@bezel-labs/bezel-kit 0.1.0
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/LICENSE +93 -0
- package/README.md +69 -0
- package/dist/chunk-5EW7EW3R.js +370 -0
- package/dist/chunk-5EW7EW3R.js.map +1 -0
- package/dist/chunk-WLGTZBXW.js +139 -0
- package/dist/chunk-WLGTZBXW.js.map +1 -0
- package/dist/cli.cjs +567 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +93 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +401 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +133 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/node.cjs +530 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +73 -0
- package/dist/node.d.ts +73 -0
- package/dist/node.js +31 -0
- package/dist/node.js.map +1 -0
- package/package.json +76 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the pure CSS transform ({@link tokensToCss}/{@link emitCss}),
|
|
3
|
+
* decoupled from any filesystem concern so they work in any environment.
|
|
4
|
+
* All optional; defaults make the zero-config case work.
|
|
5
|
+
*/
|
|
6
|
+
interface CssOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Map of context name → CSS selector. The first entry is the base context (full
|
|
9
|
+
* output); every other context emits only the variables that differ from the base.
|
|
10
|
+
* Default: `{ "$root": ":root", "dark": ".dark", "light": ".light" }`.
|
|
11
|
+
*/
|
|
12
|
+
contexts?: Record<string, string>;
|
|
13
|
+
/** Color serialization. Default: `"oklch"`. */
|
|
14
|
+
colorFormat?: "oklch" | "hex";
|
|
15
|
+
/** Dimension handling: keep the authored unit, or convert `px` → `rem`. Default: `"preserve"`. */
|
|
16
|
+
dimensionUnit?: "preserve" | "rem";
|
|
17
|
+
/** `$extensions` key holding the `exportName` array. Default: `"com.tokendesigner.app"`. */
|
|
18
|
+
nameExtension?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Fully-resolved CSS-transform options (no `undefined`). */
|
|
21
|
+
interface ResolvedCssOptions {
|
|
22
|
+
contexts: Record<string, string>;
|
|
23
|
+
colorFormat: "oklch" | "hex";
|
|
24
|
+
dimensionUnit: "preserve" | "rem";
|
|
25
|
+
nameExtension: string;
|
|
26
|
+
}
|
|
27
|
+
/** Apply defaults to {@link CssOptions}. Pure — no path resolution, no `node:*`. */
|
|
28
|
+
declare function resolveCssOptions(options?: CssOptions): ResolvedCssOptions;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Minimal type surface for the W3C Design Tokens (DTCG) 2025.10 format, plus
|
|
32
|
+
* the internal shapes the generator passes between stages.
|
|
33
|
+
*
|
|
34
|
+
* @see https://www.designtokens.org/tr/2025.10/format/
|
|
35
|
+
*/
|
|
36
|
+
/** A DTCG color value (e.g. `{ colorSpace: "oklch", components: [...], hex, alpha }`). */
|
|
37
|
+
interface ColorValue {
|
|
38
|
+
colorSpace: string;
|
|
39
|
+
components: number[];
|
|
40
|
+
hex?: string;
|
|
41
|
+
alpha?: number;
|
|
42
|
+
}
|
|
43
|
+
/** A DTCG dimension value (e.g. `{ value: 12, unit: "px" }`). */
|
|
44
|
+
interface DimensionValue {
|
|
45
|
+
value: number;
|
|
46
|
+
unit: string;
|
|
47
|
+
}
|
|
48
|
+
/** Any DTCG token value: a literal, a reference string `"{a.b.c}"`, or a typed object. */
|
|
49
|
+
type TokenValue = string | number | ColorValue | DimensionValue | (string | number)[] | Record<string, unknown>;
|
|
50
|
+
/**
|
|
51
|
+
* An arbitrary DTCG node — either a group (nested nodes) or a token (`$value`).
|
|
52
|
+
* Indexed loosely because we walk it structurally rather than by a fixed schema.
|
|
53
|
+
*/
|
|
54
|
+
interface DtcgNode {
|
|
55
|
+
$value?: TokenValue;
|
|
56
|
+
$type?: string;
|
|
57
|
+
$description?: string;
|
|
58
|
+
$extensions?: Record<string, unknown>;
|
|
59
|
+
[key: string]: unknown;
|
|
60
|
+
}
|
|
61
|
+
/** A single logical token after the tree has been collapsed + flattened for one context. */
|
|
62
|
+
interface FlatToken {
|
|
63
|
+
/** Dot-path of the token in the source tree (contexts already stripped). */
|
|
64
|
+
path: string;
|
|
65
|
+
/** The token's value for the active context (may still be a `"{ref}"`). */
|
|
66
|
+
value: TokenValue;
|
|
67
|
+
/** Resolved/inherited `$type`, if known. */
|
|
68
|
+
type?: string;
|
|
69
|
+
/** Vendor extensions carried through from the source token. */
|
|
70
|
+
extensions?: Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Pure default constants shared by the isomorphic core and the Node layer.
|
|
75
|
+
* Kept free of `node:*` imports so the browser/edge entry can use them.
|
|
76
|
+
*/
|
|
77
|
+
/** Default context → selector mapping. The first key is the base context. */
|
|
78
|
+
declare const DEFAULT_CONTEXTS: Record<string, string>;
|
|
79
|
+
declare const DEFAULT_NAME_EXTENSION = "com.tokendesigner.app";
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Convert a DTCG token tree into a scoped CSS string. The first context in
|
|
83
|
+
* `options.contexts` is the base (emitted in full); every other context emits
|
|
84
|
+
* only the variables whose value differs from the base.
|
|
85
|
+
*/
|
|
86
|
+
declare function emitCss(tokens: DtcgNode, options: ResolvedCssOptions): string;
|
|
87
|
+
|
|
88
|
+
/** Name the `$root` context maps to in generated output (matches the `:root` CSS scope). */
|
|
89
|
+
declare const DEFAULT_CONTEXT_NAME = "default";
|
|
90
|
+
/**
|
|
91
|
+
* Extract the distinct context names declared anywhere in a DTCG token tree.
|
|
92
|
+
*
|
|
93
|
+
* Walks to each logical token (a node with a `$root` context wrapper) and collects the
|
|
94
|
+
* context keys it declares (`$root`, `dark`, `light`, …). `$root` is mapped to
|
|
95
|
+
* `"default"` and placed first; the rest follow in first-seen order, deduped.
|
|
96
|
+
*/
|
|
97
|
+
declare function getContexts(tokens: DtcgNode, rootName?: string): string[];
|
|
98
|
+
/** Render the generated `contexts.ts` module emitted alongside `variables.css`. */
|
|
99
|
+
declare function formatContextsModule(contexts: string[]): string;
|
|
100
|
+
|
|
101
|
+
/** A web font to load: a family name and the weights it is used at. */
|
|
102
|
+
interface FontDef {
|
|
103
|
+
family: string;
|
|
104
|
+
weights: number[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Extract the web fonts referenced by a DTCG token tree.
|
|
108
|
+
*
|
|
109
|
+
* Collects every distinct `fontFamily` value (references resolved), then derives each
|
|
110
|
+
* family's weights from the semantic typography composites — a group whose `font-family`
|
|
111
|
+
* resolves to that family contributes its sibling `font-weight`. Families used without an
|
|
112
|
+
* accompanying weight default to `[400]`. Result is sorted by family for determinism.
|
|
113
|
+
*/
|
|
114
|
+
declare function getFonts(tokens: DtcgNode): FontDef[];
|
|
115
|
+
/** Render the generated `fonts.ts` module emitted alongside `variables.css`. */
|
|
116
|
+
declare function formatFontsModule(fonts: FontDef[]): string;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Convert a DTCG token object into a scoped `variables.css` string.
|
|
120
|
+
*
|
|
121
|
+
* Resolves each configured context (with `$root` fallback and reference
|
|
122
|
+
* resolution) and emits one CSS scope per context — the base context in full,
|
|
123
|
+
* others as override-only blocks. Pure: no filesystem access.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* const css = tokensToCss(tokens)
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* const css = tokensToCss(tokens, { colorFormat: "hex", contexts: { $root: ":root" } })
|
|
130
|
+
*/
|
|
131
|
+
declare function tokensToCss(tokens: DtcgNode, options?: CssOptions): string;
|
|
132
|
+
|
|
133
|
+
export { type ColorValue, type CssOptions, DEFAULT_CONTEXTS, DEFAULT_CONTEXT_NAME, DEFAULT_NAME_EXTENSION, type DimensionValue, type DtcgNode, type FlatToken, type FontDef, type ResolvedCssOptions, type TokenValue, emitCss, formatContextsModule, formatFontsModule, getContexts, getFonts, resolveCssOptions, tokensToCss };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the pure CSS transform ({@link tokensToCss}/{@link emitCss}),
|
|
3
|
+
* decoupled from any filesystem concern so they work in any environment.
|
|
4
|
+
* All optional; defaults make the zero-config case work.
|
|
5
|
+
*/
|
|
6
|
+
interface CssOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Map of context name → CSS selector. The first entry is the base context (full
|
|
9
|
+
* output); every other context emits only the variables that differ from the base.
|
|
10
|
+
* Default: `{ "$root": ":root", "dark": ".dark", "light": ".light" }`.
|
|
11
|
+
*/
|
|
12
|
+
contexts?: Record<string, string>;
|
|
13
|
+
/** Color serialization. Default: `"oklch"`. */
|
|
14
|
+
colorFormat?: "oklch" | "hex";
|
|
15
|
+
/** Dimension handling: keep the authored unit, or convert `px` → `rem`. Default: `"preserve"`. */
|
|
16
|
+
dimensionUnit?: "preserve" | "rem";
|
|
17
|
+
/** `$extensions` key holding the `exportName` array. Default: `"com.tokendesigner.app"`. */
|
|
18
|
+
nameExtension?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Fully-resolved CSS-transform options (no `undefined`). */
|
|
21
|
+
interface ResolvedCssOptions {
|
|
22
|
+
contexts: Record<string, string>;
|
|
23
|
+
colorFormat: "oklch" | "hex";
|
|
24
|
+
dimensionUnit: "preserve" | "rem";
|
|
25
|
+
nameExtension: string;
|
|
26
|
+
}
|
|
27
|
+
/** Apply defaults to {@link CssOptions}. Pure — no path resolution, no `node:*`. */
|
|
28
|
+
declare function resolveCssOptions(options?: CssOptions): ResolvedCssOptions;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Minimal type surface for the W3C Design Tokens (DTCG) 2025.10 format, plus
|
|
32
|
+
* the internal shapes the generator passes between stages.
|
|
33
|
+
*
|
|
34
|
+
* @see https://www.designtokens.org/tr/2025.10/format/
|
|
35
|
+
*/
|
|
36
|
+
/** A DTCG color value (e.g. `{ colorSpace: "oklch", components: [...], hex, alpha }`). */
|
|
37
|
+
interface ColorValue {
|
|
38
|
+
colorSpace: string;
|
|
39
|
+
components: number[];
|
|
40
|
+
hex?: string;
|
|
41
|
+
alpha?: number;
|
|
42
|
+
}
|
|
43
|
+
/** A DTCG dimension value (e.g. `{ value: 12, unit: "px" }`). */
|
|
44
|
+
interface DimensionValue {
|
|
45
|
+
value: number;
|
|
46
|
+
unit: string;
|
|
47
|
+
}
|
|
48
|
+
/** Any DTCG token value: a literal, a reference string `"{a.b.c}"`, or a typed object. */
|
|
49
|
+
type TokenValue = string | number | ColorValue | DimensionValue | (string | number)[] | Record<string, unknown>;
|
|
50
|
+
/**
|
|
51
|
+
* An arbitrary DTCG node — either a group (nested nodes) or a token (`$value`).
|
|
52
|
+
* Indexed loosely because we walk it structurally rather than by a fixed schema.
|
|
53
|
+
*/
|
|
54
|
+
interface DtcgNode {
|
|
55
|
+
$value?: TokenValue;
|
|
56
|
+
$type?: string;
|
|
57
|
+
$description?: string;
|
|
58
|
+
$extensions?: Record<string, unknown>;
|
|
59
|
+
[key: string]: unknown;
|
|
60
|
+
}
|
|
61
|
+
/** A single logical token after the tree has been collapsed + flattened for one context. */
|
|
62
|
+
interface FlatToken {
|
|
63
|
+
/** Dot-path of the token in the source tree (contexts already stripped). */
|
|
64
|
+
path: string;
|
|
65
|
+
/** The token's value for the active context (may still be a `"{ref}"`). */
|
|
66
|
+
value: TokenValue;
|
|
67
|
+
/** Resolved/inherited `$type`, if known. */
|
|
68
|
+
type?: string;
|
|
69
|
+
/** Vendor extensions carried through from the source token. */
|
|
70
|
+
extensions?: Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Pure default constants shared by the isomorphic core and the Node layer.
|
|
75
|
+
* Kept free of `node:*` imports so the browser/edge entry can use them.
|
|
76
|
+
*/
|
|
77
|
+
/** Default context → selector mapping. The first key is the base context. */
|
|
78
|
+
declare const DEFAULT_CONTEXTS: Record<string, string>;
|
|
79
|
+
declare const DEFAULT_NAME_EXTENSION = "com.tokendesigner.app";
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Convert a DTCG token tree into a scoped CSS string. The first context in
|
|
83
|
+
* `options.contexts` is the base (emitted in full); every other context emits
|
|
84
|
+
* only the variables whose value differs from the base.
|
|
85
|
+
*/
|
|
86
|
+
declare function emitCss(tokens: DtcgNode, options: ResolvedCssOptions): string;
|
|
87
|
+
|
|
88
|
+
/** Name the `$root` context maps to in generated output (matches the `:root` CSS scope). */
|
|
89
|
+
declare const DEFAULT_CONTEXT_NAME = "default";
|
|
90
|
+
/**
|
|
91
|
+
* Extract the distinct context names declared anywhere in a DTCG token tree.
|
|
92
|
+
*
|
|
93
|
+
* Walks to each logical token (a node with a `$root` context wrapper) and collects the
|
|
94
|
+
* context keys it declares (`$root`, `dark`, `light`, …). `$root` is mapped to
|
|
95
|
+
* `"default"` and placed first; the rest follow in first-seen order, deduped.
|
|
96
|
+
*/
|
|
97
|
+
declare function getContexts(tokens: DtcgNode, rootName?: string): string[];
|
|
98
|
+
/** Render the generated `contexts.ts` module emitted alongside `variables.css`. */
|
|
99
|
+
declare function formatContextsModule(contexts: string[]): string;
|
|
100
|
+
|
|
101
|
+
/** A web font to load: a family name and the weights it is used at. */
|
|
102
|
+
interface FontDef {
|
|
103
|
+
family: string;
|
|
104
|
+
weights: number[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Extract the web fonts referenced by a DTCG token tree.
|
|
108
|
+
*
|
|
109
|
+
* Collects every distinct `fontFamily` value (references resolved), then derives each
|
|
110
|
+
* family's weights from the semantic typography composites — a group whose `font-family`
|
|
111
|
+
* resolves to that family contributes its sibling `font-weight`. Families used without an
|
|
112
|
+
* accompanying weight default to `[400]`. Result is sorted by family for determinism.
|
|
113
|
+
*/
|
|
114
|
+
declare function getFonts(tokens: DtcgNode): FontDef[];
|
|
115
|
+
/** Render the generated `fonts.ts` module emitted alongside `variables.css`. */
|
|
116
|
+
declare function formatFontsModule(fonts: FontDef[]): string;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Convert a DTCG token object into a scoped `variables.css` string.
|
|
120
|
+
*
|
|
121
|
+
* Resolves each configured context (with `$root` fallback and reference
|
|
122
|
+
* resolution) and emits one CSS scope per context — the base context in full,
|
|
123
|
+
* others as override-only blocks. Pure: no filesystem access.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* const css = tokensToCss(tokens)
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* const css = tokensToCss(tokens, { colorFormat: "hex", contexts: { $root: ":root" } })
|
|
130
|
+
*/
|
|
131
|
+
declare function tokensToCss(tokens: DtcgNode, options?: CssOptions): string;
|
|
132
|
+
|
|
133
|
+
export { type ColorValue, type CssOptions, DEFAULT_CONTEXTS, DEFAULT_CONTEXT_NAME, DEFAULT_NAME_EXTENSION, type DimensionValue, type DtcgNode, type FlatToken, type FontDef, type ResolvedCssOptions, type TokenValue, emitCss, formatContextsModule, formatFontsModule, getContexts, getFonts, resolveCssOptions, tokensToCss };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_CONTEXTS,
|
|
3
|
+
DEFAULT_CONTEXT_NAME,
|
|
4
|
+
DEFAULT_NAME_EXTENSION,
|
|
5
|
+
emitCss,
|
|
6
|
+
formatContextsModule,
|
|
7
|
+
formatFontsModule,
|
|
8
|
+
getContexts,
|
|
9
|
+
getFonts,
|
|
10
|
+
resolveCssOptions,
|
|
11
|
+
tokensToCss
|
|
12
|
+
} from "./chunk-5EW7EW3R.js";
|
|
13
|
+
export {
|
|
14
|
+
DEFAULT_CONTEXTS,
|
|
15
|
+
DEFAULT_CONTEXT_NAME,
|
|
16
|
+
DEFAULT_NAME_EXTENSION,
|
|
17
|
+
emitCss,
|
|
18
|
+
formatContextsModule,
|
|
19
|
+
formatFontsModule,
|
|
20
|
+
getContexts,
|
|
21
|
+
getFonts,
|
|
22
|
+
resolveCssOptions,
|
|
23
|
+
tokensToCss
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|