@fabiocv/component-code 0.0.0-stage → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fabio Azevedo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,151 @@
1
- # Temporary Holding Version
1
+ # component-code
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A React component beside the code that makes it, where every value in the code
4
+ is a control. Give it your components in `scope` and the code renders as its own
5
+ preview, so the two cannot differ.
6
+
7
+ About 8 kB gzipped, with no dependencies beyond React.
8
+
9
+ ```sh
10
+ npm install @fabiocv/component-code
11
+ ```
12
+
13
+ ```tsx
14
+ import { ComponentCode } from '@fabiocv/component-code';
15
+ import { Button } from './Button';
16
+
17
+ <ComponentCode
18
+ interactive
19
+ file="Button.tsx"
20
+ scope={{ Button }}
21
+ controls={{ size: ['small', 'medium', 'large'] }}
22
+ code={`
23
+ <Button size="medium" disabled={false}>
24
+ Save
25
+ </Button>
26
+ `}
27
+ />;
28
+ ```
29
+
30
+ The component adds its own stylesheet, so there is nothing else to import.
31
+
32
+ ## Props
33
+
34
+ | Prop | What it sets |
35
+ | ------------- | --------------------------------------------------------------------------------------------------------- |
36
+ | `code` | The code as it is written. The blank lines around it and its shared indent are dropped. |
37
+ | `scope` | What the code can name: your components and values. With it, the preview is the code itself, rendered. |
38
+ | `interactive` | Makes each string, number, boolean and line of text in the code a control. |
39
+ | `controls` | How a prop is changed, by its name or by `Element.prop`. |
40
+ | `onChange` | Called with `{ prop, value, code }` as the reader changes a value. |
41
+ | `children` | The preview, for code that cannot run from its text, such as code with a hook. Use it instead of `scope`. |
42
+ | `file` | The file named in the code's tab. `Code` when left out. |
43
+ | `theme` | `light` or `dark`. Without it, the page's `color-scheme` decides. |
44
+ | `note` | A line shown from an info icon beside reset, once the reader changes a value. |
45
+ | `className` | A class for the outer element. |
46
+
47
+ ## What the code can hold
48
+
49
+ The code is read, not run. It can hold elements, fragments, props, spreads,
50
+ text, strings, numbers, booleans, `null`, `undefined`, lists, objects, other
51
+ elements and the names in `scope`, with their members, such as `Card.Title` or
52
+ `post.title`. A lowercase tag is the browser's own element.
53
+
54
+ A function, a call or a condition goes in through `scope` under a name. Code
55
+ that cannot run says why in place of the preview, and so does a component that
56
+ throws, until the code changes.
57
+
58
+ ## Controls
59
+
60
+ With `interactive`, each element's strings, numbers and booleans are controls,
61
+ and its text where that is all it holds, on one line.
62
+
63
+ | Value | Control | In `controls` |
64
+ | ------- | ------------------------------------------------------------- | -------------------- |
65
+ | Number | Dragged sideways, or stepped with the arrow keys. Shift: ten. | `{ min, max, step }` |
66
+ | Boolean | Pressed to switch. | |
67
+ | Text | Typed over in place. Enter or Escape leaves it. | |
68
+ | Option | Picked from a menu, which stays open to try the others. | A list of values |
69
+ | Any | Left as written. | `false` |
70
+
71
+ A number steps by its last decimal place unless `step` is set: `1` for `8`,
72
+ `0.1` for `0.5`. A prop written alone, such as `open`, is shown as `open={true}`
73
+ so it can switch.
74
+
75
+ ## Styling
76
+
77
+ It follows the page's `color-scheme`, or `theme`. Each colour and font is a
78
+ custom property on `.cc`, which a page can set:
79
+
80
+ ```css
81
+ .cc {
82
+ --cc-mono: 'JetBrains Mono', monospace;
83
+ --cc-tag: light-dark(#116329, #7ee787);
84
+ }
85
+ ```
86
+
87
+ | Property | Sets |
88
+ | ------------------------------------------------------------------------------------- | -------------------------------------------------- |
89
+ | `--cc-surface`, `--cc-subtle`, `--cc-sunken` | The preview, frame and code grounds |
90
+ | `--cc-foreground`, `--cc-secondary`, `--cc-muted`, `--cc-disabled` | Text and icons |
91
+ | `--cc-text`, `--cc-line`, `--cc-tag`, `--cc-attribute`, `--cc-string`, `--cc-keyword` | Code colours |
92
+ | `--cc-sans`, `--cc-mono` | Fonts, Geist and Geist Mono when the page has them |
93
+
94
+ When rendering on a server, put `styles` in the page's head so the first paint
95
+ is styled:
96
+
97
+ ```tsx
98
+ import { styles } from '@fabiocv/component-code';
99
+
100
+ <style id="component-code">{styles}</style>;
101
+ ```
102
+
103
+ ## HTML, CSS and JS
104
+
105
+ For a canvas, an SVG or anything without React, import `ComponentCode` from
106
+ `@fabiocv/component-code/html` and give it files. They run together as one page
107
+ in a sandboxed frame, with a tab for each file.
108
+
109
+ ```tsx
110
+ import { ComponentCode } from '@fabiocv/component-code/html';
111
+
112
+ <ComponentCode
113
+ files={{
114
+ 'index.html': '<canvas></canvas>',
115
+ 'style.css': ':root { --speed: 1; }',
116
+ 'script.js': 'const gap = 16;',
117
+ }}
118
+ controls={{ '--speed': { min: 0, max: 4, step: 0.1 }, gap: true }}
119
+ />;
120
+ ```
121
+
122
+ | Prop | What it sets |
123
+ | ----------- | --------------------------------------------------------------------------------------------------------- |
124
+ | `files` | The files by name, each in its own tab: `.html`, `.css` and `.js`. The HTML is the page's body. |
125
+ | `controls` | The values the reader can change, by name. Each takes `true`, a list of options, or `{ min, max, step }`. |
126
+ | `onChange` | Called with `{ file, prop, value, code }` as the reader changes a value. |
127
+ | `theme` | `light` or `dark`. Without it, the page's `color-scheme` decides, and the frame takes the same. |
128
+ | `note` | A line shown from an info icon beside reset, once the reader changes a value. |
129
+ | `className` | A class for the outer element. |
130
+
131
+ A value is named by its attribute, as `r` or `circle.r`, by its CSS property or
132
+ custom property, as `--speed`, or by the JS `const`, `let` or `var` it sets to a
133
+ number, string or boolean. A CSS number keeps its unit.
134
+
135
+ A CSS value changes in place as the reader drags it, so a script that reads
136
+ custom properties each frame follows along. A change to the HTML or JS runs the
137
+ page again, loading it behind the one shown so the preview does not flash. An
138
+ error in the page shows in its place.
139
+
140
+ When rendering on a server, put its `styles` in the page's head with the id
141
+ `component-code-html`.
142
+
143
+ ## In the chat
144
+
145
+ [`@fabiocv/component-code-mcp`](https://www.npmjs.com/package/@fabiocv/component-code-mcp)
146
+ shows a component in Component Code in Claude, ChatGPT, VS Code and other MCP
147
+ hosts.
148
+
149
+ ## Licence
150
+
151
+ MIT
@@ -0,0 +1,57 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ControlOptions } from './controls';
3
+ import type { Scope } from './run';
4
+ /**
5
+ * The stylesheet, which the component adds itself. Put it in the page's head
6
+ * when rendering on a server.
7
+ */
8
+ export declare const styles: string;
9
+ export type { ControlOptions, Scope };
10
+ /** A prop the reader changed, and what to. */
11
+ export type ComponentCodeChange = {
12
+ prop: string;
13
+ value: string | number | boolean;
14
+ /** The whole code after the change. */
15
+ code: string;
16
+ };
17
+ export type ComponentCodeProps = {
18
+ /**
19
+ * The code as it is written. The blank lines around it and its shared
20
+ * indent are dropped.
21
+ */
22
+ code: string;
23
+ /** The file named in the code's tab. */
24
+ file?: string;
25
+ /** Sets light or dark. Without it, the page's `color-scheme` decides. */
26
+ theme?: 'light' | 'dark';
27
+ /** A line from an info icon beside reset, once the reader changes a value. */
28
+ note?: string;
29
+ className?: string;
30
+ } & ({
31
+ /**
32
+ * What the code can name. With it, the preview is the code itself,
33
+ * rendered: elements, props, text, strings, numbers, booleans, lists,
34
+ * objects and these names.
35
+ */
36
+ scope: Scope;
37
+ /** Makes each value in the code a control the reader can change. */
38
+ interactive?: boolean;
39
+ /** How a prop is changed, by its name or by `Element.prop`. */
40
+ controls?: Readonly<Record<string, ControlOptions>>;
41
+ /** Called as the reader changes a prop. */
42
+ onChange?: (change: ComponentCodeChange) => void;
43
+ children?: undefined;
44
+ } | {
45
+ /** The preview, for code that cannot run from its text, such as a hook. */
46
+ children: ReactNode;
47
+ scope?: undefined;
48
+ interactive?: undefined;
49
+ controls?: undefined;
50
+ onChange?: undefined;
51
+ });
52
+ /**
53
+ * A component beside the code that makes it. With `scope` the preview is
54
+ * rendered from the code, so the two cannot differ, and `interactive` lets
55
+ * the reader change its values in the code.
56
+ */
57
+ export declare function ComponentCode({ code, file, theme, note, className, scope, interactive, controls: options, onChange, children, }: ComponentCodeProps): import("react").JSX.Element;
@@ -0,0 +1,6 @@
1
+ 'use client';
2
+ var C=new Set("as async await break case catch class const continue default delete do else enum export extends false finally for from function if import in instanceof interface let new null of return satisfies static switch this throw true try type typeof undefined var void while yield".split(" ")),N=/^(|[(,=:?[{}>&|!]|return)$/;function H(e){let d=[],a=[{in:"code",depth:0}],t=0,i="",s=n=>(n.lastIndex=t,n.exec(e)?.[0]??""),p=(n,c)=>{c&&d.push({ink:n,start:t,end:t+c}),t+=c},u=n=>{let c=t+1;for(;c<e.length&&e[c]!==n;)c+=e[c]==="\\"?2:1;p("string",Math.min(c+1,e.length)-t)};for(;t<e.length;){let n=a[a.length-1],c=e[t];if(n.in==="text"){if(c==="{")t++,a.push({in:"code",depth:0});else if(c==="<")t++,e[t]==="/"?(t++,p("tag",s(/[\w$.:-]*/y).length),t=Math.max(t,e.indexOf(">",t)+1),a.pop()):a.push({in:"tag",named:!1});else{let g=e.slice(t).search(/[<{]/);t=g<0?e.length:t+g}continue}if(n.in==="tag"){let g=s(/[\w$.:-]+/y);g?p(n.named?"attribute":"tag",g.length):c==='"'||c==="'"?u(c):c==="{"?(t++,a.push({in:"code",depth:0})):c===">"?(t++,a[a.length-1]={in:"text"}):e.startsWith("/>",t)?(t+=2,a.pop()):t++,n.named=!0;continue}let o=s(/\s+|\/\/.*|\/\*[\s\S]*?(\*\/|$)/y);if(o){t+=o.length;continue}let l=s(/[A-Za-z_$][\w$]*/y);if(l){let g=e.slice(t+l.length).match(/^\s*(\S)/)?.[1],v=C.has(l)?"keyword":g==="("||/^[A-Z]/.test(l)?"tag":e[t-1]==="."||g===":"&&i!=="?"?"attribute":void 0;v?p(v,l.length):t+=l.length,i=l==="return"?l:"name";continue}let h=s(/\d[\d_]*\.?\d*(e[+-]?\d+)?n?|\.\d+/iy);if(h){p("keyword",h.length),i="name";continue}if(c==='"'||c==="'"||c==="`"){u(c),i="name";continue}if(c==="<"&&N.test(i)&&/[A-Za-z>]/.test(e[t+1]??"")){t++,a.push({in:"tag",named:e[t]===">"}),e[t]===">"&&(t++,a[a.length-1]={in:"text"});continue}if(c==="{"&&n.depth++,c==="}"){if(n.depth===0&&a.length>1){t++,a.pop();continue}n.depth--}i=e.startsWith("&&",t)||e.startsWith("||",t)?"&":c,t++}return d}import{useEffect as M,useInsertionEffect as $,useRef as k,useState as y}from"react";var x='.cc{--cc-surface: light-dark(oklch(100% 0 0), oklch(17.5% 0 0));--cc-subtle: light-dark(oklch(93% 0 0), oklch(24.5% 0 0));--cc-sunken: light-dark(oklch(89.5% 0 0), oklch(21% 0 0));--cc-foreground: light-dark( oklch(22.7% .006 271.2), oklch(92.3% .004 286.3) );--cc-secondary: light-dark( oklch(41.8% .014 274.6), oklch(78.2% .016 281.9) );--cc-muted: light-dark(oklch(52% .044 267.6), oklch(67.3% .028 276.2));--cc-disabled: light-dark(oklch(72% .01 270), oklch(48% .01 280));--cc-text: light-dark(oklch(49% .04 268), oklch(67.3% .028 276.2));--cc-line: light-dark(oklch(59% .02 270), oklch(51% .02 276));--cc-tag: light-dark(oklch(46% .185 145.3), oklch(84.4% .185 145.3));--cc-attribute: light-dark(oklch(46% .088 229.9), oklch(85.7% .088 229.9));--cc-string: light-dark(oklch(46% .191 32.2), oklch(71.2% .191 32.2));--cc-keyword: light-dark(oklch(46% .2 317.2), oklch(76.9% .2 317.2));--cc-sans: Geist, ui-sans-serif, system-ui, sans-serif;--cc-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;--cc-ease: .24s cubic-bezier(.2, .9, .3, 1);--copy: 0;--reset: 0;position:relative;box-sizing:border-box;width:100%;overflow:hidden;container-type:inline-size;border-radius:8px;outline:1px solid var(--cc-subtle);background:var(--cc-subtle);color:var(--cc-foreground);font:16px/24px var(--cc-sans);text-align:left;-webkit-font-smoothing:antialiased}.cc[data-theme=light]{color-scheme:light}.cc[data-theme=dark]{color-scheme:dark}.cc *,.cc *:before,.cc *:after{box-sizing:inherit}.cc-frame{display:grid;gap:2px;padding:2px;background:var(--cc-surface)}@container (min-width: 640px){.cc-frame{grid-template-columns:repeat(2,minmax(0,1fr))}}.cc-preview{display:grid;place-items:center;min-width:0;padding:48px 24px 24px}.cc-problem{margin:0;color:var(--cc-muted);font:14px/20px var(--cc-sans);text-align:center}.cc-tab{--inset: 0px;position:absolute;top:calc(var(--inset) * -1);left:calc(var(--inset) * -1);display:flex;align-items:center;height:24px;padding:0 8px;border-bottom-right-radius:6px;background:var(--ground);color:var(--cc-muted);font:12px/16px var(--cc-sans);white-space:nowrap;pointer-events:none}.cc-tab:before,.cc-tab:after{content:"";position:absolute;width:6px;height:6px;background:radial-gradient(circle at 100% 100%,transparent 6px,var(--ground) 6.5px)}.cc-tab:before{top:var(--inset);left:100%}.cc-tab:after{top:100%;left:var(--inset)}.cc>.cc-tab{--ground: var(--cc-subtle)}.cc-code{--ground: var(--cc-surface);--tint: var(--cc-text);position:relative;min-width:0;padding-top:22px;border-radius:6px;background:var(--cc-sunken);color:var(--cc-text);font:14px/24px var(--cc-mono)}.cc-code>.cc-tab{--inset: 2px}.cc-body{display:flex}.cc-lines{flex-shrink:0;padding:16px 4px 16px 16px;color:var(--cc-line);text-align:right;white-space:pre;user-select:none}.cc-scroll{flex-grow:1;min-width:0;padding:16px 16px 16px 4px;overflow-x:auto;scrollbar-width:thin;scrollbar-color:var(--cc-disabled) transparent}.cc .cc-scroll>code{all:unset;display:block;width:max-content;min-width:100%;white-space:pre;tab-size:2}.cc-tag{color:var(--cc-tag)}.cc-attribute{color:var(--cc-attribute)}.cc-string{--tint: var(--cc-string);color:var(--cc-string)}.cc-keyword{--tint: var(--cc-keyword);color:var(--cc-keyword)}.cc-box{all:unset;display:inline-block;margin:0 -2px;padding:0 4px;border-radius:4px;background:color-mix(in srgb,var(--tint) 14%,transparent);line-height:20px;white-space:pre;cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent}.cc-box:hover,.cc-box:focus-within,.cc-box[aria-expanded=true]{background:color-mix(in srgb,var(--tint) 28%,transparent)}.cc-box:focus-visible,.cc-action:focus-visible,.cc-menu>button:focus-visible{outline:2px solid currentColor;outline-offset:-2px}.cc-scrub{cursor:ew-resize;touch-action:pan-y}.cc-field{display:inline-grid;min-width:8px;cursor:text}.cc-field:after{content:attr(data-value);grid-area:1 / 1;visibility:hidden;white-space:pre}.cc-field>input{all:unset;grid-area:1 / 1;width:100%;min-width:0}.cc-menu{position:fixed;inset:auto;display:none;min-width:96px;margin:0;padding:2px;border:0;font:14px/20px var(--cc-mono)}.cc-menu,.cc-code:after{border-radius:8px;background:var(--cc-subtle);color:var(--cc-secondary);box-shadow:0 8px 24px #0000001f}.cc-menu:popover-open{display:grid}.cc-menu>button{all:unset;display:flex;align-items:center;gap:16px;height:32px;padding:0 8px;border-radius:6px;white-space:pre;cursor:pointer}.cc-menu>button:is(:hover,:focus){background:var(--cc-sunken);color:var(--cc-foreground)}.cc-menu>[aria-checked=true]:after{content:"\\2713";margin-left:auto;color:var(--cc-muted)}.cc-code:is(:hover,:has(:focus-visible)){--copy: 1}@media(hover:none){.cc-code{--copy: 1}}.cc-changed{--reset: 1}.cc-actions{--open: max(var(--copy), var(--reset));top:-2px;right:-2px;left:auto;padding:0 calc(var(--open) * 4px) 0 0;border-radius:0 0 0 6px;pointer-events:auto;transition:padding var(--cc-ease)}.cc-actions:before,.cc-actions:after{left:auto;background:radial-gradient(circle at 0 100%,transparent 6px,var(--ground) 6.5px);opacity:var(--open);transition:opacity var(--cc-ease)}.cc-actions:before{right:100%}.cc-actions:after{right:var(--inset)}.cc-slot{--shown: var(--copy);display:flex;justify-content:flex-end;width:calc(var(--shown) * 24px);overflow:hidden;transition:width var(--cc-ease)}.cc-note,.cc-reset{--shown: var(--reset)}.cc-action{all:unset;display:grid;place-items:center;flex-shrink:0;width:20px;height:20px;border-radius:4px;color:var(--cc-muted);cursor:pointer;transform:translate(calc((1 - var(--shown)) * 24px));transition:transform var(--cc-ease)}.cc-action:hover{color:var(--cc-foreground)}.cc-code:after{content:attr(data-note);position:absolute;top:26px;right:4px;padding:4px 8px;font:12px/16px var(--cc-sans);white-space:nowrap;opacity:0;transition:opacity var(--cc-ease)}.cc-code:has(.cc-note :is(:hover,:focus)):after{opacity:1}@media(prefers-reduced-motion:reduce){.cc *{transition:none!important}}';import{Fragment as O,jsx as r,jsxs as f}from"react/jsx-runtime";var W=x;function B(e,d){$(()=>{if(document.getElementById(e))return;let a=document.createElement("style");a.id=e,a.textContent=d,document.head.prepend(a)},[])}function _(e){let d=e.replace(/^\s*\n/,"").trimEnd().split(`
3
+ `),a=Math.min(...d.filter(t=>t.trim()).map(t=>t.search(/\S/)));return d.map(t=>t.slice(a)).join(`
4
+ `)}var m=e=>e.kind==="boolean"||typeof e.value=="number"?"cc-box cc-keyword":e.quote?"cc-box cc-string":"cc-box";function b({d:e}){return r("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:r("path",{d:e})})}var I="M8 7.5h7.5v8H8zM12 4.5H4.5v8",R="M5 10.5l3 3 7-7",T="M5 8.5a5.5 5.5 0 1 1 .5 4.5M5 4.5v4h4",P="M16 10a6 6 0 1 1-12 0a6 6 0 0 1 12 0M10 9.5V13m0-6v.01";function S({control:e,onChange:d,written:a}){let{min:t=-1/0,max:i=1/0,step:s}=e,p=e.value,u=k(null),n=i-t<1/0?Math.min(12,Math.max(2,240*s/(i-t))):6,c=o=>{o=Math.min(i,Math.max(t,o)),o!==p&&d(o)};return r("span",{className:`${m(e)} cc-scrub`,role:"slider",tabIndex:0,"aria-label":e.prop,"aria-valuenow":p,"aria-valuemin":t>-1/0?t:void 0,"aria-valuemax":i<1/0?i:void 0,onPointerDown:o=>{o.currentTarget.setPointerCapture(o.pointerId),u.current={x:o.clientX,value:p}},onPointerMove:o=>{if(u.current){let l=Math.round((o.clientX-u.current.x)/n);c(u.current.value+l*s)}},onPointerUp:()=>u.current=null,onPointerCancel:()=>u.current=null,onKeyDown:o=>{let l=o.shiftKey?s*10:s,h={ArrowUp:p+l,ArrowRight:p+l,ArrowDown:p-l,ArrowLeft:p-l,Home:t,End:i}[o.key];h!==void 0&&Number.isFinite(h)&&(o.preventDefault(),c(h))},children:a})}function A({control:e,onChange:d}){let a=`${e.value}`,{quote:t}=e;return f("label",{className:m(e),children:[t,r("span",{className:"cc-field","data-value":a,children:r("input",{size:1,value:a,"aria-label":e.prop,spellCheck:!1,onChange:i=>d(i.target.value),onKeyDown:i=>{(i.key==="Enter"||i.key==="Escape")&&i.currentTarget.blur()}})}),t]})}function z({control:e,onChange:d,written:a}){let t=k(null),[i,s]=y(!1),p=n=>{let c=typeof n=="string"?e.quote:"";return c+n+c},u=()=>[...t.current.children];return M(()=>{let n=t.current,c=l=>s(l.newState==="open"),o=()=>n.matches(":popover-open")&&n.hidePopover();return n.addEventListener("toggle",c),addEventListener("scroll",o,!0),()=>{n.removeEventListener("toggle",c),removeEventListener("scroll",o,!0)}},[]),f(O,{children:[r("button",{type:"button",className:m(e),"aria-haspopup":"menu","aria-expanded":i,"aria-label":e.prop,onClick:n=>{let c=t.current,{left:o,bottom:l}=n.currentTarget.getBoundingClientRect();c.style.left=`${o}px`,c.style.top=`${l+4}px`,c.showPopover(),u().find(h=>h.getAttribute("aria-checked")==="true")?.focus()},children:a}),r("div",{ref:t,className:"cc-menu",popover:"auto",role:"menu",onKeyDown:n=>{let c=u(),o=c.indexOf(document.activeElement),l={ArrowDown:1,ArrowUp:-1}[n.key];l&&(n.preventDefault(),c[(o+l+c.length)%c.length].focus())},children:e.options.map(n=>r("button",{type:"button",role:"menuitemradio","aria-checked":n===e.value,onClick:()=>d(n),children:p(n)},`${n}`))})]})}function D({source:e,tokens:d,controls:a,onChange:t}){let i=[],s=0,p=0,u=n=>{for(;s<n;){for(;p<d.length&&d[p].end<=s;)p++;let c=d[p];if(c&&c.start<=s){let o=Math.min(c.end,n);i.push(r("span",{className:`cc-${c.ink}`,children:e.slice(s,o)},s)),s=o}else{let o=Math.min(c?.start??n,n);i.push(e.slice(s,o)),s=o}}};return a.forEach((n,c)=>{u(n.range.start);let o=e.slice(n.range.start,n.range.end),l={control:n,written:o,onChange:h=>t(n,h)};i.push(n.kind==="boolean"?r("button",{type:"button",className:m(n),"aria-label":n.prop,"aria-pressed":n.value,onClick:()=>l.onChange(!n.value),children:o},`c${c}`):n.kind==="number"?r(S,{...l},`c${c}`):n.kind==="option"?r(z,{...l},`c${c}`):r(A,{...l},`c${c}`)),s=n.range.end}),u(e.length),f("div",{className:"cc-body",children:[r("div",{className:"cc-lines","aria-hidden":!0,children:e.split(`
5
+ `).map((n,c)=>c+1).join(`
6
+ `)}),r("div",{className:"cc-scroll",children:r("code",{children:i})})]})}function L({source:e,changed:d,note:a,onReset:t}){let[i,s]=y(!1);return f("div",{className:`cc-tab cc-actions${d?" cc-changed":""}`,children:[a&&r("span",{className:"cc-slot cc-note",children:r("button",{type:"button",className:"cc-action","aria-label":a,tabIndex:d?0:-1,children:r(b,{d:P})})}),r("span",{className:"cc-slot",children:r("button",{type:"button",className:"cc-action","aria-label":i?"Copied":"Copy code",onClick:()=>navigator.clipboard.writeText(e).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}),children:r(b,{d:i?R:I})})}),r("span",{className:"cc-slot cc-reset",children:r("button",{type:"button",className:"cc-action","aria-label":"Reset code",tabIndex:d?0:-1,onClick:t,children:r(b,{d:T})})})]})}function j({className:e,theme:d,preview:a,tab:t,source:i,changed:s,note:p,onReset:u,...n}){return f("div",{className:e?`cc ${e}`:"cc","data-theme":d,children:[f("div",{className:"cc-frame",children:[r("div",{className:"cc-preview",children:a}),f("div",{className:"cc-code","data-note":p,children:[t,r(L,{source:i,changed:s,note:p,onReset:u}),r(D,{source:i,...n})]})]}),r("div",{className:"cc-tab",children:"Preview"})]})}var w=e=>`${e}`.split(".")[1]?.length??0,Z=e=>10**-w(e),G=(e,d)=>`${+e.toFixed(w(d))}`;export{Z as a,G as b,H as c,W as d,B as e,_ as f,j as g};
@@ -0,0 +1,6 @@
1
+ 'use client';
2
+ var C=new Set("as async await break case catch class const continue default delete do else enum export extends false finally for from function if import in instanceof interface let new null of return satisfies static switch this throw true try type typeof undefined var void while yield".split(" ")),E=/^(|[(,=:?[{}>&|!]|return)$/;function O(t){let l=[],o=[{in:"code",depth:0}],e=0,i="",d=c=>(c.lastIndex=e,c.exec(t)?.[0]??""),p=(c,n)=>{n&&l.push({ink:c,start:e,end:e+n}),e+=n},u=c=>{let n=e+1;for(;n<t.length&&t[n]!==c;)n+=t[n]==="\\"?2:1;p("string",Math.min(n+1,t.length)-e)};for(;e<t.length;){let c=o[o.length-1],n=t[e];if(c.in==="text"){if(n==="{")e++,o.push({in:"code",depth:0});else if(n==="<")e++,t[e]==="/"?(e++,p("tag",d(/[\w$.:-]*/y).length),e=Math.max(e,t.indexOf(">",e)+1),o.pop()):o.push({in:"tag",named:!1});else{let g=t.slice(e).search(/[<{]/);e=g<0?t.length:e+g}continue}if(c.in==="tag"){let g=d(/[\w$.:-]+/y);g?p(c.named?"attribute":"tag",g.length):n==='"'||n==="'"?u(n):n==="{"?(e++,o.push({in:"code",depth:0})):n===">"?(e++,o[o.length-1]={in:"text"}):t.startsWith("/>",e)?(e+=2,o.pop()):e++,c.named=!0;continue}let a=d(/\s+|\/\/.*|\/\*[\s\S]*?(\*\/|$)/y);if(a){e+=a.length;continue}let r=d(/[A-Za-z_$][\w$]*/y);if(r){let g=t.slice(e+r.length).match(/^\s*(\S)/)?.[1],b=C.has(r)?"keyword":g==="("||/^[A-Z]/.test(r)?"tag":t[e-1]==="."||g===":"&&i!=="?"?"attribute":void 0;b?p(b,r.length):e+=r.length,i=r==="return"?r:"name";continue}let h=d(/\d[\d_]*\.?\d*(e[+-]?\d+)?n?|\.\d+/iy);if(h){p("keyword",h.length),i="name";continue}if(n==='"'||n==="'"||n==="`"){u(n),i="name";continue}if(n==="<"&&E.test(i)&&/[A-Za-z>]/.test(t[e+1]??"")){e++,o.push({in:"tag",named:t[e]===">"}),t[e]===">"&&(e++,o[o.length-1]={in:"text"});continue}if(n==="{"&&c.depth++,n==="}"){if(c.depth===0&&o.length>1){e++,o.pop();continue}c.depth--}i=t.startsWith("&&",e)||t.startsWith("||",e)?"&":n,e++}return l}import{useEffect as M,useInsertionEffect as $,useRef as k,useState as y}from"react";var v='.cc{--cc-surface: light-dark(oklch(100% 0 0), oklch(17.5% 0 0));--cc-subtle: light-dark(oklch(93% 0 0), oklch(24.5% 0 0));--cc-sunken: light-dark(oklch(89.5% 0 0), oklch(21% 0 0));--cc-foreground: light-dark( oklch(22.7% .006 271.2), oklch(92.3% .004 286.3) );--cc-secondary: light-dark( oklch(41.8% .014 274.6), oklch(78.2% .016 281.9) );--cc-muted: light-dark(oklch(52% .044 267.6), oklch(67.3% .028 276.2));--cc-disabled: light-dark(oklch(72% .01 270), oklch(48% .01 280));--cc-text: light-dark(oklch(49% .04 268), oklch(67.3% .028 276.2));--cc-line: light-dark(oklch(59% .02 270), oklch(51% .02 276));--cc-tag: light-dark(oklch(46% .185 145.3), oklch(84.4% .185 145.3));--cc-attribute: light-dark(oklch(46% .088 229.9), oklch(85.7% .088 229.9));--cc-string: light-dark(oklch(46% .191 32.2), oklch(71.2% .191 32.2));--cc-keyword: light-dark(oklch(46% .2 317.2), oklch(76.9% .2 317.2));--cc-sans: Geist, ui-sans-serif, system-ui, sans-serif;--cc-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;--cc-ease: .24s cubic-bezier(.2, .9, .3, 1);--copy: 0;--reset: 0;position:relative;box-sizing:border-box;width:100%;overflow:hidden;container-type:inline-size;border-radius:8px;outline:1px solid var(--cc-subtle);background:var(--cc-subtle);color:var(--cc-foreground);font:16px/24px var(--cc-sans);text-align:left;-webkit-font-smoothing:antialiased}.cc[data-theme=light]{color-scheme:light}.cc[data-theme=dark]{color-scheme:dark}.cc *,.cc *:before,.cc *:after{box-sizing:inherit}.cc-frame{display:grid;gap:2px;padding:2px;background:var(--cc-surface)}@container (min-width: 640px){.cc-frame{grid-template-columns:repeat(2,minmax(0,1fr))}}.cc-preview{display:grid;place-items:center;min-width:0;padding:48px 24px 24px}.cc-problem{margin:0;color:var(--cc-muted);font:14px/20px var(--cc-sans);text-align:center}.cc-tab{--inset: 0px;position:absolute;top:calc(var(--inset) * -1);left:calc(var(--inset) * -1);display:flex;align-items:center;height:24px;padding:0 8px;border-bottom-right-radius:6px;background:var(--ground);color:var(--cc-muted);font:12px/16px var(--cc-sans);white-space:nowrap;pointer-events:none}.cc-tab:before,.cc-tab:after{content:"";position:absolute;width:6px;height:6px;background:radial-gradient(circle at 100% 100%,transparent 6px,var(--ground) 6.5px)}.cc-tab:before{top:var(--inset);left:100%}.cc-tab:after{top:100%;left:var(--inset)}.cc>.cc-tab{--ground: var(--cc-subtle)}.cc-code{--ground: var(--cc-surface);--tint: var(--cc-text);position:relative;min-width:0;padding-top:22px;border-radius:6px;background:var(--cc-sunken);color:var(--cc-text);font:14px/24px var(--cc-mono)}.cc-code>.cc-tab{--inset: 2px}.cc-body{display:flex}.cc-lines{flex-shrink:0;padding:16px 4px 16px 16px;color:var(--cc-line);text-align:right;white-space:pre;user-select:none}.cc-scroll{flex-grow:1;min-width:0;padding:16px 16px 16px 4px;overflow-x:auto;scrollbar-width:thin;scrollbar-color:var(--cc-disabled) transparent}.cc .cc-scroll>code{all:unset;display:block;width:max-content;min-width:100%;white-space:pre;tab-size:2}.cc-tag{color:var(--cc-tag)}.cc-attribute{color:var(--cc-attribute)}.cc-string{--tint: var(--cc-string);color:var(--cc-string)}.cc-keyword{--tint: var(--cc-keyword);color:var(--cc-keyword)}.cc-box{all:unset;display:inline-block;margin:0 -2px;padding:0 4px;border-radius:4px;background:color-mix(in srgb,var(--tint) 14%,transparent);line-height:20px;white-space:pre;cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent}.cc-box:hover,.cc-box:focus-within,.cc-box[aria-expanded=true]{background:color-mix(in srgb,var(--tint) 28%,transparent)}.cc-box:focus-visible,.cc-action:focus-visible,.cc-menu>button:focus-visible{outline:2px solid currentColor;outline-offset:-2px}.cc-scrub{cursor:ew-resize;touch-action:pan-y}.cc-field{display:inline-grid;min-width:8px;cursor:text}.cc-field:after{content:attr(data-value);grid-area:1 / 1;visibility:hidden;white-space:pre}.cc-field>input{all:unset;grid-area:1 / 1;width:100%;min-width:0}.cc-menu{position:fixed;inset:auto;display:none;min-width:96px;margin:0;padding:2px;border:0;border-radius:8px;background:var(--cc-subtle);color:var(--cc-secondary);font:14px/20px var(--cc-mono);box-shadow:0 8px 24px #0000001f}.cc-menu:popover-open{display:grid}.cc-menu>button{all:unset;display:flex;align-items:center;gap:16px;height:32px;padding:0 8px;border-radius:6px;white-space:pre;cursor:pointer}.cc-menu>button:is(:hover,:focus){background:var(--cc-sunken);color:var(--cc-foreground)}.cc-menu>[aria-checked=true]:after{content:"\\2713";margin-left:auto;color:var(--cc-muted)}.cc-code:is(:hover,:has(:focus-visible)){--copy: 1}@media(hover:none){.cc-code{--copy: 1}}.cc-changed{--reset: 1}.cc-actions{--open: max(var(--copy), var(--reset));top:-2px;right:-2px;left:auto;padding:0 calc(var(--open) * 4px) 0 0;border-radius:0 0 0 6px;pointer-events:auto;transition:padding var(--cc-ease)}.cc-actions:before,.cc-actions:after{left:auto;background:radial-gradient(circle at 0 100%,transparent 6px,var(--ground) 6.5px);opacity:var(--open);transition:opacity var(--cc-ease)}.cc-actions:before{right:100%}.cc-actions:after{right:var(--inset)}.cc-slot{--shown: var(--copy);display:flex;justify-content:flex-end;width:calc(var(--shown) * 24px);overflow:hidden;transition:width var(--cc-ease)}.cc-slot+.cc-slot{--shown: var(--reset)}.cc-action{all:unset;display:grid;place-items:center;flex-shrink:0;width:20px;height:20px;border-radius:4px;color:var(--cc-muted);cursor:pointer;transform:translate(calc((1 - var(--shown)) * 24px));transition:transform var(--cc-ease)}.cc-action:hover{color:var(--cc-foreground)}@media(prefers-reduced-motion:reduce){.cc *{transition:none!important}}';import{Fragment as L,jsx as s,jsxs as m}from"react/jsx-runtime";var V=v;function W(t,l){$(()=>{if(document.getElementById(t))return;let o=document.createElement("style");o.id=t,o.textContent=l,document.head.prepend(o)},[])}function B(t){let l=t.replace(/^\s*\n/,"").trimEnd().split(`
3
+ `),o=Math.min(...l.filter(e=>e.trim()).map(e=>e.search(/\S/)));return l.map(e=>e.slice(o)).join(`
4
+ `)}var f=t=>t.kind==="boolean"||typeof t.value=="number"?"cc-box cc-keyword":t.quote?"cc-box cc-string":"cc-box";function x({d:t}){return s("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:s("path",{d:t})})}var I="M8 7.5h7.5v8H8zM12 4.5H4.5v8",R="M5 10.5l3 3 7-7",T="M5 8.5a5.5 5.5 0 1 1 .5 4.5M5 4.5v4h4";function P({control:t,onChange:l,written:o}){let{min:e=-1/0,max:i=1/0,step:d}=t,p=t.value,u=k(null),c=i-e<1/0?Math.min(12,Math.max(2,240*d/(i-e))):6,n=a=>{a=Math.min(i,Math.max(e,a)),a!==p&&l(a)};return s("span",{className:`${f(t)} cc-scrub`,role:"slider",tabIndex:0,"aria-label":t.prop,"aria-valuenow":p,"aria-valuemin":e>-1/0?e:void 0,"aria-valuemax":i<1/0?i:void 0,onPointerDown:a=>{a.currentTarget.setPointerCapture(a.pointerId),u.current={x:a.clientX,value:p}},onPointerMove:a=>{if(u.current){let r=Math.round((a.clientX-u.current.x)/c);n(u.current.value+r*d)}},onPointerUp:()=>u.current=null,onPointerCancel:()=>u.current=null,onKeyDown:a=>{let r=a.shiftKey?d*10:d,h={ArrowUp:p+r,ArrowRight:p+r,ArrowDown:p-r,ArrowLeft:p-r,Home:e,End:i}[a.key];h!==void 0&&Number.isFinite(h)&&(a.preventDefault(),n(h))},children:o})}function S({control:t,onChange:l}){let o=`${t.value}`,{quote:e}=t;return m("label",{className:f(t),children:[e,s("span",{className:"cc-field","data-value":o,children:s("input",{size:1,value:o,"aria-label":t.prop,spellCheck:!1,onChange:i=>l(i.target.value),onKeyDown:i=>{(i.key==="Enter"||i.key==="Escape")&&i.currentTarget.blur()}})}),e]})}function A({control:t,onChange:l,written:o}){let e=k(null),[i,d]=y(!1),p=c=>{let n=typeof c=="string"?t.quote:"";return n+c+n},u=()=>[...e.current.children];return M(()=>{let c=e.current,n=r=>d(r.newState==="open"),a=()=>c.matches(":popover-open")&&c.hidePopover();return c.addEventListener("toggle",n),addEventListener("scroll",a,!0),()=>{c.removeEventListener("toggle",n),removeEventListener("scroll",a,!0)}},[]),m(L,{children:[s("button",{type:"button",className:f(t),"aria-haspopup":"menu","aria-expanded":i,"aria-label":t.prop,onClick:c=>{let n=e.current,{left:a,bottom:r}=c.currentTarget.getBoundingClientRect();n.style.left=`${a}px`,n.style.top=`${r+4}px`,n.showPopover(),u().find(h=>h.getAttribute("aria-checked")==="true")?.focus()},children:o}),s("div",{ref:e,className:"cc-menu",popover:"auto",role:"menu",onKeyDown:c=>{let n=u(),a=n.indexOf(document.activeElement),r={ArrowDown:1,ArrowUp:-1}[c.key];r&&(c.preventDefault(),n[(a+r+n.length)%n.length].focus())},children:t.options.map(c=>s("button",{type:"button",role:"menuitemradio","aria-checked":c===t.value,onClick:()=>l(c),children:p(c)},`${c}`))})]})}function z({source:t,tokens:l,controls:o,onChange:e}){let i=[],d=0,p=0,u=c=>{for(;d<c;){for(;p<l.length&&l[p].end<=d;)p++;let n=l[p];if(n&&n.start<=d){let a=Math.min(n.end,c);i.push(s("span",{className:`cc-${n.ink}`,children:t.slice(d,a)},d)),d=a}else{let a=Math.min(n?.start??c,c);i.push(t.slice(d,a)),d=a}}};return o.forEach((c,n)=>{u(c.range.start);let a=t.slice(c.range.start,c.range.end),r={control:c,written:a,onChange:h=>e(c,h)};i.push(c.kind==="boolean"?s("button",{type:"button",className:f(c),"aria-label":c.prop,"aria-pressed":c.value,onClick:()=>r.onChange(!c.value),children:a},`c${n}`):c.kind==="number"?s(P,{...r},`c${n}`):c.kind==="option"?s(A,{...r},`c${n}`):s(S,{...r},`c${n}`)),d=c.range.end}),u(t.length),m("div",{className:"cc-body",children:[s("div",{className:"cc-lines","aria-hidden":!0,children:t.split(`
5
+ `).map((c,n)=>n+1).join(`
6
+ `)}),s("div",{className:"cc-scroll",children:s("code",{children:i})})]})}function D({source:t,changed:l,onReset:o}){let[e,i]=y(!1);return m("div",{className:`cc-tab cc-actions${l?" cc-changed":""}`,children:[s("span",{className:"cc-slot",children:s("button",{type:"button",className:"cc-action","aria-label":e?"Copied":"Copy code",onClick:()=>navigator.clipboard.writeText(t).then(()=>{i(!0),setTimeout(()=>i(!1),1500)}),children:s(x,{d:e?R:I})})}),s("span",{className:"cc-slot",children:s("button",{type:"button",className:"cc-action","aria-label":"Reset code",tabIndex:l?0:-1,onClick:o,children:s(x,{d:T})})})]})}function _({className:t,theme:l,preview:o,tab:e,source:i,changed:d,onReset:p,...u}){return m("div",{className:t?`cc ${t}`:"cc","data-theme":l,children:[m("div",{className:"cc-frame",children:[s("div",{className:"cc-preview",children:o}),m("div",{className:"cc-code",children:[e,s(D,{source:i,changed:d,onReset:p}),s(z,{source:i,...u})]})]}),s("div",{className:"cc-tab",children:"Preview"})]})}var w=t=>`${t}`.split(".")[1]?.length??0,X=t=>10**-w(t),Z=(t,l)=>`${+t.toFixed(w(l))}`;export{X as a,Z as b,O as c,V as d,W as e,B as f,_ as g};
@@ -0,0 +1,6 @@
1
+ 'use client';
2
+ var C=new Set("as async await break case catch class const continue default delete do else enum export extends false finally for from function if import in instanceof interface let new null of return satisfies static switch this throw true try type typeof undefined var void while yield".split(" ")),N=/^(|[(,=:?[{}>&|!]|return)$/;function H(e){let d=[],a=[{in:"code",depth:0}],t=0,i="",s=n=>(n.lastIndex=t,n.exec(e)?.[0]??""),p=(n,c)=>{c&&d.push({ink:n,start:t,end:t+c}),t+=c},u=n=>{let c=t+1;for(;c<e.length&&e[c]!==n;)c+=e[c]==="\\"?2:1;p("string",Math.min(c+1,e.length)-t)};for(;t<e.length;){let n=a[a.length-1],c=e[t];if(n.in==="text"){if(c==="{")t++,a.push({in:"code",depth:0});else if(c==="<")t++,e[t]==="/"?(t++,p("tag",s(/[\w$.:-]*/y).length),t=Math.max(t,e.indexOf(">",t)+1),a.pop()):a.push({in:"tag",named:!1});else{let g=e.slice(t).search(/[<{]/);t=g<0?e.length:t+g}continue}if(n.in==="tag"){let g=s(/[\w$.:-]+/y);g?p(n.named?"attribute":"tag",g.length):c==='"'||c==="'"?u(c):c==="{"?(t++,a.push({in:"code",depth:0})):c===">"?(t++,a[a.length-1]={in:"text"}):e.startsWith("/>",t)?(t+=2,a.pop()):t++,n.named=!0;continue}let o=s(/\s+|\/\/.*|\/\*[\s\S]*?(\*\/|$)/y);if(o){t+=o.length;continue}let l=s(/[A-Za-z_$][\w$]*/y);if(l){let g=e.slice(t+l.length).match(/^\s*(\S)/)?.[1],v=C.has(l)?"keyword":g==="("||/^[A-Z]/.test(l)?"tag":e[t-1]==="."||g===":"&&i!=="?"?"attribute":void 0;v?p(v,l.length):t+=l.length,i=l==="return"?l:"name";continue}let h=s(/\d[\d_]*\.?\d*(e[+-]?\d+)?n?|\.\d+/iy);if(h){p("keyword",h.length),i="name";continue}if(c==='"'||c==="'"||c==="`"){u(c),i="name";continue}if(c==="<"&&N.test(i)&&/[A-Za-z>]/.test(e[t+1]??"")){t++,a.push({in:"tag",named:e[t]===">"}),e[t]===">"&&(t++,a[a.length-1]={in:"text"});continue}if(c==="{"&&n.depth++,c==="}"){if(n.depth===0&&a.length>1){t++,a.pop();continue}n.depth--}i=e.startsWith("&&",t)||e.startsWith("||",t)?"&":c,t++}return d}import{useEffect as M,useInsertionEffect as $,useRef as k,useState as y}from"react";var x='.cc{--cc-surface: light-dark(oklch(100% 0 0), oklch(17.5% 0 0));--cc-subtle: light-dark(oklch(93% 0 0), oklch(24.5% 0 0));--cc-sunken: light-dark(oklch(89.5% 0 0), oklch(21% 0 0));--cc-foreground: light-dark( oklch(22.7% .006 271.2), oklch(92.3% .004 286.3) );--cc-secondary: light-dark( oklch(41.8% .014 274.6), oklch(78.2% .016 281.9) );--cc-muted: light-dark(oklch(52% .044 267.6), oklch(67.3% .028 276.2));--cc-disabled: light-dark(oklch(72% .01 270), oklch(48% .01 280));--cc-text: light-dark(oklch(49% .04 268), oklch(67.3% .028 276.2));--cc-line: light-dark(oklch(59% .02 270), oklch(51% .02 276));--cc-tag: light-dark(oklch(46% .185 145.3), oklch(84.4% .185 145.3));--cc-attribute: light-dark(oklch(46% .088 229.9), oklch(85.7% .088 229.9));--cc-string: light-dark(oklch(46% .191 32.2), oklch(71.2% .191 32.2));--cc-keyword: light-dark(oklch(46% .2 317.2), oklch(76.9% .2 317.2));--cc-sans: Geist, ui-sans-serif, system-ui, sans-serif;--cc-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;--cc-ease: .24s cubic-bezier(.2, .9, .3, 1);--copy: 0;--reset: 0;position:relative;box-sizing:border-box;width:100%;overflow:hidden;container-type:inline-size;border-radius:8px;outline:1px solid var(--cc-subtle);background:var(--cc-subtle);color:var(--cc-foreground);font:16px/24px var(--cc-sans);text-align:left;-webkit-font-smoothing:antialiased}.cc[data-theme=light]{color-scheme:light}.cc[data-theme=dark]{color-scheme:dark}.cc *,.cc *:before,.cc *:after{box-sizing:inherit}.cc-frame{display:grid;gap:2px;padding:2px;background:var(--cc-surface)}@container (min-width: 640px){.cc-frame{grid-template-columns:repeat(2,minmax(0,1fr))}}.cc-preview{display:grid;place-items:center;min-width:0;padding:48px 24px 24px}.cc-problem{margin:0;color:var(--cc-muted);font:14px/20px var(--cc-sans);text-align:center}.cc-tab{--inset: 0px;position:absolute;top:calc(var(--inset) * -1);left:calc(var(--inset) * -1);display:flex;align-items:center;height:24px;padding:0 8px;border-bottom-right-radius:6px;background:var(--ground);color:var(--cc-muted);font:12px/16px var(--cc-sans);white-space:nowrap;pointer-events:none}.cc-tab:before,.cc-tab:after{content:"";position:absolute;width:6px;height:6px;background:radial-gradient(circle at 100% 100%,transparent 6px,var(--ground) 6.5px)}.cc-tab:before{top:var(--inset);left:100%}.cc-tab:after{top:100%;left:var(--inset)}.cc>.cc-tab{--ground: var(--cc-subtle)}.cc-code{--ground: var(--cc-surface);--tint: var(--cc-text);position:relative;min-width:0;padding-top:22px;border-radius:6px;background:var(--cc-sunken);color:var(--cc-text);font:14px/24px var(--cc-mono)}.cc-code>.cc-tab{--inset: 2px}.cc-body{display:flex}.cc-lines{flex-shrink:0;padding:16px 4px 16px 16px;color:var(--cc-line);text-align:right;white-space:pre;user-select:none}.cc-scroll{flex-grow:1;min-width:0;padding:16px 16px 16px 4px;overflow-x:auto;scrollbar-width:thin;scrollbar-color:var(--cc-disabled) transparent}.cc .cc-scroll>code{all:unset;display:block;width:max-content;min-width:100%;white-space:pre;tab-size:2}.cc-tag{color:var(--cc-tag)}.cc-attribute{color:var(--cc-attribute)}.cc-string{--tint: var(--cc-string);color:var(--cc-string)}.cc-keyword{--tint: var(--cc-keyword);color:var(--cc-keyword)}.cc-box{all:unset;display:inline-block;margin:0 -2px;padding:0 4px;border-radius:4px;background:color-mix(in srgb,var(--tint) 14%,transparent);line-height:20px;white-space:pre;cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent}.cc-box:hover,.cc-box:focus-within,.cc-box[aria-expanded=true]{background:color-mix(in srgb,var(--tint) 28%,transparent)}.cc-box:focus-visible,.cc-action:focus-visible,.cc-menu>button:focus-visible{outline:2px solid currentColor;outline-offset:-2px}.cc-scrub{cursor:ew-resize;touch-action:pan-y}.cc-field{display:inline-grid;min-width:8px;cursor:text}.cc-field:after{content:attr(data-value);grid-area:1 / 1;visibility:hidden;white-space:pre}.cc-field>input{all:unset;grid-area:1 / 1;width:100%;min-width:0}.cc-menu{position:fixed;inset:auto;display:none;min-width:96px;margin:0;padding:2px;border:0;font:14px/20px var(--cc-mono)}.cc-menu,.cc-code:after{border-radius:8px;background:var(--cc-subtle);color:var(--cc-secondary);box-shadow:0 8px 24px #0000001f}.cc-menu:popover-open{display:grid}.cc-menu>button{all:unset;display:flex;align-items:center;gap:16px;height:32px;padding:0 8px;border-radius:6px;white-space:pre;cursor:pointer}.cc-menu>button:is(:hover,:focus){background:var(--cc-sunken);color:var(--cc-foreground)}.cc-menu>[aria-checked=true]:after{content:"\\2713";margin-left:auto;color:var(--cc-muted)}.cc-code:is(:hover,:has(:focus-visible)){--copy: 1}@media(hover:none){.cc-code{--copy: 1}}.cc-changed{--reset: 1}.cc-actions{--open: max(var(--copy), var(--reset));top:-2px;right:-2px;left:auto;padding:0 calc(var(--open) * 4px) 0 0;border-radius:0 0 0 6px;pointer-events:auto;transition:padding var(--cc-ease)}.cc-actions:before,.cc-actions:after{left:auto;background:radial-gradient(circle at 0 100%,transparent 6px,var(--ground) 6.5px);opacity:var(--open);transition:opacity var(--cc-ease)}.cc-actions:before{right:100%}.cc-actions:after{right:var(--inset)}.cc-slot{--shown: var(--copy);display:flex;justify-content:flex-end;width:calc(var(--shown) * 24px);overflow:hidden;transition:width var(--cc-ease)}.cc-note,.cc-reset{--shown: var(--reset)}.cc-action{all:unset;display:grid;place-items:center;flex-shrink:0;width:20px;height:20px;border-radius:4px;color:var(--cc-muted);cursor:pointer;transform:translate(calc((1 - var(--shown)) * 24px));transition:transform var(--cc-ease)}.cc-action:hover{color:var(--cc-foreground)}.cc-code:after{content:attr(data-note);position:absolute;top:26px;right:4px;padding:4px 8px;font:12px/16px var(--cc-sans);white-space:nowrap;opacity:0;transition:opacity var(--cc-ease);pointer-events:none}.cc-code:has(.cc-note :is(:hover,:focus)):after{opacity:1}@media(prefers-reduced-motion:reduce){.cc *{transition:none!important}}';import{Fragment as O,jsx as r,jsxs as f}from"react/jsx-runtime";var W=x;function B(e,d){$(()=>{if(document.getElementById(e))return;let a=document.createElement("style");a.id=e,a.textContent=d,document.head.prepend(a)},[])}function _(e){let d=e.replace(/^\s*\n/,"").trimEnd().split(`
3
+ `),a=Math.min(...d.filter(t=>t.trim()).map(t=>t.search(/\S/)));return d.map(t=>t.slice(a)).join(`
4
+ `)}var m=e=>e.kind==="boolean"||typeof e.value=="number"?"cc-box cc-keyword":e.quote?"cc-box cc-string":"cc-box";function b({d:e}){return r("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:r("path",{d:e})})}var I="M8 7.5h7.5v8H8zM12 4.5H4.5v8",R="M5 10.5l3 3 7-7",T="M5 8.5a5.5 5.5 0 1 1 .5 4.5M5 4.5v4h4",P="M16 10a6 6 0 1 1-12 0a6 6 0 0 1 12 0M10 9.5V13m0-6v.01";function S({control:e,onChange:d,written:a}){let{min:t=-1/0,max:i=1/0,step:s}=e,p=e.value,u=k(null),n=i-t<1/0?Math.min(12,Math.max(2,240*s/(i-t))):6,c=o=>{o=Math.min(i,Math.max(t,o)),o!==p&&d(o)};return r("span",{className:`${m(e)} cc-scrub`,role:"slider",tabIndex:0,"aria-label":e.prop,"aria-valuenow":p,"aria-valuemin":t>-1/0?t:void 0,"aria-valuemax":i<1/0?i:void 0,onPointerDown:o=>{o.currentTarget.setPointerCapture(o.pointerId),u.current={x:o.clientX,value:p}},onPointerMove:o=>{if(u.current){let l=Math.round((o.clientX-u.current.x)/n);c(u.current.value+l*s)}},onPointerUp:()=>u.current=null,onPointerCancel:()=>u.current=null,onKeyDown:o=>{let l=o.shiftKey?s*10:s,h={ArrowUp:p+l,ArrowRight:p+l,ArrowDown:p-l,ArrowLeft:p-l,Home:t,End:i}[o.key];h!==void 0&&Number.isFinite(h)&&(o.preventDefault(),c(h))},children:a})}function A({control:e,onChange:d}){let a=`${e.value}`,{quote:t}=e;return f("label",{className:m(e),children:[t,r("span",{className:"cc-field","data-value":a,children:r("input",{size:1,value:a,"aria-label":e.prop,spellCheck:!1,onChange:i=>d(i.target.value),onKeyDown:i=>{(i.key==="Enter"||i.key==="Escape")&&i.currentTarget.blur()}})}),t]})}function z({control:e,onChange:d,written:a}){let t=k(null),[i,s]=y(!1),p=n=>{let c=typeof n=="string"?e.quote:"";return c+n+c},u=()=>[...t.current.children];return M(()=>{let n=t.current,c=l=>s(l.newState==="open"),o=()=>n.matches(":popover-open")&&n.hidePopover();return n.addEventListener("toggle",c),addEventListener("scroll",o,!0),()=>{n.removeEventListener("toggle",c),removeEventListener("scroll",o,!0)}},[]),f(O,{children:[r("button",{type:"button",className:m(e),"aria-haspopup":"menu","aria-expanded":i,"aria-label":e.prop,onClick:n=>{let c=t.current,{left:o,bottom:l}=n.currentTarget.getBoundingClientRect();c.style.left=`${o}px`,c.style.top=`${l+4}px`,c.showPopover(),u().find(h=>h.getAttribute("aria-checked")==="true")?.focus()},children:a}),r("div",{ref:t,className:"cc-menu",popover:"auto",role:"menu",onKeyDown:n=>{let c=u(),o=c.indexOf(document.activeElement),l={ArrowDown:1,ArrowUp:-1}[n.key];l&&(n.preventDefault(),c[(o+l+c.length)%c.length].focus())},children:e.options.map(n=>r("button",{type:"button",role:"menuitemradio","aria-checked":n===e.value,onClick:()=>d(n),children:p(n)},`${n}`))})]})}function D({source:e,tokens:d,controls:a,onChange:t}){let i=[],s=0,p=0,u=n=>{for(;s<n;){for(;p<d.length&&d[p].end<=s;)p++;let c=d[p];if(c&&c.start<=s){let o=Math.min(c.end,n);i.push(r("span",{className:`cc-${c.ink}`,children:e.slice(s,o)},s)),s=o}else{let o=Math.min(c?.start??n,n);i.push(e.slice(s,o)),s=o}}};return a.forEach((n,c)=>{u(n.range.start);let o=e.slice(n.range.start,n.range.end),l={control:n,written:o,onChange:h=>t(n,h)};i.push(n.kind==="boolean"?r("button",{type:"button",className:m(n),"aria-label":n.prop,"aria-pressed":n.value,onClick:()=>l.onChange(!n.value),children:o},`c${c}`):n.kind==="number"?r(S,{...l},`c${c}`):n.kind==="option"?r(z,{...l},`c${c}`):r(A,{...l},`c${c}`)),s=n.range.end}),u(e.length),f("div",{className:"cc-body",children:[r("div",{className:"cc-lines","aria-hidden":!0,children:e.split(`
5
+ `).map((n,c)=>c+1).join(`
6
+ `)}),r("div",{className:"cc-scroll",children:r("code",{children:i})})]})}function L({source:e,changed:d,note:a,onReset:t}){let[i,s]=y(!1);return f("div",{className:`cc-tab cc-actions${d?" cc-changed":""}`,children:[a&&r("span",{className:"cc-slot cc-note",children:r("button",{type:"button",className:"cc-action","aria-label":a,tabIndex:d?0:-1,children:r(b,{d:P})})}),r("span",{className:"cc-slot",children:r("button",{type:"button",className:"cc-action","aria-label":i?"Copied":"Copy code",onClick:()=>navigator.clipboard.writeText(e).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}),children:r(b,{d:i?R:I})})}),r("span",{className:"cc-slot cc-reset",children:r("button",{type:"button",className:"cc-action","aria-label":"Reset code",tabIndex:d?0:-1,onClick:t,children:r(b,{d:T})})})]})}function j({className:e,theme:d,preview:a,tab:t,source:i,changed:s,note:p,onReset:u,...n}){return f("div",{className:e?`cc ${e}`:"cc","data-theme":d,children:[f("div",{className:"cc-frame",children:[r("div",{className:"cc-preview",children:a}),f("div",{className:"cc-code","data-note":p,children:[t,r(L,{source:i,changed:s,note:p,onReset:u}),r(D,{source:i,...n})]})]}),r("div",{className:"cc-tab",children:"Preview"})]})}var w=e=>`${e}`.split(".")[1]?.length??0,Z=e=>10**-w(e),G=(e,d)=>`${+e.toFixed(w(d))}`;export{Z as a,G as b,H as c,W as d,B as e,_ as f,j as g};
@@ -0,0 +1,6 @@
1
+ 'use client';
2
+ var N=new Set("as async await break case catch class const continue default delete do else enum export extends false finally for from function if import in instanceof interface let new null of return satisfies static switch this throw true try type typeof undefined var void while yield".split(" ")),M=/^(|[(,=:?[{}>&|!]|return)$/;function H(e){let d=[],a=[{in:"code",depth:0}],t=0,r="",s=n=>(n.lastIndex=t,n.exec(e)?.[0]??""),p=(n,c)=>{c&&d.push({ink:n,start:t,end:t+c}),t+=c},u=n=>{let c=t+1;for(;c<e.length&&e[c]!==n;)c+=e[c]==="\\"?2:1;p("string",Math.min(c+1,e.length)-t)};for(;t<e.length;){let n=a[a.length-1],c=e[t];if(n.in==="text"){if(c==="{")t++,a.push({in:"code",depth:0});else if(c==="<")t++,e[t]==="/"?(t++,p("tag",s(/[\w$.:-]*/y).length),t=Math.max(t,e.indexOf(">",t)+1),a.pop()):a.push({in:"tag",named:!1});else{let g=e.slice(t).search(/[<{]/);t=g<0?e.length:t+g}continue}if(n.in==="tag"){let g=s(/[\w$.:-]+/y);g?p(n.named?"attribute":"tag",g.length):c==='"'||c==="'"?u(c):c==="{"?(t++,a.push({in:"code",depth:0})):c===">"?(t++,a[a.length-1]={in:"text"}):e.startsWith("/>",t)?(t+=2,a.pop()):t++,n.named=!0;continue}let o=s(/\s+|\/\/.*|\/\*[\s\S]*?(\*\/|$)/y);if(o){t+=o.length;continue}let l=s(/[A-Za-z_$][\w$]*/y);if(l){let g=e.slice(t+l.length).match(/^\s*(\S)/)?.[1],v=N.has(l)?"keyword":g==="("||/^[A-Z]/.test(l)?"tag":e[t-1]==="."||g===":"&&r!=="?"?"attribute":void 0;v?p(v,l.length):t+=l.length,r=l==="return"?l:"name";continue}let h=s(/\d[\d_]*\.?\d*(e[+-]?\d+)?n?|\.\d+/iy);if(h){p("keyword",h.length),r="name";continue}if(c==='"'||c==="'"||c==="`"){u(c),r="name";continue}if(c==="<"&&M.test(r)&&/[A-Za-z>]/.test(e[t+1]??"")){t++,a.push({in:"tag",named:e[t]===">"}),e[t]===">"&&(t++,a[a.length-1]={in:"text"});continue}if(c==="{"&&n.depth++,c==="}"){if(n.depth===0&&a.length>1){t++,a.pop();continue}n.depth--}r=e.startsWith("&&",t)||e.startsWith("||",t)?"&":c,t++}return d}import{useEffect as $,useInsertionEffect as I,useRef as k,useState as y}from"react";var x='.cc{--cc-surface: light-dark(oklch(100% 0 0), oklch(17.5% 0 0));--cc-subtle: light-dark(oklch(93% 0 0), oklch(24.5% 0 0));--cc-sunken: light-dark(oklch(89.5% 0 0), oklch(21% 0 0));--cc-foreground: light-dark( oklch(22.7% .006 271.2), oklch(92.3% .004 286.3) );--cc-secondary: light-dark( oklch(41.8% .014 274.6), oklch(78.2% .016 281.9) );--cc-muted: light-dark(oklch(52% .044 267.6), oklch(67.3% .028 276.2));--cc-disabled: light-dark(oklch(72% .01 270), oklch(48% .01 280));--cc-text: light-dark(oklch(49% .04 268), oklch(67.3% .028 276.2));--cc-line: light-dark(oklch(59% .02 270), oklch(51% .02 276));--cc-tag: light-dark(oklch(46% .185 145.3), oklch(84.4% .185 145.3));--cc-attribute: light-dark(oklch(46% .088 229.9), oklch(85.7% .088 229.9));--cc-string: light-dark(oklch(46% .191 32.2), oklch(71.2% .191 32.2));--cc-keyword: light-dark(oklch(46% .2 317.2), oklch(76.9% .2 317.2));--cc-sans: Geist, ui-sans-serif, system-ui, sans-serif;--cc-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;--cc-ease: .24s cubic-bezier(.2, .9, .3, 1);--copy: 0;--reset: 0;position:relative;box-sizing:border-box;width:100%;overflow:hidden;container-type:inline-size;border-radius:8px;outline:1px solid var(--cc-subtle);background:var(--cc-subtle);color:var(--cc-foreground);font:16px/24px var(--cc-sans);text-align:left;-webkit-font-smoothing:antialiased}.cc[data-theme=light]{color-scheme:light}.cc[data-theme=dark]{color-scheme:dark}.cc *,.cc *:before,.cc *:after{box-sizing:inherit}.cc-frame{display:grid;gap:2px;padding:2px;background:var(--cc-surface)}@container (min-width: 640px){.cc-frame{grid-template-columns:repeat(2,minmax(0,1fr))}}.cc-preview{display:grid;place-items:center;min-width:0;padding:48px 24px 24px}.cc-problem{margin:0;color:var(--cc-muted);font:14px/20px var(--cc-sans);text-align:center}.cc-tab{--inset: 0px;position:absolute;top:calc(var(--inset) * -1);left:calc(var(--inset) * -1);display:flex;align-items:center;height:24px;padding:0 8px;border-bottom-right-radius:6px;background:var(--ground);color:var(--cc-muted);font:12px/16px var(--cc-sans);white-space:nowrap;pointer-events:none}.cc-tab:before,.cc-tab:after{content:"";position:absolute;width:6px;height:6px;background:radial-gradient(circle at 100% 100%,transparent 6px,var(--ground) 6.5px)}.cc-tab:before{top:var(--inset);left:100%}.cc-tab:after{top:100%;left:var(--inset)}.cc>.cc-tab{--ground: var(--cc-subtle)}.cc-code{--ground: var(--cc-surface);--tint: var(--cc-text);position:relative;min-width:0;padding-top:22px;border-radius:6px;background:var(--cc-sunken);color:var(--cc-text);font:14px/24px var(--cc-mono)}.cc-code>.cc-tab{--inset: 2px}.cc-body{display:flex}.cc-lines{flex-shrink:0;padding:16px 4px 16px 16px;color:var(--cc-line);text-align:right;white-space:pre;user-select:none}.cc-scroll{flex-grow:1;min-width:0;padding:16px 16px 16px 4px;overflow-x:auto;scrollbar-width:thin;scrollbar-color:var(--cc-disabled) transparent}.cc .cc-scroll>code{all:unset;display:block;width:max-content;min-width:100%;white-space:pre;tab-size:2}.cc-tag{color:var(--cc-tag)}.cc-attribute{color:var(--cc-attribute)}.cc-string{--tint: var(--cc-string);color:var(--cc-string)}.cc-keyword{--tint: var(--cc-keyword);color:var(--cc-keyword)}.cc-box{all:unset;display:inline-block;margin:0 -2px;padding:0 4px;border-radius:4px;background:color-mix(in srgb,var(--tint) 14%,transparent);line-height:20px;white-space:pre;cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent}.cc-box:hover,.cc-box:focus-within,.cc-box[aria-expanded=true]{background:color-mix(in srgb,var(--tint) 28%,transparent)}.cc-box:focus-visible,.cc-action:focus-visible,.cc-menu>button:focus-visible{outline:2px solid currentColor;outline-offset:-2px}.cc-scrub{cursor:ew-resize;touch-action:pan-y}.cc-field{display:inline-grid;min-width:8px;cursor:text}.cc-field:after{content:attr(data-value);grid-area:1 / 1;visibility:hidden;white-space:pre}.cc-field>input{all:unset;grid-area:1 / 1;width:100%;min-width:0}.cc-menu{position:fixed;inset:auto;display:none;min-width:96px;margin:0;padding:2px;border:0;border-radius:8px;background:var(--cc-subtle);color:var(--cc-secondary);font:14px/20px var(--cc-mono);box-shadow:0 8px 24px #0000001f}.cc-menu:popover-open{display:grid}.cc-menu>button{all:unset;display:flex;align-items:center;gap:16px;height:32px;padding:0 8px;border-radius:6px;white-space:pre;cursor:pointer}.cc-menu>button:is(:hover,:focus){background:var(--cc-sunken);color:var(--cc-foreground)}.cc-menu>[aria-checked=true]:after{content:"\\2713";margin-left:auto;color:var(--cc-muted)}.cc-code:is(:hover,:has(:focus-visible)){--copy: 1}@media(hover:none){.cc-code{--copy: 1}}.cc-changed{--reset: 1}.cc-actions{--open: max(var(--copy), var(--reset));top:-2px;right:-2px;left:auto;padding:0 calc(var(--open) * 4px) 0 0;border-radius:0 0 0 6px;pointer-events:auto;transition:padding var(--cc-ease)}.cc-actions:before,.cc-actions:after{left:auto;background:radial-gradient(circle at 0 100%,transparent 6px,var(--ground) 6.5px);opacity:var(--open);transition:opacity var(--cc-ease)}.cc-actions:before{right:100%}.cc-actions:after{right:var(--inset)}.cc-slot{--shown: var(--copy);display:flex;justify-content:flex-end;width:calc(var(--shown) * 24px);overflow:hidden;transition:width var(--cc-ease)}.cc-note,.cc-reset{--shown: var(--reset)}.cc-action{all:unset;display:grid;place-items:center;flex-shrink:0;width:20px;height:20px;border-radius:4px;color:var(--cc-muted);cursor:pointer;transform:translate(calc((1 - var(--shown)) * 24px));transition:transform var(--cc-ease)}.cc-action:hover{color:var(--cc-foreground)}.cc-tip{position:absolute;top:calc(100% + 4px);right:4px;padding:4px 8px;border-radius:6px;background:var(--cc-subtle);color:var(--cc-secondary);font:12px/16px var(--cc-sans);white-space:nowrap;box-shadow:0 8px 24px #0000001f;opacity:0;transform:translateY(-2px);transition:opacity var(--cc-ease),transform var(--cc-ease);pointer-events:none}.cc-note:has(.cc-action:is(:hover,:focus))+.cc-tip{opacity:1;transform:none}@media(prefers-reduced-motion:reduce){.cc *{transition:none!important}}';import{Fragment as w,jsx as i,jsxs as m}from"react/jsx-runtime";var W=x;function B(e,d){I(()=>{if(document.getElementById(e))return;let a=document.createElement("style");a.id=e,a.textContent=d,document.head.prepend(a)},[])}function _(e){let d=e.replace(/^\s*\n/,"").trimEnd().split(`
3
+ `),a=Math.min(...d.filter(t=>t.trim()).map(t=>t.search(/\S/)));return d.map(t=>t.slice(a)).join(`
4
+ `)}var f=e=>e.kind==="boolean"||typeof e.value=="number"?"cc-box cc-keyword":e.quote?"cc-box cc-string":"cc-box";function b({d:e}){return i("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i("path",{d:e})})}var R="M8 7.5h7.5v8H8zM12 4.5H4.5v8",T="M5 10.5l3 3 7-7",P="M5 8.5a5.5 5.5 0 1 1 .5 4.5M5 4.5v4h4",S="M16 10a6 6 0 1 1-12 0a6 6 0 1 1 12 0zM10 9.5v3.5M10 7v.01";function z({control:e,onChange:d,written:a}){let{min:t=-1/0,max:r=1/0,step:s}=e,p=e.value,u=k(null),n=r-t<1/0?Math.min(12,Math.max(2,240*s/(r-t))):6,c=o=>{o=Math.min(r,Math.max(t,o)),o!==p&&d(o)};return i("span",{className:`${f(e)} cc-scrub`,role:"slider",tabIndex:0,"aria-label":e.prop,"aria-valuenow":p,"aria-valuemin":t>-1/0?t:void 0,"aria-valuemax":r<1/0?r:void 0,onPointerDown:o=>{o.currentTarget.setPointerCapture(o.pointerId),u.current={x:o.clientX,value:p}},onPointerMove:o=>{if(u.current){let l=Math.round((o.clientX-u.current.x)/n);c(u.current.value+l*s)}},onPointerUp:()=>u.current=null,onPointerCancel:()=>u.current=null,onKeyDown:o=>{let l=o.shiftKey?s*10:s,h={ArrowUp:p+l,ArrowRight:p+l,ArrowDown:p-l,ArrowLeft:p-l,Home:t,End:r}[o.key];h!==void 0&&Number.isFinite(h)&&(o.preventDefault(),c(h))},children:a})}function A({control:e,onChange:d}){let a=`${e.value}`,{quote:t}=e;return m("label",{className:f(e),children:[t,i("span",{className:"cc-field","data-value":a,children:i("input",{size:1,value:a,"aria-label":e.prop,spellCheck:!1,onChange:r=>d(r.target.value),onKeyDown:r=>{(r.key==="Enter"||r.key==="Escape")&&r.currentTarget.blur()}})}),t]})}function D({control:e,onChange:d,written:a}){let t=k(null),[r,s]=y(!1),p=n=>{let c=typeof n=="string"?e.quote:"";return c+n+c},u=()=>[...t.current.children];return $(()=>{let n=t.current,c=l=>s(l.newState==="open"),o=()=>n.matches(":popover-open")&&n.hidePopover();return n.addEventListener("toggle",c),addEventListener("scroll",o,!0),()=>{n.removeEventListener("toggle",c),removeEventListener("scroll",o,!0)}},[]),m(w,{children:[i("button",{type:"button",className:f(e),"aria-haspopup":"menu","aria-expanded":r,"aria-label":e.prop,onClick:n=>{let c=t.current,{left:o,bottom:l}=n.currentTarget.getBoundingClientRect();c.style.left=`${o}px`,c.style.top=`${l+4}px`,c.showPopover(),u().find(h=>h.getAttribute("aria-checked")==="true")?.focus()},children:a}),i("div",{ref:t,className:"cc-menu",popover:"auto",role:"menu",onKeyDown:n=>{let c=u(),o=c.indexOf(document.activeElement),l={ArrowDown:1,ArrowUp:-1}[n.key];l&&(n.preventDefault(),c[(o+l+c.length)%c.length].focus())},children:e.options.map(n=>i("button",{type:"button",role:"menuitemradio","aria-checked":n===e.value,onClick:()=>d(n),children:p(n)},`${n}`))})]})}function L({source:e,tokens:d,controls:a,onChange:t}){let r=[],s=0,p=0,u=n=>{for(;s<n;){for(;p<d.length&&d[p].end<=s;)p++;let c=d[p];if(c&&c.start<=s){let o=Math.min(c.end,n);r.push(i("span",{className:`cc-${c.ink}`,children:e.slice(s,o)},s)),s=o}else{let o=Math.min(c?.start??n,n);r.push(e.slice(s,o)),s=o}}};return a.forEach((n,c)=>{u(n.range.start);let o=e.slice(n.range.start,n.range.end),l={control:n,written:o,onChange:h=>t(n,h)};r.push(n.kind==="boolean"?i("button",{type:"button",className:f(n),"aria-label":n.prop,"aria-pressed":n.value,onClick:()=>l.onChange(!n.value),children:o},`c${c}`):n.kind==="number"?i(z,{...l},`c${c}`):n.kind==="option"?i(D,{...l},`c${c}`):i(A,{...l},`c${c}`)),s=n.range.end}),u(e.length),m("div",{className:"cc-body",children:[i("div",{className:"cc-lines","aria-hidden":!0,children:e.split(`
5
+ `).map((n,c)=>c+1).join(`
6
+ `)}),i("div",{className:"cc-scroll",children:i("code",{children:r})})]})}function O({source:e,changed:d,note:a,onReset:t}){let[r,s]=y(!1);return m("div",{className:`cc-tab cc-actions${d?" cc-changed":""}`,children:[a&&m(w,{children:[i("span",{className:"cc-slot cc-note",children:i("button",{type:"button",className:"cc-action","aria-label":a,tabIndex:d?0:-1,children:i(b,{d:S})})}),i("span",{className:"cc-tip","aria-hidden":!0,children:a})]}),i("span",{className:"cc-slot",children:i("button",{type:"button",className:"cc-action","aria-label":r?"Copied":"Copy code",onClick:()=>navigator.clipboard.writeText(e).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}),children:i(b,{d:r?T:R})})}),i("span",{className:"cc-slot cc-reset",children:i("button",{type:"button",className:"cc-action","aria-label":"Reset code",tabIndex:d?0:-1,onClick:t,children:i(b,{d:P})})})]})}function j({className:e,theme:d,preview:a,tab:t,source:r,changed:s,note:p,onReset:u,...n}){return m("div",{className:e?`cc ${e}`:"cc","data-theme":d,children:[m("div",{className:"cc-frame",children:[i("div",{className:"cc-preview",children:a}),m("div",{className:"cc-code",children:[t,i(O,{source:r,changed:s,note:p,onReset:u}),i(L,{source:r,...n})]})]}),i("div",{className:"cc-tab",children:"Preview"})]})}var C=e=>`${e}`.split(".")[1]?.length??0,Y=e=>10**-C(e),Z=(e,d)=>`${+e.toFixed(C(d))}`;export{Y as a,Z as b,H as c,W as d,B as e,_ as f,j as g};
@@ -0,0 +1,6 @@
1
+ 'use client';
2
+ var C=new Set("as async await break case catch class const continue default delete do else enum export extends false finally for from function if import in instanceof interface let new null of return satisfies static switch this throw true try type typeof undefined var void while yield".split(" ")),N=/^(|[(,=:?[{}>&|!]|return)$/;function H(e){let d=[],a=[{in:"code",depth:0}],t=0,r="",s=n=>(n.lastIndex=t,n.exec(e)?.[0]??""),p=(n,c)=>{c&&d.push({ink:n,start:t,end:t+c}),t+=c},u=n=>{let c=t+1;for(;c<e.length&&e[c]!==n;)c+=e[c]==="\\"?2:1;p("string",Math.min(c+1,e.length)-t)};for(;t<e.length;){let n=a[a.length-1],c=e[t];if(n.in==="text"){if(c==="{")t++,a.push({in:"code",depth:0});else if(c==="<")t++,e[t]==="/"?(t++,p("tag",s(/[\w$.:-]*/y).length),t=Math.max(t,e.indexOf(">",t)+1),a.pop()):a.push({in:"tag",named:!1});else{let g=e.slice(t).search(/[<{]/);t=g<0?e.length:t+g}continue}if(n.in==="tag"){let g=s(/[\w$.:-]+/y);g?p(n.named?"attribute":"tag",g.length):c==='"'||c==="'"?u(c):c==="{"?(t++,a.push({in:"code",depth:0})):c===">"?(t++,a[a.length-1]={in:"text"}):e.startsWith("/>",t)?(t+=2,a.pop()):t++,n.named=!0;continue}let o=s(/\s+|\/\/.*|\/\*[\s\S]*?(\*\/|$)/y);if(o){t+=o.length;continue}let l=s(/[A-Za-z_$][\w$]*/y);if(l){let g=e.slice(t+l.length).match(/^\s*(\S)/)?.[1],v=C.has(l)?"keyword":g==="("||/^[A-Z]/.test(l)?"tag":e[t-1]==="."||g===":"&&r!=="?"?"attribute":void 0;v?p(v,l.length):t+=l.length,r=l==="return"?l:"name";continue}let h=s(/\d[\d_]*\.?\d*(e[+-]?\d+)?n?|\.\d+/iy);if(h){p("keyword",h.length),r="name";continue}if(c==='"'||c==="'"||c==="`"){u(c),r="name";continue}if(c==="<"&&N.test(r)&&/[A-Za-z>]/.test(e[t+1]??"")){t++,a.push({in:"tag",named:e[t]===">"}),e[t]===">"&&(t++,a[a.length-1]={in:"text"});continue}if(c==="{"&&n.depth++,c==="}"){if(n.depth===0&&a.length>1){t++,a.pop();continue}n.depth--}r=e.startsWith("&&",t)||e.startsWith("||",t)?"&":c,t++}return d}import{useEffect as E,useInsertionEffect as $,useRef as k,useState as y}from"react";var x='.cc{--cc-surface: light-dark(oklch(100% 0 0), oklch(17.5% 0 0));--cc-subtle: light-dark(oklch(93% 0 0), oklch(24.5% 0 0));--cc-sunken: light-dark(oklch(89.5% 0 0), oklch(21% 0 0));--cc-foreground: light-dark( oklch(22.7% .006 271.2), oklch(92.3% .004 286.3) );--cc-secondary: light-dark( oklch(41.8% .014 274.6), oklch(78.2% .016 281.9) );--cc-muted: light-dark(oklch(52% .044 267.6), oklch(67.3% .028 276.2));--cc-disabled: light-dark(oklch(72% .01 270), oklch(48% .01 280));--cc-text: light-dark(oklch(49% .04 268), oklch(67.3% .028 276.2));--cc-line: light-dark(oklch(59% .02 270), oklch(51% .02 276));--cc-tag: light-dark(oklch(46% .185 145.3), oklch(84.4% .185 145.3));--cc-attribute: light-dark(oklch(46% .088 229.9), oklch(85.7% .088 229.9));--cc-string: light-dark(oklch(46% .191 32.2), oklch(71.2% .191 32.2));--cc-keyword: light-dark(oklch(46% .2 317.2), oklch(76.9% .2 317.2));--cc-sans: Geist, ui-sans-serif, system-ui, sans-serif;--cc-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;--cc-ease: .24s cubic-bezier(.2, .9, .3, 1);--copy: 0;--reset: 0;position:relative;box-sizing:border-box;width:100%;overflow:hidden;container-type:inline-size;border-radius:8px;outline:1px solid var(--cc-subtle);background:var(--cc-subtle);color:var(--cc-foreground);font:16px/24px var(--cc-sans);text-align:left;-webkit-font-smoothing:antialiased}.cc[data-theme=light]{color-scheme:light}.cc[data-theme=dark]{color-scheme:dark}.cc *,.cc *:before,.cc *:after{box-sizing:inherit}.cc-frame{display:grid;gap:2px;padding:2px;background:var(--cc-surface)}@container (min-width: 640px){.cc-frame{grid-template-columns:repeat(2,minmax(0,1fr))}}.cc-preview{display:grid;place-items:center;min-width:0;padding:48px 24px 24px}.cc-problem{margin:0;color:var(--cc-muted);font:14px/20px var(--cc-sans);text-align:center}.cc-tab{--inset: 0px;position:absolute;top:calc(var(--inset) * -1);left:calc(var(--inset) * -1);display:flex;align-items:center;height:24px;padding:0 8px;border-bottom-right-radius:6px;background:var(--ground);color:var(--cc-muted);font:12px/16px var(--cc-sans);white-space:nowrap;pointer-events:none}.cc-tab:before,.cc-tab:after{content:"";position:absolute;width:6px;height:6px;background:radial-gradient(circle at 100% 100%,transparent 6px,var(--ground) 6.5px)}.cc-tab:before{top:var(--inset);left:100%}.cc-tab:after{top:100%;left:var(--inset)}.cc>.cc-tab{--ground: var(--cc-subtle)}.cc-code{--ground: var(--cc-surface);--tint: var(--cc-text);position:relative;min-width:0;padding-top:22px;border-radius:6px;background:var(--cc-sunken);color:var(--cc-text);font:14px/24px var(--cc-mono)}.cc-code>.cc-tab{--inset: 2px}.cc-body{display:flex}.cc-lines{flex-shrink:0;padding:16px 4px 16px 16px;color:var(--cc-line);text-align:right;white-space:pre;user-select:none}.cc-scroll{flex-grow:1;min-width:0;padding:16px 16px 16px 4px;overflow-x:auto;scrollbar-width:thin;scrollbar-color:var(--cc-disabled) transparent}.cc .cc-scroll>code{all:unset;display:block;width:max-content;min-width:100%;white-space:pre;tab-size:2}.cc-tag{color:var(--cc-tag)}.cc-attribute{color:var(--cc-attribute)}.cc-string{--tint: var(--cc-string);color:var(--cc-string)}.cc-keyword{--tint: var(--cc-keyword);color:var(--cc-keyword)}.cc-box{all:unset;display:inline-block;margin:0 -2px;padding:0 4px;border-radius:4px;background:color-mix(in srgb,var(--tint) 14%,transparent);line-height:20px;white-space:pre;cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent}.cc-box:hover,.cc-box:focus-within,.cc-box[aria-expanded=true]{background:color-mix(in srgb,var(--tint) 28%,transparent)}.cc-box:focus-visible,.cc-action:focus-visible,.cc-menu>button:focus-visible{outline:2px solid currentColor;outline-offset:-2px}.cc-scrub{cursor:ew-resize;touch-action:pan-y}.cc-field{display:inline-grid;min-width:8px;cursor:text}.cc-field:after{content:attr(data-value);grid-area:1 / 1;visibility:hidden;white-space:pre}.cc-field>input{all:unset;grid-area:1 / 1;width:100%;min-width:0}.cc-menu{position:fixed;inset:auto;display:none;min-width:96px;margin:0;padding:2px;border:0;border-radius:8px;background:var(--cc-subtle);color:var(--cc-secondary);font:14px/20px var(--cc-mono);box-shadow:0 8px 24px #0000001f}.cc-menu:popover-open{display:grid}.cc-menu>button{all:unset;display:flex;align-items:center;gap:16px;height:32px;padding:0 8px;border-radius:6px;white-space:pre;cursor:pointer}.cc-menu>button:is(:hover,:focus){background:var(--cc-sunken);color:var(--cc-foreground)}.cc-menu>[aria-checked=true]:after{content:"\\2713";margin-left:auto;color:var(--cc-muted)}.cc-code:is(:hover,:has(:focus-visible)){--copy: 1}@media(hover:none){.cc-code{--copy: 1}}.cc-changed{--reset: 1}.cc-actions{--open: max(var(--copy), var(--reset));top:-2px;right:-2px;left:auto;padding:0 calc(var(--open) * 4px) 0 0;border-radius:0 0 0 6px;pointer-events:auto;transition:padding var(--cc-ease)}.cc-actions:before,.cc-actions:after{left:auto;background:radial-gradient(circle at 0 100%,transparent 6px,var(--ground) 6.5px);opacity:var(--open);transition:opacity var(--cc-ease)}.cc-actions:before{right:100%}.cc-actions:after{right:var(--inset)}.cc-slot{--shown: var(--copy);display:flex;justify-content:flex-end;width:calc(var(--shown) * 24px);overflow:hidden;transition:width var(--cc-ease)}.cc-note,.cc-reset{--shown: var(--reset)}.cc-action{all:unset;display:grid;place-items:center;flex-shrink:0;width:20px;height:20px;border-radius:4px;color:var(--cc-muted);cursor:pointer;transform:translate(calc((1 - var(--shown)) * 24px));transition:transform var(--cc-ease)}.cc-action:hover{color:var(--cc-foreground)}.cc-code[data-note]:after{content:attr(data-note);position:absolute;top:26px;right:4px;padding:4px 8px;border-radius:6px;background:var(--cc-subtle);color:var(--cc-secondary);font:12px/16px var(--cc-sans);white-space:nowrap;box-shadow:0 8px 24px #0000001f;opacity:0;transition:opacity var(--cc-ease);pointer-events:none}.cc-code:has(.cc-note :is(:hover,:focus)):after{opacity:1}@media(prefers-reduced-motion:reduce){.cc *{transition:none!important}}';import{Fragment as O,jsx as i,jsxs as f}from"react/jsx-runtime";var W=x;function B(e,d){$(()=>{if(document.getElementById(e))return;let a=document.createElement("style");a.id=e,a.textContent=d,document.head.prepend(a)},[])}function _(e){let d=e.replace(/^\s*\n/,"").trimEnd().split(`
3
+ `),a=Math.min(...d.filter(t=>t.trim()).map(t=>t.search(/\S/)));return d.map(t=>t.slice(a)).join(`
4
+ `)}var m=e=>e.kind==="boolean"||typeof e.value=="number"?"cc-box cc-keyword":e.quote?"cc-box cc-string":"cc-box";function b({d:e}){return i("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i("path",{d:e})})}var I="M8 7.5h7.5v8H8zM12 4.5H4.5v8",R="M5 10.5l3 3 7-7",T="M5 8.5a5.5 5.5 0 1 1 .5 4.5M5 4.5v4h4",P="M16 10a6 6 0 1 1-12 0a6 6 0 1 1 12 0zM10 9.5v3.5M10 7v.01";function S({control:e,onChange:d,written:a}){let{min:t=-1/0,max:r=1/0,step:s}=e,p=e.value,u=k(null),n=r-t<1/0?Math.min(12,Math.max(2,240*s/(r-t))):6,c=o=>{o=Math.min(r,Math.max(t,o)),o!==p&&d(o)};return i("span",{className:`${m(e)} cc-scrub`,role:"slider",tabIndex:0,"aria-label":e.prop,"aria-valuenow":p,"aria-valuemin":t>-1/0?t:void 0,"aria-valuemax":r<1/0?r:void 0,onPointerDown:o=>{o.currentTarget.setPointerCapture(o.pointerId),u.current={x:o.clientX,value:p}},onPointerMove:o=>{if(u.current){let l=Math.round((o.clientX-u.current.x)/n);c(u.current.value+l*s)}},onPointerUp:()=>u.current=null,onPointerCancel:()=>u.current=null,onKeyDown:o=>{let l=o.shiftKey?s*10:s,h={ArrowUp:p+l,ArrowRight:p+l,ArrowDown:p-l,ArrowLeft:p-l,Home:t,End:r}[o.key];h!==void 0&&Number.isFinite(h)&&(o.preventDefault(),c(h))},children:a})}function z({control:e,onChange:d}){let a=`${e.value}`,{quote:t}=e;return f("label",{className:m(e),children:[t,i("span",{className:"cc-field","data-value":a,children:i("input",{size:1,value:a,"aria-label":e.prop,spellCheck:!1,onChange:r=>d(r.target.value),onKeyDown:r=>{(r.key==="Enter"||r.key==="Escape")&&r.currentTarget.blur()}})}),t]})}function A({control:e,onChange:d,written:a}){let t=k(null),[r,s]=y(!1),p=n=>{let c=typeof n=="string"?e.quote:"";return c+n+c},u=()=>[...t.current.children];return E(()=>{let n=t.current,c=l=>s(l.newState==="open"),o=()=>n.matches(":popover-open")&&n.hidePopover();return n.addEventListener("toggle",c),addEventListener("scroll",o,!0),()=>{n.removeEventListener("toggle",c),removeEventListener("scroll",o,!0)}},[]),f(O,{children:[i("button",{type:"button",className:m(e),"aria-haspopup":"menu","aria-expanded":r,"aria-label":e.prop,onClick:n=>{let c=t.current,{left:o,bottom:l}=n.currentTarget.getBoundingClientRect();c.style.left=`${o}px`,c.style.top=`${l+4}px`,c.showPopover(),u().find(h=>h.getAttribute("aria-checked")==="true")?.focus()},children:a}),i("div",{ref:t,className:"cc-menu",popover:"auto",role:"menu",onKeyDown:n=>{let c=u(),o=c.indexOf(document.activeElement),l={ArrowDown:1,ArrowUp:-1}[n.key];l&&(n.preventDefault(),c[(o+l+c.length)%c.length].focus())},children:e.options.map(n=>i("button",{type:"button",role:"menuitemradio","aria-checked":n===e.value,onClick:()=>d(n),children:p(n)},`${n}`))})]})}function D({source:e,tokens:d,controls:a,onChange:t}){let r=[],s=0,p=0,u=n=>{for(;s<n;){for(;p<d.length&&d[p].end<=s;)p++;let c=d[p];if(c&&c.start<=s){let o=Math.min(c.end,n);r.push(i("span",{className:`cc-${c.ink}`,children:e.slice(s,o)},s)),s=o}else{let o=Math.min(c?.start??n,n);r.push(e.slice(s,o)),s=o}}};return a.forEach((n,c)=>{u(n.range.start);let o=e.slice(n.range.start,n.range.end),l={control:n,written:o,onChange:h=>t(n,h)};r.push(n.kind==="boolean"?i("button",{type:"button",className:m(n),"aria-label":n.prop,"aria-pressed":n.value,onClick:()=>l.onChange(!n.value),children:o},`c${c}`):n.kind==="number"?i(S,{...l},`c${c}`):n.kind==="option"?i(A,{...l},`c${c}`):i(z,{...l},`c${c}`)),s=n.range.end}),u(e.length),f("div",{className:"cc-body",children:[i("div",{className:"cc-lines","aria-hidden":!0,children:e.split(`
5
+ `).map((n,c)=>c+1).join(`
6
+ `)}),i("div",{className:"cc-scroll",children:i("code",{children:r})})]})}function L({source:e,changed:d,note:a,onReset:t}){let[r,s]=y(!1);return f("div",{className:`cc-tab cc-actions${d?" cc-changed":""}`,children:[a&&i("span",{className:"cc-slot cc-note",children:i("button",{type:"button",className:"cc-action","aria-label":a,tabIndex:d?0:-1,children:i(b,{d:P})})}),i("span",{className:"cc-slot",children:i("button",{type:"button",className:"cc-action","aria-label":r?"Copied":"Copy code",onClick:()=>navigator.clipboard.writeText(e).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}),children:i(b,{d:r?R:I})})}),i("span",{className:"cc-slot cc-reset",children:i("button",{type:"button",className:"cc-action","aria-label":"Reset code",tabIndex:d?0:-1,onClick:t,children:i(b,{d:T})})})]})}function j({className:e,theme:d,preview:a,tab:t,source:r,changed:s,note:p,onReset:u,...n}){return f("div",{className:e?`cc ${e}`:"cc","data-theme":d,children:[f("div",{className:"cc-frame",children:[i("div",{className:"cc-preview",children:a}),f("div",{className:"cc-code","data-note":p,children:[t,i(L,{source:r,changed:s,note:p,onReset:u}),i(D,{source:r,...n})]})]}),i("div",{className:"cc-tab",children:"Preview"})]})}var w=e=>`${e}`.split(".")[1]?.length??0,Z=e=>10**-w(e),G=(e,d)=>`${+e.toFixed(w(d))}`;export{Z as a,G as b,H as c,W as d,B as e,_ as f,j as g};
@@ -0,0 +1,6 @@
1
+ 'use client';
2
+ var C=new Set("as async await break case catch class const continue default delete do else enum export extends false finally for from function if import in instanceof interface let new null of return satisfies static switch this throw true try type typeof undefined var void while yield".split(" ")),N=/^(|[(,=:?[{}>&|!]|return)$/;function H(e){let d=[],a=[{in:"code",depth:0}],t=0,i="",s=n=>(n.lastIndex=t,n.exec(e)?.[0]??""),p=(n,c)=>{c&&d.push({ink:n,start:t,end:t+c}),t+=c},u=n=>{let c=t+1;for(;c<e.length&&e[c]!==n;)c+=e[c]==="\\"?2:1;p("string",Math.min(c+1,e.length)-t)};for(;t<e.length;){let n=a[a.length-1],c=e[t];if(n.in==="text"){if(c==="{")t++,a.push({in:"code",depth:0});else if(c==="<")t++,e[t]==="/"?(t++,p("tag",s(/[\w$.:-]*/y).length),t=Math.max(t,e.indexOf(">",t)+1),a.pop()):a.push({in:"tag",named:!1});else{let g=e.slice(t).search(/[<{]/);t=g<0?e.length:t+g}continue}if(n.in==="tag"){let g=s(/[\w$.:-]+/y);g?p(n.named?"attribute":"tag",g.length):c==='"'||c==="'"?u(c):c==="{"?(t++,a.push({in:"code",depth:0})):c===">"?(t++,a[a.length-1]={in:"text"}):e.startsWith("/>",t)?(t+=2,a.pop()):t++,n.named=!0;continue}let o=s(/\s+|\/\/.*|\/\*[\s\S]*?(\*\/|$)/y);if(o){t+=o.length;continue}let l=s(/[A-Za-z_$][\w$]*/y);if(l){let g=e.slice(t+l.length).match(/^\s*(\S)/)?.[1],v=C.has(l)?"keyword":g==="("||/^[A-Z]/.test(l)?"tag":e[t-1]==="."||g===":"&&i!=="?"?"attribute":void 0;v?p(v,l.length):t+=l.length,i=l==="return"?l:"name";continue}let h=s(/\d[\d_]*\.?\d*(e[+-]?\d+)?n?|\.\d+/iy);if(h){p("keyword",h.length),i="name";continue}if(c==='"'||c==="'"||c==="`"){u(c),i="name";continue}if(c==="<"&&N.test(i)&&/[A-Za-z>]/.test(e[t+1]??"")){t++,a.push({in:"tag",named:e[t]===">"}),e[t]===">"&&(t++,a[a.length-1]={in:"text"});continue}if(c==="{"&&n.depth++,c==="}"){if(n.depth===0&&a.length>1){t++,a.pop();continue}n.depth--}i=e.startsWith("&&",t)||e.startsWith("||",t)?"&":c,t++}return d}import{useEffect as M,useInsertionEffect as $,useRef as k,useState as y}from"react";var x='.cc{--cc-surface: light-dark(oklch(100% 0 0), oklch(17.5% 0 0));--cc-subtle: light-dark(oklch(93% 0 0), oklch(24.5% 0 0));--cc-sunken: light-dark(oklch(89.5% 0 0), oklch(21% 0 0));--cc-foreground: light-dark( oklch(22.7% .006 271.2), oklch(92.3% .004 286.3) );--cc-secondary: light-dark( oklch(41.8% .014 274.6), oklch(78.2% .016 281.9) );--cc-muted: light-dark(oklch(52% .044 267.6), oklch(67.3% .028 276.2));--cc-disabled: light-dark(oklch(72% .01 270), oklch(48% .01 280));--cc-text: light-dark(oklch(49% .04 268), oklch(67.3% .028 276.2));--cc-line: light-dark(oklch(59% .02 270), oklch(51% .02 276));--cc-tag: light-dark(oklch(46% .185 145.3), oklch(84.4% .185 145.3));--cc-attribute: light-dark(oklch(46% .088 229.9), oklch(85.7% .088 229.9));--cc-string: light-dark(oklch(46% .191 32.2), oklch(71.2% .191 32.2));--cc-keyword: light-dark(oklch(46% .2 317.2), oklch(76.9% .2 317.2));--cc-sans: Geist, ui-sans-serif, system-ui, sans-serif;--cc-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;--cc-ease: .24s cubic-bezier(.2, .9, .3, 1);--copy: 0;--reset: 0;position:relative;box-sizing:border-box;width:100%;overflow:hidden;container-type:inline-size;border-radius:8px;outline:1px solid var(--cc-subtle);background:var(--cc-subtle);color:var(--cc-foreground);font:16px/24px var(--cc-sans);text-align:left;-webkit-font-smoothing:antialiased}.cc[data-theme=light]{color-scheme:light}.cc[data-theme=dark]{color-scheme:dark}.cc *,.cc *:before,.cc *:after{box-sizing:inherit}.cc-frame{display:grid;gap:2px;padding:2px;background:var(--cc-surface)}@container (min-width: 640px){.cc-frame{grid-template-columns:repeat(2,minmax(0,1fr))}}.cc-preview{display:grid;place-items:center;min-width:0;padding:48px 24px 24px}.cc-problem{margin:0;color:var(--cc-muted);font:14px/20px var(--cc-sans);text-align:center}.cc-tab{--inset: 0px;position:absolute;top:calc(var(--inset) * -1);left:calc(var(--inset) * -1);display:flex;align-items:center;height:24px;padding:0 8px;border-bottom-right-radius:6px;background:var(--ground);color:var(--cc-muted);font:12px/16px var(--cc-sans);white-space:nowrap;pointer-events:none}.cc-tab:before,.cc-tab:after{content:"";position:absolute;width:6px;height:6px;background:radial-gradient(circle at 100% 100%,transparent 6px,var(--ground) 6.5px)}.cc-tab:before{top:var(--inset);left:100%}.cc-tab:after{top:100%;left:var(--inset)}.cc>.cc-tab{--ground: var(--cc-subtle)}.cc-code{--ground: var(--cc-surface);--tint: var(--cc-text);position:relative;min-width:0;padding-top:22px;border-radius:6px;background:var(--cc-sunken);color:var(--cc-text);font:14px/24px var(--cc-mono)}.cc-code>.cc-tab{--inset: 2px}.cc-body{display:flex}.cc-lines{flex-shrink:0;padding:16px 4px 16px 16px;color:var(--cc-line);text-align:right;white-space:pre;user-select:none}.cc-scroll{flex-grow:1;min-width:0;padding:16px 16px 16px 4px;overflow-x:auto;scrollbar-width:thin;scrollbar-color:var(--cc-disabled) transparent}.cc .cc-scroll>code{all:unset;display:block;width:max-content;min-width:100%;white-space:pre;tab-size:2}.cc-tag{color:var(--cc-tag)}.cc-attribute{color:var(--cc-attribute)}.cc-string{--tint: var(--cc-string);color:var(--cc-string)}.cc-keyword{--tint: var(--cc-keyword);color:var(--cc-keyword)}.cc-box{all:unset;display:inline-block;margin:0 -2px;padding:0 4px;border-radius:4px;background:color-mix(in srgb,var(--tint) 14%,transparent);line-height:20px;white-space:pre;cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent}.cc-box:hover,.cc-box:focus-within,.cc-box[aria-expanded=true]{background:color-mix(in srgb,var(--tint) 28%,transparent)}.cc-box:focus-visible,.cc-action:focus-visible,.cc-menu>button:focus-visible{outline:2px solid currentColor;outline-offset:-2px}.cc-scrub{cursor:ew-resize;touch-action:pan-y}.cc-field{display:inline-grid;min-width:8px;cursor:text}.cc-field:after{content:attr(data-value);grid-area:1 / 1;visibility:hidden;white-space:pre}.cc-field>input{all:unset;grid-area:1 / 1;width:100%;min-width:0}.cc-menu{position:fixed;inset:auto;display:none;min-width:96px;margin:0;padding:2px;border:0;font:14px/20px var(--cc-mono)}.cc-menu,.cc-code:after{border-radius:8px;background:var(--cc-subtle);color:var(--cc-secondary);box-shadow:0 8px 24px #0000001f}.cc-menu:popover-open{display:grid;gap:2px}.cc-menu>button{all:unset;display:flex;align-items:center;gap:16px;height:32px;padding:0 8px;border-radius:6px;white-space:pre;cursor:pointer}.cc-menu>button:is(:hover,:focus){background:var(--cc-sunken);color:var(--cc-foreground)}.cc-menu>[aria-checked=true]:after{content:"\\2713";margin-left:auto;color:var(--cc-muted)}.cc-code:is(:hover,:has(:focus-visible)){--copy: 1}@media(hover:none){.cc-code{--copy: 1}}.cc-changed{--reset: 1}.cc-actions{--open: max(var(--copy), var(--reset));top:-2px;right:-2px;left:auto;padding:0 calc(var(--open) * 4px) 0 0;border-radius:0 0 0 6px;pointer-events:auto;transition:padding var(--cc-ease)}.cc-actions:before,.cc-actions:after{left:auto;background:radial-gradient(circle at 0 100%,transparent 6px,var(--ground) 6.5px);opacity:var(--open);transition:opacity var(--cc-ease)}.cc-actions:before{right:100%}.cc-actions:after{right:var(--inset)}.cc-slot{--shown: var(--copy);display:flex;justify-content:flex-end;width:calc(var(--shown) * 24px);overflow:hidden;transition:width var(--cc-ease)}.cc-note,.cc-reset{--shown: var(--reset)}.cc-action{all:unset;display:grid;place-items:center;flex-shrink:0;width:20px;height:20px;border-radius:4px;color:var(--cc-muted);cursor:pointer;transform:translate(calc((1 - var(--shown)) * 24px));transition:transform var(--cc-ease)}.cc-action:hover{color:var(--cc-foreground)}.cc-code:after{content:attr(data-note);position:absolute;top:26px;right:4px;padding:4px 8px;font:12px/16px var(--cc-sans);white-space:nowrap;opacity:0;transition:opacity var(--cc-ease);pointer-events:none}.cc-code:has(.cc-note :is(:hover,:focus)):after{opacity:1}@media(prefers-reduced-motion:reduce){.cc *{transition:none!important}}';import{Fragment as O,jsx as r,jsxs as f}from"react/jsx-runtime";var W=x;function B(e,d){$(()=>{if(document.getElementById(e))return;let a=document.createElement("style");a.id=e,a.textContent=d,document.head.prepend(a)},[])}function _(e){let d=e.replace(/^\s*\n/,"").trimEnd().split(`
3
+ `),a=Math.min(...d.filter(t=>t.trim()).map(t=>t.search(/\S/)));return d.map(t=>t.slice(a)).join(`
4
+ `)}var m=e=>e.kind==="boolean"||typeof e.value=="number"?"cc-box cc-keyword":e.quote?"cc-box cc-string":"cc-box";function b({d:e}){return r("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:r("path",{d:e})})}var I="M8 7.5h7.5v8H8zM12 4.5H4.5v8",R="M5 10.5l3 3 7-7",T="M5 8.5a5.5 5.5 0 1 1 .5 4.5M5 4.5v4h4",P="M16 10a6 6 0 1 1-12 0a6 6 0 0 1 12 0M10 9.5V13m0-6v.01";function S({control:e,onChange:d,written:a}){let{min:t=-1/0,max:i=1/0,step:s}=e,p=e.value,u=k(null),n=i-t<1/0?Math.min(12,Math.max(2,240*s/(i-t))):6,c=o=>{o=Math.min(i,Math.max(t,o)),o!==p&&d(o)};return r("span",{className:`${m(e)} cc-scrub`,role:"slider",tabIndex:0,"aria-label":e.prop,"aria-valuenow":p,"aria-valuemin":t>-1/0?t:void 0,"aria-valuemax":i<1/0?i:void 0,onPointerDown:o=>{o.currentTarget.setPointerCapture(o.pointerId),u.current={x:o.clientX,value:p}},onPointerMove:o=>{if(u.current){let l=Math.round((o.clientX-u.current.x)/n);c(u.current.value+l*s)}},onPointerUp:()=>u.current=null,onPointerCancel:()=>u.current=null,onKeyDown:o=>{let l=o.shiftKey?s*10:s,h={ArrowUp:p+l,ArrowRight:p+l,ArrowDown:p-l,ArrowLeft:p-l,Home:t,End:i}[o.key];h!==void 0&&Number.isFinite(h)&&(o.preventDefault(),c(h))},children:a})}function A({control:e,onChange:d}){let a=`${e.value}`,{quote:t}=e;return f("label",{className:m(e),children:[t,r("span",{className:"cc-field","data-value":a,children:r("input",{size:1,value:a,"aria-label":e.prop,spellCheck:!1,onChange:i=>d(i.target.value),onKeyDown:i=>{(i.key==="Enter"||i.key==="Escape")&&i.currentTarget.blur()}})}),t]})}function z({control:e,onChange:d,written:a}){let t=k(null),[i,s]=y(!1),p=n=>{let c=typeof n=="string"?e.quote:"";return c+n+c},u=()=>[...t.current.children];return M(()=>{let n=t.current,c=l=>s(l.newState==="open"),o=()=>n.matches(":popover-open")&&n.hidePopover();return n.addEventListener("toggle",c),addEventListener("scroll",o,!0),()=>{n.removeEventListener("toggle",c),removeEventListener("scroll",o,!0)}},[]),f(O,{children:[r("button",{type:"button",className:m(e),"aria-haspopup":"menu","aria-expanded":i,"aria-label":e.prop,onClick:n=>{let c=t.current,{left:o,bottom:l}=n.currentTarget.getBoundingClientRect();c.style.left=`${o}px`,c.style.top=`${l+4}px`,c.showPopover(),u().find(h=>h.getAttribute("aria-checked")==="true")?.focus()},children:a}),r("div",{ref:t,className:"cc-menu",popover:"auto",role:"menu",onKeyDown:n=>{let c=u(),o=c.indexOf(document.activeElement),l={ArrowDown:1,ArrowUp:-1}[n.key];l&&(n.preventDefault(),c[(o+l+c.length)%c.length].focus())},children:e.options.map(n=>r("button",{type:"button",role:"menuitemradio","aria-checked":n===e.value,onClick:()=>d(n),children:p(n)},`${n}`))})]})}function D({source:e,tokens:d,controls:a,onChange:t}){let i=[],s=0,p=0,u=n=>{for(;s<n;){for(;p<d.length&&d[p].end<=s;)p++;let c=d[p];if(c&&c.start<=s){let o=Math.min(c.end,n);i.push(r("span",{className:`cc-${c.ink}`,children:e.slice(s,o)},s)),s=o}else{let o=Math.min(c?.start??n,n);i.push(e.slice(s,o)),s=o}}};return a.forEach((n,c)=>{u(n.range.start);let o=e.slice(n.range.start,n.range.end),l={control:n,written:o,onChange:h=>t(n,h)};i.push(n.kind==="boolean"?r("button",{type:"button",className:m(n),"aria-label":n.prop,"aria-pressed":n.value,onClick:()=>l.onChange(!n.value),children:o},`c${c}`):n.kind==="number"?r(S,{...l},`c${c}`):n.kind==="option"?r(z,{...l},`c${c}`):r(A,{...l},`c${c}`)),s=n.range.end}),u(e.length),f("div",{className:"cc-body",children:[r("div",{className:"cc-lines","aria-hidden":!0,children:e.split(`
5
+ `).map((n,c)=>c+1).join(`
6
+ `)}),r("div",{className:"cc-scroll",children:r("code",{children:i})})]})}function L({source:e,changed:d,note:a,onReset:t}){let[i,s]=y(!1);return f("div",{className:`cc-tab cc-actions${d?" cc-changed":""}`,children:[a&&r("span",{className:"cc-slot cc-note",children:r("button",{type:"button",className:"cc-action","aria-label":a,tabIndex:d?0:-1,children:r(b,{d:P})})}),r("span",{className:"cc-slot",children:r("button",{type:"button",className:"cc-action","aria-label":i?"Copied":"Copy code",onClick:()=>navigator.clipboard.writeText(e).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}),children:r(b,{d:i?R:I})})}),r("span",{className:"cc-slot cc-reset",children:r("button",{type:"button",className:"cc-action","aria-label":"Reset code",tabIndex:d?0:-1,onClick:t,children:r(b,{d:T})})})]})}function j({className:e,theme:d,preview:a,tab:t,source:i,changed:s,note:p,onReset:u,...n}){return f("div",{className:e?`cc ${e}`:"cc","data-theme":d,children:[f("div",{className:"cc-frame",children:[r("div",{className:"cc-preview",children:a}),f("div",{className:"cc-code","data-note":p,children:[t,r(L,{source:i,changed:s,note:p,onReset:u}),r(D,{source:i,...n})]})]}),r("div",{className:"cc-tab",children:"Preview"})]})}var w=e=>`${e}`.split(".")[1]?.length??0,Z=e=>10**-w(e),G=(e,d)=>`${+e.toFixed(w(d))}`;export{Z as a,G as b,H as c,W as d,B as e,_ as f,j as g};
@@ -0,0 +1,39 @@
1
+ import type { Element, Range } from './parse';
2
+ /**
3
+ * How a prop is changed: picked from a list, dragged within a range, or kept
4
+ * as written with `false`.
5
+ */
6
+ export type ControlOptions = false | readonly (string | number)[] | {
7
+ min?: number;
8
+ max?: number;
9
+ step?: number;
10
+ };
11
+ export type Control = {
12
+ /** The prop's name, or `children` for text. */
13
+ prop: string;
14
+ kind: 'number' | 'boolean' | 'text' | 'option';
15
+ value: string | number | boolean;
16
+ /** Where the value is, with any quotes. */
17
+ range: Range;
18
+ /** The quote around a string, if it has one. */
19
+ quote: string;
20
+ /** JSX text or a JSX attribute, which take entities rather than escapes. */
21
+ jsx: boolean;
22
+ options?: readonly (string | number)[];
23
+ min?: number;
24
+ max?: number;
25
+ step: number;
26
+ };
27
+ /**
28
+ * Each element's strings, numbers and booleans, and its text where that is
29
+ * all it holds, on one line. `options` is read by `Element.prop`, then by
30
+ * `prop`.
31
+ */
32
+ export declare function findControls(elements: Element[], options?: Readonly<Record<string, ControlOptions>>): Control[];
33
+ /** The code with one control's value changed. */
34
+ export declare function edit(source: string, control: Control, value: string | number | boolean): string;
35
+ /**
36
+ * The code with each prop written alone spelled `={true}`, so it can switch
37
+ * in place.
38
+ */
39
+ export declare function spellBooleans(source: string): string;
@@ -0,0 +1,12 @@
1
+ /** The role a piece of code takes its colour from. Code between tokens is text. */
2
+ export type Ink = 'tag' | 'attribute' | 'string' | 'keyword';
3
+ export type Token = {
4
+ ink: Ink;
5
+ start: number;
6
+ end: number;
7
+ };
8
+ /**
9
+ * Splits TSX into tokens by role: tags, types and functions; attributes and
10
+ * properties; strings; keywords, booleans, `null` and numbers.
11
+ */
12
+ export declare function highlight(source: string): Token[];
@@ -0,0 +1,41 @@
1
+ import type { Controls } from './languages';
2
+ export type { ControlOptions } from './languages';
3
+ /**
4
+ * The stylesheet, which the component adds itself. Put it in the page's head
5
+ * when rendering on a server.
6
+ */
7
+ export declare const styles: string;
8
+ /** A value the reader changed, and what to. */
9
+ export type ComponentCodeChange = {
10
+ file: string;
11
+ prop: string;
12
+ value: string | number | boolean;
13
+ /** The whole file after the change. */
14
+ code: string;
15
+ };
16
+ export type ComponentCodeProps = {
17
+ /**
18
+ * The files by name, each in its own tab: `.html`, `.css` and `.js`. They
19
+ * run together as one page. The blank lines around each and its shared
20
+ * indent are dropped.
21
+ */
22
+ files: Readonly<Record<string, string>>;
23
+ /**
24
+ * The values the reader can change: an attribute, as `r` or `circle.r`, a
25
+ * CSS property or custom property, as `--speed`, or a JS `const`, `let` or
26
+ * `var`.
27
+ */
28
+ controls?: Controls;
29
+ /** Called as the reader changes a value. */
30
+ onChange?: (change: ComponentCodeChange) => void;
31
+ /** Sets light or dark. Without it, the page's `color-scheme` decides. */
32
+ theme?: 'light' | 'dark';
33
+ /** A line from an info icon beside reset, once the reader changes a value. */
34
+ note?: string;
35
+ className?: string;
36
+ };
37
+ /**
38
+ * HTML, CSS and JS running beside their code, a tab for each file. The values
39
+ * named in `controls` are controls the reader can change.
40
+ */
41
+ export declare function ComponentCode({ files, controls: options, onChange, theme, note, className, }: ComponentCodeProps): import("react").JSX.Element;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Runs pages in sandboxed frames in `box`. A run loads behind the one shown
3
+ * and takes its place once it has loaded, so the preview never flashes. Runs
4
+ * asked for while one loads wait, and only the last one starts.
5
+ */
6
+ export declare function runner(box: HTMLElement, report: (problem?: string) => void): {
7
+ /** Runs the HTML and JS with the CSS last given, and `root` under it. */
8
+ run(html: string, js: string, root: string): void;
9
+ /** Changes the CSS without running the page again. */
10
+ css(text: string): void;
11
+ stop(): void;
12
+ };
13
+ export type Runner = ReturnType<typeof runner>;
@@ -0,0 +1,2 @@
1
+ export { ComponentCode, styles } from './ComponentCode';
2
+ export type { ComponentCodeChange, ComponentCodeProps, ControlOptions, } from './ComponentCode';
@@ -0,0 +1,37 @@
1
+ import type { Control } from '../controls';
2
+ import type { Token } from '../highlight';
3
+ import type { Value } from '../panel';
4
+ /**
5
+ * How a value is changed: `true` to change it as it is, a list of options, or
6
+ * a number's range and step.
7
+ */
8
+ export type ControlOptions = true | readonly (string | number)[] | {
9
+ min?: number;
10
+ max?: number;
11
+ step?: number;
12
+ };
13
+ export type Controls = Readonly<Record<string, ControlOptions>>;
14
+ export type Language = 'html' | 'css' | 'js';
15
+ /** A file's colours, and the controls for the values `controls` names. */
16
+ export type Reading = {
17
+ tokens: Token[];
18
+ controls: Control[];
19
+ };
20
+ export declare const languageOf: (file: string) => Language;
21
+ /** Tags, attributes and their values. A value is named `tag.attribute` or `attribute`. */
22
+ declare function html(source: string, options: Controls): Reading;
23
+ /**
24
+ * Selectors, properties and their values. A value is named by its property
25
+ * or custom property, and a number keeps its unit.
26
+ */
27
+ declare function css(source: string, options: Controls): Reading;
28
+ /** JavaScript, coloured. A value is named by the `const`, `let` or `var` it sets. */
29
+ declare function js(source: string, options: Controls): Reading;
30
+ export declare const read: {
31
+ html: typeof html;
32
+ css: typeof css;
33
+ js: typeof js;
34
+ };
35
+ /** The file with one control's value changed. */
36
+ export declare function edit(language: Language, source: string, control: Control, value: Value): string;
37
+ export {};
package/dist/html.js ADDED
@@ -0,0 +1,4 @@
1
+ 'use client';
2
+ import{a as L,b as A,c as O,d as T,e as j,f as M,g as I}from"./chunk-YERRFPDX.js";import{useEffect as v,useMemo as ee,useRef as F,useState as $}from"react";function U(){let n=document.documentElement,o=document.currentScript.previousElementSibling,e=t=>parent.postMessage(t,"*");addEventListener("message",t=>{t.source===parent&&(o.textContent=t.data.css)}),addEventListener("error",t=>e({problem:t.message})),addEventListener("unhandledrejection",t=>e({problem:`${t.reason?.message??t.reason}`})),new ResizeObserver(()=>e({height:n.getBoundingClientRect().height})).observe(n),addEventListener("load",()=>e({ready:!0}))}var S=(n,o)=>n.replace(new RegExp(`</${o}`,"gi"),`<\\/${o}`);function D(n,o,e,t){return`<!doctype html><html><head><meta charset="utf-8"><style>:root{${t}}body{margin:0}</style><style>${S(o,"style")}</style><script>(${U})()<\/script></head><body>${n}<script>${S(e,"script")}<\/script></body></html>`}function N(n,o){let e,t,c,r,a="",d=m=>m?.contentWindow?.postMessage({css:a},"*"),s=({source:m,data:p})=>{let l=[e,t].find(i=>i&&i.contentWindow===m);if(!(!l||typeof p!="object"||!p)&&(p.height!==void 0&&(l.style.height=`${Math.ceil(p.height)}px`),p.problem&&(l===e?o(p.problem):r??=p.problem),p.ready&&l===t)){e?.remove(),e=l,t=void 0,l.dataset.shown="",d(l),o(r),r=void 0;let i=c;c=void 0,i?.()}};return addEventListener("message",s),{run(m,p,l){let i=()=>{t=document.createElement("iframe"),t.setAttribute("sandbox","allow-scripts"),t.title="Preview",e&&(t.style.height=e.style.height),t.srcdoc=D(m,a,p,l),n.append(t)};t?c=i:i()},css(m){a=m,d(e),d(t)},stop(){removeEventListener("message",s),e?.remove(),t?.remove()}}}var P=/^-?(?:\d+\.?\d*|\.\d+)$/,w=n=>/\.css$/i.test(n)?"css":/\.m?js$/i.test(n)?"js":"html";function k(n,o,e,t,c,r=""){let a=Array.isArray(o);return{prop:n,kind:a?"option":typeof e=="string"?"text":typeof e,value:e,range:{start:t,end:c},quote:r,jsx:!1,step:typeof e=="number"?L(e):1,...a?{options:o}:o===!0?{}:o}}var z=n=>(o,e,t)=>{t&&n.push({ink:o,start:e,end:e+t})},W=/<!--[\s\S]*?(?:-->|$)|<[!/]?([A-Za-z][\w:-]*)([^>]*)>?/g,Z=/([^\s"'=<>/]+)(?:\s*=\s*("[^"]*"?|'[^']*'?|[^\s>]+))?/g;function G(n,o){let e=[],t=[],c=z(e),r=new RegExp(W),a;for(;a=r.exec(n);){let[d,s,m]=a;if(!s)continue;let p=a.index+d.indexOf(s);c("tag",p,s.length);let l=s.toLowerCase();for(let i of m.matchAll(Z)){let[,f,g]=i,h=p+s.length+i.index;if(c("attribute",h,f.length),!g)continue;let y=h+i[0].length-g.length;c("string",y,g.length);let b=o[`${l}.${f}`]??o[f];if(!b)continue;let u=/^["']/.test(g)?g[0]:"",C=u?g.slice(1,-1):g;t.push(k(f,b,P.test(C)?+C:C,y,y+g.length,u))}if(d[1]!=="/"&&(l==="script"||l==="style")){let i=n.indexOf(`</${l}`,r.lastIndex);r.lastIndex=i<0?n.length:i}}return{tokens:e,controls:t}}var J=/(["'])(?:\\.|(?!\1)[^\\])*\1?|#[\da-f]{3,8}\b|(?<![\w-])-?(?:\d+\.?\d*|\.\d+)(?:[a-z]+|%)?|!important/gi;function _(n,o){let e=[],t=[],c=z(e),r=0;for(;r<n.length;){let a=/\s+|\/\*[\s\S]*?(?:\*\/|$)/y;a.lastIndex=r;let d=a.exec(n)?.[0].length;if(d){r+=d;continue}let s=r,m=0;for(;s<n.length;){let i=n[s];if(i==='"'||i==="'"){let f=n.indexOf(i,s+1);s=f<0?n.length:f+1;continue}if(i==="(")m++;else if(i===")")m--;else if(m<=0&&/[{};]/.test(i))break;s++}let p=n.slice(r,s).trimEnd(),l=p.indexOf(":");if(p[0]==="@")c("keyword",r,p.match(/^@[\w-]*/)[0].length);else if(n[s]==="{")c("tag",r,p.length);else if(l>0){let i=p.slice(0,l).trim();c("attribute",r,i.length);let f=p.slice(l+1).search(/\S/),g=r+l+1+f,h=f<0?"":p.slice(l+1+f);for(let u of h.matchAll(J))c(u[1]?"string":"keyword",g+u.index,u[0].length);let y=o[i],b=h.match(/^(-?(?:\d+\.?\d*|\.\d+))([a-z]*|%)$/i);y&&h&&t.push(b&&(!Array.isArray(y)||!b[2])?k(i,y,+b[1],g,g+b[1].length):k(i,y,h,g,g+h.length))}r=s+1}return{tokens:e,controls:t}}var K=/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(-?(?:\d+\.?\d*|\.\d+)|true|false|(["'])(?:\\.|(?!\3)[^\\\n])*\3)(?=[ \t]*(?:[;,\n]|$))/g;function Q(n,o){let e=[];for(let t of n.matchAll(K)){let[c,r,a,d=""]=t,s=o[r];if(!s)continue;let m=t.index+c.length-a.length,p=d?a.slice(1,-1).replace(/\\(.)/g,"$1"):P.test(a)?+a:a==="true";e.push(k(r,s,p,m,m+a.length,d))}return{tokens:O(n),controls:e}}var H={html:G,css:_,js:Q};function X(n,o,e){let t=typeof e=="number"?A(e,o.step):`${e}`;if(n==="css")return t.replace(/[;{}<]/g,"");let{quote:c}=o;if(n==="html"){let a=t.replaceAll("&","&amp;").replaceAll("<","&lt;");return c?c+a.replaceAll(c,c==='"'?"&quot;":"&#39;")+c:a}if(typeof e!="string")return t;let r=c||"'";return r+t.replaceAll("\\","\\\\").replaceAll(r,`\\${r}`).replaceAll(`
3
+ `,"\\n")+r}function V(n,o,e,t){let{start:c,end:r}=e.range;return o.slice(0,c)+X(n,e,t)+o.slice(r)}var q=".cc .cc-files{padding:0 2px;pointer-events:auto}.cc-files>button{all:unset;display:flex;align-items:center;height:20px;padding:0 6px;border-radius:4px;cursor:pointer}.cc-files>:hover{color:var(--cc-secondary)}.cc-files>[aria-selected=true]{background:var(--cc-sunken);color:var(--cc-foreground)}.cc-files>:focus-visible{outline:2px solid currentColor;outline-offset:-2px}.cc-run:not([hidden]){display:grid;width:100%}.cc-run>iframe{grid-area:1 / 1;width:100%;border:0;opacity:0;pointer-events:none}.cc-run>[data-shown]{opacity:1;pointer-events:auto}";import{Fragment as oe,jsx as x,jsxs as re}from"react/jsx-runtime";var B=T+q,E=(n,o)=>Object.keys(n).filter(e=>w(e)===o).map(e=>n[e]).join(`
4
+ `);function te({html:n,css:o,js:e,theme:t}){let c=F(null),r=F(null),[a,d]=$();return v(()=>{let s=N(c.current,d);return r.current=s,s.stop},[]),v(()=>r.current.css(o),[o]),v(()=>{let s=matchMedia("(prefers-color-scheme: dark)"),m=()=>{let{colorScheme:p,color:l,fontFamily:i}=getComputedStyle(c.current),f=p.includes("dark")&&(!p.includes("light")||s.matches);r.current.run(n,e,`color-scheme:${f?"dark":"light"};color:${l};font-family:${i}`)};return m(),s.addEventListener("change",m),()=>s.removeEventListener("change",m)},[n,e,t]),re(oe,{children:[a&&x("p",{className:"cc-problem",children:a}),x("div",{ref:c,className:"cc-run",hidden:!!a})]})}function ne({files:n,controls:o={},onChange:e,theme:t,note:c,className:r}){j("component-code-html",B);let a=JSON.stringify(n),d=ee(()=>Object.fromEntries(Object.entries(n).map(([u,C])=>[u,M(C)])),[a]),s=Object.keys(d),[m,p]=$(s[0]),l=s.includes(m)?m:s[0],[i,f]=$({from:d,to:d});i.from!==d&&f({from:d,to:d});let g=i.from===d?i.to:d,h=w(l),{tokens:y,controls:b}=H[h](g[l],o);return x(I,{className:r,theme:t,preview:x(te,{html:E(g,"html"),css:E(g,"css"),js:E(g,"js"),theme:t}),tab:x("div",{className:"cc-tab cc-files",role:"tablist",children:s.map(u=>x("button",{type:"button",role:"tab","aria-selected":u===l,onClick:()=>p(u),children:u},u))}),source:g[l],changed:s.some(u=>g[u]!==d[u]),note:c,onReset:()=>f({from:d,to:d}),tokens:y,controls:b,onChange:(u,C)=>{let R=V(h,g[l],u,C);f({from:d,to:{...g,[l]:R}}),e?.({file:l,prop:u.prop,value:C,code:R})}})}export{ne as ComponentCode,B as styles};
@@ -0,0 +1,2 @@
1
+ export { ComponentCode, styles } from './ComponentCode';
2
+ export type { ComponentCodeChange, ComponentCodeProps, ControlOptions, Scope, } from './ComponentCode';
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use client';
2
+ import{a as j,b as k,c as B,d as O,e as V,f as q,g as P}from"./chunk-YERRFPDX.js";import{Component as Q,createElement as Y,Fragment as ee,useMemo as _,useState as te}from"react";var x=class extends Error{},T=/[A-Za-z_$][\w$-]*/y,D=/-?(?:\d[\d_]*\.?\d*|\.\d+)(?:e[+-]?\d+)?/iy,U={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:"\xA0"},w=t=>t.replace(/&(#x[\da-f]+|#\d+|\w+);/gi,(e,n)=>n[0]==="#"?String.fromCodePoint(n[1]==="x"||n[1]==="X"?parseInt(n.slice(2),16):+n.slice(1)):U[n]??e),X=t=>t.replace(/\\(u\{[\da-f]+\}|u[\da-f]{4}|x[\da-f]{2}|[\s\S])/gi,(e,n)=>n.length>1?String.fromCodePoint(parseInt(n.replace(/[ux{}]/gi,""),16)):{n:`
3
+ `,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0"}[n]??n);function $(t){let e=0,n=o=>{throw new x(o)},i=()=>t.slice(e,e+12).split(`
4
+ `)[0],r=o=>{o.lastIndex=e;let p=o.exec(t)?.[0];return p&&(e+=p.length),p},f=()=>{for(;;)if(r(/\s+/y),t.startsWith("//",e))r(/\/\/.*/y);else if(t.startsWith("/*",e)){let o=t.indexOf("*/",e+2);e=o<0?t.length:o+2}else return},a=o=>(f(),t.startsWith(o,e)),l=o=>{a(o)||n(`Expected \`${o}\` at \`${i()}\`.`),e+=o.length};function m(){let p=[r(T)??n(`Expected a name at \`${i()}\`.`)];for(;t[e]===".";)e++,p.push(r(T)??n("Expected a name after `.`."));return p}function d(o,p=!1){let h=t[e],u=e+1;for(;u<t.length&&t[u]!==h;)t[u]==="\\"&&!p&&u++,u++;u>=t.length&&n("A string is not closed.");let g=t.slice(e+1,u);return h==="`"&&g.includes("${")&&n("A template string cannot run here."),e=u+1,{type:"string",value:p?w(g):X(g),quote:h,jsx:p,start:o,end:e}}function c(){f();let o=e,p=t[e];if(p==='"'||p==="'"||p==="`")return d(o);if(p==="<")return C();if(p==="("){e++;let s=c();return l(")"),s}if(p==="["){e++;let s=[];for(;!a("]");)s.push(c()),a("]")||l(",");return e++,{type:"array",items:s,start:o,end:e}}if(p==="{"){e++;let s=[];for(;!a("}");){let b=e,S=t[e]==='"'||t[e]==="'"?d(e).value:m()[0],z={type:"name",path:[S],start:b,end:e};s.push([S,a(":")?(e++,c()):z]),a("}")||l(",")}return e++,{type:"object",entries:s,start:o,end:e}}let h=r(D);if(h)return{type:"number",value:+h.replace(/_/g,""),start:o,end:e};let u=m(),g=e;if(u.length===1){let s=u[0];if(s==="true"||s==="false")return{type:"boolean",value:s==="true",start:o,end:g};if(s==="null"||s==="undefined")return{type:s,start:o,end:g}}return a("(")&&n(`\`${u.join(".")}()\` is a call, which cannot run here.`),{type:"name",path:u,start:o,end:g}}function C(){let o=e;l("<");let p=a(">")?"":m().join("."),h=[];for(;;){if(a("/>"))return e+=2,{type:"element",name:p,attributes:h,children:[],start:o,end:e};if(a(">"))break;let g=e;if(a("{")){e++,l("...");let S=c();l("}"),h.push({name:"",value:S,spread:!0,start:g,end:e});continue}let s=r(/[\w$:-]+/y)??n(`Expected a prop at \`${i()}\`.`),b=e,y=null;a("=")&&(e++,f(),t[e]==="{"?(e++,y=c(),l("}")):t[e]==='"'||t[e]==="'"?y=d(e,!0):y=c()),h.push({name:s,value:y,start:g,end:y?e:b})}e++;let u=[];for(;;){e>=t.length&&n(`\`<${p}>\` is not closed.`);let g=e;if(t.startsWith("</",e)){e+=2,f();let s=t[e]===">"?"":m().join(".");return s!==p&&n(`\`</${s}>\` does not close \`<${p}>\`.`),l(">"),{type:"element",name:p,attributes:h,children:u,start:o,end:e}}t[e]==="<"?u.push(C()):t[e]==="{"?(e++,a("}")||u.push(c()),l("}")):(e=t.slice(e).search(/[<{]/)+e,e<g&&(e=t.length),u.push({type:"text",raw:t.slice(g,e),start:g,end:e}))}}let E=[];for(;!a(";")&&e<t.length;){t[e]!=="<"&&t[e]!=="("&&n(`Expected an element at \`${i()}\`.`);let o=c();o.type!=="element"&&n("Expected an element."),E.push(o)}return E}function I(t,e={}){let n=[],i=(f,a,l)=>{let m=e[`${f}.${a}`]??e[a],{value:d}=l,c=l.type==="string"?l.quote:"";m===!1||c==="`"||`${d}`.includes(`
5
+ `)||n.push({prop:a,kind:Array.isArray(m)?"option":l.type==="string"?"text":l.type,value:d,range:{start:l.start,end:l.end},quote:c,jsx:l.type==="string"&&(!c||!!l.jsx),step:typeof d=="number"?j(d):1,...Array.isArray(m)?{options:m}:m})},r=f=>{for(let{name:m,value:d}of f.attributes)d?.type==="element"?r(d):(d?.type==="string"||d?.type==="number"||d?.type==="boolean")&&i(f.name,m,d);let[a]=f.children,l=a?.type==="text"?a.raw.trim():"";if(f.children.length===1&&l&&!l.includes(`
6
+ `)){let m=a.start+a.raw.indexOf(l);i(f.name,"children",{type:"string",value:w(l),quote:"",start:m,end:m+l.length})}for(let m of f.children)m.type==="element"&&r(m)};return t.forEach(r),n}function Z(t,e){let{quote:n}=t;if(typeof e!="string"){let r=typeof e=="number"?k(e,t.step):`${e}`;return t.jsx&&n?`{${r}}`:r}if(!t.jsx){let r=n||'"';return r+e.replaceAll("\\","\\\\").replaceAll(r,`\\${r}`)+r}let i=e.replaceAll("&","&amp;").replaceAll("<","&lt;");return n?n+i.replaceAll(n,n==='"'?"&quot;":"&apos;")+n:i.replaceAll(">","&gt;").replaceAll("{","&#123;").replaceAll("}","&#125;")}function L(t,e,n){let{start:i,end:r}=e.range;return t.slice(0,i)+Z(e,n)+t.slice(r)}function F(t){let e=[],n=i=>{for(let r of i.attributes)!r.value&&!r.spread?e.push(r.end):r.value?.type==="element"&&n(r.value);for(let r of i.children)r.type==="element"&&n(r)};return $(t).forEach(n),e.reverse().reduce((i,r)=>i.slice(0,r)+"={true}"+i.slice(r),t)}import{createElement as G,Fragment as H}from"react";function J(t){let e=t.split(`
7
+ `);return w(e.map((n,i)=>{let r=i>0?n.trimStart():n;return i<e.length-1?r.trimEnd():r}).filter(Boolean).join(" "))}function W(t,e){let[n,...i]=t;if(!Object.hasOwn(e,n))throw new x(`\`${n}\` is not in \`scope\`.`);let r=e[n];for(let f of i)r=r?.[f];if(r===void 0)throw new x(`\`${t.join(".")}\` is not in \`scope\`.`);return r}function v(t,e){switch(t.type){case"element":return A(t,e);case"name":return W(t.path,e);case"array":return t.items.map(n=>v(n,e));case"object":return Object.fromEntries(t.entries.map(([n,i])=>[n,v(i,e)]));case"null":return null;case"undefined":return;default:return t.value}}function K(t,e){return t.type==="text"?J(t.raw)||null:v(t,e)}function A(t,e){let n=t.name?/^[a-z][^.]*$/.test(t.name)?t.name:W(t.name.split("."),e):H,i={};for(let r of t.attributes)r.spread?Object.assign(i,v(r.value,e)):i[r.name]=r.value?v(r.value,e):!0;return G(n,i,...t.children.map(r=>K(r,e)))}import{jsx as R}from"react/jsx-runtime";var M=O,N=class extends Q{state={};static getDerivedStateFromError(e){return{problem:e instanceof Error?e.message:`${e}`}}static getDerivedStateFromProps({source:e},n){return n.source===e?null:{source:e,problem:void 0}}render(){let{problem:e}=this.state;return e?R("p",{className:"cc-problem",children:e}):this.props.children}};function ne({code:t,file:e="Code",theme:n,note:i,className:r,scope:f,interactive:a,controls:l,onChange:m,children:d}){V("component-code",M);let c=_(()=>{let s=q(t);try{return a?F(s):s}catch{return s}},[t,a]),[C,E]=te({from:c,to:c});C.from!==c&&E({from:c,to:c});let o=C.from===c?C.to:c,p=_(()=>B(o),[o]),h=d,u,g=[];if(f)try{let s=$(o);h=Y(ee,null,...s.map(b=>A(b,f))),a&&(g=I(s,l))}catch(s){if(!(s instanceof x))throw s;u=s.message}return R(P,{className:r,theme:n,preview:u?R("p",{className:"cc-problem",children:u}):R(N,{source:o,children:h}),tab:R("div",{className:"cc-tab",children:e}),source:o,changed:o!==c,note:i,onReset:()=>E({from:c,to:c}),tokens:p,controls:g,onChange:(s,b)=>{let y=L(o,s,b);E({from:c,to:y}),m?.({prop:s.prop,value:b,code:y})}})}export{ne as ComponentCode,M as styles};
@@ -0,0 +1,4 @@
1
+ /** A number's step: its last decimal place, `1` for `8` and `0.1` for `0.5`. */
2
+ export declare const stepOf: (value: number) => number;
3
+ /** A number written to its step's decimal places. */
4
+ export declare const round: (value: number, step: number) => string;
@@ -0,0 +1,24 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { Control } from './controls';
3
+ import type { Token } from './highlight';
4
+ /** The stylesheet both entries share. */
5
+ export declare const base: string;
6
+ export type Value = string | number | boolean;
7
+ /** Adds `css` to the page once, first, so the page's own styles win. */
8
+ export declare function useStyles(id: string, css: string): void;
9
+ /** Code without the blank lines around it or the indent its lines share. */
10
+ export declare function dedent(code: string): string;
11
+ /** The preview beside the code, with the code's tab, copy and reset. */
12
+ export declare function Panel({ className, theme, preview, tab, source, changed, note, onReset, ...code }: {
13
+ className?: string;
14
+ theme?: 'light' | 'dark';
15
+ preview: ReactNode;
16
+ tab: ReactNode;
17
+ source: string;
18
+ changed: boolean;
19
+ note?: string;
20
+ onReset: () => void;
21
+ tokens: Token[];
22
+ controls: Control[];
23
+ onChange: (control: Control, value: Value) => void;
24
+ }): import("react").JSX.Element;
@@ -0,0 +1,58 @@
1
+ /** Where a node sits in the code, as offsets. */
2
+ export type Range = {
3
+ start: number;
4
+ end: number;
5
+ };
6
+ export type Literal = Range & ({
7
+ type: 'string';
8
+ value: string;
9
+ quote: string;
10
+ jsx?: boolean;
11
+ } | {
12
+ type: 'number';
13
+ value: number;
14
+ } | {
15
+ type: 'boolean';
16
+ value: boolean;
17
+ });
18
+ export type Value = Literal | Element | (Range & {
19
+ type: 'null' | 'undefined';
20
+ }) | (Range & {
21
+ type: 'name';
22
+ path: string[];
23
+ }) | (Range & {
24
+ type: 'array';
25
+ items: Value[];
26
+ }) | (Range & {
27
+ type: 'object';
28
+ entries: [string, Value][];
29
+ });
30
+ /** A prop, its value `null` when it is written alone, or a spread. */
31
+ export type Attribute = Range & {
32
+ name: string;
33
+ value: Value | null;
34
+ spread?: boolean;
35
+ };
36
+ export type Text = Range & {
37
+ type: 'text';
38
+ raw: string;
39
+ };
40
+ export type Child = Element | Text | Value;
41
+ /** An element. A fragment has no name. */
42
+ export type Element = Range & {
43
+ type: 'element';
44
+ name: string;
45
+ attributes: Attribute[];
46
+ children: Child[];
47
+ };
48
+ /** Why code cannot run, worded for the reader. */
49
+ export declare class CodeError extends Error {
50
+ }
51
+ /** JSX text with its entities read. */
52
+ export declare const decode: (text: string) => string;
53
+ /**
54
+ * Reads JSX: elements, their props and children. A value is a string, a
55
+ * number, a boolean, `null`, `undefined`, a list, an object, an element or a
56
+ * name with its members. Anything else is a `CodeError`.
57
+ */
58
+ export declare function parse(source: string): Element[];
package/dist/run.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { Element } from './parse';
3
+ /** What the code can name: components and values. */
4
+ export type Scope = Readonly<Record<string, unknown>>;
5
+ /**
6
+ * JSX text as React shows it: lines trimmed where they meet, empty lines
7
+ * dropped and the rest joined by a space.
8
+ */
9
+ export declare function text(raw: string): string;
10
+ /** An element, rendered with what `scope` names. A lowercase tag is the browser's own. */
11
+ export declare function render(node: Element, scope: Scope): ReactNode;
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@fabiocv/component-code",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "A React component beside the code that makes it, with every value in the code a control.",
5
+ "keywords": [
6
+ "react",
7
+ "component",
8
+ "preview",
9
+ "playground",
10
+ "live code",
11
+ "documentation",
12
+ "storybook",
13
+ "mdx"
14
+ ],
15
+ "license": "MIT",
16
+ "author": "Fabio Azevedo (https://fabio.cv)",
17
+ "homepage": "https://mcp-ui-tools.fabio.cv/component-code/",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/naso/mcp-ui-tools.git",
21
+ "directory": "packages/component-code"
22
+ },
23
+ "bugs": "https://github.com/naso/mcp-ui-tools/issues",
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./html": {
32
+ "types": "./dist/html/index.d.ts",
33
+ "default": "./dist/html.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist/**/*.js",
38
+ "dist/**/*.d.ts"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "peerDependencies": {
44
+ "react": ">=18",
45
+ "react-dom": ">=18"
46
+ },
47
+ "devDependencies": {
48
+ "@types/react": "19.2.17",
49
+ "@types/react-dom": "19.2.3",
50
+ "esbuild": "0.28.1",
51
+ "jsdom": "26.1.0",
52
+ "react": "19.2.7",
53
+ "react-dom": "19.2.7",
54
+ "typescript": "6.0.3",
55
+ "vitest": "4.1.10"
56
+ },
57
+ "scripts": {
58
+ "build": "node scripts/build.js && tsc -p tsconfig.build.json",
59
+ "test": "vitest run",
60
+ "check-types": "tsc --noEmit"
61
+ }
6
62
  }