@celestia-island/hikari 0.55.483 → 0.55.484

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.
@@ -0,0 +1 @@
1
+ export declare function buildThemeVarsCss(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celestia-island/hikari",
3
- "version": "0.55.483",
3
+ "version": "0.55.484",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
@@ -0,0 +1,117 @@
1
+ /* GENERATED by themeVarsCss.contract.test.ts (REGEN_THEME_VARS=1) —
2
+ * do not edit by hand. Source: the stock `default` preset in
3
+ * presets.ts; the regen command is in the contract test doc block. */
4
+ html[data-mode="dark"] {
5
+ --color-primary: 136 192 208;
6
+ --color-on-primary: 0 0 0;
7
+ --color-on-solid-text: 46 52 64;
8
+ --color-on-solid-icon: 46 52 64;
9
+ --color-on-solid: 46 52 64;
10
+ --color-on-danger: 255 255 255;
11
+ --color-on-success: 255 255 255;
12
+ --color-on-warning: 255 255 255;
13
+ --color-on-info: 255 255 255;
14
+ --color-secondary: 143 188 187;
15
+ --color-accent: 94 129 172;
16
+ --color-text: 247 249 252;
17
+ --color-text-secondary: 230 232 234;
18
+ --color-text-tertiary: 214 215 216;
19
+ --color-muted: 180 180 180;
20
+ --color-border: 128 128 128;
21
+ --color-focused-border: 136 192 208;
22
+ --color-background: 22 27 38;
23
+ --color-surface: 34 40 54;
24
+ --color-selected-bg: 70 70 85;
25
+ --color-selected-text: 248 248 250;
26
+ --color-status-bar-bg: 34 40 54;
27
+ --color-success: 31 101 48;
28
+ --color-error: 166 41 55;
29
+ --color-warning: 137 72 0;
30
+ --color-info: 0 98 116;
31
+ --hi-color-primary: rgb(var(--color-primary));
32
+ --hi-color-secondary: rgb(var(--color-secondary));
33
+ --hi-color-surface: rgb(var(--color-surface));
34
+ --hi-color-background: rgb(var(--color-background));
35
+ --hi-color-border: rgb(var(--color-border) / 15%);
36
+ --hi-color-text-primary: rgb(var(--color-text));
37
+ --hi-color-text-secondary: rgb(var(--color-text-secondary));
38
+ --hi-color-muted: rgb(var(--color-muted));
39
+ --hi-color-on-primary: rgb(var(--color-on-primary));
40
+ --hi-color-text-on-primary: rgb(var(--color-on-primary));
41
+ --hi-color-text-on-solid: rgb(var(--color-on-solid-text, 255 255 255));
42
+ --hi-color-icon-on-solid: rgb(var(--color-on-solid-icon, 255 255 255));
43
+ --hi-color-success: rgb(var(--color-success));
44
+ --hi-color-error: rgb(var(--color-error));
45
+ --hi-color-warning: rgb(var(--color-warning));
46
+ --hi-color-info: rgb(var(--color-info));
47
+ --hi-color-text-on-danger: rgb(var(--color-on-danger));
48
+ --hi-color-text-on-success: rgb(var(--color-on-success));
49
+ --hi-color-text-on-warning: rgb(var(--color-on-warning));
50
+ --hi-color-text-on-info: rgb(var(--color-on-info));
51
+ --hi-color-success-fg: rgb(94 162 105);
52
+ --hi-color-danger-fg: rgb(233 104 109);
53
+ --hi-color-warning-fg: rgb(200 130 73);
54
+ --hi-color-info-fg: rgb(81 158 177);
55
+ --hi-color-bg-subtle: rgb(var(--color-surface) / 0.5);
56
+ --hi-color-bg-elevated: rgb(var(--color-surface));
57
+ --hi-color-bg-container: rgb(var(--color-surface));
58
+ --hi-color-bg-canvas: rgb(var(--color-background));
59
+ --hi-secondary-bg: rgb(var(--color-surface) / 0.5);
60
+ }
61
+ html[data-mode="light"] {
62
+ --color-primary: 214 51 132;
63
+ --color-on-primary: 255 255 255;
64
+ --color-on-solid-text: 255 255 255;
65
+ --color-on-solid-icon: 255 255 255;
66
+ --color-on-solid: 255 255 255;
67
+ --color-on-danger: 255 255 255;
68
+ --color-on-success: 255 255 255;
69
+ --color-on-warning: 255 255 255;
70
+ --color-on-info: 255 255 255;
71
+ --color-secondary: 156 106 222;
72
+ --color-accent: 230 167 0;
73
+ --color-text: 30 30 30;
74
+ --color-text-secondary: 43 43 43;
75
+ --color-text-tertiary: 55 55 55;
76
+ --color-muted: 80 80 80;
77
+ --color-border: 128 128 128;
78
+ --color-focused-border: 214 51 132;
79
+ --color-background: 245 245 240;
80
+ --color-surface: 255 255 255;
81
+ --color-selected-bg: 200 200 205;
82
+ --color-selected-text: 40 40 45;
83
+ --color-status-bar-bg: 230 230 225;
84
+ --color-success: 31 101 48;
85
+ --color-error: 166 41 55;
86
+ --color-warning: 137 72 0;
87
+ --color-info: 0 98 116;
88
+ --hi-color-primary: rgb(var(--color-primary));
89
+ --hi-color-secondary: rgb(var(--color-secondary));
90
+ --hi-color-surface: rgb(var(--color-surface));
91
+ --hi-color-background: rgb(var(--color-background));
92
+ --hi-color-border: rgb(var(--color-border) / 15%);
93
+ --hi-color-text-primary: rgb(var(--color-text));
94
+ --hi-color-text-secondary: rgb(var(--color-text-secondary));
95
+ --hi-color-muted: rgb(var(--color-muted));
96
+ --hi-color-on-primary: rgb(var(--color-on-primary));
97
+ --hi-color-text-on-primary: rgb(var(--color-on-primary));
98
+ --hi-color-text-on-solid: rgb(var(--color-on-solid-text, 255 255 255));
99
+ --hi-color-icon-on-solid: rgb(var(--color-on-solid-icon, 255 255 255));
100
+ --hi-color-success: rgb(var(--color-success));
101
+ --hi-color-error: rgb(var(--color-error));
102
+ --hi-color-warning: rgb(var(--color-warning));
103
+ --hi-color-info: rgb(var(--color-info));
104
+ --hi-color-text-on-danger: rgb(var(--color-on-danger));
105
+ --hi-color-text-on-success: rgb(var(--color-on-success));
106
+ --hi-color-text-on-warning: rgb(var(--color-on-warning));
107
+ --hi-color-text-on-info: rgb(var(--color-on-info));
108
+ --hi-color-success-fg: rgb(31 101 48);
109
+ --hi-color-danger-fg: rgb(166 41 55);
110
+ --hi-color-warning-fg: rgb(137 72 0);
111
+ --hi-color-info-fg: rgb(0 98 116);
112
+ --hi-color-bg-subtle: rgb(var(--color-surface) / 0.5);
113
+ --hi-color-bg-elevated: rgb(var(--color-surface));
114
+ --hi-color-bg-container: rgb(var(--color-surface));
115
+ --hi-color-bg-canvas: rgb(var(--color-background));
116
+ --hi-secondary-bg: rgb(var(--color-surface) / 0.5);
117
+ }
@@ -0,0 +1,65 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { describe, expect, it } from "vitest";
5
+
6
+ import { buildThemeVarsCss } from "./themeVarsCss";
7
+
8
+ /**
9
+ * Drift contract for the PRE-RENDERED theme CSS (hikari#1546): the checked
10
+ * -in `src/styles/theme-vars.css` must be byte-identical to what
11
+ * `buildThemeVarsCss()` composes from the live preset table. When the
12
+ * table changes (new slot, adjusted color), the CSS MUST be regenerated in
13
+ * the same PR — otherwise a returning visitor's pre-hydration paint uses
14
+ * stale colors and the runtime injection visibly snaps them on mount.
15
+ *
16
+ * Regeneration (the preset table is TS, so the toolchain that can execute
17
+ * it IS this runner — the vue-mirror discipline):
18
+ *
19
+ * REGEN_THEME_VARS=1 \
20
+ * node_modules/.bin/vitest run src/theme/themeVarsCss.contract.test.ts
21
+ *
22
+ * The test executes the same composition any future generator would, so
23
+ * the writer and the checker cannot disagree.
24
+ */
25
+ const here = dirname(fileURLToPath(import.meta.url));
26
+ const cssPath = join(here, "..", "styles", "theme-vars.css");
27
+
28
+ describe("pre-rendered theme vars CSS (hikari#1546)", () => {
29
+ const css = buildThemeVarsCss();
30
+
31
+ it("matches the composition of the live preset table", () => {
32
+ const checkedIn = readFileSync(cssPath, "utf8");
33
+ if (checkedIn === css) return;
34
+ // Drift: the preset table moved without a regen. Rewrite ONLY under the
35
+ // explicit env (a stray REGEN_THEME_VARS in a normal run must not touch
36
+ // the worktree silently), then re-read for a real assertion — the write
37
+ // happens AFTER the drift is established, never before the compare.
38
+ // MUT:mut-regen-write-order — reverting to write-before-compare silences
39
+ // this test entirely (the round-1 review footgun).
40
+ if (process.env.REGEN_THEME_VARS === "1") {
41
+ writeFileSync(cssPath, css);
42
+ expect(readFileSync(cssPath, "utf8"), "regen wrote the composition").toBe(css);
43
+ console.log(`REGEN: rewrote drifted ${cssPath} (${css.length} bytes)`);
44
+ return;
45
+ }
46
+ expect(checkedIn).toBe(css);
47
+ });
48
+
49
+ it("covers both modes with the core color tokens", () => {
50
+ expect(css).toContain('html[data-mode="dark"]');
51
+ expect(css).toContain('html[data-mode="light"]');
52
+ // The slots with no per-component CSS fallback — a missing one leaves
53
+ // the unthemed flash hikari#1546 describes, so each is load-bearing.
54
+ for (const slot of [
55
+ "--color-primary",
56
+ "--color-text",
57
+ "--color-background",
58
+ "--color-surface",
59
+ "--color-muted",
60
+ "--color-border",
61
+ ]) {
62
+ expect(css, `${slot} must be pre-rendered`).toContain(`${slot}:`);
63
+ }
64
+ });
65
+ });
@@ -0,0 +1,56 @@
1
+ import { themePresets, tokensToCSSVars, getThemeTokens } from "./presets";
2
+
3
+ /**
4
+ * The PRE-RENDERED static form of the stock theme table (hikari#1546).
5
+ *
6
+ * `applyTheme()` injects the whole cssvar set from JS, which is why a
7
+ * phone's first paint used to flash the unthemed default: no JS, no vars.
8
+ * This module composes the SAME `tokensToCSSVars` output the runtime uses
9
+ * into plain CSS blocks keyed on the `data-mode` attribute — the SSR
10
+ * template ships it in `<head>`, and a tiny inline bootstrap only sets
11
+ * `data-theme`/`data-mode` (attribute writes, no computation) before body
12
+ * paint. The cascade picks the block instantly.
13
+ *
14
+ * Selectors are mode-keyed and deliberately NOT theme-keyed: a stored
15
+ * CUSTOM theme id cannot be pre-rendered (user-authored, lives in
16
+ * localStorage), so pre-hydration those users see the stock colors in the
17
+ * right MODE — strictly better than the previous unthemed flash — and
18
+ * `applyTheme()` replaces them the moment the bundle lands. Override
19
+ * mechanics: the runtime writes a managed `<style data-hikari-theme-vars>`
20
+ * block whose selector (`html:root`, 0-1-1) TIES with these `html[data-mode]`
21
+ * blocks — the runtime wins by head ORDER (its block is appended after the
22
+ * SSR sheet), so the static sheet must stay in the SSR head; a late/async
23
+ * -loaded copy would re-tie and could snap the theme back.
24
+ *
25
+ * Phase 2 (de-Vue): the table itself moves to the Rust palette crate
26
+ * (tairitsu lane) and this module consumes generated JSON — the CSS form
27
+ * and the bootstrap contract stay exactly as they are here.
28
+ *
29
+ * Group tokens (shape/radius) are intentionally NOT included: every
30
+ * component reads them with its own CSS fallback (e.g.
31
+ * `var(--hk-radius-sm, 4px)` in HkSkeleton, `var(--hk-z-*)`,
32
+ * `var(--hk-picker-*)`), so the pre-hydration window degrades to identical
33
+ * geometry, and the runtime emission covers them anyway.
34
+ */
35
+ const MODES = ["dark", "light"] as const;
36
+
37
+ export function buildThemeVarsCss(): string {
38
+ const preset = themePresets.default;
39
+ if (!preset) return "/* stock preset table is empty — nothing to pre-render */\n";
40
+ const chunks: string[] = [
41
+ "/* GENERATED by themeVarsCss.contract.test.ts (REGEN_THEME_VARS=1) —",
42
+ " * do not edit by hand. Source: the stock `default` preset in",
43
+ " * presets.ts; the regen command is in the contract test doc block. */",
44
+ ];
45
+ for (const mode of MODES) {
46
+ const tokens = getThemeTokens("default", mode);
47
+ if (!tokens) continue;
48
+ const vars = tokensToCSSVars(tokens);
49
+ chunks.push(`html[data-mode="${mode}"] {`);
50
+ for (const name of Object.keys(vars)) {
51
+ chunks.push(` ${name}: ${vars[name]};`);
52
+ }
53
+ chunks.push("}");
54
+ }
55
+ return chunks.join("\n") + "\n";
56
+ }