@leafer-draw/worker 1.0.8 → 1.0.10
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 +13 -13
- package/dist/worker.esm.js +13 -13
- package/dist/worker.esm.min.js +1 -1
- package/dist/worker.js +64 -40
- package/dist/worker.min.cjs +1 -1
- package/dist/worker.min.js +1 -1
- package/dist/worker.module.js +64 -40
- package/dist/worker.module.min.js +1 -1
- package/package.json +6 -6
package/dist/worker.module.js
CHANGED
|
@@ -1411,14 +1411,13 @@ const UICreator = {
|
|
|
1411
1411
|
list: {},
|
|
1412
1412
|
register(UI) {
|
|
1413
1413
|
const { __tag: tag } = UI.prototype;
|
|
1414
|
-
if (list$1[tag])
|
|
1414
|
+
if (list$1[tag])
|
|
1415
1415
|
debug$c.repeat(tag);
|
|
1416
|
-
|
|
1417
|
-
else {
|
|
1418
|
-
list$1[tag] = UI;
|
|
1419
|
-
}
|
|
1416
|
+
list$1[tag] = UI;
|
|
1420
1417
|
},
|
|
1421
1418
|
get(tag, data, x, y, width, height) {
|
|
1419
|
+
if (!list$1[tag])
|
|
1420
|
+
debug$c.error('not register ' + tag);
|
|
1422
1421
|
const ui = new list$1[tag](data);
|
|
1423
1422
|
if (x !== undefined) {
|
|
1424
1423
|
ui.x = x;
|
|
@@ -1442,7 +1441,7 @@ const EventCreator = {
|
|
|
1442
1441
|
Object.keys(Event).forEach(key => {
|
|
1443
1442
|
name = Event[key];
|
|
1444
1443
|
if (typeof name === 'string')
|
|
1445
|
-
nameList[name]
|
|
1444
|
+
nameList[name] && debug$b.repeat(name), nameList[name] = Event;
|
|
1446
1445
|
});
|
|
1447
1446
|
},
|
|
1448
1447
|
changeName(oldName, newName) {
|
|
@@ -1644,7 +1643,7 @@ class LeafData {
|
|
|
1644
1643
|
const t = this;
|
|
1645
1644
|
if (t.blendMode === 'pass-through') {
|
|
1646
1645
|
const leaf = this.__leaf;
|
|
1647
|
-
if ((t.opacity < 1 && leaf.isBranch) || leaf.__hasEraser || t.eraser) {
|
|
1646
|
+
if ((t.opacity < 1 && (leaf.isBranch || t.__hasMultiPaint)) || leaf.__hasEraser || t.eraser) {
|
|
1648
1647
|
t.__single = true;
|
|
1649
1648
|
}
|
|
1650
1649
|
else if (t.__single) {
|
|
@@ -2042,8 +2041,9 @@ class LeaferCanvasBase extends Canvas$1 {
|
|
|
2042
2041
|
takeCanvas = this.getSameCanvas();
|
|
2043
2042
|
takeCanvas.copyWorld(this);
|
|
2044
2043
|
}
|
|
2045
|
-
|
|
2046
|
-
|
|
2044
|
+
const s = this.size;
|
|
2045
|
+
DataHelper.copyAttrs(s, size, canvasSizeAttrs);
|
|
2046
|
+
canvasSizeAttrs.forEach(key => s[key] || (s[key] = 1));
|
|
2047
2047
|
this.bounds = new Bounds(0, 0, this.width, this.height);
|
|
2048
2048
|
if (this.context && !this.unreal) {
|
|
2049
2049
|
this.updateViewSize();
|
|
@@ -2157,6 +2157,17 @@ class LeaferCanvasBase extends Canvas$1 {
|
|
|
2157
2157
|
if (!onlyResetTransform)
|
|
2158
2158
|
this.useWorldTransform();
|
|
2159
2159
|
}
|
|
2160
|
+
useGrayscaleAlpha(bounds) {
|
|
2161
|
+
this.setTempBounds(bounds, true, true);
|
|
2162
|
+
let alpha, pixel;
|
|
2163
|
+
const { context } = this, imageData = context.getImageData(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height), { data } = imageData;
|
|
2164
|
+
for (let i = 0, len = data.length; i < len; i += 4) {
|
|
2165
|
+
pixel = data[i] * 0.299 + data[i + 1] * 0.587 + data[i + 2] * 0.114;
|
|
2166
|
+
if (alpha = data[i + 3])
|
|
2167
|
+
data[i + 3] = alpha === 255 ? pixel : alpha * (pixel / 255);
|
|
2168
|
+
}
|
|
2169
|
+
context.putImageData(imageData, tempBounds$1.x, tempBounds$1.y);
|
|
2170
|
+
}
|
|
2160
2171
|
useMask(maskCanvas, fromBounds, toBounds) {
|
|
2161
2172
|
this.copyWorld(maskCanvas, fromBounds, toBounds, 'destination-in');
|
|
2162
2173
|
}
|
|
@@ -2167,7 +2178,7 @@ class LeaferCanvasBase extends Canvas$1 {
|
|
|
2167
2178
|
if (blendMode)
|
|
2168
2179
|
this.blendMode = blendMode;
|
|
2169
2180
|
this.fillStyle = color;
|
|
2170
|
-
|
|
2181
|
+
this.setTempBounds(bounds);
|
|
2171
2182
|
this.fillRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
|
|
2172
2183
|
if (blendMode)
|
|
2173
2184
|
this.blendMode = 'source-over';
|
|
@@ -2176,22 +2187,18 @@ class LeaferCanvasBase extends Canvas$1 {
|
|
|
2176
2187
|
if (blendMode)
|
|
2177
2188
|
this.blendMode = blendMode;
|
|
2178
2189
|
this.strokeStyle = color;
|
|
2179
|
-
|
|
2190
|
+
this.setTempBounds(bounds);
|
|
2180
2191
|
this.strokeRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
|
|
2181
2192
|
if (blendMode)
|
|
2182
2193
|
this.blendMode = 'source-over';
|
|
2183
2194
|
}
|
|
2184
2195
|
clearWorld(bounds, ceilPixel) {
|
|
2185
|
-
|
|
2186
|
-
if (ceilPixel)
|
|
2187
|
-
tempBounds$1.ceil();
|
|
2196
|
+
this.setTempBounds(bounds, ceilPixel);
|
|
2188
2197
|
this.clearRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
|
|
2189
2198
|
}
|
|
2190
2199
|
clipWorld(bounds, ceilPixel) {
|
|
2191
2200
|
this.beginPath();
|
|
2192
|
-
|
|
2193
|
-
if (ceilPixel)
|
|
2194
|
-
tempBounds$1.ceil();
|
|
2201
|
+
this.setTempBounds(bounds, ceilPixel);
|
|
2195
2202
|
this.rect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
|
|
2196
2203
|
this.clip();
|
|
2197
2204
|
}
|
|
@@ -2199,6 +2206,14 @@ class LeaferCanvasBase extends Canvas$1 {
|
|
|
2199
2206
|
const { pixelRatio } = this;
|
|
2200
2207
|
this.clearRect(0, 0, this.width * pixelRatio + 2, this.height * pixelRatio + 2);
|
|
2201
2208
|
}
|
|
2209
|
+
setTempBounds(bounds, ceil, intersect) {
|
|
2210
|
+
tempBounds$1.set(bounds);
|
|
2211
|
+
if (intersect)
|
|
2212
|
+
tempBounds$1.intersect(this.bounds);
|
|
2213
|
+
tempBounds$1.scale(this.pixelRatio);
|
|
2214
|
+
if (ceil)
|
|
2215
|
+
tempBounds$1.ceil();
|
|
2216
|
+
}
|
|
2202
2217
|
isSameSize(size) {
|
|
2203
2218
|
return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
|
|
2204
2219
|
}
|
|
@@ -5212,13 +5227,14 @@ const BranchRender = {
|
|
|
5212
5227
|
this.__.__checkSingle();
|
|
5213
5228
|
},
|
|
5214
5229
|
__render(canvas, options) {
|
|
5230
|
+
this.__nowWorld = this.__getNowWorld(options);
|
|
5215
5231
|
if (this.__worldOpacity) {
|
|
5216
5232
|
if (this.__.__single) {
|
|
5217
5233
|
if (this.__.eraser === 'path')
|
|
5218
5234
|
return this.__renderEraser(canvas, options);
|
|
5219
5235
|
const tempCanvas = canvas.getSameCanvas(false, true);
|
|
5220
5236
|
this.__renderBranch(tempCanvas, options);
|
|
5221
|
-
const nowWorld = this.
|
|
5237
|
+
const nowWorld = this.__nowWorld;
|
|
5222
5238
|
canvas.opacity = this.__.opacity;
|
|
5223
5239
|
canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, this.__.__blendMode, true);
|
|
5224
5240
|
tempCanvas.recycle(nowWorld);
|
|
@@ -5959,7 +5975,7 @@ class LeafLevelList {
|
|
|
5959
5975
|
}
|
|
5960
5976
|
}
|
|
5961
5977
|
|
|
5962
|
-
const version = "1.0.
|
|
5978
|
+
const version = "1.0.10";
|
|
5963
5979
|
|
|
5964
5980
|
class LeaferCanvas extends LeaferCanvasBase {
|
|
5965
5981
|
get allowBackgroundColor() { return true; }
|
|
@@ -6428,7 +6444,8 @@ class Renderer {
|
|
|
6428
6444
|
this.totalBounds = new Bounds();
|
|
6429
6445
|
debug$3.log(target.innerName, '--->');
|
|
6430
6446
|
try {
|
|
6431
|
-
target.
|
|
6447
|
+
if (!target.isApp)
|
|
6448
|
+
target.app.emit(RenderEvent.CHILD_START, target);
|
|
6432
6449
|
this.emitRender(RenderEvent.START);
|
|
6433
6450
|
this.renderOnce(callback);
|
|
6434
6451
|
this.emitRender(RenderEvent.END, this.totalBounds);
|
|
@@ -6709,6 +6726,12 @@ class UIData extends LeafData {
|
|
|
6709
6726
|
return strokeWidth;
|
|
6710
6727
|
}
|
|
6711
6728
|
get __hasStroke() { return this.stroke && this.strokeWidth; }
|
|
6729
|
+
get __hasMultiPaint() {
|
|
6730
|
+
const t = this;
|
|
6731
|
+
if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
|
|
6732
|
+
return true;
|
|
6733
|
+
return t.fill && this.__hasStroke;
|
|
6734
|
+
}
|
|
6712
6735
|
get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
|
|
6713
6736
|
get __autoWidth() { return !this._width; }
|
|
6714
6737
|
get __autoHeight() { return !this._height; }
|
|
@@ -7078,9 +7101,8 @@ const RectRender = {
|
|
|
7078
7101
|
canvas.strokeRect(half, half, width, height);
|
|
7079
7102
|
canvas.restore();
|
|
7080
7103
|
}
|
|
7081
|
-
else
|
|
7104
|
+
else
|
|
7082
7105
|
canvas.strokeRect(half, half, width, height);
|
|
7083
|
-
}
|
|
7084
7106
|
break;
|
|
7085
7107
|
case 'outside':
|
|
7086
7108
|
canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
|
|
@@ -7305,6 +7327,15 @@ __decorate([
|
|
|
7305
7327
|
__decorate([
|
|
7306
7328
|
boundsType(0)
|
|
7307
7329
|
], UI.prototype, "padding", void 0);
|
|
7330
|
+
__decorate([
|
|
7331
|
+
boundsType(false)
|
|
7332
|
+
], UI.prototype, "lockRatio", void 0);
|
|
7333
|
+
__decorate([
|
|
7334
|
+
boundsType()
|
|
7335
|
+
], UI.prototype, "widthRange", void 0);
|
|
7336
|
+
__decorate([
|
|
7337
|
+
boundsType()
|
|
7338
|
+
], UI.prototype, "heightRange", void 0);
|
|
7308
7339
|
__decorate([
|
|
7309
7340
|
dataType(false)
|
|
7310
7341
|
], UI.prototype, "draggable", void 0);
|
|
@@ -7596,8 +7627,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
|
|
|
7596
7627
|
__onResize(event) {
|
|
7597
7628
|
this.emitEvent(event);
|
|
7598
7629
|
DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
|
|
7599
|
-
if (!event.width || !event.height)
|
|
7600
|
-
debug$1.warn('w = 0 or h = 0');
|
|
7601
7630
|
setTimeout(() => { if (this.canvasManager)
|
|
7602
7631
|
this.canvasManager.clearRecycled(); }, 0);
|
|
7603
7632
|
}
|
|
@@ -7922,9 +7951,6 @@ __decorate([
|
|
|
7922
7951
|
__decorate([
|
|
7923
7952
|
dataType(false)
|
|
7924
7953
|
], Box.prototype, "resizeChildren", void 0);
|
|
7925
|
-
__decorate([
|
|
7926
|
-
dataType(false)
|
|
7927
|
-
], Box.prototype, "textBox", void 0);
|
|
7928
7954
|
__decorate([
|
|
7929
7955
|
affectRenderBoundsType('show')
|
|
7930
7956
|
], Box.prototype, "overflow", void 0);
|
|
@@ -8335,7 +8361,6 @@ let Text = class Text extends UI {
|
|
|
8335
8361
|
this.__updateTextDrawData();
|
|
8336
8362
|
const { bounds } = data.__textDrawData;
|
|
8337
8363
|
const b = layout.boxBounds;
|
|
8338
|
-
console.log(bounds, autoWidth, autoHeight);
|
|
8339
8364
|
if (data.__lineHeight < fontSize)
|
|
8340
8365
|
spread(bounds, fontSize / 2);
|
|
8341
8366
|
if (autoWidth || autoHeight) {
|
|
@@ -9387,16 +9412,16 @@ const EffectModule = {
|
|
|
9387
9412
|
|
|
9388
9413
|
const { excludeRenderBounds } = LeafBoundsHelper;
|
|
9389
9414
|
Group.prototype.__renderMask = function (canvas, options) {
|
|
9390
|
-
let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
|
|
9415
|
+
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
9391
9416
|
const { children } = this;
|
|
9392
9417
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
9393
|
-
child = children[i];
|
|
9394
|
-
if (
|
|
9418
|
+
child = children[i], mask = child.__.mask;
|
|
9419
|
+
if (mask) {
|
|
9395
9420
|
if (currentMask) {
|
|
9396
9421
|
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
9397
9422
|
maskCanvas = contentCanvas = null;
|
|
9398
9423
|
}
|
|
9399
|
-
if (
|
|
9424
|
+
if (mask === 'path' || mask === 'clipping-path') {
|
|
9400
9425
|
if (child.opacity < 1) {
|
|
9401
9426
|
currentMask = 'opacity-path';
|
|
9402
9427
|
maskOpacity = child.opacity;
|
|
@@ -9410,14 +9435,14 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
9410
9435
|
child.__clip(contentCanvas || canvas, options);
|
|
9411
9436
|
}
|
|
9412
9437
|
else {
|
|
9413
|
-
currentMask = 'alpha';
|
|
9438
|
+
currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
|
|
9414
9439
|
if (!maskCanvas)
|
|
9415
9440
|
maskCanvas = getCanvas(canvas);
|
|
9416
9441
|
if (!contentCanvas)
|
|
9417
9442
|
contentCanvas = getCanvas(canvas);
|
|
9418
9443
|
child.__render(maskCanvas, options);
|
|
9419
9444
|
}
|
|
9420
|
-
if (
|
|
9445
|
+
if (!(mask === 'clipping' || mask === 'clipping-path'))
|
|
9421
9446
|
continue;
|
|
9422
9447
|
}
|
|
9423
9448
|
if (excludeRenderBounds(child, options))
|
|
@@ -9428,6 +9453,8 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
9428
9453
|
};
|
|
9429
9454
|
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
|
|
9430
9455
|
switch (maskMode) {
|
|
9456
|
+
case 'grayscale':
|
|
9457
|
+
maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
|
|
9431
9458
|
case 'alpha':
|
|
9432
9459
|
usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
|
|
9433
9460
|
break;
|
|
@@ -10132,15 +10159,12 @@ const canvas = LeaferCanvasBase.prototype;
|
|
|
10132
10159
|
const debug = Debug.get('@leafer-ui/export');
|
|
10133
10160
|
canvas.export = function (filename, options) {
|
|
10134
10161
|
const { quality, blob } = FileHelper.getExportOptions(options);
|
|
10135
|
-
if (filename.includes('.'))
|
|
10162
|
+
if (filename.includes('.'))
|
|
10136
10163
|
return this.saveAs(filename, quality);
|
|
10137
|
-
|
|
10138
|
-
else if (blob) {
|
|
10164
|
+
else if (blob)
|
|
10139
10165
|
return this.toBlob(filename, quality);
|
|
10140
|
-
|
|
10141
|
-
else {
|
|
10166
|
+
else
|
|
10142
10167
|
return this.toDataURL(filename, quality);
|
|
10143
|
-
}
|
|
10144
10168
|
};
|
|
10145
10169
|
canvas.toBlob = function (type, quality) {
|
|
10146
10170
|
return new Promise((resolve) => {
|