@myrmidon/cadmus-core 13.0.1 → 20.0.0
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,1281 +1,688 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import * as i1 from
|
|
5
|
-
import { DialogService } from
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Flags matching mode.
|
|
9
|
-
*/
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Inject, Injectable, Pipe, inject } from "@angular/core";
|
|
3
|
+
import { map, take } from "rxjs";
|
|
4
|
+
import * as i1 from "@myrmidon/ngx-mat-tools";
|
|
5
|
+
import { DialogService } from "@myrmidon/ngx-mat-tools";
|
|
10
6
|
var FlagMatching;
|
|
11
|
-
(function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
FlagMatching[FlagMatching["bitsAllClear"] = 2] = "bitsAllClear";
|
|
18
|
-
FlagMatching[FlagMatching["bitsAnyClear"] = 3] = "bitsAnyClear";
|
|
7
|
+
(function(FlagMatching) {
|
|
8
|
+
FlagMatching[FlagMatching["none"] = -1] = "none";
|
|
9
|
+
FlagMatching[FlagMatching["bitsAllSet"] = 0] = "bitsAllSet";
|
|
10
|
+
FlagMatching[FlagMatching["bitsAnySet"] = 1] = "bitsAnySet";
|
|
11
|
+
FlagMatching[FlagMatching["bitsAllClear"] = 2] = "bitsAllClear";
|
|
12
|
+
FlagMatching[FlagMatching["bitsAnyClear"] = 3] = "bitsAnyClear";
|
|
19
13
|
})(FlagMatching || (FlagMatching = {}));
|
|
20
|
-
/**
|
|
21
|
-
* Data pin value type in a DataPinDefinition.
|
|
22
|
-
*/
|
|
23
14
|
var DataPinValueType;
|
|
24
|
-
(function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
(function(DataPinValueType) {
|
|
16
|
+
DataPinValueType[DataPinValueType["string"] = 0] = "string";
|
|
17
|
+
DataPinValueType[DataPinValueType["boolean"] = 1] = "boolean";
|
|
18
|
+
DataPinValueType[DataPinValueType["integer"] = 2] = "integer";
|
|
19
|
+
DataPinValueType[DataPinValueType["decimal"] = 3] = "decimal";
|
|
29
20
|
})(DataPinValueType || (DataPinValueType = {}));
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
toString() {
|
|
134
|
-
let s = `${this.y}.${this.x}`;
|
|
135
|
-
if (this.at && this.run) {
|
|
136
|
-
s += `@${this.at}`;
|
|
137
|
-
if (this.run !== 1) {
|
|
138
|
-
s += `x${this.run}`;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return s;
|
|
142
|
-
}
|
|
143
|
-
compareTo(other) {
|
|
144
|
-
if (this.y !== other.y) {
|
|
145
|
-
return this.y - other.y;
|
|
146
|
-
}
|
|
147
|
-
if (this.x !== other.x) {
|
|
148
|
-
return this.x - other.x;
|
|
149
|
-
}
|
|
150
|
-
if (this.at !== other.at) {
|
|
151
|
-
return this.at - other.at;
|
|
152
|
-
}
|
|
153
|
-
return this.run - other.run;
|
|
154
|
-
}
|
|
155
|
-
integralCompareTo(other) {
|
|
156
|
-
if (this.y !== other.y) {
|
|
157
|
-
return this.y - other.y;
|
|
158
|
-
}
|
|
159
|
-
if (this.x !== other.x) {
|
|
160
|
-
return this.x - other.x;
|
|
161
|
-
}
|
|
162
|
-
return 0;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
class TokenLocation {
|
|
167
|
-
primary;
|
|
168
|
-
secondary;
|
|
169
|
-
/**
|
|
170
|
-
* Parse the text representing a token-based location,
|
|
171
|
-
* which has the form "primary-secondary", or just "primary",
|
|
172
|
-
* where each of these points has the format required by
|
|
173
|
-
* TokenPoint.parse (e.g. Y.X or Y.X@AxR or Y.X@A, where R=1).
|
|
174
|
-
* @param text The text to parse.
|
|
175
|
-
*/
|
|
176
|
-
static parse(text) {
|
|
177
|
-
if (!text) {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
const pair = text.split('-', 2);
|
|
181
|
-
if (pair.length === 0) {
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
// if the primary point cannot be parsed, the whole location is invalid;
|
|
185
|
-
// returning a TokenLocation with a null primary here would violate the
|
|
186
|
-
// non-nullable TokenPoint type and crash later on any method that
|
|
187
|
-
// touches primary (toString, compareTo, overlaps...)
|
|
188
|
-
const primary = TokenPoint.parse(pair[0]);
|
|
189
|
-
if (!primary) {
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
return new TokenLocation(primary, pair.length > 1 ? TokenPoint.parse(pair[1]) || undefined : undefined);
|
|
193
|
-
}
|
|
194
|
-
constructor(primary, secondary) {
|
|
195
|
-
this.primary = primary;
|
|
196
|
-
this.secondary = secondary;
|
|
197
|
-
}
|
|
198
|
-
isRange() {
|
|
199
|
-
// note that != checks for both null and undefined, whereas !== does not
|
|
200
|
-
return this.secondary != null;
|
|
201
|
-
}
|
|
202
|
-
toString() {
|
|
203
|
-
return this.secondary
|
|
204
|
-
? `${this.primary.toString()}-${this.secondary.toString()}`
|
|
205
|
-
: this.primary.toString();
|
|
206
|
-
}
|
|
207
|
-
compareTo(other) {
|
|
208
|
-
const n1 = this.primary.compareTo(other.primary);
|
|
209
|
-
if (n1 !== 0) {
|
|
210
|
-
return n1;
|
|
211
|
-
}
|
|
212
|
-
if (this.secondary && other.secondary) {
|
|
213
|
-
return this.secondary.compareTo(other.secondary);
|
|
214
|
-
}
|
|
215
|
-
if (!this.secondary && !other.secondary) {
|
|
216
|
-
return 0;
|
|
217
|
-
}
|
|
218
|
-
return this.secondary ? 1 : -1;
|
|
219
|
-
}
|
|
220
|
-
overlaps(other) {
|
|
221
|
-
// empty coords never overlaps
|
|
222
|
-
if (!other.primary) {
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
// (in the following comments A=this and B=other)
|
|
226
|
-
// 1) if B is a point, cases are:
|
|
227
|
-
// 1.1. A is a point: A overlaps with B (both points) if they're equal.
|
|
228
|
-
// 1.2. A is a range: A (range) overlaps with B (point)
|
|
229
|
-
// when A-left is <= B-left and A-right is >= B-right.
|
|
230
|
-
if (other.secondary == null) {
|
|
231
|
-
return !this.secondary
|
|
232
|
-
? this.primary.integralCompareTo(other.primary) === 0
|
|
233
|
-
: this.primary.compareTo(other.primary) <= 0 &&
|
|
234
|
-
this.secondary.compareTo(other.primary) >= 0;
|
|
235
|
-
}
|
|
236
|
-
// 2) if B is a range, cases are:
|
|
237
|
-
// 2.1. A is a point: A (point) overlaps with B (range) when B-left <= A and
|
|
238
|
-
// B-right >= A
|
|
239
|
-
// 2.2. A is a range: A (range) overlaps with B (range)
|
|
240
|
-
// when B-right >= A-left and B-left <= A-right
|
|
241
|
-
return !this.secondary
|
|
242
|
-
? other.primary.compareTo(this.primary) <= 0 &&
|
|
243
|
-
other.secondary.compareTo(this.primary) >= 0
|
|
244
|
-
: other.secondary.compareTo(this.primary) >= 0 &&
|
|
245
|
-
other.primary.compareTo(this.secondary) <= 0;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Pending changes guard.
|
|
251
|
-
* @param component The component to check.
|
|
252
|
-
* @returns True if the user can deactivate the component, false otherwise.
|
|
253
|
-
*/
|
|
21
|
+
var TextRange = class TextRange {
|
|
22
|
+
start;
|
|
23
|
+
length;
|
|
24
|
+
static parse(text) {
|
|
25
|
+
if (!text) return null;
|
|
26
|
+
const m = (/* @__PURE__ */ new RegExp("(\\d+)(?:[×x](\\d+))?", "gm")).exec(text);
|
|
27
|
+
if (!m) return null;
|
|
28
|
+
return new TextRange(parseInt(m[1], 10), m[2] ? parseInt(m[2], 10) : 1);
|
|
29
|
+
}
|
|
30
|
+
constructor(start, length) {
|
|
31
|
+
if (start < 0) throw new RangeError("TextRange start less than 0");
|
|
32
|
+
if (length < 0) throw new RangeError("TextRange length less than 0");
|
|
33
|
+
this.start = start;
|
|
34
|
+
this.length = length;
|
|
35
|
+
}
|
|
36
|
+
end() {
|
|
37
|
+
const n = this.start + this.length;
|
|
38
|
+
return n > 0 ? n - 1 : 0;
|
|
39
|
+
}
|
|
40
|
+
isEqual(other) {
|
|
41
|
+
if (!other) return false;
|
|
42
|
+
return this.start === other.start && this.length === other.length;
|
|
43
|
+
}
|
|
44
|
+
toString() {
|
|
45
|
+
return this.length === 1 ? this.start.toString() : `${this.start}×${this.length}`;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var TokenPoint = class TokenPoint {
|
|
49
|
+
y;
|
|
50
|
+
x;
|
|
51
|
+
at;
|
|
52
|
+
run;
|
|
53
|
+
static parse(text) {
|
|
54
|
+
const m = (/* @__PURE__ */ new RegExp("^(\\d+)\\.(\\d+)(?:@(\\d+)(?:x(\\d+))?)?$", "g")).exec(text);
|
|
55
|
+
if (!m) return null;
|
|
56
|
+
const pt = new TokenPoint(parseInt(m[1], 10), parseInt(m[2], 10), m[3] ? parseInt(m[3], 10) : 0);
|
|
57
|
+
if (m[3]) {
|
|
58
|
+
if (m[4]) pt.run = m[4] ? parseInt(m[4], 10) : 1;
|
|
59
|
+
else pt.run = 1;
|
|
60
|
+
}
|
|
61
|
+
return pt;
|
|
62
|
+
}
|
|
63
|
+
constructor(y, x, at = 0, run = 0) {
|
|
64
|
+
this.y = y;
|
|
65
|
+
this.x = x;
|
|
66
|
+
this.at = at;
|
|
67
|
+
this.run = run;
|
|
68
|
+
}
|
|
69
|
+
toString() {
|
|
70
|
+
let s = `${this.y}.${this.x}`;
|
|
71
|
+
if (this.at && this.run) {
|
|
72
|
+
s += `@${this.at}`;
|
|
73
|
+
if (this.run !== 1) s += `x${this.run}`;
|
|
74
|
+
}
|
|
75
|
+
return s;
|
|
76
|
+
}
|
|
77
|
+
compareTo(other) {
|
|
78
|
+
if (this.y !== other.y) return this.y - other.y;
|
|
79
|
+
if (this.x !== other.x) return this.x - other.x;
|
|
80
|
+
if (this.at !== other.at) return this.at - other.at;
|
|
81
|
+
return this.run - other.run;
|
|
82
|
+
}
|
|
83
|
+
integralCompareTo(other) {
|
|
84
|
+
if (this.y !== other.y) return this.y - other.y;
|
|
85
|
+
if (this.x !== other.x) return this.x - other.x;
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var TokenLocation = class TokenLocation {
|
|
90
|
+
primary;
|
|
91
|
+
secondary;
|
|
92
|
+
static parse(text) {
|
|
93
|
+
if (!text) return null;
|
|
94
|
+
const pair = text.split("-", 2);
|
|
95
|
+
if (pair.length === 0) return null;
|
|
96
|
+
const primary = TokenPoint.parse(pair[0]);
|
|
97
|
+
if (!primary) return null;
|
|
98
|
+
return new TokenLocation(primary, pair.length > 1 ? TokenPoint.parse(pair[1]) || void 0 : void 0);
|
|
99
|
+
}
|
|
100
|
+
constructor(primary, secondary) {
|
|
101
|
+
this.primary = primary;
|
|
102
|
+
this.secondary = secondary;
|
|
103
|
+
}
|
|
104
|
+
isRange() {
|
|
105
|
+
return this.secondary != null;
|
|
106
|
+
}
|
|
107
|
+
toString() {
|
|
108
|
+
return this.secondary ? `${this.primary.toString()}-${this.secondary.toString()}` : this.primary.toString();
|
|
109
|
+
}
|
|
110
|
+
compareTo(other) {
|
|
111
|
+
const n1 = this.primary.compareTo(other.primary);
|
|
112
|
+
if (n1 !== 0) return n1;
|
|
113
|
+
if (this.secondary && other.secondary) return this.secondary.compareTo(other.secondary);
|
|
114
|
+
if (!this.secondary && !other.secondary) return 0;
|
|
115
|
+
return this.secondary ? 1 : -1;
|
|
116
|
+
}
|
|
117
|
+
overlaps(other) {
|
|
118
|
+
if (!other.primary) return false;
|
|
119
|
+
if (other.secondary == null) return !this.secondary ? this.primary.integralCompareTo(other.primary) === 0 : this.primary.compareTo(other.primary) <= 0 && this.secondary.compareTo(other.primary) >= 0;
|
|
120
|
+
return !this.secondary ? other.primary.compareTo(this.primary) <= 0 && other.secondary.compareTo(this.primary) >= 0 : other.secondary.compareTo(this.primary) >= 0 && other.primary.compareTo(this.secondary) <= 0;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
254
123
|
const pendingChangesGuard = (component) => {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return !component || component.canDeactivate()
|
|
258
|
-
? true
|
|
259
|
-
: dialogService
|
|
260
|
-
.confirm('Warning', 'There are unsaved changes. Do you want to leave?')
|
|
261
|
-
.pipe(take(1), map((yes) => (yes ? true : false)));
|
|
124
|
+
const dialogService = inject(DialogService);
|
|
125
|
+
return !component || component.canDeactivate() ? true : dialogService.confirm("Warning", "There are unsaved changes. Do you want to leave?").pipe(take(1), map((yes) => yes ? true : false));
|
|
262
126
|
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
sb.push('</div>');
|
|
823
|
-
return sb.join('');
|
|
824
|
-
}
|
|
825
|
-
/*
|
|
826
|
-
Location: starting from user selection on a rendered text, get the corresponding
|
|
827
|
-
layer fragment location. This differs according to the purpose of the location
|
|
828
|
-
to be got: if getting a location for an existing fragment, at least 1 decorated
|
|
829
|
-
text (span) should be included in the selection, which does not require to be
|
|
830
|
-
exact; if getting a location for a new fragment, no decorated text (span) can be
|
|
831
|
-
included in the selection (two fragments in the same layer can never overlap),
|
|
832
|
-
which must be exact.
|
|
833
|
-
*/
|
|
834
|
-
/**
|
|
835
|
-
* Get the Y bounds from the specified selection.
|
|
836
|
-
* @param range The selection range.
|
|
837
|
-
* @param forNew True if getting bounds for a new fragment.
|
|
838
|
-
* @returns Range, inclusive, or undefined.
|
|
839
|
-
*/
|
|
840
|
-
getYBoundsFromRange(range, forNew) {
|
|
841
|
-
let p = null;
|
|
842
|
-
switch (range.commonAncestorContainer.nodeType) {
|
|
843
|
-
case Node.TEXT_NODE:
|
|
844
|
-
// single-p selection, parent=p
|
|
845
|
-
p = range.commonAncestorContainer.parentElement;
|
|
846
|
-
if (forNew && (p?.nodeName !== 'P' || !p.hasAttribute('id'))) {
|
|
847
|
-
return null;
|
|
848
|
-
}
|
|
849
|
-
if (p?.nodeName === 'SPAN') {
|
|
850
|
-
p = p.parentElement;
|
|
851
|
-
}
|
|
852
|
-
const y = parseInt(p.getAttribute('id').substring(1), 10);
|
|
853
|
-
// return [y, y];
|
|
854
|
-
return { start: y, end: y };
|
|
855
|
-
case Node.ELEMENT_NODE:
|
|
856
|
-
// div only is allowed; in this case, it's a multi-p range
|
|
857
|
-
if (range.commonAncestorContainer.nodeName !== 'DIV') {
|
|
858
|
-
return null;
|
|
859
|
-
}
|
|
860
|
-
// for each div's child p element:
|
|
861
|
-
let yMin = 0;
|
|
862
|
-
let yMax = 0;
|
|
863
|
-
let inside = false;
|
|
864
|
-
for (let i = 0; i < range.commonAncestorContainer.childNodes.length; i++) {
|
|
865
|
-
const child = range.commonAncestorContainer.childNodes[i];
|
|
866
|
-
if (child.nodeType !== Node.ELEMENT_NODE || child.nodeName !== 'P') {
|
|
867
|
-
continue;
|
|
868
|
-
}
|
|
869
|
-
// check if we're entering the start-p
|
|
870
|
-
if (!inside && child.contains(range.startContainer)) {
|
|
871
|
-
inside = true;
|
|
872
|
-
}
|
|
873
|
-
// collect y if inside
|
|
874
|
-
if (inside) {
|
|
875
|
-
const iy = parseInt(child.getAttribute('id').substring(1), 10);
|
|
876
|
-
if (!yMin || iy < yMin) {
|
|
877
|
-
yMin = iy;
|
|
878
|
-
}
|
|
879
|
-
if (!yMax || iy > yMax) {
|
|
880
|
-
yMax = iy;
|
|
881
|
-
}
|
|
882
|
-
// check if we have exited the last p
|
|
883
|
-
if (child.contains(range.endContainer)) {
|
|
884
|
-
break;
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
return {
|
|
889
|
-
start: yMin,
|
|
890
|
-
end: yMax,
|
|
891
|
-
};
|
|
892
|
-
}
|
|
893
|
-
return null;
|
|
894
|
-
}
|
|
895
|
-
locatePrevSpace(line, index) {
|
|
896
|
-
while (index > -1 && line.charAt(index) !== ' ') {
|
|
897
|
-
index--;
|
|
898
|
-
}
|
|
899
|
-
return index;
|
|
900
|
-
}
|
|
901
|
-
locateNextSpace(line, index) {
|
|
902
|
-
while (index < line.length && line.charAt(index) !== ' ') {
|
|
903
|
-
index++;
|
|
904
|
-
}
|
|
905
|
-
return index === line.length ? -1 : index;
|
|
906
|
-
}
|
|
907
|
-
/**
|
|
908
|
-
* Get the bounds of the token any character of which is indexed
|
|
909
|
-
* by index.
|
|
910
|
-
* @param line The text line.
|
|
911
|
-
* @param index The index to the text line to start from.
|
|
912
|
-
* @returns Bounds where start=index of the first character of the token,
|
|
913
|
-
* and end=index of the character past the token's last character;
|
|
914
|
-
* or null if index was not valid.
|
|
915
|
-
*/
|
|
916
|
-
getTokenBounds(line, index) {
|
|
917
|
-
if (line.charAt(index) === ' ') {
|
|
918
|
-
return null;
|
|
919
|
-
}
|
|
920
|
-
let start = this.locatePrevSpace(line, index);
|
|
921
|
-
if (start === -1) {
|
|
922
|
-
start = 0;
|
|
923
|
-
}
|
|
924
|
-
else {
|
|
925
|
-
start++;
|
|
926
|
-
}
|
|
927
|
-
let end = this.locateNextSpace(line, index);
|
|
928
|
-
if (end === -1) {
|
|
929
|
-
end = line.length;
|
|
930
|
-
}
|
|
931
|
-
// return [start, end];
|
|
932
|
-
return {
|
|
933
|
-
start,
|
|
934
|
-
end,
|
|
935
|
-
};
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
* Return the received selection bounds, adjusted to exclude spaces.
|
|
939
|
-
*/
|
|
940
|
-
getAdjustedSelectionBounds(selStart, selEnd, line) {
|
|
941
|
-
// corner case: if on space, move to right
|
|
942
|
-
if (line.charAt(selStart) === ' ') {
|
|
943
|
-
selStart++;
|
|
944
|
-
}
|
|
945
|
-
// corner case: if included trailing space, move to left
|
|
946
|
-
if (selEnd > 0 && line.charAt(selEnd - 1) === ' ') {
|
|
947
|
-
selEnd--;
|
|
948
|
-
}
|
|
949
|
-
// return [selStart, selEnd];
|
|
950
|
-
return {
|
|
951
|
-
start: selStart,
|
|
952
|
-
end: selEnd,
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Get the start coordinates for the selected range and line.
|
|
957
|
-
* @param range The selected range.
|
|
958
|
-
* @param line The reference text line.
|
|
959
|
-
*/
|
|
960
|
-
getStartCoordsFromRange(selStart, selEnd, line) {
|
|
961
|
-
// get adjusted selection bounds
|
|
962
|
-
const selBounds = this.getAdjustedSelectionBounds(selStart, selEnd, line);
|
|
963
|
-
// get the bounds of the first selected token
|
|
964
|
-
const tokBounds = this.getTokenBounds(line, selBounds.start);
|
|
965
|
-
// calculate x by counting the tokens before the target token
|
|
966
|
-
let x = 1;
|
|
967
|
-
let j = tokBounds.start - 1;
|
|
968
|
-
while (j > -1) {
|
|
969
|
-
if (line.charAt(j) === ' ') {
|
|
970
|
-
x++;
|
|
971
|
-
}
|
|
972
|
-
j--;
|
|
973
|
-
}
|
|
974
|
-
// calculate at,run only when either of these is true:
|
|
975
|
-
// (a) selection starts past the 1st char of the token (al[pha);
|
|
976
|
-
// (b) selection ends before the last char of the token (al]pha);
|
|
977
|
-
// run is calculated only if (b) is true.
|
|
978
|
-
let at = 0;
|
|
979
|
-
let run = 0;
|
|
980
|
-
if (selBounds.start > tokBounds.start || selBounds.end < tokBounds.end) {
|
|
981
|
-
at = 1 + selBounds.start - tokBounds.start;
|
|
982
|
-
run =
|
|
983
|
-
(selBounds.end < tokBounds.end
|
|
984
|
-
? selBounds.end // al]pha
|
|
985
|
-
: tokBounds.end) - // alpha]
|
|
986
|
-
Math.max(tokBounds.start, selBounds.start);
|
|
987
|
-
}
|
|
988
|
-
return {
|
|
989
|
-
y: 0,
|
|
990
|
-
x,
|
|
991
|
-
at,
|
|
992
|
-
run,
|
|
993
|
-
};
|
|
994
|
-
}
|
|
995
|
-
getEndCoordsFromRange(selStart, selEnd, line) {
|
|
996
|
-
// get adjusted selection bounds
|
|
997
|
-
const selBounds = this.getAdjustedSelectionBounds(selStart, selEnd, line);
|
|
998
|
-
// get the bounds of the last selected token
|
|
999
|
-
const tokBounds = this.getTokenBounds(line, selBounds.end - 1);
|
|
1000
|
-
// calculate x by counting the tokens before the target token
|
|
1001
|
-
let x = 1;
|
|
1002
|
-
let j = selBounds.end - 1;
|
|
1003
|
-
while (j > -1) {
|
|
1004
|
-
if (line.charAt(j) === ' ') {
|
|
1005
|
-
x++;
|
|
1006
|
-
}
|
|
1007
|
-
j--;
|
|
1008
|
-
}
|
|
1009
|
-
// calculate at,run only when selection ends before the 1st char of the token
|
|
1010
|
-
// (al]pha); run is calculated only if at is calculated.
|
|
1011
|
-
let at = 0;
|
|
1012
|
-
let run = 0;
|
|
1013
|
-
if (selBounds.end < tokBounds.end) {
|
|
1014
|
-
at =
|
|
1015
|
-
selBounds.start > tokBounds.start
|
|
1016
|
-
? 1 + selBounds.start - tokBounds.start
|
|
1017
|
-
: 1;
|
|
1018
|
-
run = selBounds.end - tokBounds.start;
|
|
1019
|
-
}
|
|
1020
|
-
return {
|
|
1021
|
-
y: 0,
|
|
1022
|
-
x,
|
|
1023
|
-
at,
|
|
1024
|
-
run,
|
|
1025
|
-
};
|
|
1026
|
-
}
|
|
1027
|
-
getSpanLocFromId(id) {
|
|
1028
|
-
if (!id) {
|
|
1029
|
-
return null;
|
|
1030
|
-
}
|
|
1031
|
-
const r = new RegExp('^f([-\\d+.@x]+)', 'g');
|
|
1032
|
-
const m = r.exec(id);
|
|
1033
|
-
if (!m) {
|
|
1034
|
-
return null;
|
|
1035
|
-
}
|
|
1036
|
-
return TokenLocation.parse(m[1]);
|
|
1037
|
-
}
|
|
1038
|
-
visitNodes(node, visitor) {
|
|
1039
|
-
if (!visitor(node)) {
|
|
1040
|
-
return;
|
|
1041
|
-
}
|
|
1042
|
-
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
1043
|
-
for (let i = 0; i < node.childNodes.length; i++) {
|
|
1044
|
-
const child = node.childNodes[i];
|
|
1045
|
-
this.visitNodes(child, visitor);
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
findFirstDescendantSpan(range) {
|
|
1050
|
-
let inside = false;
|
|
1051
|
-
let span = null;
|
|
1052
|
-
this.visitNodes(range.commonAncestorContainer, (current) => {
|
|
1053
|
-
if (current === range.startContainer) {
|
|
1054
|
-
inside = true;
|
|
1055
|
-
}
|
|
1056
|
-
if (current.nodeType === Node.ELEMENT_NODE &&
|
|
1057
|
-
current.nodeName === 'SPAN') {
|
|
1058
|
-
span = current;
|
|
1059
|
-
return false;
|
|
1060
|
-
}
|
|
1061
|
-
if (current === range.endContainer) {
|
|
1062
|
-
inside = false;
|
|
1063
|
-
}
|
|
1064
|
-
return true;
|
|
1065
|
-
});
|
|
1066
|
-
return span;
|
|
1067
|
-
}
|
|
1068
|
-
/**
|
|
1069
|
-
* Get the base offset for the specified node. This is used
|
|
1070
|
-
* when the start container of the selected range has any
|
|
1071
|
-
* preceding sibling node, which happens only when you have
|
|
1072
|
-
* any spans in the p element (=the line). In this case,
|
|
1073
|
-
* the selection offset starts from the start container node,
|
|
1074
|
-
* which is preceded by other nodes including other text.
|
|
1075
|
-
* As we must get the line-based offset, we have to start
|
|
1076
|
-
* from a base offset equal to the sum of the lengths of
|
|
1077
|
-
* all the preceding siblings.
|
|
1078
|
-
*/
|
|
1079
|
-
getNodeBaseOffset(node) {
|
|
1080
|
-
let offset = 0;
|
|
1081
|
-
let n = node;
|
|
1082
|
-
n = node.previousSibling;
|
|
1083
|
-
while (n) {
|
|
1084
|
-
offset +=
|
|
1085
|
-
n.nodeType === Node.ELEMENT_NODE
|
|
1086
|
-
? n.innerText?.length || 0
|
|
1087
|
-
: n.textContent?.length || 0;
|
|
1088
|
-
n = n.previousSibling;
|
|
1089
|
-
}
|
|
1090
|
-
return offset;
|
|
1091
|
-
}
|
|
1092
|
-
/**
|
|
1093
|
-
* Get the location corresponding to the user selection,
|
|
1094
|
-
* for editing the first fragment included in it.
|
|
1095
|
-
* @param range The selected range. You can get it from the
|
|
1096
|
-
* current selection using getSelectedRange().
|
|
1097
|
-
* @returns The token location or null.
|
|
1098
|
-
*/
|
|
1099
|
-
getSelectedLocationForEdit(range) {
|
|
1100
|
-
if (!range) {
|
|
1101
|
-
return null;
|
|
1102
|
-
}
|
|
1103
|
-
// just find the first descendant span in selection
|
|
1104
|
-
let span = null;
|
|
1105
|
-
switch (range.commonAncestorContainer.nodeType) {
|
|
1106
|
-
case Node.ELEMENT_NODE:
|
|
1107
|
-
span = range.commonAncestorContainer;
|
|
1108
|
-
if (span.nodeName !== 'SPAN') {
|
|
1109
|
-
span = this.findFirstDescendantSpan(range);
|
|
1110
|
-
}
|
|
1111
|
-
break;
|
|
1112
|
-
case Node.TEXT_NODE:
|
|
1113
|
-
span = range.commonAncestorContainer.parentElement;
|
|
1114
|
-
if (span &&
|
|
1115
|
-
(span.nodeType !== Node.ELEMENT_NODE || span.nodeName !== 'SPAN')) {
|
|
1116
|
-
span = null;
|
|
1117
|
-
}
|
|
1118
|
-
break;
|
|
1119
|
-
}
|
|
1120
|
-
return span ? this.getSpanLocFromId(span.getAttribute('id')) : null;
|
|
1121
|
-
}
|
|
1122
|
-
textLineToString(line) {
|
|
1123
|
-
if (!line || !line.tokens) {
|
|
1124
|
-
return '';
|
|
1125
|
-
}
|
|
1126
|
-
return line.tokens.join(' ');
|
|
1127
|
-
}
|
|
1128
|
-
buildCoords(start, end, singleToken) {
|
|
1129
|
-
const sb = [];
|
|
1130
|
-
// start: y.x
|
|
1131
|
-
sb.push(`${start.y}.${start.x}`);
|
|
1132
|
-
if (singleToken) {
|
|
1133
|
-
// single token: check for at,run
|
|
1134
|
-
if (start.at) {
|
|
1135
|
-
sb.push(`@${start.at}`);
|
|
1136
|
-
if (start.run && start.run > 1) {
|
|
1137
|
-
sb.push(`x${start.run}`);
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
else {
|
|
1142
|
-
// not a single token
|
|
1143
|
-
// first token
|
|
1144
|
-
if (start.at) {
|
|
1145
|
-
sb.push(`@${start.at}x${start.run}`);
|
|
1146
|
-
}
|
|
1147
|
-
// last token
|
|
1148
|
-
sb.push(`-${end.y}.${end.x}`);
|
|
1149
|
-
if (end.at) {
|
|
1150
|
-
sb.push(`@1x${end.run}`);
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
return sb.join('');
|
|
1154
|
-
}
|
|
1155
|
-
/**
|
|
1156
|
-
* Recursively find the node matching the specified matcher
|
|
1157
|
-
* function, starting from the specified node (included).
|
|
1158
|
-
*
|
|
1159
|
-
* @param node The node to start from.
|
|
1160
|
-
* @param matcher The matcher function, which receives a node
|
|
1161
|
-
* to match, and returns 1=match, 0=no match, -1=stop the
|
|
1162
|
-
* find operation with a no match.
|
|
1163
|
-
* @return 1=match, 0=no match, -1=stop the find operation with a no match.
|
|
1164
|
-
*/
|
|
1165
|
-
matchNode(node, matcher) {
|
|
1166
|
-
// self
|
|
1167
|
-
const n = matcher(node);
|
|
1168
|
-
if (n) {
|
|
1169
|
-
return n;
|
|
1170
|
-
}
|
|
1171
|
-
// children
|
|
1172
|
-
if (node.hasChildNodes()) {
|
|
1173
|
-
for (let i = 0; i < node.childNodes.length; i++) {
|
|
1174
|
-
const child = node.childNodes[i];
|
|
1175
|
-
const m = this.matchNode(child, matcher);
|
|
1176
|
-
if (m) {
|
|
1177
|
-
return m;
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
return 0;
|
|
1182
|
-
}
|
|
1183
|
-
selHasAnySpan(range) {
|
|
1184
|
-
let inside = false;
|
|
1185
|
-
if (
|
|
1186
|
-
// the selected text node must not be child of a span
|
|
1187
|
-
range.startContainer.parentElement?.tagName === 'SPAN' ||
|
|
1188
|
-
range.endContainer.parentElement?.tagName === 'SPAN' ||
|
|
1189
|
-
// the nodes tree from the common ancestor, from the start node
|
|
1190
|
-
// up to the end node, must not include any span
|
|
1191
|
-
this.matchNode(range.commonAncestorContainer, (node) => {
|
|
1192
|
-
// start checking only when start node reached
|
|
1193
|
-
if (node === range.startContainer) {
|
|
1194
|
-
inside = true;
|
|
1195
|
-
}
|
|
1196
|
-
if (!inside) {
|
|
1197
|
-
return 0;
|
|
1198
|
-
}
|
|
1199
|
-
// stop checking when end node reached
|
|
1200
|
-
if (node === range.endContainer) {
|
|
1201
|
-
return -1;
|
|
1202
|
-
}
|
|
1203
|
-
// node cannot be a span
|
|
1204
|
-
if (node.nodeType === Node.ELEMENT_NODE &&
|
|
1205
|
-
node.tagName === 'SPAN') {
|
|
1206
|
-
return 1;
|
|
1207
|
-
}
|
|
1208
|
-
return 0;
|
|
1209
|
-
}) === 1) {
|
|
1210
|
-
return true;
|
|
1211
|
-
}
|
|
1212
|
-
return false;
|
|
1213
|
-
}
|
|
1214
|
-
/**
|
|
1215
|
-
* Get the location corresponding to the user selection,
|
|
1216
|
-
* for adding a new fragment with the same extension.
|
|
1217
|
-
* @param range The selected range. You can get it from the
|
|
1218
|
-
* current selection using getSelectedRange().
|
|
1219
|
-
* @param text The full base text.
|
|
1220
|
-
* @returns TokenLocation The token location or undefined.
|
|
1221
|
-
*/
|
|
1222
|
-
getSelectedLocationForNew(range, text) {
|
|
1223
|
-
if (!range || this.selHasAnySpan(range)) {
|
|
1224
|
-
return null;
|
|
1225
|
-
}
|
|
1226
|
-
// get y bounds (min, max; equal if single-line)
|
|
1227
|
-
const yBounds = this.getYBoundsFromRange(range, true);
|
|
1228
|
-
if (!yBounds) {
|
|
1229
|
-
return null;
|
|
1230
|
-
}
|
|
1231
|
-
// get lines and calculate start/end coords
|
|
1232
|
-
const lines = this.getLines(text);
|
|
1233
|
-
const startLine = this.textLineToString(lines[yBounds.start - 1]);
|
|
1234
|
-
const endLine = this.textLineToString(lines[yBounds.end - 1]);
|
|
1235
|
-
// get the base offsets
|
|
1236
|
-
const startBaseOffset = this.getNodeBaseOffset(range.startContainer);
|
|
1237
|
-
const endBaseOffset = this.getNodeBaseOffset(range.endContainer);
|
|
1238
|
-
// get the start (including the base offset)
|
|
1239
|
-
const startLineEndOffset = yBounds.start !== yBounds.end
|
|
1240
|
-
? startLine.length
|
|
1241
|
-
: range.endOffset + startBaseOffset;
|
|
1242
|
-
const start = this.getStartCoordsFromRange(range.startOffset + startBaseOffset, startLineEndOffset, startLine);
|
|
1243
|
-
start.y = yBounds.start;
|
|
1244
|
-
// get the end (including the base offset)
|
|
1245
|
-
const end = yBounds.start !== yBounds.end
|
|
1246
|
-
? this.getEndCoordsFromRange(0, range.endOffset + endBaseOffset, endLine)
|
|
1247
|
-
: this.getEndCoordsFromRange(range.startOffset + endBaseOffset, range.endOffset + endBaseOffset, endLine);
|
|
1248
|
-
end.y = yBounds.end;
|
|
1249
|
-
const singleLine = start.y === end.y;
|
|
1250
|
-
const singleToken = singleLine && start.x === end.x;
|
|
1251
|
-
const coords = this.buildCoords(start, end, singleToken);
|
|
1252
|
-
return TokenLocation.parse(coords);
|
|
1253
|
-
}
|
|
1254
|
-
/**
|
|
1255
|
-
* Get the currently selected range in the browser's document.
|
|
1256
|
-
*/
|
|
1257
|
-
getSelectedRange() {
|
|
1258
|
-
const sel = window.getSelection();
|
|
1259
|
-
if (!sel || sel.isCollapsed) {
|
|
1260
|
-
return null;
|
|
1261
|
-
}
|
|
1262
|
-
return sel.getRangeAt(0);
|
|
1263
|
-
}
|
|
1264
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.1", ngImport: i0, type: TextLayerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1265
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.1", ngImport: i0, type: TextLayerService, providedIn: 'root' });
|
|
1266
|
-
}
|
|
1267
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.1", ngImport: i0, type: TextLayerService, decorators: [{
|
|
1268
|
-
type: Injectable,
|
|
1269
|
-
args: [{ providedIn: 'root' }]
|
|
1270
|
-
}], ctorParameters: () => [] });
|
|
1271
|
-
|
|
1272
|
-
/*
|
|
1273
|
-
* Public API Surface of cadmus-core
|
|
1274
|
-
*/
|
|
1275
|
-
|
|
1276
|
-
/**
|
|
1277
|
-
* Generated bundle index. Do not edit.
|
|
1278
|
-
*/
|
|
1279
|
-
|
|
127
|
+
var PendingChangesGuard = class PendingChangesGuard {
|
|
128
|
+
_dialogService;
|
|
129
|
+
constructor(_dialogService) {
|
|
130
|
+
this._dialogService = _dialogService;
|
|
131
|
+
}
|
|
132
|
+
canDeactivate(component) {
|
|
133
|
+
return !component || component.canDeactivate() ? true : this._dialogService.confirm("Warning", "There are unsaved changes. Do you want to leave?").pipe(take(1), map((yes) => yes ? true : false));
|
|
134
|
+
}
|
|
135
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
136
|
+
minVersion: "12.0.0",
|
|
137
|
+
version: "22.2.0",
|
|
138
|
+
ngImport: i0,
|
|
139
|
+
type: PendingChangesGuard,
|
|
140
|
+
deps: [{ token: i1.DialogService }],
|
|
141
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
142
|
+
});
|
|
143
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
144
|
+
minVersion: "12.0.0",
|
|
145
|
+
version: "22.2.0",
|
|
146
|
+
ngImport: i0,
|
|
147
|
+
type: PendingChangesGuard,
|
|
148
|
+
providedIn: "root"
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
152
|
+
minVersion: "12.0.0",
|
|
153
|
+
version: "22.2.0",
|
|
154
|
+
ngImport: i0,
|
|
155
|
+
type: PendingChangesGuard,
|
|
156
|
+
decorators: [{
|
|
157
|
+
type: Injectable,
|
|
158
|
+
args: [{ providedIn: "root" }]
|
|
159
|
+
}],
|
|
160
|
+
ctorParameters: () => [{ type: i1.DialogService }]
|
|
161
|
+
});
|
|
162
|
+
var SortPipe = class SortPipe {
|
|
163
|
+
transform(value, propName) {
|
|
164
|
+
if (!value || !Array.isArray(value)) return value;
|
|
165
|
+
return [...value].sort((a, b) => {
|
|
166
|
+
if (!a && !b) return 0;
|
|
167
|
+
if (!a && b) return -1;
|
|
168
|
+
if (a && !b) return 1;
|
|
169
|
+
if (a[propName] < b[propName]) return -1;
|
|
170
|
+
else if (a[propName] === b[propName]) return 0;
|
|
171
|
+
else if (a[propName] > b[propName]) return 1;
|
|
172
|
+
return 0;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
176
|
+
minVersion: "12.0.0",
|
|
177
|
+
version: "22.2.0",
|
|
178
|
+
ngImport: i0,
|
|
179
|
+
type: SortPipe,
|
|
180
|
+
deps: [],
|
|
181
|
+
target: i0.ɵɵFactoryTarget.Pipe
|
|
182
|
+
});
|
|
183
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({
|
|
184
|
+
minVersion: "14.0.0",
|
|
185
|
+
version: "22.2.0",
|
|
186
|
+
ngImport: i0,
|
|
187
|
+
type: SortPipe,
|
|
188
|
+
isStandalone: true,
|
|
189
|
+
name: "sort"
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
193
|
+
minVersion: "12.0.0",
|
|
194
|
+
version: "22.2.0",
|
|
195
|
+
ngImport: i0,
|
|
196
|
+
type: SortPipe,
|
|
197
|
+
decorators: [{
|
|
198
|
+
type: Pipe,
|
|
199
|
+
args: [{ name: "sort" }]
|
|
200
|
+
}]
|
|
201
|
+
});
|
|
202
|
+
var LibraryRouteService = class LibraryRouteService {
|
|
203
|
+
_partEditorKeys;
|
|
204
|
+
constructor(_partEditorKeys) {
|
|
205
|
+
this._partEditorKeys = _partEditorKeys;
|
|
206
|
+
}
|
|
207
|
+
stripFragmentRoleId(roleId) {
|
|
208
|
+
const i = roleId.lastIndexOf(":");
|
|
209
|
+
if (i > -1) roleId = roleId.substring(0, i);
|
|
210
|
+
return roleId;
|
|
211
|
+
}
|
|
212
|
+
getFragmentTypeAndRole(roleId) {
|
|
213
|
+
if (!roleId || !roleId.startsWith("fr.")) return null;
|
|
214
|
+
const i = roleId.indexOf(":");
|
|
215
|
+
if (i > -1) return {
|
|
216
|
+
frTypeId: roleId.substring(0, i),
|
|
217
|
+
frRoleId: roleId.substring(i + 1)
|
|
218
|
+
};
|
|
219
|
+
else return {
|
|
220
|
+
frTypeId: roleId,
|
|
221
|
+
frRoleId: void 0
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
findPartDefinition(partDefs, typeId, roleId = null) {
|
|
225
|
+
if (!partDefs) return;
|
|
226
|
+
if (roleId) {
|
|
227
|
+
const reqRoleId = this.stripFragmentRoleId(roleId);
|
|
228
|
+
return partDefs.find((d) => {
|
|
229
|
+
return d.typeId === typeId && d.roleId && this.stripFragmentRoleId(d.roleId) === reqRoleId;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return partDefs.find((d) => {
|
|
233
|
+
return d.typeId === typeId;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
getEditorKeyFromPartType(typeId, roleId) {
|
|
237
|
+
const partGroupKey = this._partEditorKeys[typeId];
|
|
238
|
+
if (!partGroupKey) return { partKey: "default" };
|
|
239
|
+
if (roleId) {
|
|
240
|
+
const reqRoleId = this.stripFragmentRoleId(roleId);
|
|
241
|
+
return {
|
|
242
|
+
partKey: partGroupKey.part,
|
|
243
|
+
frKey: partGroupKey.fragments?.[reqRoleId]
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return { partKey: partGroupKey.part };
|
|
247
|
+
}
|
|
248
|
+
decomposeEditorKey(key) {
|
|
249
|
+
const i = key.indexOf(" ");
|
|
250
|
+
if (i > -1) return {
|
|
251
|
+
partKey: key.substring(0, i),
|
|
252
|
+
frKey: key.substring(i + 1)
|
|
253
|
+
};
|
|
254
|
+
else return {
|
|
255
|
+
partKey: key,
|
|
256
|
+
frKey: key
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
buildPartEditorRoute(itemId, partId, typeId, roleId) {
|
|
260
|
+
let route;
|
|
261
|
+
route = `/items/${itemId}/${this.getEditorKeyFromPartType(typeId).partKey}/${typeId}/${partId}`;
|
|
262
|
+
return {
|
|
263
|
+
route,
|
|
264
|
+
rid: roleId
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
buildFragmentEditorRoute(partDefs, itemId, partId, typeId, roleId, loc) {
|
|
268
|
+
let route;
|
|
269
|
+
const editorKey = this.getEditorKeyFromPartType(typeId, roleId);
|
|
270
|
+
const frInfo = this.getFragmentTypeAndRole(roleId);
|
|
271
|
+
const frTypeId = frInfo?.frTypeId ?? typeId;
|
|
272
|
+
const frRoleId = frInfo?.frRoleId;
|
|
273
|
+
route = `/items/${itemId}/${editorKey.frKey ?? editorKey.partKey}/fragment/${partId}/${frTypeId}/${loc}`;
|
|
274
|
+
return {
|
|
275
|
+
route,
|
|
276
|
+
rid: frRoleId
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
280
|
+
minVersion: "12.0.0",
|
|
281
|
+
version: "22.2.0",
|
|
282
|
+
ngImport: i0,
|
|
283
|
+
type: LibraryRouteService,
|
|
284
|
+
deps: [{ token: "partEditorKeys" }],
|
|
285
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
286
|
+
});
|
|
287
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
288
|
+
minVersion: "12.0.0",
|
|
289
|
+
version: "22.2.0",
|
|
290
|
+
ngImport: i0,
|
|
291
|
+
type: LibraryRouteService,
|
|
292
|
+
providedIn: "root"
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
296
|
+
minVersion: "12.0.0",
|
|
297
|
+
version: "22.2.0",
|
|
298
|
+
ngImport: i0,
|
|
299
|
+
type: LibraryRouteService,
|
|
300
|
+
decorators: [{
|
|
301
|
+
type: Injectable,
|
|
302
|
+
args: [{ providedIn: "root" }]
|
|
303
|
+
}],
|
|
304
|
+
ctorParameters: () => [{
|
|
305
|
+
type: void 0,
|
|
306
|
+
decorators: [{
|
|
307
|
+
type: Inject,
|
|
308
|
+
args: ["partEditorKeys"]
|
|
309
|
+
}]
|
|
310
|
+
}]
|
|
311
|
+
});
|
|
312
|
+
var TextLayerService = class TextLayerService {
|
|
313
|
+
_wsRegex;
|
|
314
|
+
constructor() {
|
|
315
|
+
this._wsRegex = /* @__PURE__ */ new RegExp("^\\s$", "g");
|
|
316
|
+
}
|
|
317
|
+
isWhitespace(c) {
|
|
318
|
+
if (!c) return false;
|
|
319
|
+
if (c.length !== 1) c = c.charAt(0);
|
|
320
|
+
return this._wsRegex.test(c);
|
|
321
|
+
}
|
|
322
|
+
getLines(text) {
|
|
323
|
+
const results = [];
|
|
324
|
+
if (!text) return results;
|
|
325
|
+
const lines = text.split("\n");
|
|
326
|
+
for (let y = 0; y < lines.length; y++) {
|
|
327
|
+
const line = lines[y].trim();
|
|
328
|
+
const l = {
|
|
329
|
+
y: y + 1,
|
|
330
|
+
tokens: []
|
|
331
|
+
};
|
|
332
|
+
let x = 0;
|
|
333
|
+
let xBeg = 0;
|
|
334
|
+
while (x < line.length) if (this.isWhitespace(line.charAt(x))) {
|
|
335
|
+
l.tokens.push(line.substring(xBeg, x));
|
|
336
|
+
x++;
|
|
337
|
+
while (x < line.length && this.isWhitespace(line.charAt(x))) x++;
|
|
338
|
+
xBeg = x;
|
|
339
|
+
} else x++;
|
|
340
|
+
if (xBeg < x) l.tokens.push(line.substring(xBeg));
|
|
341
|
+
results.push(l);
|
|
342
|
+
}
|
|
343
|
+
return results;
|
|
344
|
+
}
|
|
345
|
+
getTextFragment(text, location) {
|
|
346
|
+
const lines = this.getLines(text);
|
|
347
|
+
if (location.isRange()) {
|
|
348
|
+
const sb = [];
|
|
349
|
+
let yn = 0;
|
|
350
|
+
for (let y = location.primary.y; y <= location.secondary.y; y++) {
|
|
351
|
+
const headLine = location.primary.y === y;
|
|
352
|
+
const tailLine = location.secondary.y === y;
|
|
353
|
+
if (++yn > 1) sb.push(" ");
|
|
354
|
+
let xn = 0;
|
|
355
|
+
for (let x = headLine ? location.primary.x : 1; x <= (tailLine ? location.secondary.x : lines[y - 1].tokens.length); x++) {
|
|
356
|
+
if (++xn > 1) sb.push(" ");
|
|
357
|
+
let start = location.primary.at && headLine && x === location.primary.x ? location.primary.at : 1;
|
|
358
|
+
let len = location.secondary.at && tailLine && x === location.secondary.x ? location.secondary.run || 1 : -1;
|
|
359
|
+
const token = lines[y - 1].tokens[x - 1];
|
|
360
|
+
if (start === 1 && len === -1) sb.push(token);
|
|
361
|
+
else sb.push(token.substring(start - 1, len === -1 ? void 0 : start - 1 + len));
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return sb.join("");
|
|
365
|
+
} else {
|
|
366
|
+
const token = lines[location.primary.y - 1].tokens[location.primary.x - 1];
|
|
367
|
+
return location.primary.at ? token.substring(location.primary.at - 1, location.primary.at - 1 + (location.primary.run || 1)) : token;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
renderOpeningSpan(loc, locPortion, sb, isSelected) {
|
|
371
|
+
sb.push(`<span id="f${loc.toString()}_${locPortion}" class="fr${isSelected ? " fr-sel" : ""}">`);
|
|
372
|
+
}
|
|
373
|
+
renderTokenAtEnd(pt, token, sb) {
|
|
374
|
+
if (pt.at) {
|
|
375
|
+
sb.push(token.substring(pt.at - 1, (pt.run || 0) + pt.at - 1));
|
|
376
|
+
sb.push("</span>");
|
|
377
|
+
if (pt.at - 1 + (pt.run || 0) < token.length) sb.push(token.substring(pt.at - 1 + (pt.run || 0)));
|
|
378
|
+
} else {
|
|
379
|
+
sb.push(token);
|
|
380
|
+
sb.push("</span>");
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
renderTokenAtPointStart(loc, token, sb, isSelected) {
|
|
384
|
+
if (loc.primary.at) sb.push(token.substring(0, loc.primary.at - 1));
|
|
385
|
+
this.renderOpeningSpan(loc, 0, sb, isSelected);
|
|
386
|
+
this.renderTokenAtEnd(loc.primary, token, sb);
|
|
387
|
+
}
|
|
388
|
+
renderTokenAtRangeStart(loc, token, sb, isSelected) {
|
|
389
|
+
if (loc.primary.at) sb.push(token.substring(0, loc.primary.at - 1));
|
|
390
|
+
this.renderOpeningSpan(loc, 0, sb, isSelected);
|
|
391
|
+
if (loc.primary.at) sb.push(token.substring(loc.primary.at - 1));
|
|
392
|
+
else sb.push(token);
|
|
393
|
+
}
|
|
394
|
+
renderTokenAtStart(loc, token, sb, isSelected) {
|
|
395
|
+
if (!loc.secondary) {
|
|
396
|
+
this.renderTokenAtPointStart(loc, token, sb, isSelected);
|
|
397
|
+
return false;
|
|
398
|
+
} else {
|
|
399
|
+
this.renderTokenAtRangeStart(loc, token, sb, isSelected);
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
render(text, locations, selectedLoc) {
|
|
404
|
+
if (!text) return "<div></div>";
|
|
405
|
+
const sb = [];
|
|
406
|
+
const lines = this.getLines(text);
|
|
407
|
+
let loc = void 0;
|
|
408
|
+
let tokenSelected = false;
|
|
409
|
+
if (!locations) locations = [];
|
|
410
|
+
sb.push("<div>");
|
|
411
|
+
for (let y = 0; y < lines.length; y++) {
|
|
412
|
+
sb.push(`<p id="y${y + 1}">`);
|
|
413
|
+
if (loc) this.renderOpeningSpan(loc, y + 1 - loc.primary.y, sb, tokenSelected);
|
|
414
|
+
const line = lines[y];
|
|
415
|
+
for (let x = 0; x < line.tokens.length; x++) {
|
|
416
|
+
if (x > 0) sb.push(" ");
|
|
417
|
+
const token = line.tokens[x];
|
|
418
|
+
if (loc && loc.secondary) {
|
|
419
|
+
if (loc.secondary.y === y + 1 && loc.secondary.x === x + 1) {
|
|
420
|
+
this.renderTokenAtEnd(loc.secondary, token, sb);
|
|
421
|
+
loc = void 0;
|
|
422
|
+
} else sb.push(token);
|
|
423
|
+
} else {
|
|
424
|
+
loc = locations.find((l) => {
|
|
425
|
+
return l.primary.y === y + 1 && l.primary.x === x + 1;
|
|
426
|
+
});
|
|
427
|
+
if (loc) {
|
|
428
|
+
tokenSelected = selectedLoc ? loc.overlaps(selectedLoc) : false;
|
|
429
|
+
if (!this.renderTokenAtStart(loc, token, sb, tokenSelected)) loc = void 0;
|
|
430
|
+
} else sb.push(token);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (loc) sb.push("</span>");
|
|
434
|
+
sb.push("</p>");
|
|
435
|
+
}
|
|
436
|
+
sb.push("</div>");
|
|
437
|
+
return sb.join("");
|
|
438
|
+
}
|
|
439
|
+
getYBoundsFromRange(range, forNew) {
|
|
440
|
+
let p = null;
|
|
441
|
+
switch (range.commonAncestorContainer.nodeType) {
|
|
442
|
+
case Node.TEXT_NODE:
|
|
443
|
+
p = range.commonAncestorContainer.parentElement;
|
|
444
|
+
if (forNew && (p?.nodeName !== "P" || !p.hasAttribute("id"))) return null;
|
|
445
|
+
if (p?.nodeName === "SPAN") p = p.parentElement;
|
|
446
|
+
const y = parseInt(p.getAttribute("id").substring(1), 10);
|
|
447
|
+
return {
|
|
448
|
+
start: y,
|
|
449
|
+
end: y
|
|
450
|
+
};
|
|
451
|
+
case Node.ELEMENT_NODE:
|
|
452
|
+
if (range.commonAncestorContainer.nodeName !== "DIV") return null;
|
|
453
|
+
let yMin = 0;
|
|
454
|
+
let yMax = 0;
|
|
455
|
+
let inside = false;
|
|
456
|
+
for (let i = 0; i < range.commonAncestorContainer.childNodes.length; i++) {
|
|
457
|
+
const child = range.commonAncestorContainer.childNodes[i];
|
|
458
|
+
if (child.nodeType !== Node.ELEMENT_NODE || child.nodeName !== "P") continue;
|
|
459
|
+
if (!inside && child.contains(range.startContainer)) inside = true;
|
|
460
|
+
if (inside) {
|
|
461
|
+
const iy = parseInt(child.getAttribute("id").substring(1), 10);
|
|
462
|
+
if (!yMin || iy < yMin) yMin = iy;
|
|
463
|
+
if (!yMax || iy > yMax) yMax = iy;
|
|
464
|
+
if (child.contains(range.endContainer)) break;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return {
|
|
468
|
+
start: yMin,
|
|
469
|
+
end: yMax
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
locatePrevSpace(line, index) {
|
|
475
|
+
while (index > -1 && line.charAt(index) !== " ") index--;
|
|
476
|
+
return index;
|
|
477
|
+
}
|
|
478
|
+
locateNextSpace(line, index) {
|
|
479
|
+
while (index < line.length && line.charAt(index) !== " ") index++;
|
|
480
|
+
return index === line.length ? -1 : index;
|
|
481
|
+
}
|
|
482
|
+
getTokenBounds(line, index) {
|
|
483
|
+
if (line.charAt(index) === " ") return null;
|
|
484
|
+
let start = this.locatePrevSpace(line, index);
|
|
485
|
+
if (start === -1) start = 0;
|
|
486
|
+
else start++;
|
|
487
|
+
let end = this.locateNextSpace(line, index);
|
|
488
|
+
if (end === -1) end = line.length;
|
|
489
|
+
return {
|
|
490
|
+
start,
|
|
491
|
+
end
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
getAdjustedSelectionBounds(selStart, selEnd, line) {
|
|
495
|
+
if (line.charAt(selStart) === " ") selStart++;
|
|
496
|
+
if (selEnd > 0 && line.charAt(selEnd - 1) === " ") selEnd--;
|
|
497
|
+
return {
|
|
498
|
+
start: selStart,
|
|
499
|
+
end: selEnd
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
getStartCoordsFromRange(selStart, selEnd, line) {
|
|
503
|
+
const selBounds = this.getAdjustedSelectionBounds(selStart, selEnd, line);
|
|
504
|
+
const tokBounds = this.getTokenBounds(line, selBounds.start);
|
|
505
|
+
let x = 1;
|
|
506
|
+
let j = tokBounds.start - 1;
|
|
507
|
+
while (j > -1) {
|
|
508
|
+
if (line.charAt(j) === " ") x++;
|
|
509
|
+
j--;
|
|
510
|
+
}
|
|
511
|
+
let at = 0;
|
|
512
|
+
let run = 0;
|
|
513
|
+
if (selBounds.start > tokBounds.start || selBounds.end < tokBounds.end) {
|
|
514
|
+
at = 1 + selBounds.start - tokBounds.start;
|
|
515
|
+
run = (selBounds.end < tokBounds.end ? selBounds.end : tokBounds.end) - Math.max(tokBounds.start, selBounds.start);
|
|
516
|
+
}
|
|
517
|
+
return {
|
|
518
|
+
y: 0,
|
|
519
|
+
x,
|
|
520
|
+
at,
|
|
521
|
+
run
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
getEndCoordsFromRange(selStart, selEnd, line) {
|
|
525
|
+
const selBounds = this.getAdjustedSelectionBounds(selStart, selEnd, line);
|
|
526
|
+
const tokBounds = this.getTokenBounds(line, selBounds.end - 1);
|
|
527
|
+
let x = 1;
|
|
528
|
+
let j = selBounds.end - 1;
|
|
529
|
+
while (j > -1) {
|
|
530
|
+
if (line.charAt(j) === " ") x++;
|
|
531
|
+
j--;
|
|
532
|
+
}
|
|
533
|
+
let at = 0;
|
|
534
|
+
let run = 0;
|
|
535
|
+
if (selBounds.end < tokBounds.end) {
|
|
536
|
+
at = selBounds.start > tokBounds.start ? 1 + selBounds.start - tokBounds.start : 1;
|
|
537
|
+
run = selBounds.end - tokBounds.start;
|
|
538
|
+
}
|
|
539
|
+
return {
|
|
540
|
+
y: 0,
|
|
541
|
+
x,
|
|
542
|
+
at,
|
|
543
|
+
run
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
getSpanLocFromId(id) {
|
|
547
|
+
if (!id) return null;
|
|
548
|
+
const m = (/* @__PURE__ */ new RegExp("^f([-\\d+.@x]+)", "g")).exec(id);
|
|
549
|
+
if (!m) return null;
|
|
550
|
+
return TokenLocation.parse(m[1]);
|
|
551
|
+
}
|
|
552
|
+
visitNodes(node, visitor) {
|
|
553
|
+
if (!visitor(node)) return;
|
|
554
|
+
if (node.nodeType === Node.ELEMENT_NODE) for (let i = 0; i < node.childNodes.length; i++) {
|
|
555
|
+
const child = node.childNodes[i];
|
|
556
|
+
this.visitNodes(child, visitor);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
findFirstDescendantSpan(range) {
|
|
560
|
+
let span = null;
|
|
561
|
+
this.visitNodes(range.commonAncestorContainer, (current) => {
|
|
562
|
+
if (current === range.startContainer) {}
|
|
563
|
+
if (current.nodeType === Node.ELEMENT_NODE && current.nodeName === "SPAN") {
|
|
564
|
+
span = current;
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
if (current === range.endContainer) {}
|
|
568
|
+
return true;
|
|
569
|
+
});
|
|
570
|
+
return span;
|
|
571
|
+
}
|
|
572
|
+
getNodeBaseOffset(node) {
|
|
573
|
+
let offset = 0;
|
|
574
|
+
let n = node;
|
|
575
|
+
n = node.previousSibling;
|
|
576
|
+
while (n) {
|
|
577
|
+
offset += n.nodeType === Node.ELEMENT_NODE ? n.innerText?.length || 0 : n.textContent?.length || 0;
|
|
578
|
+
n = n.previousSibling;
|
|
579
|
+
}
|
|
580
|
+
return offset;
|
|
581
|
+
}
|
|
582
|
+
getSelectedLocationForEdit(range) {
|
|
583
|
+
if (!range) return null;
|
|
584
|
+
let span = null;
|
|
585
|
+
switch (range.commonAncestorContainer.nodeType) {
|
|
586
|
+
case Node.ELEMENT_NODE:
|
|
587
|
+
span = range.commonAncestorContainer;
|
|
588
|
+
if (span.nodeName !== "SPAN") span = this.findFirstDescendantSpan(range);
|
|
589
|
+
break;
|
|
590
|
+
case Node.TEXT_NODE:
|
|
591
|
+
span = range.commonAncestorContainer.parentElement;
|
|
592
|
+
if (span && (span.nodeType !== Node.ELEMENT_NODE || span.nodeName !== "SPAN")) span = null;
|
|
593
|
+
}
|
|
594
|
+
return span ? this.getSpanLocFromId(span.getAttribute("id")) : null;
|
|
595
|
+
}
|
|
596
|
+
textLineToString(line) {
|
|
597
|
+
if (!line || !line.tokens) return "";
|
|
598
|
+
return line.tokens.join(" ");
|
|
599
|
+
}
|
|
600
|
+
buildCoords(start, end, singleToken) {
|
|
601
|
+
const sb = [];
|
|
602
|
+
sb.push(`${start.y}.${start.x}`);
|
|
603
|
+
if (singleToken) {
|
|
604
|
+
if (start.at) {
|
|
605
|
+
sb.push(`@${start.at}`);
|
|
606
|
+
if (start.run && start.run > 1) sb.push(`x${start.run}`);
|
|
607
|
+
}
|
|
608
|
+
} else {
|
|
609
|
+
if (start.at) sb.push(`@${start.at}x${start.run}`);
|
|
610
|
+
sb.push(`-${end.y}.${end.x}`);
|
|
611
|
+
if (end.at) sb.push(`@1x${end.run}`);
|
|
612
|
+
}
|
|
613
|
+
return sb.join("");
|
|
614
|
+
}
|
|
615
|
+
matchNode(node, matcher) {
|
|
616
|
+
const n = matcher(node);
|
|
617
|
+
if (n) return n;
|
|
618
|
+
if (node.hasChildNodes()) for (let i = 0; i < node.childNodes.length; i++) {
|
|
619
|
+
const child = node.childNodes[i];
|
|
620
|
+
const m = this.matchNode(child, matcher);
|
|
621
|
+
if (m) return m;
|
|
622
|
+
}
|
|
623
|
+
return 0;
|
|
624
|
+
}
|
|
625
|
+
selHasAnySpan(range) {
|
|
626
|
+
let inside = false;
|
|
627
|
+
if (range.startContainer.parentElement?.tagName === "SPAN" || range.endContainer.parentElement?.tagName === "SPAN" || this.matchNode(range.commonAncestorContainer, (node) => {
|
|
628
|
+
if (node === range.startContainer) inside = true;
|
|
629
|
+
if (!inside) return 0;
|
|
630
|
+
if (node === range.endContainer) return -1;
|
|
631
|
+
if (node.nodeType === Node.ELEMENT_NODE && node.tagName === "SPAN") return 1;
|
|
632
|
+
return 0;
|
|
633
|
+
}) === 1) return true;
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
getSelectedLocationForNew(range, text) {
|
|
637
|
+
if (!range || this.selHasAnySpan(range)) return null;
|
|
638
|
+
const yBounds = this.getYBoundsFromRange(range, true);
|
|
639
|
+
if (!yBounds) return null;
|
|
640
|
+
const lines = this.getLines(text);
|
|
641
|
+
const startLine = this.textLineToString(lines[yBounds.start - 1]);
|
|
642
|
+
const endLine = this.textLineToString(lines[yBounds.end - 1]);
|
|
643
|
+
const startBaseOffset = this.getNodeBaseOffset(range.startContainer);
|
|
644
|
+
const endBaseOffset = this.getNodeBaseOffset(range.endContainer);
|
|
645
|
+
const startLineEndOffset = yBounds.start !== yBounds.end ? startLine.length : range.endOffset + startBaseOffset;
|
|
646
|
+
const start = this.getStartCoordsFromRange(range.startOffset + startBaseOffset, startLineEndOffset, startLine);
|
|
647
|
+
start.y = yBounds.start;
|
|
648
|
+
const end = yBounds.start !== yBounds.end ? this.getEndCoordsFromRange(0, range.endOffset + endBaseOffset, endLine) : this.getEndCoordsFromRange(range.startOffset + endBaseOffset, range.endOffset + endBaseOffset, endLine);
|
|
649
|
+
end.y = yBounds.end;
|
|
650
|
+
const singleToken = start.y === end.y && start.x === end.x;
|
|
651
|
+
const coords = this.buildCoords(start, end, singleToken);
|
|
652
|
+
return TokenLocation.parse(coords);
|
|
653
|
+
}
|
|
654
|
+
getSelectedRange() {
|
|
655
|
+
const sel = window.getSelection();
|
|
656
|
+
if (!sel || sel.isCollapsed) return null;
|
|
657
|
+
return sel.getRangeAt(0);
|
|
658
|
+
}
|
|
659
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
660
|
+
minVersion: "12.0.0",
|
|
661
|
+
version: "22.2.0",
|
|
662
|
+
ngImport: i0,
|
|
663
|
+
type: TextLayerService,
|
|
664
|
+
deps: [],
|
|
665
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
666
|
+
});
|
|
667
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
668
|
+
minVersion: "12.0.0",
|
|
669
|
+
version: "22.2.0",
|
|
670
|
+
ngImport: i0,
|
|
671
|
+
type: TextLayerService,
|
|
672
|
+
providedIn: "root"
|
|
673
|
+
});
|
|
674
|
+
};
|
|
675
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
676
|
+
minVersion: "12.0.0",
|
|
677
|
+
version: "22.2.0",
|
|
678
|
+
ngImport: i0,
|
|
679
|
+
type: TextLayerService,
|
|
680
|
+
decorators: [{
|
|
681
|
+
type: Injectable,
|
|
682
|
+
args: [{ providedIn: "root" }]
|
|
683
|
+
}],
|
|
684
|
+
ctorParameters: () => []
|
|
685
|
+
});
|
|
1280
686
|
export { DataPinValueType, FlagMatching, LibraryRouteService, PendingChangesGuard, SortPipe, TextLayerService, TextRange, TokenLocation, TokenPoint, pendingChangesGuard };
|
|
1281
|
-
|
|
687
|
+
|
|
688
|
+
//# sourceMappingURL=myrmidon-cadmus-core.mjs.map
|