likec4 1.59.3 → 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.
- package/__app__/codegen/react.mjs +6 -6
- package/__app__/codegen/webcomponent.mjs +147 -69
- package/__app__/src/aichat/index.mjs +10 -5
- package/__app__/src/chunks/AIChat.mjs +1134 -693
- package/__app__/src/chunks/LikeC4Styles.mjs +4101 -1737
- package/__app__/src/chunks/ProjectsOverview.mjs +624 -334
- package/__app__/src/chunks/es.mjs +515 -335
- package/__app__/src/chunks/hooks.mjs +578 -366
- package/__app__/src/chunks/libs/@floating-ui.mjs +2720 -1966
- package/__app__/src/chunks/libs/@mantine.mjs +14067 -9487
- package/__app__/src/chunks/libs/@tanstack-ai.mjs +2266 -1146
- package/__app__/src/chunks/libs/@tanstack.mjs +3152 -1932
- package/__app__/src/chunks/libs/@xstate/react.mjs +2924 -1468
- package/__app__/src/chunks/libs/@xyflow/react.mjs +6627 -4067
- package/__app__/src/chunks/libs/bezier-js.mjs +1312 -726
- package/__app__/src/chunks/libs/d3.mjs +3218 -1509
- package/__app__/src/chunks/libs/fast-equals.mjs +437 -201
- package/__app__/src/chunks/libs/framer.mjs +9251 -3846
- package/__app__/src/chunks/libs/nanostores.mjs +174 -0
- package/__app__/src/chunks/libs/zod.mjs +4591 -2363
- package/__app__/src/chunks/rolldown-runtime.mjs +39 -23
- package/__app__/src/chunks/styled-system.mjs +3538 -756
- package/__app__/src/fonts.css +112 -1
- package/__app__/src/main.mjs +44398 -24039
- package/__app__/src/style.css +18488 -1
- package/config/schema.json +136 -97
- package/dist/app/render-view-client.css +1 -1
- package/dist/app/render-view-client.js +506 -338
- package/dist/chunks/enableServer.mjs +1 -1
- package/dist/chunks/filenames.mjs +16 -14
- package/dist/chunks/generate-likec4.mjs +5 -0
- package/dist/chunks/index.d.mts +246 -180
- package/dist/chunks/index2.d.mts +2882 -1977
- package/dist/chunks/libs/@chevrotain/gast.mjs +27 -1
- package/dist/chunks/libs/@chevrotain/regexp-to-ast.mjs +81 -9
- package/dist/chunks/libs/@chevrotain/types.d.mts +111 -0
- package/dist/chunks/libs/@logtape/logtape.mjs +5 -4
- package/dist/chunks/libs/@lume/kiwi.mjs +1 -1
- package/dist/chunks/libs/@ts-graphviz/core.mjs +1 -1
- package/dist/chunks/libs/birpc.mjs +1 -1
- package/dist/chunks/libs/chevrotain-allstar.mjs +2 -2
- package/dist/chunks/libs/chevrotain.mjs +87 -35
- package/dist/chunks/libs/eventemitter3.mjs +1 -1
- package/dist/chunks/libs/json5.mjs +4 -4
- package/dist/chunks/libs/langium.d.mts +9903 -5297
- package/dist/chunks/libs/langium.mjs +16 -24
- package/dist/chunks/libs/merge-error-cause.mjs +1 -1
- package/dist/chunks/libs/p-limit.mjs +1 -0
- package/dist/chunks/libs/p-queue.mjs +1 -1
- package/dist/chunks/libs/package-manager-detector.mjs +1 -1
- package/dist/chunks/libs/pako.mjs +2 -2
- package/dist/chunks/libs/pretty-ms.mjs +1 -1
- package/dist/chunks/libs/remeda.mjs +1 -1
- package/dist/chunks/libs/ufo.mjs +1 -1
- package/dist/chunks/libs/unstorage.mjs +1 -1
- package/dist/chunks/libs/which.mjs +1 -1
- package/dist/chunks/node.mjs +60 -60
- package/dist/chunks/rolldown-runtime.mjs +1 -1
- package/dist/chunks/sequence-view.mjs +1 -1
- package/dist/chunks/vite-plugin.mjs +55 -52
- package/dist/cli/index.d.mts +1 -1
- package/dist/cli/index.mjs +208 -1300
- package/dist/config/index.d.mts +2 -2
- package/dist/generators/likec4.d.mts +6578 -0
- package/dist/generators/likec4.mjs +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/model/index.d.mts +8 -5
- package/dist/vite-plugin/index.d.mts +6 -3
- package/dist/vite-plugin/index.mjs +1 -1
- package/dist/vite-plugin/internal/chunks/rolldown-runtime.mjs +9 -0
- package/dist/vite-plugin/internal/index.d.mts +16 -15
- package/dist/vite-plugin/internal/index.mjs +144 -46
- package/generators/likec4/package.json +4 -0
- package/package.json +117 -110
- package/react/index.d.mts +8500 -5399
- package/react/index.mjs +534 -58617
- package/react/rolldown-runtime-DnkiqaRY.js +1 -0
- package/skills/likec4-dsl/SKILL.md +428 -0
- package/skills/likec4-dsl/evals/evals-public.json +202 -0
- package/skills/likec4-dsl/evals/grading-spec.json +589 -0
- package/skills/likec4-dsl/references/bridge-leanix-drawio.md +42 -0
- package/skills/likec4-dsl/references/cli.md +139 -0
- package/skills/likec4-dsl/references/configuration.md +266 -0
- package/skills/likec4-dsl/references/deployment.md +160 -0
- package/skills/likec4-dsl/references/dynamic-views.md +455 -0
- package/skills/likec4-dsl/references/examples.md +370 -0
- package/skills/likec4-dsl/references/identifier-validity.md +90 -0
- package/skills/likec4-dsl/references/include-predicates-wildcards.md +179 -0
- package/skills/likec4-dsl/references/model.md +151 -0
- package/skills/likec4-dsl/references/predicates.md +123 -0
- package/skills/likec4-dsl/references/relationships-bidirectional.md +176 -0
- package/skills/likec4-dsl/references/specification.md +75 -0
- package/skills/likec4-dsl/references/style-tokens-colors.md +150 -0
- package/skills/likec4-dsl/references/troubleshooting.md +96 -0
- package/skills/likec4-dsl/references/views.md +329 -0
- package/vite-plugin-modules.d.ts +4 -2
- package/dist/chunks/libs/picomatch.mjs +0 -1
- package/dist/chunks/libs/zod.d.mts +0 -2140
- 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(
|
|
4
|
-
if (
|
|
5
|
-
if (
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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(
|
|
15
|
-
|
|
16
|
-
for (let
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
function px(
|
|
20
|
-
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
function getNodeWidth(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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:
|
|
34
|
-
height:
|
|
45
|
+
width: options.width || getNodeWidth(targetNode),
|
|
46
|
+
height: options.height || getNodeHeight(targetNode)
|
|
35
47
|
};
|
|
36
48
|
}
|
|
37
49
|
function getPixelRatio() {
|
|
38
|
-
let
|
|
50
|
+
let ratio;
|
|
51
|
+
let FINAL_PROCESS;
|
|
39
52
|
try {
|
|
40
|
-
|
|
41
|
-
} catch {}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|
59
|
-
return new Promise((
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
65
|
-
return Promise
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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(
|
|
79
|
-
|
|
80
|
-
return `${
|
|
81
|
-
}
|
|
82
|
-
function formatCSSProperties(
|
|
83
|
-
return toArray(
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
95
|
-
} catch {
|
|
152
|
+
clonedNode.className = `${clonedNode.className} ${className}`;
|
|
153
|
+
} catch (err) {
|
|
96
154
|
return;
|
|
97
155
|
}
|
|
98
|
-
|
|
99
|
-
|
|
156
|
+
const styleElement = document.createElement("style");
|
|
157
|
+
styleElement.appendChild(getPseudoElementStyle(className, pseudo, style));
|
|
158
|
+
clonedNode.appendChild(styleElement);
|
|
100
159
|
}
|
|
101
|
-
function clonePseudoElements(
|
|
102
|
-
clonePseudoElement(
|
|
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
|
|
107
|
-
|
|
108
|
-
|
|
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:
|
|
113
|
-
jpeg:
|
|
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(
|
|
120
|
-
|
|
121
|
-
return
|
|
181
|
+
function getExtension(url) {
|
|
182
|
+
const match = /\.([^./]*?)$/g.exec(url);
|
|
183
|
+
return match ? match[1] : "";
|
|
122
184
|
}
|
|
123
|
-
function getMimeType(
|
|
124
|
-
return
|
|
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(
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
function isDataUrl(
|
|
132
|
-
return
|
|
133
|
-
}
|
|
134
|
-
function makeDataUrl(
|
|
135
|
-
return `data:${
|
|
136
|
-
}
|
|
137
|
-
async function fetchAsDataURL(
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
|
|
141
|
-
return new Promise((
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
146
|
-
res
|
|
147
|
-
result:
|
|
208
|
+
resolve(process({
|
|
209
|
+
res,
|
|
210
|
+
result: reader.result
|
|
148
211
|
}));
|
|
149
|
-
} catch (
|
|
150
|
-
|
|
212
|
+
} catch (error) {
|
|
213
|
+
reject(error);
|
|
151
214
|
}
|
|
152
|
-
}
|
|
215
|
+
};
|
|
216
|
+
reader.readAsDataURL(blob);
|
|
153
217
|
});
|
|
154
218
|
}
|
|
155
|
-
var
|
|
156
|
-
function getCacheKey(
|
|
157
|
-
let
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
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(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
186
|
-
return createImage(await resourceToDataURL(
|
|
261
|
+
const poster = video.poster;
|
|
262
|
+
return createImage(await resourceToDataURL(poster, getMimeType(poster), options));
|
|
187
263
|
}
|
|
188
|
-
async function cloneIFrameElement(
|
|
264
|
+
async function cloneIFrameElement(iframe) {
|
|
265
|
+
var _a;
|
|
189
266
|
try {
|
|
190
|
-
if (
|
|
191
|
-
} catch {}
|
|
192
|
-
return
|
|
193
|
-
}
|
|
194
|
-
async function cloneSingleNode(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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(
|
|
214
|
-
isInstanceOfElement(
|
|
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(
|
|
217
|
-
if (isInstanceOfElement(
|
|
218
|
-
|
|
219
|
-
|
|
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(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
237
|
-
if (
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
|
353
|
+
return clone;
|
|
246
354
|
}
|
|
247
|
-
async function cloneNode(
|
|
248
|
-
|
|
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
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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(
|
|
376
|
+
async function embed(cssText, resourceURL, baseURL, options, getContentFromUrl) {
|
|
262
377
|
try {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
})
|
|
394
|
+
});
|
|
276
395
|
}
|
|
277
|
-
function shouldEmbed(
|
|
278
|
-
return
|
|
396
|
+
function shouldEmbed(url) {
|
|
397
|
+
return url.search(URL_REGEX) !== -1;
|
|
279
398
|
}
|
|
280
|
-
async function embedResources(
|
|
281
|
-
if (!shouldEmbed(
|
|
282
|
-
|
|
283
|
-
return parseURLs(
|
|
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(
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
|
294
|
-
}
|
|
295
|
-
async function embedBackground(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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(
|
|
309
|
-
|
|
310
|
-
await Promise.all(
|
|
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(
|
|
313
|
-
isInstanceOfElement(
|
|
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(
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
|
328
|
-
async function fetchCSS(
|
|
329
|
-
let
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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(
|
|
341
|
-
}
|
|
342
|
-
function parseCSS(
|
|
343
|
-
if (
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
|
361
|
-
}
|
|
362
|
-
async function getCSSRules(
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
-
|
|
371
|
-
} catch (
|
|
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
|
|
374
|
-
error
|
|
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
|
-
|
|
532
|
+
deferreds.push(deferred);
|
|
381
533
|
}
|
|
382
534
|
});
|
|
383
|
-
} catch (
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
})).catch((
|
|
388
|
-
console.error("Error loading remote stylesheet",
|
|
389
|
-
}))
|
|
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
|
-
})
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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(
|
|
402
|
-
return
|
|
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(
|
|
405
|
-
if (
|
|
406
|
-
return getWebFontRules(await getCSSRules(toArray(
|
|
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(
|
|
409
|
-
|
|
410
|
-
return (await Promise.all(
|
|
411
|
-
|
|
412
|
-
return embedResources(
|
|
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(
|
|
416
|
-
|
|
417
|
-
if (
|
|
418
|
-
|
|
419
|
-
|
|
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(
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
return
|
|
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(
|
|
433
|
-
return (await toCanvas(
|
|
612
|
+
async function toJpeg(node, options = {}) {
|
|
613
|
+
return (await toCanvas(node, options)).toDataURL("image/jpeg", options.quality || 1);
|
|
434
614
|
}
|
|
435
|
-
async function toBlob(
|
|
436
|
-
return await canvasToBlob(await toCanvas(
|
|
615
|
+
async function toBlob(node, options = {}) {
|
|
616
|
+
return await canvasToBlob(await toCanvas(node, options));
|
|
437
617
|
}
|
|
438
618
|
//#endregion
|
|
439
619
|
export { toBlob, toJpeg };
|