@glassly/jspolyfill 0.3.5-dev.751 → 0.3.5-dev.753

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/assets/startup.js CHANGED
@@ -546,15 +546,36 @@
546
546
  return out;
547
547
  };
548
548
  }
549
+ function bytesToBase64(bytes) {
550
+ const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
551
+ let out = "";
552
+ let i = 0;
553
+ while (i < bytes.length) {
554
+ const c1 = bytes[i++];
555
+ const c2 = i < bytes.length ? bytes[i++] : NaN;
556
+ const c3 = i < bytes.length ? bytes[i++] : NaN;
557
+ const e1 = c1 >> 2;
558
+ const e2 = (c1 & 3) << 4 | (Number.isNaN(c2) ? 0 : c2 >> 4);
559
+ const e3 = Number.isNaN(c2) ? 64 : (c2 & 15) << 2 | (Number.isNaN(c3) ? 0 : c3 >> 6);
560
+ const e4 = Number.isNaN(c3) ? 64 : c3 & 63;
561
+ out += b64[e1] + b64[e2] + (e3 === 64 ? "=" : b64[e3]) + (e4 === 64 ? "=" : b64[e4]);
562
+ }
563
+ return out;
564
+ }
549
565
  if (typeof g.fetch !== "function") {
550
566
  ;
551
567
  g.fetch = async (input, init) => {
552
568
  const url = typeof input === "string" ? input : input.toString();
553
569
  const method = (init?.method ?? "GET").toUpperCase();
554
570
  let bodyString = null;
571
+ let bodyBase64 = null;
555
572
  const reqBody = init?.body;
556
573
  if (typeof reqBody === "string") {
557
574
  bodyString = reqBody;
575
+ } else if (reqBody instanceof ArrayBuffer) {
576
+ bodyBase64 = bytesToBase64(new Uint8Array(reqBody));
577
+ } else if (ArrayBuffer.isView(reqBody)) {
578
+ bodyBase64 = bytesToBase64(new Uint8Array(reqBody.buffer, reqBody.byteOffset, reqBody.byteLength));
558
579
  } else if (reqBody && typeof reqBody.toString === "function") {
559
580
  bodyString = reqBody.toString();
560
581
  }
@@ -577,7 +598,7 @@
577
598
  }
578
599
  }
579
600
  const sendRequest = g.__sendRequest;
580
- const result = await sendRequest("fetch", "request", [{ url, method, headers, body: bodyString }]);
601
+ const result = await sendRequest("fetch", "request", [{ url, method, headers, body: bodyString, bodyBase64 }]);
581
602
  const bodyText = typeof result.body === "string" ? result.body : "";
582
603
  const responseHeaders = new Map(Object.entries(result.headers ?? {}));
583
604
  class ResponseLike {
@@ -617,22 +638,7 @@
617
638
  };
618
639
  }
