@terrazzo/plugin-css 0.10.2 → 0.10.4

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/dist/index.js CHANGED
@@ -228,7 +228,7 @@ const parseRgbLegacy = (color) => {
228
228
  if (match[1] !== void 0) res.r = match[1] / 100;
229
229
  if (match[2] !== void 0) res.g = match[2] / 100;
230
230
  if (match[3] !== void 0) res.b = match[3] / 100;
231
- } else return void 0;
231
+ } else return;
232
232
  if (match[4] !== void 0) res.alpha = Math.max(0, Math.min(1, match[4] / 100));
233
233
  else if (match[5] !== void 0) res.alpha = Math.max(0, Math.min(1, +match[5]));
234
234
  return res;
@@ -343,7 +343,7 @@ function num(chars) {
343
343
  type: Tok.Hue,
344
344
  value: value * huenits[id]
345
345
  };
346
- return void 0;
346
+ return;
347
347
  }
348
348
  if (chars[_i] === "%") {
349
349
  _i++;
@@ -396,7 +396,7 @@ function tokenize(str = "") {
396
396
  while (_i < chars.length && (chars[_i] === "\n" || chars[_i] === " " || chars[_i] === " ")) _i++;
397
397
  continue;
398
398
  }
399
- if (ch === ",") return void 0;
399
+ if (ch === ",") return;
400
400
  if (ch === ")") {
401
401
  tokens.push({ type: Tok.ParenClose });
402
402
  continue;
@@ -407,7 +407,7 @@ function tokenize(str = "") {
407
407
  tokens.push(num(chars));
408
408
  continue;
409
409
  }
410
- return void 0;
410
+ return;
411
411
  }
412
412
  if (ch === "-") {
413
413
  _i--;
@@ -422,7 +422,7 @@ function tokenize(str = "") {
422
422
  });
423
423
  continue;
424
424
  }
425
- return void 0;
425
+ return;
426
426
  }
427
427
  if (ch === ".") {
428
428
  _i--;
@@ -430,7 +430,7 @@ function tokenize(str = "") {
430
430
  tokens.push(num(chars));
431
431
  continue;
432
432
  }
433
- return void 0;
433
+ return;
434
434
  }
435
435
  if (ch === "/") {
436
436
  while (_i < chars.length && (chars[_i] === "\n" || chars[_i] === " " || chars[_i] === " ")) _i++;
@@ -457,7 +457,7 @@ function tokenize(str = "") {
457
457
  continue;
458
458
  }
459
459
  }
460
- return void 0;
460
+ return;
461
461
  }
462
462
  if (/\d/.test(ch)) {
463
463
  _i--;
@@ -469,21 +469,21 @@ function tokenize(str = "") {
469
469
  tokens.push(identlike(chars));
470
470
  continue;
471
471
  }
472
- return void 0;
472
+ return;
473
473
  }
474
474
  return tokens;
475
475
  }
