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