@stacksjs/docs 0.75.529 → 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.
package/README.md CHANGED
@@ -1,59 +1,38 @@
1
- # Documentation
1
+ # Stacks documentation
2
2
 
3
- wip
3
+ `@stacksjs/docs` supplies BunPress defaults and native branded component guides.
4
4
 
5
- ## ☘️ Features
5
+ The root export provides `frameworkDefaults`, `docsConfig` and metadata constants.
6
+ Configure the documentation site with `BunPressOptions` from `@stacksjs/bunpress`.
6
7
 
7
- wip
8
+ ## Component style guides
8
9
 
9
- - ⚡️
10
-
11
- wip
12
-
13
- ## 🤖 Usage
14
-
15
- wip
10
+ Create `config/style-guide.ts` using `StyleGuideConfig` from
11
+ `@stacksjs/docs/style-guide`, then run:
16
12
 
17
13
  ```bash
18
- bun install -d @stacksjs/docs
14
+ buddy docs:style-guide
15
+ buddy docs:style-guide:check
19
16
  ```
20
17
 
21
- Now, you can use it in your project:
22
-
23
- ```js
24
- import * as docs from '@stacksjs/docs'
18
+ The guide discovers production STX components, documents explicit public
19
+ contracts, renders isolated `.story.stx` variants and reads the application's
20
+ own design tokens and styles. Application stores are not auto-loaded into
21
+ previews. `buddy build --docs` generates configured guides automatically.
25
22
 
26
- // wip
27
- ```
23
+ Generated Markdown, a sidebar inventory, sandboxed public previews, local
24
+ assets and a JSON catalog are tracked by an ownership manifest. Freshness
25
+ checks are read-only; regeneration removes only stale owned outputs and keeps
26
+ authored documentation intact.
28
27
 
