@floegence/floe-webapp-core 0.101.17 → 0.101.20

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.
@@ -22,6 +22,7 @@ export interface MarkdownMediaLabels {
22
22
  previewHTMLWindow?: string;
23
23
  linkUnavailable?: string;
24
24
  anchorUnavailable?: string;
25
+ pointerLocked?: string;
25
26
  loading: string;
26
27
  unavailable: string;
27
28
  retry: string;
@@ -58,6 +58,7 @@ const Fe = (e) => {
58
58
  const a = e.onOpenLink, i = B();
59
59
  return a ? (r, t) => a(i, r, t) : void 0;
60
60
  }, G = () => ({
61
+ pointerLocked: e.labels.pointerLocked,
61
62
  linkUnavailable: e.labels.linkUnavailable ?? "Opening links is unavailable in this preview.",
62
63
  anchorUnavailable: e.labels.anchorUnavailable ?? "The linked section was not found."
63
64
  });
@@ -2,6 +2,7 @@ import { type JSX } from 'solid-js';
2
2
  export interface SandboxedHtmlFrameLabels {
3
3
  linkUnavailable: string;
4
4
  anchorUnavailable: string;
5
+ pointerLocked?: string;
5
6
  }
6
7
  export interface SandboxedHtmlSearch {
7
8
  search: (query: string, direction?: -1 | 0 | 1) => void;
@@ -19,7 +20,7 @@ export interface SandboxedHtmlFrameProps {
19
20
  class?: string;
20
21
  style?: JSX.CSSProperties;
21
22
  inert?: boolean;
22
- /** Deactivation pauses native media without restarting it on reactivation. */
23
+ /** Deactivation pauses native media and releases pointer lock; neither resumes automatically. */
23
24
  active?: boolean;
24
25
  /** Localized presentation while this exact document loads and reaches a render opportunity. */
25
26
  renderPending?: () => JSX.Element;
@@ -1,18 +1,38 @@
1
- import { insert as v, createComponent as M, effect as A, setAttribute as f, className as N, style as P, template as S, use as Q } from "solid-js/web";
2
- import { createSignal as w, createMemo as U, createEffect as k, untrack as B, onCleanup as I, onMount as D, Show as H } from "solid-js";
1
+ import { insert as h, createComponent as x, effect as D, setAttribute as v, className as N, style as Q, template as p, use as U } from "solid-js/web";
2
+ import { createSignal as g, createMemo as $, createEffect as T, untrack as j, onCleanup as I, onMount as B, Show as S } from "solid-js";
3
3
  import { sandboxedMarkdownHtml as K } from "../chat/markdown/media.js";
4
- import { findTextRanges as W } from "../ui/textSearch.js";
5
- import { secureRandomUUID as $ } from "../../utils/secureRandom.js";
6
- var j = /* @__PURE__ */ S('<span data-floe-html-pending style="position:absolute;inset:0;z-index:1;background:var(--background, Canvas)">'), z = /* @__PURE__ */ S('<span role=alert class="max-h-24 shrink-0 overflow-auto break-words bg-background px-3 py-2 text-xs text-destructive">'), J = /* @__PURE__ */ S('<span class="relative flex h-full min-h-0 w-full flex-col"><iframe sandbox=allow-scripts referrerpolicy=no-referrer style="display:block;width:100%;min-height:0;flex:1 1 0%;border:0">');
7
- function V(e) {
4
+ import { findTextRanges as _ } from "../ui/textSearch.js";
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">');
7
+ function Y(e) {
8
8
  return `<script>(()=>{
9
9
  const channel=new MessageChannel();
10
10
  const publish=channel.port1.postMessage.bind(channel.port1);
11
11
  const query=document.querySelectorAll.bind(document);
12
12
  const MediaElementType=HTMLMediaElement;
13
13
  const pause=Function.call.bind(MediaElementType.prototype.pause);
14
+ const lockGetter=Object.getOwnPropertyDescriptor(Document.prototype,'pointerLockElement')?.get;
15
+ const locked=lockGetter?Function.call.bind(lockGetter,document):()=>null;
16
+ const exitLock=document.exitPointerLock?.bind(document);
17
+ const hasFocus=document.hasFocus.bind(document);
18
+ let pointerLockAllowed=false,pointerGesture=false;
19
+ const releaseLock=()=>{pointerGesture=false;if(locked())exitLock()};
20
+ window.addEventListener('blur',releaseLock);
21
+ document.addEventListener('visibilitychange',()=>{if(document.hidden)releaseLock()});
22
+ const gesture=event=>{if(event.isTrusted&&pointerLockAllowed)pointerGesture=true};
23
+ window.addEventListener('pointerdown',gesture,true);
24
+ window.addEventListener('keydown',event=>{
25
+ if(event.isTrusted&&event.key==='Escape'&&locked()){event.preventDefault();event.stopImmediatePropagation();releaseLock();return}
26
+ if(event.key==='Enter'||event.key===' ')gesture(event);
27
+ },true);
28
+ document.addEventListener('pointerlockchange',()=>{
29
+ const value=!!locked();
30
+ if(value&&(!pointerLockAllowed||!pointerGesture||!hasFocus()||document.hidden)){releaseLock();return}
31
+ pointerGesture=false;
32
+ publish({type:'pointer-lock',locked:value});
33
+ });
14
34
  let active=true,searchEnabled=false,searchOpen=false,searchQuery='',matches=[],matchIndex=0;
15
- const findRanges=(${W.toString()});
35
+ const findRanges=(${_.toString()});
16
36
  const clearHighlights=()=>{CSS.highlights?.delete('floe-html-find');CSS.highlights?.delete('floe-html-find-current')};
17
37
  const paint=()=>{
18
38
  clearHighlights();
@@ -38,6 +58,8 @@ function V(e) {
38
58
  if(event.data?.type==='clear-search'){searchOpen=false;clearHighlights();return}
39
59
  if(event.data?.type!=='activation')return;
40
60
  active=event.data.active===true;searchEnabled=event.data.searchEnabled===true;
61
+ pointerLockAllowed=event.data.pointerLockAllowed===true;
62
+ if(!pointerLockAllowed)releaseLock();
41
63
  paint();
42
64
  if(!active)for(const media of query('video,audio'))pause(media);
43
65
  };
@@ -86,52 +108,57 @@ function V(e) {
86
108
  parent.postMessage({type:'floe-html-ready',token:${JSON.stringify(e)}},'*',[channel.port2]);
87
109
  })()<\/script><style>::highlight(floe-html-find){background:#fde68a;color:#111}::highlight(floe-html-find-current){background:#2563eb;color:#fff}</style>`;
88
110
  }
89
- function ee(e) {
90
- let y, p;
91
- const [x, h] = w(""), [F, L] = w(""), [R, T] = w(), b = U(() => {
92
- const r = $();
111
+ function ae(e) {
112
+ let y, b;
113
+ const [C, f] = g(""), [A, k] = g(!1), [O, R] = g(""), [P, M] = g(), w = $(() => {
114
+ const a = z();
93
115
  return {
94
- token: r,
95
- html: K(V(r) + e.html)
116
+ token: a,
117
+ html: K(Y(a) + e.html)
96
118
  };
97
- }), o = () => F() === b().token;
98
- k(() => {
99
- const r = o() ? "ready" : "loading";
100
- B(() => e.onPresentationStateChange?.(r));
101
- }), k(() => {
102
- R()?.postMessage({
119
+ }), o = () => O() === w().token;
120
+ T(() => {
121
+ const a = o() ? "ready" : "loading";
122
+ j(() => e.onPresentationStateChange?.(a));
123
+ }), T(() => {
124
+ P()?.postMessage({
103
125
  type: "activation",
104
126
  active: e.active !== !1,
127
+ pointerLockAllowed: e.active !== !1 && !e.inert && o(),
105
128
  searchEnabled: !!e.onSearchRequest
106
129
  });
107
- }), k(() => {
130
+ }), T(() => {
108
131
  const {
109
- token: r
110
- } = b(), a = new AbortController();
111
- let i, t = 0, c = 0, u = !1, l = 0;
112
- h(""), p = (s) => {
113
- !s.isTrusted || s.source !== y.contentWindow || i || s.data?.type !== "floe-html-ready" || s.data?.token !== r || s.ports.length !== 1 || (i = s.ports[0], T(i), e.onSearchReady?.({
114
- search: (d, n = 0) => {
115
- a.signal.aborted || e.inert || e.active === !1 || !o() || i?.postMessage({
132
+ token: a
133
+ } = w(), r = new AbortController();
134
+ let i, t = 0, c = 0, m = !1, l = 0, d;
135
+ f(""), k(!1), b = (s) => {
136
+ !s.isTrusted || s.source !== y.contentWindow || i || s.data?.type !== "floe-html-ready" || s.data?.token !== a || s.ports.length !== 1 || (i = s.ports[0], M(i), e.onSearchReady?.({
137
+ search: (u, n = 0) => {
138
+ r.signal.aborted || e.inert || e.active === !1 || !o() || i?.postMessage({
116
139
  type: "search",
117
- query: d,
140
+ query: u,
118
141
  direction: n,
119
142
  request: ++l
120
143
  });
121
144
  },
122
145
  clear: () => {
123
- a.signal.aborted || (l++, i?.postMessage({
146
+ r.signal.aborted || (l++, i?.postMessage({
124
147
  type: "clear-search"
125
148
  }));
126
149
  }
127
- }), i.onmessage = (d) => {
128
- if (a.signal.aborted) return;
129
- const n = d.data;
150
+ }), i.onmessage = (u) => {
151
+ if (r.signal.aborted) return;
152
+ const n = u.data;
153
+ if (n?.type === "pointer-lock" && typeof n.locked == "boolean") {
154
+ clearTimeout(d), n.locked && (d = setTimeout(() => k(!1), 3e3)), k(n.locked && !e.inert && e.active !== !1 && o());
155
+ return;
156
+ }
130
157
  if (n?.type === "document-loaded") {
131
- if (u) return;
132
- u = !0, c = requestAnimationFrame(() => {
158
+ if (m) return;
159
+ m = !0, c = requestAnimationFrame(() => {
133
160
  c = requestAnimationFrame(() => {
134
- a.signal.aborted || L(r);
161
+ r.signal.aborted || R(a);
135
162
  });
136
163
  });
137
164
  return;
@@ -149,57 +176,65 @@ function ee(e) {
149
176
  return;
150
177
  }
151
178
  if (n?.type === "anchor-opened") {
152
- h("");
179
+ f("");
153
180
  return;
154
181
  }
155
182
  if (n?.type === "anchor-missing") {
156
- h(e.labels?.anchorUnavailable ?? "The linked section was not found.");
183
+ f(e.labels?.anchorUnavailable ?? "The linked section was not found.");
157
184
  return;
158
185
  }
159
186
  if (n?.type !== "open-link" || typeof n.href != "string" || n.href.length > 8192) return;
160
- const m = n.href, g = e.onOpenLink, q = e.labels?.linkUnavailable, O = ++t;
161
- h(""), Promise.resolve().then(() => {
162
- if (!a.signal.aborted) {
163
- if (!g) throw new Error(q ?? "Opening links is unavailable in this preview.");
164
- return g(m, a.signal);
187
+ const E = n.href, F = e.onOpenLink, H = e.labels?.linkUnavailable, G = ++t;
188
+ f(""), Promise.resolve().then(() => {
189
+ if (!r.signal.aborted) {
190
+ if (!F) throw new Error(H ?? "Opening links is unavailable in this preview.");
191
+ return F(E, r.signal);
165
192
  }
166
- }).catch((E) => {
167
- !a.signal.aborted && O === t && h(E instanceof Error && E.message ? E.message : q ?? "This link could not be opened.");
193
+ }).catch((L) => {
194
+ !r.signal.aborted && G === t && f(L instanceof Error && L.message ? L.message : H ?? "This link could not be opened.");
168
195
  });
169
196
  }, i.start());
170
197
  }, I(() => {
171
- a.abort(), cancelAnimationFrame(c), i?.close(), T(void 0), p = void 0, e.onSearchReady?.(void 0);
198
+ clearTimeout(d), r.abort(), cancelAnimationFrame(c), i?.close(), M(void 0), b = void 0, e.onSearchReady?.(void 0);
172
199
  });
173
200
  });
174
- const C = (r) => p?.(r);
175
- return D(() => {
176
- window.addEventListener("message", C), I(() => window.removeEventListener("message", C));
201
+ const q = (a) => b?.(a);
202
+ return B(() => {
203
+ window.addEventListener("message", q), I(() => window.removeEventListener("message", q));
177
204
  }), (() => {
178
- var r = J(), a = r.firstChild;
179
- v(r, M(H, {
205
+ var a = X(), r = a.firstChild;
206
+ h(a, x(S, {
180
207
  get when() {
181
208
  return !o();
182
209
  },
183
210
  get children() {
184
- var t = j();
185
- return v(t, () => e.renderPending?.()), t;
211
+ var t = W();
212
+ return h(t, () => e.renderPending?.()), t;
186
213
  }
187
- }), a);
214
+ }), r);
188
215
  var i = y;
189
- return typeof i == "function" ? Q(i, a) : y = a, v(r, M(H, {
216
+ return typeof i == "function" ? U(i, r) : y = r, h(a, x(S, {
217
+ get when() {
218
+ return A();
219
+ },
220
+ get children() {
221
+ var t = J(), c = t.firstChild;
222
+ return h(c, () => e.labels?.pointerLocked ?? "Mouse locked; press Esc to exit"), t;
223
+ }
224
+ }), null), h(a, x(S, {
190
225
  get when() {
191
- return x();
226
+ return C();
192
227
  },
193
228
  get children() {
194
- var t = z();
195
- return v(t, x), t;
229
+ var t = V();
230
+ return h(t, C), t;
196
231
  }
197
- }), null), A((t) => {
198
- var c = o() ? "ready" : "loading", u = !o(), l = e.class, s = e.title, d = b().html, n = e.inert || e.active === !1 || !o(), m = e.inert || e.active === !1 || !o() ? -1 : e.tabIndex, g = {
232
+ }), null), D((t) => {
233
+ var c = o() ? "ready" : "loading", m = !o(), l = e.class, d = e.title, s = w().html, u = e.inert || e.active === !1 || !o(), n = e.inert || e.active === !1 || !o() ? -1 : e.tabIndex, E = {
199
234
  ...e.style,
200
235
  opacity: o() ? void 0 : "0"
201
236
  };
202
- return c !== t.e && f(r, "data-floe-html-state", t.e = c), u !== t.t && f(r, "aria-busy", t.t = u), l !== t.a && N(a, t.a = l), s !== t.o && f(a, "title", t.o = s), d !== t.i && f(a, "srcdoc", t.i = d), n !== t.n && (a.inert = t.n = n), m !== t.s && f(a, "tabindex", t.s = m), t.h = P(a, g, t.h), t;
237
+ return c !== t.e && v(a, "data-floe-html-state", t.e = c), m !== t.t && v(a, "aria-busy", t.t = m), l !== t.a && N(r, t.a = l), d !== t.o && v(r, "title", t.o = d), s !== t.i && v(r, "srcdoc", t.i = s), u !== t.n && (r.inert = t.n = u), n !== t.s && v(r, "tabindex", t.s = n), t.h = Q(r, E, t.h), t;
203
238
  }, {
204
239
  e: void 0,
205
240
  t: void 0,
@@ -209,9 +244,9 @@ function ee(e) {
209
244
  n: void 0,
210
245
  s: void 0,
211
246
  h: void 0
212
- }), r;
247
+ }), a;
213
248
  })();
214
249
  }
215
250
  export {
216
- ee as SandboxedHtmlFrame
251
+ ae as SandboxedHtmlFrame
217
252
  };
@@ -0,0 +1,15 @@
1
+ import { type ImageAnnotation, type ImageDimensions } from './imageAnnotation';
2
+ export type ImageAnnotationSurfaceProps = ImageDimensions & {
3
+ src: string;
4
+ label: string;
5
+ annotation?: ImageAnnotation;
6
+ onChange?: (annotation: ImageAnnotation) => void;
7
+ disabled?: boolean;
8
+ zoom?: number;
9
+ showAnnotation?: boolean;
10
+ class?: string;
11
+ };
12
+ /** A contained immutable image. Click selects a point; drag selects a rectangle.
13
+ * Scroll pans at host-controlled zoom. No iframe access or capture is performed.
14
+ */
15
+ export declare function ImageAnnotationSurface(props: ImageAnnotationSurfaceProps): import("solid-js").JSX.Element;
@@ -0,0 +1,177 @@
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({
8
+ width: 1,
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());
19
+ });
20
+ const L = (i, r = !1) => et(e, v.getBoundingClientRect(), {
21
+ x: i.clientX,
22
+ 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);
27
+ 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))
35
+ });
36
+ } 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({
42
+ kind: "point",
43
+ ...s
44
+ }) : w > 0 && y > 0 && f({
45
+ kind: "rectangle",
46
+ x: Math.min(s.x, n.x),
47
+ y: Math.min(s.y, n.y),
48
+ width: w,
49
+ height: y
50
+ });
51
+ }
52
+ }, P = (i, r = !1) => {
53
+ const n = u;
54
+ 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);
58
+ }, j = () => {
59
+ const i = E();
60
+ return i?.kind === "rectangle" ? [{
61
+ x: i.x,
62
+ y: i.y
63
+ }, {
64
+ x: i.x + i.width,
65
+ y: i.y
66
+ }, {
67
+ x: i.x,
68
+ y: i.y + i.height
69
+ }, {
70
+ x: i.x + i.width,
71
+ y: i.y + i.height
72
+ }] : [];
73
+ };
74
+ 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;
78
+ if (t.key === "Escape") {
79
+ u = void 0, f(void 0);
80
+ return;
81
+ }
82
+ const d = {
83
+ ArrowLeft: [-1, 0],
84
+ ArrowRight: [1, 0],
85
+ ArrowUp: [0, -1],
86
+ ArrowDown: [0, 1]
87
+ }[t.key];
88
+ if (!d && t.key !== "Enter" && t.key !== " ") return;
89
+ t.preventDefault();
90
+ const h = e.annotation ?? {
91
+ kind: "point",
92
+ x: e.width / 2,
93
+ y: e.height / 2
94
+ }, o = t.shiftKey ? 10 : 1;
95
+ e.onChange?.({
96
+ ...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))
99
+ });
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);
103
+ if (!d) return;
104
+ const h = t.target, o = h.getAttribute("data-corner");
105
+ u = {
106
+ id: t.pointerId,
107
+ start: d,
108
+ client: {
109
+ x: t.clientX,
110
+ y: t.clientY
111
+ },
112
+ src: e.src,
113
+ ...h.closest("[data-annotation-target]") ? {
114
+ original: e.annotation
115
+ } : {},
116
+ ...o !== null ? {
117
+ corner: Number(o)
118
+ } : {}
119
+ }, f(u.original ?? {
120
+ kind: "point",
121
+ ...d
122
+ }), v.setPointerCapture(t.pointerId), v.focus({
123
+ preventScroll: !0
124
+ }), t.preventDefault();
125
+ };
126
+ var y = v;
127
+ return typeof y == "function" ? H(y, n) : v = n, q(n, N(p, {
128
+ get when() {
129
+ return G(() => !!g())() && e.showAnnotation !== !1;
130
+ },
131
+ get children() {
132
+ return N(tt, {
133
+ get each() {
134
+ return j();
135
+ },
136
+ children: (t, d) => (() => {
137
+ 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;
141
+ }, {
142
+ e: void 0,
143
+ t: void 0,
144
+ a: void 0,
145
+ o: void 0,
146
+ i: void 0,
147
+ n: void 0,
148
+ s: void 0
149
+ }), h;
150
+ })()
151
+ });
152
+ }
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;
156
+ }, {
157
+ e: void 0,
158
+ t: void 0,
159
+ a: void 0,
160
+ o: void 0,
161
+ i: void 0,
162
+ n: void 0,
163
+ s: void 0,
164
+ h: void 0,
165
+ r: void 0,
166
+ d: void 0,
167
+ l: void 0,
168
+ u: void 0,
169
+ c: void 0,
170
+ w: void 0
171
+ }), i;
172
+ })();
173
+ }
174
+ Q(["pointerdown", "pointermove", "pointerup", "keydown"]);
175
+ export {
176
+ dt as ImageAnnotationSurface
177
+ };
@@ -0,0 +1,31 @@
1
+ export type ImageDimensions = Readonly<{
2
+ width: number;
3
+ height: number;
4
+ }>;
5
+ export type ImagePoint = Readonly<{
6
+ x: number;
7
+ y: number;
8
+ }>;
9
+ /** Continuous original-image pixels, independent of CSS pixels and device scale. */
10
+ export type ImageAnnotation = Readonly<{
11
+ kind: 'point';
12
+ x: number;
13
+ y: number;
14
+ } | {
15
+ kind: 'rectangle';
16
+ x: number;
17
+ y: number;
18
+ width: number;
19
+ height: number;
20
+ }>;
21
+ export declare function validateImageAnnotation(image: ImageDimensions, annotation: ImageAnnotation): boolean;
22
+ /** Pass the image's rendered rectangle, excluding contain letterboxing. */
23
+ export declare function imagePointFromClient(image: ImageDimensions, rect: Readonly<{
24
+ left: number;
25
+ top: number;
26
+ width: number;
27
+ height: number;
28
+ }>, client: ImagePoint, clamp?: boolean): ImagePoint | undefined;
29
+ /** One deterministic overlay is used by the editor and exported/model-visible PNG. */
30
+ export declare function imageAnnotationMarkup(image: ImageDimensions, annotation: ImageAnnotation): string;
31
+ export declare function annotateImage(source: Blob, annotation: ImageAnnotation): Promise<Blob>;
@@ -0,0 +1,37 @@
1
+ function f(i, e) {
2
+ return ![i.width, i.height].every((t) => Number.isSafeInteger(t) && t > 0 && t <= 16384) || !e || ![e.x, e.y].every(Number.isFinite) || e.x < 0 || e.y < 0 || e.x > i.width || e.y > i.height ? !1 : e.kind === "point" ? !0 : e.kind === "rectangle" && [e.width, e.height].every((t) => Number.isFinite(t) && t > 0) && e.x + e.width <= i.width && e.y + e.height <= i.height;
3
+ }
4
+ function $(i, e, t, s = !1) {
5
+ if (e.width <= 0 || e.height <= 0) return;
6
+ const h = (t.x - e.left) * i.width / e.width, r = (t.y - e.top) * i.height / e.height;
7
+ if (!(![h, r].every(Number.isFinite) || !s && (h < 0 || r < 0 || h > i.width || r > i.height)))
8
+ return { x: Math.max(0, Math.min(i.width, h)), y: Math.max(0, Math.min(i.height, r)) };
9
+ }
10
+ function g(i, e) {
11
+ if (!f(i, e)) throw new Error("Invalid image annotation");
12
+ const t = Math.max(1, Math.min(i.width, i.height) / 500), { x: s, y: h } = e, r = 9 * t, w = Math.max(r + t, Math.min(i.width - r - t, s + 17 * t)), n = Math.max(r + t, Math.min(i.height - r - t, h - 17 * t)), l = e.kind === "rectangle" ? `<rect x="${s}" y="${h}" width="${e.width}" height="${e.height}" fill="#f59e0b" fill-opacity=".08"/>` : `<path d="M${s - 6 * t},${h}h${12 * t}M${s},${h - 6 * t}v${12 * t}"/><circle cx="${s}" cy="${h}" r="${2 * t}" fill="#f59e0b"/>`;
13
+ return `<g fill="none" stroke-linejoin="round"><g stroke="#111827" stroke-width="${4 * t}">${l}</g><g stroke="#fbbf24" stroke-width="${2 * t}">${l}<path d="M${s},${h}L${w},${n}"/></g><circle cx="${w}" cy="${n}" r="${r}" fill="#fbbf24" stroke="#111827" stroke-width="${t}"/><text x="${w}" y="${n}" dy=".35em" text-anchor="middle" fill="#111827" stroke="none" font-family="sans-serif" font-size="${12 * t}" font-weight="700">1</text></g>`;
14
+ }
15
+ async function x(i, e) {
16
+ const t = await createImageBitmap(i);
17
+ let s;
18
+ try {
19
+ const { width: h, height: r } = t;
20
+ if (h * r > 32e6) throw new Error("Image exceeds annotation pixel limit");
21
+ const w = g({ width: h, height: r }, e), n = document.createElement("canvas");
22
+ n.width = h, n.height = r;
23
+ const l = n.getContext("2d");
24
+ if (!l) throw new Error("Image annotation is unavailable");
25
+ l.drawImage(t, 0, 0), s = URL.createObjectURL(new Blob([`<svg xmlns="http://www.w3.org/2000/svg" width="${h}" height="${r}" viewBox="0 0 ${h} ${r}">${w}</svg>`], { type: "image/svg+xml" }));
26
+ const c = new Image();
27
+ return c.src = s, await c.decode(), l.drawImage(c, 0, 0), await new Promise((o, a) => n.toBlob((d) => d ? o(d) : a(new Error("Image annotation is unavailable")), "image/png"));
28
+ } finally {
29
+ t.close(), s && URL.revokeObjectURL(s);
30
+ }
31
+ }
32
+ export {
33
+ x as annotateImage,
34
+ g as imageAnnotationMarkup,
35
+ $ as imagePointFromClient,
36
+ f as validateImageAnnotation
37
+ };
@@ -0,0 +1,4 @@
1
+ export { ImageAnnotationSurface } from './components/media/ImageAnnotationSurface';
2
+ export type { ImageAnnotationSurfaceProps } from './components/media/ImageAnnotationSurface';
3
+ export { imagePointFromClient, validateImageAnnotation, imageAnnotationMarkup, annotateImage } from './components/media/imageAnnotation';
4
+ export type { ImageAnnotation, ImageDimensions, ImagePoint } from './components/media/imageAnnotation';
@@ -0,0 +1,9 @@
1
+ import { ImageAnnotationSurface as o } from "./components/media/ImageAnnotationSurface.js";
2
+ import { annotateImage as e, imageAnnotationMarkup as i, imagePointFromClient as m, validateImageAnnotation as r } from "./components/media/imageAnnotation.js";
3
+ export {
4
+ o as ImageAnnotationSurface,
5
+ e as annotateImage,
6
+ i as imageAnnotationMarkup,
7
+ m as imagePointFromClient,
8
+ r as validateImageAnnotation
9
+ };