@floegence/floe-webapp-core 0.86.13 → 0.86.15
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/components/graph/routing.js +148 -144
- package/dist/remote-input.js +99 -91
- package/package.json +1 -1
|
@@ -1,48 +1,51 @@
|
|
|
1
|
-
import { AvoidLib as
|
|
2
|
-
import
|
|
3
|
-
let
|
|
4
|
-
const
|
|
5
|
-
async function
|
|
1
|
+
import { AvoidLib as X } from "../../node_modules/.pnpm/libavoid-js@0.5.0-beta.5/node_modules/libavoid-js/dist/index.js";
|
|
2
|
+
import I from "../../node_modules/.pnpm/libavoid-js@0.5.0-beta.5/node_modules/libavoid-js/dist/libavoid.wasm.js";
|
|
3
|
+
let Y;
|
|
4
|
+
const _ = { NORTH: 1, SOUTH: 2, WEST: 4, EAST: 8 }, v = ["NORTH", "EAST", "SOUTH", "WEST"], T = (i) => i.delete();
|
|
5
|
+
async function st(i, o = {}) {
|
|
6
6
|
const a = o.edgeClearance ?? 4;
|
|
7
7
|
if (!Number.isFinite(a) || a < 0)
|
|
8
8
|
throw new Error("Graph edge clearance must be finite and nonnegative");
|
|
9
|
-
if (!
|
|
10
|
-
if (!
|
|
11
|
-
await (
|
|
12
|
-
throw
|
|
9
|
+
if (!i.nodes.length) return i;
|
|
10
|
+
if (!i.edges.length) return L(i);
|
|
11
|
+
await (Y ??= X.load(I).catch((r) => {
|
|
12
|
+
throw Y = void 0, r;
|
|
13
13
|
}));
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
for (let s =
|
|
17
|
-
|
|
18
|
-
return
|
|
14
|
+
const n = X.getInstance(), c = new Map(i.nodes.map((r) => [r.id, r])), l = (r) => {
|
|
15
|
+
const h = [];
|
|
16
|
+
for (let s = c.get(r).parentId; s; s = c.get(s).parentId)
|
|
17
|
+
h.push(s);
|
|
18
|
+
return h;
|
|
19
19
|
}, f = /* @__PURE__ */ new Map();
|
|
20
|
-
for (const r of
|
|
21
|
-
const
|
|
20
|
+
for (const r of i.edges) {
|
|
21
|
+
const h = /* @__PURE__ */ new Set([...l(r.source), ...l(r.target)]), s = JSON.stringify([...h].sort()), M = f.get(s) ?? { open: h, edges: [] };
|
|
22
22
|
M.edges.push(r), f.set(s, M);
|
|
23
23
|
}
|
|
24
|
-
const
|
|
25
|
-
for (const { open: r, edges:
|
|
26
|
-
const s = new
|
|
24
|
+
const P = /* @__PURE__ */ new Map();
|
|
25
|
+
for (const { open: r, edges: h } of f.values()) {
|
|
26
|
+
const s = new n.Router(2);
|
|
27
27
|
try {
|
|
28
|
-
s.setRoutingParameter(
|
|
28
|
+
s.setRoutingParameter(n.RoutingParameter.shapeBufferDistance, a), s.setRoutingParameter(n.RoutingParameter.idealNudgingDistance, 8), s.setRoutingParameter(n.RoutingParameter.crossingPenalty, 80), s.setRoutingParameter(n.RoutingParameter.fixedSharedPathPenalty, 120), s.setRoutingParameter(n.RoutingParameter.portDirectionPenalty, 0), s.setRoutingOption(
|
|
29
|
+
n.RoutingOption.nudgeOrthogonalSegmentsConnectedToShapes,
|
|
30
|
+
!h.some((t) => t.sourcePort || t.targetPort || t.source === t.target)
|
|
31
|
+
), s.setRoutingOption(n.RoutingOption.nudgeSharedPathsWithCommonEndPoint, !0);
|
|
29
32
|
const M = new Map(
|
|
30
|
-
|
|
31
|
-
const e = new
|
|
32
|
-
return
|
|
33
|
+
i.nodes.filter((t) => !r.has(t.id) && l(t.id).every((e) => r.has(e))).map((t) => {
|
|
34
|
+
const e = new n.Point(t.x, t.y), g = new n.Point(t.x + t.width, t.y + t.height), p = new n.Rectangle(e, g), x = new n.ShapeRef(s, p);
|
|
35
|
+
return T(e), T(g), T(p), [t.id, x];
|
|
33
36
|
})
|
|
34
|
-
), O = /* @__PURE__ */ new Map(),
|
|
35
|
-
for (const t of
|
|
37
|
+
), O = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map();
|
|
38
|
+
for (const t of h) {
|
|
36
39
|
const e = [t.source, t.target].sort().join("\0"), g = O.get(e) ?? 0;
|
|
37
|
-
O.set(e, g + 1),
|
|
40
|
+
O.set(e, g + 1), C.set(t.id, g % 2 === 0 ? -6 : 6);
|
|
38
41
|
}
|
|
39
|
-
let
|
|
40
|
-
const
|
|
41
|
-
for (const t of
|
|
42
|
+
let K = v.length + 2;
|
|
43
|
+
const W = /* @__PURE__ */ new Map(), b = (t, e) => Math.max(0, Math.min(1, t / e));
|
|
44
|
+
for (const t of i.nodes) {
|
|
42
45
|
const e = M.get(t.id);
|
|
43
46
|
if (!e) continue;
|
|
44
|
-
const g = (p, x, w, y,
|
|
45
|
-
const N = new
|
|
47
|
+
const g = (p, x, w, y, u) => {
|
|
48
|
+
const N = new n.ShapeConnectionPin(
|
|
46
49
|
e,
|
|
47
50
|
p,
|
|
48
51
|
b(x, t.width),
|
|
@@ -51,13 +54,13 @@ async function et(n, o = {}) {
|
|
|
51
54
|
0,
|
|
52
55
|
y
|
|
53
56
|
);
|
|
54
|
-
N.setExclusive(
|
|
57
|
+
N.setExclusive(u), N.setConnectionCost(
|
|
55
58
|
t.width / 2 + t.height / 2 - Math.abs(x - t.width / 2) - Math.abs(w - t.height / 2)
|
|
56
59
|
);
|
|
57
60
|
};
|
|
58
61
|
for (const p of new Set(t.ports?.map((x) => x.side))) {
|
|
59
|
-
const { x, y: w } =
|
|
60
|
-
g(y, x - t.x, w - t.y,
|
|
62
|
+
const { x, y: w } = $(t, p), y = v.indexOf(p) + 2;
|
|
63
|
+
g(y, x - t.x, w - t.y, _[p], !1), W.set(
|
|
61
64
|
JSON.stringify([
|
|
62
65
|
t.id,
|
|
63
66
|
b(x - t.x, t.width),
|
|
@@ -68,209 +71,210 @@ async function et(n, o = {}) {
|
|
|
68
71
|
);
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
|
-
const
|
|
74
|
+
const Q = i.nodes.filter((t) => M.has(t.id)), F = (t, e, g, p, x, w = !1) => {
|
|
72
75
|
const y = M.get(t.id);
|
|
73
76
|
if (y && g)
|
|
74
|
-
return new
|
|
77
|
+
return new n.ConnEnd(
|
|
75
78
|
y,
|
|
76
|
-
|
|
79
|
+
v.indexOf(t.ports.find((d) => d.id === g).side) + 2
|
|
77
80
|
);
|
|
78
|
-
const
|
|
81
|
+
const u = g ? [
|
|
79
82
|
{
|
|
80
83
|
side: t.ports.find((d) => d.id === g).side,
|
|
81
|
-
position:
|
|
84
|
+
position: $(t, t.ports.find((d) => d.id === g).side)
|
|
82
85
|
}
|
|
83
|
-
] : x ? [{ side: "EAST", position: x }] : (w ? [
|
|
84
|
-
const
|
|
85
|
-
if (w) return [{ side: d, position:
|
|
86
|
-
const R = d === "NORTH" || d === "SOUTH",
|
|
86
|
+
] : x ? [{ side: "EAST", position: x }] : (w ? [q(t, e).source] : v).flatMap((d) => {
|
|
87
|
+
const H = tt(t, d, e, p);
|
|
88
|
+
if (w) return [{ side: d, position: H }];
|
|
89
|
+
const R = d === "NORTH" || d === "SOUTH", A = R ? t.x : t.y, S = R ? t.width : t.height, E = A + Math.min(8, S / 4), B = A + S - Math.min(8, S / 4);
|
|
87
90
|
return [
|
|
88
|
-
R ?
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
...
|
|
92
|
-
const k = R ?
|
|
93
|
-
return [k - a,
|
|
94
|
-
}).filter((
|
|
95
|
-
].map((
|
|
91
|
+
R ? H.x : H.y,
|
|
92
|
+
E,
|
|
93
|
+
B,
|
|
94
|
+
...Q.flatMap((m) => {
|
|
95
|
+
const k = R ? m.x : m.y, V = k + (R ? m.width : m.height);
|
|
96
|
+
return [k - a, V + a, k - a - 8, V + a + 8];
|
|
97
|
+
}).filter((m) => m >= E && m <= B)
|
|
98
|
+
].map((m) => ({
|
|
96
99
|
side: d,
|
|
97
|
-
position: R ? { x:
|
|
100
|
+
position: R ? { x: m, y: H.y } : { x: H.x, y: m }
|
|
98
101
|
}));
|
|
99
102
|
});
|
|
100
103
|
if (y) {
|
|
101
|
-
const d = (
|
|
104
|
+
const d = (S, E) => JSON.stringify([
|
|
102
105
|
t.id,
|
|
103
|
-
b(
|
|
104
|
-
b(
|
|
105
|
-
|
|
106
|
-
]),
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
106
|
+
b(E.x - t.x, t.width),
|
|
107
|
+
b(E.y - t.y, t.height),
|
|
108
|
+
S
|
|
109
|
+
]), R = !!(g || x || w) || u.every(
|
|
110
|
+
(S) => W.has(d(S.side, S.position))
|
|
111
|
+
) ? W.get(d(u[0].side, u[0].position)) : void 0;
|
|
112
|
+
if (R !== void 0) return new n.ConnEnd(y, R);
|
|
113
|
+
const A = R ?? K++;
|
|
114
|
+
for (const { side: S, position: E } of u) {
|
|
115
|
+
const B = d(S, E);
|
|
116
|
+
if (W.has(B)) continue;
|
|
117
|
+
W.set(B, A);
|
|
118
|
+
const D = E.x - t.x, m = E.y - t.y, k = new n.ShapeConnectionPin(
|
|
115
119
|
y,
|
|
116
|
-
|
|
120
|
+
A,
|
|
117
121
|
b(D, t.width),
|
|
118
|
-
b(
|
|
122
|
+
b(m, t.height),
|
|
119
123
|
!0,
|
|
120
124
|
0,
|
|
121
|
-
|
|
125
|
+
_[S]
|
|
122
126
|
);
|
|
123
127
|
k.setExclusive(!1), k.setConnectionCost(
|
|
124
|
-
t.width / 2 + t.height / 2 - Math.abs(D - t.width / 2) - Math.abs(
|
|
128
|
+
t.width / 2 + t.height / 2 - Math.abs(D - t.width / 2) - Math.abs(m - t.height / 2)
|
|
125
129
|
);
|
|
126
130
|
}
|
|
127
|
-
return new
|
|
131
|
+
return new n.ConnEnd(y, A);
|
|
128
132
|
}
|
|
129
|
-
const N =
|
|
130
|
-
return
|
|
131
|
-
},
|
|
132
|
-
const e =
|
|
133
|
+
const N = q(t, e).source, G = u.find((d) => d.side === N)?.position ?? u[0].position, j = new n.Point(G.x, G.y), z = new n.ConnEnd(j);
|
|
134
|
+
return T(j), z;
|
|
135
|
+
}, J = (t) => +!!(t.sourcePort || t.targetPort || t.source === t.target || O.get([t.source, t.target].sort().join("\0")) > 1), Z = [...h].sort((t, e) => J(e) - J(t)).map((t) => {
|
|
136
|
+
const e = c.get(t.source), g = c.get(t.target), p = t.source === t.target, x = O.get([t.source, t.target].sort().join("\0")) > 1, w = F(
|
|
133
137
|
e,
|
|
134
138
|
g,
|
|
135
139
|
t.sourcePort,
|
|
136
|
-
|
|
140
|
+
C.get(t.id),
|
|
137
141
|
p ? { x: e.x + e.width, y: e.y + e.height / 3 } : void 0,
|
|
138
142
|
x
|
|
139
|
-
), y =
|
|
143
|
+
), y = F(
|
|
140
144
|
g,
|
|
141
145
|
e,
|
|
142
146
|
t.targetPort,
|
|
143
|
-
|
|
147
|
+
C.get(t.id),
|
|
144
148
|
p ? {
|
|
145
149
|
x: g.x + g.width,
|
|
146
150
|
y: g.y + g.height * 2 / 3
|
|
147
151
|
} : void 0,
|
|
148
152
|
x
|
|
149
|
-
),
|
|
150
|
-
if (
|
|
151
|
-
const N = new
|
|
153
|
+
), u = new n.ConnRef(s, w, y);
|
|
154
|
+
if (T(w), T(y), p) {
|
|
155
|
+
const N = new n.CheckpointVector();
|
|
152
156
|
for (const G of [
|
|
153
157
|
e.y + e.height / 3,
|
|
154
158
|
e.y + e.height * 2 / 3
|
|
155
159
|
]) {
|
|
156
|
-
const
|
|
160
|
+
const j = new n.Point(
|
|
157
161
|
e.x + e.width + Math.max(24, a + 4),
|
|
158
162
|
G
|
|
159
|
-
), z = new
|
|
160
|
-
N.push_back(z),
|
|
163
|
+
), z = new n.Checkpoint(j);
|
|
164
|
+
N.push_back(z), T(j), T(z);
|
|
161
165
|
}
|
|
162
|
-
|
|
166
|
+
u.setRoutingCheckpoints(N), T(N);
|
|
163
167
|
}
|
|
164
|
-
return { edge: t, connection:
|
|
168
|
+
return { edge: t, connection: u };
|
|
165
169
|
});
|
|
166
170
|
s.processTransaction();
|
|
167
|
-
for (const { edge: t, connection: e } of
|
|
171
|
+
for (const { edge: t, connection: e } of Z) {
|
|
168
172
|
const g = e.displayRoute(), p = Array.from({ length: g.size() }, (x, w) => {
|
|
169
|
-
const y = g.at(w),
|
|
170
|
-
return
|
|
173
|
+
const y = g.at(w), u = { x: y.x, y: y.y };
|
|
174
|
+
return T(y), u;
|
|
171
175
|
});
|
|
172
|
-
if (
|
|
176
|
+
if (T(g), !e.hasValidRoute() || p.length < 2 || p.some((x) => !Number.isFinite(x.x) || !Number.isFinite(x.y)) || p.some((x, w) => w > 0 && x.x !== p[w - 1].x && x.y !== p[w - 1].y))
|
|
173
177
|
throw new Error(`Graph edge cannot be routed: ${t.id}`);
|
|
174
|
-
|
|
178
|
+
P.set(t.id, p);
|
|
175
179
|
}
|
|
176
180
|
} finally {
|
|
177
181
|
s.delete();
|
|
178
182
|
}
|
|
179
183
|
}
|
|
180
|
-
const U =
|
|
181
|
-
return
|
|
182
|
-
nodes:
|
|
184
|
+
const U = i.edges.map((r) => ({ ...r, sections: [P.get(r.id)] }));
|
|
185
|
+
return L({
|
|
186
|
+
nodes: i.nodes,
|
|
183
187
|
edges: U,
|
|
184
|
-
bounds:
|
|
188
|
+
bounds: i.bounds
|
|
185
189
|
});
|
|
186
190
|
}
|
|
187
|
-
function
|
|
191
|
+
function L(i) {
|
|
188
192
|
const o = [
|
|
189
|
-
...
|
|
190
|
-
{ x:
|
|
191
|
-
{ x:
|
|
193
|
+
...i.nodes.flatMap((c) => [
|
|
194
|
+
{ x: c.x, y: c.y },
|
|
195
|
+
{ x: c.x + c.width, y: c.y + c.height }
|
|
192
196
|
]),
|
|
193
|
-
...
|
|
194
|
-
], a = Math.min(...o.map((
|
|
197
|
+
...i.edges.flatMap((c) => c.sections.flat())
|
|
198
|
+
], a = Math.min(...o.map((c) => c.x)), n = Math.min(...o.map((c) => c.y));
|
|
195
199
|
return {
|
|
196
|
-
nodes:
|
|
197
|
-
edges:
|
|
200
|
+
nodes: i.nodes,
|
|
201
|
+
edges: i.edges,
|
|
198
202
|
bounds: {
|
|
199
203
|
x: a,
|
|
200
|
-
y:
|
|
201
|
-
width: Math.max(...o.map((
|
|
202
|
-
height: Math.max(...o.map((
|
|
204
|
+
y: n,
|
|
205
|
+
width: Math.max(...o.map((c) => c.x)) - a,
|
|
206
|
+
height: Math.max(...o.map((c) => c.y)) - n
|
|
203
207
|
}
|
|
204
208
|
};
|
|
205
209
|
}
|
|
206
|
-
function
|
|
210
|
+
function $(i, o) {
|
|
207
211
|
return {
|
|
208
|
-
x: o === "WEST" ?
|
|
209
|
-
y: o === "NORTH" ?
|
|
212
|
+
x: o === "WEST" ? i.x : o === "EAST" ? i.x + i.width : i.x + i.width / 2,
|
|
213
|
+
y: o === "NORTH" ? i.y : o === "SOUTH" ? i.y + i.height : i.y + i.height / 2
|
|
210
214
|
};
|
|
211
215
|
}
|
|
212
|
-
function
|
|
213
|
-
const a = (
|
|
214
|
-
if (
|
|
215
|
-
const
|
|
216
|
-
NORTH:
|
|
217
|
-
EAST:
|
|
218
|
-
SOUTH:
|
|
219
|
-
WEST:
|
|
220
|
-
}, M = [...
|
|
216
|
+
function q(i, o) {
|
|
217
|
+
const a = (h, s) => s.x >= h.x && s.y >= h.y && s.x + s.width <= h.x + h.width && s.y + s.height <= h.y + h.height, n = a(i, o) ? i : a(o, i) ? o : void 0;
|
|
218
|
+
if (n) {
|
|
219
|
+
const h = n === i ? o : i, s = {
|
|
220
|
+
NORTH: h.y - n.y,
|
|
221
|
+
EAST: n.x + n.width - h.x - h.width,
|
|
222
|
+
SOUTH: n.y + n.height - h.y - h.height,
|
|
223
|
+
WEST: h.x - n.x
|
|
224
|
+
}, M = [...v].sort((O, C) => s[O] - s[C])[0];
|
|
221
225
|
return { source: M, target: M };
|
|
222
226
|
}
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
o.y - (
|
|
227
|
+
const c = o.x + o.width / 2 - (i.x + i.width / 2), l = o.y + o.height / 2 - (i.y + i.height / 2), f = Math.max(i.x - (o.x + o.width), o.x - (i.x + i.width), 0), P = Math.max(
|
|
228
|
+
i.y - (o.y + o.height),
|
|
229
|
+
o.y - (i.y + i.height),
|
|
226
230
|
0
|
|
227
|
-
), r = (
|
|
228
|
-
return { source: r, target:
|
|
231
|
+
), r = (P === 0 && f > 0 ? !0 : f === 0 && P > 0 ? !1 : f === 0 && P === 0 ? Math.abs(c) >= Math.abs(l) : f <= P) ? c >= 0 ? "EAST" : "WEST" : l >= 0 ? "SOUTH" : "NORTH";
|
|
232
|
+
return { source: r, target: v[(v.indexOf(r) + 2) % 4] };
|
|
229
233
|
}
|
|
230
|
-
function
|
|
231
|
-
const
|
|
232
|
-
const O = Math.max(r, s),
|
|
233
|
-
return O <
|
|
234
|
-
},
|
|
234
|
+
function tt(i, o, a, n = 0) {
|
|
235
|
+
const c = (r) => Math.min(8, r / 4), l = (r, h, s) => Math.max(h + c(s), Math.min(h + s - c(s), r)), f = (r, h, s, M) => {
|
|
236
|
+
const O = Math.max(r, s), C = Math.min(r + h, s + M);
|
|
237
|
+
return O < C ? (O + C) / 2 + n : void 0;
|
|
238
|
+
}, P = a.x + a.width / 2, U = a.y + a.height / 2;
|
|
235
239
|
switch (o) {
|
|
236
240
|
case "NORTH":
|
|
237
241
|
return {
|
|
238
242
|
x: l(
|
|
239
|
-
f(
|
|
240
|
-
|
|
241
|
-
|
|
243
|
+
f(i.x, i.width, a.x, a.width) ?? P + n,
|
|
244
|
+
i.x,
|
|
245
|
+
i.width
|
|
242
246
|
),
|
|
243
|
-
y:
|
|
247
|
+
y: i.y
|
|
244
248
|
};
|
|
245
249
|
case "EAST":
|
|
246
250
|
return {
|
|
247
|
-
x:
|
|
251
|
+
x: i.x + i.width,
|
|
248
252
|
y: l(
|
|
249
|
-
f(
|
|
250
|
-
|
|
251
|
-
|
|
253
|
+
f(i.y, i.height, a.y, a.height) ?? U + n,
|
|
254
|
+
i.y,
|
|
255
|
+
i.height
|
|
252
256
|
)
|
|
253
257
|
};
|
|
254
258
|
case "SOUTH":
|
|
255
259
|
return {
|
|
256
260
|
x: l(
|
|
257
|
-
f(
|
|
258
|
-
|
|
259
|
-
|
|
261
|
+
f(i.x, i.width, a.x, a.width) ?? P + n,
|
|
262
|
+
i.x,
|
|
263
|
+
i.width
|
|
260
264
|
),
|
|
261
|
-
y:
|
|
265
|
+
y: i.y + i.height
|
|
262
266
|
};
|
|
263
267
|
case "WEST":
|
|
264
268
|
return {
|
|
265
|
-
x:
|
|
269
|
+
x: i.x,
|
|
266
270
|
y: l(
|
|
267
|
-
f(
|
|
268
|
-
|
|
269
|
-
|
|
271
|
+
f(i.y, i.height, a.y, a.height) ?? U + n,
|
|
272
|
+
i.y,
|
|
273
|
+
i.height
|
|
270
274
|
)
|
|
271
275
|
};
|
|
272
276
|
}
|
|
273
277
|
}
|
|
274
278
|
export {
|
|
275
|
-
|
|
279
|
+
st as routeGraphGeometry
|
|
276
280
|
};
|
package/dist/remote-input.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
function
|
|
2
|
-
const { surface:
|
|
3
|
-
if (!
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
let l = null,
|
|
7
|
-
const
|
|
8
|
-
let
|
|
9
|
-
const
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
e.addEventListener(
|
|
1
|
+
function j(n) {
|
|
2
|
+
const { surface: A } = n, x = A.ownerDocument, c = x.defaultView;
|
|
3
|
+
if (!c) throw new Error("Remote input requires an attached document");
|
|
4
|
+
const i = x.createElement("textarea");
|
|
5
|
+
i.className = "floe-remote-input", i.setAttribute("aria-label", n.label), i.setAttribute("autocorrect", "off"), i.autocomplete = "off", i.autocapitalize = "off", i.spellcheck = !1, i.wrap = "off", i.disabled = !0, i.tabIndex = -1, x.body.append(i);
|
|
6
|
+
let l = null, K = 0, f = !1, R = !1, o = null, h = !1, a = null, w = "physical";
|
|
7
|
+
const k = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set(), C = /* @__PURE__ */ new Set(), L = /* @__PURE__ */ new Set();
|
|
8
|
+
let $ = null;
|
|
9
|
+
const V = [];
|
|
10
|
+
function s(e, t, r) {
|
|
11
|
+
const d = r;
|
|
12
|
+
e.addEventListener(t, d), V.push(() => e.removeEventListener(t, d));
|
|
13
13
|
}
|
|
14
|
-
const b = (e) => e.code || e.key,
|
|
14
|
+
const b = (e) => e.code || e.key, M = (e, t) => ({
|
|
15
15
|
key: e.key,
|
|
16
16
|
code: e.code,
|
|
17
|
-
pressed:
|
|
17
|
+
pressed: t,
|
|
18
18
|
repeat: e.repeat,
|
|
19
19
|
location: e.location,
|
|
20
20
|
shiftKey: e.shiftKey,
|
|
@@ -22,139 +22,147 @@ function W(n) {
|
|
|
22
22
|
altKey: e.altKey,
|
|
23
23
|
metaKey: e.metaKey
|
|
24
24
|
});
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
function d() {
|
|
29
|
-
const e = E.getBoundingClientRect(), i = u.visualViewport, r = Math.max(e.left, i?.offsetLeft ?? 0), k = Math.max(e.top, i?.offsetTop ?? 0), B = Math.min(e.right, (i?.offsetLeft ?? 0) + (i?.width ?? u.innerWidth)), P = Math.min(e.bottom, (i?.offsetTop ?? 0) + (i?.height ?? u.innerHeight)), R = Math.max(1, Math.min(320, B - r - 8));
|
|
30
|
-
t.style.maxWidth = `${R}px`;
|
|
31
|
-
const D = t.getBoundingClientRect(), $ = T?.x ?? r + 12, N = T?.y ?? k + 12;
|
|
32
|
-
t.style.left = `${Math.max(r, Math.min($, B - D.width - 4))}px`, t.style.top = `${Math.max(k, Math.min(N, P - D.height - 4))}px`;
|
|
25
|
+
function T(e) {
|
|
26
|
+
R !== e && (R = e, n.onKeyboardVisibilityChange?.(e));
|
|
33
27
|
}
|
|
34
28
|
function p() {
|
|
35
|
-
t.
|
|
29
|
+
const e = A.getBoundingClientRect(), t = c.visualViewport, r = Math.max(e.left, t?.offsetLeft ?? 0), d = Math.max(e.top, t?.offsetTop ?? 0), y = Math.min(e.right, (t?.offsetLeft ?? 0) + (t?.width ?? c.innerWidth)), I = Math.min(e.bottom, (t?.offsetTop ?? 0) + (t?.height ?? c.innerHeight)), P = Math.max(1, Math.min(320, y - r - 8));
|
|
30
|
+
i.style.maxWidth = `${P}px`;
|
|
31
|
+
const B = i.getBoundingClientRect(), N = $?.x ?? r + 12, W = $?.y ?? d + 12;
|
|
32
|
+
i.style.left = `${Math.max(r, Math.min(N, y - B.width - 4))}px`, i.style.top = `${Math.max(d, Math.min(W, I - B.height - 4))}px`;
|
|
33
|
+
}
|
|
34
|
+
function m() {
|
|
35
|
+
i.value = "", delete i.dataset.composing, a = null;
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
const e = l,
|
|
39
|
-
|
|
37
|
+
function E() {
|
|
38
|
+
const e = l, t = u.size > 0;
|
|
39
|
+
u.clear(), k.clear(), C.clear(), e !== null && t && n.release(e);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
41
|
+
function g() {
|
|
42
|
+
K++, o && (o.cancelled = !0), h = !0, m(), E(), o && x.activeElement === i && i.blur();
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
!e || l === null ||
|
|
44
|
+
function S(e) {
|
|
45
|
+
!e || l === null || f || (w === "text" && u.size && (u.clear(), C.clear(), n.release(l)), n.commitText(e, l));
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function z(e) {
|
|
48
48
|
if (l !== null) {
|
|
49
|
-
if (
|
|
50
|
-
for (const [
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
if (!/^(Shift|Control|Alt|Meta)(Left|Right)$/.test(e.code))
|
|
50
|
+
for (const [t, r] of [
|
|
51
|
+
["Shift", e.shiftKey],
|
|
52
|
+
["Control", e.ctrlKey],
|
|
53
|
+
["Alt", e.altKey],
|
|
54
|
+
["Meta", e.metaKey]
|
|
55
|
+
]) {
|
|
56
|
+
if (!r || [...u].some((y) => y === `${t}Left` || y === `${t}Right`)) continue;
|
|
57
|
+
const d = [...k.values()].find((y) => y.code === `${t}Left` || y.code === `${t}Right`) ?? { ...e, key: t, code: `${t}Left`, pressed: !0, repeat: !1, location: 1 };
|
|
58
|
+
u.add(d.code), k.has(d.code) || C.add(d.code), n.sendKey(d, l);
|
|
59
|
+
}
|
|
60
|
+
u.add(e.code || e.key), n.sendKey(e, l);
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
|
-
function
|
|
63
|
+
function D(e) {
|
|
56
64
|
if (l === null) return;
|
|
57
|
-
const
|
|
58
|
-
n.sendKey(
|
|
65
|
+
const t = { key: e, code: e, pressed: !0, repeat: !1, shiftKey: !1, ctrlKey: !1, altKey: !1, metaKey: !1, location: 0 }, r = l;
|
|
66
|
+
n.sendKey(t, r), l === r && n.sendKey({ ...t, pressed: !1 }, r);
|
|
59
67
|
}
|
|
60
|
-
function
|
|
61
|
-
if (l === null ||
|
|
62
|
-
|
|
68
|
+
function F(e) {
|
|
69
|
+
if (l === null || f) {
|
|
70
|
+
m();
|
|
63
71
|
return;
|
|
64
72
|
}
|
|
65
|
-
if (o?.cancelled || o && o.epoch !==
|
|
66
|
-
|
|
73
|
+
if (o?.cancelled || o && o.epoch !== K) {
|
|
74
|
+
m();
|
|
67
75
|
return;
|
|
68
76
|
}
|
|
69
77
|
if (e.isComposing) {
|
|
70
|
-
o ??= { epoch:
|
|
78
|
+
o ??= { epoch: K, committed: !1, cancelled: !1 }, i.dataset.composing = "true", p();
|
|
71
79
|
return;
|
|
72
80
|
}
|
|
73
81
|
if (o) {
|
|
74
|
-
!o.committed &&
|
|
82
|
+
!o.committed && i.value && (o.committed = !0, S(i.value)), m();
|
|
75
83
|
return;
|
|
76
84
|
}
|
|
77
|
-
if (
|
|
78
|
-
|
|
85
|
+
if (h || e.inputType === "insertFromComposition") {
|
|
86
|
+
h = !1, m();
|
|
79
87
|
return;
|
|
80
88
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
const r = s;
|
|
84
|
-
f.add(r.code || r.key), n.sendKey(r, l);
|
|
85
|
-
} else V(i);
|
|
86
|
-
p();
|
|
89
|
+
const t = i.value;
|
|
90
|
+
w === "physical" && a && t === a.key && !a.altKey && t.length === 1 ? z(a) : S(t), m();
|
|
87
91
|
}
|
|
88
|
-
return
|
|
89
|
-
if (!(l === null ||
|
|
92
|
+
return s(i, "keydown", (e) => {
|
|
93
|
+
if (!(l === null || f)) {
|
|
90
94
|
if (e.stopPropagation(), o?.cancelled && !e.isComposing && e.key !== "Process" && e.keyCode !== 229 && (o = null), e.isComposing || o || e.key === "Process" || e.keyCode === 229) {
|
|
91
|
-
|
|
95
|
+
L.add(b(e)), a = null;
|
|
92
96
|
return;
|
|
93
97
|
}
|
|
94
|
-
if (
|
|
95
|
-
|
|
98
|
+
if (L.delete(b(e)), h = !1, n.clipboard?.(e, l)) {
|
|
99
|
+
a = null;
|
|
96
100
|
return;
|
|
97
101
|
}
|
|
98
|
-
if (
|
|
99
|
-
|
|
102
|
+
if (w === "text" && /^(Shift|Control|Alt|Meta)(Left|Right)$/.test(e.code)) {
|
|
103
|
+
k.set(b(e), M(e, !0));
|
|
100
104
|
return;
|
|
101
105
|
}
|
|
102
106
|
if (e.key === "Dead" || e.key === "Unidentified") {
|
|
103
|
-
|
|
107
|
+
a = null;
|
|
104
108
|
return;
|
|
105
109
|
}
|
|
106
110
|
if (Array.from(e.key).length === 1 && !e.metaKey && (!e.ctrlKey || e.getModifierState("AltGraph"))) {
|
|
107
|
-
|
|
111
|
+
a = M(e, !0);
|
|
108
112
|
return;
|
|
109
113
|
}
|
|
110
|
-
e.preventDefault(),
|
|
114
|
+
e.preventDefault(), z(M(e, !0));
|
|
115
|
+
}
|
|
116
|
+
}), s(i, "keyup", (e) => {
|
|
117
|
+
if (e.stopPropagation(), a = null, k.delete(b(e)), !L.delete(b(e)) && (l !== null && u.delete(b(e)) && n.sendKey(M(e, !1), l), l !== null && ![...u].some((t) => !/^(Shift|Control|Alt|Meta)(Left|Right)$/.test(t)))) {
|
|
118
|
+
for (const t of C)
|
|
119
|
+
u.delete(t), n.sendKey({ ...M(e, !1), code: t, key: t.replace(/Left$/, ""), location: 1 }, l);
|
|
120
|
+
C.clear();
|
|
111
121
|
}
|
|
112
|
-
}),
|
|
113
|
-
|
|
114
|
-
}), a(t, "beforeinput", (e) => {
|
|
115
|
-
if (l === null || c) {
|
|
122
|
+
}), s(i, "beforeinput", (e) => {
|
|
123
|
+
if (l === null || f) {
|
|
116
124
|
e.preventDefault();
|
|
117
125
|
return;
|
|
118
126
|
}
|
|
119
127
|
if (e.isComposing || o || e.inputType === "insertCompositionText" || e.inputType === "deleteCompositionText" || e.inputType === "insertFromComposition") return;
|
|
120
|
-
|
|
128
|
+
h = !1;
|
|
121
129
|
const r = { deleteContentBackward: "Backspace", deleteContentForward: "Delete", insertLineBreak: "Enter", insertParagraph: "Enter" }[e.inputType];
|
|
122
|
-
r && (e.preventDefault(),
|
|
123
|
-
}),
|
|
124
|
-
o = { epoch:
|
|
125
|
-
}),
|
|
126
|
-
const
|
|
127
|
-
o = null,
|
|
128
|
-
}),
|
|
129
|
-
|
|
130
|
-
}),
|
|
131
|
-
element:
|
|
130
|
+
r && (e.preventDefault(), m(), D(r));
|
|
131
|
+
}), s(i, "input", F), s(i, "compositionstart", () => {
|
|
132
|
+
o = { epoch: K, committed: !1, cancelled: l === null }, h = !1, a = null, i.dataset.composing = "true", p();
|
|
133
|
+
}), s(i, "compositionend", (e) => {
|
|
134
|
+
const t = o;
|
|
135
|
+
o = null, h = !0, m(), t && !t.cancelled && !t.committed && t.epoch === K && S(e.data);
|
|
136
|
+
}), s(i, "blur", () => {
|
|
137
|
+
g(), T(!1);
|
|
138
|
+
}), s(c, "blur", g), s(c, "pagehide", g), s(c, "resize", p), c.visualViewport && (s(c.visualViewport, "resize", p), s(c.visualViewport, "scroll", p)), p(), {
|
|
139
|
+
element: i,
|
|
132
140
|
bindTarget(e) {
|
|
133
|
-
|
|
141
|
+
f || Object.is(l, e) || (g(), l = e, i.disabled = e === null);
|
|
134
142
|
},
|
|
135
143
|
setTextInputMode(e) {
|
|
136
|
-
|
|
144
|
+
f || e === w || (g(), w = e);
|
|
137
145
|
},
|
|
138
|
-
setAnchor(e,
|
|
139
|
-
!Number.isFinite(e) || !Number.isFinite(
|
|
146
|
+
setAnchor(e, t) {
|
|
147
|
+
!Number.isFinite(e) || !Number.isFinite(t) || ($ = { x: e, y: t }, p());
|
|
140
148
|
},
|
|
141
149
|
focus() {
|
|
142
|
-
l === null ||
|
|
150
|
+
l === null || f || (i.focus({ preventScroll: !0 }), p());
|
|
143
151
|
},
|
|
144
152
|
setKeyboardVisible(e) {
|
|
145
|
-
e && l !== null && !
|
|
153
|
+
e && l !== null && !f ? (i.focus({ preventScroll: !0 }), T(!0), p()) : (i.blur(), T(!1));
|
|
146
154
|
},
|
|
147
|
-
release:
|
|
148
|
-
reset:
|
|
155
|
+
release: E,
|
|
156
|
+
reset: g,
|
|
149
157
|
dispose() {
|
|
150
|
-
if (!
|
|
151
|
-
|
|
152
|
-
for (const e of
|
|
153
|
-
|
|
158
|
+
if (!f) {
|
|
159
|
+
g(), f = !0, l = null;
|
|
160
|
+
for (const e of V) e();
|
|
161
|
+
i.remove(), T(!1);
|
|
154
162
|
}
|
|
155
163
|
}
|
|
156
164
|
};
|
|
157
165
|
}
|
|
158
166
|
export {
|
|
159
|
-
|
|
167
|
+
j as createRemoteInput
|
|
160
168
|
};
|