@miaskiewicz/turbo-dom 0.1.36 → 0.1.38
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miaskiewicz/turbo-dom",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.38",
|
|
4
4
|
"description": "Faster, more spec-correct DOM for test runners — native html5ever (Rust/WASM) parser + lazy copy-on-write DOM. A drop-in-style alternative to jsdom/happy-dom for vitest & jest.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
package/src/runtime/dom.mjs
CHANGED
|
@@ -150,7 +150,7 @@ export class Node extends EventTarget {
|
|
|
150
150
|
if (ref) kids.splice(i, 0, node); else kids.push(node);
|
|
151
151
|
node.parentNode = this;
|
|
152
152
|
node.ownerDocument = this.ownerDocument;
|
|
153
|
-
notifyMutation(this,
|
|
153
|
+
notifyMutation(this, 'childList', node, null, ref || null);
|
|
154
154
|
return node;
|
|
155
155
|
}
|
|
156
156
|
|
|
@@ -161,7 +161,7 @@ export class Node extends EventTarget {
|
|
|
161
161
|
const next = kids[i + 1] || null;
|
|
162
162
|
kids.splice(i, 1);
|
|
163
163
|
node.parentNode = null;
|
|
164
|
-
notifyMutation(this,
|
|
164
|
+
notifyMutation(this, 'childList', null, node, next);
|
|
165
165
|
return node;
|
|
166
166
|
}
|
|
167
167
|
|
|
@@ -216,7 +216,7 @@ export class Node extends EventTarget {
|
|
|
216
216
|
}
|
|
217
217
|
// normalize mutates __kids in place — bump __version (invalidate cached queries)
|
|
218
218
|
// and feed MutationObservers, like every other childList mutation path.
|
|
219
|
-
if (changed) notifyMutation(this,
|
|
219
|
+
if (changed) notifyMutation(this, 'childList', null, null, null);
|
|
220
220
|
}
|
|
221
221
|
replaceChildren(...nodes) { this.__kids = []; this.__touch(); for (const n of nodes) this.appendChild(typeof n === 'string' ? this.ownerDocument.createTextNode(n) : n); }
|
|
222
222
|
// bitmask: 1 DISCONNECTED, 2 PRECEDING, 4 FOLLOWING, 8 CONTAINS, 16 CONTAINED_BY
|
|
@@ -282,7 +282,7 @@ Object.assign(Node.prototype, {
|
|
|
282
282
|
class CharacterData extends Node {
|
|
283
283
|
constructor(ownerDocument, data) { super(ownerDocument); this._data = data ?? ''; }
|
|
284
284
|
get data() { return this._data; }
|
|
285
|
-
set data(v) { const old = this._data; this._data = String(v); notifyMutation(this,
|
|
285
|
+
set data(v) { const old = this._data; this._data = String(v); notifyMutation(this, 'characterData', null, null, null, null, old); }
|
|
286
286
|
get nodeValue() { return this._data; }
|
|
287
287
|
set nodeValue(v) { this.data = v; }
|
|
288
288
|
get length() { return this._data.length; }
|
|
@@ -407,14 +407,14 @@ export class Element extends Node {
|
|
|
407
407
|
const old = a ? a.value : null;
|
|
408
408
|
if (a) a.value = String(value);
|
|
409
409
|
else this.__attrs.push({ name, value: String(value), prefix: '' });
|
|
410
|
-
notifyMutation(this,
|
|
410
|
+
notifyMutation(this, 'attributes', null, null, null, name, old);
|
|
411
411
|
}
|
|
412
412
|
removeAttribute(name) {
|
|
413
413
|
if (!this.__ns) name = ('' + name).toLowerCase();
|
|
414
414
|
if (this.__attrs === undefined) this.__attrs = this.__buildAttrs();
|
|
415
415
|
const a = this.__attrs.find((x) => x.name === name);
|
|
416
416
|
this.__attrs = this.__attrs.filter((x) => x.name !== name);
|
|
417
|
-
if (a) notifyMutation(this,
|
|
417
|
+
if (a) notifyMutation(this, 'attributes', null, null, null, name, a.value);
|
|
418
418
|
}
|
|
419
419
|
toggleAttribute(name, force) {
|
|
420
420
|
const has = this.hasAttribute(name);
|
|
@@ -1303,29 +1303,38 @@ function isDescendant(node, ancestor) {
|
|
|
1303
1303
|
while (n) { if (n === ancestor) return true; n = n.parentNode; }
|
|
1304
1304
|
return false;
|
|
1305
1305
|
}
|
|
1306
|
-
|
|
1306
|
+
const EMPTY_NODES = []; // shared read-only addedNodes/removedNodes for empty records
|
|
1307
|
+
|
|
1308
|
+
// Mutation notification — takes primitives (a single added/removed node, etc) so
|
|
1309
|
+
// the common case (no MutationObservers — most test files) allocates NOTHING: it
|
|
1310
|
+
// only bumps __version and returns. The MutationRecord object + its node arrays
|
|
1311
|
+
// are built solely when an observer is actually registered.
|
|
1312
|
+
function notifyMutation(target, type, added, removed, nextSibling, attributeName, oldValue) {
|
|
1307
1313
|
const doc = target.ownerDocument;
|
|
1308
1314
|
if (!doc) return;
|
|
1309
1315
|
// bump the DOM version on every structural/attribute mutation — invalidates
|
|
1310
1316
|
// the document's getElementsBy* caches. Unconditional (independent of observers).
|
|
1311
1317
|
doc.__version = (doc.__version || 0) + 1;
|
|
1312
|
-
|
|
1313
|
-
|
|
1318
|
+
const mo = doc.__mo;
|
|
1319
|
+
if (!mo || mo.length === 0) return;
|
|
1320
|
+
const addedNodes = added ? [added] : EMPTY_NODES;
|
|
1321
|
+
const removedNodes = removed ? [removed] : EMPTY_NODES;
|
|
1322
|
+
for (const reg of mo) {
|
|
1314
1323
|
const { obs, target: obsTarget, options } = reg;
|
|
1315
|
-
const onTarget =
|
|
1316
|
-
const inSubtree = options.subtree && isDescendant(
|
|
1324
|
+
const onTarget = target === obsTarget;
|
|
1325
|
+
const inSubtree = options.subtree && isDescendant(target, obsTarget);
|
|
1317
1326
|
if (!onTarget && !inSubtree) continue;
|
|
1318
|
-
if (
|
|
1319
|
-
if (
|
|
1320
|
-
if (
|
|
1321
|
-
if (
|
|
1327
|
+
if (type === 'childList' && !options.childList) continue;
|
|
1328
|
+
if (type === 'attributes' && !options.attributes) continue;
|
|
1329
|
+
if (type === 'attributes' && options.attributeFilter && !options.attributeFilter.includes(attributeName)) continue;
|
|
1330
|
+
if (type === 'characterData' && !options.characterData) continue;
|
|
1322
1331
|
const rec = {
|
|
1323
|
-
type
|
|
1324
|
-
addedNodes
|
|
1325
|
-
previousSibling:
|
|
1326
|
-
attributeName:
|
|
1327
|
-
oldValue: (
|
|
1328
|
-
(
|
|
1332
|
+
type, target,
|
|
1333
|
+
addedNodes, removedNodes,
|
|
1334
|
+
previousSibling: null, nextSibling: nextSibling || null,
|
|
1335
|
+
attributeName: attributeName || null, attributeNamespace: null,
|
|
1336
|
+
oldValue: (type === 'attributes' && options.attributeOldValue) ||
|
|
1337
|
+
(type === 'characterData' && options.characterDataOldValue) ? (oldValue ?? null) : null,
|
|
1329
1338
|
};
|
|
1330
1339
|
obs.__enqueue(rec);
|
|
1331
1340
|
doc.__scheduleMO(obs);
|
package/src/runtime/events.mjs
CHANGED
|
@@ -25,7 +25,7 @@ export class Event {
|
|
|
25
25
|
this.timeStamp = 0;
|
|
26
26
|
this._stopPropagation = false;
|
|
27
27
|
this._stopImmediate = false;
|
|
28
|
-
this._path = []
|
|
28
|
+
this._path = null; // set by dispatchEvent; composedPath() reads [] until then
|
|
29
29
|
this._passiveListener = false;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -40,7 +40,7 @@ export class Event {
|
|
|
40
40
|
get returnValue() { return !this.defaultPrevented; }
|
|
41
41
|
set returnValue(v) { if (v === false) this.preventDefault(); }
|
|
42
42
|
|
|
43
|
-
composedPath() { return this._path.slice(); }
|
|
43
|
+
composedPath() { return this._path ? this._path.slice() : []; }
|
|
44
44
|
|
|
45
45
|
// legacy init — react-dom's dev rethrow path uses createEvent('Event')+initEvent
|
|
46
46
|
initEvent(type, bubbles = false, cancelable = false) {
|
|
Binary file
|