@stacksjs/docs 0.75.535 → 0.75.537

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/style-guide.js +31 -31
  2. package/package.json +5 -5
@@ -1,16 +1,16 @@
1
1
  // @bun
2
- import{createHash as Oe}from"crypto";import{existsSync as V}from"fs";import{lstat as Re,mkdir as de,readFile as A,readdir as Pe,realpath as K,rename as Ne,rm as pe,writeFile as ue}from"fs/promises";import{basename as me,dirname as X,isAbsolute as Te,join as f,relative as x,resolve as p,sep as he}from"path";import{pathToFileURL as Fe}from"url";import{generateCss as De}from"@stacksjs/stx/dev-server/ts-css";import{renderTemplateString as ze}from"@stacksjs/stx/render";import{analyzeComponent as Me}from"@stacksjs/stx/story/collect/analyzer";import{parseStoryContent as We}from"@stacksjs/stx/story/collect/parser";var Z=1,S=(t)=>t.split(he).join("/"),v=(t)=>Oe("sha256").update(t).digest("hex"),u=(t)=>t.replace(/[&<>"']/g,(i)=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[i]),g=(t)=>u(t).replaceAll("|","&#124;").replace(/\r?\n/g," "),Q=(t)=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),J=(t)=>`${JSON.stringify(t,null,2)}
3
- `,L=(t,i)=>[...t.matchAll(new RegExp(`@${i}\\s+([^\\n\\r]+)`,"g"))].map((n)=>n[1].replace(/\*\/.*$/,"").trim());function Qe(t,i=":root"){let n=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=t.match(new RegExp(`${n}\\s*\\{([^}]+)\\}`))?.[1];if(!r)throw Error(`Style guide: no token block for ${i}`);return[...r.matchAll(/(--[\w-]+)\s*:\s*([^;]+)(?:;|$)/g)].map((c)=>({name:c[1],value:c[2].trim()}))}function ge(t){let i=new Map,n=t.match(/\bdefineProps\s*<\s*(\w+)\s*>/)?.[1];if(n){let r=t.match(new RegExp(`interface\\s+${n}\\s*\\{([\\s\\S]*?)\\n\\}`))?.[1];for(let c of(r||"").matchAll(/(?:\/\*\*([\s\S]*?)\*\/\s*)?([\w$]+)(\?)?\s*:\s*([^;\n]+)[;\n]?/g)){let j=c[2];i.set(j,{name:j,type:c[4].trim(),description:`${c[3]?"Optional. ":"Required. "}${(c[1]||"").replace(/\s*\*\s*/g," ").trim()}`.trim()})}}for(let r of t.matchAll(/@prop\s+\{([^}]+)\}\s+(\S+)\s*([^\n\r]*)/g)){let c=r[2].replace(/^\[|\]$/g,"");i.set(c,{name:c,type:r[1],description:r[3].replace(/\*\/.*$/,"").trim()})}for(let r of t.matchAll(/\$props\.([a-z_$][\w$]*)|\buseReactiveProp(?:<[^>]+>)?\(\s*['"]([^'"]+)['"]/gi)){let c=r[1]||r[2];if(!i.has(c))i.set(c,{name:c,type:"Not declared",description:"Read by the implementation; see source for defaults and accepted values."})}return[...i.values()].sort((r,c)=>r.name.localeCompare(c.name))}async function Y(t){let i=[];for(let n of(await Pe(t,{withFileTypes:!0})).sort((r,c)=>r.name.localeCompare(c.name))){if(n.name.startsWith(".")||n.name==="node_modules")continue;let r=f(t,n.name);if(n.isDirectory())i.push(...await Y(r));else if(n.isFile()&&n.name.endsWith(".stx"))i.push(r)}return i}function b(t,i){let n=x(t,i);return n!==""&&!n.startsWith(`..${he}`)&&n!==".."&&!Te(n)}async function O(t,i){if(!b(t,i))throw Error(`Style guide: output must be inside the project: ${i}`);for(let n=i;n!==t;n=X(n))try{if((await Re(n)).isSymbolicLink())throw Error(`Style guide: refusing symlink output: ${n}`)}catch(r){if(r.code!=="ENOENT")throw r}}function fe(t){if(!t.startsWith("/")||/[?#<>"'\\]|\/\//.test(t)||t.split("/").includes(".."))throw Error(`Style guide: invalid local route: ${t}`);return t.replace(/\/$/,"")}function ye(t,i,n,r){let c=`:root{color-scheme:light dark}*{box-sizing:border-box}body{margin:0;padding:24px;background:${r.background};color:${r.foreground};font-family:${t.brand.font||"system-ui,sans-serif"}}body>main{max-width:1100px;margin:auto}button,input,select,textarea{font:inherit}@media(max-width:480px){body{padding:16px}}@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important}}`;return`<!doctype html>
4
- <html lang="en" class="${u(r.bodyClass||"")}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline' 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data:; font-src 'self' data:; connect-src 'none'; form-action 'none'; base-uri 'none'"><title>${u(`${t.brand.name}: ${i}`)}</title><link rel="stylesheet" href="./components.css"><style>${c}</style></head><body class="${u(r.bodyClass||"")}"><main aria-label="${u(i)}">${n}</main></body></html>
5
- `}async function Ue(t=process.cwd(),i="config/style-guide.ts"){let n=p(t,i);if(!V(n))return;let r=await import(Fe(n).href);if(!r.default||typeof r.default!=="object")throw Error(`Style guide: ${i} must export a configuration object`);return r.default}async function Ie(t,i={}){let n=await K(i.root||process.cwd()),r=p(n,t.output?.docs||"docs/style-guide/generated"),c=p(n,t.output?.public||"docs/public/style-guide/generated"),j=fe(t.output?.route||"/style-guide/generated"),D=fe(t.output?.publicUrl||"/style-guide/generated");if(await O(n,r),await O(n,c),r===c||b(r,c)||b(c,r))throw Error("Style guide: docs and public output directories must be separate");if(!t.brand?.name||!t.sources?.length)throw Error("Style guide: brand.name and at least one component source are required");let R=t.preview?.appearances?.map((e)=>Q(e.name));if(R&&(!R.length||R.some((e)=>!e)||new Set(R).size!==R.length))throw Error("Style guide: appearance names must be nonempty and unique");let P=[],C=[],z=new Map,M=new Map,ee=new Set;for(let e of t.sources){if(!/^[a-z0-9][a-z0-9-]*$/.test(e.id)||ee.has(e.id))throw Error(`Style guide: source IDs must be unique lowercase slugs: ${e.id}`);ee.add(e.id);let s=p(n,e.directory);if(b(s,r)||b(s,c)||s===r||s===c)throw Error("Style guide: outputs cannot be inside component sources");for(let o of await Y(s)){let a=S(x(s,o));if(e.exclude?.some((F)=>new Bun.Glob(F).match(a)))continue;let d={path:o,source:`${e.id}/${a}`,content:await A(o,"utf8")};if(P.push(d),o.endsWith(".story.stx")){z.set(o,d);continue}let l=me(o,".stx"),w=d.content.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi,"").replace(/<!--[\s\S]*?-->/g,""),B=Me(w,l,d.source);M.set(`${e.id}/${a.slice(0,-4)}`,d.content),C.push({id:`${e.id}/${a.slice(0,-4)}`,name:l,source:b(n,o)?S(x(n,o)):d.source,library:e.label||e.id,description:L(d.content,"description")[0]||"",props:ge(d.content),slots:B.slots.map((F)=>F.name).sort(),events:L(d.content,"event"),dependencies:[...new Set(B.dependencies)].sort(),stories:[]})}}for(let[e,s]of(t.stories||[]).entries()){let o=p(n,s);for(let a of await Y(o)){if(!a.endsWith(".story.stx")||z.has(a))continue;let d={path:a,source:`stories-${e}/${S(x(o,a))}`,content:await A(a,"utf8")};P.push(d),z.set(a,d)}}let k=[];for(let e of[...z.values()].sort((s,o)=>s.source.localeCompare(o.source))){let s=We(e.content,e.path);if(!s||s.variants.some((l)=>!l.source))throw Error(`Style guide: ${e.source} needs a Story with explicit, nonempty Variants`);let o=`${Q(e.source.replace(/\.story\.stx$/,""))}-${v(e.source).slice(0,8)}`,a=e.content.match(/<Story\b[^>]*\bcomponent=["']([^"']+)["']/)?.[1],d={id:o,title:s.title,group:s.group||"Patterns",component:a,file:e,variants:s.variants.map((l)=>({id:l.id,title:l.title,source:l.source}))};if(new Set(d.variants.map((l)=>l.id)).size!==d.variants.length)throw Error(`Style guide: duplicate variant titles in ${e.source}`);if(a){let l=C.find((w)=>w.id===a);if(!l)throw Error(`Style guide: unknown component ${a} in ${e.source}`);l.stories.push(o),M.set(a,`${M.get(a)}
6
- ${e.content}`),l.props=ge(M.get(a)),l.events=[...new Set([...l.events,...L(e.content,"event")])],l.description||=L(e.content,"description")[0]||""}k.push(d)}C.sort((e,s)=>e.id.localeCompare(s.id));let te=await Promise.all((t.styles?.files||[]).map(async(e)=>({path:p(n,e),source:S(e),content:await A(p(n,e),"utf8")})));P.push(...te);let ne=t.styles?.utilities===!1?"":await De(P.map((e)=>e.content).join(`
7
- `),n),W=`${ne}
8
- ${te.map((e)=>e.content).join(`
2
+ import{createHash as Re}from"crypto";import{existsSync as V}from"fs";import{lstat as Pe,mkdir as de,readFile as A,readdir as Ne,realpath as Z,rename as Te,rm as pe,writeFile as ue}from"fs/promises";import{basename as me,dirname as Y,isAbsolute as Fe,join as f,relative as x,resolve as p,sep as ye}from"path";import{pathToFileURL as De}from"url";import{generateCss as ze}from"@stacksjs/stx/dev-server/ts-css";import{renderTemplateString as Me}from"@stacksjs/stx/render";import{analyzeComponent as We}from"@stacksjs/stx/story/collect/analyzer";import{parseStoryContent as Ue}from"@stacksjs/stx/story/collect/parser";var Q=1,S=(t)=>t.split(ye).join("/"),b=(t)=>Re("sha256").update(t).digest("hex"),u=(t)=>t.replace(/[&<>"']/g,(o)=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[o]),g=(t)=>u(t).replaceAll("|","&#124;").replace(/\r?\n/g," "),X=(t)=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),J=(t)=>`${JSON.stringify(t,null,2)}
3
+ `,L=(t,o)=>[...t.matchAll(new RegExp(`@${o}\\s+([^\\n\\r]+)`,"g"))].map((n)=>n[1].replace(/\*\/.*$/,"").trim());function Xe(t,o=":root"){let n=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=t.match(new RegExp(`${n}\\s*\\{([^}]+)\\}`))?.[1];if(!r)throw Error(`Style guide: no token block for ${o}`);return[...r.matchAll(/(--[\w-]+)\s*:\s*([^;]+)(?:;|$)/g)].map((c)=>({name:c[1],value:c[2].trim()}))}function ge(t){let o=new Map,n=t.match(/\bdefineProps\s*<\s*(\w+)\s*>/)?.[1];if(n){let r=t.match(new RegExp(`interface\\s+${n}\\s*\\{([\\s\\S]*?)\\n\\}`))?.[1];for(let c of(r||"").matchAll(/(?:\/\*\*([\s\S]*?)\*\/\s*)?([\w$]+)(\?)?\s*:\s*([^;\n]+)[;\n]?/g)){let C=c[2];o.set(C,{name:C,type:c[4].trim(),description:`${c[3]?"Optional. ":"Required. "}${(c[1]||"").replace(/\s*\*\s*/g," ").trim()}`.trim()})}}for(let r of t.matchAll(/@prop\s+\{([^}]+)\}\s+(\S+)\s*([^\n\r]*)/g)){let c=r[2].replace(/^\[|\]$/g,"");o.set(c,{name:c,type:r[1],description:r[3].replace(/\*\/.*$/,"").trim()})}for(let r of t.matchAll(/\$props\.([a-z_$][\w$]*)|\buseReactiveProp(?:<[^>]+>)?\(\s*['"]([^'"]+)['"]/gi)){let c=r[1]||r[2];if(!o.has(c))o.set(c,{name:c,type:"Not declared",description:"Read by the implementation; see source for defaults and accepted values."})}return[...o.values()].sort((r,c)=>r.name.localeCompare(c.name))}async function ee(t){let o=[];for(let n of(await Ne(t,{withFileTypes:!0})).sort((r,c)=>r.name.localeCompare(c.name))){if(n.name.startsWith(".")||n.name==="node_modules")continue;let r=f(t,n.name);if(n.isDirectory())o.push(...await ee(r));else if(n.isFile()&&n.name.endsWith(".stx"))o.push(r)}return o}function w(t,o){let n=x(t,o);return n!==""&&!n.startsWith(`..${ye}`)&&n!==".."&&!Fe(n)}async function R(t,o){if(!w(t,o))throw Error(`Style guide: output must be inside the project: ${o}`);for(let n=o;n!==t;n=Y(n))try{if((await Pe(n)).isSymbolicLink())throw Error(`Style guide: refusing symlink output: ${n}`)}catch(r){if(r.code!=="ENOENT")throw r}}function fe(t){if(!t.startsWith("/")||/[?#<>"'\\]|\/\//.test(t)||t.split("/").includes(".."))throw Error(`Style guide: invalid local route: ${t}`);return t.replace(/\/$/,"")}function he(t,o,n,r){let c=`:root{color-scheme:light dark}*{box-sizing:border-box}body{margin:0;padding:24px;background:${r.background};color:${r.foreground};font-family:${t.brand.font||"system-ui,sans-serif"}}body>main{max-width:1100px;margin:auto}button,input,select,textarea{font:inherit}@media(max-width:480px){body{padding:16px}}@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important}}`;return`<!doctype html>
4
+ <html lang="en" class="${u(r.bodyClass||"")}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline' 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data:; font-src 'self' data:; connect-src 'none'; form-action 'none'; base-uri 'none'"><title>${u(`${t.brand.name}: ${o}`)}</title><link rel="stylesheet" href="./components.css"><style>${c}</style></head><body class="${u(r.bodyClass||"")}"><main aria-label="${u(o)}">${n}</main></body></html>
5
+ `}async function Be(t=process.cwd(),o="config/style-guide.ts"){let n=p(t,o);if(!V(n))return;let r=await import(De(n).href);if(!r.default||typeof r.default!=="object")throw Error(`Style guide: ${o} must export a configuration object`);return r.default}async function Ie(t,o={}){let n=await Z(o.root||process.cwd()),r=p(n,t.output?.docs||"docs/style-guide/generated"),c=p(n,t.output?.public||"docs/public/style-guide/generated"),C=fe(t.output?.route||"/style-guide/generated"),z=fe(t.output?.publicUrl||"/style-guide/generated");if(await R(n,r),await R(n,c),r===c||w(r,c)||w(c,r))throw Error("Style guide: docs and public output directories must be separate");if(!t.brand?.name||!t.sources?.length)throw Error("Style guide: brand.name and at least one component source are required");let P=t.preview?.appearances?.map((e)=>X(e.name));if(P&&(!P.length||P.some((e)=>!e)||new Set(P).size!==P.length))throw Error("Style guide: appearance names must be nonempty and unique");let N=[],E=[],M=new Map,W=new Map,te=new Set;for(let e of t.sources){if(!/^[a-z0-9][a-z0-9-]*$/.test(e.id)||te.has(e.id))throw Error(`Style guide: source IDs must be unique lowercase slugs: ${e.id}`);te.add(e.id);let s=p(n,e.directory);if(w(s,r)||w(s,c)||s===r||s===c)throw Error("Style guide: outputs cannot be inside component sources");for(let i of await ee(s)){let a=S(x(s,i));if(e.exclude?.some((D)=>new Bun.Glob(D).match(a)))continue;let d={path:i,source:`${e.id}/${a}`,content:await A(i,"utf8")};if(N.push(d),i.endsWith(".story.stx")){M.set(i,d);continue}let l=me(i,".stx"),v=d.content.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi,"").replace(/<!--[\s\S]*?-->/g,""),I=We(v,l,d.source);W.set(`${e.id}/${a.slice(0,-4)}`,d.content),E.push({id:`${e.id}/${a.slice(0,-4)}`,name:l,source:w(n,i)?S(x(n,i)):d.source,library:e.label||e.id,description:L(d.content,"description")[0]||"",props:ge(d.content),slots:I.slots.map((D)=>D.name).sort(),events:L(d.content,"event"),dependencies:[...new Set(I.dependencies)].sort(),stories:[]})}}for(let[e,s]of(t.stories||[]).entries()){let i=p(n,s);for(let a of await ee(i)){if(!a.endsWith(".story.stx")||M.has(a))continue;let d={path:a,source:`stories-${e}/${S(x(i,a))}`,content:await A(a,"utf8")};N.push(d),M.set(a,d)}}let k=[];for(let e of[...M.values()].sort((s,i)=>s.source.localeCompare(i.source))){let s=Ue(e.content,e.path);if(!s||s.variants.some((l)=>!l.source))throw Error(`Style guide: ${e.source} needs a Story with explicit, nonempty Variants`);let i=`${X(e.source.replace(/\.story\.stx$/,""))}-${b(e.source).slice(0,8)}`,a=e.content.match(/<Story\b[^>]*\bcomponent=["']([^"']+)["']/)?.[1],d={id:i,title:s.title,group:s.group||"Patterns",component:a,file:e,variants:s.variants.map((l)=>({id:l.id,title:l.title,source:l.source}))};if(new Set(d.variants.map((l)=>l.id)).size!==d.variants.length)throw Error(`Style guide: duplicate variant titles in ${e.source}`);if(a){let l=E.find((v)=>v.id===a);if(!l)throw Error(`Style guide: unknown component ${a} in ${e.source}`);l.stories.push(i),W.set(a,`${W.get(a)}
6
+ ${e.content}`),l.props=ge(W.get(a)),l.events=[...new Set([...l.events,...L(e.content,"event")])],l.description||=L(e.content,"description")[0]||""}k.push(d)}E.sort((e,s)=>e.id.localeCompare(s.id));let ne=await Promise.all((t.styles?.files||[]).map(async(e)=>({path:p(n,e),source:S(e),content:await A(p(n,e),"utf8")})));N.push(...ne);let se=t.styles?.utilities===!1?"":await ze(N.map((e)=>e.content).join(`
7
+ `),n),G=`${se}
8
+ ${ne.map((e)=>e.content).join(`
9
9
  `)}
