@leafer-ui/worker 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/worker.cjs +23 -323
- package/dist/worker.esm.js +24 -325
- package/dist/worker.esm.min.js +1 -1
- package/dist/worker.js +134 -436
- package/dist/worker.min.cjs +1 -1
- package/dist/worker.min.js +1 -1
- package/dist/worker.module.js +134 -437
- package/dist/worker.module.min.js +1 -1
- package/package.json +10 -10
package/dist/worker.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LeaferCanvasBase, Platform, canvasPatch, Creator, LeaferImage, defineKey, FileHelper, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, ResizeEvent, BoundsHelper,
|
|
1
|
+
import { LeaferCanvasBase, Platform, canvasPatch, Creator, LeaferImage, defineKey, FileHelper, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, ResizeEvent, BoundsHelper, Plugin, 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 { InteractionBase, HitCanvasManager } from '@leafer-ui/core';
|
|
@@ -71,6 +71,7 @@ function useCanvas(_canvasType, _power) {
|
|
|
71
71
|
}
|
|
72
72
|
Platform.name = 'web';
|
|
73
73
|
Platform.isWorker = true;
|
|
74
|
+
Platform.backgrounder = true;
|
|
74
75
|
Platform.requestRender = function (render) { requestAnimationFrame(render); };
|
|
75
76
|
defineKey(Platform, 'devicePixelRatio', { get() { return 1; } });
|
|
76
77
|
const { userAgent } = navigator;
|
|
@@ -277,7 +278,7 @@ class LayoutBlockData {
|
|
|
277
278
|
}
|
|
278
279
|
|
|
279
280
|
const { updateAllMatrix, updateAllChange } = LeafHelper;
|
|
280
|
-
const debug$
|
|
281
|
+
const debug$1 = Debug.get('Layouter');
|
|
281
282
|
class Layouter {
|
|
282
283
|
constructor(target, userConfig) {
|
|
283
284
|
this.totalTimes = 0;
|
|
@@ -312,7 +313,7 @@ class Layouter {
|
|
|
312
313
|
target.emitEvent(new LayoutEvent(LayoutEvent.END, this.layoutedBlocks, this.times));
|
|
313
314
|
}
|
|
314
315
|
catch (e) {
|
|
315
|
-
debug$
|
|
316
|
+
debug$1.error(e);
|
|
316
317
|
}
|
|
317
318
|
this.layoutedBlocks = null;
|
|
318
319
|
}
|
|
@@ -326,9 +327,9 @@ class Layouter {
|
|
|
326
327
|
}
|
|
327
328
|
layoutOnce() {
|
|
328
329
|
if (this.layouting)
|
|
329
|
-
return debug$
|
|
330
|
+
return debug$1.warn('layouting');
|
|
330
331
|
if (this.times > 3)
|
|
331
|
-
return debug$
|
|
332
|
+
return debug$1.warn('layout max times');
|
|
332
333
|
this.times++;
|
|
333
334
|
this.totalTimes++;
|
|
334
335
|
this.layouting = true;
|
|
@@ -432,7 +433,7 @@ class Layouter {
|
|
|
432
433
|
}
|
|
433
434
|
}
|
|
434
435
|
|
|
435
|
-
const debug
|
|
436
|
+
const debug = Debug.get('Renderer');
|
|
436
437
|
class Renderer {
|
|
437
438
|
get needFill() { return !!(!this.canvas.allowBackgroundColor && this.config.fill); }
|
|
438
439
|
constructor(target, canvas, userConfig) {
|
|
@@ -470,7 +471,7 @@ class Renderer {
|
|
|
470
471
|
const { target } = this;
|
|
471
472
|
this.times = 0;
|
|
472
473
|
this.totalBounds = new Bounds();
|
|
473
|
-
debug
|
|
474
|
+
debug.log(target.innerName, '--->');
|
|
474
475
|
try {
|
|
475
476
|
if (!target.isApp)
|
|
476
477
|
target.app.emit(RenderEvent.CHILD_START, target);
|
|
@@ -481,9 +482,9 @@ class Renderer {
|
|
|
481
482
|
}
|
|
482
483
|
catch (e) {
|
|
483
484
|
this.rendering = false;
|
|
484
|
-
debug
|
|
485
|
+
debug.error(e);
|
|
485
486
|
}
|
|
486
|
-
debug
|
|
487
|
+
debug.log('-------------|');
|
|
487
488
|
}
|
|
488
489
|
renderAgain() {
|
|
489
490
|
if (this.rendering) {
|
|
@@ -495,9 +496,9 @@ class Renderer {
|
|
|
495
496
|
}
|
|
496
497
|
renderOnce(callback) {
|
|
497
498
|
if (this.rendering)
|
|
498
|
-
return debug
|
|
499
|
+
return debug.warn('rendering');
|
|
499
500
|
if (this.times > 3)
|
|
500
|
-
return debug
|
|
501
|
+
return debug.warn('render max times');
|
|
501
502
|
this.times++;
|
|
502
503
|
this.totalTimes++;
|
|
503
504
|
this.rendering = true;
|
|
@@ -534,7 +535,7 @@ class Renderer {
|
|
|
534
535
|
partRender() {
|
|
535
536
|
const { canvas, updateBlocks: list } = this;
|
|
536
537
|
if (!list)
|
|
537
|
-
return debug
|
|
538
|
+
return debug.warn('PartRender: need update attr');
|
|
538
539
|
this.mergeBlocks();
|
|
539
540
|
list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty())
|
|
540
541
|
this.clipRender(block); });
|
|
@@ -637,7 +638,7 @@ class Renderer {
|
|
|
637
638
|
empty = (!leaf.__world.width || !leaf.__world.height);
|
|
638
639
|
if (empty) {
|
|
639
640
|
if (!leaf.isLeafer)
|
|
640
|
-
debug
|
|
641
|
+
debug.tip(leaf.innerName, ': empty');
|
|
641
642
|
empty = (!leaf.isBranch || leaf.isBranchLeaf);
|
|
642
643
|
}
|
|
643
644
|
return empty;
|
|
@@ -803,143 +804,26 @@ class Picker {
|
|
|
803
804
|
}
|
|
804
805
|
}
|
|
805
806
|
|
|
806
|
-
const { Yes, NoAndSkip, YesAndSkip } = Answer;
|
|
807
|
-
const idCondition = {}, classNameCondition = {}, tagCondition = {};
|
|
808
807
|
class Selector {
|
|
809
808
|
constructor(target, userConfig) {
|
|
810
809
|
this.config = {};
|
|
811
|
-
this.innerIdMap = {};
|
|
812
|
-
this.idMap = {};
|
|
813
|
-
this.methods = {
|
|
814
|
-
id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,
|
|
815
|
-
innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,
|
|
816
|
-
className: (leaf, name) => leaf.className === name ? 1 : 0,
|
|
817
|
-
tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
|
|
818
|
-
tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
|
|
819
|
-
};
|
|
820
|
-
this.target = target;
|
|
821
810
|
if (userConfig)
|
|
822
811
|
this.config = DataHelper.default(userConfig, this.config);
|
|
823
|
-
this.picker = new Picker(target, this);
|
|
824
|
-
|
|
825
|
-
this.__listenEvents();
|
|
826
|
-
}
|
|
827
|
-
getBy(condition, branch, one, options) {
|
|
828
|
-
switch (typeof condition) {
|
|
829
|
-
case 'number':
|
|
830
|
-
const leaf = this.getByInnerId(condition, branch);
|
|
831
|
-
return one ? leaf : (leaf ? [leaf] : []);
|
|
832
|
-
case 'string':
|
|
833
|
-
switch (condition[0]) {
|
|
834
|
-
case '#':
|
|
835
|
-
idCondition.id = condition.substring(1), condition = idCondition;
|
|
836
|
-
break;
|
|
837
|
-
case '.':
|
|
838
|
-
classNameCondition.className = condition.substring(1), condition = classNameCondition;
|
|
839
|
-
break;
|
|
840
|
-
default:
|
|
841
|
-
tagCondition.tag = condition, condition = tagCondition;
|
|
842
|
-
}
|
|
843
|
-
case 'object':
|
|
844
|
-
if (condition.id !== undefined) {
|
|
845
|
-
const leaf = this.getById(condition.id, branch);
|
|
846
|
-
return one ? leaf : (leaf ? [leaf] : []);
|
|
847
|
-
}
|
|
848
|
-
else if (condition.tag) {
|
|
849
|
-
const { tag } = condition, isArray = tag instanceof Array;
|
|
850
|
-
return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag);
|
|
851
|
-
}
|
|
852
|
-
else {
|
|
853
|
-
return this.getByMethod(this.methods.className, branch, one, condition.className);
|
|
854
|
-
}
|
|
855
|
-
case 'function':
|
|
856
|
-
return this.getByMethod(condition, branch, one, options);
|
|
857
|
-
}
|
|
812
|
+
this.picker = new Picker(this.target = target, this);
|
|
813
|
+
this.finder = Creator.finder && Creator.finder();
|
|
858
814
|
}
|
|
859
815
|
getByPoint(hitPoint, hitRadius, options) {
|
|
860
|
-
if (Platform.
|
|
861
|
-
this.target.
|
|
816
|
+
if (Platform.backgrounder && this.target)
|
|
817
|
+
this.target.updateLayout();
|
|
862
818
|
return this.picker.getByPoint(hitPoint, hitRadius, options);
|
|
863
819
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
if (cache)
|
|
867
|
-
return cache;
|
|
868
|
-
this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
|
|
869
|
-
return this.findLeaf;
|
|
870
|
-
}
|
|
871
|
-
getById(id, branch) {
|
|
872
|
-
const cache = this.idMap[id];
|
|
873
|
-
if (cache && LeafHelper.hasParent(cache, branch || this.target))
|
|
874
|
-
return cache;
|
|
875
|
-
this.eachFind(this.toChildren(branch), this.methods.id, null, id);
|
|
876
|
-
return this.findLeaf;
|
|
877
|
-
}
|
|
878
|
-
getByClassName(className, branch) {
|
|
879
|
-
return this.getByMethod(this.methods.className, branch, false, className);
|
|
880
|
-
}
|
|
881
|
-
getByTag(tag, branch) {
|
|
882
|
-
return this.getByMethod(this.methods.tag, branch, false, tag);
|
|
883
|
-
}
|
|
884
|
-
getByMethod(method, branch, one, options) {
|
|
885
|
-
const list = one ? null : [];
|
|
886
|
-
this.eachFind(this.toChildren(branch), method, list, options);
|
|
887
|
-
return list || this.findLeaf;
|
|
888
|
-
}
|
|
889
|
-
eachFind(children, method, list, options) {
|
|
890
|
-
let child, result;
|
|
891
|
-
for (let i = 0, len = children.length; i < len; i++) {
|
|
892
|
-
child = children[i];
|
|
893
|
-
result = method(child, options);
|
|
894
|
-
if (result === Yes || result === YesAndSkip) {
|
|
895
|
-
if (list) {
|
|
896
|
-
list.push(child);
|
|
897
|
-
}
|
|
898
|
-
else {
|
|
899
|
-
this.findLeaf = child;
|
|
900
|
-
return;
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
if (child.isBranch && result < NoAndSkip)
|
|
904
|
-
this.eachFind(child.children, method, list, options);
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
toChildren(branch) {
|
|
908
|
-
this.findLeaf = null;
|
|
909
|
-
return [branch || this.target];
|
|
910
|
-
}
|
|
911
|
-
__onRemoveChild(event) {
|
|
912
|
-
const { id, innerId } = event.child;
|
|
913
|
-
if (this.idMap[id])
|
|
914
|
-
delete this.idMap[id];
|
|
915
|
-
if (this.innerIdMap[innerId])
|
|
916
|
-
delete this.innerIdMap[innerId];
|
|
917
|
-
}
|
|
918
|
-
__checkIdChange(event) {
|
|
919
|
-
if (event.attrName === 'id') {
|
|
920
|
-
const id = event.oldValue;
|
|
921
|
-
if (this.idMap[id])
|
|
922
|
-
delete this.idMap[id];
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
__listenEvents() {
|
|
926
|
-
this.__eventIds = [
|
|
927
|
-
this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),
|
|
928
|
-
this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)
|
|
929
|
-
];
|
|
930
|
-
}
|
|
931
|
-
__removeListenEvents() {
|
|
932
|
-
this.target.off_(this.__eventIds);
|
|
933
|
-
this.__eventIds.length = 0;
|
|
820
|
+
getBy(condition, branch, one, options) {
|
|
821
|
+
return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need('find');
|
|
934
822
|
}
|
|
935
823
|
destroy() {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
this.
|
|
939
|
-
this.findLeaf = null;
|
|
940
|
-
this.innerIdMap = {};
|
|
941
|
-
this.idMap = {};
|
|
942
|
-
}
|
|
824
|
+
this.picker.destroy();
|
|
825
|
+
if (this.finder)
|
|
826
|
+
this.finder.destroy();
|
|
943
827
|
}
|
|
944
828
|
}
|
|
945
829
|
|
|
@@ -2462,197 +2346,12 @@ const ColorConvertModule = {
|
|
|
2462
2346
|
string
|
|
2463
2347
|
};
|
|
2464
2348
|
|
|
2465
|
-
const { setPoint, addPoint, toBounds } = TwoPointBoundsHelper;
|
|
2466
|
-
function getTrimBounds(canvas) {
|
|
2467
|
-
const { width, height } = canvas.view;
|
|
2468
|
-
const { data } = canvas.context.getImageData(0, 0, width, height);
|
|
2469
|
-
let x, y, pointBounds, index = 0;
|
|
2470
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
2471
|
-
if (data[i + 3] !== 0) {
|
|
2472
|
-
x = index % width;
|
|
2473
|
-
y = (index - x) / width;
|
|
2474
|
-
pointBounds ? addPoint(pointBounds, x, y) : setPoint(pointBounds = {}, x, y);
|
|
2475
|
-
}
|
|
2476
|
-
index++;
|
|
2477
|
-
}
|
|
2478
|
-
const bounds = new Bounds();
|
|
2479
|
-
toBounds(pointBounds, bounds);
|
|
2480
|
-
return bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
2481
|
-
}
|
|
2482
|
-
|
|
2483
|
-
const ExportModule = {
|
|
2484
|
-
export(leaf, filename, options) {
|
|
2485
|
-
this.running = true;
|
|
2486
|
-
const fileType = FileHelper.fileType(filename);
|
|
2487
|
-
const isDownload = filename.includes('.');
|
|
2488
|
-
options = FileHelper.getExportOptions(options);
|
|
2489
|
-
return addTask((success) => new Promise((resolve) => {
|
|
2490
|
-
const over = (result) => {
|
|
2491
|
-
success(result);
|
|
2492
|
-
resolve();
|
|
2493
|
-
this.running = false;
|
|
2494
|
-
};
|
|
2495
|
-
const { toURL } = Platform;
|
|
2496
|
-
const { download } = Platform.origin;
|
|
2497
|
-
if (fileType === 'json') {
|
|
2498
|
-
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
2499
|
-
return over({ data: isDownload ? true : leaf.toJSON(options.json) });
|
|
2500
|
-
}
|
|
2501
|
-
if (fileType === 'svg') {
|
|
2502
|
-
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2503
|
-
return over({ data: isDownload ? true : leaf.toSVG() });
|
|
2504
|
-
}
|
|
2505
|
-
const { leafer } = leaf;
|
|
2506
|
-
if (leafer) {
|
|
2507
|
-
checkLazy(leaf);
|
|
2508
|
-
leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
|
|
2509
|
-
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2510
|
-
const { worldTransform, isLeafer, isFrame } = leaf;
|
|
2511
|
-
const { slice, trim, onCanvas } = options;
|
|
2512
|
-
const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
|
|
2513
|
-
const contextSettings = options.contextSettings || leafer.config.contextSettings;
|
|
2514
|
-
const screenshot = options.screenshot || leaf.isApp;
|
|
2515
|
-
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
2516
|
-
const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
|
|
2517
|
-
if (screenshot) {
|
|
2518
|
-
renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
|
|
2519
|
-
}
|
|
2520
|
-
else {
|
|
2521
|
-
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
2522
|
-
scaleX = worldTransform.scaleX;
|
|
2523
|
-
scaleY = worldTransform.scaleY;
|
|
2524
|
-
switch (relative) {
|
|
2525
|
-
case 'inner':
|
|
2526
|
-
matrix.set(worldTransform);
|
|
2527
|
-
break;
|
|
2528
|
-
case 'local':
|
|
2529
|
-
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
2530
|
-
scaleX /= leaf.scaleX;
|
|
2531
|
-
scaleY /= leaf.scaleY;
|
|
2532
|
-
break;
|
|
2533
|
-
case 'world':
|
|
2534
|
-
scaleX = 1;
|
|
2535
|
-
scaleY = 1;
|
|
2536
|
-
break;
|
|
2537
|
-
case 'page':
|
|
2538
|
-
relative = leaf.leafer;
|
|
2539
|
-
default:
|
|
2540
|
-
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
2541
|
-
const l = relative.worldTransform;
|
|
2542
|
-
scaleX /= scaleX / l.scaleX;
|
|
2543
|
-
scaleY /= scaleY / l.scaleY;
|
|
2544
|
-
}
|
|
2545
|
-
renderBounds = leaf.getBounds('render', relative);
|
|
2546
|
-
}
|
|
2547
|
-
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
2548
|
-
MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2549
|
-
let pixelRatio = options.pixelRatio || 1;
|
|
2550
|
-
if (leaf.isApp) {
|
|
2551
|
-
scaleData.scaleX *= pixelRatio;
|
|
2552
|
-
scaleData.scaleY *= pixelRatio;
|
|
2553
|
-
pixelRatio = leaf.app.pixelRatio;
|
|
2554
|
-
}
|
|
2555
|
-
const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2556
|
-
const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
|
|
2557
|
-
let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
|
|
2558
|
-
let sliceLeaf;
|
|
2559
|
-
if (slice) {
|
|
2560
|
-
sliceLeaf = leaf;
|
|
2561
|
-
sliceLeaf.__worldOpacity = 0;
|
|
2562
|
-
leaf = leafer;
|
|
2563
|
-
renderOptions.bounds = canvas.bounds;
|
|
2564
|
-
}
|
|
2565
|
-
canvas.save();
|
|
2566
|
-
if (isFrame && fill !== undefined) {
|
|
2567
|
-
const oldFill = leaf.get('fill');
|
|
2568
|
-
leaf.fill = '';
|
|
2569
|
-
leaf.__render(canvas, renderOptions);
|
|
2570
|
-
leaf.fill = oldFill;
|
|
2571
|
-
}
|
|
2572
|
-
else {
|
|
2573
|
-
leaf.__render(canvas, renderOptions);
|
|
2574
|
-
}
|
|
2575
|
-
canvas.restore();
|
|
2576
|
-
if (sliceLeaf)
|
|
2577
|
-
sliceLeaf.__updateWorldOpacity();
|
|
2578
|
-
if (trim) {
|
|
2579
|
-
trimBounds = getTrimBounds(canvas);
|
|
2580
|
-
const old = canvas, { width, height } = trimBounds;
|
|
2581
|
-
const config = { x: 0, y: 0, width, height, pixelRatio };
|
|
2582
|
-
canvas = Creator.canvas(config);
|
|
2583
|
-
canvas.copyWorld(old, trimBounds, config);
|
|
2584
|
-
}
|
|
2585
|
-
if (needFill)
|
|
2586
|
-
canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
|
|
2587
|
-
if (onCanvas)
|
|
2588
|
-
onCanvas(canvas);
|
|
2589
|
-
const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
|
|
2590
|
-
over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
|
|
2591
|
-
}));
|
|
2592
|
-
}
|
|
2593
|
-
else {
|
|
2594
|
-
over({ data: false });
|
|
2595
|
-
}
|
|
2596
|
-
}));
|
|
2597
|
-
}
|
|
2598
|
-
};
|
|
2599
|
-
let tasker;
|
|
2600
|
-
function addTask(task) {
|
|
2601
|
-
if (!tasker)
|
|
2602
|
-
tasker = new TaskProcessor();
|
|
2603
|
-
return new Promise((resolve) => {
|
|
2604
|
-
tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
|
|
2605
|
-
});
|
|
2606
|
-
}
|
|
2607
|
-
function checkLazy(leaf) {
|
|
2608
|
-
if (leaf.__.__needComputePaint)
|
|
2609
|
-
leaf.__.__computePaint();
|
|
2610
|
-
if (leaf.isBranch)
|
|
2611
|
-
leaf.children.forEach(child => checkLazy(child));
|
|
2612
|
-
}
|
|
2613
|
-
|
|
2614
|
-
const canvas = LeaferCanvasBase.prototype;
|
|
2615
|
-
const debug = Debug.get('@leafer-ui/export');
|
|
2616
|
-
canvas.export = function (filename, options) {
|
|
2617
|
-
const { quality, blob } = FileHelper.getExportOptions(options);
|
|
2618
|
-
if (filename.includes('.'))
|
|
2619
|
-
return this.saveAs(filename, quality);
|
|
2620
|
-
else if (blob)
|
|
2621
|
-
return this.toBlob(filename, quality);
|
|
2622
|
-
else
|
|
2623
|
-
return this.toDataURL(filename, quality);
|
|
2624
|
-
};
|
|
2625
|
-
canvas.toBlob = function (type, quality) {
|
|
2626
|
-
return new Promise((resolve) => {
|
|
2627
|
-
Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
|
|
2628
|
-
resolve(blob);
|
|
2629
|
-
}).catch((e) => {
|
|
2630
|
-
debug.error(e);
|
|
2631
|
-
resolve(null);
|
|
2632
|
-
});
|
|
2633
|
-
});
|
|
2634
|
-
};
|
|
2635
|
-
canvas.toDataURL = function (type, quality) {
|
|
2636
|
-
return Platform.origin.canvasToDataURL(this.view, type, quality);
|
|
2637
|
-
};
|
|
2638
|
-
canvas.saveAs = function (filename, quality) {
|
|
2639
|
-
return new Promise((resolve) => {
|
|
2640
|
-
Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
|
|
2641
|
-
resolve(true);
|
|
2642
|
-
}).catch((e) => {
|
|
2643
|
-
debug.error(e);
|
|
2644
|
-
resolve(false);
|
|
2645
|
-
});
|
|
2646
|
-
});
|
|
2647
|
-
};
|
|
2648
|
-
|
|
2649
2349
|
Object.assign(TextConvert, TextConvertModule);
|
|
2650
2350
|
Object.assign(ColorConvert, ColorConvertModule);
|
|
2651
2351
|
Object.assign(Paint, PaintModule);
|
|
2652
2352
|
Object.assign(PaintImage, PaintImageModule);
|
|
2653
2353
|
Object.assign(PaintGradient, PaintGradientModule);
|
|
2654
2354
|
Object.assign(Effect, EffectModule);
|
|
2655
|
-
Object.assign(Export, ExportModule);
|
|
2656
2355
|
|
|
2657
2356
|
Object.assign(Creator, {
|
|
2658
2357
|
interaction: (target, canvas, selector, options) => new InteractionBase(target, canvas, selector, options),
|
|
@@ -2661,4 +2360,4 @@ Object.assign(Creator, {
|
|
|
2661
2360
|
});
|
|
2662
2361
|
useCanvas();
|
|
2663
2362
|
|
|
2664
|
-
export { Layouter, LeaferCanvas, Renderer, Selector, Watcher, useCanvas };
|
|
2363
|
+
export { Layouter, LeaferCanvas, Picker, Renderer, Selector, Watcher, useCanvas };
|
package/dist/worker.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,Creator as n,LeaferImage as s,defineKey as a,FileHelper as o,LeafList as r,DataHelper as d,RenderEvent as l,ChildEvent as h,WatchEvent as c,PropertyEvent as u,LeafHelper as f,BranchHelper as g,Bounds as _,LeafBoundsHelper as p,Debug as w,LeafLevelList as y,LayoutEvent as m,Run as v,ImageManager as x,ResizeEvent as b,BoundsHelper as B,Answer as k,MatrixHelper as R,MathHelper as S,AlignHelper as E,ImageEvent as L,AroundHelper as A,PointHelper as M,Direction4 as W,TwoPointBoundsHelper as C,TaskProcessor as O,Matrix as T}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionBase as I,HitCanvasManager as P}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as D,ColorConvert as F,PaintGradient as Y,Export as N,Group as X,TextConvert as G,Paint as U,Effect as j}from"@leafer-ui/draw";class H extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i),this.clientBounds=this.bounds}}i(OffscreenCanvasRenderingContext2D.prototype),i(Path2D.prototype);const{mineType:z}=o;function V(t,i){e.origin={createCanvas:(t,e)=>new OffscreenCanvas(t,e),canvasToDataURL:(t,e,i)=>new Promise(((n,s)=>{t.convertToBlob({type:z(e),quality:i}).then((t=>{var e=new FileReader;e.onload=t=>n(t.target.result),e.onerror=t=>s(t),e.readAsDataURL(t)})).catch((t=>{s(t)}))})),canvasToBolb:(t,e,i)=>t.convertToBlob({type:z(e),quality:i}),canvasSaveAs:(t,e,i)=>new Promise((t=>t())),download(t,e){},loadImage:t=>new Promise(((i,n)=>{let s=new XMLHttpRequest;s.open("GET",e.image.getRealURL(t),!0),s.responseType="blob",s.onload=()=>{createImageBitmap(s.response).then((t=>{i(t)})).catch((t=>{n(t)}))},s.onerror=t=>n(t),s.send()}))},e.canvas=n.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient}Object.assign(n,{canvas:(t,e)=>new H(t,e),image:t=>new s(t)}),e.name="web",e.isWorker=!0,e.requestRender=function(t){requestAnimationFrame(t)},a(e,"devicePixelRatio",{get:()=>1});const{userAgent:q}=navigator;q.indexOf("Firefox")>-1?(e.conicGradientRotate90=!0,e.intWheelDeltaY=!0):q.indexOf("Safari")>-1&&-1===q.indexOf("Chrome")&&(e.fullImageShadow=!0),q.indexOf("Windows")>-1?(e.os="Windows",e.intWheelDeltaY=!0):q.indexOf("Mac")>-1?e.os="Mac":q.indexOf("Linux")>-1&&(e.os="Linux");class Q{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new r;return this.__updatedList.list.forEach((e=>{e.leafer&&t.add(e)})),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new r,this.target=t,e&&(this.config=d.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(l.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===h.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new c(c.DATA,{updatedList:this.updatedList})),this.__updatedList=new r,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.CHANGE,this.__onAttrChange,this),t.on_([h.ADD,h.REMOVE],this.__onChildEvent,this),t.on_(c.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:J,updateBounds:Z,updateAllWorldOpacity:K}=f,{pushAllChildBranch:$,pushAllParent:tt}=g;const{worldBounds:et}=p,it={x:0,y:0,width:1e5,height:1e5};class nt{constructor(t){this.updatedBounds=new _,this.beforeBounds=new _,this.afterBounds=new _,t instanceof Array&&(t=new r(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,et)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(it):this.afterBounds.setListWithFn(t,et),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:st,updateAllChange:at}=f,ot=w.get("Layouter");class rt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,this.target=t,e&&(this.config=d.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(m.START),this.layoutOnce(),t.emitEvent(new m(m.END,this.layoutedBlocks,this.times))}catch(t){ot.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ot.warn("layouting"):this.times>3?ot.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(c.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=v.start("PartLayout"),{target:i,__updatedList:n}=this,{BEFORE:s,LAYOUT:a,AFTER:o}=m,r=this.getBlocks(n);r.forEach((t=>t.setBefore())),i.emitEvent(new m(s,r,this.times)),this.extraBlock=null,n.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(J(t,!0),e.add(t),t.isBranch&&$(t,e),tt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),tt(t,e)))}))}(n,this.__levelList),function(t){let e,i,n;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(i=e[t],i.isBranch&&i.__tempNumber){n=i.children;for(let t=0,e=n.length;t<e;t++)n[t].isBranch||Z(n[t])}Z(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&K(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(n),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new m(a,r,this.times)),i.emitEvent(new m(o,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,v.end(e)}fullLayout(){const t=v.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:n,AFTER:s}=m,a=this.getBlocks(new r(e));e.emitEvent(new m(i,a,this.times)),rt.fullLayout(e),a.forEach((t=>{t.setAfter()})),e.emitEvent(new m(n,a,this.times)),e.emitEvent(new m(s,a,this.times)),this.addBlocks(a),v.end(t)}static fullLayout(t){st(t,!0),t.isBranch?g.updateBounds(t):f.updateBounds(t),at(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new nt([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new nt(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(m.REQUEST,this.layout,this),t.on_(m.AGAIN,this.layoutAgain,this),t.on_(c.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const dt=w.get("Renderer");class lt{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=d.default(i,this.config)),this.__listenEvents()}start(){this.running=!0,this.update(!1)}stop(){this.running=!1}update(t=!0){this.changed||(this.changed=t),this.__requestRender()}requestLayout(){this.target.emit(m.REQUEST)}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new _,dt.log(e.innerName,"---\x3e");try{e.isApp||e.app.emit(l.CHILD_START,e),this.emitRender(l.START),this.renderOnce(t),this.emitRender(l.END,this.totalBounds),x.clearRecycled()}catch(t){this.rendering=!1,dt.error(t)}dt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return dt.warn("rendering");if(this.times>3)return dt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new _,this.renderOptions={},t)this.emitRender(l.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(l.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(l.RENDER,this.renderBounds,this.renderOptions),this.emitRender(l.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return dt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=v.start("PartRender"),{canvas:i}=this,n=t.getIntersect(i.bounds),s=t.includes(this.target.__world),a=new _(n);i.save(),s&&!w.showRepaint?i.clear():(n.spread(10+1/this.canvas.pixelRatio).ceil(),i.clearWorld(n,!0),i.clipWorld(n,!0)),this.__render(n,s,a),i.restore(),v.end(e)}fullRender(){const t=v.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),v.end(t)}__render(t,e,i){const n=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),w.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,n),this.renderBounds=i=i||t,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=i:this.totalBounds.add(i),w.showHitView&&this.renderHitView(n),w.showBoundsView&&this.renderBoundsView(n),this.canvas.updateRender(i)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new _;e.setList(t),t.length=0,t.push(e)}}__requestRender(){if(this.requestTime)return;const t=this.requestTime=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.requestTime=0,this.running&&(this.changed&&this.canvas.view&&this.render(),this.target.emit(l.NEXT))}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new _(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new _(0,0,1,1)),this.update()}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||dt.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new l(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(l.REQUEST,this.update,this),t.on_(m.END,this.__onLayoutEnd,this),t.on_(l.AGAIN,this.renderAgain,this),t.on_(b.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}const{hitRadiusPoint:ht}=B;class ct{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const n=i.through||!1,s=i.ignoreHittable||!1,a=i.target||this.target;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=new r(i.findList),i.findList||this.hitBranch(a);const{list:o}=this.findList,d=this.getBestMatchLeaf(o,i.bottomList,s),l=s?this.getPath(d):this.getHitablePath(d);return this.clear(),n?{path:l,target:d,throughPath:o.length?this.getThroughPath(o):l}:{path:l,target:d}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new r;const{x:n,y:s}=this.point,a={x:n,y:s,radiusX:0,radiusY:0};for(let n=0,s=t.length;n<s;n++)if(e=t[n],(i||f.worldHittable(e))&&(this.hitChild(e,a),this.findList.length))return this.findList.list[0]}if(e)for(let t=0,i=e.length;t<i;t++)if(this.hitChild(e[t].target,this.point,e[t].proxy),this.findList.length)return this.findList.list[0];return t[0]}getPath(t){const e=new r;for(;t;)e.add(t),t=t.parent;return this.target&&e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,n=new r;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(n.addAt(i,0),i.__.hitChildren);t--);return n}getThroughPath(t){const e=new r,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let n,s,a;for(let t=0,o=i.length;t<o;t++){n=i[t],s=i[t+1];for(let t=0,i=n.length;t<i&&(a=n.list[t],!s||!s.has(a));t++)e.add(a)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}eachFind(t,e){let i,n;const{point:s}=this;for(let a=t.length-1;a>-1;a--)i=t[a],!i.__.visible||e&&!i.__.mask||(n=!!i.__.hitRadius||ht(i.__world,s),i.isBranch?(n||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&this.hitChild(i,s)):n&&this.hitChild(i,s))}hitChild(t,e,i){if((!this.exclude||!this.exclude.has(t))&&t.__hitWorld(e)){const{parent:n}=t;if(n&&n.__hasMask&&!t.__.mask&&!n.children.some((t=>t.__.mask&&t.__hitWorld(e))))return;this.findList.add(i||t)}}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}const{Yes:ut,NoAndSkip:ft,YesAndSkip:gt}=k,_t={},pt={},wt={};class yt{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},this.target=t,e&&(this.config=d.default(e,this.config)),this.picker=new ct(t,this),t&&this.__listenEvents()}getBy(t,e,i,n){switch(typeof t){case"number":const s=this.getByInnerId(t,e);return i?s:s?[s]:[];case"string":switch(t[0]){case"#":_t.id=t.substring(1),t=_t;break;case".":pt.className=t.substring(1),t=pt;break;default:wt.tag=t,t=wt}case"object":if(void 0!==t.id){const n=this.getById(t.id,e);return i?n:n?[n]:[]}if(t.tag){const{tag:n}=t,s=n instanceof Array;return this.getByMethod(s?this.methods.tags:this.methods.tag,e,i,s?d.toMap(n):n)}return this.getByMethod(this.methods.className,e,i,t.className);case"function":return this.getByMethod(t,e,i,n)}}getByPoint(t,i,n){return"node"===e.name&&this.target&&this.target.emit(m.CHECK_UPDATE),this.picker.getByPoint(t,i,n)}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,e){const i=this.idMap[t];return i&&f.hasParent(i,e||this.target)?i:(this.eachFind(this.toChildren(e),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,n){const s=i?null:[];return this.eachFind(this.toChildren(e),t,s,n),s||this.findLeaf}eachFind(t,e,i,n){let s,a;for(let o=0,r=t.length;o<r;o++){if(s=t[o],a=e(s,n),a===ut||a===gt){if(!i)return void(this.findLeaf=s);i.push(s)}s.isBranch&&a<ft&&this.eachFind(s.children,e,i,n)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(h.REMOVE,this.__onRemoveChild,this),this.target.on_(u.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.picker.destroy(),this.findLeaf=null,this.innerIdMap={},this.idMap={})}}function mt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:a}=t.__.__textDrawData;for(let t=0,o=n.length;t<o;t++)i=n[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),s&&e.fillRect(i.x,i.y+s,i.width,a)}function vt(t,e,i){const{strokeAlign:n}=e.__,s="string"!=typeof t;switch(n){case"center":i.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?Bt(t,!0,e,i):bt(e,i);break;case"inside":xt("inside",t,s,e,i);break;case"outside":xt("outside",t,s,e,i)}}function xt(t,e,i,n,s){const{__strokeWidth:a,__font:o}=n.__,r=s.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*a,n.__),r.font=o,i?Bt(e,!0,n,r):bt(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",mt(n,r),r.blendMode="normal",n.__worldFlipped?s.copyWorldByReset(r,n.__nowWorld):s.copyWorldToInner(r,n.__nowWorld,n.__layout.renderBounds),r.recycle(n.__nowWorld)}function bt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:a}=t.__.__textDrawData;for(let t=0,o=n.length;t<o;t++)i=n[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),s&&e.strokeRect(i.x,i.y+s,i.width,a)}function Bt(t,e,i,n){let s;for(let a=0,o=t.length;a<o;a++)s=t[a],s.image&&D.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?bt(i,n):n.stroke(),n.restoreBlendMode()):e?bt(i,n):n.stroke())}function kt(t,e){t.__.dashPattern&&(e.beginPath(),t.__drawPathByData(e,t.__.__pathForArrow),e.dashPattern=null,e.stroke())}Object.assign(n,{watcher:(t,e)=>new Q(t,e),layouter:(t,e)=>new rt(t,e),renderer:(t,e,i)=>new lt(t,e,i),selector:(t,e)=>new yt(t,e)}),e.layout=rt.fullLayout;const{getSpread:Rt,getOuterOf:St,getByMove:Et,getIntersectData:Lt}=B;let At;function Mt(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:n}=i.__layout;switch(e.type){case"solid":let{type:s,blendMode:a,color:o,opacity:r}=e;return{type:s,blendMode:a,style:F.string(o,r)};case"image":return D.image(i,t,e,n,!At||!At[e.url]);case"linear":return Y.linearGradient(e,n);case"radial":return Y.radialGradient(e,n);case"angular":return Y.conicGradient(e,n);default:return void 0!==e.r?{type:"solid",style:F.string(e)}:void 0}}const Wt={compute:function(t,e){const i=e.__,n=[];let s,a=i.__input[t];a instanceof Array||(a=[a]),At=D.recycleImage(t,i);for(let i,s=0,o=a.length;s<o;s++)i=Mt(t,a[s],e),i&&n.push(i);i["_"+t]=n.length?n:void 0,n.length&&n[0].image&&(s=n[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=s:i.__pixelStroke=s},fill:function(t,e,i){i.fillStyle=t,e.__.__font?mt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let n;const{windingRule:s,__font:a}=e.__;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&D.checkImage(e,i,n,!a)||n.style&&(i.fillStyle=n.style,n.transform?(i.save(),i.transform(n.transform),n.blendMode&&(i.blendMode=n.blendMode),a?mt(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),a?mt(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):a?mt(e,i):s?i.fill(s):i.fill())},fillText:mt,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:a,__font:o}=n;if(s)if(o)vt(t,e,i);else switch(a){case"center":i.setStroke(t,s,n),i.stroke(),n.__useArrow&&kt(e,i);break;case"inside":i.save(),i.setStroke(t,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const a=i.getSameCanvas(!0,!0);a.setStroke(t,2*s,n),e.__drawRenderPath(a),a.stroke(),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,e.__layout.renderBounds),a.recycle(e.__nowWorld)}},strokes:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:a,__font:o}=n;if(s)if(o)vt(t,e,i);else switch(a){case"center":i.setStroke(void 0,s,n),Bt(t,!1,e,i),n.__useArrow&&kt(e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),Bt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:a}=e.__layout,o=i.getSameCanvas(!0,!0);e.__drawRenderPath(o),o.setStroke(void 0,2*s,n),Bt(t,!1,e,o),n.windingRule?o.clip(n.windingRule):o.clip(),o.clearWorld(a),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,a),o.recycle(e.__nowWorld)}},strokeText:vt,drawTextStroke:bt,shape:function(t,e,i){const n=e.getSameCanvas(),s=t.__nowWorld;let a,o,r,d,{scaleX:l,scaleY:h}=s;if(l<0&&(l=-l),h<0&&(h=-h),e.bounds.includes(s))d=n,a=r=s;else{const{renderShapeSpread:n}=t.__layout,c=Lt(n?Rt(e.bounds,l===h?n*l:[n*h,n*l]):e.bounds,s);o=e.bounds.getFitMatrix(c);let{a:u,d:f}=o;if(o.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,h*=f),r=St(s,o),a=Et(r,-o.e,-o.f),i.matrix){const{matrix:t}=i;o.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:o.withScale(u,f)})}return t.__renderShape(n,i),{canvas:n,matrix:o,bounds:a,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:h}}};let Ct={};const{get:Ot,rotateOfOuter:Tt,translate:It,scaleOfOuter:Pt,scale:Dt,rotate:Ft}=R;function Yt(t,e,i,n,s,a,o){const r=Ot();It(r,e.x+i,e.y+n),Dt(r,s,a),o&&Tt(r,{x:e.x+e.width/2,y:e.y+e.height/2},o),t.transform=r}function Nt(t,e,i,n,s,a,o){const r=Ot();It(r,e.x+i,e.y+n),s&&Dt(r,s,a),o&&Ft(r,o),t.transform=r}function Xt(t,e,i,n,s,a,o,r,d,l){const h=Ot();if(d)if("center"===l)Tt(h,{x:i/2,y:n/2},d);else switch(Ft(h,d),d){case 90:It(h,n,0);break;case 180:It(h,i,n);break;case 270:It(h,0,i)}Ct.x=e.x+s,Ct.y=e.y+a,It(h,Ct.x,Ct.y),o&&Pt(h,Ct,o,r),t.transform=h}const{get:Gt,translate:Ut}=R,jt=new _,Ht={},zt={};function Vt(t,e,i,n){const{blendMode:s,sync:a}=i;s&&(t.blendMode=s),a&&(t.sync=a),t.data=qt(i,n,e)}function qt(t,e,i){let{width:n,height:s}=i;t.padding&&(e=jt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:a,mode:o,align:r,offset:d,scale:l,size:h,rotation:c,repeat:u}=t,f=e.width===n&&e.height===s,g={mode:o},_="center"!==r&&(c||0)%180==90,p=_?s:n,w=_?n:s;let y,m,v=0,x=0;if(o&&"cover"!==o&&"fit"!==o)(l||h)&&(S.getScaleData(l,h,i,zt),y=zt.scaleX,m=zt.scaleY);else if(!f||c){const t=e.width/p,i=e.height/w;y=m="fit"===o?Math.min(t,i):Math.max(t,i),v+=(e.width-n*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:p,height:w};y&&(t.width*=y,t.height*=m),E.toPoint(r,t,e,Ht,!0),v+=Ht.x,x+=Ht.y}switch(d&&(v+=d.x,x+=d.y),o){case"stretch":f||(n=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||c)&&Nt(g,e,v,x,y,m,c);break;case"repeat":(!f||y||c)&&Xt(g,e,n,s,v,x,y,m,c,r),u||(g.repeat="repeat");break;default:y&&Yt(g,e,v,x,y,m,c)}return g.transform||(e.x||e.y)&&(g.transform=Gt(),Ut(g.transform,e.x,e.y)),y&&"stretch"!==o&&(g.scaleX=y,g.scaleY=m),g.width=n,g.height=s,a&&(g.opacity=a),u&&(g.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),g}let Qt,Jt=new _;const{isSame:Zt}=B;function Kt(t,e,i,n,s,a){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=n.width/e.pixelRatio,e.__naturalHeight=n.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||Vt(s,n,i,a),!0}function $t(t,e){ie(t,L.LOAD,e)}function te(t,e){ie(t,L.LOADED,e)}function ee(t,e,i){e.error=i,t.forceUpdate("surface"),ie(t,L.ERROR,e)}function ie(t,e,i){t.hasEvent(e)&&t.emitEvent(new L(e,i))}function ne(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:se,scale:ae,copy:oe}=R,{ceil:re,abs:de}=Math;function le(t,i,n){let{scaleX:s,scaleY:a}=x.patternLocked?t.__world:t.__nowWorld;const o=s+"-"+a+"-"+n;if(i.patternId===o||t.destroyed)return!1;{s=de(s),a=de(a);const{image:t,data:r}=i;let d,l,{width:h,height:c,scaleX:u,scaleY:f,opacity:g,transform:_,repeat:p}=r;u&&(l=se(),oe(l,_),ae(l,1/u,1/f),s*=u,a*=f),s*=n,a*=n,h*=s,c*=a;const w=h*c;if(!p&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,a/=d,h/=d,c/=d),u&&(s/=u,a/=f),(_||1!==s||1!==a)&&(l||(l=se(),_&&oe(l,_)),ae(l,1/s,1/a));const m=t.getCanvas(re(h)||1,re(c)||1,g),v=t.getPattern(m,p||e.origin.noRepeat||"no-repeat",l,i);return i.style=v,i.patternId=o,!0}}function he(t,e,i,n){return new(i||(i=Promise))((function(s,a){function o(t){try{d(n.next(t))}catch(t){a(t)}}function r(t){try{d(n.throw(t))}catch(t){a(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,r)}d((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:ce}=Math;const ue={image:function(t,e,i,n,s){let a,o;const r=x.get(i);return Qt&&i===Qt.paint&&Zt(n,Qt.boxBounds)?a=Qt.leafPaint:(a={type:i.type,image:r},Qt=r.use>1?{leafPaint:a,paint:i,boxBounds:Jt.set(n)}:null),(s||r.loading)&&(o={image:r,attrName:e,attrValue:i}),r.ready?(Kt(t,e,i,r,a,n),s&&($t(t,o),te(t,o))):r.error?s&&ee(t,o,r.error):(s&&(ne(t,!0),$t(t,o)),a.loadId=r.load((()=>{ne(t,!1),t.destroyed||(Kt(t,e,i,r,a,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),te(t,o)),a.loadId=null}),(e=>{ne(t,!1),ee(t,o,e),a.loadId=null}))),a},checkImage:function(t,i,n,s){const{scaleX:a,scaleY:o}=x.patternLocked?t.__world:t.__nowWorld,{pixelRatio:r}=i;if(!n.data||n.patternId===a+"-"+o+"-"+r&&!N.running)return!1;{const{data:d}=n;if(s)if(d.repeat)s=!1;else{let{width:t,height:i}=d;t*=ce(a)*r,i*=ce(o)*r,d.scaleX&&(t*=d.scaleX,i*=d.scaleY),s=t*i>e.image.maxCacheSize||N.running}return s?(i.save(),t.windingRule?i.clip(t.windingRule):i.clip(),n.blendMode&&(i.blendMode=n.blendMode),d.opacity&&(i.opacity*=d.opacity),d.transform&&i.transform(d.transform),i.drawImage(n.image.view,0,0,d.width,d.height),i.restore(),!0):(!n.style||n.sync||N.running?le(t,n,r):n.patternTask||(n.patternTask=x.patternTasker.add((()=>he(this,void 0,void 0,(function*(){n.patternTask=null,i.bounds.hit(t.__nowWorld)&&le(t,n,r),t.forceUpdate("surface")}))),300)),!1)}},createPattern:le,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let n,s,a,o;for(let r=0,d=i.length;r<d;r++)n=i[r].image,o=n&&n.url,o&&(s||(s={}),s[o]=!0,x.recycle(n),n.loading&&(a||(a=e.__input&&e.__input[t]||[],a instanceof Array||(a=[a])),n.unload(i[r].loadId,!a.some((t=>t.url===o)))));return s}return null},createData:Vt,getPatternData:qt,fillOrFitMode:Yt,clipMode:Nt,repeatMode:Xt},{toPoint:fe}=A,ge={},_e={};function pe(t,e,i){if(e){let n;for(let s=0,a=e.length;s<a;s++)n=e[s],"string"==typeof n?t.addColorStop(s/(a-1),F.string(n,i)):t.addColorStop(n.offset,F.string(n.color,i))}}const{getAngle:we,getDistance:ye}=M,{get:me,rotateOfOuter:ve,scaleOfOuter:xe}=R,{toPoint:be}=A,Be={},ke={};function Re(t,e,i,n,s){let a;const{width:o,height:r}=t;if(o!==r||n){const t=we(e,i);a=me(),s?(xe(a,e,o/r*(n||1),1),ve(a,e,t+90)):(xe(a,e,1,o/r*(n||1)),ve(a,e,t))}return a}const{getDistance:Se}=M,{toPoint:Ee}=A,Le={},Ae={};const Me={linearGradient:function(t,i){let{from:n,to:s,type:a,blendMode:o,opacity:r}=t;fe(n||"top",i,ge),fe(s||"bottom",i,_e);const d=e.canvas.createLinearGradient(ge.x,ge.y,_e.x,_e.y);pe(d,t.stops,r);const l={type:a,style:d};return o&&(l.blendMode=o),l},radialGradient:function(t,i){let{from:n,to:s,type:a,opacity:o,blendMode:r,stretch:d}=t;be(n||"center",i,Be),be(s||"bottom",i,ke);const l=e.canvas.createRadialGradient(Be.x,Be.y,0,Be.x,Be.y,ye(Be,ke));pe(l,t.stops,o);const h={type:a,style:l},c=Re(i,Be,ke,d,!0);return c&&(h.transform=c),r&&(h.blendMode=r),h},conicGradient:function(t,i){let{from:n,to:s,type:a,opacity:o,blendMode:r,stretch:d}=t;Ee(n||"center",i,Le),Ee(s||"bottom",i,Ae);const l=e.conicGradientSupport?e.canvas.createConicGradient(0,Le.x,Le.y):e.canvas.createRadialGradient(Le.x,Le.y,0,Le.x,Le.y,Se(Le,Ae));pe(l,t.stops,o);const h={type:a,style:l},c=Re(i,Le,Ae,d||1,e.conicGradientRotate90);return c&&(h.transform=c),r&&(h.blendMode=r),h},getTransform:Re},{copy:We,toOffsetOutBounds:Ce}=B,Oe={},Te={};function Ie(t,i,n,s){const{bounds:a,shapeBounds:o}=s;if(e.fullImageShadow){if(We(Oe,t.bounds),Oe.x+=i.x-o.x,Oe.y+=i.y-o.y,n){const{matrix:t}=s;Oe.x-=(a.x+(t?t.e:0)+a.width/2)*(n-1),Oe.y-=(a.y+(t?t.f:0)+a.height/2)*(n-1),Oe.width*=n,Oe.height*=n}t.copyWorld(s.canvas,t.bounds,Oe)}else n&&(We(Oe,i),Oe.x-=i.width/2*(n-1),Oe.y-=i.height/2*(n-1),Oe.width*=n,Oe.height*=n),t.copyWorld(s.canvas,o,n?Oe:i)}const{toOffsetOutBounds:Pe}=B,De={};const Fe={shadow:function(t,e,i){let n,s;const{__nowWorld:a,__layout:o}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),g=r.length-1;Ce(l,Te),r.forEach(((r,_)=>{f.setWorldShadow(Te.offsetX+r.x*c,Te.offsetY+r.y*u,r.blur*c,r.color),s=r.spread?1+2*r.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0)):0,Ie(f,Te,s,i),n=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,a,"copy"),n=a),d?f.copyWorld(d,a,a,"destination-out"):f.copyWorld(i.canvas,h,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,n,a,r.blendMode):e.copyWorldToInner(f,n,o.renderBounds,r.blendMode),g&&_<g&&f.clearWorld(n,!0)})),f.recycle(n)},innerShadow:function(t,e,i){let n,s;const{__nowWorld:a,__layout:o}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),g=r.length-1;Pe(l,De),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(De.offsetX+r.x*c,De.offsetY+r.y*u,r.blur*c),s=r.spread?1-2*r.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0)):0,Ie(f,De,s,i),f.restore(),d?(f.copyWorld(f,l,a,"copy"),f.copyWorld(d,a,a,"source-out"),n=a):(f.copyWorld(i.canvas,h,l,"source-out"),n=l),f.fillWorld(n,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,n,a,r.blendMode):e.copyWorldToInner(f,n,o.renderBounds,r.blendMode),g&&_<g&&f.clearWorld(n,!0)})),f.recycle(n)},blur:function(t,e,i){const{blur:n}=t.__;i.setWorldBlur(n*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Ye}=p;function Ne(t,e,i,n,s,a){switch(e){case"grayscale":s.useGrayscaleAlpha(t.__nowWorld);case"alpha":!function(t,e,i,n){const s=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(n,s),n.recycle(s),Ge(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Ge(t,i,n,a);break;case"path":i.restore()}}function Xe(t){return t.getSameCanvas(!1,!0)}function Ge(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}X.prototype.__renderMask=function(t,e){let i,n,s,a,o,r;const{children:d}=this;for(let l=0,h=d.length;l<h;l++)i=d[l],r=i.__.mask,r&&(o&&(Ne(this,o,t,s,n,a),n=s=null),"path"===r||"clipping-path"===r?(i.opacity<1?(o="opacity-path",a=i.opacity,s||(s=Xe(t))):(o="path",t.save()),i.__clip(s||t,e)):(o="grayscale"===r?"grayscale":"alpha",n||(n=Xe(t)),s||(s=Xe(t)),i.__render(n,e)),"clipping"!==r&&"clipping-path"!==r)||Ye(i,e)||i.__render(s||t,e);Ne(this,o,t,s,n,a)};const Ue=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",je=Ue+"_#~&*+\\=|≮≯≈≠=…",He=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function ze(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Ve=ze("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),qe=ze("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Qe=ze(Ue),Je=ze(je),Ze=ze("- —/~|┆·");var Ke;!function(t){t[t.Letter=0]="Letter",t[t.Single=1]="Single",t[t.Before=2]="Before",t[t.After=3]="After",t[t.Symbol=4]="Symbol",t[t.Break=5]="Break"}(Ke||(Ke={}));const{Letter:$e,Single:ti,Before:ei,After:ii,Symbol:ni,Break:si}=Ke;function ai(t){return Ve[t]?$e:Ze[t]?si:qe[t]?ei:Qe[t]?ii:Je[t]?ni:He.test(t)?ti:$e}const oi={trimRight(t){const{words:e}=t;let i,n=0,s=e.length;for(let a=s-1;a>-1&&(i=e[a].data[0]," "===i.char);a--)n++,t.width-=i.width;n&&e.splice(s-n,n)}};function ri(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:di}=oi,{Letter:li,Single:hi,Before:ci,After:ui,Symbol:fi,Break:gi}=Ke;let _i,pi,wi,yi,mi,vi,xi,bi,Bi,ki,Ri,Si,Ei,Li,Ai,Mi,Wi,Ci=[];function Oi(t,e){Bi&&!bi&&(bi=Bi),_i.data.push({char:t,width:e}),wi+=e}function Ti(){yi+=wi,_i.width=wi,pi.words.push(_i),_i={data:[]},wi=0}function Ii(){Li&&(Ai.paraNumber++,pi.paraStart=!0,Li=!1),Bi&&(pi.startCharSize=bi,pi.endCharSize=Bi,bi=0),pi.width=yi,Mi.width?di(pi):Wi&&Pi(),Ci.push(pi),pi={words:[]},yi=0}function Pi(){yi>(Ai.maxWidth||0)&&(Ai.maxWidth=yi)}const Di=0,Fi=1,Yi=2;const{top:Ni,right:Xi,bottom:Gi,left:Ui}=W;function ji(t,e,i){const{bounds:n,rows:s}=t;n[e]+=i;for(let t=0;t<s.length;t++)s[t][e]+=i}const Hi={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let n=0,s=0,a=i.__getInput("width")||0,o=i.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=i;l&&(a?(n=l[Ui],a-=l[Xi]+l[Ui]):i.autoSizeAlign||(n=l[Ui]),o?(s=l[Ni],o-=l[Ni]+l[Gi]):i.autoSizeAlign||(s=l[Ni]));const h={bounds:{x:n,y:s,width:a,height:o},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,i,n){Ai=t,Ci=t.rows,Mi=t.bounds,Wi=!Mi.width&&!n.autoSizeAlign;const{__letterSpacing:s,paraIndent:a,textCase:o}=n,{canvas:r}=e,{width:d,height:l}=Mi;if(d||l||s||"none"!==o){const t="none"!==n.textWrap,e="break"===n.textWrap;Li=!0,Ri=null,bi=xi=Bi=wi=yi=0,_i={data:[]},pi={words:[]};for(let n=0,l=i.length;n<l;n++)vi=i[n],"\n"===vi?(wi&&Ti(),pi.paraEnd=!0,Ii(),Li=!0):(ki=ai(vi),ki===li&&"none"!==o&&(vi=ri(vi,o,!wi)),xi=r.measureText(vi).width,s&&(s<0&&(Bi=xi),xi+=s),Si=ki===hi&&(Ri===hi||Ri===li)||Ri===hi&&ki!==ui,Ei=!(ki!==ci&&ki!==hi||Ri!==fi&&Ri!==ui),mi=Li&&a?d-a:d,t&&d&&yi+wi+xi>mi&&(e?(wi&&Ti(),yi&&Ii()):(Ei||(Ei=ki===li&&Ri==ui),Si||Ei||ki===gi||ki===ci||ki===hi||wi+xi>mi?(wi&&Ti(),yi&&Ii()):yi&&Ii()))," "===vi&&!0!==Li&&yi+wi===0||(ki===gi?(" "===vi&&wi&&Ti(),Oi(vi,xi),Ti()):Si||Ei?(wi&&Ti(),Oi(vi,xi)):Oi(vi,xi)),Ri=ki);wi&&Ti(),yi&&Ii(),Ci.length>0&&(Ci[Ci.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{Ai.paraNumber++,yi=r.measureText(t).width,Ci.push({x:a||0,text:t,width:yi,paraStart:!0}),Wi&&Pi()}))}(h,t,i),l&&function(t,e,i,n,s){if(!n&&i.autoSizeAlign)switch(i.textAlign){case"left":ji(e,"x",t[Ui]);break;case"right":ji(e,"x",-t[Xi])}if(!s&&i.autoSizeAlign)switch(i.verticalAlign){case"top":ji(e,"y",t[Ni]);break;case"bottom":ji(e,"y",-t[Gi])}}(l,h,i,a,o),function(t,e){const{rows:i,bounds:n}=t,{__lineHeight:s,__baseLine:a,__letterSpacing:o,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:h,autoSizeAlign:c}=e;let{x:u,y:f,width:g,height:_}=n,p=s*i.length+(h?h*(t.paraNumber-1):0),w=a;if(r&&p>_)p=Math.max(_,s),t.overflow=i.length;else if(_||c)switch(l){case"middle":f+=(_-p)/2;break;case"bottom":f+=_-p}w+=f;let y,m,v,x=g||c?g:t.maxWidth;for(let a=0,l=i.length;a<l;a++){if(y=i[a],y.x=u,y.width<g||y.width>g&&!r)switch(d){case"center":y.x+=(x-y.width)/2;break;case"right":y.x+=x-y.width}y.paraStart&&h&&a>0&&(w+=h),y.y=w,w+=s,t.overflow>a&&w>p&&(y.isOverflow=!0,t.overflow=a+1),m=y.x,v=y.width,o<0&&(y.width<0?(v=-y.width+e.fontSize+o,m-=v,v+=e.fontSize):v-=o),m<n.x&&(n.x=m),v>n.width&&(n.width=v),r&&g&&g<v&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=f,n.height=p}(h,i),function(t,e,i,n){const{rows:s}=t,{textAlign:a,paraIndent:o,letterSpacing:r}=e;let d,l,h,c,u;s.forEach((t=>{t.words&&(h=o&&t.paraStart?o:0,l=i&&"justify"===a&&t.words.length>1?(i-t.width-h)/(t.words.length-1):0,c=r||t.isOverflow?Di:l>.01?Fi:Yi,t.isOverflow&&!r&&(t.textMode=!0),c===Yi?(t.x+=h,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=h,d=t.x,t.data=[],t.words.forEach((e=>{c===Fi?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,i,n){return t.forEach((t=>{(n||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(h,i,a),h.overflow&&function(t,i,n,s){if(!s)return;const{rows:a,overflow:o}=t;let{textOverflow:r}=i;if(a.splice(o),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?e.canvas.measureText(r).width:0,h=n+s-l;("none"===i.textWrap?a:[a[o-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let n=i;n>-1&&(t=e.data[n],d=t.x+t.width,!(n===i&&d<h));n--){if(d<h&&" "!==t.char){e.data.splice(n+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(h,i,n,a),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(h,i),h}};const zi={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!F.object)return t;t=F.object(t)}let n=void 0===t.a?1:t.a;i&&(n*=e);const s=t.r+","+t.g+","+t.b;return 1===n?"rgb("+s+")":"rgba("+s+","+n+")"}},{setPoint:Vi,addPoint:qi,toBounds:Qi}=C;const Ji={export(t,i,s){this.running=!0;const a=o.fileType(i),r=i.includes(".");return s=o.getExportOptions(s),function(t){Zi||(Zi=new O);return new Promise((e=>{Zi.add((()=>he(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((d=>new Promise((l=>{const h=t=>{d(t),l(),this.running=!1},{toURL:c}=e,{download:u}=e.origin;if("json"===a)return r&&u(c(JSON.stringify(t.toJSON(s.json)),"text"),i),h({data:!!r||t.toJSON(s.json)});if("svg"===a)return r&&u(c(t.toSVG(),"svg"),i),h({data:!!r||t.toSVG()});const{leafer:f}=t;f?(Ki(t),f.waitViewCompleted((()=>he(this,void 0,void 0,(function*(){let e,a,r=1,d=1;const{worldTransform:l,isLeafer:c,isFrame:u}=t,{slice:g,trim:p,onCanvas:w}=s,y=void 0===s.smooth?f.config.smooth:s.smooth,m=s.contextSettings||f.config.contextSettings,v=s.screenshot||t.isApp,x=c&&v&&void 0===s.fill?t.fill:s.fill,b=o.isOpaqueImage(i)||x,B=new T;if(v)e=!0===v?c?f.canvas.bounds:t.worldRenderBounds:v;else{let i=s.relative||(c?"inner":"local");switch(r=l.scaleX,d=l.scaleY,i){case"inner":B.set(l);break;case"local":B.set(l).divide(t.localTransform),r/=t.scaleX,d/=t.scaleY;break;case"world":r=1,d=1;break;case"page":i=t.leafer;default:B.set(l).divide(t.getTransform(i));const e=i.worldTransform;r/=r/e.scaleX,d/=d/e.scaleY}e=t.getBounds("render",i)}const k={scaleX:1,scaleY:1};S.getScaleData(s.scale,s.size,e,k);let R=s.pixelRatio||1;t.isApp&&(k.scaleX*=R,k.scaleY*=R,R=t.app.pixelRatio);const{x:E,y:L,width:A,height:M}=new _(e).scale(k.scaleX,k.scaleY),W={matrix:B.scale(1/k.scaleX,1/k.scaleY).invert().translate(-E,-L).withScale(1/r*k.scaleX,1/d*k.scaleY)};let C,O=n.canvas({width:Math.round(A),height:Math.round(M),pixelRatio:R,smooth:y,contextSettings:m});if(g&&(C=t,C.__worldOpacity=0,t=f,W.bounds=O.bounds),O.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(O,W),t.fill=e}else t.__render(O,W);if(O.restore(),C&&C.__updateWorldOpacity(),p){a=function(t){const{width:e,height:i}=t.view,{data:n}=t.context.getImageData(0,0,e,i);let s,a,o,r=0;for(let t=0;t<n.length;t+=4)0!==n[t+3]&&(s=r%e,a=(r-s)/e,o?qi(o,s,a):Vi(o={},s,a)),r++;const d=new _;return Qi(o,d),d.scale(1/t.pixelRatio).ceil()}(O);const t=O,{width:e,height:i}=a,s={x:0,y:0,width:e,height:i,pixelRatio:R};O=n.canvas(s),O.copyWorld(t,a,s)}b&&O.fillWorld(O.bounds,x||"#FFFFFF","destination-over"),w&&w(O);const I="canvas"===i?O:yield O.export(i,s);h({data:I,width:O.pixelWidth,height:O.pixelHeight,renderBounds:e,trimBounds:a})}))))):h({data:!1})}))))}};let Zi;function Ki(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Ki(t)))}const $i=t.prototype,tn=w.get("@leafer-ui/export");$i.export=function(t,e){const{quality:i,blob:n}=o.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):n?this.toBlob(t,i):this.toDataURL(t,i)},$i.toBlob=function(t,i){return new Promise((n=>{e.origin.canvasToBolb(this.view,t,i).then((t=>{n(t)})).catch((t=>{tn.error(t),n(null)}))}))},$i.toDataURL=function(t,i){return e.origin.canvasToDataURL(this.view,t,i)},$i.saveAs=function(t,i){return new Promise((n=>{e.origin.canvasSaveAs(this.view,t,i).then((()=>{n(!0)})).catch((t=>{tn.error(t),n(!1)}))}))},Object.assign(G,Hi),Object.assign(F,zi),Object.assign(U,Wt),Object.assign(D,ue),Object.assign(Y,Me),Object.assign(j,Fe),Object.assign(N,Ji),Object.assign(n,{interaction:(t,e,i,n)=>new I(t,e,i,n),hitCanvas:(t,e)=>new H(t,e),hitCanvasManager:()=>new P}),V();export{rt as Layouter,H as LeaferCanvas,lt as Renderer,yt as Selector,Q as Watcher,V as useCanvas};
|
|
1
|
+
import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,Creator as n,LeaferImage as s,defineKey as a,FileHelper as o,LeafList as r,DataHelper as d,RenderEvent as l,ChildEvent as h,WatchEvent as c,PropertyEvent as u,LeafHelper as f,BranchHelper as _,Bounds as g,LeafBoundsHelper as p,Debug as w,LeafLevelList as y,LayoutEvent as m,Run as v,ImageManager as x,ResizeEvent as b,BoundsHelper as B,Plugin as k,MatrixHelper as R,MathHelper as E,AlignHelper as S,ImageEvent as L,AroundHelper as A,PointHelper as W,Direction4 as O}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionBase as T,HitCanvasManager as C}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as M,ColorConvert as P,PaintGradient as D,Export as I,Group as F,TextConvert as Y,Paint as G,Effect as z}from"@leafer-ui/draw";class H extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i),this.clientBounds=this.bounds}}i(OffscreenCanvasRenderingContext2D.prototype),i(Path2D.prototype);const{mineType:U}=o;function X(t,i){e.origin={createCanvas:(t,e)=>new OffscreenCanvas(t,e),canvasToDataURL:(t,e,i)=>new Promise(((n,s)=>{t.convertToBlob({type:U(e),quality:i}).then((t=>{var e=new FileReader;e.onload=t=>n(t.target.result),e.onerror=t=>s(t),e.readAsDataURL(t)})).catch((t=>{s(t)}))})),canvasToBolb:(t,e,i)=>t.convertToBlob({type:U(e),quality:i}),canvasSaveAs:(t,e,i)=>new Promise((t=>t())),download(t,e){},loadImage:t=>new Promise(((i,n)=>{let s=new XMLHttpRequest;s.open("GET",e.image.getRealURL(t),!0),s.responseType="blob",s.onload=()=>{createImageBitmap(s.response).then((t=>{i(t)})).catch((t=>{n(t)}))},s.onerror=t=>n(t),s.send()}))},e.canvas=n.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient}Object.assign(n,{canvas:(t,e)=>new H(t,e),image:t=>new s(t)}),e.name="web",e.isWorker=!0,e.backgrounder=!0,e.requestRender=function(t){requestAnimationFrame(t)},a(e,"devicePixelRatio",{get:()=>1});const{userAgent:N}=navigator;N.indexOf("Firefox")>-1?(e.conicGradientRotate90=!0,e.intWheelDeltaY=!0):N.indexOf("Safari")>-1&&-1===N.indexOf("Chrome")&&(e.fullImageShadow=!0),N.indexOf("Windows")>-1?(e.os="Windows",e.intWheelDeltaY=!0):N.indexOf("Mac")>-1?e.os="Mac":N.indexOf("Linux")>-1&&(e.os="Linux");class j{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new r;return this.__updatedList.list.forEach((e=>{e.leafer&&t.add(e)})),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new r,this.target=t,e&&(this.config=d.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(l.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===h.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new c(c.DATA,{updatedList:this.updatedList})),this.__updatedList=new r,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.CHANGE,this.__onAttrChange,this),t.on_([h.ADD,h.REMOVE],this.__onChildEvent,this),t.on_(c.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:q,updateBounds:V,updateAllWorldOpacity:Q}=f,{pushAllChildBranch:Z,pushAllParent:$}=_;const{worldBounds:J}=p,K={x:0,y:0,width:1e5,height:1e5};class tt{constructor(t){this.updatedBounds=new g,this.beforeBounds=new g,this.afterBounds=new g,t instanceof Array&&(t=new r(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,J)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(K):this.afterBounds.setListWithFn(t,J),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:et,updateAllChange:it}=f,nt=w.get("Layouter");class st{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,this.target=t,e&&(this.config=d.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(m.START),this.layoutOnce(),t.emitEvent(new m(m.END,this.layoutedBlocks,this.times))}catch(t){nt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?nt.warn("layouting"):this.times>3?nt.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(c.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=v.start("PartLayout"),{target:i,__updatedList:n}=this,{BEFORE:s,LAYOUT:a,AFTER:o}=m,r=this.getBlocks(n);r.forEach((t=>t.setBefore())),i.emitEvent(new m(s,r,this.times)),this.extraBlock=null,n.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(q(t,!0),e.add(t),t.isBranch&&Z(t,e),$(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),$(t,e)))}))}(n,this.__levelList),function(t){let e,i,n;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(i=e[t],i.isBranch&&i.__tempNumber){n=i.children;for(let t=0,e=n.length;t<e;t++)n[t].isBranch||V(n[t])}V(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&Q(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(n),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new m(a,r,this.times)),i.emitEvent(new m(o,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,v.end(e)}fullLayout(){const t=v.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:n,AFTER:s}=m,a=this.getBlocks(new r(e));e.emitEvent(new m(i,a,this.times)),st.fullLayout(e),a.forEach((t=>{t.setAfter()})),e.emitEvent(new m(n,a,this.times)),e.emitEvent(new m(s,a,this.times)),this.addBlocks(a),v.end(t)}static fullLayout(t){et(t,!0),t.isBranch?_.updateBounds(t):f.updateBounds(t),it(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new tt([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new tt(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(m.REQUEST,this.layout,this),t.on_(m.AGAIN,this.layoutAgain,this),t.on_(c.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const at=w.get("Renderer");class ot{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=d.default(i,this.config)),this.__listenEvents()}start(){this.running=!0,this.update(!1)}stop(){this.running=!1}update(t=!0){this.changed||(this.changed=t),this.__requestRender()}requestLayout(){this.target.emit(m.REQUEST)}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new g,at.log(e.innerName,"---\x3e");try{e.isApp||e.app.emit(l.CHILD_START,e),this.emitRender(l.START),this.renderOnce(t),this.emitRender(l.END,this.totalBounds),x.clearRecycled()}catch(t){this.rendering=!1,at.error(t)}at.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return at.warn("rendering");if(this.times>3)return at.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new g,this.renderOptions={},t)this.emitRender(l.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(l.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(l.RENDER,this.renderBounds,this.renderOptions),this.emitRender(l.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return at.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=v.start("PartRender"),{canvas:i}=this,n=t.getIntersect(i.bounds),s=t.includes(this.target.__world),a=new g(n);i.save(),s&&!w.showRepaint?i.clear():(n.spread(10+1/this.canvas.pixelRatio).ceil(),i.clearWorld(n,!0),i.clipWorld(n,!0)),this.__render(n,s,a),i.restore(),v.end(e)}fullRender(){const t=v.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),v.end(t)}__render(t,e,i){const n=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),w.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,n),this.renderBounds=i=i||t,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=i:this.totalBounds.add(i),w.showHitView&&this.renderHitView(n),w.showBoundsView&&this.renderBoundsView(n),this.canvas.updateRender(i)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new g;e.setList(t),t.length=0,t.push(e)}}__requestRender(){if(this.requestTime)return;const t=this.requestTime=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.requestTime=0,this.running&&(this.changed&&this.canvas.view&&this.render(),this.target.emit(l.NEXT))}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new g(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new g(0,0,1,1)),this.update()}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||at.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new l(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(l.REQUEST,this.update,this),t.on_(m.END,this.__onLayoutEnd,this),t.on_(l.AGAIN,this.renderAgain,this),t.on_(b.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}const{hitRadiusPoint:rt}=B;class dt{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const n=i.through||!1,s=i.ignoreHittable||!1,a=i.target||this.target;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=new r(i.findList),i.findList||this.hitBranch(a);const{list:o}=this.findList,d=this.getBestMatchLeaf(o,i.bottomList,s),l=s?this.getPath(d):this.getHitablePath(d);return this.clear(),n?{path:l,target:d,throughPath:o.length?this.getThroughPath(o):l}:{path:l,target:d}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new r;const{x:n,y:s}=this.point,a={x:n,y:s,radiusX:0,radiusY:0};for(let n=0,s=t.length;n<s;n++)if(e=t[n],(i||f.worldHittable(e))&&(this.hitChild(e,a),this.findList.length))return this.findList.list[0]}if(e)for(let t=0,i=e.length;t<i;t++)if(this.hitChild(e[t].target,this.point,e[t].proxy),this.findList.length)return this.findList.list[0];return t[0]}getPath(t){const e=new r;for(;t;)e.add(t),t=t.parent;return this.target&&e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,n=new r;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(n.addAt(i,0),i.__.hitChildren);t--);return n}getThroughPath(t){const e=new r,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let n,s,a;for(let t=0,o=i.length;t<o;t++){n=i[t],s=i[t+1];for(let t=0,i=n.length;t<i&&(a=n.list[t],!s||!s.has(a));t++)e.add(a)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}eachFind(t,e){let i,n;const{point:s}=this;for(let a=t.length-1;a>-1;a--)i=t[a],!i.__.visible||e&&!i.__.mask||(n=!!i.__.hitRadius||rt(i.__world,s),i.isBranch?(n||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&this.hitChild(i,s)):n&&this.hitChild(i,s))}hitChild(t,e,i){if((!this.exclude||!this.exclude.has(t))&&t.__hitWorld(e)){const{parent:n}=t;if(n&&n.__hasMask&&!t.__.mask&&!n.children.some((t=>t.__.mask&&t.__hitWorld(e))))return;this.findList.add(i||t)}}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}class lt{constructor(t,e){this.config={},e&&(this.config=d.default(e,this.config)),this.picker=new dt(this.target=t,this),this.finder=n.finder&&n.finder()}getByPoint(t,i,n){return e.backgrounder&&this.target&&this.target.updateLayout(),this.picker.getByPoint(t,i,n)}getBy(t,e,i,n){return this.finder?this.finder.getBy(t,e,i,n):k.need("find")}destroy(){this.picker.destroy(),this.finder&&this.finder.destroy()}}function ht(t,e){let i;const{rows:n,decorationY:s,decorationHeight:a}=t.__.__textDrawData;for(let t=0,o=n.length;t<o;t++)i=n[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),s&&e.fillRect(i.x,i.y+s,i.width,a)}function ct(t,e,i){const{strokeAlign:n}=e.__,s="string"!=typeof t;switch(n){case"center":i.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?_t(t,!0,e,i):ft(e,i);break;case"inside":ut("inside",t,s,e,i);break;case"outside":ut("outside",t,s,e,i)}}function ut(t,e,i,n,s){const{__strokeWidth:a,__font:o}=n.__,r=s.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*a,n.__),r.font=o,i?_t(e,!0,n,r):ft(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",ht(n,r),r.blendMode="normal",n.__worldFlipped?s.copyWorldByReset(r,n.__nowWorld):s.copyWorldToInner(r,n.__nowWorld,n.__layout.renderBounds),r.recycle(n.__nowWorld)}function ft(t,e){let i;const{rows:n,decorationY:s,decorationHeight:a}=t.__.__textDrawData;for(let t=0,o=n.length;t<o;t++)i=n[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),s&&e.strokeRect(i.x,i.y+s,i.width,a)}function _t(t,e,i,n){let s;for(let a=0,o=t.length;a<o;a++)s=t[a],s.image&&M.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?ft(i,n):n.stroke(),n.restoreBlendMode()):e?ft(i,n):n.stroke())}function gt(t,e){t.__.dashPattern&&(e.beginPath(),t.__drawPathByData(e,t.__.__pathForArrow),e.dashPattern=null,e.stroke())}Object.assign(n,{watcher:(t,e)=>new j(t,e),layouter:(t,e)=>new st(t,e),renderer:(t,e,i)=>new ot(t,e,i),selector:(t,e)=>new lt(t,e)}),e.layout=st.fullLayout;const{getSpread:pt,getOuterOf:wt,getByMove:yt,getIntersectData:mt}=B;let vt;function xt(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:n}=i.__layout;switch(e.type){case"solid":let{type:s,blendMode:a,color:o,opacity:r}=e;return{type:s,blendMode:a,style:P.string(o,r)};case"image":return M.image(i,t,e,n,!vt||!vt[e.url]);case"linear":return D.linearGradient(e,n);case"radial":return D.radialGradient(e,n);case"angular":return D.conicGradient(e,n);default:return void 0!==e.r?{type:"solid",style:P.string(e)}:void 0}}const bt={compute:function(t,e){const i=e.__,n=[];let s,a=i.__input[t];a instanceof Array||(a=[a]),vt=M.recycleImage(t,i);for(let i,s=0,o=a.length;s<o;s++)i=xt(t,a[s],e),i&&n.push(i);i["_"+t]=n.length?n:void 0,n.length&&n[0].image&&(s=n[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=s:i.__pixelStroke=s},fill:function(t,e,i){i.fillStyle=t,e.__.__font?ht(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let n;const{windingRule:s,__font:a}=e.__;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&M.checkImage(e,i,n,!a)||n.style&&(i.fillStyle=n.style,n.transform?(i.save(),i.transform(n.transform),n.blendMode&&(i.blendMode=n.blendMode),a?ht(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),a?ht(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):a?ht(e,i):s?i.fill(s):i.fill())},fillText:ht,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:a,__font:o}=n;if(s)if(o)ct(t,e,i);else switch(a){case"center":i.setStroke(t,s,n),i.stroke(),n.__useArrow&>(e,i);break;case"inside":i.save(),i.setStroke(t,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const a=i.getSameCanvas(!0,!0);a.setStroke(t,2*s,n),e.__drawRenderPath(a),a.stroke(),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,e.__layout.renderBounds),a.recycle(e.__nowWorld)}},strokes:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:a,__font:o}=n;if(s)if(o)ct(t,e,i);else switch(a){case"center":i.setStroke(void 0,s,n),_t(t,!1,e,i),n.__useArrow&>(e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),_t(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:a}=e.__layout,o=i.getSameCanvas(!0,!0);e.__drawRenderPath(o),o.setStroke(void 0,2*s,n),_t(t,!1,e,o),n.windingRule?o.clip(n.windingRule):o.clip(),o.clearWorld(a),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,a),o.recycle(e.__nowWorld)}},strokeText:ct,drawTextStroke:ft,shape:function(t,e,i){const n=e.getSameCanvas(),s=t.__nowWorld;let a,o,r,d,{scaleX:l,scaleY:h}=s;if(l<0&&(l=-l),h<0&&(h=-h),e.bounds.includes(s))d=n,a=r=s;else{const{renderShapeSpread:n}=t.__layout,c=mt(n?pt(e.bounds,l===h?n*l:[n*h,n*l]):e.bounds,s);o=e.bounds.getFitMatrix(c);let{a:u,d:f}=o;if(o.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,h*=f),r=wt(s,o),a=yt(r,-o.e,-o.f),i.matrix){const{matrix:t}=i;o.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:o.withScale(u,f)})}return t.__renderShape(n,i),{canvas:n,matrix:o,bounds:a,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:h}}};let Bt={};const{get:kt,rotateOfOuter:Rt,translate:Et,scaleOfOuter:St,scale:Lt,rotate:At}=R;function Wt(t,e,i,n,s,a,o){const r=kt();Et(r,e.x+i,e.y+n),Lt(r,s,a),o&&Rt(r,{x:e.x+e.width/2,y:e.y+e.height/2},o),t.transform=r}function Ot(t,e,i,n,s,a,o){const r=kt();Et(r,e.x+i,e.y+n),s&&Lt(r,s,a),o&&At(r,o),t.transform=r}function Tt(t,e,i,n,s,a,o,r,d,l){const h=kt();if(d)if("center"===l)Rt(h,{x:i/2,y:n/2},d);else switch(At(h,d),d){case 90:Et(h,n,0);break;case 180:Et(h,i,n);break;case 270:Et(h,0,i)}Bt.x=e.x+s,Bt.y=e.y+a,Et(h,Bt.x,Bt.y),o&&St(h,Bt,o,r),t.transform=h}const{get:Ct,translate:Mt}=R,Pt=new g,Dt={},It={};function Ft(t,e,i,n){const{blendMode:s,sync:a}=i;s&&(t.blendMode=s),a&&(t.sync=a),t.data=Yt(i,n,e)}function Yt(t,e,i){let{width:n,height:s}=i;t.padding&&(e=Pt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:a,mode:o,align:r,offset:d,scale:l,size:h,rotation:c,repeat:u}=t,f=e.width===n&&e.height===s,_={mode:o},g="center"!==r&&(c||0)%180==90,p=g?s:n,w=g?n:s;let y,m,v=0,x=0;if(o&&"cover"!==o&&"fit"!==o)(l||h)&&(E.getScaleData(l,h,i,It),y=It.scaleX,m=It.scaleY);else if(!f||c){const t=e.width/p,i=e.height/w;y=m="fit"===o?Math.min(t,i):Math.max(t,i),v+=(e.width-n*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:p,height:w};y&&(t.width*=y,t.height*=m),S.toPoint(r,t,e,Dt,!0),v+=Dt.x,x+=Dt.y}switch(d&&(v+=d.x,x+=d.y),o){case"stretch":f||(n=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||c)&&Ot(_,e,v,x,y,m,c);break;case"repeat":(!f||y||c)&&Tt(_,e,n,s,v,x,y,m,c,r),u||(_.repeat="repeat");break;default:y&&Wt(_,e,v,x,y,m,c)}return _.transform||(e.x||e.y)&&(_.transform=Ct(),Mt(_.transform,e.x,e.y)),y&&"stretch"!==o&&(_.scaleX=y,_.scaleY=m),_.width=n,_.height=s,a&&(_.opacity=a),u&&(_.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),_}let Gt,zt=new g;const{isSame:Ht}=B;function Ut(t,e,i,n,s,a){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=n.width/e.pixelRatio,e.__naturalHeight=n.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||Ft(s,n,i,a),!0}function Xt(t,e){qt(t,L.LOAD,e)}function Nt(t,e){qt(t,L.LOADED,e)}function jt(t,e,i){e.error=i,t.forceUpdate("surface"),qt(t,L.ERROR,e)}function qt(t,e,i){t.hasEvent(e)&&t.emitEvent(new L(e,i))}function Vt(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:Qt,scale:Zt,copy:$t}=R,{ceil:Jt,abs:Kt}=Math;function te(t,i,n){let{scaleX:s,scaleY:a}=x.patternLocked?t.__world:t.__nowWorld;const o=s+"-"+a+"-"+n;if(i.patternId===o||t.destroyed)return!1;{s=Kt(s),a=Kt(a);const{image:t,data:r}=i;let d,l,{width:h,height:c,scaleX:u,scaleY:f,opacity:_,transform:g,repeat:p}=r;u&&(l=Qt(),$t(l,g),Zt(l,1/u,1/f),s*=u,a*=f),s*=n,a*=n,h*=s,c*=a;const w=h*c;if(!p&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,a/=d,h/=d,c/=d),u&&(s/=u,a/=f),(g||1!==s||1!==a)&&(l||(l=Qt(),g&&$t(l,g)),Zt(l,1/s,1/a));const m=t.getCanvas(Jt(h)||1,Jt(c)||1,_),v=t.getPattern(m,p||e.origin.noRepeat||"no-repeat",l,i);return i.style=v,i.patternId=o,!0}}function ee(t,e,i,n){return new(i||(i=Promise))((function(s,a){function o(t){try{d(n.next(t))}catch(t){a(t)}}function r(t){try{d(n.throw(t))}catch(t){a(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,r)}d((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:ie}=Math;const ne={image:function(t,e,i,n,s){let a,o;const r=x.get(i);return Gt&&i===Gt.paint&&Ht(n,Gt.boxBounds)?a=Gt.leafPaint:(a={type:i.type,image:r},Gt=r.use>1?{leafPaint:a,paint:i,boxBounds:zt.set(n)}:null),(s||r.loading)&&(o={image:r,attrName:e,attrValue:i}),r.ready?(Ut(t,e,i,r,a,n),s&&(Xt(t,o),Nt(t,o))):r.error?s&&jt(t,o,r.error):(s&&(Vt(t,!0),Xt(t,o)),a.loadId=r.load((()=>{Vt(t,!1),t.destroyed||(Ut(t,e,i,r,a,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Nt(t,o)),a.loadId=null}),(e=>{Vt(t,!1),jt(t,o,e),a.loadId=null}))),a},checkImage:function(t,i,n,s){const{scaleX:a,scaleY:o}=x.patternLocked?t.__world:t.__nowWorld,{pixelRatio:r}=i;if(!n.data||n.patternId===a+"-"+o+"-"+r&&!I.running)return!1;{const{data:d}=n;if(s)if(d.repeat)s=!1;else{let{width:t,height:i}=d;t*=ie(a)*r,i*=ie(o)*r,d.scaleX&&(t*=d.scaleX,i*=d.scaleY),s=t*i>e.image.maxCacheSize||I.running}return s?(i.save(),t.windingRule?i.clip(t.windingRule):i.clip(),n.blendMode&&(i.blendMode=n.blendMode),d.opacity&&(i.opacity*=d.opacity),d.transform&&i.transform(d.transform),i.drawImage(n.image.view,0,0,d.width,d.height),i.restore(),!0):(!n.style||n.sync||I.running?te(t,n,r):n.patternTask||(n.patternTask=x.patternTasker.add((()=>ee(this,void 0,void 0,(function*(){n.patternTask=null,i.bounds.hit(t.__nowWorld)&&te(t,n,r),t.forceUpdate("surface")}))),300)),!1)}},createPattern:te,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let n,s,a,o;for(let r=0,d=i.length;r<d;r++)n=i[r].image,o=n&&n.url,o&&(s||(s={}),s[o]=!0,x.recycle(n),n.loading&&(a||(a=e.__input&&e.__input[t]||[],a instanceof Array||(a=[a])),n.unload(i[r].loadId,!a.some((t=>t.url===o)))));return s}return null},createData:Ft,getPatternData:Yt,fillOrFitMode:Wt,clipMode:Ot,repeatMode:Tt},{toPoint:se}=A,ae={},oe={};function re(t,e,i){if(e){let n;for(let s=0,a=e.length;s<a;s++)n=e[s],"string"==typeof n?t.addColorStop(s/(a-1),P.string(n,i)):t.addColorStop(n.offset,P.string(n.color,i))}}const{getAngle:de,getDistance:le}=W,{get:he,rotateOfOuter:ce,scaleOfOuter:ue}=R,{toPoint:fe}=A,_e={},ge={};function pe(t,e,i,n,s){let a;const{width:o,height:r}=t;if(o!==r||n){const t=de(e,i);a=he(),s?(ue(a,e,o/r*(n||1),1),ce(a,e,t+90)):(ue(a,e,1,o/r*(n||1)),ce(a,e,t))}return a}const{getDistance:we}=W,{toPoint:ye}=A,me={},ve={};const xe={linearGradient:function(t,i){let{from:n,to:s,type:a,blendMode:o,opacity:r}=t;se(n||"top",i,ae),se(s||"bottom",i,oe);const d=e.canvas.createLinearGradient(ae.x,ae.y,oe.x,oe.y);re(d,t.stops,r);const l={type:a,style:d};return o&&(l.blendMode=o),l},radialGradient:function(t,i){let{from:n,to:s,type:a,opacity:o,blendMode:r,stretch:d}=t;fe(n||"center",i,_e),fe(s||"bottom",i,ge);const l=e.canvas.createRadialGradient(_e.x,_e.y,0,_e.x,_e.y,le(_e,ge));re(l,t.stops,o);const h={type:a,style:l},c=pe(i,_e,ge,d,!0);return c&&(h.transform=c),r&&(h.blendMode=r),h},conicGradient:function(t,i){let{from:n,to:s,type:a,opacity:o,blendMode:r,stretch:d}=t;ye(n||"center",i,me),ye(s||"bottom",i,ve);const l=e.conicGradientSupport?e.canvas.createConicGradient(0,me.x,me.y):e.canvas.createRadialGradient(me.x,me.y,0,me.x,me.y,we(me,ve));re(l,t.stops,o);const h={type:a,style:l},c=pe(i,me,ve,d||1,e.conicGradientRotate90);return c&&(h.transform=c),r&&(h.blendMode=r),h},getTransform:pe},{copy:be,toOffsetOutBounds:Be}=B,ke={},Re={};function Ee(t,i,n,s){const{bounds:a,shapeBounds:o}=s;if(e.fullImageShadow){if(be(ke,t.bounds),ke.x+=i.x-o.x,ke.y+=i.y-o.y,n){const{matrix:t}=s;ke.x-=(a.x+(t?t.e:0)+a.width/2)*(n-1),ke.y-=(a.y+(t?t.f:0)+a.height/2)*(n-1),ke.width*=n,ke.height*=n}t.copyWorld(s.canvas,t.bounds,ke)}else n&&(be(ke,i),ke.x-=i.width/2*(n-1),ke.y-=i.height/2*(n-1),ke.width*=n,ke.height*=n),t.copyWorld(s.canvas,o,n?ke:i)}const{toOffsetOutBounds:Se}=B,Le={};const Ae={shadow:function(t,e,i){let n,s;const{__nowWorld:a,__layout:o}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),_=r.length-1;Be(l,Re),r.forEach(((r,g)=>{f.setWorldShadow(Re.offsetX+r.x*c,Re.offsetY+r.y*u,r.blur*c,r.color),s=r.spread?1+2*r.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0)):0,Ee(f,Re,s,i),n=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,a,"copy"),n=a),d?f.copyWorld(d,a,a,"destination-out"):f.copyWorld(i.canvas,h,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,n,a,r.blendMode):e.copyWorldToInner(f,n,o.renderBounds,r.blendMode),_&&g<_&&f.clearWorld(n,!0)})),f.recycle(n)},innerShadow:function(t,e,i){let n,s;const{__nowWorld:a,__layout:o}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),_=r.length-1;Se(l,Le),r.forEach(((r,g)=>{f.save(),f.setWorldShadow(Le.offsetX+r.x*c,Le.offsetY+r.y*u,r.blur*c),s=r.spread?1-2*r.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0)):0,Ee(f,Le,s,i),f.restore(),d?(f.copyWorld(f,l,a,"copy"),f.copyWorld(d,a,a,"source-out"),n=a):(f.copyWorld(i.canvas,h,l,"source-out"),n=l),f.fillWorld(n,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,n,a,r.blendMode):e.copyWorldToInner(f,n,o.renderBounds,r.blendMode),_&&g<_&&f.clearWorld(n,!0)})),f.recycle(n)},blur:function(t,e,i){const{blur:n}=t.__;i.setWorldBlur(n*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:We}=p;function Oe(t,e,i,n,s,a){switch(e){case"grayscale":s.useGrayscaleAlpha(t.__nowWorld);case"alpha":!function(t,e,i,n){const s=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(n,s),n.recycle(s),Ce(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Ce(t,i,n,a);break;case"path":i.restore()}}function Te(t){return t.getSameCanvas(!1,!0)}function Ce(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}F.prototype.__renderMask=function(t,e){let i,n,s,a,o,r;const{children:d}=this;for(let l=0,h=d.length;l<h;l++)i=d[l],r=i.__.mask,r&&(o&&(Oe(this,o,t,s,n,a),n=s=null),"path"===r||"clipping-path"===r?(i.opacity<1?(o="opacity-path",a=i.opacity,s||(s=Te(t))):(o="path",t.save()),i.__clip(s||t,e)):(o="grayscale"===r?"grayscale":"alpha",n||(n=Te(t)),s||(s=Te(t)),i.__render(n,e)),"clipping"!==r&&"clipping-path"!==r)||We(i,e)||i.__render(s||t,e);Oe(this,o,t,s,n,a)};const Me=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Pe=Me+"_#~&*+\\=|≮≯≈≠=…",De=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function Ie(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Fe=Ie("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ye=Ie("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Ge=Ie(Me),ze=Ie(Pe),He=Ie("- —/~|┆·");var Ue;!function(t){t[t.Letter=0]="Letter",t[t.Single=1]="Single",t[t.Before=2]="Before",t[t.After=3]="After",t[t.Symbol=4]="Symbol",t[t.Break=5]="Break"}(Ue||(Ue={}));const{Letter:Xe,Single:Ne,Before:je,After:qe,Symbol:Ve,Break:Qe}=Ue;function Ze(t){return Fe[t]?Xe:He[t]?Qe:Ye[t]?je:Ge[t]?qe:ze[t]?Ve:De.test(t)?Ne:Xe}const $e={trimRight(t){const{words:e}=t;let i,n=0,s=e.length;for(let a=s-1;a>-1&&(i=e[a].data[0]," "===i.char);a--)n++,t.width-=i.width;n&&e.splice(s-n,n)}};function Je(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:Ke}=$e,{Letter:ti,Single:ei,Before:ii,After:ni,Symbol:si,Break:ai}=Ue;let oi,ri,di,li,hi,ci,ui,fi,_i,gi,pi,wi,yi,mi,vi,xi,bi,Bi=[];function ki(t,e){_i&&!fi&&(fi=_i),oi.data.push({char:t,width:e}),di+=e}function Ri(){li+=di,oi.width=di,ri.words.push(oi),oi={data:[]},di=0}function Ei(){mi&&(vi.paraNumber++,ri.paraStart=!0,mi=!1),_i&&(ri.startCharSize=fi,ri.endCharSize=_i,fi=0),ri.width=li,xi.width?Ke(ri):bi&&Si(),Bi.push(ri),ri={words:[]},li=0}function Si(){li>(vi.maxWidth||0)&&(vi.maxWidth=li)}const Li=0,Ai=1,Wi=2;const{top:Oi,right:Ti,bottom:Ci,left:Mi}=O;function Pi(t,e,i){const{bounds:n,rows:s}=t;n[e]+=i;for(let t=0;t<s.length;t++)s[t][e]+=i}const Di={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let n=0,s=0,a=i.__getInput("width")||0,o=i.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=i;l&&(a?(n=l[Mi],a-=l[Ti]+l[Mi]):i.autoSizeAlign||(n=l[Mi]),o?(s=l[Oi],o-=l[Oi]+l[Ci]):i.autoSizeAlign||(s=l[Oi]));const h={bounds:{x:n,y:s,width:a,height:o},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,i,n){vi=t,Bi=t.rows,xi=t.bounds,bi=!xi.width&&!n.autoSizeAlign;const{__letterSpacing:s,paraIndent:a,textCase:o}=n,{canvas:r}=e,{width:d,height:l}=xi;if(d||l||s||"none"!==o){const t="none"!==n.textWrap,e="break"===n.textWrap;mi=!0,pi=null,fi=ui=_i=di=li=0,oi={data:[]},ri={words:[]};for(let n=0,l=i.length;n<l;n++)ci=i[n],"\n"===ci?(di&&Ri(),ri.paraEnd=!0,Ei(),mi=!0):(gi=Ze(ci),gi===ti&&"none"!==o&&(ci=Je(ci,o,!di)),ui=r.measureText(ci).width,s&&(s<0&&(_i=ui),ui+=s),wi=gi===ei&&(pi===ei||pi===ti)||pi===ei&&gi!==ni,yi=!(gi!==ii&&gi!==ei||pi!==si&&pi!==ni),hi=mi&&a?d-a:d,t&&d&&li+di+ui>hi&&(e?(di&&Ri(),li&&Ei()):(yi||(yi=gi===ti&&pi==ni),wi||yi||gi===ai||gi===ii||gi===ei||di+ui>hi?(di&&Ri(),li&&Ei()):li&&Ei()))," "===ci&&!0!==mi&&li+di===0||(gi===ai?(" "===ci&&di&&Ri(),ki(ci,ui),Ri()):wi||yi?(di&&Ri(),ki(ci,ui)):ki(ci,ui)),pi=gi);di&&Ri(),li&&Ei(),Bi.length>0&&(Bi[Bi.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{vi.paraNumber++,li=r.measureText(t).width,Bi.push({x:a||0,text:t,width:li,paraStart:!0}),bi&&Si()}))}(h,t,i),l&&function(t,e,i,n,s){if(!n&&i.autoSizeAlign)switch(i.textAlign){case"left":Pi(e,"x",t[Mi]);break;case"right":Pi(e,"x",-t[Ti])}if(!s&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Pi(e,"y",t[Oi]);break;case"bottom":Pi(e,"y",-t[Ci])}}(l,h,i,a,o),function(t,e){const{rows:i,bounds:n}=t,{__lineHeight:s,__baseLine:a,__letterSpacing:o,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:h,autoSizeAlign:c}=e;let{x:u,y:f,width:_,height:g}=n,p=s*i.length+(h?h*(t.paraNumber-1):0),w=a;if(r&&p>g)p=Math.max(g,s),t.overflow=i.length;else if(g||c)switch(l){case"middle":f+=(g-p)/2;break;case"bottom":f+=g-p}w+=f;let y,m,v,x=_||c?_:t.maxWidth;for(let a=0,l=i.length;a<l;a++){if(y=i[a],y.x=u,y.width<_||y.width>_&&!r)switch(d){case"center":y.x+=(x-y.width)/2;break;case"right":y.x+=x-y.width}y.paraStart&&h&&a>0&&(w+=h),y.y=w,w+=s,t.overflow>a&&w>p&&(y.isOverflow=!0,t.overflow=a+1),m=y.x,v=y.width,o<0&&(y.width<0?(v=-y.width+e.fontSize+o,m-=v,v+=e.fontSize):v-=o),m<n.x&&(n.x=m),v>n.width&&(n.width=v),r&&_&&_<v&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=f,n.height=p}(h,i),function(t,e,i,n){const{rows:s}=t,{textAlign:a,paraIndent:o,letterSpacing:r}=e;let d,l,h,c,u;s.forEach((t=>{t.words&&(h=o&&t.paraStart?o:0,l=i&&"justify"===a&&t.words.length>1?(i-t.width-h)/(t.words.length-1):0,c=r||t.isOverflow?Li:l>.01?Ai:Wi,t.isOverflow&&!r&&(t.textMode=!0),c===Wi?(t.x+=h,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=h,d=t.x,t.data=[],t.words.forEach((e=>{c===Ai?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,i,n){return t.forEach((t=>{(n||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(h,i,a),h.overflow&&function(t,i,n,s){if(!s)return;const{rows:a,overflow:o}=t;let{textOverflow:r}=i;if(a.splice(o),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?e.canvas.measureText(r).width:0,h=n+s-l;("none"===i.textWrap?a:[a[o-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let n=i;n>-1&&(t=e.data[n],d=t.x+t.width,!(n===i&&d<h));n--){if(d<h&&" "!==t.char){e.data.splice(n+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(h,i,n,a),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(h,i),h}};const Ii={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!P.object)return t;t=P.object(t)}let n=void 0===t.a?1:t.a;i&&(n*=e);const s=t.r+","+t.g+","+t.b;return 1===n?"rgb("+s+")":"rgba("+s+","+n+")"}};Object.assign(Y,Di),Object.assign(P,Ii),Object.assign(G,bt),Object.assign(M,ne),Object.assign(D,xe),Object.assign(z,Ae),Object.assign(n,{interaction:(t,e,i,n)=>new T(t,e,i,n),hitCanvas:(t,e)=>new H(t,e),hitCanvasManager:()=>new C}),X();export{st as Layouter,H as LeaferCanvas,dt as Picker,ot as Renderer,lt as Selector,j as Watcher,X as useCanvas};
|