@moonwitness/ui 7.3.1 → 9.0.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.
Files changed (260) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +2 -3
  3. package/scripts/consumer-smoke.mjs +0 -45
  4. package/scripts/generate-icons.mjs +0 -110
  5. package/scripts/generate-token-artifacts.mjs +0 -90
  6. package/scripts/icon-svg-to-jsx.mjs +0 -249
  7. package/scripts/verification-diagnostics.mjs +0 -40
  8. package/scripts/verify-package.mjs +0 -412
  9. package/src/cartoon/anime-avatar.tsx +0 -628
  10. package/src/cartoon/anime-stage.tsx +0 -458
  11. package/src/cartoon/index.tsx +0 -542
  12. package/src/cartoon.tsx +0 -645
  13. package/src/characters.ts +0 -625
  14. package/src/components/accordion.tsx +0 -77
  15. package/src/components/alert.tsx +0 -139
  16. package/src/components/appearance-menu.tsx +0 -181
  17. package/src/components/artwork-frame.tsx +0 -49
  18. package/src/components/audio.tsx +0 -97
  19. package/src/components/avatar.tsx +0 -75
  20. package/src/components/badge.tsx +0 -94
  21. package/src/components/brand-mark.tsx +0 -73
  22. package/src/components/breadcrumbs.tsx +0 -98
  23. package/src/components/button.tsx +0 -340
  24. package/src/components/card.tsx +0 -171
  25. package/src/components/character-badge.tsx +0 -58
  26. package/src/components/character-preview.tsx +0 -104
  27. package/src/components/character-stage.tsx +0 -225
  28. package/src/components/chart.tsx +0 -481
  29. package/src/components/checkbox.tsx +0 -64
  30. package/src/components/comic-panel.tsx +0 -301
  31. package/src/components/comic-theater.tsx +0 -170
  32. package/src/components/command.tsx +0 -189
  33. package/src/components/confirm-dialog.tsx +0 -129
  34. package/src/components/copy-button.tsx +0 -62
  35. package/src/components/date-picker.tsx +0 -126
  36. package/src/components/dialog.tsx +0 -164
  37. package/src/components/dna-icon.tsx +0 -77
  38. package/src/components/dropdown-menu.tsx +0 -87
  39. package/src/components/effects.tsx +0 -1021
  40. package/src/components/empty-state.tsx +0 -93
  41. package/src/components/epistemic-branch-panel.tsx +0 -101
  42. package/src/components/error-state.tsx +0 -137
  43. package/src/components/field.tsx +0 -96
  44. package/src/components/filter-facet-bar.tsx +0 -91
  45. package/src/components/inbox-popover.tsx +0 -146
  46. package/src/components/input.tsx +0 -25
  47. package/src/components/kanban-board.tsx +0 -190
  48. package/src/components/label.tsx +0 -19
  49. package/src/components/layered-scene.tsx +0 -555
  50. package/src/components/log-console.tsx +0 -261
  51. package/src/components/metric-tile.tsx +0 -99
  52. package/src/components/mode-picker.tsx +0 -149
  53. package/src/components/motion-timeline.tsx +0 -848
  54. package/src/components/number-input.tsx +0 -104
  55. package/src/components/page-header.tsx +0 -123
  56. package/src/components/pagination.tsx +0 -83
  57. package/src/components/panel.tsx +0 -121
  58. package/src/components/paper-note.tsx +0 -77
  59. package/src/components/popover.tsx +0 -72
  60. package/src/components/progress.tsx +0 -127
  61. package/src/components/quest-card.tsx +0 -319
  62. package/src/components/radio-group.tsx +0 -50
  63. package/src/components/riot-sticker.tsx +0 -151
  64. package/src/components/scene-particles.tsx +0 -196
  65. package/src/components/scene-transitions.tsx +0 -130
  66. package/src/components/section-ribbon.tsx +0 -94
  67. package/src/components/select-field.tsx +0 -27
  68. package/src/components/select.tsx +0 -81
  69. package/src/components/separator.tsx +0 -58
  70. package/src/components/sheet.tsx +0 -96
  71. package/src/components/skeleton.tsx +0 -35
  72. package/src/components/sketch-annotation.tsx +0 -87
  73. package/src/components/smart-button-box.tsx +0 -114
  74. package/src/components/speech-bubble.tsx +0 -116
  75. package/src/components/spinner.tsx +0 -69
  76. package/src/components/sprite-player.tsx +0 -412
  77. package/src/components/status-bar.tsx +0 -63
  78. package/src/components/status-pill.tsx +0 -68
  79. package/src/components/switch.tsx +0 -76
  80. package/src/components/table.tsx +0 -163
  81. package/src/components/tabs.tsx +0 -101
  82. package/src/components/tag-input.tsx +0 -170
  83. package/src/components/textarea.tsx +0 -25
  84. package/src/components/toast.tsx +0 -14
  85. package/src/components/toolbar.tsx +0 -39
  86. package/src/components/tooltip.tsx +0 -49
  87. package/src/components/update-banner.tsx +0 -220
  88. package/src/components/xv-primitives.tsx +0 -256
  89. package/src/css-exports.ts +0 -142
  90. package/src/dna.tsx +0 -137
  91. package/src/game/boss-hud.tsx +0 -384
  92. package/src/game/index.tsx +0 -886
  93. package/src/game/tactical.tsx +0 -245
  94. package/src/game.tsx +0 -770
  95. package/src/icons/activity.tsx +0 -38
  96. package/src/icons/add.tsx +0 -38
  97. package/src/icons/addon.tsx +0 -37
  98. package/src/icons/anime-anger.tsx +0 -37
  99. package/src/icons/anime-shock.tsx +0 -37
  100. package/src/icons/anime-sparkle.tsx +0 -38
  101. package/src/icons/anime-sweatdrop.tsx +0 -38
  102. package/src/icons/archive.tsx +0 -37
  103. package/src/icons/arrow-left.tsx +0 -37
  104. package/src/icons/arrow-right.tsx +0 -37
  105. package/src/icons/attachment.tsx +0 -38
  106. package/src/icons/bank.tsx +0 -37
  107. package/src/icons/bolt.tsx +0 -37
  108. package/src/icons/book-open.tsx +0 -37
  109. package/src/icons/bookmark.tsx +0 -37
  110. package/src/icons/boss-skull.tsx +0 -40
  111. package/src/icons/calendar-clock.tsx +0 -40
  112. package/src/icons/calendar.tsx +0 -38
  113. package/src/icons/check-circle.tsx +0 -38
  114. package/src/icons/check-square.tsx +0 -38
  115. package/src/icons/check.tsx +0 -37
  116. package/src/icons/chevron-right.tsx +0 -37
  117. package/src/icons/chevrons-left.tsx +0 -37
  118. package/src/icons/chevrons-right.tsx +0 -37
  119. package/src/icons/clapperboard.tsx +0 -38
  120. package/src/icons/clock.tsx +0 -38
  121. package/src/icons/close.tsx +0 -37
  122. package/src/icons/code.tsx +0 -37
  123. package/src/icons/columns.tsx +0 -38
  124. package/src/icons/combo-flame.tsx +0 -38
  125. package/src/icons/company.tsx +0 -38
  126. package/src/icons/credit-card.tsx +0 -38
  127. package/src/icons/critical-star.tsx +0 -37
  128. package/src/icons/currency.tsx +0 -38
  129. package/src/icons/delete.tsx +0 -37
  130. package/src/icons/document.tsx +0 -38
  131. package/src/icons/download.tsx +0 -37
  132. package/src/icons/dpad.tsx +0 -38
  133. package/src/icons/edit.tsx +0 -38
  134. package/src/icons/element-fire.tsx +0 -37
  135. package/src/icons/element-ice.tsx +0 -38
  136. package/src/icons/element-solar.tsx +0 -38
  137. package/src/icons/element-void.tsx +0 -38
  138. package/src/icons/element-volt.tsx +0 -38
  139. package/src/icons/element-wind.tsx +0 -37
  140. package/src/icons/error.tsx +0 -38
  141. package/src/icons/external-link.tsx +0 -38
  142. package/src/icons/field.tsx +0 -38
  143. package/src/icons/file-spreadsheet.tsx +0 -38
  144. package/src/icons/filter.tsx +0 -37
  145. package/src/icons/gacha-ticket.tsx +0 -38
  146. package/src/icons/gamepad.tsx +0 -40
  147. package/src/icons/globe.tsx +0 -38
  148. package/src/icons/grid.tsx +0 -40
  149. package/src/icons/hash.tsx +0 -37
  150. package/src/icons/heart-hp.tsx +0 -38
  151. package/src/icons/history.tsx +0 -37
  152. package/src/icons/home.tsx +0 -37
  153. package/src/icons/image.tsx +0 -39
  154. package/src/icons/impact-slash.tsx +0 -38
  155. package/src/icons/inbox.tsx +0 -38
  156. package/src/icons/index.ts +0 -120
  157. package/src/icons/info.tsx +0 -38
  158. package/src/icons/jobs.tsx +0 -38
  159. package/src/icons/katana.tsx +0 -38
  160. package/src/icons/key.tsx +0 -38
  161. package/src/icons/keyboard.tsx +0 -38
  162. package/src/icons/keyframe-diamond.tsx +0 -38
  163. package/src/icons/knowledge.tsx +0 -38
  164. package/src/icons/language.tsx +0 -39
  165. package/src/icons/lock.tsx +0 -38
  166. package/src/icons/logout.tsx +0 -37
  167. package/src/icons/loot-chest.tsx +0 -39
  168. package/src/icons/mail.tsx +0 -38
  169. package/src/icons/mana-crystal.tsx +0 -38
  170. package/src/icons/map-pin.tsx +0 -38
  171. package/src/icons/mecha-helm.tsx +0 -38
  172. package/src/icons/menu.tsx +0 -37
  173. package/src/icons/message.tsx +0 -38
  174. package/src/icons/model.tsx +0 -38
  175. package/src/icons/moon.tsx +0 -37
  176. package/src/icons/notification.tsx +0 -38
  177. package/src/icons/partner.tsx +0 -41
  178. package/src/icons/pause.tsx +0 -37
  179. package/src/icons/phone.tsx +0 -37
  180. package/src/icons/play.tsx +0 -37
  181. package/src/icons/potion-flask.tsx +0 -40
  182. package/src/icons/quest-scroll.tsx +0 -39
  183. package/src/icons/radar-ping.tsx +0 -40
  184. package/src/icons/refresh.tsx +0 -38
  185. package/src/icons/relation.tsx +0 -40
  186. package/src/icons/save.tsx +0 -38
  187. package/src/icons/search.tsx +0 -38
  188. package/src/icons/security.tsx +0 -38
  189. package/src/icons/send.tsx +0 -38
  190. package/src/icons/settings.tsx +0 -39
  191. package/src/icons/shield-crest.tsx +0 -38
  192. package/src/icons/shuriken.tsx +0 -38
  193. package/src/icons/signal-off.tsx +0 -37
  194. package/src/icons/signal.tsx +0 -37
  195. package/src/icons/skill-node.tsx +0 -40
  196. package/src/icons/smartphone.tsx +0 -38
  197. package/src/icons/sort-ascending.tsx +0 -37
  198. package/src/icons/sort-descending.tsx +0 -37
  199. package/src/icons/sort.tsx +0 -37
  200. package/src/icons/sparkle.tsx +0 -38
  201. package/src/icons/speech-burst.tsx +0 -37
  202. package/src/icons/story.tsx +0 -37
  203. package/src/icons/sun.tsx +0 -38
  204. package/src/icons/tag.tsx +0 -38
  205. package/src/icons/team.tsx +0 -40
  206. package/src/icons/trophy-crown.tsx +0 -39
  207. package/src/icons/upload.tsx +0 -37
  208. package/src/icons/user.tsx +0 -38
  209. package/src/icons/users.tsx +0 -39
  210. package/src/icons/visibility-off.tsx +0 -38
  211. package/src/icons/visibility.tsx +0 -38
  212. package/src/icons/volume-off.tsx +0 -37
  213. package/src/icons/volume.tsx +0 -37
  214. package/src/icons/warning.tsx +0 -38
  215. package/src/icons/workflow.tsx +0 -40
  216. package/src/icons.tsx +0 -965
  217. package/src/index.ts +0 -89
  218. package/src/lib/asset-registry.ts +0 -534
  219. package/src/lib/audio-runtime.ts +0 -314
  220. package/src/lib/character-adapter.ts +0 -370
  221. package/src/lib/character-registry.ts +0 -2368
  222. package/src/lib/cn.ts +0 -6
  223. package/src/lib/compose-refs.ts +0 -16
  224. package/src/lib/sanitize-url.ts +0 -51
  225. package/src/lib/scene-camera.ts +0 -483
  226. package/src/lib/scene-playback.ts +0 -622
  227. package/src/lib/scene-soundscape.ts +0 -151
  228. package/src/lib/scene-test-harness.ts +0 -200
  229. package/src/lib/scene-timeline.ts +0 -398
  230. package/src/lib/use-animation-visibility.ts +0 -45
  231. package/src/lib/use-modal-focus.ts +0 -270
  232. package/src/lib/use-reduced-motion.ts +0 -37
  233. package/src/motion/easing-presets.ts +0 -262
  234. package/src/motion/index.tsx +0 -894
  235. package/src/motion/physics.ts +0 -259
  236. package/src/motion/timeline-math.ts +0 -358
  237. package/src/motion.tsx +0 -639
  238. package/src/pixelfx-boundary.ts +0 -188
  239. package/src/pixelfx-registry.ts +0 -1190
  240. package/src/pixelfx-types.d.ts +0 -73
  241. package/src/pixelfx.tsx +0 -1022
  242. package/src/provider.tsx +0 -63
  243. package/src/skin-catalog.ts +0 -306
  244. package/src/skin-tokens.ts +0 -425
  245. package/src/ssr/init-script.ts +0 -281
  246. package/src/ssr/resolve-skin.ts +0 -217
  247. package/src/ssr/theme-mismatch-dev.ts +0 -181
  248. package/src/templates/battle-arena.tsx +0 -688
  249. package/src/templates/index.tsx +0 -314
  250. package/src/templates.tsx +0 -225
  251. package/src/themes/dna-presets.ts +0 -119
  252. package/src/themes/index.ts +0 -56
  253. package/src/themes/provider.tsx +0 -183
  254. package/src/themes/types.ts +0 -111
  255. package/src/themes.ts +0 -9
  256. package/src/token-exporter.ts +0 -12
  257. package/src/token-exporters.ts +0 -343
  258. package/src/token-seeds.ts +0 -335
  259. package/src/token-snapshot.ts +0 -179
  260. package/src/utils.ts +0 -58
