@razorwind/design-md 0.0.4 → 0.0.6

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.
@@ -0,0 +1 @@
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./rolldown-runtime-BIInC43l.cjs");let t=require("@power-plant/core"),n=require("@razorwind/core/plugin"),r=require("@razorwind/core/tokens"),i=require("@razorwind/core/utils"),a=require("@stryke/fs/exists"),o=require("@stryke/fs/read-file"),s=require("@stryke/path/join"),c=require("@stryke/type-checks/is-empty-object"),l=require("yaml");var u=e.t({DESIGN_MD_FILE_PATTERN:()=>d,DESIGN_MD_PATH_CANDIDATES:()=>f,default:()=>A,designMdToTokens:()=>T,extractDesignMdFrontMatter:()=>w,isDesignMdFile:()=>D,loadDesignMdTokens:()=>k,parseDesignMdTokens:()=>E,resolveDesignMdPath:()=>O});const d=/(?:^|[/\\])design\.md$/i,f=[`DESIGN.md`,`design.md`,`docs/DESIGN.md`],p=/^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,m=/^\{[^{}]+\}$/,h=new Set([`version`,`name`,`description`]),g=[`fontFamily`,`fontSize`,`fontWeight`,`lineHeight`,`letterSpacing`,`fontFeature`,`fontVariation`],_={backgroundColor:`color`,textColor:`color`,typography:`typography`,rounded:`dimension`,padding:`dimension`,size:`dimension`,height:`dimension`,width:`dimension`};function v(e){return typeof e==`string`&&m.test(e.trim())}function y(e){return typeof e==`number`?`${e}px`:e}function b(e){let t={};for(let n of g){let r=e[n];r!=null&&(t[n]=r)}for(let[n,r]of Object.entries(e))!(n in t)&&r!=null&&(typeof r==`string`||typeof r==`number`)&&(t[n]=r);return t}function x(e,t,n=!1){let r={};for(let[i,a]of Object.entries(e))a!=null&&(r[i]={$type:t,$value:v(a)?a.trim():n?y(a):a});return r}function S(e){let t={};for(let[n,r]of Object.entries(e))v(r)?t[n]={$type:`typography`,$value:r.trim()}:(0,i.isObject)(r)&&(t[n]={$type:`typography`,$value:b(r)});return t}function C(e){let t={};for(let[n,r]of Object.entries(e)){if(!(0,i.isObject)(r))continue;let e={};for(let[t,n]of Object.entries(r)){if(n==null)continue;let r=_[t];e[t]={...r?{$type:r}:{},$value:v(n)?n.trim():r===`typography`&&(0,i.isObject)(n)?b(n):y(n)}}Object.keys(e).length>0&&(t[n]=e)}return t}function w(e){let t=p.exec(e);if(!t?.[1])return;let n;try{n=(0,l.parse)(t[1])}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Failed to parse DESIGN.md front matter as YAML: ${t}`)}return(0,i.isObject)(n)?n:void 0}function T(e){let t={};for(let[n,r]of Object.entries(e))if(!(h.has(n)||!(0,i.isObject)(r)))switch(n){case`colors`:t[n]=x(r,`color`);break;case`typography`:t[n]=S(r);break;case`rounded`:case`spacing`:t[n]=x(r,`dimension`,!0);break;case`components`:t[n]=C(r);break;default:t[n]=r;break}return(0,r.normalizeTokenTree)(t)}function E(e){let t=w(e);return t?T(t):{}}function D(e){return d.test(e)}function O(e){for(let t of f){let n=(0,s.joinPaths)(e,t);if((0,a.existsSync)(n))return n}}async function k(e){let t=O(e);if(t)return E(await(0,o.readFile)(t))}var A=(0,n.definePlugin)((e={})=>({name:`design-md:extract`,parsers:[{name:`design-md`,pattern:d,parser:e=>E(e)}],extract:async n=>{if(n.tokens&&!(0,c.isEmptyObject)(n.tokens))return n;let r=e.path;if(!r){let{cwd:e}=(0,t.useExecution)();if(r=O(e),!r)return n}let i=E(await(0,o.readFile)(r));return!i||(0,c.isEmptyObject)(i)?n:{...n,tokens:i}}}));exports.DESIGN_MD_FILE_PATTERN=d,exports.DESIGN_MD_PATH_CANDIDATES=f,exports.default=A,exports.designMdToTokens=T,exports.extractDesignMdFrontMatter=w,exports.isDesignMdFile=D,exports.loadDesignMdTokens=k,exports.parseDesignMdTokens=E,exports.resolveDesignMdPath=O,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return u}});
@@ -0,0 +1,81 @@
1
+ import { DesignTokens } from "style-dictionary/types";
2
+ declare namespace extract_d_exports {
3
+ export { DESIGN_MD_FILE_PATTERN, DESIGN_MD_PATH_CANDIDATES, _default as default, designMdToTokens, extractDesignMdFrontMatter, isDesignMdFile, loadDesignMdTokens, parseDesignMdTokens, resolveDesignMdPath };
4
+ }
5
+ /**
6
+ * Basename pattern for DESIGN.md spec files
7
+ * (https://github.com/google-labs-code/design.md).
8
+ */
9
+ declare const DESIGN_MD_FILE_PATTERN: RegExp;
10
+ /** Candidate workspace paths checked for a DESIGN.md spec file. */
11
+ declare const DESIGN_MD_PATH_CANDIDATES: readonly ["DESIGN.md", "design.md", "docs/DESIGN.md"];
12
+ /**
13
+ * Extract the YAML front matter object from DESIGN.md contents.
14
+ *
15
+ * @param contents - The raw DESIGN.md file contents.
16
+ * @returns The parsed front matter, or `undefined` when no front matter fence
17
+ * is present.
18
+ */
19
+ declare function extractDesignMdFrontMatter(contents: string): Record<string, unknown> | undefined;
20
+ /**
21
+ * Convert DESIGN.md front-matter tokens (colors, typography, rounded,
22
+ * spacing, components) into a DTCG design-token tree.
23
+ *
24
+ * DESIGN.md `{path.to.token}` references are preserved verbatim — the group
25
+ * names in the emitted tree match the front-matter section names, so the
26
+ * references resolve as DTCG aliases without rewriting.
27
+ *
28
+ * @see https://github.com/google-labs-code/design.md#the-specification
29
+ *
30
+ * @param frontMatter - The parsed DESIGN.md YAML front matter.
31
+ * @returns The equivalent DTCG token tree.
32
+ */
33
+ declare function designMdToTokens(frontMatter: Record<string, unknown>): DesignTokens;
34
+ /**
35
+ * Parse DESIGN.md file contents into a DTCG token tree.
36
+ *
37
+ * @param contents - The raw DESIGN.md file contents.
38
+ * @returns The extracted tokens; an empty object when the file has no YAML
39
+ * front matter.
40
+ */
41
+ declare function parseDesignMdTokens(contents: string): DesignTokens;
42
+ /**
43
+ * Check whether a path points at a DESIGN.md spec file.
44
+ *
45
+ * @param filePath - The file path to test.
46
+ * @returns True when the basename is `DESIGN.md` (case-insensitive).
47
+ */
48
+ declare function isDesignMdFile(filePath: string): boolean;
49
+ /**
50
+ * Resolve the DESIGN.md file for a workspace, if one exists.
51
+ *
52
+ * @param cwd - The workspace root to search from.
53
+ * @returns The absolute path to the first matching candidate, or `undefined`.
54
+ */
55
+ declare function resolveDesignMdPath(cwd: string): string | undefined;
56
+ /**
57
+ * Load DTCG tokens from the DESIGN.md file in a workspace, if present.
58
+ *
59
+ * @param cwd - The workspace root to search from.
60
+ * @returns Parsed tokens, or `undefined` when no DESIGN.md exists.
61
+ */
62
+ declare function loadDesignMdTokens(cwd: string): Promise<DesignTokens | undefined>;
63
+ /**
64
+ * Extract design-system specification from DESIGN.md
65
+ *
66
+ * @see https://github.com/google-labs-code/design.md
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import { defineConfig } from "@razorwind/core";
71
+ * import designMd from "@razorwind/design-md/extract";
72
+ *
73
+ * export default defineConfig({
74
+ * plugins: [designMd()]
75
+ * });
76
+ * ```
77
+ */
78
+ declare const _default: (options: any) => import("@razorwind/core/plugin").Plugin;
79
+ //#endregion
80
+ export { DESIGN_MD_FILE_PATTERN, DESIGN_MD_PATH_CANDIDATES, _default as default, designMdToTokens, extractDesignMdFrontMatter, isDesignMdFile, loadDesignMdTokens, parseDesignMdTokens, resolveDesignMdPath, extract_d_exports as t };
81
+ //# sourceMappingURL=extract.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;cAkCa,wBAAsB;;cAGtB;;;;;;;;iBA6KG,2BACd,mBACC;;;;;;;;;;;;;;iBAgCa,iBACd,aAAa,0BACZ;;;;;;;;iBAwCa,oBAAoB,mBAAmB;;;;;;;iBAevC,eAAe;;;;;;;iBAUf,oBAAoB;;;;;;;iBAiBd,mBACpB,cACC,QAAQ"}
@@ -0,0 +1,81 @@
1
+ import { DesignTokens } from "style-dictionary/types";
2
+ declare namespace extract_d_exports {
3
+ export { DESIGN_MD_FILE_PATTERN, DESIGN_MD_PATH_CANDIDATES, _default as default, designMdToTokens, extractDesignMdFrontMatter, isDesignMdFile, loadDesignMdTokens, parseDesignMdTokens, resolveDesignMdPath };
4
+ }
5
+ /**
6
+ * Basename pattern for DESIGN.md spec files
7
+ * (https://github.com/google-labs-code/design.md).
8
+ */
9
+ declare const DESIGN_MD_FILE_PATTERN: RegExp;
10
+ /** Candidate workspace paths checked for a DESIGN.md spec file. */
11
+ declare const DESIGN_MD_PATH_CANDIDATES: readonly ["DESIGN.md", "design.md", "docs/DESIGN.md"];
12
+ /**
13
+ * Extract the YAML front matter object from DESIGN.md contents.
14
+ *
15
+ * @param contents - The raw DESIGN.md file contents.
16
+ * @returns The parsed front matter, or `undefined` when no front matter fence
17
+ * is present.
18
+ */
19
+ declare function extractDesignMdFrontMatter(contents: string): Record<string, unknown> | undefined;
20
+ /**
21
+ * Convert DESIGN.md front-matter tokens (colors, typography, rounded,
22
+ * spacing, components) into a DTCG design-token tree.
23
+ *
24
+ * DESIGN.md `{path.to.token}` references are preserved verbatim — the group
25
+ * names in the emitted tree match the front-matter section names, so the
26
+ * references resolve as DTCG aliases without rewriting.
27
+ *
28
+ * @see https://github.com/google-labs-code/design.md#the-specification
29
+ *
30
+ * @param frontMatter - The parsed DESIGN.md YAML front matter.
31
+ * @returns The equivalent DTCG token tree.
32
+ */
33
+ declare function designMdToTokens(frontMatter: Record<string, unknown>): DesignTokens;
34
+ /**
35
+ * Parse DESIGN.md file contents into a DTCG token tree.
36
+ *
37
+ * @param contents - The raw DESIGN.md file contents.
38
+ * @returns The extracted tokens; an empty object when the file has no YAML
39
+ * front matter.
40
+ */
41
+ declare function parseDesignMdTokens(contents: string): DesignTokens;
42
+ /**
43
+ * Check whether a path points at a DESIGN.md spec file.
44
+ *
45
+ * @param filePath - The file path to test.
46
+ * @returns True when the basename is `DESIGN.md` (case-insensitive).
47
+ */
48
+ declare function isDesignMdFile(filePath: string): boolean;
49
+ /**
50
+ * Resolve the DESIGN.md file for a workspace, if one exists.
51
+ *
52
+ * @param cwd - The workspace root to search from.
53
+ * @returns The absolute path to the first matching candidate, or `undefined`.
54
+ */
55
+ declare function resolveDesignMdPath(cwd: string): string | undefined;
56
+ /**
57
+ * Load DTCG tokens from the DESIGN.md file in a workspace, if present.
58
+ *
59
+ * @param cwd - The workspace root to search from.
60
+ * @returns Parsed tokens, or `undefined` when no DESIGN.md exists.
61
+ */
62
+ declare function loadDesignMdTokens(cwd: string): Promise<DesignTokens | undefined>;
63
+ /**
64
+ * Extract design-system specification from DESIGN.md
65
+ *
66
+ * @see https://github.com/google-labs-code/design.md
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import { defineConfig } from "@razorwind/core";
71
+ * import designMd from "@razorwind/design-md/extract";
72
+ *
73
+ * export default defineConfig({
74
+ * plugins: [designMd()]
75
+ * });
76
+ * ```
77
+ */
78
+ declare const _default: (options: any) => import("@razorwind/core/plugin").Plugin;
79
+ //#endregion
80
+ export { DESIGN_MD_FILE_PATTERN, DESIGN_MD_PATH_CANDIDATES, _default as default, designMdToTokens, extractDesignMdFrontMatter, isDesignMdFile, loadDesignMdTokens, parseDesignMdTokens, resolveDesignMdPath, extract_d_exports as t };
81
+ //# sourceMappingURL=extract.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./rolldown-runtime-DK3Fl9T5.mjs";import{useExecution as t}from"@power-plant/core";import{definePlugin as n}from"@razorwind/core/plugin";import{normalizeTokenTree as r}from"@razorwind/core/tokens";import{isObject as i}from"@razorwind/core/utils";import{existsSync as a}from"@stryke/fs/exists";import{readFile as o}from"@stryke/fs/read-file";import{joinPaths as s}from"@stryke/path/join";import{isEmptyObject as c}from"@stryke/type-checks/is-empty-object";import{parse as l}from"yaml";var u=e({DESIGN_MD_FILE_PATTERN:()=>d,DESIGN_MD_PATH_CANDIDATES:()=>f,default:()=>A,designMdToTokens:()=>T,extractDesignMdFrontMatter:()=>w,isDesignMdFile:()=>D,loadDesignMdTokens:()=>k,parseDesignMdTokens:()=>E,resolveDesignMdPath:()=>O});const d=/(?:^|[/\\])design\.md$/i,f=[`DESIGN.md`,`design.md`,`docs/DESIGN.md`],p=/^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,m=/^\{[^{}]+\}$/,h=new Set([`version`,`name`,`description`]),g=[`fontFamily`,`fontSize`,`fontWeight`,`lineHeight`,`letterSpacing`,`fontFeature`,`fontVariation`],_={backgroundColor:`color`,textColor:`color`,typography:`typography`,rounded:`dimension`,padding:`dimension`,size:`dimension`,height:`dimension`,width:`dimension`};function v(e){return typeof e==`string`&&m.test(e.trim())}function y(e){return typeof e==`number`?`${e}px`:e}function b(e){let t={};for(let n of g){let r=e[n];r!=null&&(t[n]=r)}for(let[n,r]of Object.entries(e))!(n in t)&&r!=null&&(typeof r==`string`||typeof r==`number`)&&(t[n]=r);return t}function x(e,t,n=!1){let r={};for(let[i,a]of Object.entries(e))a!=null&&(r[i]={$type:t,$value:v(a)?a.trim():n?y(a):a});return r}function S(e){let t={};for(let[n,r]of Object.entries(e))v(r)?t[n]={$type:`typography`,$value:r.trim()}:i(r)&&(t[n]={$type:`typography`,$value:b(r)});return t}function C(e){let t={};for(let[n,r]of Object.entries(e)){if(!i(r))continue;let e={};for(let[t,n]of Object.entries(r)){if(n==null)continue;let r=_[t];e[t]={...r?{$type:r}:{},$value:v(n)?n.trim():r===`typography`&&i(n)?b(n):y(n)}}Object.keys(e).length>0&&(t[n]=e)}return t}function w(e){let t=p.exec(e);if(!t?.[1])return;let n;try{n=l(t[1])}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Failed to parse DESIGN.md front matter as YAML: ${t}`)}return i(n)?n:void 0}function T(e){let t={};for(let[n,r]of Object.entries(e))if(!(h.has(n)||!i(r)))switch(n){case`colors`:t[n]=x(r,`color`);break;case`typography`:t[n]=S(r);break;case`rounded`:case`spacing`:t[n]=x(r,`dimension`,!0);break;case`components`:t[n]=C(r);break;default:t[n]=r;break}return r(t)}function E(e){let t=w(e);return t?T(t):{}}function D(e){return d.test(e)}function O(e){for(let t of f){let n=s(e,t);if(a(n))return n}}async function k(e){let t=O(e);if(t)return E(await o(t))}var A=n((e={})=>({name:`design-md:extract`,parsers:[{name:`design-md`,pattern:d,parser:e=>E(e)}],extract:async n=>{if(n.tokens&&!c(n.tokens))return n;let r=e.path;if(!r){let{cwd:e}=t();if(r=O(e),!r)return n}let i=E(await o(r));return!i||c(i)?n:{...n,tokens:i}}}));export{d as DESIGN_MD_FILE_PATTERN,f as DESIGN_MD_PATH_CANDIDATES,A as default,T as designMdToTokens,w as extractDesignMdFrontMatter,D as isDesignMdFile,k as loadDesignMdTokens,E as parseDesignMdTokens,O as resolveDesignMdPath,u as t};
2
+ //# sourceMappingURL=extract.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.mjs","names":[],"sources":[],"mappings":""}
@@ -0,0 +1,47 @@
1
+ import { TokenType } from "@power-plant/dtcg-schema";
2
+ //#region src/types.d.ts
3
+ /**
4
+ * A flattened design token ready for DESIGN.md extraction.
5
+ */
6
+ interface FlatToken {
7
+ /** Dot-separated token path (e.g. `color.primary`). */
8
+ path: string;
9
+ /** DTCG `$type`, when known. */
10
+ type?: TokenType | string;
11
+ /** Raw `$value` from the token document. */
12
+ value: unknown;
13
+ /** CSS-friendly string form of {@link value}. */
14
+ cssValue: string;
15
+ /** Optional DTCG `$description`. */
16
+ description?: string;
17
+ /** Theme / set id when tokens are a `Record<string, Tokens>`. */
18
+ theme?: string;
19
+ }
20
+ declare namespace generate_d_exports {
21
+ export { _default as default, selectPrimaryTheme };
22
+ }
23
+ /**
24
+ * Select the token set used for the front matter when tokens are split into
25
+ * multiple themes: the un-themed set first, then `light`, then `default`,
26
+ * then whichever theme appears first.
27
+ */
28
+ declare function selectPrimaryTheme(flat: FlatToken[]): FlatToken[];
29
+ /**
30
+ * Generate a DESIGN.md design-system specification file from a Razorwind schema.
31
+ *
32
+ * @see https://github.com/google-labs-code/design.md
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { defineConfig } from "@razorwind/core";
37
+ * import designMd from "@razorwind/design-md/generate";
38
+ *
39
+ * export default defineConfig({
40
+ * plugins: [designMd()]
41
+ * });
42
+ * ```
43
+ */
44
+ declare const _default: (options: any) => import("@razorwind/core/plugin").Plugin;
45
+ //#endregion
46
+ export { generate_d_exports as n, selectPrimaryTheme as r, _default as t };
47
+ //# sourceMappingURL=generate-BPhbyvvs.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-BPhbyvvs.d.cts","names":[],"sources":["../src/types.ts","../src/generate.ts"],"mappings":";;;;;UAkEiB;;EAEf;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;EAEA;;;;;;;;;;iBCMc,mBAAmB,MAAM,cAAc"}
@@ -0,0 +1,47 @@
1
+ import { TokenType } from "@power-plant/dtcg-schema";
2
+ //#region src/types.d.ts
3
+ /**
4
+ * A flattened design token ready for DESIGN.md extraction.
5
+ */
6
+ interface FlatToken {
7
+ /** Dot-separated token path (e.g. `color.primary`). */
8
+ path: string;
9
+ /** DTCG `$type`, when known. */
10
+ type?: TokenType | string;
11
+ /** Raw `$value` from the token document. */
12
+ value: unknown;
13
+ /** CSS-friendly string form of {@link value}. */
14
+ cssValue: string;
15
+ /** Optional DTCG `$description`. */
16
+ description?: string;
17
+ /** Theme / set id when tokens are a `Record<string, Tokens>`. */
18
+ theme?: string;
19
+ }
20
+ declare namespace generate_d_exports {
21
+ export { _default as default, selectPrimaryTheme };
22
+ }
23
+ /**
24
+ * Select the token set used for the front matter when tokens are split into
25
+ * multiple themes: the un-themed set first, then `light`, then `default`,
26
+ * then whichever theme appears first.
27
+ */
28
+ declare function selectPrimaryTheme(flat: FlatToken[]): FlatToken[];
29
+ /**
30
+ * Generate a DESIGN.md design-system specification file from a Razorwind schema.
31
+ *
32
+ * @see https://github.com/google-labs-code/design.md
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { defineConfig } from "@razorwind/core";
37
+ * import designMd from "@razorwind/design-md/generate";
38
+ *
39
+ * export default defineConfig({
40
+ * plugins: [designMd()]
41
+ * });
42
+ * ```
43
+ */
44
+ declare const _default: (options: any) => import("@razorwind/core/plugin").Plugin;
45
+ //#endregion
46
+ export { generate_d_exports as n, selectPrimaryTheme as r, _default as t };
47
+ //# sourceMappingURL=generate-BPhbyvvs.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-BPhbyvvs.d.mts","names":[],"sources":["../src/types.ts","../src/generate.ts"],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import{t as e}from"./rolldown-runtime-DK3Fl9T5.mjs";import{definePlugin as t}from"@razorwind/core/plugin";import{formatTokenValue as n,isObject as r}from"@razorwind/core/utils";function i(e,t){let n=e.split(`.`).filter(Boolean);for(;n.length>1&&t.includes(n[0].toLowerCase());)n.shift();return n.join(`-`).replaceAll(/[^\w-]+/g,`-`).toLowerCase()}function a(e){if(typeof e==`number`||typeof e==`boolean`)return String(e);let t=String(e);return/^[a-z][\w-]*$/i.test(t)?t:JSON.stringify(t)}function o(e){return e.split(/[-_.]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}const s=/^(?:light|dark|dim|high-contrast|hc|default|base|theme)(?:[._-].+)?$/i;function c(e){return`$value`in e||`value`in e||`$ref`in e||`ref`in e}function l(e){if(typeof e.$description==`string`)return e.$description;if(typeof e.description==`string`)return e.description}function u(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function d(e){if(`$value`in e)return e.$value;if(`value`in e)return e.value;if(typeof e.$ref==`string`)return e.$ref;if(typeof e.ref==`string`)return e.ref}function f(e,t,i,a,o){if(!r(e))return;let s=u(e,i);if(c(e)){let r=d(e);o.push({path:t.join(`.`),type:s,value:r,cssValue:n(r,s),description:l(e),theme:a});return}for(let[n,r]of Object.entries(e))n.startsWith(`$`)||f(r,[...t,n],s,a,o)}function p(e){if(!r(e))return[];let t=Object.keys(e).filter(e=>!e.startsWith(`$`));return t.length>0&&t.every(e=>s.test(e))?t.map(t=>({id:t,tokens:e[t]})):[{id:`default`,tokens:e}]}function m(e,t){let n=t?new Set(t):void 0,r=[];for(let t of p(e)){let e=t.id==="default"?void 0:t.id;f(t.tokens,[],void 0,e,r)}return n?r.filter(e=>!e.type||n.has(e.type)):r}var h=e({default:()=>z,selectPrimaryTheme:()=>T});const g=new Set([`backgroundColor`,`textColor`,`typography`,`rounded`,`padding`,`size`,`height`,`width`]),_={background:`backgroundColor`,backgroundcolor:`backgroundColor`,bg:`backgroundColor`,fill:`backgroundColor`,color:`textColor`,foreground:`textColor`,text:`textColor`,textcolor:`textColor`,font:`typography`,radius:`rounded`,borderradius:`rounded`,corner:`rounded`},v=[`color`,`colors`,`palette`],y=[`typography`,`type`,`text`,`font`,`fonts`],b=/(?:^|\.)(?:radius|radii|rounded|corner)(?:\.|$)/i,x=/(?:^|\.)(?:spacing|space|gap)(?:\.|$)/i,S=/^components?$/i,C=/^\{([^}]+)\}$/,w=[`fontFamily`,`fontSize`,`fontWeight`,`lineHeight`,`letterSpacing`];function T(e){let t=[...new Set(e.map(e=>e.theme))],n=t.find(e=>e===void 0)??t.find(e=>/^light/i.test(e??``))??t.find(e=>/^(?:default|base)/i.test(e??``))??t[0];return e.filter(e=>e.theme===n)}function E(e){if(typeof e==`string`)return C.exec(e.trim())?.[1]}function D(e,t){let n=e;for(let e=0;e<8;e++){let e=E(n.value);if(!e)return n;let r=t.get(e);if(!r)return n;n=r}return n}function O(e){return e.split(/[-_.\s]+/).filter(Boolean).map((e,t)=>t===0?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``)}function k(e){let t=O(e);return g.has(t)?t:_[t.toLowerCase()]}function A(e,t){let i={};if(!r(e))return i;for(let r of w){let a=e[r];if(a==null)continue;let o=E(a),s=o?t.get(o):void 0,c=s?D(s,t).cssValue:void 0;if(typeof a==`number`){i[r]=a;continue}i[r]=c??n(a)}return i}function j(e){let t=T(m(e.tokens)),n=new Map(t.map(e=>[e.path,e])),r={colors:{},colorDescriptions:{},typography:{},rounded:{},spacing:{},components:{}},a=new Map,o=[];for(let e of t){let t=e.path.split(`.`);if(t[0]&&S.test(t[0])){o.push(e);continue}if(e.type===`color`){let t=i(e.path,v),o=D(e,n);r.colors[t]=o.cssValue,e.description&&(r.colorDescriptions[t]=e.description),a.set(e.path,`colors.${t}`);continue}if(e.type===`typography`){let t=i(e.path,y);r.typography[t]=A(e.value,n),a.set(e.path,`typography.${t}`);continue}if(e.type===`fontFamily`){let t=i(e.path,y);r.typography[t]??={},r.typography[t].fontFamily=e.cssValue,a.set(e.path,`typography.${t}`);continue}let s=e.type===`dimension`||e.type===`number`||typeof e.value==`number`;if(s&&b.test(e.path)){let i=t.at(-1);r.rounded[i]=D(e,n).cssValue,a.set(e.path,`rounded.${i}`);continue}if(s&&x.test(e.path)){let i=t.at(-1);r.spacing[i]=D(e,n).cssValue,a.set(e.path,`spacing.${i}`)}}for(let e of o){let t=e.path.split(`.`).slice(1);if(t.length<2)continue;let i=k(t.at(-1));if(!i)continue;let o=t.slice(0,-1).join(`-`).replaceAll(/[^\w-]+/g,`-`).toLowerCase(),s=E(e.value),c=s?a.get(s):void 0,l=c?`{${c}}`:D(e,n).cssValue;r.components[o]??={},r.components[o][i]=l}return r}function M(e,t,n){let r=Object.entries(t);if(r.length!==0){n.push(`${e}:`);for(let[e,t]of r){if(typeof t==`object`&&t){n.push(` ${e}:`);for(let[e,r]of Object.entries(t))n.push(` ${e}: ${a(r)}`);continue}n.push(` ${e}: ${a(t)}`)}}}function N(e){let t=[`---`];return e.version&&t.push(`version: ${a(e.version)}`),t.push(`name: ${a(e.name)}`),e.description&&t.push(`description: ${a(e.description)}`),M(`colors`,e.colors,t),M(`typography`,e.typography,t),M(`rounded`,e.rounded,t),M(`spacing`,e.spacing,t),M(`components`,e.components,t),t.push(`---`),`${t.join(`
2
+ `)}\n`}function P(e,...t){return`## ${e}\n\n${t.filter(Boolean).join(`
3
+ `)}\n`}function F(e){let t=[[Object.keys(e.colors).length,`color`],[Object.keys(e.typography).length,`typography`],[Object.keys(e.rounded).length,`shape`],[Object.keys(e.spacing).length,`spacing`],[Object.keys(e.components).length,`component`]].filter(([e])=>e>0).map(([e,t])=>`${e} ${t} token${e===1?``:`s`}`).join(`, `);return`${e.name} design tokens${t?` — ${t}`:``}. The YAML front matter above is the normative source; the prose below explains how to apply it.`}function I(e,t={}){let n=[P(`Overview`,t.overview??F(e))],r=Object.entries(e.colors);r.length>0&&n.push(P(`Colors`,r.map(([t,n])=>{let r=e.colorDescriptions[t];return`- **${o(t)} (${n}):**${r?` ${r}`:``}`}).join(`
4
+ `)));let i=Object.entries(e.typography);i.length>0&&n.push(P(`Typography`,i.map(([e,t])=>`- **${e}:** ${Object.entries(t).map(([e,t])=>`${e}: ${t}`).join(`, `)}`).join(`
5
+ `)));let a=Object.entries(e.spacing);a.length>0&&n.push(P(`Layout`,`Spacing scale:`,``,a.map(([e,t])=>`- **${e}:** ${t}`).join(`
6
+ `)));let s=Object.entries(e.rounded);s.length>0&&n.push(P(`Shapes`,`Corner radius scale:`,``,s.map(([e,t])=>`- **${e}:** ${t}`).join(`
7
+ `)));let c=Object.entries(e.components);return c.length>0&&n.push(P(`Components`,c.map(([e,t])=>`- **${e}:** ${Object.entries(t).map(([e,t])=>`${e}: \`${t}\``).join(`, `)}`).join(`
8
+ `))),n.join(`
9
+ `)}function L(e,t={}){return`${N(e)}\n${I(e,t)}`}function R(e,t={}){let n=j(e);return{[t.outputPath??`DESIGN.md`]:{path:t.outputPath??`DESIGN.md`,language:`markdown`,chunks:[{content:L(n,t),meta:{name:`razorwind-design-md`}}]}}}var z=t((e={})=>({name:`design-md:generate`,generate:async t=>R(t,e)}));export{h as n,T as r,z as t};
10
+ //# sourceMappingURL=generate-DFy3tlPT.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-DFy3tlPT.mjs","names":[],"sources":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ const e=require("./rolldown-runtime-BIInC43l.cjs");let t=require("@razorwind/core/plugin"),n=require("@razorwind/core/utils");function r(e,t){let n=e.split(`.`).filter(Boolean);for(;n.length>1&&t.includes(n[0].toLowerCase());)n.shift();return n.join(`-`).replaceAll(/[^\w-]+/g,`-`).toLowerCase()}function i(e){if(typeof e==`number`||typeof e==`boolean`)return String(e);let t=String(e);return/^[a-z][\w-]*$/i.test(t)?t:JSON.stringify(t)}function a(e){return e.split(/[-_.]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}const o=/^(?:light|dark|dim|high-contrast|hc|default|base|theme)(?:[._-].+)?$/i;function s(e){return`$value`in e||`value`in e||`$ref`in e||`ref`in e}function c(e){if(typeof e.$description==`string`)return e.$description;if(typeof e.description==`string`)return e.description}function l(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function u(e){if(`$value`in e)return e.$value;if(`value`in e)return e.value;if(typeof e.$ref==`string`)return e.$ref;if(typeof e.ref==`string`)return e.ref}function d(e,t,r,i,a){if(!(0,n.isObject)(e))return;let o=l(e,r);if(s(e)){let r=u(e);a.push({path:t.join(`.`),type:o,value:r,cssValue:(0,n.formatTokenValue)(r,o),description:c(e),theme:i});return}for(let[n,r]of Object.entries(e))n.startsWith(`$`)||d(r,[...t,n],o,i,a)}function f(e){if(!(0,n.isObject)(e))return[];let t=Object.keys(e).filter(e=>!e.startsWith(`$`));return t.length>0&&t.every(e=>o.test(e))?t.map(t=>({id:t,tokens:e[t]})):[{id:`default`,tokens:e}]}function p(e,t){let n=t?new Set(t):void 0,r=[];for(let t of f(e)){let e=t.id==="default"?void 0:t.id;d(t.tokens,[],void 0,e,r)}return n?r.filter(e=>!e.type||n.has(e.type)):r}var m=e.t({default:()=>R,selectPrimaryTheme:()=>w});const h=new Set([`backgroundColor`,`textColor`,`typography`,`rounded`,`padding`,`size`,`height`,`width`]),g={background:`backgroundColor`,backgroundcolor:`backgroundColor`,bg:`backgroundColor`,fill:`backgroundColor`,color:`textColor`,foreground:`textColor`,text:`textColor`,textcolor:`textColor`,font:`typography`,radius:`rounded`,borderradius:`rounded`,corner:`rounded`},_=[`color`,`colors`,`palette`],v=[`typography`,`type`,`text`,`font`,`fonts`],y=/(?:^|\.)(?:radius|radii|rounded|corner)(?:\.|$)/i,b=/(?:^|\.)(?:spacing|space|gap)(?:\.|$)/i,x=/^components?$/i,S=/^\{([^}]+)\}$/,C=[`fontFamily`,`fontSize`,`fontWeight`,`lineHeight`,`letterSpacing`];function w(e){let t=[...new Set(e.map(e=>e.theme))],n=t.find(e=>e===void 0)??t.find(e=>/^light/i.test(e??``))??t.find(e=>/^(?:default|base)/i.test(e??``))??t[0];return e.filter(e=>e.theme===n)}function T(e){if(typeof e==`string`)return S.exec(e.trim())?.[1]}function E(e,t){let n=e;for(let e=0;e<8;e++){let e=T(n.value);if(!e)return n;let r=t.get(e);if(!r)return n;n=r}return n}function D(e){return e.split(/[-_.\s]+/).filter(Boolean).map((e,t)=>t===0?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``)}function O(e){let t=D(e);return h.has(t)?t:g[t.toLowerCase()]}function k(e,t){let r={};if(!(0,n.isObject)(e))return r;for(let i of C){let a=e[i];if(a==null)continue;let o=T(a),s=o?t.get(o):void 0,c=s?E(s,t).cssValue:void 0;if(typeof a==`number`){r[i]=a;continue}r[i]=c??(0,n.formatTokenValue)(a)}return r}function A(e){let t=w(p(e.tokens)),n=new Map(t.map(e=>[e.path,e])),i={colors:{},colorDescriptions:{},typography:{},rounded:{},spacing:{},components:{}},a=new Map,o=[];for(let e of t){let t=e.path.split(`.`);if(t[0]&&x.test(t[0])){o.push(e);continue}if(e.type===`color`){let t=r(e.path,_),o=E(e,n);i.colors[t]=o.cssValue,e.description&&(i.colorDescriptions[t]=e.description),a.set(e.path,`colors.${t}`);continue}if(e.type===`typography`){let t=r(e.path,v);i.typography[t]=k(e.value,n),a.set(e.path,`typography.${t}`);continue}if(e.type===`fontFamily`){let t=r(e.path,v);i.typography[t]??={},i.typography[t].fontFamily=e.cssValue,a.set(e.path,`typography.${t}`);continue}let s=e.type===`dimension`||e.type===`number`||typeof e.value==`number`;if(s&&y.test(e.path)){let r=t.at(-1);i.rounded[r]=E(e,n).cssValue,a.set(e.path,`rounded.${r}`);continue}if(s&&b.test(e.path)){let r=t.at(-1);i.spacing[r]=E(e,n).cssValue,a.set(e.path,`spacing.${r}`)}}for(let e of o){let t=e.path.split(`.`).slice(1);if(t.length<2)continue;let r=O(t.at(-1));if(!r)continue;let o=t.slice(0,-1).join(`-`).replaceAll(/[^\w-]+/g,`-`).toLowerCase(),s=T(e.value),c=s?a.get(s):void 0,l=c?`{${c}}`:E(e,n).cssValue;i.components[o]??={},i.components[o][r]=l}return i}function j(e,t,n){let r=Object.entries(t);if(r.length!==0){n.push(`${e}:`);for(let[e,t]of r){if(typeof t==`object`&&t){n.push(` ${e}:`);for(let[e,r]of Object.entries(t))n.push(` ${e}: ${i(r)}`);continue}n.push(` ${e}: ${i(t)}`)}}}function M(e){let t=[`---`];return e.version&&t.push(`version: ${i(e.version)}`),t.push(`name: ${i(e.name)}`),e.description&&t.push(`description: ${i(e.description)}`),j(`colors`,e.colors,t),j(`typography`,e.typography,t),j(`rounded`,e.rounded,t),j(`spacing`,e.spacing,t),j(`components`,e.components,t),t.push(`---`),`${t.join(`
2
+ `)}\n`}function N(e,...t){return`## ${e}\n\n${t.filter(Boolean).join(`
3
+ `)}\n`}function P(e){let t=[[Object.keys(e.colors).length,`color`],[Object.keys(e.typography).length,`typography`],[Object.keys(e.rounded).length,`shape`],[Object.keys(e.spacing).length,`spacing`],[Object.keys(e.components).length,`component`]].filter(([e])=>e>0).map(([e,t])=>`${e} ${t} token${e===1?``:`s`}`).join(`, `);return`${e.name} design tokens${t?` — ${t}`:``}. The YAML front matter above is the normative source; the prose below explains how to apply it.`}function F(e,t={}){let n=[N(`Overview`,t.overview??P(e))],r=Object.entries(e.colors);r.length>0&&n.push(N(`Colors`,r.map(([t,n])=>{let r=e.colorDescriptions[t];return`- **${a(t)} (${n}):**${r?` ${r}`:``}`}).join(`
4
+ `)));let i=Object.entries(e.typography);i.length>0&&n.push(N(`Typography`,i.map(([e,t])=>`- **${e}:** ${Object.entries(t).map(([e,t])=>`${e}: ${t}`).join(`, `)}`).join(`
5
+ `)));let o=Object.entries(e.spacing);o.length>0&&n.push(N(`Layout`,`Spacing scale:`,``,o.map(([e,t])=>`- **${e}:** ${t}`).join(`
6
+ `)));let s=Object.entries(e.rounded);s.length>0&&n.push(N(`Shapes`,`Corner radius scale:`,``,s.map(([e,t])=>`- **${e}:** ${t}`).join(`
7
+ `)));let c=Object.entries(e.components);return c.length>0&&n.push(N(`Components`,c.map(([e,t])=>`- **${e}:** ${Object.entries(t).map(([e,t])=>`${e}: \`${t}\``).join(`, `)}`).join(`
8
+ `))),n.join(`
9
+ `)}function I(e,t={}){return`${M(e)}\n${F(e,t)}`}function L(e,t={}){let n=A(e);return{[t.outputPath??`DESIGN.md`]:{path:t.outputPath??`DESIGN.md`,language:`markdown`,chunks:[{content:I(n,t),meta:{name:`razorwind-design-md`}}]}}}var R=(0,t.definePlugin)((e={})=>({name:`design-md:generate`,generate:async t=>L(t,e)}));Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return R}});
@@ -0,0 +1 @@
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./generate-DQw2tVYc.cjs");exports.default=e.t,exports.selectPrimaryTheme=e.r;
@@ -0,0 +1,2 @@
1
+ import { r as selectPrimaryTheme, t as _default } from "./generate-BPhbyvvs.cjs";
2
+ export { _default as default, selectPrimaryTheme };
@@ -0,0 +1,2 @@
1
+ import { r as selectPrimaryTheme, t as _default } from "./generate-BPhbyvvs.mjs";
2
+ export { _default as default, selectPrimaryTheme };
@@ -0,0 +1 @@
1
+ import{r as e,t}from"./generate-DFy3tlPT.mjs";export{t as default,e as selectPrimaryTheme};
package/dist/index.cjs CHANGED
@@ -1,9 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("@power-plant/core"),t=require("@razorwind/core/plugin"),n=require("@stryke/fs/read-file"),r=require("@stryke/type-checks/is-empty-object"),i=require("@razorwind/core/utils"),a=require("@razorwind/core/tokens"),o=require("@stryke/fs/exists"),s=require("@stryke/path/join"),c=require("yaml");function l(e,t){let n=e.split(`.`).filter(Boolean);for(;n.length>1&&t.includes(n[0].toLowerCase());)n.shift();return n.join(`-`).replaceAll(/[^\w-]+/g,`-`).toLowerCase()}function u(e){if(typeof e==`number`||typeof e==`boolean`)return String(e);let t=String(e);return/^[a-z][\w-]*$/i.test(t)?t:JSON.stringify(t)}function ee(e){return e.split(/[-_.]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}const te=/^(?:light|dark|dim|high-contrast|hc|default|base|theme)(?:[._-].+)?$/i;function d(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function f(e){return`$value`in e||`value`in e||`$ref`in e||`ref`in e}function p(e){if(typeof e.$description==`string`)return e.$description;if(typeof e.description==`string`)return e.description}function m(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function h(e){if(`$value`in e)return e.$value;if(`value`in e)return e.value;if(typeof e.$ref==`string`)return e.$ref;if(typeof e.ref==`string`)return e.ref}function g(e,t,n,r,a){if(!d(e))return;let o=m(e,n);if(f(e)){let n=h(e);a.push({path:t.join(`.`),type:o,value:n,cssValue:(0,i.formatTokenValue)(n,o),description:p(e),theme:r});return}for(let[n,i]of Object.entries(e))n.startsWith(`$`)||g(i,[...t,n],o,r,a)}function _(e){if(!d(e))return[];let t=Object.keys(e).filter(e=>!e.startsWith(`$`));return t.length>0&&t.every(e=>te.test(e))?t.map(t=>({id:t,tokens:e[t]})):[{id:`default`,tokens:e}]}function v(e,t){let n=t?new Set(t):void 0,r=[];for(let t of _(e)){let e=t.id==="default"?void 0:t.id;g(t.tokens,[],void 0,e,r)}return n?r.filter(e=>!e.type||n.has(e.type)):r}const y=new Set([`backgroundColor`,`textColor`,`typography`,`rounded`,`padding`,`size`,`height`,`width`]),ne={background:`backgroundColor`,backgroundcolor:`backgroundColor`,bg:`backgroundColor`,fill:`backgroundColor`,color:`textColor`,foreground:`textColor`,text:`textColor`,textcolor:`textColor`,font:`typography`,radius:`rounded`,borderradius:`rounded`,corner:`rounded`},re=[`color`,`colors`,`palette`],b=[`typography`,`type`,`text`,`font`,`fonts`],x=/(?:^|\.)(?:radius|radii|rounded|corner)(?:\.|$)/i,S=/(?:^|\.)(?:spacing|space|gap)(?:\.|$)/i,C=/^components?$/i,w=/^\{([^}]+)\}$/,T=[`fontFamily`,`fontSize`,`fontWeight`,`lineHeight`,`letterSpacing`];function E(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function D(e){let t=[...new Set(e.map(e=>e.theme))],n=t.find(e=>e===void 0)??t.find(e=>/^light/i.test(e??``))??t.find(e=>/^(?:default|base)/i.test(e??``))??t[0];return e.filter(e=>e.theme===n)}function O(e){if(typeof e==`string`)return w.exec(e.trim())?.[1]}function k(e,t){let n=e;for(let e=0;e<8;e++){let e=O(n.value);if(!e)return n;let r=t.get(e);if(!r)return n;n=r}return n}function ie(e){return e.split(/[-_.\s]+/).filter(Boolean).map((e,t)=>t===0?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``)}function ae(e){let t=ie(e);return y.has(t)?t:ne[t.toLowerCase()]}function oe(e,t){let n={};if(!E(e))return n;for(let r of T){let a=e[r];if(a==null)continue;let o=O(a),s=o?t.get(o):void 0,c=s?k(s,t).cssValue:void 0;if(typeof a==`number`){n[r]=a;continue}n[r]=c??(0,i.formatTokenValue)(a)}return n}function A(e,t={}){let n=D(v(e.tokens)),r=new Map(n.map(e=>[e.path,e])),i={name:t.name??`Razorwind Design System`,description:t.description,version:t.version??`alpha`,colors:{},colorDescriptions:{},typography:{},rounded:{},spacing:{},components:{}},a=new Map,o=[];for(let e of n){let t=e.path.split(`.`);if(t[0]&&C.test(t[0])){o.push(e);continue}if(e.type===`color`){let t=l(e.path,re),n=k(e,r);i.colors[t]=n.cssValue,e.description&&(i.colorDescriptions[t]=e.description),a.set(e.path,`colors.${t}`);continue}if(e.type===`typography`){let t=l(e.path,b);i.typography[t]=oe(e.value,r),a.set(e.path,`typography.${t}`);continue}if(e.type===`fontFamily`){let t=l(e.path,b);i.typography[t]??={},i.typography[t].fontFamily=e.cssValue,a.set(e.path,`typography.${t}`);continue}let n=e.type===`dimension`||e.type===`number`||typeof e.value==`number`;if(n&&x.test(e.path)){let n=t.at(-1);i.rounded[n]=k(e,r).cssValue,a.set(e.path,`rounded.${n}`);continue}if(n&&S.test(e.path)){let n=t.at(-1);i.spacing[n]=k(e,r).cssValue,a.set(e.path,`spacing.${n}`)}}for(let e of o){let t=e.path.split(`.`).slice(1);if(t.length<2)continue;let n=ae(t.at(-1));if(!n)continue;let o=t.slice(0,-1).join(`-`).replaceAll(/[^\w-]+/g,`-`).toLowerCase(),s=O(e.value),c=s?a.get(s):void 0,l=c?`{${c}}`:k(e,r).cssValue;i.components[o]??={},i.components[o][n]=l}return i}function j(e,t,n){let r=Object.entries(t);if(r.length!==0){n.push(`${e}:`);for(let[e,t]of r){if(typeof t==`object`&&t){n.push(` ${e}:`);for(let[e,r]of Object.entries(t))n.push(` ${e}: ${u(r)}`);continue}n.push(` ${e}: ${u(t)}`)}}}function M(e){let t=[`---`];return e.version&&t.push(`version: ${u(e.version)}`),t.push(`name: ${u(e.name)}`),e.description&&t.push(`description: ${u(e.description)}`),j(`colors`,e.colors,t),j(`typography`,e.typography,t),j(`rounded`,e.rounded,t),j(`spacing`,e.spacing,t),j(`components`,e.components,t),t.push(`---`),`${t.join(`
2
- `)}\n`}function N(e,...t){return`## ${e}\n\n${t.filter(Boolean).join(`
3
- `)}\n`}function P(e){let t=[[Object.keys(e.colors).length,`color`],[Object.keys(e.typography).length,`typography`],[Object.keys(e.rounded).length,`shape`],[Object.keys(e.spacing).length,`spacing`],[Object.keys(e.components).length,`component`]].filter(([e])=>e>0).map(([e,t])=>`${e} ${t} token${e===1?``:`s`}`).join(`, `);return`${e.name} design tokens${t?` — ${t}`:``}. The YAML front matter above is the normative source; the prose below explains how to apply it.`}function F(e,t={}){let n=[N(`Overview`,t.overview??P(e))],r=Object.entries(e.colors);r.length>0&&n.push(N(`Colors`,r.map(([t,n])=>{let r=e.colorDescriptions[t];return`- **${ee(t)} (${n}):**${r?` ${r}`:``}`}).join(`
4
- `)));let i=Object.entries(e.typography);i.length>0&&n.push(N(`Typography`,i.map(([e,t])=>`- **${e}:** ${Object.entries(t).map(([e,t])=>`${e}: ${t}`).join(`, `)}`).join(`
5
- `)));let a=Object.entries(e.spacing);a.length>0&&n.push(N(`Layout`,`Spacing scale:`,``,a.map(([e,t])=>`- **${e}:** ${t}`).join(`
6
- `)));let o=Object.entries(e.rounded);o.length>0&&n.push(N(`Shapes`,`Corner radius scale:`,``,o.map(([e,t])=>`- **${e}:** ${t}`).join(`
7
- `)));let s=Object.entries(e.components);return s.length>0&&n.push(N(`Components`,s.map(([e,t])=>`- **${e}:** ${Object.entries(t).map(([e,t])=>`${e}: \`${t}\``).join(`, `)}`).join(`
8
- `))),n.join(`
9
- `)}function I(e,t={}){return`${M(e)}\n${F(e,t)}`}function L(e,t={}){let n=t.outFile??`DESIGN.md`,r=A(e,t);return{[n]:{path:n,language:`markdown`,chunks:[{content:I(r,t),meta:{name:`razorwind-design-md`}}]}}}const R=/(?:^|[/\\])design\.md$/i,z=[`DESIGN.md`,`design.md`,`docs/DESIGN.md`],B=/^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,V=/^\{[^{}]+\}$/,H=new Set([`version`,`name`,`description`]),U=[`fontFamily`,`fontSize`,`fontWeight`,`lineHeight`,`letterSpacing`,`fontFeature`,`fontVariation`],W={backgroundColor:`color`,textColor:`color`,typography:`typography`,rounded:`dimension`,padding:`dimension`,size:`dimension`,height:`dimension`,width:`dimension`};function G(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function K(e){return typeof e==`string`&&V.test(e.trim())}function q(e){return typeof e==`number`?`${e}px`:e}function J(e){let t={};for(let n of U){let r=e[n];r!=null&&(t[n]=r)}for(let[n,r]of Object.entries(e))!(n in t)&&r!=null&&(typeof r==`string`||typeof r==`number`)&&(t[n]=r);return t}function Y(e,t,n=!1){let r={};for(let[i,a]of Object.entries(e))a!=null&&(r[i]={$type:t,$value:K(a)?a.trim():n?q(a):a});return r}function se(e){let t={};for(let[n,r]of Object.entries(e))K(r)?t[n]={$type:`typography`,$value:r.trim()}:G(r)&&(t[n]={$type:`typography`,$value:J(r)});return t}function ce(e){let t={};for(let[n,r]of Object.entries(e)){if(!G(r))continue;let e={};for(let[t,n]of Object.entries(r)){if(n==null)continue;let r=W[t];e[t]={...r?{$type:r}:{},$value:K(n)?n.trim():r===`typography`&&G(n)?J(n):q(n)}}Object.keys(e).length>0&&(t[n]=e)}return t}function X(e){let t=B.exec(e);if(!t?.[1])return;let n;try{n=(0,c.parse)(t[1])}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Failed to parse DESIGN.md front matter as YAML: ${t}`)}return G(n)?n:void 0}function Z(e){let t={};for(let[n,r]of Object.entries(e))if(!(H.has(n)||!G(r)))switch(n){case`colors`:t[n]=Y(r,`color`);break;case`typography`:t[n]=se(r);break;case`rounded`:case`spacing`:t[n]=Y(r,`dimension`,!0);break;case`components`:t[n]=ce(r);break;default:t[n]=r;break}return(0,a.normalizeTokenTree)(t)}function Q(e){let t=X(e);return t?Z(t):{}}function le(e){return R.test(e)}function $(e){for(let t of z){let n=(0,s.joinPaths)(e,t);if((0,o.existsSync)(n))return n}}var ue=(0,t.definePlugin)((t={})=>({name:`razorwind-design-md`,parsers:[{name:`razorwind-design-md`,pattern:R,parser:e=>Q(e)}],extract:async(i,a)=>{if(i.tokens&&!(0,r.isEmptyObject)(i.tokens))return i;let o=t.path;if(!o){let{cwd:t}=(0,e.useExecution)();if(o=$(t),!o)return i}let s=Q(await(0,n.readFile)(o));return!s||(0,r.isEmptyObject)(s)?i:{...i,tokens:s}},generate:async(e,t)=>L(e,t)}));exports.DESIGN_MD_FILE_PATTERN=R,exports.DESIGN_MD_PATH_CANDIDATES=z,exports.default=ue,exports.designMdToTokens=Z,exports.extractDesignMd=A,exports.extractDesignMdFrontMatter=X,exports.flattenTokens=v,Object.defineProperty(exports,"formatTokenValue",{enumerable:!0,get:function(){return i.formatTokenValue}}),exports.generateDesignMd=L,exports.isDesignMdFile=le,exports.parseDesignMdTokens=Q,exports.renderBody=F,exports.renderDesignMd=I,exports.renderFrontMatter=M,exports.resolveDesignMdPath=$,exports.resolveTokenSets=_,exports.selectPrimaryTheme=D,exports.toTokenName=l,exports.toYamlScalar=u;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./extract.cjs"),t=require("./generate-DQw2tVYc.cjs");Object.defineProperty(exports,"extract",{enumerable:!0,get:function(){return e.t}}),Object.defineProperty(exports,"generate",{enumerable:!0,get:function(){return t.n}});
package/dist/index.d.cts CHANGED
@@ -1,248 +1,3 @@
1
- import { Schema, Tokens } from "@razorwind/core/schema";
2
- import { TokenType } from "@power-plant/dtcg-schema";
3
- import { formatTokenValue } from "@razorwind/core/utils";
4
- import { GeneratorFunctionResult } from "@power-plant/core";
5
- import { DesignTokens } from "style-dictionary/types";
6
- //#region src/types.d.ts
7
- /**
8
- * Options for the Razorwind DESIGN.md generator.
9
- */
10
- interface Options {
11
- /**
12
- * Output file path (relative to the execution cwd).
13
- *
14
- * @defaultValue `"DESIGN.md"`
15
- */
16
- outFile?: string;
17
- /**
18
- * Design system name written to the YAML front matter.
19
- *
20
- * @defaultValue `"Razorwind Design System"`
21
- */
22
- name?: string;
23
- /**
24
- * Short design system description written to the YAML front matter.
25
- */
26
- description?: string;
27
- /**
28
- * DESIGN.md spec version written to the YAML front matter.
29
- *
30
- * @defaultValue `"alpha"`
31
- */
32
- version?: string;
33
- /**
34
- * Prose used for the `## Overview` section. When omitted, a summary is
35
- * generated from the extracted tokens.
36
- */
37
- overview?: string;
38
- }
39
- /**
40
- * A flattened design token ready for DESIGN.md extraction.
41
- */
42
- interface FlatToken {
43
- /** Dot-separated token path (e.g. `color.primary`). */
44
- path: string;
45
- /** DTCG `$type`, when known. */
46
- type?: TokenType | string;
47
- /** Raw `$value` from the token document. */
48
- value: unknown;
49
- /** CSS-friendly string form of {@link value}. */
50
- cssValue: string;
51
- /** Optional DTCG `$description`. */
52
- description?: string;
53
- /** Theme / set id when tokens are a `Record<string, Tokens>`. */
54
- theme?: string;
55
- }
56
- /**
57
- * A DESIGN.md typography token
58
- * (https://github.com/google-labs-code/design.md — Token Types).
59
- */
60
- interface TypographyToken {
61
- fontFamily?: string;
62
- fontSize?: string;
63
- fontWeight?: string | number;
64
- lineHeight?: string | number;
65
- letterSpacing?: string;
66
- }
67
- /**
68
- * A DESIGN.md component token — a map of valid component properties
69
- * (`backgroundColor`, `textColor`, `typography`, `rounded`, `padding`,
70
- * `size`, `height`, `width`) to values or `{token.references}`.
71
- */
72
- type ComponentToken = Record<string, string>;
73
- /**
74
- * Intermediate representation of a DESIGN.md document, extracted from the
75
- * Razorwind schema before rendering.
76
- */
77
- interface DesignMdDocument {
78
- name: string;
79
- description?: string;
80
- version?: string;
81
- colors: Record<string, string>;
82
- /** Prose descriptions keyed by color token name. */
83
- colorDescriptions: Record<string, string>;
84
- typography: Record<string, TypographyToken>;
85
- rounded: Record<string, string>;
86
- spacing: Record<string, string>;
87
- components: Record<string, ComponentToken>;
88
- }
89
- //#endregion
90
- //#region src/extract.d.ts
91
- /**
92
- * Select the token set used for the front matter when tokens are split into
93
- * multiple themes: the un-themed set first, then `light`, then `default`,
94
- * then whichever theme appears first.
95
- */
96
- declare function selectPrimaryTheme(flat: FlatToken[]): FlatToken[];
97
- /**
98
- * Extract a DESIGN.md document from the Razorwind schema.
99
- *
100
- * Colors, typography, rounded / spacing scales, and component tokens are
101
- * derived from the DTCG token tree. DTCG aliases are re-emitted as DESIGN.md
102
- * `{section.token}` references when the target token is part of the output,
103
- * or resolved to their terminal CSS value otherwise.
104
- */
105
- declare function extractDesignMd(spec: Schema, options?: Options): DesignMdDocument;
106
- //#endregion
107
- //#region src/flatten.d.ts
108
- interface TokenSet {
109
- id: string;
110
- tokens: Tokens;
111
- }
112
- /**
113
- * Split `Schema.tokens` into one or more named token sets.
114
- *
115
- * A record whose keys all look like themes (`light`, `dark`, …) is treated as
116
- * multi-theme input; otherwise the whole document is a single set.
117
- */
118
- declare function resolveTokenSets(tokens: Tokens | Record<string, Tokens>): TokenSet[];
119
- /**
120
- * Flatten DTCG token trees into extraction rows.
121
- */
122
- declare function flattenTokens(tokens: Tokens | Record<string, Tokens>, includeTypes?: TokenType[]): FlatToken[];
123
- //#endregion
124
- //#region src/format.d.ts
125
- /**
126
- * Convert a token path into a DESIGN.md token name.
127
- *
128
- * Strips a leading group segment (e.g. `color`, `colors`, `radius`) when it
129
- * matches the section the token is emitted into, then joins the rest with
130
- * `-` (DESIGN.md token names are flat kebab-case).
131
- *
132
- * @example
133
- * toTokenName("color.primary", ["color", "colors"]) // "primary"
134
- */
135
- declare function toTokenName(path: string, stripPrefixes: string[]): string;
136
- /**
137
- * Serialize a value as a YAML scalar, quoting when required (values starting
138
- * with `#`, `{`, containing YAML-significant characters, etc.).
139
- */
140
- declare function toYamlScalar(value: unknown): string;
141
- //#endregion
142
- //#region src/generate.d.ts
143
- /**
144
- * Render the machine-readable YAML front matter layer of a DESIGN.md file.
145
- */
146
- declare function renderFrontMatter(document: DesignMdDocument): string;
147
- /**
148
- * Render the human-readable markdown body of a DESIGN.md file. Sections
149
- * follow the canonical order defined by the spec (Overview, Colors,
150
- * Typography, Layout, Shapes, Components); empty sections are omitted.
151
- */
152
- declare function renderBody(document: DesignMdDocument, options?: Options): string;
153
- /**
154
- * Render a complete DESIGN.md file — YAML front matter followed by the
155
- * markdown body.
156
- *
157
- * @see https://github.com/google-labs-code/design.md
158
- */
159
- declare function renderDesignMd(document: DesignMdDocument, options?: Options): string;
160
- /**
161
- * Generate a DESIGN.md design-system specification file from a Razorwind
162
- * schema.
163
- *
164
- * @see https://github.com/google-labs-code/design.md
165
- */
166
- declare function generateDesignMd(spec: Schema, options?: Options): GeneratorFunctionResult<Schema, Options>;
167
- //#endregion
168
- //#region src/load.d.ts
169
- /**
170
- * Basename pattern for DESIGN.md spec files
171
- * (https://github.com/google-labs-code/design.md).
172
- */
173
- declare const DESIGN_MD_FILE_PATTERN: RegExp;
174
- /** Candidate workspace paths checked for a DESIGN.md spec file. */
175
- declare const DESIGN_MD_PATH_CANDIDATES: readonly ["DESIGN.md", "design.md", "docs/DESIGN.md"];
176
- /**
177
- * Extract the YAML front matter object from DESIGN.md contents.
178
- *
179
- * @param contents - The raw DESIGN.md file contents.
180
- * @returns The parsed front matter, or `undefined` when no front matter fence
181
- * is present.
182
- */
183
- declare function extractDesignMdFrontMatter(contents: string): Record<string, unknown> | undefined;
184
- /**
185
- * Convert DESIGN.md front-matter tokens (colors, typography, rounded,
186
- * spacing, components) into a DTCG design-token tree.
187
- *
188
- * DESIGN.md `{path.to.token}` references are preserved verbatim — the group
189
- * names in the emitted tree match the front-matter section names, so the
190
- * references resolve as DTCG aliases without rewriting.
191
- *
192
- * @see https://github.com/google-labs-code/design.md#the-specification
193
- *
194
- * @param frontMatter - The parsed DESIGN.md YAML front matter.
195
- * @returns The equivalent DTCG token tree.
196
- */
197
- declare function designMdToTokens(frontMatter: Record<string, unknown>): DesignTokens;
198
- /**
199
- * Parse DESIGN.md file contents into a DTCG token tree.
200
- *
201
- * @param contents - The raw DESIGN.md file contents.
202
- * @returns The extracted tokens; an empty object when the file has no YAML
203
- * front matter.
204
- */
205
- declare function parseDesignMdTokens(contents: string): DesignTokens;
206
- /**
207
- * Check whether a path points at a DESIGN.md spec file.
208
- *
209
- * @param filePath - The file path to test.
210
- * @returns True when the basename is `DESIGN.md` (case-insensitive).
211
- */
212
- declare function isDesignMdFile(filePath: string): boolean;
213
- /**
214
- * Resolve the DESIGN.md file for a workspace, if one exists.
215
- *
216
- * @param cwd - The workspace root to search from.
217
- * @returns The absolute path to the first matching candidate, or `undefined`.
218
- */
219
- declare function resolveDesignMdPath(cwd: string): string | undefined;
220
- //#endregion
221
- //#region src/index.d.ts
222
- interface DesignMdPluginOptions {
223
- /**
224
- * The path to the DESIGN.md file.
225
- *
226
- * @default "DESIGN.md"
227
- */
228
- path?: string;
229
- }
230
- /**
231
- * Razorwind plugin: load DESIGN.md tokens on extract, emit DESIGN.md on generate.
232
- *
233
- * @see https://github.com/google-labs-code/design.md
234
- *
235
- * @example
236
- * ```ts
237
- * import { defineConfig } from "@razorwind/core";
238
- * import designMd from "@razorwind/design-md";
239
- *
240
- * export default defineConfig({
241
- * plugins: [designMd()]
242
- * });
243
- * ```
244
- */
245
- declare const _default: any;
246
- //#endregion
247
- export { type ComponentToken, DESIGN_MD_FILE_PATTERN, DESIGN_MD_PATH_CANDIDATES, type DesignMdDocument, DesignMdPluginOptions, type FlatToken, type Options, type TypographyToken, _default as default, designMdToTokens, extractDesignMd, extractDesignMdFrontMatter, flattenTokens, formatTokenValue, generateDesignMd, isDesignMdFile, parseDesignMdTokens, renderBody, renderDesignMd, renderFrontMatter, resolveDesignMdPath, resolveTokenSets, selectPrimaryTheme, toTokenName, toYamlScalar };
248
- //# sourceMappingURL=index.d.cts.map
1
+ import { t as extract_d_exports } from "./extract.cjs";
2
+ import { n as generate_d_exports } from "./generate-BPhbyvvs.cjs";
3
+ export { extract_d_exports as extract, generate_d_exports as generate };
package/dist/index.d.mts CHANGED
@@ -1,248 +1,3 @@
1
- import { GeneratorFunctionResult } from "@power-plant/core";
2
- import { formatTokenValue } from "@razorwind/core/utils";
3
- import { Schema, Tokens } from "@razorwind/core/schema";
4
- import { TokenType } from "@power-plant/dtcg-schema";
5
- import { DesignTokens } from "style-dictionary/types";
6
- //#region src/types.d.ts
7
- /**
8
- * Options for the Razorwind DESIGN.md generator.
9
- */
10
- interface Options {
11
- /**
12
- * Output file path (relative to the execution cwd).
13
- *
14
- * @defaultValue `"DESIGN.md"`
15
- */
16
- outFile?: string;
17
- /**
18
- * Design system name written to the YAML front matter.
19
- *
20
- * @defaultValue `"Razorwind Design System"`
21
- */
22
- name?: string;
23
- /**
24
- * Short design system description written to the YAML front matter.
25
- */
26
- description?: string;
27
- /**
28
- * DESIGN.md spec version written to the YAML front matter.
29
- *
30
- * @defaultValue `"alpha"`
31
- */
32
- version?: string;
33
- /**
34
- * Prose used for the `## Overview` section. When omitted, a summary is
35
- * generated from the extracted tokens.
36
- */
37
- overview?: string;
38
- }
39
- /**
40
- * A flattened design token ready for DESIGN.md extraction.
41
- */
42
- interface FlatToken {
43
- /** Dot-separated token path (e.g. `color.primary`). */
44
- path: string;
45
- /** DTCG `$type`, when known. */
46
- type?: TokenType | string;
47
- /** Raw `$value` from the token document. */
48
- value: unknown;
49
- /** CSS-friendly string form of {@link value}. */
50
- cssValue: string;
51
- /** Optional DTCG `$description`. */
52
- description?: string;
53
- /** Theme / set id when tokens are a `Record<string, Tokens>`. */
54
- theme?: string;
55
- }
56
- /**
57
- * A DESIGN.md typography token
58
- * (https://github.com/google-labs-code/design.md — Token Types).
59
- */
60
- interface TypographyToken {
61
- fontFamily?: string;
62
- fontSize?: string;
63
- fontWeight?: string | number;
64
- lineHeight?: string | number;
65
- letterSpacing?: string;
66
- }
67
- /**
68
- * A DESIGN.md component token — a map of valid component properties
69
- * (`backgroundColor`, `textColor`, `typography`, `rounded`, `padding`,
70
- * `size`, `height`, `width`) to values or `{token.references}`.
71
- */
72
- type ComponentToken = Record<string, string>;
73
- /**
74
- * Intermediate representation of a DESIGN.md document, extracted from the
75
- * Razorwind schema before rendering.
76
- */
77
- interface DesignMdDocument {
78
- name: string;
79
- description?: string;
80
- version?: string;
81
- colors: Record<string, string>;
82
- /** Prose descriptions keyed by color token name. */
83
- colorDescriptions: Record<string, string>;
84
- typography: Record<string, TypographyToken>;
85
- rounded: Record<string, string>;
86
- spacing: Record<string, string>;
87
- components: Record<string, ComponentToken>;
88
- }
89
- //#endregion
90
- //#region src/extract.d.ts
91
- /**
92
- * Select the token set used for the front matter when tokens are split into
93
- * multiple themes: the un-themed set first, then `light`, then `default`,
94
- * then whichever theme appears first.
95
- */
96
- declare function selectPrimaryTheme(flat: FlatToken[]): FlatToken[];
97
- /**
98
- * Extract a DESIGN.md document from the Razorwind schema.
99
- *
100
- * Colors, typography, rounded / spacing scales, and component tokens are
101
- * derived from the DTCG token tree. DTCG aliases are re-emitted as DESIGN.md
102
- * `{section.token}` references when the target token is part of the output,
103
- * or resolved to their terminal CSS value otherwise.
104
- */
105
- declare function extractDesignMd(spec: Schema, options?: Options): DesignMdDocument;
106
- //#endregion
107
- //#region src/flatten.d.ts
108
- interface TokenSet {
109
- id: string;
110
- tokens: Tokens;
111
- }
112
- /**
113
- * Split `Schema.tokens` into one or more named token sets.
114
- *
115
- * A record whose keys all look like themes (`light`, `dark`, …) is treated as
116
- * multi-theme input; otherwise the whole document is a single set.
117
- */
118
- declare function resolveTokenSets(tokens: Tokens | Record<string, Tokens>): TokenSet[];
119
- /**
120
- * Flatten DTCG token trees into extraction rows.
121
- */
122
- declare function flattenTokens(tokens: Tokens | Record<string, Tokens>, includeTypes?: TokenType[]): FlatToken[];
123
- //#endregion
124
- //#region src/format.d.ts
125
- /**
126
- * Convert a token path into a DESIGN.md token name.
127
- *
128
- * Strips a leading group segment (e.g. `color`, `colors`, `radius`) when it
129
- * matches the section the token is emitted into, then joins the rest with
130
- * `-` (DESIGN.md token names are flat kebab-case).
131
- *
132
- * @example
133
- * toTokenName("color.primary", ["color", "colors"]) // "primary"
134
- */
135
- declare function toTokenName(path: string, stripPrefixes: string[]): string;
136
- /**
137
- * Serialize a value as a YAML scalar, quoting when required (values starting
138
- * with `#`, `{`, containing YAML-significant characters, etc.).
139
- */
140
- declare function toYamlScalar(value: unknown): string;
141
- //#endregion
142
- //#region src/generate.d.ts
143
- /**
144
- * Render the machine-readable YAML front matter layer of a DESIGN.md file.
145
- */
146
- declare function renderFrontMatter(document: DesignMdDocument): string;
147
- /**
148
- * Render the human-readable markdown body of a DESIGN.md file. Sections
149
- * follow the canonical order defined by the spec (Overview, Colors,
150
- * Typography, Layout, Shapes, Components); empty sections are omitted.
151
- */
152
- declare function renderBody(document: DesignMdDocument, options?: Options): string;
153
- /**
154
- * Render a complete DESIGN.md file — YAML front matter followed by the
155
- * markdown body.
156
- *
157
- * @see https://github.com/google-labs-code/design.md
158
- */
159
- declare function renderDesignMd(document: DesignMdDocument, options?: Options): string;
160
- /**
161
- * Generate a DESIGN.md design-system specification file from a Razorwind
162
- * schema.
163
- *
164
- * @see https://github.com/google-labs-code/design.md
165
- */
166
- declare function generateDesignMd(spec: Schema, options?: Options): GeneratorFunctionResult<Schema, Options>;
167
- //#endregion
168
- //#region src/load.d.ts
169
- /**
170
- * Basename pattern for DESIGN.md spec files
171
- * (https://github.com/google-labs-code/design.md).
172
- */
173
- declare const DESIGN_MD_FILE_PATTERN: RegExp;
174
- /** Candidate workspace paths checked for a DESIGN.md spec file. */
175
- declare const DESIGN_MD_PATH_CANDIDATES: readonly ["DESIGN.md", "design.md", "docs/DESIGN.md"];
176
- /**
177
- * Extract the YAML front matter object from DESIGN.md contents.
178
- *
179
- * @param contents - The raw DESIGN.md file contents.
180
- * @returns The parsed front matter, or `undefined` when no front matter fence
181
- * is present.
182
- */
183
- declare function extractDesignMdFrontMatter(contents: string): Record<string, unknown> | undefined;
184
- /**
185
- * Convert DESIGN.md front-matter tokens (colors, typography, rounded,
186
- * spacing, components) into a DTCG design-token tree.
187
- *
188
- * DESIGN.md `{path.to.token}` references are preserved verbatim — the group
189
- * names in the emitted tree match the front-matter section names, so the
190
- * references resolve as DTCG aliases without rewriting.
191
- *
192
- * @see https://github.com/google-labs-code/design.md#the-specification
193
- *
194
- * @param frontMatter - The parsed DESIGN.md YAML front matter.
195
- * @returns The equivalent DTCG token tree.
196
- */
197
- declare function designMdToTokens(frontMatter: Record<string, unknown>): DesignTokens;
198
- /**
199
- * Parse DESIGN.md file contents into a DTCG token tree.
200
- *
201
- * @param contents - The raw DESIGN.md file contents.
202
- * @returns The extracted tokens; an empty object when the file has no YAML
203
- * front matter.
204
- */
205
- declare function parseDesignMdTokens(contents: string): DesignTokens;
206
- /**
207
- * Check whether a path points at a DESIGN.md spec file.
208
- *
209
- * @param filePath - The file path to test.
210
- * @returns True when the basename is `DESIGN.md` (case-insensitive).
211
- */
212
- declare function isDesignMdFile(filePath: string): boolean;
213
- /**
214
- * Resolve the DESIGN.md file for a workspace, if one exists.
215
- *
216
- * @param cwd - The workspace root to search from.
217
- * @returns The absolute path to the first matching candidate, or `undefined`.
218
- */
219
- declare function resolveDesignMdPath(cwd: string): string | undefined;
220
- //#endregion
221
- //#region src/index.d.ts
222
- interface DesignMdPluginOptions {
223
- /**
224
- * The path to the DESIGN.md file.
225
- *
226
- * @default "DESIGN.md"
227
- */
228
- path?: string;
229
- }
230
- /**
231
- * Razorwind plugin: load DESIGN.md tokens on extract, emit DESIGN.md on generate.
232
- *
233
- * @see https://github.com/google-labs-code/design.md
234
- *
235
- * @example
236
- * ```ts
237
- * import { defineConfig } from "@razorwind/core";
238
- * import designMd from "@razorwind/design-md";
239
- *
240
- * export default defineConfig({
241
- * plugins: [designMd()]
242
- * });
243
- * ```
244
- */
245
- declare const _default: any;
246
- //#endregion
247
- export { type ComponentToken, DESIGN_MD_FILE_PATTERN, DESIGN_MD_PATH_CANDIDATES, type DesignMdDocument, DesignMdPluginOptions, type FlatToken, type Options, type TypographyToken, _default as default, designMdToTokens, extractDesignMd, extractDesignMdFrontMatter, flattenTokens, formatTokenValue, generateDesignMd, isDesignMdFile, parseDesignMdTokens, renderBody, renderDesignMd, renderFrontMatter, resolveDesignMdPath, resolveTokenSets, selectPrimaryTheme, toTokenName, toYamlScalar };
248
- //# sourceMappingURL=index.d.mts.map
1
+ import { t as extract_d_exports } from "./extract.mjs";
2
+ import { n as generate_d_exports } from "./generate-BPhbyvvs.mjs";
3
+ export { extract_d_exports as extract, generate_d_exports as generate };
package/dist/index.mjs CHANGED
@@ -1,10 +1 @@
1
- import{useExecution as e}from"@power-plant/core";import{definePlugin as t}from"@razorwind/core/plugin";import{readFile as n}from"@stryke/fs/read-file";import{isEmptyObject as r}from"@stryke/type-checks/is-empty-object";import{formatTokenValue as i}from"@razorwind/core/utils";import{normalizeTokenTree as a}from"@razorwind/core/tokens";import{existsSync as o}from"@stryke/fs/exists";import{joinPaths as s}from"@stryke/path/join";import{parse as c}from"yaml";function l(e,t){let n=e.split(`.`).filter(Boolean);for(;n.length>1&&t.includes(n[0].toLowerCase());)n.shift();return n.join(`-`).replaceAll(/[^\w-]+/g,`-`).toLowerCase()}function u(e){if(typeof e==`number`||typeof e==`boolean`)return String(e);let t=String(e);return/^[a-z][\w-]*$/i.test(t)?t:JSON.stringify(t)}function ee(e){return e.split(/[-_.]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}const te=/^(?:light|dark|dim|high-contrast|hc|default|base|theme)(?:[._-].+)?$/i;function d(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function f(e){return`$value`in e||`value`in e||`$ref`in e||`ref`in e}function p(e){if(typeof e.$description==`string`)return e.$description;if(typeof e.description==`string`)return e.description}function m(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function h(e){if(`$value`in e)return e.$value;if(`value`in e)return e.value;if(typeof e.$ref==`string`)return e.$ref;if(typeof e.ref==`string`)return e.ref}function g(e,t,n,r,a){if(!d(e))return;let o=m(e,n);if(f(e)){let n=h(e);a.push({path:t.join(`.`),type:o,value:n,cssValue:i(n,o),description:p(e),theme:r});return}for(let[n,i]of Object.entries(e))n.startsWith(`$`)||g(i,[...t,n],o,r,a)}function _(e){if(!d(e))return[];let t=Object.keys(e).filter(e=>!e.startsWith(`$`));return t.length>0&&t.every(e=>te.test(e))?t.map(t=>({id:t,tokens:e[t]})):[{id:`default`,tokens:e}]}function v(e,t){let n=t?new Set(t):void 0,r=[];for(let t of _(e)){let e=t.id==="default"?void 0:t.id;g(t.tokens,[],void 0,e,r)}return n?r.filter(e=>!e.type||n.has(e.type)):r}const y=new Set([`backgroundColor`,`textColor`,`typography`,`rounded`,`padding`,`size`,`height`,`width`]),ne={background:`backgroundColor`,backgroundcolor:`backgroundColor`,bg:`backgroundColor`,fill:`backgroundColor`,color:`textColor`,foreground:`textColor`,text:`textColor`,textcolor:`textColor`,font:`typography`,radius:`rounded`,borderradius:`rounded`,corner:`rounded`},re=[`color`,`colors`,`palette`],b=[`typography`,`type`,`text`,`font`,`fonts`],x=/(?:^|\.)(?:radius|radii|rounded|corner)(?:\.|$)/i,S=/(?:^|\.)(?:spacing|space|gap)(?:\.|$)/i,C=/^components?$/i,w=/^\{([^}]+)\}$/,T=[`fontFamily`,`fontSize`,`fontWeight`,`lineHeight`,`letterSpacing`];function E(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function D(e){let t=[...new Set(e.map(e=>e.theme))],n=t.find(e=>e===void 0)??t.find(e=>/^light/i.test(e??``))??t.find(e=>/^(?:default|base)/i.test(e??``))??t[0];return e.filter(e=>e.theme===n)}function O(e){if(typeof e==`string`)return w.exec(e.trim())?.[1]}function k(e,t){let n=e;for(let e=0;e<8;e++){let e=O(n.value);if(!e)return n;let r=t.get(e);if(!r)return n;n=r}return n}function ie(e){return e.split(/[-_.\s]+/).filter(Boolean).map((e,t)=>t===0?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``)}function ae(e){let t=ie(e);return y.has(t)?t:ne[t.toLowerCase()]}function oe(e,t){let n={};if(!E(e))return n;for(let r of T){let a=e[r];if(a==null)continue;let o=O(a),s=o?t.get(o):void 0,c=s?k(s,t).cssValue:void 0;if(typeof a==`number`){n[r]=a;continue}n[r]=c??i(a)}return n}function A(e,t={}){let n=D(v(e.tokens)),r=new Map(n.map(e=>[e.path,e])),i={name:t.name??`Razorwind Design System`,description:t.description,version:t.version??`alpha`,colors:{},colorDescriptions:{},typography:{},rounded:{},spacing:{},components:{}},a=new Map,o=[];for(let e of n){let t=e.path.split(`.`);if(t[0]&&C.test(t[0])){o.push(e);continue}if(e.type===`color`){let t=l(e.path,re),n=k(e,r);i.colors[t]=n.cssValue,e.description&&(i.colorDescriptions[t]=e.description),a.set(e.path,`colors.${t}`);continue}if(e.type===`typography`){let t=l(e.path,b);i.typography[t]=oe(e.value,r),a.set(e.path,`typography.${t}`);continue}if(e.type===`fontFamily`){let t=l(e.path,b);i.typography[t]??={},i.typography[t].fontFamily=e.cssValue,a.set(e.path,`typography.${t}`);continue}let n=e.type===`dimension`||e.type===`number`||typeof e.value==`number`;if(n&&x.test(e.path)){let n=t.at(-1);i.rounded[n]=k(e,r).cssValue,a.set(e.path,`rounded.${n}`);continue}if(n&&S.test(e.path)){let n=t.at(-1);i.spacing[n]=k(e,r).cssValue,a.set(e.path,`spacing.${n}`)}}for(let e of o){let t=e.path.split(`.`).slice(1);if(t.length<2)continue;let n=ae(t.at(-1));if(!n)continue;let o=t.slice(0,-1).join(`-`).replaceAll(/[^\w-]+/g,`-`).toLowerCase(),s=O(e.value),c=s?a.get(s):void 0,l=c?`{${c}}`:k(e,r).cssValue;i.components[o]??={},i.components[o][n]=l}return i}function j(e,t,n){let r=Object.entries(t);if(r.length!==0){n.push(`${e}:`);for(let[e,t]of r){if(typeof t==`object`&&t){n.push(` ${e}:`);for(let[e,r]of Object.entries(t))n.push(` ${e}: ${u(r)}`);continue}n.push(` ${e}: ${u(t)}`)}}}function M(e){let t=[`---`];return e.version&&t.push(`version: ${u(e.version)}`),t.push(`name: ${u(e.name)}`),e.description&&t.push(`description: ${u(e.description)}`),j(`colors`,e.colors,t),j(`typography`,e.typography,t),j(`rounded`,e.rounded,t),j(`spacing`,e.spacing,t),j(`components`,e.components,t),t.push(`---`),`${t.join(`
2
- `)}\n`}function N(e,...t){return`## ${e}\n\n${t.filter(Boolean).join(`
3
- `)}\n`}function P(e){let t=[[Object.keys(e.colors).length,`color`],[Object.keys(e.typography).length,`typography`],[Object.keys(e.rounded).length,`shape`],[Object.keys(e.spacing).length,`spacing`],[Object.keys(e.components).length,`component`]].filter(([e])=>e>0).map(([e,t])=>`${e} ${t} token${e===1?``:`s`}`).join(`, `);return`${e.name} design tokens${t?` — ${t}`:``}. The YAML front matter above is the normative source; the prose below explains how to apply it.`}function F(e,t={}){let n=[N(`Overview`,t.overview??P(e))],r=Object.entries(e.colors);r.length>0&&n.push(N(`Colors`,r.map(([t,n])=>{let r=e.colorDescriptions[t];return`- **${ee(t)} (${n}):**${r?` ${r}`:``}`}).join(`
4
- `)));let i=Object.entries(e.typography);i.length>0&&n.push(N(`Typography`,i.map(([e,t])=>`- **${e}:** ${Object.entries(t).map(([e,t])=>`${e}: ${t}`).join(`, `)}`).join(`
5
- `)));let a=Object.entries(e.spacing);a.length>0&&n.push(N(`Layout`,`Spacing scale:`,``,a.map(([e,t])=>`- **${e}:** ${t}`).join(`
6
- `)));let o=Object.entries(e.rounded);o.length>0&&n.push(N(`Shapes`,`Corner radius scale:`,``,o.map(([e,t])=>`- **${e}:** ${t}`).join(`
7
- `)));let s=Object.entries(e.components);return s.length>0&&n.push(N(`Components`,s.map(([e,t])=>`- **${e}:** ${Object.entries(t).map(([e,t])=>`${e}: \`${t}\``).join(`, `)}`).join(`
8
- `))),n.join(`
9
- `)}function I(e,t={}){return`${M(e)}\n${F(e,t)}`}function L(e,t={}){let n=t.outFile??`DESIGN.md`,r=A(e,t);return{[n]:{path:n,language:`markdown`,chunks:[{content:I(r,t),meta:{name:`razorwind-design-md`}}]}}}const R=/(?:^|[/\\])design\.md$/i,z=[`DESIGN.md`,`design.md`,`docs/DESIGN.md`],B=/^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,V=/^\{[^{}]+\}$/,H=new Set([`version`,`name`,`description`]),U=[`fontFamily`,`fontSize`,`fontWeight`,`lineHeight`,`letterSpacing`,`fontFeature`,`fontVariation`],W={backgroundColor:`color`,textColor:`color`,typography:`typography`,rounded:`dimension`,padding:`dimension`,size:`dimension`,height:`dimension`,width:`dimension`};function G(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function K(e){return typeof e==`string`&&V.test(e.trim())}function q(e){return typeof e==`number`?`${e}px`:e}function J(e){let t={};for(let n of U){let r=e[n];r!=null&&(t[n]=r)}for(let[n,r]of Object.entries(e))!(n in t)&&r!=null&&(typeof r==`string`||typeof r==`number`)&&(t[n]=r);return t}function Y(e,t,n=!1){let r={};for(let[i,a]of Object.entries(e))a!=null&&(r[i]={$type:t,$value:K(a)?a.trim():n?q(a):a});return r}function se(e){let t={};for(let[n,r]of Object.entries(e))K(r)?t[n]={$type:`typography`,$value:r.trim()}:G(r)&&(t[n]={$type:`typography`,$value:J(r)});return t}function ce(e){let t={};for(let[n,r]of Object.entries(e)){if(!G(r))continue;let e={};for(let[t,n]of Object.entries(r)){if(n==null)continue;let r=W[t];e[t]={...r?{$type:r}:{},$value:K(n)?n.trim():r===`typography`&&G(n)?J(n):q(n)}}Object.keys(e).length>0&&(t[n]=e)}return t}function X(e){let t=B.exec(e);if(!t?.[1])return;let n;try{n=c(t[1])}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Failed to parse DESIGN.md front matter as YAML: ${t}`)}return G(n)?n:void 0}function Z(e){let t={};for(let[n,r]of Object.entries(e))if(!(H.has(n)||!G(r)))switch(n){case`colors`:t[n]=Y(r,`color`);break;case`typography`:t[n]=se(r);break;case`rounded`:case`spacing`:t[n]=Y(r,`dimension`,!0);break;case`components`:t[n]=ce(r);break;default:t[n]=r;break}return a(t)}function Q(e){let t=X(e);return t?Z(t):{}}function le(e){return R.test(e)}function $(e){for(let t of z){let n=s(e,t);if(o(n))return n}}var ue=t((t={})=>({name:`razorwind-design-md`,parsers:[{name:`razorwind-design-md`,pattern:R,parser:e=>Q(e)}],extract:async(i,a)=>{if(i.tokens&&!r(i.tokens))return i;let o=t.path;if(!o){let{cwd:t}=e();if(o=$(t),!o)return i}let s=Q(await n(o));return!s||r(s)?i:{...i,tokens:s}},generate:async(e,t)=>L(e,t)}));export{R as DESIGN_MD_FILE_PATTERN,z as DESIGN_MD_PATH_CANDIDATES,ue as default,Z as designMdToTokens,A as extractDesignMd,X as extractDesignMdFrontMatter,v as flattenTokens,i as formatTokenValue,L as generateDesignMd,le as isDesignMdFile,Q as parseDesignMdTokens,F as renderBody,I as renderDesignMd,M as renderFrontMatter,$ as resolveDesignMdPath,_ as resolveTokenSets,D as selectPrimaryTheme,l as toTokenName,u as toYamlScalar};
10
- //# sourceMappingURL=index.mjs.map
1
+ import{t as e}from"./extract.mjs";import{n as t}from"./generate-DFy3tlPT.mjs";export{e as extract,t as generate};
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};export{t};
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@razorwind/design-md",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
- "description": "Razorwind design-md package that can create a DESIGN.md design-system specification file from design tokens or read a DESIGN.md file and return the design-system specification.",
5
+ "description": "Razorwind DESIGN.md plugin that can create a DESIGN.md design-system specification file from design tokens or read a DESIGN.md file and return the design-system specification.",
6
6
  "repository": {
7
7
  "type": "github",
8
8
  "url": "https://github.com/storm-software/razorwind.git",
@@ -43,6 +43,34 @@
43
43
  "default": "./dist/index.mjs"
44
44
  }
45
45
  },
46
+ "./extract": {
47
+ "require": {
48
+ "types": "./dist/extract.d.cts",
49
+ "default": "./dist/extract.cjs"
50
+ },
51
+ "import": {
52
+ "types": "./dist/extract.d.mts",
53
+ "default": "./dist/extract.mjs"
54
+ },
55
+ "default": {
56
+ "types": "./dist/extract.d.mts",
57
+ "default": "./dist/extract.mjs"
58
+ }
59
+ },
60
+ "./generate": {
61
+ "require": {
62
+ "types": "./dist/generate.d.cts",
63
+ "default": "./dist/generate.cjs"
64
+ },
65
+ "import": {
66
+ "types": "./dist/generate.d.mts",
67
+ "default": "./dist/generate.mjs"
68
+ },
69
+ "default": {
70
+ "types": "./dist/generate.d.mts",
71
+ "default": "./dist/generate.mjs"
72
+ }
73
+ },
46
74
  "./package.json": "./package.json"
47
75
  },
