@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.
@@ -12492,14 +12492,318 @@ var init_useCanvasEffects = __esm({
12492
12492
  "use client";
12493
12493
  }
12494
12494
  });
12495
+ function pickPath(entry) {
12496
+ if (Array.isArray(entry.path)) {
12497
+ return entry.path[Math.floor(Math.random() * entry.path.length)];
12498
+ }
12499
+ return entry.path;
12500
+ }
12501
+ function useGameAudio({
12502
+ manifest,
12503
+ baseUrl = "",
12504
+ initialMuted = false,
12505
+ initialVolume = 1
12506
+ }) {
12507
+ const [muted, setMutedState] = React105.useState(initialMuted);
12508
+ const [masterVolume, setMasterVolumeState] = React105.useState(initialVolume);
12509
+ const mutedRef = React105.useRef(muted);
12510
+ const volumeRef = React105.useRef(masterVolume);
12511
+ const manifestRef = React105.useRef(manifest);
12512
+ mutedRef.current = muted;
12513
+ volumeRef.current = masterVolume;
12514
+ manifestRef.current = manifest;
12515
+ const poolsRef = React105.useRef(/* @__PURE__ */ new Map());
12516
+ const getOrCreateElement = React105.useCallback((key) => {
12517
+ const entry = manifestRef.current[key];
12518
+ if (!entry) return null;
12519
+ let pool = poolsRef.current.get(key);
12520
+ if (!pool) {
12521
+ pool = [];
12522
+ poolsRef.current.set(key, pool);
12523
+ }
12524
+ const maxSize = entry.poolSize ?? 1;
12525
+ for (const audio of pool) {
12526
+ if (audio.paused && (audio.ended || audio.currentTime === 0)) {
12527
+ return audio;
12528
+ }
12529
+ }
12530
+ if (pool.length < maxSize) {
12531
+ const src = baseUrl + pickPath(entry);
12532
+ const audio = new Audio(src);
12533
+ audio.loop = entry.loop ?? false;
12534
+ pool.push(audio);
12535
+ return audio;
12536
+ }
12537
+ if (!entry.loop) {
12538
+ let oldest = pool[0];
12539
+ for (const audio of pool) {
12540
+ if (audio.currentTime > oldest.currentTime) {
12541
+ oldest = audio;
12542
+ }
12543
+ }
12544
+ oldest.pause();
12545
+ oldest.currentTime = 0;
12546
+ return oldest;
12547
+ }
12548
+ return null;
12549
+ }, [baseUrl]);
12550
+ const play = React105.useCallback((key) => {
12551
+ if (mutedRef.current) return;
12552
+ const entry = manifestRef.current[key];
12553
+ if (!entry) return;
12554
+ const audio = getOrCreateElement(key);
12555
+ if (!audio) return;
12556
+ audio.volume = Math.min(1, (entry.volume ?? 1) * volumeRef.current);
12557
+ if (!entry.loop) {
12558
+ audio.currentTime = 0;
12559
+ }
12560
+ const promise = audio.play();
12561
+ if (promise) {
12562
+ promise.catch(() => {
12563
+ });
12564
+ }
12565
+ }, [getOrCreateElement]);
12566
+ const stop = React105.useCallback((key) => {
12567
+ const pool = poolsRef.current.get(key);
12568
+ if (!pool) return;
12569
+ for (const audio of pool) {
12570
+ audio.pause();
12571
+ audio.currentTime = 0;
12572
+ }
12573
+ }, []);
12574
+ const currentMusicKeyRef = React105.useRef(null);
12575
+ const currentMusicElRef = React105.useRef(null);
12576
+ const musicFadeRef = React105.useRef(null);
12577
+ const pendingMusicKeyRef = React105.useRef(null);
12578
+ const clearMusicFade = React105.useCallback(() => {
12579
+ if (musicFadeRef.current) {
12580
+ clearInterval(musicFadeRef.current);
12581
+ musicFadeRef.current = null;
12582
+ }
12583
+ }, []);
12584
+ const playMusic = React105.useCallback((key) => {
12585
+ if (key === currentMusicKeyRef.current) return;
12586
+ pendingMusicKeyRef.current = key;
12587
+ const entry = manifestRef.current[key];
12588
+ if (!entry) return;
12589
+ const fadeDurationMs = entry.crossfadeDurationMs ?? 1500;
12590
+ const stepMs = 50;
12591
+ const totalSteps = Math.max(1, fadeDurationMs / stepMs);
12592
+ const targetVolume = Math.min(1, (entry.volume ?? 1) * volumeRef.current);
12593
+ clearMusicFade();
12594
+ const src = baseUrl + (Array.isArray(entry.path) ? entry.path[0] : entry.path);
12595
+ const incoming = new Audio(src);
12596
+ incoming.loop = true;
12597
+ incoming.volume = 0;
12598
+ const outgoing = currentMusicElRef.current;
12599
+ const outgoingStartVol = outgoing?.volume ?? 0;
12600
+ currentMusicKeyRef.current = key;
12601
+ currentMusicElRef.current = incoming;
12602
+ if (!mutedRef.current) {
12603
+ incoming.play().catch(() => {
12604
+ currentMusicKeyRef.current = null;
12605
+ currentMusicElRef.current = outgoing;
12606
+ });
12607
+ }
12608
+ let step = 0;
12609
+ musicFadeRef.current = setInterval(() => {
12610
+ step++;
12611
+ const progress = Math.min(step / totalSteps, 1);
12612
+ incoming.volume = Math.min(1, targetVolume * progress);
12613
+ if (outgoing) {
12614
+ outgoing.volume = Math.max(0, outgoingStartVol * (1 - progress));
12615
+ }
12616
+ if (progress >= 1) {
12617
+ clearMusicFade();
12618
+ if (outgoing) {
12619
+ outgoing.pause();
12620
+ outgoing.src = "";
12621
+ }
12622
+ }
12623
+ }, stepMs);
12624
+ }, [baseUrl, clearMusicFade]);
12625
+ const stopMusic = React105.useCallback((fadeDurationMs = 1e3) => {
12626
+ const outgoing = currentMusicElRef.current;
12627
+ if (!outgoing) return;
12628
+ currentMusicKeyRef.current = null;
12629
+ currentMusicElRef.current = null;
12630
+ pendingMusicKeyRef.current = null;
12631
+ clearMusicFade();
12632
+ const startVolume = outgoing.volume;
12633
+ const stepMs = 50;
12634
+ const totalSteps = Math.max(1, fadeDurationMs / stepMs);
12635
+ let step = 0;
12636
+ musicFadeRef.current = setInterval(() => {
12637
+ step++;
12638
+ const progress = step / totalSteps;
12639
+ outgoing.volume = Math.max(0, startVolume * (1 - progress));
12640
+ if (progress >= 1) {
12641
+ clearMusicFade();
12642
+ outgoing.pause();
12643
+ outgoing.src = "";
12644
+ }
12645
+ }, stepMs);
12646
+ }, [clearMusicFade]);
12647
+ const stopAll = React105.useCallback(() => {
12648
+ for (const pool of poolsRef.current.values()) {
12649
+ for (const audio of pool) {
12650
+ audio.pause();
12651
+ audio.currentTime = 0;
12652
+ }
12653
+ }
12654
+ stopMusic(0);
12655
+ }, [stopMusic]);
12656
+ const setMuted = React105.useCallback((value) => {
12657
+ setMutedState(value);
12658
+ if (value) {
12659
+ for (const [key, pool] of poolsRef.current.entries()) {
12660
+ if (manifestRef.current[key]?.loop) {
12661
+ for (const audio of pool) {
12662
+ if (!audio.paused) audio.pause();
12663
+ }
12664
+ }
12665
+ }
12666
+ currentMusicElRef.current?.pause();
12667
+ } else {
12668
+ for (const [key, pool] of poolsRef.current.entries()) {
12669
+ const entry = manifestRef.current[key];
12670
+ if (entry?.loop && entry?.autostart) {
12671
+ for (const audio of pool) {
12672
+ if (audio.paused) audio.play().catch(() => {
12673
+ });
12674
+ }
12675
+ }
12676
+ }
12677
+ const musicEl = currentMusicElRef.current;
12678
+ if (musicEl) {
12679
+ musicEl.play().catch(() => {
12680
+ });
12681
+ }
12682
+ }
12683
+ }, []);
12684
+ const setMasterVolume = React105.useCallback((volume) => {
12685
+ const clamped = Math.max(0, Math.min(1, volume));
12686
+ setMasterVolumeState(clamped);
12687
+ for (const [key, pool] of poolsRef.current.entries()) {
12688
+ const entryVol = manifestRef.current[key]?.volume ?? 1;
12689
+ for (const audio of pool) {
12690
+ audio.volume = Math.min(1, entryVol * clamped);
12691
+ }
12692
+ }
12693
+ if (!musicFadeRef.current && currentMusicElRef.current) {
12694
+ const key = currentMusicKeyRef.current;
12695
+ const entryVol = key ? manifestRef.current[key]?.volume ?? 1 : 1;
12696
+ currentMusicElRef.current.volume = Math.min(1, entryVol * clamped);
12697
+ }
12698
+ }, []);
12699
+ const unlockedRef = React105.useRef(false);
12700
+ React105.useEffect(() => {
12701
+ const autoKeys = Object.keys(manifest).filter((k) => manifest[k].autostart);
12702
+ const hasPendingMusic = () => pendingMusicKeyRef.current !== null;
12703
+ const hasAutoStart = autoKeys.length > 0;
12704
+ if (!hasAutoStart && !hasPendingMusic()) return;
12705
+ const unlock = () => {
12706
+ if (unlockedRef.current) return;
12707
+ unlockedRef.current = true;
12708
+ if (!mutedRef.current) {
12709
+ for (const key of autoKeys) {
12710
+ play(key);
12711
+ }
12712
+ const pending = pendingMusicKeyRef.current;
12713
+ if (pending && pending !== currentMusicKeyRef.current) {
12714
+ playMusic(pending);
12715
+ }
12716
+ }
12717
+ };
12718
+ document.addEventListener("click", unlock, { once: true });
12719
+ document.addEventListener("keydown", unlock, { once: true });
12720
+ document.addEventListener("touchstart", unlock, { once: true });
12721
+ return () => {
12722
+ document.removeEventListener("click", unlock);
12723
+ document.removeEventListener("keydown", unlock);
12724
+ document.removeEventListener("touchstart", unlock);
12725
+ };
12726
+ }, [manifest, play, playMusic]);
12727
+ React105.useEffect(() => {
12728
+ return () => {
12729
+ clearMusicFade();
12730
+ for (const pool of poolsRef.current.values()) {
12731
+ for (const audio of pool) {
12732
+ audio.pause();
12733
+ audio.src = "";
12734
+ }
12735
+ }
12736
+ poolsRef.current.clear();
12737
+ if (currentMusicElRef.current) {
12738
+ currentMusicElRef.current.pause();
12739
+ currentMusicElRef.current.src = "";
12740
+ currentMusicElRef.current = null;
12741
+ }
12742
+ };
12743
+ }, [clearMusicFade]);
12744
+ return {
12745
+ play,
12746
+ stop,
12747
+ stopAll,
12748
+ playMusic,
12749
+ stopMusic,
12750
+ muted,
12751
+ setMuted,
12752
+ masterVolume,
12753
+ setMasterVolume
12754
+ };
12755
+ }
12495
12756
  var init_useGameAudio = __esm({
12496
12757
  "components/game/shared/hooks/useGameAudio.ts"() {
12497
12758
  "use client";
12759
+ useGameAudio.displayName = "useGameAudio";
12498
12760
  }
12499
12761
  });
