@ac-kit/format-dash 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 (92) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/LICENSE +28 -0
  3. package/README.md +180 -2
  4. package/dist/_template.d.ts +34 -0
  5. package/dist/_template.d.ts.map +1 -0
  6. package/dist/_template.js +90 -0
  7. package/dist/_template.js.map +1 -0
  8. package/dist/_xlink.d.ts +9 -0
  9. package/dist/_xlink.d.ts.map +1 -0
  10. package/dist/_xlink.js +14 -0
  11. package/dist/_xlink.js.map +1 -0
  12. package/dist/dash-namespaces.d.ts +27 -0
  13. package/dist/dash-namespaces.d.ts.map +1 -0
  14. package/dist/dash-namespaces.js +30 -0
  15. package/dist/dash-namespaces.js.map +1 -0
  16. package/dist/errors.d.ts +127 -0
  17. package/dist/errors.d.ts.map +1 -0
  18. package/dist/errors.js +52 -0
  19. package/dist/errors.js.map +1 -0
  20. package/dist/index.d.ts +12 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +12 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/limits.d.ts +51 -0
  25. package/dist/limits.d.ts.map +1 -0
  26. package/dist/limits.js +39 -0
  27. package/dist/limits.js.map +1 -0
  28. package/dist/model/dash-common.d.ts +124 -0
  29. package/dist/model/dash-common.d.ts.map +1 -0
  30. package/dist/model/dash-common.js +2 -0
  31. package/dist/model/dash-common.js.map +1 -0
  32. package/dist/model/dash-mpd.d.ts +111 -0
  33. package/dist/model/dash-mpd.d.ts.map +1 -0
  34. package/dist/model/dash-mpd.js +2 -0
  35. package/dist/model/dash-mpd.js.map +1 -0
  36. package/dist/model/dash-segment-information.d.ts +90 -0
  37. package/dist/model/dash-segment-information.d.ts.map +1 -0
  38. package/dist/model/dash-segment-information.js +2 -0
  39. package/dist/model/dash-segment-information.js.map +1 -0
  40. package/dist/parse/_attribute-reader.d.ts +94 -0
  41. package/dist/parse/_attribute-reader.d.ts.map +1 -0
  42. package/dist/parse/_attribute-reader.js +382 -0
  43. package/dist/parse/_attribute-reader.js.map +1 -0
  44. package/dist/parse/_context.d.ts +35 -0
  45. package/dist/parse/_context.d.ts.map +1 -0
  46. package/dist/parse/_context.js +39 -0
  47. package/dist/parse/_context.js.map +1 -0
  48. package/dist/parse/_xs-temporal.d.ts +22 -0
  49. package/dist/parse/_xs-temporal.d.ts.map +1 -0
  50. package/dist/parse/_xs-temporal.js +98 -0
  51. package/dist/parse/_xs-temporal.js.map +1 -0
  52. package/dist/parse/parse-dash-mpd.d.ts +67 -0
  53. package/dist/parse/parse-dash-mpd.d.ts.map +1 -0
  54. package/dist/parse/parse-dash-mpd.js +928 -0
  55. package/dist/parse/parse-dash-mpd.js.map +1 -0
  56. package/dist/resolve/_base-url.d.ts +41 -0
  57. package/dist/resolve/_base-url.d.ts.map +1 -0
  58. package/dist/resolve/_base-url.js +69 -0
  59. package/dist/resolve/_base-url.js.map +1 -0
  60. package/dist/resolve/_essential-properties.d.ts +38 -0
  61. package/dist/resolve/_essential-properties.d.ts.map +1 -0
  62. package/dist/resolve/_essential-properties.js +106 -0
  63. package/dist/resolve/_essential-properties.js.map +1 -0
  64. package/dist/resolve/_inherit.d.ts +43 -0
  65. package/dist/resolve/_inherit.d.ts.map +1 -0
  66. package/dist/resolve/_inherit.js +105 -0
  67. package/dist/resolve/_inherit.js.map +1 -0
  68. package/dist/resolve/_segment-runs.d.ts +81 -0
  69. package/dist/resolve/_segment-runs.d.ts.map +1 -0
  70. package/dist/resolve/_segment-runs.js +126 -0
  71. package/dist/resolve/_segment-runs.js.map +1 -0
  72. package/dist/resolve/dash-resolve-diagnostic.d.ts +34 -0
  73. package/dist/resolve/dash-resolve-diagnostic.d.ts.map +1 -0
  74. package/dist/resolve/dash-resolve-diagnostic.js +2 -0
  75. package/dist/resolve/dash-resolve-diagnostic.js.map +1 -0
  76. package/dist/resolve/resolve-dash-representations.d.ts +130 -0
  77. package/dist/resolve/resolve-dash-representations.d.ts.map +1 -0
  78. package/dist/resolve/resolve-dash-representations.js +203 -0
  79. package/dist/resolve/resolve-dash-representations.js.map +1 -0
  80. package/dist/resolve/resolve-dash-segments.d.ts +169 -0
  81. package/dist/resolve/resolve-dash-segments.d.ts.map +1 -0
  82. package/dist/resolve/resolve-dash-segments.js +665 -0
  83. package/dist/resolve/resolve-dash-segments.js.map +1 -0
  84. package/dist/timing/_exact-period-timings.d.ts +28 -0
  85. package/dist/timing/_exact-period-timings.d.ts.map +1 -0
  86. package/dist/timing/_exact-period-timings.js +142 -0
  87. package/dist/timing/_exact-period-timings.js.map +1 -0
  88. package/dist/timing/dash-period-timings.d.ts +29 -0
  89. package/dist/timing/dash-period-timings.d.ts.map +1 -0
  90. package/dist/timing/dash-period-timings.js +23 -0
  91. package/dist/timing/dash-period-timings.js.map +1 -0
  92. package/package.json +63 -3
