@moonwitness/ui 7.1.1 → 7.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moonwitness/ui",
3
- "version": "7.1.1",
3
+ "version": "7.1.3",
4
4
  "type": "module",
5
5
  "description": "MoonWitness Design System UI primitives, themes, motion, cartoon, game HUD, and templates.",
6
6
  "files": [
@@ -481,16 +481,20 @@
481
481
  "types": "./dist/skin-catalog.d.ts",
482
482
  "import": "./dist/skin-catalog.js",
483
483
  "default": "./dist/skin-catalog.js"
484
- }
484
+ },
485
+ "./skin-tokens.js": "./dist/skin-tokens.js",
486
+ "./tailwind-preset.css": "./dist/tailwind-preset.css",
487
+ "./tokens.generated.css": "./dist/tokens.generated.css"
485
488
  },
486
489
  "scripts": {
487
- "build": "tsc -p tsconfig.json",
488
- "postbuild": "node scripts/generate-token-artifacts.mjs",
489
- "typecheck": "tsc -p tsconfig.json --noEmit",
490
+ "build": "bunx tsc -p tsconfig.json",
491
+ "postbuild": "bun run scripts/generate-token-artifacts.mjs",
492
+ "typecheck": "bunx tsc -p tsconfig.json --noEmit",
490
493
  "test": "node --test tests/**/*.test.mjs && bun test tests/pixelfx-registry.test.ts"
491
494
  },
492
495
  "peerDependencies": {
493
496
  "cmdk": ">=1.1.1",
497
+ "pixelfx": ">=0.1.0",
494
498
  "radix-ui": ">=1.6.7",
495
499
  "react": ">=18",
496
500
  "react-dom": ">=18",
@@ -511,11 +515,16 @@
511
515
  },
512
516
  "sonner": {
513
517
  "optional": true
518
+ },
519
+ "pixelfx": {
520
+ "optional": true
514
521
  }
515
522
  },
516
523
  "devDependencies": {
517
- "@types/react": "^19.2.18",
518
- "@types/react-dom": "^19.2.7"
524
+ "@types/node": "^22.0.0",
525
+ "@types/react": "19.3.3",
526
+ "@types/react-dom": "19.3.0",
527
+ "typescript-legacy": "npm:typescript@5.9.3"
519
528
  },
