@almadar/ui 5.76.2 → 5.76.5

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.
@@ -575,14 +575,17 @@ function lazyFamilyIcon(libKey, importer, pick, fallbackName, family) {
575
575
  Wrapped.displayName = `Lazy.${libKey}.${fallbackName}`;
576
576
  return Wrapped;
577
577
  }
578
+ function isComponentLike(v) {
579
+ return v != null && (typeof v === "function" || typeof v === "object");
580
+ }
578
581
  function resolveLucide(name) {
579
582
  if (lucideAliases[name]) return lucideAliases[name];
580
583
  const pascal = kebabToPascal(name);
581
584
  const lucideMap = LucideIcons2;
582
585
  const direct = lucideMap[pascal];
583
- if (direct && typeof direct === "function") return direct;
586
+ if (isComponentLike(direct)) return direct;
584
587
  const asIs = lucideMap[name];
585
- if (asIs && typeof asIs === "function") return asIs;
588
+ if (isComponentLike(asIs)) return asIs;
586
589
  return LucideIcons2.HelpCircle;
587
590
  }
588
591
  function resolvePhosphor(name, weight, family) {
@@ -1226,12 +1229,13 @@ function resolveIcon(name) {
1226
1229
  }
1227
1230
  function doResolve(name) {
1228
1231
  if (iconAliases[name]) return iconAliases[name];
1232
+ const isComponentLike2 = (v) => v != null && (typeof v === "function" || typeof v === "object");
1229
1233
  const pascalName = kebabToPascal2(name);
1230
1234
  const lucideMap = LucideIcons2;
1231
1235
  const directLookup = lucideMap[pascalName];
1232
- if (directLookup && typeof directLookup === "object") return directLookup;
1236
+ if (isComponentLike2(directLookup)) return directLookup;
1233
1237
  const asIs = lucideMap[name];
1234
- if (asIs && typeof asIs === "object") return asIs;
1238
+ if (isComponentLike2(asIs)) return asIs;
1235
1239
  return LucideIcons2.HelpCircle;
1236
1240
  }
1237
1241
  var colorTokenClasses, iconAliases, resolvedCache, sizeClasses, animationClasses, Icon;
@@ -12100,14 +12104,318 @@ var init_useCanvasEffects = __esm({
12100
12104
  "use client";
12101
12105
  }
12102
12106
  });