package/CHANGELOG.md ADDED
@@ -0,0 +1,89 @@
1
+ # @ac-kit/format-dash
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [065cf8d]
8
+ - Updated dependencies [065cf8d]
9
+ - Updated dependencies [065cf8d]
10
+ - @ac-kit/core@0.11.0
11
+ - @ac-kit/format-xml@0.2.1
12
+ - @ac-kit/model-markup@0.1.1
13
+
14
+ ## 0.1.0
15
+
16
+ ### Minor Changes
17
+
18
+ - 5152230: New package: MPEG-DASH manifests (ISO/IEC 23009-1, 5th edition schema).
19
+
20
+ - `parseDashMpd(source, options)` reads an MPD — string, bytes or a parsed
21
+ `@ac-kit/format-xml` document — into an as-written typed model (MPD, Period,
22
+ AdaptationSet, Representation, descriptors, ContentProtection at every
23
+ scope, BaseURL, SegmentBase, SegmentList, SegmentTemplate, SegmentTimeline),
24
+ keeping everything else in `otherAttributes`/`otherElements`. Elements match
25
+ by namespace (no namespace only for unprefixed names); an MPD in no
26
+ namespace or the legacy upper-case one is read with an advisory. Strict by
27
+ default (`DashSyntaxError` with a `code` and `position`; `MPD@profiles`,
28
+ `MPD@minBufferTime` and a Period required; XML Schema integer ranges
29
+ enforced); `mode: "lenient"` turns each unreadable typed attribute into
30
+ `null`, keeps it in `invalidAttributes` and reports it in `warnings`.
31
+ Durations and date-times are `Temporal` values after an XSD lexical check.
32
+ Limits `maxLength` (4 Mi), `maxTimelineEntries` (100 000), `maxWarnings`,
33
+ and a `budget` (a shareable `WorkBudget`, or a private limit of 500 000
34
+ units) covering XML parsing, namespace resolution and MPD construction.
35
+ A private budget raises `DashLimitError`; `tryParseDashMpd` answers `null`
36
+ for parse syntax errors but rethrows caller budget errors by identity, even
37
+ if the budget throws a syntax error.
38
+ - `resolveDashRepresentations(mpd, mpdUrl, options)` lists every
39
+ Representation with AdaptationSet values applied and its BaseURL `href`;
40
+ descriptors are given by scope, shared, never copied; `isProtected`,
41
+ `referencedContentProtections` and `ignoredBecause` (unknown
42
+ EssentialProperty at any scope, unreadable `@id`/`@bandwidth`) are flags,
43
+ never acted on. Remote (xlink) Periods and AdaptationSets list nothing;
44
+ `resolve-to-zero` ones are absent.
45
+ - `resolveDashSegments(mpd, mpdUrl, path, options)` lists one
46
+ Representation's initialization, index and media segments for every
47
+ addressing mode, following the DASH-IF timing model (`@presentationTimeOffset`
48
+ and `@eptDelta` in simple addressing, negative `S@r` bounded by the next `S@t`,
49
+ the Period end, `@endNumber`, the SegmentURL count or `now`), with exact
50
+ bigint `time`/`duration`, per-segment `index` and `diagnostic`, a lazy
51
+ re-iterable `segments` with a known `count`, `from`/`to` within the Period,
52
+ `maxSegments`, `budget`, and live (dynamic) availability windows from a
53
+ caller-supplied `now`. Span comparisons handle subnanosecond bounds exactly,
54
+ and explicit absolute resources resolve even after an invalid BaseURL.
55
+ Unreadable ranges on selected SegmentURLs never become whole-resource
56
+ requests. Errors are `DashResolveError`s with a `code`
57
+ (`unreadable-value` when a lenient parse lost a value the plan needs,
58
+ `invalid-availability` instead of a native `RangeError`); unresolved xlink,
59
+ `$SubNumber$`, `S@k` and `BaseURL@byteRange` are `UnsupportedError`s.
60
+ - `dashPeriodTimings(mpd)` gives each Period's start and duration.
61
+
62
+ ContentProtection, PSSH and license URLs are plain text only. URL policy
63
+ (which schemes and hosts to fetch) is the caller's. Requires a `Temporal`
64
+ global (Node 26, or a polyfill such as `temporal-polyfill`).
65
+
66
+ ### Patch Changes
67
+
68
+ - Updated dependencies [2a0fe74]
69
+ - Updated dependencies [5152230]
70
+ - Updated dependencies [2a0fe74]
71
+ - Updated dependencies [5152230]
72
+ - Updated dependencies [5152230]
73
+ - Updated dependencies [2a0fe74]
74
+ - Updated dependencies [2a0fe74]
75
+ - Updated dependencies [5152230]
76
+ - Updated dependencies [5152230]
77
+ - Updated dependencies [5152230]
78
+ - Updated dependencies [5152230]
79
+ - Updated dependencies [5152230]
80
+ - Updated dependencies [5152230]
81
+ - Updated dependencies [5152230]
82
+ - Updated dependencies [5152230]
83
+ - Updated dependencies [5152230]
84
+ - Updated dependencies [5152230]
85
+ - Updated dependencies [5152230]
86
+ - Updated dependencies [5152230]
87
+ - @ac-kit/core@0.10.0
88
+ - @ac-kit/format-xml@0.2.0
89
+ - @ac-kit/model-markup@0.1.0
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,181 @@
1
- # Temporary Holding Version
1
+ # @ac-kit/format-dash
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
+ MPEG-DASH manifests (ISO/IEC 23009-1, 5th edition schema): parse an MPD and
4
+ list its Representations and their segments.
5
+
6
+ An MPD describes a presentation as Periods of AdaptationSets of
7
+ Representations — one encoding each — and says where each Representation's
8
+ segments are with one of four addressing modes: a SegmentTemplate with
9
+ `@duration`, a SegmentTemplate with a SegmentTimeline, a SegmentList, or a
10
+ single file (SegmentBase, or a BaseURL alone). This package reads the whole
11
+ document into a typed model, values as written, then resolves what a
12
+ downloader needs: every Representation as a flat table, and each one's
13
+ initialization segment, index and media segments as absolute URLs with byte
14
+ ranges — for static and live (dynamic) MPDs alike. It performs no I/O and has
15
+ no clock: the caller fetches, and passes the time.
16
+
17
+ ```ts
18
+ import {
19
+ parseDashMpd,
20
+ resolveDashRepresentations,
21
+ resolveDashSegments,
22
+ } from "@ac-kit/format-dash";
23
+
24
+ const url = "https://cdn.example.test/show/manifest.mpd";
25
+ const { mpd, warnings } = parseDashMpd(
26
+ `<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" type="static" mediaPresentationDuration="PT8S"
27
+ profiles="urn:mpeg:dash:profile:isoff-live:2011" minBufferTime="PT2S">
28
+ <Period>
29
+ <AdaptationSet mimeType="video/mp4" codecs="avc1.64001f">
30
+ <SegmentTemplate timescale="1000" duration="4000"
31
+ media="$RepresentationID$/$Number%05d$.m4s" initialization="$RepresentationID$/init.mp4"/>
32
+ <Representation id="720p" bandwidth="2000000" width="1280" height="720"/>
33
+ </AdaptationSet>
34
+ </Period>
35
+ </MPD>`,
36
+ { mode: "lenient" },
37
+ );
38
+
39
+ const { representations } = resolveDashRepresentations(mpd, url);
40
+ const video = representations[0]!;
41
+ video.contentType; // "video"
42
+ video.isProtected; // false
43
+
44
+ const plan = resolveDashSegments(mpd, url, video.path);
45
+ plan.initialization?.href; // "https://cdn.example.test/show/720p/init.mp4"
46
+ plan.segments.count; // 2
47
+ for (const segment of plan.segments) {
48
+ segment.href; // "https://cdn.example.test/show/720p/00001.m4s", then 00002
49
+ }
50
+ warnings.length; // 0
51
+ ```
52
+
53
+ **Requires a `Temporal` global.** Durations are `Temporal.Duration`s and
54
+ date-times `Temporal.Instant`s, and `now` is a `Temporal.Instant`. Node 26
55
+ ships one; elsewhere, load a polyfill such as
56
+ [`temporal-polyfill`](https://www.npmjs.com/package/temporal-polyfill) first.
57
+
58
+ ## Strict and lenient
59
+
60
+ `parseDashMpd` takes a string, bytes (decoded as XML says) or an already
61
+ parsed `@ac-kit/format-xml` document. It is strict by default: the first
62
+ violation throws a `DashSyntaxError` with a stable `code` and the source
63
+ `position`. `mode: "lenient"` recovers from each instead and records it in
64
+ `warnings`: a typed attribute that does not read as its type — a number out
65
+ of its XML Schema range, a malformed duration or date-time, a template with an
66
+ unknown identifier — becomes `null`, and the attribute moves to
67
+ `invalidAttributes`. Strict mode also requires `MPD@profiles`,
68
+ `MPD@minBufferTime` and a Period. A document that is not well-formed XML
69
+ (`XmlSyntaxError`), or whose root is not an MPD, fails in both modes.
70
+
71
+ Elements match by namespace URI, whatever their prefix; no namespace matches
72
+ only an unprefixed name, so a lenient parse never reads an unbound `p:Period`
73
+ as a Period. An MPD in no namespace
74
+ or in the first edition's `urn:mpeg:DASH:schema:MPD:2011` is read like one in
75
+ `urn:mpeg:dash:schema:mpd:2011`, with an advisory. Lexical forms follow XML
76
+ Schema: `xs:duration` without weeks, fractional hours or a negative sign, and
77
+ with no years or months, which have no fixed length; an `xs:dateTime` with no
78
+ zone is taken as UTC. Everything the model does not type is kept in
79
+ `otherAttributes` and `otherElements` — EventStream, ServiceDescription,
80
+ Preselection, SubRepresentation, vendor extensions.
81
+
82
+ ## Segments
83
+
84
+ `resolveDashSegments(mpd, mpdUrl, path, options)` applies segment-information
85
+ inheritance attribute by attribute (Period → AdaptationSet → Representation),
86
+ resolves BaseURLs level by level against `mpdUrl` — the URL after redirects —
87
+ and substitutes `$RepresentationID$`, `$Number$`, `$Time$`, `$Bandwidth$` and
88
+ `$$`, with a `%0<width>d` width of at most 64; SegmentURLs come from the
89
+ nearest SegmentList that has some. Segment counts and window bounds
90
+ come from exact integer division, so `S@r="4611686018427387904"` costs what
91
+ `S@r="0"` does; `segments` is lazy, re-iterable, and knows its `count` before
92
+ iterating. `from`/`to` select the segments overlapping a span of seconds,
93
+ always within the Period; an empty or reversed span selects nothing. Bounds
94
+ are compared exactly against the supplied JavaScript numbers, without rounding
95
+ to whole nanoseconds. Each segment carries its own `index` — SegmentURL `@index`/`@indexRange`, a
96
+ per-segment SegmentTemplate `@index`, or the `@indexRange` of the segment
97
+ information — and a `diagnostic` when its URL does not resolve against a base.
98
+ Explicit absolute resource URLs still resolve if a malformed BaseURL breaks
99
+ its chain; the BaseURL diagnostic remains.
100
+
101
+ `number` is a `number` (a segment past 2^53−1 is refused), but `time` and
102
+ `duration` are `bigint`s in `timescale` units, unlike `@ac-kit/format-hls`'s
103
+ plain numbers: a `$Time$` counted from 1970 at a 10 MHz timescale is about
104
+ 1.7×10¹⁶, past 2^53. Times follow the DASH-IF timing model: with `@duration`
105
+ ("simple") addressing, segment `k` starts `@eptDelta + k × @duration` after the
106
+ Period start and its `$Time$` is `@presentationTimeOffset + k × @duration`;
107
+ with a SegmentTimeline, `$Time$` is `S@t` and the start `S@t −
108
+ @presentationTimeOffset`. A negative `S@r` repeats up to the next `S@t`, which
109
+ must be written, or on the last `S` up to the Period end, `@endNumber`, the
110
+ SegmentURL count or, live, the last available segment.
111
+
112
+ A description that cannot be listed throws a `DashResolveError` with a `code`:
113
+ a SegmentTemplate `@duration` or a single segment with no known Period end in
114
+ a static MPD, a negative `S@r` with nothing to stop it, a SegmentList whose
115
+ timeline and SegmentURLs disagree on the count, or a value a lenient parse
116
+ could not read (`unreadable-value`: the parse keeps such attributes in
117
+ `invalidAttributes` rather than let a default stand in for them). This includes
118
+ unreadable byte ranges on selected SegmentURLs; they never become whole-resource
119
+ requests. Only Period timing attributes needed to derive the selected Period's
120
+ timing are checked.
121
+ `$SubNumber$`, `S@k` and `BaseURL@byteRange` throw `UnsupportedError`, and so
122
+ does a remote (xlink) Period, AdaptationSet or SegmentList: its inline content
123
+ is a placeholder, never listed. `resolve-to-zero` makes an element absent.
124
+
125
+ ## Live MPDs
126
+
127
+ For a dynamic MPD pass `now`; nothing reads a clock. The segments listed are
128
+ those available at `now`, as DASH-IF IOP 4.3 §4.3.2.2.7 defines it: a segment
129
+ becomes available at `availabilityStartTime` + Period start + its end −
130
+ `availabilityTimeOffset` (the segment information's and every chosen
131
+ BaseURL's, summed; `INF` makes every announced segment available), and stays
132
+ so for `timeShiftBufferDepth` plus its duration. `S@r="-1"` on the last entry
133
+ of an open Period repeats up to the last available segment. Each segment
134
+ carries its `availabilityStart` and `availabilityEnd`, so a caller can tell
135
+ when to reload. An early-available Period (no start yet) cannot be listed.
136
+
137
+ ## Protection, unusable Representations and URLs
138
+
139
+ ContentProtection descriptors, `cenc:default_KID`, `cenc:pssh` and DASH-IF
140
+ `Laurl` license URLs are read as plain text and never used: nothing here
141
+ acquires a license, fetches a key or decrypts. `resolveDashRepresentations`
142
+ only flags: `isProtected` when a ContentProtection applies at any scope (MPD,
143
+ Period, AdaptationSet, Representation; `@ref` targets are listed in
144
+ `referencedContentProtections`), and
145
+ `ignoredBecause` for a Representation under an EssentialProperty whose scheme
146
+ the caller did not list in `understoodEssentialProperties`, at any scope (the
147
+ standard tells
148
+ a client to ignore those), or one a lenient parse left without `@id` or
149
+ `@bandwidth`. `skipIgnored: true` leaves the latter out. Descriptor lists are
150
+ given by scope and shared between Representations, never copied.
151
+
152
+ **URL policy belongs to the caller.** Every `href` is whatever the MPD's
153
+ BaseURLs and templates resolve to with the WHATWG `URL` parser, `file:`,
154
+ `data:` and private hosts included; check the scheme and host before fetching.
155
+ An `href` that does not resolve is `null`, with a diagnostic in `warnings`.
156
+
157
+ ## Limits
158
+
159
+ Parsing is bounded by `maxLength` (4 Mi characters by default, bytes at three
160
+ times that),
161
+ `maxTimelineEntries` (100 000 `<S>` elements) and `maxWarnings`, on top of
162
+ `@ac-kit/format-xml`'s entity-expansion and nesting limits; listing by
163
+ `maxSegments` (100 000 per call). Every call also takes a `budget`: a
164
+ `WorkBudget` from `@ac-kit/core` shared across calls — one per page, say —
165
+ whose own error propagates, or a limit for a private one, 500 000 units by
166
+ default. Parsing uses one allowance for XML parsing, namespace resolution,
167
+ and MPD model construction. A dense MPD can exhaust the budget before it hits
168
+ `maxLength` or `maxTimelineEntries`. Exceeding a DASH limit or a private budget
169
+ throws `DashLimitError` in every mode —
170
+ for `maxSegments` it carries the exact `count`, so the caller can narrow
171
+ `from`/`to`. Only the significant digits of an integer reach `BigInt`, and an
172
+ `xs:unsignedInt` or `xs:unsignedLong` past its range is refused; recursion
173
+ follows the schema's fixed depth and sibling lists are appended one by one, so
174
+ hostile input cannot overflow the stack.
175
+
176
+ Not in scope: printing an MPD, resolving xlink, MPD patches, subsegments from
177
+ `sidx` boxes, and anything to do with DRM.
178
+
179
+ See the
180
+ [generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/format-dash/)
181
+ for the full reference.
@@ -0,0 +1,34 @@
1
+ /** A template identifier (§5.3.9.4.4, Table 16). */
2
+ export type TemplateIdentifier = "RepresentationID" | "Number" | "Bandwidth" | "Time" | "SubNumber";
3
+ /** A literal run, or an identifier with its `%0<width>d` width (0 for none). */
4
+ export type TemplatePart = string | {
5
+ readonly identifier: TemplateIdentifier;
6
+ readonly width: number;
7
+ };
8
+ /**
9
+ * Splits a template into literal runs and identifiers, `$$` becoming a `$`.
10
+ * Only `%0<width>d` is a format, as DASH-IF IOP 4.3 §4.3.2.2.8 restricts it,
11
+ * and `$RepresentationID$` takes none. O(n).
12
+ *
13
+ * @returns The parts, or a message saying why the template is invalid.
14
+ */
15
+ export declare function parseTemplate(text: string): TemplatePart[] | string;
16
+ /** The values substituted into a template; `null` for one not available. */
17
+ export type TemplateValues = {
18
+ readonly representationId: string | null;
19
+ readonly bandwidth: number | null;
20
+ readonly number: number | null;
21
+ readonly time: bigint | null;
22
+ };
23
+ /**
24
+ * Substitutes `values` into parsed `parts`, padding a formatted value with
25
+ * zeros to its width. O(output).
26
+ *
27
+ * @returns The text, or the identifier with no value.
28
+ */
29
+ export declare function substituteTemplate(parts: readonly TemplatePart[], values: TemplateValues): string | {
30
+ readonly missing: TemplateIdentifier;
31
+ };
32
+ /** Whether `parts` use `identifier`. */
33
+ export declare function templateUses(parts: readonly TemplatePart[], identifier: TemplateIdentifier): boolean;
34
+ //# sourceMappingURL=_template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_template.d.ts","sourceRoot":"","sources":["../src/_template.ts"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,MAAM,MAAM,kBAAkB,GAC3B,kBAAkB,GAClB,QAAQ,GACR,WAAW,GACX,MAAM,GACN,WAAW,CAAC;AAEf,gFAAgF;AAChF,MAAM,MAAM,YAAY,GACrB,MAAM,GACN;IAAE,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAKvE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,GAAG,MAAM,CAwCnE;AAED,4EAA4E;AAC5E,MAAM,MAAM,cAAc,GAAG;IAC5B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,MAAM,EAAE,cAAc,GACpB,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAA;CAAE,CAcnD;AAED,wCAAwC;AACxC,wBAAgB,YAAY,CAC3B,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,UAAU,EAAE,kBAAkB,GAC5B,OAAO,CAIT"}
@@ -0,0 +1,90 @@
1
+ import { DASH_MAX_TEMPLATE_WIDTH } from "./limits.js";
2
+ const IDENTIFIER_ = /\$(RepresentationID|Number|Bandwidth|Time|SubNumber)(?:%0(\d{1,3})d)?\$/y;
3
+ /**
4
+ * Splits a template into literal runs and identifiers, `$$` becoming a `$`.
5
+ * Only `%0<width>d` is a format, as DASH-IF IOP 4.3 §4.3.2.2.8 restricts it,
6
+ * and `$RepresentationID$` takes none. O(n).
7
+ *
8
+ * @returns The parts, or a message saying why the template is invalid.
9
+ */
10
+ export function parseTemplate(text) {
11
+ const parts = [];
12
+ let literal = "";
13
+ let cursor = 0;
14
+ while (cursor < text.length) {
15
+ const dollar = text.indexOf("$", cursor);
16
+ if (dollar === -1) {
17
+ literal += text.slice(cursor);
18
+ break;
19
+ }
20
+ literal += text.slice(cursor, dollar);
21
+ if (text[dollar + 1] === "$") {
22
+ literal += "$";
23
+ cursor = dollar + 2;
24
+ continue;
25
+ }
26
+ IDENTIFIER_.lastIndex = dollar;
27
+ const match = IDENTIFIER_.exec(text);
28
+ if (match === null) {
29
+ return `"${text}" has an unknown identifier or format at ${dollar}`;
30
+ }
31
+ const identifier = match[1];
32
+ const width = match[2] === undefined ? 0 : Number(match[2]);
33
+ if (identifier === "RepresentationID" && match[2] !== undefined) {
34
+ return `"${text}" formats $RepresentationID$, which takes no format`;
35
+ }
36
+ if (width > DASH_MAX_TEMPLATE_WIDTH) {
37
+ return `"${text}" asks for a width of ${width}, more than ${DASH_MAX_TEMPLATE_WIDTH}`;
38
+ }
39
+ if (literal.length > 0) {
40
+ parts.push(literal);
41
+ literal = "";
42
+ }
43
+ parts.push({ identifier, width });
44
+ cursor = IDENTIFIER_.lastIndex;
45
+ }
46
+ if (literal.length > 0) {
47
+ parts.push(literal);
48
+ }
49
+ return parts;
50
+ }
51
+ /**
52
+ * Substitutes `values` into parsed `parts`, padding a formatted value with
53
+ * zeros to its width. O(output).
54
+ *
55
+ * @returns The text, or the identifier with no value.
56
+ */
57
+ export function substituteTemplate(parts, values) {
58
+ let output = "";
59
+ for (const part of parts) {
60
+ if (typeof part === "string") {
61
+ output += part;
62
+ continue;
63
+ }
64
+ const value = valueOf_(part.identifier, values);
65
+ if (value === null) {
66
+ return { missing: part.identifier };
67
+ }
68
+ output += value.padStart(part.width, "0");
69
+ }
70
+ return output;
71
+ }
72
+ /** Whether `parts` use `identifier`. */
73
+ export function templateUses(parts, identifier) {
74
+ return parts.some((part) => typeof part !== "string" && part.identifier === identifier);
75
+ }
76
+ function valueOf_(identifier, values) {
77
+ switch (identifier) {
78
+ case "RepresentationID":
79
+ return values.representationId;
80
+ case "Number":
81
+ return values.number === null ? null : String(values.number);
82
+ case "Bandwidth":
83
+ return values.bandwidth === null ? null : String(values.bandwidth);
84
+ case "Time":
85
+ return values.time === null ? null : String(values.time);
86
+ case "SubNumber":
87
+ return null;
88
+ }
89
+ }
90
+ //# sourceMappingURL=_template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_template.js","sourceRoot":"","sources":["../src/_template.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,9 @@
1
+ import type { DashXlink } from "./model/dash-common.js";
2
+ /**
3
+ * How a possibly remote element reads before any xlink is resolved (§5.5):
4
+ * `local` without `xlink:href`, `absent` for `resolve-to-zero`, `remote`
5
+ * otherwise — its inline content is a placeholder the remote one replaces, so
6
+ * nothing is listed from it.
7
+ */
8
+ export declare function xlinkState(xlink: DashXlink | null): "local" | "absent" | "remote";
9
+ //# sourceMappingURL=_xlink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_xlink.d.ts","sourceRoot":"","sources":["../src/_xlink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD;;;;;GAKG;AACH,wBAAgB,UAAU,CACzB,KAAK,EAAE,SAAS,GAAG,IAAI,GACrB,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAK/B"}
package/dist/_xlink.js ADDED
@@ -0,0 +1,14 @@
1
+ import { DASH_XLINK_RESOLVE_TO_ZERO } from "./dash-namespaces.js";
2
+ /**
3
+ * How a possibly remote element reads before any xlink is resolved (§5.5):
4
+ * `local` without `xlink:href`, `absent` for `resolve-to-zero`, `remote`
5
+ * otherwise — its inline content is a placeholder the remote one replaces, so
6
+ * nothing is listed from it.
7
+ */
8
+ export function xlinkState(xlink) {
9
+ if (xlink === null) {
10
+ return "local";
11
+ }
12
+ return xlink.href === DASH_XLINK_RESOLVE_TO_ZERO ? "absent" : "remote";
13
+ }
14
+ //# sourceMappingURL=_xlink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_xlink.js","sourceRoot":"","sources":["../src/_xlink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAGlE;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CACzB,KAAuB;IAEvB,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,OAAO,CAAC;IAChB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,KAAK,0BAA0B,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;AACxE,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The MPD namespace of ISO/IEC 23009-1, every edition since the first
3
+ * corrigendum.
4
+ */
5
+ export declare const DASH_MPD_NAMESPACE = "urn:mpeg:dash:schema:mpd:2011";
6
+ /**
7
+ * The MPD namespace as the first edition spelled it, before the corrigendum
8
+ * lowered its case. Still read, with an advisory, since older packagers wrote
9
+ * it.
10
+ */
11
+ export declare const DASH_MPD_LEGACY_NAMESPACE = "urn:mpeg:DASH:schema:MPD:2011";
12
+ /**
13
+ * The Common Encryption namespace (ISO/IEC 23001-7), of `cenc:default_KID` and
14
+ * `cenc:pssh`.
15
+ */
16
+ export declare const DASH_CENC_NAMESPACE = "urn:mpeg:cenc:2013";
17
+ /**
18
+ * The namespaces DASH-IF content protection guidelines have put the `Laurl`
19
+ * element in, newest first.
20
+ */
21
+ export declare const DASH_IF_CONTENT_PROTECTION_NAMESPACES: readonly string[];
22
+ /**
23
+ * The `xlink:href` that resolves a remote element to nothing (§5.5.3): the
24
+ * element is treated as absent.
25
+ */
26
+ export declare const DASH_XLINK_RESOLVE_TO_ZERO = "urn:mpeg:dash:resolve-to-zero:2013";
27
+ //# sourceMappingURL=dash-namespaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dash-namespaces.d.ts","sourceRoot":"","sources":["../src/dash-namespaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,kBAAkB,kCAAkC,CAAC;AAElE;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,kCAAkC,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,mBAAmB,uBAAuB,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,qCAAqC,EAAE,SAAS,MAAM,EAGlE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,uCAAuC,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The MPD namespace of ISO/IEC 23009-1, every edition since the first
3
+ * corrigendum.
4
+ */
5
+ export const DASH_MPD_NAMESPACE = "urn:mpeg:dash:schema:mpd:2011";
6
+ /**
7
+ * The MPD namespace as the first edition spelled it, before the corrigendum
8
+ * lowered its case. Still read, with an advisory, since older packagers wrote
9
+ * it.
10
+ */
11
+ export const DASH_MPD_LEGACY_NAMESPACE = "urn:mpeg:DASH:schema:MPD:2011";
12
+ /**
13
+ * The Common Encryption namespace (ISO/IEC 23001-7), of `cenc:default_KID` and
14
+ * `cenc:pssh`.
15
+ */
16
+ export const DASH_CENC_NAMESPACE = "urn:mpeg:cenc:2013";
17
+ /**
18
+ * The namespaces DASH-IF content protection guidelines have put the `Laurl`
19
+ * element in, newest first.
20
+ */
21
+ export const DASH_IF_CONTENT_PROTECTION_NAMESPACES = [
22
+ "https://dashif.org/CPS",
23
+ "https://dashif.org/",
24
+ ];
25
+ /**
26
+ * The `xlink:href` that resolves a remote element to nothing (§5.5.3): the
27
+ * element is treated as absent.
28
+ */
29
+ export const DASH_XLINK_RESOLVE_TO_ZERO = "urn:mpeg:dash:resolve-to-zero:2013";
30
+ //# sourceMappingURL=dash-namespaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dash-namespaces.js","sourceRoot":"","sources":["../src/dash-namespaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,+BAA+B,CAAC;AAElE;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,+BAA+B,CAAC;AAEzE;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAsB;IACvE,wBAAwB;IACxB,qBAAqB;CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,oCAAoC,CAAC"}