@floegence/floe-webapp-core 0.81.5 → 0.81.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.
- package/dist/remote-pointer.js +122 -119
- package/package.json +1 -1
package/dist/remote-pointer.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
function
|
|
2
|
-
const { surface: l } =
|
|
3
|
-
if (!
|
|
4
|
-
let o = null, f = null, u = null, p = null,
|
|
5
|
-
const
|
|
1
|
+
function R(d) {
|
|
2
|
+
const { surface: l } = d, I = l.ownerDocument, c = I.defaultView;
|
|
3
|
+
if (!c) throw new Error("Remote pointer requires an attached document");
|
|
4
|
+
let o = null, f = null, u = null, p = null, y = 0, z = !1, L = 0, O = 0, H = !1, K = !1, b = 0, D = !1;
|
|
5
|
+
const m = /* @__PURE__ */ new Set(), E = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Map(), P = [], k = (e) => !K && d.isTargetValid(e), x = (e, t) => Math.hypot(e.clientX - t.clientX, e.clientY - t.clientY), h = (e) => ({
|
|
6
6
|
clientX: e.clientX,
|
|
7
7
|
clientY: e.clientY,
|
|
8
8
|
shiftKey: e.shiftKey,
|
|
@@ -11,200 +11,203 @@ function F(a) {
|
|
|
11
11
|
metaKey: e.metaKey,
|
|
12
12
|
pointerType: "pointerType" in e ? String(e.pointerType) : "mouse"
|
|
13
13
|
});
|
|
14
|
-
function
|
|
15
|
-
const
|
|
16
|
-
e.addEventListener(t,
|
|
14
|
+
function a(e, t, n, i = !1) {
|
|
15
|
+
const s = n;
|
|
16
|
+
e.addEventListener(t, s, { capture: i, passive: !1 }), P.push(() => e.removeEventListener(t, s, i));
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
const n =
|
|
18
|
+
function _(e, t) {
|
|
19
|
+
const n = k(t) && d.sendPointer(e, t) !== !1;
|
|
20
20
|
if (n && e.kind === "move")
|
|
21
|
-
for (const i of
|
|
21
|
+
for (const i of g.values()) i.target === t && (i.command = { ...i.command, ...h(e) });
|
|
22
22
|
return n;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
24
|
+
function X() {
|
|
25
|
+
c.clearTimeout(O), O = 0, H && (H = !1, d.onHoldChange?.(null));
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
|
|
27
|
+
function A(e) {
|
|
28
|
+
E.delete(e), l.hasPointerCapture?.(e) && l.releasePointerCapture(e);
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
l.setPointerCapture?.(e),
|
|
30
|
+
function N(e) {
|
|
31
|
+
l.setPointerCapture?.(e), E.add(e);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
L++, z = !1,
|
|
33
|
+
function v() {
|
|
34
|
+
L++, z = !1, y && c.cancelAnimationFrame(y), y = 0;
|
|
35
35
|
const e = f;
|
|
36
|
-
f = null, e && !
|
|
36
|
+
f = null, e && !_(e.command, e.target) && r();
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
if (f && (f.target !== t || f.command.kind !== e.kind) &&
|
|
38
|
+
function C(e, t) {
|
|
39
|
+
if (f && (f.target !== t || f.command.kind !== e.kind) && v(), !!k(t)) {
|
|
40
40
|
if (e.kind === "scroll" && f?.command.kind === "scroll" && (e = { ...e, dx: f.command.dx + e.dx, dy: f.command.dy + e.dy }), f = { target: t, command: e }, e.kind === "move") {
|
|
41
41
|
if (!z) {
|
|
42
42
|
z = !0;
|
|
43
43
|
const n = L;
|
|
44
|
-
|
|
45
|
-
n === L &&
|
|
44
|
+
c.queueMicrotask(() => {
|
|
45
|
+
n === L && v();
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
if (!
|
|
51
|
-
const n =
|
|
52
|
-
n ===
|
|
50
|
+
if (!y) {
|
|
51
|
+
const n = b, i = c.requestAnimationFrame(() => {
|
|
52
|
+
n === b && y === i && v();
|
|
53
53
|
});
|
|
54
|
-
|
|
54
|
+
y = i;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
function T(e, t, n, i,
|
|
59
|
-
const
|
|
60
|
-
if (!e && !
|
|
61
|
-
e ||
|
|
62
|
-
const
|
|
63
|
-
|
|
58
|
+
function T(e, t, n, i, s = 1) {
|
|
59
|
+
const w = g.get(i);
|
|
60
|
+
if (!e && !w) return;
|
|
61
|
+
e || g.delete(i);
|
|
62
|
+
const M = { ...t, kind: e ? "down" : "up", button: i, clicks: s };
|
|
63
|
+
_(M, n) && e && g.set(i, { target: n, command: M });
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
const n =
|
|
67
|
-
return
|
|
65
|
+
function Y(e, t) {
|
|
66
|
+
const n = b;
|
|
67
|
+
return d.onActivate?.(e, t), n === b && k(t);
|
|
68
68
|
}
|
|
69
|
-
function
|
|
70
|
-
|
|
69
|
+
function B(e, t, n, i = 1) {
|
|
70
|
+
Y(e, t) && (T(!0, e, t, n, i), T(!1, e, t, n, i));
|
|
71
71
|
}
|
|
72
72
|
function r() {
|
|
73
|
-
|
|
73
|
+
b++, L++, z = !1, X(), y && c.cancelAnimationFrame(y), y = 0;
|
|
74
74
|
const e = /* @__PURE__ */ new Set();
|
|
75
|
-
o && e.add(o.target), f && e.add(f.target), u !== null && e.add(u), f = null, o = null, u = null, p = null,
|
|
76
|
-
for (const [t, n] of
|
|
75
|
+
o && e.add(o.target), f && e.add(f.target), u !== null && e.add(u), f = null, o = null, u = null, p = null, D = m.size > 0;
|
|
76
|
+
for (const [t, n] of g)
|
|
77
77
|
e.add(n.target), T(!1, n.command, n.target, t);
|
|
78
|
-
for (const t of e)
|
|
79
|
-
for (const t of [...
|
|
78
|
+
for (const t of e) d.release(t);
|
|
79
|
+
for (const t of [...E]) A(t);
|
|
80
80
|
}
|
|
81
81
|
function S(e) {
|
|
82
|
-
|
|
82
|
+
m.delete(e), A(e), m.size || (D = !1);
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function U(e) {
|
|
85
85
|
const t = o;
|
|
86
86
|
if (!t || t.id !== e.pointerId) return;
|
|
87
|
-
if (!
|
|
87
|
+
if (!k(t.target)) {
|
|
88
88
|
r();
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
|
-
const n =
|
|
92
|
-
if ((t.mode === "pending" || t.mode === "hold") &&
|
|
91
|
+
const n = h(e);
|
|
92
|
+
if ((t.mode === "pending" || t.mode === "hold") && x(t.origin, n) > 8) {
|
|
93
93
|
const i = t.mode === "hold";
|
|
94
|
-
if (
|
|
94
|
+
if (X(), p = null, t.mode = i ? "drag" : "scroll", i && Y(t.origin, t.target) && T(!0, t.origin, t.target, 0), o !== t) return;
|
|
95
95
|
}
|
|
96
96
|
if (t.mode === "scroll") {
|
|
97
|
-
const i = t.last,
|
|
98
|
-
(
|
|
99
|
-
} else t.mode === "drag" && (
|
|
97
|
+
const i = t.last, s = i.clientX - n.clientX, w = i.clientY - n.clientY;
|
|
98
|
+
(s || w) && C({ ...t.origin, kind: "scroll", dx: s, dy: w }, t.target), t.last = n;
|
|
99
|
+
} else t.mode === "drag" && (C({ ...n, kind: "move" }, t.target), t.last = n);
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
const t =
|
|
103
|
-
if (t === null || !
|
|
104
|
-
const n =
|
|
101
|
+
a(l, "pointerdown", (e) => {
|
|
102
|
+
const t = d.resolveTarget(e);
|
|
103
|
+
if (t === null || !k(t)) return;
|
|
104
|
+
const n = h(e);
|
|
105
105
|
if (e.pointerType === "touch") {
|
|
106
|
-
if (
|
|
106
|
+
if (m.add(e.pointerId), m.size > 1 || D) {
|
|
107
107
|
r();
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
|
-
(o ||
|
|
110
|
+
(o || g.size) && r(), v(), u !== null && (d.release(u), u = null), D = !1, o = { id: e.pointerId, target: t, origin: n, last: n, mode: "pending" };
|
|
111
111
|
const i = o;
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
if (!
|
|
112
|
+
O = c.setTimeout(() => {
|
|
113
|
+
if (O = 0, o === i) {
|
|
114
|
+
if (!k(t)) {
|
|
115
115
|
r();
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
|
-
i.mode = "hold",
|
|
118
|
+
i.mode = "hold", H = !0, d.onHoldChange?.({ ...n, target: t });
|
|
119
119
|
}
|
|
120
120
|
}, 450);
|
|
121
121
|
} else {
|
|
122
|
-
if (
|
|
122
|
+
if (m.size) {
|
|
123
123
|
r();
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
|
-
o && (o.id !== e.pointerId || o.target !== t) && r(),
|
|
127
|
-
const i = e.button === 0 && p?.target === t &&
|
|
128
|
-
|
|
126
|
+
o && (o.id !== e.pointerId || o.target !== t) && r(), v(), u !== null && (d.release(u), u = null), o = { id: e.pointerId, target: t, origin: n, last: n, mode: "direct" };
|
|
127
|
+
const i = e.button === 0 && p?.target === t && c.performance.now() - p.time <= 350 && x(p.position, n) <= 16;
|
|
128
|
+
Y(n, t) && T(!0, n, t, e.button, Math.max(1, e.detail, i ? 2 : 1));
|
|
129
129
|
}
|
|
130
|
-
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
const t = o?.target ?? a.resolveTarget(e);
|
|
138
|
-
if (t === null || !w(t)) {
|
|
130
|
+
N(e.pointerId), e.pointerType === "touch" && e.preventDefault();
|
|
131
|
+
});
|
|
132
|
+
const q = "onpointerrawupdate" in c;
|
|
133
|
+
function F(e, t) {
|
|
134
|
+
if (D || m.size) return;
|
|
135
|
+
const n = o?.target ?? d.resolveTarget(e);
|
|
136
|
+
if (n === null || !k(n)) {
|
|
139
137
|
o && r();
|
|
140
138
|
return;
|
|
141
139
|
}
|
|
142
|
-
const
|
|
140
|
+
const i = h(e);
|
|
143
141
|
if (o) {
|
|
144
|
-
o.last =
|
|
145
|
-
for (const [
|
|
146
|
-
const
|
|
147
|
-
|
|
142
|
+
t && (o.last = i);
|
|
143
|
+
for (const [s, w] of [[0, 1], [1, 4], [2, 2], [3, 8], [4, 16]]) {
|
|
144
|
+
const M = !!(e.buttons & w);
|
|
145
|
+
M !== g.has(s) && (v(), T(M, i, n, s));
|
|
148
146
|
}
|
|
149
147
|
}
|
|
150
|
-
|
|
151
|
-
}
|
|
148
|
+
t && C({ ...i, kind: "move" }, n);
|
|
149
|
+
}
|
|
150
|
+
q && a(l, "pointerrawupdate", (e) => {
|
|
151
|
+
e.pointerType !== "touch" && F(e, !0);
|
|
152
|
+
}), a(l, "pointermove", (e) => {
|
|
153
|
+
e.pointerType === "touch" ? U(e) : F(e, !q);
|
|
154
|
+
}), a(l, "pointerup", (e) => {
|
|
152
155
|
const t = o;
|
|
153
|
-
if (t?.id === e.pointerId && !
|
|
154
|
-
if (!
|
|
156
|
+
if (t?.id === e.pointerId && !D)
|
|
157
|
+
if (!k(t.target)) r();
|
|
155
158
|
else if (e.pointerType === "touch") {
|
|
156
|
-
|
|
157
|
-
const n =
|
|
159
|
+
U(e), X();
|
|
160
|
+
const n = h(e);
|
|
158
161
|
if (t.mode === "pending") {
|
|
159
|
-
const i =
|
|
160
|
-
|
|
161
|
-
} else t.mode === "hold" ? (p = null,
|
|
162
|
-
|
|
162
|
+
const i = c.performance.now(), s = p?.target === t.target && i - p.time <= 350 && x(p.position, n) <= 16;
|
|
163
|
+
B(n, t.target, 0, s ? 2 : 1), p = s ? null : { target: t.target, position: n, time: i };
|
|
164
|
+
} else t.mode === "hold" ? (p = null, B(n, t.target, 2)) : (v(), t.mode === "drag" && T(!1, n, t.target, 0));
|
|
165
|
+
d.release(t.target), o = null;
|
|
163
166
|
} else {
|
|
164
|
-
f?.command.kind === "move" && (f.command = { ...
|
|
165
|
-
const n =
|
|
166
|
-
for (const i of [...
|
|
167
|
-
p = e.button === 0 && n && "clicks" in n && n.clicks === 1 &&
|
|
167
|
+
f?.command.kind === "move" && (f.command = { ...h(e), kind: "move" }), v();
|
|
168
|
+
const n = g.get(e.button)?.command;
|
|
169
|
+
for (const i of [...g.keys()]) T(!1, h(e), t.target, i, n && "clicks" in n ? n.clicks : 1);
|
|
170
|
+
p = e.button === 0 && n && "clicks" in n && n.clicks === 1 && x(t.origin, h(e)) <= 8 ? { target: t.target, position: h(e), time: c.performance.now() } : null, g.size || (o = null);
|
|
168
171
|
}
|
|
169
172
|
(!o || o.id !== e.pointerId) && S(e.pointerId);
|
|
170
|
-
}),
|
|
173
|
+
}), a(l, "pointercancel", (e) => {
|
|
171
174
|
r(), S(e.pointerId);
|
|
172
|
-
}),
|
|
173
|
-
|
|
174
|
-
}),
|
|
175
|
+
}), a(l, "lostpointercapture", (e) => {
|
|
176
|
+
E.has(e.pointerId) && (r(), S(e.pointerId));
|
|
177
|
+
}), a(I, "pointerup", (e) => {
|
|
175
178
|
o?.id !== e.pointerId && S(e.pointerId);
|
|
176
|
-
}),
|
|
177
|
-
o && (e.pointerType === "touch" && e.pointerId !== o.id ? (
|
|
178
|
-
}, !0),
|
|
179
|
-
const t =
|
|
180
|
-
if (t === null || !
|
|
181
|
-
p = null, u !== null && u !== t && (
|
|
182
|
-
const n = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? l.clientWidth ||
|
|
183
|
-
Number.isFinite(
|
|
179
|
+
}), a(I, "pointercancel", (e) => S(e.pointerId)), a(I, "pointerdown", (e) => {
|
|
180
|
+
o && (e.pointerType === "touch" && e.pointerId !== o.id ? (m.add(e.pointerId), r()) : l.contains(e.target) || r());
|
|
181
|
+
}, !0), a(l, "wheel", (e) => {
|
|
182
|
+
const t = d.resolveTarget(e);
|
|
183
|
+
if (t === null || !k(t) || (e.preventDefault(), o || m.size)) return;
|
|
184
|
+
p = null, u !== null && u !== t && (v(), d.release(u)), u = t;
|
|
185
|
+
const n = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? l.clientWidth || c.innerWidth : 1, i = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? l.clientHeight || c.innerHeight : 1, s = e.deltaX * n, w = e.deltaY * i;
|
|
186
|
+
Number.isFinite(s) && Number.isFinite(w) && (s || w) && C({ ...h(e), kind: "scroll", dx: s, dy: w }, t);
|
|
184
187
|
});
|
|
185
188
|
for (const e of ["mousedown", "mouseup", "click", "dblclick", "contextmenu", "dragstart", "selectstart"])
|
|
186
|
-
|
|
187
|
-
|
|
189
|
+
a(l, e, (t) => {
|
|
190
|
+
d.resolveTarget(t) !== null && t.preventDefault();
|
|
188
191
|
});
|
|
189
|
-
for (const e of ["blur", "pagehide", "resize", "orientationchange"])
|
|
190
|
-
if (
|
|
192
|
+
for (const e of ["blur", "pagehide", "resize", "orientationchange"]) a(c, e, r);
|
|
193
|
+
if (a(I, "visibilitychange", () => {
|
|
191
194
|
I.hidden && r();
|
|
192
|
-
}),
|
|
195
|
+
}), a(c, "scroll", r, !0), c.visualViewport && (a(c.visualViewport, "resize", r), a(c.visualViewport, "scroll", r)), typeof ResizeObserver < "u") {
|
|
193
196
|
let e = `${l.clientWidth}:${l.clientHeight}`;
|
|
194
197
|
const t = new ResizeObserver(() => {
|
|
195
198
|
const n = `${l.clientWidth}:${l.clientHeight}`;
|
|
196
199
|
n !== e && (e = n, r());
|
|
197
200
|
});
|
|
198
|
-
t.observe(l),
|
|
201
|
+
t.observe(l), P.push(() => t.disconnect());
|
|
199
202
|
}
|
|
200
|
-
return { flush:
|
|
201
|
-
if (!
|
|
202
|
-
r(),
|
|
203
|
-
for (const e of
|
|
204
|
-
|
|
203
|
+
return { flush: v, reset: r, dispose() {
|
|
204
|
+
if (!K) {
|
|
205
|
+
r(), K = !0;
|
|
206
|
+
for (const e of P) e();
|
|
207
|
+
m.clear();
|
|
205
208
|
}
|
|
206
209
|
} };
|
|
207
210
|
}
|
|
208
211
|
export {
|
|
209
|
-
|
|
212
|
+
R as createRemotePointer
|
|
210
213
|
};
|