@ac-kit/format-hls 0.0.0-stage → 0.1.1

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.
Files changed (148) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/LICENSE +28 -0
  3. package/README.md +145 -2
  4. package/dist/_date-range-fields.d.ts +14 -0
  5. package/dist/_date-range-fields.d.ts.map +1 -0
  6. package/dist/_date-range-fields.js +53 -0
  7. package/dist/_date-range-fields.js.map +1 -0
  8. package/dist/_key-scope.d.ts +8 -0
  9. package/dist/_key-scope.d.ts.map +1 -0
  10. package/dist/_key-scope.js +14 -0
  11. package/dist/_key-scope.js.map +1 -0
  12. package/dist/_temporal.d.ts +3 -0
  13. package/dist/_temporal.d.ts.map +1 -0
  14. package/dist/_temporal.js +14 -0
  15. package/dist/_temporal.js.map +1 -0
  16. package/dist/attribute/_print-attribute.d.ts +10 -0
  17. package/dist/attribute/_print-attribute.d.ts.map +1 -0
  18. package/dist/attribute/_print-attribute.js +31 -0
  19. package/dist/attribute/_print-attribute.js.map +1 -0
  20. package/dist/attribute/_scan-attribute-list.d.ts +24 -0
  21. package/dist/attribute/_scan-attribute-list.d.ts.map +1 -0
  22. package/dist/attribute/_scan-attribute-list.js +147 -0
  23. package/dist/attribute/_scan-attribute-list.js.map +1 -0
  24. package/dist/attribute/hls-attribute.d.ts +38 -0
  25. package/dist/attribute/hls-attribute.d.ts.map +1 -0
  26. package/dist/attribute/hls-attribute.js +42 -0
  27. package/dist/attribute/hls-attribute.js.map +1 -0
  28. package/dist/document/hls-document.d.ts +52 -0
  29. package/dist/document/hls-document.d.ts.map +1 -0
  30. package/dist/document/hls-document.js +2 -0
  31. package/dist/document/hls-document.js.map +1 -0
  32. package/dist/document/parse-hls-document.d.ts +14 -0
  33. package/dist/document/parse-hls-document.d.ts.map +1 -0
  34. package/dist/document/parse-hls-document.js +79 -0
  35. package/dist/document/parse-hls-document.js.map +1 -0
  36. package/dist/document/print-hls-document.d.ts +10 -0
  37. package/dist/document/print-hls-document.d.ts.map +1 -0
  38. package/dist/document/print-hls-document.js +28 -0
  39. package/dist/document/print-hls-document.js.map +1 -0
  40. package/dist/errors.d.ts +92 -0
  41. package/dist/errors.d.ts.map +1 -0
  42. package/dist/errors.js +67 -0
  43. package/dist/errors.js.map +1 -0
  44. package/dist/hls-playlist-queries.d.ts +16 -0
  45. package/dist/hls-playlist-queries.d.ts.map +1 -0
  46. package/dist/hls-playlist-queries.js +28 -0
  47. package/dist/hls-playlist-queries.js.map +1 -0
  48. package/dist/index.d.ts +21 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +21 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/limits.d.ts +48 -0
  53. package/dist/limits.d.ts.map +1 -0
  54. package/dist/limits.js +24 -0
  55. package/dist/limits.js.map +1 -0
  56. package/dist/live/apply-hls-delta-update.d.ts +49 -0
  57. package/dist/live/apply-hls-delta-update.d.ts.map +1 -0
  58. package/dist/live/apply-hls-delta-update.js +298 -0
  59. package/dist/live/apply-hls-delta-update.js.map +1 -0
  60. package/dist/model/hls-key.d.ts +29 -0
  61. package/dist/model/hls-key.d.ts.map +1 -0
  62. package/dist/model/hls-key.js +2 -0
  63. package/dist/model/hls-key.js.map +1 -0
  64. package/dist/model/hls-media-playlist.d.ts +202 -0
  65. package/dist/model/hls-media-playlist.d.ts.map +1 -0
  66. package/dist/model/hls-media-playlist.js +2 -0
  67. package/dist/model/hls-media-playlist.js.map +1 -0
  68. package/dist/model/hls-multivariant-playlist.d.ts +142 -0
  69. package/dist/model/hls-multivariant-playlist.d.ts.map +1 -0
  70. package/dist/model/hls-multivariant-playlist.js +2 -0
  71. package/dist/model/hls-multivariant-playlist.js.map +1 -0
  72. package/dist/model/hls-playlist.d.ts +77 -0
  73. package/dist/model/hls-playlist.d.ts.map +1 -0
  74. package/dist/model/hls-playlist.js +2 -0
  75. package/dist/model/hls-playlist.js.map +1 -0
  76. package/dist/parse/_attribute-reader.d.ts +106 -0
  77. package/dist/parse/_attribute-reader.d.ts.map +1 -0
  78. package/dist/parse/_attribute-reader.js +266 -0
  79. package/dist/parse/_attribute-reader.js.map +1 -0
  80. package/dist/parse/_context.d.ts +87 -0
  81. package/dist/parse/_context.d.ts.map +1 -0
  82. package/dist/parse/_context.js +179 -0
  83. package/dist/parse/_context.js.map +1 -0
  84. package/dist/parse/_interpret-media.d.ts +18 -0
  85. package/dist/parse/_interpret-media.d.ts.map +1 -0
  86. package/dist/parse/_interpret-media.js +677 -0
  87. package/dist/parse/_interpret-media.js.map +1 -0
  88. package/dist/parse/_interpret-multivariant.d.ts +9 -0
  89. package/dist/parse/_interpret-multivariant.d.ts.map +1 -0
  90. package/dist/parse/_interpret-multivariant.js +435 -0
  91. package/dist/parse/_interpret-multivariant.js.map +1 -0
  92. package/dist/parse/_media-validation.d.ts +14 -0
  93. package/dist/parse/_media-validation.d.ts.map +1 -0
  94. package/dist/parse/_media-validation.js +50 -0
  95. package/dist/parse/_media-validation.js.map +1 -0
  96. package/dist/parse/_prepare-lines.d.ts +12 -0
  97. package/dist/parse/_prepare-lines.d.ts.map +1 -0
  98. package/dist/parse/_prepare-lines.js +118 -0
  99. package/dist/parse/_prepare-lines.js.map +1 -0
  100. package/dist/parse/_sink.d.ts +30 -0
  101. package/dist/parse/_sink.d.ts.map +1 -0
  102. package/dist/parse/_sink.js +53 -0
  103. package/dist/parse/_sink.js.map +1 -0
  104. package/dist/parse/_values.d.ts +31 -0
  105. package/dist/parse/_values.d.ts.map +1 -0
  106. package/dist/parse/_values.js +89 -0
  107. package/dist/parse/_values.js.map +1 -0
  108. package/dist/parse/_variables.d.ts +34 -0
  109. package/dist/parse/_variables.d.ts.map +1 -0
  110. package/dist/parse/_variables.js +65 -0
  111. package/dist/parse/_variables.js.map +1 -0
  112. package/dist/parse/parse-hls-date-time.d.ts +13 -0
  113. package/dist/parse/parse-hls-date-time.d.ts.map +1 -0
  114. package/dist/parse/parse-hls-date-time.js +36 -0
  115. package/dist/parse/parse-hls-date-time.js.map +1 -0
  116. package/dist/parse/parse-hls-playlist.d.ts +58 -0
  117. package/dist/parse/parse-hls-playlist.d.ts.map +1 -0
  118. package/dist/parse/parse-hls-playlist.js +119 -0
  119. package/dist/parse/parse-hls-playlist.js.map +1 -0
  120. package/dist/parse-stream.d.ts +19 -0
  121. package/dist/parse-stream.d.ts.map +1 -0
  122. package/dist/parse-stream.js +54 -0
  123. package/dist/parse-stream.js.map +1 -0
  124. package/dist/print/print-hls-playlist.d.ts +39 -0
  125. package/dist/print/print-hls-playlist.d.ts.map +1 -0
  126. package/dist/print/print-hls-playlist.js +504 -0
  127. package/dist/print/print-hls-playlist.js.map +1 -0
  128. package/dist/print-stream.d.ts +11 -0
  129. package/dist/print-stream.d.ts.map +1 -0
  130. package/dist/print-stream.js +13 -0
  131. package/dist/print-stream.js.map +1 -0
  132. package/dist/resolve/_href.d.ts +13 -0
  133. package/dist/resolve/_href.d.ts.map +1 -0
  134. package/dist/resolve/_href.js +26 -0
  135. package/dist/resolve/_href.js.map +1 -0
  136. package/dist/resolve/hls-resolve-diagnostic.d.ts +26 -0
  137. package/dist/resolve/hls-resolve-diagnostic.d.ts.map +1 -0
  138. package/dist/resolve/hls-resolve-diagnostic.js +2 -0
  139. package/dist/resolve/hls-resolve-diagnostic.js.map +1 -0
  140. package/dist/resolve/resolve-hls-segments.d.ts +74 -0
  141. package/dist/resolve/resolve-hls-segments.d.ts.map +1 -0
  142. package/dist/resolve/resolve-hls-segments.js +179 -0
  143. package/dist/resolve/resolve-hls-segments.js.map +1 -0
  144. package/dist/resolve/resolve-hls-variants.d.ts +105 -0
  145. package/dist/resolve/resolve-hls-variants.d.ts.map +1 -0
  146. package/dist/resolve/resolve-hls-variants.js +162 -0
  147. package/dist/resolve/resolve-hls-variants.js.map +1 -0
  148. package/package.json +63 -3
