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