12500
12762
  function useGameAudioContextOptional() {
12501
12763
  return React105.useContext(GameAudioContext);
12502
12764
  }
12765
+ function GameAudioProvider({
12766
+ manifest,
12767
+ baseUrl = "",
12768
+ children,
12769
+ initialMuted = false
12770
+ }) {
12771
+ const eventBus = useEventBus();
12772
+ const { play, stop, stopAll, playMusic, stopMusic, muted, setMuted, masterVolume, setMasterVolume } = useGameAudio({ manifest, baseUrl, initialMuted });
12773
+ React105.useEffect(() => {
12774
+ const unsubPlay = eventBus.on("UI:PLAY_SOUND", (event) => {
12775
+ const key = event.payload?.key;
12776
+ if (key) play(key);
12777
+ });
12778
+ const unsubStop = eventBus.on("UI:STOP_SOUND", (event) => {
12779
+ const key = event.payload?.key;
12780
+ if (key) {
12781
+ stop(key);
12782
+ } else {
12783
+ stopAll();
12784
+ }
12785
+ });
12786
+ const unsubChangeMusic = eventBus.on("UI:CHANGE_MUSIC", (event) => {
12787
+ const key = event.payload?.key;
12788
+ if (key) {
12789
+ playMusic(key);
12790
+ } else {
12791
+ stopMusic();
12792
+ }
12793
+ });
12794
+ const unsubStopMusic = eventBus.on("UI:STOP_MUSIC", () => {
12795
+ stopMusic();
12796
+ });
12797
+ return () => {
12798
+ unsubPlay();
12799
+ unsubStop();
12800
+ unsubChangeMusic();
12801
+ unsubStopMusic();
12802
+ };
12803
+ }, [eventBus, play, stop, stopAll, playMusic, stopMusic]);
12804
+ const value = { muted, setMuted, masterVolume, setMasterVolume, play, playMusic, stopMusic };
12805
+ return /* @__PURE__ */ jsxRuntime.jsx(GameAudioContext.Provider, { value, children });
12806
+ }
12503
12807
  var GameAudioContext;