619
640
  if (typeof g.WebSocket !== "function") {
620
- let bytesToBase642 = function(bytes) {
621
- const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
622
- let out = "";
623
- let i = 0;
624
- while (i < bytes.length) {
625
- const c1 = bytes[i++];
626
- const c2 = i < bytes.length ? bytes[i++] : NaN;
627
- const c3 = i < bytes.length ? bytes[i++] : NaN;
628
- const e1 = c1 >> 2;
629
- const e2 = (c1 & 3) << 4 | (Number.isNaN(c2) ? 0 : c2 >> 4);
630
- const e3 = Number.isNaN(c2) ? 64 : (c2 & 15) << 2 | (Number.isNaN(c3) ? 0 : c3 >> 6);
631
- const e4 = Number.isNaN(c3) ? 64 : c3 & 63;
632
- out += b64[e1] + b64[e2] + (e3 === 64 ? "=" : b64[e3]) + (e4 === 64 ? "=" : b64[e4]);
633
- }
634
- return out;
635
- }, base64ToBytes2 = function(s) {
641
+ let base64ToBytes2 = function(s) {
636
642
  const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
637
643
  const clean = s.replace(/=+$/, "");
638
644
  const out = [];
@@ -654,7 +660,7 @@
654
660
  if (typeof q === "function") q(fn);
655
661
  else g.Promise.resolve().then(fn);
656
662
  };
657
- var bytesToBase64 = bytesToBase642, base64ToBytes = base64ToBytes2, queueMicrotaskSafe = queueMicrotaskSafe2;
663
+ var base64ToBytes = base64ToBytes2, queueMicrotaskSafe = queueMicrotaskSafe2;
658
664
  const sockets = /* @__PURE__ */ new Map();
659
665
  g.__deliverWebSocketEvent = (sid, type, payload) => {
660
666
  const sock = sockets.get(sid);
@@ -713,7 +719,7 @@
713
719
  } else {
714
720
  kind = "binary";
715
721
  const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
716
- payload = bytesToBase642(bytes);
722
+ payload = bytesToBase64(bytes);
717
723
  }
718
724
  try {
719
725
  __dispatch("ws", "send", JSON.stringify([{ sid: this.sid, kind, payload }]));
package/dist/startup.js CHANGED
@@ -546,15 +546,36 @@
546
546
  return out;
547
547
  };
548
548
  }
549
+ function bytesToBase64(bytes) {
550
+ const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
551
+ let out = "";
552
+ let i = 0;
553
+ while (i < bytes.length) {
554
+ const c1 = bytes[i++];
555
+ const c2 = i < bytes.length ? bytes[i++] : NaN;
556
+ const c3 = i < bytes.length ? bytes[i++] : NaN;
557
+ const e1 = c1 >> 2;
558
+ const e2 = (c1 & 3) << 4 | (Number.isNaN(c2) ? 0 : c2 >> 4);
559
+ const e3 = Number.isNaN(c2) ? 64 : (c2 & 15) << 2 | (Number.isNaN(c3) ? 0 : c3 >> 6);
560
+ const e4 = Number.isNaN(c3) ? 64 : c3 & 63;
561
+ out += b64[e1] + b64[e2] + (e3 === 64 ? "=" : b64[e3]) + (e4 === 64 ? "=" : b64[e4]);
562
+ }
563
+ return out;
564
+ }
549
565
  if (typeof g.fetch !== "function") {
550
566
  ;
551
567
  g.fetch = async (input, init) => {
552
568
  const url = typeof input === "string" ? input : input.toString();
553
569
  const method = (init?.method ?? "GET").toUpperCase();
554
570
  let bodyString = null;
571
+ let bodyBase64 = null;
555
572
  const reqBody = init?.body;
556
573
  if (typeof reqBody === "string") {
557
574
  bodyString = reqBody;
575
+ } else if (reqBody instanceof ArrayBuffer) {
576
+ bodyBase64 = bytesToBase64(new Uint8Array(reqBody));
577
+ } else if (ArrayBuffer.isView(reqBody)) {
578
+ bodyBase64 = bytesToBase64(new Uint8Array(reqBody.buffer, reqBody.byteOffset, reqBody.byteLength));
558
579
  } else if (reqBody && typeof reqBody.toString === "function") {
559
580
  bodyString = reqBody.toString();
560
581
  }
@@ -577,7 +598,7 @@
577
598
  }
578
599
  }
579
600
  const sendRequest = g.__sendRequest;
580
- const result = await sendRequest("fetch", "request", [{ url, method, headers, body: bodyString }]);
601
+ const result = await sendRequest("fetch", "request", [{ url, method, headers, body: bodyString, bodyBase64 }]);
581
602
  const bodyText = typeof result.body === "string" ? result.body : "";
582
603
  const responseHeaders = new Map(Object.entries(result.headers ?? {}));
583
604
  class ResponseLike {
@@ -617,22 +638,7 @@
617
638
  };
618
639
  }
