@miaskiewicz/turbo-dom 0.1.13 → 0.1.15

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.13",
3
+ "version": "0.1.15",
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",
@@ -545,7 +545,15 @@ export class Element extends Node {
545
545
  return el;
546
546
  }
547
547
 
548
- click() { this.dispatchEvent(new Event('click', { bubbles: true, cancelable: true })); }
548
+ click() {
549
+ // WHATWG "click in progress" flag: a nested .click() on the same element
550
+ // (e.g. a parent onClick that re-clicks this element on the bubble path) is
551
+ // a no-op, which breaks the otherwise-infinite re-entrancy.
552
+ if (this.__clickInProgress) return;
553
+ this.__clickInProgress = true;
554
+ try { this.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, detail: 1 })); }
555
+ finally { this.__clickInProgress = false; }
556
+ }
549
557
  // pre-click activation (runs BEFORE click listeners; undone if preventDefault)
550
558
  __preClickActivation() {
551
559
  if (this.localName !== 'input') return null;
@@ -1162,8 +1170,29 @@ export class Document extends Node {
1162
1170
  getElementsByClassName(cls) { const self = this; const classes = cls.split(/\s+/).filter(Boolean); return liveHTMLCollection(() => collectByClass(self, classes)); }
1163
1171
  contains(node) { return Node.prototype.contains.call(this, node); }
1164
1172
 
1165
- get cookie() { return this.__cookie || ''; }
1166
- set cookie(v) { this.__cookie = (this.__cookie ? this.__cookie + '; ' : '') + v; }
1173
+ // cookie jar: store name=value, strip attributes (path/Secure/SameSite/…),
1174
+ // dedupe by name, honor deletion via max-age<=0 or a past expires.
1175
+ get cookie() {
1176
+ if (!this.__cookieJar) return '';
1177
+ return [...this.__cookieJar].map(([k, v]) => `${k}=${v}`).join('; ');
1178
+ }
1179
+ set cookie(str) {
1180
+ if (!this.__cookieJar) this.__cookieJar = new Map();
1181
+ const parts = String(str).split(';');
1182
+ const pair = parts.shift();
1183
+ const eq = pair.indexOf('=');
1184
+ if (eq === -1) return;
1185
+ const name = pair.slice(0, eq).trim();
1186
+ if (!name) return;
1187
+ const value = pair.slice(eq + 1).trim();
1188
+ const attrs = parts.map((a) => a.trim().toLowerCase());
1189
+ const maxAge = attrs.find((a) => a.startsWith('max-age='));
1190
+ const expires = attrs.find((a) => a.startsWith('expires='));
1191
+ const deleted = (maxAge && parseInt(maxAge.slice(8), 10) <= 0) ||
1192
+ (expires && new Date(expires.slice(8)).getTime() <= Date.now());
1193
+ if (deleted) this.__cookieJar.delete(name);
1194
+ else this.__cookieJar.set(name, value);
1195
+ }
1167
1196
 
1168
1197
  // document state (honest defaults for a headless, focused, loaded page)
1169
1198
  get visibilityState() { return 'visible'; }
@@ -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.__cookie = '';
43
+ document.__cookieJar = null;
44
44
  },
45
45
  };
46
46
  }