@nxds/core 0.9.0 → 0.10.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/README.md CHANGED
@@ -173,7 +173,7 @@ at build time.
173
173
  ### Generate CSS
174
174
 
175
175
  ```bash
176
- pnpm tokens:tailwind # From the repo root: build core and generate @nxds/tailwind CSS
176
+ pnpm tokens:tailwind # From the repo root: generate the token scales, build core and generate @nxds/tailwind CSS
177
177
  ```
178
178
 
179
179
  ### Output Files
@@ -197,4 +197,4 @@ When multi-platform support is needed, tools like Style Dictionary can be added
197
197
  - **Color** is engine-owned: edit the derivation in `src/lib/surface-ladder.ts` / `src/lib/derive-theme.ts` (color primitives live in `tokens/primitives/color.json`).
198
198
  - **Non-color** (spacing, radius, shadow, borderwidth, motion, typography): edit the DTCG token files in `tokens/` (`$value`, `$type`, `$description`).
199
199
 
200
- Then run `make tokens` (or `pnpm tokens:tailwind`) to regenerate CSS; the output is copied into the `@nxds/tailwind` package. A new or renamed token file also needs an import in `src/catalogue/token-files.ts`; `pnpm test:unit` fails until the manifest matches the files on disk.
200
+ Then run `make tokens` (or `pnpm tokens:tailwind`) to regenerate the spacing steps and palette names in `src/lib/token-scales.generated.ts` and the CSS; the CSS is copied into the `@nxds/tailwind` package. A new or renamed token file also needs an import in `src/catalogue/token-files.ts`; `pnpm test:unit` fails until the manifest matches the files on disk.
@@ -2531,10 +2531,33 @@ var color_default = {
2531
2531
  }
2532
2532
  };
2533
2533
 
2534
+ // src/lib/token-scales.generated.ts
2535
+ var PRIMITIVE_PALETTE_NAMES = [
2536
+ "green",
2537
+ "emerald",
2538
+ "teal",
2539
+ "cyan",
2540
+ "sky",
2541
+ "indigo",
2542
+ "violet",
2543
+ "purple",
2544
+ "fuchsia",
2545
+ "pink",
2546
+ "slate",
2547
+ "rose",
2548
+ "lime",
2549
+ "yellow",
2550
+ "blue",
2551
+ "gray",
2552
+ "zinc",
2553
+ "neutral",
2554
+ "stone",
2555
+ "red",
2556
+ "orange",
2557
+ "amber"
2558
+ ];
2559
+
2534
2560
  // src/lib/primitive-palette.ts
2535
- var PRIMITIVE_PALETTE_NAMES = Object.keys(color_default).filter(
2536
- (name) => name !== "white" && name !== "black"
2537
- );
2538
2561
  var rampCache = /* @__PURE__ */ new Map();
