@leafer-draw/miniapp 1.2.2 → 1.3.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/miniapp.cjs +12 -197
- package/dist/miniapp.esm.js +13 -198
- package/dist/miniapp.esm.min.js +1 -1
- package/dist/miniapp.min.cjs +1 -1
- package/dist/miniapp.module.js +104 -283
- package/dist/miniapp.module.min.js +1 -1
- package/package.json +8 -7
package/dist/miniapp.cjs
CHANGED
|
@@ -415,7 +415,7 @@ class LayoutBlockData {
|
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
const { updateAllMatrix, updateAllChange } = core.LeafHelper;
|
|
418
|
-
const debug$
|
|
418
|
+
const debug$1 = core.Debug.get('Layouter');
|
|
419
419
|
class Layouter {
|
|
420
420
|
constructor(target, userConfig) {
|
|
421
421
|
this.totalTimes = 0;
|
|
@@ -450,7 +450,7 @@ class Layouter {
|
|
|
450
450
|
target.emitEvent(new core.LayoutEvent(core.LayoutEvent.END, this.layoutedBlocks, this.times));
|
|
451
451
|
}
|
|
452
452
|
catch (e) {
|
|
453
|
-
debug$
|
|
453
|
+
debug$1.error(e);
|
|
454
454
|
}
|
|
455
455
|
this.layoutedBlocks = null;
|
|
456
456
|
}
|
|
@@ -464,9 +464,9 @@ class Layouter {
|
|
|
464
464
|
}
|
|
465
465
|
layoutOnce() {
|
|
466
466
|
if (this.layouting)
|
|
467
|
-
return debug$
|
|
467
|
+
return debug$1.warn('layouting');
|
|
468
468
|
if (this.times > 3)
|
|
469
|
-
return debug$
|
|
469
|
+
return debug$1.warn('layout max times');
|
|
470
470
|
this.times++;
|
|
471
471
|
this.totalTimes++;
|
|
472
472
|
this.layouting = true;
|
|
@@ -570,7 +570,7 @@ class Layouter {
|
|
|
570
570
|
}
|
|
571
571
|
}
|
|
572
572
|
|
|
573
|
-
const debug
|
|
573
|
+
const debug = core.Debug.get('Renderer');
|
|
574
574
|
class Renderer {
|
|
575
575
|
get needFill() { return !!(!this.canvas.allowBackgroundColor && this.config.fill); }
|
|
576
576
|
constructor(target, canvas, userConfig) {
|
|
@@ -608,7 +608,7 @@ class Renderer {
|
|
|
608
608
|
const { target } = this;
|
|
609
609
|
this.times = 0;
|
|
610
610
|
this.totalBounds = new core.Bounds();
|
|
611
|
-
debug
|
|
611
|
+
debug.log(target.innerName, '--->');
|
|
612
612
|
try {
|
|
613
613
|
if (!target.isApp)
|
|
614
614
|
target.app.emit(core.RenderEvent.CHILD_START, target);
|
|
@@ -619,9 +619,9 @@ class Renderer {
|
|
|
619
619
|
}
|
|
620
620
|
catch (e) {
|
|
621
621
|
this.rendering = false;
|
|
622
|
-
debug
|
|
622
|
+
debug.error(e);
|
|
623
623
|
}
|
|
624
|
-
debug
|
|
624
|
+
debug.log('-------------|');
|
|
625
625
|
}
|
|
626
626
|
renderAgain() {
|
|
627
627
|
if (this.rendering) {
|
|
@@ -633,9 +633,9 @@ class Renderer {
|
|
|
633
633
|
}
|
|
634
634
|
renderOnce(callback) {
|
|
635
635
|
if (this.rendering)
|
|
636
|
-
return debug
|
|
636
|
+
return debug.warn('rendering');
|
|
637
637
|
if (this.times > 3)
|
|
638
|
-
return debug
|
|
638
|
+
return debug.warn('render max times');
|
|
639
639
|
this.times++;
|
|
640
640
|
this.totalTimes++;
|
|
641
641
|
this.rendering = true;
|
|
@@ -672,7 +672,7 @@ class Renderer {
|
|
|
672
672
|
partRender() {
|
|
673
673
|
const { canvas, updateBlocks: list } = this;
|
|
674
674
|
if (!list)
|
|
675
|
-
return debug
|
|
675
|
+
return debug.warn('PartRender: need update attr');
|
|
676
676
|
this.mergeBlocks();
|
|
677
677
|
list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty())
|
|
678
678
|
this.clipRender(block); });
|
|
@@ -775,7 +775,7 @@ class Renderer {
|
|
|
775
775
|
empty = (!leaf.__world.width || !leaf.__world.height);
|
|
776
776
|
if (empty) {
|
|
777
777
|
if (!leaf.isLeafer)
|
|
778
|
-
debug
|
|
778
|
+
debug.tip(leaf.innerName, ': empty');
|
|
779
779
|
empty = (!leaf.isBranch || leaf.isBranchLeaf);
|
|
780
780
|
}
|
|
781
781
|
return empty;
|
|
@@ -2327,197 +2327,12 @@ const ColorConvertModule = {
|
|
|
2327
2327
|
string
|
|
2328
2328
|
};
|
|
2329
2329
|
|
|
2330
|
-
const { setPoint, addPoint, toBounds } = core.TwoPointBoundsHelper;
|
|
2331
|
-
function getTrimBounds(canvas) {
|
|
2332
|
-
const { width, height } = canvas.view;
|
|
2333
|
-
const { data } = canvas.context.getImageData(0, 0, width, height);
|
|
2334
|
-
let x, y, pointBounds, index = 0;
|
|
2335
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
2336
|
-
if (data[i + 3] !== 0) {
|
|
2337
|
-
x = index % width;
|
|
2338
|
-
y = (index - x) / width;
|
|
2339
|
-
pointBounds ? addPoint(pointBounds, x, y) : setPoint(pointBounds = {}, x, y);
|
|
2340
|
-
}
|
|
2341
|
-
index++;
|
|
2342
|
-
}
|
|
2343
|
-
const bounds = new core.Bounds();
|
|
2344
|
-
toBounds(pointBounds, bounds);
|
|
2345
|
-
return bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
2346
|
-
}
|
|
2347
|
-
|
|
2348
|
-
const ExportModule = {
|
|
2349
|
-
export(leaf, filename, options) {
|
|
2350
|
-
this.running = true;
|
|
2351
|
-
const fileType = core.FileHelper.fileType(filename);
|
|
2352
|
-
const isDownload = filename.includes('.');
|
|
2353
|
-
options = core.FileHelper.getExportOptions(options);
|
|
2354
|
-
return addTask((success) => new Promise((resolve) => {
|
|
2355
|
-
const over = (result) => {
|
|
2356
|
-
success(result);
|
|
2357
|
-
resolve();
|
|
2358
|
-
this.running = false;
|
|
2359
|
-
};
|
|
2360
|
-
const { toURL } = core.Platform;
|
|
2361
|
-
const { download } = core.Platform.origin;
|
|
2362
|
-
if (fileType === 'json') {
|
|
2363
|
-
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
2364
|
-
return over({ data: isDownload ? true : leaf.toJSON(options.json) });
|
|
2365
|
-
}
|
|
2366
|
-
if (fileType === 'svg') {
|
|
2367
|
-
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2368
|
-
return over({ data: isDownload ? true : leaf.toSVG() });
|
|
2369
|
-
}
|
|
2370
|
-
const { leafer } = leaf;
|
|
2371
|
-
if (leafer) {
|
|
2372
|
-
checkLazy(leaf);
|
|
2373
|
-
leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
|
|
2374
|
-
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2375
|
-
const { worldTransform, isLeafer, isFrame } = leaf;
|
|
2376
|
-
const { slice, trim, onCanvas } = options;
|
|
2377
|
-
const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
|
|
2378
|
-
const contextSettings = options.contextSettings || leafer.config.contextSettings;
|
|
2379
|
-
const screenshot = options.screenshot || leaf.isApp;
|
|
2380
|
-
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
2381
|
-
const needFill = core.FileHelper.isOpaqueImage(filename) || fill, matrix = new core.Matrix();
|
|
2382
|
-
if (screenshot) {
|
|
2383
|
-
renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
|
|
2384
|
-
}
|
|
2385
|
-
else {
|
|
2386
|
-
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
2387
|
-
scaleX = worldTransform.scaleX;
|
|
2388
|
-
scaleY = worldTransform.scaleY;
|
|
2389
|
-
switch (relative) {
|
|
2390
|
-
case 'inner':
|
|
2391
|
-
matrix.set(worldTransform);
|
|
2392
|
-
break;
|
|
2393
|
-
case 'local':
|
|
2394
|
-
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
2395
|
-
scaleX /= leaf.scaleX;
|
|
2396
|
-
scaleY /= leaf.scaleY;
|
|
2397
|
-
break;
|
|
2398
|
-
case 'world':
|
|
2399
|
-
scaleX = 1;
|
|
2400
|
-
scaleY = 1;
|
|
2401
|
-
break;
|
|
2402
|
-
case 'page':
|
|
2403
|
-
relative = leaf.leafer;
|
|
2404
|
-
default:
|
|
2405
|
-
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
2406
|
-
const l = relative.worldTransform;
|
|
2407
|
-
scaleX /= scaleX / l.scaleX;
|
|
2408
|
-
scaleY /= scaleY / l.scaleY;
|
|
2409
|
-
}
|
|
2410
|
-
renderBounds = leaf.getBounds('render', relative);
|
|
2411
|
-
}
|
|
2412
|
-
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
2413
|
-
core.MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2414
|
-
let pixelRatio = options.pixelRatio || 1;
|
|
2415
|
-
if (leaf.isApp) {
|
|
2416
|
-
scaleData.scaleX *= pixelRatio;
|
|
2417
|
-
scaleData.scaleY *= pixelRatio;
|
|
2418
|
-
pixelRatio = leaf.app.pixelRatio;
|
|
2419
|
-
}
|
|
2420
|
-
const { x, y, width, height } = new core.Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2421
|
-
const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
|
|
2422
|
-
let canvas = core.Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
|
|
2423
|
-
let sliceLeaf;
|
|
2424
|
-
if (slice) {
|
|
2425
|
-
sliceLeaf = leaf;
|
|
2426
|
-
sliceLeaf.__worldOpacity = 0;
|
|
2427
|
-
leaf = leafer;
|
|
2428
|
-
renderOptions.bounds = canvas.bounds;
|
|
2429
|
-
}
|
|
2430
|
-
canvas.save();
|
|
2431
|
-
if (isFrame && fill !== undefined) {
|
|
2432
|
-
const oldFill = leaf.get('fill');
|
|
2433
|
-
leaf.fill = '';
|
|
2434
|
-
leaf.__render(canvas, renderOptions);
|
|
2435
|
-
leaf.fill = oldFill;
|
|
2436
|
-
}
|
|
2437
|
-
else {
|
|
2438
|
-
leaf.__render(canvas, renderOptions);
|
|
2439
|
-
}
|
|
2440
|
-
canvas.restore();
|
|
2441
|
-
if (sliceLeaf)
|
|
2442
|
-
sliceLeaf.__updateWorldOpacity();
|
|
2443
|
-
if (trim) {
|
|
2444
|
-
trimBounds = getTrimBounds(canvas);
|
|
2445
|
-
const old = canvas, { width, height } = trimBounds;
|
|
2446
|
-
const config = { x: 0, y: 0, width, height, pixelRatio };
|
|
2447
|
-
canvas = core.Creator.canvas(config);
|
|
2448
|
-
canvas.copyWorld(old, trimBounds, config);
|
|
2449
|
-
}
|
|
2450
|
-
if (needFill)
|
|
2451
|
-
canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
|
|
2452
|
-
if (onCanvas)
|
|
2453
|
-
onCanvas(canvas);
|
|
2454
|
-
const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
|
|
2455
|
-
over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
|
|
2456
|
-
}));
|
|
2457
|
-
}
|
|
2458
|
-
else {
|
|
2459
|
-
over({ data: false });
|
|
2460
|
-
}
|
|
2461
|
-
}));
|
|
2462
|
-
}
|
|
2463
|
-
};
|
|
2464
|
-
let tasker;
|
|
2465
|
-
function addTask(task) {
|
|
2466
|
-
if (!tasker)
|
|
2467
|
-
tasker = new core.TaskProcessor();
|
|
2468
|
-
return new Promise((resolve) => {
|
|
2469
|
-
tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
|
|
2470
|
-
});
|
|
2471
|
-
}
|
|
2472
|
-
function checkLazy(leaf) {
|
|
2473
|
-
if (leaf.__.__needComputePaint)
|
|
2474
|
-
leaf.__.__computePaint();
|
|
2475
|
-
if (leaf.isBranch)
|
|
2476
|
-
leaf.children.forEach(child => checkLazy(child));
|
|
2477
|
-
}
|
|
2478
|
-
|
|
2479
|
-
const canvas = core.LeaferCanvasBase.prototype;
|
|
2480
|
-
const debug = core.Debug.get('@leafer-ui/export');
|
|
2481
|
-
canvas.export = function (filename, options) {
|
|
2482
|
-
const { quality, blob } = core.FileHelper.getExportOptions(options);
|
|
2483
|
-
if (filename.includes('.'))
|
|
2484
|
-
return this.saveAs(filename, quality);
|
|
2485
|
-
else if (blob)
|
|
2486
|
-
return this.toBlob(filename, quality);
|
|
2487
|
-
else
|
|
2488
|
-
return this.toDataURL(filename, quality);
|
|
2489
|
-
};
|
|
2490
|
-
canvas.toBlob = function (type, quality) {
|
|
2491
|
-
return new Promise((resolve) => {
|
|
2492
|
-
core.Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
|
|
2493
|
-
resolve(blob);
|
|
2494
|
-
}).catch((e) => {
|
|
2495
|
-
debug.error(e);
|
|
2496
|
-
resolve(null);
|
|
2497
|
-
});
|
|
2498
|
-
});
|
|
2499
|
-
};
|
|
2500
|
-
canvas.toDataURL = function (type, quality) {
|
|
2501
|
-
return core.Platform.origin.canvasToDataURL(this.view, type, quality);
|
|
2502
|
-
};
|
|
2503
|
-
canvas.saveAs = function (filename, quality) {
|
|
2504
|
-
return new Promise((resolve) => {
|
|
2505
|
-
core.Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
|
|
2506
|
-
resolve(true);
|
|
2507
|
-
}).catch((e) => {
|
|
2508
|
-
debug.error(e);
|
|
2509
|
-
resolve(false);
|
|
2510
|
-
});
|
|
2511
|
-
});
|
|
2512
|
-
};
|
|
2513
|
-
|
|
2514
2330
|
Object.assign(draw.TextConvert, TextConvertModule);
|
|
2515
2331
|
Object.assign(draw.ColorConvert, ColorConvertModule);
|
|
2516
2332
|
Object.assign(draw.Paint, PaintModule);
|
|
2517
2333
|
Object.assign(draw.PaintImage, PaintImageModule);
|
|
2518
2334
|
Object.assign(draw.PaintGradient, PaintGradientModule);
|
|
2519
2335
|
Object.assign(draw.Effect, EffectModule);
|
|
2520
|
-
Object.assign(draw.Export, ExportModule);
|
|
2521
2336
|
|
|
2522
2337
|
try {
|
|
2523
2338
|
if (wx)
|
package/dist/miniapp.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LeaferCanvasBase, Platform, canvasPatch, DataHelper, canvasSizeAttrs, ResizeEvent, Creator, LeaferImage, defineKey, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, BoundsHelper, MatrixHelper, MathHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4
|
|
1
|
+
import { LeaferCanvasBase, Platform, canvasPatch, DataHelper, canvasSizeAttrs, ResizeEvent, Creator, LeaferImage, defineKey, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, BoundsHelper, MatrixHelper, MathHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4 } from '@leafer/core';
|
|
2
2
|
export * from '@leafer/core';
|
|
3
3
|
export { LeaferImage } from '@leafer/core';
|
|
4
4
|
import { PaintImage, ColorConvert, PaintGradient, Export, Group, TextConvert, Paint, Effect } from '@leafer-ui/draw';
|
|
@@ -416,7 +416,7 @@ class LayoutBlockData {
|
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
const { updateAllMatrix, updateAllChange } = LeafHelper;
|
|
419
|
-
const debug$
|
|
419
|
+
const debug$1 = Debug.get('Layouter');
|
|
420
420
|
class Layouter {
|
|
421
421
|
constructor(target, userConfig) {
|
|
422
422
|
this.totalTimes = 0;
|
|
@@ -451,7 +451,7 @@ class Layouter {
|
|
|
451
451
|
target.emitEvent(new LayoutEvent(LayoutEvent.END, this.layoutedBlocks, this.times));
|
|
452
452
|
}
|
|
453
453
|
catch (e) {
|
|
454
|
-
debug$
|
|
454
|
+
debug$1.error(e);
|
|
455
455
|
}
|
|
456
456
|
this.layoutedBlocks = null;
|
|
457
457
|
}
|
|
@@ -465,9 +465,9 @@ class Layouter {
|
|
|
465
465
|
}
|
|
466
466
|
layoutOnce() {
|
|
467
467
|
if (this.layouting)
|
|
468
|
-
return debug$
|
|
468
|
+
return debug$1.warn('layouting');
|
|
469
469
|
if (this.times > 3)
|
|
470
|
-
return debug$
|
|
470
|
+
return debug$1.warn('layout max times');
|
|
471
471
|
this.times++;
|
|
472
472
|
this.totalTimes++;
|
|
473
473
|
this.layouting = true;
|
|
@@ -571,7 +571,7 @@ class Layouter {
|
|
|
571
571
|
}
|
|
572
572
|
}
|
|
573
573
|
|
|
574
|
-
const debug
|
|
574
|
+
const debug = Debug.get('Renderer');
|
|
575
575
|
class Renderer {
|
|
576
576
|
get needFill() { return !!(!this.canvas.allowBackgroundColor && this.config.fill); }
|
|
577
577
|
constructor(target, canvas, userConfig) {
|
|
@@ -609,7 +609,7 @@ class Renderer {
|
|
|
609
609
|
const { target } = this;
|
|
610
610
|
this.times = 0;
|
|
611
611
|
this.totalBounds = new Bounds();
|
|
612
|
-
debug
|
|
612
|
+
debug.log(target.innerName, '--->');
|
|
613
613
|
try {
|
|
614
614
|
if (!target.isApp)
|
|
615
615
|
target.app.emit(RenderEvent.CHILD_START, target);
|
|
@@ -620,9 +620,9 @@ class Renderer {
|
|
|
620
620
|
}
|
|
621
621
|
catch (e) {
|
|
622
622
|
this.rendering = false;
|
|
623
|
-
debug
|
|
623
|
+
debug.error(e);
|
|
624
624
|
}
|
|
625
|
-
debug
|
|
625
|
+
debug.log('-------------|');
|
|
626
626
|
}
|
|
627
627
|
renderAgain() {
|
|
628
628
|
if (this.rendering) {
|
|
@@ -634,9 +634,9 @@ class Renderer {
|
|
|
634
634
|
}
|
|
635
635
|
renderOnce(callback) {
|
|
636
636
|
if (this.rendering)
|
|
637
|
-
return debug
|
|
637
|
+
return debug.warn('rendering');
|
|
638
638
|
if (this.times > 3)
|
|
639
|
-
return debug
|
|
639
|
+
return debug.warn('render max times');
|
|
640
640
|
this.times++;
|
|
641
641
|
this.totalTimes++;
|
|
642
642
|
this.rendering = true;
|
|
@@ -673,7 +673,7 @@ class Renderer {
|
|
|
673
673
|
partRender() {
|
|
674
674
|
const { canvas, updateBlocks: list } = this;
|
|
675
675
|
if (!list)
|
|
676
|
-
return debug
|
|
676
|
+
return debug.warn('PartRender: need update attr');
|
|
677
677
|
this.mergeBlocks();
|
|
678
678
|
list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty())
|
|
679
679
|
this.clipRender(block); });
|
|
@@ -776,7 +776,7 @@ class Renderer {
|
|
|
776
776
|
empty = (!leaf.__world.width || !leaf.__world.height);
|
|
777
777
|
if (empty) {
|
|
778
778
|
if (!leaf.isLeafer)
|
|
779
|
-
debug
|
|
779
|
+
debug.tip(leaf.innerName, ': empty');
|
|
780
780
|
empty = (!leaf.isBranch || leaf.isBranchLeaf);
|
|
781
781
|
}
|
|
782
782
|
return empty;
|
|
@@ -2328,197 +2328,12 @@ const ColorConvertModule = {
|
|
|
2328
2328
|
string
|
|
2329
2329
|
};
|
|
2330
2330
|
|
|
2331
|
-
const { setPoint, addPoint, toBounds } = TwoPointBoundsHelper;
|
|
2332
|
-
function getTrimBounds(canvas) {
|
|
2333
|
-
const { width, height } = canvas.view;
|
|
2334
|
-
const { data } = canvas.context.getImageData(0, 0, width, height);
|
|
2335
|
-
let x, y, pointBounds, index = 0;
|
|
2336
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
2337
|
-
if (data[i + 3] !== 0) {
|
|
2338
|
-
x = index % width;
|
|
2339
|
-
y = (index - x) / width;
|
|
2340
|
-
pointBounds ? addPoint(pointBounds, x, y) : setPoint(pointBounds = {}, x, y);
|
|
2341
|
-
}
|
|
2342
|
-
index++;
|
|
2343
|
-
}
|
|
2344
|
-
const bounds = new Bounds();
|
|
2345
|
-
toBounds(pointBounds, bounds);
|
|
2346
|
-
return bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
2347
|
-
}
|
|
2348
|
-
|
|
2349
|
-
const ExportModule = {
|
|
2350
|
-
export(leaf, filename, options) {
|
|
2351
|
-
this.running = true;
|
|
2352
|
-
const fileType = FileHelper.fileType(filename);
|
|
2353
|
-
const isDownload = filename.includes('.');
|
|
2354
|
-
options = FileHelper.getExportOptions(options);
|
|
2355
|
-
return addTask((success) => new Promise((resolve) => {
|
|
2356
|
-
const over = (result) => {
|
|
2357
|
-
success(result);
|
|
2358
|
-
resolve();
|
|
2359
|
-
this.running = false;
|
|
2360
|
-
};
|
|
2361
|
-
const { toURL } = Platform;
|
|
2362
|
-
const { download } = Platform.origin;
|
|
2363
|
-
if (fileType === 'json') {
|
|
2364
|
-
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
2365
|
-
return over({ data: isDownload ? true : leaf.toJSON(options.json) });
|
|
2366
|
-
}
|
|
2367
|
-
if (fileType === 'svg') {
|
|
2368
|
-
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2369
|
-
return over({ data: isDownload ? true : leaf.toSVG() });
|
|
2370
|
-
}
|
|
2371
|
-
const { leafer } = leaf;
|
|
2372
|
-
if (leafer) {
|
|
2373
|
-
checkLazy(leaf);
|
|
2374
|
-
leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
|
|
2375
|
-
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2376
|
-
const { worldTransform, isLeafer, isFrame } = leaf;
|
|
2377
|
-
const { slice, trim, onCanvas } = options;
|
|
2378
|
-
const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
|
|
2379
|
-
const contextSettings = options.contextSettings || leafer.config.contextSettings;
|
|
2380
|
-
const screenshot = options.screenshot || leaf.isApp;
|
|
2381
|
-
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
2382
|
-
const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
|
|
2383
|
-
if (screenshot) {
|
|
2384
|
-
renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
|
|
2385
|
-
}
|
|
2386
|
-
else {
|
|
2387
|
-
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
2388
|
-
scaleX = worldTransform.scaleX;
|
|
2389
|
-
scaleY = worldTransform.scaleY;
|
|
2390
|
-
switch (relative) {
|
|
2391
|
-
case 'inner':
|
|
2392
|
-
matrix.set(worldTransform);
|
|
2393
|
-
break;
|
|
2394
|
-
case 'local':
|
|
2395
|
-
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
2396
|
-
scaleX /= leaf.scaleX;
|
|
2397
|
-
scaleY /= leaf.scaleY;
|
|
2398
|
-
break;
|
|
2399
|
-
case 'world':
|
|
2400
|
-
scaleX = 1;
|
|
2401
|
-
scaleY = 1;
|
|
2402
|
-
break;
|
|
2403
|
-
case 'page':
|
|
2404
|
-
relative = leaf.leafer;
|
|
2405
|
-
default:
|
|
2406
|
-
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
2407
|
-
const l = relative.worldTransform;
|
|
2408
|
-
scaleX /= scaleX / l.scaleX;
|
|
2409
|
-
scaleY /= scaleY / l.scaleY;
|
|
2410
|
-
}
|
|
2411
|
-
renderBounds = leaf.getBounds('render', relative);
|
|
2412
|
-
}
|
|
2413
|
-
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
2414
|
-
MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2415
|
-
let pixelRatio = options.pixelRatio || 1;
|
|
2416
|
-
if (leaf.isApp) {
|
|
2417
|
-
scaleData.scaleX *= pixelRatio;
|
|
2418
|
-
scaleData.scaleY *= pixelRatio;
|
|
2419
|
-
pixelRatio = leaf.app.pixelRatio;
|
|
2420
|
-
}
|
|
2421
|
-
const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2422
|
-
const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
|
|
2423
|
-
let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
|
|
2424
|
-
let sliceLeaf;
|
|
2425
|
-
if (slice) {
|
|
2426
|
-
sliceLeaf = leaf;
|
|
2427
|
-
sliceLeaf.__worldOpacity = 0;
|
|
2428
|
-
leaf = leafer;
|
|
2429
|
-
renderOptions.bounds = canvas.bounds;
|
|
2430
|
-
}
|
|
2431
|
-
canvas.save();
|
|
2432
|
-
if (isFrame && fill !== undefined) {
|
|
2433
|
-
const oldFill = leaf.get('fill');
|
|
2434
|
-
leaf.fill = '';
|
|
2435
|
-
leaf.__render(canvas, renderOptions);
|
|
2436
|
-
leaf.fill = oldFill;
|
|
2437
|
-
}
|
|
2438
|
-
else {
|
|
2439
|
-
leaf.__render(canvas, renderOptions);
|
|
2440
|
-
}
|
|
2441
|
-
canvas.restore();
|
|
2442
|
-
if (sliceLeaf)
|
|
2443
|
-
sliceLeaf.__updateWorldOpacity();
|
|
2444
|
-
if (trim) {
|
|
2445
|
-
trimBounds = getTrimBounds(canvas);
|
|
2446
|
-
const old = canvas, { width, height } = trimBounds;
|
|
2447
|
-
const config = { x: 0, y: 0, width, height, pixelRatio };
|
|
2448
|
-
canvas = Creator.canvas(config);
|
|
2449
|
-
canvas.copyWorld(old, trimBounds, config);
|
|
2450
|
-
}
|
|
2451
|
-
if (needFill)
|
|
2452
|
-
canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
|
|
2453
|
-
if (onCanvas)
|
|
2454
|
-
onCanvas(canvas);
|
|
2455
|
-
const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
|
|
2456
|
-
over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
|
|
2457
|
-
}));
|
|
2458
|
-
}
|
|
2459
|
-
else {
|
|
2460
|
-
over({ data: false });
|
|
2461
|
-
}
|
|
2462
|
-
}));
|
|
2463
|
-
}
|
|
2464
|
-
};
|
|
2465
|
-
let tasker;
|
|
2466
|
-
function addTask(task) {
|
|
2467
|
-
if (!tasker)
|
|
2468
|
-
tasker = new TaskProcessor();
|
|
2469
|
-
return new Promise((resolve) => {
|
|
2470
|
-
tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
|
|
2471
|
-
});
|
|
2472
|
-
}
|
|
2473
|
-
function checkLazy(leaf) {
|
|
2474
|
-
if (leaf.__.__needComputePaint)
|
|
2475
|
-
leaf.__.__computePaint();
|
|
2476
|
-
if (leaf.isBranch)
|
|
2477
|
-
leaf.children.forEach(child => checkLazy(child));
|
|
2478
|
-
}
|
|
2479
|
-
|
|
2480
|
-
const canvas = LeaferCanvasBase.prototype;
|
|
2481
|
-
const debug = Debug.get('@leafer-ui/export');
|
|
2482
|
-
canvas.export = function (filename, options) {
|
|
2483
|
-
const { quality, blob } = FileHelper.getExportOptions(options);
|
|
2484
|
-
if (filename.includes('.'))
|
|
2485
|
-
return this.saveAs(filename, quality);
|
|
2486
|
-
else if (blob)
|
|
2487
|
-
return this.toBlob(filename, quality);
|
|
2488
|
-
else
|
|
2489
|
-
return this.toDataURL(filename, quality);
|
|
2490
|
-
};
|
|
2491
|
-
canvas.toBlob = function (type, quality) {
|
|
2492
|
-
return new Promise((resolve) => {
|
|
2493
|
-
Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
|
|
2494
|
-
resolve(blob);
|
|
2495
|
-
}).catch((e) => {
|
|
2496
|
-
debug.error(e);
|
|
2497
|
-
resolve(null);
|
|
2498
|
-
});
|
|
2499
|
-
});
|
|
2500
|
-
};
|
|
2501
|
-
canvas.toDataURL = function (type, quality) {
|
|
2502
|
-
return Platform.origin.canvasToDataURL(this.view, type, quality);
|
|
2503
|
-
};
|
|
2504
|
-
canvas.saveAs = function (filename, quality) {
|
|
2505
|
-
return new Promise((resolve) => {
|
|
2506
|
-
Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
|
|
2507
|
-
resolve(true);
|
|
2508
|
-
}).catch((e) => {
|
|
2509
|
-
debug.error(e);
|
|
2510
|
-
resolve(false);
|
|
2511
|
-
});
|
|
2512
|
-
});
|
|
2513
|
-
};
|
|
2514
|
-
|
|
2515
2331
|
Object.assign(TextConvert, TextConvertModule);
|
|
2516
2332
|
Object.assign(ColorConvert, ColorConvertModule);
|
|
2517
2333
|
Object.assign(Paint, PaintModule);
|
|
2518
2334
|
Object.assign(PaintImage, PaintImageModule);
|
|
2519
2335
|
Object.assign(PaintGradient, PaintGradientModule);
|
|
2520
2336
|
Object.assign(Effect, EffectModule);
|
|
2521
|
-
Object.assign(Export, ExportModule);
|
|
2522
2337
|
|
|
2523
2338
|
try {
|
|
2524
2339
|
if (wx)
|