@php-wasm/web 3.1.34 → 3.1.36

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.
package/index.js CHANGED
@@ -1,14 +1,44 @@
1
- import { LatestSupportedPHPVersion as oe, withResolvedPHPExtensions as Ie, resolvePHPExtension as Y, isLegacyPHPVersion as Ke, createLegacyPhpIniPreRunStep as De, loadPHPRuntime as We, FSHelpers as M, __private__dont__use as O } from "@php-wasm/universal";
2
- import { consumeAPI as Ut, exposeAPI as vt } from "@php-wasm/universal";
3
- import { concatArrayBuffers as v, concatUint8Arrays as H, Semaphore as Pe, joinPaths as ce, basename as be } from "@php-wasm/util";
4
- import { logger as B } from "@php-wasm/logger";
5
- import { fetchWithCorsProxy as Re } from "@php-wasm/web-service-worker";
6
- import { FirewallInterferenceError as xt, fetchWithCorsProxy as Nt } from "@php-wasm/web-service-worker";
7
- import { createMemoizedFetch as Be } from "@wp-playground/common";
8
- import { jspi as Ue } from "wasm-feature-detect";
9
- import { journalFSEvents as ve, normalizeFilesystemOperations as Me } from "@php-wasm/fs-journal";
10
- async function xe(i = oe) {
11
- switch (i) {
1
+ import { LatestSupportedPHPVersion as Se, withResolvedPHPExtensions as Pe, isLegacyPHPVersion as le, isPHPNextVersion as be, resolvePHPExtension as Y, createLegacyPhpIniPreRunStep as Re, loadPHPRuntime as Be, FSHelpers as v, __private__dont__use as O } from "@php-wasm/universal";
2
+ import { consumeAPI as qt, exposeAPI as Ft } from "@php-wasm/universal";
3
+ import { concatArrayBuffers as x, concatUint8Arrays as H, Semaphore as Ue, joinPaths as he, basename as xe } from "@php-wasm/util";
4
+ import { logger as g } from "@php-wasm/logger";
5
+ import { fetchWithCorsProxy as ve } from "@php-wasm/web-service-worker";
6
+ import { FirewallInterferenceError as jt, fetchWithCorsProxy as $t } from "@php-wasm/web-service-worker";
7
+ import { createMemoizedFetch as Me } from "@wp-playground/common";
8
+ import { jspi as Ne } from "wasm-feature-detect";
9
+ import { journalFSEvents as ke, normalizeFilesystemOperations as qe } from "@php-wasm/fs-journal";
10
+ async function Fe() {
11
+ const s = Oe();
12
+ let e;
13
+ for (const t of s)
14
+ try {
15
+ return await import(
16
+ /* @vite-ignore */
17
+ t
18
+ );
19
+ } catch (n) {
20
+ e = n;
21
+ }
22
+ throw new Error(
23
+ "PHP next assets are missing. Run `npm run sync:php-next` before using PHP next locally.",
24
+ { cause: e }
25
+ );
26
+ }
27
+ function Oe() {
28
+ var n, r;
29
+ const s = ((n = globalThis.location) == null ? void 0 : n.origin) || "", t = (((r = globalThis.location) == null ? void 0 : r.pathname) || "/").startsWith("/website-server/") ? "/website-server/" : "/";
30
+ return Array.from(
31
+ /* @__PURE__ */ new Set([
32
+ `${s}${t}php-next/index.js`,
33
+ `${s}/website-server/php-next/index.js`,
34
+ `${s}/php-next/index.js`
35
+ ])
36
+ );
37
+ }
38
+ async function je(s = Se, e = "asyncify") {
39
+ switch (s) {
40
+ case "next":
41
+ return (await Fe()).getPHPLoaderModule(e);
12
42
  case "8.5":
13
43
  return (await import("@php-wasm/web-8-5")).getPHPLoaderModule();
14
44
  case "8.4":
@@ -26,26 +56,26 @@ async function xe(i = oe) {
26
56
  case "5.2":
27
57
  return (await import("@php-wasm/web-5-2")).getPHPLoaderModule();
28
58
  }
29
- throw new Error(`Unsupported PHP version ${i}`);
59
+ throw new Error(`Unsupported PHP version ${s}`);
30
60
  }
31
- function p(i) {
32
- return Object.fromEntries(Object.entries(i).map(([e, t]) => [t, e]));
61
+ function w(s) {
62
+ return Object.fromEntries(Object.entries(s).map(([e, t]) => [t, e]));
33
63
  }
34
- function D(i) {
35
- return new Uint8Array([i >> 8 & 255, i & 255]);
64
+ function W(s) {
65
+ return new Uint8Array([s >> 8 & 255, s & 255]);
36
66
  }
37
- function m(i) {
67
+ function L(s) {
38
68
  return new Uint8Array([
39
- i >> 16 & 255,
40
- i >> 8 & 255,
41
- i & 255
69
+ s >> 16 & 255,
70
+ s >> 8 & 255,
71
+ s & 255
42
72
  ]);
43
73
  }
44
- function Z(i) {
74
+ function Z(s) {
45
75
  const e = new ArrayBuffer(8);
46
- return new DataView(e).setBigUint64(0, BigInt(i), !1), new Uint8Array(e);
76
+ return new DataView(e).setBigUint64(0, BigInt(s), !1), new Uint8Array(e);
47
77
  }
48
- class g {
78
+ class I {
49
79
  constructor(e) {
50
80
  this.offset = 0, this.buffer = e, this.view = new DataView(e);
51
81
  }
@@ -86,7 +116,7 @@ class N {
86
116
  this.uint8Array.set(e, this.offset), this.offset += e.length;
87
117
  }
88
118
  }
89
- const W = {
119
+ const P = {
90
120
  server_name: 0,
91
121
  max_fragment_length: 1,
92
122
  client_certificate_url: 2,
@@ -141,28 +171,28 @@ const W = {
141
171
  transparency_info: 52,
142
172
  connection_id: 54,
143
173
  renegotiation_info: 65281
144
- }, Ne = p(W), Se = {
174
+ }, $e = w(P), Ce = {
145
175
  host_name: 0
146
- }, ke = p(Se);
147
- class Ce {
176
+ }, Ge = w(Ce);
177
+ class ue {
148
178
  static decodeFromClient(e) {
149
179
  const t = new DataView(e.buffer);
150
180
  let n = 0;
151
181
  const r = t.getUint16(n);
152
182
  n += 2;
153
- const s = [];
183
+ const i = [];
154
184
  for (; n < r + 2; ) {
155
185
  const a = e[n];
156
186
  n += 1;
157
187
  const _ = t.getUint16(n);
158
188
  n += 2;
159
- const c = e.slice(n, n + _);
189
+ const o = e.slice(n, n + _);
160
190
  switch (n += _, a) {
161
- case Se.host_name:
162
- s.push({
163
- name_type: ke[a],
191
+ case Ce.host_name:
192
+ i.push({
193
+ name_type: Ge[a],
164
194
  name: {
165
- host_name: new TextDecoder().decode(c)
195
+ host_name: new TextDecoder().decode(o)
166
196
  }
167
197
  });
168
198
  break;
@@ -170,7 +200,7 @@ class Ce {
170
200
  throw new Error(`Unsupported name type ${a}`);
171
201
  }
172
202
  }
173
- return { server_name_list: s };
203
+ return { server_name_list: i };
174
204
  }
175
205
  /**
176
206
  * Encode the server_name extension
@@ -189,15 +219,15 @@ class Ce {
189
219
  "Encoding non-empty lists for ClientHello is not supported yet. Only empty lists meant for ServerHello are supported today."
190
220
  );
191
221
  const t = new N(4);
192
- return t.writeUint16(W.server_name), t.writeUint16(0), t.uint8Array;
222
+ return t.writeUint16(P.server_name), t.writeUint16(0), t.uint8Array;
193
223
  }
194
224
  }
195
- const le = {
225
+ const Ae = {
196
226
  uncompressed: 0,
197
227
  ansiX962_compressed_prime: 1,
198
228
  ansiX962_compressed_char2: 2
199
- }, J = p(le);
200
- class he {
229
+ }, J = w(Ae);
230
+ class He {
201
231
  /**
202
232
  * +--------------------------------------------------+
203
233
  * | Payload Length [2B] |
@@ -214,8 +244,8 @@ class he {
214
244
  * +--------------------------------------------------+
215
245
  */
216
246
  static decodeFromClient(e) {
217
- const t = new g(e.buffer), n = t.readUint8(), r = [];
218
- for (let s = 0; s < n; s++) {
247
+ const t = new I(e.buffer), n = t.readUint8(), r = [];
248
+ for (let i = 0; i < n; i++) {
219
249
  const a = t.readUint8();
220
250
  a in J && r.push(J[a]);
221
251
  }
@@ -237,14 +267,14 @@ class he {
237
267
  */
238
268
  static encodeForClient(e) {
239
269
  const t = new N(6);
240
- return t.writeUint16(W.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(le[e]), t.uint8Array;
270
+ return t.writeUint16(P.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(Ae[e]), t.uint8Array;
241
271
  }
242
272
  }
243
- const Ae = {
244
- decodeFromClient(i) {
245
- const e = i[0] ?? 0;
273
+ const de = {
274
+ decodeFromClient(s) {
275
+ const e = s[0] ?? 0;
246
276
  return {
247
- renegotiatedConnection: i.slice(1, 1 + e)
277
+ renegotiatedConnection: s.slice(1, 1 + e)
248
278
  };
249
279
  },
250
280
  /**
@@ -252,16 +282,16 @@ const Ae = {
252
282
  * with an empty renegotiated_connection field.
253
283
  */
254
284
  encodeForClient() {
255
- const i = W.renegotiation_info, e = new Uint8Array([0]);
285
+ const s = P.renegotiation_info, e = new Uint8Array([0]);
256
286
  return new Uint8Array([
257
- i >> 8 & 255,
258
- i & 255,
287
+ s >> 8 & 255,
288
+ s & 255,
259
289
  0,
260
290
  e.length,
261
291
  ...e
262
292
  ]);
263
293
  }
264
- }, ue = {
294
+ }, fe = {
265
295
  TLS1_CK_PSK_WITH_RC4_128_SHA: 138,
266
296
  TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA: 139,
267
297
  TLS1_CK_PSK_WITH_AES_128_CBC_SHA: 140,
@@ -464,14 +494,14 @@ const Ae = {
464
494
  TLS1_CK_ECDHE_PSK_WITH_CHACHA20_POLY1305: 52396,
465
495
  TLS1_CK_DHE_PSK_WITH_CHACHA20_POLY1305: 52397,
466
496
  TLS1_CK_RSA_PSK_WITH_CHACHA20_POLY1305: 52398
467
- }, X = p(ue), He = {
497
+ }, X = w(fe), Ee = {
468
498
  secp256r1: 23,
469
499
  secp384r1: 24,
470
500
  secp521r1: 25,
471
501
  x25519: 29,
472
502
  x448: 30
473
- }, Q = p(He);
474
- class qe {
503
+ }, Q = w(Ee);
504
+ class Ve {
475
505
  /**
476
506
  * +--------------------------------------------------+
477
507
  * | Payload Length [2B] |
@@ -488,7 +518,7 @@ class qe {
488
518
  * +--------------------------------------------------+
489
519
  */
490
520
  static decodeFromClient(e) {
491
- const t = new g(e.buffer);
521
+ const t = new I(e.buffer);
492
522
  t.readUint16();
493
523
  const n = [];
494
524
  for (; !t.isFinished(); ) {
@@ -509,7 +539,7 @@ class qe {
509
539
  */
510
540
  static encodeForClient(e) {
511
541
  const t = new N(6);
512
- return t.writeUint16(W.supported_groups), t.writeUint16(2), t.writeUint16(He[e]), t.uint8Array;
542
+ return t.writeUint16(P.supported_groups), t.writeUint16(2), t.writeUint16(Ee[e]), t.uint8Array;
513
543
  }
514
544
  }
515
545
  const V = {
@@ -517,7 +547,7 @@ const V = {
517
547
  rsa: 1,
518
548
  dsa: 2,
519
549
  ecdsa: 3
520
- }, ee = p(V), z = {
550
+ }, ee = w(V), z = {
521
551
  none: 0,
522
552
  md5: 1,
523
553
  sha1: 2,
@@ -525,8 +555,8 @@ const V = {
525
555
  sha256: 4,
526
556
  sha384: 5,
527
557
  sha512: 6
528
- }, te = p(z);
529
- class Fe {
558
+ }, te = w(z);
559
+ class ze {
530
560
  /**
531
561
  * Binary layout:
532
562
  *
@@ -543,18 +573,18 @@ class Fe {
543
573
  * +------------------------------------+
544
574
  */
545
575
  static decodeFromClient(e) {
546
- const t = new g(e.buffer);
576
+ const t = new I(e.buffer);
547
577
  t.readUint16();
548
578
  const n = [];
549
579
  for (; !t.isFinished(); ) {
550
- const r = t.readUint8(), s = t.readUint8();
551
- if (ee[s]) {
580
+ const r = t.readUint8(), i = t.readUint8();
581
+ if (ee[i]) {
552
582
  if (!te[r]) {
553
- B.warn(`Unknown hash algorithm: ${r}`);
583
+ g.warn(`Unknown hash algorithm: ${r}`);
554
584
  continue;
555
585
  }
556
586
  n.push({
557
- algorithm: ee[s],
587
+ algorithm: ee[i],
558
588
  hash: te[r]
559
589
  });
560
590
  }
@@ -574,61 +604,61 @@ class Fe {
574
604
  */
575
605
  static encodeforClient(e, t) {
576
606
  const n = new N(6);
577
- return n.writeUint16(W.signature_algorithms), n.writeUint16(2), n.writeUint8(z[e]), n.writeUint8(V[t]), n.uint8Array;
607
+ return n.writeUint16(P.signature_algorithms), n.writeUint16(2), n.writeUint8(z[e]), n.writeUint8(V[t]), n.uint8Array;
578
608
  }
579
609
  }
580
610
  const ne = {
581
- server_name: Ce,
582
- signature_algorithms: Fe,
583
- supported_groups: qe,
584
- ec_point_formats: he,
585
- renegotiation_info: Ae
611
+ server_name: ue,
612
+ signature_algorithms: ze,
613
+ supported_groups: Ve,
614
+ ec_point_formats: He,
615
+ renegotiation_info: de
586
616
  };
587
- function Oe(i) {
588
- const e = new g(i.buffer), t = [];
617
+ function Ye(s) {
618
+ const e = new I(s.buffer), t = [];
589
619
  for (; !e.isFinished(); ) {
590
- const n = e.offset, r = e.readUint16(), s = Ne[r], a = e.readUint16(), _ = e.readUint8Array(a);
591
- if (!(s in ne))
620
+ const n = e.offset, r = e.readUint16(), i = $e[r], a = e.readUint16(), _ = e.readUint8Array(a);
621
+ if (!(i in ne))
592
622
  continue;
593
- const c = ne[s];
623
+ const o = ne[i];
594
624
  t.push({
595
- type: s,
596
- data: c.decodeFromClient(_),
597
- raw: i.slice(n, n + 4 + a)
625
+ type: i,
626
+ data: o.decodeFromClient(_),
627
+ raw: s.slice(n, n + 4 + a)
598
628
  });
599
629
  }
600
630
  return t;
601
631
  }
602
- async function G(i, e, t, n) {
603
- const r = v([e, t]), s = await crypto.subtle.importKey(
632
+ async function $(s, e, t, n) {
633
+ const r = x([e, t]), i = await crypto.subtle.importKey(
604
634
  "raw",
605
- i,
635
+ s,
606
636
  { name: "HMAC", hash: { name: "SHA-256" } },
607
637
  !1,
608
638
  ["sign"]
609
639
  );
610
640
  let a = r;
611
641
  const _ = [];
612
- for (; v(_).byteLength < n; ) {
613
- a = await re(s, a);
614
- const S = v([a, r]), C = await re(s, S);
615
- _.push(C);
642
+ for (; x(_).byteLength < n; ) {
643
+ a = await re(i, a);
644
+ const S = x([a, r]), l = await re(i, S);
645
+ _.push(l);
616
646
  }
617
- return v(_).slice(0, n);
647
+ return x(_).slice(0, n);
618
648
  }
619
- async function re(i, e) {
649
+ async function re(s, e) {
620
650
  return await crypto.subtle.sign(
621
651
  { name: "HMAC", hash: "SHA-256" },
622
- i,
652
+ s,
623
653
  e
624
654
  );
625
655
  }
626
- const je = {
656
+ const Ze = {
627
657
  Null: 0
628
- }, de = {
658
+ }, Te = {
629
659
  Warning: 1,
630
660
  Fatal: 2
631
- }, fe = p(de), Ee = {
661
+ }, pe = w(Te), we = {
632
662
  CloseNotify: 0,
633
663
  UnexpectedMessage: 10,
634
664
  BadRecordMac: 20,
@@ -654,12 +684,12 @@ const je = {
654
684
  UserCanceled: 90,
655
685
  NoRenegotiation: 100,
656
686
  UnsupportedExtension: 110
657
- }, Te = p(Ee), l = {
687
+ }, ye = w(we), C = {
658
688
  ChangeCipherSpec: 20,
659
689
  Alert: 21,
660
690
  Handshake: 22,
661
691
  ApplicationData: 23
662
- }, f = {
692
+ }, E = {
663
693
  HelloRequest: 0,
664
694
  ClientHello: 1,
665
695
  ServerHello: 2,
@@ -668,7 +698,7 @@ const je = {
668
698
  ServerHelloDone: 14,
669
699
  ClientKeyExchange: 16,
670
700
  Finished: 20
671
- }, Ge = {
701
+ }, Je = {
672
702
  /**
673
703
  * Indicates that a named curve is used. This option
674
704
  * SHOULD be used when applicable.
@@ -677,12 +707,12 @@ const je = {
677
707
  /**
678
708
  * Values 248 through 255 are reserved for private use.
679
709
  */
680
- }, $e = {
710
+ }, Xe = {
681
711
  secp256r1: 23
682
712
  };
683
713
  class j extends Error {
684
714
  }
685
- const x = new Uint8Array([3, 3]), Ve = crypto.subtle.generateKey(
715
+ const M = new Uint8Array([3, 3]), Qe = crypto.subtle.generateKey(
686
716
  {
687
717
  name: "ECDH",
688
718
  namedCurve: "P-256"
@@ -693,7 +723,7 @@ const x = new Uint8Array([3, 3]), Ve = crypto.subtle.generateKey(
693
723
  ["deriveKey", "deriveBits"]
694
724
  // Key usage
695
725
  );
696
- class ze {
726
+ class et {
697
727
  constructor() {
698
728
  this.receivedRecordSequenceNumber = 0, this.sentRecordSequenceNumber = 0, this.closed = !1, this.receivedBytesBuffer = new Uint8Array(), this.receivedTLSRecords = [], this.partialTLSMessages = {}, this.handshakeMessages = [], this.MAX_CHUNK_SIZE = 1024 * 16, this.clientEnd = {
699
729
  // We don't need to chunk the encrypted data.
@@ -710,14 +740,14 @@ class ze {
710
740
  * This will spread some messages across multiple records,
711
741
  * but TLS supports it so that's fine.
712
742
  */
713
- downstream: Ye(this.MAX_CHUNK_SIZE)
743
+ downstream: tt(this.MAX_CHUNK_SIZE)
714
744
  }, this.serverUpstreamWriter = this.serverEnd.upstream.writable.getWriter();
715
745
  const e = this;
716
746
  this.serverEnd.downstream.readable.pipeTo(
717
747
  new WritableStream({
718
748
  async write(t) {
719
749
  await e.writeTLSRecord(
720
- l.ApplicationData,
750
+ C.ApplicationData,
721
751
  t
722
752
  );
723
753
  },
@@ -767,7 +797,7 @@ class ze {
767
797
  */
768
798
  async TLSHandshake(e, t) {
769
799
  const n = await this.readNextHandshakeMessage(
770
- f.ClientHello
800
+ E.ClientHello
771
801
  );
772
802
  if (!n.body.cipher_suites.length)
773
803
  throw new Error(
@@ -775,46 +805,46 @@ class ze {
775
805
  );
776
806
  const r = crypto.getRandomValues(new Uint8Array(32));
777
807
  await this.writeTLSRecord(
778
- l.Handshake,
779
- K.serverHello(
808
+ C.Handshake,
809
+ D.serverHello(
780
810
  n.body,
781
811
  r,
782
- je.Null
812
+ Ze.Null
783
813
  )
784
814
  ), await this.writeTLSRecord(
785
- l.Handshake,
786
- K.certificate(t)
815
+ C.Handshake,
816
+ D.certificate(t)
787
817
  );
788
- const s = await Ve, a = n.body.random, _ = await K.ECDHEServerKeyExchange(
818
+ const i = await Qe, a = n.body.random, _ = await D.ECDHEServerKeyExchange(
789
819
  a,
790
820
  r,
791
- s,
821
+ i,
792
822
  e
793
823
  );
794
- await this.writeTLSRecord(l.Handshake, _), await this.writeTLSRecord(
795
- l.Handshake,
796
- K.serverHelloDone()
824
+ await this.writeTLSRecord(C.Handshake, _), await this.writeTLSRecord(
825
+ C.Handshake,
826
+ D.serverHelloDone()
797
827
  );
798
- const c = await this.readNextHandshakeMessage(
799
- f.ClientKeyExchange
828
+ const o = await this.readNextHandshakeMessage(
829
+ E.ClientKeyExchange
800
830
  );
801
- await this.readNextMessage(l.ChangeCipherSpec), this.sessionKeys = await this.deriveSessionKeys({
831
+ await this.readNextMessage(C.ChangeCipherSpec), this.sessionKeys = await this.deriveSessionKeys({
802
832
  clientRandom: a,
803
833
  serverRandom: r,
804
- serverPrivateKey: s.privateKey,
834
+ serverPrivateKey: i.privateKey,
805
835
  clientPublicKey: await crypto.subtle.importKey(
806
836
  "raw",
807
- c.body.exchange_keys,
837
+ o.body.exchange_keys,
808
838
  { name: "ECDH", namedCurve: "P-256" },
809
839
  !1,
810
840
  []
811
841
  )
812
- }), await this.readNextHandshakeMessage(f.Finished), await this.writeTLSRecord(
813
- l.ChangeCipherSpec,
814
- K.changeCipherSpec()
842
+ }), await this.readNextHandshakeMessage(E.Finished), await this.writeTLSRecord(
843
+ C.ChangeCipherSpec,
844
+ D.changeCipherSpec()
815
845
  ), await this.writeTLSRecord(
816
- l.Handshake,
817
- await K.createFinishedMessage(
846
+ C.Handshake,
847
+ await D.createFinishedMessage(
818
848
  this.handshakeMessages,
819
849
  this.sessionKeys.masterSecret
820
850
  )
@@ -830,7 +860,7 @@ class ze {
830
860
  serverPrivateKey: n,
831
861
  clientPublicKey: r
832
862
  }) {
833
- const s = await crypto.subtle.deriveBits(
863
+ const i = await crypto.subtle.deriveBits(
834
864
  {
835
865
  name: "ECDH",
836
866
  public: r
@@ -839,19 +869,19 @@ class ze {
839
869
  256
840
870
  // Length of the derived secret (256 bits for P-256)
841
871
  ), a = new Uint8Array(
842
- await G(
843
- s,
872
+ await $(
873
+ i,
844
874
  new TextEncoder().encode("master secret"),
845
875
  H([e, t]),
846
876
  48
847
877
  )
848
- ), _ = await G(
878
+ ), _ = await $(
849
879
  a,
850
880
  new TextEncoder().encode("key expansion"),
851
881
  H([t, e]),
852
882
  // Client key, server key, client IV, server IV
853
883
  40
854
- ), c = new g(_), S = c.readUint8Array(16), C = c.readUint8Array(16), h = c.readUint8Array(4), A = c.readUint8Array(4);
884
+ ), o = new I(_), S = o.readUint8Array(16), l = o.readUint8Array(16), h = o.readUint8Array(4), A = o.readUint8Array(4);
855
885
  return {
856
886
  masterSecret: a,
857
887
  clientWriteKey: await crypto.subtle.importKey(
@@ -863,7 +893,7 @@ class ze {
863
893
  ),
864
894
  serverWriteKey: await crypto.subtle.importKey(
865
895
  "raw",
866
- C,
896
+ l,
867
897
  { name: "AES-GCM" },
868
898
  !1,
869
899
  ["encrypt", "decrypt"]
@@ -873,7 +903,7 @@ class ze {
873
903
  };
874
904
  }
875
905
  async readNextHandshakeMessage(e) {
876
- const t = await this.readNextMessage(l.Handshake);
906
+ const t = await this.readNextMessage(C.Handshake);
877
907
  if (t.msg_type !== e)
878
908
  throw new Error(`Expected ${e} message`);
879
909
  return t;
@@ -883,34 +913,34 @@ class ze {
883
913
  do
884
914
  t = await this.readNextTLSRecord(e), n = await this.accumulateUntilMessageIsComplete(t);
885
915
  while (n === !1);
886
- const r = E.TLSMessage(
916
+ const r = T.TLSMessage(
887
917
  t.type,
888
918
  n
889
919
  );
890
- return t.type === l.Handshake && this.handshakeMessages.push(t.fragment), r;
920
+ return t.type === C.Handshake && this.handshakeMessages.push(t.fragment), r;
891
921
  }
892
922
  async readNextTLSRecord(e) {
893
923
  for (; ; ) {
894
924
  for (let _ = 0; _ < this.receivedTLSRecords.length; _++) {
895
- const c = this.receivedTLSRecords[_];
896
- if (c.type === e)
897
- return this.receivedTLSRecords.splice(_, 1), c;
925
+ const o = this.receivedTLSRecords[_];
926
+ if (o.type === e)
927
+ return this.receivedTLSRecords.splice(_, 1), o;
898
928
  }
899
- const t = await this.pollBytes(5), n = t[3] << 8 | t[4], r = t[0], s = await this.pollBytes(n), a = {
929
+ const t = await this.pollBytes(5), n = t[3] << 8 | t[4], r = t[0], i = await this.pollBytes(n), a = {
900
930
  type: r,
901
931
  version: {
902
932
  major: t[1],
903
933
  minor: t[2]
904
934
  },
905
935
  length: n,
906
- fragment: this.sessionKeys && r !== l.ChangeCipherSpec ? await this.decryptData(r, s) : s
936
+ fragment: this.sessionKeys && r !== C.ChangeCipherSpec ? await this.decryptData(r, i) : i
907
937
  };
908
- if (a.type === l.Alert) {
909
- const _ = a.fragment[0], c = a.fragment[1], S = fe[_], C = Te[c];
910
- throw _ === de.Warning && c === Ee.CloseNotify ? new j(
938
+ if (a.type === C.Alert) {
939
+ const _ = a.fragment[0], o = a.fragment[1], S = pe[_], l = ye[o];
940
+ throw _ === Te.Warning && o === we.CloseNotify ? new j(
911
941
  "TLS connection closed by peer (CloseNotify)"
912
942
  ) : new Error(
913
- `TLS alert received: ${S} ${C}`
943
+ `TLS alert received: ${S} ${l}`
914
944
  );
915
945
  }
916
946
  this.receivedTLSRecords.push(a);
@@ -930,7 +960,7 @@ class ze {
930
960
  n
931
961
  ]), this.receivedBytesBuffer.length >= e)
932
962
  break;
933
- await new Promise((s) => setTimeout(s, 100));
963
+ await new Promise((i) => setTimeout(i, 100));
934
964
  }
935
965
  const t = this.receivedBytesBuffer.slice(0, e);
936
966
  return this.receivedBytesBuffer = this.receivedBytesBuffer.slice(e), t;
@@ -943,7 +973,7 @@ class ze {
943
973
  try {
944
974
  for (; ; ) {
945
975
  const e = await this.readNextMessage(
946
- l.ApplicationData
976
+ C.ApplicationData
947
977
  );
948
978
  this.serverUpstreamWriter.write(e.body);
949
979
  }
@@ -958,16 +988,16 @@ class ze {
958
988
  * the AES-GCM algorithm.
959
989
  */
960
990
  async decryptData(e, t) {
961
- const n = this.sessionKeys.clientIV, r = t.slice(0, 8), s = new Uint8Array([...n, ...r]), a = await crypto.subtle.decrypt(
991
+ const n = this.sessionKeys.clientIV, r = t.slice(0, 8), i = new Uint8Array([...n, ...r]), a = await crypto.subtle.decrypt(
962
992
  {
963
993
  name: "AES-GCM",
964
- iv: s,
994
+ iv: i,
965
995
  additionalData: new Uint8Array([
966
996
  ...Z(this.receivedRecordSequenceNumber),
967
997
  e,
968
- ...x,
998
+ ...M,
969
999
  // Payload length without IV and tag
970
- ...D(t.length - 8 - 16)
1000
+ ...W(t.length - 8 - 16)
971
1001
  ]),
972
1002
  tagLength: 128
973
1003
  },
@@ -984,7 +1014,7 @@ class ze {
984
1014
  ]);
985
1015
  const t = this.partialTLSMessages[e.type];
986
1016
  switch (e.type) {
987
- case l.Handshake: {
1017
+ case C.Handshake: {
988
1018
  if (t.length < 4)
989
1019
  return !1;
990
1020
  const n = t[1] << 8 | t[2];
@@ -992,13 +1022,13 @@ class ze {
992
1022
  return !1;
993
1023
  break;
994
1024
  }
995
- case l.Alert: {
1025
+ case C.Alert: {
996
1026
  if (t.length < 2)
997
1027
  return !1;
998
1028
  break;
999
1029
  }
1000
- case l.ChangeCipherSpec:
1001
- case l.ApplicationData:
1030
+ case C.ChangeCipherSpec:
1031
+ case C.ApplicationData:
1002
1032
  break;
1003
1033
  default:
1004
1034
  throw new Error(`TLS: Unsupported record type ${e.type}`);
@@ -1013,10 +1043,10 @@ class ze {
1013
1043
  * only kicks in after the handshake is complete.
1014
1044
  */
1015
1045
  async writeTLSRecord(e, t) {
1016
- e === l.Handshake && this.handshakeMessages.push(t), this.sessionKeys && e !== l.ChangeCipherSpec && (t = await this.encryptData(e, t));
1017
- const n = x, r = t.length, s = new Uint8Array(5);
1018
- s[0] = e, s[1] = n[0], s[2] = n[1], s[3] = r >> 8 & 255, s[4] = r & 255;
1019
- const a = H([s, t]);
1046
+ e === C.Handshake && this.handshakeMessages.push(t), this.sessionKeys && e !== C.ChangeCipherSpec && (t = await this.encryptData(e, t));
1047
+ const n = M, r = t.length, i = new Uint8Array(5);
1048
+ i[0] = e, i[1] = n[0], i[2] = n[1], i[3] = r >> 8 & 255, i[4] = r & 255;
1049
+ const a = H([i, t]);
1020
1050
  this.clientDownstreamWriter.write(a);
1021
1051
  }
1022
1052
  /**
@@ -1024,16 +1054,16 @@ class ze {
1024
1054
  * the AES-GCM algorithm.
1025
1055
  */
1026
1056
  async encryptData(e, t) {
1027
- const n = this.sessionKeys.serverIV, r = crypto.getRandomValues(new Uint8Array(8)), s = new Uint8Array([...n, ...r]), a = new Uint8Array([
1057
+ const n = this.sessionKeys.serverIV, r = crypto.getRandomValues(new Uint8Array(8)), i = new Uint8Array([...n, ...r]), a = new Uint8Array([
1028
1058
  ...Z(this.sentRecordSequenceNumber),
1029
1059
  e,
1030
- ...x,
1060
+ ...M,
1031
1061
  // Payload length without IV and tag
1032
- ...D(t.length)
1062
+ ...W(t.length)
1033
1063
  ]), _ = await crypto.subtle.encrypt(
1034
1064
  {
1035
1065
  name: "AES-GCM",
1036
- iv: s,
1066
+ iv: i,
1037
1067
  additionalData: a,
1038
1068
  tagLength: 128
1039
1069
  },
@@ -1046,17 +1076,17 @@ class ze {
1046
1076
  ]);
1047
1077
  }
1048
1078
  }
1049
- class E {
1079
+ class T {
1050
1080
  static TLSMessage(e, t) {
1051
1081
  switch (e) {
1052
- case l.Handshake:
1053
- return E.clientHandshake(t);
1054
- case l.Alert:
1055
- return E.alert(t);
1056
- case l.ChangeCipherSpec:
1057
- return E.changeCipherSpec();
1058
- case l.ApplicationData:
1059
- return E.applicationData(t);
1082
+ case C.Handshake:
1083
+ return T.clientHandshake(t);
1084
+ case C.Alert:
1085
+ return T.alert(t);
1086
+ case C.ChangeCipherSpec:
1087
+ return T.changeCipherSpec();
1088
+ case C.ApplicationData:
1089
+ return T.applicationData(t);
1060
1090
  default:
1061
1091
  throw new Error(`TLS: Unsupported TLS record type ${e}`);
1062
1092
  }
@@ -1085,7 +1115,7 @@ class E {
1085
1115
  * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4
1086
1116
  */
1087
1117
  static parseCipherSuites(e) {
1088
- const t = new g(e);
1118
+ const t = new I(e);
1089
1119
  t.readUint16();
1090
1120
  const n = [];
1091
1121
  for (; !t.isFinished(); ) {
@@ -1096,47 +1126,47 @@ class E {
1096
1126
  }
1097
1127
  static applicationData(e) {
1098
1128
  return {
1099
- type: l.ApplicationData,
1129
+ type: C.ApplicationData,
1100
1130
  body: e
1101
1131
  };
1102
1132
  }
1103
1133
  static changeCipherSpec() {
1104
1134
  return {
1105
- type: l.ChangeCipherSpec,
1135
+ type: C.ChangeCipherSpec,
1106
1136
  body: new Uint8Array()
1107
1137
  };
1108
1138
  }
1109
1139
  static alert(e) {
1110
1140
  return {
1111
- type: l.Alert,
1112
- level: fe[e[0]],
1113
- description: Te[e[1]]
1141
+ type: C.Alert,
1142
+ level: pe[e[0]],
1143
+ description: ye[e[1]]
1114
1144
  };
1115
1145
  }
1116
1146
  static clientHandshake(e) {
1117
1147
  const t = e[0], n = e[1] << 16 | e[2] << 8 | e[3], r = e.slice(4);
1118
- let s;
1148
+ let i;
1119
1149
  switch (t) {
1120
- case f.HelloRequest:
1121
- s = E.clientHelloRequestPayload();
1150
+ case E.HelloRequest:
1151
+ i = T.clientHelloRequestPayload();
1122
1152
  break;
1123
- case f.ClientHello:
1124
- s = E.clientHelloPayload(r);
1153
+ case E.ClientHello:
1154
+ i = T.clientHelloPayload(r);
1125
1155
  break;
1126
- case f.ClientKeyExchange:
1127
- s = E.clientKeyExchangePayload(r);
1156
+ case E.ClientKeyExchange:
1157
+ i = T.clientKeyExchangePayload(r);
1128
1158
  break;
1129
- case f.Finished:
1130
- s = E.clientFinishedPayload(r);
1159
+ case E.Finished:
1160
+ i = T.clientFinishedPayload(r);
1131
1161
  break;
1132
1162
  default:
1133
1163
  throw new Error(`Invalid handshake type ${t}`);
1134
1164
  }
1135
1165
  return {
1136
- type: l.Handshake,
1166
+ type: C.Handshake,
1137
1167
  msg_type: t,
1138
1168
  length: n,
1139
- body: s
1169
+ body: i
1140
1170
  };
1141
1171
  }
1142
1172
  static clientHelloRequestPayload() {
@@ -1183,7 +1213,7 @@ class E {
1183
1213
  * +------+------+---------------------------+
1184
1214
  */
1185
1215
  static clientHelloPayload(e) {
1186
- const t = new g(e.buffer), n = {
1216
+ const t = new I(e.buffer), n = {
1187
1217
  client_version: t.readUint8Array(2),
1188
1218
  /**
1189
1219
  * Technically this consists of a GMT timestamp
@@ -1193,16 +1223,16 @@ class E {
1193
1223
  random: t.readUint8Array(32)
1194
1224
  }, r = t.readUint8();
1195
1225
  n.session_id = t.readUint8Array(r);
1196
- const s = t.readUint16();
1197
- n.cipher_suites = E.parseCipherSuites(
1198
- t.readUint8Array(s).buffer
1226
+ const i = t.readUint16();
1227
+ n.cipher_suites = T.parseCipherSuites(
1228
+ t.readUint8Array(i).buffer
1199
1229
  );
1200
1230
  const a = t.readUint8();
1201
1231
  n.compression_methods = t.readUint8Array(
1202
1232
  a
1203
1233
  );
1204
1234
  const _ = t.readUint16();
1205
- return n.extensions = Oe(
1235
+ return n.extensions = Ye(
1206
1236
  t.readUint8Array(_)
1207
1237
  ), n;
1208
1238
  }
@@ -1227,26 +1257,26 @@ class E {
1227
1257
  };
1228
1258
  }
1229
1259
  }
1230
- function Ye(i) {
1260
+ function tt(s) {
1231
1261
  return new TransformStream({
1232
1262
  transform(e, t) {
1233
1263
  for (; e.length > 0; )
1234
- t.enqueue(e.slice(0, i)), e = e.slice(i);
1264
+ t.enqueue(e.slice(0, s)), e = e.slice(s);
1235
1265
  }
1236
1266
  });
1237
1267
  }
1238
- class K {
1268
+ class D {
1239
1269
  static certificate(e) {
1240
1270
  const t = [];
1241
- for (const s of e)
1242
- t.push(m(s.byteLength)), t.push(new Uint8Array(s));
1271
+ for (const i of e)
1272
+ t.push(L(i.byteLength)), t.push(new Uint8Array(i));
1243
1273
  const n = H(t), r = new Uint8Array([
1244
- ...m(n.byteLength),
1274
+ ...L(n.byteLength),
1245
1275
  ...n
1246
1276
  ]);
1247
1277
  return new Uint8Array([
1248
- f.Certificate,
1249
- ...m(r.length),
1278
+ E.Certificate,
1279
+ ...L(r.length),
1250
1280
  ...r
1251
1281
  ]);
1252
1282
  }
@@ -1284,17 +1314,17 @@ class K {
1284
1314
  * @returns
1285
1315
  */
1286
1316
  static async ECDHEServerKeyExchange(e, t, n, r) {
1287
- const s = new Uint8Array(
1317
+ const i = new Uint8Array(
1288
1318
  await crypto.subtle.exportKey("raw", n.publicKey)
1289
1319
  ), a = new Uint8Array([
1290
1320
  // Curve type (1 byte)
1291
- Ge.NamedCurve,
1321
+ Je.NamedCurve,
1292
1322
  // Curve name (2 bytes)
1293
- ...D($e.secp256r1),
1323
+ ...W(Xe.secp256r1),
1294
1324
  // Public key length (1 byte)
1295
- s.byteLength,
1325
+ i.byteLength,
1296
1326
  // Public key (65 bytes, uncompressed format)
1297
- ...s
1327
+ ...i
1298
1328
  ]), _ = await crypto.subtle.sign(
1299
1329
  {
1300
1330
  name: "RSASSA-PKCS1-v1_5",
@@ -1302,19 +1332,19 @@ class K {
1302
1332
  },
1303
1333
  r,
1304
1334
  new Uint8Array([...e, ...t, ...a])
1305
- ), c = new Uint8Array(_), S = new Uint8Array([
1335
+ ), o = new Uint8Array(_), S = new Uint8Array([
1306
1336
  z.sha256,
1307
1337
  V.rsa
1308
- ]), C = new Uint8Array([
1338
+ ]), l = new Uint8Array([
1309
1339
  ...a,
1310
1340
  ...S,
1311
- ...D(c.length),
1312
- ...c
1341
+ ...W(o.length),
1342
+ ...o
1313
1343
  ]);
1314
1344
  return new Uint8Array([
1315
- f.ServerKeyExchange,
1316
- ...m(C.length),
1317
- ...C
1345
+ E.ServerKeyExchange,
1346
+ ...L(l.length),
1347
+ ...l
1318
1348
  ]);
1319
1349
  }
1320
1350
  /**
@@ -1359,34 +1389,34 @@ class K {
1359
1389
  const r = e.extensions.map((_) => {
1360
1390
  switch (_.type) {
1361
1391
  case "server_name":
1362
- return Ce.encodeForClient();
1392
+ return ue.encodeForClient();
1363
1393
  case "ec_point_formats":
1364
- return he.encodeForClient(
1394
+ return He.encodeForClient(
1365
1395
  "uncompressed"
1366
1396
  );
1367
1397
  case "renegotiation_info":
1368
- return Ae.encodeForClient();
1398
+ return de.encodeForClient();
1369
1399
  }
1370
- }).filter((_) => _ !== void 0), s = H(r), a = new Uint8Array([
1400
+ }).filter((_) => _ !== void 0), i = H(r), a = new Uint8Array([
1371
1401
  // Version field – 0x03, 0x03 means TLS 1.2
1372
- ...x,
1402
+ ...M,
1373
1403
  ...t,
1374
1404
  e.session_id.length,
1375
1405
  ...e.session_id,
1376
- ...D(ue.TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
1406
+ ...W(fe.TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
1377
1407
  n,
1378
1408
  // Extensions length (2 bytes)
1379
- ...D(s.length),
1380
- ...s
1409
+ ...W(i.length),
1410
+ ...i
1381
1411
  ]);
1382
1412
  return new Uint8Array([
1383
- f.ServerHello,
1384
- ...m(a.length),
1413
+ E.ServerHello,
1414
+ ...L(a.length),
1385
1415
  ...a
1386
1416
  ]);
1387
1417
  }
1388
1418
  static serverHelloDone() {
1389
- return new Uint8Array([f.ServerHelloDone, ...m(0)]);
1419
+ return new Uint8Array([E.ServerHelloDone, ...L(0)]);
1390
1420
  }
1391
1421
  /**
1392
1422
  * Server finished message.
@@ -1411,7 +1441,7 @@ class K {
1411
1441
  "SHA-256",
1412
1442
  H(e)
1413
1443
  ), r = new Uint8Array(
1414
- await G(
1444
+ await $(
1415
1445
  t,
1416
1446
  new TextEncoder().encode("server finished"),
1417
1447
  n,
@@ -1420,8 +1450,8 @@ class K {
1420
1450
  )
1421
1451
  );
1422
1452
  return new Uint8Array([
1423
- f.Finished,
1424
- ...m(r.length),
1453
+ E.Finished,
1454
+ ...L(r.length),
1425
1455
  ...r
1426
1456
  ]);
1427
1457
  }
@@ -1429,25 +1459,25 @@ class K {
1429
1459
  return new Uint8Array([1]);
1430
1460
  }
1431
1461
  }
1432
- function Ze(i, e) {
1433
- return Je.generateCertificate(i, e);
1462
+ function nt(s, e) {
1463
+ return rt.generateCertificate(s, e);
1434
1464
  }
1435
- function gt(i) {
1465
+ function bt(s) {
1436
1466
  return `-----BEGIN CERTIFICATE-----
1437
- ${we(
1438
- pe(i.buffer)
1467
+ ${Le(
1468
+ me(s.buffer)
1439
1469
  )}
1440
1470
  -----END CERTIFICATE-----`;
1441
1471
  }
1442
- async function It(i) {
1443
- const e = await crypto.subtle.exportKey("pkcs8", i);
1472
+ async function Rt(s) {
1473
+ const e = await crypto.subtle.exportKey("pkcs8", s);
1444
1474
  return `-----BEGIN PRIVATE KEY-----
1445
- ${we(
1446
- pe(e)
1475
+ ${Le(
1476
+ me(e)
1447
1477
  )}
1448
1478
  -----END PRIVATE KEY-----`;
1449
1479
  }
1450
- class Je {
1480
+ class rt {
1451
1481
  static async generateCertificate(e, t) {
1452
1482
  const n = await crypto.subtle.generateKey(
1453
1483
  {
@@ -1462,13 +1492,13 @@ class Je {
1462
1492
  ), r = await this.signingRequest(
1463
1493
  e,
1464
1494
  n.publicKey
1465
- ), s = await this.sign(
1495
+ ), i = await this.sign(
1466
1496
  r,
1467
1497
  (t == null ? void 0 : t.privateKey) ?? n.privateKey
1468
1498
  );
1469
1499
  return {
1470
1500
  keyPair: n,
1471
- certificate: s,
1501
+ certificate: i,
1472
1502
  tbsCertificate: r,
1473
1503
  tbsDescription: e
1474
1504
  };
@@ -1482,17 +1512,17 @@ class Je {
1482
1512
  t,
1483
1513
  e.buffer
1484
1514
  );
1485
- return o.sequence([
1515
+ return c.sequence([
1486
1516
  new Uint8Array(e.buffer),
1487
1517
  this.signatureAlgorithm("sha256WithRSAEncryption"),
1488
- o.bitString(new Uint8Array(n))
1518
+ c.bitString(new Uint8Array(n))
1489
1519
  ]);
1490
1520
  }
1491
1521
  static async signingRequest(e, t) {
1492
1522
  const n = [];
1493
1523
  return e.keyUsage && n.push(this.keyUsage(e.keyUsage)), e.extKeyUsage && n.push(this.extKeyUsage(e.extKeyUsage)), e.subjectAltNames && n.push(this.subjectAltName(e.subjectAltNames)), e.nsCertType && n.push(this.nsCertType(e.nsCertType)), e.basicConstraints && n.push(
1494
1524
  this.basicConstraints(e.basicConstraints)
1495
- ), o.sequence([
1525
+ ), c.sequence([
1496
1526
  this.version(e.version),
1497
1527
  this.serialNumber(e.serialNumber),
1498
1528
  this.signatureAlgorithm(e.signatureAlgorithm),
@@ -1504,56 +1534,56 @@ class Je {
1504
1534
  ]);
1505
1535
  }
1506
1536
  static version(e = 2) {
1507
- return o.ASN1(
1537
+ return c.ASN1(
1508
1538
  160,
1509
- o.integer(new Uint8Array([e]))
1539
+ c.integer(new Uint8Array([e]))
1510
1540
  );
1511
1541
  }
1512
1542
  static serialNumber(e = crypto.getRandomValues(new Uint8Array(4))) {
1513
- return o.integer(e);
1543
+ return c.integer(e);
1514
1544
  }
1515
1545
  static signatureAlgorithm(e = "sha256WithRSAEncryption") {
1516
- return o.sequence([
1517
- o.objectIdentifier(w(e)),
1518
- o.null()
1546
+ return c.sequence([
1547
+ c.objectIdentifier(y(e)),
1548
+ c.null()
1519
1549
  ]);
1520
1550
  }
1521
1551
  static async subjectPublicKeyInfo(e) {
1522
1552
  return new Uint8Array(await crypto.subtle.exportKey("spki", e));
1523
1553
  }
1524
1554
  static extensions(e) {
1525
- return o.ASN1(163, o.sequence(e));
1555
+ return c.ASN1(163, c.sequence(e));
1526
1556
  }
1527
1557
  static distinguishedName(e) {
1528
1558
  const t = [];
1529
1559
  for (const [n, r] of Object.entries(e)) {
1530
- const s = [
1531
- o.objectIdentifier(w(n))
1560
+ const i = [
1561
+ c.objectIdentifier(y(n))
1532
1562
  ];
1533
1563
  switch (n) {
1534
1564
  case "countryName":
1535
- s.push(o.printableString(r));
1565
+ i.push(c.printableString(r));
1536
1566
  break;
1537
1567
  default:
1538
- s.push(o.utf8String(r));
1568
+ i.push(c.utf8String(r));
1539
1569
  }
1540
- t.push(o.set([o.sequence(s)]));
1570
+ t.push(c.set([c.sequence(i)]));
1541
1571
  }
1542
- return o.sequence(t);
1572
+ return c.sequence(t);
1543
1573
  }
1544
1574
  static validity(e) {
1545
- return o.sequence([
1546
- o.ASN1(
1547
- d.UTCTime,
1575
+ return c.sequence([
1576
+ c.ASN1(
1577
+ f.UTCTime,
1548
1578
  new TextEncoder().encode(
1549
1579
  ie((e == null ? void 0 : e.notBefore) ?? /* @__PURE__ */ new Date())
1550
1580
  )
1551
1581
  ),
1552
- o.ASN1(
1553
- d.UTCTime,
1582
+ c.ASN1(
1583
+ f.UTCTime,
1554
1584
  new TextEncoder().encode(
1555
1585
  ie(
1556
- (e == null ? void 0 : e.notAfter) ?? Qe(/* @__PURE__ */ new Date(), 10)
1586
+ (e == null ? void 0 : e.notAfter) ?? it(/* @__PURE__ */ new Date(), 10)
1557
1587
  )
1558
1588
  )
1559
1589
  )
@@ -1563,63 +1593,63 @@ class Je {
1563
1593
  ca: e = !0,
1564
1594
  pathLenConstraint: t = void 0
1565
1595
  }) {
1566
- const n = [o.boolean(e)];
1596
+ const n = [c.boolean(e)];
1567
1597
  return t !== void 0 && n.push(
1568
- o.integer(new Uint8Array([t]))
1569
- ), o.sequence([
1570
- o.objectIdentifier(w("basicConstraints")),
1571
- o.octetString(o.sequence(n))
1598
+ c.integer(new Uint8Array([t]))
1599
+ ), c.sequence([
1600
+ c.objectIdentifier(y("basicConstraints")),
1601
+ c.octetString(c.sequence(n))
1572
1602
  ]);
1573
1603
  }
1574
1604
  static keyUsage(e) {
1575
1605
  const t = new Uint8Array([0]);
1576
- return e != null && e.digitalSignature && (t[0] |= 1), e != null && e.nonRepudiation && (t[0] |= 2), e != null && e.keyEncipherment && (t[0] |= 4), e != null && e.dataEncipherment && (t[0] |= 8), e != null && e.keyAgreement && (t[0] |= 16), e != null && e.keyCertSign && (t[0] |= 32), e != null && e.cRLSign && (t[0] |= 64), e != null && e.encipherOnly && (t[0] |= 128), e != null && e.decipherOnly && (t[0] |= 64), o.sequence([
1577
- o.objectIdentifier(w("keyUsage")),
1578
- o.boolean(!0),
1606
+ return e != null && e.digitalSignature && (t[0] |= 1), e != null && e.nonRepudiation && (t[0] |= 2), e != null && e.keyEncipherment && (t[0] |= 4), e != null && e.dataEncipherment && (t[0] |= 8), e != null && e.keyAgreement && (t[0] |= 16), e != null && e.keyCertSign && (t[0] |= 32), e != null && e.cRLSign && (t[0] |= 64), e != null && e.encipherOnly && (t[0] |= 128), e != null && e.decipherOnly && (t[0] |= 64), c.sequence([
1607
+ c.objectIdentifier(y("keyUsage")),
1608
+ c.boolean(!0),
1579
1609
  // Critical
1580
- o.octetString(o.bitString(t))
1610
+ c.octetString(c.bitString(t))
1581
1611
  ]);
1582
1612
  }
1583
1613
  static extKeyUsage(e = {}) {
1584
- return o.sequence([
1585
- o.objectIdentifier(w("extKeyUsage")),
1586
- o.boolean(!0),
1614
+ return c.sequence([
1615
+ c.objectIdentifier(y("extKeyUsage")),
1616
+ c.boolean(!0),
1587
1617
  // Critical
1588
- o.octetString(
1589
- o.sequence(
1590
- Object.entries(e).map(([t, n]) => n ? o.objectIdentifier(
1591
- w(t)
1592
- ) : o.null())
1618
+ c.octetString(
1619
+ c.sequence(
1620
+ Object.entries(e).map(([t, n]) => n ? c.objectIdentifier(
1621
+ y(t)
1622
+ ) : c.null())
1593
1623
  )
1594
1624
  )
1595
1625
  ]);
1596
1626
  }
1597
1627
  static nsCertType(e) {
1598
1628
  const t = new Uint8Array([0]);
1599
- return e.client && (t[0] |= 1), e.server && (t[0] |= 2), e.email && (t[0] |= 4), e.objsign && (t[0] |= 8), e.sslCA && (t[0] |= 16), e.emailCA && (t[0] |= 32), e.objCA && (t[0] |= 64), o.sequence([
1600
- o.objectIdentifier(w("nsCertType")),
1601
- o.octetString(t)
1629
+ return e.client && (t[0] |= 1), e.server && (t[0] |= 2), e.email && (t[0] |= 4), e.objsign && (t[0] |= 8), e.sslCA && (t[0] |= 16), e.emailCA && (t[0] |= 32), e.objCA && (t[0] |= 64), c.sequence([
1630
+ c.objectIdentifier(y("nsCertType")),
1631
+ c.octetString(t)
1602
1632
  ]);
1603
1633
  }
1604
1634
  static subjectAltName(e) {
1605
- var s, a;
1606
- const t = ((s = e.dnsNames) == null ? void 0 : s.map((_) => {
1607
- const c = o.ia5String(_);
1608
- return o.contextSpecific(2, c);
1635
+ var i, a;
1636
+ const t = ((i = e.dnsNames) == null ? void 0 : i.map((_) => {
1637
+ const o = c.ia5String(_);
1638
+ return c.contextSpecific(2, o);
1609
1639
  })) || [], n = ((a = e.ipAddresses) == null ? void 0 : a.map((_) => {
1610
- const c = o.ia5String(_);
1611
- return o.contextSpecific(7, c);
1612
- })) || [], r = o.octetString(
1613
- o.sequence([...t, ...n])
1640
+ const o = c.ia5String(_);
1641
+ return c.contextSpecific(7, o);
1642
+ })) || [], r = c.octetString(
1643
+ c.sequence([...t, ...n])
1614
1644
  );
1615
- return o.sequence([
1616
- o.objectIdentifier(w("subjectAltName")),
1617
- o.boolean(!0),
1645
+ return c.sequence([
1646
+ c.objectIdentifier(y("subjectAltName")),
1647
+ c.boolean(!0),
1618
1648
  r
1619
1649
  ]);
1620
1650
  }
1621
1651
  }
1622
- const Xe = {
1652
+ const st = {
1623
1653
  // Algorithm OIDs
1624
1654
  "1.2.840.113549.1.1.1": "rsaEncryption",
1625
1655
  "1.2.840.113549.1.1.4": "md5WithRSAEncryption",
@@ -1729,13 +1759,13 @@ const Xe = {
1729
1759
  "1.3.6.1.5.5.7.3.4": "emailProtection",
1730
1760
  "1.3.6.1.5.5.7.3.8": "timeStamping"
1731
1761
  };
1732
- function w(i) {
1733
- for (const [e, t] of Object.entries(Xe))
1734
- if (t === i)
1762
+ function y(s) {
1763
+ for (const [e, t] of Object.entries(st))
1764
+ if (t === s)
1735
1765
  return e;
1736
- throw new Error(`OID not found for name: ${i}`);
1766
+ throw new Error(`OID not found for name: ${s}`);
1737
1767
  }
1738
- const se = 32, d = {
1768
+ const se = 32, f = {
1739
1769
  Boolean: 1,
1740
1770
  Integer: 2,
1741
1771
  BitString: 3,
@@ -1749,7 +1779,7 @@ const se = 32, d = {
1749
1779
  IA5String: 22,
1750
1780
  UTCTime: 23
1751
1781
  };
1752
- class o {
1782
+ class c {
1753
1783
  // Helper functions for ASN.1 DER encoding
1754
1784
  static length_(e) {
1755
1785
  if (e < 128)
@@ -1759,15 +1789,15 @@ class o {
1759
1789
  const n = [];
1760
1790
  for (; t > 0; )
1761
1791
  n.unshift(t & 255), t >>= 8;
1762
- const r = n.length, s = new Uint8Array(1 + r);
1763
- s[0] = 128 | r;
1792
+ const r = n.length, i = new Uint8Array(1 + r);
1793
+ i[0] = 128 | r;
1764
1794
  for (let a = 0; a < r; a++)
1765
- s[a + 1] = n[a];
1766
- return s;
1795
+ i[a + 1] = n[a];
1796
+ return i;
1767
1797
  }
1768
1798
  }
1769
1799
  static ASN1(e, t) {
1770
- const n = o.length_(t.length), r = new Uint8Array(1 + n.length + t.length);
1800
+ const n = c.length_(t.length), r = new Uint8Array(1 + n.length + t.length);
1771
1801
  return r[0] = e, r.set(n, 1), r.set(t, 1 + n.length), r;
1772
1802
  }
1773
1803
  static integer(e) {
@@ -1778,85 +1808,85 @@ class o {
1778
1808
  const n = new Uint8Array(e.length + 1);
1779
1809
  n[0] = 0, n.set(e, 1), e = n;
1780
1810
  }
1781
- return o.ASN1(d.Integer, e);
1811
+ return c.ASN1(f.Integer, e);
1782
1812
  }
1783
1813
  static bitString(e) {
1784
1814
  const t = new Uint8Array([0]), n = new Uint8Array(t.length + e.length);
1785
- return n.set(t), n.set(e, t.length), o.ASN1(d.BitString, n);
1815
+ return n.set(t), n.set(e, t.length), c.ASN1(f.BitString, n);
1786
1816
  }
1787
1817
  static octetString(e) {
1788
- return o.ASN1(d.OctetString, e);
1818
+ return c.ASN1(f.OctetString, e);
1789
1819
  }
1790
1820
  static null() {
1791
- return o.ASN1(d.Null, new Uint8Array(0));
1821
+ return c.ASN1(f.Null, new Uint8Array(0));
1792
1822
  }
1793
1823
  static objectIdentifier(e) {
1794
1824
  const t = e.split(".").map(Number), r = [t[0] * 40 + t[1]];
1795
- for (let s = 2; s < t.length; s++) {
1796
- let a = t[s];
1825
+ for (let i = 2; i < t.length; i++) {
1826
+ let a = t[i];
1797
1827
  const _ = [];
1798
1828
  do
1799
1829
  _.unshift(a & 127), a >>= 7;
1800
1830
  while (a > 0);
1801
- for (let c = 0; c < _.length - 1; c++)
1802
- _[c] |= 128;
1831
+ for (let o = 0; o < _.length - 1; o++)
1832
+ _[o] |= 128;
1803
1833
  r.push(..._);
1804
1834
  }
1805
- return o.ASN1(d.OID, new Uint8Array(r));
1835
+ return c.ASN1(f.OID, new Uint8Array(r));
1806
1836
  }
1807
1837
  static utf8String(e) {
1808
1838
  const t = new TextEncoder().encode(e);
1809
- return o.ASN1(d.Utf8String, t);
1839
+ return c.ASN1(f.Utf8String, t);
1810
1840
  }
1811
1841
  static printableString(e) {
1812
1842
  const t = new TextEncoder().encode(e);
1813
- return o.ASN1(d.PrintableString, t);
1843
+ return c.ASN1(f.PrintableString, t);
1814
1844
  }
1815
1845
  static sequence(e) {
1816
- return o.ASN1(d.Sequence, H(e));
1846
+ return c.ASN1(f.Sequence, H(e));
1817
1847
  }
1818
1848
  static set(e) {
1819
- return o.ASN1(d.Set, H(e));
1849
+ return c.ASN1(f.Set, H(e));
1820
1850
  }
1821
1851
  static ia5String(e) {
1822
1852
  const t = new TextEncoder().encode(e);
1823
- return o.ASN1(d.IA5String, t);
1853
+ return c.ASN1(f.IA5String, t);
1824
1854
  }
1825
1855
  static contextSpecific(e, t, n = !1) {
1826
1856
  const r = (n ? 160 : 128) | e;
1827
- return o.ASN1(r, t);
1857
+ return c.ASN1(r, t);
1828
1858
  }
1829
1859
  static boolean(e) {
1830
- return o.ASN1(
1831
- d.Boolean,
1860
+ return c.ASN1(
1861
+ f.Boolean,
1832
1862
  new Uint8Array([e ? 255 : 0])
1833
1863
  );
1834
1864
  }
1835
1865
  }
1836
- function pe(i) {
1837
- return btoa(String.fromCodePoint(...new Uint8Array(i)));
1866
+ function me(s) {
1867
+ return btoa(String.fromCodePoint(...new Uint8Array(s)));
1838
1868
  }
1839
- function we(i) {
1869
+ function Le(s) {
1840
1870
  var e;
1841
- return ((e = i.match(/.{1,64}/g)) == null ? void 0 : e.join(`
1842
- `)) || i;
1871
+ return ((e = s.match(/.{1,64}/g)) == null ? void 0 : e.join(`
1872
+ `)) || s;
1843
1873
  }
1844
- function ie(i) {
1845
- const e = i.getUTCFullYear().toString().substr(2), t = R(i.getUTCMonth() + 1), n = R(i.getUTCDate()), r = R(i.getUTCHours()), s = R(i.getUTCMinutes()), a = R(i.getUTCSeconds());
1846
- return `${e}${t}${n}${r}${s}${a}Z`;
1874
+ function ie(s) {
1875
+ const e = s.getUTCFullYear().toString().substr(2), t = U(s.getUTCMonth() + 1), n = U(s.getUTCDate()), r = U(s.getUTCHours()), i = U(s.getUTCMinutes()), a = U(s.getUTCSeconds());
1876
+ return `${e}${t}${n}${r}${i}${a}Z`;
1847
1877
  }
1848
- function R(i) {
1849
- return i.toString().padStart(2, "0");
1878
+ function U(s) {
1879
+ return s.toString().padStart(2, "0");
1850
1880
  }
1851
- function Qe(i, e) {
1852
- const t = new Date(i);
1881
+ function it(s, e) {
1882
+ const t = new Date(s);
1853
1883
  return t.setUTCFullYear(t.getUTCFullYear() + e), t;
1854
1884
  }
1855
- class et extends TransformStream {
1885
+ class at extends TransformStream {
1856
1886
  constructor() {
1857
1887
  let e = new Uint8Array(0), t = "SCAN_CHUNK_SIZE", n = 0;
1858
1888
  super({
1859
- transform(r, s) {
1889
+ transform(r, i) {
1860
1890
  for (e = H([e, r]); e.length > 0; )
1861
1891
  if (t === "SCAN_CHUNK_SIZE") {
1862
1892
  if (e.length < 3)
@@ -1880,18 +1910,18 @@ class et extends TransformStream {
1880
1910
  );
1881
1911
  const _ = new TextDecoder().decode(
1882
1912
  e.slice(0, a)
1883
- ), c = parseInt(_, 16);
1884
- if (e = e.slice(a + 2), c === 0) {
1885
- t = "SCAN_FINAL_CHUNK", s.terminate();
1913
+ ), o = parseInt(_, 16);
1914
+ if (e = e.slice(a + 2), o === 0) {
1915
+ t = "SCAN_FINAL_CHUNK", i.terminate();
1886
1916
  return;
1887
1917
  }
1888
- n = c, t = "SCAN_CHUNK_DATA";
1918
+ n = o, t = "SCAN_CHUNK_DATA";
1889
1919
  } else if (t === "SCAN_CHUNK_DATA") {
1890
1920
  const a = Math.min(
1891
1921
  n,
1892
1922
  e.length
1893
1923
  ), _ = e.slice(0, a);
1894
- e = e.slice(a), n -= a, s.enqueue(_), n === 0 && (t = "SCAN_CHUNK_TRAILER");
1924
+ e = e.slice(a), n -= a, i.enqueue(_), n === 0 && (t = "SCAN_CHUNK_TRAILER");
1895
1925
  } else if (t === "SCAN_CHUNK_TRAILER") {
1896
1926
  if (e.length < 2)
1897
1927
  return;
@@ -1905,15 +1935,15 @@ class et extends TransformStream {
1905
1935
  });
1906
1936
  }
1907
1937
  }
1908
- const tt = (i, e) => ({
1909
- ...i,
1938
+ const _t = (s, e) => ({
1939
+ ...s,
1910
1940
  websocket: {
1911
1941
  url: (t, n, r) => `ws://playground.internal/?${new URLSearchParams({
1912
1942
  host: n,
1913
1943
  port: r
1914
1944
  }).toString()}`,
1915
1945
  subprotocol: "binary",
1916
- decorator: () => class extends nt {
1946
+ decorator: () => class extends ot {
1917
1947
  constructor(t, n) {
1918
1948
  super(t, n, {
1919
1949
  CAroot: e.CAroot,
@@ -1923,15 +1953,15 @@ const tt = (i, e) => ({
1923
1953
  }
1924
1954
  }
1925
1955
  });
1926
- class nt {
1956
+ class ot {
1927
1957
  constructor(e, t, {
1928
1958
  CAroot: n,
1929
1959
  corsProxyUrl: r,
1930
- outputType: s = "messages"
1960
+ outputType: i = "messages"
1931
1961
  } = {}) {
1932
1962
  this.CONNECTING = 0, this.OPEN = 1, this.CLOSING = 2, this.CLOSED = 3, this.readyState = this.CONNECTING, this.binaryType = "blob", this.bufferedAmount = 0, this.extensions = "", this.protocol = "ws", this.host = "", this.port = 0, this.listeners = /* @__PURE__ */ new Map(), this.clientUpstream = new TransformStream(), this.clientUpstreamWriter = this.clientUpstream.writable.getWriter(), this.clientDownstream = new TransformStream(), this.fetchInitiated = !1, this.bufferedBytesFromClient = new Uint8Array(0), this.url = e, this.options = t;
1933
1963
  const a = new URL(e);
1934
- this.host = a.searchParams.get("host"), this.port = parseInt(a.searchParams.get("port"), 10), this.binaryType = "arraybuffer", this.corsProxyUrl = r, this.CAroot = n, s === "messages" && this.clientDownstream.readable.pipeTo(
1964
+ this.host = a.searchParams.get("host"), this.port = parseInt(a.searchParams.get("port"), 10), this.binaryType = "arraybuffer", this.corsProxyUrl = r, this.CAroot = n, i === "messages" && this.clientDownstream.readable.pipeTo(
1935
1965
  new WritableStream({
1936
1966
  write: (_) => {
1937
1967
  this.emit("message", { data: _ });
@@ -1994,7 +2024,7 @@ class nt {
1994
2024
  switch (this.bufferedBytesFromClient = H([
1995
2025
  this.bufferedBytesFromClient,
1996
2026
  new Uint8Array(e)
1997
- ]), st(this.port, this.bufferedBytesFromClient)) {
2027
+ ]), St(this.port, this.bufferedBytesFromClient)) {
1998
2028
  case !1:
1999
2029
  return;
2000
2030
  case "other":
@@ -2013,7 +2043,7 @@ class nt {
2013
2043
  throw new Error(
2014
2044
  "TLS protocol is only supported when the TCPOverFetchWebsocket is instantiated with a CAroot"
2015
2045
  );
2016
- const e = await Ze(
2046
+ const e = await nt(
2017
2047
  {
2018
2048
  subject: {
2019
2049
  commonName: this.host,
@@ -2023,28 +2053,28 @@ class nt {
2023
2053
  issuer: this.CAroot.tbsDescription.subject
2024
2054
  },
2025
2055
  this.CAroot.keyPair
2026
- ), t = new ze();
2056
+ ), t = new et();
2027
2057
  this.clientUpstream.readable.pipeTo(t.clientEnd.upstream.writable).catch(() => {
2028
2058
  }), t.clientEnd.downstream.readable.pipeTo(this.clientDownstream.writable).catch(() => {
2029
2059
  }), await t.TLSHandshake(e.keyPair.privateKey, [
2030
2060
  e.certificate,
2031
2061
  this.CAroot.certificate
2032
2062
  ]);
2033
- const { request: n, expectsContinue: r } = await L.parseHttpRequest(
2063
+ const { request: n, expectsContinue: r } = await p.parseHttpRequest(
2034
2064
  t.serverEnd.upstream.readable,
2035
2065
  this.host,
2036
2066
  "https"
2037
2067
  );
2038
2068
  if (r) {
2039
- const s = t.serverEnd.downstream.writable.getWriter();
2040
- await s.write(
2069
+ const i = t.serverEnd.downstream.writable.getWriter();
2070
+ await i.write(
2041
2071
  new TextEncoder().encode(`HTTP/1.1 100 Continue\r
2042
2072
  \r
2043
2073
  `)
2044
- ), s.releaseLock();
2074
+ ), i.releaseLock();
2045
2075
  }
2046
2076
  try {
2047
- await L.fetchRawResponseBytes(
2077
+ await p.fetchRawResponseBytes(
2048
2078
  n,
2049
2079
  this.corsProxyUrl
2050
2080
  ).pipeTo(t.serverEnd.downstream.writable);
@@ -2052,7 +2082,7 @@ class nt {
2052
2082
  }
2053
2083
  }
2054
2084
  async fetchOverHTTP() {
2055
- const { request: e, expectsContinue: t } = await L.parseHttpRequest(
2085
+ const { request: e, expectsContinue: t } = await p.parseHttpRequest(
2056
2086
  this.clientUpstream.readable,
2057
2087
  this.host,
2058
2088
  "http"
@@ -2066,7 +2096,7 @@ class nt {
2066
2096
  ), n.releaseLock();
2067
2097
  }
2068
2098
  try {
2069
- await L.fetchRawResponseBytes(
2099
+ await p.fetchRawResponseBytes(
2070
2100
  e,
2071
2101
  this.corsProxyUrl
2072
2102
  ).pipeTo(this.clientDownstream.writable);
@@ -2077,7 +2107,7 @@ class nt {
2077
2107
  this.emit("message", { data: new Uint8Array(0) }), this.readyState = this.CLOSING, this.emit("close"), this.readyState = this.CLOSED;
2078
2108
  }
2079
2109
  }
2080
- const rt = [
2110
+ const ct = [
2081
2111
  "GET",
2082
2112
  "POST",
2083
2113
  "HEAD",
@@ -2087,20 +2117,20 @@ const rt = [
2087
2117
  "PUT",
2088
2118
  "TRACE"
2089
2119
  ];
2090
- function st(i, e) {
2120
+ function St(s, e) {
2091
2121
  if (e.length < 8)
2092
2122
  return !1;
2093
- if (i === 443 && e[0] === l.Handshake && // TLS versions between 1.0 and 1.2
2123
+ if (s === 443 && e[0] === C.Handshake && // TLS versions between 1.0 and 1.2
2094
2124
  e[1] === 3 && e[2] >= 1 && e[2] <= 3)
2095
2125
  return "tls";
2096
2126
  const n = new TextDecoder("latin1", {
2097
2127
  fatal: !0
2098
2128
  }).decode(e);
2099
- return rt.some(
2100
- (s) => n.startsWith(s + " ")
2129
+ return ct.some(
2130
+ (i) => n.startsWith(i + " ")
2101
2131
  ) ? "http" : "other";
2102
2132
  }
2103
- class L {
2133
+ class p {
2104
2134
  /**
2105
2135
  * Streams a HTTP response including the status line and headers.
2106
2136
  */
@@ -2110,12 +2140,12 @@ class L {
2110
2140
  var _;
2111
2141
  let r;
2112
2142
  try {
2113
- r = await Re(
2143
+ r = await ve(
2114
2144
  e,
2115
2145
  void 0,
2116
2146
  t
2117
2147
  );
2118
- } catch (c) {
2148
+ } catch (o) {
2119
2149
  n.enqueue(
2120
2150
  new TextEncoder().encode(
2121
2151
  `HTTP/1.1 400 Bad Request\r
@@ -2123,23 +2153,23 @@ Content-Length: 0\r
2123
2153
  \r
2124
2154
  `
2125
2155
  )
2126
- ), n.error(c);
2156
+ ), n.error(o);
2127
2157
  return;
2128
2158
  }
2129
- n.enqueue(L.headersAsBytes(r));
2130
- const s = (_ = r.body) == null ? void 0 : _.getReader();
2131
- if (!s) {
2159
+ n.enqueue(p.headersAsBytes(r));
2160
+ const i = (_ = r.body) == null ? void 0 : _.getReader();
2161
+ if (!i) {
2132
2162
  n.close();
2133
2163
  return;
2134
2164
  }
2135
2165
  const a = new TextEncoder();
2136
2166
  for (; ; ) {
2137
- const { done: c, value: S } = await s.read();
2167
+ const { done: o, value: S } = await i.read();
2138
2168
  if (S && (n.enqueue(
2139
2169
  a.encode(`${S.length.toString(16)}\r
2140
2170
  `)
2141
2171
  ), n.enqueue(S), n.enqueue(a.encode(`\r
2142
- `))), c) {
2172
+ `))), o) {
2143
2173
  n.enqueue(a.encode(`0\r
2144
2174
  \r
2145
2175
  `)), n.close();
@@ -2157,110 +2187,134 @@ Content-Length: 0\r
2157
2187
  const r = [];
2158
2188
  for (const [a, _] of Object.entries(n))
2159
2189
  r.push(`${a}: ${_}`);
2160
- const s = [t, ...r].join(`\r
2190
+ const i = [t, ...r].join(`\r
2161
2191
  `) + `\r
2162
2192
  \r
2163
2193
  `;
2164
- return new TextEncoder().encode(s);
2194
+ return new TextEncoder().encode(i);
2165
2195
  }
2166
2196
  /**
2167
2197
  * Parses a raw, streamed HTTP request into a Request object
2168
2198
  * with known headers and a readable body stream.
2169
2199
  */
2170
2200
  static async parseHttpRequest(e, t, n) {
2171
- let r = new Uint8Array(0), s = !1, a = -1;
2201
+ let r = new Uint8Array(0), i = !1, a = -1;
2172
2202
  const _ = e.getReader();
2173
2203
  for (; a === -1; ) {
2174
- const { done: k, value: P } = await _.read();
2204
+ const { done: k, value: R } = await _.read();
2175
2205
  if (k) {
2176
- s = !0;
2206
+ i = !0;
2177
2207
  break;
2178
2208
  }
2179
- r = H([r, P]), a = it(
2209
+ r = H([r, R]), a = lt(
2180
2210
  r,
2181
2211
  new Uint8Array([13, 10, 13, 10])
2182
2212
  );
2183
2213
  }
2184
2214
  _.releaseLock();
2185
- const c = r.slice(0, a), S = L.parseRequestHeaders(c), C = S.headers.get("Transfer-Encoding") !== null ? "chunked" : "content-length", h = S.headers.get("Content-Length") !== null ? parseInt(S.headers.get("Content-Length"), 10) : void 0, A = r.slice(
2215
+ const o = r.slice(0, a), S = p.parseRequestHeaders(o), l = p.expectsContinue(
2216
+ S.headers
2217
+ ), h = S.headers.get("Transfer-Encoding") !== null ? "chunked" : "content-length", A = S.headers.get("Content-Length") !== null ? parseInt(S.headers.get("Content-Length"), 10) : void 0, u = r.slice(
2186
2218
  a + 4
2187
2219
  /* Skip \r\n\r\n */
2188
2220
  );
2189
- let u;
2190
- if (S.method !== "GET") {
2221
+ let d;
2222
+ if (S.method !== "GET" && S.method !== "HEAD") {
2191
2223
  const k = e.getReader();
2192
- let P = A.length, q = A.slice(-6);
2193
- const me = new TextEncoder().encode(`0\r
2224
+ let R = u.length, q = u.slice(-6);
2225
+ const Ke = new TextEncoder().encode(`0\r
2194
2226
  \r
2195
2227
  `);
2196
- u = new ReadableStream({
2197
- async start(b) {
2198
- A.length > 0 && b.enqueue(A);
2199
- const F = C === "content-length" && h !== void 0 && P >= h;
2200
- (s || F) && b.close();
2228
+ d = new ReadableStream({
2229
+ async start(B) {
2230
+ u.length > 0 && B.enqueue(u);
2231
+ const F = h === "content-length" && A !== void 0 && R >= A;
2232
+ (i || F) && B.close();
2201
2233
  },
2202
- async pull(b) {
2203
- const { done: F, value: I } = await k.read();
2204
- if (P += (I == null ? void 0 : I.length) || 0, I && (b.enqueue(I), q = H([
2234
+ async pull(B) {
2235
+ const { done: F, value: K } = await k.read();
2236
+ if (R += (K == null ? void 0 : K.length) || 0, K && (B.enqueue(K), q = H([
2205
2237
  q,
2206
- I || new Uint8Array()
2207
- ]).slice(-5)), F || C === "content-length" && h !== void 0 && P >= h || C === "chunked" && q.every(
2208
- (Le, ge) => Le === me[ge]
2238
+ K || new Uint8Array()
2239
+ ]).slice(-5)), F || h === "content-length" && A !== void 0 && R >= A || h === "chunked" && q.every(
2240
+ (De, We) => De === Ke[We]
2209
2241
  )) {
2210
- b.close();
2242
+ B.close();
2211
2243
  return;
2212
2244
  }
2213
2245
  }
2214
- }), C === "chunked" && (u = u.pipeThrough(
2215
- new et()
2246
+ }), h === "chunked" && (d = d.pipeThrough(
2247
+ new at()
2216
2248
  ));
2217
2249
  }
2218
- const T = S.headers.get("Host") ?? t, y = new URL(S.path, n + "://" + T);
2250
+ const m = S.headers.get("Host") ?? t, b = new URL(S.path, n + "://" + m), Ie = p.normalizeRequestHeadersForFetch(
2251
+ S.headers
2252
+ );
2219
2253
  return {
2220
- request: new Request(y.toString(), {
2254
+ request: new Request(b.toString(), {
2221
2255
  method: S.method,
2222
- headers: S.headers,
2223
- body: u,
2256
+ headers: Ie,
2257
+ body: d,
2224
2258
  // @ts-expect-error duplex is required for streaming request bodies
2225
- duplex: u ? "half" : void 0
2259
+ duplex: d ? "half" : void 0
2226
2260
  }),
2227
- expectsContinue: S.expectsContinue
2261
+ expectsContinue: l
2228
2262
  };
2229
2263
  }
2230
2264
  static parseRequestHeaders(e) {
2231
- var c;
2232
2265
  const t = new TextDecoder().decode(e), n = t.split(`
2233
- `)[0], [r, s] = n.split(" "), a = new Headers();
2234
- for (const S of t.split(`\r
2266
+ `)[0], [r, i] = n.split(" "), a = new Headers();
2267
+ for (const _ of t.split(`\r
2235
2268
  `).slice(1)) {
2236
- if (S === "")
2269
+ if (_ === "")
2237
2270
  break;
2238
- const C = S.indexOf(":");
2239
- if (C === -1)
2271
+ const o = _.indexOf(":");
2272
+ if (o === -1)
2240
2273
  continue;
2241
- const h = S.slice(0, C).trim(), A = S.slice(C + 1).trimStart();
2242
- h !== "" && a.set(h, A);
2274
+ const S = _.slice(0, o).trim(), l = _.slice(o + 1).trimStart();
2275
+ S !== "" && a.set(S, l);
2243
2276
  }
2244
- const _ = ((c = a.get("Expect")) == null ? void 0 : c.toLowerCase()) === "100-continue";
2245
- return a.delete("Expect"), { method: r, path: s, headers: a, expectsContinue: _ };
2277
+ return { method: r, path: i, headers: a };
2278
+ }
2279
+ static expectsContinue(e) {
2280
+ var t;
2281
+ return ((t = e.get("Expect")) == null ? void 0 : t.toLowerCase()) === "100-continue";
2282
+ }
2283
+ static normalizeRequestHeadersForFetch(e) {
2284
+ const t = new Headers(e);
2285
+ for (const n of [
2286
+ "Connection",
2287
+ "Content-Length",
2288
+ "Expect",
2289
+ "Host",
2290
+ "Keep-Alive",
2291
+ "Proxy-Authenticate",
2292
+ "Proxy-Authorization",
2293
+ "TE",
2294
+ "Trailer",
2295
+ "Transfer-Encoding",
2296
+ "Upgrade"
2297
+ ])
2298
+ t.delete(n);
2299
+ return t;
2246
2300
  }
2247
2301
  }
2248
- function it(i, e) {
2249
- const t = i.length, n = e.length, r = t - n;
2250
- for (let s = 0; s <= r; s++) {
2302
+ function lt(s, e) {
2303
+ const t = s.length, n = e.length, r = t - n;
2304
+ for (let i = 0; i <= r; i++) {
2251
2305
  let a = !0;
2252
2306
  for (let _ = 0; _ < n; _++)
2253
- if (i[s + _] !== e[_]) {
2307
+ if (s[i + _] !== e[_]) {
2254
2308
  a = !1;
2255
2309
  break;
2256
2310
  }
2257
2311
  if (a)
2258
- return s;
2312
+ return i;
2259
2313
  }
2260
2314
  return -1;
2261
2315
  }
2262
- async function at(i = oe) {
2263
- switch (i) {
2316
+ async function ht(s = Se) {
2317
+ switch (s) {
2264
2318
  case "8.5":
2265
2319
  return (await import("@php-wasm/web-8-5")).getIntlExtensionPath();
2266
2320
  case "8.4":
@@ -2276,19 +2330,25 @@ async function at(i = oe) {
2276
2330
  case "7.4":
2277
2331
  return (await import("@php-wasm/web-7-4")).getIntlExtensionPath();
2278
2332
  }
2279
- throw new Error(`Unsupported PHP version ${i}`);
2333
+ throw new Error(`Unsupported PHP version ${s}`);
2280
2334
  }
2281
- async function _t(i, e, t, n = []) {
2335
+ async function Ct(s, e, t, n = []) {
2282
2336
  if (!n.length)
2283
2337
  return t;
2284
2338
  const r = await Promise.all(
2285
2339
  n.map(
2286
- (s) => ot(i, e, s)
2340
+ (i) => ut(s, e, i)
2287
2341
  )
2288
2342
  );
2289
- return Ie(t, r);
2343
+ return Pe(t, r);
2290
2344
  }
2291
- async function ot(i, e, t) {
2345
+ async function ut(s, e, t) {
2346
+ if (le(s))
2347
+ throw new Error(
2348
+ `Extensions are not available for legacy PHP ${s}.`
2349
+ );
2350
+ if (be(s))
2351
+ throw new Error("Extensions are not available for PHP next.");
2292
2352
  if (typeof t == "object" && "source" in t) {
2293
2353
  if (e === "asyncify")
2294
2354
  throw new Error(
@@ -2296,20 +2356,20 @@ async function ot(i, e, t) {
2296
2356
  );
2297
2357
  return await Y({
2298
2358
  ...t,
2299
- phpVersion: i
2359
+ phpVersion: s
2300
2360
  });
2301
2361
  }
2302
2362
  const n = typeof t == "string" ? t : t.name;
2303
2363
  if (n !== "intl")
2304
2364
  throw new Error(`Unknown bundled PHP web extension: ${String(n)}.`);
2305
- const r = Be(fetch), s = await at(i), a = (await import("../intl/shared/icu.dat")).default, [_, c] = await Promise.all(
2306
- [s, a].map(async (S) => {
2307
- const C = await r(S);
2308
- if (!C.ok)
2365
+ const r = Me(fetch), i = await ht(s), a = (await import("./shared/icu.dat")).default, [_, o] = await Promise.all(
2366
+ [i, a].map(async (S) => {
2367
+ const l = await r(S);
2368
+ if (!l.ok)
2309
2369
  throw new Error(
2310
- `Failed to fetch bundled PHP web extension asset: ${C.url || S} (${C.status} ${C.statusText}).`
2370
+ `Failed to fetch bundled PHP web extension asset: ${l.url || S} (${l.status} ${l.statusText}).`
2311
2371
  );
2312
- return await C.arrayBuffer();
2372
+ return await l.arrayBuffer();
2313
2373
  })
2314
2374
  );
2315
2375
  return await Y({
@@ -2318,21 +2378,21 @@ async function ot(i, e, t) {
2318
2378
  name: "intl",
2319
2379
  bytes: new Uint8Array(_)
2320
2380
  },
2321
- phpVersion: i,
2381
+ phpVersion: s,
2322
2382
  env: {
2323
2383
  ICU_DATA: "/internal/shared"
2324
2384
  },
2325
2385
  extraFiles: {
2326
2386
  files: {
2327
2387
  // The Intl extension looks for the hard-coded ICU data name.
2328
- "/internal/shared/icudt74l.dat": new Uint8Array(c)
2388
+ "/internal/shared/icudt74l.dat": new Uint8Array(o)
2329
2389
  }
2330
2390
  }
2331
2391
  });
2332
2392
  }
2333
- const ct = () => ({
2393
+ const At = () => ({
2334
2394
  websocket: {
2335
- decorator: (i) => class extends i {
2395
+ decorator: (s) => class extends s {
2336
2396
  constructor() {
2337
2397
  try {
2338
2398
  super();
@@ -2345,71 +2405,71 @@ const ct = () => ({
2345
2405
  }
2346
2406
  }
2347
2407
  });
2348
- async function Dt(i, e = {}) {
2349
- var c;
2408
+ async function Ut(s, e = {}) {
2409
+ var o;
2350
2410
  "setImmediate" in globalThis || (globalThis.setImmediate = (S) => setTimeout(S, 0));
2351
- const t = await Ue() ? "jspi" : "asyncify";
2411
+ const t = await Ne() ? "jspi" : "asyncify";
2352
2412
  let n = {
2353
- ...ct(),
2413
+ ...At(),
2354
2414
  ...e.emscriptenOptions || {},
2355
2415
  phpWasmAsyncMode: t
2356
2416
  };
2357
- e.tcpOverFetch && (n = tt(
2417
+ e.tcpOverFetch && (n = _t(
2358
2418
  n,
2359
2419
  e.tcpOverFetch
2360
2420
  ));
2361
- const r = Ke(i), s = [...e.extensions ?? []];
2362
- if (e.withIntl && !St(s, "intl") && s.push("intl"), r) {
2363
- const S = await n, C = S.preRun || [];
2421
+ const r = le(s), i = [...e.extensions ?? []];
2422
+ if (e.withIntl && !Ht(i, "intl") && i.push("intl"), r) {
2423
+ const S = await n, l = S.preRun || [];
2364
2424
  n = {
2365
2425
  ...S,
2366
- preRun: [...C, De()]
2426
+ preRun: [...l, Re()]
2367
2427
  };
2368
2428
  }
2369
- if (r && s.length)
2429
+ if (r && i.length)
2370
2430
  throw new Error(
2371
- `Extensions are not available for legacy PHP ${i}.`
2431
+ `Extensions are not available for legacy PHP ${s}.`
2372
2432
  );
2373
- r || (n = _t(
2374
- i,
2433
+ r || (n = Ct(
2434
+ s,
2375
2435
  t,
2376
2436
  await n,
2377
- s
2437
+ i
2378
2438
  ));
2379
2439
  const [a, _] = await Promise.all([
2380
- xe(i),
2440
+ je(s, t),
2381
2441
  n
2382
2442
  ]);
2383
- return (c = e.onPhpLoaderModuleLoaded) == null || c.call(e, a), await We(a, _);
2443
+ return (o = e.onPhpLoaderModuleLoaded) == null || o.call(e, a), await Be(a, _);
2384
2444
  }
2385
- function St(i, e) {
2386
- return i.some((t) => typeof t == "string" ? t === e : !("source" in t) && t.name === e);
2445
+ function Ht(s, e) {
2446
+ return s.some((t) => typeof t == "string" ? t === e : !("source" in t) && t.name === e);
2387
2447
  }
2388
- function Wt(i, e) {
2448
+ function xt(s, e) {
2389
2449
  window.addEventListener("message", (t) => {
2390
- t.source === i.contentWindow && (e && t.origin !== e || typeof t.data != "object" || t.data.type !== "relay" || window.parent.postMessage(t.data, "*"));
2450
+ t.source === s.contentWindow && (e && t.origin !== e || typeof t.data != "object" || t.data.type !== "relay" || window.parent.postMessage(t.data, "*"));
2391
2451
  }), window.addEventListener("message", (t) => {
2392
2452
  var n;
2393
- t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (n = i == null ? void 0 : i.contentWindow) == null || n.postMessage(t.data));
2453
+ t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (n = s == null ? void 0 : s.contentWindow) == null || n.postMessage(t.data));
2394
2454
  });
2395
2455
  }
2396
- async function Pt(i) {
2397
- const e = new Worker(i, { type: "module" });
2456
+ async function vt(s) {
2457
+ const e = new Worker(s, { type: "module" });
2398
2458
  return new Promise((t, n) => {
2399
- e.onerror = (s) => {
2459
+ e.onerror = (i) => {
2400
2460
  const a = new Error(
2401
- `WebWorker failed to load at ${i}. ${s.message ? `Original error: ${s.message}` : ""}`
2461
+ `WebWorker failed to load at ${s}. ${i.message ? `Original error: ${i.message}` : ""}`
2402
2462
  );
2403
- a.filename = s.filename, n(a);
2463
+ a.filename = i.filename, n(a);
2404
2464
  };
2405
- function r(s) {
2406
- s.data === "worker-script-started" && (t(e), e.removeEventListener("message", r));
2465
+ function r(i) {
2466
+ i.data === "worker-script-started" && (t(e), e.removeEventListener("message", r));
2407
2467
  }
2408
2468
  e.addEventListener("message", r);
2409
2469
  });
2410
2470
  }
2411
- const Ct = 1e3;
2412
- function bt(i, e = { initialSync: {} }) {
2471
+ const dt = 1e3;
2472
+ function Mt(s, e = { initialSync: {} }) {
2413
2473
  return e = {
2414
2474
  ...e,
2415
2475
  initialSync: {
@@ -2417,45 +2477,72 @@ function bt(i, e = { initialSync: {} }) {
2417
2477
  direction: e.initialSync.direction ?? "opfs-to-memfs"
2418
2478
  }
2419
2479
  }, async function(t, n, r) {
2420
- var a;
2421
- e.initialSync.direction === "opfs-to-memfs" ? (M.fileExists(n, r) && M.rmdir(n, r), M.mkdir(n, r), await lt(n, i, r)) : await ye(
2422
- n,
2423
- i,
2424
- r,
2425
- e.initialSync.onProgress
2426
- );
2427
- const s = At(t, i, r);
2428
- return (a = e.onMount) == null || a.call(e, s), s.unmount;
2480
+ var i, a, _, o;
2481
+ if (e.initialSync.direction === "opfs-to-memfs") {
2482
+ v.fileExists(n, r) && v.rmdir(n, r), v.mkdir(n, r), await ft(n, s, r);
2483
+ const S = ae(t, s, r);
2484
+ return (i = e.onMount) == null || i.call(e, S), S.unmount;
2485
+ } else {
2486
+ const S = ae(t, s, r);
2487
+ (a = e.onMount) == null || a.call(e, S);
2488
+ let l;
2489
+ try {
2490
+ await ge(
2491
+ n,
2492
+ s,
2493
+ r,
2494
+ async (h) => {
2495
+ var A, u;
2496
+ l = {
2497
+ ...h,
2498
+ phase: "copying"
2499
+ }, await ((u = (A = e.initialSync).onProgress) == null ? void 0 : u.call(A, l));
2500
+ }
2501
+ ), await ((o = (_ = e.initialSync).onProgress) == null ? void 0 : o.call(_, {
2502
+ files: (l == null ? void 0 : l.files) ?? 0,
2503
+ total: (l == null ? void 0 : l.total) ?? 0,
2504
+ phase: "flushing"
2505
+ })), S.flush().catch((h) => {
2506
+ g.error("OPFS flush failed after initial sync", {
2507
+ error: h,
2508
+ vfsMountPoint: r
2509
+ });
2510
+ });
2511
+ } catch (h) {
2512
+ throw await S.unmount(), h;
2513
+ }
2514
+ return S.unmount;
2515
+ }
2429
2516
  };
2430
2517
  }
2431
- async function lt(i, e, t) {
2432
- M.mkdir(i, t);
2433
- const n = new Pe({
2518
+ async function ft(s, e, t) {
2519
+ v.mkdir(s, t);
2520
+ const n = new Ue({
2434
2521
  concurrency: 40
2435
- }), r = [], s = [
2522
+ }), r = [], i = [
2436
2523
  [e, t]
2437
2524
  ];
2438
- for (; s.length > 0; ) {
2439
- const [a, _] = s.pop();
2440
- for await (const c of a.values()) {
2525
+ for (; i.length > 0; ) {
2526
+ const [a, _] = i.pop();
2527
+ for await (const o of a.values()) {
2441
2528
  const S = n.run(async () => {
2442
- const C = ce(
2529
+ const l = he(
2443
2530
  _,
2444
- c.name
2531
+ o.name
2445
2532
  );
2446
- if (c.kind === "directory") {
2533
+ if (o.kind === "directory") {
2447
2534
  try {
2448
- i.mkdir(C);
2535
+ s.mkdir(l);
2449
2536
  } catch (h) {
2450
2537
  if ((h == null ? void 0 : h.errno) !== 20)
2451
- throw B.error(h), h;
2538
+ throw g.error(h), h;
2452
2539
  }
2453
- s.push([c, C]);
2454
- } else if (c.kind === "file") {
2455
- const h = await c.getFile(), A = new Uint8Array(await h.arrayBuffer());
2456
- i.createDataFile(
2540
+ i.push([o, l]);
2541
+ } else if (o.kind === "file") {
2542
+ const h = await o.getFile(), A = new Uint8Array(await h.arrayBuffer());
2543
+ s.createDataFile(
2457
2544
  _,
2458
- c.name,
2545
+ o.name,
2459
2546
  A,
2460
2547
  !0,
2461
2548
  !0,
@@ -2466,39 +2553,43 @@ async function lt(i, e, t) {
2466
2553
  });
2467
2554
  r.push(S);
2468
2555
  }
2469
- for (; s.length === 0 && r.length > 0; )
2556
+ for (; i.length === 0 && r.length > 0; )
2470
2557
  await Promise.any(r);
2471
2558
  }
2472
2559
  }
2473
- async function ye(i, e, t, n) {
2474
- i.mkdirTree(t);
2560
+ async function ge(s, e, t, n) {
2561
+ s.mkdirTree(t);
2475
2562
  const r = [];
2476
- async function s(C, h) {
2563
+ async function i(l, h) {
2477
2564
  await Promise.all(
2478
- i.readdir(C).filter(
2565
+ s.readdir(l).filter(
2479
2566
  (A) => A !== "." && A !== ".."
2480
2567
  ).map(async (A) => {
2481
- const u = ce(C, A);
2482
- if (!ht(i, u)) {
2568
+ const u = he(l, A);
2569
+ if (!Et(s, u)) {
2483
2570
  r.push([h, u, A]);
2484
2571
  return;
2485
2572
  }
2486
- const T = await h.getDirectoryHandle(A, {
2573
+ const d = await h.getDirectoryHandle(A, {
2487
2574
  create: !0
2488
2575
  });
2489
- return await s(u, T);
2576
+ return await i(u, d);
2490
2577
  })
2491
2578
  );
2492
2579
  }
2493
- await s(t, e);
2580
+ await i(t, e);
2494
2581
  let a = 0;
2495
- const _ = n && dt(n, 100), c = 100, S = /* @__PURE__ */ new Set();
2582
+ await (n == null ? void 0 : n({
2583
+ files: a,
2584
+ total: r.length
2585
+ }));
2586
+ const _ = n && wt(n, 100), o = 100, S = /* @__PURE__ */ new Set();
2496
2587
  try {
2497
- for (const [C, h, A] of r) {
2498
- const u = $(
2499
- C,
2588
+ for (const [l, h, A] of r) {
2589
+ const u = G(
2590
+ l,
2500
2591
  A,
2501
- i,
2592
+ s,
2502
2593
  h
2503
2594
  ).then(() => {
2504
2595
  a++, S.delete(u), _ == null || _({
@@ -2506,7 +2597,7 @@ async function ye(i, e, t, n) {
2506
2597
  total: r.length
2507
2598
  });
2508
2599
  });
2509
- S.add(u), S.size >= c && (await Promise.race(S), _ == null || _({
2600
+ S.add(u), S.size >= o && (await Promise.race(S), _ == null || _({
2510
2601
  files: a,
2511
2602
  total: r.length
2512
2603
  }));
@@ -2514,11 +2605,15 @@ async function ye(i, e, t, n) {
2514
2605
  } finally {
2515
2606
  await Promise.allSettled(S);
2516
2607
  }
2608
+ _ == null || _.cancel(), await (n == null ? void 0 : n({
2609
+ files: r.length,
2610
+ total: r.length
2611
+ }));
2517
2612
  }
2518
- function ht(i, e) {
2519
- return i.isDir(i.lookupPath(e, { follow: !0 }).node.mode);
2613
+ function Et(s, e) {
2614
+ return s.isDir(s.lookupPath(e, { follow: !0 }).node.mode);
2520
2615
  }
2521
- async function $(i, e, t, n) {
2616
+ async function G(s, e, t, n) {
2522
2617
  let r;
2523
2618
  try {
2524
2619
  r = t.readFile(n, {
@@ -2527,12 +2622,12 @@ async function $(i, e, t, n) {
2527
2622
  } catch {
2528
2623
  return;
2529
2624
  }
2530
- const s = await i.getFileHandle(e, { create: !0 }), a = s.createWritable !== void 0 ? (
2625
+ const i = await s.getFileHandle(e, { create: !0 }), a = i.createWritable !== void 0 ? (
2531
2626
  // Google Chrome, Firefox, probably more browsers
2532
- await s.createWritable()
2627
+ await i.createWritable()
2533
2628
  ) : (
2534
2629
  // Safari
2535
- await s.createSyncAccessHandle()
2630
+ await i.createSyncAccessHandle()
2536
2631
  );
2537
2632
  try {
2538
2633
  await a.truncate(0), await a.write(r);
@@ -2540,35 +2635,35 @@ async function $(i, e, t, n) {
2540
2635
  await a.close();
2541
2636
  }
2542
2637
  }
2543
- function At(i, e, t, n = {}) {
2544
- const r = [], s = ve(i, t, (u) => {
2638
+ function ae(s, e, t, n = {}) {
2639
+ const r = [], i = ke(s, t, (u) => {
2545
2640
  r.push(u);
2546
- }), a = new ut(i, e, t);
2641
+ }), a = new Tt(s, e, t);
2547
2642
  let _;
2548
- function c() {
2643
+ function o() {
2549
2644
  return _ === void 0 && (_ = h().finally(() => {
2550
2645
  _ = void 0;
2551
2646
  })), _;
2552
2647
  }
2553
2648
  async function S() {
2554
2649
  try {
2555
- await c();
2650
+ await o();
2556
2651
  } finally {
2557
- s(), i.removeEventListener("request.end", C), i.removeEventListener("filesystem.write", C);
2652
+ i(), s.removeEventListener("request.end", l), s.removeEventListener("filesystem.write", l);
2558
2653
  }
2559
2654
  }
2560
- function C() {
2561
- c().catch((u) => {
2562
- B.error(u);
2655
+ function l() {
2656
+ o().catch((u) => {
2657
+ g.error(u);
2563
2658
  });
2564
2659
  }
2565
2660
  async function h() {
2566
- const u = n.maxFlushPasses ?? Ct;
2567
- for (let T = 0; r.length > 0; T++) {
2568
- if (T >= u) {
2569
- const y = r.length, U = y === 1 ? `${y} journal entry remains` : `${y} journal entries remain`;
2661
+ const u = n.maxFlushPasses ?? dt;
2662
+ for (let d = 0; r.length > 0; d++) {
2663
+ if (d >= u) {
2664
+ const m = r.length, b = m === 1 ? `${m} journal entry remains` : `${m} journal entries remain`;
2570
2665
  throw new Error(
2571
- `OPFS flush for "${t}" did not settle after ${u} journal batches; ${U}. This can happen when filesystem writes are continuously enqueued while flushing.`
2666
+ `OPFS flush for "${t}" did not settle after ${u} journal batches; ${b}. This can happen when filesystem writes are continuously enqueued while flushing.`
2572
2667
  );
2573
2668
  }
2574
2669
  await A();
@@ -2577,32 +2672,32 @@ function At(i, e, t, n = {}) {
2577
2672
  async function A() {
2578
2673
  if (r.length === 0)
2579
2674
  return;
2580
- const u = await i.semaphore.acquire(), T = [...r];
2581
- r.splice(0, T.length);
2582
- const y = Me(T);
2675
+ const u = await s.semaphore.acquire(), d = [...r];
2676
+ r.splice(0, d.length);
2677
+ const m = qe(d);
2583
2678
  try {
2584
- for (const U of y)
2585
- await a.processEntry(U);
2679
+ for (const b of m)
2680
+ await a.processEntry(b);
2586
2681
  } finally {
2587
2682
  u();
2588
2683
  }
2589
2684
  }
2590
- return i.addEventListener("request.end", C), i.addEventListener("filesystem.write", C), {
2591
- flush: c,
2685
+ return s.addEventListener("request.end", l), s.addEventListener("filesystem.write", l), {
2686
+ flush: o,
2592
2687
  unmount: S
2593
2688
  };
2594
2689
  }
2595
- class ut {
2690
+ class Tt {
2596
2691
  constructor(e, t, n) {
2597
- this.php = e, this.opfs = t, this.memfsRoot = ae(n);
2692
+ this.php = e, this.opfs = t, this.memfsRoot = _e(n);
2598
2693
  }
2599
2694
  toOpfsPath(e) {
2600
- return ae(e.substring(this.memfsRoot.length));
2695
+ return _e(e.substring(this.memfsRoot.length));
2601
2696
  }
2602
2697
  async processEntry(e) {
2603
2698
  if (!e.path.startsWith(this.memfsRoot) || e.path === this.memfsRoot)
2604
2699
  return;
2605
- const t = this.toOpfsPath(e.path), n = await _e(this.opfs, t), r = Ht(t);
2700
+ const t = this.toOpfsPath(e.path), n = await oe(this.opfs, t), r = pt(t);
2606
2701
  if (r)
2607
2702
  try {
2608
2703
  if (e.operation === "DELETE")
@@ -2619,16 +2714,16 @@ class ut {
2619
2714
  create: !0
2620
2715
  });
2621
2716
  else if (e.operation === "WRITE")
2622
- await $(
2717
+ await G(
2623
2718
  n,
2624
2719
  r,
2625
2720
  this.php[O].FS,
2626
2721
  e.path
2627
2722
  );
2628
2723
  else if (e.operation === "RENAME" && e.toPath.startsWith(this.memfsRoot)) {
2629
- const s = this.toOpfsPath(e.toPath), a = await _e(
2724
+ const i = this.toOpfsPath(e.toPath), a = await oe(
2630
2725
  this.opfs,
2631
- s
2726
+ i
2632
2727
  );
2633
2728
  if (e.nodeType === "directory") {
2634
2729
  const _ = await a.getDirectoryHandle(
@@ -2637,7 +2732,7 @@ class ut {
2637
2732
  create: !0
2638
2733
  }
2639
2734
  );
2640
- await ye(
2735
+ await ge(
2641
2736
  this.php[O].FS,
2642
2737
  _,
2643
2738
  e.toPath
@@ -2649,62 +2744,77 @@ class ut {
2649
2744
  await n.removeEntry(r);
2650
2745
  } catch {
2651
2746
  }
2652
- await $(
2747
+ await G(
2653
2748
  a,
2654
- be(s),
2749
+ xe(i),
2655
2750
  this.php[O].FS,
2656
2751
  e.toPath
2657
2752
  );
2658
2753
  }
2659
2754
  }
2660
- } catch (s) {
2661
- throw B.log({ entry: e, name: r }), B.error(s), s;
2755
+ } catch (i) {
2756
+ throw g.log({ entry: e, name: r }), g.error(i), i;
2662
2757
  }
2663
2758
  }
2664
2759
  }
2665
- function ae(i) {
2666
- return i.replace(/\/$/, "").replace(/\/\/+/g, "/");
2760
+ function _e(s) {
2761
+ return s.replace(/\/$/, "").replace(/\/\/+/g, "/");
2667
2762
  }
2668
- function Ht(i) {
2669
- return i.substring(i.lastIndexOf("/") + 1);
2763
+ function pt(s) {
2764
+ return s.substring(s.lastIndexOf("/") + 1);
2670
2765
  }
2671
- async function _e(i, e) {
2766
+ async function oe(s, e) {
2672
2767
  const t = e.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
2673
2768
  if (!t)
2674
- return i;
2769
+ return s;
2675
2770
  const n = t.split("/");
2676
- let r = i;
2677
- for (let s = 0; s < n.length - 1; s++) {
2678
- const a = n[s];
2771
+ let r = s;
2772
+ for (let i = 0; i < n.length - 1; i++) {
2773
+ const a = n[i];
2679
2774
  r = await r.getDirectoryHandle(a, { create: !0 });
2680
2775
  }
2681
2776
  return r;
2682
2777
  }
2683
- function dt(i, e) {
2778
+ function wt(s, e) {
2684
2779
  let t = 0, n, r;
2685
- return function(...a) {
2686
- r = a;
2687
- const _ = Date.now() - t;
2780
+ const i = function(..._) {
2781
+ r = _;
2782
+ const o = Date.now() - t;
2688
2783
  if (n === void 0) {
2689
- const c = Math.max(0, e - _);
2784
+ const S = Math.max(0, e - o);
2690
2785
  n = setTimeout(() => {
2691
- n = void 0, t = Date.now(), i(...r);
2692
- }, c);
2786
+ n = void 0, t = Date.now();
2787
+ const l = r;
2788
+ r = void 0;
2789
+ try {
2790
+ Promise.resolve(s(...l)).catch(
2791
+ ce
2792
+ );
2793
+ } catch (h) {
2794
+ ce(h);
2795
+ }
2796
+ }, S);
2693
2797
  }
2694
2798
  };
2799
+ return i.cancel = () => {
2800
+ n !== void 0 && clearTimeout(n), n = void 0, r = void 0;
2801
+ }, i;
2802
+ }
2803
+ function ce(s) {
2804
+ g.error("Throttled progress callback failed", { error: s });
2695
2805
  }
2696
2806
  export {
2697
- xt as FirewallInterferenceError,
2698
- gt as certificateToPEM,
2699
- Ut as consumeAPI,
2700
- bt as createDirectoryHandleMountHandler,
2701
- vt as exposeAPI,
2702
- Nt as fetchWithCorsProxy,
2703
- Ze as generateCertificate,
2704
- xe as getPHPLoaderModule,
2705
- Dt as loadWebRuntime,
2706
- It as privateKeyToPEM,
2707
- Wt as setupPostMessageRelay,
2708
- Pt as spawnPHPWorkerThread
2807
+ jt as FirewallInterferenceError,
2808
+ bt as certificateToPEM,
2809
+ qt as consumeAPI,
2810
+ Mt as createDirectoryHandleMountHandler,
2811
+ Ft as exposeAPI,
2812
+ $t as fetchWithCorsProxy,
2813
+ nt as generateCertificate,
2814
+ je as getPHPLoaderModule,
2815
+ Ut as loadWebRuntime,
2816
+ Rt as privateKeyToPEM,
2817
+ xt as setupPostMessageRelay,
2818
+ vt as spawnPHPWorkerThread
2709
2819
  };
2710
2820
  //# sourceMappingURL=index.js.map