@floegence/floe-webapp-core 0.103.4 → 0.103.6

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,41 +1,44 @@
1
- import { spread as j, mergeProps as q, insert as T, effect as G, className as J, setStyleProperty as K, template as Q, use as ee } from "solid-js/web";
2
- import { createSignal as b, untrack as x, createMemo as te, createEffect as A, onCleanup as D } from "solid-js";
3
- import { cn as y } from "../../utils/cn.js";
4
- import { startHotInteraction as I } from "../../utils/hotInteraction.js";
5
- import { resolveSurfaceInteractionTargetRole as ne, resolveSurfaceWheelRouting as re, DEFAULT_CANVAS_WHEEL_INTERACTIVE_SELECTOR as oe } from "./localInteractionSurface.js";
6
- import { startPointerSession as ae } from "./pointerSession.js";
7
- import { clientToCanvasLocal as R, localToCanvasWorld as ie, createViewportFromZoomAnchor as ce } from "./canvasGeometry.js";
8
- import { SURFACE_PORTAL_LAYER_ATTR as le } from "./dialogSurfaceScope.js";
9
- var se = /* @__PURE__ */ Q('<div><div style="transform-origin:0 0">');
10
- const ue = 1, de = 0.45, fe = 2.2, me = 14e-4, we = '[data-floe-canvas-pan-surface="true"]', Y = 3;
11
- function Se(t, s, i) {
1
+ import { spread as G, mergeProps as J, insert as x, effect as K, className as Q, setStyleProperty as ee, template as te, use as ne } from "solid-js/web";
2
+ import { createSignal as D, untrack as y, createMemo as re, createEffect as R, onCleanup as Y } from "solid-js";
3
+ import { cn as F } from "../../utils/cn.js";
4
+ import { resolveSurfaceInteractionTargetRole as oe, resolveSurfaceWheelRouting as ae, DEFAULT_CANVAS_WHEEL_INTERACTIVE_SELECTOR as ie } from "./localInteractionSurface.js";
5
+ import { startPointerSession as ce } from "./pointerSession.js";
6
+ import { clientToCanvasLocal as M, localToCanvasWorld as le, createViewportFromZoomAnchor as se } from "./canvasGeometry.js";
7
+ import { SURFACE_PORTAL_LAYER_ATTR as ue } from "./dialogSurfaceScope.js";
8
+ var de = /* @__PURE__ */ te('<div><div style="transform-origin:0 0">');
9
+ const fe = 1, me = 0.45, we = 2.2, ve = 14e-4, Se = '[data-floe-canvas-pan-surface="true"]', I = 3;
10
+ function pe(t, s, i) {
12
11
  return Math.max(s, Math.min(i, t));
13
12
  }
14
- function k(t) {
13
+ function X(t) {
15
14
  return {
16
15
  x: Number.isFinite(t.x) ? t.x : 0,
17
16
  y: Number.isFinite(t.y) ? t.y : 0,
18
- scale: Number.isFinite(t.scale) && t.scale > 0 ? t.scale : ue
17
+ scale: Number.isFinite(t.scale) && t.scale > 0 ? t.scale : fe
19
18
  };
20
19
  }
21
- function ve(t, s) {
20
+ function Ee(t, s) {
22
21
  return t.deltaMode === 1 ? t.deltaY * 16 : t.deltaMode === 2 ? t.deltaY * (s?.clientHeight ?? window.innerHeight) : t.deltaY;
23
22
  }
24
- function Te(t) {
23
+ function Ae(t) {
25
24
  let s = !1;
26
- const [i, S] = b(x(() => k(t.viewport))), [w, v] = b(null), M = te(() => {
25
+ const [i, w] = D(y(() => X(t.viewport))), [v, E] = D(null), k = re(() => {
27
26
  const e = t.children;
28
27
  return typeof e == "function" ? e(i) : e;
29
28
  });
30
- let l, d, f, m = !1, u;
31
- const X = () => t.interactiveSelector ?? '[data-floe-canvas-interactive="true"]', F = () => t.panSurfaceSelector ?? we, V = () => t.wheelInteractiveSelector ?? oe, N = () => t.minScale ?? de, H = () => t.maxScale ?? fe, U = () => t.wheelZoomSpeed ?? me, W = () => {
32
- const e = w();
29
+ let l, d, S, p;
30
+ const L = () => {
31
+ p = void 0, S && w(S), S = void 0;
32
+ };
33
+ let f, m = !1, u;
34
+ const V = () => t.interactiveSelector ?? '[data-floe-canvas-interactive="true"]', N = () => t.panSurfaceSelector ?? Se, U = () => t.wheelInteractiveSelector ?? ie, W = () => t.minScale ?? me, Z = () => t.maxScale ?? we, H = () => t.wheelZoomSpeed ?? ve, O = () => {
35
+ const e = v();
33
36
  return e ? e.startedFromPanSurface ? e.moved : !0 : !1;
34
- }, p = () => {
37
+ }, C = () => {
35
38
  f !== void 0 && (window.clearTimeout(f), f = void 0);
36
39
  }, g = () => {
37
40
  m = !1, u !== void 0 && (window.clearTimeout(u), u = void 0);
38
- }, Z = () => {
41
+ }, $ = () => {
39
42
  if (typeof window > "u") {
40
43
  m = !1;
41
44
  return;
@@ -43,34 +46,34 @@ function Te(t) {
43
46
  u !== void 0 && window.clearTimeout(u), u = window.setTimeout(() => {
44
47
  u = void 0, m = !1;
45
48
  }, 0);
46
- }, E = (e) => {
47
- x(() => t.onViewportChange?.(e));
48
- }, O = (e) => {
49
+ }, h = (e) => {
50
+ y(() => t.onViewportChange?.(e));
51
+ }, z = (e) => {
49
52
  if (typeof window > "u") {
50
- E(e);
53
+ h(e);
51
54
  return;
52
55
  }
53
- p(), f = window.setTimeout(() => {
54
- f = void 0, E(e);
56
+ C(), f = window.setTimeout(() => {
57
+ f = void 0, h(e);
55
58
  }, 90);
56
- }, C = (e) => (t.resolveTargetRole ?? ne)({
59
+ }, P = (e) => (t.resolveTargetRole ?? oe)({
57
60
  target: e,
58
- interactiveSelector: X(),
59
- panSurfaceSelector: F()
60
- }), $ = () => {
61
- const e = w();
61
+ interactiveSelector: V(),
62
+ panSurfaceSelector: N()
63
+ }), B = () => {
64
+ const e = v();
62
65
  if (!e) return;
63
- e.stopInteraction?.();
66
+ p !== void 0 && window.cancelAnimationFrame(p), L();
64
67
  const n = i();
65
- v(null), d = void 0, e.startedFromPanSurface && e.moved && (m = !0, Z()), E(n);
68
+ E(null), d = void 0, e.startedFromPanSurface && e.moved && (m = !0, $()), h(n);
66
69
  };
67
- A(() => {
68
- w() || S(k(t.viewport));
69
- }), A(() => {
70
+ R(() => {
71
+ v() || w(X(t.viewport));
72
+ }), R(() => {
70
73
  const e = l;
71
74
  if (!e) return;
72
75
  const n = (o) => {
73
- !m || C(o.target) !== "pan_surface" || (g(), o.preventDefault(), o.stopPropagation());
76
+ !m || P(o.target) !== "pan_surface" || (g(), o.preventDefault(), o.stopPropagation());
74
77
  }, a = (o) => {
75
78
  o.code !== "Space" || o.isComposing || o.target instanceof Element && o.target.closest('input, textarea, select, [contenteditable="true"], [contenteditable="plaintext-only"]') || (s = !0, e.contains(o.target) && o.preventDefault());
76
79
  }, r = () => {
@@ -78,96 +81,92 @@ function Te(t) {
78
81
  };
79
82
  document.addEventListener("keydown", a), document.addEventListener("keyup", r), window.addEventListener("blur", r);
80
83
  const c = (o) => {
81
- (o.button === 1 || o.button === 0 && s) && h(o);
84
+ (o.button === 1 || o.button === 0 && s) && _(o);
82
85
  };
83
- e.addEventListener("pointerdown", c, !0), e.addEventListener("click", n, !0), e.addEventListener("wheel", P, {
86
+ e.addEventListener("pointerdown", c, !0), e.addEventListener("click", n, !0), e.addEventListener("wheel", T, {
84
87
  passive: !1
85
- }), D(() => {
86
- document.removeEventListener("keydown", a), document.removeEventListener("keyup", r), window.removeEventListener("blur", r), e.removeEventListener("pointerdown", c, !0), e.removeEventListener("click", n, !0), e.removeEventListener("wheel", P);
88
+ }), Y(() => {
89
+ document.removeEventListener("keydown", a), document.removeEventListener("keyup", r), window.removeEventListener("blur", r), e.removeEventListener("pointerdown", c, !0), e.removeEventListener("click", n, !0), e.removeEventListener("wheel", T);
87
90
  });
88
- }), D(() => {
89
- p(), d?.stop({
91
+ }), Y(() => {
92
+ C(), d?.stop({
90
93
  reason: "manual_stop",
91
94
  commit: !0
92
95
  }), d = void 0, g();
93
96
  });
94
- const h = (e) => {
97
+ const _ = (e) => {
95
98
  const n = e.button === 1 || e.button === 0 && s;
96
99
  if (e.button !== 0 && e.button !== 1) return;
97
- const a = n ? "canvas" : C(e.target);
100
+ const a = n ? "canvas" : P(e.target);
98
101
  if (a === "canvas" && t.onCanvasPointerDown?.(e), t.disablePanZoom) return;
99
102
  n && e.stopPropagation();
100
103
  const r = a === "pan_surface";
101
- a !== "local_surface" && (p(), g(), r || (t.onViewportInteractionStart?.("pan"), e.preventDefault()), d?.stop({
104
+ a !== "local_surface" && (C(), g(), r || (t.onViewportInteractionStart?.("pan"), e.preventDefault()), d?.stop({
102
105
  reason: "manual_stop",
103
106
  commit: !0
104
- }), v({
107
+ }), E({
105
108
  pointerId: e.pointerId,
106
109
  startClientX: e.clientX,
107
110
  startClientY: e.clientY,
108
111
  startViewport: i(),
109
112
  moved: !1,
110
- startedFromPanSurface: r,
111
- stopInteraction: r ? void 0 : I({
112
- kind: "drag",
113
- cursor: "grabbing"
114
- })
115
- }), d = ae({
113
+ startedFromPanSurface: r
114
+ }), d = ce({
116
115
  pointerEvent: e,
117
116
  captureEl: l ?? null,
118
117
  capturePointer: !r,
119
- onMove: z,
118
+ onMove: q,
120
119
  onEnd: () => {
121
- $();
120
+ B();
122
121
  }
123
122
  }));
124
- }, z = (e) => {
125
- const n = w();
123
+ }, q = (e) => {
124
+ const n = v();
126
125
  if (!n || n.pointerId !== e.pointerId) return;
127
126
  const a = e.clientX - n.startClientX, r = e.clientY - n.startClientY;
128
- if (!(n.moved || Math.abs(a) > Y || Math.abs(r) > Y)) return;
127
+ if (!(n.moved || Math.abs(a) > I || Math.abs(r) > I)) return;
129
128
  n.moved || (e.preventDefault(), (!l || typeof l.hasPointerCapture != "function" || !l.hasPointerCapture(e.pointerId)) && d?.capturePointer());
130
129
  const o = {
131
130
  ...n.startViewport,
132
131
  x: n.startViewport.x + a,
133
132
  y: n.startViewport.y + r
134
133
  };
135
- n.moved || v({
136
- ...n,
137
- moved: !0,
138
- stopInteraction: n.stopInteraction ?? I({
139
- kind: "drag",
140
- cursor: "grabbing"
141
- })
142
- }), S(o);
143
- }, P = (e) => {
134
+ if (!n.moved) {
135
+ E({
136
+ ...n,
137
+ moved: !0
138
+ }), w(o);
139
+ return;
140
+ }
141
+ S = o, p ??= window.requestAnimationFrame(L);
142
+ }, T = (e) => {
144
143
  const n = l?.getBoundingClientRect();
145
- if (!n || (t.resolveWheelRouting ?? re)({
144
+ if (!n || (t.resolveWheelRouting ?? ae)({
146
145
  target: e.target,
147
146
  disablePanZoom: !!t.disablePanZoom,
148
- wheelInteractiveSelector: V()
147
+ wheelInteractiveSelector: U()
149
148
  }).kind !== "canvas_zoom") return;
150
149
  e.preventDefault(), t.onViewportInteractionStart?.("wheel");
151
- const r = i(), c = R(n, {
150
+ const r = i(), c = M(n, {
152
151
  clientX: e.clientX,
153
152
  clientY: e.clientY
154
- }), o = ve(e, l), L = Se(r.scale * Math.exp(-o * U()), N(), H());
155
- if (Math.abs(L - r.scale) < 1e-4) return;
156
- const _ = ce({
153
+ }), o = Ee(e, l), A = pe(r.scale * Math.exp(-o * H()), W(), Z());
154
+ if (Math.abs(A - r.scale) < 1e-4) return;
155
+ const b = se({
157
156
  viewport: r,
158
157
  localPoint: c,
159
- nextScale: L
158
+ nextScale: A
160
159
  });
161
- S(_), O(_);
162
- }, B = (e) => {
163
- if (C(e.target) !== "canvas") return;
160
+ w(b), z(b);
161
+ }, j = (e) => {
162
+ if (P(e.target) !== "canvas") return;
164
163
  const n = l?.getBoundingClientRect();
165
164
  if (!n) return;
166
165
  e.preventDefault();
167
- const a = R(n, {
166
+ const a = M(n, {
168
167
  clientX: e.clientX,
169
168
  clientY: e.clientY
170
- }), r = i(), c = ie(r, a);
169
+ }), r = i(), c = le(r, a);
171
170
  t.onCanvasContextMenu?.({
172
171
  clientX: e.clientX,
173
172
  clientY: e.clientY,
@@ -178,22 +177,22 @@ function Te(t) {
178
177
  });
179
178
  };
180
179
  return (() => {
181
- var e = se(), n = e.firstChild, a = l;
182
- return typeof a == "function" ? ee(a, e) : l = e, j(e, q({
180
+ var e = de(), n = e.firstChild, a = l;
181
+ return typeof a == "function" ? ne(a, e) : l = e, G(e, J({
183
182
  get class() {
184
- return y("floe-infinite-canvas", W() && "is-panning", t.disablePanZoom && "is-locked", t.class);
183
+ return F("floe-infinite-canvas", O() && "is-panning", t.disablePanZoom && "is-locked", t.class);
185
184
  }
186
185
  }, {
187
- [le]: "true"
186
+ [ue]: "true"
188
187
  }, {
189
- onPointerDown: h,
190
- onContextMenu: B,
188
+ onPointerDown: _,
189
+ onContextMenu: j,
191
190
  get "aria-label"() {
192
191
  return t.ariaLabel ?? "Infinite canvas";
193
192
  }
194
- }), !1, !0), T(n, M), T(e, () => t.overlay?.(i), null), G((r) => {
195
- var c = y("floe-infinite-canvas__viewport", t.contentClass), o = `translate(${i().x}px, ${i().y}px) scale(${i().scale})`;
196
- return c !== r.e && J(n, r.e = c), o !== r.t && K(n, "transform", r.t = o), r;
193
+ }), !1, !0), x(n, k), x(e, () => t.overlay?.(i), null), K((r) => {
194
+ var c = F("floe-infinite-canvas__viewport", t.contentClass), o = `translate(${i().x}px, ${i().y}px) scale(${i().scale})`;
195
+ return c !== r.e && Q(n, r.e = c), o !== r.t && ee(n, "transform", r.t = o), r;
197
196
  }, {
198
197
  e: void 0,
199
198
  t: void 0
@@ -201,5 +200,5 @@ function Te(t) {
201
200
  })();
202
201
  }
203
202
  export {
204
- Te as InfiniteCanvas
203
+ Ae as InfiniteCanvas
205
204
  };
@@ -13,3 +13,4 @@ export interface ViewActivationProviderProps {
13
13
  }
14
14
  export declare function ViewActivationProvider(props: ViewActivationProviderProps): JSX.Element;
15
15
  export declare function useViewActivation(): Required<ViewActivationContextValue>;
16
+ export declare function useViewVisibility(): Accessor<boolean>;
@@ -1,25 +1,29 @@
1
- import { createComponent as a } from "solid-js/web";
2
- import { useContext as o, untrack as v, createContext as u } from "solid-js";
3
- const i = u();
1
+ import { createComponent as u } from "solid-js/web";
2
+ import { useContext as n, untrack as v, createContext as a } from "solid-js";
3
+ const i = a();
4
4
  function w(t) {
5
- const n = o(i), e = v(() => t.value), r = e.visible ?? e.active, c = {
5
+ const o = n(i), e = v(() => t.value), r = e.visible ?? e.active, c = {
6
6
  ...e,
7
- visible: () => (n?.visible() ?? !0) && r()
7
+ visible: () => (o?.visible() ?? !0) && r()
8
8
  };
9
- return a(i.Provider, {
9
+ return u(i.Provider, {
10
10
  value: c,
11
11
  get children() {
12
12
  return t.children;
13
13
  }
14
14
  });
15
15
  }
16
- function d() {
17
- const t = o(i);
16
+ function V() {
17
+ const t = n(i);
18
18
  if (!t)
19
19
  throw new Error("ViewActivationContext not found. Wrap your view with <ViewActivationProvider />.");
20
20
  return t;
21
21
  }
22
+ function f() {
23
+ return n(i)?.visible ?? (() => !0);
24
+ }
22
25
  export {
23
26
  w as ViewActivationProvider,
24
- d as useViewActivation
27
+ V as useViewActivation,
28
+ f as useViewVisibility
25
29
  };