@almadar/ui 5.76.2 → 5.76.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.
@@ -15900,14 +15900,318 @@ var init_useCanvasEffects = __esm({
15900
15900
  "use client";
15901
15901
  }
15902
15902
  });
15903
+ function pickPath(entry) {
15904
+ if (Array.isArray(entry.path)) {
15905
+ return entry.path[Math.floor(Math.random() * entry.path.length)];
15906
+ }
15907
+ return entry.path;
15908
+ }
15909
+ function useGameAudio({
15910
+ manifest,
15911
+ baseUrl = "",
15912
+ initialMuted = false,
15913
+ initialVolume = 1
15914
+ }) {
15915
+ const [muted, setMutedState] = React114.useState(initialMuted);
15916
+ const [masterVolume, setMasterVolumeState] = React114.useState(initialVolume);
15917
+ const mutedRef = React114.useRef(muted);
15918
+ const volumeRef = React114.useRef(masterVolume);
15919
+ const manifestRef = React114.useRef(manifest);
15920
+ mutedRef.current = muted;
15921
+ volumeRef.current = masterVolume;
15922
+ manifestRef.current = manifest;
15923
+ const poolsRef = React114.useRef(/* @__PURE__ */ new Map());
15924
+ const getOrCreateElement = React114.useCallback((key) => {
15925
+ const entry = manifestRef.current[key];
15926
+ if (!entry) return null;
15927
+ let pool = poolsRef.current.get(key);
15928
+ if (!pool) {
15929
+ pool = [];
15930
+ poolsRef.current.set(key, pool);
15931
+ }
15932
+ const maxSize = entry.poolSize ?? 1;
15933
+ for (const audio of pool) {
15934
+ if (audio.paused && (audio.ended || audio.currentTime === 0)) {
15935
+ return audio;
15936
+ }
15937
+ }
15938
+ if (pool.length < maxSize) {
15939
+ const src = baseUrl + pickPath(entry);
15940
+ const audio = new Audio(src);
15941
+ audio.loop = entry.loop ?? false;
15942
+ pool.push(audio);
15943
+ return audio;
15944
+ }
15945
+ if (!entry.loop) {
15946
+ let oldest = pool[0];
15947
+ for (const audio of pool) {
15948
+ if (audio.currentTime > oldest.currentTime) {
15949
+ oldest = audio;
15950
+ }
15951
+ }
15952
+ oldest.pause();
15953
+ oldest.currentTime = 0;
15954
+ return oldest;
15955
+ }
15956
+ return null;
15957
+ }, [baseUrl]);
15958
+ const play = React114.useCallback((key) => {
15959
+ if (mutedRef.current) return;
15960
+ const entry = manifestRef.current[key];
15961
+ if (!entry) return;
15962
+ const audio = getOrCreateElement(key);
15963
+ if (!audio) return;
15964
+ audio.volume = Math.min(1, (entry.volume ?? 1) * volumeRef.current);
15965
+ if (!entry.loop) {
15966
+ audio.currentTime = 0;
15967
+ }
15968
+ const promise = audio.play();
15969
+ if (promise) {
15970
+ promise.catch(() => {
15971
+ });
15972
+ }
15973
+ }, [getOrCreateElement]);
15974
+ const stop = React114.useCallback((key) => {
15975
+ const pool = poolsRef.current.get(key);
15976
+ if (!pool) return;
15977
+ for (const audio of pool) {
15978
+ audio.pause();
15979
+ audio.currentTime = 0;
15980
+ }
15981
+ }, []);
15982
+ const currentMusicKeyRef = React114.useRef(null);
15983
+ const currentMusicElRef = React114.useRef(null);
15984
+ const musicFadeRef = React114.useRef(null);
15985
+ const pendingMusicKeyRef = React114.useRef(null);
15986
+ const clearMusicFade = React114.useCallback(() => {
15987
+ if (musicFadeRef.current) {
15988
+ clearInterval(musicFadeRef.current);
15989
+ musicFadeRef.current = null;
15990
+ }
15991
+ }, []);
15992
+ const playMusic = React114.useCallback((key) => {
15993
+ if (key === currentMusicKeyRef.current) return;
15994
+ pendingMusicKeyRef.current = key;
15995
+ const entry = manifestRef.current[key];
15996
+ if (!entry) return;
15997
+ const fadeDurationMs = entry.crossfadeDurationMs ?? 1500;
15998
+ const stepMs = 50;
15999
+ const totalSteps = Math.max(1, fadeDurationMs / stepMs);
16000
+ const targetVolume = Math.min(1, (entry.volume ?? 1) * volumeRef.current);
16001
+ clearMusicFade();
16002
+ const src = baseUrl + (Array.isArray(entry.path) ? entry.path[0] : entry.path);
16003
+ const incoming = new Audio(src);
16004
+ incoming.loop = true;
16005
+ incoming.volume = 0;
16006
+ const outgoing = currentMusicElRef.current;
16007
+ const outgoingStartVol = outgoing?.volume ?? 0;
16008
+ currentMusicKeyRef.current = key;
16009
+ currentMusicElRef.current = incoming;
16010
+ if (!mutedRef.current) {
16011
+ incoming.play().catch(() => {
16012
+ currentMusicKeyRef.current = null;
16013
+ currentMusicElRef.current = outgoing;
16014
+ });
16015
+ }
16016
+ let step = 0;
16017
+ musicFadeRef.current = setInterval(() => {
16018
+ step++;
16019
+ const progress = Math.min(step / totalSteps, 1);
16020
+ incoming.volume = Math.min(1, targetVolume * progress);
16021
+ if (outgoing) {
16022
+ outgoing.volume = Math.max(0, outgoingStartVol * (1 - progress));
16023
+ }
16024
+ if (progress >= 1) {
16025
+ clearMusicFade();
16026
+ if (outgoing) {
16027
+ outgoing.pause();
16028
+ outgoing.src = "";
16029
+ }
16030
+ }
16031
+ }, stepMs);
16032
+ }, [baseUrl, clearMusicFade]);
16033
+ const stopMusic = React114.useCallback((fadeDurationMs = 1e3) => {
16034
+ const outgoing = currentMusicElRef.current;
16035
+ if (!outgoing) return;
16036
+ currentMusicKeyRef.current = null;
16037
+ currentMusicElRef.current = null;
16038
+ pendingMusicKeyRef.current = null;
16039
+ clearMusicFade();
16040
+ const startVolume = outgoing.volume;
16041
+ const stepMs = 50;
16042
+ const totalSteps = Math.max(1, fadeDurationMs / stepMs);
16043
+ let step = 0;
16044
+ musicFadeRef.current = setInterval(() => {
16045
+ step++;
16046
+ const progress = step / totalSteps;
16047
+ outgoing.volume = Math.max(0, startVolume * (1 - progress));
16048
+ if (progress >= 1) {
16049
+ clearMusicFade();
16050
+ outgoing.pause();
16051
+ outgoing.src = "";
16052
+ }
16053
+ }, stepMs);
16054
+ }, [clearMusicFade]);
16055
+ const stopAll = React114.useCallback(() => {
16056
+ for (const pool of poolsRef.current.values()) {
16057
+ for (const audio of pool) {
16058
+ audio.pause();
16059
+ audio.currentTime = 0;
16060
+ }
16061
+ }
16062
+ stopMusic(0);
16063
+ }, [stopMusic]);
16064
+ const setMuted = React114.useCallback((value) => {
16065
+ setMutedState(value);
16066
+ if (value) {
16067
+ for (const [key, pool] of poolsRef.current.entries()) {
16068
+ if (manifestRef.current[key]?.loop) {
16069
+ for (const audio of pool) {
16070
+ if (!audio.paused) audio.pause();
16071
+ }
16072
+ }
16073
+ }
16074
+ currentMusicElRef.current?.pause();
16075
+ } else {
16076
+ for (const [key, pool] of poolsRef.current.entries()) {
16077
+ const entry = manifestRef.current[key];
16078
+ if (entry?.loop && entry?.autostart) {
16079
+ for (const audio of pool) {
16080
+ if (audio.paused) audio.play().catch(() => {
16081
+ });
16082
+ }
16083
+ }
16084
+ }
16085
+ const musicEl = currentMusicElRef.current;
16086
+ if (musicEl) {
16087
+ musicEl.play().catch(() => {
16088
+ });
16089
+ }
16090
+ }
16091
+ }, []);
16092
+ const setMasterVolume = React114.useCallback((volume) => {
16093
+ const clamped = Math.max(0, Math.min(1, volume));
16094
+ setMasterVolumeState(clamped);
16095
+ for (const [key, pool] of poolsRef.current.entries()) {
16096
+ const entryVol = manifestRef.current[key]?.volume ?? 1;
16097
+ for (const audio of pool) {
16098
+ audio.volume = Math.min(1, entryVol * clamped);
16099
+ }
16100
+ }
16101
+ if (!musicFadeRef.current && currentMusicElRef.current) {
16102
+ const key = currentMusicKeyRef.current;
16103
+ const entryVol = key ? manifestRef.current[key]?.volume ?? 1 : 1;
16104
+ currentMusicElRef.current.volume = Math.min(1, entryVol * clamped);
16105
+ }
16106
+ }, []);
16107
+ const unlockedRef = React114.useRef(false);
16108
+ React114.useEffect(() => {
16109
+ const autoKeys = Object.keys(manifest).filter((k) => manifest[k].autostart);
16110
+ const hasPendingMusic = () => pendingMusicKeyRef.current !== null;
16111
+ const hasAutoStart = autoKeys.length > 0;
16112
+ if (!hasAutoStart && !hasPendingMusic()) return;
16113
+ const unlock = () => {
16114
+ if (unlockedRef.current) return;
16115
+ unlockedRef.current = true;
16116
+ if (!mutedRef.current) {
16117
+ for (const key of autoKeys) {
16118
+ play(key);
16119
+ }
16120
+ const pending = pendingMusicKeyRef.current;
16121
+ if (pending && pending !== currentMusicKeyRef.current) {
16122
+ playMusic(pending);
16123
+ }
16124
+ }
16125
+ };
16126
+ document.addEventListener("click", unlock, { once: true });
16127
+ document.addEventListener("keydown", unlock, { once: true });
16128
+ document.addEventListener("touchstart", unlock, { once: true });
16129
+ return () => {
16130
+ document.removeEventListener("click", unlock);
16131
+ document.removeEventListener("keydown", unlock);
16132
+ document.removeEventListener("touchstart", unlock);
16133
+ };
16134
+ }, [manifest, play, playMusic]);
16135
+ React114.useEffect(() => {
16136
+ return () => {
16137
+ clearMusicFade();
16138
+ for (const pool of poolsRef.current.values()) {
16139
+ for (const audio of pool) {
16140
+ audio.pause();
16141
+ audio.src = "";
16142
+ }
16143
+ }
16144
+ poolsRef.current.clear();
16145
+ if (currentMusicElRef.current) {
16146
+ currentMusicElRef.current.pause();
16147
+ currentMusicElRef.current.src = "";
16148
+ currentMusicElRef.current = null;
16149
+ }
16150
+ };
16151
+ }, [clearMusicFade]);
16152
+ return {
16153
+ play,
16154
+ stop,
16155
+ stopAll,
16156
+ playMusic,
16157
+ stopMusic,
16158
+ muted,
16159
+ setMuted,
16160
+ masterVolume,
16161
+ setMasterVolume
16162
+ };
16163
+ }
15903
16164
  var init_useGameAudio = __esm({
15904
16165
  "components/game/shared/hooks/useGameAudio.ts"() {
15905
16166
  "use client";
16167
+ useGameAudio.displayName = "useGameAudio";
15906
16168
  }
15907
16169
  });
