@razorwind/storybook 0.0.25 → 0.0.27
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/index.cjs +86 -35
- package/dist/index.d.cts +19 -13
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +19 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +84 -33
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("@razorwind/core/plugin"),t=require("@razorwind/core/utils"),n=require("node:path");function r(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).replaceAll(`
|
|
2
|
-
`,`\\n`).replaceAll(`\r`,`\\r`)}function
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("@razorwind/core/plugin"),t=require("@razorwind/core/utils"),n=require("node:path");function r(e,n={}){let r=n.cssVarPrefix??`rw`;return(0,t.flattenTokens)(e,{includeTypes:n.includeTypes,enrichToken:e=>({...e,cssVar:(0,t.toCssVar)(e.path,r)})})}function i(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).replaceAll(`
|
|
2
|
+
`,`\\n`).replaceAll(`\r`,`\\r`)}function a(e){return typeof e==`string`?`"${i(e)}"`:typeof e==`number`||typeof e==`boolean`?String(e):e==null?`undefined`:JSON.stringify(e)}function o(e){let t=e.titlePrefix??`Design Tokens`,n=e.themeFiles&&e.themeFiles.length>0?`
|
|
3
|
+
## Storybook UI theme
|
|
4
|
+
|
|
5
|
+
Generated theme module(s):
|
|
6
|
+
|
|
7
|
+
${e.themeFiles.map(e=>`- \`${e}\``).join(`
|
|
8
|
+
`)}
|
|
9
|
+
|
|
10
|
+
Wire into \`.storybook/preview.ts\`:
|
|
11
|
+
|
|
12
|
+
\`\`\`ts
|
|
13
|
+
import theme from "../${e.themeFiles[0]}";
|
|
14
|
+
|
|
15
|
+
export const parameters = {
|
|
16
|
+
docs: { theme }
|
|
17
|
+
};
|
|
18
|
+
\`\`\`
|
|
19
|
+
`:``;return`# Installing Storybook Token Docs
|
|
20
|
+
|
|
21
|
+
Generated by \`@razorwind/storybook\`.
|
|
22
|
+
|
|
23
|
+
## Files
|
|
24
|
+
|
|
25
|
+
- \`${e.outputPath}/Tokens.mdx\` — token overview (${t})
|
|
26
|
+
- \`${e.outputPath}/blocks/\` — React doc blocks (ColorPalette, Typeset, …)
|
|
27
|
+
- \`${e.outputPath}/tokens.json\` — flattened token manifest
|
|
28
|
+
${n}
|
|
29
|
+
## Setup
|
|
30
|
+
|
|
31
|
+
1. Add the generated MDX pages to Storybook (paths depend on your \`stories\` config):
|
|
32
|
+
|
|
33
|
+
\`\`\`ts
|
|
34
|
+
// .storybook/main.ts
|
|
35
|
+
export default {
|
|
36
|
+
stories: [
|
|
37
|
+
"../${e.outputPath}/**/*.mdx"
|
|
38
|
+
]
|
|
39
|
+
};
|
|
40
|
+
\`\`\`
|
|
41
|
+
|
|
42
|
+
2. Import doc blocks in MDX as needed:
|
|
43
|
+
|
|
44
|
+
\`\`\`mdx
|
|
45
|
+
import { ColorPaletteBlock } from "./blocks";
|
|
46
|
+
\`\`\`
|
|
47
|
+
|
|
48
|
+
3. Start Storybook and open **${t}** in the sidebar.
|
|
49
|
+
|
|
50
|
+
## Regenerate
|
|
51
|
+
|
|
52
|
+
Re-run Razorwind generate when tokens change to refresh docs under \`${e.outputPath}/\`.
|
|
53
|
+
`}function s(e,t){let n=new Map;for(let r of e){let e=r.path.split(`.`).slice(0,Math.max(t,1)).join(`.`)||r.path,i=n.get(e)??[];i.push(r),n.set(e,i)}return n}function c(e,t){return e===t?e.split(`.`).at(-1)??e:e.startsWith(`${t}.`)?e.slice(t.length+1):e.split(`.`).at(-1)??e}function l(e,t={}){return`import { ColorPalette, ColorItem } from "@storybook/addon-docs/blocks";
|
|
3
54
|
|
|
4
55
|
/**
|
|
5
56
|
* Color tokens rendered with Storybook's ColorPalette doc block.
|
|
@@ -9,10 +60,10 @@ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{val
|
|
|
9
60
|
export function ColorPaletteBlock() {
|
|
10
61
|
return (
|
|
11
62
|
<ColorPalette>
|
|
12
|
-
${[...
|
|
63
|
+
${[...s(e.filter(e=>e.type===`color`),t.colorGroupBy??2).entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>{let n=t.map(t=>` ${a(c(t.path,e))}: ${a(t.cssValue)}`).join(`,
|
|
13
64
|
`),r=t.find(e=>e.description)?.description??`${t.length} token${t.length===1?``:`s`}`;return` <ColorItem
|
|
14
|
-
title={${
|
|
15
|
-
subtitle={${
|
|
65
|
+
title={${a(e)}}
|
|
66
|
+
subtitle={${a(r)}}
|
|
16
67
|
colors={{
|
|
17
68
|
${n}
|
|
18
69
|
}}
|
|
@@ -21,7 +72,7 @@ ${n}
|
|
|
21
72
|
</ColorPalette>
|
|
22
73
|
);
|
|
23
74
|
}
|
|
24
|
-
`}function
|
|
75
|
+
`}function u(e,t={}){let n=t.sampleText??`The quick brown fox jumps over the lazy dog`,r=e.filter(e=>e.type===`dimension`&&/(?:font|type|text).*size|size.*(?:font|type|text)/i.test(e.path)).map(e=>{let t=/^(\d+(?:\.\d+)?)/.exec(e.cssValue);return t?Number(t[1]):e.cssValue}),i=[...new Set(r)],o=e.find(e=>e.type===`fontFamily`)?.cssValue??`system-ui, sans-serif`,s=e.find(e=>e.type===`fontWeight`),c=s&&Number.parseFloat(s.cssValue)||400,l=i.length>0?`[${i.map(e=>a(e)).join(`, `)}]`:`[12, 14, 16, 20, 24, 32]`;return`import { Typeset } from "@storybook/addon-docs/blocks";
|
|
25
76
|
|
|
26
77
|
/**
|
|
27
78
|
* Typography tokens rendered with Storybook's Typeset doc block.
|
|
@@ -31,14 +82,14 @@ ${n}
|
|
|
31
82
|
export function TypesetBlock() {
|
|
32
83
|
return (
|
|
33
84
|
<Typeset
|
|
34
|
-
fontFamily={${
|
|
85
|
+
fontFamily={${a(o)}}
|
|
35
86
|
fontSizes={${l}}
|
|
36
|
-
fontWeight={${
|
|
37
|
-
sampleText={${
|
|
87
|
+
fontWeight={${a(c)}}
|
|
88
|
+
sampleText={${a(n)}}
|
|
38
89
|
/>
|
|
39
90
|
);
|
|
40
91
|
}
|
|
41
|
-
`}function
|
|
92
|
+
`}function d(e){return`import type { CSSProperties, ReactElement } from "react";
|
|
42
93
|
|
|
43
94
|
export interface TokenTableRow {
|
|
44
95
|
path: string;
|
|
@@ -50,12 +101,12 @@ export interface TokenTableRow {
|
|
|
50
101
|
}
|
|
51
102
|
|
|
52
103
|
const TOKENS: TokenTableRow[] = [
|
|
53
|
-
${e.map(e=>{let t=e.theme?
|
|
54
|
-
path: ${
|
|
55
|
-
type: ${e.type?
|
|
56
|
-
value: ${
|
|
57
|
-
cssVar: ${
|
|
58
|
-
description: ${e.description?
|
|
104
|
+
${e.map(e=>{let t=e.theme?a(e.theme):`undefined`;return` {
|
|
105
|
+
path: ${a(e.path)},
|
|
106
|
+
type: ${e.type?a(e.type):`undefined`},
|
|
107
|
+
value: ${a(e.cssValue)},
|
|
108
|
+
cssVar: ${a(e.cssVar)},
|
|
109
|
+
description: ${e.description?a(e.description):`undefined`},
|
|
59
110
|
theme: ${t}
|
|
60
111
|
}`}).join(`,
|
|
61
112
|
`)||``}
|
|
@@ -142,11 +193,11 @@ export function TokenTableBlock({
|
|
|
142
193
|
</table>
|
|
143
194
|
);
|
|
144
195
|
}
|
|
145
|
-
`}function
|
|
196
|
+
`}function f(e){let t=e.titlePrefix??`Design Tokens`,n=e.hasColors?`
|
|
146
197
|
## Colors
|
|
147
198
|
|
|
148
199
|
<ColorPaletteBlock />
|
|
149
|
-
`:``,
|
|
200
|
+
`:``,r=e.hasTypography?`
|
|
150
201
|
## Typography
|
|
151
202
|
|
|
152
203
|
<TypesetBlock />
|
|
@@ -155,32 +206,32 @@ import { ColorPaletteBlock } from "./blocks/ColorPalette";
|
|
|
155
206
|
import { TokenTableBlock } from "./blocks/TokenTable";
|
|
156
207
|
import { TypesetBlock } from "./blocks/Typeset";
|
|
157
208
|
|
|
158
|
-
<Meta title="${
|
|
209
|
+
<Meta title="${i(t)}/Overview" />
|
|
159
210
|
|
|
160
211
|
# ${t}
|
|
161
212
|
|
|
162
213
|
Design tokens generated by \`@razorwind/storybook\` for Storybook MDX docs.
|
|
163
|
-
${n}${
|
|
214
|
+
${n}${r}
|
|
164
215
|
## All tokens
|
|
165
216
|
|
|
166
217
|
<TokenTableBlock />
|
|
167
|
-
`}function
|
|
218
|
+
`}function p(e={}){return`import { Meta } from "@storybook/addon-docs/blocks";
|
|
168
219
|
import { ColorPaletteBlock } from "./blocks/ColorPalette";
|
|
169
220
|
|
|
170
|
-
<Meta title="${
|
|
221
|
+
<Meta title="${i(e.titlePrefix??`Design Tokens`)}/Colors" />
|
|
171
222
|
|
|
172
223
|
# Colors
|
|
173
224
|
|
|
174
225
|
<ColorPaletteBlock />
|
|
175
|
-
`}function
|
|
226
|
+
`}function m(e={}){return`import { Meta } from "@storybook/addon-docs/blocks";
|
|
176
227
|
import { TypesetBlock } from "./blocks/Typeset";
|
|
177
228
|
|
|
178
|
-
<Meta title="${
|
|
229
|
+
<Meta title="${i(e.titlePrefix??`Design Tokens`)}/Typography" />
|
|
179
230
|
|
|
180
231
|
# Typography
|
|
181
232
|
|
|
182
233
|
<TypesetBlock />
|
|
183
|
-
`}function
|
|
234
|
+
`}function h(e,t){let n=e[t];return typeof n==`string`?n:void 0}function g(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _(e){return`import { IconGallery, IconItem } from "@storybook/addon-docs/blocks";
|
|
184
235
|
|
|
185
236
|
/**
|
|
186
237
|
* Icons rendered with Storybook's IconGallery doc block.
|
|
@@ -190,30 +241,30 @@ import { TypesetBlock } from "./blocks/Typeset";
|
|
|
190
241
|
export function IconGalleryBlock() {
|
|
191
242
|
return (
|
|
192
243
|
<IconGallery>
|
|
193
|
-
${(
|
|
244
|
+
${(g(e)?Object.values(e).filter(g).toSorted((e,t)=>(h(e,`name`)??``).localeCompare(h(t,`name`)??``)):[]).map(e=>{let t=h(e,`name`)??`unknown`,n=(Array.isArray(e.files)?e.files:[]).find(e=>g(e)&&h(e,`type`)===`svg`&&typeof e.content==`string`),r=g(n)&&typeof n.content==`string`?`<span
|
|
194
245
|
style={{ display: "inline-flex", width: 24, height: 24 }}
|
|
195
|
-
dangerouslySetInnerHTML={{ __html: ${
|
|
196
|
-
/>`:`<code>${
|
|
197
|
-
${
|
|
246
|
+
dangerouslySetInnerHTML={{ __html: ${a(n.content)} }}
|
|
247
|
+
/>`:`<code>${i(t)}</code>`;return` <IconItem name={${a(t)}}>
|
|
248
|
+
${r}
|
|
198
249
|
</IconItem>`}).join(`
|
|
199
250
|
`)||` {/* No icons */}`}
|
|
200
251
|
</IconGallery>
|
|
201
252
|
);
|
|
202
253
|
}
|
|
203
|
-
`}function
|
|
254
|
+
`}function v(e={}){return`import { Meta } from "@storybook/addon-docs/blocks";
|
|
204
255
|
import { IconGalleryBlock } from "./blocks/IconGallery";
|
|
205
256
|
|
|
206
|
-
<Meta title="${
|
|
257
|
+
<Meta title="${i(e.titlePrefix??`Design Tokens`)}/Icons" />
|
|
207
258
|
|
|
208
259
|
# Icons
|
|
209
260
|
|
|
210
261
|
<IconGalleryBlock />
|
|
211
|
-
`}function
|
|
262
|
+
`}function y(){return`export { ColorPaletteBlock } from "./ColorPalette";
|
|
212
263
|
export { IconGalleryBlock } from "./IconGallery";
|
|
213
264
|
export { TokenTableBlock } from "./TokenTable";
|
|
214
265
|
export type { TokenTableBlockProps, TokenTableRow } from "./TokenTable";
|
|
215
266
|
export { TypesetBlock } from "./Typeset";
|
|
216
|
-
`}function
|
|
267
|
+
`}function b(e){return`import { create } from "storybook/theming";
|
|
217
268
|
|
|
218
269
|
/**
|
|
219
270
|
* Storybook UI theme generated by \`@razorwind/storybook\`.
|
|
@@ -221,7 +272,7 @@ export { TypesetBlock } from "./Typeset";
|
|
|
221
272
|
* @see https://storybook.js.org/docs/configure/user-interface/theming
|
|
222
273
|
*/
|
|
223
274
|
export default create({
|
|
224
|
-
${Object.entries(e).filter(([,e])=>e!==void 0).map(([e,t])=>` ${e}: ${
|
|
275
|
+
${Object.entries(e).filter(([,e])=>e!==void 0).map(([e,t])=>` ${e}: ${a(t)}`).join(`,
|
|
225
276
|
`)}
|
|
226
277
|
});
|
|
227
|
-
`}function
|
|
278
|
+
`}function x(e,n,r){return(0,t.createDocument)(e,n,{name:`razorwind-storybook`},r)}function S(e,t={}){let i=t.outputPath??`storybook/tokens`,a=r(e.tokens,t),s=a.some(e=>e.type===`color`),c=a.some(e=>e.type===`fontFamily`||e.type===`fontWeight`||e.type===`typography`||e.type===`dimension`&&/(?:font|type|text).*size|size.*(?:font|type|text)/i.test(e.path)),h=!t.skipIcons&&g(e.icons)&&Object.keys(e.icons).length>0,S={[(0,n.join)(i,`blocks/ColorPalette.tsx`)]:x((0,n.join)(i,`blocks/ColorPalette.tsx`),l(a,t),`tsx`),[(0,n.join)(i,`blocks/Typeset.tsx`)]:x((0,n.join)(i,`blocks/Typeset.tsx`),u(a,t),`tsx`),[(0,n.join)(i,`blocks/TokenTable.tsx`)]:x((0,n.join)(i,`blocks/TokenTable.tsx`),d(a),`tsx`),[(0,n.join)(i,`blocks/IconGallery.tsx`)]:x((0,n.join)(i,`blocks/IconGallery.tsx`),_(t.skipIcons?{}:e.icons),`tsx`),[(0,n.join)(i,`blocks/index.ts`)]:x((0,n.join)(i,`blocks/index.ts`),y(),`typescript`),[(0,n.join)(i,`Tokens.mdx`)]:x((0,n.join)(i,`Tokens.mdx`),f({titlePrefix:t.titlePrefix,hasColors:s,hasTypography:c}),`mdx`)};if(s&&(S[(0,n.join)(i,`Colors.mdx`)]=x((0,n.join)(i,`Colors.mdx`),p(t),`mdx`)),c&&(S[(0,n.join)(i,`Typography.mdx`)]=x((0,n.join)(i,`Typography.mdx`),m(t),`mdx`)),h&&(S[(0,n.join)(i,`Icons.mdx`)]=x((0,n.join)(i,`Icons.mdx`),v(t),`mdx`)),S[(0,n.join)(i,`tokens.json`)]=x((0,n.join)(i,`tokens.json`),`${JSON.stringify(a,null,2)}\n`,`json`),t.generateTheme){let r=t.generateTheme(e.tokens);if(typeof r==`object`&&r)for(let[e,t]of Object.entries(r))S[(0,n.join)(i,`theme-${e}.ts`)]=x((0,n.join)(i,`theme-${e}.ts`),b(t),`typescript`);else S[(0,n.join)(i,`theme.ts`)]=x((0,n.join)(i,`theme.ts`),b(r),`typescript`)}let C=Object.keys(S).filter(e=>e.startsWith((0,n.join)(i,`theme`))).map(e=>e.slice(i.length+1)),w=t.installGuide??o({outputPath:i,titlePrefix:t.titlePrefix,themeFiles:C.length>0?C:void 0}),T=(0,n.join)(i,`INSTALL.md`);return S[T]=x(T,w,`markdown`),S}var C=(0,e.definePlugin)(e=>({name:`storybook`,generate:async t=>S(t,e??{})}));exports.default=C,exports.flattenTokens=r,Object.defineProperty(exports,"formatTokenValue",{enumerable:!0,get:function(){return t.formatTokenValue}}),exports.generateTokenDocs=S,exports.renderInstallMd=o,exports.renderThemeFile=b,exports.resolveTokenSets=t.resolveTokenSets,Object.defineProperty(exports,"toCssVar",{enumerable:!0,get:function(){return t.toCssVar}});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TokenType, Tokens } from "@power-plant/dtcg-schema";
|
|
2
2
|
import { Schema, Tokens as Tokens$1 } from "@razorwind/core/schema";
|
|
3
|
-
import { formatTokenValue, toCssVar } from "@razorwind/core/utils";
|
|
3
|
+
import { formatTokenValue, resolveTokenSets, toCssVar } from "@razorwind/core/utils";
|
|
4
4
|
import { GeneratorFunctionResult } from "@power-plant/core";
|
|
5
5
|
//#region src/types.d.ts
|
|
6
6
|
/**
|
|
@@ -122,25 +122,31 @@ interface StorybookPluginOptions {
|
|
|
122
122
|
* @defaultValue `false`
|
|
123
123
|
*/
|
|
124
124
|
skipIcons?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Override body for generated `INSTALL.md`. When omitted, Storybook wiring
|
|
127
|
+
* steps are generated for the output directory.
|
|
128
|
+
*/
|
|
129
|
+
installGuide?: string;
|
|
125
130
|
}
|
|
126
131
|
//#endregion
|
|
127
132
|
//#region src/flatten.d.ts
|
|
128
|
-
interface TokenSet {
|
|
129
|
-
id: string;
|
|
130
|
-
tokens: Tokens$1;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Split `Schema.tokens` into one or more named token sets.
|
|
134
|
-
*
|
|
135
|
-
* A record whose keys all look like themes (`light`, `dark`, …) is treated as
|
|
136
|
-
* multi-theme input; otherwise the whole document is a single set.
|
|
137
|
-
*/
|
|
138
|
-
declare function resolveTokenSets(tokens: Tokens$1 | Record<string, Tokens$1>): TokenSet[];
|
|
139
133
|
/**
|
|
140
134
|
* Flatten DTCG token trees into documentation rows.
|
|
141
135
|
*/
|
|
142
136
|
declare function flattenTokens(tokens: Tokens$1 | Record<string, Tokens$1>, options?: Pick<StorybookPluginOptions, "cssVarPrefix" | "includeTypes">): FlatToken[];
|
|
143
137
|
//#endregion
|
|
138
|
+
//#region src/install.d.ts
|
|
139
|
+
/**
|
|
140
|
+
* Build Storybook INSTALL.md for generated token docs.
|
|
141
|
+
*
|
|
142
|
+
* @see https://storybook.js.org/docs/writing-docs/mdx
|
|
143
|
+
*/
|
|
144
|
+
declare function renderInstallMd(options: {
|
|
145
|
+
outputPath: string;
|
|
146
|
+
titlePrefix?: string;
|
|
147
|
+
themeFiles?: string[];
|
|
148
|
+
}): string;
|
|
149
|
+
//#endregion
|
|
144
150
|
//#region src/generate.d.ts
|
|
145
151
|
/**
|
|
146
152
|
* Serialize a Storybook theme object as a `storybook/theming` `create()` module.
|
|
@@ -182,5 +188,5 @@ declare function generateTokenDocs(spec: Schema, options?: StorybookPluginOption
|
|
|
182
188
|
*/
|
|
183
189
|
declare const _default: (options?: StorybookPluginOptions | undefined) => import("@razorwind/core/plugin").Plugin;
|
|
184
190
|
//#endregion
|
|
185
|
-
export { type FlatToken, type GenerateStorybookTheme, type StorybookPluginOptions, type StorybookTheme, _default as default, flattenTokens, formatTokenValue, generateTokenDocs, renderThemeFile, resolveTokenSets, toCssVar };
|
|
191
|
+
export { type FlatToken, type GenerateStorybookTheme, type StorybookPluginOptions, type StorybookTheme, _default as default, flattenTokens, formatTokenValue, generateTokenDocs, renderInstallMd, renderThemeFile, resolveTokenSets, toCssVar };
|
|
186
192
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/flatten.ts","../src/generate.ts","../src/index.ts"],"mappings":";;;;;;;;UAuBiB;;EAEf;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;UAQe;;EAEf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU,uBACV,iBAAiB,eAAe;;;;;;KAOtB,0BACV,QAAQ,SAAS,eAAe,YAC7B;;;;UAKY;;;;;;EAMf;;;;;;EAOA;;;;;;EAOA;;;;;;EAOA;;;;;EAMA,eAAe;;;;;;EAOf;;;;;;;;;EAUA,gBAAgB;;;;;;EAOhB
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/flatten.ts","../src/install.ts","../src/generate.ts","../src/index.ts"],"mappings":";;;;;;;;UAuBiB;;EAEf;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;UAQe;;EAEf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU,uBACV,iBAAiB,eAAe;;;;;;KAOtB,0BACV,QAAQ,SAAS,eAAe,YAC7B;;;;UAKY;;;;;;EAMf;;;;;;EAOA;;;;;;EAOA;;;;;;EAOA;;;;;EAMA,eAAe;;;;;;EAOf;;;;;;;;;EAUA,gBAAgB;;;;;;EAOhB;;;;;EAMA;;;;;;;iBC7Hc,cACd,QAAQ,WAAS,eAAe,WAChC,UAAS,KAAK,2DACb;;;;;;;;iBCba,gBAAgB;EAC9B;EACA;EACA;;;;;;;;;iBCybc,gBAAgB,OAAO;;;;iBAqCvB,kBACd,MAAM,QACN,UAAS,yBACR,wBAAwB,QAAQ"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatTokenValue, toCssVar } from "@razorwind/core/utils";
|
|
1
|
+
import { formatTokenValue, resolveTokenSets, toCssVar } from "@razorwind/core/utils";
|
|
2
2
|
import { TokenType, Tokens } from "@power-plant/dtcg-schema";
|
|
3
3
|
import { Schema, Tokens as Tokens$1 } from "@razorwind/core/schema";
|
|
4
4
|
import { GeneratorFunctionResult } from "@power-plant/core";
|
|
@@ -122,25 +122,31 @@ interface StorybookPluginOptions {
|
|
|
122
122
|
* @defaultValue `false`
|
|
123
123
|
*/
|
|
124
124
|
skipIcons?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Override body for generated `INSTALL.md`. When omitted, Storybook wiring
|
|
127
|
+
* steps are generated for the output directory.
|
|
128
|
+
*/
|
|
129
|
+
installGuide?: string;
|
|
125
130
|
}
|
|
126
131
|
//#endregion
|
|
127
132
|
//#region src/flatten.d.ts
|
|
128
|
-
interface TokenSet {
|
|
129
|
-
id: string;
|
|
130
|
-
tokens: Tokens$1;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Split `Schema.tokens` into one or more named token sets.
|
|
134
|
-
*
|
|
135
|
-
* A record whose keys all look like themes (`light`, `dark`, …) is treated as
|
|
136
|
-
* multi-theme input; otherwise the whole document is a single set.
|
|
137
|
-
*/
|
|
138
|
-
declare function resolveTokenSets(tokens: Tokens$1 | Record<string, Tokens$1>): TokenSet[];
|
|
139
133
|
/**
|
|
140
134
|
* Flatten DTCG token trees into documentation rows.
|
|
141
135
|
*/
|
|
142
136
|
declare function flattenTokens(tokens: Tokens$1 | Record<string, Tokens$1>, options?: Pick<StorybookPluginOptions, "cssVarPrefix" | "includeTypes">): FlatToken[];
|
|
143
137
|
//#endregion
|
|
138
|
+
//#region src/install.d.ts
|
|
139
|
+
/**
|
|
140
|
+
* Build Storybook INSTALL.md for generated token docs.
|
|
141
|
+
*
|
|
142
|
+
* @see https://storybook.js.org/docs/writing-docs/mdx
|
|
143
|
+
*/
|
|
144
|
+
declare function renderInstallMd(options: {
|
|
145
|
+
outputPath: string;
|
|
146
|
+
titlePrefix?: string;
|
|
147
|
+
themeFiles?: string[];
|
|
148
|
+
}): string;
|
|
149
|
+
//#endregion
|
|
144
150
|
//#region src/generate.d.ts
|
|
145
151
|
/**
|
|
146
152
|
* Serialize a Storybook theme object as a `storybook/theming` `create()` module.
|
|
@@ -182,5 +188,5 @@ declare function generateTokenDocs(spec: Schema, options?: StorybookPluginOption
|
|
|
182
188
|
*/
|
|
183
189
|
declare const _default: (options?: StorybookPluginOptions | undefined) => import("@razorwind/core/plugin").Plugin;
|
|
184
190
|
//#endregion
|
|
185
|
-
export { type FlatToken, type GenerateStorybookTheme, type StorybookPluginOptions, type StorybookTheme, _default as default, flattenTokens, formatTokenValue, generateTokenDocs, renderThemeFile, resolveTokenSets, toCssVar };
|
|
191
|
+
export { type FlatToken, type GenerateStorybookTheme, type StorybookPluginOptions, type StorybookTheme, _default as default, flattenTokens, formatTokenValue, generateTokenDocs, renderInstallMd, renderThemeFile, resolveTokenSets, toCssVar };
|
|
186
192
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/flatten.ts","../src/generate.ts","../src/index.ts"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/flatten.ts","../src/install.ts","../src/generate.ts","../src/index.ts"],"mappings":""}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
|
-
import{definePlugin as e}from"@razorwind/core/plugin";import{createDocument as t,
|
|
2
|
-
`,`\\n`).replaceAll(`\r`,`\\r`)}function
|
|
1
|
+
import{definePlugin as e}from"@razorwind/core/plugin";import{createDocument as t,flattenTokens as n,formatTokenValue as r,resolveTokenSets as i,toCssVar as a,toCssVar as o}from"@razorwind/core/utils";import{join as s}from"node:path";function c(e,t={}){let r=t.cssVarPrefix??`rw`;return n(e,{includeTypes:t.includeTypes,enrichToken:e=>({...e,cssVar:o(e.path,r)})})}function l(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).replaceAll(`
|
|
2
|
+
`,`\\n`).replaceAll(`\r`,`\\r`)}function u(e){return typeof e==`string`?`"${l(e)}"`:typeof e==`number`||typeof e==`boolean`?String(e):e==null?`undefined`:JSON.stringify(e)}function d(e){let t=e.titlePrefix??`Design Tokens`,n=e.themeFiles&&e.themeFiles.length>0?`
|
|
3
|
+
## Storybook UI theme
|
|
4
|
+
|
|
5
|
+
Generated theme module(s):
|
|
6
|
+
|
|
7
|
+
${e.themeFiles.map(e=>`- \`${e}\``).join(`
|
|
8
|
+
`)}
|
|
9
|
+
|
|
10
|
+
Wire into \`.storybook/preview.ts\`:
|
|
11
|
+
|
|
12
|
+
\`\`\`ts
|
|
13
|
+
import theme from "../${e.themeFiles[0]}";
|
|
14
|
+
|
|
15
|
+
export const parameters = {
|
|
16
|
+
docs: { theme }
|
|
17
|
+
};
|
|
18
|
+
\`\`\`
|
|
19
|
+
`:``;return`# Installing Storybook Token Docs
|
|
20
|
+
|
|
21
|
+
Generated by \`@razorwind/storybook\`.
|
|
22
|
+
|
|
23
|
+
## Files
|
|
24
|
+
|
|
25
|
+
- \`${e.outputPath}/Tokens.mdx\` — token overview (${t})
|
|
26
|
+
- \`${e.outputPath}/blocks/\` — React doc blocks (ColorPalette, Typeset, …)
|
|
27
|
+
- \`${e.outputPath}/tokens.json\` — flattened token manifest
|
|
28
|
+
${n}
|
|
29
|
+
## Setup
|
|
30
|
+
|
|
31
|
+
1. Add the generated MDX pages to Storybook (paths depend on your \`stories\` config):
|
|
32
|
+
|
|
33
|
+
\`\`\`ts
|
|
34
|
+
// .storybook/main.ts
|
|
35
|
+
export default {
|
|
36
|
+
stories: [
|
|
37
|
+
"../${e.outputPath}/**/*.mdx"
|
|
38
|
+
]
|
|
39
|
+
};
|
|
40
|
+
\`\`\`
|
|
41
|
+
|
|
42
|
+
2. Import doc blocks in MDX as needed:
|
|
43
|
+
|
|
44
|
+
\`\`\`mdx
|
|
45
|
+
import { ColorPaletteBlock } from "./blocks";
|
|
46
|
+
\`\`\`
|
|
47
|
+
|
|
48
|
+
3. Start Storybook and open **${t}** in the sidebar.
|
|
49
|
+
|
|
50
|
+
## Regenerate
|
|
51
|
+
|
|
52
|
+
Re-run Razorwind generate when tokens change to refresh docs under \`${e.outputPath}/\`.
|
|
53
|
+
`}function f(e,t){let n=new Map;for(let r of e){let e=r.path.split(`.`).slice(0,Math.max(t,1)).join(`.`)||r.path,i=n.get(e)??[];i.push(r),n.set(e,i)}return n}function p(e,t){return e===t?e.split(`.`).at(-1)??e:e.startsWith(`${t}.`)?e.slice(t.length+1):e.split(`.`).at(-1)??e}function m(e,t={}){return`import { ColorPalette, ColorItem } from "@storybook/addon-docs/blocks";
|
|
3
54
|
|
|
4
55
|
/**
|
|
5
56
|
* Color tokens rendered with Storybook's ColorPalette doc block.
|
|
@@ -9,10 +60,10 @@ import{definePlugin as e}from"@razorwind/core/plugin";import{createDocument as t
|
|
|
9
60
|
export function ColorPaletteBlock() {
|
|
10
61
|
return (
|
|
11
62
|
<ColorPalette>
|
|
12
|
-
${[...
|
|
63
|
+
${[...f(e.filter(e=>e.type===`color`),t.colorGroupBy??2).entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>{let n=t.map(t=>` ${u(p(t.path,e))}: ${u(t.cssValue)}`).join(`,
|
|
13
64
|
`),r=t.find(e=>e.description)?.description??`${t.length} token${t.length===1?``:`s`}`;return` <ColorItem
|
|
14
|
-
title={${
|
|
15
|
-
subtitle={${
|
|
65
|
+
title={${u(e)}}
|
|
66
|
+
subtitle={${u(r)}}
|
|
16
67
|
colors={{
|
|
17
68
|
${n}
|
|
18
69
|
}}
|
|
@@ -21,7 +72,7 @@ ${n}
|
|
|
21
72
|
</ColorPalette>
|
|
22
73
|
);
|
|
23
74
|
}
|
|
24
|
-
`}function
|
|
75
|
+
`}function h(e,t={}){let n=t.sampleText??`The quick brown fox jumps over the lazy dog`,r=e.filter(e=>e.type===`dimension`&&/(?:font|type|text).*size|size.*(?:font|type|text)/i.test(e.path)).map(e=>{let t=/^(\d+(?:\.\d+)?)/.exec(e.cssValue);return t?Number(t[1]):e.cssValue}),i=[...new Set(r)],a=e.find(e=>e.type===`fontFamily`)?.cssValue??`system-ui, sans-serif`,o=e.find(e=>e.type===`fontWeight`),s=o&&Number.parseFloat(o.cssValue)||400,c=i.length>0?`[${i.map(e=>u(e)).join(`, `)}]`:`[12, 14, 16, 20, 24, 32]`;return`import { Typeset } from "@storybook/addon-docs/blocks";
|
|
25
76
|
|
|
26
77
|
/**
|
|
27
78
|
* Typography tokens rendered with Storybook's Typeset doc block.
|
|
@@ -31,14 +82,14 @@ ${n}
|
|
|
31
82
|
export function TypesetBlock() {
|
|
32
83
|
return (
|
|
33
84
|
<Typeset
|
|
34
|
-
fontFamily={${
|
|
35
|
-
fontSizes={${
|
|
36
|
-
fontWeight={${s
|
|
37
|
-
sampleText={${
|
|
85
|
+
fontFamily={${u(a)}}
|
|
86
|
+
fontSizes={${c}}
|
|
87
|
+
fontWeight={${u(s)}}
|
|
88
|
+
sampleText={${u(n)}}
|
|
38
89
|
/>
|
|
39
90
|
);
|
|
40
91
|
}
|
|
41
|
-
`}function
|
|
92
|
+
`}function g(e){return`import type { CSSProperties, ReactElement } from "react";
|
|
42
93
|
|
|
43
94
|
export interface TokenTableRow {
|
|
44
95
|
path: string;
|
|
@@ -50,12 +101,12 @@ export interface TokenTableRow {
|
|
|
50
101
|
}
|
|
51
102
|
|
|
52
103
|
const TOKENS: TokenTableRow[] = [
|
|
53
|
-
${e.map(e=>{let t=e.theme?
|
|
54
|
-
path: ${
|
|
55
|
-
type: ${e.type?
|
|
56
|
-
value: ${
|
|
57
|
-
cssVar: ${
|
|
58
|
-
description: ${e.description?
|
|
104
|
+
${e.map(e=>{let t=e.theme?u(e.theme):`undefined`;return` {
|
|
105
|
+
path: ${u(e.path)},
|
|
106
|
+
type: ${e.type?u(e.type):`undefined`},
|
|
107
|
+
value: ${u(e.cssValue)},
|
|
108
|
+
cssVar: ${u(e.cssVar)},
|
|
109
|
+
description: ${e.description?u(e.description):`undefined`},
|
|
59
110
|
theme: ${t}
|
|
60
111
|
}`}).join(`,
|
|
61
112
|
`)||``}
|
|
@@ -142,7 +193,7 @@ export function TokenTableBlock({
|
|
|
142
193
|
</table>
|
|
143
194
|
);
|
|
144
195
|
}
|
|
145
|
-
`}function
|
|
196
|
+
`}function _(e){let t=e.titlePrefix??`Design Tokens`,n=e.hasColors?`
|
|
146
197
|
## Colors
|
|
147
198
|
|
|
148
199
|
<ColorPaletteBlock />
|
|
@@ -155,7 +206,7 @@ import { ColorPaletteBlock } from "./blocks/ColorPalette";
|
|
|
155
206
|
import { TokenTableBlock } from "./blocks/TokenTable";
|
|
156
207
|
import { TypesetBlock } from "./blocks/Typeset";
|
|
157
208
|
|
|
158
|
-
<Meta title="${
|
|
209
|
+
<Meta title="${l(t)}/Overview" />
|
|
159
210
|
|
|
160
211
|
# ${t}
|
|
161
212
|
|
|
@@ -164,23 +215,23 @@ ${n}${r}
|
|
|
164
215
|
## All tokens
|
|
165
216
|
|
|
166
217
|
<TokenTableBlock />
|
|
167
|
-
`}function
|
|
218
|
+
`}function v(e={}){return`import { Meta } from "@storybook/addon-docs/blocks";
|
|
168
219
|
import { ColorPaletteBlock } from "./blocks/ColorPalette";
|
|
169
220
|
|
|
170
|
-
<Meta title="${
|
|
221
|
+
<Meta title="${l(e.titlePrefix??`Design Tokens`)}/Colors" />
|
|
171
222
|
|
|
172
223
|
# Colors
|
|
173
224
|
|
|
174
225
|
<ColorPaletteBlock />
|
|
175
|
-
`}function
|
|
226
|
+
`}function y(e={}){return`import { Meta } from "@storybook/addon-docs/blocks";
|
|
176
227
|
import { TypesetBlock } from "./blocks/Typeset";
|
|
177
228
|
|
|
178
|
-
<Meta title="${
|
|
229
|
+
<Meta title="${l(e.titlePrefix??`Design Tokens`)}/Typography" />
|
|
179
230
|
|
|
180
231
|
# Typography
|
|
181
232
|
|
|
182
233
|
<TypesetBlock />
|
|
183
|
-
`}function
|
|
234
|
+
`}function b(e,t){let n=e[t];return typeof n==`string`?n:void 0}function x(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function S(e){return`import { IconGallery, IconItem } from "@storybook/addon-docs/blocks";
|
|
184
235
|
|
|
185
236
|
/**
|
|
186
237
|
* Icons rendered with Storybook's IconGallery doc block.
|
|
@@ -190,30 +241,30 @@ import { TypesetBlock } from "./blocks/Typeset";
|
|
|
190
241
|
export function IconGalleryBlock() {
|
|
191
242
|
return (
|
|
192
243
|
<IconGallery>
|
|
193
|
-
${(
|
|
244
|
+
${(x(e)?Object.values(e).filter(x).toSorted((e,t)=>(b(e,`name`)??``).localeCompare(b(t,`name`)??``)):[]).map(e=>{let t=b(e,`name`)??`unknown`,n=(Array.isArray(e.files)?e.files:[]).find(e=>x(e)&&b(e,`type`)===`svg`&&typeof e.content==`string`),r=x(n)&&typeof n.content==`string`?`<span
|
|
194
245
|
style={{ display: "inline-flex", width: 24, height: 24 }}
|
|
195
|
-
dangerouslySetInnerHTML={{ __html: ${
|
|
196
|
-
/>`:`<code>${
|
|
246
|
+
dangerouslySetInnerHTML={{ __html: ${u(n.content)} }}
|
|
247
|
+
/>`:`<code>${l(t)}</code>`;return` <IconItem name={${u(t)}}>
|
|
197
248
|
${r}
|
|
198
249
|
</IconItem>`}).join(`
|
|
199
250
|
`)||` {/* No icons */}`}
|
|
200
251
|
</IconGallery>
|
|
201
252
|
);
|
|
202
253
|
}
|
|
203
|
-
`}function
|
|
254
|
+
`}function C(e={}){return`import { Meta } from "@storybook/addon-docs/blocks";
|
|
204
255
|
import { IconGalleryBlock } from "./blocks/IconGallery";
|
|
205
256
|
|
|
206
|
-
<Meta title="${
|
|
257
|
+
<Meta title="${l(e.titlePrefix??`Design Tokens`)}/Icons" />
|
|
207
258
|
|
|
208
259
|
# Icons
|
|
209
260
|
|
|
210
261
|
<IconGalleryBlock />
|
|
211
|
-
`}function
|
|
262
|
+
`}function w(){return`export { ColorPaletteBlock } from "./ColorPalette";
|
|
212
263
|
export { IconGalleryBlock } from "./IconGallery";
|
|
213
264
|
export { TokenTableBlock } from "./TokenTable";
|
|
214
265
|
export type { TokenTableBlockProps, TokenTableRow } from "./TokenTable";
|
|
215
266
|
export { TypesetBlock } from "./Typeset";
|
|
216
|
-
`}function
|
|
267
|
+
`}function T(e){return`import { create } from "storybook/theming";
|
|
217
268
|
|
|
218
269
|
/**
|
|
219
270
|
* Storybook UI theme generated by \`@razorwind/storybook\`.
|
|
@@ -221,8 +272,8 @@ export { TypesetBlock } from "./Typeset";
|
|
|
221
272
|
* @see https://storybook.js.org/docs/configure/user-interface/theming
|
|
222
273
|
*/
|
|
223
274
|
export default create({
|
|
224
|
-
${Object.entries(e).filter(([,e])=>e!==void 0).map(([e,t])=>` ${e}: ${
|
|
275
|
+
${Object.entries(e).filter(([,e])=>e!==void 0).map(([e,t])=>` ${e}: ${u(t)}`).join(`,
|
|
225
276
|
`)}
|
|
226
277
|
});
|
|
227
|
-
`}function
|
|
278
|
+
`}function E(e,n,r){return t(e,n,{name:`razorwind-storybook`},r)}function D(e,t={}){let n=t.outputPath??`storybook/tokens`,r=c(e.tokens,t),i=r.some(e=>e.type===`color`),a=r.some(e=>e.type===`fontFamily`||e.type===`fontWeight`||e.type===`typography`||e.type===`dimension`&&/(?:font|type|text).*size|size.*(?:font|type|text)/i.test(e.path)),o=!t.skipIcons&&x(e.icons)&&Object.keys(e.icons).length>0,l={[s(n,`blocks/ColorPalette.tsx`)]:E(s(n,`blocks/ColorPalette.tsx`),m(r,t),`tsx`),[s(n,`blocks/Typeset.tsx`)]:E(s(n,`blocks/Typeset.tsx`),h(r,t),`tsx`),[s(n,`blocks/TokenTable.tsx`)]:E(s(n,`blocks/TokenTable.tsx`),g(r),`tsx`),[s(n,`blocks/IconGallery.tsx`)]:E(s(n,`blocks/IconGallery.tsx`),S(t.skipIcons?{}:e.icons),`tsx`),[s(n,`blocks/index.ts`)]:E(s(n,`blocks/index.ts`),w(),`typescript`),[s(n,`Tokens.mdx`)]:E(s(n,`Tokens.mdx`),_({titlePrefix:t.titlePrefix,hasColors:i,hasTypography:a}),`mdx`)};if(i&&(l[s(n,`Colors.mdx`)]=E(s(n,`Colors.mdx`),v(t),`mdx`)),a&&(l[s(n,`Typography.mdx`)]=E(s(n,`Typography.mdx`),y(t),`mdx`)),o&&(l[s(n,`Icons.mdx`)]=E(s(n,`Icons.mdx`),C(t),`mdx`)),l[s(n,`tokens.json`)]=E(s(n,`tokens.json`),`${JSON.stringify(r,null,2)}\n`,`json`),t.generateTheme){let r=t.generateTheme(e.tokens);if(typeof r==`object`&&r)for(let[e,t]of Object.entries(r))l[s(n,`theme-${e}.ts`)]=E(s(n,`theme-${e}.ts`),T(t),`typescript`);else l[s(n,`theme.ts`)]=E(s(n,`theme.ts`),T(r),`typescript`)}let u=Object.keys(l).filter(e=>e.startsWith(s(n,`theme`))).map(e=>e.slice(n.length+1)),f=t.installGuide??d({outputPath:n,titlePrefix:t.titlePrefix,themeFiles:u.length>0?u:void 0}),p=s(n,`INSTALL.md`);return l[p]=E(p,f,`markdown`),l}var O=e(e=>({name:`storybook`,generate:async t=>D(t,e??{})}));export{O as default,c as flattenTokens,r as formatTokenValue,D as generateTokenDocs,d as renderInstallMd,T as renderThemeFile,i as resolveTokenSets,a as toCssVar};
|
|
228
279
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@razorwind/storybook",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Razorwind plugin that creates Storybook MDX token doc blocks from Razorwind design tokens.",
|
|
6
6
|
"repository": {
|
|
@@ -83,9 +83,9 @@
|
|
|
83
83
|
"types": "./dist/index.d.cts",
|
|
84
84
|
"typings": "dist/index.d.mts",
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@power-plant/core": "^0.0.
|
|
86
|
+
"@power-plant/core": "^0.0.81",
|
|
87
87
|
"@power-plant/dtcg-schema": "^0.0.1",
|
|
88
|
-
"@razorwind/core": "0.0.
|
|
88
|
+
"@razorwind/core": "^0.0.30",
|
|
89
89
|
"@stryke/type-checks": "^0.6.35"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
@@ -99,10 +99,10 @@
|
|
|
99
99
|
"storybook": { "optional": true }
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
|
-
"@powerlines/plugin-tsdown": "^0.1.
|
|
102
|
+
"@powerlines/plugin-tsdown": "^0.1.590",
|
|
103
103
|
"@types/node": "^25.9.5",
|
|
104
104
|
"typescript": "^6.0.3"
|
|
105
105
|
},
|
|
106
106
|
"publishConfig": { "access": "public" },
|
|
107
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "11a6e827627acf51ef0044e366fd9493f2173ec2"
|
|
108
108
|
}
|