@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.
@@ -1124,14 +1124,17 @@ function lazyFamilyIcon(libKey, importer, pick, fallbackName, family) {
1124
1124
  Wrapped.displayName = `Lazy.${libKey}.${fallbackName}`;
1125
1125
  return Wrapped;
1126
1126
  }
1127
+ function isComponentLike(v) {
1128
+ return v != null && (typeof v === "function" || typeof v === "object");
1129
+ }
1127
1130
  function resolveLucide(name) {
1128
1131
  if (lucideAliases[name]) return lucideAliases[name];
1129
1132
  const pascal = kebabToPascal(name);
1130
1133
  const lucideMap = LucideIcons2;
1131
1134
  const direct = lucideMap[pascal];
1132
- if (direct && typeof direct === "function") return direct;
1135
+ if (isComponentLike(direct)) return direct;
1133
1136
  const asIs = lucideMap[name];
1134
- if (asIs && typeof asIs === "function") return asIs;
1137
+ if (isComponentLike(asIs)) return asIs;
1135
1138
  return LucideIcons2.HelpCircle;
1136
1139
  }
1137
1140
  function resolvePhosphor(name, weight, family) {
@@ -1775,12 +1778,13 @@ function resolveIcon(name) {
1775
1778
  }
1776
1779
  function doResolve(name) {
1777
1780
  if (iconAliases[name]) return iconAliases[name];
1781
+ const isComponentLike2 = (v) => v != null && (typeof v === "function" || typeof v === "object");
1778
1782
  const pascalName = kebabToPascal2(name);
1779
1783
  const lucideMap = LucideIcons2;
1780
1784
  const directLookup = lucideMap[pascalName];
1781
- if (directLookup && typeof directLookup === "object") return directLookup;
1785
+ if (isComponentLike2(directLookup)) return directLookup;
1782
1786
  const asIs = lucideMap[name];
1783
- if (asIs && typeof asIs === "object") return asIs;
1787
+ if (isComponentLike2(asIs)) return asIs;
1784
1788
  return LucideIcons2.HelpCircle;
1785
1789
  }
1786
1790
  var colorTokenClasses, iconAliases, resolvedCache, sizeClasses, animationClasses, Icon;
@@ -12447,14 +12451,318 @@ var init_useCanvasEffects = __esm({
12447
12451
  "use client";
12448
12452
  }
12449
12453
  });