15908
16170
  function useGameAudioContextOptional() {
15909
16171
  return React114.useContext(GameAudioContext);
15910
16172
  }
16173
+ function GameAudioProvider({
16174
+ manifest,
16175
+ baseUrl = "",
16176
+ children,
16177
+ initialMuted = false
16178
+ }) {
16179
+ const eventBus = useEventBus();
16180
+ const { play, stop, stopAll, playMusic, stopMusic, muted, setMuted, masterVolume, setMasterVolume } = useGameAudio({ manifest, baseUrl, initialMuted });
16181
+ React114.useEffect(() => {
16182
+ const unsubPlay = eventBus.on("UI:PLAY_SOUND", (event) => {
16183
+ const key = event.payload?.key;
16184
+ if (key) play(key);
16185
+ });
16186
+ const unsubStop = eventBus.on("UI:STOP_SOUND", (event) => {
16187
+ const key = event.payload?.key;
16188
+ if (key) {
16189
+ stop(key);
16190
+ } else {
16191
+ stopAll();
16192
+ }
16193
+ });
16194
+ const unsubChangeMusic = eventBus.on("UI:CHANGE_MUSIC", (event) => {
16195
+ const key = event.payload?.key;
16196
+ if (key) {
16197
+ playMusic(key);
16198
+ } else {
16199
+ stopMusic();
16200
+ }
16201
+ });
16202
+ const unsubStopMusic = eventBus.on("UI:STOP_MUSIC", () => {
16203
+ stopMusic();
16204
+ });
16205
+ return () => {
16206
+ unsubPlay();
16207
+ unsubStop();
16208
+ unsubChangeMusic();
16209
+ unsubStopMusic();
16210
+ };
16211
+ }, [eventBus, play, stop, stopAll, playMusic, stopMusic]);
16212
+ const value = { muted, setMuted, masterVolume, setMasterVolume, play, playMusic, stopMusic };
16213
+ return /* @__PURE__ */ jsxRuntime.jsx(GameAudioContext.Provider, { value, children });
16214
+ }
15911
16215
  var GameAudioContext;