12107
+ function pickPath(entry) {
12108
+ if (Array.isArray(entry.path)) {
12109
+ return entry.path[Math.floor(Math.random() * entry.path.length)];
12110
+ }
12111
+ return entry.path;
12112
+ }
12113
+ function useGameAudio({
12114
+ manifest,
12115
+ baseUrl = "",
12116
+ initialMuted = false,
12117
+ initialVolume = 1
12118
+ }) {
12119
+ const [muted, setMutedState] = useState(initialMuted);
12120
+ const [masterVolume, setMasterVolumeState] = useState(initialVolume);
12121
+ const mutedRef = useRef(muted);
12122
+ const volumeRef = useRef(masterVolume);
12123
+ const manifestRef = useRef(manifest);
12124
+ mutedRef.current = muted;
12125
+ volumeRef.current = masterVolume;
12126
+ manifestRef.current = manifest;
12127
+ const poolsRef = useRef(/* @__PURE__ */ new Map());
12128
+ const getOrCreateElement = useCallback((key) => {
12129
+ const entry = manifestRef.current[key];
12130
+ if (!entry) return null;
12131
+ let pool = poolsRef.current.get(key);
12132
+ if (!pool) {
12133
+ pool = [];
12134
+ poolsRef.current.set(key, pool);
12135
+ }
12136
+ const maxSize = entry.poolSize ?? 1;
12137
+ for (const audio of pool) {
12138
+ if (audio.paused && (audio.ended || audio.currentTime === 0)) {
12139
+ return audio;
12140
+ }
12141
+ }
12142
+ if (pool.length < maxSize) {
12143
+ const src = baseUrl + pickPath(entry);
12144
+ const audio = new Audio(src);
12145
+ audio.loop = entry.loop ?? false;
12146
+ pool.push(audio);
12147
+ return audio;
12148
+ }
12149
+ if (!entry.loop) {
12150
+ let oldest = pool[0];
12151
+ for (const audio of pool) {
12152
+ if (audio.currentTime > oldest.currentTime) {
12153
+ oldest = audio;
12154
+ }
12155
+ }
12156
+ oldest.pause();
12157
+ oldest.currentTime = 0;
12158
+ return oldest;
12159
+ }
12160
+ return null;
12161
+ }, [baseUrl]);
12162
+ const play = useCallback((key) => {
12163
+ if (mutedRef.current) return;
12164
+ const entry = manifestRef.current[key];
12165
+ if (!entry) return;
12166
+ const audio = getOrCreateElement(key);
12167
+ if (!audio) return;
12168
+ audio.volume = Math.min(1, (entry.volume ?? 1) * volumeRef.current);
12169
+ if (!entry.loop) {
12170
+ audio.currentTime = 0;
12171
+ }
12172
+ const promise = audio.play();
12173
+ if (promise) {
12174
+ promise.catch(() => {
12175
+ });
12176
+ }
12177
+ }, [getOrCreateElement]);
12178
+ const stop = useCallback((key) => {
12179
+ const pool = poolsRef.current.get(key);
12180
+ if (!pool) return;
12181
+ for (const audio of pool) {
12182
+ audio.pause();
12183
+ audio.currentTime = 0;
12184
+ }
12185
+ }, []);
12186
+ const currentMusicKeyRef = useRef(null);
12187
+ const currentMusicElRef = useRef(null);
12188
+ const musicFadeRef = useRef(null);
12189
+ const pendingMusicKeyRef = useRef(null);
12190
+ const clearMusicFade = useCallback(() => {
12191
+ if (musicFadeRef.current) {
12192
+ clearInterval(musicFadeRef.current);
12193
+ musicFadeRef.current = null;
12194
+ }
12195
+ }, []);
12196
+ const playMusic = useCallback((key) => {
12197
+ if (key === currentMusicKeyRef.current) return;
12198
+ pendingMusicKeyRef.current = key;
12199
+ const entry = manifestRef.current[key];
12200
+ if (!entry) return;
12201
+ const fadeDurationMs = entry.crossfadeDurationMs ?? 1500;
12202
+ const stepMs = 50;
12203
+ const totalSteps = Math.max(1, fadeDurationMs / stepMs);
12204
+ const targetVolume = Math.min(1, (entry.volume ?? 1) * volumeRef.current);
12205
+ clearMusicFade();
12206
+ const src = baseUrl + (Array.isArray(entry.path) ? entry.path[0] : entry.path);
12207
+ const incoming = new Audio(src);
12208
+ incoming.loop = true;
12209
+ incoming.volume = 0;
12210
+ const outgoing = currentMusicElRef.current;
12211
+ const outgoingStartVol = outgoing?.volume ?? 0;
12212
+ currentMusicKeyRef.current = key;
12213
+ currentMusicElRef.current = incoming;
12214
+ if (!mutedRef.current) {
12215
+ incoming.play().catch(() => {
12216
+ currentMusicKeyRef.current = null;
12217
+ currentMusicElRef.current = outgoing;
12218
+ });
12219
+ }
12220
+ let step = 0;
12221
+ musicFadeRef.current = setInterval(() => {
12222
+ step++;
12223
+ const progress = Math.min(step / totalSteps, 1);
12224
+ incoming.volume = Math.min(1, targetVolume * progress);
12225
+ if (outgoing) {
12226
+ outgoing.volume = Math.max(0, outgoingStartVol * (1 - progress));
12227
+ }
12228
+ if (progress >= 1) {
12229
+ clearMusicFade();
12230
+ if (outgoing) {
12231
+ outgoing.pause();
12232
+ outgoing.src = "";
12233
+ }
12234
+ }
12235
+ }, stepMs);
12236
+ }, [baseUrl, clearMusicFade]);
12237
+ const stopMusic = useCallback((fadeDurationMs = 1e3) => {
12238
+ const outgoing = currentMusicElRef.current;
12239
+ if (!outgoing) return;
12240
+ currentMusicKeyRef.current = null;
12241
+ currentMusicElRef.current = null;
12242
+ pendingMusicKeyRef.current = null;
12243
+ clearMusicFade();
12244
+ const startVolume = outgoing.volume;
12245
+ const stepMs = 50;
12246
+ const totalSteps = Math.max(1, fadeDurationMs / stepMs);
12247
+ let step = 0;
12248
+ musicFadeRef.current = setInterval(() => {
12249
+ step++;
12250
+ const progress = step / totalSteps;
12251
+ outgoing.volume = Math.max(0, startVolume * (1 - progress));
12252
+ if (progress >= 1) {
12253
+ clearMusicFade();
12254
+ outgoing.pause();
12255
+ outgoing.src = "";
12256
+ }
12257
+ }, stepMs);
12258
+ }, [clearMusicFade]);
12259
+ const stopAll = useCallback(() => {
12260
+ for (const pool of poolsRef.current.values()) {
12261
+ for (const audio of pool) {
12262
+ audio.pause();
12263
+ audio.currentTime = 0;
12264
+ }
12265
+ }
12266
+ stopMusic(0);
12267
+ }, [stopMusic]);
12268
+ const setMuted = useCallback((value) => {
12269
+ setMutedState(value);
12270
+ if (value) {
12271
+ for (const [key, pool] of poolsRef.current.entries()) {
12272
+ if (manifestRef.current[key]?.loop) {
12273
+ for (const audio of pool) {
12274
+ if (!audio.paused) audio.pause();
12275
+ }
12276
+ }
12277
+ }
12278
+ currentMusicElRef.current?.pause();
12279
+ } else {
12280
+ for (const [key, pool] of poolsRef.current.entries()) {
12281
+ const entry = manifestRef.current[key];
12282
+ if (entry?.loop && entry?.autostart) {
12283
+ for (const audio of pool) {
12284
+ if (audio.paused) audio.play().catch(() => {
12285
+ });
12286
+ }
12287
+ }
12288
+ }
12289
+ const musicEl = currentMusicElRef.current;
12290
+ if (musicEl) {
12291
+ musicEl.play().catch(() => {
12292
+ });
12293
+ }
12294
+ }
12295
+ }, []);
12296
+ const setMasterVolume = useCallback((volume) => {
12297
+ const clamped = Math.max(0, Math.min(1, volume));
12298
+ setMasterVolumeState(clamped);
12299
+ for (const [key, pool] of poolsRef.current.entries()) {
12300
+ const entryVol = manifestRef.current[key]?.volume ?? 1;
12301
+ for (const audio of pool) {
12302
+ audio.volume = Math.min(1, entryVol * clamped);
12303
+ }
12304
+ }
12305
+ if (!musicFadeRef.current && currentMusicElRef.current) {
12306
+ const key = currentMusicKeyRef.current;
12307
+ const entryVol = key ? manifestRef.current[key]?.volume ?? 1 : 1;
12308
+ currentMusicElRef.current.volume = Math.min(1, entryVol * clamped);
12309
+ }
12310
+ }, []);
12311
+ const unlockedRef = useRef(false);
12312
+ useEffect(() => {
12313
+ const autoKeys = Object.keys(manifest).filter((k) => manifest[k].autostart);
12314
+ const hasPendingMusic = () => pendingMusicKeyRef.current !== null;
12315
+ const hasAutoStart = autoKeys.length > 0;
12316
+ if (!hasAutoStart && !hasPendingMusic()) return;
12317
+ const unlock = () => {
12318
+ if (unlockedRef.current) return;
12319
+ unlockedRef.current = true;
12320
+ if (!mutedRef.current) {
12321
+ for (const key of autoKeys) {
12322
+ play(key);
12323
+ }
12324
+ const pending = pendingMusicKeyRef.current;
12325
+ if (pending && pending !== currentMusicKeyRef.current) {
12326
+ playMusic(pending);
12327
+ }
12328
+ }
12329
+ };
12330
+ document.addEventListener("click", unlock, { once: true });
12331
+ document.addEventListener("keydown", unlock, { once: true });
12332
+ document.addEventListener("touchstart", unlock, { once: true });
12333
+ return () => {
12334
+ document.removeEventListener("click", unlock);
12335
+ document.removeEventListener("keydown", unlock);
12336
+ document.removeEventListener("touchstart", unlock);
12337
+ };
12338
+ }, [manifest, play, playMusic]);
12339
+ useEffect(() => {
12340
+ return () => {
12341
+ clearMusicFade();
12342
+ for (const pool of poolsRef.current.values()) {
12343
+ for (const audio of pool) {
12344
+ audio.pause();
12345
+ audio.src = "";
12346
+ }
12347
+ }
12348
+ poolsRef.current.clear();
12349
+ if (currentMusicElRef.current) {
12350
+ currentMusicElRef.current.pause();
12351
+ currentMusicElRef.current.src = "";
12352
+ currentMusicElRef.current = null;
12353
+ }
12354
+ };
12355
+ }, [clearMusicFade]);
12356
+ return {
12357
+ play,
12358
+ stop,
12359
+ stopAll,
12360
+ playMusic,
12361
+ stopMusic,
12362
+ muted,
12363
+ setMuted,
12364
+ masterVolume,
12365
+ setMasterVolume
12366
+ };
12367
+ }
12103
12368
  var init_useGameAudio = __esm({
12104
12369
  "components/game/shared/hooks/useGameAudio.ts"() {
12105
12370
  "use client";
12371
+ useGameAudio.displayName = "useGameAudio";
12106
12372
  }
12107
12373
  });
