@leafer/core 1.0.9 → 1.1.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.cjs CHANGED
@@ -110,7 +110,7 @@ const MathHelper = {
110
110
  return rotation - oldRotation;
111
111
  },
112
112
  float(num, maxLength) {
113
- const a = maxLength ? pow$1(10, maxLength) : 1000000000000;
113
+ const a = maxLength !== undefined ? pow$1(10, maxLength) : 1000000000000;
114
114
  num = round(num * a) / a;
115
115
  return num === -0 ? 0 : num;
116
116
  },
@@ -1413,14 +1413,13 @@ const UICreator = {
1413
1413
  list: {},
1414
1414
  register(UI) {
1415
1415
  const { __tag: tag } = UI.prototype;
1416
- if (list$1[tag]) {
1416
+ if (list$1[tag])
1417
1417
  debug$7.repeat(tag);
1418
- }
1419
- else {
1420
- list$1[tag] = UI;
1421
- }
1418
+ list$1[tag] = UI;
1422
1419
  },
1423
1420
  get(tag, data, x, y, width, height) {
1421
+ if (!list$1[tag])
1422
+ debug$7.error('not register ' + tag);
1424
1423
  const ui = new list$1[tag](data);
1425
1424
  if (x !== undefined) {
1426
1425
  ui.x = x;
@@ -1444,7 +1443,7 @@ const EventCreator = {
1444
1443
  Object.keys(Event).forEach(key => {
1445
1444
  name = Event[key];
1446
1445
  if (typeof name === 'string')
1447
- nameList[name] ? debug$6.repeat(name) : nameList[name] = Event;
1446
+ nameList[name] && debug$6.repeat(name), nameList[name] = Event;
1448
1447
  });
1449
1448
  },
1450
1449
  changeName(oldName, newName) {
@@ -1646,7 +1645,7 @@ class LeafData {
1646
1645
  const t = this;
1647
1646
  if (t.blendMode === 'pass-through') {
1648
1647
  const leaf = this.__leaf;
1649
- if ((t.opacity < 1 && leaf.isBranch) || leaf.__hasEraser || t.eraser) {
1648
+ if ((t.opacity < 1 && (leaf.isBranch || t.__hasMultiPaint)) || leaf.__hasEraser || t.eraser) {
1650
1649
  t.__single = true;
1651
1650
  }
1652
1651
  else if (t.__single) {
@@ -2044,8 +2043,9 @@ class LeaferCanvasBase extends Canvas {
2044
2043
  takeCanvas = this.getSameCanvas();
2045
2044
  takeCanvas.copyWorld(this);
2046
2045
  }
2047
- DataHelper.copyAttrs(this.size, size, canvasSizeAttrs);
2048
- this.size.pixelRatio || (this.size.pixelRatio = 1);
2046
+ const s = this.size;
2047
+ DataHelper.copyAttrs(s, size, canvasSizeAttrs);
2048
+ canvasSizeAttrs.forEach(key => s[key] || (s[key] = 1));
2049
2049
  this.bounds = new Bounds(0, 0, this.width, this.height);
2050
2050
  if (this.context && !this.unreal) {
2051
2051
  this.updateViewSize();
@@ -2159,6 +2159,17 @@ class LeaferCanvasBase extends Canvas {
2159
2159
  if (!onlyResetTransform)
2160
2160
  this.useWorldTransform();
2161
2161
  }
2162
+ useGrayscaleAlpha(bounds) {
2163
+ this.setTempBounds(bounds, true, true);
2164
+ let alpha, pixel;
2165
+ const { context } = this, imageData = context.getImageData(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height), { data } = imageData;
2166
+ for (let i = 0, len = data.length; i < len; i += 4) {
2167
+ pixel = data[i] * 0.299 + data[i + 1] * 0.587 + data[i + 2] * 0.114;
2168
+ if (alpha = data[i + 3])
2169
+ data[i + 3] = alpha === 255 ? pixel : alpha * (pixel / 255);
2170
+ }
2171
+ context.putImageData(imageData, tempBounds.x, tempBounds.y);
2172
+ }
2162
2173
  useMask(maskCanvas, fromBounds, toBounds) {
2163
2174
  this.copyWorld(maskCanvas, fromBounds, toBounds, 'destination-in');
2164
2175
  }
@@ -2169,7 +2180,7 @@ class LeaferCanvasBase extends Canvas {
2169
2180
  if (blendMode)
2170
2181
  this.blendMode = blendMode;
2171
2182
  this.fillStyle = color;
2172
- tempBounds.set(bounds).scale(this.pixelRatio);
2183
+ this.setTempBounds(bounds);
2173
2184
  this.fillRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
2174
2185
  if (blendMode)
2175
2186
  this.blendMode = 'source-over';
@@ -2178,22 +2189,18 @@ class LeaferCanvasBase extends Canvas {
2178
2189
  if (blendMode)
2179
2190
  this.blendMode = blendMode;
2180
2191
  this.strokeStyle = color;
2181
- tempBounds.set(bounds).scale(this.pixelRatio);
2192
+ this.setTempBounds(bounds);
2182
2193
  this.strokeRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
2183
2194
  if (blendMode)
2184
2195
  this.blendMode = 'source-over';
2185
2196
  }
2186
2197
  clearWorld(bounds, ceilPixel) {
2187
- tempBounds.set(bounds).scale(this.pixelRatio);
2188
- if (ceilPixel)
2189
- tempBounds.ceil();
2198
+ this.setTempBounds(bounds, ceilPixel);
2190
2199
  this.clearRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
2191
2200
  }
2192
2201
  clipWorld(bounds, ceilPixel) {
2193
2202
  this.beginPath();
2194
- tempBounds.set(bounds).scale(this.pixelRatio);
2195
- if (ceilPixel)
2196
- tempBounds.ceil();
2203
+ this.setTempBounds(bounds, ceilPixel);
2197
2204
  this.rect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
2198
2205
  this.clip();
2199
2206
  }
@@ -2201,6 +2208,14 @@ class LeaferCanvasBase extends Canvas {
2201
2208
  const { pixelRatio } = this;
2202
2209
  this.clearRect(0, 0, this.width * pixelRatio + 2, this.height * pixelRatio + 2);
2203
2210
  }
2211
+ setTempBounds(bounds, ceil, intersect) {
2212
+ tempBounds.set(bounds);
2213
+ if (intersect)
2214
+ tempBounds.intersect(this.bounds);
2215
+ tempBounds.scale(this.pixelRatio);
2216
+ if (ceil)
2217
+ tempBounds.ceil();
2218
+ }
2204
2219
  isSameSize(size) {
2205
2220
  return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
2206
2221
  }
@@ -4152,20 +4167,17 @@ const LeafHelper = {
4152
4167
  }
4153
4168
  return true;
4154
4169
  },
4155
- moveWorld(t, x, y = 0, isInnerPoint) {
4170
+ moveWorld(t, x, y = 0, isInnerPoint, transition) {
4156
4171
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4157
4172
  isInnerPoint ? toOuterPoint$1(t.localTransform, local, local, true) : (t.parent && toInnerPoint$1(t.parent.worldTransform, local, local, true));
4158
- L.moveLocal(t, local.x, local.y);
4173
+ L.moveLocal(t, local.x, local.y, transition);
4159
4174
  },
4160
- moveLocal(t, x, y = 0) {
4161
- if (typeof x === 'object') {
4162
- t.x += x.x;
4163
- t.y += x.y;
4164
- }
4165
- else {
4166
- t.x += x;
4167
- t.y += y;
4168
- }
4175
+ moveLocal(t, x, y = 0, transition) {
4176
+ if (typeof x === 'object')
4177
+ y = x.y, x = x.x;
4178
+ x += t.x;
4179
+ y += t.y;
4180
+ transition ? t.animate({ x, y }, transition) : (t.x = x, t.y = y);
4169
4181
  },
4170
4182
  zoomOfWorld(t, origin, scaleX, scaleY, resize) {
4171
4183
  L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
@@ -5214,13 +5226,14 @@ const BranchRender = {
5214
5226
  this.__.__checkSingle();
5215
5227
  },
5216
5228
  __render(canvas, options) {
5229
+ this.__nowWorld = this.__getNowWorld(options);
5217
5230
  if (this.__worldOpacity) {
5218
5231
  if (this.__.__single) {
5219
5232
  if (this.__.eraser === 'path')
5220
5233
  return this.__renderEraser(canvas, options);
5221
5234
  const tempCanvas = canvas.getSameCanvas(false, true);
5222
5235
  this.__renderBranch(tempCanvas, options);
5223
- const nowWorld = this.__getNowWorld(options);
5236
+ const nowWorld = this.__nowWorld;
5224
5237
  canvas.opacity = this.__.opacity;
5225
5238
  canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, this.__.__blendMode, true);
5226
5239
  tempCanvas.recycle(nowWorld);
@@ -5544,11 +5557,11 @@ exports.Leaf = class Leaf {
5544
5557
  transform(matrix, resize) {
5545
5558
  transform(this, matrix, resize);
5546
5559
  }
5547
- move(x, y) {
5548
- moveLocal(this, x, y);
5560
+ move(x, y, transition) {
5561
+ moveLocal(this, x, y, transition);
5549
5562
  }
5550
- moveInner(x, y) {
5551
- moveWorld(this, x, y, true);
5563
+ moveInner(x, y, transition) {
5564
+ moveWorld(this, x, y, true, transition);
5552
5565
  }
5553
5566
  scaleOf(origin, scaleX, scaleY, resize) {
5554
5567
  zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
@@ -5562,8 +5575,8 @@ exports.Leaf = class Leaf {
5562
5575
  transformWorld(worldTransform, resize) {
5563
5576
  transformWorld(this, worldTransform, resize);
5564
5577
  }
5565
- moveWorld(x, y) {
5566
- moveWorld(this, x, y);
5578
+ moveWorld(x, y, transition) {
5579
+ moveWorld(this, x, y, false, transition);
5567
5580
  }
5568
5581
  scaleOfWorld(worldOrigin, scaleX, scaleY, resize) {
5569
5582
  zoomOfWorld(this, worldOrigin, scaleX, scaleY, resize);
@@ -5961,7 +5974,7 @@ class LeafLevelList {
5961
5974
  }
5962
5975
  }
5963
5976
 
5964
- const version = "1.0.9";
5977
+ const version = "1.1.0";
5965
5978
 
5966
5979
  exports.AlignHelper = AlignHelper;
5967
5980
  exports.AroundHelper = AroundHelper;
package/lib/core.esm.js CHANGED
@@ -108,7 +108,7 @@ const MathHelper = {
108
108
  return rotation - oldRotation;
109
109
  },
110
110
  float(num, maxLength) {
111
- const a = maxLength ? pow$1(10, maxLength) : 1000000000000;
111
+ const a = maxLength !== undefined ? pow$1(10, maxLength) : 1000000000000;
112
112
  num = round(num * a) / a;
113
113
  return num === -0 ? 0 : num;
114
114
  },
@@ -1411,14 +1411,13 @@ const UICreator = {
1411
1411
  list: {},
1412
1412
  register(UI) {
1413
1413
  const { __tag: tag } = UI.prototype;
1414
- if (list$1[tag]) {
1414
+ if (list$1[tag])
1415
1415
  debug$7.repeat(tag);
1416
- }
1417
- else {
1418
- list$1[tag] = UI;
1419
- }
1416
+ list$1[tag] = UI;
1420
1417
  },
1421
1418
  get(tag, data, x, y, width, height) {
1419
+ if (!list$1[tag])
1420
+ debug$7.error('not register ' + tag);
1422
1421
  const ui = new list$1[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] ? debug$6.repeat(name) : nameList[name] = Event;
1444
+ nameList[name] && debug$6.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 {
2042
2041
  takeCanvas = this.getSameCanvas();
2043
2042
  takeCanvas.copyWorld(this);
2044
2043
  }
2045
- DataHelper.copyAttrs(this.size, size, canvasSizeAttrs);
2046
- this.size.pixelRatio || (this.size.pixelRatio = 1);
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 {
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.x, tempBounds.y, tempBounds.width, tempBounds.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.x, tempBounds.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 {
2167
2178
  if (blendMode)
2168
2179
  this.blendMode = blendMode;
2169
2180
  this.fillStyle = color;
2170
- tempBounds.set(bounds).scale(this.pixelRatio);
2181
+ this.setTempBounds(bounds);
2171
2182
  this.fillRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
2172
2183
  if (blendMode)
2173
2184
  this.blendMode = 'source-over';
@@ -2176,22 +2187,18 @@ class LeaferCanvasBase extends Canvas {
2176
2187
  if (blendMode)
2177
2188
  this.blendMode = blendMode;
2178
2189
  this.strokeStyle = color;
2179
- tempBounds.set(bounds).scale(this.pixelRatio);
2190
+ this.setTempBounds(bounds);
2180
2191
  this.strokeRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
2181
2192
  if (blendMode)
2182
2193
  this.blendMode = 'source-over';
2183
2194
  }
2184
2195
  clearWorld(bounds, ceilPixel) {
2185
- tempBounds.set(bounds).scale(this.pixelRatio);
2186
- if (ceilPixel)
2187
- tempBounds.ceil();
2196
+ this.setTempBounds(bounds, ceilPixel);
2188
2197
  this.clearRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
2189
2198
  }
2190
2199
  clipWorld(bounds, ceilPixel) {
2191
2200
  this.beginPath();
2192
- tempBounds.set(bounds).scale(this.pixelRatio);
2193
- if (ceilPixel)
2194
- tempBounds.ceil();
2201
+ this.setTempBounds(bounds, ceilPixel);
2195
2202
  this.rect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
2196
2203
  this.clip();
2197
2204
  }
@@ -2199,6 +2206,14 @@ class LeaferCanvasBase extends Canvas {
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.set(bounds);
2211
+ if (intersect)
2212
+ tempBounds.intersect(this.bounds);
2213
+ tempBounds.scale(this.pixelRatio);
2214
+ if (ceil)
2215
+ tempBounds.ceil();
2216
+ }
2202
2217
  isSameSize(size) {
2203
2218
  return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
2204
2219
  }
@@ -4150,20 +4165,17 @@ const LeafHelper = {
4150
4165
  }
4151
4166
  return true;
4152
4167
  },
4153
- moveWorld(t, x, y = 0, isInnerPoint) {
4168
+ moveWorld(t, x, y = 0, isInnerPoint, transition) {
4154
4169
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4155
4170
  isInnerPoint ? toOuterPoint$1(t.localTransform, local, local, true) : (t.parent && toInnerPoint$1(t.parent.worldTransform, local, local, true));
4156
- L.moveLocal(t, local.x, local.y);
4171
+ L.moveLocal(t, local.x, local.y, transition);
4157
4172
  },
4158
- moveLocal(t, x, y = 0) {
4159
- if (typeof x === 'object') {
4160
- t.x += x.x;
4161
- t.y += x.y;
4162
- }
4163
- else {
4164
- t.x += x;
4165
- t.y += y;
4166
- }
4173
+ moveLocal(t, x, y = 0, transition) {
4174
+ if (typeof x === 'object')
4175
+ y = x.y, x = x.x;
4176
+ x += t.x;
4177
+ y += t.y;
4178
+ transition ? t.animate({ x, y }, transition) : (t.x = x, t.y = y);
4167
4179
  },
4168
4180
  zoomOfWorld(t, origin, scaleX, scaleY, resize) {
4169
4181
  L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
@@ -5212,13 +5224,14 @@ const BranchRender = {
5212
5224
  this.__.__checkSingle();
5213
5225
  },
5214
5226
  __render(canvas, options) {
5227
+ this.__nowWorld = this.__getNowWorld(options);
5215
5228
  if (this.__worldOpacity) {
5216
5229
  if (this.__.__single) {
5217
5230
  if (this.__.eraser === 'path')
5218
5231
  return this.__renderEraser(canvas, options);
5219
5232
  const tempCanvas = canvas.getSameCanvas(false, true);
5220
5233
  this.__renderBranch(tempCanvas, options);
5221
- const nowWorld = this.__getNowWorld(options);
5234
+ const nowWorld = this.__nowWorld;
5222
5235
  canvas.opacity = this.__.opacity;
5223
5236
  canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, this.__.__blendMode, true);
5224
5237
  tempCanvas.recycle(nowWorld);
@@ -5542,11 +5555,11 @@ let Leaf = class Leaf {
5542
5555
  transform(matrix, resize) {
5543
5556
  transform(this, matrix, resize);
5544
5557
  }
5545
- move(x, y) {
5546
- moveLocal(this, x, y);
5558
+ move(x, y, transition) {
5559
+ moveLocal(this, x, y, transition);
5547
5560
  }
5548
- moveInner(x, y) {
5549
- moveWorld(this, x, y, true);
5561
+ moveInner(x, y, transition) {
5562
+ moveWorld(this, x, y, true, transition);
5550
5563
  }
5551
5564
  scaleOf(origin, scaleX, scaleY, resize) {
5552
5565
  zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
@@ -5560,8 +5573,8 @@ let Leaf = class Leaf {
5560
5573
  transformWorld(worldTransform, resize) {
5561
5574
  transformWorld(this, worldTransform, resize);
5562
5575
  }
5563
- moveWorld(x, y) {
5564
- moveWorld(this, x, y);
5576
+ moveWorld(x, y, transition) {
5577
+ moveWorld(this, x, y, false, transition);
5565
5578
  }
5566
5579
  scaleOfWorld(worldOrigin, scaleX, scaleY, resize) {
5567
5580
  zoomOfWorld(this, worldOrigin, scaleX, scaleY, resize);
@@ -5959,6 +5972,6 @@ class LeafLevelList {
5959
5972
  }
5960
5973
  }
5961
5974
 
5962
- const version = "1.0.9";
5975
+ const version = "1.1.0";
5963
5976
 
5964
5977
  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, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, 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, isNull, layoutProcessor, maskType, naturalBoundsType, needPlugin, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, useModule, version, visibleType };