@fuzdev/fuz_code 0.44.1 → 0.45.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/dist/highlight_manager.d.ts +9 -1
- package/dist/highlight_manager.d.ts.map +1 -1
- package/dist/highlight_manager.js +9 -1
- package/dist/highlight_priorities.gen.d.ts +1 -1
- package/dist/highlight_priorities.gen.d.ts.map +1 -1
- package/dist/svelte_preprocess_fuz_code.d.ts +20 -0
- package/dist/svelte_preprocess_fuz_code.d.ts.map +1 -1
- package/dist/svelte_preprocess_fuz_code.js +17 -0
- package/dist/syntax_styler.d.ts +6 -0
- package/dist/syntax_styler.d.ts.map +1 -1
- package/dist/syntax_styler.js +6 -0
- package/dist/syntax_styler_global.d.ts +10 -0
- package/dist/syntax_styler_global.d.ts.map +1 -1
- package/dist/syntax_styler_global.js +10 -0
- package/dist/tokenize_syntax.d.ts +2 -0
- package/dist/tokenize_syntax.d.ts.map +1 -1
- package/dist/tokenize_syntax.js +2 -0
- package/package.json +10 -5
- package/src/lib/highlight_manager.ts +9 -1
- package/src/lib/highlight_priorities.gen.ts +1 -1
- package/src/lib/svelte_preprocess_fuz_code.ts +20 -0
- package/src/lib/syntax_styler.ts +6 -0
- package/src/lib/syntax_styler_global.ts +10 -0
- package/src/lib/tokenize_syntax.ts +2 -0
|
@@ -5,8 +5,16 @@ export type HighlightMode = 'auto' | 'ranges' | 'html';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare const supports_css_highlight_api: () => boolean;
|
|
7
7
|
/**
|
|
8
|
-
* Manages
|
|
8
|
+
* Manages CSS Custom Highlight API ranges for a single element.
|
|
9
9
|
* Tracks ranges per element and only removes its own ranges when clearing.
|
|
10
|
+
*
|
|
11
|
+
* **Experimental** — limited browser support. Use `Code` for production.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const manager = new HighlightManager();
|
|
16
|
+
* manager.highlight_from_syntax_tokens(element, tokens);
|
|
17
|
+
* ```
|
|
10
18
|
*/
|
|
11
19
|
export declare class HighlightManager {
|
|
12
20
|
#private;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"highlight_manager.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/highlight_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAGzD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEvD;;GAEG;AACH,eAAO,MAAM,0BAA0B,QAAO,OACS,CAAC;AAExD
|
|
1
|
+
{"version":3,"file":"highlight_manager.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/highlight_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAGzD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEvD;;GAEG;AACH,eAAO,MAAM,0BAA0B,QAAO,OACS,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,qBAAa,gBAAgB;;IAC5B,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;;IAS1C;;OAEG;IACH,4BAA4B,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAkD/E;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAmB5B,OAAO,IAAI,IAAI;CAiFf"}
|
|
@@ -4,8 +4,16 @@ import { highlight_priorities } from './highlight_priorities.js';
|
|
|
4
4
|
*/
|
|
5
5
|
export const supports_css_highlight_api = () => !!(globalThis.CSS?.highlights && globalThis.Highlight); // eslint-disable-line @typescript-eslint/no-unnecessary-condition
|
|
6
6
|
/**
|
|
7
|
-
* Manages
|
|
7
|
+
* Manages CSS Custom Highlight API ranges for a single element.
|
|
8
8
|
* Tracks ranges per element and only removes its own ranges when clearing.
|
|
9
|
+
*
|
|
10
|
+
* **Experimental** — limited browser support. Use `Code` for production.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const manager = new HighlightManager();
|
|
15
|
+
* manager.highlight_from_syntax_tokens(element, tokens);
|
|
16
|
+
* ```
|
|
9
17
|
*/
|
|
10
18
|
export class HighlightManager {
|
|
11
19
|
element_ranges;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"highlight_priorities.gen.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/highlight_priorities.gen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"highlight_priorities.gen.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/highlight_priorities.gen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,aAAa,CAAC;AAKrC,cAAc;AACd,eAAO,MAAM,GAAG,EAAE,GAgEjB,CAAC"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type PreprocessorGroup } from 'svelte/compiler';
|
|
2
2
|
import type { SyntaxStyler } from './syntax_styler.js';
|
|
3
|
+
/**
|
|
4
|
+
* Options for `svelte_preprocess_fuz_code`.
|
|
5
|
+
*/
|
|
3
6
|
export interface PreprocessFuzCodeOptions {
|
|
4
7
|
/** File patterns to exclude. */
|
|
5
8
|
exclude?: Array<string | RegExp>;
|
|
@@ -20,5 +23,22 @@ export interface PreprocessFuzCodeOptions {
|
|
|
20
23
|
*/
|
|
21
24
|
on_error?: 'log' | 'throw';
|
|
22
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Svelte preprocessor that compiles static `Code` component content at build time,
|
|
28
|
+
* replacing runtime syntax highlighting with pre-rendered HTML.
|
|
29
|
+
*
|
|
30
|
+
* @param options preprocessor configuration
|
|
31
|
+
* @returns a Svelte preprocessor group
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* // svelte.config.js
|
|
36
|
+
* import {svelte_preprocess_fuz_code} from './svelte_preprocess_fuz_code.js';
|
|
37
|
+
*
|
|
38
|
+
* export default {
|
|
39
|
+
* preprocess: [svelte_preprocess_fuz_code(), vitePreprocess()],
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
23
43
|
export declare const svelte_preprocess_fuz_code: (options?: PreprocessFuzCodeOptions) => PreprocessorGroup;
|
|
24
44
|
//# sourceMappingURL=svelte_preprocess_fuz_code.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svelte_preprocess_fuz_code.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/svelte_preprocess_fuz_code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,iBAAiB,EAAW,MAAM,iBAAiB,CAAC;AAgBxE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,wBAAwB;IACxC,gCAAgC;IAChC,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAEjC,0DAA0D;IAC1D,aAAa,CAAC,EAAE,YAAY,CAAC;IAE7B,8CAA8C;IAC9C,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAElC;;;OAGG;IACH,QAAQ,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;CAC3B;AAED,eAAO,MAAM,0BAA0B,GACtC,UAAS,wBAA6B,KACpC,iBA6DF,CAAC"}
|
|
1
|
+
{"version":3,"file":"svelte_preprocess_fuz_code.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/svelte_preprocess_fuz_code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,iBAAiB,EAAW,MAAM,iBAAiB,CAAC;AAgBxE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC,gCAAgC;IAChC,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAEjC,0DAA0D;IAC1D,aAAa,CAAC,EAAE,YAAY,CAAC;IAE7B,8CAA8C;IAC9C,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAElC;;;OAGG;IACH,QAAQ,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,0BAA0B,GACtC,UAAS,wBAA6B,KACpC,iBA6DF,CAAC"}
|
|
@@ -5,6 +5,23 @@ import { should_exclude_path } from '@fuzdev/fuz_util/path.js';
|
|
|
5
5
|
import { escape_js_string } from '@fuzdev/fuz_util/string.js';
|
|
6
6
|
import { find_attribute, extract_static_string, try_extract_conditional_chain, build_static_bindings, resolve_component_names, handle_preprocess_error, } from '@fuzdev/fuz_util/svelte_preprocess_helpers.js';
|
|
7
7
|
import { syntax_styler_global } from './syntax_styler_global.js';
|
|
8
|
+
/**
|
|
9
|
+
* Svelte preprocessor that compiles static `Code` component content at build time,
|
|
10
|
+
* replacing runtime syntax highlighting with pre-rendered HTML.
|
|
11
|
+
*
|
|
12
|
+
* @param options preprocessor configuration
|
|
13
|
+
* @returns a Svelte preprocessor group
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // svelte.config.js
|
|
18
|
+
* import {svelte_preprocess_fuz_code} from './svelte_preprocess_fuz_code.js';
|
|
19
|
+
*
|
|
20
|
+
* export default {
|
|
21
|
+
* preprocess: [svelte_preprocess_fuz_code(), vitePreprocess()],
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
8
25
|
export const svelte_preprocess_fuz_code = (options = {}) => {
|
|
9
26
|
const { exclude = [], syntax_styler = syntax_styler_global, cache = true, component_imports = ['@fuzdev/fuz_code/Code.svelte'], on_error = process.env.CI === 'true' ? 'throw' : 'log', } = options;
|
|
10
27
|
// In-memory cache: content+lang hash → highlighted HTML
|
package/dist/syntax_styler.d.ts
CHANGED
|
@@ -46,18 +46,24 @@ export declare class SyntaxStyler {
|
|
|
46
46
|
* @returns HTML string with syntax highlighting using CSS classes (`.token_*`)
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
49
|
+
* ```ts
|
|
49
50
|
* // Standard usage - uses registered grammar
|
|
50
51
|
* stylize('var foo = true;', 'ts');
|
|
52
|
+
* ```
|
|
51
53
|
*
|
|
52
54
|
* @example
|
|
55
|
+
* ```ts
|
|
53
56
|
* // Custom grammar - overrides registered grammar
|
|
54
57
|
* const customGrammar = { keyword: [...], string: [...] };
|
|
55
58
|
* stylize('var foo = false;', 'ts', customGrammar);
|
|
59
|
+
* ```
|
|
56
60
|
*
|
|
57
61
|
* @example
|
|
62
|
+
* ```ts
|
|
58
63
|
* // Extended grammar - builds on existing grammar
|
|
59
64
|
* const extended = this.extend_grammar('ts', { customToken: [...] });
|
|
60
65
|
* stylize('var foo = 42;', 'ts-extended', extended);
|
|
66
|
+
* ```
|
|
61
67
|
*/
|
|
62
68
|
stylize(text: string, lang: string, grammar?: SyntaxGrammar | undefined): string;
|
|
63
69
|
/**
|
|
@@ -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;;IACxB,KAAK,EAAE,MAAM,C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;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
|
@@ -91,18 +91,24 @@ export class SyntaxStyler {
|
|
|
91
91
|
* @returns HTML string with syntax highlighting using CSS classes (`.token_*`)
|
|
92
92
|
*
|
|
93
93
|
* @example
|
|
94
|
+
* ```ts
|
|
94
95
|
* // Standard usage - uses registered grammar
|
|
95
96
|
* stylize('var foo = true;', 'ts');
|
|
97
|
+
* ```
|
|
96
98
|
*
|
|
97
99
|
* @example
|
|
100
|
+
* ```ts
|
|
98
101
|
* // Custom grammar - overrides registered grammar
|
|
99
102
|
* const customGrammar = { keyword: [...], string: [...] };
|
|
100
103
|
* stylize('var foo = false;', 'ts', customGrammar);
|
|
104
|
+
* ```
|
|
101
105
|
*
|
|
102
106
|
* @example
|
|
107
|
+
* ```ts
|
|
103
108
|
* // Extended grammar - builds on existing grammar
|
|
104
109
|
* const extended = this.extend_grammar('ts', { customToken: [...] });
|
|
105
110
|
* stylize('var foo = 42;', 'ts-extended', extended);
|
|
111
|
+
* ```
|
|
106
112
|
*/
|
|
107
113
|
stylize(text, lang, grammar = this.get_lang(lang)) {
|
|
108
114
|
var ctx = {
|
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import { SyntaxStyler } from './syntax_styler.js';
|
|
2
|
+
/**
|
|
3
|
+
* Pre-configured `SyntaxStyler` instance with all built-in grammars registered.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import {syntax_styler_global} from './syntax_styler_global.js';
|
|
8
|
+
*
|
|
9
|
+
* const html = syntax_styler_global.stylize('const x = 1;', 'ts');
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
2
12
|
export declare const syntax_styler_global: SyntaxStyler;
|
|
3
13
|
//# sourceMappingURL=syntax_styler_global.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax_styler_global.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/syntax_styler_global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAUhD,eAAO,MAAM,oBAAoB,cAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"syntax_styler_global.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/syntax_styler_global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAUhD;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,cAAqB,CAAC"}
|
|
@@ -7,6 +7,16 @@ import { add_grammar_ts } from './grammar_ts.js';
|
|
|
7
7
|
import { add_grammar_svelte } from './grammar_svelte.js';
|
|
8
8
|
import { add_grammar_json } from './grammar_json.js';
|
|
9
9
|
import { add_grammar_markdown } from './grammar_markdown.js';
|
|
10
|
+
/**
|
|
11
|
+
* Pre-configured `SyntaxStyler` instance with all built-in grammars registered.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import {syntax_styler_global} from './syntax_styler_global.js';
|
|
16
|
+
*
|
|
17
|
+
* const html = syntax_styler_global.stylize('const x = 1;', 'ts');
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
10
20
|
export const syntax_styler_global = new SyntaxStyler();
|
|
11
21
|
add_grammar_markup(syntax_styler_global);
|
|
12
22
|
add_grammar_css(syntax_styler_global);
|
|
@@ -16,6 +16,7 @@ import { type SyntaxTokenStream } from './syntax_token.js';
|
|
|
16
16
|
* @returns an array of strings and tokens, a token stream
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
|
+
* ```ts
|
|
19
20
|
* var code = `var foo = 0;`;
|
|
20
21
|
* var tokens = tokenize_syntax(code, SyntaxStyler.langs.js);
|
|
21
22
|
* for (var token of tokens) {
|
|
@@ -23,6 +24,7 @@ import { type SyntaxTokenStream } from './syntax_token.js';
|
|
|
23
24
|
* console.log(`Found numeric literal: ${token.content}`);
|
|
24
25
|
* }
|
|
25
26
|
* }
|
|
27
|
+
* ```
|
|
26
28
|
*/
|
|
27
29
|
export declare const tokenize_syntax: (text: string, grammar: SyntaxGrammar) => SyntaxTokenStream;
|
|
28
30
|
//# sourceMappingURL=tokenize_syntax.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenize_syntax.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/tokenize_syntax.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAc,KAAK,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAEtE
|
|
1
|
+
{"version":3,"file":"tokenize_syntax.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/tokenize_syntax.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAc,KAAK,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,SAAS,aAAa,KAAG,iBAQtE,CAAC"}
|
package/dist/tokenize_syntax.js
CHANGED
|
@@ -15,6 +15,7 @@ import { SyntaxToken } from './syntax_token.js';
|
|
|
15
15
|
* @returns an array of strings and tokens, a token stream
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
|
+
* ```ts
|
|
18
19
|
* var code = `var foo = 0;`;
|
|
19
20
|
* var tokens = tokenize_syntax(code, SyntaxStyler.langs.js);
|
|
20
21
|
* for (var token of tokens) {
|
|
@@ -22,6 +23,7 @@ import { SyntaxToken } from './syntax_token.js';
|
|
|
22
23
|
* console.log(`Found numeric literal: ${token.content}`);
|
|
23
24
|
* }
|
|
24
25
|
* }
|
|
26
|
+
* ```
|
|
25
27
|
*/
|
|
26
28
|
export const tokenize_syntax = (text, grammar) => {
|
|
27
29
|
// Grammar is already normalized (rest merged, patterns in arrays, etc.)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fuzdev/fuz_code",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0",
|
|
4
4
|
"description": "syntax styling utilities and components for TypeScript, Svelte, and Markdown",
|
|
5
5
|
"glyph": "🎨",
|
|
6
6
|
"logo": "logo.svg",
|
|
@@ -58,15 +58,18 @@
|
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@changesets/changelog-git": "^0.2.1",
|
|
61
|
-
"@fuzdev/fuz_css": "^0.
|
|
62
|
-
"@fuzdev/fuz_ui": "^0.
|
|
63
|
-
"@fuzdev/fuz_util": "^0.50.
|
|
61
|
+
"@fuzdev/fuz_css": "^0.48.0",
|
|
62
|
+
"@fuzdev/fuz_ui": "^0.182.1",
|
|
63
|
+
"@fuzdev/fuz_util": "^0.50.1",
|
|
64
|
+
"@fuzdev/gro": "^0.192.1",
|
|
65
|
+
"@jridgewell/trace-mapping": "^0.3.31",
|
|
64
66
|
"@ryanatkn/eslint-config": "^0.9.0",
|
|
65
67
|
"@ryanatkn/gro": "^0.191.0",
|
|
66
68
|
"@sveltejs/adapter-static": "^3.0.10",
|
|
67
69
|
"@sveltejs/kit": "^2.50.1",
|
|
68
70
|
"@sveltejs/package": "^2.5.7",
|
|
69
71
|
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
|
72
|
+
"@types/estree": "^1.0.8",
|
|
70
73
|
"@types/node": "^24.10.1",
|
|
71
74
|
"@webref/css": "^8.2.0",
|
|
72
75
|
"eslint": "^9.39.1",
|
|
@@ -77,11 +80,13 @@
|
|
|
77
80
|
"prettier-plugin-svelte": "^3.4.1",
|
|
78
81
|
"svelte": "^5.49.1",
|
|
79
82
|
"svelte-check": "^4.3.6",
|
|
83
|
+
"svelte2tsx": "^0.7.47",
|
|
80
84
|
"tslib": "^2.8.1",
|
|
81
85
|
"typescript": "^5.9.3",
|
|
82
86
|
"typescript-eslint": "^8.48.1",
|
|
83
87
|
"vitest": "^4.0.15",
|
|
84
|
-
"zimmerframe": "^1.1.4"
|
|
88
|
+
"zimmerframe": "^1.1.4",
|
|
89
|
+
"zod": "^4.3.6"
|
|
85
90
|
},
|
|
86
91
|
"prettier": {
|
|
87
92
|
"plugins": [
|
|
@@ -10,8 +10,16 @@ export const supports_css_highlight_api = (): boolean =>
|
|
|
10
10
|
!!(globalThis.CSS?.highlights && globalThis.Highlight); // eslint-disable-line @typescript-eslint/no-unnecessary-condition
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Manages
|
|
13
|
+
* Manages CSS Custom Highlight API ranges for a single element.
|
|
14
14
|
* Tracks ranges per element and only removes its own ranges when clearing.
|
|
15
|
+
*
|
|
16
|
+
* **Experimental** — limited browser support. Use `Code` for production.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const manager = new HighlightManager();
|
|
21
|
+
* manager.highlight_from_syntax_tokens(element, tokens);
|
|
22
|
+
* ```
|
|
15
23
|
*/
|
|
16
24
|
export class HighlightManager {
|
|
17
25
|
element_ranges: Map<string, Array<Range>>;
|
|
@@ -16,6 +16,9 @@ import {
|
|
|
16
16
|
import {syntax_styler_global} from './syntax_styler_global.js';
|
|
17
17
|
import type {SyntaxStyler} from './syntax_styler.js';
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Options for `svelte_preprocess_fuz_code`.
|
|
21
|
+
*/
|
|
19
22
|
export interface PreprocessFuzCodeOptions {
|
|
20
23
|
/** File patterns to exclude. */
|
|
21
24
|
exclude?: Array<string | RegExp>;
|
|
@@ -41,6 +44,23 @@ export interface PreprocessFuzCodeOptions {
|
|
|
41
44
|
on_error?: 'log' | 'throw';
|
|
42
45
|
}
|
|
43
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Svelte preprocessor that compiles static `Code` component content at build time,
|
|
49
|
+
* replacing runtime syntax highlighting with pre-rendered HTML.
|
|
50
|
+
*
|
|
51
|
+
* @param options preprocessor configuration
|
|
52
|
+
* @returns a Svelte preprocessor group
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* // svelte.config.js
|
|
57
|
+
* import {svelte_preprocess_fuz_code} from '@fuzdev/fuz_code/svelte_preprocess_fuz_code.js';
|
|
58
|
+
*
|
|
59
|
+
* export default {
|
|
60
|
+
* preprocess: [svelte_preprocess_fuz_code(), vitePreprocess()],
|
|
61
|
+
* };
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
44
64
|
export const svelte_preprocess_fuz_code = (
|
|
45
65
|
options: PreprocessFuzCodeOptions = {},
|
|
46
66
|
): PreprocessorGroup => {
|
package/src/lib/syntax_styler.ts
CHANGED
|
@@ -104,18 +104,24 @@ export class SyntaxStyler {
|
|
|
104
104
|
* @returns HTML string with syntax highlighting using CSS classes (`.token_*`)
|
|
105
105
|
*
|
|
106
106
|
* @example
|
|
107
|
+
* ```ts
|
|
107
108
|
* // Standard usage - uses registered grammar
|
|
108
109
|
* stylize('var foo = true;', 'ts');
|
|
110
|
+
* ```
|
|
109
111
|
*
|
|
110
112
|
* @example
|
|
113
|
+
* ```ts
|
|
111
114
|
* // Custom grammar - overrides registered grammar
|
|
112
115
|
* const customGrammar = { keyword: [...], string: [...] };
|
|
113
116
|
* stylize('var foo = false;', 'ts', customGrammar);
|
|
117
|
+
* ```
|
|
114
118
|
*
|
|
115
119
|
* @example
|
|
120
|
+
* ```ts
|
|
116
121
|
* // Extended grammar - builds on existing grammar
|
|
117
122
|
* const extended = this.extend_grammar('ts', { customToken: [...] });
|
|
118
123
|
* stylize('var foo = 42;', 'ts-extended', extended);
|
|
124
|
+
* ```
|
|
119
125
|
*/
|
|
120
126
|
stylize(
|
|
121
127
|
text: string,
|
|
@@ -8,6 +8,16 @@ import {add_grammar_svelte} from './grammar_svelte.js';
|
|
|
8
8
|
import {add_grammar_json} from './grammar_json.js';
|
|
9
9
|
import {add_grammar_markdown} from './grammar_markdown.js';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Pre-configured `SyntaxStyler` instance with all built-in grammars registered.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import {syntax_styler_global} from '@fuzdev/fuz_code/syntax_styler_global.js';
|
|
17
|
+
*
|
|
18
|
+
* const html = syntax_styler_global.stylize('const x = 1;', 'ts');
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
11
21
|
export const syntax_styler_global = new SyntaxStyler();
|
|
12
22
|
|
|
13
23
|
add_grammar_markup(syntax_styler_global);
|
|
@@ -17,6 +17,7 @@ import {SyntaxToken, type SyntaxTokenStream} from './syntax_token.js';
|
|
|
17
17
|
* @returns an array of strings and tokens, a token stream
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
|
+
* ```ts
|
|
20
21
|
* var code = `var foo = 0;`;
|
|
21
22
|
* var tokens = tokenize_syntax(code, SyntaxStyler.langs.js);
|
|
22
23
|
* for (var token of tokens) {
|
|
@@ -24,6 +25,7 @@ import {SyntaxToken, type SyntaxTokenStream} from './syntax_token.js';
|
|
|
24
25
|
* console.log(`Found numeric literal: ${token.content}`);
|
|
25
26
|
* }
|
|
26
27
|
* }
|
|
28
|
+
* ```
|
|
27
29
|
*/
|
|
28
30
|
export const tokenize_syntax = (text: string, grammar: SyntaxGrammar): SyntaxTokenStream => {
|
|
29
31
|
// Grammar is already normalized (rest merged, patterns in arrays, etc.)
|