octane 0.2.11 → 0.2.13
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/README.md +5 -0
- package/dist/behavior-root.d.ts +13 -3
- package/dist/behavior-root.js +28 -5
- package/dist/cjs/behavior-root.cjs +32 -6
- package/dist/cjs/class-names.cjs +49 -0
- package/dist/cjs/constants.cjs +9 -0
- package/dist/cjs/context-epoch.cjs +38 -0
- package/dist/cjs/css.cjs +6 -27
- package/dist/cjs/data-encoding.cjs +160 -0
- package/dist/cjs/dom-binding-handoff.cjs +93 -0
- package/dist/cjs/dom-binding-protocol.cjs +115 -0
- package/dist/cjs/dom-binding-styles.cjs +292 -0
- package/dist/cjs/dom-bindings.cjs +700 -0
- package/dist/cjs/dom-focused-move.cjs +66 -0
- package/dist/cjs/dom-stage.cjs +896 -0
- package/dist/cjs/dom-tables.cjs +4 -94
- package/dist/cjs/error-codes.client.generated.cjs +33 -0
- package/dist/cjs/error-codes.server.generated.cjs +24 -0
- package/dist/cjs/hydration/control-capture.cjs +244 -0
- package/dist/cjs/hydration/event-capture.cjs +125 -43
- package/dist/cjs/hydration/interaction-config.cjs +50 -2
- package/dist/cjs/hydration-markers.cjs +37 -0
- package/dist/cjs/independent-hydration-protocol.cjs +106 -0
- package/dist/cjs/index.cjs +9 -0
- package/dist/cjs/runtime.cjs +6397 -1683
- package/dist/cjs/runtime.server.cjs +1465 -213
- package/dist/cjs/server/early-signals.cjs +45 -0
- package/dist/cjs/server/index.cjs +47 -0
- package/dist/cjs/server/rpc-batch.cjs +149 -0
- package/dist/cjs/server/rpc-stream.cjs +146 -0
- package/dist/cjs/server/rpc.cjs +34 -15
- package/dist/cjs/server/signal-query-observation.cjs +158 -0
- package/dist/cjs/server/streamed-region.cjs +52 -0
- package/dist/cjs/server/streamed-signals.cjs +512 -0
- package/dist/cjs/server-call.cjs +103 -0
- package/dist/cjs/server-rpc-batch-client.cjs +141 -0
- package/dist/cjs/server-rpc-client.cjs +94 -27
- package/dist/cjs/server-rpc-protocol.cjs +141 -0
- package/dist/cjs/server-rpc-stream-client.cjs +118 -0
- package/dist/cjs/signals/actions.cjs +474 -0
- package/dist/cjs/signals/client.cjs +4 -1
- package/dist/cjs/signals/computations.cjs +460 -0
- package/dist/cjs/signals/control-binding.cjs +368 -0
- package/dist/cjs/signals/derived-facade.cjs +50 -0
- package/dist/cjs/signals/document-owner.cjs +71 -0
- package/dist/cjs/signals/early-values.cjs +155 -0
- package/dist/cjs/signals/encoding.cjs +6 -95
- package/dist/cjs/signals/engine.cjs +276 -12
- package/dist/cjs/signals/errors.cjs +18 -0
- package/dist/cjs/signals/facade.cjs +477 -0
- package/dist/cjs/signals/graph.cjs +166 -20
- package/dist/cjs/signals/handle-protocol.cjs +36 -0
- package/dist/cjs/signals/index.cjs +81 -2
- package/dist/cjs/signals/native-read-client.cjs +10 -0
- package/dist/cjs/signals/owner-context.cjs +112 -0
- package/dist/cjs/signals/query-attempt-observer.cjs +68 -0
- package/dist/cjs/signals/query-facade.cjs +72 -0
- package/dist/cjs/signals/read-protocol.cjs +54 -0
- package/dist/cjs/signals/requests.cjs +287 -14
- package/dist/cjs/signals/scalar-computations.cjs +76 -0
- package/dist/cjs/signals/server.cjs +4 -1
- package/dist/cjs/signals/transition-candidate.cjs +567 -0
- package/dist/cjs/signals/transition-state.cjs +106 -0
- package/dist/cjs/signals/types.cjs +50 -0
- package/dist/cjs/stream-protocol.cjs +3 -0
- package/dist/cjs/streamed-signals-protocol.cjs +159 -0
- package/dist/cjs/style-values.cjs +122 -0
- package/dist/cjs/trusted-html.cjs +30 -0
- package/dist/cjs/version.cjs +1 -1
- package/dist/class-names.d.ts +5 -0
- package/dist/class-names.js +25 -0
- package/dist/compiler/bundler.js +51 -22
- package/dist/compiler/compile.js +2534 -581
- package/dist/compiler/dom-binding-program.js +935 -0
- package/dist/compiler/dom-binding-request.js +57 -0
- package/dist/compiler/dom-bindings.js +2245 -0
- package/dist/compiler/hook-deps.js +759 -10
- package/dist/compiler/hydrate-boundaries.js +358 -15
- package/dist/compiler/index.d.ts +39 -2
- package/dist/compiler/index.js +1 -0
- package/dist/compiler/native-attribute-reads.js +127 -0
- package/dist/compiler/native-change-diagnostics.js +32 -38
- package/dist/compiler/native-read-diagnostics.js +69 -8
- package/dist/compiler/native-read-types.js +80 -34
- package/dist/compiler/parser.node.js +1 -1
- package/dist/compiler/renderer-boundaries.js +40 -0
- package/dist/compiler/server-context.js +118 -0
- package/dist/compiler/signal-attempt-reads.js +479 -0
- package/dist/compiler/signal-declarations.js +557 -0
- package/dist/compiler/signal-start-reads.js +413 -0
- package/dist/compiler/slot-hooks.d.ts +3 -1
- package/dist/compiler/slot-hooks.js +168 -34
- package/dist/compiler/strong-auto-memo.js +90 -0
- package/dist/compiler/strong-html.js +143 -0
- package/dist/compiler/strong-mode.js +764 -66
- package/dist/compiler/strong-template-policy.js +307 -0
- package/dist/compiler/template-ir.js +200 -0
- package/dist/compiler/typescript.d.ts +2 -0
- package/dist/compiler/typescript.js +2 -0
- package/dist/compiler/vite.d.ts +3 -1
- package/dist/compiler/vite.js +122 -4
- package/dist/compiler/volar.LICENSES.txt +1 -1
- package/dist/compiler/volar.d.ts +6 -1
- package/dist/compiler/volar.js +750 -1433
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +10 -0
- package/dist/context-epoch.d.ts +2 -0
- package/dist/context-epoch.js +13 -0
- package/dist/css.d.ts +2 -5
- package/dist/css.js +2 -23
- package/dist/data-encoding.d.ts +9 -0
- package/dist/data-encoding.js +134 -0
- package/dist/dom-binding-classes.d.ts +15 -0
- package/dist/dom-binding-classes.js +129 -0
- package/dist/dom-binding-controls.d.ts +2 -0
- package/dist/dom-binding-controls.js +6 -0
- package/dist/dom-binding-handoff.d.ts +55 -0
- package/dist/dom-binding-handoff.js +62 -0
- package/dist/dom-binding-program.d.ts +300 -0
- package/dist/dom-binding-program.js +1625 -0
- package/dist/dom-binding-projections.d.ts +15 -0
- package/dist/dom-binding-projections.js +187 -0
- package/dist/dom-binding-protocol.d.ts +13 -0
- package/dist/dom-binding-protocol.js +88 -0
- package/dist/dom-binding-signals.d.ts +21 -0
- package/dist/dom-binding-signals.js +109 -0
- package/dist/dom-binding-styles.d.ts +17 -0
- package/dist/dom-binding-styles.js +272 -0
- package/dist/dom-bindings.d.ts +89 -0
- package/dist/dom-bindings.js +670 -0
- package/dist/dom-focused-move.d.ts +6 -0
- package/dist/dom-focused-move.js +42 -0
- package/dist/dom-stage.d.ts +52 -0
- package/dist/dom-stage.js +872 -0
- package/dist/dom-tables.d.ts +1 -3
- package/dist/dom-tables.js +1 -91
- package/dist/error-codes.client.generated.d.ts +9 -0
- package/dist/error-codes.client.generated.js +33 -0
- package/dist/error-codes.server.generated.d.ts +6 -0
- package/dist/error-codes.server.generated.js +24 -0
- package/dist/hydration/control-capture.d.ts +62 -0
- package/dist/hydration/control-capture.js +223 -0
- package/dist/hydration/document-lifecycle.d.ts +23 -0
- package/dist/hydration/document-lifecycle.js +80 -0
- package/dist/hydration/event-capture.d.ts +20 -1
- package/dist/hydration/event-capture.js +128 -42
- package/dist/hydration/independent-island.d.ts +45 -0
- package/dist/hydration/independent-island.js +233 -0
- package/dist/hydration/index.d.ts +8 -1
- package/dist/hydration/index.js +55 -1
- package/dist/hydration/interaction-config.d.ts +5 -0
- package/dist/hydration/interaction-config.js +44 -1
- package/dist/hydration/stream-delivery.d.ts +32 -0
- package/dist/hydration/stream-delivery.js +333 -0
- package/dist/hydration/stream-receiver.d.ts +26 -0
- package/dist/hydration/stream-receiver.js +204 -0
- package/dist/hydration/stream-result-receiver.d.ts +70 -0
- package/dist/hydration/stream-result-receiver.js +246 -0
- package/dist/hydration/streamed-signals.d.ts +44 -0
- package/dist/hydration/streamed-signals.js +186 -0
- package/dist/hydration/types.d.ts +6 -0
- package/dist/hydration-markers.d.ts +7 -0
- package/dist/hydration-markers.js +10 -0
- package/dist/independent-hydration-protocol.d.ts +31 -0
- package/dist/independent-hydration-protocol.js +80 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/internal/signal-read.d.ts +1 -0
- package/dist/internal/signal-read.js +4 -0
- package/dist/jsx-runtime-strong.d.ts +33 -0
- package/dist/jsx-runtime.d.ts +58 -2
- package/dist/public-types.d.ts +15 -1
- package/dist/runtime.d.ts +297 -23
- package/dist/runtime.js +6405 -1679
- package/dist/runtime.server.d.ts +110 -27
- package/dist/runtime.server.js +1458 -213
- package/dist/server/early-signals.d.ts +14 -0
- package/dist/server/early-signals.js +34 -0
- package/dist/server/index.d.ts +11 -2
- package/dist/server/index.js +50 -1
- package/dist/server/rpc-batch.d.ts +17 -0
- package/dist/server/rpc-batch.js +129 -0
- package/dist/server/rpc-stream.d.ts +9 -0
- package/dist/server/rpc-stream.js +125 -0
- package/dist/server/rpc.d.ts +5 -1
- package/dist/server/rpc.js +37 -13
- package/dist/server/signal-query-observation.d.ts +3 -0
- package/dist/server/signal-query-observation.js +134 -0
- package/dist/server/streamed-region.d.ts +15 -0
- package/dist/server/streamed-region.js +30 -0
- package/dist/server/streamed-signals.d.ts +45 -0
- package/dist/server/streamed-signals.js +488 -0
- package/dist/server-call.d.ts +41 -0
- package/dist/server-call.js +75 -0
- package/dist/server-rpc-batch-client.d.ts +7 -0
- package/dist/server-rpc-batch-client.js +119 -0
- package/dist/server-rpc-client.d.ts +3 -1
- package/dist/server-rpc-client.js +99 -27
- package/dist/server-rpc-protocol.d.ts +47 -0
- package/dist/server-rpc-protocol.js +109 -0
- package/dist/server-rpc-stream-client.d.ts +5 -0
- package/dist/server-rpc-stream-client.js +98 -0
- package/dist/signals/actions.d.ts +12 -0
- package/dist/signals/actions.js +466 -0
- package/dist/signals/client.d.ts +2 -0
- package/dist/signals/client.js +1 -0
- package/dist/signals/computations.d.ts +37 -0
- package/dist/signals/computations.js +455 -0
- package/dist/signals/control-binding.d.ts +31 -0
- package/dist/signals/control-binding.js +353 -0
- package/dist/signals/derived-facade.d.ts +3 -0
- package/dist/signals/derived-facade.js +25 -0
- package/dist/signals/document-owner.d.ts +10 -0
- package/dist/signals/document-owner.js +43 -0
- package/dist/signals/early-values.d.ts +24 -0
- package/dist/signals/early-values.js +124 -0
- package/dist/signals/encoding.d.ts +1 -3
- package/dist/signals/encoding.js +3 -93
- package/dist/signals/engine.d.ts +53 -4
- package/dist/signals/engine.js +275 -16
- package/dist/signals/errors.d.ts +7 -0
- package/dist/signals/errors.js +16 -0
- package/dist/signals/facade.d.ts +74 -0
- package/dist/signals/facade.js +452 -0
- package/dist/signals/graph.d.ts +52 -6
- package/dist/signals/graph.js +174 -19
- package/dist/signals/handle-protocol.d.ts +4 -0
- package/dist/signals/handle-protocol.js +11 -0
- package/dist/signals/index.d.ts +12 -3
- package/dist/signals/index.js +71 -2
- package/dist/signals/native-read-client.d.ts +3 -0
- package/dist/signals/native-read-client.js +10 -0
- package/dist/signals/owner-context.d.ts +22 -0
- package/dist/signals/owner-context.js +77 -0
- package/dist/signals/query-attempt-observer.d.ts +49 -0
- package/dist/signals/query-attempt-observer.js +41 -0
- package/dist/signals/query-facade.d.ts +3 -0
- package/dist/signals/query-facade.js +49 -0
- package/dist/signals/read-protocol.d.ts +37 -2
- package/dist/signals/read-protocol.js +44 -0
- package/dist/signals/requests.d.ts +38 -5
- package/dist/signals/requests.js +298 -15
- package/dist/signals/scalar-computations.d.ts +2 -0
- package/dist/signals/scalar-computations.js +60 -0
- package/dist/signals/server.d.ts +2 -0
- package/dist/signals/server.js +1 -0
- package/dist/signals/transition-candidate.d.ts +71 -0
- package/dist/signals/transition-candidate.js +557 -0
- package/dist/signals/transition-state.d.ts +51 -0
- package/dist/signals/transition-state.js +70 -0
- package/dist/signals/types.d.ts +95 -5
- package/dist/signals/types.js +20 -0
- package/dist/stream-protocol.d.ts +0 -5
- package/dist/stream-protocol.js +3 -0
- package/dist/streamed-signals-protocol.d.ts +60 -0
- package/dist/streamed-signals-protocol.js +130 -0
- package/dist/style-values.d.ts +3 -0
- package/dist/style-values.js +96 -0
- package/dist/trusted-html.d.ts +17 -0
- package/dist/trusted-html.js +6 -0
- package/dist/universal-core.d.ts +6 -0
- package/dist/universal-core.js +214 -202
- package/dist/version.js +1 -1
- package/package.json +48 -5
|
@@ -0,0 +1,872 @@
|
|
|
1
|
+
const EAGER_METADATA = /* @__PURE__ */ new Set([
|
|
2
|
+
// reconcileDeoptChildren: renderer keys used while planning retained hosts.
|
|
3
|
+
"$$deoptKey",
|
|
4
|
+
// renderPortalState: fixed end marker on a newly created portal start marker.
|
|
5
|
+
"$$portalEnd",
|
|
6
|
+
// attr: listener identity ledger; actual native registrations are staged.
|
|
7
|
+
"$$ceListeners",
|
|
8
|
+
// setAutoFocus: one-time mount ownership; focusing uses the commit queue.
|
|
9
|
+
"$$afSeen",
|
|
10
|
+
// setFormAction: one-time submit driver installation, shared across renders.
|
|
11
|
+
"$$formSubmitWired",
|
|
12
|
+
// maybeEnqueueRestore: native input/change event sequence state.
|
|
13
|
+
"$$checkableActivation",
|
|
14
|
+
"$$selectPick",
|
|
15
|
+
// handleFormSubmit/publishManualFormPending: native submit lifetime counter.
|
|
16
|
+
"$$pendingSubmits"
|
|
17
|
+
]);
|
|
18
|
+
const PROJECTED_PROPERTIES = /* @__PURE__ */ new Set([
|
|
19
|
+
"id",
|
|
20
|
+
"className",
|
|
21
|
+
"slot",
|
|
22
|
+
"title",
|
|
23
|
+
"lang",
|
|
24
|
+
"dir",
|
|
25
|
+
"hidden",
|
|
26
|
+
"inert",
|
|
27
|
+
"tabIndex",
|
|
28
|
+
"accessKey",
|
|
29
|
+
"draggable",
|
|
30
|
+
"contentEditable",
|
|
31
|
+
"spellcheck",
|
|
32
|
+
"translate",
|
|
33
|
+
"role",
|
|
34
|
+
"name",
|
|
35
|
+
"type",
|
|
36
|
+
"value",
|
|
37
|
+
"defaultValue",
|
|
38
|
+
"checked",
|
|
39
|
+
"defaultChecked",
|
|
40
|
+
"selected",
|
|
41
|
+
"defaultSelected",
|
|
42
|
+
"disabled",
|
|
43
|
+
"multiple",
|
|
44
|
+
"readOnly",
|
|
45
|
+
"required",
|
|
46
|
+
"autofocus",
|
|
47
|
+
"placeholder",
|
|
48
|
+
"min",
|
|
49
|
+
"max",
|
|
50
|
+
"step",
|
|
51
|
+
"pattern",
|
|
52
|
+
"minLength",
|
|
53
|
+
"maxLength",
|
|
54
|
+
"size",
|
|
55
|
+
"rows",
|
|
56
|
+
"cols",
|
|
57
|
+
"accept",
|
|
58
|
+
"action",
|
|
59
|
+
"method",
|
|
60
|
+
"enctype",
|
|
61
|
+
"target",
|
|
62
|
+
"noValidate",
|
|
63
|
+
"href",
|
|
64
|
+
"src",
|
|
65
|
+
"srcset",
|
|
66
|
+
"sizes",
|
|
67
|
+
"alt",
|
|
68
|
+
"width",
|
|
69
|
+
"height",
|
|
70
|
+
"loading",
|
|
71
|
+
"decoding",
|
|
72
|
+
"crossOrigin",
|
|
73
|
+
"referrerPolicy",
|
|
74
|
+
"htmlFor",
|
|
75
|
+
"open",
|
|
76
|
+
"controls",
|
|
77
|
+
"muted",
|
|
78
|
+
"loop"
|
|
79
|
+
]);
|
|
80
|
+
class DOMStage {
|
|
81
|
+
constructor(captureGuard) {
|
|
82
|
+
this.captureGuard = captureGuard;
|
|
83
|
+
}
|
|
84
|
+
captureGuard;
|
|
85
|
+
views = /* @__PURE__ */ new Map();
|
|
86
|
+
children = /* @__PURE__ */ new Map();
|
|
87
|
+
links = /* @__PURE__ */ new Map();
|
|
88
|
+
projections = /* @__PURE__ */ new Map();
|
|
89
|
+
parents = /* @__PURE__ */ new Map();
|
|
90
|
+
values = /* @__PURE__ */ new Map();
|
|
91
|
+
states = /* @__PURE__ */ new Map();
|
|
92
|
+
styles = /* @__PURE__ */ new Map();
|
|
93
|
+
documents = /* @__PURE__ */ new Map();
|
|
94
|
+
fresh = /* @__PURE__ */ new Set();
|
|
95
|
+
actions = [];
|
|
96
|
+
ended = false;
|
|
97
|
+
/** Mark an actual creation/clone result, never an arbitrary detached node. */
|
|
98
|
+
created(node) {
|
|
99
|
+
this.fresh.add(node);
|
|
100
|
+
const templates = (root) => {
|
|
101
|
+
if (root.nodeType !== 1 && root.nodeType !== 11) return;
|
|
102
|
+
const mark = (template) => {
|
|
103
|
+
if (template.content === void 0) return;
|
|
104
|
+
this.fresh.add(template.content);
|
|
105
|
+
templates(template.content);
|
|
106
|
+
};
|
|
107
|
+
if (root.nodeType === 1 && root.localName === "template")
|
|
108
|
+
mark(root);
|
|
109
|
+
for (const template of root.querySelectorAll("template"))
|
|
110
|
+
mark(template);
|
|
111
|
+
};
|
|
112
|
+
templates(node);
|
|
113
|
+
return node;
|
|
114
|
+
}
|
|
115
|
+
view(node) {
|
|
116
|
+
if (this.ended || node === null || typeof node !== "object" || typeof node.nodeType !== "number" || !("ownerDocument" in node))
|
|
117
|
+
return node;
|
|
118
|
+
let view = this.views.get(node);
|
|
119
|
+
if (view === void 0) {
|
|
120
|
+
view = new Proxy(node, {
|
|
121
|
+
get: (_, key) => this.get(node, key),
|
|
122
|
+
set: (_, key, value) => {
|
|
123
|
+
this.set(node, key, value);
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
this.views.set(node, view);
|
|
128
|
+
}
|
|
129
|
+
return view;
|
|
130
|
+
}
|
|
131
|
+
/** Lifecycle work is interleaved with host writes, especially before removal. */
|
|
132
|
+
enqueue(action, durable = false) {
|
|
133
|
+
if (this.ended) throw new Error("Cannot append to a completed DOM commit.");
|
|
134
|
+
this.actions.push({ action, guard: durable ? void 0 : this.captureGuard?.() });
|
|
135
|
+
}
|
|
136
|
+
commit() {
|
|
137
|
+
if (this.ended) return;
|
|
138
|
+
this.ended = true;
|
|
139
|
+
const actions = this.actions;
|
|
140
|
+
this.release();
|
|
141
|
+
let failed = false;
|
|
142
|
+
let firstError;
|
|
143
|
+
for (const { action, guard } of actions) {
|
|
144
|
+
try {
|
|
145
|
+
if (guard === void 0 || guard()) action();
|
|
146
|
+
} catch (error) {
|
|
147
|
+
if (!failed) {
|
|
148
|
+
failed = true;
|
|
149
|
+
firstError = error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (failed) throw firstError;
|
|
154
|
+
}
|
|
155
|
+
release() {
|
|
156
|
+
this.actions = [];
|
|
157
|
+
this.views.clear();
|
|
158
|
+
this.children.clear();
|
|
159
|
+
this.links.clear();
|
|
160
|
+
this.projections.clear();
|
|
161
|
+
this.parents.clear();
|
|
162
|
+
this.values.clear();
|
|
163
|
+
this.states.clear();
|
|
164
|
+
this.styles.clear();
|
|
165
|
+
this.documents.clear();
|
|
166
|
+
this.fresh.clear();
|
|
167
|
+
}
|
|
168
|
+
isFresh(node) {
|
|
169
|
+
for (let current = node; current !== null; current = current.parentNode) {
|
|
170
|
+
if (this.fresh.has(current)) return true;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
childList(node) {
|
|
175
|
+
let list = this.children.get(node);
|
|
176
|
+
if (list !== void 0) return list;
|
|
177
|
+
list = { first: node.firstChild, last: node.lastChild, length: 0, snapshot: null };
|
|
178
|
+
let previous = null;
|
|
179
|
+
for (let child = node.firstChild; child !== null; child = child.nextSibling) {
|
|
180
|
+
this.links.set(child, { previous, next: child.nextSibling });
|
|
181
|
+
previous = child;
|
|
182
|
+
list.length++;
|
|
183
|
+
}
|
|
184
|
+
this.children.set(node, list);
|
|
185
|
+
return list;
|
|
186
|
+
}
|
|
187
|
+
childNodes(node) {
|
|
188
|
+
const list = this.children.get(node);
|
|
189
|
+
if (list === void 0) return Array.from(node.childNodes);
|
|
190
|
+
if (list.snapshot !== null) return list.snapshot;
|
|
191
|
+
const result = [];
|
|
192
|
+
for (let child = list.first; child !== null; child = this.links.get(child).next)
|
|
193
|
+
result.push(child);
|
|
194
|
+
return list.snapshot = result;
|
|
195
|
+
}
|
|
196
|
+
child(node, key) {
|
|
197
|
+
const list = this.children.get(node);
|
|
198
|
+
return list === void 0 ? node[key] : key === "firstChild" ? list.first : list.last;
|
|
199
|
+
}
|
|
200
|
+
parent(node) {
|
|
201
|
+
return this.parents.has(node) ? this.parents.get(node) : node.parentNode;
|
|
202
|
+
}
|
|
203
|
+
siblings(node, direction, elements) {
|
|
204
|
+
const parent = this.parent(node);
|
|
205
|
+
if (parent === null) return null;
|
|
206
|
+
if (!this.children.has(parent)) {
|
|
207
|
+
if (elements)
|
|
208
|
+
return direction > 0 ? node.nextElementSibling : node.previousElementSibling;
|
|
209
|
+
return direction > 0 ? node.nextSibling : node.previousSibling;
|
|
210
|
+
}
|
|
211
|
+
let current = node;
|
|
212
|
+
while (true) {
|
|
213
|
+
const link = this.links.get(current);
|
|
214
|
+
const next = direction > 0 ? link.next : link.previous;
|
|
215
|
+
if (next === null || !elements || next.nodeType === 1) return next;
|
|
216
|
+
current = next;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
root(node, composed = false) {
|
|
220
|
+
let parent;
|
|
221
|
+
while ((parent = this.parent(node) ?? (composed && node.nodeType === 11 ? node.host ?? null : null)) !== null)
|
|
222
|
+
node = parent;
|
|
223
|
+
return node;
|
|
224
|
+
}
|
|
225
|
+
contains(node, other) {
|
|
226
|
+
while (other !== null) {
|
|
227
|
+
if (other === node) return true;
|
|
228
|
+
other = this.parent(other);
|
|
229
|
+
}
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
collection(nodes) {
|
|
233
|
+
return Object.assign(nodes, {
|
|
234
|
+
item: (index) => nodes[index] ?? null,
|
|
235
|
+
namedItem: (name) => nodes.find(
|
|
236
|
+
(node) => node.nodeType === 1 && (this.get(node, "id") === name || this.get(node, "name") === name)
|
|
237
|
+
) ?? null
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
inertDocument(node) {
|
|
241
|
+
const owner = node.nodeType === 9 ? node : node.ownerDocument;
|
|
242
|
+
let inert = this.documents.get(owner);
|
|
243
|
+
if (inert === void 0) {
|
|
244
|
+
inert = owner.implementation.createHTMLDocument("");
|
|
245
|
+
this.documents.set(owner, inert);
|
|
246
|
+
}
|
|
247
|
+
return inert;
|
|
248
|
+
}
|
|
249
|
+
/** Native reflection/coercion runs in a document with no custom registry. */
|
|
250
|
+
state(node) {
|
|
251
|
+
let state = this.states.get(node);
|
|
252
|
+
if (state !== void 0) return state;
|
|
253
|
+
const doc = this.inertDocument(node);
|
|
254
|
+
if (node.namespaceURI === "http://www.w3.org/1999/xhtml" && (node.localName === "input" || node.localName === "textarea" || node.localName === "option") && !node.hasAttribute("is")) {
|
|
255
|
+
state = doc.importNode(node, false);
|
|
256
|
+
if (node.localName !== "input") state.textContent = node.textContent;
|
|
257
|
+
if (node.localName === "option")
|
|
258
|
+
state.selected = node.selected;
|
|
259
|
+
} else {
|
|
260
|
+
state = doc.createElementNS(
|
|
261
|
+
node.namespaceURI,
|
|
262
|
+
node.prefix ? `${node.prefix}:${node.localName}` : node.localName
|
|
263
|
+
);
|
|
264
|
+
for (const attr of Array.from(node.attributes))
|
|
265
|
+
state.setAttributeNS(attr.namespaceURI, attr.name, attr.value);
|
|
266
|
+
}
|
|
267
|
+
if (node.localName === "video" || node.localName === "audio")
|
|
268
|
+
state.muted = node.muted;
|
|
269
|
+
this.states.set(node, state);
|
|
270
|
+
return state;
|
|
271
|
+
}
|
|
272
|
+
/** Cold selector/form reads use an inert projection and map results back. */
|
|
273
|
+
projection(node, ancestors = false) {
|
|
274
|
+
const originalRoot = ancestors ? this.root(node) : node;
|
|
275
|
+
const cached = this.projections.get(originalRoot);
|
|
276
|
+
if (cached !== void 0) return { ...cached, node: cached.copies.get(node) };
|
|
277
|
+
const doc = this.inertDocument(node);
|
|
278
|
+
const originals = /* @__PURE__ */ new Map();
|
|
279
|
+
const copies = /* @__PURE__ */ new Map();
|
|
280
|
+
let target;
|
|
281
|
+
const project = (original) => {
|
|
282
|
+
let copy;
|
|
283
|
+
switch (original.nodeType) {
|
|
284
|
+
case 1: {
|
|
285
|
+
const state = this.state(original);
|
|
286
|
+
copy = doc.importNode(state, false);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case 3:
|
|
290
|
+
copy = doc.createTextNode(this.get(original, "nodeValue"));
|
|
291
|
+
break;
|
|
292
|
+
case 8:
|
|
293
|
+
copy = doc.createComment(this.get(original, "nodeValue"));
|
|
294
|
+
break;
|
|
295
|
+
case 9: {
|
|
296
|
+
const document = doc.implementation.createHTMLDocument("");
|
|
297
|
+
document.replaceChildren();
|
|
298
|
+
copy = document;
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
default:
|
|
302
|
+
copy = doc.createDocumentFragment();
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
originals.set(copy, original);
|
|
306
|
+
copies.set(original, copy);
|
|
307
|
+
if (original === node) target = copy;
|
|
308
|
+
const isTemplate = original.nodeType === 1 && original.localName === "template" && "content" in original;
|
|
309
|
+
const sourceParent = isTemplate ? original.content : original;
|
|
310
|
+
const copyParent = isTemplate ? copy.content : copy;
|
|
311
|
+
for (const child of this.childNodes(sourceParent)) {
|
|
312
|
+
if (child.nodeType !== 10) copyParent.appendChild(project(child));
|
|
313
|
+
}
|
|
314
|
+
if (original.nodeType === 1 && original.localName === "option")
|
|
315
|
+
copy.selected = this.state(original).selected;
|
|
316
|
+
const values = this.values.get(original);
|
|
317
|
+
if (values !== void 0 && copy.nodeType === 1) {
|
|
318
|
+
for (const key of ["value", "checked", "selected", "selectedIndex"]) {
|
|
319
|
+
if (values.has(key)) Reflect.set(copy, key, values.get(key));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return copy;
|
|
323
|
+
};
|
|
324
|
+
project(originalRoot);
|
|
325
|
+
const projection = { root: originalRoot, originals, copies };
|
|
326
|
+
this.projections.set(originalRoot, projection);
|
|
327
|
+
return { ...projection, node: target };
|
|
328
|
+
}
|
|
329
|
+
textContent(node) {
|
|
330
|
+
if (node.nodeType === 9 || node.nodeType === 10) return null;
|
|
331
|
+
if (node.nodeType === 3 || node.nodeType === 8) return this.get(node, "nodeValue");
|
|
332
|
+
let text = "";
|
|
333
|
+
for (const child of this.childNodes(node)) {
|
|
334
|
+
if (child.nodeType !== 8) text += this.textContent(child) ?? "";
|
|
335
|
+
}
|
|
336
|
+
return text;
|
|
337
|
+
}
|
|
338
|
+
get(node, key) {
|
|
339
|
+
if (this.ended) {
|
|
340
|
+
const value2 = Reflect.get(node, key, node);
|
|
341
|
+
return typeof value2 === "function" ? value2.bind(node) : value2;
|
|
342
|
+
}
|
|
343
|
+
const values = this.values.get(node);
|
|
344
|
+
if ((node.nodeType === 3 || node.nodeType === 8) && (key === "data" || key === "textContent"))
|
|
345
|
+
key = "nodeValue";
|
|
346
|
+
if (values?.has(key)) return values.get(key);
|
|
347
|
+
if (key === "length" && (node.nodeType === 3 || node.nodeType === 8))
|
|
348
|
+
return this.get(node, "nodeValue").length;
|
|
349
|
+
switch (key) {
|
|
350
|
+
case "parentNode":
|
|
351
|
+
return this.parent(node);
|
|
352
|
+
case "parentElement": {
|
|
353
|
+
const parent = this.parent(node);
|
|
354
|
+
return parent?.nodeType === 1 ? parent : null;
|
|
355
|
+
}
|
|
356
|
+
case "firstChild":
|
|
357
|
+
case "lastChild":
|
|
358
|
+
return this.child(node, key);
|
|
359
|
+
case "nextSibling":
|
|
360
|
+
return this.siblings(node, 1, false);
|
|
361
|
+
case "previousSibling":
|
|
362
|
+
return this.siblings(node, -1, false);
|
|
363
|
+
case "nextElementSibling":
|
|
364
|
+
return this.siblings(node, 1, true);
|
|
365
|
+
case "previousElementSibling":
|
|
366
|
+
return this.siblings(node, -1, true);
|
|
367
|
+
case "firstElementChild":
|
|
368
|
+
return this.childNodes(node).find((child) => child.nodeType === 1) ?? null;
|
|
369
|
+
case "lastElementChild":
|
|
370
|
+
return this.childNodes(node).filter((child) => child.nodeType === 1).at(-1) ?? null;
|
|
371
|
+
case "childNodes":
|
|
372
|
+
return this.collection(this.childNodes(node).slice());
|
|
373
|
+
case "children":
|
|
374
|
+
return this.collection(this.childNodes(node).filter((child) => child.nodeType === 1));
|
|
375
|
+
case "childElementCount":
|
|
376
|
+
return this.childNodes(node).filter((child) => child.nodeType === 1).length;
|
|
377
|
+
case "isConnected":
|
|
378
|
+
return this.root(node, true).nodeType === 9;
|
|
379
|
+
case "textContent":
|
|
380
|
+
return this.textContent(node);
|
|
381
|
+
case "innerHTML":
|
|
382
|
+
case "outerHTML":
|
|
383
|
+
return Reflect.get(this.projection(node).node, key);
|
|
384
|
+
case "style":
|
|
385
|
+
return this.style(node);
|
|
386
|
+
case "classList":
|
|
387
|
+
return this.classList(node);
|
|
388
|
+
case "attributes":
|
|
389
|
+
return this.state(node).attributes;
|
|
390
|
+
case "options":
|
|
391
|
+
case "selectedOptions":
|
|
392
|
+
case "elements": {
|
|
393
|
+
const projected = this.projection(node, key === "elements");
|
|
394
|
+
const options = Reflect.get(projected.node, key);
|
|
395
|
+
return this.collection(Array.from(options, (option) => projected.originals.get(option)));
|
|
396
|
+
}
|
|
397
|
+
case "selectedIndex":
|
|
398
|
+
return Reflect.get(this.projection(node).node, key);
|
|
399
|
+
case "form": {
|
|
400
|
+
const projected = this.projection(node, true);
|
|
401
|
+
const form = Reflect.get(projected.node, key);
|
|
402
|
+
return form === null ? null : projected.originals.get(form) ?? null;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const value = Reflect.get(node, key, node);
|
|
406
|
+
if (typeof value === "function") return (...args) => this.call(node, key, args);
|
|
407
|
+
if (node.nodeType === 1 && typeof key === "string" && (PROJECTED_PROPERTIES.has(key) || key.startsWith("aria")) && key in this.state(node) && (value === null || typeof value !== "object")) {
|
|
408
|
+
if (key === "value" && (node.localName === "select" || node.localName === "option"))
|
|
409
|
+
return Reflect.get(this.projection(node).node, key);
|
|
410
|
+
return Reflect.get(this.state(node), key);
|
|
411
|
+
}
|
|
412
|
+
return value;
|
|
413
|
+
}
|
|
414
|
+
value(node, key, value) {
|
|
415
|
+
let values = this.values.get(node);
|
|
416
|
+
if (values === void 0) this.values.set(node, values = /* @__PURE__ */ new Map());
|
|
417
|
+
values.set(key, value);
|
|
418
|
+
}
|
|
419
|
+
set(node, key, value) {
|
|
420
|
+
if (this.ended || typeof key === "symbol" || typeof key === "string" && (key.startsWith("__oct") || EAGER_METADATA.has(key))) {
|
|
421
|
+
Reflect.set(node, key, value, node);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const radioWrite = node.nodeType === 1 && node.localName === "input" && (key === "checked" || key === "defaultChecked") && this.state(node).type === "radio";
|
|
425
|
+
if (!radioWrite) this.projections.clear();
|
|
426
|
+
if ((node.nodeType === 3 || node.nodeType === 8) && (key === "data" || key === "textContent" || key === "nodeValue")) {
|
|
427
|
+
key = "nodeValue";
|
|
428
|
+
value = value === null || value === void 0 ? "" : String(value);
|
|
429
|
+
}
|
|
430
|
+
if ((key === "innerHTML" || key === "textContent") && this.isFresh(node) && !this.children.has(node) && !(node.localName === "template" && this.children.has(node.content))) {
|
|
431
|
+
Reflect.set(node, key, value, node);
|
|
432
|
+
this.states.delete(node);
|
|
433
|
+
this.created(node);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (key === "textContent" && node.nodeType !== 3 && node.nodeType !== 8) {
|
|
437
|
+
const text = value === null || value === void 0 ? "" : String(value);
|
|
438
|
+
const children = text === "" ? [] : [this.created(node.ownerDocument.createTextNode(text))];
|
|
439
|
+
this.replaceChildren(node, children);
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (key === "innerHTML") {
|
|
443
|
+
const element = node;
|
|
444
|
+
const shell = this.inertDocument(node).createElementNS(
|
|
445
|
+
element.namespaceURI,
|
|
446
|
+
element.prefix ? `${element.prefix}:${element.localName}` : element.localName
|
|
447
|
+
);
|
|
448
|
+
shell.innerHTML = value;
|
|
449
|
+
const isTemplate = element.localName === "template" && "content" in element;
|
|
450
|
+
const parsed = isTemplate ? shell.content : shell;
|
|
451
|
+
const children = Array.from(
|
|
452
|
+
parsed.childNodes,
|
|
453
|
+
(child) => this.created(node.ownerDocument.importNode(child, true))
|
|
454
|
+
);
|
|
455
|
+
this.replaceChildren(isTemplate ? element.content : node, children);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (key === "style") {
|
|
459
|
+
this.style(node).cssText = value;
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (key === "scrollTop" || key === "scrollLeft") {
|
|
463
|
+
this.write(node, () => {
|
|
464
|
+
Reflect.set(node, key, value, node);
|
|
465
|
+
});
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (node.nodeType === 1 && this.setFormProperty(node, key, value)) return;
|
|
469
|
+
if (this.isFresh(node)) {
|
|
470
|
+
Reflect.set(node, key, value, node);
|
|
471
|
+
this.states.delete(node);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
if (node.nodeType === 1 && typeof key === "string") {
|
|
475
|
+
const state = this.state(node);
|
|
476
|
+
if (key in state && !key.startsWith("on") && !key.startsWith("_") && !key.startsWith("$")) {
|
|
477
|
+
Reflect.set(state, key, value);
|
|
478
|
+
if (key === "selected" || key === "selectedIndex" || !PROJECTED_PROPERTIES.has(key) && !key.startsWith("aria"))
|
|
479
|
+
this.value(node, key, Reflect.get(state, key));
|
|
480
|
+
} else this.value(node, key, value);
|
|
481
|
+
} else this.value(node, key, value);
|
|
482
|
+
this.enqueue(() => {
|
|
483
|
+
Reflect.set(node, key, value, node);
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
setFormProperty(node, key, value) {
|
|
487
|
+
if (node.localName === "input" && (key === "checked" || key === "defaultChecked") && this.state(node).type === "radio") {
|
|
488
|
+
const projected2 = this.projection(node, true);
|
|
489
|
+
const target2 = projected2.node;
|
|
490
|
+
Reflect.set(target2, key, value);
|
|
491
|
+
for (const [copy, original] of projected2.originals) {
|
|
492
|
+
if (copy.nodeType !== 1 || copy.localName !== "input") continue;
|
|
493
|
+
const input = copy;
|
|
494
|
+
if (input !== target2 && (input.type !== "radio" || input.name !== target2.name || input.form !== target2.form))
|
|
495
|
+
continue;
|
|
496
|
+
this.states.set(original, this.inertDocument(original).importNode(input, false));
|
|
497
|
+
this.values.get(original)?.delete("checked");
|
|
498
|
+
}
|
|
499
|
+
this.projections.clear();
|
|
500
|
+
this.projections.set(projected2.root, projected2);
|
|
501
|
+
this.enqueue(() => {
|
|
502
|
+
Reflect.set(node, key, value, node);
|
|
503
|
+
});
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
if (node.localName === "textarea" && key === "defaultValue") {
|
|
507
|
+
const state = this.state(node);
|
|
508
|
+
state.defaultValue = value;
|
|
509
|
+
this.replaceChildren(
|
|
510
|
+
node,
|
|
511
|
+
state.defaultValue === "" ? [] : [this.created(node.ownerDocument.createTextNode(state.defaultValue))]
|
|
512
|
+
);
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
let select = node;
|
|
516
|
+
if (node.localName === "option" && key === "selected") {
|
|
517
|
+
while (select !== null && select.localName !== "select")
|
|
518
|
+
select = this.parent(select);
|
|
519
|
+
} else if (node.localName !== "select" || key !== "value" && key !== "selectedIndex")
|
|
520
|
+
return false;
|
|
521
|
+
if (select === null) return false;
|
|
522
|
+
const projected = this.projection(select);
|
|
523
|
+
let target = projected.node;
|
|
524
|
+
if (node !== select)
|
|
525
|
+
for (const [copy, original] of projected.originals) {
|
|
526
|
+
if (original === node) {
|
|
527
|
+
target = copy;
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
Reflect.set(target, key, value);
|
|
532
|
+
for (const option of Array.from(projected.node.options)) {
|
|
533
|
+
const original = projected.originals.get(option);
|
|
534
|
+
this.state(original).selected = option.selected;
|
|
535
|
+
this.value(original, "selected", option.selected);
|
|
536
|
+
}
|
|
537
|
+
this.enqueue(() => {
|
|
538
|
+
Reflect.set(node, key, value, node);
|
|
539
|
+
});
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
style(node) {
|
|
543
|
+
let style = this.styles.get(node);
|
|
544
|
+
if (style !== void 0) return style;
|
|
545
|
+
const actual = node.style;
|
|
546
|
+
style = new Proxy(actual, {
|
|
547
|
+
get: (_, key) => {
|
|
548
|
+
const state = this.state(node).style;
|
|
549
|
+
if (key === "setProperty" || key === "removeProperty")
|
|
550
|
+
return (...args) => {
|
|
551
|
+
const result = Reflect.apply(Reflect.get(state, key), state, args);
|
|
552
|
+
this.write(node, () => {
|
|
553
|
+
Reflect.apply(Reflect.get(actual, key), actual, args);
|
|
554
|
+
});
|
|
555
|
+
return result;
|
|
556
|
+
};
|
|
557
|
+
const value = Reflect.get(state, key, state);
|
|
558
|
+
return typeof value === "function" ? value.bind(state) : value;
|
|
559
|
+
},
|
|
560
|
+
set: (_, key, value) => {
|
|
561
|
+
Reflect.set(this.state(node).style, key, value);
|
|
562
|
+
this.write(node, () => {
|
|
563
|
+
Reflect.set(actual, key, value);
|
|
564
|
+
});
|
|
565
|
+
return true;
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
this.styles.set(node, style);
|
|
569
|
+
return style;
|
|
570
|
+
}
|
|
571
|
+
classList(node) {
|
|
572
|
+
return new Proxy(node.classList, {
|
|
573
|
+
get: (_, key) => {
|
|
574
|
+
const list = this.state(node).classList;
|
|
575
|
+
const value = Reflect.get(list, key, list);
|
|
576
|
+
if (key === "add" || key === "remove" || key === "toggle" || key === "replace")
|
|
577
|
+
return (...args) => {
|
|
578
|
+
const result = Reflect.apply(value, list, args);
|
|
579
|
+
this.write(node, () => {
|
|
580
|
+
Reflect.apply(Reflect.get(node.classList, key), node.classList, args);
|
|
581
|
+
});
|
|
582
|
+
return result;
|
|
583
|
+
};
|
|
584
|
+
return typeof value === "function" ? value.bind(list) : value;
|
|
585
|
+
},
|
|
586
|
+
set: (_, key, value) => {
|
|
587
|
+
Reflect.set(this.state(node).classList, key, value);
|
|
588
|
+
this.write(node, () => {
|
|
589
|
+
Reflect.set(node.classList, key, value);
|
|
590
|
+
});
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
write(node, action) {
|
|
596
|
+
this.projections.clear();
|
|
597
|
+
if (this.isFresh(node)) action();
|
|
598
|
+
else this.enqueue(action);
|
|
599
|
+
}
|
|
600
|
+
remove(parent, child) {
|
|
601
|
+
const list = this.childList(parent);
|
|
602
|
+
if (this.parent(child) !== parent)
|
|
603
|
+
throw new DOMException("The node is not a child of this parent.", "NotFoundError");
|
|
604
|
+
const link = this.links.get(child);
|
|
605
|
+
if (link.previous === null) list.first = link.next;
|
|
606
|
+
else this.links.get(link.previous).next = link.next;
|
|
607
|
+
if (link.next === null) list.last = link.previous;
|
|
608
|
+
else this.links.get(link.next).previous = link.previous;
|
|
609
|
+
list.length--;
|
|
610
|
+
list.snapshot = null;
|
|
611
|
+
this.links.delete(child);
|
|
612
|
+
this.parents.set(child, null);
|
|
613
|
+
this.projections.clear();
|
|
614
|
+
}
|
|
615
|
+
insert(parent, child, anchor, move = false) {
|
|
616
|
+
if (child === anchor) return;
|
|
617
|
+
if (anchor !== null && this.parent(anchor) !== parent)
|
|
618
|
+
throw new DOMException("The anchor is not a child of this parent.", "NotFoundError");
|
|
619
|
+
if (this.contains(child, parent))
|
|
620
|
+
throw new DOMException("The insertion would create a cycle.", "HierarchyRequestError");
|
|
621
|
+
if (child.nodeType === 11) {
|
|
622
|
+
for (const item of this.childNodes(child).slice()) this.insert(parent, item, anchor);
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
const oldParent = this.parent(child);
|
|
626
|
+
const eager = this.isFresh(parent) && this.isFresh(child) && !this.parents.has(child) && !this.children.has(parent) && (oldParent === null || !this.children.has(oldParent)) && (anchor === null || anchor.parentNode === parent);
|
|
627
|
+
if (eager) {
|
|
628
|
+
parent.insertBefore(child, anchor);
|
|
629
|
+
this.projections.clear();
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
if (oldParent !== null) this.remove(oldParent, child);
|
|
633
|
+
const list = this.childList(parent);
|
|
634
|
+
const previous = anchor === null ? list.last : this.links.get(anchor).previous;
|
|
635
|
+
this.links.set(child, { previous, next: anchor });
|
|
636
|
+
if (previous === null) list.first = child;
|
|
637
|
+
else this.links.get(previous).next = child;
|
|
638
|
+
if (anchor === null) list.last = child;
|
|
639
|
+
else this.links.get(anchor).previous = child;
|
|
640
|
+
list.length++;
|
|
641
|
+
list.snapshot = null;
|
|
642
|
+
this.parents.set(child, parent);
|
|
643
|
+
this.projections.clear();
|
|
644
|
+
this.enqueue(() => {
|
|
645
|
+
if (move)
|
|
646
|
+
parent.moveBefore(
|
|
647
|
+
child,
|
|
648
|
+
anchor
|
|
649
|
+
);
|
|
650
|
+
else parent.insertBefore(child, anchor);
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
replaceChildren(node, children) {
|
|
654
|
+
const list = this.childList(node);
|
|
655
|
+
for (let child = list.first; child !== null; ) {
|
|
656
|
+
const next = this.links.get(child).next;
|
|
657
|
+
this.parents.set(child, null);
|
|
658
|
+
this.links.delete(child);
|
|
659
|
+
child = next;
|
|
660
|
+
}
|
|
661
|
+
list.first = list.last = null;
|
|
662
|
+
list.length = 0;
|
|
663
|
+
list.snapshot = null;
|
|
664
|
+
this.projections.clear();
|
|
665
|
+
this.enqueue(() => {
|
|
666
|
+
node.textContent = "";
|
|
667
|
+
});
|
|
668
|
+
for (const child of children) this.insert(node, child, null);
|
|
669
|
+
}
|
|
670
|
+
/** Clear a shared-parent range once while retaining both live anchors. */
|
|
671
|
+
clearBetween(start, end) {
|
|
672
|
+
const parent = this.parent(start);
|
|
673
|
+
if (parent === null || this.parent(end) !== parent)
|
|
674
|
+
throw new DOMException("Range anchors have different parents.", "NotFoundError");
|
|
675
|
+
this.childList(parent);
|
|
676
|
+
let child = this.siblings(start, 1, false);
|
|
677
|
+
while (child !== null && child !== end) child = this.siblings(child, 1, false);
|
|
678
|
+
if (child !== end)
|
|
679
|
+
throw new DOMException("The end anchor precedes the start.", "NotFoundError");
|
|
680
|
+
child = this.siblings(start, 1, false);
|
|
681
|
+
while (child !== null && child !== end) {
|
|
682
|
+
const next = this.siblings(child, 1, false);
|
|
683
|
+
this.remove(parent, child);
|
|
684
|
+
child = next;
|
|
685
|
+
}
|
|
686
|
+
this.enqueue(() => {
|
|
687
|
+
if (start.parentNode !== parent || end.parentNode !== parent) return;
|
|
688
|
+
const range = parent.ownerDocument.createRange();
|
|
689
|
+
range.setStartAfter(start);
|
|
690
|
+
range.setEndBefore(end);
|
|
691
|
+
range.deleteContents();
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
nodes(node, args) {
|
|
695
|
+
return args.map(
|
|
696
|
+
(value) => typeof value === "object" && value !== null && "nodeType" in value ? value : this.created(node.ownerDocument.createTextNode(String(value)))
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
call(node, key, args) {
|
|
700
|
+
switch (key) {
|
|
701
|
+
case "hasChildNodes":
|
|
702
|
+
return this.childNodes(node).length > 0;
|
|
703
|
+
case "contains":
|
|
704
|
+
return this.contains(node, args[0]);
|
|
705
|
+
case "getRootNode":
|
|
706
|
+
return this.root(node, args[0]?.composed);
|
|
707
|
+
case "compareDocumentPosition": {
|
|
708
|
+
const other = args[0];
|
|
709
|
+
if (node === other) return 0;
|
|
710
|
+
if (this.contains(node, other)) return 20;
|
|
711
|
+
if (this.contains(other, node)) return 10;
|
|
712
|
+
if (this.root(node) !== this.root(other)) return node.compareDocumentPosition(other) | 1;
|
|
713
|
+
const path = (current) => {
|
|
714
|
+
const result = [current];
|
|
715
|
+
let parent;
|
|
716
|
+
while ((parent = this.parent(current)) !== null) result.unshift(current = parent);
|
|
717
|
+
return result;
|
|
718
|
+
};
|
|
719
|
+
const a = path(node), b = path(other);
|
|
720
|
+
let index = 0;
|
|
721
|
+
while (a[index] === b[index]) index++;
|
|
722
|
+
const children = this.childNodes(a[index - 1]);
|
|
723
|
+
return children.indexOf(a[index]) < children.indexOf(b[index]) ? 4 : 2;
|
|
724
|
+
}
|
|
725
|
+
case "appendChild":
|
|
726
|
+
this.insert(node, args[0], null);
|
|
727
|
+
return args[0];
|
|
728
|
+
case "insertBefore":
|
|
729
|
+
this.insert(node, args[0], args[1]);
|
|
730
|
+
return args[0];
|
|
731
|
+
case "moveBefore":
|
|
732
|
+
this.insert(node, args[0], args[1], true);
|
|
733
|
+
return;
|
|
734
|
+
case "removeChild": {
|
|
735
|
+
const child = args[0];
|
|
736
|
+
if (this.isFresh(node) && this.isFresh(child) && !this.children.has(node)) {
|
|
737
|
+
node.removeChild(child);
|
|
738
|
+
this.projections.clear();
|
|
739
|
+
} else {
|
|
740
|
+
this.remove(node, child);
|
|
741
|
+
this.enqueue(() => {
|
|
742
|
+
if (child.parentNode === node) node.removeChild(child);
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
return child;
|
|
746
|
+
}
|
|
747
|
+
case "replaceChild": {
|
|
748
|
+
const child = args[0], old = args[1];
|
|
749
|
+
if (child !== old) {
|
|
750
|
+
this.insert(node, child, old);
|
|
751
|
+
this.call(node, "removeChild", [old]);
|
|
752
|
+
}
|
|
753
|
+
return old;
|
|
754
|
+
}
|
|
755
|
+
case "replaceChildren":
|
|
756
|
+
this.replaceChildren(node, this.nodes(node, args));
|
|
757
|
+
return;
|
|
758
|
+
case "append":
|
|
759
|
+
for (const child of this.nodes(node, args)) this.insert(node, child, null);
|
|
760
|
+
return;
|
|
761
|
+
case "prepend": {
|
|
762
|
+
const anchor = this.childNodes(node)[0] ?? null;
|
|
763
|
+
for (const child of this.nodes(node, args)) this.insert(node, child, anchor);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
case "remove": {
|
|
767
|
+
const parent = this.parent(node);
|
|
768
|
+
if (parent !== null) this.call(parent, "removeChild", [node]);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
case "before":
|
|
772
|
+
case "after":
|
|
773
|
+
case "replaceWith": {
|
|
774
|
+
const parent = this.parent(node);
|
|
775
|
+
if (parent === null) return;
|
|
776
|
+
const anchor = key === "after" ? this.siblings(node, 1, false) : node;
|
|
777
|
+
for (const child of this.nodes(node, args)) this.insert(parent, child, anchor);
|
|
778
|
+
if (key === "replaceWith") this.call(parent, "removeChild", [node]);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
case "getAttribute":
|
|
782
|
+
case "getAttributeNS":
|
|
783
|
+
case "getAttributeNames":
|
|
784
|
+
case "hasAttribute":
|
|
785
|
+
case "hasAttributeNS":
|
|
786
|
+
case "hasAttributes": {
|
|
787
|
+
const state = this.states.get(node) ?? node;
|
|
788
|
+
return Reflect.apply(Reflect.get(state, key), state, args);
|
|
789
|
+
}
|
|
790
|
+
case "setAttribute":
|
|
791
|
+
case "setAttributeNS":
|
|
792
|
+
case "removeAttribute":
|
|
793
|
+
case "removeAttributeNS":
|
|
794
|
+
case "toggleAttribute": {
|
|
795
|
+
const state = this.state(node);
|
|
796
|
+
const result = Reflect.apply(Reflect.get(state, key), state, args);
|
|
797
|
+
this.write(node, () => {
|
|
798
|
+
Reflect.apply(Reflect.get(node, key), node, args);
|
|
799
|
+
});
|
|
800
|
+
return result;
|
|
801
|
+
}
|
|
802
|
+
case "getElementsByTagName":
|
|
803
|
+
case "getElementsByTagNameNS":
|
|
804
|
+
case "getElementsByClassName":
|
|
805
|
+
case "getElementsByName":
|
|
806
|
+
case "getElementById": {
|
|
807
|
+
const result = [];
|
|
808
|
+
const name = String(args[key === "getElementsByTagNameNS" ? 1 : 0]);
|
|
809
|
+
const tokens = name.trim().split(/\s+/);
|
|
810
|
+
const visit = (parent) => {
|
|
811
|
+
for (const child of this.childNodes(parent)) {
|
|
812
|
+
if (child.nodeType !== 1) continue;
|
|
813
|
+
const element = child;
|
|
814
|
+
let match;
|
|
815
|
+
if (key === "getElementsByClassName")
|
|
816
|
+
match = name.trim() !== "" && tokens.every((token) => this.state(element).classList.contains(token));
|
|
817
|
+
else if (key === "getElementsByName")
|
|
818
|
+
match = this.state(element).getAttribute("name") === name;
|
|
819
|
+
else if (key === "getElementById")
|
|
820
|
+
match = name !== "" && this.get(element, "id") === name;
|
|
821
|
+
else if (key === "getElementsByTagNameNS")
|
|
822
|
+
match = (args[0] === "*" || (args[0] || null) === element.namespaceURI) && (name === "*" || name === element.localName);
|
|
823
|
+
else
|
|
824
|
+
match = name === "*" || (element.namespaceURI === "http://www.w3.org/1999/xhtml" ? name.toLowerCase() === element.localName : name === element.tagName);
|
|
825
|
+
if (match) result.push(element);
|
|
826
|
+
visit(element);
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
visit(node);
|
|
830
|
+
return key === "getElementById" ? result[0] ?? null : this.collection(result);
|
|
831
|
+
}
|
|
832
|
+
case "querySelector":
|
|
833
|
+
case "querySelectorAll":
|
|
834
|
+
case "matches":
|
|
835
|
+
case "closest": {
|
|
836
|
+
const projected = this.projection(node, key === "matches" || key === "closest");
|
|
837
|
+
const result = Reflect.apply(Reflect.get(projected.node, key), projected.node, args);
|
|
838
|
+
if (key === "matches") return result;
|
|
839
|
+
if (key === "querySelectorAll")
|
|
840
|
+
return this.collection(
|
|
841
|
+
Array.from(result, (item) => projected.originals.get(item))
|
|
842
|
+
);
|
|
843
|
+
return result === null ? null : projected.originals.get(result) ?? null;
|
|
844
|
+
}
|
|
845
|
+
case "addEventListener":
|
|
846
|
+
case "removeEventListener":
|
|
847
|
+
case "focus":
|
|
848
|
+
case "blur":
|
|
849
|
+
case "setSelectionRange":
|
|
850
|
+
case "setRangeText":
|
|
851
|
+
case "scrollTo":
|
|
852
|
+
case "scrollBy":
|
|
853
|
+
case "scrollIntoView":
|
|
854
|
+
this.write(node, () => {
|
|
855
|
+
Reflect.apply(Reflect.get(node, key), node, args);
|
|
856
|
+
});
|
|
857
|
+
return;
|
|
858
|
+
case "createElement":
|
|
859
|
+
case "createElementNS":
|
|
860
|
+
case "createTextNode":
|
|
861
|
+
case "createComment":
|
|
862
|
+
case "createDocumentFragment":
|
|
863
|
+
case "importNode":
|
|
864
|
+
case "cloneNode":
|
|
865
|
+
return this.created(Reflect.apply(Reflect.get(node, key), node, args));
|
|
866
|
+
}
|
|
867
|
+
return Reflect.apply(Reflect.get(node, key), node, args);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
export {
|
|
871
|
+
DOMStage
|
|
872
|
+
};
|