@php-wasm/web 1.0.15 → 1.0.16

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,41 +1,42 @@
1
1
  import { PHPResponse as we, LatestSupportedPHPVersion as Le, loadPHPRuntime as me, FSHelpers as B, __private__dont__use as k } from "@php-wasm/universal";
2
2
  import * as E from "comlink";
3
3
  import { jspi as ye } from "wasm-feature-detect";
4
- import { logger as b } from "@php-wasm/logger";
5
- import { Semaphore as ge, joinPaths as se } from "@php-wasm/util";
6
- import { journalFSEvents as Ke } from "@php-wasm/fs-journal";
7
- function _t(s, e = void 0) {
4
+ import { logger as R } from "@php-wasm/logger";
5
+ import { cloneRequest as ge } from "@php-wasm/web-service-worker";
6
+ import { Semaphore as Ke, joinPaths as se } from "@php-wasm/util";
7
+ import { journalFSEvents as Ie } from "@php-wasm/fs-journal";
8
+ function ct(n, e = void 0) {
8
9
  ie();
9
- const t = s instanceof Worker ? s : E.windowEndpoint(s, e), r = E.wrap(t), n = x(r);
10
- return new Proxy(n, {
10
+ const t = n instanceof Worker ? n : E.windowEndpoint(n, e), r = E.wrap(t), s = x(r);
11
+ return new Proxy(s, {
11
12
  get: (i, _) => _ === "isConnected" ? async () => {
12
13
  for (; ; )
13
14
  try {
14
- await Ie(r.isConnected(), 200);
15
+ await De(r.isConnected(), 200);
15
16
  break;
16
17
  } catch {
17
18
  }
18
19
  } : r[_]
19
20
  });
20
21
  }
21
- async function Ie(s, e) {
22
+ async function De(n, e) {
22
23
  return new Promise((t, r) => {
23
- setTimeout(r, e), s.then(t);
24
+ setTimeout(r, e), n.then(t);
24
25
  });
25
26
  }
26
- function at(s, e) {
27
+ function St(n, e) {
27
28
  ie();
28
29
  const t = Promise.resolve();
29
- let r, n;
30
+ let r, s;
30
31
  const i = new Promise((c, S) => {
31
- r = c, n = S;
32
- }), _ = x(s), a = new Proxy(_, {
32
+ r = c, s = S;
33
+ }), _ = x(n), a = new Proxy(_, {
33
34
  get: (c, S) => S === "isConnected" ? () => t : S === "isReady" ? () => i : S in c ? c[S] : e == null ? void 0 : e[S]
34
35
  });
35
36
  return E.expose(
36
37
  a,
37
38
  typeof window < "u" ? E.windowEndpoint(self.parent) : void 0
38
- ), [r, n, a];
39
+ ), [r, s, a];
39
40
  }
40
41
  let F = !1;
41
42
  function ie() {
@@ -53,8 +54,8 @@ function ie() {
53
54
  }), E.transferHandlers.set("FUNCTION", {
54
55
  canHandle: (t) => typeof t == "function",
55
56
  serialize(t) {
56
- const { port1: r, port2: n } = new MessageChannel();
57
- return E.expose(t, r), [n, [n]];
57
+ const { port1: r, port2: s } = new MessageChannel();
58
+ return E.expose(t, r), [s, [s]];
58
59
  },
59
60
  deserialize(t) {
60
61
  return t.start(), E.wrap(t);
@@ -68,14 +69,14 @@ function ie() {
68
69
  return we.fromRawData(t);
69
70
  }
70
71
  });
71
- const s = E.transferHandlers.get("throw"), e = s == null ? void 0 : s.serialize;
72
- s.serialize = ({ value: t }) => {
72
+ const n = E.transferHandlers.get("throw"), e = n == null ? void 0 : n.serialize;
73
+ n.serialize = ({ value: t }) => {
73
74
  const r = e({ value: t });
74
75
  return t.response && (r[0].value.response = t.response), t.source && (r[0].value.source = t.source), r;
75
76
  };
76
77
  }
77
- function x(s) {
78
- return new Proxy(s, {
78
+ function x(n) {
79
+ return new Proxy(n, {
79
80
  get(e, t) {
80
81
  switch (typeof e[t]) {
81
82
  case "function":
@@ -92,9 +93,9 @@ function x(s) {
92
93
  }
93
94
  });
94
95
  }
95
- async function De(s = Le) {
96
+ async function We(n = Le) {
96
97
  if (await ye())
97
- switch (s) {
98
+ switch (n) {
98
99
  case "8.3":
99
100
  return await import("./php/jspi/php_8_3.js");
100
101
  case "8.2":
@@ -115,7 +116,7 @@ async function De(s = Le) {
115
116
  return await import("./php/jspi/php_7_0.js");
116
117
  }
117
118
  else
118
- switch (s) {
119
+ switch (n) {
119
120
  case "8.3":
120
121
  return await import("./php/asyncify/php_8_3.js");
121
122
  case "8.2":
@@ -135,36 +136,36 @@ async function De(s = Le) {
135
136
  case "7.0":
136
137
  return await import("./php/asyncify/php_7_0.js");
137
138
  }
138
- throw new Error(`Unsupported PHP version ${s}`);
139
+ throw new Error(`Unsupported PHP version ${n}`);
139
140
  }
140
- function p(s) {
141
- return Object.fromEntries(Object.entries(s).map(([e, t]) => [t, e]));
141
+ function p(n) {
142
+ return Object.fromEntries(Object.entries(n).map(([e, t]) => [t, e]));
142
143
  }
143
- function h(s) {
144
+ function h(n) {
144
145
  let e = 0;
145
- s.forEach((n) => e += n.length);
146
+ n.forEach((s) => e += s.length);
146
147
  const t = new Uint8Array(e);
147
148
  let r = 0;
148
- return s.forEach((n) => {
149
- t.set(n, r), r += n.length;
149
+ return n.forEach((s) => {
150
+ t.set(s, r), r += s.length;
150
151
  }), t;
151
152
  }
152
- function P(s) {
153
- return h(s.map((e) => new Uint8Array(e))).buffer;
153
+ function P(n) {
154
+ return h(n.map((e) => new Uint8Array(e))).buffer;
154
155
  }
155
- function I(s) {
156
- return new Uint8Array([s >> 8 & 255, s & 255]);
156
+ function I(n) {
157
+ return new Uint8Array([n >> 8 & 255, n & 255]);
157
158
  }
158
- function m(s) {
159
+ function m(n) {
159
160
  return new Uint8Array([
160
- s >> 16 & 255,
161
- s >> 8 & 255,
162
- s & 255
161
+ n >> 16 & 255,
162
+ n >> 8 & 255,
163
+ n & 255
163
164
  ]);
164
165
  }
165
- function G(s) {
166
+ function G(n) {
166
167
  const e = new ArrayBuffer(8);
167
- return new DataView(e).setBigUint64(0, BigInt(s), !1), new Uint8Array(e);
168
+ return new DataView(e).setBigUint64(0, BigInt(n), !1), new Uint8Array(e);
168
169
  }
169
170
  class g {
170
171
  constructor(e) {
@@ -207,7 +208,7 @@ class v {
207
208
  this.uint8Array.set(e, this.offset), this.offset += e.length;
208
209
  }
209
210
  }
210
- const R = {
211
+ const b = {
211
212
  server_name: 0,
212
213
  max_fragment_length: 1,
213
214
  client_certificate_url: 2,
@@ -261,17 +262,17 @@ const R = {
261
262
  key_share: 51,
262
263
  transparency_info: 52,
263
264
  connection_id: 54
264
- }, We = p(R), _e = {
265
+ }, Re = p(b), _e = {
265
266
  host_name: 0
266
267
  }, be = p(_e);
267
268
  class ae {
268
269
  static decodeFromClient(e) {
269
270
  const t = new DataView(e.buffer);
270
271
  let r = 0;
271
- const n = t.getUint16(r);
272
+ const s = t.getUint16(r);
272
273
  r += 2;
273
274
  const i = [];
274
- for (; r < n + 2; ) {
275
+ for (; r < s + 2; ) {
275
276
  const _ = e[r];
276
277
  r += 1;
277
278
  const a = t.getUint16(r);
@@ -309,7 +310,7 @@ class ae {
309
310
  "Encoding non-empty lists for ClientHello is not supported yet. Only empty lists meant for ServerHello are supported today."
310
311
  );
311
312
  const t = new v(4);
312
- return t.writeUint16(R.server_name), t.writeUint16(0), t.uint8Array;
313
+ return t.writeUint16(b.server_name), t.writeUint16(0), t.uint8Array;
313
314
  }
314
315
  }
315
316
  const oe = {
@@ -543,8 +544,8 @@ class Se {
543
544
  t.readUint16();
544
545
  const r = [];
545
546
  for (; !t.isFinished(); ) {
546
- const n = t.readUint16();
547
- n in $ && r.push($[n]);
547
+ const s = t.readUint16();
548
+ s in $ && r.push($[s]);
548
549
  }
549
550
  return r;
550
551
  }
@@ -560,7 +561,7 @@ class Se {
560
561
  */
561
562
  static encodeForClient(e) {
562
563
  const t = new v(6);
563
- return t.writeUint16(R.supported_groups), t.writeUint16(2), t.writeUint16(ce[e]), t.uint8Array;
564
+ return t.writeUint16(b.supported_groups), t.writeUint16(2), t.writeUint16(ce[e]), t.uint8Array;
564
565
  }
565
566
  }
566
567
  const Ce = {
@@ -585,12 +586,12 @@ class le {
585
586
  * +--------------------------------------------------+
586
587
  */
587
588
  static decodeFromClient(e) {
588
- const t = new g(e.buffer), r = t.readUint8(), n = [];
589
+ const t = new g(e.buffer), r = t.readUint8(), s = [];
589
590
  for (let i = 0; i < r; i++) {
590
591
  const _ = t.readUint8();
591
- _ in V && n.push(V[_]);
592
+ _ in V && s.push(V[_]);
592
593
  }
593
- return n;
594
+ return s;
594
595
  }
595
596
  /**
596
597
  * Encode the ec_point_formats extension
@@ -608,7 +609,7 @@ class le {
608
609
  */
609
610
  static encodeForClient(e) {
610
611
  const t = new v(6);
611
- return t.writeUint16(R.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(Ce[e]), t.uint8Array;
612
+ return t.writeUint16(b.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(Ce[e]), t.uint8Array;
612
613
  }
613
614
  }
614
615
  const N = {
@@ -646,18 +647,18 @@ class Ae {
646
647
  t.readUint16();
647
648
  const r = [];
648
649
  for (; !t.isFinished(); ) {
649
- const n = t.readUint8(), i = t.readUint8();
650
+ const s = t.readUint8(), i = t.readUint8();
650
651
  if (!z[i]) {
651
- b.warn(`Unknown signature algorithm: ${i}`);
652
+ R.warn(`Unknown signature algorithm: ${i}`);
652
653
  continue;
653
654
  }
654
- if (!Y[n]) {
655
- b.warn(`Unknown hash algorithm: ${n}`);
655
+ if (!Y[s]) {
656
+ R.warn(`Unknown hash algorithm: ${s}`);
656
657
  continue;
657
658
  }
658
659
  r.push({
659
660
  algorithm: z[i],
660
- hash: Y[n]
661
+ hash: Y[s]
661
662
  });
662
663
  }
663
664
  return r;
@@ -675,7 +676,7 @@ class Ae {
675
676
  */
676
677
  static encodeforClient(e, t) {
677
678
  const r = new v(6);
678
- return r.writeUint16(R.signature_algorithms), r.writeUint16(2), r.writeUint8(O[e]), r.writeUint8(N[t]), r.uint8Array;
679
+ return r.writeUint16(b.signature_algorithms), r.writeUint16(2), r.writeUint8(O[e]), r.writeUint8(N[t]), r.uint8Array;
679
680
  }
680
681
  }
681
682
  const J = {
@@ -684,50 +685,50 @@ const J = {
684
685
  supported_groups: Se,
685
686
  ec_point_formats: le
686
687
  };
687
- function Re(s) {
688
- const e = new g(s.buffer), t = [];
688
+ function Pe(n) {
689
+ const e = new g(n.buffer), t = [];
689
690
  for (; !e.isFinished(); ) {
690
- const r = e.offset, n = e.readUint16(), i = We[n], _ = e.readUint16(), a = e.readUint8Array(_);
691
+ const r = e.offset, s = e.readUint16(), i = Re[s], _ = e.readUint16(), a = e.readUint8Array(_);
691
692
  if (!(i in J))
692
693
  continue;
693
694
  const c = J[i];
694
695
  t.push({
695
696
  type: i,
696
697
  data: c.decodeFromClient(a),
697
- raw: s.slice(r, r + 4 + _)
698
+ raw: n.slice(r, r + 4 + _)
698
699
  });
699
700
  }
700
701
  return t;
701
702
  }
702
- async function M(s, e, t, r) {
703
- const n = P([e, t]), i = await crypto.subtle.importKey(
703
+ async function M(n, e, t, r) {
704
+ const s = P([e, t]), i = await crypto.subtle.importKey(
704
705
  "raw",
705
- s,
706
+ n,
706
707
  { name: "HMAC", hash: { name: "SHA-256" } },
707
708
  !1,
708
709
  ["sign"]
709
710
  );
710
- let _ = n;
711
+ let _ = s;
711
712
  const a = [];
712
713
  for (; P(a).byteLength < r; ) {
713
714
  _ = await X(i, _);
714
- const S = P([_, n]), l = await X(i, S);
715
+ const S = P([_, s]), l = await X(i, S);
715
716
  a.push(l);
716
717
  }
717
718
  return P(a).slice(0, r);
718
719
  }
719
- async function X(s, e) {
720
+ async function X(n, e) {
720
721
  return await crypto.subtle.sign(
721
722
  { name: "HMAC", hash: "SHA-256" },
722
- s,
723
+ n,
723
724
  e
724
725
  );
725
726
  }
726
- var ue = /* @__PURE__ */ ((s) => (s[s.Null = 0] = "Null", s[s.Deflate = 1] = "Deflate", s))(ue || {});
727
- const Pe = {
727
+ var ue = /* @__PURE__ */ ((n) => (n[n.Null = 0] = "Null", n[n.Deflate = 1] = "Deflate", n))(ue || {});
728
+ const Be = {
728
729
  Warning: 1,
729
730
  Fatal: 2
730
- }, he = p(Pe), Be = {
731
+ }, he = p(Be), Ue = {
731
732
  CloseNotify: 0,
732
733
  UnexpectedMessage: 10,
733
734
  BadRecordMac: 20,
@@ -753,14 +754,14 @@ const Pe = {
753
754
  UserCanceled: 90,
754
755
  NoRenegotiation: 100,
755
756
  UnsupportedExtension: 110
756
- }, He = p(Be), C = {
757
+ }, He = p(Ue), C = {
757
758
  ChangeCipherSpec: 20,
758
759
  Alert: 21,
759
760
  Handshake: 22,
760
761
  ApplicationData: 23
761
762
  };
762
- var d = /* @__PURE__ */ ((s) => (s[s.HelloRequest = 0] = "HelloRequest", s[s.ClientHello = 1] = "ClientHello", s[s.ServerHello = 2] = "ServerHello", s[s.Certificate = 11] = "Certificate", s[s.ServerKeyExchange = 12] = "ServerKeyExchange", s[s.CertificateRequest = 13] = "CertificateRequest", s[s.ServerHelloDone = 14] = "ServerHelloDone", s[s.CertificateVerify = 15] = "CertificateVerify", s[s.ClientKeyExchange = 16] = "ClientKeyExchange", s[s.Finished = 20] = "Finished", s))(d || {});
763
- const Ue = {
763
+ var d = /* @__PURE__ */ ((n) => (n[n.HelloRequest = 0] = "HelloRequest", n[n.ClientHello = 1] = "ClientHello", n[n.ServerHello = 2] = "ServerHello", n[n.Certificate = 11] = "Certificate", n[n.ServerKeyExchange = 12] = "ServerKeyExchange", n[n.CertificateRequest = 13] = "CertificateRequest", n[n.ServerHelloDone = 14] = "ServerHelloDone", n[n.CertificateVerify = 15] = "CertificateVerify", n[n.ClientKeyExchange = 16] = "ClientKeyExchange", n[n.Finished = 20] = "Finished", n))(d || {});
764
+ const ve = {
764
765
  /**
765
766
  * Indicates the elliptic curve domain parameters are
766
767
  * conveyed verbosely, and the underlying finite field is a prime
@@ -781,7 +782,7 @@ const Ue = {
781
782
  /**
782
783
  * Values 248 through 255 are reserved for private use.
783
784
  */
784
- }, ve = {
785
+ }, Me = {
785
786
  sect163k1: 1,
786
787
  sect163r1: 2,
787
788
  sect163r2: 3,
@@ -803,7 +804,7 @@ const Ue = {
803
804
  };
804
805
  class Z extends Error {
805
806
  }
806
- const U = new Uint8Array([3, 3]), Me = crypto.subtle.generateKey(
807
+ const U = new Uint8Array([3, 3]), xe = crypto.subtle.generateKey(
807
808
  {
808
809
  name: "ECDH",
809
810
  namedCurve: "P-256"
@@ -814,7 +815,7 @@ const U = new Uint8Array([3, 3]), Me = crypto.subtle.generateKey(
814
815
  ["deriveKey", "deriveBits"]
815
816
  // Key usage
816
817
  );
817
- class xe {
818
+ class Ne {
818
819
  constructor() {
819
820
  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 = {
820
821
  // We don't need to chunk the encrypted data.
@@ -831,7 +832,7 @@ class xe {
831
832
  * This will spread some messages across multiple records,
832
833
  * but TLS supports it so that's fine.
833
834
  */
834
- downstream: Ne(this.MAX_CHUNK_SIZE)
835
+ downstream: Oe(this.MAX_CHUNK_SIZE)
835
836
  }, this.serverUpstreamWriter = this.serverEnd.upstream.writable.getWriter();
836
837
  const e = this;
837
838
  this.serverEnd.downstream.readable.pipeTo(
@@ -894,21 +895,21 @@ class xe {
894
895
  throw new Error(
895
896
  "Client did not propose any supported cipher suites."
896
897
  );
897
- const n = crypto.getRandomValues(new Uint8Array(32));
898
+ const s = crypto.getRandomValues(new Uint8Array(32));
898
899
  await this.writeTLSRecord(
899
900
  C.Handshake,
900
901
  K.serverHello(
901
902
  r.body,
902
- n,
903
+ s,
903
904
  ue.Null
904
905
  )
905
906
  ), await this.writeTLSRecord(
906
907
  C.Handshake,
907
908
  K.certificate(t)
908
909
  );
909
- const i = await Me, _ = r.body.random, a = await K.ECDHEServerKeyExchange(
910
+ const i = await xe, _ = r.body.random, a = await K.ECDHEServerKeyExchange(
910
911
  _,
911
- n,
912
+ s,
912
913
  i,
913
914
  e
914
915
  );
@@ -921,7 +922,7 @@ class xe {
921
922
  );
922
923
  await this.readNextMessage(C.ChangeCipherSpec), this.sessionKeys = await this.deriveSessionKeys({
923
924
  clientRandom: _,
924
- serverRandom: n,
925
+ serverRandom: s,
925
926
  serverPrivateKey: i.privateKey,
926
927
  clientPublicKey: await crypto.subtle.importKey(
927
928
  "raw",
@@ -949,12 +950,12 @@ class xe {
949
950
  clientRandom: e,
950
951
  serverRandom: t,
951
952
  serverPrivateKey: r,
952
- clientPublicKey: n
953
+ clientPublicKey: s
953
954
  }) {
954
955
  const i = await crypto.subtle.deriveBits(
955
956
  {
956
957
  name: "ECDH",
957
- public: n
958
+ public: s
958
959
  },
959
960
  r,
960
961
  256
@@ -1006,11 +1007,11 @@ class xe {
1006
1007
  t
1007
1008
  );
1008
1009
  while (r === !1);
1009
- const n = f.TLSMessage(
1010
+ const s = f.TLSMessage(
1010
1011
  t.type,
1011
1012
  r
1012
1013
  );
1013
- return t.type === C.Handshake && this.handshakeMessages.push(t.fragment), n;
1014
+ return t.type === C.Handshake && this.handshakeMessages.push(t.fragment), s;
1014
1015
  }
1015
1016
  async readNextTLSRecord(e) {
1016
1017
  for (; ; ) {
@@ -1019,14 +1020,14 @@ class xe {
1019
1020
  if (c.type === e)
1020
1021
  return this.receivedTLSRecords.splice(a, 1), c;
1021
1022
  }
1022
- const t = await this.pollBytes(5), r = t[3] << 8 | t[4], n = t[0], i = await this.pollBytes(r), _ = {
1023
- type: n,
1023
+ const t = await this.pollBytes(5), r = t[3] << 8 | t[4], s = t[0], i = await this.pollBytes(r), _ = {
1024
+ type: s,
1024
1025
  version: {
1025
1026
  major: t[1],
1026
1027
  minor: t[2]
1027
1028
  },
1028
1029
  length: r,
1029
- fragment: this.sessionKeys && n !== C.ChangeCipherSpec ? await this.decryptData(n, i) : i
1030
+ fragment: this.sessionKeys && s !== C.ChangeCipherSpec ? await this.decryptData(s, i) : i
1030
1031
  };
1031
1032
  if (_.type === C.Alert) {
1032
1033
  const a = he[_.fragment[0]], c = He[_.fragment[1]];
@@ -1043,8 +1044,8 @@ class xe {
1043
1044
  */
1044
1045
  async pollBytes(e) {
1045
1046
  for (; this.receivedBytesBuffer.length < e; ) {
1046
- const { value: r, done: n } = await this.clientUpstreamReader.read();
1047
- if (n)
1047
+ const { value: r, done: s } = await this.clientUpstreamReader.read();
1048
+ if (s)
1048
1049
  throw await this.close(), new Z("TLS connection closed");
1049
1050
  if (this.receivedBytesBuffer = h([
1050
1051
  this.receivedBytesBuffer,
@@ -1079,7 +1080,7 @@ class xe {
1079
1080
  * the AES-GCM algorithm.
1080
1081
  */
1081
1082
  async decryptData(e, t) {
1082
- const r = this.sessionKeys.clientIV, n = t.slice(0, 8), i = new Uint8Array([...r, ...n]), _ = await crypto.subtle.decrypt(
1083
+ const r = this.sessionKeys.clientIV, s = t.slice(0, 8), i = new Uint8Array([...r, ...s]), _ = await crypto.subtle.decrypt(
1083
1084
  {
1084
1085
  name: "AES-GCM",
1085
1086
  iv: i,
@@ -1135,8 +1136,8 @@ class xe {
1135
1136
  */
1136
1137
  async writeTLSRecord(e, t) {
1137
1138
  e === C.Handshake && this.handshakeMessages.push(t), this.sessionKeys && e !== C.ChangeCipherSpec && (t = await this.encryptData(e, t));
1138
- const r = U, n = t.length, i = new Uint8Array(5);
1139
- i[0] = e, i[1] = r[0], i[2] = r[1], i[3] = n >> 8 & 255, i[4] = n & 255;
1139
+ const r = U, s = t.length, i = new Uint8Array(5);
1140
+ i[0] = e, i[1] = r[0], i[2] = r[1], i[3] = s >> 8 & 255, i[4] = s & 255;
1140
1141
  const _ = h([i, t]);
1141
1142
  this.clientDownstreamWriter.write(_);
1142
1143
  }
@@ -1145,7 +1146,7 @@ class xe {
1145
1146
  * the AES-GCM algorithm.
1146
1147
  */
1147
1148
  async encryptData(e, t) {
1148
- const r = this.sessionKeys.serverIV, n = crypto.getRandomValues(new Uint8Array(8)), i = new Uint8Array([...r, ...n]), _ = new Uint8Array([
1149
+ const r = this.sessionKeys.serverIV, s = crypto.getRandomValues(new Uint8Array(8)), i = new Uint8Array([...r, ...s]), _ = new Uint8Array([
1149
1150
  ...G(this.sentRecordSequenceNumber),
1150
1151
  e,
1151
1152
  ...U,
@@ -1162,7 +1163,7 @@ class xe {
1162
1163
  t
1163
1164
  );
1164
1165
  return ++this.sentRecordSequenceNumber, h([
1165
- n,
1166
+ s,
1166
1167
  new Uint8Array(a)
1167
1168
  ]);
1168
1169
  }
@@ -1210,8 +1211,8 @@ class f {
1210
1211
  t.readUint16();
1211
1212
  const r = [];
1212
1213
  for (; !t.isFinished(); ) {
1213
- const n = t.readUint16();
1214
- n in j && r.push(j[n]);
1214
+ const s = t.readUint16();
1215
+ s in j && r.push(j[s]);
1215
1216
  }
1216
1217
  return r;
1217
1218
  }
@@ -1235,20 +1236,20 @@ class f {
1235
1236
  };
1236
1237
  }
1237
1238
  static clientHandshake(e) {
1238
- const t = e[0], r = e[1] << 16 | e[2] << 8 | e[3], n = e.slice(4);
1239
+ const t = e[0], r = e[1] << 16 | e[2] << 8 | e[3], s = e.slice(4);
1239
1240
  let i;
1240
1241
  switch (t) {
1241
1242
  case d.HelloRequest:
1242
1243
  i = f.clientHelloRequestPayload();
1243
1244
  break;
1244
1245
  case d.ClientHello:
1245
- i = f.clientHelloPayload(n);
1246
+ i = f.clientHelloPayload(s);
1246
1247
  break;
1247
1248
  case d.ClientKeyExchange:
1248
- i = f.clientKeyExchangePayload(n);
1249
+ i = f.clientKeyExchangePayload(s);
1249
1250
  break;
1250
1251
  case d.Finished:
1251
- i = f.clientFinishedPayload(n);
1252
+ i = f.clientFinishedPayload(s);
1252
1253
  break;
1253
1254
  default:
1254
1255
  throw new Error(`Invalid handshake type ${t}`);
@@ -1312,8 +1313,8 @@ class f {
1312
1313
  * parse this further.
1313
1314
  */
1314
1315
  random: t.readUint8Array(32)
1315
- }, n = t.readUint8();
1316
- r.session_id = t.readUint8Array(n);
1316
+ }, s = t.readUint8();
1317
+ r.session_id = t.readUint8Array(s);
1317
1318
  const i = t.readUint16();
1318
1319
  r.cipher_suites = f.parseCipherSuites(
1319
1320
  t.readUint8Array(i).buffer
@@ -1323,7 +1324,7 @@ class f {
1323
1324
  _
1324
1325
  );
1325
1326
  const a = t.readUint16();
1326
- return r.extensions = Re(
1327
+ return r.extensions = Pe(
1327
1328
  t.readUint8Array(a)
1328
1329
  ), r;
1329
1330
  }
@@ -1348,11 +1349,11 @@ class f {
1348
1349
  };
1349
1350
  }
1350
1351
  }
1351
- function Ne(s) {
1352
+ function Oe(n) {
1352
1353
  return new TransformStream({
1353
1354
  transform(e, t) {
1354
1355
  for (; e.length > 0; )
1355
- t.enqueue(e.slice(0, s)), e = e.slice(s);
1356
+ t.enqueue(e.slice(0, n)), e = e.slice(n);
1356
1357
  }
1357
1358
  });
1358
1359
  }
@@ -1361,14 +1362,14 @@ class K {
1361
1362
  const t = [];
1362
1363
  for (const i of e)
1363
1364
  t.push(m(i.byteLength)), t.push(new Uint8Array(i));
1364
- const r = h(t), n = new Uint8Array([
1365
+ const r = h(t), s = new Uint8Array([
1365
1366
  ...m(r.byteLength),
1366
1367
  ...r
1367
1368
  ]);
1368
1369
  return new Uint8Array([
1369
1370
  d.Certificate,
1370
- ...m(n.length),
1371
- ...n
1371
+ ...m(s.length),
1372
+ ...s
1372
1373
  ]);
1373
1374
  }
1374
1375
  /*
@@ -1404,14 +1405,14 @@ class K {
1404
1405
  * @param rsaPrivateKey - RSA private key for signing
1405
1406
  * @returns
1406
1407
  */
1407
- static async ECDHEServerKeyExchange(e, t, r, n) {
1408
+ static async ECDHEServerKeyExchange(e, t, r, s) {
1408
1409
  const i = new Uint8Array(
1409
1410
  await crypto.subtle.exportKey("raw", r.publicKey)
1410
1411
  ), _ = new Uint8Array([
1411
1412
  // Curve type (1 byte)
1412
- Ue.NamedCurve,
1413
+ ve.NamedCurve,
1413
1414
  // Curve name (2 bytes)
1414
- ...I(ve.secp256r1),
1415
+ ...I(Me.secp256r1),
1415
1416
  // Public key length (1 byte)
1416
1417
  i.byteLength,
1417
1418
  // Public key (65 bytes, uncompressed format)
@@ -1421,7 +1422,7 @@ class K {
1421
1422
  name: "RSASSA-PKCS1-v1_5",
1422
1423
  hash: "SHA-256"
1423
1424
  },
1424
- n,
1425
+ s,
1425
1426
  new Uint8Array([...e, ...t, ..._])
1426
1427
  ), c = new Uint8Array(a), S = new Uint8Array([
1427
1428
  O.sha256,
@@ -1477,7 +1478,7 @@ class K {
1477
1478
  * +------------------------------------+
1478
1479
  */
1479
1480
  static serverHello(e, t, r) {
1480
- const n = e.extensions.map((a) => {
1481
+ const s = e.extensions.map((a) => {
1481
1482
  switch (a.type) {
1482
1483
  case "server_name":
1483
1484
  return ae.encodeForClient();
@@ -1495,7 +1496,7 @@ class K {
1495
1496
  "rsa"
1496
1497
  );
1497
1498
  }
1498
- }).filter((a) => a !== void 0), i = h(n), _ = new Uint8Array([
1499
+ }).filter((a) => a !== void 0), i = h(s), _ = new Uint8Array([
1499
1500
  // Version field – 0x03, 0x03 means TLS 1.2
1500
1501
  ...U,
1501
1502
  ...t,
@@ -1538,7 +1539,7 @@ class K {
1538
1539
  const r = await crypto.subtle.digest(
1539
1540
  "SHA-256",
1540
1541
  h(e)
1541
- ), n = new Uint8Array(
1542
+ ), s = new Uint8Array(
1542
1543
  await M(
1543
1544
  t,
1544
1545
  new TextEncoder().encode("server finished"),
@@ -1549,33 +1550,33 @@ class K {
1549
1550
  );
1550
1551
  return new Uint8Array([
1551
1552
  d.Finished,
1552
- ...m(n.length),
1553
- ...n
1553
+ ...m(s.length),
1554
+ ...s
1554
1555
  ]);
1555
1556
  }
1556
1557
  static changeCipherSpec() {
1557
1558
  return new Uint8Array([1]);
1558
1559
  }
1559
1560
  }
1560
- function Oe(s, e) {
1561
- return qe.generateCertificate(s, e);
1561
+ function qe(n, e) {
1562
+ return ke.generateCertificate(n, e);
1562
1563
  }
1563
- function ot(s) {
1564
+ function Ct(n) {
1564
1565
  return `-----BEGIN CERTIFICATE-----
1565
1566
  ${fe(
1566
- de(s.buffer)
1567
+ de(n.buffer)
1567
1568
  )}
1568
1569
  -----END CERTIFICATE-----`;
1569
1570
  }
1570
- async function ct(s) {
1571
- const e = await crypto.subtle.exportKey("pkcs8", s);
1571
+ async function lt(n) {
1572
+ const e = await crypto.subtle.exportKey("pkcs8", n);
1572
1573
  return `-----BEGIN PRIVATE KEY-----
1573
1574
  ${fe(
1574
1575
  de(e)
1575
1576
  )}
1576
1577
  -----END PRIVATE KEY-----`;
1577
1578
  }
1578
- class qe {
1579
+ class ke {
1579
1580
  static async generateCertificate(e, t) {
1580
1581
  const r = await crypto.subtle.generateKey(
1581
1582
  {
@@ -1587,17 +1588,17 @@ class qe {
1587
1588
  !0,
1588
1589
  // extractable
1589
1590
  ["sign", "verify"]
1590
- ), n = await this.signingRequest(
1591
+ ), s = await this.signingRequest(
1591
1592
  e,
1592
1593
  r.publicKey
1593
1594
  ), i = await this.sign(
1594
- n,
1595
+ s,
1595
1596
  (t == null ? void 0 : t.privateKey) ?? r.privateKey
1596
1597
  );
1597
1598
  return {
1598
1599
  keyPair: r,
1599
1600
  certificate: i,
1600
- tbsCertificate: n,
1601
+ tbsCertificate: s,
1601
1602
  tbsDescription: e
1602
1603
  };
1603
1604
  }
@@ -1654,16 +1655,16 @@ class qe {
1654
1655
  }
1655
1656
  static distinguishedName(e) {
1656
1657
  const t = [];
1657
- for (const [r, n] of Object.entries(e)) {
1658
+ for (const [r, s] of Object.entries(e)) {
1658
1659
  const i = [
1659
1660
  o.objectIdentifier(w(r))
1660
1661
  ];
1661
1662
  switch (r) {
1662
1663
  case "countryName":
1663
- i.push(o.printableString(n));
1664
+ i.push(o.printableString(s));
1664
1665
  break;
1665
1666
  default:
1666
- i.push(o.utf8String(n));
1667
+ i.push(o.utf8String(s));
1667
1668
  }
1668
1669
  t.push(o.set([o.sequence(i)]));
1669
1670
  }
@@ -1681,7 +1682,7 @@ class qe {
1681
1682
  H.UTCTime,
1682
1683
  new TextEncoder().encode(
1683
1684
  ee(
1684
- (e == null ? void 0 : e.notAfter) ?? Fe(/* @__PURE__ */ new Date(), 10)
1685
+ (e == null ? void 0 : e.notAfter) ?? Ge(/* @__PURE__ */ new Date(), 10)
1685
1686
  )
1686
1687
  )
1687
1688
  )
@@ -1737,17 +1738,17 @@ class qe {
1737
1738
  })) || [], r = ((_ = e.ipAddresses) == null ? void 0 : _.map((a) => {
1738
1739
  const c = o.ia5String(a);
1739
1740
  return o.contextSpecific(7, c);
1740
- })) || [], n = o.octetString(
1741
+ })) || [], s = o.octetString(
1741
1742
  o.sequence([...t, ...r])
1742
1743
  );
1743
1744
  return o.sequence([
1744
1745
  o.objectIdentifier(w("subjectAltName")),
1745
1746
  o.boolean(!0),
1746
- n
1747
+ s
1747
1748
  ]);
1748
1749
  }
1749
1750
  }
1750
- const ke = {
1751
+ const Fe = {
1751
1752
  // Algorithm OIDs
1752
1753
  "1.2.840.113549.1.1.1": "rsaEncryption",
1753
1754
  "1.2.840.113549.1.1.4": "md5WithRSAEncryption",
@@ -1857,11 +1858,11 @@ const ke = {
1857
1858
  "1.3.6.1.5.5.7.3.4": "emailProtection",
1858
1859
  "1.3.6.1.5.5.7.3.8": "timeStamping"
1859
1860
  };
1860
- function w(s) {
1861
- for (const [e, t] of Object.entries(ke))
1862
- if (t === s)
1861
+ function w(n) {
1862
+ for (const [e, t] of Object.entries(Fe))
1863
+ if (t === n)
1863
1864
  return e;
1864
- throw new Error(`OID not found for name: ${s}`);
1865
+ throw new Error(`OID not found for name: ${n}`);
1865
1866
  }
1866
1867
  const Q = 32, H = {
1867
1868
  EOC: 0,
@@ -1907,16 +1908,16 @@ class o {
1907
1908
  const r = [];
1908
1909
  for (; t > 0; )
1909
1910
  r.unshift(t & 255), t >>= 8;
1910
- const n = r.length, i = new Uint8Array(1 + n);
1911
- i[0] = 128 | n;
1912
- for (let _ = 0; _ < n; _++)
1911
+ const s = r.length, i = new Uint8Array(1 + s);
1912
+ i[0] = 128 | s;
1913
+ for (let _ = 0; _ < s; _++)
1913
1914
  i[_ + 1] = r[_];
1914
1915
  return i;
1915
1916
  }
1916
1917
  }
1917
1918
  static ASN1(e, t) {
1918
- const r = o.length_(t.length), n = new Uint8Array(1 + r.length + t.length);
1919
- return n[0] = e, n.set(r, 1), n.set(t, 1 + r.length), n;
1919
+ const r = o.length_(t.length), s = new Uint8Array(1 + r.length + t.length);
1920
+ return s[0] = e, s.set(r, 1), s.set(t, 1 + r.length), s;
1920
1921
  }
1921
1922
  static integer(e) {
1922
1923
  if (e[0] > 127) {
@@ -1936,7 +1937,7 @@ class o {
1936
1937
  return o.ASN1(H.Null, new Uint8Array(0));
1937
1938
  }
1938
1939
  static objectIdentifier(e) {
1939
- const t = e.split(".").map(Number), n = [t[0] * 40 + t[1]];
1940
+ const t = e.split(".").map(Number), s = [t[0] * 40 + t[1]];
1940
1941
  for (let i = 2; i < t.length; i++) {
1941
1942
  let _ = t[i];
1942
1943
  const a = [];
@@ -1945,9 +1946,9 @@ class o {
1945
1946
  while (_ > 0);
1946
1947
  for (let c = 0; c < a.length - 1; c++)
1947
1948
  a[c] |= 128;
1948
- n.push(...a);
1949
+ s.push(...a);
1949
1950
  }
1950
- return o.ASN1(H.OID, new Uint8Array(n));
1951
+ return o.ASN1(H.OID, new Uint8Array(s));
1951
1952
  }
1952
1953
  static utf8String(e) {
1953
1954
  const t = new TextEncoder().encode(e);
@@ -1968,8 +1969,8 @@ class o {
1968
1969
  return o.ASN1(H.IA5String, t);
1969
1970
  }
1970
1971
  static contextSpecific(e, t, r = !1) {
1971
- const n = (r ? 160 : 128) | e;
1972
- return o.ASN1(n, t);
1972
+ const s = (r ? 160 : 128) | e;
1973
+ return o.ASN1(s, t);
1973
1974
  }
1974
1975
  static boolean(e) {
1975
1976
  return o.ASN1(
@@ -1978,49 +1979,73 @@ class o {
1978
1979
  );
1979
1980
  }
1980
1981
  }
1981
- function de(s) {
1982
- return btoa(String.fromCodePoint(...new Uint8Array(s)));
1982
+ function de(n) {
1983
+ return btoa(String.fromCodePoint(...new Uint8Array(n)));
1983
1984
  }
1984
- function fe(s) {
1985
+ function fe(n) {
1985
1986
  var e;
1986
- return ((e = s.match(/.{1,64}/g)) == null ? void 0 : e.join(`
1987
- `)) || s;
1987
+ return ((e = n.match(/.{1,64}/g)) == null ? void 0 : e.join(`
1988
+ `)) || n;
1988
1989
  }
1989
- function ee(s) {
1990
- const e = s.getUTCFullYear().toString().substr(2), t = W(s.getUTCMonth() + 1), r = W(s.getUTCDate()), n = W(s.getUTCHours()), i = W(s.getUTCMinutes()), _ = W(s.getUTCSeconds());
1991
- return `${e}${t}${r}${n}${i}${_}Z`;
1990
+ function ee(n) {
1991
+ const e = n.getUTCFullYear().toString().substr(2), t = W(n.getUTCMonth() + 1), r = W(n.getUTCDate()), s = W(n.getUTCHours()), i = W(n.getUTCMinutes()), _ = W(n.getUTCSeconds());
1992
+ return `${e}${t}${r}${s}${i}${_}Z`;
1992
1993
  }
1993
- function W(s) {
1994
- return s.toString().padStart(2, "0");
1994
+ function W(n) {
1995
+ return n.toString().padStart(2, "0");
1995
1996
  }
1996
- function Fe(s, e) {
1997
- const t = new Date(s);
1997
+ function Ge(n, e) {
1998
+ const t = new Date(n);
1998
1999
  return t.setUTCFullYear(t.getUTCFullYear() + e), t;
1999
2000
  }
2000
- const Ge = (s) => ({
2001
+ async function je(n, e, t) {
2002
+ const r = fetch(n, e);
2003
+ if (!t)
2004
+ return r;
2005
+ try {
2006
+ return await r;
2007
+ } catch {
2008
+ let s;
2009
+ if (typeof n == "string" || n instanceof URL)
2010
+ s = `${t}${n}`;
2011
+ else if (n instanceof Request)
2012
+ s = await ge(n, {
2013
+ url: `${t}${n.url}`
2014
+ });
2015
+ else
2016
+ throw new Error("Invalid input type for fetch");
2017
+ return fetch(s, e);
2018
+ }
2019
+ }
2020
+ const $e = (n) => ({
2001
2021
  websocket: {
2002
2022
  url: (e, t, r) => `ws://playground.internal/?${new URLSearchParams({
2003
2023
  host: t,
2004
2024
  port: r
2005
2025
  }).toString()}`,
2006
2026
  subprotocol: "binary",
2007
- decorator: () => class extends je {
2027
+ decorator: () => class extends Ve {
2008
2028
  constructor(e, t) {
2009
2029
  super(e, t, {
2010
- CAroot: s.CAroot
2030
+ CAroot: n.CAroot,
2031
+ corsProxyUrl: n.corsProxyUrl
2011
2032
  });
2012
2033
  }
2013
2034
  }
2014
2035
  }
2015
2036
  });
2016
- class je {
2017
- constructor(e, t, { CAroot: r, outputType: n = "messages" } = {}) {
2037
+ class Ve {
2038
+ constructor(e, t, {
2039
+ CAroot: r,
2040
+ corsProxyUrl: s,
2041
+ outputType: i = "messages"
2042
+ } = {}) {
2018
2043
  this.url = e, this.options = t, 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);
2019
- const i = new URL(e);
2020
- this.host = i.searchParams.get("host"), this.port = parseInt(i.searchParams.get("port"), 10), this.binaryType = "arraybuffer", this.CAroot = r, n === "messages" && this.clientDownstream.readable.pipeTo(
2044
+ const _ = new URL(e);
2045
+ this.host = _.searchParams.get("host"), this.port = parseInt(_.searchParams.get("port"), 10), this.binaryType = "arraybuffer", this.corsProxyUrl = s, this.CAroot = r, i === "messages" && this.clientDownstream.readable.pipeTo(
2021
2046
  new WritableStream({
2022
- write: (_) => {
2023
- this.emit("message", { data: _ });
2047
+ write: (a) => {
2048
+ this.emit("message", { data: a });
2024
2049
  },
2025
2050
  abort: () => {
2026
2051
  this.emit("error", new Error("ECONNREFUSED")), this.close();
@@ -2036,8 +2061,8 @@ class je {
2036
2061
  this.addEventListener(e, t);
2037
2062
  }
2038
2063
  once(e, t) {
2039
- const r = (n) => {
2040
- t(n), this.removeEventListener(e, r);
2064
+ const r = (s) => {
2065
+ t(s), this.removeEventListener(e, r);
2041
2066
  };
2042
2067
  this.addEventListener(e, r);
2043
2068
  }
@@ -2055,8 +2080,8 @@ class je {
2055
2080
  e === "message" ? this.onmessage(t) : e === "close" ? this.onclose(t) : e === "error" ? this.onerror(t) : e === "open" && this.onopen(t);
2056
2081
  const r = this.listeners.get(e);
2057
2082
  if (r)
2058
- for (const n of r)
2059
- n(t);
2083
+ for (const s of r)
2084
+ s(t);
2060
2085
  }
2061
2086
  // Default event handlers that can be overridden by the user
2062
2087
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -2080,7 +2105,7 @@ class je {
2080
2105
  switch (this.bufferedBytesFromClient = h([
2081
2106
  this.bufferedBytesFromClient,
2082
2107
  new Uint8Array(e)
2083
- ]), Ve(this.port, this.bufferedBytesFromClient)) {
2108
+ ]), Ye(this.port, this.bufferedBytesFromClient)) {
2084
2109
  case !1:
2085
2110
  return;
2086
2111
  case "other":
@@ -2099,7 +2124,7 @@ class je {
2099
2124
  throw new Error(
2100
2125
  "TLS protocol is only supported when the TCPOverFetchWebsocket is instantiated with a CAroot"
2101
2126
  );
2102
- const e = await Oe(
2127
+ const e = await qe(
2103
2128
  {
2104
2129
  subject: {
2105
2130
  commonName: this.host,
@@ -2109,7 +2134,7 @@ class je {
2109
2134
  issuer: this.CAroot.tbsDescription.subject
2110
2135
  },
2111
2136
  this.CAroot.keyPair
2112
- ), t = new xe();
2137
+ ), t = new Ne();
2113
2138
  this.clientUpstream.readable.pipeTo(t.clientEnd.upstream.writable).catch(() => {
2114
2139
  }), t.clientEnd.downstream.readable.pipeTo(this.clientDownstream.writable).catch(() => {
2115
2140
  }), await t.TLSHandshake(e.keyPair.privateKey, [
@@ -2122,9 +2147,10 @@ class je {
2122
2147
  "https"
2123
2148
  );
2124
2149
  try {
2125
- await y.fetchRawResponseBytes(r).pipeTo(
2126
- t.serverEnd.downstream.writable
2127
- );
2150
+ await y.fetchRawResponseBytes(
2151
+ r,
2152
+ this.corsProxyUrl
2153
+ ).pipeTo(t.serverEnd.downstream.writable);
2128
2154
  } catch {
2129
2155
  }
2130
2156
  }
@@ -2135,9 +2161,10 @@ class je {
2135
2161
  "http"
2136
2162
  );
2137
2163
  try {
2138
- await y.fetchRawResponseBytes(e).pipeTo(
2139
- this.clientDownstream.writable
2140
- );
2164
+ await y.fetchRawResponseBytes(
2165
+ e,
2166
+ this.corsProxyUrl
2167
+ ).pipeTo(this.clientDownstream.writable);
2141
2168
  } catch {
2142
2169
  }
2143
2170
  }
@@ -2145,7 +2172,7 @@ class je {
2145
2172
  this.emit("message", { data: new Uint8Array(0) }), this.readyState = this.CLOSING, this.emit("close"), this.readyState = this.CLOSED;
2146
2173
  }
2147
2174
  }
2148
- const $e = [
2175
+ const ze = [
2149
2176
  "GET",
2150
2177
  "POST",
2151
2178
  "HEAD",
@@ -2155,16 +2182,16 @@ const $e = [
2155
2182
  "PUT",
2156
2183
  "TRACE"
2157
2184
  ];
2158
- function Ve(s, e) {
2185
+ function Ye(n, e) {
2159
2186
  if (e.length < 8)
2160
2187
  return !1;
2161
- if (s === 443 && e[0] === C.Handshake && // TLS versions between 1.0 and 1.2
2188
+ if (n === 443 && e[0] === C.Handshake && // TLS versions between 1.0 and 1.2
2162
2189
  e[1] === 3 && e[2] >= 1 && e[2] <= 3)
2163
2190
  return "tls";
2164
2191
  const r = new TextDecoder("latin1", {
2165
2192
  fatal: !0
2166
2193
  }).decode(e);
2167
- return $e.some(
2194
+ return ze.some(
2168
2195
  (i) => r.startsWith(i + " ")
2169
2196
  ) ? "http" : "other";
2170
2197
  }
@@ -2172,33 +2199,45 @@ class y {
2172
2199
  /**
2173
2200
  * Streams a HTTP response including the status line and headers.
2174
2201
  */
2175
- static fetchRawResponseBytes(e) {
2202
+ static fetchRawResponseBytes(e, t) {
2176
2203
  return new ReadableStream({
2177
- async start(t) {
2178
- var _;
2179
- let r;
2204
+ async start(r) {
2205
+ var a;
2206
+ let s;
2180
2207
  try {
2181
- r = await fetch(e), t.enqueue(y.headersAsBytes(r));
2182
- } catch (a) {
2183
- t.error(a);
2208
+ s = await je(
2209
+ e,
2210
+ void 0,
2211
+ t
2212
+ );
2213
+ } catch (c) {
2214
+ r.enqueue(
2215
+ new TextEncoder().encode(
2216
+ `HTTP/1.1 400 Bad Request\r
2217
+ Content-Length: 0\r
2218
+ \r
2219
+ `
2220
+ )
2221
+ ), r.error(c);
2184
2222
  return;
2185
2223
  }
2186
- const n = (_ = r.body) == null ? void 0 : _.getReader();
2187
- if (!n) {
2188
- t.close();
2224
+ r.enqueue(y.headersAsBytes(s));
2225
+ const i = (a = s.body) == null ? void 0 : a.getReader();
2226
+ if (!i) {
2227
+ r.close();
2189
2228
  return;
2190
2229
  }
2191
- const i = new TextEncoder();
2230
+ const _ = new TextEncoder();
2192
2231
  for (; ; ) {
2193
- const { done: a, value: c } = await n.read();
2194
- if (c && (t.enqueue(
2195
- i.encode(`${c.length.toString(16)}\r
2232
+ const { done: c, value: S } = await i.read();
2233
+ if (S && (r.enqueue(
2234
+ _.encode(`${S.length.toString(16)}\r
2196
2235
  `)
2197
- ), t.enqueue(c), t.enqueue(i.encode(`\r
2198
- `))), a) {
2199
- t.enqueue(i.encode(`0\r
2236
+ ), r.enqueue(S), r.enqueue(_.encode(`\r
2237
+ `))), c) {
2238
+ r.enqueue(_.encode(`0\r
2200
2239
  \r
2201
- `)), t.close();
2240
+ `)), r.close();
2202
2241
  return;
2203
2242
  }
2204
2243
  }
@@ -2210,10 +2249,10 @@ class y {
2210
2249
  e.headers.forEach((_, a) => {
2211
2250
  r[a.toLowerCase()] = _;
2212
2251
  }), delete r["content-length"], r["transfer-encoding"] = "chunked";
2213
- const n = [];
2252
+ const s = [];
2214
2253
  for (const [_, a] of Object.entries(r))
2215
- n.push(`${_}: ${a}`);
2216
- const i = [t, ...n].join(`\r
2254
+ s.push(`${_}: ${a}`);
2255
+ const i = [t, ...s].join(`\r
2217
2256
  `) + `\r
2218
2257
  \r
2219
2258
  `;
@@ -2224,7 +2263,7 @@ class y {
2224
2263
  * with known headers and a readable body stream.
2225
2264
  */
2226
2265
  static async parseHttpRequest(e, t, r) {
2227
- let n = new Uint8Array(0), i = !1, _ = -1;
2266
+ let s = new Uint8Array(0), i = !1, _ = -1;
2228
2267
  const a = e.getReader();
2229
2268
  for (; _ === -1; ) {
2230
2269
  const { done: D, value: L } = await a.read();
@@ -2232,13 +2271,13 @@ class y {
2232
2271
  i = !0;
2233
2272
  break;
2234
2273
  }
2235
- n = h([n, L]), _ = ze(
2236
- n,
2274
+ s = h([s, L]), _ = Je(
2275
+ s,
2237
2276
  new Uint8Array([13, 10, 13, 10])
2238
2277
  );
2239
2278
  }
2240
2279
  a.releaseLock();
2241
- const c = n.slice(0, _), S = y.parseRequestHeaders(c), l = n.slice(
2280
+ const c = s.slice(0, _), S = y.parseRequestHeaders(c), l = s.slice(
2242
2281
  _ + 4
2243
2282
  /* Skip \r\n\r\n */
2244
2283
  );
@@ -2271,7 +2310,7 @@ class y {
2271
2310
  }
2272
2311
  static parseRequestHeaders(e) {
2273
2312
  const t = new TextDecoder().decode(e), r = t.split(`
2274
- `)[0], [n, i] = r.split(" "), _ = new Headers();
2313
+ `)[0], [s, i] = r.split(" "), _ = new Headers();
2275
2314
  for (const a of t.split(`\r
2276
2315
  `).slice(1)) {
2277
2316
  if (a === "")
@@ -2279,15 +2318,15 @@ class y {
2279
2318
  const [c, S] = a.split(": ");
2280
2319
  _.set(c, S);
2281
2320
  }
2282
- return { method: n, path: i, headers: _ };
2321
+ return { method: s, path: i, headers: _ };
2283
2322
  }
2284
2323
  }
2285
- function ze(s, e) {
2286
- const t = s.length, r = e.length, n = t - r;
2287
- for (let i = 0; i <= n; i++) {
2324
+ function Je(n, e) {
2325
+ const t = n.length, r = e.length, s = t - r;
2326
+ for (let i = 0; i <= s; i++) {
2288
2327
  let _ = !0;
2289
2328
  for (let a = 0; a < r; a++)
2290
- if (s[i + a] !== e[a]) {
2329
+ if (n[i + a] !== e[a]) {
2291
2330
  _ = !1;
2292
2331
  break;
2293
2332
  }
@@ -2296,9 +2335,9 @@ function ze(s, e) {
2296
2335
  }
2297
2336
  return -1;
2298
2337
  }
2299
- const Ye = () => ({
2338
+ const Xe = () => ({
2300
2339
  websocket: {
2301
- decorator: (s) => class extends s {
2340
+ decorator: (n) => class extends n {
2302
2341
  constructor() {
2303
2342
  try {
2304
2343
  super();
@@ -2311,60 +2350,60 @@ const Ye = () => ({
2311
2350
  }
2312
2351
  }
2313
2352
  });
2314
- async function Ct(s, e = {}) {
2315
- var n;
2316
- const t = await De(s);
2317
- (n = e.onPhpLoaderModuleLoaded) == null || n.call(e, t);
2318
- const r = e.tcpOverFetch ? Ge(e.tcpOverFetch) : Ye();
2353
+ async function ut(n, e = {}) {
2354
+ var s;
2355
+ const t = await We(n);
2356
+ (s = e.onPhpLoaderModuleLoaded) == null || s.call(e, t);
2357
+ const r = e.tcpOverFetch ? $e(e.tcpOverFetch) : Xe();
2319
2358
  return await me(t, {
2320
2359
  ...e.emscriptenOptions || {},
2321
2360
  ...r
2322
2361
  });
2323
2362
  }
2324
- function lt(s, e) {
2363
+ function ht(n, e) {
2325
2364
  window.addEventListener("message", (t) => {
2326
- t.source === s.contentWindow && (e && t.origin !== e || typeof t.data != "object" || t.data.type !== "relay" || window.parent.postMessage(t.data, "*"));
2365
+ t.source === n.contentWindow && (e && t.origin !== e || typeof t.data != "object" || t.data.type !== "relay" || window.parent.postMessage(t.data, "*"));
2327
2366
  }), window.addEventListener("message", (t) => {
2328
2367
  var r;
2329
- t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (r = s == null ? void 0 : s.contentWindow) == null || r.postMessage(t.data));
2368
+ t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (r = n == null ? void 0 : n.contentWindow) == null || r.postMessage(t.data));
2330
2369
  });
2331
2370
  }
2332
- async function At(s) {
2333
- const e = new Worker(s, { type: "module" });
2371
+ async function Ht(n) {
2372
+ const e = new Worker(n, { type: "module" });
2334
2373
  return new Promise((t, r) => {
2335
2374
  e.onerror = (i) => {
2336
2375
  const _ = new Error(
2337
- `WebWorker failed to load at ${s}. ${i.message ? `Original error: ${i.message}` : ""}`
2376
+ `WebWorker failed to load at ${n}. ${i.message ? `Original error: ${i.message}` : ""}`
2338
2377
  );
2339
2378
  _.filename = i.filename, r(_);
2340
2379
  };
2341
- function n(i) {
2342
- i.data === "worker-script-started" && (t(e), e.removeEventListener("message", n));
2380
+ function s(i) {
2381
+ i.data === "worker-script-started" && (t(e), e.removeEventListener("message", s));
2343
2382
  }
2344
- e.addEventListener("message", n);
2383
+ e.addEventListener("message", s);
2345
2384
  });
2346
2385
  }
2347
- function ut(s, e = { initialSync: {} }) {
2386
+ function dt(n, e = { initialSync: {} }) {
2348
2387
  return e = {
2349
2388
  ...e,
2350
2389
  initialSync: {
2351
2390
  ...e.initialSync,
2352
2391
  direction: e.initialSync.direction ?? "opfs-to-memfs"
2353
2392
  }
2354
- }, async function(t, r, n) {
2355
- return e.initialSync.direction === "opfs-to-memfs" ? (B.fileExists(r, n) && B.rmdir(r, n), B.mkdir(r, n), await Je(r, s, n)) : await Ee(
2393
+ }, async function(t, r, s) {
2394
+ return e.initialSync.direction === "opfs-to-memfs" ? (B.fileExists(r, s) && B.rmdir(r, s), B.mkdir(r, s), await Ze(r, n, s)) : await Ee(
2356
2395
  r,
2357
- s,
2358
2396
  n,
2397
+ s,
2359
2398
  e.initialSync.onProgress
2360
- ), Ze(t, s, n);
2399
+ ), et(t, n, s);
2361
2400
  };
2362
2401
  }
2363
- async function Je(s, e, t) {
2364
- B.mkdir(s, t);
2365
- const r = new ge({
2402
+ async function Ze(n, e, t) {
2403
+ B.mkdir(n, t);
2404
+ const r = new Ke({
2366
2405
  concurrency: 40
2367
- }), n = [], i = [
2406
+ }), s = [], i = [
2368
2407
  [e, t]
2369
2408
  ];
2370
2409
  for (; i.length > 0; ) {
@@ -2377,15 +2416,15 @@ async function Je(s, e, t) {
2377
2416
  );
2378
2417
  if (c.kind === "directory") {
2379
2418
  try {
2380
- s.mkdir(l);
2419
+ n.mkdir(l);
2381
2420
  } catch (A) {
2382
2421
  if ((A == null ? void 0 : A.errno) !== 20)
2383
- throw b.error(A), A;
2422
+ throw R.error(A), A;
2384
2423
  }
2385
2424
  i.push([c, l]);
2386
2425
  } else if (c.kind === "file") {
2387
2426
  const A = await c.getFile(), u = new Uint8Array(await A.arrayBuffer());
2388
- s.createDataFile(
2427
+ n.createDataFile(
2389
2428
  a,
2390
2429
  c.name,
2391
2430
  u,
@@ -2394,25 +2433,25 @@ async function Je(s, e, t) {
2394
2433
  !0
2395
2434
  );
2396
2435
  }
2397
- n.splice(n.indexOf(S), 1);
2436
+ s.splice(s.indexOf(S), 1);
2398
2437
  });
2399
- n.push(S);
2438
+ s.push(S);
2400
2439
  }
2401
- for (; i.length === 0 && n.length > 0; )
2402
- await Promise.any(n);
2440
+ for (; i.length === 0 && s.length > 0; )
2441
+ await Promise.any(s);
2403
2442
  }
2404
2443
  }
2405
- async function Ee(s, e, t, r) {
2406
- s.mkdirTree(t);
2407
- const n = [];
2444
+ async function Ee(n, e, t, r) {
2445
+ n.mkdirTree(t);
2446
+ const s = [];
2408
2447
  async function i(l, A) {
2409
2448
  await Promise.all(
2410
- s.readdir(l).filter(
2449
+ n.readdir(l).filter(
2411
2450
  (u) => u !== "." && u !== ".."
2412
2451
  ).map(async (u) => {
2413
2452
  const T = se(l, u);
2414
- if (!Xe(s, T)) {
2415
- n.push([A, T, u]);
2453
+ if (!Qe(n, T)) {
2454
+ s.push([A, T, u]);
2416
2455
  return;
2417
2456
  }
2418
2457
  const D = await A.getDirectoryHandle(u, {
@@ -2424,42 +2463,42 @@ async function Ee(s, e, t, r) {
2424
2463
  }
2425
2464
  await i(t, e);
2426
2465
  let _ = 0;
2427
- const a = r && et(r, 100), c = 100, S = /* @__PURE__ */ new Set();
2466
+ const a = r && rt(r, 100), c = 100, S = /* @__PURE__ */ new Set();
2428
2467
  try {
2429
- for (const [l, A, u] of n) {
2468
+ for (const [l, A, u] of s) {
2430
2469
  const T = Te(
2431
2470
  l,
2432
2471
  u,
2433
- s,
2472
+ n,
2434
2473
  A
2435
2474
  ).then(() => {
2436
2475
  _++, S.delete(T), a == null || a({
2437
2476
  files: _,
2438
- total: n.length
2477
+ total: s.length
2439
2478
  });
2440
2479
  });
2441
2480
  S.add(T), S.size >= c && (await Promise.race(S), a == null || a({
2442
2481
  files: _,
2443
- total: n.length
2482
+ total: s.length
2444
2483
  }));
2445
2484
  }
2446
2485
  } finally {
2447
2486
  await Promise.allSettled(S);
2448
2487
  }
2449
2488
  }
2450
- function Xe(s, e) {
2451
- return s.isDir(s.lookupPath(e, { follow: !0 }).node.mode);
2489
+ function Qe(n, e) {
2490
+ return n.isDir(n.lookupPath(e, { follow: !0 }).node.mode);
2452
2491
  }
2453
- async function Te(s, e, t, r) {
2454
- let n;
2492
+ async function Te(n, e, t, r) {
2493
+ let s;
2455
2494
  try {
2456
- n = t.readFile(r, {
2495
+ s = t.readFile(r, {
2457
2496
  encoding: "binary"
2458
2497
  });
2459
2498
  } catch {
2460
2499
  return;
2461
2500
  }
2462
- const i = await s.getFileHandle(e, { create: !0 }), _ = i.createWritable !== void 0 ? (
2501
+ const i = await n.getFileHandle(e, { create: !0 }), _ = i.createWritable !== void 0 ? (
2463
2502
  // Google Chrome, Firefox, probably more browsers
2464
2503
  await i.createWritable()
2465
2504
  ) : (
@@ -2467,17 +2506,17 @@ async function Te(s, e, t, r) {
2467
2506
  await i.createSyncAccessHandle()
2468
2507
  );
2469
2508
  try {
2470
- await _.truncate(0), await _.write(n);
2509
+ await _.truncate(0), await _.write(s);
2471
2510
  } finally {
2472
2511
  await _.close();
2473
2512
  }
2474
2513
  }
2475
- function Ze(s, e, t) {
2476
- const r = [], n = Ke(s, t, (a) => {
2514
+ function et(n, e, t) {
2515
+ const r = [], s = Ie(n, t, (a) => {
2477
2516
  r.push(a);
2478
- }), i = new Qe(s, e, t);
2517
+ }), i = new tt(n, e, t);
2479
2518
  async function _() {
2480
- const a = await s.semaphore.acquire();
2519
+ const a = await n.semaphore.acquire();
2481
2520
  try {
2482
2521
  for (; r.length; )
2483
2522
  await i.processEntry(r.shift());
@@ -2485,11 +2524,11 @@ function Ze(s, e, t) {
2485
2524
  a();
2486
2525
  }
2487
2526
  }
2488
- return s.addEventListener("request.end", _), function() {
2489
- n(), s.removeEventListener("request.end", _);
2527
+ return n.addEventListener("request.end", _), function() {
2528
+ s(), n.removeEventListener("request.end", _);
2490
2529
  };
2491
2530
  }
2492
- class Qe {
2531
+ class tt {
2493
2532
  constructor(e, t, r) {
2494
2533
  this.php = e, this.opfs = t, this.memfsRoot = te(r);
2495
2534
  }
@@ -2499,26 +2538,26 @@ class Qe {
2499
2538
  async processEntry(e) {
2500
2539
  if (!e.path.startsWith(this.memfsRoot) || e.path === this.memfsRoot)
2501
2540
  return;
2502
- const t = this.toOpfsPath(e.path), r = await ne(this.opfs, t), n = re(t);
2503
- if (n)
2541
+ const t = this.toOpfsPath(e.path), r = await ne(this.opfs, t), s = re(t);
2542
+ if (s)
2504
2543
  try {
2505
2544
  if (e.operation === "DELETE")
2506
2545
  try {
2507
- await r.removeEntry(n, {
2546
+ await r.removeEntry(s, {
2508
2547
  recursive: !0
2509
2548
  });
2510
2549
  } catch {
2511
2550
  }
2512
2551
  else if (e.operation === "CREATE")
2513
- e.nodeType === "directory" ? await r.getDirectoryHandle(n, {
2552
+ e.nodeType === "directory" ? await r.getDirectoryHandle(s, {
2514
2553
  create: !0
2515
- }) : await r.getFileHandle(n, {
2554
+ }) : await r.getFileHandle(s, {
2516
2555
  create: !0
2517
2556
  });
2518
2557
  else if (e.operation === "WRITE")
2519
2558
  await Te(
2520
2559
  r,
2521
- n,
2560
+ s,
2522
2561
  this.php[k].FS,
2523
2562
  e.path
2524
2563
  );
@@ -2529,7 +2568,7 @@ class Qe {
2529
2568
  ), a = re(i);
2530
2569
  if (e.nodeType === "directory") {
2531
2570
  const c = await _.getDirectoryHandle(
2532
- n,
2571
+ s,
2533
2572
  {
2534
2573
  create: !0
2535
2574
  }
@@ -2538,57 +2577,58 @@ class Qe {
2538
2577
  this.php[k].FS,
2539
2578
  c,
2540
2579
  e.toPath
2541
- ), await r.removeEntry(n, {
2580
+ ), await r.removeEntry(s, {
2542
2581
  recursive: !0
2543
2582
  });
2544
2583
  } else
2545
- (await r.getFileHandle(n)).move(_, a);
2584
+ (await r.getFileHandle(s)).move(_, a);
2546
2585
  }
2547
2586
  } catch (i) {
2548
- throw b.log({ entry: e, name: n }), b.error(i), i;
2587
+ throw R.log({ entry: e, name: s }), R.error(i), i;
2549
2588
  }
2550
2589
  }
2551
2590
  }
2552
- function te(s) {
2553
- return s.replace(/\/$/, "").replace(/\/\/+/g, "/");
2591
+ function te(n) {
2592
+ return n.replace(/\/$/, "").replace(/\/\/+/g, "/");
2554
2593
  }
2555
- function re(s) {
2556
- return s.substring(s.lastIndexOf("/") + 1);
2594
+ function re(n) {
2595
+ return n.substring(n.lastIndexOf("/") + 1);
2557
2596
  }
2558
- async function ne(s, e) {
2597
+ async function ne(n, e) {
2559
2598
  const t = e.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
2560
2599
  if (!t)
2561
- return s;
2600
+ return n;
2562
2601
  const r = t.split("/");
2563
- let n = s;
2602
+ let s = n;
2564
2603
  for (let i = 0; i < r.length - 1; i++) {
2565
2604
  const _ = r[i];
2566
- n = await n.getDirectoryHandle(_, { create: !0 });
2605
+ s = await s.getDirectoryHandle(_, { create: !0 });
2567
2606
  }
2568
- return n;
2607
+ return s;
2569
2608
  }
2570
- function et(s, e) {
2571
- let t = 0, r, n;
2609
+ function rt(n, e) {
2610
+ let t = 0, r, s;
2572
2611
  return function(..._) {
2573
- n = _;
2612
+ s = _;
2574
2613
  const a = Date.now() - t;
2575
2614
  if (r === void 0) {
2576
2615
  const c = Math.max(0, e - a);
2577
2616
  r = setTimeout(() => {
2578
- r = void 0, t = Date.now(), s(...n);
2617
+ r = void 0, t = Date.now(), n(...s);
2579
2618
  }, c);
2580
2619
  }
2581
2620
  };
2582
2621
  }
2583
2622
  export {
2584
- ot as certificateToPEM,
2585
- _t as consumeAPI,
2586
- ut as createDirectoryHandleMountHandler,
2587
- at as exposeAPI,
2588
- Oe as generateCertificate,
2589
- De as getPHPLoaderModule,
2590
- Ct as loadWebRuntime,
2591
- ct as privateKeyToPEM,
2592
- lt as setupPostMessageRelay,
2593
- At as spawnPHPWorkerThread
2623
+ Ct as certificateToPEM,
2624
+ ct as consumeAPI,
2625
+ dt as createDirectoryHandleMountHandler,
2626
+ St as exposeAPI,
2627
+ je as fetchWithCorsProxy,
2628
+ qe as generateCertificate,
2629
+ We as getPHPLoaderModule,
2630
+ ut as loadWebRuntime,
2631
+ lt as privateKeyToPEM,
2632
+ ht as setupPostMessageRelay,
2633
+ Ht as spawnPHPWorkerThread
2594
2634
  };