ziex 0.1.0-dev.1458 → 0.1.0-dev.1466

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/wasm/init.dev.js CHANGED
@@ -1,3 +1,27 @@
1
+ // src/wasm/constants.ts
2
+ var DOM_CMD_HEADER_SIZE = 8;
3
+ var DOM_CMD_RECORD_SIZE = 24;
4
+ var DomOp_CreateElement = 1;
5
+ var DomOp_CreateText = 2;
6
+ var DomOp_HydrateInsert = 3;
7
+ var DomOp_SetAttr = 4;
8
+ var DomOp_SetProp = 5;
9
+ var DomOp_RemoveAttr = 6;
10
+ var DomOp_SetNodeValue = 7;
11
+ var DomOp_SetInnerHtml = 8;
12
+ var DomOp_AppendChild = 9;
13
+ var DomOp_InsertBefore = 10;
14
+ var DomOp_RemoveChild = 11;
15
+ var DomOp_ReplaceChild = 12;
16
+ var CallbackType_FetchSuccess = 1;
17
+ var CallbackType_FetchError = 2;
18
+ var CallbackType_Timeout = 3;
19
+ var CallbackType_Interval = 4;
20
+ var CallbackType_WebSocketOpen = 5;
21
+ var CallbackType_WebSocketMessage = 6;
22
+ var CallbackType_WebSocketError = 7;
23
+ var CallbackType_WebSocketClose = 8;
24
+
1
25
  // ../../vendor/jsz/js/src/zigjs.ts
2
26
  var NAN_PREFIX = 2146959360;
