@floegence/floe-webapp-core 0.36.38 → 0.36.39

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.
@@ -0,0 +1,48 @@
1
+ import type { WorkbenchViewport } from './types';
2
+ export declare const WORKBENCH_EDGE_AUTO_PAN_FRAME_SELECTOR = "[data-floe-workbench-canvas-frame=\"true\"]";
3
+ export interface WorkbenchEdgeAutoPanFrame {
4
+ left: number;
5
+ top: number;
6
+ right: number;
7
+ bottom: number;
8
+ width: number;
9
+ height: number;
10
+ }
11
+ export interface WorkbenchEdgeAutoPanVelocityOptions {
12
+ frame: WorkbenchEdgeAutoPanFrame;
13
+ clientX: number;
14
+ clientY: number;
15
+ thresholdPx?: number;
16
+ outsideTolerancePx?: number;
17
+ maxSpeedPxPerSecond?: number;
18
+ }
19
+ export interface WorkbenchEdgeAutoPanVelocity {
20
+ viewportVelocityX: number;
21
+ viewportVelocityY: number;
22
+ }
23
+ export interface WorkbenchEdgeAutoPanStep {
24
+ viewportDeltaX: number;
25
+ viewportDeltaY: number;
26
+ worldDeltaX: number;
27
+ worldDeltaY: number;
28
+ viewport: WorkbenchViewport;
29
+ }
30
+ export interface WorkbenchEdgeAutoPanControllerOptions {
31
+ readFrame: () => WorkbenchEdgeAutoPanFrame | null;
32
+ readViewport: () => WorkbenchViewport | null;
33
+ commitViewport: (viewport: WorkbenchViewport) => void;
34
+ onPan?: (step: WorkbenchEdgeAutoPanStep) => void;
35
+ onPanStart?: () => void;
36
+ shouldPan?: () => boolean;
37
+ thresholdPx?: number;
38
+ outsideTolerancePx?: number;
39
+ activationDelayMs?: number;
40
+ maxSpeedPxPerSecond?: number;
41
+ }
42
+ export interface WorkbenchEdgeAutoPanController {
43
+ updatePointer: (clientX: number, clientY: number) => void;
44
+ stop: () => void;
45
+ }
46
+ export declare function resolveWorkbenchEdgeAutoPanVelocity(options: WorkbenchEdgeAutoPanVelocityOptions): WorkbenchEdgeAutoPanVelocity;
47
+ export declare function frameFromElement(element: HTMLElement | null | undefined): WorkbenchEdgeAutoPanFrame | null;
48
+ export declare function createWorkbenchEdgeAutoPanController(options: WorkbenchEdgeAutoPanControllerOptions): WorkbenchEdgeAutoPanController;
@@ -0,0 +1,134 @@
1
+ const N = '[data-floe-workbench-canvas-frame="true"]';
2
+ function c(e, t) {
3
+ return Number.isFinite(e) && Number(e) > 0 ? Number(e) : t;
4
+ }
5
+ function F(e) {
6
+ const { frame: t, clientX: i, clientY: r, outsideTolerancePx: n } = e;
7
+ return i >= t.left - n && i <= t.right + n && r >= t.top - n && r <= t.bottom + n;
8
+ }
9
+ function P(e, t) {
10
+ const i = (t - Math.max(0, e)) / t, r = Math.max(0, Math.min(1, i));
11
+ return r * r;
12
+ }
13
+ function X(e) {
14
+ const t = c(e.thresholdPx, 36), i = Math.max(0, c(
15
+ e.outsideTolerancePx,
16
+ 10
17
+ )), r = c(
18
+ e.maxSpeedPxPerSecond,
19
+ 480
20
+ ), n = e.frame;
21
+ if (!Number.isFinite(n.width) || n.width <= 0 || !Number.isFinite(n.height) || n.height <= 0 || !F({
22
+ frame: n,
23
+ clientX: e.clientX,
24
+ clientY: e.clientY,
25
+ outsideTolerancePx: i
26
+ }))
27
+ return { viewportVelocityX: 0, viewportVelocityY: 0 };
28
+ const l = r / 1e3, E = P(e.clientX - n.left, t), f = P(n.right - e.clientX, t), A = P(e.clientY - n.top, t), D = P(n.bottom - e.clientY, t);
29
+ return {
30
+ viewportVelocityX: (E - f) * l,
31
+ viewportVelocityY: (A - D) * l
32
+ };
33
+ }
34
+ function y(e) {
35
+ const t = e?.getBoundingClientRect();
36
+ return t ? {
37
+ left: t.left,
38
+ top: t.top,
39
+ right: t.right,
40
+ bottom: t.bottom,
41
+ width: t.width,
42
+ height: t.height
43
+ } : null;
44
+ }
45
+ function L(e) {
46
+ return typeof window > "u" || typeof window.requestAnimationFrame != "function" ? null : window.requestAnimationFrame(e);
47
+ }
48
+ function p(e) {
49
+ e === null || typeof window > "u" || typeof window.cancelAnimationFrame != "function" || window.cancelAnimationFrame(e);
50
+ }
51
+ function b(e) {
52
+ let t = null, i = null, r = null, n = null, l = !1, E = !1;
53
+ const f = () => c(e.thresholdPx, 36), A = () => Math.max(0, c(
54
+ e.outsideTolerancePx,
55
+ 10
56
+ )), D = () => Math.max(0, c(
57
+ e.activationDelayMs,
58
+ 100
59
+ )), M = () => c(
60
+ e.maxSpeedPxPerSecond,
61
+ 480
62
+ ), s = () => {
63
+ n = null, r = null;
64
+ }, a = () => {
65
+ l || i !== null || !t || (i = L(w));
66
+ }, w = (o) => {
67
+ if (i = null, l || !t) return;
68
+ if (e.shouldPan && !e.shouldPan()) {
69
+ s();
70
+ return;
71
+ }
72
+ const d = e.readFrame(), u = e.readViewport();
73
+ if (!d || !u) {
74
+ s();
75
+ return;
76
+ }
77
+ const _ = X({
78
+ frame: d,
79
+ clientX: t.clientX,
80
+ clientY: t.clientY,
81
+ thresholdPx: f(),
82
+ outsideTolerancePx: A(),
83
+ maxSpeedPxPerSecond: M()
84
+ });
85
+ if (_.viewportVelocityX === 0 && _.viewportVelocityY === 0) {
86
+ s();
87
+ return;
88
+ }
89
+ if (n === null) {
90
+ n = o, r = o, a();
91
+ return;
92
+ }
93
+ if (o - n < D()) {
94
+ r = o, a();
95
+ return;
96
+ }
97
+ const T = Math.max(0, Math.min(48, o - (r ?? o)));
98
+ if (r = o, T <= 0) {
99
+ a();
100
+ return;
101
+ }
102
+ const m = _.viewportVelocityX * T, h = _.viewportVelocityY * T;
103
+ if (Math.abs(m) < 0.01 && Math.abs(h) < 0.01) {
104
+ a();
105
+ return;
106
+ }
107
+ const x = Math.max(Math.abs(Number(u.scale)), 1e-3), S = {
108
+ ...u,
109
+ x: u.x + m,
110
+ y: u.y + h
111
+ };
112
+ E || (E = !0, e.onPanStart?.()), e.commitViewport(S), e.onPan?.({
113
+ viewportDeltaX: m,
114
+ viewportDeltaY: h,
115
+ worldDeltaX: -m / x,
116
+ worldDeltaY: -h / x,
117
+ viewport: S
118
+ }), a();
119
+ };
120
+ return {
121
+ updatePointer: (o, d) => {
122
+ t = { clientX: o, clientY: d }, a();
123
+ },
124
+ stop: () => {
125
+ l = !0, p(i), i = null, t = null, s();
126
+ }
127
+ };
128
+ }
129
+ export {
130
+ N as WORKBENCH_EDGE_AUTO_PAN_FRAME_SELECTOR,
131
+ b as createWorkbenchEdgeAutoPanController,
132
+ y as frameFromElement,
133
+ X as resolveWorkbenchEdgeAutoPanVelocity
134
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.36.38",
3
+ "version": "0.36.39",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",