@soomo/react-text-annotator 3.2.0-staging.4 → 3.2.0-staging.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 (37) hide show
  1. package/dist/react-text-annotator.es10.js +497 -78
  2. package/dist/react-text-annotator.es10.js.map +1 -1
  3. package/dist/react-text-annotator.es11.js +77 -40
  4. package/dist/react-text-annotator.es11.js.map +1 -1
  5. package/dist/react-text-annotator.es12.js +41 -21
  6. package/dist/react-text-annotator.es12.js.map +1 -1
  7. package/dist/react-text-annotator.es13.js +19 -1637
  8. package/dist/react-text-annotator.es13.js.map +1 -1
  9. package/dist/react-text-annotator.es14.js +1642 -9
  10. package/dist/react-text-annotator.es14.js.map +1 -1
  11. package/dist/react-text-annotator.es15.js +13 -0
  12. package/dist/react-text-annotator.es15.js.map +1 -0
  13. package/dist/react-text-annotator.es17.js +566 -244
  14. package/dist/react-text-annotator.es17.js.map +1 -1
  15. package/dist/react-text-annotator.es18.js +252 -471
  16. package/dist/react-text-annotator.es18.js.map +1 -1
  17. package/dist/react-text-annotator.es2.js +1 -1
  18. package/dist/react-text-annotator.es25.js +111 -124
  19. package/dist/react-text-annotator.es25.js.map +1 -1
  20. package/dist/react-text-annotator.es26.js +285 -140
  21. package/dist/react-text-annotator.es26.js.map +1 -1
  22. package/dist/react-text-annotator.es27.js +43 -296
  23. package/dist/react-text-annotator.es27.js.map +1 -1
  24. package/dist/react-text-annotator.es28.js +19 -113
  25. package/dist/react-text-annotator.es28.js.map +1 -1
  26. package/dist/react-text-annotator.es29.js +105 -287
  27. package/dist/react-text-annotator.es29.js.map +1 -1
  28. package/dist/react-text-annotator.es30.js +154 -48
  29. package/dist/react-text-annotator.es30.js.map +1 -1
  30. package/dist/react-text-annotator.es31.js +310 -19
  31. package/dist/react-text-annotator.es31.js.map +1 -1
  32. package/dist/react-text-annotator.es4.js +2 -2
  33. package/dist/react-text-annotator.es5.js +1 -1
  34. package/dist/react-text-annotator.es7.js +4 -4
  35. package/package.json +2 -2
  36. package/dist/react-text-annotator.es16.js +0 -607
  37. package/dist/react-text-annotator.es16.js.map +0 -1
