@terrazzo/plugin-css 2.0.0-alpha.1 → 2.0.0-alpha.3

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/CHANGELOG.md CHANGED
@@ -10,12 +10,16 @@
10
10
 
11
11
  - [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - ⚠️ [Plugin API] Minor breaking change: token.originalValue may be undefined for tokens created with $ref. This shouldn’t affect any tokens or plugins not using $refs. But going forward this value will be missing if the token was created dynamically via $ref.
12
12
 
13
+ - [#589](https://github.com/terrazzoapp/terrazzo/pull/589) [`8f32d44`](https://github.com/terrazzoapp/terrazzo/commit/8f32d44792bba62194e674c9b60cfdeb366c96c7) Thanks [@michaelurban](https://github.com/michaelurban)! - feat: add typography shorthand, improve Sass plugin
14
+
13
15
  ### Patch Changes
14
16
 
15
17
  - [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - Validation moved to lint rules, which means token validation can be individually configured, and optionally extended.
16
18
 
17
19
  - [#553](https://github.com/terrazzoapp/terrazzo/pull/553) [`e63a627`](https://github.com/terrazzoapp/terrazzo/commit/e63a6277f61282fb608744a8348689b16f977076) Thanks [@Sidnioulz](https://github.com/Sidnioulz)! - Add support for the Token Listing format
18
20
 
21
+ - [#568](https://github.com/terrazzoapp/terrazzo/pull/568) [`67c75be`](https://github.com/terrazzoapp/terrazzo/commit/67c75be78978cece52b61cf258ccc3a875e6af48) Thanks [@drwpow](https://github.com/drwpow)! - Fix border tokens not cascading correctly across modes
22
+
19
23
  ## 0.10.4
20
24
 
21
25
  ### Patch Changes
package/README.md CHANGED
@@ -4,13 +4,13 @@ Convert DTCG tokens into CSS variables for use in any web application or native
4
4
 
5
5
  ## Setup
6
6
 
7
- Requires [Node.js 20 or later](https://nodejs.org) and [the CLI installed](https://terrazzo.app/docs/cli). With both installed, run:
7
+ Requires [Node.js 20 or later](https://nodejs.org) and [the CLI installed](https://terrazzo.app/docs). With both installed, run:
8
8
 
9
9
  ```sh
10
10
  npm i -D @terrazzo/plugin-css
11
11
  ```
12
12
 
13
- Add a `terrazzo.config.js` to the root of your project:
13
+ Add a `terrazzo.config.ts` to the root of your project:
14
14
 
15
15
  ```ts
16
16
  import { defineConfig } from "@terrazzo/cli";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/lib.ts","../src/build/index.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;KAEY,eAAA;KAEA,gBAAA;AAFA,cAIC,SAAA,GAJc,KAAA;AAEf,cAIC,WAAA,GAJe,uJAAA;AAEf,UAMI,gBAAA,CANK;EAET;AAIb;;;UAWyB,CAAA,EAAA,MAAA;;SAE+B,CAAA,EAAA,MAAA,EAAA;;eAE5C,CAAA,EANM,YAMN,EAAA;EAAM;EAsBD,YAAA,CAAA,EAAY,CAAA,KAAA,EA1BJ,eA0BI,EAAA,GAAA,MAAA;EAcZ;EAIA,SAAA,CAAO,EAAA,CAAA,KAAA,EA1CF,eA0CE,EAAA,IAAA,EAAA,MAAA,EAAA,GA1CgC,gBA0ChC,CAAA,OAAA,CAAA;EAAA;SAGO,CAAA,EA3CnB,MA2CmB,CA3CZ,eA2CY,EAAA,MAAA,EAAA,CAAA;;;AAI/B;AAoEA;;;;ACrIA;;WACW,CAAA,EAAA,OAAA;;;;;EAKmB,YAAA,CAAA,EAAA,MAAA;;;;ECNN,UAAA,CAAA,EAAS,MAAA;;AAAW,UFwC3B,YAAA,CExC2B;;EAAyB,IAAA,EAAA,MAAA;;;;;;;;UFsDpD,kBAAA;;;;UAIA,OAAA;;;gBAGD,eAAe;;;iBAIf,UAAA,QAAkB;UAoEjB,cAAA;;;;;;UCrIA,k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AA,SAAA,CAAA;EAIP,YAAA,EAAA,MAAgB;EASf,UAAA,ECNJ,gBDMI,CAAA,YAAA,CAAA;;;;AAjBN,iBEKY,SAAA,CFLI,OAAA,CAAA,EEKgB,gBFLhB,CAAA,EEKmC,MFLnC"}
package/dist/index.js CHANGED
@@ -2431,14 +2431,11 @@ const convertXyz65ToItp = ({ x, y, z, alpha }) => {
2431
2431
  const l = transferPqEncode(.3592832590121217 * absX + .6976051147779502 * absY - .0358915932320289 * absZ);
2432
2432
  const m = transferPqEncode(-.1920808463704995 * absX + 1.1004767970374323 * absY + .0753748658519118 * absZ);
2433
2433
  const s = transferPqEncode(.0070797844607477 * absX + .0748396662186366 * absY + .8433265453898765 * absZ);
2434
- const i = .5 * l + .5 * m;
2435
- const t = 1.61376953125 * l - 3.323486328125 * m + 1.709716796875 * s;
2436
- const p$2 = 4.378173828125 * l - 4.24560546875 * m - .132568359375 * s;
2437
2434
  const res = {
2438
2435
  mode: "itp",
2439
- i,
2440
- t,
2441
- p: p$2
2436
+ i: .5 * l + .5 * m,
2437
+ t: 1.61376953125 * l - 3.323486328125 * m + 1.709716796875 * s,
2438
+ p: 4.378173828125 * l - 4.24560546875 * m - .132568359375 * s
2442
2439
  };
2443
2440
  if (alpha !== void 0) res.alpha = alpha;
2444
2441
  return res;
@@ -2748,13 +2745,11 @@ const convertLuvToXyz50 = ({ l, u, v, alpha }) => {
2748
2745
  let up = u / (13 * l) + un;
2749
2746
  let vp = v / (13 * l) + vn;
2750
2747
  let y = D50.Y * (l <= 8 ? l / k : Math.pow((l + 16) / 116, 3));
2751
- let x = y * (9 * up) / (4 * vp);
2752
- let z = y * (12 - 3 * up - 20 * vp) / (4 * vp);
2753
2748
  let res = {
2754
2749
  mode: "xyz50",
2755
- x,
2750
+ x: y * (9 * up) / (4 * vp),
2756
2751
  y,
2757
- z
2752
+ z: y * (12 - 3 * up - 20 * vp) / (4 * vp)
2758
2753
  };
2759
2754
  if (alpha !== void 0) res.alpha = alpha;
2760
2755
  return res;
@@ -2918,8 +2913,7 @@ function find_cusp(a, b) {
2918
2913
  b: S_cusp * b
2919
2914
  });
2920
2915
  let L_cusp = Math.cbrt(1 / Math.max(rgb$4.r, rgb$4.g, rgb$4.b));
2921
- let C_cusp = L_cusp * S_cusp;
2922
- return [L_cusp, C_cusp];
2916
+ return [L_cusp, L_cusp * S_cusp];
2923
2917
  }
2924
2918
  function find_gamut_intersection(a, b, L1, C1$1, L0, cusp = null) {
2925
2919
  if (!cusp) cusp = find_cusp(a, b);
@@ -3456,7 +3450,7 @@ function toGamut(dest = "rgb", mode = "oklch", delta = differenceEuclidean("oklc
3456
3450
  }
3457
3451
 
3458
3452
  //#endregion
3459
- //#region ../token-tools/dist/string-D3-qmBT2.js
3453
+ //#region ../token-tools/dist/string-BIhoe-L2.js
3460
3454
  const HEX_RE = /^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i;
3461
3455
  const CULORI_TO_CSS = {
3462
3456
  a98: "a98-rgb",
@@ -3943,13 +3937,30 @@ function defaultAliasTransform(token) {
3943
3937
  return `var(${makeCSSVar(token.id)})`;
3944
3938
  }
3945
3939
  /** Generate shorthand CSS for select token types */
3946
- function generateShorthand({ $type, localID }) {
3947
- switch ($type) {
3940
+ function generateShorthand({ token, localID }) {
3941
+ switch (token.$type) {
3948
3942
  case "transition": return [
3949
3943
  "duration",
3950
3944
  "delay",
3951
3945
  "timing-function"
3952
3946
  ].map((p$2) => makeCSSVar(`${localID}-${p$2}`, { wrapVar: true })).join(" ");
3947
+ case "typography": {
3948
+ const typeVar = (name) => makeCSSVar(`${localID}-${name}`, { wrapVar: true });
3949
+ if ("font-size" in token.$value && "font-family" in token.$value) {
3950
+ let output = "";
3951
+ for (const prop of [
3952
+ "font-style",
3953
+ "font-variant",
3954
+ "font-weight"
3955
+ ]) if (prop in token.$value) output += ` ${typeVar(prop)}`;
3956
+ let fontSizeVar = typeVar("font-size");
3957
+ if ("line-height" in token.$value) fontSizeVar += `/${typeVar("line-height")}`;
3958
+ output += ` ${fontSizeVar}`;
3959
+ output += ` ${typeVar("font-family")}`;
3960
+ return output.trim();
3961
+ }
3962
+ break;
3963
+ }
3953
3964
  }
3954
3965
  }
3955
3966
  const CSS_VAR_RE = /(?:(\p{Uppercase_Letter}?[\p{Lowercase_Letter}\p{Number}]+|[\p{Uppercase_Letter}\p{Number}]+|[\u{80}-\u{10FFFF}\p{Number}]+)|.)/u;
@@ -4186,10 +4197,7 @@ function transformString(token, options) {
4186
4197
  function transformTransition(token, options) {
4187
4198
  const { tokensSet, transformAlias = defaultAliasTransform } = options;
4188
4199
  if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
4189
- const duration = token.partialAliasOf?.duration ? transformAlias(tokensSet[token.partialAliasOf.duration]) : transformDuration({ $value: token.$value.duration }, options);
4190
- const delay = token.partialAliasOf?.delay ? transformAlias(tokensSet[token.partialAliasOf.delay]) : transformDuration({ $value: token.$value.delay }, options);
4191
- const timingFunction = token.partialAliasOf?.timingFunction ? transformAlias(tokensSet[token.partialAliasOf.timingFunction]) : transformCubicBezier({ $value: token.$value.timingFunction }, options);
4192
- return `${duration} ${delay} ${timingFunction}`;
4200
+ return `${token.partialAliasOf?.duration ? transformAlias(tokensSet[token.partialAliasOf.duration]) : transformDuration({ $value: token.$value.duration }, options)} ${token.partialAliasOf?.delay ? transformAlias(tokensSet[token.partialAliasOf.delay]) : transformDuration({ $value: token.$value.delay }, options)} ${token.partialAliasOf?.timingFunction ? transformAlias(tokensSet[token.partialAliasOf.timingFunction]) : transformCubicBezier({ $value: token.$value.timingFunction }, options)}`;
4193
4201
  }
4194
4202
  /** Convert typography value to multiple CSS values */
4195
4203
  function transformTypography(token, options) {
@@ -4225,7 +4233,7 @@ function transformTypography(token, options) {
4225
4233
  return output;
4226
4234
  }
4227
4235
  /** Main CSS Transform */
4228
- function transformCSSValue(token, { mode,...options }) {
4236
+ function transformCSSValue(token, { mode, ...options }) {
4229
4237
  const selectedMode = token.mode[mode];
4230
4238
  if (!selectedMode) return;
4231
4239
  const tokenWithModeValue = {
@@ -4296,9 +4304,7 @@ function _printRule(rule) {
4296
4304
  output.push(`${indent}:root {`);
4297
4305
  indent += " ";
4298
4306
  }
4299
- const declarations = Object.entries(rule.declarations);
4300
- declarations.sort((a, b) => a[0].localeCompare(b[0], "en-us", { numeric: true }));
4301
- for (const [k$3, d] of declarations) output.push(`${indent}${k$3}: ${d.value};${d.description ? ` /* ${d.description} */` : ""}`);
4307
+ for (const [k$3, d] of Object.entries(rule.declarations)) output.push(`${indent}${k$3}: ${d.value};${d.description ? ` /* ${d.description} */` : ""}`);
4302
4308
  while (indent !== "") {
4303
4309
  indent = indent.substring(0, indent.length - 2);
4304
4310
  output.push(`${indent}}`);
@@ -4569,18 +4575,21 @@ function buildFormat({ getTransforms, exclude, utility, modeSelectors, baseSelec
4569
4575
  }
4570
4576
  }
4571
4577
  } else if (token.type === "MULTI_VALUE") {
4578
+ for (const [name, value] of Object.entries(token.value)) rootRule.declarations[name === "." ? localID : [localID, name].join("-")] = {
4579
+ value,
4580
+ description: token.token.$description
4581
+ };
4572
4582
  const shorthand = generateShorthand({
4573
- $type: token.token.$type,
4583
+ token: {
4584
+ ...token.token,
4585
+ $value: token.value
4586
+ },
4574
4587
  localID
4575
4588
  });
4576
4589
  if (shorthand) rootRule.declarations[token.localID ?? token.token.id] = {
4577
4590
  value: shorthand,
4578
4591
  description: token.token.$description
4579
4592
  };
4580
- for (const [name, value] of Object.entries(token.value)) rootRule.declarations[name === "." ? localID : [localID, name].join("-")] = {
4581
- value,
4582
- description: token.token.$description
4583
- };
4584
4593
  }
4585
4594
  }
4586
4595
  }
@@ -4645,18 +4654,21 @@ function buildFormat({ getTransforms, exclude, utility, modeSelectors, baseSelec
4645
4654
  }
4646
4655
  }
4647
4656
  } else {
4657
+ for (const [name, subvalue] of Object.entries(token.value)) selectorRule.declarations[`${localID}-${name}`] = {
4658
+ value: subvalue,
4659
+ description: token.token.$description
4660
+ };
4648
4661
  const shorthand = generateShorthand({
4649
- $type: token.token.$type,
4662
+ token: {
4663
+ ...token.token,
4664
+ $value: token.value
4665
+ },
4650
4666
  localID
4651
4667
  });
4652
4668
  if (shorthand) selectorRule.declarations[localID] = {
4653
4669
  value: shorthand,
4654
4670
  description: token.token.$description
4655
4671
  };
4656
- for (const [name, subvalue] of Object.entries(token.value)) selectorRule.declarations[`${localID}-${name}`] = {
4657
- value: subvalue,
4658
- description: token.token.$description
4659
- };
4660
4672
  }
4661
4673
  for (const alias of aliasTokens) if (alias.localID && typeof alias.value === "string") selectorAliasDeclarations[alias.localID] = {
4662
4674
  value: alias.value,
@@ -4724,7 +4736,7 @@ function cssPlugin(options) {
4724
4736
  if (transformedValue !== void 0) {
4725
4737
  let listingName = localID;
4726
4738
  if (typeof transformedValue === "object" && generateShorthand({
4727
- $type: token.$type,
4739
+ token,
4728
4740
  localID
4729
4741
  }) === void 0) listingName = void 0;
4730
4742
  setTransform(id, {