likec4 1.59.4 → 1.60.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.
Files changed (96) hide show
  1. package/__app__/codegen/react.mjs +6 -6
  2. package/__app__/codegen/webcomponent.mjs +147 -69
  3. package/__app__/src/aichat/index.mjs +10 -5
  4. package/__app__/src/chunks/AIChat.mjs +1134 -693
  5. package/__app__/src/chunks/LikeC4Styles.mjs +3995 -1779
  6. package/__app__/src/chunks/ProjectsOverview.mjs +624 -334
  7. package/__app__/src/chunks/es.mjs +515 -335
  8. package/__app__/src/chunks/hooks.mjs +578 -369
  9. package/__app__/src/chunks/libs/@floating-ui.mjs +2720 -1966
  10. package/__app__/src/chunks/libs/@mantine.mjs +13920 -10057
  11. package/__app__/src/chunks/libs/@tanstack-ai.mjs +2266 -1146
  12. package/__app__/src/chunks/libs/@tanstack.mjs +3152 -1926
  13. package/__app__/src/chunks/libs/@xstate/react.mjs +2924 -1468
  14. package/__app__/src/chunks/libs/@xyflow/react.mjs +6627 -4067
  15. package/__app__/src/chunks/libs/bezier-js.mjs +1312 -726
  16. package/__app__/src/chunks/libs/d3.mjs +3219 -1505
  17. package/__app__/src/chunks/libs/fast-equals.mjs +434 -210
  18. package/__app__/src/chunks/libs/framer.mjs +9251 -3846
  19. package/__app__/src/chunks/libs/nanostores.mjs +174 -0
  20. package/__app__/src/chunks/libs/zod.mjs +4591 -2363
  21. package/__app__/src/chunks/rolldown-runtime.mjs +39 -23
  22. package/__app__/src/chunks/styled-system.mjs +2279 -1951
  23. package/__app__/src/fonts.css +112 -1
  24. package/__app__/src/main.mjs +40817 -21840
  25. package/__app__/src/style.css +18488 -1
  26. package/config/schema.json +122 -97
  27. package/dist/app/render-view-client.css +1 -1
  28. package/dist/app/render-view-client.js +508 -334
  29. package/dist/chunks/enableServer.mjs +1 -1
  30. package/dist/chunks/filenames.mjs +11 -9
  31. package/dist/chunks/generate-likec4.mjs +5 -0
  32. package/dist/chunks/index.d.mts +243 -183
  33. package/dist/chunks/index2.d.mts +2865 -1977
  34. package/dist/chunks/libs/@chevrotain/gast.mjs +27 -1
  35. package/dist/chunks/libs/@chevrotain/regexp-to-ast.mjs +81 -9
  36. package/dist/chunks/libs/@chevrotain/types.d.mts +4 -1
  37. package/dist/chunks/libs/@logtape/logtape.mjs +5 -4
  38. package/dist/chunks/libs/@lume/kiwi.mjs +1 -1
  39. package/dist/chunks/libs/@ts-graphviz/core.mjs +1 -1
  40. package/dist/chunks/libs/birpc.mjs +1 -1
  41. package/dist/chunks/libs/chevrotain-allstar.mjs +2 -2
  42. package/dist/chunks/libs/chevrotain.mjs +87 -35
  43. package/dist/chunks/libs/eventemitter3.mjs +1 -1
  44. package/dist/chunks/libs/json5.mjs +4 -4
  45. package/dist/chunks/libs/langium.d.mts +9038 -6193
  46. package/dist/chunks/libs/langium.mjs +16 -24
  47. package/dist/chunks/libs/merge-error-cause.mjs +1 -1
  48. package/dist/chunks/libs/p-limit.mjs +1 -0
  49. package/dist/chunks/libs/p-queue.mjs +1 -1
  50. package/dist/chunks/libs/package-manager-detector.mjs +1 -1
  51. package/dist/chunks/libs/pako.mjs +1 -1
  52. package/dist/chunks/libs/pretty-ms.mjs +1 -1
  53. package/dist/chunks/libs/remeda.mjs +1 -1
  54. package/dist/chunks/libs/ufo.mjs +1 -1
  55. package/dist/chunks/libs/unstorage.mjs +1 -1
  56. package/dist/chunks/libs/which.mjs +1 -1
  57. package/dist/chunks/node.mjs +59 -58
  58. package/dist/chunks/rolldown-runtime.mjs +1 -1
  59. package/dist/chunks/sequence-view.mjs +1 -1
  60. package/dist/chunks/vite-plugin.mjs +45 -45
  61. package/dist/cli/index.mjs +207 -1315
  62. package/dist/config/index.d.mts +2 -2
  63. package/dist/generators/likec4.d.mts +6578 -0
  64. package/dist/generators/likec4.mjs +1 -0
  65. package/dist/model/index.d.mts +4 -1
  66. package/dist/vite-plugin/index.d.mts +4 -1
  67. package/dist/vite-plugin/index.mjs +1 -1
  68. package/dist/vite-plugin/internal/chunks/rolldown-runtime.mjs +9 -0
  69. package/dist/vite-plugin/internal/index.d.mts +6 -5
  70. package/dist/vite-plugin/internal/index.mjs +83 -30
  71. package/generators/likec4/package.json +4 -0
  72. package/package.json +113 -106
  73. package/react/index.d.mts +8500 -26659
  74. package/react/index.mjs +534 -63936
  75. package/react/rolldown-runtime-DnkiqaRY.js +1 -0
  76. package/skills/likec4-dsl/SKILL.md +428 -0
  77. package/skills/likec4-dsl/evals/evals-public.json +202 -0
  78. package/skills/likec4-dsl/evals/grading-spec.json +589 -0
  79. package/skills/likec4-dsl/references/bridge-leanix-drawio.md +42 -0
  80. package/skills/likec4-dsl/references/cli.md +139 -0
  81. package/skills/likec4-dsl/references/configuration.md +266 -0
  82. package/skills/likec4-dsl/references/deployment.md +160 -0
  83. package/skills/likec4-dsl/references/dynamic-views.md +455 -0
  84. package/skills/likec4-dsl/references/examples.md +370 -0
  85. package/skills/likec4-dsl/references/identifier-validity.md +90 -0
  86. package/skills/likec4-dsl/references/include-predicates-wildcards.md +179 -0
  87. package/skills/likec4-dsl/references/model.md +151 -0
  88. package/skills/likec4-dsl/references/predicates.md +123 -0
  89. package/skills/likec4-dsl/references/relationships-bidirectional.md +176 -0
  90. package/skills/likec4-dsl/references/specification.md +75 -0
  91. package/skills/likec4-dsl/references/style-tokens-colors.md +150 -0
  92. package/skills/likec4-dsl/references/troubleshooting.md +96 -0
  93. package/skills/likec4-dsl/references/views.md +329 -0
  94. package/dist/chunks/libs/picomatch.mjs +0 -1
  95. package/dist/chunks/libs/zod.d.mts +0 -3840
  96. package/dist/chunks/libs/zod.mjs +0 -65
@@ -1,439 +1,619 @@
1
1
  import "./rolldown-runtime.mjs";
2
2
  //#region ../../node_modules/.pnpm/html-to-image@1.11.11/node_modules/html-to-image/es/util.js
