@grafctory/skin 0.0.0-stage → 0.3.1

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.
Files changed (78) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +469 -2
  3. package/dist/index.core.d.ts +201 -0
  4. package/dist/index.core.d.ts.map +1 -0
  5. package/dist/index.core.js +17 -0
  6. package/dist/index.core.js.map +1 -0
  7. package/dist/index.css +126 -0
  8. package/dist/index.d.ts +432 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +184 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/markup/alerts.css +83 -0
  13. package/dist/markup/blocks.css +255 -0
  14. package/dist/markup/forms.css +551 -0
  15. package/dist/markup/headings.css +131 -0
  16. package/dist/markup/highlights.css +38 -0
  17. package/dist/markup/inlines.css +183 -0
  18. package/dist/markup/lists.css +206 -0
  19. package/dist/markup/reset.css +38 -0
  20. package/dist/markup/tables.css +78 -0
  21. package/dist/presets/inter.css +194 -0
  22. package/dist/presets/roboto.css +198 -0
  23. package/dist/tokens/borders.css +151 -0
  24. package/dist/tokens/borders.d.ts +57 -0
  25. package/dist/tokens/borders.d.ts.map +1 -0
  26. package/dist/tokens/borders.js +72 -0
  27. package/dist/tokens/borders.js.map +1 -0
  28. package/dist/tokens/colors.css +515 -0
  29. package/dist/tokens/colors.d.ts +171 -0
  30. package/dist/tokens/colors.d.ts.map +1 -0
  31. package/dist/tokens/colors.js +186 -0
  32. package/dist/tokens/colors.js.map +1 -0
  33. package/dist/tokens/elevations.css +110 -0
  34. package/dist/tokens/elevations.d.ts +54 -0
  35. package/dist/tokens/elevations.d.ts.map +1 -0
  36. package/dist/tokens/elevations.js +69 -0
  37. package/dist/tokens/elevations.js.map +1 -0
  38. package/dist/tokens/layers.css +57 -0
  39. package/dist/tokens/layers.d.ts +34 -0
  40. package/dist/tokens/layers.d.ts.map +1 -0
  41. package/dist/tokens/layers.js +49 -0
  42. package/dist/tokens/layers.js.map +1 -0
  43. package/dist/tokens/motions.css +91 -0
  44. package/dist/tokens/motions.d.ts +40 -0
  45. package/dist/tokens/motions.d.ts.map +1 -0
  46. package/dist/tokens/motions.js +55 -0
  47. package/dist/tokens/motions.js.map +1 -0
  48. package/dist/tokens/opacities.css +41 -0
  49. package/dist/tokens/opacities.d.ts +32 -0
  50. package/dist/tokens/opacities.d.ts.map +1 -0
  51. package/dist/tokens/opacities.js +47 -0
  52. package/dist/tokens/opacities.js.map +1 -0
  53. package/dist/tokens/palettes.css +546 -0
  54. package/dist/tokens/palettes.d.ts +140 -0
  55. package/dist/tokens/palettes.d.ts.map +1 -0
  56. package/dist/tokens/palettes.js +155 -0
  57. package/dist/tokens/palettes.js.map +1 -0
  58. package/dist/tokens/scalings.css +81 -0
  59. package/dist/tokens/scalings.d.ts +31 -0
  60. package/dist/tokens/scalings.d.ts.map +1 -0
  61. package/dist/tokens/scalings.js +46 -0
  62. package/dist/tokens/scalings.js.map +1 -0
  63. package/dist/tokens/spacings.css +78 -0
  64. package/dist/tokens/spacings.d.ts +34 -0
  65. package/dist/tokens/spacings.d.ts.map +1 -0
  66. package/dist/tokens/spacings.js +49 -0
  67. package/dist/tokens/spacings.js.map +1 -0
  68. package/dist/tokens/typography.css +156 -0
  69. package/dist/tokens/typography.d.ts +77 -0
  70. package/dist/tokens/typography.d.ts.map +1 -0
  71. package/dist/tokens/typography.js +92 -0
  72. package/dist/tokens/typography.js.map +1 -0
  73. package/dist/tokens/viewports.css +101 -0
  74. package/dist/tokens/viewports.d.ts +75 -0
  75. package/dist/tokens/viewports.d.ts.map +1 -0
  76. package/dist/tokens/viewports.js +90 -0
  77. package/dist/tokens/viewports.js.map +1 -0
  78. package/package.json +87 -4
