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