3
- function resolveUrl(e, t) {
4
- if (e.match(/^[a-z]+:\/\//i)) return e;
5
- if (e.match(/^\/\//)) return window.location.protocol + e;
6
- if (e.match(/^[a-z]+:/i)) return e;
7
- let n = document.implementation.createHTMLDocument(), r = n.createElement("base"), i = n.createElement("a");
8
- return n.head.appendChild(r), n.body.appendChild(i), t && (r.href = t), i.href = e, i.href;
9
- }
10
- var e = (() => {
11
- let e = 0, random = () => `0000${(Math.random() * 36 ** 4 << 0).toString(36)}`.slice(-4);
12
- return () => (e += 1, `u${random()}${e}`);
3
+ function resolveUrl(url, baseUrl) {
4
+ if (url.match(/^[a-z]+:\/\//i)) return url;
5
+ if (url.match(/^\/\//)) return window.location.protocol + url;
6
+ if (url.match(/^[a-z]+:/i)) return url;
7
+ const doc = document.implementation.createHTMLDocument();
8
+ const base = doc.createElement("base");
9
+ const a = doc.createElement("a");
10
+ doc.head.appendChild(base);
11
+ doc.body.appendChild(a);
12
+ if (baseUrl) base.href = baseUrl;
13
+ a.href = url;
14
+ return a.href;
15
+ }
16
+ var uuid = (() => {
17
+ let counter = 0;
18
+ const random = () => `0000${(Math.random() * 36 ** 4 << 0).toString(36)}`.slice(-4);
19
+ return () => {
20
+ counter += 1;
21
+ return `u${random()}${counter}`;
22
+ };
13
23
  })();
14
- function toArray(e) {
15
- let t = [];
16
- for (let n = 0, r = e.length; n < r; n++) t.push(e[n]);
17
- return t;
18
- }
19
- function px(e, t) {
20
- let n = (e.ownerDocument.defaultView || window).getComputedStyle(e).getPropertyValue(t);
21
- return n ? parseFloat(n.replace("px", "")) : 0;
22
- }
23
- function getNodeWidth(e) {
24
- let t = px(e, "border-left-width"), n = px(e, "border-right-width");
25
- return e.clientWidth + t + n;
26
- }
27
- function getNodeHeight(e) {
28
- let t = px(e, "border-top-width"), n = px(e, "border-bottom-width");
29
- return e.clientHeight + t + n;
30
- }
31
- function getImageSize(e, t = {}) {
24
+ function toArray(arrayLike) {
25
+ const arr = [];
26
+ for (let i = 0, l = arrayLike.length; i < l; i++) arr.push(arrayLike[i]);
27
+ return arr;
28
+ }
29
+ function px(node, styleProperty) {
30
+ const val = (node.ownerDocument.defaultView || window).getComputedStyle(node).getPropertyValue(styleProperty);
31
+ return val ? parseFloat(val.replace("px", "")) : 0;
32
+ }
33
+ function getNodeWidth(node) {
34
+ const leftBorder = px(node, "border-left-width");
35
+ const rightBorder = px(node, "border-right-width");
36
+ return node.clientWidth + leftBorder + rightBorder;
37
+ }
38
+ function getNodeHeight(node) {
39
+ const topBorder = px(node, "border-top-width");
40
+ const bottomBorder = px(node, "border-bottom-width");
41
+ return node.clientHeight + topBorder + bottomBorder;
42
+ }
43
+ function getImageSize(targetNode, options = {}) {
32
44
  return {
33
- width: t.width || getNodeWidth(e),
34
- height: t.height || getNodeHeight(e)
45
+ width: options.width || getNodeWidth(targetNode),
46
+ height: options.height || getNodeHeight(targetNode)
35
47
  };
36
48
  }
37
49
  function getPixelRatio() {
38
- let e, t;
50
+ let ratio;
51
+ let FINAL_PROCESS;
39
52
  try {
40
- t = process;
41
- } catch {}
42
- let n = t && t.env ? t.env.devicePixelRatio : null;
43
- return n && (e = parseInt(n, 10), Number.isNaN(e) && (e = 1)), e || window.devicePixelRatio || 1;
44
- }
45
- var t = 16384;
46
- function checkCanvasDimensions(e) {
47
- (e.width > t || e.height > t) && (e.width > t && e.height > t ? e.width > e.height ? (e.height *= t / e.width, e.width = t) : (e.width *= t / e.height, e.height = t) : e.width > t ? (e.height *= t / e.width, e.width = t) : (e.width *= t / e.height, e.height = t));
48
- }
49
- function canvasToBlob(e, t = {}) {
50
- return e.toBlob ? new Promise((n) => {
51
- e.toBlob(n, t.type ? t.type : "image/png", t.quality ? t.quality : 1);
52
- }) : new Promise((n) => {
53
- let r = window.atob(e.toDataURL(t.type ? t.type : void 0, t.quality ? t.quality : void 0).split(",")[1]), i = r.length, a = new Uint8Array(i);
54
- for (let e = 0; e < i; e += 1) a[e] = r.charCodeAt(e);
55
- n(new Blob([a], { type: t.type ? t.type : "image/png" }));
56
- });
53
+ FINAL_PROCESS = process;
54
+ } catch (e) {}
55
+ const val = FINAL_PROCESS && FINAL_PROCESS.env ? FINAL_PROCESS.env.devicePixelRatio : null;
56
+ if (val) {
57
+ ratio = parseInt(val, 10);
58
+ if (Number.isNaN(ratio)) ratio = 1;
59
+ }
60
+ return ratio || window.devicePixelRatio || 1;
61
+ }
62
+ var canvasDimensionLimit = 16384;
63
+ function checkCanvasDimensions(canvas) {
64
+ if (canvas.width > canvasDimensionLimit || canvas.height > canvasDimensionLimit) {
65
+ if (canvas.width > canvasDimensionLimit && canvas.height > canvasDimensionLimit) {
66
+ if (canvas.width > canvas.height) {
67
+ canvas.height *= canvasDimensionLimit / canvas.width;
68
+ canvas.width = canvasDimensionLimit;
69
+ } else {
70
+ canvas.width *= canvasDimensionLimit / canvas.height;
71
+ canvas.height = canvasDimensionLimit;
72
+ }
73
+ } else if (canvas.width > canvasDimensionLimit) {
74
+ canvas.height *= canvasDimensionLimit / canvas.width;
75
+ canvas.width = canvasDimensionLimit;
76
+ } else {
77
+ canvas.width *= canvasDimensionLimit / canvas.height;
78
+ canvas.height = canvasDimensionLimit;
79
+ }
80
+ }
57
81
  }
58
- function createImage(e) {
59
- return new Promise((t, n) => {
60
- let r = new Image();
61
- r.decode = () => t(r), r.onload = () => t(r), r.onerror = n, r.crossOrigin = "anonymous", r.decoding = "async", r.src = e;
82
+ function canvasToBlob(canvas, options = {}) {
83
+ if (canvas.toBlob) return new Promise((resolve) => {
84
+ canvas.toBlob(resolve, options.type ? options.type : "image/png", options.quality ? options.quality : 1);
85
+ });
86
+ return new Promise((resolve) => {
87
+ const binaryString = window.atob(canvas.toDataURL(options.type ? options.type : void 0, options.quality ? options.quality : void 0).split(",")[1]);
88
+ const len = binaryString.length;
89
+ const binaryArray = new Uint8Array(len);
90
+ for (let i = 0; i < len; i += 1) binaryArray[i] = binaryString.charCodeAt(i);
91
+ resolve(new Blob([binaryArray], { type: options.type ? options.type : "image/png" }));
62
92
  });
63
93
  }
64
- async function svgToDataURL(e) {
65
- return Promise.resolve().then(() => new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then((e) => `data:image/svg+xml;charset=utf-8,${e}`);
66
- }
67
- async function nodeToDataURL(e, t, n) {
68
- let r = "http://www.w3.org/2000/svg", i = document.createElementNS(r, "svg"), a = document.createElementNS(r, "foreignObject");
69
- return i.setAttribute("width", `${t}`), i.setAttribute("height", `${n}`), i.setAttribute("viewBox", `0 0 ${t} ${n}`), a.setAttribute("width", "100%"), a.setAttribute("height", "100%"), a.setAttribute("x", "0"), a.setAttribute("y", "0"), a.setAttribute("externalResourcesRequired", "true"), i.appendChild(a), a.appendChild(e), svgToDataURL(i);
94
+ function createImage(url) {
95
+ return new Promise((resolve, reject) => {
96
+ const img = new Image();
97
+ img.decode = () => resolve(img);
98
+ img.onload = () => resolve(img);
99
+ img.onerror = reject;
100
+ img.crossOrigin = "anonymous";
101
+ img.decoding = "async";
102
+ img.src = url;
103
+ });
70
104
  }
71
- var isInstanceOfElement = (e, t) => {
72
- if (e instanceof t) return !0;
73
- let n = Object.getPrototypeOf(e);
74
- return n === null ? !1 : n.constructor.name === t.name || isInstanceOfElement(n, t);
105
+ async function svgToDataURL(svg) {
106
+ return Promise.resolve().then(() => new XMLSerializer().serializeToString(svg)).then(encodeURIComponent).then((html) => `data:image/svg+xml;charset=utf-8,${html}`);
107
+ }
108
+ async function nodeToDataURL(node, width, height) {
109
+ const xmlns = "http://www.w3.org/2000/svg";
110
+ const svg = document.createElementNS(xmlns, "svg");
111
+ const foreignObject = document.createElementNS(xmlns, "foreignObject");
112
+ svg.setAttribute("width", `${width}`);
113
+ svg.setAttribute("height", `${height}`);
114
+ svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
115
+ foreignObject.setAttribute("width", "100%");
116
+ foreignObject.setAttribute("height", "100%");
117
+ foreignObject.setAttribute("x", "0");
118
+ foreignObject.setAttribute("y", "0");
119
+ foreignObject.setAttribute("externalResourcesRequired", "true");
120
+ svg.appendChild(foreignObject);
121
+ foreignObject.appendChild(node);
122
+ return svgToDataURL(svg);
123
+ }
124
+ var isInstanceOfElement = (node, instance) => {
125
+ if (node instanceof instance) return true;
126
+ const nodePrototype = Object.getPrototypeOf(node);
127
+ if (nodePrototype === null) return false;
128
+ return nodePrototype.constructor.name === instance.name || isInstanceOfElement(nodePrototype, instance);
75
129
  };
76
130
  //#endregion
77
131
  //#region ../../node_modules/.pnpm/html-to-image@1.11.11/node_modules/html-to-image/es/clone-pseudos.js
78
- function formatCSSText(e) {
79
- let t = e.getPropertyValue("content");
80
- return `${e.cssText} content: '${t.replace(/'|"/g, "")}';`;
81
- }
82
- function formatCSSProperties(e) {
83
- return toArray(e).map((t) => `${t}: ${e.getPropertyValue(t)}${e.getPropertyPriority(t) ? " !important" : ""};`).join(" ");
84
- }
85
- function getPseudoElementStyle(e, t, n) {
86
- let r = `.${e}:${t}`, i = n.cssText ? formatCSSText(n) : formatCSSProperties(n);
87
- return document.createTextNode(`${r}{${i}}`);
88
- }
89
- function clonePseudoElement(t, n, r) {
90
- let i = window.getComputedStyle(t, r), a = i.getPropertyValue("content");
91
- if (a === "" || a === "none") return;
92
- let o = e();
132
+ function formatCSSText(style) {
133
+ const content = style.getPropertyValue("content");
134
+ return `${style.cssText} content: '${content.replace(/'|"/g, "")}';`;
135
+ }
136
+ function formatCSSProperties(style) {
137
+ return toArray(style).map((name) => {
138
+ return `${name}: ${style.getPropertyValue(name)}${style.getPropertyPriority(name) ? " !important" : ""};`;
139
+ }).join(" ");
140
+ }
141
+ function getPseudoElementStyle(className, pseudo, style) {
142
+ const selector = `.${className}:${pseudo}`;
143
+ const cssText = style.cssText ? formatCSSText(style) : formatCSSProperties(style);
144
+ return document.createTextNode(`${selector}{${cssText}}`);
145
+ }
146
+ function clonePseudoElement(nativeNode, clonedNode, pseudo) {
147
+ const style = window.getComputedStyle(nativeNode, pseudo);
148
+ const content = style.getPropertyValue("content");
149
+ if (content === "" || content === "none") return;
150
+ const className = uuid();
93
151
  try {
94
- n.className = `${n.className} ${o}`;
95
- } catch {
152
+ clonedNode.className = `${clonedNode.className} ${className}`;
153
+ } catch (err) {
96
154
  return;
97
155
  }
98
- let s = document.createElement("style");
99
- s.appendChild(getPseudoElementStyle(o, r, i)), n.appendChild(s);
156
+ const styleElement = document.createElement("style");
157
+ styleElement.appendChild(getPseudoElementStyle(className, pseudo, style));
158
+ clonedNode.appendChild(styleElement);
100
159
  }
101
- function clonePseudoElements(e, t) {
102
- clonePseudoElement(e, t, ":before"), clonePseudoElement(e, t, ":after");
160
+ function clonePseudoElements(nativeNode, clonedNode) {
161
+ clonePseudoElement(nativeNode, clonedNode, ":before");
162
+ clonePseudoElement(nativeNode, clonedNode, ":after");
103
163
  }
104
164
  //#endregion
105
165
  //#region ../../node_modules/.pnpm/html-to-image@1.11.11/node_modules/html-to-image/es/mimes.js
106
- var n = "application/font-woff", r = "image/jpeg", i = {
107
- woff: n,
108
- woff2: n,
166
+ var WOFF = "application/font-woff";
167
+ var JPEG = "image/jpeg";
168
+ var mimes = {
169
+ woff: WOFF,
170
+ woff2: WOFF,
109
171
  ttf: "application/font-truetype",
110
172
  eot: "application/vnd.ms-fontobject",
111
173
  png: "image/png",
112
- jpg: r,
113
- jpeg: r,
174
+ jpg: JPEG,
175
+ jpeg: JPEG,
114
176
  gif: "image/gif",
115
177
  tiff: "image/tiff",
116
178
  svg: "image/svg+xml",
117
179
  webp: "image/webp"
118
180
  };
119
- function getExtension(e) {
120
- let t = /\.([^./]*?)$/g.exec(e);
121
- return t ? t[1] : "";
181
+ function getExtension(url) {
182
+ const match = /\.([^./]*?)$/g.exec(url);
183
+ return match ? match[1] : "";
122
184
  }
123
- function getMimeType(e) {
124
- return i[getExtension(e).toLowerCase()] || "";
185
+ function getMimeType(url) {
186
+ return mimes[getExtension(url).toLowerCase()] || "";
125
187
  }
126
188
  //#endregion
127
189
  //#region ../../node_modules/.pnpm/html-to-image@1.11.11/node_modules/html-to-image/es/dataurl.js
128
- function getContentFromDataUrl(e) {
129
- return e.split(/,/)[1];
130
- }
131
- function isDataUrl(e) {
132
- return e.search(/^(data:)/) !== -1;
133
- }
134
- function makeDataUrl(e, t) {
135
- return `data:${t};base64,${e}`;
136
- }
137
- async function fetchAsDataURL(e, t, n) {
138
- let r = await fetch(e, t);
139
- if (r.status === 404) throw Error(`Resource "${r.url}" not found`);
140
- let i = await r.blob();
141
- return new Promise((e, t) => {
142
- let a = new FileReader();
143
- a.onerror = t, a.onloadend = () => {
190
+ function getContentFromDataUrl(dataURL) {
191
+ return dataURL.split(/,/)[1];
192
+ }
193
+ function isDataUrl(url) {
194
+ return url.search(/^(data:)/) !== -1;
195
+ }
196
+ function makeDataUrl(content, mimeType) {
197
+ return `data:${mimeType};base64,${content}`;
198
+ }
199
+ async function fetchAsDataURL(url, init, process) {
200
+ const res = await fetch(url, init);
201
+ if (res.status === 404) throw new Error(`Resource "${res.url}" not found`);
202
+ const blob = await res.blob();
203
+ return new Promise((resolve, reject) => {
204
+ const reader = new FileReader();
205
+ reader.onerror = reject;
206
+ reader.onloadend = () => {
144
207
  try {
145
- e(n({
146
- res: r,
147
- result: a.result
208
+ resolve(process({
209
+ res,
210
+ result: reader.result
148
211
  }));
149
- } catch (e) {
150
- t(e);
212
+ } catch (error) {
213
+ reject(error);
151
214
  }
152
- }, a.readAsDataURL(i);
215
+ };
216
+ reader.readAsDataURL(blob);
153
217
  });
154
218
  }
155
- var a = {};
156
- function getCacheKey(e, t, n) {
157
- let r = e.replace(/\?.*/, "");
158
- return n && (r = e), /ttf|otf|eot|woff2?/i.test(r) && (r = r.replace(/.*\//, "")), t ? `[${t}]${r}` : r;
159
- }
160
- async function resourceToDataURL(e, t, n) {
161
- let r = getCacheKey(e, t, n.includeQueryParams);
162
- if (a[r] != null) return a[r];
163
- n.cacheBust && (e += (/\?/.test(e) ? "&" : "?") + (/* @__PURE__ */ new Date()).getTime());
164
- let i;
219
+ var cache = {};
220
+ function getCacheKey(url, contentType, includeQueryParams) {
221
+ let key = url.replace(/\?.*/, "");
222
+ if (includeQueryParams) key = url;
223
+ if (/ttf|otf|eot|woff2?/i.test(key)) key = key.replace(/.*\//, "");
224
+ return contentType ? `[${contentType}]${key}` : key;
225
+ }
226
+ async function resourceToDataURL(resourceUrl, contentType, options) {
227
+ const cacheKey = getCacheKey(resourceUrl, contentType, options.includeQueryParams);
228
+ if (cache[cacheKey] != null) return cache[cacheKey];
229
+ if (options.cacheBust) resourceUrl += (/\?/.test(resourceUrl) ? "&" : "?") + (/* @__PURE__ */ new Date()).getTime();
230
+ let dataURL;
165
231
  try {
166
- i = makeDataUrl(await fetchAsDataURL(e, n.fetchRequestInit, ({ res: e, result: n }) => (t ||= e.headers.get("Content-Type") || "", getContentFromDataUrl(n))), t);
167
- } catch (t) {
168
- i = n.imagePlaceholder || "";
169
- let r = `Failed to fetch resource: ${e}`;
170
- t && (r = typeof t == "string" ? t : t.message), r && console.warn(r);
232
+ dataURL = makeDataUrl(await fetchAsDataURL(resourceUrl, options.fetchRequestInit, ({ res, result }) => {
233
+ if (!contentType) contentType = res.headers.get("Content-Type") || "";
234
+ return getContentFromDataUrl(result);
235
+ }), contentType);
236
+ } catch (error) {
237
+ dataURL = options.imagePlaceholder || "";
238
+ let msg = `Failed to fetch resource: ${resourceUrl}`;
239
+ if (error) msg = typeof error === "string" ? error : error.message;
240
+ if (msg) console.warn(msg);
171
241
  }
172
- return a[r] = i, i;
242
+ cache[cacheKey] = dataURL;
243
+ return dataURL;
173
244
  }
174
245
  //#endregion
175
246
  //#region ../../node_modules/.pnpm/html-to-image@1.11.11/node_modules/html-to-image/es/clone-node.js
176
- async function cloneCanvasElement(e) {
177
- let t = e.toDataURL();
178
- return t === "data:," ? e.cloneNode(!1) : createImage(t);
179
- }
180
- async function cloneVideoElement(e, t) {
181
- if (e.currentSrc) {
182
- let t = document.createElement("canvas"), n = t.getContext("2d");
183
- return t.width = e.clientWidth, t.height = e.clientHeight, n?.drawImage(e, 0, 0, t.width, t.height), createImage(t.toDataURL());
247
+ async function cloneCanvasElement(canvas) {
248
+ const dataURL = canvas.toDataURL();
249
+ if (dataURL === "data:,") return canvas.cloneNode(false);
250
+ return createImage(dataURL);
251
+ }
252
+ async function cloneVideoElement(video, options) {
253
+ if (video.currentSrc) {
254
+ const canvas = document.createElement("canvas");
255
+ const ctx = canvas.getContext("2d");
256
+ canvas.width = video.clientWidth;
257
+ canvas.height = video.clientHeight;
258
+ ctx === null || ctx === void 0 || ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
259
+ return createImage(canvas.toDataURL());
184
260
  }
185
- let n = e.poster;
186
- return createImage(await resourceToDataURL(n, getMimeType(n), t));
261
+ const poster = video.poster;
262
+ return createImage(await resourceToDataURL(poster, getMimeType(poster), options));
187
263
  }
188
- async function cloneIFrameElement(e) {
264
+ async function cloneIFrameElement(iframe) {
265
+ var _a;
189
266
  try {
190
- if (e?.contentDocument?.body) return await cloneNode(e.contentDocument.body, {}, !0);
191
- } catch {}
192
- return e.cloneNode(!1);
193
- }
194
- async function cloneSingleNode(e, t) {
195
- return isInstanceOfElement(e, HTMLCanvasElement) ? cloneCanvasElement(e) : isInstanceOfElement(e, HTMLVideoElement) ? cloneVideoElement(e, t) : isInstanceOfElement(e, HTMLIFrameElement) ? cloneIFrameElement(e) : e.cloneNode(!1);
196
- }
197
- var isSlotElement = (e) => e.tagName != null && e.tagName.toUpperCase() === "SLOT";
198
- async function cloneChildren(e, t, n) {
199
- let r = [];
200
- return r = isSlotElement(e) && e.assignedNodes ? toArray(e.assignedNodes()) : isInstanceOfElement(e, HTMLIFrameElement) && e.contentDocument?.body ? toArray(e.contentDocument.body.childNodes) : toArray((e.shadowRoot ?? e).childNodes), r.length === 0 || isInstanceOfElement(e, HTMLVideoElement) || await r.reduce((e, r) => e.then(() => cloneNode(r, n)).then((e) => {
201
- e && t.appendChild(e);
202
- }), Promise.resolve()), t;
203
- }
204
- function cloneCSSStyle(e, t) {
205
- let n = t.style;
206
- if (!n) return;
207
- let r = window.getComputedStyle(e);
208
- r.cssText ? (n.cssText = r.cssText, n.transformOrigin = r.transformOrigin) : toArray(r).forEach((i) => {
209
- let a = r.getPropertyValue(i);
210
- i === "font-size" && a.endsWith("px") && (a = `${Math.floor(parseFloat(a.substring(0, a.length - 2))) - .1}px`), isInstanceOfElement(e, HTMLIFrameElement) && i === "display" && a === "inline" && (a = "block"), i === "d" && t.getAttribute("d") && (a = `path(${t.getAttribute("d")})`), n.setProperty(i, a, r.getPropertyPriority(i));
267
+ if ((_a = iframe === null || iframe === void 0 ? void 0 : iframe.contentDocument) === null || _a === void 0 ? void 0 : _a.body) return await cloneNode(iframe.contentDocument.body, {}, true);
268
+ } catch (_b) {}
269
+ return iframe.cloneNode(false);
270
+ }
271
+ async function cloneSingleNode(node, options) {
272
+ if (isInstanceOfElement(node, HTMLCanvasElement)) return cloneCanvasElement(node);
273
+ if (isInstanceOfElement(node, HTMLVideoElement)) return cloneVideoElement(node, options);
274
+ if (isInstanceOfElement(node, HTMLIFrameElement)) return cloneIFrameElement(node);
275
+ return node.cloneNode(false);
276
+ }
277
+ var isSlotElement = (node) => node.tagName != null && node.tagName.toUpperCase() === "SLOT";
278
+ async function cloneChildren(nativeNode, clonedNode, options) {
279
+ var _a;
280
+ var _b;
281
+ let children = [];
282
+ if (isSlotElement(nativeNode) && nativeNode.assignedNodes) children = toArray(nativeNode.assignedNodes());
283
+ else if (isInstanceOfElement(nativeNode, HTMLIFrameElement) && ((_a = nativeNode.contentDocument) === null || _a === void 0 ? void 0 : _a.body)) children = toArray(nativeNode.contentDocument.body.childNodes);
284
+ else children = toArray(((_b = nativeNode.shadowRoot) !== null && _b !== void 0 ? _b : nativeNode).childNodes);
285
+ if (children.length === 0 || isInstanceOfElement(nativeNode, HTMLVideoElement)) return clonedNode;
286
+ await children.reduce((deferred, child) => deferred.then(() => cloneNode(child, options)).then((clonedChild) => {
287
+ if (clonedChild) clonedNode.appendChild(clonedChild);
288
+ }), Promise.resolve());
289
+ return clonedNode;
290
+ }
291
+ function cloneCSSStyle(nativeNode, clonedNode) {
292
+ const targetStyle = clonedNode.style;
293
+ if (!targetStyle) return;
294
+ const sourceStyle = window.getComputedStyle(nativeNode);
295
+ if (sourceStyle.cssText) {
296
+ targetStyle.cssText = sourceStyle.cssText;
297
+ targetStyle.transformOrigin = sourceStyle.transformOrigin;
298
+ } else toArray(sourceStyle).forEach((name) => {
299
+ let value = sourceStyle.getPropertyValue(name);
300
+ if (name === "font-size" && value.endsWith("px")) value = `${Math.floor(parseFloat(value.substring(0, value.length - 2))) - .1}px`;
301
+ if (isInstanceOfElement(nativeNode, HTMLIFrameElement) && name === "display" && value === "inline") value = "block";
302
+ if (name === "d" && clonedNode.getAttribute("d")) value = `path(${clonedNode.getAttribute("d")})`;
303
+ targetStyle.setProperty(name, value, sourceStyle.getPropertyPriority(name));
211
304
  });
212
305
  }
213
- function cloneInputValue(e, t) {
214
- isInstanceOfElement(e, HTMLTextAreaElement) && (t.innerHTML = e.value), isInstanceOfElement(e, HTMLInputElement) && t.setAttribute("value", e.value);
306
+ function cloneInputValue(nativeNode, clonedNode) {
307
+ if (isInstanceOfElement(nativeNode, HTMLTextAreaElement)) clonedNode.innerHTML = nativeNode.value;
308
+ if (isInstanceOfElement(nativeNode, HTMLInputElement)) clonedNode.setAttribute("value", nativeNode.value);
215
309
  }
216
- function cloneSelectValue(e, t) {
217
- if (isInstanceOfElement(e, HTMLSelectElement)) {
218
- let n = t, r = Array.from(n.children).find((t) => e.value === t.getAttribute("value"));
219
- r && r.setAttribute("selected", "");
310
+ function cloneSelectValue(nativeNode, clonedNode) {
311
+ if (isInstanceOfElement(nativeNode, HTMLSelectElement)) {
312
+ const clonedSelect = clonedNode;
313
+ const selectedOption = Array.from(clonedSelect.children).find((child) => nativeNode.value === child.getAttribute("value"));
314
+ if (selectedOption) selectedOption.setAttribute("selected", "");
220
315
  }
221
316
  }
222
- function decorate(e, t) {
223
- return isInstanceOfElement(t, Element) && (cloneCSSStyle(e, t), clonePseudoElements(e, t), cloneInputValue(e, t), cloneSelectValue(e, t)), t;
224
- }
225
- async function ensureSVGSymbols(e, t) {
226
- let n = e.querySelectorAll ? e.querySelectorAll("use") : [];
227
- if (n.length === 0) return e;
228
- let r = {};
229
- for (let i = 0; i < n.length; i++) {
230
- let a = n[i].getAttribute("xlink:href");
231
- if (a) {
232
- let n = e.querySelector(a), i = document.querySelector(a);
233
- !n && i && !r[a] && (r[a] = await cloneNode(i, t, !0));
317
+ function decorate(nativeNode, clonedNode) {
318
+ if (isInstanceOfElement(clonedNode, Element)) {
319
+ cloneCSSStyle(nativeNode, clonedNode);
320
+ clonePseudoElements(nativeNode, clonedNode);
321
+ cloneInputValue(nativeNode, clonedNode);
322
+ cloneSelectValue(nativeNode, clonedNode);
323
+ }
324
+ return clonedNode;
325
+ }
326
+ async function ensureSVGSymbols(clone, options) {
327
+ const uses = clone.querySelectorAll ? clone.querySelectorAll("use") : [];
328
+ if (uses.length === 0) return clone;
329
+ const processedDefs = {};
330
+ for (let i = 0; i < uses.length; i++) {
331
+ const id = uses[i].getAttribute("xlink:href");
332
+ if (id) {
333
+ const exist = clone.querySelector(id);
334
+ const definition = document.querySelector(id);
335
+ if (!exist && definition && !processedDefs[id]) processedDefs[id] = await cloneNode(definition, options, true);
234
336
  }
235
337
  }
236
- let i = Object.values(r);
237
- if (i.length) {
238
- let t = "http://www.w3.org/1999/xhtml", n = document.createElementNS(t, "svg");
239
- n.setAttribute("xmlns", t), n.style.position = "absolute", n.style.width = "0", n.style.height = "0", n.style.overflow = "hidden", n.style.display = "none";
240
- let r = document.createElementNS(t, "defs");
241
- n.appendChild(r);
242
- for (let e = 0; e < i.length; e++) r.appendChild(i[e]);
243
- e.appendChild(n);
338
+ const nodes = Object.values(processedDefs);
339
+ if (nodes.length) {
340
+ const ns = "http://www.w3.org/1999/xhtml";
341
+ const svg = document.createElementNS(ns, "svg");
342
+ svg.setAttribute("xmlns", ns);
343
+ svg.style.position = "absolute";
344
+ svg.style.width = "0";
345
+ svg.style.height = "0";
346
+ svg.style.overflow = "hidden";
347
+ svg.style.display = "none";
348
+ const defs = document.createElementNS(ns, "defs");
349
+ svg.appendChild(defs);
350
+ for (let i = 0; i < nodes.length; i++) defs.appendChild(nodes[i]);
351
+ clone.appendChild(svg);
244
352
  }
245
- return e;
353
+ return clone;
246
354
  }
247
- async function cloneNode(e, t, n) {
248
- return !n && t.filter && !t.filter(e) ? null : Promise.resolve(e).then((e) => cloneSingleNode(e, t)).then((n) => cloneChildren(e, n, t)).then((t) => decorate(e, t)).then((e) => ensureSVGSymbols(e, t));
355
+ async function cloneNode(node, options, isRoot) {
356
+ if (!isRoot && options.filter && !options.filter(node)) return null;
357
+ return Promise.resolve(node).then((clonedNode) => cloneSingleNode(clonedNode, options)).then((clonedNode) => cloneChildren(node, clonedNode, options)).then((clonedNode) => decorate(node, clonedNode)).then((clonedNode) => ensureSVGSymbols(clonedNode, options));
249
358
  }
250
359
  //#endregion
251
360
  //#region ../../node_modules/.pnpm/html-to-image@1.11.11/node_modules/html-to-image/es/embed-resources.js
252
- var o = /url\((['"]?)([^'"]+?)\1\)/g, s = /url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g, c = /src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;
253
- function toRegex(e) {
254
- let t = e.replace(/([.*+?^${}()|\[\]\/\\])/g, "\\$1");
255
- return RegExp(`(url\\(['"]?)(${t})(['"]?\\))`, "g");
256
- }
257
- function parseURLs(e) {
258
- let t = [];
259
- return e.replace(o, (e, n, r) => (t.push(r), e)), t.filter((e) => !isDataUrl(e));
361
+ var URL_REGEX = /url\((['"]?)([^'"]+?)\1\)/g;
362
+ var URL_WITH_FORMAT_REGEX = /url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g;
363
+ var FONT_SRC_REGEX = /src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;
364
+ function toRegex(url) {
365
+ const escaped = url.replace(/([.*+?^${}()|\[\]\/\\])/g, "\\$1");
366
+ return new RegExp(`(url\\(['"]?)(${escaped})(['"]?\\))`, "g");
367
+ }
368
+ function parseURLs(cssText) {
369
+ const urls = [];
370
+ cssText.replace(URL_REGEX, (raw, quotation, url) => {
371
+ urls.push(url);
372
+ return raw;
373
+ });
374
+ return urls.filter((url) => !isDataUrl(url));
260
375
  }
261
- async function embed(e, t, n, r, i) {
376
+ async function embed(cssText, resourceURL, baseURL, options, getContentFromUrl) {
262
377
  try {
263
- let a = n ? resolveUrl(t, n) : t, o = getMimeType(t), s;
264
- return s = i ? makeDataUrl(await i(a), o) : await resourceToDataURL(a, o, r), e.replace(toRegex(t), `$1${s}$3`);
265
- } catch {}
266
- return e;
267
- }
268
- function filterPreferredFontFormat(e, { preferredFontFormat: t }) {
269
- return t ? e.replace(c, (e) => {
270
- for (;;) {
271
- let [n, , r] = s.exec(e) || [];
272
- if (!r) return "";
273
- if (r === t) return `src: ${n};`;
378
+ const resolvedURL = baseURL ? resolveUrl(resourceURL, baseURL) : resourceURL;
379
+ const contentType = getMimeType(resourceURL);
380
+ let dataURL;
381
+ if (getContentFromUrl) dataURL = makeDataUrl(await getContentFromUrl(resolvedURL), contentType);
382
+ else dataURL = await resourceToDataURL(resolvedURL, contentType, options);
383
+ return cssText.replace(toRegex(resourceURL), `$1${dataURL}$3`);
384
+ } catch (error) {}
385
+ return cssText;
386
+ }
387
+ function filterPreferredFontFormat(str, { preferredFontFormat }) {
388
+ return !preferredFontFormat ? str : str.replace(FONT_SRC_REGEX, (match) => {
389
+ while (true) {
390
+ const [src, , format] = URL_WITH_FORMAT_REGEX.exec(match) || [];
391
+ if (!format) return "";
392
+ if (format === preferredFontFormat) return `src: ${src};`;
274
393
  }
275
- }) : e;
394
+ });
276
395
  }
277
- function shouldEmbed(e) {
278
- return e.search(o) !== -1;
396
+ function shouldEmbed(url) {
397
+ return url.search(URL_REGEX) !== -1;
279
398
  }
280
- async function embedResources(e, t, n) {
281
- if (!shouldEmbed(e)) return e;
282
- let r = filterPreferredFontFormat(e, n);
283
- return parseURLs(r).reduce((e, r) => e.then((e) => embed(e, r, t, n)), Promise.resolve(r));
399
+ async function embedResources(cssText, baseUrl, options) {
400
+ if (!shouldEmbed(cssText)) return cssText;
401
+ const filteredCSSText = filterPreferredFontFormat(cssText, options);
402
+ return parseURLs(filteredCSSText).reduce((deferred, url) => deferred.then((css) => embed(css, url, baseUrl, options)), Promise.resolve(filteredCSSText));
284
403
  }
285
404
  //#endregion
286
405
  //#region ../../node_modules/.pnpm/html-to-image@1.11.11/node_modules/html-to-image/es/embed-images.js
287
- async function embedProp(e, t, n) {
288
- let r = t.style?.getPropertyValue(e);
289
- if (r) {
290
- let i = await embedResources(r, null, n);
291
- return t.style.setProperty(e, i, t.style.getPropertyPriority(e)), !0;
406
+ async function embedProp(propName, node, options) {
407
+ var _a;
408
+ const propValue = (_a = node.style) === null || _a === void 0 ? void 0 : _a.getPropertyValue(propName);
409
+ if (propValue) {
410
+ const cssString = await embedResources(propValue, null, options);
411
+ node.style.setProperty(propName, cssString, node.style.getPropertyPriority(propName));
412
+ return true;
292
413
  }
293
- return !1;
294
- }
295
- async function embedBackground(e, t) {
296
- await embedProp("background", e, t) || await embedProp("background-image", e, t), await embedProp("mask", e, t) || await embedProp("mask-image", e, t);
297
- }
298
- async function embedImageNode(e, t) {
299
- let n = isInstanceOfElement(e, HTMLImageElement);
300
- if ((!n || isDataUrl(e.src)) && (!isInstanceOfElement(e, SVGImageElement) || isDataUrl(e.href.baseVal))) return;
301
- let r = n ? e.src : e.href.baseVal, i = await resourceToDataURL(r, getMimeType(r), t);
302
- await new Promise((t, r) => {
303
- e.onload = t, e.onerror = r;
304
- let a = e;
305
- a.decode &&= t, a.loading === "lazy" && (a.loading = "eager"), n ? (e.srcset = "", e.src = i) : e.href.baseVal = i;
414
+ return false;
415
+ }
416
+ async function embedBackground(clonedNode, options) {
417
+ if (!await embedProp("background", clonedNode, options)) await embedProp("background-image", clonedNode, options);
418
+ if (!await embedProp("mask", clonedNode, options)) await embedProp("mask-image", clonedNode, options);
419
+ }
420
+ async function embedImageNode(clonedNode, options) {
421
+ const isImageElement = isInstanceOfElement(clonedNode, HTMLImageElement);
422
+ if (!(isImageElement && !isDataUrl(clonedNode.src)) && !(isInstanceOfElement(clonedNode, SVGImageElement) && !isDataUrl(clonedNode.href.baseVal))) return;
423
+ const url = isImageElement ? clonedNode.src : clonedNode.href.baseVal;
424
+ const dataURL = await resourceToDataURL(url, getMimeType(url), options);
425
+ await new Promise((resolve, reject) => {
426
+ clonedNode.onload = resolve;
427
+ clonedNode.onerror = reject;
428
+ const image = clonedNode;
429
+ if (image.decode) image.decode = resolve;
430
+ if (image.loading === "lazy") image.loading = "eager";
431
+ if (isImageElement) {
432
+ clonedNode.srcset = "";
433
+ clonedNode.src = dataURL;
434
+ } else clonedNode.href.baseVal = dataURL;
306
435
  });
307
436
  }
308
- async function embedChildren(e, t) {
309
- let n = toArray(e.childNodes).map((e) => embedImages(e, t));
310
- await Promise.all(n).then(() => e);
437
+ async function embedChildren(clonedNode, options) {
438
+ const deferreds = toArray(clonedNode.childNodes).map((child) => embedImages(child, options));
439
+ await Promise.all(deferreds).then(() => clonedNode);
311
440
  }
312
- async function embedImages(e, t) {
313
- isInstanceOfElement(e, Element) && (await embedBackground(e, t), await embedImageNode(e, t), await embedChildren(e, t));
441
+ async function embedImages(clonedNode, options) {
442
+ if (isInstanceOfElement(clonedNode, Element)) {
443
+ await embedBackground(clonedNode, options);
444
+ await embedImageNode(clonedNode, options);
445
+ await embedChildren(clonedNode, options);
446
+ }
314
447
  }
315
448
  //#endregion
316
449
  //#region ../../node_modules/.pnpm/html-to-image@1.11.11/node_modules/html-to-image/es/apply-style.js
317
- function applyStyle(e, t) {
318
- let { style: n } = e;
319
- t.backgroundColor && (n.backgroundColor = t.backgroundColor), t.width && (n.width = `${t.width}px`), t.height && (n.height = `${t.height}px`);
320
- let r = t.style;
321
- return r != null && Object.keys(r).forEach((e) => {
322
- n[e] = r[e];
323
- }), e;
450
+ function applyStyle(node, options) {
451
+ const { style } = node;
452
+ if (options.backgroundColor) style.backgroundColor = options.backgroundColor;
453
+ if (options.width) style.width = `${options.width}px`;
454
+ if (options.height) style.height = `${options.height}px`;
455
+ const manual = options.style;
456
+ if (manual != null) Object.keys(manual).forEach((key) => {
457
+ style[key] = manual[key];
458
+ });
459
+ return node;
324
460
  }
325
461
  //#endregion
326
462
  //#region ../../node_modules/.pnpm/html-to-image@1.11.11/node_modules/html-to-image/es/embed-webfonts.js
327
- var l = {};
328
- async function fetchCSS(e) {
329
- let t = l[e];
330
- return t ?? (t = {
331
- url: e,
332
- cssText: await (await fetch(e)).text()
333
- }, l[e] = t, t);
334
- }
335
- async function embedFonts(e, t) {
336
- let n = e.cssText, r = /url\(["']?([^"')]+)["']?\)/g, i = (n.match(/url\([^)]+\)/g) || []).map(async (i) => {
337
- let a = i.replace(r, "$1");
338
- return a.startsWith("https://") || (a = new URL(a, e.url).href), fetchAsDataURL(a, t.fetchRequestInit, ({ result: e }) => (n = n.replace(i, `url(${e})`), [i, e]));
463
+ var cssFetchCache = {};
464
+ async function fetchCSS(url) {
465
+ let cache = cssFetchCache[url];
466
+ if (cache != null) return cache;
467
+ cache = {
468
+ url,
469
+ cssText: await (await fetch(url)).text()
470
+ };
471
+ cssFetchCache[url] = cache;
472
+ return cache;
473
+ }
474
+ async function embedFonts(data, options) {
475
+ let cssText = data.cssText;
476
+ const regexUrl = /url\(["']?([^"')]+)["']?\)/g;
477
+ const loadFonts = (cssText.match(/url\([^)]+\)/g) || []).map(async (loc) => {
478
+ let url = loc.replace(regexUrl, "$1");
479
+ if (!url.startsWith("https://")) url = new URL(url, data.url).href;
480
+ return fetchAsDataURL(url, options.fetchRequestInit, ({ result }) => {
481
+ cssText = cssText.replace(loc, `url(${result})`);
482
+ return [loc, result];
483
+ });
339
484
  });
340
- return Promise.all(i).then(() => n);
341
- }
342
- function parseCSS(e) {
343
- if (e == null) return [];
344
- let t = [], n = e.replace(/(\/\*[\s\S]*?\*\/)/gi, ""), r = /* @__PURE__ */ RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})", "gi");
345
- for (;;) {
346
- let e = r.exec(n);
347
- if (e === null) break;
348
- t.push(e[0]);
485
+ return Promise.all(loadFonts).then(() => cssText);
486
+ }
487
+ function parseCSS(source) {
488
+ if (source == null) return [];
489
+ const result = [];
490
+ let cssText = source.replace(/(\/\*[\s\S]*?\*\/)/gi, "");
491
+ const keyframesRegex = /* @__PURE__ */ new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})", "gi");
492
+ while (true) {
493
+ const matches = keyframesRegex.exec(cssText);
494
+ if (matches === null) break;
495
+ result.push(matches[0]);
349
496
  }
350
- n = n.replace(r, "");
351
- let i = /@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi, a = /* @__PURE__ */ RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})", "gi");
352
- for (;;) {
353
- let e = i.exec(n);
354
- if (e === null) {
355
- if (e = a.exec(n), e === null) break;
356
- i.lastIndex = a.lastIndex;
357
- } else a.lastIndex = i.lastIndex;
358
- t.push(e[0]);
497
+ cssText = cssText.replace(keyframesRegex, "");
498
+ const importRegex = /@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi;
499
+ const unifiedRegex = /* @__PURE__ */ new RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})", "gi");
500
+ while (true) {
501
+ let matches = importRegex.exec(cssText);
502
+ if (matches === null) {
503
+ matches = unifiedRegex.exec(cssText);
504
+ if (matches === null) break;
505
+ else importRegex.lastIndex = unifiedRegex.lastIndex;
506
+ } else unifiedRegex.lastIndex = importRegex.lastIndex;
507
+ result.push(matches[0]);
359
508
  }
360
- return t;
361
- }
362
- async function getCSSRules(e, t) {
363
- let n = [], r = [];
364
- return e.forEach((n) => {
365
- if ("cssRules" in n) try {
366
- toArray(n.cssRules || []).forEach((e, i) => {
367
- if (e.type === CSSRule.IMPORT_RULE) {
368
- let a = i + 1, o = e.href, s = fetchCSS(o).then((e) => embedFonts(e, t)).then((e) => parseCSS(e).forEach((e) => {
509
+ return result;
510
+ }
511
+ async function getCSSRules(styleSheets, options) {
512
+ const ret = [];
513
+ const deferreds = [];
514
+ styleSheets.forEach((sheet) => {
515
+ if ("cssRules" in sheet) try {
516
+ toArray(sheet.cssRules || []).forEach((item, index) => {
517
+ if (item.type === CSSRule.IMPORT_RULE) {
518
+ let importIndex = index + 1;
519
+ const url = item.href;
520
+ const deferred = fetchCSS(url).then((metadata) => embedFonts(metadata, options)).then((cssText) => parseCSS(cssText).forEach((rule) => {
369
521
  try {
370
- n.insertRule(e, e.startsWith("@import") ? a += 1 : n.cssRules.length);
371
- } catch (t) {
522
+ sheet.insertRule(rule, rule.startsWith("@import") ? importIndex += 1 : sheet.cssRules.length);
523
+ } catch (error) {
372
524
  console.error("Error inserting rule from remote css", {
373
- rule: e,
374
- error: t
525
+ rule,
526
+ error
375
527
  });
376
528
  }
377
529
  })).catch((e) => {
378
530
  console.error("Error loading remote css", e.toString());
379
531
  });
380
- r.push(s);
532
+ deferreds.push(deferred);
381
533
  }
382
534
  });
383
- } catch (i) {
384
- let a = e.find((e) => e.href == null) || document.styleSheets[0];
385
- n.href != null && r.push(fetchCSS(n.href).then((e) => embedFonts(e, t)).then((e) => parseCSS(e).forEach((e) => {
386
- a.insertRule(e, n.cssRules.length);
387
- })).catch((e) => {
388
- console.error("Error loading remote stylesheet", e);
389
- })), console.error("Error inlining remote css file", i);
535
+ } catch (e) {
536
+ const inline = styleSheets.find((a) => a.href == null) || document.styleSheets[0];
537
+ if (sheet.href != null) deferreds.push(fetchCSS(sheet.href).then((metadata) => embedFonts(metadata, options)).then((cssText) => parseCSS(cssText).forEach((rule) => {
538
+ inline.insertRule(rule, sheet.cssRules.length);
539
+ })).catch((err) => {
540
+ console.error("Error loading remote stylesheet", err);
541
+ }));
542
+ console.error("Error inlining remote css file", e);
390
543
  }
391
- }), Promise.all(r).then(() => (e.forEach((e) => {
392
- if ("cssRules" in e) try {
393
- toArray(e.cssRules || []).forEach((e) => {
394
- n.push(e);
395
- });
396
- } catch (t) {
397
- console.error(`Error while reading CSS rules from ${e.href}`, t);
398
- }
399
- }), n));
544
+ });
545
+ return Promise.all(deferreds).then(() => {
546
+ styleSheets.forEach((sheet) => {
547
+ if ("cssRules" in sheet) try {
548
+ toArray(sheet.cssRules || []).forEach((item) => {
549
+ ret.push(item);
550
+ });
551
+ } catch (e) {
552
+ console.error(`Error while reading CSS rules from ${sheet.href}`, e);
553
+ }
554
+ });
555
+ return ret;
556
+ });
400
557
  }
401
- function getWebFontRules(e) {
402
- return e.filter((e) => e.type === CSSRule.FONT_FACE_RULE).filter((e) => shouldEmbed(e.style.getPropertyValue("src")));
558
+ function getWebFontRules(cssRules) {
559
+ return cssRules.filter((rule) => rule.type === CSSRule.FONT_FACE_RULE).filter((rule) => shouldEmbed(rule.style.getPropertyValue("src")));
403
560
  }
404
- async function parseWebFontRules(e, t) {
405
- if (e.ownerDocument == null) throw Error("Provided element is not within a Document");
406
- return getWebFontRules(await getCSSRules(toArray(e.ownerDocument.styleSheets), t));
561
+ async function parseWebFontRules(node, options) {
562
+ if (node.ownerDocument == null) throw new Error("Provided element is not within a Document");
563
+ return getWebFontRules(await getCSSRules(toArray(node.ownerDocument.styleSheets), options));
407
564
  }
408
- async function getWebFontCSS(e, t) {
409
- let n = await parseWebFontRules(e, t);
410
- return (await Promise.all(n.map((e) => {
411
- let n = e.parentStyleSheet ? e.parentStyleSheet.href : null;
412
- return embedResources(e.cssText, n, t);
565
+ async function getWebFontCSS(node, options) {
566
+ const rules = await parseWebFontRules(node, options);
567
+ return (await Promise.all(rules.map((rule) => {
568
+ const baseUrl = rule.parentStyleSheet ? rule.parentStyleSheet.href : null;
569
+ return embedResources(rule.cssText, baseUrl, options);
413
570
  }))).join("\n");
414
571
  }
415
- async function embedWebFonts(e, t) {
416
- let n = t.fontEmbedCSS == null ? t.skipFonts ? null : await getWebFontCSS(e, t) : t.fontEmbedCSS;
417
- if (n) {
418
- let t = document.createElement("style"), r = document.createTextNode(n);
419
- t.appendChild(r), e.firstChild ? e.insertBefore(t, e.firstChild) : e.appendChild(t);
572
+ async function embedWebFonts(clonedNode, options) {
573
+ const cssText = options.fontEmbedCSS != null ? options.fontEmbedCSS : options.skipFonts ? null : await getWebFontCSS(clonedNode, options);
574
+ if (cssText) {
575
+ const styleNode = document.createElement("style");
576
+ const sytleContent = document.createTextNode(cssText);
577
+ styleNode.appendChild(sytleContent);
578
+ if (clonedNode.firstChild) clonedNode.insertBefore(styleNode, clonedNode.firstChild);
579
+ else clonedNode.appendChild(styleNode);
420
580
  }
421
581
  }
422
582
  //#endregion
423
583
  //#region ../../node_modules/.pnpm/html-to-image@1.11.11/node_modules/html-to-image/es/index.js
424
- async function toSvg(e, t = {}) {
425
- let { width: n, height: r } = getImageSize(e, t), i = await cloneNode(e, t, !0);
426
- return await embedWebFonts(i, t), await embedImages(i, t), applyStyle(i, t), await nodeToDataURL(i, n, r);
427
- }
428
- async function toCanvas(e, t = {}) {
429
- let { width: n, height: r } = getImageSize(e, t), i = await createImage(await toSvg(e, t)), a = document.createElement("canvas"), o = a.getContext("2d"), s = t.pixelRatio || getPixelRatio(), c = t.canvasWidth || n, l = t.canvasHeight || r;
430
- return a.width = c * s, a.height = l * s, t.skipAutoScale || checkCanvasDimensions(a), a.style.width = `${c}`, a.style.height = `${l}`, t.backgroundColor && (o.fillStyle = t.backgroundColor, o.fillRect(0, 0, a.width, a.height)), o.drawImage(i, 0, 0, a.width, a.height), a;
584
+ async function toSvg(node, options = {}) {
585
+ const { width, height } = getImageSize(node, options);
586
+ const clonedNode = await cloneNode(node, options, true);
587
+ await embedWebFonts(clonedNode, options);
588
+ await embedImages(clonedNode, options);
589
+ applyStyle(clonedNode, options);
590
+ return await nodeToDataURL(clonedNode, width, height);
591
+ }
592
+ async function toCanvas(node, options = {}) {
593
+ const { width, height } = getImageSize(node, options);
594
+ const img = await createImage(await toSvg(node, options));
595
+ const canvas = document.createElement("canvas");
596
+ const context = canvas.getContext("2d");
597
+ const ratio = options.pixelRatio || getPixelRatio();
598
+ const canvasWidth = options.canvasWidth || width;
599
+ const canvasHeight = options.canvasHeight || height;
600
+ canvas.width = canvasWidth * ratio;
601
+ canvas.height = canvasHeight * ratio;
602
+ if (!options.skipAutoScale) checkCanvasDimensions(canvas);
603
+ canvas.style.width = `${canvasWidth}`;
604
+ canvas.style.height = `${canvasHeight}`;
605
+ if (options.backgroundColor) {
606
+ context.fillStyle = options.backgroundColor;
607
+ context.fillRect(0, 0, canvas.width, canvas.height);
608
+ }
609
+ context.drawImage(img, 0, 0, canvas.width, canvas.height);
610
+ return canvas;
431
611
  }
432
- async function toJpeg(e, t = {}) {
433
- return (await toCanvas(e, t)).toDataURL("image/jpeg", t.quality || 1);
612
+ async function toJpeg(node, options = {}) {
613
+ return (await toCanvas(node, options)).toDataURL("image/jpeg", options.quality || 1);
434
614
  }
435
- async function toBlob(e, t = {}) {
436
- return await canvasToBlob(await toCanvas(e, t));
615
+ async function toBlob(node, options = {}) {
616
+ return await canvasToBlob(await toCanvas(node, options));
437
617
  }
438
618
  //#endregion
439
619
  export { toBlob, toJpeg };