@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,119 @@
1
+ import { memoize, percentDecodedQuery } from "@ac-kit/core";
2
+ import { parseHlsDocument } from "../document/parse-hls-document.js";
3
+ import { HlsSyntaxError } from "../errors.js";
4
+ import { hlsLimits } from "../limits.js";
5
+ import { interpretMediaPlaylist } from "./_interpret-media.js";
6
+ import { interpretMultivariantPlaylist } from "./_interpret-multivariant.js";
7
+ import { prepareLines } from "./_prepare-lines.js";
8
+ import { DiagnosticSink } from "./_sink.js";
9
+ import { VariableTable } from "./_variables.js";
10
+ /**
11
+ * Parses a media or multivariant playlist (RFC 8216 and
12
+ * draft-pantos-hls-rfc8216bis-22, protocol versions 1 to 13), applying variable
13
+ * substitution and tag scoping. Fetches nothing.
14
+ *
15
+ * A playlist with neither media nor multivariant tags is an empty multivariant
16
+ * playlist (§4.1). Lenient mode also tolerates what real servers write: a byte
17
+ * order mark, blank lines before `#EXTM3U`, lone CR line ends, trailing
18
+ * whitespace in tag names and around attribute-list separators, lower-case
19
+ * hexadecimal digits. A plain M3U file with no `#EXTM3U` is rejected in both
20
+ * modes.
21
+ *
22
+ * O(n + e) time and memory, n the source length and e the characters
23
+ * substitution adds (at most `maxExpansion`).
24
+ *
25
+ * @throws {HlsSyntaxError} On the first violation in strict mode; in both modes
26
+ * on `missing-extm3u` or `mixed-playlist-kinds`.
27
+ * @throws {HlsLimitError} Past one of the {@link HlsLimits}, in both modes.
28
+ */
29
+ export function parseHlsPlaylist(source, options) {
30
+ const limits = hlsLimits(options);
31
+ const sink = new DiagnosticSink(options?.mode === "lenient", limits.maxWarnings);
32
+ const lines = prepareLines(parseHlsDocument(source, limits), sink);
33
+ const context = {
34
+ sink,
35
+ variables: new VariableTable(sink, limits.maxExpansion),
36
+ limits,
37
+ baseUrl: options?.url === undefined ? null : URL.parse(options.url),
38
+ queryParameters: memoize(() => options?.url === undefined ? new Map() : percentDecodedQuery(options.url)),
39
+ importedVariables: options?.importedVariables,
40
+ };
41
+ const playlist = detectKind_(lines, sink) === "media"
42
+ ? interpretMediaPlaylist(context, lines)
43
+ : interpretMultivariantPlaylist(context, lines);
44
+ return {
45
+ playlist,
46
+ warnings: sink.warnings,
47
+ warningsTruncated: sink.truncated,
48
+ };
49
+ }
50
+ /**
51
+ * {@link parseHlsPlaylist}, answering `null` instead of throwing
52
+ * {@link HlsSyntaxError}. Limits still throw.
53
+ */
54
+ export function tryParseHlsPlaylist(source, options) {
55
+ try {
56
+ return parseHlsPlaylist(source, options);
57
+ }
58
+ catch (error) {
59
+ if (error instanceof HlsSyntaxError) {
60
+ return null;
61
+ }
62
+ throw error;
63
+ }
64
+ }
65
+ const MEDIA_TAGS_ = new Set([
66
+ "EXT-X-TARGETDURATION",
67
+ "EXT-X-MEDIA-SEQUENCE",
68
+ "EXT-X-DISCONTINUITY-SEQUENCE",
69
+ "EXT-X-ENDLIST",
70
+ "EXT-X-PLAYLIST-TYPE",
71
+ "EXT-X-I-FRAMES-ONLY",
72
+ "EXT-X-PART-INF",
73
+ "EXT-X-SERVER-CONTROL",
74
+ "EXTINF",
75
+ "EXT-X-BYTERANGE",
76
+ "EXT-X-DISCONTINUITY",
77
+ "EXT-X-KEY",
78
+ "EXT-X-MAP",
79
+ "EXT-X-PROGRAM-DATE-TIME",
80
+ "EXT-X-GAP",
81
+ "EXT-X-BITRATE",
82
+ "EXT-X-PART",
83
+ "EXT-X-DATERANGE",
84
+ "EXT-X-SKIP",
85
+ "EXT-X-PRELOAD-HINT",
86
+ "EXT-X-RENDITION-REPORT",
87
+ ]);
88
+ const MULTIVARIANT_TAGS_ = new Set([
89
+ "EXT-X-MEDIA",
90
+ "EXT-X-STREAM-INF",
91
+ "EXT-X-I-FRAME-STREAM-INF",
92
+ "EXT-X-SESSION-DATA",
93
+ "EXT-X-SESSION-KEY",
94
+ "EXT-X-CONTENT-STEERING",
95
+ ]);
96
+ function detectKind_(lines, sink) {
97
+ let kind = null;
98
+ for (const line of lines) {
99
+ if (line.kind !== "tag") {
100
+ continue;
101
+ }
102
+ const lineKind = MEDIA_TAGS_.has(line.name)
103
+ ? "media"
104
+ : MULTIVARIANT_TAGS_.has(line.name)
105
+ ? "multivariant"
106
+ : null;
107
+ if (lineKind === null) {
108
+ continue;
109
+ }
110
+ if (kind === null) {
111
+ kind = lineKind;
112
+ }
113
+ else if (kind !== lineKind) {
114
+ sink.fatal("mixed-playlist-kinds", line.line, 1, `${line.name} is a ${lineKind} tag in a ${kind} playlist`);
115
+ }
116
+ }
117
+ return kind ?? "multivariant";
118
+ }
119
+ //# sourceMappingURL=parse-hls-playlist.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-hls-playlist.js","sourceRoot":"","sources":["../../src/parse/parse-hls-playlist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAkB,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAiChD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,gBAAgB,CAC/B,MAAc,EACd,OAAyB;IAEzB,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,IAAI,cAAc,CAC9B,OAAO,EAAE,IAAI,KAAK,SAAS,EAC3B,MAAM,CAAC,WAAW,CAClB,CAAC;IACF,MAAM,KAAK,GAAG,YAAY,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IACnE,MAAM,OAAO,GAAiB;QAC7B,IAAI;QACJ,SAAS,EAAE,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* Buffers a UTF-8 byte stream and emits one {@link HlsParseResult} when it ends:
4
+ * a playlist is always reloaded whole, so nothing can be emitted earlier.
5
+ *
6
+ * Every chunk is copied into one owned, growing buffer as it arrives, so the
7
+ * caller may reuse its chunk once written, and empty chunks cost nothing. The
8
+ * bytes held are bounded at three times `maxLength`, the most UTF-8 a string of
9
+ * `maxLength` UTF-16 units can take; the buffer's capacity at most that.
10
+ * Decoding is fatal in strict mode, as §4.1 says a client should fail on a
11
+ * playlist that is not UTF-8; lenient mode replaces bad sequences with U+FFFD.
12
+ * A byte order mark is kept for the parser to judge. Errors are wrapped in an
13
+ * `Error` whose `cause` is the {@link HlsSyntaxError}, {@link HlsLimitError} or
14
+ * decoding `TypeError`.
15
+ */
16
+ export declare class HlsParseStream extends TransformStream<Uint8Array, HlsParseResult> {
17
+ constructor(options?: HlsParseOptions);
18
+ }
19
+ //# sourceMappingURL=parse-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-stream.d.ts","sourceRoot":"","sources":["../src/parse-stream.ts"],"names":[],"mappings":"AAIA,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,cAAc,EAEnB,MAAM,+BAA+B,CAAC;AAEvC;;;;;;;;;;;;;GAaG;AACH,qBAAa,cAAe,SAAQ,eAAe,CAClD,UAAU,EACV,cAAc,CACd;IACA,YAAY,OAAO,CAAC,EAAE,eAAe,EA8BpC;CACD"}
@@ -0,0 +1,54 @@
1
+ import { BufferOverflowError, ByteAccumulator, decodeText } from "@ac-kit/core";
2
+ import { HlsLimitError } from "./errors.js";
3
+ import { hlsLimits } from "./limits.js";
4
+ import { parseHlsPlaylist, } from "./parse/parse-hls-playlist.js";
5
+ /**
6
+ * Buffers a UTF-8 byte stream and emits one {@link HlsParseResult} when it ends:
7
+ * a playlist is always reloaded whole, so nothing can be emitted earlier.
8
+ *
9
+ * Every chunk is copied into one owned, growing buffer as it arrives, so the
10
+ * caller may reuse its chunk once written, and empty chunks cost nothing. The
11
+ * bytes held are bounded at three times `maxLength`, the most UTF-8 a string of
12
+ * `maxLength` UTF-16 units can take; the buffer's capacity at most that.
13
+ * Decoding is fatal in strict mode, as §4.1 says a client should fail on a
14
+ * playlist that is not UTF-8; lenient mode replaces bad sequences with U+FFFD.
15
+ * A byte order mark is kept for the parser to judge. Errors are wrapped in an
16
+ * `Error` whose `cause` is the {@link HlsSyntaxError}, {@link HlsLimitError} or
17
+ * decoding `TypeError`.
18
+ */
19
+ export class HlsParseStream extends TransformStream {
20
+ constructor(options) {
21
+ const lenient = options?.mode === "lenient";
22
+ const maxLength = hlsLimits(options).maxLength;
23
+ const buffer = new ByteAccumulator(Math.max(1, maxLength * 3), {
24
+ initialCapacity: 65536,
25
+ });
26
+ const wrap = (cause) => new Error("parse HLS", { cause });
27
+ super({
28
+ transform(chunk) {
29
+ try {
30
+ buffer.append(chunk);
31
+ }
32
+ catch (error) {
33
+ if (error instanceof BufferOverflowError) {
34
+ throw wrap(new HlsLimitError("maxLength", maxLength, 0));
35
+ }
36
+ throw error;
37
+ }
38
+ },
39
+ flush(controller) {
40
+ try {
41
+ const source = decodeText(buffer.take(), "utf-8", {
42
+ fatal: !lenient,
43
+ ignoreBOM: true,
44
+ });
45
+ controller.enqueue(parseHlsPlaylist(source, options));
46
+ }
47
+ catch (error) {
48
+ throw wrap(error);
49
+ }
50
+ },
51
+ });
52
+ }
53
+ }
54
+ //# sourceMappingURL=parse-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-stream.js","sourceRoot":"","sources":["../src/parse-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAGN,gBAAgB,GAChB,MAAM,+BAA+B,CAAC;AAEvC;;;;;;;;;;;;;GAaG;AACH,M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39 @@
1
+ import type { HlsPlaylist } from "../model/hls-playlist.js";
2
+ /** Options of {@link printHlsPlaylist}. */
3
+ export type HlsPrintOptions = {
4
+ /** Line terminator, `"\n"` by default. */
5
+ readonly newline?: "\n" | "\r\n";
6
+ };
7
+ /**
8
+ * Prints `playlist` in canonical tag order. Comments, blank lines and the
9
+ * spelling of numbers are not kept; the document layer
10
+ * ({@link printHlsDocument}) is the byte-exact face.
11
+ *
12
+ * - Defaults are left implicit (`EXT-X-MEDIA-SEQUENCE:0`, `DEFAULT=NO`).
13
+ * - Each block's `EXT-X-KEY` tags are written as declared; `EXT-X-MAP` and
14
+ * `EXT-X-BITRATE` where the value in effect changes.
15
+ * - Numbers are the shortest decimal that reads back to the same `number`, never
16
+ * in exponent form; `-0` stays `-0` where the format allows a sign.
17
+ * - Variables are written back as definitions, and every value as it was after
18
+ * substitution, so the output can be longer than the source.
19
+ * - An unknown tag is written raw at the end of its block: the header, a segment
20
+ * (after its `EXTINF`) or the trailer.
21
+ *
22
+ * Guarantee: for any `p` that `parseHlsPlaylist(source, options)` produced,
23
+ * `parseHlsPlaylist(printHlsPlaylist(p), options).playlist` deep-equals `p` —
24
+ * given the same options, since an `IMPORT` or `QUERYPARAM` definition reads
25
+ * its value from them, and limits large enough for the printed text, which
26
+ * holds substituted values. A lenient parse ignores a definition that comes
27
+ * after a reference to its name, so a reference it left as written never meets
28
+ * a definition on the way back. O(output).
29
+ *
30
+ * @throws {HlsPlaylistError} `unprintable-value` for a value the format cannot
31
+ * carry or that would read back differently: a quoted value holding `"`, CR
32
+ * or LF; a negative, non-finite or unsafe number where the format wants a
33
+ * non-negative one; a URI line that is empty, starts with `#` or holds
34
+ * surrounding whitespace; an `EXT-X-MAP` or `EXT-X-BITRATE` that stops being
35
+ * in effect; or a value holding `{$name}` for a variable the playlist
36
+ * defines, which would be substituted on the way back.
37
+ */
38
+ export declare function printHlsPlaylist(playlist: HlsPlaylist, options?: HlsPrintOptions): string;
39
+ //# sourceMappingURL=print-hls-playlist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"print-hls-playlist.d.ts","sourceRoot":"","sources":["../../src/print/print-hls-playlist.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAEX,WAAW,EAGX,MAAM,0BAA0B,CAAC;AAElC,2CAA2C;AAC3C,MAAM,MAAM,eAAe,GAAG;IAC7B,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CACjC,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,gBAAgB,CAC/B,QAAQ,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE,eAAe,GACvB,MAAM,CASR"}