476
476
  function parseColorSyntax(tokens) {
477
477
  tokens._i = 0;
478
478
  let token = tokens[tokens._i++];
479
- if (!token || token.type !== Tok.Function || token.value !== "color") return void 0;
479
+ if (!token || token.type !== Tok.Function || token.value !== "color") return;
480
480
  token = tokens[tokens._i++];
481
- if (token.type !== Tok.Ident) return void 0;
481
+ if (token.type !== Tok.Ident) return;
482
482
  const mode = colorProfiles[token.value];
483
- if (!mode) return void 0;
483
+ if (!mode) return;
484
484
  const res = { mode };
485
485
  const coords = consumeCoords(tokens, false);
486
- if (!coords) return void 0;
486
+ if (!coords) return;
487
487
  const channels = getMode(mode).channels;
488
488
  for (let ii = 0, c$1, ch; ii < channels.length; ii++) {
489
489
  c$1 = coords[ii];
@@ -505,14 +505,14 @@ function consumeCoords(tokens, includeHue) {
505
505
  continue;
506
506
  }
507
507
  if (token.type === Tok.ParenClose) {
508
- if (tokens._i < tokens.length) return void 0;
508
+ if (tokens._i < tokens.length) return;
509
509
  continue;
510
510
  }
511
- return void 0;
511
+ return;
512
512
  }
513
- if (coords.length < 3 || coords.length > 4) return void 0;
513
+ if (coords.length < 3 || coords.length > 4) return;
514
514
  if (coords.length === 4) {
515
- if (coords[3].type !== Tok.Alpha) return void 0;
515
+ if (coords[3].type !== Tok.Alpha) return;
516
516
  coords[3] = coords[3].value;
517
517
  }
518
518
  if (coords.length === 3) coords.push({
@@ -524,14 +524,14 @@ function consumeCoords(tokens, includeHue) {
524
524
  function parseModernSyntax(tokens, includeHue) {
525
525
  tokens._i = 0;
526
526
  let token = tokens[tokens._i++];
527
- if (!token || token.type !== Tok.Function) return void 0;
527
+ if (!token || token.type !== Tok.Function) return;
528
528
  let coords = consumeCoords(tokens, includeHue);
529
- if (!coords) return void 0;
529
+ if (!coords) return;
530
530
  coords.unshift(token.value);
531
531
  return coords;
532
532
  }
533
533
  const parse = (color) => {
534
- if (typeof color !== "string") return void 0;
534
+ if (typeof color !== "string") return;
535
535
  const tokens = tokenize(color);
536
536
  const parsed = tokens ? parseModernSyntax(tokens, true) : void 0;
537
537
  let result = void 0;
@@ -545,10 +545,10 @@ var parse_default = parse;
545
545
  //#endregion
546
546
  //#region ../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/rgb/parseRgb.js
547
547
  function parseRgb(color, parsed) {
548
- if (!parsed || parsed[0] !== "rgb" && parsed[0] !== "rgba") return void 0;
548
+ if (!parsed || parsed[0] !== "rgb" && parsed[0] !== "rgba") return;
549
549
  const res = { mode: "rgb" };
550
550
  const [, r$1, g, b, alpha] = parsed;
551
- if (r$1.type === Tok.Hue || g.type === Tok.Hue || b.type === Tok.Hue) return void 0;
551
+ if (r$1.type === Tok.Hue || g.type === Tok.Hue || b.type === Tok.Hue) return;
552
552
  if (r$1.type !== Tok.None) res.r = r$1.type === Tok.Number ? r$1.value / 255 : r$1.value / 100;
553
553
  if (g.type !== Tok.None) res.g = g.type === Tok.Number ? g.value / 255 : g.value / 100;
554
554
  if (b.type !== Tok.None) res.b = b.type === Tok.Number ? b.value / 255 : b.value / 100;
@@ -895,19 +895,19 @@ var parseHslLegacy_default = parseHslLegacy;
895
895
  //#endregion
896
896
  //#region ../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/hsl/parseHsl.js
897
897
  function parseHsl(color, parsed) {
898
- if (!parsed || parsed[0] !== "hsl" && parsed[0] !== "hsla") return void 0;
898
+ if (!parsed || parsed[0] !== "hsl" && parsed[0] !== "hsla") return;
899
899
  const res = { mode: "hsl" };
900
900
  const [, h, s, l, alpha] = parsed;
901
901
  if (h.type !== Tok.None) {
902
- if (h.type === Tok.Percentage) return void 0;
902
+ if (h.type === Tok.Percentage) return;
903
903
  res.h = h.value;
904
904
  }
905
905
  if (s.type !== Tok.None) {
906
- if (s.type === Tok.Hue) return void 0;
906
+ if (s.type === Tok.Hue) return;
907
907
  res.s = s.value / 100;
908
908
  }
909
909
  if (l.type !== Tok.None) {
910
- if (l.type === Tok.Hue) return void 0;
910
+ if (l.type === Tok.Hue) return;
911
911
  res.l = l.value / 100;
912
912
  }
913
913
  if (alpha.type !== Tok.None) res.alpha = Math.min(1, Math.max(0, alpha.type === Tok.Number ? alpha.value : alpha.value / 100));
@@ -1178,19 +1178,19 @@ function convertRgbToHwb(rgba) {
1178
1178
  //#endregion
1179
1179
  //#region ../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/hwb/parseHwb.js
1180
1180
  function ParseHwb(color, parsed) {
1181
- if (!parsed || parsed[0] !== "hwb") return void 0;
1181
+ if (!parsed || parsed[0] !== "hwb") return;
1182
1182
  const res = { mode: "hwb" };
1183
1183
  const [, h, w, b, alpha] = parsed;
1184
1184
  if (h.type !== Tok.None) {
1185
- if (h.type === Tok.Percentage) return void 0;
1185
+ if (h.type === Tok.Percentage) return;
1186
1186
  res.h = h.value;
1187
1187
  }
1188
1188
  if (w.type !== Tok.None) {
1189
- if (w.type === Tok.Hue) return void 0;
1189
+ if (w.type === Tok.Hue) return;
1190
1190
  res.w = w.value / 100;
1191
1191
  }
1192
1192
  if (b.type !== Tok.None) {
1193
- if (b.type === Tok.Hue) return void 0;
1193
+ if (b.type === Tok.Hue) return;
1194
1194
  res.b = b.value / 100;
1195
1195
  }
1196
1196
  if (alpha.type !== Tok.None) res.alpha = Math.min(1, Math.max(0, alpha.type === Tok.Number ? alpha.value : alpha.value / 100));
@@ -1341,10 +1341,10 @@ var convertRgbToLab_default = convertRgbToLab;
1341
1341
  //#endregion
1342
1342
  //#region ../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/lab/parseLab.js
1343
1343
  function parseLab(color, parsed) {
1344
- if (!parsed || parsed[0] !== "lab") return void 0;
1344
+ if (!parsed || parsed[0] !== "lab") return;
1345
1345
  const res = { mode: "lab" };
1346
1346
  const [, l, a, b, alpha] = parsed;
1347
- if (l.type === Tok.Hue || a.type === Tok.Hue || b.type === Tok.Hue) return void 0;
1347
+ if (l.type === Tok.Hue || a.type === Tok.Hue || b.type === Tok.Hue) return;
1348
1348
  if (l.type !== Tok.None) res.l = Math.min(Math.max(0, l.value), 100);
1349
1349
  if (a.type !== Tok.None) res.a = a.type === Tok.Number ? a.value : a.value * 125 / 100;
1350
1350
  if (b.type !== Tok.None) res.b = b.type === Tok.Number ? b.value : b.value * 125 / 100;
@@ -1509,16 +1509,16 @@ var convertLchToLab_default = convertLchToLab;
1509
1509
  //#endregion
1510
1510
  //#region ../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/lch/parseLch.js
1511
1511
  function parseLch(color, parsed) {
1512
- if (!parsed || parsed[0] !== "lch") return void 0;
1512
+ if (!parsed || parsed[0] !== "lch") return;
1513
1513
  const res = { mode: "lch" };
1514
1514
  const [, l, c$1, h, alpha] = parsed;
1515
1515
  if (l.type !== Tok.None) {
1516
- if (l.type === Tok.Hue) return void 0;
1516
+ if (l.type === Tok.Hue) return;
1517
1517
  res.l = Math.min(Math.max(0, l.value), 100);
1518
1518
  }
1519
1519
  if (c$1.type !== Tok.None) res.c = Math.max(0, c$1.type === Tok.Number ? c$1.value : c$1.value * 150 / 100);
1520
1520
  if (h.type !== Tok.None) {
1521
- if (h.type === Tok.Percentage) return void 0;
1521
+ if (h.type === Tok.Percentage) return;
1522
1522
  res.h = h.value;
1523
1523
  }
1524
1524
  if (alpha.type !== Tok.None) res.alpha = Math.min(1, Math.max(0, alpha.type === Tok.Number ? alpha.value : alpha.value / 100));
@@ -1660,10 +1660,10 @@ var convertOklabToRgb_default = convertOklabToRgb;
1660
1660
  //#endregion
1661
1661
  //#region ../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/oklab/parseOklab.js
1662
1662
  function parseOklab(color, parsed) {
1663
- if (!parsed || parsed[0] !== "oklab") return void 0;
1663
+ if (!parsed || parsed[0] !== "oklab") return;
1664
1664
  const res = { mode: "oklab" };
1665
1665
  const [, l, a, b, alpha] = parsed;
1666
- if (l.type === Tok.Hue || a.type === Tok.Hue || b.type === Tok.Hue) return void 0;
1666
+ if (l.type === Tok.Hue || a.type === Tok.Hue || b.type === Tok.Hue) return;
1667
1667
  if (l.type !== Tok.None) res.l = Math.min(Math.max(0, l.type === Tok.Number ? l.value : l.value / 100), 1);
1668
1668
  if (a.type !== Tok.None) res.a = a.type === Tok.Number ? a.value : a.value * .4 / 100;
1669
1669
  if (b.type !== Tok.None) res.b = b.type === Tok.Number ? b.value : b.value * .4 / 100;
@@ -1698,16 +1698,16 @@ var definition_default$7 = definition$17;
1698
1698
  //#endregion
1699
1699
  //#region ../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/oklch/parseOklch.js
1700
1700
  function parseOklch(color, parsed) {
1701
- if (!parsed || parsed[0] !== "oklch") return void 0;
1701
+ if (!parsed || parsed[0] !== "oklch") return;
1702
1702
  const res = { mode: "oklch" };
1703
1703
  const [, l, c$1, h, alpha] = parsed;
1704
1704
  if (l.type !== Tok.None) {
1705
- if (l.type === Tok.Hue) return void 0;
1705
+ if (l.type === Tok.Hue) return;
1706
1706
  res.l = Math.min(Math.max(0, l.type === Tok.Number ? l.value : l.value / 100), 1);
1707
1707
  }
1708
1708
  if (c$1.type !== Tok.None) res.c = Math.max(0, c$1.type === Tok.Number ? c$1.value : c$1.value * .4 / 100);
1709
1709
  if (h.type !== Tok.None) {
1710
- if (h.type === Tok.Percentage) return void 0;
1710
+ if (h.type === Tok.Percentage) return;
1711
1711
  res.h = h.value;
1712
1712
  }
1713
1713
  if (alpha.type !== Tok.None) res.alpha = Math.min(1, Math.max(0, alpha.type === Tok.Number ? alpha.value : alpha.value / 100));
@@ -2993,9 +2993,8 @@ function get_Cs(L, a_, b_) {
2993
2993
  let C_mid = .9 * k$3 * Math.sqrt(Math.sqrt(1 / (1 / (C_a * C_a * C_a * C_a) + 1 / (C_b * C_b * C_b * C_b))));
2994
2994
  C_a = L * .4;
2995
2995
  C_b = (1 - L) * .8;
2996
- let C_0 = Math.sqrt(1 / (1 / (C_a * C_a) + 1 / (C_b * C_b)));
2997
2996
  return [
2998
- C_0,
2997
+ Math.sqrt(1 / (1 / (C_a * C_a) + 1 / (C_b * C_b))),
2999
2998
  C_mid,
3000
2999
  C_max
3001
3000
  ];
@@ -3023,14 +3022,12 @@ function convertOklabToOkhsl(lab$2) {
3023
3022
  let k_0 = 0;
3024
3023
  let k_1 = .8 * C_0;
3025
3024
  let k_2 = 1 - k_1 / C_mid;
3026
- let t = (c$1 - k_0) / (k_1 + k_2 * (c$1 - k_0));
3027
- s = t * .8;
3025
+ s = (c$1 - k_0) / (k_1 + k_2 * (c$1 - k_0)) * .8;
3028
3026
  } else {
3029
3027
  let k_0 = C_mid;
3030
3028
  let k_1 = .2 * C_mid * C_mid * 1.25 * 1.25 / C_0;
3031
3029
  let k_2 = 1 - k_1 / (C_max - C_mid);
3032
- let t = (c$1 - k_0) / (k_1 + k_2 * (c$1 - k_0));
3033
- s = .8 + .2 * t;
3030
+ s = .8 + .2 * ((c$1 - k_0) / (k_1 + k_2 * (c$1 - k_0)));
3034
3031
  }
3035
3032
  if (s) {
3036
3033
  ret.s = s;
@@ -3343,20 +3340,20 @@ const fixup = (value) => Math.round(clamp(value) * 255);
3343
3340
  const rgb$2 = converter_default("rgb");
3344
3341
  const hsl$1 = converter_default("hsl");
3345
3342
  const serializeHex = (color) => {
3346
- if (color === void 0) return void 0;
3343
+ if (color === void 0) return;
3347
3344
  let r$1 = fixup(color.r);
3348
3345
  let g = fixup(color.g);
3349
3346
  let b = fixup(color.b);
3350
3347
  return "#" + (1 << 24 | r$1 << 16 | g << 8 | b).toString(16).slice(1);
3351
3348
  };
3352
3349
  const serializeHex8 = (color) => {
3353
- if (color === void 0) return void 0;
3350
+ if (color === void 0) return;
3354
3351
  let a = fixup(color.alpha !== void 0 ? color.alpha : 1);
3355
3352
  return serializeHex(color) + (256 | a).toString(16).slice(1);
3356
3353
  };
3357
3354
  const formatCss = (c$1) => {
3358
3355
  const color = _prepare_default(c$1);
3359
- if (!color) return void 0;
3356
+ if (!color) return;
3360
3357
  const def = getMode(color.mode);
3361
3358
  if (!def.serialize || typeof def.serialize === "string") {
3362
3359
  let res = `color(${def.serialize || `--${color.mode}`} `;
@@ -3367,7 +3364,6 @@ const formatCss = (c$1) => {
3367
3364
  return res + ")";
3368
3365
  }
3369
3366
  if (typeof def.serialize === "function") return def.serialize(color);
3370
- return void 0;
3371
3367
  };
3372
3368
  const formatHex = (c$1) => serializeHex(rgb$2(c$1));
3373
3369
  const formatHex8 = (c$1) => serializeHex8(rgb$2(c$1));
@@ -3405,7 +3401,7 @@ function clampGamut(mode = "rgb") {
3405
3401
  const inDestGamut = inGamut(destMode);
3406
3402
  return (color) => {
3407
3403
  const original = _prepare_default(color);
3408
- if (!original) return void 0;
3404
+ if (!original) return;
3409
3405
  const converted = destConv(original);
3410
3406
  if (inDestGamut(converted)) return original;
3411
3407
  const clamped = fixup_rgb(converted);
@@ -3424,7 +3420,7 @@ function toGamut(dest = "rgb", mode = "oklch", delta = differenceEuclidean("oklc
3424
3420
  if (!ranges.l || !ranges.c) throw new Error("LCH-like space expected");
3425
3421
  return (color) => {
3426
3422
  color = _prepare_default(color);
3427
- if (color === void 0) return void 0;
3423
+ if (color === void 0) return;
3428
3424
  const candidate = { ...ucs(color) };
3429
3425
  if (candidate.l === void 0) candidate.l = 0;
3430
3426
  if (candidate.c === void 0) candidate.c = 0;
@@ -3460,7 +3456,7 @@ function toGamut(dest = "rgb", mode = "oklch", delta = differenceEuclidean("oklc
3460
3456
  }
3461
3457
 
3462
3458
  //#endregion
3463
- //#region ../token-tools/dist/string-BwN3ybNv.js
3459
+ //#region ../token-tools/dist/string-Dpqb78jQ.js
3464
3460
  const HEX_RE = /^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i;
3465
3461
  const CULORI_TO_CSS = {
3466
3462
  a98: "a98-rgb",
@@ -3516,14 +3512,13 @@ function parseColor(color) {
3516
3512
  case "p3":
3517
3513
  case "prophoto":
3518
3514
  case "lrgb":
3519
- case "rgb": {
3515
+ case "rgb":
3520
3516
  components = [
3521
3517
  result.r,
3522
3518
  result.g,
3523
3519
  result.b
3524
3520
  ];
3525
3521
  break;
3526
- }
3527
3522
  case "hsl": {
3528
3523
  const maxS = COLORSPACE[colorSpace].ranges[1]?.[1] ?? 1;
3529
3524
  const maxL = COLORSPACE[colorSpace].ranges[2]?.[1] ?? 1;
@@ -3546,40 +3541,36 @@ function parseColor(color) {
3546
3541
  }
3547
3542
  case "lab":
3548
3543
  case "lab65":
3549
- case "oklab": {
3544
+ case "oklab":
3550
3545
  components = [
3551
3546
  result.l,
3552
3547
  result.a,
3553
3548
  result.b
3554
3549
  ];
3555
3550
  break;
3556
- }
3557
3551
  case "lch":
3558
- case "oklch": {
3552
+ case "oklch":
3559
3553
  components = [
3560
3554
  result.l,
3561
3555
  result.c,
3562
3556
  result.h ?? 0
3563
3557
  ];
3564
3558
  break;
3565
- }
3566
- case "okhsv": {
3559
+ case "okhsv":
3567
3560
  components = [
3568
3561
  result.h ?? 0,
3569
3562
  result.s,
3570
3563
  result.v
3571
3564
  ];
3572
3565
  break;
3573
- }
3574
3566
  case "xyz50":
3575
- case "xyz65": {
3567
+ case "xyz65":
3576
3568
  components = [
3577
3569
  result.x,
3578
3570
  result.y,
3579
3571
  result.z
3580
3572
  ];
3581
3573
  break;
3582
- }
3583
3574
  }
3584
3575
  const value = {
3585
3576
  colorSpace,
@@ -3635,9 +3626,8 @@ function tokenToCulori(value) {
3635
3626
  case "lab-d65":
3636
3627
  case "oklab": {
3637
3628
  const [l, a, b] = value.components;
3638
- const mode = value.colorSpace === "lab-d65" ? "lab65" : value.colorSpace;
3639
3629
  return {
3640
- mode,
3630
+ mode: value.colorSpace === "lab-d65" ? "lab65" : value.colorSpace,
3641
3631
  l,
3642
3632
  a,
3643
3633
  b,
@@ -3906,10 +3896,9 @@ function validateCustomTransform(value, { $type }) {
3906
3896
  if (value) {
3907
3897
  if (typeof value !== "string" && typeof value !== "object" || Array.isArray(value)) throw new Error(`transform(): expected string or Object of strings, received ${Array.isArray(value) ? "Array" : typeof value}`);
3908
3898
  switch ($type) {
3909
- case "typography": {
3899
+ case "typography":
3910
3900
  if (typeof value !== "object") throw new Error("transform(): typography tokens must be an object of keys");
3911
3901
  break;
3912
- }
3913
3902
  }
3914
3903
  }
3915
3904
  }
@@ -4159,9 +4148,8 @@ function transformShadowLayer(value, options) {
4159
4148
  const offsetY = partialAliasOf?.offsetY ? transformAlias(tokensSet[partialAliasOf.offsetY]) : transformDimension({ $value: value.offsetY }, options);
4160
4149
  const blur = partialAliasOf?.blur ? transformAlias(tokensSet[partialAliasOf.blur]) : transformDimension({ $value: value.blur }, options);
4161
4150
  const spread = partialAliasOf?.spread ? transformAlias(tokensSet[partialAliasOf.spread]) : transformDimension({ $value: value.spread }, options);
4162
- const inset = value?.inset === true ? "inset" : void 0;
4163
4151
  return [
4164
- inset,
4152
+ value?.inset === true ? "inset" : void 0,
4165
4153
  offsetX,
4166
4154
  offsetY,
4167
4155
  blur,
@@ -4214,28 +4202,23 @@ function transformTypography(token, options) {
4214
4202
  const resolvedToken = tokensSet[aliasedID];
4215
4203
  transformedValue = transformAlias(resolvedToken.$type === "typography" ? { id: `${aliasedID}-${property}` } : resolvedToken);
4216
4204
  } else switch (property) {
4217
- case "fontFamily": {
4205
+ case "fontFamily":
4218
4206
  transformedValue = transformFontFamily({ $value: subvalue }, options);
4219
4207
  break;
4220
- }
4221
4208
  case "fontSize":
4222
- case "letterSpacing": {
4209
+ case "letterSpacing":
4223
4210
  transformedValue = transformDimension({ $value: subvalue }, options);
4224
4211
  break;
4225
- }
4226
- case "fontWeight": {
4212
+ case "fontWeight":
4227
4213
  transformedValue = transformFontWeight({ $value: subvalue }, options);
4228
4214
  break;
4229
- }
4230
- case "lineHeight": {
4215
+ case "lineHeight":
4231
4216
  if (typeof subvalue === "number") transformedValue = transformNumber({ $value: subvalue }, options);
4232
4217
  else transformedValue = transformDimension({ $value: subvalue }, options);
4233
4218
  break;
4234
- }
4235
- default: {
4219
+ default:
4236
4220
  transformedValue = transformString({ $value: subvalue }, options);
4237
4221
  break;
4238
- }
4239
4222
  }
4240
4223
  output[kebabCase(property)] = transformedValue;
4241
4224
  }
@@ -4354,17 +4337,16 @@ function generateUtilityCSS(groups, tokens) {
4354
4337
  break;
4355
4338
  }
4356
4339
  switch (group) {
4357
- case "bg": {
4340
+ case "bg":
4358
4341
  for (const token of matchingTokens) {
4359
4342
  const selector = makeSelector(token, "bg");
4360
4343
  switch (token.token.$type) {
4361
- case "color": {
4344
+ case "color":
4362
4345
  output.push({
4363
4346
  selectors: [selector],
4364
4347
  declarations: { "background-color": makeVarValue(token) }
4365
4348
  });
4366
4349
  break;
4367
- }
4368
4350
  case "gradient": output.push({
4369
4351
  selectors: [selector],
4370
4352
  declarations: { "background-image": { value: `linear-gradient(${makeCSSVar(token.localID ?? token.token.id, { wrapVar: true })})` } }
@@ -4372,8 +4354,7 @@ function generateUtilityCSS(groups, tokens) {
4372
4354
  }
4373
4355
  }
4374
4356
  break;
4375
- }
4376
- case "border": {
4357
+ case "border":
4377
4358
  for (const token of matchingTokens) {
4378
4359
  const property = {
4379
4360
  border: "border",
@@ -4404,8 +4385,7 @@ function generateUtilityCSS(groups, tokens) {
4404
4385
  });
4405
4386
  }
4406
4387
  break;
4407
- }
4408
- case "font": {
4388
+ case "font":
4409
4389
  for (const token of matchingTokens) {
4410
4390
  const selector = makeSelector(token, "font");
4411
4391
  if (token.token.$type === "typography" && token.type === "MULTI_VALUE") {
@@ -4428,7 +4408,6 @@ function generateUtilityCSS(groups, tokens) {
4428
4408
  }
4429
4409
  }
4430
4410
  break;
4431
- }
4432
4411
  case "layout": {
4433
4412
  const filteredTokens = matchingTokens.filter((t) => t.token.$type === "dimension");
4434
4413
  for (const token of filteredTokens) output.push({
@@ -4487,26 +4466,24 @@ function generateUtilityCSS(groups, tokens) {
4487
4466
  }
4488
4467
  break;
4489
4468
  }
4490
- case "shadow": {
4469
+ case "shadow":
4491
4470
  for (const token of matchingTokens) if (token.token.$type === "shadow") output.push({
4492
4471
  selectors: [makeSelector(token, "shadow")],
4493
4472
  declarations: { "box-shadow": makeVarValue(token) }
4494
4473
  });
4495
4474
  break;
4496
- }
4497
- case "text": {
4475
+ case "text":
4498
4476
  for (const token of matchingTokens) {
4499
4477
  const selector = makeSelector(token, "text");
4500
4478
  const value = makeVarValue(token);
4501
4479
  switch (token.token.$type) {
4502
- case "color": {
4480
+ case "color":
4503
4481
  output.push({
4504
4482
  selectors: [selector],
4505
4483
  declarations: { color: value }
4506
4484
  });
4507
4485
  break;
4508
- }
4509
- case "gradient": {
4486
+ case "gradient":
4510
4487
  output.push({
4511
4488
  selectors: [selector],
4512
4489
  declarations: {
@@ -4516,15 +4493,12 @@ function generateUtilityCSS(groups, tokens) {
4516
4493
  }
4517
4494
  });
4518
4495
  break;
4519
- }
4520
4496
  }
4521
4497
  }
4522
4498
  break;
4523
- }
4524
- default: {
4499
+ default:
4525
4500
  console.warn(`[@terrazzo/plugin-css] unknown utility CSS group "${group}", ignoring`);
4526
4501
  break;
4527
- }
4528
4502
  }
4529
4503
  }
4530
4504
  return output;
@@ -4534,7 +4508,7 @@ function generateUtilityCSS(groups, tokens) {
4534
4508
  //#region src/build/index.ts
4535
4509
  const P3_MQ = "@media (color-gamut: p3)";
4536
4510
  const REC2020_MQ = "@media (color-gamut: rec2020)";
4537
- function buildFormat({ getTransforms, exclude, utility, modeSelectors, baseSelector }) {
4511
+ function buildFormat({ getTransforms, exclude, utility, modeSelectors, baseSelector, baseScheme }) {
4538
4512
  const rules = [];
4539
4513
  const rootTokens = getTransforms({
4540
4514
  format: FORMAT_ID,
@@ -4557,6 +4531,7 @@ function buildFormat({ getTransforms, exclude, utility, modeSelectors, baseSelec
4557
4531
  };
4558
4532
  rules.push(rootRule, p3Rule, rec2020Rule);
4559
4533
  const shouldExclude = wildcardMatch(exclude ?? []);
4534
+ if (baseScheme) rootRule.declarations["color-scheme"] = { value: baseScheme };
4560
4535
  for (const token of rootTokens) {
4561
4536
  if (shouldExclude(token.token.id)) continue;
4562
4537
  const localID = token.localID ?? token.token.id;
@@ -4609,7 +4584,7 @@ function buildFormat({ getTransforms, exclude, utility, modeSelectors, baseSelec
4609
4584
  }
4610
4585
  }
4611
4586
  }
4612
- for (const { selectors, tokens, mode } of modeSelectors ?? []) {
4587
+ for (const { selectors, tokens, mode, scheme } of modeSelectors ?? []) {
4613
4588
  if (!selectors.length) continue;
4614
4589
  const selectorTokens = getTransforms({
4615
4590
  format: FORMAT_ID,
@@ -4633,6 +4608,7 @@ function buildFormat({ getTransforms, exclude, utility, modeSelectors, baseSelec
4633
4608
  };
4634
4609
  const selectorAliasDeclarations = {};
4635
4610
  rules.push(selectorRule, selectorP3Rule, selectorRec2020Rule);
4611
+ if (scheme) selectorRule.declarations["color-scheme"] = { value: scheme };
4636
4612
  for (const token of selectorTokens) {
4637
4613
  const localID = token.localID ?? token.token.id;
4638
4614
  const aliasTokens = token.token.aliasedBy?.length ? getTransforms({
@@ -4702,7 +4678,7 @@ function buildFormat({ getTransforms, exclude, utility, modeSelectors, baseSelec
4702
4678
  //#endregion
4703
4679
  //#region src/index.ts
4704
4680
  function cssPlugin(options) {
4705
- const { exclude, variableName, modeSelectors, transform: customTransform, utility, legacyHex, skipBuild } = options ?? {};
4681
+ const { exclude, variableName, modeSelectors, transform: customTransform, utility, legacyHex, skipBuild, baseScheme } = options ?? {};
4706
4682
  const filename = options?.filename ?? options?.fileName ?? "index.css";
4707
4683
  const baseSelector = options?.baseSelector ?? ":root";
4708
4684
  function transformName(token) {
@@ -4717,12 +4693,11 @@ function cssPlugin(options) {
4717
4693
  return {
4718
4694
  name: "@terrazzo/plugin-css",
4719
4695
  async transform({ tokens, getTransforms, setTransform }) {
4720
- const cssTokens = getTransforms({
4696
+ if (getTransforms({
4721
4697
  format: FORMAT_ID,
4722
4698
  id: "*",
4723
4699
  mode: "*"
4724
- });
4725
- if (cssTokens.length) return;
4700
+ }).length) return;
4726
4701
  for (const [id, token] of Object.entries(tokens)) {
4727
4702
  const localID = transformName(token);
4728
4703
  for (const mode of Object.keys(token.mode)) {
@@ -4762,7 +4737,8 @@ function cssPlugin(options) {
4762
4737
  getTransforms,
4763
4738
  modeSelectors,
4764
4739
  utility,
4765
- baseSelector
4740
+ baseSelector,
4741
+ baseScheme
4766
4742
  }), "\n");
4767
4743
  outputFile(filename, output.join("\n"));
4768
4744
  }