@php-wasm/web 3.1.20 → 3.1.22

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,12 +1,13 @@
1
- import { LatestSupportedPHPVersion as G, FSHelpers as w, loadPHPRuntime as me, __private__dont__use as F } from "@php-wasm/universal";
2
- import { consumeAPI as gt, exposeAPI as It } from "@php-wasm/universal";
3
- import { concatArrayBuffers as R, concatUint8Arrays as u, Semaphore as ge, joinPaths as ae, basename as Ie } from "@php-wasm/util";
4
- import { logger as U } from "@php-wasm/logger";
5
- import { fetchWithCorsProxy as Ke } from "@php-wasm/web-service-worker";
6
- import { FirewallInterferenceError as Dt, fetchWithCorsProxy as Wt } from "@php-wasm/web-service-worker";
7
- import { createMemoizedFetch as De } from "@wp-playground/common";
8
- import { journalFSEvents as We, normalizeFilesystemOperations as be } from "@php-wasm/fs-journal";
9
- async function Pe(i = G) {
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) {
10
11
  switch (i) {
11
12
  case "8.5":
12
13
  return (await import("@php-wasm/web-8-5")).getPHPLoaderModule();
@@ -22,27 +23,29 @@ async function Pe(i = G) {
22
23
  return (await import("@php-wasm/web-8-0")).getPHPLoaderModule();
23
24
  case "7.4":
24
25
  return (await import("@php-wasm/web-7-4")).getPHPLoaderModule();
26
+ case "5.2":
27
+ return (await import("@php-wasm/web-5-2")).getPHPLoaderModule();
25
28
  }
26
29
  throw new Error(`Unsupported PHP version ${i}`);
27
30
  }
28
- function f(i) {
31
+ function p(i) {
29
32
  return Object.fromEntries(Object.entries(i).map(([e, t]) => [t, e]));
30
33
  }
31
- function K(i) {
34
+ function D(i) {
32
35
  return new Uint8Array([i >> 8 & 255, i & 255]);
33
36
  }
34
- function L(i) {
37
+ function m(i) {
35
38
  return new Uint8Array([
36
39
  i >> 16 & 255,
37
40
  i >> 8 & 255,
38
41
  i & 255
39
42
  ]);
40
43
  }
41
- function z(i) {
44
+ function Z(i) {
42
45
  const e = new ArrayBuffer(8);
43
46
  return new DataView(e).setBigUint64(0, BigInt(i), !1), new Uint8Array(e);
44
47
  }
45
- class m {
48
+ class g {
46
49
  constructor(e) {
47
50
  this.offset = 0, this.buffer = e, this.view = new DataView(e);
48
51
  }
@@ -66,7 +69,7 @@ class m {
66
69
  return this.offset >= this.buffer.byteLength;
67
70
  }
68
71
  }
69
- class x {
72
+ class N {
70
73
  constructor(e) {
71
74
  this.offset = 0, this.buffer = new ArrayBuffer(e), this.uint8Array = new Uint8Array(this.buffer), this.view = new DataView(this.buffer);
72
75
  }
@@ -83,7 +86,7 @@ class x {
83
86
  this.uint8Array.set(e, this.offset), this.offset += e.length;
84
87
  }
85
88
  }
86
- const D = {
89
+ const W = {
87
90
  server_name: 0,
88
91
  max_fragment_length: 1,
89
92
  client_certificate_url: 2,
@@ -138,10 +141,10 @@ const D = {
138
141
  transparency_info: 52,
139
142
  connection_id: 54,
140
143
  renegotiation_info: 65281
141
- }, Re = f(D), _e = {
144
+ }, Ne = p(W), Se = {
142
145
  host_name: 0
143
- }, Be = f(_e);
144
- class oe {
146
+ }, ke = p(Se);
147
+ class Ce {
145
148
  static decodeFromClient(e) {
146
149
  const t = new DataView(e.buffer);
147
150
  let n = 0;
@@ -153,13 +156,13 @@ class oe {
153
156
  n += 1;
154
157
  const _ = t.getUint16(n);
155
158
  n += 2;
156
- const S = e.slice(n, n + _);
159
+ const c = e.slice(n, n + _);
157
160
  switch (n += _, a) {
158
- case _e.host_name:
161
+ case Se.host_name:
159
162
  s.push({
160
- name_type: Be[a],
163
+ name_type: ke[a],
161
164
  name: {
162
- host_name: new TextDecoder().decode(S)
165
+ host_name: new TextDecoder().decode(c)
163
166
  }
164
167
  });
165
168
  break;
@@ -185,16 +188,16 @@ class oe {
185
188
  throw new Error(
186
189
  "Encoding non-empty lists for ClientHello is not supported yet. Only empty lists meant for ServerHello are supported today."
187
190
  );
188
- const t = new x(4);
189
- return t.writeUint16(D.server_name), t.writeUint16(0), t.uint8Array;
191
+ const t = new N(4);
192
+ return t.writeUint16(W.server_name), t.writeUint16(0), t.uint8Array;
190
193
  }
191
194
  }
192
- const ce = {
195
+ const le = {
193
196
  uncompressed: 0,
194
197
  ansiX962_compressed_prime: 1,
195
198
  ansiX962_compressed_char2: 2
196
- }, Y = f(ce);
197
- class Se {
199
+ }, X = p(le);
200
+ class he {
198
201
  /**
199
202
  * +--------------------------------------------------+
200
203
  * | Payload Length [2B] |
@@ -211,10 +214,10 @@ class Se {
211
214
  * +--------------------------------------------------+
212
215
  */
213
216
  static decodeFromClient(e) {
214
- const t = new m(e.buffer), n = t.readUint8(), r = [];
217
+ const t = new g(e.buffer), n = t.readUint8(), r = [];
215
218
  for (let s = 0; s < n; s++) {
216
219
  const a = t.readUint8();
217
- a in Y && r.push(Y[a]);
220
+ a in X && r.push(X[a]);
218
221
  }
219
222
  return r;
220
223
  }
@@ -233,11 +236,11 @@ class Se {
233
236
  * +--------------------------------------------------+
234
237
  */
235
238
  static encodeForClient(e) {
236
- const t = new x(6);
237
- return t.writeUint16(D.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(ce[e]), t.uint8Array;
239
+ 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;
238
241
  }
239
242
  }
240
- const Ce = {
243
+ const Ae = {
241
244
  decodeFromClient(i) {
242
245
  const e = i[0] ?? 0;
243
246
  return {
@@ -249,7 +252,7 @@ const Ce = {
249
252
  * with an empty renegotiated_connection field.
250
253
  */
251
254
  encodeForClient() {
252
- const i = D.renegotiation_info, e = new Uint8Array([0]);
255
+ const i = W.renegotiation_info, e = new Uint8Array([0]);
253
256
  return new Uint8Array([
254
257
  i >> 8 & 255,
255
258
  i & 255,
@@ -258,7 +261,7 @@ const Ce = {
258
261
  ...e
259
262
  ]);
260
263
  }
261
- }, le = {
264
+ }, ue = {
262
265
  TLS1_CK_PSK_WITH_RC4_128_SHA: 138,
263
266
  TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA: 139,
264
267
  TLS1_CK_PSK_WITH_AES_128_CBC_SHA: 140,
@@ -461,14 +464,14 @@ const Ce = {
461
464
  TLS1_CK_ECDHE_PSK_WITH_CHACHA20_POLY1305: 52396,
462
465
  TLS1_CK_DHE_PSK_WITH_CHACHA20_POLY1305: 52397,
463
466
  TLS1_CK_RSA_PSK_WITH_CHACHA20_POLY1305: 52398
464
- }, Z = f(le), he = {
467
+ }, J = p(ue), He = {
465
468
  secp256r1: 23,
466
469
  secp384r1: 24,
467
470
  secp521r1: 25,
468
471
  x25519: 29,
469
472
  x448: 30
470
- }, J = f(he);
471
- class Ue {
473
+ }, Q = p(He);
474
+ class Fe {
472
475
  /**
473
476
  * +--------------------------------------------------+
474
477
  * | Payload Length [2B] |
@@ -485,12 +488,12 @@ class Ue {
485
488
  * +--------------------------------------------------+
486
489
  */
487
490
  static decodeFromClient(e) {
488
- const t = new m(e.buffer);
491
+ const t = new g(e.buffer);
489
492
  t.readUint16();
490
493
  const n = [];
491
494
  for (; !t.isFinished(); ) {
492
495
  const r = t.readUint16();
493
- r in J && n.push(J[r]);
496
+ r in Q && n.push(Q[r]);
494
497
  }
495
498
  return n;
496
499
  }
@@ -505,16 +508,16 @@ class Ue {
505
508
  * +--------------------------------------------------+
506
509
  */
507
510
  static encodeForClient(e) {
508
- const t = new x(6);
509
- return t.writeUint16(D.supported_groups), t.writeUint16(2), t.writeUint16(he[e]), t.uint8Array;
511
+ const t = new N(6);
512
+ return t.writeUint16(W.supported_groups), t.writeUint16(2), t.writeUint16(He[e]), t.uint8Array;
510
513
  }
511
514
  }
512
- const $ = {
515
+ const V = {
513
516
  anonymous: 0,
514
517
  rsa: 1,
515
518
  dsa: 2,
516
519
  ecdsa: 3
517
- }, X = f($), V = {
520
+ }, ee = p(V), z = {
518
521
  none: 0,
519
522
  md5: 1,
520
523
  sha1: 2,
@@ -522,8 +525,8 @@ const $ = {
522
525
  sha256: 4,
523
526
  sha384: 5,
524
527
  sha512: 6
525
- }, Q = f(V);
526
- class xe {
528
+ }, te = p(z);
529
+ class qe {
527
530
  /**
528
531
  * Binary layout:
529
532
  *
@@ -540,19 +543,19 @@ class xe {
540
543
  * +------------------------------------+
541
544
  */
542
545
  static decodeFromClient(e) {
543
- const t = new m(e.buffer);
546
+ const t = new g(e.buffer);
544
547
  t.readUint16();
545
548
  const n = [];
546
549
  for (; !t.isFinished(); ) {
547
550
  const r = t.readUint8(), s = t.readUint8();
548
- if (X[s]) {
549
- if (!Q[r]) {
550
- U.warn(`Unknown hash algorithm: ${r}`);
551
+ if (ee[s]) {
552
+ if (!te[r]) {
553
+ B.warn(`Unknown hash algorithm: ${r}`);
551
554
  continue;
552
555
  }
553
556
  n.push({
554
- algorithm: X[s],
555
- hash: Q[r]
557
+ algorithm: ee[s],
558
+ hash: te[r]
556
559
  });
557
560
  }
558
561
  }
@@ -570,34 +573,34 @@ class xe {
570
573
  * +--------------------------------------------------+
571
574
  */
572
575
  static encodeforClient(e, t) {
573
- const n = new x(6);
574
- return n.writeUint16(D.signature_algorithms), n.writeUint16(2), n.writeUint8(V[e]), n.writeUint8($[t]), n.uint8Array;
576
+ 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;
575
578
  }
576
579
  }
577
- const ee = {
578
- server_name: oe,
579
- signature_algorithms: xe,
580
- supported_groups: Ue,
581
- ec_point_formats: Se,
582
- renegotiation_info: Ce
580
+ const ne = {
581
+ server_name: Ce,
582
+ signature_algorithms: qe,
583
+ supported_groups: Fe,
584
+ ec_point_formats: he,
585
+ renegotiation_info: Ae
583
586
  };
584
- function Me(i) {
585
- const e = new m(i.buffer), t = [];
587
+ function Oe(i) {
588
+ const e = new g(i.buffer), t = [];
586
589
  for (; !e.isFinished(); ) {
587
- const n = e.offset, r = e.readUint16(), s = Re[r], a = e.readUint16(), _ = e.readUint8Array(a);
588
- if (!(s in ee))
590
+ const n = e.offset, r = e.readUint16(), s = Ne[r], a = e.readUint16(), _ = e.readUint8Array(a);
591
+ if (!(s in ne))
589
592
  continue;
590
- const S = ee[s];
593
+ const c = ne[s];
591
594
  t.push({
592
595
  type: s,
593
- data: S.decodeFromClient(_),
596
+ data: c.decodeFromClient(_),
594
597
  raw: i.slice(n, n + 4 + a)
595
598
  });
596
599
  }
597
600
  return t;
598
601
  }
599
- async function O(i, e, t, n) {
600
- const r = R([e, t]), s = await crypto.subtle.importKey(
602
+ async function G(i, e, t, n) {
603
+ const r = v([e, t]), s = await crypto.subtle.importKey(
601
604
  "raw",
602
605
  i,
603
606
  { name: "HMAC", hash: { name: "SHA-256" } },
@@ -606,26 +609,26 @@ async function O(i, e, t, n) {
606
609
  );
607
610
  let a = r;
608
611
  const _ = [];
609
- for (; R(_).byteLength < n; ) {
610
- a = await te(s, a);
611
- const c = R([a, r]), C = await te(s, c);
612
+ for (; v(_).byteLength < n; ) {
613
+ a = await re(s, a);
614
+ const S = v([a, r]), C = await re(s, S);
612
615
  _.push(C);
613
616
  }
614
- return R(_).slice(0, n);
617
+ return v(_).slice(0, n);
615
618
  }
616
- async function te(i, e) {
619
+ async function re(i, e) {
617
620
  return await crypto.subtle.sign(
618
621
  { name: "HMAC", hash: "SHA-256" },
619
622
  i,
620
623
  e
621
624
  );
622
625
  }
623
- const ve = {
626
+ const je = {
624
627
  Null: 0
625
- }, Ae = {
628
+ }, de = {
626
629
  Warning: 1,
627
630
  Fatal: 2
628
- }, ue = f(Ae), He = {
631
+ }, fe = p(de), Ee = {
629
632
  CloseNotify: 0,
630
633
  UnexpectedMessage: 10,
631
634
  BadRecordMac: 20,
@@ -651,12 +654,12 @@ const ve = {
651
654
  UserCanceled: 90,
652
655
  NoRenegotiation: 100,
653
656
  UnsupportedExtension: 110
654
- }, de = f(He), l = {
657
+ }, Te = p(Ee), l = {
655
658
  ChangeCipherSpec: 20,
656
659
  Alert: 21,
657
660
  Handshake: 22,
658
661
  ApplicationData: 23
659
- }, E = {
662
+ }, f = {
660
663
  HelloRequest: 0,
661
664
  ClientHello: 1,
662
665
  ServerHello: 2,
@@ -665,7 +668,7 @@ const ve = {
665
668
  ServerHelloDone: 14,
666
669
  ClientKeyExchange: 16,
667
670
  Finished: 20
668
- }, Ne = {
671
+ }, Ge = {
669
672
  /**
670
673
  * Indicates that a named curve is used. This option
671
674
  * SHOULD be used when applicable.
@@ -674,12 +677,12 @@ const ve = {
674
677
  /**
675
678
  * Values 248 through 255 are reserved for private use.
676
679
  */
677
- }, ke = {
680
+ }, $e = {
678
681
  secp256r1: 23
679
682
  };
680
- class q extends Error {
683
+ class j extends Error {
681
684
  }
682
- const B = new Uint8Array([3, 3]), Fe = crypto.subtle.generateKey(
685
+ const x = new Uint8Array([3, 3]), Ve = crypto.subtle.generateKey(
683
686
  {
684
687
  name: "ECDH",
685
688
  namedCurve: "P-256"
@@ -690,7 +693,7 @@ const B = new Uint8Array([3, 3]), Fe = crypto.subtle.generateKey(
690
693
  ["deriveKey", "deriveBits"]
691
694
  // Key usage
692
695
  );
693
- class qe {
696
+ class ze {
694
697
  constructor() {
695
698
  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 = {
696
699
  // We don't need to chunk the encrypted data.
@@ -707,7 +710,7 @@ class qe {
707
710
  * This will spread some messages across multiple records,
708
711
  * but TLS supports it so that's fine.
709
712
  */
710
- downstream: Oe(this.MAX_CHUNK_SIZE)
713
+ downstream: Ye(this.MAX_CHUNK_SIZE)
711
714
  }, this.serverUpstreamWriter = this.serverEnd.upstream.writable.getWriter();
712
715
  const e = this;
713
716
  this.serverEnd.downstream.readable.pipeTo(
@@ -764,7 +767,7 @@ class qe {
764
767
  */
765
768
  async TLSHandshake(e, t) {
766
769
  const n = await this.readNextHandshakeMessage(
767
- E.ClientHello
770
+ f.ClientHello
768
771
  );
769
772
  if (!n.body.cipher_suites.length)
770
773
  throw new Error(
@@ -773,16 +776,16 @@ class qe {
773
776
  const r = crypto.getRandomValues(new Uint8Array(32));
774
777
  await this.writeTLSRecord(
775
778
  l.Handshake,
776
- I.serverHello(
779
+ K.serverHello(
777
780
  n.body,
778
781
  r,
779
- ve.Null
782
+ je.Null
780
783
  )
781
784
  ), await this.writeTLSRecord(
782
785
  l.Handshake,
783
- I.certificate(t)
786
+ K.certificate(t)
784
787
  );
785
- const s = await Fe, a = n.body.random, _ = await I.ECDHEServerKeyExchange(
788
+ const s = await Ve, a = n.body.random, _ = await K.ECDHEServerKeyExchange(
786
789
  a,
787
790
  r,
788
791
  s,
@@ -790,10 +793,10 @@ class qe {
790
793
  );
791
794
  await this.writeTLSRecord(l.Handshake, _), await this.writeTLSRecord(
792
795
  l.Handshake,
793
- I.serverHelloDone()
796
+ K.serverHelloDone()
794
797
  );
795
- const S = await this.readNextHandshakeMessage(
796
- E.ClientKeyExchange
798
+ const c = await this.readNextHandshakeMessage(
799
+ f.ClientKeyExchange
797
800
  );
798
801
  await this.readNextMessage(l.ChangeCipherSpec), this.sessionKeys = await this.deriveSessionKeys({
799
802
  clientRandom: a,
@@ -801,17 +804,17 @@ class qe {
801
804
  serverPrivateKey: s.privateKey,
802
805
  clientPublicKey: await crypto.subtle.importKey(
803
806
  "raw",
804
- S.body.exchange_keys,
807
+ c.body.exchange_keys,
805
808
  { name: "ECDH", namedCurve: "P-256" },
806
809
  !1,
807
810
  []
808
811
  )
809
- }), await this.readNextHandshakeMessage(E.Finished), await this.writeTLSRecord(
812
+ }), await this.readNextHandshakeMessage(f.Finished), await this.writeTLSRecord(
810
813
  l.ChangeCipherSpec,
811
- I.changeCipherSpec()
814
+ K.changeCipherSpec()
812
815
  ), await this.writeTLSRecord(
813
816
  l.Handshake,
814
- await I.createFinishedMessage(
817
+ await K.createFinishedMessage(
815
818
  this.handshakeMessages,
816
819
  this.sessionKeys.masterSecret
817
820
  )
@@ -836,24 +839,24 @@ class qe {
836
839
  256
837
840
  // Length of the derived secret (256 bits for P-256)
838
841
  ), a = new Uint8Array(
839
- await O(
842
+ await G(
840
843
  s,
841
844
  new TextEncoder().encode("master secret"),
842
- u([e, t]),
845
+ H([e, t]),
843
846
  48
844
847
  )
845
- ), _ = await O(
848
+ ), _ = await G(
846
849
  a,
847
850
  new TextEncoder().encode("key expansion"),
848
- u([t, e]),
851
+ H([t, e]),
849
852
  // Client key, server key, client IV, server IV
850
853
  40
851
- ), S = new m(_), c = S.readUint8Array(16), C = S.readUint8Array(16), h = S.readUint8Array(4), A = S.readUint8Array(4);
854
+ ), c = new g(_), S = c.readUint8Array(16), C = c.readUint8Array(16), h = c.readUint8Array(4), A = c.readUint8Array(4);
852
855
  return {
853
856
  masterSecret: a,
854
857
  clientWriteKey: await crypto.subtle.importKey(
855
858
  "raw",
856
- c,
859
+ S,
857
860
  { name: "AES-GCM" },
858
861
  !1,
859
862
  ["encrypt", "decrypt"]
@@ -880,7 +883,7 @@ class qe {
880
883
  do
881
884
  t = await this.readNextTLSRecord(e), n = await this.accumulateUntilMessageIsComplete(t);
882
885
  while (n === !1);
883
- const r = T.TLSMessage(
886
+ const r = E.TLSMessage(
884
887
  t.type,
885
888
  n
886
889
  );
@@ -889,9 +892,9 @@ class qe {
889
892
  async readNextTLSRecord(e) {
890
893
  for (; ; ) {
891
894
  for (let _ = 0; _ < this.receivedTLSRecords.length; _++) {
892
- const S = this.receivedTLSRecords[_];
893
- if (S.type === e)
894
- return this.receivedTLSRecords.splice(_, 1), S;
895
+ const c = this.receivedTLSRecords[_];
896
+ if (c.type === e)
897
+ return this.receivedTLSRecords.splice(_, 1), c;
895
898
  }
896
899
  const t = await this.pollBytes(5), n = t[3] << 8 | t[4], r = t[0], s = await this.pollBytes(n), a = {
897
900
  type: r,
@@ -903,11 +906,11 @@ class qe {
903
906
  fragment: this.sessionKeys && r !== l.ChangeCipherSpec ? await this.decryptData(r, s) : s
904
907
  };
905
908
  if (a.type === l.Alert) {
906
- const _ = a.fragment[0], S = a.fragment[1], c = ue[_], C = de[S];
907
- throw _ === Ae.Warning && S === He.CloseNotify ? new q(
909
+ const _ = a.fragment[0], c = a.fragment[1], S = fe[_], C = Te[c];
910
+ throw _ === de.Warning && c === Ee.CloseNotify ? new j(
908
911
  "TLS connection closed by peer (CloseNotify)"
909
912
  ) : new Error(
910
- `TLS alert received: ${c} ${C}`
913
+ `TLS alert received: ${S} ${C}`
911
914
  );
912
915
  }
913
916
  this.receivedTLSRecords.push(a);
@@ -921,8 +924,8 @@ class qe {
921
924
  for (; this.receivedBytesBuffer.length < e; ) {
922
925
  const { value: n, done: r } = await this.clientUpstreamReader.read();
923
926
  if (r)
924
- throw await this.close(), new q("TLS connection closed");
925
- if (this.receivedBytesBuffer = u([
927
+ throw await this.close(), new j("TLS connection closed");
928
+ if (this.receivedBytesBuffer = H([
926
929
  this.receivedBytesBuffer,
927
930
  n
928
931
  ]), this.receivedBytesBuffer.length >= e)
@@ -945,7 +948,7 @@ class qe {
945
948
  this.serverUpstreamWriter.write(e.body);
946
949
  }
947
950
  } catch (e) {
948
- if (e instanceof q)
951
+ if (e instanceof j)
949
952
  return;
950
953
  throw e;
951
954
  }
@@ -960,11 +963,11 @@ class qe {
960
963
  name: "AES-GCM",
961
964
  iv: s,
962
965
  additionalData: new Uint8Array([
963
- ...z(this.receivedRecordSequenceNumber),
966
+ ...Z(this.receivedRecordSequenceNumber),
964
967
  e,
965
- ...B,
968
+ ...x,
966
969
  // Payload length without IV and tag
967
- ...K(t.length - 8 - 16)
970
+ ...D(t.length - 8 - 16)
968
971
  ]),
969
972
  tagLength: 128
970
973
  },
@@ -975,7 +978,7 @@ class qe {
975
978
  return ++this.receivedRecordSequenceNumber, new Uint8Array(a);
976
979
  }
977
980
  async accumulateUntilMessageIsComplete(e) {
978
- this.partialTLSMessages[e.type] = u([
981
+ this.partialTLSMessages[e.type] = H([
979
982
  this.partialTLSMessages[e.type] || new Uint8Array(),
980
983
  e.fragment
981
984
  ]);
@@ -1011,9 +1014,9 @@ class qe {
1011
1014
  */
1012
1015
  async writeTLSRecord(e, t) {
1013
1016
  e === l.Handshake && this.handshakeMessages.push(t), this.sessionKeys && e !== l.ChangeCipherSpec && (t = await this.encryptData(e, t));
1014
- const n = B, r = t.length, s = new Uint8Array(5);
1017
+ const n = x, r = t.length, s = new Uint8Array(5);
1015
1018
  s[0] = e, s[1] = n[0], s[2] = n[1], s[3] = r >> 8 & 255, s[4] = r & 255;
1016
- const a = u([s, t]);
1019
+ const a = H([s, t]);
1017
1020
  this.clientDownstreamWriter.write(a);
1018
1021
  }
1019
1022
  /**
@@ -1022,11 +1025,11 @@ class qe {
1022
1025
  */
1023
1026
  async encryptData(e, t) {
1024
1027
  const n = this.sessionKeys.serverIV, r = crypto.getRandomValues(new Uint8Array(8)), s = new Uint8Array([...n, ...r]), a = new Uint8Array([
1025
- ...z(this.sentRecordSequenceNumber),
1028
+ ...Z(this.sentRecordSequenceNumber),
1026
1029
  e,
1027
- ...B,
1030
+ ...x,
1028
1031
  // Payload length without IV and tag
1029
- ...K(t.length)
1032
+ ...D(t.length)
1030
1033
  ]), _ = await crypto.subtle.encrypt(
1031
1034
  {
1032
1035
  name: "AES-GCM",
@@ -1037,23 +1040,23 @@ class qe {
1037
1040
  this.sessionKeys.serverWriteKey,
1038
1041
  t
1039
1042
  );
1040
- return ++this.sentRecordSequenceNumber, u([
1043
+ return ++this.sentRecordSequenceNumber, H([
1041
1044
  r,
1042
1045
  new Uint8Array(_)
1043
1046
  ]);
1044
1047
  }
1045
1048
  }
1046
- class T {
1049
+ class E {
1047
1050
  static TLSMessage(e, t) {
1048
1051
  switch (e) {
1049
1052
  case l.Handshake:
1050
- return T.clientHandshake(t);
1053
+ return E.clientHandshake(t);
1051
1054
  case l.Alert:
1052
- return T.alert(t);
1055
+ return E.alert(t);
1053
1056
  case l.ChangeCipherSpec:
1054
- return T.changeCipherSpec();
1057
+ return E.changeCipherSpec();
1055
1058
  case l.ApplicationData:
1056
- return T.applicationData(t);
1059
+ return E.applicationData(t);
1057
1060
  default:
1058
1061
  throw new Error(`TLS: Unsupported TLS record type ${e}`);
1059
1062
  }
@@ -1082,12 +1085,12 @@ class T {
1082
1085
  * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4
1083
1086
  */
1084
1087
  static parseCipherSuites(e) {
1085
- const t = new m(e);
1088
+ const t = new g(e);
1086
1089
  t.readUint16();
1087
1090
  const n = [];
1088
1091
  for (; !t.isFinished(); ) {
1089
1092
  const r = t.readUint16();
1090
- r in Z && n.push(Z[r]);
1093
+ r in J && n.push(J[r]);
1091
1094
  }
1092
1095
  return n;
1093
1096
  }
@@ -1106,25 +1109,25 @@ class T {
1106
1109
  static alert(e) {
1107
1110
  return {
1108
1111
  type: l.Alert,
1109
- level: ue[e[0]],
1110
- description: de[e[1]]
1112
+ level: fe[e[0]],
1113
+ description: Te[e[1]]
1111
1114
  };
1112
1115
  }
1113
1116
  static clientHandshake(e) {
1114
1117
  const t = e[0], n = e[1] << 16 | e[2] << 8 | e[3], r = e.slice(4);
1115
1118
  let s;
1116
1119
  switch (t) {
1117
- case E.HelloRequest:
1118
- s = T.clientHelloRequestPayload();
1120
+ case f.HelloRequest:
1121
+ s = E.clientHelloRequestPayload();
1119
1122
  break;
1120
- case E.ClientHello:
1121
- s = T.clientHelloPayload(r);
1123
+ case f.ClientHello:
1124
+ s = E.clientHelloPayload(r);
1122
1125
  break;
1123
- case E.ClientKeyExchange:
1124
- s = T.clientKeyExchangePayload(r);
1126
+ case f.ClientKeyExchange:
1127
+ s = E.clientKeyExchangePayload(r);
1125
1128
  break;
1126
- case E.Finished:
1127
- s = T.clientFinishedPayload(r);
1129
+ case f.Finished:
1130
+ s = E.clientFinishedPayload(r);
1128
1131
  break;
1129
1132
  default:
1130
1133
  throw new Error(`Invalid handshake type ${t}`);
@@ -1180,7 +1183,7 @@ class T {
1180
1183
  * +------+------+---------------------------+
1181
1184
  */
1182
1185
  static clientHelloPayload(e) {
1183
- const t = new m(e.buffer), n = {
1186
+ const t = new g(e.buffer), n = {
1184
1187
  client_version: t.readUint8Array(2),
1185
1188
  /**
1186
1189
  * Technically this consists of a GMT timestamp
@@ -1191,7 +1194,7 @@ class T {
1191
1194
  }, r = t.readUint8();
1192
1195
  n.session_id = t.readUint8Array(r);
1193
1196
  const s = t.readUint16();
1194
- n.cipher_suites = T.parseCipherSuites(
1197
+ n.cipher_suites = E.parseCipherSuites(
1195
1198
  t.readUint8Array(s).buffer
1196
1199
  );
1197
1200
  const a = t.readUint8();
@@ -1199,7 +1202,7 @@ class T {
1199
1202
  a
1200
1203
  );
1201
1204
  const _ = t.readUint16();
1202
- return n.extensions = Me(
1205
+ return n.extensions = Oe(
1203
1206
  t.readUint8Array(_)
1204
1207
  ), n;
1205
1208
  }
@@ -1224,7 +1227,7 @@ class T {
1224
1227
  };
1225
1228
  }
1226
1229
  }
1227
- function Oe(i) {
1230
+ function Ye(i) {
1228
1231
  return new TransformStream({
1229
1232
  transform(e, t) {
1230
1233
  for (; e.length > 0; )
@@ -1232,18 +1235,18 @@ function Oe(i) {
1232
1235
  }
1233
1236
  });
1234
1237
  }
1235
- class I {
1238
+ class K {
1236
1239
  static certificate(e) {
1237
1240
  const t = [];
1238
1241
  for (const s of e)
1239
- t.push(L(s.byteLength)), t.push(new Uint8Array(s));
1240
- const n = u(t), r = new Uint8Array([
1241
- ...L(n.byteLength),
1242
+ t.push(m(s.byteLength)), t.push(new Uint8Array(s));
1243
+ const n = H(t), r = new Uint8Array([
1244
+ ...m(n.byteLength),
1242
1245
  ...n
1243
1246
  ]);
1244
1247
  return new Uint8Array([
1245
- E.Certificate,
1246
- ...L(r.length),
1248
+ f.Certificate,
1249
+ ...m(r.length),
1247
1250
  ...r
1248
1251
  ]);
1249
1252
  }
@@ -1285,9 +1288,9 @@ class I {
1285
1288
  await crypto.subtle.exportKey("raw", n.publicKey)
1286
1289
  ), a = new Uint8Array([
1287
1290
  // Curve type (1 byte)
1288
- Ne.NamedCurve,
1291
+ Ge.NamedCurve,
1289
1292
  // Curve name (2 bytes)
1290
- ...K(ke.secp256r1),
1293
+ ...D($e.secp256r1),
1291
1294
  // Public key length (1 byte)
1292
1295
  s.byteLength,
1293
1296
  // Public key (65 bytes, uncompressed format)
@@ -1299,18 +1302,18 @@ class I {
1299
1302
  },
1300
1303
  r,
1301
1304
  new Uint8Array([...e, ...t, ...a])
1302
- ), S = new Uint8Array(_), c = new Uint8Array([
1303
- V.sha256,
1304
- $.rsa
1305
+ ), c = new Uint8Array(_), S = new Uint8Array([
1306
+ z.sha256,
1307
+ V.rsa
1305
1308
  ]), C = new Uint8Array([
1306
1309
  ...a,
1307
- ...c,
1308
- ...K(S.length),
1309
- ...S
1310
+ ...S,
1311
+ ...D(c.length),
1312
+ ...c
1310
1313
  ]);
1311
1314
  return new Uint8Array([
1312
- E.ServerKeyExchange,
1313
- ...L(C.length),
1315
+ f.ServerKeyExchange,
1316
+ ...m(C.length),
1314
1317
  ...C
1315
1318
  ]);
1316
1319
  }
@@ -1356,34 +1359,34 @@ class I {
1356
1359
  const r = e.extensions.map((_) => {
1357
1360
  switch (_.type) {
1358
1361
  case "server_name":
1359
- return oe.encodeForClient();
1362
+ return Ce.encodeForClient();
1360
1363
  case "ec_point_formats":
1361
- return Se.encodeForClient(
1364
+ return he.encodeForClient(
1362
1365
  "uncompressed"
1363
1366
  );
1364
1367
  case "renegotiation_info":
1365
- return Ce.encodeForClient();
1368
+ return Ae.encodeForClient();
1366
1369
  }
1367
- }).filter((_) => _ !== void 0), s = u(r), a = new Uint8Array([
1370
+ }).filter((_) => _ !== void 0), s = H(r), a = new Uint8Array([
1368
1371
  // Version field – 0x03, 0x03 means TLS 1.2
1369
- ...B,
1372
+ ...x,
1370
1373
  ...t,
1371
1374
  e.session_id.length,
1372
1375
  ...e.session_id,
1373
- ...K(le.TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
1376
+ ...D(ue.TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
1374
1377
  n,
1375
1378
  // Extensions length (2 bytes)
1376
- ...K(s.length),
1379
+ ...D(s.length),
1377
1380
  ...s
1378
1381
  ]);
1379
1382
  return new Uint8Array([
1380
- E.ServerHello,
1381
- ...L(a.length),
1383
+ f.ServerHello,
1384
+ ...m(a.length),
1382
1385
  ...a
1383
1386
  ]);
1384
1387
  }
1385
1388
  static serverHelloDone() {
1386
- return new Uint8Array([E.ServerHelloDone, ...L(0)]);
1389
+ return new Uint8Array([f.ServerHelloDone, ...m(0)]);
1387
1390
  }
1388
1391
  /**
1389
1392
  * Server finished message.
@@ -1406,9 +1409,9 @@ class I {
1406
1409
  static async createFinishedMessage(e, t) {
1407
1410
  const n = await crypto.subtle.digest(
1408
1411
  "SHA-256",
1409
- u(e)
1412
+ H(e)
1410
1413
  ), r = new Uint8Array(
1411
- await O(
1414
+ await G(
1412
1415
  t,
1413
1416
  new TextEncoder().encode("server finished"),
1414
1417
  n,
@@ -1417,8 +1420,8 @@ class I {
1417
1420
  )
1418
1421
  );
1419
1422
  return new Uint8Array([
1420
- E.Finished,
1421
- ...L(r.length),
1423
+ f.Finished,
1424
+ ...m(r.length),
1422
1425
  ...r
1423
1426
  ]);
1424
1427
  }
@@ -1426,25 +1429,25 @@ class I {
1426
1429
  return new Uint8Array([1]);
1427
1430
  }
1428
1431
  }
1429
- function je(i, e) {
1430
- return Ge.generateCertificate(i, e);
1432
+ function Ze(i, e) {
1433
+ return Xe.generateCertificate(i, e);
1431
1434
  }
1432
- function dt(i) {
1435
+ function gt(i) {
1433
1436
  return `-----BEGIN CERTIFICATE-----
1434
- ${Te(
1435
- Ee(i.buffer)
1437
+ ${we(
1438
+ pe(i.buffer)
1436
1439
  )}
1437
1440
  -----END CERTIFICATE-----`;
1438
1441
  }
1439
- async function Et(i) {
1442
+ async function It(i) {
1440
1443
  const e = await crypto.subtle.exportKey("pkcs8", i);
1441
1444
  return `-----BEGIN PRIVATE KEY-----
1442
- ${Te(
1443
- Ee(e)
1445
+ ${we(
1446
+ pe(e)
1444
1447
  )}
1445
1448
  -----END PRIVATE KEY-----`;
1446
1449
  }
1447
- class Ge {
1450
+ class Xe {
1448
1451
  static async generateCertificate(e, t) {
1449
1452
  const n = await crypto.subtle.generateKey(
1450
1453
  {
@@ -1511,7 +1514,7 @@ class Ge {
1511
1514
  }
1512
1515
  static signatureAlgorithm(e = "sha256WithRSAEncryption") {
1513
1516
  return o.sequence([
1514
- o.objectIdentifier(p(e)),
1517
+ o.objectIdentifier(w(e)),
1515
1518
  o.null()
1516
1519
  ]);
1517
1520
  }
@@ -1525,7 +1528,7 @@ class Ge {
1525
1528
  const t = [];
1526
1529
  for (const [n, r] of Object.entries(e)) {
1527
1530
  const s = [
1528
- o.objectIdentifier(p(n))
1531
+ o.objectIdentifier(w(n))
1529
1532
  ];
1530
1533
  switch (n) {
1531
1534
  case "countryName":
@@ -1541,16 +1544,16 @@ class Ge {
1541
1544
  static validity(e) {
1542
1545
  return o.sequence([
1543
1546
  o.ASN1(
1544
- H.UTCTime,
1547
+ d.UTCTime,
1545
1548
  new TextEncoder().encode(
1546
- re((e == null ? void 0 : e.notBefore) ?? /* @__PURE__ */ new Date())
1549
+ ie((e == null ? void 0 : e.notBefore) ?? /* @__PURE__ */ new Date())
1547
1550
  )
1548
1551
  ),
1549
1552
  o.ASN1(
1550
- H.UTCTime,
1553
+ d.UTCTime,
1551
1554
  new TextEncoder().encode(
1552
- re(
1553
- (e == null ? void 0 : e.notAfter) ?? Ve(/* @__PURE__ */ new Date(), 10)
1555
+ ie(
1556
+ (e == null ? void 0 : e.notAfter) ?? Qe(/* @__PURE__ */ new Date(), 10)
1554
1557
  )
1555
1558
  )
1556
1559
  )
@@ -1564,14 +1567,14 @@ class Ge {
1564
1567
  return t !== void 0 && n.push(
1565
1568
  o.integer(new Uint8Array([t]))
1566
1569
  ), o.sequence([
1567
- o.objectIdentifier(p("basicConstraints")),
1570
+ o.objectIdentifier(w("basicConstraints")),
1568
1571
  o.octetString(o.sequence(n))
1569
1572
  ]);
1570
1573
  }
1571
1574
  static keyUsage(e) {
1572
1575
  const t = new Uint8Array([0]);
1573
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([
1574
- o.objectIdentifier(p("keyUsage")),
1577
+ o.objectIdentifier(w("keyUsage")),
1575
1578
  o.boolean(!0),
1576
1579
  // Critical
1577
1580
  o.octetString(o.bitString(t))
@@ -1579,13 +1582,13 @@ class Ge {
1579
1582
  }
1580
1583
  static extKeyUsage(e = {}) {
1581
1584
  return o.sequence([
1582
- o.objectIdentifier(p("extKeyUsage")),
1585
+ o.objectIdentifier(w("extKeyUsage")),
1583
1586
  o.boolean(!0),
1584
1587
  // Critical
1585
1588
  o.octetString(
1586
1589
  o.sequence(
1587
1590
  Object.entries(e).map(([t, n]) => n ? o.objectIdentifier(
1588
- p(t)
1591
+ w(t)
1589
1592
  ) : o.null())
1590
1593
  )
1591
1594
  )
@@ -1594,29 +1597,29 @@ class Ge {
1594
1597
  static nsCertType(e) {
1595
1598
  const t = new Uint8Array([0]);
1596
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([
1597
- o.objectIdentifier(p("nsCertType")),
1600
+ o.objectIdentifier(w("nsCertType")),
1598
1601
  o.octetString(t)
1599
1602
  ]);
1600
1603
  }
1601
1604
  static subjectAltName(e) {
1602
1605
  var s, a;
1603
1606
  const t = ((s = e.dnsNames) == null ? void 0 : s.map((_) => {
1604
- const S = o.ia5String(_);
1605
- return o.contextSpecific(2, S);
1607
+ const c = o.ia5String(_);
1608
+ return o.contextSpecific(2, c);
1606
1609
  })) || [], n = ((a = e.ipAddresses) == null ? void 0 : a.map((_) => {
1607
- const S = o.ia5String(_);
1608
- return o.contextSpecific(7, S);
1610
+ const c = o.ia5String(_);
1611
+ return o.contextSpecific(7, c);
1609
1612
  })) || [], r = o.octetString(
1610
1613
  o.sequence([...t, ...n])
1611
1614
  );
1612
1615
  return o.sequence([
1613
- o.objectIdentifier(p("subjectAltName")),
1616
+ o.objectIdentifier(w("subjectAltName")),
1614
1617
  o.boolean(!0),
1615
1618
  r
1616
1619
  ]);
1617
1620
  }
1618
1621
  }
1619
- const $e = {
1622
+ const Je = {
1620
1623
  // Algorithm OIDs
1621
1624
  "1.2.840.113549.1.1.1": "rsaEncryption",
1622
1625
  "1.2.840.113549.1.1.4": "md5WithRSAEncryption",
@@ -1726,13 +1729,13 @@ const $e = {
1726
1729
  "1.3.6.1.5.5.7.3.4": "emailProtection",
1727
1730
  "1.3.6.1.5.5.7.3.8": "timeStamping"
1728
1731
  };
1729
- function p(i) {
1730
- for (const [e, t] of Object.entries($e))
1732
+ function w(i) {
1733
+ for (const [e, t] of Object.entries(Je))
1731
1734
  if (t === i)
1732
1735
  return e;
1733
1736
  throw new Error(`OID not found for name: ${i}`);
1734
1737
  }
1735
- const ne = 32, H = {
1738
+ const se = 32, d = {
1736
1739
  Boolean: 1,
1737
1740
  Integer: 2,
1738
1741
  BitString: 3,
@@ -1740,8 +1743,8 @@ const ne = 32, H = {
1740
1743
  Null: 5,
1741
1744
  OID: 6,
1742
1745
  Utf8String: 12,
1743
- Sequence: 16 | ne,
1744
- Set: 17 | ne,
1746
+ Sequence: 16 | se,
1747
+ Set: 17 | se,
1745
1748
  PrintableString: 19,
1746
1749
  IA5String: 22,
1747
1750
  UTCTime: 23
@@ -1768,21 +1771,24 @@ class o {
1768
1771
  return r[0] = e, r.set(n, 1), r.set(t, 1 + n.length), r;
1769
1772
  }
1770
1773
  static integer(e) {
1771
- if (e[0] > 127) {
1772
- const t = new Uint8Array(e.length + 1);
1773
- t[0] = 0, t.set(e, 1), e = t;
1774
+ let t = 0;
1775
+ for (; t < e.length - 1 && e[t] === 0 && e[t + 1] < 128; )
1776
+ t++;
1777
+ if (t > 0 && (e = e.subarray(t)), e[0] > 127) {
1778
+ const n = new Uint8Array(e.length + 1);
1779
+ n[0] = 0, n.set(e, 1), e = n;
1774
1780
  }
1775
- return o.ASN1(H.Integer, e);
1781
+ return o.ASN1(d.Integer, e);
1776
1782
  }
1777
1783
  static bitString(e) {
1778
1784
  const t = new Uint8Array([0]), n = new Uint8Array(t.length + e.length);
1779
- return n.set(t), n.set(e, t.length), o.ASN1(H.BitString, n);
1785
+ return n.set(t), n.set(e, t.length), o.ASN1(d.BitString, n);
1780
1786
  }
1781
1787
  static octetString(e) {
1782
- return o.ASN1(H.OctetString, e);
1788
+ return o.ASN1(d.OctetString, e);
1783
1789
  }
1784
1790
  static null() {
1785
- return o.ASN1(H.Null, new Uint8Array(0));
1791
+ return o.ASN1(d.Null, new Uint8Array(0));
1786
1792
  }
1787
1793
  static objectIdentifier(e) {
1788
1794
  const t = e.split(".").map(Number), r = [t[0] * 40 + t[1]];
@@ -1792,29 +1798,29 @@ class o {
1792
1798
  do
1793
1799
  _.unshift(a & 127), a >>= 7;
1794
1800
  while (a > 0);
1795
- for (let S = 0; S < _.length - 1; S++)
1796
- _[S] |= 128;
1801
+ for (let c = 0; c < _.length - 1; c++)
1802
+ _[c] |= 128;
1797
1803
  r.push(..._);
1798
1804
  }
1799
- return o.ASN1(H.OID, new Uint8Array(r));
1805
+ return o.ASN1(d.OID, new Uint8Array(r));
1800
1806
  }
1801
1807
  static utf8String(e) {
1802
1808
  const t = new TextEncoder().encode(e);
1803
- return o.ASN1(H.Utf8String, t);
1809
+ return o.ASN1(d.Utf8String, t);
1804
1810
  }
1805
1811
  static printableString(e) {
1806
1812
  const t = new TextEncoder().encode(e);
1807
- return o.ASN1(H.PrintableString, t);
1813
+ return o.ASN1(d.PrintableString, t);
1808
1814
  }
1809
1815
  static sequence(e) {
1810
- return o.ASN1(H.Sequence, u(e));
1816
+ return o.ASN1(d.Sequence, H(e));
1811
1817
  }
1812
1818
  static set(e) {
1813
- return o.ASN1(H.Set, u(e));
1819
+ return o.ASN1(d.Set, H(e));
1814
1820
  }
1815
1821
  static ia5String(e) {
1816
1822
  const t = new TextEncoder().encode(e);
1817
- return o.ASN1(H.IA5String, t);
1823
+ return o.ASN1(d.IA5String, t);
1818
1824
  }
1819
1825
  static contextSpecific(e, t, n = !1) {
1820
1826
  const r = (n ? 160 : 128) | e;
@@ -1822,45 +1828,45 @@ class o {
1822
1828
  }
1823
1829
  static boolean(e) {
1824
1830
  return o.ASN1(
1825
- H.Boolean,
1831
+ d.Boolean,
1826
1832
  new Uint8Array([e ? 255 : 0])
1827
1833
  );
1828
1834
  }
1829
1835
  }
1830
- function Ee(i) {
1836
+ function pe(i) {
1831
1837
  return btoa(String.fromCodePoint(...new Uint8Array(i)));
1832
1838
  }
1833
- function Te(i) {
1839
+ function we(i) {
1834
1840
  var e;
1835
1841
  return ((e = i.match(/.{1,64}/g)) == null ? void 0 : e.join(`
1836
1842
  `)) || i;
1837
1843
  }
1838
- function re(i) {
1839
- const e = i.getUTCFullYear().toString().substr(2), t = P(i.getUTCMonth() + 1), n = P(i.getUTCDate()), r = P(i.getUTCHours()), s = P(i.getUTCMinutes()), a = P(i.getUTCSeconds());
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());
1840
1846
  return `${e}${t}${n}${r}${s}${a}Z`;
1841
1847
  }
1842
- function P(i) {
1848
+ function R(i) {
1843
1849
  return i.toString().padStart(2, "0");
1844
1850
  }
1845
- function Ve(i, e) {
1851
+ function Qe(i, e) {
1846
1852
  const t = new Date(i);
1847
1853
  return t.setUTCFullYear(t.getUTCFullYear() + e), t;
1848
1854
  }
1849
- class ze extends TransformStream {
1855
+ class et extends TransformStream {
1850
1856
  constructor() {
1851
1857
  let e = new Uint8Array(0), t = "SCAN_CHUNK_SIZE", n = 0;
1852
1858
  super({
1853
1859
  transform(r, s) {
1854
- for (e = u([e, r]); e.length > 0; )
1860
+ for (e = H([e, r]); e.length > 0; )
1855
1861
  if (t === "SCAN_CHUNK_SIZE") {
1856
1862
  if (e.length < 3)
1857
1863
  return;
1858
1864
  let a = 0;
1859
1865
  for (; a < e.length; ) {
1860
- const c = e[a];
1861
- if (!(c >= 48 && c <= 57 || // 0-9
1862
- c >= 97 && c <= 102 || // a-f
1863
- c >= 65 && c <= 70)) break;
1866
+ const S = e[a];
1867
+ if (!(S >= 48 && S <= 57 || // 0-9
1868
+ S >= 97 && S <= 102 || // a-f
1869
+ S >= 65 && S <= 70)) break;
1864
1870
  a++;
1865
1871
  }
1866
1872
  if (a === 0)
@@ -1874,12 +1880,12 @@ class ze extends TransformStream {
1874
1880
  );
1875
1881
  const _ = new TextDecoder().decode(
1876
1882
  e.slice(0, a)
1877
- ), S = parseInt(_, 16);
1878
- if (e = e.slice(a + 2), S === 0) {
1883
+ ), c = parseInt(_, 16);
1884
+ if (e = e.slice(a + 2), c === 0) {
1879
1885
  t = "SCAN_FINAL_CHUNK", s.terminate();
1880
1886
  return;
1881
1887
  }
1882
- n = S, t = "SCAN_CHUNK_DATA";
1888
+ n = c, t = "SCAN_CHUNK_DATA";
1883
1889
  } else if (t === "SCAN_CHUNK_DATA") {
1884
1890
  const a = Math.min(
1885
1891
  n,
@@ -1899,7 +1905,7 @@ class ze extends TransformStream {
1899
1905
  });
1900
1906
  }
1901
1907
  }
1902
- const Ye = (i, e) => ({
1908
+ const tt = (i, e) => ({
1903
1909
  ...i,
1904
1910
  websocket: {
1905
1911
  url: (t, n, r) => `ws://playground.internal/?${new URLSearchParams({
@@ -1907,7 +1913,7 @@ const Ye = (i, e) => ({
1907
1913
  port: r
1908
1914
  }).toString()}`,
1909
1915
  subprotocol: "binary",
1910
- decorator: () => class extends Ze {
1916
+ decorator: () => class extends nt {
1911
1917
  constructor(t, n) {
1912
1918
  super(t, n, {
1913
1919
  CAroot: e.CAroot,
@@ -1917,7 +1923,7 @@ const Ye = (i, e) => ({
1917
1923
  }
1918
1924
  }
1919
1925
  });
1920
- class Ze {
1926
+ class nt {
1921
1927
  constructor(e, t, {
1922
1928
  CAroot: n,
1923
1929
  corsProxyUrl: r,
@@ -1985,10 +1991,10 @@ class Ze {
1985
1991
  */
1986
1992
  send(e) {
1987
1993
  if (!(this.readyState === this.CLOSING || this.readyState === this.CLOSED) && (this.clientUpstreamWriter.write(new Uint8Array(e)), !this.fetchInitiated))
1988
- switch (this.bufferedBytesFromClient = u([
1994
+ switch (this.bufferedBytesFromClient = H([
1989
1995
  this.bufferedBytesFromClient,
1990
1996
  new Uint8Array(e)
1991
- ]), Xe(this.port, this.bufferedBytesFromClient)) {
1997
+ ]), st(this.port, this.bufferedBytesFromClient)) {
1992
1998
  case !1:
1993
1999
  return;
1994
2000
  case "other":
@@ -2007,7 +2013,7 @@ class Ze {
2007
2013
  throw new Error(
2008
2014
  "TLS protocol is only supported when the TCPOverFetchWebsocket is instantiated with a CAroot"
2009
2015
  );
2010
- const e = await je(
2016
+ const e = await Ze(
2011
2017
  {
2012
2018
  subject: {
2013
2019
  commonName: this.host,
@@ -2017,14 +2023,14 @@ class Ze {
2017
2023
  issuer: this.CAroot.tbsDescription.subject
2018
2024
  },
2019
2025
  this.CAroot.keyPair
2020
- ), t = new qe();
2026
+ ), t = new ze();
2021
2027
  this.clientUpstream.readable.pipeTo(t.clientEnd.upstream.writable).catch(() => {
2022
2028
  }), t.clientEnd.downstream.readable.pipeTo(this.clientDownstream.writable).catch(() => {
2023
2029
  }), await t.TLSHandshake(e.keyPair.privateKey, [
2024
2030
  e.certificate,
2025
2031
  this.CAroot.certificate
2026
2032
  ]);
2027
- const { request: n, expectsContinue: r } = await y.parseHttpRequest(
2033
+ const { request: n, expectsContinue: r } = await L.parseHttpRequest(
2028
2034
  t.serverEnd.upstream.readable,
2029
2035
  this.host,
2030
2036
  "https"
@@ -2038,7 +2044,7 @@ class Ze {
2038
2044
  ), s.releaseLock();
2039
2045
  }
2040
2046
  try {
2041
- await y.fetchRawResponseBytes(
2047
+ await L.fetchRawResponseBytes(
2042
2048
  n,
2043
2049
  this.corsProxyUrl
2044
2050
  ).pipeTo(t.serverEnd.downstream.writable);
@@ -2046,7 +2052,7 @@ class Ze {
2046
2052
  }
2047
2053
  }
2048
2054
  async fetchOverHTTP() {
2049
- const { request: e, expectsContinue: t } = await y.parseHttpRequest(
2055
+ const { request: e, expectsContinue: t } = await L.parseHttpRequest(
2050
2056
  this.clientUpstream.readable,
2051
2057
  this.host,
2052
2058
  "http"
@@ -2060,7 +2066,7 @@ class Ze {
2060
2066
  ), n.releaseLock();
2061
2067
  }
2062
2068
  try {
2063
- await y.fetchRawResponseBytes(
2069
+ await L.fetchRawResponseBytes(
2064
2070
  e,
2065
2071
  this.corsProxyUrl
2066
2072
  ).pipeTo(this.clientDownstream.writable);
@@ -2071,7 +2077,7 @@ class Ze {
2071
2077
  this.emit("message", { data: new Uint8Array(0) }), this.readyState = this.CLOSING, this.emit("close"), this.readyState = this.CLOSED;
2072
2078
  }
2073
2079
  }
2074
- const Je = [
2080
+ const rt = [
2075
2081
  "GET",
2076
2082
  "POST",
2077
2083
  "HEAD",
@@ -2081,7 +2087,7 @@ const Je = [
2081
2087
  "PUT",
2082
2088
  "TRACE"
2083
2089
  ];
2084
- function Xe(i, e) {
2090
+ function st(i, e) {
2085
2091
  if (e.length < 8)
2086
2092
  return !1;
2087
2093
  if (i === 443 && e[0] === l.Handshake && // TLS versions between 1.0 and 1.2
@@ -2090,11 +2096,11 @@ function Xe(i, e) {
2090
2096
  const n = new TextDecoder("latin1", {
2091
2097
  fatal: !0
2092
2098
  }).decode(e);
2093
- return Je.some(
2099
+ return rt.some(
2094
2100
  (s) => n.startsWith(s + " ")
2095
2101
  ) ? "http" : "other";
2096
2102
  }
2097
- class y {
2103
+ class L {
2098
2104
  /**
2099
2105
  * Streams a HTTP response including the status line and headers.
2100
2106
  */
@@ -2104,12 +2110,12 @@ class y {
2104
2110
  var _;
2105
2111
  let r;
2106
2112
  try {
2107
- r = await Ke(
2113
+ r = await Re(
2108
2114
  e,
2109
2115
  void 0,
2110
2116
  t
2111
2117
  );
2112
- } catch (S) {
2118
+ } catch (c) {
2113
2119
  n.enqueue(
2114
2120
  new TextEncoder().encode(
2115
2121
  `HTTP/1.1 400 Bad Request\r
@@ -2117,10 +2123,10 @@ Content-Length: 0\r
2117
2123
  \r
2118
2124
  `
2119
2125
  )
2120
- ), n.error(S);
2126
+ ), n.error(c);
2121
2127
  return;
2122
2128
  }
2123
- n.enqueue(y.headersAsBytes(r));
2129
+ n.enqueue(L.headersAsBytes(r));
2124
2130
  const s = (_ = r.body) == null ? void 0 : _.getReader();
2125
2131
  if (!s) {
2126
2132
  n.close();
@@ -2128,12 +2134,12 @@ Content-Length: 0\r
2128
2134
  }
2129
2135
  const a = new TextEncoder();
2130
2136
  for (; ; ) {
2131
- const { done: S, value: c } = await s.read();
2132
- if (c && (n.enqueue(
2133
- a.encode(`${c.length.toString(16)}\r
2137
+ const { done: c, value: S } = await s.read();
2138
+ if (S && (n.enqueue(
2139
+ a.encode(`${S.length.toString(16)}\r
2134
2140
  `)
2135
- ), n.enqueue(c), n.enqueue(a.encode(`\r
2136
- `))), S) {
2141
+ ), n.enqueue(S), n.enqueue(a.encode(`\r
2142
+ `))), c) {
2137
2143
  n.enqueue(a.encode(`0\r
2138
2144
  \r
2139
2145
  `)), n.close();
@@ -2165,81 +2171,81 @@ Content-Length: 0\r
2165
2171
  let r = new Uint8Array(0), s = !1, a = -1;
2166
2172
  const _ = e.getReader();
2167
2173
  for (; a === -1; ) {
2168
- const { done: v, value: W } = await _.read();
2169
- if (v) {
2174
+ const { done: k, value: P } = await _.read();
2175
+ if (k) {
2170
2176
  s = !0;
2171
2177
  break;
2172
2178
  }
2173
- r = u([r, W]), a = Qe(
2179
+ r = H([r, P]), a = it(
2174
2180
  r,
2175
2181
  new Uint8Array([13, 10, 13, 10])
2176
2182
  );
2177
2183
  }
2178
2184
  _.releaseLock();
2179
- const S = r.slice(0, a), c = y.parseRequestHeaders(S), C = c.headers.get("Transfer-Encoding") !== null ? "chunked" : "content-length", h = c.headers.get("Content-Length") !== null ? parseInt(c.headers.get("Content-Length"), 10) : void 0, A = r.slice(
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(
2180
2186
  a + 4
2181
2187
  /* Skip \r\n\r\n */
2182
2188
  );
2183
- let d;
2184
- if (c.method !== "GET") {
2185
- const v = e.getReader();
2186
- let W = A.length, N = A.slice(-6);
2187
- const we = new TextEncoder().encode(`0\r
2189
+ let u;
2190
+ if (S.method !== "GET") {
2191
+ const k = e.getReader();
2192
+ let P = A.length, F = A.slice(-6);
2193
+ const me = new TextEncoder().encode(`0\r
2188
2194
  \r
2189
2195
  `);
2190
- d = new ReadableStream({
2196
+ u = new ReadableStream({
2191
2197
  async start(b) {
2192
2198
  A.length > 0 && b.enqueue(A);
2193
- const k = C === "content-length" && h !== void 0 && W >= h;
2194
- (s || k) && b.close();
2199
+ const q = C === "content-length" && h !== void 0 && P >= h;
2200
+ (s || q) && b.close();
2195
2201
  },
2196
2202
  async pull(b) {
2197
- const { done: k, value: g } = await v.read();
2198
- if (W += (g == null ? void 0 : g.length) || 0, g && (b.enqueue(g), N = u([
2199
- N,
2200
- g || new Uint8Array()
2201
- ]).slice(-5)), k || C === "content-length" && h !== void 0 && W >= h || C === "chunked" && N.every(
2202
- (Le, ye) => Le === we[ye]
2203
+ const { done: q, value: I } = await k.read();
2204
+ if (P += (I == null ? void 0 : I.length) || 0, I && (b.enqueue(I), F = H([
2205
+ F,
2206
+ I || new Uint8Array()
2207
+ ]).slice(-5)), q || C === "content-length" && h !== void 0 && P >= h || C === "chunked" && F.every(
2208
+ (Le, ge) => Le === me[ge]
2203
2209
  )) {
2204
2210
  b.close();
2205
2211
  return;
2206
2212
  }
2207
2213
  }
2208
- }), C === "chunked" && (d = d.pipeThrough(
2209
- new ze()
2214
+ }), C === "chunked" && (u = u.pipeThrough(
2215
+ new et()
2210
2216
  ));
2211
2217
  }
2212
- const M = c.headers.get("Host") ?? t, pe = new URL(c.path, n + "://" + M);
2218
+ const T = S.headers.get("Host") ?? t, y = new URL(S.path, n + "://" + T);
2213
2219
  return {
2214
- request: new Request(pe.toString(), {
2215
- method: c.method,
2216
- headers: c.headers,
2217
- body: d,
2220
+ request: new Request(y.toString(), {
2221
+ method: S.method,
2222
+ headers: S.headers,
2223
+ body: u,
2218
2224
  // @ts-expect-error duplex is required for streaming request bodies
2219
- duplex: d ? "half" : void 0
2225
+ duplex: u ? "half" : void 0
2220
2226
  }),
2221
- expectsContinue: c.expectsContinue
2227
+ expectsContinue: S.expectsContinue
2222
2228
  };
2223
2229
  }
2224
2230
  static parseRequestHeaders(e) {
2225
- var S;
2231
+ var c;
2226
2232
  const t = new TextDecoder().decode(e), n = t.split(`
2227
2233
  `)[0], [r, s] = n.split(" "), a = new Headers();
2228
- for (const c of t.split(`\r
2234
+ for (const S of t.split(`\r
2229
2235
  `).slice(1)) {
2230
- if (c === "")
2236
+ if (S === "")
2231
2237
  break;
2232
- const C = c.indexOf(":");
2238
+ const C = S.indexOf(":");
2233
2239
  if (C === -1)
2234
2240
  continue;
2235
- const h = c.slice(0, C).trim(), A = c.slice(C + 1).trimStart();
2241
+ const h = S.slice(0, C).trim(), A = S.slice(C + 1).trimStart();
2236
2242
  h !== "" && a.set(h, A);
2237
2243
  }
2238
- const _ = ((S = a.get("Expect")) == null ? void 0 : S.toLowerCase()) === "100-continue";
2244
+ const _ = ((c = a.get("Expect")) == null ? void 0 : c.toLowerCase()) === "100-continue";
2239
2245
  return a.delete("Expect"), { method: r, path: s, headers: a, expectsContinue: _ };
2240
2246
  }
2241
2247
  }
2242
- function Qe(i, e) {
2248
+ function it(i, e) {
2243
2249
  const t = i.length, n = e.length, r = t - n;
2244
2250
  for (let s = 0; s <= r; s++) {
2245
2251
  let a = !0;
@@ -2253,7 +2259,7 @@ function Qe(i, e) {
2253
2259
  }
2254
2260
  return -1;
2255
2261
  }
2256
- async function et(i = G) {
2262
+ async function at(i = oe) {
2257
2263
  switch (i) {
2258
2264
  case "8.5":
2259
2265
  return (await import("@php-wasm/web-8-5")).getIntlExtensionPath();
@@ -2272,48 +2278,57 @@ async function et(i = G) {
2272
2278
  }
2273
2279
  throw new Error(`Unsupported PHP version ${i}`);
2274
2280
  }
2275
- async function tt(i = G, e) {
2276
- const t = De(fetch), n = "intl.so", r = "icu.dat", s = await et(i), a = (await import("./shared/icu.dat")).default, [_, S] = await Promise.all([
2277
- t(s).then((c) => c.arrayBuffer()),
2278
- t(a).then((c) => c.arrayBuffer())
2279
- ]);
2280
- return {
2281
- ...e,
2282
- ENV: {
2283
- ...e.ENV,
2284
- PHP_INI_SCAN_DIR: "/internal/shared/extensions",
2281
+ async function _t(i, e, t, n = []) {
2282
+ if (!n.length)
2283
+ return t;
2284
+ const r = await Promise.all(
2285
+ n.map(
2286
+ (s) => ot(i, e, s)
2287
+ )
2288
+ );
2289
+ return Ie(t, r);
2290
+ }
2291
+ async function ot(i, e, t) {
2292
+ if (typeof t == "object" && "source" in t)
2293
+ return await Y({
2294
+ ...t,
2295
+ phpVersion: i,
2296
+ asyncMode: e
2297
+ });
2298
+ const n = typeof t == "string" ? t : t.name;
2299
+ if (n !== "intl")
2300
+ throw new Error(`Unknown bundled PHP web extension: ${String(n)}.`);
2301
+ const r = Be(fetch), s = await at(i), a = (await import("../intl/shared/icu.dat")).default, [_, c] = await Promise.all(
2302
+ [s, a].map(async (S) => {
2303
+ const C = await r(S);
2304
+ if (!C.ok)
2305
+ throw new Error(
2306
+ `Failed to fetch bundled PHP web extension asset: ${C.url || S} (${C.status} ${C.statusText}).`
2307
+ );
2308
+ return await C.arrayBuffer();
2309
+ })
2310
+ );
2311
+ return await Y({
2312
+ source: {
2313
+ format: "so",
2314
+ name: "intl",
2315
+ bytes: new Uint8Array(_)
2316
+ },
2317
+ phpVersion: i,
2318
+ asyncMode: e,
2319
+ env: {
2285
2320
  ICU_DATA: "/internal/shared"
2286
2321
  },
2287
- onRuntimeInitialized: (c) => {
2288
- e.onRuntimeInitialized && e.onRuntimeInitialized(c), w.fileExists(
2289
- c.FS,
2290
- "/internal/shared/extensions"
2291
- ) || c.FS.mkdirTree("/internal/shared/extensions"), w.fileExists(
2292
- c.FS,
2293
- `/internal/shared/extensions/${n}`
2294
- ) || c.FS.writeFile(
2295
- `/internal/shared/extensions/${n}`,
2296
- new Uint8Array(_)
2297
- ), w.fileExists(
2298
- c.FS,
2299
- "/internal/shared/extensions/intl.ini"
2300
- ) || c.FS.writeFile(
2301
- "/internal/shared/extensions/intl.ini",
2302
- [
2303
- `extension=/internal/shared/extensions/${n}`
2304
- ].join(`
2305
- `)
2306
- ), w.fileExists(
2307
- c.FS,
2308
- `${c.ENV.ICU_DATA}/${r}`
2309
- ) || (c.FS.mkdirTree(c.ENV.ICU_DATA), c.FS.writeFile(
2310
- `${c.ENV.ICU_DATA}/icudt74l.dat`,
2311
- new Uint8Array(S)
2312
- ));
2322
+ extraFiles: {
2323
+ targetPath: "/internal/shared",
2324
+ files: {
2325
+ // The Intl extension looks for the hard-coded ICU data name.
2326
+ "icudt74l.dat": new Uint8Array(c)
2327
+ }
2313
2328
  }
2314
- };
2329
+ });
2315
2330
  }
2316
- const nt = () => ({
2331
+ const ct = () => ({
2317
2332
  websocket: {
2318
2333
  decorator: (i) => class extends i {
2319
2334
  constructor() {
@@ -2328,24 +2343,47 @@ const nt = () => ({
2328
2343
  }
2329
2344
  }
2330
2345
  });
2331
- async function ft(i, e = {}) {
2332
- var s;
2333
- "setImmediate" in globalThis || (globalThis.setImmediate = (a) => setTimeout(a, 0));
2334
- let t = {
2335
- ...nt(),
2336
- ...e.emscriptenOptions || {}
2346
+ async function Dt(i, e = {}) {
2347
+ var c;
2348
+ "setImmediate" in globalThis || (globalThis.setImmediate = (S) => setTimeout(S, 0));
2349
+ const t = await Ue() ? "jspi" : "asyncify";
2350
+ let n = {
2351
+ ...ct(),
2352
+ ...e.emscriptenOptions || {},
2353
+ phpWasmAsyncMode: t
2337
2354
  };
2338
- e.tcpOverFetch && (t = Ye(
2339
- t,
2355
+ e.tcpOverFetch && (n = tt(
2356
+ n,
2340
2357
  e.tcpOverFetch
2341
- )), e.withIntl && (t = tt(i, t));
2342
- const [n, r] = await Promise.all([
2343
- Pe(i),
2344
- t
2358
+ ));
2359
+ const r = Ke(i), s = [...e.extensions ?? []];
2360
+ if (e.withIntl && !St(s, "intl") && s.push("intl"), r) {
2361
+ const S = await n, C = S.preRun || [];
2362
+ n = {
2363
+ ...S,
2364
+ preRun: [...C, De()]
2365
+ };
2366
+ }
2367
+ if (r && s.length)
2368
+ throw new Error(
2369
+ `Extensions are not available for legacy PHP ${i}.`
2370
+ );
2371
+ r || (n = _t(
2372
+ i,
2373
+ t,
2374
+ await n,
2375
+ s
2376
+ ));
2377
+ const [a, _] = await Promise.all([
2378
+ xe(i),
2379
+ n
2345
2380
  ]);
2346
- return (s = e.onPhpLoaderModuleLoaded) == null || s.call(e, n), await me(n, r);
2381
+ return (c = e.onPhpLoaderModuleLoaded) == null || c.call(e, a), await We(a, _);
2382
+ }
2383
+ function St(i, e) {
2384
+ return i.some((t) => typeof t == "string" ? t === e : !("source" in t) && t.name === e);
2347
2385
  }
2348
- function pt(i, e) {
2386
+ function Wt(i, e) {
2349
2387
  window.addEventListener("message", (t) => {
2350
2388
  t.source === i.contentWindow && (e && t.origin !== e || typeof t.data != "object" || t.data.type !== "relay" || window.parent.postMessage(t.data, "*"));
2351
2389
  }), window.addEventListener("message", (t) => {
@@ -2353,7 +2391,7 @@ function pt(i, e) {
2353
2391
  t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (n = i == null ? void 0 : i.contentWindow) == null || n.postMessage(t.data));
2354
2392
  });
2355
2393
  }
2356
- async function wt(i) {
2394
+ async function Pt(i) {
2357
2395
  const e = new Worker(i, { type: "module" });
2358
2396
  return new Promise((t, n) => {
2359
2397
  e.onerror = (s) => {
@@ -2368,7 +2406,8 @@ async function wt(i) {
2368
2406
  e.addEventListener("message", r);
2369
2407
  });
2370
2408
  }
2371
- function Lt(i, e = { initialSync: {} }) {
2409
+ const Ct = 1e3;
2410
+ function bt(i, e = { initialSync: {} }) {
2372
2411
  return e = {
2373
2412
  ...e,
2374
2413
  initialSync: {
@@ -2376,57 +2415,60 @@ function Lt(i, e = { initialSync: {} }) {
2376
2415
  direction: e.initialSync.direction ?? "opfs-to-memfs"
2377
2416
  }
2378
2417
  }, async function(t, n, r) {
2379
- return e.initialSync.direction === "opfs-to-memfs" ? (w.fileExists(n, r) && w.rmdir(n, r), w.mkdir(n, r), await rt(n, i, r)) : await fe(
2418
+ var a;
2419
+ 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(
2380
2420
  n,
2381
2421
  i,
2382
2422
  r,
2383
2423
  e.initialSync.onProgress
2384
- ), it(t, i, r);
2424
+ );
2425
+ const s = At(t, i, r);
2426
+ return (a = e.onMount) == null || a.call(e, s), s.unmount;
2385
2427
  };
2386
2428
  }
2387
- async function rt(i, e, t) {
2388
- w.mkdir(i, t);
2389
- const n = new ge({
2429
+ async function lt(i, e, t) {
2430
+ M.mkdir(i, t);
2431
+ const n = new Pe({
2390
2432
  concurrency: 40
2391
2433
  }), r = [], s = [
2392
2434
  [e, t]
2393
2435
  ];
2394
2436
  for (; s.length > 0; ) {
2395
2437
  const [a, _] = s.pop();
2396
- for await (const S of a.values()) {
2397
- const c = n.run(async () => {
2398
- const C = ae(
2438
+ for await (const c of a.values()) {
2439
+ const S = n.run(async () => {
2440
+ const C = ce(
2399
2441
  _,
2400
- S.name
2442
+ c.name
2401
2443
  );
2402
- if (S.kind === "directory") {
2444
+ if (c.kind === "directory") {
2403
2445
  try {
2404
2446
  i.mkdir(C);
2405
2447
  } catch (h) {
2406
2448
  if ((h == null ? void 0 : h.errno) !== 20)
2407
- throw U.error(h), h;
2449
+ throw B.error(h), h;
2408
2450
  }
2409
- s.push([S, C]);
2410
- } else if (S.kind === "file") {
2411
- const h = await S.getFile(), A = new Uint8Array(await h.arrayBuffer());
2451
+ s.push([c, C]);
2452
+ } else if (c.kind === "file") {
2453
+ const h = await c.getFile(), A = new Uint8Array(await h.arrayBuffer());
2412
2454
  i.createDataFile(
2413
2455
  _,
2414
- S.name,
2456
+ c.name,
2415
2457
  A,
2416
2458
  !0,
2417
2459
  !0,
2418
2460
  !0
2419
2461
  );
2420
2462
  }
2421
- r.splice(r.indexOf(c), 1);
2463
+ r.splice(r.indexOf(S), 1);
2422
2464
  });
2423
- r.push(c);
2465
+ r.push(S);
2424
2466
  }
2425
2467
  for (; s.length === 0 && r.length > 0; )
2426
2468
  await Promise.any(r);
2427
2469
  }
2428
2470
  }
2429
- async function fe(i, e, t, n) {
2471
+ async function ye(i, e, t, n) {
2430
2472
  i.mkdirTree(t);
2431
2473
  const r = [];
2432
2474
  async function s(C, h) {
@@ -2434,47 +2476,47 @@ async function fe(i, e, t, n) {
2434
2476
  i.readdir(C).filter(
2435
2477
  (A) => A !== "." && A !== ".."
2436
2478
  ).map(async (A) => {
2437
- const d = ae(C, A);
2438
- if (!st(i, d)) {
2439
- r.push([h, d, A]);
2479
+ const u = ce(C, A);
2480
+ if (!ht(i, u)) {
2481
+ r.push([h, u, A]);
2440
2482
  return;
2441
2483
  }
2442
- const M = await h.getDirectoryHandle(A, {
2484
+ const T = await h.getDirectoryHandle(A, {
2443
2485
  create: !0
2444
2486
  });
2445
- return await s(d, M);
2487
+ return await s(u, T);
2446
2488
  })
2447
2489
  );
2448
2490
  }
2449
2491
  await s(t, e);
2450
2492
  let a = 0;
2451
- const _ = n && ot(n, 100), S = 100, c = /* @__PURE__ */ new Set();
2493
+ const _ = n && dt(n, 100), c = 100, S = /* @__PURE__ */ new Set();
2452
2494
  try {
2453
2495
  for (const [C, h, A] of r) {
2454
- const d = j(
2496
+ const u = $(
2455
2497
  C,
2456
2498
  A,
2457
2499
  i,
2458
2500
  h
2459
2501
  ).then(() => {
2460
- a++, c.delete(d), _ == null || _({
2502
+ a++, S.delete(u), _ == null || _({
2461
2503
  files: a,
2462
2504
  total: r.length
2463
2505
  });
2464
2506
  });
2465
- c.add(d), c.size >= S && (await Promise.race(c), _ == null || _({
2507
+ S.add(u), S.size >= c && (await Promise.race(S), _ == null || _({
2466
2508
  files: a,
2467
2509
  total: r.length
2468
2510
  }));
2469
2511
  }
2470
2512
  } finally {
2471
- await Promise.allSettled(c);
2513
+ await Promise.allSettled(S);
2472
2514
  }
2473
2515
  }
2474
- function st(i, e) {
2516
+ function ht(i, e) {
2475
2517
  return i.isDir(i.lookupPath(e, { follow: !0 }).node.mode);
2476
2518
  }
2477
- async function j(i, e, t, n) {
2519
+ async function $(i, e, t, n) {
2478
2520
  let r;
2479
2521
  try {
2480
2522
  r = t.readFile(n, {
@@ -2496,38 +2538,69 @@ async function j(i, e, t, n) {
2496
2538
  await a.close();
2497
2539
  }
2498
2540
  }
2499
- function it(i, e, t) {
2500
- const n = [], r = We(i, t, (_) => {
2501
- n.push(_);
2502
- }), s = new at(i, e, t);
2503
- async function a() {
2504
- if (n.length === 0)
2541
+ function At(i, e, t, n = {}) {
2542
+ const r = [], s = ve(i, t, (u) => {
2543
+ r.push(u);
2544
+ }), a = new ut(i, e, t);
2545
+ let _;
2546
+ function c() {
2547
+ return _ === void 0 && (_ = h().finally(() => {
2548
+ _ = void 0;
2549
+ })), _;
2550
+ }
2551
+ async function S() {
2552
+ try {
2553
+ await c();
2554
+ } finally {
2555
+ s(), i.removeEventListener("request.end", C), i.removeEventListener("filesystem.write", C);
2556
+ }
2557
+ }
2558
+ function C() {
2559
+ c().catch((u) => {
2560
+ B.error(u);
2561
+ });
2562
+ }
2563
+ async function h() {
2564
+ const u = n.maxFlushPasses ?? Ct;
2565
+ for (let T = 0; r.length > 0; T++) {
2566
+ if (T >= u) {
2567
+ const y = r.length, U = y === 1 ? `${y} journal entry remains` : `${y} journal entries remain`;
2568
+ throw new Error(
2569
+ `OPFS flush for "${t}" did not settle after ${u} journal batches; ${U}. This can happen when filesystem writes are continuously enqueued while flushing.`
2570
+ );
2571
+ }
2572
+ await A();
2573
+ }
2574
+ }
2575
+ async function A() {
2576
+ if (r.length === 0)
2505
2577
  return;
2506
- const _ = await i.semaphore.acquire(), S = [...n];
2507
- n.splice(0, S.length);
2508
- const c = be(S);
2578
+ const u = await i.semaphore.acquire(), T = [...r];
2579
+ r.splice(0, T.length);
2580
+ const y = Me(T);
2509
2581
  try {
2510
- for (const C of c)
2511
- await s.processEntry(C);
2582
+ for (const U of y)
2583
+ await a.processEntry(U);
2512
2584
  } finally {
2513
- _();
2585
+ u();
2514
2586
  }
2515
2587
  }
2516
- return i.addEventListener("request.end", a), i.addEventListener("filesystem.write", a), function() {
2517
- r(), i.removeEventListener("request.end", a), i.removeEventListener("filesystem.write", a);
2588
+ return i.addEventListener("request.end", C), i.addEventListener("filesystem.write", C), {
2589
+ flush: c,
2590
+ unmount: S
2518
2591
  };
2519
2592
  }
2520
- class at {
2593
+ class ut {
2521
2594
  constructor(e, t, n) {
2522
- this.php = e, this.opfs = t, this.memfsRoot = se(n);
2595
+ this.php = e, this.opfs = t, this.memfsRoot = ae(n);
2523
2596
  }
2524
2597
  toOpfsPath(e) {
2525
- return se(e.substring(this.memfsRoot.length));
2598
+ return ae(e.substring(this.memfsRoot.length));
2526
2599
  }
2527
2600
  async processEntry(e) {
2528
2601
  if (!e.path.startsWith(this.memfsRoot) || e.path === this.memfsRoot)
2529
2602
  return;
2530
- const t = this.toOpfsPath(e.path), n = await ie(this.opfs, t), r = _t(t);
2603
+ const t = this.toOpfsPath(e.path), n = await _e(this.opfs, t), r = Ht(t);
2531
2604
  if (r)
2532
2605
  try {
2533
2606
  if (e.operation === "DELETE")
@@ -2544,14 +2617,14 @@ class at {
2544
2617
  create: !0
2545
2618
  });
2546
2619
  else if (e.operation === "WRITE")
2547
- await j(
2620
+ await $(
2548
2621
  n,
2549
2622
  r,
2550
- this.php[F].FS,
2623
+ this.php[O].FS,
2551
2624
  e.path
2552
2625
  );
2553
2626
  else if (e.operation === "RENAME" && e.toPath.startsWith(this.memfsRoot)) {
2554
- const s = this.toOpfsPath(e.toPath), a = await ie(
2627
+ const s = this.toOpfsPath(e.toPath), a = await _e(
2555
2628
  this.opfs,
2556
2629
  s
2557
2630
  );
@@ -2562,8 +2635,8 @@ class at {
2562
2635
  create: !0
2563
2636
  }
2564
2637
  );
2565
- await fe(
2566
- this.php[F].FS,
2638
+ await ye(
2639
+ this.php[O].FS,
2567
2640
  _,
2568
2641
  e.toPath
2569
2642
  ), await n.removeEntry(r, {
@@ -2574,26 +2647,26 @@ class at {
2574
2647
  await n.removeEntry(r);
2575
2648
  } catch {
2576
2649
  }
2577
- await j(
2650
+ await $(
2578
2651
  a,
2579
- Ie(s),
2580
- this.php[F].FS,
2652
+ be(s),
2653
+ this.php[O].FS,
2581
2654
  e.toPath
2582
2655
  );
2583
2656
  }
2584
2657
  }
2585
2658
  } catch (s) {
2586
- throw U.log({ entry: e, name: r }), U.error(s), s;
2659
+ throw B.log({ entry: e, name: r }), B.error(s), s;
2587
2660
  }
2588
2661
  }
2589
2662
  }
2590
- function se(i) {
2663
+ function ae(i) {
2591
2664
  return i.replace(/\/$/, "").replace(/\/\/+/g, "/");
2592
2665
  }
2593
- function _t(i) {
2666
+ function Ht(i) {
2594
2667
  return i.substring(i.lastIndexOf("/") + 1);
2595
2668
  }
2596
- async function ie(i, e) {
2669
+ async function _e(i, e) {
2597
2670
  const t = e.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
2598
2671
  if (!t)
2599
2672
  return i;
@@ -2605,31 +2678,31 @@ async function ie(i, e) {
2605
2678
  }
2606
2679
  return r;
2607
2680
  }
2608
- function ot(i, e) {
2681
+ function dt(i, e) {
2609
2682
  let t = 0, n, r;
2610
2683
  return function(...a) {
2611
2684
  r = a;
2612
2685
  const _ = Date.now() - t;
2613
2686
  if (n === void 0) {
2614
- const S = Math.max(0, e - _);
2687
+ const c = Math.max(0, e - _);
2615
2688
  n = setTimeout(() => {
2616
2689
  n = void 0, t = Date.now(), i(...r);
2617
- }, S);
2690
+ }, c);
2618
2691
  }
2619
2692
  };
2620
2693
  }
2621
2694
  export {
2622
- Dt as FirewallInterferenceError,
2623
- dt as certificateToPEM,
2624
- gt as consumeAPI,
2625
- Lt as createDirectoryHandleMountHandler,
2626
- It as exposeAPI,
2627
- Wt as fetchWithCorsProxy,
2628
- je as generateCertificate,
2629
- Pe as getPHPLoaderModule,
2630
- ft as loadWebRuntime,
2631
- Et as privateKeyToPEM,
2632
- pt as setupPostMessageRelay,
2633
- wt as spawnPHPWorkerThread
2695
+ xt as FirewallInterferenceError,
2696
+ gt as certificateToPEM,
2697
+ Ut as consumeAPI,
2698
+ bt as createDirectoryHandleMountHandler,
2699
+ vt as exposeAPI,
2700
+ Nt as fetchWithCorsProxy,
2701
+ Ze as generateCertificate,
2702
+ xe as getPHPLoaderModule,
2703
+ Dt as loadWebRuntime,
2704
+ It as privateKeyToPEM,
2705
+ Wt as setupPostMessageRelay,
2706
+ Pt as spawnPHPWorkerThread
2634
2707
  };
2635
2708
  //# sourceMappingURL=index.js.map