likec4 1.36.0 → 1.37.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.
@@ -22,10 +22,6 @@ function toArray(arrayLike) {
22
22
  arr.push(arrayLike[i]);
23
23
  return arr;
24
24
  }
25
- let styleProps = null;
26
- function getStyleProperties(options = {}) {
27
- return styleProps || (options.includeStyleProperties ? (styleProps = options.includeStyleProperties, styleProps) : (styleProps = toArray(window.getComputedStyle(document.documentElement)), styleProps));
28
- }
29
25
  function px(node, styleProperty) {
30
26
  const val = (node.ownerDocument.defaultView || window).getComputedStyle(node).getPropertyValue(styleProperty);
31
27
  return val ? parseFloat(val.replace("px", "")) : 0;
@@ -70,11 +66,7 @@ function canvasToBlob(canvas, options = {}) {
70
66
  function createImage(url) {
71
67
  return new Promise((resolve, reject) => {
72
68
  const img = new Image();
73
- img.onload = () => {
74
- img.decode().then(() => {
75
- requestAnimationFrame(() => resolve(img));
76
- });
77
- }, img.onerror = reject, img.crossOrigin = "anonymous", img.decoding = "async", img.src = url;
69
+ img.decode = () => resolve(img), img.onload = () => resolve(img), img.onerror = reject, img.crossOrigin = "anonymous", img.decoding = "async", img.src = url;
78
70
  });
79
71
  }
80
72
  async function svgToDataURL(svg) {
@@ -94,17 +86,17 @@ function formatCSSText(style) {
94
86
  const content = style.getPropertyValue("content");
95
87
  return `${style.cssText} content: '${content.replace(/'|"/g, "")}';`;
96
88
  }
97
- function formatCSSProperties(style, options) {
98
- return getStyleProperties(options).map((name) => {
89
+ function formatCSSProperties(style) {
90
+ return toArray(style).map((name) => {
99
91
  const value = style.getPropertyValue(name), priority = style.getPropertyPriority(name);
100
92
  return `${name}: ${value}${priority ? " !important" : ""};`;
101
93
  }).join(" ");
102
94
  }
103
- function getPseudoElementStyle(className, pseudo, style, options) {
104
- const selector = `.${className}:${pseudo}`, cssText = style.cssText ? formatCSSText(style) : formatCSSProperties(style, options);
95
+ function getPseudoElementStyle(className, pseudo, style) {
96
+ const selector = `.${className}:${pseudo}`, cssText = style.cssText ? formatCSSText(style) : formatCSSProperties(style);
105
97
  return document.createTextNode(`${selector}{${cssText}}`);
106
98
  }
107
- function clonePseudoElement(nativeNode, clonedNode, pseudo, options) {
99
+ function clonePseudoElement(nativeNode, clonedNode, pseudo) {
108
100
  const style = window.getComputedStyle(nativeNode, pseudo), content = style.getPropertyValue("content");
109
101
  if (content === "" || content === "none")
110
102
  return;
@@ -115,10 +107,10 @@ function clonePseudoElement(nativeNode, clonedNode, pseudo, options) {
115
107
  return;
116
108
  }
117
109
  const styleElement = document.createElement("style");
118
- styleElement.appendChild(getPseudoElementStyle(className, pseudo, style, options)), clonedNode.appendChild(styleElement);
110
+ styleElement.appendChild(getPseudoElementStyle(className, pseudo, style)), clonedNode.appendChild(styleElement);
119
111
  }
120
- function clonePseudoElements(nativeNode, clonedNode, options) {
121
- clonePseudoElement(nativeNode, clonedNode, ":before", options), clonePseudoElement(nativeNode, clonedNode, ":after", options);
112
+ function clonePseudoElements(nativeNode, clonedNode) {
113
+ clonePseudoElement(nativeNode, clonedNode, ":before"), clonePseudoElement(nativeNode, clonedNode, ":after");
122
114
  }
123
115
  const WOFF = "application/font-woff", JPEG = "image/jpeg", mimes = {
124
116
  woff: WOFF,
@@ -201,34 +193,32 @@ async function cloneVideoElement(video, options) {
201
193
  const poster = video.poster, contentType = getMimeType(poster), dataURL = await resourceToDataURL(poster, contentType, options);
202
194
  return createImage(dataURL);
203
195
  }
204
- async function cloneIFrameElement(iframe, options) {
196
+ async function cloneIFrameElement(iframe) {
205
197
  var _a;
206
198
  try {
207
199
  if (!((_a = iframe?.contentDocument) === null || _a === void 0) && _a.body)
208
- return await cloneNode(iframe.contentDocument.body, options, !0);
200
+ return await cloneNode(iframe.contentDocument.body, {}, !0);
209
201
  } catch {
210
202
  }
211
203
  return iframe.cloneNode(!1);
212
204
  }
213
205
  async function cloneSingleNode(node, options) {
214
- return isInstanceOfElement(node, HTMLCanvasElement) ? cloneCanvasElement(node) : isInstanceOfElement(node, HTMLVideoElement) ? cloneVideoElement(node, options) : isInstanceOfElement(node, HTMLIFrameElement) ? cloneIFrameElement(node, options) : node.cloneNode(isSVGElement(node));
206
+ return isInstanceOfElement(node, HTMLCanvasElement) ? cloneCanvasElement(node) : isInstanceOfElement(node, HTMLVideoElement) ? cloneVideoElement(node, options) : isInstanceOfElement(node, HTMLIFrameElement) ? cloneIFrameElement(node) : node.cloneNode(!1);
215
207
  }
216
- const isSlotElement = (node) => node.tagName != null && node.tagName.toUpperCase() === "SLOT", isSVGElement = (node) => node.tagName != null && node.tagName.toUpperCase() === "SVG";
208
+ const isSlotElement = (node) => node.tagName != null && node.tagName.toUpperCase() === "SLOT";
217
209
  async function cloneChildren(nativeNode, clonedNode, options) {
218
210
  var _a, _b;
219
- if (isSVGElement(clonedNode))
220
- return clonedNode;
221
211
  let children = [];
222
212
  return isSlotElement(nativeNode) && nativeNode.assignedNodes ? children = toArray(nativeNode.assignedNodes()) : isInstanceOfElement(nativeNode, HTMLIFrameElement) && (!((_a = nativeNode.contentDocument) === null || _a === void 0) && _a.body) ? children = toArray(nativeNode.contentDocument.body.childNodes) : children = toArray(((_b = nativeNode.shadowRoot) !== null && _b !== void 0 ? _b : nativeNode).childNodes), children.length === 0 || isInstanceOfElement(nativeNode, HTMLVideoElement) || await children.reduce((deferred, child) => deferred.then(() => cloneNode(child, options)).then((clonedChild) => {
223
213
  clonedChild && clonedNode.appendChild(clonedChild);
224
214
  }), Promise.resolve()), clonedNode;
225
215
  }
226
- function cloneCSSStyle(nativeNode, clonedNode, options) {
216
+ function cloneCSSStyle(nativeNode, clonedNode) {
227
217
  const targetStyle = clonedNode.style;
228
218
  if (!targetStyle)
229
219
  return;
230
220
  const sourceStyle = window.getComputedStyle(nativeNode);
231
- sourceStyle.cssText ? (targetStyle.cssText = sourceStyle.cssText, targetStyle.transformOrigin = sourceStyle.transformOrigin) : getStyleProperties(options).forEach((name) => {
221
+ sourceStyle.cssText ? (targetStyle.cssText = sourceStyle.cssText, targetStyle.transformOrigin = sourceStyle.transformOrigin) : toArray(sourceStyle).forEach((name) => {
232
222
  let value = sourceStyle.getPropertyValue(name);
233
223
  name === "font-size" && value.endsWith("px") && (value = `${Math.floor(parseFloat(value.substring(0, value.length - 2))) - 0.1}px`), isInstanceOfElement(nativeNode, HTMLIFrameElement) && name === "display" && value === "inline" && (value = "block"), name === "d" && clonedNode.getAttribute("d") && (value = `path(${clonedNode.getAttribute("d")})`), targetStyle.setProperty(name, value, sourceStyle.getPropertyPriority(name));
234
224
  });
@@ -242,8 +232,8 @@ function cloneSelectValue(nativeNode, clonedNode) {
242
232
  selectedOption && selectedOption.setAttribute("selected", "");
243
233
  }
244
234
  }
245
- function decorate(nativeNode, clonedNode, options) {
246
- return isInstanceOfElement(clonedNode, Element) && (cloneCSSStyle(nativeNode, clonedNode, options), clonePseudoElements(nativeNode, clonedNode, options), cloneInputValue(nativeNode, clonedNode), cloneSelectValue(nativeNode, clonedNode)), clonedNode;
235
+ function decorate(nativeNode, clonedNode) {
236
+ return isInstanceOfElement(clonedNode, Element) && (cloneCSSStyle(nativeNode, clonedNode), clonePseudoElements(nativeNode, clonedNode), cloneInputValue(nativeNode, clonedNode), cloneSelectValue(nativeNode, clonedNode)), clonedNode;
247
237
  }
248
238
  async function ensureSVGSymbols(clone, options) {
249
239
  const uses = clone.querySelectorAll ? clone.querySelectorAll("use") : [];
@@ -270,7 +260,7 @@ async function ensureSVGSymbols(clone, options) {
270
260
  return clone;
271
261
  }
272
262
  async function cloneNode(node, options, isRoot) {
273
- return !isRoot && options.filter && !options.filter(node) ? null : Promise.resolve(node).then((clonedNode) => cloneSingleNode(clonedNode, options)).then((clonedNode) => cloneChildren(node, clonedNode, options)).then((clonedNode) => decorate(node, clonedNode, options)).then((clonedNode) => ensureSVGSymbols(clonedNode, options));
263
+ return !isRoot && options.filter && !options.filter(node) ? null : Promise.resolve(node).then((clonedNode) => cloneSingleNode(clonedNode, options)).then((clonedNode) => cloneChildren(node, clonedNode, options)).then((clonedNode) => decorate(node, clonedNode)).then((clonedNode) => ensureSVGSymbols(clonedNode, options));
274
264
  }
275
265
  const URL_REGEX = /url\((['"]?)([^'"]+?)\1\)/g, URL_WITH_FORMAT_REGEX = /url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g, FONT_SRC_REGEX = /src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;
276
266
  function toRegex(url) {
@@ -320,7 +310,7 @@ async function embedProp(propName, node, options) {
320
310
  return !1;
321
311
  }
322
312
  async function embedBackground(clonedNode, options) {
323
- await embedProp("background", clonedNode, options) || await embedProp("background-image", clonedNode, options), await embedProp("mask", clonedNode, options) || await embedProp("-webkit-mask", clonedNode, options) || await embedProp("mask-image", clonedNode, options) || await embedProp("-webkit-mask-image", clonedNode, options);
313
+ await embedProp("background", clonedNode, options) || await embedProp("background-image", clonedNode, options), await embedProp("mask", clonedNode, options) || await embedProp("mask-image", clonedNode, options);
324
314
  }
325
315
  async function embedImageNode(clonedNode, options) {
326
316
  const isImageElement = isInstanceOfElement(clonedNode, HTMLImageElement);
@@ -328,13 +318,7 @@ async function embedImageNode(clonedNode, options) {
328
318
  return;
329
319
  const url = isImageElement ? clonedNode.src : clonedNode.href.baseVal, dataURL = await resourceToDataURL(url, getMimeType(url), options);
330
320
  await new Promise((resolve, reject) => {
331
- clonedNode.onload = resolve, clonedNode.onerror = options.onImageErrorHandler ? (...attributes) => {
332
- try {
333
- resolve(options.onImageErrorHandler(...attributes));
334
- } catch (error) {
335
- reject(error);
336
- }
337
- } : reject;
321
+ clonedNode.onload = resolve, clonedNode.onerror = reject;
338
322
  const image = clonedNode;
339
323
  image.decode && (image.decode = resolve), image.loading === "lazy" && (image.loading = "eager"), isImageElement ? (clonedNode.srcset = "", clonedNode.src = dataURL) : clonedNode.href.baseVal = dataURL;
340
324
  });
@@ -422,7 +406,7 @@ async function getCSSRules(styleSheets, options) {
422
406
  } catch (e) {
423
407
  const inline = styleSheets.find((a) => a.href == null) || document.styleSheets[0];
424
408
  sheet.href != null && deferreds.push(fetchCSS(sheet.href).then((metadata) => embedFonts(metadata, options)).then((cssText) => parseCSS(cssText).forEach((rule) => {
425
- inline.insertRule(rule, inline.cssRules.length);
409
+ inline.insertRule(rule, sheet.cssRules.length);
426
410
  })).catch((err) => {
427
411
  console.error("Error loading remote stylesheet", err);
428
412
  })), console.error("Error inlining remote css file", e);
@@ -447,23 +431,9 @@ async function parseWebFontRules(node, options) {
447
431
  const styleSheets = toArray(node.ownerDocument.styleSheets), cssRules = await getCSSRules(styleSheets, options);
448
432
  return getWebFontRules(cssRules);
449
433
  }
450
- function normalizeFontFamily(font) {
451
- return font.trim().replace(/["']/g, "");
452
- }
453
- function getUsedFonts(node) {
454
- const fonts = /* @__PURE__ */ new Set();
455
- function traverse(node2) {
456
- (node2.style.fontFamily || getComputedStyle(node2).fontFamily).split(",").forEach((font) => {
457
- fonts.add(normalizeFontFamily(font));
458
- }), Array.from(node2.children).forEach((child) => {
459
- child instanceof HTMLElement && traverse(child);
460
- });
461
- }
462
- return traverse(node), fonts;
463
- }
464
434
  async function getWebFontCSS(node, options) {
465
- const rules = await parseWebFontRules(node, options), usedFonts = getUsedFonts(node);
466
- return (await Promise.all(rules.filter((rule) => usedFonts.has(normalizeFontFamily(rule.style.fontFamily))).map((rule) => {
435
+ const rules = await parseWebFontRules(node, options);
436
+ return (await Promise.all(rules.map((rule) => {
467
437
  const baseUrl = rule.parentStyleSheet ? rule.parentStyleSheet.href : null;
468
438
  return embedResources(rule.cssText, baseUrl, options);
469
439
  }))).join(`