@fuzdev/fuz_code 0.37.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.
Files changed (76) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +185 -0
  3. package/dist/Code.svelte +146 -0
  4. package/dist/Code.svelte.d.ts +79 -0
  5. package/dist/Code.svelte.d.ts.map +1 -0
  6. package/dist/CodeHighlight.svelte +205 -0
  7. package/dist/CodeHighlight.svelte.d.ts +101 -0
  8. package/dist/CodeHighlight.svelte.d.ts.map +1 -0
  9. package/dist/code_sample.d.ts +8 -0
  10. package/dist/code_sample.d.ts.map +1 -0
  11. package/dist/code_sample.js +2 -0
  12. package/dist/grammar_clike.d.ts +12 -0
  13. package/dist/grammar_clike.d.ts.map +1 -0
  14. package/dist/grammar_clike.js +43 -0
  15. package/dist/grammar_css.d.ts +11 -0
  16. package/dist/grammar_css.d.ts.map +1 -0
  17. package/dist/grammar_css.js +70 -0
  18. package/dist/grammar_js.d.ts +11 -0
  19. package/dist/grammar_js.d.ts.map +1 -0
  20. package/dist/grammar_js.js +180 -0
  21. package/dist/grammar_json.d.ts +11 -0
  22. package/dist/grammar_json.d.ts.map +1 -0
  23. package/dist/grammar_json.js +35 -0
  24. package/dist/grammar_markdown.d.ts +8 -0
  25. package/dist/grammar_markdown.d.ts.map +1 -0
  26. package/dist/grammar_markdown.js +228 -0
  27. package/dist/grammar_markup.d.ts +31 -0
  28. package/dist/grammar_markup.d.ts.map +1 -0
  29. package/dist/grammar_markup.js +192 -0
  30. package/dist/grammar_svelte.d.ts +12 -0
  31. package/dist/grammar_svelte.d.ts.map +1 -0
  32. package/dist/grammar_svelte.js +150 -0
  33. package/dist/grammar_ts.d.ts +11 -0
  34. package/dist/grammar_ts.d.ts.map +1 -0
  35. package/dist/grammar_ts.js +95 -0
  36. package/dist/highlight_manager.d.ts +25 -0
  37. package/dist/highlight_manager.d.ts.map +1 -0
  38. package/dist/highlight_manager.js +139 -0
  39. package/dist/highlight_priorities.d.ts +3 -0
  40. package/dist/highlight_priorities.d.ts.map +1 -0
  41. package/dist/highlight_priorities.gen.d.ts +4 -0
  42. package/dist/highlight_priorities.gen.d.ts.map +1 -0
  43. package/dist/highlight_priorities.gen.js +58 -0
  44. package/dist/highlight_priorities.js +55 -0
  45. package/dist/syntax_styler.d.ts +277 -0
  46. package/dist/syntax_styler.d.ts.map +1 -0
  47. package/dist/syntax_styler.js +426 -0
  48. package/dist/syntax_styler_global.d.ts +3 -0
  49. package/dist/syntax_styler_global.d.ts.map +1 -0
  50. package/dist/syntax_styler_global.js +18 -0
  51. package/dist/syntax_token.d.ts +34 -0
  52. package/dist/syntax_token.d.ts.map +1 -0
  53. package/dist/syntax_token.js +27 -0
  54. package/dist/theme.css +98 -0
  55. package/dist/theme_highlight.css +160 -0
  56. package/dist/theme_variables.css +20 -0
  57. package/dist/tokenize_syntax.d.ts +28 -0
  58. package/dist/tokenize_syntax.d.ts.map +1 -0
  59. package/dist/tokenize_syntax.js +194 -0
  60. package/package.json +117 -0
  61. package/src/lib/code_sample.ts +10 -0
  62. package/src/lib/grammar_clike.ts +48 -0
  63. package/src/lib/grammar_css.ts +84 -0
  64. package/src/lib/grammar_js.ts +215 -0
  65. package/src/lib/grammar_json.ts +38 -0
  66. package/src/lib/grammar_markdown.ts +289 -0
  67. package/src/lib/grammar_markup.ts +225 -0
  68. package/src/lib/grammar_svelte.ts +165 -0
  69. package/src/lib/grammar_ts.ts +114 -0
  70. package/src/lib/highlight_manager.ts +182 -0
  71. package/src/lib/highlight_priorities.gen.ts +71 -0
  72. package/src/lib/highlight_priorities.ts +110 -0
  73. package/src/lib/syntax_styler.ts +583 -0
  74. package/src/lib/syntax_styler_global.ts +20 -0
  75. package/src/lib/syntax_token.ts +49 -0
  76. package/src/lib/tokenize_syntax.ts +270 -0
