leafer-ui 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/README.md +66 -32
- package/dist/web.cjs +13 -13
- package/dist/web.esm.js +13 -13
- package/dist/web.esm.min.js +1 -1
- package/dist/web.js +69 -50
- package/dist/web.min.cjs +1 -1
- package/dist/web.min.js +1 -1
- package/dist/web.module.js +69 -50
- package/dist/web.module.min.js +1 -1
- package/package.json +11 -11
package/dist/web.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$2[tag])
|
|
1414
|
+
if (list$2[tag])
|
|
1415
1415
|
debug$f.repeat(tag);
|
|
1416
|
-
|
|
1417
|
-
else {
|
|
1418
|
-
list$2[tag] = UI;
|
|
1419
|
-
}
|
|
1416
|
+
list$2[tag] = UI;
|
|
1420
1417
|
},
|
|
1421
1418
|
get(tag, data, x, y, width, height) {
|
|
1419
|
+
if (!list$2[tag])
|
|
1420
|
+
debug$f.error('not register ' + tag);
|
|
1422
1421
|
const ui = new list$2[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$e.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
|
const debug$7 = Debug.get('LeaferCanvas');
|
|
5965
5981
|
class LeaferCanvas extends LeaferCanvasBase {
|
|
@@ -6601,7 +6617,8 @@ class Renderer {
|
|
|
6601
6617
|
this.totalBounds = new Bounds();
|
|
6602
6618
|
debug$5.log(target.innerName, '--->');
|
|
6603
6619
|
try {
|
|
6604
|
-
target.
|
|
6620
|
+
if (!target.isApp)
|
|
6621
|
+
target.app.emit(RenderEvent.CHILD_START, target);
|
|
6605
6622
|
this.emitRender(RenderEvent.START);
|
|
6606
6623
|
this.renderOnce(callback);
|
|
6607
6624
|
this.emitRender(RenderEvent.END, this.totalBounds);
|
|
@@ -7155,6 +7172,12 @@ class UIData extends LeafData {
|
|
|
7155
7172
|
return strokeWidth;
|
|
7156
7173
|
}
|
|
7157
7174
|
get __hasStroke() { return this.stroke && this.strokeWidth; }
|
|
7175
|
+
get __hasMultiPaint() {
|
|
7176
|
+
const t = this;
|
|
7177
|
+
if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
|
|
7178
|
+
return true;
|
|
7179
|
+
return t.fill && this.__hasStroke;
|
|
7180
|
+
}
|
|
7158
7181
|
get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
|
|
7159
7182
|
get __autoWidth() { return !this._width; }
|
|
7160
7183
|
get __autoHeight() { return !this._height; }
|
|
@@ -7524,9 +7547,8 @@ const RectRender = {
|
|
|
7524
7547
|
canvas.strokeRect(half, half, width, height);
|
|
7525
7548
|
canvas.restore();
|
|
7526
7549
|
}
|
|
7527
|
-
else
|
|
7550
|
+
else
|
|
7528
7551
|
canvas.strokeRect(half, half, width, height);
|
|
7529
|
-
}
|
|
7530
7552
|
break;
|
|
7531
7553
|
case 'outside':
|
|
7532
7554
|
canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
|
|
@@ -7751,6 +7773,15 @@ __decorate([
|
|
|
7751
7773
|
__decorate([
|
|
7752
7774
|
boundsType(0)
|
|
7753
7775
|
], UI.prototype, "padding", void 0);
|
|
7776
|
+
__decorate([
|
|
7777
|
+
boundsType(false)
|
|
7778
|
+
], UI.prototype, "lockRatio", void 0);
|
|
7779
|
+
__decorate([
|
|
7780
|
+
boundsType()
|
|
7781
|
+
], UI.prototype, "widthRange", void 0);
|
|
7782
|
+
__decorate([
|
|
7783
|
+
boundsType()
|
|
7784
|
+
], UI.prototype, "heightRange", void 0);
|
|
7754
7785
|
__decorate([
|
|
7755
7786
|
dataType(false)
|
|
7756
7787
|
], UI.prototype, "draggable", void 0);
|
|
@@ -8042,8 +8073,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
|
|
|
8042
8073
|
__onResize(event) {
|
|
8043
8074
|
this.emitEvent(event);
|
|
8044
8075
|
DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
|
|
8045
|
-
if (!event.width || !event.height)
|
|
8046
|
-
debug$3.warn('w = 0 or h = 0');
|
|
8047
8076
|
setTimeout(() => { if (this.canvasManager)
|
|
8048
8077
|
this.canvasManager.clearRecycled(); }, 0);
|
|
8049
8078
|
}
|
|
@@ -8368,9 +8397,6 @@ __decorate([
|
|
|
8368
8397
|
__decorate([
|
|
8369
8398
|
dataType(false)
|
|
8370
8399
|
], Box.prototype, "resizeChildren", void 0);
|
|
8371
|
-
__decorate([
|
|
8372
|
-
dataType(false)
|
|
8373
|
-
], Box.prototype, "textBox", void 0);
|
|
8374
8400
|
__decorate([
|
|
8375
8401
|
affectRenderBoundsType('show')
|
|
8376
8402
|
], Box.prototype, "overflow", void 0);
|
|
@@ -8781,7 +8807,6 @@ let Text = class Text extends UI {
|
|
|
8781
8807
|
this.__updateTextDrawData();
|
|
8782
8808
|
const { bounds } = data.__textDrawData;
|
|
8783
8809
|
const b = layout.boxBounds;
|
|
8784
|
-
console.log(bounds, autoWidth, autoHeight);
|
|
8785
8810
|
if (data.__lineHeight < fontSize)
|
|
8786
8811
|
spread(bounds, fontSize / 2);
|
|
8787
8812
|
if (autoWidth || autoHeight) {
|
|
@@ -9126,19 +9151,13 @@ class UIEvent extends Event {
|
|
|
9126
9151
|
Object.assign(this, params);
|
|
9127
9152
|
}
|
|
9128
9153
|
getBoxPoint(relative) {
|
|
9129
|
-
|
|
9130
|
-
relative = this.current;
|
|
9131
|
-
return relative.getBoxPoint(this);
|
|
9154
|
+
return (relative || this.current).getBoxPoint(this);
|
|
9132
9155
|
}
|
|
9133
9156
|
getInnerPoint(relative) {
|
|
9134
|
-
|
|
9135
|
-
relative = this.current;
|
|
9136
|
-
return relative.getInnerPoint(this);
|
|
9157
|
+
return (relative || this.current).getInnerPoint(this);
|
|
9137
9158
|
}
|
|
9138
9159
|
getLocalPoint(relative) {
|
|
9139
|
-
|
|
9140
|
-
relative = this.current;
|
|
9141
|
-
return relative.getLocalPoint(this);
|
|
9160
|
+
return (relative || this.current).getLocalPoint(this);
|
|
9142
9161
|
}
|
|
9143
9162
|
getPagePoint() {
|
|
9144
9163
|
return this.current.getPagePoint(this);
|
|
@@ -9372,7 +9391,8 @@ const debug$2 = Debug.get('LeaferTypeCreator');
|
|
|
9372
9391
|
const LeaferTypeCreator = {
|
|
9373
9392
|
list: {},
|
|
9374
9393
|
register(name, fn) {
|
|
9375
|
-
list[name]
|
|
9394
|
+
list[name] && debug$2.repeat(name);
|
|
9395
|
+
list[name] = fn;
|
|
9376
9396
|
},
|
|
9377
9397
|
run(name, leafer) {
|
|
9378
9398
|
const fn = list[name];
|
|
@@ -11740,16 +11760,16 @@ const EffectModule = {
|
|
|
11740
11760
|
|
|
11741
11761
|
const { excludeRenderBounds } = LeafBoundsHelper;
|
|
11742
11762
|
Group.prototype.__renderMask = function (canvas, options) {
|
|
11743
|
-
let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
|
|
11763
|
+
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
11744
11764
|
const { children } = this;
|
|
11745
11765
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
11746
|
-
child = children[i];
|
|
11747
|
-
if (
|
|
11766
|
+
child = children[i], mask = child.__.mask;
|
|
11767
|
+
if (mask) {
|
|
11748
11768
|
if (currentMask) {
|
|
11749
11769
|
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
11750
11770
|
maskCanvas = contentCanvas = null;
|
|
11751
11771
|
}
|
|
11752
|
-
if (
|
|
11772
|
+
if (mask === 'path' || mask === 'clipping-path') {
|
|
11753
11773
|
if (child.opacity < 1) {
|
|
11754
11774
|
currentMask = 'opacity-path';
|
|
11755
11775
|
maskOpacity = child.opacity;
|
|
@@ -11763,14 +11783,14 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
11763
11783
|
child.__clip(contentCanvas || canvas, options);
|
|
11764
11784
|
}
|
|
11765
11785
|
else {
|
|
11766
|
-
currentMask = 'alpha';
|
|
11786
|
+
currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
|
|
11767
11787
|
if (!maskCanvas)
|
|
11768
11788
|
maskCanvas = getCanvas(canvas);
|
|
11769
11789
|
if (!contentCanvas)
|
|
11770
11790
|
contentCanvas = getCanvas(canvas);
|
|
11771
11791
|
child.__render(maskCanvas, options);
|
|
11772
11792
|
}
|
|
11773
|
-
if (
|
|
11793
|
+
if (!(mask === 'clipping' || mask === 'clipping-path'))
|
|
11774
11794
|
continue;
|
|
11775
11795
|
}
|
|
11776
11796
|
if (excludeRenderBounds(child, options))
|
|
@@ -11781,6 +11801,8 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
11781
11801
|
};
|
|
11782
11802
|
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
|
|
11783
11803
|
switch (maskMode) {
|
|
11804
|
+
case 'grayscale':
|
|
11805
|
+
maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
|
|
11784
11806
|
case 'alpha':
|
|
11785
11807
|
usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
|
|
11786
11808
|
break;
|
|
@@ -12485,15 +12507,12 @@ const canvas = LeaferCanvasBase.prototype;
|
|
|
12485
12507
|
const debug = Debug.get('@leafer-ui/export');
|
|
12486
12508
|
canvas.export = function (filename, options) {
|
|
12487
12509
|
const { quality, blob } = FileHelper.getExportOptions(options);
|
|
12488
|
-
if (filename.includes('.'))
|
|
12510
|
+
if (filename.includes('.'))
|
|
12489
12511
|
return this.saveAs(filename, quality);
|
|
12490
|
-
|
|
12491
|
-
else if (blob) {
|
|
12512
|
+
else if (blob)
|
|
12492
12513
|
return this.toBlob(filename, quality);
|
|
12493
|
-
|
|
12494
|
-
else {
|
|
12514
|
+
else
|
|
12495
12515
|
return this.toDataURL(filename, quality);
|
|
12496
|
-
}
|
|
12497
12516
|
};
|
|
12498
12517
|
canvas.toBlob = function (type, quality) {
|
|
12499
12518
|
return new Promise((resolve) => {
|