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