@soomo/react-text-annotator 3.0.0-staging.4 → 3.0.0-staging.40

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 (77) hide show
  1. package/dist/TextAnnotator.d.ts +3 -3
  2. package/dist/TextAnnotator.d.ts.map +1 -1
  3. package/dist/TextAnnotatorPlugin.d.ts +1 -2
  4. package/dist/TextAnnotatorPlugin.d.ts.map +1 -1
  5. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts +16 -0
  6. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +1 -0
  7. package/dist/TextAnnotatorPopup/index.d.ts +2 -0
  8. package/dist/TextAnnotatorPopup/index.d.ts.map +1 -0
  9. package/dist/hooks/index.d.ts +3 -0
  10. package/dist/hooks/index.d.ts.map +1 -0
  11. package/dist/hooks/useAnnouncePopupNavigation.d.ts +10 -0
  12. package/dist/hooks/useAnnouncePopupNavigation.d.ts.map +1 -0
  13. package/dist/hooks/useRestoreSelectionCaret.d.ts +13 -0
  14. package/dist/hooks/useRestoreSelectionCaret.d.ts.map +1 -0
  15. package/dist/index.d.ts +7 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/react-text-annotator.css +31 -1
  18. package/dist/react-text-annotator.es.js +14 -4
  19. package/dist/react-text-annotator.es.js.map +1 -1
  20. package/dist/react-text-annotator.es11.js +459 -861
  21. package/dist/react-text-annotator.es11.js.map +1 -1
  22. package/dist/react-text-annotator.es12.js +64 -2
  23. package/dist/react-text-annotator.es12.js.map +1 -1
  24. package/dist/react-text-annotator.es13.js +45 -2
  25. package/dist/react-text-annotator.es13.js.map +1 -1
  26. package/dist/react-text-annotator.es14.js +1444 -107
  27. package/dist/react-text-annotator.es14.js.map +1 -1
  28. package/dist/react-text-annotator.es16.js +228 -45
  29. package/dist/react-text-annotator.es16.js.map +1 -1
  30. package/dist/react-text-annotator.es17.js +565 -16
  31. package/dist/react-text-annotator.es17.js.map +1 -1
  32. package/dist/react-text-annotator.es18.js +5 -0
  33. package/dist/react-text-annotator.es18.js.map +1 -0
  34. package/dist/{react-text-annotator.es10.js → react-text-annotator.es19.js} +7 -11
  35. package/dist/{react-text-annotator.es10.js.map → react-text-annotator.es19.js.map} +1 -1
  36. package/dist/react-text-annotator.es2.js +2 -2
  37. package/dist/react-text-annotator.es20.js +901 -0
  38. package/dist/react-text-annotator.es20.js.map +1 -0
  39. package/dist/react-text-annotator.es21.js +117 -0
  40. package/dist/react-text-annotator.es21.js.map +1 -0
  41. package/dist/{react-text-annotator.es15.js → react-text-annotator.es22.js} +1 -1
  42. package/dist/{react-text-annotator.es15.js.map → react-text-annotator.es22.js.map} +1 -1
  43. package/dist/react-text-annotator.es23.js +61 -0
  44. package/dist/react-text-annotator.es23.js.map +1 -0
  45. package/dist/react-text-annotator.es24.js +23 -0
  46. package/dist/react-text-annotator.es24.js.map +1 -0
  47. package/dist/react-text-annotator.es25.js +5 -0
  48. package/dist/react-text-annotator.es25.js.map +1 -0
  49. package/dist/react-text-annotator.es26.js +5 -0
  50. package/dist/react-text-annotator.es26.js.map +1 -0
  51. package/dist/react-text-annotator.es27.js +130 -0
  52. package/dist/react-text-annotator.es27.js.map +1 -0
  53. package/dist/react-text-annotator.es28.js +155 -0
  54. package/dist/react-text-annotator.es28.js.map +1 -0
  55. package/dist/react-text-annotator.es29.js +314 -0
  56. package/dist/react-text-annotator.es29.js.map +1 -0
  57. package/dist/react-text-annotator.es3.js +2 -2
  58. package/dist/react-text-annotator.es30.js +152 -0
  59. package/dist/react-text-annotator.es30.js.map +1 -0
  60. package/dist/react-text-annotator.es31.js +563 -0
  61. package/dist/react-text-annotator.es31.js.map +1 -0
  62. package/dist/react-text-annotator.es4.js +29 -27
  63. package/dist/react-text-annotator.es4.js.map +1 -1
  64. package/dist/react-text-annotator.es5.js +38 -48
  65. package/dist/react-text-annotator.es5.js.map +1 -1
  66. package/dist/react-text-annotator.es6.js +25 -10
  67. package/dist/react-text-annotator.es6.js.map +1 -1
  68. package/dist/react-text-annotator.es7.js +134 -1
  69. package/dist/react-text-annotator.es7.js.map +1 -1
  70. package/dist/react-text-annotator.es8.js +177 -486
  71. package/dist/react-text-annotator.es8.js.map +1 -1
  72. package/dist/react-text-annotator.es9.js +10 -2
  73. package/dist/react-text-annotator.es9.js.map +1 -1
  74. package/dist/tei/TEIAnnotator.d.ts +2 -2
  75. package/package.json +23 -15
  76. package/dist/TextAnnotatorPopup.d.ts +0 -14
  77. package/dist/TextAnnotatorPopup.d.ts.map +0 -1
