ziex 0.1.0-dev.1458 → 0.1.0-dev.1567

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 = {
@@ -251,7 +275,7 @@ var ZigJS = class {
251
275
  function createFetchImports(getMemory) {
252
276
  const encoder2 = new TextEncoder();
253
277
  const decoder2 = new TextDecoder();
254
- function readStr(ptr, len) {
278
+ function readStr2(ptr, len) {
255
279
  return decoder2.decode(new Uint8Array(getMemory().buffer, ptr, len));
256
280
  }
257
281
  function writeBytes2(buf_ptr, buf_max, data) {
@@ -277,9 +301,9 @@ function createFetchImports(getMemory) {
277
301
  return headers;
278
302
  }
279
303
  async function doFetch(url_ptr, url_len, method_ptr, method_len, headers_ptr, headers_len, body_ptr, body_len, timeout_ms, status_out, buf_ptr, buf_max) {
280
- const url = readStr(url_ptr, url_len);
281
- const method = method_len > 0 ? readStr(method_ptr, method_len) : "GET";
282
- const headersJson = headers_len > 0 ? readStr(headers_ptr, headers_len) : "{}";
304
+ const url = readStr2(url_ptr, url_len);
305
+ const method = method_len > 0 ? readStr2(method_ptr, method_len) : "GET";
306
+ const headersJson = headers_len > 0 ? readStr2(headers_ptr, headers_len) : "{}";
283
307
  const body = body_len > 0 ? readBytes(body_ptr, body_len) : void 0;
284
308
  const headers = parseHeaders(headersJson);
285
309
  const controller = new AbortController();
@@ -302,14 +326,14 @@ function createFetchImports(getMemory) {
302
326
  return -1;
303
327
  }
304
328
  }
305
- const Suspending = WebAssembly.Suspending;
306
- if (typeof Suspending !== "function") {
329
+ const Suspending2 = WebAssembly.Suspending;
330
+ if (typeof Suspending2 !== "function") {
307
331
  return {
308
332
  fetch: (_url_ptr, _url_len, _method_ptr, _method_len, _headers_ptr, _headers_len, _body_ptr, _body_len, _timeout_ms, _status_out, _buf_ptr, _buf_max) => -1
309
333
  };
310
334
  }
311
335
  return {
312
- fetch: new Suspending(doFetch)
336
+ fetch: new Suspending2(doFetch)
313
337
  };
314
338
  }
315
339
 
@@ -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,240 +595,619 @@ function bindWasmAlloc(allocRef, exports) {
575
595
  allocRef[0] = exports.__zx_alloc;
576
596
  }
577
597
 
578
- // src/runtime/kv/extern.ts
579
- function putOptions(ttlSeconds) {
580
- if (ttlSeconds < 60) return void 0;
581
- return { expirationTtl: ttlSeconds };
582
- }
583
- function isSyncKVNamespace(binding) {
584
- const candidate = binding;
585
- return typeof candidate.getSync === "function" && typeof candidate.putSync === "function" && typeof candidate.deleteSync === "function" && typeof candidate.listSync === "function";
586
- }
587
- function createKVImports(bindings, getMemory, allocRef) {
588
- const encoder2 = new TextEncoder();
589
- const decoder2 = new TextDecoder();
590
- function readStr(ptr, len) {
591
- return decoder2.decode(new Uint8Array(getMemory().buffer, ptr, len));
592
- }
593
- function binding(ns) {
594
- return bindings[ns] ?? bindings["default"] ?? null;
595
- }
596
- const Suspending = WebAssembly.Suspending;
597
- if (typeof Suspending !== "function") {
598
- let syncBinding2 = function(ns) {
599
- const candidate = binding(ns);
600
- return candidate && isSyncKVNamespace(candidate) ? candidate : null;
601
- };
602
- var syncBinding = syncBinding2;
603
- return {
604
- kv_get: (ns_ptr, ns_len, key_ptr, key_len, out_ptr) => {
605
- const b = syncBinding2(readStr(ns_ptr, ns_len));
606
- if (!b) return -1;
607
- const value = b.getSync(readStr(key_ptr, key_len));
608
- if (value === null) return -1;
609
- return writeBytesOut(getMemory, allocRef, out_ptr, encoder2.encode(value));
610
- },
611
- kv_put: (ns_ptr, ns_len, key_ptr, key_len, val_ptr, val_len, ttl_seconds) => {
612
- const b = syncBinding2(readStr(ns_ptr, ns_len));
613
- if (!b) return 0;
614
- b.putSync(readStr(key_ptr, key_len), readStr(val_ptr, val_len), putOptions(ttl_seconds));
615
- return 0;
616
- },
617
- kv_delete: (ns_ptr, ns_len, key_ptr, key_len) => {
618
- const b = syncBinding2(readStr(ns_ptr, ns_len));
619
- if (!b) return 0;
620
- b.deleteSync(readStr(key_ptr, key_len));
621
- return 0;
622
- },
623
- kv_list: (ns_ptr, ns_len, pfx_ptr, pfx_len, out_ptr) => {
624
- const b = syncBinding2(readStr(ns_ptr, ns_len));
625
- if (!b) return writeJsonOut(getMemory, allocRef, out_ptr, []);
626
- const prefix = readStr(pfx_ptr, pfx_len);
627
- const result = b.listSync(prefix.length > 0 ? { prefix } : void 0);
628
- return writeJsonOut(getMemory, allocRef, out_ptr, result.keys.map((k) => k.name));
629
- }
630
- };
631
- }
632
- return {
633
- kv_get: new Suspending(async (ns_ptr, ns_len, key_ptr, key_len, out_ptr) => {
634
- const b = binding(readStr(ns_ptr, ns_len));
635
- if (!b) return -1;
636
- const value = await b.get(readStr(key_ptr, key_len));
637
- if (value === null) return -1;
638
- return writeBytesOut(getMemory, allocRef, out_ptr, encoder2.encode(value));
639
- }),
640
- kv_put: new Suspending(async (ns_ptr, ns_len, key_ptr, key_len, val_ptr, val_len, ttl_seconds) => {
641
- const b = binding(readStr(ns_ptr, ns_len));
642
- if (!b) return -1;
643
- await b.put(readStr(key_ptr, key_len), readStr(val_ptr, val_len), putOptions(ttl_seconds));
644
- return 0;
645
- }),
646
- kv_delete: new Suspending(async (ns_ptr, ns_len, key_ptr, key_len) => {
647
- const b = binding(readStr(ns_ptr, ns_len));
648
- if (!b) return -1;
649
- await b.delete(readStr(key_ptr, key_len));
650
- return 0;
651
- }),
652
- kv_list: new Suspending(async (ns_ptr, ns_len, prefix_ptr, prefix_len, out_ptr) => {
653
- const b = binding(readStr(ns_ptr, ns_len));
654
- if (!b) return writeJsonOut(getMemory, allocRef, out_ptr, []);
655
- const prefix = readStr(prefix_ptr, prefix_len);
656
- const result = await b.list(prefix.length > 0 ? { prefix } : void 0);
657
- const names = result.keys.map((k) => k.name);
658
- if (names.length === 0) {
659
- new DataView(getMemory().buffer).setUint32(out_ptr, 0, true);
660
- return 0;
661
- }
662
- return writeJsonOut(getMemory, allocRef, out_ptr, names);
663
- })
664
- };
665
- }
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
+ ];
666
801
 
667
- // src/runtime/kv/localstorage.ts
668
- function getLocalStorage() {
669
- if (typeof localStorage === "undefined") {
670
- throw new Error("localStorage is not available in this environment");
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
+ var BOOL_PROPS = /* @__PURE__ */ new Set([
808
+ "checked",
809
+ "selected",
810
+ "muted",
811
+ "defaultChecked",
812
+ "indeterminate"
813
+ ]);
814
+ function enqueueAfterConnect(queue, el, kind) {
815
+ for (let i = 0; i < queue.length; i++) {
816
+ const job = queue[i];
817
+ if (job.el === el && job.kind === kind) return;
671
818
  }
672
- return localStorage;
819
+ queue.push({ el, kind });
673
820
  }
674
- function createLocalStorageKV(options = {}) {
675
- const storage = getLocalStorage();
676
- const namespace = options.namespace ?? "default";
677
- const storagePrefix = options.storagePrefix ?? "ziex-kv";
678
- const scopedKey = (key) => `${storagePrefix}:${namespace}:${key}`;
679
- const namespacePrefix = scopedKey("");
680
- return {
681
- getSync(key) {
682
- return storage.getItem(scopedKey(key));
683
- },
684
- async get(key) {
685
- return this.getSync(key);
686
- },
687
- putSync(key, value) {
688
- storage.setItem(scopedKey(key), value);
689
- },
690
- async put(key, value) {
691
- this.putSync(key, value);
692
- },
693
- deleteSync(key) {
694
- storage.removeItem(scopedKey(key));
695
- },
696
- async delete(key) {
697
- this.deleteSync(key);
698
- },
699
- listSync(options2) {
700
- const prefix = namespacePrefix + (options2?.prefix ?? "");
701
- const keys = [];
702
- for (let i = 0; i < storage.length; i += 1) {
703
- const key = storage.key(i);
704
- if (!key || !key.startsWith(prefix)) continue;
705
- keys.push({ name: key.slice(namespacePrefix.length) });
821
+ function runAfterConnect(queue) {
822
+ for (let i = 0; i < queue.length; i++) {
823
+ const job = queue[i];
824
+ if (!job.el.isConnected) continue;
825
+ switch (job.kind) {
826
+ case "focus": {
827
+ if (typeof job.el.focus !== "function") break;
828
+ try {
829
+ job.el.focus({ preventScroll: true });
830
+ } catch {
831
+ job.el.focus();
832
+ }
833
+ break;
706
834
  }
707
- return { keys };
708
- },
709
- async list(options2) {
710
- return this.listSync(options2);
711
835
  }
712
- };
713
- }
714
-
715
- // src/runtime/kv/indexdb.ts
716
- function getIndexedDb() {
717
- if (typeof indexedDB === "undefined") {
718
- throw new Error("IndexedDB is not available in this environment");
719
836
  }
720
- return indexedDB;
721
837
  }
722
- function requestToPromise(request) {
723
- return new Promise((resolve, reject) => {
724
- request.onsuccess = () => resolve(request.result);
725
- request.onerror = () => reject(request.error ?? new Error("IndexedDB request failed"));
726
- });
838
+ function assignProp(el, name, val) {
839
+ if (BOOL_PROPS.has(name)) {
840
+ const on = val !== "false";
841
+ el[name] = on;
842
+ if (name === "defaultChecked" && "checked" in el) {
843
+ el.checked = on;
844
+ }
845
+ return;
846
+ }
847
+ if (name === "defaultValue") {
848
+ el.defaultValue = val;
849
+ if (typeof el.value === "string" && (el.value === "" || el.value === el.defaultValue)) {
850
+ el.value = val;
851
+ }
852
+ return;
853
+ }
854
+ el[name] = val;
727
855
  }
728
- function transactionToPromise(transaction) {
729
- return new Promise((resolve, reject) => {
730
- transaction.oncomplete = () => resolve();
731
- transaction.onabort = () => reject(transaction.error ?? new Error("IndexedDB transaction aborted"));
732
- transaction.onerror = () => reject(transaction.error ?? new Error("IndexedDB transaction failed"));
733
- });
734
- }
735
- function createIndexedDbKV(options = {}) {
736
- const databaseName = options.databaseName ?? "ziex-kv";
737
- const storeName = options.storeName ?? "kv";
738
- const namespace = options.namespace ?? "default";
739
- const dbPromise = new Promise((resolve, reject) => {
740
- const request = getIndexedDb().open(databaseName, 1);
741
- request.onupgradeneeded = () => {
742
- const db = request.result;
743
- if (!db.objectStoreNames.contains(storeName)) {
744
- db.createObjectStore(storeName);
856
+ function flushDomCmds(ptr, len, ctx) {
857
+ const start = ptr >>> 0;
858
+ const length = len >>> 0;
859
+ if (length < DOM_CMD_HEADER_SIZE) return;
860
+ const mem = getMemoryView();
861
+ if (start + length > mem.byteLength) return;
862
+ const view = new DataView(mem.buffer, mem.byteOffset + start, length);
863
+ const count = view.getUint32(0, true);
864
+ const recordsBytes = count * DOM_CMD_RECORD_SIZE;
865
+ if (DOM_CMD_HEADER_SIZE + recordsBytes > length) return;
866
+ const { domNodes: domNodes2, cleanupDomNodes: cleanupDomNodes2 } = ctx;
867
+ const afterConnect = [];
868
+ for (let i = 0; i < count; i++) {
869
+ const off = DOM_CMD_HEADER_SIZE + i * DOM_CMD_RECORD_SIZE;
870
+ const op = view.getUint8(off);
871
+ const p0 = view.getUint32(off + 4, true);
872
+ const p1 = view.getUint32(off + 8, true);
873
+ const p2 = view.getUint32(off + 12, true);
874
+ const p3 = view.getUint32(off + 16, true);
875
+ const p4 = view.getUint32(off + 20, true);
876
+ switch (op) {
877
+ case DomOp_CreateElement: {
878
+ const isCustom = p0 === CUSTOM_TAG_INDEX;
879
+ const tagName = isCustom ? readString(p2, p3) : TAG_NAMES[p0];
880
+ const el = !isCustom && p0 >= SVG_TAG_START_INDEX ? document.createElementNS("http://www.w3.org/2000/svg", tagName) : document.createElement(tagName);
881
+ el.__zx_ref = p1;
882
+ domNodes2.set(p1, el);
883
+ break;
745
884
  }
746
- };
747
- request.onsuccess = () => resolve(request.result);
748
- request.onerror = () => reject(request.error ?? new Error("Failed to open IndexedDB"));
749
- });
750
- const scopedKey = (key) => `${namespace}:${key}`;
885
+ case DomOp_CreateText: {
886
+ const node = document.createTextNode(readString(p0, p1));
887
+ node.__zx_ref = p2;
888
+ domNodes2.set(p2, node);
889
+ break;
890
+ }
891
+ case DomOp_HydrateInsert: {
892
+ const child = domNodes2.get(p0);
893
+ const ref = BigInt(p1) | BigInt(p2) << 32n;
894
+ const end = loadValueFromRef(ref);
895
+ if (!child || !end?.parentNode) break;
896
+ end.parentNode.insertBefore(child, end);
897
+ break;
898
+ }
899
+ case DomOp_SetAttr: {
900
+ const el = domNodes2.get(p0);
901
+ if (!el) break;
902
+ const name = readString(p1, p2);
903
+ const val = readString(p3, p4);
904
+ el.setAttribute(name, val);
905
+ if (name === "autofocus") {
906
+ enqueueAfterConnect(afterConnect, el, "focus");
907
+ }
908
+ break;
909
+ }
910
+ case DomOp_SetProp: {
911
+ const el = domNodes2.get(p0);
912
+ if (el) assignProp(el, readString(p1, p2), readString(p3, p4));
913
+ break;
914
+ }
915
+ case DomOp_RemoveAttr: {
916
+ domNodes2.get(p0)?.removeAttribute(readString(p1, p2));
917
+ break;
918
+ }
919
+ case DomOp_SetNodeValue: {
920
+ const node = domNodes2.get(p0);
921
+ if (node) node.nodeValue = readString(p1, p2);
922
+ break;
923
+ }
924
+ case DomOp_SetInnerHtml: {
925
+ const el = domNodes2.get(p0);
926
+ if (el) el.innerHTML = readString(p1, p2);
927
+ break;
928
+ }
929
+ case DomOp_AppendChild: {
930
+ const parent = domNodes2.get(p0);
931
+ const child = domNodes2.get(p1);
932
+ if (parent && child) parent.appendChild(child);
933
+ break;
934
+ }
935
+ case DomOp_InsertBefore: {
936
+ const parent = domNodes2.get(p0);
937
+ const child = domNodes2.get(p1);
938
+ const refNode = domNodes2.get(p2) ?? null;
939
+ if (parent && child) parent.insertBefore(child, refNode);
940
+ break;
941
+ }
942
+ case DomOp_RemoveChild: {
943
+ const parent = domNodes2.get(p0);
944
+ const child = domNodes2.get(p1);
945
+ if (parent && child) {
946
+ parent.removeChild(child);
947
+ cleanupDomNodes2(child);
948
+ }
949
+ break;
950
+ }
951
+ case DomOp_ReplaceChild: {
952
+ const parent = domNodes2.get(p0);
953
+ const newChild = domNodes2.get(p1);
954
+ const oldChild = domNodes2.get(p2);
955
+ if (parent && newChild && oldChild) {
956
+ parent.replaceChild(newChild, oldChild);
957
+ cleanupDomNodes2(oldChild);
958
+ }
959
+ break;
960
+ }
961
+ default:
962
+ break;
963
+ }
964
+ }
965
+ runAfterConnect(afterConnect);
966
+ }
967
+
968
+ // src/runtime/kv/extern.ts
969
+ var Suspending = WebAssembly.Suspending;
970
+ var jspi = typeof Suspending === "function";
971
+ var miss = jspi ? -1 : 0;
972
+ function putOptions(ttlSeconds) {
973
+ if (ttlSeconds < 60) return void 0;
974
+ return { expirationTtl: ttlSeconds };
975
+ }
976
+ function kvDel(binding, key) {
977
+ const b = binding;
978
+ return (b.del ?? b.delete).call(b, key);
979
+ }
980
+ function isSyncKVNamespace(binding) {
981
+ return typeof binding.get === "function" && binding.get.constructor.name !== "AsyncFunction";
982
+ }
983
+ function listOpts(prefix) {
984
+ return prefix.length > 0 ? { prefix } : void 0;
985
+ }
986
+ function maybeThen(r, f) {
987
+ return r instanceof Promise ? r.then(f) : f(r);
988
+ }
989
+ function readStr(getMemory, ptr, len) {
990
+ return textDecoder.decode(new Uint8Array(getMemory().buffer, ptr, len));
991
+ }
992
+ function resolve(bindings, ns) {
993
+ const b = bindings[ns] ?? bindings["default"] ?? null;
994
+ if (!b || jspi) return b;
995
+ return isSyncKVNamespace(b) ? b : null;
996
+ }
997
+ function encodeGet(getMemory, allocRef, value, out_ptr) {
998
+ if (value === null) return -1;
999
+ return writeBytesOut(getMemory, allocRef, out_ptr, textEncoder.encode(value));
1000
+ }
1001
+ function encodeList(getMemory, allocRef, names, out_ptr) {
1002
+ if (names.length === 0) {
1003
+ new DataView(getMemory().buffer).setUint32(out_ptr, 0, true);
1004
+ return 0;
1005
+ }
1006
+ return writeJsonOut(getMemory, allocRef, out_ptr, names);
1007
+ }
1008
+ function get(b, key, out_ptr, getMemory, allocRef) {
1009
+ return maybeThen(b.get(key), (v) => encodeGet(getMemory, allocRef, v, out_ptr));
1010
+ }
1011
+ function put(b, key, val, ttl) {
1012
+ return maybeThen(b.put(key, val, putOptions(ttl)), () => 0);
1013
+ }
1014
+ function del(b, key) {
1015
+ return maybeThen(kvDel(b, key), () => 0);
1016
+ }
1017
+ function list(b, prefix, out_ptr, getMemory, allocRef) {
1018
+ return maybeThen(
1019
+ b.list(listOpts(prefix)),
1020
+ (result) => encodeList(getMemory, allocRef, result.keys.map((k) => k.name), out_ptr)
1021
+ );
1022
+ }
1023
+ function wrapImport(impl) {
1024
+ if (!jspi) {
1025
+ return ((...args) => {
1026
+ const r = impl(...args);
1027
+ if (r instanceof Promise) throw new Error("async kv binding requires JSPI");
1028
+ return r;
1029
+ });
1030
+ }
1031
+ return new Suspending(impl);
1032
+ }
1033
+ function createKVImports(bindings, getMemory, allocRef) {
751
1034
  return {
752
- async get(key) {
753
- const db = await dbPromise;
754
- const tx = db.transaction(storeName, "readonly");
755
- const store = tx.objectStore(storeName);
756
- const value = await requestToPromise(store.get(scopedKey(key)));
757
- await transactionToPromise(tx);
758
- return typeof value === "string" ? value : null;
759
- },
760
- async put(key, value) {
761
- const db = await dbPromise;
762
- const tx = db.transaction(storeName, "readwrite");
763
- tx.objectStore(storeName).put(value, scopedKey(key));
764
- await transactionToPromise(tx);
765
- },
766
- async delete(key) {
767
- const db = await dbPromise;
768
- const tx = db.transaction(storeName, "readwrite");
769
- tx.objectStore(storeName).delete(scopedKey(key));
770
- await transactionToPromise(tx);
771
- },
772
- async list(options2) {
773
- const db = await dbPromise;
774
- const tx = db.transaction(storeName, "readonly");
775
- const store = tx.objectStore(storeName);
776
- const keys = await requestToPromise(store.getAllKeys());
777
- await transactionToPromise(tx);
778
- const prefix = scopedKey(options2?.prefix ?? "");
779
- return {
780
- keys: keys.filter((key) => typeof key === "string" && key.startsWith(prefix)).map((key) => ({ name: key.slice(namespace.length + 1) }))
781
- };
1035
+ kv_get: wrapImport((ns_ptr, ns_len, key_ptr, key_len, out_ptr) => {
1036
+ const b = resolve(bindings, readStr(getMemory, ns_ptr, ns_len));
1037
+ if (!b) return -1;
1038
+ return get(b, readStr(getMemory, key_ptr, key_len), out_ptr, getMemory, allocRef);
1039
+ }),
1040
+ kv_put: wrapImport((ns_ptr, ns_len, key_ptr, key_len, val_ptr, val_len, ttl_seconds) => {
1041
+ const b = resolve(bindings, readStr(getMemory, ns_ptr, ns_len));
1042
+ if (!b) return miss;
1043
+ return put(
1044
+ b,
1045
+ readStr(getMemory, key_ptr, key_len),
1046
+ readStr(getMemory, val_ptr, val_len),
1047
+ ttl_seconds
1048
+ );
1049
+ }),
1050
+ kv_delete: wrapImport((ns_ptr, ns_len, key_ptr, key_len) => {
1051
+ const b = resolve(bindings, readStr(getMemory, ns_ptr, ns_len));
1052
+ if (!b) return miss;
1053
+ return del(b, readStr(getMemory, key_ptr, key_len));
1054
+ }),
1055
+ kv_list: wrapImport((ns_ptr, ns_len, pfx_ptr, pfx_len, out_ptr) => {
1056
+ const b = resolve(bindings, readStr(getMemory, ns_ptr, ns_len));
1057
+ if (!b) return writeJsonOut(getMemory, allocRef, out_ptr, []);
1058
+ return list(b, readStr(getMemory, pfx_ptr, pfx_len), out_ptr, getMemory, allocRef);
1059
+ })
1060
+ };
1061
+ }
1062
+
1063
+ // src/runtime/kv/localstorage.ts
1064
+ var namespace = "default";
1065
+ var storagePrefix = "ziex-kv";
1066
+ var namespacePrefix = `${storagePrefix}:${namespace}:`;
1067
+ function storage() {
1068
+ if (typeof localStorage === "undefined") {
1069
+ throw new Error("localStorage is not available in this environment");
1070
+ }
1071
+ return localStorage;
1072
+ }
1073
+ function get2(key) {
1074
+ return storage().getItem(`${storagePrefix}:${namespace}:${key}`);
1075
+ }
1076
+ function put2(key, value) {
1077
+ storage().setItem(`${storagePrefix}:${namespace}:${key}`, value);
1078
+ }
1079
+ function del2(key) {
1080
+ storage().removeItem(`${storagePrefix}:${namespace}:${key}`);
1081
+ }
1082
+ function list2(options) {
1083
+ const ls = storage();
1084
+ const prefix = namespacePrefix + (options?.prefix ?? "");
1085
+ const keys = [];
1086
+ for (let i = 0; i < ls.length; i += 1) {
1087
+ const key = ls.key(i);
1088
+ if (!key || !key.startsWith(prefix)) continue;
1089
+ keys.push({ name: key.slice(namespacePrefix.length) });
1090
+ }
1091
+ return { keys };
1092
+ }
1093
+
1094
+ // src/runtime/kv/indexdb.ts
1095
+ var databaseName = "ziex-kv";
1096
+ var storeName = "kv";
1097
+ var namespace2 = "default";
1098
+ var dbPromise;
1099
+ function openDb() {
1100
+ if (!dbPromise) {
1101
+ if (typeof indexedDB === "undefined") {
1102
+ return Promise.reject(new Error("IndexedDB is not available in this environment"));
782
1103
  }
1104
+ dbPromise = new Promise((resolve2, reject) => {
1105
+ const request = indexedDB.open(databaseName, 1);
1106
+ request.onupgradeneeded = () => {
1107
+ const db = request.result;
1108
+ if (!db.objectStoreNames.contains(storeName)) {
1109
+ db.createObjectStore(storeName);
1110
+ }
1111
+ };
1112
+ request.onsuccess = () => resolve2(request.result);
1113
+ request.onerror = () => reject(request.error ?? new Error("Failed to open IndexedDB"));
1114
+ });
1115
+ }
1116
+ return dbPromise;
1117
+ }
1118
+ function requestToPromise(request) {
1119
+ return new Promise((resolve2, reject) => {
1120
+ request.onsuccess = () => resolve2(request.result);
1121
+ request.onerror = () => reject(request.error ?? new Error("IndexedDB request failed"));
1122
+ });
1123
+ }
1124
+ function transactionToPromise(transaction) {
1125
+ return new Promise((resolve2, reject) => {
1126
+ transaction.oncomplete = () => resolve2();
1127
+ transaction.onabort = () => reject(transaction.error ?? new Error("IndexedDB transaction aborted"));
1128
+ transaction.onerror = () => reject(transaction.error ?? new Error("IndexedDB transaction failed"));
1129
+ });
1130
+ }
1131
+ async function get3(key) {
1132
+ const db = await openDb();
1133
+ const tx = db.transaction(storeName, "readonly");
1134
+ const value = await requestToPromise(tx.objectStore(storeName).get(`${namespace2}:${key}`));
1135
+ await transactionToPromise(tx);
1136
+ return typeof value === "string" ? value : null;
1137
+ }
1138
+ async function put3(key, value) {
1139
+ const db = await openDb();
1140
+ const tx = db.transaction(storeName, "readwrite");
1141
+ tx.objectStore(storeName).put(value, `${namespace2}:${key}`);
1142
+ await transactionToPromise(tx);
1143
+ }
1144
+ async function del3(key) {
1145
+ const db = await openDb();
1146
+ const tx = db.transaction(storeName, "readwrite");
1147
+ tx.objectStore(storeName).delete(`${namespace2}:${key}`);
1148
+ await transactionToPromise(tx);
1149
+ }
1150
+ async function list3(options) {
1151
+ const db = await openDb();
1152
+ const tx = db.transaction(storeName, "readonly");
1153
+ const keys = await requestToPromise(tx.objectStore(storeName).getAllKeys());
1154
+ await transactionToPromise(tx);
1155
+ const prefix = `${namespace2}:${options?.prefix ?? ""}`;
1156
+ return {
1157
+ keys: keys.filter((key) => typeof key === "string" && key.startsWith(prefix)).map((key) => ({ name: key.slice(namespace2.length + 1) }))
783
1158
  };
784
1159
  }
785
1160
 
786
1161
  // src/runtime/kv.ts
787
- function hasJSPI() {
788
- return typeof WebAssembly.Suspending === "function" && typeof WebAssembly.promising === "function";
789
- }
1162
+ var hasJspi = typeof WebAssembly.Suspending === "function" && typeof WebAssembly.promising === "function";
790
1163
  function createBrowserKVBindings(options = {}) {
791
- const namespace = options.namespace ?? "default";
1164
+ const namespace3 = options.namespace ?? "default";
792
1165
  return {
793
- [namespace]: hasJSPI() ? createIndexedDbKV(options) : createLocalStorageKV(options)
1166
+ [namespace3]: hasJspi && !options.forceLocalStorage ? { get: get3, put: put3, del: del3, list: list3 } : { get: get2, put: put2, del: del2, list: list2 }
794
1167
  };
795
1168
  }
796
1169
 
1170
+ // src/wasm/generated/events.ts
1171
+ var DELEGATED_EVENTS = [
1172
+ "click",
1173
+ "dblclick",
1174
+ "input",
1175
+ "change",
1176
+ "submit",
1177
+ "focusin",
1178
+ "focusout",
1179
+ "keydown",
1180
+ "keyup",
1181
+ "keypress",
1182
+ "mouseenter",
1183
+ "mouseleave",
1184
+ "mousedown",
1185
+ "mouseup",
1186
+ "mousemove",
1187
+ "touchstart",
1188
+ "touchend",
1189
+ "touchmove",
1190
+ "scroll",
1191
+ "wheel",
1192
+ "pointerdown",
1193
+ "pointermove",
1194
+ "pointerup",
1195
+ "pointercancel",
1196
+ "pointerenter",
1197
+ "pointerleave",
1198
+ "lostpointercapture"
1199
+ ];
1200
+
1201
+ // src/wasm/generated/event_bits.ts
1202
+ var HIGH_FREQ_EVENT_BITS = 3031040;
1203
+
797
1204
  // src/wasm/index.ts
798
1205
  var ZxBridge = class extends ZxBridgeCore {
799
1206
  #websockets = /* @__PURE__ */ new Map();
800
- #wsOnOpenHandler;
801
- #wsOnMessageHandler;
802
- #wsOnErrorHandler;
803
- #wsOnCloseHandler;
804
1207
  #eventbridge;
805
1208
  #eventbridgeAsync;
806
1209
  constructor(exports) {
807
1210
  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
1211
  this.#eventbridge = exports.__zx_eventbridge;
813
1212
  this.#eventbridgeAsync = wrapPromisingExport(
814
1213
  exports.__zx_eventbridge_async ?? exports.__zx_eventbridge
@@ -834,8 +1233,8 @@ var ZxBridge = class extends ZxBridgeCore {
834
1233
  const present = eventHandlersPresent.get(velementId) ?? 0;
835
1234
  eventHandlersPresent.delete(velementId);
836
1235
  eventHandlersSuspend.delete(velementId);
837
- for (const eventTypeId of HIGH_FREQ_EVENT_IDS) {
838
- if (present & 1 << eventTypeId) maybeRemoveHighFreqListener(eventTypeId);
1236
+ for (let bits = present & HIGH_FREQ_EVENT_BITS; bits !== 0; bits &= bits - 1) {
1237
+ maybeRemoveHighFreqListener(31 - Math.clz32(bits));
839
1238
  }
840
1239
  }
841
1240
  /** Submit a form action with bound-state round-trip. */
@@ -857,7 +1256,7 @@ var ZxBridge = class extends ZxBridgeCore {
857
1256
  }
858
1257
  /**
859
1258
  * Create and connect a WebSocket.
860
- * Calls __zx_ws_onopen, __zx_ws_onmessage, __zx_ws_onerror, __zx_ws_onclose.
1259
+ * Completes via `__zx_cb(ws_open|ws_message|ws_error|ws_close, ...)`.
861
1260
  */
862
1261
  wsConnect(wsId, urlPtr, urlLen, protocolsPtr, protocolsLen) {
863
1262
  const url = readString(urlPtr, urlLen);
@@ -867,42 +1266,32 @@ var ZxBridge = class extends ZxBridgeCore {
867
1266
  const ws = protocols && protocols.length > 0 ? new WebSocket(url, protocols) : new WebSocket(url);
868
1267
  ws.binaryType = "arraybuffer";
869
1268
  ws.onopen = () => {
870
- const handler = this.#wsOnOpenHandler;
871
- if (!handler) return;
872
1269
  const protocol = ws.protocol || "";
873
1270
  const [ptr, len] = this._writeStringToWasm(protocol);
874
- invokeWasmExport(handler, wsId, ptr, len);
1271
+ this._invoke(CallbackType_WebSocketOpen, wsId, BigInt(ptr), BigInt(len));
875
1272
  };
876
1273
  ws.onmessage = (event) => {
877
- const handler = this.#wsOnMessageHandler;
878
- if (!handler) return;
879
1274
  const isBinary = event.data instanceof ArrayBuffer;
880
1275
  const data = isBinary ? new Uint8Array(event.data) : textEncoder.encode(event.data);
881
1276
  const [ptr, len] = this.writeBytesToWasm(data);
882
- invokeWasmExport(handler, wsId, ptr, len, isBinary ? 1 : 0);
1277
+ this._invoke(CallbackType_WebSocketMessage, wsId, BigInt(ptr), BigInt(len), BigInt(isBinary ? 1 : 0));
883
1278
  };
884
1279
  ws.onerror = (_event) => {
885
- const handler = this.#wsOnErrorHandler;
886
- if (!handler) return;
887
1280
  const [ptr, len] = this._writeStringToWasm("WebSocket error");
888
- invokeWasmExport(handler, wsId, ptr, len);
1281
+ this._invoke(CallbackType_WebSocketError, wsId, BigInt(ptr), BigInt(len));
889
1282
  };
890
1283
  ws.onclose = (event) => {
891
- const handler = this.#wsOnCloseHandler;
892
- if (!handler) return;
893
1284
  const reason = event.reason || "";
894
1285
  const [ptr, len] = this._writeStringToWasm(reason);
895
- invokeWasmExport(handler, wsId, event.code, ptr, len, event.wasClean ? 1 : 0);
1286
+ const c = BigInt(len) | BigInt(event.wasClean ? 1 : 0) << 32n;
1287
+ this._invoke(CallbackType_WebSocketClose, wsId, BigInt(event.code), BigInt(ptr), c);
896
1288
  this.#websockets.delete(wsId);
897
1289
  };
898
1290
  this.#websockets.set(wsId, ws);
899
1291
  } 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
- }
1292
+ const msg = error instanceof Error ? error.message : "WebSocket connection failed";
1293
+ const [ptr, len] = this._writeStringToWasm(msg);
1294
+ this._invoke(CallbackType_WebSocketError, wsId, BigInt(ptr), BigInt(len));
906
1295
  }
907
1296
  }
908
1297
  /** Send data over WebSocket */
@@ -1003,79 +1392,11 @@ var ZxBridge = class extends ZxBridgeCore {
1003
1392
  _wsClose: (wsId, code, reasonPtr, reasonLen) => {
1004
1393
  bridgeRef[0]?.wsClose(wsId, code, reasonPtr, reasonLen);
1005
1394
  },
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
- }
1395
+ _flush: (ptr, len) => {
1396
+ flushDomCmds(ptr, len, {
1397
+ domNodes,
1398
+ cleanupDomNodes
1399
+ });
1079
1400
  },
1080
1401
  _getLocationHref: (bufPtr, bufLen) => {
1081
1402
  const bytes = textEncoder.encode(window.location.href);
@@ -1114,6 +1435,10 @@ var ZxBridge = class extends ZxBridgeCore {
1114
1435
  if (!form || !(form instanceof HTMLFormElement)) return;
1115
1436
  const statesJson = statesLen > 0 ? readString(statesPtr, statesLen) : "[]";
1116
1437
  bridgeRef[0]?.submitFormActionAsync(form, actionId, statesJson, fetchId);
1438
+ },
1439
+ _formReset: (vnodeId) => {
1440
+ const form = domNodes.get(Number(vnodeId));
1441
+ if (form instanceof HTMLFormElement) form.reset();
1117
1442
  }
1118
1443
  }
1119
1444
  };
@@ -1140,247 +1465,10 @@ function cleanupDomNodes(node) {
1140
1465
  const children = n.childNodes;
1141
1466
  for (let i = 0; i < children.length; i++) stack.push(children[i]);
1142
1467
  }
1143
- for (const eventTypeId of HIGH_FREQ_EVENT_IDS) {
1144
- if (highFreqBits & 1 << eventTypeId) maybeRemoveHighFreqListener(eventTypeId);
1468
+ for (let bits = highFreqBits & HIGH_FREQ_EVENT_BITS; bits !== 0; bits &= bits - 1) {
1469
+ maybeRemoveHighFreqListener(31 - Math.clz32(bits));
1145
1470
  }
1146
1471
  }
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
1472
  var delegationState = null;
1385
1473
  function makeDelegatedListener(bridge, eventTypeId) {
1386
1474
  return (event) => {
@@ -1428,7 +1516,7 @@ function anyHandlerForType(eventTypeId) {
1428
1516
  return false;
1429
1517
  }
1430
1518
  function maybeRemoveHighFreqListener(eventTypeId) {
1431
- if (!HIGH_FREQ_EVENT_IDS.has(eventTypeId)) return;
1519
+ if ((HIGH_FREQ_EVENT_BITS & 1 << eventTypeId) === 0) return;
1432
1520
  if (anyHandlerForType(eventTypeId)) return;
1433
1521
  const state = delegationState;
1434
1522
  if (!state) return;
@@ -1444,7 +1532,7 @@ function initEventDelegation(bridge, rootSelector = "body") {
1444
1532
  };
1445
1533
  delegationState = { root, bridge, attached: /* @__PURE__ */ new Map() };
1446
1534
  for (let eventTypeId = 0; eventTypeId < DELEGATED_EVENTS.length; eventTypeId++) {
1447
- if (HIGH_FREQ_EVENT_IDS.has(eventTypeId)) continue;
1535
+ if ((HIGH_FREQ_EVENT_BITS & 1 << eventTypeId) !== 0) continue;
1448
1536
  ensureDelegatedListener(eventTypeId);
1449
1537
  }
1450
1538
  return () => {