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

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 +72 -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
package/CHANGELOG.md ADDED
@@ -0,0 +1,72 @@
1
+ # @ac-kit/format-hls
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5152230: New package: HLS playlists (RFC 8216 and draft-pantos-hls-rfc8216bis-22,
8
+ protocol versions 1 to 13).
9
+
10
+ - `parseHlsPlaylist(source, options)` reads a media or multivariant playlist
11
+ into a typed model of every tag, low-latency, delta-update, date-range and
12
+ content-steering tags included, with variable substitution (`IMPORT` through
13
+ `importedVariables`, `QUERYPARAM` through `url`). Strict by default: the
14
+ first violation throws `HlsSyntaxError` with a stable `code`, line and
15
+ column. `mode: "lenient"` recovers from each, reports it in `warnings`, and
16
+ keeps every variant. Plain M3U, mixed playlist kinds and the size limits
17
+ (`maxLength` 16 Mi by default, `maxLineLength`, `maxLines`, `maxSegments`,
18
+ `maxExpansion`, `maxWarnings`; `HlsLimitError`) fail in both modes; an
19
+ integer past 2^53−1 fails strict and sets the tag aside in lenient mode;
20
+ `EXT-X-VERSION` above 13 is advisory. `tryParseHlsPlaylist` answers `null`
21
+ instead of throwing.
22
+ - `printHlsPlaylist` writes a model back; for a model a parse produced,
23
+ parsing its output with the same options, and limits large enough for the
24
+ output, gives the same model. `parseHlsDocument`/`printHlsDocument` are the
25
+ byte-exact line layer, `parseHlsAttributeList`/`printHlsAttributeList` the
26
+ attribute-list grammar.
27
+ - `resolveHlsSegments` and `resolveHlsVariants` resolve against the playlist
28
+ URL: absolute `href`s (`null` with a diagnostic of its own for an item that
29
+ cannot be fetched as described), sequence numbers, byte ranges,
30
+ initialization sections, the keys in effect (bounded by
31
+ `maxKeyScopeEntries`) and `encrypted`, program dates as `Temporal.Instant`,
32
+ rendition groups with `unresolvedGroups`, `sessionKeys`, Content Steering
33
+ pathways with a `pathwayId` filter, and §6.3.1 filtering behind
34
+ `skipUnsupported`. An unrecognized `TYPE` is kept in `unknownAttributes`
35
+ with `HlsRendition.type: null`; it joins no typed group, but a reference to
36
+ its `GROUP-ID` with no usable match is `unsupported`, not `absent`. The
37
+ model keeps keys as per-block `keyTags` declarations.
38
+ - `applyHlsDeltaUpdate` merges an `EXT-X-SKIP` delta update into the previous
39
+ playlist, carrying the key, program-date and byte-range state that slid out
40
+ and every date-range declaration. It checks the byte-range splice, timeline
41
+ and sequence numbers (`incomplete-delta-update`,
42
+ `inconsistent-delta-update`). `isHlsPlaylistComplete`, `hlsPlaylistDuration`,
43
+ `hlsVariables` and `parseHlsDateTime` answer the common questions.
44
+ - `HlsParseStream` and `HlsPrintStream` wrap parsing and printing for byte
45
+ streams; the parse stream copies each chunk into one bounded buffer, and
46
+ decoding is fatal in strict mode.
47
+
48
+ Only a clean, unquoted `METHOD=NONE` on its own clears the active key scope.
49
+ Keys and session keys are plain data: nothing fetches, resolves a key URI,
50
+ derives an IV or decrypts. Program dates need a `Temporal` global (Node 26, or
51
+ a polyfill such as `temporal-polyfill`).
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies [2a0fe74]
56
+ - Updated dependencies [5152230]
57
+ - Updated dependencies [2a0fe74]
58
+ - Updated dependencies [5152230]
59
+ - Updated dependencies [5152230]
60
+ - Updated dependencies [2a0fe74]
61
+ - Updated dependencies [2a0fe74]
62
+ - Updated dependencies [5152230]
63
+ - Updated dependencies [5152230]
64
+ - Updated dependencies [5152230]
65
+ - Updated dependencies [5152230]
66
+ - Updated dependencies [5152230]
67
+ - Updated dependencies [5152230]
68
+ - Updated dependencies [5152230]
69
+ - Updated dependencies [5152230]
70
+ - @ac-kit/core@0.10.0
71
+ - @ac-kit/format-core@0.4.0
72
+ - @ac-kit/math-numbers@0.2.7
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,3 +1,146 @@
1
- # Temporary Holding Version
1
+ # @ac-kit/format-hls
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ HLS playlists — RFC 8216 and its successor, draft-pantos-hls-rfc8216bis
4
+ (protocol versions 1 to 13): parse, model, resolve and print.
5
+
6
+ An `.m3u8` file is either a **multivariant playlist**, listing the variant
7
+ streams of a presentation and their alternative audio, video and subtitle
8
+ renditions, or a **media playlist**, listing the segments of one rendition.
9
+ This package reads both into a typed model covering every tag of the format,
10
+ including low-latency HLS, delta updates, date ranges and content steering. It
11
+ then resolves them into what a downloader needs: absolute segment URLs with
12
+ their byte ranges and initialization sections, and variants joined to their
13
+ renditions. It performs no I/O, and never fetches a key, decrypts or derives an
14
+ initialization vector: keys are plain data.
15
+
16
+ ```ts
17
+ import {
18
+ parseHlsPlaylist,
19
+ resolveHlsSegments,
20
+ resolveHlsVariants,
21
+ } from "@ac-kit/format-hls";
22
+
23
+ const url = "https://cdn.example.test/show/index.m3u8";
24
+ const { playlist, warnings } = parseHlsPlaylist(
25
+ "#EXTM3U\n" +
26
+ '#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="English",URI="en.m3u8"\n' +
27
+ '#EXT-X-STREAM-INF:BANDWIDTH=1280000,CODECS="avc1.64001f,mp4a.40.2",AUDIO="aac"\n' +
28
+ "720p.m3u8\n",
29
+ { mode: "lenient", url },
30
+ );
31
+
32
+ if (playlist.kind === "multivariant") {
33
+ const { variants, sessionKeys } = resolveHlsVariants(playlist, url);
34
+ variants[0]?.href; // "https://cdn.example.test/show/720p.m3u8"
35
+ variants[0]?.audio[0]?.href; // "https://cdn.example.test/show/en.m3u8"
36
+ sessionKeys.length; // 0: nothing announced as encrypted
37
+ } else {
38
+ const { segments } = resolveHlsSegments(playlist, url);
39
+ segments[0]?.href;
40
+ }
41
+ warnings.length; // 0
42
+ ```
43
+
44
+ **Requires a `Temporal` global** for program dates (`parseHlsDateTime`, and the
45
+ `programDateTime` of a resolved segment). Node 26 ships one; elsewhere, load a
46
+ polyfill such as [`temporal-polyfill`](https://www.npmjs.com/package/temporal-polyfill)
47
+ before using those.
48
+
49
+ ## Strict and lenient
50
+
51
+ `parseHlsPlaylist` is strict by default: the first violation of the format
52
+ throws an `HlsSyntaxError` with a stable `code`, a line and a column. Pass
53
+ `mode: "lenient"` to recover from each instead, every one recorded in
54
+ `warnings`. Lenient mode tolerates what real servers write — a byte order mark,
55
+ blank lines before `#EXTM3U`, lone CR line ends, trailing whitespace in tag
56
+ names and around attribute separators, text not in Unicode NFC, lower-case hexadecimal, a missing
57
+ `EXT-X-TARGETDURATION` (derived from the segments) — and keeps every variant.
58
+
59
+ Some problems fail in both modes: a file with no `#EXTM3U` (plain M3U is
60
+ rejected), a playlist mixing media and multivariant tags, and every size limit
61
+ (`HlsLimitError`). An integer past 2^53−1 fails a strict parse; a lenient one
62
+ keeps the tag raw among `unknownTags`, except `EXT-X-KEY`, which is never set
63
+ aside so a segment under it never looks unencrypted. `EXT-X-VERSION` above 13
64
+ is an advisory in both modes. A key declaration with a quoted or missing
65
+ `METHOD`, or `METHOD=NONE` in a malformed list or alongside other attributes,
66
+ is a violation. Lenient mode reads its method as `""`, so it never clears the
67
+ keys in effect.
68
+
69
+ Section 6.3.1 tells a client to ignore a tag with an unknown `REQ-` attribute
70
+ or an unrecognized enumerated value. The parser keeps such variants and
71
+ renditions, with the attribute in `unknownAttributes`; `resolveHlsVariants`
72
+ flags them `supported: false` and drops them only with `skipUnsupported: true`.
73
+ An unrecognized `TYPE` yields `HlsRendition.type: null`. The rendition does
74
+ not join any typed group, but a reference to its `GROUP-ID` with no usable
75
+ match is reported as `unsupported`, not `absent`.
76
+
77
+ ## Limits
78
+
79
+ Every parse is bounded: `maxLength` (16 Mi characters by default),
80
+ `maxLineLength`, `maxLines`, `maxSegments`, `maxExpansion` (the characters
81
+ variable substitution may add) and `maxWarnings`. Parsing, printing and
82
+ resolving are linear and iterative; hostile input cannot overflow the stack.
83
+
84
+ ## Variables
85
+
86
+ `EXT-X-DEFINE` is applied as the format says: in URI lines, quoted values and
87
+ hexadecimal values, with names defined earlier only, and never twice. The same
88
+ holds for `X-` and unknown attributes of known tags (quoted values, and
89
+ unquoted ones starting with `0x`); unknown tags are kept raw. `IMPORT` reads
90
+ the `importedVariables` option — `hlsVariables(parent)` — and `QUERYPARAM` the
91
+ `url` option, percent-decoded only.
92
+
93
+ ## Live playlists
94
+
95
+ `isHlsPlaylistComplete` tells a live or event playlist from a finished one.
96
+ `applyHlsDeltaUpdate(previous, update)` merges a Playlist Delta Update
97
+ (`EXT-X-SKIP`) into the previous full version. It carries the skipped
98
+ segments with their tags, the state that slid out before them (keys in
99
+ effect, the last program date, the sub-range a byte range continues) and
100
+ every date-range declaration the update left out. Key declarations stay
101
+ declarations, so an update's `METHOD=NONE` clears as written. It throws
102
+ `incomplete-delta-update` when the previous version lacks something the update
103
+ relies on — the signal to reload without `_HLS_skip` — and
104
+ `inconsistent-delta-update` when date-range declarations disagree, program
105
+ dates are duplicated, or byte ranges at the splice or sequence numbers
106
+ overflow. Pass `playlistUrl` when different URI spellings may identify the
107
+ same resource at a byte-range splice.
108
+
109
+ ## Resolving
110
+
111
+ `resolveHlsSegments` gives each segment its absolute `href` (WHATWG `URL`,
112
+ against the playlist URL after redirects), Media Sequence and Discontinuity
113
+ Sequence Numbers, start time, byte range with every offset filled in (a range
114
+ continues the previous one when both resolve to the same URL),
115
+ initialization section, the keys in effect with an `encrypted` flag, and
116
+ program date, extrapolated from the last one. The model keeps keys as each
117
+ block's `keyTags` declarations, so it stays linear however many key formats
118
+ rotate; the view bounds the key entries it materialises
119
+ (`maxKeyScopeEntries`). `resolveHlsVariants` joins variants to their
120
+ rendition groups, says which referenced groups are absent or unsupported
121
+ (`unresolvedGroups`), lists the Content Steering `pathways` and filters on one
122
+ with `pathwayId`. An item that cannot be resolved — a bad URI, a URI holding a
123
+ TAB, a byte range past 2^53−1, an unreadable initialization range — gets
124
+ `href: null` and a diagnostic of its own in `warnings`; the rest of the list
125
+ is unaffected.
126
+
127
+ ## Printing
128
+
129
+ `printHlsPlaylist(playlist)` writes a model back in canonical order: numbers
130
+ as the shortest decimal (`-0` kept where a sign is allowed), key tags as
131
+ declared, `EXT-X-MAP` and `EXT-X-BITRATE` only where they change, and every
132
+ value as it was after substitution. For a model a parse produced, parsing the
133
+ output with the same options gives the same model — the same options because
134
+ `IMPORT` and `QUERYPARAM` read their values from them, and limits large enough
135
+ for the output, which holds substituted values and can be longer than the
136
+ source. A lenient parse ignores a definition that follows a reference to its
137
+ name, so a reference it left as written stays that way on the way back. For a
138
+ byte-exact copy, comments included, use the line layer:
139
+ `printHlsDocument(parseHlsDocument(source)) === source`.
140
+
141
+ `HlsParseStream` and `HlsPrintStream` wrap both for byte streams; decoding is
142
+ fatal in strict mode.
143
+
144
+ See the
145
+ [generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/format-hls/)
146
+ for the full reference.
@@ -0,0 +1,14 @@
1
+ import type { HlsDateRange } from "./model/hls-media-playlist.js";
2
+ /**
3
+ * The attributes one `EXT-X-DATERANGE` declares besides `ID`, as name and
4
+ * comparable text: what two declarations of one ID must agree on (§4.4.5.1).
5
+ * Absent attributes are left out; a later declaration may add them.
6
+ */
7
+ export declare function dateRangeFields(range: HlsDateRange): Map<string, string>;
8
+ /**
9
+ * Records `range` against the attributes already declared for its ID, and
10
+ * answers the first attribute it contradicts, or `null`. `known` maps each ID
11
+ * to its attributes so far. O(attributes).
12
+ */
13
+ export declare function mergeDateRangeFields(known: Map<string, Map<string, string>>, range: HlsDateRange): string | null;
14
+ //# sourceMappingURL=_date-range-fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_date-range-fields.d.ts","sourceRoot":"","sources":["../src/_date-range-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CA4BxE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACvC,KAAK,EAAE,YAAY,GACjB,MAAM,GAAG,IAAI,CAef"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The attributes one `EXT-X-DATERANGE` declares besides `ID`, as name and
3
+ * comparable text: what two declarations of one ID must agree on (§4.4.5.1).
4
+ * Absent attributes are left out; a later declaration may add them.
5
+ */
6
+ export function dateRangeFields(range) {
7
+ const fields = new Map();
8
+ const put = (name, value) => {
9
+ if (value !== null) {
10
+ fields.set(name, String(value));
11
+ }
12
+ };
13
+ put("CLASS", range.class);
14
+ put("START-DATE", range.startDate);
15
+ put("END-DATE", range.endDate);
16
+ put("DURATION", range.duration);
17
+ put("PLANNED-DURATION", range.plannedDuration);
18
+ put("SCTE35-CMD", range.scte35Cmd);
19
+ put("SCTE35-OUT", range.scte35Out);
20
+ put("SCTE35-IN", range.scte35In);
21
+ if (range.cue.length > 0) {
22
+ fields.set("CUE", range.cue.join(","));
23
+ }
24
+ if (range.endOnNext) {
25
+ fields.set("END-ON-NEXT", "YES");
26
+ }
27
+ for (const attribute of range.clientAttributes) {
28
+ fields.set(attribute.name, `${attribute.quoted ? "q" : "u"}${attribute.value}`);
29
+ }
30
+ return fields;
31
+ }
32
+ /**
33
+ * Records `range` against the attributes already declared for its ID, and
34
+ * answers the first attribute it contradicts, or `null`. `known` maps each ID
35
+ * to its attributes so far. O(attributes).
36
+ */
37
+ export function mergeDateRangeFields(known, range) {
38
+ const fields = dateRangeFields(range);
39
+ const previous = known.get(range.id);
40
+ if (previous === undefined) {
41
+ known.set(range.id, fields);
42
+ return null;
43
+ }
44
+ for (const [name, value] of fields) {
45
+ const earlier = previous.get(name);
46
+ if (earlier !== undefined && earlier !== value) {
47
+ return name;
48
+ }
49
+ previous.set(name, value);
50
+ }
51
+ return null;
52
+ }
53
+ //# sourceMappingURL=_date-range-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_date-range-fields.js","sourceRoot":"","sources":["../src/_date-range-fields.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAmB;IAClD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,KAA6B,EAAQ,EAAE;QACjE,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACpB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC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AAQ,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC5B,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;YAChD,OAAO,IAAI,CAAC;QACb,CAAC;QACD,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { HlsKey } from "./model/hls-key.js";
2
+ /**
3
+ * The keys in effect after `key` is declared (§4.4.4.4): `METHOD=NONE` clears
4
+ * every key, any other method replaces the key of the same `KEYFORMAT` or is
5
+ * added after the others. Never mutates `keys`. O(keys).
6
+ */
7
+ export declare function applyKeyTag(keys: readonly HlsKey[], key: HlsKey): readonly HlsKey[];
8
+ //# sourceMappingURL=_key-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_key-scope.d.ts","sourceRoot":"","sources":["../src/_key-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;GAIG;AACH,wBAAgB,WAAW,CAC1B,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,GAAG,EAAE,MAAM,GACT,SAAS,MAAM,EAAE,CASnB"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The keys in effect after `key` is declared (§4.4.4.4): `METHOD=NONE` clears
3
+ * every key, any other method replaces the key of the same `KEYFORMAT` or is
4
+ * added after the others. Never mutates `keys`. O(keys).
5
+ */
6
+ export function applyKeyTag(keys, key) {
7
+ if (key.method === "NONE") {
8
+ return keys.length === 0 ? keys : [];
9
+ }
10
+ const format = key.keyFormat ?? "identity";
11
+ const index = keys.findIndex((existing) => (existing.keyFormat ?? "identity") === format);
12
+ return index === -1 ? [...keys, key] : keys.with(index, key);
13
+ }
14
+ //# sourceMappingURL=_key-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_key-scope.js","sourceRoot":"","sources":["../src/_key-scope.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAC1B,IAAuB,EACvB,GAAW;IAEX,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACtC,CAAC;IACD,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,IAAI,UAAU,CAAC;IAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAC3B,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,IAAI,UAAU,CAAC,KAAK,MAAM,CAC3D,CAAC;IACF,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** `instant` plus `seconds`, or `null` past what an instant can hold. */
2
+ export declare function addSeconds(instant: Temporal.Instant, seconds: number): Temporal.Instant | null;
3
+ //# sourceMappingURL=_temporal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_temporal.d.ts","sourceRoot":"","sources":["../src/_temporal.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,wBAAgB,UAAU,CACzB,OAAO,EAAE,QAAQ,CAAC,OAAO,EACzB,OAAO,EAAE,MAAM,GACb,QAAQ,CAAC,OAAO,GAAG,IAAI,CAUzB"}
@@ -0,0 +1,14 @@
1
+ /** `instant` plus `seconds`, or `null` past what an instant can hold. */
2
+ export function addSeconds(instant, seconds) {
3
+ const nanoseconds = Math.round(seconds * 1e9);
4
+ if (!Number.isSafeInteger(nanoseconds)) {
5
+ return null;
6
+ }
7
+ try {
8
+ return instant.add({ nanoseconds });
9
+ }
10
+ catch {
11
+ return null;
12
+ }
13
+ }
14
+ //# sourceMappingURL=_temporal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_temporal.js","sourceRoot":"","sources":["../src/_temporal.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,UAAU,UAAU,CACzB,OAAyB,EACzB,OAAe;IAEf,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,OAAO,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { HlsAttribute } from "./hls-attribute.js";
2
+ /** One pair of `printHlsAttributeList`, with the same checks. */
3
+ export declare function printAttribute(attribute: HlsAttribute): string;
4
+ /**
5
+ * Throws unless `value` can be written as a quoted-string.
6
+ *
7
+ * @throws {HlsPlaylistError} `unprintable-value` for `"`, CR or LF.
8
+ */
9
+ export declare function assertQuotable(value: string, name: string): void;
10
+ //# sourceMappingURL=_print-attribute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_print-attribute.d.ts","sourceRoot":"","sources":["../../src/attribute/_print-attribute.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,iEAAiE;AACjE,wBAAgB,cAAc,CAAC,SAAS,EAAE,YAAY,GAAG,MAAM,CAmB9D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAUhE"}
@@ -0,0 +1,31 @@
1
+ import { CR, DOUBLE_QUOTE, LF } from "@ac-kit/core";
2
+ import { HlsPlaylistError } from "../errors.js";
3
+ /** One pair of `printHlsAttributeList`, with the same checks. */
4
+ export function printAttribute(attribute) {
5
+ const { name, value, quoted } = attribute;
6
+ if (name.length === 0 || /[\s=,"]/u.test(name)) {
7
+ throw new HlsPlaylistError("unprintable-value", `Cannot print attribute name "${name}"`);
8
+ }
9
+ if (quoted) {
10
+ assertQuotable(value, name);
11
+ return `${name}="${value}"`;
12
+ }
13
+ if (/[,"\r\n]/u.test(value)) {
14
+ throw new HlsPlaylistError("unprintable-value", `Cannot print unquoted value of "${name}"`);
15
+ }
16
+ return `${name}=${value}`;
17
+ }
18
+ /**
19
+ * Throws unless `value` can be written as a quoted-string.
20
+ *
21
+ * @throws {HlsPlaylistError} `unprintable-value` for `"`, CR or LF.
22
+ */
23
+ export function assertQuotable(value, name) {
24
+ for (let index = 0; index < value.length; index++) {
25
+ const code = value.charCodeAt(index);
26
+ if (code === DOUBLE_QUOTE || code === CR || code === LF) {
27
+ throw new HlsPlaylistError("unprintable-value", `Quoted value of "${name}" holds a double quote, CR or LF`);
28
+ }
29
+ }
30
+ }
31
+ //# sourceMappingURL=_print-attribute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_print-attribute.js","sourceRoot":"","sources":["../../src/attribute/_print-attribute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EA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Receives a problem at a 0-based offset into the scanned text. */
4
+ export type AttributeListReport = (code: HlsDiagnosticCode, offset: number, message: string) => void;
5
+ /** An attribute and the 0-based offset of its name in the scanned text. */
6
+ export type ScannedAttribute = HlsAttribute & {
7
+ readonly offset: number;
8
+ };
9
+ /**
10
+ * Scans an attribute-list (§4.2) in source order, in one pass.
11
+ *
12
+ * Strict mode reports whitespace, names outside `[A-Z0-9-]`, empty unquoted
13
+ * values, unterminated quotes, CR or LF in a value, trailing commas and
14
+ * duplicate names. Lenient mode reports the same through `report` but recovers:
15
+ * whitespace around `,` and `=` is skipped, an unterminated quote runs to the
16
+ * end, a pair with no `=` is dropped, and the first of two duplicates wins.
17
+ *
18
+ * `report` throws to stop a strict scan; in lenient mode it returns and the
19
+ * scan goes on. O(text length).
20
+ */
21
+ export declare function scanAttributeList(text: string, lenient: boolean, report: AttributeListReport): ScannedAttribute[];
22
+ /** Whether `name` is an AttributeName: one or more of `[A-Z0-9-]`. */
23
+ export declare function isAttributeName(name: string): boolean;
24
+ //# sourceMappingURL=_scan-attribute-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_scan-attribute-list.d.ts","sourceRoot":"","sources":["../../src/attribute/_scan-attribute-list.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,oEAAoE;AACpE,MAAM,MAAM,mBAAmB,GAAG,CACjC,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,KACX,IAAI,CAAC;AAEV,2EAA2E;AAC3E,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAI1E;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,mBAAmB,GACzB,gBAAgB,EAAE,CA+IpB;AAED,sEAAsE;AACtE,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAWrD"}
@@ -0,0 +1,147 @@
1
+ import { COMMA, CR, LF, DOUBLE_QUOTE, EQUALS, isAsciiBlank, isAsciiDigit, isAsciiUpperAlpha, } from "@ac-kit/core";
2
+ const HYPHEN_ = 0x2d;
3
+ /**
4
+ * Scans an attribute-list (§4.2) in source order, in one pass.
5
+ *
6
+ * Strict mode reports whitespace, names outside `[A-Z0-9-]`, empty unquoted
7
+ * values, unterminated quotes, CR or LF in a value, trailing commas and
8
+ * duplicate names. Lenient mode reports the same through `report` but recovers:
9
+ * whitespace around `,` and `=` is skipped, an unterminated quote runs to the
10
+ * end, a pair with no `=` is dropped, and the first of two duplicates wins.
11
+ *
12
+ * `report` throws to stop a strict scan; in lenient mode it returns and the
13
+ * scan goes on. O(text length).
14
+ */
15
+ export function scanAttributeList(text, lenient, report) {
16
+ const attributes = [];
17
+ const seen = new Set();
18
+ let position = 0;
19
+ const skip = (from) => {
20
+ const to = skipBlanks_(text, from);
21
+ if (to !== from) {
22
+ report("invalid-attribute-list", from, "Whitespace in an attribute list");
23
+ }
24
+ return to;
25
+ };
26
+ while (position <= text.length) {
27
+ if (lenient) {
28
+ position = skip(position);
29
+ }
30
+ if (position >= text.length) {
31
+ if (attributes.length > 0 || text.length > 0) {
32
+ report("invalid-attribute-list", position, "Attribute list is empty or ends with a comma");
33
+ }
34
+ break;
35
+ }
36
+ const nameStart = position;
37
+ while (position < text.length &&
38
+ text.charCodeAt(position) !== EQUALS &&
39
+ text.charCodeAt(position) !== COMMA) {
40
+ position++;
41
+ }
42
+ const rawName = text.slice(nameStart, position);
43
+ const name = lenient ? rawName.trimEnd() : rawName;
44
+ if (name !== rawName) {
45
+ report("invalid-attribute-list", nameStart + name.length, "Whitespace in an attribute list");
46
+ }
47
+ if (text.charCodeAt(position) !== EQUALS) {
48
+ report("invalid-attribute-list", nameStart, `Attribute "${rawName}" has no value`);
49
+ position++;
50
+ continue;
51
+ }
52
+ if (!isAttributeName(name)) {
53
+ report("invalid-attribute-list", nameStart, `Invalid attribute name "${rawName}"`);
54
+ }
55
+ position++;
56
+ if (lenient) {
57
+ position = skip(position);
58
+ }
59
+ let value;
60
+ let quoted = false;
61
+ if (text.charCodeAt(position) === DOUBLE_QUOTE) {
62
+ quoted = true;
63
+ const close = text.indexOf('"', position + 1);
64
+ if (close === -1) {
65
+ report("invalid-attribute-list", position, `Unterminated quoted value for "${name}"`);
66
+ value = text.slice(position + 1);
67
+ position = text.length;
68
+ }
69
+ else {
70
+ value = text.slice(position + 1, close);
71
+ position = close + 1;
72
+ }
73
+ if (/[\r\n]/u.test(value)) {
74
+ report("invalid-attribute-list", nameStart, `Quoted value of "${name}" holds CR or LF`);
75
+ }
76
+ if (lenient) {
77
+ position = skip(position);
78
+ }
79
+ if (position < text.length && text.charCodeAt(position) !== COMMA) {
80
+ report("invalid-attribute-list", position, `Unexpected text after the quoted value of "${name}"`);
81
+ const comma = text.indexOf(",", position);
82
+ position = comma === -1 ? text.length : comma;
83
+ }
84
+ }
85
+ else {
86
+ const valueStart = position;
87
+ const comma = text.indexOf(",", position);
88
+ position = comma === -1 ? text.length : comma;
89
+ const rawValue = text.slice(valueStart, position);
90
+ value = lenient ? rawValue.trimEnd() : rawValue;
91
+ if (value !== rawValue) {
92
+ report("invalid-attribute-list", valueStart + value.length, "Whitespace in an attribute list");
93
+ }
94
+ if (!isUnquotedValue_(value)) {
95
+ report("invalid-attribute-list", valueStart, `Invalid unquoted value for "${name}"`);
96
+ }
97
+ }
98
+ if (seen.has(name)) {
99
+ report("duplicate-attribute", nameStart, `Attribute "${name}" appears more than once`);
100
+ }
101
+ else if (name.length > 0) {
102
+ seen.add(name);
103
+ attributes.push({ name, value, quoted, offset: nameStart });
104
+ }
105
+ if (position >= text.length) {
106
+ break;
107
+ }
108
+ position++;
109
+ }
110
+ return attributes;
111
+ }
112
+ /** Whether `name` is an AttributeName: one or more of `[A-Z0-9-]`. */
113
+ export function isAttributeName(name) {
114
+ if (name.length === 0) {
115
+ return false;
116
+ }
117
+ for (let index = 0; index < name.length; index++) {
118
+ const code = name.charCodeAt(index);
119
+ if (!isAsciiUpperAlpha(code) && !isAsciiDigit(code) && code !== HYPHEN_) {
120
+ return false;
121
+ }
122
+ }
123
+ return true;
124
+ }
125
+ function isUnquotedValue_(value) {
126
+ if (value.length === 0) {
127
+ return false;
128
+ }
129
+ for (let index = 0; index < value.length; index++) {
130
+ const code = value.charCodeAt(index);
131
+ if (isAsciiBlank(code) ||
132
+ code === DOUBLE_QUOTE ||
133
+ code === CR ||
134
+ code === LF) {
135
+ return false;
136
+ }
137
+ }
138
+ return true;
139
+ }
140
+ function skipBlanks_(text, position) {
141
+ let index = position;
142
+ while (index < text.length && isAsciiBlank(text.charCodeAt(index))) {
143
+ index++;
144
+ }
145
+ return index;
146
+ }
147
+ //# sourceMappingURL=_scan-attribute-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_scan-attribute-list.js","sourceRoot":"","sources":["../../src/attribute/_scan-attribute-list.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,EACL,EAAE,EACF,EAAE,EACF,YAAY,EACZ,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,iBAAiB,GACjB,MAAM,cAAc,CAAC;AAetB,MAAM,OAAO,GAAG,IAAI,CAAC;AAErB;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAChC,IAAY,EACZ,OAAgB,EAChB,MAA2B;IAE3B,MAAM,UAAU,GAAuB,EAAE,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,IAAI,QAAQ,GAAG,CAAC,CAAC;IAEjB,MAAM,IAAI,GAAG,CAAC,IAAY,EAAU,EAAE;QACrC,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI,C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