10
10
  ${t.styles?.css||""}
11
- `,m=new Map,E={};async function se(e){if(!e.startsWith("/")||e.startsWith("//")||/[?#]/.test(e))throw Error(`Style guide: CSS assets must be local public paths: ${e}`);let s=p(n,"public",`.${e}`);if(!b(p(n,"public"),s)||!b(await K(p(n,"public")),await K(s)))throw Error(`Style guide: asset outside public: ${e}`);return A(s)}async function re(e){if(e.startsWith("data:")||e.startsWith("#"))return e;let s=await se(e),o=`${v(s).slice(0,12)}-${me(e)}`;return m.set(f(c,"assets",o),s),E[e]=v(s),`./assets/${o}`}let be=[...new Set([...W.matchAll(/url\(\s*['"]?([^)'"\s]+)['"]?\s*\)/g)].map((e)=>e[1]))];for(let e of be)W=W.replaceAll(e,await re(e));m.set(f(c,"components.css"),W);let $e=v(await A(import.meta.path)),we=JSON.parse(await A(p(X(Bun.resolveSync("@stacksjs/stx/render",import.meta.dir)),"../package.json"),"utf8")).version,ie=()=>v(J({format:Z,implementation:$e,renderer:we,config:t,inputs:P.map((e)=>[e.source,v(e.content)]).sort(),utilityCss:v(ne),assets:Object.fromEntries(Object.entries(E).sort())})),N=f(r,"manifest.json"),y;if(V(N)){if(await O(n,N),y=JSON.parse(await A(N,"utf8")),y.format!==Z||!y.files||typeof y.files!=="object")throw Error("Style guide: invalid ownership manifest");for(let e of Object.keys(y.files)){let s=p(n,e);if(!b(r,s)&&!b(c,s)||e!==S(x(n,s))||s===N)throw Error(`Style guide: invalid owned path: ${e}`);await O(n,s)}}let ve={...E},T=Boolean(y);for(let e of y?.assets||[])try{E[e]=v(await se(e))}catch{T=!1}if(T&&=y?.fingerprint===ie(),T&&y){for(let[e,s]of Object.entries(y.files))if(!V(p(n,e))||v(await A(p(n,e)))!==s){if(i.check)throw Error(`Style guide output is stale: ${e}. Run buddy docs:style-guide.`);T=!1;break}}if(T&&y)return{...y.result,checked:Boolean(i.check)};if(i.check)throw Error("Style guide is stale. Run buddy docs:style-guide and commit the generated files.");for(let e of Object.keys(E))delete E[e];Object.assign(E,ve);let H=(e)=>`components/${e.id.split("/").map((s)=>encodeURIComponent(s)).join("/")}`,oe=(e,s)=>`| ${e.join(" | ")} |
11
+ `,m=new Map,j={};async function H(e){if(!e.startsWith("/")||e.startsWith("//")||/[?#]/.test(e))throw Error(`Style guide: CSS assets must be local public paths: ${e}`);let s=p(n,"public",`.${e}`);if(!w(p(n,"public"),s)||!w(await Z(p(n,"public")),await Z(s)))throw Error(`Style guide: asset outside public: ${e}`);return A(s)}async function re(e){if(e.startsWith("data:")||e.startsWith("#"))return e;let s=await H(e),i=`${b(s).slice(0,12)}-${me(e)}`;return m.set(f(c,"assets",i),s),j[e]=b(s),`./assets/${i}`}let be=[...new Set([...G.matchAll(/url\(\s*['"]?([^)'"\s]+)['"]?\s*\)/g)].map((e)=>e[1]))],$e=new Set([...G.matchAll(/@font-face\s*\{[^}]*\}/gi)].flatMap((e)=>[...e[0].matchAll(/url\(\s*['"]?([^)'"\s]+)['"]?\s*\)/g)].map((s)=>s[1])));for(let e of be)if($e.has(e)&&!e.startsWith("data:")){let s=await H(e);j[e]=b(s);let i=Bun.file(e).type||"application/octet-stream";G=G.replaceAll(e,`data:${i};base64,${s.toString("base64")}`)}else G=G.replaceAll(e,await re(e));m.set(f(c,"components.css"),G);let we=b(await A(import.meta.path)),ve=JSON.parse(await A(p(Y(Bun.resolveSync("@stacksjs/stx/render",import.meta.dir)),"../package.json"),"utf8")).version,ie=()=>b(J({format:Q,implementation:we,renderer:ve,config:t,inputs:N.map((e)=>[e.source,b(e.content)]).sort(),utilityCss:b(se),assets:Object.fromEntries(Object.entries(j).sort())})),T=f(r,"manifest.json"),h;if(V(T)){if(await R(n,T),h=JSON.parse(await A(T,"utf8")),h.format!==Q||!h.files||typeof h.files!=="object")throw Error("Style guide: invalid ownership manifest");for(let e of Object.keys(h.files)){let s=p(n,e);if(!w(r,s)&&!w(c,s)||e!==S(x(n,s))||s===T)throw Error(`Style guide: invalid owned path: ${e}`);await R(n,s)}}let Se={...j},F=Boolean(h);for(let e of h?.assets||[])try{j[e]=b(await H(e))}catch{F=!1}if(F&&=h?.fingerprint===ie(),F&&h){for(let[e,s]of Object.entries(h.files))if(!V(p(n,e))||b(await A(p(n,e)))!==s){if(o.check)throw Error(`Style guide output is stale: ${e}. Run buddy docs:style-guide.`);F=!1;break}}if(F&&h)return{...h.result,checked:Boolean(o.check)};if(o.check)throw Error("Style guide is stale. Run buddy docs:style-guide and commit the generated files.");for(let e of Object.keys(j))delete j[e];Object.assign(j,Se);let _=(e)=>`components/${e.id.split("/").map((s)=>encodeURIComponent(s)).join("/")}`,oe=(e,s)=>`| ${e.join(" | ")} |
12
12
  | ${e.map(()=>"---").join(" | ")} |
