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