@rak200/ui 0.2.3 → 0.2.4

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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { UiButton, type ButtonVariant } from './button.js';
2
2
  export { UiField } from './field.js';
3
- export { tokens, defaults, tokenStyleSheet, type Token } from './tokens.js';
3
+ export { tokens, defaults, darkScheme, tokenStyleSheet, type Token } from './tokens.js';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { UiButton } from './button.js';
2
2
  export { UiField } from './field.js';
3
- export { tokens, defaults, tokenStyleSheet } from './tokens.js';
3
+ export { tokens, defaults, darkScheme, tokenStyleSheet } from './tokens.js';
4
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAc,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAc,MAAM,aAAa,CAAC"}
package/dist/tokens.d.ts CHANGED
@@ -20,9 +20,36 @@ export type Token = (typeof tokens)[number];
20
20
  * system's defaults are what a host sees before it has decided anything.
21
21
  */
22
22
  export declare const defaults: Readonly<Record<Token, string>>;
23
+ /**
24
+ * The grounds whose value differs when the page is rendered dark.
25
+ *
26
+ * **A scheme is not a theme, and conflating them is the mistake this shape exists to
27
+ * avoid.** A theme is a named set of decisions, selected with `data-ui-theme`; a scheme is
28
+ * the light or dark rendering of whichever theme is in force, selected with
29
+ * `color-scheme`. The two axes are independent, and a token carries both of its schemes in
30
+ * one value through `light-dark()`, so a theme is a handful of grounds rather than a
31
+ * parallel block per scheme plus a media query nobody writes correctly the first time.
32
+ *
33
+ * `Partial` is the type doing the work: it answers *which grounds vary by scheme* in the
34
+ * type system. `--ui-radius` does not vary and `--ui-color-surface` does, and folding both
35
+ * schemes into {@link defaults} as a single expression would make those two
36
+ * indistinguishable — and would hand a native emitter a CSS function to parse instead of a
37
+ * value to read.
38
+ *
39
+ * Only colours appear here, and that is a rule rather than a coincidence: `light-dark()`
40
+ * takes colours, so a dark value for `--ui-radius` would emit CSS the browser discards.
41
+ */
42
+ export declare const darkScheme: Readonly<Partial<Record<Token, string>>>;
23
43
  /**
24
44
  * The token defaults as a CSS rule, for a host that wants them without importing a
25
45
  * component. Returns the text of a `:root` block; a host inserts it however it prefers.
46
+ *
47
+ * **It declares `color-scheme` as well as the tokens, and that is deliberate.**
48
+ * `color-scheme` is a real property rather than a custom one, so it can never be a token —
49
+ * and leaving it to the host is a silent failure at the highest possible frequency: every
50
+ * host would have to remember, and forgetting means dark mode simply never happens, with
51
+ * no error anywhere to read. A host who wants something else — `only light`, say — governs
52
+ * the order this sheet is inserted in, which is a knob they already hold.
26
53
  */
27
54
  export declare function tokenStyleSheet(): string;
28
55
  //# sourceMappingURL=tokens.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,mEAAmE;AACnE,eAAO,MAAM,MAAM,0LAUT,CAAC;AAEX,kDAAkD;AAClD,MAAM,MAAM,KAAK,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAkBpD,CAAC;AAEF;;;GAGG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAIxC"}
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,mEAAmE;AACnE,eAAO,MAAM,MAAM,0LAUT,CAAC;AAEX,kDAAkD;AAClD,MAAM,MAAM,KAAK,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAkBpD,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAW/D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAUxC"}
package/dist/tokens.js CHANGED
@@ -46,12 +46,55 @@ export const defaults = {
46
46
  '--ui-space': '0.5rem',
47
47
  '--ui-font': 'system-ui, sans-serif',
48
48
  };
