@leafer/core 1.5.3 → 1.6.1
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/lib/core.cjs +90 -36
- package/lib/core.cjs.map +1 -1
- package/lib/core.esm.js +90 -36
- package/lib/core.esm.js.map +1 -1
- package/lib/core.esm.min.js +1 -1
- package/lib/core.esm.min.js.map +1 -1
- package/lib/core.min.cjs +1 -1
- package/lib/core.min.cjs.map +1 -1
- package/package.json +17 -17
- package/src/index.ts +1 -1
- package/types/index.d.ts +1 -1
package/lib/core.cjs
CHANGED
|
@@ -47,7 +47,7 @@ const IncrementId = {
|
|
|
47
47
|
};
|
|
48
48
|
const I$1 = IncrementId;
|
|
49
49
|
|
|
50
|
-
const { round, pow: pow$1, PI: PI$2 } = Math;
|
|
50
|
+
const { round: round$3, pow: pow$1, PI: PI$2 } = Math;
|
|
51
51
|
const MathHelper = {
|
|
52
52
|
within(value, min, max) {
|
|
53
53
|
if (typeof min === 'object')
|
|
@@ -111,7 +111,7 @@ const MathHelper = {
|
|
|
111
111
|
},
|
|
112
112
|
float(num, maxLength) {
|
|
113
113
|
const a = maxLength !== undefined ? pow$1(10, maxLength) : 1000000000000;
|
|
114
|
-
num = round(num * a) / a;
|
|
114
|
+
num = round$3(num * a) / a;
|
|
115
115
|
return num === -0 ? 0 : num;
|
|
116
116
|
},
|
|
117
117
|
getScaleData(scale, size, originSize, scaleData) {
|
|
@@ -134,8 +134,15 @@ const MathHelper = {
|
|
|
134
134
|
scaleData.scaleX = scale.x;
|
|
135
135
|
scaleData.scaleY = scale.y;
|
|
136
136
|
}
|
|
137
|
+
},
|
|
138
|
+
randInt,
|
|
139
|
+
randColor(opacity) {
|
|
140
|
+
return `rgba(${randInt(255)},${randInt(255)},${randInt(255)},${opacity || 1})`;
|
|
137
141
|
}
|
|
138
142
|
};
|
|
143
|
+
function randInt(num) {
|
|
144
|
+
return Math.round(Math.random() * num);
|
|
145
|
+
}
|
|
139
146
|
const OneRadian = PI$2 / 180;
|
|
140
147
|
const PI2 = PI$2 * 2;
|
|
141
148
|
const PI_2 = PI$2 / 2;
|
|
@@ -433,7 +440,7 @@ const MatrixHelper = {
|
|
|
433
440
|
const M$6 = MatrixHelper;
|
|
434
441
|
|
|
435
442
|
const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
|
|
436
|
-
const { sin: sin$2, cos: cos$2, abs: abs$2, sqrt: sqrt$2, atan2: atan2$2, min: min$1, PI: PI$1 } = Math;
|
|
443
|
+
const { sin: sin$2, cos: cos$2, abs: abs$2, sqrt: sqrt$2, atan2: atan2$2, min: min$1, round: round$2, PI: PI$1 } = Math;
|
|
437
444
|
const PointHelper = {
|
|
438
445
|
defaultPoint: getPointData(),
|
|
439
446
|
tempPoint: {},
|
|
@@ -454,6 +461,10 @@ const PointHelper = {
|
|
|
454
461
|
t.x = x;
|
|
455
462
|
t.y = y;
|
|
456
463
|
},
|
|
464
|
+
round(t, halfPixel) {
|
|
465
|
+
t.x = halfPixel ? round$2(t.x - 0.5) + 0.5 : round$2(t.x);
|
|
466
|
+
t.y = halfPixel ? round$2(t.y - 0.5) + 0.5 : round$2(t.y);
|
|
467
|
+
},
|
|
457
468
|
move(t, x, y) {
|
|
458
469
|
t.x += x;
|
|
459
470
|
t.y += y;
|
|
@@ -1319,6 +1330,7 @@ const StringNumberMap = {
|
|
|
1319
1330
|
'E': 1
|
|
1320
1331
|
};
|
|
1321
1332
|
|
|
1333
|
+
const { randColor } = MathHelper;
|
|
1322
1334
|
class Debug {
|
|
1323
1335
|
constructor(name) {
|
|
1324
1336
|
this.repeatMap = {};
|
|
@@ -1333,6 +1345,19 @@ class Debug {
|
|
|
1333
1345
|
static set exclude(name) {
|
|
1334
1346
|
this.excludeList = getNameList(name);
|
|
1335
1347
|
}
|
|
1348
|
+
static drawRepaint(canvas, bounds) {
|
|
1349
|
+
const color = randColor();
|
|
1350
|
+
canvas.fillWorld(bounds, color.replace('1)', '.1)'));
|
|
1351
|
+
canvas.strokeWorld(bounds, color);
|
|
1352
|
+
}
|
|
1353
|
+
static drawBounds(leaf, canvas, _options) {
|
|
1354
|
+
const showHit = Debug.showBounds === 'hit', w = leaf.__nowWorld, color = randColor();
|
|
1355
|
+
if (showHit)
|
|
1356
|
+
canvas.setWorld(w), leaf.__drawHitPath(canvas), canvas.fillStyle = color.replace('1)', '.2)'), canvas.fill();
|
|
1357
|
+
canvas.resetTransform();
|
|
1358
|
+
canvas.setStroke(color, 2);
|
|
1359
|
+
showHit ? canvas.stroke() : canvas.strokeWorld(w, color);
|
|
1360
|
+
}
|
|
1336
1361
|
log(...messages) {
|
|
1337
1362
|
if (D$4.enable) {
|
|
1338
1363
|
if (D$4.filterList.length && D$4.filterList.every(name => name !== this.name))
|
|
@@ -1419,7 +1444,7 @@ const Plugin = {
|
|
|
1419
1444
|
return rs;
|
|
1420
1445
|
},
|
|
1421
1446
|
need(name) {
|
|
1422
|
-
console.error('
|
|
1447
|
+
console.error('please install plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name);
|
|
1423
1448
|
}
|
|
1424
1449
|
};
|
|
1425
1450
|
setTimeout(() => check.forEach(name => Plugin.has(name, true)));
|
|
@@ -2019,7 +2044,7 @@ __decorate([
|
|
|
2019
2044
|
contextMethod()
|
|
2020
2045
|
], Canvas.prototype, "strokeText", null);
|
|
2021
2046
|
|
|
2022
|
-
const { copy: copy$5 } = MatrixHelper;
|
|
2047
|
+
const { copy: copy$5, multiplyParent: multiplyParent$3 } = MatrixHelper, { round: round$1 } = Math;
|
|
2023
2048
|
const minSize = { width: 1, height: 1, pixelRatio: 1 };
|
|
2024
2049
|
const canvasSizeAttrs = ['width', 'height', 'pixelRatio'];
|
|
2025
2050
|
class LeaferCanvasBase extends Canvas {
|
|
@@ -2028,6 +2053,8 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2028
2053
|
get pixelRatio() { return this.size.pixelRatio; }
|
|
2029
2054
|
get pixelWidth() { return this.width * this.pixelRatio; }
|
|
2030
2055
|
get pixelHeight() { return this.height * this.pixelRatio; }
|
|
2056
|
+
get pixelSnap() { return this.config.pixelSnap; }
|
|
2057
|
+
set pixelSnap(value) { this.config.pixelSnap = value; }
|
|
2031
2058
|
get allowBackgroundColor() { return this.view && this.parentView; }
|
|
2032
2059
|
constructor(config, manager) {
|
|
2033
2060
|
super();
|
|
@@ -2088,15 +2115,22 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2088
2115
|
stopAutoLayout() { }
|
|
2089
2116
|
setCursor(_cursor) { }
|
|
2090
2117
|
setWorld(matrix, parentMatrix) {
|
|
2091
|
-
const { pixelRatio } = this;
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2118
|
+
const { pixelRatio, pixelSnap } = this, w = this.worldTransform;
|
|
2119
|
+
if (parentMatrix)
|
|
2120
|
+
multiplyParent$3(matrix, parentMatrix, w);
|
|
2121
|
+
w.a = matrix.a * pixelRatio;
|
|
2122
|
+
w.b = matrix.b * pixelRatio;
|
|
2123
|
+
w.c = matrix.c * pixelRatio;
|
|
2124
|
+
w.d = matrix.d * pixelRatio;
|
|
2125
|
+
w.e = matrix.e * pixelRatio;
|
|
2126
|
+
w.f = matrix.f * pixelRatio;
|
|
2127
|
+
if (pixelSnap) {
|
|
2128
|
+
if (matrix.half && (matrix.half * pixelRatio) % 2)
|
|
2129
|
+
w.e = round$1(w.e - 0.5) + 0.5, w.f = round$1(w.f - 0.5) + 0.5;
|
|
2130
|
+
else
|
|
2131
|
+
w.e = round$1(w.e), w.f = round$1(w.f);
|
|
2099
2132
|
}
|
|
2133
|
+
this.setTransform(w.a, w.b, w.c, w.d, w.e, w.f);
|
|
2100
2134
|
}
|
|
2101
2135
|
useWorldTransform(worldTransform) {
|
|
2102
2136
|
if (worldTransform)
|
|
@@ -2239,12 +2273,13 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2239
2273
|
return this.width === size.width && this.height === size.height && (!size.pixelRatio || this.pixelRatio === size.pixelRatio);
|
|
2240
2274
|
}
|
|
2241
2275
|
getSameCanvas(useSameWorldTransform, useSameSmooth) {
|
|
2242
|
-
const canvas = this.manager ? this.manager.get(
|
|
2276
|
+
const { size, pixelSnap } = this, canvas = this.manager ? this.manager.get(size) : Creator.canvas(Object.assign({}, size));
|
|
2243
2277
|
canvas.save();
|
|
2244
2278
|
if (useSameWorldTransform)
|
|
2245
2279
|
copy$5(canvas.worldTransform, this.worldTransform), canvas.useWorldTransform();
|
|
2246
2280
|
if (useSameSmooth)
|
|
2247
2281
|
canvas.smooth = this.smooth;
|
|
2282
|
+
canvas.pixelSnap !== pixelSnap && (canvas.pixelSnap = pixelSnap);
|
|
2248
2283
|
return canvas;
|
|
2249
2284
|
}
|
|
2250
2285
|
recycle(clearBounds) {
|
|
@@ -3671,7 +3706,7 @@ const Resource = {
|
|
|
3671
3706
|
const R = Resource;
|
|
3672
3707
|
|
|
3673
3708
|
const ImageManager = {
|
|
3674
|
-
maxRecycled:
|
|
3709
|
+
maxRecycled: 10,
|
|
3675
3710
|
recycledList: [],
|
|
3676
3711
|
patternTasker: new TaskProcessor(),
|
|
3677
3712
|
get(config) {
|
|
@@ -4024,9 +4059,8 @@ function hitType(defaultValue) {
|
|
|
4024
4059
|
set(value) {
|
|
4025
4060
|
if (this.__setAttr(key, value)) {
|
|
4026
4061
|
this.__layout.hitCanvasChanged = true;
|
|
4027
|
-
if (Debug.
|
|
4062
|
+
if (Debug.showBounds === 'hit')
|
|
4028
4063
|
this.__layout.surfaceChanged || this.__layout.surfaceChange();
|
|
4029
|
-
}
|
|
4030
4064
|
if (this.leafer)
|
|
4031
4065
|
this.leafer.updateCursor();
|
|
4032
4066
|
}
|
|
@@ -4187,7 +4221,7 @@ function registerUIEvent() {
|
|
|
4187
4221
|
}
|
|
4188
4222
|
|
|
4189
4223
|
const { copy: copy$3, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter, rotateOfOuter, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
|
|
4190
|
-
const matrix = {};
|
|
4224
|
+
const matrix = {}, { round } = Math;
|
|
4191
4225
|
const LeafHelper = {
|
|
4192
4226
|
updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
|
|
4193
4227
|
if (checkAutoLayout && leaf.__hasAutoLayout && leaf.__layout.matrixChanged)
|
|
@@ -4261,6 +4295,8 @@ const LeafHelper = {
|
|
|
4261
4295
|
y = x.y, x = x.x;
|
|
4262
4296
|
x += t.x;
|
|
4263
4297
|
y += t.y;
|
|
4298
|
+
if (t.leafer && t.leafer.config.pointSnap)
|
|
4299
|
+
x = round(x), y = round(y);
|
|
4264
4300
|
transition ? t.animate({ x, y }, transition) : (t.x = x, t.y = y);
|
|
4265
4301
|
},
|
|
4266
4302
|
zoomOfWorld(t, origin, scaleX, scaleY, resize, transition) {
|
|
@@ -4499,6 +4535,7 @@ class LeafLayout {
|
|
|
4499
4535
|
set contentBounds(bounds) { this._contentBounds = bounds; }
|
|
4500
4536
|
get strokeBounds() { return this._strokeBounds || this.boxBounds; }
|
|
4501
4537
|
get renderBounds() { return this._renderBounds || this.boxBounds; }
|
|
4538
|
+
set renderBounds(bounds) { this._renderBounds = bounds; }
|
|
4502
4539
|
get localContentBounds() { toOuterOf$2(this.contentBounds, this.leaf.__localMatrix, this[localContent] || (this[localContent] = {})); return this[localContent]; }
|
|
4503
4540
|
get localStrokeBounds() { return this._localStrokeBounds || this; }
|
|
4504
4541
|
get localRenderBounds() { return this._localRenderBounds || this; }
|
|
@@ -4517,11 +4554,13 @@ class LeafLayout {
|
|
|
4517
4554
|
get height() { return this.boxBounds.height; }
|
|
4518
4555
|
constructor(leaf) {
|
|
4519
4556
|
this.leaf = leaf;
|
|
4520
|
-
this.boxBounds = { x: 0, y: 0, width: 0, height: 0 };
|
|
4521
4557
|
if (this.leaf.__local)
|
|
4522
4558
|
this._localRenderBounds = this._localStrokeBounds = this.leaf.__local;
|
|
4523
|
-
|
|
4524
|
-
|
|
4559
|
+
if (leaf.__world) {
|
|
4560
|
+
this.boxBounds = { x: 0, y: 0, width: 0, height: 0 };
|
|
4561
|
+
this.boxChange();
|
|
4562
|
+
this.matrixChange();
|
|
4563
|
+
}
|
|
4525
4564
|
}
|
|
4526
4565
|
createLocal() {
|
|
4527
4566
|
const local = this.leaf.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 };
|
|
@@ -4853,6 +4892,9 @@ class ResizeEvent extends Event {
|
|
|
4853
4892
|
}
|
|
4854
4893
|
this.old = oldSize;
|
|
4855
4894
|
}
|
|
4895
|
+
static isResizing(leaf) {
|
|
4896
|
+
return this.resizingKeys && this.resizingKeys[leaf.innerId] !== undefined;
|
|
4897
|
+
}
|
|
4856
4898
|
}
|
|
4857
4899
|
ResizeEvent.RESIZE = 'resize';
|
|
4858
4900
|
|
|
@@ -4895,6 +4937,7 @@ class RenderEvent extends Event {
|
|
|
4895
4937
|
}
|
|
4896
4938
|
RenderEvent.REQUEST = 'render.request';
|
|
4897
4939
|
RenderEvent.CHILD_START = 'render.child_start';
|
|
4940
|
+
RenderEvent.CHILD_END = 'render.child_end';
|
|
4898
4941
|
RenderEvent.START = 'render.start';
|
|
4899
4942
|
RenderEvent.BEFORE = 'render.before';
|
|
4900
4943
|
RenderEvent.RENDER = 'render';
|
|
@@ -5274,24 +5317,27 @@ const LeafBounds = {
|
|
|
5274
5317
|
const LeafRender = {
|
|
5275
5318
|
__render(canvas, options) {
|
|
5276
5319
|
if (this.__worldOpacity) {
|
|
5320
|
+
const data = this.__;
|
|
5277
5321
|
canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
|
|
5278
|
-
canvas.opacity =
|
|
5322
|
+
canvas.opacity = options.dimOpacity && !data.dimskip ? data.opacity * options.dimOpacity : data.opacity;
|
|
5279
5323
|
if (this.__.__single) {
|
|
5280
|
-
if (
|
|
5324
|
+
if (data.eraser === 'path')
|
|
5281
5325
|
return this.__renderEraser(canvas, options);
|
|
5282
5326
|
const tempCanvas = canvas.getSameCanvas(true, true);
|
|
5283
5327
|
this.__draw(tempCanvas, options, canvas);
|
|
5284
5328
|
if (this.__worldFlipped) {
|
|
5285
|
-
canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null,
|
|
5329
|
+
canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, data.__blendMode, true);
|
|
5286
5330
|
}
|
|
5287
5331
|
else {
|
|
5288
|
-
canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds,
|
|
5332
|
+
canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, data.__blendMode);
|
|
5289
5333
|
}
|
|
5290
5334
|
tempCanvas.recycle(this.__nowWorld);
|
|
5291
5335
|
}
|
|
5292
5336
|
else {
|
|
5293
5337
|
this.__draw(canvas, options);
|
|
5294
5338
|
}
|
|
5339
|
+
if (Debug.showBounds)
|
|
5340
|
+
Debug.drawBounds(this, canvas, options);
|
|
5295
5341
|
}
|
|
5296
5342
|
},
|
|
5297
5343
|
__clip(canvas, options) {
|
|
@@ -5321,14 +5367,19 @@ const BranchRender = {
|
|
|
5321
5367
|
__render(canvas, options) {
|
|
5322
5368
|
this.__nowWorld = this.__getNowWorld(options);
|
|
5323
5369
|
if (this.__worldOpacity) {
|
|
5324
|
-
|
|
5325
|
-
|
|
5370
|
+
const data = this.__;
|
|
5371
|
+
if (data.dim)
|
|
5372
|
+
options.dimOpacity = data.dim === true ? 0.2 : data.dim;
|
|
5373
|
+
else if (data.dimskip)
|
|
5374
|
+
options.dimOpacity && (options.dimOpacity = 0);
|
|
5375
|
+
if (data.__single) {
|
|
5376
|
+
if (data.eraser === 'path')
|
|
5326
5377
|
return this.__renderEraser(canvas, options);
|
|
5327
5378
|
const tempCanvas = canvas.getSameCanvas(false, true);
|
|
5328
5379
|
this.__renderBranch(tempCanvas, options);
|
|
5329
5380
|
const nowWorld = this.__nowWorld;
|
|
5330
|
-
canvas.opacity =
|
|
5331
|
-
canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld,
|
|
5381
|
+
canvas.opacity = options.dimOpacity ? data.opacity * options.dimOpacity : data.opacity;
|
|
5382
|
+
canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, data.__blendMode, true);
|
|
5332
5383
|
tempCanvas.recycle(nowWorld);
|
|
5333
5384
|
}
|
|
5334
5385
|
else {
|
|
@@ -5403,9 +5454,11 @@ exports.Leaf = class Leaf {
|
|
|
5403
5454
|
reset(data) {
|
|
5404
5455
|
if (this.leafer)
|
|
5405
5456
|
this.leafer.forceRender(this.__world);
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5457
|
+
if (data !== 0) {
|
|
5458
|
+
this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1 };
|
|
5459
|
+
if (data !== null)
|
|
5460
|
+
this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 };
|
|
5461
|
+
}
|
|
5409
5462
|
this.__worldOpacity = 1;
|
|
5410
5463
|
this.__ = new this.__DataProcessor(this);
|
|
5411
5464
|
this.__layout = new this.__LayoutProcessor(this);
|
|
@@ -5541,9 +5594,10 @@ exports.Leaf = class Leaf {
|
|
|
5541
5594
|
if (options.matrix) {
|
|
5542
5595
|
if (!this.__cameraWorld)
|
|
5543
5596
|
this.__cameraWorld = {};
|
|
5544
|
-
const cameraWorld = this.__cameraWorld;
|
|
5545
|
-
multiplyParent(
|
|
5597
|
+
const cameraWorld = this.__cameraWorld, world = this.__world;
|
|
5598
|
+
multiplyParent(world, options.matrix, cameraWorld, undefined, world);
|
|
5546
5599
|
toOuterOf(this.__layout.renderBounds, cameraWorld, cameraWorld);
|
|
5600
|
+
cameraWorld.half !== world.half && (cameraWorld.half = world.half);
|
|
5547
5601
|
return cameraWorld;
|
|
5548
5602
|
}
|
|
5549
5603
|
else {
|
|
@@ -5703,7 +5757,7 @@ exports.Leaf = class Leaf {
|
|
|
5703
5757
|
__updateHitCanvas() { }
|
|
5704
5758
|
__render(_canvas, _options) { }
|
|
5705
5759
|
__drawFast(_canvas, _options) { }
|
|
5706
|
-
__draw(_canvas, _options) { }
|
|
5760
|
+
__draw(_canvas, _options, _originCanvas) { }
|
|
5707
5761
|
__clip(_canvas, _options) { }
|
|
5708
5762
|
__renderShape(_canvas, _options, _ignoreFill, _ignoreStroke) { }
|
|
5709
5763
|
__updateWorldOpacity() { }
|
|
@@ -6073,7 +6127,7 @@ class LeafLevelList {
|
|
|
6073
6127
|
}
|
|
6074
6128
|
}
|
|
6075
6129
|
|
|
6076
|
-
const version = "1.
|
|
6130
|
+
const version = "1.6.1";
|
|
6077
6131
|
|
|
6078
6132
|
exports.AlignHelper = AlignHelper;
|
|
6079
6133
|
exports.AroundHelper = AroundHelper;
|