@@ -0,0 +1,38 @@
1
+ /**
2
+ * One `NAME=value` pair of an attribute-list (§4.2).
3
+ *
4
+ * Only quoted or unquoted is recorded here: whether an unquoted value is a
5
+ * decimal-integer, a hexadecimal-sequence, a float, an enumerated string or a
6
+ * resolution is decided by the attribute's definition, so vendor tags and `X-`
7
+ * attributes stay readable.
8
+ */
9
+ export type HlsAttribute = {
10
+ readonly name: string;
11
+ /** Without the quotes. */
12
+ readonly value: string;
13
+ readonly quoted: boolean;
14
+ };
15
+ /**
16
+ * Parses an attribute-list in source order. No variable is substituted.
17
+ *
18
+ * Strict mode (the default) rejects whitespace, names outside `[A-Z0-9-]`,
19
+ * empty unquoted values, unterminated quotes, trailing commas and duplicate
20
+ * names. Lenient mode never throws: it skips whitespace around `,` and `=`,
21
+ * runs an unterminated quote to the end, drops a pair with no `=`, and keeps
22
+ * the first of two duplicates. O(text length).
23
+ *
24
+ * @throws {HlsSyntaxError} `invalid-attribute-list` or `duplicate-attribute` in
25
+ * strict mode, on line 1 at the offending column.
26
+ */
27
+ export declare function parseHlsAttributeList(text: string, options?: {
28
+ readonly mode?: "strict" | "lenient";
29
+ }): HlsAttribute[];
30
+ /**
31
+ * Prints attributes as an attribute-list, in the order given. O(output).
32
+ *
33
+ * @throws {HlsPlaylistError} `unprintable-value` for a name that is empty or
34
+ * holds `=`, `,`, `"`, whitespace, CR or LF; a quoted value holding `"`, CR
35
+ * or LF; or an unquoted value holding `,`, `"`, CR or LF.
36
+ */
37
+ export declare function printHlsAttributeList(attributes: readonly HlsAttribute[]): string;
38
+ //# sourceMappingURL=hls-attribute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hls-attribute.d.ts","sourceRoot":"","sources":["../../src/attribute/hls-attribute.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0BAA0B;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;CAAE,GAChD,YAAY,EAAE,CAQhB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACpC,UAAU,EAAE,SAAS,YAAY,EAAE,GACjC,MAAM,CASR"}
@@ -0,0 +1,42 @@
1
+ import { HlsSyntaxError } from "../errors.js";
2
+ import { printAttribute } from "./_print-attribute.js";
3
+ import { scanAttributeList } from "./_scan-attribute-list.js";
4
+ /**
5
+ * Parses an attribute-list in source order. No variable is substituted.
6
+ *
7
+ * Strict mode (the default) rejects whitespace, names outside `[A-Z0-9-]`,
8
+ * empty unquoted values, unterminated quotes, trailing commas and duplicate
9
+ * names. Lenient mode never throws: it skips whitespace around `,` and `=`,
10
+ * runs an unterminated quote to the end, drops a pair with no `=`, and keeps
11
+ * the first of two duplicates. O(text length).
12
+ *
13
+ * @throws {HlsSyntaxError} `invalid-attribute-list` or `duplicate-attribute` in
14
+ * strict mode, on line 1 at the offending column.
15
+ */
16
+ export function parseHlsAttributeList(text, options) {
17
+ const lenient = options?.mode === "lenient";
18
+ const scanned = scanAttributeList(text, lenient, (code, offset, message) => {
19
+ if (!lenient) {
20
+ throw new HlsSyntaxError(code, message, 1, offset + 1);
21
+ }
22
+ });
23
+ return scanned.map(({ name, value, quoted }) => ({ name, value, quoted }));
24
+ }
25
+ /**
26
+ * Prints attributes as an attribute-list, in the order given. O(output).
27
+ *
28
+ * @throws {HlsPlaylistError} `unprintable-value` for a name that is empty or
29
+ * holds `=`, `,`, `"`, whitespace, CR or LF; a quoted value holding `"`, CR
30
+ * or LF; or an unquoted value holding `,`, `"`, CR or LF.
31
+ */
32
+ export function printHlsAttributeList(attributes) {
33
+ let output = "";
34
+ for (const attribute of attributes) {
35
+ if (output.length > 0) {
36
+ output += ",";
37
+ }
38
+ output += printAttribute(attribute);
39
+ }
40
+ return output;
41
+ }
42
+ //# sourceMappingURL=hls-attribute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hls-attribute.js","sourceRoot":"","sources":["../../src/attribute/hls-attribute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAiB9D;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,qBAAqB,CACpC,IAAY,EACZ,OAAkD;IAElD,MAAM,OAAO,GAAG,OAAO,EAAE,IAAI,KAAK,SAAS,CAAC;IAC5C,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;QAC1E,IAAI,CAAC,OAAO,EAAE,CAAC;YACd,MAAM,IAAI,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;QACxD,CAAC;IACF,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACpC,UAAmC;IAEnC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,CAAC;QACf,CAAC;QACD,MAAM,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A playlist as lines, keeping everything a byte-exact reprint needs.
3
+ *
4
+ * The document layer never interprets a tag, never substitutes a variable and
5
+ * never rejects content: it is the face for editors, linters and readers of
6
+ * vendor tags, and the layer {@link parseHlsPlaylist} reads.
7
+ */
8
+ export type HlsDocument = {
9
+ readonly lines: readonly HlsLine[];
10
+ /** Whether the source began with U+FEFF, which is not part of any line. */
11
+ readonly byteOrderMark: boolean;
12
+ };
13
+ /** One line of an {@link HlsDocument}. */
14
+ export type HlsLine = HlsTagLine | HlsUriLine | HlsCommentLine | HlsBlankLine;
15
+ /**
16
+ * What ended a line: LF, CRLF, a lone CR (which the format does not allow but
17
+ * some servers write), or nothing for a last line with no terminator.
18
+ */
19
+ export type HlsLineTerminator = "\n" | "\r\n" | "\r" | "";
20
+ /** Fields every line kind carries. */
21
+ export type HlsLineBase = {
22
+ /** 1-based line number in the source. */
23
+ readonly line: number;
24
+ readonly terminator: HlsLineTerminator;
25
+ };
26
+ /**
27
+ * A line starting with `#EXT`: `#${name}` or `#${name}:${value}`. Tag names are
28
+ * case-sensitive and kept verbatim, trailing whitespace included.
29
+ */
30
+ export type HlsTagLine = HlsLineBase & {
31
+ readonly kind: "tag";
32
+ /** Without the `#`, up to the first `:`: `"EXT-X-KEY"`. */
33
+ readonly name: string;
34
+ /** Text after the first `:`, verbatim; `null` when the line has no `:`. */
35
+ readonly value: string | null;
36
+ };
37
+ /** A line that is neither blank nor starts with `#`, verbatim. */
38
+ export type HlsUriLine = HlsLineBase & {
39
+ readonly kind: "uri";
40
+ readonly text: string;
41
+ };
42
+ /** A line starting with `#` but not `#EXT`; `text` excludes the `#`. */
43
+ export type HlsCommentLine = HlsLineBase & {
44
+ readonly kind: "comment";
45
+ readonly text: string;
46
+ };
47
+ /** An empty line, or one of spaces and tabs only, verbatim. */
48
+ export type HlsBlankLine = HlsLineBase & {
49
+ readonly kind: "blank";
50
+ readonly text: string;
51
+ };
52
+ //# sourceMappingURL=h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W,GAAG;IACxC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=hls-document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hls-document.js","sourceRoot":"","sources":["../../src/document/hls-document.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import { type HlsLimits } from "../limits.js";
2
+ import type { HlsDocument } from "./hls-document.js";
3
+ /**
4
+ * Splits `source` into lines, at LF, CRLF and lone CR.
5
+ *
6
+ * Never rejects content: {@link printHlsDocument} gives `source` back exactly
7
+ * for any input within the limits. O(n) time and memory.
8
+ *
9
+ * @param options `maxLength`, `maxLineLength` and `maxLines` apply; the other
10
+ * bounds are read by {@link parseHlsPlaylist} only.
11
+ * @throws {HlsLimitError} Past `maxLength`, `maxLineLength` or `maxLines`.
12
+ */
13
+ export declare function parseHlsDocument(source: string, options?: Pick<HlsLimits, "maxLength" | "maxLineLength" | "maxLines">): HlsDocument;
14
+ //# sourceMappingURL=parse-hls-document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-hls-document.d.ts","sourceRoot":"","sources":["../../src/document/parse-hls-document.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EACX,WAAW,EAGX,MAAM,mBAAmB,CAAC;AAI3B;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,WAAW,GAAG,eAAe,GAAG,UAAU,CAAC,GACnE,WAAW,CA0Cb"}
@@ -0,0 +1,79 @@
1
+ import { CR, HASH, isAsciiBlank, LF } from "@ac-kit/core";
2
+ import { HlsLimitError } from "../errors.js";
3
+ import { hlsLimits } from "../limits.js";
4
+ const BYTE_ORDER_MARK_ = 0xfeff;
5
+ /**
6
+ * Splits `source` into lines, at LF, CRLF and lone CR.
7
+ *
8
+ * Never rejects content: {@link printHlsDocument} gives `source` back exactly
9
+ * for any input within the limits. O(n) time and memory.
10
+ *
11
+ * @param options `maxLength`, `maxLineLength` and `maxLines` apply; the other
12
+ * bounds are read by {@link parseHlsPlaylist} only.
13
+ * @throws {HlsLimitError} Past `maxLength`, `maxLineLength` or `maxLines`.
14
+ */
15
+ export function parseHlsDocument(source, options) {
16
+ const limits = hlsLimits(options);
17
+ if (source.length > limits.maxLength) {
18
+ throw new HlsLimitError("maxLength", limits.maxLength, 0);
19
+ }
20
+ const byteOrderMark = source.charCodeAt(0) === BYTE_ORDER_MARK_;
21
+ const lines = [];
22
+ let start = byteOrderMark ? 1 : 0;
23
+ while (start < source.length) {
24
+ let end = start;
25
+ let code = source.charCodeAt(end);
26
+ while (end < source.length && code !== LF && code !== CR) {
27
+ end++;
28
+ code = source.charCodeAt(end);
29
+ }
30
+ let terminator = "";
31
+ if (code === LF) {
32
+ terminator = "\n";
33
+ }
34
+ else if (code === CR) {
35
+ terminator = source.charCodeAt(end + 1) === LF ? "\r\n" : "\r";
36
+ }
37
+ const lineNumber = lines.length + 1;
38
+ if (lineNumber > limits.maxLines) {
39
+ throw new HlsLimitError("maxLines", limits.maxLines, lineNumber);
40
+ }
41
+ if (end - start > limits.maxLineLength) {
42
+ throw new HlsLimitError("maxLineLength", limits.maxLineLength, lineNumber);
43
+ }
44
+ lines.push(classifyLine_(source.slice(start, end), lineNumber, terminator));
45
+ start = end + terminator.length;
46
+ }
47
+ return { lines, byteOrderMark };
48
+ }
49
+ function classifyLine_(text, line, terminator) {
50
+ if (isBlank_(text)) {
51
+ return { kind: "blank", line, terminator, text };
52
+ }
53
+ if (text.charCodeAt(0) !== HASH) {
54
+ return { kind: "uri", line, terminator, text };
55
+ }
56
+ if (!text.startsWith("#EXT")) {
57
+ return { kind: "comment", line, terminator, text: text.slice(1) };
58
+ }
59
+ const colon = text.indexOf(":");
60
+ if (colon === -1) {
61
+ return { kind: "tag", line, terminator, name: text.slice(1), value: null };
62
+ }
63
+ return {
64
+ kind: "tag",
65
+ line,
66
+ terminator,
67
+ name: text.slice(1, colon),
68
+ value: text.slice(colon + 1),
69
+ };
70
+ }
71
+ function isBlank_(text) {
72
+ for (let index = 0; index < text.length; index++) {
73
+ if (!isAsciiBlank(text.charCodeAt(index))) {
74
+ return false;
75
+ }
76
+ }
77
+ return true;
78
+ }
79
+ //# sourceMappingURL=parse-hls-document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-hls-document.js","sourceRoot":"","sources":["../../src/document/parse-hls-document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAkB,SAAS,EAAE,MAAM,cAAc,CAAC;AAOzD,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAC/B,MAAc,EACd,OAAqE;IAErE,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAClC,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QACtC,MAAM,IAAI,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,gBAAgB,CAAC;IAChE,MAAM,KAAK,GAAc,EAAE,CAAC;IAC5B,IAAI,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAElC,OAAO,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QAC9B,IAAI,GAAG,GAAG,KAAK,CA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,CAAC,EAAE,CAAC;YAC3C,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { HlsDocument } from "./hls-document.js";
2
+ /**
3
+ * Inverse of {@link parseHlsDocument}: `printHlsDocument(parseHlsDocument(s))`
4
+ * is `s` for every `s` within the limits. O(n).
5
+ *
6
+ * A document built in code prints as given; nothing is validated, so a line
7
+ * holding a terminator or a URI line starting with `#` reads back differently.
8
+ */
9
+ export declare function printHlsDocument(document: HlsDocument): string;
10
+ //# sourceMappingURL=print-hls-document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"print-hls-document.d.ts","sourceRoot":"","sources":["../../src/document/print-hls-document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAW,MAAM,mBAAmB,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,CAM9D"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Inverse of {@link parseHlsDocument}: `printHlsDocument(parseHlsDocument(s))`
3
+ * is `s` for every `s` within the limits. O(n).
4
+ *
5
+ * A document built in code prints as given; nothing is validated, so a line
6
+ * holding a terminator or a URI line starting with `#` reads back differently.
7
+ */
8
+ export function printHlsDocument(document) {
9
+ let output = document.byteOrderMark ? "\uFEFF" : "";
10
+ for (const line of document.lines) {
11
+ output += lineText_(line) + line.terminator;
12
+ }
13
+ return output;
14
+ }
15
+ function lineText_(line) {
16
+ switch (line.kind) {
17
+ case "tag":
18
+ return line.value === null
19
+ ? `#${line.name}`
20
+ : `#${line.name}:${line.value}`;
21
+ case "comment":
22
+ return `#${line.text}`;
23
+ case "uri":
24
+ case "blank":
25
+ return line.text;
26
+ }
27
+ }
28
+ //# sourceMappingURL=print-hls-document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"print-hls-document.js","sourceRoot":"","sources":["../../src/document/print-hls-document.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAqB;IACrD,IAAI,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IACpD,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;QACnC,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC;IAC7C,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,SAAS,CAAC,IAAa;IAC/B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,KAAK;YACT,OAAO,IAAI,CAAC,KAAK,KAAK,IAAI;gBACzB,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE;gBACjB,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QAClC,KAAK,SAAS;YACb,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACxB,KAAK,KAAK,CAAC;QACX,KAAK,OAAO;YACX,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;AACF,CAAC"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Stable identifiers of everything {@link parseHlsPlaylist} can report.
3
+ *
4
+ * Every code but the three advisory ones is a violation of the playlist format
5
+ * (RFC 8216 and its successor draft, section 4): a strict parse throws at the
6
+ * first one, a lenient parse recovers and records it. The advisory codes —
7
+ * `unsupported-version`, `ignorable-tag` and `segment-exceeds-target-duration`
8
+ * — are warnings in both modes.
9
+ *
10
+ * - File level: `missing-extm3u`, `byte-order-mark`, `control-character`,
11
+ * `lone-carriage-return`, `leading-blank-line`, `invalid-whitespace`,
12
+ * `not-nfc` (text not in Unicode Normalization Form C, §4.1).
13
+ * - Syntax: `invalid-tag-name`, `invalid-tag-value`, `invalid-attribute-list`,
14
+ * `duplicate-attribute`, `missing-attribute`, `invalid-attribute-value`,
15
+ * `unsafe-integer`, `invalid-date-time`.
16
+ * - Structure: `mixed-playlist-kinds`, `misplaced-tag`, `duplicate-tag`,
17
+ * `missing-tag`, `missing-uri`, `missing-extinf`, `orphan-uri`,
18
+ * `byterange-without-previous`, `unknown-group`, `conflicting-date-range`
19
+ * (two declarations of one `EXT-X-DATERANGE` ID disagreeing on an attribute,
20
+ * §4.4.5.1).
21
+ * - Variables: `invalid-define`, `duplicate-variable`, `undefined-variable`,
22
+ * `unresolved-define`.
23
+ */
24
+ export type HlsDiagnosticCode = "missing-extm3u" | "byte-order-mark" | "control-character" | "lone-carriage-return" | "leading-blank-line" | "invalid-whitespace" | "not-nfc" | "invalid-tag-name" | "invalid-tag-value" | "invalid-attribute-list" | "duplicate-attribute" | "missing-attribute" | "invalid-attribute-value" | "unsafe-integer" | "invalid-date-time" | "mixed-playlist-kinds" | "misplaced-tag" | "duplicate-tag" | "missing-tag" | "missing-uri" | "missing-extinf" | "orphan-uri" | "byterange-without-previous" | "unknown-group" | "conflicting-date-range" | "invalid-define" | "duplicate-variable" | "undefined-variable" | "unresolved-define" | "unsupported-version" | "ignorable-tag" | "segment-exceeds-target-duration";
25
+ /** One problem found while parsing, at a 1-based line and column. */
26
+ export type HlsDiagnostic = {
27
+ readonly code: HlsDiagnosticCode;
28
+ /** An advisory never fails a parse; a violation fails a strict one. */
29
+ readonly severity: "violation" | "advisory";
30
+ readonly message: string;
31
+ /** 1-based line in the source. */
32
+ readonly line: number;
33
+ /** 1-based column, in UTF-16 code units. */
34
+ readonly column: number;
35
+ };
36
+ /**
37
+ * A playlist that breaks the format in a way the active mode does not tolerate:
38
+ * any violation in strict mode, and in both modes a missing `#EXTM3U` or a
39
+ * playlist mixing media and multivariant tags.
40
+ */
41
+ export declare class HlsSyntaxError extends SyntaxError {
42
+ readonly code: HlsDiagnosticCode;
43
+ /** 1-based line in the source. */
44
+ readonly line: number;
45
+ /** 1-based column, in UTF-16 code units. */
46
+ readonly column: number;
47
+ constructor(code: HlsDiagnosticCode, message: string,
48
+ /** 1-based line in the source. */
49
+ line: number,
50
+ /** 1-based column, in UTF-16 code units. */
51
+ column: number);
52
+ }
53
+ /** Which of the {@link HlsLimits} an {@link HlsLimitError} reports. */
54
+ export type HlsLimitName = "maxLength" | "maxLineLength" | "maxLines" | "maxSegments" | "maxExpansion" | "maxKeyScopeEntries";
55
+ /** Input past one of the {@link HlsLimits}; thrown in every mode. */
56
+ export declare class HlsLimitError extends RangeError {
57
+ readonly limit: HlsLimitName;
58
+ /** The bound that was exceeded. */
59
+ readonly value: number;
60
+ /** 1-based line where the bound was crossed; 0 before any line is read. */
61
+ readonly line: number;
62
+ constructor(limit: HlsLimitName,
63
+ /** The bound that was exceeded. */
64
+ value: number,
65
+ /** 1-based line where the bound was crossed; 0 before any line is read. */
66
+ line: number);
67
+ }
68
+ /** Why an operation on an in-memory playlist model failed. */
69
+ export type HlsPlaylistErrorCode = "unprintable-value" | "unrepresentable-value" | "not-a-delta-update" | "incomplete-delta-update" | "inconsistent-delta-update";
70
+ /**
71
+ * An in-memory model an operation cannot honour.
72
+ *
73
+ * - `unprintable-value`: the printer was handed a value the format cannot carry,
74
+ * or one that would not read back the same.
75
+ * - `unrepresentable-value`: a value derived from a hand-built model — a Media
76
+ * Sequence or Discontinuity Sequence Number — is past 2^53−1.
77
+ * - `not-a-delta-update`: {@link applyHlsDeltaUpdate} was given an update with no
78
+ * `EXT-X-SKIP`, or a previous playlist that still has one.
79
+ * - `incomplete-delta-update`: the previous playlist does not hold every segment
80
+ * the update skipped, or state the update relies on — the sub-range a byte
81
+ * range continues, or a first declaration or program-date anchor needed by a
82
+ * date range; the playlist must be reloaded without the `_HLS_skip`
83
+ * directive.
84
+ * - `inconsistent-delta-update`: the merged timeline is invalid (such as
85
+ * conflicting date-range declarations or duplicate program dates), or a byte
86
+ * range at the splice or a sequence number would overflow.
87
+ */
88
+ export declare class HlsPlaylistError extends Error {
89
+ readonly code: HlsPlaylistErrorCode;
90
+ constructor(code: HlsPlaylistErrorCode, message: string);
91
+ }
92
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,iBAAiB,GAC1B,gBAAgB,GAChB,iBAAiB,GACjB,mBAAmB,GACnB,sBAAsB,GACtB,oBAAoB,GACpB,oBAAoB,GACpB,SAAS,GACT,kBAAkB,GAClB,mBAAmB,GACnB,wBAAwB,GACxB,qBAAqB,GACrB,mBAAmB,GACnB,yBAAyB,GACzB,gBAAgB,GAChB,mBAAmB,GACnB,sBAAsB,GACtB,eAAe,GACf,eAAe,GACf,aAAa,GACb,aAAa,GACb,gBAAgB,GAChB,YAAY,GACZ,4BAA4B,GAC5B,eAAe,GACf,wBAAwB,GACxB,gBAAgB,GAChB,oBAAoB,GACpB,oBAAoB,GACpB,mBAAmB,GACnB,qBAAqB,GACrB,eAAe,GACf,iCAAiC,CAAC;AAErC,qEAAqE;AACrE,MAAM,MAAM,aAAa,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,EAAE,WAAW,GAAG,UAAU,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,WAAW;IAE7C,QAAQ,CAAC,IAAI,EAAE,iBAAiB;IAEhC,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM;IANxB,YACU,IAAI,EAAE,iBAAiB,EAChC,OAAO,EAAE,MAAM;IACf,kCAAkC;IACzB,IAAI,EAAE,MAAM;IACrB,4CAA4C;IACnC,MAAM,EAAE,MAAM,EAIvB;CACD;AAED,uEAAuE;AACvE,MAAM,MAAM,YAAY,GACrB,WAAW,GACX,eAAe,GACf,UAAU,GACV,aAAa,GACb,cAAc,GACd,oBAAoB,CAAC;AAExB,qEAAqE;AACrE,qBAAa,aAAc,SAAQ,UAAU;IAE3C,QAAQ,CAAC,KAAK,EAAE,YAAY;IAC5B,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM;IALtB,YACU,KAAK,EAAE,YAAY;IAC5B,mCAAmC;IAC1B,KAAK,EAAE,MAAM;IACtB,2EAA2E;IAClE,IAAI,EAAE,MAAM,EAQrB;CACD;AAED,8DAA8D;AAC9D,MAAM,MAAM,oBAAoB,GAC7B,mBAAmB,GACnB,uBAAuB,GACvB,oBAAoB,GACpB,yBAAyB,GACzB,2BAA2B,CAAC;AAE/B;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IAEzC,QAAQ,CAAC,IAAI,EAAE,oBAAoB;IADpC,YACU,IAAI,EAAE,oBAAoB,EACnC,OAAO,EAAE,MAAM,EAIf;CACD"}
package/dist/errors.js ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * A playlist that breaks the format in a way the active mode does not tolerate:
3
+ * any violation in strict mode, and in both modes a missing `#EXTM3U` or a
4
+ * playlist mixing media and multivariant tags.
5
+ */
6
+ export class HlsSyntaxError extends SyntaxError {
7
+ code;
8
+ line;
9
+ column;
10
+ constructor(code, message,
11
+ /** 1-based line in the source. */
12
+ line,
13
+ /** 1-based column, in UTF-16 code units. */
14
+ column) {
15
+ super(`${message} (line ${line}, column ${column})`);
16
+ this.code = code;
17
+ this.line = line;
18
+ this.column = column;
19
+ this.name = "HlsSyntaxError";
20
+ }
21
+ }
22
+ /** Input past one of the {@link HlsLimits}; thrown in every mode. */
23
+ export class HlsLimitError extends RangeError {
24
+ limit;
25
+ value;
26
+ line;
27
+ constructor(limit,
28
+ /** The bound that was exceeded. */
29
+ value,
30
+ /** 1-based line where the bound was crossed; 0 before any line is read. */
31
+ line) {
32
+ super(line > 0
33
+ ? `HLS playlist exceeds ${limit} (${value}) at line ${line}`
34
+ : `HLS playlist exceeds ${limit} (${value})`);
35
+ this.limit = limit;
36
+ this.value = value;
37
+ this.line = line;
38
+ this.name = "HlsLimitError";
39
+ }
40
+ }
41
+ /**
42
+ * An in-memory model an operation cannot honour.
43
+ *
44
+ * - `unprintable-value`: the printer was handed a value the format cannot carry,
45
+ * or one that would not read back the same.
46
+ * - `unrepresentable-value`: a value derived from a hand-built model — a Media
47
+ * Sequence or Discontinuity Sequence Number — is past 2^53−1.
48
+ * - `not-a-delta-update`: {@link applyHlsDeltaUpdate} was given an update with no
49
+ * `EXT-X-SKIP`, or a previous playlist that still has one.
50
+ * - `incomplete-delta-update`: the previous playlist does not hold every segment
51
+ * the update skipped, or state the update relies on — the sub-range a byte
52
+ * range continues, or a first declaration or program-date anchor needed by a
53
+ * date range; the playlist must be reloaded without the `_HLS_skip`
54
+ * directive.
55
+ * - `inconsistent-delta-update`: the merged timeline is invalid (such as
56
+ * conflicting date-range declarations or duplicate program dates), or a byte
57
+ * range at the splice or a sequence number would overflow.
58
+ */
59
+ export class HlsPlaylistError extends Error {
60
+ code;
61
+ constructor(code, message) {
62
+ super(message);
63
+ this.code = code;
64
+ this.name = "HlsPlaylistError";
65
+ }
66
+ }
67
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAqEA;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,WAAW;IAEpC,IAAI;IAGJ,IAAI;IAEJ,MAAM;IANhB,YACU,IAAuB,EAChC,OAAe;IACf,kCAAkC;IACzB,IAAY;IACrB,4CAA4C;IACnC,MAAc;QAEvB,KAAK,CAAC,GAAG,OAAO,UAAU,IAAI,YAAY,MAAM,GAAG,CAAC,CAAC;oBAP5C,IAAI;oBAGJ,IAAI;sBAEJ,MAAM;QAGf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC9B,CAAC;CACD;AAWD,qEAAqE;AACrE,MAAM,OAAO,aAAc,SAAQ,UAAU;IAElC,KAAK;IAEL,KAAK;IAEL,IAAI;IALd,YACU,KAAmB;IAC5B,mCAAmC;IAC1B,KAAa;IACtB,2EAA2E;IAClE,IAAY;QAErB,KAAK,CACJ,IAAI,GAAG,CAAC;YACP,CAAC,CAAC,wBAAwB,KAAK,KAAK,KAAK,aAAa,IAAI,EAAE;YAC5D,CAAC,CAAC,wBAAwB,KAAK,KAAK,KAAK,GAAG,CAC7C,CAAC;qBAVO,KAAK;qBAEL,KAAK;oBAEL,IAAI;QAOb,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC7B,CAAC;CACD;AAUD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAEhC,IAAI;IADd,YACU,IAA0B,EACnC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;oBAHN,IAAI;QAIb,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IAChC,CAAC;CACD"}
@@ -0,0 +1,16 @@
1
+ import type { HlsMediaPlaylist } from "./model/hls-media-playlist.js";
2
+ import type { HlsPlaylistHeader } from "./model/hls-playlist.js";
3
+ /**
4
+ * Whether no segment will be added: `EXT-X-ENDLIST` is present, or the type is
5
+ * `VOD` (§6.2.1). `false` means a live or event playlist to reload.
6
+ */
7
+ export declare function isHlsPlaylistComplete(playlist: Pick<HlsMediaPlaylist, "endList" | "playlistType">): boolean;
8
+ /** The sum of `EXTINF` durations, in seconds (§4.1). O(segments). */
9
+ export declare function hlsPlaylistDuration(playlist: Pick<HlsMediaPlaylist, "segments">): number;
10
+ /**
11
+ * The variables a playlist defines, by name: what to pass as a media playlist's
12
+ * `importedVariables` when its parent is this multivariant playlist.
13
+ * O(defines).
14
+ */
15
+ export declare function hlsVariables(playlist: Pick<HlsPlaylistHeader, "defines">): ReadonlyMap<string, string>;
16
+ //# sourceMappingURL=hls-playlist-queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hls-playlist-queries.d.ts","sourceRoot":"","sources":["../src/hls-playlist-queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,cAAc,CAAC,GAC1D,OAAO,CAET;AAED,qEAAqE;AACrE,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,GAC1C,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC3B,QAAQ,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAC1C,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAM7B"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Whether no segment will be added: `EXT-X-ENDLIST` is present, or the type is
3
+ * `VOD` (§6.2.1). `false` means a live or event playlist to reload.
4
+ */
5
+ export function isHlsPlaylistComplete(playlist) {
6
+ return playlist.endList || playlist.playlistType === "VOD";
7
+ }
8
+ /** The sum of `EXTINF` durations, in seconds (§4.1). O(segments). */
9
+ export function hlsPlaylistDuration(playlist) {
10
+ let duration = 0;
11
+ for (const segment of playlist.segments) {
12
+ duration += segment.duration;
13
+ }
14
+ return duration;
15
+ }
16
+ /**
17
+ * The variables a playlist defines, by name: what to pass as a media playlist's
18
+ * `importedVariables` when its parent is this multivariant playlist.
19
+ * O(defines).
20
+ */
21
+ export function hlsVariables(playlist) {
22
+ const variables = new Map();
23
+ for (const define of playlist.defines) {
24
+ variables.set(define.name, define.value);
25
+ }
26
+ return variables;
27
+ }
28
+ //# sourceMappingURL=hls-playlist-queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hls-playlist-queries.js","sourceRoot":"","sources":["../src/hls-playlist-queries.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACpC,QAA4D;IAE5D,OAAO,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,YAAY,KAAK,KAAK,CAAC;AAC5D,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,mBAAmB,CAClC,QAA4C;IAE5C,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACzC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IAC9B,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC3B,QAA4C;IAE5C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC5C,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;QACvC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC"}
@@ -0,0 +1,21 @@
1
+ export * from "./attribute/hls-attribute.js";
2
+ export * from "./document/hls-document.js";
3
+ export * from "./document/parse-hls-document.js";
4
+ export * from "./document/print-hls-document.js";
5
+ export * from "./errors.js";
6
+ export * from "./hls-playlist-queries.js";
7
+ export * from "./limits.js";
8
+ export * from "./live/apply-hls-delta-update.js";
9
+ export * from "./model/hls-key.js";
10
+ export * from "./model/hls-media-playlist.js";
11
+ export * from "./model/hls-multivariant-playlist.js";
12
+ export * from "./model/hls-playlist.js";
13
+ export * from "./parse-stream.js";
14
+ export * from "./parse/parse-hls-date-time.js";
15
+ export * from "./parse/parse-hls-playlist.js";
16
+ export * from "./print-stream.js";
17
+ export * from "./print/print-hls-playlist.js";
18
+ export * from "./resolve/hls-resolve-diagnostic.js";
19
+ export * from "./resolve/resolve-hls-segments.js";
20
+ export * from "./resolve/resolve-hls-variants.js";
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,kCAAkC,CAAC;AACjD,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ export * from "./attribute/hls-attribute.js";
2
+ export * from "./document/hls-document.js";
3
+ export * from "./document/parse-hls-document.js";
4
+ export * from "./document/print-hls-document.js";
5
+ export * from "./errors.js";
6
+ export * from "./hls-playlist-queries.js";
7
+ export * from "./limits.js";
8
+ export * from "./live/apply-hls-delta-update.js";
9
+ export * from "./model/hls-key.js";
10
+ export * from "./model/hls-media-playlist.js";
11
+ export * from "./model/hls-multivariant-playlist.js";
12
+ export * from "./model/hls-playlist.js";
13
+ export * from "./parse-stream.js";
14
+ export * from "./parse/parse-hls-date-time.js";
15
+ export * from "./parse/parse-hls-playlist.js";
16
+ export * from "./print-stream.js";
17
+ export * from "./print/print-hls-playlist.js";
18
+ export * from "./resolve/hls-resolve-diagnostic.js";
19
+ export * from "./resolve/resolve-hls-segments.js";
20
+ export * from "./resolve/resolve-hls-variants.js";
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,kCAAkC,CAAC;AACjD,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Bounds on what one playlist may cost to parse.
3
+ *
4
+ * A playlist comes from a server the caller does not control, so its size is
5
+ * the caller's problem. Each bound guards a different multiplier: the source
6
+ * text, the longest single line, the line count (every line becomes an object),
7
+ * the segment count (every segment becomes several), and the text variable
8
+ * substitution adds on top of the source.
9
+ */
10
+ export type HlsLimits = {
11
+ /**
12
+ * Most characters of source, 16 777 216 (16 Mi) by default — a day of
13
+ * one-second segments with long signed URLs is about 10 Mi. On the stream
14
+ * path the bytes are bounded at three times this before decoding.
15
+ */
16
+ readonly maxLength?: number;
17
+ /**
18
+ * Longest line, 1 048 576 characters by default, which leaves room for
19
+ * `data:` URIs.
20
+ */
21
+ readonly maxLineLength?: number;
22
+ /** Most lines, 1 048 576 by default. */
23
+ readonly maxLines?: number;
24
+ /**
25
+ * Most media segments in one media playlist, and in the result of
26
+ * {@link applyHlsDeltaUpdate}; 262 144 by default. Partial segments are
27
+ * bounded by `maxLines` only.
28
+ */
29
+ readonly maxSegments?: number;
30
+ /**
31
+ * Most characters variable substitution may add in total; `maxLength` by
32
+ * default, so a parse holds at most about twice its input. Without it a line
33
+ * of `{$a}{$a}…` with a long `a` grows quadratically.
34
+ */
35
+ readonly maxExpansion?: number;
36
+ /** Most warnings kept, 1 000 by default; later ones are counted, not stored. */
37
+ readonly maxWarnings?: number;
38
+ };
39
+ /** Every bound in {@link HlsLimits}, filled in. */
40
+ export type ResolvedHlsLimits = Required<HlsLimits>;
41
+ /** The defaults behind every unset bound in {@link HlsLimits}. */
42
+ export declare const DEFAULT_HLS_LIMITS: Readonly<Omit<ResolvedHlsLimits, "maxExpansion">>;
43
+ /**
44
+ * Fills in the unset bounds from {@link DEFAULT_HLS_LIMITS}; `maxExpansion`
45
+ * defaults to the resolved `maxLength`.
46
+ */
47
+ export declare function hlsLimits(limits?: HlsLimits): ResolvedHlsLimits;
48
+ //# sourceMappingURL=limits.d.ts.map