@progress/kendo-pdfviewer-common 0.3.0-dev.202409251459 → 0.3.0-dev.202410100645
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/es/annotations/annotation-editor-layer-builder.js +139 -0
- package/dist/es/annotations/annotation-editor-layer.js +780 -0
- package/dist/es/annotations/annotation-editor-ui-manager.js +1690 -0
- package/dist/es/annotations/annotation-layer-builder.js +217 -0
- package/dist/es/annotations/annotation-layer.js +2793 -0
- package/dist/es/annotations/draw-layer-builder.js +65 -0
- package/dist/es/annotations/draw-layer.js +220 -0
- package/dist/es/annotations/editors/annotation-editor.js +1519 -0
- package/dist/es/annotations/editors/free-text-editor.js +783 -0
- package/dist/es/annotations/editors/highlight-editor.js +717 -0
- package/dist/es/annotations/editors/outliner.js +747 -0
- package/dist/es/annotations/helpers/annotation-storage.js +294 -0
- package/dist/es/annotations/helpers/color-manager.js +72 -0
- package/dist/es/annotations/helpers/command-manager.js +133 -0
- package/dist/es/annotations/helpers/id-manager.js +34 -0
- package/dist/es/annotations/helpers/image-manager.js +176 -0
- package/dist/es/annotations/helpers/text-accessibility-manager.js +212 -0
- package/dist/es/annotations/helpers/tools.js +19 -0
- package/dist/es/annotations/shared/display_utils.js +1024 -0
- package/dist/es/annotations/shared/event_utils.js +213 -0
- package/dist/es/annotations/shared/murmurhash3.js +126 -0
- package/dist/es/annotations/shared/scripting_utils.js +90 -0
- package/dist/es/annotations/shared/ui_utils.js +823 -0
- package/dist/es/annotations/shared/utils.js +909 -0
- package/dist/es/common/component.js +33 -0
- package/dist/es/common/core.js +91 -0
- package/dist/es/common/dom.js +11 -0
- package/dist/es/common/main.js +4 -0
- package/dist/es/common/math.js +1 -0
- package/dist/es/enums/PdfViewerInteractionMode.js +6 -0
- package/dist/es/links/link-service.js +505 -0
- package/dist/es/main.js +2 -0
- package/dist/es/scroller.js +29 -30
- package/dist/es/text/text-layer-builder.js +288 -0
- package/dist/es/utils.js +5 -5
- package/dist/es/widget/page.js +762 -0
- package/dist/es/widget/pdfviewer.js +1659 -0
- package/dist/es2015/annotations/annotation-editor-layer-builder.js +139 -0
- package/dist/es2015/annotations/annotation-editor-layer.js +780 -0
- package/dist/es2015/annotations/annotation-editor-ui-manager.js +1690 -0
- package/dist/es2015/annotations/annotation-layer-builder.js +217 -0
- package/dist/es2015/annotations/annotation-layer.js +2793 -0
- package/dist/es2015/annotations/draw-layer-builder.js +65 -0
- package/dist/es2015/annotations/draw-layer.js +220 -0
- package/dist/es2015/annotations/editors/annotation-editor.js +1519 -0
- package/dist/es2015/annotations/editors/free-text-editor.js +783 -0
- package/dist/es2015/annotations/editors/highlight-editor.js +717 -0
- package/dist/es2015/annotations/editors/outliner.js +747 -0
- package/dist/es2015/annotations/helpers/annotation-storage.js +294 -0
- package/dist/es2015/annotations/helpers/color-manager.js +72 -0
- package/dist/es2015/annotations/helpers/command-manager.js +133 -0
- package/dist/es2015/annotations/helpers/id-manager.js +34 -0
- package/dist/es2015/annotations/helpers/image-manager.js +176 -0
- package/dist/es2015/annotations/helpers/text-accessibility-manager.js +212 -0
- package/dist/es2015/annotations/helpers/tools.js +19 -0
- package/dist/es2015/annotations/shared/display_utils.js +1024 -0
- package/dist/es2015/annotations/shared/event_utils.js +213 -0
- package/dist/es2015/annotations/shared/murmurhash3.js +126 -0
- package/dist/es2015/annotations/shared/scripting_utils.js +90 -0
- package/dist/es2015/annotations/shared/ui_utils.js +823 -0
- package/dist/es2015/annotations/shared/utils.js +909 -0
- package/dist/es2015/common/component.js +33 -0
- package/dist/es2015/common/core.js +91 -0
- package/dist/es2015/common/dom.js +11 -0
- package/dist/es2015/common/main.js +4 -0
- package/dist/es2015/common/math.js +1 -0
- package/dist/es2015/enums/PdfViewerInteractionMode.js +6 -0
- package/dist/es2015/links/link-service.js +505 -0
- package/dist/es2015/main.js +2 -0
- package/dist/es2015/scroller.js +29 -30
- package/dist/es2015/text/text-layer-builder.js +288 -0
- package/dist/es2015/utils.js +5 -5
- package/dist/es2015/widget/page.js +762 -0
- package/dist/es2015/widget/pdfviewer.js +1659 -0
- package/dist/npm/annotations/annotation-editor-layer-builder.d.ts +39 -0
- package/dist/npm/annotations/annotation-editor-layer-builder.js +142 -0
- package/dist/npm/annotations/annotation-editor-layer.d.ts +196 -0
- package/dist/npm/annotations/annotation-editor-layer.js +783 -0
- package/dist/npm/annotations/annotation-editor-ui-manager.d.ts +281 -0
- package/dist/npm/annotations/annotation-editor-ui-manager.js +1694 -0
- package/dist/npm/annotations/annotation-layer-builder.d.ts +58 -0
- package/dist/npm/annotations/annotation-layer-builder.js +220 -0
- package/dist/npm/annotations/annotation-layer.d.ts +134 -0
- package/dist/npm/annotations/annotation-layer.js +2794 -0
- package/dist/npm/annotations/draw-layer-builder.d.ts +21 -0
- package/dist/npm/annotations/draw-layer-builder.js +68 -0
- package/dist/npm/annotations/draw-layer.d.ts +33 -0
- package/dist/npm/annotations/draw-layer.js +223 -0
- package/dist/npm/annotations/editors/annotation-editor.d.ts +349 -0
- package/dist/npm/annotations/editors/annotation-editor.js +1523 -0
- package/dist/npm/annotations/editors/free-text-editor.d.ts +108 -0
- package/dist/npm/annotations/editors/free-text-editor.js +786 -0
- package/dist/npm/annotations/editors/highlight-editor.d.ts +114 -0
- package/dist/npm/annotations/editors/highlight-editor.js +717 -0
- package/dist/npm/annotations/editors/outliner.d.ts +51 -0
- package/dist/npm/annotations/editors/outliner.js +750 -0
- package/dist/npm/annotations/helpers/annotation-storage.d.ts +98 -0
- package/dist/npm/annotations/helpers/annotation-storage.js +299 -0
- package/dist/npm/annotations/helpers/color-manager.d.ts +6 -0
- package/dist/npm/annotations/helpers/color-manager.js +76 -0
- package/dist/npm/annotations/helpers/command-manager.d.ts +42 -0
- package/dist/npm/annotations/helpers/command-manager.js +137 -0
- package/dist/npm/annotations/helpers/id-manager.d.ts +6 -0
- package/dist/npm/annotations/helpers/id-manager.js +38 -0
- package/dist/npm/annotations/helpers/image-manager.d.ts +18 -0
- package/dist/npm/annotations/helpers/image-manager.js +180 -0
- package/dist/npm/annotations/helpers/text-accessibility-manager.d.ts +36 -0
- package/dist/npm/annotations/helpers/text-accessibility-manager.js +215 -0
- package/dist/npm/annotations/helpers/tools.d.ts +1 -0
- package/dist/npm/annotations/helpers/tools.js +23 -0
- package/dist/npm/annotations/shared/display_utils.d.ts +6 -0
- package/dist/npm/annotations/shared/display_utils.js +1030 -0
- package/dist/npm/annotations/shared/event_utils.d.ts +33 -0
- package/dist/npm/annotations/shared/event_utils.js +165 -0
- package/dist/npm/annotations/shared/murmurhash3.d.ts +8 -0
- package/dist/npm/annotations/shared/murmurhash3.js +129 -0
- package/dist/npm/annotations/shared/scripting_utils.d.ts +17 -0
- package/dist/npm/annotations/shared/scripting_utils.js +93 -0
- package/dist/npm/annotations/shared/ui_utils.d.ts +54 -0
- package/dist/npm/annotations/shared/ui_utils.js +250 -0
- package/dist/npm/annotations/shared/utils.d.ts +148 -0
- package/dist/npm/annotations/shared/utils.js +872 -0
- package/dist/npm/common/component.d.ts +9 -0
- package/dist/npm/common/component.js +37 -0
- package/dist/npm/common/core.d.ts +18 -0
- package/dist/npm/common/core.js +112 -0
- package/dist/npm/common/dom.d.ts +3 -0
- package/dist/npm/common/dom.js +17 -0
- package/dist/npm/common/main.d.ts +4 -0
- package/dist/npm/common/main.js +7 -0
- package/dist/npm/common/math.d.ts +1 -0
- package/dist/npm/common/math.js +5 -0
- package/dist/npm/enums/PdfViewerInteractionMode.d.ts +4 -0
- package/dist/npm/enums/PdfViewerInteractionMode.js +9 -0
- package/dist/npm/links/link-service.d.ts +116 -0
- package/dist/npm/links/link-service.js +501 -0
- package/dist/npm/main.d.ts +2 -0
- package/dist/npm/main.js +2 -0
- package/dist/npm/scroller.d.ts +7 -3
- package/dist/npm/scroller.js +32 -32
- package/dist/npm/text/text-layer-builder.d.ts +30 -0
- package/dist/npm/text/text-layer-builder.js +291 -0
- package/dist/npm/utils.d.ts +20 -2
- package/dist/npm/utils.js +11 -8
- package/dist/npm/widget/page.d.ts +75 -0
- package/dist/npm/widget/page.js +763 -0
- package/dist/npm/widget/pdfviewer.d.ts +222 -0
- package/dist/npm/widget/pdfviewer.js +1663 -0
- package/package.json +13 -9
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
/* Copyright 2023 Mozilla Foundation
|
|
2
|
+
*
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
var _Outliner_instances, _Outliner_box, _Outliner_verticalEdges, _Outliner_intervals, _Outliner_getOutlines, _Outliner_binarySearch, _Outliner_insert, _Outliner_remove, _Outliner_breakEdge, _HighlightOutline_box, _HighlightOutline_outlines, _FreeOutliner_instances, _a, _FreeOutliner_box, _FreeOutliner_bottom, _FreeOutliner_innerMargin, _FreeOutliner_isLTR, _FreeOutliner_top, _FreeOutliner_last, _FreeOutliner_lastX, _FreeOutliner_lastY, _FreeOutliner_min, _FreeOutliner_min_dist, _FreeOutliner_scaleFactor, _FreeOutliner_thickness, _FreeOutliner_points, _FreeOutliner_MIN_DIST, _FreeOutliner_MIN_DIFF, _FreeOutliner_MIN, _FreeOutliner_getLastCoords, _FreeHighlightOutline_instances, _FreeHighlightOutline_box, _FreeHighlightOutline_bbox, _FreeHighlightOutline_innerMargin, _FreeHighlightOutline_isLTR, _FreeHighlightOutline_points, _FreeHighlightOutline_scaleFactor, _FreeHighlightOutline_outline, _FreeHighlightOutline_rescale, _FreeHighlightOutline_rescaleAndSwap, _FreeHighlightOutline_computeMinMax;
|
|
16
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
17
|
+
import { Util } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
18
|
+
// import { Util } from "../../shared/utils";
|
|
19
|
+
export class Outliner {
|
|
20
|
+
/*
|
|
21
|
+
* Construct an outliner.
|
|
22
|
+
* @param {Array<Object>} boxes - An array of axis-aligned rectangles.
|
|
23
|
+
* @param {number} borderWidth - The width of the border of the boxes, it
|
|
24
|
+
* allows to make the boxes bigger (or smaller).
|
|
25
|
+
* @param {number} innerMargin - The margin between the boxes and the
|
|
26
|
+
* outlines. It's important to not have a null innerMargin when we want to
|
|
27
|
+
* draw the outline else the stroked outline could be clipped because of its
|
|
28
|
+
* width.
|
|
29
|
+
* @param {boolean} isLTR - true if we're in LTR mode. It's used to determine
|
|
30
|
+
* the last point of the boxes.
|
|
31
|
+
*/
|
|
32
|
+
constructor(boxes, borderWidth = 0, innerMargin = 0, isLTR = true) {
|
|
33
|
+
_Outliner_instances.add(this);
|
|
34
|
+
_Outliner_box.set(this, void 0);
|
|
35
|
+
_Outliner_verticalEdges.set(this, []);
|
|
36
|
+
_Outliner_intervals.set(this, []);
|
|
37
|
+
let minX = Infinity;
|
|
38
|
+
let maxX = -Infinity;
|
|
39
|
+
let minY = Infinity;
|
|
40
|
+
let maxY = -Infinity;
|
|
41
|
+
// We round the coordinates to slightly reduce the number of edges in the
|
|
42
|
+
// final outlines.
|
|
43
|
+
const NUMBER_OF_DIGITS = 4;
|
|
44
|
+
const EPSILON = Math.pow(10, -NUMBER_OF_DIGITS);
|
|
45
|
+
// The coordinates of the boxes are in the page coordinate system.
|
|
46
|
+
for (const { x, y, width, height } of boxes) {
|
|
47
|
+
const x1 = Math.floor((x - borderWidth) / EPSILON) * EPSILON;
|
|
48
|
+
const x2 = Math.ceil((x + width + borderWidth) / EPSILON) * EPSILON;
|
|
49
|
+
const y1 = Math.floor((y - borderWidth) / EPSILON) * EPSILON;
|
|
50
|
+
const y2 = Math.ceil((y + height + borderWidth) / EPSILON) * EPSILON;
|
|
51
|
+
const left = [x1, y1, y2, true];
|
|
52
|
+
const right = [x2, y1, y2, false];
|
|
53
|
+
__classPrivateFieldGet(this, _Outliner_verticalEdges, "f").push(left, right);
|
|
54
|
+
minX = Math.min(minX, x1);
|
|
55
|
+
maxX = Math.max(maxX, x2);
|
|
56
|
+
minY = Math.min(minY, y1);
|
|
57
|
+
maxY = Math.max(maxY, y2);
|
|
58
|
+
}
|
|
59
|
+
const bboxWidth = maxX - minX + 2 * innerMargin;
|
|
60
|
+
const bboxHeight = maxY - minY + 2 * innerMargin;
|
|
61
|
+
const shiftedMinX = minX - innerMargin;
|
|
62
|
+
const shiftedMinY = minY - innerMargin;
|
|
63
|
+
const lastEdge = __classPrivateFieldGet(this, _Outliner_verticalEdges, "f").at(isLTR ? -1 : -2);
|
|
64
|
+
const lastPoint = [lastEdge[0], lastEdge[2]];
|
|
65
|
+
// Convert the coordinates of the edges into box coordinates.
|
|
66
|
+
for (const edge of __classPrivateFieldGet(this, _Outliner_verticalEdges, "f")) {
|
|
67
|
+
const [x, y1, y2] = edge;
|
|
68
|
+
edge[0] = (x - shiftedMinX) / bboxWidth;
|
|
69
|
+
edge[1] = (y1 - shiftedMinY) / bboxHeight;
|
|
70
|
+
edge[2] = (y2 - shiftedMinY) / bboxHeight;
|
|
71
|
+
}
|
|
72
|
+
__classPrivateFieldSet(this, _Outliner_box, {
|
|
73
|
+
x: shiftedMinX,
|
|
74
|
+
y: shiftedMinY,
|
|
75
|
+
width: bboxWidth,
|
|
76
|
+
height: bboxHeight,
|
|
77
|
+
lastPoint
|
|
78
|
+
}, "f");
|
|
79
|
+
}
|
|
80
|
+
getOutlines() {
|
|
81
|
+
// We begin to sort lexicographically the vertical edges by their abscissa,
|
|
82
|
+
// and then by their ordinate.
|
|
83
|
+
__classPrivateFieldGet(this, _Outliner_verticalEdges, "f").sort((a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2]);
|
|
84
|
+
// We're now using a sweep line algorithm to find the outlines.
|
|
85
|
+
// We start with the leftmost vertical edge, and we're going to iterate
|
|
86
|
+
// over all the vertical edges from left to right.
|
|
87
|
+
// Each time we encounter a left edge, we're going to insert the interval
|
|
88
|
+
// [y1, y2] in the set of intervals.
|
|
89
|
+
// This set of intervals is used to break the vertical edges into chunks:
|
|
90
|
+
// we only take the part of the vertical edge that isn't in the union of
|
|
91
|
+
// the intervals.
|
|
92
|
+
const outlineVerticalEdges = [];
|
|
93
|
+
for (const edge of __classPrivateFieldGet(this, _Outliner_verticalEdges, "f")) {
|
|
94
|
+
if (edge[3]) {
|
|
95
|
+
// Left edge.
|
|
96
|
+
outlineVerticalEdges.push(...__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_breakEdge).call(this, edge));
|
|
97
|
+
__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_insert).call(this, edge);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Right edge.
|
|
101
|
+
__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_remove).call(this, edge);
|
|
102
|
+
outlineVerticalEdges.push(...__classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_breakEdge).call(this, edge));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return __classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_getOutlines).call(this, outlineVerticalEdges);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
_Outliner_box = new WeakMap(), _Outliner_verticalEdges = new WeakMap(), _Outliner_intervals = new WeakMap(), _Outliner_instances = new WeakSet(), _Outliner_getOutlines = function _Outliner_getOutlines(outlineVerticalEdges) {
|
|
109
|
+
const edges = [];
|
|
110
|
+
const allEdges = new Set();
|
|
111
|
+
for (const edge of outlineVerticalEdges) {
|
|
112
|
+
const [x, y1, y2] = edge;
|
|
113
|
+
edges.push([x, y1, edge], [x, y2, edge]);
|
|
114
|
+
}
|
|
115
|
+
// We sort lexicographically the vertices of each edge by their ordinate and
|
|
116
|
+
// by their abscissa.
|
|
117
|
+
// Every pair (v_2i, v_{2i + 1}) of vertices defines a horizontal edge.
|
|
118
|
+
// So for every vertical edge, we're going to add the two vertical edges
|
|
119
|
+
// which are connected to it through a horizontal edge.
|
|
120
|
+
edges.sort((a, b) => a[1] - b[1] || a[0] - b[0]);
|
|
121
|
+
for (let i = 0, ii = edges.length; i < ii; i += 2) {
|
|
122
|
+
const edge1 = edges[i][2];
|
|
123
|
+
const edge2 = edges[i + 1][2];
|
|
124
|
+
edge1.push(edge2);
|
|
125
|
+
edge2.push(edge1);
|
|
126
|
+
allEdges.add(edge1);
|
|
127
|
+
allEdges.add(edge2);
|
|
128
|
+
}
|
|
129
|
+
const outlines = [];
|
|
130
|
+
let outline;
|
|
131
|
+
while (allEdges.size > 0) {
|
|
132
|
+
const edge = allEdges.values().next().value;
|
|
133
|
+
let [x, y1, y2, edge1, edge2] = edge;
|
|
134
|
+
allEdges.delete(edge);
|
|
135
|
+
let lastPointX = x;
|
|
136
|
+
let lastPointY = y1;
|
|
137
|
+
outline = [x, y2];
|
|
138
|
+
outlines.push(outline);
|
|
139
|
+
while (true) {
|
|
140
|
+
let e;
|
|
141
|
+
if (allEdges.has(edge1)) {
|
|
142
|
+
e = edge1;
|
|
143
|
+
}
|
|
144
|
+
else if (allEdges.has(edge2)) {
|
|
145
|
+
e = edge2;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
allEdges.delete(e);
|
|
151
|
+
[x, y1, y2, edge1, edge2] = e;
|
|
152
|
+
if (lastPointX !== x) {
|
|
153
|
+
outline.push(lastPointX, lastPointY, x, lastPointY === y1 ? y1 : y2);
|
|
154
|
+
lastPointX = x;
|
|
155
|
+
}
|
|
156
|
+
lastPointY = lastPointY === y1 ? y2 : y1;
|
|
157
|
+
}
|
|
158
|
+
outline.push(lastPointX, lastPointY);
|
|
159
|
+
}
|
|
160
|
+
return new HighlightOutline(outlines, __classPrivateFieldGet(this, _Outliner_box, "f"));
|
|
161
|
+
}, _Outliner_binarySearch = function _Outliner_binarySearch(y) {
|
|
162
|
+
const array = __classPrivateFieldGet(this, _Outliner_intervals, "f");
|
|
163
|
+
let start = 0;
|
|
164
|
+
let end = array.length - 1;
|
|
165
|
+
while (start <= end) {
|
|
166
|
+
const middle = (start + end) >> 1;
|
|
167
|
+
const y1 = array[middle][0];
|
|
168
|
+
if (y1 === y) {
|
|
169
|
+
return middle;
|
|
170
|
+
}
|
|
171
|
+
if (y1 < y) {
|
|
172
|
+
start = middle + 1;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
end = middle - 1;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return end + 1;
|
|
179
|
+
}, _Outliner_insert = function _Outliner_insert([, y1, y2]) {
|
|
180
|
+
const index = __classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_binarySearch).call(this, y1);
|
|
181
|
+
__classPrivateFieldGet(this, _Outliner_intervals, "f").splice(index, 0, [y1, y2]);
|
|
182
|
+
}, _Outliner_remove = function _Outliner_remove([, y1, y2]) {
|
|
183
|
+
const index = __classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_binarySearch).call(this, y1);
|
|
184
|
+
for (let i = index; i < __classPrivateFieldGet(this, _Outliner_intervals, "f").length; i++) {
|
|
185
|
+
const [start, end] = __classPrivateFieldGet(this, _Outliner_intervals, "f")[i];
|
|
186
|
+
if (start !== y1) {
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
if (start === y1 && end === y2) {
|
|
190
|
+
__classPrivateFieldGet(this, _Outliner_intervals, "f").splice(i, 1);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
195
|
+
const [start, end] = __classPrivateFieldGet(this, _Outliner_intervals, "f")[i];
|
|
196
|
+
if (start !== y1) {
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
if (start === y1 && end === y2) {
|
|
200
|
+
__classPrivateFieldGet(this, _Outliner_intervals, "f").splice(i, 1);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}, _Outliner_breakEdge = function _Outliner_breakEdge(edge) {
|
|
205
|
+
const [x, y1, y2] = edge;
|
|
206
|
+
const results = [[x, y1, y2]];
|
|
207
|
+
const index = __classPrivateFieldGet(this, _Outliner_instances, "m", _Outliner_binarySearch).call(this, y2);
|
|
208
|
+
for (let i = 0; i < index; i++) {
|
|
209
|
+
const [start, end] = __classPrivateFieldGet(this, _Outliner_intervals, "f")[i];
|
|
210
|
+
for (let j = 0, jj = results.length; j < jj; j++) {
|
|
211
|
+
const [, y3, y4] = results[j];
|
|
212
|
+
if (end <= y3 || y4 <= start) {
|
|
213
|
+
// There is no intersection between the interval and the edge, hence
|
|
214
|
+
// we keep it as is.
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (y3 >= start) {
|
|
218
|
+
if (y4 > end) {
|
|
219
|
+
results[j][1] = end;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
if (jj === 1) {
|
|
223
|
+
return [];
|
|
224
|
+
}
|
|
225
|
+
// The edge is included in the interval, hence we remove it.
|
|
226
|
+
results.splice(j, 1);
|
|
227
|
+
j--;
|
|
228
|
+
jj--;
|
|
229
|
+
}
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
results[j][2] = start;
|
|
233
|
+
if (y4 > end) {
|
|
234
|
+
results.push([x, end, y4]);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return results;
|
|
239
|
+
};
|
|
240
|
+
class Outline {
|
|
241
|
+
/**
|
|
242
|
+
* @returns {string} The SVG path of the outline.
|
|
243
|
+
*/
|
|
244
|
+
toSVGPath() {
|
|
245
|
+
throw new Error("Abstract method `toSVGPath` must be implemented.");
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* @type {Object|null} The bounding box of the outline.
|
|
249
|
+
*/
|
|
250
|
+
get box() {
|
|
251
|
+
throw new Error("Abstract getter `box` must be implemented.");
|
|
252
|
+
}
|
|
253
|
+
// serialize() {
|
|
254
|
+
// serialize(_bbox, _rotation) {
|
|
255
|
+
serialize([blX, blY, trX, trY]) {
|
|
256
|
+
// throw new Error("Abstract method `serialize` must be implemented.");
|
|
257
|
+
if (!blX || !blY || !trX || !trY) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
get free() {
|
|
262
|
+
return this instanceof FreeHighlightOutline;
|
|
263
|
+
// return false;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
class HighlightOutline extends Outline {
|
|
267
|
+
constructor(outlines, box) {
|
|
268
|
+
super();
|
|
269
|
+
_HighlightOutline_box.set(this, void 0);
|
|
270
|
+
_HighlightOutline_outlines.set(this, void 0);
|
|
271
|
+
__classPrivateFieldSet(this, _HighlightOutline_outlines, outlines, "f");
|
|
272
|
+
__classPrivateFieldSet(this, _HighlightOutline_box, box, "f");
|
|
273
|
+
}
|
|
274
|
+
toSVGPath() {
|
|
275
|
+
const buffer = [];
|
|
276
|
+
for (const polygon of __classPrivateFieldGet(this, _HighlightOutline_outlines, "f")) {
|
|
277
|
+
let [prevX, prevY] = polygon;
|
|
278
|
+
buffer.push(`M${prevX} ${prevY}`);
|
|
279
|
+
for (let i = 2; i < polygon.length; i += 2) {
|
|
280
|
+
const x = polygon[i];
|
|
281
|
+
const y = polygon[i + 1];
|
|
282
|
+
if (x === prevX) {
|
|
283
|
+
buffer.push(`V${y}`);
|
|
284
|
+
prevY = y;
|
|
285
|
+
}
|
|
286
|
+
else if (y === prevY) {
|
|
287
|
+
buffer.push(`H${x}`);
|
|
288
|
+
prevX = x;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
buffer.push("Z");
|
|
292
|
+
}
|
|
293
|
+
return buffer.join(" ");
|
|
294
|
+
}
|
|
295
|
+
/*
|
|
296
|
+
* Serialize the outlines into the PDF page coordinate system.
|
|
297
|
+
* @param {Array<number>} _bbox - the bounding box of the annotation.
|
|
298
|
+
* @param {number} _rotation - the rotation of the annotation.
|
|
299
|
+
* @returns {Array<Array<number>>}
|
|
300
|
+
*/
|
|
301
|
+
// serialize([blX, blY, trX, trY], _rotation) {
|
|
302
|
+
serialize([blX, blY, trX, trY]) {
|
|
303
|
+
const outlines = [];
|
|
304
|
+
const width = trX - blX;
|
|
305
|
+
const height = trY - blY;
|
|
306
|
+
for (const outline of __classPrivateFieldGet(this, _HighlightOutline_outlines, "f")) {
|
|
307
|
+
const points = new Array(outline.length);
|
|
308
|
+
for (let i = 0; i < outline.length; i += 2) {
|
|
309
|
+
points[i] = blX + outline[i] * width;
|
|
310
|
+
points[i + 1] = trY - outline[i + 1] * height;
|
|
311
|
+
}
|
|
312
|
+
outlines.push(points);
|
|
313
|
+
}
|
|
314
|
+
return outlines;
|
|
315
|
+
}
|
|
316
|
+
get box() {
|
|
317
|
+
return __classPrivateFieldGet(this, _HighlightOutline_box, "f");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
_HighlightOutline_box = new WeakMap(), _HighlightOutline_outlines = new WeakMap();
|
|
321
|
+
class FreeOutliner {
|
|
322
|
+
constructor({ x, y }, box, scaleFactor, thickness, isLTR, innerMargin = 0) {
|
|
323
|
+
_FreeOutliner_instances.add(this);
|
|
324
|
+
_FreeOutliner_box.set(this, void 0);
|
|
325
|
+
_FreeOutliner_bottom.set(this, []);
|
|
326
|
+
_FreeOutliner_innerMargin.set(this, void 0);
|
|
327
|
+
_FreeOutliner_isLTR.set(this, void 0);
|
|
328
|
+
_FreeOutliner_top.set(this, []);
|
|
329
|
+
// The first 6 elements are the last 3 points of the top part of the outline.
|
|
330
|
+
// The next 6 elements are the last 3 points of the line.
|
|
331
|
+
// The next 6 elements are the last 3 points of the bottom part of the
|
|
332
|
+
// outline.
|
|
333
|
+
// We track the last 3 points in order to be able to:
|
|
334
|
+
// - compute the normal of the line,
|
|
335
|
+
// - compute the control points of the quadratic Bézier curve.
|
|
336
|
+
_FreeOutliner_last.set(this, new Float64Array(18));
|
|
337
|
+
_FreeOutliner_lastX.set(this, void 0);
|
|
338
|
+
_FreeOutliner_lastY.set(this, void 0);
|
|
339
|
+
_FreeOutliner_min.set(this, void 0);
|
|
340
|
+
_FreeOutliner_min_dist.set(this, void 0);
|
|
341
|
+
_FreeOutliner_scaleFactor.set(this, void 0);
|
|
342
|
+
_FreeOutliner_thickness.set(this, void 0);
|
|
343
|
+
_FreeOutliner_points.set(this, []);
|
|
344
|
+
__classPrivateFieldSet(this, _FreeOutliner_box, box, "f");
|
|
345
|
+
__classPrivateFieldSet(this, _FreeOutliner_thickness, thickness * scaleFactor, "f");
|
|
346
|
+
__classPrivateFieldSet(this, _FreeOutliner_isLTR, isLTR, "f");
|
|
347
|
+
__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([NaN, NaN, NaN, NaN, x, y], 6);
|
|
348
|
+
__classPrivateFieldSet(this, _FreeOutliner_innerMargin, innerMargin, "f");
|
|
349
|
+
__classPrivateFieldSet(this, _FreeOutliner_min_dist, __classPrivateFieldGet(_a, _a, "f", _FreeOutliner_MIN_DIST) * scaleFactor, "f");
|
|
350
|
+
__classPrivateFieldSet(this, _FreeOutliner_min, __classPrivateFieldGet(_a, _a, "f", _FreeOutliner_MIN) * scaleFactor, "f");
|
|
351
|
+
__classPrivateFieldSet(this, _FreeOutliner_scaleFactor, scaleFactor, "f");
|
|
352
|
+
__classPrivateFieldGet(this, _FreeOutliner_points, "f").push(x, y);
|
|
353
|
+
}
|
|
354
|
+
get free() {
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
isEmpty() {
|
|
358
|
+
// When we add a second point then this.#last.slice(6) will be something
|
|
359
|
+
// like [NaN, NaN, firstX, firstY, secondX, secondY,...] so having a NaN
|
|
360
|
+
// at index 8 means that we've only one point.
|
|
361
|
+
return isNaN(__classPrivateFieldGet(this, _FreeOutliner_last, "f")[8]);
|
|
362
|
+
}
|
|
363
|
+
add({ x, y }) {
|
|
364
|
+
var _b;
|
|
365
|
+
__classPrivateFieldSet(this, _FreeOutliner_lastX, x, "f");
|
|
366
|
+
__classPrivateFieldSet(this, _FreeOutliner_lastY, y, "f");
|
|
367
|
+
const [layerX, layerY, layerWidth, layerHeight] = __classPrivateFieldGet(this, _FreeOutliner_box, "f");
|
|
368
|
+
let [x1, y1, x2, y2] = __classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(8, 12);
|
|
369
|
+
const diffX = x - x2;
|
|
370
|
+
const diffY = y - y2;
|
|
371
|
+
const d = Math.hypot(diffX, diffY);
|
|
372
|
+
if (d < __classPrivateFieldGet(this, _FreeOutliner_min, "f")) {
|
|
373
|
+
// The idea is to avoid garbage points around the last point.
|
|
374
|
+
// When the points are too close, it just leads to bad normal vectors and
|
|
375
|
+
// control points.
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
const diffD = d - __classPrivateFieldGet(this, _FreeOutliner_min_dist, "f");
|
|
379
|
+
const K = diffD / d;
|
|
380
|
+
const shiftX = K * diffX;
|
|
381
|
+
const shiftY = K * diffY;
|
|
382
|
+
// We update the last 3 points of the line.
|
|
383
|
+
let x0 = x1;
|
|
384
|
+
let y0 = y1;
|
|
385
|
+
x1 = x2;
|
|
386
|
+
y1 = y2;
|
|
387
|
+
x2 += shiftX;
|
|
388
|
+
y2 += shiftY;
|
|
389
|
+
// We keep track of the points in order to be able to compute the focus
|
|
390
|
+
// outline.
|
|
391
|
+
(_b = __classPrivateFieldGet(this, _FreeOutliner_points, "f")) === null || _b === void 0 ? void 0 : _b.push(x, y);
|
|
392
|
+
// Create the normal unit vector.
|
|
393
|
+
// |(shiftX, shiftY)| = |K| * |(diffX, diffY)| = |K| * d = diffD.
|
|
394
|
+
const nX = -shiftY / diffD;
|
|
395
|
+
const nY = shiftX / diffD;
|
|
396
|
+
const thX = nX * __classPrivateFieldGet(this, _FreeOutliner_thickness, "f");
|
|
397
|
+
const thY = nY * __classPrivateFieldGet(this, _FreeOutliner_thickness, "f");
|
|
398
|
+
__classPrivateFieldGet(this, _FreeOutliner_last, "f").set(__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(2, 8), 0);
|
|
399
|
+
__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x2 + thX, y2 + thY], 4);
|
|
400
|
+
__classPrivateFieldGet(this, _FreeOutliner_last, "f").set(__classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(14, 18), 12);
|
|
401
|
+
__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x2 - thX, y2 - thY], 16);
|
|
402
|
+
if (isNaN(__classPrivateFieldGet(this, _FreeOutliner_last, "f")[6])) {
|
|
403
|
+
if (__classPrivateFieldGet(this, _FreeOutliner_top, "f").length === 0) {
|
|
404
|
+
__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x1 + thX, y1 + thY], 2);
|
|
405
|
+
__classPrivateFieldGet(this, _FreeOutliner_top, "f").push(NaN, NaN, NaN, NaN, (x1 + thX - layerX) / layerWidth, (y1 + thY - layerY) / layerHeight);
|
|
406
|
+
__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x1 - thX, y1 - thY], 14);
|
|
407
|
+
__classPrivateFieldGet(this, _FreeOutliner_bottom, "f").push(NaN, NaN, NaN, NaN, (x1 - thX - layerX) / layerWidth, (y1 - thY - layerY) / layerHeight);
|
|
408
|
+
}
|
|
409
|
+
__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x0, y0, x1, y1, x2, y2], 6);
|
|
410
|
+
return !this.isEmpty();
|
|
411
|
+
}
|
|
412
|
+
__classPrivateFieldGet(this, _FreeOutliner_last, "f").set([x0, y0, x1, y1, x2, y2], 6);
|
|
413
|
+
const angle = Math.abs(Math.atan2(y0 - y1, x0 - x1) - Math.atan2(shiftY, shiftX));
|
|
414
|
+
if (angle < Math.PI / 2) {
|
|
415
|
+
// In order to avoid some possible artifacts, we're going to use the a
|
|
416
|
+
// straight line instead of a quadratic Bézier curve.
|
|
417
|
+
[x1, y1, x2, y2] = __classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(2, 6);
|
|
418
|
+
__classPrivateFieldGet(this, _FreeOutliner_top, "f").push(NaN, NaN, NaN, NaN, ((x1 + x2) / 2 - layerX) / layerWidth, ((y1 + y2) / 2 - layerY) / layerHeight);
|
|
419
|
+
[x1, y1, x0, y0] = __classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(14, 18);
|
|
420
|
+
__classPrivateFieldGet(this, _FreeOutliner_bottom, "f").push(NaN, NaN, NaN, NaN, ((x0 + x1) / 2 - layerX) / layerWidth, ((y0 + y1) / 2 - layerY) / layerHeight);
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
// Control points and the final point for the quadratic Bézier curve.
|
|
424
|
+
[x0, y0, x1, y1, x2, y2] = __classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(0, 6);
|
|
425
|
+
__classPrivateFieldGet(this, _FreeOutliner_top, "f").push(((x0 + 5 * x1) / 6 - layerX) / layerWidth, ((y0 + 5 * y1) / 6 - layerY) / layerHeight, ((5 * x1 + x2) / 6 - layerX) / layerWidth, ((5 * y1 + y2) / 6 - layerY) / layerHeight, ((x1 + x2) / 2 - layerX) / layerWidth, ((y1 + y2) / 2 - layerY) / layerHeight);
|
|
426
|
+
[x2, y2, x1, y1, x0, y0] = __classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(12, 18);
|
|
427
|
+
__classPrivateFieldGet(this, _FreeOutliner_bottom, "f").push(((x0 + 5 * x1) / 6 - layerX) / layerWidth, ((y0 + 5 * y1) / 6 - layerY) / layerHeight, ((5 * x1 + x2) / 6 - layerX) / layerWidth, ((5 * y1 + y2) / 6 - layerY) / layerHeight, ((x1 + x2) / 2 - layerX) / layerWidth, ((y1 + y2) / 2 - layerY) / layerHeight);
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
toSVGPath() {
|
|
431
|
+
if (this.isEmpty()) {
|
|
432
|
+
// We've only one point.
|
|
433
|
+
return "";
|
|
434
|
+
}
|
|
435
|
+
const top = __classPrivateFieldGet(this, _FreeOutliner_top, "f");
|
|
436
|
+
const bottom = __classPrivateFieldGet(this, _FreeOutliner_bottom, "f");
|
|
437
|
+
const lastTop = __classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(4, 6);
|
|
438
|
+
const lastBottom = __classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(16, 18);
|
|
439
|
+
const [x, y, width, height] = __classPrivateFieldGet(this, _FreeOutliner_box, "f");
|
|
440
|
+
const [lastTopX, lastTopY, lastBottomX, lastBottomY] = __classPrivateFieldGet(this, _FreeOutliner_instances, "m", _FreeOutliner_getLastCoords).call(this);
|
|
441
|
+
if (isNaN(__classPrivateFieldGet(this, _FreeOutliner_last, "f")[6]) && !this.isEmpty()) {
|
|
442
|
+
// We've only two points.
|
|
443
|
+
return `M${(__classPrivateFieldGet(this, _FreeOutliner_last, "f")[2] - x) / width} ${(__classPrivateFieldGet(this, _FreeOutliner_last, "f")[3] - y) / height} L${(__classPrivateFieldGet(this, _FreeOutliner_last, "f")[4] - x) / width} ${(__classPrivateFieldGet(this, _FreeOutliner_last, "f")[5] - y) / height} L${lastTopX} ${lastTopY} L${lastBottomX} ${lastBottomY} L${(__classPrivateFieldGet(this, _FreeOutliner_last, "f")[16] - x) / width} ${(__classPrivateFieldGet(this, _FreeOutliner_last, "f")[17] - y) / height} L${(__classPrivateFieldGet(this, _FreeOutliner_last, "f")[14] - x) / width} ${(__classPrivateFieldGet(this, _FreeOutliner_last, "f")[15] - y) / height} Z`;
|
|
444
|
+
}
|
|
445
|
+
const buffer = [];
|
|
446
|
+
buffer.push(`M${top[4]} ${top[5]}`);
|
|
447
|
+
for (let i = 6; i < top.length; i += 6) {
|
|
448
|
+
if (isNaN(top[i])) {
|
|
449
|
+
buffer.push(`L${top[i + 4]} ${top[i + 5]}`);
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
buffer.push(`C${top[i]} ${top[i + 1]} ${top[i + 2]} ${top[i + 3]} ${top[i + 4]} ${top[i + 5]}`);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
buffer.push(`L${(lastTop[0] - x) / width} ${(lastTop[1] - y) / height} L${lastTopX} ${lastTopY} L${lastBottomX} ${lastBottomY} L${(lastBottom[0] - x) / width} ${(lastBottom[1] - y) / height}`);
|
|
456
|
+
for (let i = bottom.length - 6; i >= 6; i -= 6) {
|
|
457
|
+
if (isNaN(bottom[i])) {
|
|
458
|
+
buffer.push(`L${bottom[i + 4]} ${bottom[i + 5]}`);
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
buffer.push(`C${bottom[i]} ${bottom[i + 1]} ${bottom[i + 2]} ${bottom[i + 3]} ${bottom[i + 4]} ${bottom[i + 5]}`);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
buffer.push(`L${bottom[4]} ${bottom[5]} Z`);
|
|
465
|
+
return buffer.join(" ");
|
|
466
|
+
}
|
|
467
|
+
getOutlines() {
|
|
468
|
+
var _b, _c;
|
|
469
|
+
const top = __classPrivateFieldGet(this, _FreeOutliner_top, "f");
|
|
470
|
+
const bottom = __classPrivateFieldGet(this, _FreeOutliner_bottom, "f");
|
|
471
|
+
const last = __classPrivateFieldGet(this, _FreeOutliner_last, "f");
|
|
472
|
+
const lastTop = last.subarray(4, 6);
|
|
473
|
+
const lastBottom = last.subarray(16, 18);
|
|
474
|
+
const [layerX, layerY, layerWidth, layerHeight] = __classPrivateFieldGet(this, _FreeOutliner_box, "f");
|
|
475
|
+
const points = new Float64Array(((_c = (_b = __classPrivateFieldGet(this, _FreeOutliner_points, "f")) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) + 2);
|
|
476
|
+
for (let i = 0, ii = points.length - 2; i < ii; i += 2) {
|
|
477
|
+
points[i] = (__classPrivateFieldGet(this, _FreeOutliner_points, "f")[i] - layerX) / layerWidth;
|
|
478
|
+
points[i + 1] = (__classPrivateFieldGet(this, _FreeOutliner_points, "f")[i + 1] - layerY) / layerHeight;
|
|
479
|
+
}
|
|
480
|
+
points[points.length - 2] = (__classPrivateFieldGet(this, _FreeOutliner_lastX, "f") - layerX) / layerWidth;
|
|
481
|
+
points[points.length - 1] = (__classPrivateFieldGet(this, _FreeOutliner_lastY, "f") - layerY) / layerHeight;
|
|
482
|
+
const [lastTopX, lastTopY, lastBottomX, lastBottomY] = __classPrivateFieldGet(this, _FreeOutliner_instances, "m", _FreeOutliner_getLastCoords).call(this);
|
|
483
|
+
if (isNaN(last[6]) && !this.isEmpty()) {
|
|
484
|
+
// We've only two points.
|
|
485
|
+
const outlineObj = new Float64Array(36);
|
|
486
|
+
outlineObj.set([
|
|
487
|
+
NaN,
|
|
488
|
+
NaN,
|
|
489
|
+
NaN,
|
|
490
|
+
NaN,
|
|
491
|
+
(last[2] - layerX) / layerWidth,
|
|
492
|
+
(last[3] - layerY) / layerHeight,
|
|
493
|
+
NaN,
|
|
494
|
+
NaN,
|
|
495
|
+
NaN,
|
|
496
|
+
NaN,
|
|
497
|
+
(last[4] - layerX) / layerWidth,
|
|
498
|
+
(last[5] - layerY) / layerHeight,
|
|
499
|
+
NaN,
|
|
500
|
+
NaN,
|
|
501
|
+
NaN,
|
|
502
|
+
NaN,
|
|
503
|
+
lastTopX,
|
|
504
|
+
lastTopY,
|
|
505
|
+
NaN,
|
|
506
|
+
NaN,
|
|
507
|
+
NaN,
|
|
508
|
+
NaN,
|
|
509
|
+
lastBottomX,
|
|
510
|
+
lastBottomY,
|
|
511
|
+
NaN,
|
|
512
|
+
NaN,
|
|
513
|
+
NaN,
|
|
514
|
+
NaN,
|
|
515
|
+
(last[16] - layerX) / layerWidth,
|
|
516
|
+
(last[17] - layerY) / layerHeight,
|
|
517
|
+
NaN,
|
|
518
|
+
NaN,
|
|
519
|
+
NaN,
|
|
520
|
+
NaN,
|
|
521
|
+
(last[14] - layerX) / layerWidth,
|
|
522
|
+
(last[15] - layerY) / layerHeight,
|
|
523
|
+
], 0);
|
|
524
|
+
return new FreeHighlightOutline(outlineObj, points, __classPrivateFieldGet(this, _FreeOutliner_box, "f"), __classPrivateFieldGet(this, _FreeOutliner_scaleFactor, "f"), __classPrivateFieldGet(this, _FreeOutliner_innerMargin, "f"), __classPrivateFieldGet(this, _FreeOutliner_isLTR, "f"));
|
|
525
|
+
}
|
|
526
|
+
const outline = new Float64Array(__classPrivateFieldGet(this, _FreeOutliner_top, "f").length + 24 + __classPrivateFieldGet(this, _FreeOutliner_bottom, "f").length);
|
|
527
|
+
let N = top.length;
|
|
528
|
+
for (let i = 0; i < N; i += 2) {
|
|
529
|
+
if (isNaN(top[i])) {
|
|
530
|
+
outline[i] = outline[i + 1] = NaN;
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
outline[i] = top[i];
|
|
534
|
+
outline[i + 1] = top[i + 1];
|
|
535
|
+
}
|
|
536
|
+
outline.set([
|
|
537
|
+
NaN,
|
|
538
|
+
NaN,
|
|
539
|
+
NaN,
|
|
540
|
+
NaN,
|
|
541
|
+
(lastTop[0] - layerX) / layerWidth,
|
|
542
|
+
(lastTop[1] - layerY) / layerHeight,
|
|
543
|
+
NaN,
|
|
544
|
+
NaN,
|
|
545
|
+
NaN,
|
|
546
|
+
NaN,
|
|
547
|
+
lastTopX,
|
|
548
|
+
lastTopY,
|
|
549
|
+
NaN,
|
|
550
|
+
NaN,
|
|
551
|
+
NaN,
|
|
552
|
+
NaN,
|
|
553
|
+
lastBottomX,
|
|
554
|
+
lastBottomY,
|
|
555
|
+
NaN,
|
|
556
|
+
NaN,
|
|
557
|
+
NaN,
|
|
558
|
+
NaN,
|
|
559
|
+
(lastBottom[0] - layerX) / layerWidth,
|
|
560
|
+
(lastBottom[1] - layerY) / layerHeight,
|
|
561
|
+
], N);
|
|
562
|
+
N += 24;
|
|
563
|
+
for (let i = bottom.length - 6; i >= 6; i -= 6) {
|
|
564
|
+
for (let j = 0; j < 6; j += 2) {
|
|
565
|
+
if (isNaN(bottom[i + j])) {
|
|
566
|
+
outline[N] = outline[N + 1] = NaN;
|
|
567
|
+
N += 2;
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
outline[N] = bottom[i + j];
|
|
571
|
+
outline[N + 1] = bottom[i + j + 1];
|
|
572
|
+
N += 2;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
outline.set([NaN, NaN, NaN, NaN, bottom[4], bottom[5]], N);
|
|
576
|
+
return new FreeHighlightOutline(outline, points, __classPrivateFieldGet(this, _FreeOutliner_box, "f"), __classPrivateFieldGet(this, _FreeOutliner_scaleFactor, "f"), __classPrivateFieldGet(this, _FreeOutliner_innerMargin, "f"), __classPrivateFieldGet(this, _FreeOutliner_isLTR, "f"));
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
_a = FreeOutliner, _FreeOutliner_box = new WeakMap(), _FreeOutliner_bottom = new WeakMap(), _FreeOutliner_innerMargin = new WeakMap(), _FreeOutliner_isLTR = new WeakMap(), _FreeOutliner_top = new WeakMap(), _FreeOutliner_last = new WeakMap(), _FreeOutliner_lastX = new WeakMap(), _FreeOutliner_lastY = new WeakMap(), _FreeOutliner_min = new WeakMap(), _FreeOutliner_min_dist = new WeakMap(), _FreeOutliner_scaleFactor = new WeakMap(), _FreeOutliner_thickness = new WeakMap(), _FreeOutliner_points = new WeakMap(), _FreeOutliner_instances = new WeakSet(), _FreeOutliner_getLastCoords = function _FreeOutliner_getLastCoords() {
|
|
580
|
+
const lastTop = __classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(4, 6);
|
|
581
|
+
const lastBottom = __classPrivateFieldGet(this, _FreeOutliner_last, "f").subarray(16, 18);
|
|
582
|
+
const [x, y, width, height] = __classPrivateFieldGet(this, _FreeOutliner_box, "f");
|
|
583
|
+
return [
|
|
584
|
+
(__classPrivateFieldGet(this, _FreeOutliner_lastX, "f") + (lastTop[0] - lastBottom[0]) / 2 - x) / width,
|
|
585
|
+
(__classPrivateFieldGet(this, _FreeOutliner_lastY, "f") + (lastTop[1] - lastBottom[1]) / 2 - y) / height,
|
|
586
|
+
(__classPrivateFieldGet(this, _FreeOutliner_lastX, "f") + (lastBottom[0] - lastTop[0]) / 2 - x) / width,
|
|
587
|
+
(__classPrivateFieldGet(this, _FreeOutliner_lastY, "f") + (lastBottom[1] - lastTop[1]) / 2 - y) / height,
|
|
588
|
+
];
|
|
589
|
+
};
|
|
590
|
+
_FreeOutliner_MIN_DIST = { value: 8 };
|
|
591
|
+
_FreeOutliner_MIN_DIFF = { value: 2 };
|
|
592
|
+
_FreeOutliner_MIN = { value: __classPrivateFieldGet(_a, _a, "f", _FreeOutliner_MIN_DIST) + __classPrivateFieldGet(_a, _a, "f", _FreeOutliner_MIN_DIFF) };
|
|
593
|
+
class FreeHighlightOutline extends Outline {
|
|
594
|
+
constructor(outline, points, box, scaleFactor, innerMargin, isLTR) {
|
|
595
|
+
super();
|
|
596
|
+
_FreeHighlightOutline_instances.add(this);
|
|
597
|
+
_FreeHighlightOutline_box.set(this, void 0);
|
|
598
|
+
_FreeHighlightOutline_bbox.set(this, null);
|
|
599
|
+
_FreeHighlightOutline_innerMargin.set(this, void 0);
|
|
600
|
+
_FreeHighlightOutline_isLTR.set(this, void 0);
|
|
601
|
+
_FreeHighlightOutline_points.set(this, void 0);
|
|
602
|
+
_FreeHighlightOutline_scaleFactor.set(this, void 0);
|
|
603
|
+
_FreeHighlightOutline_outline.set(this, void 0);
|
|
604
|
+
__classPrivateFieldSet(this, _FreeHighlightOutline_outline, outline, "f");
|
|
605
|
+
__classPrivateFieldSet(this, _FreeHighlightOutline_points, points, "f");
|
|
606
|
+
__classPrivateFieldSet(this, _FreeHighlightOutline_box, box, "f");
|
|
607
|
+
__classPrivateFieldSet(this, _FreeHighlightOutline_scaleFactor, scaleFactor, "f");
|
|
608
|
+
__classPrivateFieldSet(this, _FreeHighlightOutline_innerMargin, innerMargin, "f");
|
|
609
|
+
__classPrivateFieldSet(this, _FreeHighlightOutline_isLTR, isLTR, "f");
|
|
610
|
+
__classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_computeMinMax).call(this, isLTR);
|
|
611
|
+
const { x, y, width, height } = __classPrivateFieldGet(this, _FreeHighlightOutline_bbox, "f");
|
|
612
|
+
for (let i = 0, ii = outline.length; i < ii; i += 2) {
|
|
613
|
+
outline[i] = (outline[i] - x) / width;
|
|
614
|
+
outline[i + 1] = (outline[i + 1] - y) / height;
|
|
615
|
+
}
|
|
616
|
+
for (let i = 0, ii = points.length; i < ii; i += 2) {
|
|
617
|
+
points[i] = (points[i] - x) / width;
|
|
618
|
+
points[i + 1] = (points[i + 1] - y) / height;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
toSVGPath() {
|
|
622
|
+
const buffer = [`M${__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[4]} ${__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[5]}`];
|
|
623
|
+
for (let i = 6, ii = __classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f").length; i < ii; i += 6) {
|
|
624
|
+
if (isNaN(__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i])) {
|
|
625
|
+
buffer.push(`L${__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 4]} ${__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 5]}`);
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
buffer.push(`C${__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i]} ${__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 1]} ${__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 2]} ${__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 3]} ${__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 4]} ${__classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f")[i + 5]}`);
|
|
629
|
+
}
|
|
630
|
+
buffer.push("Z");
|
|
631
|
+
return buffer.join(" ");
|
|
632
|
+
}
|
|
633
|
+
// @ts-expect-error(TS:2556)
|
|
634
|
+
serialize([blX, blY, trX, trY], rotation) {
|
|
635
|
+
const width = trX - blX;
|
|
636
|
+
const height = trY - blY;
|
|
637
|
+
let outline;
|
|
638
|
+
let points;
|
|
639
|
+
switch (rotation) {
|
|
640
|
+
case 0:
|
|
641
|
+
outline = __classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescale).call(this, __classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f"), blX, trY, width, -height);
|
|
642
|
+
points = __classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescale).call(this, __classPrivateFieldGet(this, _FreeHighlightOutline_points, "f"), blX, trY, width, -height);
|
|
643
|
+
break;
|
|
644
|
+
case 90:
|
|
645
|
+
outline = __classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescaleAndSwap).call(this, __classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f"), blX, blY, width, height);
|
|
646
|
+
points = __classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescaleAndSwap).call(this, __classPrivateFieldGet(this, _FreeHighlightOutline_points, "f"), blX, blY, width, height);
|
|
647
|
+
break;
|
|
648
|
+
case 180:
|
|
649
|
+
outline = __classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescale).call(this, __classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f"), trX, blY, -width, height);
|
|
650
|
+
points = __classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescale).call(this, __classPrivateFieldGet(this, _FreeHighlightOutline_points, "f"), trX, blY, -width, height);
|
|
651
|
+
break;
|
|
652
|
+
case 270:
|
|
653
|
+
outline = __classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescaleAndSwap).call(this, __classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f"), trX, trY, -width, -height);
|
|
654
|
+
points = __classPrivateFieldGet(this, _FreeHighlightOutline_instances, "m", _FreeHighlightOutline_rescaleAndSwap).call(this, __classPrivateFieldGet(this, _FreeHighlightOutline_points, "f"), trX, trY, -width, -height);
|
|
655
|
+
break;
|
|
656
|
+
default: break;
|
|
657
|
+
}
|
|
658
|
+
return { outline: Array.from(outline), points: [Array.from(points)] };
|
|
659
|
+
}
|
|
660
|
+
get box() {
|
|
661
|
+
return __classPrivateFieldGet(this, _FreeHighlightOutline_bbox, "f");
|
|
662
|
+
}
|
|
663
|
+
getNewOutline(thickness, innerMargin) {
|
|
664
|
+
// Build the outline of the highlight to use as the focus outline.
|
|
665
|
+
const { x, y, width, height } = __classPrivateFieldGet(this, _FreeHighlightOutline_bbox, "f");
|
|
666
|
+
const [layerX, layerY, layerWidth, layerHeight] = __classPrivateFieldGet(this, _FreeHighlightOutline_box, "f");
|
|
667
|
+
const sx = width * layerWidth;
|
|
668
|
+
const sy = height * layerHeight;
|
|
669
|
+
const tx = x * layerWidth + layerX;
|
|
670
|
+
const ty = y * layerHeight + layerY;
|
|
671
|
+
const outliner = new FreeOutliner({
|
|
672
|
+
x: __classPrivateFieldGet(this, _FreeHighlightOutline_points, "f")[0] * sx + tx,
|
|
673
|
+
y: __classPrivateFieldGet(this, _FreeHighlightOutline_points, "f")[1] * sy + ty,
|
|
674
|
+
}, __classPrivateFieldGet(this, _FreeHighlightOutline_box, "f"), __classPrivateFieldGet(this, _FreeHighlightOutline_scaleFactor, "f"), thickness, __classPrivateFieldGet(this, _FreeHighlightOutline_isLTR, "f"), innerMargin !== null && innerMargin !== void 0 ? innerMargin : __classPrivateFieldGet(this, _FreeHighlightOutline_innerMargin, "f"));
|
|
675
|
+
for (let i = 2; i < __classPrivateFieldGet(this, _FreeHighlightOutline_points, "f").length; i += 2) {
|
|
676
|
+
outliner.add({
|
|
677
|
+
x: __classPrivateFieldGet(this, _FreeHighlightOutline_points, "f")[i] * sx + tx,
|
|
678
|
+
y: __classPrivateFieldGet(this, _FreeHighlightOutline_points, "f")[i + 1] * sy + ty,
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
return outliner.getOutlines();
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
_FreeHighlightOutline_box = new WeakMap(), _FreeHighlightOutline_bbox = new WeakMap(), _FreeHighlightOutline_innerMargin = new WeakMap(), _FreeHighlightOutline_isLTR = new WeakMap(), _FreeHighlightOutline_points = new WeakMap(), _FreeHighlightOutline_scaleFactor = new WeakMap(), _FreeHighlightOutline_outline = new WeakMap(), _FreeHighlightOutline_instances = new WeakSet(), _FreeHighlightOutline_rescale = function _FreeHighlightOutline_rescale(src, tx, ty, sx, sy) {
|
|
685
|
+
const dest = new Float64Array(src.length);
|
|
686
|
+
for (let i = 0, ii = src.length; i < ii; i += 2) {
|
|
687
|
+
dest[i] = tx + src[i] * sx;
|
|
688
|
+
dest[i + 1] = ty + src[i + 1] * sy;
|
|
689
|
+
}
|
|
690
|
+
return dest;
|
|
691
|
+
}, _FreeHighlightOutline_rescaleAndSwap = function _FreeHighlightOutline_rescaleAndSwap(src, tx, ty, sx, sy) {
|
|
692
|
+
const dest = new Float64Array(src.length);
|
|
693
|
+
for (let i = 0, ii = src.length; i < ii; i += 2) {
|
|
694
|
+
dest[i] = tx + src[i + 1] * sx;
|
|
695
|
+
dest[i + 1] = ty + src[i] * sy;
|
|
696
|
+
}
|
|
697
|
+
return dest;
|
|
698
|
+
}, _FreeHighlightOutline_computeMinMax = function _FreeHighlightOutline_computeMinMax(isLTR) {
|
|
699
|
+
const outline = __classPrivateFieldGet(this, _FreeHighlightOutline_outline, "f");
|
|
700
|
+
let lastX = outline[4];
|
|
701
|
+
let lastY = outline[5];
|
|
702
|
+
let minX = lastX;
|
|
703
|
+
let minY = lastY;
|
|
704
|
+
let maxX = lastX;
|
|
705
|
+
let maxY = lastY;
|
|
706
|
+
let lastPointX = lastX;
|
|
707
|
+
let lastPointY = lastY;
|
|
708
|
+
const ltrCallback = isLTR ? Math.max : Math.min;
|
|
709
|
+
for (let i = 6, ii = outline.length; i < ii; i += 6) {
|
|
710
|
+
if (isNaN(outline[i])) {
|
|
711
|
+
minX = Math.min(minX, outline[i + 4]);
|
|
712
|
+
minY = Math.min(minY, outline[i + 5]);
|
|
713
|
+
maxX = Math.max(maxX, outline[i + 4]);
|
|
714
|
+
maxY = Math.max(maxY, outline[i + 5]);
|
|
715
|
+
if (lastPointY < outline[i + 5]) {
|
|
716
|
+
lastPointX = outline[i + 4];
|
|
717
|
+
lastPointY = outline[i + 5];
|
|
718
|
+
}
|
|
719
|
+
else if (lastPointY === outline[i + 5]) {
|
|
720
|
+
lastPointX = ltrCallback(lastPointX, outline[i + 4]);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
else {
|
|
724
|
+
const bbox = Util.bezierBoundingBox(lastX, lastY,
|
|
725
|
+
// @ts-expect-error(TS:2556)
|
|
726
|
+
...outline.slice(i, i + 6));
|
|
727
|
+
minX = Math.min(minX, bbox[0]);
|
|
728
|
+
minY = Math.min(minY, bbox[1]);
|
|
729
|
+
maxX = Math.max(maxX, bbox[2]);
|
|
730
|
+
maxY = Math.max(maxY, bbox[3]);
|
|
731
|
+
if (lastPointY < bbox[3]) {
|
|
732
|
+
lastPointX = bbox[2];
|
|
733
|
+
lastPointY = bbox[3];
|
|
734
|
+
}
|
|
735
|
+
else if (lastPointY === bbox[3]) {
|
|
736
|
+
lastPointX = ltrCallback(lastPointX, bbox[2]);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
lastX = outline[i + 4];
|
|
740
|
+
lastY = outline[i + 5];
|
|
741
|
+
}
|
|
742
|
+
const x = minX - __classPrivateFieldGet(this, _FreeHighlightOutline_innerMargin, "f"), y = minY - __classPrivateFieldGet(this, _FreeHighlightOutline_innerMargin, "f"), width = maxX - minX + 2 * __classPrivateFieldGet(this, _FreeHighlightOutline_innerMargin, "f"), height = maxY - minY + 2 * __classPrivateFieldGet(this, _FreeHighlightOutline_innerMargin, "f");
|
|
743
|
+
__classPrivateFieldSet(this, _FreeHighlightOutline_bbox, { x, y, width, height, lastPoint: [lastPointX, lastPointY] }, "f");
|
|
744
|
+
};
|
|
745
|
+
// export { FreeOutliner, Outliner };
|
|
746
|
+
export { FreeOutliner };
|
|
747
|
+
// export { Outliner };
|