@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.
@@ -15,8 +15,8 @@ type DeepReadonly<T> = T extends object ? {
15
15
  type CatalogueFamily = 'borderwidth' | 'breakpoint' | 'color' | 'motion' | 'radius' | 'shadow' | 'spacing' | 'typography' | 'z-index';
16
16
  /**
17
17
  * Canonical identity: an identifier in the `--nx-*` custom property scheme.
18
- * Most tokens declare it in the generated CSS. Typography and shadow styles
19
- * and breakpoints do not; they declare a theme property or a utility instead.
18
+ * Most tokens declare it in the generated CSS. Typography styles and
19
+ * breakpoints do not; they declare a utility or a theme property instead.
20
20
  */
21
21
  type CatalogueTokenName = `--nx-${string}`;
22
22
  /** Another name that maps onto the canonical token. */
@@ -52,7 +52,7 @@ interface CatalogueDeclaration {
52
52
  interface CatalogueVariant {
53
53
  /**
54
54
  * The theme mode the value applies in (`light` / `dark` for a runtime
55
- * colour or a shadow layer), or `null` when it applies in both.
55
+ * colour or a shadow), or `null` when it applies in both.
56
56
  */
57
57
  readonly mode: Mode | null;
58
58
  /**
@@ -68,8 +68,8 @@ interface CatalogueVariant {
68
68
  readonly authoredValue: TokenValue | null;
69
69
  /**
70
70
  * What the generated CSS declares: one custom property for a scalar or a
71
- * shadow style (`--nx-spacing-4`, or `--breakpoint-md` and `--shadow-sm` for
72
- * a token declared only under `@theme`), or the `@utility` body for a
71
+ * shadow style (`--nx-spacing-4`, `--nx-shadow-sm`, or `--breakpoint-md`
72
+ * for a token declared only under `@theme`), or the `@utility` body for a
73
73
  * typography style.
74
74
  */
75
75
  readonly declarations: readonly CatalogueDeclaration[];
@@ -106,6 +106,7 @@ interface CatalogueToken {
106
106
  /**
107
107
  * Every nxds token, identified by its `--nx-*` name: primitives, runtime
108
108
  * colours, spacing, z-index, breakpoints, and typography and shadow styles.
109
+ * Shadow layer primitives only compose the shadow styles.
109
110
  * Runtime colours are computed from `DEFAULT_NXDS_APPEARANCE` in explicit
110
111
  * light and dark modes; each variant records the appearance it used.
111
112
  */
@@ -15,8 +15,8 @@ type DeepReadonly<T> = T extends object ? {
15
15
  type CatalogueFamily = 'borderwidth' | 'breakpoint' | 'color' | 'motion' | 'radius' | 'shadow' | 'spacing' | 'typography' | 'z-index';
16
16
  /**
17
17
  * Canonical identity: an identifier in the `--nx-*` custom property scheme.
18
- * Most tokens declare it in the generated CSS. Typography and shadow styles
19
- * and breakpoints do not; they declare a theme property or a utility instead.
18
+ * Most tokens declare it in the generated CSS. Typography styles and
19
+ * breakpoints do not; they declare a utility or a theme property instead.
20
20
  */
21
21
  type CatalogueTokenName = `--nx-${string}`;
22
22
  /** Another name that maps onto the canonical token. */
@@ -52,7 +52,7 @@ interface CatalogueDeclaration {
52
52
  interface CatalogueVariant {
53
53
  /**
54
54
  * The theme mode the value applies in (`light` / `dark` for a runtime
55
- * colour or a shadow layer), or `null` when it applies in both.
55
+ * colour or a shadow), or `null` when it applies in both.
56
56
  */
57
57
  readonly mode: Mode | null;
58
58
  /**
@@ -68,8 +68,8 @@ interface CatalogueVariant {
68
68
  readonly authoredValue: TokenValue | null;
69
69
  /**
70
70
  * What the generated CSS declares: one custom property for a scalar or a
71
- * shadow style (`--nx-spacing-4`, or `--breakpoint-md` and `--shadow-sm` for
72
- * a token declared only under `@theme`), or the `@utility` body for a
71
+ * shadow style (`--nx-spacing-4`, `--nx-shadow-sm`, or `--breakpoint-md`
72
+ * for a token declared only under `@theme`), or the `@utility` body for a
73
73
  * typography style.
74
74
  */
75
75
  readonly declarations: readonly CatalogueDeclaration[];
@@ -106,6 +106,7 @@ interface CatalogueToken {
106
106
  /**
107
107
  * Every nxds token, identified by its `--nx-*` name: primitives, runtime
108
108
  * colours, spacing, z-index, breakpoints, and typography and shadow styles.
109
+ * Shadow layer primitives only compose the shadow styles.
109
110
  * Runtime colours are computed from `DEFAULT_NXDS_APPEARANCE` in explicit
110
111
  * light and dark modes; each variant records the appearance it used.
111
112
  */
@@ -408,6 +408,13 @@ var CHART_PALETTE_REFERENCES = [
408
408
  { palette: "rose", light: "600", dark: "200" },
409
409
  { palette: "indigo", light: "600", dark: "200" }
410
410
  ];
411
+ var SYNTAX_PALETTE_REFERENCES = {
412
+ keyword: CHART_PALETTE_REFERENCES[3],
413
+ string: CHART_PALETTE_REFERENCES[1],
414
+ function: CHART_PALETTE_REFERENCES[4],
415
+ type: CHART_PALETTE_REFERENCES[0],
416
+ constant: CHART_PALETTE_REFERENCES[2]
417
+ };
411
418
 
412
419
  // src/lib/apca-pairs.ts
413
420
  var COLOR_FAMILIES = [
@@ -422,6 +429,8 @@ var CATEGORICAL_INDICES = CHART_PALETTE_REFERENCES.map(
422
429
  (_, index) => index + 1
423
430
  );
424
431
  var CHART_STAGGER_LC = 4.5;
432
+ var DIFF_SURFACES = ["success-subtle", "error-subtle"];
433
+ var CODE_SURFACES = ["container", "container-hover", ...DIFF_SURFACES];
425
434
  var FOCUS_SURFACES = [
426
435
  "background",
427
436
  "container",
@@ -481,11 +490,23 @@ var APCA_PAIRS = [
481
490
  ink(`${family}-subtle-foreground`, `${family}-subtle-active`, "ui")
482
491
  ]),
483
492
  ...CATEGORICAL_INDICES.flatMap(
484
- (index) => ["container", "background"].map((bg) => ({
493
+ (index) => ["container", "container-hover", "background"].map((bg) => ({
485
494
  ...ink(`chart-categorical-${index}`, bg, "ui"),
486
495
  offset: (index - 1) * CHART_STAGGER_LC
487
496
  }))
488
497
  ),
498
+ ...CODE_SURFACES.flatMap(
499
+ (bg) => Object.keys(SYNTAX_PALETTE_REFERENCES).map(
500
+ (role) => ink(`syntax-${role}`, bg, "ui")
501
+ )
502
+ ),
503
+ // codeBlockTheme also colours code with the text tokens, which already read
504
+ // on container and container-hover.
505
+ ...DIFF_SURFACES.flatMap((bg) => [
506
+ text("foreground", bg, "ui"),
507
+ text("muted-foreground", bg, "ui"),
508
+ text("muted-foreground-subtle", bg, "incidental")
509
+ ]),
489
510
  // Focus is the primary accent (components.md § Focus States), so it shares
490
511
  // one solved color with primary-subtle-foreground.
491
512
  ...FOCUS_SURFACES.flatMap((surface) => [
@@ -2502,10 +2523,33 @@ var color_default = {
2502
2523
  }
2503
2524
  };
2504
2525
 
2526
+ // src/lib/token-scales.generated.ts
2527
+ var PRIMITIVE_PALETTE_NAMES = [
2528
+ "green",
2529
+ "emerald",
2530
+ "teal",
2531
+ "cyan",
2532
+ "sky",
2533
+ "indigo",
2534
+ "violet",
2535
+ "purple",
2536
+ "fuchsia",
2537
+ "pink",
2538
+ "slate",
2539
+ "rose",
2540
+ "lime",
2541
+ "yellow",
2542
+ "blue",
2543
+ "gray",
2544
+ "zinc",
2545
+ "neutral",
2546
+ "stone",
2547
+ "red",
2548
+ "orange",
2549
+ "amber"
2550
+ ];
2551
+
2505
2552
  // src/lib/primitive-palette.ts
2506
- var PRIMITIVE_PALETTE_NAMES = Object.keys(color_default).filter(
2507
- (name) => name !== "white" && name !== "black"
2508
- );
2509
2553
  var rampCache = /* @__PURE__ */ new Map();
2510
2554
  function getPaletteRamp(palette) {
2511
2555
  if (!PRIMITIVE_PALETTE_NAMES.includes(palette)) {
@@ -2759,6 +2803,14 @@ function deriveChart(mode) {
2759
2803
  ])
2760
2804
  );
2761
2805
  }
2806
+ function deriveSyntax(mode) {
2807
+ return Object.fromEntries(
2808
+ Object.entries(SYNTAX_PALETTE_REFERENCES).map(([role, reference]) => [
2809
+ `--nx-color-syntax-${role}`,
2810
+ getPaletteShade(reference.palette, reference[mode])
2811
+ ])
2812
+ );
2813
+ }
2762
2814
  function deriveAlpha(surfaceTone, mode, profile) {
2763
2815
  const tone = SURFACE_TONE[surfaceTone];
2764
2816
  const dark = mode === "dark";
@@ -2874,6 +2926,7 @@ function deriveThemeMode(input, mode) {
2874
2926
  ...deriveSecondary(mode),
2875
2927
  ...deriveStatus(mode),
2876
2928
  ...deriveChart(mode),
2929
+ ...deriveSyntax(mode),
2877
2930
  ...deriveAlpha(surfaceTone, mode, profile),
2878
2931
  "--nx-color-focus-error": getPaletteShade(
2879
2932
  STATUS_PALETTE_FAMILIES.error,
@@ -3005,6 +3058,13 @@ var CHART_TOKEN_NAMES = [
3005
3058
  "chart-categorical-4",
3006
3059
  "chart-categorical-5"
3007
3060
  ];
3061
+ var SYNTAX_TOKEN_NAMES = [
3062
+ "syntax-keyword",
3063
+ "syntax-string",
3064
+ "syntax-function",
3065
+ "syntax-type",
3066
+ "syntax-constant"
3067
+ ];
3008
3068
  var FOCUS_TOKEN_NAMES = ["focus-default", "focus-error"];
3009
3069
  var ALPHA_TOKEN_NAMES = [
3010
3070
  "background-hover-alpha",
@@ -3023,6 +3083,7 @@ var SEMANTIC_TOKEN_REGISTRY = [
3023
3083
  ...metas("brand", BRAND_TOKEN_NAMES),
3024
3084
  ...metas("status", STATUS_TOKEN_NAMES),
3025
3085
  ...metas("chart", CHART_TOKEN_NAMES),
3086
+ ...metas("syntax", SYNTAX_TOKEN_NAMES),
3026
3087
  ...metas("focus", FOCUS_TOKEN_NAMES),
3027
3088
  ...metas("alpha", ALPHA_TOKEN_NAMES)
3028
3089
  ];
@@ -3168,6 +3229,15 @@ function formatShadowStyle(tokenPath, value, primitiveMap) {
3168
3229
  const isInset = tokenPath.length === 1 && tokenPath[0] === "inner";
3169
3230
  return formatShadowComposite(value, primitiveMap, isInset);
3170
3231
  }
3232
+ function inlineVariables(value, values) {
3233
+ return value.replace(/var\((--[\w-]+)\)/g, (reference, name) => {
3234
+ const literal = values.get(name);
3235
+ if (literal === void 0) {
3236
+ throw new Error(`inlineVariables: ${reference} has no value`);
3237
+ }
3238
+ return literal;
3239
+ });
3240
+ }
3171
3241
  var TYPOGRAPHY_PROPERTIES = [
3172
3242
  ["fontFamily", "font-family"],
3173
3243
  ["fontSize", "font-size"],
@@ -3384,6 +3454,11 @@ var NEUTRAL_DESCRIPTIONS = {
3384
3454
  "chart-categorical-3": "Third chart series, on container or background.",
3385
3455
  "chart-categorical-4": "Fourth chart series, on container or background.",
3386
3456
  "chart-categorical-5": "Fifth chart series, on container or background.",
3457
+ "syntax-keyword": "Keywords in code, such as const and return, on CodeBlock surfaces.",
3458
+ "syntax-string": "Strings in code, on CodeBlock surfaces.",
3459
+ "syntax-function": "Function and attribute names in code, on CodeBlock surfaces.",
3460
+ "syntax-type": "Type, class and tag names in code, on CodeBlock surfaces.",
3461
+ "syntax-constant": "Numbers and constants in code, on CodeBlock surfaces.",
3387
3462
  "focus-default": "Focus ring of every interactive control, on any surface.",
3388
3463
  "focus-error": "Focus ring of an invalid control.",
3389
3464
  "background-hover-alpha": "Translucent hover fill for controls that sit on an image or an unknown surface.",
@@ -11208,21 +11283,46 @@ function typographyStyleEntry(lookup) {
11208
11283
  };
11209
11284
  };
11210
11285
  }
11211
- function shadowStyleEntry(lookup) {
11212
- return ({ leaf }) => {
11286
+ function shadowLayerSets(layers, lookup) {
11287
+ const sets = /* @__PURE__ */ new Map();
11288
+ for (const { preset, mode, leaf } of layers) {
11289
+ const key = `${preset}/${mode}`;
11290
+ const set = sets.get(key) ?? { preset, mode, values: /* @__PURE__ */ new Map() };
11291
+ set.values.set(
11292
+ primitiveName("shadow", leaf.path),
11293
+ resolveValue(leaf.value, lookup, leaf.type, leaf.path)
11294
+ );
11295
+ sets.set(key, set);
11296
+ }
11297
+ return [...sets.values()];
11298
+ }
11299
+ function shadowStyleTokens(layers, lookup) {
11300
+ const sets = shadowLayerSets(layers, lookup);
11301
+ return styleLeaves("shadow", SHADOW_STYLES_FILE).map(({ leaf }) => {
11213
11302
  const key = pathToCssVarPrefixed(leaf.path, "shadow");
11214
- const property = `--${key}`;
11303
+ const name = `--nx-${key}`;
11304
+ const composite = formatShadowStyle(leaf.path, leaf.value, lookup);
11215
11305
  return {
11216
- name: `--nx-${key}`,
11217
- aliases: [cssVariable(property)],
11218
- declarations: [
11219
- {
11220
- property,
11221
- value: formatShadowStyle(leaf.path, leaf.value, lookup)
11222
- }
11223
- ]
11306
+ name,
11307
+ family: "shadow",
11308
+ group: leafGroup("shadow", leaf.path),
11309
+ type: leaf.type,
11310
+ description: leaf.description ?? null,
11311
+ aliases: [cssVariable(`--${key}`)],
11312
+ control: PRESET_CONTROLS.shadow ?? null,
11313
+ variants: sets.map(({ preset, mode, values }) => ({
11314
+ mode,
11315
+ preset,
11316
+ source: { file: SHADOW_STYLES_FILE, path: leaf.path },
11317
+ appearance: null,
11318
+ authoredValue: structuredClone(leaf.value),
11319
+ declarations: [
11320
+ { property: name, value: inlineVariables(composite, values) }
11321
+ ],
11322
+ references: []
11323
+ }))
11224
11324
  };
11225
- };
11325
+ });
11226
11326
  }
11227
11327
  function styleLeaves(family, file) {
11228
11328
  return fileLeaves(family, file, SINGLE_SOURCE).filter(
@@ -11284,8 +11384,13 @@ function runtimeColorTokens() {
11284
11384
  function createTokenCatalogue() {
11285
11385
  const primitives = PRIMITIVE_FAMILIES.flatMap(primitiveLeaves);
11286
11386
  const lookup = primitiveLookup(primitives);
11387
+ const shadowLayers = primitives.filter(({ family }) => family === "shadow");
11287
11388
  return [
11288
- ...authoredTokens(primitives, lookup, primitiveEntry(lookup)),
11389
+ ...authoredTokens(
11390
+ primitives.filter((leaf) => leaf.family !== "shadow"),
11391
+ lookup,
11392
+ primitiveEntry(lookup)
11393
+ ),
11289
11394
  ...runtimeColorTokens(),
11290
11395
  ...authoredTokens(spacingLeaves(), lookup, spacingEntry),
11291
11396
  ...authoredTokens(
@@ -11303,11 +11408,7 @@ function createTokenCatalogue() {
11303
11408
  lookup,
11304
11409
  typographyStyleEntry(lookup)
11305
11410
  ),
11306
- ...authoredTokens(
11307
- styleLeaves("shadow", SHADOW_STYLES_FILE),
11308
- lookup,
11309
- shadowStyleEntry(lookup)
11310
- )
11411
+ ...shadowStyleTokens(shadowLayers, lookup)
11311
11412
  ];
11312
11413
  }
11313
11414
  export {