2539
2562
  function getPaletteRamp(palette) {
2540
2563
  if (!PRIMITIVE_PALETTE_NAMES.includes(palette)) {
@@ -3197,6 +3220,15 @@ function formatShadowStyle(tokenPath, value, primitiveMap) {
3197
3220
  const isInset = tokenPath.length === 1 && tokenPath[0] === "inner";
3198
3221
  return formatShadowComposite(value, primitiveMap, isInset);
3199
3222
  }
3223
+ function inlineVariables(value, values) {
3224
+ return value.replace(/var\((--[\w-]+)\)/g, (reference, name) => {
3225
+ const literal = values.get(name);
3226
+ if (literal === void 0) {
3227
+ throw new Error(`inlineVariables: ${reference} has no value`);
3228
+ }
3229
+ return literal;
3230
+ });
3231
+ }
3200
3232
  var TYPOGRAPHY_PROPERTIES = [
3201
3233
  ["fontFamily", "font-family"],
3202
3234
  ["fontSize", "font-size"],
@@ -3346,24 +3378,117 @@ function borderColorAliasName(tokenName) {
3346
3378
  }
3347
3379
 
3348
3380
  // src/catalogue/descriptions.ts
3349
- var FOREGROUND_DESCRIPTIONS = Object.fromEntries(
3350
- COLOR_FAMILIES.flatMap((family) => [
3351
- [
3352
- `${family}-foreground`,
3353
- `Foreground on ${family}-background. The surface relationship defines this role, not text alone: text and icons share it, and contrasting control parts or indicators may use it on the same surface. Other pairings require contrast coverage.`
3354
- ],
3355
- [
3356
- `${family}-subtle-foreground`,
3357
- `Foreground on ${family}-subtle. The surface relationship defines this role, not text alone: text and icons share it, and contrasting indicators may use it on that surface. Use on neutral surfaces only with contrast coverage for the intended content tier.`
3358
- ]
3359
- ])
3360
- );
3361
- var RUNTIME_COLOR_DESCRIPTIONS = {
3381
+ var FAMILY_ROLES = {
3382
+ primary: "the main action on a surface",
3383
+ secondary: "a supporting action beside a primary one",
3384
+ success: "a completed or healthy state",
3385
+ warning: "a state that needs attention soon",
3386
+ error: "a failed, invalid or destructive state",
3387
+ information: "neutral guidance or a status update"
3388
+ };
3389
+ var FAMILY_TEMPLATES = {
3390
+ background: (family, role) => `Solid fill for buttons, badges and other strong emphasis in this family. Pair with ${family}-foreground. Marks ${role}.`,
3391
+ "background-hover": (family) => `${family}-background while the pointer is over the control.`,
3392
+ "background-active": (family) => `${family}-background while the control is pressed.`,
3393
+ foreground: (family) => `Foreground on ${family}-background. The surface relationship defines this role, not text alone: text and icons share it, and contrasting control parts or indicators may use it on the same surface. Other pairings require contrast coverage.`,
3394
+ disabled: () => "Fill of a disabled control in this family. Pair with disabled-foreground.",
3395
+ subtle: (family, role) => `Tinted fill for light badges, alerts and selected rows on background or container. Pair with ${family}-subtle-foreground. Marks ${role}.`,
3396
+ "subtle-foreground": (family) => `Foreground on ${family}-subtle. The surface relationship defines this role, not text alone: text and icons share it, and contrasting indicators may use it on that surface. Use on neutral surfaces only with contrast coverage for the intended content tier.`,
3397
+ "subtle-hover": (family) => `${family}-subtle while the pointer is over the control.`,
3398
+ "subtle-active": (family) => `${family}-subtle while the control is pressed.`,
3399
+ border: () => "Border of an outlined control or alert in this family, on background or container.",
3400
+ "border-active": (family) => `${family}-border while the control is pressed or selected.`
3401
+ };
3402
+ function familyRole(name) {
3403
+ for (const family of COLOR_FAMILIES) {
3404
+ if (name === `border-${family}-active`) return [family, "border-active"];
3405
+ if (name.startsWith(`${family}-`)) {
3406
+ return [family, name.slice(family.length + 1)];
3407
+ }
3408
+ }
3409
+ return void 0;
3410
+ }
3411
+ var NEUTRAL_DESCRIPTIONS = {
3412
+ background: "Page background, the base surface everything sits on. Pair with foreground.",
3413
+ "background-hover": "Row or ghost-control hover on background. Pair with foreground.",
3414
+ "background-active": "Row or ghost-control press and selection on background. Pair with foreground.",
3415
+ muted: "Quiet fill for wells, code, skeletons and inactive tracks on background. Pair with muted-foreground.",
3362
3416
  "muted-extralight": "Quietest muted surface \u2014 sits between background and muted for barely-there fills (empty states, subtle panels).",
3417
+ container: "Card and panel surface on background. Pair with container-foreground.",
3418
+ "container-hover": "Row or control hover inside a container.",
3419
+ "container-active": "Row or control press and selection inside a container.",
3420
+ popover: "Surface of menus, popovers, tooltips and dialogs. Pair with popover-foreground.",
3421
+ "popover-hover": "Highlighted menu row inside a popover.",
3422
+ "popover-active": "Pressed or checked menu row inside a popover.",
3423
+ "control-background": "Rail of neutral controls: switch tracks, slider tracks, segmented tabs. Also the hover fill on a neutral control rail.",
3424
+ "control-background-hover": "control-background while the pointer is over it.",
3425
+ "control-thumb": "Thumb of switches and sliders, on control-background.",
3426
+ "nav-background": "Sidebar and navigation surface. Pair with nav-foreground.",
3427
+ "nav-item-hover": "Navigation item hover on nav-background.",
3428
+ "nav-item-active": "Current navigation item on nav-background.",
3429
+ "nav-border": "Border between the sidebar and the page, and inside it.",
3430
+ disabled: "Fill of a disabled neutral control or input. Pair with disabled-foreground.",
3431
+ "border-focus": "Border of a focused input, on background or container.",
3432
+ foreground: "Body text and icons on background, muted and the hover fills.",
3433
+ "container-foreground": "Text and icons on container.",
3434
+ "popover-foreground": "Text and icons on popover and its row fills.",
3435
+ "nav-foreground": "Navigation text and icons on nav-background.",
3363
3436
  "muted-foreground": "It's a gray that softens contrast so primary content stands forward.",
3437
+ "nav-muted-foreground": "Secondary navigation text, such as group labels, on nav-background.",
3364
3438
  "muted-foreground-subtle": "Tertiary text tier below muted-foreground - helper text, captions, divider labels.",
3365
- ...FOREGROUND_DESCRIPTIONS
3439
+ "disabled-foreground": "Text and icons of a disabled control, on disabled and the family disabled fills.",
3440
+ "border-default": "Default border of inputs, cards, tables and separators, on background or container.",
3441
+ "border-disabled": "Border of a disabled control.",
3442
+ "border-hairline": "Faint divider between rows and grouped items.",
3443
+ "chart-categorical-1": "First chart series, on container or background. Series colours stay in order.",
3444
+ "chart-categorical-2": "Second chart series, on container or background.",
3445
+ "chart-categorical-3": "Third chart series, on container or background.",
3446
+ "chart-categorical-4": "Fourth chart series, on container or background.",
3447
+ "chart-categorical-5": "Fifth chart series, on container or background.",
3448
+ "focus-default": "Focus ring of every interactive control, on any surface.",
3449
+ "focus-error": "Focus ring of an invalid control.",
3450
+ "background-hover-alpha": "Translucent hover fill for controls that sit on an image or an unknown surface.",
3451
+ "border-default-alpha": "Translucent border for controls that sit on an image or an unknown surface.",
3452
+ overlay: "Scrim behind dialogs, sheets and drawers.",
3453
+ "popover-alpha": "Translucent popover surface for frosted overlays.",
3454
+ "popover-backdrop": "Backdrop behind a frosted popover."
3366
3455
  };
3456
+ var REGISTRY_NAMES = SEMANTIC_TOKEN_REGISTRY.map(
3457
+ (token2) => token2.name
3458
+ );
3459
+ function familyDescriptions() {
3460
+ const used = /* @__PURE__ */ new Set();
3461
+ const entries = REGISTRY_NAMES.flatMap((name) => {
3462
+ const match = familyRole(name);
3463
+ if (!match) return [];
3464
+ const [family, role] = match;
3465
+ const template = FAMILY_TEMPLATES[role];
3466
+ if (!template) return [];
3467
+ used.add(role);
3468
+ return [[name, template(family, FAMILY_ROLES[family])]];
3469
+ });
3470
+ const unused = Object.keys(FAMILY_TEMPLATES).filter(
3471
+ (role) => !used.has(role)
3472
+ );
3473
+ if (unused.length > 0) {
3474
+ throw new Error(
3475
+ `FAMILY_TEMPLATES describes ${unused.join(", ")}, which no registry colour has.`
3476
+ );
3477
+ }
3478
+ return entries;
3479
+ }
3480
+ function neutralDescriptions() {
3481
+ const unknown = Object.keys(NEUTRAL_DESCRIPTIONS).filter(
3482
+ (name) => !REGISTRY_NAMES.includes(name)
3483
+ );
3484
+ if (unknown.length > 0) {
3485
+ throw new Error(
3486
+ `NEUTRAL_DESCRIPTIONS describes ${unknown.join(", ")}, which the registry doesn't have.`
3487
+ );
3488
+ }
3489
+ return Object.entries(NEUTRAL_DESCRIPTIONS);
3490
+ }
3491
+ var RUNTIME_COLOR_DESCRIPTIONS = Object.fromEntries([...neutralDescriptions(), ...familyDescriptions()]);
3367
3492
 
3368
3493
  // tokens/primitives/borderwidth/borderwidth-fine.json
3369
3494
  var borderwidth_fine_default = {
@@ -11144,21 +11269,46 @@ function typographyStyleEntry(lookup) {
11144
11269
  };
11145
11270
  };
11146
11271
  }
11147
- function shadowStyleEntry(lookup) {
11148
- return ({ leaf }) => {
11272
+ function shadowLayerSets(layers, lookup) {
11273
+ const sets = /* @__PURE__ */ new Map();
11274
+ for (const { preset, mode, leaf } of layers) {
11275
+ const key = `${preset}/${mode}`;
11276
+ const set = sets.get(key) ?? { preset, mode, values: /* @__PURE__ */ new Map() };
11277
+ set.values.set(
11278
+ primitiveName("shadow", leaf.path),
11279
+ resolveValue(leaf.value, lookup, leaf.type, leaf.path)
11280
+ );
11281
+ sets.set(key, set);
11282
+ }
11283
+ return [...sets.values()];
11284
+ }
11285
+ function shadowStyleTokens(layers, lookup) {
11286
+ const sets = shadowLayerSets(layers, lookup);
11287
+ return styleLeaves("shadow", SHADOW_STYLES_FILE).map(({ leaf }) => {
11149
11288
  const key = pathToCssVarPrefixed(leaf.path, "shadow");
11150
- const property = `--${key}`;
11289
+ const name = `--nx-${key}`;
11290
+ const composite = formatShadowStyle(leaf.path, leaf.value, lookup);
11151
11291
  return {
11152
- name: `--nx-${key}`,
11153
- aliases: [cssVariable(property)],
11154
- declarations: [
11155
- {
11156
- property,
11157
- value: formatShadowStyle(leaf.path, leaf.value, lookup)
11158
- }
11159
- ]
11292
+ name,
11293
+ family: "shadow",
11294
+ group: leafGroup("shadow", leaf.path),
11295
+ type: leaf.type,
11296
+ description: leaf.description ?? null,
11297
+ aliases: [cssVariable(`--${key}`)],
11298
+ control: PRESET_CONTROLS.shadow ?? null,
11299
+ variants: sets.map(({ preset, mode, values }) => ({
11300
+ mode,
11301
+ preset,
11302
+ source: { file: SHADOW_STYLES_FILE, path: leaf.path },
11303
+ appearance: null,
11304
+ authoredValue: structuredClone(leaf.value),
11305
+ declarations: [
11306
+ { property: name, value: inlineVariables(composite, values) }
11307
+ ],
11308
+ references: []
11309
+ }))
11160
11310
  };
11161
- };
11311
+ });
11162
11312
  }
11163
11313
  function styleLeaves(family, file) {
11164
11314
  return fileLeaves(family, file, SINGLE_SOURCE).filter(
@@ -11220,8 +11370,13 @@ function runtimeColorTokens() {
11220
11370
  function createTokenCatalogue() {
11221
11371
  const primitives = PRIMITIVE_FAMILIES.flatMap(primitiveLeaves);
11222
11372
  const lookup = primitiveLookup(primitives);
11373
+ const shadowLayers = primitives.filter(({ family }) => family === "shadow");
11223
11374
  return [
11224
- ...authoredTokens(primitives, lookup, primitiveEntry(lookup)),
11375
+ ...authoredTokens(
11376
+ primitives.filter((leaf) => leaf.family !== "shadow"),
11377
+ lookup,
11378
+ primitiveEntry(lookup)
11379
+ ),
11225
11380
  ...runtimeColorTokens(),
11226
11381
  ...authoredTokens(spacingLeaves(), lookup, spacingEntry),
11227
11382
  ...authoredTokens(
@@ -11239,11 +11394,7 @@ function createTokenCatalogue() {
11239
11394
  lookup,
11240
11395
  typographyStyleEntry(lookup)
11241
11396
  ),
11242
- ...authoredTokens(
11243
- styleLeaves("shadow", SHADOW_STYLES_FILE),
11244
- lookup,
11245
- shadowStyleEntry(lookup)
11246
- )
11397
+ ...shadowStyleTokens(shadowLayers, lookup)
11247
11398
  ];
11248
11399
  }
11249
11400
  // Annotate the CommonJS export names for ESM import in node: