@leafer-game/miniapp 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/miniapp.module.js +73 -53
- package/dist/miniapp.module.min.js +1 -1
- package/package.json +4 -4
package/dist/miniapp.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$e.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$e.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$d.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 false; }
|
|
@@ -6072,7 +6088,7 @@ function useCanvas(_canvasType, app) {
|
|
|
6072
6088
|
Platform.origin = {
|
|
6073
6089
|
createCanvas: (width, height, _format) => {
|
|
6074
6090
|
const data = { type: '2d', width, height };
|
|
6075
|
-
app.createOffscreenCanvas ? app.createOffscreenCanvas(data) : app.createOffScreenCanvas(data);
|
|
6091
|
+
return app.createOffscreenCanvas ? app.createOffscreenCanvas(data) : app.createOffScreenCanvas(data);
|
|
6076
6092
|
},
|
|
6077
6093
|
canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
|
|
6078
6094
|
canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, { quality }),
|
|
@@ -6183,7 +6199,7 @@ function useCanvas(_canvasType, app) {
|
|
|
6183
6199
|
}
|
|
6184
6200
|
Platform.name = 'miniapp';
|
|
6185
6201
|
Platform.requestRender = function (render) {
|
|
6186
|
-
const { view } =
|
|
6202
|
+
const { view } = Platform.renderCanvas || Platform.canvas;
|
|
6187
6203
|
view.requestAnimationFrame ? view.requestAnimationFrame(render) : setTimeout(render, 16);
|
|
6188
6204
|
};
|
|
6189
6205
|
defineKey(Platform, 'devicePixelRatio', { get() { return Math.max(1, wx.getSystemInfoSync().pixelRatio); } });
|
|
@@ -6568,7 +6584,8 @@ class Renderer {
|
|
|
6568
6584
|
this.totalBounds = new Bounds();
|
|
6569
6585
|
debug$5.log(target.innerName, '--->');
|
|
6570
6586
|
try {
|
|
6571
|
-
target.
|
|
6587
|
+
if (!target.isApp)
|
|
6588
|
+
target.app.emit(RenderEvent.CHILD_START, target);
|
|
6572
6589
|
this.emitRender(RenderEvent.START);
|
|
6573
6590
|
this.renderOnce(callback);
|
|
6574
6591
|
this.emitRender(RenderEvent.END, this.totalBounds);
|
|
@@ -7122,6 +7139,12 @@ class UIData extends LeafData {
|
|
|
7122
7139
|
return strokeWidth;
|
|
7123
7140
|
}
|
|
7124
7141
|
get __hasStroke() { return this.stroke && this.strokeWidth; }
|
|
7142
|
+
get __hasMultiPaint() {
|
|
7143
|
+
const t = this;
|
|
7144
|
+
if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
|
|
7145
|
+
return true;
|
|
7146
|
+
return t.fill && this.__hasStroke;
|
|
7147
|
+
}
|
|
7125
7148
|
get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
|
|
7126
7149
|
get __autoWidth() { return !this._width; }
|
|
7127
7150
|
get __autoHeight() { return !this._height; }
|
|
@@ -7491,9 +7514,8 @@ const RectRender = {
|
|
|
7491
7514
|
canvas.strokeRect(half, half, width, height);
|
|
7492
7515
|
canvas.restore();
|
|
7493
7516
|
}
|
|
7494
|
-
else
|
|
7517
|
+
else
|
|
7495
7518
|
canvas.strokeRect(half, half, width, height);
|
|
7496
|
-
}
|
|
7497
7519
|
break;
|
|
7498
7520
|
case 'outside':
|
|
7499
7521
|
canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
|
|
@@ -7718,6 +7740,15 @@ __decorate([
|
|
|
7718
7740
|
__decorate([
|
|
7719
7741
|
boundsType(0)
|
|
7720
7742
|
], UI.prototype, "padding", void 0);
|
|
7743
|
+
__decorate([
|
|
7744
|
+
boundsType(false)
|
|
7745
|
+
], UI.prototype, "lockRatio", void 0);
|
|
7746
|
+
__decorate([
|
|
7747
|
+
boundsType()
|
|
7748
|
+
], UI.prototype, "widthRange", void 0);
|
|
7749
|
+
__decorate([
|
|
7750
|
+
boundsType()
|
|
7751
|
+
], UI.prototype, "heightRange", void 0);
|
|
7721
7752
|
__decorate([
|
|
7722
7753
|
dataType(false)
|
|
7723
7754
|
], UI.prototype, "draggable", void 0);
|
|
@@ -8009,8 +8040,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
|
|
|
8009
8040
|
__onResize(event) {
|
|
8010
8041
|
this.emitEvent(event);
|
|
8011
8042
|
DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
|
|
8012
|
-
if (!event.width || !event.height)
|
|
8013
|
-
debug$3.warn('w = 0 or h = 0');
|
|
8014
8043
|
setTimeout(() => { if (this.canvasManager)
|
|
8015
8044
|
this.canvasManager.clearRecycled(); }, 0);
|
|
8016
8045
|
}
|
|
@@ -8335,9 +8364,6 @@ __decorate([
|
|
|
8335
8364
|
__decorate([
|
|
8336
8365
|
dataType(false)
|
|
8337
8366
|
], Box.prototype, "resizeChildren", void 0);
|
|
8338
|
-
__decorate([
|
|
8339
|
-
dataType(false)
|
|
8340
|
-
], Box.prototype, "textBox", void 0);
|
|
8341
8367
|
__decorate([
|
|
8342
8368
|
affectRenderBoundsType('show')
|
|
8343
8369
|
], Box.prototype, "overflow", void 0);
|
|
@@ -8748,7 +8774,6 @@ let Text = class Text extends UI {
|
|
|
8748
8774
|
this.__updateTextDrawData();
|
|
8749
8775
|
const { bounds } = data.__textDrawData;
|
|
8750
8776
|
const b = layout.boxBounds;
|
|
8751
|
-
console.log(bounds, autoWidth, autoHeight);
|
|
8752
8777
|
if (data.__lineHeight < fontSize)
|
|
8753
8778
|
spread(bounds, fontSize / 2);
|
|
8754
8779
|
if (autoWidth || autoHeight) {
|
|
@@ -9093,19 +9118,13 @@ class UIEvent extends Event {
|
|
|
9093
9118
|
Object.assign(this, params);
|
|
9094
9119
|
}
|
|
9095
9120
|
getBoxPoint(relative) {
|
|
9096
|
-
|
|
9097
|
-
relative = this.current;
|
|
9098
|
-
return relative.getBoxPoint(this);
|
|
9121
|
+
return (relative || this.current).getBoxPoint(this);
|
|
9099
9122
|
}
|
|
9100
9123
|
getInnerPoint(relative) {
|
|
9101
|
-
|
|
9102
|
-
relative = this.current;
|
|
9103
|
-
return relative.getInnerPoint(this);
|
|
9124
|
+
return (relative || this.current).getInnerPoint(this);
|
|
9104
9125
|
}
|
|
9105
9126
|
getLocalPoint(relative) {
|
|
9106
|
-
|
|
9107
|
-
relative = this.current;
|
|
9108
|
-
return relative.getLocalPoint(this);
|
|
9127
|
+
return (relative || this.current).getLocalPoint(this);
|
|
9109
9128
|
}
|
|
9110
9129
|
getPagePoint() {
|
|
9111
9130
|
return this.current.getPagePoint(this);
|
|
@@ -9339,7 +9358,8 @@ const debug$2 = Debug.get('LeaferTypeCreator');
|
|
|
9339
9358
|
const LeaferTypeCreator = {
|
|
9340
9359
|
list: {},
|
|
9341
9360
|
register(name, fn) {
|
|
9342
|
-
list[name]
|
|
9361
|
+
list[name] && debug$2.repeat(name);
|
|
9362
|
+
list[name] = fn;
|
|
9343
9363
|
},
|
|
9344
9364
|
run(name, leafer) {
|
|
9345
9365
|
const fn = list[name];
|
|
@@ -11460,16 +11480,16 @@ const EffectModule = {
|
|
|
11460
11480
|
|
|
11461
11481
|
const { excludeRenderBounds } = LeafBoundsHelper;
|
|
11462
11482
|
Group.prototype.__renderMask = function (canvas, options) {
|
|
11463
|
-
let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
|
|
11483
|
+
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
11464
11484
|
const { children } = this;
|
|
11465
11485
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
11466
|
-
child = children[i];
|
|
11467
|
-
if (
|
|
11486
|
+
child = children[i], mask = child.__.mask;
|
|
11487
|
+
if (mask) {
|
|
11468
11488
|
if (currentMask) {
|
|
11469
11489
|
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
11470
11490
|
maskCanvas = contentCanvas = null;
|
|
11471
11491
|
}
|
|
11472
|
-
if (
|
|
11492
|
+
if (mask === 'path' || mask === 'clipping-path') {
|
|
11473
11493
|
if (child.opacity < 1) {
|
|
11474
11494
|
currentMask = 'opacity-path';
|
|
11475
11495
|
maskOpacity = child.opacity;
|
|
@@ -11483,14 +11503,14 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
11483
11503
|
child.__clip(contentCanvas || canvas, options);
|
|
11484
11504
|
}
|
|
11485
11505
|
else {
|
|
11486
|
-
currentMask = 'alpha';
|
|
11506
|
+
currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
|
|
11487
11507
|
if (!maskCanvas)
|
|
11488
11508
|
maskCanvas = getCanvas(canvas);
|
|
11489
11509
|
if (!contentCanvas)
|
|
11490
11510
|
contentCanvas = getCanvas(canvas);
|
|
11491
11511
|
child.__render(maskCanvas, options);
|
|
11492
11512
|
}
|
|
11493
|
-
if (
|
|
11513
|
+
if (!(mask === 'clipping' || mask === 'clipping-path'))
|
|
11494
11514
|
continue;
|
|
11495
11515
|
}
|
|
11496
11516
|
if (excludeRenderBounds(child, options))
|
|
@@ -11501,6 +11521,8 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
11501
11521
|
};
|
|
11502
11522
|
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
|
|
11503
11523
|
switch (maskMode) {
|
|
11524
|
+
case 'grayscale':
|
|
11525
|
+
maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
|
|
11504
11526
|
case 'alpha':
|
|
11505
11527
|
usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
|
|
11506
11528
|
break;
|
|
@@ -12205,15 +12227,12 @@ const canvas = LeaferCanvasBase.prototype;
|
|
|
12205
12227
|
const debug = Debug.get('@leafer-ui/export');
|
|
12206
12228
|
canvas.export = function (filename, options) {
|
|
12207
12229
|
const { quality, blob } = FileHelper.getExportOptions(options);
|
|
12208
|
-
if (filename.includes('.'))
|
|
12230
|
+
if (filename.includes('.'))
|
|
12209
12231
|
return this.saveAs(filename, quality);
|
|
12210
|
-
|
|
12211
|
-
else if (blob) {
|
|
12232
|
+
else if (blob)
|
|
12212
12233
|
return this.toBlob(filename, quality);
|
|
12213
|
-
|
|
12214
|
-
else {
|
|
12234
|
+
else
|
|
12215
12235
|
return this.toDataURL(filename, quality);
|
|
12216
|
-
}
|
|
12217
12236
|
};
|
|
12218
12237
|
canvas.toBlob = function (type, quality) {
|
|
12219
12238
|
return new Promise((resolve) => {
|
|
@@ -12950,7 +12969,8 @@ let Animate = class Animate extends Eventer {
|
|
|
12950
12969
|
return;
|
|
12951
12970
|
if (typeof time === 'object')
|
|
12952
12971
|
time = UnitConvert.number(time, this.duration);
|
|
12953
|
-
time
|
|
12972
|
+
if (time)
|
|
12973
|
+
time /= this.speed;
|
|
12954
12974
|
if (!this.started || time < this.time)
|
|
12955
12975
|
this.start(true);
|
|
12956
12976
|
this.time = time;
|