@billtaofbj/mindmap 1.0.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.
@@ -0,0 +1,307 @@
1
+ import { B as e, H as t, Ot as n, Q as r, at as i, et as a, n as o, nt as s, pt as c, wt as l, x as u } from "./utils-DjW7eJ1w.mjs";
2
+ //#region ../../node_modules/.pnpm/simple-mind-map@0.14.0-fix.2/node_modules/simple-mind-map/src/utils/simulateCSSBackgroundInCanvas.js
3
+ var d = (e) => String(e).split(/\s+/).map((e) => {
4
+ if (/^[\d.]+/.test(e)) {
5
+ let t = /^([\d.]+)(.*)$/.exec(e);
6
+ return [Number(t[1]), t[2]];
7
+ } else return e;
8
+ }), f = (e, t) => e * t, p = (e, t) => t / e, m = {
9
+ left: 0,
10
+ top: 0,
11
+ center: 50,
12
+ bottom: 100,
13
+ right: 100
14
+ }, h = ({ backgroundSize: e, drawOpt: t, imageRatio: n, canvasWidth: r, canvasHeight: i, canvasRatio: a }) => {
15
+ if (e) {
16
+ let o = d(e);
17
+ if (o[0] === "auto" && o[1] === "auto") return;
18
+ if (o[0] === "cover") {
19
+ n > a ? (t.height = i, t.width = f(n, i)) : (t.width = r, t.height = p(n, r));
20
+ return;
21
+ }
22
+ if (o[0] === "contain") {
23
+ n > a ? (t.width = r, t.height = p(n, r)) : (t.height = i, t.width = f(n, i));
24
+ return;
25
+ }
26
+ let s = -1;
27
+ o[0] && (Array.isArray(o[0]) ? o[0][1] === "%" ? (t.width = o[0][0] / 100 * r, s = t.width) : (t.width = o[0][0], s = o[0][0]) : o[0] === "auto" && o[1] && (o[1][1] === "%" ? t.width = f(n, o[1][0] / 100 * i) : t.width = f(n, o[1][0]))), o[1] && Array.isArray(o[1]) ? o[1][1] === "%" ? t.height = o[1][0] / 100 * i : t.height = o[1][0] : s !== -1 && (t.height = p(n, s));
28
+ }
29
+ }, g = ({ backgroundPosition: e, drawOpt: t, imgWidth: n, imgHeight: r, canvasWidth: i, canvasHeight: a }) => {
30
+ if (e) {
31
+ let o = d(e);
32
+ o = o.map((e) => typeof e == "string" ? m[e] === void 0 ? e : [m[e], "%"] : e), Array.isArray(o[0]) && (o.length === 1 && o.push([50, "%"]), o[0][1] === "%" ? t.x = o[0][0] / 100 * i - o[0][0] / 100 * n : t.x = o[0][0], o[1][1] === "%" ? t.y = o[1][0] / 100 * a - o[1][0] / 100 * r : t.y = o[1][0]);
33
+ }
34
+ }, _ = ({ ctx: e, image: t, backgroundRepeat: n, drawOpt: r, imgWidth: i, imgHeight: a, canvasWidth: o, canvasHeight: s }) => {
35
+ if (n) {
36
+ let c = r.x, l = r.y, u = Math.ceil(c / i), f = Math.ceil(l / a), p = c - u * i, m = l - f * a, h = d(n);
37
+ if (h[0] === "no-repeat" || i >= o && a >= s) return;
38
+ if (h[0] === "repeat-x" && o > i) {
39
+ let n = p;
40
+ for (; n < o;) v(e, t, {
41
+ ...r,
42
+ x: n
43
+ }), n += i;
44
+ return !0;
45
+ }
46
+ if (h[0] === "repeat-y" && s > a) {
47
+ let n = m;
48
+ for (; n < s;) v(e, t, {
49
+ ...r,
50
+ y: n
51
+ }), n += a;
52
+ return !0;
53
+ }
54
+ if (h[0] === "repeat") {
55
+ let n = p;
56
+ for (; n < o;) {
57
+ if (s > a) {
58
+ let i = m;
59
+ for (; i < s;) v(e, t, {
60
+ ...r,
61
+ x: n,
62
+ y: i
63
+ }), i += a;
64
+ }
65
+ n += i;
66
+ }
67
+ return !0;
68
+ }
69
+ }
70
+ }, v = (e, t, n) => {
71
+ e.drawImage(t, n.sx, n.sy, n.swidth, n.sheight, n.x, n.y, n.width, n.height);
72
+ }, y = (e, t, n, r, { backgroundSize: i, backgroundPosition: a, backgroundRepeat: o }, s = () => {}) => {
73
+ let c = t / n, l = new Image();
74
+ l.src = r, l.onload = () => {
75
+ let r = l.width, u = l.height, d = r / u, f = {
76
+ sx: 0,
77
+ sy: 0,
78
+ swidth: r,
79
+ sheight: u,
80
+ x: 0,
81
+ y: 0,
82
+ width: r,
83
+ height: u
84
+ };
85
+ h({
86
+ backgroundSize: i,
87
+ drawOpt: f,
88
+ imageRatio: d,
89
+ canvasWidth: t,
90
+ canvasHeight: n,
91
+ canvasRatio: c
92
+ }), g({
93
+ backgroundPosition: a,
94
+ drawOpt: f,
95
+ imgWidth: f.width,
96
+ imgHeight: f.height,
97
+ imageRatio: d,
98
+ canvasWidth: t,
99
+ canvasHeight: n,
100
+ canvasRatio: c
101
+ }), _({
102
+ ctx: e,
103
+ image: l,
104
+ backgroundRepeat: o,
105
+ drawOpt: f,
106
+ imgWidth: f.width,
107
+ imgHeight: f.height,
108
+ imageRatio: d,
109
+ canvasWidth: t,
110
+ canvasHeight: n,
111
+ canvasRatio: c
112
+ }) || v(e, l, f), s();
113
+ }, l.onerror = (e) => {
114
+ s(e);
115
+ };
116
+ }, b = (e) => e.richText ? r(e.text) : e.text, x = (e) => Array(e).fill("#").join(""), S = (e) => Array(e - 6).fill(" ").join("") + "*", C = (e) => {
117
+ let t = "";
118
+ return c(e, null, (e, n, r, i) => {
119
+ let a = i + 1;
120
+ a <= 6 ? t += x(a) : t += S(a), t += " " + b(e.data);
121
+ let o = e.data.generalization;
122
+ if (Array.isArray(o)) t += o.map((e) => ` [${b(e)}]`);
123
+ else if (o && o.text) {
124
+ let e = b(o);
125
+ t += ` [${e}]`;
126
+ }
127
+ t += "\n\n", e.data.note && (t += e.data.note + "\n\n");
128
+ }, () => {}, !0), t;
129
+ }, w = (e) => e.richText ? r(e.text) : e.text, T = (e) => Array(e).fill(" ").join(""), E = (e) => {
130
+ let t = "";
131
+ return c(e, null, (e, n, r, i) => {
132
+ t += T(i), t += " " + w(e.data);
133
+ let a = e.data.generalization;
134
+ Array.isArray(a) ? t += a.map((e) => ` [${w(e)}]`) : a && a.text && (t += ` [${w(a)}]`), t += "\n\n";
135
+ }, () => {}, !0), t;
136
+ }, D = class {
137
+ constructor(e) {
138
+ this.mindMap = e.mindMap;
139
+ }
140
+ async export(e, t = !0, n = "思维导图", ...r) {
141
+ if (this[e]) {
142
+ let i = await this[e](n, ...r);
143
+ return t && u(i, n + "." + e), i;
144
+ } else return null;
145
+ }
146
+ createTransformImgTaskList(e, n, r, i) {
147
+ return e.find(n).map(async (e) => {
148
+ let n = i(e);
149
+ if (/^data:/.test(n) || n === "none") return;
150
+ let a = await t(n);
151
+ e.attr(r, a);
152
+ });
153
+ }
154
+ async getSvgData(e) {
155
+ let { exportPaddingX: t, exportPaddingY: r, errorHandler: i, resetCss: a, addContentToHeader: s, addContentToFooter: c, handleBeingExportSvg: u } = this.mindMap.opt, { svg: d, svgHTML: f, clipData: p } = this.mindMap.getSvgData({
156
+ paddingX: t,
157
+ paddingY: r,
158
+ addContentToHeader: s,
159
+ addContentToFooter: c,
160
+ node: e
161
+ });
162
+ p && (p.paddingX = t, p.paddingY = r);
163
+ let m = !1, h = this.createTransformImgTaskList(d, "image", "href", (e) => e.attr("href") || e.attr("xlink:href")), g = this.createTransformImgTaskList(d, "img", "src", (e) => e.attr("src")), _ = [...h, ...g];
164
+ try {
165
+ await Promise.all(_);
166
+ } catch (e) {
167
+ i(n.EXPORT_LOAD_IMAGE_ERROR, e);
168
+ }
169
+ if (this.mindMap.richText) {
170
+ let e = d.find("foreignObject");
171
+ if (e.length > 0 && (e[0].add(l(`<style>${a}</style>`)), m = !0), this.mindMap.formula && d.find(".ql-formula").length > 0) {
172
+ let t = this.mindMap.formula.getStyleText();
173
+ if (t) {
174
+ let n = document.createElement("style");
175
+ n.innerHTML = t, o(n), e[0].add(n), m = !0;
176
+ }
177
+ }
178
+ }
179
+ return typeof u == "function" && (m = !0, d = u(d)), (_.length > 0 || m) && (f = d.svg()), {
180
+ node: d,
181
+ str: f,
182
+ clipData: p
183
+ };
184
+ }
185
+ svgToPng(e, t, n = null, r = !1, a = "image/png") {
186
+ let { maxCanvasSize: o, minExportImgCanvasScale: s } = this.mindMap.opt;
187
+ return new Promise((c, l) => {
188
+ let u = new Image();
189
+ u.setAttribute("crossOrigin", "anonymous"), u.onload = async () => {
190
+ try {
191
+ let e = document.createElement("canvas"), l = Math.max(window.devicePixelRatio, s), d = u.width, f = u.height, p = 0, m = 0;
192
+ n && (p = n.paddingX, m = n.paddingY, d = n.width + p * 2, f = n.height + m * 2);
193
+ let h = 0, g = 0, { backgroundImage: _ } = this.mindMap.themeConfig;
194
+ if (r && _ && !t) {
195
+ let e = await new Promise((e) => {
196
+ let t = new Image();
197
+ t.onload = () => {
198
+ e([t.width, t.height]);
199
+ }, t.onerror = () => {
200
+ e(null);
201
+ }, t.src = _;
202
+ });
203
+ if (e) {
204
+ let t = d / f, n = e[0] / e[1];
205
+ t > n ? (h = d, g = d / n) : (g = f, h = f * n);
206
+ }
207
+ }
208
+ let v = 1, y = 1, b = (h || d) * l, x = (g || f) * l;
209
+ if (b > o || x > o) {
210
+ let e = null, t = null;
211
+ b > o ? e = o : x > o && (t = o);
212
+ let n = i(b, x, e, t);
213
+ v = n[0] / b, y = n[1] / x, b = n[0], x = n[1];
214
+ }
215
+ e.width = b, e.height = x;
216
+ let S = b / l, C = x / l;
217
+ e.style.width = S + "px", e.style.height = C + "px";
218
+ let w = e.getContext("2d");
219
+ w.scale(l, l), t || await this.drawBackgroundToCanvas(w, S, C);
220
+ let T = (h > 0 ? (h - d) / 2 : 0) * v, E = (g > 0 ? (g - f) / 2 : 0) * y;
221
+ n ? w.drawImage(u, n.left, n.top, n.width, n.height, p * v + T, m * y + E, n.width * v, n.height * y) : w.drawImage(u, T, E, d * v, f * y), c(e.toDataURL(a));
222
+ } catch (e) {
223
+ l(e);
224
+ }
225
+ }, u.onerror = (e) => {
226
+ l(e);
227
+ }, u.src = e;
228
+ });
229
+ }
230
+ drawBackgroundToCanvas(e, t, n) {
231
+ return new Promise((r, i) => {
232
+ let { backgroundColor: a = "#fff", backgroundImage: o, backgroundRepeat: s = "no-repeat", backgroundPosition: c = "center center", backgroundSize: l = "cover" } = this.mindMap.themeConfig;
233
+ e.save(), e.rect(0, 0, t, n), e.fillStyle = a, e.fill(), e.restore(), o && o !== "none" ? (e.save(), y(e, t, n, o, {
234
+ backgroundRepeat: s,
235
+ backgroundPosition: c,
236
+ backgroundSize: l
237
+ }, (t) => {
238
+ t ? i(t) : r(), e.restore();
239
+ })) : r();
240
+ });
241
+ }
242
+ drawBackgroundToSvg(e) {
243
+ return new Promise(async (n) => {
244
+ let { backgroundColor: r = "#fff", backgroundImage: i, backgroundRepeat: a = "repeat" } = this.mindMap.themeConfig;
245
+ if (e.css("background-color", r), i && i !== "none") {
246
+ let r = await t(i);
247
+ e.css("background-image", `url(${r})`), e.css("background-repeat", a), n();
248
+ } else n();
249
+ });
250
+ }
251
+ async _image(e, t, n = !1, r = null, i = !1) {
252
+ this.mindMap.renderer.textEdit.hideEditTextBox(), this.handleNodeExport(r);
253
+ let { str: a, clipData: o } = await this.getSvgData(r), s = await this.fixSvgStrAndToBlob(a);
254
+ return await this.svgToPng(s, n, o, i, e);
255
+ }
256
+ async png(...e) {
257
+ return await this._image("image/png", ...e);
258
+ }
259
+ async jpg(...e) {
260
+ return await this._image("image/jpg", ...e);
261
+ }
262
+ handleNodeExport(e) {
263
+ if (e && e.getData("isActive")) {
264
+ e.deactivate();
265
+ let { alwaysShowExpandBtn: t, notShowExpandBtn: n } = this.mindMap.opt;
266
+ !t && !n && e.getData("expand") && e.removeExpandBtn();
267
+ }
268
+ }
269
+ async pdf(e, t = !1, n = !1) {
270
+ if (!this.mindMap.doExportPDF) throw Error("请注册ExportPDF插件");
271
+ let r = await this.png(e, t, null, n);
272
+ return await this.mindMap.doExportPDF.pdf(r);
273
+ }
274
+ async xmind(e) {
275
+ if (!this.mindMap.doExportXMind) throw Error("请注册ExportXMind插件");
276
+ let t = this.mindMap.getData();
277
+ return await a(await this.mindMap.doExportXMind.xmind(t, e));
278
+ }
279
+ async svg(e) {
280
+ this.mindMap.renderer.textEdit.hideEditTextBox();
281
+ let { node: t } = await this.getSvgData();
282
+ t.first().before(l(`<title>${e}</title>`)), await this.drawBackgroundToSvg(t);
283
+ let n = t.svg();
284
+ return await this.fixSvgStrAndToBlob(n);
285
+ }
286
+ async fixSvgStrAndToBlob(t) {
287
+ return t = s(t), t = e(t), await a(new Blob([t], { type: "image/svg+xml" }));
288
+ }
289
+ async json(e, t = !0) {
290
+ let n = this.mindMap.getData(t), r = JSON.stringify(n);
291
+ return await a(new Blob([r]));
292
+ }
293
+ async smm(e, t) {
294
+ return await this.json(e, t);
295
+ }
296
+ async md() {
297
+ let e = C(this.mindMap.getData());
298
+ return await a(new Blob([e]));
299
+ }
300
+ async txt() {
301
+ let e = E(this.mindMap.getData());
302
+ return await a(new Blob([e]));
303
+ }
304
+ };
305
+ D.instanceName = "doExport";
306
+ //#endregion
307
+ export { D as default };