@stacksjs/docs 0.75.528 → 0.75.535
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 +23 -44
- package/dist/meta.d.ts +2 -5
- package/dist/style-guide.d.ts +55 -0
- package/dist/style-guide.js +109 -0
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,59 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Stacks documentation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@stacksjs/docs` supplies BunPress defaults and native branded component guides.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The root export provides `frameworkDefaults`, `docsConfig` and metadata constants.
|
|
6
|
+
Configure the documentation site with `BunPressOptions` from `@stacksjs/bunpress`.
|
|
6
7
|
|
|
7
|
-
|
|
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
|
-
|
|
14
|
+
buddy docs:style-guide
|
|
15
|
+
buddy docs:style-guide:check
|
|
19
16
|
```
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
32
|
+
## Tests
|
|
32
33
|
|
|
33
34
|
```bash
|
|
34
|
-
bun test
|
|
35
|
+
bun test ./storage/framework/core/docs/tests
|
|
35
36
|
```
|
|
36
37
|
|
|
37
|
-
|
|
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:
|
|
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 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)=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[i]),g=(t)=>u(t).replaceAll("|","|").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(`
|
|
9
|
+
`)}
|
|
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(" | ")} |
|
|
12
|
+
| ${e.map(()=>"---").join(" | ")} |
|
|
13
|
+
${s.map((o)=>`| ${o.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
|
+
`,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)}
|
|
26
|
+
|
|
27
|
+
${oe(["Token","Value","Purpose"],s.map((o)=>[o.name,o.value,o.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
|
+
${Ce}
|
|
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="${D}/foundations.html">Open branded color and typography specimens</a>
|
|
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(`
|
|
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}
|
|
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>
|
|
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(`
|
|
57
|
+
|
|
58
|
+
`);s.push(`
|
|
59
|
+
\`\`\`stx
|
|
60
|
+
${Ge}
|
|
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.
|
|
63
|
+
|
|
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}.`)}
|
|
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,`${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(`
|
|
92
|
+
`);m.set(f(r,"index.md"),U(`${t.brand.name} component guide`,`${g(t.brand.description||"")}
|
|
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.
|
|
95
|
+
|
|
96
|
+
${I("foundations","Foundations, tokens and branding")}
|
|
97
|
+
|
|
98
|
+
## Patterns and live examples
|
|
99
|
+
|
|
100
|
+
${Ae||"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
|
+
${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};
|
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.
|
|
5
|
+
"version": "0.75.535",
|
|
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.
|
|
62
|
-
"@stacksjs/path": "0.75.
|
|
61
|
+
"@stacksjs/config": "0.75.535",
|
|
62
|
+
"@stacksjs/path": "0.75.535",
|
|
63
|
+
"@stacksjs/stx": "0.2.842"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
|
-
"@stacksjs/alias": "0.75.
|
|
66
|
-
"@stacksjs/server": "0.75.
|
|
66
|
+
"@stacksjs/alias": "0.75.535",
|
|
67
|
+
"@stacksjs/server": "0.75.535",
|
|
67
68
|
"better-dx": "^0.2.24"
|
|
68
69
|
}
|
|
69
70
|
}
|