@stacksjs/components 0.2.854 → 0.2.855

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 (44) hide show
  1. package/dist/CodeEditor-jg4w7e15.stx +497 -0
  2. package/dist/code-editor/editor.js +2166 -0
  3. package/dist/components/CodeBlock.d.ts +12 -5
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +29 -12
  6. package/dist/ui/code-editor/CodeEditor.d.ts +46 -0
  7. package/dist/ui/code-editor/controller.d.ts +103 -0
  8. package/dist/ui/code-editor/core/commands.d.ts +55 -0
  9. package/dist/ui/code-editor/core/completion.d.ts +40 -0
  10. package/dist/ui/code-editor/core/editor.d.ts +69 -0
  11. package/dist/ui/code-editor/core/highlight.d.ts +61 -0
  12. package/dist/ui/code-editor/core/history.d.ts +27 -0
  13. package/dist/ui/code-editor/core/index.d.ts +13 -0
  14. package/dist/ui/code-editor/core/keymap.d.ts +38 -0
  15. package/dist/ui/code-editor/core/selection.d.ts +30 -0
  16. package/dist/ui/code-editor/core/text.d.ts +64 -0
  17. package/dist/ui/code-editor/editor.d.ts +15 -0
  18. package/dist/ui/code-editor/index.d.ts +29 -0
  19. package/dist/ui/code-editor/tokenizer.d.ts +18 -0
  20. package/dist/ui/code-editor/view.d.ts +59 -0
  21. package/dist/utils/highlighter.d.ts +19 -1
  22. package/dist/utils/highlighter.js +24 -7
  23. package/dist/utils/syntax-theme.d.ts +44 -0
  24. package/package.json +9 -4
  25. package/src/components/CodeBlock.stx +195 -17
  26. package/src/index.ts +2 -0
  27. package/src/ui/code-editor/CodeEditor.stx +497 -0
  28. package/src/ui/code-editor/README.md +134 -0
  29. package/src/ui/code-editor/controller.ts +517 -0
  30. package/src/ui/code-editor/core/commands.ts +381 -0
  31. package/src/ui/code-editor/core/completion.ts +212 -0
  32. package/src/ui/code-editor/core/editor.ts +319 -0
  33. package/src/ui/code-editor/core/highlight.ts +203 -0
  34. package/src/ui/code-editor/core/history.ts +190 -0
  35. package/src/ui/code-editor/core/index.ts +14 -0
  36. package/src/ui/code-editor/core/keymap.ts +125 -0
  37. package/src/ui/code-editor/core/selection.ts +104 -0
  38. package/src/ui/code-editor/core/text.ts +252 -0
  39. package/src/ui/code-editor/editor.ts +16 -0
  40. package/src/ui/code-editor/index.ts +46 -0
  41. package/src/ui/code-editor/tokenizer.ts +74 -0
  42. package/src/ui/code-editor/view.ts +1066 -0
  43. package/src/utils/highlighter.ts +121 -218
  44. package/src/utils/syntax-theme.ts +144 -0
@@ -1,8 +1,25 @@
1
1
  // @bun
