@nxds/core 0.9.1 → 0.11.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.
@@ -437,6 +437,13 @@ var CHART_PALETTE_REFERENCES = [
437
437
  { palette: "rose", light: "600", dark: "200" },
438
438
  { palette: "indigo", light: "600", dark: "200" }
439
439
  ];
440
+ var SYNTAX_PALETTE_REFERENCES = {
441
+ keyword: CHART_PALETTE_REFERENCES[3],
442
+ string: CHART_PALETTE_REFERENCES[1],
443
+ function: CHART_PALETTE_REFERENCES[4],
444
+ type: CHART_PALETTE_REFERENCES[0],
445
+ constant: CHART_PALETTE_REFERENCES[2]
446
+ };
440
447
 
441
448
  // src/lib/apca-pairs.ts
442
449
  var COLOR_FAMILIES = [
@@ -451,6 +458,8 @@ var CATEGORICAL_INDICES = CHART_PALETTE_REFERENCES.map(
451
458
  (_, index) => index + 1
452
459
  );
453
460
  var CHART_STAGGER_LC = 4.5;
461
+ var DIFF_SURFACES = ["success-subtle", "error-subtle"];
462
+ var CODE_SURFACES = ["container", "container-hover", ...DIFF_SURFACES];
454
463
  var FOCUS_SURFACES = [
455
464
  "background",
456
465
  "container",
@@ -510,11 +519,23 @@ var APCA_PAIRS = [
510
519
  ink(`${family}-subtle-foreground`, `${family}-subtle-active`, "ui")
511
520
  ]),
512
521
  ...CATEGORICAL_INDICES.flatMap(
513
- (index) => ["container", "background"].map((bg) => ({
522
+ (index) => ["container", "container-hover", "background"].map((bg) => ({
514
523
  ...ink(`chart-categorical-${index}`, bg, "ui"),
515
524
  offset: (index - 1) * CHART_STAGGER_LC
516
525
  }))
517
526
  ),
527
+ ...CODE_SURFACES.flatMap(
528
+ (bg) => Object.keys(SYNTAX_PALETTE_REFERENCES).map(
529
+ (role) => ink(`syntax-${role}`, bg, "ui")
530
+ )
531
+ ),
532
+ // codeBlockTheme also colours code with the text tokens, which already read
533
+ // on container and container-hover.
534
+ ...DIFF_SURFACES.flatMap((bg) => [
535
+ text("foreground", bg, "ui"),
536
+ text("muted-foreground", bg, "ui"),
537
+ text("muted-foreground-subtle", bg, "incidental")
538
+ ]),
518
539
  // Focus is the primary accent (components.md § Focus States), so it shares
519
540
  // one solved color with primary-subtle-foreground.
520
541
  ...FOCUS_SURFACES.flatMap((surface) => [
@@ -2531,10 +2552,33 @@ var color_default = {
2531
2552
  }
2532
2553
  };
2533
2554
 
2555
+ // src/lib/token-scales.generated.ts
2556
+ var PRIMITIVE_PALETTE_NAMES = [
2557
+ "green",
2558
+ "emerald",
2559
+ "teal",
2560
+ "cyan",
2561
+ "sky",
2562
+ "indigo",
2563
+ "violet",
2564
+ "purple",
2565
+ "fuchsia",
2566
+ "pink",
2567
+ "slate",
2568
+ "rose",
2569
+ "lime",
2570
+ "yellow",
2571
+ "blue",
2572
+ "gray",
2573
+ "zinc",
2574
+ "neutral",
2575
+ "stone",
2576
+ "red",
2577
+ "orange",
2578
+ "amber"
2579
+ ];
2580
+
2534
2581
  // src/lib/primitive-palette.ts
2535
- var PRIMITIVE_PALETTE_NAMES = Object.keys(color_default).filter(
2536
- (name) => name !== "white" && name !== "black"
2537
- );
2538
2582
  var rampCache = /* @__PURE__ */ new Map();
2539
2583
  function getPaletteRamp(palette) {
2540
2584
  if (!PRIMITIVE_PALETTE_NAMES.includes(palette)) {
@@ -2788,6 +2832,14 @@ function deriveChart(mode) {
2788
2832
  ])
2789
2833
  );
2790
2834
  }
2835
+ function deriveSyntax(mode) {
2836
+ return Object.fromEntries(
2837
+ Object.entries(SYNTAX_PALETTE_REFERENCES).map(([role, reference]) => [
2838
+ `--nx-color-syntax-${role}`,
2839
+ getPaletteShade(reference.palette, reference[mode])
2840
+ ])
2841
+ );
2842
+ }
2791
2843
  function deriveAlpha(surfaceTone, mode, profile) {
2792
2844
  const tone = SURFACE_TONE[surfaceTone];
2793
2845
  const dark = mode === "dark";
@@ -2903,6 +2955,7 @@ function deriveThemeMode(input, mode) {
2903
2955
  ...deriveSecondary(mode),
2904
2956
  ...deriveStatus(mode),
2905
2957
  ...deriveChart(mode),
2958
+ ...deriveSyntax(mode),
2906
2959
  ...deriveAlpha(surfaceTone, mode, profile),
2907
2960
  "--nx-color-focus-error": getPaletteShade(
2908
2961
  STATUS_PALETTE_FAMILIES.error,
@@ -3034,6 +3087,13 @@ var CHART_TOKEN_NAMES = [
3034
3087
  "chart-categorical-4",
3035
3088
  "chart-categorical-5"
3036
3089
  ];
3090
+ var SYNTAX_TOKEN_NAMES = [
3091
+ "syntax-keyword",
3092
+ "syntax-string",
3093
+ "syntax-function",
3094
+ "syntax-type",
3095
+ "syntax-constant"
3096
+ ];
3037
3097
  var FOCUS_TOKEN_NAMES = ["focus-default", "focus-error"];
3038
3098
  var ALPHA_TOKEN_NAMES = [
3039
3099
  "background-hover-alpha",
@@ -3052,6 +3112,7 @@ var SEMANTIC_TOKEN_REGISTRY = [
3052
3112
  ...metas("brand", BRAND_TOKEN_NAMES),
3053
3113
  ...metas("status", STATUS_TOKEN_NAMES),
3054
3114
  ...metas("chart", CHART_TOKEN_NAMES),
3115
+ ...metas("syntax", SYNTAX_TOKEN_NAMES),
3055
3116
  ...metas("focus", FOCUS_TOKEN_NAMES),
3056
3117
  ...metas("alpha", ALPHA_TOKEN_NAMES)
3057
3118
  ];
@@ -3197,6 +3258,15 @@ function formatShadowStyle(tokenPath, value, primitiveMap) {
3197
3258
  const isInset = tokenPath.length === 1 && tokenPath[0] === "inner";
3198
3259
  return formatShadowComposite(value, primitiveMap, isInset);
3199
3260
  }
3261
+ function inlineVariables(value, values) {
3262
+ return value.replace(/var\((--[\w-]+)\)/g, (reference, name) => {
3263
+ const literal = values.get(name);
3264
+ if (literal === void 0) {
3265
+ throw new Error(`inlineVariables: ${reference} has no value`);
3266
+ }
3267
+ return literal;
3268
+ });
3269
+ }
3200
3270
  var TYPOGRAPHY_PROPERTIES = [
3201
3271
  ["fontFamily", "font-family"],
3202
3272
  ["fontSize", "font-size"],
@@ -3413,6 +3483,11 @@ var NEUTRAL_DESCRIPTIONS = {
3413
3483
  "chart-categorical-3": "Third chart series, on container or background.",
3414
3484
  "chart-categorical-4": "Fourth chart series, on container or background.",
3415
3485
  "chart-categorical-5": "Fifth chart series, on container or background.",
3486
+ "syntax-keyword": "Keywords in code, such as const and return, on CodeBlock surfaces.",
3487
+ "syntax-string": "Strings in code, on CodeBlock surfaces.",
3488
+ "syntax-function": "Function and attribute names in code, on CodeBlock surfaces.",
3489
+ "syntax-type": "Type, class and tag names in code, on CodeBlock surfaces.",
3490
+ "syntax-constant": "Numbers and constants in code, on CodeBlock surfaces.",
3416
3491
  "focus-default": "Focus ring of every interactive control, on any surface.",
3417
3492
  "focus-error": "Focus ring of an invalid control.",
3418
3493
  "background-hover-alpha": "Translucent hover fill for controls that sit on an image or an unknown surface.",
@@ -11237,21 +11312,46 @@ function typographyStyleEntry(lookup) {
11237
11312
  };
11238
11313
  };
11239
11314
  }
11240
- function shadowStyleEntry(lookup) {
11241
- return ({ leaf }) => {
11315
+ function shadowLayerSets(layers, lookup) {
11316
+ const sets = /* @__PURE__ */ new Map();
11317
+ for (const { preset, mode, leaf } of layers) {
11318
+ const key = `${preset}/${mode}`;
11319
+ const set = sets.get(key) ?? { preset, mode, values: /* @__PURE__ */ new Map() };
11320
+ set.values.set(
11321
+ primitiveName("shadow", leaf.path),
11322
+ resolveValue(leaf.value, lookup, leaf.type, leaf.path)
11323
+ );
11324
+ sets.set(key, set);
11325
+ }
11326
+ return [...sets.values()];
11327
+ }
11328
+ function shadowStyleTokens(layers, lookup) {
11329
+ const sets = shadowLayerSets(layers, lookup);
11330
+ return styleLeaves("shadow", SHADOW_STYLES_FILE).map(({ leaf }) => {
11242
11331
  const key = pathToCssVarPrefixed(leaf.path, "shadow");
11243
- const property = `--${key}`;
11332
+ const name = `--nx-${key}`;
11333
+ const composite = formatShadowStyle(leaf.path, leaf.value, lookup);
11244
11334
  return {
11245
- name: `--nx-${key}`,
11246
- aliases: [cssVariable(property)],
11247
- declarations: [
11248
- {
11249
- property,
11250
- value: formatShadowStyle(leaf.path, leaf.value, lookup)
11251
- }
11252
- ]
11335
+ name,
11336
+ family: "shadow",
11337
+ group: leafGroup("shadow", leaf.path),
11338
+ type: leaf.type,
11339
+ description: leaf.description ?? null,
11340
+ aliases: [cssVariable(`--${key}`)],
11341
+ control: PRESET_CONTROLS.shadow ?? null,
11342
+ variants: sets.map(({ preset, mode, values }) => ({
11343
+ mode,
11344
+ preset,
11345
+ source: { file: SHADOW_STYLES_FILE, path: leaf.path },
11346
+ appearance: null,
11347
+ authoredValue: structuredClone(leaf.value),
11348
+ declarations: [
11349
+ { property: name, value: inlineVariables(composite, values) }
11350
+ ],
11351
+ references: []
11352
+ }))
11253
11353
  };
11254
- };
11354
+ });
11255
11355
  }
11256
11356
  function styleLeaves(family, file) {
11257
11357
  return fileLeaves(family, file, SINGLE_SOURCE).filter(
@@ -11313,8 +11413,13 @@ function runtimeColorTokens() {
11313
11413
  function createTokenCatalogue() {
11314
11414
  const primitives = PRIMITIVE_FAMILIES.flatMap(primitiveLeaves);
11315
11415
  const lookup = primitiveLookup(primitives);
11416
+ const shadowLayers = primitives.filter(({ family }) => family === "shadow");
11316
11417
  return [
11317
- ...authoredTokens(primitives, lookup, primitiveEntry(lookup)),
11418
+ ...authoredTokens(
11419
+ primitives.filter((leaf) => leaf.family !== "shadow"),
11420
+ lookup,
11421
+ primitiveEntry(lookup)
11422
+ ),
11318
11423
  ...runtimeColorTokens(),
11319
11424
  ...authoredTokens(spacingLeaves(), lookup, spacingEntry),
11320
11425
  ...authoredTokens(
@@ -11332,11 +11437,7 @@ function createTokenCatalogue() {
11332
11437
  lookup,
11333
11438
  typographyStyleEntry(lookup)
11334
11439
  ),
11335
- ...authoredTokens(
11336
- styleLeaves("shadow", SHADOW_STYLES_FILE),
11337
- lookup,
11338
- shadowStyleEntry(lookup)
11339
- )
11440
+ ...shadowStyleTokens(shadowLayers, lookup)
11340
11441
  ];
11341
11442
  }
11342
11443
  // Annotate the CommonJS export names for ESM import in node: