@soomo/react-text-annotator 3.0.0-staging.16 → 3.0.0-staging.17

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 (48) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/react-text-annotator.es.js +2 -0
  4. package/dist/react-text-annotator.es.js.map +1 -1
  5. package/dist/react-text-annotator.es10.js +210 -562
  6. package/dist/react-text-annotator.es10.js.map +1 -1
  7. package/dist/react-text-annotator.es11.js +535 -444
  8. package/dist/react-text-annotator.es11.js.map +1 -1
  9. package/dist/react-text-annotator.es12.js +488 -2
  10. package/dist/react-text-annotator.es12.js.map +1 -1
  11. package/dist/react-text-annotator.es13.js +2 -35
  12. package/dist/react-text-annotator.es13.js.map +1 -1
  13. package/dist/react-text-annotator.es14.js +24 -888
  14. package/dist/react-text-annotator.es14.js.map +1 -1
  15. package/dist/react-text-annotator.es15.js +891 -220
  16. package/dist/react-text-annotator.es15.js.map +1 -1
  17. package/dist/react-text-annotator.es16.js +218 -126
  18. package/dist/react-text-annotator.es16.js.map +1 -1
  19. package/dist/react-text-annotator.es17.js +136 -2
  20. package/dist/react-text-annotator.es17.js.map +1 -1
  21. package/dist/react-text-annotator.es18.js +2 -2
  22. package/dist/react-text-annotator.es19.js +2 -114
  23. package/dist/react-text-annotator.es19.js.map +1 -1
  24. package/dist/react-text-annotator.es2.js +2 -2
  25. package/dist/react-text-annotator.es20.js +107 -302
  26. package/dist/react-text-annotator.es20.js.map +1 -1
  27. package/dist/react-text-annotator.es21.js +290 -39
  28. package/dist/react-text-annotator.es21.js.map +1 -1
  29. package/dist/react-text-annotator.es22.js +55 -17
  30. package/dist/react-text-annotator.es22.js.map +1 -1
  31. package/dist/react-text-annotator.es23.js +17 -118
  32. package/dist/react-text-annotator.es23.js.map +1 -1
  33. package/dist/react-text-annotator.es24.js +107 -538
  34. package/dist/react-text-annotator.es24.js.map +1 -1
  35. package/dist/react-text-annotator.es25.js +555 -0
  36. package/dist/react-text-annotator.es25.js.map +1 -0
  37. package/dist/react-text-annotator.es3.js +2 -2
  38. package/dist/react-text-annotator.es4.js +2 -2
  39. package/dist/react-text-annotator.es5.js +4 -4
  40. package/dist/react-text-annotator.es6.js +178 -9
  41. package/dist/react-text-annotator.es6.js.map +1 -1
  42. package/dist/react-text-annotator.es7.js +12 -1
  43. package/dist/react-text-annotator.es7.js.map +1 -1
  44. package/dist/react-text-annotator.es9.js +20 -223
  45. package/dist/react-text-annotator.es9.js.map +1 -1
  46. package/package.json +13 -7
  47. package/dist/react-text-annotator.es8.js +0 -27
  48. package/dist/react-text-annotator.es8.js.map +0 -1
