@wallarm-org/design-system 0.58.1 → 0.59.0

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.
Files changed (32) hide show
  1. package/dist/components/AnimatedBackground/AnimatedBackground.js +18 -82
  2. package/dist/components/AnimatedBackground/GameHud.d.ts +1 -0
  3. package/dist/components/AnimatedBackground/GameHud.js +2 -2
  4. package/dist/components/AnimatedBackground/module/celebration-renderer.d.ts +5 -0
  5. package/dist/components/AnimatedBackground/module/celebration-renderer.js +60 -0
  6. package/dist/components/AnimatedBackground/module/celebration.d.ts +102 -0
  7. package/dist/components/AnimatedBackground/module/celebration.js +628 -0
  8. package/dist/components/AnimatedBackground/module/engine-grid.d.ts +8 -1
  9. package/dist/components/AnimatedBackground/module/engine-grid.js +19 -5
  10. package/dist/components/AnimatedBackground/module/engine.d.ts +2 -0
  11. package/dist/components/AnimatedBackground/module/engine.js +24 -5
  12. package/dist/components/AnimatedBackground/module/game-logic.d.ts +8 -0
  13. package/dist/components/AnimatedBackground/module/game-logic.js +81 -37
  14. package/dist/components/AnimatedBackground/module/game-renderer.d.ts +1 -0
  15. package/dist/components/AnimatedBackground/module/game-renderer.js +51 -12
  16. package/dist/components/AnimatedBackground/module/index.d.ts +1 -0
  17. package/dist/components/AnimatedBackground/module/index.js +2 -1
  18. package/dist/components/AnimatedBackground/module/math.d.ts +4 -0
  19. package/dist/components/AnimatedBackground/module/math.js +10 -0
  20. package/dist/components/AnimatedBackground/module/sfx.d.ts +15 -0
  21. package/dist/components/AnimatedBackground/module/sfx.js +143 -0
  22. package/dist/components/AnimatedBackground/module/useGame.d.ts +22 -0
  23. package/dist/components/AnimatedBackground/module/useGame.js +112 -0
  24. package/dist/components/AnimatedBackground/module/useGameKeyboard.d.ts +1 -1
  25. package/dist/components/AnimatedBackground/module/useGameKeyboard.js +23 -14
  26. package/dist/components/Flex/Flex.d.ts +1 -1
  27. package/dist/components/SegmentedControl/SegmentedControlSeparator.d.ts +1 -1
  28. package/dist/components/Separator/Separator.d.ts +1 -1
  29. package/dist/components/Skeleton/Skeleton.d.ts +1 -1
  30. package/dist/components/Stack/Stack.d.ts +1 -1
  31. package/dist/metadata/components.json +2 -2
  32. package/package.json +1 -1
