leafer-ui 1.0.9 → 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.
@@ -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$f.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$f.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] ? debug$e.repeat(name) : nameList[name] = Event;
1444
+ nameList[name] && debug$e.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
- 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$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
- tempBounds$1.set(bounds).scale(this.pixelRatio);
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
- tempBounds$1.set(bounds).scale(this.pixelRatio);
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
- tempBounds$1.set(bounds).scale(this.pixelRatio);
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
- tempBounds$1.set(bounds).scale(this.pixelRatio);
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.__getNowWorld(options);
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.9";
5978
+ const version = "1.0.10";
5963
5979
 
5964
5980
  const debug$7 = Debug.get('LeaferCanvas');
5965
5981
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6601,7 +6617,8 @@ class Renderer {
6601
6617
  this.totalBounds = new Bounds();
6602
6618
  debug$5.log(target.innerName, '--->');
6603
6619
  try {
6604
- target.app.emit(RenderEvent.CHILD_START, target);
6620
+ if (!target.isApp)
6621
+ target.app.emit(RenderEvent.CHILD_START, target);
6605
6622
  this.emitRender(RenderEvent.START);
6606
6623
  this.renderOnce(callback);
6607
6624
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -7155,6 +7172,12 @@ class UIData extends LeafData {
7155
7172
  return strokeWidth;
7156
7173
  }
7157
7174
  get __hasStroke() { return this.stroke && this.strokeWidth; }
7175
+ get __hasMultiPaint() {
7176
+ const t = this;
7177
+ if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
7178
+ return true;
7179
+ return t.fill && this.__hasStroke;
7180
+ }
7158
7181
  get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
7159
7182
  get __autoWidth() { return !this._width; }
7160
7183
  get __autoHeight() { return !this._height; }
@@ -7524,9 +7547,8 @@ const RectRender = {
7524
7547
  canvas.strokeRect(half, half, width, height);
7525
7548
  canvas.restore();
7526
7549
  }
7527
- else {
7550
+ else
7528
7551
  canvas.strokeRect(half, half, width, height);
7529
- }
7530
7552
  break;
7531
7553
  case 'outside':
7532
7554
  canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
@@ -7751,6 +7773,15 @@ __decorate([
7751
7773
  __decorate([
7752
7774
  boundsType(0)
7753
7775
  ], UI.prototype, "padding", void 0);
7776
+ __decorate([
7777
+ boundsType(false)
7778
+ ], UI.prototype, "lockRatio", void 0);
7779
+ __decorate([
7780
+ boundsType()
7781
+ ], UI.prototype, "widthRange", void 0);
7782
+ __decorate([
7783
+ boundsType()
7784
+ ], UI.prototype, "heightRange", void 0);
7754
7785
  __decorate([
7755
7786
  dataType(false)
7756
7787
  ], UI.prototype, "draggable", void 0);
@@ -8042,8 +8073,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8042
8073
  __onResize(event) {
8043
8074
  this.emitEvent(event);
8044
8075
  DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
8045
- if (!event.width || !event.height)
8046
- debug$3.warn('w = 0 or h = 0');
8047
8076
  setTimeout(() => { if (this.canvasManager)
8048
8077
  this.canvasManager.clearRecycled(); }, 0);
8049
8078
  }
@@ -8368,9 +8397,6 @@ __decorate([
8368
8397
  __decorate([
8369
8398
  dataType(false)
8370
8399
  ], Box.prototype, "resizeChildren", void 0);
8371
- __decorate([
8372
- dataType(false)
8373
- ], Box.prototype, "textBox", void 0);
8374
8400
  __decorate([
8375
8401
  affectRenderBoundsType('show')
8376
8402
  ], Box.prototype, "overflow", void 0);
@@ -9125,19 +9151,13 @@ class UIEvent extends Event {
9125
9151
  Object.assign(this, params);
9126
9152
  }
9127
9153
  getBoxPoint(relative) {
9128
- if (!relative)
9129
- relative = this.current;
9130
- return relative.getBoxPoint(this);
9154
+ return (relative || this.current).getBoxPoint(this);
9131
9155
  }
9132
9156
  getInnerPoint(relative) {
9133
- if (!relative)
9134
- relative = this.current;
9135
- return relative.getInnerPoint(this);
9157
+ return (relative || this.current).getInnerPoint(this);
9136
9158
  }
9137
9159
  getLocalPoint(relative) {
9138
- if (!relative)
9139
- relative = this.current;
9140
- return relative.getLocalPoint(this);
9160
+ return (relative || this.current).getLocalPoint(this);
9141
9161
  }
9142
9162
  getPagePoint() {
9143
9163
  return this.current.getPagePoint(this);
@@ -9371,7 +9391,8 @@ const debug$2 = Debug.get('LeaferTypeCreator');
9371
9391
  const LeaferTypeCreator = {
9372
9392
  list: {},
9373
9393
  register(name, fn) {
9374
- list[name] ? debug$2.repeat(name) : list[name] = fn;
9394
+ list[name] && debug$2.repeat(name);
9395
+ list[name] = fn;
9375
9396
  },
9376
9397
  run(name, leafer) {
9377
9398
  const fn = list[name];
@@ -11739,16 +11760,16 @@ const EffectModule = {
11739
11760
 
11740
11761
  const { excludeRenderBounds } = LeafBoundsHelper;
11741
11762
  Group.prototype.__renderMask = function (canvas, options) {
11742
- let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
11763
+ let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
11743
11764
  const { children } = this;
11744
11765
  for (let i = 0, len = children.length; i < len; i++) {
11745
- child = children[i];
11746
- if (child.__.mask) {
11766
+ child = children[i], mask = child.__.mask;
11767
+ if (mask) {
11747
11768
  if (currentMask) {
11748
11769
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
11749
11770
  maskCanvas = contentCanvas = null;
11750
11771
  }
11751
- if (child.__.mask === 'path') {
11772
+ if (mask === 'path' || mask === 'clipping-path') {
11752
11773
  if (child.opacity < 1) {
11753
11774
  currentMask = 'opacity-path';
11754
11775
  maskOpacity = child.opacity;
@@ -11762,14 +11783,14 @@ Group.prototype.__renderMask = function (canvas, options) {
11762
11783
  child.__clip(contentCanvas || canvas, options);
11763
11784
  }
11764
11785
  else {
11765
- currentMask = 'alpha';
11786
+ currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
11766
11787
  if (!maskCanvas)
11767
11788
  maskCanvas = getCanvas(canvas);
11768
11789
  if (!contentCanvas)
11769
11790
  contentCanvas = getCanvas(canvas);
11770
11791
  child.__render(maskCanvas, options);
11771
11792
  }
11772
- if (child.__.mask !== 'clipping')
11793
+ if (!(mask === 'clipping' || mask === 'clipping-path'))
11773
11794
  continue;
11774
11795
  }
11775
11796
  if (excludeRenderBounds(child, options))
@@ -11780,6 +11801,8 @@ Group.prototype.__renderMask = function (canvas, options) {
11780
11801
  };
11781
11802
  function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
11782
11803
  switch (maskMode) {
11804
+ case 'grayscale':
11805
+ maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
11783
11806
  case 'alpha':
11784
11807
  usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
11785
11808
  break;
@@ -12484,15 +12507,12 @@ const canvas = LeaferCanvasBase.prototype;
12484
12507
  const debug = Debug.get('@leafer-ui/export');
12485
12508
  canvas.export = function (filename, options) {
12486
12509
  const { quality, blob } = FileHelper.getExportOptions(options);
12487
- if (filename.includes('.')) {
12510
+ if (filename.includes('.'))
12488
12511
  return this.saveAs(filename, quality);
12489
- }
12490
- else if (blob) {
12512
+ else if (blob)
12491
12513
  return this.toBlob(filename, quality);
12492
- }
12493
- else {
12514
+ else
12494
12515
  return this.toDataURL(filename, quality);
12495
- }
12496
12516
  };
12497
12517
  canvas.toBlob = function (type, quality) {
12498
12518
  return new Promise((resolve) => {