@razorwind/design-md 0.0.4 → 0.0.5
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/extract.cjs +1 -0
- package/dist/extract.d.cts +81 -0
- package/dist/extract.d.cts.map +1 -0
- package/dist/extract.d.mts +81 -0
- package/dist/extract.d.mts.map +1 -0
- package/dist/extract.mjs +2 -0
- package/dist/extract.mjs.map +1 -0
- package/dist/generate-BIFtSW2h.cjs +9 -0
- package/dist/generate-BvP-cKvD.d.cts +47 -0
- package/dist/generate-BvP-cKvD.d.cts.map +1 -0
- package/dist/generate-BvP-cKvD.d.mts +47 -0
- package/dist/generate-BvP-cKvD.d.mts.map +1 -0
- package/dist/generate-C7bCox0_.mjs +10 -0
- package/dist/generate-C7bCox0_.mjs.map +1 -0
- package/dist/generate.cjs +1 -0
- package/dist/generate.d.cts +2 -0
- package/dist/generate.d.mts +2 -0
- package/dist/generate.mjs +1 -0
- package/dist/index.cjs +1 -9
- package/dist/index.d.cts +3 -248
- package/dist/index.d.mts +3 -248
- package/dist/index.mjs +1 -10
- package/dist/rolldown-runtime-BIInC43l.cjs +1 -0
- package/dist/rolldown-runtime-DK3Fl9T5.mjs +1 -0
- package/package.json +32 -4
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/extract.cjs
ADDED
|
@@ -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("@stryke/fs/read-file"),i=require("@stryke/type-checks/is-empty-object"),a=require("@razorwind/core/tokens"),o=require("@stryke/fs/exists"),s=require("@stryke/path/join"),c=require("yaml");var l=e.t({DESIGN_MD_FILE_PATTERN:()=>u,DESIGN_MD_PATH_CANDIDATES:()=>d,default:()=>A,designMdToTokens:()=>T,extractDesignMdFrontMatter:()=>w,isDesignMdFile:()=>D,loadDesignMdTokens:()=>k,parseDesignMdTokens:()=>E,resolveDesignMdPath:()=>O});const u=/(?:^|[/\\])design\.md$/i,d=[`DESIGN.md`,`design.md`,`docs/DESIGN.md`],f=/^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,p=/^\{[^{}]+\}$/,m=new Set([`version`,`name`,`description`]),h=[`fontFamily`,`fontSize`,`fontWeight`,`lineHeight`,`letterSpacing`,`fontFeature`,`fontVariation`],g={backgroundColor:`color`,textColor:`color`,typography:`typography`,rounded:`dimension`,padding:`dimension`,size:`dimension`,height:`dimension`,width:`dimension`};function _(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function v(e){return typeof e==`string`&&p.test(e.trim())}function y(e){return typeof e==`number`?`${e}px`:e}function b(e){let t={};for(let n of h){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()}:_(r)&&(t[n]={$type:`typography`,$value:b(r)});return t}function C(e){let t={};for(let[n,r]of Object.entries(e)){if(!_(r))continue;let e={};for(let[t,n]of Object.entries(r)){if(n==null)continue;let r=g[t];e[t]={...r?{$type:r}:{},$value:v(n)?n.trim():r===`typography`&&_(n)?b(n):y(n)}}Object.keys(e).length>0&&(t[n]=e)}return t}function w(e){let t=f.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 _(n)?n:void 0}function T(e){let t={};for(let[n,r]of Object.entries(e))if(!(m.has(n)||!_(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,a.normalizeTokenTree)(t)}function E(e){let t=w(e);return t?T(t):{}}function D(e){return u.test(e)}function O(e){for(let t of d){let n=(0,s.joinPaths)(e,t);if((0,o.existsSync)(n))return n}}async function k(e){let t=O(e);if(t)return E(await(0,r.readFile)(t))}var A=(0,n.definePlugin)((e={})=>({name:`design-md:extract`,parsers:[{name:`design-md`,pattern:u,parser:e=>E(e)}],extract:async n=>{if(n.tokens&&!(0,i.isEmptyObject)(n.tokens))return n;let a=e.path;if(!a){let{cwd:e}=(0,t.useExecution)();if(a=O(e),!a)return n}let o=E(await(0,r.readFile)(a));return!o||(0,i.isEmptyObject)(o)?n:{...n,tokens:o}}}));exports.DESIGN_MD_FILE_PATTERN=u,exports.DESIGN_MD_PATH_CANDIDATES=d,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 l}});
|
|
@@ -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: any;
|
|
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;;;;;;;;iBAiLG,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: any;
|
|
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":""}
|
package/dist/extract.mjs
ADDED
|
@@ -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{readFile as r}from"@stryke/fs/read-file";import{isEmptyObject as i}from"@stryke/type-checks/is-empty-object";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";var l=e({DESIGN_MD_FILE_PATTERN:()=>u,DESIGN_MD_PATH_CANDIDATES:()=>d,default:()=>A,designMdToTokens:()=>T,extractDesignMdFrontMatter:()=>w,isDesignMdFile:()=>D,loadDesignMdTokens:()=>k,parseDesignMdTokens:()=>E,resolveDesignMdPath:()=>O});const u=/(?:^|[/\\])design\.md$/i,d=[`DESIGN.md`,`design.md`,`docs/DESIGN.md`],f=/^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,p=/^\{[^{}]+\}$/,m=new Set([`version`,`name`,`description`]),h=[`fontFamily`,`fontSize`,`fontWeight`,`lineHeight`,`letterSpacing`,`fontFeature`,`fontVariation`],g={backgroundColor:`color`,textColor:`color`,typography:`typography`,rounded:`dimension`,padding:`dimension`,size:`dimension`,height:`dimension`,width:`dimension`};function _(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function v(e){return typeof e==`string`&&p.test(e.trim())}function y(e){return typeof e==`number`?`${e}px`:e}function b(e){let t={};for(let n of h){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()}:_(r)&&(t[n]={$type:`typography`,$value:b(r)});return t}function C(e){let t={};for(let[n,r]of Object.entries(e)){if(!_(r))continue;let e={};for(let[t,n]of Object.entries(r)){if(n==null)continue;let r=g[t];e[t]={...r?{$type:r}:{},$value:v(n)?n.trim():r===`typography`&&_(n)?b(n):y(n)}}Object.keys(e).length>0&&(t[n]=e)}return t}function w(e){let t=f.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 _(n)?n:void 0}function T(e){let t={};for(let[n,r]of Object.entries(e))if(!(m.has(n)||!_(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 a(t)}function E(e){let t=w(e);return t?T(t):{}}function D(e){return u.test(e)}function O(e){for(let t of d){let n=s(e,t);if(o(n))return n}}async function k(e){let t=O(e);if(t)return E(await r(t))}var A=n((e={})=>({name:`design-md:extract`,parsers:[{name:`design-md`,pattern:u,parser:e=>E(e)}],extract:async n=>{if(n.tokens&&!i(n.tokens))return n;let a=e.path;if(!a){let{cwd:e}=t();if(a=O(e),!a)return n}let o=E(await r(a));return!o||i(o)?n:{...n,tokens:o}}}));export{u as DESIGN_MD_FILE_PATTERN,d 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,l as t};
|
|
2
|
+
//# sourceMappingURL=extract.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.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 typeof e==`object`&&!!e&&!Array.isArray(e)}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,r,i,a){if(!s(e))return;let o=u(e,r);if(c(e)){let r=d(e);a.push({path:t.join(`.`),type:o,value:r,cssValue:(0,n.formatTokenValue)(r,o),description:l(e),theme:i});return}for(let[n,r]of Object.entries(e))n.startsWith(`$`)||f(r,[...t,n],o,i,a)}function p(e){if(!s(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 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.t({default:()=>B,selectPrimaryTheme:()=>E});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){return typeof e==`object`&&!!e&&!Array.isArray(e)}function E(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 D(e){if(typeof e==`string`)return C.exec(e.trim())?.[1]}function O(e,t){let n=e;for(let e=0;e<8;e++){let e=D(n.value);if(!e)return n;let r=t.get(e);if(!r)return n;n=r}return n}function k(e){return e.split(/[-_.\s]+/).filter(Boolean).map((e,t)=>t===0?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``)}function A(e){let t=k(e);return g.has(t)?t:_[t.toLowerCase()]}function j(e,t){let r={};if(!T(e))return r;for(let i of w){let a=e[i];if(a==null)continue;let o=D(a),s=o?t.get(o):void 0,c=s?O(s,t).cssValue:void 0;if(typeof a==`number`){r[i]=a;continue}r[i]=c??(0,n.formatTokenValue)(a)}return r}function M(e){let t=E(m(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]&&S.test(t[0])){o.push(e);continue}if(e.type===`color`){let t=r(e.path,v),o=O(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,y);i.typography[t]=j(e.value,n),a.set(e.path,`typography.${t}`);continue}if(e.type===`fontFamily`){let t=r(e.path,y);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&&b.test(e.path)){let r=t.at(-1);i.rounded[r]=O(e,n).cssValue,a.set(e.path,`rounded.${r}`);continue}if(s&&x.test(e.path)){let r=t.at(-1);i.spacing[r]=O(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=A(t.at(-1));if(!r)continue;let o=t.slice(0,-1).join(`-`).replaceAll(/[^\w-]+/g,`-`).toLowerCase(),s=D(e.value),c=s?a.get(s):void 0,l=c?`{${c}}`:O(e,n).cssValue;i.components[o]??={},i.components[o][r]=l}return i}function N(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 P(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)}`),N(`colors`,e.colors,t),N(`typography`,e.typography,t),N(`rounded`,e.rounded,t),N(`spacing`,e.spacing,t),N(`components`,e.components,t),t.push(`---`),`${t.join(`
|
|
2
|
+
`)}\n`}function F(e,...t){return`## ${e}\n\n${t.filter(Boolean).join(`
|
|
3
|
+
`)}\n`}function I(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 L(e,t={}){let n=[F(`Overview`,t.overview??I(e))],r=Object.entries(e.colors);r.length>0&&n.push(F(`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(F(`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(F(`Layout`,`Spacing scale:`,``,o.map(([e,t])=>`- **${e}:** ${t}`).join(`
|
|
6
|
+
`)));let s=Object.entries(e.rounded);s.length>0&&n.push(F(`Shapes`,`Corner radius scale:`,``,s.map(([e,t])=>`- **${e}:** ${t}`).join(`
|
|
7
|
+
`)));let c=Object.entries(e.components);return c.length>0&&n.push(F(`Components`,c.map(([e,t])=>`- **${e}:** ${Object.entries(t).map(([e,t])=>`${e}: \`${t}\``).join(`, `)}`).join(`
|
|
8
|
+
`))),n.join(`
|
|
9
|
+
`)}function R(e,t={}){return`${P(e)}\n${L(e,t)}`}function z(e,t={}){let n=M(e);return{[t.outputPath??`DESIGN.md`]:{path:t.outputPath??`DESIGN.md`,language:`markdown`,chunks:[{content:R(n,t),meta:{name:`razorwind-design-md`}}]}}}var B=(0,t.definePlugin)((e={})=>({name:`design-md:generate`,generate:async t=>z(t,e)}));Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return B}});
|
|
@@ -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: any;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { generate_d_exports as n, selectPrimaryTheme as r, _default as t };
|
|
47
|
+
//# sourceMappingURL=generate-BvP-cKvD.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-BvP-cKvD.d.cts","names":[],"sources":["../src/types.ts","../src/generate.ts"],"mappings":";;;;;UAkEiB;;EAEf;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;EAEA;;;;;;;;;;iBCSc,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: any;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { generate_d_exports as n, selectPrimaryTheme as r, _default as t };
|
|
47
|
+
//# sourceMappingURL=generate-BvP-cKvD.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-BvP-cKvD.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}from"@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 typeof e==`object`&&!!e&&!Array.isArray(e)}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,r,i,a){if(!s(e))return;let o=u(e,r);if(c(e)){let r=d(e);a.push({path:t.join(`.`),type:o,value:r,cssValue:n(r,o),description:l(e),theme:i});return}for(let[n,r]of Object.entries(e))n.startsWith(`$`)||f(r,[...t,n],o,i,a)}function p(e){if(!s(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 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:()=>B,selectPrimaryTheme:()=>E});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){return typeof e==`object`&&!!e&&!Array.isArray(e)}function E(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 D(e){if(typeof e==`string`)return C.exec(e.trim())?.[1]}function O(e,t){let n=e;for(let e=0;e<8;e++){let e=D(n.value);if(!e)return n;let r=t.get(e);if(!r)return n;n=r}return n}function k(e){return e.split(/[-_.\s]+/).filter(Boolean).map((e,t)=>t===0?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``)}function A(e){let t=k(e);return g.has(t)?t:_[t.toLowerCase()]}function j(e,t){let r={};if(!T(e))return r;for(let i of w){let a=e[i];if(a==null)continue;let o=D(a),s=o?t.get(o):void 0,c=s?O(s,t).cssValue:void 0;if(typeof a==`number`){r[i]=a;continue}r[i]=c??n(a)}return r}function M(e){let t=E(m(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]&&S.test(t[0])){o.push(e);continue}if(e.type===`color`){let t=r(e.path,v),o=O(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,y);i.typography[t]=j(e.value,n),a.set(e.path,`typography.${t}`);continue}if(e.type===`fontFamily`){let t=r(e.path,y);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&&b.test(e.path)){let r=t.at(-1);i.rounded[r]=O(e,n).cssValue,a.set(e.path,`rounded.${r}`);continue}if(s&&x.test(e.path)){let r=t.at(-1);i.spacing[r]=O(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=A(t.at(-1));if(!r)continue;let o=t.slice(0,-1).join(`-`).replaceAll(/[^\w-]+/g,`-`).toLowerCase(),s=D(e.value),c=s?a.get(s):void 0,l=c?`{${c}}`:O(e,n).cssValue;i.components[o]??={},i.components[o][r]=l}return i}function N(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 P(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)}`),N(`colors`,e.colors,t),N(`typography`,e.typography,t),N(`rounded`,e.rounded,t),N(`spacing`,e.spacing,t),N(`components`,e.components,t),t.push(`---`),`${t.join(`
|
|
2
|
+
`)}\n`}function F(e,...t){return`## ${e}\n\n${t.filter(Boolean).join(`
|
|
3
|
+
`)}\n`}function I(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 L(e,t={}){let n=[F(`Overview`,t.overview??I(e))],r=Object.entries(e.colors);r.length>0&&n.push(F(`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(F(`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(F(`Layout`,`Spacing scale:`,``,o.map(([e,t])=>`- **${e}:** ${t}`).join(`
|
|
6
|
+
`)));let s=Object.entries(e.rounded);s.length>0&&n.push(F(`Shapes`,`Corner radius scale:`,``,s.map(([e,t])=>`- **${e}:** ${t}`).join(`
|
|
7
|
+
`)));let c=Object.entries(e.components);return c.length>0&&n.push(F(`Components`,c.map(([e,t])=>`- **${e}:** ${Object.entries(t).map(([e,t])=>`${e}: \`${t}\``).join(`, `)}`).join(`
|
|
8
|
+
`))),n.join(`
|
|
9
|
+
`)}function R(e,t={}){return`${P(e)}\n${L(e,t)}`}function z(e,t={}){let n=M(e);return{[t.outputPath??`DESIGN.md`]:{path:t.outputPath??`DESIGN.md`,language:`markdown`,chunks:[{content:R(n,t),meta:{name:`razorwind-design-md`}}]}}}var B=t((e={})=>({name:`design-md:generate`,generate:async t=>z(t,e)}));export{h as n,E as r,B as t};
|
|
10
|
+
//# sourceMappingURL=generate-C7bCox0_.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-C7bCox0_.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./generate-BIFtSW2h.cjs");exports.default=e.t,exports.selectPrimaryTheme=e.r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e,t}from"./generate-C7bCox0_.mjs";export{t as default,e as selectPrimaryTheme};
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
Object.
|
|
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-BIFtSW2h.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 {
|
|
2
|
-
import {
|
|
3
|
-
|
|
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-BvP-cKvD.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 {
|
|
2
|
-
import {
|
|
3
|
-
|
|
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-BvP-cKvD.mjs";
|
|
3
|
+
export { extract_d_exports as extract, generate_d_exports as generate };
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import{
|
|
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-C7bCox0_.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.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Razorwind
|
|
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",
|
|
@@ -52,7 +80,7 @@
|
|
|
52
80
|
"dependencies": {
|
|
53
81
|
"@power-plant/core": "^0.0.37",
|
|
54
82
|
"@power-plant/dtcg-schema": "^0.0.1",
|
|
55
|
-
"@razorwind/core": "^0.0.
|
|
83
|
+
"@razorwind/core": "^0.0.9",
|
|
56
84
|
"@stryke/fs": "^0.33.99",
|
|
57
85
|
"@stryke/path": "^0.29.25",
|
|
58
86
|
"@stryke/type-checks": "^0.6.31",
|
|
@@ -65,5 +93,5 @@
|
|
|
65
93
|
"typescript": "^6.0.3"
|
|
66
94
|
},
|
|
67
95
|
"publishConfig": { "access": "public" },
|
|
68
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "6ca83196e6028c6c051887e6390dbd62dd3b0582"
|
|
69
97
|
}
|
package/dist/index.d.cts.map
DELETED
|
@@ -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"}
|
package/dist/index.d.mts.map
DELETED
|
@@ -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":""}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":[],"mappings":""}
|