rx-player 4.5.0-dev.2026021900 → 4.5.0-dev.2026031700

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 (100) hide show
  1. package/CHANGELOG.md +13 -3
  2. package/VERSION +1 -1
  3. package/dist/commonjs/__GENERATED_CODE/embedded_dash_wasm.d.ts.map +1 -1
  4. package/dist/commonjs/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
  5. package/dist/commonjs/__GENERATED_CODE/embedded_worker.d.ts.map +1 -1
  6. package/dist/commonjs/__GENERATED_CODE/embedded_worker.js +1 -1
  7. package/dist/commonjs/core/cmcd/cmcd_data_builder.js +2 -2
  8. package/dist/commonjs/core/entry/content_preparer.d.ts +1 -6
  9. package/dist/commonjs/core/entry/content_preparer.d.ts.map +1 -1
  10. package/dist/commonjs/core/entry/content_preparer.js +2 -125
  11. package/dist/commonjs/core/entry/core_entry.d.ts +1 -1
  12. package/dist/commonjs/core/entry/core_entry.d.ts.map +1 -1
  13. package/dist/commonjs/core/entry/core_entry.js +2 -7
  14. package/dist/commonjs/core/entry/core_text_displayer_interface.d.ts.map +1 -1
  15. package/dist/commonjs/core/entry/core_text_displayer_interface.js +3 -1
  16. package/dist/commonjs/core/entry/index.d.ts +1 -1
  17. package/dist/commonjs/core/entry/index.d.ts.map +1 -1
  18. package/dist/commonjs/core/entry/utils.d.ts +64 -0
  19. package/dist/commonjs/core/entry/utils.d.ts.map +1 -1
  20. package/dist/commonjs/core/entry/utils.js +165 -0
  21. package/dist/commonjs/core/fetchers/segment/segment_queue.d.ts +5 -6
  22. package/dist/commonjs/core/fetchers/segment/segment_queue.d.ts.map +1 -1
  23. package/dist/commonjs/core/fetchers/thumbnails/thumbnail_fetcher.d.ts.map +1 -1
  24. package/dist/commonjs/core/fetchers/thumbnails/thumbnail_fetcher.js +34 -30
  25. package/dist/commonjs/experimental/features/worker/index.d.ts +2 -1
  26. package/dist/commonjs/experimental/features/worker/index.d.ts.map +1 -1
  27. package/dist/commonjs/experimental/features/worker/index.js +4 -3
  28. package/dist/commonjs/main_thread/api/public_api.js +3 -3
  29. package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.d.ts.map +1 -1
  30. package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.js +16 -1
  31. package/dist/es2017/__GENERATED_CODE/embedded_dash_wasm.d.ts.map +1 -1
  32. package/dist/es2017/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
  33. package/dist/es2017/__GENERATED_CODE/embedded_worker.d.ts.map +1 -1
  34. package/dist/es2017/__GENERATED_CODE/embedded_worker.js +1 -1
  35. package/dist/es2017/core/cmcd/cmcd_data_builder.js +2 -2
  36. package/dist/es2017/core/entry/content_preparer.d.ts +1 -6
  37. package/dist/es2017/core/entry/content_preparer.d.ts.map +1 -1
  38. package/dist/es2017/core/entry/content_preparer.js +1 -76
  39. package/dist/es2017/core/entry/core_entry.d.ts +1 -1
  40. package/dist/es2017/core/entry/core_entry.d.ts.map +1 -1
  41. package/dist/es2017/core/entry/core_entry.js +2 -7
  42. package/dist/es2017/core/entry/core_text_displayer_interface.d.ts.map +1 -1
  43. package/dist/es2017/core/entry/core_text_displayer_interface.js +3 -1
  44. package/dist/es2017/core/entry/index.d.ts +1 -1
  45. package/dist/es2017/core/entry/index.d.ts.map +1 -1
  46. package/dist/es2017/core/entry/utils.d.ts +64 -0
  47. package/dist/es2017/core/entry/utils.d.ts.map +1 -1
  48. package/dist/es2017/core/entry/utils.js +98 -0
  49. package/dist/es2017/core/fetchers/segment/segment_queue.d.ts +5 -6
  50. package/dist/es2017/core/fetchers/segment/segment_queue.d.ts.map +1 -1
  51. package/dist/es2017/core/fetchers/thumbnails/thumbnail_fetcher.d.ts.map +1 -1
  52. package/dist/es2017/core/fetchers/thumbnails/thumbnail_fetcher.js +21 -16
  53. package/dist/es2017/experimental/features/worker/index.d.ts +2 -1
  54. package/dist/es2017/experimental/features/worker/index.d.ts.map +1 -1
  55. package/dist/es2017/experimental/features/worker/index.js +2 -3
  56. package/dist/es2017/main_thread/api/public_api.js +3 -3
  57. package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.d.ts.map +1 -1
  58. package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.js +16 -1
  59. package/dist/mpd-parser.wasm +0 -0
  60. package/dist/worker.js +8 -8
  61. package/package.json +19 -22
  62. package/src/__GENERATED_CODE/embedded_dash_wasm.ts +1 -1
  63. package/src/__GENERATED_CODE/embedded_worker.ts +1 -1
  64. package/src/core/adaptive/__tests__/adaptive_representation_selector.test.ts +734 -0
  65. package/src/core/adaptive/__tests__/guess_based_chooser.test.ts +5 -2
  66. package/src/core/adaptive/utils/__tests__/bandwidth_estimator.test.ts +117 -0
  67. package/src/core/adaptive/utils/__tests__/last_estimate_storage.test.ts +76 -0
  68. package/src/core/adaptive/utils/__tests__/pending_requests_store.test.ts +5 -2
  69. package/src/core/adaptive/utils/__tests__/representation_score_calculator.test.ts +4 -2
  70. package/src/core/cmcd/__tests__/cmcd_data_builder.test.ts +464 -0
  71. package/src/core/cmcd/cmcd_data_builder.ts +2 -2
  72. package/src/core/entry/__tests__/FreezeResolver.test.ts +1 -1
  73. package/src/core/entry/__tests__/content_time_boundaries_observer.test.ts +1 -2
  74. package/src/core/entry/__tests__/core_text_displayer_interface.test.ts +205 -0
  75. package/src/core/entry/__tests__/get_buffered_data_per_media_buffer.test.ts +95 -0
  76. package/src/core/entry/__tests__/track_choice_setter.test.ts +288 -0
  77. package/src/core/entry/__tests__/utils.test.ts +309 -0
  78. package/src/core/entry/content_preparer.ts +7 -118
  79. package/src/core/entry/core_entry.ts +7 -14
  80. package/src/core/entry/core_text_displayer_interface.ts +3 -1
  81. package/src/core/entry/index.ts +1 -1
  82. package/src/core/entry/utils.ts +151 -0
  83. package/src/core/fetchers/__tests__/cdn_prioritizer.test.ts +166 -0
  84. package/src/core/fetchers/manifest/__tests__/manifest_fetcher.test.ts +803 -0
  85. package/src/core/fetchers/segment/__tests__/segment_fetcher.test.ts +872 -0
  86. package/src/core/fetchers/segment/__tests__/segment_queue.test.ts +557 -0
  87. package/src/core/fetchers/segment/segment_queue.ts +5 -6
  88. package/src/core/fetchers/thumbnails/__tests__/thumbnail_fetcher.test.ts +435 -0
  89. package/src/core/fetchers/thumbnails/thumbnail_fetcher.ts +28 -20
  90. package/src/core/fetchers/utils/__tests__/schedule_request.test.ts +331 -0
  91. package/src/core/stream/adaptation/__tests__/get_representations_switch_strategy.test.ts +4 -3
  92. package/src/core/stream/representation/utils/__tests__/append_segment_to_buffer.test.ts +1 -1
  93. package/src/core/stream/representation/utils/__tests__/get_segment_priority.test.ts +1 -1
  94. package/src/core/stream/representation/utils/__tests__/push_init_segment.test.ts +1 -1
  95. package/src/core/stream/representation/utils/__tests__/push_media_segment.test.ts +1 -1
  96. package/src/experimental/features/worker/index.ts +2 -4
  97. package/src/main_thread/api/public_api.ts +3 -3
  98. package/src/mse/__tests__/main_media_source_interface.test.ts +846 -0
  99. package/src/parsers/texttracks/ttml/html/apply_line_height.ts +16 -1
  100. package/src/utils/__tests__/base64.test.ts +159 -191
