@codady/coax 0.0.1 → 0.0.3

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 (43) hide show
  1. package/dist/coax.cjs.js +829 -140
  2. package/dist/coax.cjs.min.js +3 -3
  3. package/dist/coax.esm.js +823 -140
  4. package/dist/coax.esm.min.js +3 -3
  5. package/dist/coax.umd.js +849 -138
  6. package/dist/coax.umd.min.js +3 -3
  7. package/examples/.htaccess +0 -0
  8. package/examples/append-highlight.html +82 -0
  9. package/examples/color-selector.html +412 -0
  10. package/examples/css-highlight.html +2 -18
  11. package/examples/deepseek-highlight.html +91 -0
  12. package/examples/js-highlight.html +2 -17
  13. package/examples/md-highlight.html +60 -0
  14. package/examples/nginx.htaccess +0 -0
  15. package/examples/plain-highlight.html +47 -0
  16. package/examples/replace-highlight.html +69 -0
  17. package/examples/stream-highlight.html +64 -0
  18. package/examples/theme-highlight.html +69 -0
  19. package/package.json +19 -3
  20. package/rollup.config.js +3 -3
  21. package/src/Coax.js +50 -184
  22. package/src/Coax.ts +56 -207
  23. package/src/components/CoaxElem.js +457 -0
  24. package/src/components/CoaxElem.ts +488 -0
  25. package/src/modules.js +12 -0
  26. package/src/modules.ts +23 -0
  27. package/src/rules/css.js +11 -0
  28. package/src/rules/css.ts +11 -0
  29. package/src/rules/html.js +13 -0
  30. package/src/rules/html.ts +13 -0
  31. package/src/rules/javascript.js +10 -0
  32. package/src/rules/javascript.ts +10 -0
  33. package/src/rules/markdown.js +29 -0
  34. package/src/rules/markdown.ts +41 -0
  35. package/src/rules/ruleCss - /345/211/257/346/234/254.js" +10 -0
  36. package/src/rules/ruleHTML - /345/211/257/346/234/254.js" +12 -0
  37. package/src/rules/ruleJs - /345/211/257/346/234/254.js" +10 -0
  38. package/src/rules/ruleTs - /345/211/257/346/234/254.js" +12 -0
  39. package/src/rules/typescript.js +12 -0
  40. package/src/rules/typescript.ts +12 -0
  41. package/src/tools/copy.js +26 -0
  42. package/src/tools/copy.ts +29 -0
  43. package/tsconfig.json +2 -2
package/src/Coax.js CHANGED
@@ -1,192 +1,58 @@
1
1
  /**
2
- * Last modified: 2026/01/04 15:50:55
2
+ * Last modified: 2026/01/12 08:57:22
3
3
  */
