impact-nova 3.0.0-alpha.22 → 3.0.0-alpha.23

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.
@@ -1,137 +1,140 @@
1
- import * as r from "react";
2
- import { centeredCamera as C, applyCameraViewBox as D, prefersReducedMotion as W, clampZoom as I, zoomCameraAt as H, HEX_ZOOM_DEFAULT as M, clientToSvgPoint as T, panCamera as E, HEX_BUTTON_ZOOM_STEP as Y, HEX_ZOOM_MIN as q, HEX_ZOOM_MAX as K, interpolateCamera as V, HEX_WHEEL_ZOOM_STEP as j, easeOutCubic as z } from "./hex-camera.js";
3
- const G = 180;
4
- function Q({
1
+ import * as e from "react";
2
+ import { centeredCamera as C, applyCameraViewBox as D, prefersReducedMotion as W, clampZoom as I, zoomCameraAt as Y, HEX_ZOOM_DEFAULT as O, clientToSvgPoint as T, panCamera as y, HEX_BUTTON_ZOOM_STEP as x, HEX_ZOOM_MIN as q, HEX_ZOOM_MAX as V, interpolateCamera as j, HEX_WHEEL_ZOOM_STEP as z, easeOutCubic as G } from "./hex-camera.js";
3
+ const J = 180;
4
+ function $({
5
5
  extents: f,
6
- zoom: m,
7
- onZoomChange: Z,
6
+ zoom: p,
7
+ onZoomChange: P,
8
8
  svgRef: l,
9
- viewportRef: P
9
+ viewportRef: Z,
10
+ wheelZoomMode: g
10
11
  }) {
11
- const [x, g] = r.useState(!1), c = r.useRef(C(f, m)), o = r.useRef(f), w = r.useRef(m), p = r.useRef(null), k = r.useRef(null), a = r.useCallback((t) => {
12
+ const [F, H] = e.useState(!1), c = e.useRef(C(f, p)), o = e.useRef(f), E = e.useRef(p), m = e.useRef(null), k = e.useRef(null), u = e.useCallback((t) => {
12
13
  c.current = t;
13
- const e = l.current;
14
- e && D(e, t);
15
- }, [l]), y = r.useCallback(
14
+ const r = l.current;
15
+ r && D(r, t);
16
+ }, [l]), A = e.useCallback(
16
17
  (t) => {
17
- const e = I(t);
18
- e !== w.current && Z(e);
18
+ const r = I(t);
19
+ r !== E.current && P(r);
19
20
  },
20
- [Z]
21
- ), d = r.useCallback(() => {
22
- p.current !== null && (cancelAnimationFrame(p.current), p.current = null);
23
- }, []), i = r.useCallback(
24
- (t, e) => {
21
+ [P]
22
+ ), d = e.useCallback(() => {
23
+ m.current !== null && (cancelAnimationFrame(m.current), m.current = null);
24
+ }, []), i = e.useCallback(
25
+ (t, r) => {
25
26
  d();
26
27
  const n = c.current;
27
- if (y(e), W()) {
28
- a(t);
28
+ if (A(r), W()) {
29
+ u(t);
29
30
  return;
30
31
  }
31
- const u = performance.now(), s = (X) => {
32
- const b = Math.min(1, (X - u) / G);
33
- if (a(V(n, t, z(b))), b < 1) {
34
- p.current = requestAnimationFrame(s);
32
+ const a = performance.now(), s = (X) => {
33
+ const b = Math.min(1, (X - a) / J);
34
+ if (u(j(n, t, G(b))), b < 1) {
35
+ m.current = requestAnimationFrame(s);
35
36
  return;
36
37
  }
37
- p.current = null;
38
+ m.current = null;
38
39
  };
39
- p.current = requestAnimationFrame(s);
40
+ m.current = requestAnimationFrame(s);
40
41
  },
41
- [d, y, a]
42
- ), A = f.width, _ = f.height;
43
- r.useEffect(() => {
44
- o.current = { width: A, height: _ }, w.current = m;
45
- }, [_, A, m]), r.useEffect(() => {
46
- const t = { width: A, height: _ };
42
+ [d, A, u]
43
+ ), w = f.width, _ = f.height;
44
+ e.useEffect(() => {
45
+ o.current = { width: w, height: _ }, E.current = p;
46
+ }, [_, w, p]), e.useEffect(() => {
47
+ const t = { width: w, height: _ };
47
48
  o.current = t;
48
- const e = C(t, w.current);
49
- c.current = e;
49
+ const r = C(t, E.current);
50
+ c.current = r;
50
51
  const n = l.current;
51
- n && D(n, e);
52
- }, [_, A, l]), r.useLayoutEffect(() => {
52
+ n && D(n, r);
53
+ }, [_, w, l]), e.useLayoutEffect(() => {
53
54
  const t = l.current;
54
55
  t && D(t, c.current);
55
- }), r.useEffect(() => () => d(), [d]);
56
- const h = r.useCallback(
57
- (t, e, n = !1) => {
58
- const u = I(w.current + t), s = H(c.current, o.current, u, e);
56
+ }), e.useEffect(() => () => d(), [d]);
57
+ const h = e.useCallback(
58
+ (t, r, n = !1) => {
59
+ const a = I(E.current + t), s = Y(c.current, o.current, a, r);
59
60
  if (n) {
60
- d(), a(s), y(u);
61
+ d(), u(s), A(a);
61
62
  return;
62
63
  }
63
- i(s, u);
64
+ i(s, a);
64
65
  },
65
- [i, d, y, a]
66
- ), F = r.useCallback(
66
+ [i, d, A, u]
67
+ ), L = e.useCallback(
67
68
  (t) => {
68
- const e = I(t);
69
- i(H(c.current, o.current, e), e);
69
+ const r = I(t);
70
+ i(Y(c.current, o.current, r), r);
70
71
  },
71
72
  [i]
72
- ), O = r.useCallback(() => {
73
- i(C(o.current, M), M);
74
- }, [i]), L = r.useCallback(() => {
75
- i(C(o.current, M), M);
76
- }, [i]), S = r.useCallback(
73
+ ), M = e.useCallback(() => {
74
+ i(C(o.current, O), O);
75
+ }, [i]), S = e.useCallback(() => {
76
+ i(C(o.current, O), O);
77
+ }, [i]), R = e.useCallback(
77
78
  (t) => {
78
79
  t.button === 0 && (t.target.closest("[data-hex-tilemap-zoom]") || (k.current = {
79
80
  pointerId: t.pointerId,
80
81
  lastX: t.clientX,
81
82
  lastY: t.clientY
82
- }, t.currentTarget.setPointerCapture(t.pointerId), g(!0)));
83
+ }, t.currentTarget.setPointerCapture(t.pointerId), H(!0)));
83
84
  },
84
85
  []
85
- ), R = r.useCallback(
86
+ ), B = e.useCallback(
86
87
  (t) => {
87
- const e = k.current, n = l.current;
88
- if (!e || e.pointerId !== t.pointerId || !n) return;
89
- const u = T(n, e.lastX, e.lastY), s = T(n, t.clientX, t.clientY);
90
- e.lastX = t.clientX, e.lastY = t.clientY, !(!u || !s) && a(
91
- E(c.current, o.current, s.x - u.x, s.y - u.y)
88
+ const r = k.current, n = l.current;
89
+ if (!r || r.pointerId !== t.pointerId || !n) return;
90
+ const a = T(n, r.lastX, r.lastY), s = T(n, t.clientX, t.clientY);
91
+ r.lastX = t.clientX, r.lastY = t.clientY, !(!a || !s) && u(
92
+ y(c.current, o.current, s.x - a.x, s.y - a.y)
92
93
  );
93
94
  },
94
- [a, l]
95
- ), B = r.useCallback((t) => {
96
- t && k.current && k.current.pointerId !== t.pointerId || (k.current = null, g(!1));
95
+ [u, l]
96
+ ), N = e.useCallback((t) => {
97
+ t && k.current && k.current.pointerId !== t.pointerId || (k.current = null, H(!1));
97
98
  }, []);
98
- r.useEffect(() => {
99
- const t = P.current;
99
+ e.useEffect(() => {
100
+ const t = Z.current;
100
101
  if (!t) return;
101
- const e = (n) => {
102
+ const r = (n) => {
103
+ if (g === "pinch-only" && !n.ctrlKey)
104
+ return;
102
105
  n.preventDefault();
103
- const u = l.current, s = n.deltaY < 0 ? 1 : -1, X = n.ctrlKey ? 10 : j, b = u ? T(u, n.clientX, n.clientY) : null;
106
+ const a = l.current, s = n.deltaY < 0 ? 1 : -1, X = n.ctrlKey ? 10 : z, b = a ? T(a, n.clientX, n.clientY) : null;
104
107
  h(s * X, b ?? void 0, !0);
105
108
  };
106
- return t.addEventListener("wheel", e, { passive: !1 }), () => t.removeEventListener("wheel", e);
107
- }, [l, P, h]);
108
- const N = r.useCallback(
109
+ return t.addEventListener("wheel", r, { passive: !1 }), () => t.removeEventListener("wheel", r);
110
+ }, [l, Z, g, h]);
111
+ const K = e.useCallback(
109
112
  (t) => {
110
- const e = c.current.width * 0.08;
111
- t.key === "+" || t.key === "=" ? (t.preventDefault(), h(Y)) : t.key === "-" || t.key === "_" ? (t.preventDefault(), h(-Y)) : t.key === "ArrowLeft" ? (t.preventDefault(), a(E(c.current, o.current, -e, 0))) : t.key === "ArrowRight" ? (t.preventDefault(), a(E(c.current, o.current, e, 0))) : t.key === "ArrowUp" ? (t.preventDefault(), a(E(c.current, o.current, 0, -e))) : t.key === "ArrowDown" ? (t.preventDefault(), a(E(c.current, o.current, 0, e))) : t.key === "0" && (t.preventDefault(), O());
113
+ const r = c.current.width * 0.08;
114
+ t.key === "+" || t.key === "=" ? (t.preventDefault(), h(x)) : t.key === "-" || t.key === "_" ? (t.preventDefault(), h(-x)) : t.key === "ArrowLeft" ? (t.preventDefault(), u(y(c.current, o.current, -r, 0))) : t.key === "ArrowRight" ? (t.preventDefault(), u(y(c.current, o.current, r, 0))) : t.key === "ArrowUp" ? (t.preventDefault(), u(y(c.current, o.current, 0, -r))) : t.key === "ArrowDown" ? (t.preventDefault(), u(y(c.current, o.current, 0, r))) : t.key === "0" && (t.preventDefault(), M());
112
115
  },
113
- [a, O, h]
114
- ), U = r.useMemo(
115
- () => C(f, m),
116
+ [u, M, h]
117
+ ), U = e.useMemo(
118
+ () => C(f, p),
116
119
  // Recapture only when the land frame changes so wheel/pan viewBox writes stay on the SVG.
117
120
  // eslint-disable-next-line react-hooks/exhaustive-deps
118
121
  [f.height, f.width]
119
122
  );
120
123
  return {
121
- isPanning: x,
122
- handlePointerDown: S,
123
- handlePointerMove: R,
124
- endPan: B,
125
- handleKeyDown: N,
124
+ isPanning: F,
125
+ handlePointerDown: R,
126
+ handlePointerMove: B,
127
+ endPan: N,
128
+ handleKeyDown: K,
126
129
  zoomBy: h,
127
- zoomTo: F,
128
- resetZoom: O,
129
- zoomToFit: L,
130
+ zoomTo: L,
131
+ resetZoom: M,
132
+ zoomToFit: S,
130
133
  initialViewBox: U,
131
- canZoomIn: m < K,
132
- canZoomOut: m > q
134
+ canZoomIn: p < V,
135
+ canZoomOut: p > q
133
136
  };
134
137
  }
135
138
  export {
136
- Q as useHexCamera
139
+ $ as useHexCamera
137
140
  };