@@ -1,412 +0,0 @@
1
- "use client";
2
-
3
- import {
4
- useCallback,
5
- useEffect,
6
- useMemo,
7
- useRef,
8
- useState,
9
- type CSSProperties,
10
- } from "react";
11
- import { useComponentPixelFx } from "../pixelfx.js";
12
- import type { PixelFxProp } from "../pixelfx-registry.js";
13
- import { createSpriteSequenceAdapter } from "../lib/character-adapter.js";
14
- import { cn } from "../lib/cn.js";
15
- import {
16
- createScenePlaybackController,
17
- type ScenePlaybackController,
18
- type ScenePlaybackSnapshot,
19
- } from "../lib/scene-playback.js";
20
- import { getActiveSceneHarness } from "../lib/scene-test-harness.js";
21
- import { useReducedMotion } from "../lib/use-reduced-motion.js";
22
-
23
- export interface SpriteClipMetadata {
24
- readonly id: string;
25
- readonly frames: readonly string[];
26
- readonly fps?: number;
27
- readonly durationMs?: number;
28
- readonly loop?: boolean;
29
- readonly pingPong?: boolean;
30
- readonly fallbackAsset: string;
31
- readonly width: number;
32
- readonly height: number;
33
- }
34
-
35
- /** One image holding every frame in a grid; frames swap by background offset, never by src. */
36
- export interface SpriteSheetAtlas {
37
- readonly src: string;
38
- readonly columns: number;
39
- readonly rows: number;
40
- readonly frameWidth: number;
41
- readonly frameHeight: number;
42
- readonly frameCount?: number;
43
- }
44
-
45
- export interface SpritePlayerProps {
46
- readonly clip: SpriteClipMetadata;
47
- readonly spriteSheet?: SpriteSheetAtlas;
48
- readonly label?: string;
49
- readonly scale?: number;
50
- readonly playing?: boolean;
51
- readonly paused?: boolean;
52
- readonly pinnedFrame?: number;
53
- readonly reducedMotion?: boolean;
54
- readonly pauseOffscreen?: boolean;
55
- readonly className?: string;
56
- readonly style?: CSSProperties;
57
- readonly frameStyle?: CSSProperties;
58
- readonly onFrameChange?: (frameIndex: number) => void;
59
- readonly fx?: PixelFxProp;
60
- }
61
-
62
- const DEFAULT_SPRITE_FPS = 12;
63
- const spriteAdapter = createSpriteSequenceAdapter();
64
-
65
- const isPositiveInt = (value: unknown): value is number =>
66
- Number.isInteger(value) && (value as number) > 0;
67
-
68
- export function isValidSpriteSheet(
69
- atlas: SpriteSheetAtlas | undefined,
70
- ): atlas is SpriteSheetAtlas {
71
- return (
72
- atlas !== undefined &&
73
- atlas.src.length > 0 &&
74
- isPositiveInt(atlas.columns) &&
75
- isPositiveInt(atlas.rows) &&
76
- Number.isFinite(atlas.frameWidth) &&
77
- atlas.frameWidth > 0 &&
78
- Number.isFinite(atlas.frameHeight) &&
79
- atlas.frameHeight > 0
80
- );
81
- }
82
-
83
- export function resolveSpriteSheetFrameCount(atlas: SpriteSheetAtlas): number {
84
- const cells = atlas.columns * atlas.rows;
85
- return isPositiveInt(atlas.frameCount) && atlas.frameCount <= cells
86
- ? atlas.frameCount
87
- : cells;
88
- }
89
-
90
- /** Background offset (in %) that shows grid cell `frameIndex`, filling rows left to right. */
91
- export function computeSpriteSheetOffset(
92
- frameIndex: number,
93
- atlas: Pick<SpriteSheetAtlas, "columns" | "rows">,
94
- ): { readonly x: number; readonly y: number } {
95
- const column = frameIndex % atlas.columns;
96
- const row = Math.floor(frameIndex / atlas.columns) % atlas.rows;
97
- return {
98
- x: atlas.columns > 1 ? (column / (atlas.columns - 1)) * 100 : 0,
99
- y: atlas.rows > 1 ? (row / (atlas.rows - 1)) * 100 : 0,
100
- };
101
- }
102
-
103
- function SpriteSheetFrame({
104
- atlas,
105
- frameIndex,
106
- label,
107
- style,
108
- }: {
109
- readonly atlas: SpriteSheetAtlas;
110
- readonly frameIndex: number;
111
- readonly label: string;
112
- readonly style?: CSSProperties;
113
- }) {
114
- const offset = computeSpriteSheetOffset(frameIndex, atlas);
115
- return (
116
- <div
117
- className="mw-ui-sprite-player-frame"
118
- role="img"
119
- aria-label={label}
120
- data-sprite-atlas="true"
121
- style={{
122
- ...style,
123
- width: "100%",
124
- height: "100%",
125
- backgroundImage: `url(${JSON.stringify(atlas.src)})`,
126
- backgroundRepeat: "no-repeat",
127
- backgroundSize: `${atlas.columns * 100}% ${atlas.rows * 100}%`,
128
- backgroundPosition: `${offset.x}% ${offset.y}%`,
129
- }}
130
- />
131
- );
132
- }
133
-
134
- function resolveClipCycleDurationMs(
135
- clip: Pick<SpriteClipMetadata, "frames" | "fps" | "durationMs" | "pingPong">,
136
- ): number {
137
- const count = clip.frames.length;
138
- if (count === 0) return 0;
139
- const fps =
140
- typeof clip.fps === "number" && Number.isFinite(clip.fps) && clip.fps > 0
141
- ? clip.fps
142
- : DEFAULT_SPRITE_FPS;
143
- const baseDurationMs =
144
- typeof clip.durationMs === "number" &&
145
- Number.isFinite(clip.durationMs) &&
146
- clip.durationMs > 0
147
- ? clip.durationMs
148
- : (count / fps) * 1000;
149
-
150
- if (clip.pingPong && count >= 2) {
151
- const frameDurationMs = baseDurationMs / count;
152
- return frameDurationMs * (2 * (count - 1));
153
- }
154
- return baseDurationMs;
155
- }
156
-
157
- export function computeSpriteFrameIndex(
158
- clip: Pick<
159
- SpriteClipMetadata,
160
- "frames" | "fps" | "durationMs" | "loop" | "pingPong"
161
- >,
162
- timeMs: number,
163
- options?: {
164
- readonly reducedMotion?: boolean;
165
- readonly pinnedFrame?: number;
166
- },
167
- ): number {
168
- const resolved = spriteAdapter.resolveFrame(
169
- {
170
- id: "sprite-clip",
171
- format: "sprite-sequence",
172
- frames: clip.frames,
173
- fps: clip.fps,
174
- durationMs: clip.durationMs,
175
- loop: clip.loop,
176
- pingPong: clip.pingPong,
177
- fallbackAsset: clip.frames[0] ?? "",
178
- },
179
- timeMs,
180
- {
181
- reducedMotion: options?.reducedMotion,
182
- pinnedFrame: options?.pinnedFrame,
183
- },
184
- );
185
- return resolved.frameIndex;
186
- }
187
-
188
- export function SpritePlayer({
189
- clip: sourceClip,
190
- spriteSheet,
191
- label,
192
- scale = 1,
193
- playing = true,
194
- paused = false,
195
- pinnedFrame,
196
- reducedMotion,
197
- pauseOffscreen = true,
198
- className,
199
- style,
200
- frameStyle,
201
- onFrameChange,
202
- fx = "auto",
203
- }: SpritePlayerProps) {
204
- const harness = getActiveSceneHarness();
205
- const atlas = isValidSpriteSheet(spriteSheet) ? spriteSheet : undefined;
206
- const atlasSrc = atlas?.src;
207
- const atlasFrameCount = atlas ? resolveSpriteSheetFrameCount(atlas) : 0;
208
- const clip = useMemo<SpriteClipMetadata>(
209
- () =>
210
- atlasSrc === undefined
211
- ? sourceClip
212
- : {
213
- ...sourceClip,
214
- frames: Array.from({ length: atlasFrameCount }, () => atlasSrc),
215
- },
216
- [sourceClip, atlasSrc, atlasFrameCount],
217
- );
218
- const effectiveReducedMotion = useReducedMotion(reducedMotion);
219
- const pfx = useComponentPixelFx({
220
- kind: "sprite-player",
221
- fx: effectiveReducedMotion ? false : fx,
222
- placement: "background",
223
- });
224
- const effectivePinnedFrame = pinnedFrame ?? harness?.fixedFrame;
225
- const effectivePaused = Boolean(paused || harness?.paused === true);
226
- const fixedTimeMs = harness?.fixedTimeMs;
227
- const shouldPlay =
228
- !effectiveReducedMotion &&
229
- effectivePinnedFrame === undefined &&
230
- fixedTimeMs === undefined &&
231
- playing &&
232
- !effectivePaused &&
233
- clip.frames.length > 1;
234
-
235
- const clipSignature = useMemo(
236
- () =>
237
- [
238
- clip.id,
239
- clip.fallbackAsset,
240
- String(clip.fps ?? ""),
241
- String(clip.durationMs ?? ""),
242
- String(clip.loop ?? ""),
243
- String(clip.pingPong ?? ""),
244
- clip.frames.join("|"),
245
- ].join("::"),
246
- [
247
- clip.id,
248
- clip.fallbackAsset,
249
- clip.fps,
250
- clip.durationMs,
251
- clip.loop,
252
- clip.pingPong,
253
- clip.frames,
254
- ],
255
- );
256
-
257
- const cycleDurationMs = useMemo(
258
- () => resolveClipCycleDurationMs(clip),
259
- [clip],
260
- );
261
-
262
- const [snapshot, setSnapshot] = useState<ScenePlaybackSnapshot>(() => ({
263
- timeMs: fixedTimeMs ?? 0,
264
- durationMs: cycleDurationMs > 0 ? cycleDurationMs : null,
265
- progress: 0,
266
- requestedPlaying: shouldPlay,
267
- effectiveState: effectiveReducedMotion
268
- ? "static"
269
- : shouldPlay
270
- ? "playing"
271
- : "paused",
272
- reducedMotion: effectiveReducedMotion,
273
- visible: true,
274
- documentHidden: false,
275
- disposed: false,
276
- activeHandleCount: 0,
277
- }));
278
-
279
- const [containerElement, setContainerElement] =
280
- useState<HTMLDivElement | null>(null);
281
- const controllerRef = useRef<ScenePlaybackController | null>(null);
282
- const lastReportedFrameRef = useRef<number | null>(null);
283
-
284
- const containerRef = useCallback((element: HTMLDivElement | null) => {
285
- setContainerElement(element);
286
- }, []);
287
-
288
- useEffect(() => {
289
- const controller = createScenePlaybackController({
290
- durationMs: cycleDurationMs > 0 ? cycleDurationMs : undefined,
291
- loop: clip.loop !== false || Boolean(clip.pingPong),
292
- initialTimeMs: fixedTimeMs ?? 0,
293
- autoPlay: shouldPlay,
294
- reducedMotion: effectiveReducedMotion,
295
- pauseOffscreen,
296
- });
297
- controllerRef.current = controller;
298
- setSnapshot(controller.getSnapshot());
299
-
300
- const unsubscribe = controller.subscribe(setSnapshot);
301
- const detachObservers = controller.attachObservers(containerElement);
302
-
303
- return () => {
304
- unsubscribe();
305
- detachObservers();
306
- controller.dispose();
307
- if (controllerRef.current === controller) {
308
- controllerRef.current = null;
309
- }
310
- };
311
- }, [
312
- clipSignature,
313
- clip.loop,
314
- clip.pingPong,
315
- cycleDurationMs,
316
- pauseOffscreen,
317
- containerElement,
318
- fixedTimeMs,
319
- effectiveReducedMotion,
320
- shouldPlay,
321
- ]);
322
-
323
- const effectiveTimeMs = fixedTimeMs ?? snapshot.timeMs;
324
- const isReduced = effectiveReducedMotion || snapshot.reducedMotion;
325
-
326
- const resolved = spriteAdapter.resolveFrame(
327
- {
328
- id: clip.id,
329
- format: "sprite-sequence",
330
- frames: clip.frames,
331
- fps: clip.fps,
332
- durationMs: clip.durationMs,
333
- loop: clip.loop,
334
- pingPong: clip.pingPong,
335
- fallbackAsset: clip.fallbackAsset,
336
- },
337
- effectiveTimeMs,
338
- {
339
- reducedMotion: isReduced,
340
- pinnedFrame: effectivePinnedFrame,
341
- },
342
- );
343
-
344
- useEffect(() => {
345
- if (lastReportedFrameRef.current !== resolved.frameIndex) {
346
- lastReportedFrameRef.current = resolved.frameIndex;
347
- onFrameChange?.(resolved.frameIndex);
348
- }
349
- }, [resolved.frameIndex, onFrameChange]);
350
-
351
- const spriteState =
352
- isReduced || clip.frames.length === 0
353
- ? "static"
354
- : effectivePinnedFrame !== undefined
355
- ? "pinned"
356
- : resolved.completed
357
- ? "completed"
358
- : shouldPlay && snapshot.effectiveState === "playing"
359
- ? "playing"
360
- : "paused";
361
-
362
- const effectiveScale = Number.isFinite(scale) && scale > 0 ? scale : 1;
363
- const scaledWidth = Math.max(1, Math.round(clip.width * effectiveScale));
364
- const scaledHeight = Math.max(1, Math.round(clip.height * effectiveScale));
365
-
366
- return (
367
- <div
368
- ref={containerRef}
369
- className={cn("mw-ui-sprite-player", className)}
370
- data-sprite-clip={clip.id}
371
- data-sprite-frame={String(resolved.frameIndex)}
372
- data-sprite-state={spriteState}
373
- {...pfx.dataAttributes}
374
- {...pfx.handlers}
375
- style={{
376
- display: "inline-block",
377
- width: `min(100%, ${scaledWidth}px)`,
378
- maxWidth: "100%",
379
- aspectRatio: atlas
380
- ? `${atlas.frameWidth} / ${atlas.frameHeight}`
381
- : `${scaledWidth} / ${scaledHeight}`,
382
- ...style,
383
- }}
384
- >
385
- {pfx.layer}
386
- {atlas ? (
387
- <SpriteSheetFrame
388
- atlas={atlas}
389
- frameIndex={resolved.frameIndex}
390
- label={label ?? `${clip.id} sprite frame`}
391
- style={frameStyle}
392
- />
393
- ) : (
394
- <img
395
- className="mw-ui-sprite-player-frame"
396
- src={resolved.asset}
397
- alt={label ?? `${clip.id} sprite frame`}
398
- width={scaledWidth}
399
- height={scaledHeight}
400
- decoding="async"
401
- style={{
402
- ...frameStyle,
403
- display: "block",
404
- width: "100%",
405
- height: "100%",
406
- objectFit: "contain",
407
- }}
408
- />
409
- )}
410
- </div>
411
- );
412
- }
@@ -1,63 +0,0 @@
1
- import { Badge } from "./badge.js";
2
- import { useComponentPixelFx } from "../pixelfx.js";
3
- import type { PixelFxProp } from "../pixelfx-registry.js";
4
- import { cn } from "../utils.js";
5
-
6
- export type StatusBarStepState = "done" | "active" | "disabled";
7
-
8
- export type StatusBarStep = {
9
- id: string;
10
- label: string;
11
- state: StatusBarStepState;
12
- count?: number;
13
- };
14
-
15
- export type StatusBarProps = {
16
- steps: readonly StatusBarStep[];
17
- fx?: PixelFxProp;
18
- className?: string;
19
- };
20
-
21
- export function StatusBar({
22
- steps,
23
- fx = "auto",
24
- className = "",
25
- }: StatusBarProps) {
26
- const pfx = useComponentPixelFx({
27
- kind: "status-bar",
28
- fx,
29
- placement: "background",
30
- });
31
- return (
32
- <ol
33
- className={cn("mw-ui-status-bar", className)}
34
- aria-label="Workflow status"
35
- {...pfx.dataAttributes}
36
- {...pfx.handlers}
37
- >
38
- {pfx.layer}
39
- {steps.map((step, index) => {
40
- const isActive = step.state === "active";
41
- const isDone = step.state === "done";
42
- return (
43
- <li
44
- key={step.id}
45
- className="mw-ui-status-step"
46
- data-state={step.state}
47
- aria-current={isActive ? "step" : undefined}
48
- >
49
- <span className="mw-ui-status-step-index">
50
- {isDone ? "✓" : index + 1}
51
- </span>
52
- <span>{step.label}</span>
53
- {typeof step.count === "number" ? (
54
- <Badge size="sm" variant={isActive ? "magenta" : "default"}>
55
- {step.count}
56
- </Badge>
57
- ) : null}
58
- </li>
59
- );
60
- })}
61
- </ol>
62
- );
63
- }
@@ -1,68 +0,0 @@
1
- import { forwardRef, type ComponentProps } from "react";
2
- import { useComponentPixelFx } from "../pixelfx.js";
3
- import type { PixelFxProp } from "../pixelfx-registry.js";
4
- import { cn } from "../utils.js";
5
-
6
- export type StatusPillVariant =
7
- | "live"
8
- | "reconnecting"
9
- | "offline"
10
- | "magpie"
11
- | "ready"
12
- | "absent"
13
- | "clean"
14
- | "dirty"
15
- | "online"
16
- | "offline-svc"
17
- | "green"
18
- | "magenta"
19
- | "cyan"
20
- | "yellow"
21
- | "violet";
22
-
23
- export type StatusPillSize = "sm" | "md";
24
-
25
- export type StatusPillProps = ComponentProps<"span"> & {
26
- variant: StatusPillVariant;
27
- size?: StatusPillSize;
28
- pulse?: boolean;
29
- fx?: PixelFxProp;
30
- };
31
-
32
- export const StatusPill = forwardRef<HTMLSpanElement, StatusPillProps>(
33
- function StatusPill(
34
- { className, variant, size = "sm", pulse = true, fx = "auto", children, ...props },
35
- ref,
36
- ) {
37
- const pfx = useComponentPixelFx({
38
- kind: "status-pill",
39
- fx,
40
- placement: "background",
41
- });
42
- const classes = [
43
- "mw-ui-status-pill",
44
- `mw-ui-status-pill--${variant}`,
45
- size !== "md" ? `mw-ui-status-pill--${size}` : "",
46
- pulse ? "mw-ui-status-pill--pulse" : "",
47
- className,
48
- ]
49
- .filter(Boolean)
50
- .join(" ");
51
-
52
- return (
53
- <span
54
- ref={ref}
55
- data-slot="status-pill"
56
- data-variant={variant}
57
- data-size={size}
58
- className={classes}
59
- {...pfx.dataAttributes}
60
- {...pfx.handlers}
61
- {...props}
62
- >
63
- {pfx.layer}
64
- {children}
65
- </span>
66
- );
67
- },
68
- );
@@ -1,76 +0,0 @@
1
- 'use client';
2
- import { forwardRef } from "react";
3
- import { Switch as RadixSwitch } from "radix-ui";
4
- import { PixelFxComponentLayer, usePixelFxBurst } from "../pixelfx.js";
5
- import {
6
- resolveComponentPixelFx,
7
- type EmpirePaletteId,
8
- type PixelFxEffectId,
9
- } from "../pixelfx-registry.js";
10
-
11
- export interface SwitchProps {
12
- id?: string;
13
- checked?: boolean;
14
- defaultChecked?: boolean;
15
- disabled?: boolean;
16
- size?: "sm" | "default";
17
- fx?: PixelFxEffectId | "auto" | false;
18
- fxPalette?: EmpirePaletteId;
19
- onCheckedChange?: (checked: boolean) => void;
20
- "aria-label"?: string;
21
- "aria-labelledby"?: string;
22
- className?: string;
23
- }
24
-
25
- export const Switch = forwardRef<HTMLButtonElement, SwitchProps>(
26
- function Switch(
27
- {
28
- size = "default",
29
- fx = "auto",
30
- fxPalette,
31
- onCheckedChange,
32
- className,
33
- ...props
34
- }: SwitchProps,
35
- ref
36
- ) {
37
- const burst = usePixelFxBurst();
38
- const autoFx = resolveComponentPixelFx("switch", size);
39
- const resolvedEffectId =
40
- fx === false ? null : fx === "auto" ? autoFx.effectId : fx;
41
-
42
- return (
43
- <RadixSwitch.Root
44
- ref={ref}
45
- className={className ? `mw-ui-switch ${className}` : "mw-ui-switch"}
46
- data-size={size}
47
- data-pixelfx={resolvedEffectId ?? undefined}
48
- data-pixelfx-ready={resolvedEffectId ? "true" : undefined}
49
- onCheckedChange={(next) => {
50
- if (resolvedEffectId) burst.trigger();
51
- onCheckedChange?.(next);
52
- }}
53
- {...props}
54
- >
55
- <RadixSwitch.Thumb className="mw-ui-switch-thumb" />
56
- {resolvedEffectId ? (
57
- <PixelFxComponentLayer
58
- effectId={resolvedEffectId}
59
- paletteId={fxPalette ?? autoFx.paletteId}
60
- layer={autoFx.layer}
61
- loop={false}
62
- active={burst.active}
63
- speed={autoFx.speed}
64
- seed={autoFx.seed + burst.triggerKey}
65
- lightK={autoFx.lightK}
66
- triggerKey={burst.triggerKey}
67
- placement="burst"
68
- width={64}
69
- height={64}
70
- onComplete={burst.handleComplete}
71
- />
72
- ) : null}
73
- </RadixSwitch.Root>
74
- );
75
- }
76
- );