@codady/coax 0.0.2 → 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 (40) hide show
  1. package/dist/coax.cjs.js +421 -257
  2. package/dist/coax.cjs.min.js +3 -3
  3. package/dist/coax.esm.js +415 -257
  4. package/dist/coax.esm.min.js +3 -3
  5. package/dist/coax.umd.js +435 -249
  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/deepseek-highlight.html +91 -0
  11. package/examples/js-highlight.html +1 -1
  12. package/examples/md-highlight.html +60 -0
  13. package/examples/nginx.htaccess +0 -0
  14. package/examples/replace-highlight.html +69 -0
  15. package/examples/stream-highlight.html +64 -0
  16. package/examples/theme-highlight.html +69 -0
  17. package/package.json +3 -3
  18. package/rollup.config.js +3 -3
  19. package/src/Coax.js +26 -414
  20. package/src/Coax.ts +29 -443
  21. package/src/components/CoaxElem.js +457 -0
  22. package/src/components/CoaxElem.ts +488 -0
  23. package/src/modules.js +12 -0
  24. package/src/modules.ts +23 -0
  25. package/src/rules/css.js +11 -0
  26. package/src/rules/css.ts +11 -0
  27. package/src/rules/html.js +13 -0
  28. package/src/rules/html.ts +13 -0
  29. package/src/rules/javascript.js +10 -0
  30. package/src/rules/javascript.ts +10 -0
  31. package/src/rules/markdown.js +29 -0
  32. package/src/rules/markdown.ts +41 -0
  33. package/src/rules/ruleCss - /345/211/257/346/234/254.js" +10 -0
  34. package/src/rules/ruleHTML - /345/211/257/346/234/254.js" +12 -0
  35. package/src/rules/ruleJs - /345/211/257/346/234/254.js" +10 -0
  36. package/src/rules/ruleTs - /345/211/257/346/234/254.js" +12 -0
  37. package/src/rules/typescript.js +12 -0
  38. package/src/rules/typescript.ts +12 -0
  39. package/src/tools/copy.js +26 -0
  40. package/src/tools/copy.ts +29 -0