@@ -0,0 +1,112 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { GameHud } from "../GameHud.js";
4
+ import { useGameKeyboard } from "./useGameKeyboard.js";
5
+ const GATE_TARGET = 5;
6
+ const useGame = ({ game, isHalftone, excludeCardSize, canvasRef })=>{
7
+ const engineRef = useRef(null);
8
+ const gameRef = useRef(game);
9
+ const hasStartedRoundRef = useRef(false);
10
+ const [stats, setStats] = useState({
11
+ kills: 0,
12
+ stopped: 0,
13
+ escaped: 0,
14
+ spawned: 0,
15
+ done: false
16
+ });
17
+ const [catchKey, setCatchKey] = useState(0);
18
+ const [soundOn, setSoundOn] = useState(true);
19
+ useEffect(()=>{
20
+ gameRef.current = game;
21
+ });
22
+ const gameActive = game && isHalftone;
23
+ const caught = stats.kills;
24
+ const armed = game && caught >= GATE_TARGET;
25
+ const roundOver = armed && stats.done;
26
+ const faced = stats.stopped + stats.escaped;
27
+ const accuracy = faced > 0 ? Math.round(stats.stopped / faced * 100) : 100;
28
+ const onEngineCreated = useCallback((engine)=>{
29
+ engineRef.current = engine;
30
+ engine.onStats((s)=>{
31
+ setStats(s);
32
+ if (gameRef.current && !s.done) setCatchKey((prev)=>prev + 1);
33
+ });
34
+ }, []);
35
+ const onEngineDestroyed = useCallback(()=>{
36
+ engineRef.current = null;
37
+ }, []);
38
+ useEffect(()=>{
39
+ engineRef.current?.setGameActive(game && isHalftone);
40
+ }, [
41
+ game,
42
+ isHalftone
43
+ ]);
44
+ const exW = excludeCardSize?.width;
45
+ const exH = excludeCardSize?.height;
46
+ useEffect(()=>{
47
+ engineRef.current?.setExclusion(null != exW && null != exH ? {
48
+ width: exW,
49
+ height: exH
50
+ } : null);
51
+ }, [
52
+ exW,
53
+ exH
54
+ ]);
55
+ const soundCapable = game;
56
+ useEffect(()=>{
57
+ engineRef.current?.setSound(soundCapable && soundOn);
58
+ }, [
59
+ soundCapable,
60
+ soundOn
61
+ ]);
62
+ const toggleSound = useCallback(()=>{
63
+ setSoundOn((prev)=>!prev);
64
+ }, []);
65
+ useEffect(()=>{
66
+ if (!game || !armed) return;
67
+ if (hasStartedRoundRef.current) return void engineRef.current?.setMode('armed');
68
+ hasStartedRoundRef.current = true;
69
+ engineRef.current?.startRound();
70
+ }, [
71
+ game,
72
+ armed
73
+ ]);
74
+ useGameKeyboard(engineRef, game, armed, roundOver, hasStartedRoundRef, toggleSound);
75
+ const onPointerDown = useCallback((e)=>{
76
+ if (!game) return;
77
+ const canvas = canvasRef.current;
78
+ if (!canvas) return;
79
+ const rect = canvas.getBoundingClientRect();
80
+ const x = e.clientX - rect.left;
81
+ const y = e.clientY - rect.top;
82
+ engineRef.current?.catchAt(x, y);
83
+ }, [
84
+ game,
85
+ canvasRef
86
+ ]);
87
+ const handleTryAgain = useCallback(()=>{
88
+ engineRef.current?.startRound();
89
+ }, []);
90
+ const hudElement = /*#__PURE__*/ jsx(GameHud, {
91
+ caught: caught,
92
+ armed: armed,
93
+ roundOver: roundOver,
94
+ stats: stats,
95
+ accuracy: accuracy,
96
+ faced: faced,
97
+ catchKey: catchKey,
98
+ gateTarget: GATE_TARGET,
99
+ onTryAgain: handleTryAgain,
100
+ soundOn: soundOn
101
+ });
102
+ return {
103
+ gameActive,
104
+ onPointerDown: gameActive ? onPointerDown : void 0,
105
+ hudElement: gameActive ? hudElement : null,
106
+ onEngineCreated,
107
+ onEngineDestroyed,
108
+ soundOn,
109
+ toggleSound
110
+ };
111
+ };
112
+ export { useGame };
@@ -1,3 +1,3 @@
1
1
  import type { MutableRefObject, RefObject } from 'react';
2
2
  import type { SweepEngine } from './index';
