@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.esm.js CHANGED
@@ -45,7 +45,7 @@ const IncrementId = {
45
45
  };
46
46
  const I$1 = IncrementId;
47
47
 
48
- const { round, pow: pow$1, PI: PI$2 } = Math;
48
+ const { round: round$3, pow: pow$1, PI: PI$2 } = Math;
49
49
  const MathHelper = {
50
50
  within(value, min, max) {
51
51
  if (typeof min === 'object')
@@ -109,7 +109,7 @@ const MathHelper = {
109
109
  },
110
110
  float(num, maxLength) {
111
111
  const a = maxLength !== undefined ? pow$1(10, maxLength) : 1000000000000;
112
- num = round(num * a) / a;
112
+ num = round$3(num * a) / a;
113
113
  return num === -0 ? 0 : num;
114
114
  },
115
115
  getScaleData(scale, size, originSize, scaleData) {
@@ -132,8 +132,15 @@ const MathHelper = {
132
132
  scaleData.scaleX = scale.x;
133
133
  scaleData.scaleY = scale.y;
134
134
  }
135
+ },
136
+ randInt,
137
+ randColor(opacity) {
138
+ return `rgba(${randInt(255)},${randInt(255)},${randInt(255)},${opacity || 1})`;
135
139
  }
136
140
  };
141
+ function randInt(num) {
142
+ return Math.round(Math.random() * num);
143
+ }
137
144
  const OneRadian = PI$2 / 180;
138
145
  const PI2 = PI$2 * 2;
139
146
  const PI_2 = PI$2 / 2;
@@ -431,7 +438,7 @@ const MatrixHelper = {
431
438
  const M$6 = MatrixHelper;
432
439
 
433
440
  const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
434
- const { sin: sin$2, cos: cos$2, abs: abs$2, sqrt: sqrt$2, atan2: atan2$2, min: min$1, PI: PI$1 } = Math;
441
+ 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;
435
442
  const PointHelper = {
436
443
  defaultPoint: getPointData(),
437
444
  tempPoint: {},
@@ -452,6 +459,10 @@ const PointHelper = {
452
459
  t.x = x;
453
460
  t.y = y;
454
461
  },
462
+ round(t, halfPixel) {
463
+ t.x = halfPixel ? round$2(t.x - 0.5) + 0.5 : round$2(t.x);
464
+ t.y = halfPixel ? round$2(t.y - 0.5) + 0.5 : round$2(t.y);
465
+ },
455
466
  move(t, x, y) {
456
467
  t.x += x;
457
468
  t.y += y;
@@ -1317,6 +1328,7 @@ const StringNumberMap = {
1317
1328
  'E': 1
1318
1329
  };
1319
1330
 
1331
+ const { randColor } = MathHelper;
1320
1332
  class Debug {
1321
1333
  constructor(name) {
1322
1334
  this.repeatMap = {};
@@ -1331,6 +1343,19 @@ class Debug {
1331
1343
  static set exclude(name) {
1332
1344
  this.excludeList = getNameList(name);
1333
1345
  }
1346
+ static drawRepaint(canvas, bounds) {
1347
+ const color = randColor();
1348
+ canvas.fillWorld(bounds, color.replace('1)', '.1)'));
1349
+ canvas.strokeWorld(bounds, color);
1350
+ }
1351
+ static drawBounds(leaf, canvas, _options) {
1352
+ const showHit = Debug.showBounds === 'hit', w = leaf.__nowWorld, color = randColor();
1353
+ if (showHit)
1354
+ canvas.setWorld(w), leaf.__drawHitPath(canvas), canvas.fillStyle = color.replace('1)', '.2)'), canvas.fill();
1355
+ canvas.resetTransform();
1356
+ canvas.setStroke(color, 2);
1357
+ showHit ? canvas.stroke() : canvas.strokeWorld(w, color);
1358
+ }
1334
1359
  log(...messages) {
1335
1360
  if (D$4.enable) {
1336
1361
  if (D$4.filterList.length && D$4.filterList.every(name => name !== this.name))
@@ -1417,7 +1442,7 @@ const Plugin = {
1417
1442
  return rs;
1418
1443
  },
1419
1444
  need(name) {
1420
- console.error('need plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name);
1445
+ console.error('please install plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name);
1421
1446
  }
1422
1447
  };
1423
1448
  setTimeout(() => check.forEach(name => Plugin.has(name, true)));
@@ -2017,7 +2042,7 @@ __decorate([
2017
2042
  contextMethod()
2018
2043
  ], Canvas.prototype, "strokeText", null);
2019
2044
 
2020
- const { copy: copy$5 } = MatrixHelper;
2045
+ const { copy: copy$5, multiplyParent: multiplyParent$3 } = MatrixHelper, { round: round$1 } = Math;
2021
2046
  const minSize = { width: 1, height: 1, pixelRatio: 1 };
2022
2047
  const canvasSizeAttrs = ['width', 'height', 'pixelRatio'];
2023
2048
  class LeaferCanvasBase extends Canvas {
@@ -2026,6 +2051,8 @@ class LeaferCanvasBase extends Canvas {
2026
2051
  get pixelRatio() { return this.size.pixelRatio; }
2027
2052
  get pixelWidth() { return this.width * this.pixelRatio; }
2028
2053
  get pixelHeight() { return this.height * this.pixelRatio; }
2054
+ get pixelSnap() { return this.config.pixelSnap; }
2055
+ set pixelSnap(value) { this.config.pixelSnap = value; }
2029
2056
  get allowBackgroundColor() { return this.view && this.parentView; }
2030
2057
  constructor(config, manager) {
2031
2058
  super();
@@ -2086,15 +2113,22 @@ class LeaferCanvasBase extends Canvas {
2086
2113
  stopAutoLayout() { }
2087
2114
  setCursor(_cursor) { }
2088
2115
  setWorld(matrix, parentMatrix) {
2089
- const { pixelRatio } = this;
2090
- const w = this.worldTransform;
2091
- if (parentMatrix) {
2092
- const { a, b, c, d, e, f } = parentMatrix;
2093
- this.setTransform(w.a = ((matrix.a * a) + (matrix.b * c)) * pixelRatio, w.b = ((matrix.a * b) + (matrix.b * d)) * pixelRatio, w.c = ((matrix.c * a) + (matrix.d * c)) * pixelRatio, w.d = ((matrix.c * b) + (matrix.d * d)) * pixelRatio, w.e = (((matrix.e * a) + (matrix.f * c) + e)) * pixelRatio, w.f = (((matrix.e * b) + (matrix.f * d) + f)) * pixelRatio);
2094
- }
2095
- else {
2096
- this.setTransform(w.a = matrix.a * pixelRatio, w.b = matrix.b * pixelRatio, w.c = matrix.c * pixelRatio, w.d = matrix.d * pixelRatio, w.e = matrix.e * pixelRatio, w.f = matrix.f * pixelRatio);
2116
+ const { pixelRatio, pixelSnap } = this, w = this.worldTransform;
2117
+ if (parentMatrix)
2118
+ multiplyParent$3(matrix, parentMatrix, w);
2119
+ w.a = matrix.a * pixelRatio;
2120
+ w.b = matrix.b * pixelRatio;
2121
+ w.c = matrix.c * pixelRatio;
2122
+ w.d = matrix.d * pixelRatio;
2123
+ w.e = matrix.e * pixelRatio;
2124
+ w.f = matrix.f * pixelRatio;
2125
+ if (pixelSnap) {
2126
+ if (matrix.half && (matrix.half * pixelRatio) % 2)
2127
+ w.e = round$1(w.e - 0.5) + 0.5, w.f = round$1(w.f - 0.5) + 0.5;
2128
+ else
2129
+ w.e = round$1(w.e), w.f = round$1(w.f);
2097
2130
  }
2131
+ this.setTransform(w.a, w.b, w.c, w.d, w.e, w.f);
2098
2132
  }
2099
2133
  useWorldTransform(worldTransform) {
2100
2134
  if (worldTransform)
@@ -2237,12 +2271,13 @@ class LeaferCanvasBase extends Canvas {
2237
2271
  return this.width === size.width && this.height === size.height && (!size.pixelRatio || this.pixelRatio === size.pixelRatio);
2238
2272
  }
2239
2273
  getSameCanvas(useSameWorldTransform, useSameSmooth) {
2240
- const canvas = this.manager ? this.manager.get(this.size) : Creator.canvas(Object.assign({}, this.size));
2274
+ const { size, pixelSnap } = this, canvas = this.manager ? this.manager.get(size) : Creator.canvas(Object.assign({}, size));
2241
2275
  canvas.save();
2242
2276
  if (useSameWorldTransform)
2243
2277
  copy$5(canvas.worldTransform, this.worldTransform), canvas.useWorldTransform();
2244
2278
  if (useSameSmooth)
2245
2279
  canvas.smooth = this.smooth;
2280
+ canvas.pixelSnap !== pixelSnap && (canvas.pixelSnap = pixelSnap);
2246
2281
  return canvas;
2247
2282
  }
2248
2283
  recycle(clearBounds) {
@@ -3669,7 +3704,7 @@ const Resource = {
3669
3704
  const R = Resource;
3670
3705
 
3671
3706
  const ImageManager = {
3672
- maxRecycled: 100,
3707
+ maxRecycled: 10,
3673
3708
  recycledList: [],
3674
3709
  patternTasker: new TaskProcessor(),
3675
3710
  get(config) {
@@ -4022,9 +4057,8 @@ function hitType(defaultValue) {
4022
4057
  set(value) {
4023
4058
  if (this.__setAttr(key, value)) {
4024
4059
  this.__layout.hitCanvasChanged = true;
4025
- if (Debug.showHitView) {
4060
+ if (Debug.showBounds === 'hit')
4026
4061
  this.__layout.surfaceChanged || this.__layout.surfaceChange();
4027
- }
4028
4062
  if (this.leafer)
4029
4063
  this.leafer.updateCursor();
4030
4064
  }
@@ -4185,7 +4219,7 @@ function registerUIEvent() {
4185
4219
  }
4186
4220
 
4187
4221
  const { copy: copy$3, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter, rotateOfOuter, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
4188
- const matrix = {};
4222
+ const matrix = {}, { round } = Math;
4189
4223
  const LeafHelper = {
4190
4224
  updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
4191
4225
  if (checkAutoLayout && leaf.__hasAutoLayout && leaf.__layout.matrixChanged)
@@ -4259,6 +4293,8 @@ const LeafHelper = {
4259
4293
  y = x.y, x = x.x;
4260
4294
  x += t.x;
4261
4295
  y += t.y;
4296
+ if (t.leafer && t.leafer.config.pointSnap)
4297
+ x = round(x), y = round(y);
4262
4298
  transition ? t.animate({ x, y }, transition) : (t.x = x, t.y = y);
4263
4299
  },
4264
4300
  zoomOfWorld(t, origin, scaleX, scaleY, resize, transition) {
@@ -4497,6 +4533,7 @@ class LeafLayout {
4497
4533
  set contentBounds(bounds) { this._contentBounds = bounds; }
4498
4534
  get strokeBounds() { return this._strokeBounds || this.boxBounds; }
4499
4535
  get renderBounds() { return this._renderBounds || this.boxBounds; }
4536
+ set renderBounds(bounds) { this._renderBounds = bounds; }
4500
4537
  get localContentBounds() { toOuterOf$2(this.contentBounds, this.leaf.__localMatrix, this[localContent] || (this[localContent] = {})); return this[localContent]; }
4501
4538
  get localStrokeBounds() { return this._localStrokeBounds || this; }
4502
4539
  get localRenderBounds() { return this._localRenderBounds || this; }
@@ -4515,11 +4552,13 @@ class LeafLayout {
4515
4552
  get height() { return this.boxBounds.height; }
4516
4553
  constructor(leaf) {
4517
4554
  this.leaf = leaf;
4518
- this.boxBounds = { x: 0, y: 0, width: 0, height: 0 };
4519
4555
  if (this.leaf.__local)
4520
4556
  this._localRenderBounds = this._localStrokeBounds = this.leaf.__local;
4521
- this.boxChange();
4522
- this.matrixChange();
4557
+ if (leaf.__world) {
4558
+ this.boxBounds = { x: 0, y: 0, width: 0, height: 0 };
4559
+ this.boxChange();
4560
+ this.matrixChange();
4561
+ }
4523
4562
  }
4524
4563
  createLocal() {
4525
4564
  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 };
@@ -4851,6 +4890,9 @@ class ResizeEvent extends Event {
4851
4890
  }
4852
4891
  this.old = oldSize;
4853
4892
  }
4893
+ static isResizing(leaf) {
4894
+ return this.resizingKeys && this.resizingKeys[leaf.innerId] !== undefined;
4895
+ }
4854
4896
  }
4855
4897
  ResizeEvent.RESIZE = 'resize';
4856
4898
 
@@ -4893,6 +4935,7 @@ class RenderEvent extends Event {
4893
4935
  }
4894
4936
  RenderEvent.REQUEST = 'render.request';
4895
4937
  RenderEvent.CHILD_START = 'render.child_start';
4938
+ RenderEvent.CHILD_END = 'render.child_end';
4896
4939
  RenderEvent.START = 'render.start';
4897
4940
  RenderEvent.BEFORE = 'render.before';
4898
4941
  RenderEvent.RENDER = 'render';
@@ -5272,24 +5315,27 @@ const LeafBounds = {
5272
5315
  const LeafRender = {
5273
5316
  __render(canvas, options) {
5274
5317
  if (this.__worldOpacity) {
5318
+ const data = this.__;
5275
5319
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5276
- canvas.opacity = this.__.opacity;
5320
+ canvas.opacity = options.dimOpacity && !data.dimskip ? data.opacity * options.dimOpacity : data.opacity;
5277
5321
  if (this.__.__single) {
5278
- if (this.__.eraser === 'path')
5322
+ if (data.eraser === 'path')
5279
5323
  return this.__renderEraser(canvas, options);
5280
5324
  const tempCanvas = canvas.getSameCanvas(true, true);
5281
5325
  this.__draw(tempCanvas, options, canvas);
5282
5326
  if (this.__worldFlipped) {
5283
- canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, this.__.__blendMode, true);
5327
+ canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, data.__blendMode, true);
5284
5328
  }
5285
5329
  else {
5286
- canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, this.__.__blendMode);
5330
+ canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, data.__blendMode);
5287
5331
  }
5288
5332
  tempCanvas.recycle(this.__nowWorld);
5289
5333
  }
5290
5334
  else {
5291
5335
  this.__draw(canvas, options);
5292
5336
  }
5337
+ if (Debug.showBounds)
5338
+ Debug.drawBounds(this, canvas, options);
5293
5339
  }
5294
5340
  },
5295
5341
  __clip(canvas, options) {
@@ -5319,14 +5365,19 @@ const BranchRender = {
5319
5365
  __render(canvas, options) {
5320
5366
  this.__nowWorld = this.__getNowWorld(options);
5321
5367
  if (this.__worldOpacity) {
5322
- if (this.__.__single) {
5323
- if (this.__.eraser === 'path')
5368
+ const data = this.__;
5369
+ if (data.dim)
5370
+ options.dimOpacity = data.dim === true ? 0.2 : data.dim;
5371
+ else if (data.dimskip)
5372
+ options.dimOpacity && (options.dimOpacity = 0);
5373
+ if (data.__single) {
5374
+ if (data.eraser === 'path')
5324
5375
  return this.__renderEraser(canvas, options);
5325
5376
  const tempCanvas = canvas.getSameCanvas(false, true);
5326
5377
  this.__renderBranch(tempCanvas, options);
5327
5378
  const nowWorld = this.__nowWorld;
5328
- canvas.opacity = this.__.opacity;
5329
- canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, this.__.__blendMode, true);
5379
+ canvas.opacity = options.dimOpacity ? data.opacity * options.dimOpacity : data.opacity;
5380
+ canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, data.__blendMode, true);
5330
5381
  tempCanvas.recycle(nowWorld);
5331
5382
  }
5332
5383
  else {
@@ -5401,9 +5452,11 @@ let Leaf = class Leaf {
5401
5452
  reset(data) {
5402
5453
  if (this.leafer)
5403
5454
  this.leafer.forceRender(this.__world);
5404
- 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 };
5405
- if (data !== null)
5406
- this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 };
5455
+ if (data !== 0) {
5456
+ 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 };
5457
+ if (data !== null)
5458
+ this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 };
5459
+ }
5407
5460
  this.__worldOpacity = 1;
5408
5461
  this.__ = new this.__DataProcessor(this);
5409
5462
  this.__layout = new this.__LayoutProcessor(this);
@@ -5539,9 +5592,10 @@ let Leaf = class Leaf {
5539
5592
  if (options.matrix) {
5540
5593
  if (!this.__cameraWorld)
5541
5594
  this.__cameraWorld = {};
5542
- const cameraWorld = this.__cameraWorld;
5543
- multiplyParent(this.__world, options.matrix, cameraWorld, undefined, this.__world);
5595
+ const cameraWorld = this.__cameraWorld, world = this.__world;
5596
+ multiplyParent(world, options.matrix, cameraWorld, undefined, world);
5544
5597
  toOuterOf(this.__layout.renderBounds, cameraWorld, cameraWorld);
5598
+ cameraWorld.half !== world.half && (cameraWorld.half = world.half);
5545
5599
  return cameraWorld;
5546
5600
  }
5547
5601
  else {
@@ -5701,7 +5755,7 @@ let Leaf = class Leaf {
5701
5755
  __updateHitCanvas() { }
5702
5756
  __render(_canvas, _options) { }
5703
5757
  __drawFast(_canvas, _options) { }
5704
- __draw(_canvas, _options) { }
5758
+ __draw(_canvas, _options, _originCanvas) { }
5705
5759
  __clip(_canvas, _options) { }
5706
5760
  __renderShape(_canvas, _options, _ignoreFill, _ignoreStroke) { }
5707
5761
  __updateWorldOpacity() { }
@@ -6071,7 +6125,7 @@ class LeafLevelList {
6071
6125
  }
6072
6126
  }
6073
6127
 
6074
- const version = "1.5.3";
6128
+ const version = "1.6.1";
6075
6129
 
6076
6130
  export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, FileHelper, ImageEvent, ImageManager, IncrementId, LayoutEvent, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, LeaferCanvasBase, LeaferEvent, LeaferImage, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Plugin, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Resource, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isEmptyData, isNull, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, useModule, version, visibleType };
6077
6131
  //# sourceMappingURL=core.esm.js.map