13
- ${s.map((o)=>`| ${o.map(g).join(" | ")} |`).join(`
13
+ ${s.map((i)=>`| ${i.map(g).join(" | ")} |`).join(`
14
14
  `)}
15
15
  `,U=(e,s)=>`---
16
16
  title: ${JSON.stringify(`${t.brand.name}: ${e}`)}
@@ -22,15 +22,15 @@ description: ${JSON.stringify(`${e}. Production component reference for ${t.bran
22
22
  # ${g(e)}
23
23
 
24
24
  ${s}
25
- `,I=(e,s)=>`[${g(s)}](${j}/${e})`,_=[{text:"Component guide",link:`${j}/`},{text:"Foundations",link:`${j}/foundations`}],Se=Object.values(t.tokens||{}).flat().filter((e)=>/^(?:#[\da-f]{3,8}\b|rgba?\(|hsla?\(|oklch\()/i.test(e.value)),xe=Object.entries(t.tokens||{}).filter(([e])=>/typography|fonts/i.test(e)).flatMap(([,e])=>e),ke=Se.map((e)=>`<article style="border:1px solid #8885;min-width:0"><div style="height:80px;background:${u(e.value)}"></div><div style="padding:12px;overflow-wrap:anywhere"><strong>${u(e.name)}</strong><p>${u(e.value)}</p></div></article>`).join(""),je=`<header style="border-bottom:4px solid ${u(t.brand.accent)};padding-bottom:24px;margin-bottom:24px"><p>Design foundations</p><h1 style="font-size:32px;font-weight:700">${u(t.brand.name)}</h1><p>${u(t.brand.description||"")}</p></header><section aria-label="Color tokens" style="display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:16px">${ke}</section><section aria-label="Typography" style="margin-top:32px">${xe.map((e)=>`<article style="padding:20px 0;border-bottom:1px solid #8884"><p>${u(e.name)}: ${u(e.value)}</p><p style="font-family:${u(e.value)};font-size:28px;line-height:1.35">Training with purpose. Aa 0123456789</p></article>`).join("")}</section>`;m.set(f(c,"foundations.html"),ye(t,"Foundations",je,{background:t.brand.background||"#fff",foreground:t.brand.foreground||"#17202a"}));let Ce=Object.entries(t.tokens||{}).map(([e,s])=>`## ${g(e)}
25
+ `,B=(e,s)=>`[${g(s)}](${C}/${e})`,K=[{text:"Component guide",link:`${C}/`},{text:"Foundations",link:`${C}/foundations`}],xe=Object.values(t.tokens||{}).flat().filter((e)=>/^(?:#[\da-f]{3,8}\b|rgba?\(|hsla?\(|oklch\()/i.test(e.value)),ke=Object.entries(t.tokens||{}).filter(([e])=>/typography|fonts/i.test(e)).flatMap(([,e])=>e),je=xe.map((e)=>`<article style="border:1px solid #8885;min-width:0"><div style="height:80px;background:${u(e.value)}"></div><div style="padding:12px;overflow-wrap:anywhere"><strong>${u(e.name)}</strong><p>${u(e.value)}</p></div></article>`).join(""),Ce=`<header style="border-bottom:4px solid ${u(t.brand.accent)};padding-bottom:24px;margin-bottom:24px"><p>Design foundations</p><h1 style="font-size:32px;font-weight:700">${u(t.brand.name)}</h1><p>${u(t.brand.description||"")}</p></header><section aria-label="Color tokens" style="display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:16px">${je}</section><section aria-label="Typography" style="margin-top:32px">${ke.map((e)=>`<article style="padding:20px 0;border-bottom:1px solid #8884"><p>${u(e.name)}: ${u(e.value)}</p><p style="font-family:${u(e.value)};font-size:28px;line-height:1.35">Training with purpose. Aa 0123456789</p></article>`).join("")}</section>`;m.set(f(c,"foundations.html"),he(t,"Foundations",Ce,{background:t.brand.background||"#fff",foreground:t.brand.foreground||"#17202a"}));let Ee=Object.entries(t.tokens||{}).map(([e,s])=>`## ${g(e)}
26
26
 
27
- ${oe(["Token","Value","Purpose"],s.map((o)=>[o.name,o.value,o.description||""]))}`).join(`
27
+ ${oe(["Token","Value","Purpose"],s.map((i)=>[i.name,i.value,i.description||""]))}`).join(`
28
28
  `);m.set(f(r,"foundations.md"),U("Foundations",`${g(t.brand.description||"")}
29
29
 
30
30
  ${(t.brand.principles||[]).map((e)=>`- ${g(e)}`).join(`
31
31
  `)}
32
32
 
33
- ${Ce}
33
+ ${Ee}
34
34
  ## Accessibility and behavior
35
35
 
36
36
  Use semantic controls, visible keyboard focus, persistent labels and accessible names for icon actions. Test both appearances, reduced motion and touch targets. Destructive actions retain their semantic color when a brand changes. Disabled and busy states must remain distinguishable. The previews show browser rendering; validate native layout and interaction separately.
@@ -41,28 +41,28 @@ Read tokens and styles from the production theme in config/style-guide.ts. Keep
41
41
  `)),m.set(f(r,"foundations.md"),`${m.get(f(r,"foundations.md"))}
42
42
  ## Visual specimens
43
43
 
44
- <a href="${D}/foundations.html">Open branded color and typography specimens</a>
44
+ <a href="${z}/foundations.html">Open branded color and typography specimens</a>
45
45
 
46
- <iframe title="${u(t.brand.name)} foundations" src="${D}/foundations.html" loading="lazy" sandbox="allow-scripts" style="width:100%;height:600px;border:1px solid #8884;border-radius:8px"></iframe>
47
- `);for(let e of k){let s=[],o=[...e.file.content.matchAll(/<script\b[^>]*>[\s\S]*?<\/script>/gi)].map((l)=>l[0]).join(`
46
+ <iframe title="${u(t.brand.name)} foundations" src="${z}/foundations.html" loading="lazy" sandbox="allow-scripts" style="width:100%;height:600px;border:1px solid #8884;border-radius:8px"></iframe>
47
+ `);for(let e of k){let s=[],i=[...e.file.content.matchAll(/<script\b[^>]*>[\s\S]*?<\/script>/gi)].map((l)=>l[0]).join(`
48
48
  `),a=[...e.file.content.matchAll(/<style\b[^>]*>[\s\S]*?<\/style>/gi)].map((l)=>l[0]).join(`
49
- `);for(let l of e.variants){let w=await ze(`${o}
49
+ `);for(let l of e.variants){let v=await Me(`${i}
50
50
  ${l.source}
51
- ${a}`,e.file.path,{options:{componentsDir:p(n,t.preview?.componentDirs?.[0]||t.sources[0].directory),additionalComponentsDirs:(t.preview?.componentDirs?.slice(1)||t.sources.slice(1).map((h)=>h.directory)).map((h)=>p(n,h)),storesDir:p(n,"storage/framework/runtime/style-guide/no-stores")},context:{},processClientScripts:!0});for(let h of[...w.matchAll(/\bsrc=["'](\/[^"']+)["']/g)])w=w.replaceAll(h[1],await re(h[1]));let B=w.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi,"");if(/<[A-Z][\w.-]*(?:\s|\/?>)/.test(B))throw Error(`Style guide: unresolved component in ${e.file.source}: ${l.title}`);w=w.replace(/<script([^>]*\bdata-stx-runtime\b[^>]*)>([\s\S]*?)<\/script>/gi,(h,G,q)=>{if(/\bsrc\s*=/.test(G))return h;let le=`runtime-${v(q).slice(0,12)}.js`;return m.set(f(c,le),q),`<script${G} src="./${le}"></script>`}),s.push(`## ${g(l.title)}
52
- `);let F=t.preview?.appearances||[{name:"Default",bodyClass:t.preview?.bodyClass,background:t.brand.background||"#fff",foreground:t.brand.foreground||"#17202a"}];for(let h of F){let G=`${e.id}-${l.id}-${Q(h.name)}.html`,q=ye(t,`${e.title}, ${l.title}, ${h.name}`,w,h);m.set(f(c,G),q),s.push(`
53
- <a href="${D}/${G}">Open ${u(l.title)} preview (${u(h.name)})</a>
51
+ ${a}`,e.file.path,{options:{componentsDir:p(n,t.preview?.componentDirs?.[0]||t.sources[0].directory),additionalComponentsDirs:(t.preview?.componentDirs?.slice(1)||t.sources.slice(1).map((y)=>y.directory)).map((y)=>p(n,y)),storesDir:p(n,"storage/framework/runtime/style-guide/no-stores")},context:{},processClientScripts:!0});for(let y of[...v.matchAll(/\bsrc=["'](\/[^"']+)["']/g)])v=v.replaceAll(y[1],await re(y[1]));let I=v.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi,"");if(/<[A-Z][\w.-]*(?:\s|\/?>)/.test(I))throw Error(`Style guide: unresolved component in ${e.file.source}: ${l.title}`);v=v.replace(/<script([^>]*\bdata-stx-runtime\b[^>]*)>([\s\S]*?)<\/script>/gi,(y,O,q)=>{if(/\bsrc\s*=/.test(O))return y;let le=`runtime-${b(q).slice(0,12)}.js`;return m.set(f(c,le),q),`<script${O} src="./${le}"></script>`}),s.push(`## ${g(l.title)}
52
+ `);let D=t.preview?.appearances||[{name:"Default",bodyClass:t.preview?.bodyClass,background:t.brand.background||"#fff",foreground:t.brand.foreground||"#17202a"}];for(let y of D){let O=`${e.id}-${l.id}-${X(y.name)}.html`,q=he(t,`${e.title}, ${l.title}, ${y.name}`,v,y);m.set(f(c,O),q),s.push(`
53
+ <a href="${z}/${O}">Open ${u(l.title)} preview (${u(y.name)})</a>
54
54
 
55
- <iframe title="${u(`${e.title}: ${l.title}, ${h.name}`)}" src="${D}/${G}" loading="lazy" sandbox="allow-scripts" style="width:100%;height:440px;border:1px solid #8884;border-radius:8px"></iframe>
56
- `)}let Ge=[o,l.source,a].filter(Boolean).join(`
55
+ <iframe title="${u(`${e.title}: ${l.title}, ${y.name}`)}" src="${z}/${O}" loading="lazy" sandbox="allow-scripts" style="width:100%;height:440px;border:1px solid #8884;border-radius:8px"></iframe>
56
+ `)}let Oe=[i,l.source,a].filter(Boolean).join(`
57
57
 
58
58
  `);s.push(`
59
59
  \`\`\`stx
60
- ${Ge}
60
+ ${Oe}
61
61
  \`\`\`
62
- `)}let d=b(n,e.file.path)?S(x(n,e.file.path)):e.file.source;m.set(f(r,"patterns",`${e.id}.md`),U(e.title,`Source: \`${d}\`. Group: ${g(e.group)}. Local demonstration data only.
62
+ `)}let d=w(n,e.file.path)?S(x(n,e.file.path)):e.file.source;m.set(f(r,"patterns",`${e.id}.md`),U(e.title,`Source: \`${d}\`. Group: ${g(e.group)}. Local demonstration data only.
63
63
 
64
64
  ${s.join(`
65
- `)}`)),_.push({text:e.title,link:`${j}/patterns/${e.id}`})}for(let e of C){let s=e.stories.length?e.stories.map((a)=>I(`patterns/${a}`,k.find((d)=>d.id===a).title)).join(", "):"Reference only. Add an isolated .story.stx fixture before enabling a preview; this component is never executed by the inventory scan.",o=`${g(e.description||`${e.name} component in ${e.library}.`)}
65
+ `)}`)),K.push({text:e.title,link:`${C}/patterns/${e.id}`})}for(let e of E){let s=e.stories.length?e.stories.map((a)=>B(`patterns/${a}`,k.find((d)=>d.id===a).title)).join(", "):"Reference only. Add an isolated .story.stx fixture before enabling a preview; this component is never executed by the inventory scan.",i=`${g(e.description||`${e.name} component in ${e.library}.`)}
66
66
 
