@annotorious/react 3.7.3 → 3.7.5

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 (34) hide show
  1. package/dist/Annotorious.d.ts.map +1 -1
  2. package/dist/annotorious-react.es12.js +22 -8
  3. package/dist/annotorious-react.es12.js.map +1 -1
  4. package/dist/annotorious-react.es13.js +7 -252
  5. package/dist/annotorious-react.es13.js.map +1 -1
  6. package/dist/annotorious-react.es14.js +251 -7
  7. package/dist/annotorious-react.es14.js.map +1 -1
  8. package/dist/annotorious-react.es15.js +9 -398
  9. package/dist/annotorious-react.es15.js.map +1 -1
  10. package/dist/annotorious-react.es16.js +386 -186
  11. package/dist/annotorious-react.es16.js.map +1 -1
  12. package/dist/annotorious-react.es17.js +197 -13
  13. package/dist/annotorious-react.es17.js.map +1 -1
  14. package/dist/annotorious-react.es18.js +14 -21
  15. package/dist/annotorious-react.es18.js.map +1 -1
  16. package/dist/annotorious-react.es19.js +20 -132
  17. package/dist/annotorious-react.es19.js.map +1 -1
  18. package/dist/annotorious-react.es2.js +91 -87
  19. package/dist/annotorious-react.es2.js.map +1 -1
  20. package/dist/annotorious-react.es20.js +133 -6
  21. package/dist/annotorious-react.es20.js.map +1 -1
  22. package/dist/annotorious-react.es21.js +7 -2
  23. package/dist/annotorious-react.es21.js.map +1 -1
  24. package/dist/annotorious-react.es22.js +2 -11
  25. package/dist/annotorious-react.es22.js.map +1 -1
  26. package/dist/annotorious-react.es23.js +9 -125
  27. package/dist/annotorious-react.es23.js.map +1 -1
  28. package/dist/annotorious-react.es24.js +113 -454
  29. package/dist/annotorious-react.es24.js.map +1 -1
  30. package/dist/annotorious-react.es25.js +471 -0
  31. package/dist/annotorious-react.es25.js.map +1 -0
  32. package/dist/annotorious-react.es4.js +5 -5
  33. package/dist/annotorious-react.es9.js +5 -5
  34. package/package.json +10 -9
