@zumer/snapdom 1.9.5 → 1.9.6-dev.0

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/dist/snapdom.js CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  /*
3
3
  * snapdom
4
- * v.1.9.5
4
+ * v.1.9.6-dev.0
5
5
  * Author Juan Martin Muda
6
6
  * License MIT
7
7
  **/
@@ -57,13 +57,29 @@
57
57
  };
58
58
 
59
59
  // src/core/cache.js
60
- var imageCache = /* @__PURE__ */ new Map();
61
- var bgCache = /* @__PURE__ */ new Map();
62
- var resourceCache = /* @__PURE__ */ new Map();
63
- var defaultStylesCache = /* @__PURE__ */ new Map();
64
- var baseCSSCache = /* @__PURE__ */ new Map();
65
- var computedStyleCache = /* @__PURE__ */ new WeakMap();
66
- var processedFontURLs = /* @__PURE__ */ new Set();
60
+ var cache = {
61
+ image: /* @__PURE__ */ new Map(),
62
+ background: /* @__PURE__ */ new Map(),
63
+ resource: /* @__PURE__ */ new Map(),
64
+ defaultStyle: /* @__PURE__ */ new Map(),
65
+ baseStyle: /* @__PURE__ */ new Map(),
66
+ computedStyle: /* @__PURE__ */ new WeakMap(),
67
+ font: /* @__PURE__ */ new Set(),
68
+ snapshot: /* @__PURE__ */ new WeakMap(),
69
+ snapshotKey: /* @__PURE__ */ new Map(),
70
+ preStyleMap: /* @__PURE__ */ new Map(),
71
+ preStyle: /* @__PURE__ */ new WeakMap(),
72
+ preNodeMap: /* @__PURE__ */ new Map(),
73
+ reset: resetCache
74
+ };
75
+ function resetCache() {
76
+ cache.computedStyle = /* @__PURE__ */ new WeakMap();
77
+ cache.snapshot = /* @__PURE__ */ new WeakMap();
78
+ cache.snapshotKey.clear();
79
+ cache.preStyleMap.clear();
80
+ cache.preStyle = /* @__PURE__ */ new WeakMap();
81
+ cache.preNodeMap.clear();
82
+ }
67
83
 
68
84
  // src/utils/cssTools.js
69
85
  var commonTags = [
@@ -111,13 +127,13 @@
111
127
  }
112
128
  }
113
129
  function getDefaultStyleForTag(tagName) {
114
- if (defaultStylesCache.has(tagName)) {
115
- return defaultStylesCache.get(tagName);
130
+ if (cache.defaultStyle.has(tagName)) {
131
+ return cache.defaultStyle.get(tagName);
116
132
  }
117
133
  const skipTags = /* @__PURE__ */ new Set(["script", "style", "meta", "link", "noscript", "template"]);
118
134
  if (skipTags.has(tagName)) {
119
135
  const empty = {};
120
- defaultStylesCache.set(tagName, empty);
136
+ cache.defaultStyle.set(tagName, empty);
121
137
  return empty;
122
138
  }
123
139
  let sandbox = document.getElementById("snapdom-sandbox");
@@ -141,7 +157,7 @@
141
157
  defaults[prop] = styles.getPropertyValue(prop);
142
158
  }
143
159
  sandbox.removeChild(el);
144
- defaultStylesCache.set(tagName, defaults);
160
+ cache.defaultStyle.set(tagName, defaults);
145
161
  return defaults;
146
162
  }
