@leafer/core 1.6.7 → 1.8.0

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
@@ -43,7 +43,7 @@ const IncrementId = {
43
43
  };
44
44
  const I$1 = IncrementId;
45
45
 
46
- const { round: round$3, pow: pow$1, PI: PI$2 } = Math;
46
+ const { round: round$3, pow: pow$1, PI: PI$1 } = Math;
47
47
  const MathHelper = {
48
48
  within(value, min, max) {
49
49
  if (typeof min === 'object')
@@ -139,9 +139,9 @@ const MathHelper = {
139
139
  function randInt(num) {
140
140
  return Math.round(Math.random() * num);
141
141
  }
142
- const OneRadian = PI$2 / 180;
143
- const PI2 = PI$2 * 2;
144
- const PI_2 = PI$2 / 2;
142
+ const OneRadian = PI$1 / 180;
143
+ const PI2 = PI$1 * 2;
144
+ const PI_2 = PI$1 / 2;
145
145
  function getPointData() { return { x: 0, y: 0 }; }
146
146
  function getBoundsData() { return { x: 0, y: 0, width: 0, height: 0 }; }
147
147
  function getMatrixData() { return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }; }
@@ -436,7 +436,7 @@ const MatrixHelper = {
436
436
  const M$6 = MatrixHelper;
437
437
 
438
438
  const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
439
- 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;
439
+ const { sin: sin$2, cos: cos$2, abs: abs$2, sqrt: sqrt$2, atan2: atan2$2, min: min$1, round: round$2 } = Math;
440
440
  const PointHelper = {
441
441
  defaultPoint: getPointData(),
442
442
  tempPoint: {},
@@ -549,10 +549,11 @@ const PointHelper = {
549
549
  getRadianFrom(fromX, fromY, originX, originY, toX, toY, toOriginX, toOriginY) {
550
550
  if (toOriginX === undefined)
551
551
  toOriginX = originX, toOriginY = originY;
552
- let fromAngle = atan2$2(fromY - originY, fromX - originX);
553
- let toAngle = atan2$2(toY - toOriginY, toX - toOriginX);
554
- const radian = toAngle - fromAngle;
555
- return radian < -PI$1 ? radian + PI2 : radian;
552
+ const a = fromX - originX;
553
+ const b = fromY - originY;
554
+ const c = toX - toOriginX;
555
+ const d = toY - toOriginY;
556
+ return Math.atan2(a * d - b * c, a * c + b * d);
556
557
  },
557
558
  getAtan2(t, to) {
558
559
  return atan2$2(to.y - t.y, to.x - t.x);
@@ -859,6 +860,12 @@ const AroundHelper = {
859
860
  }
860
861
  if (!onlyBoxSize)
861
862
  to.x += box.x, to.y += box.y;
863
+ },
864
+ getPoint(around, box, to) {
865
+ if (!to)
866
+ to = {};
867
+ AroundHelper.toPoint(around, box, to, true);
868
+ return to;
862
869
  }
863
870
  };
864
871
  function get(around) {
@@ -1787,10 +1794,13 @@ function contextAttr(realName) {
1787
1794
  return (target, key) => {
1788
1795
  if (!realName)
1789
1796
  realName = key;
1790
- Object.defineProperty(target, key, {
1797
+ const property = {
1791
1798
  get() { return this.context[realName]; },
1792
1799
  set(value) { this.context[realName] = value; }
1793
- });
1800
+ };
1801
+ if (key === 'strokeCap')
1802
+ property.set = function (value) { this.context[realName] = value === 'none' ? 'butt' : value; };
1803
+ Object.defineProperty(target, key, property);
1794
1804
  };
1795
1805
  }
1796
1806
  const contextMethodNameList = [];
@@ -2073,8 +2083,8 @@ class LeaferCanvasBase extends Canvas {
2073
2083
  get width() { return this.size.width; }
2074
2084
  get height() { return this.size.height; }
2075
2085
  get pixelRatio() { return this.size.pixelRatio; }
2076
- get pixelWidth() { return this.width * this.pixelRatio; }
2077
- get pixelHeight() { return this.height * this.pixelRatio; }
2086
+ get pixelWidth() { return this.width * this.pixelRatio || 0; }
2087
+ get pixelHeight() { return this.height * this.pixelRatio || 0; }
2078
2088
  get pixelSnap() { return this.config.pixelSnap; }
2079
2089
  set pixelSnap(value) { this.config.pixelSnap = value; }
2080
2090
  get allowBackgroundColor() { return this.view && this.parentView; }
@@ -2161,20 +2171,33 @@ class LeaferCanvasBase extends Canvas {
2161
2171
  if (w)
2162
2172
  this.setTransform(w.a, w.b, w.c, w.d, w.e, w.f);
2163
2173
  }
2164
- setStroke(color, strokeWidth, options) {
2174
+ setStroke(color, strokeWidth, options, childOptions) {
2165
2175
  if (strokeWidth)
2166
2176
  this.strokeWidth = strokeWidth;
2167
2177
  if (color)
2168
2178
  this.strokeStyle = color;
2169
2179
  if (options)
2170
- this.setStrokeOptions(options);
2171
- }
2172
- setStrokeOptions(options) {
2173
- this.strokeCap = options.strokeCap === 'none' ? 'butt' : options.strokeCap;
2174
- this.strokeJoin = options.strokeJoin;
2175
- this.dashPattern = options.dashPattern;
2176
- this.dashOffset = options.dashOffset;
2177
- this.miterLimit = options.miterLimit;
2180
+ this.setStrokeOptions(options, childOptions);
2181
+ }
2182
+ setStrokeOptions(options, childOptions) {
2183
+ let { strokeCap, strokeJoin, dashPattern, dashOffset, miterLimit } = options;
2184
+ if (childOptions) {
2185
+ if (childOptions.strokeCap)
2186
+ strokeCap = childOptions.strokeCap;
2187
+ if (childOptions.strokeJoin)
2188
+ strokeJoin = childOptions.strokeJoin;
2189
+ if (childOptions.dashPattern !== undefined)
2190
+ dashPattern = childOptions.dashPattern;
2191
+ if (childOptions.dashOffset !== undefined)
2192
+ dashOffset = childOptions.dashOffset;
2193
+ if (childOptions.miterLimit)
2194
+ miterLimit = childOptions.miterLimit;
2195
+ }
2196
+ this.strokeCap = strokeCap;
2197
+ this.strokeJoin = strokeJoin;
2198
+ this.dashPattern = dashPattern;
2199
+ this.dashOffset = dashOffset;
2200
+ this.miterLimit = miterLimit;
2178
2201
  }
2179
2202
  saveBlendMode(blendMode) {
2180
2203
  this.savedBlendMode = this.blendMode;
@@ -3339,7 +3362,7 @@ const { getCenterX, getCenterY } = PointHelper;
3339
3362
  const { arcTo } = PathCommandDataHelper;
3340
3363
  const PathCorner = {
3341
3364
  smooth(data, cornerRadius, _cornerSmoothing) {
3342
- let command, commandLen;
3365
+ let command, lastCommand, commandLen;
3343
3366
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0;
3344
3367
  const len = data.length;
3345
3368
  const smooth = [];
@@ -3377,8 +3400,10 @@ const PathCorner = {
3377
3400
  lastY = y;
3378
3401
  break;
3379
3402
  case Z:
3380
- arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3381
- smooth.push(Z);
3403
+ if (lastCommand !== Z) {
3404
+ arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3405
+ smooth.push(Z);
3406
+ }
3382
3407
  i += 1;
3383
3408
  break;
3384
3409
  default:
@@ -3387,6 +3412,7 @@ const PathCorner = {
3387
3412
  smooth.push(data[i + j]);
3388
3413
  i += commandLen;
3389
3414
  }
3415
+ lastCommand = command;
3390
3416
  }
3391
3417
  if (command !== Z) {
3392
3418
  smooth[1] = startX;
@@ -3883,12 +3909,12 @@ class LeaferImage {
3883
3909
  try {
3884
3910
  if (transform && pattern.setTransform) {
3885
3911
  pattern.setTransform(transform);
3886
- transform = null;
3912
+ transform = undefined;
3887
3913
  }
3888
3914
  }
3889
3915
  catch (_a) { }
3890
3916
  if (paint)
3891
- paint.transform = transform;
3917
+ DataHelper.stintSet(paint, 'transform', transform);
3892
3918
  return pattern;
3893
3919
  }
3894
3920
  destroy() {
@@ -3906,6 +3932,13 @@ function defineKey(target, key, descriptor, noConfigurable) {
3906
3932
  function getDescriptor(object, name) {
3907
3933
  return Object.getOwnPropertyDescriptor(object, name);
3908
3934
  }
3935
+ function createDescriptor(key, defaultValue) {
3936
+ const privateKey = '_' + key;
3937
+ return {
3938
+ get() { const v = this[privateKey]; return v === undefined ? defaultValue : v; },
3939
+ set(value) { this[privateKey] = value; }
3940
+ };
3941
+ }
3909
3942
  function getNames(object) {
3910
3943
  return Object.getOwnPropertyNames(object);
3911
3944
  }
@@ -3993,10 +4026,14 @@ function pathInputType(defaultValue) {
3993
4026
  }));
3994
4027
  }
3995
4028
  const pathType = boundsType;
3996
- function affectStrokeBoundsType(defaultValue) {
4029
+ function affectStrokeBoundsType(defaultValue, useStroke) {
3997
4030
  return decorateLeafAttr(defaultValue, (key) => attr({
3998
4031
  set(value) {
3999
- this.__setAttr(key, value) && doStrokeType(this);
4032
+ if (this.__setAttr(key, value)) {
4033
+ doStrokeType(this);
4034
+ if (useStroke)
4035
+ this.__.__useStroke = true;
4036
+ }
4000
4037
  }
4001
4038
  }));
4002
4039
  }
@@ -4134,15 +4171,7 @@ function defineDataProcessor(target, key, defaultValue) {
4134
4171
  const data = target.__DataProcessor.prototype;
4135
4172
  const computedKey = '_' + key;
4136
4173
  const setMethodName = getSetMethodName(key);
4137
- const property = {
4138
- get() {
4139
- const v = this[computedKey];
4140
- return v === undefined ? defaultValue : v;
4141
- },
4142
- set(value) {
4143
- this[computedKey] = value;
4144
- }
4145
- };
4174
+ const property = createDescriptor(key, defaultValue);
4146
4175
  if (defaultValue === undefined) {
4147
4176
  property.get = function () { return this[computedKey]; };
4148
4177
  }
@@ -4329,6 +4358,14 @@ const LeafHelper = {
4329
4358
  }
4330
4359
  return true;
4331
4360
  },
4361
+ copyCanvasByWorld(leaf, currentCanvas, fromCanvas, fromWorld, blendMode, onlyResetTransform) {
4362
+ if (!fromWorld)
4363
+ fromWorld = leaf.__nowWorld;
4364
+ if (leaf.__worldFlipped || Platform.fullImageShadow)
4365
+ currentCanvas.copyWorldByReset(fromCanvas, fromWorld, leaf.__nowWorld, blendMode, onlyResetTransform);
4366
+ else
4367
+ currentCanvas.copyWorldToInner(fromCanvas, fromWorld, leaf.__layout.renderBounds, blendMode);
4368
+ },
4332
4369
  moveWorld(t, x, y = 0, isInnerPoint, transition) {
4333
4370
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4334
4371
  isInnerPoint ? toOuterPoint$1(t.localTransform, local, local, true) : (t.parent && toInnerPoint$1(t.parent.worldTransform, local, local, true));
@@ -5261,13 +5298,14 @@ const { setLayout, multiplyParent: multiplyParent$1, translateInner, defaultWorl
5261
5298
  const { toPoint, tempPoint } = AroundHelper;
5262
5299
  const LeafMatrix = {
5263
5300
  __updateWorldMatrix() {
5264
- multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__, this.parent && this.parent.__);
5301
+ const { parent, __layout } = this;
5302
+ multiplyParent$1(this.__local || __layout, parent ? parent.__world : defaultWorld, this.__world, !!__layout.affectScaleOrRotation, this.__, parent && (parent.scrollY || parent.scrollX) && parent.__);
5265
5303
  },
5266
5304
  __updateLocalMatrix() {
5267
5305
  if (this.__local) {
5268
5306
  const layout = this.__layout, local = this.__local, data = this.__;
5269
5307
  if (layout.affectScaleOrRotation) {
5270
- if ((layout.scaleChanged && (layout.resized = 'scale')) || layout.rotationChanged) {
5308
+ if ((layout.scaleChanged && (layout.resized || (layout.resized = 'scale'))) || layout.rotationChanged) {
5271
5309
  setLayout(local, data, null, null, layout.affectRotation);
5272
5310
  layout.scaleChanged = layout.rotationChanged = undefined;
5273
5311
  }
@@ -5422,6 +5460,8 @@ const LeafBounds = {
5422
5460
 
5423
5461
  const LeafRender = {
5424
5462
  __render(canvas, options) {
5463
+ if (options.shape)
5464
+ return this.__renderShape(canvas, options);
5425
5465
  if (this.__worldOpacity) {
5426
5466
  const data = this.__;
5427
5467
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
@@ -5431,12 +5471,7 @@ const LeafRender = {
5431
5471
  return this.__renderEraser(canvas, options);
5432
5472
  const tempCanvas = canvas.getSameCanvas(true, true);
5433
5473
  this.__draw(tempCanvas, options, canvas);
5434
- if (this.__worldFlipped) {
5435
- canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, data.__blendMode, true);
5436
- }
5437
- else {
5438
- canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, data.__blendMode);
5439
- }
5474
+ LeafHelper.copyCanvasByWorld(this, canvas, tempCanvas, this.__nowWorld, data.__blendMode, true);
5440
5475
  tempCanvas.recycle(this.__nowWorld);
5441
5476
  }
5442
5477
  else {
@@ -5446,6 +5481,12 @@ const LeafRender = {
5446
5481
  Debug.drawBounds(this, canvas, options);
5447
5482
  }
5448
5483
  },
5484
+ __renderShape(canvas, options) {
5485
+ if (this.__worldOpacity) {
5486
+ canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5487
+ this.__drawShape(canvas, options);
5488
+ }
5489
+ },
5449
5490
  __clip(canvas, options) {
5450
5491
  if (this.__worldOpacity) {
5451
5492
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
@@ -5478,7 +5519,7 @@ const BranchRender = {
5478
5519
  options.dimOpacity = data.dim === true ? 0.2 : data.dim;
5479
5520
  else if (data.dimskip)
5480
5521
  options.dimOpacity && (options.dimOpacity = 0);
5481
- if (data.__single) {
5522
+ if (data.__single && !this.isBranchLeaf) {
5482
5523
  if (data.eraser === 'path')
5483
5524
  return this.__renderEraser(canvas, options);
5484
5525
  const tempCanvas = canvas.getSameCanvas(false, true);
@@ -5500,9 +5541,7 @@ const BranchRender = {
5500
5541
  else {
5501
5542
  const { children } = this;
5502
5543
  for (let i = 0, len = children.length; i < len; i++) {
5503
- if (excludeRenderBounds(children[i], options))
5504
- continue;
5505
- children[i].__render(canvas, options);
5544
+ excludeRenderBounds(children[i], options) || children[i].__render(canvas, options);
5506
5545
  }
5507
5546
  }
5508
5547
  },
@@ -5510,14 +5549,13 @@ const BranchRender = {
5510
5549
  if (this.__worldOpacity) {
5511
5550
  const { children } = this;
5512
5551
  for (let i = 0, len = children.length; i < len; i++) {
5513
- if (excludeRenderBounds(children[i], options))
5514
- continue;
5515
- children[i].__clip(canvas, options);
5552
+ excludeRenderBounds(children[i], options) || children[i].__clip(canvas, options);
5516
5553
  }
5517
5554
  }
5518
5555
  }
5519
5556
  };
5520
5557
 
5558
+ const tempScaleData = {};
5521
5559
  const { LEAF, create } = IncrementId;
5522
5560
  const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper;
5523
5561
  const { toOuterOf } = BoundsHelper;
@@ -5710,6 +5748,22 @@ let Leaf = class Leaf {
5710
5748
  return this.__world;
5711
5749
  }
5712
5750
  }
5751
+ getClampRenderScale() {
5752
+ let { scaleX } = this.__nowWorld || this.__world;
5753
+ if (scaleX < 0)
5754
+ scaleX = -scaleX;
5755
+ return scaleX > 1 ? scaleX : 1;
5756
+ }
5757
+ getRenderScaleData(abs, scaleFixed) {
5758
+ const { scaleX, scaleY } = ImageManager.patternLocked ? this.__world : this.__nowWorld;
5759
+ if (scaleFixed)
5760
+ tempScaleData.scaleX = tempScaleData.scaleY = 1;
5761
+ else if (abs)
5762
+ tempScaleData.scaleX = scaleX < 0 ? -scaleX : scaleX, tempScaleData.scaleY = scaleY < 0 ? -scaleY : scaleY;
5763
+ else
5764
+ tempScaleData.scaleX = scaleX, tempScaleData.scaleY = scaleY;
5765
+ return tempScaleData;
5766
+ }
5713
5767
  getTransform(relative) {
5714
5768
  return this.__layout.getTransform(relative || 'local');
5715
5769
  }
@@ -5865,7 +5919,8 @@ let Leaf = class Leaf {
5865
5919
  __drawFast(_canvas, _options) { }
5866
5920
  __draw(_canvas, _options, _originCanvas) { }
5867
5921
  __clip(_canvas, _options) { }
5868
- __renderShape(_canvas, _options, _ignoreFill, _ignoreStroke) { }
5922
+ __renderShape(_canvas, _options) { }
5923
+ __drawShape(_canvas, _options) { }
5869
5924
  __updateWorldOpacity() { }
5870
5925
  __updateChange() { }
5871
5926
  __drawPath(_canvas) { }
@@ -6233,6 +6288,6 @@ class LeafLevelList {
6233
6288
  }
6234
6289
  }
6235
6290
 
6236
- const version = "1.6.7";
6291
+ const version = "1.8.0";
6237
6292
 
6238
- export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, 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 };
6293
+ export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, 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, createDescriptor, 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 };