@miaskiewicz/turbo-dom 0.1.46 → 0.1.48
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.48",
|
|
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/buffer.mjs
CHANGED
|
@@ -5,7 +5,9 @@ const NS_SHORT = ['', 'svg', 'math'];
|
|
|
5
5
|
|
|
6
6
|
// Inflate the packed byte blob into named typed-array views (zero-copy).
|
|
7
7
|
// Mirrors the column order in lib.rs JsSoa::from. One ArrayBuffer, ~13 views.
|
|
8
|
-
|
|
8
|
+
// Exported so the parse cache can unpack ONCE per HTML (the views are read-only
|
|
9
|
+
// over the shared immutable buffer) instead of re-unpacking per Document.
|
|
10
|
+
export function unpack(soa) {
|
|
9
11
|
const u8 = soa.packed, ab = u8.buffer, base = u8.byteOffset, n = soa.n, m = soa.m;
|
|
10
12
|
let off = base;
|
|
11
13
|
const i32 = () => { const a = new Int32Array(ab, off, n); off += n * 4; return a; };
|
package/src/runtime/dom.mjs
CHANGED
|
@@ -630,7 +630,15 @@ export class Element extends Node {
|
|
|
630
630
|
get children() {
|
|
631
631
|
if (this.__childrenList) return this.__childrenList;
|
|
632
632
|
const self = this;
|
|
633
|
-
|
|
633
|
+
// version-cache the element-filtered array (like cachedQSA): re-filter only when
|
|
634
|
+
// the DOM version changes, not on every children[i]/length access. Live —
|
|
635
|
+
// every mutation bumps Document.__version, invalidating the cache.
|
|
636
|
+
return (this.__childrenList = liveHTMLCollection(() => {
|
|
637
|
+
const d = self.ownerDocument, v = d ? (d.__version || 0) : 0;
|
|
638
|
+
if (self.__childrenArr !== undefined && self.__childrenArrV === v) return self.__childrenArr;
|
|
639
|
+
self.__childrenArrV = v;
|
|
640
|
+
return (self.__childrenArr = self.__children().filter((n) => n.nodeType === ELEMENT_NODE));
|
|
641
|
+
}));
|
|
634
642
|
}
|
|
635
643
|
get childElementCount() { return this.__children().filter((n) => n.nodeType === ELEMENT_NODE).length; }
|
|
636
644
|
get firstElementChild() { return this.__children().find((n) => n.nodeType === ELEMENT_NODE) ?? null; }
|
package/src/runtime/index.mjs
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { createRequire } from 'node:module';
|
|
10
10
|
import { Document } from './dom.mjs';
|
|
11
11
|
import { createWindow } from './window.mjs';
|
|
12
|
+
import { unpack } from './buffer.mjs';
|
|
12
13
|
|
|
13
14
|
const require = createRequire(import.meta.url);
|
|
14
15
|
const native = require('../../index.js');
|
|
@@ -33,7 +34,11 @@ function parseBufferCached(html) {
|
|
|
33
34
|
if (html !== __parseCacheMRU) { __parseCache.delete(html); __parseCache.set(html, hit); __parseCacheMRU = html; }
|
|
34
35
|
return hit;
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
let soa = native.parseBuffer(html);
|
|
38
|
+
// Unpack the packed blob into typed-array views ONCE here, not per Document in
|
|
39
|
+
// every Buffer ctor — the views are read-only over the shared immutable buffer,
|
|
40
|
+
// so all Documents backed by this cached soa reuse them (no re-unpack per file).
|
|
41
|
+
if (soa.packed) soa = unpack(soa);
|
|
37
42
|
// Evict the single oldest entry, not the whole cache — a suite with >64 distinct
|
|
38
43
|
// shells should keep its hot fixtures warm, not thrash every one cold on overflow.
|
|
39
44
|
if (__parseCache.size >= __PARSE_CACHE_MAX) __parseCache.delete(__parseCache.keys().next().value);
|
|
Binary file
|