@fabiocv/component-code 0.3.0 → 0.4.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 +8 -0
- package/dist/ComponentCode.d.ts +3 -2
- package/dist/chunk-GQ4OIYAA.js +6 -0
- package/dist/html/ComponentCode.d.ts +3 -2
- package/dist/html.js +3 -3
- package/dist/index.js +5 -5
- package/dist/panel.d.ts +12 -1
- package/package.json +1 -1
- package/dist/chunk-OLVBO6EI.js +0 -6
package/README.md
CHANGED
|
@@ -40,6 +40,10 @@ The component adds its own stylesheet, so there is nothing else to import.
|
|
|
40
40
|
| `onChange` | Called with `{ prop, value, code }` as the reader changes a value. |
|
|
41
41
|
| `children` | The preview, for code that cannot run from its text, such as code with a hook. Use it instead of `scope`. |
|
|
42
42
|
| `file` | The file named in the code's tab. `Code` when left out. |
|
|
43
|
+
| `title` | The preview's tab. `Preview` when left out. |
|
|
44
|
+
| `tabs` | `false` hides the tabs: the preview's and the code's. |
|
|
45
|
+
| `collapsed` | `preview` or `code`: that side starts closed, and dragging the line between them opens it. |
|
|
46
|
+
| `only` | `preview` or `code`: shows that side alone, without the other or the line between them. |
|
|
43
47
|
| `theme` | `light` or `dark`. Without it, the page's `color-scheme` decides. |
|
|
44
48
|
| `note` | A line shown from an info icon beside reset, once the reader changes a value. |
|
|
45
49
|
| `className` | A class for the outer element. |
|
|
@@ -144,6 +148,10 @@ import { ComponentCode } from '@fabiocv/component-code/html';
|
|
|
144
148
|
| `controls` | The values the reader can change, by name. Each takes `true`, a list of options, or `{ min, max, step }`. |
|
|
145
149
|
| `onChange` | Called with `{ file, prop, value, code }` as the reader changes a value. |
|
|
146
150
|
| `theme` | `light` or `dark`. Without it, the page's `color-scheme` decides, and the frame takes the same. |
|
|
151
|
+
| `title` | The preview's tab. `Preview` when left out. |
|
|
152
|
+
| `tabs` | `false` hides the tabs: the preview's and the files'. |
|
|
153
|
+
| `collapsed` | `preview` or `code`: that side starts closed, and dragging the line between them opens it. |
|
|
154
|
+
| `only` | `preview` or `code`: shows that side alone, without the other or the line between them. |
|
|
147
155
|
| `note` | A line shown from an info icon beside reset, once the reader changes a value. |
|
|
148
156
|
| `className` | A class for the outer element. |
|
|
149
157
|
|
package/dist/ComponentCode.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { ControlOptions } from './controls';
|
|
3
|
+
import type { Layout } from './panel';
|
|
3
4
|
import type { Scope } from './run';
|
|
4
5
|
/**
|
|
5
6
|
* The stylesheet, which the component adds itself. Put it in the page's head
|
|
@@ -27,7 +28,7 @@ export type ComponentCodeProps = {
|
|
|
27
28
|
/** A line from an info icon beside reset, once the reader changes a value. */
|
|
28
29
|
note?: string;
|
|
29
30
|
className?: string;
|
|
30
|
-
} & ({
|
|
31
|
+
} & Layout & ({
|
|
31
32
|
/**
|
|
32
33
|
* What the code can name. With it, the preview is the code itself,
|
|
33
34
|
* rendered: elements, props, text, strings, numbers, booleans, lists,
|
|
@@ -54,4 +55,4 @@ export type ComponentCodeProps = {
|
|
|
54
55
|
* rendered from the code, so the two cannot differ, and `interactive` lets
|
|
55
56
|
* the reader change its values in the code.
|
|
56
57
|
*/
|
|
57
|
-
export declare function ComponentCode({ code, file, theme, note, className, scope, interactive, controls: options, onChange, children, }: ComponentCodeProps): import("react").JSX.Element;
|
|
58
|
+
export declare function ComponentCode({ code, file, theme, note, className, scope, interactive, controls: options, onChange, children, ...layout }: ComponentCodeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var H=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(" ")),I=/^(|[(,=:?[{}>&|!]|return)$/;function _(c){let l=[],o=[{in:"code",depth:0}],e=0,a="",r=t=>(t.lastIndex=e,t.exec(c)?.[0]??""),p=(t,n)=>{n&&l.push({ink:t,start:e,end:e+n}),e+=n},d=t=>{let n=e+1;for(;n<c.length&&c[n]!==t;)n+=c[n]==="\\"?2:1;p("string",Math.min(n+1,c.length)-e)};for(;e<c.length;){let t=o[o.length-1],n=c[e];if(t.in==="text"){if(n==="{")e++,o.push({in:"code",depth:0});else if(n==="<")e++,c[e]==="/"?(e++,p("tag",r(/[\w$.:-]*/y).length),e=Math.max(e,c.indexOf(">",e)+1),o.pop()):o.push({in:"tag",named:!1});else{let m=c.slice(e).search(/[<{]/);e=m<0?c.length:e+m}continue}if(t.in==="tag"){let m=r(/[\w$.:-]+/y);m?p(t.named?"attribute":"tag",m.length):n==='"'||n==="'"?d(n):n==="{"?(e++,o.push({in:"code",depth:0})):n===">"?(e++,o[o.length-1]={in:"text"}):c.startsWith("/>",e)?(e+=2,o.pop()):e++,t.named=!0;continue}let i=r(/\s+|\/\/.*|\/\*[\s\S]*?(\*\/|$)/y);if(i){e+=i.length;continue}let s=r(/[A-Za-z_$][\w$]*/y);if(s){let m=c.slice(e+s.length).match(/^\s*(\S)/)?.[1],f=H.has(s)?"keyword":m==="("||/^[A-Z]/.test(s)?"tag":c[e-1]==="."||m===":"&&a!=="?"?"attribute":void 0;f?p(f,s.length):e+=s.length,a=s==="return"?s:"name";continue}let u=r(/\d[\d_]*\.?\d*(e[+-]?\d+)?n?|\.\d+/iy);if(u){p("keyword",u.length),a="name";continue}if(n==='"'||n==="'"||n==="`"){d(n),a="name";continue}if(n==="<"&&I.test(a)&&/[A-Za-z>]/.test(c[e+1]??"")){e++,o.push({in:"tag",named:c[e]===">"}),c[e]===">"&&(e++,o[o.length-1]={in:"text"});continue}if(n==="{"&&t.depth++,n==="}"){if(t.depth===0&&o.length>1){e++,o.pop();continue}t.depth--}a=c.startsWith("&&",e)||c.startsWith("||",e)?"&":n,e++}return l}import{useEffect as T,useInsertionEffect as R,useRef as k,useState as P}from"react";var C=`.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;--split:.5;--seam:min(2px,var(--split)*(100cqw - 4px),(1 - var(--split))*(100cqw - 4px));--edge:calc(2px + var(--split)*(100cqw - 4px - var(--seam)));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)}.cc-split{position:absolute;inset:0 auto;left:calc(var(--edge) + var(--seam)/2 - 5px);display:none;width:14px;translate:max(-8px,min(0px,(1 - var(--split))*(100cqw - 4px - var(--seam)) - 8px));cursor:grab;touch-action:none}.cc-split:active{cursor:grabbing}.cc-split:before,.cc-split:after{content:"";position:absolute;transition:.4s linear(0,.48,1,1.13,1.06,1,.98,1);transition-property:opacity,scale}.cc-split:before{top:calc(50% - 29.315px);left:calc(var(--seam)/2 + 4px);width:9px;height:58.63px;transform-origin:1px;background:var(--cc-surface);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='3 0 9 58.63'%3E%3Cpath d='M3 0H4A6 6 0 0 0 8 5.66A6 6 0 0 1 12 11.31V47.31A6 6 0 0 1 8 52.97A6 6 0 0 0 4 58.63H3Z'/%3E%3C/svg%3E")}.cc-split:after{top:calc(50% - 20px);left:calc(var(--seam)/2 + 5px);width:4px;height:40px;transform-origin:0;border-radius:2px;background:var(--cc-disabled)}.cc-split:not(:hover,:active):before,.cc-split:not(:hover,:active):after{opacity:0;scale:.8}.cc-split:active:before,.cc-split:active:after{scale:1.1}@container (min-width: 640px){.cc-frame{grid-template-columns:calc(var(--split)*(100% - var(--seam))) minmax(0,1fr);column-gap:var(--seam)}.cc-preview{overflow:clip}.cc-code{clip-path:inset(-2px 0 0 -2px)}.cc>.cc-tab{--cut:calc(var(--edge) + var(--seam) - 2px);clip-path:polygon(-1px -1px,calc(var(--cut) + 6px) -1px,calc(var(--cut) + 6px) 0,calc(var(--cut) + 4.45px) .2px,calc(var(--cut) + 3px) .8px,calc(var(--cut) + 1.76px) 1.76px,calc(var(--cut) + .8px) 3px,calc(var(--cut) + .2px) 4.45px,var(--cut) 6px,var(--cut) calc(100% + 6px),-1px calc(100% + 6px))}.cc-split{display:block}.cc[data-only]>.cc-frame{grid-template-columns:minmax(0,1fr)}.cc[data-only]>.cc-tab{clip-path:none}}.cc{--share:.5;--seam-y:2px;--edge-y:var(--rest,0px)}.cc[data-stack]{--seam-y:min(2px,var(--share)*var(--stack),(1 - var(--share))*var(--stack));--edge-y:calc(2px + var(--share)*(var(--stack) - var(--seam-y)))}@container (width < 640px){.cc[data-stack]>.cc-frame{height:calc(var(--stack) + 4px);grid-template-rows:calc(var(--share)*(100% - var(--seam-y))) minmax(0,1fr);row-gap:var(--seam-y)}.cc[data-stack] .cc-preview{min-height:0;overflow:clip}.cc[data-stack] .cc-code{display:flex;flex-direction:column;min-height:0;padding-top:0;clip-path:inset(-2px -2px 0 -2px)}.cc[data-stack] .cc-body{flex-grow:1;min-height:0;margin-top:22px;overflow-y:auto}.cc[data-stack][data-tabs=hidden] .cc-body{margin-top:0}.cc[data-stack]>.cc-tab{clip-path:inset(-1px -7px calc(26px - var(--edge-y) - var(--seam-y)) -1px)}.cc-split{display:block;inset:auto 0;top:calc(var(--edge-y) + var(--seam-y)/2 - 5px);width:auto;height:14px;translate:0 max(-8px,min(0px,(1 - var(--share))*(var(--stack,100vh) - var(--seam-y)) - 8px))}.cc-split:before{top:calc(var(--seam-y)/2 + 4px);left:calc(50% - 29.315px);width:58.63px;height:9px;transform-origin:50% 1px;mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 3 58.63 9'%3E%3Cpath d='M0 3V4A6 6 0 0 1 5.66 8A6 6 0 0 0 11.31 12H47.31A6 6 0 0 0 52.97 8A6 6 0 0 1 58.63 4V3Z'/%3E%3C/svg%3E")}.cc-split:after{top:calc(var(--seam-y)/2 + 5px);left:calc(50% - 20px);width:40px;height:4px;transform-origin:50% 0}}.cc-preview{display:grid;place-items:center;min-width:0;padding:48px 24px 24px}.cc[data-tabs=hidden] .cc-preview{padding-top:24px}.cc[data-tabs=hidden] .cc-code{padding-top:0}.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 X,jsx as h,jsxs as v}from"react/jsx-runtime";var Q=C;function ee(c,l){R(()=>{if(document.getElementById(c))return;let o=document.createElement("style");o.id=c,o.textContent=l,document.head.prepend(o)},[])}function te(c){let l=c.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 w=c=>c.kind==="boolean"||typeof c.value=="number"?"cc-box cc-keyword":c.quote?"cc-box cc-string":"cc-box",S="M8 7.5h7.5v8H8zM12 4.5H4.5v8",L="M5 10.5l3 3 7-7",D="M5 8.5a5.5 5.5 0 1 1 .5 4.5M5 4.5v4h4",q="M16 10a6 6 0 1 1-12 0a6 6 0 0 1 12 0M10 9.5V13m0-6v.01";function z({control:c,onChange:l,written:o}){let{min:e=-1/0,max:a=1/0,step:r}=c,p=c.value,d=k(null),t=a-e<1/0?Math.min(12,Math.max(2,240*r/(a-e))):6,n=()=>d.current=null,i=s=>{s=Math.min(a,Math.max(e,s)),s!==p&&l(s)};return h("span",{className:`${w(c)} cc-scrub`,role:"slider",tabIndex:0,"aria-label":c.prop,"aria-valuenow":p,"aria-valuemin":e>-1/0?e:void 0,"aria-valuemax":a<1/0?a:void 0,onPointerDown:s=>{s.currentTarget.setPointerCapture(s.pointerId),d.current={x:s.clientX,value:p}},onPointerMove:s=>{if(d.current){let u=Math.round((s.clientX-d.current.x)/t);i(d.current.value+u*r)}},onPointerUp:n,onPointerCancel:n,onKeyDown:s=>{let u=s.shiftKey?r*10:r,m={ArrowUp:p+u,ArrowRight:p+u,ArrowDown:p-u,ArrowLeft:p-u,Home:e,End:a}[s.key];m!==void 0&&isFinite(m)&&(s.preventDefault(),i(m))},children:o})}function O({control:c,onChange:l,written:o}){return h("button",{type:"button",className:w(c),"aria-label":c.prop,"aria-pressed":c.value,onClick:()=>l(!c.value),children:o})}function F({control:c,onChange:l}){let o=`${c.value}`,{quote:e}=c;return v("label",{className:w(c),children:[e,h("span",{className:"cc-field","data-value":o,children:h("input",{size:1,value:o,"aria-label":c.prop,spellCheck:!1,onChange:a=>l(a.target.value),onKeyDown:a=>{(a.key==="Enter"||a.key==="Escape")&&a.currentTarget.blur()}})}),e]})}function V({control:c,onChange:l,written:o}){let e=k(null),a=k(null),[r,p]=P(!1),d=n=>{let i=typeof n=="string"?c.quote:"";return i+n+i},t=()=>[...e.current.children];return T(()=>{let n=e.current,i=u=>p(u.newState==="open"),s=()=>n.matches(":popover-open")&&n.hidePopover();return n.addEventListener("toggle",i),addEventListener("scroll",s,!0),()=>{n.removeEventListener("toggle",i),removeEventListener("scroll",s,!0)}},[]),v(X,{children:[h("button",{ref:a,type:"button",className:w(c),"aria-haspopup":"menu","aria-expanded":r,"aria-label":c.prop,onClick:n=>{let i=e.current,{left:s,bottom:u}=n.currentTarget.getBoundingClientRect();i.style.left=`${s}px`,i.style.top=`${u+4}px`,i.showPopover(),i.querySelector("[aria-checked=true]")?.focus()},children:o}),h("div",{ref:e,className:"cc-menu",popover:"auto",role:"menu",onKeyDown:n=>{let i=t(),s=i.indexOf(document.activeElement),{key:u}=n,m=u.length===1&&[...i.slice(s+1),...i].find(g=>g.textContent.replace(/^\W/,"").startsWith(u)),f=m?i.indexOf(m):{ArrowDown:s+1,ArrowUp:s-1,Home:0,End:-1}[u];u==="Escape"&&a.current.focus(),f!==void 0&&(n.preventDefault(),i.at(f%i.length).focus())},children:c.options.map(n=>h("button",{type:"button",role:"menuitemradio","aria-checked":n===c.value,onClick:()=>l(n),children:d(n)},`${n}`))})]})}function j({source:c,tokens:l,controls:o,onChange:e}){let a=[],r=0,p=0,d=t=>{for(;r<t;){for(;p<l.length&&l[p].end<=r;)p++;let n=l[p];if(n&&n.start<=r){let i=Math.min(n.end,t);a.push(h("span",{className:`cc-${n.ink}`,children:c.slice(r,i)},r)),r=i}else{let i=Math.min(n?.start??t,t);a.push(c.slice(r,i)),r=i}}};return o.forEach((t,n)=>{d(t.range.start);let i=c.slice(t.range.start,t.range.end),s={control:t,written:i,onChange:m=>e(t,m)},u={boolean:O,number:z,option:V,text:F}[t.kind];a.push(h(u,{...s},`c${n}`)),r=t.range.end}),d(c.length),v("div",{className:"cc-body",children:[h("div",{className:"cc-lines","aria-hidden":!0,children:c.split(`
|
|
5
|
+
`).map((t,n)=>n+1).join(`
|
|
6
|
+
`)}),h("div",{className:"cc-scroll",children:h("code",{children:a})})]})}function y({slot:c,label:l,d:o,hidden:e,onClick:a}){return h("span",{className:`cc-slot${c}`,children:h("button",{type:"button",className:"cc-action","aria-label":l,tabIndex:e?-1:0,onClick:a,children:h("svg",{width:"20",height:"20",viewBox:"0 0 20 20","aria-hidden":!0,children:h("path",{d:o})})})})}function W({source:c,changed:l,note:o,onReset:e}){let[a,r]=P(!1);return v("div",{className:`cc-tab cc-actions${l?" cc-changed":""}`,children:[o&&h(y,{slot:" cc-note",label:o,d:q,hidden:!l}),h(y,{slot:" cc-reset",label:"Reset code",d:D,hidden:!l,onClick:e}),h(y,{slot:"",label:a?"Copied":"Copy code",d:a?L:S,onClick:()=>navigator.clipboard.writeText(c).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})})]})}var B=(2*Math.PI/.35)**2,K=4*Math.PI/.35;function N(c,l,o,e){let a={min:o,closed:e===void 0?0:e*2-1,to:e??.5,home:.5,off:0,speed:0,track:1,show(){c.style.setProperty(l,`${Math.min(1,Math.max(0,a.to+a.off))}`)},jump(t){a.off=matchMedia("(prefers-reduced-motion: reduce)").matches?0:a.off+a.to-t,a.to=t,p||(r=performance.now(),p=requestAnimationFrame(d))},ease(t){let n=o-t;return n<=0?t:n>o/2?0:o-o/4*(1-Math.exp(-4*n/o))},stop:()=>cancelAnimationFrame(p)},r=0,p=0,d=t=>{let n=Math.min(.05,(t-r)/1e3);r=t;for(let i=0;i<n;i+=.001)a.speed-=(B*a.off+K*a.speed)*.001,a.off+=a.speed*.001;Math.abs(a.off)*a.track<.5?a.off=a.speed=p=0:p=requestAnimationFrame(d),a.show()};return a}function Z({start:c}){let l=k(null);return T(()=>{let o=l.current,e=o.parentElement,a=e.firstElementChild,r=a.firstElementChild,p=N(e,"--split",160,c),d=N(e,"--share",80),t=p,n,i=()=>t=e.clientWidth<640?d:p,s=f=>t===d?f.clientY:f.clientX,u=globalThis.ResizeObserver&&new ResizeObserver(()=>e.style.setProperty("--rest",`${r.offsetTop+r.offsetHeight}px`));u?.observe(r),o.onpointerdown=f=>{if(!f.button){if(f.preventDefault(),o.setPointerCapture(f.pointerId),i()===d){if(!("stack"in e.dataset)){let g=a.clientHeight-4;d.to=d.home=r.offsetHeight/(g-2),d.show(),e.style.setProperty("--stack",`${g}px`),e.dataset.stack=""}d.track=a.clientHeight-6}else p.track=a.clientWidth-6;n=s(f)-t.to*t.track}},o.onpointermove=f=>{if(n===void 0)return;if(!(f.buttons&1))return m();let{track:g}=t,x=s(f)-n;if(t.closed){let E=t.closed<0?Math.min(x,0):Math.max(x-g,0);if(n+=E,x-=E,(t.closed<0?x:g-x)<t.min){t.to=x/g,t.show();return}t.closed=0}let b=t.ease(x),M=t.ease(g-x);t.closed=b?M?0:1:-1,t.closed?(t.jump(t.closed<0?0:1),n=s(f)-t.to*g):t.to=(b===x?g-M:b)/g,t.show()};let m=()=>{if(n===void 0)return;n=void 0;let{min:f,track:g}=t,x=t.to*g,b=Math.min(x,g-x);t.closed&&b<f/2?t.jump(t.closed<0?0:1):b<f&&(t.closed=0,t.jump((x<f?f:g-f)/g))};return o.onpointerup=o.onpointercancel=o.onlostpointercapture=m,o.ondblclick=()=>{i()===d&&!("stack"in e.dataset)||(t.closed=0,t.jump(t.home))},()=>{p.stop(),d.stop(),u?.disconnect()}},[]),h("div",{ref:l,className:"cc-split","aria-hidden":!0})}function ce({className:c,theme:l,title:o="Preview",tabs:e=!0,collapsed:a,only:r,preview:p,tab:d,source:t,changed:n,note:i,onReset:s,...u}){let m=r||!a?void 0:+(a==="code");return v("div",{className:c?`cc ${c}`:"cc","data-theme":l,"data-tabs":e?void 0:"hidden","data-only":r,style:m===void 0?void 0:{"--split":m},children:[v("div",{className:"cc-frame",children:[r!=="code"&&h("div",{className:"cc-preview",children:p}),r!=="preview"&&v("div",{className:"cc-code","data-note":i,children:[e&&d,h(W,{source:t,changed:n,note:i,onReset:s}),h(j,{source:t,...u})]})]}),e&&r!=="code"&&h("div",{className:"cc-tab",children:o}),!r&&h(Z,{start:m})]})}var A=c=>`${c}`.split(".")[1]?.length??0,oe=c=>10**-A(c),re=(c,l)=>`${+c.toFixed(A(l))}`;export{oe as a,re as b,_ as c,Q as d,ee as e,te as f,ce as g};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Controls } from './languages';
|
|
2
|
+
import type { Layout } from '../panel';
|
|
2
3
|
export type { ControlOptions } from './languages';
|
|
3
4
|
/**
|
|
4
5
|
* The stylesheet, which the component adds itself. Put it in the page's head
|
|
@@ -33,9 +34,9 @@ export type ComponentCodeProps = {
|
|
|
33
34
|
/** A line from an info icon beside reset, once the reader changes a value. */
|
|
34
35
|
note?: string;
|
|
35
36
|
className?: string;
|
|
36
|
-
};
|
|
37
|
+
} & Layout;
|
|
37
38
|
/**
|
|
38
39
|
* HTML, CSS and JS running beside their code, a tab for each file. The values
|
|
39
40
|
* named in `controls` are controls the reader can change.
|
|
40
41
|
*/
|
|
41
|
-
export declare function ComponentCode({ files, controls: options, onChange, theme, note, className, }: ComponentCodeProps): import("react").JSX.Element;
|
|
42
|
+
export declare function ComponentCode({ files, controls: options, onChange, theme, note, className, ...layout }: ComponentCodeProps): import("react").JSX.Element;
|
package/dist/html.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{a as
|
|
3
|
-
`,"\\n")+
|
|
4
|
-
`);function
|
|
2
|
+
import{a as A,b as O,c as T,d as j,e as M,f as I,g as S}from"./chunk-GQ4OIYAA.js";import{useEffect as E,useMemo as te,useRef as B,useState as L}from"react";function D(){let n=document.documentElement,r=document.currentScript.previousElementSibling,e=t=>parent.postMessage(t,"*");addEventListener("message",t=>{t.source===parent&&(r.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 N=(n,r)=>n.replace(new RegExp(`</${r}`,"gi"),`<\\/${r}`);function W(n,r,e,t){return`<!doctype html><html><head><meta charset="utf-8"><style>:root{${t}}body{margin:0}</style><style>${N(r,"style")}</style><script>(${D})()<\/script></head><body>${n}<script>${N(e,"script")}<\/script></body></html>`}function P(n,r){let e,t,c,s,l="",f=p=>p?.contentWindow?.postMessage({css:l},"*"),o=({source:p,data:a})=>{let d=[e,t].find(i=>i&&i.contentWindow===p);if(!(!d||typeof a!="object"||!a)&&(a.height!==void 0&&(d.style.height=`${Math.ceil(a.height)}px`),a.problem&&(d===e?r(a.problem):s??=a.problem),a.ready&&d===t)){e?.remove(),e=d,t=void 0,d.dataset.shown="",f(d),r(s),s=void 0;let i=c;c=void 0,i?.()}};return addEventListener("message",o),{run(p,a,d){let i=()=>{t=document.createElement("iframe"),t.setAttribute("sandbox","allow-scripts"),t.title="Preview",e&&(t.style.height=e.style.height),t.srcdoc=W(p,l,a,d),n.append(t)};t?c=i:i()},css(p){l=p,f(e),f(t)},stop(){removeEventListener("message",o),e?.remove(),t?.remove()}}}var z=/^-?(?:\d+\.?\d*|\.\d+)$/,v=n=>/\.css$/i.test(n)?"css":/\.m?js$/i.test(n)?"js":"html";function w(n,r,e,t,c,s=""){let l=Array.isArray(r);return{prop:n,kind:l?"option":typeof e=="string"?"text":typeof e,value:e,range:{start:t,end:c},quote:s,jsx:!1,step:typeof e=="number"?A(e):1,...l?{options:r}:r===!0?{}:r}}var H=n=>(r,e,t)=>{t&&n.push({ink:r,start:e,end:e+t})},Z=/<!--[\s\S]*?(?:-->|$)|<[!/]?([A-Za-z][\w:-]*)([^>]*)>?/g,G=/([^\s"'=<>/]+)(?:\s*=\s*("[^"]*"?|'[^']*'?|[^\s>]+))?/g;function J(n,r){let e=[],t=[],c=H(e),s=new RegExp(Z),l;for(;l=s.exec(n);){let[f,o,p]=l;if(!o)continue;let a=l.index+f.indexOf(o);c("tag",a,o.length);let d=o.toLowerCase();for(let i of p.matchAll(G)){let[,g,m]=i,u=a+o.length+i.index;if(c("attribute",u,g.length),!m)continue;let y=u+i[0].length-m.length;c("string",y,m.length);let b=r[`${d}.${g}`]??r[g];if(!b)continue;let C=/^["']/.test(m)?m[0]:"",h=C?m.slice(1,-1):m;t.push(w(g,b,z.test(h)?+h:h,y,y+m.length,C))}if(f[1]!=="/"&&(d==="script"||d==="style")){let i=n.indexOf(`</${d}`,s.lastIndex);s.lastIndex=i<0?n.length:i}}return{tokens:e,controls:t}}var _=/(["'])(?:\\.|(?!\1)[^\\])*\1?|#[\da-f]{3,8}\b|(?<![\w-])-?(?:\d+\.?\d*|\.\d+)(?:[a-z]+|%)?|!important/gi;function K(n,r){let e=[],t=[],c=H(e),s=0;for(;s<n.length;){let l=/\s+|\/\*[\s\S]*?(?:\*\/|$)/y;l.lastIndex=s;let f=l.exec(n)?.[0].length;if(f){s+=f;continue}let o=s,p=0;for(;o<n.length;){let i=n[o];if(i==='"'||i==="'"){let g=n.indexOf(i,o+1);o=g<0?n.length:g+1;continue}if(i==="(")p++;else if(i===")")p--;else if(p<=0&&/[{};]/.test(i))break;o++}let a=n.slice(s,o).trimEnd(),d=a.indexOf(":");if(a[0]==="@")c("keyword",s,a.match(/^@[\w-]*/)[0].length);else if(n[o]==="{")c("tag",s,a.length);else if(d>0){let i=a.slice(0,d).trim();c("attribute",s,i.length);let g=a.slice(d+1).search(/\S/),m=s+d+1+g,u=g<0?"":a.slice(d+1+g);for(let C of u.matchAll(_))c(C[1]?"string":"keyword",m+C.index,C[0].length);let y=r[i],b=u.match(/^(-?(?:\d+\.?\d*|\.\d+))([a-z]*|%)$/i);y&&u&&t.push(b&&(!Array.isArray(y)||!b[2])?w(i,y,+b[1],m,m+b[1].length):w(i,y,u,m,m+u.length))}s=o+1}return{tokens:e,controls:t}}var Q=/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(-?(?:\d+\.?\d*|\.\d+)|true|false|(["'])(?:\\.|(?!\3)[^\\\n])*\3)(?=[ \t]*(?:[;,\n]|$))/g;function X(n,r){let e=[];for(let t of n.matchAll(Q)){let[c,s,l,f=""]=t,o=r[s];if(!o)continue;let p=t.index+c.length-l.length,a=f?l.slice(1,-1).replace(/\\(.)/g,"$1"):z.test(l)?+l:l==="true";e.push(w(s,o,a,p,p+l.length,f))}return{tokens:T(n),controls:e}}var V={html:J,css:K,js:X};function Y(n,r,e){let t=typeof e=="number"?O(e,r.step):`${e}`;if(n==="css")return t.replace(/[;{}<]/g,"");let{quote:c}=r;if(n==="html"){let l=t.replaceAll("&","&").replaceAll("<","<");return c?c+l.replaceAll(c,c==='"'?""":"'")+c:l}if(typeof e!="string")return t;let s=c||"'";return s+t.replaceAll("\\","\\\\").replaceAll(s,`\\${s}`).replaceAll(`
|
|
3
|
+
`,"\\n")+s}function q(n,r,e,t){let{start:c,end:s}=e.range;return r.slice(0,c)+Y(n,e,t)+r.slice(s)}var F=".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 re,jsx as x,jsxs as se}from"react/jsx-runtime";var U=j+F,$=(n,r)=>Object.keys(n).filter(e=>v(e)===r).map(e=>n[e]).join(`
|
|
4
|
+
`);function ne({html:n,css:r,js:e,theme:t}){let c=B(null),s=B(null),[l,f]=L();return E(()=>{let o=P(c.current,f);return s.current=o,o.stop},[]),E(()=>s.current.css(r),[r]),E(()=>{let o=matchMedia("(prefers-color-scheme: dark)"),p=()=>{let{colorScheme:a,color:d,fontFamily:i}=getComputedStyle(c.current),g=a.includes("dark")&&(!a.includes("light")||o.matches);s.current.run(n,e,`color-scheme:${g?"dark":"light"};color:${d};font-family:${i}`)};return p(),o.addEventListener("change",p),()=>o.removeEventListener("change",p)},[n,e,t]),se(re,{children:[l&&x("p",{className:"cc-problem",children:l}),x("div",{ref:c,className:"cc-run",hidden:!!l})]})}function oe({files:n,controls:r={},onChange:e,theme:t,note:c,className:s,...l}){M("component-code-html",U);let f=JSON.stringify(n),o=te(()=>Object.fromEntries(Object.entries(n).map(([h,k])=>[h,I(k)])),[f]),p=Object.keys(o),[a,d]=L(p[0]),i=p.includes(a)?a:p[0],[g,m]=L({from:o,to:o});g.from!==o&&m({from:o,to:o});let u=g.from===o?g.to:o,y=v(i),{tokens:b,controls:C}=V[y](u[i],r);return x(S,{className:s,theme:t,...l,preview:x(ne,{html:$(u,"html"),css:$(u,"css"),js:$(u,"js"),theme:t}),tab:x("div",{className:"cc-tab cc-files",role:"tablist",children:p.map(h=>x("button",{type:"button",role:"tab","aria-selected":h===i,onClick:()=>d(h),children:h},h))}),source:u[i],changed:p.some(h=>u[h]!==o[h]),note:c,onReset:()=>m({from:o,to:o}),tokens:b,controls:C,onChange:(h,k)=>{let R=q(y,u[i],h,k);m({from:o,to:{...u,[i]:R}}),e?.({file:i,prop:h.prop,value:k,code:R})}})}export{oe as ComponentCode,U as styles};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{a as
|
|
3
|
-
`,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0"}[n]??n);function A(t){let e=0,n=o=>{throw new
|
|
4
|
-
`)[0],r=o=>{o.lastIndex=e;let
|
|
5
|
-
`)||n.push({prop:
|
|
6
|
-
`)){let
|
|
2
|
+
import{a as B,b as O,c as V,d as q,e as P,f as L,g as I}from"./chunk-GQ4OIYAA.js";import{Component as ee,createElement as te,Fragment as ne,useMemo as D,useState as re}from"react";var E=class extends Error{},M=/[A-Za-z_$][\w$-]*/y,X=/-?(?:\d[\d_]*\.?\d*|\.\d+)(?:e[+-]?\d+)?/iy,Z={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:"\xA0"},R=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)):Z[n]??e),G=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 E(o)},l=()=>t.slice(e,e+12).split(`
|
|
4
|
+
`)[0],r=o=>{o.lastIndex=e;let s=o.exec(t)?.[0];return s&&(e+=s.length),s},p=()=>{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=>(p(),t.startsWith(o,e)),i=o=>{a(o)||n(`Expected \`${o}\` at \`${l()}\`.`),e+=o.length};function m(){let s=[r(M)??n(`Expected a name at \`${l()}\`.`)];for(;t[e]===".";)e++,s.push(r(M)??n("Expected a name after `.`."));return s}function d(o,s=!1){let b=t[e],u=e+1;for(;u<t.length&&t[u]!==b;)t[u]==="\\"&&!s&&u++,u++;u>=t.length&&n("A string is not closed.");let g=t.slice(e+1,u);return b==="`"&&g.includes("${")&&n("A template string cannot run here."),e=u+1,{type:"string",value:s?R(g):G(g),quote:b,jsx:s,start:o,end:e}}function y(){p();let o=e,s=t[e];if(s==='"'||s==="'"||s==="`")return d(o);if(s==="<")return h();if(s==="("){e++;let c=y();return i(")"),c}if(s==="["){e++;let c=[];for(;!a("]");)c.push(y()),a("]")||i(",");return e++,{type:"array",items:c,start:o,end:e}}if(s==="{"){e++;let c=[];for(;!a("}");){let w=e,C=t[e]==='"'||t[e]==="'"?d(e).value:m()[0],x={type:"name",path:[C],start:w,end:e};c.push([C,a(":")?(e++,y()):x]),a("}")||i(",")}return e++,{type:"object",entries:c,start:o,end:e}}let b=r(X);if(b)return{type:"number",value:+b.replace(/_/g,""),start:o,end:e};let u=m(),g=e;if(u.length===1){let c=u[0];if(c==="true"||c==="false")return{type:"boolean",value:c==="true",start:o,end:g};if(c==="null"||c==="undefined")return{type:c,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 h(){let o=e;i("<");let s=a(">")?"":m().join("."),b=[];for(;;){if(a("/>"))return e+=2,{type:"element",name:s,attributes:b,children:[],start:o,end:e};if(a(">"))break;let g=e;if(a("{")){e++,i("...");let C=y();i("}"),b.push({name:"",value:C,spread:!0,start:g,end:e});continue}let c=r(/[\w$:-]+/y)??n(`Expected a prop at \`${l()}\`.`),w=e,f=null;a("=")&&(e++,p(),t[e]==="{"?(e++,f=y(),i("}")):t[e]==='"'||t[e]==="'"?f=d(e,!0):f=y()),b.push({name:c,value:f,start:g,end:f?e:w})}e++;let u=[];for(;;){e>=t.length&&n(`\`<${s}>\` is not closed.`);let g=e;if(t.startsWith("</",e)){e+=2,p();let c=t[e]===">"?"":m().join(".");return c!==s&&n(`\`</${c}>\` does not close \`<${s}>\`.`),i(">"),{type:"element",name:s,attributes:b,children:u,start:o,end:e}}t[e]==="<"?u.push(h()):t[e]==="{"?(e++,a("}")||u.push(y()),i("}")):(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 v=[];for(;!a(";")&&e<t.length;){t[e]!=="<"&&t[e]!=="("&&n(`Expected an element at \`${l()}\`.`);let o=y();o.type!=="element"&&n("Expected an element."),v.push(o)}return v}function F(t,e={}){let n=[],l=(p,a,i)=>{let m=e[`${p}.${a}`]??e[a],{value:d}=i,y=i.type==="string"?i.quote:"";m===!1||y==="`"||`${d}`.includes(`
|
|
5
|
+
`)||n.push({prop:a,kind:Array.isArray(m)?"option":i.type==="string"?"text":i.type,value:d,range:{start:i.start,end:i.end},quote:y,jsx:i.type==="string"&&(!y||!!i.jsx),step:typeof d=="number"?B(d):1,...Array.isArray(m)?{options:m}:m})},r=p=>{for(let{name:m,value:d}of p.attributes)d?.type==="element"?r(d):(d?.type==="string"||d?.type==="number"||d?.type==="boolean")&&l(p.name,m,d);let[a]=p.children,i=a?.type==="text"?a.raw.trim():"";if(p.children.length===1&&i&&!i.includes(`
|
|
6
|
+
`)){let m=a.start+a.raw.indexOf(i);l(p.name,"children",{type:"string",value:R(i),quote:"",start:m,end:m+i.length})}for(let m of p.children)m.type==="element"&&r(m)};return t.forEach(r),n}function H(t,e){let{quote:n}=t;if(typeof e!="string"){let r=typeof e=="number"?O(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 l=e.replaceAll("&","&").replaceAll("<","<");return n?n+l.replaceAll(n,n==='"'?""":"'")+n:l.replaceAll(">",">").replaceAll("{","{").replaceAll("}","}")}function W(t,e,n){let{start:l,end:r}=e.range;return t.slice(0,l)+H(e,n)+t.slice(r)}function _(t){let e=[],n=l=>{for(let r of l.attributes)!r.value&&!r.spread?e.push(r.end):r.value?.type==="element"&&n(r.value);for(let r of l.children)r.type==="element"&&n(r)};return A(t).forEach(n),e.reverse().reduce((l,r)=>l.slice(0,r)+"={true}"+l.slice(r),t)}import{createElement as J,Fragment as K}from"react";var k=Symbol(),Q=t=>R(t.split(/\s*\n\s*/).filter(Boolean).join(" "));function z(t,e){let[n,...l]=t;if(!Object.hasOwn(e,n))throw new E(`\`${n}\` is not in \`scope\`.`);let r=e[n];for(let p of l)r=r?.[p];if(r===void 0)throw new E(`\`${t.join(".")}\` is not in \`scope\`.`);return r}function S(t,e){switch(t.type){case"element":return N(t,e);case"name":return z(t.path,e);case"array":return t.items.map(n=>S(n,e));case"object":return Object.fromEntries(t.entries.map(([n,l])=>[n,S(l,e)]));case"null":return null;case"undefined":return;default:return t.value}}function Y(t,e){return t.type==="text"?Q(t.raw)||null:S(t,e)}function N(t,e){let n=t.name?/^[a-z][^.]*$/.test(t.name)?t.name:z(t.name.split("."),e):K,l={},r=e[k];for(let p of t.attributes){let a=typeof n!="string"&&r?.get(p.value?.start);if(a){let{name:i}=p;l[`on${i[0].toUpperCase()}${i.slice(1)}Change`]=a}p.spread?Object.assign(l,S(p.value,e)):l[p.name]=p.value?S(p.value,e):!0}return J(n,l,...t.children.map(p=>Y(p,e)))}import{jsx as $}from"react/jsx-runtime";var U=q,j=class extends ee{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?$("p",{className:"cc-problem",children:e}):this.props.children}};function oe({code:t,file:e="Code",theme:n,note:l,className:r,scope:p,interactive:a,controls:i,onChange:m,children:d,...y}){P("component-code",U);let h=D(()=>{let f=L(t);try{return a?_(f):f}catch{return f}},[t,a]),[v,o]=re({from:h,to:h});v.from!==h&&o({from:h,to:h});let s=v.from===h?v.to:h,b=D(()=>V(s),[s]),u=(f,C)=>{let x=W(s,f,C);o({from:h,to:x}),m?.({prop:f.prop,value:C,code:x})},g=d,c,w=[];if(p)try{let f=A(s);a&&(w=F(f,i));let C={...p,[k]:new Map(w.map(x=>[x.range.start,T=>typeof T==typeof x.value&&u(x,T)]))};g=te(ne,null,...f.map(x=>N(x,C)))}catch(f){if(!(f instanceof E))throw f;c=f.message}return $(I,{className:r,theme:n,...y,preview:c?$("p",{className:"cc-problem",children:c}):$(j,{source:s,children:g}),tab:$("div",{className:"cc-tab",children:e}),source:s,changed:s!==h,note:l,onReset:()=>o({from:h,to:h}),tokens:b,controls:w,onChange:u})}export{oe as ComponentCode,U as styles};
|
package/dist/panel.d.ts
CHANGED
|
@@ -8,8 +8,19 @@ export type Value = string | number | boolean;
|
|
|
8
8
|
export declare function useStyles(id: string, css: string): void;
|
|
9
9
|
/** Code without the blank lines around it or the indent its lines share. */
|
|
10
10
|
export declare function dedent(code: string): string;
|
|
11
|
+
/** How the panel is laid out, which both entries take as props. */
|
|
12
|
+
export type Layout = {
|
|
13
|
+
/** The preview's tab. `Preview` when left out. */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** `false` hides the tabs: the preview's and the code's. */
|
|
16
|
+
tabs?: boolean;
|
|
17
|
+
/** The side that starts closed, which the line between them opens. */
|
|
18
|
+
collapsed?: 'preview' | 'code';
|
|
19
|
+
/** The one side shown, without the other or the line between them. */
|
|
20
|
+
only?: 'preview' | 'code';
|
|
21
|
+
};
|
|
11
22
|
/** The preview beside the code, with the code's tab, copy and reset. */
|
|
12
|
-
export declare function Panel({ className, theme, preview, tab, source, changed, note, onReset, ...code }: {
|
|
23
|
+
export declare function Panel({ className, theme, title, tabs, collapsed, only, preview, tab, source, changed, note, onReset, ...code }: Layout & {
|
|
13
24
|
className?: string;
|
|
14
25
|
theme?: 'light' | 'dark';
|
|
15
26
|
preview: ReactNode;
|
package/package.json
CHANGED
package/dist/chunk-OLVBO6EI.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
var D=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(" ")),H=/^(|[(,=:?[{}>&|!]|return)$/;function J(e){let r=[],a=[{in:"code",depth:0}],t=0,o="",s=c=>(c.lastIndex=t,c.exec(e)?.[0]??""),d=(c,n)=>{n&&r.push({ink:c,start:t,end:t+n}),t+=n},p=c=>{let n=t+1;for(;n<e.length&&e[n]!==c;)n+=e[n]==="\\"?2:1;d("string",Math.min(n+1,e.length)-t)};for(;t<e.length;){let c=a[a.length-1],n=e[t];if(c.in==="text"){if(n==="{")t++,a.push({in:"code",depth:0});else if(n==="<")t++,e[t]==="/"?(t++,d("tag",s(/[\w$.:-]*/y).length),t=Math.max(t,e.indexOf(">",t)+1),a.pop()):a.push({in:"tag",named:!1});else{let m=e.slice(t).search(/[<{]/);t=m<0?e.length:t+m}continue}if(c.in==="tag"){let m=s(/[\w$.:-]+/y);m?d(c.named?"attribute":"tag",m.length):n==='"'||n==="'"?p(n):n==="{"?(t++,a.push({in:"code",depth:0})):n===">"?(t++,a[a.length-1]={in:"text"}):e.startsWith("/>",t)?(t+=2,a.pop()):t++,c.named=!0;continue}let l=s(/\s+|\/\/.*|\/\*[\s\S]*?(\*\/|$)/y);if(l){t+=l.length;continue}let i=s(/[A-Za-z_$][\w$]*/y);if(i){let m=e.slice(t+i.length).match(/^\s*(\S)/)?.[1],x=D.has(i)?"keyword":m==="("||/^[A-Z]/.test(i)?"tag":e[t-1]==="."||m===":"&&o!=="?"?"attribute":void 0;x?d(x,i.length):t+=i.length,o=i==="return"?i:"name";continue}let h=s(/\d[\d_]*\.?\d*(e[+-]?\d+)?n?|\.\d+/iy);if(h){d("keyword",h.length),o="name";continue}if(n==='"'||n==="'"||n==="`"){p(n),o="name";continue}if(n==="<"&&H.test(o)&&/[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(n==="{"&&c.depth++,n==="}"){if(c.depth===0&&a.length>1){t++,a.pop();continue}c.depth--}o=e.startsWith("&&",t)||e.startsWith("||",t)?"&":n,t++}return r}import{useEffect as S,useInsertionEffect as L,useRef as y,useState as $}from"react";var P=`.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;--split:.5;--seam:min(2px,var(--split)*(100cqw - 4px),(1 - var(--split))*(100cqw - 4px));--edge:calc(2px + var(--split)*(100cqw - 4px - var(--seam)));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)}.cc-split{position:absolute;inset:0 auto;left:calc(var(--edge) + var(--seam)/2 - 5px);display:none;width:14px;translate:max(-8px,min(0px,(1 - var(--split))*(100cqw - 4px - var(--seam)) - 8px));cursor:grab;touch-action:none}.cc-split:active{cursor:grabbing}.cc-split:before,.cc-split:after{content:"";position:absolute;transition:.4s linear(0,.48,1,1.13,1.06,1,.98,1);transition-property:opacity,scale}.cc-split:before{top:calc(50% - 29.315px);left:calc(var(--seam)/2 + 4px);width:9px;height:58.63px;transform-origin:1px;background:var(--cc-surface);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='3 0 9 58.63'%3E%3Cpath d='M3 0H4A6 6 0 0 0 8 5.66A6 6 0 0 1 12 11.31V47.31A6 6 0 0 1 8 52.97A6 6 0 0 0 4 58.63H3Z'/%3E%3C/svg%3E")}.cc-split:after{top:calc(50% - 20px);left:calc(var(--seam)/2 + 5px);width:4px;height:40px;transform-origin:0;border-radius:2px;background:var(--cc-disabled)}.cc-split:not(:hover,:active):before,.cc-split:not(:hover,:active):after{opacity:0;scale:.8}.cc-split:active:before,.cc-split:active:after{scale:1.1}@container (min-width: 640px){.cc-frame{grid-template-columns:calc(var(--split)*(100% - var(--seam))) minmax(0,1fr);column-gap:var(--seam)}.cc-preview{overflow:clip}.cc-code{clip-path:inset(-2px 0 0 -2px)}.cc>.cc-tab{--cut:calc(var(--edge) + var(--seam) - 2px);clip-path:polygon(-1px -1px,calc(var(--cut) + 6px) -1px,calc(var(--cut) + 6px) 0,calc(var(--cut) + 4.45px) .2px,calc(var(--cut) + 3px) .8px,calc(var(--cut) + 1.76px) 1.76px,calc(var(--cut) + .8px) 3px,calc(var(--cut) + .2px) 4.45px,var(--cut) 6px,var(--cut) calc(100% + 6px),-1px calc(100% + 6px))}.cc-split{display:block}}.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 Y,jsx as u,jsxs as b}from"react/jsx-runtime";var ce=P;function oe(e,r){L(()=>{if(document.getElementById(e))return;let a=document.createElement("style");a.id=e,a.textContent=r,document.head.prepend(a)},[])}function ae(e){let r=e.replace(/^\s*\n/,"").trimEnd().split(`
|
|
3
|
-
`),a=Math.min(...r.filter(t=>t.trim()).map(t=>t.search(/\S/)));return r.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",F="M8 7.5h7.5v8H8zM12 4.5H4.5v8",O="M5 10.5l3 3 7-7",z="M5 8.5a5.5 5.5 0 1 1 .5 4.5M5 4.5v4h4",V="M16 10a6 6 0 1 1-12 0a6 6 0 0 1 12 0M10 9.5V13m0-6v.01";function W({control:e,onChange:r,written:a}){let{min:t=-1/0,max:o=1/0,step:s}=e,d=e.value,p=y(null),c=o-t<1/0?Math.min(12,Math.max(2,240*s/(o-t))):6,n=()=>p.current=null,l=i=>{i=Math.min(o,Math.max(t,i)),i!==d&&r(i)};return u("span",{className:`${M(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),p.current={x:i.clientX,value:d}},onPointerMove:i=>{if(p.current){let h=Math.round((i.clientX-p.current.x)/c);l(p.current.value+h*s)}},onPointerUp:n,onPointerCancel:n,onKeyDown:i=>{let h=i.shiftKey?s*10:s,m={ArrowUp:d+h,ArrowRight:d+h,ArrowDown:d-h,ArrowLeft:d-h,Home:t,End:o}[i.key];m!==void 0&&isFinite(m)&&(i.preventDefault(),l(m))},children:a})}function B({control:e,onChange:r,written:a}){return u("button",{type:"button",className:M(e),"aria-label":e.prop,"aria-pressed":e.value,onClick:()=>r(!e.value),children:a})}function K({control:e,onChange:r}){let a=`${e.value}`,{quote:t}=e;return b("label",{className:M(e),children:[t,u("span",{className:"cc-field","data-value":a,children:u("input",{size:1,value:a,"aria-label":e.prop,spellCheck:!1,onChange:o=>r(o.target.value),onKeyDown:o=>{(o.key==="Enter"||o.key==="Escape")&&o.currentTarget.blur()}})}),t]})}function X({control:e,onChange:r,written:a}){let t=y(null),o=y(null),[s,d]=$(!1),p=n=>{let l=typeof n=="string"?e.quote:"";return l+n+l},c=()=>[...t.current.children];return S(()=>{let n=t.current,l=h=>d(h.newState==="open"),i=()=>n.matches(":popover-open")&&n.hidePopover();return n.addEventListener("toggle",l),addEventListener("scroll",i,!0),()=>{n.removeEventListener("toggle",l),removeEventListener("scroll",i,!0)}},[]),b(Y,{children:[u("button",{ref:o,type:"button",className:M(e),"aria-haspopup":"menu","aria-expanded":s,"aria-label":e.prop,onClick:n=>{let l=t.current,{left:i,bottom:h}=n.currentTarget.getBoundingClientRect();l.style.left=`${i}px`,l.style.top=`${h+4}px`,l.showPopover(),l.querySelector("[aria-checked=true]")?.focus()},children:a}),u("div",{ref:t,className:"cc-menu",popover:"auto",role:"menu",onKeyDown:n=>{let l=c(),i=l.indexOf(document.activeElement),{key:h}=n,m=h.length===1&&[...l.slice(i+1),...l].find(w=>w.textContent.replace(/^\W/,"").startsWith(h)),x=m?l.indexOf(m):{ArrowDown:i+1,ArrowUp:i-1,Home:0,End:-1}[h];h==="Escape"&&o.current.focus(),x!==void 0&&(n.preventDefault(),l.at(x%l.length).focus())},children:e.options.map(n=>u("button",{type:"button",role:"menuitemradio","aria-checked":n===e.value,onClick:()=>r(n),children:p(n)},`${n}`))})]})}function j({source:e,tokens:r,controls:a,onChange:t}){let o=[],s=0,d=0,p=c=>{for(;s<c;){for(;d<r.length&&r[d].end<=s;)d++;let n=r[d];if(n&&n.start<=s){let l=Math.min(n.end,c);o.push(u("span",{className:`cc-${n.ink}`,children:e.slice(s,l)},s)),s=l}else{let l=Math.min(n?.start??c,c);o.push(e.slice(s,l)),s=l}}};return a.forEach((c,n)=>{p(c.range.start);let l=e.slice(c.range.start,c.range.end),i={control:c,written:l,onChange:m=>t(c,m)},h={boolean:B,number:W,option:X,text:K}[c.kind];o.push(u(h,{...i},`c${n}`)),s=c.range.end}),p(e.length),b("div",{className:"cc-body",children:[u("div",{className:"cc-lines","aria-hidden":!0,children:e.split(`
|
|
5
|
-
`).map((c,n)=>n+1).join(`
|
|
6
|
-
`)}),u("div",{className:"cc-scroll",children:u("code",{children:o})})]})}function C({slot:e,label:r,d:a,hidden:t,onClick:o}){return u("span",{className:`cc-slot${e}`,children:u("button",{type:"button",className:"cc-action","aria-label":r,tabIndex:t?-1:0,onClick:o,children:u("svg",{width:"20",height:"20",viewBox:"0 0 20 20","aria-hidden":!0,children:u("path",{d:a})})})})}function G({source:e,changed:r,note:a,onReset:t}){let[o,s]=$(!1);return b("div",{className:`cc-tab cc-actions${r?" cc-changed":""}`,children:[a&&u(C,{slot:" cc-note",label:a,d:V,hidden:!r}),u(C,{slot:" cc-reset",label:"Reset code",d:z,hidden:!r,onClick:t}),u(C,{slot:"",label:o?"Copied":"Copy code",d:o?O:F,onClick:()=>navigator.clipboard.writeText(e).then(()=>{s(!0),setTimeout(()=>s(!1),1500)})})]})}var v=160,T=40,A=80,Z=(2*Math.PI/.35)**2,_=4*Math.PI/.35;function U(){let e=y(null);return S(()=>{let r=e.current,a=r.parentElement,t=a.firstElementChild,o=.5,s=0,d=0,p=1,c=0,n,l=0,i=0,h=()=>a.style.setProperty("--split",`${Math.min(1,Math.max(0,o+s))}`),m=f=>{let g=Math.min(.05,(f-l)/1e3);l=f;for(let k=0;k<g;k+=.001)d-=(Z*s+_*d)*.001,s+=d*.001;Math.abs(s)*p<.5?s=d=i=0:i=requestAnimationFrame(m),h()},x=f=>{s=matchMedia("(prefers-reduced-motion: reduce)").matches?0:s+o-f,o=f,i||(l=performance.now(),i=requestAnimationFrame(m))},w=f=>{let g=v-f;return g<=0?f:g>A?0:v-T*(1-Math.exp(-g/T))};r.onpointerdown=f=>{f.button||(f.preventDefault(),r.setPointerCapture(f.pointerId),p=t.clientWidth-6,n=f.clientX-o*p)},r.onpointermove=f=>{if(n===void 0)return;if(!(f.buttons&1))return E();let g=f.clientX-n;if(c){let I=c<0?Math.min(g,0):Math.max(g-p,0);if(n+=I,g-=I,(c<0?g:p-g)<v){o=g/p,h();return}c=0}let k=w(g),N=w(p-g);c=k?N?0:1:-1,c?(x(c<0?0:1),n=f.clientX-o*p):o=(k===g?p-N:k)/p,h()};let E=()=>{if(n===void 0)return;n=void 0;let f=o*p,g=Math.min(f,p-f);c&&g<v-A?x(c<0?0:1):g<v&&(c=0,x((f<v?v:p-v)/p))};return r.onpointerup=r.onpointercancel=r.onlostpointercapture=E,r.ondblclick=()=>{c=0,x(.5)},()=>cancelAnimationFrame(i)},[]),u("div",{ref:e,className:"cc-split","aria-hidden":!0})}function ie({className:e,theme:r,preview:a,tab:t,source:o,changed:s,note:d,onReset:p,...c}){return b("div",{className:e?`cc ${e}`:"cc","data-theme":r,children:[b("div",{className:"cc-frame",children:[u("div",{className:"cc-preview",children:a}),b("div",{className:"cc-code","data-note":d,children:[t,u(G,{source:o,changed:s,note:d,onReset:p}),u(j,{source:o,...c})]})]}),u("div",{className:"cc-tab",children:"Preview"}),u(U,{})]})}var R=e=>`${e}`.split(".")[1]?.length??0,le=e=>10**-R(e),pe=(e,r)=>`${+e.toFixed(R(r))}`;export{le as a,pe as b,J as c,ce as d,oe as e,ae as f,ie as g};
|