@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.
package/dist/avl/index.js CHANGED
@@ -4520,14 +4520,17 @@ function lazyFamilyIcon(libKey, importer, pick, fallbackName, family) {
4520
4520
  Wrapped.displayName = `Lazy.${libKey}.${fallbackName}`;
4521
4521
  return Wrapped;
4522
4522
  }
4523
+ function isComponentLike(v) {
4524
+ return v != null && (typeof v === "function" || typeof v === "object");
4525
+ }
4523
4526
  function resolveLucide(name) {
4524
4527
  if (lucideAliases[name]) return lucideAliases[name];
4525
4528
  const pascal = kebabToPascal(name);
4526
4529
  const lucideMap = LucideIcons2;
4527
4530
  const direct = lucideMap[pascal];
4528
- if (direct && typeof direct === "function") return direct;
4531
+ if (isComponentLike(direct)) return direct;
4529
4532
  const asIs = lucideMap[name];
4530
- if (asIs && typeof asIs === "function") return asIs;
4533
+ if (isComponentLike(asIs)) return asIs;
4531
4534
  return LucideIcons2.HelpCircle;
4532
4535
  }
4533
4536
  function resolvePhosphor(name, weight, family) {
@@ -5171,12 +5174,13 @@ function resolveIcon(name) {
5171
5174
  }
5172
5175
  function doResolve(name) {
5173
5176
  if (iconAliases[name]) return iconAliases[name];
5177
+ const isComponentLike2 = (v) => v != null && (typeof v === "function" || typeof v === "object");
5174
5178
  const pascalName = kebabToPascal2(name);
5175
5179
  const lucideMap = LucideIcons2;
5176
5180
  const directLookup = lucideMap[pascalName];
5177
- if (directLookup && typeof directLookup === "object") return directLookup;
5181
+ if (isComponentLike2(directLookup)) return directLookup;
5178
5182
  const asIs = lucideMap[name];
5179
- if (asIs && typeof asIs === "object") return asIs;
5183
+ if (isComponentLike2(asIs)) return asIs;
5180
5184
  return LucideIcons2.HelpCircle;
5181
5185
  }
5182
5186
  var colorTokenClasses, iconAliases, resolvedCache, sizeClasses, animationClasses, Icon;
@@ -15854,14 +15858,318 @@ var init_useCanvasEffects = __esm({
15854
15858
  "use client";
15855
15859
  }
15856
15860
  });
