@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 W, insert as j, createComponent as D, effect as N, setAttribute as c, setStyleProperty as k, memo as G, className as tt, template as Y, delegateEvents as et } from "solid-js/web";
2
- import { createSignal as J, createMemo as it, onMount as nt, onCleanup as at, For as Q, Show as V } from "solid-js";
3
- import { imageAnnotationMarkup as Z, validateImageAnnotation as X, imagePointFromClient as ot } from "./imageAnnotation.js";
4
- var rt = /* @__PURE__ */ Y("<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>"), dt = /* @__PURE__ */ Y("<svg><g style=pointer-events:none></svg>", !1, !0, !1), lt = /* @__PURE__ */ Y("<svg><rect data-annotation-target fill=white stroke=#111827></svg>", !1, !0, !1);
5
- function gt(e) {
6
- let f, v;
7
- const [P, $] = J({
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
- }), [F, M] = J();
11
- let x, m;
12
- const L = () => F() ?? e.annotation, w = it(() => Math.min(P().width / e.width, P().height / e.height) * Math.max(1, e.zoom ?? 1)), _ = () => e.showAnnotation !== !1 && L() && X(e, L()) ? Z(e, L(), e.marker ?? (e.activeIndex !== void 0 ? e.activeIndex + 1 : 1)) : "";
13
- nt(() => {
14
- let i = 0;
15
- const o = () => {
16
- i = 0;
17
- const d = f.clientWidth, h = f.clientHeight;
18
- $((g) => g.width === d && g.height === h ? g : {
19
- width: d,
20
- height: h
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
- }, n = new ResizeObserver(() => {
23
- i || (i = requestAnimationFrame(o));
24
+ }, o = new ResizeObserver(() => {
25
+ n || (n = requestAnimationFrame(r));
24
26
  });
25
- n.observe(f), o(), at(() => {
26
- n.disconnect(), cancelAnimationFrame(i);
27
+ o.observe(v), r(), V(() => {
28
+ o.disconnect(), cancelAnimationFrame(n);
27
29
  });
28
30
  });
29
- const T = (i, o = !1) => ot(e, v.getBoundingClientRect(), {
30
- x: i.clientX,
31
- y: i.clientY
32
- }, o), y = () => !!e.onChange && !e.disabled && !e.panning, B = (i) => {
33
- if (m?.id === i.pointerId) {
34
- f.scrollLeft = m.left + m.x - i.clientX, f.scrollTop = m.top + m.y - i.clientY;
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 o = x;
38
- if (!o || o.id !== i.pointerId || o.src !== e.src || !y()) return;
39
- const n = T(i, !0);
40
- if (!n) return;
41
- const d = o.original;
42
- if (d && o.corner === void 0) {
43
- const h = d.kind === "rectangle" ? d.width : 0, g = d.kind === "rectangle" ? d.height : 0;
44
- M({
45
- ...d,
46
- x: Math.max(0, Math.min(e.width - h, d.x + n.x - o.start.x)),
47
- y: Math.max(0, Math.min(e.height - g, d.y + n.y - o.start.y))
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 h = d?.kind === "rectangle" && o.corner !== void 0 ? {
51
- x: d.x + (o.corner % 2 ? 0 : d.width),
52
- y: d.y + (o.corner < 2 ? d.height : 0)
53
- } : o.start, g = Math.abs(n.x - h.x), I = Math.abs(n.y - h.y);
54
- Math.hypot(i.clientX - o.client.x, i.clientY - o.client.y) >= 5 && (o.dragged = !0), !o.dragged && !d ? M(o.pin ? void 0 : {
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
- ...h
57
- }) : g > 0 && I > 0 && M({
58
+ ...c
59
+ }) : g > 0 && A > 0 && k({
58
60
  kind: "rectangle",
59
- x: Math.min(h.x, n.x),
60
- y: Math.min(h.y, n.y),
61
+ x: Math.min(c.x, o.x),
62
+ y: Math.min(c.y, o.y),
61
63
  width: g,
62
- height: I
64
+ height: A
63
65
  });
64
66
  }
65
- }, E = (i, o = !1) => {
66
- if (m?.id === i.pointerId) {
67
- m = void 0, v.hasPointerCapture(i.pointerId) && v.releasePointerCapture(i.pointerId);
68
- return;
69
- }
70
- const n = x;
71
- if (!n || n.id !== i.pointerId) return;
72
- o || B(i);
73
- const d = F();
74
- x = void 0, M(void 0), v.hasPointerCapture(i.pointerId) && v.releasePointerCapture(i.pointerId), !(o || n.src !== e.src || !y()) && (n.pin && !n.dragged ? e.annotations?.[n.pin.index] === n.pin.annotation && e.onSelect?.(n.pin.index) : d && X(e, d) && e.onChange?.(d));
75
- }, p = () => {
76
- const i = L();
77
- return i?.kind === "rectangle" ? [{
78
- x: i.x,
79
- y: i.y
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: i.x + i.width,
82
- y: i.y
87
+ x: n.x + n.width,
88
+ y: n.y
83
89
  }, {
84
- x: i.x,
85
- y: i.y + i.height
90
+ x: n.x,
91
+ y: n.y + n.height
86
92
  }, {
87
- x: i.x + i.width,
88
- y: i.y + i.height
93
+ x: n.x + n.width,
94
+ y: n.y + n.height
89
95
  }] : [];
90
96
  };
91
97
  return (() => {
92
- var i = rt(), o = i.firstChild, n = o.firstChild, d = n.firstChild, h = d.nextSibling, g = f;
93
- typeof g == "function" ? W(g, i) : f = i, n.$$keydown = (t) => {
94
- if (!y()) return;
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
- x = void 0, M(void 0);
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 r = e.annotation ?? {
113
+ const d = e.annotation ?? {
108
114
  kind: "point",
109
115
  x: e.width / 2,
110
116
  y: e.height / 2
111
- }, a = t.shiftKey ? 10 : 1;
117
+ }, i = t.shiftKey ? 10 : 1;
112
118
  e.onChange?.({
113
- ...r,
114
- x: Math.max(0, Math.min(e.width - (r.kind === "rectangle" ? r.width : 0), r.x + (l?.[0] ?? 0) * a)),
115
- y: Math.max(0, Math.min(e.height - (r.kind === "rectangle" ? r.height : 0), r.y + (l?.[1] ?? 0) * a))
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
- }, n.addEventListener("lostpointercapture", (t) => E(t, !0)), n.addEventListener("pointercancel", (t) => E(t, !0)), n.$$pointerup = (t) => E(t), n.$$pointermove = B, n.$$pointerdown = (t) => {
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: f.scrollLeft,
124
- top: f.scrollTop
125
- }, v.setPointerCapture(t.pointerId), t.preventDefault();
130
+ left: v.scrollLeft,
131
+ top: v.scrollTop
132
+ }, P(t), t.preventDefault();
126
133
  return;
127
134
  }
128
- if (!y() || t.button !== 0 || x) return;
129
- const l = T(t);
135
+ if (!w() || t.button !== 0 || b) return;
136
+ const l = B(t);
130
137
  if (!l) return;
131
- const r = t.target, a = r.closest("[data-annotation-index]")?.getAttribute("data-annotation-index"), s = a == null ? void 0 : e.annotations?.[Number(a)];
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(a)), t.preventDefault();
140
+ e.onSelect?.(Number(i)), t.preventDefault();
134
141
  return;
135
142
  }
136
- const u = r.getAttribute("data-corner");
137
- x = {
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(a),
155
+ index: Number(i),
149
156
  annotation: s
150
157
  }
151
158
  } : {},
152
- ...r.closest("[data-annotation-target]") ? {
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
- }, M(x.pin ? void 0 : x.original ?? {
165
+ }, k(b.pin ? void 0 : b.original ?? {
159
166
  kind: "point",
160
167
  ...l
161
- }), v.setPointerCapture(t.pointerId), v.focus({
168
+ }), P(t), D.focus({
162
169
  preventScroll: !0
163
170
  }), t.preventDefault();
164
171
  };
165
- var I = v;
166
- return typeof I == "function" ? W(I, n) : v = n, j(n, D(Q, {
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) => D(V, {
177
+ children: (t, l) => N($, {
171
178
  get when() {
172
- return G(() => e.showAnnotation !== !1 && l() !== e.activeIndex)() && X(e, t);
179
+ return J(() => e.showAnnotation !== !1 && l() !== e.activeIndex)() && Y(e, t);
173
180
  },
174
181
  get children() {
175
- var r = dt();
176
- return N((a) => {
177
- var s = l(), u = Z(e, t, l() + 1), b = e.cursor ?? (e.onSelect ? "pointer" : void 0);
178
- return s !== a.e && c(r, "data-annotation-index", a.e = s), u !== a.t && (r.innerHTML = a.t = u), b !== a.a && k(r, "cursor", a.a = b), a;
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
- }), r;
190
+ }), d;
184
191
  }
185
192
  })
186
- }), h), j(n, D(V, {
193
+ }), c), G(o, N($, {
187
194
  get when() {
188
- return G(() => !!y())() && e.showAnnotation !== !1;
195
+ return J(() => !!w())() && e.showAnnotation !== !1;
189
196
  },
190
197
  get children() {
191
- return D(Q, {
198
+ return N(Z, {
192
199
  get each() {
193
- return p();
200
+ return et();
194
201
  },
195
202
  children: (t, l) => (() => {
196
- var r = lt();
197
- return N((a) => {
198
- var s = l(), u = t.x - 5 / w(), b = t.y - 5 / w(), C = 10 / w(), A = 10 / w(), S = 1 / w(), z = e.cursor ?? (l() === 0 || l() === 3 ? "nwse-resize" : "nesw-resize");
199
- return s !== a.e && c(r, "data-corner", a.e = s), u !== a.t && c(r, "x", a.t = u), b !== a.a && c(r, "y", a.a = b), C !== a.o && c(r, "width", a.o = C), A !== a.i && c(r, "height", a.i = A), S !== a.n && c(r, "stroke-width", a.n = S), z !== a.s && k(r, "cursor", a.s = z), a;
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
- }), r;
215
+ }), d;
209
216
  })()
210
217
  });
211
218
  }
212
- }), null), N((t) => {
213
- var l = e.class, r = (e.zoom ?? 1) > 1 ? "auto" : "hidden", a = (e.zoom ?? 1) > 1 ? "stable" : "auto", s = `${Math.max(P().width, e.width * w())}px`, u = `${Math.max(P().height, e.height * w())}px`, b = e.width * w(), C = e.height * w(), A = `0 0 ${e.width} ${e.height}`, S = e.label, z = y() ? 0 : void 0, H = y() || e.panning ? "none" : "auto", R = e.cursor ?? (e.panning ? "grab" : y() ? "crosshair" : "default"), q = e.src, K = e.width, O = e.height, U = _();
214
- return l !== t.e && tt(i, t.e = l), r !== t.t && k(i, "overflow", t.t = r), a !== t.a && k(i, "scrollbar-gutter", t.a = a), s !== t.o && k(o, "width", t.o = s), u !== t.i && k(o, "height", t.i = u), b !== t.n && c(n, "width", t.n = b), C !== t.s && c(n, "height", t.s = C), A !== t.h && c(n, "viewBox", t.h = A), S !== t.r && c(n, "aria-label", t.r = S), z !== t.d && c(n, "tabindex", t.d = z), H !== t.l && k(n, "touch-action", t.l = H), R !== t.u && k(n, "cursor", t.u = R), q !== t.c && c(d, "href", t.c = q), K !== t.w && c(d, "width", t.w = K), O !== t.m && c(d, "height", t.m = O), U !== t.f && (h.innerHTML = t.f = U), t;
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
- }), i;
239
+ }), n;
233
240
  })();
234
241
  }
235
- et(["pointerdown", "pointermove", "pointerup", "keydown"]);
242
+ it(["pointerdown", "keydown"]);
236
243
  export {
237
- gt as ImageAnnotationSurface
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.103.7",
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.6",
213
+ "vite": "^7.3.7",
214
214
  "vite-plugin-solid": "^2.11.14"
215
215
  },
216
216
  "peerDependenciesMeta": {