@designtools/tokens 0.14.0 → 0.16.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/CHANGELOG.md +41 -0
- package/README.md +76 -12
- package/dist/{chunk-7PQDEFU6.js → chunk-PG4SXPRL.js} +327 -20
- package/dist/cli.js +266 -37
- package/dist/index.d.ts +98 -1
- package/dist/index.js +23 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
Notable changes to `@designtools/tokens`. Dates are release dates; versions follow semver, with breaking changes in the minor slot while the package is pre-1.0.
|
|
4
4
|
|
|
5
|
+
## 0.16.0
|
|
6
|
+
|
|
7
|
+
### Minor Changes
|
|
8
|
+
|
|
9
|
+
- edbceee: A ground's border reads on its card: a floor of 1.5:1 against the ground's `--surface`.
|
|
10
|
+
|
|
11
|
+
- Under `tint own`, a ground's `--border` kept the page's separation from the ground and was never measured against the ground's card. After 0.14 re-spaced the ramps, a deep navy band's hairline sat one step off its card (navy 600 on a 700 card, 1.39:1) and all but vanished, with every check passing; on many dark bands the border was the card's own step (1:1). The border is now searched to at least 1.5:1 against the card, the gentlest step of its ramp that gets there, never fading on the ground to do it, so it stays a hairline and well under an input's 3:1. The navy band's border is navy-500, which is what madebymany-com pinned by hand.
|
|
12
|
+
- 1.5:1 sits above the 1.1 that lets a panel draw (a 1px line has far less area), below the 1.6 a tonal button aims for to read as a shape and the 3:1 of a control's edge, and at the page's own dark-mode hairline on its card (1.48 to 1.69:1 across the bench).
|
|
13
|
+
- Under `tint page` or one colour the lines are as asked; a border under 1.5:1 on the card is noted in `--report`.
|
|
14
|
+
- **This changes generated output** for grounds with `tint own` whose border was under 1.5:1 on their card: their `--border` moves, usually one or two steps (a dark band's to a lighter or darker step of its ramp; a pale band's, such as mist or sand at 200, one step darker). Nothing else moves. **Upgrading:** regenerate, and look at each ground's lines; a `--border` pinned in `tokens.local.css` to work around this can come out.
|
|
15
|
+
- b5af598: `--local`: a dark override reaches every dark reader, and the check holds it to that.
|
|
16
|
+
|
|
17
|
+
- `tokens.css` sets dark twice: for the toggle (`[data-theme="dark"]`, `.dark`) and for a visitor whose system is dark (`:root:not([data-theme="light"]):not(.light)` inside `@media (prefers-color-scheme: dark)`), the second at a higher specificity. The `tokens.local.css` check accepted only the toggle's selectors, so a dark override showed on the toggle, missed every system-dark visitor, and passed.
|
|
18
|
+
- The check now accepts the system-dark block exactly as `tokens.css` writes it, and requires each dark override in both places at the same value. One set only for the toggle fails with the block to add: `--surface in [data-theme="dark"] or .dark: a visitor whose system is dark keeps the generated value, since the system-dark block outranks the toggle. Set the same under system dark: @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]):not(.light) { --surface: …; } }`. One set only under system dark fails the other way. Overrides under system dark are re-checked for contrast like the rest. `LocalProblem` has a new kind, `"dark"`.
|
|
19
|
+
- **Upgrading:** a `tokens.local.css` with dark overrides under `[data-theme="dark"]` or `.dark` alone now exits 1. Paste the block the message gives after them. Any other at-rule is still refused.
|
|
20
|
+
- d358fbb: `--color` refuses a reserved name where it is given, with the reason and the list.
|
|
21
|
+
|
|
22
|
+
- `--color "yellow=#ffff00@200"` used to produce no `yellow` ramp: it recoloured warning instead, and the mistake only showed later, as `--ground-action midnight=yellow-200` failing with "names no ramp: yellow". Now it fails at the flag: `"yellow" is warning's second name (written by --aliases), so it never becomes a ramp of its own: recolour warning with --color warning=…, or give this colour another name`, followed by the reserved names.
|
|
23
|
+
- Reserved, with or without `--aliases`: `green`, `red` and `yellow` (the status colours' second names), `white` and `black` (the fixed colours, which a ramp would replace), and the page tokens `canvas`, `surface`, `overlay`, `foreground`, `border`, `input`, `ring` and `shadow` (`--color border=…` wrote a second `--border`). The same names are refused in a seed file's `additionalColors`.
|
|
24
|
+
- **Upgrading:** a command or seed that adds a colour under one of these names now exits 1. To recolour a status colour, name it (`--color warning=…`, `--color destructive=…`); for a colour of your own, give it another name (`sun`, `brick`). With `--aliases`, recolouring by the status name still moves both names.
|
|
25
|
+
- Exported: `RESERVED_COLOR_NAMES`, `reservedColorReason`. The library's `generateTokens` is unchanged.
|
|
26
|
+
- 220e546: The type tiers of the owned scale are closed: a new name there is a step, never a use.
|
|
27
|
+
|
|
28
|
+
- **`scale --verify`** and **`designtools-manifest check`** now fail a name in `--text-*`, `--leading-*`, `--tracking-*` or `--font-weight-*` that is not a step of that tier: `--text-display`, `--text-headline`, `--text-label`, `--text-cta` and `--leading-lead` all fail. The steps are Tailwind's own words, plus the ones between two of them: text `3xs`, `2xs`, `xs`, `sm`, `base`, `lg`, `xl`, `2xl` to `9xl` (with their `--line-height`, `--letter-spacing` and `--font-weight` companions); leading `none`, `tightest`, `tighter`, `tight`, `snug`, `medium`, `normal`, `relaxed`, `loose`, `looser`, `loosest`; tracking `tightest`, `tighter`, `tight`, `normal`, `wide`, `wider`, `widest`; weights `thin`, `extralight`, `light`, `normal`, `medium`, `semibold`, `bold`, `extrabold`, `black`. The message names the tier's steps and says what to do instead: a size that changes by screen is set in the component (`text-5xl lg:text-8xl`); a role a page uses (display, headline, label) is a step, mapped in the docs config's `type.hierarchy`.
|
|
29
|
+
- **Upgrading:** run `generate-tokens scale --verify` on your `scale.css`. For each name it refuses, set the component in a step (`--text-display: 4rem` becomes `--text-6xl: 4rem`, or an existing step), replace the use's utility in the code (`text-display` to `text-6xl`), and map the role to the step in the docs config's `type.hierarchy`. Spacing, size, container, radius, shadow, duration, ease and breakpoint still take any name inside their namespace (`--spacing-section-lg`).
|
|
30
|
+
- **`scale --init`** refuses an `--overrides` name in a type tier that is not a step, so an owned scale starts inside the contract.
|
|
31
|
+
- The owned scale's header no longer invites new names in the type tiers; a scale written before keeps its old header, which is only a comment.
|
|
32
|
+
- `ScaleVerdict` has a new `offScale` list. Exported: `TYPE_STEPS`, `offScaleReason`, `OFF_SCALE_ADVICE`.
|
|
33
|
+
|
|
34
|
+
## 0.15.0
|
|
35
|
+
|
|
36
|
+
### Minor Changes
|
|
37
|
+
|
|
38
|
+
- 41dd086: The scale is written once and owned by the project; the colour has one checked place for overrides; one command sets a project up.
|
|
39
|
+
|
|
40
|
+
- **`generate-tokens scale --init`** writes the non-colour scale once, with a header marking it the project's own, then refuses to write over it (`--force` rewrites, after listing what changes). Nothing regenerates it and no overrides file tracks it. **`scale --verify <file>`** checks its names against the contract: every default name kept, every added name inside a tier's namespace; values are never compared. Regenerating without `--init`, and `scale --check`, still work and warn. Exported: `verifyScale`, `isOwnedScale`, `ownedScaleHeader`, `OWNED_SCALE_MARK`.
|
|
41
|
+
- **`--local <file>`**: the project's colour overrides (`tokens.local.css`), checked on every run. Only the generator's selectors, only its token names (never a `--color-*` alias, ramp step or new name), and values that point at the system (`var()`, or a ramp step nudged with relative colour), never a literal colour. Every override is listed as pinned by hand, and each pair it touches is re-checked for contrast at `--target`. Exit 1 on any problem. Exported: `checkLocalOverrides`.
|
|
42
|
+
- **`generate-tokens init`** writes `tokens.css`, an empty `tokens.local.css` and the owned `scale.css` in `--dir` (default `app/styles`), and with `--entry` adds their imports to a stylesheet, in order. Run again, it keeps the scale and the overrides and regenerates the colour.
|
|
43
|
+
- **`designtools-manifest check`** holds an owned scale to the same contract, so it is checked on every commit. A project without one is told how to make one, not failed.
|
|
44
|
+
- `--help`: the `--only grounds` line names the `[data-surface]` scopes it writes, not the `--on-*` tokens 0.12 stopped writing.
|
|
45
|
+
|
|
5
46
|
## 0.14.0
|
|
6
47
|
|
|
7
48
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -193,6 +193,8 @@ A **ground** is a section painted one step of a ramp: a deep green band, a lime
|
|
|
193
193
|
| `own` | steps from the ground's ramp, searched to the text floors | steps from the ground's ramp, each searched to its floor: a deeper green line on green | a step off the ground on its ramp, as far from it as the page's card is from the page: a lighter green card on deep green |
|
|
194
194
|
| one colour: `white`, `black`, or a step (`sage-100`) | that colour for body and secondary text both (the report says secondary text is then no quieter) | as `own`, with that colour for every line, edge and ring: white lines on deep green | that colour for the card and the quiet panel, their text the ground's where it reads and white or black where it doesn't. The report notes a card that doesn't draw against the ground |
|
|
195
195
|
|
|
196
|
+
**A ground's hairline reads on its card.** Under `tint own` the border keeps the separation the page's has from the page, and then at least 1.5:1 against the ground's card, so a card's edge and a rule inside it still show: on a deep navy band with a navy-700 card, navy-500 rather than 600 (1.39:1, all but gone). It is the gentlest step of its ramp that reaches that, never fading on the ground to do it, so it stays a hairline, well under an input's 3:1. Under `tint page` or one colour the lines are as asked, and the report notes a border under 1.5:1 on the card.
|
|
197
|
+
|
|
196
198
|
Defaults: `text page`, `tint own`, and panels unset, which follow the lines: the page's under `tint page`, the ground's own otherwise. So text is one standard set across a site, and lines and panels take each ground's hue. A bare value sets every ground; `<name>=<value>` sets one and wins: `--ground-tint own --ground-tint pine=white`. In a seed: `"grounds": { "pine": { "ramp": "pine", "step": 800, "tint": "white", "panels": "page" } }`, `"groundTint"`, `"groundPanels"`, `"groundText"`.
|
|
197
199
|
|
|
198
200
|
**Buttons and other colours keep the page's value unless it fails.** The primary and secondary buttons, accent, success, error and warning are the page's wherever they stand out from the ground (3:1 for a fill, with a label that reads on it). One that doesn't is searched along its own ramp: a navy button on deep green moves to a step that shows. Under `tint own` (and one colour) the primary button is drawn from the ground's ramp (on its own colour it turns over: the deepest step with the ground's colour in its label), and the secondary button is tonal: a tint of the ground's hue whose label carries it.
|
|
@@ -308,6 +310,8 @@ This is deliberately a **dumb, deterministic tool** — no model, no network, no
|
|
|
308
310
|
- **`--ramps` + `--merge` for partial regeneration.** Change one colour in a file a human has also edited, without rewriting their work. See [Regenerating part of a token file](#regenerating-part-of-a-token-file).
|
|
309
311
|
- **`--only` for tier-level slicing.** Keep generated colour in a different file from anything hand-tuned.
|
|
310
312
|
- **`--seed` / `--stdin`** to replay a whole configuration from JSON instead of assembling flags.
|
|
313
|
+
- **`--local` for overrides.** The one place for a colour a flag can't say, checked against the system and against contrast on every run. See [Overriding the colour](#overriding-the-colour).
|
|
314
|
+
- **`init` for a new project.** The colour, the override file and the scale, wired in, in one step. See [Setting a project up](#setting-a-project-up).
|
|
311
315
|
|
|
312
316
|
Generated files carry a provenance header naming the version and a hash of the inputs, so an agent can tell "the generator was upgraded" apart from "a human edited this":
|
|
313
317
|
|
|
@@ -327,14 +331,65 @@ check: tokens.css differs — same generator and seed, so the file was edited by
|
|
|
327
331
|
check: tokens.css differs — generated by v0.4.0, running v0.5.0. Expected after a generator upgrade.
|
|
328
332
|
```
|
|
329
333
|
|
|
334
|
+
## Setting a project up
|
|
335
|
+
|
|
336
|
+
One command sets a project's tokens up, so none starts without the scale or invents its own way of overriding the colour:
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
npx @designtools/tokens init --primary "#4e9caf" --dir app/styles --entry app/styles/globals.css
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
It writes three files in `--dir` (default `app/styles`) and, with `--entry`, adds their imports to a stylesheet after Tailwind's own, in the order they cascade:
|
|
343
|
+
|
|
344
|
+
| File | What it is | Who changes it |
|
|
345
|
+
| --- | --- | --- |
|
|
346
|
+
| `tokens.css` | The colour, generated from the flags | The generator, every run; `--check` in CI |
|
|
347
|
+
| `tokens.local.css` | The project's overrides of that colour, empty to start | The project, held to the system's terms; checked every run |
|
|
348
|
+
| `scale.css` | Everything that isn't colour, written once | The project, by hand; the names checked by `designtools-manifest check` |
|
|
349
|
+
|
|
350
|
+
Every other flag goes to the colour run, as it would without `init`. Run again, `init` keeps the scale and the override file (they are the project's) and regenerates the colour.
|
|
351
|
+
|
|
352
|
+
## Overriding the colour
|
|
353
|
+
|
|
354
|
+
Most changes are an input: a flag, the seed, shade overrides. For the few a flag can't say, there is one place, `tokens.local.css`, loaded straight after `tokens.css`, and the generator holds it to the system's own terms on every run (`--local <file>`; `init` passes it for you):
|
|
355
|
+
|
|
356
|
+
- **Selectors are the generator's own:** `:root`, `[data-theme="light"]`, `[data-theme="dark"]`, `.dark` and `[data-surface="<ground>"]`, alone or in a list, and the system-dark block exactly as `tokens.css` writes it. No other at-rule.
|
|
357
|
+
- **A dark override reaches every dark reader.** `tokens.css` sets dark twice: for the toggle (`[data-theme="dark"]`, `.dark`) and for a visitor whose system is dark (`:root:not([data-theme="light"]):not(.light)` inside `@media (prefers-color-scheme: dark)`), the second at a higher specificity. An override set only for the toggle misses a system-dark visitor, toggle or not, so each dark override is set in both, to the same value. The check names any that isn't, and gives the block to add.
|
|
358
|
+
- **Names are tokens the generator writes:** never a `--color-*` alias or ramp step (move a step with shade overrides; set a token by its own name), and never a new name. A name of the project's own belongs in its own stylesheet.
|
|
359
|
+
- **Values point at the system:** `var()` references, or a ramp step nudged with relative colour, never a literal colour.
|
|
360
|
+
|
|
361
|
+
```css
|
|
362
|
+
/* tokens.local.css */
|
|
363
|
+
[data-surface="navy"] {
|
|
364
|
+
--surface: oklch(from var(--color-navy-800) calc(l + 0.07) c h);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/* a dark override, for both dark readers */
|
|
368
|
+
[data-theme="dark"], .dark {
|
|
369
|
+
--surface: var(--color-neutral-800);
|
|
370
|
+
}
|
|
371
|
+
@media (prefers-color-scheme: dark) {
|
|
372
|
+
:root:not([data-theme="light"]):not(.light) {
|
|
373
|
+
--surface: var(--color-neutral-800);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
Each override is listed as pinned by hand, and every pair it touches (a surface and the text set on it) is re-checked for contrast at `--target`, so a pinned card can't quietly fail its text. Any problem exits 1:
|
|
379
|
+
|
|
380
|
+
```
|
|
381
|
+
local: pinned by hand: --surface in [data-surface="navy"]
|
|
382
|
+
local: tokens.local.css keeps to the system (1 pinned)
|
|
383
|
+
local: tokens.local.css: --surface-foreground-secondary on --surface in [data-surface="lime"]: 4.24:1, under 4.5:1
|
|
384
|
+
```
|
|
385
|
+
|
|
330
386
|
## The scale: everything that isn't colour
|
|
331
387
|
|
|
332
|
-
Colour comes from a seed; the rest of a system has none,
|
|
388
|
+
Colour comes from a seed; the rest of a system has none, and its values are art direction. So the scale is written once, as defaults to start from, and from then on it is the project's own file: edited by hand, never regenerated, and tracked by no overrides file.
|
|
333
389
|
|
|
334
390
|
```bash
|
|
335
|
-
npx @designtools/tokens scale --format tailwind-v4 --
|
|
336
|
-
npx @designtools/tokens scale --
|
|
337
|
-
npx @designtools/tokens scale --format all --out ./tokens # css, tailwind-v3, dtcg, json
|
|
391
|
+
npx @designtools/tokens scale --init --format tailwind-v4 --out app/styles/scale.css
|
|
392
|
+
npx @designtools/tokens scale --verify app/styles/scale.css
|
|
338
393
|
```
|
|
339
394
|
|
|
340
395
|
| Tier | Tokens | What it is |
|
|
@@ -348,15 +403,24 @@ npx @designtools/tokens scale --format all --out ./tokens # css, tailwind-v3,
|
|
|
348
403
|
| Screen sizes | `--breakpoint-sm` … `--breakpoint-2xl` | Where a page can change shape, from each size up |
|
|
349
404
|
| Widths | `--container-3xs` … `--container-7xl` | The widths content is set to |
|
|
350
405
|
|
|
351
|
-
The
|
|
406
|
+
The values are the project's; **the names are the contract.** Keep every name, and add new ones only inside a tier's namespace, never a system of their own beside it.
|
|
352
407
|
|
|
353
|
-
|
|
408
|
+
**The type tiers are scales, so a new name there is a step, never a use.** A name says where a step sits, and only the tier's own words do that:
|
|
354
409
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
410
|
+
| Tier | Steps a project can add |
|
|
411
|
+
| --- | --- |
|
|
412
|
+
| `--text-*` | `3xs`, `2xs`, `xs`, `sm`, `base`, `lg`, `xl`, `2xl` to `9xl`, each with its `--line-height`, `--letter-spacing` and `--font-weight` companions |
|
|
413
|
+
| `--leading-*` | `none`, `tightest`, `tighter`, `tight`, `snug`, `medium`, `normal`, `relaxed`, `loose`, `looser`, `loosest` |
|
|
414
|
+
| `--tracking-*` | `tightest`, `tighter`, `tight`, `normal`, `wide`, `wider`, `widest` |
|
|
415
|
+
| `--font-weight-*` | `thin`, `extralight`, `light`, `normal`, `medium`, `semibold`, `bold`, `extrabold`, `black` |
|
|
416
|
+
|
|
417
|
+
Tailwind's own words, and the ones between two of them (`--leading-medium` sits between snug and normal). `--text-display`, `--text-headline`, `--text-label` or `--leading-lead` name a use, and fail. A size that changes by screen is set in the component (`text-5xl lg:text-8xl`); a role a page uses (display, headline, label) is a step, mapped in the docs config's `type.hierarchy`.
|
|
418
|
+
|
|
419
|
+
The other tiers take a project's own names inside their namespace: a section step is `--spacing-section`, a page width `--container-measure`. `--verify`, and `designtools-manifest check` on every commit, hold a project to all of this and never compare values. The names are Tailwind v4's theme namespaces, so on Tailwind each is a utility as well, and on any other stack a plain custom property. Screen sizes are the one tier a variable can't carry, since CSS can't read one in `@media`: `--format css` writes them as `@custom-media` too (compiled by Lightning CSS or postcss-preset-env), and DTCG, JSON and Tailwind v3 carry them as values.
|
|
420
|
+
|
|
421
|
+
`--init` refuses to write over a scale that is already there; `--force` writes over it after listing what changes, for the rare deliberate reset. `--overrides` (JSON by token name: a value, or a value with its description) starts `--init` from other values than the defaults. `--format all` writes css, tailwind-v3, dtcg and json.
|
|
358
422
|
|
|
359
|
-
|
|
423
|
+
**Adopting the owned scale (from 0.13 and before).** A project that regenerates its scale from an overrides file moves once: run `scale --init --force` with its overrides, so the file keeps every value, then delete the overrides file and drop `scale --check` from CI. Regenerating without `--init`, and `--check`, still work, and warn.
|
|
360
424
|
|
|
361
425
|
## Trying scales live: the studio
|
|
362
426
|
|
|
@@ -477,7 +541,7 @@ So an agent's contract is *scope, merge, verify* — and a bad merge is caught r
|
|
|
477
541
|
|
|
478
542
|
### Aliases move together
|
|
479
543
|
|
|
480
|
-
With `--aliases`, `destructive`/`red`, `success`/`green` and `warning`/`yellow` are two names for one scale, so
|
|
544
|
+
With `--aliases`, `destructive`/`red`, `success`/`green` and `warning`/`yellow` are two names for one scale, so recolouring it (`--color destructive=…`) moves both. Without that, `bg-red-500` would stay on the old colour and the two names would silently disagree inside the same file. The second names can't be given to `--color` at all, with `--aliases` or without: `--color yellow=…` would recolour warning rather than add a yellow, so it is refused, and says so.
|
|
481
545
|
|
|
482
546
|
## Upgrading to 0.12
|
|
483
547
|
|
|
@@ -564,7 +628,7 @@ With `gamut: "p3"`, the wide-gamut tiers are on `tokens.p3`, and the checks take
|
|
|
564
628
|
|---|---|---|
|
|
565
629
|
| `--primary <colour>` | — | Your brand colour. Required unless `--seed` supplies it. |
|
|
566
630
|
| `--neutral <colour>` | `#747474` | Neutral seed. Drives greys, surfaces, borders. |
|
|
567
|
-
| `--color <name>=<colour>[@<shade>]` | — | An extra named colour: a ramp and semantic tokens. Repeatable. `@<shade>` anchors its seed on that step. See [Adding colours](#adding-colours). |
|
|
631
|
+
| `--color <name>=<colour>[@<shade>]` | — | An extra named colour: a ramp and semantic tokens. Repeatable. `@<shade>` anchors its seed on that step. See [Adding colours](#adding-colours). Naming a status colour (`--color destructive=…`) recolours it. Some names are reserved, with or without `--aliases`, and refused where they are given: `green`, `red` and `yellow` (the status colours' second names; recolour warning with `--color warning=…`), `white` and `black` (fixed colours), and the page tokens `canvas`, `surface`, `overlay`, `foreground`, `border`, `input`, `ring` and `shadow`. |
|
|
568
632
|
| `--decorative <name>` | — | Give an added colour its ramp only, with no semantic slots (`--<name>`, `-foreground`, `bg-<name>`), so an accent that must never be text or an action cannot be used as one. Repeatable. In a seed file, `"decorative": true` on the colour. |
|
|
569
633
|
| `--seed <file.json>` | — | Replay a saved configuration. Flags given alongside it win, so a seed is defaults rather than a lock. |
|
|
570
634
|
| `--stdin` | off | Read that same JSON from standard input. |
|
|
@@ -862,7 +862,7 @@ function generateSurfaceTokens(palette, mode, overrides, shades, colors, pageSur
|
|
|
862
862
|
const black = palette.black;
|
|
863
863
|
const white = palette.white;
|
|
864
864
|
const defaults = mode === "light" ? { canvas: snap(25), "canvas-foreground": snap(800), surface: "white", "surface-foreground": snap(800), overlay: "white", "overlay-foreground": snap(800) } : { canvas: snap(950), "canvas-foreground": "white", surface: "black", "surface-foreground": "white", overlay: "black", "overlay-foreground": "white" };
|
|
865
|
-
function
|
|
865
|
+
function resolve3(key) {
|
|
866
866
|
const raw = overrides?.[key] ?? defaults[key];
|
|
867
867
|
if (raw === "white") return { value: white, ref: { type: "white" } };
|
|
868
868
|
if (raw === "black") return { value: black, ref: { type: "black" } };
|
|
@@ -871,9 +871,9 @@ function generateSurfaceTokens(palette, mode, overrides, shades, colors, pageSur
|
|
|
871
871
|
}
|
|
872
872
|
const ground = (key) => {
|
|
873
873
|
const given = colors?.[key];
|
|
874
|
-
if (!given) return { bg:
|
|
874
|
+
if (!given) return { bg: resolve3(key), fg: resolve3(`${key}-foreground`) };
|
|
875
875
|
const bg = { value: given, ref: { type: "value", value: given } };
|
|
876
|
-
return { bg, fg: overrides?.[`${key}-foreground`] ?
|
|
876
|
+
return { bg, fg: overrides?.[`${key}-foreground`] ? resolve3(`${key}-foreground`) : textOn(given, neutral, white, black, activeShades) };
|
|
877
877
|
};
|
|
878
878
|
const { bg: canvas, fg: canvasFg } = ground("canvas");
|
|
879
879
|
const { bg: surface, fg: surfaceFg } = ground("surface");
|
|
@@ -1083,6 +1083,7 @@ var GROUND_BASE_TOKENS = [
|
|
|
1083
1083
|
var GROUND_COLOR_PARTS = ["", "-foreground", "-subdued", "-subdued-foreground", "-hover", "-active"];
|
|
1084
1084
|
var FILL_FLOOR = 3;
|
|
1085
1085
|
var PANEL_FLOOR = 1.1;
|
|
1086
|
+
var BORDER_FLOOR = 1.5;
|
|
1086
1087
|
var TEXT_FLOOR = { "aa-large": 3, aa: 4.5, aaa: 7 };
|
|
1087
1088
|
var BODY_AIM = 7;
|
|
1088
1089
|
function groundTokenNames(colors) {
|
|
@@ -1092,20 +1093,15 @@ function semanticColors(semantic) {
|
|
|
1092
1093
|
const core = ["primary", "neutral", "success", "destructive", "warning"];
|
|
1093
1094
|
return [...core, ...Object.keys(semantic).filter((n) => !core.includes(n))];
|
|
1094
1095
|
}
|
|
1096
|
+
var PAGE_NAMES = ["canvas", "surface", "overlay", "foreground", "border", "input", "ring", "shadow", "white", "black"];
|
|
1095
1097
|
function reservedSurfaceNames(colors) {
|
|
1096
|
-
return [
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
"ring",
|
|
1104
|
-
"shadow",
|
|
1105
|
-
"white",
|
|
1106
|
-
"black",
|
|
1107
|
-
...colors.flatMap((c) => [c, `${c}-subdued`])
|
|
1108
|
-
];
|
|
1098
|
+
return [...PAGE_NAMES, ...colors.flatMap((c) => [c, `${c}-subdued`])];
|
|
1099
|
+
}
|
|
1100
|
+
var RESERVED_COLOR_NAMES = [...ALIAS_PAIRS.map(([, alias]) => alias), ...PAGE_NAMES];
|
|
1101
|
+
function reservedColorReason(name) {
|
|
1102
|
+
const pair = ALIAS_PAIRS.find(([, alias]) => alias === name);
|
|
1103
|
+
const why = pair ? `"${name}" is ${pair[0]}'s second name (written by --aliases), so it never becomes a ramp of its own: recolour ${pair[0]} with --color ${pair[0]}=\u2026, or give this colour another name` : name === "white" || name === "black" ? `"${name}" is the fixed --color-${name}: give this colour another name` : PAGE_NAMES.includes(name) ? `"${name}" is the page token --${name}, which a colour of that name would collide with: give this colour another name` : void 0;
|
|
1104
|
+
return why && `${why}. Reserved: ${RESERVED_COLOR_NAMES.join(", ")}`;
|
|
1109
1105
|
}
|
|
1110
1106
|
var valueOf = (ref, palette) => {
|
|
1111
1107
|
switch (ref.type) {
|
|
@@ -1445,6 +1441,15 @@ function buildGround(name, given, tiers, views, options) {
|
|
|
1445
1441
|
refs.surface = fillRef(panels, srgb);
|
|
1446
1442
|
if (cr(refs.surface, ground) < PANEL_FLOOR) notes.push(`surface: ${cr(refs.surface, ground).toFixed(2)}:1 against the ground, so the card doesn't draw`);
|
|
1447
1443
|
}
|
|
1444
|
+
if (cr(refs.border, refs.surface) < BORDER_FLOOR) {
|
|
1445
|
+
const from = refs.border;
|
|
1446
|
+
if (tint === "own" && from.type === "shade") {
|
|
1447
|
+
const strength = (r) => Math.max(cr(r, refs.surface), cr(r, ground));
|
|
1448
|
+
refs.border = active.filter((s) => srgb[from.colorName]?.[s] !== void 0).map((s) => shade(from.colorName, s)).filter((r) => cr(r, refs.surface) >= BORDER_FLOOR && cr(r, ground) >= cr(from, ground)).sort((a, b) => strength(a) - strength(b))[0] ?? bestEnd(refs.surface);
|
|
1449
|
+
} else {
|
|
1450
|
+
notes.push(`border: ${cr(refs.border, refs.surface).toFixed(2)}:1 against the card, under ${BORDER_FLOOR}:1`);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1448
1453
|
refs.canvas = ground;
|
|
1449
1454
|
refs["canvas-foreground"] = body;
|
|
1450
1455
|
refs["surface-foreground"] = cr(body, refs.surface) >= textFloor ? body : bestEnd(refs.surface);
|
|
@@ -2519,6 +2524,224 @@ function diffSlice(target, slice) {
|
|
|
2519
2524
|
return { matches: differing.length === 0 && missing.length === 0, differing, missing };
|
|
2520
2525
|
}
|
|
2521
2526
|
|
|
2527
|
+
// src/local.ts
|
|
2528
|
+
function blocks(css) {
|
|
2529
|
+
const out = [];
|
|
2530
|
+
const text = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
2531
|
+
let i = 0;
|
|
2532
|
+
let prelude = "";
|
|
2533
|
+
const stack = [];
|
|
2534
|
+
let body = "";
|
|
2535
|
+
while (i < text.length) {
|
|
2536
|
+
const ch = text[i];
|
|
2537
|
+
if (ch === "{") {
|
|
2538
|
+
stack.push(prelude.trim());
|
|
2539
|
+
prelude = "";
|
|
2540
|
+
body = "";
|
|
2541
|
+
} else if (ch === "}") {
|
|
2542
|
+
const selector = stack.pop() ?? "";
|
|
2543
|
+
if (body.trim()) {
|
|
2544
|
+
const at = stack.filter((s) => s.startsWith("@")).join(" ");
|
|
2545
|
+
out.push({ selector: at ? `${at} ${selector}` : selector, decls: decls(body) });
|
|
2546
|
+
}
|
|
2547
|
+
body = "";
|
|
2548
|
+
prelude = "";
|
|
2549
|
+
} else if (stack.length) {
|
|
2550
|
+
body += ch;
|
|
2551
|
+
if (ch === ";") prelude = "";
|
|
2552
|
+
else prelude += ch;
|
|
2553
|
+
} else {
|
|
2554
|
+
prelude += ch;
|
|
2555
|
+
}
|
|
2556
|
+
i++;
|
|
2557
|
+
}
|
|
2558
|
+
return out;
|
|
2559
|
+
}
|
|
2560
|
+
function decls(body) {
|
|
2561
|
+
return [...body.matchAll(/(--[\w-]+)\s*:\s*([^;]+);?/g)].map((m) => [m[1], m[2].trim()]);
|
|
2562
|
+
}
|
|
2563
|
+
var SYSTEM_DARK = /^@media\s*\(\s*prefers-color-scheme\s*:\s*dark\s*\)\s+(.+)$/;
|
|
2564
|
+
var isSystemDark = (selector) => SYSTEM_DARK.exec(selector)?.[1].trim() === MODE_SELECTORS.systemDark;
|
|
2565
|
+
var isToggledDark = (selector) => selector.split(",").some((part) => ['[data-theme="dark"]', ".dark"].includes(part.trim()));
|
|
2566
|
+
var SYSTEM_DARK_BLOCK = (decls2) => `@media (prefers-color-scheme: dark) { ${MODE_SELECTORS.systemDark} { ${decls2} } }`;
|
|
2567
|
+
function scopesOf(selector) {
|
|
2568
|
+
if (isSystemDark(selector)) return ["dark"];
|
|
2569
|
+
const scopes = [];
|
|
2570
|
+
for (const part of selector.split(",").map((s) => s.trim())) {
|
|
2571
|
+
if (part === ":root" || part === '[data-theme="light"]' || part === '[data-surface="canvas"]') scopes.push("light");
|
|
2572
|
+
else if (part === '[data-theme="dark"]' || part === ".dark") scopes.push("dark");
|
|
2573
|
+
else {
|
|
2574
|
+
const m = /^\[data-surface="([\w-]+)"\]$/.exec(part);
|
|
2575
|
+
if (!m) return void 0;
|
|
2576
|
+
scopes.push(m[1]);
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
return scopes;
|
|
2580
|
+
}
|
|
2581
|
+
var LITERAL = [/#[0-9a-f]{3,8}\b/i, /\b(?:rgba?|hsla?|hwb|lab|lch|oklab|color)\(/i, /\boklch\((?!\s*from\b)/i];
|
|
2582
|
+
function scopesFrom(generated) {
|
|
2583
|
+
const all = blocks(generated).filter((b) => !b.selector.startsWith("@media"));
|
|
2584
|
+
const ramps = /* @__PURE__ */ new Map();
|
|
2585
|
+
const names = /* @__PURE__ */ new Set();
|
|
2586
|
+
for (const b of all) for (const [n, v] of b.decls) {
|
|
2587
|
+
names.add(n);
|
|
2588
|
+
if (/^--color-/.test(n) && !v.startsWith("var(")) ramps.set(n, v);
|
|
2589
|
+
}
|
|
2590
|
+
const light = all.find((b) => b.selector.includes('[data-theme="light"]'));
|
|
2591
|
+
const dark = all.find((b) => b.selector.startsWith('[data-theme="dark"]'));
|
|
2592
|
+
const groundBlocks = /* @__PURE__ */ new Map();
|
|
2593
|
+
for (const b of all) {
|
|
2594
|
+
const m = /^\[data-surface="([\w-]+)"\]$/.exec(b.selector);
|
|
2595
|
+
if (m) groundBlocks.set(m[1], b);
|
|
2596
|
+
}
|
|
2597
|
+
const grounds = /* @__PURE__ */ new Set([...groundBlocks.keys(), "canvas"]);
|
|
2598
|
+
const scope = (name) => {
|
|
2599
|
+
const map = new Map(ramps);
|
|
2600
|
+
const isDark = name === "dark" || name !== "light" && Boolean(dark?.selector.includes(`[data-surface="${name}"]`));
|
|
2601
|
+
for (const [n, v] of (isDark ? dark : light)?.decls ?? []) map.set(n, v);
|
|
2602
|
+
for (const [n, v] of groundBlocks.get(name)?.decls ?? []) map.set(n, v);
|
|
2603
|
+
return map;
|
|
2604
|
+
};
|
|
2605
|
+
return { ramps, scope, grounds, names };
|
|
2606
|
+
}
|
|
2607
|
+
function resolve(value, scope, depth = 0) {
|
|
2608
|
+
if (depth > 20) return void 0;
|
|
2609
|
+
const v = value.trim();
|
|
2610
|
+
const ref = /^var\(\s*(--[\w-]+)\s*(?:,\s*(.+))?\)$/.exec(v);
|
|
2611
|
+
if (ref) {
|
|
2612
|
+
const next = scope.get(ref[1]) ?? ref[2];
|
|
2613
|
+
return next === void 0 ? void 0 : resolve(next, scope, depth + 1);
|
|
2614
|
+
}
|
|
2615
|
+
const rel = /^oklch\(\s*from\s+(var\([^)]*\)|\S+)\s+(.+)\)$/.exec(v);
|
|
2616
|
+
if (rel) {
|
|
2617
|
+
const base = resolve(rel[1], scope, depth + 1);
|
|
2618
|
+
if (!base) return void 0;
|
|
2619
|
+
const from = parseToOklch(base);
|
|
2620
|
+
const parts = rel[2].match(/calc\([^)]*\)|\S+/g) ?? [];
|
|
2621
|
+
if (parts.length < 3) return void 0;
|
|
2622
|
+
const channel = (expr, own2) => {
|
|
2623
|
+
const body = expr.replace(/^calc\(|\)$/g, "").replace(/\b([lch])\b/g, (_, k) => String(own2[k]));
|
|
2624
|
+
if (!/^[\d\s.+\-*/()]+$/.test(body)) return Number.NaN;
|
|
2625
|
+
return Function(`"use strict"; return (${body});`)();
|
|
2626
|
+
};
|
|
2627
|
+
const own = { l: from.l, c: from.c, h: from.h ?? 0 };
|
|
2628
|
+
const [l, c, h] = parts.slice(0, 3).map((p) => channel(p, own));
|
|
2629
|
+
if ([l, c, h].some(Number.isNaN)) return void 0;
|
|
2630
|
+
return oklchToHex({ mode: "oklch", l, c, h });
|
|
2631
|
+
}
|
|
2632
|
+
if (v.startsWith("color-mix(")) return void 0;
|
|
2633
|
+
return v;
|
|
2634
|
+
}
|
|
2635
|
+
var TARGETS = { "aa-large": 3, aa: 4.5, aaa: 7 };
|
|
2636
|
+
function checkLocalOverrides(generated, local, target = "aa") {
|
|
2637
|
+
const problems = [];
|
|
2638
|
+
const overrides = [];
|
|
2639
|
+
const { scope, grounds, names } = scopesFrom(generated);
|
|
2640
|
+
const floor = TARGETS[target];
|
|
2641
|
+
if ((local.match(/{/g) ?? []).length !== (local.match(/}/g) ?? []).length) {
|
|
2642
|
+
return { overrides, problems: [{ kind: "syntax", message: "the braces don't balance" }] };
|
|
2643
|
+
}
|
|
2644
|
+
const touched = /* @__PURE__ */ new Map();
|
|
2645
|
+
for (const b of blocks(local)) {
|
|
2646
|
+
if (b.selector.startsWith("@") && !isSystemDark(b.selector)) {
|
|
2647
|
+
problems.push({
|
|
2648
|
+
kind: "selector",
|
|
2649
|
+
message: `${b.selector}: no at-rules but the system-dark block (${SYSTEM_DARK_BLOCK("\u2026")}); set a mode with [data-theme="dark"]`
|
|
2650
|
+
});
|
|
2651
|
+
continue;
|
|
2652
|
+
}
|
|
2653
|
+
const reached = scopesOf(b.selector);
|
|
2654
|
+
if (!reached) {
|
|
2655
|
+
problems.push({ kind: "selector", message: `${b.selector}: only the generator's own selectors (:root, [data-theme], .dark, [data-surface="\u2026"])` });
|
|
2656
|
+
continue;
|
|
2657
|
+
}
|
|
2658
|
+
for (const s of reached) {
|
|
2659
|
+
if (s !== "light" && s !== "dark" && !grounds.has(s)) {
|
|
2660
|
+
problems.push({ kind: "selector", message: `[data-surface="${s}"]: not a ground the generator makes` });
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
for (const [name, value] of b.decls) {
|
|
2664
|
+
overrides.push({ selector: b.selector, name, value });
|
|
2665
|
+
if (name.startsWith("--color-")) {
|
|
2666
|
+
problems.push({
|
|
2667
|
+
kind: "name",
|
|
2668
|
+
message: `${name} in ${b.selector}: set the token, not its --color- alias or a ramp step (move a step with shade overrides)`
|
|
2669
|
+
});
|
|
2670
|
+
} else if (!names.has(name)) {
|
|
2671
|
+
problems.push({ kind: "name", message: `${name} in ${b.selector}: not a token the generator writes; a new name belongs in the project's own stylesheet` });
|
|
2672
|
+
}
|
|
2673
|
+
if (LITERAL.some((re) => re.test(value))) {
|
|
2674
|
+
problems.push({ kind: "value", message: `${name} in ${b.selector}: a literal colour; point at a ramp step (var(--color-\u2026)) or nudge one with oklch(from \u2026)` });
|
|
2675
|
+
}
|
|
2676
|
+
for (const s of reached) {
|
|
2677
|
+
if (!touched.has(s)) touched.set(s, /* @__PURE__ */ new Set());
|
|
2678
|
+
touched.get(s)?.add(name);
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
const darkOf = (match) => {
|
|
2683
|
+
const out = /* @__PURE__ */ new Map();
|
|
2684
|
+
for (const b of blocks(local)) if (match(b.selector)) for (const [n, v] of b.decls) out.set(n, v);
|
|
2685
|
+
return out;
|
|
2686
|
+
};
|
|
2687
|
+
const toggled = darkOf(isToggledDark);
|
|
2688
|
+
const system = darkOf(isSystemDark);
|
|
2689
|
+
const missing = [...toggled].filter(([n, v]) => system.get(n) !== v);
|
|
2690
|
+
if (missing.length) {
|
|
2691
|
+
problems.push({
|
|
2692
|
+
kind: "dark",
|
|
2693
|
+
message: `${missing.map(([n]) => n).join(", ")} in [data-theme="dark"] or .dark: a visitor whose system is dark keeps the generated value, since the system-dark block outranks the toggle. Set the same under system dark: ${SYSTEM_DARK_BLOCK(missing.map(([n, v]) => `${n}: ${v};`).join(" "))}`
|
|
2694
|
+
});
|
|
2695
|
+
}
|
|
2696
|
+
const unpaired = [...system].filter(([n, v]) => toggled.get(n) !== v);
|
|
2697
|
+
if (unpaired.length) {
|
|
2698
|
+
problems.push({
|
|
2699
|
+
kind: "dark",
|
|
2700
|
+
message: `${unpaired.map(([n]) => n).join(", ")} under system dark: a visitor who turns dark on with the toggle on a light system keeps the generated value. Set the same in [data-theme="dark"], .dark { ${unpaired.map(([n, v]) => `${n}: ${v};`).join(" ")} }`
|
|
2701
|
+
});
|
|
2702
|
+
}
|
|
2703
|
+
const localBlocks = blocks(local).filter((b) => !b.selector.startsWith("@") || isSystemDark(b.selector));
|
|
2704
|
+
for (const [s, touchedNames] of touched) {
|
|
2705
|
+
const map = scope(s);
|
|
2706
|
+
for (const b of localBlocks) {
|
|
2707
|
+
if (scopesOf(b.selector)?.includes(s)) for (const [n, v] of b.decls) map.set(n, v);
|
|
2708
|
+
}
|
|
2709
|
+
const bases = /* @__PURE__ */ new Set();
|
|
2710
|
+
for (const name of touchedNames) {
|
|
2711
|
+
if (name.startsWith("--color-")) continue;
|
|
2712
|
+
const base = name.replace(/-foreground(-secondary)?$/, "");
|
|
2713
|
+
if (map.has(`${base}-foreground`)) bases.add(base);
|
|
2714
|
+
}
|
|
2715
|
+
for (const base of bases) {
|
|
2716
|
+
const ground = resolve(`var(${base})`, map);
|
|
2717
|
+
for (const text of [`${base}-foreground`, `${base}-foreground-secondary`]) {
|
|
2718
|
+
if (!map.has(text)) continue;
|
|
2719
|
+
const ink = resolve(`var(${text})`, map);
|
|
2720
|
+
if (!ground || !ink) continue;
|
|
2721
|
+
const ratio = getContrastRatio(ink, ground);
|
|
2722
|
+
if (ratio < floor) {
|
|
2723
|
+
problems.push({
|
|
2724
|
+
kind: "contrast",
|
|
2725
|
+
message: `${text} on ${base} in ${s === "light" || s === "dark" ? `the ${s} page` : `[data-surface="${s}"]`}: ${ratio.toFixed(2)}:1, under ${floor}:1`
|
|
2726
|
+
});
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
return { overrides, problems };
|
|
2732
|
+
}
|
|
2733
|
+
var LOCAL_TEMPLATE = `/* tokens.local.css: the project's overrides of the generated colour, loaded after tokens.css.
|
|
2734
|
+
Most changes are an input instead (a flag, the seed, shade overrides): use this only for a value
|
|
2735
|
+
the generator can't say. generate-tokens --local checks it against the system:
|
|
2736
|
+
- selectors: :root, [data-theme="light"], [data-theme="dark"], .dark, [data-surface="<ground>"];
|
|
2737
|
+
- a dark override is set twice, to the same value, so it reaches every dark reader: in
|
|
2738
|
+
[data-theme="dark"], .dark { \u2026 } and in the system-dark block, which outranks the toggle:
|
|
2739
|
+
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]):not(.light) { \u2026 } }
|
|
2740
|
+
- names: tokens the generator writes (never a --color- alias or ramp step, never a new name);
|
|
2741
|
+
- values: var() references, or a ramp step nudged with oklch(from var(--color-\u2026) \u2026); never a literal colour.
|
|
2742
|
+
Each override is reported as pinned by hand, and the pairs it touches are re-checked for contrast. */
|
|
2743
|
+
`;
|
|
2744
|
+
|
|
2522
2745
|
// src/scale.ts
|
|
2523
2746
|
var t = (name, value, description) => ({ name, value, description });
|
|
2524
2747
|
var textStep = (step, size, px, leading, tracking, use) => [
|
|
@@ -2737,19 +2960,19 @@ function toTailwindV4(tiers) {
|
|
|
2737
2960
|
const plain = tiers.filter((x) => !x.themed && x.tokens.length);
|
|
2738
2961
|
return ["@theme static {", ...block(themed, " "), "}", ...plain.length ? ["", "/* Tailwind has no namespace for these: use them as h-(--size-xl), duration-(--duration-base) */", "@layer base {", " :root {", ...block(plain, " "), " }", "}"] : []].join("\n");
|
|
2739
2962
|
}
|
|
2740
|
-
function
|
|
2741
|
-
return depth > 5 ? value : value.replace(/var\((--[\w-]+)\)/g, (m, name) => all.has(name) && !/--shadow$/.test(name) ?
|
|
2963
|
+
function resolve2(value, all, depth = 0) {
|
|
2964
|
+
return depth > 5 ? value : value.replace(/var\((--[\w-]+)\)/g, (m, name) => all.has(name) && !/--shadow$/.test(name) ? resolve2(all.get(name), all, depth + 1) : m);
|
|
2742
2965
|
}
|
|
2743
2966
|
function toTailwindV3(tiers) {
|
|
2744
2967
|
const all = new Map(tiers.flatMap((x) => x.tokens.map((tok) => [tok.name, tok.value])));
|
|
2745
|
-
const of = (id, prefix) => Object.fromEntries((tiers.find((x) => x.id === id)?.tokens ?? []).filter((tok) => !tok.name.includes("--", 2)).map((tok) => [tok.name.slice(prefix.length),
|
|
2968
|
+
const of = (id, prefix) => Object.fromEntries((tiers.find((x) => x.id === id)?.tokens ?? []).filter((tok) => !tok.name.includes("--", 2)).map((tok) => [tok.name.slice(prefix.length), resolve2(tok.value, all)]));
|
|
2746
2969
|
const base = Number.parseFloat(all.get("--spacing") ?? "0.25");
|
|
2747
2970
|
const steps = [0.5, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32];
|
|
2748
2971
|
const text = Object.fromEntries(
|
|
2749
2972
|
(tiers.find((x) => x.id === "text")?.tokens ?? []).filter((tok) => !tok.name.includes("--", 2)).map((tok) => {
|
|
2750
2973
|
const lh = all.get(`${tok.name}--line-height`);
|
|
2751
2974
|
const ls = all.get(`${tok.name}--letter-spacing`);
|
|
2752
|
-
const extra = { ...lh ? { lineHeight:
|
|
2975
|
+
const extra = { ...lh ? { lineHeight: resolve2(lh, all) } : {}, ...ls ? { letterSpacing: resolve2(ls, all) } : {} };
|
|
2753
2976
|
return [tok.name.slice("--text-".length), Object.keys(extra).length ? [tok.value, extra] : tok.value];
|
|
2754
2977
|
})
|
|
2755
2978
|
);
|
|
@@ -2831,6 +3054,79 @@ function exportScale(tiers, format, header) {
|
|
|
2831
3054
|
${body}
|
|
2832
3055
|
`;
|
|
2833
3056
|
}
|
|
3057
|
+
var OWNED_SCALE_MARK = "@designtools/tokens scale";
|
|
3058
|
+
function ownedScaleHeader(version) {
|
|
3059
|
+
return [
|
|
3060
|
+
`/* ${OWNED_SCALE_MARK} v${version}: scaffolded once, now this project's own.`,
|
|
3061
|
+
" Retune any value here by hand: nothing regenerates this file. The names are the contract:",
|
|
3062
|
+
" keep every one. Type sizes, line heights, tracking and weights are scales, so a new name",
|
|
3063
|
+
" there is a step (--text-5xl, --leading-loose), never a use (--text-display): a role is a",
|
|
3064
|
+
" step mapped in the docs config, and a size that changes by screen is set in the component.",
|
|
3065
|
+
" Space, sizes, widths, corners, shadows and motion take a project's own names inside their",
|
|
3066
|
+
" namespace (--spacing-section). designtools-manifest check verifies both. */"
|
|
3067
|
+
].join("\n");
|
|
3068
|
+
}
|
|
3069
|
+
function isOwnedScale(css) {
|
|
3070
|
+
return css.includes(OWNED_SCALE_MARK);
|
|
3071
|
+
}
|
|
3072
|
+
var TIER_PREFIX = {
|
|
3073
|
+
spacing: "--spacing",
|
|
3074
|
+
size: "--size-",
|
|
3075
|
+
text: "--text-",
|
|
3076
|
+
leading: "--leading-",
|
|
3077
|
+
tracking: "--tracking-",
|
|
3078
|
+
"font-weight": "--font-weight-",
|
|
3079
|
+
radius: "--radius-",
|
|
3080
|
+
shadow: "--shadow-",
|
|
3081
|
+
duration: "--duration-",
|
|
3082
|
+
ease: "--ease-",
|
|
3083
|
+
breakpoint: "--breakpoint-",
|
|
3084
|
+
container: "--container-"
|
|
3085
|
+
};
|
|
3086
|
+
var TYPE_STEPS = {
|
|
3087
|
+
text: ["3xs", "2xs", "xs", "sm", "base", "lg", "xl", "2xl", "3xl", "4xl", "5xl", "6xl", "7xl", "8xl", "9xl"],
|
|
3088
|
+
leading: ["none", "tightest", "tighter", "tight", "snug", "medium", "normal", "relaxed", "loose", "looser", "loosest"],
|
|
3089
|
+
tracking: ["tightest", "tighter", "tight", "normal", "wide", "wider", "widest"],
|
|
3090
|
+
"font-weight": ["thin", "extralight", "light", "normal", "medium", "semibold", "bold", "extrabold", "black"]
|
|
3091
|
+
};
|
|
3092
|
+
var TEXT_COMPANIONS = ["line-height", "letter-spacing", "font-weight"];
|
|
3093
|
+
var TYPE_TITLE = {
|
|
3094
|
+
text: "type sizes",
|
|
3095
|
+
leading: "line heights",
|
|
3096
|
+
tracking: "tracking",
|
|
3097
|
+
"font-weight": "weights"
|
|
3098
|
+
};
|
|
3099
|
+
function typeStep(name) {
|
|
3100
|
+
for (const tier of Object.keys(TYPE_STEPS)) {
|
|
3101
|
+
const prefix = TIER_PREFIX[tier];
|
|
3102
|
+
if (!name.startsWith(prefix)) continue;
|
|
3103
|
+
const [step, companion, ...rest] = name.slice(prefix.length).split("--");
|
|
3104
|
+
const steps = TYPE_STEPS[tier];
|
|
3105
|
+
const ok = steps.includes(step) && !rest.length && (companion === void 0 || tier === "text" && TEXT_COMPANIONS.includes(companion));
|
|
3106
|
+
return { tier, step: ok };
|
|
3107
|
+
}
|
|
3108
|
+
return void 0;
|
|
3109
|
+
}
|
|
3110
|
+
function offScaleReason(name) {
|
|
3111
|
+
const tier = typeStep(name)?.tier ?? "text";
|
|
3112
|
+
return `is not a step of the ${TYPE_TITLE[tier]} (${TYPE_STEPS[tier].join(", ")})`;
|
|
3113
|
+
}
|
|
3114
|
+
var OFF_SCALE_ADVICE = "a type step names a place on the scale, never a use. A size that changes by screen is set in the component (text-5xl lg:text-8xl); a role a page uses (display, headline, label) is a step, mapped in the docs config's type.hierarchy.";
|
|
3115
|
+
function verifyScale(css) {
|
|
3116
|
+
const declared = new Set([...css.matchAll(/(?:^|[;{\s])(--[\w-]+)\s*:/g)].map((m) => m[1]));
|
|
3117
|
+
const tiers = defaultScale();
|
|
3118
|
+
const names = new Set(tiers.flatMap((tier) => tier.tokens.map((tok) => tok.name)));
|
|
3119
|
+
const inTier = (name) => Object.values(TIER_PREFIX).some((prefix) => name === prefix || name.startsWith(prefix.endsWith("-") ? prefix : `${prefix}-`));
|
|
3120
|
+
const missing = [...names].filter((name) => !declared.has(name));
|
|
3121
|
+
const added = [...declared].filter((name) => !names.has(name));
|
|
3122
|
+
const offScale = added.filter((name) => typeStep(name)?.step === false);
|
|
3123
|
+
return {
|
|
3124
|
+
missing,
|
|
3125
|
+
strays: added.filter((name) => !inTier(name)),
|
|
3126
|
+
offScale,
|
|
3127
|
+
own: added.filter((name) => inTier(name) && !offScale.includes(name))
|
|
3128
|
+
};
|
|
3129
|
+
}
|
|
2834
3130
|
|
|
2835
3131
|
// src/contract.ts
|
|
2836
3132
|
var ALIASES = new Set(ALIAS_PAIRS.map(([, alias]) => alias));
|
|
@@ -2965,6 +3261,8 @@ export {
|
|
|
2965
3261
|
GROUND_COLOR_PARTS,
|
|
2966
3262
|
groundTokenNames,
|
|
2967
3263
|
reservedSurfaceNames,
|
|
3264
|
+
RESERVED_COLOR_NAMES,
|
|
3265
|
+
reservedColorReason,
|
|
2968
3266
|
suggestStep,
|
|
2969
3267
|
generateGroundTokens,
|
|
2970
3268
|
generateTokens,
|
|
@@ -2987,9 +3285,18 @@ export {
|
|
|
2987
3285
|
readDeclarations,
|
|
2988
3286
|
mergeSlice,
|
|
2989
3287
|
diffSlice,
|
|
3288
|
+
checkLocalOverrides,
|
|
3289
|
+
LOCAL_TEMPLATE,
|
|
2990
3290
|
defaultScale,
|
|
2991
3291
|
applyScaleOverrides,
|
|
2992
3292
|
exportScale,
|
|
3293
|
+
OWNED_SCALE_MARK,
|
|
3294
|
+
ownedScaleHeader,
|
|
3295
|
+
isOwnedScale,
|
|
3296
|
+
TYPE_STEPS,
|
|
3297
|
+
offScaleReason,
|
|
3298
|
+
OFF_SCALE_ADVICE,
|
|
3299
|
+
verifyScale,
|
|
2993
3300
|
stepContract,
|
|
2994
3301
|
GENERATOR_NAME,
|
|
2995
3302
|
stableStringify,
|