15861
+ function pickPath(entry) {
15862
+ if (Array.isArray(entry.path)) {
15863
+ return entry.path[Math.floor(Math.random() * entry.path.length)];
15864
+ }
15865
+ return entry.path;
15866
+ }
15867
+ function useGameAudio({
15868
+ manifest,
15869
+ baseUrl = "",
15870
+ initialMuted = false,
15871
+ initialVolume = 1
15872
+ }) {
15873
+ const [muted, setMutedState] = useState(initialMuted);
15874
+ const [masterVolume, setMasterVolumeState] = useState(initialVolume);
15875
+ const mutedRef = useRef(muted);
15876
+ const volumeRef = useRef(masterVolume);
15877
+ const manifestRef = useRef(manifest);
15878
+ mutedRef.current = muted;
15879
+ volumeRef.current = masterVolume;
15880
+ manifestRef.current = manifest;
15881
+ const poolsRef = useRef(/* @__PURE__ */ new Map());
15882
+ const getOrCreateElement = useCallback((key) => {
15883
+ const entry = manifestRef.current[key];
15884
+ if (!entry) return null;
15885
+ let pool = poolsRef.current.get(key);
15886
+ if (!pool) {
15887
+ pool = [];
15888
+ poolsRef.current.set(key, pool);
15889
+ }
15890
+ const maxSize = entry.poolSize ?? 1;
15891
+ for (const audio of pool) {
15892
+ if (audio.paused && (audio.ended || audio.currentTime === 0)) {
15893
+ return audio;
15894
+ }
15895
+ }
15896
+ if (pool.length < maxSize) {
15897
+ const src = baseUrl + pickPath(entry);
15898
+ const audio = new Audio(src);
15899
+ audio.loop = entry.loop ?? false;
15900
+ pool.push(audio);
15901
+ return audio;
15902
+ }
15903
+ if (!entry.loop) {
15904
+ let oldest = pool[0];
15905
+ for (const audio of pool) {
15906
+ if (audio.currentTime > oldest.currentTime) {
15907
+ oldest = audio;
15908
+ }
15909
+ }
15910
+ oldest.pause();
15911
+ oldest.currentTime = 0;
15912
+ return oldest;
15913
+ }
15914
+ return null;
15915
+ }, [baseUrl]);
15916
+ const play = useCallback((key) => {
15917
+ if (mutedRef.current) return;
15918
+ const entry = manifestRef.current[key];
15919
+ if (!entry) return;
15920
+ const audio = getOrCreateElement(key);
15921
+ if (!audio) return;
15922
+ audio.volume = Math.min(1, (entry.volume ?? 1) * volumeRef.current);
15923
+ if (!entry.loop) {
15924
+ audio.currentTime = 0;
15925
+ }
15926
+ const promise = audio.play();
15927
+ if (promise) {
15928
+ promise.catch(() => {
15929
+ });
15930
+ }
15931
+ }, [getOrCreateElement]);
15932
+ const stop = useCallback((key) => {
15933
+ const pool = poolsRef.current.get(key);
15934
+ if (!pool) return;
15935
+ for (const audio of pool) {
15936
+ audio.pause();
15937
+ audio.currentTime = 0;
15938
+ }
15939
+ }, []);
15940
+ const currentMusicKeyRef = useRef(null);
15941
+ const currentMusicElRef = useRef(null);
15942
+ const musicFadeRef = useRef(null);
15943
+ const pendingMusicKeyRef = useRef(null);
15944
+ const clearMusicFade = useCallback(() => {
15945
+ if (musicFadeRef.current) {
15946
+ clearInterval(musicFadeRef.current);
15947
+ musicFadeRef.current = null;
15948
+ }
15949
+ }, []);
15950
+ const playMusic = useCallback((key) => {
15951
+ if (key === currentMusicKeyRef.current) return;
15952
+ pendingMusicKeyRef.current = key;
15953
+ const entry = manifestRef.current[key];
15954
+ if (!entry) return;
15955
+ const fadeDurationMs = entry.crossfadeDurationMs ?? 1500;
15956
+ const stepMs = 50;
15957
+ const totalSteps = Math.max(1, fadeDurationMs / stepMs);
15958
+ const targetVolume = Math.min(1, (entry.volume ?? 1) * volumeRef.current);
15959
+ clearMusicFade();
15960
+ const src = baseUrl + (Array.isArray(entry.path) ? entry.path[0] : entry.path);
15961
+ const incoming = new Audio(src);
15962
+ incoming.loop = true;
15963
+ incoming.volume = 0;
15964
+ const outgoing = currentMusicElRef.current;
15965
+ const outgoingStartVol = outgoing?.volume ?? 0;
15966
+ currentMusicKeyRef.current = key;
15967
+ currentMusicElRef.current = incoming;
15968
+ if (!mutedRef.current) {
15969
+ incoming.play().catch(() => {
15970
+ currentMusicKeyRef.current = null;
15971
+ currentMusicElRef.current = outgoing;
15972
+ });
15973
+ }
15974
+ let step = 0;
15975
+ musicFadeRef.current = setInterval(() => {
15976
+ step++;
15977
+ const progress = Math.min(step / totalSteps, 1);
15978
+ incoming.volume = Math.min(1, targetVolume * progress);
15979
+ if (outgoing) {
15980
+ outgoing.volume = Math.max(0, outgoingStartVol * (1 - progress));
15981
+ }
15982
+ if (progress >= 1) {
15983
+ clearMusicFade();
15984
+ if (outgoing) {
15985
+ outgoing.pause();
15986
+ outgoing.src = "";
15987
+ }
15988
+ }
15989
+ }, stepMs);
15990
+ }, [baseUrl, clearMusicFade]);
15991
+ const stopMusic = useCallback((fadeDurationMs = 1e3) => {
15992
+ const outgoing = currentMusicElRef.current;
15993
+ if (!outgoing) return;
15994
+ currentMusicKeyRef.current = null;
15995
+ currentMusicElRef.current = null;
15996
+ pendingMusicKeyRef.current = null;
15997
+ clearMusicFade();
15998
+ const startVolume = outgoing.volume;
15999
+ const stepMs = 50;
16000
+ const totalSteps = Math.max(1, fadeDurationMs / stepMs);
16001
+ let step = 0;
16002
+ musicFadeRef.current = setInterval(() => {
16003
+ step++;
16004
+ const progress = step / totalSteps;
16005
+ outgoing.volume = Math.max(0, startVolume * (1 - progress));
16006
+ if (progress >= 1) {
16007
+ clearMusicFade();
16008
+ outgoing.pause();
16009
+ outgoing.src = "";
16010
+ }
16011
+ }, stepMs);
16012
+ }, [clearMusicFade]);
16013
+ const stopAll = useCallback(() => {
16014
+ for (const pool of poolsRef.current.values()) {
16015
+ for (const audio of pool) {
16016
+ audio.pause();
16017
+ audio.currentTime = 0;
16018
+ }
16019
+ }
16020
+ stopMusic(0);
16021
+ }, [stopMusic]);
16022
+ const setMuted = useCallback((value) => {
16023
+ setMutedState(value);
16024
+ if (value) {
16025
+ for (const [key, pool] of poolsRef.current.entries()) {
16026
+ if (manifestRef.current[key]?.loop) {
16027
+ for (const audio of pool) {
16028
+ if (!audio.paused) audio.pause();
16029
+ }
16030
+ }
16031
+ }
16032
+ currentMusicElRef.current?.pause();
16033
+ } else {
16034
+ for (const [key, pool] of poolsRef.current.entries()) {
16035
+ const entry = manifestRef.current[key];
16036
+ if (entry?.loop && entry?.autostart) {
16037
+ for (const audio of pool) {
16038
+ if (audio.paused) audio.play().catch(() => {
16039
+ });
16040
+ }
16041
+ }
16042
+ }
16043
+ const musicEl = currentMusicElRef.current;
16044
+ if (musicEl) {
16045
+ musicEl.play().catch(() => {
16046
+ });
16047
+ }
16048
+ }
16049
+ }, []);
16050
+ const setMasterVolume = useCallback((volume) => {
16051
+ const clamped = Math.max(0, Math.min(1, volume));
16052
+ setMasterVolumeState(clamped);
16053
+ for (const [key, pool] of poolsRef.current.entries()) {
16054
+ const entryVol = manifestRef.current[key]?.volume ?? 1;
16055
+ for (const audio of pool) {
16056
+ audio.volume = Math.min(1, entryVol * clamped);
16057
+ }
16058
+ }
16059
+ if (!musicFadeRef.current && currentMusicElRef.current) {
16060
+ const key = currentMusicKeyRef.current;
16061
+ const entryVol = key ? manifestRef.current[key]?.volume ?? 1 : 1;
16062
+ currentMusicElRef.current.volume = Math.min(1, entryVol * clamped);
16063
+ }
16064
+ }, []);
16065
+ const unlockedRef = useRef(false);
16066
+ useEffect(() => {
16067
+ const autoKeys = Object.keys(manifest).filter((k) => manifest[k].autostart);
16068
+ const hasPendingMusic = () => pendingMusicKeyRef.current !== null;
16069
+ const hasAutoStart = autoKeys.length > 0;
16070
+ if (!hasAutoStart && !hasPendingMusic()) return;
16071
+ const unlock = () => {
16072
+ if (unlockedRef.current) return;
16073
+ unlockedRef.current = true;
16074
+ if (!mutedRef.current) {
16075
+ for (const key of autoKeys) {
16076
+ play(key);
16077
+ }
16078
+ const pending = pendingMusicKeyRef.current;
16079
+ if (pending && pending !== currentMusicKeyRef.current) {
16080
+ playMusic(pending);
16081
+ }
16082
+ }
16083
+ };
16084
+ document.addEventListener("click", unlock, { once: true });
16085
+ document.addEventListener("keydown", unlock, { once: true });
16086
+ document.addEventListener("touchstart", unlock, { once: true });
16087
+ return () => {
16088
+ document.removeEventListener("click", unlock);
16089
+ document.removeEventListener("keydown", unlock);
16090
+ document.removeEventListener("touchstart", unlock);
16091
+ };
16092
+ }, [manifest, play, playMusic]);
16093
+ useEffect(() => {
16094
+ return () => {
16095
+ clearMusicFade();
16096
+ for (const pool of poolsRef.current.values()) {
16097
+ for (const audio of pool) {
16098
+ audio.pause();
16099
+ audio.src = "";
16100
+ }
16101
+ }
16102
+ poolsRef.current.clear();
16103
+ if (currentMusicElRef.current) {
16104
+ currentMusicElRef.current.pause();
16105
+ currentMusicElRef.current.src = "";
16106
+ currentMusicElRef.current = null;
16107
+ }
16108
+ };
16109
+ }, [clearMusicFade]);
16110
+ return {
16111
+ play,
16112
+ stop,
16113
+ stopAll,
16114
+ playMusic,
16115
+ stopMusic,
16116
+ muted,
16117
+ setMuted,
16118
+ masterVolume,
16119
+ setMasterVolume
16120
+ };
16121
+ }
15857
16122
  var init_useGameAudio = __esm({
15858
16123
  "components/game/shared/hooks/useGameAudio.ts"() {
15859
16124
  "use client";
16125
+ useGameAudio.displayName = "useGameAudio";
15860
16126
  }
15861
16127
  });
