@leafer-editor/worker 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$3[tag]) {
1414
+ if (list$3[tag])
1415
1415
  debug$f.repeat(tag);
1416
- }
1417
- else {
1418
- list$3[tag] = UI;
1419
- }
1416
+ list$3[tag] = UI;
1420
1417
  },
1421
1418
  get(tag, data, x, y, width, height) {
1419
+ if (!list$3[tag])
1420
+ debug$f.error('not register ' + tag);
1422
1421
  const ui = new list$3[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
  class LeaferCanvas extends LeaferCanvasBase {
5965
5981
  get allowBackgroundColor() { return true; }
@@ -6428,7 +6444,8 @@ class Renderer {
6428
6444
  this.totalBounds = new Bounds();
6429
6445
  debug$6.log(target.innerName, '--->');
6430
6446
  try {
6431
- target.app.emit(RenderEvent.CHILD_START, target);
6447
+ if (!target.isApp)
6448
+ target.app.emit(RenderEvent.CHILD_START, target);
6432
6449
  this.emitRender(RenderEvent.START);
6433
6450
  this.renderOnce(callback);
6434
6451
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -6982,6 +6999,12 @@ class UIData extends LeafData {
6982
6999
  return strokeWidth;
6983
7000
  }
6984
7001
  get __hasStroke() { return this.stroke && this.strokeWidth; }
7002
+ get __hasMultiPaint() {
7003
+ const t = this;
7004
+ if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
7005
+ return true;
7006
+ return t.fill && this.__hasStroke;
7007
+ }
6985
7008
  get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6986
7009
  get __autoWidth() { return !this._width; }
6987
7010
  get __autoHeight() { return !this._height; }
@@ -7351,9 +7374,8 @@ const RectRender = {
7351
7374
  canvas.strokeRect(half, half, width, height);
7352
7375
  canvas.restore();
7353
7376
  }
7354
- else {
7377
+ else
7355
7378
  canvas.strokeRect(half, half, width, height);
7356
- }
7357
7379
  break;
7358
7380
  case 'outside':
7359
7381
  canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
@@ -7578,6 +7600,15 @@ __decorate([
7578
7600
  __decorate([
7579
7601
  boundsType(0)
7580
7602
  ], UI.prototype, "padding", void 0);
7603
+ __decorate([
7604
+ boundsType(false)
7605
+ ], UI.prototype, "lockRatio", void 0);
7606
+ __decorate([
7607
+ boundsType()
7608
+ ], UI.prototype, "widthRange", void 0);
7609
+ __decorate([
7610
+ boundsType()
7611
+ ], UI.prototype, "heightRange", void 0);
7581
7612
  __decorate([
7582
7613
  dataType(false)
7583
7614
  ], UI.prototype, "draggable", void 0);
@@ -7869,8 +7900,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7869
7900
  __onResize(event) {
7870
7901
  this.emitEvent(event);
7871
7902
  DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
7872
- if (!event.width || !event.height)
7873
- debug$4.warn('w = 0 or h = 0');
7874
7903
  setTimeout(() => { if (this.canvasManager)
7875
7904
  this.canvasManager.clearRecycled(); }, 0);
7876
7905
  }
@@ -8195,9 +8224,6 @@ __decorate([
8195
8224
  __decorate([
8196
8225
  dataType(false)
8197
8226
  ], Box.prototype, "resizeChildren", void 0);
8198
- __decorate([
8199
- dataType(false)
8200
- ], Box.prototype, "textBox", void 0);
8201
8227
  __decorate([
8202
8228
  affectRenderBoundsType('show')
8203
8229
  ], Box.prototype, "overflow", void 0);
@@ -8952,19 +8978,13 @@ class UIEvent extends Event {
8952
8978
  Object.assign(this, params);
8953
8979
  }
8954
8980
  getBoxPoint(relative) {
8955
- if (!relative)
8956
- relative = this.current;
8957
- return relative.getBoxPoint(this);
8981
+ return (relative || this.current).getBoxPoint(this);
8958
8982
  }
8959
8983
  getInnerPoint(relative) {
8960
- if (!relative)
8961
- relative = this.current;
8962
- return relative.getInnerPoint(this);
8984
+ return (relative || this.current).getInnerPoint(this);
8963
8985
  }
8964
8986
  getLocalPoint(relative) {
8965
- if (!relative)
8966
- relative = this.current;
8967
- return relative.getLocalPoint(this);
8987
+ return (relative || this.current).getLocalPoint(this);
8968
8988
  }
8969
8989
  getPagePoint() {
8970
8990
  return this.current.getPagePoint(this);
@@ -9198,7 +9218,8 @@ const debug$3 = Debug.get('LeaferTypeCreator');
9198
9218
  const LeaferTypeCreator = {
9199
9219
  list: {},
9200
9220
  register(name, fn) {
9201
- list$1[name] ? debug$3.repeat(name) : list$1[name] = fn;
9221
+ list$1[name] && debug$3.repeat(name);
9222
+ list$1[name] = fn;
9202
9223
  },
9203
9224
  run(name, leafer) {
9204
9225
  const fn = list$1[name];
@@ -11214,16 +11235,16 @@ const EffectModule = {
11214
11235
 
11215
11236
  const { excludeRenderBounds } = LeafBoundsHelper;
11216
11237
  Group.prototype.__renderMask = function (canvas, options) {
11217
- let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
11238
+ let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
11218
11239
  const { children } = this;
11219
11240
  for (let i = 0, len = children.length; i < len; i++) {
11220
- child = children[i];
11221
- if (child.__.mask) {
11241
+ child = children[i], mask = child.__.mask;
11242
+ if (mask) {
11222
11243
  if (currentMask) {
11223
11244
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
11224
11245
  maskCanvas = contentCanvas = null;
11225
11246
  }
11226
- if (child.__.mask === 'path') {
11247
+ if (mask === 'path' || mask === 'clipping-path') {
11227
11248
  if (child.opacity < 1) {
11228
11249
  currentMask = 'opacity-path';
11229
11250
  maskOpacity = child.opacity;
@@ -11237,14 +11258,14 @@ Group.prototype.__renderMask = function (canvas, options) {
11237
11258
  child.__clip(contentCanvas || canvas, options);
11238
11259
  }
11239
11260
  else {
11240
- currentMask = 'alpha';
11261
+ currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
11241
11262
  if (!maskCanvas)
11242
11263
  maskCanvas = getCanvas(canvas);
11243
11264
  if (!contentCanvas)
11244
11265
  contentCanvas = getCanvas(canvas);
11245
11266
  child.__render(maskCanvas, options);
11246
11267
  }
11247
- if (child.__.mask !== 'clipping')
11268
+ if (!(mask === 'clipping' || mask === 'clipping-path'))
11248
11269
  continue;
11249
11270
  }
11250
11271
  if (excludeRenderBounds(child, options))
@@ -11255,6 +11276,8 @@ Group.prototype.__renderMask = function (canvas, options) {
11255
11276
  };
11256
11277
  function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
11257
11278
  switch (maskMode) {
11279
+ case 'grayscale':
11280
+ maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
11258
11281
  case 'alpha':
11259
11282
  usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
11260
11283
  break;
@@ -11959,15 +11982,12 @@ const canvas = LeaferCanvasBase.prototype;
11959
11982
  const debug$1 = Debug.get('@leafer-ui/export');
11960
11983
  canvas.export = function (filename, options) {
11961
11984
  const { quality, blob } = FileHelper.getExportOptions(options);
11962
- if (filename.includes('.')) {
11985
+ if (filename.includes('.'))
11963
11986
  return this.saveAs(filename, quality);
11964
- }
11965
- else if (blob) {
11987
+ else if (blob)
11966
11988
  return this.toBlob(filename, quality);
11967
- }
11968
- else {
11989
+ else
11969
11990
  return this.toDataURL(filename, quality);
11970
- }
11971
11991
  };
11972
11992
  canvas.toBlob = function (type, quality) {
11973
11993
  return new Promise((resolve) => {
@@ -13009,7 +13029,7 @@ class EditBox extends Group {
13009
13029
  }
13010
13030
  getPointStyle(userStyle) {
13011
13031
  const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
13012
- const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius };
13032
+ const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0 };
13013
13033
  return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
13014
13034
  }
13015
13035
  getPointsStyle() {
@@ -13091,9 +13111,10 @@ class EditBox extends Group {
13091
13111
  const { editor } = this;
13092
13112
  if (editor.single) {
13093
13113
  const { element } = editor;
13094
- if (element.isBranch) {
13114
+ if (element.isBranch && !element.editInner) {
13095
13115
  if (element.textBox) {
13096
- const find = element.children.find(item => item.editable && item instanceof Text);
13116
+ const { children } = element;
13117
+ const find = children.find(item => item.editable && item instanceof Text) || children.find(item => item instanceof Text);
13097
13118
  if (find)
13098
13119
  return editor.openInnerEditor(find);
13099
13120
  }
@@ -13353,7 +13374,8 @@ const EditToolCreator = {
13353
13374
  list: {},
13354
13375
  register(EditTool) {
13355
13376
  const { tag } = EditTool.prototype;
13356
- list[tag] ? debug.repeat(tag) : (list[tag] = EditTool);
13377
+ list[tag] && debug.repeat(tag);
13378
+ list[tag] = EditTool;
13357
13379
  },
13358
13380
  get(tag, editor) {
13359
13381
  return new list[tag](editor);
@@ -14047,12 +14069,16 @@ LineEditTool = __decorate([
14047
14069
  ], LineEditTool);
14048
14070
 
14049
14071
  Creator.editor = function (options) { return new Editor(options); };
14072
+ dataType(false)(Box.prototype, 'textBox');
14050
14073
  defineKey(UI.prototype, 'editOuter', {
14051
14074
  get() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
14052
14075
  });
14053
14076
  defineKey(UI.prototype, 'editInner', {
14054
14077
  get() { return 'PathEditor'; }
14055
14078
  });
14079
+ defineKey(Group.prototype, 'editInner', {
14080
+ get() { return ''; }
14081
+ });
14056
14082
  defineKey(Text.prototype, 'editInner', {
14057
14083
  get() { return 'TextEditor'; }
14058
14084
  });
@@ -14680,8 +14706,10 @@ let TextEditor = class TextEditor extends InnerEditor {
14680
14706
  this.textScale = textScale;
14681
14707
  const { a, b, c, d, e, f } = new Matrix(text.worldTransform).scale(1 / textScale);
14682
14708
  let { x, y } = this.inBody ? text.app.clientBounds : text.app.tree.clientBounds;
14709
+ if (!this.inBody)
14710
+ x -= window.scrollX, y -= window.scrollY;
14683
14711
  let { width, height } = text;
14684
- x -= window.scrollX, y -= window.scrollY, width *= textScale, height *= textScale;
14712
+ width *= textScale, height *= textScale;
14685
14713
  const data = text.__;
14686
14714
  if (data.__autoWidth && data.autoSizeAlign) {
14687
14715
  width += 20;