@fuzdev/fuz_code 0.38.0 → 0.40.0
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 +2 -2
- package/README.md +8 -8
- package/dist/Code.svelte +15 -3
- package/dist/Code.svelte.d.ts +7 -0
- package/dist/Code.svelte.d.ts.map +1 -1
- package/dist/CodeHighlight.svelte +3 -2
- package/dist/CodeHighlight.svelte.d.ts.map +1 -1
- package/dist/syntax_styler.d.ts +1 -17
- package/dist/syntax_styler.d.ts.map +1 -1
- package/dist/syntax_styler.js +7 -7
- package/dist/theme_variables.css +2 -2
- package/package.json +11 -12
- package/src/lib/syntax_styler.ts +7 -7
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -25,8 +25,8 @@ but there are two optional dependencies:
|
|
|
25
25
|
based on [`prism-svelte`](https://github.com/pngwn/prism-svelte)
|
|
26
26
|
and a [Svelte component](src/lib/Code.svelte) for convenient usage.
|
|
27
27
|
- The [default theme](src/lib/theme.css) integrates
|
|
28
|
-
with my CSS library [
|
|
29
|
-
Non-
|
|
28
|
+
with my CSS library [fuz_css](https://github.com/fuzdev/fuz_css) for colors that adapt to the user's runtime `color-scheme` preference.
|
|
29
|
+
Non-fuz_css users should import [theme_variables.css](src/lib/theme_variables.css)
|
|
30
30
|
or otherwise define those variables.
|
|
31
31
|
|
|
32
32
|
Compared to [Shiki](https://github.com/shikijs/shiki),
|
|
@@ -79,14 +79,14 @@ import '@fuzdev/fuz_code/theme.css';
|
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
The primary themes (currently just [one](src/lib/theme.css)) have a dependency
|
|
82
|
-
on my CSS library [
|
|
82
|
+
on my CSS library [fuz_css](https://github.com/fuzdev/fuz_css)
|
|
83
83
|
for [color-scheme](https://css.fuz.dev/docs/themes) awareness.
|
|
84
|
-
See the [
|
|
84
|
+
See the [fuz_css docs](https://css.fuz.dev/) for its usage.
|
|
85
85
|
|
|
86
|
-
If you're not using
|
|
86
|
+
If you're not using fuz_css, import `theme_variables.css` alongside `theme.css`:
|
|
87
87
|
|
|
88
88
|
```ts
|
|
89
|
-
// Without
|
|
89
|
+
// Without fuz_css:
|
|
90
90
|
import '@fuzdev/fuz_code/theme.css';
|
|
91
91
|
import '@fuzdev/fuz_code/theme_variables.css';
|
|
92
92
|
```
|
|
@@ -96,9 +96,9 @@ import '@fuzdev/fuz_code/theme_variables.css';
|
|
|
96
96
|
- [@fuzdev/fuz_code/syntax_styler_global.js](src/lib/syntax_styler_global.ts) - pre-configured instance with all grammars
|
|
97
97
|
- [@fuzdev/fuz_code/syntax_styler.js](src/lib/syntax_styler.ts) - base class for custom grammars
|
|
98
98
|
- [@fuzdev/fuz_code/theme.css](src/lib/theme.css) -
|
|
99
|
-
default theme that depends on [
|
|
99
|
+
default theme that depends on [fuz_css](https://github.com/fuzdev/fuz_css)
|
|
100
100
|
- [@fuzdev/fuz_code/theme_variables.css](src/lib/theme_variables.css) -
|
|
101
|
-
CSS variables for non-
|
|
101
|
+
CSS variables for non-fuz_css users
|
|
102
102
|
- [@fuzdev/fuz_code/Code.svelte](src/lib/Code.svelte) -
|
|
103
103
|
Svelte component for syntax highlighting with HTML generation
|
|
104
104
|
|
package/dist/Code.svelte
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
grammar,
|
|
13
13
|
inline = false,
|
|
14
14
|
wrap = false,
|
|
15
|
+
nomargin = false,
|
|
15
16
|
syntax_styler = syntax_styler_global,
|
|
16
17
|
children,
|
|
17
18
|
...rest
|
|
@@ -74,6 +75,13 @@
|
|
|
74
75
|
* @default false
|
|
75
76
|
*/
|
|
76
77
|
wrap?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Whether to disable the default margin-bottom on block code.
|
|
80
|
+
* Block code has `margin-bottom: var(--space_lg)` by default when not `:last-child`.
|
|
81
|
+
*
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
nomargin?: boolean;
|
|
77
85
|
/**
|
|
78
86
|
* Custom SyntaxStyler instance to use for highlighting.
|
|
79
87
|
* Allows using a different styler with custom grammars or configuration.
|
|
@@ -121,14 +129,14 @@
|
|
|
121
129
|
|
|
122
130
|
<!-- eslint-disable svelte/no-at-html-tags -->
|
|
123
131
|
|
|
124
|
-
<code {...rest} class:inline class:wrap data-lang={lang}
|
|
132
|
+
<code {...rest} class:inline class:wrap class:nomargin data-lang={lang}
|
|
125
133
|
>{#if highlighting_disabled}{content}{:else if children}{@render children(
|
|
126
134
|
html_content,
|
|
127
135
|
)}{:else}{@html html_content}{/if}</code
|
|
128
136
|
>
|
|
129
137
|
|
|
130
138
|
<style>
|
|
131
|
-
/* inline code inherits
|
|
139
|
+
/* inline code inherits fuz_css defaults: pre-wrap, inline-block, baseline alignment */
|
|
132
140
|
|
|
133
141
|
code:not(.inline) {
|
|
134
142
|
/* block code: traditional no-wrap, horizontal scroll */
|
|
@@ -140,7 +148,11 @@
|
|
|
140
148
|
}
|
|
141
149
|
|
|
142
150
|
code.wrap:not(.inline) {
|
|
143
|
-
/* unset what we set above, otherwise rely on
|
|
151
|
+
/* unset what we set above, otherwise rely on fuz_css base styles */
|
|
144
152
|
white-space: pre-wrap;
|
|
145
153
|
}
|
|
154
|
+
|
|
155
|
+
code:not(.inline):not(.nomargin):not(:last-child) {
|
|
156
|
+
margin-bottom: var(--space_lg);
|
|
157
|
+
}
|
|
146
158
|
</style>
|
package/dist/Code.svelte.d.ts
CHANGED
|
@@ -60,6 +60,13 @@ type $$ComponentProps = SvelteHTMLElements['code'] & {
|
|
|
60
60
|
* @default false
|
|
61
61
|
*/
|
|
62
62
|
wrap?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Whether to disable the default margin-bottom on block code.
|
|
65
|
+
* Block code has `margin-bottom: var(--space_lg)` by default when not `:last-child`.
|
|
66
|
+
*
|
|
67
|
+
* @default false
|
|
68
|
+
*/
|
|
69
|
+
nomargin?: boolean;
|
|
63
70
|
/**
|
|
64
71
|
* Custom SyntaxStyler instance to use for highlighting.
|
|
65
72
|
* Allows using a different styler with custom grammars or configuration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Code.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/Code.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,QAAQ,CAAC;AAEpC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAGxD,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEnE,KAAK,gBAAgB,GAAI,kBAAkB,CAAC,MAAM,CAAC,GAAG;IACrD,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrC,CAAC;
|
|
1
|
+
{"version":3,"file":"Code.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/Code.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,QAAQ,CAAC;AAEpC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAGxD,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEnE,KAAK,gBAAgB,GAAI,kBAAkB,CAAC,MAAM,CAAC,GAAG;IACrD,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrC,CAAC;AA8DH,QAAA,MAAM,IAAI,sDAAwC,CAAC;AACnD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AACpC,eAAe,IAAI,CAAC"}
|
|
@@ -172,6 +172,7 @@
|
|
|
172
172
|
highlight_manager?.destroy();
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
+
// TODO use intersect attachment from fuz_ui to optimize ranges
|
|
175
176
|
// TODO do syntax styling at compile-time in the normal case, and don't import these at runtime
|
|
176
177
|
// TODO @html making me nervous
|
|
177
178
|
</script>
|
|
@@ -187,7 +188,7 @@
|
|
|
187
188
|
>
|
|
188
189
|
|
|
189
190
|
<style>
|
|
190
|
-
/* inline code inherits
|
|
191
|
+
/* inline code inherits fuz_css defaults: pre-wrap, inline-block, baseline alignment */
|
|
191
192
|
|
|
192
193
|
code:not(.inline) {
|
|
193
194
|
/* block code: traditional no-wrap, horizontal scroll */
|
|
@@ -199,7 +200,7 @@
|
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
code.wrap:not(.inline) {
|
|
202
|
-
/* unset what we set above, otherwise rely on
|
|
203
|
+
/* unset what we set above, otherwise rely on fuz_css base styles */
|
|
203
204
|
white-space: pre-wrap;
|
|
204
205
|
}
|
|
205
206
|
</style>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeHighlight.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/CodeHighlight.svelte"],"names":[],"mappings":"AAGA;;;;;OAKI;AACJ,OAAO,EAAY,KAAK,OAAO,EAAC,MAAM,QAAQ,CAAC;AAE/C,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAGxD,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEpE,OAAO,EAGL,KAAK,aAAa,EAClB,MAAM,wBAAwB,CAAC;AAEhC,KAAK,gBAAgB,GAAI,kBAAkB,CAAC,MAAM,CAAC,GAAG;IACrD,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrC,CAAC;
|
|
1
|
+
{"version":3,"file":"CodeHighlight.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/CodeHighlight.svelte"],"names":[],"mappings":"AAGA;;;;;OAKI;AACJ,OAAO,EAAY,KAAK,OAAO,EAAC,MAAM,QAAQ,CAAC;AAE/C,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAGxD,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEpE,OAAO,EAGL,KAAK,aAAa,EAClB,MAAM,wBAAwB,CAAC;AAEhC,KAAK,gBAAgB,GAAI,kBAAkB,CAAC,MAAM,CAAC,GAAG;IACrD,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrC,CAAC;AAiGH,QAAA,MAAM,aAAa,sDAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
|
package/dist/syntax_styler.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type AddSyntaxGrammar = (syntax_styler: SyntaxStyler) => void;
|
|
|
9
9
|
* @see LICENSE
|
|
10
10
|
*/
|
|
11
11
|
export declare class SyntaxStyler {
|
|
12
|
+
#private;
|
|
12
13
|
langs: Record<string, SyntaxGrammar | undefined>;
|
|
13
14
|
add_lang(id: string, grammar: SyntaxGrammarRaw, aliases?: Array<string>): void;
|
|
14
15
|
add_extended_lang(base_id: string, extension_id: string, extension: SyntaxGrammarRaw, aliases?: Array<string>): SyntaxGrammar;
|
|
@@ -165,23 +166,6 @@ export declare class SyntaxStyler {
|
|
|
165
166
|
* @returns the new grammar
|
|
166
167
|
*/
|
|
167
168
|
extend_grammar(base_id: string, extension: SyntaxGrammarRaw): SyntaxGrammar;
|
|
168
|
-
/**
|
|
169
|
-
* Normalize a single pattern to have consistent shape.
|
|
170
|
-
* This ensures all patterns have the same object shape for V8 optimization.
|
|
171
|
-
*/
|
|
172
|
-
private normalize_pattern;
|
|
173
|
-
/**
|
|
174
|
-
* Normalize a grammar to have consistent object shapes.
|
|
175
|
-
* This performs several optimizations:
|
|
176
|
-
* 1. Merges `rest` property into main grammar
|
|
177
|
-
* 2. Ensures all pattern values are arrays
|
|
178
|
-
* 3. Normalizes all pattern objects to have consistent shapes
|
|
179
|
-
* 4. Adds global flag to greedy patterns
|
|
180
|
-
*
|
|
181
|
-
* This is called once at registration time to avoid runtime overhead.
|
|
182
|
-
* @param visited - Set of grammar object IDs already normalized (for circular references)
|
|
183
|
-
*/
|
|
184
|
-
private normalize_grammar;
|
|
185
169
|
plugins: Record<string, any>;
|
|
186
170
|
hooks_before_tokenize: Array<HookBeforeTokenizeCallback>;
|
|
187
171
|
hooks_after_tokenize: Array<HookAfterTokenizeCallback>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax_styler.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/syntax_styler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,KAAK,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAGtE,MAAM,MAAM,gBAAgB,GAAG,CAAC,aAAa,EAAE,YAAY,KAAK,IAAI,CAAC;AAErE;;;;;;;GAOG;AACH,qBAAa,YAAY
|
|
1
|
+
{"version":3,"file":"syntax_styler.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/syntax_styler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,KAAK,iBAAiB,EAAC,MAAM,mBAAmB,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,KAAK,CAAC,MAAM,CAAC,CAAC;IACrB,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAwBtE,MAAM,MAAM,0BAA0B,GAAG,CAAC,GAAG,EAAE,iCAAiC,KAAK,IAAI,CAAC;AAC1F,MAAM,MAAM,yBAAyB,GAAG,CAAC,GAAG,EAAE,gCAAgC,KAAK,IAAI,CAAC;AACxF,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,uBAAuB,KAAK,IAAI,CAAC;AAEtE,MAAM,WAAW,iCAAiC;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,CAAC;CAClB;AACD,MAAM,WAAW,gCAAgC;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;CAC1B;AACD,MAAM,WAAW,uBAAuB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC;CACb"}
|
package/dist/syntax_styler.js
CHANGED
|
@@ -30,7 +30,7 @@ export class SyntaxStyler {
|
|
|
30
30
|
add_lang(id, grammar, aliases) {
|
|
31
31
|
// Normalize grammar once at registration for optimal runtime performance
|
|
32
32
|
// Use a visited set to handle circular references
|
|
33
|
-
this
|
|
33
|
+
this.#normalize_grammar(grammar, new Set());
|
|
34
34
|
// After normalization, grammar has the shape of SyntaxGrammar
|
|
35
35
|
const normalized = grammar;
|
|
36
36
|
this.langs[id] = normalized;
|
|
@@ -207,7 +207,7 @@ export class SyntaxStyler {
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
// Normalize the updated grammar to ensure inserted patterns have consistent shape
|
|
210
|
-
this
|
|
210
|
+
this.#normalize_grammar(updated, new Set());
|
|
211
211
|
// After normalization, cast to SyntaxGrammar
|
|
212
212
|
const normalized = updated;
|
|
213
213
|
var old = root[inside];
|
|
@@ -296,7 +296,7 @@ export class SyntaxStyler {
|
|
|
296
296
|
// Merge normalized base with un-normalized extension
|
|
297
297
|
const extended = { ...structuredClone(this.get_lang(base_id)), ...extension };
|
|
298
298
|
// Normalize the extension parts
|
|
299
|
-
this
|
|
299
|
+
this.#normalize_grammar(extended, new Set());
|
|
300
300
|
// Return as SyntaxGrammar
|
|
301
301
|
return extended;
|
|
302
302
|
}
|
|
@@ -304,7 +304,7 @@ export class SyntaxStyler {
|
|
|
304
304
|
* Normalize a single pattern to have consistent shape.
|
|
305
305
|
* This ensures all patterns have the same object shape for V8 optimization.
|
|
306
306
|
*/
|
|
307
|
-
normalize_pattern(pattern, visited) {
|
|
307
|
+
#normalize_pattern(pattern, visited) {
|
|
308
308
|
const p = pattern instanceof RegExp ? { pattern } : pattern;
|
|
309
309
|
let regex = p.pattern;
|
|
310
310
|
// Add global flag if greedy and not already present
|
|
@@ -320,7 +320,7 @@ export class SyntaxStyler {
|
|
|
320
320
|
// Recursively normalize the inside grammar if present
|
|
321
321
|
let normalized_inside = null;
|
|
322
322
|
if (p.inside) {
|
|
323
|
-
this
|
|
323
|
+
this.#normalize_grammar(p.inside, visited);
|
|
324
324
|
// After normalization, cast to SyntaxGrammar
|
|
325
325
|
normalized_inside = p.inside;
|
|
326
326
|
}
|
|
@@ -343,7 +343,7 @@ export class SyntaxStyler {
|
|
|
343
343
|
* This is called once at registration time to avoid runtime overhead.
|
|
344
344
|
* @param visited - Set of grammar object IDs already normalized (for circular references)
|
|
345
345
|
*/
|
|
346
|
-
normalize_grammar(grammar, visited) {
|
|
346
|
+
#normalize_grammar(grammar, visited) {
|
|
347
347
|
// Check if we've already normalized this grammar (circular reference)
|
|
348
348
|
const grammar_id = id_of(grammar);
|
|
349
349
|
if (visited.has(grammar_id)) {
|
|
@@ -371,7 +371,7 @@ export class SyntaxStyler {
|
|
|
371
371
|
}
|
|
372
372
|
// Always store as array of normalized patterns
|
|
373
373
|
const patterns = Array.isArray(value) ? value : [value];
|
|
374
|
-
grammar[key] = patterns.map((p) => this
|
|
374
|
+
grammar[key] = patterns.map((p) => this.#normalize_pattern(p, visited));
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
377
|
// TODO add some builtins
|
package/dist/theme_variables.css
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fuzdev/fuz_code",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"description": "syntax styling utilities and components for TypeScript, Svelte, and Markdown",
|
|
5
5
|
"glyph": "🎨",
|
|
6
6
|
"logo": "logo.svg",
|
|
7
7
|
"logo_alt": "a friendly pink spider facing you",
|
|
8
|
-
"public": true,
|
|
9
8
|
"license": "MIT",
|
|
10
9
|
"homepage": "https://code.fuz.dev/",
|
|
11
10
|
"repository": "https://github.com/fuzdev/fuz_code",
|
|
@@ -24,16 +23,16 @@
|
|
|
24
23
|
"test": "gro test",
|
|
25
24
|
"preview": "vite preview",
|
|
26
25
|
"deploy": "gro deploy",
|
|
27
|
-
"benchmark": "gro run benchmark/run_benchmarks.ts",
|
|
28
|
-
"benchmark
|
|
29
|
-
"update
|
|
26
|
+
"benchmark": "gro run src/benchmark/run_benchmarks.ts",
|
|
27
|
+
"benchmark:compare": "gro run src/benchmark/compare/run_compare.ts",
|
|
28
|
+
"fixtures:update": "gro src/test/fixtures/update"
|
|
30
29
|
},
|
|
31
30
|
"type": "module",
|
|
32
31
|
"engines": {
|
|
33
32
|
"node": ">=22.15"
|
|
34
33
|
},
|
|
35
34
|
"peerDependencies": {
|
|
36
|
-
"@fuzdev/fuz_css": ">=0.
|
|
35
|
+
"@fuzdev/fuz_css": ">=0.44.1",
|
|
37
36
|
"svelte": "^5"
|
|
38
37
|
},
|
|
39
38
|
"peerDependenciesMeta": {
|
|
@@ -46,24 +45,24 @@
|
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
47
|
"@changesets/changelog-git": "^0.2.1",
|
|
49
|
-
"@fuzdev/fuz_css": "^0.
|
|
50
|
-
"@fuzdev/fuz_ui": "^0.
|
|
51
|
-
"@fuzdev/fuz_util": "^0.
|
|
48
|
+
"@fuzdev/fuz_css": "^0.44.1",
|
|
49
|
+
"@fuzdev/fuz_ui": "^0.178.2",
|
|
50
|
+
"@fuzdev/fuz_util": "^0.45.3",
|
|
52
51
|
"@ryanatkn/eslint-config": "^0.9.0",
|
|
53
|
-
"@ryanatkn/gro": "^0.
|
|
52
|
+
"@ryanatkn/gro": "^0.186.0",
|
|
54
53
|
"@sveltejs/adapter-static": "^3.0.10",
|
|
55
54
|
"@sveltejs/kit": "^2.49.1",
|
|
56
55
|
"@sveltejs/package": "^2.5.7",
|
|
57
56
|
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
|
58
57
|
"@types/node": "^24.10.1",
|
|
58
|
+
"@webref/css": "^8.2.0",
|
|
59
59
|
"eslint": "^9.39.1",
|
|
60
60
|
"eslint-plugin-svelte": "^3.13.1",
|
|
61
61
|
"esm-env": "^1.2.2",
|
|
62
62
|
"prettier": "^3.7.4",
|
|
63
|
-
"prettier-plugin-svelte": "^3.4.
|
|
63
|
+
"prettier-plugin-svelte": "^3.4.1",
|
|
64
64
|
"svelte": "^5.45.6",
|
|
65
65
|
"svelte-check": "^4.3.4",
|
|
66
|
-
"tinybench": "^6.0.0",
|
|
67
66
|
"tslib": "^2.8.1",
|
|
68
67
|
"typescript": "^5.9.3",
|
|
69
68
|
"typescript-eslint": "^8.48.1",
|
package/src/lib/syntax_styler.ts
CHANGED
|
@@ -35,7 +35,7 @@ export class SyntaxStyler {
|
|
|
35
35
|
add_lang(id: string, grammar: SyntaxGrammarRaw, aliases?: Array<string>): void {
|
|
36
36
|
// Normalize grammar once at registration for optimal runtime performance
|
|
37
37
|
// Use a visited set to handle circular references
|
|
38
|
-
this
|
|
38
|
+
this.#normalize_grammar(grammar, new Set());
|
|
39
39
|
// After normalization, grammar has the shape of SyntaxGrammar
|
|
40
40
|
const normalized = grammar as unknown as SyntaxGrammar;
|
|
41
41
|
this.langs[id] = normalized;
|
|
@@ -233,7 +233,7 @@ export class SyntaxStyler {
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
// Normalize the updated grammar to ensure inserted patterns have consistent shape
|
|
236
|
-
this
|
|
236
|
+
this.#normalize_grammar(updated, new Set());
|
|
237
237
|
|
|
238
238
|
// After normalization, cast to SyntaxGrammar
|
|
239
239
|
const normalized = updated as unknown as SyntaxGrammar;
|
|
@@ -334,7 +334,7 @@ export class SyntaxStyler {
|
|
|
334
334
|
// Merge normalized base with un-normalized extension
|
|
335
335
|
const extended = {...structuredClone(this.get_lang(base_id)), ...extension};
|
|
336
336
|
// Normalize the extension parts
|
|
337
|
-
this
|
|
337
|
+
this.#normalize_grammar(extended as SyntaxGrammarRaw, new Set());
|
|
338
338
|
// Return as SyntaxGrammar
|
|
339
339
|
return extended as unknown as SyntaxGrammar;
|
|
340
340
|
}
|
|
@@ -343,7 +343,7 @@ export class SyntaxStyler {
|
|
|
343
343
|
* Normalize a single pattern to have consistent shape.
|
|
344
344
|
* This ensures all patterns have the same object shape for V8 optimization.
|
|
345
345
|
*/
|
|
346
|
-
|
|
346
|
+
#normalize_pattern(
|
|
347
347
|
pattern: RegExp | SyntaxGrammarTokenRaw,
|
|
348
348
|
visited: Set<number>,
|
|
349
349
|
): SyntaxGrammarToken {
|
|
@@ -366,7 +366,7 @@ export class SyntaxStyler {
|
|
|
366
366
|
// Recursively normalize the inside grammar if present
|
|
367
367
|
let normalized_inside: SyntaxGrammar | null = null;
|
|
368
368
|
if (p.inside) {
|
|
369
|
-
this
|
|
369
|
+
this.#normalize_grammar(p.inside, visited);
|
|
370
370
|
// After normalization, cast to SyntaxGrammar
|
|
371
371
|
normalized_inside = p.inside as unknown as SyntaxGrammar;
|
|
372
372
|
}
|
|
@@ -391,7 +391,7 @@ export class SyntaxStyler {
|
|
|
391
391
|
* This is called once at registration time to avoid runtime overhead.
|
|
392
392
|
* @param visited - Set of grammar object IDs already normalized (for circular references)
|
|
393
393
|
*/
|
|
394
|
-
|
|
394
|
+
#normalize_grammar(grammar: SyntaxGrammarRaw, visited: Set<number>): void {
|
|
395
395
|
// Check if we've already normalized this grammar (circular reference)
|
|
396
396
|
const grammar_id = id_of(grammar);
|
|
397
397
|
if (visited.has(grammar_id)) {
|
|
@@ -422,7 +422,7 @@ export class SyntaxStyler {
|
|
|
422
422
|
|
|
423
423
|
// Always store as array of normalized patterns
|
|
424
424
|
const patterns = Array.isArray(value) ? value : [value];
|
|
425
|
-
grammar[key] = patterns.map((p) => this
|
|
425
|
+
grammar[key] = patterns.map((p) => this.#normalize_pattern(p, visited));
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
428
|
|