@isoloop/dom 0.0.0-next.4da23df

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.
@@ -0,0 +1,152 @@
1
+ import { s as WorkerDom } from "./dom-ANUAQHqi.js";
2
+ import { FixtureMessage, UsageLog } from "./testing-worker.js";
3
+ /** An event as a host bridge sends it to the isolate, reduced to what the suite reads. */
4
+ type ConformanceEvent = {
5
+ type: string;
6
+ target: string;
7
+ currentTargets: string[];
8
+ value?: string;
9
+ mods: {
10
+ alt: boolean;
11
+ ctrl: boolean;
12
+ meta: boolean;
13
+ shift: boolean;
14
+ };
15
+ };
16
+ /** The host side of a bridge, as the compositor drives it. */
17
+ interface ConformanceHost {
18
+ mount(root: ShadowRoot, send: (event: ConformanceEvent) => void): void;
19
+ /** Applies one batch. Returns false and changes nothing if the batch is malformed. */
20
+ apply(batch: unknown): boolean;
21
+ unmount(): void;
22
+ }
23
+ /** A node on the isolate side, as the suite sees it. Opaque to the suite. */
24
+ type Handle = {
25
+ readonly __handle: true;
26
+ };
27
+ /**
28
+ * The isolate side of a bridge, reduced to the DOM operations the suite needs.
29
+ * Each bridge provides its own; the isoloop-dom driver calls the worker-side
30
+ * DOM subset.
31
+ */
32
+ interface IsolateDriver {
33
+ /** An element with `class="cf-root"` that the suite builds under. Already inserted. */
34
+ readonly root: Handle;
35
+ el(tag: string): Handle;
36
+ text(data: string): Handle;
37
+ /** `document.createComment(data)`. */
38
+ comment(data: string): Handle;
39
+ /** `document.createDocumentFragment()`; `insert` takes it as a parent or a child. */
40
+ fragment(): Handle;
41
+ /** How many children `parent` has, on the isolate side. */
42
+ childCount(parent: Handle): number;
43
+ /** Inserts `child` into `parent` before `before`, or at the end. Moves it if it's already in the tree. */
44
+ insert(parent: Handle, child: Handle, before?: Handle | null): void;
45
+ remove(child: Handle): void;
46
+ /** `null` removes the attribute. */
47
+ setAttr(el: Handle, name: string, value: string | null): void;
48
+ setText(text: Handle, data: string): void;
49
+ /** Sets the `value` property, as a framework does on a controlled input; `force` overrides a focused host input. */
50
+ setValue(el: Handle, value: string, force?: boolean): void;
51
+ listen(el: Handle, type: string): void;
52
+ /** `el.classList`: `add`, `remove`, `toggle` (with `force`) or `contains`; returns whether `el` has the token after. */
53
+ classList(el: Handle, op: "add" | "remove" | "toggle" | "contains", token: string, force?: boolean): boolean;
54
+ /** `el.dataset[key] = value`, or `delete el.dataset[key]` for `null`; returns `el.dataset[key]` after. */
55
+ dataset(el: Handle, key: string, value?: string | null): string | undefined;
56
+ /** `document.getElementById(id)`. */
57
+ byId(id: string): Handle | null;
58
+ /** `a.contains(b)`. */
59
+ contains(a: Handle, b: Handle | null): boolean;
60
+ /** The batches produced since the last flush, in order. */
61
+ flush(): unknown[];
62
+ /** The node id the isolate side uses for `h`, for bridges that expose ids. */
63
+ idOf(h: Handle): string;
64
+ /** The handle an event's `target` or `currentTargets` entry names. */
65
+ handleFor(nodeId: string): Handle | undefined;
66
+ }
67
+ /** Host-side node-id lookups (design §4.5). Optional until every bridge has them. */
68
+ interface NodeIds {
69
+ idFor(node: Node): string | undefined;
70
+ nodeFor(id: string): Element | undefined;
71
+ }
72
+ interface BridgePair {
73
+ host: ConformanceHost & Partial<NodeIds>;
74
+ isolate: IsolateDriver;
75
+ /** Attributes the bridge writes for its own bookkeeping, left out when trees are compared. */
76
+ internalAttr?: (name: string) => boolean;
77
+ }
78
+ type MakeBridgePair = () => BridgePair;
79
+ /** Cases a bridge may declare as known gaps; they run as expected failures. */
80
+ export declare const CASES: {
81
+ readonly create: "creates elements, attributes and text";
82
+ readonly update: "updates attributes and text, and removes attributes";
83
+ readonly move: "moves a node";
84
+ readonly remove: "removes nodes";
85
+ readonly keyed: "keyed list reorders keep node identity and focus";
86
+ readonly sanitise: "sanitises tags, attributes and URLs (I9)";
87
+ readonly ids: "maps node ids both ways";
88
+ readonly events: "registers listeners and round-trips events";
89
+ readonly noListener: "sends nothing for a node without a listener";
90
+ readonly inputs: "host-owned inputs keep the live value while focused";
91
+ readonly styles: "applies inline styles";
92
+ readonly malformed: "rejects a malformed batch and keeps the tree";
93
+ readonly classList: "classList reads and writes the class attribute";
94
+ readonly dataset: "dataset reads and writes data-* attributes";
95
+ readonly getElementById: "getElementById finds rendered elements by id";
96
+ readonly contains: "contains walks the isolate tree";
97
+ readonly fragment: "inserting a fragment inserts its children in order and empties it";
98
+ readonly comment: "comment nodes round-trip, and their data updates";
99
+ readonly forced: "a forced value replaces a focused input’s value, caret at the end";
100
+ };
101
+ type CaseName = keyof typeof CASES;
102
+ /**
103
+ * The suite every render bridge must pass, with no known gaps for the
104
+ * isoloop-dom bridge. Known gaps can be marked per bridge. Batches go through
105
+ * `structuredClone`, as they would through `postMessage`.
106
+ */
107
+ export declare function runBridgeConformance(name: string, makePair: MakeBridgePair, opts?: {
108
+ knownGaps?: readonly CaseName[];
109
+ }): void;
110
+ /**
111
+ * The isolate side of isoloop-dom for the conformance suite: the real
112
+ * worker-side subset, run in the test page without installing globals.
113
+ * Batches are collected and handed over on `flush()`.
114
+ */
115
+ export declare function createIsoloopDomDriver(): IsolateDriver & {
116
+ dom: WorkerDom;
117
+ };
118
+ /**
119
+ * Reads the subset doesn't serve, each with why that's fine. A read of an
120
+ * absent member returns `undefined`, which these call sites handle.
121
+ */
122
+ export declare const TOLERATED_MISSING: Readonly<Record<string, string>>;
123
+ export declare function checkDomUsage(worker: Worker, logPath: string, write: boolean): Promise<UsageLog>;
124
+ type FixtureHost = {
125
+ /** What the worker rendered, under a `<div>` in the document. */
126
+ readonly container: HTMLElement;
127
+ /**
128
+ * Resolves once the worker has rendered and no batch has arrived for
129
+ * `quietMs` (default 30). Rejects if the worker failed, or rendered nothing
130
+ * within 5 s.
131
+ */
132
+ settled(quietMs?: number): Promise<void>;
133
+ /** Terminates the worker and removes the container. */
134
+ dispose(): void;
135
+ };
136
+ export declare function mountFixture(worker: Worker): FixtureHost;
137
+ /**
138
+ * The user actions the smoke tests take on the fixture app (the same ones
139
+ * `driveUsageFixture` sends as events), for a container either way: the
140
+ * fixture host's or a real-DOM render's.
141
+ */
142
+ export declare const SMOKE_STEPS: readonly {
143
+ name: string;
144
+ act(root: Element): void;
145
+ }[];
146
+ /** What the smoke tests compare: the markup, and the controls' live values. */
147
+ export declare function snapshot(root: Element): {
148
+ html: string;
149
+ input: string;
150
+ select: string;
151
+ };
152
+ export type { BridgePair, CaseName, ConformanceEvent, ConformanceHost, FixtureHost, FixtureMessage, Handle, IsolateDriver, MakeBridgePair, NodeIds, UsageLog };