@myrmidon/cadmus-text-segment 0.0.0-stage → 0.0.3
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.
|
@@ -0,0 +1,1012 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ElementRef, InjectionToken, InputSignal, Type } from "@angular/core";
|
|
3
|
+
import { ConnectedPosition } from "@angular/cdk/overlay";
|
|
4
|
+
/**
|
|
5
|
+
* The selection mode of a text segment:
|
|
6
|
+
* - `allowed`: a selection can start or end at this segment (default).
|
|
7
|
+
* - `wrapped`: a selection cannot start or end at this segment, but it can
|
|
8
|
+
* include it when it starts before and ends after it (e.g. a space between
|
|
9
|
+
* two words).
|
|
10
|
+
* - `attached`: like `wrapped`, but the segment is glued to the segment
|
|
11
|
+
* preceding it: whenever that segment is at the end of a selection, all the
|
|
12
|
+
* attached segments following it are included too; and a selection starting
|
|
13
|
+
* at an attached segment starts from its base instead (e.g. a Unicode
|
|
14
|
+
* combining diacritic following its base letter).
|
|
15
|
+
* - `blocked`: no selection can start, end, or cross this segment: when
|
|
16
|
+
* dragging or extending a selection, the selection stops before it.
|
|
17
|
+
*/
|
|
18
|
+
export type TextSegmentSelectionMode = 'allowed' | 'wrapped' | 'attached' | 'blocked';
|
|
19
|
+
/**
|
|
20
|
+
* An arbitrarily defined segment of a text. Segments are pure data: they
|
|
21
|
+
* never carry any view state (selection, search results, etc.), which is
|
|
22
|
+
* kept by the viewer, so that a segment object is never mutated once
|
|
23
|
+
* created and can be safely shared and compared by identity.
|
|
24
|
+
*/
|
|
25
|
+
export interface TextSegment<T = unknown> {
|
|
26
|
+
/**
|
|
27
|
+
* Arbitrary numeric ID, unique in the whole segmented text.
|
|
28
|
+
*/
|
|
29
|
+
id: number;
|
|
30
|
+
/**
|
|
31
|
+
* The ordinal position of the segment, as defined by the segmentation
|
|
32
|
+
* logic (e.g. the index of a character in the source text). This is
|
|
33
|
+
* informative only: the viewer orders segments by their position in
|
|
34
|
+
* blocks, and there can be holes in this numeric sequence (e.g. when
|
|
35
|
+
* skipping CR+LF).
|
|
36
|
+
*/
|
|
37
|
+
index: number;
|
|
38
|
+
/**
|
|
39
|
+
* The text value of the segment. This is what is searched by the finder.
|
|
40
|
+
*/
|
|
41
|
+
value: string;
|
|
42
|
+
/**
|
|
43
|
+
* The text to display for the segment, falling back to `value` if not set.
|
|
44
|
+
*/
|
|
45
|
+
label?: string;
|
|
46
|
+
/**
|
|
47
|
+
* An optional precomputed tip for the segment, used when the settings do
|
|
48
|
+
* not define a tip template or function.
|
|
49
|
+
*/
|
|
50
|
+
tip?: string;
|
|
51
|
+
/**
|
|
52
|
+
* An optional data object attached to the segment. All the segments in a
|
|
53
|
+
* text have the same payload type.
|
|
54
|
+
*/
|
|
55
|
+
payload?: T;
|
|
56
|
+
/**
|
|
57
|
+
* The selection mode for this segment. Default is `allowed`.
|
|
58
|
+
*/
|
|
59
|
+
selectionMode?: TextSegmentSelectionMode;
|
|
60
|
+
/**
|
|
61
|
+
* The fill color of the segment's text box, overriding the default color
|
|
62
|
+
* from settings. When the segment is selected or is a search result, this
|
|
63
|
+
* is temporarily replaced by the corresponding color from settings.
|
|
64
|
+
*/
|
|
65
|
+
color?: string;
|
|
66
|
+
/**
|
|
67
|
+
* The color of the segment's text box text, overriding the default text
|
|
68
|
+
* color from settings.
|
|
69
|
+
*/
|
|
70
|
+
textColor?: string;
|
|
71
|
+
/**
|
|
72
|
+
* The color of the segment's text box border, overriding the default
|
|
73
|
+
* border color from settings. Segmentation logic can use it to visually
|
|
74
|
+
* represent additional metadata.
|
|
75
|
+
*/
|
|
76
|
+
borderColor?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Optional CSS class(es) to add to the segment view's host element.
|
|
79
|
+
*/
|
|
80
|
+
cssClass?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A block (e.g. a paragraph or a line) of text segments.
|
|
84
|
+
*/
|
|
85
|
+
export interface TextSegmentBlock<T = unknown> {
|
|
86
|
+
/**
|
|
87
|
+
* The index of the block in the text (0-N).
|
|
88
|
+
*/
|
|
89
|
+
index: number;
|
|
90
|
+
/**
|
|
91
|
+
* The segments in the block, in their display order.
|
|
92
|
+
*/
|
|
93
|
+
segments: TextSegment<T>[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The position of a segment tip.
|
|
97
|
+
*/
|
|
98
|
+
export type TextSegmentTipPosition = 'below' | 'popup';
|
|
99
|
+
/**
|
|
100
|
+
* How the segments of a block wrap to the next line when they do not fit
|
|
101
|
+
* the available width:
|
|
102
|
+
* - `segment`: the line can wrap after any segment (default).
|
|
103
|
+
* - `word`: the line wraps only after a whitespace segment (i.e. a segment
|
|
104
|
+
* whose value is entirely whitespace), so that the segments between two
|
|
105
|
+
* whitespaces (e.g. the characters of a word) stay together, like in
|
|
106
|
+
* normal text. A run of segments wider than the whole line still wraps
|
|
107
|
+
* after any segment.
|
|
108
|
+
*/
|
|
109
|
+
export type TextSegmentWrapMode = 'segment' | 'word';
|
|
110
|
+
/**
|
|
111
|
+
* The contract of a component used to render the tip of a segment via
|
|
112
|
+
* the `tipComponent` setting. The component gets the segment bound to its
|
|
113
|
+
* `segment` input.
|
|
114
|
+
*/
|
|
115
|
+
export interface TextSegmentTipComponent<T = unknown> {
|
|
116
|
+
segment: InputSignal<TextSegment<T> | undefined>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Display settings for a segmented text view. Colors can be any CSS color
|
|
120
|
+
* value, including CSS variables like the Angular Material M3 tokens
|
|
121
|
+
* (`var(--mat-sys-...)`), which are used by default so that the view
|
|
122
|
+
* follows the application theme (and its dark mode).
|
|
123
|
+
*/
|
|
124
|
+
export interface SegmentedTextSettings {
|
|
125
|
+
/** The horizontal gap (px) between two segments in the same block. */
|
|
126
|
+
segmentOffset: number;
|
|
127
|
+
/** The vertical gap (px) between two wrapped lines in the same block. */
|
|
128
|
+
lineOffset: number;
|
|
129
|
+
/** The vertical gap (px) between two blocks. */
|
|
130
|
+
blockOffset: number;
|
|
131
|
+
/** True to show the block number (=index+1) before each block. */
|
|
132
|
+
showBlockNumbers?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* How segments wrap to the next line (default `segment`): see
|
|
135
|
+
* `TextSegmentWrapMode`.
|
|
136
|
+
*/
|
|
137
|
+
wrapMode?: TextSegmentWrapMode;
|
|
138
|
+
/** True to show the ID box in each segment view. */
|
|
139
|
+
showIdBox?: boolean;
|
|
140
|
+
/** True to show the index box in each segment view. */
|
|
141
|
+
showIndexBox?: boolean;
|
|
142
|
+
/** True to show the tip (below each segment or as a popup). */
|
|
143
|
+
showTipBox?: boolean;
|
|
144
|
+
/** Default fill color of the text box. */
|
|
145
|
+
color: string;
|
|
146
|
+
/** Default text color of the text box. */
|
|
147
|
+
textColor: string;
|
|
148
|
+
/** Default border color of the text box. */
|
|
149
|
+
borderColor: string;
|
|
150
|
+
/** Fill color of a selected segment. */
|
|
151
|
+
selectionColor: string;
|
|
152
|
+
/** Text color of a selected segment. */
|
|
153
|
+
selectionTextColor: string;
|
|
154
|
+
/** Fill color of a segment matching the current search. */
|
|
155
|
+
resultColor: string;
|
|
156
|
+
/** Text color of a segment matching the current search. */
|
|
157
|
+
resultTextColor: string;
|
|
158
|
+
/** Color of the outline drawn around the segment with the caret. */
|
|
159
|
+
caretColor: string;
|
|
160
|
+
/** Font family of the text box text. */
|
|
161
|
+
fontFace: string;
|
|
162
|
+
/** Font size of the text box text (any CSS font-size, e.g. `16px`). */
|
|
163
|
+
fontSize: string;
|
|
164
|
+
/** Text box height (px). Its width fits the text. */
|
|
165
|
+
textRectHeight: number;
|
|
166
|
+
/**
|
|
167
|
+
* Text box minimum width (px). When > 0 it forces a segment to be
|
|
168
|
+
* visible even with a text like a space.
|
|
169
|
+
*/
|
|
170
|
+
textRectMinWidth?: number;
|
|
171
|
+
/** Horizontal padding (px) between the text and its box border. */
|
|
172
|
+
textRectPadding?: number;
|
|
173
|
+
/** Corner radius (px) of the boxes. */
|
|
174
|
+
textRectRadius?: number;
|
|
175
|
+
/** Border stroke width (px) of the text box. */
|
|
176
|
+
textRectStrokeWidth?: number;
|
|
177
|
+
/** Border stroke dash array of the text box (e.g. `4 2`). */
|
|
178
|
+
textRectStrokeDasharray?: string;
|
|
179
|
+
/** Font family of the ID and index boxes. */
|
|
180
|
+
infoFontFace: string;
|
|
181
|
+
/** Font size of the ID and index boxes. */
|
|
182
|
+
infoFontSize: string;
|
|
183
|
+
/** Height (px) of the ID and index boxes. */
|
|
184
|
+
infoRectHeight: number;
|
|
185
|
+
/** Font family of the tip. */
|
|
186
|
+
tipFontFace: string;
|
|
187
|
+
/** Font size of the tip. */
|
|
188
|
+
tipFontSize: string;
|
|
189
|
+
/** Height (px) of the tip box when below (its width is the segment's). */
|
|
190
|
+
tipRectHeight: number;
|
|
191
|
+
/**
|
|
192
|
+
* Template string for the tip, with placeholders in `{{...}}`. Each
|
|
193
|
+
* placeholder is a dot-separated path into the segment's payload (e.g.
|
|
194
|
+
* `{{uni.category}}`), or one of `$id`, `$index`, `$value`, `$label`
|
|
195
|
+
* for the segment's own properties. Unresolved placeholders are removed.
|
|
196
|
+
*/
|
|
197
|
+
tipTemplate?: string;
|
|
198
|
+
/**
|
|
199
|
+
* Function returning the tip for a segment. When set, it overrides
|
|
200
|
+
* `tipTemplate`.
|
|
201
|
+
*/
|
|
202
|
+
tipFn?: (segment: TextSegment<any>) => string | null | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* A component to render the tip instead of text, for a fully custom
|
|
205
|
+
* visualization. It must declare a `segment` input (see
|
|
206
|
+
* `TextSegmentTipComponent`). When set, it overrides both `tipFn` and
|
|
207
|
+
* `tipTemplate`.
|
|
208
|
+
*/
|
|
209
|
+
tipComponent?: Type<unknown>;
|
|
210
|
+
/**
|
|
211
|
+
* Max length in characters of a textual tip: text beyond it is replaced
|
|
212
|
+
* by a trailing ellipsis.
|
|
213
|
+
*/
|
|
214
|
+
tipMaxLength?: number;
|
|
215
|
+
/** Whether to display the tip below the segment or as a popup on hover. */
|
|
216
|
+
tipPosition: TextSegmentTipPosition;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The default settings for a segmented text view, used for any setting
|
|
220
|
+
* which is not explicitly provided.
|
|
221
|
+
*/
|
|
222
|
+
export declare const DEFAULT_SEGMENTED_TEXT_SETTINGS: Readonly<SegmentedTextSettings>;
|
|
223
|
+
/**
|
|
224
|
+
* Merge the specified partial settings with the default ones.
|
|
225
|
+
*/
|
|
226
|
+
export declare function resolveSegmentedTextSettings(settings?: Partial<SegmentedTextSettings> | null): SegmentedTextSettings;
|
|
227
|
+
/**
|
|
228
|
+
* A segmented text with its optional display settings. This is just a
|
|
229
|
+
* convenience container for transferring both data and settings.
|
|
230
|
+
*/
|
|
231
|
+
export interface SegmentedText<T = unknown> {
|
|
232
|
+
blocks: TextSegmentBlock<T>[];
|
|
233
|
+
settings?: Partial<SegmentedTextSettings>;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Interface implemented by text segmenters. A segmenter contains the whole
|
|
237
|
+
* segmentation logic, which is completely external to the viewer: it builds
|
|
238
|
+
* blocks of segments from a text, and maps selections to and from
|
|
239
|
+
* coordinates expressed in its own syntax.
|
|
240
|
+
*/
|
|
241
|
+
export interface TextSegmenter<T = unknown> {
|
|
242
|
+
/**
|
|
243
|
+
* Get blocks of segments from the specified text.
|
|
244
|
+
*/
|
|
245
|
+
getBlocks(text?: string): TextSegmentBlock<T>[];
|
|
246
|
+
/**
|
|
247
|
+
* Get the coordinates of the specified segments.
|
|
248
|
+
* @param blocks The blocks of the whole text, providing the context
|
|
249
|
+
* required to calculate coordinates.
|
|
250
|
+
* @param segments The segments (usually the selected ones), in their
|
|
251
|
+
* text order.
|
|
252
|
+
* @returns The coordinates, or an empty string if there are no
|
|
253
|
+
* coordinates for the specified segments.
|
|
254
|
+
*/
|
|
255
|
+
getSegmentCoords(blocks: readonly TextSegmentBlock<T>[], segments: readonly TextSegment<T>[]): string;
|
|
256
|
+
/**
|
|
257
|
+
* Get the segments included by the specified coordinates.
|
|
258
|
+
* @param blocks The blocks of the whole text.
|
|
259
|
+
* @param coords The coordinates.
|
|
260
|
+
* @returns The segments in their text order, or null if the coordinates
|
|
261
|
+
* are not valid.
|
|
262
|
+
*/
|
|
263
|
+
getCoordsSegments(blocks: readonly TextSegmentBlock<T>[], coords: string): TextSegment<T>[] | null;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Injection token for an optional text segmenter used by the segmented text
|
|
267
|
+
* view for coordinates. The view's `segmenter` input, when set, takes
|
|
268
|
+
* precedence over it.
|
|
269
|
+
*/
|
|
270
|
+
export declare const TEXT_SEGMENTER: InjectionToken<TextSegmenter<any>>;
|
|
271
|
+
/**
|
|
272
|
+
* The selection of a segmented text view, as emitted by it.
|
|
273
|
+
*/
|
|
274
|
+
export interface TextSegmentSelection<T = unknown> {
|
|
275
|
+
/** The IDs of the selected segments, in their text order. */
|
|
276
|
+
ids: number[];
|
|
277
|
+
/** The selected segments, in their text order. */
|
|
278
|
+
segments: TextSegment<T>[];
|
|
279
|
+
/**
|
|
280
|
+
* The coordinates of the selection, when a segmenter is available and
|
|
281
|
+
* the selection is not empty.
|
|
282
|
+
*/
|
|
283
|
+
coords?: string;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* A click on a segment, as emitted by a segmented text view. This is
|
|
287
|
+
* emitted for any segment, whatever its selection mode: so it is the only
|
|
288
|
+
* way for a consumer to know that the user clicked a segment which cannot
|
|
289
|
+
* be selected (e.g. a `blocked` segment representing an existing
|
|
290
|
+
* annotation, which the consumer may want to pick for editing).
|
|
291
|
+
*/
|
|
292
|
+
export interface TextSegmentClick<T = unknown> {
|
|
293
|
+
/** The clicked segment. */
|
|
294
|
+
segment: TextSegment<T>;
|
|
295
|
+
/** The pointer event which completed the click. */
|
|
296
|
+
event: PointerEvent;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Options for finding text in segments.
|
|
300
|
+
*/
|
|
301
|
+
export interface TextSegmentFindOptions {
|
|
302
|
+
/** The text to find. Empty means no search. */
|
|
303
|
+
query: string;
|
|
304
|
+
/**
|
|
305
|
+
* True to find text across segment boundaries (concatenating the values
|
|
306
|
+
* of all the segments in each block); false to find text inside each
|
|
307
|
+
* single segment value.
|
|
308
|
+
*/
|
|
309
|
+
crossSegments: boolean;
|
|
310
|
+
/** True for a case-sensitive search. */
|
|
311
|
+
caseSensitive: boolean;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Resolve a dot-separated path in the specified object.
|
|
315
|
+
* @param obj The object.
|
|
316
|
+
* @param path The path, e.g. `uni.category` or `tags.0`.
|
|
317
|
+
* @returns The value, or undefined if not found.
|
|
318
|
+
*/
|
|
319
|
+
export declare function resolvePath(obj: unknown, path: string): unknown;
|
|
320
|
+
/**
|
|
321
|
+
* Fill a tip template with data from a segment. Each placeholder in `{{...}}`
|
|
322
|
+
* is a dot-separated path into the segment's payload, or one of `$id`,
|
|
323
|
+
* `$index`, `$value`, `$label` for the segment's own properties. Unresolved
|
|
324
|
+
* placeholders are replaced with an empty string, and the result is trimmed.
|
|
325
|
+
* @param template The template, e.g. `cat.='{{uni.category}}'`.
|
|
326
|
+
* @param segment The segment.
|
|
327
|
+
* @returns The filled template.
|
|
328
|
+
*/
|
|
329
|
+
export declare function fillTipTemplate(template: string, segment: TextSegment<unknown>): string;
|
|
330
|
+
/**
|
|
331
|
+
* Truncate the specified text to the specified max length, appending an
|
|
332
|
+
* ellipsis when truncated.
|
|
333
|
+
*/
|
|
334
|
+
export declare function truncateText(text: string, maxLength?: number): string;
|
|
335
|
+
/**
|
|
336
|
+
* Get the textual tip for a segment according to the specified settings:
|
|
337
|
+
* `tipFn` wins over `tipTemplate`, which wins over the segment's own `tip`.
|
|
338
|
+
* The result is truncated according to `tipMaxLength`.
|
|
339
|
+
* @returns The tip, or an empty string if none.
|
|
340
|
+
*/
|
|
341
|
+
export declare function resolveSegmentTip(segment: TextSegment<unknown>, settings: Pick<SegmentedTextSettings, 'tipFn' | 'tipTemplate' | 'tipMaxLength'>): string;
|
|
342
|
+
/**
|
|
343
|
+
* A range of positions (inclusive) in the flat list of all the segments of
|
|
344
|
+
* a text.
|
|
345
|
+
*/
|
|
346
|
+
export interface SegmentRange {
|
|
347
|
+
start: number;
|
|
348
|
+
end: number;
|
|
349
|
+
}
|
|
350
|
+
type ModeSource = readonly Pick<TextSegment<unknown>, 'selectionMode'>[];
|
|
351
|
+
/**
|
|
352
|
+
* Clamp a focus position so that walking from the anchor to it never
|
|
353
|
+
* crosses a `blocked` segment.
|
|
354
|
+
* @returns The farthest position reachable from the anchor towards the
|
|
355
|
+
* focus, or the anchor itself.
|
|
356
|
+
*/
|
|
357
|
+
export declare function clampFocus(segments: ModeSource, anchor: number, focus: number): number;
|
|
358
|
+
/**
|
|
359
|
+
* Resolve the range of segments selected by dragging (or extending) from an
|
|
360
|
+
* anchor position to a focus position, according to the selection mode of
|
|
361
|
+
* each segment:
|
|
362
|
+
* - the range never crosses a `blocked` segment: it stops before it, and
|
|
363
|
+
* if the anchor itself is blocked there is no selection;
|
|
364
|
+
* - a range starting at an `attached` segment starts at its base instead,
|
|
365
|
+
* and a range ending at a segment followed by attached segments includes
|
|
366
|
+
* them;
|
|
367
|
+
* - the range is trimmed so that it starts at an `allowed` segment and ends
|
|
368
|
+
* at an `allowed` segment (or at an attached segment of an allowed one).
|
|
369
|
+
*
|
|
370
|
+
* @param segments The flat list of all the segments.
|
|
371
|
+
* @param anchor The anchor position (where the selection started).
|
|
372
|
+
* @param focus The focus position (where the selection ends).
|
|
373
|
+
* @returns The range, or null if nothing can be selected.
|
|
374
|
+
*/
|
|
375
|
+
export declare function resolveSegmentRange(segments: ModeSource, anchor: number, focus: number): SegmentRange | null;
|
|
376
|
+
/**
|
|
377
|
+
* Find the next position where a caret can be placed, i.e. the first
|
|
378
|
+
* `allowed` segment from the specified position (excluded) in the specified
|
|
379
|
+
* direction.
|
|
380
|
+
* @returns The position, or -1 if not found.
|
|
381
|
+
*/
|
|
382
|
+
export declare function findCaretPosition(segments: ModeSource, from: number, dir: 1 | -1): number;
|
|
383
|
+
/**
|
|
384
|
+
* Find the next position where the focus of a selection being extended can
|
|
385
|
+
* move to from the specified position in the specified direction: this
|
|
386
|
+
* skips `wrapped` and `attached` segments, and stops at `blocked` ones.
|
|
387
|
+
* @returns The position, or -1 if the focus cannot move.
|
|
388
|
+
*/
|
|
389
|
+
export declare function findExtendPosition(segments: ModeSource, from: number, dir: 1 | -1): number;
|
|
390
|
+
/**
|
|
391
|
+
* Find the allowed position nearest to the specified one within the range
|
|
392
|
+
* [min, max], looking forward first and then backward.
|
|
393
|
+
* @returns The position, or -1 if not found.
|
|
394
|
+
*/
|
|
395
|
+
export declare function findNearestAllowed(segments: ModeSource, pos: number, min: number, max: number): number;
|
|
396
|
+
/**
|
|
397
|
+
* Find text in the segments of the specified blocks.
|
|
398
|
+
* @param blocks The blocks.
|
|
399
|
+
* @param options The find options. When `crossSegments` is false, each
|
|
400
|
+
* segment whose value contains the query is a match; when true, the values
|
|
401
|
+
* of all the segments in each block are concatenated, and each occurrence of
|
|
402
|
+
* the query in it is a match including all the segments it overlaps (matches
|
|
403
|
+
* never cross block boundaries, and do not overlap each other).
|
|
404
|
+
* @returns The matches in text order, each with the IDs of its segments.
|
|
405
|
+
*/
|
|
406
|
+
export declare function findTextSegments(blocks: readonly TextSegmentBlock<unknown>[], options: TextSegmentFindOptions): number[][];
|
|
407
|
+
/**
|
|
408
|
+
* A service to measure the width of text rendered with a given font, used
|
|
409
|
+
* to size the SVG boxes of segments. Measures are cached, and the cache is
|
|
410
|
+
* cleared whenever web fonts finish loading: as `version` changes at that
|
|
411
|
+
* time, computations reading it are re-evaluated to get the new measures.
|
|
412
|
+
* When no canvas is available (e.g. server-side or in tests), widths are
|
|
413
|
+
* estimated from the font size.
|
|
414
|
+
*/
|
|
415
|
+
export declare class TextMeasureService {
|
|
416
|
+
private readonly _document;
|
|
417
|
+
private _context?;
|
|
418
|
+
private readonly _cache;
|
|
419
|
+
private readonly _version;
|
|
420
|
+
/**
|
|
421
|
+
* A version number incremented every time the cache is invalidated
|
|
422
|
+
* because of a change in available fonts. Read it in a computation to
|
|
423
|
+
* re-run it when measures change.
|
|
424
|
+
*/
|
|
425
|
+
readonly version: import("@angular/core").Signal<number>;
|
|
426
|
+
constructor();
|
|
427
|
+
private getContext;
|
|
428
|
+
/**
|
|
429
|
+
* Clear the cache of measures.
|
|
430
|
+
*/
|
|
431
|
+
invalidate(): void;
|
|
432
|
+
/**
|
|
433
|
+
* Estimate the width of a text from a CSS font size, used when measuring
|
|
434
|
+
* is not possible.
|
|
435
|
+
*/
|
|
436
|
+
static estimate(text: string, fontSize: string): number;
|
|
437
|
+
/**
|
|
438
|
+
* Measure the width in pixels of the specified text.
|
|
439
|
+
* @param text The text to measure.
|
|
440
|
+
* @param fontFace The CSS font family.
|
|
441
|
+
* @param fontSize The CSS font size.
|
|
442
|
+
* @returns The width.
|
|
443
|
+
*/
|
|
444
|
+
measure(text: string, fontFace: string, fontSize: string): number;
|
|
445
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<TextMeasureService, never>;
|
|
446
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* The view state of a segmented text: selection, caret and search results.
|
|
450
|
+
* This is provided by each `SegmentedTextView` instance, and contains all
|
|
451
|
+
* the selection and navigation logic, independently from the DOM. The
|
|
452
|
+
* selection is linear: it is defined by an anchor (where it started) and a
|
|
453
|
+
* focus (where it ends, i.e. the caret), both kept as segment IDs, so that
|
|
454
|
+
* it survives changes in the blocks when the same IDs are still present.
|
|
455
|
+
* Actions return true when they changed the selection.
|
|
456
|
+
*/
|
|
457
|
+
export declare class SegmentedTextStore<T = unknown> {
|
|
458
|
+
private readonly _anchorId;
|
|
459
|
+
private readonly _focusId;
|
|
460
|
+
private readonly _selectedIds;
|
|
461
|
+
/**
|
|
462
|
+
* The blocks of the text.
|
|
463
|
+
*/
|
|
464
|
+
readonly blocks: import("@angular/core").WritableSignal<readonly TextSegmentBlock<T>[]>;
|
|
465
|
+
/**
|
|
466
|
+
* All the segments of the text in their order, i.e. the flat list of
|
|
467
|
+
* the blocks segments. A "position" is an index in this list.
|
|
468
|
+
*/
|
|
469
|
+
readonly segments: import("@angular/core").Signal<readonly TextSegment<T>[]>;
|
|
470
|
+
/**
|
|
471
|
+
* Map of positions keyed by segment ID.
|
|
472
|
+
*/
|
|
473
|
+
readonly positions: import("@angular/core").Signal<Map<number, number>>;
|
|
474
|
+
private readonly _blockRanges;
|
|
475
|
+
/**
|
|
476
|
+
* The IDs of the selected segments, in their text order.
|
|
477
|
+
*/
|
|
478
|
+
readonly selectedIds: import("@angular/core").Signal<readonly number[]>;
|
|
479
|
+
/**
|
|
480
|
+
* The set of the selected segments IDs, for fast lookup.
|
|
481
|
+
*/
|
|
482
|
+
readonly selectedSet: import("@angular/core").Signal<ReadonlySet<number>>;
|
|
483
|
+
/**
|
|
484
|
+
* The selected segments, in their text order.
|
|
485
|
+
*/
|
|
486
|
+
readonly selectedSegments: import("@angular/core").Signal<TextSegment<T>[]>;
|
|
487
|
+
/**
|
|
488
|
+
* The ID of the segment with the caret (the selection focus), if any.
|
|
489
|
+
*/
|
|
490
|
+
readonly caretId: import("@angular/core").Signal<number | null>;
|
|
491
|
+
/**
|
|
492
|
+
* The current find options.
|
|
493
|
+
*/
|
|
494
|
+
readonly find: import("@angular/core").WritableSignal<TextSegmentFindOptions>;
|
|
495
|
+
/**
|
|
496
|
+
* The search matches in text order, each with its segments IDs.
|
|
497
|
+
*/
|
|
498
|
+
readonly matches: import("@angular/core").Signal<number[][]>;
|
|
499
|
+
/**
|
|
500
|
+
* The set of the IDs of all the segments in any search match.
|
|
501
|
+
*/
|
|
502
|
+
readonly hitSet: import("@angular/core").Signal<ReadonlySet<number>>;
|
|
503
|
+
/**
|
|
504
|
+
* The index of the current match, or -1. This is reset whenever matches
|
|
505
|
+
* change.
|
|
506
|
+
*/
|
|
507
|
+
readonly currentMatch: import("@angular/core").WritableSignal<number>;
|
|
508
|
+
private posOf;
|
|
509
|
+
private blockIndexOf;
|
|
510
|
+
private setIds;
|
|
511
|
+
/**
|
|
512
|
+
* Set anchor and focus, and select the range resolved between them.
|
|
513
|
+
*/
|
|
514
|
+
private applyRange;
|
|
515
|
+
/**
|
|
516
|
+
* Move the focus to the specified position, extending the selection from
|
|
517
|
+
* the current anchor, or collapsing it there.
|
|
518
|
+
*/
|
|
519
|
+
private moveFocus;
|
|
520
|
+
/**
|
|
521
|
+
* Set the blocks of the text. The current selection is kept for the
|
|
522
|
+
* segments which are still present.
|
|
523
|
+
* @returns True if the selection changed.
|
|
524
|
+
*/
|
|
525
|
+
setBlocks(blocks: readonly TextSegmentBlock<T>[]): boolean;
|
|
526
|
+
/**
|
|
527
|
+
* Start a selection at the specified segment (e.g. on pointer down).
|
|
528
|
+
* @param id The segment ID.
|
|
529
|
+
* @param extend True to extend the current selection up to this segment
|
|
530
|
+
* (e.g. on SHIFT+click) rather than starting a new one.
|
|
531
|
+
*/
|
|
532
|
+
startAt(id: number, extend?: boolean): boolean;
|
|
533
|
+
/**
|
|
534
|
+
* Extend the selection from its anchor to the specified segment (e.g.
|
|
535
|
+
* while dragging).
|
|
536
|
+
*/
|
|
537
|
+
extendTo(id: number): boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Move the caret by one segment in the specified direction.
|
|
540
|
+
* @param dir The direction.
|
|
541
|
+
* @param extend True to extend the selection, false to collapse it to the
|
|
542
|
+
* segment with the caret.
|
|
543
|
+
*/
|
|
544
|
+
moveCaret(dir: 1 | -1, extend?: boolean): boolean;
|
|
545
|
+
/**
|
|
546
|
+
* Move the caret to the same relative position in the previous or next
|
|
547
|
+
* non-empty block.
|
|
548
|
+
*/
|
|
549
|
+
moveBlock(dir: 1 | -1, extend?: boolean): boolean;
|
|
550
|
+
/**
|
|
551
|
+
* Move the caret to the start or end of its block.
|
|
552
|
+
*/
|
|
553
|
+
moveToBlockEdge(edge: 'start' | 'end', extend?: boolean): boolean;
|
|
554
|
+
/**
|
|
555
|
+
* Move the caret to the start or end of the text.
|
|
556
|
+
*/
|
|
557
|
+
moveToTextEdge(edge: 'start' | 'end', extend?: boolean): boolean;
|
|
558
|
+
private moveToEdge;
|
|
559
|
+
/**
|
|
560
|
+
* Select all the text, within the limits of blocked segments starting
|
|
561
|
+
* from the first selectable segment.
|
|
562
|
+
*/
|
|
563
|
+
selectAll(): boolean;
|
|
564
|
+
/**
|
|
565
|
+
* Clear the selection and the caret.
|
|
566
|
+
*/
|
|
567
|
+
clear(): boolean;
|
|
568
|
+
/**
|
|
569
|
+
* Directly select the specified segments, bypassing selection rules (e.g.
|
|
570
|
+
* when selecting from coordinates or from a binding). Unknown IDs are
|
|
571
|
+
* ignored, and the selection is sorted in text order.
|
|
572
|
+
*/
|
|
573
|
+
setSelectedIds(ids: readonly number[]): boolean;
|
|
574
|
+
/**
|
|
575
|
+
* Go to the next or previous search match (wrapping around), selecting it.
|
|
576
|
+
* @returns The IDs of the match segments, or null if no match.
|
|
577
|
+
*/
|
|
578
|
+
goToMatch(dir: 1 | -1): number[] | null;
|
|
579
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SegmentedTextStore<any>, never>;
|
|
580
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Options for `SpacedTextSegmenter`.
|
|
584
|
+
*/
|
|
585
|
+
export interface SpacedTextSegmenterOptions<T = unknown> {
|
|
586
|
+
/**
|
|
587
|
+
* True to include each LF as the last segment of its block. Default is
|
|
588
|
+
* false, i.e. LF just ends the block.
|
|
589
|
+
*/
|
|
590
|
+
includeLf?: boolean;
|
|
591
|
+
/**
|
|
592
|
+
* The label for a space. Default is `_`.
|
|
593
|
+
*/
|
|
594
|
+
spaceLabel?: string;
|
|
595
|
+
/**
|
|
596
|
+
* The selection mode for Unicode combining characters. Default is
|
|
597
|
+
* `wrapped`; use `attached` to keep each combining character together
|
|
598
|
+
* with its base character in any selection.
|
|
599
|
+
*/
|
|
600
|
+
combiningMode?: Extract<TextSegmentSelectionMode, 'wrapped' | 'attached'>;
|
|
601
|
+
/**
|
|
602
|
+
* An optional function to build the payload of each segment.
|
|
603
|
+
* @param char The segment character.
|
|
604
|
+
* @param id The segment ID.
|
|
605
|
+
* @param index The segment index.
|
|
606
|
+
*/
|
|
607
|
+
payloadFactory?: (char: string, id: number, index: number) => T | undefined;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* A text segmenter where each character is a segment, and each line is a
|
|
611
|
+
* block. Its coordinates are token-based and optionally character-based
|
|
612
|
+
* within tokens, a token being any sequence of non-whitespace characters.
|
|
613
|
+
* A point has form `Y.X@AxR` where `Y` is the block ordinal (1-N), `X` the
|
|
614
|
+
* token ordinal in its block (1-N), and optionally `A` is the ordinal of the
|
|
615
|
+
* first character in the token (1-N) and `R` the count of characters
|
|
616
|
+
* (1-N, omitted when 1). A range spanning several tokens has two points
|
|
617
|
+
* separated by `-`, both inclusive: the start point starts at `A` (and
|
|
618
|
+
* extends to the end of its token), the end point ends at `A+R-1` of its
|
|
619
|
+
* token. For instance, in `alpha beta`, `1.2@2x2` is `et` and
|
|
620
|
+
* `1.1@4x2-1.2@1` is `ha b`.
|
|
621
|
+
*
|
|
622
|
+
* Segment IDs are code point ordinals (1-N), and indexes are the UTF-16
|
|
623
|
+
* offsets in the source text (so that `text.substring(index, index +
|
|
624
|
+
* value.length) === value`). CR and LF are not segments (unless LF is
|
|
625
|
+
* included via options), but they still count for IDs and indexes.
|
|
626
|
+
*/
|
|
627
|
+
export declare class SpacedTextSegmenter<T = unknown> implements TextSegmenter<T> {
|
|
628
|
+
private readonly _options;
|
|
629
|
+
private readonly _indexes;
|
|
630
|
+
constructor(options?: SpacedTextSegmenterOptions<T>);
|
|
631
|
+
/**
|
|
632
|
+
* Get the label for the specified character, if it needs one: ASCII
|
|
633
|
+
* control characters get their Unicode Control Pictures symbols (U+2400),
|
|
634
|
+
* and space gets the configured space label.
|
|
635
|
+
*/
|
|
636
|
+
getLabel(char: string): string | undefined;
|
|
637
|
+
private createSegment;
|
|
638
|
+
/**
|
|
639
|
+
* Get blocks of segments from the specified text: one segment per
|
|
640
|
+
* character (code point), one block per line.
|
|
641
|
+
*/
|
|
642
|
+
getBlocks(text?: string): TextSegmentBlock<T>[];
|
|
643
|
+
private getIndex;
|
|
644
|
+
/**
|
|
645
|
+
* Get the coordinates of the specified segments, assumed to be contiguous
|
|
646
|
+
* and in text order. Whitespace segments at the edges are ignored.
|
|
647
|
+
* @returns The coordinates, or an empty string if the segments contain
|
|
648
|
+
* no token character.
|
|
649
|
+
*/
|
|
650
|
+
getSegmentCoords(blocks: readonly TextSegmentBlock<T>[], segments: readonly TextSegment<T>[]): string;
|
|
651
|
+
private static parsePoint;
|
|
652
|
+
/**
|
|
653
|
+
* Get the segments included by the specified coordinates.
|
|
654
|
+
* @returns The segments, or null if the coordinates are not valid, or
|
|
655
|
+
* refer to a non-existing location.
|
|
656
|
+
*/
|
|
657
|
+
getCoordsSegments(blocks: readonly TextSegmentBlock<T>[], coords: string): TextSegment<T>[] | null;
|
|
658
|
+
}
|
|
659
|
+
interface BoxGeometry {
|
|
660
|
+
y: number;
|
|
661
|
+
height: number;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* The geometry of a segment view.
|
|
665
|
+
*/
|
|
666
|
+
export interface TextSegmentGeometry {
|
|
667
|
+
width: number;
|
|
668
|
+
height: number;
|
|
669
|
+
strokeWidth: number;
|
|
670
|
+
radius: number;
|
|
671
|
+
text: BoxGeometry;
|
|
672
|
+
id?: BoxGeometry;
|
|
673
|
+
index?: BoxGeometry;
|
|
674
|
+
tip?: BoxGeometry;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* View of a single text segment: an SVG with a text box, optionally
|
|
678
|
+
* followed by an ID box, an index box, and a tip box. This is a dumb
|
|
679
|
+
* component, entirely driven by its inputs. Its host element carries the
|
|
680
|
+
* segment ID in its `data-seg-id` attribute, which is used by the
|
|
681
|
+
* containing views for event delegation.
|
|
682
|
+
*/
|
|
683
|
+
export declare class TextSegmentView {
|
|
684
|
+
private readonly _measure;
|
|
685
|
+
/**
|
|
686
|
+
* The segment to display.
|
|
687
|
+
*/
|
|
688
|
+
readonly segment: import("@angular/core").InputSignal<TextSegment<any>>;
|
|
689
|
+
/**
|
|
690
|
+
* The display settings.
|
|
691
|
+
*/
|
|
692
|
+
readonly settings: import("@angular/core").InputSignal<SegmentedTextSettings>;
|
|
693
|
+
/**
|
|
694
|
+
* True if the segment is selected.
|
|
695
|
+
*/
|
|
696
|
+
readonly selected: import("@angular/core").InputSignal<boolean>;
|
|
697
|
+
/**
|
|
698
|
+
* True if the segment is part of a search result.
|
|
699
|
+
*/
|
|
700
|
+
readonly hit: import("@angular/core").InputSignal<boolean>;
|
|
701
|
+
/**
|
|
702
|
+
* True if the segment has the caret.
|
|
703
|
+
*/
|
|
704
|
+
readonly caret: import("@angular/core").InputSignal<boolean>;
|
|
705
|
+
readonly label: import("@angular/core").Signal<string>;
|
|
706
|
+
readonly hostClass: import("@angular/core").Signal<string>;
|
|
707
|
+
/**
|
|
708
|
+
* True if the tip box is displayed below the segment.
|
|
709
|
+
*/
|
|
710
|
+
readonly tipBelow: import("@angular/core").Signal<boolean>;
|
|
711
|
+
/**
|
|
712
|
+
* The textual tip, when displayed below and not rendered by a component.
|
|
713
|
+
*/
|
|
714
|
+
readonly tipText: import("@angular/core").Signal<string>;
|
|
715
|
+
readonly tipInputs: import("@angular/core").Signal<{
|
|
716
|
+
segment: TextSegment<any>;
|
|
717
|
+
}>;
|
|
718
|
+
readonly geometry: import("@angular/core").Signal<TextSegmentGeometry>;
|
|
719
|
+
readonly fill: import("@angular/core").Signal<string>;
|
|
720
|
+
readonly textFill: import("@angular/core").Signal<string>;
|
|
721
|
+
readonly stroke: import("@angular/core").Signal<string>;
|
|
722
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<TextSegmentView, never>;
|
|
723
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<TextSegmentView, "cadmus-text-segment-view", never, {
|
|
724
|
+
"segment": {
|
|
725
|
+
"alias": "segment";
|
|
726
|
+
"required": true;
|
|
727
|
+
"isSignal": true;
|
|
728
|
+
};
|
|
729
|
+
"settings": {
|
|
730
|
+
"alias": "settings";
|
|
731
|
+
"required": false;
|
|
732
|
+
"isSignal": true;
|
|
733
|
+
};
|
|
734
|
+
"selected": {
|
|
735
|
+
"alias": "selected";
|
|
736
|
+
"required": false;
|
|
737
|
+
"isSignal": true;
|
|
738
|
+
};
|
|
739
|
+
"hit": {
|
|
740
|
+
"alias": "hit";
|
|
741
|
+
"required": false;
|
|
742
|
+
"isSignal": true;
|
|
743
|
+
};
|
|
744
|
+
"caret": {
|
|
745
|
+
"alias": "caret";
|
|
746
|
+
"required": false;
|
|
747
|
+
"isSignal": true;
|
|
748
|
+
};
|
|
749
|
+
}, {}, never, never, true, never>;
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Split the specified segments into runs for `word` wrapping: each run ends
|
|
753
|
+
* with a whitespace segment (i.e. a segment whose value is entirely
|
|
754
|
+
* whitespace), except for the last one.
|
|
755
|
+
*/
|
|
756
|
+
export declare function getTextSegmentRuns<T>(segments: readonly TextSegment<T>[]): TextSegment<T>[][];
|
|
757
|
+
/**
|
|
758
|
+
* View of a block of text segments: a row of segment views, reflowing to
|
|
759
|
+
* the next line when reaching the container's end, optionally preceded by
|
|
760
|
+
* the block number. According to the `wrapMode` setting, the row can wrap
|
|
761
|
+
* after any segment, or only after whitespace segments, so that words stay
|
|
762
|
+
* together. This is a dumb component, entirely driven by its inputs.
|
|
763
|
+
*/
|
|
764
|
+
export declare class TextSegmentBlockView {
|
|
765
|
+
/**
|
|
766
|
+
* The block to display.
|
|
767
|
+
*/
|
|
768
|
+
readonly block: import("@angular/core").InputSignal<TextSegmentBlock<any>>;
|
|
769
|
+
/**
|
|
770
|
+
* The display settings.
|
|
771
|
+
*/
|
|
772
|
+
readonly settings: import("@angular/core").InputSignal<SegmentedTextSettings>;
|
|
773
|
+
/**
|
|
774
|
+
* The IDs of the selected segments.
|
|
775
|
+
*/
|
|
776
|
+
readonly selectedIds: import("@angular/core").InputSignal<ReadonlySet<number>>;
|
|
777
|
+
/**
|
|
778
|
+
* The IDs of the segments in search results.
|
|
779
|
+
*/
|
|
780
|
+
readonly hitIds: import("@angular/core").InputSignal<ReadonlySet<number>>;
|
|
781
|
+
/**
|
|
782
|
+
* The ID of the segment with the caret, if any.
|
|
783
|
+
*/
|
|
784
|
+
readonly caretId: import("@angular/core").InputSignal<number | null>;
|
|
785
|
+
/**
|
|
786
|
+
* The runs of segments kept together when wrapping by word, or null
|
|
787
|
+
* when wrapping by segment.
|
|
788
|
+
*/
|
|
789
|
+
readonly runs: import("@angular/core").Signal<TextSegment<any>[][] | null>;
|
|
790
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<TextSegmentBlockView, never>;
|
|
791
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<TextSegmentBlockView, "cadmus-text-segment-block-view", never, {
|
|
792
|
+
"block": {
|
|
793
|
+
"alias": "block";
|
|
794
|
+
"required": true;
|
|
795
|
+
"isSignal": true;
|
|
796
|
+
};
|
|
797
|
+
"settings": {
|
|
798
|
+
"alias": "settings";
|
|
799
|
+
"required": false;
|
|
800
|
+
"isSignal": true;
|
|
801
|
+
};
|
|
802
|
+
"selectedIds": {
|
|
803
|
+
"alias": "selectedIds";
|
|
804
|
+
"required": false;
|
|
805
|
+
"isSignal": true;
|
|
806
|
+
};
|
|
807
|
+
"hitIds": {
|
|
808
|
+
"alias": "hitIds";
|
|
809
|
+
"required": false;
|
|
810
|
+
"isSignal": true;
|
|
811
|
+
};
|
|
812
|
+
"caretId": {
|
|
813
|
+
"alias": "caretId";
|
|
814
|
+
"required": false;
|
|
815
|
+
"isSignal": true;
|
|
816
|
+
};
|
|
817
|
+
}, {}, never, never, true, never>;
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* The debounce time (ms) for applying typed coordinates.
|
|
821
|
+
*/
|
|
822
|
+
export declare const SEGMENTED_TEXT_COORDS_DEBOUNCE = 400;
|
|
823
|
+
/** Minimum zoom factor. */
|
|
824
|
+
export declare const SEGMENTED_TEXT_MIN_ZOOM = 0.5;
|
|
825
|
+
/** Maximum zoom factor. */
|
|
826
|
+
export declare const SEGMENTED_TEXT_MAX_ZOOM = 3;
|
|
827
|
+
interface ViewControls {
|
|
828
|
+
zoom: number;
|
|
829
|
+
coords: string;
|
|
830
|
+
}
|
|
831
|
+
interface HoveredSegment<T> {
|
|
832
|
+
element: Element;
|
|
833
|
+
segment: TextSegment<T>;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* View of a segmented text: its blocks stacked vertically in a scrollable
|
|
837
|
+
* viewport, with a toolbar for zoom, find, and coordinates. Users select
|
|
838
|
+
* segments like text in an editor: by clicking, dragging, SHIFT+clicking, or
|
|
839
|
+
* with the keyboard (arrows, Home/End, CTRL+A, Escape), always within the
|
|
840
|
+
* rules defined by each segment's selection mode. The selection is exposed
|
|
841
|
+
* by the two-way `selectedIds` model, and each new selection made by the
|
|
842
|
+
* user is emitted by `selectionChange`.
|
|
843
|
+
*/
|
|
844
|
+
export declare class SegmentedTextView<T = unknown> {
|
|
845
|
+
private readonly _document;
|
|
846
|
+
private readonly _injectedSegmenter;
|
|
847
|
+
private _dragging;
|
|
848
|
+
private _dragChanged;
|
|
849
|
+
private _downId;
|
|
850
|
+
private _lastCoords;
|
|
851
|
+
/**
|
|
852
|
+
* The state store of this view.
|
|
853
|
+
*/
|
|
854
|
+
readonly store: SegmentedTextStore<T>;
|
|
855
|
+
/**
|
|
856
|
+
* The blocks of segments to display.
|
|
857
|
+
*/
|
|
858
|
+
readonly blocks: import("@angular/core").InputSignal<readonly TextSegmentBlock<T>[]>;
|
|
859
|
+
/**
|
|
860
|
+
* The display settings. Any setting not specified here gets its default
|
|
861
|
+
* value from `DEFAULT_SEGMENTED_TEXT_SETTINGS`.
|
|
862
|
+
*/
|
|
863
|
+
readonly settings: import("@angular/core").InputSignal<Partial<SegmentedTextSettings> | null | undefined>;
|
|
864
|
+
/**
|
|
865
|
+
* The segmenter used for coordinates. When not set, the one provided via
|
|
866
|
+
* the `TEXT_SEGMENTER` token is used, if any. Without a segmenter, the
|
|
867
|
+
* coordinates box is not displayed.
|
|
868
|
+
*/
|
|
869
|
+
readonly segmenter: import("@angular/core").InputSignal<TextSegmenter<T> | null | undefined>;
|
|
870
|
+
/** True to show the zoom control. */
|
|
871
|
+
readonly showZoom: import("@angular/core").InputSignal<boolean>;
|
|
872
|
+
/** True to show the find control. */
|
|
873
|
+
readonly showFind: import("@angular/core").InputSignal<boolean>;
|
|
874
|
+
/** True to show the coordinates box (when a segmenter is available). */
|
|
875
|
+
readonly showCoords: import("@angular/core").InputSignal<boolean>;
|
|
876
|
+
/** The accessible label of the text. */
|
|
877
|
+
readonly ariaLabel: import("@angular/core").InputSignal<string>;
|
|
878
|
+
/**
|
|
879
|
+
* The IDs of the selected segments, in text order.
|
|
880
|
+
*/
|
|
881
|
+
readonly selectedIds: import("@angular/core").ModelSignal<number[]>;
|
|
882
|
+
/**
|
|
883
|
+
* Emitted whenever the user makes a new selection.
|
|
884
|
+
*/
|
|
885
|
+
readonly selectionChange: import("@angular/core").OutputEmitterRef<TextSegmentSelection<T>>;
|
|
886
|
+
/**
|
|
887
|
+
* Emitted when the user clicks a segment (i.e. presses and releases the
|
|
888
|
+
* primary pointer button on the same segment), whatever its selection
|
|
889
|
+
* mode, including segments which cannot be selected like `blocked` ones.
|
|
890
|
+
* This is emitted after any selection change caused by the click.
|
|
891
|
+
*/
|
|
892
|
+
readonly segmentClick: import("@angular/core").OutputEmitterRef<TextSegmentClick<T>>;
|
|
893
|
+
readonly resolvedSettings: import("@angular/core").Signal<SegmentedTextSettings>;
|
|
894
|
+
readonly activeSegmenter: import("@angular/core").Signal<TextSegmenter<T> | null>;
|
|
895
|
+
readonly minZoom = 0.5;
|
|
896
|
+
readonly maxZoom = 3;
|
|
897
|
+
private readonly _view;
|
|
898
|
+
/**
|
|
899
|
+
* The form for the view controls (zoom and coordinates).
|
|
900
|
+
*/
|
|
901
|
+
readonly viewForm: import("@angular/forms/signals").FieldTree<ViewControls, string | number, "writable">;
|
|
902
|
+
/**
|
|
903
|
+
* The form for the find controls, bound to the store's find options.
|
|
904
|
+
*/
|
|
905
|
+
readonly findForm: import("@angular/forms/signals").FieldTree<TextSegmentFindOptions, string | number, "writable">;
|
|
906
|
+
/**
|
|
907
|
+
* True when the typed coordinates are not valid.
|
|
908
|
+
*/
|
|
909
|
+
readonly coordsError: import("@angular/core").WritableSignal<boolean>;
|
|
910
|
+
readonly viewport: import("@angular/core").Signal<ElementRef<HTMLElement>>;
|
|
911
|
+
private readonly _overlay;
|
|
912
|
+
readonly hovered: import("@angular/core").WritableSignal<HoveredSegment<T> | null>;
|
|
913
|
+
readonly popupEnabled: import("@angular/core").Signal<boolean>;
|
|
914
|
+
readonly popupText: import("@angular/core").Signal<string>;
|
|
915
|
+
readonly popupOpen: import("@angular/core").Signal<boolean>;
|
|
916
|
+
readonly popupInputs: import("@angular/core").Signal<{
|
|
917
|
+
segment: TextSegment<T> | undefined;
|
|
918
|
+
}>;
|
|
919
|
+
readonly popupOrigin: import("@angular/core").Signal<Element>;
|
|
920
|
+
readonly popupPositions: ConnectedPosition[];
|
|
921
|
+
constructor();
|
|
922
|
+
/**
|
|
923
|
+
* Update the coordinates box from the current selection.
|
|
924
|
+
* @returns The coordinates.
|
|
925
|
+
*/
|
|
926
|
+
private updateCoords;
|
|
927
|
+
/**
|
|
928
|
+
* Publish the store's selection to the model and to the selection event.
|
|
929
|
+
* @param writeCoords False to leave the coordinates box untouched, e.g.
|
|
930
|
+
* when the selection comes from it.
|
|
931
|
+
*/
|
|
932
|
+
private commit;
|
|
933
|
+
private applyCoords;
|
|
934
|
+
/**
|
|
935
|
+
* Scroll the viewport so that the specified segment is visible.
|
|
936
|
+
*/
|
|
937
|
+
scrollToSegment(id: number): void;
|
|
938
|
+
/**
|
|
939
|
+
* Clear the selection.
|
|
940
|
+
*/
|
|
941
|
+
clearSelection(): void;
|
|
942
|
+
/**
|
|
943
|
+
* Go to the next or previous search match, selecting it.
|
|
944
|
+
*/
|
|
945
|
+
goToMatch(dir: 1 | -1): void;
|
|
946
|
+
formatZoom(value: number): string;
|
|
947
|
+
resetZoom(): void;
|
|
948
|
+
clearFind(): void;
|
|
949
|
+
toggleCrossSegments(): void;
|
|
950
|
+
toggleCaseSensitive(): void;
|
|
951
|
+
onFindKeydown(event: KeyboardEvent): void;
|
|
952
|
+
private segmentIdAt;
|
|
953
|
+
private segmentById;
|
|
954
|
+
onPointerDown(event: PointerEvent): void;
|
|
955
|
+
onPointerMove(event: PointerEvent): void;
|
|
956
|
+
onPointerUp(event: PointerEvent): void;
|
|
957
|
+
private autoScroll;
|
|
958
|
+
onPointerOver(event: PointerEvent): void;
|
|
959
|
+
onPointerLeave(): void;
|
|
960
|
+
private disablePopupPointer;
|
|
961
|
+
onPopupAttach(): void;
|
|
962
|
+
onKeyDown(event: KeyboardEvent): void;
|
|
963
|
+
onWheel(event: WheelEvent): void;
|
|
964
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SegmentedTextView<any>, never>;
|
|
965
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<SegmentedTextView<any>, "cadmus-segmented-text-view", never, {
|
|
966
|
+
"blocks": {
|
|
967
|
+
"alias": "blocks";
|
|
968
|
+
"required": false;
|
|
969
|
+
"isSignal": true;
|
|
970
|
+
};
|
|
971
|
+
"settings": {
|
|
972
|
+
"alias": "settings";
|
|
973
|
+
"required": false;
|
|
974
|
+
"isSignal": true;
|
|
975
|
+
};
|
|
976
|
+
"segmenter": {
|
|
977
|
+
"alias": "segmenter";
|
|
978
|
+
"required": false;
|
|
979
|
+
"isSignal": true;
|
|
980
|
+
};
|
|
981
|
+
"showZoom": {
|
|
982
|
+
"alias": "showZoom";
|
|
983
|
+
"required": false;
|
|
984
|
+
"isSignal": true;
|
|
985
|
+
};
|
|
986
|
+
"showFind": {
|
|
987
|
+
"alias": "showFind";
|
|
988
|
+
"required": false;
|
|
989
|
+
"isSignal": true;
|
|
990
|
+
};
|
|
991
|
+
"showCoords": {
|
|
992
|
+
"alias": "showCoords";
|
|
993
|
+
"required": false;
|
|
994
|
+
"isSignal": true;
|
|
995
|
+
};
|
|
996
|
+
"ariaLabel": {
|
|
997
|
+
"alias": "ariaLabel";
|
|
998
|
+
"required": false;
|
|
999
|
+
"isSignal": true;
|
|
1000
|
+
};
|
|
1001
|
+
"selectedIds": {
|
|
1002
|
+
"alias": "selectedIds";
|
|
1003
|
+
"required": false;
|
|
1004
|
+
"isSignal": true;
|
|
1005
|
+
};
|
|
1006
|
+
}, {
|
|
1007
|
+
"selectedIds": "selectedIdsChange";
|
|
1008
|
+
"selectionChange": "selectionChange";
|
|
1009
|
+
"segmentClick": "segmentClick";
|
|
1010
|
+
}, never, never, true, never>;
|
|
1011
|
+
}
|
|
1012
|
+
export {};
|