New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@annotorious/core

Package Overview
Dependencies
Maintainers
0
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@annotorious/core - npm Package Compare versions

Comparing version 3.0.4 to 3.0.5

529

dist/annotorious-core.es.js

@@ -1,2 +0,2 @@

var W = Object.prototype.hasOwnProperty;
var q = Object.prototype.hasOwnProperty;
function I(e, n) {

@@ -16,3 +16,3 @@ var t, o;

for (t in e)
if (W.call(e, t) && ++o && !W.call(n, t) || !(t in n) || !I(e[t], n[t])) return !1;
if (q.call(e, t) && ++o && !q.call(n, t) || !(t in n) || !I(e[t], n[t])) return !1;
return Object.keys(n).length === o;

@@ -25,17 +25,17 @@ }

}
function Q(e, n) {
function X(e, n) {
return e != e ? n == n : e !== n || e && typeof e == "object" || typeof e == "function";
}
const k = [];
function j(e, n = _) {
function M(e, n = _) {
let t;
const o = /* @__PURE__ */ new Set();
function i(b) {
if (Q(e, b) && (e = b, t)) {
const y = !k.length;
for (const h of o)
h[1](), k.push(h, e);
if (y) {
for (let h = 0; h < k.length; h += 2)
k[h][0](k[h + 1]);
if (X(e, b) && (e = b, t)) {
const w = !k.length;
for (const g of o)
g[1](), k.push(g, e);
if (w) {
for (let g = 0; g < k.length; g += 2)
k[g][0](k[g + 1]);
k.length = 0;

@@ -48,12 +48,12 @@ }

}
function w(b, y = _) {
const h = [b, y];
return o.add(h), o.size === 1 && (t = n(i, f) || _), b(e), () => {
o.delete(h), o.size === 0 && t && (t(), t = null);
function y(b, w = _) {
const g = [b, w];
return o.add(g), o.size === 1 && (t = n(i, f) || _), b(e), () => {
o.delete(g), o.size === 0 && t && (t(), t = null);
};
}
return { set: i, update: f, subscribe: w };
return { set: i, update: f, subscribe: y };
}
const Se = (e) => {
const { subscribe: n, set: t } = j();
const Ue = (e) => {
const { subscribe: n, set: t } = M();
let o;

@@ -63,4 +63,4 @@ return n((i) => o = i), e.observe(({ changes: i }) => {

(i.deleted || []).some((b) => b.id === o) && t(void 0);
const w = (i.updated || []).find(({ oldValue: b }) => b.id === o);
w && t(w.newValue.id);
const y = (i.updated || []).find(({ oldValue: b }) => b.id === o);
y && t(y.newValue.id);
}

@@ -75,29 +75,29 @@ }), {

};
var X = /* @__PURE__ */ ((e) => (e.EDIT = "EDIT", e.SELECT = "SELECT", e.NONE = "NONE", e))(X || {});
const z = { selected: [] }, Ue = (e, n) => {
const { subscribe: t, set: o } = j(z);
var Z = /* @__PURE__ */ ((e) => (e.EDIT = "EDIT", e.SELECT = "SELECT", e.NONE = "NONE", e))(Z || {});
const z = { selected: [] }, Te = (e, n) => {
const { subscribe: t, set: o } = M(z);
let i = n, f = z;
t((m) => f = m);
const w = () => {
t((A) => f = A);
const y = () => {
I(f, z) || o(z);
}, b = () => {
var m;
return ((m = f.selected) == null ? void 0 : m.length) === 0;
}, y = (m) => {
var A;
return ((A = f.selected) == null ? void 0 : A.length) === 0;
}, w = (A) => {
if (b())
return !1;
const v = typeof m == "string" ? m : m.id;
const v = typeof A == "string" ? A : A.id;
return f.selected.some((L) => L.id === v);
}, h = (m, v) => {
const L = e.getAnnotation(m);
}, g = (A, v) => {
const L = e.getAnnotation(A);
if (!L) {
console.warn("Invalid selection: " + m);
console.warn("Invalid selection: " + A);
return;
}
switch (q(L, i)) {
switch (G(L, i)) {
case "EDIT":
o({ selected: [{ id: m, editable: !0 }], event: v });
o({ selected: [{ id: A, editable: !0 }], event: v });
break;
case "SELECT":
o({ selected: [{ id: m }], event: v });
o({ selected: [{ id: A }], event: v });
break;

@@ -107,18 +107,18 @@ default:

}
}, S = (m, v) => {
const L = Array.isArray(m) ? m : [m], O = L.map((a) => e.getAnnotation(a)).filter((a) => !!a);
}, S = (A, v) => {
const L = Array.isArray(A) ? A : [A], O = L.map((a) => e.getAnnotation(a)).filter((a) => !!a);
o({
selected: O.map((a) => {
const u = v === void 0 ? q(a, i) === "EDIT" : v;
const u = v === void 0 ? G(a, i) === "EDIT" : v;
return { id: a.id, editable: u };
})
}), O.length !== L.length && console.warn("Invalid selection", m);
}, r = (m) => {
}), O.length !== L.length && console.warn("Invalid selection", A);
}, r = (A) => {
if (b())
return !1;
const { selected: v } = f;
v.some(({ id: O }) => m.includes(O)) && o({ selected: v.filter(({ id: O }) => !m.includes(O)) });
}, E = (m) => i = m;
v.some(({ id: O }) => A.includes(O)) && o({ selected: v.filter(({ id: O }) => !A.includes(O)) });
}, E = (A) => i = A;
return e.observe(
({ changes: m }) => r((m.deleted || []).map((v) => v.id))
({ changes: A }) => r((A.deleted || []).map((v) => v.id))
), {

@@ -134,35 +134,35 @@ get event() {

},
clear: w,
clear: y,
isEmpty: b,
isSelected: y,
isSelected: w,
setSelected: S,
setUserSelectAction: E,
subscribe: t,
userSelect: h
userSelect: g
};
}, q = (e, n) => typeof n == "function" ? n(e) : n || "EDIT";
}, G = (e, n) => typeof n == "function" ? n(e) : n || "EDIT";
var D = [];
for (var Y = 0; Y < 256; ++Y)
D.push((Y + 256).toString(16).slice(1));
function Z(e, n = 0) {
function K(e, n = 0) {
return (D[e[n + 0]] + D[e[n + 1]] + D[e[n + 2]] + D[e[n + 3]] + "-" + D[e[n + 4]] + D[e[n + 5]] + "-" + D[e[n + 6]] + D[e[n + 7]] + "-" + D[e[n + 8]] + D[e[n + 9]] + "-" + D[e[n + 10]] + D[e[n + 11]] + D[e[n + 12]] + D[e[n + 13]] + D[e[n + 14]] + D[e[n + 15]]).toLowerCase();
}
var $, K = new Uint8Array(16);
function ee() {
var $, ee = new Uint8Array(16);
function te() {
if (!$ && ($ = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !$))
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
return $(K);
return $(ee);
}
var te = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
const G = {
randomUUID: te
var ne = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
const H = {
randomUUID: ne
};
function H(e, n, t) {
if (G.randomUUID && !n && !e)
return G.randomUUID();
function F(e, n, t) {
if (H.randomUUID && !n && !e)
return H.randomUUID();
e = e || {};
var o = e.random || (e.rng || ee)();
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Z(o);
var o = e.random || (e.rng || te)();
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, K(o);
}
const Te = (e) => {
const Oe = (e) => {
const { creator: n, updatedBy: t } = e.target, o = e.bodies.reduce((i, f) => [...i, f.creator, f.updatedBy].filter(Boolean), []);

@@ -174,4 +174,14 @@ return [

].filter((i) => i);
}, Oe = (e, n, t, o) => ({
id: H(),
}, j = (e) => {
const n = (t) => {
const o = { ...t };
return t.created && typeof t.created == "string" && (o.created = new Date(t.created)), t.updated && typeof t.updated == "string" && (o.updated = new Date(t.updated)), o;
};
return {
...e,
bodies: (e.bodies || []).map(n),
target: n(e.target)
};
}, De = (e, n, t, o) => ({
id: F(),
annotation: typeof e == "string" ? e : e.id,

@@ -181,13 +191,13 @@ created: t || /* @__PURE__ */ new Date(),

...n
}), ne = (e, n) => {
}), oe = (e, n) => {
const t = new Set(e.bodies.map((o) => o.id));
return n.bodies.filter((o) => !t.has(o.id));
}, oe = (e, n) => {
}, se = (e, n) => {
const t = new Set(n.bodies.map((o) => o.id));
return e.bodies.filter((o) => !t.has(o.id));
}, se = (e, n) => n.bodies.map((t) => {
}, ie = (e, n) => n.bodies.map((t) => {
const o = e.bodies.find((i) => i.id === t.id);
return { newBody: t, oldBody: o && !I(o, t) ? o : void 0 };
}).filter(({ oldBody: t }) => t).map(({ oldBody: t, newBody: o }) => ({ oldBody: t, newBody: o })), ie = (e, n) => !I(e.target, n.target), F = (e, n) => {
const t = ne(e, n), o = oe(e, n), i = se(e, n);
}).filter(({ oldBody: t }) => t).map(({ oldBody: t, newBody: o }) => ({ oldBody: t, newBody: o })), de = (e, n) => !I(e.target, n.target), J = (e, n) => {
const t = oe(e, n), o = se(e, n), i = ie(e, n);
return {

@@ -199,8 +209,8 @@ oldValue: e,

bodiesUpdated: i.length > 0 ? i : void 0,
targetUpdated: ie(e, n) ? { oldTarget: e.target, newTarget: n.target } : void 0
targetUpdated: de(e, n) ? { oldTarget: e.target, newTarget: n.target } : void 0
};
};
var de = /* @__PURE__ */ ((e) => (e.BODY_ONLY = "BODY_ONLY", e.TARGET_ONLY = "TARGET_ONLY", e))(de || {}), T = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e.SILENT = "SILENT", e))(T || {});
const ae = (e, n) => {
var f, w;
var ae = /* @__PURE__ */ ((e) => (e.BODY_ONLY = "BODY_ONLY", e.TARGET_ONLY = "TARGET_ONLY", e))(ae || {}), T = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e.SILENT = "SILENT", e))(T || {});
const re = (e, n) => {
var f, y;
const { changes: t, origin: o } = n;

@@ -210,5 +220,5 @@ if (!(e.options.origin ? e.options.origin === o : o !== "SILENT"))

if (e.options.ignore) {
const { ignore: b } = e.options, y = (S) => S && S.length > 0;
if (!(y(t.created) || y(t.deleted))) {
const S = (f = t.updated) == null ? void 0 : f.some((E) => y(E.bodiesCreated) || y(E.bodiesDeleted) || y(E.bodiesUpdated)), r = (w = t.updated) == null ? void 0 : w.some((E) => E.targetUpdated);
const { ignore: b } = e.options, w = (S) => S && S.length > 0;
if (!(w(t.created) || w(t.deleted))) {
const S = (f = t.updated) == null ? void 0 : f.some((E) => w(E.bodiesCreated) || w(E.bodiesDeleted) || w(E.bodiesUpdated)), r = (y = t.updated) == null ? void 0 : y.some((E) => E.targetUpdated);
if (b === "BODY_ONLY" && S && !r || b === "TARGET_ONLY" && r && !S)

@@ -220,14 +230,14 @@ return !1;

const b = /* @__PURE__ */ new Set([
...(t.created || []).map((h) => h.id),
...(t.deleted || []).map((h) => h.id),
...(t.updated || []).map(({ oldValue: h }) => h.id)
...(t.created || []).map((g) => g.id),
...(t.deleted || []).map((g) => g.id),
...(t.updated || []).map(({ oldValue: g }) => g.id)
]);
return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((h) => b.has(h));
return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((g) => b.has(g));
} else
return !0;
}, re = (e, n) => {
const t = new Set((e.created || []).map((r) => r.id)), o = new Set((e.updated || []).map(({ newValue: r }) => r.id)), i = new Set((n.created || []).map((r) => r.id)), f = new Set((n.deleted || []).map((r) => r.id)), w = new Set((n.updated || []).map(({ oldValue: r }) => r.id)), b = new Set((n.updated || []).filter(({ oldValue: r }) => t.has(r.id) || o.has(r.id)).map(({ oldValue: r }) => r.id)), y = [
...(e.created || []).filter((r) => !f.has(r.id)).map((r) => w.has(r.id) ? n.updated.find(({ oldValue: E }) => E.id === r.id).newValue : r),
}, ce = (e, n) => {
const t = new Set((e.created || []).map((r) => r.id)), o = new Set((e.updated || []).map(({ newValue: r }) => r.id)), i = new Set((n.created || []).map((r) => r.id)), f = new Set((n.deleted || []).map((r) => r.id)), y = new Set((n.updated || []).map(({ oldValue: r }) => r.id)), b = new Set((n.updated || []).filter(({ oldValue: r }) => t.has(r.id) || o.has(r.id)).map(({ oldValue: r }) => r.id)), w = [
...(e.created || []).filter((r) => !f.has(r.id)).map((r) => y.has(r.id) ? n.updated.find(({ oldValue: E }) => E.id === r.id).newValue : r),
...n.created || []
], h = [
], g = [
...(e.deleted || []).filter((r) => !i.has(r.id)),

@@ -237,6 +247,6 @@ ...(n.deleted || []).filter((r) => !t.has(r.id))

...(e.updated || []).filter(({ newValue: r }) => !f.has(r.id)).map((r) => {
const { oldValue: E, newValue: m } = r;
if (w.has(m.id)) {
const v = n.updated.find((L) => L.oldValue.id === m.id).newValue;
return F(E, v);
const { oldValue: E, newValue: A } = r;
if (y.has(A.id)) {
const v = n.updated.find((L) => L.oldValue.id === A.id).newValue;
return J(E, v);
} else

@@ -247,5 +257,5 @@ return r;

];
return { created: y, deleted: h, updated: S };
return { created: w, deleted: g, updated: S };
}, V = (e) => {
const n = e.id === void 0 ? H() : e.id;
const n = e.id === void 0 ? F() : e.id;
return {

@@ -263,3 +273,3 @@ ...e,

};
}, ce = (e) => e.id !== void 0, De = () => {
}, le = (e) => e.id !== void 0, Re = () => {
const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = [], o = (d, c = {}) => {

@@ -281,5 +291,5 @@ t.push({ onChange: d, options: c });

t.forEach((p) => {
ae(p, l) && p.onChange(l);
re(p, l) && p.onChange(l);
});
}, w = (d, c = T.LOCAL) => {
}, y = (d, c = T.LOCAL) => {
if (d.id && e.get(d.id))

@@ -294,10 +304,10 @@ throw Error(`Cannot add annotation ${d.id} - exists already`);

if (U) {
const C = F(U, l);
const C = J(U, l);
return p === l.id ? e.set(p, l) : (e.delete(p), e.set(l.id, l)), U.bodies.forEach((B) => n.delete(B.id)), l.bodies.forEach((B) => n.set(B.id, l.id)), C;
} else
console.warn(`Cannot update annotation ${p} - does not exist`);
}, y = (d, c = T.LOCAL, l = T.LOCAL) => {
const p = ce(c) ? l : c, U = b(d, c);
}, w = (d, c = T.LOCAL, l = T.LOCAL) => {
const p = le(c) ? l : c, U = b(d, c);
U && f(p, { updated: [U] });
}, h = (d, c = T.LOCAL) => {
}, g = (d, c = T.LOCAL) => {
const l = d.reduce((p, U) => {

@@ -325,3 +335,3 @@ const C = b(U);

e.clear(), n.clear(), f(d, { deleted: c });
}, m = (d, c = !0, l = T.LOCAL) => {
}, A = (d, c = !0, l = T.LOCAL) => {
const p = d.map(V);

@@ -335,4 +345,4 @@ if (c) {

const U = d.reduce((C, B) => {
const P = B.id && e.get(B.id);
return P ? [...C, P] : C;
const W = B.id && e.get(B.id);
return W ? [...C, W] : C;
}, []);

@@ -384,9 +394,9 @@ if (U.length > 0)

l.length > 0 && f(c, { updated: l });
}, g = (d) => {
}, h = (d) => {
const c = e.get(d);
return c ? { ...c } : void 0;
}, A = (d) => {
}, m = (d) => {
const c = n.get(d);
if (c) {
const p = g(c).bodies.find((U) => U.id === d);
const p = h(c).bodies.find((U) => U.id === d);
if (p)

@@ -419,3 +429,3 @@ return p;

f(c, { updated: l });
}, M = (d) => {
}, P = (d) => {
const c = e.get(d.annotation);

@@ -442,12 +452,12 @@ if (c) {

return {
addAnnotation: w,
addAnnotation: y,
addBody: S,
all: r,
bulkAddAnnotation: m,
bulkAddAnnotation: A,
bulkDeleteAnnotation: O,
bulkDeleteBodies: s,
bulkUpdateAnnotation: h,
bulkUpdateAnnotation: g,
bulkUpdateBodies: x,
bulkUpdateTargets: (d, c = T.LOCAL) => {
const l = d.map((p) => M(p)).filter(Boolean);
const l = d.map((p) => P(p)).filter(Boolean);
l.length > 0 && f(c, { updated: l });

@@ -458,14 +468,14 @@ },

deleteBody: u,
getAnnotation: g,
getBody: A,
getAnnotation: h,
getBody: m,
observe: o,
unobserve: i,
updateAnnotation: y,
updateAnnotation: w,
updateBody: N,
updateTarget: (d, c = T.LOCAL) => {
const l = M(d);
const l = P(d);
l && f(c, { updated: [l] });
}
};
}, Re = (e) => ({
}, Be = (e) => ({
...e,

@@ -477,3 +487,3 @@ subscribe: (t) => {

});
let J = () => ({
let Q = () => ({
emit(e, ...n) {

@@ -492,30 +502,30 @@ for (let t = 0, o = this.events[e] || [], i = o.length; t < i; t++)

});
const le = 250, Be = (e) => {
const n = J(), t = [];
const ue = 250, Ie = (e) => {
const n = Q(), t = [];
let o = -1, i = !1, f = 0;
const w = (s) => {
const y = (s) => {
if (!i) {
const { changes: g } = s, A = performance.now();
if (A - f > le)
t.splice(o + 1), t.push(g), o = t.length - 1;
const { changes: h } = s, m = performance.now();
if (m - f > ue)
t.splice(o + 1), t.push(h), o = t.length - 1;
else {
const R = t.length - 1;
t[R] = re(t[R], g);
t[R] = ce(t[R], h);
}
f = A;
f = m;
}
i = !1;
};
e.observe(w, { origin: T.LOCAL });
const b = (s) => s && s.length > 0 && e.bulkDeleteAnnotation(s), y = (s) => s && s.length > 0 && e.bulkAddAnnotation(s, !1), h = (s) => s && s.length > 0 && e.bulkUpdateAnnotation(s.map(({ oldValue: g }) => g)), S = (s) => s && s.length > 0 && e.bulkUpdateAnnotation(s.map(({ newValue: g }) => g)), r = (s) => s && s.length > 0 && e.bulkAddAnnotation(s, !1), E = (s) => s && s.length > 0 && e.bulkDeleteAnnotation(s);
e.observe(y, { origin: T.LOCAL });
const b = (s) => s && s.length > 0 && e.bulkDeleteAnnotation(s), w = (s) => s && s.length > 0 && e.bulkAddAnnotation(s, !1), g = (s) => s && s.length > 0 && e.bulkUpdateAnnotation(s.map(({ oldValue: h }) => h)), S = (s) => s && s.length > 0 && e.bulkUpdateAnnotation(s.map(({ newValue: h }) => h)), r = (s) => s && s.length > 0 && e.bulkAddAnnotation(s, !1), E = (s) => s && s.length > 0 && e.bulkDeleteAnnotation(s);
return {
canRedo: () => t.length - 1 > o,
canUndo: () => o > -1,
destroy: () => e.unobserve(w),
on: (s, g) => n.on(s, g),
destroy: () => e.unobserve(y),
on: (s, h) => n.on(s, h),
redo: () => {
if (t.length - 1 > o) {
i = !0;
const { created: s, updated: g, deleted: A } = t[o + 1];
y(s), S(g), E(A), n.emit("redo", t[o + 1]), o += 1;
const { created: s, updated: h, deleted: m } = t[o + 1];
w(s), S(h), E(m), n.emit("redo", t[o + 1]), o += 1;
}

@@ -526,9 +536,9 @@ },

i = !0;
const { created: s, updated: g, deleted: A } = t[o];
b(s), h(g), r(A), n.emit("undo", t[o]), o -= 1;
const { created: s, updated: h, deleted: m } = t[o];
b(s), g(h), r(m), n.emit("undo", t[o]), o -= 1;
}
}
};
}, Ie = () => {
const { subscribe: e, set: n } = j([]);
}, xe = () => {
const { subscribe: e, set: n } = M([]);
return {

@@ -538,21 +548,21 @@ subscribe: e,

};
}, xe = (e, n, t, o) => {
const { store: i, selection: f, hover: w, viewport: b } = e, y = /* @__PURE__ */ new Map();
let h = [], S, r;
}, ke = (e, n, t, o) => {
const { store: i, selection: f, hover: y, viewport: b } = e, w = /* @__PURE__ */ new Map();
let g = [], S, r;
const E = (a, u) => {
y.has(a) ? y.get(a).push(u) : y.set(a, [u]);
}, m = (a, u) => {
const s = y.get(a);
w.has(a) ? w.get(a).push(u) : w.set(a, [u]);
}, A = (a, u) => {
const s = w.get(a);
if (s) {
const g = s.indexOf(u);
g !== -1 && s.splice(g, 1);
const h = s.indexOf(u);
h !== -1 && s.splice(h, 1);
}
}, v = (a, u, s) => {
y.has(a) && setTimeout(() => {
y.get(a).forEach((g) => {
w.has(a) && setTimeout(() => {
w.get(a).forEach((h) => {
if (t) {
const A = Array.isArray(u) ? u.map((N) => t.serialize(N)) : t.serialize(u), R = s ? s instanceof PointerEvent ? s : t.serialize(s) : void 0;
g(A, R);
const m = Array.isArray(u) ? u.map((N) => t.serialize(N)) : t.serialize(u), R = s ? s instanceof PointerEvent ? s : t.serialize(s) : void 0;
h(m, R);
} else
g(u, s);
h(u, s);
});

@@ -563,33 +573,33 @@ }, 1);

u.forEach((s) => {
const g = h.find((A) => A.id === s.id);
(!g || !I(g, s)) && v("updateAnnotation", s, g);
}), h = h.map((s) => {
const g = u.find(({ id: A }) => A === s.id);
return g || s;
const h = g.find((m) => m.id === s.id);
(!h || !I(h, s)) && v("updateAnnotation", s, h);
}), g = g.map((s) => {
const h = u.find(({ id: m }) => m === s.id);
return h || s;
});
};
f.subscribe(({ selected: a }) => {
if (!(h.length === 0 && a.length === 0)) {
if (h.length === 0 && a.length > 0)
h = a.map(({ id: u }) => i.getAnnotation(u));
else if (h.length > 0 && a.length === 0)
h.forEach((u) => {
if (!(g.length === 0 && a.length === 0)) {
if (g.length === 0 && a.length > 0)
g = a.map(({ id: u }) => i.getAnnotation(u));
else if (g.length > 0 && a.length === 0)
g.forEach((u) => {
const s = i.getAnnotation(u.id);
s && !I(s, u) && v("updateAnnotation", s, u);
}), h = [];
}), g = [];
else {
const u = new Set(h.map((A) => A.id)), s = new Set(a.map(({ id: A }) => A));
h.filter((A) => !s.has(A.id)).forEach((A) => {
const R = i.getAnnotation(A.id);
R && !I(R, A) && v("updateAnnotation", R, A);
}), h = [
const u = new Set(g.map((m) => m.id)), s = new Set(a.map(({ id: m }) => m));
g.filter((m) => !s.has(m.id)).forEach((m) => {
const R = i.getAnnotation(m.id);
R && !I(R, m) && v("updateAnnotation", R, m);
}), g = [
// Remove annotations that were deselected
...h.filter((A) => s.has(A.id)),
...g.filter((m) => s.has(m.id)),
// Add editable annotations that were selected
...a.filter(({ id: A }) => !u.has(A)).map(({ id: A }) => i.getAnnotation(A))
...a.filter(({ id: m }) => !u.has(m)).map(({ id: m }) => i.getAnnotation(m))
];
}
v("selectionChanged", h);
v("selectionChanged", g);
}
}), w.subscribe((a) => {
}), y.subscribe((a) => {
!S && a ? v("mouseEnterAnnotation", i.getAnnotation(a)) : S && !a ? v("mouseLeaveAnnotation", i.getAnnotation(S)) : S && a && (v("mouseLeaveAnnotation", i.getAnnotation(S)), v("mouseEnterAnnotation", i.getAnnotation(a))), S = a;

@@ -599,16 +609,16 @@ }), b == null || b.subscribe((a) => v("viewportIntersect", a.map((u) => i.getAnnotation(u)))), i.observe((a) => {

const { created: u, deleted: s } = a.changes;
(u || []).forEach((A) => v("createAnnotation", A)), (s || []).forEach((A) => v("deleteAnnotation", A)), (a.changes.updated || []).filter((A) => [
...A.bodiesCreated || [],
...A.bodiesDeleted || [],
...A.bodiesUpdated || []
].length > 0).forEach(({ oldValue: A, newValue: R }) => {
const N = h.find((x) => x.id === A.id) || A;
h = h.map((x) => x.id === A.id ? R : x), v("updateAnnotation", R, N);
(u || []).forEach((m) => v("createAnnotation", m)), (s || []).forEach((m) => v("deleteAnnotation", m)), (a.changes.updated || []).filter((m) => [
...m.bodiesCreated || [],
...m.bodiesDeleted || [],
...m.bodiesUpdated || []
].length > 0).forEach(({ oldValue: m, newValue: R }) => {
const N = g.find((x) => x.id === m.id) || m;
g = g.map((x) => x.id === m.id ? R : x), v("updateAnnotation", R, N);
});
}, { origin: T.LOCAL }), i.observe((a) => {
if (h) {
const u = new Set(h.map((g) => g.id)), s = (a.changes.updated || []).filter(({ newValue: g }) => u.has(g.id)).map(({ newValue: g }) => g);
s.length > 0 && (h = h.map((g) => {
const A = s.find((R) => R.id === g.id);
return A || g;
if (g) {
const u = new Set(g.map((h) => h.id)), s = (a.changes.updated || []).filter(({ newValue: h }) => u.has(h.id)).map(({ newValue: h }) => h);
s.length > 0 && (g = g.map((h) => {
const m = s.find((R) => R.id === h.id);
return m || h;
}));

@@ -619,6 +629,6 @@ }

const { updated: s } = u;
a ? (s || []).forEach((g) => v("updateAnnotation", g.oldValue, g.newValue)) : (s || []).forEach((g) => v("updateAnnotation", g.newValue, g.oldValue));
a ? (s || []).forEach((h) => v("updateAnnotation", h.oldValue, h.newValue)) : (s || []).forEach((h) => v("updateAnnotation", h.newValue, h.oldValue));
};
return n.on("undo", O(!0)), n.on("redo", O(!1)), { on: E, off: m, emit: v };
}, ke = (e) => (n) => n.map((t) => e.serialize(t)), ue = (e) => (n) => n.reduce((t, o) => {
return n.on("undo", O(!0)), n.on("redo", O(!1)), { on: E, off: A, emit: v };
}, Ne = (e) => (n) => n.map((t) => e.serialize(t)), fe = (e) => (n) => n.reduce((t, o) => {
const { parsed: i, error: f } = e.parse(o);

@@ -634,3 +644,3 @@ return f ? {

};
}, { parsed: [], failed: [] }), Ne = (e, n, t) => {
}, { parsed: [], failed: [] }), ze = (e, n, t) => {
const { store: o, selection: i } = e, f = (a) => {

@@ -641,11 +651,11 @@ if (t) {

} else
o.addAnnotation(a, T.REMOTE);
}, w = () => i.clear(), b = () => o.clear(), y = (a) => {
o.addAnnotation(j(a), T.REMOTE);
}, y = () => i.clear(), b = () => o.clear(), w = (a) => {
const u = o.getAnnotation(a);
return t && u ? t.serialize(u) : u;
}, h = () => t ? o.all().map(t.serialize) : o.all(), S = () => {
}, g = () => t ? o.all().map(t.serialize) : o.all(), S = () => {
var s;
const u = (((s = i.selected) == null ? void 0 : s.map((g) => g.id)) || []).map((g) => o.getAnnotation(g)).filter(Boolean);
const u = (((s = i.selected) == null ? void 0 : s.map((h) => h.id)) || []).map((h) => o.getAnnotation(h)).filter(Boolean);
return t ? u.map(t.serialize) : u;
}, r = (a, u = !0) => fetch(a).then((s) => s.json()).then((s) => (m(s, u), s)), E = (a) => {
}, r = (a, u = !0) => fetch(a).then((s) => s.json()).then((s) => (A(s, u), s)), E = (a) => {
if (typeof a == "string") {

@@ -660,8 +670,8 @@ const u = o.getAnnotation(a);

}
}, m = (a, u = !0) => {
}, A = (a, u = !0) => {
if (t) {
const { parsed: s, failed: g } = ue(t)(a);
g.length > 0 && console.warn(`Discarded ${g.length} invalid annotations`, g), o.bulkAddAnnotation(s, u, T.REMOTE);
const s = t.parseAll || fe(t), { parsed: h, failed: m } = s(a);
m.length > 0 && console.warn(`Discarded ${m.length} invalid annotations`, m), o.bulkAddAnnotation(h, u, T.REMOTE);
} else
o.bulkAddAnnotation(a, u, T.REMOTE);
o.bulkAddAnnotation(a.map(j), u, T.REMOTE);
}, v = (a, u) => {

@@ -677,3 +687,3 @@ a ? i.setSelected(a, u) : i.clear();

const u = o.getAnnotation(a.id);
return o.updateAnnotation(a), u;
return o.updateAnnotation(j(a)), u;
}

@@ -683,8 +693,8 @@ };

addAnnotation: f,
cancelSelected: w,
cancelSelected: y,
canRedo: n.canRedo,
canUndo: n.canUndo,
clearAnnotations: b,
getAnnotationById: y,
getAnnotations: h,
getAnnotationById: w,
getAnnotations: g,
getSelected: S,

@@ -694,3 +704,3 @@ loadAnnotations: r,

removeAnnotation: E,
setAnnotations: m,
setAnnotations: A,
setSelected: v,

@@ -701,20 +711,20 @@ setUserSelectAction: L,

};
}, fe = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
let pe = (e) => crypto.getRandomValues(new Uint8Array(e)), he = (e, n, t) => {
}, pe = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
let ge = (e) => crypto.getRandomValues(new Uint8Array(e)), he = (e, n, t) => {
let o = (2 << Math.log(e.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * n / e.length);
return (f = n) => {
let w = "";
let y = "";
for (; ; ) {
let b = t(i), y = i;
for (; y--; )
if (w += e[b[y] & o] || "", w.length === f) return w;
let b = t(i), w = i;
for (; w--; )
if (y += e[b[w] & o] || "", y.length === f) return y;
}
};
}, ge = (e, n = 21) => he(e, n, pe), me = (e = 21) => {
}, me = (e, n = 21) => he(e, n, ge), Ae = (e = 21) => {
let n = "", t = crypto.getRandomValues(new Uint8Array(e));
for (; e--; )
n += fe[t[e] & 63];
n += pe[t[e] & 63];
return n;
};
const ze = () => ({ isGuest: !0, id: ge("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Ae = (e) => {
const $e = () => ({ isGuest: !0, id: me("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), be = (e) => {
const n = JSON.stringify(e);

@@ -727,18 +737,18 @@ let t = 0;

return `${t}`;
}, be = (e) => e ? typeof e == "object" ? { ...e } : e : void 0, $e = (e, n) => (Array.isArray(e) ? e : [e]).map((t) => {
const { id: o, type: i, purpose: f, value: w, created: b, modified: y, creator: h, ...S } = t;
}, ve = (e) => e ? typeof e == "object" ? { ...e } : e : void 0, Ve = (e, n) => (Array.isArray(e) ? e : [e]).map((t) => {
const { id: o, type: i, purpose: f, value: y, created: b, modified: w, creator: g, ...S } = t;
return {
id: o || `temp-${Ae(t)}`,
id: o || `temp-${be(t)}`,
annotation: n,
type: i,
purpose: f,
value: w,
creator: be(h),
value: y,
creator: ve(g),
created: b ? new Date(b) : void 0,
updated: y ? new Date(y) : void 0,
updated: w ? new Date(w) : void 0,
...S
};
}), Ve = (e) => e.map((n) => {
}), _e = (e) => e.map((n) => {
var b;
const { annotation: t, created: o, updated: i, ...f } = n, w = {
const { annotation: t, created: o, updated: i, ...f } = n, y = {
...f,

@@ -748,4 +758,4 @@ created: o == null ? void 0 : o.toISOString(),

};
return (b = w.id) != null && b.startsWith("temp-") && delete w.id, w;
}), ve = [
return (b = y.id) != null && b.startsWith("temp-") && delete y.id, y;
}), Ee = [
"#ff7c00",

@@ -769,4 +779,4 @@ // orange

// blue
], Ee = () => {
const e = [...ve];
], we = () => {
const e = [...Ee];
return { assignRandomColor: () => {

@@ -777,3 +787,3 @@ const o = Math.floor(Math.random() * e.length), i = e[o];

}, ye = () => {
const e = Ee();
const e = we();
return { addUser: (o, i) => {

@@ -787,4 +797,4 @@ const f = e.assignRandomColor();

}, removeUser: (o) => e.releaseColor(o.appearance.color) };
}, we = (e, n) => e.every((t) => e.includes(t)) && n.every((t) => e.includes(t)), _e = me(), Ye = (e = ye()) => {
const n = J(), t = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), i = (r, E) => {
}, Ce = (e, n) => e.every((t) => e.includes(t)) && n.every((t) => e.includes(t)), Ye = Ae(), je = (e = ye()) => {
const n = Q(), t = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), i = (r, E) => {
if (t.has(r)) {

@@ -794,7 +804,7 @@ console.warn("Attempt to add user that is already present", r, E);

}
const m = e.addUser(r, E);
const A = e.addUser(r, E);
t.set(r, {
...E,
presenceKey: r,
appearance: m
appearance: A
});

@@ -808,11 +818,11 @@ }, f = (r) => {

e.removeUser(E), t.delete(r);
}, w = (r) => {
const E = new Set(r.map((L) => L.presenceKey)), m = r.filter(({ presenceKey: L }) => !t.has(L)), v = Array.from(t.values()).filter((L) => !E.has(L.presenceKey));
m.forEach(({ presenceKey: L, user: O }) => i(L, O)), v.forEach((L) => {
}, y = (r) => {
const E = new Set(r.map((L) => L.presenceKey)), A = r.filter(({ presenceKey: L }) => !t.has(L)), v = Array.from(t.values()).filter((L) => !E.has(L.presenceKey));
A.forEach(({ presenceKey: L, user: O }) => i(L, O)), v.forEach((L) => {
const { presenceKey: O } = L;
o.has(O) && n.emit("selectionChange", L, null), f(O);
}), (m.length > 0 || v.length > 0) && n.emit("presence", h());
}), (A.length > 0 || v.length > 0) && n.emit("presence", g());
}, b = (r, E) => {
const m = t.get(r);
if (!m) {
const A = t.get(r);
if (!A) {
console.warn("Activity notification from user that is not present");

@@ -822,48 +832,49 @@ return;

const v = o.get(r);
(!v || !we(v, E)) && (o.set(r, E), n.emit("selectionChange", m, E));
}, y = (r, E) => {
const m = t.get(r);
if (!m) {
(!v || !Ce(v, E)) && (o.set(r, E), n.emit("selectionChange", A, E));
}, w = (r, E) => {
const A = t.get(r);
if (!A) {
console.warn("Selection change for user that is not present", r);
return;
}
E ? o.set(r, E) : o.delete(r), n.emit("selectionChange", m, E);
}, h = () => [...Array.from(t.values())];
E ? o.set(r, E) : o.delete(r), n.emit("selectionChange", A, E);
}, g = () => [...Array.from(t.values())];
return {
getPresentUsers: h,
getPresentUsers: g,
notifyActivity: b,
on: (r, E) => n.on(r, E),
syncUsers: w,
updateSelection: y
syncUsers: y,
updateSelection: w
};
};
export {
de as Ignore,
ae as Ignore,
T as Origin,
_e as PRESENCE_KEY,
X as UserSelectAction,
ze as createAnonymousGuest,
Ne as createBaseAnnotator,
Oe as createBody,
Ye as PRESENCE_KEY,
Z as UserSelectAction,
$e as createAnonymousGuest,
ze as createBaseAnnotator,
De as createBody,
ye as createDefaultAppearanceProvider,
Se as createHoverState,
xe as createLifecycleObserver,
Ye as createPresenceState,
Ue as createSelectionState,
De as createStore,
Be as createUndoStack,
Ie as createViewportState,
Ee as defaultColorProvider,
F as diffAnnotations,
Te as getContributors,
re as mergeChanges,
q as onUserSelect,
ue as parseAll,
$e as parseW3CBodies,
be as parseW3CUser,
ke as serializeAll,
Ve as serializeW3CBodies,
ae as shouldNotify,
Re as toSvelteStore
Ue as createHoverState,
ke as createLifecycleObserver,
je as createPresenceState,
Te as createSelectionState,
Re as createStore,
Ie as createUndoStack,
xe as createViewportState,
we as defaultColorProvider,
J as diffAnnotations,
Oe as getContributors,
ce as mergeChanges,
G as onUserSelect,
fe as parseAll,
Ve as parseW3CBodies,
ve as parseW3CUser,
j as reviveDates,
Ne as serializeAll,
_e as serializeW3CBodies,
re as shouldNotify,
Be as toSvelteStore
};
//# sourceMappingURL=annotorious-core.es.js.map
import { Annotation } from './Annotation';
export interface FormatAdapter<A extends Annotation, T extends unknown> {
parse(serialized: T): ParseResult<A>;
parseAll?(serialized: unknown[]): {
parsed: A[];
failed: T[];
};
serialize(core: A): T;

@@ -5,0 +9,0 @@ }

@@ -8,2 +8,10 @@ import { Annotation, AnnotationBody } from '../model/Annotation';

export declare const getContributors: (annotation: Annotation) => User[];
/**
* Converts any string dates in the given annotation(-like)
* object to proper Date objects.
*/
export declare const reviveDates: <A extends Annotation>(annotation: A) => A;
/**
* Shorthand/helper.
*/
export declare const createBody: (annotationOrId: string | Annotation, payload: {

@@ -10,0 +18,0 @@ [key: string]: any;

{
"name": "@annotorious/core",
"version": "3.0.4",
"version": "3.0.5",
"description": "Annotorious core types and functions",

@@ -35,3 +35,3 @@ "author": "Rainer Simon",

"typescript": "5.5.4",
"vite": "^5.4.2",
"vite": "^5.4.3",
"vite-plugin-dts": "^4.1.0",

@@ -38,0 +38,0 @@ "vitest": "^2.0.5"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc