@terpjs/contract 0.30.0 → 0.32.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.
@@ -26,8 +26,11 @@ const pairsSource = JSON.parse(fs.readFileSync(here("../token-pairs.json"), "utf
26
26
  const registry = JSON.parse(fs.readFileSync(here("../themes.json"), "utf8"));
27
27
 
28
28
  const rules = parseRules(tokensCss);
29
+ // The rule whose selector LIST names `selector`: a renamed theme's rule lists its earlier names
30
+ // beside its own (themes.json aliases).
29
31
  const declarationsFor = (selector) =>
30
- rules.find((rule) => rule.selector === selector).declarations;
32
+ rules.find((rule) => rule.selector.split(",").map((part) => part.trim()).includes(selector))
33
+ .declarations;
31
34
  const base = declarationsFor(":root");
32
35
 
33
36
  /** Each theme's own block: the base on `:root`, every other on its attribute selector. */
@@ -69,10 +72,13 @@ describe("token manifest", () => {
69
72
  // a tool a theme it cannot apply.
70
73
  expect(manifest.base).toBe(registry.base);
71
74
  expect(manifest.systemDark).toBe(registry.systemDark);
75
+ // `aliases` on every theme, empty where it has none, so a tool mapping a stored or
76
+ // hand-written old name (dark, midnight, light) to today's needs no special case.
72
77
  expect(manifest.themes).toEqual(
73
- registry.themes.map(({ name, label, appearance, description, minimumContrast }) => ({
78
+ registry.themes.map(({ name, label, appearance, description, minimumContrast, aliases }) => ({
74
79
  name,
75
80
  label,
81
+ aliases: aliases ?? [],
76
82
  appearance,
77
83
  description,
78
84
  minimumContrast: minimumContrast ?? 4.5,
@@ -112,6 +118,14 @@ describe("token manifest", () => {
112
118
  `${theme.name}: the non-text bar must not exceed the text bar`,
113
119
  ).toBeLessThan(theme.minimumContrast);
114
120
  }
121
+ // The APCA floors, which the gate reads back the same way, published with the build they
122
+ // were measured under because an Lc means nothing without its constants. Pinned whole: a
123
+ // floor that moved is a decision for ADR 0170 to record, not a side effect of editing the
124
+ // builder, and the gate would follow it silently because it reads this value.
125
+ expect(manifest.apca).toEqual({
126
+ version: "0.0.98G-4g",
127
+ minimumLc: { body: 90, secondary: 75, incidental: 60 },
128
+ });
115
129
  });
116
130
 
117
131
  it("records the value each token resolves to, in every theme", () => {
@@ -45,9 +45,14 @@ const registry = JSON.parse(fs.readFileSync(here("../themes.json"), "utf8"));
45
45
  const BASE = registry.themes.find((theme) => theme.name === registry.base);
46
46
  const OVERLAYS = registry.themes.filter((theme) => theme.name !== registry.base);
47
47
 
48
- /** The base theme lives on `:root`; every other theme on its own attribute selector. */
48
+ /**
49
+ * The base theme lives on `:root`; every other theme on its own attribute selector -- its name,
50
+ * then each earlier name it answers to (`aliases`), in ONE rule, so an old name paints exactly
51
+ * what the new one does.
52
+ */
49
53
  const BASE_SELECTOR = ":root";
50
- const selectorFor = (theme) => `[data-theme='${theme.name}']`;
54
+ const selectorFor = (theme) =>
55
+ [theme.name, ...(theme.aliases ?? [])].map((name) => `[data-theme='${name}']`).join(",\n");
51
56
  /** The `@media (prefers-color-scheme: dark)` copy of the `systemDark` theme. */
52
57
  const SYSTEM_DARK_SELECTOR = ":root:not([data-theme])";
53
58
 
@@ -100,6 +105,33 @@ describe("token sheet themes", () => {
100
105
  expect([...appearances].sort()).toEqual(["dark", "light"]);
101
106
  });
102
107
 
108
+ it("paints every earlier name exactly as the theme it now names", () => {
109
+ // The themes were renamed for the time of day they suit, and a rename must not change any
110
+ // app's palette: a stored choice, a defaultTheme and a hand-written data-theme="dark" all
111
+ // predate it. So each alias sits in its theme's OWN rule -- the same block, not a copy that
112
+ // could drift -- and no name is claimed twice. The base's alias needs no rule: the base is
113
+ // :root, and an attribute no overlay matches leaves it standing.
114
+ // Mutation: drop the aliases from the generator's selector, and the dark/midnight names
115
+ // stop matching any rule here.
116
+ const claimed = new Set();
117
+ for (const theme of registry.themes) {
118
+ for (const name of [theme.name, ...(theme.aliases ?? [])]) {
119
+ expect(claimed.has(name), `${name} is claimed twice`).toBe(false);
120
+ claimed.add(name);
121
+ }
122
+ }
123
+ const renamed = { light: "midday", dark: "evening", midnight: "night" };
124
+ for (const [old, now] of Object.entries(renamed)) {
125
+ const theme = registry.themes.find((entry) => entry.name === now);
126
+ expect(theme?.aliases, `${now} answers to ${old}`).toContain(old);
127
+ if (theme.name === registry.base) continue;
128
+ const rule = ruleFor(selectorFor(theme));
129
+ expect(rule.selector, `[data-theme='${old}'] shares ${now}'s rule`).toContain(
130
+ `[data-theme='${old}']`,
131
+ );
132
+ }
133
+ });
134
+
103
135
  it("registers every theme source that exists on disk", () => {
104
136
  // A `tokens.<name>.json` nobody registered compiles to nothing and is invisible: no
105
137
  // block, no gate, no manifest entry. Registration is explicit on purpose, so the failure
package/themes.json CHANGED
@@ -1,35 +1,44 @@
1
1
  {
2
- "$comment": "The shipped themes, as data. `scripts/build-tokens.mjs` compiles one stylesheet block per entry and publishes the same list in the token manifest; `src/tokens.themes.test.js` holds every entry to completeness and `src/tokens.contrast.test.js` holds every entry to WCAG AA, or to `minimumContrast` where an entry sets a higher floor. Registration is explicit rather than a glob over `tokens.*.json`, because four things about a theme cannot be inferred from its file: which theme the OS dark preference selects, whether a theme reads as light or dark to native chrome, what contrast it promises, and what to call it. A theme is added by writing its overlay and adding it here — nothing else, and the gates refuse it if the overlay is incomplete or illegible.",
3
- "base": "light",
4
- "systemDark": "dark",
2
+ "$comment": "The shipped themes, as data. `scripts/build-tokens.mjs` compiles one stylesheet block per entry and publishes the same list in the token manifest; `src/tokens.themes.test.js` holds every entry to completeness and `src/tokens.contrast.test.js` holds every entry to WCAG AA, or to `minimumContrast` where an entry sets a higher floor. Registration is explicit rather than a glob over `tokens.*.json`, because five things about a theme cannot be inferred from its file: which theme the OS dark preference selects, whether a theme reads as light or dark to native chrome, what contrast it promises, what to call it, and which names it used to have. A theme is added by writing its overlay and adding it here — nothing else, and the gates refuse it if the overlay is incomplete or illegible. `aliases` are those earlier names: the themes were renamed for the time of day they suit (light → midday, dark → evening, midnight → night), and an alias is compiled into the same selector as its theme and accepted wherever a theme is named, so a stored choice, an app's defaultTheme and a data-theme attribute written before the rename keep their palette.",
3
+ "base": "midday",
4
+ "systemDark": "night",
5
5
  "themes": [
6
6
  {
7
- "name": "light",
8
- "label": "Light",
7
+ "name": "midday",
8
+ "label": "Midday",
9
9
  "appearance": "light",
10
10
  "source": "tokens.json",
11
+ "aliases": [
12
+ "light"
13
+ ],
11
14
  "description": "The default. Carries every token, including the geometry the other themes inherit."
12
15
  },
13
16
  {
14
- "name": "dark",
15
- "label": "Dark",
17
+ "name": "twilight",
18
+ "label": "Twilight",
16
19
  "appearance": "dark",
17
- "source": "tokens.dark.json",
18
- "description": "The slate-neutral dark counterpart to light, and the theme the OS dark preference selects."
20
+ "source": "tokens.twilight.json",
21
+ "description": "A dimmed violet dark between midday and evening: light text on violet-grey surfaces well above evening's near-black, for a room that is getting dark rather than one that is."
19
22
  },
20
23
  {
21
- "name": "midnight",
22
- "label": "Midnight",
24
+ "name": "evening",
25
+ "label": "Evening",
23
26
  "appearance": "dark",
24
- "source": "tokens.midnight.json",
25
- "description": "A near-black dark for low light and OLED displays: cooler neutrals, a deeper canvas than dark, and a deeper accent that holds a white label at AA."
27
+ "source": "tokens.evening.json",
28
+ "aliases": [
29
+ "dark"
30
+ ],
31
+ "description": "The slate-neutral dark counterpart to midday."
26
32
  },
27
33
  {
28
- "name": "twilight",
29
- "label": "Twilight",
34
+ "name": "night",
35
+ "label": "Night",
30
36
  "appearance": "dark",
31
- "source": "tokens.twilight.json",
32
- "description": "A warm violet-tinted dark. Its neutrals sit in a different hue family from dark and midnight, which is what proves a theme is a palette rather than a lightness setting."
37
+ "source": "tokens.night.json",
38
+ "aliases": [
39
+ "midnight"
40
+ ],
41
+ "description": "A near-black dark for low light and OLED displays: cooler neutrals, a deeper canvas than evening, and a deeper accent that holds a white label at AA. The theme the OS dark preference selects."
33
42
  },
34
43
  {
35
44
  "name": "contrast",