@marianmeres/design-tokens 1.5.0 → 1.6.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/AGENTS.md CHANGED
@@ -55,7 +55,7 @@ Entry points:
55
55
  | --------------------------------------------- | --------------------------------------------------------------------------------------------------- |
56
56
  | `generateCssTokens(schema, prefix, options?)` | Generate token key-value pairs. Third arg: `GenerateOptions` object or `"light"`/`"dark"` shorthand |
57
57
  | `toCssString(tokens, selector?)` | Convert tokens to a CSS declaration block (groups by base color name) |
58
- | `generateThemeCss(schema, prefix, options?)` | Generate complete CSS for light + optional dark mode; supports `cssLayer` wrapping |
58
+ | `generateThemeCss(schema, prefix, options?)` | Generate complete CSS for light + optional dark mode; supports `cssLayer` wrapping and `prettierIgnore` pragma |
59
59
  | `hexToRgb(hex)` | Parse hex to `[r, g, b]` tuple |
60
60
  | `hexToRgbTriplet(hex)` | Convert hex to `"r, g, b"` string |
61
61
 
@@ -83,7 +83,7 @@ Entry points:
83
83
  | `SingleColor` | `string \| ColorValue` |
84
84
  | `GeneratedTokens` | `Record<string, string>` |
85
85
  | `GenerateOptions` | `{ mode?, deriveStates?, surfaceForegroundContrast? }` |
86
- | `GenerateThemeOptions` | `Omit<GenerateOptions, "mode"> & { cssLayer? }` |
86
+ | `GenerateThemeOptions` | `Omit<GenerateOptions, "mode"> & { cssLayer?, prettierIgnore? }` |
87
87
  | `RolePairedKey` | Required: `"background" \| "muted" \| "surface"` |
88
88
  | `RolePairedOptionalKey` | Optional: `"surface-1"` (all bundled themes ship it) |
89
89
 
package/API.md CHANGED
@@ -71,6 +71,7 @@ Generate complete CSS for a theme with light mode and optional dark mode.
71
71
  - `prefix` (`string`) — CSS variable prefix (trailing dash optional)
72
72
  - `options` (`GenerateThemeOptions`, optional) — Accepts all `GenerateOptions` (except `mode`, which is set per section) plus:
73
73
  - `cssLayer` (`string`, optional) — Wrap the output in `@layer {name} { ... }`. Useful for CSS cascade control.
74
+ - `prettierIgnore` (`boolean`, optional) — Prepend a `/* prettier-ignore */` comment so Prettier preserves the generated whitespace alignment when the output is written to a file that later gets formatted. Default: `false`.
74
75
 
75
76
  **Returns:** `string` — Complete CSS with `:root` for light and `:root.dark` for dark mode, optionally wrapped in `@layer`.
76
77
 
@@ -290,10 +291,11 @@ Options passed to `generateCssTokens`. See the function docs above for field mea
290
291
  ```typescript
291
292
  type GenerateThemeOptions = Omit<GenerateOptions, "mode"> & {
292
293
  cssLayer?: string;
294
+ prettierIgnore?: boolean;
293
295
  };
294
296
  ```
295
297
 
296
- Options passed to `generateThemeCss`. Omits `mode` (set automatically per section) and adds `cssLayer` for optional `@layer` wrapping.
298
+ Options passed to `generateThemeCss`. Omits `mode` (set automatically per section) and adds `cssLayer` for optional `@layer` wrapping plus `prettierIgnore` to prepend a `/* prettier-ignore */` pragma for build pipelines that pass the output through Prettier.
297
299
 
298
300
  ---
299
301
 
@@ -32,6 +32,15 @@ export type GenerateThemeOptions = Omit<GenerateOptions, "mode"> & {
32
32
  * Wrap the output in `@layer {name} { ... }`. Pass a layer name to enable.
33
33
  */
34
34
  cssLayer?: string;
35
+ /**
36
+ * Prepend a `/* prettier-ignore *\/` comment so Prettier preserves the
37
+ * generated whitespace alignment when the output is written to a file that
38
+ * later gets formatted. Has no runtime effect; only meaningful for build
39
+ * pipelines that pass the result through Prettier.
40
+ *
41
+ * @default false
42
+ */
43
+ prettierIgnore?: boolean;
35
44
  };