29
- Learn more in the docs.
28
+ See [the complete configuration and story conventions](https://stacksjs.com/docs/basics/style-guide).
29
+ The programmatic API exports `loadStyleGuideConfig`, `generateStyleGuide`,
30
+ `runStyleGuide` and `styleGuideCssTokens` from `@stacksjs/docs/style-guide`.
30
31
 
31
- ## 🧪 Testing
32
+ ## Tests
32
33
 
33
34
  ```bash
34
- bun test
35
+ bun test ./storage/framework/core/docs/tests
35
36
  ```
36
37
 
37
- ## 📈 Changelog
38
-
39
- Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
40
-
41
- ## 🚜 Contributing
42
-
43
- Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
44
-
45
- ## 🏝 Community
46
-
47
- For help, discussion about best practices, or any other conversation that would benefit from being searchable:
48
-
49
- [Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)
50
-
51
- For casual chit-chat with others using this package:
52
-
53
- [Join the Stacks Discord Server](https://stacksjs.com/discord)
54
-
55
- ## 📄 License
56
-
57
- The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
58
-
59
- Made with 💙
38
+ MIT license. Contributions follow the Stacks repository conventions.
package/dist/meta.d.ts CHANGED
@@ -11,13 +11,10 @@ export declare const releases: 'https://github.com/stacksjs/stacks/releases';
11
11
  export declare const contributing: 'https://github.com/stacksjs/stacks/blob/main/CONTRIBUTING.md';
12
12
  export declare const discord: 'https://chat.stacksjs.com';
13
13
  export declare const twitter: 'https://twitter.com/stacksjs';
14
- /* Avatar/Image/Sponsors servers
15
- * @defaultValue `[googleapis, gstatic]`
16
- */
14
+ /* Avatar/Image/Sponsors servers */
17
15
  export declare const preconnectLinks: unknown[];
18
- /** @defaultValue `[googleapis, gstatic]` */
19
16
  export declare const preconnectHomeLinks: unknown[];
20
17
  /* PWA runtime caching urlPattern regular expressions */
21
18
  export declare const pwaFontsRegex: RegExp;
22
19
  export declare const pwaFontStylesRegex: RegExp;
23
- export declare const githubusercontentRegex: unknown;
20
+ export declare const githubusercontentRegex: RegExp;
@@ -0,0 +1,55 @@
1
+ /** Extract custom properties from a chosen declaration block, not arbitrary selectors. */
2
+ export declare function styleGuideCssTokens(css: string, selector?: string): StyleGuideToken[];
3
+ export declare function loadStyleGuideConfig(root?: string, file?: string): Promise<StyleGuideConfig | undefined>;
4
+ /** Generate an owned reference directory, or verify inputs and every published byte without writing. */
5
+ export declare function generateStyleGuide(config: StyleGuideConfig, options?: { root?: string, check?: boolean }): Promise<StyleGuideResult>;
6
+ export declare function runStyleGuide(options?: { root?: string, config?: string, check?: boolean, optional?: boolean }): Promise<StyleGuideResult | undefined>;
7
+ export declare interface StyleGuideToken {
8
+ name: string
9
+ value: string
10
+ description?: string
11
+ }
12
+ export declare interface StyleGuideConfig {
13
+ brand: {
14
+ name: string
15
+ description?: string
16
+ accent: string
17
+ background?: string
18
+ foreground?: string
19
+ font?: string
20
+ principles?: string[]
21
+ }
22
+ sources: { id: string, directory: string, label?: string, exclude?: string[] }[]
23
+ stories?: string[]
24
+ tokens?: Record<string, StyleGuideToken[]>
25
+ styles?: { files?: string[], css?: string, utilities?: boolean }
26
+ preview?: {
27
+ componentDirs?: string[]
28
+ bodyClass?: string
29
+ appearances?: { name: string, bodyClass?: string, background: string, foreground: string }[]
30
+ }
31
+ output?: {
32
+ docs?: string
33
+ public?: string
34
+ route?: string
35
+ publicUrl?: string
36
+ }
37
+ }
38
+ export declare interface StyleGuideComponent {
39
+ id: string
40
+ name: string
41
+ source: string
42
+ library: string
43
+ description: string
44
+ props: { name: string, type: string, description: string }[]
45
+ slots: string[]
46
+ events: string[]
47
+ dependencies: string[]
48
+ stories: string[]
49
+ }
50
+ export declare interface StyleGuideResult {
51
+ components: number
52
+ stories: number
53
+ variants: number
54
+ checked: boolean
55
+ }
@@ -0,0 +1,109 @@
1
+ // @bun
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
+ `)}
10
+ ${t.styles?.css||""}
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
+ | ${e.map(()=>"---").join(" | ")} |
13
+ ${s.map((i)=>`| ${i.map(g).join(" | ")} |`).join(`
14
+ `)}
15
+ `,U=(e,s)=>`---
16
+ title: ${JSON.stringify(`${t.brand.name}: ${e}`)}
17
+ description: ${JSON.stringify(`${e}. Production component reference for ${t.brand.name}.`)}
18
+ ---
19
+
20
+ <!-- Generated by buddy docs:style-guide. Edit components, stories or config/style-guide.ts. -->
21
+
22
+ # ${g(e)}
23
+
24
+ ${s}
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
+
27
+ ${oe(["Token","Value","Purpose"],s.map((i)=>[i.name,i.value,i.description||""]))}`).join(`
28
+ `);m.set(f(r,"foundations.md"),U("Foundations",`${g(t.brand.description||"")}
29
+
30
+ ${(t.brand.principles||[]).map((e)=>`- ${g(e)}`).join(`
31
+ `)}
32
+
33
+ ${Ee}
34
+ ## Accessibility and behavior
35
+
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.
37
+
38
+ ## Branding and maintenance
39
+
40
+ Read tokens and styles from the production theme in config/style-guide.ts. Keep brand values out of component fixtures. Add isolated .story.stx variants for normal, disabled, busy, empty, error and boundary states where applicable. Use local fictional data; never import account stores or call services from a story. Regenerate with buddy docs:style-guide. Verify freshness with buddy docs:style-guide:check.
41
+ `)),m.set(f(r,"foundations.md"),`${m.get(f(r,"foundations.md"))}
42
+ ## Visual specimens
43
+
44
+ <a href="${z}/foundations.html">Open branded color and typography specimens</a>
45
+
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
+ `),a=[...e.file.content.matchAll(/<style\b[^>]*>[\s\S]*?<\/style>/gi)].map((l)=>l[0]).join(`
49
+ `);for(let l of e.variants){let v=await Me(`${i}
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((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
+
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
+
58
+ `);s.push(`
59
+ \`\`\`stx
60
+ ${Oe}
61
+ \`\`\`
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
+
64
+ ${s.join(`
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
+
67
+ Source: \`${e.source}\`. Stable ID: \`${e.id}\`.
68
+
69
+ ## Examples
70
+
71
+ ${s}
72
+
73
+ ## Props
74
+
75
+ ${e.props.length?oe(["Name","Type","Contract"],e.props.map((a)=>[a.name,a.type,a.description])):"No public prop declarations or supported prop reads were detected. Consult the source before assuming a prop contract."}
76
+ ## Slots
77
+
78
+ ${e.slots.length?e.slots.map((a)=>`- \`${g(a)}\``).join(`
79
+ `):"No slot outlets detected."}
80
+
81
+ ## Events
82
+
83
+ ${e.events.length?e.events.map((a)=>`- ${g(a)}`).join(`
84
+ `):"No explicit @event contract documented. DOM bindings and internal event handlers are not inferred as public events."}
85
+
86
+ ## Composition
87
+
88
+ ${e.dependencies.length?e.dependencies.map((a)=>`- \`${g(a)}\``).join(`
89
+ `):"No child component tags detected."}
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
+ `);m.set(f(r,"index.md"),U(`${t.brand.name} component guide`,`${g(t.brand.description||"")}
93
+
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
+
96
+ ${B("foundations","Foundations, tokens and branding")}
97
+
98
+ ## Patterns and live examples
99
+
100
+ ${Ge||"No isolated stories configured yet."}
101
+
102
+ ## All components
103
+
104
+ Every configured component is indexed. Reference-only entries do not claim tested behavior or visual coverage.
105
+
106
+ | Component | Library | Examples |
107
+ | --- | --- | --- |
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.529",
5
+ "version": "0.75.537",
6
6
  "description": "The Stacks way to document.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -58,12 +58,13 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@stacksjs/bunpress": "^0.2.25",
61
- "@stacksjs/config": "0.75.529",
62
- "@stacksjs/path": "0.75.529"
61
+ "@stacksjs/config": "0.75.537",
62
+ "@stacksjs/path": "0.75.537",
63
+ "@stacksjs/stx": "0.2.842"
63
64
  },
64
65
  "devDependencies": {
65
- "@stacksjs/alias": "0.75.529",
66
- "@stacksjs/server": "0.75.529",
66
+ "@stacksjs/alias": "0.75.537",
67
+ "@stacksjs/server": "0.75.537",
67
68
  "better-dx": "^0.2.24"
68
69
  }
69
70
  }