@@ -1,491 +1,182 @@
1
- import defaultBehaviors from "./react-text-annotator.es14.js";
2
- import * as utilities from "./react-text-annotator.es15.js";
3
- import { hideContent, defineCustomElement, tagName } from "./react-text-annotator.es15.js";
4
- import { addBehaviors, addBehavior, removeBehavior } from "./react-text-annotator.es16.js";
5
- import { learnElementNames, learnCustomElementNames } from "./react-text-annotator.es17.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
- }
54
- }
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
- }
76
- }
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
- }
176
- }
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;
188
- }
189
- }
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
- }
209
- }
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);
221
- }
222
- }
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
- }
264
- }
265
- appendBasic(elt, content) {
266
- if (this.discardContent) {
267
- elt.innerHTML = "";
268
- } else {
269
- hideContent(elt, true);
270
- }
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;
284
- } else {
285
- return elt && elt.nextElementSibling && this.childExists(elt.nextElementSibling, name);
286
- }
287
- }
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
- };
301
- }
302
- if (Array.isArray(template) && !Array.isArray(template[0])) {
303
- return this.applyDecorator(template);
304
- }
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
- }
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
- };
327
- }
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
- }
340
- }
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]));
351
- }
352
- }
353
- }
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
- }
360
- }
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
- }
373
- }
374
- if (content.childNodes.length < 2) {
375
- return content.firstChild;
376
- } else {
377
- return content;
378
- }
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
- }
388
- }
389
- for (let node of Array.from(elt.childNodes)) {
390
- if (node.nodeType === 1) {
391
- this.processElement(node);
392
- }
393
- }
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
- }
407
- } else {
408
- result = result.replace(replacements[0], "");
409
- }
410
- }
411
- }
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);
420
- }
421
- }
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
- }
432
- }
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
- }
451
- }
452
- }
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);
475
- }
476
- }
1
+ const Yt = "not-annotatable", D = `.${Yt}`, pt = (t) => {
2
+ const e = t.cloneContents();
3
+ return e.querySelectorAll(D).forEach((n) => n.remove()), e;
4
+ }, oe = (t, e, n = 10, o) => {
5
+ const r = e, i = document.createRange();
6
+ i.setStart(r, 0), i.setEnd(t.startContainer, t.startOffset);
7
+ const s = pt(i).textContent, a = document.createRange();
8
+ a.setStart(t.endContainer, t.endOffset), r === document.body ? a.setEnd(r, r.childNodes.length) : a.setEndAfter(r);
9
+ const u = pt(a).textContent;
10
+ return {
11
+ prefix: s.substring(s.length - n),
12
+ suffix: u.substring(0, n)
13
+ };
14
+ };
15
+ var U = [];
16
+ for (var lt = 0; lt < 256; ++lt)
17
+ U.push((lt + 256).toString(16).slice(1));
18
+ function Re(t, e = 0) {
19
+ return (U[t[e + 0]] + U[t[e + 1]] + U[t[e + 2]] + U[t[e + 3]] + "-" + U[t[e + 4]] + U[t[e + 5]] + "-" + U[t[e + 6]] + U[t[e + 7]] + "-" + U[t[e + 8]] + U[t[e + 9]] + "-" + U[t[e + 10]] + U[t[e + 11]] + U[t[e + 12]] + U[t[e + 13]] + U[t[e + 14]] + U[t[e + 15]]).toLowerCase();
477
20
  }
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);
21
+ var Z, Ne = new Uint8Array(16);
22
+ function Me() {
23
+ if (!Z && (Z = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Z))
24
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
25
+ return Z(Ne);
26
+ }
27
+ var Oe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
28
+ const Mt = {
29
+ randomUUID: Oe
30
+ };
31
+ function Ht(t, e, n) {
32
+ if (Mt.randomUUID && !e && !t)
33
+ return Mt.randomUUID();
34
+ t = t || {};
35
+ var o = t.random || (t.rng || Me)();
36
+ return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Re(o);
487
37
  }
