@leafer-in/export 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/export.cjs +214 -165
- package/dist/export.esm.js +212 -163
- package/dist/export.esm.min.js +1 -1
- package/dist/export.esm.min.js.map +1 -1
- package/dist/export.js +199 -169
- package/dist/export.min.cjs +1 -1
- package/dist/export.min.cjs.map +1 -1
- package/dist/export.min.js +1 -1
- package/dist/export.min.js.map +1 -1
- package/package.json +4 -4
- package/src/export.ts +108 -99
- package/src/trim.ts +5 -2
- package/types/index.d.ts +1 -1
package/dist/export.js
CHANGED
|
@@ -1,42 +1,40 @@
|
|
|
1
|
-
(function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1
|
+
(function(draw) {
|
|
2
|
+
"use strict";
|
|
3
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
6
|
+
resolve(value);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
10
|
+
function fulfilled(value) {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.next(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function step(result) {
|
|
25
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
26
|
+
}
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
31
|
+
var e = new Error(message);
|
|
32
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
34
33
|
};
|
|
35
|
-
|
|
36
|
-
const { setPoint, addPoint, toBounds } = draw.TwoPointBoundsHelper;
|
|
34
|
+
const {setPoint: setPoint, addPoint: addPoint, toBounds: toBounds} = draw.TwoPointBoundsHelper;
|
|
37
35
|
function getTrimBounds(canvas) {
|
|
38
|
-
const { width, height } = canvas.view;
|
|
39
|
-
const { data
|
|
36
|
+
const {width: width, height: height} = canvas.view;
|
|
37
|
+
const {data: data} = canvas.context.getImageData(0, 0, width, height);
|
|
40
38
|
let x, y, pointBounds, index = 0;
|
|
41
39
|
for (let i = 0; i < data.length; i += 4) {
|
|
42
40
|
if (data[i + 3] !== 0) {
|
|
@@ -46,196 +44,228 @@
|
|
|
46
44
|
}
|
|
47
45
|
index++;
|
|
48
46
|
}
|
|
49
|
-
const bounds = new draw.Bounds
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
const bounds = new draw.Bounds;
|
|
48
|
+
if (pointBounds) {
|
|
49
|
+
toBounds(pointBounds, bounds);
|
|
50
|
+
bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
51
|
+
}
|
|
52
|
+
return bounds;
|
|
52
53
|
}
|
|
53
|
-
|
|
54
54
|
const ExportModule = {
|
|
55
55
|
syncExport(leaf, filename, options) {
|
|
56
|
-
|
|
56
|
+
draw.Export.running = true;
|
|
57
57
|
let result;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
58
|
+
try {
|
|
59
|
+
const fileType = draw.FileHelper.fileType(filename);
|
|
60
|
+
const isDownload = filename.includes(".");
|
|
61
|
+
options = draw.FileHelper.getExportOptions(options);
|
|
62
|
+
const {toURL: toURL} = draw.Platform;
|
|
63
|
+
const {download: download} = draw.Platform.origin;
|
|
64
|
+
if (fileType === "json") {
|
|
65
|
+
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), "text"), filename);
|
|
66
|
+
result = {
|
|
67
|
+
data: isDownload ? true : leaf.toJSON(options.json)
|
|
68
|
+
};
|
|
69
|
+
} else if (fileType === "svg") {
|
|
70
|
+
isDownload && download(toURL(leaf.toSVG(), "svg"), filename);
|
|
71
|
+
result = {
|
|
72
|
+
data: isDownload ? true : leaf.toSVG()
|
|
73
|
+
};
|
|
74
|
+
} else {
|
|
75
|
+
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
76
|
+
const {worldTransform: worldTransform, isLeafer: isLeafer, leafer: leafer, isFrame: isFrame} = leaf;
|
|
77
|
+
const {slice: slice, clip: clip, trim: trim, screenshot: screenshot, padding: padding, onCanvas: onCanvas} = options;
|
|
78
|
+
const smooth = draw.isUndefined(options.smooth) ? leafer ? leafer.config.smooth : true : options.smooth;
|
|
79
|
+
const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
|
|
80
|
+
const fill = isLeafer && screenshot ? draw.isUndefined(options.fill) ? leaf.fill : options.fill : options.fill;
|
|
81
|
+
const needFill = draw.FileHelper.isOpaqueImage(filename) || fill, matrix = new draw.Matrix;
|
|
82
|
+
if (screenshot) {
|
|
83
|
+
renderBounds = screenshot === true ? isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds : screenshot;
|
|
84
|
+
} else {
|
|
85
|
+
let relative = options.relative || (isLeafer ? "inner" : "local");
|
|
86
|
+
scaleX = worldTransform.scaleX;
|
|
87
|
+
scaleY = worldTransform.scaleY;
|
|
88
|
+
switch (relative) {
|
|
89
|
+
case "inner":
|
|
88
90
|
matrix.set(worldTransform);
|
|
89
91
|
break;
|
|
90
|
-
|
|
92
|
+
|
|
93
|
+
case "local":
|
|
91
94
|
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
92
95
|
scaleX /= leaf.scaleX;
|
|
93
96
|
scaleY /= leaf.scaleY;
|
|
94
97
|
break;
|
|
95
|
-
|
|
98
|
+
|
|
99
|
+
case "world":
|
|
96
100
|
scaleX = 1;
|
|
97
101
|
scaleY = 1;
|
|
98
102
|
break;
|
|
99
|
-
|
|
103
|
+
|
|
104
|
+
case "page":
|
|
100
105
|
relative = leafer || leaf;
|
|
101
|
-
|
|
106
|
+
|
|
107
|
+
default:
|
|
102
108
|
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
103
109
|
const l = relative.worldTransform;
|
|
104
110
|
scaleX /= scaleX / l.scaleX;
|
|
105
111
|
scaleY /= scaleY / l.scaleY;
|
|
112
|
+
}
|
|
113
|
+
renderBounds = leaf.getBounds("render", relative);
|
|
106
114
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
x += clip.x, y += clip.y, width = clip.width, height = clip.height;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
canvas.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
115
|
+
const scaleData = {
|
|
116
|
+
scaleX: 1,
|
|
117
|
+
scaleY: 1
|
|
118
|
+
};
|
|
119
|
+
draw.MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
120
|
+
let pixelRatio = options.pixelRatio || 1;
|
|
121
|
+
let {x: x, y: y, width: width, height: height} = new draw.Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
122
|
+
if (clip) x += clip.x, y += clip.y, width = clip.width, height = clip.height;
|
|
123
|
+
const renderOptions = {
|
|
124
|
+
exporting: true,
|
|
125
|
+
matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY)
|
|
126
|
+
};
|
|
127
|
+
let canvas = draw.Creator.canvas({
|
|
128
|
+
width: Math.floor(width),
|
|
129
|
+
height: Math.floor(height),
|
|
130
|
+
pixelRatio: pixelRatio,
|
|
131
|
+
smooth: smooth,
|
|
132
|
+
contextSettings: contextSettings
|
|
133
|
+
});
|
|
134
|
+
let sliceLeaf;
|
|
135
|
+
if (slice) {
|
|
136
|
+
sliceLeaf = leaf;
|
|
137
|
+
sliceLeaf.__worldOpacity = 0;
|
|
138
|
+
leaf = leafer || leaf;
|
|
139
|
+
renderOptions.bounds = canvas.bounds;
|
|
140
|
+
}
|
|
141
|
+
canvas.save();
|
|
142
|
+
if (isFrame && !draw.isUndefined(fill)) {
|
|
143
|
+
const oldFill = leaf.get("fill");
|
|
144
|
+
leaf.fill = "";
|
|
145
|
+
leaf.__render(canvas, renderOptions);
|
|
146
|
+
leaf.fill = oldFill;
|
|
147
|
+
} else {
|
|
148
|
+
leaf.__render(canvas, renderOptions);
|
|
149
|
+
}
|
|
150
|
+
canvas.restore();
|
|
151
|
+
if (sliceLeaf) sliceLeaf.__updateWorldOpacity();
|
|
152
|
+
if (trim) {
|
|
153
|
+
trimBounds = getTrimBounds(canvas);
|
|
154
|
+
const old = canvas, {width: width, height: height} = trimBounds;
|
|
155
|
+
const config = {
|
|
156
|
+
x: 0,
|
|
157
|
+
y: 0,
|
|
158
|
+
width: width,
|
|
159
|
+
height: height,
|
|
160
|
+
pixelRatio: pixelRatio
|
|
161
|
+
};
|
|
162
|
+
canvas = draw.Creator.canvas(config);
|
|
163
|
+
canvas.copyWorld(old, trimBounds, config);
|
|
164
|
+
old.destroy();
|
|
165
|
+
}
|
|
166
|
+
if (padding) {
|
|
167
|
+
const [top, right, bottom, left] = draw.MathHelper.fourNumber(padding);
|
|
168
|
+
const old = canvas, {width: width, height: height} = old;
|
|
169
|
+
canvas = draw.Creator.canvas({
|
|
170
|
+
width: width + left + right,
|
|
171
|
+
height: height + top + bottom,
|
|
172
|
+
pixelRatio: pixelRatio
|
|
173
|
+
});
|
|
174
|
+
canvas.copyWorld(old, old.bounds, {
|
|
175
|
+
x: left,
|
|
176
|
+
y: top,
|
|
177
|
+
width: width,
|
|
178
|
+
height: height
|
|
179
|
+
});
|
|
180
|
+
old.destroy();
|
|
181
|
+
}
|
|
182
|
+
if (needFill) canvas.fillWorld(canvas.bounds, fill || "#FFFFFF", "destination-over");
|
|
183
|
+
if (onCanvas) onCanvas(canvas);
|
|
184
|
+
const data = filename === "canvas" ? canvas : canvas.export(filename, options);
|
|
185
|
+
result = {
|
|
186
|
+
data: data,
|
|
187
|
+
width: canvas.pixelWidth,
|
|
188
|
+
height: canvas.pixelHeight,
|
|
189
|
+
renderBounds: renderBounds,
|
|
190
|
+
trimBounds: trimBounds
|
|
191
|
+
};
|
|
149
192
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
|
|
193
|
+
} catch (error) {
|
|
194
|
+
result = {
|
|
195
|
+
data: "",
|
|
196
|
+
error: error
|
|
197
|
+
};
|
|
156
198
|
}
|
|
157
|
-
|
|
199
|
+
draw.Export.running = false;
|
|
158
200
|
return result;
|
|
159
201
|
},
|
|
160
202
|
export(leaf, filename, options) {
|
|
161
|
-
|
|
162
|
-
return addTask(
|
|
163
|
-
const getResult = () => __awaiter(this, void 0, void 0, function*
|
|
164
|
-
if (!draw.Resource.isComplete)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (result.data instanceof Promise)
|
|
168
|
-
result.data = yield result.data;
|
|
203
|
+
draw.Export.running = true;
|
|
204
|
+
return addTask(success => new Promise(resolve => {
|
|
205
|
+
const getResult = () => __awaiter(this, void 0, void 0, function*() {
|
|
206
|
+
if (!draw.Resource.isComplete) return draw.Platform.requestRender(getResult);
|
|
207
|
+
const result = draw.Export.syncExport(leaf, filename, options);
|
|
208
|
+
if (result.data instanceof Promise) result.data = yield result.data;
|
|
169
209
|
success(result);
|
|
170
210
|
resolve();
|
|
171
211
|
});
|
|
172
212
|
leaf.updateLayout();
|
|
173
213
|
checkLazy(leaf);
|
|
174
|
-
const { leafer
|
|
175
|
-
if (leafer)
|
|
176
|
-
leafer.waitViewCompleted(getResult);
|
|
177
|
-
else
|
|
178
|
-
getResult();
|
|
214
|
+
const {leafer: leafer} = leaf;
|
|
215
|
+
if (leafer) leafer.waitViewCompleted(getResult); else getResult();
|
|
179
216
|
}));
|
|
180
217
|
}
|
|
181
218
|
};
|
|
182
219
|
let tasker;
|
|
183
220
|
function addTask(task) {
|
|
184
|
-
if (!tasker)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
221
|
+
if (!tasker) tasker = new draw.TaskProcessor;
|
|
222
|
+
return new Promise(resolve => {
|
|
223
|
+
tasker.add(() => __awaiter(this, void 0, void 0, function*() {
|
|
224
|
+
return yield task(resolve);
|
|
225
|
+
}), {
|
|
226
|
+
parallel: false
|
|
227
|
+
});
|
|
188
228
|
});
|
|
189
229
|
}
|
|
190
230
|
function checkLazy(leaf) {
|
|
191
|
-
if (leaf.__.__needComputePaint)
|
|
192
|
-
|
|
193
|
-
if (leaf.isBranch)
|
|
194
|
-
leaf.children.forEach(child => checkLazy(child));
|
|
231
|
+
if (leaf.__.__needComputePaint) leaf.__.__computePaint();
|
|
232
|
+
if (leaf.isBranch) leaf.children.forEach(child => checkLazy(child));
|
|
195
233
|
}
|
|
196
|
-
|
|
197
234
|
const canvas = draw.LeaferCanvasBase.prototype;
|
|
198
|
-
const debug = draw.Debug.get(
|
|
199
|
-
canvas.export = function
|
|
200
|
-
const { quality, blob } = draw.FileHelper.getExportOptions(options);
|
|
201
|
-
if (filename.includes(
|
|
202
|
-
return this.saveAs(filename, quality);
|
|
203
|
-
else if (blob)
|
|
204
|
-
return this.toBlob(filename, quality);
|
|
205
|
-
else
|
|
206
|
-
return this.toDataURL(filename, quality);
|
|
235
|
+
const debug = draw.Debug.get("@leafer-in/export");
|
|
236
|
+
canvas.export = function(filename, options) {
|
|
237
|
+
const {quality: quality, blob: blob} = draw.FileHelper.getExportOptions(options);
|
|
238
|
+
if (filename.includes(".")) return this.saveAs(filename, quality); else if (blob) return this.toBlob(filename, quality); else return this.toDataURL(filename, quality);
|
|
207
239
|
};
|
|
208
|
-
canvas.toBlob = function
|
|
209
|
-
return new Promise(
|
|
210
|
-
draw.Platform.origin.canvasToBolb(this.view, type, quality).then(
|
|
240
|
+
canvas.toBlob = function(type, quality) {
|
|
241
|
+
return new Promise(resolve => {
|
|
242
|
+
draw.Platform.origin.canvasToBolb(this.view, type, quality).then(blob => {
|
|
211
243
|
resolve(blob);
|
|
212
|
-
}).catch(
|
|
244
|
+
}).catch(e => {
|
|
213
245
|
debug.error(e);
|
|
214
246
|
resolve(null);
|
|
215
247
|
});
|
|
216
248
|
});
|
|
217
249
|
};
|
|
218
|
-
canvas.toDataURL = function
|
|
250
|
+
canvas.toDataURL = function(type, quality) {
|
|
219
251
|
return draw.Platform.origin.canvasToDataURL(this.view, type, quality);
|
|
220
252
|
};
|
|
221
|
-
canvas.saveAs = function
|
|
222
|
-
return new Promise(
|
|
253
|
+
canvas.saveAs = function(filename, quality) {
|
|
254
|
+
return new Promise(resolve => {
|
|
223
255
|
draw.Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
|
|
224
256
|
resolve(true);
|
|
225
|
-
}).catch(
|
|
257
|
+
}).catch(e => {
|
|
226
258
|
debug.error(e);
|
|
227
259
|
resolve(false);
|
|
228
260
|
});
|
|
229
261
|
});
|
|
230
262
|
};
|
|
231
|
-
|
|
232
|
-
draw.Plugin.add('export');
|
|
263
|
+
draw.Plugin.add("export");
|
|
233
264
|
Object.assign(draw.Export, ExportModule);
|
|
234
|
-
draw.UI.prototype.export = function
|
|
265
|
+
draw.UI.prototype.export = function(filename, options) {
|
|
235
266
|
return draw.Export.export(this, filename, options);
|
|
236
267
|
};
|
|
237
|
-
draw.UI.prototype.syncExport = function
|
|
268
|
+
draw.UI.prototype.syncExport = function(filename, options) {
|
|
238
269
|
return draw.Export.syncExport(this, filename, options);
|
|
239
270
|
};
|
|
240
|
-
|
|
241
271
|
})(LeaferUI);
|
package/dist/export.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("@leafer-ui/draw");function t(e,t,o,n){return new(o||(o=Promise))(
|
|
1
|
+
"use strict";var e=require("@leafer-ui/draw");function t(e,t,o,n){return new(o||(o=Promise))(function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function s(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(a,s)}l((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const{setPoint:o,addPoint:n,toBounds:r}=e.TwoPointBoundsHelper;const i={syncExport(t,i,a){let s;e.Export.running=!0;try{const l=e.FileHelper.fileType(i),c=i.includes(".");a=e.FileHelper.getExportOptions(a);const{toURL:d}=e.Platform,{download:u}=e.Platform.origin;if("json"===l)c&&u(d(JSON.stringify(t.toJSON(a.json)),"text"),i),s={data:!!c||t.toJSON(a.json)};else if("svg"===l)c&&u(d(t.toSVG(),"svg"),i),s={data:!!c||t.toSVG()};else{let l,c,d=1,u=1;const{worldTransform:h,isLeafer:p,leafer:f,isFrame:g}=t,{slice:x,clip:w,trim:v,screenshot:m,padding:y,onCanvas:P}=a,b=e.isUndefined(a.smooth)?!f||f.config.smooth:a.smooth,E=a.contextSettings||(f?f.config.contextSettings:void 0),_=p&&m&&e.isUndefined(a.fill)?t.fill:a.fill,B=e.FileHelper.isOpaqueImage(i)||_,S=new e.Matrix;if(m)l=!0===m?p?f.canvas.bounds:t.worldRenderBounds:m;else{let e=a.relative||(p?"inner":"local");switch(d=h.scaleX,u=h.scaleY,e){case"inner":S.set(h);break;case"local":S.set(h).divide(t.localTransform),d/=t.scaleX,u/=t.scaleY;break;case"world":d=1,u=1;break;case"page":e=f||t;default:S.set(h).divide(t.getTransform(e));const o=e.worldTransform;d/=d/o.scaleX,u/=u/o.scaleY}l=t.getBounds("render",e)}const R={scaleX:1,scaleY:1};e.MathHelper.getScaleData(a.scale,a.size,l,R);let F=a.pixelRatio||1,{x:O,y:T,width:U,height:C}=new e.Bounds(l).scale(R.scaleX,R.scaleY);w&&(O+=w.x,T+=w.y,U=w.width,C=w.height);const H={exporting:!0,matrix:S.scale(1/R.scaleX,1/R.scaleY).invert().translate(-O,-T).withScale(1/d*R.scaleX,1/u*R.scaleY)};let L,X=e.Creator.canvas({width:Math.floor(U),height:Math.floor(C),pixelRatio:F,smooth:b,contextSettings:E});if(x&&(L=t,L.__worldOpacity=0,t=f||t,H.bounds=X.bounds),X.save(),g&&!e.isUndefined(_)){const e=t.get("fill");t.fill="",t.__render(X,H),t.fill=e}else t.__render(X,H);if(X.restore(),L&&L.__updateWorldOpacity(),v){c=function(t){const{width:i,height:a}=t.view,{data:s}=t.context.getImageData(0,0,i,a);let l,c,d,u=0;for(let e=0;e<s.length;e+=4)0!==s[e+3]&&(l=u%i,c=(u-l)/i,d?n(d,l,c):o(d={},l,c)),u++;const h=new e.Bounds;return d&&(r(d,h),h.scale(1/t.pixelRatio).ceil()),h}(X);const t=X,{width:i,height:a}=c,s={x:0,y:0,width:i,height:a,pixelRatio:F};X=e.Creator.canvas(s),X.copyWorld(t,c,s),t.destroy()}if(y){const[t,o,n,r]=e.MathHelper.fourNumber(y),i=X,{width:a,height:s}=i;X=e.Creator.canvas({width:a+r+o,height:s+t+n,pixelRatio:F}),X.copyWorld(i,i.bounds,{x:r,y:t,width:a,height:s}),i.destroy()}B&&X.fillWorld(X.bounds,_||"#FFFFFF","destination-over"),P&&P(X);s={data:"canvas"===i?X:X.export(i,a),width:X.pixelWidth,height:X.pixelHeight,renderBounds:l,trimBounds:c}}}catch(e){s={data:"",error:e}}return e.Export.running=!1,s},export(o,n,r){return e.Export.running=!0,function(o){a||(a=new e.TaskProcessor);return new Promise(e=>{a.add(()=>t(this,void 0,void 0,function*(){return yield o(e)}),{parallel:!1})})}(i=>new Promise(a=>{const l=()=>t(this,void 0,void 0,function*(){if(!e.Resource.isComplete)return e.Platform.requestRender(l);const t=e.Export.syncExport(o,n,r);t.data instanceof Promise&&(t.data=yield t.data),i(t),a()});o.updateLayout(),s(o);const{leafer:c}=o;c?c.waitViewCompleted(l):l()}))}};let a;function s(e){e.__.__needComputePaint&&e.__.__computePaint(),e.isBranch&&e.children.forEach(e=>s(e))}const l=e.LeaferCanvasBase.prototype,c=e.Debug.get("@leafer-in/export");l.export=function(t,o){const{quality:n,blob:r}=e.FileHelper.getExportOptions(o);return t.includes(".")?this.saveAs(t,n):r?this.toBlob(t,n):this.toDataURL(t,n)},l.toBlob=function(t,o){return new Promise(n=>{e.Platform.origin.canvasToBolb(this.view,t,o).then(e=>{n(e)}).catch(e=>{c.error(e),n(null)})})},l.toDataURL=function(t,o){return e.Platform.origin.canvasToDataURL(this.view,t,o)},l.saveAs=function(t,o){return new Promise(n=>{e.Platform.origin.canvasSaveAs(this.view,t,o).then(()=>{n(!0)}).catch(e=>{c.error(e),n(!1)})})},e.Plugin.add("export"),Object.assign(e.Export,i),e.UI.prototype.export=function(t,o){return e.Export.export(this,t,o)},e.UI.prototype.syncExport=function(t,o){return e.Export.syncExport(this,t,o)};
|
|
2
2
|
//# sourceMappingURL=export.min.cjs.map
|