@@ -1,504 +1,285 @@
1
- import defaultBehaviors from "./react-text-annotator.es28.js";
2
- import * as utilities from "./react-text-annotator.es29.js";
3
- import { hideContent, defineCustomElement, tagName } from "./react-text-annotator.es29.js";
4
- import { addBehaviors, addBehavior, removeBehavior } from "./react-text-annotator.es30.js";
5
- import { learnElementNames, learnCustomElementNames } from "./react-text-annotator.es31.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];
26
- }
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
- } 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
- }
53
- }
1
+ import { inline as inline$1, offset as offset$1, flip as flip$1, shift as shift$1, computePosition, arrow as arrow$2 } from "./react-text-annotator.es17.js";
2
+ import { autoUpdate, platform } from "./react-text-annotator.es17.js";
3
+ import * as React from "react";
4
+ import { useLayoutEffect, useEffect } from "react";
5
+ import * as ReactDOM from "react-dom";
6
+ var index = typeof document !== "undefined" ? useLayoutEffect : useEffect;
7
+ function deepEqual(a, b) {
8
+ if (a === b) {
9
+ return true;
54
10
  }
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(/\/[^\/]*$/, "/");
63
- }
64
- 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);
75
- }
11
+ if (typeof a !== typeof b) {
12
+ return false;
76
13
  }
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);
14
+ if (typeof a === "function" && a.toString() === b.toString()) {
15
+ return true;
84
16
  }
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" && el.namespaceURI == "http://www.tei-c.org/ns/1.0") {
119
- let getLevel = function(el2) {
120
- let count = 0;
121
- let ancestor = el2.parentElement;
122
- while (ancestor) {
123
- let children = ancestor.children;
124
- let i = 0;
125
- while (i < children.length) {
126
- if (children[i].tagName.toLowerCase() === "head" && children[i].namespaceURI === "http://www.tei-c.org/ns/1.0") {
127
- count++;
128
- break;
129
- }
130
- i++;
131
- }
132
- ancestor = ancestor.parentElement;
133
- }
134
- return count;
135
- };
136
- newElement.setAttribute("data-level", getLevel(el));
137
- }
138
- if (el.localName == "tagsDecl") {
139
- let style = this.document.createElement("style");
140
- for (let node of Array.from(el.childNodes)) {
141
- if (node.nodeType == 1 && node.localName == "rendition" && node.getAttribute("scheme") == "css") {
142
- let rule = "";
143
- if (node.hasAttribute("selector")) {
144
- rule += node.getAttribute("selector").replace(/([^#, >]+\w*)/g, "tei-$1").replace(/#tei-/g, "#") + "{\n";
145
- rule += node.textContent;
146
- } else {
147
- rule += "." + node.getAttribute("xml:id") + "{\n";
148
- rule += node.textContent;
149
- }
150
- rule += "\n}\n";
151
- style.appendChild(this.document.createTextNode(rule));
152
- }
153
- }
154
- if (style.childNodes.length > 0) {
155
- newElement.appendChild(style);
156
- this.hasStyle = true;
17
+ let length;
18
+ let i;
19
+ let keys;
20
+ if (a && b && typeof a === "object") {
21
+ if (Array.isArray(a)) {
22
+ length = a.length;
23
+ if (length !== b.length) return false;
24
+ for (i = length; i-- !== 0; ) {
25
+ if (!deepEqual(a[i], b[i])) {
26
+ return false;
157
27
  }
158
28
  }
159
- if (el.localName == "prefixDef") {
160
- this.prefixDefs.push(el.getAttribute("ident"));
161
- this.prefixDefs[el.getAttribute("ident")] = {
162
- "matchPattern": el.getAttribute("matchPattern"),
163
- "replacementPattern": el.getAttribute("replacementPattern")
164
- };
165
- }
166
- for (let node of Array.from(el.childNodes)) {
167
- if (node.nodeType == 1) {
168
- newElement.appendChild(convertEl(node));
169
- } else {
170
- newElement.appendChild(node.cloneNode());
171
- }
172
- }
173
- if (perElementFn) {
174
- perElementFn(newElement, el);
175
- }
176
- return newElement;
177
- };
178
- this.dom = this.document.createDocumentFragment();
179
- for (let node of Array.from(XML_dom.childNodes)) {
180
- if (node.nodeType == 1) {
181
- this.dom.appendChild(convertEl(node));
182
- }
183
- if (node.nodeType == 7) {
184
- this.dom.appendChild(this.document.importNode(node, true));
185
- }
186
- if (node.nodeType == 8) {
187
- this.dom.appendChild(this.document.importNode(node, true));
188
- }
29
+ return true;
189
30
  }
190
- this.utilities.dom = this.dom.firstElementChild;
191
- if (callback) {
192
- callback(this.dom, this);
193
- if (window) {
194
- window.dispatchEvent(ceteiceanLoad);
195
- }
196
- } else {
197
- if (typeof window !== "undefined") {
198
- window.dispatchEvent(ceteiceanLoad);
31
+ keys = Object.keys(a);
32
+ length = keys.length;
33
+ if (length !== Object.keys(b).length) {
34
+ return false;
35
+ }
36
+ for (i = length; i-- !== 0; ) {
37
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
38
+ return false;
199
39
  }
200
- return this.dom;
201
40
  }
202
- }
203
- /*
204
- Converts the supplied XML DOM into HTML5 Custom Elements. If a callback
205
- function is supplied, calls it on the result.
206
- */
207
- domToHTML5(XML_dom, callback, perElementFn) {
208
- this.preprocess(XML_dom, null, perElementFn);
209
- this.applyBehaviors();
210
- this.done = true;
211
- if (callback) {
212
- callback(this.dom, this);
213
- if (window) {
214
- window.dispatchEvent(ceteiceanLoad);
41
+ for (i = length; i-- !== 0; ) {
42
+ const key = keys[i];
43
+ if (key === "_owner" && a.$$typeof) {
44
+ continue;
215
45
  }
216
- } else {
217
- if (typeof window !== "undefined") {
218
- window.dispatchEvent(ceteiceanLoad);
46
+ if (!deepEqual(a[key], b[key])) {
47
+ return false;
219
48
  }
220
- return this.dom;
221
49
  }
50
+ return true;
222
51
  }
223
- /*
224
- Convenience method for HTML pages containing pre-processed CETEIcean Custom
225
- Elements. Usage:
226
- const c = new CETEI();
227
- c.processPage();
228
- */
229
- processPage() {
230
- this.els = learnCustomElementNames(this.document);
231
- this.applyBehaviors();
232
- if (window) {
233
- window.dispatchEvent(ceteiceanLoad);
234
- }
235
- }
236
- /*
237
- To change a namespace -> prefix mapping, the namespace must first be
238
- unset. Takes a namespace URI. In order to process a TEI P4 document, e.g.,
239
- the TEI namespace must be unset before it can be set to the empty string.
240
- */
241
- unsetNamespace(ns) {
242
- this.namespaces.delete(ns);
243
- }
244
- /*
245
- Sets the base URL for the document. Used to rewrite relative links in the
246
- XML source (which may be in a completely different location from the HTML
247
- wrapper).
248
- */
249
- setBaseUrl(base) {
250
- this.base = base;
251
- }
252
- /*
253
- Appends any element returned by the function passed in the first
254
- parameter to the element in the second parameter. If the function
255
- returns nothing, this is a no-op aside from any side effects caused
256
- by the provided function.
257
-
258
- Called by getHandler() and fallback()
259
- */
260
- append(fn, elt) {
261
- let self = this;
262
- if (elt && !elt.hasAttribute("data-processed")) {
263
- let content = fn.call(self.utilities, elt);
264
- if (content) {
265
- self.appendBasic(elt, content);
266
- }
267
- } else {
268
- return function() {
269
- if (!this.hasAttribute("data-processed")) {
270
- let content = fn.call(self.utilities, this);
271
- if (content) {
272
- self.appendBasic(this, content);
273
- }
274
- }
275
- };
276
- }
52
+ return a !== a && b !== b;
53
+ }
54
+ function getDPR(element) {
55
+ if (typeof window === "undefined") {
56
+ return 1;
277
57
  }
278
- appendBasic(elt, content) {
279
- if (this.discardContent) {
280
- elt.innerHTML = "";
281
- } else {
282
- hideContent(elt, true);
283
- }
284
- elt.appendChild(content);
58
+ const win = element.ownerDocument.defaultView || window;
59
+ return win.devicePixelRatio || 1;
60
+ }
61
+ function roundByDPR(element, value) {
62
+ const dpr = getDPR(element);
63
+ return Math.round(value * dpr) / dpr;
64
+ }
65
+ function useLatestRef(value) {
66
+ const ref = React.useRef(value);
67
+ index(() => {
68
+ ref.current = value;
69
+ });
70
+ return ref;
71
+ }
72
+ function useFloating(options) {
73
+ if (options === void 0) {
74
+ options = {};
285
75
  }
286
- // Given an element, return its qualified name as defined in a behaviors object
287
- bName(e) {
288
- return e.tagName.substring(0, e.tagName.indexOf("-")).toLowerCase() + ":" + e.getAttribute("data-origname");
76
+ const {
77
+ placement = "bottom",
78
+ strategy = "absolute",
79
+ middleware = [],
80
+ platform: platform2,
81
+ elements: {
82
+ reference: externalReference,
83
+ floating: externalFloating
84
+ } = {},
85
+ transform = true,
86
+ whileElementsMounted,
87
+ open
88
+ } = options;
89
+ const [data, setData] = React.useState({
90
+ x: 0,
91
+ y: 0,
92
+ strategy,
93
+ placement,
94
+ middlewareData: {},
95
+ isPositioned: false
96
+ });
97
+ const [latestMiddleware, setLatestMiddleware] = React.useState(middleware);
98
+ if (!deepEqual(latestMiddleware, middleware)) {
99
+ setLatestMiddleware(middleware);
289
100
  }
290
- /*
291
- Private method called by append(). Takes a child element and a name, and recurses through the
292
- child's siblings until an element with that name is found, returning true if it is and false if not.
293
- */
294
- childExists(elt, name) {
295
- if (elt && elt.nodeName == name) {
296
- return true;
297
- } else {
298
- return elt && elt.nextElementSibling && this.childExists(elt.nextElementSibling, name);
101
+ const [_reference, _setReference] = React.useState(null);
102
+ const [_floating, _setFloating] = React.useState(null);
103
+ const setReference = React.useCallback((node) => {
104
+ if (node !== referenceRef.current) {
105
+ referenceRef.current = node;
106
+ _setReference(node);
299
107
  }
300
- }
301
- /*
302
- Takes a template in the form of either an array of 1 or 2
303
- strings or an object with CSS selector keys and either functions
304
- or arrays as described above. Returns a closure around a function
305
- that can be called in the element constructor or applied to an
306
- individual element. An empty array is considered a no-op.
307
-
308
- Called by the getHandler() and getFallback() methods
309
- */
310
- decorator(template) {
311
- if (Array.isArray(template) && template.length == 0) {
312
- return function(e) {
313
- };
108
+ }, []);
109
+ const setFloating = React.useCallback((node) => {
110
+ if (node !== floatingRef.current) {
111
+ floatingRef.current = node;
112
+ _setFloating(node);
314
113
  }
315
- if (Array.isArray(template) && !Array.isArray(template[0])) {
316
- return this.applyDecorator(template);
114
+ }, []);
115
+ const referenceEl = externalReference || _reference;
116
+ const floatingEl = externalFloating || _floating;
117
+ const referenceRef = React.useRef(null);
118
+ const floatingRef = React.useRef(null);
119
+ const dataRef = React.useRef(data);
120
+ const hasWhileElementsMounted = whileElementsMounted != null;
121
+ const whileElementsMountedRef = useLatestRef(whileElementsMounted);
122
+ const platformRef = useLatestRef(platform2);
123
+ const openRef = useLatestRef(open);
124
+ const update = React.useCallback(() => {
125
+ if (!referenceRef.current || !floatingRef.current) {
126
+ return;
317
127
  }
318
- let self = this;
319
- return function(elt) {
320
- for (let rule of template) {
321
- if (elt.matches(rule[0]) || rule[0] === "_") {
322
- if (Array.isArray(rule[1])) {
323
- return self.decorator(rule[1]).call(this, elt);
324
- } else {
325
- return rule[1].call(this, elt);
326
- }
327
- }
328
- }
329
- };
330
- }
331
- applyDecorator(strings) {
332
- let self = this;
333
- return function(elt) {
334
- let copy = [];
335
- for (let i = 0; i < strings.length; i++) {
336
- copy.push(self.template(strings[i], elt));
337
- }
338
- return self.insert(elt, copy);
128
+ const config = {
129
+ placement,
130
+ strategy,
131
+ middleware: latestMiddleware
339
132
  };
340
- }
341
- /*
342
- Returns the fallback function for the given element name.
343
- Called by fallback().
344
- */
345
- getFallback(behaviors, fn) {
346
- if (behaviors[fn]) {
347
- if (behaviors[fn] instanceof Function) {
348
- return behaviors[fn];
349
- } else {
350
- return this.decorator(behaviors[fn]);
351
- }
133
+ if (platformRef.current) {
134
+ config.platform = platformRef.current;
352
135
  }
353
- }
354
- /*
355
- Returns the handler function for the given element name
356
- Called by define().
357
- */
358
- getHandler(behaviors, fn) {
359
- if (behaviors[fn]) {
360
- if (behaviors[fn] instanceof Function) {
361
- return this.append(behaviors[fn]);
362
- } else {
363
- return this.append(this.decorator(behaviors[fn]));
364
- }
365
- }
366
- }
367
- insert(elt, strings) {
368
- let content = this.document.createElement("cetei-content");
369
- for (let node of Array.from(elt.childNodes)) {
370
- if (node.nodeType === 1 && !node.hasAttribute("data-processed")) {
371
- this.processElement(node);
372
- }
373
- }
374
- if (strings[0].match("<[^>]+>") && strings[1] && strings[1].match("<[^>]+>")) {
375
- content.innerHTML = strings[0] + elt.innerHTML + (strings[1] ? strings[1] : "");
376
- } else {
377
- content.innerHTML = strings[0];
378
- content.setAttribute("data-before", strings[0].replace(/<[^>]+>/g, "").length);
379
- for (let node of Array.from(elt.childNodes)) {
380
- content.appendChild(node.cloneNode(true));
381
- }
382
- if (strings.length > 1) {
383
- content.innerHTML += strings[1];
384
- content.setAttribute("data-after", strings[1].replace(/<[^>]+>/g, "").length);
385
- }
386
- }
387
- if (content.childNodes.length < 2) {
388
- return content.firstChild;
389
- } else {
390
- return content;
136
+ computePosition(referenceRef.current, floatingRef.current, config).then((data2) => {
137
+ const fullData = {
138
+ ...data2,
139
+ // The floating element's position may be recomputed while it's closed
140
+ // but still mounted (such as when transitioning out). To ensure
141
+ // `isPositioned` will be `false` initially on the next open, avoid
142
+ // setting it to `true` when `open === false` (must be specified).
143
+ isPositioned: openRef.current !== false
144
+ };
145
+ if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
146
+ dataRef.current = fullData;
147
+ ReactDOM.flushSync(() => {
148
+ setData(fullData);
149
+ });
150
+ }
151
+ });
152
+ }, [latestMiddleware, placement, strategy, platformRef, openRef]);
153
+ index(() => {
154
+ if (open === false && dataRef.current.isPositioned) {
155
+ dataRef.current.isPositioned = false;
156
+ setData((data2) => ({
157
+ ...data2,
158
+ isPositioned: false
159
+ }));
391
160
  }
392
- }
393
- // Runs behaviors recursively on the supplied element and children
394
- processElement(elt) {
395
- if (elt.hasAttribute("data-origname") && !elt.hasAttribute("data-processed")) {
396
- let fn = this.getFallback(this.bName(elt));
397
- if (fn) {
398
- this.append(fn, elt);
399
- elt.setAttribute("data-processed", "");
400
- }
161
+ }, [open]);
162
+ const isMountedRef = React.useRef(false);
163
+ index(() => {
164
+ isMountedRef.current = true;
165
+ return () => {
166
+ isMountedRef.current = false;
167
+ };
168
+ }, []);
169
+ index(() => {
170
+ if (referenceEl) referenceRef.current = referenceEl;
171
+ if (floatingEl) floatingRef.current = floatingEl;
172
+ if (referenceEl && floatingEl) {
173
+ if (whileElementsMountedRef.current) {
174
+ return whileElementsMountedRef.current(referenceEl, floatingEl, update);
175
+ }
176
+ update();
401
177
  }
402
- for (let node of Array.from(elt.childNodes)) {
403
- if (node.nodeType === 1) {
404
- this.processElement(node);
405
- }
178
+ }, [referenceEl, floatingEl, update, whileElementsMountedRef, hasWhileElementsMounted]);
179
+ const refs = React.useMemo(() => ({
180
+ reference: referenceRef,
181
+ floating: floatingRef,
182
+ setReference,
183
+ setFloating
184
+ }), [setReference, setFloating]);
185
+ const elements = React.useMemo(() => ({
186
+ reference: referenceEl,
187
+ floating: floatingEl
188
+ }), [referenceEl, floatingEl]);
189
+ const floatingStyles = React.useMemo(() => {
190
+ const initialStyles = {
191
+ position: strategy,
192
+ left: 0,
193
+ top: 0
194
+ };
195
+ if (!elements.floating) {
196
+ return initialStyles;
406
197
  }
407
- }
408
- template(str, elt) {
409
- let result = str;
410
- if (str.search(/\$(\w*)(@([a-zA-Z:]+))/)) {
411
- let re = /\$(\w*)@([a-zA-Z:]+)/g;
412
- let replacements;
413
- while (replacements = re.exec(str)) {
414
- if (elt.hasAttribute(replacements[2])) {
415
- if (replacements[1] && this.utilities[replacements[1]]) {
416
- result = result.replace(replacements[0], this.utilities[replacements[1]](elt.getAttribute(replacements[2])));
417
- } else {
418
- result = result.replace(replacements[0], elt.getAttribute(replacements[2]));
419
- }
420
- } else {
421
- result = result.replace(replacements[0], "");
198
+ const x = roundByDPR(elements.floating, data.x);
199
+ const y = roundByDPR(elements.floating, data.y);
200
+ if (transform) {
201
+ return {
202
+ ...initialStyles,
203
+ transform: "translate(" + x + "px, " + y + "px)",
204
+ ...getDPR(elements.floating) >= 1.5 && {
205
+ willChange: "transform"
422
206
  }
423
- }
424
- }
425
- return result;
426
- }
427
- // Define or apply behaviors for the document
428
- applyBehaviors() {
429
- if (typeof window !== "undefined" && window.customElements) {
430
- this.define.call(this, this.els);
431
- } else {
432
- this.fallback.call(this, this.els);
433
- }
434
- }
435
- /*
436
- Registers the list of elements provided with the browser.
437
- Called by makeHTML5(), but can be called independently if, for example,
438
- you've created Custom Elements via an XSLT transformation instead.
439
- */
440
- define(names) {
441
- for (let name of names) {
442
- const fn = this.getHandler(this.behaviors, name);
443
- defineCustomElement(name, fn, this.debug);
207
+ };
444
208
  }
209
+ return {
210
+ position: strategy,
211
+ left: x,
212
+ top: y
213
+ };
214
+ }, [strategy, transform, elements.floating, data.x, data.y]);
215
+ return React.useMemo(() => ({
216
+ ...data,
217
+ update,
218
+ refs,
219
+ elements,
220
+ floatingStyles
221
+ }), [data, update, refs, elements, floatingStyles]);
222
+ }
223
+ const arrow$1 = (options) => {
224
+ function isRef(value) {
225
+ return {}.hasOwnProperty.call(value, "current");
445
226
  }
446
- /*
447
- Provides fallback functionality for environments where Custom Elements
448
- are not supported.
449
-
450
- Like define(), this is called by makeHTML5(), but can be called
451
- independently.
452
- */
453
- fallback(names) {
454
- for (let name of names) {
455
- let fn = this.getFallback(this.behaviors, name);
456
- if (fn) {
457
- for (let elt of Array.from((this.dom && !this.done ? this.dom : this.document).querySelectorAll(tagName(name)))) {
458
- if (!elt.hasAttribute("data-processed")) {
459
- this.append(fn, elt);
460
- elt.setAttribute("data-processed", "");
461
- }
227
+ return {
228
+ name: "arrow",
229
+ options,
230
+ fn(state) {
231
+ const {
232
+ element,
233
+ padding
234
+ } = typeof options === "function" ? options(state) : options;
235
+ if (element && isRef(element)) {
236
+ if (element.current != null) {
237
+ return arrow$2({
238
+ element: element.current,
239
+ padding
240
+ }).fn(state);
462
241
  }
242
+ return {};
463
243
  }
464
- }
465
- }
466
- /**********************
467
- * Utility functions *
468
- **********************/
469
- static savePosition() {
470
- window.sessionStorage.setItem(window.location + "-scroll", window.scrollY);
471
- }
472
- static restorePosition() {
473
- if (!window.location.hash) {
474
- let scroll;
475
- if (scroll = window.sessionStorage.getItem(window.location + "-scroll")) {
476
- window.sessionStorage.removeItem(window.location + "-scroll");
477
- setTimeout(function() {
478
- window.scrollTo(0, scroll);
479
- }, 100);
244
+ if (element) {
245
+ return arrow$2({
246
+ element,
247
+ padding
248
+ }).fn(state);
480
249
  }
481
- } else {
482
- setTimeout(function() {
483
- let h = this.document.querySelector(window.decodeURI(window.location.hash));
484
- if (h) {
485
- h.scrollIntoView();
486
- }
487
- }, 100);
250
+ return {};
488
251
  }
489
- }
490
- }
491
- try {
492
- if (typeof window !== "undefined") {
493
- window.CETEI = CETEI;
494
- window.addEventListener("beforeunload", CETEI.savePosition);
495
- var ceteiceanLoad = new Event("ceteiceanload");
496
- window.addEventListener("ceteiceanload", CETEI.restorePosition);
497
- }
498
- } catch (e) {
499
- console.log(e);
500
- }
252
+ };
253
+ };
254
+ const offset = (options, deps) => ({
255
+ ...offset$1(options),
256
+ options: [options, deps]
257
+ });
258
+ const shift = (options, deps) => ({
259
+ ...shift$1(options),
260
+ options: [options, deps]
261
+ });
262
+ const flip = (options, deps) => ({
263
+ ...flip$1(options),
264
+ options: [options, deps]
265
+ });
266
+ const inline = (options, deps) => ({
267
+ ...inline$1(options),
268
+ options: [options, deps]
269
+ });
270
+ const arrow = (options, deps) => ({
271
+ ...arrow$1(options),
272
+ options: [options, deps]
273
+ });
501
274
  export {
502
- CETEI as default
275
+ arrow,
276
+ autoUpdate,
277
+ computePosition,
278
+ flip,
279
+ inline,
280
+ offset,
281
+ platform,
282
+ shift,
283
+ useFloating
503
284
  };
504
285
  //# sourceMappingURL=react-text-annotator.es18.js.map