67
67
  Source: \`${e.source}\`. Stable ID: \`${e.id}\`.
68
68
 
@@ -87,17 +87,17 @@ ${e.events.length?e.events.map((a)=>`- ${g(a)}`).join(`
87
87
 
88
88
  ${e.dependencies.length?e.dependencies.map((a)=>`- \`${g(a)}\``).join(`
89
89
  `):"No child component tags detected."}
90
- `;m.set(f(r,`${H(e)}.md`),U(e.name,o)),_.push({text:`${e.library}: ${e.name}`,link:`${j}/${H(e)}`})}let Ee=C.map((e)=>`| ${I(H(e),e.name)} | ${g(e.library)} | ${e.stories.length?`${e.stories.length} fixture(s)`:"Reference only"} |`).join(`
91
- `),Ae=k.map((e)=>`- ${I(`patterns/${e.id}`,e.title)} (${g(e.group)}, ${e.variants.length} variants)`).join(`
90
+ `;m.set(f(r,`${_(e)}.md`),U(e.name,i)),K.push({text:`${e.library}: ${e.name}`,link:`${C}/${_(e)}`})}let Ae=E.map((e)=>`| ${B(_(e),e.name)} | ${g(e.library)} | ${e.stories.length?`${e.stories.length} fixture(s)`:"Reference only"} |`).join(`
91
+ `),Ge=k.map((e)=>`- ${B(`patterns/${e.id}`,e.title)} (${g(e.group)}, ${e.variants.length} variants)`).join(`
92
92
  `);m.set(f(r,"index.md"),U(`${t.brand.name} component guide`,`${g(t.brand.description||"")}
