@floegence/floe-webapp-core 0.36.16 → 0.36.17

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,14 +1,15 @@
1
- import { spread as B, mergeProps as j, insert as T, effect as q, className as G, setStyleProperty as J, template as K, use as Q } from "solid-js/web";
2
- import { createSignal as _, untrack as I, createEffect as L, onCleanup as A } from "solid-js";
1
+ import { spread as z, mergeProps as B, insert as _, effect as j, className as q, setStyleProperty as G, template as J, use as K } from "solid-js/web";
2
+ import { createSignal as T, untrack as L, createEffect as A, onCleanup as I } from "solid-js";
3
3
  import { cn as D } from "../../utils/cn.js";
4
4
  import { startHotInteraction as x } from "../../utils/hotInteraction.js";
5
- import { resolveSurfaceInteractionTargetRole as ee, resolveSurfaceWheelRouting as te, DEFAULT_CANVAS_WHEEL_INTERACTIVE_SELECTOR as ne } from "./localInteractionSurface.js";
5
+ import { resolveSurfaceInteractionTargetRole as Q, resolveSurfaceWheelRouting as ee, DEFAULT_CANVAS_WHEEL_INTERACTIVE_SELECTOR as te } from "./localInteractionSurface.js";
6
+ import { startPointerSession as ne } from "./pointerSession.js";
6
7
  import { clientToCanvasLocal as Y, localToCanvasWorld as re, createViewportFromZoomAnchor as oe } from "./canvasGeometry.js";
7
8
  import { SURFACE_PORTAL_LAYER_ATTR as ae } from "./dialogSurfaceScope.js";