12454
+ function pickPath(entry) {
12455
+ if (Array.isArray(entry.path)) {
12456
+ return entry.path[Math.floor(Math.random() * entry.path.length)];
12457
+ }
12458
+ return entry.path;
12459
+ }
12460
+ function useGameAudio({
12461
+ manifest,
12462
+ baseUrl = "",
12463
+ initialMuted = false,
12464
+ initialVolume = 1
12465
+ }) {
12466
+ const [muted, setMutedState] = useState(initialMuted);
12467
+ const [masterVolume, setMasterVolumeState] = useState(initialVolume);
12468
+ const mutedRef = useRef(muted);
12469
+ const volumeRef = useRef(masterVolume);
12470
+ const manifestRef = useRef(manifest);
12471
+ mutedRef.current = muted;
12472
+ volumeRef.current = masterVolume;
12473
+ manifestRef.current = manifest;
12474
+ const poolsRef = useRef(/* @__PURE__ */ new Map());
12475
+ const getOrCreateElement = useCallback((key) => {
12476
+ const entry = manifestRef.current[key];
12477
+ if (!entry) return null;
12478
+ let pool = poolsRef.current.get(key);
12479
+ if (!pool) {
12480
+ pool = [];
12481
+ poolsRef.current.set(key, pool);
12482
+ }
12483
+ const maxSize = entry.poolSize ?? 1;
12484
+ for (const audio of pool) {
12485
+ if (audio.paused && (audio.ended || audio.currentTime === 0)) {
12486
+ return audio;
12487
+ }
12488
+ }
12489
+ if (pool.length < maxSize) {
12490
+ const src = baseUrl + pickPath(entry);
12491
+ const audio = new Audio(src);
12492
+ audio.loop = entry.loop ?? false;
12493
+ pool.push(audio);
12494
+ return audio;
12495
+ }
12496
+ if (!entry.loop) {
12497
+ let oldest = pool[0];
12498
+ for (const audio of pool) {
12499
+ if (audio.currentTime > oldest.currentTime) {
12500
+ oldest = audio;
12501
+ }
12502
+ }
12503
+ oldest.pause();
12504
+ oldest.currentTime = 0;
12505
+ return oldest;
12506
+ }
12507
+ return null;
12508
+ }, [baseUrl]);
12509
+ const play = useCallback((key) => {
12510
+ if (mutedRef.current) return;
12511
+ const entry = manifestRef.current[key];
12512
+ if (!entry) return;
12513
+ const audio = getOrCreateElement(key);
12514
+ if (!audio) return;
12515
+ audio.volume = Math.min(1, (entry.volume ?? 1) * volumeRef.current);
12516
+ if (!entry.loop) {
12517
+ audio.currentTime = 0;
12518
+ }
12519
+ const promise = audio.play();
12520
+ if (promise) {
12521
+ promise.catch(() => {
12522
+ });
12523
+ }
12524
+ }, [getOrCreateElement]);
12525
+ const stop = useCallback((key) => {
12526
+ const pool = poolsRef.current.get(key);
12527
+ if (!pool) return;
12528
+ for (const audio of pool) {
12529
+ audio.pause();
12530
+ audio.currentTime = 0;
12531
+ }
12532
+ }, []);
12533
+ const currentMusicKeyRef = useRef(null);
12534
+ const currentMusicElRef = useRef(null);
12535
+ const musicFadeRef = useRef(null);
12536
+ const pendingMusicKeyRef = useRef(null);
12537
+ const clearMusicFade = useCallback(() => {
12538
+ if (musicFadeRef.current) {
12539
+ clearInterval(musicFadeRef.current);
12540
+ musicFadeRef.current = null;
12541
+ }
12542
+ }, []);
12543
+ const playMusic = useCallback((key) => {
12544
+ if (key === currentMusicKeyRef.current) return;
12545
+ pendingMusicKeyRef.current = key;
12546
+ const entry = manifestRef.current[key];
12547
+ if (!entry) return;
12548
+ const fadeDurationMs = entry.crossfadeDurationMs ?? 1500;
12549
+ const stepMs = 50;
12550
+ const totalSteps = Math.max(1, fadeDurationMs / stepMs);
12551
+ const targetVolume = Math.min(1, (entry.volume ?? 1) * volumeRef.current);
12552
+ clearMusicFade();
12553
+ const src = baseUrl + (Array.isArray(entry.path) ? entry.path[0] : entry.path);
12554
+ const incoming = new Audio(src);
12555
+ incoming.loop = true;
12556
+ incoming.volume = 0;
12557
+ const outgoing = currentMusicElRef.current;
12558
+ const outgoingStartVol = outgoing?.volume ?? 0;
12559
+ currentMusicKeyRef.current = key;
12560
+ currentMusicElRef.current = incoming;
12561
+ if (!mutedRef.current) {
12562
+ incoming.play().catch(() => {
12563
+ currentMusicKeyRef.current = null;
12564
+ currentMusicElRef.current = outgoing;
12565
+ });
12566
+ }
12567
+ let step = 0;
12568
+ musicFadeRef.current = setInterval(() => {
12569
+ step++;
12570
+ const progress = Math.min(step / totalSteps, 1);
12571
+ incoming.volume = Math.min(1, targetVolume * progress);
12572
+ if (outgoing) {
12573
+ outgoing.volume = Math.max(0, outgoingStartVol * (1 - progress));
12574
+ }
12575
+ if (progress >= 1) {
12576
+ clearMusicFade();
12577
+ if (outgoing) {
12578
+ outgoing.pause();
12579
+ outgoing.src = "";
12580
+ }
12581
+ }
12582
+ }, stepMs);
12583
+ }, [baseUrl, clearMusicFade]);
12584
+ const stopMusic = useCallback((fadeDurationMs = 1e3) => {
12585
+ const outgoing = currentMusicElRef.current;
12586
+ if (!outgoing) return;
12587
+ currentMusicKeyRef.current = null;
12588
+ currentMusicElRef.current = null;
12589
+ pendingMusicKeyRef.current = null;
12590
+ clearMusicFade();
12591
+ const startVolume = outgoing.volume;
12592
+ const stepMs = 50;
12593
+ const totalSteps = Math.max(1, fadeDurationMs / stepMs);
12594
+ let step = 0;
12595
+ musicFadeRef.current = setInterval(() => {
12596
+ step++;
12597
+ const progress = step / totalSteps;
12598
+ outgoing.volume = Math.max(0, startVolume * (1 - progress));
12599
+ if (progress >= 1) {
12600
+ clearMusicFade();
12601
+ outgoing.pause();
12602
+ outgoing.src = "";
12603
+ }
12604
+ }, stepMs);
12605
+ }, [clearMusicFade]);
12606
+ const stopAll = useCallback(() => {
12607
+ for (const pool of poolsRef.current.values()) {
12608
+ for (const audio of pool) {
12609
+ audio.pause();
12610
+ audio.currentTime = 0;
12611
+ }
12612
+ }
12613
+ stopMusic(0);
12614
+ }, [stopMusic]);
12615
+ const setMuted = useCallback((value) => {
12616
+ setMutedState(value);
12617
+ if (value) {
12618
+ for (const [key, pool] of poolsRef.current.entries()) {
12619
+ if (manifestRef.current[key]?.loop) {
12620
+ for (const audio of pool) {
12621
+ if (!audio.paused) audio.pause();
12622
+ }
12623
+ }
12624
+ }
12625
+ currentMusicElRef.current?.pause();
12626
+ } else {
12627
+ for (const [key, pool] of poolsRef.current.entries()) {
12628
+ const entry = manifestRef.current[key];
12629
+ if (entry?.loop && entry?.autostart) {
12630
+ for (const audio of pool) {
12631
+ if (audio.paused) audio.play().catch(() => {
12632
+ });
12633
+ }
12634
+ }
12635
+ }
12636
+ const musicEl = currentMusicElRef.current;
12637
+ if (musicEl) {
12638
+ musicEl.play().catch(() => {
12639
+ });
12640
+ }
12641
+ }
12642
+ }, []);
12643
+ const setMasterVolume = useCallback((volume) => {
12644
+ const clamped = Math.max(0, Math.min(1, volume));
12645
+ setMasterVolumeState(clamped);
12646
+ for (const [key, pool] of poolsRef.current.entries()) {
12647
+ const entryVol = manifestRef.current[key]?.volume ?? 1;
12648
+ for (const audio of pool) {
12649
+ audio.volume = Math.min(1, entryVol * clamped);
12650
+ }
12651
+ }
12652
+ if (!musicFadeRef.current && currentMusicElRef.current) {
12653
+ const key = currentMusicKeyRef.current;
12654
+ const entryVol = key ? manifestRef.current[key]?.volume ?? 1 : 1;
12655
+ currentMusicElRef.current.volume = Math.min(1, entryVol * clamped);
12656
+ }
12657
+ }, []);
12658
+ const unlockedRef = useRef(false);
12659
+ useEffect(() => {
12660
+ const autoKeys = Object.keys(manifest).filter((k) => manifest[k].autostart);
12661
+ const hasPendingMusic = () => pendingMusicKeyRef.current !== null;
12662
+ const hasAutoStart = autoKeys.length > 0;
12663
+ if (!hasAutoStart && !hasPendingMusic()) return;
12664
+ const unlock = () => {
12665
+ if (unlockedRef.current) return;
12666
+ unlockedRef.current = true;
12667
+ if (!mutedRef.current) {
12668
+ for (const key of autoKeys) {
12669
+ play(key);
12670
+ }
12671
+ const pending = pendingMusicKeyRef.current;
12672
+ if (pending && pending !== currentMusicKeyRef.current) {
12673
+ playMusic(pending);
12674
+ }
12675
+ }
12676
+ };
12677
+ document.addEventListener("click", unlock, { once: true });
12678
+ document.addEventListener("keydown", unlock, { once: true });
12679
+ document.addEventListener("touchstart", unlock, { once: true });
12680
+ return () => {
12681
+ document.removeEventListener("click", unlock);
12682
+ document.removeEventListener("keydown", unlock);
12683
+ document.removeEventListener("touchstart", unlock);
12684
+ };
12685
+ }, [manifest, play, playMusic]);
12686
+ useEffect(() => {
12687
+ return () => {
12688
+ clearMusicFade();
12689
+ for (const pool of poolsRef.current.values()) {
12690
+ for (const audio of pool) {
12691
+ audio.pause();
12692
+ audio.src = "";
12693
+ }
12694
+ }
12695
+ poolsRef.current.clear();
12696
+ if (currentMusicElRef.current) {
12697
+ currentMusicElRef.current.pause();
12698
+ currentMusicElRef.current.src = "";
12699
+ currentMusicElRef.current = null;
12700
+ }
12701
+ };
12702
+ }, [clearMusicFade]);
12703
+ return {
12704
+ play,
12705
+ stop,
12706
+ stopAll,
12707
+ playMusic,
12708
+ stopMusic,
12709
+ muted,
12710
+ setMuted,
12711
+ masterVolume,
12712
+ setMasterVolume
12713
+ };
12714
+ }
12450
12715
  var init_useGameAudio = __esm({
12451
12716
  "components/game/shared/hooks/useGameAudio.ts"() {
12452
12717
  "use client";
12718
+ useGameAudio.displayName = "useGameAudio";
12453
12719
  }
12454
12720
  });
