@crewlethq/tokens 0.135.0 → 0.136.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/README.md +39 -1
- package/dist/css/tokens.css +44 -0
- package/package.json +1 -1
- package/test/palette.d.mts +25 -0
- package/test/palette.mjs +154 -0
- package/test/palette.test.mjs +113 -0
package/README.md
CHANGED
|
@@ -83,6 +83,15 @@ nearestContrastShade('#00baba', '#f6f7fb', WCAG_CONTRAST.aaLarge); // '#00a0a0',
|
|
|
83
83
|
|
|
84
84
|
Show the ratio of the value it returns, measured with `contrast`, rather than the floor it was asked for.
|
|
85
85
|
|
|
86
|
+
## Added: the code host's colours
|
|
87
|
+
|
|
88
|
+
Colours for code read in a code host: a diff's rows, gutters, words, signs and diffstat, syntax, a change's state, a branch, a search match and a file's status. Each is an alias of a step every palette already paints, declared once in `css` and resolved wherever a palette is painted, a brand scope's layer included.
|
|
89
|
+
|
|
90
|
+
| What changed | What to change | Details |
|
|
91
|
+
| --- | --- | --- |
|
|
92
|
+
| `--color-diff-*`, `--color-syntax-*`, `--color-change-{open,merged,closed,draft}-*`, `--color-code-ref-fill`, `--color-code-ref-ink`, `--color-code-match` and `--color-file-*-ink` are new, in `css` only. | Nothing. | [Code read in a code host](#code-read-in-a-code-host) |
|
|
93
|
+
| In `@crewlethq/tokens/test/palette`, the rules `a syntax ink clears its floor on code and on a changed line`, `a code ink clears 3:1 as a glyph on the hunk row's gutter`, `a changed line's sign clears its floor on its line and its gutter`, `the code text clears its floor on a changed word and on a match`, `an open pill's label clears 4.5:1 on its fill`, `a branch chip's ink clears its floor on its chip and on a selected row`, `a diff tint is seen on what it is drawn over`, `a gutter reads on its line`, `the hunk row reads apart from a changed line`, `added and removed lines read apart`, `syntax inks stay apart` and `a code host alias names a step held for its use` are new, with the exports `CODE_GROUNDS`, `CODE_PICK`, `SYNTAX_INKS`, `CODE_TEXT`, `DIFF_ROWS`, `DIFF_HUNK`, `DIFF_SEEN_DE`, `DIFF_GUTTER_DE`, `DIFF_APART_DE`, `SYNTAX_APART_DE`, `CHANGE_STATES`, `CHANGE_DRAFT_CHIP`, `FILE_STATUSES`, `CODE_REF` and `CODE_MATCH`. Every theme already clears them. | Nothing, unless an application's own palette override moves a step the family aliases under one of them. | [The palette suite](#the-palette-suite) |
|
|
94
|
+
|
|
86
95
|
## Added: the layered map's drawing
|
|
87
96
|
|
|
88
97
|
The layered map (`GraphCanvas` in `@crewlethq/ui`) draws a fine grid, see-through panes and hairlines. Each is a step of the palette at a fixed share, derived per palette and per mode by the build, so a theme repaints the map without declaring it. They are tokens rather than mixes in the component because a mix is a colour nobody measured.
|
|
@@ -641,6 +650,35 @@ Each kind of artifact is drawn in a hue of its own wherever its kind is pictured
|
|
|
641
650
|
|
|
642
651
|
The first six are aliases of the six node hues, so every theme repaints them with no value of its own. `brand`, a company's brand kit, came after every node hue was taken, so every theme declares it beside its node hues (ink `#dabcdb` in dark and `#74246a` in light), and the build derives its fill and line from it at the node alphas. The palette suite holds every kind's hue at 3:1 as a mark on every rung, its ink at 4.5:1 on its own fill and on every rung, and every pair of kind hues dE 8 apart under normal vision, in every palette of every theme.
|
|
643
652
|
|
|
653
|
+
### Code read in a code host
|
|
654
|
+
|
|
655
|
+
The diff and syntax tokens colour code where an application shows it, and the change, ref and file tokens mark a code host's change, branch or file wherever one is listed. Inside them a hue is a kind, never a state or an action: green is an added line, an open change or a string, never done, and the accent is a keyword, a merged change, a branch or the hunk row, never what to act on. Each is drawn beside its sign, word, letter or glyph, never alone.
|
|
656
|
+
|
|
657
|
+
Code views read them, and so do the kit's `DiffView` and `DiffSummary`. Each is an alias declared once in `css`, not in the typed export, so a theme repaints the family without declaring it.
|
|
658
|
+
|
|
659
|
+
| Tokens | Alias of | Drawn as |
|
|
660
|
+
| --- | --- | --- |
|
|
661
|
+
| `--color-diff-{added,removed}-row` | the success and danger `-soft` steps | a changed line's ground, on the sheet or a card |
|
|
662
|
+
| `--color-diff-{added,removed,hunk}-gutter` | `--color-fill-row` | the band a line's numbers stand in, over its row |
|
|
663
|
+
| `--color-diff-{added,removed}-word` | the success and danger `-line` steps | a changed word, over its row, in the primary text |
|
|
664
|
+
| `--color-diff-{added,removed}-sign` | the success and danger inks | a changed line's sign, and its numbers where a gutter is drawn |
|
|
665
|
+
| `--color-diff-{added,removed}-mark` | the success and danger fills | a diffstat's squares |
|
|
666
|
+
| `--color-diff-hunk-row` | `--color-brand-accent-soft` | the hunk row |
|
|
667
|
+
| `--color-syntax-{keyword,string,number,function,type}` | the accent, success, warning, info and danger inks | code |
|
|
668
|
+
| `--color-syntax-comment`, `-punctuation` | `--color-text-tertiary`, `--color-text-secondary` | a comment (also italic) and punctuation |
|
|
669
|
+
| `--color-change-{open,merged,closed}-fill`, `-label` | the success ink and the inverse text; the accent and on-accent; danger and on-danger | a state pill |
|
|
670
|
+
| `--color-change-draft-fill`, `-edge`, `-label` | raised, the strong hairline, the secondary text | the draft chip |
|
|
671
|
+
| `--color-change-{open,merged,closed,draft}-ink` | the success, accent and danger inks, and the tertiary text | a state's glyph on a row |
|
|
672
|
+
| `--color-code-ref-fill`, `--color-code-ref-ink` | the accent's soft step and ink | a branch chip, on the sheet or a card |
|
|
673
|
+
| `--color-code-match` | the warning `-line` step | a search match, in the primary text |
|
|
674
|
+
| `--color-file-{added,modified,deleted,renamed}-ink` | the success, warning and danger inks, and the tertiary text | a file's status in a tree; a type change reads as modified |
|
|
675
|
+
|
|
676
|
+
Here `-fill` is the ground a label or an ink stands on and `-label` the word on a pill. Two carve-outs: the open pill stands on the success ink, the family's one ground in an `-ink` step, because no label clears the success fill in both modes; and a match is amber, because in code the accent already marks the hunk row, a picked line, a branch chip and keywords.
|
|
677
|
+
|
|
678
|
+
A picked line, or one a finding or a link marks, takes `--color-surface-selected` in place of its tint and its gutter, never over them, and keeps its sign and an accent bar at its start, since its tint is the hunk row's; no tinted line takes the hover overlay. On a selected row a branch chip draws no ground of its own.
|
|
679
|
+
|
|
680
|
+
Under forced colours every tint gives way to the canvas: a changed line keeps its sign and its word, a state pill its word and a 1px border, and a match takes `Mark` and `MarkText`, as `Highlight` does. A diffstat's squares give way too, so draw them in `CanvasText` and the rest in `GrayText` there, as `SegmentedMeter`'s segments do, and give a branch chip a transparent 1px border, as a pill has.
|
|
681
|
+
|
|
644
682
|
### The accent
|
|
645
683
|
|
|
646
684
|
The accent is a violet, and it is **per palette**:
|
|
@@ -746,7 +784,7 @@ The marketing root keeps its own state and series values (`tokens/color.json`),
|
|
|
746
784
|
|
|
747
785
|
## The palette suite
|
|
748
786
|
|
|
749
|
-
`test/palette.mjs` holds the rule table and the colour maths, and `test/palette.test.mjs` runs it over `dist/css` in import order, in every theme state: the base marketing root (`base`), the dark root (`dark`), light by media query (`light (media query)`) and light by attribute (`light (attribute)`), which are the keys `paletteStates()` returns. It measures every text step on every surface it can land on (the four opaque rungs in `OPAQUE_SURFACES`, and the translucent overlays composited over each of them), the step between a word and a dimmed one, every ink on its own soft tint, every fill as a mark, each status glyph's ink on its fill, the primary action's three fills under its label and the steps between them, the destructive action's fill and its hover under the same label, the focus ring, the control boundary, the rail's current row, the steps between the rungs, the hairline that finds a card and the strong hairline round a raised chip, whether a hovered and a pressed row can be seen, the hue separations under normal, protan and deuteranopic vision (the states from each other, the chart series from their neighbours and from the danger red, and every hue from the accent), each artifact kind's hue as a mark, its ink on its own fill and the kind hues apart from each other, and the structure of the theme file itself. The WCAG maths it measures with is the package's own runtime export (see [Contrast at runtime](#contrast-at-runtime)), re-exported from `test/color.mjs`. A component suite that measures a colour of its own measures it on `OPAQUE_SURFACES` too, rather than on a list of surface names it keeps itself.
|
|
787
|
+
`test/palette.mjs` holds the rule table and the colour maths, and `test/palette.test.mjs` runs it over `dist/css` in import order, in every theme state: the base marketing root (`base`), the dark root (`dark`), light by media query (`light (media query)`) and light by attribute (`light (attribute)`), which are the keys `paletteStates()` returns. It measures every text step on every surface it can land on (the four opaque rungs in `OPAQUE_SURFACES`, and the translucent overlays composited over each of them), the step between a word and a dimmed one, every ink on its own soft tint, every fill as a mark, each status glyph's ink on its fill, the primary action's three fills under its label and the steps between them, the destructive action's fill and its hover under the same label, the focus ring, the control boundary, the rail's current row, the steps between the rungs, the hairline that finds a card and the strong hairline round a raised chip, whether a hovered and a pressed row can be seen, the hue separations under normal, protan and deuteranopic vision (the states from each other, the chart series from their neighbours and from the danger red, and every hue from the accent), each artifact kind's hue as a mark, its ink on its own fill and the kind hues apart from each other, the code host's family on its grounds and tints, and the structure of the theme file itself. The WCAG maths it measures with is the package's own runtime export (see [Contrast at runtime](#contrast-at-runtime)), re-exported from `test/color.mjs`. A component suite that measures a colour of its own measures it on `OPAQUE_SURFACES` too, rather than on a list of surface names it keeps itself. The code host's rules hold the shared steps the family aliases (the state inks and tints, the accent's soft step and ink, the tertiary text), so a fit holds those floors as well.
|
|
750
788
|
|
|
751
789
|
The module is **published**, as `@crewlethq/tokens/test/palette`, so a consumer runs the same rules over the version it installed:
|
|
752
790
|
|
package/dist/css/tokens.css
CHANGED
|
@@ -347,6 +347,50 @@
|
|
|
347
347
|
--font-weight-unread: var(--font-weight-black); /** A name with news in a long list read in passing (a room list): the heaviest step, beside names at the regular weight, so news is read by weight alone and at a glance. Named for its job, so the step can move without a rename. */
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
+
/* The code host's colours, resolved where a palette is painted. */
|
|
351
|
+
:root,
|
|
352
|
+
[class~="crewlet-brand-scope__layer"] {
|
|
353
|
+
--color-diff-added-row: var(--color-feedback-success-soft);
|
|
354
|
+
--color-diff-added-gutter: var(--color-fill-row);
|
|
355
|
+
--color-diff-added-word: var(--color-feedback-success-line);
|
|
356
|
+
--color-diff-added-sign: var(--color-feedback-success-ink);
|
|
357
|
+
--color-diff-added-mark: var(--color-feedback-success);
|
|
358
|
+
--color-diff-removed-row: var(--color-feedback-danger-soft);
|
|
359
|
+
--color-diff-removed-gutter: var(--color-fill-row);
|
|
360
|
+
--color-diff-removed-word: var(--color-feedback-danger-line);
|
|
361
|
+
--color-diff-removed-sign: var(--color-feedback-danger-ink);
|
|
362
|
+
--color-diff-removed-mark: var(--color-feedback-danger);
|
|
363
|
+
--color-diff-hunk-row: var(--color-brand-accent-soft);
|
|
364
|
+
--color-diff-hunk-gutter: var(--color-fill-row);
|
|
365
|
+
--color-syntax-keyword: var(--color-brand-accent-ink);
|
|
366
|
+
--color-syntax-string: var(--color-feedback-success-ink);
|
|
367
|
+
--color-syntax-number: var(--color-feedback-warning-ink);
|
|
368
|
+
--color-syntax-function: var(--color-feedback-info-ink);
|
|
369
|
+
--color-syntax-type: var(--color-feedback-danger-ink);
|
|
370
|
+
--color-syntax-comment: var(--color-text-tertiary);
|
|
371
|
+
--color-syntax-punctuation: var(--color-text-secondary);
|
|
372
|
+
--color-change-open-fill: var(--color-feedback-success-ink);
|
|
373
|
+
--color-change-open-label: var(--color-text-inverse);
|
|
374
|
+
--color-change-open-ink: var(--color-feedback-success-ink);
|
|
375
|
+
--color-change-merged-fill: var(--color-brand-accent);
|
|
376
|
+
--color-change-merged-label: var(--color-text-on-accent);
|
|
377
|
+
--color-change-merged-ink: var(--color-brand-accent-ink);
|
|
378
|
+
--color-change-closed-fill: var(--color-feedback-danger);
|
|
379
|
+
--color-change-closed-label: var(--color-text-on-danger);
|
|
380
|
+
--color-change-closed-ink: var(--color-feedback-danger-ink);
|
|
381
|
+
--color-change-draft-fill: var(--color-surface-elevated);
|
|
382
|
+
--color-change-draft-edge: var(--color-border-strong);
|
|
383
|
+
--color-change-draft-label: var(--color-text-secondary);
|
|
384
|
+
--color-change-draft-ink: var(--color-text-tertiary);
|
|
385
|
+
--color-code-ref-fill: var(--color-brand-accent-soft);
|
|
386
|
+
--color-code-ref-ink: var(--color-brand-accent-ink);
|
|
387
|
+
--color-code-match: var(--color-feedback-warning-line);
|
|
388
|
+
--color-file-added-ink: var(--color-feedback-success-ink);
|
|
389
|
+
--color-file-modified-ink: var(--color-feedback-warning-ink);
|
|
390
|
+
--color-file-deleted-ink: var(--color-feedback-danger-ink);
|
|
391
|
+
--color-file-renamed-ink: var(--color-text-tertiary);
|
|
392
|
+
}
|
|
393
|
+
|
|
350
394
|
@media (prefers-contrast: more) {
|
|
351
395
|
:root {
|
|
352
396
|
--color-edge-hairline: var(--color-border-control);
|
package/package.json
CHANGED
package/test/palette.d.mts
CHANGED
|
@@ -222,3 +222,28 @@ export const ARTIFACT_KIND_FILL_ALPHA: number;
|
|
|
222
222
|
export const ARTIFACT_KIND_DE: number;
|
|
223
223
|
/** The kind ground steps the primary text is held to 4.5:1 on, over the card rung (`ground`, `ground-strong`). */
|
|
224
224
|
export const ARTIFACT_KIND_GROUNDS: readonly string[];
|
|
225
|
+
|
|
226
|
+
/** The grounds code is read on, the sheet and the card. */
|
|
227
|
+
export const CODE_GROUNDS: readonly string[];
|
|
228
|
+
/** The selected tint a picked or marked line takes in place of its diff tint. */
|
|
229
|
+
export const CODE_PICK: string;
|
|
230
|
+
/** The seven syntax inks, by custom-property name. */
|
|
231
|
+
export const SYNTAX_INKS: readonly string[];
|
|
232
|
+
/** The code's own text, which a changed word and a match carry. */
|
|
233
|
+
export const CODE_TEXT: string;
|
|
234
|
+
/** A changed line's steps, added then removed. */
|
|
235
|
+
export const DIFF_ROWS: readonly { kind: string; row: string; gutter: string; word: string; sign: string; mark: string }[];
|
|
236
|
+
export const DIFF_HUNK: { readonly row: string; readonly gutter: string };
|
|
237
|
+
export const DIFF_SEEN_DE: number;
|
|
238
|
+
export const DIFF_GUTTER_DE: number;
|
|
239
|
+
export const DIFF_APART_DE: number;
|
|
240
|
+
export const SYNTAX_APART_DE: number;
|
|
241
|
+
/** Each change state as [state, fill, label, ink]: open, merged, closed, draft. */
|
|
242
|
+
export const CHANGE_STATES: readonly (readonly [string, string, string, string])[];
|
|
243
|
+
/** The draft chip as [fill, edge]. */
|
|
244
|
+
export const CHANGE_DRAFT_CHIP: readonly [string, string];
|
|
245
|
+
/** A file's status inks: added, modified, deleted, renamed. */
|
|
246
|
+
export const FILE_STATUSES: readonly string[];
|
|
247
|
+
/** A branch chip as [ink, fill]. */
|
|
248
|
+
export const CODE_REF: readonly [string, string];
|
|
249
|
+
export const CODE_MATCH: string;
|
package/test/palette.mjs
CHANGED
|
@@ -379,6 +379,50 @@ export const ARTIFACT_KIND_DE = 8;
|
|
|
379
379
|
*/
|
|
380
380
|
export const ARTIFACT_KIND_GROUNDS = ['ground', 'ground-strong'];
|
|
381
381
|
|
|
382
|
+
// ---------------------------------------------------------------------------
|
|
383
|
+
// Code read in a code host
|
|
384
|
+
// ---------------------------------------------------------------------------
|
|
385
|
+
|
|
386
|
+
/** The grounds code is read on: the sheet and the card (a code block, a diff's body, a code host's lists). */
|
|
387
|
+
export const CODE_GROUNDS = ['--color-surface-background', '--color-surface-subtle'];
|
|
388
|
+
/** A picked line, or one a finding marks: the selected tint, in place of its diff tint. */
|
|
389
|
+
export const CODE_PICK = '--color-surface-selected';
|
|
390
|
+
export const SYNTAX_INKS = ['keyword', 'string', 'number', 'function', 'type', 'comment', 'punctuation'].map((kind) => `--color-syntax-${kind}`);
|
|
391
|
+
/** The code's own text, which a changed word and a match carry. */
|
|
392
|
+
export const CODE_TEXT = '--color-text-primary';
|
|
393
|
+
/** A changed line's steps. The gutter and the word are drawn over the row. */
|
|
394
|
+
export const DIFF_ROWS = ['added', 'removed'].map((kind) => ({
|
|
395
|
+
kind,
|
|
396
|
+
row: `--color-diff-${kind}-row`,
|
|
397
|
+
gutter: `--color-diff-${kind}-gutter`,
|
|
398
|
+
word: `--color-diff-${kind}-word`,
|
|
399
|
+
sign: `--color-diff-${kind}-sign`,
|
|
400
|
+
mark: `--color-diff-${kind}-mark`,
|
|
401
|
+
}));
|
|
402
|
+
export const DIFF_HUNK = { row: '--color-diff-hunk-row', gutter: '--color-diff-hunk-gutter' };
|
|
403
|
+
/** A row, a word, the hunk row and a match: tints a reader looks for, in OKLab dE. */
|
|
404
|
+
export const DIFF_SEEN_DE = 3;
|
|
405
|
+
/** A gutter, and the hunk row beside a changed row: found by what they hold too. */
|
|
406
|
+
export const DIFF_GUTTER_DE = 1.5;
|
|
407
|
+
/** An added row from a removed one; the sign says which as well. */
|
|
408
|
+
export const DIFF_APART_DE = 3;
|
|
409
|
+
/** Two hued syntax inks, under normal vision. */
|
|
410
|
+
export const SYNTAX_APART_DE = 3;
|
|
411
|
+
/** A change's state as [state, fill, label, ink]. */
|
|
412
|
+
export const CHANGE_STATES = ['open', 'merged', 'closed', 'draft'].map((state) => [
|
|
413
|
+
state,
|
|
414
|
+
`--color-change-${state}-fill`,
|
|
415
|
+
`--color-change-${state}-label`,
|
|
416
|
+
`--color-change-${state}-ink`,
|
|
417
|
+
]);
|
|
418
|
+
/** The draft chip as [fill, edge]: the RAISED_CHIP pair. */
|
|
419
|
+
export const CHANGE_DRAFT_CHIP = ['--color-change-draft-fill', '--color-change-draft-edge'];
|
|
420
|
+
export const FILE_STATUSES = ['added', 'modified', 'deleted', 'renamed'].map((status) => `--color-file-${status}-ink`);
|
|
421
|
+
/** A branch chip as [ink, fill]. */
|
|
422
|
+
export const CODE_REF = ['--color-code-ref-ink', '--color-code-ref-fill'];
|
|
423
|
+
/** A search match's ground, under the code text. */
|
|
424
|
+
export const CODE_MATCH = '--color-code-match';
|
|
425
|
+
|
|
382
426
|
// ---------------------------------------------------------------------------
|
|
383
427
|
// The rail
|
|
384
428
|
// ---------------------------------------------------------------------------
|
|
@@ -1040,6 +1084,78 @@ function checkState(state, values, profile, push, theme = { tint: null, contrast
|
|
|
1040
1084
|
}
|
|
1041
1085
|
}
|
|
1042
1086
|
|
|
1087
|
+
// CODE READ IN A CODE HOST. Each token is an alias, followed to the step it names; a pair an
|
|
1088
|
+
// existing rule already holds is asserted by checkStructure, not measured again.
|
|
1089
|
+
{
|
|
1090
|
+
const ink = high ? HIGH_CONTRAST.ink : 4.5;
|
|
1091
|
+
const inkOf = (name) => colour(dereference(values, name));
|
|
1092
|
+
const over = (name, grounds) => grounds.map(([where, rgb]) => [`${name} on ${where}`, flatten(values.get(dereference(values, name)), rgb)]);
|
|
1093
|
+
const code = opaque.filter(([name]) => CODE_GROUNDS.includes(name));
|
|
1094
|
+
const rows = DIFF_ROWS.map((diff) => {
|
|
1095
|
+
const lines = over(diff.row, code);
|
|
1096
|
+
return { ...diff, lines, gutters: over(diff.gutter, lines), words: over(diff.word, lines) };
|
|
1097
|
+
});
|
|
1098
|
+
const hunk = over(DIFF_HUNK.row, code);
|
|
1099
|
+
const hunkGutters = over(DIFF_HUNK.gutter, hunk);
|
|
1100
|
+
const hovered = over('--color-surface-hover', code);
|
|
1101
|
+
const picked = over(CODE_PICK, code);
|
|
1102
|
+
const floor = (rule, subject, low, min) => say(rule, low.ratio >= min, subject, low.ratio, `${low.ratio.toFixed(2)}:1 >= ${min} (worst on ${low.name})`);
|
|
1103
|
+
|
|
1104
|
+
const read = [...code, ...hovered, ...rows.flatMap((diff) => diff.lines), ...hunk, ...picked];
|
|
1105
|
+
// Rule 1 leaves the code text to TEXT_STEPS (7:1), which no tint here brings near 4.5.
|
|
1106
|
+
for (const name of [...SYNTAX_INKS, CODE_TEXT]) {
|
|
1107
|
+
if (name !== CODE_TEXT) floor('a syntax ink clears its floor on code and on a changed line', name, worst(inkOf(name), read), ink);
|
|
1108
|
+
floor("a code ink clears 3:1 as a glyph on the hunk row's gutter", name, worst(inkOf(name), hunkGutters), 3);
|
|
1109
|
+
}
|
|
1110
|
+
for (const diff of rows) {
|
|
1111
|
+
floor("a changed line's sign clears its floor on its line and its gutter", diff.sign, worst(inkOf(diff.sign), [...diff.lines, ...diff.gutters]), ink);
|
|
1112
|
+
}
|
|
1113
|
+
{
|
|
1114
|
+
const marks = [...rows.flatMap((diff) => diff.words), ...over(CODE_MATCH, code)];
|
|
1115
|
+
floor('the code text clears its floor on a changed word and on a match', CODE_TEXT, worst(inkOf(CODE_TEXT), marks), ink);
|
|
1116
|
+
}
|
|
1117
|
+
{
|
|
1118
|
+
// The open pill alone: merged and closed are LABEL_ON_FILL pairs.
|
|
1119
|
+
const [, fill, label] = CHANGE_STATES.find(([state]) => state === 'open');
|
|
1120
|
+
floor("an open pill's label clears 4.5:1 on its fill", `${label} on ${fill}`, worst(inkOf(label), over(fill, opaque)), 4.5);
|
|
1121
|
+
}
|
|
1122
|
+
{
|
|
1123
|
+
// A chip at rest and on a hovered row; on a selected row it draws no ground.
|
|
1124
|
+
const [refInk, refFill] = CODE_REF;
|
|
1125
|
+
const grounds = [...over(refFill, code), ...over(refFill, hovered), ...picked];
|
|
1126
|
+
floor("a branch chip's ink clears its floor on its chip and on a selected row", refInk, worst(inkOf(refInk), grounds), ink);
|
|
1127
|
+
}
|
|
1128
|
+
if (profile === 'full') {
|
|
1129
|
+
const apart = (rule, a, b, min, subject) => {
|
|
1130
|
+
const low = a.reduce((least, [where, rgb], i) => {
|
|
1131
|
+
const measured = deltaE(rgb, b[i][1]);
|
|
1132
|
+
return measured < least.measured ? { measured, where } : least;
|
|
1133
|
+
}, { measured: Infinity, where: '' });
|
|
1134
|
+
say(rule, low.measured >= min, subject, low.measured, `dE ${low.measured.toFixed(2)} >= ${min} (closest ${low.where})`);
|
|
1135
|
+
};
|
|
1136
|
+
const SEEN = 'a diff tint is seen on what it is drawn over';
|
|
1137
|
+
const GUTTER = 'a gutter reads on its line';
|
|
1138
|
+
for (const diff of rows) {
|
|
1139
|
+
apart(SEEN, diff.lines, code, DIFF_SEEN_DE, diff.row);
|
|
1140
|
+
apart(SEEN, diff.words, diff.lines, DIFF_SEEN_DE, diff.word);
|
|
1141
|
+
apart(GUTTER, diff.gutters, diff.lines, DIFF_GUTTER_DE, diff.gutter);
|
|
1142
|
+
apart('the hunk row reads apart from a changed line', hunk, diff.lines, DIFF_GUTTER_DE, `${DIFF_HUNK.row} vs ${diff.row}`);
|
|
1143
|
+
}
|
|
1144
|
+
apart(SEEN, hunk, code, DIFF_SEEN_DE, DIFF_HUNK.row);
|
|
1145
|
+
apart(SEEN, over(CODE_MATCH, code), code, DIFF_SEEN_DE, CODE_MATCH);
|
|
1146
|
+
apart(GUTTER, hunkGutters, hunk, DIFF_GUTTER_DE, DIFF_HUNK.gutter);
|
|
1147
|
+
const [added, removed] = rows;
|
|
1148
|
+
apart('added and removed lines read apart', added.lines, removed.lines, DIFF_APART_DE, `${added.row} vs ${removed.row}`);
|
|
1149
|
+
const hued = SYNTAX_INKS.filter((name) => !name.endsWith('-comment') && !name.endsWith('-punctuation'));
|
|
1150
|
+
for (let i = 0; i < hued.length; i += 1) {
|
|
1151
|
+
for (let j = i + 1; j < hued.length; j += 1) {
|
|
1152
|
+
const measured = deltaE(inkOf(hued[i]), inkOf(hued[j]));
|
|
1153
|
+
say('syntax inks stay apart', measured >= SYNTAX_APART_DE, `${hued[i]} vs ${hued[j]}`, measured, `dE ${measured.toFixed(1)} >= ${SYNTAX_APART_DE}`);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1043
1159
|
// THE PRIMARY ACTION'S STEPS. See ACTION_STEPS.
|
|
1044
1160
|
for (const [rule, step, from] of ACTION_STEPS) {
|
|
1045
1161
|
const name = labelOf(step);
|
|
@@ -1547,6 +1663,44 @@ function checkStructure(sources, states, push) {
|
|
|
1547
1663
|
? `all ${literal.length} literal steps differ between the palettes (${SHADOW_STEPS.length - literal.length} repaint through var())`
|
|
1548
1664
|
: `the same value in both palettes: ${invariant.map((name) => `${name} (${lightBlock.get(name)})`).join('; ')}`,
|
|
1549
1665
|
);
|
|
1666
|
+
|
|
1667
|
+
// A CODE HOST ALIAS NAMES A STEP HELD FOR ITS USE. Value-independent, so a fit never moves it:
|
|
1668
|
+
// it asserts the aliases that put the family's pills, glyphs and marks under existing rules.
|
|
1669
|
+
{
|
|
1670
|
+
const rule = 'a code host alias names a step held for its use';
|
|
1671
|
+
const values = states.dark;
|
|
1672
|
+
const named = (name) => dereference(values, name);
|
|
1673
|
+
const among = (name, steps) => steps.some((step) => named(step) === named(name));
|
|
1674
|
+
const inks = [...INK_STEPS, ...TEXT_STEPS.map(([name]) => name)];
|
|
1675
|
+
const check = (subject, problems) =>
|
|
1676
|
+
say(rule, problems.length === 0, subject, problems.length === 0 ? 'each alias names a step held for its use' : problems.join('; '));
|
|
1677
|
+
const expect = (ok, name, should) => (ok ? [] : [`${name} names ${named(name)}, not ${should}`]);
|
|
1678
|
+
for (const [state, fill, label, ink] of CHANGE_STATES) {
|
|
1679
|
+
const problems = [];
|
|
1680
|
+
if (state === 'open') {
|
|
1681
|
+
problems.push(...expect(among(fill, [...INK_STEPS, ...FILL_STEPS]), fill, 'an INK_STEPS or FILL_STEPS step'));
|
|
1682
|
+
} else if (state === 'draft') {
|
|
1683
|
+
const [chipFill, edge] = CHANGE_DRAFT_CHIP;
|
|
1684
|
+
problems.push(...expect(named(chipFill) === named(RAISED_CHIP[0]), chipFill, RAISED_CHIP[0]));
|
|
1685
|
+
problems.push(...expect(named(edge) === named(RAISED_CHIP[1]), edge, RAISED_CHIP[1]));
|
|
1686
|
+
problems.push(...expect(among(label, TEXT_STEPS.map(([name]) => name)), label, 'a TEXT_STEPS step'));
|
|
1687
|
+
} else {
|
|
1688
|
+
const paired = LABEL_ON_FILL.some(([l, f]) => named(l) === named(label) && named(f) === named(fill));
|
|
1689
|
+
problems.push(...expect(paired, `${label} on ${fill}`, 'a LABEL_ON_FILL pair'));
|
|
1690
|
+
problems.push(...expect(among(fill, FILL_STEPS), fill, 'a FILL_STEPS step'));
|
|
1691
|
+
}
|
|
1692
|
+
problems.push(...expect(among(ink, inks), ink, 'an INK_STEPS or TEXT_STEPS step'));
|
|
1693
|
+
check(`--color-change-${state}`, problems);
|
|
1694
|
+
}
|
|
1695
|
+
for (const name of FILE_STATUSES) check(name, expect(among(name, inks), name, 'an INK_STEPS or TEXT_STEPS step'));
|
|
1696
|
+
for (const { mark } of DIFF_ROWS) check(mark, expect(among(mark, FILL_STEPS), mark, 'a FILL_STEPS step'));
|
|
1697
|
+
// No two states share a fill or an ink; within one state the open pill's fill is its ink.
|
|
1698
|
+
const changes = CHANGE_STATES.flatMap(([, fill, , ink]) => (named(fill) === named(ink) ? [fill] : [fill, ink]));
|
|
1699
|
+
for (const [group, list] of [['the change states', changes], ['the file statuses', FILE_STATUSES]]) {
|
|
1700
|
+
const shared = list.filter((name, i) => list.findIndex((other) => named(other) === named(name)) !== i);
|
|
1701
|
+
check(group, shared.map((name) => `${name} names ${named(name)}, as another does`));
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1550
1704
|
}
|
|
1551
1705
|
|
|
1552
1706
|
// ---------------------------------------------------------------------------
|
package/test/palette.test.mjs
CHANGED
|
@@ -21,11 +21,16 @@ import {
|
|
|
21
21
|
ARTIFACT_KIND_HUES,
|
|
22
22
|
ARTIFACT_KINDS,
|
|
23
23
|
CARD_HAIRLINE,
|
|
24
|
+
CHANGE_DRAFT_CHIP,
|
|
25
|
+
CHANGE_STATES,
|
|
26
|
+
CODE_REF,
|
|
24
27
|
DATA,
|
|
25
28
|
DATA_ADJACENT_DE,
|
|
26
29
|
DATA_ADJACENT_NORMAL_DE,
|
|
27
30
|
describeFailure,
|
|
31
|
+
DIFF_ROWS,
|
|
28
32
|
DIMMED_TEXT,
|
|
33
|
+
FILE_STATUSES,
|
|
29
34
|
fromOklab,
|
|
30
35
|
hex,
|
|
31
36
|
MARK_ON_FILL,
|
|
@@ -39,6 +44,7 @@ import {
|
|
|
39
44
|
RAISED_CHIP,
|
|
40
45
|
runPalette,
|
|
41
46
|
RUNG_STEPS,
|
|
47
|
+
SYNTAX_INKS,
|
|
42
48
|
tightest,
|
|
43
49
|
toOklab,
|
|
44
50
|
VEIL_ALPHA,
|
|
@@ -569,6 +575,113 @@ describe('the state and chart hues', () => {
|
|
|
569
575
|
});
|
|
570
576
|
});
|
|
571
577
|
|
|
578
|
+
describe('code read in a code host', () => {
|
|
579
|
+
const { checks } = runPalette(sources);
|
|
580
|
+
const RULES = [
|
|
581
|
+
'a syntax ink clears its floor on code and on a changed line',
|
|
582
|
+
"a code ink clears 3:1 as a glyph on the hunk row's gutter",
|
|
583
|
+
"a changed line's sign clears its floor on its line and its gutter",
|
|
584
|
+
'the code text clears its floor on a changed word and on a match',
|
|
585
|
+
"an open pill's label clears 4.5:1 on its fill",
|
|
586
|
+
"a branch chip's ink clears its floor on its chip and on a selected row",
|
|
587
|
+
'a diff tint is seen on what it is drawn over',
|
|
588
|
+
'a gutter reads on its line',
|
|
589
|
+
'the hunk row reads apart from a changed line',
|
|
590
|
+
'added and removed lines read apart',
|
|
591
|
+
'syntax inks stay apart',
|
|
592
|
+
'a code host alias names a step held for its use',
|
|
593
|
+
];
|
|
594
|
+
const rule = (n) => RULES[n - 1];
|
|
595
|
+
|
|
596
|
+
/** The rules that fail, each once and sorted, once one family alias in tokens.css names another value. */
|
|
597
|
+
function familyAfter(name, value) {
|
|
598
|
+
const tokens = sources.tokens.replace(new RegExp(`(${name}: )[^;]+;`), `$1${value};`);
|
|
599
|
+
assert.notEqual(tokens, sources.tokens, `${name} is not declared in tokens.css`);
|
|
600
|
+
const states = [...THEME_STATES, 'the token files'];
|
|
601
|
+
return [...new Set(runPalette({ ...sources, tokens }).failures.filter((check) => states.includes(check.state)).map((check) => check.rule))].sort();
|
|
602
|
+
}
|
|
603
|
+
const expect = (...numbers) => numbers.map(rule).sort();
|
|
604
|
+
|
|
605
|
+
test('rules 1 to 11 run in every theme state and rule 12 over the token files', () => {
|
|
606
|
+
for (const name of RULES.slice(0, 11)) {
|
|
607
|
+
for (const state of THEME_STATES) assert.ok(checks.some((check) => check.state === state && check.rule === name), `${name} in ${state}`);
|
|
608
|
+
}
|
|
609
|
+
assert.ok(checks.some((check) => check.state === 'the token files' && check.rule === rule(12)));
|
|
610
|
+
assert.equal(SYNTAX_INKS.length, 7);
|
|
611
|
+
assert.deepEqual(DIFF_ROWS.map((diff) => diff.kind), ['added', 'removed']);
|
|
612
|
+
assert.deepEqual(CHANGE_STATES.map(([state]) => state), ['open', 'merged', 'closed', 'draft']);
|
|
613
|
+
assert.equal(FILE_STATUSES.length, 4);
|
|
614
|
+
assert.equal(CHANGE_DRAFT_CHIP.length, 2);
|
|
615
|
+
assert.equal(CODE_REF.length, 2);
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
test('a comment in the decorative step is caught on code and on the hunk gutter', () => {
|
|
619
|
+
assert.deepEqual(familyAfter('--color-syntax-comment', 'var(--color-text-muted)'), expect(1, 2));
|
|
620
|
+
assert.deepEqual(familyAfter('--color-diff-hunk-gutter', 'var(--color-text-muted)'), expect(2));
|
|
621
|
+
});
|
|
622
|
+
test('a sign in its fill step is caught on its own row, and on its gutter', () => {
|
|
623
|
+
assert.deepEqual(familyAfter('--color-diff-removed-sign', 'var(--color-feedback-danger)'), expect(3));
|
|
624
|
+
assert.deepEqual(familyAfter('--color-diff-removed-gutter', 'var(--color-feedback-danger-line)'), expect(3));
|
|
625
|
+
});
|
|
626
|
+
test('a picked line in a stronger tint is caught under code and under a branch chip', () => {
|
|
627
|
+
assert.deepEqual(familyAfter('--color-surface-selected', 'var(--color-brand-accent-soft-strong)'), expect(1, 6));
|
|
628
|
+
});
|
|
629
|
+
test('a changed word or a match drawn as a solid fill is caught under the code text', () => {
|
|
630
|
+
assert.deepEqual(familyAfter('--color-diff-added-word', 'var(--color-feedback-success)'), expect(4));
|
|
631
|
+
assert.deepEqual(familyAfter('--color-code-match', 'var(--color-feedback-warning)'), expect(4));
|
|
632
|
+
});
|
|
633
|
+
test('an open pill labelled in the on-accent step is caught', () => {
|
|
634
|
+
assert.deepEqual(familyAfter('--color-change-open-label', 'var(--color-text-on-accent)'), expect(5));
|
|
635
|
+
});
|
|
636
|
+
test('a branch chip in the decorative step, or on a red ground, is caught', () => {
|
|
637
|
+
assert.deepEqual(familyAfter('--color-code-ref-ink', 'var(--color-text-muted)'), expect(6));
|
|
638
|
+
// Fails on a hovered row only.
|
|
639
|
+
assert.deepEqual(familyAfter('--color-code-ref-fill', 'var(--color-feedback-danger-soft)'), expect(6));
|
|
640
|
+
});
|
|
641
|
+
test('a row, a word, the hunk row or a match nobody can see, and a gutter with no band, are caught', () => {
|
|
642
|
+
for (const name of ['--color-diff-added-row', '--color-diff-removed-word', '--color-diff-hunk-row', '--color-code-match']) {
|
|
643
|
+
assert.deepEqual(familyAfter(name, 'var(--color-fill-row)'), expect(7), name);
|
|
644
|
+
}
|
|
645
|
+
// Literals the build refuses, so only this suite can catch them.
|
|
646
|
+
assert.deepEqual(familyAfter('--color-diff-added-gutter', 'rgba(0, 0, 0, 0)'), expect(8));
|
|
647
|
+
assert.deepEqual(familyAfter('--color-diff-hunk-gutter', 'rgba(0, 0, 0, 0)'), expect(8));
|
|
648
|
+
});
|
|
649
|
+
test('a hunk row in the removed tint, and a removed row in the added tint, are caught', () => {
|
|
650
|
+
assert.deepEqual(familyAfter('--color-diff-hunk-row', 'var(--color-feedback-danger-soft)'), expect(9));
|
|
651
|
+
assert.deepEqual(familyAfter('--color-diff-removed-row', 'var(--color-feedback-success-soft)'), expect(10));
|
|
652
|
+
});
|
|
653
|
+
test('two syntax kinds in one ink are caught', () => {
|
|
654
|
+
assert.deepEqual(familyAfter('--color-syntax-function', 'var(--color-brand-accent-ink)'), expect(11));
|
|
655
|
+
});
|
|
656
|
+
test('an alias that leaves the step its rules hold is caught by the structure alone', () => {
|
|
657
|
+
for (const [name, value] of [
|
|
658
|
+
['--color-change-closed-fill', 'var(--color-surface-frame)'],
|
|
659
|
+
['--color-change-merged-ink', 'var(--color-brand-accent)'],
|
|
660
|
+
['--color-change-draft-fill', 'var(--color-surface-subtle)'],
|
|
661
|
+
['--color-file-renamed-ink', 'var(--color-text-muted)'],
|
|
662
|
+
['--color-file-added-ink', 'var(--color-feedback-danger-ink)'],
|
|
663
|
+
['--color-diff-added-mark', 'var(--color-feedback-success-ink)'],
|
|
664
|
+
['--color-change-merged-label', 'var(--color-text-inverse)'],
|
|
665
|
+
['--color-change-draft-edge', 'var(--color-border-default)'],
|
|
666
|
+
['--color-change-draft-label', 'var(--color-text-muted)'],
|
|
667
|
+
['--color-change-open-ink', 'var(--color-brand-accent-ink)'],
|
|
668
|
+
['--color-change-open-fill', 'var(--color-text-primary)'],
|
|
669
|
+
['--color-change-open-fill', 'var(--color-feedback-danger-ink)'],
|
|
670
|
+
]) {
|
|
671
|
+
assert.deepEqual(familyAfter(name, value), expect(12), `${name}: ${value}`);
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
test('high contrast holds the family to its own floors', () => {
|
|
675
|
+
const theme = byId('high-contrast');
|
|
676
|
+
const failing = (edit) => [...new Set(runPalette({ ...namedSources(theme), tokens: edit(sources.tokens) }).failures.map((check) => check.rule))].sort();
|
|
677
|
+
const gutter = (tokens) => tokens.replace(/(--color-diff-removed-gutter: )[^;]+;/, '$1var(--color-feedback-info-soft);');
|
|
678
|
+
assert.deepEqual(failing((tokens) => tokens), []);
|
|
679
|
+
// Clears 4.5:1 in the default theme, not 7:1 here.
|
|
680
|
+
assert.deepEqual(familyAfter('--color-diff-removed-gutter', 'var(--color-feedback-info-soft)'), []);
|
|
681
|
+
assert.deepEqual(failing(gutter), expect(3));
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
|
|
572
685
|
describe('the colour maths', () => {
|
|
573
686
|
test('a colour a screen shows round-trips through OKLab, and one past the gamut says so', () => {
|
|
574
687
|
// fromOklab reads its channels from oklabToLinear and clips them, so a
|