3
- export declare const useGameKeyboard: (engineRef: RefObject<SweepEngine | null>, game: boolean, armed: boolean, roundOver: boolean, hasStartedRoundRef: MutableRefObject<boolean>) => void;
3
+ export declare const useGameKeyboard: (engineRef: RefObject<SweepEngine | null>, game: boolean, armed: boolean, roundOver: boolean, hasStartedRoundRef: MutableRefObject<boolean>, toggleSound: () => void) => void;
@@ -1,5 +1,22 @@
1
- import { useEffect } from "react";
2
- const useGameKeyboard = (engineRef, game, armed, roundOver, hasStartedRoundRef)=>{
1
+ import { useCallback, useEffect } from "react";
2
+ const useGameKeyboard = (engineRef, game, armed, roundOver, hasStartedRoundRef, toggleSound)=>{
3
+ const handleCommonKey = useCallback((e)=>{
4
+ if ('Escape' === e.key) {
5
+ e.preventDefault();
6
+ engineRef.current?.exitGame();
7
+ hasStartedRoundRef.current = false;
8
+ return true;
9
+ }
10
+ if ('m' === e.key || 'M' === e.key) {
11
+ toggleSound();
12
+ return true;
13
+ }
14
+ return false;
15
+ }, [
16
+ engineRef,
17
+ hasStartedRoundRef,
18
+ toggleSound
19
+ ]);
3
20
  useEffect(()=>{
4
21
  if (!game || !armed || roundOver) return;
5
22
  const held = {
@@ -11,6 +28,7 @@ const useGameKeyboard = (engineRef, game, armed, roundOver, hasStartedRoundRef)=
11
28
  engineRef.current?.setCannonDir(dir);
12
29
  }
13
30
  function onKeyDown(e) {
31
+ if (handleCommonKey(e)) return;
14
32
  if ('ArrowLeft' === e.key) {
15
33
  e.preventDefault();
16
34
  held.left = true;
@@ -22,10 +40,6 @@ const useGameKeyboard = (engineRef, game, armed, roundOver, hasStartedRoundRef)=
22
40
  } else if (' ' === e.key || 'Spacebar' === e.key) {
23
41
  e.preventDefault();
24
42
  if (!e.repeat) engineRef.current?.setFiring(true);
25
- } else if ('Escape' === e.key) {
26
- e.preventDefault();
27
- engineRef.current?.exitGame();
28
- hasStartedRoundRef.current = false;
29
43
  }
30
44
  }
31
45
  function onKeyUp(e) {
@@ -50,24 +64,19 @@ const useGameKeyboard = (engineRef, game, armed, roundOver, hasStartedRoundRef)=
50
64
  armed,
51
65
  roundOver,
52
66
  engineRef,
53
- hasStartedRoundRef
67
+ handleCommonKey
54
68
  ]);
55
69
  useEffect(()=>{
56
70
  if (!game || !roundOver) return;
57
71
  function onKeyDown(e) {
58
- if ('Escape' === e.key) {
59
- e.preventDefault();
60
- engineRef.current?.exitGame();
61
- hasStartedRoundRef.current = false;
62
- }
72
+ handleCommonKey(e);
63
73
  }
64
74
  window.addEventListener('keydown', onKeyDown);
65
75
  return ()=>window.removeEventListener('keydown', onKeyDown);
66
76
  }, [
67
77
  game,
68
78
  roundOver,
69
- engineRef,
70
- hasStartedRoundRef
79
+ handleCommonKey
71
80
  ]);
72
81
  };
73
82
  export { useGameKeyboard };
@@ -7,7 +7,7 @@ declare const flexVariants: (props?: ({
7
7
  align?: "center" | "end" | "baseline" | "start" | "stretch" | null | undefined;
8
8
  justify?: "center" | "end" | "start" | "between" | "around" | "evenly" | null | undefined;
9
9
  wrap?: "reverse" | "nowrap" | "wrap" | null | undefined;
10
- gap?: 1 | 2 | 4 | 6 | 8 | 16 | 44 | 80 | 24 | 12 | 40 | 48 | 20 | 32 | 28 | 36 | 56 | 64 | 96 | 112 | 128 | 144 | null | undefined;
10
+ gap?: 1 | 2 | 4 | 6 | 8 | 16 | 44 | 80 | 12 | 20 | 32 | 40 | 24 | 56 | 48 | 28 | 36 | 64 | 96 | 112 | 128 | 144 | null | undefined;
11
11
  grow?: boolean | null | undefined;
12
12
  shrink?: boolean | null | undefined;
13
13
  fullWidth?: boolean | null | undefined;
@@ -2,7 +2,7 @@ import type { ComponentRef, FC, Ref } from 'react';
2
2
  import { type VariantProps } from 'class-variance-authority';
3
3
  import { Separator, type SeparatorProps } from '../Separator';
4
4
  declare const segmentedControlSeparatorVariants: (props?: ({
5
- mx?: 1 | 2 | 4 | 6 | 8 | 16 | 44 | 80 | 24 | 12 | 40 | 48 | 20 | 32 | 28 | 36 | 56 | 64 | 96 | 112 | 128 | 144 | null | undefined;
5
+ mx?: 1 | 2 | 4 | 6 | 8 | 16 | 44 | 80 | 12 | 20 | 32 | 40 | 24 | 56 | 48 | 28 | 36 | 64 | 96 | 112 | 128 | 144 | null | undefined;
6
6
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
7
  type SegmentedControlSeparatorVariants = VariantProps<typeof segmentedControlSeparatorVariants>;
8
8
  /**
@@ -3,7 +3,7 @@ import { type VariantProps } from 'class-variance-authority';
3
3
  import type { TestableProps } from '../../utils/testId';
4
4
  declare const separatorVariants: (props?: ({
5
5
  orientation?: "horizontal" | "vertical" | null | undefined;
6
- spacing?: 1 | 2 | 4 | 6 | 8 | 16 | 44 | 80 | 24 | 12 | 40 | 48 | 20 | 32 | 28 | 36 | 56 | 64 | 96 | 112 | 128 | 144 | null | undefined;
6
+ spacing?: 1 | 2 | 4 | 6 | 8 | 16 | 44 | 80 | 12 | 20 | 32 | 40 | 24 | 56 | 48 | 28 | 36 | 64 | 96 | 112 | 128 | 144 | null | undefined;
7
7
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
8
8
  export type SeparatorProps = ComponentPropsWithoutRef<'div'> & VariantProps<typeof separatorVariants> & TestableProps & {
9
9
  ref?: Ref<HTMLDivElement>;
@@ -3,7 +3,7 @@ import { type VariantProps } from 'class-variance-authority';
3
3
  import type { TestableProps } from '../../utils/testId';
4
4
  declare const skeletonVariants: (props?: ({
5
5
  transparent?: boolean | null | undefined;
6
- rounded?: 2 | 4 | 6 | "none" | 8 | 16 | 24 | 12 | "full" | 32 | null | undefined;
6
+ rounded?: 2 | 4 | 6 | "none" | 8 | 16 | 12 | 32 | 24 | "full" | null | undefined;
7
7
  withDimensions?: boolean | null | undefined;
8
8
  withChildren?: boolean | null | undefined;
9
9
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
@@ -10,7 +10,7 @@ declare const stackVariants: (props?: ({
10
10
  fullWidth?: boolean | null | undefined;
11
11
  flexGrow?: boolean | null | undefined;
12
12
  flexShrink?: boolean | null | undefined;
13
- gap?: 0 | 1 | 2 | 4 | 6 | 8 | 16 | 44 | 80 | 24 | 12 | 40 | 48 | 20 | 32 | 28 | 36 | 56 | 64 | 96 | 112 | 128 | 144 | null | undefined;
13
+ gap?: 0 | 1 | 2 | 4 | 6 | 8 | 16 | 44 | 80 | 12 | 20 | 32 | 40 | 24 | 56 | 48 | 28 | 36 | 64 | 96 | 112 | 128 | 144 | null | undefined;
14
14
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
15
15
  type StackNativeProps = HTMLAttributes<HTMLDivElement>;
16
16
  type StackVariantProps = VariantProps<typeof stackVariants>;
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "0.58.0",
3
- "generatedAt": "2026-06-12T16:11:56.418Z",
2
+ "version": "0.58.1",
3
+ "generatedAt": "2026-06-13T22:37:33.156Z",
4
4
  "components": [
5
5
  {
6
6
  "name": "Accordion",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wallarm-org/design-system",
3
- "version": "0.58.1",
3
+ "version": "0.59.0",
4
4
  "description": "Core design system library with React components and Storybook documentation",
5
5
  "publishConfig": {
6
6
  "access": "public",