12455
12721
  function useGameAudioContextOptional() {
12456
12722
  return useContext(GameAudioContext);
12457
12723
  }
12724
+ function GameAudioProvider({
12725
+ manifest,
12726
+ baseUrl = "",
12727
+ children,
12728
+ initialMuted = false
12729
+ }) {
12730
+ const eventBus = useEventBus();
12731
+ const { play, stop, stopAll, playMusic, stopMusic, muted, setMuted, masterVolume, setMasterVolume } = useGameAudio({ manifest, baseUrl, initialMuted });
12732
+ useEffect(() => {
12733
+ const unsubPlay = eventBus.on("UI:PLAY_SOUND", (event) => {
12734
+ const key = event.payload?.key;
12735
+ if (key) play(key);
12736
+ });
12737
+ const unsubStop = eventBus.on("UI:STOP_SOUND", (event) => {
12738
+ const key = event.payload?.key;
12739
+ if (key) {
12740
+ stop(key);
12741
+ } else {
12742
+ stopAll();
12743
+ }
12744
+ });
12745
+ const unsubChangeMusic = eventBus.on("UI:CHANGE_MUSIC", (event) => {
12746
+ const key = event.payload?.key;
12747
+ if (key) {
12748
+ playMusic(key);
12749
+ } else {
12750
+ stopMusic();
12751
+ }
12752
+ });
12753
+ const unsubStopMusic = eventBus.on("UI:STOP_MUSIC", () => {
12754
+ stopMusic();
12755
+ });
12756
+ return () => {
12757
+ unsubPlay();
12758
+ unsubStop();
12759
+ unsubChangeMusic();
12760
+ unsubStopMusic();
12761
+ };
12762
+ }, [eventBus, play, stop, stopAll, playMusic, stopMusic]);
12763
+ const value = { muted, setMuted, masterVolume, setMasterVolume, play, playMusic, stopMusic };
12764
+ return /* @__PURE__ */ jsx(GameAudioContext.Provider, { value, children });
12765
+ }
12458
12766
  var GameAudioContext;