@@ -0,0 +1,41 @@
1
+ const markdown = [
2
+ // 注释: 这是 Markdown 中的行内注释
3
+ { token: 'comment', pattern: /<!--[\s\S]*?-->/, light: '#6a737d', dark: '#8b949e' },
4
+
5
+ // 标题: 通过 `#` 来定义标题
6
+ { token: 'heading', pattern: /(^|\n)(#{1,6})\s*(.+)/, light: '#e36209', dark: '#ffa657' },
7
+
8
+ // 粗体: **text** 或 __text__
9
+ { token: 'bold', pattern: /\*\*([^*]+)\*\*|__([^_]+)__/g, light: '#d73a49', dark: '#ff7b72' },
10
+
11
+ // 斜体: *text* 或 _text_
12
+ { token: 'italic', pattern: /\*([^*]+)\*|_([^_]+)_/g, light: '#032f62', dark: '#a5d6ff' },
13
+
14
+ // 链接: [text](url)
15
+ { token: 'link', pattern: /\[([^\]]+)\]\(([^)]+)\)/g, light: '#0288d1', dark: '#80c0ff' },
16
+
17
+ // 行内代码: `code`
18
+ { token: 'inline-code', pattern: /`([^`]+)`/g, light: '#032f62', dark: '#98c379' },
19
+
20
+ // 代码块: ```code```
21
+ { token: 'code-block', pattern: /```([^\n]+)\n([\s\S]*?)```/g, light: '#24292e', dark: '#c9d1d9' },
22
+
23
+ // 列表项: - item 或 * item
24
+ { token: 'list-item', pattern: /(^|\n)([-*])\s+(.+)/g, light: '#5c6e7c', dark: '#8b949e' },
25
+
26
+ // 引用: > text
27
+ { token: 'quote', pattern: /(^|\n)>[ \t]*(.+)/g, light: '#6f42c1', dark: '#d2a8ff' },
28
+
29
+ // 图片: ![alt](url)
30
+ { token: 'image', pattern: /!\[([^\]]+)\]\(([^)]+)\)/g, light: '#d73a49', dark: '#ff7b72' },
31
+
32
+ // 分割线: ---
33
+ { token: 'hr', pattern: /^(---|___|\*\*\*)\s*$/gm, light: '#24292e', dark: '#c9d1d9' },
34
+
35
+ // 强调和删除: ~~text~~
36
+ { token: 'strikethrough', pattern: /~~([^~]+)~~/g, light: '#e36209', dark: '#ffa657' },
37
+
38
+ // 表格: | header1 | header2 |
39
+ { token: 'table', pattern: /\|([^\|]+)\|([^\|]+)\|/g, light: '#5c6e7c', dark: '#8b949e' }
40
+ ]
41
+ export default markdown;
@@ -0,0 +1,10 @@
1
+ export const ruleCss = [
2
+ { token: 'comment', pattern: /\/\*[\s\S]*?\*\//, light: '#6a737d', dark: '#8b949e' },
3
+ { token: 'value', pattern: /(?:'|")(?:\\.|[^\\'"\b])*?(?:'|")/, light: '#032f62', dark: '#a5d6ff' },
4
+ { token: 'func', pattern: /[a-z-]+\(?=/, light: '#e36209', dark: '#ffa657' },
5
+ { token: 'property', pattern: /[a-z-]+(?=\s*:)/, light: '#005cc5', dark: '#79c0ff' },
6
+ { token: 'selector', pattern: /[.#a-z0-9, \n\t>:+()_-]+(?=\s*\{)/i, light: '#22863a', dark: '#7ee787' },
7
+ { token: 'unit', pattern: /(?<=\d)(px|em|rem|%|vh|vw|ms|s|deg)/, light: '#d73a49', dark: '#ff7b72' },
8
+ { token: 'number', pattern: /\b\d+(\.\d+)?\b/, light: '#005cc5', dark: '#79c0ff' },
9
+ { token: 'punct', pattern: /[{}();:]/, light: '#24292e', dark: '#c9d1d9' }
10
+ ];
@@ -0,0 +1,12 @@
1
+ export const ruleHTML = [
2
+ { token: 'comment', pattern: /&lt;!--[\s\S]*?--&gt;/, light: '#999999', dark: '#6e7681' },
3
+ { token: 'doctype', pattern: /&lt;!DOCTYPE[\s\S]*?&gt;/i, light: '#6a737d', dark: '#8b949e' },
4
+ // 匹配标签名: <div, </div
5
+ { token: 'tag', pattern: /&lt;\/?[a-zA-Z0-9]+/, light: '#22863a', dark: '#7ee787' },
6
+ // 匹配属性名: class=
7
+ { token: 'attr', pattern: /[a-zA-Z-]+(?=\s*=\s*)/, light: '#6f42c1', dark: '#d2a8ff' },
8
+ // 匹配属性值: "value"
9
+ { token: 'string', pattern: /(['"])(?:\\.|[^\\])*?\1/, light: '#032f62', dark: '#a5d6ff' },
10
+ // 匹配标签闭合: >, />
11
+ { token: 'bracket', pattern: /\/?&gt;/, light: '#24292e', dark: '#c9d1d9' }
12
+ ];
@@ -0,0 +1,10 @@
1
+ const ruleJs = [
2
+ { token: 'comment', pattern: /\/\/[^\n]*|\/\*[\s\S]*?\*\//, light: '#6a737d', dark: '#8b949e' },
3
+ { token: 'string', pattern: /(?:'|"|`)(?:\\.|[^\\'"\b])*?(?:'|"|`)/, light: '#032f62', dark: '#98c379' },
4
+ { token: 'keyword', pattern: /\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/, light: '#d73a49', dark: '#ff7b72' },
5
+ { token: 'builtin', pattern: /\b(console|window|document|Math|JSON|true|false|null|undefined|Object|Array|Promise|Number|String|Boolean)\b/, light: '#e36209', dark: '#ffa657' },
6
+ { token: 'number', pattern: /\b(0x[\da-fA-F]+|0b[01]+|\d+(\.\d+)?)\b/, light: '#005cc5', dark: '#79c0ff' },
7
+ { token: 'func', pattern: /\b[a-zA-Z_]\w*(?=\s*\()/, light: '#6f42c1', dark: '#d2a8ff' },
8
+ { token: 'op', pattern: /[+\-*/%=<>!&|^~]+/, light: '#069598', dark: '#56b6c2' }
9
+ ];
10
+ export default ruleJs;
@@ -0,0 +1,12 @@
1
+ const ruleTs = [
2
+ { token: 'comment', pattern: /\/\/[^\n]*|\/\*[\s\S]*?\*\//, light: '#6a737d', dark: '#8b949e' },
3
+ { token: 'string', pattern: /(?:'|"|`)(?:\\.|[^\\'"\b])*?(?:'|"|`)/, light: '#032f62', dark: '#98c379' },
4
+ { token: 'decorator', pattern: /@[a-zA-Z_]\w*/, light: '#953800', dark: '#ffa657' },
5
+ { token: 'keyword', pattern: /\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/, light: '#d73a49', dark: '#ff7b72' },
6
+ { token: 'builtin', pattern: /\b(any|boolean|never|number|string|symbol|unknown|void|undefined|null|true|false|console|window|document)\b/, light: '#e36209', dark: '#ffa657' },
7
+ { token: 'type', pattern: /\b[A-Z]\w*\b/, light: '#005cc5', dark: '#79c0ff' },
8
+ { token: 'number', pattern: /\b(0x[\da-fA-F]+|0b[01]+|\d+(\.\d+)?)\b/, light: '#005cc5', dark: '#79c0ff' },
9
+ { token: 'func', pattern: /\b[a-zA-Z_]\w*(?=\s*\()/, light: '#6f42c1', dark: '#d2a8ff' },
10
+ { token: 'op', pattern: /(\?\.|![:\.]|[+\-*/%=<>!&|^~]+)/, light: '#089ba6', dark: '#79c0ff' }
11
+ ];
12
+ export default ruleTs;
@@ -0,0 +1,12 @@
1
+ const typescript = [
2
+ { token: 'comment', pattern: /\/\/[^\n]*|\/\*[\s\S]*?\*\//, light: '#6a737d', dark: '#8b949e' },
3
+ { token: 'string', pattern: /(?:'|"|`)(?:\\.|[^\\'"\b])*?(?:'|"|`)/, light: '#032f62', dark: '#98c379' },
4
+ { token: 'decorator', pattern: /@[a-zA-Z_]\w*/, light: '#953800', dark: '#ffa657' },
5
+ { token: 'keyword', pattern: /\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/, light: '#d73a49', dark: '#ff7b72' },
6
+ { token: 'builtin', pattern: /\b(any|boolean|never|number|string|symbol|unknown|void|undefined|null|true|false|console|window|document)\b/, light: '#e36209', dark: '#ffa657' },
7
+ { token: 'type', pattern: /\b[A-Z]\w*\b/, light: '#005cc5', dark: '#79c0ff' },
8
+ { token: 'number', pattern: /\b(0x[\da-fA-F]+|0b[01]+|\d+(\.\d+)?)\b/, light: '#005cc5', dark: '#79c0ff' },
9
+ { token: 'func', pattern: /\b[a-zA-Z_]\w*(?=\s*\()/, light: '#6f42c1', dark: '#d2a8ff' },
10
+ { token: 'op', pattern: /(\?\.|![:\.]|[+\-*/%=<>!&|^~]+)/, light: '#089ba6', dark: '#79c0ff' }
11
+ ];
12
+ export default typescript;
@@ -0,0 +1,12 @@
1
+ const typescript = [
2
+ { token: 'comment', pattern: /\/\/[^\n]*|\/\*[\s\S]*?\*\//, light: '#6a737d', dark: '#8b949e' },
3
+ { token: 'string', pattern: /(?:'|"|`)(?:\\.|[^\\'"\b])*?(?:'|"|`)/, light: '#032f62', dark: '#98c379' },
4
+ { token: 'decorator', pattern: /@[a-zA-Z_]\w*/, light: '#953800', dark: '#ffa657' },
5
+ { token: 'keyword', pattern: /\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/, light: '#d73a49', dark: '#ff7b72' },
6
+ { token: 'builtin', pattern: /\b(any|boolean|never|number|string|symbol|unknown|void|undefined|null|true|false|console|window|document)\b/, light: '#e36209', dark: '#ffa657' },
7
+ { token: 'type', pattern: /\b[A-Z]\w*\b/, light: '#005cc5', dark: '#79c0ff' },
8
+ { token: 'number', pattern: /\b(0x[\da-fA-F]+|0b[01]+|\d+(\.\d+)?)\b/, light: '#005cc5', dark: '#79c0ff' },
9
+ { token: 'func', pattern: /\b[a-zA-Z_]\w*(?=\s*\()/, light: '#6f42c1', dark: '#d2a8ff' },
10
+ { token: 'op', pattern: /(\?\.|![:\.]|[+\-*/%=<>!&|^~]+)/, light: '#089ba6', dark: '#79c0ff' }
11
+ ]
12
+ export default typescript;
@@ -0,0 +1,26 @@
1
+ import icaxCheck from "@codady/icax/src/icaxCheck";
2
+ import icaxCopy from "@codady/icax/src/icaxCopy";
3
+ const copy = {
4
+ name: 'copy',
5
+ icon: icaxCopy(),
6
+ action: function (arg) {
7
+ arg.wrapEl.onclick = () => {
8
+ //this只是组件实例
9
+ navigator.clipboard.writeText(this.source)
10
+ .then(() => {
11
+ console.log('Text successfully copied to clipboard');
12
+ arg.iconEl.innerHTML = icaxCheck();
13
+ arg.iconEl.toggleAttribute('disabled', true);
14
+ setTimeout(() => {
15
+ //恢复
16
+ arg.iconEl.removeAttribute('disabled');
17
+ arg.iconEl.innerHTML = icaxCopy();
18
+ }, 2000);
19
+ })
20
+ .catch(err => {
21
+ console.error('Error copying text to clipboard: ', err);
22
+ });
23
+ };
24
+ }
25
+ };
26
+ export default copy;
@@ -0,0 +1,29 @@
1
+ import icaxCheck from "@codady/icax/src/icaxCheck";
2
+ import icaxCopy from "@codady/icax/src/icaxCopy";
3
+ import { toolsItem } from "@codady/utils/createTools";
4
+
5
+ const copy:toolsItem = {
6
+ name: 'copy',
7
+ icon: icaxCopy(),
8
+ action: function (this:any,arg: any) {
9
+ arg.wrapEl.onclick = () => {
10
+ //this只是组件实例
11
+ navigator.clipboard.writeText(this.source)
12
+ .then(() => {
13
+ console.log('Text successfully copied to clipboard');
14
+ arg.iconEl.innerHTML = icaxCheck();
15
+ arg.iconEl.toggleAttribute('disabled', true);
16
+ setTimeout(() => {
17
+ //恢复
18
+ arg.iconEl.removeAttribute('disabled');
19
+ arg.iconEl.innerHTML = icaxCopy();
20
+ }, 2000);
21
+ })
22
+ .catch(err => {
23
+ console.error('Error copying text to clipboard: ', err);
24
+ });
25
+ }
26
+ }
27
+ }
28
+
29
+ export default copy;