@miaskiewicz/turbo-dom 0.1.7 → 0.1.8

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.7",
3
+ "version": "0.1.8",
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",
@@ -807,35 +807,42 @@ export class XMLSerializer {
807
807
 
808
808
  // minimal inline-style CSSOM (honest: only inline + explicitly set props)
809
809
  function makeStyle(el) {
810
+ // parse → { values: Map<prop,value>, prio: Map<prop,'important'|''> } (handles !important)
810
811
  const parse = () => {
811
- const map = new Map();
812
+ const values = new Map();
813
+ const prio = new Map();
812
814
  for (const decl of (el.getAttribute('style') || '').split(';')) {
813
815
  const i = decl.indexOf(':');
814
816
  if (i === -1) continue;
815
817
  const prop = decl.slice(0, i).trim();
816
- const val = decl.slice(i + 1).trim();
817
- if (prop) map.set(prop, val);
818
+ let val = decl.slice(i + 1).trim();
819
+ if (!prop) continue;
820
+ const m = /\s*!\s*important\s*$/i.exec(val);
821
+ if (m) { val = val.slice(0, m.index).trim(); prio.set(prop, 'important'); }
822
+ values.set(prop, val);
818
823
  }
819
- return map;
824
+ return { values, prio };
825
+ };
826
+ const write = ({ values, prio }) => {
827
+ el.setAttribute('style', [...values].map(([k, v]) => `${k}: ${v}${prio.get(k) === 'important' ? ' !important' : ''}`).join('; '));
820
828
  };
821
- const write = (map) => el.setAttribute('style', [...map].map(([k, v]) => `${k}: ${v}`).join('; '));
822
829
  return new Proxy({}, {
823
830
  get(_t, key) {
824
- if (key === 'getPropertyValue') return (p) => parse().get(p) ?? '';
825
- if (key === 'getPropertyPriority') return () => ''; // we don't model !important
826
- if (key === 'setProperty') return (p, v) => { const m = parse(); m.set(p, v); write(m); };
827
- if (key === 'removeProperty') return (p) => { const m = parse(); const v = m.get(p) ?? ''; m.delete(p); write(m); return v; };
828
- if (key === 'item') return (i) => [...parse().keys()][i] ?? '';
829
- if (key === 'length') return parse().size;
831
+ if (key === 'getPropertyValue') return (p) => parse().values.get(p) ?? '';
832
+ if (key === 'getPropertyPriority') return (p) => parse().prio.get(p) ?? '';
833
+ if (key === 'setProperty') return (p, v, priority) => { const s = parse(); s.values.set(p, String(v)); if (priority) s.prio.set(p, 'important'); else s.prio.delete(p); write(s); };
834
+ if (key === 'removeProperty') return (p) => { const s = parse(); const v = s.values.get(p) ?? ''; s.values.delete(p); s.prio.delete(p); write(s); return v; };
835
+ if (key === 'item') return (i) => [...parse().values.keys()][i] ?? '';
836
+ if (key === 'length') return parse().values.size;
830
837
  if (key === 'cssText') return el.getAttribute('style') || '';
831
- if (key === 'cssFloat') return parse().get('float') ?? '';
832
- if (key === Symbol.iterator) { const keys = [...parse().keys()]; return keys[Symbol.iterator].bind(keys); }
838
+ if (key === 'cssFloat') return parse().values.get('float') ?? '';
839
+ if (key === Symbol.iterator) { const keys = [...parse().values.keys()]; return keys[Symbol.iterator].bind(keys); }
833
840
  if (typeof key !== 'string') return undefined;
834
- return parse().get(kebab(key)) ?? '';
841
+ return parse().values.get(kebab(key)) ?? '';
835
842
  },
836
843
  set(_t, key, value) {
837
844
  if (key === 'cssText') { el.setAttribute('style', String(value)); return true; }
838
- const m = parse(); m.set(kebab(key), String(value)); write(m); return true;
845
+ const s = parse(); s.values.set(kebab(key), String(value)); write(s); return true;
839
846
  },
840
847
  has(_t, key) { return typeof key === 'string'; },
841
848
  });
@@ -102,6 +102,9 @@ export function createWindow(document, { url = 'http://localhost/' } = {}) {
102
102
  structuredClone: (...a) => hostStructuredClone(...a),
103
103
  getSelection: () => document.getSelection(),
104
104
  scrollTo() {}, scroll() {}, scrollBy() {},
105
+ // window methods libraries/tests spy on — must exist as own props for vi.spyOn
106
+ open: () => null, close() {}, stop() {}, print() {}, focus() {}, blur() {},
107
+ moveTo() {}, moveBy() {}, resizeTo() {}, resizeBy() {},
105
108
  alert() {}, confirm: () => false, prompt: () => null,
106
109
  dispatchEvent: (e) => document.dispatchEvent(e),
107
110
  addEventListener: (...a) => document.addEventListener(...a),