@@ -35,7 +35,22 @@ export default function applyLineHeight(element: HTMLElement, lineHeight: string
35
35
  }
36
36
  if (
37
37
  firstLineHeight[2] === "px" ||
38
- firstLineHeight[2] === "%" ||
38
+ // TODO: For now, we disable the percentage unit as its rules are complex to
39
+ // implement in our current logic:
40
+ // A percentage `lineHeight` depends on the `fontSize` computed at that point,
41
+ // yet a lineHeight applies to a `p` in TTML and `fontSize` applies to a `span`
42
+ // (below `p`) and our translation applies that same level of style: CSS `lineHeight`
43
+ // is set on the element defining it, but `fontSize` is set at the end on each cue.
44
+ //
45
+ // Thus we cannot easily just rely on CSS' similar behavior for percentage
46
+ // `lineHeight`s because the `fontSize` might not be known at that point by
47
+ // the CSS (yet it might be for TTML). Work-around tricks are not straightforward
48
+ // either (e.g. we cannot just repeat the `fontSize` at both places because
49
+ // the potential percentage values in which they are expressed could coumpound).
50
+ // Seeing other players, it also seems poorly supported, so for now I think
51
+ // we can just ignore those. In a perfect world, it should be implemented
52
+ // though!
53
+ // firstLineHeight[2] === "%" ||
39
54
  firstLineHeight[2] === "em"
40
55
  ) {
41
56
  element.style.lineHeight = firstLineHeight[1] + firstLineHeight[2];
@@ -1,213 +1,181 @@
1
- import { describe, beforeEach, it, expect, vi, afterEach } from "vitest";
2
- import type {
3
- base64ToBytes as IBase64ToBytes,
4
- bytesToBase64 as IBytesToBase64,
5
- } from "../base64";
6
- import globalScope from "../global_scope";
7
-
8
- /** Every chars defined in base64. */
9
- const CHARS = [
10
- "A",
11
- "R",
12
- "i",
13
- "z",
14
- "B",
15
- "S",
16
- "j",
17
- "0",
18
- "C",
19
- "T",
20
- "k",
21
- "1",
22
- "D",
23
- "U",
24
- "l",
25
- "2",
26
- "E",
27
- "V",
28
- "m",
29
- "3",
30
- "F",
31
- "W",
32
- "n",
33
- "4",
34
- "G",
35
- "X",
36
- "o",
37
- "5",
38
- "H",
39
- "Y",
40
- "p",
41
- "6",
42
- "I",
43
- "Z",
44
- "q",
45
- "7",
46
- "J",
47
- "a",
48
- "r",
49
- "8",
50
- "K",
51
- "b",
52
- "s",
53
- "9",
54
- "L",
55
- "c",
56
- "t",
57
- "+",
58
- "M",
59
- "d",
60
- "u",
61
- "/",
62
- "N",
63
- "e",
64
- "v",
65
- "O",
66
- "f",
67
- "w",
68
- "P",
69
- "g",
70
- "x",
71
- "Q",
72
- "h",
73
- "y",
74
- ];
75
-
76
- describe("base64ToBytes", () => {
77
- const logWarn = vi.fn();
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { bytesToBase64, base64ToBytes } from "../base64";
3
+
4
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
5
+ /* eslint-disable @typescript-eslint/unbound-method */
6
+
7
+ const { mockWarn } = vi.hoisted(() => {
8
+ return { mockWarn: vi.fn() };
9
+ });
10
+
11
+ vi.mock("../../log", () => ({
12
+ default: {
13
+ warn: mockWarn,
14
+ },
15
+ }));
16
+
17
+ function removeNativeBytesToBase64() {
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ delete (Uint8Array.prototype as any).toBase64;
20
+ }
21
+
22
+ function removeNativeBase64ToBytes() {
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ delete (Uint8Array as any).fromBase64;
25
+ }
26
+
27
+ describe("bytesToBase64 – non-native fallback", () => {
28
+ let originalToBase64: ((options?: object) => string) | undefined;
29
+
78
30
  beforeEach(() => {
79
- vi.doMock("../../log", () => ({
80
- default: { warn: logWarn },
81
- }));
31
+ mockWarn.mockClear();
32
+ // Stash and remove the native method so the fallback is always exercised
33
+ originalToBase64 = (Uint8Array.prototype as { toBase64?: () => string }).toBase64;
34
+ removeNativeBytesToBase64();
82
35
  });
36
+
83
37
  afterEach(() => {
84
- vi.resetModules();
85
- logWarn.mockReset();
38
+ if (originalToBase64 !== undefined) {
39
+ (Uint8Array.prototype as { toBase64?: () => string }).toBase64 = originalToBase64;
40
+ }
86
41
  });
87
42
 
88
- it("should return an empty Uint8Array for an empty string", async () => {
89
- const base64ToBytes = (await vi.importActual("../base64"))
90
- .base64ToBytes as typeof IBase64ToBytes;
91
- expect(base64ToBytes("")).toEqual(new Uint8Array([]));
92
- expect(logWarn).not.toHaveBeenCalled();
43
+ it("encodes an empty Uint8Array to an empty string", () => {
44
+ expect(bytesToBase64(new Uint8Array([]))).toBe("");
93
45
  });
94
46
 
95
- it("should convert a base64 to an Uint8Array", async () => {
96
- const base64ToBytes = (await vi.importActual("../base64"))
97
- .base64ToBytes as typeof IBase64ToBytes;
98
- expect(base64ToBytes("woDCge+/vg==")).toEqual(
99
- new Uint8Array([194, 128, 194, 129, 239, 191, 190]),
100
- );
101
- expect(base64ToBytes("dG90b/CfjIM=")).toEqual(
102
- new Uint8Array([116, 111, 116, 111, 240, 159, 140, 131]),
103
- );
104
- expect(base64ToBytes("JGV4cGVjdChiYXNlNjRUb1VpbnQ4QXJyYXkoIiIp")).toEqual(
105
- new Uint8Array([
106
- 36, 101, 120, 112, 101, 99, 116, 40, 98, 97, 115, 101, 54, 52, 84, 111, 85, 105,
107
- 110, 116, 56, 65, 114, 114, 97, 121, 40, 34, 34, 41,
108
- ]),
109
- );
110
- expect(base64ToBytes(globalScope.btoa("toto"))).toEqual(
111
- new Uint8Array([116, 111, 116, 111]),
112
- );
113
- expect(logWarn).not.toHaveBeenCalled();
114
-
115
- const bytesToBase64 = (await vi.importActual("../base64"))
116
- .bytesToBase64 as typeof IBytesToBase64;
117
-
118
- for (let i = 0; i < CHARS.length; i++) {
119
- const char1 = CHARS[i];
120
- for (let j = 0; j < CHARS.length; j++) {
121
- const char2 = CHARS[j];
122
- // for (let k = 0; k < CHARS.length; k++) {
123
- // const char3 = CHARS[j];
124
- // for (let l = 0; l < CHARS.length; l++) {
125
- // const char4 = CHARS[j];
126
- const combination = char1 + char2 + char2 + char1;
127
- expect(bytesToBase64(base64ToBytes(combination))).toEqual(combination);
128
- // }
129
- // }
130
- }
131
- }
47
+ it("encodes a single byte – 1 octet path (== padding)", () => {
48
+ // 0x4D => "TQ=="
49
+ expect(bytesToBase64(new Uint8Array([0x4d]))).toBe("TQ==");
132
50
  });
133
51
 
134
- it("should convert a non-padded base64 to an Uint8Array", async () => {
135
- const base64ToBytes = (await vi.importActual("../base64"))
136
- .base64ToBytes as typeof IBase64ToBytes;
137
- expect(base64ToBytes("woDCge+/vg")).toEqual(
138
- new Uint8Array([194, 128, 194, 129, 239, 191, 190]),
139
- );
140
- expect(logWarn).toHaveBeenCalledTimes(1);
141
- expect(logWarn).toHaveBeenNthCalledWith(
142
- 1,
143
- "utils",
144
- "base64ToBytes: base64 given miss padding",
145
- { padding: 2 },
146
- );
147
- expect(base64ToBytes("dG90b/CfjIM")).toEqual(
148
- new Uint8Array([116, 111, 116, 111, 240, 159, 140, 131]),
149
- );
150
- expect(logWarn).toHaveBeenCalledTimes(2);
151
- expect(logWarn).toHaveBeenNthCalledWith(
152
- 2,
153
- "utils",
154
- "base64ToBytes: base64 given miss padding",
155
- { padding: 3 },
156
- );
52
+ it("encodes two bytes – 2 octet path (= padding)", () => {
53
+ // 0x4D 0x61 => "TWE="
54
+ expect(bytesToBase64(new Uint8Array([0x4d, 0x61]))).toBe("TWE=");
157
55
  });
158
56
 
159
- it("should fail on invalid data", async () => {
160
- const base64ToBytes = (await vi.importActual("../base64"))
161
- .base64ToBytes as typeof IBase64ToBytes;
162
- expect(() => base64ToBytes("woD=Cge+/vg=")).toThrowError(
163
- "Unable to parse base64 string.",
164
- );
165
- expect(() => base64ToBytes("woDCg{+/vg==")).toThrowError(
166
- "Unable to parse base64 string.",
167
- );
168
- expect(() => base64ToBytes("dG90b/Cfj===")).toThrowError(
169
- "Unable to parse base64 string.",
170
- );
57
+ it("encodes three bytes – full group, no padding", () => {
58
+ // 0x4D 0x61 0x6E => "TWFu"
59
+ expect(bytesToBase64(new Uint8Array([0x4d, 0x61, 0x6e]))).toBe("TWFu");
60
+ });
61
+
62
+ it("encodes multiple full groups", () => {
63
+ const bytes = new Uint8Array([0x4d, 0x61, 0x6e, 0x4d, 0x61, 0x6e]);
64
+ expect(bytesToBase64(bytes)).toBe("TWFuTWFu");
65
+ });
66
+
67
+ it("encodes all-zero bytes", () => {
68
+ expect(bytesToBase64(new Uint8Array([0, 0, 0]))).toBe("AAAA");
69
+ });
70
+
71
+ it("encodes all-max-value bytes", () => {
72
+ expect(bytesToBase64(new Uint8Array([255, 255, 255]))).toBe("////");
73
+ });
74
+ });
75
+
76
+ describe("bytesToBase64 – native path", () => {
77
+ it("delegates to toBase64 when it exists on the instance", () => {
78
+ const nativeResult = "nativeBase64==";
79
+ const bytes = new Uint8Array([1, 2, 3]) as Uint8Array & { toBase64: () => string };
80
+ bytes.toBase64 = vi.fn().mockReturnValue(nativeResult);
81
+ expect(bytesToBase64(bytes)).toBe(nativeResult);
82
+ expect(bytes.toBase64).toHaveBeenCalledOnce();
171
83
  });
172
84
  });
173
85
 
174
- describe("bytesToBase64", () => {
175
- const logWarn = vi.fn();
86
+ describe("base64ToBytes – non-native fallback", () => {
87
+ let originalFromBase64: ((base64: string, options?: object) => Uint8Array) | undefined;
88
+
176
89
  beforeEach(() => {
177
- vi.resetModules();
178
- logWarn.mockReset();
179
- vi.doMock("../../log", () => ({
180
- default: { warn: logWarn },
181
- }));
90
+ mockWarn.mockClear();
91
+ // Stash and remove the native static method so the fallback is always exercised
92
+ originalFromBase64 = Uint8Array.fromBase64;
93
+ removeNativeBase64ToBytes();
182
94
  });
183
95
 
184
- it("should return an empty string for an empty Uint8Array", async () => {
185
- const bytesToBase64 = (await vi.importActual("../base64"))
186
- .bytesToBase64 as typeof IBytesToBase64;
187
- expect(bytesToBase64(new Uint8Array([]))).toEqual("");
188
- expect(logWarn).not.toHaveBeenCalled();
96
+ afterEach(() => {
97
+ if (originalFromBase64 !== undefined) {
98
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
+ (Uint8Array as any).fromBase64 = originalFromBase64;
100
+ }
189
101
  });
190
102
 
191
- it("should convert a base64 to an Uint8Array", async () => {
192
- const bytesToBase64 = (await vi.importActual("../base64"))
193
- .bytesToBase64 as typeof IBytesToBase64;
194
- expect(bytesToBase64(new Uint8Array([194, 128, 194, 129, 239, 191, 190]))).toEqual(
195
- "woDCge+/vg==",
196
- );
197
- expect(
198
- bytesToBase64(new Uint8Array([116, 111, 116, 111, 240, 159, 140, 131])),
199
- ).toEqual("dG90b/CfjIM=");
200
- expect(
201
- bytesToBase64(
202
- new Uint8Array([
203
- 36, 101, 120, 112, 101, 99, 116, 40, 98, 97, 115, 101, 54, 52, 84, 111, 85, 105,
204
- 110, 116, 56, 65, 114, 114, 97, 121, 40, 34, 34, 41,
205
- ]),
206
- ),
207
- ).toEqual("JGV4cGVjdChiYXNlNjRUb1VpbnQ4QXJyYXkoIiIp");
208
- expect(bytesToBase64(new Uint8Array([116, 111, 116, 111]))).toEqual(
209
- globalScope.btoa("toto"),
103
+ it("decodes a standard base64 string with no padding needed", () => {
104
+ // "TWFu" => "Man"
105
+ expect(base64ToBytes("TWFu")).toEqual(new Uint8Array([0x4d, 0x61, 0x6e]));
106
+ });
107
+
108
+ it("decodes base64 with a single trailing padding char", () => {
109
+ // "TWE=" => "Ma"
110
+ expect(base64ToBytes("TWE=")).toEqual(new Uint8Array([0x4d, 0x61]));
111
+ });
112
+
113
+ it("decodes base64 with double trailing padding chars", () => {
114
+ // "TQ==" => "M"
115
+ expect(base64ToBytes("TQ==")).toEqual(new Uint8Array([0x4d]));
116
+ });
117
+
118
+ it("decodes an empty string to an empty Uint8Array", () => {
119
+ expect(base64ToBytes("")).toEqual(new Uint8Array([]));
120
+ });
121
+
122
+ it("decodes multiple full groups", () => {
123
+ expect(base64ToBytes("TWFuTWFu")).toEqual(
124
+ new Uint8Array([0x4d, 0x61, 0x6e, 0x4d, 0x61, 0x6e]),
210
125
  );
211
- expect(logWarn).not.toHaveBeenCalled();
126
+ });
127
+
128
+ it("warns and recovers when 1 padding char is missing (length % 4 === 3)", () => {
129
+ // "TWE" is "TWE=" without the trailing "="
130
+ const result = base64ToBytes("TWE");
131
+ expect(mockWarn).toHaveBeenCalledOnce();
132
+ expect(result).toEqual(new Uint8Array([0x4d, 0x61]));
133
+ });
134
+
135
+ it("warns and recovers when 2 padding chars are missing (length % 4 === 2)", () => {
136
+ // "TQ" is "TQ==" without the trailing "=="
137
+ const result = base64ToBytes("TQ");
138
+ expect(mockWarn).toHaveBeenCalledOnce();
139
+ expect(result).toEqual(new Uint8Array([0x4d]));
140
+ });
141
+
142
+ it("does not warn when input is already correctly padded", () => {
143
+ base64ToBytes("TWFu");
144
+ expect(mockWarn).not.toHaveBeenCalled();
145
+ });
146
+
147
+ it("throws when an invalid base64 character is encountered", () => {
148
+ expect(() => base64ToBytes("TQ=!")).toThrow("Unable to parse base64 string.");
149
+ });
150
+
151
+ it("throws when a high char code (>= 123) is encountered", () => {
152
+ // '~' has char code 126, beyond the base64codes table
153
+ expect(() => base64ToBytes("TQ=~")).toThrow("Unable to parse base64 string.");
154
+ });
155
+
156
+ it("throws when a padding char appears in a non-terminal position", () => {
157
+ expect(() => base64ToBytes("TQ==A")).toThrow("Unable to parse base64 string.");
158
+ });
159
+
160
+ it("is the inverse of bytesToBase64 for arbitrary byte sequences", () => {
161
+ const original = new Uint8Array([0, 1, 127, 128, 200, 255, 42, 7]);
162
+ const encoded = bytesToBase64(original);
163
+ expect(base64ToBytes(encoded)).toEqual(original);
164
+ });
165
+ });
166
+
167
+ describe("base64ToBytes – native path", () => {
168
+ it("delegates to Uint8Array.fromBase64 when it exists", () => {
169
+ const fakeResult = new Uint8Array([1, 2, 3]);
170
+ const spy = vi.fn().mockReturnValue(fakeResult);
171
+ (Uint8Array as { fromBase64?: unknown }).fromBase64 = spy;
172
+
173
+ try {
174
+ const result = base64ToBytes("AQID");
175
+ expect(spy).toHaveBeenCalledWith("AQID");
176
+ expect(result).toBe(fakeResult);
177
+ } finally {
178
+ delete (Uint8Array as { fromBase64?: unknown }).fromBase64;
179
+ }
212
180
  });
213
181
  });