8
- var ie = /* @__PURE__ */ K('<div><div style="transform-origin:0 0">');
9
- const ce = 1, le = 0.45, se = 2.2, ue = 14e-4, de = '[data-floe-canvas-pan-surface="true"]', R = 3;
10
- function fe(t, a, u) {
11
- return Math.max(a, Math.min(u, t));
9
+ var ie = /* @__PURE__ */ J('<div><div style="transform-origin:0 0">');
10
+ const ce = 1, le = 0.45, se = 2.2, ue = 14e-4, fe = '[data-floe-canvas-pan-surface="true"]', R = 3;
11
+ function de(t, a, f) {
12
+ return Math.max(a, Math.min(f, t));
12
13
  }
13
14
  function b(t) {
14
15
  return {
@@ -20,67 +21,73 @@ function b(t) {
20
21
  function me(t, a) {
21
22
  return t.deltaMode === 1 ? t.deltaY * 16 : t.deltaMode === 2 ? t.deltaY * (a?.clientHeight ?? window.innerHeight) : t.deltaY;
22
23
  }
23
- function ge(t) {
24
- const [a, u] = _(I(() => b(t.viewport))), [m, S] = _(null);
25
- let i, d, f = !1, l;
26
- const M = () => t.interactiveSelector ?? '[data-floe-canvas-interactive="true"]', X = () => t.panSurfaceSelector ?? de, F = () => t.wheelInteractiveSelector ?? ne, V = () => t.minScale ?? le, y = () => t.maxScale ?? se, k = () => t.wheelZoomSpeed ?? ue, U = () => {
27
- const e = m();
24
+ function Pe(t) {
25
+ const [a, f] = T(L(() => b(t.viewport))), [S, w] = T(null);
26
+ let i, s, d, m = !1, l;
27
+ const M = () => t.interactiveSelector ?? '[data-floe-canvas-interactive="true"]', X = () => t.panSurfaceSelector ?? fe, F = () => t.wheelInteractiveSelector ?? te, V = () => t.minScale ?? le, y = () => t.maxScale ?? se, k = () => t.wheelZoomSpeed ?? ue, N = () => {
28
+ const e = S();
28
29
  return e ? e.startedFromPanSurface ? e.moved : !0 : !1;
29
- }, w = () => {
30
+ }, v = () => {
30
31
  d !== void 0 && (window.clearTimeout(d), d = void 0);
31
32
  }, C = () => {
32
- f = !1, l !== void 0 && (window.clearTimeout(l), l = void 0);
33
- }, N = () => {
33
+ m = !1, l !== void 0 && (window.clearTimeout(l), l = void 0);
34
+ }, U = () => {
34
35
  if (typeof window > "u") {
35
- f = !1;
36
+ m = !1;
36
37
  return;
37
38
  }
38
39
  l !== void 0 && window.clearTimeout(l), l = window.setTimeout(() => {
39
- l = void 0, f = !1;
40
+ l = void 0, m = !1;
40
41
  }, 0);
41
- }, v = (e) => {
42
- I(() => t.onViewportChange?.(e));
42
+ }, g = (e) => {
43
+ L(() => t.onViewportChange?.(e));
43
44
  }, Z = (e) => {
44
45
  if (typeof window > "u") {
45
- v(e);
46
+ g(e);
46
47
  return;
47
48
  }
48
- w(), d = window.setTimeout(() => {
49
- d = void 0, v(e);
49
+ v(), d = window.setTimeout(() => {
50
+ d = void 0, g(e);
50
51
  }, 90);
51
- }, h = (e) => ee({
52
+ }, p = (e) => Q({
52
53
  target: e,
53
54
  interactiveSelector: M(),
54
55
  panSurfaceSelector: X()
55
- }), p = (e) => {
56
- const n = m();
57
- if (!n || e !== void 0 && n.pointerId !== e) return;
58
- n.stopInteraction?.();
59
- const r = a();
60
- S(null), i && i.hasPointerCapture(n.pointerId) && i.releasePointerCapture(n.pointerId), n.startedFromPanSurface && n.moved && (f = !0, N()), v(r);
56
+ }), H = () => {
57
+ const e = S();
58
+ if (!e) return;
59
+ e.stopInteraction?.();
60
+ const n = a();
61
+ w(null), s = void 0, e.startedFromPanSurface && e.moved && (m = !0, U()), g(n);
61
62
  };
62
- L(() => {
63
- m() || u(b(t.viewport));
64
- }), L(() => {
63
+ A(() => {
64
+ S() || f(b(t.viewport));
65
+ }), A(() => {
65
66
  const e = i;
66
67
  if (!e) return;
67
68
  const n = (r) => {
68
- !f || h(r.target) !== "pan_surface" || (C(), r.preventDefault(), r.stopPropagation());
69
+ !m || p(r.target) !== "pan_surface" || (C(), r.preventDefault(), r.stopPropagation());
69
70
  };
70
- e.addEventListener("click", n, !0), e.addEventListener("wheel", P, {
71
+ e.addEventListener("click", n, !0), e.addEventListener("wheel", h, {
71
72
  passive: !1
72
- }), A(() => {
73
- e.removeEventListener("click", n, !0), e.removeEventListener("wheel", P);
73
+ }), I(() => {
74
+ e.removeEventListener("click", n, !0), e.removeEventListener("wheel", h);
74
75
  });
75
- }), A(() => {
76
- w(), p(), C();
76
+ }), I(() => {
77
+ v(), s?.stop({
78
+ reason: "manual_stop",
79
+ commit: !0
80
+ }), s = void 0, C();
77
81
  });
78
- const H = (e) => {
82
+ const W = (e) => {
79
83
  if (e.button !== 0) return;
80
- const n = h(e.target);
84
+ const n = p(e.target);
81
85
  if (n === "canvas" && t.onCanvasPointerDown?.(e), t.disablePanZoom) return;
82
86
  const r = n === "pan_surface";
83
- n !== "local_surface" && (w(), C(), r || (t.onViewportInteractionStart?.("pan"), e.preventDefault(), i?.setPointerCapture(e.pointerId)), S({
87
+ n !== "local_surface" && (v(), C(), r || (t.onViewportInteractionStart?.("pan"), e.preventDefault()), s?.stop({
88
+ reason: "manual_stop",
89
+ commit: !0
90
+ }), w({
84
91
  pointerId: e.pointerId,
85
92
  startClientX: e.clientX,
86
93
  startClientY: e.clientY,
@@ -91,33 +98,37 @@ function ge(t) {
91
98
  kind: "drag",
92
99
  cursor: "grabbing"
93
100
  })
101
+ }), s = ne({
102
+ pointerEvent: e,
103
+ captureEl: i ?? null,
104
+ capturePointer: !r,
105
+ onMove: O,
106
+ onEnd: () => {
107
+ H();
108
+ }
94
109
  }));
95
- }, W = (e) => {
96
- const n = m();
110
+ }, O = (e) => {
111
+ const n = S();
97
112
  if (!n || n.pointerId !== e.pointerId) return;
98
113
  const r = e.clientX - n.startClientX, o = e.clientY - n.startClientY;
99
114
  if (!(n.moved || Math.abs(r) > R || Math.abs(o) > R)) return;
100
- n.moved || (e.preventDefault(), i?.hasPointerCapture(e.pointerId) || i?.setPointerCapture(e.pointerId));
101
- const s = {
115
+ n.moved || (e.preventDefault(), (!i || typeof i.hasPointerCapture != "function" || !i.hasPointerCapture(e.pointerId)) && s?.capturePointer());
116
+ const u = {
102
117
  ...n.startViewport,
103
118
  x: n.startViewport.x + r,
104
119
  y: n.startViewport.y + o
105
120
  };
106
- n.moved || S({
121
+ n.moved || w({
107
122
  ...n,
108
123
  moved: !0,
109
124
  stopInteraction: n.stopInteraction ?? x({
110
125
  kind: "drag",
111
126
  cursor: "grabbing"
112
127
  })
113
- }), u(s);
114
- }, O = (e) => {
115
- p(e.pointerId);
116
- }, $ = (e) => {
117
- p(e.pointerId);
118
- }, P = (e) => {
128
+ }), f(u);
129
+ }, h = (e) => {
119
130
  const n = i?.getBoundingClientRect();
120
- if (!n || te({
131
+ if (!n || ee({
121
132
  target: e.target,
122
133
  disablePanZoom: !!t.disablePanZoom,
123
134
  wheelInteractiveSelector: F()
@@ -126,16 +137,16 @@ function ge(t) {
126
137
  const o = a(), c = Y(n, {
127
138
  clientX: e.clientX,
128
139
  clientY: e.clientY
129
- }), s = me(e, i), g = fe(o.scale * Math.exp(-s * k()), V(), y());
130
- if (Math.abs(g - o.scale) < 1e-4) return;
131
- const E = oe({
140
+ }), u = me(e, i), E = de(o.scale * Math.exp(-u * k()), V(), y());
141
+ if (Math.abs(E - o.scale) < 1e-4) return;
142
+ const P = oe({
132
143
  viewport: o,
133
144
  localPoint: c,
134
- nextScale: g
145
+ nextScale: E
135
146
  });
136
- u(E), Z(E);
137
- }, z = (e) => {
138
- if (h(e.target) !== "canvas") return;
147
+ f(P), Z(P);
148
+ }, $ = (e) => {
149
+ if (p(e.target) !== "canvas") return;
139
150
  const n = i?.getBoundingClientRect();
140
151
  if (!n) return;
141
152
  e.preventDefault();
@@ -154,24 +165,21 @@ function ge(t) {
154
165
  };
155
166
  return (() => {
156
167
  var e = ie(), n = e.firstChild, r = i;
157
- return typeof r == "function" ? Q(r, e) : i = e, B(e, j({
168
+ return typeof r == "function" ? K(r, e) : i = e, z(e, B({
158
169
  get class() {
159
- return D("floe-infinite-canvas", U() && "is-panning", t.disablePanZoom && "is-locked", t.class);
170
+ return D("floe-infinite-canvas", N() && "is-panning", t.disablePanZoom && "is-locked", t.class);
160
171
  }
161
172
  }, {
162
173
  [ae]: "true"
163
174
  }, {
164
- onPointerDown: H,
165
- onPointerMove: W,
166
- onPointerUp: O,
167
- onPointerCancel: $,
168
- onContextMenu: z,
175
+ onPointerDown: W,
176
+ onContextMenu: $,
169
177
  get "aria-label"() {
170
178
  return t.ariaLabel ?? "Infinite canvas";
171
179
  }
172
- }), !1, !0), T(n, () => t.children), T(e, () => t.overlay?.(a()), null), q((o) => {
173
- var c = D("floe-infinite-canvas__viewport", t.contentClass), s = `translate(${a().x}px, ${a().y}px) scale(${a().scale})`;
174
- return c !== o.e && G(n, o.e = c), s !== o.t && J(n, "transform", o.t = s), o;
180
+ }), !1, !0), _(n, () => t.children), _(e, () => t.overlay?.(a()), null), j((o) => {
181
+ var c = D("floe-infinite-canvas__viewport", t.contentClass), u = `translate(${a().x}px, ${a().y}px) scale(${a().scale})`;
182
+ return c !== o.e && q(n, o.e = c), u !== o.t && G(n, "transform", o.t = u), o;
175
183
  }, {
176
184
  e: void 0,
177
185
  t: void 0
@@ -179,5 +187,5 @@ function ge(t) {
179
187
  })();
180
188
  }
181
189
  export {
182
- ge as InfiniteCanvas
190
+ Pe as InfiniteCanvas
183
191
  };
@@ -7,6 +7,7 @@ export { Dropdown, Select, type DropdownProps, type DropdownItem, type SelectPro
7
7
  export { Tooltip, type TooltipProps } from './Tooltip';
8
8
  export { CommandPalette } from './CommandPalette';
9
9
  export { InfiniteCanvas, type InfiniteCanvasProps, type InfiniteCanvasPoint, type InfiniteCanvasContextMenuEvent, } from './InfiniteCanvas';
10
+ export { startPointerSession, type PointerSessionController, type PointerSessionEndEvent, type PointerSessionEndReason, type PointerSessionSnapshot, type StartPointerSessionOptions, } from './pointerSession';
10
11
  export { clientToCanvasLocal, clientToCanvasWorld, createViewportFromZoomAnchor, isPointInsideCanvasRect, localToCanvasWorld, type CanvasClientPoint, type CanvasLocalPoint, type CanvasViewportLike, type CanvasViewportRectLike, type CanvasWorldPoint, } from './canvasGeometry';
11
12
  export { CANVAS_WHEEL_INTERACTIVE_ATTR, DEFAULT_CANVAS_WHEEL_INTERACTIVE_SELECTOR, LOCAL_INTERACTION_SURFACE_ATTR, DEFAULT_LOCAL_INTERACTION_SURFACE_SELECTOR, WORKBENCH_WIDGET_SHELL_ATTR, DEFAULT_WORKBENCH_WIDGET_SHELL_SELECTOR, isLocalInteractionSurfaceTarget, resolveSurfaceInteractionTargetRole, resolveSurfaceWheelRouting, resolveWorkbenchWidgetEventOwnership, type SurfaceInteractionRoutingOptions, type SurfaceInteractionTargetRole, type SurfaceWheelLocalReason, type SurfaceWheelRoutingDecision, type SurfaceWheelRoutingOptions, type WorkbenchWidgetEventOwnership, type WorkbenchWidgetEventOwnershipOptions, } from './localInteractionSurface';
12
13
  export { DIALOG_SURFACE_HOST_ATTR, SURFACE_PORTAL_HOST_ATTR, SURFACE_PORTAL_LAYER_ATTR, DIALOG_SURFACE_BOUNDARY_ATTR, ensureSurfacePortalInteractionTracking, isSurfacePortalMode, projectSurfacePortalPosition, projectSurfacePortalRect, resolveSurfacePortalBoundaryRect, resolveSurfacePortalHost, resolveSurfacePortalMount, resolveSurfacePortalMountRect, __resetSurfacePortalScopeForTests, type ResolvedSurfacePortalHost, type SurfacePortalBoundaryRect, type SurfacePortalInteractionSnapshot, type SurfacePortalMode, type SurfacePortalRect, } from './surfacePortalScope';
@@ -0,0 +1,35 @@
1
+ export type PointerSessionEndReason = 'pointer_up' | 'pointer_cancel' | 'buttons_released' | 'lost_pointer_capture' | 'window_blur' | 'document_hidden' | 'manual_stop';
2
+ export interface PointerSessionSnapshot {
3
+ pointerId: number;
4
+ latestClientX: number;
5
+ latestClientY: number;
6
+ latestButtons: number;
7
+ active: boolean;
8
+ captureActive: boolean;
9
+ }
10
+ export interface PointerSessionEndEvent {
11
+ reason: PointerSessionEndReason;
12
+ commit: boolean;
13
+ snapshot: PointerSessionSnapshot;
14
+ event?: Pick<PointerEvent, 'pointerId' | 'clientX' | 'clientY' | 'buttons'>;
15
+ }
16
+ export interface StartPointerSessionOptions {
17
+ pointerEvent: PointerEvent;
18
+ captureEl?: HTMLElement | null;
19
+ ownerDocument?: Document;
20
+ buttonMask?: number;
21
+ capturePointer?: boolean;
22
+ onMove?: (event: PointerEvent, snapshot: PointerSessionSnapshot) => void;
23
+ onEnd: (event: PointerSessionEndEvent) => void;
24
+ }
25
+ export interface PointerSessionController {
26
+ snapshot: () => PointerSessionSnapshot;
27
+ updatePointer: (event: Pick<PointerEvent, 'pointerId' | 'clientX' | 'clientY' | 'buttons'>) => void;
28
+ capturePointer: () => void;
29
+ stop: (options?: {
30
+ reason?: PointerSessionEndReason;
31
+ commit?: boolean;
32
+ event?: Pick<PointerEvent, 'pointerId' | 'clientX' | 'clientY' | 'buttons'>;
33
+ }) => void;
34
+ }
35
+ export declare function startPointerSession(options: StartPointerSessionOptions): PointerSessionController;
@@ -0,0 +1,85 @@
1
+ function C(e) {
2
+ if (e.ownerDocument) return e.ownerDocument;
3
+ if (e.captureEl?.ownerDocument) return e.captureEl.ownerDocument;
4
+ const n = e.pointerEvent.target;
5
+ return n && typeof n == "object" && "ownerDocument" in n && n.ownerDocument instanceof Document ? n.ownerDocument : document;
6
+ }
7
+ function c(e, n) {
8
+ return typeof e.buttons == "number" ? e.buttons : n;
9
+ }
10
+ function L(e, n) {
11
+ return !e || e.pointerId === n;
12
+ }
13
+ function b(e) {
14
+ const n = C(e), l = n.defaultView ?? window, a = e.buttonMask ?? 1, h = c(e.pointerEvent, a), t = {
15
+ pointerId: e.pointerEvent.pointerId,
16
+ latestClientX: e.pointerEvent.clientX,
17
+ latestClientY: e.pointerEvent.clientY,
18
+ latestButtons: h,
19
+ active: !0,
20
+ captureActive: !1
21
+ }, o = (r) => {
22
+ !t.active || r.pointerId !== t.pointerId || (t.latestClientX = r.clientX, t.latestClientY = r.clientY, t.latestButtons = c(r, t.latestButtons));
23
+ }, s = () => {
24
+ if (t.active && !(!e.captureEl || typeof e.captureEl.setPointerCapture != "function"))
25
+ try {
26
+ e.captureEl.setPointerCapture(t.pointerId), t.captureActive = !0;
27
+ } catch {
28
+ }
29
+ }, w = () => {
30
+ if (!e.captureEl || typeof e.captureEl.releasePointerCapture != "function") {
31
+ t.captureActive = !1;
32
+ return;
33
+ }
34
+ try {
35
+ (typeof e.captureEl.hasPointerCapture != "function" || e.captureEl.hasPointerCapture(t.pointerId)) && e.captureEl.releasePointerCapture(t.pointerId);
36
+ } catch {
37
+ } finally {
38
+ t.captureActive = !1;
39
+ }
40
+ }, P = () => {
41
+ n.removeEventListener("pointermove", p, !0), n.removeEventListener("pointerup", d, !0), n.removeEventListener("pointercancel", f, !0), n.removeEventListener("visibilitychange", E), l.removeEventListener("blur", v), e.captureEl?.removeEventListener("lostpointercapture", m);
42
+ }, i = (r = {}) => {
43
+ if (!t.active) return;
44
+ const u = r.event;
45
+ L(u, t.pointerId) && (u && o(u), t.active = !1, P(), w(), e.onEnd({
46
+ reason: r.reason ?? "manual_stop",
47
+ commit: r.commit ?? !1,
48
+ snapshot: t,
49
+ ...u ? { event: u } : {}
50
+ }));
51
+ };
52
+ function p(r) {
53
+ if (!(!t.active || r.pointerId !== t.pointerId)) {
54
+ if (o(r), a > 0 && (c(r, t.latestButtons) & a) !== a) {
55
+ i({ reason: "buttons_released", commit: !0, event: r });
56
+ return;
57
+ }
58
+ e.onMove?.(r, t);
59
+ }
60
+ }
61
+ function d(r) {
62
+ i({ reason: "pointer_up", commit: !0, event: r });
63
+ }
64
+ function f(r) {
65
+ i({ reason: "pointer_cancel", commit: !1, event: r });
66
+ }
67
+ function m() {
68
+ i({ reason: "lost_pointer_capture", commit: !0 });
69
+ }
70
+ function v() {
71
+ i({ reason: "window_blur", commit: !0 });
72
+ }
73
+ function E() {
74
+ n.hidden && i({ reason: "document_hidden", commit: !0 });
75
+ }
76
+ return n.addEventListener("pointermove", p, !0), n.addEventListener("pointerup", d, !0), n.addEventListener("pointercancel", f, !0), n.addEventListener("visibilitychange", E), l.addEventListener("blur", v), e.captureEl?.addEventListener("lostpointercapture", m), e.capturePointer !== !1 && s(), {
77
+ snapshot: () => t,
78
+ updatePointer: o,
79
+ capturePointer: s,
80
+ stop: i
81
+ };
82
+ }
83
+ export {
84
+ b as startPointerSession
85
+ };