@myrmidon/cadmus-layer-demo 20.0.0 → 20.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
# CadmusLayerDemo
|
|
2
|
-
|
|
3
|
-
- 📦 `@myrmidon/cadmus-layer-demo`
|
|
4
|
-
|
|
5
|
-
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.0.0.
|
|
6
|
-
|
|
7
|
-
This library contains the Cadmus layers demo page. It is mostly used for developing or demonstrative purposes.
|
|
1
|
+
# CadmusLayerDemo
|
|
2
|
+
|
|
3
|
+
- 📦 `@myrmidon/cadmus-layer-demo`
|
|
4
|
+
|
|
5
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.0.0.
|
|
6
|
+
|
|
7
|
+
This library contains the Cadmus text layers demo page. It is mostly used for developing or demonstrative purposes, as a playground for the token-based coordinates system used by text layers.
|
|
8
|
+
|
|
9
|
+
The page uses the same component used by the text layer part editor, i.e. `DecoratedTokenTextComponent` from `@myrmidon/cadmus-ui` (see its documentation for the details of the coordinates system). Users can:
|
|
10
|
+
|
|
11
|
+
- enter any base text, which is displayed live. Each line is a block.
|
|
12
|
+
- add fragments, either by typing their location (e.g. `1.2@2x2`), or by selecting any portion of the text, which shows the selection's location and text. Like the backend does when adding a fragment to a layer part, adding a fragment removes any existing fragment overlapping it.
|
|
13
|
+
- see that the characters of fragments are highlighted and blocked, so that a new selection can never overlap them.
|
|
14
|
+
- click a fragment (or its chip in the fragments list) to pick it, viewing its location and text, or removing it.
|
|
15
|
+
- zoom the text, find text in it, or select a portion of it by typing its coordinates in the box below the text.
|
|
16
|
+
|
|
17
|
+
## History
|
|
18
|
+
|
|
19
|
+
- 2026-11-19: refactored the page for the new `DecoratedTokenTextComponent`, based on `@myrmidon/cadmus-text-segment`. The text is now rendered live (no more render button), and the DOM-based selection of the legacy `TextLayerService` is replaced by the segmented text selection.
|
|
@@ -1,74 +1,92 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { ChangeDetectionStrategy, Component,
|
|
3
|
-
import { FormField, FormRoot, form, maxLength
|
|
4
|
-
import { MatCard, MatCardContent, MatCardHeader } from "@angular/material/card";
|
|
5
|
-
import {
|
|
2
|
+
import { ChangeDetectionStrategy, Component, computed, signal, viewChild } from "@angular/core";
|
|
3
|
+
import { FormField, FormRoot, form, maxLength } from "@angular/forms/signals";
|
|
4
|
+
import { MatCard, MatCardAvatar, MatCardContent, MatCardHeader, MatCardSubtitle, MatCardTitle } from "@angular/material/card";
|
|
5
|
+
import { MatButton, MatIconButton } from "@angular/material/button";
|
|
6
|
+
import { MatChip, MatChipRemove, MatChipSet } from "@angular/material/chips";
|
|
7
|
+
import { MatError, MatFormField, MatHint, MatLabel } from "@angular/material/form-field";
|
|
8
|
+
import { MatIcon } from "@angular/material/icon";
|
|
6
9
|
import { MatInput } from "@angular/material/input";
|
|
7
|
-
import {
|
|
8
|
-
import { MatIconButton } from "@angular/material/button";
|
|
10
|
+
import { MatExpansionPanel, MatExpansionPanelHeader, MatExpansionPanelTitle } from "@angular/material/expansion";
|
|
9
11
|
import { MatTooltip } from "@angular/material/tooltip";
|
|
10
|
-
import { MatIcon } from "@angular/material/icon";
|
|
11
|
-
import { SafeHtmlPipe } from "@myrmidon/ngx-tools";
|
|
12
|
-
import * as i1 from "@myrmidon/cadmus-core";
|
|
13
12
|
import { TokenLocation } from "@myrmidon/cadmus-core";
|
|
13
|
+
import { DecoratedTokenTextComponent, TokenTextSegmenter } from "@myrmidon/cadmus-ui";
|
|
14
|
+
const LAYER_DEMO_TEXT = "alpha beta\ngamma\ndelta epsilon waw\nzeta";
|
|
14
15
|
var LayerDemoComponent = class LayerDemoComponent {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
_segmenter = new TokenTextSegmenter();
|
|
17
|
+
_textView = viewChild(DecoratedTokenTextComponent, ...ngDevMode ? [{ debugName: "_textView" }] : /* istanbul ignore next */ []);
|
|
17
18
|
locations = signal([], ...ngDevMode ? [{ debugName: "locations" }] : /* istanbul ignore next */ []);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
textSize = signal(
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
selectedLocation = signal(void 0, ...ngDevMode ? [{ debugName: "selectedLocation" }] : /* istanbul ignore next */ []);
|
|
20
|
+
selection = signal(null, ...ngDevMode ? [{ debugName: "selection" }] : /* istanbul ignore next */ []);
|
|
21
|
+
textSize = signal(16, ...ngDevMode ? [{ debugName: "textSize" }] : /* istanbul ignore next */ []);
|
|
22
|
+
locationError = signal(null, ...ngDevMode ? [{ debugName: "locationError" }] : /* istanbul ignore next */ []);
|
|
23
|
+
demoForm = form(signal({
|
|
24
|
+
text: LAYER_DEMO_TEXT,
|
|
23
25
|
location: "1.2@2x2"
|
|
24
26
|
}), (path) => {
|
|
25
|
-
maxLength(path.text,
|
|
26
|
-
required(path.location);
|
|
27
|
+
maxLength(path.text, 5e3);
|
|
27
28
|
}, { submission: {
|
|
28
29
|
action: async () => {
|
|
29
|
-
this.
|
|
30
|
+
this.addTypedLocation();
|
|
30
31
|
},
|
|
31
32
|
ignoreValidators: "all"
|
|
32
33
|
} });
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
text = computed(() => this.demoForm.text().value() || "", ...ngDevMode ? [{ debugName: "text" }] : /* istanbul ignore next */ []);
|
|
35
|
+
_blocks = computed(() => this._segmenter.getBlocks(this.text()), ...ngDevMode ? [{ debugName: "_blocks" }] : /* istanbul ignore next */ []);
|
|
36
|
+
selectedText = computed(() => {
|
|
37
|
+
const loc = this.selectedLocation();
|
|
38
|
+
if (!loc) return "";
|
|
39
|
+
const segments = this._segmenter.getLocationSegments(this._blocks(), loc);
|
|
40
|
+
return segments ? this._segmenter.getSegmentsText(this._blocks(), segments) : "";
|
|
41
|
+
}, ...ngDevMode ? [{ debugName: "selectedText" }] : /* istanbul ignore next */ []);
|
|
36
42
|
makeLarger() {
|
|
37
|
-
|
|
38
|
-
if (size > 24) return;
|
|
39
|
-
this.textSize.set(size);
|
|
43
|
+
this.textSize.update((size) => Math.min(24, size + 2));
|
|
40
44
|
}
|
|
41
45
|
makeSmaller() {
|
|
42
|
-
|
|
43
|
-
if (size < 12) return;
|
|
44
|
-
this.textSize.set(size);
|
|
46
|
+
this.textSize.update((size) => Math.max(12, size - 2));
|
|
45
47
|
}
|
|
46
|
-
removeOverlaps(loc) {
|
|
47
|
-
|
|
48
|
-
for (let i = locations.length - 1; i > -1; i--) {
|
|
49
|
-
if (loc === locations[i]) continue;
|
|
50
|
-
if (loc.overlaps(locations[i])) locations.splice(i, 1);
|
|
51
|
-
}
|
|
52
|
-
this.locations.set(locations);
|
|
48
|
+
removeOverlaps(loc, locations) {
|
|
49
|
+
for (let i = locations.length - 1; i > -1; i--) if (loc !== locations[i] && loc.overlaps(locations[i])) locations.splice(i, 1);
|
|
53
50
|
}
|
|
54
|
-
addLocation() {
|
|
55
|
-
const location = this.rendition.location().value();
|
|
56
|
-
if (!location) return;
|
|
57
|
-
const loc = TokenLocation.parse(location);
|
|
58
|
-
if (!loc) return;
|
|
51
|
+
addLocation(loc) {
|
|
59
52
|
const locations = [...this.locations()];
|
|
60
53
|
let done = false;
|
|
61
54
|
for (let i = 0; i < locations.length && !done; i++) {
|
|
62
55
|
const n = loc.compareTo(locations[i]);
|
|
63
|
-
if (n === 0) return;
|
|
56
|
+
if (n === 0) return false;
|
|
64
57
|
if (n < 0) {
|
|
65
58
|
locations.splice(i, 0, loc);
|
|
66
59
|
done = true;
|
|
67
60
|
}
|
|
68
61
|
}
|
|
69
62
|
if (!done) locations.push(loc);
|
|
63
|
+
this.removeOverlaps(loc, locations);
|
|
70
64
|
this.locations.set(locations);
|
|
71
|
-
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
addTypedLocation() {
|
|
68
|
+
const value = this.demoForm.location().value()?.trim();
|
|
69
|
+
if (!value) {
|
|
70
|
+
this.locationError.set(null);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const loc = TokenLocation.parse(value);
|
|
74
|
+
if (!loc || !this._segmenter.getCoordsSegments(this._blocks(), loc.toString())) {
|
|
75
|
+
this.locationError.set(loc ? "location not found in text" : "invalid location");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.locationError.set(null);
|
|
79
|
+
this.addLocation(loc);
|
|
80
|
+
}
|
|
81
|
+
addSelection() {
|
|
82
|
+
const loc = this.selection()?.location;
|
|
83
|
+
if (loc && this.addLocation(loc)) this.selection.set(null);
|
|
84
|
+
}
|
|
85
|
+
onSelectionChange(selection) {
|
|
86
|
+
this.selection.set(selection.coords ? selection : null);
|
|
87
|
+
}
|
|
88
|
+
pickLocation(loc) {
|
|
89
|
+
this.selectedLocation.set(loc);
|
|
72
90
|
}
|
|
73
91
|
removeLocation(loc) {
|
|
74
92
|
const i = this.locations().indexOf(loc);
|
|
@@ -76,47 +94,41 @@ var LayerDemoComponent = class LayerDemoComponent {
|
|
|
76
94
|
const locations = [...this.locations()];
|
|
77
95
|
locations.splice(i, 1);
|
|
78
96
|
this.locations.set(locations);
|
|
97
|
+
if (this.selectedLocation() === loc) this.selectedLocation.set(void 0);
|
|
79
98
|
}
|
|
80
99
|
}
|
|
81
100
|
clearLocations() {
|
|
82
101
|
this.locations.set([]);
|
|
102
|
+
this.selectedLocation.set(void 0);
|
|
83
103
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this.result.set(this._textLayerService.render(text, this.locations()));
|
|
88
|
-
}
|
|
89
|
-
getLocationForNew() {
|
|
90
|
-
const text = this.rendition.text().value();
|
|
91
|
-
if (!text) return;
|
|
92
|
-
this.userLocation.set(this._textLayerService.getSelectedLocationForNew(this._textLayerService.getSelectedRange(), text) || void 0);
|
|
93
|
-
}
|
|
94
|
-
getLocationForEdit() {
|
|
95
|
-
this.userLocation.set(this._textLayerService.getSelectedLocationForEdit(this._textLayerService.getSelectedRange()) || void 0);
|
|
104
|
+
clearSelection() {
|
|
105
|
+
this._textView()?.clearSelection();
|
|
106
|
+
this.selection.set(null);
|
|
96
107
|
}
|
|
97
108
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
98
109
|
minVersion: "12.0.0",
|
|
99
|
-
version: "22.
|
|
110
|
+
version: "22.3.0",
|
|
100
111
|
ngImport: i0,
|
|
101
112
|
type: LayerDemoComponent,
|
|
102
|
-
deps: [
|
|
113
|
+
deps: [],
|
|
103
114
|
target: i0.ɵɵFactoryTarget.Component
|
|
104
115
|
});
|
|
105
116
|
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
106
117
|
minVersion: "17.0.0",
|
|
107
|
-
version: "22.
|
|
118
|
+
version: "22.3.0",
|
|
108
119
|
type: LayerDemoComponent,
|
|
109
120
|
isStandalone: true,
|
|
110
121
|
selector: "cadmus-layer-demo",
|
|
111
122
|
viewQueries: [{
|
|
112
|
-
propertyName: "
|
|
123
|
+
propertyName: "_textView",
|
|
113
124
|
first: true,
|
|
114
|
-
predicate:
|
|
115
|
-
descendants: true
|
|
125
|
+
predicate: DecoratedTokenTextComponent,
|
|
126
|
+
descendants: true,
|
|
127
|
+
isSignal: true
|
|
116
128
|
}],
|
|
117
129
|
ngImport: i0,
|
|
118
|
-
template: "<mat-card appearance=\"outlined\">\
|
|
119
|
-
styles: ["
|
|
130
|
+
template: "<mat-card appearance=\"outlined\">\n <mat-card-header>\n <mat-icon mat-card-avatar>layers</mat-icon>\n <mat-card-title>Text Layers Demo</mat-card-title>\n <mat-card-subtitle>token-based coordinates</mat-card-subtitle>\n </mat-card-header>\n <mat-card-content>\n <mat-expansion-panel>\n <mat-expansion-panel-header>\n <mat-panel-title>How it works</mat-panel-title>\n </mat-expansion-panel-header>\n <article>\n <p>\n A text layer annotates portions of a base text with fragments. Each\n fragment has a <strong>location</strong> with token-based\n coordinates, where a token is any sequence of non-whitespace\n characters. A point is <code>Y.X@AxR</code>:\n </p>\n <ul>\n <li><code>Y</code>: the line number (1-N).</li>\n <li><code>X</code>: the token number in the line (1-N).</li>\n <li>\n optionally, when not selecting whole tokens: <code>A</code> is\n the first character in the token (1-N), and <code>R</code> the\n count of characters (omitted when 1).\n </li>\n </ul>\n <p>\n A selection spanning several tokens has a start and an end point\n separated by <code>-</code>: the start point picks from its\n <code>A</code> to the end of its token, the end point picks the\n first <code>R</code> characters of its token. Whitespace at the\n edges of a selection is ignored. For instance, with the default\n text: <code>2.1</code> is <em>gamma</em>, <code>1.2@2x2</code>\n is <em>et</em>, <code>3.1@4x2-3.2@1</code> is\n <em>ta e</em>.\n </p>\n <p>\n Fragments in the same layer never overlap: so their characters are\n highlighted and <strong>blocked</strong>, and a selection always\n stops before them. Click a fragment to pick it; select any other\n portion of text (by dragging, SHIFT+clicking, or with SHIFT+arrows)\n to get its location, and add it as a new fragment. You can also\n type coordinates in the box below the text to select them.\n </p>\n </article>\n </mat-expansion-panel>\n\n <div class=\"layout\">\n <!-- input -->\n <form class=\"input\" [formRoot]=\"demoForm\">\n <mat-form-field class=\"text-field\">\n <mat-label>base text</mat-label>\n <textarea\n matInput\n id=\"text\"\n rows=\"6\"\n spellcheck=\"false\"\n [formField]=\"demoForm.text\"\n ></textarea>\n <mat-hint>each line is a block</mat-hint>\n </mat-form-field>\n\n <div class=\"location-row\">\n <mat-form-field>\n <mat-label>location</mat-label>\n <input\n matInput\n id=\"location\"\n spellcheck=\"false\"\n autocomplete=\"off\"\n [formField]=\"demoForm.location\"\n />\n @if (locationError(); as error) {\n <mat-error>{{ error }}</mat-error>\n } @else {\n <mat-hint>Y.X@AxR or Y.X@AxR-Y.X@AxR</mat-hint>\n }\n </mat-form-field>\n <button\n mat-icon-button\n type=\"submit\"\n matTooltip=\"Add a fragment at the typed location\"\n >\n <mat-icon class=\"mat-primary\">add_circle</mat-icon>\n </button>\n </div>\n\n <!-- fragments -->\n <div class=\"fragments\">\n <div class=\"fragments-header\">\n <span>fragments: {{ locations().length }}</span>\n <button\n mat-icon-button\n type=\"button\"\n matTooltip=\"Remove all the fragments\"\n [disabled]=\"!locations().length\"\n (click)=\"clearLocations()\"\n >\n <mat-icon class=\"mat-warn\">delete_sweep</mat-icon>\n </button>\n </div>\n <mat-chip-set aria-label=\"fragments\">\n @for (loc of locations(); track loc) {\n <mat-chip\n [highlighted]=\"selectedLocation() === loc\"\n (click)=\"pickLocation(loc)\"\n (removed)=\"removeLocation(loc)\"\n >\n {{ loc.toString() }}\n <button\n matChipRemove\n type=\"button\"\n [attr.aria-label]=\"'remove ' + loc.toString()\"\n >\n <mat-icon>cancel</mat-icon>\n </button>\n </mat-chip>\n }\n </mat-chip-set>\n </div>\n </form>\n\n <!-- text -->\n <div class=\"output\">\n <div class=\"size-bar\">\n <button\n mat-icon-button\n type=\"button\"\n matTooltip=\"Larger text\"\n (click)=\"makeLarger()\"\n [disabled]=\"textSize() >= 24\"\n >\n <mat-icon>format_size</mat-icon>\n </button>\n <button\n mat-icon-button\n type=\"button\"\n matTooltip=\"Smaller text\"\n (click)=\"makeSmaller()\"\n [disabled]=\"textSize() <= 12\"\n >\n <mat-icon>text_fields</mat-icon>\n </button>\n </div>\n <cadmus-decorated-token-text\n [baseText]=\"text()\"\n [locations]=\"locations()\"\n [fontSize]=\"textSize()\"\n [showToolbar]=\"true\"\n [(selectedLocation)]=\"selectedLocation\"\n (selectionChange)=\"onSelectionChange($event)\"\n />\n\n <!-- details -->\n <div class=\"details\">\n <div class=\"detail\">\n <div class=\"detail-title\">\n <mat-icon>highlight_alt</mat-icon> selection\n </div>\n @if (selection(); as sel) {\n <div class=\"detail-body\">\n <code class=\"loc\">{{ sel.coords }}</code>\n <span class=\"text\">{{ sel.text }}</span>\n @if (sel.overlapping) {\n <span class=\"warn\">overlaps a fragment</span>\n }\n </div>\n <div class=\"detail-actions\">\n <button\n mat-flat-button\n type=\"button\"\n [disabled]=\"!sel.location\"\n (click)=\"addSelection()\"\n >\n <mat-icon>add_circle</mat-icon>\n add fragment\n </button>\n <button mat-button type=\"button\" (click)=\"clearSelection()\">\n clear\n </button>\n </div>\n } @else {\n <div class=\"detail-body muted\">\n select any portion of the text\n </div>\n }\n </div>\n\n <div class=\"detail\">\n <div class=\"detail-title\">\n <mat-icon>bookmark</mat-icon> picked fragment\n </div>\n @if (selectedLocation(); as loc) {\n <div class=\"detail-body\">\n <code class=\"loc\">{{ loc.toString() }}</code>\n <span class=\"text\">{{ selectedText() }}</span>\n </div>\n <div class=\"detail-actions\">\n <button\n mat-button\n type=\"button\"\n class=\"mat-warn\"\n (click)=\"removeLocation(loc)\"\n >\n <mat-icon>remove_circle</mat-icon>\n remove\n </button>\n </div>\n } @else {\n <div class=\"detail-body muted\">click a fragment to pick it</div>\n }\n </div>\n </div>\n </div>\n </div>\n </mat-card-content>\n</mat-card>\n",
|
|
131
|
+
styles: ["article{column-width:24em;font:var(--mat-sys-body-medium)}article code,code.loc{font-family:Roboto Mono,Consolas,monospace}.layout{display:grid;grid-template-columns:minmax(260px,1fr) minmax(0,2fr);gap:16px;margin-top:16px}@media(max-width:800px){.layout{grid-template-columns:minmax(0,1fr)}}.input{display:flex;flex-direction:column;gap:8px;min-width:0}.text-field{width:100%}textarea#text{font-family:Roboto Mono,Consolas,monospace}.location-row{display:flex;align-items:flex-start;gap:4px}.location-row mat-form-field{flex:1 1 auto}.location-row input{font-family:Roboto Mono,Consolas,monospace}.location-row button{margin-top:8px}.fragments-header{display:flex;align-items:center;justify-content:space-between;font:var(--mat-sys-title-small)}.fragments mat-chip{font-family:Roboto Mono,Consolas,monospace;cursor:pointer}.output{display:flex;flex-direction:column;gap:8px;min-width:0}.size-bar{display:flex;justify-content:flex-end}cadmus-decorated-token-text{--cadmus-decorated-token-text-max-height: 60vh}.details{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:12px}.detail{display:flex;flex-direction:column;gap:6px;padding:8px 12px;border:1px solid var(--mat-sys-outline-variant);border-radius:var(--mat-sys-corner-small, 4px);background-color:var(--mat-sys-surface-container-low)}.detail-title{display:flex;align-items:center;gap:6px;font:var(--mat-sys-title-small);color:var(--mat-sys-on-surface-variant)}.detail-title mat-icon{font-size:18px;width:18px;height:18px}.detail-body{display:flex;flex-wrap:wrap;align-items:baseline;gap:4px 12px;min-height:24px}.detail-body .text{font-style:italic;overflow-wrap:anywhere}.detail-body .warn{color:var(--mat-sys-error);font:var(--mat-sys-label-medium)}.detail-actions{display:flex;gap:8px}.muted{color:var(--mat-sys-on-surface-variant);font:var(--mat-sys-body-small)}\n"],
|
|
120
132
|
dependencies: [
|
|
121
133
|
{
|
|
122
134
|
kind: "component",
|
|
@@ -130,23 +142,72 @@ var LayerDemoComponent = class LayerDemoComponent {
|
|
|
130
142
|
type: MatCardHeader,
|
|
131
143
|
selector: "mat-card-header"
|
|
132
144
|
},
|
|
145
|
+
{
|
|
146
|
+
kind: "directive",
|
|
147
|
+
type: MatCardAvatar,
|
|
148
|
+
selector: "[mat-card-avatar], [matCardAvatar]"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
kind: "directive",
|
|
152
|
+
type: MatCardTitle,
|
|
153
|
+
selector: "mat-card-title, [mat-card-title], [matCardTitle]"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
kind: "directive",
|
|
157
|
+
type: MatCardSubtitle,
|
|
158
|
+
selector: "mat-card-subtitle, [mat-card-subtitle], [matCardSubtitle]"
|
|
159
|
+
},
|
|
133
160
|
{
|
|
134
161
|
kind: "directive",
|
|
135
162
|
type: MatCardContent,
|
|
136
163
|
selector: "mat-card-content"
|
|
137
164
|
},
|
|
138
165
|
{
|
|
139
|
-
kind: "
|
|
140
|
-
type:
|
|
141
|
-
selector: "[
|
|
142
|
-
inputs: ["
|
|
143
|
-
exportAs: ["
|
|
166
|
+
kind: "component",
|
|
167
|
+
type: MatButton,
|
|
168
|
+
selector: " button[matButton], a[matButton], button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button], a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button] ",
|
|
169
|
+
inputs: ["matButton"],
|
|
170
|
+
exportAs: ["matButton", "matAnchor"]
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
kind: "component",
|
|
174
|
+
type: MatIconButton,
|
|
175
|
+
selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]",
|
|
176
|
+
exportAs: ["matButton", "matAnchor"]
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
kind: "component",
|
|
180
|
+
type: MatChipSet,
|
|
181
|
+
selector: "mat-chip-set",
|
|
182
|
+
inputs: [
|
|
183
|
+
"disabled",
|
|
184
|
+
"role",
|
|
185
|
+
"tabIndex"
|
|
186
|
+
]
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
kind: "component",
|
|
190
|
+
type: MatChip,
|
|
191
|
+
selector: "mat-basic-chip, [mat-basic-chip], mat-chip, [mat-chip]",
|
|
192
|
+
inputs: [
|
|
193
|
+
"role",
|
|
194
|
+
"id",
|
|
195
|
+
"aria-label",
|
|
196
|
+
"aria-description",
|
|
197
|
+
"value",
|
|
198
|
+
"color",
|
|
199
|
+
"removable",
|
|
200
|
+
"highlighted",
|
|
201
|
+
"disableRipple",
|
|
202
|
+
"disabled"
|
|
203
|
+
],
|
|
204
|
+
outputs: ["removed", "destroyed"],
|
|
205
|
+
exportAs: ["matChip"]
|
|
144
206
|
},
|
|
145
207
|
{
|
|
146
208
|
kind: "directive",
|
|
147
|
-
type:
|
|
148
|
-
selector: "
|
|
149
|
-
inputs: ["formRoot"]
|
|
209
|
+
type: MatChipRemove,
|
|
210
|
+
selector: "[matChipRemove]"
|
|
150
211
|
},
|
|
151
212
|
{
|
|
152
213
|
kind: "component",
|
|
@@ -167,6 +228,18 @@ var LayerDemoComponent = class LayerDemoComponent {
|
|
|
167
228
|
type: MatLabel,
|
|
168
229
|
selector: "mat-label"
|
|
169
230
|
},
|
|
231
|
+
{
|
|
232
|
+
kind: "directive",
|
|
233
|
+
type: MatHint,
|
|
234
|
+
selector: "mat-hint",
|
|
235
|
+
inputs: ["align", "id"]
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
kind: "directive",
|
|
239
|
+
type: MatError,
|
|
240
|
+
selector: "mat-error, [matError]",
|
|
241
|
+
inputs: ["id"]
|
|
242
|
+
},
|
|
170
243
|
{
|
|
171
244
|
kind: "directive",
|
|
172
245
|
type: MatInput,
|
|
@@ -186,24 +259,18 @@ var LayerDemoComponent = class LayerDemoComponent {
|
|
|
186
259
|
],
|
|
187
260
|
exportAs: ["matInput"]
|
|
188
261
|
},
|
|
189
|
-
{
|
|
190
|
-
kind: "directive",
|
|
191
|
-
type: MatHint,
|
|
192
|
-
selector: "mat-hint",
|
|
193
|
-
inputs: ["align", "id"]
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
kind: "component",
|
|
197
|
-
type: MatToolbar,
|
|
198
|
-
selector: "mat-toolbar",
|
|
199
|
-
inputs: ["color"],
|
|
200
|
-
exportAs: ["matToolbar"]
|
|
201
|
-
},
|
|
202
262
|
{
|
|
203
263
|
kind: "component",
|
|
204
|
-
type:
|
|
205
|
-
selector: "
|
|
206
|
-
|
|
264
|
+
type: MatIcon,
|
|
265
|
+
selector: "mat-icon",
|
|
266
|
+
inputs: [
|
|
267
|
+
"color",
|
|
268
|
+
"inline",
|
|
269
|
+
"svgIcon",
|
|
270
|
+
"fontSet",
|
|
271
|
+
"fontIcon"
|
|
272
|
+
],
|
|
273
|
+
exportAs: ["matIcon"]
|
|
207
274
|
},
|
|
208
275
|
{
|
|
209
276
|
kind: "directive",
|
|
@@ -223,21 +290,54 @@ var LayerDemoComponent = class LayerDemoComponent {
|
|
|
223
290
|
},
|
|
224
291
|
{
|
|
225
292
|
kind: "component",
|
|
226
|
-
type:
|
|
227
|
-
selector: "mat-
|
|
293
|
+
type: MatExpansionPanel,
|
|
294
|
+
selector: "mat-expansion-panel",
|
|
295
|
+
inputs: ["hideToggle", "togglePosition"],
|
|
296
|
+
outputs: ["afterExpand", "afterCollapse"],
|
|
297
|
+
exportAs: ["matExpansionPanel"]
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
kind: "component",
|
|
301
|
+
type: MatExpansionPanelHeader,
|
|
302
|
+
selector: "mat-expansion-panel-header",
|
|
228
303
|
inputs: [
|
|
229
|
-
"
|
|
230
|
-
"
|
|
231
|
-
"
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
304
|
+
"expandedHeight",
|
|
305
|
+
"collapsedHeight",
|
|
306
|
+
"tabIndex"
|
|
307
|
+
]
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
kind: "directive",
|
|
311
|
+
type: MatExpansionPanelTitle,
|
|
312
|
+
selector: "mat-panel-title"
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
kind: "directive",
|
|
316
|
+
type: FormField,
|
|
317
|
+
selector: "[formField]",
|
|
318
|
+
inputs: ["formField"],
|
|
319
|
+
exportAs: ["formField"]
|
|
236
320
|
},
|
|
237
321
|
{
|
|
238
|
-
kind: "
|
|
239
|
-
type:
|
|
240
|
-
|
|
322
|
+
kind: "directive",
|
|
323
|
+
type: FormRoot,
|
|
324
|
+
selector: "form[formRoot]",
|
|
325
|
+
inputs: ["formRoot"]
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
kind: "component",
|
|
329
|
+
type: DecoratedTokenTextComponent,
|
|
330
|
+
selector: "cadmus-decorated-token-text",
|
|
331
|
+
inputs: [
|
|
332
|
+
"baseText",
|
|
333
|
+
"locations",
|
|
334
|
+
"selectedLocation",
|
|
335
|
+
"fontSize",
|
|
336
|
+
"showToolbar",
|
|
337
|
+
"settings",
|
|
338
|
+
"colors"
|
|
339
|
+
],
|
|
340
|
+
outputs: ["selectedLocationChange", "selectionChange"]
|
|
241
341
|
}
|
|
242
342
|
],
|
|
243
343
|
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
@@ -245,7 +345,7 @@ var LayerDemoComponent = class LayerDemoComponent {
|
|
|
245
345
|
};
|
|
246
346
|
i0.ɵɵngDeclareClassMetadata({
|
|
247
347
|
minVersion: "12.0.0",
|
|
248
|
-
version: "22.
|
|
348
|
+
version: "22.3.0",
|
|
249
349
|
ngImport: i0,
|
|
250
350
|
type: LayerDemoComponent,
|
|
251
351
|
decorators: [{
|
|
@@ -256,29 +356,38 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
256
356
|
imports: [
|
|
257
357
|
MatCard,
|
|
258
358
|
MatCardHeader,
|
|
359
|
+
MatCardAvatar,
|
|
360
|
+
MatCardTitle,
|
|
361
|
+
MatCardSubtitle,
|
|
259
362
|
MatCardContent,
|
|
260
|
-
|
|
261
|
-
|
|
363
|
+
MatButton,
|
|
364
|
+
MatIconButton,
|
|
365
|
+
MatChipSet,
|
|
366
|
+
MatChip,
|
|
367
|
+
MatChipRemove,
|
|
262
368
|
MatFormField,
|
|
263
369
|
MatLabel,
|
|
264
|
-
MatInput,
|
|
265
370
|
MatHint,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
MatTooltip,
|
|
371
|
+
MatError,
|
|
372
|
+
MatInput,
|
|
269
373
|
MatIcon,
|
|
270
|
-
|
|
374
|
+
MatTooltip,
|
|
375
|
+
MatExpansionPanel,
|
|
376
|
+
MatExpansionPanelHeader,
|
|
377
|
+
MatExpansionPanelTitle,
|
|
378
|
+
FormField,
|
|
379
|
+
FormRoot,
|
|
380
|
+
DecoratedTokenTextComponent
|
|
271
381
|
],
|
|
272
|
-
template: "<mat-card appearance=\"outlined\">\
|
|
273
|
-
styles: ["
|
|
382
|
+
template: "<mat-card appearance=\"outlined\">\n <mat-card-header>\n <mat-icon mat-card-avatar>layers</mat-icon>\n <mat-card-title>Text Layers Demo</mat-card-title>\n <mat-card-subtitle>token-based coordinates</mat-card-subtitle>\n </mat-card-header>\n <mat-card-content>\n <mat-expansion-panel>\n <mat-expansion-panel-header>\n <mat-panel-title>How it works</mat-panel-title>\n </mat-expansion-panel-header>\n <article>\n <p>\n A text layer annotates portions of a base text with fragments. Each\n fragment has a <strong>location</strong> with token-based\n coordinates, where a token is any sequence of non-whitespace\n characters. A point is <code>Y.X@AxR</code>:\n </p>\n <ul>\n <li><code>Y</code>: the line number (1-N).</li>\n <li><code>X</code>: the token number in the line (1-N).</li>\n <li>\n optionally, when not selecting whole tokens: <code>A</code> is\n the first character in the token (1-N), and <code>R</code> the\n count of characters (omitted when 1).\n </li>\n </ul>\n <p>\n A selection spanning several tokens has a start and an end point\n separated by <code>-</code>: the start point picks from its\n <code>A</code> to the end of its token, the end point picks the\n first <code>R</code> characters of its token. Whitespace at the\n edges of a selection is ignored. For instance, with the default\n text: <code>2.1</code> is <em>gamma</em>, <code>1.2@2x2</code>\n is <em>et</em>, <code>3.1@4x2-3.2@1</code> is\n <em>ta e</em>.\n </p>\n <p>\n Fragments in the same layer never overlap: so their characters are\n highlighted and <strong>blocked</strong>, and a selection always\n stops before them. Click a fragment to pick it; select any other\n portion of text (by dragging, SHIFT+clicking, or with SHIFT+arrows)\n to get its location, and add it as a new fragment. You can also\n type coordinates in the box below the text to select them.\n </p>\n </article>\n </mat-expansion-panel>\n\n <div class=\"layout\">\n <!-- input -->\n <form class=\"input\" [formRoot]=\"demoForm\">\n <mat-form-field class=\"text-field\">\n <mat-label>base text</mat-label>\n <textarea\n matInput\n id=\"text\"\n rows=\"6\"\n spellcheck=\"false\"\n [formField]=\"demoForm.text\"\n ></textarea>\n <mat-hint>each line is a block</mat-hint>\n </mat-form-field>\n\n <div class=\"location-row\">\n <mat-form-field>\n <mat-label>location</mat-label>\n <input\n matInput\n id=\"location\"\n spellcheck=\"false\"\n autocomplete=\"off\"\n [formField]=\"demoForm.location\"\n />\n @if (locationError(); as error) {\n <mat-error>{{ error }}</mat-error>\n } @else {\n <mat-hint>Y.X@AxR or Y.X@AxR-Y.X@AxR</mat-hint>\n }\n </mat-form-field>\n <button\n mat-icon-button\n type=\"submit\"\n matTooltip=\"Add a fragment at the typed location\"\n >\n <mat-icon class=\"mat-primary\">add_circle</mat-icon>\n </button>\n </div>\n\n <!-- fragments -->\n <div class=\"fragments\">\n <div class=\"fragments-header\">\n <span>fragments: {{ locations().length }}</span>\n <button\n mat-icon-button\n type=\"button\"\n matTooltip=\"Remove all the fragments\"\n [disabled]=\"!locations().length\"\n (click)=\"clearLocations()\"\n >\n <mat-icon class=\"mat-warn\">delete_sweep</mat-icon>\n </button>\n </div>\n <mat-chip-set aria-label=\"fragments\">\n @for (loc of locations(); track loc) {\n <mat-chip\n [highlighted]=\"selectedLocation() === loc\"\n (click)=\"pickLocation(loc)\"\n (removed)=\"removeLocation(loc)\"\n >\n {{ loc.toString() }}\n <button\n matChipRemove\n type=\"button\"\n [attr.aria-label]=\"'remove ' + loc.toString()\"\n >\n <mat-icon>cancel</mat-icon>\n </button>\n </mat-chip>\n }\n </mat-chip-set>\n </div>\n </form>\n\n <!-- text -->\n <div class=\"output\">\n <div class=\"size-bar\">\n <button\n mat-icon-button\n type=\"button\"\n matTooltip=\"Larger text\"\n (click)=\"makeLarger()\"\n [disabled]=\"textSize() >= 24\"\n >\n <mat-icon>format_size</mat-icon>\n </button>\n <button\n mat-icon-button\n type=\"button\"\n matTooltip=\"Smaller text\"\n (click)=\"makeSmaller()\"\n [disabled]=\"textSize() <= 12\"\n >\n <mat-icon>text_fields</mat-icon>\n </button>\n </div>\n <cadmus-decorated-token-text\n [baseText]=\"text()\"\n [locations]=\"locations()\"\n [fontSize]=\"textSize()\"\n [showToolbar]=\"true\"\n [(selectedLocation)]=\"selectedLocation\"\n (selectionChange)=\"onSelectionChange($event)\"\n />\n\n <!-- details -->\n <div class=\"details\">\n <div class=\"detail\">\n <div class=\"detail-title\">\n <mat-icon>highlight_alt</mat-icon> selection\n </div>\n @if (selection(); as sel) {\n <div class=\"detail-body\">\n <code class=\"loc\">{{ sel.coords }}</code>\n <span class=\"text\">{{ sel.text }}</span>\n @if (sel.overlapping) {\n <span class=\"warn\">overlaps a fragment</span>\n }\n </div>\n <div class=\"detail-actions\">\n <button\n mat-flat-button\n type=\"button\"\n [disabled]=\"!sel.location\"\n (click)=\"addSelection()\"\n >\n <mat-icon>add_circle</mat-icon>\n add fragment\n </button>\n <button mat-button type=\"button\" (click)=\"clearSelection()\">\n clear\n </button>\n </div>\n } @else {\n <div class=\"detail-body muted\">\n select any portion of the text\n </div>\n }\n </div>\n\n <div class=\"detail\">\n <div class=\"detail-title\">\n <mat-icon>bookmark</mat-icon> picked fragment\n </div>\n @if (selectedLocation(); as loc) {\n <div class=\"detail-body\">\n <code class=\"loc\">{{ loc.toString() }}</code>\n <span class=\"text\">{{ selectedText() }}</span>\n </div>\n <div class=\"detail-actions\">\n <button\n mat-button\n type=\"button\"\n class=\"mat-warn\"\n (click)=\"removeLocation(loc)\"\n >\n <mat-icon>remove_circle</mat-icon>\n remove\n </button>\n </div>\n } @else {\n <div class=\"detail-body muted\">click a fragment to pick it</div>\n }\n </div>\n </div>\n </div>\n </div>\n </mat-card-content>\n</mat-card>\n",
|
|
383
|
+
styles: ["article{column-width:24em;font:var(--mat-sys-body-medium)}article code,code.loc{font-family:Roboto Mono,Consolas,monospace}.layout{display:grid;grid-template-columns:minmax(260px,1fr) minmax(0,2fr);gap:16px;margin-top:16px}@media(max-width:800px){.layout{grid-template-columns:minmax(0,1fr)}}.input{display:flex;flex-direction:column;gap:8px;min-width:0}.text-field{width:100%}textarea#text{font-family:Roboto Mono,Consolas,monospace}.location-row{display:flex;align-items:flex-start;gap:4px}.location-row mat-form-field{flex:1 1 auto}.location-row input{font-family:Roboto Mono,Consolas,monospace}.location-row button{margin-top:8px}.fragments-header{display:flex;align-items:center;justify-content:space-between;font:var(--mat-sys-title-small)}.fragments mat-chip{font-family:Roboto Mono,Consolas,monospace;cursor:pointer}.output{display:flex;flex-direction:column;gap:8px;min-width:0}.size-bar{display:flex;justify-content:flex-end}cadmus-decorated-token-text{--cadmus-decorated-token-text-max-height: 60vh}.details{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:12px}.detail{display:flex;flex-direction:column;gap:6px;padding:8px 12px;border:1px solid var(--mat-sys-outline-variant);border-radius:var(--mat-sys-corner-small, 4px);background-color:var(--mat-sys-surface-container-low)}.detail-title{display:flex;align-items:center;gap:6px;font:var(--mat-sys-title-small);color:var(--mat-sys-on-surface-variant)}.detail-title mat-icon{font-size:18px;width:18px;height:18px}.detail-body{display:flex;flex-wrap:wrap;align-items:baseline;gap:4px 12px;min-height:24px}.detail-body .text{font-style:italic;overflow-wrap:anywhere}.detail-body .warn{color:var(--mat-sys-error);font:var(--mat-sys-label-medium)}.detail-actions{display:flex;gap:8px}.muted{color:var(--mat-sys-on-surface-variant);font:var(--mat-sys-body-small)}\n"]
|
|
274
384
|
}]
|
|
275
385
|
}],
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
args: ["resultElem"]
|
|
386
|
+
propDecorators: { _textView: [{
|
|
387
|
+
type: i0.ViewChild,
|
|
388
|
+
args: [i0.forwardRef(() => DecoratedTokenTextComponent), { isSignal: true }]
|
|
280
389
|
}] }
|
|
281
390
|
});
|
|
282
|
-
export { LayerDemoComponent };
|
|
391
|
+
export { LAYER_DEMO_TEXT, LayerDemoComponent };
|
|
283
392
|
|
|
284
393
|
//# sourceMappingURL=myrmidon-cadmus-layer-demo.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"myrmidon-cadmus-layer-demo.mjs","names":[],"sources":["../../../../projects/myrmidon/cadmus-layer-demo/src/lib/layer-demo/layer-demo.component.ts","../../../../projects/myrmidon/cadmus-layer-demo/src/lib/layer-demo/layer-demo.component.html"],"sourcesContent":["import {\r\n Component,\r\n ViewChild,\r\n ElementRef,\r\n signal,\r\n ChangeDetectionStrategy,\r\n} from '@angular/core';\r\nimport {\r\n FormField,\r\n FormRoot,\r\n form,\r\n maxLength,\r\n required,\r\n} from '@angular/forms/signals';\r\n\r\nimport { MatCard, MatCardHeader, MatCardContent } from '@angular/material/card';\r\nimport { MatFormField, MatLabel, MatHint } from '@angular/material/form-field';\r\nimport { MatInput } from '@angular/material/input';\r\nimport { MatToolbar } from '@angular/material/toolbar';\r\nimport { MatIconButton } from '@angular/material/button';\r\nimport { MatTooltip } from '@angular/material/tooltip';\r\nimport { MatIcon } from '@angular/material/icon';\r\n\r\nimport { SafeHtmlPipe } from '@myrmidon/ngx-tools';\r\n\r\nimport { TextLayerService, TokenLocation } from '@myrmidon/cadmus-core';\r\n\r\n@Component({\r\n selector: 'cadmus-layer-demo',\r\n templateUrl: './layer-demo.component.html',\r\n styleUrls: ['./layer-demo.component.css'],\r\n changeDetection: ChangeDetectionStrategy.OnPush,\r\n imports: [\r\n MatCard,\r\n MatCardHeader,\r\n MatCardContent,\r\n FormField,\r\n FormRoot,\r\n MatFormField,\r\n MatLabel,\r\n MatInput,\r\n MatHint,\r\n MatToolbar,\r\n MatIconButton,\r\n MatTooltip,\r\n MatIcon,\r\n SafeHtmlPipe,\r\n ],\r\n})\r\nexport class LayerDemoComponent {\r\n @ViewChild('resultElem') _resultElement?: ElementRef;\r\n\r\n public readonly locations = signal<TokenLocation[]>([]);\r\n public readonly result = signal<string>('');\r\n public readonly userLocation = signal<TokenLocation | undefined>(undefined);\r\n public readonly textSize = signal<number>(14);\r\n\r\n /**\r\n * The rendition form. This page is a submission root: submitting it\r\n * (the render button, or Enter in the location input) renders the text.\r\n * As with the old ngSubmit, rendering does not depend on validity: the\r\n * location is required only to add it.\r\n */\r\n public readonly rendition = form(\r\n signal({\r\n text: 'alpha beta\\ngamma\\ndelta epsilon waw\\nzeta',\r\n location: '1.2@2x2',\r\n }),\r\n (path) => {\r\n maxLength(path.text, 1000);\r\n required(path.location);\r\n },\r\n {\r\n submission: {\r\n action: async () => {\r\n this.render();\r\n return undefined;\r\n },\r\n ignoreValidators: 'all',\r\n },\r\n },\r\n );\r\n\r\n constructor(private _textLayerService: TextLayerService) {}\r\n\r\n public makeLarger(): void {\r\n const size = this.textSize() + 2;\r\n if (size > 24) {\r\n return;\r\n }\r\n this.textSize.set(size);\r\n }\r\n\r\n public makeSmaller(): void {\r\n const size = this.textSize() - 2;\r\n if (size < 12) {\r\n return;\r\n }\r\n this.textSize.set(size);\r\n }\r\n\r\n private removeOverlaps(loc: TokenLocation): void {\r\n const locations = [...this.locations()];\r\n\r\n for (let i = locations.length - 1; i > -1; i--) {\r\n if (loc === locations[i]) {\r\n continue;\r\n }\r\n if (loc.overlaps(locations[i])) {\r\n locations.splice(i, 1);\r\n }\r\n }\r\n\r\n this.locations.set(locations);\r\n }\r\n\r\n public addLocation(): void {\r\n const location = this.rendition.location().value();\r\n if (!location) {\r\n return;\r\n }\r\n const loc = TokenLocation.parse(location);\r\n if (!loc) {\r\n return;\r\n }\r\n\r\n const locations = [...this.locations()];\r\n let done = false;\r\n for (let i = 0; i < locations.length && !done; i++) {\r\n const n = loc.compareTo(locations[i]);\r\n // nothing to do if equal\r\n if (n === 0) {\r\n return;\r\n }\r\n // insert before nearest bigger sort value\r\n if (n < 0) {\r\n locations.splice(i, 0, loc);\r\n done = true;\r\n }\r\n }\r\n // append if not yet inserted\r\n if (!done) {\r\n locations.push(loc);\r\n }\r\n this.locations.set(locations);\r\n\r\n // remove all the overlapping locations\r\n this.removeOverlaps(loc);\r\n }\r\n\r\n public removeLocation(loc: TokenLocation): void {\r\n const i = this.locations().indexOf(loc);\r\n if (i > -1) {\r\n const locations = [...this.locations()];\r\n locations.splice(i, 1);\r\n this.locations.set(locations);\r\n }\r\n }\r\n\r\n public clearLocations(): void {\r\n this.locations.set([]);\r\n }\r\n\r\n public render(): void {\r\n const text = this.rendition.text().value();\r\n if (!text) {\r\n return;\r\n }\r\n this.result.set(this._textLayerService.render(text, this.locations()));\r\n }\r\n\r\n public getLocationForNew(): void {\r\n const text = this.rendition.text().value();\r\n if (!text) {\r\n return;\r\n }\r\n this.userLocation.set(\r\n this._textLayerService.getSelectedLocationForNew(\r\n this._textLayerService.getSelectedRange()!,\r\n text,\r\n ) || undefined,\r\n );\r\n }\r\n\r\n public getLocationForEdit(): void {\r\n this.userLocation.set(\r\n this._textLayerService.getSelectedLocationForEdit(\r\n this._textLayerService.getSelectedRange()!,\r\n ) || undefined,\r\n );\r\n }\r\n}\r\n","<mat-card appearance=\"outlined\">\r\n <mat-card-header>\r\n <h3>Layered Text Demo</h3>\r\n </mat-card-header>\r\n <mat-card-content>\r\n <article>\r\n <p>\r\n Enter some base text and zero or more layer fragments locations, then\r\n click the render button. This renders the base text with all its ranges.\r\n </p>\r\n <p>\r\n Once the text has been decorated, select any portion of it, either\r\n including a decorated part, or not. Then, if you selected a part\r\n including decorations, click the location button with the checkmark\r\n (=get the location of the fragment to edit); else, click the location\r\n button with the plus (=get the location of a new fragment).\r\n </p>\r\n <p>\r\n This will show you the token-based coordinates corresponding to your\r\n selection, provided that if you include any portion of a decorated text\r\n you will get the full coordinates of the decoration; otherwise, you will\r\n just get the coordinates of the selected character(s).\r\n </p>\r\n <p>\r\n This behavior is used to allow users edit existing part fragments by\r\n just selecting any part of it, even partially; while they must be\r\n precise when they are creating a new fragment.\r\n </p>\r\n </article>\r\n <hr />\r\n\r\n <form [formRoot]=\"rendition\">\r\n <div>\r\n <mat-form-field>\r\n <mat-label>base text</mat-label>\r\n <textarea\r\n matInput\r\n type=\"text\"\r\n id=\"text\"\r\n spellcheck=\"false\"\r\n [formField]=\"rendition.text\"\r\n ></textarea>\r\n </mat-form-field>\r\n </div>\r\n\r\n <div>\r\n <mat-form-field>\r\n <mat-label>location</mat-label>\r\n <input\r\n matInput\r\n type=\"text\"\r\n id=\"location\"\r\n spellcheck=\"false\"\r\n [formField]=\"rendition.location\"\r\n />\r\n <mat-hint>Y.X@AxR</mat-hint>\r\n </mat-form-field>\r\n </div>\r\n\r\n <div>\r\n <mat-toolbar>\r\n <span>\r\n <button\r\n mat-icon-button\r\n (click)=\"addLocation()\"\r\n type=\"button\"\r\n matTooltip=\"Add the specified location\"\r\n >\r\n <mat-icon style=\"color: #66cc75\">add_circle</mat-icon>\r\n </button>\r\n <button\r\n mat-icon-button\r\n (click)=\"clearLocations()\"\r\n type=\"button\"\r\n matTooltip=\"Remove all the locations\"\r\n >\r\n <mat-icon class=\"mat-warn\">delete_sweep</mat-icon>\r\n </button>\r\n <button\r\n mat-icon-button\r\n type=\"submit\"\r\n matTooltip=\"Render the decorated base text\"\r\n >\r\n <mat-icon class=\"mat-primary\">play_circle_outline</mat-icon>\r\n </button>\r\n <button\r\n mat-icon-button\r\n (click)=\"getLocationForNew()\"\r\n type=\"button\"\r\n matTooltip=\"Get location for new item\"\r\n >\r\n <mat-icon>playlist_add</mat-icon>\r\n </button>\r\n <button\r\n mat-icon-button\r\n (click)=\"getLocationForEdit()\"\r\n type=\"button\"\r\n matTooltip=\"Get location for selected item\"\r\n >\r\n <mat-icon>playlist_add_check</mat-icon>\r\n </button>\r\n <button\r\n mat-icon-button\r\n type=\"button\"\r\n matTooltip=\"Larger text\"\r\n (click)=\"makeLarger()\"\r\n [disabled]=\"textSize() >= 24\"\r\n >\r\n <mat-icon>format_size</mat-icon>\r\n </button>\r\n <button\r\n mat-icon-button\r\n type=\"button\"\r\n matTooltip=\"Smaller text\"\r\n (click)=\"makeSmaller()\"\r\n [disabled]=\"textSize() <= 12\"\r\n >\r\n <mat-icon>text_fields</mat-icon>\r\n </button>\r\n </span>\r\n <span class=\"tb-fill-remaining-space\"></span>\r\n <span>{{ userLocation() }}</span>\r\n </mat-toolbar>\r\n </div>\r\n\r\n <table>\r\n <tbody>\r\n @for (loc of locations(); track loc) {\r\n <tr>\r\n <td>\r\n <button type=\"button\" mat-icon-button (click)=\"removeLocation(loc)\">\r\n <mat-icon class=\"mat-warn\">remove_circle</mat-icon>\r\n </button>\r\n </td>\r\n <td>{{ loc.toString() }}</td>\r\n </tr>\r\n }\r\n </tbody>\r\n </table>\r\n </form>\r\n </mat-card-content>\r\n</mat-card>\r\n\r\n<mat-card appearance=\"outlined\">\r\n <mat-card-header>\r\n <h3>Rendition</h3>\r\n </mat-card-header>\r\n <mat-card-content>\r\n <div\r\n [style.font-size]=\"textSize() + 'px'\"\r\n [innerHtml]=\"result() | safeHtml: 'html'\"\r\n id=\"result()\"\r\n #resultElem\r\n ></div>\r\n <hr />\r\n <div>\r\n <code>{{ result() }}</code>\r\n </div>\r\n </mat-card-content>\r\n</mat-card>\r\n"],"mappings":";;;;;;;;;;;;;AAiDA,IAAa,qBAAb,MAAa,mBAAkB;CAkCT;CAjCK;CAET,YAAY,OAAwB,CAAA,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CACvC,SAAS,OAAe,IAAG,GAAA,YAAA,CAAA,EAAA,WAAA,SAAA,CAAA,+BAAA,CAAA,CAAA;CAC3B,eAAe,OAAkC,QAAU,GAAA,YAAA,CAAA,EAAA,WAAA,eAAA,CAAA,+BAAA,CAAA,CAAA;CAC3D,WAAW,OAAe,IAAG,GAAA,YAAA,CAAA,EAAA,WAAA,WAAA,CAAA,+BAAA,CAAA,CAAA;CAQ7B,YAAY,KAC1B,OAAO;EACL,MAAM;EACN,UAAU;CACX,CAAA,IACA,SAAQ;EACP,UAAU,KAAK,MAAM,GAAI;EACzB,SAAS,KAAK,QAAQ;CACxB,GACA,EACE,YAAY;EACV,QAAQ,YAAW;GACjB,KAAK,OAAM;EAEb;EACA,kBAAkB;CACnB,EACF,CAAA;CAGH,YAAoB,mBAAmC;EAAnC,KAAA,oBAAA;CAAsC;CAEnD,aAAU;EACf,MAAM,OAAO,KAAK,SAAQ,IAAK;EAC/B,IAAI,OAAO,IACT;EAEF,KAAK,SAAS,IAAI,IAAI;CACxB;CAEO,cAAW;EAChB,MAAM,OAAO,KAAK,SAAQ,IAAK;EAC/B,IAAI,OAAO,IACT;EAEF,KAAK,SAAS,IAAI,IAAI;CACxB;CAEQ,eAAe,KAAkB;EACvC,MAAM,YAAY,CAAC,GAAG,KAAK,UAAS,CAAE;EAEtC,K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A,QAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA;IAAA;IAAA,UAAA,CAAA,UAAA;GAAA;GAAA;IAAA,MAAA;IAAA,MACR;IAAO,UAAA;IAAA,QAAA,CAAA,SAAA,IAAA;GAAA;GAAA;IAAA,MAAA;IAAA,MACP;IAAU,UAAA;IAAA,QAAA,CAAA,OAAA;IAAA,UAAA,CAAA,YAAA;GAAA;GAAA;IAAA,MAAA;IAAA,MACV;IAAa,UAAA;IAAA,UAAA,CAAA,aAAA,WAAA;GAAA;GAAA;IAAA,MAAA;IAAA,MACb;IAAU,UAAA;IAAA,QAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA;IAAA;IAAA,UAAA,CAAA,YAAA;GAAA;GAAA;IAAA,MAAA;IAAA,MACV;IAAO,UAAA;IAAA,QAAA;KAAA;KAAA;KAAA;KAAA;KAAA;IAAA;IAAA,UAAA,CAAA,SAAA;GAAA;GAAA;IAAA,MAAA;IAAA,MACP;IAAY,MAAA;GAAA;EAAA;EAAA,iBAAA,GAAA,wBAAA;CAAA,CAAA;;AAGH,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAkB,YAAA,CAAA;EAtB9B,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAmB,iBAGZ,wBAAwB;GAAM,SACtC;IACP;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;GACD;GAAA,UAAA;GAAA,QAAA,CAAA,iWAAA;EAAA,CAAA;;;;EAGA,MAAA;EAAU,MAAA,CAAA,YAAY"}
|
|
1
|
+
{"version":3,"file":"myrmidon-cadmus-layer-demo.mjs","names":[],"sources":["../../../../projects/myrmidon/cadmus-layer-demo/src/lib/layer-demo/layer-demo.component.ts","../../../../projects/myrmidon/cadmus-layer-demo/src/lib/layer-demo/layer-demo.component.html"],"sourcesContent":["import {\n ChangeDetectionStrategy,\n Component,\n computed,\n signal,\n viewChild,\n} from '@angular/core';\nimport { FormField, FormRoot, form, maxLength } from '@angular/forms/signals';\n\nimport {\n MatCard,\n MatCardContent,\n MatCardHeader,\n MatCardTitle,\n MatCardSubtitle,\n MatCardAvatar,\n} from '@angular/material/card';\nimport { MatButton, MatIconButton } from '@angular/material/button';\nimport { MatChip, MatChipRemove, MatChipSet } from '@angular/material/chips';\nimport {\n MatError,\n MatFormField,\n MatHint,\n MatLabel,\n} from '@angular/material/form-field';\nimport { MatIcon } from '@angular/material/icon';\nimport { MatInput } from '@angular/material/input';\nimport {\n MatExpansionPanel,\n MatExpansionPanelHeader,\n MatExpansionPanelTitle,\n} from '@angular/material/expansion';\nimport { MatTooltip } from '@angular/material/tooltip';\n\nimport { TokenLocation } from '@myrmidon/cadmus-core';\nimport {\n DecoratedTokenTextComponent,\n DecoratedTokenTextSelection,\n TokenTextSegmenter,\n} from '@myrmidon/cadmus-ui';\n\n/**\n * The default demo text.\n */\nexport const LAYER_DEMO_TEXT = 'alpha beta\\ngamma\\ndelta epsilon waw\\nzeta';\n\n/**\n * Text layers demo page. This lets users play with the token-based\n * coordinates system used by Cadmus text layers, as implemented by\n * `DecoratedTokenTextComponent` and its `TokenTextSegmenter`:\n * - enter a base text, which is displayed live.\n * - add fragments (i.e. their locations) either by typing their\n * coordinates, or by selecting a portion of the text. Fragment characters\n * are highlighted and blocked, so that a new selection can never overlap\n * them.\n * - click a fragment to pick it, viewing its location and text, or\n * removing it.\n */\n@Component({\n selector: 'cadmus-layer-demo',\n templateUrl: './layer-demo.component.html',\n styleUrls: ['./layer-demo.component.css'],\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [\n MatCard,\n MatCardHeader,\n MatCardAvatar,\n MatCardTitle,\n MatCardSubtitle,\n MatCardContent,\n MatButton,\n MatIconButton,\n MatChipSet,\n MatChip,\n MatChipRemove,\n MatFormField,\n MatLabel,\n MatHint,\n MatError,\n MatInput,\n MatIcon,\n MatTooltip,\n MatExpansionPanel,\n MatExpansionPanelHeader,\n MatExpansionPanelTitle,\n FormField,\n FormRoot,\n DecoratedTokenTextComponent,\n ],\n})\nexport class LayerDemoComponent {\n private readonly _segmenter = new TokenTextSegmenter();\n private readonly _textView = viewChild(DecoratedTokenTextComponent);\n\n /**\n * The fragments locations, in their order.\n */\n public readonly locations = signal<TokenLocation[]>([]);\n\n /**\n * The location of the picked fragment, if any.\n */\n public readonly selectedLocation = signal<TokenLocation | undefined>(\n undefined,\n );\n\n /**\n * The current text selection.\n */\n public readonly selection = signal<DecoratedTokenTextSelection | null>(\n null,\n );\n\n /**\n * The text size in pixels.\n */\n public readonly textSize = signal<number>(16);\n\n /**\n * The error for the typed location, if any.\n */\n public readonly locationError = signal<string | null>(null);\n\n /**\n * The demo form. This is a submission root: submitting it (e.g. with\n * Enter in the location input) adds the typed location.\n */\n public readonly demoForm = form(\n signal({\n text: LAYER_DEMO_TEXT,\n location: '1.2@2x2',\n }),\n (path) => {\n maxLength(path.text, 5000);\n },\n {\n submission: {\n action: async () => {\n this.addTypedLocation();\n return undefined;\n },\n ignoreValidators: 'all',\n },\n },\n );\n\n /**\n * The base text.\n */\n public readonly text = computed(() => this.demoForm.text().value() || '');\n\n private readonly _blocks = computed(() =>\n this._segmenter.getBlocks(this.text()),\n );\n\n /**\n * The text of the picked fragment.\n */\n public readonly selectedText = computed(() => {\n const loc = this.selectedLocation();\n if (!loc) {\n return '';\n }\n const segments = this._segmenter.getLocationSegments(this._blocks(), loc);\n return segments\n ? this._segmenter.getSegmentsText(this._blocks(), segments)\n : '';\n });\n\n public makeLarger(): void {\n this.textSize.update((size) => Math.min(24, size + 2));\n }\n\n public makeSmaller(): void {\n this.textSize.update((size) => Math.max(12, size - 2));\n }\n\n private removeOverlaps(loc: TokenLocation, locations: TokenLocation[]): void {\n for (let i = locations.length - 1; i > -1; i--) {\n if (loc !== locations[i] && loc.overlaps(locations[i])) {\n locations.splice(i, 1);\n }\n }\n }\n\n /**\n * Add the specified location to the fragments, keeping them sorted.\n * Like the backend does when adding a fragment to a layer part, any\n * existing fragment overlapping the new one is removed.\n * @returns True if added.\n */\n public addLocation(loc: TokenLocation): boolean {\n const locations = [...this.locations()];\n let done = false;\n for (let i = 0; i < locations.length && !done; i++) {\n const n = loc.compareTo(locations[i]);\n // nothing to do if equal\n if (n === 0) {\n return false;\n }\n // insert before nearest bigger sort value\n if (n < 0) {\n locations.splice(i, 0, loc);\n done = true;\n }\n }\n // append if not yet inserted\n if (!done) {\n locations.push(loc);\n }\n this.removeOverlaps(loc, locations);\n this.locations.set(locations);\n return true;\n }\n\n /**\n * Add the location typed in the form.\n */\n public addTypedLocation(): void {\n const value = this.demoForm.location().value()?.trim();\n if (!value) {\n this.locationError.set(null);\n return;\n }\n const loc = TokenLocation.parse(value);\n if (\n !loc ||\n !this._segmenter.getCoordsSegments(this._blocks(), loc.toString())\n ) {\n this.locationError.set(\n loc ? 'location not found in text' : 'invalid location',\n );\n return;\n }\n this.locationError.set(null);\n this.addLocation(loc);\n }\n\n /**\n * Add the location of the current selection.\n */\n public addSelection(): void {\n const loc = this.selection()?.location;\n if (loc && this.addLocation(loc)) {\n this.selection.set(null);\n }\n }\n\n /**\n * Handle a new selection in the text.\n */\n public onSelectionChange(selection: DecoratedTokenTextSelection): void {\n this.selection.set(selection.coords ? selection : null);\n }\n\n /**\n * Pick the specified fragment.\n */\n public pickLocation(loc: TokenLocation): void {\n this.selectedLocation.set(loc);\n }\n\n public removeLocation(loc: TokenLocation): void {\n const i = this.locations().indexOf(loc);\n if (i > -1) {\n const locations = [...this.locations()];\n locations.splice(i, 1);\n this.locations.set(locations);\n if (this.selectedLocation() === loc) {\n this.selectedLocation.set(undefined);\n }\n }\n }\n\n public clearLocations(): void {\n this.locations.set([]);\n this.selectedLocation.set(undefined);\n }\n\n /**\n * Clear the text selection.\n */\n public clearSelection(): void {\n this._textView()?.clearSelection();\n this.selection.set(null);\n }\n}\n","<mat-card appearance=\"outlined\">\n <mat-card-header>\n <mat-icon mat-card-avatar>layers</mat-icon>\n <mat-card-title>Text Layers Demo</mat-card-title>\n <mat-card-subtitle>token-based coordinates</mat-card-subtitle>\n </mat-card-header>\n <mat-card-content>\n <mat-expansion-panel>\n <mat-expansion-panel-header>\n <mat-panel-title>How it works</mat-panel-title>\n </mat-expansion-panel-header>\n <article>\n <p>\n A text layer annotates portions of a base text with fragments. Each\n fragment has a <strong>location</strong> with token-based\n coordinates, where a token is any sequence of non-whitespace\n characters. A point is <code>Y.X@AxR</code>:\n </p>\n <ul>\n <li><code>Y</code>: the line number (1-N).</li>\n <li><code>X</code>: the token number in the line (1-N).</li>\n <li>\n optionally, when not selecting whole tokens: <code>A</code> is\n the first character in the token (1-N), and <code>R</code> the\n count of characters (omitted when 1).\n </li>\n </ul>\n <p>\n A selection spanning several tokens has a start and an end point\n separated by <code>-</code>: the start point picks from its\n <code>A</code> to the end of its token, the end point picks the\n first <code>R</code> characters of its token. Whitespace at the\n edges of a selection is ignored. For instance, with the default\n text: <code>2.1</code> is <em>gamma</em>, <code>1.2@2x2</code>\n is <em>et</em>, <code>3.1@4x2-3.2@1</code> is\n <em>ta e</em>.\n </p>\n <p>\n Fragments in the same layer never overlap: so their characters are\n highlighted and <strong>blocked</strong>, and a selection always\n stops before them. Click a fragment to pick it; select any other\n portion of text (by dragging, SHIFT+clicking, or with SHIFT+arrows)\n to get its location, and add it as a new fragment. You can also\n type coordinates in the box below the text to select them.\n </p>\n </article>\n </mat-expansion-panel>\n\n <div class=\"layout\">\n <!-- input -->\n <form class=\"input\" [formRoot]=\"demoForm\">\n <mat-form-field class=\"text-field\">\n <mat-label>base text</mat-label>\n <textarea\n matInput\n id=\"text\"\n rows=\"6\"\n spellcheck=\"false\"\n [formField]=\"demoForm.text\"\n ></textarea>\n <mat-hint>each line is a block</mat-hint>\n </mat-form-field>\n\n <div class=\"location-row\">\n <mat-form-field>\n <mat-label>location</mat-label>\n <input\n matInput\n id=\"location\"\n spellcheck=\"false\"\n autocomplete=\"off\"\n [formField]=\"demoForm.location\"\n />\n @if (locationError(); as error) {\n <mat-error>{{ error }}</mat-error>\n } @else {\n <mat-hint>Y.X@AxR or Y.X@AxR-Y.X@AxR</mat-hint>\n }\n </mat-form-field>\n <button\n mat-icon-button\n type=\"submit\"\n matTooltip=\"Add a fragment at the typed location\"\n >\n <mat-icon class=\"mat-primary\">add_circle</mat-icon>\n </button>\n </div>\n\n <!-- fragments -->\n <div class=\"fragments\">\n <div class=\"fragments-header\">\n <span>fragments: {{ locations().length }}</span>\n <button\n mat-icon-button\n type=\"button\"\n matTooltip=\"Remove all the fragments\"\n [disabled]=\"!locations().length\"\n (click)=\"clearLocations()\"\n >\n <mat-icon class=\"mat-warn\">delete_sweep</mat-icon>\n </button>\n </div>\n <mat-chip-set aria-label=\"fragments\">\n @for (loc of locations(); track loc) {\n <mat-chip\n [highlighted]=\"selectedLocation() === loc\"\n (click)=\"pickLocation(loc)\"\n (removed)=\"removeLocation(loc)\"\n >\n {{ loc.toString() }}\n <button\n matChipRemove\n type=\"button\"\n [attr.aria-label]=\"'remove ' + loc.toString()\"\n >\n <mat-icon>cancel</mat-icon>\n </button>\n </mat-chip>\n }\n </mat-chip-set>\n </div>\n </form>\n\n <!-- text -->\n <div class=\"output\">\n <div class=\"size-bar\">\n <button\n mat-icon-button\n type=\"button\"\n matTooltip=\"Larger text\"\n (click)=\"makeLarger()\"\n [disabled]=\"textSize() >= 24\"\n >\n <mat-icon>format_size</mat-icon>\n </button>\n <button\n mat-icon-button\n type=\"button\"\n matTooltip=\"Smaller text\"\n (click)=\"makeSmaller()\"\n [disabled]=\"textSize() <= 12\"\n >\n <mat-icon>text_fields</mat-icon>\n </button>\n </div>\n <cadmus-decorated-token-text\n [baseText]=\"text()\"\n [locations]=\"locations()\"\n [fontSize]=\"textSize()\"\n [showToolbar]=\"true\"\n [(selectedLocation)]=\"selectedLocation\"\n (selectionChange)=\"onSelectionChange($event)\"\n />\n\n <!-- details -->\n <div class=\"details\">\n <div class=\"detail\">\n <div class=\"detail-title\">\n <mat-icon>highlight_alt</mat-icon> selection\n </div>\n @if (selection(); as sel) {\n <div class=\"detail-body\">\n <code class=\"loc\">{{ sel.coords }}</code>\n <span class=\"text\">{{ sel.text }}</span>\n @if (sel.overlapping) {\n <span class=\"warn\">overlaps a fragment</span>\n }\n </div>\n <div class=\"detail-actions\">\n <button\n mat-flat-button\n type=\"button\"\n [disabled]=\"!sel.location\"\n (click)=\"addSelection()\"\n >\n <mat-icon>add_circle</mat-icon>\n add fragment\n </button>\n <button mat-button type=\"button\" (click)=\"clearSelection()\">\n clear\n </button>\n </div>\n } @else {\n <div class=\"detail-body muted\">\n select any portion of the text\n </div>\n }\n </div>\n\n <div class=\"detail\">\n <div class=\"detail-title\">\n <mat-icon>bookmark</mat-icon> picked fragment\n </div>\n @if (selectedLocation(); as loc) {\n <div class=\"detail-body\">\n <code class=\"loc\">{{ loc.toString() }}</code>\n <span class=\"text\">{{ selectedText() }}</span>\n </div>\n <div class=\"detail-actions\">\n <button\n mat-button\n type=\"button\"\n class=\"mat-warn\"\n (click)=\"removeLocation(loc)\"\n >\n <mat-icon>remove_circle</mat-icon>\n remove\n </button>\n </div>\n } @else {\n <div class=\"detail-body muted\">click a fragment to pick it</div>\n }\n </div>\n </div>\n </div>\n </div>\n </mat-card-content>\n</mat-card>\n"],"mappings":";;;;;;;;;;;;;AA4CA,MAAa,kBAAkB;AA8C/B,IAAa,qBAAb,MAAa,mBAAkB;CACZ,aAAa,IAAI,mBAAkB;CACnC,YAAY,UAAU,6BAA4B,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CAKnD,YAAY,OAAwB,CAAA,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CAKvC,mBAAmB,OACjC,QACD,GAAA,YAAA,CAAA,EAAA,WAAA,mBAAA,CAAA,+BAAA,CAAA,CAAA;CAKe,YAAY,OAC1B,MACD,GAA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;GAAA;GAAA;IAAA,MAAA;IAAA,MACjB;IAAuB,UAAA;IAAA,QAAA;KAAA;KAAA;KAAA;IAAA;GAAA;GAAA;IAAA,MAAA;IAAA,MACvB;IAAsB,UAAA;GAAA;GAAA;IAAA,MAAA;IAAA,MACtB;IAAS,UAAA;IAAA,QAAA,CAAA,WAAA;IAAA,UAAA,CAAA,WAAA;GAAA;GAAA;IAAA,MAAA;IAAA,MACT;IAAQ,UAAA;IAAA,QAAA,CAAA,UAAA;GAAA;GAAA;IAAA,MAAA;IAAA,MACR;IAA2B,UAAA;IAAA,QAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA;IAAA;IAAA,SAAA,CAAA,0BAAA,iBAAA;GAAA;EAAA;EAAA,iBAAA,GAAA,wBAAA;CAAA,CAAA;;AAGlB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAkB,YAAA,CAAA;EAhC9B,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAmB,iBAGZ,wBAAwB;GAAM,SACtC;IACP;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;GACD;GAAA,UAAA;GAAA,QAAA,CAAA,2zDAAA;EAAA,CAAA;CAIsC,CAAA;CAAA,gBAAA,EAAA,WAAA,CAAA;EAAA,MAAA,GAAA;EAAA,MAAA,CAAA,GAAA,iBAAA,2BAA2B,GAAA,EAAA,UAAA,KAAA,CAAA;CAAA,CAAA,EAAA;AAAA,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@myrmidon/cadmus-layer-demo",
|
|
3
|
-
"version": "20.0.0",
|
|
4
2
|
"description": "Cadmus - text layer demo page.",
|
|
5
3
|
"keywords": [
|
|
6
4
|
"Cadmus"
|
|
@@ -21,20 +19,21 @@
|
|
|
21
19
|
"@myrmidon/cadmus-core": "^20.0.0",
|
|
22
20
|
"@myrmidon/cadmus-ui": "^20.0.0"
|
|
23
21
|
},
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
22
|
+
"name": "@myrmidon/cadmus-layer-demo",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"main": "./fesm2022/myrmidon-cadmus-layer-demo.mjs",
|
|
26
|
+
"module": "./fesm2022/myrmidon-cadmus-layer-demo.mjs",
|
|
27
|
+
"typings": "./types/myrmidon-cadmus-layer-demo.d.ts",
|
|
28
|
+
"types": "./types/myrmidon-cadmus-layer-demo.d.ts",
|
|
29
29
|
"exports": {
|
|
30
|
-
"./package.json": {
|
|
31
|
-
"default": "./package.json"
|
|
32
|
-
},
|
|
33
30
|
".": {
|
|
34
31
|
"types": "./types/myrmidon-cadmus-layer-demo.d.ts",
|
|
35
32
|
"default": "./fesm2022/myrmidon-cadmus-layer-demo.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": {
|
|
35
|
+
"default": "./package.json"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
}
|
|
38
|
+
"version": "20.0.2"
|
|
39
|
+
}
|
|
@@ -1,33 +1,94 @@
|
|
|
1
|
+
import { TokenLocation } from "@myrmidon/cadmus-core";
|
|
2
|
+
import { DecoratedTokenTextSelection } from "@myrmidon/cadmus-ui";
|
|
1
3
|
import * as i0 from "@angular/core";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The default demo text.
|
|
6
|
+
*/
|
|
7
|
+
export declare const LAYER_DEMO_TEXT = "alpha beta\ngamma\ndelta epsilon waw\nzeta";
|
|
8
|
+
/**
|
|
9
|
+
* Text layers demo page. This lets users play with the token-based
|
|
10
|
+
* coordinates system used by Cadmus text layers, as implemented by
|
|
11
|
+
* `DecoratedTokenTextComponent` and its `TokenTextSegmenter`:
|
|
12
|
+
* - enter a base text, which is displayed live.
|
|
13
|
+
* - add fragments (i.e. their locations) either by typing their
|
|
14
|
+
* coordinates, or by selecting a portion of the text. Fragment characters
|
|
15
|
+
* are highlighted and blocked, so that a new selection can never overlap
|
|
16
|
+
* them.
|
|
17
|
+
* - click a fragment to pick it, viewing its location and text, or
|
|
18
|
+
* removing it.
|
|
19
|
+
*/
|
|
4
20
|
export declare class LayerDemoComponent {
|
|
5
|
-
private
|
|
6
|
-
|
|
21
|
+
private readonly _segmenter;
|
|
22
|
+
private readonly _textView;
|
|
23
|
+
/**
|
|
24
|
+
* The fragments locations, in their order.
|
|
25
|
+
*/
|
|
7
26
|
readonly locations: import("@angular/core").WritableSignal<TokenLocation[]>;
|
|
8
|
-
|
|
9
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The location of the picked fragment, if any.
|
|
29
|
+
*/
|
|
30
|
+
readonly selectedLocation: import("@angular/core").WritableSignal<TokenLocation | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* The current text selection.
|
|
33
|
+
*/
|
|
34
|
+
readonly selection: import("@angular/core").WritableSignal<DecoratedTokenTextSelection | null>;
|
|
35
|
+
/**
|
|
36
|
+
* The text size in pixels.
|
|
37
|
+
*/
|
|
10
38
|
readonly textSize: import("@angular/core").WritableSignal<number>;
|
|
11
39
|
/**
|
|
12
|
-
* The
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
40
|
+
* The error for the typed location, if any.
|
|
41
|
+
*/
|
|
42
|
+
readonly locationError: import("@angular/core").WritableSignal<string | null>;
|
|
43
|
+
/**
|
|
44
|
+
* The demo form. This is a submission root: submitting it (e.g. with
|
|
45
|
+
* Enter in the location input) adds the typed location.
|
|
16
46
|
*/
|
|
17
|
-
readonly
|
|
47
|
+
readonly demoForm: import("@angular/forms/signals").FieldTree<{
|
|
18
48
|
text: string;
|
|
19
49
|
location: string;
|
|
20
50
|
}, string | number, "writable">;
|
|
21
|
-
|
|
51
|
+
/**
|
|
52
|
+
* The base text.
|
|
53
|
+
*/
|
|
54
|
+
readonly text: import("@angular/core").Signal<string>;
|
|
55
|
+
private readonly _blocks;
|
|
56
|
+
/**
|
|
57
|
+
* The text of the picked fragment.
|
|
58
|
+
*/
|
|
59
|
+
readonly selectedText: import("@angular/core").Signal<string>;
|
|
22
60
|
makeLarger(): void;
|
|
23
61
|
makeSmaller(): void;
|
|
24
62
|
private removeOverlaps;
|
|
25
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Add the specified location to the fragments, keeping them sorted.
|
|
65
|
+
* Like the backend does when adding a fragment to a layer part, any
|
|
66
|
+
* existing fragment overlapping the new one is removed.
|
|
67
|
+
* @returns True if added.
|
|
68
|
+
*/
|
|
69
|
+
addLocation(loc: TokenLocation): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Add the location typed in the form.
|
|
72
|
+
*/
|
|
73
|
+
addTypedLocation(): void;
|
|
74
|
+
/**
|
|
75
|
+
* Add the location of the current selection.
|
|
76
|
+
*/
|
|
77
|
+
addSelection(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Handle a new selection in the text.
|
|
80
|
+
*/
|
|
81
|
+
onSelectionChange(selection: DecoratedTokenTextSelection): void;
|
|
82
|
+
/**
|
|
83
|
+
* Pick the specified fragment.
|
|
84
|
+
*/
|
|
85
|
+
pickLocation(loc: TokenLocation): void;
|
|
26
86
|
removeLocation(loc: TokenLocation): void;
|
|
27
87
|
clearLocations(): void;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Clear the text selection.
|
|
90
|
+
*/
|
|
91
|
+
clearSelection(): void;
|
|
31
92
|
static ɵfac: i0.ɵɵFactoryDeclaration<LayerDemoComponent, never>;
|
|
32
93
|
static ɵcmp: i0.ɵɵComponentDeclaration<LayerDemoComponent, "cadmus-layer-demo", never, {}, {}, never, never, true, never>;
|
|
33
94
|
}
|