619
640
  if (typeof g.WebSocket !== "function") {
620
- let bytesToBase642 = function(bytes) {
621
- const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
622
- let out = "";
623
- let i = 0;
624
- while (i < bytes.length) {
625
- const c1 = bytes[i++];
626
- const c2 = i < bytes.length ? bytes[i++] : NaN;
627
- const c3 = i < bytes.length ? bytes[i++] : NaN;
628
- const e1 = c1 >> 2;
629
- const e2 = (c1 & 3) << 4 | (Number.isNaN(c2) ? 0 : c2 >> 4);
630
- const e3 = Number.isNaN(c2) ? 64 : (c2 & 15) << 2 | (Number.isNaN(c3) ? 0 : c3 >> 6);
631
- const e4 = Number.isNaN(c3) ? 64 : c3 & 63;
632
- out += b64[e1] + b64[e2] + (e3 === 64 ? "=" : b64[e3]) + (e4 === 64 ? "=" : b64[e4]);
633
- }
634
- return out;
635
- }, base64ToBytes2 = function(s) {
641
+ let base64ToBytes2 = function(s) {
636
642
  const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
637
643
  const clean = s.replace(/=+$/, "");
638
644
  const out = [];
@@ -654,7 +660,7 @@
654
660
  if (typeof q === "function") q(fn);
655
661
  else g.Promise.resolve().then(fn);
656
662
  };
657
- var bytesToBase64 = bytesToBase642, base64ToBytes = base64ToBytes2, queueMicrotaskSafe = queueMicrotaskSafe2;
663
+ var base64ToBytes = base64ToBytes2, queueMicrotaskSafe = queueMicrotaskSafe2;
658
664
  const sockets = /* @__PURE__ */ new Map();
659
665
  g.__deliverWebSocketEvent = (sid, type, payload) => {
660
666
  const sock = sockets.get(sid);
@@ -713,7 +719,7 @@
713
719
  } else {
714
720
  kind = "binary";
715
721
  const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
716
- payload = bytesToBase642(bytes);
722
+ payload = bytesToBase64(bytes);
717
723
  }
718
724
  try {
719
725
  __dispatch("ws", "send", JSON.stringify([{ sid: this.sid, kind, payload }]));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glassly/jspolyfill",
3
- "version": "0.3.5-dev.751",
3
+ "version": "0.3.5-dev.753",
4
4
  "description": "JSRuntime polyfill bundle — installed into each per-miniapp JSContext (iOS-JSC, Android-QuickJS) at spawn time. Provides browser-like globals (console, timers, fetch, WebSocket, localStorage, crypto.subtle) over a single __dispatch native bridge, plus the __deliver / signalReady plumbing the host runtime relies on.",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
package/src/startup.ts CHANGED
@@ -726,6 +726,23 @@ declare const __nativeClearTimer: (token: number) => void
726
726
  }
727
727
  }
728
728
 
729
+ function bytesToBase64(bytes: Uint8Array): string {
730
+ const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
731
+ let out = ""
732
+ let i = 0
733
+ while (i < bytes.length) {
734
+ const c1 = bytes[i++]!
735
+ const c2 = i < bytes.length ? bytes[i++]! : NaN
736
+ const c3 = i < bytes.length ? bytes[i++]! : NaN
737
+ const e1 = c1 >> 2
738
+ const e2 = ((c1 & 3) << 4) | (Number.isNaN(c2) ? 0 : c2 >> 4)
739
+ const e3 = Number.isNaN(c2) ? 64 : ((c2 & 15) << 2) | (Number.isNaN(c3) ? 0 : c3 >> 6)
740
+ const e4 = Number.isNaN(c3) ? 64 : c3 & 63
741
+ out += b64[e1]! + b64[e2]! + (e3 === 64 ? "=" : b64[e3]!) + (e4 === 64 ? "=" : b64[e4]!)
742
+ }
743
+ return out
744
+ }
745
+
729
746
  // ---------- fetch (thin native bridge) -----------------------------------
730
747
  // Async — uses __sendRequest under the hood with iface "fetch". The
731
748
  // native handler is expected to return {status, statusText, headers, body}
@@ -735,9 +752,14 @@ declare const __nativeClearTimer: (token: number) => void
735
752
  const url = typeof input === "string" ? input : input.toString()
736
753
  const method = (init?.method ?? "GET").toUpperCase()
737
754
  let bodyString: string | null = null
755
+ let bodyBase64: string | null = null
738
756
  const reqBody = init?.body as unknown
739
757
  if (typeof reqBody === "string") {
740
758
  bodyString = reqBody
759
+ } else if (reqBody instanceof ArrayBuffer) {
760
+ bodyBase64 = bytesToBase64(new Uint8Array(reqBody))
761
+ } else if (ArrayBuffer.isView(reqBody)) {
762
+ bodyBase64 = bytesToBase64(new Uint8Array(reqBody.buffer, reqBody.byteOffset, reqBody.byteLength))
741
763
  } else if (reqBody && typeof (reqBody as {toString?: () => string}).toString === "function") {
742
764
  bodyString = (reqBody as {toString: () => string}).toString()
743
765
  }
@@ -764,7 +786,7 @@ declare const __nativeClearTimer: (token: number) => void
764
786
  method: string,
765
787
  args: unknown[],
766
788
  ) => Promise<unknown>
767
- const result = (await sendRequest("fetch", "request", [{url, method, headers, body: bodyString}])) as {
789
+ const result = (await sendRequest("fetch", "request", [{url, method, headers, body: bodyString, bodyBase64}])) as {
768
790
  status: number
769
791
  statusText?: string
770
792
  headers?: Record<string, string>
@@ -998,22 +1020,6 @@ declare const __nativeClearTimer: (token: number) => void
998
1020
  }
999
1021
  }
1000
1022
 
1001
- function bytesToBase64(bytes: Uint8Array): string {
1002
- const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
1003
- let out = ""
1004
- let i = 0
1005
- while (i < bytes.length) {
1006
- const c1 = bytes[i++]!
1007
- const c2 = i < bytes.length ? bytes[i++]! : NaN
1008
- const c3 = i < bytes.length ? bytes[i++]! : NaN
1009
- const e1 = c1 >> 2
1010
- const e2 = ((c1 & 3) << 4) | (Number.isNaN(c2) ? 0 : c2 >> 4)
1011
- const e3 = Number.isNaN(c2) ? 64 : ((c2 & 15) << 2) | (Number.isNaN(c3) ? 0 : c3 >> 6)
1012
- const e4 = Number.isNaN(c3) ? 64 : c3 & 63
1013
- out += b64[e1]! + b64[e2]! + (e3 === 64 ? "=" : b64[e3]!) + (e4 === 64 ? "=" : b64[e4]!)
1014
- }
1015
- return out
1016
- }
1017
1023
  function base64ToBytes(s: string): Uint8Array {
1018
1024
  const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
1019
1025
  const clean = s.replace(/=+$/, "")