@@ -0,0 +1,71 @@
1
+ import type {Gen} from '@ryanatkn/gro';
2
+ import {readFileSync} from 'node:fs';
3
+
4
+ const theme_css_path = 'src/lib/theme_highlight.css';
5
+
6
+ /** @nodocs */
7
+ export const gen: Gen = {
8
+ dependencies: {files: [theme_css_path]},
9
+ generate: ({origin_path}) => {
10
+ // Read the theme_highlight.css file
11
+ let css_content = readFileSync(theme_css_path, 'utf-8');
12
+
13
+ // Strip CSS comments to avoid false positives
14
+ css_content = css_content.replace(/\/\*[\s\S]*?\*\//g, '');
15
+
16
+ // Extract ::highlight() rules by CSS rule blocks
17
+ const highlight_priorities: Record<string, number> = {};
18
+ let priority = 1;
19
+
20
+ // Split CSS into rule blocks (roughly by closing braces)
21
+ const rule_blocks = css_content.split('}');
22
+
23
+ for (const block of rule_blocks) {
24
+ // Find all ::highlight(token_name) declarations in this block
25
+ const highlight_regex = /::highlight\(([^)]+)\)/g;
26
+ const tokens_in_block: Array<string> = [];
27
+ let match;
28
+
29
+ while ((match = highlight_regex.exec(block)) !== null) {
30
+ const token_name = match[1]!;
31
+ if (!tokens_in_block.includes(token_name)) {
32
+ tokens_in_block.push(token_name);
33
+ }
34
+ }
35
+
36
+ // Assign the same priority to all tokens in this block
37
+ if (tokens_in_block.length > 0) {
38
+ for (const token_name of tokens_in_block) {
39
+ if (!Object.hasOwn(highlight_priorities, token_name)) {
40
+ highlight_priorities[token_name] = priority;
41
+ }
42
+ }
43
+ priority++;
44
+ }
45
+ }
46
+
47
+ const banner = `// generated by ${origin_path} - DO NOT EDIT OR RISK LOST DATA`;
48
+
49
+ // Generate priority entries
50
+ const priority_entries = Object.entries(highlight_priorities)
51
+ .map(([token, priority]) => `\t${token}: ${priority}`)
52
+ .join(',\n');
53
+
54
+ // Generate the type
55
+ const token_names = Object.keys(highlight_priorities)
56
+ .map((name) => `'${name}'`)
57
+ .join(' | ');
58
+
59
+ return `
60
+ ${banner}
61
+
62
+ export type HighlightTokenName = ${token_names};
63
+
64
+ export const highlight_priorities: Record<HighlightTokenName, number | undefined> = {
65
+ ${priority_entries},
66
+ } as const;
67
+
68
+ ${banner}
69
+ `;
70
+ },
71
+ };
@@ -0,0 +1,110 @@
1
+ // generated by src/lib/highlight_priorities.gen.ts - DO NOT EDIT OR RISK LOST DATA
2
+
3
+ export type HighlightTokenName =
4
+ | 'token_processing_instruction'
5
+ | 'token_doctype'
6
+ | 'token_cdata'
7
+ | 'token_punctuation'
8
+ | 'token_tag'
9
+ | 'token_constant'
10
+ | 'token_symbol'
11
+ | 'token_deleted'
12
+ | 'token_keyword'
13
+ | 'token_null'
14
+ | 'token_boolean'
15
+ | 'token_interpolation_punctuation'
16
+ | 'token_heading'
17
+ | 'token_heading_punctuation'
18
+ | 'token_tag_punctuation'
19
+ | 'token_comment'
20
+ | 'token_char'
21
+ | 'token_inserted'
22
+ | 'token_blockquote'
23
+ | 'token_blockquote_punctuation'
24
+ | 'token_builtin'
25
+ | 'token_class_name'
26
+ | 'token_number'
27
+ | 'token_attr_value'
28
+ | 'token_attr_quote'
29
+ | 'token_string'
30
+ | 'token_template_punctuation'
31
+ | 'token_inline_code'
32
+ | 'token_code_punctuation'
33
+ | 'token_attr_equals'
34
+ | 'token_selector'
35
+ | 'token_function'
36
+ | 'token_regex'
37
+ | 'token_important'
38
+ | 'token_variable'
39
+ | 'token_atrule'
40
+ | 'token_attr_name'
41
+ | 'token_property'
42
+ | 'token_decorator'
43
+ | 'token_decorator_name'
44
+ | 'token_link_text_wrapper'
45
+ | 'token_link_text'
46
+ | 'token_link_punctuation'
47
+ | 'token_special_keyword'
48
+ | 'token_namespace'
49
+ | 'token_rule'
50
+ | 'token_at_keyword'
51
+ | 'token_url'
52
+ | 'token_strikethrough'
53
+ | 'token_bold'
54
+ | 'token_italic';
55
+
56
+ export const highlight_priorities: Record<HighlightTokenName, number | undefined> = {
57
+ token_processing_instruction: 1,
58
+ token_doctype: 1,
59
+ token_cdata: 1,
60
+ token_punctuation: 1,
61
+ token_tag: 2,
62
+ token_constant: 2,
63
+ token_symbol: 2,
64
+ token_deleted: 2,
65
+ token_keyword: 2,
66
+ token_null: 2,
67
+ token_boolean: 2,
68
+ token_interpolation_punctuation: 2,
69
+ token_heading: 2,
70
+ token_heading_punctuation: 2,
71
+ token_tag_punctuation: 2,
72
+ token_comment: 3,
73
+ token_char: 3,
74
+ token_inserted: 3,
75
+ token_blockquote: 3,
76
+ token_blockquote_punctuation: 3,
77
+ token_builtin: 4,
78
+ token_class_name: 4,
79
+ token_number: 4,
80
+ token_attr_value: 5,
81
+ token_attr_quote: 5,
82
+ token_string: 5,
83
+ token_template_punctuation: 5,
84
+ token_inline_code: 5,
85
+ token_code_punctuation: 5,
86
+ token_attr_equals: 6,
87
+ token_selector: 7,
88
+ token_function: 7,
89
+ token_regex: 7,
90
+ token_important: 7,
91
+ token_variable: 7,
92
+ token_atrule: 8,
93
+ token_attr_name: 9,
94
+ token_property: 9,
95
+ token_decorator: 9,
96
+ token_decorator_name: 9,
97
+ token_link_text_wrapper: 9,
98
+ token_link_text: 9,
99
+ token_link_punctuation: 9,
100
+ token_special_keyword: 10,
101
+ token_namespace: 10,
102
+ token_rule: 10,
103
+ token_at_keyword: 11,
104
+ token_url: 11,
105
+ token_strikethrough: 13,
106
+ token_bold: 14,
107
+ token_italic: 15,
108
+ } as const;
109
+
110
+ // generated by src/lib/highlight_priorities.gen.ts - DO NOT EDIT OR RISK LOST DATA