15912
16216
  var init_GameAudioProvider = __esm({
15913
16217
  "components/game/shared/providers/GameAudioProvider.tsx"() {
@@ -15916,6 +16220,7 @@ var init_GameAudioProvider = __esm({
15916
16220
  init_useGameAudio();
15917
16221
  GameAudioContext = React114.createContext(null);
15918
16222
  GameAudioContext.displayName = "GameAudioContext";
16223
+ GameAudioProvider.displayName = "GameAudioProvider";
15919
16224
  }
15920
16225
  });
15921
16226
  function GameAudioToggle({
@@ -52956,9 +53261,33 @@ var init_ToastSlot = __esm({
52956
53261
  ToastSlot.displayName = "ToastSlot";
52957
53262
  }
52958
53263
  });
52959
-
52960
- // components/core/organisms/component-registry.generated.ts
52961
- var COMPONENT_REGISTRY;
53264
+ function lazyThree(name, loader) {
53265
+ const Lazy = React114__namespace.default.lazy(
53266
+ () => loader().then((m) => {
53267
+ const Resolved = m[name];
53268
+ if (!Resolved) {
53269
+ throw new Error(
53270
+ `[@almadar/ui] 3D component "${name}" was not found in the three subpath bundle.`
53271
+ );
53272
+ }
53273
+ return { default: Resolved };
53274
+ })
53275
+ );
53276
+ function ThreeWrapper(props) {
53277
+ return React114__namespace.default.createElement(
53278
+ ThreeBoundary,
53279
+ { name },
53280
+ React114__namespace.default.createElement(
53281
+ React114__namespace.default.Suspense,
53282
+ { fallback: null },
53283
+ React114__namespace.default.createElement(Lazy, props)
53284
+ )
53285
+ );
53286
+ }
53287
+ ThreeWrapper.displayName = `Lazy(${name})`;
53288
+ return ThreeWrapper;
53289
+ }
53290
+ var ThreeBoundary, GameBoard3D, GameCanvas3D, GameCanvas3DBattleTemplate, GameCanvas3DCastleTemplate, GameCanvas3DWorldMapTemplate, COMPONENT_REGISTRY;
52962
53291
  var init_component_registry_generated = __esm({
52963
53292
  "components/core/organisms/component-registry.generated.ts"() {
52964
53293
  init_AboutPageTemplate();
@@ -53069,9 +53398,11 @@ var init_component_registry_generated = __esm({
53069
53398
  init_Form();
53070
53399
  init_FormField();
53071
53400
  init_FormSectionHeader();
53401
+ init_GameAudioProvider();
53072
53402
  init_GameAudioToggle();
53073
53403
  init_GameCard();
53074
53404
  init_GameHud();
53405
+ init_GameIcon();
53075
53406
  init_GameMenu();
53076
53407
  init_GameShell();
53077
53408
  init_GameTemplate();
@@ -53256,6 +53587,33 @@ var init_component_registry_generated = __esm({
53256
53587
  init_WizardProgress();
53257
53588
  init_WorldMapBoard();
53258
53589
  init_WorldMapTemplate();
53590
+ ThreeBoundary = class extends React114__namespace.default.Component {
53591
+ constructor() {
53592
+ super(...arguments);
53593
+ __publicField(this, "state", { failed: false });
53594
+ }
53595
+ static getDerivedStateFromError() {
53596
+ return { failed: true };
53597
+ }
53598
+ render() {
53599
+ if (this.state.failed) {
53600
+ return React114__namespace.default.createElement(
53601
+ "div",
53602
+ {
53603
+ "data-testid": "three-unavailable",
53604
+ style: { padding: 16, fontSize: 13, lineHeight: 1.5, opacity: 0.7 }
53605
+ },
53606
+ `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.`
53607
+ );
53608
+ }
53609
+ return this.props.children;
53610
+ }
53611
+ };
53612
+ GameBoard3D = lazyThree("GameBoard3D", () => import('@almadar/ui/components/molecules/game/three'));
53613
+ GameCanvas3D = lazyThree("GameCanvas3D", () => import('@almadar/ui/components/molecules/game/three'));
53614
+ GameCanvas3DBattleTemplate = lazyThree("GameCanvas3DBattleTemplate", () => import('@almadar/ui/components/molecules/game/three'));
53615
+ GameCanvas3DCastleTemplate = lazyThree("GameCanvas3DCastleTemplate", () => import('@almadar/ui/components/molecules/game/three'));
53616
+ GameCanvas3DWorldMapTemplate = lazyThree("GameCanvas3DWorldMapTemplate", () => import('@almadar/ui/components/molecules/game/three'));
53259
53617
  COMPONENT_REGISTRY = {
53260
53618
  "AboutPageTemplate": AboutPageTemplate,
53261
53619
  "Accordion": Accordion,
@@ -53371,9 +53729,16 @@ var init_component_registry_generated = __esm({
53371
53729
  "Form": Form,
53372
53730
  "FormField": FormField,
53373
53731
  "FormSectionHeader": FormSectionHeader,
53732
+ "GameAudioProvider": GameAudioProvider,
53374
53733
  "GameAudioToggle": GameAudioToggle,
53734
+ "GameBoard3D": GameBoard3D,
53735
+ "GameCanvas3D": GameCanvas3D,
53736
+ "GameCanvas3DBattleTemplate": GameCanvas3DBattleTemplate,
53737
+ "GameCanvas3DCastleTemplate": GameCanvas3DCastleTemplate,
53738
+ "GameCanvas3DWorldMapTemplate": GameCanvas3DWorldMapTemplate,
53375
53739
  "GameCard": GameCard,
53376
53740
  "GameHud": GameHud,
53741
+ "GameIcon": GameIcon,
53377
53742
  "GameMenu": GameMenu,
53378
53743
  "GameShell": GameShell,
53379
53744
  "GameTemplate": GameTemplate,