38
+ var V = [];
39
+ for (var ht = 0; ht < 256; ++ht)
40
+ V.push((ht + 256).toString(16).slice(1));
41
+ typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
42
+ const on = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
43
+ let cn = (t = 21) => {
44
+ let e = "", n = crypto.getRandomValues(new Uint8Array(t));
45
+ for (; t--; )
46
+ e += on[n[t] & 63];
47
+ return e;
48
+ };
49
+ const dn = (t) => {
50
+ const e = JSON.stringify(t);
51
+ let n = 0;
52
+ for (let o = 0, r = e.length; o < r; o++) {
53
+ let i = e.charCodeAt(o);
54
+ n = (n << 5) - n + i, n |= 0;
55
+ }
56
+ return `${n}`;
57
+ }, Ft = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, un = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
58
+ const { id: o, type: r, purpose: i, value: s, created: a, modified: u, creator: f, ...g } = n;
59
+ return {
60
+ id: o || `temp-${dn(n)}`,
61
+ annotation: e,
62
+ type: r,
63
+ purpose: i,
64
+ value: s,
65
+ creator: Ft(f),
66
+ created: a ? new Date(a) : void 0,
67
+ updated: u ? new Date(u) : void 0,
68
+ ...g
69
+ };
70
+ }), hn = (t) => t.map((e) => {
71
+ var n;
72
+ const { annotation: o, created: r, updated: i, ...s } = e, a = {
73
+ ...s,
74
+ created: r == null ? void 0 : r.toISOString(),
75
+ modified: i == null ? void 0 : i.toISOString()
76
+ };
77
+ return (n = a.id) != null && n.startsWith("temp-") && delete a.id, a;
78
+ });
79
+ cn();
80
+ const Vn = (t, e) => ({
81
+ parse: (n) => pn(n),
82
+ serialize: (n) => mn(n, t, e)
83
+ }), fn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, gn = (t) => {
84
+ const {
85
+ id: e,
86
+ creator: n,
87
+ created: o,
88
+ modified: r,
89
+ target: i
90
+ } = t, s = Array.isArray(i) ? i : [i], a = {
91
+ creator: Ft(n),
92
+ created: o ? new Date(o) : void 0,
93
+ updated: r ? new Date(r) : void 0,
94
+ annotation: e,
95
+ selector: []
96
+ };
97
+ for (const u of s) {
98
+ const g = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((d, m) => {
99
+ switch (m.type) {
100
+ case "TextQuoteSelector":
101
+ d.quote = m.exact;
102
+ break;
103
+ case "TextPositionSelector":
104
+ d.start = m.start, d.end = m.end;
105
+ break;
106
+ }
107
+ return d;
108
+ }, {});
109
+ if (fn(g))
110
+ a.selector.push({ id: u.id, ...g });
111
+ else {
112
+ const d = [
113
+ g.start ? void 0 : "TextPositionSelector",
114
+ g.quote ? void 0 : "TextQuoteSelector"
115
+ ].filter(Boolean);
116
+ return { error: Error(`Missing selector types: ${d.join(" and ")} for annotation: ${t.id}`) };
117
+ }
118
+ }
119
+ return { parsed: a };
120
+ }, pn = (t) => {
121
+ const e = t.id || Ht(), {
122
+ creator: n,
123
+ created: o,
124
+ modified: r,
125
+ body: i,
126
+ ...s
127
+ } = t, a = un(i, e), u = gn(t);
128
+ return "error" in u ? { error: u.error } : {
129
+ parsed: {
130
+ ...s,
131
+ id: e,
132
+ bodies: a,
133
+ target: u.parsed
134
+ }
135
+ };
136
+ }, mn = (t, e, n) => {
137
+ const { bodies: o, target: r, ...i } = t, {
138
+ selector: s,
139
+ creator: a,
140
+ created: u,
141
+ updated: f,
142
+ ...g
143
+ } = r, d = s.map((m) => {
144
+ const { quote: h, start: w, end: y, range: p } = m, { prefix: l, suffix: c } = oe(p, n), b = [{
145
+ type: "TextQuoteSelector",
146
+ exact: h,
147
+ prefix: l,
148
+ suffix: c
149
+ }, {
150
+ type: "TextPositionSelector",
151
+ start: w,
152
+ end: y
153
+ }];
154
+ return {
155
+ ...g,
156
+ id: m.id,
157
+ source: e,
158
+ selector: b
159
+ };
160
+ });
161
+ return {
162
+ ...i,
163
+ "@context": "http://www.w3.org/ns/anno.jsonld",
164
+ id: t.id,
165
+ type: "Annotation",
166
+ body: hn(t.bodies),
167
+ creator: a,
168
+ created: u == null ? void 0 : u.toISOString(),
169
+ modified: f == null ? void 0 : f.toISOString(),
170
+ target: d
171
+ };
172
+ };
488
173
  export {
489
- CETEI as default
174
+ Yt as NOT_ANNOTATABLE_CLASS,
175
+ D as NOT_ANNOTATABLE_SELECTOR,
176
+ Vn as W3CTextFormat,
177
+ oe as getQuoteContext,
178
+ pt as getRangeAnnotatableContents,
179
+ pn as parseW3CTextAnnotation,
180
+ mn as serializeW3CTextAnnotation
490
181
  };
491
182
  //# sourceMappingURL=react-text-annotator.es8.js.map