@leafer-draw/worker 1.0.0-rc.27 → 1.0.0-rc.30
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.esm.js +27 -15
- package/dist/worker.esm.min.js +1 -1
- package/dist/worker.js +71 -46
- package/dist/worker.min.js +1 -1
- package/dist/worker.module.js +71 -46
- package/dist/worker.module.min.js +1 -1
- package/package.json +6 -6
package/dist/worker.module.js
CHANGED
|
@@ -11,8 +11,15 @@ const Platform = {
|
|
|
11
11
|
hitCanvasSize: 100,
|
|
12
12
|
maxCacheSize: 2560 * 1600,
|
|
13
13
|
maxPatternSize: 4096 * 2160,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
crossOrigin: 'anonymous',
|
|
15
|
+
getRealURL(url) {
|
|
16
|
+
const { prefix, suffix } = Platform.image;
|
|
17
|
+
if (suffix && !url.startsWith('data:') && !url.startsWith('blob:'))
|
|
18
|
+
url += (url.includes("?") ? "&" : "?") + suffix;
|
|
19
|
+
if (prefix && url[0] === '/')
|
|
20
|
+
url = prefix + url;
|
|
21
|
+
return url;
|
|
22
|
+
}
|
|
16
23
|
}
|
|
17
24
|
};
|
|
18
25
|
|
|
@@ -1548,7 +1555,7 @@ class LeafData {
|
|
|
1548
1555
|
if (this.__input && this.__input[name] !== undefined)
|
|
1549
1556
|
this.__input[name] = undefined;
|
|
1550
1557
|
}
|
|
1551
|
-
__getInputData(names) {
|
|
1558
|
+
__getInputData(names, options) {
|
|
1552
1559
|
const data = {};
|
|
1553
1560
|
if (names) {
|
|
1554
1561
|
if (names instanceof Array) {
|
|
@@ -1575,6 +1582,12 @@ class LeafData {
|
|
|
1575
1582
|
}
|
|
1576
1583
|
}
|
|
1577
1584
|
}
|
|
1585
|
+
if (options) {
|
|
1586
|
+
if (options.matrix) {
|
|
1587
|
+
const { a, b, c, d, e, f } = this.__leaf.__localMatrix;
|
|
1588
|
+
data.matrix = { a, b, c, d, e, f };
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1578
1591
|
return data;
|
|
1579
1592
|
}
|
|
1580
1593
|
__setMiddle(name, value) {
|
|
@@ -5126,6 +5139,7 @@ let Leaf = class Leaf {
|
|
|
5126
5139
|
get __worldFlipped() { return this.__world.scaleX < 0 || this.__world.scaleY < 0; }
|
|
5127
5140
|
get __onlyHitMask() { return this.__hasMask && !this.__.hitChildren; }
|
|
5128
5141
|
get __ignoreHitWorld() { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren; }
|
|
5142
|
+
get __inLazyBounds() { const { leafer } = this; return leafer && leafer.created && leafer.lazyBounds.hit(this.__world); }
|
|
5129
5143
|
get pathInputed() { return this.__.__pathInputed; }
|
|
5130
5144
|
constructor(data) {
|
|
5131
5145
|
this.innerId = create(LEAF);
|
|
@@ -5192,11 +5206,13 @@ let Leaf = class Leaf {
|
|
|
5192
5206
|
setAttr(name, value) { this[name] = value; }
|
|
5193
5207
|
getAttr(name) { return this[name]; }
|
|
5194
5208
|
getComputedAttr(name) { return this.__[name]; }
|
|
5195
|
-
toJSON() {
|
|
5196
|
-
|
|
5209
|
+
toJSON(options) {
|
|
5210
|
+
if (options)
|
|
5211
|
+
this.__layout.update();
|
|
5212
|
+
return this.__.__getInputData(null, options);
|
|
5197
5213
|
}
|
|
5198
|
-
toString() {
|
|
5199
|
-
return JSON.stringify(this.toJSON());
|
|
5214
|
+
toString(options) {
|
|
5215
|
+
return JSON.stringify(this.toJSON(options));
|
|
5200
5216
|
}
|
|
5201
5217
|
toSVG() { return undefined; }
|
|
5202
5218
|
__SVG(_data) { }
|
|
@@ -5210,6 +5226,9 @@ let Leaf = class Leaf {
|
|
|
5210
5226
|
findOne(_condition, _options) { return undefined; }
|
|
5211
5227
|
findId(_id) { return undefined; }
|
|
5212
5228
|
focus(_value) { }
|
|
5229
|
+
updateLayout() {
|
|
5230
|
+
this.__layout.update();
|
|
5231
|
+
}
|
|
5213
5232
|
forceUpdate(attrName) {
|
|
5214
5233
|
if (attrName === undefined)
|
|
5215
5234
|
attrName = 'width';
|
|
@@ -5219,8 +5238,8 @@ let Leaf = class Leaf {
|
|
|
5219
5238
|
this.__[attrName] = value === undefined ? null : undefined;
|
|
5220
5239
|
this[attrName] = value;
|
|
5221
5240
|
}
|
|
5222
|
-
|
|
5223
|
-
this.
|
|
5241
|
+
forceRender(_bounds) {
|
|
5242
|
+
this.forceUpdate('surface');
|
|
5224
5243
|
}
|
|
5225
5244
|
__updateWorldMatrix() { }
|
|
5226
5245
|
__updateLocalMatrix() { }
|
|
@@ -5266,14 +5285,6 @@ let Leaf = class Leaf {
|
|
|
5266
5285
|
return this.__world;
|
|
5267
5286
|
}
|
|
5268
5287
|
}
|
|
5269
|
-
getWorld(attrName) {
|
|
5270
|
-
this.__layout.update();
|
|
5271
|
-
if (attrName === 'x')
|
|
5272
|
-
return this.__world.e;
|
|
5273
|
-
if (attrName === 'y')
|
|
5274
|
-
return this.__world.f;
|
|
5275
|
-
return this.getLayoutBounds()[attrName];
|
|
5276
|
-
}
|
|
5277
5288
|
getTransform(relative) {
|
|
5278
5289
|
return this.__layout.getTransform(relative || 'local');
|
|
5279
5290
|
}
|
|
@@ -5394,14 +5405,8 @@ let Leaf = class Leaf {
|
|
|
5394
5405
|
this.scaleY *= scaleY;
|
|
5395
5406
|
}
|
|
5396
5407
|
__scaleResize(_scaleX, _scaleY) { }
|
|
5397
|
-
resizeWidth(
|
|
5398
|
-
|
|
5399
|
-
this.scaleResize(scale, this.__.lockRatio ? scale : 1);
|
|
5400
|
-
}
|
|
5401
|
-
resizeHeight(height) {
|
|
5402
|
-
const scale = height / this.__localBoxBounds.height;
|
|
5403
|
-
this.scaleResize(this.__.lockRatio ? scale : 1, scale);
|
|
5404
|
-
}
|
|
5408
|
+
resizeWidth(_width) { }
|
|
5409
|
+
resizeHeight(_height) { }
|
|
5405
5410
|
__hitWorld(_point) { return true; }
|
|
5406
5411
|
__hit(_local) { return true; }
|
|
5407
5412
|
__hitFill(_inner) { return true; }
|
|
@@ -5752,7 +5757,7 @@ class LeafLevelList {
|
|
|
5752
5757
|
}
|
|
5753
5758
|
}
|
|
5754
5759
|
|
|
5755
|
-
const version = "1.0.0-rc.
|
|
5760
|
+
const version = "1.0.0-rc.30";
|
|
5756
5761
|
const inviteCode = {};
|
|
5757
5762
|
|
|
5758
5763
|
class LeaferCanvas extends LeaferCanvasBase {
|
|
@@ -5801,10 +5806,8 @@ function useCanvas(_canvasType, _power) {
|
|
|
5801
5806
|
download(_url, _filename) { return undefined; },
|
|
5802
5807
|
loadImage(src) {
|
|
5803
5808
|
return new Promise((resolve, reject) => {
|
|
5804
|
-
if (!src.startsWith('data:') && Platform.image.suffix)
|
|
5805
|
-
src += (src.includes("?") ? "&" : "?") + Platform.image.suffix;
|
|
5806
5809
|
let req = new XMLHttpRequest();
|
|
5807
|
-
req.open('GET', src, true);
|
|
5810
|
+
req.open('GET', Platform.image.getRealURL(src), true);
|
|
5808
5811
|
req.responseType = "blob";
|
|
5809
5812
|
req.onload = () => {
|
|
5810
5813
|
createImageBitmap(req.response).then(img => {
|
|
@@ -6937,7 +6940,7 @@ let UI = UI_1 = class UI extends Leaf {
|
|
|
6937
6940
|
__onUpdateSize() {
|
|
6938
6941
|
if (this.__.__input) {
|
|
6939
6942
|
const data = this.__;
|
|
6940
|
-
(data.lazy && this.
|
|
6943
|
+
(data.lazy && !this.__inLazyBounds && !Export.running) ? data.__needComputePaint = true : data.__computePaint();
|
|
6941
6944
|
}
|
|
6942
6945
|
}
|
|
6943
6946
|
__updateRenderPath() {
|
|
@@ -7294,9 +7297,9 @@ let Group = class Group extends UI {
|
|
|
7294
7297
|
super.set(data);
|
|
7295
7298
|
}
|
|
7296
7299
|
}
|
|
7297
|
-
toJSON() {
|
|
7298
|
-
const data = super.toJSON();
|
|
7299
|
-
data.children = this.children.map(child => child.toJSON());
|
|
7300
|
+
toJSON(options) {
|
|
7301
|
+
const data = super.toJSON(options);
|
|
7302
|
+
data.children = this.children.map(child => child.toJSON(options));
|
|
7300
7303
|
return data;
|
|
7301
7304
|
}
|
|
7302
7305
|
pick(_hitPoint, _options) { return undefined; }
|
|
@@ -7463,6 +7466,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
|
|
|
7463
7466
|
__onResize(event) {
|
|
7464
7467
|
this.emitEvent(event);
|
|
7465
7468
|
DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
|
|
7469
|
+
if (!event.width || !event.height)
|
|
7470
|
+
debug$1.warn('w = 0 or h = 0');
|
|
7466
7471
|
setTimeout(() => { if (this.canvasManager)
|
|
7467
7472
|
this.canvasManager.clearRecycled(); }, 0);
|
|
7468
7473
|
}
|
|
@@ -7486,6 +7491,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
|
|
|
7486
7491
|
__setAttr(attrName, newValue) {
|
|
7487
7492
|
if (this.canvas) {
|
|
7488
7493
|
if (canvasSizeAttrs.includes(attrName)) {
|
|
7494
|
+
if (!newValue)
|
|
7495
|
+
debug$1.warn(attrName + ' is 0');
|
|
7489
7496
|
this.__changeCanvasSize(attrName, newValue);
|
|
7490
7497
|
}
|
|
7491
7498
|
else if (attrName === 'fill') {
|
|
@@ -7495,6 +7502,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
|
|
|
7495
7502
|
if (!this.parent)
|
|
7496
7503
|
this.canvas.hittable = newValue;
|
|
7497
7504
|
}
|
|
7505
|
+
else if (attrName === 'zIndex') {
|
|
7506
|
+
this.canvas.zIndex = newValue;
|
|
7507
|
+
setTimeout(() => this.parent && this.parent.__updateSortChildren());
|
|
7508
|
+
}
|
|
7498
7509
|
}
|
|
7499
7510
|
return super.__setAttr(attrName, newValue);
|
|
7500
7511
|
}
|
|
@@ -8113,7 +8124,7 @@ let Canvas = class Canvas extends Rect {
|
|
|
8113
8124
|
__drawAfterFill(canvas, _options) {
|
|
8114
8125
|
const origin = this.canvas.view;
|
|
8115
8126
|
const { width, height } = this;
|
|
8116
|
-
if (this.__.cornerRadius) {
|
|
8127
|
+
if (this.__.cornerRadius || this.pathInputed) {
|
|
8117
8128
|
canvas.save();
|
|
8118
8129
|
canvas.clip();
|
|
8119
8130
|
canvas.drawImage(this.canvas.view, 0, 0, origin.width, origin.height, 0, 0, width, height);
|
|
@@ -8994,7 +9005,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
8994
9005
|
width *= data.scaleX;
|
|
8995
9006
|
height *= data.scaleY;
|
|
8996
9007
|
}
|
|
8997
|
-
allowPaint = width * height > Platform.image.maxCacheSize;
|
|
9008
|
+
allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
|
|
8998
9009
|
}
|
|
8999
9010
|
else {
|
|
9000
9011
|
allowPaint = false;
|
|
@@ -9506,7 +9517,8 @@ function createRows(drawData, content, style) {
|
|
|
9506
9517
|
if (breakAll) {
|
|
9507
9518
|
if (wordWidth)
|
|
9508
9519
|
addWord();
|
|
9509
|
-
|
|
9520
|
+
if (rowWidth)
|
|
9521
|
+
addRow();
|
|
9510
9522
|
}
|
|
9511
9523
|
else {
|
|
9512
9524
|
if (!afterBreak)
|
|
@@ -9514,10 +9526,12 @@ function createRows(drawData, content, style) {
|
|
|
9514
9526
|
if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
|
|
9515
9527
|
if (wordWidth)
|
|
9516
9528
|
addWord();
|
|
9517
|
-
|
|
9529
|
+
if (rowWidth)
|
|
9530
|
+
addRow();
|
|
9518
9531
|
}
|
|
9519
9532
|
else {
|
|
9520
|
-
|
|
9533
|
+
if (rowWidth)
|
|
9534
|
+
addRow();
|
|
9521
9535
|
}
|
|
9522
9536
|
}
|
|
9523
9537
|
}
|
|
@@ -9720,7 +9734,9 @@ function layoutText(drawData, style) {
|
|
|
9720
9734
|
bounds.height = realHeight;
|
|
9721
9735
|
}
|
|
9722
9736
|
|
|
9723
|
-
function clipText(drawData, style) {
|
|
9737
|
+
function clipText(drawData, style, x, width) {
|
|
9738
|
+
if (!width)
|
|
9739
|
+
return;
|
|
9724
9740
|
const { rows, overflow } = drawData;
|
|
9725
9741
|
let { textOverflow } = style;
|
|
9726
9742
|
rows.splice(overflow);
|
|
@@ -9731,7 +9747,7 @@ function clipText(drawData, style) {
|
|
|
9731
9747
|
textOverflow = '...';
|
|
9732
9748
|
let char, charRight;
|
|
9733
9749
|
const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
|
|
9734
|
-
const right =
|
|
9750
|
+
const right = x + width - ellipsisWidth;
|
|
9735
9751
|
const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
|
|
9736
9752
|
list.forEach(row => {
|
|
9737
9753
|
if (row.isOverflow && row.data) {
|
|
@@ -9807,7 +9823,7 @@ function getDrawData(content, style) {
|
|
|
9807
9823
|
layoutText(drawData, style);
|
|
9808
9824
|
layoutChar(drawData, style, width);
|
|
9809
9825
|
if (drawData.overflow)
|
|
9810
|
-
clipText(drawData, style);
|
|
9826
|
+
clipText(drawData, style, x, width);
|
|
9811
9827
|
if (textDecoration !== 'none')
|
|
9812
9828
|
decorationText(drawData, style);
|
|
9813
9829
|
return drawData;
|
|
@@ -9878,6 +9894,8 @@ function getTrimBounds(canvas) {
|
|
|
9878
9894
|
const ExportModule = {
|
|
9879
9895
|
export(leaf, filename, options) {
|
|
9880
9896
|
this.running = true;
|
|
9897
|
+
const fileType = FileHelper.fileType(filename);
|
|
9898
|
+
options = FileHelper.getExportOptions(options);
|
|
9881
9899
|
return addTask((success) => new Promise((resolve) => {
|
|
9882
9900
|
const over = (result) => {
|
|
9883
9901
|
success(result);
|
|
@@ -9886,12 +9904,11 @@ const ExportModule = {
|
|
|
9886
9904
|
};
|
|
9887
9905
|
const { toURL } = Platform;
|
|
9888
9906
|
const { download } = Platform.origin;
|
|
9889
|
-
const fileType = FileHelper.fileType(filename);
|
|
9890
9907
|
if (filename === 'json') {
|
|
9891
|
-
return over({ data: leaf.toJSON() });
|
|
9908
|
+
return over({ data: leaf.toJSON(options.json) });
|
|
9892
9909
|
}
|
|
9893
9910
|
else if (fileType === 'json') {
|
|
9894
|
-
download(toURL(JSON.stringify(leaf.toJSON()), 'text'), filename);
|
|
9911
|
+
download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
9895
9912
|
return over({ data: true });
|
|
9896
9913
|
}
|
|
9897
9914
|
if (filename === 'svg') {
|
|
@@ -9903,13 +9920,15 @@ const ExportModule = {
|
|
|
9903
9920
|
}
|
|
9904
9921
|
const { leafer } = leaf;
|
|
9905
9922
|
if (leafer) {
|
|
9923
|
+
checkLazy(leaf);
|
|
9906
9924
|
leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
|
|
9907
|
-
options = FileHelper.getExportOptions(options);
|
|
9908
9925
|
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
9909
9926
|
const { worldTransform, isLeafer, isFrame } = leaf;
|
|
9910
9927
|
const { slice, trim, onCanvas } = options;
|
|
9911
9928
|
let scale = options.scale || 1;
|
|
9912
9929
|
let pixelRatio = options.pixelRatio || 1;
|
|
9930
|
+
const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
|
|
9931
|
+
const contextSettings = options.contextSettings || leafer.config.contextSettings;
|
|
9913
9932
|
if (leaf.isApp) {
|
|
9914
9933
|
scale *= pixelRatio;
|
|
9915
9934
|
pixelRatio = leaf.app.pixelRatio;
|
|
@@ -9948,7 +9967,7 @@ const ExportModule = {
|
|
|
9948
9967
|
renderBounds = leaf.getBounds('render', relative);
|
|
9949
9968
|
}
|
|
9950
9969
|
const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
|
|
9951
|
-
let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio });
|
|
9970
|
+
let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
|
|
9952
9971
|
const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
|
|
9953
9972
|
if (slice) {
|
|
9954
9973
|
leaf = leafer;
|
|
@@ -9994,6 +10013,12 @@ function addTask(task) {
|
|
|
9994
10013
|
tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
|
|
9995
10014
|
});
|
|
9996
10015
|
}
|
|
10016
|
+
function checkLazy(leaf) {
|
|
10017
|
+
if (leaf.__.__needComputePaint)
|
|
10018
|
+
leaf.__.__computePaint();
|
|
10019
|
+
if (leaf.isBranch)
|
|
10020
|
+
leaf.children.forEach(child => checkLazy(child));
|
|
10021
|
+
}
|
|
9997
10022
|
|
|
9998
10023
|
const canvas = LeaferCanvasBase.prototype;
|
|
9999
10024
|
const debug = Debug.get('@leafer-ui/export');
|