2
- async function j(){try{let t=await import("ts-syntax-highlighter");return t.createHighlighter}catch{return null}}var f=null,x="github-light",b="github-dark";function d(t){return`<pre class="syntax"><code>${t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}</code></pre>`}async function C(){if(!f){let t=await j();if(!t)throw Error("ts-syntax-highlighter could not be loaded");f=await t({theme:"github-light"})}return f}var L=/<span class="([^"]*)"[^>]*style="([^"]*)"/g,S=/^token\s+(\S.*)$/;function w(t){let n=[];for(let i of t.matchAll(L)){let e=S.exec(i[1]??"");if(e)n.push([e[1].trim(),i[2]??""])}return n}function P(t){return/^[\w-]+$/.test(t)}async function A(t,n,i){let e,u;try{e=await t.highlight(n,i,{theme:x}),u=await t.highlight(n,i,{theme:b})}catch{return null}let m=e?.html,g=u?.html;if(!m||!g)return null;let h=w(m),c=w(g);if(h.length===0||h.length!==c.length)return null;let r=new Map;for(let s=0;s<h.length;s++){let[l,p]=h[s],H=c[s][1];if(!l||!p||!H||r.has(l)||!P(l))continue;r.set(l,{light:p,dark:H})}if(r.size===0)return null;let o=[],a=[];for(let[s,{light:l,dark:p}]of r)o.push(`.syntax .token.${s} { ${l} }`),a.push(`.syntax .token.${s} { ${p} }`);let y=/\.syntax\s*\{([^}]*)\}/.exec(u.css??"")?.[1],k=y?y.split(";").map((s)=>s.trim()).filter((s)=>/^(?:background-color|color)\s*:/.test(s)).join("; "):"";if(k)a.unshift(`.syntax { ${k} }`);let T=[e.css??"",o.join(`
3
- `),`@media (prefers-color-scheme: dark) {
4
- :root:not(.light) ${a.join(`
5
- :root:not(.light) `)}
6
- }`,a.map((s)=>`.dark ${s}`).join(`
7
- `)].filter(Boolean).join(`
8
- `);return{html:m.replace(/(<span class="[^"]*")[^>]*?\s+style="[^"]*"/g,(s,l)=>S.test(/class="([^"]*)"/.exec(l)?.[1]??"")?l:s),css:T}}async function N(t,n={}){let{theme:i="auto",language:e="typescript",lineNumbers:u=!1,wrapLines:m=!0}=n,g=i==="auto"?globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches?"github-dark":"github-light":i==="dark"?b:x,h;try{h=await C()}catch{return{html:d(t),css:"",language:e,theme:g}}if(i==="auto"){let a=await A(h,t,e);if(a)return{html:a.html,css:a.css,language:e,theme:"auto"}}let c;try{c=await h.highlight(t,e,{theme:g})}catch{return{html:d(t),css:"",language:e,theme:g}}let r=c,o=typeof r==="string"?{html:r,css:""}:{html:r?.html??d(t),css:r?.css??""};return{html:o.html,css:o.css,language:e,theme:g}}function D(t){if(t.includes("<!DOCTYPE")||t.includes("<html"))return"html";if(t.includes("<?php"))return"php";if(t.includes("import")&&t.includes("from"))return"typescript";if(t.includes("function")||t.includes("const"))return"javascript";if(t.includes("{")&&t.includes("}"))return"json";if(t.includes("$")&&t.includes("|"))return"bash";if(t.includes("#")&&t.includes("##"))return"markdown";return"typescript"}function E(t,n){return`<div class="${n?`rounded-md overflow-auto text-sm leading-relaxed font-mono ${n}`:"rounded-md overflow-auto text-sm leading-relaxed font-mono"}">${t}</div>`}export{E as applyHeadwindClasses,D as detectLanguage,C as getHighlighter,N as highlight};
2
+ var k=["keyword","string","comment","numeric","constant","function","operator","punctuation","type","variable","tag","attribute"],c={background:"#ffffff",foreground:"#24292f",keyword:"#cf222e",string:"#0a3069",comment:"#6e7781",numeric:"#0550ae",constant:"#0550ae",function:"#8250df",operator:"#cf222e",punctuation:"#24292f",type:"#953800",variable:"#953800",tag:"#116329",attribute:"#0550ae"},g={background:"#0d1117",foreground:"#c9d1d9",keyword:"#ff7b72",string:"#a5d6ff",comment:"#8b949e",numeric:"#79c0ff",constant:"#79c0ff",function:"#d2a8ff",operator:"#ff7b72",punctuation:"#c9d1d9",type:"#ffa657",variable:"#ffa657",tag:"#7ee787",attribute:"#79c0ff"},v=["background","foreground",...k];function o(t,n=" "){return v.map((e)=>`${n}--stx-syntax-${e}: ${t[e]};`).join(`
3
+ `)}function h(){return k.map((t)=>`.tok-${t} { color: var(--stx-syntax-${t}); }`).concat(".tok-comment { font-style: italic; }").join(`
4
+ `)}function C(){let t=o(c),n=o(g);return[`:where(:root) {
5
+ ${t}
6
+ }`,`@media (prefers-color-scheme: dark) {
7
+ :where(:root:not(.light)) {
8
+ ${n}
9
+ }
10
+ }`,`:where(.dark) {
11
+ ${n}
12
+ }`,`:where([data-syntax-theme="light"]) {
13
+ ${t}
14
+ }`,`:where([data-syntax-theme="dark"]) {
15
+ ${n}
16
+ }`,h()].join(`
17
+ `)}function f(){return[".syntax {"," margin: 0;"," padding: 1rem;"," overflow-x: auto;"," border-radius: 0.375rem;"," background-color: var(--stx-syntax-background);"," color: var(--stx-syntax-foreground);",' font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;'," font-size: 0.875rem;"," line-height: 1.5;"," tab-size: 2;","}",".syntax code { display: block; font-family: inherit; }",".syntax[data-line-numbers] { counter-reset: stx-syntax-line; }",".syntax[data-line-numbers] .line::before {"," counter-increment: stx-syntax-line;"," content: counter(stx-syntax-line);"," display: inline-block;"," width: 2.5em;"," margin-right: 1em;"," text-align: right;"," opacity: 0.5;"," user-select: none;","}"].join(`
18
+ `)}function w(){return`${C()}
19
+ ${f()}`}var T=null;function S(){return T??=import("ts-syntax-highlighter/browser").catch(()=>null),T}var m=null,H="github-light",R="github-dark";function p(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function A(t){return`<pre class="syntax"><code>${p(t)}</code></pre>`}async function L(){if(!m){let{createHighlighter:t}=await import("ts-syntax-highlighter");m=await t({theme:"github-light"})}return m}async function N(t,n={}){let e=await S();if(!e)return null;let r;try{let i=await e.resolveGrammar(n.language??"typescript");if(!i)return null;r=new e.Tokenizer(i).tokenizeLinesFrom(t.replace(/\r\n?/g,`
20
+ `).split(`
21
+ `)).lines}catch{return null}let l=r.map((i)=>{let d="",s="",a="",y=()=>{if(s!=="")d+=a===""?p(s):`<span class="tok-${a}">${p(s)}</span>`;s=""};for(let x of i.tokens){let b=e.tokenClass(x.type);if(b!==a)y(),a=b;s+=x.content}return y(),`<span class="line">${d}</span>`}).join(`
22
+ `);return`<pre ${['class="syntax"',n.theme==="light"||n.theme==="dark"?`data-syntax-theme="${n.theme}"`:"",n.lineNumbers?"data-line-numbers":""].filter(Boolean).join(" ")}><code>${l}</code></pre>`}function P(t){if(t==="auto")return w();return[`[data-syntax-theme="${t}"] {
23
+ ${o(t==="dark"?g:c)}
24
+ }`,h(),f()].join(`
25
+ `)}async function Y(t,n={}){let{theme:e="auto",language:r="typescript",lineNumbers:l=!1}=n,u=await N(t,{language:r,theme:e,lineNumbers:l});if(u===null)return{html:A(t),css:"",language:r,theme:e==="dark"?R:H};return{html:u,css:P(e),language:r,theme:e==="auto"?"auto":e==="dark"?R:H}}function B(t){if(t.includes("<!DOCTYPE")||t.includes("<html"))return"html";if(t.includes("<?php"))return"php";if(t.includes("import")&&t.includes("from"))return"typescript";if(t.includes("function")||t.includes("const"))return"javascript";if(t.includes("{")&&t.includes("}"))return"json";if(t.includes("$")&&t.includes("|"))return"bash";if(t.includes("#")&&t.includes("##"))return"markdown";return"typescript"}function X(t,n){return`<div class="${n?`rounded-md overflow-auto text-sm leading-relaxed font-mono ${n}`:"rounded-md overflow-auto text-sm leading-relaxed font-mono"}">${t}</div>`}export{X as applyHeadwindClasses,B as detectLanguage,L as getHighlighter,Y as highlight,N as highlightToHtml};
@@ -0,0 +1,44 @@
1
+ /** `--stx-syntax-keyword: #cf222e;` for every property, one per line. */
2
+ export declare function syntaxVariables(palette: Readonly<Record<string, string>>, indent?: string): string;
3
+ /** The rules that colour a token class from its variable. */
4
+ export declare function syntaxTokenRules(): string;
5
+ /**
6
+ * The whole sheet: light values, dark values for a reader following their
7
+ * system and for an app with a `.dark` toggle, an explicit theme on the
8
+ * element itself, and the token rules.
9
+ *
10
+ * `:where()` throughout, so none of it outranks a single class an app writes.
11
+ */
12
+ export declare function syntaxThemeCss(): string;
13
+ /**
14
+ * The block a `<CodeBlock>` draws its code in.
15
+ *
16
+ * Line numbers are a counter, not text, so selecting a numbered block and
17
+ * copying it gives the code and not `1const a = 1`.
18
+ */
19
+ export declare function syntaxPanelCss(): string;
20
+ /** Everything `<CodeBlock>` needs: the palettes, the token rules and the panel. */
21
+ export declare function codeBlockCss(): string;
22
+ /**
23
+ * The colours of code, as CSS custom properties.
24
+ *
25
+ * Two places draw highlighted code - `<CodeBlock>` and `<CodeEditor>` - and
26
+ * both write a class on each token (`tok-keyword`) rather than a colour. What a
27
+ * keyword looks like is decided here, once, as `--stx-syntax-keyword`, so an
28
+ * app re-themes both by setting a variable, and light and dark are the same
29
+ * markup under a different set of values.
30
+ *
31
+ * The defaults are the highlighter's GitHub pair. `test/syntax-theme.test.ts`
32
+ * holds them to `ts-syntax-highlighter`'s own themes, so they cannot drift from
33
+ * what the highlighter would have written inline.
34
+ *
35
+ * A component's `<style>` block is extracted from its source before anything
36
+ * is interpolated, so the two components carry this CSS as literal text rather
37
+ * than importing it. The same test holds those copies to this file.
38
+ */
39
+ /** The token classes, in the order the rules are written. */
40
+ export declare const SYNTAX_TOKENS: readonly string[];
41
+ export declare const SYNTAX_LIGHT: Readonly<Record<string, string>>;
42
+ export declare const SYNTAX_DARK: Readonly<Record<string, string>>;
43
+ /** The properties a palette sets: the panel's two, then one per token. */
44
+ export declare const SYNTAX_PROPERTIES: readonly string[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/components",
3
3
  "type": "module",
4
- "version": "0.2.854",
4
+ "version": "0.2.855",
5
5
  "description": "A modern component library built with STX, featuring headwind utility classes and TypeScript syntax highlighting.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -52,6 +52,11 @@
52
52
  "bun": "./dist/chat/controller.js",
53
53
  "import": "./dist/chat/controller.js"
54
54
  },
55
+ "./code-editor": {
56
+ "types": "./dist/ui/code-editor/editor.d.ts",
57
+ "bun": "./dist/code-editor/editor.js",
58
+ "import": "./dist/code-editor/editor.js"
59
+ },
55
60
  "./overlays": {
56
61
  "types": "./dist/utils/overlays.d.ts",
57
62
  "bun": "./dist/overlays/overlays.js",
@@ -84,9 +89,9 @@
84
89
  "dependencies": {
85
90
  "@iconify-json/f7": "^1.2.2",
86
91
  "@stacksjs/ts-css": "^0.3.11",
87
- "@stacksjs/stx": "0.2.854",
88
- "bun-plugin-stx": "0.2.854",
89
- "ts-syntax-highlighter": "^0.2.17",
92
+ "@stacksjs/stx": "0.2.855",
93
+ "bun-plugin-stx": "0.2.855",
94
+ "ts-syntax-highlighter": "^0.2.20",
90
95
  "ts-video-player": "^0.1.11"
91
96
  },
92
97
  "devDependencies": {
@@ -15,14 +15,21 @@ export const lineNumbers = $bool($props.lineNumbers, true)
15
15
  export const copyable = $bool($props.copyable, true)
16
16
  export const className = $props.className || ''
17
17
 
18
- const result = await highlight(code, { language, theme, lineNumbers })
18
+ /*
19
+ * `lineNumbers` is still not passed on. `highlight()` can number lines now (as
20
+ * a CSS counter, so they never reach a copy), but this prop defaults to true
21
+ * and has always been dropped: honouring it would put numbers on every block
22
+ * already in use. Turning it on is its own change.
23
+ */
24
+ const result = await highlight(code, { language, theme })
19
25
  export const highlightedCode = applyHeadwindClasses(result.html, className)
20
- // Exported, not rendered: no stylesheet in this package covers the
21
- // highlighter's class names, so a consumer needs these rules to see colour --
22
- // but a <style> inside a component is extracted from the component's source
23
- // before interpolation runs, so emitting it here ships an empty tag. Until that
24
- // is fixed in stx, an app includes this itself (or sets its own token styles).
26
+ // The same sheet the <style> block below ships as literal text. A <style>
27
+ // inside a component is extracted from its source before interpolation runs,
28
+ // so `{{ highlightCss }}` in one would ship an empty tag; the literal copy is
29
+ // what a page gets, and this export is for a caller that wants the string.
25
30
  export const highlightCss = result.css
31
+ export const renderedOnServer = code !== ''
32
+ export const liveClasses = `rounded-md overflow-auto text-sm leading-relaxed font-mono ${className}`.trim()
26
33
 
27
34
  /*
28
35
  * The clipboard payload, decided on the SERVER.
@@ -57,23 +64,70 @@ export const copyPayload = copyable ? code : ''
57
64
  * "1const a = 1" rather than the code. Gating is the version that cannot
58
65
  * silently corrupt what lands on the clipboard.
59
66
  */
60
- const code = {{ copyPayload }}
67
+ let code = {{ copyPayload }}
61
68
  const copied = state(false)
62
69
 
63
- async function copyToClipboard() {
64
- try {
65
- await navigator.clipboard.writeText(code)
66
- copied.set(true)
67
- setTimeout(() => copied.set(false), 2000)
68
- }
69
- catch (err) {
70
- console.error('Failed to copy code:', err)
71
- }
70
+ /*
71
+ * A block whose code is bound (`:code="snippet()"`) follows it in the browser.
72
+ *
73
+ * The new code is shown at once, as text. It is coloured as well when the page
74
+ * hands this block a highlighter: `:highlighter="highlightToHtml"`, the function
75
+ * this package exports, which runs in a browser through the highlighter's
76
+ * browser entry. It is passed in rather than imported here because an import
77
+ * in this script is bundled into every page that has a code block on it, and a
78
+ * page of static snippets should not download a tokenizer and its grammars to
79
+ * show HTML the server already coloured.
80
+ *
81
+ * `null` as the default for `code`, not the server's code: a default would put
82
+ * the snippet in this script whether or not anything needs it (#2014).
83
+ */
84
+ const liveCode = useReactiveProp('code', null, { parse: v => v })
85
+ const liveLanguage = useReactiveProp('language', {{ language }}, { parse: v => (v == null ? '' : String(v)) })
86
+ const liveHighlighter = useReactiveProp('highlighter', null, { parse: v => v })
87
+ const liveHtml = state('')
88
+ // What the server drew. A bound prop is not known there, so it drew nothing.
89
+ let renderedCode = {{ renderedOnServer }} ? null : ''
90
+ let renderedLanguage = {{ language }}
91
+ let request = 0
92
+
93
+ const themeAttribute = {{ theme }} === 'light' || {{ theme }} === 'dark' ? ' data-syntax-theme="' + {{ theme }} + '"' : ''
94
+ function plainHtml(text) {
95
+ return '<pre class="syntax"' + themeAttribute + '><code>' + String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') + '</code></pre>'
72
96
  }
97
+
98
+ effect(() => {
99
+ const next = liveCode()
100
+ const language = liveLanguage() || {{ language }}
101
+ const highlighter = liveHighlighter()
102
+ if (typeof next !== 'string') return
103
+ // The first value a bound prop delivers is the one the server drew.
104
+ if (renderedCode === null) {
105
+ renderedCode = next
106
+ return
107
+ }
108
+ if (next === renderedCode && language === renderedLanguage) return
109
+
110
+ renderedCode = next
111
+ renderedLanguage = language
112
+ if ({{ copyable }}) code = next
113
+ const mine = ++request
114
+ liveHtml.set(plainHtml(next))
115
+ if (typeof highlighter !== 'function') return
116
+
117
+ Promise.resolve()
118
+ .then(() => highlighter(next, { language, theme: {{ theme }} }))
119
+ .then((html) => {
120
+ // A later change has already been drawn, or there was nothing to colour.
121
+ if (mine === request && typeof html === 'string' && html) liveHtml.set(html)
122
+ })
123
+ .catch(() => {})
124
+ })
73
125
  </script>
74
126
 
75
127
  <div class="relative group">
76
- {!! highlightedCode !!}
128
+ {{-- The server's render, until a bound `code` changes; then the browser's. --}}
129
+ <div :show="!liveHtml()">{!! highlightedCode !!}</div>
130
+ <div class="{{ liveClasses }}" :show="liveHtml()" :html="liveHtml()"></div>
77
131
 
78
132
  @if(copyable)
79
133
  <button
@@ -107,3 +161,127 @@ async function copyToClipboard() {
107
161
  </button>
108
162
  @endif
109
163
  </div>
164
+
165
+ <style>
166
+ /* codeBlockCss() in utils/syntax-theme.ts, as literal text. A test holds the two
167
+ together; change that file and paste, not this. */
168
+ :where(:root) {
169
+ --stx-syntax-background: #ffffff;
170
+ --stx-syntax-foreground: #24292f;
171
+ --stx-syntax-keyword: #cf222e;
172
+ --stx-syntax-string: #0a3069;
173
+ --stx-syntax-comment: #6e7781;
174
+ --stx-syntax-numeric: #0550ae;
175
+ --stx-syntax-constant: #0550ae;
176
+ --stx-syntax-function: #8250df;
177
+ --stx-syntax-operator: #cf222e;
178
+ --stx-syntax-punctuation: #24292f;
179
+ --stx-syntax-type: #953800;
180
+ --stx-syntax-variable: #953800;
181
+ --stx-syntax-tag: #116329;
182
+ --stx-syntax-attribute: #0550ae;
183
+ }
184
+ @media (prefers-color-scheme: dark) {
185
+ :where(:root:not(.light)) {
186
+ --stx-syntax-background: #0d1117;
187
+ --stx-syntax-foreground: #c9d1d9;
188
+ --stx-syntax-keyword: #ff7b72;
189
+ --stx-syntax-string: #a5d6ff;
190
+ --stx-syntax-comment: #8b949e;
191
+ --stx-syntax-numeric: #79c0ff;
192
+ --stx-syntax-constant: #79c0ff;
193
+ --stx-syntax-function: #d2a8ff;
194
+ --stx-syntax-operator: #ff7b72;
195
+ --stx-syntax-punctuation: #c9d1d9;
196
+ --stx-syntax-type: #ffa657;
197
+ --stx-syntax-variable: #ffa657;
198
+ --stx-syntax-tag: #7ee787;
199
+ --stx-syntax-attribute: #79c0ff;
200
+ }
201
+ }
202
+ :where(.dark) {
203
+ --stx-syntax-background: #0d1117;
204
+ --stx-syntax-foreground: #c9d1d9;
205
+ --stx-syntax-keyword: #ff7b72;
206
+ --stx-syntax-string: #a5d6ff;
207
+ --stx-syntax-comment: #8b949e;
208
+ --stx-syntax-numeric: #79c0ff;
209
+ --stx-syntax-constant: #79c0ff;
210
+ --stx-syntax-function: #d2a8ff;
211
+ --stx-syntax-operator: #ff7b72;
212
+ --stx-syntax-punctuation: #c9d1d9;
213
+ --stx-syntax-type: #ffa657;
214
+ --stx-syntax-variable: #ffa657;
215
+ --stx-syntax-tag: #7ee787;
216
+ --stx-syntax-attribute: #79c0ff;
217
+ }
218
+ :where([data-syntax-theme="light"]) {
219
+ --stx-syntax-background: #ffffff;
220
+ --stx-syntax-foreground: #24292f;
221
+ --stx-syntax-keyword: #cf222e;
222
+ --stx-syntax-string: #0a3069;
223
+ --stx-syntax-comment: #6e7781;
224
+ --stx-syntax-numeric: #0550ae;
225
+ --stx-syntax-constant: #0550ae;
226
+ --stx-syntax-function: #8250df;
227
+ --stx-syntax-operator: #cf222e;
228
+ --stx-syntax-punctuation: #24292f;
229
+ --stx-syntax-type: #953800;
230
+ --stx-syntax-variable: #953800;
231
+ --stx-syntax-tag: #116329;
232
+ --stx-syntax-attribute: #0550ae;
233
+ }
234
+ :where([data-syntax-theme="dark"]) {
235
+ --stx-syntax-background: #0d1117;
236
+ --stx-syntax-foreground: #c9d1d9;
237
+ --stx-syntax-keyword: #ff7b72;
238
+ --stx-syntax-string: #a5d6ff;
239
+ --stx-syntax-comment: #8b949e;
240
+ --stx-syntax-numeric: #79c0ff;
241
+ --stx-syntax-constant: #79c0ff;
242
+ --stx-syntax-function: #d2a8ff;
243
+ --stx-syntax-operator: #ff7b72;
244
+ --stx-syntax-punctuation: #c9d1d9;
245
+ --stx-syntax-type: #ffa657;
246
+ --stx-syntax-variable: #ffa657;
247
+ --stx-syntax-tag: #7ee787;
248
+ --stx-syntax-attribute: #79c0ff;
249
+ }
250
+ .tok-keyword { color: var(--stx-syntax-keyword); }
251
+ .tok-string { color: var(--stx-syntax-string); }
252
+ .tok-comment { color: var(--stx-syntax-comment); }
253
+ .tok-numeric { color: var(--stx-syntax-numeric); }
254
+ .tok-constant { color: var(--stx-syntax-constant); }
255
+ .tok-function { color: var(--stx-syntax-function); }
256
+ .tok-operator { color: var(--stx-syntax-operator); }
257
+ .tok-punctuation { color: var(--stx-syntax-punctuation); }
258
+ .tok-type { color: var(--stx-syntax-type); }
259
+ .tok-variable { color: var(--stx-syntax-variable); }
260
+ .tok-tag { color: var(--stx-syntax-tag); }
261
+ .tok-attribute { color: var(--stx-syntax-attribute); }
262
+ .tok-comment { font-style: italic; }
263
+ .syntax {
264
+ margin: 0;
265
+ padding: 1rem;
266
+ overflow-x: auto;
267
+ border-radius: 0.375rem;
268
+ background-color: var(--stx-syntax-background);
269
+ color: var(--stx-syntax-foreground);
270
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
271
+ font-size: 0.875rem;
272
+ line-height: 1.5;
273
+ tab-size: 2;
274
+ }
275
+ .syntax code { display: block; font-family: inherit; }
276
+ .syntax[data-line-numbers] { counter-reset: stx-syntax-line; }
277
+ .syntax[data-line-numbers] .line::before {
278
+ counter-increment: stx-syntax-line;
279
+ content: counter(stx-syntax-line);
280
+ display: inline-block;
281
+ width: 2.5em;
282
+ margin-right: 1em;
283
+ text-align: right;
284
+ opacity: 0.5;
285
+ user-select: none;
286
+ }
287
+ </style>
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ export * from './ui/card'
29
29
 
30
30
  export * from './ui/checkbox'
31
31
  export * from './ui/choice-chips'
32
+ export * from './ui/code-editor'
32
33
  export * from './ui/combobox'
33
34
  export * from './ui/command-palette'
34
35
  export * from './ui/dialog'
@@ -78,6 +79,7 @@ export * from './utils/i18n'
78
79
  export * from './utils/keep-alive'
79
80
  export * from './utils/lazy-loading'
80
81
  export * from './utils/prop-validation'
82
+ export * from './utils/syntax-theme'
81
83
  export * from './utils/theme'
82
84
 
83
85
  // Types