@sub37/webvtt-adapter 1.0.2 → 1.0.4

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,6 +1,6 @@
1
1
  # @sub37/webvtt-adapter
2
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/*`.
3
+ As its name says, this adapter 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
4
 
5
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
6
 
package/lib/Adapter.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { BaseAdapter } from "@sub37/server";
2
- export default class Adapter extends BaseAdapter {
2
+ export default class WebVTTAdapter extends BaseAdapter {
3
3
  static get supportedType(): string;
4
- static toString(): string;
5
- toString(): string;
6
4
  parse(rawContent: string): BaseAdapter.ParseResult;
7
5
  }
package/lib/Adapter.js CHANGED
@@ -17,16 +17,10 @@ var BlockType;
17
17
  BlockType[BlockType["STYLE"] = 4] = "STYLE";
18
18
  BlockType[BlockType["CUE"] = 8] = "CUE";
19
19
  })(BlockType || (BlockType = {}));
20
- export default class Adapter extends BaseAdapter {
20
+ export default class WebVTTAdapter extends BaseAdapter {
21
21
  static get supportedType() {
22
22
  return "text/vtt";
23
23
  }
24
- static toString() {
25
- return "WebVTT Adapter";
26
- }
27
- toString() {
28
- return "WebVTT Adapter";
29
- }
30
24
  parse(rawContent) {
31
25
  if (!rawContent) {
32
26
  return BaseAdapter.ParseResult(undefined, [
@@ -160,10 +154,12 @@ export default class Adapter extends BaseAdapter {
160
154
  if (style.attributes.size && tag.attributes.size) {
161
155
  for (const [key, value] of tag.attributes) {
162
156
  const styleAttributeValue = style.attributes.get(key);
163
- if (styleAttributeValue === null) {
157
+ if (!styleAttributeValue) {
164
158
  continue stylesLoop;
165
159
  }
166
- if (styleAttributeValue && styleAttributeValue !== value) {
160
+ if (styleAttributeValue &&
161
+ styleAttributeValue !== value &&
162
+ styleAttributeValue !== "*") {
167
163
  continue stylesLoop;
168
164
  }
169
165
  }
@@ -245,7 +245,7 @@ export class WebVTTRenderingModifiers {
245
245
  * Cuebox's left edge matches at position
246
246
  * point and ends at 100%.
247
247
  *
248
- * For schemas, refer to width on "center" case.
248
+ * For schemas, refer to width on "line-left" case.
249
249
  */
250
250
  return this.position;
251
251
  }
@@ -13,7 +13,17 @@ export function parseRegion(rawRegionData) {
13
13
  case "regionanchor":
14
14
  case "viewportanchor": {
15
15
  const [x = "0%", y = "0%"] = value.split(",");
16
- region[key] = [parseInt(x), parseInt(y)];
16
+ if (!x.endsWith("%") || !y.endsWith("%")) {
17
+ break;
18
+ }
19
+ const xInteger = parseInt(x);
20
+ const yInteger = parseInt(y);
21
+ if (Number.isNaN(xInteger) || Number.isNaN(yInteger)) {
22
+ break;
23
+ }
24
+ const clampedX = Math.max(0, Math.min(xInteger, 100));
25
+ const clampedY = Math.max(0, Math.min(yInteger, 100));
26
+ region[key] = [clampedX, clampedY];
17
27
  break;
18
28
  }
19
29
  case "scroll": {
@@ -73,8 +83,8 @@ class WebVTTRegion {
73
83
  */
74
84
  const leftOffset = (regionAnchorWidth * this.width) / 100;
75
85
  const topOffset = (regionAnchorHeight * height) / 100;
76
- const originX = viewportAnchorWidth - leftOffset;
77
- const originY = viewportAnchorHeight - topOffset;
86
+ const originX = `${viewportAnchorWidth - leftOffset}%`;
87
+ const originY = `${viewportAnchorHeight - topOffset}%`;
78
88
  return [originX, originY];
79
89
  }
80
90
  }
@@ -90,7 +90,7 @@ function getSelectorComponents(rawSelector) {
90
90
  for (const [, tag = selector, attribute, value] of matchIterator) {
91
91
  selector = tag;
92
92
  if (attribute) {
93
- attributes.push([attribute, value]);
93
+ attributes.push([attribute, value || "*"]);
94
94
  }
95
95
  }
96
96
  return {
package/lib/Token.d.ts CHANGED
@@ -9,12 +9,12 @@ type Boundaries = {
9
9
  end: number;
10
10
  };
11
11
  export declare class Token {
12
- readonly type: TokenType;
13
- readonly content: string;
14
12
  annotations: string[];
15
13
  classes: string[];
16
14
  offset: number;
17
15
  length: number;
16
+ readonly type: TokenType;
17
+ readonly content: string;
18
18
  private constructor();
19
19
  static String(content: string, boundaries: Boundaries): Token;
20
20
  static StartTag(tagName: string, boundaries: Boundaries, classes?: string[], annotations?: string[]): Token;
package/lib/Tokenizer.js CHANGED
@@ -40,7 +40,7 @@ export class Tokenizer {
40
40
  this.startPoint = 0;
41
41
  }
42
42
  static isWhitespace(character) {
43
- return character == " " || character == "\x09" || character == "\x0C";
43
+ return character == "\x20" || character == "\x09" || character == "\x0C";
44
44
  }
45
45
  static isNewLine(character) {
46
46
  return character == "\x0A";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sub37/webvtt-adapter",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A subtitles adapter for WebVTT subtitles",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -8,9 +8,9 @@
8
8
  "@sub37/server": "^1.0.0"
9
9
  },
10
10
  "scripts": {
11
- "build": "rm -rf lib && npx tsc -p tsconfig.build.json",
12
- "test": "npm run build && npm --prefix ../.. run test",
13
- "prepublishOnly": "npm run build"
11
+ "build": "rm -rf lib && pnpm tsc -p tsconfig.build.json",
12
+ "test": "pnpm build && pnpm --prefix ../.. run test",
13
+ "prepublishOnly": "pnpm build"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
@@ -24,5 +24,6 @@
24
24
  "homepage": "https://github.com/alexandercerutti/sub37#readme",
25
25
  "files": [
26
26
  "lib/**/*.+(js|d.ts)!(*.map)"
27
- ]
27
+ ],
28
+ "gitHead": "eddbc140e9228ac38ca5858550697545423db203"
28
29
  }