@floegence/floe-webapp-core 0.101.45 → 0.101.46

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,40 +1,40 @@
1
- function g(i, e) {
2
- return ![i.width, i.height].every((r) => Number.isSafeInteger(r) && r > 0 && r <= 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((r) => Number.isFinite(r) && r > 0) && e.x + e.width <= i.width && e.y + e.height <= i.height;
1
+ function $(i, t) {
2
+ return ![i.width, i.height].every((h) => Number.isSafeInteger(h) && h > 0 && h <= 16384) || !t || ![t.x, t.y].every(Number.isFinite) || t.x < 0 || t.y < 0 || t.x > i.width || t.y > i.height ? !1 : t.kind === "point" ? !0 : t.kind === "rectangle" && [t.width, t.height].every((h) => Number.isFinite(h) && h > 0) && t.x + t.width <= i.width && t.y + t.height <= i.height;
3
3
  }
4
- function m(i, e, r, t = !1) {
5
- if (e.width <= 0 || e.height <= 0) return;
6
- const h = (r.x - e.left) * i.width / e.width, n = (r.y - e.top) * i.height / e.height;
7
- if (!(![h, n].every(Number.isFinite) || !t && (h < 0 || n < 0 || h > i.width || n > i.height)))
8
- return { x: Math.max(0, Math.min(i.width, h)), y: Math.max(0, Math.min(i.height, n)) };
4
+ function m(i, t, h, e = !1) {
5
+ if (t.width <= 0 || t.height <= 0) return;
6
+ const r = (h.x - t.left) * i.width / t.width, n = (h.y - t.top) * i.height / t.height;
7
+ if (!(![r, n].every(Number.isFinite) || !e && (r < 0 || n < 0 || r > i.width || n > i.height)))
8
+ return { x: Math.max(0, Math.min(i.width, r)), y: Math.max(0, Math.min(i.height, n)) };
9
9
  }
10
- function $(i, e, r = 1) {
11
- if (!Number.isSafeInteger(r) || r < 1 || r > 99) throw new Error("Invalid annotation marker");
12
- if (!g(i, e)) throw new Error("Invalid image annotation");
13
- const t = Math.max(1, Math.min(i.width, i.height) / 500), { x: h, y: n } = e, a = 9 * t, l = Math.max(a + t, Math.min(i.width - a - t, h + 17 * t)), s = Math.max(a + t, Math.min(i.height - a - t, n - 17 * t)), o = e.kind === "rectangle" ? `<rect x="${h}" y="${n}" width="${e.width}" height="${e.height}" fill="#f59e0b" fill-opacity=".08"/>` : `<path d="M${h - 6 * t},${n}h${12 * t}M${h},${n - 6 * t}v${12 * t}"/><circle cx="${h}" cy="${n}" r="${2 * t}" fill="#f59e0b"/>`;
14
- return `<g fill="none" stroke-linejoin="round"><g stroke="#111827" stroke-width="${4 * t}">${o}</g><g stroke="#fbbf24" stroke-width="${2 * t}">${o}<path d="M${h},${n}L${l},${s}"/></g><circle data-annotation-marker="" pointer-events="all" cx="${l}" cy="${s}" r="${a}" fill="#fbbf24" stroke="#111827" stroke-width="${t}"/><text data-annotation-marker="" pointer-events="all" x="${l}" y="${s}" dy=".35em" text-anchor="middle" fill="#111827" stroke="none" font-family="sans-serif" font-size="${12 * t}" font-weight="700">${r}</text></g>`;
10
+ function f(i, t, h = 1) {
11
+ if (!Number.isSafeInteger(h) || h < 1 || h > 99) throw new Error("Invalid annotation marker");
12
+ if (!$(i, t)) throw new Error("Invalid image annotation");
13
+ const e = Math.max(1, Math.min(i.width, i.height) / 800), { x: r, y: n } = t, s = 11 * e, o = Math.max(s + e, Math.min(i.width - s - e, r + s)), w = Math.max(s + e, Math.min(i.height - s - e, n - s - 3 * e)), a = t.kind === "rectangle" ? `<rect x="${r}" y="${n}" width="${t.width}" height="${t.height}"/>` : `<path d="M${r - 5 * e},${n}h${10 * e}M${r},${n - 5 * e}v${10 * e}"/>`;
14
+ return `<g fill="none" stroke-linejoin="round">${t.kind === "rectangle" ? `<rect x="${r}" y="${n}" width="${t.width}" height="${t.height}" fill="#2563eb" fill-opacity=".035"/>` : ""}<g stroke="white" stroke-opacity=".9" stroke-width="${3.5 * e}">${a}</g><g stroke="#2563eb" stroke-width="${1.5 * e}">${a}<path d="M${r},${n}L${o},${w}"/></g><rect data-annotation-marker="" pointer-events="all" x="${o - s}" y="${w - s}" width="${2 * s}" height="${2 * s}" rx="${7 * e}" fill="#2563eb" stroke="white" stroke-width="${1.5 * e}"/><text data-annotation-marker="" pointer-events="all" x="${o}" y="${w}" dy=".35em" text-anchor="middle" fill="white" stroke="none" font-family="system-ui, sans-serif" font-size="${11 * e}" font-weight="600">${h}</text></g>`;
15
15
  }
16
- async function x(i, e) {
17
- const r = await createImageBitmap(i);
18
- let t;
16
+ async function x(i, t) {
17
+ const h = await createImageBitmap(i);
18
+ let e;
19
19
  try {
20
- const { width: h, height: n } = r;
21
- if (h * n > 32e6) throw new Error("Image exceeds annotation pixel limit");
22
- const a = Array.isArray(e) ? e : [e];
23
- if (!a.length || a.length > 99) throw new Error("Invalid annotation count");
24
- const l = a.map((d, c) => $({ width: h, height: n }, d, c + 1)).join(""), s = document.createElement("canvas");
25
- s.width = h, s.height = n;
26
- const o = s.getContext("2d");
27
- if (!o) throw new Error("Image annotation is unavailable");
28
- o.drawImage(r, 0, 0), t = URL.createObjectURL(new Blob([`<svg xmlns="http://www.w3.org/2000/svg" width="${h}" height="${n}" viewBox="0 0 ${h} ${n}">${l}</svg>`], { type: "image/svg+xml" }));
29
- const w = new Image();
30
- return w.src = t, await w.decode(), o.drawImage(w, 0, 0), await new Promise((d, c) => s.toBlob((f) => f ? d(f) : c(new Error("Image annotation is unavailable")), "image/png"));
20
+ const { width: r, height: n } = h;
21
+ if (r * n > 32e6) throw new Error("Image exceeds annotation pixel limit");
22
+ const s = Array.isArray(t) ? t : [t];
23
+ if (!s.length || s.length > 99) throw new Error("Invalid annotation count");
24
+ const o = s.map((l, g) => f({ width: r, height: n }, l, g + 1)).join(""), w = document.createElement("canvas");
25
+ w.width = r, w.height = n;
26
+ const a = w.getContext("2d");
27
+ if (!a) throw new Error("Image annotation is unavailable");
28
+ a.drawImage(h, 0, 0), e = URL.createObjectURL(new Blob([`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${n}" viewBox="0 0 ${r} ${n}">${o}</svg>`], { type: "image/svg+xml" }));
29
+ const d = new Image();
30
+ return d.src = e, await d.decode(), a.drawImage(d, 0, 0), await new Promise((l, g) => w.toBlob((c) => c ? l(c) : g(new Error("Image annotation is unavailable")), "image/png"));
31
31
  } finally {
32
- r.close(), t && URL.revokeObjectURL(t);
32
+ h.close(), e && URL.revokeObjectURL(e);
33
33
  }
34
34
  }
35
35
  export {
36
36
  x as annotateImage,
37
- $ as imageAnnotationMarkup,
37
+ f as imageAnnotationMarkup,
38
38
  m as imagePointFromClient,
39
- g as validateImageAnnotation
39
+ $ as validateImageAnnotation
40
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.101.45",
3
+ "version": "0.101.46",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",