147
163
  function getStyleKey(snapshot, tagName, compress = false) {
@@ -177,7 +193,7 @@
177
193
  function generateDedupedBaseCSS(usedTagNames) {
178
194
  const groups = /* @__PURE__ */ new Map();
179
195
  for (let tagName of usedTagNames) {
180
- const styles = defaultStylesCache.get(tagName);
196
+ const styles = cache.defaultStyle.get(tagName);
181
197
  if (!styles) continue;
182
198
  const key = Object.entries(styles).map(([k, v]) => `${k}:${v};`).sort().join("");
183
199
  if (!groups.has(key)) {
@@ -192,8 +208,8 @@
192
208
  }
193
209
  return css;
194
210
  }
195
- function generateCSSClasses(styleMap) {
196
- const keySet = new Set(styleMap.values());
211
+ function generateCSSClasses() {
212
+ const keySet = new Set(cache.preStyleMap.values());
197
213
  const classMap = /* @__PURE__ */ new Map();
198
214
  let counter = 1;
199
215
  for (const key of keySet) {
@@ -205,16 +221,15 @@
205
221
  // src/utils/helpers.js
206
222
  function inlineSingleBackgroundEntry(_0) {
207
223
  return __async(this, arguments, function* (entry, options = {}) {
208
- const match = entry.match(/url\(["']?(.*?)["']?\)/);
209
- const rawUrl = match == null ? void 0 : match[1];
224
+ const rawUrl = extractURL(entry);
210
225
  const isGradient = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(entry);
211
226
  if (rawUrl) {
212
227
  const encodedUrl = safeEncodeURI(rawUrl);
213
- if (bgCache.has(encodedUrl)) {
214
- return options.skipInline ? void 0 : `url(${bgCache.get(encodedUrl)})`;
228
+ if (cache.background.has(encodedUrl)) {
229
+ return options.skipInline ? void 0 : `url(${cache.background.get(encodedUrl)})`;
215
230
  } else {
216
231
  const dataUrl = yield fetchImage(encodedUrl, { useProxy: options.useProxy });
217
- bgCache.set(encodedUrl, dataUrl);
232
+ cache.background.set(encodedUrl, dataUrl);
218
233
  return options.skipInline ? void 0 : `url("${dataUrl}")`;
219
234
  }
220
235
  }
@@ -236,10 +251,10 @@
236
251
  if (!(el instanceof Element)) {
237
252
  return window.getComputedStyle(el, pseudo);
238
253
  }
239
- let map = computedStyleCache.get(el);
254
+ let map = cache.computedStyle.get(el);
240
255
  if (!map) {
241
256
  map = /* @__PURE__ */ new Map();
242
- computedStyleCache.set(el, map);
257
+ cache.computedStyle.set(el, map);
243
258
  }
244
259
  if (!map.has(pseudo)) {
245
260
  const st = window.getComputedStyle(el, pseudo);
@@ -315,13 +330,13 @@
315
330
  }
316
331
  const crossOriginValue = getCrossOriginMode(src);
317
332
  console.log(`[SnapDOM - fetchImage] Start loading image: ${src} with crossOrigin=${crossOriginValue}`);
318
- if (imageCache.has(src)) {
333
+ if (cache.image.has(src)) {
319
334
  console.log(`[SnapDOM - fetchImage] Cache hit for: ${src}`);
320
- return Promise.resolve(imageCache.get(src));
335
+ return Promise.resolve(cache.image.get(src));
321
336
  }
322
337
  const isDataURI = src.startsWith("data:image/");
323
338
  if (isDataURI) {
324
- imageCache.set(src, src);
339
+ cache.image.set(src, src);
325
340
  return Promise.resolve(src);
326
341
  }
327
342
  const isSVG = /\.svg(\?.*)?$/i.test(src);
@@ -334,7 +349,7 @@
334
349
  });
335
350
  const svgText = yield response.text();
336
351
  const encoded = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgText)}`;
337
- imageCache.set(src, encoded);
352
+ cache.image.set(src, encoded);
338
353
  return encoded;
339
354
  } catch (e) {
340
355
  return fetchWithFallback(src);
@@ -358,12 +373,12 @@
358
373
  const ctx = canvas.getContext("2d");
359
374
  ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
360
375
  const dataURL = canvas.toDataURL("image/png");
361
- imageCache.set(src, dataURL);
376
+ cache.image.set(src, dataURL);
362
377
  resolve(dataURL);
363
378
  } catch (e) {
364
379
  try {
365
380
  const fallbackDataURL = yield fetchWithFallback(src);
366
- imageCache.set(src, fallbackDataURL);
381
+ cache.image.set(src, fallbackDataURL);
367
382
  resolve(fallbackDataURL);
368
383
  } catch (e2) {
369
384
  reject(e2);
@@ -375,7 +390,7 @@
375
390
  console.error(`[SnapDOM - fetchImage] Image failed to load: ${src}`);
376
391
  try {
377
392
  const fallbackDataURL = yield fetchWithFallback(src);
378
- imageCache.set(src, fallbackDataURL);
393
+ cache.image.set(src, fallbackDataURL);
379
394
  resolve(fallbackDataURL);
380
395
  } catch (e) {
381
396
  reject(e);
@@ -439,8 +454,6 @@
439
454
  }
440
455
 
441
456
  // src/modules/styles.js
442
- var snapshotCache = /* @__PURE__ */ new WeakMap();
443
- var snapshotKeyCache = /* @__PURE__ */ new Map();
444
457
  function snapshotComputedStyleFull(style) {
445
458
  const result = {};
446
459
  for (let i = 0; i < style.length; i++) {
@@ -453,34 +466,34 @@
453
466
  }
454
467
  return result;
455
468
  }
456
- function inlineAllStyles(source, clone, styleMap, cache, compress) {
469
+ function inlineAllStyles(source, clone, compress) {
457
470
  var _a;
458
471
  if (source.tagName === "STYLE") return;
459
- if (!cache.has(source)) {
460
- cache.set(source, getStyle(source));
472
+ if (!cache.preStyle.has(source)) {
473
+ cache.preStyle.set(source, getStyle(source));
461
474
  }
462
- const style = cache.get(source);
463
- if (!snapshotCache.has(source)) {
475
+ const style = cache.preStyle.get(source);
476
+ if (!cache.snapshot.has(source)) {
464
477
  const snapshot2 = snapshotComputedStyleFull(style);
465
- snapshotCache.set(source, snapshot2);
478
+ cache.snapshot.set(source, snapshot2);
466
479
  }
467
- const snapshot = snapshotCache.get(source);
480
+ const snapshot = cache.snapshot.get(source);
468
481
  const hash = Object.entries(snapshot).sort(([a], [b]) => a.localeCompare(b)).map(([prop, val]) => `${prop}:${val}`).join(";");
469
- if (snapshotKeyCache.has(hash)) {
470
- styleMap.set(clone, snapshotKeyCache.get(hash));
482
+ if (cache.snapshotKey.has(hash)) {
483
+ cache.preStyleMap.set(clone, cache.snapshotKey.get(hash));
471
484
  return;
472
485
  }
473
486
  const tagName = ((_a = source.tagName) == null ? void 0 : _a.toLowerCase()) || "div";
474
487
  const key = getStyleKey(snapshot, tagName, compress);
475
- snapshotKeyCache.set(hash, key);
476
- styleMap.set(clone, key);
488
+ cache.snapshotKey.set(hash, key);
489
+ cache.preStyleMap.set(clone, key);
477
490
  }
478
491
 
479
492
  // src/core/clone.js
480
493
  function isSlotElement(node) {
481
494
  return node.nodeType === Node.ELEMENT_NODE && node.tagName === "SLOT";
482
495
  }
483
- function deepClone(node, styleMap, styleCache, nodeMap, compress, options = {}, originalRoot) {
496
+ function deepClone(node, compress, options = {}, originalRoot) {
484
497
  var _a, _b;
485
498
  if (node.nodeType === Node.TEXT_NODE) {
486
499
  return node.cloneNode(true);
@@ -526,8 +539,8 @@
526
539
  }
527
540
  if (node.getAttribute("data-capture") === "placeholder") {
528
541
  const clone2 = node.cloneNode(false);
529
- nodeMap.set(clone2, node);
530
- inlineAllStyles(node, clone2, styleMap, styleCache, compress);
542
+ cache.preNodeMap.set(clone2, node);
543
+ inlineAllStyles(node, clone2, compress);
531
544
  const placeholder = document.createElement("div");
532
545
  placeholder.textContent = node.getAttribute("data-placeholder-text") || "";
533
546
  placeholder.style.cssText = `color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;`;
@@ -546,7 +559,7 @@
546
559
  return img;
547
560
  }
548
561
  const clone = node.cloneNode(false);
549
- nodeMap.set(clone, node);
562
+ cache.preNodeMap.set(clone, node);
550
563
  if (node instanceof HTMLInputElement) {
551
564
  clone.value = node.value;
552
565
  clone.setAttribute("value", node.value);
@@ -569,13 +582,13 @@
569
582
  }
570
583
  });
571
584
  }
572
- inlineAllStyles(node, clone, styleMap, styleCache, compress);
585
+ inlineAllStyles(node, clone, compress);
573
586
  if (isSlotElement(node)) {
574
587
  const assigned = ((_b = node.assignedNodes) == null ? void 0 : _b.call(node, { flatten: true })) || [];
575
588
  const nodesToClone = assigned.length > 0 ? assigned : Array.from(node.childNodes);
576
589
  const fragment = document.createDocumentFragment();
577
590
  for (const child of nodesToClone) {
578
- const clonedChild = deepClone(child, styleMap, styleCache, nodeMap, compress, options, originalRoot || node);
591
+ const clonedChild = deepClone(child, compress, options, originalRoot || node);
579
592
  if (clonedChild) fragment.appendChild(clonedChild);
580
593
  }
581
594
  return fragment;
@@ -583,13 +596,13 @@
583
596
  } else {
584
597
  const baseChildren = node.shadowRoot ? node.shadowRoot.childNodes : node.childNodes;
585
598
  for (const child of baseChildren) {
586
- const clonedChild = deepClone(child, styleMap, styleCache, nodeMap, compress, options, originalRoot || node);
599
+ const clonedChild = deepClone(child, compress, options, originalRoot || node);
587
600
  if (clonedChild) clone.appendChild(clonedChild);
588
601
  }
589
602
  if (node.shadowRoot && node.childNodes.length > 0 && !node.shadowRoot.querySelector("slot")) {
590
603
  const lightDomContent = document.createDocumentFragment();
591
604
  for (const child of node.childNodes) {
592
- const clonedChild = deepClone(child, styleMap, styleCache, nodeMap, compress, options, originalRoot || node);
605
+ const clonedChild = deepClone(child, compress, options, originalRoot || node);
593
606
  if (clonedChild) lightDomContent.appendChild(clonedChild);
594
607
  }
595
608
  clone.appendChild(lightDomContent);
@@ -678,14 +691,14 @@
678
691
  }
679
692
  function embedCustomFonts() {
680
693
  return __async(this, arguments, function* ({ preCached = false } = {}) {
681
- if (resourceCache.has("fonts-embed-css")) {
694
+ if (cache.resource.has("fonts-embed-css")) {
682
695
  if (preCached) {
683
696
  const style = document.createElement("style");
684
697
  style.setAttribute("data-snapdom", "embedFonts");
685
- style.textContent = resourceCache.get("fonts-embed-css");
698
+ style.textContent = cache.resource.get("fonts-embed-css");
686
699
  document.head.appendChild(style);
687
700
  }
688
- return resourceCache.get("fonts-embed-css");
701
+ return cache.resource.get("fonts-embed-css");
689
702
  }
690
703
  const importRegex = /@import\s+url\(["']?([^"')]+)["']?\)/g;
691
704
  const styleImports = [];
@@ -718,11 +731,11 @@
718
731
  url = new URL(url, link.href).href;
719
732
  }
720
733
  if (isIconFont(url)) return null;
721
- if (resourceCache.has(url)) {
722
- processedFontURLs.add(url);
723
- return { original: match[0], inlined: `url(${resourceCache.get(url)})` };
734
+ if (cache.resource.has(url)) {
735
+ cache.font.add(url);
736
+ return { original: match[0], inlined: `url(${cache.resource.get(url)})` };
724
737
  }
725
- if (processedFontURLs.has(url)) return null;
738
+ if (cache.font.has(url)) return null;
726
739
  try {
727
740
  const fontRes = yield fetch(url);
728
741
  const blob = yield fontRes.blob();
@@ -731,8 +744,8 @@
731
744
  reader.onload = () => resolve(reader.result);
732
745
  reader.readAsDataURL(blob);
733
746
  });
734
- resourceCache.set(url, b64);
735
- processedFontURLs.add(url);
747
+ cache.resource.set(url, b64);
748
+ cache.font.add(url);
736
749
  return { original: match[0], inlined: `url(${b64})` };
737
750
  } catch (e) {
738
751
  console.warn("[snapdom] Failed to fetch font resource:", url);
@@ -768,12 +781,12 @@
768
781
  url = new URL(url, sheet.href || location.href).href;
769
782
  }
770
783
  if (isIconFont(url)) continue;
771
- if (resourceCache.has(url)) {
772
- processedFontURLs.add(url);
773
- inlinedSrc = inlinedSrc.replace(match[0], `url(${resourceCache.get(url)})`);
784
+ if (cache.resource.has(url)) {
785
+ cache.font.add(url);
786
+ inlinedSrc = inlinedSrc.replace(match[0], `url(${cache.resource.get(url)})`);
774
787
  continue;
775
788
  }
776
- if (processedFontURLs.has(url)) continue;
789
+ if (cache.font.has(url)) continue;
777
790
  try {
778
791
  const res = yield fetch(url);
779
792
  const blob = yield res.blob();
@@ -782,8 +795,8 @@
782
795
  reader.onload = () => resolve(reader.result);
783
796
  reader.readAsDataURL(blob);
784
797
  });
785
- resourceCache.set(url, b64);
786
- processedFontURLs.add(url);
798
+ cache.resource.set(url, b64);
799
+ cache.font.add(url);
787
800
  inlinedSrc = inlinedSrc.replace(match[0], `url(${b64})`);
788
801
  } catch (e) {
789
802
  console.warn("[snapdom] Failed to fetch font URL:", url);
@@ -808,10 +821,10 @@
808
821
  if (isIconFont(font.family)) continue;
809
822
  let b64 = font._snapdomSrc;
810
823
  if (!b64.startsWith("data:")) {
811
- if (resourceCache.has(font._snapdomSrc)) {
812
- b64 = resourceCache.get(font._snapdomSrc);
813
- processedFontURLs.add(font._snapdomSrc);
814
- } else if (!processedFontURLs.has(font._snapdomSrc)) {
824
+ if (cache.resource.has(font._snapdomSrc)) {
825
+ b64 = cache.resource.get(font._snapdomSrc);
826
+ cache.font.add(font._snapdomSrc);
827
+ } else if (!cache.font.has(font._snapdomSrc)) {
815
828
  try {
816
829
  const res = yield fetch(font._snapdomSrc);
817
830
  const blob = yield res.blob();
@@ -820,8 +833,8 @@
820
833
  reader.onload = () => resolve(reader.result);
821
834
  reader.readAsDataURL(blob);
822
835
  });
823
- resourceCache.set(font._snapdomSrc, b64);
824
- processedFontURLs.add(font._snapdomSrc);
836
+ cache.resource.set(font._snapdomSrc, b64);
837
+ cache.font.add(font._snapdomSrc);
825
838
  } catch (e) {
826
839
  console.warn("[snapdom] Failed to fetch dynamic font src:", font._snapdomSrc);
827
840
  continue;
@@ -838,7 +851,7 @@
838
851
  }
839
852
  }
840
853
  if (finalCSS) {
841
- resourceCache.set("fonts-embed-css", finalCSS);
854
+ cache.resource.set("fonts-embed-css", finalCSS);
842
855
  if (preCached) {
843
856
  const style = document.createElement("style");
844
857
  style.setAttribute("data-snapdom", "embedFonts");
@@ -851,7 +864,7 @@
851
864
  }
852
865
 
853
866
  // src/modules/pseudo.js
854
- function inlinePseudoElements(source, clone, styleMap, styleCache, compress, embedFonts = false, useProxy) {
867
+ function inlinePseudoElements(source, clone, compress, embedFonts = false, useProxy) {
855
868
  return __async(this, null, function* () {
856
869
  if (!(source instanceof Element) || !(clone instanceof Element)) return;
857
870
  for (const pseudo of ["::before", "::after", "::first-letter"]) {
@@ -876,7 +889,7 @@
876
889
  span.dataset.snapdomPseudo = "::first-letter";
877
890
  const snapshot = snapshotComputedStyle(style);
878
891
  const key = getStyleKey(snapshot, "span", compress);
879
- styleMap.set(span, key);
892
+ cache.preStyleMap.set(span, key);
880
893
  const restNode = document.createTextNode(rest);
881
894
  clone.replaceChild(restNode, textNode);
882
895
  clone.insertBefore(span, restNode);
@@ -897,7 +910,7 @@
897
910
  pseudoEl.dataset.snapdomPseudo = pseudo;
898
911
  const snapshot = snapshotComputedStyle(style);
899
912
  const key = getStyleKey(snapshot, "span", compress);
900
- styleMap.set(pseudoEl, key);
913
+ cache.preStyleMap.set(pseudoEl, key);
901
914
  const isIconFont2 = isIconFont(fontFamily);
902
915
  const cleanContent = parseContent(content);
903
916
  if (isIconFont2 && cleanContent.length === 1) {
@@ -948,8 +961,6 @@
948
961
  yield inlinePseudoElements(
949
962
  sChildren[i],
950
963
  cChildren[i],
951
- styleMap,
952
- styleCache,
953
964
  compress,
954
965
  embedFonts,
955
966
  useProxy
@@ -992,18 +1003,15 @@
992
1003
  function prepareClone(_0) {
993
1004
  return __async(this, arguments, function* (element, compress = false, embedFonts = false, options = {}) {
994
1005
  var _a;
995
- const styleMap = /* @__PURE__ */ new Map();
996
- const styleCache = /* @__PURE__ */ new WeakMap();
997
- const nodeMap = /* @__PURE__ */ new Map();
998
- let clone;
1006
+ let clone, classCSS;
999
1007
  try {
1000
- clone = deepClone(element, styleMap, styleCache, nodeMap, compress, options, element);
1008
+ clone = deepClone(element, compress, options, element);
1001
1009
  } catch (e) {
1002
1010
  console.warn("deepClone failed:", e);
1003
1011
  throw e;
1004
1012
  }
1005
1013
  try {
1006
- yield inlinePseudoElements(element, clone, styleMap, styleCache, compress, embedFonts, options.useProxy);
1014
+ yield inlinePseudoElements(element, clone, compress, embedFonts, options.useProxy);
1007
1015
  } catch (e) {
1008
1016
  console.warn("inlinePseudoElements failed:", e);
1009
1017
  }
@@ -1012,11 +1020,10 @@
1012
1020
  } catch (e) {
1013
1021
  console.warn("inlineExternalDef failed:", e);
1014
1022
  }
1015
- let classCSS = "";
1016
1023
  if (compress) {
1017
- const keyToClass = generateCSSClasses(styleMap);
1024
+ const keyToClass = generateCSSClasses();
1018
1025
  classCSS = Array.from(keyToClass.entries()).map(([key, className]) => `.${className}{${key}}`).join("");
1019
- for (const [node, key] of styleMap.entries()) {
1026
+ for (const [node, key] of cache.preStyleMap.entries()) {
1020
1027
  if (node.tagName === "STYLE") continue;
1021
1028
  const className = keyToClass.get(key);
1022
1029
  if (className) node.classList.add(className);
@@ -1025,12 +1032,12 @@
1025
1032
  if (bgImage && bgImage !== "none") node.style.backgroundImage = bgImage;
1026
1033
  }
1027
1034
  } else {
1028
- for (const [node, key] of styleMap.entries()) {
1035
+ for (const [node, key] of cache.preStyleMap.entries()) {
1029
1036
  if (node.tagName === "STYLE") continue;
1030
1037
  node.setAttribute("style", key.replace(/;/g, "; "));
1031
1038
  }
1032
1039
  }
1033
- for (const [cloneNode, originalNode] of nodeMap.entries()) {
1040
+ for (const [cloneNode, originalNode] of cache.preNodeMap.entries()) {
1034
1041
  const scrollX = originalNode.scrollLeft;
1035
1042
  const scrollY = originalNode.scrollTop;
1036
1043
  const hasScroll = scrollX || scrollY;
@@ -1049,9 +1056,9 @@
1049
1056
  cloneNode.appendChild(inner);
1050
1057
  }
1051
1058
  }
1052
- if (element === nodeMap.get(clone)) {
1053
- const computed = styleCache.get(element) || window.getComputedStyle(element);
1054
- styleCache.set(element, computed);
1059
+ if (element === cache.preNodeMap.get(clone)) {
1060
+ const computed = cache.preStyle.get(element) || window.getComputedStyle(element);
1061
+ cache.preStyle.set(element, computed);
1055
1062
  const transform = stripTranslate(computed.transform);
1056
1063
  clone.style.margin = "0";
1057
1064
  clone.style.position = "static";
@@ -1064,13 +1071,13 @@
1064
1071
  clone.style.clear = "none";
1065
1072
  clone.style.transform = transform || "";
1066
1073
  }
1067
- for (const [cloneNode, originalNode] of nodeMap.entries()) {
1074
+ for (const [cloneNode, originalNode] of cache.preNodeMap.entries()) {
1068
1075
  if (originalNode.tagName === "PRE") {
1069
1076
  cloneNode.style.marginTop = "0";
1070
1077
  cloneNode.style.marginBlockStart = "0";
1071
1078
  }
1072
1079
  }
1073
- return { clone, classCSS, styleCache };
1080
+ return { clone, classCSS };
1074
1081
  });
1075
1082
  }
1076
1083
 
@@ -1100,8 +1107,8 @@
1100
1107
  }
1101
1108
 
1102
1109
  // src/modules/background.js
1103
- function inlineBackgroundImages(_0, _1, _2) {
1104
- return __async(this, arguments, function* (source, clone, styleCache, options = {}) {
1110
+ function inlineBackgroundImages(_0, _1) {
1111
+ return __async(this, arguments, function* (source, clone, options = {}) {
1105
1112
  const queue = [[source, clone]];
1106
1113
  const imageProps = [
1107
1114
  "background-image",
@@ -1115,8 +1122,8 @@
1115
1122
  ];
1116
1123
  while (queue.length) {
1117
1124
  const [srcNode, cloneNode] = queue.shift();
1118
- const style = styleCache.get(srcNode) || getStyle(srcNode);
1119
- if (!styleCache.has(srcNode)) styleCache.set(srcNode, style);
1125
+ const style = cache.preStyle.get(srcNode) || getStyle(srcNode);
1126
+ if (!cache.preStyle.has(srcNode)) cache.preStyle.set(srcNode, style);
1120
1127
  for (const prop of imageProps) {
1121
1128
  const val = style.getPropertyValue(prop);
1122
1129
  if (!val || val === "none") continue;
@@ -1145,13 +1152,14 @@
1145
1152
  function captureDOM(_0) {
1146
1153
  return __async(this, arguments, function* (element, options = {}) {
1147
1154
  if (!element) throw new Error("Element cannot be null or undefined");
1155
+ cache.reset();
1148
1156
  const { compress = true, embedFonts = false, fast = true, scale = 1, useProxy = "" } = options;
1149
- let clone, classCSS, styleCache;
1157
+ let clone, classCSS;
1150
1158
  let fontsCSS = "";
1151
1159
  let baseCSS = "";
1152
1160
  let dataURL;
1153
1161
  let svgString;
1154
- ({ clone, classCSS, styleCache } = yield prepareClone(element, compress, embedFonts, options));
1162
+ ({ clone, classCSS } = yield prepareClone(element, compress, embedFonts, options));
1155
1163
  yield new Promise((resolve) => {
1156
1164
  idle(() => __async(null, null, function* () {
1157
1165
  yield inlineImages(clone, options);
@@ -1160,7 +1168,7 @@
1160
1168
  });
1161
1169
  yield new Promise((resolve) => {
1162
1170
  idle(() => __async(null, null, function* () {
1163
- yield inlineBackgroundImages(element, clone, styleCache, options);
1171
+ yield inlineBackgroundImages(element, clone, options);
1164
1172
  resolve();
1165
1173
  }), { fast });
1166
1174
  });
@@ -1175,13 +1183,13 @@
1175
1183
  if (compress) {
1176
1184
  const usedTags = collectUsedTagNames(clone).sort();
1177
1185
  const tagKey = usedTags.join(",");
1178
- if (baseCSSCache.has(tagKey)) {
1179
- baseCSS = baseCSSCache.get(tagKey);
1186
+ if (cache.baseStyle.has(tagKey)) {
1187
+ baseCSS = cache.baseStyle.get(tagKey);
1180
1188
  } else {
1181
1189
  yield new Promise((resolve) => {
1182
1190
  idle(() => {
1183
1191
  baseCSS = generateDedupedBaseCSS(usedTags);
1184
- baseCSSCache.set(tagKey, baseCSS);
1192
+ cache.baseStyle.set(tagKey, baseCSS);
1185
1193
  resolve();
1186
1194
  }, { fast });
1187
1195
  });
@@ -1423,10 +1431,7 @@
1423
1431
  return __async(this, arguments, function* (root = document, options = {}) {
1424
1432
  const { embedFonts = true, reset = false } = options;
1425
1433
  if (reset) {
1426
- imageCache.clear();
1427
- bgCache.clear();
1428
- resourceCache.clear();
1429
- baseCSSCache.clear();
1434
+ cache.reset();
1430
1435
  return;
1431
1436
  }
1432
1437
  yield document.fonts.ready;
@@ -1439,9 +1444,9 @@
1439
1444
  const promises = [];
1440
1445
  for (const img of imgEls) {
1441
1446
  const src = img.src;
1442
- if (!imageCache.has(src)) {
1447
+ if (!cache.image.has(src)) {
1443
1448
  promises.push(
1444
- fetchImage(src, { useProxy: options.useProxy }).then((dataURL) => imageCache.set(src, dataURL)).catch(() => {
1449
+ fetchImage(src, { useProxy: options.useProxy }).then((dataURL) => cache.image.set(src, dataURL)).catch(() => {
1445
1450
  })
1446
1451
  );
1447
1452
  }