3
27
  var predefined = {
@@ -382,30 +406,26 @@ function invokeWasmExport(fn, ...args) {
382
406
  var ZxBridgeCore = class _ZxBridgeCore {
383
407
  #intervals = /* @__PURE__ */ new Map();
384
408
  #handler;
385
- #fetchCompleteHandler;
386
409
  constructor(exports) {
387
410
  this._alloc = exports.__zx_alloc;
388
411
  this.#handler = wrapPromisingExport(exports.__zx_cb);
389
- const fetchCompleteHandler = wrapPromisingExport(exports.__zx_fetch_complete);
390
- if (!fetchCompleteHandler) {
391
- throw new Error("__zx_fetch_complete not exported from WASM");
412
+ if (!this.#handler) {
413
+ console.warn("__zx_cb not exported from WASM");
392
414
  }
393
- this.#fetchCompleteHandler = fetchCompleteHandler;
394
415
  if (exports.memory) jsz.memory = exports.memory;
395
416
  }
396
417
  /** Invoke the unified callback handler */
397
- #invoke(type, id, data) {
418
+ _invoke(type, id, a = 0n, b = 0n, c = 0n) {
398
419
  const handler = this.#handler;
399
420
  if (!handler) {
400
421
  console.warn("__zx_cb not exported from WASM");
401
422
  return;
402
423
  }
403
- const dataRef = storeValueGetRef(data);
404
- invokeWasmExport(handler, type, id, dataRef);
424
+ invokeWasmExport(handler, type, id, a, b, c);
405
425
  }
406
426
  /**
407
427
  * Async fetch with full options support.
408
- * Calls __zx_fetch_complete when done.
428
+ * Completes via `__zx_cb(fetch_success|fetch_error, ...)`.
409
429
  */
410
430
  fetchAsync(urlPtr, urlLen, methodPtr, methodLen, headersPtr, headersLen, bodyPtr, bodyLen, timeoutMs, fetchId) {
411
431
  const url = readString(urlPtr, urlLen);
@@ -444,23 +464,23 @@ var ZxBridgeCore = class _ZxBridgeCore {
444
464
  }
445
465
  /** Notify WASM that a fetch completed. `body` is raw bytes on success, text on error. */
446
466
  _notifyFetchComplete(fetchId, statusCode, body, isError) {
447
- const handler = this.#fetchCompleteHandler;
448
467
  const encoded = typeof body === "string" ? textEncoder.encode(body) : body;
449
468
  const ptr = this._alloc(encoded.length) >>> 0;
450
469
  if (!ptr && encoded.length > 0) return;
451
470
  writeBytes(ptr, encoded);
452
- invokeWasmExport(handler, fetchId, statusCode, ptr, encoded.length, isError ? 1 : 0);
471
+ const type = isError ? CallbackType_FetchError : CallbackType_FetchSuccess;
472
+ this._invoke(type, fetchId, BigInt(statusCode), BigInt(ptr), BigInt(encoded.length));
453
473
  }
454
474
  /** Set a timeout and callback when it fires */
455
475
  setTimeout(callbackId, delayMs) {
456
476
  setTimeout(() => {
457
- this.#invoke(3, callbackId, null);
477
+ this._invoke(CallbackType_Timeout, callbackId);
458
478
  }, delayMs);
459
479
  }
460
480
  /** Set an interval and callback each time it fires */
461
481
  setInterval(callbackId, intervalMs) {
462
482
  const handle = setInterval(() => {
463
- this.#invoke(4, callbackId, null);
483
+ this._invoke(CallbackType_Interval, callbackId);
464
484
  }, intervalMs);
465
485
  this.#intervals.set(callbackId, handle);
466
486
  }
@@ -575,6 +595,326 @@ function bindWasmAlloc(allocRef, exports) {
575
595
  allocRef[0] = exports.__zx_alloc;
576
596
  }
577
597
 
598
+ // src/wasm/generated/tags.ts
599
+ var TAG_NAMES = [
600
+ "aside",
601
+ "fragment",
602
+ "iframe",
603
+ "slot",
604
+ "img",
605
+ "html",
606
+ "base",
607
+ "head",
608
+ "link",
609
+ "meta",
610
+ "script",
611
+ "style",
612
+ "title",
613
+ "address",
614
+ "article",
615
+ "body",
616
+ "h1",
617
+ "h6",
618
+ "footer",
619
+ "header",
620
+ "h2",
621
+ "h3",
622
+ "h4",
623
+ "h5",
624
+ "hgroup",
625
+ "nav",
626
+ "section",
627
+ "dd",
628
+ "dl",
629
+ "dt",
630
+ "div",
631
+ "figcaption",
632
+ "figure",
633
+ "hr",
634
+ "li",
635
+ "ol",
636
+ "ul",
637
+ "menu",
638
+ "main",
639
+ "p",
640
+ "picture",
641
+ "pre",
642
+ "a",
643
+ "abbr",
644
+ "b",
645
+ "bdi",
646
+ "bdo",
647
+ "br",
648
+ "cite",
649
+ "code",
650
+ "data",
651
+ "time",
652
+ "dfn",
653
+ "em",
654
+ "i",
655
+ "kbd",
656
+ "mark",
657
+ "q",
658
+ "blockquote",
659
+ "rp",
660
+ "ruby",
661
+ "rt",
662
+ "rtc",
663
+ "rb",
664
+ "s",
665
+ "del",
666
+ "ins",
667
+ "samp",
668
+ "small",
669
+ "span",
670
+ "strong",
671
+ "sub",
672
+ "sup",
673
+ "u",
674
+ "var",
675
+ "wbr",
676
+ "area",
677
+ "map",
678
+ "audio",
679
+ "source",
680
+ "track",
681
+ "video",
682
+ "embed",
683
+ "object",
684
+ "param",
685
+ "canvas",
686
+ "noscript",
687
+ "caption",
688
+ "table",
689
+ "col",
690
+ "colgroup",
691
+ "tbody",
692
+ "tr",
693
+ "thead",
694
+ "tfoot",
695
+ "td",
696
+ "th",
697
+ "button",
698
+ "datalist",
699
+ "option",
700
+ "fieldset",
701
+ "label",
702
+ "form",
703
+ "input",
704
+ "keygen",
705
+ "legend",
706
+ "meter",
707
+ "optgroup",
708
+ "select",
709
+ "output",
710
+ "progress",
711
+ "textarea",
712
+ "details",
713
+ "dialog",
714
+ "menuitem",
715
+ "summary",
716
+ "content",
717
+ "element",
718
+ "shadow",
719
+ "template",
720
+ "acronym",
721
+ "applet",
722
+ "basefont",
723
+ "font",
724
+ "big",
725
+ "blink",
726
+ "center",
727
+ "command",
728
+ "dir",
729
+ "frame",
730
+ "frameset",
731
+ "isindex",
732
+ "listing",
733
+ "marquee",
734
+ "noembed",
735
+ "plaintext",
736
+ "spacer",
737
+ "strike",
738
+ "tt",
739
+ "xmp",
740
+ "animate",
741
+ "animateMotion",
742
+ "animateTransform",
743
+ "circle",
744
+ "clipPath",
745
+ "defs",
746
+ "desc",
747
+ "ellipse",
748
+ "feBlend",
749
+ "feColorMatrix",
750
+ "feComponentTransfer",
751
+ "feComposite",
752
+ "feConvolveMatrix",
753
+ "feDiffuseLighting",
754
+ "feDisplacementMap",
755
+ "feDistantLight",
756
+ "feDropShadow",
757
+ "feFlood",
758
+ "feFuncA",
759
+ "feFuncB",
760
+ "feFuncG",
761
+ "feFuncR",
762
+ "feGaussianBlur",
763
+ "feImage",
764
+ "feMerge",
765
+ "feMergeNode",
766
+ "feMorphology",
767
+ "feOffset",
768
+ "fePointLight",
769
+ "feSpecularLighting",
770
+ "feSpotLight",
771
+ "feTile",
772
+ "feTurbulence",
773
+ "filter",
774
+ "foreignObject",
775
+ "g",
776
+ "image",
777
+ "line",
778
+ "linearGradient",
779
+ "marker",
780
+ "mask",
781
+ "metadata",
782
+ "mpath",
783
+ "path",
784
+ "pattern",
785
+ "polygon",
786
+ "polyline",
787
+ "radialGradient",
788
+ "rect",
789
+ "set",
790
+ "stop",
791
+ "svg",
792
+ "switch",
793
+ "symbol",
794
+ "text",
795
+ "textPath",
796
+ "tspan",
797
+ "use",
798
+ "view",
799
+ "custom"
800
+ ];
801
+
802
+ // src/wasm/generated/tag_indices.ts
803
+ var SVG_TAG_START_INDEX = 140;
804
+ var CUSTOM_TAG_INDEX = 199;
805
+
806
+ // src/wasm/dom_cmd.ts
807
+ function flushDomCmds(ptr, len, ctx) {
808
+ const start = ptr >>> 0;
809
+ const length = len >>> 0;
810
+ if (length < DOM_CMD_HEADER_SIZE) return;
811
+ const mem = getMemoryView();
812
+ if (start + length > mem.byteLength) return;
813
+ const view = new DataView(mem.buffer, mem.byteOffset + start, length);
814
+ const count = view.getUint32(0, true);
815
+ const recordsBytes = count * DOM_CMD_RECORD_SIZE;
816
+ if (DOM_CMD_HEADER_SIZE + recordsBytes > length) return;
817
+ const { domNodes: domNodes2, cleanupDomNodes: cleanupDomNodes2 } = ctx;
818
+ for (let i = 0; i < count; i++) {
819
+ const off = DOM_CMD_HEADER_SIZE + i * DOM_CMD_RECORD_SIZE;
820
+ const op = view.getUint8(off);
821
+ const p0 = view.getUint32(off + 4, true);
822
+ const p1 = view.getUint32(off + 8, true);
823
+ const p2 = view.getUint32(off + 12, true);
824
+ const p3 = view.getUint32(off + 16, true);
825
+ const p4 = view.getUint32(off + 20, true);
826
+ switch (op) {
827
+ case DomOp_CreateElement: {
828
+ const isCustom = p0 === CUSTOM_TAG_INDEX;
829
+ const tagName = isCustom ? readString(p2, p3) : TAG_NAMES[p0];
830
+ const el = !isCustom && p0 >= SVG_TAG_START_INDEX ? document.createElementNS("http://www.w3.org/2000/svg", tagName) : document.createElement(tagName);
831
+ el.__zx_ref = p1;
832
+ domNodes2.set(p1, el);
833
+ break;
834
+ }
835
+ case DomOp_CreateText: {
836
+ const node = document.createTextNode(readString(p0, p1));
837
+ node.__zx_ref = p2;
838
+ domNodes2.set(p2, node);
839
+ break;
840
+ }
841
+ case DomOp_HydrateInsert: {
842
+ const child = domNodes2.get(p0);
843
+ const ref = BigInt(p1) | BigInt(p2) << 32n;
844
+ const end = loadValueFromRef(ref);
845
+ if (!child || !end?.parentNode) break;
846
+ end.parentNode.insertBefore(child, end);
847
+ break;
848
+ }
849
+ case DomOp_SetAttr: {
850
+ domNodes2.get(p0)?.setAttribute(readString(p1, p2), readString(p3, p4));
851
+ break;
852
+ }
853
+ case DomOp_SetProp: {
854
+ const el = domNodes2.get(p0);
855
+ if (el) {
856
+ const name = readString(p1, p2);
857
+ const val = readString(p3, p4);
858
+ if (name === "checked" || name === "selected" || name === "muted") {
859
+ el[name] = val !== "false";
860
+ } else {
861
+ el[name] = val;
862
+ }
863
+ }
864
+ break;
865
+ }
866
+ case DomOp_RemoveAttr: {
867
+ domNodes2.get(p0)?.removeAttribute(readString(p1, p2));
868
+ break;
869
+ }
870
+ case DomOp_SetNodeValue: {
871
+ const node = domNodes2.get(p0);
872
+ if (node) node.nodeValue = readString(p1, p2);
873
+ break;
874
+ }
875
+ case DomOp_SetInnerHtml: {
876
+ const el = domNodes2.get(p0);
877
+ if (el) el.innerHTML = readString(p1, p2);
878
+ break;
879
+ }
880
+ case DomOp_AppendChild: {
881
+ const parent = domNodes2.get(p0);
882
+ const child = domNodes2.get(p1);
883
+ if (parent && child) parent.appendChild(child);
884
+ break;
885
+ }
886
+ case DomOp_InsertBefore: {
887
+ const parent = domNodes2.get(p0);
888
+ const child = domNodes2.get(p1);
889
+ const refNode = domNodes2.get(p2) ?? null;
890
+ if (parent && child) parent.insertBefore(child, refNode);
891
+ break;
892
+ }
893
+ case DomOp_RemoveChild: {
894
+ const parent = domNodes2.get(p0);
895
+ const child = domNodes2.get(p1);
896
+ if (parent && child) {
897
+ parent.removeChild(child);
898
+ cleanupDomNodes2(child);
899
+ }
900
+ break;
901
+ }
902
+ case DomOp_ReplaceChild: {
903
+ const parent = domNodes2.get(p0);
904
+ const newChild = domNodes2.get(p1);
905
+ const oldChild = domNodes2.get(p2);
906
+ if (parent && newChild && oldChild) {
907
+ parent.replaceChild(newChild, oldChild);
908
+ cleanupDomNodes2(oldChild);
909
+ }
910
+ break;
911
+ }
912
+ default:
913
+ break;
914
+ }
915
+ }
916
+ }
917
+
578
918
  // src/runtime/kv/extern.ts
579
919
  function putOptions(ttlSeconds) {
580
920
  if (ttlSeconds < 60) return void 0;
@@ -789,26 +1129,53 @@ function hasJSPI() {
789
1129
  }
790
1130
  function createBrowserKVBindings(options = {}) {
791
1131
  const namespace = options.namespace ?? "default";
1132
+ const isIndexedDb = hasJSPI() && !options.forceLocalStorage;
792
1133
  return {
793
- [namespace]: hasJSPI() ? createIndexedDbKV(options) : createLocalStorageKV(options)
1134
+ [namespace]: isIndexedDb ? createIndexedDbKV(options) : createLocalStorageKV(options)
794
1135
  };
795
1136
  }
796
1137
 
1138
+ // src/wasm/generated/events.ts
1139
+ var DELEGATED_EVENTS = [
1140
+ "click",
1141
+ "dblclick",
1142
+ "input",
1143
+ "change",
1144
+ "submit",
1145
+ "focusin",
1146
+ "focusout",
1147
+ "keydown",
1148
+ "keyup",
1149
+ "keypress",
1150
+ "mouseenter",
1151
+ "mouseleave",
1152
+ "mousedown",
1153
+ "mouseup",
1154
+ "mousemove",
1155
+ "touchstart",
1156
+ "touchend",
1157
+ "touchmove",
1158
+ "scroll",
1159
+ "wheel",
1160
+ "pointerdown",
1161
+ "pointermove",
1162
+ "pointerup",
1163
+ "pointercancel",
1164
+ "pointerenter",
1165
+ "pointerleave",
1166
+ "lostpointercapture"
1167
+ ];
1168
+
1169
+ // src/wasm/generated/event_bits.ts
1170
+ var HIGH_FREQ_EVENT_BITS = 3031040;
1171
+
797
1172
  // src/wasm/index.ts
798
1173
  var ZxBridge = class extends ZxBridgeCore {
799
1174
  #websockets = /* @__PURE__ */ new Map();
800
- #wsOnOpenHandler;
801
- #wsOnMessageHandler;
802
- #wsOnErrorHandler;
803
- #wsOnCloseHandler;
804
1175
  #eventbridge;
805
1176
  #eventbridgeAsync;
806
1177
  constructor(exports) {
807
1178
  super(exports);
808
- this.#wsOnOpenHandler = wrapPromisingExport(exports.__zx_ws_onopen);
809
- this.#wsOnMessageHandler = wrapPromisingExport(exports.__zx_ws_onmessage);
810
- this.#wsOnErrorHandler = wrapPromisingExport(exports.__zx_ws_onerror);
811
- this.#wsOnCloseHandler = wrapPromisingExport(exports.__zx_ws_onclose);
812
1179
  this.#eventbridge = exports.__zx_eventbridge;
813
1180
  this.#eventbridgeAsync = wrapPromisingExport(
814
1181
  exports.__zx_eventbridge_async ?? exports.__zx_eventbridge
@@ -834,8 +1201,8 @@ var ZxBridge = class extends ZxBridgeCore {
834
1201
  const present = eventHandlersPresent.get(velementId) ?? 0;
835
1202
  eventHandlersPresent.delete(velementId);
836
1203
  eventHandlersSuspend.delete(velementId);
837
- for (const eventTypeId of HIGH_FREQ_EVENT_IDS) {
838
- if (present & 1 << eventTypeId) maybeRemoveHighFreqListener(eventTypeId);
1204
+ for (let bits = present & HIGH_FREQ_EVENT_BITS; bits !== 0; bits &= bits - 1) {
1205
+ maybeRemoveHighFreqListener(31 - Math.clz32(bits));
839
1206
  }
840
1207
  }
841
1208
  /** Submit a form action with bound-state round-trip. */
@@ -857,7 +1224,7 @@ var ZxBridge = class extends ZxBridgeCore {
857
1224
  }
858
1225
  /**
859
1226
  * Create and connect a WebSocket.
860
- * Calls __zx_ws_onopen, __zx_ws_onmessage, __zx_ws_onerror, __zx_ws_onclose.
1227
+ * Completes via `__zx_cb(ws_open|ws_message|ws_error|ws_close, ...)`.
861
1228
  */
862
1229
  wsConnect(wsId, urlPtr, urlLen, protocolsPtr, protocolsLen) {
863
1230
  const url = readString(urlPtr, urlLen);
@@ -867,42 +1234,32 @@ var ZxBridge = class extends ZxBridgeCore {
867
1234
  const ws = protocols && protocols.length > 0 ? new WebSocket(url, protocols) : new WebSocket(url);
868
1235
  ws.binaryType = "arraybuffer";
869
1236
  ws.onopen = () => {
870
- const handler = this.#wsOnOpenHandler;
871
- if (!handler) return;
872
1237
  const protocol = ws.protocol || "";
873
1238
  const [ptr, len] = this._writeStringToWasm(protocol);
874
- invokeWasmExport(handler, wsId, ptr, len);
1239
+ this._invoke(CallbackType_WebSocketOpen, wsId, BigInt(ptr), BigInt(len));
875
1240
  };
876
1241
  ws.onmessage = (event) => {
877
- const handler = this.#wsOnMessageHandler;
878
- if (!handler) return;
879
1242
  const isBinary = event.data instanceof ArrayBuffer;
880
1243
  const data = isBinary ? new Uint8Array(event.data) : textEncoder.encode(event.data);
881
1244
  const [ptr, len] = this.writeBytesToWasm(data);
882
- invokeWasmExport(handler, wsId, ptr, len, isBinary ? 1 : 0);
1245
+ this._invoke(CallbackType_WebSocketMessage, wsId, BigInt(ptr), BigInt(len), BigInt(isBinary ? 1 : 0));
883
1246
  };
884
1247
  ws.onerror = (_event) => {
885
- const handler = this.#wsOnErrorHandler;
886
- if (!handler) return;
887
1248
  const [ptr, len] = this._writeStringToWasm("WebSocket error");
888
- invokeWasmExport(handler, wsId, ptr, len);
1249
+ this._invoke(CallbackType_WebSocketError, wsId, BigInt(ptr), BigInt(len));
889
1250
  };
890
1251
  ws.onclose = (event) => {
891
- const handler = this.#wsOnCloseHandler;
892
- if (!handler) return;
893
1252
  const reason = event.reason || "";
894
1253
  const [ptr, len] = this._writeStringToWasm(reason);
895
- invokeWasmExport(handler, wsId, event.code, ptr, len, event.wasClean ? 1 : 0);
1254
+ const c = BigInt(len) | BigInt(event.wasClean ? 1 : 0) << 32n;
1255
+ this._invoke(CallbackType_WebSocketClose, wsId, BigInt(event.code), BigInt(ptr), c);
896
1256
  this.#websockets.delete(wsId);
897
1257
  };
898
1258
  this.#websockets.set(wsId, ws);
899
1259
  } catch (error) {
900
- const handler = this.#wsOnErrorHandler;
901
- if (handler) {
902
- const msg = error instanceof Error ? error.message : "WebSocket connection failed";
903
- const [ptr, len] = this._writeStringToWasm(msg);
904
- invokeWasmExport(handler, wsId, ptr, len);
905
- }
1260
+ const msg = error instanceof Error ? error.message : "WebSocket connection failed";
1261
+ const [ptr, len] = this._writeStringToWasm(msg);
1262
+ this._invoke(CallbackType_WebSocketError, wsId, BigInt(ptr), BigInt(len));
906
1263
  }
907
1264
  }
908
1265
  /** Send data over WebSocket */
@@ -1003,79 +1360,11 @@ var ZxBridge = class extends ZxBridgeCore {
1003
1360
  _wsClose: (wsId, code, reasonPtr, reasonLen) => {
1004
1361
  bridgeRef[0]?.wsClose(wsId, code, reasonPtr, reasonLen);
1005
1362
  },
1006
- _ce: (id, vnodeId) => {
1007
- const nid = Number(vnodeId);
1008
- const tagName = TAG_NAMES[id];
1009
- const el = id >= SVG_TAG_START_INDEX ? document.createElementNS("http://www.w3.org/2000/svg", tagName) : document.createElement(tagName);
1010
- el.__zx_ref = nid;
1011
- domNodes.set(nid, el);
1012
- },
1013
- _ct: (ptr, len, vnodeId) => {
1014
- const nid = Number(vnodeId);
1015
- const node = document.createTextNode(readString(ptr, len));
1016
- node.__zx_ref = nid;
1017
- domNodes.set(nid, node);
1018
- },
1019
- /** Insert vnode before a jsz-held end comment (hydration). */
1020
- _ih: (vnodeId, endCommentRef) => {
1021
- const child = domNodes.get(Number(vnodeId));
1022
- const end = loadValueFromRef(endCommentRef);
1023
- if (!child || !end?.parentNode) return;
1024
- end.parentNode.insertBefore(child, end);
1025
- },
1026
- _sa: (vnodeId, namePtr, nameLen, valPtr, valLen) => {
1027
- domNodes.get(Number(vnodeId))?.setAttribute(readString(namePtr, nameLen), readString(valPtr, valLen));
1028
- },
1029
- _sp: (vnodeId, namePtr, nameLen, valPtr, valLen) => {
1030
- const el = domNodes.get(Number(vnodeId));
1031
- if (el) {
1032
- const name = readString(namePtr, nameLen);
1033
- const val = readString(valPtr, valLen);
1034
- if (name === "checked" || name === "selected" || name === "muted") {
1035
- el[name] = val !== "false";
1036
- } else {
1037
- el[name] = val;
1038
- }
1039
- }
1040
- },
1041
- _ra: (vnodeId, namePtr, nameLen) => {
1042
- domNodes.get(Number(vnodeId))?.removeAttribute(readString(namePtr, nameLen));
1043
- },
1044
- _snv: (vnodeId, ptr, len) => {
1045
- const node = domNodes.get(Number(vnodeId));
1046
- if (node) node.nodeValue = readString(ptr, len);
1047
- },
1048
- _srh: (vnodeId, ptr, len) => {
1049
- const el = domNodes.get(Number(vnodeId));
1050
- if (el) el.innerHTML = readString(ptr, len);
1051
- },
1052
- _ac: (parentId, childId) => {
1053
- const parent = domNodes.get(Number(parentId));
1054
- const child = domNodes.get(Number(childId));
1055
- if (parent && child) parent.appendChild(child);
1056
- },
1057
- _ib: (parentId, childId, refId) => {
1058
- const parent = domNodes.get(Number(parentId));
1059
- const child = domNodes.get(Number(childId));
1060
- const ref = domNodes.get(Number(refId)) ?? null;
1061
- if (parent && child) parent.insertBefore(child, ref);
1062
- },
1063
- _rc: (parentId, childId) => {
1064
- const parent = domNodes.get(Number(parentId));
1065
- const child = domNodes.get(Number(childId));
1066
- if (parent && child) {
1067
- parent.removeChild(child);
1068
- cleanupDomNodes(child);
1069
- }
1070
- },
1071
- _rpc: (parentId, newId, oldId) => {
1072
- const parent = domNodes.get(Number(parentId));
1073
- const newChild = domNodes.get(Number(newId));
1074
- const oldChild = domNodes.get(Number(oldId));
1075
- if (parent && newChild && oldChild) {
1076
- parent.replaceChild(newChild, oldChild);
1077
- cleanupDomNodes(oldChild);
1078
- }
1363
+ _flush: (ptr, len) => {
1364
+ flushDomCmds(ptr, len, {
1365
+ domNodes,
1366
+ cleanupDomNodes
1367
+ });
1079
1368
  },
1080
1369
  _getLocationHref: (bufPtr, bufLen) => {
1081
1370
  const bytes = textEncoder.encode(window.location.href);
@@ -1140,247 +1429,10 @@ function cleanupDomNodes(node) {
1140
1429
  const children = n.childNodes;
1141
1430
  for (let i = 0; i < children.length; i++) stack.push(children[i]);
1142
1431
  }
1143
- for (const eventTypeId of HIGH_FREQ_EVENT_IDS) {
1144
- if (highFreqBits & 1 << eventTypeId) maybeRemoveHighFreqListener(eventTypeId);
1432
+ for (let bits = highFreqBits & HIGH_FREQ_EVENT_BITS; bits !== 0; bits &= bits - 1) {
1433
+ maybeRemoveHighFreqListener(31 - Math.clz32(bits));
1145
1434
  }
1146
1435
  }
1147
- var SVG_TAG_START_INDEX = 140;
1148
- var TAG_NAMES = [
1149
- "aside",
1150
- "fragment",
1151
- "iframe",
1152
- "slot",
1153
- "img",
1154
- "html",
1155
- "base",
1156
- "head",
1157
- "link",
1158
- "meta",
1159
- "script",
1160
- "style",
1161
- "title",
1162
- "address",
1163
- "article",
1164
- "body",
1165
- "h1",
1166
- "h6",
1167
- "footer",
1168
- "header",
1169
- "h2",
1170
- "h3",
1171
- "h4",
1172
- "h5",
1173
- "hgroup",
1174
- "nav",
1175
- "section",
1176
- "dd",
1177
- "dl",
1178
- "dt",
1179
- "div",
1180
- "figcaption",
1181
- "figure",
1182
- "hr",
1183
- "li",
1184
- "ol",
1185
- "ul",
1186
- "menu",
1187
- "main",
1188
- "p",
1189
- "picture",
1190
- "pre",
1191
- "a",
1192
- "abbr",
1193
- "b",
1194
- "bdi",
1195
- "bdo",
1196
- "br",
1197
- "cite",
1198
- "code",
1199
- "data",
1200
- "time",
1201
- "dfn",
1202
- "em",
1203
- "i",
1204
- "kbd",
1205
- "mark",
1206
- "q",
1207
- "blockquote",
1208
- "rp",
1209
- "ruby",
1210
- "rt",
1211
- "rtc",
1212
- "rb",
1213
- "s",
1214
- "del",
1215
- "ins",
1216
- "samp",
1217
- "small",
1218
- "span",
1219
- "strong",
1220
- "sub",
1221
- "sup",
1222
- "u",
1223
- "var",
1224
- "wbr",
1225
- "area",
1226
- "map",
1227
- "audio",
1228
- "source",
1229
- "track",
1230
- "video",
1231
- "embed",
1232
- "object",
1233
- "param",
1234
- "canvas",
1235
- "noscript",
1236
- "caption",
1237
- "table",
1238
- "col",
1239
- "colgroup",
1240
- "tbody",
1241
- "tr",
1242
- "thead",
1243
- "tfoot",
1244
- "td",
1245
- "th",
1246
- "button",
1247
- "datalist",
1248
- "option",
1249
- "fieldset",
1250
- "label",
1251
- "form",
1252
- "input",
1253
- "keygen",
1254
- "legend",
1255
- "meter",
1256
- "optgroup",
1257
- "select",
1258
- "output",
1259
- "progress",
1260
- "textarea",
1261
- "details",
1262
- "dialog",
1263
- "menuitem",
1264
- "summary",
1265
- "content",
1266
- "element",
1267
- "shadow",
1268
- "template",
1269
- "acronym",
1270
- "applet",
1271
- "basefont",
1272
- "font",
1273
- "big",
1274
- "blink",
1275
- "center",
1276
- "command",
1277
- "dir",
1278
- "frame",
1279
- "frameset",
1280
- "isindex",
1281
- "listing",
1282
- "marquee",
1283
- "noembed",
1284
- "plaintext",
1285
- "spacer",
1286
- "strike",
1287
- "tt",
1288
- "xmp",
1289
- // SVG Tags
1290
- "animate",
1291
- "animateMotion",
1292
- "animateTransform",
1293
- "circle",
1294
- "clipPath",
1295
- "defs",
1296
- "desc",
1297
- "ellipse",
1298
- "feBlend",
1299
- "feColorMatrix",
1300
- "feComponentTransfer",
1301
- "feComposite",
1302
- "feConvolveMatrix",
1303
- "feDiffuseLighting",
1304
- "feDisplacementMap",
1305
- "feDistantLight",
1306
- "feDropShadow",
1307
- "feFlood",
1308
- "feFuncA",
1309
- "feFuncB",
1310
- "feFuncG",
1311
- "feFuncR",
1312
- "feGaussianBlur",
1313
- "feImage",
1314
- "feMerge",
1315
- "feMergeNode",
1316
- "feMorphology",
1317
- "feOffset",
1318
- "fePointLight",
1319
- "feSpecularLighting",
1320
- "feSpotLight",
1321
- "feTile",
1322
- "feTurbulence",
1323
- "filter",
1324
- "foreignObject",
1325
- "g",
1326
- "image",
1327
- "line",
1328
- "linearGradient",
1329
- "marker",
1330
- "mask",
1331
- "metadata",
1332
- "mpath",
1333
- "path",
1334
- "pattern",
1335
- "polygon",
1336
- "polyline",
1337
- "radialGradient",
1338
- "rect",
1339
- "set",
1340
- "stop",
1341
- "svg",
1342
- "switch",
1343
- "symbol",
1344
- "text",
1345
- "textPath",
1346
- "tspan",
1347
- "use",
1348
- "view"
1349
- ];
1350
- var DELEGATED_EVENTS = [
1351
- "click",
1352
- "dblclick",
1353
- "input",
1354
- "change",
1355
- "submit",
1356
- // focus/blur do not bubble - listen to focusin/focusout instead.
1357
- "focusin",
1358
- "focusout",
1359
- "keydown",
1360
- "keyup",
1361
- "keypress",
1362
- "mouseenter",
1363
- "mouseleave",
1364
- "mousedown",
1365
- "mouseup",
1366
- "mousemove",
1367
- "touchstart",
1368
- "touchend",
1369
- "touchmove",
1370
- "scroll",
1371
- "wheel",
1372
- "pointerdown",
1373
- "pointermove",
1374
- "pointerup",
1375
- "pointercancel"
1376
- ];
1377
- var HIGH_FREQ_EVENT_IDS = new Set([
1378
- DELEGATED_EVENTS.indexOf("mousemove"),
1379
- DELEGATED_EVENTS.indexOf("pointermove"),
1380
- DELEGATED_EVENTS.indexOf("wheel"),
1381
- DELEGATED_EVENTS.indexOf("scroll"),
1382
- DELEGATED_EVENTS.indexOf("touchmove")
1383
- ].filter((id) => id >= 0));
1384
1436
  var delegationState = null;
1385
1437
  function makeDelegatedListener(bridge, eventTypeId) {
1386
1438
  return (event) => {
@@ -1428,7 +1480,7 @@ function anyHandlerForType(eventTypeId) {
1428
1480
  return false;
1429
1481
  }
1430
1482
  function maybeRemoveHighFreqListener(eventTypeId) {
1431
- if (!HIGH_FREQ_EVENT_IDS.has(eventTypeId)) return;
1483
+ if ((HIGH_FREQ_EVENT_BITS & 1 << eventTypeId) === 0) return;
1432
1484
  if (anyHandlerForType(eventTypeId)) return;
1433
1485
  const state = delegationState;
1434
1486
  if (!state) return;
@@ -1444,7 +1496,7 @@ function initEventDelegation(bridge, rootSelector = "body") {
1444
1496
  };
1445
1497
  delegationState = { root, bridge, attached: /* @__PURE__ */ new Map() };
1446
1498
  for (let eventTypeId = 0; eventTypeId < DELEGATED_EVENTS.length; eventTypeId++) {
1447
- if (HIGH_FREQ_EVENT_IDS.has(eventTypeId)) continue;
1499
+ if ((HIGH_FREQ_EVENT_BITS & 1 << eventTypeId) !== 0) continue;
1448
1500
  ensureDelegatedListener(eventTypeId);
1449
1501
  }
1450
1502
  return () => {