15862
16128
  function useGameAudioContextOptional() {
15863
16129
  return useContext(GameAudioContext);
15864
16130
  }
16131
+ function GameAudioProvider({
16132
+ manifest,
16133
+ baseUrl = "",
16134
+ children,
16135
+ initialMuted = false
16136
+ }) {
16137
+ const eventBus = useEventBus();
16138
+ const { play, stop, stopAll, playMusic, stopMusic, muted, setMuted, masterVolume, setMasterVolume } = useGameAudio({ manifest, baseUrl, initialMuted });
16139
+ useEffect(() => {
16140
+ const unsubPlay = eventBus.on("UI:PLAY_SOUND", (event) => {
16141
+ const key = event.payload?.key;
16142
+ if (key) play(key);
16143
+ });
16144
+ const unsubStop = eventBus.on("UI:STOP_SOUND", (event) => {
16145
+ const key = event.payload?.key;
16146
+ if (key) {
16147
+ stop(key);
16148
+ } else {
16149
+ stopAll();
16150
+ }
16151
+ });
16152
+ const unsubChangeMusic = eventBus.on("UI:CHANGE_MUSIC", (event) => {
16153
+ const key = event.payload?.key;
16154
+ if (key) {
16155
+ playMusic(key);
16156
+ } else {
16157
+ stopMusic();
16158
+ }
16159
+ });
16160
+ const unsubStopMusic = eventBus.on("UI:STOP_MUSIC", () => {
16161
+ stopMusic();
16162
+ });
16163
+ return () => {
16164
+ unsubPlay();
16165
+ unsubStop();
16166
+ unsubChangeMusic();
16167
+ unsubStopMusic();
16168
+ };
16169
+ }, [eventBus, play, stop, stopAll, playMusic, stopMusic]);
16170
+ const value = { muted, setMuted, masterVolume, setMasterVolume, play, playMusic, stopMusic };
16171
+ return /* @__PURE__ */ jsx(GameAudioContext.Provider, { value, children });
16172
+ }
15865
16173
  var GameAudioContext;
