@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.
Files changed (2) hide show
  1. package/dist/remote-pointer.js +122 -119
  2. package/package.json +1 -1
@@ -1,8 +1,8 @@
1
- function F(a) {
2
- const { surface: l } = a, I = l.ownerDocument, s = I.defaultView;
3
- if (!s) throw new Error("Remote pointer requires an attached document");
4
- let o = null, f = null, u = null, p = null, k = 0, z = !1, L = 0, M = 0, C = !1, H = !1, D = 0, b = !1;
5
- const g = /* @__PURE__ */ new Set(), O = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Map(), K = [], w = (e) => !H && a.isTargetValid(e), E = (e, t) => Math.hypot(e.clientX - t.clientX, e.clientY - t.clientY), v = (e) => ({
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 d(e, t, n, i = !1) {
15
- const c = n;
16
- e.addEventListener(t, c, { capture: i, passive: !1 }), K.push(() => e.removeEventListener(t, c, i));
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 Y(e, t) {
19
- const n = w(t) && a.sendPointer(e, t) !== !1;
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 h.values()) i.target === t && (i.command = { ...i.command, ...v(e) });
21
+ for (const i of g.values()) i.target === t && (i.command = { ...i.command, ...h(e) });
22
22
  return n;
23
23
  }
24
- function P() {
25
- s.clearTimeout(M), M = 0, C && (C = !1, a.onHoldChange?.(null));
24
+ function X() {
25
+ c.clearTimeout(O), O = 0, H && (H = !1, d.onHoldChange?.(null));
26
26
  }
27
- function _(e) {
28
- O.delete(e), l.hasPointerCapture?.(e) && l.releasePointerCapture(e);
27
+ function A(e) {
28
+ E.delete(e), l.hasPointerCapture?.(e) && l.releasePointerCapture(e);
29
29
  }
30
- function q(e) {
31
- l.setPointerCapture?.(e), O.add(e);
30
+ function N(e) {
31
+ l.setPointerCapture?.(e), E.add(e);
32
32
  }
33
- function y() {
34
- L++, z = !1, k && s.cancelAnimationFrame(k), k = 0;
33
+ function v() {
34
+ L++, z = !1, y && c.cancelAnimationFrame(y), y = 0;
35
35
  const e = f;
36
- f = null, e && !Y(e.command, e.target) && r();
36
+ f = null, e && !_(e.command, e.target) && r();
37
37
  }
38
- function x(e, t) {
39
- if (f && (f.target !== t || f.command.kind !== e.kind) && y(), !!w(t)) {
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
- s.queueMicrotask(() => {
45
- n === L && y();
44
+ c.queueMicrotask(() => {
45
+ n === L && v();
46
46
  });
47
47
  }
48
48
  return;
49
49
  }
50
- if (!k) {
51
- const n = D, i = s.requestAnimationFrame(() => {
52
- n === D && k === i && y();
50
+ if (!y) {
51
+ const n = b, i = c.requestAnimationFrame(() => {
52
+ n === b && y === i && v();
53
53
  });
54
- k = i;
54
+ y = i;
55
55
  }
56
56
  }
57
57
  }
58
- function T(e, t, n, i, c = 1) {
59
- const m = h.get(i);
60
- if (!e && !m) return;
61
- e || h.delete(i);
62
- const U = { ...t, kind: e ? "down" : "up", button: i, clicks: c };
63
- Y(U, n) && e && h.set(i, { target: n, command: U });
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 X(e, t) {
66
- const n = D;
67
- return a.onActivate?.(e, t), n === D && w(t);
65
+ function Y(e, t) {
66
+ const n = b;
67
+ return d.onActivate?.(e, t), n === b && k(t);
68
68
  }
69
- function A(e, t, n, i = 1) {
70
- X(e, t) && (T(!0, e, t, n, i), T(!1, e, t, n, i));
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
- D++, L++, z = !1, P(), k && s.cancelAnimationFrame(k), k = 0;
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, b = g.size > 0;
76
- for (const [t, n] of h)
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) a.release(t);
79
- for (const t of [...O]) _(t);
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
- g.delete(e), _(e), g.size || (b = !1);
82
+ m.delete(e), A(e), m.size || (D = !1);
83
83
  }
84
- function B(e) {
84
+ function U(e) {
85
85
  const t = o;
86
86
  if (!t || t.id !== e.pointerId) return;
87
- if (!w(t.target)) {
87
+ if (!k(t.target)) {
88
88
  r();
89
89
  return;
90
90
  }
91
- const n = v(e);
92
- if ((t.mode === "pending" || t.mode === "hold") && E(t.origin, n) > 8) {
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 (P(), p = null, t.mode = i ? "drag" : "scroll", i && X(t.origin, t.target) && T(!0, t.origin, t.target, 0), o !== t) return;
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, c = i.clientX - n.clientX, m = i.clientY - n.clientY;
98
- (c || m) && x({ ...t.origin, kind: "scroll", dx: c, dy: m }, t.target), t.last = n;
99
- } else t.mode === "drag" && (x({ ...n, kind: "move" }, t.target), t.last = n);
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
- d(l, "pointerdown", (e) => {
102
- const t = a.resolveTarget(e);
103
- if (t === null || !w(t)) return;
104
- const n = v(e);
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 (g.add(e.pointerId), g.size > 1 || b) {
106
+ if (m.add(e.pointerId), m.size > 1 || D) {
107
107
  r();
108
108
  return;
109
109
  }
110
- (o || h.size) && r(), y(), u !== null && (a.release(u), u = null), b = !1, o = { id: e.pointerId, target: t, origin: n, last: n, mode: "pending" };
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
- M = s.setTimeout(() => {
113
- if (M = 0, o === i) {
114
- if (!w(t)) {
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", C = !0, a.onHoldChange?.({ ...n, target: t });
118
+ i.mode = "hold", H = !0, d.onHoldChange?.({ ...n, target: t });
119
119
  }
120
120
  }, 450);
121
121
  } else {
122
- if (g.size) {
122
+ if (m.size) {
123
123
  r();
124
124
  return;
125
125
  }
126
- o && (o.id !== e.pointerId || o.target !== t) && r(), y(), u !== null && (a.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 && s.performance.now() - p.time <= 350 && E(p.position, n) <= 16;
128
- X(n, t) && T(!0, n, t, e.button, Math.max(1, e.detail, i ? 2 : 1));
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
- q(e.pointerId), e.pointerType === "touch" && e.preventDefault();
131
- }), d(l, "pointermove", (e) => {
132
- if (e.pointerType === "touch") {
133
- B(e);
134
- return;
135
- }
136
- if (b || g.size) return;
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 n = v(e);
140
+ const i = h(e);
143
141
  if (o) {
144
- o.last = n;
145
- for (const [i, c] of [[0, 1], [1, 4], [2, 2], [3, 8], [4, 16]]) {
146
- const m = !!(e.buttons & c);
147
- m !== h.has(i) && (y(), T(m, n, t, i));
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
- x({ ...n, kind: "move" }, t);
151
- }), d(l, "pointerup", (e) => {
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 && !b)
154
- if (!w(t.target)) r();
156
+ if (t?.id === e.pointerId && !D)
157
+ if (!k(t.target)) r();
155
158
  else if (e.pointerType === "touch") {
156
- B(e), P();
157
- const n = v(e);
159
+ U(e), X();
160
+ const n = h(e);
158
161
  if (t.mode === "pending") {
159
- const i = s.performance.now(), c = p?.target === t.target && i - p.time <= 350 && E(p.position, n) <= 16;
160
- A(n, t.target, 0, c ? 2 : 1), p = c ? null : { target: t.target, position: n, time: i };
161
- } else t.mode === "hold" ? (p = null, A(n, t.target, 2)) : (y(), t.mode === "drag" && T(!1, n, t.target, 0));
162
- a.release(t.target), o = null;
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 = { ...v(e), kind: "move" }), y();
165
- const n = h.get(e.button)?.command;
166
- for (const i of [...h.keys()]) T(!1, v(e), t.target, i, n && "clicks" in n ? n.clicks : 1);
167
- p = e.button === 0 && n && "clicks" in n && n.clicks === 1 && E(t.origin, v(e)) <= 8 ? { target: t.target, position: v(e), time: s.performance.now() } : null, h.size || (o = null);
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
- }), d(l, "pointercancel", (e) => {
173
+ }), a(l, "pointercancel", (e) => {
171
174
  r(), S(e.pointerId);
172
- }), d(l, "lostpointercapture", (e) => {
173
- O.has(e.pointerId) && (r(), S(e.pointerId));
174
- }), d(I, "pointerup", (e) => {
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
- }), d(I, "pointercancel", (e) => S(e.pointerId)), d(I, "pointerdown", (e) => {
177
- o && (e.pointerType === "touch" && e.pointerId !== o.id ? (g.add(e.pointerId), r()) : l.contains(e.target) || r());
178
- }, !0), d(l, "wheel", (e) => {
179
- const t = a.resolveTarget(e);
180
- if (t === null || !w(t) || (e.preventDefault(), o || g.size)) return;
181
- p = null, u !== null && u !== t && (y(), a.release(u)), u = t;
182
- const n = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? l.clientWidth || s.innerWidth : 1, i = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? l.clientHeight || s.innerHeight : 1, c = e.deltaX * n, m = e.deltaY * i;
183
- Number.isFinite(c) && Number.isFinite(m) && (c || m) && x({ ...v(e), kind: "scroll", dx: c, dy: m }, t);
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
- d(l, e, (t) => {
187
- a.resolveTarget(t) !== null && t.preventDefault();
189
+ a(l, e, (t) => {
190
+ d.resolveTarget(t) !== null && t.preventDefault();
188
191
  });
189
- for (const e of ["blur", "pagehide", "resize", "orientationchange"]) d(s, e, r);
190
- if (d(I, "visibilitychange", () => {
192
+ for (const e of ["blur", "pagehide", "resize", "orientationchange"]) a(c, e, r);
193
+ if (a(I, "visibilitychange", () => {
191
194
  I.hidden && r();
192
- }), d(s, "scroll", r, !0), s.visualViewport && (d(s.visualViewport, "resize", r), d(s.visualViewport, "scroll", r)), typeof ResizeObserver < "u") {
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), K.push(() => t.disconnect());
201
+ t.observe(l), P.push(() => t.disconnect());
199
202
  }
200
- return { flush: y, reset: r, dispose() {
201
- if (!H) {
202
- r(), H = !0;
203
- for (const e of K) e();
204
- g.clear();
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
- F as createRemotePointer
212
+ R as createRemotePointer
210
213
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.81.5",
3
+ "version": "0.81.6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",