12504
12808
  var init_GameAudioProvider = __esm({
12505
12809
  "components/game/shared/providers/GameAudioProvider.tsx"() {
@@ -12508,6 +12812,7 @@ var init_GameAudioProvider = __esm({
12508
12812
  init_useGameAudio();
12509
12813
  GameAudioContext = React105.createContext(null);
12510
12814
  GameAudioContext.displayName = "GameAudioContext";
12815
+ GameAudioProvider.displayName = "GameAudioProvider";
12511
12816
  }
12512
12817
  });
12513
12818
  function GameAudioToggle({
@@ -50451,9 +50756,33 @@ var init_ToastSlot = __esm({
50451
50756
  ToastSlot.displayName = "ToastSlot";
50452
50757
  }
50453
50758
  });
50454
-
50455
- // components/core/organisms/component-registry.generated.ts
50456
- var COMPONENT_REGISTRY;
50759
+ function lazyThree(name, loader) {
50760
+ const Lazy = React105__namespace.default.lazy(
50761
+ () => loader().then((m) => {
50762
+ const Resolved = m[name];
50763
+ if (!Resolved) {
50764
+ throw new Error(
50765
+ `[@almadar/ui] 3D component "${name}" was not found in the three subpath bundle.`
50766
+ );
50767
+ }
50768
+ return { default: Resolved };
50769
+ })
50770
+ );
50771
+ function ThreeWrapper(props) {
50772
+ return React105__namespace.default.createElement(
50773
+ ThreeBoundary,
50774
+ { name },
50775
+ React105__namespace.default.createElement(
50776
+ React105__namespace.default.Suspense,
50777
+ { fallback: null },
50778
+ React105__namespace.default.createElement(Lazy, props)
50779
+ )
50780
+ );
50781
+ }
50782
+ ThreeWrapper.displayName = `Lazy(${name})`;
50783
+ return ThreeWrapper;
50784
+ }
50785
+ var ThreeBoundary, GameBoard3D, GameCanvas3D, GameCanvas3DBattleTemplate, GameCanvas3DCastleTemplate, GameCanvas3DWorldMapTemplate, COMPONENT_REGISTRY;
50457
50786
  var init_component_registry_generated = __esm({
50458
50787
  "components/core/organisms/component-registry.generated.ts"() {
50459
50788
  init_AboutPageTemplate();
@@ -50564,9 +50893,11 @@ var init_component_registry_generated = __esm({
50564
50893
  init_Form();
50565
50894
  init_FormField();
50566
50895
  init_FormSectionHeader();
50896
+ init_GameAudioProvider();
50567
50897
  init_GameAudioToggle();
50568
50898
  init_GameCard();
50569
50899
  init_GameHud();
50900
+ init_GameIcon();
50570
50901
  init_GameMenu();
50571
50902
  init_GameShell();
50572
50903
  init_GameTemplate();
@@ -50751,6 +51082,33 @@ var init_component_registry_generated = __esm({
50751
51082
  init_WizardProgress();
50752
51083
  init_WorldMapBoard();
50753
51084
  init_WorldMapTemplate();
51085
+ ThreeBoundary = class extends React105__namespace.default.Component {
51086
+ constructor() {
51087
+ super(...arguments);
51088
+ __publicField(this, "state", { failed: false });
51089
+ }
51090
+ static getDerivedStateFromError() {
51091
+ return { failed: true };
51092
+ }
51093
+ render() {
51094
+ if (this.state.failed) {
51095
+ return React105__namespace.default.createElement(
51096
+ "div",
51097
+ {
51098
+ "data-testid": "three-unavailable",
51099
+ style: { padding: 16, fontSize: 13, lineHeight: 1.5, opacity: 0.7 }
51100
+ },
51101
+ `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.`
51102
+ );
51103
+ }
51104
+ return this.props.children;
51105
+ }
51106
+ };
51107
+ GameBoard3D = lazyThree("GameBoard3D", () => import('@almadar/ui/components/molecules/game/three'));
51108
+ GameCanvas3D = lazyThree("GameCanvas3D", () => import('@almadar/ui/components/molecules/game/three'));
51109
+ GameCanvas3DBattleTemplate = lazyThree("GameCanvas3DBattleTemplate", () => import('@almadar/ui/components/molecules/game/three'));
51110
+ GameCanvas3DCastleTemplate = lazyThree("GameCanvas3DCastleTemplate", () => import('@almadar/ui/components/molecules/game/three'));
51111
+ GameCanvas3DWorldMapTemplate = lazyThree("GameCanvas3DWorldMapTemplate", () => import('@almadar/ui/components/molecules/game/three'));
50754
51112
  COMPONENT_REGISTRY = {
50755
51113
  "AboutPageTemplate": AboutPageTemplate,
50756
51114
  "Accordion": Accordion,
@@ -50866,9 +51224,16 @@ var init_component_registry_generated = __esm({
50866
51224
  "Form": Form,
50867
51225
  "FormField": FormField,
50868
51226
  "FormSectionHeader": FormSectionHeader,
51227
+ "GameAudioProvider": GameAudioProvider,
50869
51228
  "GameAudioToggle": GameAudioToggle,
51229
+ "GameBoard3D": GameBoard3D,
51230
+ "GameCanvas3D": GameCanvas3D,
51231
+ "GameCanvas3DBattleTemplate": GameCanvas3DBattleTemplate,
51232
+ "GameCanvas3DCastleTemplate": GameCanvas3DCastleTemplate,
51233
+ "GameCanvas3DWorldMapTemplate": GameCanvas3DWorldMapTemplate,
50870
51234
  "GameCard": GameCard,
50871
51235
  "GameHud": GameHud,
51236
+ "GameIcon": GameIcon,
50872
51237
  "GameMenu": GameMenu,
50873
51238
  "GameShell": GameShell,
50874
51239
  "GameTemplate": GameTemplate,