93
93
 
94
- ${C.length} components, ${k.length} isolated stories and ${k.reduce((e,s)=>e+s.variants.length,0)} variants. Generated from production sources, with ${g(t.brand.name)} branding.
94
+ ${E.length} components, ${k.length} isolated stories and ${k.reduce((e,s)=>e+s.variants.length,0)} variants. Generated from production sources, with ${g(t.brand.name)} branding.
95
95
 
96
- ${I("foundations","Foundations, tokens and branding")}
96
+ ${B("foundations","Foundations, tokens and branding")}
97
97
 
98
98
  ## Patterns and live examples
99
99
 
100
- ${Ae||"No isolated stories configured yet."}
100
+ ${Ge||"No isolated stories configured yet."}
101
101
 
102
102
  ## All components
103
103
 
@@ -105,5 +105,5 @@ Every configured component is indexed. Reference-only entries do not claim teste
105
105
 
106
106
  | Component | Library | Examples |
107
107
  | --- | --- | --- |
108
- ${Ee}
109
- `)),m.set(f(r,"sidebar.json"),J(_)),m.set(f(c,"catalog.json"),J({brand:t.brand,tokens:t.tokens||{},components:C,stories:k.map((e)=>({id:e.id,title:e.title,group:e.group,source:b(n,e.file.path)?S(x(n,e.file.path)):e.file.source,variants:e.variants}))}));let ae={components:C.length,stories:k.length,variants:k.reduce((e,s)=>e+s.variants.length,0)},ce=Object.fromEntries([...m].map(([e,s])=>[S(x(n,e)),v(s)]).sort(([e],[s])=>e.localeCompare(s)));for(let e of m.keys())if(await O(n,e),V(e)&&!y?.files[S(x(n,e))])throw Error(`Style guide: refusing to overwrite an unowned file: ${S(x(n,e))}`);for(let[e,s]of m){await de(X(e),{recursive:!0});let o=`${e}.style-guide-tmp`;await O(n,o),await ue(o,s,{flag:"wx"});try{await Ne(o,e)}finally{await pe(o,{force:!0})}}for(let e of Object.keys(y?.files||{}))if(!ce[e])await pe(p(n,e),{force:!0});return await de(r,{recursive:!0}),await ue(N,J({format:Z,fingerprint:ie(),files:ce,result:ae,assets:Object.keys(E).sort()})),{...ae,checked:!1}}async function Xe(t={}){let i=p(t.root||process.cwd()),n=await Ue(i,t.config);if(!n){if(t.optional)return;throw Error("Style guide: create config/style-guide.ts first. See the Stacks style guide documentation.")}return Ie(n,{root:i,check:t.check})}export{Ie as generateStyleGuide,Ue as loadStyleGuideConfig,Xe as runStyleGuide,Qe as styleGuideCssTokens};
108
+ ${Ae}
109
+ `)),m.set(f(r,"sidebar.json"),J(K)),m.set(f(c,"catalog.json"),J({brand:t.brand,tokens:t.tokens||{},components:E,stories:k.map((e)=>({id:e.id,title:e.title,group:e.group,source:w(n,e.file.path)?S(x(n,e.file.path)):e.file.source,variants:e.variants}))}));let ae={components:E.length,stories:k.length,variants:k.reduce((e,s)=>e+s.variants.length,0)},ce=Object.fromEntries([...m].map(([e,s])=>[S(x(n,e)),b(s)]).sort(([e],[s])=>e.localeCompare(s)));for(let e of m.keys())if(await R(n,e),V(e)&&!h?.files[S(x(n,e))])throw Error(`Style guide: refusing to overwrite an unowned file: ${S(x(n,e))}`);for(let[e,s]of m){await de(Y(e),{recursive:!0});let i=`${e}.style-guide-tmp`;await R(n,i),await ue(i,s,{flag:"wx"});try{await Te(i,e)}finally{await pe(i,{force:!0})}}for(let e of Object.keys(h?.files||{}))if(!ce[e])await pe(p(n,e),{force:!0});return await de(r,{recursive:!0}),await ue(T,J({format:Q,fingerprint:ie(),files:ce,result:ae,assets:Object.keys(j).sort()})),{...ae,checked:!1}}async function Ye(t={}){let o=p(t.root||process.cwd()),n=await Be(o,t.config);if(!n){if(t.optional)return;throw Error("Style guide: create config/style-guide.ts first. See the Stacks style guide documentation.")}return Ie(n,{root:o,check:t.check})}export{Ie as generateStyleGuide,Be as loadStyleGuideConfig,Ye as runStyleGuide,Xe as styleGuideCssTokens};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/docs",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.535",
5
+ "version": "0.75.537",
6
6
  "description": "The Stacks way to document.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -58,13 +58,13 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@stacksjs/bunpress": "^0.2.25",
61
- "@stacksjs/config": "0.75.535",
62
- "@stacksjs/path": "0.75.535",
61
+ "@stacksjs/config": "0.75.537",
62
+ "@stacksjs/path": "0.75.537",
63
63
  "@stacksjs/stx": "0.2.842"
64
64
  },
65
65
  "devDependencies": {
66
- "@stacksjs/alias": "0.75.535",
67
- "@stacksjs/server": "0.75.535",
66
+ "@stacksjs/alias": "0.75.537",
67
+ "@stacksjs/server": "0.75.537",
68
68
  "better-dx": "^0.2.24"
69
69
  }
70
70
  }