15866
16174
  var init_GameAudioProvider = __esm({
15867
16175
  "components/game/shared/providers/GameAudioProvider.tsx"() {
@@ -15870,6 +16178,7 @@ var init_GameAudioProvider = __esm({
15870
16178
  init_useGameAudio();
15871
16179
  GameAudioContext = createContext(null);
15872
16180
  GameAudioContext.displayName = "GameAudioContext";
16181
+ GameAudioProvider.displayName = "GameAudioProvider";
15873
16182
  }
15874
16183
  });
15875
16184
  function GameAudioToggle({
@@ -52910,9 +53219,33 @@ var init_ToastSlot = __esm({
52910
53219
  ToastSlot.displayName = "ToastSlot";
52911
53220
  }
52912
53221
  });
52913
-
52914
- // components/core/organisms/component-registry.generated.ts
52915
- var COMPONENT_REGISTRY;
53222
+ function lazyThree(name, loader) {
53223
+ const Lazy = React114__default.lazy(
53224
+ () => loader().then((m) => {
53225
+ const Resolved = m[name];
53226
+ if (!Resolved) {
53227
+ throw new Error(
53228
+ `[@almadar/ui] 3D component "${name}" was not found in the three subpath bundle.`
53229
+ );
53230
+ }
53231
+ return { default: Resolved };
53232
+ })
53233
+ );
53234
+ function ThreeWrapper(props) {
53235
+ return React114__default.createElement(
53236
+ ThreeBoundary,
53237
+ { name },
53238
+ React114__default.createElement(
53239
+ React114__default.Suspense,
53240
+ { fallback: null },
53241
+ React114__default.createElement(Lazy, props)
53242
+ )
53243
+ );
53244
+ }
53245
+ ThreeWrapper.displayName = `Lazy(${name})`;
53246
+ return ThreeWrapper;
53247
+ }
53248
+ var ThreeBoundary, GameBoard3D, GameCanvas3D, GameCanvas3DBattleTemplate, GameCanvas3DCastleTemplate, GameCanvas3DWorldMapTemplate, COMPONENT_REGISTRY;
52916
53249
  var init_component_registry_generated = __esm({
52917
53250
  "components/core/organisms/component-registry.generated.ts"() {
52918
53251
  init_AboutPageTemplate();
@@ -53023,9 +53356,11 @@ var init_component_registry_generated = __esm({
53023
53356
  init_Form();
53024
53357
  init_FormField();
53025
53358
  init_FormSectionHeader();
53359
+ init_GameAudioProvider();
53026
53360
  init_GameAudioToggle();
53027
53361
  init_GameCard();
53028
53362
  init_GameHud();
53363
+ init_GameIcon();
53029
53364
  init_GameMenu();
53030
53365
  init_GameShell();
53031
53366
  init_GameTemplate();
@@ -53210,6 +53545,33 @@ var init_component_registry_generated = __esm({
53210
53545
  init_WizardProgress();
53211
53546
  init_WorldMapBoard();
53212
53547
  init_WorldMapTemplate();
53548
+ ThreeBoundary = class extends React114__default.Component {
53549
+ constructor() {
53550
+ super(...arguments);
53551
+ __publicField(this, "state", { failed: false });
53552
+ }
53553
+ static getDerivedStateFromError() {
53554
+ return { failed: true };
53555
+ }
53556
+ render() {
53557
+ if (this.state.failed) {
53558
+ return React114__default.createElement(
53559
+ "div",
53560
+ {
53561
+ "data-testid": "three-unavailable",
53562
+ style: { padding: 16, fontSize: 13, lineHeight: 1.5, opacity: 0.7 }
53563
+ },
53564
+ `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.`
53565
+ );
53566
+ }
53567
+ return this.props.children;
53568
+ }
53569
+ };
53570
+ GameBoard3D = lazyThree("GameBoard3D", () => import('@almadar/ui/components/molecules/game/three'));
53571
+ GameCanvas3D = lazyThree("GameCanvas3D", () => import('@almadar/ui/components/molecules/game/three'));
53572
+ GameCanvas3DBattleTemplate = lazyThree("GameCanvas3DBattleTemplate", () => import('@almadar/ui/components/molecules/game/three'));
53573
+ GameCanvas3DCastleTemplate = lazyThree("GameCanvas3DCastleTemplate", () => import('@almadar/ui/components/molecules/game/three'));
53574
+ GameCanvas3DWorldMapTemplate = lazyThree("GameCanvas3DWorldMapTemplate", () => import('@almadar/ui/components/molecules/game/three'));
53213
53575
  COMPONENT_REGISTRY = {
53214
53576
  "AboutPageTemplate": AboutPageTemplate,
53215
53577
  "Accordion": Accordion,
@@ -53325,9 +53687,16 @@ var init_component_registry_generated = __esm({
53325
53687
  "Form": Form,
53326
53688
  "FormField": FormField,
53327
53689
  "FormSectionHeader": FormSectionHeader,
53690
+ "GameAudioProvider": GameAudioProvider,
53328
53691
  "GameAudioToggle": GameAudioToggle,
53692
+ "GameBoard3D": GameBoard3D,
53693
+ "GameCanvas3D": GameCanvas3D,
53694
+ "GameCanvas3DBattleTemplate": GameCanvas3DBattleTemplate,
53695
+ "GameCanvas3DCastleTemplate": GameCanvas3DCastleTemplate,
53696
+ "GameCanvas3DWorldMapTemplate": GameCanvas3DWorldMapTemplate,
53329
53697
  "GameCard": GameCard,
53330
53698
  "GameHud": GameHud,
53699
+ "GameIcon": GameIcon,
53331
53700
  "GameMenu": GameMenu,
53332
53701
  "GameShell": GameShell,
53333
53702
  "GameTemplate": GameTemplate,