@soomo/react-text-annotator 3.0.0-staging.53 → 3.0.0-staging.55

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.
@@ -1,48 +1,67 @@
1
- function* range(minimum, maximum) {
2
- for (let number = minimum; number <= maximum; number++) {
3
- yield number;
4
- }
5
- }
6
- function randomInteger(minimum, maximum) {
7
- return Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
1
+ const $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY = 7e3;
2
+ let $319e236875307eab$var$liveAnnouncer = null;
3
+ function $319e236875307eab$export$a9b970dcc4ae71a9(message, assertiveness = "assertive", timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {
4
+ if (!$319e236875307eab$var$liveAnnouncer) $319e236875307eab$var$liveAnnouncer = new $319e236875307eab$var$LiveAnnouncer();
5
+ $319e236875307eab$var$liveAnnouncer.announce(message, assertiveness, timeout);
8
6
  }
9
- function randomIntegerWithout(minimum, maximum, excludedValue) {
10
- const number = randomInteger(minimum, maximum - 1);
11
- return number >= excludedValue ? number + 1 : number;
12
- }
13
- function makeCallable(generator) {
14
- const iterator = generator();
15
- function random() {
16
- return iterator.next().value;
7
+ function $319e236875307eab$export$d8686216b8b81b2f() {
8
+ if ($319e236875307eab$var$liveAnnouncer) {
9
+ $319e236875307eab$var$liveAnnouncer.destroy();
10
+ $319e236875307eab$var$liveAnnouncer = null;
17
11
  }
18
- random[Symbol.iterator] = function* () {
19
- while (true) {
20
- yield random();
21
- }
22
- };
23
- return random;
24
12
  }
25
- function exhaustiveUniqueRandom(minimum, maximum) {
26
- return makeCallable(function* () {
27
- let unconsumedValues = [...range(minimum, maximum)];
28
- while (true) {
29
- while (unconsumedValues.length > 1) {
30
- yield unconsumedValues.splice(
31
- randomInteger(0, unconsumedValues.length - 1),
32
- 1
33
- )[0];
34
- }
35
- const [previousValue] = unconsumedValues;
36
- yield previousValue;
37
- unconsumedValues = [...range(minimum, maximum)];
38
- yield unconsumedValues.splice(
39
- randomIntegerWithout(0, unconsumedValues.length - 1, previousValue - minimum),
40
- 1
41
- )[0];
42
- }
43
- });
13
+ class $319e236875307eab$var$LiveAnnouncer {
14
+ createLog(ariaLive) {
15
+ let node = document.createElement("div");
16
+ node.setAttribute("role", "log");
17
+ node.setAttribute("aria-live", ariaLive);
18
+ node.setAttribute("aria-relevant", "additions");
19
+ return node;
20
+ }
21
+ destroy() {
22
+ if (!this.node) return;
23
+ document.body.removeChild(this.node);
24
+ this.node = null;
25
+ }
26
+ announce(message, assertiveness = "assertive", timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {
27
+ if (!this.node) return;
28
+ let node = document.createElement("div");
29
+ node.textContent = message;
30
+ if (assertiveness === "assertive") this.assertiveLog.appendChild(node);
31
+ else this.politeLog.appendChild(node);
32
+ if (message !== "") setTimeout(() => {
33
+ node.remove();
34
+ }, timeout);
35
+ }
36
+ clear(assertiveness) {
37
+ if (!this.node) return;
38
+ if (!assertiveness || assertiveness === "assertive") this.assertiveLog.innerHTML = "";
39
+ if (!assertiveness || assertiveness === "polite") this.politeLog.innerHTML = "";
40
+ }
41
+ constructor() {
42
+ this.node = document.createElement("div");
43
+ this.node.dataset.liveAnnouncer = "true";
44
+ Object.assign(this.node.style, {
45
+ border: 0,
46
+ clip: "rect(0 0 0 0)",
47
+ clipPath: "inset(50%)",
48
+ height: "1px",
49
+ margin: "-1px",
50
+ overflow: "hidden",
51
+ padding: 0,
52
+ position: "absolute",
53
+ width: "1px",
54
+ whiteSpace: "nowrap"
55
+ });
56
+ this.assertiveLog = this.createLog("assertive");
57
+ this.node.appendChild(this.assertiveLog);
58
+ this.politeLog = this.createLog("polite");
59
+ this.node.appendChild(this.politeLog);
60
+ document.body.prepend(this.node);
61
+ }
44
62
  }
45
63
  export {
46
- exhaustiveUniqueRandom
64
+ $319e236875307eab$export$a9b970dcc4ae71a9 as announce,
65
+ $319e236875307eab$export$d8686216b8b81b2f as destroyAnnouncer
47
66
  };
48
67
  //# sourceMappingURL=react-text-annotator.es11.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-text-annotator.es11.js","sources":["../../../node_modules/unique-random/index.js"],"sourcesContent":["function * range(minimum, maximum) {\n\tfor (let number = minimum; number <= maximum; number++) {\n\t\tyield number;\n\t}\n}\n\nfunction randomInteger(minimum, maximum) {\n\treturn Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;\n}\n\nfunction randomIntegerWithout(minimum, maximum, excludedValue) {\n\tconst number = randomInteger(minimum, maximum - 1);\n\n\treturn number >= excludedValue ? number + 1 : number;\n}\n\nfunction makeCallable(generator) {\n\tconst iterator = generator();\n\n\tfunction random() {\n\t\treturn iterator.next().value;\n\t}\n\n\trandom[Symbol.iterator] = function * () {\n\t\twhile (true) {\n\t\t\tyield random();\n\t\t}\n\t};\n\n\treturn random;\n}\n\nexport function consecutiveUniqueRandom(minimum, maximum) {\n\treturn makeCallable(function * () {\n\t\tif (minimum === maximum) {\n\t\t\twhile (true) {\n\t\t\t\tyield minimum;\n\t\t\t}\n\t\t}\n\n\t\tlet previousValue = randomInteger(minimum, maximum);\n\t\tyield previousValue;\n\n\t\twhile (true) {\n\t\t\tpreviousValue = randomIntegerWithout(minimum, maximum, previousValue);\n\t\t\tyield previousValue;\n\t\t}\n\t});\n}\n\nexport function exhaustiveUniqueRandom(minimum, maximum) {\n\treturn makeCallable(function * () {\n\t\tif (minimum === maximum) {\n\t\t\twhile (true) {\n\t\t\t\tyield minimum;\n\t\t\t}\n\t\t}\n\n\t\tlet unconsumedValues = [...range(minimum, maximum)];\n\n\t\twhile (true) {\n\t\t\twhile (unconsumedValues.length > 1) {\n\t\t\t\tyield unconsumedValues.splice(\n\t\t\t\t\trandomInteger(0, unconsumedValues.length - 1),\n\t\t\t\t\t1,\n\t\t\t\t)[0];\n\t\t\t}\n\n\t\t\tconst [previousValue] = unconsumedValues;\n\n\t\t\tyield previousValue;\n\n\t\t\tunconsumedValues = [...range(minimum, maximum)];\n\n\t\t\tyield unconsumedValues.splice(\n\t\t\t\trandomIntegerWithout(0, unconsumedValues.length - 1, previousValue - minimum),\n\t\t\t\t1,\n\t\t\t)[0];\n\t\t}\n\t});\n}\n"],"names":[],"mappings":"AAAA,UAAW,MAAM,SAAS,SAAS;AAClC,WAAS,SAAS,SAAS,UAAU,SAAS,UAAU;AACvD,UAAM;AAAA,EACN;AACF;AAEA,SAAS,cAAc,SAAS,SAAS;AACxC,SAAO,KAAK,MAAM,KAAK,OAAM,KAAM,UAAU,UAAU,EAAE,IAAI;AAC9D;AAEA,SAAS,qBAAqB,SAAS,SAAS,eAAe;AAC9D,QAAM,SAAS,cAAc,SAAS,UAAU,CAAC;AAEjD,SAAO,UAAU,gBAAgB,SAAS,IAAI;AAC/C;AAEA,SAAS,aAAa,WAAW;AAChC,QAAM,WAAW;AAEjB,WAAS,SAAS;AACjB,WAAO,SAAS,KAAM,EAAC;AAAA,EACvB;AAED,SAAO,OAAO,QAAQ,IAAI,aAAc;AACvC,WAAO,MAAM;AACZ,YAAM,OAAM;AAAA,IACZ;AAAA,EACH;AAEC,SAAO;AACR;AAoBO,SAAS,uBAAuB,SAAS,SAAS;AACxD,SAAO,aAAa,aAAc;AAOjC,QAAI,mBAAmB,CAAC,GAAG,MAAM,SAAS,OAAO,CAAC;AAElD,WAAO,MAAM;AACZ,aAAO,iBAAiB,SAAS,GAAG;AACnC,cAAM,iBAAiB;AAAA,UACtB,cAAc,GAAG,iBAAiB,SAAS,CAAC;AAAA,UAC5C;AAAA,QACA,EAAC,CAAC;AAAA,MACH;AAED,YAAM,CAAC,aAAa,IAAI;AAExB,YAAM;AAEN,yBAAmB,CAAC,GAAG,MAAM,SAAS,OAAO,CAAC;AAE9C,YAAM,iBAAiB;AAAA,QACtB,qBAAqB,GAAG,iBAAiB,SAAS,GAAG,gBAAgB,OAAO;AAAA,QAC5E;AAAA,MACA,EAAC,CAAC;AAAA,IACH;AAAA,EACH,CAAE;AACF;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"react-text-annotator.es11.js","sources":["../../../node_modules/@react-aria/live-announcer/dist/LiveAnnouncer.mjs"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */ /* Inspired by https://github.com/AlmeroSteyn/react-aria-live */ const $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY = 7000;\nlet $319e236875307eab$var$liveAnnouncer = null;\nfunction $319e236875307eab$export$a9b970dcc4ae71a9(message, assertiveness = 'assertive', timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {\n if (!$319e236875307eab$var$liveAnnouncer) $319e236875307eab$var$liveAnnouncer = new $319e236875307eab$var$LiveAnnouncer();\n $319e236875307eab$var$liveAnnouncer.announce(message, assertiveness, timeout);\n}\nfunction $319e236875307eab$export$d10ae4f68404609a(assertiveness) {\n if ($319e236875307eab$var$liveAnnouncer) $319e236875307eab$var$liveAnnouncer.clear(assertiveness);\n}\nfunction $319e236875307eab$export$d8686216b8b81b2f() {\n if ($319e236875307eab$var$liveAnnouncer) {\n $319e236875307eab$var$liveAnnouncer.destroy();\n $319e236875307eab$var$liveAnnouncer = null;\n }\n}\n// LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18\n// ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a\n// subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.\n// As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer\n// is simple enough to implement without React, so that's what we do here.\n// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638\nclass $319e236875307eab$var$LiveAnnouncer {\n createLog(ariaLive) {\n let node = document.createElement('div');\n node.setAttribute('role', 'log');\n node.setAttribute('aria-live', ariaLive);\n node.setAttribute('aria-relevant', 'additions');\n return node;\n }\n destroy() {\n if (!this.node) return;\n document.body.removeChild(this.node);\n this.node = null;\n }\n announce(message, assertiveness = 'assertive', timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {\n if (!this.node) return;\n let node = document.createElement('div');\n node.textContent = message;\n if (assertiveness === 'assertive') this.assertiveLog.appendChild(node);\n else this.politeLog.appendChild(node);\n if (message !== '') setTimeout(()=>{\n node.remove();\n }, timeout);\n }\n clear(assertiveness) {\n if (!this.node) return;\n if (!assertiveness || assertiveness === 'assertive') this.assertiveLog.innerHTML = '';\n if (!assertiveness || assertiveness === 'polite') this.politeLog.innerHTML = '';\n }\n constructor(){\n this.node = document.createElement('div');\n this.node.dataset.liveAnnouncer = 'true';\n // copied from VisuallyHidden\n Object.assign(this.node.style, {\n border: 0,\n clip: 'rect(0 0 0 0)',\n clipPath: 'inset(50%)',\n height: '1px',\n margin: '-1px',\n overflow: 'hidden',\n padding: 0,\n position: 'absolute',\n width: '1px',\n whiteSpace: 'nowrap'\n });\n this.assertiveLog = this.createLog('assertive');\n this.node.appendChild(this.assertiveLog);\n this.politeLog = this.createLog('polite');\n this.node.appendChild(this.politeLog);\n document.body.prepend(this.node);\n }\n}\n\n\nexport {$319e236875307eab$export$a9b970dcc4ae71a9 as announce, $319e236875307eab$export$d10ae4f68404609a as clearAnnouncer, $319e236875307eab$export$d8686216b8b81b2f as destroyAnnouncer};\n//# sourceMappingURL=LiveAnnouncer.module.js.map\n"],"names":[],"mappings":"AAUqE,MAAM,iDAAiD;AAC5H,IAAI,sCAAsC;AAC1C,SAAS,0CAA0C,SAAS,gBAAgB,aAAa,UAAU,gDAAgD;AAC/I,MAAI,CAAC,oCAAqC,uCAAsC,IAAI,oCAAmC;AACvH,sCAAoC,SAAS,SAAS,eAAe,OAAO;AAChF;AAIA,SAAS,4CAA4C;AACjD,MAAI,qCAAqC;AACrC,wCAAoC,QAAO;AAC3C,0CAAsC;AAAA,EACzC;AACL;AAOA,MAAM,oCAAoC;AAAA,EACtC,UAAU,UAAU;AAChB,QAAI,OAAO,SAAS,cAAc,KAAK;AACvC,SAAK,aAAa,QAAQ,KAAK;AAC/B,SAAK,aAAa,aAAa,QAAQ;AACvC,SAAK,aAAa,iBAAiB,WAAW;AAC9C,WAAO;AAAA,EACV;AAAA,EACD,UAAU;AACN,QAAI,CAAC,KAAK,KAAM;AAChB,aAAS,KAAK,YAAY,KAAK,IAAI;AACnC,SAAK,OAAO;AAAA,EACf;AAAA,EACD,SAAS,SAAS,gBAAgB,aAAa,UAAU,gDAAgD;AACrG,QAAI,CAAC,KAAK,KAAM;AAChB,QAAI,OAAO,SAAS,cAAc,KAAK;AACvC,SAAK,cAAc;AACnB,QAAI,kBAAkB,YAAa,MAAK,aAAa,YAAY,IAAI;AAAA,QAChE,MAAK,UAAU,YAAY,IAAI;AACpC,QAAI,YAAY,GAAI,YAAW,MAAI;AAC/B,WAAK,OAAM;AAAA,IACd,GAAE,OAAO;AAAA,EACb;AAAA,EACD,MAAM,eAAe;AACjB,QAAI,CAAC,KAAK,KAAM;AAChB,QAAI,CAAC,iBAAiB,kBAAkB,YAAa,MAAK,aAAa,YAAY;AACnF,QAAI,CAAC,iBAAiB,kBAAkB,SAAU,MAAK,UAAU,YAAY;AAAA,EAChF;AAAA,EACD,cAAa;AACT,SAAK,OAAO,SAAS,cAAc,KAAK;AACxC,SAAK,KAAK,QAAQ,gBAAgB;AAElC,WAAO,OAAO,KAAK,KAAK,OAAO;AAAA,MAC3B,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,UAAU;AAAA,MACV,SAAS;AAAA,MACT,UAAU;AAAA,MACV,OAAO;AAAA,MACP,YAAY;AAAA,IACxB,CAAS;AACD,SAAK,eAAe,KAAK,UAAU,WAAW;AAC9C,SAAK,KAAK,YAAY,KAAK,YAAY;AACvC,SAAK,YAAY,KAAK,UAAU,QAAQ;AACxC,SAAK,KAAK,YAAY,KAAK,SAAS;AACpC,aAAS,KAAK,QAAQ,KAAK,IAAI;AAAA,EAClC;AACL;","x_google_ignoreList":[0]}
@@ -1,490 +1,48 @@
1
- import defaultBehaviors from "./react-text-annotator.es22.js";
2
- import * as utilities from "./react-text-annotator.es23.js";
3
- import { hideContent, defineCustomElement, tagName } from "./react-text-annotator.es23.js";
4
- import { addBehaviors, addBehavior, removeBehavior } from "./react-text-annotator.es24.js";
5
- import { learnElementNames, learnCustomElementNames } from "./react-text-annotator.es25.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") return "http://www.tei-c.org/ns/1.0";
121
- }, 1, null);
122
- newElement.setAttribute("data-level", level.numberValue);
123
- }
124
- if (el.localName == "tagsDecl") {
125
- let style = this.document.createElement("style");
126
- for (let node of Array.from(el.childNodes)) {
127
- if (node.nodeType == 1 && node.localName == "rendition" && node.getAttribute("scheme") == "css") {
128
- let rule = "";
129
- if (node.hasAttribute("selector")) {
130
- rule += node.getAttribute("selector").replace(/([^#, >]+\w*)/g, "tei-$1").replace(/#tei-/g, "#") + "{\n";
131
- rule += node.textContent;
132
- } else {
133
- rule += "." + node.getAttribute("xml:id") + "{\n";
134
- rule += node.textContent;
135
- }
136
- rule += "\n}\n";
137
- style.appendChild(this.document.createTextNode(rule));
138
- }
139
- }
140
- if (style.childNodes.length > 0) {
141
- newElement.appendChild(style);
142
- this.hasStyle = true;
143
- }
144
- }
145
- if (el.localName == "prefixDef") {
146
- this.prefixDefs.push(el.getAttribute("ident"));
147
- this.prefixDefs[el.getAttribute("ident")] = {
148
- "matchPattern": el.getAttribute("matchPattern"),
149
- "replacementPattern": el.getAttribute("replacementPattern")
150
- };
151
- }
152
- for (let node of Array.from(el.childNodes)) {
153
- if (node.nodeType == 1) {
154
- newElement.appendChild(convertEl(node));
155
- } else {
156
- newElement.appendChild(node.cloneNode());
157
- }
158
- }
159
- if (perElementFn) {
160
- perElementFn(newElement, el);
161
- }
162
- return newElement;
163
- };
164
- this.dom = this.document.createDocumentFragment();
165
- for (let node of Array.from(XML_dom.childNodes)) {
166
- if (node.nodeType == 1) {
167
- this.dom.appendChild(convertEl(node));
168
- }
169
- if (node.nodeType == 7) {
170
- this.dom.appendChild(this.document.importNode(node, true));
171
- }
172
- if (node.nodeType == 8) {
173
- this.dom.appendChild(this.document.importNode(node, true));
174
- }
175
- }
176
- this.utilities.dom = this.dom.firstElementChild;
177
- if (callback) {
178
- callback(this.dom, this);
179
- if (window) {
180
- window.dispatchEvent(ceteiceanLoad);
181
- }
182
- } else {
183
- if (typeof window !== "undefined") {
184
- window.dispatchEvent(ceteiceanLoad);
185
- }
186
- return this.dom;
187
- }
188
- }
189
- /*
190
- Converts the supplied XML DOM into HTML5 Custom Elements. If a callback
191
- function is supplied, calls it on the result.
192
- */
193
- domToHTML5(XML_dom, callback, perElementFn) {
194
- this.preprocess(XML_dom, null, perElementFn);
195
- this.applyBehaviors();
196
- this.done = true;
197
- if (callback) {
198
- callback(this.dom, this);
199
- if (window) {
200
- window.dispatchEvent(ceteiceanLoad);
201
- }
202
- } else {
203
- if (typeof window !== "undefined") {
204
- window.dispatchEvent(ceteiceanLoad);
205
- }
206
- return this.dom;
207
- }
208
- }
209
- /*
210
- Convenience method for HTML pages containing pre-processed CETEIcean Custom
211
- Elements. Usage:
212
- const c = new CETEI();
213
- c.processPage();
214
- */
215
- processPage() {
216
- this.els = learnCustomElementNames(this.document);
217
- this.applyBehaviors();
218
- if (window) {
219
- window.dispatchEvent(ceteiceanLoad);
220
- }
221
- }
222
- /*
223
- To change a namespace -> prefix mapping, the namespace must first be
224
- unset. Takes a namespace URI. In order to process a TEI P4 document, e.g.,
225
- the TEI namespace must be unset before it can be set to the empty string.
226
- */
227
- unsetNamespace(ns) {
228
- this.namespaces.delete(ns);
229
- }
230
- /*
231
- Sets the base URL for the document. Used to rewrite relative links in the
232
- XML source (which may be in a completely different location from the HTML
233
- wrapper).
234
- */
235
- setBaseUrl(base) {
236
- this.base = base;
237
- }
238
- /*
239
- Appends any element returned by the function passed in the first
240
- parameter to the element in the second parameter. If the function
241
- returns nothing, this is a no-op aside from any side effects caused
242
- by the provided function.
243
-
244
- Called by getHandler() and fallback()
245
- */
246
- append(fn, elt) {
247
- let self = this;
248
- if (elt && !elt.hasAttribute("data-processed")) {
249
- let content = fn.call(self.utilities, elt);
250
- if (content) {
251
- self.appendBasic(elt, content);
252
- }
253
- } else {
254
- return function() {
255
- if (!this.hasAttribute("data-processed")) {
256
- let content = fn.call(self.utilities, this);
257
- if (content) {
258
- self.appendBasic(this, content);
259
- }
260
- }
261
- };
262
- }
263
- }
264
- appendBasic(elt, content) {
265
- if (this.discardContent) {
266
- elt.innerHTML = "";
267
- } else {
268
- hideContent(elt, true);
269
- }
270
- elt.appendChild(content);
1
+ function* range(minimum, maximum) {
2
+ for (let number = minimum; number <= maximum; number++) {
3
+ yield number;
271
4
  }
272
- // Given an element, return its qualified name as defined in a behaviors object
273
- bName(e) {
274
- return e.tagName.substring(0, e.tagName.indexOf("-")).toLowerCase() + ":" + e.getAttribute("data-origname");
275
- }
276
- /*
277
- Private method called by append(). Takes a child element and a name, and recurses through the
278
- child's siblings until an element with that name is found, returning true if it is and false if not.
279
- */
280
- childExists(elt, name) {
281
- if (elt && elt.nodeName == name) {
282
- return true;
283
- } else {
284
- return elt && elt.nextElementSibling && this.childExists(elt.nextElementSibling, name);
285
- }
286
- }
287
- /*
288
- Takes a template in the form of either an array of 1 or 2
289
- strings or an object with CSS selector keys and either functions
290
- or arrays as described above. Returns a closure around a function
291
- that can be called in the element constructor or applied to an
292
- individual element. An empty array is considered a no-op.
293
-
294
- Called by the getHandler() and getFallback() methods
295
- */
296
- decorator(template) {
297
- if (Array.isArray(template) && template.length == 0) {
298
- return function(e) {
299
- };
300
- }
301
- if (Array.isArray(template) && !Array.isArray(template[0])) {
302
- return this.applyDecorator(template);
303
- }
304
- let self = this;
305
- return function(elt) {
306
- for (let rule of template) {
307
- if (elt.matches(rule[0]) || rule[0] === "_") {
308
- if (Array.isArray(rule[1])) {
309
- return self.decorator(rule[1]).call(this, elt);
310
- } else {
311
- return rule[1].call(this, elt);
312
- }
313
- }
314
- }
315
- };
316
- }
317
- applyDecorator(strings) {
318
- let self = this;
319
- return function(elt) {
320
- let copy = [];
321
- for (let i = 0; i < strings.length; i++) {
322
- copy.push(self.template(strings[i], elt));
323
- }
324
- return self.insert(elt, copy);
325
- };
326
- }
327
- /*
328
- Returns the fallback function for the given element name.
329
- Called by fallback().
330
- */
331
- getFallback(behaviors, fn) {
332
- if (behaviors[fn]) {
333
- if (behaviors[fn] instanceof Function) {
334
- return behaviors[fn];
335
- } else {
336
- return this.decorator(behaviors[fn]);
337
- }
338
- }
339
- }
340
- /*
341
- Returns the handler function for the given element name
342
- Called by define().
343
- */
344
- getHandler(behaviors, fn) {
345
- if (behaviors[fn]) {
346
- if (behaviors[fn] instanceof Function) {
347
- return this.append(behaviors[fn]);
348
- } else {
349
- return this.append(this.decorator(behaviors[fn]));
350
- }
351
- }
352
- }
353
- insert(elt, strings) {
354
- let content = this.document.createElement("cetei-content");
355
- for (let node of Array.from(elt.childNodes)) {
356
- if (node.nodeType === 1 && !node.hasAttribute("data-processed")) {
357
- this.processElement(node);
358
- }
359
- }
360
- if (strings[0].match("<[^>]+>") && strings[1] && strings[1].match("<[^>]+>")) {
361
- content.innerHTML = strings[0] + elt.innerHTML + (strings[1] ? strings[1] : "");
362
- } else {
363
- content.innerHTML = strings[0];
364
- content.setAttribute("data-before", strings[0].replace(/<[^>]+>/g, "").length);
365
- for (let node of Array.from(elt.childNodes)) {
366
- content.appendChild(node.cloneNode(true));
367
- }
368
- if (strings.length > 1) {
369
- content.innerHTML += strings[1];
370
- content.setAttribute("data-after", strings[1].replace(/<[^>]+>/g, "").length);
371
- }
372
- }
373
- if (content.childNodes.length < 2) {
374
- return content.firstChild;
375
- } else {
376
- return content;
377
- }
378
- }
379
- // Runs behaviors recursively on the supplied element and children
380
- processElement(elt) {
381
- if (elt.hasAttribute("data-origname") && !elt.hasAttribute("data-processed")) {
382
- let fn = this.getFallback(this.bName(elt));
383
- if (fn) {
384
- this.append(fn, elt);
385
- elt.setAttribute("data-processed", "");
386
- }
387
- }
388
- for (let node of Array.from(elt.childNodes)) {
389
- if (node.nodeType === 1) {
390
- this.processElement(node);
391
- }
392
- }
393
- }
394
- template(str, elt) {
395
- let result = str;
396
- if (str.search(/\$(\w*)(@([a-zA-Z:]+))/)) {
397
- let re = /\$(\w*)@([a-zA-Z:]+)/g;
398
- let replacements;
399
- while (replacements = re.exec(str)) {
400
- if (elt.hasAttribute(replacements[2])) {
401
- if (replacements[1] && this.utilities[replacements[1]]) {
402
- result = result.replace(replacements[0], this.utilities[replacements[1]](elt.getAttribute(replacements[2])));
403
- } else {
404
- result = result.replace(replacements[0], elt.getAttribute(replacements[2]));
405
- }
406
- } else {
407
- result = result.replace(replacements[0], "");
408
- }
409
- }
410
- }
411
- return result;
412
- }
413
- // Define or apply behaviors for the document
414
- applyBehaviors() {
415
- if (typeof window !== "undefined" && window.customElements) {
416
- this.define.call(this, this.els);
417
- } else {
418
- this.fallback.call(this, this.els);
419
- }
420
- }
421
- /*
422
- Registers the list of elements provided with the browser.
423
- Called by makeHTML5(), but can be called independently if, for example,
424
- you've created Custom Elements via an XSLT transformation instead.
425
- */
426
- define(names) {
427
- for (let name of names) {
428
- const fn = this.getHandler(this.behaviors, name);
429
- defineCustomElement(name, fn, this.debug);
430
- }
431
- }
432
- /*
433
- Provides fallback functionality for environments where Custom Elements
434
- are not supported.
435
-
436
- Like define(), this is called by makeHTML5(), but can be called
437
- independently.
438
- */
439
- fallback(names) {
440
- for (let name of names) {
441
- let fn = this.getFallback(this.behaviors, name);
442
- if (fn) {
443
- for (let elt of Array.from((this.dom && !this.done ? this.dom : this.document).querySelectorAll(tagName(name)))) {
444
- if (!elt.hasAttribute("data-processed")) {
445
- this.append(fn, elt);
446
- elt.setAttribute("data-processed", "");
447
- }
448
- }
449
- }
450
- }
451
- }
452
- /**********************
453
- * Utility functions *
454
- **********************/
455
- static savePosition() {
456
- window.sessionStorage.setItem(window.location + "-scroll", window.scrollY);
5
+ }
6
+ function randomInteger(minimum, maximum) {
7
+ return Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
8
+ }
9
+ function randomIntegerWithout(minimum, maximum, excludedValue) {
10
+ const number = randomInteger(minimum, maximum - 1);
11
+ return number >= excludedValue ? number + 1 : number;
12
+ }
13
+ function makeCallable(generator) {
14
+ const iterator = generator();
15
+ function random() {
16
+ return iterator.next().value;
457
17
  }
458
- static restorePosition() {
459
- if (!window.location.hash) {
460
- let scroll;
461
- if (scroll = window.sessionStorage.getItem(window.location + "-scroll")) {
462
- window.sessionStorage.removeItem(window.location + "-scroll");
463
- setTimeout(function() {
464
- window.scrollTo(0, scroll);
465
- }, 100);
466
- }
467
- } else {
468
- setTimeout(function() {
469
- let h = this.document.querySelector(window.decodeURI(window.location.hash));
470
- if (h) {
471
- h.scrollIntoView();
472
- }
473
- }, 100);
18
+ random[Symbol.iterator] = function* () {
19
+ while (true) {
20
+ yield random();
474
21
  }
475
- }
22
+ };
23
+ return random;
476
24
  }
477
- try {
478
- if (typeof window !== "undefined") {
479
- window.CETEI = CETEI;
480
- window.addEventListener("beforeunload", CETEI.savePosition);
481
- var ceteiceanLoad = new Event("ceteiceanload");
482
- window.addEventListener("ceteiceanload", CETEI.restorePosition);
483
- }
484
- } catch (e) {
485
- console.log(e);
25
+ function exhaustiveUniqueRandom(minimum, maximum) {
26
+ return makeCallable(function* () {
27
+ let unconsumedValues = [...range(minimum, maximum)];
28
+ while (true) {
29
+ while (unconsumedValues.length > 1) {
30
+ yield unconsumedValues.splice(
31
+ randomInteger(0, unconsumedValues.length - 1),
32
+ 1
33
+ )[0];
34
+ }
35
+ const [previousValue] = unconsumedValues;
36
+ yield previousValue;
37
+ unconsumedValues = [...range(minimum, maximum)];
38
+ yield unconsumedValues.splice(
39
+ randomIntegerWithout(0, unconsumedValues.length - 1, previousValue - minimum),
40
+ 1
41
+ )[0];
42
+ }
43
+ });
486
44
  }
487
45
  export {
488
- CETEI as default
46
+ exhaustiveUniqueRandom
489
47
  };
490
48
  //# sourceMappingURL=react-text-annotator.es12.js.map