@floegence/floe-webapp-core 0.103.7 → 0.104.0
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,99 +1,105 @@
|
|
|
1
|
-
import { use as
|
|
2
|
-
import { createSignal as
|
|
3
|
-
import { imageAnnotationMarkup as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { use as j, insert as G, createComponent as N, effect as X, setAttribute as h, setStyleProperty as y, memo as J, className as nt, template as F, delegateEvents as it } from "solid-js/web";
|
|
2
|
+
import { createSignal as Q, onCleanup as V, createMemo as at, onMount as ot, For as Z, Show as $ } from "solid-js";
|
|
3
|
+
import { imageAnnotationMarkup as _, validateImageAnnotation as Y, imagePointFromClient as rt } from "./imageAnnotation.js";
|
|
4
|
+
import { startPointerSession as dt } from "../ui/pointerSession.js";
|
|
5
|
+
var lt = /* @__PURE__ */ F("<div data-floe-image-annotation style=width:100%;height:100%;overscroll-behavior:contain><div style=display:grid;place-items:center><svg xmlns=http://www.w3.org/2000/svg role=img style=display:block;user-select:none;flex:none><image></image><g data-annotation-target>"), ct = /* @__PURE__ */ F("<svg><g style=pointer-events:none></svg>", !1, !0, !1), ht = /* @__PURE__ */ F("<svg><rect data-annotation-target fill=white stroke=#111827></svg>", !1, !0, !1);
|
|
6
|
+
function ft(e) {
|
|
7
|
+
let v, D;
|
|
8
|
+
const [E, p] = Q({
|
|
8
9
|
width: 1,
|
|
9
10
|
height: 1
|
|
10
|
-
}), [
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
}), [T, k] = Q();
|
|
12
|
+
let b, m, M;
|
|
13
|
+
V(() => M?.stop());
|
|
14
|
+
const L = () => T() ?? e.annotation, f = at(() => Math.min(E().width / e.width, E().height / e.height) * Math.max(1, e.zoom ?? 1)), tt = () => e.showAnnotation !== !1 && L() && Y(e, L()) ? _(e, L(), e.marker ?? (e.activeIndex !== void 0 ? e.activeIndex + 1 : 1)) : "";
|
|
15
|
+
ot(() => {
|
|
16
|
+
let n = 0;
|
|
17
|
+
const r = () => {
|
|
18
|
+
n = 0;
|
|
19
|
+
const a = v.clientWidth, c = v.clientHeight;
|
|
20
|
+
p((g) => g.width === a && g.height === c ? g : {
|
|
21
|
+
width: a,
|
|
22
|
+
height: c
|
|
21
23
|
});
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
+
}, o = new ResizeObserver(() => {
|
|
25
|
+
n || (n = requestAnimationFrame(r));
|
|
24
26
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
o.observe(v), r(), V(() => {
|
|
28
|
+
o.disconnect(), cancelAnimationFrame(n);
|
|
27
29
|
});
|
|
28
30
|
});
|
|
29
|
-
const
|
|
30
|
-
x:
|
|
31
|
-
y:
|
|
32
|
-
},
|
|
33
|
-
if (m?.id ===
|
|
34
|
-
|
|
31
|
+
const B = (n, r = !1) => rt(e, D.getBoundingClientRect(), {
|
|
32
|
+
x: n.clientX,
|
|
33
|
+
y: n.clientY
|
|
34
|
+
}, r), w = () => !!e.onChange && !e.disabled && !e.panning, H = (n) => {
|
|
35
|
+
if (m?.id === n.pointerId) {
|
|
36
|
+
v.scrollLeft = m.left + m.x - n.clientX, v.scrollTop = m.top + m.y - n.clientY;
|
|
35
37
|
return;
|
|
36
38
|
}
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
...
|
|
46
|
-
x: Math.max(0, Math.min(e.width -
|
|
47
|
-
y: Math.max(0, Math.min(e.height - g,
|
|
39
|
+
const r = b;
|
|
40
|
+
if (!r || r.id !== n.pointerId || r.src !== e.src || !w()) return;
|
|
41
|
+
const o = B(n, !0);
|
|
42
|
+
if (!o) return;
|
|
43
|
+
const a = r.original;
|
|
44
|
+
if (a && r.corner === void 0) {
|
|
45
|
+
const c = a.kind === "rectangle" ? a.width : 0, g = a.kind === "rectangle" ? a.height : 0;
|
|
46
|
+
k({
|
|
47
|
+
...a,
|
|
48
|
+
x: Math.max(0, Math.min(e.width - c, a.x + o.x - r.start.x)),
|
|
49
|
+
y: Math.max(0, Math.min(e.height - g, a.y + o.y - r.start.y))
|
|
48
50
|
});
|
|
49
51
|
} else {
|
|
50
|
-
const
|
|
51
|
-
x:
|
|
52
|
-
y:
|
|
53
|
-
} :
|
|
54
|
-
Math.hypot(
|
|
52
|
+
const c = a?.kind === "rectangle" && r.corner !== void 0 ? {
|
|
53
|
+
x: a.x + (r.corner % 2 ? 0 : a.width),
|
|
54
|
+
y: a.y + (r.corner < 2 ? a.height : 0)
|
|
55
|
+
} : r.start, g = Math.abs(o.x - c.x), A = Math.abs(o.y - c.y);
|
|
56
|
+
Math.hypot(n.clientX - r.client.x, n.clientY - r.client.y) >= 5 && (r.dragged = !0), !r.dragged && !a ? k(r.pin ? void 0 : {
|
|
55
57
|
kind: "point",
|
|
56
|
-
...
|
|
57
|
-
}) : g > 0 &&
|
|
58
|
+
...c
|
|
59
|
+
}) : g > 0 && A > 0 && k({
|
|
58
60
|
kind: "rectangle",
|
|
59
|
-
x: Math.min(
|
|
60
|
-
y: Math.min(
|
|
61
|
+
x: Math.min(c.x, o.x),
|
|
62
|
+
y: Math.min(c.y, o.y),
|
|
61
63
|
width: g,
|
|
62
|
-
height:
|
|
64
|
+
height: A
|
|
63
65
|
});
|
|
64
66
|
}
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
}, P = (n) => {
|
|
68
|
+
M = dt({
|
|
69
|
+
pointerEvent: n,
|
|
70
|
+
captureEl: v,
|
|
71
|
+
continueOnCaptureLoss: !0,
|
|
72
|
+
onMove: H,
|
|
73
|
+
onEnd: (r) => {
|
|
74
|
+
M = void 0;
|
|
75
|
+
const o = r.reason === "pointer_up" && r.event;
|
|
76
|
+
o && H(o), m = void 0;
|
|
77
|
+
const a = b, c = T();
|
|
78
|
+
b = void 0, k(void 0), !(!a || !o || a.src !== e.src || !w()) && (a.pin && !a.dragged ? e.annotations?.[a.pin.index] === a.pin.annotation && e.onSelect?.(a.pin.index) : c && Y(e, c) && e.onChange?.(c));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}, et = () => {
|
|
82
|
+
const n = L();
|
|
83
|
+
return n?.kind === "rectangle" ? [{
|
|
84
|
+
x: n.x,
|
|
85
|
+
y: n.y
|
|
80
86
|
}, {
|
|
81
|
-
x:
|
|
82
|
-
y:
|
|
87
|
+
x: n.x + n.width,
|
|
88
|
+
y: n.y
|
|
83
89
|
}, {
|
|
84
|
-
x:
|
|
85
|
-
y:
|
|
90
|
+
x: n.x,
|
|
91
|
+
y: n.y + n.height
|
|
86
92
|
}, {
|
|
87
|
-
x:
|
|
88
|
-
y:
|
|
93
|
+
x: n.x + n.width,
|
|
94
|
+
y: n.y + n.height
|
|
89
95
|
}] : [];
|
|
90
96
|
};
|
|
91
97
|
return (() => {
|
|
92
|
-
var
|
|
93
|
-
typeof g == "function" ?
|
|
94
|
-
if (!
|
|
98
|
+
var n = lt(), r = n.firstChild, o = r.firstChild, a = o.firstChild, c = a.nextSibling, g = v;
|
|
99
|
+
typeof g == "function" ? j(g, n) : v = n, o.$$keydown = (t) => {
|
|
100
|
+
if (!w()) return;
|
|
95
101
|
if (t.key === "Escape") {
|
|
96
|
-
|
|
102
|
+
M?.stop();
|
|
97
103
|
return;
|
|
98
104
|
}
|
|
99
105
|
const l = {
|
|
@@ -104,37 +110,38 @@ function gt(e) {
|
|
|
104
110
|
}[t.key];
|
|
105
111
|
if (!l && t.key !== "Enter" && t.key !== " ") return;
|
|
106
112
|
t.preventDefault();
|
|
107
|
-
const
|
|
113
|
+
const d = e.annotation ?? {
|
|
108
114
|
kind: "point",
|
|
109
115
|
x: e.width / 2,
|
|
110
116
|
y: e.height / 2
|
|
111
|
-
},
|
|
117
|
+
}, i = t.shiftKey ? 10 : 1;
|
|
112
118
|
e.onChange?.({
|
|
113
|
-
...
|
|
114
|
-
x: Math.max(0, Math.min(e.width - (
|
|
115
|
-
y: Math.max(0, Math.min(e.height - (
|
|
119
|
+
...d,
|
|
120
|
+
x: Math.max(0, Math.min(e.width - (d.kind === "rectangle" ? d.width : 0), d.x + (l?.[0] ?? 0) * i)),
|
|
121
|
+
y: Math.max(0, Math.min(e.height - (d.kind === "rectangle" ? d.height : 0), d.y + (l?.[1] ?? 0) * i))
|
|
116
122
|
});
|
|
117
|
-
},
|
|
123
|
+
}, o.$$pointerdown = (t) => {
|
|
124
|
+
if (M) return;
|
|
118
125
|
if (e.panning && t.button === 0 && !m) {
|
|
119
126
|
m = {
|
|
120
127
|
id: t.pointerId,
|
|
121
128
|
x: t.clientX,
|
|
122
129
|
y: t.clientY,
|
|
123
|
-
left:
|
|
124
|
-
top:
|
|
125
|
-
},
|
|
130
|
+
left: v.scrollLeft,
|
|
131
|
+
top: v.scrollTop
|
|
132
|
+
}, P(t), t.preventDefault();
|
|
126
133
|
return;
|
|
127
134
|
}
|
|
128
|
-
if (!
|
|
129
|
-
const l =
|
|
135
|
+
if (!w() || t.button !== 0 || b) return;
|
|
136
|
+
const l = B(t);
|
|
130
137
|
if (!l) return;
|
|
131
|
-
const
|
|
138
|
+
const d = t.target, i = d.closest("[data-annotation-index]")?.getAttribute("data-annotation-index"), s = i == null ? void 0 : e.annotations?.[Number(i)];
|
|
132
139
|
if (s && (e.annotation || e.activeIndex !== void 0)) {
|
|
133
|
-
e.onSelect?.(Number(
|
|
140
|
+
e.onSelect?.(Number(i)), t.preventDefault();
|
|
134
141
|
return;
|
|
135
142
|
}
|
|
136
|
-
const u =
|
|
137
|
-
|
|
143
|
+
const u = d.getAttribute("data-corner");
|
|
144
|
+
b = {
|
|
138
145
|
id: t.pointerId,
|
|
139
146
|
start: l,
|
|
140
147
|
client: {
|
|
@@ -145,58 +152,58 @@ function gt(e) {
|
|
|
145
152
|
src: e.src,
|
|
146
153
|
...s ? {
|
|
147
154
|
pin: {
|
|
148
|
-
index: Number(
|
|
155
|
+
index: Number(i),
|
|
149
156
|
annotation: s
|
|
150
157
|
}
|
|
151
158
|
} : {},
|
|
152
|
-
...
|
|
159
|
+
...d.closest("[data-annotation-target]") ? {
|
|
153
160
|
original: e.annotation
|
|
154
161
|
} : {},
|
|
155
162
|
...u !== null ? {
|
|
156
163
|
corner: Number(u)
|
|
157
164
|
} : {}
|
|
158
|
-
},
|
|
165
|
+
}, k(b.pin ? void 0 : b.original ?? {
|
|
159
166
|
kind: "point",
|
|
160
167
|
...l
|
|
161
|
-
}),
|
|
168
|
+
}), P(t), D.focus({
|
|
162
169
|
preventScroll: !0
|
|
163
170
|
}), t.preventDefault();
|
|
164
171
|
};
|
|
165
|
-
var
|
|
166
|
-
return typeof
|
|
172
|
+
var A = D;
|
|
173
|
+
return typeof A == "function" ? j(A, o) : D = o, G(o, N(Z, {
|
|
167
174
|
get each() {
|
|
168
175
|
return e.annotations?.slice(0, 99);
|
|
169
176
|
},
|
|
170
|
-
children: (t, l) =>
|
|
177
|
+
children: (t, l) => N($, {
|
|
171
178
|
get when() {
|
|
172
|
-
return
|
|
179
|
+
return J(() => e.showAnnotation !== !1 && l() !== e.activeIndex)() && Y(e, t);
|
|
173
180
|
},
|
|
174
181
|
get children() {
|
|
175
|
-
var
|
|
176
|
-
return
|
|
177
|
-
var s = l(), u =
|
|
178
|
-
return s !==
|
|
182
|
+
var d = ct();
|
|
183
|
+
return X((i) => {
|
|
184
|
+
var s = l(), u = _(e, t, l() + 1), x = e.cursor ?? (e.onSelect ? "pointer" : void 0);
|
|
185
|
+
return s !== i.e && h(d, "data-annotation-index", i.e = s), u !== i.t && (d.innerHTML = i.t = u), x !== i.a && y(d, "cursor", i.a = x), i;
|
|
179
186
|
}, {
|
|
180
187
|
e: void 0,
|
|
181
188
|
t: void 0,
|
|
182
189
|
a: void 0
|
|
183
|
-
}),
|
|
190
|
+
}), d;
|
|
184
191
|
}
|
|
185
192
|
})
|
|
186
|
-
}),
|
|
193
|
+
}), c), G(o, N($, {
|
|
187
194
|
get when() {
|
|
188
|
-
return
|
|
195
|
+
return J(() => !!w())() && e.showAnnotation !== !1;
|
|
189
196
|
},
|
|
190
197
|
get children() {
|
|
191
|
-
return
|
|
198
|
+
return N(Z, {
|
|
192
199
|
get each() {
|
|
193
|
-
return
|
|
200
|
+
return et();
|
|
194
201
|
},
|
|
195
202
|
children: (t, l) => (() => {
|
|
196
|
-
var
|
|
197
|
-
return
|
|
198
|
-
var s = l(), u = t.x - 5 /
|
|
199
|
-
return s !==
|
|
203
|
+
var d = ht();
|
|
204
|
+
return X((i) => {
|
|
205
|
+
var s = l(), u = t.x - 5 / f(), x = t.y - 5 / f(), C = 10 / f(), S = 10 / f(), I = 1 / f(), z = e.cursor ?? (l() === 0 || l() === 3 ? "nwse-resize" : "nesw-resize");
|
|
206
|
+
return s !== i.e && h(d, "data-corner", i.e = s), u !== i.t && h(d, "x", i.t = u), x !== i.a && h(d, "y", i.a = x), C !== i.o && h(d, "width", i.o = C), S !== i.i && h(d, "height", i.i = S), I !== i.n && h(d, "stroke-width", i.n = I), z !== i.s && y(d, "cursor", i.s = z), i;
|
|
200
207
|
}, {
|
|
201
208
|
e: void 0,
|
|
202
209
|
t: void 0,
|
|
@@ -205,13 +212,13 @@ function gt(e) {
|
|
|
205
212
|
i: void 0,
|
|
206
213
|
n: void 0,
|
|
207
214
|
s: void 0
|
|
208
|
-
}),
|
|
215
|
+
}), d;
|
|
209
216
|
})()
|
|
210
217
|
});
|
|
211
218
|
}
|
|
212
|
-
}), null),
|
|
213
|
-
var l = e.class,
|
|
214
|
-
return l !== t.e &&
|
|
219
|
+
}), null), X((t) => {
|
|
220
|
+
var l = e.class, d = (e.zoom ?? 1) > 1 ? "auto" : "hidden", i = (e.zoom ?? 1) > 1 ? "stable" : "auto", s = `${Math.max(E().width, e.width * f())}px`, u = `${Math.max(E().height, e.height * f())}px`, x = e.width * f(), C = e.height * f(), S = `0 0 ${e.width} ${e.height}`, I = e.label, z = w() ? 0 : void 0, R = w() || e.panning ? "none" : "auto", O = e.cursor ?? (e.panning ? "grab" : w() ? "crosshair" : "default"), q = e.src, K = e.width, U = e.height, W = tt();
|
|
221
|
+
return l !== t.e && nt(n, t.e = l), d !== t.t && y(n, "overflow", t.t = d), i !== t.a && y(n, "scrollbar-gutter", t.a = i), s !== t.o && y(r, "width", t.o = s), u !== t.i && y(r, "height", t.i = u), x !== t.n && h(o, "width", t.n = x), C !== t.s && h(o, "height", t.s = C), S !== t.h && h(o, "viewBox", t.h = S), I !== t.r && h(o, "aria-label", t.r = I), z !== t.d && h(o, "tabindex", t.d = z), R !== t.l && y(o, "touch-action", t.l = R), O !== t.u && y(o, "cursor", t.u = O), q !== t.c && h(a, "href", t.c = q), K !== t.w && h(a, "width", t.w = K), U !== t.m && h(a, "height", t.m = U), W !== t.f && (c.innerHTML = t.f = W), t;
|
|
215
222
|
}, {
|
|
216
223
|
e: void 0,
|
|
217
224
|
t: void 0,
|
|
@@ -229,10 +236,10 @@ function gt(e) {
|
|
|
229
236
|
w: void 0,
|
|
230
237
|
m: void 0,
|
|
231
238
|
f: void 0
|
|
232
|
-
}),
|
|
239
|
+
}), n;
|
|
233
240
|
})();
|
|
234
241
|
}
|
|
235
|
-
|
|
242
|
+
it(["pointerdown", "keydown"]);
|
|
236
243
|
export {
|
|
237
|
-
|
|
244
|
+
ft as ImageAnnotationSurface
|
|
238
245
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floegence/floe-webapp-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.104.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -210,7 +210,7 @@
|
|
|
210
210
|
"solid-js": "^1.9.17",
|
|
211
211
|
"tailwindcss": "^4.3.3",
|
|
212
212
|
"typescript": "^5.9.3",
|
|
213
|
-
"vite": "^7.3.
|
|
213
|
+
"vite": "^7.3.7",
|
|
214
214
|
"vite-plugin-solid": "^2.11.14"
|
|
215
215
|
},
|
|
216
216
|
"peerDependenciesMeta": {
|