12459
12767
  var init_GameAudioProvider = __esm({
12460
12768
  "components/game/shared/providers/GameAudioProvider.tsx"() {
@@ -12463,6 +12771,7 @@ var init_GameAudioProvider = __esm({
12463
12771
  init_useGameAudio();
12464
12772
  GameAudioContext = createContext(null);
12465
12773
  GameAudioContext.displayName = "GameAudioContext";
12774
+ GameAudioProvider.displayName = "GameAudioProvider";
12466
12775
  }
12467
12776
  });
12468
12777
  function GameAudioToggle({
@@ -50406,9 +50715,33 @@ var init_ToastSlot = __esm({
50406
50715
  ToastSlot.displayName = "ToastSlot";
50407
50716
  }
50408
50717
  });
50409
-
50410
- // components/core/organisms/component-registry.generated.ts
50411
- var COMPONENT_REGISTRY;
50718
+ function lazyThree(name, loader) {
50719
+ const Lazy = React105__default.lazy(
50720
+ () => loader().then((m) => {
50721
+ const Resolved = m[name];
50722
+ if (!Resolved) {
50723
+ throw new Error(
50724
+ `[@almadar/ui] 3D component "${name}" was not found in the three subpath bundle.`
50725
+ );
50726
+ }
50727
+ return { default: Resolved };
50728
+ })
50729
+ );
50730
+ function ThreeWrapper(props) {
50731
+ return React105__default.createElement(
50732
+ ThreeBoundary,
50733
+ { name },
50734
+ React105__default.createElement(
50735
+ React105__default.Suspense,
50736
+ { fallback: null },
50737
+ React105__default.createElement(Lazy, props)
50738
+ )
50739
+ );
50740
+ }
50741
+ ThreeWrapper.displayName = `Lazy(${name})`;
50742
+ return ThreeWrapper;
50743
+ }
50744
+ var ThreeBoundary, GameBoard3D, GameCanvas3D, GameCanvas3DBattleTemplate, GameCanvas3DCastleTemplate, GameCanvas3DWorldMapTemplate, COMPONENT_REGISTRY;
50412
50745
  var init_component_registry_generated = __esm({
50413
50746
  "components/core/organisms/component-registry.generated.ts"() {
50414
50747
  init_AboutPageTemplate();
@@ -50519,9 +50852,11 @@ var init_component_registry_generated = __esm({
50519
50852
  init_Form();
50520
50853
  init_FormField();
50521
50854
  init_FormSectionHeader();
50855
+ init_GameAudioProvider();
50522
50856
  init_GameAudioToggle();
50523
50857
  init_GameCard();
50524
50858
  init_GameHud();
50859
+ init_GameIcon();
50525
50860
  init_GameMenu();
50526
50861
  init_GameShell();
50527
50862
  init_GameTemplate();
@@ -50706,6 +51041,33 @@ var init_component_registry_generated = __esm({
50706
51041
  init_WizardProgress();
50707
51042
  init_WorldMapBoard();
50708
51043
  init_WorldMapTemplate();
51044
+ ThreeBoundary = class extends React105__default.Component {
51045
+ constructor() {
51046
+ super(...arguments);
51047
+ __publicField(this, "state", { failed: false });
51048
+ }
51049
+ static getDerivedStateFromError() {
51050
+ return { failed: true };
51051
+ }
51052
+ render() {
51053
+ if (this.state.failed) {
51054
+ return React105__default.createElement(
51055
+ "div",
51056
+ {
51057
+ "data-testid": "three-unavailable",
51058
+ style: { padding: 16, fontSize: 13, lineHeight: 1.5, opacity: 0.7 }
51059
+ },
51060
+ `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.`
51061
+ );
51062
+ }
51063
+ return this.props.children;
51064
+ }
51065
+ };
51066
+ GameBoard3D = lazyThree("GameBoard3D", () => import('@almadar/ui/components/molecules/game/three'));
51067
+ GameCanvas3D = lazyThree("GameCanvas3D", () => import('@almadar/ui/components/molecules/game/three'));
51068
+ GameCanvas3DBattleTemplate = lazyThree("GameCanvas3DBattleTemplate", () => import('@almadar/ui/components/molecules/game/three'));
51069
+ GameCanvas3DCastleTemplate = lazyThree("GameCanvas3DCastleTemplate", () => import('@almadar/ui/components/molecules/game/three'));
51070
+ GameCanvas3DWorldMapTemplate = lazyThree("GameCanvas3DWorldMapTemplate", () => import('@almadar/ui/components/molecules/game/three'));
50709
51071
  COMPONENT_REGISTRY = {
50710
51072
  "AboutPageTemplate": AboutPageTemplate,
50711
51073
  "Accordion": Accordion,
@@ -50821,9 +51183,16 @@ var init_component_registry_generated = __esm({
50821
51183
  "Form": Form,
50822
51184
  "FormField": FormField,
50823
51185
  "FormSectionHeader": FormSectionHeader,
51186
+ "GameAudioProvider": GameAudioProvider,
50824
51187
  "GameAudioToggle": GameAudioToggle,
51188
+ "GameBoard3D": GameBoard3D,
51189
+ "GameCanvas3D": GameCanvas3D,
51190
+ "GameCanvas3DBattleTemplate": GameCanvas3DBattleTemplate,
51191
+ "GameCanvas3DCastleTemplate": GameCanvas3DCastleTemplate,
51192
+ "GameCanvas3DWorldMapTemplate": GameCanvas3DWorldMapTemplate,
50825
51193
  "GameCard": GameCard,
50826
51194
  "GameHud": GameHud,
51195
+ "GameIcon": GameIcon,
50827
51196
  "GameMenu": GameMenu,
50828
51197
  "GameShell": GameShell,
50829
51198
  "GameTemplate": GameTemplate,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/ui",
3
- "version": "5.76.2",
3
+ "version": "5.76.5",
4
4
  "description": "React UI components, hooks, and providers for Almadar",
5
5
  "type": "module",
6
6
  "sideEffects": [