@fusion.dev/helix-sandbox 0.0.0-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +112 -0
- package/api.json +1 -0
- package/custom-elements.json +1182 -0
- package/dist/code-block/code-block-highlight.d.ts +16 -0
- package/dist/code-block/code-block-highlight.d.ts.map +1 -0
- package/dist/code-block/code-block-highlight.js +10 -0
- package/dist/code-block/code-block-highlight.js.map +1 -0
- package/dist/code-block/index.d.ts +2 -0
- package/dist/code-block/index.d.ts.map +1 -0
- package/dist/code-block/index.js +5 -0
- package/dist/code-block/index.js.map +1 -0
- package/dist/editor/index.d.ts +2 -0
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.js +2 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/editor/root/editor-root.css.d.ts +2 -0
- package/dist/editor/root/editor-root.css.d.ts.map +1 -0
- package/dist/editor/root/editor-root.css.js +3 -0
- package/dist/editor/root/editor-root.css.js.map +1 -0
- package/dist/editor/root/editor-root.d.ts +146 -0
- package/dist/editor/root/editor-root.d.ts.map +1 -0
- package/dist/editor/root/editor-root.js +199 -0
- package/dist/editor/root/editor-root.js.map +1 -0
- package/dist/highlight/highlight.d.ts +25 -0
- package/dist/highlight/highlight.d.ts.map +1 -0
- package/dist/highlight/highlight.js +97 -0
- package/dist/highlight/highlight.js.map +1 -0
- package/dist/highlight/index.d.ts +4 -0
- package/dist/highlight/index.d.ts.map +1 -0
- package/dist/highlight/index.js +4 -0
- package/dist/highlight/index.js.map +1 -0
- package/dist/highlight/language.d.ts +26 -0
- package/dist/highlight/language.d.ts.map +1 -0
- package/dist/highlight/language.js +21 -0
- package/dist/highlight/language.js.map +1 -0
- package/dist/highlight/shell.d.ts +10 -0
- package/dist/highlight/shell.d.ts.map +1 -0
- package/dist/highlight/shell.js +31 -0
- package/dist/highlight/shell.js.map +1 -0
- package/dist/highlight/stream.d.ts +10 -0
- package/dist/highlight/stream.d.ts.map +1 -0
- package/dist/highlight/stream.js +178 -0
- package/dist/highlight/stream.js.map +1 -0
- package/dist/highlight/syntax.d.ts +10 -0
- package/dist/highlight/syntax.d.ts.map +1 -0
- package/dist/highlight/syntax.js +100 -0
- package/dist/highlight/syntax.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox/editor/sandbox-editor.css.d.ts +2 -0
- package/dist/sandbox/editor/sandbox-editor.css.d.ts.map +1 -0
- package/dist/sandbox/editor/sandbox-editor.css.js +3 -0
- package/dist/sandbox/editor/sandbox-editor.css.js.map +1 -0
- package/dist/sandbox/editor/sandbox-editor.d.ts +147 -0
- package/dist/sandbox/editor/sandbox-editor.d.ts.map +1 -0
- package/dist/sandbox/editor/sandbox-editor.js +199 -0
- package/dist/sandbox/editor/sandbox-editor.js.map +1 -0
- package/examples.json +1 -0
- package/lint.json +1 -0
- package/package.json +116 -0
- package/types/jsx.d.ts +638 -0
- package/types/svelte.d.ts +36 -0
- package/types/vue.d.ts +134 -0
- package/types/words.d.ts +22 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const NAMES = {
|
|
2
|
+
bash: 'sh',
|
|
3
|
+
cjs: 'js',
|
|
4
|
+
css: 'css',
|
|
5
|
+
cts: 'ts',
|
|
6
|
+
htm: 'html',
|
|
7
|
+
html: 'html',
|
|
8
|
+
javascript: 'js',
|
|
9
|
+
js: 'js',
|
|
10
|
+
jsx: 'tsx',
|
|
11
|
+
mjs: 'js',
|
|
12
|
+
mts: 'ts',
|
|
13
|
+
sh: 'sh',
|
|
14
|
+
shell: 'sh',
|
|
15
|
+
ts: 'ts',
|
|
16
|
+
tsx: 'tsx',
|
|
17
|
+
typescript: 'ts',
|
|
18
|
+
zsh: 'sh',
|
|
19
|
+
};
|
|
20
|
+
export const languageOf = (name) => NAMES[name.trim().toLowerCase()];
|
|
21
|
+
//# sourceMappingURL=language.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language.js","sourceRoot":"","sources":["../../src/highlight/language.ts"],"names":[],"mappings":"AA0BA,MAAM,KAAK,GAAsC;IAC/C,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,MAAM;IACX,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,IAAI;IAChB,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,EAAE,EAAE,IAAI;IACR,KAAK,EAAE,IAAI;IACX,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,KAAK;IACV,UAAU,EAAE,IAAI;IAChB,GAAG,EAAE,IAAI;CACV,CAAA;AAMD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAiC,EAAE,CACxE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StreamParser } from '@codemirror/language';
|
|
2
|
+
import { type Tag } from '@lezer/highlight';
|
|
3
|
+
export interface ShellState {
|
|
4
|
+
helixHead: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** The sh mode, with the command named. */
|
|
7
|
+
export declare const shellMode: StreamParser<ShellState>;
|
|
8
|
+
/** What `shellMode`'s own token name is drawn as, for its `tokenTable`. */
|
|
9
|
+
export declare const shellTokens: Record<string, Tag>;
|
|
10
|
+
//# sourceMappingURL=shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/highlight/shell.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,OAAO,EAAE,KAAK,GAAG,EAAQ,MAAM,kBAAkB,CAAA;AAyCjD,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,OAAO,CAAA;CACnB;AAED,2CAA2C;AAC3C,eAAO,MAAM,SAAS,EAAE,YAAY,CAAC,UAAU,CA8B9C,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAA6B,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { shell } from '@codemirror/legacy-modes/mode/shell';
|
|
2
|
+
import { tags } from '@lezer/highlight';
|
|
3
|
+
const OPENS = /^[|&;({!]+$/;
|
|
4
|
+
export const shellMode = {
|
|
5
|
+
...shell,
|
|
6
|
+
startState(indent) {
|
|
7
|
+
const state = shell.startState?.(indent) ?? {};
|
|
8
|
+
state.helixHead = true;
|
|
9
|
+
return state;
|
|
10
|
+
},
|
|
11
|
+
token(stream, state) {
|
|
12
|
+
if (stream.sol()) {
|
|
13
|
+
state.helixHead = true;
|
|
14
|
+
}
|
|
15
|
+
const head = state.helixHead;
|
|
16
|
+
const from = stream.pos;
|
|
17
|
+
const token = shell.token(stream, state);
|
|
18
|
+
const text = stream.string.slice(from, stream.pos);
|
|
19
|
+
if (text.trim() === '') {
|
|
20
|
+
return token;
|
|
21
|
+
}
|
|
22
|
+
if (OPENS.test(text.trim())) {
|
|
23
|
+
state.helixHead = true;
|
|
24
|
+
return token;
|
|
25
|
+
}
|
|
26
|
+
state.helixHead = false;
|
|
27
|
+
return token === null && head && /^[A-Za-z_][\w.@/-]*$/.test(text) ? 'command' : token;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
export const shellTokens = { command: tags.keyword };
|
|
31
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/highlight/shell.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAC3D,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AAwB,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StreamParser } from '@codemirror/language';
|
|
2
|
+
import { type Highlighter, type Tag } from '@lezer/highlight';
|
|
3
|
+
/**
|
|
4
|
+
* Highlights `code` with a mode, in the shape `highlightCode` from
|
|
5
|
+
* `@lezer/highlight` uses: `put` for each run of text with its classes, and
|
|
6
|
+
* `putBreak` between lines. Neighboring tokens with the same classes are one
|
|
7
|
+
* run, as they are there.
|
|
8
|
+
*/
|
|
9
|
+
export declare const highlightStream: <State>(code: string, mode: StreamParser<State>, table: Record<string, Tag | readonly Tag[]>, highlighter: Highlighter, put: (text: string, classes: string) => void, putBreak: () => void) => void;
|
|
10
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/highlight/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,GAAG,EAAQ,MAAM,kBAAkB,CAAA;AAkLnE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,QAC7B,MAAM,QACN,YAAY,CAAC,KAAK,CAAC,SAClB,MAAM,CAAC,MAAM,EAAE,GAAG,GAAG,SAAS,GAAG,EAAE,CAAC,eAC9B,WAAW,OACnB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,YAClC,MAAM,IAAI,KACnB,IAkDF,CAAA"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { tags } from '@lezer/highlight';
|
|
2
|
+
const LEGACY = {
|
|
3
|
+
attribute: 'attributeName',
|
|
4
|
+
builtin: 'variableName.standard',
|
|
5
|
+
def: 'variableName.definition',
|
|
6
|
+
error: 'invalid',
|
|
7
|
+
header: 'heading',
|
|
8
|
+
property: 'propertyName',
|
|
9
|
+
qualifier: 'modifier',
|
|
10
|
+
'string-2': 'string.special',
|
|
11
|
+
tag: 'tagName',
|
|
12
|
+
type: 'typeName',
|
|
13
|
+
variable: 'variableName',
|
|
14
|
+
'variable-2': 'variableName.special',
|
|
15
|
+
};
|
|
16
|
+
const tagsOf = (token, table) => {
|
|
17
|
+
const name = LEGACY[token];
|
|
18
|
+
const known = (part) => name === undefined
|
|
19
|
+
? (table[part] ?? tags[part])
|
|
20
|
+
: tags[part];
|
|
21
|
+
return (name ?? token).split(' ').flatMap((word) => {
|
|
22
|
+
let found = [];
|
|
23
|
+
for (const part of word.split('.')) {
|
|
24
|
+
const value = known(part);
|
|
25
|
+
if (typeof value === 'function') {
|
|
26
|
+
found = found.map(value);
|
|
27
|
+
}
|
|
28
|
+
else if (value !== undefined && found.length === 0) {
|
|
29
|
+
found = Array.isArray(value) ? [...value] : [value];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return found;
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const columnOf = (string, end, tabSize) => {
|
|
36
|
+
let column = 0;
|
|
37
|
+
for (let at = 0; at < end; at += 1) {
|
|
38
|
+
column = string.charCodeAt(at) === 9 ? column + tabSize - (column % tabSize) : column + 1;
|
|
39
|
+
}
|
|
40
|
+
return column;
|
|
41
|
+
};
|
|
42
|
+
class LineStream {
|
|
43
|
+
constructor(string, tabSize, indentUnit) {
|
|
44
|
+
this.string = string;
|
|
45
|
+
this.tabSize = tabSize;
|
|
46
|
+
this.indentUnit = indentUnit;
|
|
47
|
+
this.pos = 0;
|
|
48
|
+
this.start = 0;
|
|
49
|
+
}
|
|
50
|
+
backUp(count) {
|
|
51
|
+
this.pos -= count;
|
|
52
|
+
}
|
|
53
|
+
column() {
|
|
54
|
+
return columnOf(this.string, this.start, this.tabSize);
|
|
55
|
+
}
|
|
56
|
+
current() {
|
|
57
|
+
return this.string.slice(this.start, this.pos);
|
|
58
|
+
}
|
|
59
|
+
eat(match) {
|
|
60
|
+
const char = this.string.charAt(this.pos);
|
|
61
|
+
const ok = typeof match === 'string'
|
|
62
|
+
? char === match
|
|
63
|
+
: char !== '' && (match instanceof RegExp ? match.test(char) : match(char));
|
|
64
|
+
if (ok) {
|
|
65
|
+
this.pos += 1;
|
|
66
|
+
return char;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
eatSpace() {
|
|
71
|
+
const from = this.pos;
|
|
72
|
+
while (/[\s ]/.test(this.string.charAt(this.pos))) {
|
|
73
|
+
this.pos += 1;
|
|
74
|
+
}
|
|
75
|
+
return this.pos > from;
|
|
76
|
+
}
|
|
77
|
+
eatWhile(match) {
|
|
78
|
+
const from = this.pos;
|
|
79
|
+
while (this.eat(match) !== undefined) {
|
|
80
|
+
}
|
|
81
|
+
return this.pos > from;
|
|
82
|
+
}
|
|
83
|
+
eol() {
|
|
84
|
+
return this.pos >= this.string.length;
|
|
85
|
+
}
|
|
86
|
+
indentation() {
|
|
87
|
+
return columnOf(this.string, this.string.search(/\S|$/), this.tabSize);
|
|
88
|
+
}
|
|
89
|
+
match(pattern, consume = true, caseInsensitive = false) {
|
|
90
|
+
if (typeof pattern === 'string') {
|
|
91
|
+
const fold = (text) => (caseInsensitive ? text.toLowerCase() : text);
|
|
92
|
+
const ahead = this.string.slice(this.pos, this.pos + pattern.length);
|
|
93
|
+
if (fold(ahead) !== fold(pattern)) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
if (consume) {
|
|
97
|
+
this.pos += pattern.length;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
const found = this.string.slice(this.pos).match(pattern);
|
|
102
|
+
if (found?.index !== 0) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
if (consume) {
|
|
106
|
+
this.pos += found[0].length;
|
|
107
|
+
}
|
|
108
|
+
return found;
|
|
109
|
+
}
|
|
110
|
+
next() {
|
|
111
|
+
return this.pos < this.string.length ? this.string.charAt(this.pos++) : undefined;
|
|
112
|
+
}
|
|
113
|
+
peek() {
|
|
114
|
+
return this.string.charAt(this.pos) || undefined;
|
|
115
|
+
}
|
|
116
|
+
skipTo(char) {
|
|
117
|
+
const found = this.string.indexOf(char, this.pos);
|
|
118
|
+
if (found > -1) {
|
|
119
|
+
this.pos = found;
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
skipToEnd() {
|
|
125
|
+
this.pos = this.string.length;
|
|
126
|
+
}
|
|
127
|
+
sol() {
|
|
128
|
+
return this.pos === 0;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export const highlightStream = (code, mode, table, highlighter, put, putBreak) => {
|
|
132
|
+
const state = mode.startState?.(2) ?? true;
|
|
133
|
+
const classes = new Map();
|
|
134
|
+
const classOf = (token) => {
|
|
135
|
+
if (token === null) {
|
|
136
|
+
return '';
|
|
137
|
+
}
|
|
138
|
+
let found = classes.get(token);
|
|
139
|
+
if (found === undefined) {
|
|
140
|
+
found = highlighter.style(tagsOf(token, table)) ?? '';
|
|
141
|
+
classes.set(token, found);
|
|
142
|
+
}
|
|
143
|
+
return found;
|
|
144
|
+
};
|
|
145
|
+
code.split('\n').forEach((line, index) => {
|
|
146
|
+
if (index > 0) {
|
|
147
|
+
putBreak();
|
|
148
|
+
}
|
|
149
|
+
if (line === '') {
|
|
150
|
+
mode.blankLine?.(state, 2);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const stream = new LineStream(line, 4, 2);
|
|
154
|
+
let run = '';
|
|
155
|
+
let from = 0;
|
|
156
|
+
while (!stream.eol()) {
|
|
157
|
+
stream.start = stream.pos;
|
|
158
|
+
let token = null;
|
|
159
|
+
for (let attempt = 0; attempt < 10 && stream.pos === stream.start; attempt += 1) {
|
|
160
|
+
token = mode.token(stream, state);
|
|
161
|
+
}
|
|
162
|
+
if (stream.pos === stream.start) {
|
|
163
|
+
stream.skipToEnd();
|
|
164
|
+
token = null;
|
|
165
|
+
}
|
|
166
|
+
const now = classOf(token);
|
|
167
|
+
if (now !== run) {
|
|
168
|
+
if (stream.start > from) {
|
|
169
|
+
put(line.slice(from, stream.start), run);
|
|
170
|
+
}
|
|
171
|
+
from = stream.start;
|
|
172
|
+
run = now;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
put(line.slice(from), run);
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/highlight/stream.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAenE,MAAM,MAAM,GAA2B;IACrC,SAAS,EAAE,eAAe;IAC1B,OAAO,EAAE,uBAAuB;IAChC,GAAG,EAAE,yBAAyB;IAC9B,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,cAAc;IACxB,SAAS,EAAE,UAAU;IACrB,UAAU,EAAE,gBAAgB;IAC5B,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,cAAc;IACxB,YAAY,EAAE,sBAAsB;CACrC,CAAA;AASD,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,KAA2C,EAAS,EAAE;IACnF,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IAC1B,MAAM,KAAK,GAAG,CAAC,IAAY,EAAqB,EAAE,CAChD,IAAI,KAAK,SAAS;QAChB,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAK,IAA8B,CAAC,IAAI,CAAC,CAAC;QACxD,CAAC,CAAE,IAA8B,CAAC,IAAI,CAAC,CAAA;IAC3C,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC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AAK,CAAC,MAAiC,EAAE,KAAK,CAAC,CAAA;YAC9D,CAAC;YACD,IAAI,MAAM,CAAC,GAAG,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;gBAChC,MAAM,CAAC,SAAS,EAAE,CAAA;gBAClB,KAAK,GAAG,IAAI,CAAA;YACd,CAAC;YACD,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;YAC1B,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;gBAChB,IAAI,MAAM,CAAC,KAAK,GAAG,IAAI,EAAE,CAAC;oBACxB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAA;gBAC1C,CAAC;gBACD,IAAI,GAAG,MAAM,CAAC,KAAK,CAAA;gBACnB,GAAG,GAAG,GAAG,CAAA;YACX,CAAC;QACH,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Highlighter } from '@lezer/highlight';
|
|
2
|
+
/**
|
|
3
|
+
* Gives each token the class of the rule that colors it, a `helix-syntax-`
|
|
4
|
+
* class such as `helix-syntax-keyword`. Pass it to `highlight`, and put
|
|
5
|
+
* `syntaxRules` where the result is drawn.
|
|
6
|
+
*/
|
|
7
|
+
export declare const syntaxHighlighter: Highlighter;
|
|
8
|
+
/** The CSS for `syntaxHighlighter`'s classes, which colors them from the `--helix-color-syntax-*` tokens. */
|
|
9
|
+
export declare const syntaxRules: string;
|
|
10
|
+
//# sourceMappingURL=syntax.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["../../src/highlight/syntax.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAkC,MAAM,kBAAkB,CAAA;AAoInF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,WAE/B,CAAA;AAED,6GAA6G;AAC7G,eAAO,MAAM,WAAW,EAAE,MAOd,CAAA"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { tagHighlighter, tags } from '@lezer/highlight';
|
|
2
|
+
const RULES = [
|
|
3
|
+
{
|
|
4
|
+
class: 'helix-syntax-comment',
|
|
5
|
+
style: { color: 'var(--helix-color-syntax-comment)', fontStyle: 'italic' },
|
|
6
|
+
tag: [tags.comment, tags.lineComment, tags.blockComment, tags.docComment],
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
class: 'helix-syntax-keyword',
|
|
10
|
+
style: { color: 'var(--helix-color-syntax-keyword)' },
|
|
11
|
+
tag: [
|
|
12
|
+
tags.keyword,
|
|
13
|
+
tags.controlKeyword,
|
|
14
|
+
tags.definitionKeyword,
|
|
15
|
+
tags.moduleKeyword,
|
|
16
|
+
tags.operatorKeyword,
|
|
17
|
+
tags.self,
|
|
18
|
+
tags.null,
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
class: 'helix-syntax-string',
|
|
23
|
+
style: { color: 'var(--helix-color-syntax-string)' },
|
|
24
|
+
tag: [tags.string, tags.special(tags.string), tags.regexp, tags.escape],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
class: 'helix-syntax-tag',
|
|
28
|
+
style: { color: 'var(--helix-color-syntax-tag)' },
|
|
29
|
+
tag: [tags.tagName, tags.standard(tags.tagName), tags.heading, tags.quote],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
class: 'helix-syntax-name',
|
|
33
|
+
style: { color: 'var(--helix-color-syntax-name)' },
|
|
34
|
+
tag: [
|
|
35
|
+
tags.attributeName,
|
|
36
|
+
tags.variableName,
|
|
37
|
+
tags.propertyName,
|
|
38
|
+
tags.number,
|
|
39
|
+
tags.integer,
|
|
40
|
+
tags.float,
|
|
41
|
+
tags.labelName,
|
|
42
|
+
tags.namespace,
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
class: 'helix-syntax-callable',
|
|
47
|
+
style: { color: 'var(--helix-color-syntax-callable)' },
|
|
48
|
+
tag: [
|
|
49
|
+
tags.function(tags.variableName),
|
|
50
|
+
tags.function(tags.propertyName),
|
|
51
|
+
tags.definition(tags.function(tags.variableName)),
|
|
52
|
+
tags.className,
|
|
53
|
+
tags.typeName,
|
|
54
|
+
tags.macroName,
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
class: 'helix-syntax-constant',
|
|
59
|
+
style: { color: 'var(--helix-color-syntax-constant)' },
|
|
60
|
+
tag: [
|
|
61
|
+
tags.atom,
|
|
62
|
+
tags.bool,
|
|
63
|
+
tags.constant(tags.name),
|
|
64
|
+
tags.standard(tags.name),
|
|
65
|
+
tags.unit,
|
|
66
|
+
tags.attributeValue,
|
|
67
|
+
tags.color,
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
class: 'helix-syntax-strong',
|
|
72
|
+
style: { color: 'var(--helix-color-foreground)', fontWeight: 'bold' },
|
|
73
|
+
tag: tags.strong,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
class: 'helix-syntax-emphasis',
|
|
77
|
+
style: { color: 'var(--helix-color-foreground)', fontStyle: 'italic' },
|
|
78
|
+
tag: tags.emphasis,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
class: 'helix-syntax-link',
|
|
82
|
+
style: { color: 'var(--helix-color-syntax-name)', textDecoration: 'underline' },
|
|
83
|
+
tag: tags.link,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
class: 'helix-syntax-strikethrough',
|
|
87
|
+
style: { textDecoration: 'line-through' },
|
|
88
|
+
tag: tags.strikethrough,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
class: 'helix-syntax-invalid',
|
|
92
|
+
style: { color: 'var(--helix-color-syntax-invalid)' },
|
|
93
|
+
tag: tags.invalid,
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
export const syntaxHighlighter = tagHighlighter(RULES.map((rule) => ({ class: rule.class, tag: rule.tag })));
|
|
97
|
+
export const syntaxRules = RULES.map((rule) => `.${rule.class} { ${Object.entries(rule.style)
|
|
98
|
+
.map(([name, value]) => `${name.replace(/[A-Z]/g, (up) => `-${up.toLowerCase()}`)}: ${value};`)
|
|
99
|
+
.join(' ')} }`).join('\n');
|
|
100
|
+
//# sourceMappingURL=syntax.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax.js","sourceRoot":"","sources":["../../src/highlight/syntax.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,cAAc,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAiCnF,MAAM,KAAK,GAA0B;IACnC;QACE,KAAK,EAAE,sBAAsB;QAC7B,KAAK,EAAE,EAAE,KAAK,EAAE,mCAAmC,EAAE,SAAS,EAAE,QAAQ,EAAE;QAC1E,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC;KAC1E;IACD;QACE,KAAK,EAAE,sBAAsB;QAC7B,KAAK,EAAE,EAAE,KAAK,EAAE,mCAAmC,EAAE;QACrD,GAAG,EAAE;YACH,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,cAAc;YACnB,IAAI,CAAC,iBAAiB;YACtB,IAAI,CAAC,aAAa;YAClB,IAAI,CAAC,eAAe;YACpB,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,IAAI;SACV;KACF;IACD;QACE,KAAK,EAAE,qBAAqB;QAC5B,KAAK,EAAE,EAAE,KAAK,EAAE,kCAAkC,EAAE;QACpD,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO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AAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,KAAK,KAAK,GAAG,CAC1F;KACA,IAAI,CAAC,GAAG,CAAC,IAAI,CACnB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The source editor and the code highlighter of the Helix sandbox.
|
|
3
|
+
*
|
|
4
|
+
* Each entry does one thing, and two of them register something:
|
|
5
|
+
*
|
|
6
|
+
* - `./editor` registers `helix-sandbox-editor`, an editable pane of source
|
|
7
|
+
* with CodeMirror behind it, for `@fusion.dev/helix/sandbox`.
|
|
8
|
+
* - `./code-block` gives every Code Block a highlighter, the grammars below in
|
|
9
|
+
* the editor's colors.
|
|
10
|
+
* - `./highlight` turns a snippet into highlighted HTML, on a server or in a
|
|
11
|
+
* page, and registers nothing.
|
|
12
|
+
*
|
|
13
|
+
* This entry registers nothing either. It exports what `./highlight` exports,
|
|
14
|
+
* and the editor's class and events as types, which the framework typings
|
|
15
|
+
* import from here. Importing it loads no editor.
|
|
16
|
+
*/
|
|
17
|
+
export type { CaretDetail, HelixBeforeEditEvent, HelixCaretEvent, HelixEditEvent, } from '@fusion.dev/helix-core';
|
|
18
|
+
export * from './highlight/index.js';
|
|
19
|
+
export type { EditorLanguage, HelixSandboxEditor } from './sandbox/editor/sandbox-editor.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,YAAY,EACV,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,cAAc,GACf,MAAM,wBAAwB,CAAA;AAC/B,cAAc,sBAAsB,CAAA;AACpC,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-editor.css.d.ts","sourceRoot":"","sources":["../../../src/sandbox/editor/sandbox-editor.css.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,yBAAihC,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createSheet } from '@fusion.dev/helix-core';
|
|
2
|
+
export const styles = createSheet(`:host {display: block;min-block-size: 0;overflow: hidden}[part="editor"] {block-size: 100%;font-family: var(--helix-font-mono);font-size: var(--helix-text-sm)}[part="editor"] .cm-editor {block-size: 100%}[part="editor"] .cm-scroller {font-family: inherit;line-height: var(--helix-leading-normal)}[part="editor"] .cm-gutters {background-color: transparent;border: none;color: var(--helix-color-foreground-muted)}[part="editor"] .cm-activeLineGutter, [part="editor"] .cm-activeLine {background-color: var(--helix-color-surface-sunken)}[part="editor"] .cm-content {caret-color: var(--helix-color-primary)}[part="editor"] .cm-cursor {border-left-color: var(--helix-color-primary)}[part="editor"] .cm-selectionBackground, [part="editor"] .cm-editor.cm-focused .cm-selectionBackground {background-color: var(--helix-color-primary-subtle)}[part="editor"] .cm-editor.cm-focused {outline: none}:host([readonly]) [part="editor"] .cm-cursor {border-left-color: var(--helix-color-foreground-subtle)}@media print {:host {display: none}}`);
|
|
3
|
+
//# sourceMappingURL=sandbox-editor.css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-editor.css.js","sourceRoot":"","sources":["../../../src/sandbox/editor/sandbox-editor.css.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEpD,MAAM,CAAC,MAAM,MAAM,GAAG,WAAW,CAAC,igCAAigC,CAAC,CAAA"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { type CaretDetail, HelixElement } from '@fusion.dev/helix-core';
|
|
2
|
+
import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
|
|
3
|
+
/**
|
|
4
|
+
* A language the editor knows, by the name a file or a sandbox pane carries.
|
|
5
|
+
*
|
|
6
|
+
* **Written out, where `keyof typeof` would hide the values.** The manifest
|
|
7
|
+
* records a property's type as the text somebody wrote, so a type derived from
|
|
8
|
+
* a record's keys reached it as a name with nothing in it and the reference
|
|
9
|
+
* page listed no values. A union on one line resolves for every reader of these
|
|
10
|
+
* sources without a type system, the `axes` rule included.
|
|
11
|
+
*
|
|
12
|
+
* The names are the panes': `js`, `jsx`, `mjs`, `ts` and `tsx` beside `css`,
|
|
13
|
+
* `html` and `sh`, and `javascript`. The editor reads every name `languageOf`
|
|
14
|
+
* from `@fusion.dev/helix-sandbox/highlight` reads, such as `TypeScript` or
|
|
15
|
+
* `bash`, and `jsx` as `tsx`.
|
|
16
|
+
*/
|
|
17
|
+
export type EditorLanguage = 'css' | 'html' | 'javascript' | 'js' | 'jsx' | 'mjs' | 'sh' | 'ts' | 'tsx';
|
|
18
|
+
/**
|
|
19
|
+
* @summary An editable pane of source, with highlighting and line numbers.
|
|
20
|
+
*
|
|
21
|
+
* @description
|
|
22
|
+
* CodeMirror, not a `<textarea>`. A textarea cannot highlight what it holds,
|
|
23
|
+
* number its lines, or say where the cursor is, and a status bar reading line
|
|
24
|
+
* and column has to ask something.
|
|
25
|
+
*
|
|
26
|
+
* **On its own path.** This is `@fusion.dev/helix-sandbox/editor`, and the
|
|
27
|
+
* package's root exports its class as a type only, because CodeMirror is most
|
|
28
|
+
* of what the package weighs over the wire. A sandbox with no editable pane
|
|
29
|
+
* pays for none, and neither does a site that registers its elements once.
|
|
30
|
+
*
|
|
31
|
+
* `language` names the grammar by the name a file or a sandbox pane carries:
|
|
32
|
+
* `css`, `html`, `js`, `jsx`, `mjs`, `sh`, `ts` or `tsx`. A name the editor
|
|
33
|
+
* does not read draws the source plain, and the console says so once.
|
|
34
|
+
*
|
|
35
|
+
* Each edit a reader makes is `helix-before-edit` first, which you can cancel
|
|
36
|
+
* to refuse the edit, and `helix-edit` once the source holds it, as
|
|
37
|
+
* `helix-sandbox-source` sends them. A `value` set from outside is the source the editor is given, and
|
|
38
|
+
* sends neither. **The editor is `:state(modified)` while its source differs
|
|
39
|
+
* from the source it was given**, the first `value` or the last one set from
|
|
40
|
+
* outside, and `reset()` puts that source back as an edit.
|
|
41
|
+
*
|
|
42
|
+
* The view is built once and reconfigured, not rebuilt. Replacing it on every
|
|
43
|
+
* change would throw away the undo history, the scroll position, and the
|
|
44
|
+
* selection, which is most of what an editor is.
|
|
45
|
+
*
|
|
46
|
+
* @since 0.1.0
|
|
47
|
+
* @status experimental
|
|
48
|
+
* @category tooling
|
|
49
|
+
* @family sandbox
|
|
50
|
+
* @aliases Code editor, Source pane
|
|
51
|
+
* @documentation https://fusion.dev/helix/components/sandbox
|
|
52
|
+
*
|
|
53
|
+
* @event {HelixBeforeEditEvent} helix-before-edit - Fired before the source is edited. Cancelable: refusing it takes the decision and nothing moves.
|
|
54
|
+
* @event {HelixCaretEvent} helix-caret - Fired when the cursor moves, with its line and column.
|
|
55
|
+
* @event {HelixEditEvent} helix-edit - Fired after the source was edited, with the new source.
|
|
56
|
+
*
|
|
57
|
+
* @csspart editor - The element CodeMirror is mounted into.
|
|
58
|
+
*
|
|
59
|
+
* @cssstate modified - While the source differs from the source the editor was given, until `reset()` or a new `value`.
|
|
60
|
+
*/
|
|
61
|
+
export declare class HelixSandboxEditor extends HelixElement {
|
|
62
|
+
/**
|
|
63
|
+
* The key the editor's words are registered under, its tag:
|
|
64
|
+
* `registerWords('de', { 'helix-sandbox-editor': { fieldLabel: 'Quelltext' } })`.
|
|
65
|
+
*/
|
|
66
|
+
static words: string;
|
|
67
|
+
/**
|
|
68
|
+
* Accessible name for the editable region.
|
|
69
|
+
*/
|
|
70
|
+
fieldLabel: string;
|
|
71
|
+
/**
|
|
72
|
+
* The language of the source, which decides how it is highlighted. A name
|
|
73
|
+
* the editor does not read draws the source plain.
|
|
74
|
+
*/
|
|
75
|
+
language: EditorLanguage;
|
|
76
|
+
/**
|
|
77
|
+
* Which source this pane holds, echoed in every change.
|
|
78
|
+
*/
|
|
79
|
+
name: string;
|
|
80
|
+
/**
|
|
81
|
+
* Whether the text can be changed.
|
|
82
|
+
*
|
|
83
|
+
* `EditorState.readOnly` rather than removing the editor's focus or its
|
|
84
|
+
* keymap: a reader still needs to select the text, scroll it, and put a
|
|
85
|
+
* cursor in it to read a long line. What it stops is the typing.
|
|
86
|
+
*/
|
|
87
|
+
readOnly: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* The source being edited.
|
|
90
|
+
*/
|
|
91
|
+
value: string;
|
|
92
|
+
private readonly readOnly$;
|
|
93
|
+
private view;
|
|
94
|
+
private readonly language$;
|
|
95
|
+
/** The editable region's name, which follows `field-label` and the words registered for it. */
|
|
96
|
+
private readonly name$;
|
|
97
|
+
/** The source the editor was given: its first `value`, or the last one set from outside. */
|
|
98
|
+
private baseline;
|
|
99
|
+
/** The source the last edit left, while `value` still holds it. */
|
|
100
|
+
private edited;
|
|
101
|
+
/** The `language` last reported as one the editor does not read. */
|
|
102
|
+
private unread;
|
|
103
|
+
/**
|
|
104
|
+
* Whether the source differs from the source the editor was given: its
|
|
105
|
+
* first `value`, or the last one set from outside.
|
|
106
|
+
*/
|
|
107
|
+
get modified(): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Puts back the source the editor was given, as an edit: `helix-before-edit`
|
|
110
|
+
* is sent first and can refuse it, and a sandbox passes it to its preview.
|
|
111
|
+
*/
|
|
112
|
+
reset(): void;
|
|
113
|
+
/**
|
|
114
|
+
* What `language` turns on: its grammar, or nothing for a name the editor
|
|
115
|
+
* does not read, which it reports once for each name.
|
|
116
|
+
*/
|
|
117
|
+
private grammar;
|
|
118
|
+
/** Where the cursor is, counted from one, as an editor reports it. */
|
|
119
|
+
get caret(): CaretDetail;
|
|
120
|
+
private get mount();
|
|
121
|
+
/**
|
|
122
|
+
* Builds the view once the mount exists.
|
|
123
|
+
*
|
|
124
|
+
* `root` is the shadow root rather than the document, or CodeMirror puts its
|
|
125
|
+
* stylesheet where this element cannot see it and the editor renders unstyled.
|
|
126
|
+
*/
|
|
127
|
+
private create;
|
|
128
|
+
/**
|
|
129
|
+
* Moves focus into the text, not onto the host.
|
|
130
|
+
*
|
|
131
|
+
* The host is not focusable: what a reader types into is CodeMirror's
|
|
132
|
+
* contenteditable, several nodes down inside this shadow root. Without this,
|
|
133
|
+
* `editor.focus()` from outside silently does nothing.
|
|
134
|
+
*/
|
|
135
|
+
focus(): void;
|
|
136
|
+
disconnectedCallback(): void;
|
|
137
|
+
protected willUpdate(changed: PropertyValues): void;
|
|
138
|
+
protected updated(changed: PropertyValues): void;
|
|
139
|
+
protected render(): TemplateResult;
|
|
140
|
+
static styles: CSSResultGroup;
|
|
141
|
+
}
|
|
142
|
+
declare global {
|
|
143
|
+
interface HTMLElementTagNameMap {
|
|
144
|
+
'helix-sandbox-editor': HelixSandboxEditor;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=sandbox-editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-editor.d.ts","sourceRoot":"","sources":["../../../src/sandbox/editor/sandbox-editor.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,WAAW,EAKhB,YAAY,EAGb,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAQzE;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,cAAc,GACtB,KAAK,GACL,MAAM,GACN,YAAY,GACZ,IAAI,GACJ,KA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