@floegence/floe-webapp-core 0.101.20 → 0.101.23

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.
@@ -3,7 +3,7 @@ import { createSignal as g, createMemo as $, createEffect as T, untrack as j, on
3
3
  import { sandboxedMarkdownHtml as K } from "../chat/markdown/media.js";
4
4
  import { findTextRanges as _ } from "../ui/textSearch.js";
5
5
  import { secureRandomUUID as z } from "../../utils/secureRandom.js";
6
- var W = /* @__PURE__ */ p('<span data-floe-html-pending style="position:absolute;inset:0;z-index:1;background:var(--background, Canvas)">'), J = /* @__PURE__ */ p('<span role=status class="pointer-events-none absolute inset-x-0 top-3 z-10 flex justify-center px-3"><span class="rounded-md bg-background/95 px-3 py-2 text-xs text-foreground shadow-sm">'), V = /* @__PURE__ */ p('<span role=alert class="max-h-24 shrink-0 overflow-auto break-words bg-background px-3 py-2 text-xs text-destructive">'), X = /* @__PURE__ */ p('<span class="relative flex h-full min-h-0 w-full flex-col"><iframe sandbox="allow-scripts allow-pointer-lock"referrerpolicy=no-referrer style="display:block;width:100%;min-height:0;flex:1 1 0%;border:0">');
6
+ var W = /* @__PURE__ */ p('<span data-floe-html-pending style="position:absolute;inset:0;z-index:1;background:var(--background, Canvas)">'), J = /* @__PURE__ */ p('<span role=status class="pointer-events-none absolute inset-x-0 top-3 z-10 flex justify-center px-3"><span class="rounded-md bg-background px-3 py-2 text-xs text-foreground shadow-sm">'), V = /* @__PURE__ */ p('<span role=alert class="max-h-24 shrink-0 overflow-auto break-words bg-background px-3 py-2 text-xs text-destructive">'), X = /* @__PURE__ */ p('<span class="relative flex h-full min-h-0 w-full flex-col"><iframe sandbox="allow-scripts allow-pointer-lock"referrerpolicy=no-referrer style="display:block;width:100%;min-height:0;flex:1 1 0%;border:0">');
7
7
  function Y(e) {
8
8
  return `<script>(()=>{
9
9
  const channel=new MessageChannel();
@@ -6,6 +6,8 @@ export type ImageAnnotationSurfaceProps = ImageDimensions & {
6
6
  onChange?: (annotation: ImageAnnotation) => void;
7
7
  disabled?: boolean;
8
8
  zoom?: number;
9
+ /** Drag the zoomed viewport without changing its annotation. */
10
+ panning?: boolean;
9
11
  showAnnotation?: boolean;
10
12
  class?: string;
11
13
  };
@@ -1,62 +1,79 @@
1
- import { use as H, insert as q, createComponent as N, effect as K, setAttribute as c, setStyleProperty as S, memo as G, className as J, template as U, delegateEvents as Q } from "solid-js/web";
2
- import { createSignal as O, createMemo as V, onMount as Z, onCleanup as _, Show as p, For as tt } from "solid-js";
3
- import { validateImageAnnotation as T, imagePointFromClient as et, imageAnnotationMarkup as it } from "./imageAnnotation.js";
4
- var nt = /* @__PURE__ */ U("<div data-floe-image-annotation style=width:100%;height:100%;overflow:auto;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>"), ot = /* @__PURE__ */ U("<svg><rect data-annotation-target fill=white stroke=#111827></svg>", !1, !0, !1);
5
- function dt(e) {
6
- let m, v;
7
- const [z, W] = O({
1
+ import { use as H, insert as G, createComponent as N, effect as q, setAttribute as l, setStyleProperty as S, memo as J, className as Q, template as U, delegateEvents as V } from "solid-js/web";
2
+ import { createSignal as K, createMemo as Z, onMount as _, onCleanup as p, Show as tt, For as it } from "solid-js";
3
+ import { validateImageAnnotation as O, imagePointFromClient as et, imageAnnotationMarkup as nt } from "./imageAnnotation.js";
4
+ var rt = /* @__PURE__ */ U("<div data-floe-image-annotation style=width:100%;height:100%;overflow:auto;scrollbar-gutter:stable;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>"), ot = /* @__PURE__ */ U("<svg><rect data-annotation-target fill=white stroke=#111827></svg>", !1, !0, !1);
5
+ function lt(e) {
6
+ let u, g;
7
+ const [z, W] = K({
8
8
  width: 1,
9
9
  height: 1
10
- }), [D, f] = O();
11
- let u;
12
- const E = () => D() ?? e.annotation, l = V(() => Math.min(z().width / e.width, z().height / e.height) * Math.max(1, e.zoom ?? 1)), $ = () => e.showAnnotation !== !1 && E() && T(e, E()) ? it(e, E()) : "";
13
- Z(() => {
14
- const i = new ResizeObserver(() => W({
15
- width: m.clientWidth,
16
- height: m.clientHeight
17
- }));
18
- i.observe(m), _(() => i.disconnect());
10
+ }), [E, y] = K();
11
+ let v, f;
12
+ const L = () => E() ?? e.annotation, w = Z(() => Math.min(z().width / e.width, z().height / e.height) * Math.max(1, e.zoom ?? 1)), $ = () => e.showAnnotation !== !1 && L() && O(e, L()) ? nt(e, L()) : "";
13
+ _(() => {
14
+ let i = 0;
15
+ const o = () => {
16
+ i = 0;
17
+ const r = u.clientWidth, c = u.clientHeight;
18
+ W((s) => s.width === r && s.height === c ? s : {
19
+ width: r,
20
+ height: c
21
+ });
22
+ }, n = new ResizeObserver(() => {
23
+ i || (i = requestAnimationFrame(o));
24
+ });
25
+ n.observe(u), o(), p(() => {
26
+ n.disconnect(), cancelAnimationFrame(i);
27
+ });
19
28
  });
20
- const L = (i, r = !1) => et(e, v.getBoundingClientRect(), {
29
+ const X = (i, o = !1) => et(e, g.getBoundingClientRect(), {
21
30
  x: i.clientX,
22
31
  y: i.clientY
23
- }, r), g = () => !!e.onChange && !e.disabled, B = (i) => {
24
- const r = u;
25
- if (!r || r.id !== i.pointerId || r.src !== e.src || !g()) return;
26
- const n = L(i, !0);
32
+ }, o), m = () => !!e.onChange && !e.disabled && !e.panning, Y = (i) => {
33
+ if (f?.id === i.pointerId) {
34
+ u.scrollLeft = f.left + f.x - i.clientX, u.scrollTop = f.top + f.y - i.clientY;
35
+ return;
36
+ }
37
+ const o = v;
38
+ if (!o || o.id !== i.pointerId || o.src !== e.src || !m()) return;
39
+ const n = X(i, !0);
27
40
  if (!n) return;
28
- const a = r.original;
29
- if (a && r.corner === void 0) {
30
- const s = a.kind === "rectangle" ? a.width : 0, w = a.kind === "rectangle" ? a.height : 0;
31
- f({
32
- ...a,
33
- x: Math.max(0, Math.min(e.width - s, a.x + n.x - r.start.x)),
34
- y: Math.max(0, Math.min(e.height - w, a.y + n.y - r.start.y))
41
+ const r = o.original;
42
+ if (r && o.corner === void 0) {
43
+ const c = r.kind === "rectangle" ? r.width : 0, s = r.kind === "rectangle" ? r.height : 0;
44
+ y({
45
+ ...r,
46
+ x: Math.max(0, Math.min(e.width - c, r.x + n.x - o.start.x)),
47
+ y: Math.max(0, Math.min(e.height - s, r.y + n.y - o.start.y))
35
48
  });
36
49
  } else {
37
- const s = a?.kind === "rectangle" && r.corner !== void 0 ? {
38
- x: a.x + (r.corner % 2 ? 0 : a.width),
39
- y: a.y + (r.corner < 2 ? a.height : 0)
40
- } : r.start, w = Math.abs(n.x - s.x), y = Math.abs(n.y - s.y);
41
- Math.hypot(i.clientX - r.client.x, i.clientY - r.client.y) < 5 && !a ? f({
50
+ const c = r?.kind === "rectangle" && o.corner !== void 0 ? {
51
+ x: r.x + (o.corner % 2 ? 0 : r.width),
52
+ y: r.y + (o.corner < 2 ? r.height : 0)
53
+ } : o.start, s = Math.abs(n.x - c.x), x = Math.abs(n.y - c.y);
54
+ Math.hypot(i.clientX - o.client.x, i.clientY - o.client.y) < 5 && !r ? y({
42
55
  kind: "point",
43
- ...s
44
- }) : w > 0 && y > 0 && f({
56
+ ...c
57
+ }) : s > 0 && x > 0 && y({
45
58
  kind: "rectangle",
46
- x: Math.min(s.x, n.x),
47
- y: Math.min(s.y, n.y),
48
- width: w,
49
- height: y
59
+ x: Math.min(c.x, n.x),
60
+ y: Math.min(c.y, n.y),
61
+ width: s,
62
+ height: x
50
63
  });
51
64
  }
52
- }, P = (i, r = !1) => {
53
- const n = u;
65
+ }, D = (i, o = !1) => {
66
+ if (f?.id === i.pointerId) {
67
+ f = void 0, g.hasPointerCapture(i.pointerId) && g.releasePointerCapture(i.pointerId);
68
+ return;
69
+ }
70
+ const n = v;
54
71
  if (!n || n.id !== i.pointerId) return;
55
- r || B(i);
56
- const a = D();
57
- u = void 0, f(void 0), v.hasPointerCapture(i.pointerId) && v.releasePointerCapture(i.pointerId), !r && n.src === e.src && g() && a && T(e, a) && e.onChange?.(a);
72
+ o || Y(i);
73
+ const r = E();
74
+ v = void 0, y(void 0), g.hasPointerCapture(i.pointerId) && g.releasePointerCapture(i.pointerId), !o && n.src === e.src && m() && r && O(e, r) && e.onChange?.(r);
58
75
  }, j = () => {
59
- const i = E();
76
+ const i = L();
60
77
  return i?.kind === "rectangle" ? [{
61
78
  x: i.x,
62
79
  y: i.y
@@ -72,11 +89,11 @@ function dt(e) {
72
89
  }] : [];
73
90
  };
74
91
  return (() => {
75
- var i = nt(), r = i.firstChild, n = r.firstChild, a = n.firstChild, s = a.nextSibling, w = m;
76
- typeof w == "function" ? H(w, i) : m = i, n.$$keydown = (t) => {
77
- if (!g()) return;
92
+ var i = rt(), o = i.firstChild, n = o.firstChild, r = n.firstChild, c = r.nextSibling, s = u;
93
+ typeof s == "function" ? H(s, i) : u = i, n.$$keydown = (t) => {
94
+ if (!m()) return;
78
95
  if (t.key === "Escape") {
79
- u = void 0, f(void 0);
96
+ v = void 0, y(void 0);
80
97
  return;
81
98
  }
82
99
  const d = {
@@ -91,18 +108,28 @@ function dt(e) {
91
108
  kind: "point",
92
109
  x: e.width / 2,
93
110
  y: e.height / 2
94
- }, o = t.shiftKey ? 10 : 1;
111
+ }, a = t.shiftKey ? 10 : 1;
95
112
  e.onChange?.({
96
113
  ...h,
97
- x: Math.max(0, Math.min(e.width - (h.kind === "rectangle" ? h.width : 0), h.x + (d?.[0] ?? 0) * o)),
98
- y: Math.max(0, Math.min(e.height - (h.kind === "rectangle" ? h.height : 0), h.y + (d?.[1] ?? 0) * o))
114
+ x: Math.max(0, Math.min(e.width - (h.kind === "rectangle" ? h.width : 0), h.x + (d?.[0] ?? 0) * a)),
115
+ y: Math.max(0, Math.min(e.height - (h.kind === "rectangle" ? h.height : 0), h.y + (d?.[1] ?? 0) * a))
99
116
  });
100
- }, n.addEventListener("lostpointercapture", (t) => P(t, !0)), n.addEventListener("pointercancel", (t) => P(t, !0)), n.$$pointerup = (t) => P(t), n.$$pointermove = B, n.$$pointerdown = (t) => {
101
- if (!g() || t.button !== 0 || u) return;
102
- const d = L(t);
117
+ }, n.addEventListener("lostpointercapture", (t) => D(t, !0)), n.addEventListener("pointercancel", (t) => D(t, !0)), n.$$pointerup = (t) => D(t), n.$$pointermove = Y, n.$$pointerdown = (t) => {
118
+ if (e.panning && t.button === 0 && !f) {
119
+ f = {
120
+ id: t.pointerId,
121
+ x: t.clientX,
122
+ y: t.clientY,
123
+ left: u.scrollLeft,
124
+ top: u.scrollTop
125
+ }, g.setPointerCapture(t.pointerId), t.preventDefault();
126
+ return;
127
+ }
128
+ if (!m() || t.button !== 0 || v) return;
129
+ const d = X(t);
103
130
  if (!d) return;
104
- const h = t.target, o = h.getAttribute("data-corner");
105
- u = {
131
+ const h = t.target, a = h.getAttribute("data-corner");
132
+ v = {
106
133
  id: t.pointerId,
107
134
  start: d,
108
135
  client: {
@@ -113,31 +140,31 @@ function dt(e) {
113
140
  ...h.closest("[data-annotation-target]") ? {
114
141
  original: e.annotation
115
142
  } : {},
116
- ...o !== null ? {
117
- corner: Number(o)
143
+ ...a !== null ? {
144
+ corner: Number(a)
118
145
  } : {}
119
- }, f(u.original ?? {
146
+ }, y(v.original ?? {
120
147
  kind: "point",
121
148
  ...d
122
- }), v.setPointerCapture(t.pointerId), v.focus({
149
+ }), g.setPointerCapture(t.pointerId), g.focus({
123
150
  preventScroll: !0
124
151
  }), t.preventDefault();
125
152
  };
126
- var y = v;
127
- return typeof y == "function" ? H(y, n) : v = n, q(n, N(p, {
153
+ var x = g;
154
+ return typeof x == "function" ? H(x, n) : g = n, G(n, N(tt, {
128
155
  get when() {
129
- return G(() => !!g())() && e.showAnnotation !== !1;
156
+ return J(() => !!m())() && e.showAnnotation !== !1;
130
157
  },
131
158
  get children() {
132
- return N(tt, {
159
+ return N(it, {
133
160
  get each() {
134
161
  return j();
135
162
  },
136
163
  children: (t, d) => (() => {
137
164
  var h = ot();
138
- return K((o) => {
139
- var x = d(), k = t.x - 5 / l(), M = t.y - 5 / l(), b = 10 / l(), C = 10 / l(), A = 1 / l(), I = d() === 0 || d() === 3 ? "nwse-resize" : "nesw-resize";
140
- return x !== o.e && c(h, "data-corner", o.e = x), k !== o.t && c(h, "x", o.t = k), M !== o.a && c(h, "y", o.a = M), b !== o.o && c(h, "width", o.o = b), C !== o.i && c(h, "height", o.i = C), A !== o.n && c(h, "stroke-width", o.n = A), I !== o.s && S(h, "cursor", o.s = I), o;
165
+ return q((a) => {
166
+ var b = d(), k = t.x - 5 / w(), M = t.y - 5 / w(), C = 10 / w(), I = 10 / w(), A = 1 / w(), P = d() === 0 || d() === 3 ? "nwse-resize" : "nesw-resize";
167
+ return b !== a.e && l(h, "data-corner", a.e = b), k !== a.t && l(h, "x", a.t = k), M !== a.a && l(h, "y", a.a = M), C !== a.o && l(h, "width", a.o = C), I !== a.i && l(h, "height", a.i = I), A !== a.n && l(h, "stroke-width", a.n = A), P !== a.s && S(h, "cursor", a.s = P), a;
141
168
  }, {
142
169
  e: void 0,
143
170
  t: void 0,
@@ -150,9 +177,9 @@ function dt(e) {
150
177
  })()
151
178
  });
152
179
  }
153
- }), null), K((t) => {
154
- var d = e.class, h = `${Math.max(z().width, e.width * l())}px`, o = `${Math.max(z().height, e.height * l())}px`, x = e.width * l(), k = e.height * l(), M = `0 0 ${e.width} ${e.height}`, b = e.label, C = g() ? 0 : void 0, A = g() ? "none" : "auto", I = g() ? "crosshair" : "default", R = e.src, X = e.width, Y = e.height, F = $();
155
- return d !== t.e && J(i, t.e = d), h !== t.t && S(r, "width", t.t = h), o !== t.a && S(r, "height", t.a = o), x !== t.o && c(n, "width", t.o = x), k !== t.i && c(n, "height", t.i = k), M !== t.n && c(n, "viewBox", t.n = M), b !== t.s && c(n, "aria-label", t.s = b), C !== t.h && c(n, "tabindex", t.h = C), A !== t.r && S(n, "touch-action", t.r = A), I !== t.d && S(n, "cursor", t.d = I), R !== t.l && c(a, "href", t.l = R), X !== t.u && c(a, "width", t.u = X), Y !== t.c && c(a, "height", t.c = Y), F !== t.w && (s.innerHTML = t.w = F), t;
180
+ }), null), q((t) => {
181
+ var d = e.class, h = `${Math.max(z().width, e.width * w())}px`, a = `${Math.max(z().height, e.height * w())}px`, b = e.width * w(), k = e.height * w(), M = `0 0 ${e.width} ${e.height}`, C = e.label, I = m() ? 0 : void 0, A = m() || e.panning ? "none" : "auto", P = e.panning ? "grab" : m() ? "crosshair" : "default", F = e.src, B = e.width, R = e.height, T = $();
182
+ return d !== t.e && Q(i, t.e = d), h !== t.t && S(o, "width", t.t = h), a !== t.a && S(o, "height", t.a = a), b !== t.o && l(n, "width", t.o = b), k !== t.i && l(n, "height", t.i = k), M !== t.n && l(n, "viewBox", t.n = M), C !== t.s && l(n, "aria-label", t.s = C), I !== t.h && l(n, "tabindex", t.h = I), A !== t.r && S(n, "touch-action", t.r = A), P !== t.d && S(n, "cursor", t.d = P), F !== t.l && l(r, "href", t.l = F), B !== t.u && l(r, "width", t.u = B), R !== t.c && l(r, "height", t.c = R), T !== t.w && (c.innerHTML = t.w = T), t;
156
183
  }, {
157
184
  e: void 0,
158
185
  t: void 0,
@@ -171,7 +198,7 @@ function dt(e) {
171
198
  }), i;
172
199
  })();
173
200
  }
174
- Q(["pointerdown", "pointermove", "pointerup", "keydown"]);
201
+ V(["pointerdown", "pointermove", "pointerup", "keydown"]);
175
202
  export {
176
- dt as ImageAnnotationSurface
203
+ lt as ImageAnnotationSurface
177
204
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.101.20",
3
+ "version": "0.101.23",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",