12108
12374
  function useGameAudioContextOptional() {
12109
12375
  return useContext(GameAudioContext);
12110
12376
  }
12377
+ function GameAudioProvider({
12378
+ manifest,
12379
+ baseUrl = "",
12380
+ children,
12381
+ initialMuted = false
12382
+ }) {
12383
+ const eventBus = useEventBus();
12384
+ const { play, stop, stopAll, playMusic, stopMusic, muted, setMuted, masterVolume, setMasterVolume } = useGameAudio({ manifest, baseUrl, initialMuted });
12385
+ useEffect(() => {
12386
+ const unsubPlay = eventBus.on("UI:PLAY_SOUND", (event) => {
12387
+ const key = event.payload?.key;
12388
+ if (key) play(key);
12389
+ });
12390
+ const unsubStop = eventBus.on("UI:STOP_SOUND", (event) => {
12391
+ const key = event.payload?.key;
12392
+ if (key) {
12393
+ stop(key);
12394
+ } else {
12395
+ stopAll();
12396
+ }
12397
+ });
12398
+ const unsubChangeMusic = eventBus.on("UI:CHANGE_MUSIC", (event) => {
12399
+ const key = event.payload?.key;
12400
+ if (key) {
12401
+ playMusic(key);
12402
+ } else {
12403
+ stopMusic();
12404
+ }
12405
+ });
12406
+ const unsubStopMusic = eventBus.on("UI:STOP_MUSIC", () => {
12407
+ stopMusic();
12408
+ });
12409
+ return () => {
12410
+ unsubPlay();
12411
+ unsubStop();
12412
+ unsubChangeMusic();
12413
+ unsubStopMusic();
12414
+ };
12415
+ }, [eventBus, play, stop, stopAll, playMusic, stopMusic]);
12416
+ const value = { muted, setMuted, masterVolume, setMasterVolume, play, playMusic, stopMusic };
12417
+ return /* @__PURE__ */ jsx(GameAudioContext.Provider, { value, children });
12418
+ }
12111
12419
  var GameAudioContext;