4
- class Coax extends HTMLElement {
5
- // A static Map to hold the configuration for different languages
6
- static languages = new Map();
7
- // Raw code as text from the HTML content
8
- rawCode;
9
- constructor() {
10
- super();
11
- // Attach a Shadow DOM to the custom element
12
- this.attachShadow({ mode: 'open' });
13
- // Remove leading/trailing whitespace from the raw code content
14
- this.rawCode = this.textContent?.replace(/^\s*\n|\n\s*$/g, '') || '';
15
- }
16
- /**
17
- * Registers a new language with a set of syntax highlighting rules.
18
- * @param name - The name of the programming language.
19
- * @param config - Configuration for the language, including rules, theme, and optional CSS.
20
- */
21
- static register(name, { rules, theme = {}, internalCss = '', cssPrefix = '' }) {
22
- // Store the language configuration in the static map
23
- this.languages.set(name, { rules, theme, internalCss, cssPrefix });
24
- // Render the highlighted code for all elements with the registered language
25
- document.querySelectorAll('ax-code').forEach(el => {
26
- if (el.getAttribute('lang') === name)
27
- el.render();
28
- });
29
- }
30
- // Called when the element is connected to the DOM
31
- connectedCallback() { this.render(); }
32
- // Observed attributes for changes
33
- static get observedAttributes() { return ['lang', 'height', 'max-height']; }
34
- /**
35
- * Called when any of the observed attributes change.
36
- */
37
- attributeChangedCallback() {
38
- this.render();
39
- }
40
- /**
41
- * Renders the highlighted code within the shadow DOM.
42
- */
43
- render() {
44
- // Get language name, fallback to 'js' if not provided
45
- const lang = this.getAttribute('lang') || 'js',
46
- // Get the language configuration
47
- config = Coax.languages.get(lang),
48
- // Default to language name if no prefix is set
49
- cssPrefix = config?.cssPrefix || lang, height = this.getAttribute('height'), maxHeight = this.getAttribute('max-height');
50
- let highlightedCode = '', dynamicStyles = '';
51
- if (config) {
52
- //Generate the highlighted HTML by applying the syntax rules
53
- const combinedRegex = new RegExp(config.rules.map((r) => `(${r.reg.source})`).join('|'), 'g'), escaped = this.rawCode.replace(/[&<>]/g, m => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[m]));
54
- // Replace code with highlighted syntax
55
- highlightedCode = escaped.replace(combinedRegex, (match, ...args) => {
56
- const index = args.findIndex(val => val !== undefined);
57
- return index !== -1 && config.rules[index] ? `<span class="ax-${cssPrefix}-${config.rules[index].name}">${match}</span>` : match;
58
- });
59
- //Generate dynamic CSS classes for each syntax rule
60
- // 为 rules 中的每一个 name 生成类似 .hl-name { color: var(--ax-code-name); }
61
- dynamicStyles = config.rules.map((rule) => `
62
- .ax-${cssPrefix}-${rule.name} { color: var(--ax-${cssPrefix}-${rule.name}); }
63
- `).join('\n');
64
- }
65
- else {
66
- // If no config, display raw code without highlighting
67
- highlightedCode = this.rawCode;
68
- }
69
- //Generate CSS theme variables if a theme is provided
70
- const themeVars = config?.theme
71
- ? Object.entries(config.theme).map(([k, v]) => `--ax-${cssPrefix}-${k}: ${v};`).join('\n')
72
- : '';
73
- // Set the inner HTML of the shadow root, including styles and highlighted code
74
- this.shadowRoot.innerHTML = `
75
- <style>
76
- :host {
77
- ${themeVars}
78
-
79
- font-size: var(--ax-code-fs,14px);
80
- display: block;
81
- padding: var(--ax-code-p,1em);
82
- box-sizing:border-box;
83
- line-height: var(--ax-code-lh,1.5);
84
- background-color:var(--ax-code-bg,rgba(0,0,0,0.02));
85
- color:var(--ax-code-c,#333);
86
- border:var(--ax-code-bw,1px) solid var(--ax-code-bc,rgba(0,0,0,0.08));
87
- height:${height || 'var(--ax-code-h,auto)'};
88
- max-height:${maxHeight || 'var(--ax-code-mh,500px)'};
89
- overflow:auto;
90
- transition: border-color 0.3s ease,color 0.3s ease;
91
- border-radius: var(--ax-code-r,9px);
92
- }
93
- pre,code{
94
- font-family:"Consolas", "Monaco", "Andale Mono", "Ubuntu Mono", "monospace", "microsoft yahei", "Microsoft JhengHei", "Yu Mincho", "simsun";
95
- margin:0;
96
- padding:0;
97
- }
98
-
99
-
100
- /* Dynamically generated styles for syntax highlighting */
101
- ${dynamicStyles}
102
-
103
- /* Inject additional CSS specific to the language if provided */
104
- ${config?.internalCss || ''}
105
- </style>
106
- <pre><code>${highlightedCode}</code></pre>`;
107
- }
108
- }
109
- customElements.define('ax-code', Coax);
110
- Coax.register('html', {
111
- rules: [
112
- { name: 'comment', reg: /&lt;!--[\s\S]*?--&gt;/ },
113
- { name: 'doctype', reg: /&lt;!DOCTYPE[\s\S]*?&gt;/i },
114
- // 匹配标签名: <div, </div
115
- { name: 'tag', reg: /&lt;\/?[a-zA-Z0-9]+/ },
116
- // 匹配属性名: class=
117
- { name: 'attr', reg: /[a-zA-Z-]+(?=\s*=\s*)/ },
118
- // 匹配属性值: "value"
119
- { name: 'string', reg: /(['"])(?:\\.|[^\\])*?\1/ },
120
- // 匹配标签闭合: >, />
121
- { name: 'bracket', reg: /\/?&gt;/ }
122
- ],
123
- //添加root变量:--ax-html-keyword
124
- /* theme: {
125
- 'tag': '#e06c75', // 红色
126
- 'attr': '#d19a66', // 橙色
127
- 'bracket': '#abb2bf', // 灰色
128
- 'doctype': '#56b6c2' // 青色
129
- } */
130
- });
4
+ 'use strict';
5
+ import NAMESPACE from "@codady/utils/namespace";
6
+ import CoaxElem from "./components/CoaxElem.js";
7
+ import html from "./rules/html.js";
8
+ import javascript from "./rules/javascript.js";
9
+ import markdown from "./rules/markdown.js";
10
+ import typescript from "./rules/typescript.js";
11
+ import copy from "./tools/copy.js";
12
+ import css from "./rules/css.js";
13
+ const Coax = CoaxElem;
14
+ //注册语言类型
131
15
  Coax.register('css', {
132
- rules: [
133
- { name: 'comment', reg: /\/\*[\s\S]*?\*\// },
134
- { name: 'value', reg: /(?:'|")(?:\\.|[^\\'"\b])*?(?:'|")/ },
135
- { name: 'func', reg: /[a-z-]+\(?=/ },
136
- { name: 'property', reg: /[a-z-]+(?=\s*:)/ },
137
- { name: 'selector', reg: /[.#a-z0-9, \n\t>:+()_-]+(?=\s*\{)/i },
138
- { name: 'unit', reg: /(?<=\d)(px|em|rem|%|vh|vw|ms|s|deg)/ },
139
- { name: 'number', reg: /\b\d+(\.\d+)?\b/ },
140
- { name: 'punct', reg: /[{}();:]/ }
141
- ],
142
- //添加root变量:--ax-code-keyword
143
- theme: {
144
- 'type': '#61afef', // 蓝色选择器
145
- 'keyword': '#d19a66', // 橙色属性名
146
- 'string': '#98c379', // 绿色属性值
147
- 'op': '#abb2bf' // 灰色符号
148
- },
149
- internalCss: `
150
- .ax-css-string { color: var(--ax-code-string); }
151
- .ax-css-string::first-letter { color: var(--ax-code-c); }
152
- `
16
+ alias: 'CSS',
17
+ rules: css,
18
+ /* cssPrefix: 'css',
19
+ themeStyles: `
20
+ :host {
21
+ --background:rgba(0,0,0,0.02);
22
+ --border-color:rgba(0,0,0,0.08);
23
+ --color-code:#333;
24
+ }
25
+ :host([scheme="dark"]){
26
+ --background: #282c34;
27
+ --border-color: transparent;
28
+ --color-code: #abb2bf;
29
+ }
30
+ @media (prefers-color-scheme: dark) {
31
+ :host{
32
+ --background: #282c34;
33
+ --border-color: transparent;
34
+ --color-code: #abb2bf;
35
+ }
36
+ }
37
+ ` */
38
+ });
39
+ Coax.register('html', {
40
+ alias: 'HTML',
41
+ rules: html,
153
42
  });
154
43
  Coax.register('js', {
155
- rules: [
156
- { name: 'comment', reg: /\/\/[^\n]*|\/\*[\s\S]*?\*\// },
157
- { name: 'string', reg: /(?:'|"|`)(?:\\.|[^\\'"\b])*?(?:'|"|`)/ },
158
- { name: 'keyword', reg: /\b(async|await|break|case|catch|class|const|continue|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|while|with|yield|let|static)\b/ },
159
- { name: 'builtin', reg: /\b(console|window|document|Math|JSON|true|false|null|undefined|Object|Array|Promise)\b/ },
160
- { name: 'number', reg: /\b\d+\b/ },
161
- { name: 'func', reg: /\b[a-zA-Z_]\w*(?=\s*\()/ },
162
- { name: 'op', reg: /[+\-*/%=<>!&|^~]+/ }
163
- ],
164
- /* theme: {
165
- 'keyword': '#c678dd',
166
- 'func': '#61afef',
167
- 'builtin': '#e5c07b'
168
- } */
44
+ alias: 'Javascript',
45
+ rules: javascript,
169
46
  });
170
47
  Coax.register('ts', {
171
- rules: [
172
- { name: 'comment', reg: /\/\/[^\n]*|\/\*[\s\S]*?\*\// },
173
- { name: 'string', reg: /(?:'|"|`)(?:\\.|[^\\'"\b])*?(?:'|"|`)/ },
174
- { name: 'decorator', reg: /@[a-zA-Z_]\w*/ },
175
- { name: 'keyword', reg: /\b(abstract|as|async|await|break|case|catch|class|const|continue|debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|is|keyof|let|module|namespace|new|package|private|protected|public|readonly|return|set|static|super|switch|this|throw|try|type|typeof|var|while|with|yield)\b/ },
176
- { name: 'builtin', reg: /\b(any|boolean|never|number|string|symbol|unknown|void|undefined|null|boolean|true|false|console|window|document)\b/ },
177
- { name: 'type', reg: /\b[A-Z]\w*\b/ },
178
- { name: 'number', reg: /\b\d+\b/ },
179
- { name: 'func', reg: /\b[a-zA-Z_]\w*(?=\s*\()/ },
180
- { name: 'op', reg: /(\?\.|![:\.]|[+\-*/%=<>!&|^~]+)/ }
181
- ],
182
- /* theme: {
183
- 'decorator': '#e06c75',
184
- 'type': '#4dbed9',
185
- 'builtin': '#d19a66',
186
- 'keyword': '#c678dd'
187
- },
188
- internalCss: `
189
- .ax-ts-type { font-weight: bold; }
190
- ` */
48
+ alias: 'Typescript',
49
+ rules: typescript,
50
+ });
51
+ Coax.register('md', {
52
+ alias: 'Markdown',
53
+ rules: markdown
191
54
  });
192
- export {};
55
+ //注册工具箱
56
+ Coax.addTools([copy]);
57
+ customElements.define(`${NAMESPACE}-code`, Coax);
58
+ export default Coax;
package/src/Coax.ts CHANGED
@@ -1,217 +1,66 @@
1
1
  /**
2
- * Last modified: 2026/01/04 15:50:55
2
+ * Last modified: 2026/01/12 08:57:22
3
3
  */
4
-
5
-
6
- // Define the structure for the language configuration
7
- export interface LanguageConfig {
8
- rules: { name: string, reg: RegExp }[]; // Array of syntax highlighting rules
9
- theme?: Record<string, string>; // Optional theme with color values
10
- internalCss?: string; // Optional internal CSS for language-specific styles
11
- cssPrefix?: string; // Optional CSS prefix for class names
12
- }
13
-
14
- class Coax extends HTMLElement {
15
- // A static Map to hold the configuration for different languages
16
- static languages = new Map();
17
- // Raw code as text from the HTML content
18
- private rawCode: string;
19
-
20
- constructor() {
21
- super();
22
- // Attach a Shadow DOM to the custom element
23
- this.attachShadow({ mode: 'open' });
24
- // Remove leading/trailing whitespace from the raw code content
25
- this.rawCode = this.textContent?.replace(/^\s*\n|\n\s*$/g, '') || '';
26
- }
27
- /**
28
- * Registers a new language with a set of syntax highlighting rules.
29
- * @param name - The name of the programming language.
30
- * @param config - Configuration for the language, including rules, theme, and optional CSS.
31
- */
32
- static register(name: string, { rules, theme = {}, internalCss = '', cssPrefix = '' }: LanguageConfig): void {
33
- // Store the language configuration in the static map
34
- this.languages.set(name, { rules, theme, internalCss, cssPrefix });
35
- // Render the highlighted code for all elements with the registered language
36
- document.querySelectorAll('ax-code').forEach(el => {
37
- if (el.getAttribute('lang') === name) (el as any).render();
38
- });
39
- }
40
- // Called when the element is connected to the DOM
41
- connectedCallback() { this.render(); }
42
-
43
- // Observed attributes for changes
44
- static get observedAttributes() { return ['lang', 'height', 'max-height']; }
45
-
46
- /**
47
- * Called when any of the observed attributes change.
48
- */
49
- attributeChangedCallback() {
50
- this.render();
51
- }
52
- /**
53
- * Renders the highlighted code within the shadow DOM.
54
- */
55
- render() {
56
- // Get language name, fallback to 'js' if not provided
57
- const lang = this.getAttribute('lang') || 'js',
58
- // Get the language configuration
59
- config = Coax.languages.get(lang),
60
- // Default to language name if no prefix is set
61
- cssPrefix = config?.cssPrefix || lang,
62
- height = this.getAttribute('height'),
63
- maxHeight = this.getAttribute('max-height');
64
-
65
- let highlightedCode = '',
66
- dynamicStyles = '';
67
-
68
- if (config) {
69
-
70
- //Generate the highlighted HTML by applying the syntax rules
71
- const combinedRegex = new RegExp(config.rules.map((r: any) => `(${r.reg.source})`).join('|'), 'g'),
72
- escaped = this.rawCode.replace(/[&<>]/g, m => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[m] as string));
73
- // Replace code with highlighted syntax
74
- highlightedCode = escaped.replace(combinedRegex, (match, ...args) => {
75
- const index = args.findIndex(val => val !== undefined);
76
- return index !== -1 && config.rules[index] ? `<span class="ax-${cssPrefix}-${config.rules[index].name}">${match}</span>` : match;
77
- });
78
-
79
- //Generate dynamic CSS classes for each syntax rule
80
- // 为 rules 中的每一个 name 生成类似 .hl-name { color: var(--ax-code-name); }
81
- dynamicStyles = config.rules.map((rule: any) => `
82
- .ax-${cssPrefix}-${rule.name} { color: var(--ax-${cssPrefix}-${rule.name}); }
83
- `).join('\n');
84
- } else {
85
- // If no config, display raw code without highlighting
86
- highlightedCode = this.rawCode;
87
- }
88
-
89
- //Generate CSS theme variables if a theme is provided
90
- const themeVars = config?.theme
91
- ? Object.entries(config.theme).map(([k, v]) => `--ax-${cssPrefix}-${k}: ${v};`).join('\n')
92
- : '';
93
- // Set the inner HTML of the shadow root, including styles and highlighted code
94
- (this.shadowRoot as any).innerHTML = `
95
- <style>
96
- :host {
97
- ${themeVars}
98
-
99
- font-size: var(--ax-code-fs,14px);
100
- display: block;
101
- padding: var(--ax-code-p,1em);
102
- box-sizing:border-box;
103
- line-height: var(--ax-code-lh,1.5);
104
- background-color:var(--ax-code-bg,rgba(0,0,0,0.02));
105
- color:var(--ax-code-c,#333);
106
- border:var(--ax-code-bw,1px) solid var(--ax-code-bc,rgba(0,0,0,0.08));
107
- height:${height || 'var(--ax-code-h,auto)'};
108
- max-height:${maxHeight || 'var(--ax-code-mh,500px)'};
109
- overflow:auto;
110
- transition: border-color 0.3s ease,color 0.3s ease;
111
- border-radius: var(--ax-code-r,9px);
112
- }
113
- pre,code{
114
- font-family:"Consolas", "Monaco", "Andale Mono", "Ubuntu Mono", "monospace", "microsoft yahei", "Microsoft JhengHei", "Yu Mincho", "simsun";
115
- margin:0;
116
- padding:0;
117
- }
118
-
119
-
120
- /* Dynamically generated styles for syntax highlighting */
121
- ${dynamicStyles}
122
-
123
- /* Inject additional CSS specific to the language if provided */
124
- ${config?.internalCss || ''}
125
- </style>
126
- <pre><code>${highlightedCode}</code></pre>`;
127
- }
128
- }
129
-
130
- customElements.define('ax-code', Coax);
131
-
132
-
133
- Coax.register('html', {
134
- rules: [
135
- { name: 'comment', reg: /&lt;!--[\s\S]*?--&gt;/ },
136
- { name: 'doctype', reg: /&lt;!DOCTYPE[\s\S]*?&gt;/i },
137
- // 匹配标签名: <div, </div
138
- { name: 'tag', reg: /&lt;\/?[a-zA-Z0-9]+/ },
139
- // 匹配属性名: class=
140
- { name: 'attr', reg: /[a-zA-Z-]+(?=\s*=\s*)/ },
141
- // 匹配属性值: "value"
142
- { name: 'string', reg: /(['"])(?:\\.|[^\\])*?\1/ },
143
- // 匹配标签闭合: >, />
144
- { name: 'bracket', reg: /\/?&gt;/ }
145
- ],
146
- //添加root变量:--ax-html-keyword
147
- /* theme: {
148
- 'tag': '#e06c75', // 红色
149
- 'attr': '#d19a66', // 橙色
150
- 'bracket': '#abb2bf', // 灰色
151
- 'doctype': '#56b6c2' // 青色
152
- } */
4
+ 'use strict'
5
+
6
+ import NAMESPACE from "@codady/utils/namespace";
7
+ import CoaxElem from "./components/CoaxElem.js";
8
+ import html from "./rules/html.js";
9
+ import javascript from "./rules/javascript.js";
10
+ import markdown from "./rules/markdown.js";
11
+ import typescript from "./rules/typescript.js";
12
+ import copy from "./tools/copy.js";
13
+ import css from "./rules/css.js";
14
+
15
+ const Coax = CoaxElem;
16
+ //注册语言类型
17
+ Coax.register('css', {
18
+ alias: 'CSS',
19
+ rules: css,
20
+ /* cssPrefix: 'css',
21
+ themeStyles: `
22
+ :host {
23
+ --background:rgba(0,0,0,0.02);
24
+ --border-color:rgba(0,0,0,0.08);
25
+ --color-code:#333;
26
+ }
27
+ :host([scheme="dark"]){
28
+ --background: #282c34;
29
+ --border-color: transparent;
30
+ --color-code: #abb2bf;
31
+ }
32
+ @media (prefers-color-scheme: dark) {
33
+ :host{
34
+ --background: #282c34;
35
+ --border-color: transparent;
36
+ --color-code: #abb2bf;
37
+ }
38
+ }
39
+ ` */
153
40
  });
154
41
 
155
- Coax.register('css', {
156
- rules: [
157
- { name: 'comment', reg: /\/\*[\s\S]*?\*\// },
158
- { name: 'value', reg: /(?:'|")(?:\\.|[^\\'"\b])*?(?:'|")/ },
159
- { name: 'func', reg: /[a-z-]+\(?=/ },
160
- { name: 'property', reg: /[a-z-]+(?=\s*:)/ },
161
- { name: 'selector', reg: /[.#a-z0-9, \n\t>:+()_-]+(?=\s*\{)/i },
162
- { name: 'unit', reg: /(?<=\d)(px|em|rem|%|vh|vw|ms|s|deg)/ },
163
- { name: 'number', reg: /\b\d+(\.\d+)?\b/ },
164
- { name: 'punct', reg: /[{}();:]/ }
165
- ],
166
- //添加root变量:--ax-code-keyword
167
- theme: {
168
- 'type': '#61afef', // 蓝色选择器
169
- 'keyword': '#d19a66', // 橙色属性名
170
- 'string': '#98c379', // 绿色属性值
171
- 'op': '#abb2bf' // 灰色符号
172
- },
173
- internalCss: `
174
- .ax-css-string { color: var(--ax-code-string); }
175
- .ax-css-string::first-letter { color: var(--ax-code-c); }
176
- `
42
+ Coax.register('html', {
43
+ alias: 'HTML',
44
+ rules: html,
177
45
  });
178
46
 
179
47
  Coax.register('js', {
180
- rules: [
181
- { name: 'comment', reg: /\/\/[^\n]*|\/\*[\s\S]*?\*\// },
182
- { name: 'string', reg: /(?:'|"|`)(?:\\.|[^\\'"\b])*?(?:'|"|`)/ },
183
- { name: 'keyword', reg: /\b(async|await|break|case|catch|class|const|continue|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|while|with|yield|let|static)\b/ },
184
- { name: 'builtin', reg: /\b(console|window|document|Math|JSON|true|false|null|undefined|Object|Array|Promise)\b/ },
185
- { name: 'number', reg: /\b\d+\b/ },
186
- { name: 'func', reg: /\b[a-zA-Z_]\w*(?=\s*\()/ },
187
- { name: 'op', reg: /[+\-*/%=<>!&|^~]+/ }
188
- ],
189
- /* theme: {
190
- 'keyword': '#c678dd',
191
- 'func': '#61afef',
192
- 'builtin': '#e5c07b'
193
- } */
48
+ alias: 'Javascript',
49
+ rules: javascript,
194
50
  });
195
51
 
196
52
  Coax.register('ts', {
197
- rules: [
198
- { name: 'comment', reg: /\/\/[^\n]*|\/\*[\s\S]*?\*\// },
199
- { name: 'string', reg: /(?:'|"|`)(?:\\.|[^\\'"\b])*?(?:'|"|`)/ },
200
- { name: 'decorator', reg: /@[a-zA-Z_]\w*/ },
201
- { name: 'keyword', reg: /\b(abstract|as|async|await|break|case|catch|class|const|continue|debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|is|keyof|let|module|namespace|new|package|private|protected|public|readonly|return|set|static|super|switch|this|throw|try|type|typeof|var|while|with|yield)\b/ },
202
- { name: 'builtin', reg: /\b(any|boolean|never|number|string|symbol|unknown|void|undefined|null|boolean|true|false|console|window|document)\b/ },
203
- { name: 'type', reg: /\b[A-Z]\w*\b/ },
204
- { name: 'number', reg: /\b\d+\b/ },
205
- { name: 'func', reg: /\b[a-zA-Z_]\w*(?=\s*\()/ },
206
- { name: 'op', reg: /(\?\.|![:\.]|[+\-*/%=<>!&|^~]+)/ }
207
- ],
208
- /* theme: {
209
- 'decorator': '#e06c75',
210
- 'type': '#4dbed9',
211
- 'builtin': '#d19a66',
212
- 'keyword': '#c678dd'
213
- },
214
- internalCss: `
215
- .ax-ts-type { font-weight: bold; }
216
- ` */
217
- });
53
+ alias: 'Typescript',
54
+ rules: typescript,
55
+ });
56
+
57
+ Coax.register('md', {
58
+ alias: 'Markdown',
59
+ rules: markdown
60
+ });
61
+ //注册工具箱
62
+ Coax.addTools([copy]);
63
+
64
+ customElements.define(`${NAMESPACE}-code`, Coax);
65
+
66
+ export default Coax;