Skip to content

Commit 342e8b0

Browse files
authored
Web client (#83)
1 parent 76d62d8 commit 342e8b0

File tree

14 files changed

+1407
-534
lines changed

14 files changed

+1407
-534
lines changed

crx/capo.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/astro.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export default defineConfig({
4747
label: 'Home',
4848
link: '/'
4949
},
50+
{
51+
label: 'Demo',
52+
link: '/user/demo/'
53+
},
5054
{
5155
label: 'Getting started',
5256
items: [

docs/package-lock.json

Lines changed: 274 additions & 381 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
import { Icon } from '@astrojs/starlight/components';
3+
---
4+
5+
<script>
6+
import { run } from '../lib/capo.js';
7+
import { VirtualConsole } from '../lib/VirtualConsole.js';
8+
9+
document.addEventListener('DOMContentLoaded', init);
10+
11+
function init() {
12+
const input = document.querySelector('#input');
13+
const markup = document.querySelector('#markup');
14+
const output = document.querySelector('#output');
15+
16+
const virtualConsole = new VirtualConsole(output);
17+
18+
input.addEventListener('submit', e => {
19+
try {
20+
run(markup.value, virtualConsole);
21+
} catch (e) {
22+
console.error(e);
23+
}
24+
e.preventDefault();
25+
});
26+
}
27+
</script>
28+
29+
<style>
30+
form {
31+
display: flex;
32+
flex-direction: column;
33+
gap: 1.5rem;
34+
}
35+
36+
textarea {
37+
display: block;
38+
width: 100%;
39+
height: 200px;
40+
font-family: monospace !important;
41+
}
42+
43+
button {
44+
cursor: pointer;
45+
align-self: center;
46+
display: inline-block;
47+
border: none;
48+
border-radius: 999rem;
49+
margin: 0 !important;
50+
padding: 1rem 1.25rem;
51+
background-color: var(--sl-color-text-accent);
52+
color: var(--sl-color-black);
53+
font-size: var(--sl-text-base);
54+
}
55+
56+
button svg {
57+
display: inline !important;
58+
vertical-align: middle;
59+
margin-left: 0.5rem;
60+
}
61+
</style>
62+
63+
<form id="input">
64+
<textarea id="markup" placeholder="Enter HTML">
65+
<title>test</title>
66+
</textarea>
67+
<button>Run <Icon name="rocket" color="inherit" size="1.5rem" /></button>
68+
</form>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: capo.js demo
3+
description: Try capo.js
4+
---
5+
6+
import CapoClient from '../../../components/CapoClient.astro';
7+
8+
## Try it live
9+
10+
To see capo.js in action, enter some HTML in the form field below and click the "Run" button.
11+
12+
Results are logged to the DevTools console.
13+
14+
<CapoClient/>

docs/src/lib/VirtualConsole.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export class VirtualConsole {
2+
3+
constructor(rootElement) {
4+
this.rootElement = rootElement;
5+
}
6+
7+
log(...args) {
8+
console.log(...args);
9+
}
10+
11+
warn(...args) {
12+
console.log(...args);
13+
}
14+
15+
error(...args) {
16+
console.error(...args);
17+
}
18+
19+
groupCollapsed(...args) {
20+
console.groupCollapsed(...args);
21+
}
22+
23+
groupEnd(...args) {
24+
console.groupEnd(...args);
25+
}
26+
27+
}

0 commit comments

Comments
 (0)