12112
12420
  var init_GameAudioProvider = __esm({
12113
12421
  "components/game/shared/providers/GameAudioProvider.tsx"() {
@@ -12116,6 +12424,7 @@ var init_GameAudioProvider = __esm({
12116
12424
  init_useGameAudio();
12117
12425
  GameAudioContext = createContext(null);
12118
12426
  GameAudioContext.displayName = "GameAudioContext";
12427
+ GameAudioProvider.displayName = "GameAudioProvider";
12119
12428
  }
12120
12429
  });
12121
12430
  function GameAudioToggle({
@@ -50756,9 +51065,33 @@ var init_ToastSlot = __esm({
50756
51065
  ToastSlot.displayName = "ToastSlot";
50757
51066
  }
50758
51067
  });
50759
-
50760
- // components/core/organisms/component-registry.generated.ts
50761
- var COMPONENT_REGISTRY;
51068
+ function lazyThree(name, loader) {
51069
+ const Lazy = React107__default.lazy(
51070
+ () => loader().then((m) => {
51071
+ const Resolved = m[name];
51072
+ if (!Resolved) {
51073
+ throw new Error(
51074
+ `[@almadar/ui] 3D component "${name}" was not found in the three subpath bundle.`
51075
+ );
51076
+ }
51077
+ return { default: Resolved };
51078
+ })
51079
+ );
51080
+ function ThreeWrapper(props) {
51081
+ return React107__default.createElement(
51082
+ ThreeBoundary,
51083
+ { name },
51084
+ React107__default.createElement(
51085
+ React107__default.Suspense,
51086
+ { fallback: null },
51087
+ React107__default.createElement(Lazy, props)
51088
+ )
51089
+ );
51090
+ }
51091
+ ThreeWrapper.displayName = `Lazy(${name})`;
51092
+ return ThreeWrapper;
51093
+ }
51094
+ var ThreeBoundary, GameBoard3D, GameCanvas3D, GameCanvas3DBattleTemplate, GameCanvas3DCastleTemplate, GameCanvas3DWorldMapTemplate, COMPONENT_REGISTRY;
50762
51095
  var init_component_registry_generated = __esm({
50763
51096
  "components/core/organisms/component-registry.generated.ts"() {
50764
51097
  init_AboutPageTemplate();
@@ -50869,9 +51202,11 @@ var init_component_registry_generated = __esm({
50869
51202
  init_Form();
50870
51203
  init_FormField();
50871
51204
  init_FormSectionHeader();
51205
+ init_GameAudioProvider();
50872
51206
  init_GameAudioToggle();
50873
51207
  init_GameCard();
50874
51208
  init_GameHud();
51209
+ init_GameIcon();
50875
51210
  init_GameMenu();
50876
51211
  init_GameShell();
50877
51212
  init_GameTemplate();
@@ -51056,6 +51391,33 @@ var init_component_registry_generated = __esm({
51056
51391
  init_WizardProgress();
51057
51392
  init_WorldMapBoard();
51058
51393
  init_WorldMapTemplate();
51394
+ ThreeBoundary = class extends React107__default.Component {
51395
+ constructor() {
51396
+ super(...arguments);
51397
+ __publicField(this, "state", { failed: false });
51398
+ }
51399
+ static getDerivedStateFromError() {
51400
+ return { failed: true };
51401
+ }
51402
+ render() {
51403
+ if (this.state.failed) {
51404
+ return React107__default.createElement(
51405
+ "div",
51406
+ {
51407
+ "data-testid": "three-unavailable",
51408
+ style: { padding: 16, fontSize: 13, lineHeight: 1.5, opacity: 0.7 }
51409
+ },
51410
+ `3D pattern "${this.props.name}" requires three.js. Install the optional peers three + @react-three/fiber + @react-three/drei (matching the host React major) to render it.`
51411
+ );
51412
+ }
51413
+ return this.props.children;
51414
+ }
51415
+ };
51416
+ GameBoard3D = lazyThree("GameBoard3D", () => import('@almadar/ui/components/molecules/game/three'));
51417
+ GameCanvas3D = lazyThree("GameCanvas3D", () => import('@almadar/ui/components/molecules/game/three'));
51418
+ GameCanvas3DBattleTemplate = lazyThree("GameCanvas3DBattleTemplate", () => import('@almadar/ui/components/molecules/game/three'));
51419
+ GameCanvas3DCastleTemplate = lazyThree("GameCanvas3DCastleTemplate", () => import('@almadar/ui/components/molecules/game/three'));
51420
+ GameCanvas3DWorldMapTemplate = lazyThree("GameCanvas3DWorldMapTemplate", () => import('@almadar/ui/components/molecules/game/three'));
51059
51421
  COMPONENT_REGISTRY = {
51060
51422
  "AboutPageTemplate": AboutPageTemplate,
51061
51423
  "Accordion": Accordion,
@@ -51171,9 +51533,16 @@ var init_component_registry_generated = __esm({
51171
51533
  "Form": Form,
51172
51534
  "FormField": FormField,
51173
51535
  "FormSectionHeader": FormSectionHeader,
51536
+ "GameAudioProvider": GameAudioProvider,
51174
51537
  "GameAudioToggle": GameAudioToggle,
51538
+ "GameBoard3D": GameBoard3D,
51539
+ "GameCanvas3D": GameCanvas3D,
51540
+ "GameCanvas3DBattleTemplate": GameCanvas3DBattleTemplate,
51541
+ "GameCanvas3DCastleTemplate": GameCanvas3DCastleTemplate,
51542
+ "GameCanvas3DWorldMapTemplate": GameCanvas3DWorldMapTemplate,
51175
51543
  "GameCard": GameCard,
51176
51544
  "GameHud": GameHud,
51545
+ "GameIcon": GameIcon,
51177
51546
  "GameMenu": GameMenu,
51178
51547
  "GameShell": GameShell,
51179
51548
  "GameTemplate": GameTemplate,