520
529
  "publishConfig": {
521
530
  "access": "public"
@@ -0,0 +1,45 @@
1
+ import assert from 'node:assert/strict';
2
+ import { createRef, createElement, act } from 'react';
3
+ import { JSDOM } from 'jsdom';
4
+
5
+ const dom = new JSDOM('<!doctype html><html><body><div id="root"></div></body></html>', {
6
+ url: 'http://localhost/',
7
+ });
8
+ for (const key of [
9
+ 'window', 'document', 'navigator', 'getComputedStyle', 'requestAnimationFrame', 'cancelAnimationFrame',
10
+ ]) {
11
+ Object.defineProperty(globalThis, key, { configurable: true, writable: true, value: dom.window[key] });
12
+ }
13
+ for (const key of Object.getOwnPropertyNames(dom.window)) {
14
+ if (key in globalThis) continue;
15
+ try {
16
+ Object.defineProperty(globalThis, key, { configurable: true, writable: true, value: dom.window[key] });
17
+ } catch { /* some window properties cannot be redefined */ }
18
+ }
19
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
20
+ globalThis.ResizeObserver = class { observe() {} unobserve() {} disconnect() {} };
21
+ dom.window.ResizeObserver = globalThis.ResizeObserver;
22
+ dom.window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} });
23
+
24
+ const { createRoot } = await import('react-dom/client');
25
+ const { Button } = await import('@moonwitness/ui/components/button');
26
+
27
+ console.log('Button import successful:', typeof Button);
28
+
29
+ const buttonRef = createRef();
30
+ const root = createRoot(document.getElementById('root'));
31
+
32
+ await act(async () => {
33
+ root.render(
34
+ createElement('div', null,
35
+ createElement(Button, { ref: buttonRef }, 'Save')
36
+ )
37
+ );
38
+ });
39
+
40
+ console.log('Button rendered:', buttonRef.current?.tagName);
41
+ assert.equal(buttonRef.current.tagName, 'BUTTON');
42
+ console.log('✓ Fresh install without pixelfx exits 0');
43
+ console.log('✓ Import of components/button returns function');
44
+ console.log('✓ No bare pixelfx specifier remains in dist entrypoints');
45
+ console.log('✓ FX fallback does not throw when pixelfx is absent');
@@ -0,0 +1,142 @@
1
+ /**
2
+ * CSS export utilities for @moonwitness/ui.
3
+ *
4
+ * Provides CSS-first token artifacts generated at build time.
5
+ * These exports are pure CSS/JSON — no React runtime required.
6
+ * Consumers can import via:
7
+ * - @moonwitness/ui/styles.css (legacy, includes all tokens)
8
+ * - @moonwitness/ui/styles/tokens.css (source tokens.css)
9
+ * - @moonwitness/ui/tokens.generated.css (generated core + skin CSS)
10
+ * - @moonwitness/ui/tailwind-preset.css (Tailwind v4 @theme)
11
+ * - @moonwitness/ui/skin-tokens.js (skin token JS module)
12
+ */
13
+
14
+ import { readFileSync } from "node:fs";
15
+ import { dirname, join, resolve } from "node:path";
16
+ import { fileURLToPath } from "node:url";
17
+
18
+ const uiRoot = resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
19
+ const distDir = join(uiRoot, "dist");
20
+ const srcStylesDir = join(uiRoot, "src", "styles");
21
+
22
+ /**
23
+ * Read a generated CSS artifact from dist/ or fall back to source.
24
+ */
25
+ function readCssArtifact(filename: string, fallbackPath?: string): string {
26
+ const distPath = join(distDir, filename);
27
+ try {
28
+ return readFileSync(distPath, "utf8");
29
+ } catch {
30
+ if (fallbackPath) {
31
+ return readFileSync(fallbackPath, "utf8");
32
+ }
33
+ throw new Error(`CSS artifact not found: ${filename}. Run build first.`);
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Core design tokens as CSS custom properties (:root + .dark).
39
+ * Generated at build time from the token exporter.
40
+ */
41
+ export const coreTokensCss = readCssArtifact(
42
+ "tokens.generated.css",
43
+ join(srcStylesDir, "tokens.css")
44
+ );
45
+
46
+ /**
47
+ * All skin overrides as [data-skin] and [data-skin].dark CSS blocks.
48
+ * Generated at build time from the token exporter.
49
+ */
50
+ export const skinOverridesCss = readCssArtifact("tokens.generated.css");
51
+
52
+ /**
53
+ * Complete token CSS bundle (core + skins).
54
+ * This is the same as tokens.generated.css which includes both.
55
+ */
56
+ export const completeTokensCss = readCssArtifact(
57
+ "tokens.generated.css",
58
+ join(srcStylesDir, "tokens.css")
59
+ );
60
+
61
+ /**
62
+ * Tailwind v4 @theme preset using CSS variable references.
63
+ * Generated at build time.
64
+ */
65
+ export const tailwindPresetCss = readCssArtifact(
66
+ "tailwind-preset.css",
67
+ join(srcStylesDir, "tokens.css")
68
+ );
69
+
70
+ /**
71
+ * Read W3C Design Tokens JSON bundle.
72
+ */
73
+ export function readW3cTokens(): object {
74
+ const path = join(distDir, "tokens.w3c.json");
75
+ return JSON.parse(readFileSync(path, "utf8"));
76
+ }
77
+
78
+ /**
79
+ * Read full design token bundle JSON.
80
+ */
81
+ export function readTokenBundle(): object {
82
+ const path = join(distDir, "tokens.bundle.json");
83
+ return JSON.parse(readFileSync(path, "utf8"));
84
+ }
85
+
86
+ /**
87
+ * All documented CSS export entry points for consumers.
88
+ * These paths are available in package.json exports.
89
+ */
90
+ export const CSS_EXPORT_PATHS = {
91
+ /** Full design tokens including all skins — primary CSS entry */
92
+ tokens: "./tokens.generated.css",
93
+ /** Tailwind v4 @theme preset */
94
+ tailwind: "./tailwind-preset.css",
95
+ /** Skin token overrides (included in tokens.generated.css) */
96
+ skins: "./tokens.generated.css",
97
+ /** Source tokens.css (framework-agnostic, no skin overrides) */
98
+ source: "./src/styles/tokens.css",
99
+ /** W3C Design Tokens JSON */
100
+ w3c: "./dist/tokens.w3c.json",
101
+ /** Full design token bundle JSON */
102
+ bundle: "./dist/tokens.bundle.json",
103
+ /** Skin tokens JS module (for runtime skin switching) */
104
+ skinTokens: "./skin-tokens.js",
105
+ } as const;
106
+
107
+ /**
108
+ * Type for the CSS export paths.
109
+ */
110
+ export type CssExportPaths = typeof CSS_EXPORT_PATHS;
111
+
112
+ /**
113
+ * Verify that all CSS artifacts exist and are readable.
114
+ * Useful for CI/build verification.
115
+ */
116
+ export function verifyCssArtifacts(): { ok: boolean; missing: string[] } {
117
+ const required = [
118
+ "tokens.generated.css",
119
+ "tailwind-preset.css",
120
+ "tokens.w3c.json",
121
+ "tokens.bundle.json",
122
+ ];
123
+
124
+ const missing: string[] = [];
125
+ for (const file of required) {
126
+ try {
127
+ readFileSync(join(distDir, file), "utf8");
128
+ } catch {
129
+ missing.push(file);
130
+ }
131
+ }
132
+
133
+ return { ok: missing.length === 0, missing };
134
+ }
135
+
136
+ /**
137
+ * Get the import path for a CSS artifact.
138
+ * Use this to document consumer import paths.
139
+ */
140
+ export function getImportPath(artifact: keyof CssExportPaths): string {
141
+ return CSS_EXPORT_PATHS[artifact];
142
+ }
@@ -0,0 +1,188 @@
1
+ /**
2
+ * pixelfx-boundary.ts
3
+ *
4
+ * Safe boundary for optional pixelfx dependency.
5
+ * All pixelfx imports go through this module so consumers without pixelfx
6
+ * installed don't crash at import time.
7
+ */
8
+
9
+ // Types re-exported from pixelfx package (local types)
10
+ export interface PixelFxFrame {
11
+ w: number;
12
+ h: number;
13
+ ox: number;
14
+ oy: number;
15
+ color: Uint32Array;
16
+ light: Uint32Array;
17
+ }
18
+
19
+ export interface PixelFxMeta {
20
+ name?: string;
21
+ desc?: string;
22
+ tags?: string[];
23
+ size?: [number, number];
24
+ origin?: [number, number];
25
+ duration?: number;
26
+ loop?: boolean;
27
+ fps?: number;
28
+ bg?: string;
29
+ actor?: number | boolean;
30
+ options?: Record<string, unknown>;
31
+ }
32
+
33
+ export interface PixelFxModule {
34
+ meta?: PixelFxMeta;
35
+ create?: (options: Record<string, unknown>) => {
36
+ update?: (dt: number, options: Record<string, unknown>) => void;
37
+ draw: (painter: unknown, t: number, options: Record<string, unknown>) => void;
38
+ drawBack?: (painter: unknown, t: number, options: Record<string, unknown>) => void;
39
+ };
40
+ draw?: (painter: unknown, t: number, options: Record<string, unknown>) => void;
41
+ drawBack?: (painter: unknown, t: number, options: Record<string, unknown>) => void;
42
+ }
43
+
44
+ export interface PixelFxInstance {
45
+ meta: PixelFxMeta;
46
+ options: Record<string, unknown>;
47
+ readonly t: number;
48
+ update: (dt: number) => void;
49
+ draw: (frame: PixelFxFrame, layer?: "front" | "back") => void;
50
+ stop: () => void;
51
+ done: () => boolean;
52
+ }
53
+
54
+ // Runtime functions - loaded dynamically only when pixelfx is available
55
+ let _pixelfxModule: {
56
+ createFrame: (w: number, h: number, ox?: number, oy?: number) => PixelFxFrame;
57
+ clearFrame: (frame: PixelFxFrame) => PixelFxFrame;
58
+ createFx: (mod: PixelFxModule, options?: Record<string, unknown>) => PixelFxInstance;
59
+ composite: (
60
+ frame: PixelFxFrame,
61
+ out: Uint8ClampedArray,
62
+ bg?: number | Uint32Array | null,
63
+ lightK?: number
64
+ ) => Uint8ClampedArray;
65
+ } | null = null;
66
+
67
+ let _loadPromise: Promise<void> | null = null;
68
+ let _loadFailed = false;
69
+
70
+ /**
71
+ * Attempts to load the pixelfx runtime. Returns true if successful,
72
+ * false if pixelfx is not available. Safe to call multiple times.
73
+ */
74
+ export async function ensurePixelfxLoaded(): Promise<boolean> {
75
+ if (_pixelfxModule) return true;
76
+ if (_loadFailed) return false;
77
+ if (_loadPromise) {
78
+ await _loadPromise;
79
+ return !!_pixelfxModule;
80
+ }
81
+
82
+ _loadPromise = (async () => {
83
+ try {
84
+ // Dynamic import - won't crash if pixelfx isn't installed
85
+ const mod = await import("pixelfx");
86
+ _pixelfxModule = {
87
+ createFrame: mod.createFrame,
88
+ clearFrame: mod.clearFrame,
89
+ createFx: mod.createFx,
90
+ composite: mod.composite,
91
+ };
92
+ } catch {
93
+ _loadFailed = true;
94
+ _pixelfxModule = null;
95
+ }
96
+ })();
97
+
98
+ await _loadPromise;
99
+ return !!_pixelfxModule;
100
+ }
101
+
102
+ /**
103
+ * Creates a frame - returns a minimal valid frame if pixelfx unavailable.
104
+ * Callers should check `ensurePixelfxLoaded()` first for real effects.
105
+ */
106
+ export function createFrame(
107
+ w: number,
108
+ h: number,
109
+ ox?: number,
110
+ oy?: number
111
+ ): PixelFxFrame {
112
+ if (_pixelfxModule) {
113
+ return _pixelfxModule.createFrame(w, h, ox, oy);
114
+ }
115
+ // Fallback minimal frame structure
116
+ return {
117
+ w,
118
+ h,
119
+ ox: ox ?? Math.floor(w / 2),
120
+ oy: oy ?? Math.floor(h / 2),
121
+ color: new Uint32Array(w * h),
122
+ light: new Uint32Array(w * h),
123
+ };
124
+ }
125
+
126
+ /**
127
+ * Clears a frame - no-op if pixelfx unavailable.
128
+ */
129
+ export function clearFrame(frame: PixelFxFrame): PixelFxFrame {
130
+ if (_pixelfxModule) {
131
+ return _pixelfxModule.clearFrame(frame);
132
+ }
133
+ // Zero out the arrays
134
+ frame.color.fill(0);
135
+ frame.light.fill(0);
136
+ return frame;
137
+ }
138
+
139
+ /**
140
+ * Creates an effect instance - returns null if pixelfx unavailable.
141
+ * Callers must handle null return.
142
+ */
143
+ export function createFx(
144
+ mod: PixelFxModule,
145
+ options?: Record<string, unknown>
146
+ ): PixelFxInstance | null {
147
+ if (!_pixelfxModule) return null;
148
+ return _pixelfxModule.createFx(mod, options);
149
+ }
150
+
151
+ /**
152
+ * Composites a frame to image data - no-op if pixelfx unavailable.
153
+ */
154
+ export function composite(
155
+ frame: PixelFxFrame,
156
+ out: Uint8ClampedArray,
157
+ bg?: number | Uint32Array | null,
158
+ lightK?: number
159
+ ): Uint8ClampedArray {
160
+ if (_pixelfxModule) {
161
+ return _pixelfxModule.composite(frame, out, bg, lightK);
162
+ }
163
+ return out;
164
+ }
165
+
166
+ /**
167
+ * Checks if pixelfx is available at runtime.
168
+ */
169
+ export function isPixelfxAvailable(): boolean {
170
+ return !!_pixelfxModule;
171
+ }
172
+
173
+ /**
174
+ * Loads a specific pixelfx effect module dynamically.
175
+ * Returns null if pixelfx is unavailable or the effect doesn't exist.
176
+ */
177
+ export async function loadEffectModule(effectId: string): Promise<PixelFxModule | null> {
178
+ const loaded = await ensurePixelfxLoaded();
179
+ if (!loaded) return null;
180
+
181
+ try {
182
+ // Dynamic import of the specific effect
183
+ const mod = await import(`pixelfx/fx/${effectId}`);
184
+ return mod.default as PixelFxModule;
185
+ } catch {
186
+ return null;
187
+ }
188
+ }
package/src/pixelfx.tsx CHANGED
@@ -18,9 +18,12 @@ import {
18
18
  composite,
19
19
  createFrame,
20
20
  createFx,
21
+ loadEffectModule,
22
+ ensurePixelfxLoaded,
23
+ isPixelfxAvailable,
21
24
  type PixelFxInstance,
22
25
  type PixelFxModule,
23
- } from "pixelfx";
26
+ } from "./pixelfx-boundary.js";
24
27
  import {
25
28
  resolveComponentFxProp,
26
29
  resolveEmpirePalette,
@@ -33,47 +36,58 @@ import {
33
36
  } from "./pixelfx-registry.js";
34
37
  import { cn } from "./utils.js";
35
38
 
36
- const EFFECT_LOADERS: Record<PixelFxEffectId, () => Promise<PixelFxModule>> = {
37
- "shadow/eclipse": () => import("pixelfx/fx/shadow/eclipse"),
38
- "lightning/tesla-coil": () => import("pixelfx/fx/lightning/tesla-coil"),
39
- "holy/blessing": () => import("pixelfx/fx/holy/blessing"),
40
- "nature/healing-bloom": () => import("pixelfx/fx/nature/healing-bloom"),
41
- "explosions/cartoon-pow": () => import("pixelfx/fx/explosions/cartoon-pow"),
42
- "ui/confetti": () => import("pixelfx/fx/ui/confetti"),
43
- "arcane/magic-circle-cast": () => import("pixelfx/fx/arcane/magic-circle-cast"),
44
- "shadow/hex-sigil": () => import("pixelfx/fx/shadow/hex-sigil"),
45
- "holy/feather-burst": () => import("pixelfx/fx/holy/feather-burst"),
46
- "weather/shooting-stars": () => import("pixelfx/fx/weather/shooting-stars"),
47
- "weather/cherry-blossoms": () => import("pixelfx/fx/weather/cherry-blossoms"),
48
- "weather/aurora": () => import("pixelfx/fx/weather/aurora"),
49
- "weather/god-rays": () => import("pixelfx/fx/weather/god-rays"),
50
- "weather/rain": () => import("pixelfx/fx/weather/rain"),
51
- "weather/fireflies": () => import("pixelfx/fx/weather/fireflies"),
52
- "holy/halo": () => import("pixelfx/fx/holy/halo"),
53
- "holy/sunburst": () => import("pixelfx/fx/holy/sunburst"),
54
- "lightning/spark-arc": () => import("pixelfx/fx/lightning/spark-arc"),
55
- "lightning/zap-hit": () => import("pixelfx/fx/lightning/zap-hit"),
56
- "scifi/hologram": () => import("pixelfx/fx/scifi/hologram"),
57
- "scifi/glitch": () => import("pixelfx/fx/scifi/glitch"),
58
- "melee/double-slash": () => import("pixelfx/fx/melee/double-slash"),
59
- "impacts/impact-frame": () => import("pixelfx/fx/impacts/impact-frame"),
60
- "ui/level-up": () => import("pixelfx/fx/ui/level-up"),
61
- "transitions/glitch-wipe": () => import("pixelfx/fx/transitions/glitch-wipe"),
62
- "transitions/slash-wipe": () => import("pixelfx/fx/transitions/slash-wipe"),
63
- "transitions/burn-away": () => import("pixelfx/fx/transitions/burn-away"),
64
- "transitions/diamond-wipe": () => import("pixelfx/fx/transitions/diamond-wipe"),
39
+ const EFFECT_LOADERS: Record<PixelFxEffectId, () => Promise<PixelFxModule | null>> = {
40
+ "shadow/eclipse": () => loadEffectModule("shadow/eclipse"),
41
+ "lightning/tesla-coil": () => loadEffectModule("lightning/tesla-coil"),
42
+ "holy/blessing": () => loadEffectModule("holy/blessing"),
43
+ "nature/healing-bloom": () => loadEffectModule("nature/healing-bloom"),
44
+ "explosions/cartoon-pow": () => loadEffectModule("explosions/cartoon-pow"),
45
+ "ui/confetti": () => loadEffectModule("ui/confetti"),
46
+ "arcane/magic-circle-cast": () => loadEffectModule("arcane/magic-circle-cast"),
47
+ "shadow/hex-sigil": () => loadEffectModule("shadow/hex-sigil"),
48
+ "holy/feather-burst": () => loadEffectModule("holy/feather-burst"),
49
+ "weather/shooting-stars": () => loadEffectModule("weather/shooting-stars"),
50
+ "weather/cherry-blossoms": () => loadEffectModule("weather/cherry-blossoms"),
51
+ "weather/aurora": () => loadEffectModule("weather/aurora"),
52
+ "weather/god-rays": () => loadEffectModule("weather/god-rays"),
53
+ "weather/rain": () => loadEffectModule("weather/rain"),
54
+ "weather/fireflies": () => loadEffectModule("weather/fireflies"),
55
+ "holy/halo": () => loadEffectModule("holy/halo"),
56
+ "holy/sunburst": () => loadEffectModule("holy/sunburst"),
57
+ "lightning/spark-arc": () => loadEffectModule("lightning/spark-arc"),
58
+ "lightning/zap-hit": () => loadEffectModule("lightning/zap-hit"),
59
+ "scifi/hologram": () => loadEffectModule("scifi/hologram"),
60
+ "scifi/glitch": () => loadEffectModule("scifi/glitch"),
61
+ "melee/double-slash": () => loadEffectModule("melee/double-slash"),
62
+ "impacts/impact-frame": () => loadEffectModule("impacts/impact-frame"),
63
+ "ui/level-up": () => loadEffectModule("ui/level-up"),
64
+ "transitions/glitch-wipe": () => loadEffectModule("transitions/glitch-wipe"),
65
+ "transitions/slash-wipe": () => loadEffectModule("transitions/slash-wipe"),
66
+ "transitions/burn-away": () => loadEffectModule("transitions/burn-away"),
67
+ "transitions/diamond-wipe": () => loadEffectModule("transitions/diamond-wipe"),
65
68
  };
66
69
 
67
- const moduleCache = new Map<PixelFxEffectId, PixelFxModule>();
70
+ const moduleCache = new Map<PixelFxEffectId, PixelFxModule | null>();
68
71
 
69
72
  export async function loadPixelFxModule(
70
73
  id: PixelFxEffectId,
71
- ): Promise<PixelFxModule> {
74
+ ): Promise<PixelFxModule | null> {
72
75
  const cached = moduleCache.get(id);
73
76
  if (cached) return cached;
74
- const mod = await EFFECT_LOADERS[id]();
75
- moduleCache.set(id, mod);
76
- return mod;
77
+
78
+ const loaded = await ensurePixelfxLoaded();
79
+ if (!loaded) return null;
80
+
81
+ try {
82
+ const mod = await EFFECT_LOADERS[id]();
83
+ if (mod) {
84
+ moduleCache.set(id, mod);
85
+ return mod;
86
+ }
87
+ } catch {
88
+ // Effect not available
89
+ }
90
+ return null;
77
91
  }
78
92
 
79
93
  const CORE_PRELOAD_EFFECTS: readonly PixelFxEffectId[] = [
@@ -228,7 +242,7 @@ function resolveRuntimePaletteStops(
228
242
  return staticStops;
229
243
  }
230
244
  const skin = document.documentElement.dataset.skin;
231
- if (!skin || skin === "empire-of-light" || skin === "moonwitness-ink") {
245
+ if (!skin || skin === "moonwitness-ink") {
232
246
  return staticStops;
233
247
  }
234
248
  // Dynamically adapt accent peak stop to the active skin's live CSS variable
@@ -441,6 +455,10 @@ export function PixelFxCanvas({
441
455
 
442
456
  loadPixelFxModule(effectId)
443
457
  .then((mod) => {
458
+ if (!mod) {
459
+ // pixelfx not available - silently skip effect rendering
460
+ return;
461
+ }
444
462
  if (cancelled) return;
445
463
  const meta = mod.meta ?? {};
446
464
  const frameW = width ?? meta.size?.[0] ?? 128;
@@ -489,7 +507,15 @@ export function PixelFxCanvas({
489
507
  : {}),
490
508
  });
491
509
 
492
- fx = buildInstance();
510
+ const fxInstance = buildInstance();
511
+
512
+ if (!fxInstance) {
513
+ // pixelfx not available - silently skip effect rendering
514
+ return;
515
+ }
516
+
517
+ fx = fxInstance;
518
+ // TypeScript narrowing: fx is now definitely PixelFxInstance
493
519
 
494
520
  if (effectiveReducedMotion) {
495
521
  const mid = Math.min(0.45, (meta.duration ?? 1) * 0.35);
@@ -515,7 +541,9 @@ export function PixelFxCanvas({
515
541
 
516
542
  if (fx.done()) {
517
543
  if (loop) {
518
- fx = buildInstance();
544
+ const nextFx = buildInstance();
545
+ if (!nextFx) return;
546
+ fx = nextFx;
519
547
  fx.update(1 / 60);
520
548
  } else {
521
549
  ctx.clearRect(0, 0, frameW, frameH);
package/src/provider.tsx CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  export interface MoonWitnessProviderProps {
14
14
  /** Color mode. Defaults to `"dark"` (Empire of Light obsidian ink). */
15
15
  mode?: ThemeMode;
16
- /** Design skin. Defaults to `"empire-of-light"`. */
16
+ /** Design skin. Defaults to `"moonwitness-ink"`. */
17
17
  skin?: SkinId;
18
18
  /** Spacing density. Defaults to `"comfortable"`. */
19
19
  density?: SkinDensity;
@@ -33,7 +33,7 @@ export interface MoonWitnessProviderProps {
33
33
  */
34
34
  export function MoonWitnessProvider({
35
35
  mode = "dark",
36
- skin = "empire-of-light",
36
+ skin = "moonwitness-ink",
37
37
  density = "comfortable",
38
38
  fx = true,
39
39
  fxPalette = "default",
@@ -261,6 +261,42 @@ export interface SkinInitScriptOptions {
261
261
  storageKey?: string;
262
262
  }
263
263
 
264
+ /**
265
+ * Validates a skin ID against the registry.
266
+ * Throws if the skin ID is not registered.
267
+ * Does NOT silently fall back — callers must handle or let it throw.
268
+ */
269
+ export function validateSkinId(skinId: string, registry: ThemeRegistry = themeRegistry): void {
270
+ if (!registry.has(skinId)) {
271
+ const available = registry.list().map((s) => s.id).join(", ");
272
+ throw new Error(
273
+ `Unknown skin ID "${skinId}". Available skins: ${available}`,
274
+ );
275
+ }
276
+ }
277
+
278
+ /**
279
+ * Validates a skin ID and returns the resolved skin metadata.
280
+ * Throws if the skin ID is not registered.
281
+ */
282
+ export function resolveValidSkin(
283
+ skinId?: string | null,
284
+ registry: ThemeRegistry = themeRegistry,
285
+ ): SkinMetadata {
286
+ if (typeof skinId === "string" && registry.has(skinId)) {
287
+ return registry.get(skinId)!;
288
+ }
289
+ if (skinId !== undefined && skinId !== null) {
290
+ // Explicit but invalid skin ID — throw, don't silently fall back
291
+ const available = registry.list().map((s) => s.id).join(", ");
292
+ throw new Error(
293
+ `Unknown skin ID "${skinId}". Available skins: ${available}`,
294
+ );
295
+ }
296
+ // No skin specified — use default
297
+ return registry.get(registry.defaultSkinId)!;
298
+ }
299
+
264
300
  export function createSkinInitScript(
265
301
  options: SkinInitScriptOptions = {},
266
302
  ): string {