49
+ /**
50
+ * The grounds whose value differs when the page is rendered dark.
51
+ *
52
+ * **A scheme is not a theme, and conflating them is the mistake this shape exists to
53
+ * avoid.** A theme is a named set of decisions, selected with `data-ui-theme`; a scheme is
54
+ * the light or dark rendering of whichever theme is in force, selected with
55
+ * `color-scheme`. The two axes are independent, and a token carries both of its schemes in
56
+ * one value through `light-dark()`, so a theme is a handful of grounds rather than a
57
+ * parallel block per scheme plus a media query nobody writes correctly the first time.
58
+ *
59
+ * `Partial` is the type doing the work: it answers *which grounds vary by scheme* in the
60
+ * type system. `--ui-radius` does not vary and `--ui-color-surface` does, and folding both
61
+ * schemes into {@link defaults} as a single expression would make those two
62
+ * indistinguishable — and would hand a native emitter a CSS function to parse instead of a
63
+ * value to read.
64
+ *
65
+ * Only colours appear here, and that is a rule rather than a coincidence: `light-dark()`
66
+ * takes colours, so a dark value for `--ui-radius` would emit CSS the browser discards.
67
+ */
68
+ export const darkScheme = {
69
+ // Blue-400 over the dark surface rather than blue-600, which is legible on white and
70
+ // muddy on charcoal. Its contrast pair is inverted with it: dark text on a light
71
+ // accent is what reads at this end.
72
+ '--ui-color-accent': '#60a5fa',
73
+ '--ui-color-accent-contrast': '#111827',
74
+ '--ui-color-surface': '#111827',
75
+ '--ui-color-text': '#e5e7eb',
76
+ // Red-700 is 2.74:1 on the dark surface — under the 4.5:1 floor for text, and error
77
+ // text is the one thing in this set that must never be hard to read. Red-400 is 6.41.
78
+ '--ui-color-danger': '#f87171',
79
+ };
49
80
  /**
50
81
  * The token defaults as a CSS rule, for a host that wants them without importing a
51
82
  * component. Returns the text of a `:root` block; a host inserts it however it prefers.
83
+ *
84
+ * **It declares `color-scheme` as well as the tokens, and that is deliberate.**
85
+ * `color-scheme` is a real property rather than a custom one, so it can never be a token —
86
+ * and leaving it to the host is a silent failure at the highest possible frequency: every
87
+ * host would have to remember, and forgetting means dark mode simply never happens, with
88
+ * no error anywhere to read. A host who wants something else — `only light`, say — governs
89
+ * the order this sheet is inserted in, which is a knob they already hold.
52
90
  */
53
91
  export function tokenStyleSheet() {
54
- const body = tokens.map((token) => ` ${token}: ${defaults[token]};`).join('\n');
55
- return `:root {\n${body}\n}`;
92
+ const body = tokens
93
+ .map((token) => {
94
+ const dark = darkScheme[token];
95
+ return ` ${token}: ${dark === undefined ? defaults[token] : `light-dark(${defaults[token]}, ${dark})`};`;
96
+ })
97
+ .join('\n');
98
+ return `:root {\n color-scheme: light dark;\n${body}\n}`;
56
99
  }
57
100
  //# sourceMappingURL=tokens.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,mEAAmE;AACnE,MAAM,CAAC,MAAM,MAAM,GAAG;IAClB,mBAAmB;IACnB,4BAA4B;IAC5B,oBAAoB;IACpB,iBAAiB;IACjB,kBAAkB;IAClB,mBAAmB;IACnB,aAAa;IACb,YAAY;IACZ,WAAW;CACL,CAAC;AAKX;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAoC;IACrD,mBAAmB,EAAE,SAAS;IAC9B,4BAA4B,EAAE,SAAS;IACvC,oBAAoB,EAAE,SAAS;IAC/B,iBAAiB,EAAE,SAAS;IAC5B,mFAAmF;IACnF,qFAAqF;IACrF,gFAAgF;IAChF,mFAAmF;IACnF,iFAAiF;IACjF,oFAAoF;IACpF,iFAAiF;IACjF,4BAA4B;IAC5B,kBAAkB,EAAE,SAAS;IAC7B,mBAAmB,EAAE,SAAS;IAC9B,aAAa,EAAE,UAAU;IACzB,YAAY,EAAE,QAAQ;IACtB,WAAW,EAAE,uBAAuB;CACvC,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC3B,MAAM,IAAI,GAA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IAC3B,MAAM,IAAI,GAAG,MAAM;SACd,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACX,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QAE/B,OAAO,KAAK,KAAK,KAAK,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,GAAG,CAAC;IAC9G,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEhB,OAAO,yCAAyC,IAAI,KAAK,CAAC;AAC9D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rak200/ui",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Host-agnostic custom-element UI components for the rak200 ecosystem",
5
5
  "license": "MIT",
6
6
  "author": "rak200 <rak.ricardo@windowslive.com>",