@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.
- package/dist/coax.cjs.js +829 -140
- package/dist/coax.cjs.min.js +3 -3
- package/dist/coax.esm.js +823 -140
- package/dist/coax.esm.min.js +3 -3
- package/dist/coax.umd.js +849 -138
- package/dist/coax.umd.min.js +3 -3
- package/examples/.htaccess +0 -0
- package/examples/append-highlight.html +82 -0
- package/examples/color-selector.html +412 -0
- package/examples/css-highlight.html +2 -18
- package/examples/deepseek-highlight.html +91 -0
- package/examples/js-highlight.html +2 -17
- package/examples/md-highlight.html +60 -0
- package/examples/nginx.htaccess +0 -0
- package/examples/plain-highlight.html +47 -0
- package/examples/replace-highlight.html +69 -0
- package/examples/stream-highlight.html +64 -0
- package/examples/theme-highlight.html +69 -0
- package/package.json +19 -3
- package/rollup.config.js +3 -3
- package/src/Coax.js +50 -184
- package/src/Coax.ts +56 -207
- package/src/components/CoaxElem.js +457 -0
- package/src/components/CoaxElem.ts +488 -0
- package/src/modules.js +12 -0
- package/src/modules.ts +23 -0
- package/src/rules/css.js +11 -0
- package/src/rules/css.ts +11 -0
- package/src/rules/html.js +13 -0
- package/src/rules/html.ts +13 -0
- package/src/rules/javascript.js +10 -0
- package/src/rules/javascript.ts +10 -0
- package/src/rules/markdown.js +29 -0
- package/src/rules/markdown.ts +41 -0
- package/src/rules/ruleCss - /345/211/257/346/234/254.js" +10 -0
- package/src/rules/ruleHTML - /345/211/257/346/234/254.js" +12 -0
- package/src/rules/ruleJs - /345/211/257/346/234/254.js" +10 -0
- package/src/rules/ruleTs - /345/211/257/346/234/254.js" +12 -0
- package/src/rules/typescript.js +12 -0
- package/src/rules/typescript.ts +12 -0
- package/src/tools/copy.js +26 -0
- package/src/tools/copy.ts +29 -0
- package/tsconfig.json +2 -2
package/src/Coax.js
CHANGED
|
@@ -1,192 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Last modified: 2026/01/
|
|
2
|
+
* Last modified: 2026/01/12 08:57:22
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 => ({ '&': '&', '<': '<', '>': '>' }[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: /<!--[\s\S]*?-->/ },
|
|
113
|
-
{ name: 'doctype', reg: /<!DOCTYPE[\s\S]*?>/i },
|
|
114
|
-
// 匹配标签名: <div, </div
|
|
115
|
-
{ name: 'tag', reg: /<\/?[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: /\/?>/ }
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
156
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
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/
|
|
2
|
+
* Last modified: 2026/01/12 08:57:22
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 => ({ '&': '&', '<': '<', '>': '>' }[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: /<!--[\s\S]*?-->/ },
|
|
136
|
-
{ name: 'doctype', reg: /<!DOCTYPE[\s\S]*?>/i },
|
|
137
|
-
// 匹配标签名: <div, </div
|
|
138
|
-
{ name: 'tag', reg: /<\/?[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: /\/?>/ }
|
|
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('
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
181
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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;
|