@fabiocv/component-code 0.1.1 → 0.2.0

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/README.md CHANGED
@@ -72,6 +72,25 @@ A number steps by its last decimal place unless `step` is set: `1` for `8`,
72
72
  `0.1` for `0.5`. A prop written alone, such as `open`, is shown as `open={true}`
73
73
  so it can switch.
74
74
 
75
+ A component in the preview can change its own code too. For each value the code
76
+ sets on it, such as `checked={true}`, it gets a handler named the way Base UI
77
+ and Radix name them, such as `onCheckedChange`. Calling it with a new value
78
+ writes that value into the code, so switching a toggle in the preview shows in
79
+ the code. A handler the code writes itself is kept, and the browser's own
80
+ elements get none.
81
+
82
+ ```tsx
83
+ function Toggle({ checked, onCheckedChange }) {
84
+ return (
85
+ <button
86
+ role="switch"
87
+ aria-checked={checked}
88
+ onClick={() => onCheckedChange?.(!checked)}
89
+ />
90
+ );
91
+ }
92
+ ```
93
+
75
94
  ## Styling
76
95
 
77
96
  It follows the page's `color-scheme`, or `theme`. Each colour and font is a
@@ -0,0 +1,6 @@
1
+ 'use client';
2
+ var E=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 F(e){let s=[],c=[{in:"code",depth:0}],t=0,o="",l=a=>(a.lastIndex=t,a.exec(e)?.[0]??""),d=(a,n)=>{n&&s.push({ink:a,start:t,end:t+n}),t+=n},g=a=>{let n=t+1;for(;n<e.length&&e[n]!==a;)n+=e[n]==="\\"?2:1;d("string",Math.min(n+1,e.length)-t)};for(;t<e.length;){let a=c[c.length-1],n=e[t];if(a.in==="text"){if(n==="{")t++,c.push({in:"code",depth:0});else if(n==="<")t++,e[t]==="/"?(t++,d("tag",l(/[\w$.:-]*/y).length),t=Math.max(t,e.indexOf(">",t)+1),c.pop()):c.push({in:"tag",named:!1});else{let h=e.slice(t).search(/[<{]/);t=h<0?e.length:t+h}continue}if(a.in==="tag"){let h=l(/[\w$.:-]+/y);h?d(a.named?"attribute":"tag",h.length):n==='"'||n==="'"?g(n):n==="{"?(t++,c.push({in:"code",depth:0})):n===">"?(t++,c[c.length-1]={in:"text"}):e.startsWith("/>",t)?(t+=2,c.pop()):t++,a.named=!0;continue}let r=l(/\s+|\/\/.*|\/\*[\s\S]*?(\*\/|$)/y);if(r){t+=r.length;continue}let i=l(/[A-Za-z_$][\w$]*/y);if(i){let h=e.slice(t+i.length).match(/^\s*(\S)/)?.[1],m=E.has(i)?"keyword":h==="("||/^[A-Z]/.test(i)?"tag":e[t-1]==="."||h===":"&&o!=="?"?"attribute":void 0;m?d(m,i.length):t+=i.length,o=i==="return"?i:"name";continue}let u=l(/\d[\d_]*\.?\d*(e[+-]?\d+)?n?|\.\d+/iy);if(u){d("keyword",u.length),o="name";continue}if(n==='"'||n==="'"||n==="`"){g(n),o="name";continue}if(n==="<"&&M.test(o)&&/[A-Za-z>]/.test(e[t+1]??"")){t++,c.push({in:"tag",named:e[t]===">"}),e[t]===">"&&(t++,c[c.length-1]={in:"text"});continue}if(n==="{"&&a.depth++,n==="}"){if(a.depth===0&&c.length>1){t++,c.pop();continue}a.depth--}o=e.startsWith("&&",t)||e.startsWith("||",t)?"&":n,t++}return s}import{useEffect as T,useInsertionEffect as $,useRef as b,useState as y}from"react";var k='.cc{--cc-surface:light-dark(#fff,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%,#0000 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) #0000}.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%,#0000);line-height:20px;white-space:pre;cursor:pointer;user-select:none;-webkit-tap-highlight-color:#0000}.cc-box:is(:hover,:focus-within,[aria-expanded=true]){background:color-mix(in srgb,var(--tint) 28%,#0000)}:is(.cc-box,.cc-action,.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%,#0000 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-action svg{fill:none;stroke:currentColor;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round}.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 q,jsx as p,jsxs as f}from"react/jsx-runtime";var _=k;function j(e,s){$(()=>{if(document.getElementById(e))return;let c=document.createElement("style");c.id=e,c.textContent=s,document.head.prepend(c)},[])}function U(e){let s=e.replace(/^\s*\n/,"").trimEnd().split(`
3
+ `),c=Math.min(...s.filter(t=>t.trim()).map(t=>t.search(/\S/)));return s.map(t=>t.slice(c)).join(`
4
+ `)}var v=e=>e.kind==="boolean"||typeof e.value=="number"?"cc-box cc-keyword":e.quote?"cc-box cc-string":"cc-box",I="M8 7.5h7.5v8H8zM12 4.5H4.5v8",P="M5 10.5l3 3 7-7",R="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 0 1 12 0M10 9.5V13m0-6v.01";function A({control:e,onChange:s,written:c}){let{min:t=-1/0,max:o=1/0,step:l}=e,d=e.value,g=b(null),a=o-t<1/0?Math.min(12,Math.max(2,240*l/(o-t))):6,n=()=>g.current=null,r=i=>{i=Math.min(o,Math.max(t,i)),i!==d&&s(i)};return p("span",{className:`${v(e)} cc-scrub`,role:"slider",tabIndex:0,"aria-label":e.prop,"aria-valuenow":d,"aria-valuemin":t>-1/0?t:void 0,"aria-valuemax":o<1/0?o:void 0,onPointerDown:i=>{i.currentTarget.setPointerCapture(i.pointerId),g.current={x:i.clientX,value:d}},onPointerMove:i=>{if(g.current){let u=Math.round((i.clientX-g.current.x)/a);r(g.current.value+u*l)}},onPointerUp:n,onPointerCancel:n,onKeyDown:i=>{let u=i.shiftKey?l*10:l,h={ArrowUp:d+u,ArrowRight:d+u,ArrowDown:d-u,ArrowLeft:d-u,Home:t,End:o}[i.key];h!==void 0&&isFinite(h)&&(i.preventDefault(),r(h))},children:c})}function z({control:e,onChange:s,written:c}){return p("button",{type:"button",className:v(e),"aria-label":e.prop,"aria-pressed":e.value,onClick:()=>s(!e.value),children:c})}function D({control:e,onChange:s}){let c=`${e.value}`,{quote:t}=e;return f("label",{className:v(e),children:[t,p("span",{className:"cc-field","data-value":c,children:p("input",{size:1,value:c,"aria-label":e.prop,spellCheck:!1,onChange:o=>s(o.target.value),onKeyDown:o=>{(o.key==="Enter"||o.key==="Escape")&&o.currentTarget.blur()}})}),t]})}function H({control:e,onChange:s,written:c}){let t=b(null),o=b(null),[l,d]=y(!1),g=n=>{let r=typeof n=="string"?e.quote:"";return r+n+r},a=()=>[...t.current.children];return T(()=>{let n=t.current,r=u=>d(u.newState==="open"),i=()=>n.matches(":popover-open")&&n.hidePopover();return n.addEventListener("toggle",r),addEventListener("scroll",i,!0),()=>{n.removeEventListener("toggle",r),removeEventListener("scroll",i,!0)}},[]),f(q,{children:[p("button",{ref:o,type:"button",className:v(e),"aria-haspopup":"menu","aria-expanded":l,"aria-label":e.prop,onClick:n=>{let r=t.current,{left:i,bottom:u}=n.currentTarget.getBoundingClientRect();r.style.left=`${i}px`,r.style.top=`${u+4}px`,r.showPopover(),r.querySelector("[aria-checked=true]")?.focus()},children:c}),p("div",{ref:t,className:"cc-menu",popover:"auto",role:"menu",onKeyDown:n=>{let r=a(),i=r.indexOf(document.activeElement),{key:u}=n,h=u.length===1&&[...r.slice(i+1),...r].find(C=>C.textContent.replace(/^\W/,"").startsWith(u)),m=h?r.indexOf(h):{ArrowDown:i+1,ArrowUp:i-1,Home:0,End:-1}[u];u==="Escape"&&o.current.focus(),m!==void 0&&(n.preventDefault(),r.at(m%r.length).focus())},children:e.options.map(n=>p("button",{type:"button",role:"menuitemradio","aria-checked":n===e.value,onClick:()=>s(n),children:g(n)},`${n}`))})]})}function L({source:e,tokens:s,controls:c,onChange:t}){let o=[],l=0,d=0,g=a=>{for(;l<a;){for(;d<s.length&&s[d].end<=l;)d++;let n=s[d];if(n&&n.start<=l){let r=Math.min(n.end,a);o.push(p("span",{className:`cc-${n.ink}`,children:e.slice(l,r)},l)),l=r}else{let r=Math.min(n?.start??a,a);o.push(e.slice(l,r)),l=r}}};return c.forEach((a,n)=>{g(a.range.start);let r=e.slice(a.range.start,a.range.end),i={control:a,written:r,onChange:h=>t(a,h)},u={boolean:z,number:A,option:H,text:D}[a.kind];o.push(p(u,{...i},`c${n}`)),l=a.range.end}),g(e.length),f("div",{className:"cc-body",children:[p("div",{className:"cc-lines","aria-hidden":!0,children:e.split(`
5
+ `).map((a,n)=>n+1).join(`
6
+ `)}),p("div",{className:"cc-scroll",children:p("code",{children:o})})]})}function x({slot:e,label:s,d:c,hidden:t,onClick:o}){return p("span",{className:`cc-slot${e}`,children:p("button",{type:"button",className:"cc-action","aria-label":s,tabIndex:t?-1:0,onClick:o,children:p("svg",{width:"20",height:"20",viewBox:"0 0 20 20","aria-hidden":!0,children:p("path",{d:c})})})})}function O({source:e,changed:s,note:c,onReset:t}){let[o,l]=y(!1);return f("div",{className:`cc-tab cc-actions${s?" cc-changed":""}`,children:[c&&p(x,{slot:" cc-note",label:c,d:S,hidden:!s}),p(x,{slot:" cc-reset",label:"Reset code",d:R,hidden:!s,onClick:t}),p(x,{slot:"",label:o?"Copied":"Copy code",d:o?P:I,onClick:()=>navigator.clipboard.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)})})]})}function X({className:e,theme:s,preview:c,tab:t,source:o,changed:l,note:d,onReset:g,...a}){return f("div",{className:e?`cc ${e}`:"cc","data-theme":s,children:[f("div",{className:"cc-frame",children:[p("div",{className:"cc-preview",children:c}),f("div",{className:"cc-code","data-note":d,children:[t,p(O,{source:o,changed:l,note:d,onReset:g}),p(L,{source:o,...a})]})]}),p("div",{className:"cc-tab",children:"Preview"})]})}var w=e=>`${e}`.split(".")[1]?.length??0,Y=e=>10**-w(e),J=(e,s)=>`${+e.toFixed(w(s))}`;export{Y as a,J as b,F as c,_ as d,j as e,U as f,X as g};
package/dist/html.js CHANGED
@@ -1,4 +1,4 @@
1
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(`
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-6KF2RVCT.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
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};
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
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};
2
+ import{a as T,b as B,c as O,d as V,e as q,f as P,g as I}from"./chunk-6KF2RVCT.js";import{Component as Y,createElement as ee,Fragment as te,useMemo as z,useState as ne}from"react";var C=class extends Error{},L=/[A-Za-z_$][\w$-]*/y,U=/-?(?:\d[\d_]*\.?\d*|\.\d+)(?:e[+-]?\d+)?/iy,X={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:"\xA0"},v=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)):X[n]??e),Z=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 A(t){let e=0,n=o=>{throw new C(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},l=()=>{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},s=o=>(l(),t.startsWith(o,e)),a=o=>{s(o)||n(`Expected \`${o}\` at \`${i()}\`.`),e+=o.length};function f(){let p=[r(L)??n(`Expected a name at \`${i()}\`.`)];for(;t[e]===".";)e++,p.push(r(L)??n("Expected a name after `.`."));return p}function g(o,p=!1){let h=t[e],m=e+1;for(;m<t.length&&t[m]!==h;)t[m]==="\\"&&!p&&m++,m++;m>=t.length&&n("A string is not closed.");let d=t.slice(e+1,m);return h==="`"&&d.includes("${")&&n("A template string cannot run here."),e=m+1,{type:"string",value:p?v(d):Z(d),quote:h,jsx:p,start:o,end:e}}function c(){l();let o=e,p=t[e];if(p==='"'||p==="'"||p==="`")return g(o);if(p==="<")return E();if(p==="("){e++;let u=c();return a(")"),u}if(p==="["){e++;let u=[];for(;!s("]");)u.push(c()),s("]")||a(",");return e++,{type:"array",items:u,start:o,end:e}}if(p==="{"){e++;let u=[];for(;!s("}");){let y=e,b=t[e]==='"'||t[e]==="'"?g(e).value:f()[0],$={type:"name",path:[b],start:y,end:e};u.push([b,s(":")?(e++,c()):$]),s("}")||a(",")}return e++,{type:"object",entries:u,start:o,end:e}}let h=r(U);if(h)return{type:"number",value:+h.replace(/_/g,""),start:o,end:e};let m=f(),d=e;if(m.length===1){let u=m[0];if(u==="true"||u==="false")return{type:"boolean",value:u==="true",start:o,end:d};if(u==="null"||u==="undefined")return{type:u,start:o,end:d}}return s("(")&&n(`\`${m.join(".")}()\` is a call, which cannot run here.`),{type:"name",path:m,start:o,end:d}}function E(){let o=e;a("<");let p=s(">")?"":f().join("."),h=[];for(;;){if(s("/>"))return e+=2,{type:"element",name:p,attributes:h,children:[],start:o,end:e};if(s(">"))break;let d=e;if(s("{")){e++,a("...");let b=c();a("}"),h.push({name:"",value:b,spread:!0,start:d,end:e});continue}let u=r(/[\w$:-]+/y)??n(`Expected a prop at \`${i()}\`.`),y=e,x=null;s("=")&&(e++,l(),t[e]==="{"?(e++,x=c(),a("}")):t[e]==='"'||t[e]==="'"?x=g(e,!0):x=c()),h.push({name:u,value:x,start:d,end:x?e:y})}e++;let m=[];for(;;){e>=t.length&&n(`\`<${p}>\` is not closed.`);let d=e;if(t.startsWith("</",e)){e+=2,l();let u=t[e]===">"?"":f().join(".");return u!==p&&n(`\`</${u}>\` does not close \`<${p}>\`.`),a(">"),{type:"element",name:p,attributes:h,children:m,start:o,end:e}}t[e]==="<"?m.push(E()):t[e]==="{"?(e++,s("}")||m.push(c()),a("}")):(e=t.slice(e).search(/[<{]/)+e,e<d&&(e=t.length),m.push({type:"text",raw:t.slice(d,e),start:d,end:e}))}}let w=[];for(;!s(";")&&e<t.length;){t[e]!=="<"&&t[e]!=="("&&n(`Expected an element at \`${i()}\`.`);let o=c();o.type!=="element"&&n("Expected an element."),w.push(o)}return w}function M(t,e={}){let n=[],i=(l,s,a)=>{let f=e[`${l}.${s}`]??e[s],{value:g}=a,c=a.type==="string"?a.quote:"";f===!1||c==="`"||`${g}`.includes(`
5
+ `)||n.push({prop:s,kind:Array.isArray(f)?"option":a.type==="string"?"text":a.type,value:g,range:{start:a.start,end:a.end},quote:c,jsx:a.type==="string"&&(!c||!!a.jsx),step:typeof g=="number"?T(g):1,...Array.isArray(f)?{options:f}:f})},r=l=>{for(let{name:f,value:g}of l.attributes)g?.type==="element"?r(g):(g?.type==="string"||g?.type==="number"||g?.type==="boolean")&&i(l.name,f,g);let[s]=l.children,a=s?.type==="text"?s.raw.trim():"";if(l.children.length===1&&a&&!a.includes(`
6
+ `)){let f=s.start+s.raw.indexOf(a);i(l.name,"children",{type:"string",value:v(a),quote:"",start:f,end:f+a.length})}for(let f of l.children)f.type==="element"&&r(f)};return t.forEach(r),n}function G(t,e){let{quote:n}=t;if(typeof e!="string"){let r=typeof e=="number"?B(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 F(t,e,n){let{start:i,end:r}=e.range;return t.slice(0,i)+G(e,n)+t.slice(r)}function W(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 A(t).forEach(n),e.reverse().reduce((i,r)=>i.slice(0,r)+"={true}"+i.slice(r),t)}import{createElement as H,Fragment as J}from"react";var k=Symbol(),K=t=>v(t.split(/\s*\n\s*/).filter(Boolean).join(" "));function _(t,e){let[n,...i]=t;if(!Object.hasOwn(e,n))throw new C(`\`${n}\` is not in \`scope\`.`);let r=e[n];for(let l of i)r=r?.[l];if(r===void 0)throw new C(`\`${t.join(".")}\` is not in \`scope\`.`);return r}function R(t,e){switch(t.type){case"element":return N(t,e);case"name":return _(t.path,e);case"array":return t.items.map(n=>R(n,e));case"object":return Object.fromEntries(t.entries.map(([n,i])=>[n,R(i,e)]));case"null":return null;case"undefined":return;default:return t.value}}function Q(t,e){return t.type==="text"?K(t.raw)||null:R(t,e)}function N(t,e){let n=t.name?/^[a-z][^.]*$/.test(t.name)?t.name:_(t.name.split("."),e):J,i={},r=e[k];for(let l of t.attributes){let s=typeof n!="string"&&r?.get(l.value?.start);if(s){let{name:a}=l;i[`on${a[0].toUpperCase()}${a.slice(1)}Change`]=s}l.spread?Object.assign(i,R(l.value,e)):i[l.name]=l.value?R(l.value,e):!0}return H(n,i,...t.children.map(l=>Q(l,e)))}import{jsx as S}from"react/jsx-runtime";var D=V,j=class extends Y{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?S("p",{className:"cc-problem",children:e}):this.props.children}};function re({code:t,file:e="Code",theme:n,note:i,className:r,scope:l,interactive:s,controls:a,onChange:f,children:g}){q("component-code",D);let c=z(()=>{let y=P(t);try{return s?W(y):y}catch{return y}},[t,s]),[E,w]=ne({from:c,to:c});E.from!==c&&w({from:c,to:c});let o=E.from===c?E.to:c,p=z(()=>O(o),[o]),h=(y,x)=>{let b=F(o,y,x);w({from:c,to:b}),f?.({prop:y.prop,value:x,code:b})},m=g,d,u=[];if(l)try{let y=A(o);s&&(u=M(y,a));let x={...l,[k]:new Map(u.map(b=>[b.range.start,$=>typeof $==typeof b.value&&h(b,$)]))};m=ee(te,null,...y.map(b=>N(b,x)))}catch(y){if(!(y instanceof C))throw y;d=y.message}return S(I,{className:r,theme:n,preview:d?S("p",{className:"cc-problem",children:d}):S(j,{source:o,children:m}),tab:S("div",{className:"cc-tab",children:e}),source:o,changed:o!==c,note:i,onReset:()=>w({from:c,to:c}),tokens:p,controls:u,onChange:h})}export{re as ComponentCode,D as styles};
package/dist/run.d.ts CHANGED
@@ -2,10 +2,21 @@ import type { ReactNode } from 'react';
2
2
  import type { Element } from './parse';
3
3
  /** What the code can name: components and values. */
4
4
  export type Scope = Readonly<Record<string, unknown>>;
5
+ /**
6
+ * Under this key in a scope, by where each value starts in the code, a
7
+ * function that writes a new value there. A symbol, so the code cannot name
8
+ * it.
9
+ */
10
+ export declare const SETTERS: unique symbol;
11
+ /** What a scope holds under `SETTERS`. */
12
+ export type Setters = Map<number, (value: unknown) => void>;
5
13
  /**
6
14
  * JSX text as React shows it: lines trimmed where they meet, empty lines
7
15
  * dropped and the rest joined by a space.
8
16
  */
9
- export declare function text(raw: string): string;
10
- /** An element, rendered with what `scope` names. A lowercase tag is the browser's own. */
17
+ export declare const text: (raw: string) => string;
18
+ /**
19
+ * An element, rendered with what `scope` names. A lowercase tag is the
20
+ * browser's own.
21
+ */
11
22
  export declare function render(node: Element, scope: Scope): ReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabiocv/component-code",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "A React component beside the code that makes it, with every value in the code a control.",
5
5
  "keywords": [
6
6
  "react",
@@ -1,6 +0,0 @@
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};
@@ -1,6 +0,0 @@
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};
@@ -1,6 +0,0 @@
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};
@@ -1,6 +0,0 @@
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};
@@ -1,6 +0,0 @@
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};
@@ -1,6 +0,0 @@
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};