36
45
  /**
37
46
  * Generate CSS token key-value pairs from a {@link TokenSchema}.
package/dist/generate.js CHANGED
@@ -55,10 +55,10 @@ function generatePairedColorTokens(tokens, key, pair, prefix) {
55
55
  tokens[`${prefix}color-${key}-hover`] = pair.hover ?? pair.DEFAULT;
56
56
  tokens[`${prefix}color-${key}-active`] = pair.active ?? pair.DEFAULT;
57
57
  tokens[`${prefix}color-${key}-foreground`] = pair.foreground;
58
- tokens[`${prefix}color-${key}-foreground-hover`] = pair.foregroundHover ??
59
- pair.foreground;
60
- tokens[`${prefix}color-${key}-foreground-active`] = pair.foregroundActive ??
61
- pair.foreground;
58
+ tokens[`${prefix}color-${key}-foreground-hover`] =
59
+ pair.foregroundHover ?? pair.foreground;
60
+ tokens[`${prefix}color-${key}-foreground-active`] =
61
+ pair.foregroundActive ?? pair.foreground;
62
62
  }
63
63
  /** Generate color tokens for a single color */
64
64
  function generateSingleColorTokens(tokens, key, color, prefix) {
@@ -85,9 +85,7 @@ function generateSingleColorTokens(tokens, key, color, prefix) {
85
85
  * @param options - Generation options, or a shorthand `"light"`/`"dark"` mode string
86
86
  */
87
87
  export function generateCssTokens(schema, prefix, options = {}) {
88
- const opts = typeof options === "string"
89
- ? { mode: options }
90
- : options;
88
+ const opts = typeof options === "string" ? { mode: options } : options;
91
89
  const mode = opts.mode ?? "light";
92
90
  const deriveStates = opts.deriveStates ?? true;
93
91
  const surfaceContrast = opts.surfaceForegroundContrast ?? 50;
@@ -173,18 +171,34 @@ export function toCssString(tokens, selector = ":root") {
173
171
  * @param options - Generation + output options
174
172
  */
175
173
  export function generateThemeCss(schema, prefix, options = {}) {
176
- const { cssLayer, ...genOptions } = options;
177
- let css = toCssString(generateCssTokens(schema.light, prefix, { ...genOptions, mode: "light" }));
174
+ const { cssLayer, prettierIgnore, ...genOptions } = options;
175
+ const PRETTIER_IGNORE_PREFIX = "/* prettier-ignore */\n";
176
+ let css = toCssString(generateCssTokens(schema.light, prefix, {
177
+ ...genOptions,
178
+ mode: "light",
179
+ }));
180
+ if (!cssLayer && prettierIgnore) {
181
+ css = PRETTIER_IGNORE_PREFIX + css;
182
+ }
178
183
  if (schema.dark) {
179
- css += "\n" +
180
- toCssString(generateCssTokens(schema.dark, prefix, {
181
- ...genOptions,
182
- mode: "dark",
183
- }), ":root.dark");
184
+ let darkCss = toCssString(generateCssTokens(schema.dark, prefix, {
185
+ ...genOptions,
186
+ mode: "dark",
187
+ }), ":root.dark");
188
+ if (!cssLayer && prettierIgnore) {
189
+ darkCss = PRETTIER_IGNORE_PREFIX + darkCss;
190
+ }
191
+ css += "\n" + darkCss;
184
192
  }
185
193
  if (cssLayer) {
186
- const indented = css.split("\n").map((l) => (l ? "\t" + l : l)).join("\n");
194
+ const indented = css
195
+ .split("\n")
196
+ .map((l) => (l ? "\t" + l : l))
197
+ .join("\n");
187
198
  css = `@layer ${cssLayer} {\n${indented}}\n`;
199
+ if (prettierIgnore) {
200
+ css = PRETTIER_IGNORE_PREFIX + css;
201
+ }
188
202
  }
189
203
  return css;
190
204
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/design-tokens",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "type": "module",
5
5
  "main": "dist/mod.js",
6
6
  "types": "dist/mod.d.ts",