@isoloop/dom 0.0.0-next.69da74b → 0.0.0-next.d028bc1

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.
@@ -17,6 +17,7 @@ function createApplier(container, policy) {
17
17
  const nodes = /* @__PURE__ */ new Map([[0, container]]);
18
18
  const ids = new WeakMap([[container, 0]]);
19
19
  const listens = /* @__PURE__ */ new Map();
20
+ const known = /* @__PURE__ */ new WeakMap();
20
21
  const setAttr = (el, name, value) => {
21
22
  const safe = value === null ? null : policy.attribute(el.localName, nsOf(el), name, value);
22
23
  try {
@@ -25,6 +26,7 @@ function createApplier(container, policy) {
25
26
  } catch {}
26
27
  };
27
28
  const setProp = (el, name, value, force = false) => {
29
+ if (name === "checked") known.set(el, Boolean(value));
28
30
  if (!policy.property(el, name, value, force)) return;
29
31
  if (name === "checked" && el instanceof HTMLInputElement) el.checked = Boolean(value);
30
32
  else if (name === "selected" && el instanceof HTMLOptionElement) el.selected = Boolean(value);
@@ -160,7 +162,11 @@ function createApplier(container, policy) {
160
162
  };
161
163
  const el = nodes.get(target);
162
164
  if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) out.value = el.value;
163
- if (el instanceof HTMLInputElement && (el.type === "checkbox" || el.type === "radio")) out.checked = el.checked;
165
+ if (el instanceof HTMLInputElement && el.type === "radio") out.checked = el.checked;
166
+ else if (el instanceof HTMLInputElement && el.type === "checkbox" && known.get(el) !== el.checked) {
167
+ out.checked = el.checked;
168
+ known.set(el, el.checked);
169
+ }
164
170
  if (e instanceof MouseEvent || e instanceof KeyboardEvent) out.mods = {
165
171
  alt: e.altKey,
166
172
  ctrl: e.ctrlKey,
@@ -171,6 +177,10 @@ function createApplier(container, policy) {
171
177
  out.key = e.key;
172
178
  out.code = e.code;
173
179
  }
180
+ if (e.type === "scroll" && el instanceof Element) {
181
+ out.scrollTop = el.scrollTop;
182
+ out.scrollLeft = el.scrollLeft;
183
+ }
174
184
  if (e instanceof MouseEvent) {
175
185
  out.x = e.clientX;
176
186
  out.y = e.clientY;
@@ -1,4 +1,4 @@
1
- import { i as DomRecord, n as DomEvent, o as Namespace, s as NodeId, t as DomBatch, u as SyncedProp } from "./records-2Jf3U4Sp.js";
1
+ import { i as DomRecord, n as DomEvent, o as Namespace, s as NodeId, t as DomBatch, u as SyncedProp } from "./records-OXGckMg9.js";
2
2
  type ListenerFn = (event: Event) => void;
3
3
  type Listener = {
4
4
  fn: ListenerFn | {
@@ -7,13 +7,20 @@ type Listener = {
7
7
  capture: boolean;
8
8
  once: boolean;
9
9
  };
10
- /** Shared state of one document: ids, the recorder, known nodes. */
10
+ /**
11
+ * One render root and where its records go. A worker has one; a pool has one
12
+ * per visual member, all in the same document (ADR 0015).
13
+ */
14
+ type Owner = {
15
+ readonly root: WElement;
16
+ push(r: DomRecord): void;
17
+ };
18
+ /** Shared state of one document: ids, the render roots, known nodes. */
11
19
  type Core = {
12
- /** The render root, set by `createDom()`. */
13
- root: WElement | null;
20
+ /** The render roots, in the order they were made. */
21
+ roots: Set<WElement>;
14
22
  nextId: number;
15
23
  known: Map<NodeId, WNode>;
16
- record(r: DomRecord): void;
17
24
  /** An element was inserted into `document.head`, which the bridge doesn't render. */
18
25
  onHead(tag: string): void;
19
26
  };
@@ -51,8 +58,19 @@ declare abstract class WNode extends WEventTarget {
51
58
  /** @internal */ isoNext: WNode | null;
52
59
  /** @internal Whether the host knows this node (it's in the tree under the root). */
53
60
  isoKnown: boolean;
61
+ /**
62
+ * @internal The root this node was rendered under, once it has been. Kept
63
+ * after the node leaves the tree, so it can't move to another member's root
64
+ * in a pool (ADR 0015, decision 3).
65
+ */
66
+ isoOwner: Owner | null;
54
67
  constructor(doc: WDocument, id: NodeId);
55
68
  /** @internal */ override isoParentTarget(): WEventTarget | null;
69
+ /**
70
+ * @internal The id the host knows this node by: a render root is always
71
+ * `ROOT_ID` to its own surface, whatever its id in the document.
72
+ */
73
+ get isoWire(): NodeId;
56
74
  /** @internal */ override isoListenChanged(type: string, on: boolean): void;
57
75
  get parentNode(): WParentNode | null;
58
76
  get parentElement(): WElement | null;
@@ -165,6 +183,11 @@ declare class WElement extends WParentNode {
165
183
  /** @internal */ isoStyle: WStyle | null;
166
184
  /** @internal */ isoClassList: WDOMTokenList | null;
167
185
  /** @internal */ isoDataset: Record<string, string | undefined> | null;
186
+ /** @internal The offsets the last `scroll` event brought (design §4.6). */
187
+ isoScroll: {
188
+ top: number;
189
+ left: number;
190
+ };
168
191
  constructor(doc: WDocument, id: NodeId, localName: string, ns: Namespace);
169
192
  get tagName(): string;
170
193
  get nodeName(): string;
@@ -183,6 +206,12 @@ declare class WElement extends WParentNode {
183
206
  get style(): WStyle;
184
207
  get classList(): WDOMTokenList;
185
208
  get dataset(): Record<string, string | undefined>;
209
+ /**
210
+ * Read only, and as of the last `scroll` event the element got: the host
211
+ * owns scrolling. 0 until the element is scrolled and listens for `scroll`.
212
+ */
213
+ get scrollTop(): number;
214
+ get scrollLeft(): number;
186
215
  get id(): string;
187
216
  set id(v: string);
188
217
  /** @internal */ isoSetProp(name: SyncedProp, value: string | boolean, record: boolean): void;
@@ -256,6 +285,32 @@ interface WorkerDom {
256
285
  setValue(node: WNode, value: string, opts?: {
257
286
  force?: boolean;
258
287
  }): void;
288
+ /**
289
+ * Adds another render root to this document, with its own batches: one per
290
+ * visual member of a pool (ADR 0015). Its surface knows it as `ROOT_ID`.
291
+ */
292
+ addRoot(opts: RootOptions): RenderRoot;
293
+ }
294
+ type RootOptions = {
295
+ /** Receives this root's batches, in order. */
296
+ onBatch(batch: DomBatch): void;
297
+ /** Called once per batch with the flush to run; default `queueMicrotask`. */
298
+ schedule?: (flush: () => void) => void;
299
+ };
300
+ /** One member's render root in a shared document (ADR 0015). */
301
+ interface RenderRoot {
302
+ readonly root: WElement;
303
+ /** Sends this root's pending records now, if any. */
304
+ flush(): void;
305
+ /** Dispatches an event from this root's surface; `ROOT_ID` names the root. */
306
+ deliver(event: DomEvent): void;
307
+ /** The id this root's surface knows `node` by, or `undefined` if it isn't rendered under this root. */
308
+ idOf(node: WNode): NodeId | undefined;
309
+ setValue(node: WNode, value: string, opts?: {
310
+ force?: boolean;
311
+ }): void;
312
+ /** Stops sending this root's records and forgets its nodes: the member stopped. */
313
+ dispose(): void;
259
314
  }
260
315
  declare function createDom(opts: WorkerDomOptions): WorkerDom;
261
- export { WNode as a, WorkerDomOptions as c, WElement as i, createDom as l, WDocument as n, WText as o, WDocumentFragment as r, WorkerDom as s, WComment as t };
316
+ export { WDocumentFragment as a, WText as c, createDom as d, WDocument as i, WorkerDom as l, RootOptions as n, WElement as o, WComment as r, WNode as s, RenderRoot as t, WorkerDomOptions as u };
@@ -9,6 +9,10 @@ const domError = (name, message) => {
9
9
  e.name = name;
10
10
  return e;
11
11
  };
12
+ /** Records a change to a known node, to the root that holds it. */
13
+ const emit = (n, r) => {
14
+ n.isoOwner?.push(r);
15
+ };
12
16
  /** Listener storage and capture/bubble dispatch through `isoParentTarget()`. */
13
17
  var WEventTarget = class {
14
18
  /** @internal */ isoListeners = /* @__PURE__ */ new Map();
@@ -152,6 +156,12 @@ var WNode = class extends WEventTarget {
152
156
  /** @internal */ isoNext = null;
153
157
  /** @internal Whether the host knows this node (it's in the tree under the root). */
154
158
  isoKnown = false;
159
+ /**
160
+ * @internal The root this node was rendered under, once it has been. Kept
161
+ * after the node leaves the tree, so it can't move to another member's root
162
+ * in a pool (ADR 0015, decision 3).
163
+ */
164
+ isoOwner = null;
155
165
  constructor(doc, id) {
156
166
  super();
157
167
  this.ownerDocument = doc;
@@ -160,10 +170,17 @@ var WNode = class extends WEventTarget {
160
170
  /** @internal */ isoParentTarget() {
161
171
  return this.isoParent;
162
172
  }
173
+ /**
174
+ * @internal The id the host knows this node by: a render root is always
175
+ * `ROOT_ID` to its own surface, whatever its id in the document.
176
+ */
177
+ get isoWire() {
178
+ return this.isoOwner?.root === this ? 0 : this.isoId;
179
+ }
163
180
  /** @internal */ isoListenChanged(type, on) {
164
- if (this.isoKnown) this.ownerDocument.isoCore.record([
181
+ if (this.isoKnown) emit(this, [
165
182
  "listen",
166
- this.isoId,
183
+ this.isoWire,
167
184
  type,
168
185
  on
169
186
  ]);
@@ -217,9 +234,9 @@ var WCharacterData = class extends WNode {
217
234
  const data = str(v);
218
235
  if (data === this.isoData) return;
219
236
  this.isoData = data;
220
- if (this.isoKnown) this.ownerDocument.isoCore.record([
237
+ if (this.isoKnown) emit(this, [
221
238
  "text",
222
- this.isoId,
239
+ this.isoWire,
223
240
  data
224
241
  ]);
225
242
  }
@@ -443,27 +460,28 @@ var WParentNode = class extends WNode {
443
460
  return child;
444
461
  }
445
462
  if (this.ownerDocument.head === this && child instanceof WElement) this.ownerDocument.isoCore.onHead(child.localName);
463
+ if (this.isoKnown && ownedElsewhere(child, this.isoOwner)) throw domError("HierarchyRequestError", "insertBefore: a node can't move to another member's root in a pool");
446
464
  const wasKnown = child.isoKnown;
447
465
  child.isoParent?.isoUnlink(child);
448
466
  this.isoLink(child, ref);
449
467
  const core = this.ownerDocument.isoCore;
450
- if (wasKnown && this.isoKnown) core.record([
468
+ if (wasKnown && this.isoKnown) emit(this, [
451
469
  "move",
452
- this.isoId,
470
+ this.isoWire,
453
471
  child.isoId,
454
472
  ref?.isoId ?? null
455
473
  ]);
456
474
  else if (wasKnown) {
457
- core.record(["remove", child.isoId]);
475
+ emit(child, ["remove", child.isoId]);
458
476
  forget(child, core);
459
477
  } else if (this.isoKnown) {
460
- core.record([
478
+ emit(this, [
461
479
  "insert",
462
- this.isoId,
480
+ this.isoWire,
463
481
  serialize(child),
464
482
  ref?.isoId ?? null
465
483
  ]);
466
- learn(child, core);
484
+ learn(child, core, this.isoOwner);
467
485
  }
468
486
  return child;
469
487
  }
@@ -471,9 +489,8 @@ var WParentNode = class extends WNode {
471
489
  if (child.isoParent !== this) throw domError("NotFoundError", "removeChild: not a child");
472
490
  this.isoUnlink(child);
473
491
  if (child.isoKnown) {
474
- const core = this.ownerDocument.isoCore;
475
- core.record(["remove", child.isoId]);
476
- forget(child, core);
492
+ emit(child, ["remove", child.isoId]);
493
+ forget(child, this.ownerDocument.isoCore);
477
494
  }
478
495
  return child;
479
496
  }
@@ -528,6 +545,11 @@ var WElement = class extends WParentNode {
528
545
  /** @internal */ isoStyle = null;
529
546
  /** @internal */ isoClassList = null;
530
547
  /** @internal */ isoDataset = null;
548
+ /** @internal The offsets the last `scroll` event brought (design §4.6). */
549
+ isoScroll = {
550
+ top: 0,
551
+ left: 0
552
+ };
531
553
  constructor(doc, id, localName, ns) {
532
554
  super(doc, id);
533
555
  this.localName = localName;
@@ -561,9 +583,9 @@ var WElement = class extends WParentNode {
561
583
  const v = str(value);
562
584
  if (this.isoAttrs.get(n) === v) return;
563
585
  this.isoAttrs.set(n, v);
564
- if (this.isoKnown) this.ownerDocument.isoCore.record([
586
+ if (this.isoKnown) emit(this, [
565
587
  "attr",
566
- this.isoId,
588
+ this.isoWire,
567
589
  n,
568
590
  v
569
591
  ]);
@@ -571,9 +593,9 @@ var WElement = class extends WParentNode {
571
593
  removeAttribute(name) {
572
594
  const n = this.isoAttrName(name);
573
595
  if (!this.isoAttrs.delete(n)) return;
574
- if (this.isoKnown) this.ownerDocument.isoCore.record([
596
+ if (this.isoKnown) emit(this, [
575
597
  "attr",
576
- this.isoId,
598
+ this.isoWire,
577
599
  n,
578
600
  null
579
601
  ]);
@@ -594,6 +616,16 @@ var WElement = class extends WParentNode {
594
616
  this.isoDataset ??= createDataset(this);
595
617
  return this.isoDataset;
596
618
  }
619
+ /**
620
+ * Read only, and as of the last `scroll` event the element got: the host
621
+ * owns scrolling. 0 until the element is scrolled and listens for `scroll`.
622
+ */
623
+ get scrollTop() {
624
+ return this.isoScroll.top;
625
+ }
626
+ get scrollLeft() {
627
+ return this.isoScroll.left;
628
+ }
597
629
  get id() {
598
630
  return this.getAttribute("id") ?? "";
599
631
  }
@@ -603,9 +635,9 @@ var WElement = class extends WParentNode {
603
635
  /** @internal */ isoSetProp(name, value, record) {
604
636
  if (this.isoProps.get(name) === value) return;
605
637
  this.isoProps.set(name, value);
606
- if (record && this.isoKnown) this.ownerDocument.isoCore.record([
638
+ if (record && this.isoKnown) emit(this, [
607
639
  "prop",
608
- this.isoId,
640
+ this.isoWire,
609
641
  name,
610
642
  value
611
643
  ]);
@@ -892,8 +924,11 @@ var WDocument = class extends WEventTarget {
892
924
  }
893
925
  return null;
894
926
  };
895
- const root = this.isoCore.root;
896
- return (root ? walk(root) : null) ?? walk(this.head);
927
+ for (const root of this.isoCore.roots) {
928
+ const hit = walk(root);
929
+ if (hit) return hit;
930
+ }
931
+ return walk(this.head);
897
932
  }
898
933
  /**
899
934
  * Type selectors only, alone or as a `head > title` child chain: what React
@@ -952,78 +987,132 @@ function serialize(n) {
952
987
  children: n.childNodes.map(serialize)
953
988
  };
954
989
  }
955
- function learn(n, core) {
990
+ /** Whether `n` or anything under it was rendered under a root other than `owner`. */
991
+ function ownedElsewhere(n, owner) {
992
+ if (n.isoOwner && n.isoOwner !== owner) return true;
993
+ return !n.isoKnown && n.childNodes.some((c) => ownedElsewhere(c, owner));
994
+ }
995
+ function learn(n, core, owner) {
956
996
  n.isoKnown = true;
997
+ n.isoOwner = owner;
957
998
  core.known.set(n.isoId, n);
958
- for (const c of n.childNodes) learn(c, core);
999
+ for (const c of n.childNodes) learn(c, core, owner);
959
1000
  }
960
1001
  function forget(n, core) {
961
1002
  n.isoKnown = false;
962
1003
  core.known.delete(n.isoId);
963
1004
  for (const c of n.childNodes) forget(c, core);
964
1005
  }
965
- function createDom(opts) {
966
- const schedule = opts.schedule ?? ((fn) => queueMicrotask(fn));
1006
+ const isControl = (node) => node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement;
1007
+ function setValueOf(node, value, o) {
1008
+ if (!isControl(node)) throw new TypeError("setValue: not an input, textarea or select");
1009
+ if (!o.force) {
1010
+ node.value = value;
1011
+ return;
1012
+ }
1013
+ node.isoSetProp("value", value, false);
1014
+ if (node.isoKnown) emit(node, [
1015
+ "prop",
1016
+ node.isoWire,
1017
+ "value",
1018
+ value,
1019
+ true
1020
+ ]);
1021
+ }
1022
+ function deliverTo(node, event) {
1023
+ if (!node) return;
1024
+ if (isControl(node) && event.value !== void 0) node.isoSetProp("value", event.value, false);
1025
+ if (node instanceof WHTMLInputElement && event.checked !== void 0) node.isoSetProp("checked", event.checked, false);
1026
+ if (event.type === "scroll" && node instanceof WElement) node.isoScroll = {
1027
+ top: event.scrollTop ?? 0,
1028
+ left: event.scrollLeft ?? 0
1029
+ };
1030
+ node.dispatchEvent(toEvent(event));
1031
+ }
1032
+ /** A root's recorder: records batched per microtask (or `schedule`) into `onBatch`. */
1033
+ function recorder(root, onBatch, schedule) {
967
1034
  let pending = [];
968
1035
  let scheduled = false;
1036
+ let live = true;
969
1037
  const flush = () => {
970
1038
  scheduled = false;
971
1039
  if (pending.length === 0) return;
972
1040
  const batch = pending;
973
1041
  pending = [];
974
- opts.onBatch(batch);
1042
+ if (live) onBatch(batch);
1043
+ };
1044
+ return {
1045
+ owner: {
1046
+ root,
1047
+ push(r) {
1048
+ if (!live) return;
1049
+ pending.push(r);
1050
+ if (!scheduled) {
1051
+ scheduled = true;
1052
+ schedule(flush);
1053
+ }
1054
+ }
1055
+ },
1056
+ flush,
1057
+ stop: () => {
1058
+ live = false;
1059
+ pending = [];
1060
+ }
975
1061
  };
1062
+ }
1063
+ function createDom(opts) {
1064
+ const schedule = opts.schedule ?? ((fn) => queueMicrotask(fn));
976
1065
  const core = {
977
- root: null,
1066
+ roots: /* @__PURE__ */ new Set(),
978
1067
  nextId: 1,
979
1068
  known: /* @__PURE__ */ new Map(),
980
- onHead: opts.onHead ?? (() => {}),
981
- record(r) {
982
- pending.push(r);
983
- if (!scheduled) {
984
- scheduled = true;
985
- schedule(flush);
986
- }
987
- }
1069
+ onHead: opts.onHead ?? (() => {})
988
1070
  };
989
1071
  const document = new WDocument(core);
990
- const root = new WHTMLElement(document, 0, "iso-root", "html");
991
- root.isoKnown = true;
992
- core.known.set(0, root);
993
- core.root = root;
1072
+ const makeRoot = (id) => {
1073
+ const root = new WHTMLElement(document, id, "iso-root", "html");
1074
+ root.isoKnown = true;
1075
+ core.known.set(id, root);
1076
+ core.roots.add(root);
1077
+ return root;
1078
+ };
1079
+ const root = makeRoot(0);
1080
+ const main = recorder(root, (b) => opts.onBatch(b), schedule);
1081
+ root.isoOwner = main.owner;
994
1082
  return {
995
1083
  document,
996
1084
  root,
997
- flush,
1085
+ flush: main.flush,
998
1086
  idOf: (node) => node.isoId,
999
- setValue(node, value, o = {}) {
1000
- if (!(node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement)) throw new TypeError("setValue: not an input, textarea or select");
1001
- if (!o.force) {
1002
- node.value = value;
1003
- return;
1004
- }
1005
- node.isoSetProp("value", value, false);
1006
- if (node.isoKnown) core.record([
1007
- "prop",
1008
- node.isoId,
1009
- "value",
1010
- value,
1011
- true
1012
- ]);
1013
- },
1014
- deliver(event) {
1015
- const node = core.known.get(event.target);
1016
- if (!node) return;
1017
- if ((node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement) && event.value !== void 0) node.isoSetProp("value", event.value, false);
1018
- if (node instanceof WHTMLInputElement && event.checked !== void 0) node.isoSetProp("checked", event.checked, false);
1019
- node.dispatchEvent(toEvent(event));
1087
+ setValue: (node, value, o = {}) => setValueOf(node, value, o),
1088
+ deliver: (event) => deliverTo(core.known.get(event.target), event),
1089
+ addRoot(o) {
1090
+ const member = makeRoot(core.nextId++);
1091
+ const rec = recorder(member, (b) => o.onBatch(b), o.schedule ?? schedule);
1092
+ member.isoOwner = rec.owner;
1093
+ const mine = (node) => node?.isoKnown && node.isoOwner === rec.owner ? node : void 0;
1094
+ return {
1095
+ root: member,
1096
+ flush: rec.flush,
1097
+ idOf: (node) => mine(node) ? node.isoWire : void 0,
1098
+ setValue(node, value, so = {}) {
1099
+ if (node.isoOwner && node.isoOwner !== rec.owner) throw new TypeError("setValue: not a node of this member's root");
1100
+ setValueOf(node, value, so);
1101
+ },
1102
+ deliver: (event) => deliverTo(mine(event.target === 0 ? member : core.known.get(event.target)), event),
1103
+ dispose() {
1104
+ rec.stop();
1105
+ core.roots.delete(member);
1106
+ forget(member, core);
1107
+ }
1108
+ };
1020
1109
  }
1021
1110
  };
1022
1111
  }
1023
1112
  /** A real `Event` with the fields frameworks read from mouse and keyboard events. */
1024
1113
  function toEvent(e) {
1025
1114
  const ev = new Event(e.type, {
1026
- bubbles: true,
1115
+ bubbles: e.type !== "scroll",
1027
1116
  cancelable: true
1028
1117
  });
1029
1118
  const mods = {
package/dist/host.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ISOLOOP_DOM_FMT, c as ROOT_ID, d as isDomBatch, i as DomRecord, l as SerializedNode, n as DomEvent, o as Namespace, r as DomMods, s as NodeId, t as DomBatch, u as SyncedProp } from "./records-2Jf3U4Sp.js";
1
+ import { a as ISOLOOP_DOM_FMT, c as ROOT_ID, d as isDomBatch, i as DomRecord, l as SerializedNode, n as DomEvent, o as Namespace, r as DomMods, s as NodeId, t as DomBatch, u as SyncedProp } from "./records-OXGckMg9.js";
2
2
  /** Decides what the applier may create and write. Supplied by the host; required. */
3
3
  interface SanitisePolicy {
4
4
  /** The host element to create for an isolate's tag. */
package/dist/host.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import { n as ROOT_ID, r as isDomBatch, t as ISOLOOP_DOM_FMT } from "./records-wVZrPpqr.js";
2
- import { t as createApplier } from "./applier-CkaI6Dw-.js";
2
+ import { t as createApplier } from "./applier-D5wb4gz9.js";
3
3
  export { ISOLOOP_DOM_FMT, ROOT_ID, createApplier, isDomBatch };
@@ -1,4 +1,4 @@
1
- import { _ as WText, a as WDocumentFragment, c as WHTMLElement, d as WHTMLOptionElement, f as WHTMLSelectElement, g as WSVGElement, l as WHTMLIFrameElement, m as WNode, n as WComment, o as WElement, p as WHTMLTextAreaElement, r as WDOMTokenList, u as WHTMLInputElement } from "./dom-9S5T0UVQ.js";
1
+ import { _ as WText, a as WDocumentFragment, c as WHTMLElement, d as WHTMLOptionElement, f as WHTMLSelectElement, g as WSVGElement, l as WHTMLIFrameElement, m as WNode, n as WComment, o as WElement, p as WHTMLTextAreaElement, r as WDOMTokenList, u as WHTMLInputElement } from "./dom-yLsf0Z4e.js";
2
2
  // src/worker/install.ts
3
3
  /** The DOM globals the subset provides (ADR 0010 point 2), by their DOM names. */
4
4
  const DOM_GLOBALS = {
@@ -52,6 +52,9 @@ type DomEvent = {
52
52
  /** For `resize` on a transferred canvas: its new CSS size (design §4.7). */
53
53
  width?: number;
54
54
  height?: number;
55
+ /** For `scroll`: the scrolled element's offsets, mirrored on the worker node. */
56
+ scrollTop?: number;
57
+ scrollLeft?: number;
55
58
  };
56
59
  /** The batch comes from an isolate, so its shape is checked before anything touches the DOM. */
57
60
  declare function isDomBatch(x: unknown): x is DomBatch;
@@ -1,5 +1,5 @@
1
- import { t as DomBatch } from "./records-2Jf3U4Sp.js";
2
- import { s as WorkerDom } from "./dom-BrJVEi7G.js";
1
+ import { t as DomBatch } from "./records-OXGckMg9.js";
2
+ import { l as WorkerDom } from "./dom-Bctskbvg.js";
3
3
  /** One framework major's log, as `packages/dom/usage/<project>.json` stores it. */
4
4
  export type UsageLog = {
5
5
  /** E.g. `preact@10.29.8`. */
@@ -19,6 +19,7 @@ export type UsageTracker = {
19
19
  export type FixtureMessage = {
20
20
  t: "batch";
21
21
  batch: DomBatch;
22
+ member?: number;
22
23
  } | {
23
24
  t: "usage";
24
25
  log: UsageLog;
@@ -26,6 +27,13 @@ export type FixtureMessage = {
26
27
  t: "error";
27
28
  error: string;
28
29
  };
30
+ /**
31
+ * A pooled fixture (ADR 0015, M2d): one subset document installed as this
32
+ * worker's `document`, with `n` render roots, one per member. Each root's
33
+ * batches are posted with its `member` index, and the page's events for a
34
+ * member go to its root. Pair with `mountMembers()` on the page.
35
+ */
36
+ export declare function servePoolFixture(n: number): Element[];
29
37
  /**
30
38
  * Installs the subset as this worker's `document`, posts every batch, and
31
39
  * delivers the page's events. Import it before the framework: React decides
@@ -1,5 +1,5 @@
1
- import { n as install, t as DOM_GLOBALS } from "./install-DBKGtAel.js";
2
- import { h as WParentNode, i as WDocument, o as WElement, s as WEventTarget, t as WCharacterData, v as createDom } from "./dom-9S5T0UVQ.js";
1
+ import { n as install, t as DOM_GLOBALS } from "./install-D7m7By8i.js";
2
+ import { h as WParentNode, i as WDocument, o as WElement, s as WEventTarget, t as WCharacterData, v as createDom } from "./dom-yLsf0Z4e.js";
3
3
  // src/testing/worker.ts
4
4
  /** Everything a framework sees: the classes `install()` exposes, and `document`. */
5
5
  const CLASSES = [
@@ -26,6 +26,40 @@ const fail = (err) => {
26
26
  });
27
27
  };
28
28
  const isEventMessage = (x) => typeof x === "object" && x !== null && Reflect.get(x, "t") === "event";
29
+ const catchErrors = () => {
30
+ addEventListener("error", (e) => {
31
+ e.preventDefault();
32
+ fail(e.error);
33
+ });
34
+ addEventListener("unhandledrejection", (e) => {
35
+ e.preventDefault();
36
+ fail(e.reason);
37
+ });
38
+ };
39
+ /**
40
+ * A pooled fixture (ADR 0015, M2d): one subset document installed as this
41
+ * worker's `document`, with `n` render roots, one per member. Each root's
42
+ * batches are posted with its `member` index, and the page's events for a
43
+ * member go to its root. Pair with `mountMembers()` on the page.
44
+ */
45
+ function servePoolFixture(n) {
46
+ const dom = createDom({ onBatch: () => {} });
47
+ install(dom, self);
48
+ const roots = Array.from({ length: n }, (_, member) => dom.addRoot({ onBatch: (batch) => post({
49
+ t: "batch",
50
+ batch,
51
+ member
52
+ }) }));
53
+ addEventListener("message", (e) => {
54
+ if (isEventMessage(e.data)) roots[e.data.member ?? 0]?.deliver(e.data.event);
55
+ });
56
+ catchErrors();
57
+ return roots.map((r) => {
58
+ const container = r.root;
59
+ if (!(container instanceof Element)) throw new Error("the subset is not installed");
60
+ return container;
61
+ });
62
+ }
29
63
  /**
30
64
  * Installs the subset as this worker's `document`, posts every batch, and
31
65
  * delivers the page's events. Import it before the framework: React decides
@@ -180,4 +214,4 @@ async function reportUsage(tracker, framework, run) {
180
214
  fail(err);
181
215
  }
182
216
  }
183
- export { driveUsageFixture, reportUsage, serveFixture, trackUsage };
217
+ export { driveUsageFixture, reportUsage, serveFixture, servePoolFixture, trackUsage };
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { s as WorkerDom } from "./dom-BrJVEi7G.js";
1
+ import { l as WorkerDom } from "./dom-Bctskbvg.js";
2
2
  import { FixtureMessage, UsageLog } from "./testing-worker.js";
3
3
  /** An event as a host bridge sends it to the isolate, reduced to what the suite reads. */
4
4
  type ConformanceEvent = {
@@ -134,6 +134,12 @@ type FixtureHost = {
134
134
  dispose(): void;
135
135
  };
136
136
  export declare function mountFixture(worker: Worker): FixtureHost;
137
+ /**
138
+ * The page side of `servePoolFixture(n)`: one container per member, each
139
+ * with its own applier, getting only that member's batches and sending its
140
+ * events back for that member (ADR 0015, M2d task 2).
141
+ */
142
+ export declare function mountMembers(worker: Worker, n: number): HTMLElement[];
137
143
  /**
138
144
  * The user actions the smoke tests take on the fixture app (the same ones
139
145
  * `driveUsageFixture` sends as events), for a container either way: the
package/dist/testing.js CHANGED
@@ -1,5 +1,5 @@
1
- import { h as WParentNode, o as WElement, t as WCharacterData, v as createDom } from "./dom-9S5T0UVQ.js";
2
- import { t as createApplier } from "./applier-CkaI6Dw-.js";
1
+ import { h as WParentNode, o as WElement, t as WCharacterData, v as createDom } from "./dom-yLsf0Z4e.js";
2
+ import { t as createApplier } from "./applier-D5wb4gz9.js";
3
3
  import { afterEach, describe, expect, it } from "vitest";
4
4
  import { commands } from "vitest/browser";
5
5
  // src/testing/conformance.ts
@@ -615,6 +615,34 @@ function mountFixture(worker) {
615
615
  }
616
616
  };
617
617
  }
618
+ /**
619
+ * The page side of `servePoolFixture(n)`: one container per member, each
620
+ * with its own applier, getting only that member's batches and sending its
621
+ * events back for that member (ADR 0015, M2d task 2).
622
+ */
623
+ function mountMembers(worker, n) {
624
+ const surfaces = Array.from({ length: n }, (_, member) => {
625
+ const container = document.createElement("div");
626
+ document.body.append(container);
627
+ const applier = createApplier(container, OPEN);
628
+ for (const type of EVENTS) container.addEventListener(type, (e) => {
629
+ const event = applier.eventFor(e);
630
+ if (event) worker.postMessage({
631
+ t: "event",
632
+ event,
633
+ member
634
+ });
635
+ });
636
+ return {
637
+ container,
638
+ applier
639
+ };
640
+ });
641
+ worker.addEventListener("message", (e) => {
642
+ if (isMessage(e.data) && e.data.t === "batch") surfaces[e.data.member ?? 0]?.applier.apply(e.data.batch);
643
+ });
644
+ return surfaces.map((s) => s.container);
645
+ }
618
646
  /** Sets a control's value the way typing does: through the prototype's setter, past React's value tracker. */
619
647
  function setNative(el, value) {
620
648
  const proto = el instanceof HTMLInputElement ? HTMLInputElement.prototype : HTMLSelectElement.prototype;
@@ -668,4 +696,4 @@ function snapshot(root) {
668
696
  select: one(root, "select", HTMLSelectElement).value
669
697
  };
670
698
  }
671
- export { CASES, SMOKE_STEPS, TOLERATED_MISSING, checkDomUsage, createIsoloopDomDriver, mountFixture, runBridgeConformance, snapshot };
699
+ export { CASES, SMOKE_STEPS, TOLERATED_MISSING, checkDomUsage, createIsoloopDomDriver, mountFixture, mountMembers, runBridgeConformance, snapshot };
package/dist/worker.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as ISOLOOP_DOM_FMT, c as ROOT_ID, i as DomRecord, l as SerializedNode, n as DomEvent, o as Namespace, r as DomMods, s as NodeId, t as DomBatch, u as SyncedProp } from "./records-2Jf3U4Sp.js";
2
- import { a as WNode, c as WorkerDomOptions, i as WElement, l as createDom, n as WDocument, o as WText, r as WDocumentFragment, s as WorkerDom, t as WComment } from "./dom-BrJVEi7G.js";
1
+ import { a as ISOLOOP_DOM_FMT, c as ROOT_ID, i as DomRecord, l as SerializedNode, n as DomEvent, o as Namespace, r as DomMods, s as NodeId, t as DomBatch, u as SyncedProp } from "./records-OXGckMg9.js";
2
+ import { a as WDocumentFragment, c as WText, d as createDom, i as WDocument, l as WorkerDom, n as RootOptions, o as WElement, r as WComment, s as WNode, t as RenderRoot, u as WorkerDomOptions } from "./dom-Bctskbvg.js";
3
3
  /** The DOM globals the subset provides (ADR 0010 point 2), by their DOM names. */
4
4
  export declare const DOM_GLOBALS: Readonly<Record<string, unknown>>;
5
5
  /**
@@ -8,4 +8,4 @@ export declare const DOM_GLOBALS: Readonly<Record<string, unknown>>;
8
8
  * headless isolate never calls this.
9
9
  */
10
10
  export declare function install(dom: WorkerDom, scope: object): void;
11
- export { type DomBatch, type DomEvent, type DomMods, type DomRecord, ISOLOOP_DOM_FMT, type Namespace, type NodeId, ROOT_ID, type SerializedNode, type SyncedProp, WComment, WDocument, WDocumentFragment, WElement, WNode, WText, type WorkerDom, type WorkerDomOptions, createDom };
11
+ export { type DomBatch, type DomEvent, type DomMods, type DomRecord, ISOLOOP_DOM_FMT, type Namespace, type NodeId, ROOT_ID, type RenderRoot, type RootOptions, type SerializedNode, type SyncedProp, WComment, WDocument, WDocumentFragment, WElement, WNode, WText, type WorkerDom, type WorkerDomOptions, createDom };
package/dist/worker.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { n as ROOT_ID, t as ISOLOOP_DOM_FMT } from "./records-wVZrPpqr.js";
2
- import { _ as WText, a as WDocumentFragment, i as WDocument, m as WNode, n as WComment, o as WElement, v as createDom } from "./dom-9S5T0UVQ.js";
3
- import { n as install, t as DOM_GLOBALS } from "./install-DBKGtAel.js";
2
+ import { _ as WText, a as WDocumentFragment, i as WDocument, m as WNode, n as WComment, o as WElement, v as createDom } from "./dom-yLsf0Z4e.js";
3
+ import { n as install, t as DOM_GLOBALS } from "./install-D7m7By8i.js";
4
4
  export { DOM_GLOBALS, ISOLOOP_DOM_FMT, ROOT_ID, WComment, WDocument, WDocumentFragment, WElement, WNode, WText, createDom, install };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isoloop/dom",
3
- "version": "0.0.0-next.69da74b",
3
+ "version": "0.0.0-next.d028bc1",
4
4
  "description": "Internal: Isoloop's render bridge (isoloop-dom@1). Used by @isoloop/runtime and @isoloop/host; not for app code.",
5
5
  "license": "MIT",
6
6
  "type": "module",