48
76
  "main": "./dist/index.cjs",
@@ -50,9 +78,9 @@
50
78
  "types": "./dist/index.d.cts",
51
79
  "typings": "dist/index.d.mts",
52
80
  "dependencies": {
53
- "@power-plant/core": "^0.0.37",
81
+ "@power-plant/core": "^0.0.40",
54
82
  "@power-plant/dtcg-schema": "^0.0.1",
55
- "@razorwind/core": "^0.0.8",
83
+ "@razorwind/core": "^0.0.10",
56
84
  "@stryke/fs": "^0.33.99",
57
85
  "@stryke/path": "^0.29.25",
58
86
  "@stryke/type-checks": "^0.6.31",
@@ -60,10 +88,10 @@
60
88
  "yaml": "^2.9.0"
61
89
  },
62
90
  "devDependencies": {
63
- "@powerlines/plugin-tsdown": "^0.1.560",
91
+ "@powerlines/plugin-tsdown": "^0.1.561",
64
92
  "@types/node": "^25.9.5",
65
93
  "typescript": "^6.0.3"
66
94
  },
67
95
  "publishConfig": { "access": "public" },
68
- "gitHead": "1d74276595c13888022fafaa5f501092dc8e03a0"
96
+ "gitHead": "35f5d31c337fdedeb003c0d9eca72949d4305437"
69
97
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/extract.ts","../src/flatten.ts","../src/format.ts","../src/generate.ts","../src/load.ts","../src/index.ts"],"mappings":";;;;;;;;;UAuBiB;;;;;;EAMf;;;;;;EAOA;;;;EAKA;;;;;;EAOA;;;;;EAMA;;;;;UAMe;;EAEf;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;EAEA;;;;;;UAOe;EACf;EACA;EACA;EACA;EACA;;;;;;;KAQU,iBAAiB;;;;;UAMZ;EACf;EACA;EACA;EACA,QAAQ;;EAER,mBAAmB;EACnB,YAAY,eAAe;EAC3B,SAAS;EACT,SAAS;EACT,YAAY,eAAe;;;;;;;;;iBC5Bb,mBAAmB,MAAM,cAAc;;;;;;;;;iBA6GvC,gBACd,MAAM,QACN,UAAS,UACR;;;UCpFc;EACf;EACA,QAAQ;;;;;;;;iBASM,iBACd,QAAQ,SAAS,eAAe,UAC/B;;;;iBAsBa,cACd,QAAQ,SAAS,eAAe,SAChC,eAAe,cACd;;;;;;;;;;;;;iBCpHa,YAAY,cAAc;;;;;iBAoB1B,aAAa;;;;;;iBCIb,kBAAkB,UAAU;;;;;;iBAgD5B,WACd,UAAU,kBACV,UAAS;;;;;;;iBA6FK,eACd,UAAU,kBACV,UAAS;;;;;;;iBAWK,iBACd,MAAM,QACN,UAAS,UACR,wBAAwB,QAAQ;;;;;;;cCzLtB,wBAAsB;;cAGtB;;;;;;;;iBAiLG,2BACd,mBACC;;;;;;;;;;;;;;iBAgCa,iBACd,aAAa,0BACZ;;;;;;;;iBAwCa,oBAAoB,mBAAmB;;;;;;;iBAevC,eAAe;;;;;;;iBAUf,oBAAoB;;;UC7PnB;;;;;;EAMf"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/extract.ts","../src/flatten.ts","../src/format.ts","../src/generate.ts","../src/load.ts","../src/index.ts"],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":[],"mappings":""}