@soomo/react-text-annotator 3.0.0-staging.9 → 3.1.0-staging.1
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.
- package/dist/TextAnnotator.d.ts +4 -5
- package/dist/TextAnnotator.d.ts.map +1 -1
- package/dist/TextAnnotatorPlugin.d.ts +1 -2
- package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts +15 -0
- package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +1 -0
- package/dist/TextAnnotatorPopup/index.d.ts +2 -0
- package/dist/TextAnnotatorPopup/index.d.ts.map +1 -0
- package/dist/TextAnnotatorPopup/isMobile.d.ts +2 -0
- package/dist/TextAnnotatorPopup/isMobile.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/useAnnouncePopupNavigation.d.ts +10 -0
- package/dist/hooks/useAnnouncePopupNavigation.d.ts.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/react-text-annotator.css +31 -1
- package/dist/react-text-annotator.es.js +9 -5
- package/dist/react-text-annotator.es.js.map +1 -1
- package/dist/react-text-annotator.es10.js +442 -521
- package/dist/react-text-annotator.es10.js.map +1 -1
- package/dist/react-text-annotator.es11.js +9 -488
- package/dist/react-text-annotator.es11.js.map +1 -1
- package/dist/react-text-annotator.es12.js +1448 -2
- package/dist/react-text-annotator.es12.js.map +1 -1
- package/dist/react-text-annotator.es14.js +238 -891
- package/dist/react-text-annotator.es14.js.map +1 -1
- package/dist/react-text-annotator.es15.js +554 -197
- package/dist/react-text-annotator.es15.js.map +1 -1
- package/dist/react-text-annotator.es16.js +72 -126
- package/dist/react-text-annotator.es16.js.map +1 -1
- package/dist/react-text-annotator.es17.js +43 -112
- package/dist/react-text-annotator.es17.js.map +1 -1
- package/dist/react-text-annotator.es18.js +2 -309
- package/dist/react-text-annotator.es18.js.map +1 -1
- package/dist/react-text-annotator.es19.js +29 -56
- package/dist/react-text-annotator.es19.js.map +1 -1
- package/dist/react-text-annotator.es2.js +2 -2
- package/dist/react-text-annotator.es20.js +897 -19
- package/dist/react-text-annotator.es20.js.map +1 -1
- package/dist/react-text-annotator.es23.js +113 -120
- package/dist/react-text-annotator.es23.js.map +1 -1
- package/dist/react-text-annotator.es24.js +276 -519
- package/dist/react-text-annotator.es24.js.map +1 -1
- package/dist/react-text-annotator.es25.js +61 -0
- package/dist/react-text-annotator.es25.js.map +1 -0
- package/dist/react-text-annotator.es26.js +23 -0
- package/dist/react-text-annotator.es26.js.map +1 -0
- package/dist/react-text-annotator.es27.js +130 -0
- package/dist/react-text-annotator.es27.js.map +1 -0
- package/dist/react-text-annotator.es28.js +167 -0
- package/dist/react-text-annotator.es28.js.map +1 -0
- package/dist/react-text-annotator.es29.js +314 -0
- package/dist/react-text-annotator.es29.js.map +1 -0
- package/dist/react-text-annotator.es3.js +2 -2
- package/dist/react-text-annotator.es30.js +152 -0
- package/dist/react-text-annotator.es30.js.map +1 -0
- package/dist/react-text-annotator.es31.js +566 -0
- package/dist/react-text-annotator.es31.js.map +1 -0
- package/dist/react-text-annotator.es4.js +38 -28
- package/dist/react-text-annotator.es4.js.map +1 -1
- package/dist/react-text-annotator.es5.js +24 -72
- package/dist/react-text-annotator.es5.js.map +1 -1
- package/dist/react-text-annotator.es6.js +127 -10
- package/dist/react-text-annotator.es6.js.map +1 -1
- package/dist/react-text-annotator.es7.js +546 -1
- package/dist/react-text-annotator.es7.js.map +1 -1
- package/dist/react-text-annotator.es8.js +10 -24
- package/dist/react-text-annotator.es8.js.map +1 -1
- package/dist/tei/TEIAnnotator.d.ts +2 -3
- package/package.json +23 -17
- package/dist/TextAnnotatorPopup.d.ts +0 -15
- package/dist/TextAnnotatorPopup.d.ts.map +0 -1
- package/dist/react-text-annotator.es13.js +0 -38
- package/dist/react-text-annotator.es13.js.map +0 -1
- package/dist/react-text-annotator.es9.js +0 -199
- package/dist/react-text-annotator.es9.js.map +0 -1
- package/dist/utils.d.ts +0 -14
- package/dist/utils.d.ts.map +0 -1
|
@@ -1,555 +1,312 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
let
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const alignmentAxis = getAlignmentAxis(placement);
|
|
9
|
-
const alignLength = getAxisLength(alignmentAxis);
|
|
10
|
-
const side = getSide(placement);
|
|
11
|
-
const isVertical = sideAxis === "y";
|
|
12
|
-
const commonX = reference.x + reference.width / 2 - floating.width / 2;
|
|
13
|
-
const commonY = reference.y + reference.height / 2 - floating.height / 2;
|
|
14
|
-
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
|
|
15
|
-
let coords;
|
|
16
|
-
switch (side) {
|
|
17
|
-
case "top":
|
|
18
|
-
coords = {
|
|
19
|
-
x: commonX,
|
|
20
|
-
y: reference.y - floating.height
|
|
21
|
-
};
|
|
22
|
-
break;
|
|
23
|
-
case "bottom":
|
|
24
|
-
coords = {
|
|
25
|
-
x: commonX,
|
|
26
|
-
y: reference.y + reference.height
|
|
27
|
-
};
|
|
28
|
-
break;
|
|
29
|
-
case "right":
|
|
30
|
-
coords = {
|
|
31
|
-
x: reference.x + reference.width,
|
|
32
|
-
y: commonY
|
|
33
|
-
};
|
|
34
|
-
break;
|
|
35
|
-
case "left":
|
|
36
|
-
coords = {
|
|
37
|
-
x: reference.x - floating.width,
|
|
38
|
-
y: commonY
|
|
39
|
-
};
|
|
40
|
-
break;
|
|
41
|
-
default:
|
|
42
|
-
coords = {
|
|
43
|
-
x: reference.x,
|
|
44
|
-
y: reference.y
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
switch (getAlignment(placement)) {
|
|
48
|
-
case "start":
|
|
49
|
-
coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
|
|
50
|
-
break;
|
|
51
|
-
case "end":
|
|
52
|
-
coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
|
|
1
|
+
function getOrdinality(elt, name) {
|
|
2
|
+
let pos = 1;
|
|
3
|
+
let e = elt;
|
|
4
|
+
while (e && e.previousElementSibling !== null && (name ? e.previousElementSibling.localName == name : true)) {
|
|
5
|
+
pos++;
|
|
6
|
+
e = e.previousElementSibling;
|
|
7
|
+
if (!e.previousElementSibling) {
|
|
53
8
|
break;
|
|
9
|
+
}
|
|
54
10
|
}
|
|
55
|
-
return
|
|
11
|
+
return pos;
|
|
56
12
|
}
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const {
|
|
80
|
-
name,
|
|
81
|
-
fn
|
|
82
|
-
} = validMiddleware[i];
|
|
83
|
-
const {
|
|
84
|
-
x: nextX,
|
|
85
|
-
y: nextY,
|
|
86
|
-
data,
|
|
87
|
-
reset
|
|
88
|
-
} = await fn({
|
|
89
|
-
x,
|
|
90
|
-
y,
|
|
91
|
-
initialPlacement: placement,
|
|
92
|
-
placement: statefulPlacement,
|
|
93
|
-
strategy,
|
|
94
|
-
middlewareData,
|
|
95
|
-
rects,
|
|
96
|
-
platform,
|
|
97
|
-
elements: {
|
|
98
|
-
reference,
|
|
99
|
-
floating
|
|
13
|
+
function copyAndReset(node) {
|
|
14
|
+
const doc = node.ownerDocument;
|
|
15
|
+
let clone = (n) => {
|
|
16
|
+
let result;
|
|
17
|
+
switch (n.nodeType) {
|
|
18
|
+
case 1:
|
|
19
|
+
result = doc.createElement(n.nodeName);
|
|
20
|
+
break;
|
|
21
|
+
case 9:
|
|
22
|
+
result = doc.implementation.createDocument();
|
|
23
|
+
break;
|
|
24
|
+
case 11:
|
|
25
|
+
result = doc.createDocumentFragment();
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
result = n.cloneNode(true);
|
|
29
|
+
}
|
|
30
|
+
if (n.attributes) {
|
|
31
|
+
for (let att of Array.from(n.attributes)) {
|
|
32
|
+
if (att.name !== "data-processed") {
|
|
33
|
+
result.setAttribute(att.name, att.value);
|
|
34
|
+
}
|
|
100
35
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
36
|
+
}
|
|
37
|
+
for (let nd of Array.from(n.childNodes)) {
|
|
38
|
+
if (nd.nodeType == 1) {
|
|
39
|
+
if (nd.hasAttribute("data-original")) {
|
|
40
|
+
for (let childNode of Array.from(nd.childNodes)) {
|
|
41
|
+
let child = result.appendChild(clone(childNode));
|
|
42
|
+
if (child.nodeType === 1 && child.hasAttribute("data-origid")) {
|
|
43
|
+
child.setAttribute("id", child.getAttribute("data-origid"));
|
|
44
|
+
child.removeAttribute("data-origid");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
} else if (nd.hasAttribute("data-origname")) {
|
|
49
|
+
result.appendChild(clone(nd));
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
result.appendChild(nd.cloneNode());
|
|
109
53
|
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
return clone(node);
|
|
58
|
+
}
|
|
59
|
+
function first(urls) {
|
|
60
|
+
return urls.replace(/ .*$/, "");
|
|
61
|
+
}
|
|
62
|
+
function hideContent(elt, rewriteIds = true) {
|
|
63
|
+
const doc = elt.ownerDocument;
|
|
64
|
+
if (elt.childNodes.length > 0) {
|
|
65
|
+
let hidden = doc.createElement("cetei-original");
|
|
66
|
+
elt.appendChild(hidden);
|
|
67
|
+
hidden.setAttribute("hidden", "");
|
|
68
|
+
hidden.setAttribute("data-original", "");
|
|
69
|
+
for (let node of Array.from(elt.childNodes)) {
|
|
70
|
+
if (node !== hidden) {
|
|
71
|
+
if (node.nodeType === 1) {
|
|
72
|
+
node.setAttribute("data-processed", "");
|
|
73
|
+
for (let e of node.querySelectorAll("*")) {
|
|
74
|
+
e.setAttribute("data-processed", "");
|
|
75
|
+
}
|
|
116
76
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
77
|
+
hidden.appendChild(elt.removeChild(node));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (rewriteIds) {
|
|
81
|
+
for (let e of Array.from(hidden.querySelectorAll("*"))) {
|
|
82
|
+
if (e.hasAttribute("id")) {
|
|
83
|
+
e.setAttribute("data-origid", e.getAttribute("id"));
|
|
84
|
+
e.removeAttribute("id");
|
|
123
85
|
}
|
|
124
|
-
({
|
|
125
|
-
x,
|
|
126
|
-
y
|
|
127
|
-
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
|
128
86
|
}
|
|
129
|
-
i = -1;
|
|
130
87
|
}
|
|
131
88
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
async function detectOverflow(state, options) {
|
|
141
|
-
var _await$platform$isEle;
|
|
142
|
-
if (options === void 0) {
|
|
143
|
-
options = {};
|
|
89
|
+
}
|
|
90
|
+
function normalizeURI(urls) {
|
|
91
|
+
return this.rw(this.first(urls));
|
|
92
|
+
}
|
|
93
|
+
function repeat(str, times) {
|
|
94
|
+
let result = "";
|
|
95
|
+
for (let i = 0; i < times; i++) {
|
|
96
|
+
result += str;
|
|
144
97
|
}
|
|
145
|
-
|
|
146
|
-
x,
|
|
147
|
-
y,
|
|
148
|
-
platform,
|
|
149
|
-
rects,
|
|
150
|
-
elements,
|
|
151
|
-
strategy
|
|
152
|
-
} = state;
|
|
153
|
-
const {
|
|
154
|
-
boundary = "clippingAncestors",
|
|
155
|
-
rootBoundary = "viewport",
|
|
156
|
-
elementContext = "floating",
|
|
157
|
-
altBoundary = false,
|
|
158
|
-
padding = 0
|
|
159
|
-
} = evaluate(options, state);
|
|
160
|
-
const paddingObject = getPaddingObject(padding);
|
|
161
|
-
const altContext = elementContext === "floating" ? "reference" : "floating";
|
|
162
|
-
const element = elements[altBoundary ? altContext : elementContext];
|
|
163
|
-
const clippingClientRect = rectToClientRect(await platform.getClippingRect({
|
|
164
|
-
element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating)),
|
|
165
|
-
boundary,
|
|
166
|
-
rootBoundary,
|
|
167
|
-
strategy
|
|
168
|
-
}));
|
|
169
|
-
const rect = elementContext === "floating" ? {
|
|
170
|
-
x,
|
|
171
|
-
y,
|
|
172
|
-
width: rects.floating.width,
|
|
173
|
-
height: rects.floating.height
|
|
174
|
-
} : rects.reference;
|
|
175
|
-
const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
|
|
176
|
-
const offsetScale = await (platform.isElement == null ? void 0 : platform.isElement(offsetParent)) ? await (platform.getScale == null ? void 0 : platform.getScale(offsetParent)) || {
|
|
177
|
-
x: 1,
|
|
178
|
-
y: 1
|
|
179
|
-
} : {
|
|
180
|
-
x: 1,
|
|
181
|
-
y: 1
|
|
182
|
-
};
|
|
183
|
-
const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
184
|
-
elements,
|
|
185
|
-
rect,
|
|
186
|
-
offsetParent,
|
|
187
|
-
strategy
|
|
188
|
-
}) : rect);
|
|
189
|
-
return {
|
|
190
|
-
top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
|
|
191
|
-
bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
|
|
192
|
-
left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
|
|
193
|
-
right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
|
|
194
|
-
};
|
|
98
|
+
return result;
|
|
195
99
|
}
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
return
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return true;
|
|
203
|
-
});
|
|
100
|
+
function resolveURI(uri) {
|
|
101
|
+
let prefixdef = this.prefixDefs[uri.substring(0, uri.indexOf(":"))];
|
|
102
|
+
return uri.replace(new RegExp(prefixdef["matchPattern"]), prefixdef["replacementPattern"]);
|
|
103
|
+
}
|
|
104
|
+
function getPrefixDef(prefix) {
|
|
105
|
+
return this.prefixDefs[prefix];
|
|
204
106
|
}
|
|
205
|
-
|
|
206
|
-
if (
|
|
207
|
-
|
|
107
|
+
function rw(url) {
|
|
108
|
+
if (!url.match(/^(?:http|mailto|file|\/|#).*$/)) {
|
|
109
|
+
return this.base + first(url);
|
|
110
|
+
} else {
|
|
111
|
+
return url;
|
|
208
112
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
|
|
236
|
-
if (placement !== currentPlacement) {
|
|
237
|
-
return {
|
|
238
|
-
reset: {
|
|
239
|
-
placement: placements$1[0]
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]];
|
|
244
|
-
const allOverflows = [...((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || [], {
|
|
245
|
-
placement: currentPlacement,
|
|
246
|
-
overflows: currentOverflows
|
|
247
|
-
}];
|
|
248
|
-
const nextPlacement = placements$1[currentIndex + 1];
|
|
249
|
-
if (nextPlacement) {
|
|
250
|
-
return {
|
|
251
|
-
data: {
|
|
252
|
-
index: currentIndex + 1,
|
|
253
|
-
overflows: allOverflows
|
|
254
|
-
},
|
|
255
|
-
reset: {
|
|
256
|
-
placement: nextPlacement
|
|
257
|
-
}
|
|
258
|
-
};
|
|
113
|
+
}
|
|
114
|
+
function resetAndSerialize(el, stripElt, ws) {
|
|
115
|
+
return serialize(copyAndReset(el), stripElt, ws);
|
|
116
|
+
}
|
|
117
|
+
function serialize(el, stripElt, ws) {
|
|
118
|
+
let str = "";
|
|
119
|
+
const ignorable = (txt) => {
|
|
120
|
+
return !/[^\t\n\r ]/.test(txt);
|
|
121
|
+
};
|
|
122
|
+
if (el.nodeType === 9 || el.nodeType === 11) {
|
|
123
|
+
str += '<?xml version="1.0" encoding="UTF-8"?>\n';
|
|
124
|
+
}
|
|
125
|
+
if (!stripElt && el.nodeType == 1) {
|
|
126
|
+
if (typeof ws === "string" && ws !== "") {
|
|
127
|
+
str += "\n" + ws + "<";
|
|
128
|
+
} else {
|
|
129
|
+
str += "<";
|
|
130
|
+
}
|
|
131
|
+
str += el.getAttribute("data-origname");
|
|
132
|
+
let attrNames = el.hasAttribute("data-origatts") ? el.getAttribute("data-origatts").split(" ") : [];
|
|
133
|
+
for (let attr of Array.from(el.attributes)) {
|
|
134
|
+
if (!attr.name.startsWith("data-") && !["id", "lang", "class"].includes(attr.name)) {
|
|
135
|
+
str += " " + attrNames.find(function(e) {
|
|
136
|
+
return e.toLowerCase() == attr.name;
|
|
137
|
+
}) + '="' + attr.value + '"';
|
|
259
138
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return [d.placement, alignment2 && crossAxis ? (
|
|
263
|
-
// Check along the mainAxis and main crossAxis side.
|
|
264
|
-
d.overflows.slice(0, 2).reduce((acc, v) => acc + v, 0)
|
|
265
|
-
) : (
|
|
266
|
-
// Check only the mainAxis.
|
|
267
|
-
d.overflows[0]
|
|
268
|
-
), d.overflows];
|
|
269
|
-
}).sort((a, b) => a[1] - b[1]);
|
|
270
|
-
const placementsThatFitOnEachSide = placementsSortedByMostSpace.filter((d) => d[2].slice(
|
|
271
|
-
0,
|
|
272
|
-
// Aligned placements should not check their opposite crossAxis
|
|
273
|
-
// side.
|
|
274
|
-
getAlignment(d[0]) ? 2 : 3
|
|
275
|
-
).every((v) => v <= 0));
|
|
276
|
-
const resetPlacement = ((_placementsThatFitOnE = placementsThatFitOnEachSide[0]) == null ? void 0 : _placementsThatFitOnE[0]) || placementsSortedByMostSpace[0][0];
|
|
277
|
-
if (resetPlacement !== placement) {
|
|
278
|
-
return {
|
|
279
|
-
data: {
|
|
280
|
-
index: currentIndex + 1,
|
|
281
|
-
overflows: allOverflows
|
|
282
|
-
},
|
|
283
|
-
reset: {
|
|
284
|
-
placement: resetPlacement
|
|
285
|
-
}
|
|
286
|
-
};
|
|
139
|
+
if (attr.name == "data-xmlns") {
|
|
140
|
+
str += ' xmlns="' + attr.value + '"';
|
|
287
141
|
}
|
|
288
|
-
return {};
|
|
289
142
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
function getBoundingRect(rects) {
|
|
293
|
-
const minX = min(...rects.map((rect) => rect.left));
|
|
294
|
-
const minY = min(...rects.map((rect) => rect.top));
|
|
295
|
-
const maxX = max(...rects.map((rect) => rect.right));
|
|
296
|
-
const maxY = max(...rects.map((rect) => rect.bottom));
|
|
297
|
-
return {
|
|
298
|
-
x: minX,
|
|
299
|
-
y: minY,
|
|
300
|
-
width: maxX - minX,
|
|
301
|
-
height: maxY - minY
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
function getRectsByLine(rects) {
|
|
305
|
-
const sortedRects = rects.slice().sort((a, b) => a.y - b.y);
|
|
306
|
-
const groups = [];
|
|
307
|
-
let prevRect = null;
|
|
308
|
-
for (let i = 0; i < sortedRects.length; i++) {
|
|
309
|
-
const rect = sortedRects[i];
|
|
310
|
-
if (!prevRect || rect.y - prevRect.y > prevRect.height / 2) {
|
|
311
|
-
groups.push([rect]);
|
|
143
|
+
if (el.childNodes.length > 0) {
|
|
144
|
+
str += ">";
|
|
312
145
|
} else {
|
|
313
|
-
|
|
146
|
+
str += "/>";
|
|
314
147
|
}
|
|
315
|
-
prevRect = rect;
|
|
316
|
-
}
|
|
317
|
-
return groups.map((rect) => rectToClientRect(getBoundingRect(rect)));
|
|
318
|
-
}
|
|
319
|
-
const inline = function(options) {
|
|
320
|
-
if (options === void 0) {
|
|
321
|
-
options = {};
|
|
322
148
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
rects,
|
|
331
|
-
platform,
|
|
332
|
-
strategy
|
|
333
|
-
} = state;
|
|
334
|
-
const {
|
|
335
|
-
padding = 2,
|
|
336
|
-
x,
|
|
337
|
-
y
|
|
338
|
-
} = evaluate(options, state);
|
|
339
|
-
const nativeClientRects = Array.from(await (platform.getClientRects == null ? void 0 : platform.getClientRects(elements.reference)) || []);
|
|
340
|
-
const clientRects = getRectsByLine(nativeClientRects);
|
|
341
|
-
const fallback = rectToClientRect(getBoundingRect(nativeClientRects));
|
|
342
|
-
const paddingObject = getPaddingObject(padding);
|
|
343
|
-
function getBoundingClientRect() {
|
|
344
|
-
if (clientRects.length === 2 && clientRects[0].left > clientRects[1].right && x != null && y != null) {
|
|
345
|
-
return clientRects.find((rect) => x > rect.left - paddingObject.left && x < rect.right + paddingObject.right && y > rect.top - paddingObject.top && y < rect.bottom + paddingObject.bottom) || fallback;
|
|
149
|
+
for (let node of Array.from(el.childNodes)) {
|
|
150
|
+
switch (node.nodeType) {
|
|
151
|
+
case 1:
|
|
152
|
+
if (typeof ws === "string") {
|
|
153
|
+
str += serialize(node, false, ws + " ");
|
|
154
|
+
} else {
|
|
155
|
+
str += serialize(node, false, ws);
|
|
346
156
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const top2 = firstRect.top;
|
|
353
|
-
const bottom2 = lastRect.bottom;
|
|
354
|
-
const left2 = isTop ? firstRect.left : lastRect.left;
|
|
355
|
-
const right2 = isTop ? firstRect.right : lastRect.right;
|
|
356
|
-
const width2 = right2 - left2;
|
|
357
|
-
const height2 = bottom2 - top2;
|
|
358
|
-
return {
|
|
359
|
-
top: top2,
|
|
360
|
-
bottom: bottom2,
|
|
361
|
-
left: left2,
|
|
362
|
-
right: right2,
|
|
363
|
-
width: width2,
|
|
364
|
-
height: height2,
|
|
365
|
-
x: left2,
|
|
366
|
-
y: top2
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
const isLeftSide = getSide(placement) === "left";
|
|
370
|
-
const maxRight = max(...clientRects.map((rect) => rect.right));
|
|
371
|
-
const minLeft = min(...clientRects.map((rect) => rect.left));
|
|
372
|
-
const measureRects = clientRects.filter((rect) => isLeftSide ? rect.left === minLeft : rect.right === maxRight);
|
|
373
|
-
const top = measureRects[0].top;
|
|
374
|
-
const bottom = measureRects[measureRects.length - 1].bottom;
|
|
375
|
-
const left = minLeft;
|
|
376
|
-
const right = maxRight;
|
|
377
|
-
const width = right - left;
|
|
378
|
-
const height = bottom - top;
|
|
379
|
-
return {
|
|
380
|
-
top,
|
|
381
|
-
bottom,
|
|
382
|
-
left,
|
|
383
|
-
right,
|
|
384
|
-
width,
|
|
385
|
-
height,
|
|
386
|
-
x: left,
|
|
387
|
-
y: top
|
|
388
|
-
};
|
|
157
|
+
break;
|
|
158
|
+
case 7:
|
|
159
|
+
str += `<?${node.nodeName} ${node.nodeValue}?>`;
|
|
160
|
+
if (el.nodeType === 9 || el.nodeType === 11) {
|
|
161
|
+
str += "\n";
|
|
389
162
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
return {};
|
|
163
|
+
break;
|
|
164
|
+
case 8:
|
|
165
|
+
str += `<!--${node.nodeValue}-->`;
|
|
166
|
+
if (el.nodeType === 9 || el.nodeType === 11) {
|
|
167
|
+
str += "\n";
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
if (stripElt && ignorable(node.nodeValue)) {
|
|
172
|
+
str += node.nodeValue.replace(/^\s*\n/, "");
|
|
173
|
+
}
|
|
174
|
+
if (typeof ws === "string" && ignorable(node.nodeValue)) {
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
str += node.nodeValue;
|
|
407
178
|
}
|
|
408
|
-
};
|
|
409
|
-
};
|
|
410
|
-
async function convertValueToCoords(state, options) {
|
|
411
|
-
const {
|
|
412
|
-
placement,
|
|
413
|
-
platform,
|
|
414
|
-
elements
|
|
415
|
-
} = state;
|
|
416
|
-
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
417
|
-
const side = getSide(placement);
|
|
418
|
-
const alignment = getAlignment(placement);
|
|
419
|
-
const isVertical = getSideAxis(placement) === "y";
|
|
420
|
-
const mainAxisMulti = ["left", "top"].includes(side) ? -1 : 1;
|
|
421
|
-
const crossAxisMulti = rtl && isVertical ? -1 : 1;
|
|
422
|
-
const rawValue = evaluate(options, state);
|
|
423
|
-
let {
|
|
424
|
-
mainAxis,
|
|
425
|
-
crossAxis,
|
|
426
|
-
alignmentAxis
|
|
427
|
-
} = typeof rawValue === "number" ? {
|
|
428
|
-
mainAxis: rawValue,
|
|
429
|
-
crossAxis: 0,
|
|
430
|
-
alignmentAxis: null
|
|
431
|
-
} : {
|
|
432
|
-
mainAxis: 0,
|
|
433
|
-
crossAxis: 0,
|
|
434
|
-
alignmentAxis: null,
|
|
435
|
-
...rawValue
|
|
436
|
-
};
|
|
437
|
-
if (alignment && typeof alignmentAxis === "number") {
|
|
438
|
-
crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
|
|
439
179
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
180
|
+
if (!stripElt && el.nodeType == 1 && el.childNodes.length > 0) {
|
|
181
|
+
if (typeof ws === "string") {
|
|
182
|
+
str += "\n" + ws + "</";
|
|
183
|
+
} else {
|
|
184
|
+
str += "</";
|
|
185
|
+
}
|
|
186
|
+
str += el.getAttribute("data-origname") + ">";
|
|
187
|
+
}
|
|
188
|
+
if (el.nodeType === 9 || el.nodeType === 11) {
|
|
189
|
+
str += "\n";
|
|
190
|
+
}
|
|
191
|
+
return str;
|
|
447
192
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
193
|
+
function serializeHTML(el, stripElt, ws) {
|
|
194
|
+
const EMPTY_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"];
|
|
195
|
+
let str = "";
|
|
196
|
+
const ignorable = (txt) => {
|
|
197
|
+
return !/[^\t\n\r ]/.test(txt);
|
|
198
|
+
};
|
|
199
|
+
if (!stripElt && el.nodeType == 1) {
|
|
200
|
+
if (typeof ws === "string" && ws !== "") {
|
|
201
|
+
str += "\n" + ws + "<";
|
|
202
|
+
} else {
|
|
203
|
+
str += "<";
|
|
204
|
+
}
|
|
205
|
+
str += el.nodeName;
|
|
206
|
+
for (let attr of Array.from(el.attributes)) {
|
|
207
|
+
str += " " + attr.name + '="' + attr.value + '"';
|
|
208
|
+
}
|
|
209
|
+
str += ">";
|
|
451
210
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
return {};
|
|
466
|
-
}
|
|
467
|
-
return {
|
|
468
|
-
x: x + diffCoords.x,
|
|
469
|
-
y: y + diffCoords.y,
|
|
470
|
-
data: {
|
|
471
|
-
...diffCoords,
|
|
472
|
-
placement
|
|
211
|
+
for (let node of Array.from(el.childNodes)) {
|
|
212
|
+
switch (node.nodeType) {
|
|
213
|
+
case 1:
|
|
214
|
+
if (typeof ws === "string") {
|
|
215
|
+
str += serializeHTML(node, false, ws + " ");
|
|
216
|
+
} else {
|
|
217
|
+
str += serializeHTML(node, false, ws);
|
|
218
|
+
}
|
|
219
|
+
break;
|
|
220
|
+
case 7:
|
|
221
|
+
str += `<?${node.nodeName} ${node.nodeValue}?>`;
|
|
222
|
+
if (el.nodeType === 9 || el.nodeType === 11) {
|
|
223
|
+
str += "\n";
|
|
473
224
|
}
|
|
474
|
-
|
|
225
|
+
break;
|
|
226
|
+
case 8:
|
|
227
|
+
str += `<!--${node.nodeValue}-->`;
|
|
228
|
+
if (el.nodeType === 9 || el.nodeType === 11) {
|
|
229
|
+
str += "\n";
|
|
230
|
+
}
|
|
231
|
+
break;
|
|
232
|
+
default:
|
|
233
|
+
if (stripElt && ignorable(node.nodeValue)) {
|
|
234
|
+
str += node.nodeValue.replace(/^\s*\n/, "");
|
|
235
|
+
}
|
|
236
|
+
if (typeof ws === "string" && ignorable(node.nodeValue)) {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
str += node.nodeValue.replace(/</g, "<");
|
|
475
240
|
}
|
|
476
|
-
};
|
|
477
|
-
};
|
|
478
|
-
const shift = function(options) {
|
|
479
|
-
if (options === void 0) {
|
|
480
|
-
options = {};
|
|
481
241
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
placement
|
|
490
|
-
} = state;
|
|
491
|
-
const {
|
|
492
|
-
mainAxis: checkMainAxis = true,
|
|
493
|
-
crossAxis: checkCrossAxis = false,
|
|
494
|
-
limiter = {
|
|
495
|
-
fn: (_ref) => {
|
|
496
|
-
let {
|
|
497
|
-
x: x2,
|
|
498
|
-
y: y2
|
|
499
|
-
} = _ref;
|
|
500
|
-
return {
|
|
501
|
-
x: x2,
|
|
502
|
-
y: y2
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
},
|
|
506
|
-
...detectOverflowOptions
|
|
507
|
-
} = evaluate(options, state);
|
|
508
|
-
const coords = {
|
|
509
|
-
x,
|
|
510
|
-
y
|
|
511
|
-
};
|
|
512
|
-
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
513
|
-
const crossAxis = getSideAxis(getSide(placement));
|
|
514
|
-
const mainAxis = getOppositeAxis(crossAxis);
|
|
515
|
-
let mainAxisCoord = coords[mainAxis];
|
|
516
|
-
let crossAxisCoord = coords[crossAxis];
|
|
517
|
-
if (checkMainAxis) {
|
|
518
|
-
const minSide = mainAxis === "y" ? "top" : "left";
|
|
519
|
-
const maxSide = mainAxis === "y" ? "bottom" : "right";
|
|
520
|
-
const min2 = mainAxisCoord + overflow[minSide];
|
|
521
|
-
const max2 = mainAxisCoord - overflow[maxSide];
|
|
522
|
-
mainAxisCoord = clamp(min2, mainAxisCoord, max2);
|
|
242
|
+
if (!EMPTY_ELEMENTS.includes(el.nodeName)) {
|
|
243
|
+
if (!stripElt && el.nodeType == 1) {
|
|
244
|
+
if (typeof ws === "string") {
|
|
245
|
+
str += `
|
|
246
|
+
${ws}</`;
|
|
247
|
+
} else {
|
|
248
|
+
str += "</";
|
|
523
249
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
250
|
+
str += `${el.nodeName}>`;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (el.nodeType === 9 || el.nodeType === 11) {
|
|
254
|
+
str += "\n";
|
|
255
|
+
}
|
|
256
|
+
return str;
|
|
257
|
+
}
|
|
258
|
+
function unEscapeEntities(str) {
|
|
259
|
+
return str.replace(/>/, ">").replace(/"/, '"').replace(/'/, "'").replace(/&/, "&");
|
|
260
|
+
}
|
|
261
|
+
function tagName(name) {
|
|
262
|
+
if (name.includes(":"), 1) {
|
|
263
|
+
return name.replace(/:/, "-").toLowerCase();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function defineCustomElement(name, behavior = null, debug = false) {
|
|
267
|
+
try {
|
|
268
|
+
window.customElements.define(tagName(name), class extends HTMLElement {
|
|
269
|
+
constructor() {
|
|
270
|
+
super();
|
|
271
|
+
if (!this.matches(":defined")) {
|
|
272
|
+
if (behavior) {
|
|
273
|
+
behavior.call(this);
|
|
274
|
+
this.setAttribute("data-processed", "");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
530
277
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
data: {
|
|
539
|
-
x: limitedCoords.x - x,
|
|
540
|
-
y: limitedCoords.y - y
|
|
278
|
+
// Process new elements when they are connected to the browser DOM
|
|
279
|
+
connectedCallback() {
|
|
280
|
+
if (!this.hasAttribute("data-processed")) {
|
|
281
|
+
if (behavior) {
|
|
282
|
+
behavior.call(this);
|
|
283
|
+
this.setAttribute("data-processed", "");
|
|
284
|
+
}
|
|
541
285
|
}
|
|
542
|
-
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
} catch (error) {
|
|
289
|
+
if (debug) {
|
|
290
|
+
console.log(tagName(name) + " couldn't be registered or is already registered.");
|
|
291
|
+
console.log(error);
|
|
543
292
|
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
546
295
|
export {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
296
|
+
copyAndReset,
|
|
297
|
+
defineCustomElement,
|
|
298
|
+
first,
|
|
299
|
+
getOrdinality,
|
|
300
|
+
getPrefixDef,
|
|
301
|
+
hideContent,
|
|
302
|
+
normalizeURI,
|
|
303
|
+
repeat,
|
|
304
|
+
resetAndSerialize,
|
|
305
|
+
resolveURI,
|
|
306
|
+
rw,
|
|
307
|
+
serialize,
|
|
308
|
+
serializeHTML,
|
|
309
|
+
tagName,
|
|
310
|
+
unEscapeEntities
|
|
554
311
|
};
|
|
555
312
|
//# sourceMappingURL=react-text-annotator.es24.js.map
|