@fabiocv/component-code 0.4.0 → 0.5.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/dist/html.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
'use client';
|
|
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-
|
|
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-SWAR2HJY.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
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
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,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
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-
|
|
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-SWAR2HJY.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
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
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
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(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabiocv/component-code",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
],
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"author": "Fabio Azevedo (https://fabio.cv)",
|
|
17
|
-
"homepage": "https://
|
|
17
|
+
"homepage": "https://ui.fabio.cv/component-code/",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/naso/
|
|
20
|
+
"url": "git+https://github.com/naso/ui.fabio.cv.git",
|
|
21
21
|
"directory": "packages/component-code"
|
|
22
22
|
},
|
|
23
|
-
"bugs": "https://github.com/naso/
|
|
23
|
+
"bugs": "https://github.com/naso/ui.fabio.cv/issues",
|
|
24
24
|
"type": "module",
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"exports": {
|
|
File without changes
|