@miaskiewicz/turbo-dom 0.1.12 → 0.1.14
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.14",
|
|
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
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
package/src/runtime/dom.mjs
CHANGED
|
@@ -1162,8 +1162,29 @@ export class Document extends Node {
|
|
|
1162
1162
|
getElementsByClassName(cls) { const self = this; const classes = cls.split(/\s+/).filter(Boolean); return liveHTMLCollection(() => collectByClass(self, classes)); }
|
|
1163
1163
|
contains(node) { return Node.prototype.contains.call(this, node); }
|
|
1164
1164
|
|
|
1165
|
-
|
|
1166
|
-
|
|
1165
|
+
// cookie jar: store name=value, strip attributes (path/Secure/SameSite/…),
|
|
1166
|
+
// dedupe by name, honor deletion via max-age<=0 or a past expires.
|
|
1167
|
+
get cookie() {
|
|
1168
|
+
if (!this.__cookieJar) return '';
|
|
1169
|
+
return [...this.__cookieJar].map(([k, v]) => `${k}=${v}`).join('; ');
|
|
1170
|
+
}
|
|
1171
|
+
set cookie(str) {
|
|
1172
|
+
if (!this.__cookieJar) this.__cookieJar = new Map();
|
|
1173
|
+
const parts = String(str).split(';');
|
|
1174
|
+
const pair = parts.shift();
|
|
1175
|
+
const eq = pair.indexOf('=');
|
|
1176
|
+
if (eq === -1) return;
|
|
1177
|
+
const name = pair.slice(0, eq).trim();
|
|
1178
|
+
if (!name) return;
|
|
1179
|
+
const value = pair.slice(eq + 1).trim();
|
|
1180
|
+
const attrs = parts.map((a) => a.trim().toLowerCase());
|
|
1181
|
+
const maxAge = attrs.find((a) => a.startsWith('max-age='));
|
|
1182
|
+
const expires = attrs.find((a) => a.startsWith('expires='));
|
|
1183
|
+
const deleted = (maxAge && parseInt(maxAge.slice(8), 10) <= 0) ||
|
|
1184
|
+
(expires && new Date(expires.slice(8)).getTime() <= Date.now());
|
|
1185
|
+
if (deleted) this.__cookieJar.delete(name);
|
|
1186
|
+
else this.__cookieJar.set(name, value);
|
|
1187
|
+
}
|
|
1167
1188
|
|
|
1168
1189
|
// document state (honest defaults for a headless, focused, loaded page)
|
|
1169
1190
|
get visibilityState() { return 'visible'; }
|
package/src/runtime/index.mjs
CHANGED
|
@@ -40,7 +40,7 @@ export function createEnvironment(html = '<!doctype html><html><head></head><bod
|
|
|
40
40
|
document.__load(soa); // drops __cache + __kids overlay, keeps the buffer if reused
|
|
41
41
|
win.resetGlobals();
|
|
42
42
|
document.__active = null;
|
|
43
|
-
document.
|
|
43
|
+
document.__cookieJar = null;
|
|
44
44
|
},
|
|
45
45
|
};
|
|
46
46
|
}
|
package/src/runtime/window.mjs
CHANGED
|
@@ -64,6 +64,10 @@ class TurboFormData {
|
|
|
64
64
|
function tagClass(matcher) {
|
|
65
65
|
const test = typeof matcher === 'string' ? (n) => n === matcher : (n) => matcher.test(n);
|
|
66
66
|
const C = function () { throw new TypeError('Illegal constructor'); };
|
|
67
|
+
// share Element.prototype so prototype-level spies/reads resolve (e.g.
|
|
68
|
+
// vi.spyOn(HTMLAnchorElement.prototype, 'click')); instanceof is decided by
|
|
69
|
+
// the tag matcher below, not the prototype chain.
|
|
70
|
+
C.prototype = Element.prototype;
|
|
67
71
|
Object.defineProperty(C, Symbol.hasInstance, {
|
|
68
72
|
value: (o) => o != null && o.nodeType === 1 && test(o.localName),
|
|
69
73
|
});
|
|
Binary file
|