@annotorious/svelte 3.0.0-rc.18 → 3.0.0-rc.2

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.
Files changed (36) hide show
  1. package/dist/annotorious-svelte.es.js +6 -17
  2. package/dist/annotorious-svelte.es.js.map +1 -1
  3. package/dist/annotorious-svelte.es10.js +2 -111
  4. package/dist/annotorious-svelte.es10.js.map +1 -1
  5. package/dist/annotorious-svelte.es11.js +4 -2
  6. package/dist/annotorious-svelte.es11.js.map +1 -1
  7. package/dist/annotorious-svelte.es2.js +25 -30
  8. package/dist/annotorious-svelte.es2.js.map +1 -1
  9. package/dist/annotorious-svelte.es3.js +106 -86
  10. package/dist/annotorious-svelte.es3.js.map +1 -1
  11. package/dist/annotorious-svelte.es4.js +100 -91
  12. package/dist/annotorious-svelte.es4.js.map +1 -1
  13. package/dist/annotorious-svelte.es5.js +304 -118
  14. package/dist/annotorious-svelte.es5.js.map +1 -1
  15. package/dist/annotorious-svelte.es6.js +7 -96
  16. package/dist/annotorious-svelte.es6.js.map +1 -1
  17. package/dist/annotorious-svelte.es7.js +2 -43
  18. package/dist/annotorious-svelte.es7.js.map +1 -1
  19. package/dist/annotorious-svelte.es8.js +20598 -21
  20. package/dist/annotorious-svelte.es8.js.map +1 -1
  21. package/dist/annotorious-svelte.es9.js +119 -23
  22. package/dist/annotorious-svelte.es9.js.map +1 -1
  23. package/dist/index.d.ts +2 -14
  24. package/dist/index.d.ts.map +1 -1
  25. package/package.json +11 -17
  26. package/src/index.ts +5 -72
  27. package/vite.config.js +0 -1
  28. package/dist/annotorious-svelte.es12.js +0 -5
  29. package/dist/annotorious-svelte.es12.js.map +0 -1
  30. package/dist/annotorious-svelte.es13.js +0 -123
  31. package/dist/annotorious-svelte.es13.js.map +0 -1
  32. package/dist/annotorious-svelte.es14.js +0 -2
  33. package/dist/annotorious-svelte.es14.js.map +0 -1
  34. package/dist/annotorious-svelte.es15.js +0 -59
  35. package/dist/annotorious-svelte.es15.js.map +0 -1
  36. /package/dist/{annotorious-svelte.css → style.css} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-svelte.es3.js","sources":["../../annotorious-core/dist/annotorious-core.es.js"],"sourcesContent":["var Y = Object.prototype.hasOwnProperty;\nfunction x(e, n) {\n var t, o;\n if (e === n)\n return !0;\n if (e && n && (t = e.constructor) === n.constructor) {\n if (t === Date)\n return e.getTime() === n.getTime();\n if (t === RegExp)\n return e.toString() === n.toString();\n if (t === Array) {\n if ((o = e.length) === n.length)\n for (; o-- && x(e[o], n[o]); )\n ;\n return o === -1;\n }\n if (!t || typeof e == \"object\") {\n o = 0;\n for (t in e)\n if (Y.call(e, t) && ++o && !Y.call(n, t) || !(t in n) || !x(e[t], n[t]))\n return !1;\n return Object.keys(n).length === o;\n }\n }\n return e !== e && n !== n;\n}\nfunction $() {\n}\nfunction W(e, n) {\n return e != e ? n == n : e !== n || e && typeof e == \"object\" || typeof e == \"function\";\n}\nconst k = [];\nfunction _(e, n = $) {\n let t;\n const o = /* @__PURE__ */ new Set();\n function i(b) {\n if (W(e, b) && (e = b, t)) {\n const w = !k.length;\n for (const u of o)\n u[1](), k.push(u, e);\n if (w) {\n for (let u = 0; u < k.length; u += 2)\n k[u][0](k[u + 1]);\n k.length = 0;\n }\n }\n }\n function p(b) {\n i(b(e));\n }\n function U(b, w = $) {\n const u = [b, w];\n return o.add(u), o.size === 1 && (t = n(i, p) || $), b(e), () => {\n o.delete(u), o.size === 0 && t && (t(), t = null);\n };\n }\n return { set: i, update: p, subscribe: U };\n}\nconst be = (e) => {\n const { subscribe: n, set: t } = _();\n let o;\n return n((i) => o = i), e.observe(({ changes: i }) => {\n if (o) {\n (i.deleted || []).some((b) => b.id === o) && t(void 0);\n const U = (i.updated || []).find(({ oldValue: b }) => b.id === o);\n U && t(U.newValue.id);\n }\n }), {\n get current() {\n return o;\n },\n subscribe: n,\n set: t\n };\n};\nvar q = /* @__PURE__ */ ((e) => (e.EDIT = \"EDIT\", e.SELECT = \"SELECT\", e.NONE = \"NONE\", e))(q || {});\nconst V = { selected: [] }, ve = (e, n = \"EDIT\") => {\n const { subscribe: t, set: o } = _(V);\n let i = V;\n t((s) => i = s);\n const p = () => o(V), U = () => {\n var s;\n return ((s = i.selected) == null ? void 0 : s.length) === 0;\n }, b = (s) => {\n if (i.selected.length === 0)\n return !1;\n const g = typeof s == \"string\" ? s : s.id;\n return i.selected.some((y) => y.id === g);\n }, w = (s, g) => {\n const y = e.getAnnotation(s);\n if (y) {\n const A = G(y, n);\n o(A === \"EDIT\" ? { selected: [{ id: s, editable: !0 }], pointerEvent: g } : A === \"SELECT\" ? { selected: [{ id: s }], pointerEvent: g } : { selected: [], pointerEvent: g });\n } else\n console.warn(\"Invalid selection: \" + s);\n }, u = (s, g = !0) => {\n const y = Array.isArray(s) ? s : [s], A = y.map((O) => e.getAnnotation(O)).filter(Boolean);\n o({ selected: A.map(({ id: O }) => ({ id: O, editable: g })) }), A.length !== y.length && console.warn(\"Invalid selection\", s);\n }, S = (s) => {\n if (i.selected.length === 0)\n return !1;\n const { selected: g } = i;\n g.filter(({ id: A }) => s.includes(A)).length > 0 && o({ selected: g.filter(({ id: A }) => !s.includes(A)) });\n };\n return e.observe(({ changes: s }) => S((s.deleted || []).map((g) => g.id))), {\n clear: p,\n clickSelect: w,\n get selected() {\n return i ? [...i.selected] : null;\n },\n get pointerEvent() {\n return i ? i.pointerEvent : null;\n },\n isEmpty: U,\n isSelected: b,\n setSelected: u,\n subscribe: t\n };\n}, G = (e, n) => typeof n == \"function\" ? n(e) || \"EDIT\" : n || \"EDIT\";\nlet z;\nconst H = new Uint8Array(16);\nfunction F() {\n if (!z && (z = typeof crypto < \"u\" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !z))\n throw new Error(\"crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported\");\n return z(H);\n}\nconst R = [];\nfor (let e = 0; e < 256; ++e)\n R.push((e + 256).toString(16).slice(1));\nfunction J(e, n = 0) {\n return R[e[n + 0]] + R[e[n + 1]] + R[e[n + 2]] + R[e[n + 3]] + \"-\" + R[e[n + 4]] + R[e[n + 5]] + \"-\" + R[e[n + 6]] + R[e[n + 7]] + \"-\" + R[e[n + 8]] + R[e[n + 9]] + \"-\" + R[e[n + 10]] + R[e[n + 11]] + R[e[n + 12]] + R[e[n + 13]] + R[e[n + 14]] + R[e[n + 15]];\n}\nconst Q = typeof crypto < \"u\" && crypto.randomUUID && crypto.randomUUID.bind(crypto), j = {\n randomUUID: Q\n};\nfunction X(e, n, t) {\n if (j.randomUUID && !n && !e)\n return j.randomUUID();\n e = e || {};\n const o = e.random || (e.rng || F)();\n if (o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, n) {\n t = t || 0;\n for (let i = 0; i < 16; ++i)\n n[t + i] = o[i];\n return n;\n }\n return J(o);\n}\nconst Ce = (e) => {\n const { creator: n, updatedBy: t } = e.target, o = e.bodies.reduce((i, p) => [...i, p.creator, p.updatedBy].filter(Boolean), []);\n return [\n n,\n t,\n ...o\n ].filter((i) => i);\n}, we = (e, n, t, o) => ({\n id: X(),\n annotation: e.id,\n created: t || /* @__PURE__ */ new Date(),\n creator: o,\n ...n\n}), Z = (e, n) => {\n const t = new Set(e.bodies.map((o) => o.id));\n return n.bodies.filter((o) => !t.has(o.id));\n}, K = (e, n) => {\n const t = new Set(n.bodies.map((o) => o.id));\n return e.bodies.filter((o) => !t.has(o.id));\n}, ee = (e, n) => n.bodies.map((t) => {\n const o = e.bodies.find((i) => i.id === t.id);\n return { newBody: t, oldBody: o && !x(o, t) ? o : void 0 };\n}).filter(({ oldBody: t }) => t).map(({ oldBody: t, newBody: o }) => ({ oldBody: t, newBody: o })), te = (e, n) => !x(e.target, n.target), M = (e, n) => {\n const t = Z(e, n), o = K(e, n), i = ee(e, n);\n return {\n oldValue: e,\n newValue: n,\n bodiesCreated: t.length > 0 ? t : void 0,\n bodiesDeleted: o.length > 0 ? o : void 0,\n bodiesUpdated: i.length > 0 ? i : void 0,\n targetUpdated: te(e, n) ? { oldTarget: e.target, newTarget: n.target } : void 0\n };\n};\nvar ne = /* @__PURE__ */ ((e) => (e.BODY_ONLY = \"BODY_ONLY\", e.TARGET_ONLY = \"TARGET_ONLY\", e))(ne || {}), T = /* @__PURE__ */ ((e) => (e.LOCAL = \"LOCAL\", e.REMOTE = \"REMOTE\", e))(T || {});\nconst oe = (e, n) => {\n var p, U;\n const { changes: t, origin: o } = n;\n if (!(!e.options.origin || e.options.origin === o))\n return !1;\n if (e.options.ignore) {\n const { ignore: b } = e.options, w = (S) => S && S.length > 0;\n if (!(w(t.created) || w(t.deleted))) {\n const S = (p = t.updated) == null ? void 0 : p.some((g) => w(g.bodiesCreated) || w(g.bodiesDeleted) || w(g.bodiesUpdated)), s = (U = t.updated) == null ? void 0 : U.some((g) => g.targetUpdated);\n if (b === \"BODY_ONLY\" && S && !s || b === \"TARGET_ONLY\" && s && !S)\n return !1;\n }\n }\n if (e.options.annotations) {\n const b = /* @__PURE__ */ new Set([\n ...(t.created || []).map((u) => u.id),\n ...(t.deleted || []).map((u) => u.id),\n ...(t.updated || []).map(({ oldValue: u }) => u.id)\n ]);\n return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((u) => b.has(u));\n } else\n return !0;\n}, se = (e, n) => {\n const t = new Set((e.created || []).map((s) => s.id)), o = new Set((e.updated || []).map(({ newValue: s }) => s.id)), i = new Set((n.created || []).map((s) => s.id)), p = new Set((n.deleted || []).map((s) => s.id)), U = new Set((n.updated || []).map(({ oldValue: s }) => s.id)), b = new Set((n.updated || []).filter(({ oldValue: s }) => t.has(s.id) || o.has(s.id)).map(({ oldValue: s }) => s.id)), w = [\n ...(e.created || []).filter((s) => !p.has(s.id)).map((s) => U.has(s.id) ? n.updated.find(({ oldValue: g }) => g.id === s.id).newValue : s),\n ...n.created || []\n ], u = [\n ...(e.deleted || []).filter((s) => !i.has(s.id)),\n ...(n.deleted || []).filter((s) => !t.has(s.id))\n ], S = [\n ...(e.updated || []).filter(({ newValue: s }) => !p.has(s.id)).map((s) => {\n const { oldValue: g, newValue: y } = s;\n if (U.has(y.id)) {\n const A = n.updated.find((O) => O.oldValue.id === y.id).newValue;\n return M(g, A);\n } else\n return s;\n }),\n ...(n.updated || []).filter(({ oldValue: s }) => !b.has(s.id))\n ];\n return { created: w, deleted: u, updated: S };\n}, ie = (e) => e.id !== void 0, ye = () => {\n const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = [], o = (d, l = {}) => t.push({ onChange: d, options: l }), i = (d) => {\n const l = t.findIndex((c) => c.onChange == d);\n l > -1 && t.splice(l, 1);\n }, p = (d, l) => {\n const c = {\n origin: d,\n changes: {\n created: l.created || [],\n updated: l.updated || [],\n deleted: l.deleted || []\n },\n state: [...e.values()]\n };\n t.forEach((f) => {\n oe(f, c) && f.onChange(c);\n });\n }, U = (d, l = T.LOCAL) => {\n if (e.get(d.id))\n throw Error(`Cannot add annotation ${d.id} - exists already`);\n e.set(d.id, d), d.bodies.forEach((f) => n.set(f.id, d.id)), p(l, { created: [d] });\n }, b = (d, l) => {\n const c = typeof d == \"string\" ? l : d, f = typeof d == \"string\" ? d : d.id, v = e.get(f);\n if (v) {\n const D = M(v, c);\n return f === c.id ? e.set(f, c) : (e.delete(f), e.set(c.id, c)), v.bodies.forEach((B) => n.delete(B.id)), c.bodies.forEach((B) => n.set(B.id, c.id)), D;\n } else\n console.warn(`Cannot update annotation ${f} - does not exist`);\n }, w = (d, l = T.LOCAL, c = T.LOCAL) => {\n const f = ie(l) ? c : l, v = b(d, l);\n v && p(f, { updated: [v] });\n }, u = (d, l = T.LOCAL) => {\n const c = d.reduce((f, v) => {\n const D = b(v);\n return D ? [...f, D] : f;\n }, []);\n c.length > 0 && p(l, { updated: c });\n }, S = (d, l = T.LOCAL) => {\n const c = e.get(d.annotation);\n if (c) {\n const f = {\n ...c,\n bodies: [...c.bodies, d]\n };\n e.set(c.id, f), n.set(d.id, f.id), p(l, { updated: [{\n oldValue: c,\n newValue: f,\n bodiesCreated: [d]\n }] });\n } else\n console.warn(`Attempt to add body to missing annotation: ${d.annotation}`);\n }, s = () => [...e.values()], g = (d = T.LOCAL) => {\n const l = [...e.values()];\n e.clear(), n.clear(), p(d, { deleted: l });\n }, y = (d, l = !0, c = T.LOCAL) => {\n if (l) {\n const f = [...e.values()];\n e.clear(), n.clear(), d.forEach((v) => {\n e.set(v.id, v), v.bodies.forEach((D) => n.set(D.id, v.id));\n }), p(c, { created: d, deleted: f });\n } else {\n const f = d.reduce((v, D) => {\n const B = e.get(D.id);\n return B ? [...v, B] : v;\n }, []);\n if (f.length > 0)\n throw Error(`Bulk insert would overwrite the following annotations: ${f.map((v) => v.id).join(\", \")}`);\n d.forEach((v) => {\n e.set(v.id, v), v.bodies.forEach((D) => n.set(D.id, v.id));\n }), p(c, { created: d });\n }\n }, A = (d) => {\n const l = typeof d == \"string\" ? d : d.id, c = e.get(l);\n if (c)\n return e.delete(l), c.bodies.forEach((f) => n.delete(f.id)), c;\n console.warn(`Attempt to delete missing annotation: ${l}`);\n }, O = (d, l = T.LOCAL) => {\n const c = A(d);\n c && p(l, { deleted: [c] });\n }, C = (d, l = T.LOCAL) => {\n const c = d.reduce((f, v) => {\n const D = A(v);\n return D ? [...f, D] : f;\n }, []);\n c.length > 0 && p(l, { deleted: c });\n }, a = (d, l = T.LOCAL) => {\n const c = e.get(d.annotation);\n if (c) {\n const f = c.bodies.find((v) => v.id === d.id);\n if (f) {\n n.delete(f.id);\n const v = {\n ...c,\n bodies: c.bodies.filter((B) => B.id !== d.id)\n };\n e.set(c.id, v), p(l, { updated: [{\n oldValue: c,\n newValue: v,\n bodiesDeleted: [f]\n }] });\n } else\n console.warn(`Attempt to delete missing body ${d.id} from annotation ${d.annotation}`);\n } else\n console.warn(`Attempt to delete body from missing annotation ${d.annotation}`);\n }, m = (d) => {\n const l = e.get(d);\n return l ? { ...l } : void 0;\n }, r = (d) => {\n const l = n.get(d);\n if (l) {\n const f = m(l).bodies.find((v) => v.id === d);\n if (f)\n return f;\n console.error(`Store integrity error: body ${d} in index, but not in annotation`);\n } else\n console.warn(`Attempt to retrieve missing body: ${d}`);\n }, E = (d, l) => {\n if (d.annotation !== l.annotation)\n throw \"Annotation integrity violation: annotation ID must be the same when updating bodies\";\n const c = e.get(d.annotation);\n if (c) {\n const f = c.bodies.find((D) => D.id === d.id), v = {\n ...c,\n bodies: c.bodies.map((D) => D.id === f.id ? l : D)\n };\n return e.set(c.id, v), f.id !== l.id && (n.delete(f.id), n.set(l.id, v.id)), {\n oldValue: c,\n newValue: v,\n bodiesUpdated: [{ oldBody: f, newBody: l }]\n };\n } else\n console.warn(`Attempt to add body to missing annotation ${d.annotation}`);\n }, h = (d, l, c = T.LOCAL) => {\n const f = E(d, l);\n f && p(c, { updated: [f] });\n }, L = (d, l = T.LOCAL) => {\n const c = d.map((f) => E({ id: f.id, annotation: f.annotation }, f)).filter(Boolean);\n p(l, { updated: c });\n }, I = (d) => {\n const l = e.get(d.annotation);\n if (l) {\n const c = {\n ...l,\n target: {\n ...l.target,\n ...d\n }\n };\n return e.set(l.id, c), {\n oldValue: l,\n newValue: c,\n targetUpdated: {\n oldTarget: l.target,\n newTarget: d\n }\n };\n } else\n console.warn(`Attempt to update target on missing annotation: ${d.annotation}`);\n };\n return {\n addAnnotation: U,\n addBody: S,\n all: s,\n bulkAddAnnotation: y,\n bulkDeleteAnnotation: C,\n bulkUpdateAnnotation: u,\n bulkUpdateBodies: L,\n bulkUpdateTargets: (d, l = T.LOCAL) => {\n const c = d.map((f) => I(f)).filter(Boolean);\n c.length > 0 && p(l, { updated: c });\n },\n clear: g,\n deleteAnnotation: O,\n deleteBody: a,\n getAnnotation: m,\n getBody: r,\n observe: o,\n unobserve: i,\n updateAnnotation: w,\n updateBody: h,\n updateTarget: (d, l = T.LOCAL) => {\n const c = I(d);\n c && p(l, { updated: [c] });\n }\n };\n}, Ue = (e) => ({\n ...e,\n subscribe: (t) => {\n const o = (i) => t(i.state);\n return e.observe(o), t(e.all()), () => e.unobserve(o);\n }\n});\nlet P = () => ({\n emit(e, ...n) {\n for (let t = 0, o = this.events[e] || [], i = o.length; t < i; t++)\n o[t](...n);\n },\n events: {},\n on(e, n) {\n var t;\n return ((t = this.events)[e] || (t[e] = [])).push(n), () => {\n var o;\n this.events[e] = (o = this.events[e]) == null ? void 0 : o.filter((i) => n !== i);\n };\n }\n});\nconst de = 250, Le = (e) => {\n const n = P(), t = [];\n let o = -1, i = !1, p = 0;\n const U = (r) => {\n if (!i) {\n const { changes: E } = r, h = performance.now();\n if (h - p > de)\n t.splice(o + 1), t.push(E), o = t.length - 1;\n else {\n const L = t.length - 1;\n t[L] = se(t[L], E);\n }\n p = h;\n }\n i = !1;\n };\n e.observe(U, { origin: T.LOCAL });\n const b = (r) => r && r.length > 0 && e.bulkDeleteAnnotation(r), w = (r) => r && r.length > 0 && e.bulkAddAnnotation(r, !1), u = (r) => r && r.length > 0 && e.bulkUpdateAnnotation(r.map(({ oldValue: E }) => E)), S = (r) => r && r.length > 0 && e.bulkUpdateAnnotation(r.map(({ newValue: E }) => E)), s = (r) => r && r.length > 0 && e.bulkAddAnnotation(r, !1), g = (r) => r && r.length > 0 && e.bulkDeleteAnnotation(r);\n return {\n canRedo: () => t.length - 1 > o,\n canUndo: () => o > -1,\n destroy: () => e.unobserve(U),\n on: (r, E) => n.on(r, E),\n redo: () => {\n if (t.length - 1 > o) {\n i = !0;\n const { created: r, updated: E, deleted: h } = t[o + 1];\n w(r), S(E), g(h), n.emit(\"redo\", t[o + 1]), o += 1;\n }\n },\n undo: () => {\n if (o > -1) {\n i = !0;\n const { created: r, updated: E, deleted: h } = t[o];\n b(r), u(E), s(h), n.emit(\"undo\", t[o]), o -= 1;\n }\n }\n };\n}, Se = () => {\n const { subscribe: e, set: n } = _([]);\n return {\n subscribe: e,\n set: n\n };\n}, Oe = (e, n, t, o) => {\n const { store: i, selection: p, hover: U, viewport: b } = e, w = /* @__PURE__ */ new Map();\n let u = [], S, s;\n const g = (a, m) => {\n w.has(a) ? w.get(a).push(m) : w.set(a, [m]);\n }, y = (a, m) => {\n const r = w.get(a);\n r && r.indexOf(m) > 0 && r.splice(r.indexOf(m), 1);\n }, A = (a, m, r) => {\n w.has(a) && setTimeout(() => {\n w.get(a).forEach((E) => {\n if (t) {\n const h = Array.isArray(m) ? m.map((I) => t.serialize(I)) : t.serialize(m), L = r ? r instanceof PointerEvent ? r : t.serialize(r) : void 0;\n E(h, L);\n } else\n E(m, r);\n });\n }, 1);\n }, O = () => {\n const { selected: a } = p, m = (a || []).map(({ id: r }) => i.getAnnotation(r));\n m.forEach((r) => {\n const E = u.find((h) => h.id === r.id);\n (!E || !x(E, r)) && A(\"updateAnnotation\", r, E);\n }), u = u.map((r) => {\n const E = m.find(({ id: h }) => h === r.id);\n return E || r;\n });\n };\n p.subscribe(({ selected: a }) => {\n if (!(u.length === 0 && a.length === 0)) {\n if (u.length === 0 && a.length > 0)\n u = a.map(({ id: m }) => i.getAnnotation(m));\n else if (u.length > 0 && a.length === 0)\n u.forEach((m) => {\n const r = i.getAnnotation(m.id);\n r && !x(r, m) && A(\"updateAnnotation\", r, m);\n }), u = [];\n else {\n const m = new Set(u.map((h) => h.id)), r = new Set(a.map(({ id: h }) => h));\n u.filter((h) => !r.has(h.id)).forEach((h) => {\n const L = i.getAnnotation(h.id);\n L && !x(L, h) && A(\"updateAnnotation\", L, h);\n }), u = [\n // Remove annotations that were deselected\n ...u.filter((h) => r.has(h.id)),\n // Add editable annotations that were selected\n ...a.filter(({ id: h }) => !m.has(h)).map(({ id: h }) => i.getAnnotation(h))\n ];\n }\n A(\"selectionChanged\", u);\n }\n }), U.subscribe((a) => {\n !S && a ? A(\"mouseEnterAnnotation\", i.getAnnotation(a)) : S && !a ? A(\"mouseLeaveAnnotation\", i.getAnnotation(S)) : S && a && (A(\"mouseLeaveAnnotation\", i.getAnnotation(S)), A(\"mouseEnterAnnotation\", i.getAnnotation(a))), S = a;\n }), b == null || b.subscribe((a) => A(\"viewportIntersect\", a.map((m) => i.getAnnotation(m)))), i.observe((a) => {\n o && (s && clearTimeout(s), s = setTimeout(O, 1e3));\n const { created: m, deleted: r } = a.changes;\n (m || []).forEach((h) => A(\"createAnnotation\", h)), (r || []).forEach((h) => A(\"deleteAnnotation\", h)), (a.changes.updated || []).filter((h) => [\n ...h.bodiesCreated || [],\n ...h.bodiesDeleted || [],\n ...h.bodiesUpdated || []\n ].length > 0).forEach(({ oldValue: h, newValue: L }) => {\n const I = u.find((N) => N.id === h.id) || h;\n u = u.map((N) => N.id === h.id ? L : N), A(\"updateAnnotation\", L, I);\n });\n }, { origin: T.LOCAL }), i.observe((a) => {\n if (u) {\n const m = new Set(u.map((E) => E.id)), r = (a.changes.updated || []).filter(({ newValue: E }) => m.has(E.id)).map(({ newValue: E }) => E);\n r.length > 0 && (u = u.map((E) => {\n const h = r.find((L) => L.id === E.id);\n return h || E;\n }));\n }\n }, { origin: T.REMOTE });\n const C = (a) => (m) => {\n const { created: r, deleted: E, updated: h } = m;\n (r || []).forEach((L) => A(\"createAnnotation\", L)), (E || []).forEach((L) => A(\"deleteAnnotation\", L)), a ? (h || []).forEach((L) => A(\"updateAnnotation\", L.oldValue, L.newValue)) : (h || []).forEach((L) => A(\"updateAnnotation\", L.newValue, L.oldValue));\n };\n return n.on(\"undo\", C(!0)), n.on(\"redo\", C(!1)), { on: g, off: y, emit: A };\n}, Te = (e) => (n) => n.map((t) => e.serialize(t)), re = (e) => (n) => n.reduce((t, o) => {\n const { parsed: i, error: p } = e.parse(o);\n return p ? {\n parsed: t.parsed,\n failed: [...t.failed, o]\n } : i ? {\n parsed: [...t.parsed, i],\n failed: t.failed\n } : {\n ...t\n };\n}, { parsed: [], failed: [] }), De = (e, n, t) => {\n const { store: o, selection: i } = e, p = (C) => {\n if (t) {\n const { parsed: a, error: m } = t.parse(C);\n a ? o.addAnnotation(a, T.REMOTE) : console.error(m);\n } else\n o.addAnnotation(C, T.REMOTE);\n }, U = () => i.clear(), b = () => o.clear(), w = (C) => {\n const a = o.getAnnotation(C);\n return t && a ? t.serialize(a) : a;\n }, u = () => t ? o.all().map(t.serialize) : o.all(), S = () => {\n var m;\n const a = (((m = i.selected) == null ? void 0 : m.map((r) => r.id)) || []).map((r) => o.getAnnotation(r)).filter(Boolean);\n return t ? a.map(t.serialize) : a;\n }, s = (C) => fetch(C).then((a) => a.json()).then((a) => (y(a), a)), g = (C) => {\n if (typeof C == \"string\") {\n const a = o.getAnnotation(C);\n if (o.deleteAnnotation(C), a)\n return t ? t.serialize(a) : a;\n } else {\n const a = t ? t.parse(C).parsed : C;\n if (a)\n return o.deleteAnnotation(a), C;\n }\n }, y = (C) => {\n if (t) {\n const { parsed: a, failed: m } = re(t)(C);\n m.length > 0 && console.warn(`Discarded ${m.length} invalid annotations`, m), o.bulkAddAnnotation(a, !0, T.REMOTE);\n } else\n o.bulkAddAnnotation(C, !0, T.REMOTE);\n }, A = (C) => {\n C ? i.setSelected(C) : i.clear();\n }, O = (C) => {\n if (t) {\n const a = t.parse(C).parsed, m = t.serialize(o.getAnnotation(a.id));\n return o.updateAnnotation(a), m;\n } else {\n const a = o.getAnnotation(C.id);\n return o.updateAnnotation(C), a;\n }\n };\n return {\n addAnnotation: p,\n cancelSelected: U,\n canRedo: n.canRedo,\n canUndo: n.canUndo,\n clearAnnotations: b,\n getAnnotationById: w,\n getAnnotations: u,\n getSelected: S,\n loadAnnotations: s,\n redo: n.redo,\n removeAnnotation: g,\n setAnnotations: y,\n setSelected: A,\n undo: n.undo,\n updateAnnotation: O\n };\n};\nlet ae = (e) => crypto.getRandomValues(new Uint8Array(e)), ce = (e, n, t) => {\n let o = (2 << Math.log(e.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * n / e.length);\n return (p = n) => {\n let U = \"\";\n for (; ; ) {\n let b = t(i), w = i;\n for (; w--; )\n if (U += e[b[w] & o] || \"\", U.length === p)\n return U;\n }\n };\n}, le = (e, n = 21) => ce(e, n, ae), ue = (e = 21) => crypto.getRandomValues(new Uint8Array(e)).reduce((n, t) => (t &= 63, t < 36 ? n += t.toString(36) : t < 62 ? n += (t - 26).toString(36).toUpperCase() : t > 62 ? n += \"-\" : n += \"_\", n), \"\");\nconst Re = () => ({ isGuest: !0, id: le(\"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_\", 20)() }), fe = (e) => {\n const n = JSON.stringify(e);\n let t = 0;\n for (let o = 0, i = n.length; o < i; o++) {\n let p = n.charCodeAt(o);\n t = (t << 5) - t + p, t |= 0;\n }\n return `${t}`;\n}, pe = (e) => e ? typeof e == \"object\" ? { ...e } : e : void 0, Be = (e, n) => (Array.isArray(e) ? e : [e]).map((t) => {\n const { id: o, type: i, purpose: p, value: U, created: b, creator: w, ...u } = t;\n return {\n id: o || `temp-${fe(t)}`,\n annotation: n,\n type: i,\n purpose: p,\n value: U,\n created: b ? new Date(b) : void 0,\n creator: pe(w),\n ...u\n };\n}), xe = (e) => e.map((n) => {\n var o, i;\n const t = { ...n };\n return delete t.annotation, (o = t.id) != null && o.startsWith(\"temp-\") && delete t.id, { ...t, created: (i = t.created) == null ? void 0 : i.toISOString() };\n}), ge = [\n \"#ff7c00\",\n // orange\n \"#1ac938\",\n // green\n \"#e8000b\",\n // red\n \"#8b2be2\",\n // purple\n \"#9f4800\",\n // brown\n \"#f14cc1\",\n // pink\n \"#ffc400\",\n // khaki\n \"#00d7ff\",\n // cyan\n \"#023eff\"\n // blue\n], he = () => {\n const e = [...ge];\n return { assignRandomColor: () => {\n const o = Math.floor(Math.random() * e.length), i = e[o];\n return e.splice(o, 1), i;\n }, releaseColor: (o) => e.push(o) };\n}, me = () => {\n const e = he();\n return { addUser: (o, i) => {\n const p = e.assignRandomColor();\n return {\n label: i.name || i.id,\n avatar: i.avatar,\n color: p\n };\n }, removeUser: (o) => e.releaseColor(o.appearance.color) };\n}, Ae = (e, n) => e.every((t) => e.includes(t)) && n.every((t) => e.includes(t)), Ie = ue(), ke = (e = me()) => {\n const n = P(), t = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), i = (s, g) => {\n if (t.has(s)) {\n console.warn(\"Attempt to add user that is already present\", s, g);\n return;\n }\n const y = e.addUser(s, g);\n t.set(s, {\n ...g,\n presenceKey: s,\n appearance: y\n });\n }, p = (s) => {\n const g = t.get(s);\n if (!g) {\n console.warn(\"Attempt to remove user that is not present\", s);\n return;\n }\n e.removeUser(g), t.delete(s);\n }, U = (s) => {\n const g = new Set(s.map((O) => O.presenceKey)), y = s.filter(({ presenceKey: O }) => !t.has(O)), A = Array.from(t.values()).filter((O) => !g.has(O.presenceKey));\n y.forEach(({ presenceKey: O, user: C }) => i(O, C)), A.forEach((O) => {\n const { presenceKey: C } = O;\n o.has(C) && n.emit(\"selectionChange\", O, null), p(C);\n }), (y.length > 0 || A.length > 0) && n.emit(\"presence\", u());\n }, b = (s, g) => {\n const y = t.get(s);\n if (!y) {\n console.warn(\"Activity notification from user that is not present\");\n return;\n }\n const A = o.get(s);\n (!A || !Ae(A, g)) && (o.set(s, g), n.emit(\"selectionChange\", y, g));\n }, w = (s, g) => {\n const y = t.get(s);\n if (!y) {\n console.warn(\"Selection change for user that is not present\", s);\n return;\n }\n g ? o.set(s, g) : o.delete(s), n.emit(\"selectionChange\", y, g);\n }, u = () => [...Array.from(t.values())];\n return {\n getPresentUsers: u,\n notifyActivity: b,\n on: (s, g) => n.on(s, g),\n syncUsers: U,\n updateSelection: w\n };\n};\nexport {\n ne as Ignore,\n T as Origin,\n Ie as PRESENCE_KEY,\n q as PointerSelectAction,\n Re as createAnonymousGuest,\n De as createBaseAnnotator,\n we as createBody,\n me as createDefaultAppearenceProvider,\n be as createHoverState,\n Oe as createLifecyleObserver,\n ke as createPresenceState,\n ve as createSelectionState,\n ye as createStore,\n Le as createUndoStack,\n Se as createViewportState,\n he as defaultColorProvider,\n M as diffAnnotations,\n Ce as getContributors,\n se as mergeChanges,\n G as onPointerSelect,\n re as parseAll,\n Be as parseW3CBodies,\n pe as parseW3CUser,\n Te as serializeAll,\n xe as serializeW3CBodies,\n oe as shouldNotify,\n Ue as toSvelteStore\n};\n//# sourceMappingURL=annotorious-core.es.js.map\n"],"names":["q","e","z","H","F","R","J","n","Q","j","X","t","o","i","we","T","Ue","ae","ce","p","U","b","w","le","ue","Re","ge","he"],"mappings":"AA2EG,IAACA,IAAqB,kBAACC,OAAOA,EAAE,OAAO,QAAQA,EAAE,SAAS,UAAUA,EAAE,OAAO,QAAQA,IAAID,KAAK,EAAE;AA4CnG,IAAIE;AACJ,MAAMC,IAAI,IAAI,WAAW,EAAE;AAC3B,SAASC,IAAI;AACX,MAAI,CAACF,MAAMA,IAAI,OAAO,SAAS,OAAO,OAAO,mBAAmB,OAAO,gBAAgB,KAAK,MAAM,GAAG,CAACA;AACpG,UAAM,IAAI,MAAM,0GAA0G;AAC5H,SAAOA,EAAEC,CAAC;AACZ;AACA,MAAME,IAAI,CAAA;AACV,SAASJ,IAAI,GAAGA,IAAI,KAAK,EAAEA;AACzB,EAAAI,EAAE,MAAMJ,IAAI,KAAK,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AACxC,SAASK,EAAEL,GAAGM,IAAI,GAAG;AACnB,SAAOF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAI,MAAMF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAI,MAAMF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAI,MAAMF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAIF,EAAEJ,EAAEM,IAAI,CAAC,CAAC,IAAI,MAAMF,EAAEJ,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AK,MAAM;AACZ,QAAM1B,IAAI,CAAC,GAAGyB,CAAE;AAChB,SAAO,EAAE,mBAAmB,MAAM;AAChC,UAAM,IAAI,KAAK,MAAM,KAAK,OAAM,IAAKzB,EAAE,MAAM,GAAGY,IAAIZ,EAAE,CAAC;AACvD,WAAOA,EAAE,OAAO,GAAG,CAAC,GAAGY;AAAA,EAC3B,GAAK,cAAc,CAAC,MAAMZ,EAAE,KAAK,CAAC;AAClC;AAUuFuB,EAAI;"}
1
+ {"version":3,"file":"annotorious-svelte.es3.js","sources":["../src/osd/OpenSeadragonAnnotator.svelte"],"sourcesContent":["<script lang=\"ts\">\n import { setContext } from 'svelte';\n import { SvelteAnnotator, SvelteAnnotatorState, toSvelteStore } from '@annotorious/core';\n import { createOSDAnnotator, ImageAnnotation } from '@annotorious/openseadragon';\n import type OpenSeadragon from 'openseadragon';\n\n /** props **/\n export let viewer: OpenSeadragon.Viewer;\n export let opts = {};\n export let anno: SvelteAnnotator<ImageAnnotation> = undefined;\n\n $: init(viewer);\n\n const init = (viewer: OpenSeadragon.Viewer) => {\n if (viewer) {\n const annotator = createOSDAnnotator(viewer, opts);\n\n // Wrap the store for Svelte reactivity\n const svelteStore = toSvelteStore(annotator.state.store);\n\n const shim = {\n ...annotator,\n state: {\n ...annotator.state,\n store: svelteStore\n } as SvelteAnnotatorState<ImageAnnotation>\n } as SvelteAnnotator<ImageAnnotation>\n\n setContext('anno', shim);\n setContext('viewer', viewer);\n\n anno = shim;\n }\n }\n</script>\n\n{#if viewer}\n <slot />\n{/if}\n"],"names":["ctx","create_if_block","viewer","$$props","opts","anno","init","annotator","createOSDAnnotator","svelteStore","toSvelteStore","shim","setContext","$$invalidate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoCKA,EAAM,CAAA,KAAAC,EAAAD,CAAA;AAAA;;;;;;;;;;MAANA,EAAM,CAAA;;;;;;;;;;;;;;;;;6CA7BE,QAAAE,EAA4B,IAAAC,KAC5B,MAAAC,IAAI,GAAA,IAAAD,GACJ,EAAA,MAAAE,IAAyC,OAAS,IAAAF;AAIvD,QAAAG,IAAQ,CAAAJ,MAA4B;QACpCA,GAAM;AACF,YAAAK,IAAYC,EAAmBN,GAAQE,CAAI,GAG3CK,IAAcC,EAAcH,EAAU,MAAM,KAAK,GAEjDI,IAAI;AAAA,WACLJ;AAAA,QACH,YACKA,EAAU,OACb,OAAOE,EAAA;AAAA;AAIX,MAAAG,EAAW,QAAQD,CAAI,GACvBC,EAAW,UAAUV,CAAM,GAE3BW,EAAA,GAAAR,IAAOM,CAAI;AAAA;;;;;;SApBZL,EAAKJ,CAAM;AAAA;;;;;;;;"}
@@ -1,117 +1,126 @@
1
- import { safe_not_equal as g, create_slot as b, update_slot_base as h, get_all_dirty_from_scope as k, get_slot_changes as w } from "./annotorious-svelte.es6.js";
2
- import { empty as A, insert as O, detach as v } from "./annotorious-svelte.es7.js";
3
- import { transition_in as s, transition_out as c, check_outros as C, group_outros as q } from "./annotorious-svelte.es8.js";
4
- import { setContext as _ } from "./annotorious-svelte.es9.js";
5
- import { SvelteComponent as y, init as D } from "./annotorious-svelte.es10.js";
6
- import "./annotorious-svelte.es11.js";
7
- import { toSvelteStore as N } from "./annotorious-svelte.es3.js";
8
- import { createOSDAnnotator as U } from "@annotorious/openseadragon";
9
- function d(f) {
10
- let o;
11
- const n = (
12
- /*#slots*/
13
- f[4].default
14
- ), t = b(
15
- n,
16
- f,
17
- /*$$scope*/
18
- f[3],
19
- null
20
- );
1
+ import { SvelteComponent as A, init as H, safe_not_equal as I, empty as X, insert as P, noop as v, detach as S, component_subscribe as Y, onMount as q, element as x, text as G, attr as L, append as R, action_destroyer as U, listen as _, set_data as z, is_function as B, run_all as F } from "./annotorious-svelte.es5.js";
2
+ import { draggable as J } from "./annotorious-svelte.es9.js";
3
+ import b from "openseadragon";
4
+ import "./annotorious-svelte.es10.js";
5
+ function w(n) {
6
+ let o, e = (
7
+ /*$selection*/
8
+ n[0].selected.map(y).join(", ") + ""
9
+ ), t, s, a, d;
21
10
  return {
22
11
  c() {
23
- t && t.c();
24
- },
25
- m(e, r) {
26
- t && t.m(e, r), o = !0;
12
+ o = x("div"), t = G(e), L(o, "class", "a9s-popup a9s-osd-popup svelte-1xuxeat");
27
13
  },
28
- p(e, r) {
29
- t && t.p && (!o || r & /*$$scope*/
30
- 8) && h(
31
- t,
32
- n,
33
- e,
34
- /*$$scope*/
35
- e[3],
36
- o ? w(
37
- n,
38
- /*$$scope*/
39
- e[3],
40
- r,
41
- null
42
- ) : k(
43
- /*$$scope*/
44
- e[3]
14
+ m(r, l) {
15
+ P(r, o, l), R(o, t), a || (d = [
16
+ U(s = J.call(null, o, {
17
+ position: { x: (
18
+ /*left*/
19
+ n[1]
20
+ ), y: (
21
+ /*top*/
22
+ n[2]
23
+ ) }
24
+ })),
25
+ _(
26
+ o,
27
+ "neodrag:start",
28
+ /*onDragStart*/
29
+ n[4]
45
30
  ),
46
- null
47
- );
48
- },
49
- i(e) {
50
- o || (s(t, e), o = !0);
31
+ _(
32
+ o,
33
+ "neodrag:end",
34
+ /*onDragEnd*/
35
+ n[5]
36
+ )
37
+ ], a = !0);
51
38
  },
52
- o(e) {
53
- c(t, e), o = !1;
39
+ p(r, l) {
40
+ l & /*$selection*/
41
+ 1 && e !== (e = /*$selection*/
42
+ r[0].selected.map(y).join(", ") + "") && z(t, e), s && B(s.update) && l & /*left, top*/
43
+ 6 && s.update.call(null, {
44
+ position: { x: (
45
+ /*left*/
46
+ r[1]
47
+ ), y: (
48
+ /*top*/
49
+ r[2]
50
+ ) }
51
+ });
54
52
  },
55
- d(e) {
56
- t && t.d(e);
53
+ d(r) {
54
+ r && S(o), a = !1, F(d);
57
55
  }
58
56
  };
59
57
  }
60
- function j(f) {
61
- let o, n, t = (
62
- /*viewer*/
63
- f[0] && d(f)
58
+ function K(n) {
59
+ let o, e = (
60
+ /*$selection*/
61
+ n[0] && w(n)
64
62
  );
65
63
  return {
66
64
  c() {
67
- t && t.c(), o = A();
65
+ e && e.c(), o = X();
68
66
  },
69
- m(e, r) {
70
- t && t.m(e, r), O(e, o, r), n = !0;
67
+ m(t, s) {
68
+ e && e.m(t, s), P(t, o, s);
71
69
  },
72
- p(e, [r]) {
73
- /*viewer*/
74
- e[0] ? t ? (t.p(e, r), r & /*viewer*/
75
- 1 && s(t, 1)) : (t = d(e), t.c(), s(t, 1), t.m(o.parentNode, o)) : t && (q(), c(t, 1, 1, () => {
76
- t = null;
77
- }), C());
70
+ p(t, [s]) {
71
+ /*$selection*/
72
+ t[0] ? e ? e.p(t, s) : (e = w(t), e.c(), e.m(o.parentNode, o)) : e && (e.d(1), e = null);
78
73
  },
79
- i(e) {
80
- n || (s(t), n = !0);
81
- },
82
- o(e) {
83
- c(t), n = !1;
84
- },
85
- d(e) {
86
- e && v(o), t && t.d(e);
74
+ i: v,
75
+ o: v,
76
+ d(t) {
77
+ e && e.d(t), t && S(o);
87
78
  }
88
79
  };
89
80
  }
90
- function z(f, o, n) {
91
- let { $$slots: t = {}, $$scope: e } = o, { viewer: r } = o, { opts: l = {} } = o, { anno: a = void 0 } = o;
92
- const p = (i) => {
93
- if (i) {
94
- const u = U(i, l), S = N(u.state.store), m = {
95
- ...u,
96
- state: { ...u.state, store: S }
97
- };
98
- _("anno", m), _("viewer", i), n(1, a = m);
99
- }
81
+ const y = (n) => n.id;
82
+ function Q(n, o, e) {
83
+ let t, { state: s } = o, { viewer: a } = o, d, r, l = !1, c;
84
+ const { selection: m, store: u } = s;
85
+ Y(n, m, (i) => e(0, t = i));
86
+ const g = (i) => {
87
+ var p;
88
+ return ((p = i.selected) == null ? void 0 : p.length) > 0;
89
+ }, E = () => {
90
+ l = !0, a.setMouseNavEnabled(!1);
91
+ }, D = () => {
92
+ a.setMouseNavEnabled(!0);
93
+ }, N = () => {
94
+ c && u.unobserve(c), g(t) && (l = !1, f(t), c = (i) => {
95
+ l || f(t);
96
+ }, u.observe(c, {
97
+ annotations: t.selected.map((i) => i.id)
98
+ }));
99
+ }, f = (i) => {
100
+ const p = i.selected[0].id, h = u.getAnnotation(p), { minX: k, minY: C, maxX: M, maxY: O } = h.target.selector.geometry.bounds, T = 14, V = a.viewport.imageToViewerElementCoordinates(new b.Point(k, C)), j = a.viewport.imageToViewerElementCoordinates(new b.Point(M, O));
101
+ e(1, d = j.x + T), e(2, r = V.y);
100
102
  };
101
- return f.$$set = (i) => {
102
- "viewer" in i && n(0, r = i.viewer), "opts" in i && n(2, l = i.opts), "anno" in i && n(1, a = i.anno), "$$scope" in i && n(3, e = i.$$scope);
103
- }, f.$$.update = () => {
104
- f.$$.dirty & /*viewer*/
105
- 1 && p(r);
106
- }, [r, a, l, e, t];
103
+ return q(() => {
104
+ const i = () => {
105
+ g(t) && !l && f(t);
106
+ };
107
+ return a.addHandler("update-viewport", i), () => {
108
+ a.removeHandler("update-viewport", i);
109
+ };
110
+ }), n.$$set = (i) => {
111
+ "state" in i && e(6, s = i.state), "viewer" in i && e(7, a = i.viewer);
112
+ }, n.$$.update = () => {
113
+ n.$$.dirty & /*$selection*/
114
+ 1 && N();
115
+ }, [t, d, r, m, E, D, s, a];
107
116
  }
108
- class B extends y {
117
+ class W extends A {
109
118
  constructor(o) {
110
- super(), D(this, o, z, j, g, { viewer: 0, opts: 2, anno: 1 });
119
+ super(), H(this, o, Q, K, I, { state: 6, viewer: 7 });
111
120
  }
112
121
  }
113
- const M = B;
122
+ const oe = W;
114
123
  export {
115
- M as default
124
+ oe as default
116
125
  };
117
126
  //# sourceMappingURL=annotorious-svelte.es4.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-svelte.es4.js","sources":["../src/osd/OpenSeadragonAnnotator.svelte"],"sourcesContent":["<script lang=\"ts\">\n import { setContext } from 'svelte';\n import { SvelteAnnotator, SvelteAnnotatorState, toSvelteStore } from '@annotorious/core';\n import { createOSDAnnotator, ImageAnnotation } from '@annotorious/openseadragon';\n import type OpenSeadragon from 'openseadragon';\n\n /** props **/\n export let viewer: OpenSeadragon.Viewer;\n export let opts = {};\n export let anno: SvelteAnnotator<ImageAnnotation> = undefined;\n\n $: init(viewer);\n\n const init = (viewer: OpenSeadragon.Viewer) => {\n if (viewer) {\n const annotator = createOSDAnnotator(viewer, opts);\n\n // Wrap the store for Svelte reactivity\n const svelteStore = toSvelteStore(annotator.state.store);\n\n const shim = {\n ...annotator,\n state: {\n ...annotator.state,\n store: svelteStore\n } as SvelteAnnotatorState<ImageAnnotation>\n } as SvelteAnnotator<ImageAnnotation>\n\n setContext('anno', shim);\n setContext('viewer', viewer);\n\n anno = shim;\n }\n }\n</script>\n\n{#if viewer}\n <slot />\n{/if}\n"],"names":["ctx","create_if_block","viewer","$$props","opts","anno","init","annotator","createOSDAnnotator","svelteStore","toSvelteStore","shim","setContext","$$invalidate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoCKA,EAAM,CAAA,KAAAC,EAAAD,CAAA;AAAA;;;;;;;;;;MAANA,EAAM,CAAA;;;;;;;;;;;;;;;;;6CA7BE,QAAAE,EAA4B,IAAAC,KAC5B,MAAAC,IAAI,GAAA,IAAAD,GACJ,EAAA,MAAAE,IAAyC,OAAS,IAAAF;AAIvD,QAAAG,IAAQ,CAAAJ,MAA4B;QACpCA,GAAM;AACF,YAAAK,IAAYC,EAAmBN,GAAQE,CAAI,GAG3CK,IAAcC,EAAcH,EAAU,MAAM,KAAK,GAEjDI,IAAI;AAAA,WACLJ;AAAA,QACH,YACKA,EAAU,OACb,OAAOE,EAAA;AAAA;AAIX,MAAAG,EAAW,QAAQD,CAAI,GACvBC,EAAW,UAAUV,CAAM,GAE3BW,EAAA,GAAAR,IAAOM,CAAI;AAAA;;;;;;SApBZL,EAAKJ,CAAM;AAAA;;;;;;;;"}
1
+ {"version":3,"file":"annotorious-svelte.es4.js","sources":["../src/osd/OpenSeadragonPopup.svelte"],"sourcesContent":["<script lang=\"ts\">\n import { onMount } from 'svelte';\n import { draggable } from '@neodrag/svelte';\n import OpenSeadragon from 'openseadragon';\n import type { Selection, StoreChangeEvent, SvelteAnnotatorState } from '@annotorious/core';\n import type { ImageAnnotation } from '@annotorious/annotorious';\n\n export let state: SvelteAnnotatorState<ImageAnnotation>;\n\n export let viewer: OpenSeadragon.Viewer;\n\n let left: number;\n\n let top: number;\n\n let dragged = false;\n\n let storeObserver: (event: StoreChangeEvent<ImageAnnotation>) => void;\n\n const { selection, store } = state; \n\n const isSelected = (selection: Selection) => selection.selected?.length > 0;\n\n const onDragStart = () => {\n dragged = true;\n viewer.setMouseNavEnabled(false);\n }\n\n const onDragEnd = () => {\n viewer.setMouseNavEnabled(true);\n }\n\n $: $selection, onSelect();\n\n const onSelect = () => {\n if (storeObserver)\n store.unobserve(storeObserver);\n\n if (isSelected($selection)) {\n dragged = false;\n\n setPosition($selection);\n\n storeObserver = (event: StoreChangeEvent<ImageAnnotation>) => {\n if (!dragged)\n setPosition($selection);\n }\n\n store.observe(storeObserver, { annotations: $selection.selected.map(s => s.id) });\n }\n }\n\n const setPosition = (selection: Selection) => {\n // Note: this demo popup only supports a single selection\n const selectedId = selection.selected[0].id;\n const annotation = store.getAnnotation(selectedId);\n\n const { minX, minY, maxX, maxY } = annotation.target.selector.geometry.bounds;\n\n const PADDING = 14;\n\n const topLeft = viewer.viewport.imageToViewerElementCoordinates(new OpenSeadragon.Point(minX, minY));\n const bottomRight = viewer.viewport.imageToViewerElementCoordinates(new OpenSeadragon.Point(maxX, maxY));\n\n // [left, top] = defaultStrategy(annotation, lastPointerDown);\n left = bottomRight.x + PADDING;\n top = topLeft.y;\n }\n\n onMount(() => {\n const onUpdateViewport = () => {\n if (isSelected($selection) && !dragged)\n setPosition($selection);\n }\n\n viewer.addHandler('update-viewport', onUpdateViewport);\n\n return () => {\n viewer.removeHandler('update-viewport', onUpdateViewport);\n }\n });\n</script>\n\n{#if $selection}\n <div \n class=\"a9s-popup a9s-osd-popup\"\n use:draggable={{ position: { x: left, y: top }}}\n on:neodrag:start={onDragStart}\n on:neodrag:end={onDragEnd}>\n {$selection.selected.map(s => s.id).join(', ')}\n </div>\n{/if}\n\n<style>\n .a9s-osd-popup {\n background-color: #fff;\n border: 1px solid #a2a2a2;\n height: 250px;\n position: absolute;\n width: 400px;\n z-index: 1;\n }\n</style>"],"names":["t_value","ctx","func","insert","target","div","anchor","dirty","set_data","create_if_block","s","state","$$props","viewer","left","top","dragged","storeObserver","selection","store","isSelected","_a","onDragStart","onDragEnd","onSelect","$selection","setPosition","event","selectedId","annotation","minX","minY","maxX","maxY","PADDING","topLeft","OpenSeadragon","bottomRight","$$invalidate","onMount","onUpdateViewport"],"mappings":";;;;;SAyFKA;AAAA;AAAA,IAAAC,KAAW,SAAS,IAAeC,CAAA,EAAA,KAAK,IAAI,IAAA;AAAA;;;;;;AAL/C,MAAAC,EAMKC,GAAAC,GAAAC,CAAA;;UAJc,YAAY;AAAA;AAAA,YAAGL,EAAM,CAAA;AAAA,aAAA;AAAA;AAAA,YAAGA,EAAG,CAAA;AAAA,YAAA;AAAA;;;;;UAC1BA,EAAW,CAAA;AAAA,QAAA;AAAA;;;;UACbA,EAAS,CAAA;AAAA,QAAA;AAAA;;;AACxB,MAAAM;AAAA,MAAA,KAAAP,OAAAA;AAAA,MAAAC,KAAW,SAAS,IAAeC,CAAA,EAAA,KAAK,IAAI,IAAA,OAAAM,EAAA,GAAAR,CAAA;;QAH5B,YAAY;AAAA;AAAA,UAAGC,EAAM,CAAA;AAAA,WAAA;AAAA;AAAA,UAAGA,EAAG,CAAA;AAAA,UAAA;AAAA;;;;;;;;;;IAH3CA,EAAU,CAAA,KAAAQ,EAAAR,CAAA;AAAA;;;;;;;;;;MAAVA,EAAU,CAAA;;;;;;;;;UAMc,CAAAS,MAAKA,EAAE;;WAlFvB,OAAAC,EAA4C,IAAAC,KAE5C,QAAAC,EAA4B,IAAAD,GAEnCE,GAEAC,GAEAC,IAAU,IAEVC;UAEI,WAAAC,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