@@ -1,491 +1,582 @@
1
- import defaultBehaviors from "./react-text-annotator.es19.js";
2
- import * as utilities from "./react-text-annotator.es20.js";
3
- import { hideContent, defineCustomElement, tagName } from "./react-text-annotator.es20.js";
4
- import { addBehaviors, addBehavior, removeBehavior } from "./react-text-annotator.es21.js";
5
- import { learnElementNames, learnCustomElementNames } from "./react-text-annotator.es22.js";
6
- class CETEI {
7
- constructor(options) {
8
- this.options = options ? options : {};
9
- this.document = this.options.documentObject ? this.options.documentObject : void 0;
10
- if (this.document === void 0) {
11
- if (typeof window !== "undefined" && window.document) {
12
- this.document = window.document;
13
- } else if (typeof global !== "undefined" && global.document) {
14
- this.document = global.document;
15
- }
16
- }
17
- this.addBehaviors = addBehaviors.bind(this);
18
- this.addBehavior = addBehavior.bind(this);
19
- this.removeBehavior = removeBehavior.bind(this);
20
- this.utilities = {};
21
- for (const u of Object.keys(utilities)) {
22
- if (["getPrefixDef", "rw", "resolveURI"].includes(u)) {
23
- this.utilities[u] = utilities[u].bind(this);
24
- } else {
25
- this.utilities[u] = utilities[u];
1
+ import { offset as offset$1, autoPlacement as autoPlacement$1, shift as shift$1, inline as inline$1, computePosition as computePosition$1 } from "./react-text-annotator.es25.js";
2
+ import { createCoords, rectToClientRect, round, floor, max, min } from "./react-text-annotator.es24.js";
3
+ import { getOverflowAncestors, isElement, getWindow, getComputedStyle, getDocumentElement, isHTMLElement, isWebKit, getNodeName, isOverflowElement, getNodeScroll, getParentNode, isLastTraversableNode, isTableElement, isContainingBlock, getContainingBlock } from "./react-text-annotator.es17.js";
4
+ function getCssDimensions(element) {
5
+ const css = getComputedStyle(element);
6
+ let width = parseFloat(css.width) || 0;
7
+ let height = parseFloat(css.height) || 0;
8
+ const hasOffset = isHTMLElement(element);
9
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
10
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
11
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
12
+ if (shouldFallback) {
13
+ width = offsetWidth;
14
+ height = offsetHeight;
15
+ }
16
+ return {
17
+ width,
18
+ height,
19
+ $: shouldFallback
20
+ };
21
+ }
22
+ function unwrapElement(element) {
23
+ return !isElement(element) ? element.contextElement : element;
24
+ }
25
+ function getScale(element) {
26
+ const domElement = unwrapElement(element);
27
+ if (!isHTMLElement(domElement)) {
28
+ return createCoords(1);
29
+ }
30
+ const rect = domElement.getBoundingClientRect();
31
+ const {
32
+ width,
33
+ height,
34
+ $
35
+ } = getCssDimensions(domElement);
36
+ let x = ($ ? round(rect.width) : rect.width) / width;
37
+ let y = ($ ? round(rect.height) : rect.height) / height;
38
+ if (!x || !Number.isFinite(x)) {
39
+ x = 1;
40
+ }
41
+ if (!y || !Number.isFinite(y)) {
42
+ y = 1;
43
+ }
44
+ return {
45
+ x,
46
+ y
47
+ };
48
+ }
49
+ const noOffsets = /* @__PURE__ */ createCoords(0);
50
+ function getVisualOffsets(element) {
51
+ const win = getWindow(element);
52
+ if (!isWebKit() || !win.visualViewport) {
53
+ return noOffsets;
54
+ }
55
+ return {
56
+ x: win.visualViewport.offsetLeft,
57
+ y: win.visualViewport.offsetTop
58
+ };
59
+ }
60
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
61
+ if (isFixed === void 0) {
62
+ isFixed = false;
63
+ }
64
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
65
+ return false;
66
+ }
67
+ return isFixed;
68
+ }
69
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
70
+ if (includeScale === void 0) {
71
+ includeScale = false;
72
+ }
73
+ if (isFixedStrategy === void 0) {
74
+ isFixedStrategy = false;
75
+ }
76
+ const clientRect = element.getBoundingClientRect();
77
+ const domElement = unwrapElement(element);
78
+ let scale = createCoords(1);
79
+ if (includeScale) {
80
+ if (offsetParent) {
81
+ if (isElement(offsetParent)) {
82
+ scale = getScale(offsetParent);
26
83
  }
27
- }
28
- this.els = [];
29
- this.namespaces = /* @__PURE__ */ new Map();
30
- this.behaviors = {};
31
- this.hasStyle = false;
32
- this.prefixDefs = [];
33
- this.debug = this.options.debug === true ? true : false;
34
- this.discardContent = this.options.discardContent === true ? true : false;
35
- if (this.options.base) {
36
- this.base = this.options.base;
37
84
  } else {
38
- try {
39
- if (window) {
40
- this.base = window.location.href.replace(/\/[^\/]*$/, "/");
41
- }
42
- } catch (e) {
43
- this.base = "";
44
- }
45
- }
46
- if (!this.options.omitDefaultBehaviors) {
47
- this.addBehaviors(defaultBehaviors);
48
- }
49
- if (this.options.ignoreFragmentId) {
50
- if (window) {
51
- window.removeEventListener("ceteiceanload", CETEI.restorePosition);
52
- }
85
+ scale = getScale(element);
53
86
  }
54
87
  }
55
- /*
56
- Returns a Promise that fetches an XML source document from the URL
57
- provided in the first parameter and then calls the makeHTML5 method
58
- on the returned document.
59
- */
60
- async getHTML5(XML_url, callback, perElementFn) {
61
- if (window && window.location.href.startsWith(this.base) && XML_url.indexOf("/") >= 0) {
62
- this.base = XML_url.replace(/\/[^\/]*$/, "/");
88
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
89
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
90
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
91
+ let width = clientRect.width / scale.x;
92
+ let height = clientRect.height / scale.y;
93
+ if (domElement) {
94
+ const win = getWindow(domElement);
95
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
96
+ let currentWin = win;
97
+ let currentIFrame = currentWin.frameElement;
98
+ while (currentIFrame && offsetParent && offsetWin !== currentWin) {
99
+ const iframeScale = getScale(currentIFrame);
100
+ const iframeRect = currentIFrame.getBoundingClientRect();
101
+ const css = getComputedStyle(currentIFrame);
102
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
103
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
104
+ x *= iframeScale.x;
105
+ y *= iframeScale.y;
106
+ width *= iframeScale.x;
107
+ height *= iframeScale.y;
108
+ x += left;
109
+ y += top;
110
+ currentWin = getWindow(currentIFrame);
111
+ currentIFrame = currentWin.frameElement;
63
112
  }
113
+ }
114
+ return rectToClientRect({
115
+ width,
116
+ height,
117
+ x,
118
+ y
119
+ });
120
+ }
121
+ const topLayerSelectors = [":popover-open", ":modal"];
122
+ function isTopLayer(element) {
123
+ return topLayerSelectors.some((selector) => {
64
124
  try {
65
- const response = await fetch(XML_url);
66
- if (response.ok) {
67
- const XML = await response.text();
68
- return this.makeHTML5(XML, callback, perElementFn);
69
- } else {
70
- console.log(`Could not get XML file ${XML_url}.
71
- Server returned ${response.status}: ${response.statusText}`);
72
- }
73
- } catch (error) {
74
- console.log(error);
125
+ return element.matches(selector);
126
+ } catch (e) {
127
+ return false;
75
128
  }
129
+ });
130
+ }
131
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
132
+ let {
133
+ elements,
134
+ rect,
135
+ offsetParent,
136
+ strategy
137
+ } = _ref;
138
+ const isFixed = strategy === "fixed";
139
+ const documentElement = getDocumentElement(offsetParent);
140
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
141
+ if (offsetParent === documentElement || topLayer && isFixed) {
142
+ return rect;
76
143
  }
77
- /*
78
- Converts the supplied XML string into HTML5 Custom Elements. If a callback
79
- function is supplied, calls it on the result.
80
- */
81
- makeHTML5(XML, callback, perElementFn) {
82
- this.XML_dom = new DOMParser().parseFromString(XML, "text/xml");
83
- return this.domToHTML5(this.XML_dom, callback, perElementFn);
84
- }
85
- preprocess(XML_dom, callback, perElementFn) {
86
- this.els = learnElementNames(XML_dom, this.namespaces);
87
- let convertEl = (el) => {
88
- let newElement;
89
- if (this.namespaces.has(el.namespaceURI ? el.namespaceURI : "")) {
90
- let prefix = this.namespaces.get(el.namespaceURI ? el.namespaceURI : "");
91
- newElement = this.document.createElement(`${prefix}-${el.localName.toLowerCase()}`);
92
- } else {
93
- newElement = this.document.importNode(el, false);
94
- }
95
- for (let att of Array.from(el.attributes)) {
96
- if (att.name == "xmlns") {
97
- newElement.setAttribute("data-xmlns", att.value);
98
- } else {
99
- newElement.setAttribute(att.name, att.value);
100
- }
101
- if (att.name == "xml:id") {
102
- newElement.setAttribute("id", att.value);
103
- }
104
- if (att.name == "xml:lang") {
105
- newElement.setAttribute("lang", att.value);
106
- }
107
- if (att.name == "rendition") {
108
- newElement.setAttribute("class", att.value.replace(/#/g, ""));
109
- }
110
- }
111
- newElement.setAttribute("data-origname", el.localName);
112
- if (el.hasAttributes()) {
113
- newElement.setAttribute("data-origatts", el.getAttributeNames().join(" "));
114
- }
115
- if (el.childNodes.length == 0) {
116
- newElement.setAttribute("data-empty", "");
117
- }
118
- if (el.localName == "head") {
119
- let level = XML_dom.evaluate("count(ancestor::*[tei:head])", el, function(ns) {
120
- if (ns == "tei")
121
- return "http://www.tei-c.org/ns/1.0";
122
- }, 1, null);
123
- newElement.setAttribute("data-level", level.numberValue);
124
- }
125
- if (el.localName == "tagsDecl") {
126
- let style = this.document.createElement("style");
127
- for (let node of Array.from(el.childNodes)) {
128
- if (node.nodeType == 1 && node.localName == "rendition" && node.getAttribute("scheme") == "css") {
129
- let rule = "";
130
- if (node.hasAttribute("selector")) {
131
- rule += node.getAttribute("selector").replace(/([^#, >]+\w*)/g, "tei-$1").replace(/#tei-/g, "#") + "{\n";
132
- rule += node.textContent;
133
- } else {
134
- rule += "." + node.getAttribute("xml:id") + "{\n";
135
- rule += node.textContent;
136
- }
137
- rule += "\n}\n";
138
- style.appendChild(this.document.createTextNode(rule));
139
- }
140
- }
141
- if (style.childNodes.length > 0) {
142
- newElement.appendChild(style);
143
- this.hasStyle = true;
144
- }
145
- }
146
- if (el.localName == "prefixDef") {
147
- this.prefixDefs.push(el.getAttribute("ident"));
148
- this.prefixDefs[el.getAttribute("ident")] = {
149
- "matchPattern": el.getAttribute("matchPattern"),
150
- "replacementPattern": el.getAttribute("replacementPattern")
151
- };
152
- }
153
- for (let node of Array.from(el.childNodes)) {
154
- if (node.nodeType == 1) {
155
- newElement.appendChild(convertEl(node));
156
- } else {
157
- newElement.appendChild(node.cloneNode());
158
- }
159
- }
160
- if (perElementFn) {
161
- perElementFn(newElement, el);
162
- }
163
- return newElement;
164
- };
165
- this.dom = this.document.createDocumentFragment();
166
- for (let node of Array.from(XML_dom.childNodes)) {
167
- if (node.nodeType == 1) {
168
- this.dom.appendChild(convertEl(node));
169
- }
170
- if (node.nodeType == 7) {
171
- this.dom.appendChild(this.document.importNode(node, true));
172
- }
173
- if (node.nodeType == 8) {
174
- this.dom.appendChild(this.document.importNode(node, true));
175
- }
144
+ let scroll = {
145
+ scrollLeft: 0,
146
+ scrollTop: 0
147
+ };
148
+ let scale = createCoords(1);
149
+ const offsets = createCoords(0);
150
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
151
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
152
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
153
+ scroll = getNodeScroll(offsetParent);
176
154
  }
177
- this.utilities.dom = this.dom.firstElementChild;
178
- if (callback) {
179
- callback(this.dom, this);
180
- if (window) {
181
- window.dispatchEvent(ceteiceanLoad);
182
- }
183
- } else {
184
- if (typeof window !== "undefined") {
185
- window.dispatchEvent(ceteiceanLoad);
186
- }
187
- return this.dom;
155
+ if (isHTMLElement(offsetParent)) {
156
+ const offsetRect = getBoundingClientRect(offsetParent);
157
+ scale = getScale(offsetParent);
158
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
159
+ offsets.y = offsetRect.y + offsetParent.clientTop;
188
160
  }
189
161
  }
190
- /*
191
- Converts the supplied XML DOM into HTML5 Custom Elements. If a callback
192
- function is supplied, calls it on the result.
193
- */
194
- domToHTML5(XML_dom, callback, perElementFn) {
195
- this.preprocess(XML_dom, null, perElementFn);
196
- this.applyBehaviors();
197
- this.done = true;
198
- if (callback) {
199
- callback(this.dom, this);
200
- if (window) {
201
- window.dispatchEvent(ceteiceanLoad);
202
- }
203
- } else {
204
- if (typeof window !== "undefined") {
205
- window.dispatchEvent(ceteiceanLoad);
206
- }
207
- return this.dom;
208
- }
162
+ return {
163
+ width: rect.width * scale.x,
164
+ height: rect.height * scale.y,
165
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
166
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
167
+ };
168
+ }
169
+ function getClientRects(element) {
170
+ return Array.from(element.getClientRects());
171
+ }
172
+ function getWindowScrollBarX(element) {
173
+ return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
174
+ }
175
+ function getDocumentRect(element) {
176
+ const html = getDocumentElement(element);
177
+ const scroll = getNodeScroll(element);
178
+ const body = element.ownerDocument.body;
179
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
180
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
181
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
182
+ const y = -scroll.scrollTop;
183
+ if (getComputedStyle(body).direction === "rtl") {
184
+ x += max(html.clientWidth, body.clientWidth) - width;
209
185
  }
210
- /*
211
- Convenience method for HTML pages containing pre-processed CETEIcean Custom
212
- Elements. Usage:
213
- const c = new CETEI();
214
- c.processPage();
215
- */
216
- processPage() {
217
- this.els = learnCustomElementNames(this.document);
218
- this.applyBehaviors();
219
- if (window) {
220
- window.dispatchEvent(ceteiceanLoad);
186
+ return {
187
+ width,
188
+ height,
189
+ x,
190
+ y
191
+ };
192
+ }
193
+ function getViewportRect(element, strategy) {
194
+ const win = getWindow(element);
195
+ const html = getDocumentElement(element);
196
+ const visualViewport = win.visualViewport;
197
+ let width = html.clientWidth;
198
+ let height = html.clientHeight;
199
+ let x = 0;
200
+ let y = 0;
201
+ if (visualViewport) {
202
+ width = visualViewport.width;
203
+ height = visualViewport.height;
204
+ const visualViewportBased = isWebKit();
205
+ if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
206
+ x = visualViewport.offsetLeft;
207
+ y = visualViewport.offsetTop;
221
208
  }
222
209
  }
223
- /*
224
- To change a namespace -> prefix mapping, the namespace must first be
225
- unset. Takes a namespace URI. In order to process a TEI P4 document, e.g.,
226
- the TEI namespace must be unset before it can be set to the empty string.
227
- */
228
- unsetNamespace(ns) {
229
- this.namespaces.delete(ns);
230
- }
231
- /*
232
- Sets the base URL for the document. Used to rewrite relative links in the
233
- XML source (which may be in a completely different location from the HTML
234
- wrapper).
235
- */
236
- setBaseUrl(base) {
237
- this.base = base;
238
- }
239
- /*
240
- Appends any element returned by the function passed in the first
241
- parameter to the element in the second parameter. If the function
242
- returns nothing, this is a no-op aside from any side effects caused
243
- by the provided function.
244
-
245
- Called by getHandler() and fallback()
246
- */
247
- append(fn, elt) {
248
- let self = this;
249
- if (elt && !elt.hasAttribute("data-processed")) {
250
- let content = fn.call(self.utilities, elt);
251
- if (content) {
252
- self.appendBasic(elt, content);
253
- }
254
- } else {
255
- return function() {
256
- if (!this.hasAttribute("data-processed")) {
257
- let content = fn.call(self.utilities, this);
258
- if (content) {
259
- self.appendBasic(this, content);
260
- }
261
- }
262
- };
263
- }
210
+ return {
211
+ width,
212
+ height,
213
+ x,
214
+ y
215
+ };
216
+ }
217
+ function getInnerBoundingClientRect(element, strategy) {
218
+ const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
219
+ const top = clientRect.top + element.clientTop;
220
+ const left = clientRect.left + element.clientLeft;
221
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
222
+ const width = element.clientWidth * scale.x;
223
+ const height = element.clientHeight * scale.y;
224
+ const x = left * scale.x;
225
+ const y = top * scale.y;
226
+ return {
227
+ width,
228
+ height,
229
+ x,
230
+ y
231
+ };
232
+ }
233
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
234
+ let rect;
235
+ if (clippingAncestor === "viewport") {
236
+ rect = getViewportRect(element, strategy);
237
+ } else if (clippingAncestor === "document") {
238
+ rect = getDocumentRect(getDocumentElement(element));
239
+ } else if (isElement(clippingAncestor)) {
240
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
241
+ } else {
242
+ const visualOffsets = getVisualOffsets(element);
243
+ rect = {
244
+ ...clippingAncestor,
245
+ x: clippingAncestor.x - visualOffsets.x,
246
+ y: clippingAncestor.y - visualOffsets.y
247
+ };
264
248
  }
265
- appendBasic(elt, content) {
266
- if (this.discardContent) {
267
- elt.innerHTML = "";
268
- } else {
269
- hideContent(elt, true);
249
+ return rectToClientRect(rect);
250
+ }
251
+ function hasFixedPositionAncestor(element, stopNode) {
252
+ const parentNode = getParentNode(element);
253
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
254
+ return false;
255
+ }
256
+ return getComputedStyle(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
257
+ }
258
+ function getClippingElementAncestors(element, cache) {
259
+ const cachedResult = cache.get(element);
260
+ if (cachedResult) {
261
+ return cachedResult;
262
+ }
263
+ let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
264
+ let currentContainingBlockComputedStyle = null;
265
+ const elementIsFixed = getComputedStyle(element).position === "fixed";
266
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
267
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
268
+ const computedStyle = getComputedStyle(currentNode);
269
+ const currentNodeIsContaining = isContainingBlock(currentNode);
270
+ if (!currentNodeIsContaining && computedStyle.position === "fixed") {
271
+ currentContainingBlockComputedStyle = null;
270
272
  }
271
- elt.appendChild(content);
272
- }
273
- // Given an element, return its qualified name as defined in a behaviors object
274
- bName(e) {
275
- return e.tagName.substring(0, e.tagName.indexOf("-")).toLowerCase() + ":" + e.getAttribute("data-origname");
276
- }
277
- /*
278
- Private method called by append(). Takes a child element and a name, and recurses through the
279
- child's siblings until an element with that name is found, returning true if it is and false if not.
280
- */
281
- childExists(elt, name) {
282
- if (elt && elt.nodeName == name) {
283
- return true;
273
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && ["absolute", "fixed"].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
274
+ if (shouldDropCurrentNode) {
275
+ result = result.filter((ancestor) => ancestor !== currentNode);
284
276
  } else {
285
- return elt && elt.nextElementSibling && this.childExists(elt.nextElementSibling, name);
277
+ currentContainingBlockComputedStyle = computedStyle;
286
278
  }
279
+ currentNode = getParentNode(currentNode);
287
280
  }
288
- /*
289
- Takes a template in the form of either an array of 1 or 2
290
- strings or an object with CSS selector keys and either functions
291
- or arrays as described above. Returns a closure around a function
292
- that can be called in the element constructor or applied to an
293
- individual element. An empty array is considered a no-op.
294
-
295
- Called by the getHandler() and getFallback() methods
296
- */
297
- decorator(template) {
298
- if (Array.isArray(template) && template.length == 0) {
299
- return function(e) {
300
- };
281
+ cache.set(element, result);
282
+ return result;
283
+ }
284
+ function getClippingRect(_ref) {
285
+ let {
286
+ element,
287
+ boundary,
288
+ rootBoundary,
289
+ strategy
290
+ } = _ref;
291
+ const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
292
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
293
+ const firstClippingAncestor = clippingAncestors[0];
294
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
295
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
296
+ accRect.top = max(rect.top, accRect.top);
297
+ accRect.right = min(rect.right, accRect.right);
298
+ accRect.bottom = min(rect.bottom, accRect.bottom);
299
+ accRect.left = max(rect.left, accRect.left);
300
+ return accRect;
301
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
302
+ return {
303
+ width: clippingRect.right - clippingRect.left,
304
+ height: clippingRect.bottom - clippingRect.top,
305
+ x: clippingRect.left,
306
+ y: clippingRect.top
307
+ };
308
+ }
309
+ function getDimensions(element) {
310
+ const {
311
+ width,
312
+ height
313
+ } = getCssDimensions(element);
314
+ return {
315
+ width,
316
+ height
317
+ };
318
+ }
319
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
320
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
321
+ const documentElement = getDocumentElement(offsetParent);
322
+ const isFixed = strategy === "fixed";
323
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
324
+ let scroll = {
325
+ scrollLeft: 0,
326
+ scrollTop: 0
327
+ };
328
+ const offsets = createCoords(0);
329
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
330
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
331
+ scroll = getNodeScroll(offsetParent);
301
332
  }
302
- if (Array.isArray(template) && !Array.isArray(template[0])) {
303
- return this.applyDecorator(template);
333
+ if (isOffsetParentAnElement) {
334
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
335
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
336
+ offsets.y = offsetRect.y + offsetParent.clientTop;
337
+ } else if (documentElement) {
338
+ offsets.x = getWindowScrollBarX(documentElement);
304
339
  }
305
- let self = this;
306
- return function(elt) {
307
- for (let rule of template) {
308
- if (elt.matches(rule[0]) || rule[0] === "_") {
309
- if (Array.isArray(rule[1])) {
310
- return self.decorator(rule[1]).call(this, elt);
311
- } else {
312
- return rule[1].call(this, elt);
313
- }
314
- }
315
- }
316
- };
317
340
  }
318
- applyDecorator(strings) {
319
- let self = this;
320
- return function(elt) {
321
- let copy = [];
322
- for (let i = 0; i < strings.length; i++) {
323
- copy.push(self.template(strings[i], elt));
324
- }
325
- return self.insert(elt, copy);
326
- };
341
+ const x = rect.left + scroll.scrollLeft - offsets.x;
342
+ const y = rect.top + scroll.scrollTop - offsets.y;
343
+ return {
344
+ x,
345
+ y,
346
+ width: rect.width,
347
+ height: rect.height
348
+ };
349
+ }
350
+ function isStaticPositioned(element) {
351
+ return getComputedStyle(element).position === "static";
352
+ }
353
+ function getTrueOffsetParent(element, polyfill) {
354
+ if (!isHTMLElement(element) || getComputedStyle(element).position === "fixed") {
355
+ return null;
327
356
  }
328
- /*
329
- Returns the fallback function for the given element name.
330
- Called by fallback().
331
- */
332
- getFallback(behaviors, fn) {
333
- if (behaviors[fn]) {
334
- if (behaviors[fn] instanceof Function) {
335
- return behaviors[fn];
336
- } else {
337
- return this.decorator(behaviors[fn]);
338
- }
339
- }
357
+ if (polyfill) {
358
+ return polyfill(element);
359
+ }
360
+ return element.offsetParent;
361
+ }
362
+ function getOffsetParent(element, polyfill) {
363
+ const win = getWindow(element);
364
+ if (isTopLayer(element)) {
365
+ return win;
340
366
  }
341
- /*
342
- Returns the handler function for the given element name
343
- Called by define().
344
- */
345
- getHandler(behaviors, fn) {
346
- if (behaviors[fn]) {
347
- if (behaviors[fn] instanceof Function) {
348
- return this.append(behaviors[fn]);
349
- } else {
350
- return this.append(this.decorator(behaviors[fn]));
367
+ if (!isHTMLElement(element)) {
368
+ let svgOffsetParent = getParentNode(element);
369
+ while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
370
+ if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
371
+ return svgOffsetParent;
351
372
  }
373
+ svgOffsetParent = getParentNode(svgOffsetParent);
352
374
  }
375
+ return win;
353
376
  }
354
- insert(elt, strings) {
355
- let content = this.document.createElement("cetei-content");
356
- for (let node of Array.from(elt.childNodes)) {
357
- if (node.nodeType === 1 && !node.hasAttribute("data-processed")) {
358
- this.processElement(node);
359
- }
377
+ let offsetParent = getTrueOffsetParent(element, polyfill);
378
+ while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
379
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
380
+ }
381
+ if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
382
+ return win;
383
+ }
384
+ return offsetParent || getContainingBlock(element) || win;
385
+ }
386
+ const getElementRects = async function(data) {
387
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
388
+ const getDimensionsFn = this.getDimensions;
389
+ const floatingDimensions = await getDimensionsFn(data.floating);
390
+ return {
391
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
392
+ floating: {
393
+ x: 0,
394
+ y: 0,
395
+ width: floatingDimensions.width,
396
+ height: floatingDimensions.height
360
397
  }
361
- if (strings[0].match("<[^>]+>") && strings[1] && strings[1].match("<[^>]+>")) {
362
- content.innerHTML = strings[0] + elt.innerHTML + (strings[1] ? strings[1] : "");
363
- } else {
364
- content.innerHTML = strings[0];
365
- content.setAttribute("data-before", strings[0].replace(/<[^>]+>/g, "").length);
366
- for (let node of Array.from(elt.childNodes)) {
367
- content.appendChild(node.cloneNode(true));
368
- }
369
- if (strings.length > 1) {
370
- content.innerHTML += strings[1];
371
- content.setAttribute("data-after", strings[1].replace(/<[^>]+>/g, "").length);
372
- }
398
+ };
399
+ };
400
+ function isRTL(element) {
401
+ return getComputedStyle(element).direction === "rtl";
402
+ }
403
+ const platform = {
404
+ convertOffsetParentRelativeRectToViewportRelativeRect,
405
+ getDocumentElement,
406
+ getClippingRect,
407
+ getOffsetParent,
408
+ getElementRects,
409
+ getClientRects,
410
+ getDimensions,
411
+ getScale,
412
+ isElement,
413
+ isRTL
414
+ };
415
+ function observeMove(element, onMove) {
416
+ let io = null;
417
+ let timeoutId;
418
+ const root = getDocumentElement(element);
419
+ function cleanup() {
420
+ var _io;
421
+ clearTimeout(timeoutId);
422
+ (_io = io) == null || _io.disconnect();
423
+ io = null;
424
+ }
425
+ function refresh(skip, threshold) {
426
+ if (skip === void 0) {
427
+ skip = false;
373
428
  }
374
- if (content.childNodes.length < 2) {
375
- return content.firstChild;
376
- } else {
377
- return content;
429
+ if (threshold === void 0) {
430
+ threshold = 1;
378
431
  }
379
- }
380
- // Runs behaviors recursively on the supplied element and children
381
- processElement(elt) {
382
- if (elt.hasAttribute("data-origname") && !elt.hasAttribute("data-processed")) {
383
- let fn = this.getFallback(this.bName(elt));
384
- if (fn) {
385
- this.append(fn, elt);
386
- elt.setAttribute("data-processed", "");
387
- }
432
+ cleanup();
433
+ const {
434
+ left,
435
+ top,
436
+ width,
437
+ height
438
+ } = element.getBoundingClientRect();
439
+ if (!skip) {
440
+ onMove();
388
441
  }
389
- for (let node of Array.from(elt.childNodes)) {
390
- if (node.nodeType === 1) {
391
- this.processElement(node);
392
- }
442
+ if (!width || !height) {
443
+ return;
393
444
  }
394
- }
395
- template(str, elt) {
396
- let result = str;
397
- if (str.search(/\$(\w*)(@([a-zA-Z:]+))/)) {
398
- let re = /\$(\w*)@([a-zA-Z:]+)/g;
399
- let replacements;
400
- while (replacements = re.exec(str)) {
401
- if (elt.hasAttribute(replacements[2])) {
402
- if (replacements[1] && this.utilities[replacements[1]]) {
403
- result = result.replace(replacements[0], this.utilities[replacements[1]](elt.getAttribute(replacements[2])));
404
- } else {
405
- result = result.replace(replacements[0], elt.getAttribute(replacements[2]));
406
- }
445
+ const insetTop = floor(top);
446
+ const insetRight = floor(root.clientWidth - (left + width));
447
+ const insetBottom = floor(root.clientHeight - (top + height));
448
+ const insetLeft = floor(left);
449
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
450
+ const options = {
451
+ rootMargin,
452
+ threshold: max(0, min(1, threshold)) || 1
453
+ };
454
+ let isFirstUpdate = true;
455
+ function handleObserve(entries) {
456
+ const ratio = entries[0].intersectionRatio;
457
+ if (ratio !== threshold) {
458
+ if (!isFirstUpdate) {
459
+ return refresh();
460
+ }
461
+ if (!ratio) {
462
+ timeoutId = setTimeout(() => {
463
+ refresh(false, 1e-7);
464
+ }, 1e3);
407
465
  } else {
408
- result = result.replace(replacements[0], "");
466
+ refresh(false, ratio);
409
467
  }
410
468
  }
469
+ isFirstUpdate = false;
411
470
  }
412
- return result;
413
- }
414
- // Define or apply behaviors for the document
415
- applyBehaviors() {
416
- if (typeof window !== "undefined" && window.customElements) {
417
- this.define.call(this, this.els);
418
- } else {
419
- this.fallback.call(this, this.els);
471
+ try {
472
+ io = new IntersectionObserver(handleObserve, {
473
+ ...options,
474
+ // Handle <iframe>s
475
+ root: root.ownerDocument
476
+ });
477
+ } catch (e) {
478
+ io = new IntersectionObserver(handleObserve, options);
420
479
  }
480
+ io.observe(element);
421
481
  }
422
- /*
423
- Registers the list of elements provided with the browser.
424
- Called by makeHTML5(), but can be called independently if, for example,
425
- you've created Custom Elements via an XSLT transformation instead.
426
- */
427
- define(names) {
428
- for (let name of names) {
429
- const fn = this.getHandler(this.behaviors, name);
430
- defineCustomElement(name, fn, this.debug);
431
- }
482
+ refresh(true);
483
+ return cleanup;
484
+ }
485
+ function autoUpdate(reference, floating, update, options) {
486
+ if (options === void 0) {
487
+ options = {};
432
488
  }
433
- /*
434
- Provides fallback functionality for environments where Custom Elements
435
- are not supported.
436
-
437
- Like define(), this is called by makeHTML5(), but can be called
438
- independently.
439
- */
440
- fallback(names) {
441
- for (let name of names) {
442
- let fn = this.getFallback(this.behaviors, name);
443
- if (fn) {
444
- for (let elt of Array.from((this.dom && !this.done ? this.dom : this.document).querySelectorAll(tagName(name)))) {
445
- if (!elt.hasAttribute("data-processed")) {
446
- this.append(fn, elt);
447
- elt.setAttribute("data-processed", "");
448
- }
449
- }
450
- }
489
+ const {
490
+ ancestorScroll = true,
491
+ ancestorResize = true,
492
+ elementResize = typeof ResizeObserver === "function",
493
+ layoutShift = typeof IntersectionObserver === "function",
494
+ animationFrame = false
495
+ } = options;
496
+ const referenceEl = unwrapElement(reference);
497
+ const ancestors = ancestorScroll || ancestorResize ? [...referenceEl ? getOverflowAncestors(referenceEl) : [], ...getOverflowAncestors(floating)] : [];
498
+ ancestors.forEach((ancestor) => {
499
+ ancestorScroll && ancestor.addEventListener("scroll", update, {
500
+ passive: true
501
+ });
502
+ ancestorResize && ancestor.addEventListener("resize", update);
503
+ });
504
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
505
+ let reobserveFrame = -1;
506
+ let resizeObserver = null;
507
+ if (elementResize) {
508
+ resizeObserver = new ResizeObserver((_ref) => {
509
+ let [firstEntry] = _ref;
510
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
511
+ resizeObserver.unobserve(floating);
512
+ cancelAnimationFrame(reobserveFrame);
513
+ reobserveFrame = requestAnimationFrame(() => {
514
+ var _resizeObserver;
515
+ (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
516
+ });
517
+ }
518
+ update();
519
+ });
520
+ if (referenceEl && !animationFrame) {
521
+ resizeObserver.observe(referenceEl);
451
522
  }
523
+ resizeObserver.observe(floating);
452
524
  }
453
- /**********************
454
- * Utility functions *
455
- **********************/
456
- static savePosition() {
457
- window.sessionStorage.setItem(window.location + "-scroll", window.scrollY);
458
- }
459
- static restorePosition() {
460
- if (!window.location.hash) {
461
- let scroll;
462
- if (scroll = window.sessionStorage.getItem(window.location + "-scroll")) {
463
- window.sessionStorage.removeItem(window.location + "-scroll");
464
- setTimeout(function() {
465
- window.scrollTo(0, scroll);
466
- }, 100);
467
- }
468
- } else {
469
- setTimeout(function() {
470
- let h = this.document.querySelector(window.decodeURI(window.location.hash));
471
- if (h) {
472
- h.scrollIntoView();
473
- }
474
- }, 100);
525
+ let frameId;
526
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
527
+ if (animationFrame) {
528
+ frameLoop();
529
+ }
530
+ function frameLoop() {
531
+ const nextRefRect = getBoundingClientRect(reference);
532
+ if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
533
+ update();
475
534
  }
535
+ prevRefRect = nextRefRect;
536
+ frameId = requestAnimationFrame(frameLoop);
476
537
  }
538
+ update();
539
+ return () => {
540
+ var _resizeObserver2;
541
+ ancestors.forEach((ancestor) => {
542
+ ancestorScroll && ancestor.removeEventListener("scroll", update);
543
+ ancestorResize && ancestor.removeEventListener("resize", update);
544
+ });
545
+ cleanupIo == null || cleanupIo();
546
+ (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
547
+ resizeObserver = null;
548
+ if (animationFrame) {
549
+ cancelAnimationFrame(frameId);
550
+ }
551
+ };
477
552
  }
478
- try {
479
- if (typeof window !== "undefined") {
480
- window.CETEI = CETEI;
481
- window.addEventListener("beforeunload", CETEI.savePosition);
482
- var ceteiceanLoad = new Event("ceteiceanload");
483
- window.addEventListener("ceteiceanload", CETEI.restorePosition);
484
- }
485
- } catch (e) {
486
- console.log(e);
487
- }
553
+ const offset = offset$1;
554
+ const autoPlacement = autoPlacement$1;
555
+ const shift = shift$1;
556
+ const inline = inline$1;
557
+ const computePosition = (reference, floating, options) => {
558
+ const cache = /* @__PURE__ */ new Map();
559
+ const mergedOptions = {
560
+ platform,
561
+ ...options
562
+ };
563
+ const platformWithCache = {
564
+ ...mergedOptions.platform,
565
+ _c: cache
566
+ };
567
+ return computePosition$1(reference, floating, {
568
+ ...mergedOptions,
569
+ platform: platformWithCache
570
+ });
571
+ };
488
572
  export {
489
- CETEI as default
573
+ autoPlacement,
574
+ autoUpdate,
575
+ computePosition,
576
+ getOverflowAncestors,
577
+ inline,
578
+ offset,
579
+ platform,
580
+ shift
490
581
  };
491
582
  //# sourceMappingURL=react-text-annotator.es11.js.map