@@ -1,137 +1,25 @@
1
- function c() {
2
- return typeof window < "u";
3
- }
4
- function u(t) {
5
- return p(t) ? (t.nodeName || "").toLowerCase() : "#document";
6
- }
7
- function i(t) {
8
- var e;
9
- return (t == null || (e = t.ownerDocument) == null ? void 0 : e.defaultView) || window;
10
- }
11
- function N(t) {
12
- var e;
13
- return (e = (p(t) ? t.ownerDocument : t.document) || window.document) == null ? void 0 : e.documentElement;
14
- }
15
- function p(t) {
16
- return c() ? t instanceof Node || t instanceof i(t).Node : !1;
17
- }
18
- function m(t) {
19
- return c() ? t instanceof Element || t instanceof i(t).Element : !1;
20
- }
21
- function w(t) {
22
- return c() ? t instanceof HTMLElement || t instanceof i(t).HTMLElement : !1;
23
- }
24
- function f(t) {
25
- return !c() || typeof ShadowRoot > "u" ? !1 : t instanceof ShadowRoot || t instanceof i(t).ShadowRoot;
26
- }
27
- const E = /* @__PURE__ */ new Set(["inline", "contents"]);
28
- function y(t) {
29
- const {
30
- overflow: e,
31
- overflowX: n,
32
- overflowY: o,
33
- display: r
34
- } = S(t);
35
- return /auto|scroll|overlay|hidden|clip/.test(e + o + n) && !E.has(r);
36
- }
37
- const T = /* @__PURE__ */ new Set(["table", "td", "th"]);
38
- function A(t) {
39
- return T.has(u(t));
40
- }
41
- const v = [":popover-open", ":modal"];
42
- function L(t) {
43
- return v.some((e) => {
44
- try {
45
- return t.matches(e);
46
- } catch {
47
- return !1;
48
- }
1
+ import * as r from "react";
2
+ import { useLayoutEffect as u } from "react";
3
+ var c = typeof document < "u", s = function() {
4
+ }, l = c ? u : s;
5
+ const a = {
6
+ ...r
7
+ }, i = a.useInsertionEffect, E = i || ((e) => e());
8
+ function p(e) {
9
+ const t = r.useRef(() => {
10
+ if (process.env.NODE_ENV !== "production")
11
+ throw new Error("Cannot call an event handler while rendering.");
49
12
  });
50
- }
51
- const D = ["transform", "translate", "scale", "rotate", "perspective"], C = ["transform", "translate", "scale", "rotate", "perspective", "filter"], k = ["paint", "layout", "strict", "content"];
52
- function V(t) {
53
- const e = O(), n = m(t) ? S(t) : t;
54
- return D.some((o) => n[o] ? n[o] !== "none" : !1) || (n.containerType ? n.containerType !== "normal" : !1) || !e && (n.backdropFilter ? n.backdropFilter !== "none" : !1) || !e && (n.filter ? n.filter !== "none" : !1) || C.some((o) => (n.willChange || "").includes(o)) || k.some((o) => (n.contain || "").includes(o));
55
- }
56
- function B(t) {
57
- let e = s(t);
58
- for (; w(e) && !h(e); ) {
59
- if (V(e))
60
- return e;
61
- if (L(e))
62
- return null;
63
- e = s(e);
64
- }
65
- return null;
66
- }
67
- function O() {
68
- return typeof CSS > "u" || !CSS.supports ? !1 : CSS.supports("-webkit-backdrop-filter", "none");
69
- }
70
- const R = /* @__PURE__ */ new Set(["html", "body", "#document"]);
71
- function h(t) {
72
- return R.has(u(t));
73
- }
74
- function S(t) {
75
- return i(t).getComputedStyle(t);
76
- }
77
- function F(t) {
78
- return m(t) ? {
79
- scrollLeft: t.scrollLeft,
80
- scrollTop: t.scrollTop
81
- } : {
82
- scrollLeft: t.scrollX,
83
- scrollTop: t.scrollY
84
- };
85
- }
86
- function s(t) {
87
- if (u(t) === "html")
88
- return t;
89
- const e = (
90
- // Step into the shadow DOM of the parent of a slotted node.
91
- t.assignedSlot || // DOM Element detected.
92
- t.parentNode || // ShadowRoot detected.
93
- f(t) && t.host || // Fallback.
94
- N(t)
95
- );
96
- return f(e) ? e.host : e;
97
- }
98
- function b(t) {
99
- const e = s(t);
100
- return h(e) ? t.ownerDocument ? t.ownerDocument.body : t.body : w(e) && y(e) ? e : b(e);
101
- }
102
- function d(t, e, n) {
103
- var o;
104
- e === void 0 && (e = []), n === void 0 && (n = !0);
105
- const r = b(t), g = r === ((o = t.ownerDocument) == null ? void 0 : o.body), l = i(r);
106
- if (g) {
107
- const a = _(l);
108
- return e.concat(l, l.visualViewport || [], y(r) ? r : [], a && n ? d(a) : []);
109
- }
110
- return e.concat(r, d(r, [], n));
111
- }
112
- function _(t) {
113
- return t.parent && Object.getPrototypeOf(t.parent) ? t.frameElement : null;
13
+ return E(() => {
14
+ t.current = e;
15
+ }), r.useCallback(function() {
16
+ for (var o = arguments.length, f = new Array(o), n = 0; n < o; n++)
17
+ f[n] = arguments[n];
18
+ return t.current == null ? void 0 : t.current(...f);
19
+ }, []);
114
20
  }
115
21
  export {
116
- S as getComputedStyle,
117
- B as getContainingBlock,
118
- N as getDocumentElement,
119
- _ as getFrameElement,
120
- b as getNearestOverflowAncestor,
121
- u as getNodeName,
122
- F as getNodeScroll,
123
- d as getOverflowAncestors,
124
- s as getParentNode,
125
- i as getWindow,
126
- V as isContainingBlock,
127
- m as isElement,
128
- w as isHTMLElement,
129
- h as isLastTraversableNode,
130
- p as isNode,
131
- y as isOverflowElement,
132
- f as isShadowRoot,
133
- A as isTableElement,
134
- L as isTopLayer,
135
- O as isWebKit
22
+ p as useEffectEvent,
23
+ l as useModernLayoutEffect
136
24
  };
137
25
  //# sourceMappingURL=annotorious-react.es19.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es19.js","sources":["../../../node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.mjs"],"sourcesContent":["function hasWindow() {\n return typeof window !== 'undefined';\n}\nfunction getNodeName(node) {\n if (isNode(node)) {\n return (node.nodeName || '').toLowerCase();\n }\n // Mocked nodes in testing environments may not be instances of Node. By\n // returning `#document` an infinite loop won't occur.\n // https://github.com/floating-ui/floating-ui/issues/2317\n return '#document';\n}\nfunction getWindow(node) {\n var _node$ownerDocument;\n return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;\n}\nfunction getDocumentElement(node) {\n var _ref;\n return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;\n}\nfunction isNode(value) {\n if (!hasWindow()) {\n return false;\n }\n return value instanceof Node || value instanceof getWindow(value).Node;\n}\nfunction isElement(value) {\n if (!hasWindow()) {\n return false;\n }\n return value instanceof Element || value instanceof getWindow(value).Element;\n}\nfunction isHTMLElement(value) {\n if (!hasWindow()) {\n return false;\n }\n return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;\n}\nfunction isShadowRoot(value) {\n if (!hasWindow() || typeof ShadowRoot === 'undefined') {\n return false;\n }\n return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;\n}\nconst invalidOverflowDisplayValues = /*#__PURE__*/new Set(['inline', 'contents']);\nfunction isOverflowElement(element) {\n const {\n overflow,\n overflowX,\n overflowY,\n display\n } = getComputedStyle(element);\n return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !invalidOverflowDisplayValues.has(display);\n}\nconst tableElements = /*#__PURE__*/new Set(['table', 'td', 'th']);\nfunction isTableElement(element) {\n return tableElements.has(getNodeName(element));\n}\nconst topLayerSelectors = [':popover-open', ':modal'];\nfunction isTopLayer(element) {\n return topLayerSelectors.some(selector => {\n try {\n return element.matches(selector);\n } catch (_e) {\n return false;\n }\n });\n}\nconst transformProperties = ['transform', 'translate', 'scale', 'rotate', 'perspective'];\nconst willChangeValues = ['transform', 'translate', 'scale', 'rotate', 'perspective', 'filter'];\nconst containValues = ['paint', 'layout', 'strict', 'content'];\nfunction isContainingBlock(elementOrCss) {\n const webkit = isWebKit();\n const css = isElement(elementOrCss) ? getComputedStyle(elementOrCss) : elementOrCss;\n\n // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block\n // https://drafts.csswg.org/css-transforms-2/#individual-transforms\n return transformProperties.some(value => css[value] ? css[value] !== 'none' : false) || (css.containerType ? css.containerType !== 'normal' : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== 'none' : false) || !webkit && (css.filter ? css.filter !== 'none' : false) || willChangeValues.some(value => (css.willChange || '').includes(value)) || containValues.some(value => (css.contain || '').includes(value));\n}\nfunction getContainingBlock(element) {\n let currentNode = getParentNode(element);\n while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {\n if (isContainingBlock(currentNode)) {\n return currentNode;\n } else if (isTopLayer(currentNode)) {\n return null;\n }\n currentNode = getParentNode(currentNode);\n }\n return null;\n}\nfunction isWebKit() {\n if (typeof CSS === 'undefined' || !CSS.supports) return false;\n return CSS.supports('-webkit-backdrop-filter', 'none');\n}\nconst lastTraversableNodeNames = /*#__PURE__*/new Set(['html', 'body', '#document']);\nfunction isLastTraversableNode(node) {\n return lastTraversableNodeNames.has(getNodeName(node));\n}\nfunction getComputedStyle(element) {\n return getWindow(element).getComputedStyle(element);\n}\nfunction getNodeScroll(element) {\n if (isElement(element)) {\n return {\n scrollLeft: element.scrollLeft,\n scrollTop: element.scrollTop\n };\n }\n return {\n scrollLeft: element.scrollX,\n scrollTop: element.scrollY\n };\n}\nfunction getParentNode(node) {\n if (getNodeName(node) === 'html') {\n return node;\n }\n const result =\n // Step into the shadow DOM of the parent of a slotted node.\n node.assignedSlot ||\n // DOM Element detected.\n node.parentNode ||\n // ShadowRoot detected.\n isShadowRoot(node) && node.host ||\n // Fallback.\n getDocumentElement(node);\n return isShadowRoot(result) ? result.host : result;\n}\nfunction getNearestOverflowAncestor(node) {\n const parentNode = getParentNode(node);\n if (isLastTraversableNode(parentNode)) {\n return node.ownerDocument ? node.ownerDocument.body : node.body;\n }\n if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {\n return parentNode;\n }\n return getNearestOverflowAncestor(parentNode);\n}\nfunction getOverflowAncestors(node, list, traverseIframes) {\n var _node$ownerDocument2;\n if (list === void 0) {\n list = [];\n }\n if (traverseIframes === void 0) {\n traverseIframes = true;\n }\n const scrollableAncestor = getNearestOverflowAncestor(node);\n const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);\n const win = getWindow(scrollableAncestor);\n if (isBody) {\n const frameElement = getFrameElement(win);\n return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);\n }\n return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));\n}\nfunction getFrameElement(win) {\n return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;\n}\n\nexport { getComputedStyle, getContainingBlock, getDocumentElement, getFrameElement, getNearestOverflowAncestor, getNodeName, getNodeScroll, getOverflowAncestors, getParentNode, getWindow, isContainingBlock, isElement, isHTMLElement, isLastTraversableNode, isNode, isOverflowElement, isShadowRoot, isTableElement, isTopLayer, isWebKit };\n"],"names":["hasWindow","getNodeName","node","isNode","getWindow","_node$ownerDocument","getDocumentElement","_ref","value","isElement","isHTMLElement","isShadowRoot","invalidOverflowDisplayValues","isOverflowElement","element","overflow","overflowX","overflowY","display","getComputedStyle","tableElements","isTableElement","topLayerSelectors","isTopLayer","selector","transformProperties","willChangeValues","containValues","isContainingBlock","elementOrCss","webkit","isWebKit","css","getContainingBlock","currentNode","getParentNode","isLastTraversableNode","lastTraversableNodeNames","getNodeScroll","result","getNearestOverflowAncestor","parentNode","getOverflowAncestors","list","traverseIframes","_node$ownerDocument2","scrollableAncestor","isBody","win","frameElement","getFrameElement"],"mappings":"AAAA,SAASA,IAAY;AACnB,SAAO,OAAO,SAAW;AAC3B;AACA,SAASC,EAAYC,GAAM;AACzB,SAAIC,EAAOD,CAAI,KACLA,EAAK,YAAY,IAAI,YAAW,IAKnC;AACT;AACA,SAASE,EAAUF,GAAM;AACvB,MAAIG;AACJ,UAAQH,KAAQ,SAASG,IAAsBH,EAAK,kBAAkB,OAAO,SAASG,EAAoB,gBAAgB;AAC5H;AACA,SAASC,EAAmBJ,GAAM;AAChC,MAAIK;AACJ,UAAQA,KAAQJ,EAAOD,CAAI,IAAIA,EAAK,gBAAgBA,EAAK,aAAa,OAAO,aAAa,OAAO,SAASK,EAAK;AACjH;AACA,SAASJ,EAAOK,GAAO;AACrB,SAAKR,EAAS,IAGPQ,aAAiB,QAAQA,aAAiBJ,EAAUI,CAAK,EAAE,OAFzD;AAGX;AACA,SAASC,EAAUD,GAAO;AACxB,SAAKR,EAAS,IAGPQ,aAAiB,WAAWA,aAAiBJ,EAAUI,C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QAAMqC;AAAA;AAAA,IAENrC,EAAK;AAAA,IAELA,EAAK;AAAA,IAELS,EAAaT,CAAI,KAAKA,EAAK;AAAA,IAE3BI,EAAmBJ,CAAI;AAAA;AACvB,SAAOS,EAAa4B,CAAM,IAAIA,EAAO,OAAOA;AAC9C;AACA,SAASC,EAA2BtC,GAAM;AACxC,QAAMuC,IAAaN,EAAcjC,CAAI;AACrC,SAAIkC,EAAsBK,CAAU,IAC3BvC,EAAK,gBAAgBA,EAAK,cAAc,OAAOA,EAAK,OAEzDQ,EAAc+B,CAAU,KAAK5B,EAAkB4B,CAAU,IACpDA,IAEFD,EAA2BC,CAAU;AAC9C;AACA,SAASC,EAAqBxC,GAAMyC,GAAMC,GAAiB;AACzD,MAAIC;AACJ,EAAIF,MAAS,WACXA,IAAO,CAAA,IAELC,MAAoB,WACtBA,IAAkB;AAEpB,QAAME,IAAqBN,EAA2BtC,CAAI,GACpD6C,IAASD,QAAyBD,IAAuB3C,EAAK,kBAAkB,OAAO,SAAS2C,EAAqB,OACrHG,IAAM5C,EAAU0C,CAAkB;AACxC,MAAIC,GAAQ;AACV,UAAME,IAAeC,EAAgBF,CAAG;AACxC,WAAOL,EAAK,OAAOK,GAAKA,EAAI,kBAAkB,CAAA,GAAInC,EAAkBiC,CAAkB,IAAIA,IAAqB,CAAA,GAAIG,KAAgBL,IAAkBF,EAAqBO,CAAY,IAAI,EAAE;AAAA,EAC9L;AACA,SAAON,EAAK,OAAOG,GAAoBJ,EAAqBI,GAAoB,CAAA,GAAIF,CAAe,CAAC;AACtG;AACA,SAASM,EAAgBF,GAAK;AAC5B,SAAOA,EAAI,UAAU,OAAO,eAAeA,EAAI,MAAM,IAAIA,EAAI,eAAe;AAC9E;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"annotorious-react.es19.js","sources":["../../../node_modules/@floating-ui/react/dist/floating-ui.react.utils.mjs"],"sourcesContent":["import { isShadowRoot, isHTMLElement } from '@floating-ui/utils/dom';\nimport * as React from 'react';\nimport { useLayoutEffect } from 'react';\nimport { floor } from '@floating-ui/utils';\nimport { tabbable } from 'tabbable';\n\n// Avoid Chrome DevTools blue warning.\nfunction getPlatform() {\n const uaData = navigator.userAgentData;\n if (uaData != null && uaData.platform) {\n return uaData.platform;\n }\n return navigator.platform;\n}\nfunction getUserAgent() {\n const uaData = navigator.userAgentData;\n if (uaData && Array.isArray(uaData.brands)) {\n return uaData.brands.map(_ref => {\n let {\n brand,\n version\n } = _ref;\n return brand + \"/\" + version;\n }).join(' ');\n }\n return navigator.userAgent;\n}\nfunction isSafari() {\n // Chrome DevTools does not complain about navigator.vendor\n return /apple/i.test(navigator.vendor);\n}\nfunction isAndroid() {\n const re = /android/i;\n return re.test(getPlatform()) || re.test(getUserAgent());\n}\nfunction isMac() {\n return getPlatform().toLowerCase().startsWith('mac') && !navigator.maxTouchPoints;\n}\nfunction isJSDOM() {\n return getUserAgent().includes('jsdom/');\n}\n\nconst FOCUSABLE_ATTRIBUTE = 'data-floating-ui-focusable';\nconst TYPEABLE_SELECTOR = \"input:not([type='hidden']):not([disabled]),\" + \"[contenteditable]:not([contenteditable='false']),textarea:not([disabled])\";\nconst ARROW_LEFT = 'ArrowLeft';\nconst ARROW_RIGHT = 'ArrowRight';\nconst ARROW_UP = 'ArrowUp';\nconst ARROW_DOWN = 'ArrowDown';\n\nfunction activeElement(doc) {\n let activeElement = doc.activeElement;\n while (((_activeElement = activeElement) == null || (_activeElement = _activeElement.shadowRoot) == null ? void 0 : _activeElement.activeElement) != null) {\n var _activeElement;\n activeElement = activeElement.shadowRoot.activeElement;\n }\n return activeElement;\n}\nfunction contains(parent, child) {\n if (!parent || !child) {\n return false;\n }\n const rootNode = child.getRootNode == null ? void 0 : child.getRootNode();\n\n // First, attempt with faster native method\n if (parent.contains(child)) {\n return true;\n }\n\n // then fallback to custom implementation with Shadow DOM support\n if (rootNode && isShadowRoot(rootNode)) {\n let next = child;\n while (next) {\n if (parent === next) {\n return true;\n }\n // @ts-ignore\n next = next.parentNode || next.host;\n }\n }\n\n // Give up, the result is false\n return false;\n}\nfunction getTarget(event) {\n if ('composedPath' in event) {\n return event.composedPath()[0];\n }\n\n // TS thinks `event` is of type never as it assumes all browsers support\n // `composedPath()`, but browsers without shadow DOM don't.\n return event.target;\n}\nfunction isEventTargetWithin(event, node) {\n if (node == null) {\n return false;\n }\n if ('composedPath' in event) {\n return event.composedPath().includes(node);\n }\n\n // TS thinks `event` is of type never as it assumes all browsers support composedPath, but browsers without shadow dom don't\n const e = event;\n return e.target != null && node.contains(e.target);\n}\nfunction isRootElement(element) {\n return element.matches('html,body');\n}\nfunction getDocument(node) {\n return (node == null ? void 0 : node.ownerDocument) || document;\n}\nfunction isTypeableElement(element) {\n return isHTMLElement(element) && element.matches(TYPEABLE_SELECTOR);\n}\nfunction isTypeableCombobox(element) {\n if (!element) return false;\n return element.getAttribute('role') === 'combobox' && isTypeableElement(element);\n}\nfunction matchesFocusVisible(element) {\n // We don't want to block focus from working with `visibleOnly`\n // (JSDOM doesn't match `:focus-visible` when the element has `:focus`)\n if (!element || isJSDOM()) return true;\n try {\n return element.matches(':focus-visible');\n } catch (_e) {\n return true;\n }\n}\nfunction getFloatingFocusElement(floatingElement) {\n if (!floatingElement) {\n return null;\n }\n // Try to find the element that has `{...getFloatingProps()}` spread on it.\n // This indicates the floating element is acting as a positioning wrapper, and\n // so focus should be managed on the child element with the event handlers and\n // aria props.\n return floatingElement.hasAttribute(FOCUSABLE_ATTRIBUTE) ? floatingElement : floatingElement.querySelector(\"[\" + FOCUSABLE_ATTRIBUTE + \"]\") || floatingElement;\n}\n\nfunction getNodeChildren(nodes, id, onlyOpenChildren) {\n if (onlyOpenChildren === void 0) {\n onlyOpenChildren = true;\n }\n const directChildren = nodes.filter(node => {\n var _node$context;\n return node.parentId === id && (!onlyOpenChildren || ((_node$context = node.context) == null ? void 0 : _node$context.open));\n });\n return directChildren.flatMap(child => [child, ...getNodeChildren(nodes, child.id, onlyOpenChildren)]);\n}\nfunction getDeepestNode(nodes, id) {\n let deepestNodeId;\n let maxDepth = -1;\n function findDeepest(nodeId, depth) {\n if (depth > maxDepth) {\n deepestNodeId = nodeId;\n maxDepth = depth;\n }\n const children = getNodeChildren(nodes, nodeId);\n children.forEach(child => {\n findDeepest(child.id, depth + 1);\n });\n }\n findDeepest(id, 0);\n return nodes.find(node => node.id === deepestNodeId);\n}\nfunction getNodeAncestors(nodes, id) {\n var _nodes$find;\n let allAncestors = [];\n let currentParentId = (_nodes$find = nodes.find(node => node.id === id)) == null ? void 0 : _nodes$find.parentId;\n while (currentParentId) {\n const currentNode = nodes.find(node => node.id === currentParentId);\n currentParentId = currentNode == null ? void 0 : currentNode.parentId;\n if (currentNode) {\n allAncestors = allAncestors.concat(currentNode);\n }\n }\n return allAncestors;\n}\n\nfunction stopEvent(event) {\n event.preventDefault();\n event.stopPropagation();\n}\nfunction isReactEvent(event) {\n return 'nativeEvent' in event;\n}\n\n// License: https://github.com/adobe/react-spectrum/blob/b35d5c02fe900badccd0cf1a8f23bb593419f238/packages/@react-aria/utils/src/isVirtualEvent.ts\nfunction isVirtualClick(event) {\n // FIXME: Firefox is now emitting a deprecation warning for `mozInputSource`.\n // Try to find a workaround for this. `react-aria` source still has the check.\n if (event.mozInputSource === 0 && event.isTrusted) {\n return true;\n }\n if (isAndroid() && event.pointerType) {\n return event.type === 'click' && event.buttons === 1;\n }\n return event.detail === 0 && !event.pointerType;\n}\nfunction isVirtualPointerEvent(event) {\n if (isJSDOM()) return false;\n return !isAndroid() && event.width === 0 && event.height === 0 || isAndroid() && event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'mouse' ||\n // iOS VoiceOver returns 0.333• for width/height.\n event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'touch';\n}\nfunction isMouseLikePointerType(pointerType, strict) {\n // On some Linux machines with Chromium, mouse inputs return a `pointerType`\n // of \"pen\": https://github.com/floating-ui/floating-ui/issues/2015\n const values = ['mouse', 'pen'];\n if (!strict) {\n values.push('', undefined);\n }\n return values.includes(pointerType);\n}\n\nvar isClient = typeof document !== 'undefined';\n\nvar noop = function noop() {};\nvar index = isClient ? useLayoutEffect : noop;\n\n// https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379\nconst SafeReact = {\n ...React\n};\n\nfunction useLatestRef(value) {\n const ref = React.useRef(value);\n index(() => {\n ref.current = value;\n });\n return ref;\n}\nconst useInsertionEffect = SafeReact.useInsertionEffect;\nconst useSafeInsertionEffect = useInsertionEffect || (fn => fn());\nfunction useEffectEvent(callback) {\n const ref = React.useRef(() => {\n if (process.env.NODE_ENV !== \"production\") {\n throw new Error('Cannot call an event handler while rendering.');\n }\n });\n useSafeInsertionEffect(() => {\n ref.current = callback;\n });\n return React.useCallback(function () {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n return ref.current == null ? void 0 : ref.current(...args);\n }, []);\n}\n\nfunction isDifferentGridRow(index, cols, prevRow) {\n return Math.floor(index / cols) !== prevRow;\n}\nfunction isIndexOutOfListBounds(listRef, index) {\n return index < 0 || index >= listRef.current.length;\n}\nfunction getMinListIndex(listRef, disabledIndices) {\n return findNonDisabledListIndex(listRef, {\n disabledIndices\n });\n}\nfunction getMaxListIndex(listRef, disabledIndices) {\n return findNonDisabledListIndex(listRef, {\n decrement: true,\n startingIndex: listRef.current.length,\n disabledIndices\n });\n}\nfunction findNonDisabledListIndex(listRef, _temp) {\n let {\n startingIndex = -1,\n decrement = false,\n disabledIndices,\n amount = 1\n } = _temp === void 0 ? {} : _temp;\n let index = startingIndex;\n do {\n index += decrement ? -amount : amount;\n } while (index >= 0 && index <= listRef.current.length - 1 && isListIndexDisabled(listRef, index, disabledIndices));\n return index;\n}\nfunction getGridNavigatedIndex(listRef, _ref) {\n let {\n event,\n orientation,\n loop,\n rtl,\n cols,\n disabledIndices,\n minIndex,\n maxIndex,\n prevIndex,\n stopEvent: stop = false\n } = _ref;\n let nextIndex = prevIndex;\n if (event.key === ARROW_UP) {\n stop && stopEvent(event);\n if (prevIndex === -1) {\n nextIndex = maxIndex;\n } else {\n nextIndex = findNonDisabledListIndex(listRef, {\n startingIndex: nextIndex,\n amount: cols,\n decrement: true,\n disabledIndices\n });\n if (loop && (prevIndex - cols < minIndex || nextIndex < 0)) {\n const col = prevIndex % cols;\n const maxCol = maxIndex % cols;\n const offset = maxIndex - (maxCol - col);\n if (maxCol === col) {\n nextIndex = maxIndex;\n } else {\n nextIndex = maxCol > col ? offset : offset - cols;\n }\n }\n }\n if (isIndexOutOfListBounds(listRef, nextIndex)) {\n nextIndex = prevIndex;\n }\n }\n if (event.key === ARROW_DOWN) {\n stop && stopEvent(event);\n if (prevIndex === -1) {\n nextIndex = minIndex;\n } else {\n nextIndex = findNonDisabledListIndex(listRef, {\n startingIndex: prevIndex,\n amount: cols,\n disabledIndices\n });\n if (loop && prevIndex + cols > maxIndex) {\n nextIndex = findNonDisabledListIndex(listRef, {\n startingIndex: prevIndex % cols - cols,\n amount: cols,\n disabledIndices\n });\n }\n }\n if (isIndexOutOfListBounds(listRef, nextIndex)) {\n nextIndex = prevIndex;\n }\n }\n\n // Remains on the same row/column.\n if (orientation === 'both') {\n const prevRow = floor(prevIndex / cols);\n if (event.key === (rtl ? ARROW_LEFT : ARROW_RIGHT)) {\n stop && stopEvent(event);\n if (prevIndex % cols !== cols - 1) {\n nextIndex = findNonDisabledListIndex(listRef, {\n startingIndex: prevIndex,\n disabledIndices\n });\n if (loop && isDifferentGridRow(nextIndex, cols, prevRow)) {\n nextIndex = findNonDisabledListIndex(listRef, {\n startingIndex: prevIndex - prevIndex % cols - 1,\n disabledIndices\n });\n }\n } else if (loop) {\n nextIndex = findNonDisabledListIndex(listRef, {\n startingIndex: prevIndex - prevIndex % cols - 1,\n disabledIndices\n });\n }\n if (isDifferentGridRow(nextIndex, cols, prevRow)) {\n nextIndex = prevIndex;\n }\n }\n if (event.key === (rtl ? ARROW_RIGHT : ARROW_LEFT)) {\n stop && stopEvent(event);\n if (prevIndex % cols !== 0) {\n nextIndex = findNonDisabledListIndex(listRef, {\n startingIndex: prevIndex,\n decrement: true,\n disabledIndices\n });\n if (loop && isDifferentGridRow(nextIndex, cols, prevRow)) {\n nextIndex = findNonDisabledListIndex(listRef, {\n startingIndex: prevIndex + (cols - prevIndex % cols),\n decrement: true,\n disabledIndices\n });\n }\n } else if (loop) {\n nextIndex = findNonDisabledListIndex(listRef, {\n startingIndex: prevIndex + (cols - prevIndex % cols),\n decrement: true,\n disabledIndices\n });\n }\n if (isDifferentGridRow(nextIndex, cols, prevRow)) {\n nextIndex = prevIndex;\n }\n }\n const lastRow = floor(maxIndex / cols) === prevRow;\n if (isIndexOutOfListBounds(listRef, nextIndex)) {\n if (loop && lastRow) {\n nextIndex = event.key === (rtl ? ARROW_RIGHT : ARROW_LEFT) ? maxIndex : findNonDisabledListIndex(listRef, {\n startingIndex: prevIndex - prevIndex % cols - 1,\n disabledIndices\n });\n } else {\n nextIndex = prevIndex;\n }\n }\n }\n return nextIndex;\n}\n\n/** For each cell index, gets the item index that occupies that cell */\nfunction createGridCellMap(sizes, cols, dense) {\n const cellMap = [];\n let startIndex = 0;\n sizes.forEach((_ref2, index) => {\n let {\n width,\n height\n } = _ref2;\n if (width > cols) {\n if (process.env.NODE_ENV !== \"production\") {\n throw new Error(\"[Floating UI]: Invalid grid - item width at index \" + index + \" is greater than grid columns\");\n }\n }\n let itemPlaced = false;\n if (dense) {\n startIndex = 0;\n }\n while (!itemPlaced) {\n const targetCells = [];\n for (let i = 0; i < width; i++) {\n for (let j = 0; j < height; j++) {\n targetCells.push(startIndex + i + j * cols);\n }\n }\n if (startIndex % cols + width <= cols && targetCells.every(cell => cellMap[cell] == null)) {\n targetCells.forEach(cell => {\n cellMap[cell] = index;\n });\n itemPlaced = true;\n } else {\n startIndex++;\n }\n }\n });\n\n // convert into a non-sparse array\n return [...cellMap];\n}\n\n/** Gets cell index of an item's corner or -1 when index is -1. */\nfunction getGridCellIndexOfCorner(index, sizes, cellMap, cols, corner) {\n if (index === -1) return -1;\n const firstCellIndex = cellMap.indexOf(index);\n const sizeItem = sizes[index];\n switch (corner) {\n case 'tl':\n return firstCellIndex;\n case 'tr':\n if (!sizeItem) {\n return firstCellIndex;\n }\n return firstCellIndex + sizeItem.width - 1;\n case 'bl':\n if (!sizeItem) {\n return firstCellIndex;\n }\n return firstCellIndex + (sizeItem.height - 1) * cols;\n case 'br':\n return cellMap.lastIndexOf(index);\n }\n}\n\n/** Gets all cell indices that correspond to the specified indices */\nfunction getGridCellIndices(indices, cellMap) {\n return cellMap.flatMap((index, cellIndex) => indices.includes(index) ? [cellIndex] : []);\n}\nfunction isListIndexDisabled(listRef, index, disabledIndices) {\n if (typeof disabledIndices === 'function') {\n return disabledIndices(index);\n } else if (disabledIndices) {\n return disabledIndices.includes(index);\n }\n const element = listRef.current[index];\n return element == null || element.hasAttribute('disabled') || element.getAttribute('aria-disabled') === 'true';\n}\n\nconst getTabbableOptions = () => ({\n getShadowRoot: true,\n displayCheck:\n // JSDOM does not support the `tabbable` library. To solve this we can\n // check if `ResizeObserver` is a real function (not polyfilled), which\n // determines if the current environment is JSDOM-like.\n typeof ResizeObserver === 'function' && ResizeObserver.toString().includes('[native code]') ? 'full' : 'none'\n});\nfunction getTabbableIn(container, dir) {\n const list = tabbable(container, getTabbableOptions());\n const len = list.length;\n if (len === 0) return;\n const active = activeElement(getDocument(container));\n const index = list.indexOf(active);\n const nextIndex = index === -1 ? dir === 1 ? 0 : len - 1 : index + dir;\n return list[nextIndex];\n}\nfunction getNextTabbable(referenceElement) {\n return getTabbableIn(getDocument(referenceElement).body, 1) || referenceElement;\n}\nfunction getPreviousTabbable(referenceElement) {\n return getTabbableIn(getDocument(referenceElement).body, -1) || referenceElement;\n}\nfunction isOutsideEvent(event, container) {\n const containerElement = container || event.currentTarget;\n const relatedTarget = event.relatedTarget;\n return !relatedTarget || !contains(containerElement, relatedTarget);\n}\nfunction disableFocusInside(container) {\n const tabbableElements = tabbable(container, getTabbableOptions());\n tabbableElements.forEach(element => {\n element.dataset.tabindex = element.getAttribute('tabindex') || '';\n element.setAttribute('tabindex', '-1');\n });\n}\nfunction enableFocusInside(container) {\n const elements = container.querySelectorAll('[data-tabindex]');\n elements.forEach(element => {\n const tabindex = element.dataset.tabindex;\n delete element.dataset.tabindex;\n if (tabindex) {\n element.setAttribute('tabindex', tabindex);\n } else {\n element.removeAttribute('tabindex');\n }\n });\n}\n\nexport { activeElement, contains, createGridCellMap, disableFocusInside, enableFocusInside, findNonDisabledListIndex, getDeepestNode, getDocument, getFloatingFocusElement, getGridCellIndexOfCorner, getGridCellIndices, getGridNavigatedIndex, getMaxListIndex, getMinListIndex, getNextTabbable, getNodeAncestors, getNodeChildren, getPlatform, getPreviousTabbable, getTabbableOptions, getTarget, getUserAgent, isAndroid, isDifferentGridRow, isEventTargetWithin, isIndexOutOfListBounds, isJSDOM, isListIndexDisabled, isMac, isMouseLikePointerType, isOutsideEvent, isReactEvent, isRootElement, isSafari, isTypeableCombobox, isTypeableElement, isVirtualClick, isVirtualPointerEvent, matchesFocusVisible, stopEvent, useEffectEvent, useLatestRef, index as useModernLayoutEffect };\n"],"names":["isClient","noop","index","useLayoutEffect","SafeReact","React","useInsertionEffect","useSafeInsertionEffect","fn","useEffectEvent","callback","ref","_len","args","_key"],"mappings":";;AAsNA,IAAIA,IAAW,OAAO,WAAa,KAE/BC,IAAO,WAAgB;AAAC,GACxBC,IAAQF,IAAWG,IAAkBF;AAGzC,MAAMG,IAAY;AAAA,EAChB,GAAGC;AACL,GASMC,IAAqBF,EAAU,oBAC/BG,IAAyBD,MAAuB,CAAAE,MAAMA;AAC5D,SAASC,EAAeC,GAAU;AAChC,QAAMC,IAAMN,EAAM,OAAO,MAAM;AAC7B,QAAI,QAAQ,IAAI,aAAa;AAC3B,YAAM,IAAI,MAAM,+CAA+C;AAAA,EAEnE,CAAC;AACD,SAAAE,EAAuB,MAAM;AAC3B,IAAAI,EAAI,UAAUD;AAAA,EAChB,CAAC,GACML,EAAM,YAAY,WAAY;AACnC,aAASO,IAAO,UAAU,QAAQC,IAAO,IAAI,MAAMD,CAAI,GAAGE,IAAO,GAAGA,IAAOF,GAAME;AAC/E,MAAAD,EAAKC,CAAI,IAAI,UAAUA,CAAI;AAE7B,WAAOH,EAAI,WAAW,OAAO,SAASA,EAAI,QAAQ,GAAGE,CAAI;AAAA,EAC3D,GAAG,CAAA,CAAE;AACP;","x_google_ignoreList":[0]}
@@ -1,138 +1,142 @@
1
1
  import { jsx as I } from "react/jsx-runtime";
2
- import { createContext as J, forwardRef as N, useState as d, useRef as U, useImperativeHandle as j, useEffect as S, useContext as h } from "react";
3
- import { useDebounce as O } from "./annotorious-react.es12.js";
4
- const f = J({
2
+ import { dequal as O } from "./annotorious-react.es12.js";
3
+ import { createContext as U, forwardRef as j, useState as v, useRef as P, useImperativeHandle as k, useEffect as w, useContext as h } from "react";
4
+ import { useDebounce as _ } from "./annotorious-react.es13.js";
5
+ const f = U({
5
6
  anno: void 0,
6
7
  setAnno: void 0,
7
8
  annotations: [],
8
9
  selection: { selected: [] }
9
- }), K = N((t, e) => {
10
- const [n, c] = d(null), [a, o] = d([]), [u, s] = d({ selected: [], previous: [] }), m = U([]);
11
- return j(e, () => n), S(() => {
12
- if (n) {
13
- const { selection: p, store: r } = n.state;
14
- r.all().length > 0 && o(r.all());
15
- const A = () => o(() => r.all());
16
- r.observe(A);
10
+ }), y = (t, n) => {
11
+ const { event: e, ...r } = t, { event: s, ...o } = n;
12
+ return O(r, o) ? (e == null ? void 0 : e.timeStamp) === (s == null ? void 0 : s.timeStamp) : !1;
13
+ }, Q = j((t, n) => {
14
+ const [e, r] = v(null), [s, o] = v([]), [u, c] = v({ selected: [], previous: [] }), V = P([]);
15
+ return k(n, () => e), w(() => {
16
+ if (e) {
17
+ const { selection: p, store: i } = e.state;
18
+ i.all().length > 0 && o(i.all());
19
+ const A = () => o(() => i.all());
20
+ i.observe(A);
17
21
  let l;
18
- const g = p.subscribe(({ selected: w, ...D }) => {
19
- l && r.unobserve(l);
20
- const R = (w || []).map(({ id: i, editable: v }) => ({ annotation: r.getAnnotation(i), editable: v }));
21
- s((i) => {
22
- const v = {
23
- selected: R,
24
- previous: i.selected,
25
- ...D
22
+ const m = p.subscribe(({ selected: S, ...R }) => {
23
+ l && i.unobserve(l);
24
+ const q = (S || []).map(({ id: a, editable: d }) => ({ annotation: i.getAnnotation(a), editable: d }));
25
+ c((a) => {
26
+ const d = {
27
+ selected: q,
28
+ previous: a.selected,
29
+ ...R
26
30
  };
27
- return JSON.stringify(i) === JSON.stringify(v) ? i : (m.current = i.selected, v);
28
- }), l = (i) => {
29
- const { updated: v } = i.changes;
30
- s((V) => ({
31
- ...V,
32
- selected: V.selected.map(({ annotation: x, editable: C }) => {
33
- const H = v.find((y) => y.oldValue.id === x.id);
31
+ return y(a, d) ? a : (V.current = a.selected, d);
32
+ }), l = (a) => {
33
+ const { updated: d } = a.changes;
34
+ c((g) => ({
35
+ ...g,
36
+ selected: g.selected.map(({ annotation: x, editable: C }) => {
37
+ const H = d.find((E) => E.oldValue.id === x.id);
34
38
  return H ? { annotation: H.newValue, editable: C } : { annotation: x, editable: C };
35
39
  })
36
40
  }));
37
- }, r.observe(l, { annotations: w.map(({ id: i }) => i) });
41
+ }, i.observe(l, { annotations: S.map(({ id: a }) => a) });
38
42
  });
39
43
  return () => {
40
- r.unobserve(A), g();
44
+ i.unobserve(A), m();
41
45
  };
42
46
  }
43
- }, [n]), /* @__PURE__ */ I(f.Provider, { value: {
44
- anno: n,
45
- setAnno: c,
46
- annotations: a,
47
+ }, [e]), /* @__PURE__ */ I(f.Provider, { value: {
48
+ anno: e,
49
+ setAnno: r,
50
+ annotations: s,
47
51
  selection: u
48
52
  }, children: t.children });
49
53
  }), b = () => {
50
54
  const { anno: t } = h(f);
51
55
  return t;
52
- }, E = () => {
56
+ }, z = () => {
53
57
  const t = b();
54
58
  return t == null ? void 0 : t.state.store;
55
- }, P = () => {
59
+ }, B = () => {
56
60
  const { annotations: t } = h(f);
57
61
  return t;
58
- }, k = (t) => {
59
- const { annotations: e } = h(f);
60
- return O(e, t);
61
- }, L = (t) => t ? k(t) : P(), q = (t, e) => {
62
- const n = E(), [c, a] = d(
63
- n == null ? void 0 : n.getAnnotation(t)
62
+ }, F = (t) => {
63
+ const { annotations: n } = h(f);
64
+ return _(n, t);
65
+ }, T = (t) => t ? F(t) : B(), G = (t, n) => {
66
+ const e = z(), [r, s] = v(
67
+ e == null ? void 0 : e.getAnnotation(t)
64
68
  );
65
- return S(() => {
66
- if (!n) return;
69
+ return w(() => {
70
+ if (!e) return;
67
71
  const o = (u) => {
68
- const s = u.changes.updated[0];
69
- s && a(s.newValue);
72
+ const c = u.changes.updated[0];
73
+ c && s(c.newValue);
70
74
  };
71
- return n.observe(o, { ...e, annotations: t }), () => n.unobserve(o);
72
- }, []), c;
73
- }, M = (t) => {
74
- const e = b(), n = q(t);
75
- return e && n ? e.state.selection.evalSelectAction(n) : void 0;
76
- }, Q = () => {
75
+ return e.observe(o, { ...n, annotations: t }), () => e.unobserve(o);
76
+ }, []), r;
77
+ }, W = (t) => {
78
+ const n = b(), e = G(t);
79
+ return n && e ? n.state.selection.evalSelectAction(e) : void 0;
80
+ }, X = () => {
77
81
  const { selection: t } = h(f);
78
82
  return t;
79
- }, T = () => {
80
- const t = b(), [e, n] = d();
81
- return S(() => {
83
+ }, Y = () => {
84
+ const t = b(), [n, e] = v();
85
+ return w(() => {
82
86
  if (!t) return;
83
- const { hover: c, store: a } = t.state, o = c.subscribe((u) => {
87
+ const { hover: r, store: s } = t.state, o = r.subscribe((u) => {
84
88
  if (u) {
85
- const s = a.getAnnotation(u);
86
- n(s);
89
+ const c = s.getAnnotation(u);
90
+ e(c);
87
91
  } else
88
- n(void 0);
92
+ e(void 0);
89
93
  });
90
94
  return () => {
91
95
  o();
92
96
  };
93
- }, [t]), e;
94
- }, W = () => {
97
+ }, [t]), n;
98
+ }, Z = () => {
95
99
  const t = b();
96
100
  return t == null ? void 0 : t.getUser();
97
- }, _ = () => {
98
- const t = b(), [e, n] = d([]);
99
- return S(() => {
101
+ }, D = () => {
102
+ const t = b(), [n, e] = v([]);
103
+ return w(() => {
100
104
  if (t) {
101
- const { store: c, viewport: a } = t.state;
102
- if (!a)
105
+ const { store: r, viewport: s } = t.state;
106
+ if (!s)
103
107
  return;
104
108
  let o;
105
- const u = a.subscribe((s) => {
106
- o && c.unobserve(o);
107
- const m = s.map((p) => c.getAnnotation(p));
108
- n(m), o = (p) => {
109
- const { updated: r } = p.changes;
110
- n((A) => A.map((l) => {
111
- const g = r.find((w) => w.oldValue.id === l.id);
112
- return g ? g.newValue : l;
109
+ const u = s.subscribe((c) => {
110
+ o && r.unobserve(o);
111
+ const V = c.map((p) => r.getAnnotation(p));
112
+ e(V), o = (p) => {
113
+ const { updated: i } = p.changes;
114
+ e((A) => A.map((l) => {
115
+ const m = i.find((S) => S.oldValue.id === l.id);
116
+ return m ? m.newValue : l;
113
117
  }));
114
- }, c.observe(o, { annotations: s });
118
+ }, r.observe(o, { annotations: c });
115
119
  });
116
120
  return () => {
117
121
  u();
118
122
  };
119
123
  }
120
- }, [t]), e;
121
- }, z = (t) => {
122
- const e = _();
123
- return O(e, t);
124
- }, X = (t) => t ? z(t) : _();
124
+ }, [t]), n;
125
+ }, J = (t) => {
126
+ const n = D();
127
+ return _(n, t);
128
+ }, $ = (t) => t ? J(t) : D();
125
129
  export {
126
- K as Annotorious,
130
+ Q as Annotorious,
127
131
  f as AnnotoriousContext,
128
- q as useAnnotation,
129
- M as useAnnotationSelectAction,
130
- E as useAnnotationStore,
131
- L as useAnnotations,
132
+ G as useAnnotation,
133
+ W as useAnnotationSelectAction,
134
+ z as useAnnotationStore,
135
+ T as useAnnotations,
132
136
  b as useAnnotator,
133
- W as useAnnotatorUser,
134
- T as useHover,
135
- Q as useSelection,
136
- X as useViewportState
137
+ Z as useAnnotatorUser,
138
+ Y as useHover,
139
+ X as useSelection,
140
+ $ as useViewportState
137
141
  };
138
142
  //# sourceMappingURL=annotorious-react.es2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es2.js","sources":["../src/Annotorious.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { \n createContext, \n forwardRef,\n useContext, \n useEffect, \n useImperativeHandle, \n useRef,\n useState \n} from 'react';\nimport type { StoreObserveOptions } from '@annotorious/core';\nimport type {\n Annotation,\n Annotator,\n ImageAnnotation,\n Selection as CoreSelection,\n Store,\n StoreChangeEvent,\n User\n} from '@annotorious/annotorious';\nimport { useDebounce } from './useDebounce';\n\ninterface Selection<T extends Annotation = Annotation> extends Omit<CoreSelection, 'selected'> {\n\n selected: { annotation: T, editable?: boolean }[];\n\n previous: { annotation: T, editable?: boolean }[];\n\n}\n\nexport const AnnotoriousContext = createContext({\n\n anno: undefined,\n\n setAnno: undefined,\n\n annotations: [],\n\n selection: { selected: [] }\n\n});\n\nexport const Annotorious = forwardRef<Annotator, { children: ReactNode }>((props: { children: ReactNode }, ref) => {\n\n const [anno, setAnno] = useState<Annotator>(null);\n\n const [annotations, setAnnotations] = useState<Annotation[]>([]);\n\n const [selection, setSelection] = useState<Selection>({ selected: [], previous: [] });\n\n const previousSelectionRef = useRef<{ annotation: Annotation, editable?: boolean }[]>([]);\n\n useImperativeHandle(ref, () => anno);\n\n useEffect(() => {\n if (anno) {\n const { selection, store } = anno.state;\n\n // Components below <Annotorious /> may have\n // loaded annotations into the store already! \n if (store.all().length > 0)\n setAnnotations(store.all());\n\n // Keeps annotations in sync with a React state,\n // so clients can render components the usual React way.\n const onStoreChange = () => setAnnotations(() => store.all());\n\n store.observe(onStoreChange);\n\n // Keep selection in sync with a react state, and resolve them\n // from IDs to annotations automatically, for convenience\n let selectionStoreObserver: (event: StoreChangeEvent<Annotation>) => void;\n\n const unsubscribeSelection = selection.subscribe(({ selected, ...rest }) => {\n if (selectionStoreObserver)\n store.unobserve(selectionStoreObserver);\n\n const resolved = (selected || [])\n .map(({ id, editable }) => ({ annotation: store.getAnnotation(id), editable }));\n\n setSelection(currentSelection => {\n const next = {\n selected: resolved,\n previous: currentSelection.selected,\n ...rest\n } as Selection;\n\n if (JSON.stringify(currentSelection) === JSON.stringify(next)) \n return currentSelection;\n \n previousSelectionRef.current = currentSelection.selected;\n \n return next;\n });\n\n selectionStoreObserver = event => {\n const { updated } = event.changes;\n\n setSelection((selection) => ({\n ...selection,\n selected: selection.selected.map(({ annotation, editable }) => {\n const next = updated.find(u => u.oldValue.id === annotation.id);\n return next ? { annotation: next.newValue, editable } : { annotation, editable };\n })\n }));\n }\n\n store.observe(selectionStoreObserver, { annotations: selected.map(({ id }) => id) });\n });\n\n return () => {\n store.unobserve(onStoreChange);\n unsubscribeSelection();\n }\n }\n }, [anno]);\n\n return (\n <AnnotoriousContext.Provider value={{\n anno,\n setAnno,\n annotations,\n selection\n }}>\n {props.children}\n </AnnotoriousContext.Provider>\n )\n\n});\n\nexport const useAnnotator = <T extends unknown = Annotator<any, unknown>>() => {\n const { anno } = useContext(AnnotoriousContext);\n return anno as T;\n}\n\nexport const useAnnotationStore = <T extends unknown = Store<Annotation>>() => {\n const anno = useAnnotator();\n return anno?.state.store as T | undefined;\n}\n\nconst _useAnnotations = <T extends Annotation>() => {\n const { annotations } = useContext(AnnotoriousContext);\n return annotations as T[];\n}\n\nconst _useAnnotationsDebounced = <T extends Annotation>(debounce: number) => {\n const { annotations } = useContext(AnnotoriousContext);\n return useDebounce(annotations, debounce) as T[];\n}\n\nexport const useAnnotations = <T extends Annotation = ImageAnnotation>(debounce?: number) =>\n debounce ? _useAnnotationsDebounced<T>(debounce) : _useAnnotations<T>();\n\nexport const useAnnotation = <T extends Annotation = ImageAnnotation>(\n id: string,\n options?: Omit<StoreObserveOptions, 'annotations'>\n) => {\n const store = useAnnotationStore<Store<T>>();\n\n const [annotation, setAnnotation] = useState<T | undefined>(\n store?.getAnnotation(id)\n );\n\n useEffect(() => {\n if (!store) return;\n\n const handleChange = (event: StoreChangeEvent<T>) => {\n const updated = event.changes.updated[0];\n if (updated) {\n setAnnotation(updated.newValue);\n }\n };\n\n store.observe(handleChange, { ...options, annotations: id });\n return () => store.unobserve(handleChange);\n }, []);\n\n return annotation;\n}\n\nexport const useAnnotationSelectAction = <I extends Annotation = ImageAnnotation>(\n id: string\n) => {\n const anno = useAnnotator();\n const annotation = useAnnotation<I>(id);\n return anno && annotation ? anno.state.selection.evalSelectAction(annotation) : undefined;\n}\n\nexport const useSelection = <T extends Annotation = ImageAnnotation>() => {\n const { selection } = useContext(AnnotoriousContext);\n return selection as Selection<T>;\n}\n\nexport const useHover = <T extends Annotation = ImageAnnotation>() => {\n const anno = useAnnotator();\n\n const [hover, setHover] = useState<T | undefined>();\n\n useEffect(() => {\n if (!anno) return;\n\n const { hover, store } = (anno as Annotator<T, unknown>).state;\n\n const unsubscribeHover = hover.subscribe(id => {\n if (id) {\n const annotation = store.getAnnotation(id);\n setHover(annotation);\n } else {\n setHover(undefined);\n }\n });\n\n return () => {\n unsubscribeHover();\n };\n }, [anno]);\n\n return hover;\n}\n\nexport const useAnnotatorUser = (): User => {\n const anno = useAnnotator();\n return anno?.getUser();\n}\n\nconst _useViewportState = <T extends Annotation>() => {\n const anno = useAnnotator();\n\n const [inViewport, setInViewport] = useState<T[]>([]);\n\n useEffect(() => {\n if (anno) {\n const { store, viewport } = anno.state;\n\n if (!viewport)\n return;\n\n // Keep viewport annotations in sync with a react state, and resolve them\n // from IDs to annotations automatically, for convenience\n let viewportStoreObserver: (event: StoreChangeEvent<T>) => void;\n\n const unsubscribeViewport = viewport.subscribe(ids => {\n if (viewportStoreObserver)\n store.unobserve(viewportStoreObserver);\n\n const resolved = ids.map(id => store.getAnnotation(id)) as T[];\n setInViewport(resolved);\n\n viewportStoreObserver = event => {\n const { updated } = event.changes;\n\n setInViewport(annotations => annotations.map(annotation => {\n const next = updated.find(u => u.oldValue.id === annotation.id);\n return next ? next.newValue : annotation;\n }));\n };\n\n store.observe(viewportStoreObserver, { annotations: ids });\n });\n\n return () => {\n unsubscribeViewport();\n };\n }\n }, [anno]);\n\n return inViewport;\n}\n\nconst _useViewportStateDebounced = <T extends Annotation>(debounce: number) => {\n const inViewport = _useViewportState();\n return useDebounce(inViewport, debounce) as T[];\n}\n\nexport const useViewportState = <T extends Annotation = ImageAnnotation>(debounce?: number) =>\n debounce ? _useViewportStateDebounced<T>(debounce) : _useViewportState<T>();\n"],"names":["AnnotoriousContext","createContext","Annotorious","forwardRef","props","ref","anno","setAnno","useState","annotations","setAnnotations","selection","setSelection","previousSelectionRef","useRef","useImperativeHandle","useEffect","store","onStoreChange","selectionStoreObserver","unsubscribeSelection","selected","rest","resolved","id","editable","currentSelection","next","event","updated","annotation","u","jsx","useAnnotator","useContext","useAnnotationStore","_useAnnotations","_useAnnotationsDebounced","debounce","useDebounce","useAnnotations","useAnnotation","options","setAnnotation","handleChange","useAnnotationSelectAction","useSelection","useHover","hover","setHover","unsubscribeHover","useAnnotatorUser","_useViewportState","inViewport","setInViewport","viewport","viewportStoreObserver","unsubscribeViewport","ids","_useViewportStateDebounced","useViewportState"],"mappings":";;;AA8BO,MAAMA,IAAqBC,EAAc;AAAA,EAE9C,MAAM;AAAA,EAEN,SAAS;AAAA,EAET,aAAa,CAAA;AAAA,EAEb,WAAW,EAAE,UAAU,CAAA,EAAC;AAE1B,CAAC,GAEYC,IAAcC,EAA+C,CAACC,GAAgCC,MAAQ;AAEjH,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAoB,IAAI,GAE1C,CAACC,GAAaC,CAAc,IAAIF,EAAuB,CAAA,CAAE,GAEzD,CAACG,GAAWC,CAAY,IAAIJ,EAAoB,EAAE,UAAU,CAAA,GAAI,UAAU,CAAA,GAAI,GAE9EK,IAAuBC,EAAyD,EAAE;AAExF,SAAAC,EAAoBV,GAAK,MAAMC,CAAI,GAEnCU,EAAU,MAAM;AACd,QAAIV,GAAM;AACR,YAAM,EAAE,WAAAK,GAAW,OAAAM,EAA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zC,EAAM,cAAcO,CAAE,CAAC;AACtD,QAAA8B,EAAc/B,CAAQ,GAEtBiC,IAAwB,CAAA5B,MAAS;AAC/B,gBAAM,EAAE,SAAAC,MAAYD,EAAM;AAE1B,UAAA0B,EAAc,CAAA7C,MAAeA,EAAY,IAAI,CAAAqB,MAAc;AACzD,kBAAMH,IAAOE,EAAQ,KAAK,CAAAE,MAAKA,EAAE,SAAS,OAAOD,EAAW,EAAE;AAC9D,mBAAOH,IAAOA,EAAK,WAAWG;AAAA,UAChC,CAAC,CAAC;AAAA,QACJ,GAEAb,EAAM,QAAQuC,GAAuB,EAAE,aAAaE,GAAK;AAAA,MAC3D,CAAC;AAED,aAAO,MAAM;AACX,QAAAD,EAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAACnD,CAAI,CAAC,GAEF+C;AACT,GAEMM,IAA6B,CAAuBrB,MAAqB;AAC7E,QAAMe,IAAaD,EAAA;AACnB,SAAOb,EAAYc,GAAYf,CAAQ;AACzC,GAEasB,IAAmB,CAAyCtB,MACvEA,IAAWqB,EAA8BrB,CAAQ,IAAIc,EAAA;"}
1
+ {"version":3,"file":"annotorious-react.es2.js","sources":["../src/Annotorious.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { dequal } from 'dequal/lite';\nimport { \n createContext, \n forwardRef,\n useContext, \n useEffect, \n useImperativeHandle, \n useRef,\n useState \n} from 'react';\nimport type { StoreObserveOptions } from '@annotorious/core';\nimport type {\n Annotation,\n Annotator,\n ImageAnnotation,\n Selection as CoreSelection,\n Store,\n StoreChangeEvent,\n User\n} from '@annotorious/annotorious';\nimport { useDebounce } from './useDebounce';\n\ninterface Selection<T extends Annotation = Annotation> extends Omit<CoreSelection, 'selected'> {\n\n selected: { annotation: T, editable?: boolean }[];\n\n previous: { annotation: T, editable?: boolean }[];\n\n}\n\nexport const AnnotoriousContext = createContext({\n\n anno: undefined,\n\n setAnno: undefined,\n\n annotations: [],\n\n selection: { selected: [] }\n\n});\n\nconst isSelectionEqual = (a: Selection, b: Selection) => {\n const { event: eventA, ...restA } = a; \n const { event: eventB, ...restB } = b; \n\n if (!dequal(restA, restB)) return false;\n\n return eventA?.timeStamp === eventB?.timeStamp;\n}\n\nexport const Annotorious = forwardRef<Annotator, { children: ReactNode }>((props: { children: ReactNode }, ref) => {\n\n const [anno, setAnno] = useState<Annotator>(null);\n\n const [annotations, setAnnotations] = useState<Annotation[]>([]);\n\n const [selection, setSelection] = useState<Selection>({ selected: [], previous: [] });\n\n const previousSelectionRef = useRef<{ annotation: Annotation, editable?: boolean }[]>([]);\n\n useImperativeHandle(ref, () => anno);\n\n useEffect(() => {\n if (anno) {\n const { selection, store } = anno.state;\n\n // Components below <Annotorious /> may have\n // loaded annotations into the store already! \n if (store.all().length > 0)\n setAnnotations(store.all());\n\n // Keeps annotations in sync with a React state,\n // so clients can render components the usual React way.\n const onStoreChange = () => setAnnotations(() => store.all());\n\n store.observe(onStoreChange);\n\n // Keep selection in sync with a react state, and resolve them\n // from IDs to annotations automatically, for convenience\n let selectionStoreObserver: (event: StoreChangeEvent<Annotation>) => void;\n\n const unsubscribeSelection = selection.subscribe(({ selected, ...rest }) => {\n if (selectionStoreObserver)\n store.unobserve(selectionStoreObserver);\n\n const resolved = (selected || [])\n .map(({ id, editable }) => ({ annotation: store.getAnnotation(id), editable }));\n\n setSelection(currentSelection => {\n const next = {\n selected: resolved,\n previous: currentSelection.selected,\n ...rest\n } as Selection;\n\n // Prevent unnecessary re-renders\n if (isSelectionEqual(currentSelection, next))\n return currentSelection;\n \n previousSelectionRef.current = currentSelection.selected;\n \n return next;\n });\n\n selectionStoreObserver = event => {\n const { updated } = event.changes;\n\n setSelection((selection) => ({\n ...selection,\n selected: selection.selected.map(({ annotation, editable }) => {\n const next = updated.find(u => u.oldValue.id === annotation.id);\n return next ? { annotation: next.newValue, editable } : { annotation, editable };\n })\n }));\n }\n\n store.observe(selectionStoreObserver, { annotations: selected.map(({ id }) => id) });\n });\n\n return () => {\n store.unobserve(onStoreChange);\n unsubscribeSelection();\n }\n }\n }, [anno]);\n\n return (\n <AnnotoriousContext.Provider value={{\n anno,\n setAnno,\n annotations,\n selection\n }}>\n {props.children}\n </AnnotoriousContext.Provider>\n )\n\n});\n\nexport const useAnnotator = <T extends unknown = Annotator<any, unknown>>() => {\n const { anno } = useContext(AnnotoriousContext);\n return anno as T;\n}\n\nexport const useAnnotationStore = <T extends unknown = Store<Annotation>>() => {\n const anno = useAnnotator();\n return anno?.state.store as T | undefined;\n}\n\nconst _useAnnotations = <T extends Annotation>() => {\n const { annotations } = useContext(AnnotoriousContext);\n return annotations as T[];\n}\n\nconst _useAnnotationsDebounced = <T extends Annotation>(debounce: number) => {\n const { annotations } = useContext(AnnotoriousContext);\n return useDebounce(annotations, debounce) as T[];\n}\n\nexport const useAnnotations = <T extends Annotation = ImageAnnotation>(debounce?: number) =>\n debounce ? _useAnnotationsDebounced<T>(debounce) : _useAnnotations<T>();\n\nexport const useAnnotation = <T extends Annotation = ImageAnnotation>(\n id: string,\n options?: Omit<StoreObserveOptions, 'annotations'>\n) => {\n const store = useAnnotationStore<Store<T>>();\n\n const [annotation, setAnnotation] = useState<T | undefined>(\n store?.getAnnotation(id)\n );\n\n useEffect(() => {\n if (!store) return;\n\n const handleChange = (event: StoreChangeEvent<T>) => {\n const updated = event.changes.updated[0];\n if (updated) {\n setAnnotation(updated.newValue);\n }\n };\n\n store.observe(handleChange, { ...options, annotations: id });\n return () => store.unobserve(handleChange);\n }, []);\n\n return annotation;\n}\n\nexport const useAnnotationSelectAction = <I extends Annotation = ImageAnnotation>(\n id: string\n) => {\n const anno = useAnnotator();\n const annotation = useAnnotation<I>(id);\n return anno && annotation ? anno.state.selection.evalSelectAction(annotation) : undefined;\n}\n\nexport const useSelection = <T extends Annotation = ImageAnnotation>() => {\n const { selection } = useContext(AnnotoriousContext);\n return selection as Selection<T>;\n}\n\nexport const useHover = <T extends Annotation = ImageAnnotation>() => {\n const anno = useAnnotator();\n\n const [hover, setHover] = useState<T | undefined>();\n\n useEffect(() => {\n if (!anno) return;\n\n const { hover, store } = (anno as Annotator<T, unknown>).state;\n\n const unsubscribeHover = hover.subscribe(id => {\n if (id) {\n const annotation = store.getAnnotation(id);\n setHover(annotation);\n } else {\n setHover(undefined);\n }\n });\n\n return () => {\n unsubscribeHover();\n };\n }, [anno]);\n\n return hover;\n}\n\nexport const useAnnotatorUser = (): User => {\n const anno = useAnnotator();\n return anno?.getUser();\n}\n\nconst _useViewportState = <T extends Annotation>() => {\n const anno = useAnnotator();\n\n const [inViewport, setInViewport] = useState<T[]>([]);\n\n useEffect(() => {\n if (anno) {\n const { store, viewport } = anno.state;\n\n if (!viewport)\n return;\n\n // Keep viewport annotations in sync with a react state, and resolve them\n // from IDs to annotations automatically, for convenience\n let viewportStoreObserver: (event: StoreChangeEvent<T>) => void;\n\n const unsubscribeViewport = viewport.subscribe(ids => {\n if (viewportStoreObserver)\n store.unobserve(viewportStoreObserver);\n\n const resolved = ids.map(id => store.getAnnotation(id)) as T[];\n setInViewport(resolved);\n\n viewportStoreObserver = event => {\n const { updated } = event.changes;\n\n setInViewport(annotations => annotations.map(annotation => {\n const next = updated.find(u => u.oldValue.id === annotation.id);\n return next ? next.newValue : annotation;\n }));\n };\n\n store.observe(viewportStoreObserver, { annotations: ids });\n });\n\n return () => {\n unsubscribeViewport();\n };\n }\n }, [anno]);\n\n return inViewport;\n}\n\nconst _useViewportStateDebounced = <T extends Annotation>(debounce: number) => {\n const inViewport = _useViewportState();\n return useDebounce(inViewport, debounce) as T[];\n}\n\nexport const useViewportState = <T extends Annotation = ImageAnnotation>(debounce?: number) =>\n debounce ? _useViewportStateDebounced<T>(debounce) : _useViewportState<T>();\n"],"names":["AnnotoriousContext","createContext","isSelectionEqual","a","b","eventA","restA","eventB","restB","dequal","Annotorious","forwardRef","props","ref","anno","setAnno","useState","annotations","setAnnotations","selection","setSelection","previousSelectionRef","useRef","useImperativeHandle","useEffect","store","onStoreChange","selectionStoreObserver","unsubscribeSelection","selected","rest","resolved","id","editable","currentSelection","next","event","updated","annotation","u","jsx","useAnnotator","useContext","useAnnotationStore","_useAnnotations","_useAnnotationsDebounced","debounce","useDebounce","useAnnotations","useAnnotation","options","setAnnotation","handleChange","useAnnotationSelectAction","useSelection","useHover","hover","setHover","unsubscribeHover","useAnnotatorUser","_useViewportState","inViewport","setInViewport","viewport","viewportStoreObserver","unsubscribeViewport","ids","_useViewportStateDebounced","useViewportState"],"mappings":";;;;AA+BO,MAAMA,IAAqBC,EAAc;AAAA,EAE9C,MAAM;AAAA,EAEN,SAAS;AAAA,EAET,aAAa,CAAA;AAAA,EAEb,WAAW,EAAE,UAAU,CAAA,EAAC;AAE1B,CAAC,GAEKC,IAAmB,CAACC,GAAcC,MAAiB;AACvD,QAAM,EAAE,OAAOC,GAAQ,GAAGC,MAAUH,GAC9B,EAAE,OAAOI,GAAQ,GAAGC,MAAUJ;AAEpC,SAAKK,EAAOH,GAAOE,CAAK,KAEjBH,KAAA,gBAAAA,EAAQ,gBAAcE,KAAA,gBAAAA,EAAQ,aAFH;AAGpC,GAEaG,IAAcC,EAA+C,CAACC,GAAgCC,MAAQ;AAEjH,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAoB,IAAI,GAE1C,CAACC,GAAaC,CAAc,IAAIF,EAAuB,CAAA,CAAE,GAEzD,CAACG,GAAWC,CAAY,IAAIJ,EAAoB,EAAE,UAAU,CAAA,GAAI,UAAU,CAAA,GAAI,GAE9EK,IAAuBC,EAAyD,EAAE;AAExF,SAAAC,EAAoBV,GAAK,MAAMC,CAAI,GAEnCU,EAAU,MAAM;AACd,QAAIV,GAAM;AACR,YAAM,EAAE,WAAAK,GAAW,OAAAM,EAAA,IAAUX,EAAK;AAIlC,MAAIW,EAAM,MAAM,SAAS,KACvBP,EAAeO,EAAM,KAAK;AAI5B,YAAMC,IAAgB,MAAMR,EAAe,MAAMO,EAAM,KAAK;AAE5D,MAAAA,EAAM,QAAQC,CAAa;AAI3B,UAAIC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