@sub37/webvtt-adapter 1.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 ADDED
@@ -0,0 +1,23 @@
1
+ # @sub37/webvtt-adapter
2
+
3
+ As its name says, this renderer handles whatever concerns the parsing, the tokenization and hence the conversion of a WebVTT text track so that it can be used by `@sub37/*`.
4
+
5
+ It tries to adhere as much as possible to the standard, leaving out or manipulating some concepts regarding the rendering of cues (which must be accomplished along with `@sub37/captions-renderer`).
6
+
7
+ ### Supported features
8
+
9
+ Here below a list of features that other platforms do not or partially support:
10
+
11
+ - **Timestamps** to show timed text within the same cue (right now this is not supported by browsers even if part of the standard);
12
+ - **Regions** (not very well supported by Firefox, but supported in Chromium);
13
+ - **Positioning** attributes (like `position: 30%,line-left`, supported by Firefox but not supported by Chromium);
14
+
15
+ ### Manipulated concepts or missing features
16
+
17
+ - `lines`: as one of the core principles of `@sub37/captions-renderer` is to collect everything into regions, the line amount is to be intended of how many lines the region will show before hiding older lines;
18
+ - `snapToLines`: this is not supported, cause of `lines`
19
+ - `::past / ::future`: not yet supported. Might require deep changes, but they haven't been evaluated yet;
20
+ - `::cue-region`: as above;
21
+ - Vertical text support is missing yet. Will be introduced soon, as it requires changes also into `@sub37/captions-renderer`.
22
+ - [Default CSS Properties](https://www.w3.org/TR/webvtt1/#applying-css-properties) are not supported as they are matter of `@sub37/captions-renderer`;
23
+ - [Time-aligned metadata](https://www.w3.org/TR/webvtt1/#introduction-metadata) cues are not supported yet.
@@ -0,0 +1,7 @@
1
+ import { BaseAdapter } from "@sub37/server";
2
+ export default class Adapter extends BaseAdapter {
3
+ static get supportedType(): string;
4
+ static toString(): string;
5
+ toString(): string;
6
+ parse(rawContent: string): BaseAdapter.ParseResult;
7
+ }
package/lib/Adapter.js ADDED
@@ -0,0 +1,279 @@
1
+ import { BaseAdapter, CueNode, Entities } from "@sub37/server";
2
+ import { InvalidFormatError } from "./InvalidFormatError.js";
3
+ import { MissingContentError } from "./MissingContentError.js";
4
+ import * as Parser from "./Parser/index.js";
5
+ const WEBVTT_HEADER_SECTION = /^(?:[\uFEFF\n\s]*)?WEBVTT(?:\n(.+))?/;
6
+ const BLOCK_MATCH_REGEX = /(?<blocktype>(?:REGION|STYLE|NOTE))[\s\r\n]*(?<payload>[\w\W]*)/;
7
+ const CUE_MATCH_REGEX = /(?:(?<cueid>[^\n\t]*)\s+)?(?<starttime>(?:(?:\d\d:)?(?:\d\d:)(?:\d\d)\.\d{3}))\s-->\s(?<endtime>(?:(?:\d\d:)?(?:\d\d:)(?:\d\d)\.\d{3}))\s*?(?:(?<attributes>[^\r\n]*?)\s*)[\r\n]+\s*(?<text>(?:.+\s*)+)/;
8
+ const TABS_REGEX = /\t+/g;
9
+ /**
10
+ * @see https://www.w3.org/TR/webvtt1/#file-structure
11
+ */
12
+ var BlockType;
13
+ (function (BlockType) {
14
+ BlockType[BlockType["IGNORED"] = 0] = "IGNORED";
15
+ BlockType[BlockType["HEADER"] = 1] = "HEADER";
16
+ BlockType[BlockType["REGION"] = 2] = "REGION";
17
+ BlockType[BlockType["STYLE"] = 4] = "STYLE";
18
+ BlockType[BlockType["CUE"] = 8] = "CUE";
19
+ })(BlockType || (BlockType = {}));
20
+ export default class Adapter extends BaseAdapter {
21
+ static get supportedType() {
22
+ return "text/vtt";
23
+ }
24
+ static toString() {
25
+ return "WebVTT Adapter";
26
+ }
27
+ toString() {
28
+ return "WebVTT Adapter";
29
+ }
30
+ parse(rawContent) {
31
+ if (!rawContent) {
32
+ return BaseAdapter.ParseResult(undefined, [
33
+ {
34
+ error: new MissingContentError(),
35
+ failedChunk: "",
36
+ isCritical: true,
37
+ },
38
+ ]);
39
+ }
40
+ const cues = [];
41
+ const content = String(rawContent).replace(/\r?\n/g, "\n");
42
+ const block = {
43
+ start: 0,
44
+ cursor: 0,
45
+ };
46
+ const regions = Object.create(null);
47
+ const styles = [];
48
+ const failures = [];
49
+ /**
50
+ * Phase indicator to ignore unordered blocks.
51
+ * Standard expects header (WEBVTT, STYLE, REGION, COMMENTS)
52
+ * and then only CUES and COMMENTS.
53
+ */
54
+ let latestBlockPhase = BlockType.HEADER;
55
+ do {
56
+ /**
57
+ * Checking if the current character is a newline linefeed indicator (\n) and if the next one is so.
58
+ * If so, we ended the block. The same if we reached the string end.
59
+ */
60
+ if ((content[block.cursor] !== "\n" || content[block.cursor + 1] !== "\n") &&
61
+ block.cursor !== content.length) {
62
+ block.cursor += 1;
63
+ continue;
64
+ }
65
+ try {
66
+ const blockEvaluationResult = evaluateBlock(content, block.start, block.cursor);
67
+ if (isError(blockEvaluationResult)) {
68
+ failures.push({
69
+ error: blockEvaluationResult,
70
+ failedChunk: content.substring(block.start, block.cursor),
71
+ isCritical: false,
72
+ });
73
+ /** Skipping \n\n and going to the next character */
74
+ block.cursor += 3;
75
+ block.start = block.cursor - 1;
76
+ continue;
77
+ }
78
+ /**
79
+ * According to WebVTT standard, Region and style blocks should be
80
+ * placed above the cues. So we try to ignore them if they are mixed.
81
+ */
82
+ const shouldProcessNonCues = latestBlockPhase & (BlockType.REGION | BlockType.STYLE | BlockType.HEADER);
83
+ if (isRegion(blockEvaluationResult) && shouldProcessNonCues) {
84
+ const [blockType, parsedContent] = blockEvaluationResult;
85
+ if (parsedContent === null || parsedContent === void 0 ? void 0 : parsedContent.id) {
86
+ latestBlockPhase = blockType;
87
+ regions[parsedContent.id] = parsedContent;
88
+ }
89
+ }
90
+ if (isStyle(blockEvaluationResult) && shouldProcessNonCues) {
91
+ const [blockType, parsedContent] = blockEvaluationResult;
92
+ latestBlockPhase = blockType;
93
+ styles.push(parsedContent);
94
+ }
95
+ if (isCue(blockEvaluationResult)) {
96
+ const [blockType, parsedContent] = blockEvaluationResult;
97
+ latestBlockPhase = blockType;
98
+ /**
99
+ * Saving the first cue with the id of the next cues
100
+ * so we can inherit the different properties and
101
+ * always have a reference to the cue timelines cues
102
+ * origin from.
103
+ */
104
+ let latestRootCue = undefined;
105
+ for (const parsedCue of parsedContent) {
106
+ if (parsedCue.startTime >= parsedCue.endTime) {
107
+ continue;
108
+ }
109
+ const cue = CueNode.from(latestRootCue, {
110
+ id: parsedCue.id,
111
+ startTime: parsedCue.startTime,
112
+ endTime: parsedCue.endTime,
113
+ content: parsedCue.text,
114
+ renderingModifiers: parsedCue.renderingModifiers,
115
+ });
116
+ if (parsedCue.renderingModifiers.regionIdentifier) {
117
+ cue.region = regions[parsedCue.renderingModifiers.regionIdentifier];
118
+ }
119
+ if (!latestRootCue) {
120
+ latestRootCue = cue;
121
+ }
122
+ const stylesEntities = styles
123
+ .filter((style) => {
124
+ return ((style.type === 1 /* Parser.StyleDomain.ID */ && style.selector === parsedCue.id) ||
125
+ style.type === 0 /* Parser.StyleDomain.GLOBAL */);
126
+ })
127
+ .sort(styleSpecificitySorter);
128
+ const entities = [];
129
+ if (stylesEntities.length) {
130
+ /**
131
+ * Having the same length of the style entities here allows
132
+ * us to prevent having several elements with the same styles
133
+ * in renderer.
134
+ */
135
+ const superCue = Object.getPrototypeOf(cue);
136
+ const length = superCue instanceof CueNode ? superCue.content.length : parsedCue.text.length;
137
+ entities.push(new Entities.Tag({
138
+ offset: 0,
139
+ length,
140
+ tagType: Entities.TagType.SPAN,
141
+ attributes: new Map(),
142
+ classes: [],
143
+ }));
144
+ for (let style of stylesEntities) {
145
+ entities[0].setStyles(style.styleString);
146
+ }
147
+ }
148
+ for (const tag of parsedCue.tags) {
149
+ entities.push(tag);
150
+ stylesLoop: for (const style of styles) {
151
+ if (style.type !== 2 /* Parser.StyleDomain.TAG */) {
152
+ continue;
153
+ }
154
+ if (style.tagName && style.tagName !== tag.tagType) {
155
+ continue;
156
+ }
157
+ if (style.attributes.size > tag.attributes.size) {
158
+ continue;
159
+ }
160
+ if (style.attributes.size && tag.attributes.size) {
161
+ for (const [key, value] of tag.attributes) {
162
+ const styleAttributeValue = style.attributes.get(key);
163
+ if (styleAttributeValue === null) {
164
+ continue stylesLoop;
165
+ }
166
+ if (styleAttributeValue && styleAttributeValue !== value) {
167
+ continue stylesLoop;
168
+ }
169
+ }
170
+ }
171
+ if (style.classes.length !== tag.classes.length) {
172
+ continue;
173
+ }
174
+ for (const className of tag.classes) {
175
+ if (!style.classes.includes(className)) {
176
+ continue stylesLoop;
177
+ }
178
+ }
179
+ tag.setStyles(style.styleString);
180
+ }
181
+ }
182
+ cue.entities = entities;
183
+ cues.push(cue);
184
+ }
185
+ }
186
+ /** Skipping \n\n and going to the next character */
187
+ block.cursor += 3;
188
+ block.start = block.cursor - 1;
189
+ }
190
+ catch (err) {
191
+ const error = err instanceof Error ? err : new Error(JSON.stringify(err));
192
+ return BaseAdapter.ParseResult(undefined, [
193
+ {
194
+ error,
195
+ isCritical: true,
196
+ failedChunk: undefined,
197
+ },
198
+ ]);
199
+ }
200
+ } while (block.cursor <= content.length);
201
+ return BaseAdapter.ParseResult(cues, failures);
202
+ }
203
+ }
204
+ function evaluateBlock(content, start, end) {
205
+ if (start === 0) {
206
+ /** Parsing Headers */
207
+ if (!WEBVTT_HEADER_SECTION.test(content)) {
208
+ throw new InvalidFormatError("WEBVTT_HEADER_MISSING", content.substring(start, end));
209
+ }
210
+ return [BlockType.HEADER, undefined];
211
+ }
212
+ const contentSection = content.substring(start, end);
213
+ const blockMatch = contentSection.match(BLOCK_MATCH_REGEX);
214
+ if (blockMatch === null || blockMatch === void 0 ? void 0 : blockMatch.groups["blocktype"]) {
215
+ switch (blockMatch.groups["blocktype"]) {
216
+ case "REGION": {
217
+ const payload = Parser.parseRegion(blockMatch.groups["payload"]);
218
+ return [BlockType.REGION, payload];
219
+ }
220
+ case "STYLE": {
221
+ const payload = Parser.parseStyle(blockMatch.groups["payload"]);
222
+ return [BlockType.STYLE, payload];
223
+ }
224
+ case "NOTE": {
225
+ return [BlockType.IGNORED, undefined];
226
+ }
227
+ }
228
+ }
229
+ const cueMatch = contentSection.match(CUE_MATCH_REGEX);
230
+ if (!cueMatch) {
231
+ return new InvalidFormatError("UNKNOWN_BLOCK_ENTITY", contentSection);
232
+ }
233
+ const { attributes, cueid, endtime, starttime, text } = cueMatch.groups;
234
+ const cueParsingResult = Parser.parseCue({
235
+ attributes,
236
+ cueid: cueid || `cue-${start}-${end}`,
237
+ endtime,
238
+ starttime,
239
+ text: text.replace(TABS_REGEX, ""),
240
+ });
241
+ return [BlockType.CUE, cueParsingResult];
242
+ }
243
+ function isRegion(evalutation) {
244
+ return Boolean(evalutation[0] & BlockType.REGION);
245
+ }
246
+ function isStyle(evalutation) {
247
+ return Boolean(evalutation[0] & BlockType.STYLE);
248
+ }
249
+ function isCue(evaluation) {
250
+ return Boolean(evaluation[0] & BlockType.CUE);
251
+ }
252
+ /**
253
+ * If the content is not a critical error, it will be returned as-is.
254
+ * If it is critical, it will be thrown
255
+ *
256
+ * @param evaluation
257
+ * @returns
258
+ */
259
+ function isError(evaluation) {
260
+ return !Array.isArray(evaluation) && evaluation instanceof Error;
261
+ }
262
+ /**
263
+ * Reorders styles so that Global styles are placed
264
+ * before id styles
265
+ *
266
+ * @param s1
267
+ * @param s2
268
+ * @returns
269
+ */
270
+ function styleSpecificitySorter(s1, s2) {
271
+ if (s1.type === s2.type) {
272
+ return 0;
273
+ }
274
+ if (s1.type === 1 /* Parser.StyleDomain.ID */ && s2.type === 0 /* Parser.StyleDomain.GLOBAL */) {
275
+ return 1;
276
+ }
277
+ return -1;
278
+ }
279
+ //# sourceMappingURL=Adapter.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * When VTT file doesn't start with WEBVTT format
3
+ */
4
+ type Reason = "WEBVTT_HEADER_MISSING" | "UNKNOWN_BLOCK_ENTITY" | "INVALID_CUE_FORMAT";
5
+ export declare class InvalidFormatError extends Error {
6
+ constructor(reason: Reason, dataBlock: string);
7
+ }
8
+ export {};
@@ -0,0 +1,28 @@
1
+ /**
2
+ * When VTT file doesn't start with WEBVTT format
3
+ */
4
+ export class InvalidFormatError extends Error {
5
+ constructor(reason, dataBlock) {
6
+ super();
7
+ this.name = "InvalidFormatError";
8
+ if (reason === "WEBVTT_HEADER_MISSING") {
9
+ this.message = `Content provided to WebVTTAdapter cannot be parsed.
10
+
11
+ Reason code: ${reason}
12
+ `;
13
+ }
14
+ else {
15
+ this.message = `Content provided to WebVTTAdapter cannot be parsed.
16
+
17
+ Reason code: ${reason}
18
+
19
+ This block seems to be invalid:
20
+
21
+ =============
22
+ ${dataBlock.replace(/\n/g, "\n\t")}
23
+ =============
24
+ `;
25
+ }
26
+ }
27
+ }
28
+ //# sourceMappingURL=InvalidFormatError.js.map
@@ -0,0 +1,3 @@
1
+ export declare class MissingContentError extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1,8 @@
1
+ export class MissingContentError extends Error {
2
+ constructor() {
3
+ super();
4
+ this.name = "MissingContentError";
5
+ this.message = "Cannot parse content. Empty content received.";
6
+ }
7
+ }
8
+ //# sourceMappingURL=MissingContentError.js.map
@@ -0,0 +1,18 @@
1
+ import type { RenderingModifiers } from "@sub37/server";
2
+ export declare class WebVTTRenderingModifiers implements RenderingModifiers {
3
+ static fromString(source: string | undefined): WebVTTRenderingModifiers;
4
+ private position?;
5
+ private positionAlignment?;
6
+ private align?;
7
+ private region?;
8
+ /**
9
+ * @TODO support vertical in renderer
10
+ * along with a new property "writing mode"
11
+ */
12
+ private size;
13
+ get id(): number;
14
+ get width(): number;
15
+ get leftOffset(): number;
16
+ get textAlignment(): typeof this.align;
17
+ get regionIdentifier(): string;
18
+ }
@@ -0,0 +1,300 @@
1
+ // const GROWING_LEFT = "rl";
2
+ // type GROWING_LEFT = typeof GROWING_LEFT;
3
+ // const GROWING_RIGHT = "lr";
4
+ // type GROWING_RIGHT = typeof GROWING_RIGHT;
5
+ // const HORIZONTAL = "";
6
+ // type HORIZONTAL = typeof HORIZONTAL;
7
+ const ALIGNMENT_NUMBER_IDENTIFIERS = {
8
+ start: 1,
9
+ left: 2,
10
+ center: 3,
11
+ right: 4,
12
+ end: 5,
13
+ };
14
+ export class WebVTTRenderingModifiers {
15
+ constructor() {
16
+ this.position = 50;
17
+ this.positionAlignment = "center";
18
+ this.align = "center";
19
+ /**
20
+ * @TODO support vertical in renderer
21
+ * along with a new property "writing mode"
22
+ */
23
+ // private vertical?: HORIZONTAL | GROWING_LEFT | GROWING_RIGHT = HORIZONTAL;
24
+ this.size = 100;
25
+ }
26
+ static fromString(source) {
27
+ const modifier = new WebVTTRenderingModifiers();
28
+ if (!(source === null || source === void 0 ? void 0 : source.length)) {
29
+ return modifier;
30
+ }
31
+ const properties = source.split(" ").reduce((acc, curr) => {
32
+ const [key, value] = curr.split(":");
33
+ return (key && value && Object.assign(Object.assign({}, acc), { [key]: value })) || acc;
34
+ }, {});
35
+ let position = "auto";
36
+ let positionAlignment = "auto";
37
+ for (const [key, value] of Object.entries(properties)) {
38
+ switch (key) {
39
+ case "position": {
40
+ /** e.g. position:30%,line-left */
41
+ const [pos, posAlignment] = value.split(",");
42
+ if (isPositionAlignmentStandard(posAlignment)) {
43
+ positionAlignment = posAlignment;
44
+ }
45
+ if (pos !== "auto") {
46
+ const integerPosition = (pos.endsWith("%") && parseInt(pos)) || NaN;
47
+ if (!Number.isNaN(integerPosition)) {
48
+ position = Math.min(Math.max(0, integerPosition), 100);
49
+ }
50
+ }
51
+ break;
52
+ }
53
+ /** e.g. align:center */
54
+ case "align": {
55
+ if (isTextAlignmentStandard(value)) {
56
+ modifier.align = value;
57
+ }
58
+ break;
59
+ }
60
+ /** e.g. region:fred */
61
+ case "region": {
62
+ modifier.region = value;
63
+ break;
64
+ }
65
+ /** e.g. size:80% */
66
+ case "size": {
67
+ const integerSize = (value.endsWith("%") && parseInt(value)) || NaN;
68
+ if (!Number.isNaN(integerSize)) {
69
+ modifier.size = Math.min(Math.max(0, integerSize), 100);
70
+ }
71
+ break;
72
+ }
73
+ // case "vertical": {
74
+ // if (isVerticalStandard(value)) {
75
+ // modifier.vertical = value;
76
+ // }
77
+ // break;
78
+ // }
79
+ }
80
+ }
81
+ // **************************************************** //
82
+ // ***************** DEPENDENCY PHASE ***************** //
83
+ // *** Some properties final value depend on others *** //
84
+ // **************************************************** //
85
+ /**
86
+ * @see https://www.w3.org/TR/webvtt1/#webvtt-cue-position
87
+ */
88
+ if (position === "auto") {
89
+ switch (modifier.align) {
90
+ case "left": {
91
+ modifier.position = 0;
92
+ break;
93
+ }
94
+ case "right": {
95
+ modifier.position = 100;
96
+ break;
97
+ }
98
+ default: {
99
+ modifier.position = 50;
100
+ }
101
+ }
102
+ }
103
+ else {
104
+ modifier.position = position;
105
+ }
106
+ if (positionAlignment === "auto") {
107
+ switch (modifier.align) {
108
+ case "left": {
109
+ modifier.positionAlignment = "line-left";
110
+ break;
111
+ }
112
+ case "right": {
113
+ modifier.positionAlignment = "line-right";
114
+ break;
115
+ }
116
+ case "start":
117
+ case "end": {
118
+ /**
119
+ * @TODO to implement based on base direction
120
+ * base direction is detected with
121
+ *
122
+ * U+200E LEFT-TO-RIGHT MARK ---> start: "line-left", end: "line-right"
123
+ * U+200F RIGHT-TO-LEFT MARK ---> start: "line-right", end: "line-left"
124
+ */
125
+ break;
126
+ }
127
+ default: {
128
+ modifier.positionAlignment = "center";
129
+ }
130
+ }
131
+ }
132
+ else {
133
+ modifier.positionAlignment = positionAlignment;
134
+ }
135
+ return modifier;
136
+ }
137
+ get id() {
138
+ return Math.abs(this.width + this.leftOffset - ALIGNMENT_NUMBER_IDENTIFIERS[this.align]);
139
+ }
140
+ get width() {
141
+ /**
142
+ * Width, and hence cuebox left offset, calculation is
143
+ * highly influenced by the alignment.
144
+ *
145
+ * In fact, we need to apply different formulas based on
146
+ * the point we start and the direction we want to proceed.
147
+ *
148
+ * In the same way, also leftOffset is influenced by alignment
149
+ * and highly tied to width.
150
+ */
151
+ switch (this.positionAlignment) {
152
+ case "line-left": {
153
+ /**
154
+ * Cuebox's left edge matches at position
155
+ * point and ends at 100%.
156
+ *
157
+ * @example scheme, 60%
158
+ * Calculation starts from right edge
159
+ *
160
+ * 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
161
+ * |----|----|----|----|----|----|----|----|----|----|
162
+ * | | |
163
+ * | |----|----|----|----|
164
+ * | Left Offset | |--te|xt--| |
165
+ * | |----|----|----|----|
166
+ * | | |
167
+ * |----|----|----|----|----|----|----|----|----|----|
168
+ */
169
+ return Math.min(this.size, 100 - this.position);
170
+ }
171
+ case "center": {
172
+ /**
173
+ * Cuebox center matches the position point
174
+ * and spans in both direction.
175
+ *
176
+ * Based on the position point, we need to change
177
+ * the formula to begin calculating the width
178
+ * starting from one edge or the other.
179
+ *
180
+ * @example scheme, point < 50%
181
+ * Calculation start from left edge
182
+ *
183
+ * 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
184
+ * |----|----|----|----|----|----|----|----|----|----|
185
+ * | | |
186
+ * |----|----|----|----|----|----| |
187
+ * | |--te|xt--| | |
188
+ * |----|----|----|----|----|----| |
189
+ * | | |
190
+ * |----|----|----|----|----|----|----|----|----|----|
191
+ */
192
+ if (this.position <= 50) {
193
+ return Math.min(this.size, this.position * 2);
194
+ }
195
+ /**
196
+ * @example scheme, point > 50%
197
+ * Calculation starts from right edge
198
+ *
199
+ * 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
200
+ * |----|----|----|----|----|----|----|----|----|----|
201
+ * | | |
202
+ * | Left |----|----|----|----|----|----|----|----|
203
+ * | - | |--te|xt--| |
204
+ * | Offset |----|----|----|----|----|----|----|----|
205
+ * | | |
206
+ * |----|----|----|----|----|----|----|----|----|----|
207
+ */
208
+ return Math.min(this.size, (100 - this.position) * 2);
209
+ }
210
+ case "line-right": {
211
+ /**
212
+ * Cuebox's right edge matches the position point
213
+ * and spans the available space on the left
214
+ * (to 0%)
215
+ *
216
+ * @example scheme, 60%
217
+ * Calculation starts from left edge
218
+ *
219
+ * 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
220
+ * |----|----|----|----|----|----|----|----|----|----|
221
+ * | | |
222
+ * |----|----|----|----|----|----| |
223
+ * | |--te|xt--| | |
224
+ * |----|----|----|----|----|----| |
225
+ * | | |
226
+ * |----|----|----|----|----|----|----|----|----|----|
227
+ */
228
+ return Math.min(this.size, this.position);
229
+ }
230
+ }
231
+ }
232
+ get leftOffset() {
233
+ /**
234
+ * Width, and hence cuebox left offset, calculation is
235
+ * highly influenced by the alignment.
236
+ * In fact, we need to apply different formulas based on
237
+ * the point we start and the direction we want to proceed.
238
+ *
239
+ * In the same way, also leftOffset is influenced by alignment
240
+ * and highly tied to width.
241
+ */
242
+ switch (this.positionAlignment) {
243
+ case "line-left": {
244
+ /**
245
+ * Cuebox's left edge matches at position
246
+ * point and ends at 100%.
247
+ *
248
+ * For schemas, refer to width on "center" case.
249
+ */
250
+ return this.position;
251
+ }
252
+ case "center": {
253
+ /**
254
+ * Cuebox center matches the position point
255
+ * and spans in both direction.
256
+ *
257
+ * Based on the position point, we need to change
258
+ * the formula to begin calculating the width,
259
+ * and hence the leftOffset, starting from one
260
+ * edge or the other.
261
+ *
262
+ * For schemas, refer to width on "center" case.
263
+ */
264
+ if (this.position <= 50) {
265
+ return 0;
266
+ }
267
+ const width = (100 - this.position) * 2;
268
+ return 100 - width;
269
+ }
270
+ case "line-right": {
271
+ /**
272
+ * Cuebox's right edge matches the position point
273
+ * and spans the available space on the left
274
+ * (to 0%)
275
+ *
276
+ * For schemas, refer to width on "line-right" case.
277
+ */
278
+ return 0;
279
+ }
280
+ }
281
+ }
282
+ get textAlignment() {
283
+ return this.align;
284
+ }
285
+ get regionIdentifier() {
286
+ return this.region;
287
+ }
288
+ }
289
+ function isPositionAlignmentStandard(alignment) {
290
+ return ["line-left", "center", "line-right"].includes(alignment);
291
+ }
292
+ function isTextAlignmentStandard(alignment) {
293
+ return ["start", "left", "center", "right", "end"].includes(alignment);
294
+ }
295
+ // function isVerticalStandard(
296
+ // vertical: string,
297
+ // ): vertical is HORIZONTAL | GROWING_LEFT | GROWING_RIGHT {
298
+ // return [HORIZONTAL, GROWING_LEFT, GROWING_RIGHT].includes(vertical);
299
+ // }
300
+ //# sourceMappingURL=RenderingModifiers.js.map