@@ -0,0 +1,432 @@
1
+ /**
2
+ * Design system.
3
+ *
4
+ * Names the tokens an app may override to restyle an interface, and a component reads to inherit that styling, and
5
+ * gives the custom property each one resolves to, for a value taken outside the cascade. A token is read wherever a
6
+ * CSS value is written by hand, and assigned to a subtree through a style declaration any rendering layer accepts.
7
+ * The values behind them are provided by the companion stylesheet.
8
+ *
9
+ * An app that includes the stylesheet gets the Metreeca colours set in the platform faces, light or dark according to
10
+ * the platform colour scheme. One that includes a preset in its place gets the faces the preset bundles, and one that
11
+ * redefines the tokens gets its own look, with no component change. Components name tokens through this contract
12
+ * rather than through literal strings, so a renamed token breaks the build instead of losing its style.
13
+ *
14
+ * The tokens cover typography, spacing, sizing, borders, colours, elevation, data and editor palettes, stacking,
15
+ * motion, opacity and viewport breakpoints. {@link skin} gathers them all in one place, so a consumer names any token
16
+ * from the package root, without having to know which of these concerns it belongs to.
17
+ *
18
+ * @example
19
+ *
20
+ * Include the stylesheet once, at the entry point of the app:
21
+ *
22
+ * ```typescript
23
+ * import "@grafctory/skin/index.css";
24
+ * ```
25
+ *
26
+ * Include a preset in its place to set the interface in the faces the preset bundles:
27
+ *
28
+ * ```typescript
29
+ * import "@grafctory/skin/presets/roboto.css";
30
+ * ```
31
+ *
32
+ * Override any token to restyle the whole interface, stating a colour for both schemes as a `light-dark()` pair:
33
+ *
34
+ * ```css
35
+ * :root {
36
+ * --skin--color-strong: light-dark(#06C, #4AF);
37
+ * }
38
+ * ```
39
+ *
40
+ * Pin a colour scheme, on the root element or on any subtree that has to differ from the page:
41
+ *
42
+ * ```tsx
43
+ * <aside data-scheme="dark">
44
+ * ```
45
+ *
46
+ * Assign the tokens inline to restyle a single subtree instead:
47
+ *
48
+ * ```tsx
49
+ * <section style={css({ colorStrong: "#06C" })}>
50
+ * ```
51
+ *
52
+ * Read a token where a single CSS value is written by hand:
53
+ *
54
+ * ```tsx
55
+ * <span style={{ backgroundColor: css.var(skin.colorStrong) }}/>
56
+ * ```
57
+ *
58
+ * @remarks
59
+ *
60
+ * **Override order** — the stylesheet declares its rules in a `skin` cascade layer, so a rule an app or a component
61
+ * writes outside a layer wins whatever order the two stylesheets reach the document in, and whichever selector is the
62
+ * more specific. An app declaring layers of its own orders them after `skin`, or the design system outranks them. A
63
+ * preset restates tokens inside the same layer, after the defaults it overrides, so an app rule wins over a preset too.
64
+ *
65
+ * **Missing and malformed values** — a token carrying a literal states it as the registered default of its custom
66
+ * property, so the value lives in one place. A malformed override is caught only where the token has a fixed type: a
67
+ * weight, a duration or an opacity the browser cannot parse stays on its default. Most tokens, the colour anchors and
68
+ * the sizes among them, take an override as written, so a malformed value leaves whatever reads it unstyled rather
69
+ * than on the default. A component styled against a token it cannot count on, because the stylesheet may not
70
+ * be loaded at all, names its own fallback in the reference it writes by hand, the one case {@link css css.var} does
71
+ * not cover, stating the shipped light default: `var(--skin--color-strong, #B74300)`.
72
+ *
73
+ * **First paint** — the stylesheet has to reach the document before it is painted, or the first frame shows the
74
+ * unstyled markup: an app bundling it from the entry point is served by the bundler, while one assembling its own HTML
75
+ * links it in the document head. An override stated in a `<style>` in the document head is in force from the first
76
+ * frame, so a loader painted before the stylesheet arrives already reads the app's brand.
77
+ *
78
+ * **Values outside the cascade** — a consumer painting where a reference doesn't reach, on a canvas or against an API
79
+ * taking a colour as text, takes the value a token resolves to for the element it applies to, rather than a copy of
80
+ * the default, and so keeps whatever the app overrode and whichever colour scheme is in force. A colour token holds a
81
+ * `light-dark()` pair or a mix until something paints with it, so it is resolved through a colour property of an
82
+ * element in the subtree:
83
+ *
84
+ * ```typescript
85
+ * probe.style.color = css.var(skin.colorStrong);
86
+ * getComputedStyle(probe).color
87
+ * ```
88
+ *
89
+ * @module index
90
+ */
91
+ import type { Alias, Fill, Ink, Literal, Palette } from "./index.core.js";
92
+ /**
93
+ * The custom property behind every design system token.
94
+ *
95
+ * Resolves each {@link Token token name} to the {@link Property custom property} carrying its value, which is what
96
+ * {@link css css.var} reads a token through and what a value taken outside the cascade is looked up by; assigning a
97
+ * token to a subtree goes through {@link css} instead. Gathers every token group, so a consumer names a token without
98
+ * knowing which one it belongs to.
99
+ */
100
+ export declare const skin: {
101
+ viewportSmall: "--skin--viewport-small";
102
+ viewportMedium: "--skin--viewport-medium";
103
+ viewportLarge: "--skin--viewport-large";
104
+ viewportXlarge: "--skin--viewport-xlarge";
105
+ opacityDisabled: "--skin--opacity-disabled";
106
+ opacityLoading: "--skin--opacity-loading";
107
+ opacityLocked: "--skin--opacity-locked";
108
+ durationFast: "--skin--duration-fast";
109
+ durationNormal: "--skin--duration-normal";
110
+ durationSlow: "--skin--duration-slow";
111
+ durationSpin: "--skin--duration-spin";
112
+ easingStandard: "--skin--easing-standard";
113
+ easingEnter: "--skin--easing-enter";
114
+ easingExit: "--skin--easing-exit";
115
+ zIndexSticky: "--skin--z-index-sticky";
116
+ zIndexDropdown: "--skin--z-index-dropdown";
117
+ zIndexBlanket: "--skin--z-index-blanket";
118
+ zIndexModal: "--skin--z-index-modal";
119
+ zIndexToast: "--skin--z-index-toast";
120
+ zIndexTooltip: "--skin--z-index-tooltip";
121
+ colorGray010: "--skin--color-gray-010";
122
+ colorGray020: "--skin--color-gray-020";
123
+ colorGray030: "--skin--color-gray-030";
124
+ colorGray040: "--skin--color-gray-040";
125
+ colorGray050: "--skin--color-gray-050";
126
+ colorGray060: "--skin--color-gray-060";
127
+ colorGray070: "--skin--color-gray-070";
128
+ colorGray080: "--skin--color-gray-080";
129
+ colorGray090: "--skin--color-gray-090";
130
+ colorGray100: "--skin--color-gray-100";
131
+ colorSubtle010: "--skin--color-subtle-010";
132
+ colorSubtle020: "--skin--color-subtle-020";
133
+ colorSubtle030: "--skin--color-subtle-030";
134
+ colorSubtle040: "--skin--color-subtle-040";
135
+ colorSubtle050: "--skin--color-subtle-050";
136
+ colorSubtle060: "--skin--color-subtle-060";
137
+ colorSubtle070: "--skin--color-subtle-070";
138
+ colorSubtle080: "--skin--color-subtle-080";
139
+ colorSubtle090: "--skin--color-subtle-090";
140
+ colorSubtle100: "--skin--color-subtle-100";
141
+ colorStrong010: "--skin--color-strong-010";
142
+ colorStrong020: "--skin--color-strong-020";
143
+ colorStrong030: "--skin--color-strong-030";
144
+ colorStrong040: "--skin--color-strong-040";
145
+ colorStrong050: "--skin--color-strong-050";
146
+ colorStrong060: "--skin--color-strong-060";
147
+ colorStrong070: "--skin--color-strong-070";
148
+ colorStrong080: "--skin--color-strong-080";
149
+ colorStrong090: "--skin--color-strong-090";
150
+ colorStrong100: "--skin--color-strong-100";
151
+ colorHeat010: "--skin--color-heat-010";
152
+ colorHeat020: "--skin--color-heat-020";
153
+ colorHeat030: "--skin--color-heat-030";
154
+ colorHeat040: "--skin--color-heat-040";
155
+ colorHeat050: "--skin--color-heat-050";
156
+ colorHeat060: "--skin--color-heat-060";
157
+ colorHeat070: "--skin--color-heat-070";
158
+ colorHeat080: "--skin--color-heat-080";
159
+ colorHeat090: "--skin--color-heat-090";
160
+ colorHeat100: "--skin--color-heat-100";
161
+ colorSeries1: "--skin--color-series-1";
162
+ colorSeries2: "--skin--color-series-2";
163
+ colorSeries3: "--skin--color-series-3";
164
+ colorSeries4: "--skin--color-series-4";
165
+ colorSeries5: "--skin--color-series-5";
166
+ colorSeries6: "--skin--color-series-6";
167
+ colorSeries7: "--skin--color-series-7";
168
+ colorSeries8: "--skin--color-series-8";
169
+ colorSeries9: "--skin--color-series-9";
170
+ colorArea1: "--skin--color-area-1";
171
+ colorArea2: "--skin--color-area-2";
172
+ colorArea3: "--skin--color-area-3";
173
+ colorArea4: "--skin--color-area-4";
174
+ colorBlack: "--skin--color-black";
175
+ colorGray: "--skin--color-gray";
176
+ colorWhite: "--skin--color-white";
177
+ colorRedStrong: "--skin--color-red-strong";
178
+ colorRed: "--skin--color-red";
179
+ colorRedSubtle: "--skin--color-red-subtle";
180
+ colorYellowStrong: "--skin--color-yellow-strong";
181
+ colorYellow: "--skin--color-yellow";
182
+ colorYellowSubtle: "--skin--color-yellow-subtle";
183
+ colorGreenStrong: "--skin--color-green-strong";
184
+ colorGreen: "--skin--color-green";
185
+ colorGreenSubtle: "--skin--color-green-subtle";
186
+ colorBlueStrong: "--skin--color-blue-strong";
187
+ colorBlue: "--skin--color-blue";
188
+ colorBlueSubtle: "--skin--color-blue-subtle";
189
+ colorPurpleStrong: "--skin--color-purple-strong";
190
+ colorPurple: "--skin--color-purple";
191
+ colorPurpleSubtle: "--skin--color-purple-subtle";
192
+ backgroundColorRaised: "--skin--background-color-raised";
193
+ backgroundColorOverlay: "--skin--background-color-overlay";
194
+ backgroundColorSunken: "--skin--background-color-sunken";
195
+ backgroundColorBlanket: "--skin--background-color-blanket";
196
+ backgroundColorGlass: "--skin--background-color-glass";
197
+ backdropFilterGlass: "--skin--backdrop-filter-glass";
198
+ boxShadowRaised: "--skin--box-shadow-raised";
199
+ boxShadowOverlay: "--skin--box-shadow-overlay";
200
+ boxShadow: "--skin--box-shadow";
201
+ color: "--skin--color";
202
+ backgroundColor: "--skin--background-color";
203
+ colorSubtle: "--skin--color-subtle";
204
+ colorStrong: "--skin--color-strong";
205
+ colorNote: "--skin--color-note";
206
+ colorPass: "--skin--color-pass";
207
+ colorFlag: "--skin--color-flag";
208
+ colorWarn: "--skin--color-warn";
209
+ colorFail: "--skin--color-fail";
210
+ colorNoteStroke: "--skin--color-note-stroke";
211
+ colorPassStroke: "--skin--color-pass-stroke";
212
+ colorFlagStroke: "--skin--color-flag-stroke";
213
+ colorWarnStroke: "--skin--color-warn-stroke";
214
+ colorFailStroke: "--skin--color-fail-stroke";
215
+ colorLabel: "--skin--color-label";
216
+ colorPlaceholder: "--skin--color-placeholder";
217
+ colorEnabled: "--skin--color-enabled";
218
+ colorDisabled: "--skin--color-disabled";
219
+ colorLink: "--skin--color-link";
220
+ colorLinkHover: "--skin--color-link-hover";
221
+ colorHover: "--skin--color-hover";
222
+ colorPressed: "--skin--color-pressed";
223
+ colorSelected: "--skin--color-selected";
224
+ colorFocus: "--skin--color-focus";
225
+ colorOver: "--skin--color-over";
226
+ colorStrongOver: "--skin--color-strong-over";
227
+ backgroundColorEdit: "--skin--background-color-edit";
228
+ backgroundColorStripe: "--skin--background-color-stripe";
229
+ backgroundColorHover: "--skin--background-color-hover";
230
+ backgroundColorPressed: "--skin--background-color-pressed";
231
+ backgroundColorSelected: "--skin--background-color-selected";
232
+ backgroundColorHoverNeutral: "--skin--background-color-hover-neutral";
233
+ backgroundColorPressedNeutral: "--skin--background-color-pressed-neutral";
234
+ backgroundColorNote: "--skin--background-color-note";
235
+ backgroundColorPass: "--skin--background-color-pass";
236
+ backgroundColorFlag: "--skin--background-color-flag";
237
+ backgroundColorWarn: "--skin--background-color-warn";
238
+ backgroundColorFail: "--skin--background-color-fail";
239
+ borderStyle: "--skin--border-style";
240
+ borderColor: "--skin--border-color";
241
+ borderColorField: "--skin--border-color-field";
242
+ borderWidth: "--skin--border-width";
243
+ borderRadius025: "--skin--border-radius-025";
244
+ borderRadius050: "--skin--border-radius-050";
245
+ borderRadius075: "--skin--border-radius-075";
246
+ borderRadius100: "--skin--border-radius-100";
247
+ borderRadius: "--skin--border-radius";
248
+ outlineFocus: "--skin--outline-focus";
249
+ outlineInvalid: "--skin--outline-invalid";
250
+ strokeWidth: "--skin--stroke-width";
251
+ strokeWidthStrong: "--skin--stroke-width-strong";
252
+ scaling025: "--skin--scaling-025";
253
+ scaling050: "--skin--scaling-050";
254
+ scaling075: "--skin--scaling-075";
255
+ scaling090: "--skin--scaling-090";
256
+ scaling100: "--skin--scaling-100";
257
+ scaling110: "--skin--scaling-110";
258
+ scaling125: "--skin--scaling-125";
259
+ scaling150: "--skin--scaling-150";
260
+ scaling200: "--skin--scaling-200";
261
+ scaling250: "--skin--scaling-250";
262
+ spacing010: "--skin--spacing-010";
263
+ spacing025: "--skin--spacing-025";
264
+ spacing050: "--skin--spacing-050";
265
+ spacing075: "--skin--spacing-075";
266
+ spacing100: "--skin--spacing-100";
267
+ spacing150: "--skin--spacing-150";
268
+ spacing200: "--skin--spacing-200";
269
+ spacing250: "--skin--spacing-250";
270
+ padding: "--skin--padding";
271
+ fontFamily: "--skin--font-family";
272
+ fontFamilyHeading: "--skin--font-family-heading";
273
+ fontFamilyMono: "--skin--font-family-mono";
274
+ fontSize: "--skin--font-size";
275
+ fontSizeSmall: "--skin--font-size-small";
276
+ fontSizeLarge: "--skin--font-size-large";
277
+ fontSizeHeading: "--skin--font-size-heading";
278
+ lineHeight: "--skin--line-height";
279
+ lineHeightDisplay: "--skin--line-height-display";
280
+ letterSpacingHeading: "--skin--letter-spacing-heading";
281
+ letterSpacingCaps: "--skin--letter-spacing-caps";
282
+ textTransformHeading: "--skin--text-transform-heading";
283
+ textTransformCaps: "--skin--text-transform-caps";
284
+ inlineSizeProse: "--skin--inline-size-prose";
285
+ fontWeight: "--skin--font-weight";
286
+ fontWeightStrong: "--skin--font-weight-strong";
287
+ };
288
+ /**
289
+ * An inline style declaration.
290
+ *
291
+ * Assignable with no cast to the `style` prop of a rendering layer, a token override being a style like any other.
292
+ */
293
+ export type Style = Readonly<Record<string, string>>;
294
+ /**
295
+ * The custom property carrying the value of a design system token.
296
+ *
297
+ * As given by {@link skin}: what {@link css css.var} takes, and what a computed-style read is keyed by.
298
+ */
299
+ export type Property = typeof skin[Token];
300
+ /**
301
+ * The tokens assigned to an area, and what each is assigned.
302
+ *
303
+ * Every token is optional, so an override names the ones it restyles and leaves the rest at whatever the cascade
304
+ * already gives them. Each takes the {@link Value value} that token admits, be that a name off the ladder it belongs
305
+ * to or a CSS value of the shape it carries, so an editor offers the handful of names and keywords that belong where
306
+ * one is assigned: a colour offers colours, a text size the type and scaling ladders, a viewport switch `on` and `off`.
307
+ */
308
+ export type Tokens = {
309
+ readonly [K in Token]?: Value<K>;
310
+ };
311
+ /**
312
+ * The name of a design system token.
313
+ *
314
+ * Addresses a token in a {@link css} call, where a {@link Property custom property} is rejected.
315
+ */
316
+ export type Token = keyof typeof skin;
317
+ /**
318
+ * The value a design system token is assigned.
319
+ *
320
+ * Admits only what the token in hand can carry, as three alternatives, two named by types left out of this reference:
321
+ *
322
+ * - `Alias<K>` — the {@link Token token names} `K` may be set from, taken off the ladders it belongs to and no other:
323
+ * a colour offers colours, a surface fill the palette colours as well, classing an area or colouring it as an
324
+ * author chose, and a text size the type and scaling ladders and not the spacing one, though all are lengths.
325
+ * An alias stands for whatever the token it names carries, so `colorStrong: "colorSubtle"` assigns a reference to
326
+ * that token rather than the text of its name. A token on no ladder, a switch or a keyword, has no alias at all.
327
+ * - `Literal<K>` — the CSS values `K` takes written out, of the shape it is defined over: a colour where a colour
328
+ * goes, a length carrying a unit unless it is zero, a keyword token held to the words it names. A number is taken
329
+ * where the value is a scalar, sparing the caller a conversion, and a function wherever a value is computed, since
330
+ * what one resolves to is beyond the reach of a type.
331
+ * - `undefined` — assigns nothing, so a token is left at whatever the cascade already gives it, and a conditional
332
+ * override is expressed inline.
333
+ *
334
+ * An arbitrary string is taken only where CSS states no shape to hold a value to, as a font stack or a shorthand.
335
+ * Everywhere else a value of the wrong shape is rejected at the call site rather than assigned and left to resolve to
336
+ * nothing.
337
+ *
338
+ * @typeParam K The token being assigned; every token, and so every value any of them admits, where left out
339
+ */
340
+ export type Value<K extends Token = Token> = undefined | Alias<K> | Literal<K>;
341
+ export type { Palette, Ink, Fill, Type, Scaling, Spacing, Radius, Stroke, Tracking, Weight, Opacity, Layer, Timing, Easing, Shadow, Filter, Family, Breakpoint, Padding, Rounding, Lifting } from "./index.core.js";
342
+ /**
343
+ * Overrides design system tokens for a subtree.
344
+ *
345
+ * Assigns each named token its value, restyling the elements that read it and leaving the rest untouched:
346
+ *
347
+ * ```tsx
348
+ * <section style={css({ colorStrong: "#06C" })}>
349
+ * ```
350
+ *
351
+ * A value naming a token stands for whatever that token carries, so one token is set from another without spelling
352
+ * out the reference, and an editor offers the names that belong where it is assigned, a colour offering colours and a
353
+ * text size the type and scaling ladders:
354
+ *
355
+ * ```tsx
356
+ * <section style={css({ fontSize: "fontSizeLarge" })}>
357
+ * ```
358
+ *
359
+ * Anything else is a CSS value of the shape the token carries, so a colour where a length goes is rejected here rather
360
+ * than assigned and left to resolve to nothing. A number is converted to its CSS text form, sparing a scalar token
361
+ * the restatement as a string; a token mapped to `undefined` is left out, so a conditional override is expressed
362
+ * inline.
363
+ *
364
+ * The face, the size, the weight and the leading a page is written in are applied to the area as well as assigned to
365
+ * it, since the page states each of them once and nothing below reads them again; an area given one of the four is
366
+ * therefore written in it, rather than assigning a value nothing would consult. What an area holds inherits them as
367
+ * it inherits any other, so a size stated on an area compounds with a size stated on an area inside it, exactly as
368
+ * CSS has it. The text and background colours are applied the same way, so an area given either is painted in it.
369
+ *
370
+ * The box tokens, `padding`, `borderRadius` and `boxShadow`, are read by no rule at all, and are applied to the
371
+ * element they are assigned to alone, padding, rounding or lifting it without reaching what it holds:
372
+ *
373
+ * ```tsx
374
+ * <section style={css({ padding: "spacing100", borderRadius: "borderRadius050" })}>
375
+ * ```
376
+ *
377
+ * Reading a token where a CSS value is written by hand goes through {@link css css.var} instead, and tinting a
378
+ * surface with a colour rather than painting it in one goes through {@link css css.tint}, which this call accepts.
379
+ *
380
+ * @param tokens The value each token takes, keyed by {@link Token token name}
381
+ *
382
+ * @returns An immutable {@link Style style declaration} assigning the {@link Property custom property} of each token
383
+ * given a defined value in `tokens` its text form, or a reference to the token it names, and applying the CSS
384
+ * property as well for the typography and the colours the page carries its own defaults in, and for the box tokens
385
+ */
386
+ export declare const css: ((tokens: Tokens) => Style) & {
387
+ /**
388
+ * Reads a design system token.
389
+ *
390
+ * Gives the reference a CSS value takes a token through, so a consumer paints with the design system wherever
391
+ * a value is written by hand rather than by a rule: an inline style, an SVG presentation attribute, a length
392
+ * handed to a widget that takes one.
393
+ *
394
+ * ```tsx
395
+ * <span style={{ backgroundColor: css.var(skin.colorStrong) }}/>
396
+ * ```
397
+ *
398
+ * The reference resolves wherever it is read, so it carries whatever an app overrode and whichever colour
399
+ * scheme is in force, which a copy of the default value would not. Assigning a token for a subtree goes
400
+ * through {@link css} itself instead, and a consumer that cannot count on the stylesheet being loaded at all
401
+ * writes the reference by hand, naming in it the fallback it wants.
402
+ *
403
+ * @param property The {@link Property custom property} of the token to be read, as given by {@link skin}
404
+ *
405
+ * @returns A `var()` reference resolving to the value `property` carries on the element reading it
406
+ */
407
+ var(property: Property): string;
408
+ /**
409
+ * Washes a colour token out into a surface fill.
410
+ *
411
+ * Gives the value a surface takes to be tinted by a colour rather than painted in it: the columns of a board
412
+ * tinted along its flow from the heat scale, the lanes of a swimlane by type from the area classes. The
413
+ * colour is mixed into the sunken surface, so a low share keeps the area close to the page and the text it
414
+ * holds readable on the page colour, in either colour scheme, with no `color` of its own:
415
+ *
416
+ * ```tsx
417
+ * <Box css={{ backgroundColor: css.tint(skin.colorHeat030, 20) }}>
418
+ * ```
419
+ *
420
+ * The text an area holds still needs a `color` of its own wherever a higher share takes the fill far from
421
+ * the page. The value reads the sunken surface where it is assigned, so it is never assigned to
422
+ * `backgroundColorSunken` itself, which it would then be made of, leaving the fill to resolve to nothing.
423
+ *
424
+ * @param property The {@link Property custom property} of the colour to tint with, as given by {@link skin}
425
+ * @param share The share of colour in the mix, in percent: `0` leaves the bare sunken surface, `100` the colour
426
+ *
427
+ * @returns A `color-mix()` value carrying `share` percent of `property` into the sunken surface, resolving
428
+ * wherever it is read, so it follows whatever an app overrode and whichever colour scheme is in force
429
+ */
430
+ tint(property: (typeof skin)[Palette | Ink | Fill], share: number): `color-mix(${string})`;
431
+ };
432
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AA+C1E;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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G,IAAI,CAAC,SAAS,MAAM,GAAG,aAAa,MAAM,GAAG;CAOzF,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,184 @@
1
+ /*
2
+ * Copyright © 2023-2026 Metreeca srl
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { borders } from "./tokens/borders.js";
17
+ import { colors } from "./tokens/colors.js";
18
+ import { elevations } from "./tokens/elevations.js";
19
+ import { layers } from "./tokens/layers.js";
20
+ import { motions } from "./tokens/motions.js";
21
+ import { opacities } from "./tokens/opacities.js";
22
+ import { palettes } from "./tokens/palettes.js";
23
+ import { scalings } from "./tokens/scalings.js";
24
+ import { spacings } from "./tokens/spacings.js";
25
+ import { typography } from "./tokens/typography.js";
26
+ import { viewports } from "./tokens/viewports.js";
27
+ /**
28
+ * The CSS property a token is applied through as well as assigned, for a token no rule below the page reads.
29
+ *
30
+ * Every other token is read by a rule on the elements that take it, so assigning it anywhere is enough to restyle
31
+ * what stands below. A token listed here is read at most a single time, where the page sets its own defaults, and an
32
+ * element further down takes the property it inherits rather than looking the token up again. Assigning one of them to
33
+ * an area would therefore do nothing at all, which is the one outcome a consumer cannot be expected to predict from
34
+ * the name. Applying the property alongside the assignment makes the area behave as every other token already leads
35
+ * them to expect.
36
+ *
37
+ * A token joins the list on that condition alone, whatever it decides, and the entry names the property it is applied
38
+ * through: an inherited one carries an override down the subtree, as the typography and the colours do, while the box
39
+ * tokens name properties that do not inherit, so each shapes the element it is assigned to and nothing inside it.
40
+ */
41
+ const applied = {
42
+ fontFamily: "font-family",
43
+ fontSize: "font-size",
44
+ fontWeight: "font-weight",
45
+ lineHeight: "line-height",
46
+ color: "color",
47
+ backgroundColor: "background-color",
48
+ padding: "padding",
49
+ borderRadius: "border-radius",
50
+ boxShadow: "box-shadow"
51
+ };
52
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53
+ /**
54
+ * The custom property behind every design system token.
55
+ *
56
+ * Resolves each {@link Token token name} to the {@link Property custom property} carrying its value, which is what
57
+ * {@link css css.var} reads a token through and what a value taken outside the cascade is looked up by; assigning a
58
+ * token to a subtree goes through {@link css} instead. Gathers every token group, so a consumer names a token without
59
+ * knowing which one it belongs to.
60
+ */
61
+ export const skin = {
62
+ ...typography,
63
+ ...spacings,
64
+ ...scalings,
65
+ ...borders,
66
+ ...colors,
67
+ ...elevations,
68
+ ...palettes,
69
+ ...layers,
70
+ ...motions,
71
+ ...opacities,
72
+ ...viewports
73
+ };
74
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75
+ /**
76
+ * Overrides design system tokens for a subtree.
77
+ *
78
+ * Assigns each named token its value, restyling the elements that read it and leaving the rest untouched:
79
+ *
80
+ * ```tsx
81
+ * <section style={css({ colorStrong: "#06C" })}>
82
+ * ```
83
+ *
84
+ * A value naming a token stands for whatever that token carries, so one token is set from another without spelling
85
+ * out the reference, and an editor offers the names that belong where it is assigned, a colour offering colours and a
86
+ * text size the type and scaling ladders:
87
+ *
88
+ * ```tsx
89
+ * <section style={css({ fontSize: "fontSizeLarge" })}>
90
+ * ```
91
+ *
92
+ * Anything else is a CSS value of the shape the token carries, so a colour where a length goes is rejected here rather
93
+ * than assigned and left to resolve to nothing. A number is converted to its CSS text form, sparing a scalar token
94
+ * the restatement as a string; a token mapped to `undefined` is left out, so a conditional override is expressed
95
+ * inline.
96
+ *
97
+ * The face, the size, the weight and the leading a page is written in are applied to the area as well as assigned to
98
+ * it, since the page states each of them once and nothing below reads them again; an area given one of the four is
99
+ * therefore written in it, rather than assigning a value nothing would consult. What an area holds inherits them as
100
+ * it inherits any other, so a size stated on an area compounds with a size stated on an area inside it, exactly as
101
+ * CSS has it. The text and background colours are applied the same way, so an area given either is painted in it.
102
+ *
103
+ * The box tokens, `padding`, `borderRadius` and `boxShadow`, are read by no rule at all, and are applied to the
104
+ * element they are assigned to alone, padding, rounding or lifting it without reaching what it holds:
105
+ *
106
+ * ```tsx
107
+ * <section style={css({ padding: "spacing100", borderRadius: "borderRadius050" })}>
108
+ * ```
109
+ *
110
+ * Reading a token where a CSS value is written by hand goes through {@link css css.var} instead, and tinting a
111
+ * surface with a colour rather than painting it in one goes through {@link css css.tint}, which this call accepts.
112
+ *
113
+ * @param tokens The value each token takes, keyed by {@link Token token name}
114
+ *
115
+ * @returns An immutable {@link Style style declaration} assigning the {@link Property custom property} of each token
116
+ * given a defined value in `tokens` its text form, or a reference to the token it names, and applying the CSS
117
+ * property as well for the typography and the colours the page carries its own defaults in, and for the box tokens
118
+ */
119
+ export const css = Object.assign(function css(tokens) {
120
+ const properties = skin; // keyed by string, matching the entries below
121
+ return Object.fromEntries(Object.entries(tokens)
122
+ .filter(([, value]) => value !== undefined)
123
+ .flatMap(([token, value]) => {
124
+ const property = applied[token];
125
+ // a value naming a token stands for what that token carries; no CSS value is spelt as a token name,
126
+ // the names being camel-cased identifiers and CSS values keywords, numbers, colours and functions
127
+ const text = typeof value === "string" && value in properties
128
+ ? `var(${properties[value]})`
129
+ : String(value);
130
+ return property === undefined
131
+ ? [[properties[token], text]]
132
+ : [[properties[token], text], [property, text]];
133
+ }));
134
+ }, {
135
+ /**
136
+ * Reads a design system token.
137
+ *
138
+ * Gives the reference a CSS value takes a token through, so a consumer paints with the design system wherever
139
+ * a value is written by hand rather than by a rule: an inline style, an SVG presentation attribute, a length
140
+ * handed to a widget that takes one.
141
+ *
142
+ * ```tsx
143
+ * <span style={{ backgroundColor: css.var(skin.colorStrong) }}/>
144
+ * ```
145
+ *
146
+ * The reference resolves wherever it is read, so it carries whatever an app overrode and whichever colour
147
+ * scheme is in force, which a copy of the default value would not. Assigning a token for a subtree goes
148
+ * through {@link css} itself instead, and a consumer that cannot count on the stylesheet being loaded at all
149
+ * writes the reference by hand, naming in it the fallback it wants.
150
+ *
151
+ * @param property The {@link Property custom property} of the token to be read, as given by {@link skin}
152
+ *
153
+ * @returns A `var()` reference resolving to the value `property` carries on the element reading it
154
+ */
155
+ var(property) {
156
+ return `var(${property})`;
157
+ },
158
+ /**
159
+ * Washes a colour token out into a surface fill.
160
+ *
161
+ * Gives the value a surface takes to be tinted by a colour rather than painted in it: the columns of a board
162
+ * tinted along its flow from the heat scale, the lanes of a swimlane by type from the area classes. The
163
+ * colour is mixed into the sunken surface, so a low share keeps the area close to the page and the text it
164
+ * holds readable on the page colour, in either colour scheme, with no `color` of its own:
165
+ *
166
+ * ```tsx
167
+ * <Box css={{ backgroundColor: css.tint(skin.colorHeat030, 20) }}>
168
+ * ```
169
+ *
170
+ * The text an area holds still needs a `color` of its own wherever a higher share takes the fill far from
171
+ * the page. The value reads the sunken surface where it is assigned, so it is never assigned to
172
+ * `backgroundColorSunken` itself, which it would then be made of, leaving the fill to resolve to nothing.
173
+ *
174
+ * @param property The {@link Property custom property} of the colour to tint with, as given by {@link skin}
175
+ * @param share The share of colour in the mix, in percent: `0` leaves the bare sunken surface, `100` the colour
176
+ *
177
+ * @returns A `color-mix()` value carrying `share` percent of `property` into the sunken surface, resolving
178
+ * wherever it is read, so it follows whatever an app overrode and whichever colour scheme is in force
179
+ */
180
+ tint(property, share) {
181
+ return `color-mix(in oklab, var(${property}) ${share}%, var(${skin.backgroundColorSunken}))`;
182
+ }
183
+ });
184
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA8FH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5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