@leafer-editor/worker 1.4.1 → 1.5.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/dist/worker.js CHANGED
@@ -3638,7 +3638,12 @@ var LeaferUI = (function (exports) {
3638
3638
  return R.map[key];
3639
3639
  },
3640
3640
  remove(key) {
3641
- delete R.map[key];
3641
+ const r = R.map[key];
3642
+ if (r) {
3643
+ if (r.destroy)
3644
+ r.destroy();
3645
+ delete R.map[key];
3646
+ }
3642
3647
  },
3643
3648
  loadImage(key, format) {
3644
3649
  return new Promise((resolve, reject) => {
@@ -3664,6 +3669,7 @@ var LeaferUI = (function (exports) {
3664
3669
  const R = Resource;
3665
3670
 
3666
3671
  const ImageManager = {
3672
+ maxRecycled: 100,
3667
3673
  recycledList: [],
3668
3674
  patternTasker: new TaskProcessor(),
3669
3675
  get(config) {
@@ -3680,13 +3686,8 @@ var LeaferUI = (function (exports) {
3680
3686
  },
3681
3687
  clearRecycled() {
3682
3688
  const list = I$1.recycledList;
3683
- if (list.length > 100) {
3684
- list.forEach(image => {
3685
- if (!image.use && image.url) {
3686
- Resource.remove(image.url);
3687
- image.destroy();
3688
- }
3689
- });
3689
+ if (list.length > I$1.maxRecycled) {
3690
+ list.forEach(image => (!image.use && image.url) && Resource.remove(image.url));
3690
3691
  list.length = 0;
3691
3692
  }
3692
3693
  },
@@ -4072,12 +4073,11 @@ var LeaferUI = (function (exports) {
4072
4073
  if (defaultValue === undefined) {
4073
4074
  property.get = function () { return this[computedKey]; };
4074
4075
  }
4075
- else if (typeof defaultValue === 'object') {
4076
- const { clone } = DataHelper;
4076
+ else if (typeof defaultValue === 'function') {
4077
4077
  property.get = function () {
4078
4078
  let v = this[computedKey];
4079
4079
  if (v === undefined)
4080
- this[computedKey] = v = clone(defaultValue);
4080
+ this[computedKey] = v = defaultValue(this.__leaf);
4081
4081
  return v;
4082
4082
  };
4083
4083
  }
@@ -5724,10 +5724,10 @@ var LeaferUI = (function (exports) {
5724
5724
  static changeAttr(attrName, defaultValue, fn) {
5725
5725
  fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5726
5726
  }
5727
- static addAttr(attrName, defaultValue, fn) {
5727
+ static addAttr(attrName, defaultValue, fn, helpValue) {
5728
5728
  if (!fn)
5729
5729
  fn = boundsType;
5730
- fn(defaultValue)(this.prototype, attrName);
5730
+ fn(defaultValue, helpValue)(this.prototype, attrName);
5731
5731
  }
5732
5732
  __emitLifeEvent(type) {
5733
5733
  if (this.hasEvent(type))
@@ -6054,7 +6054,7 @@ var LeaferUI = (function (exports) {
6054
6054
  }
6055
6055
  }
6056
6056
 
6057
- const version = "1.4.1";
6057
+ const version = "1.5.0";
6058
6058
 
6059
6059
  class LeaferCanvas extends LeaferCanvasBase {
6060
6060
  get allowBackgroundColor() { return true; }
@@ -6941,7 +6941,11 @@ var LeaferUI = (function (exports) {
6941
6941
  setStyleName() { return Plugin.need('state'); },
6942
6942
  set() { return Plugin.need('state'); }
6943
6943
  };
6944
- const Transition = {};
6944
+ const Transition = {
6945
+ list: {},
6946
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6947
+ get(attrName) { return Transition.list[attrName]; }
6948
+ };
6945
6949
 
6946
6950
  const { parse, objectToCanvasData } = PathConvert;
6947
6951
  const emptyPaint = {};
@@ -7365,9 +7369,6 @@ var LeaferUI = (function (exports) {
7365
7369
  this.__drawPathByBox(pen);
7366
7370
  return pen;
7367
7371
  }
7368
- get editConfig() { return undefined; }
7369
- get editOuter() { return ''; }
7370
- get editInner() { return ''; }
7371
7372
  constructor(data) {
7372
7373
  super(data);
7373
7374
  }
@@ -7449,8 +7450,11 @@ var LeaferUI = (function (exports) {
7449
7450
  export(_filename, _options) {
7450
7451
  return Plugin.need('export');
7451
7452
  }
7453
+ syncExport(_filename, _options) {
7454
+ return Plugin.need('export');
7455
+ }
7452
7456
  clone(data) {
7453
- const json = this.toJSON();
7457
+ const json = DataHelper.clone(this.toJSON());
7454
7458
  if (data)
7455
7459
  Object.assign(json, data);
7456
7460
  return UI_1.one(json);
@@ -7749,7 +7753,7 @@ var LeaferUI = (function (exports) {
7749
7753
  get layoutLocked() { return !this.layouter.running; }
7750
7754
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7751
7755
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7752
- get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
7756
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7753
7757
  constructor(userConfig, data) {
7754
7758
  super(data);
7755
7759
  this.config = {
@@ -8051,6 +8055,10 @@ var LeaferUI = (function (exports) {
8051
8055
  getPagePointByClient(clientPoint, updateClient) {
8052
8056
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8053
8057
  }
8058
+ getClientPointByWorld(worldPoint) {
8059
+ const { x, y } = this.clientBounds;
8060
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
8061
+ }
8054
8062
  updateClientBounds() {
8055
8063
  this.canvas && this.canvas.updateClientBounds();
8056
8064
  }
@@ -9990,8 +9998,8 @@ var LeaferUI = (function (exports) {
9990
9998
  this.__drawRenderPath(canvas); };
9991
9999
 
9992
10000
  const matrix$2 = new Matrix();
9993
- const ui$3 = exports.UI.prototype;
9994
- ui$3.__updateHitCanvas = function () {
10001
+ const ui$2 = exports.UI.prototype;
10002
+ ui$2.__updateHitCanvas = function () {
9995
10003
  const data = this.__, { hitCanvasManager } = this.leafer;
9996
10004
  const isHitPixelFill = (data.__pixelFill || data.__isCanvas) && data.hitFill === 'pixel';
9997
10005
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
@@ -10018,9 +10026,7 @@ var LeaferUI = (function (exports) {
10018
10026
  this.__drawHitPath(h);
10019
10027
  h.setStrokeOptions(data);
10020
10028
  };
10021
- ui$3.__hit = function (inner) {
10022
- if (Platform.name === 'miniapp')
10023
- this.__drawHitPath(this.__hitCanvas);
10029
+ ui$2.__hit = function (inner) {
10024
10030
  const data = this.__;
10025
10031
  if (data.__isHitPixel && this.__hitPixel(inner))
10026
10032
  return true;
@@ -10058,15 +10064,15 @@ var LeaferUI = (function (exports) {
10058
10064
  return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
10059
10065
  };
10060
10066
 
10061
- const ui$2 = exports.UI.prototype, rect = exports.Rect.prototype, box$1 = exports.Box.prototype;
10067
+ const ui$1 = exports.UI.prototype, rect = exports.Rect.prototype, box$1 = exports.Box.prototype;
10062
10068
  rect.__updateHitCanvas = box$1.__updateHitCanvas = function () {
10063
10069
  if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
10064
- ui$2.__updateHitCanvas.call(this);
10070
+ ui$1.__updateHitCanvas.call(this);
10065
10071
  else if (this.__hitCanvas)
10066
10072
  this.__hitCanvas = null;
10067
10073
  };
10068
10074
  rect.__hitFill = box$1.__hitFill = function (inner) {
10069
- return this.__hitCanvas ? ui$2.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
10075
+ return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
10070
10076
  };
10071
10077
 
10072
10078
  function getSelector$1(ui) {
@@ -11375,13 +11381,14 @@ var LeaferUI = (function (exports) {
11375
11381
  }
11376
11382
 
11377
11383
  function layoutText(drawData, style) {
11378
- const { rows, bounds } = drawData;
11384
+ const { rows, bounds } = drawData, countRows = rows.length;
11379
11385
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
11380
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11386
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11381
11387
  let starY = __baseLine;
11382
11388
  if (__clipText && realHeight > height) {
11383
11389
  realHeight = Math.max(height, __lineHeight);
11384
- drawData.overflow = rows.length;
11390
+ if (countRows > 1)
11391
+ drawData.overflow = countRows;
11385
11392
  }
11386
11393
  else if (height || autoSizeAlign) {
11387
11394
  switch (verticalAlign) {
@@ -11393,7 +11400,7 @@ var LeaferUI = (function (exports) {
11393
11400
  }
11394
11401
  starY += y;
11395
11402
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
11396
- for (let i = 0, len = rows.length; i < len; i++) {
11403
+ for (let i = 0, len = countRows; i < len; i++) {
11397
11404
  row = rows[i];
11398
11405
  row.x = x;
11399
11406
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -11462,7 +11469,7 @@ var LeaferUI = (function (exports) {
11462
11469
  if (i === end && charRight < right) {
11463
11470
  break;
11464
11471
  }
11465
- else if (charRight < right && char.char !== ' ') {
11472
+ else if ((charRight < right && char.char !== ' ') || !i) {
11466
11473
  row.data.splice(i + 1);
11467
11474
  row.width -= char.width;
11468
11475
  break;
@@ -11614,6 +11621,7 @@ var LeaferUI = (function (exports) {
11614
11621
  super(type, data);
11615
11622
  }
11616
11623
  }
11624
+ EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
11617
11625
  EditorMoveEvent.MOVE = 'editor.move';
11618
11626
 
11619
11627
  class EditorScaleEvent extends EditorEvent {
@@ -11621,6 +11629,7 @@ var LeaferUI = (function (exports) {
11621
11629
  super(type, data);
11622
11630
  }
11623
11631
  }
11632
+ EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
11624
11633
  EditorScaleEvent.SCALE = 'editor.scale';
11625
11634
 
11626
11635
  class EditorRotateEvent extends EditorEvent {
@@ -11628,6 +11637,7 @@ var LeaferUI = (function (exports) {
11628
11637
  super(type, data);
11629
11638
  }
11630
11639
  }
11640
+ EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
11631
11641
  EditorRotateEvent.ROTATE = 'editor.rotate';
11632
11642
 
11633
11643
  class EditorSkewEvent extends EditorEvent {
@@ -11635,6 +11645,7 @@ var LeaferUI = (function (exports) {
11635
11645
  super(type, data);
11636
11646
  }
11637
11647
  }
11648
+ EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
11638
11649
  EditorSkewEvent.SKEW = 'editor.skew';
11639
11650
 
11640
11651
  function targetAttr(fn) {
@@ -11687,7 +11698,7 @@ var LeaferUI = (function (exports) {
11687
11698
  for (let i = 0; i < list.length; i++) {
11688
11699
  leaf = list[i];
11689
11700
  const { worldTransform, worldRenderBounds } = leaf;
11690
- if (!bounds || bounds.hit(worldRenderBounds, options.matrix)) {
11701
+ if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
11691
11702
  const aScaleX = abs$1(worldTransform.scaleX), aScaleY = abs$1(worldTransform.scaleY);
11692
11703
  if (aScaleX !== aScaleY) {
11693
11704
  copy$2(matrix$1, worldTransform);
@@ -11813,9 +11824,9 @@ var LeaferUI = (function (exports) {
11813
11824
  }
11814
11825
  onSelect() {
11815
11826
  if (this.running) {
11816
- const { mergeConfig: config, list } = this.editor;
11817
- const { stroke, strokeWidth } = config;
11818
- this.targetStroker.setTarget(list, { stroke, strokeWidth: Math.max(1, strokeWidth / 2) });
11827
+ const { mergeConfig, list } = this.editor;
11828
+ const { stroke, strokeWidth, selectedStyle } = mergeConfig;
11829
+ this.targetStroker.setTarget(list, Object.assign({ stroke, strokeWidth: Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
11819
11830
  this.hoverStroker.target = null;
11820
11831
  }
11821
11832
  }
@@ -12002,7 +12013,7 @@ var LeaferUI = (function (exports) {
12002
12013
  const EditDataHelper = {
12003
12014
  getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
12004
12015
  let align, origin = {}, scaleX = 1, scaleY = 1;
12005
- const { boxBounds, widthRange, heightRange, dragBounds } = element;
12016
+ const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = element;
12006
12017
  const { width, height } = startBounds;
12007
12018
  if (around) {
12008
12019
  totalMove.x *= 2;
@@ -12016,10 +12027,6 @@ var LeaferUI = (function (exports) {
12016
12027
  const changedScaleY = scaleMode ? originChangedScaleY : signY * boxBounds.height / height;
12017
12028
  totalMove.x *= scaleMode ? originChangedScaleX : signX;
12018
12029
  totalMove.y *= scaleMode ? originChangedScaleY : signY;
12019
- if (Math.abs(totalMove.x) === width)
12020
- totalMove.x += 0.1;
12021
- if (Math.abs(totalMove.y) === height)
12022
- totalMove.y += 0.1;
12023
12030
  const topScale = (-totalMove.y + height) / height;
12024
12031
  const rightScale = (totalMove.x + width) / width;
12025
12032
  const bottomScale = (totalMove.y + height) / height;
@@ -12109,6 +12116,10 @@ var LeaferUI = (function (exports) {
12109
12116
  const nowHeight = boxBounds.height * element.scaleY;
12110
12117
  scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
12111
12118
  }
12119
+ if (Math.abs(scaleX * worldBoxBounds.width) < 1)
12120
+ scaleX = (scaleX < 0 ? -1 : 1) / worldBoxBounds.width;
12121
+ if (Math.abs(scaleY * worldBoxBounds.height) < 1)
12122
+ scaleY = (scaleY < 0 ? -1 : 1) / worldBoxBounds.height;
12112
12123
  return { origin, scaleX, scaleY, direction, lockRatio, around };
12113
12124
  },
12114
12125
  getRotateData(bounds, direction, current, last, around) {
@@ -12237,7 +12248,7 @@ var LeaferUI = (function (exports) {
12237
12248
  let { rotation } = editBox;
12238
12249
  const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
12239
12250
  const { pointType } = point, { flippedX, flippedY } = editBox;
12240
- let showResize = pointType === 'resize';
12251
+ let showResize = pointType.includes('resize');
12241
12252
  if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
12242
12253
  showResize = false;
12243
12254
  const showSkew = skewable && !showResize && point.name === 'resize-line';
@@ -12264,7 +12275,7 @@ var LeaferUI = (function (exports) {
12264
12275
  class EditPoint extends exports.Box {
12265
12276
  }
12266
12277
 
12267
- const fourDirection = ['top', 'right', 'bottom', 'left'];
12278
+ const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
12268
12279
  class EditBox extends exports.Group {
12269
12280
  get flipped() { return this.flippedX || this.flippedY; }
12270
12281
  get flippedX() { return this.scaleX < 0; }
@@ -12279,6 +12290,7 @@ var LeaferUI = (function (exports) {
12279
12290
  this.resizePoints = [];
12280
12291
  this.rotatePoints = [];
12281
12292
  this.resizeLines = [];
12293
+ this.dragStartData = {};
12282
12294
  this.__eventIds = [];
12283
12295
  this.editor = editor;
12284
12296
  this.visible = false;
@@ -12320,7 +12332,7 @@ var LeaferUI = (function (exports) {
12320
12332
  resizeP.rotation = (i / 2) * 90;
12321
12333
  }
12322
12334
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
12323
- rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
12335
+ rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
12324
12336
  rect.hittable = !single;
12325
12337
  rect.syncEventer = single && this.editor;
12326
12338
  if (single) {
@@ -12329,14 +12341,14 @@ var LeaferUI = (function (exports) {
12329
12341
  }
12330
12342
  }
12331
12343
  update(bounds) {
12332
- this.visible = !this.editor.element.locked;
12344
+ const { mergeConfig, element, multiple } = this.editor;
12345
+ const { middlePoint, resizeable, rotateable, hideOnSmall, editBox } = mergeConfig;
12346
+ this.visible = !element.locked;
12333
12347
  if (this.view.worldOpacity) {
12334
- const { mergeConfig } = this.editor;
12335
12348
  const { width, height } = bounds;
12336
12349
  const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
12337
- const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig;
12338
12350
  const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
12339
- const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
12351
+ const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
12340
12352
  let point = {}, rotateP, resizeP, resizeL;
12341
12353
  for (let i = 0; i < 8; i++) {
12342
12354
  AroundHelper.toPoint(AroundHelper.directionData[i], bounds, point);
@@ -12352,13 +12364,13 @@ var LeaferUI = (function (exports) {
12352
12364
  resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
12353
12365
  if (((i + 1) / 2) % 2) {
12354
12366
  resizeL.width = width;
12355
- if (resizeP.width > width - 30)
12367
+ if (hideOnSmall && resizeP.width * 2 > width)
12356
12368
  resizeP.visible = false;
12357
12369
  }
12358
12370
  else {
12359
12371
  resizeL.height = height;
12360
12372
  resizeP.rotation = 90;
12361
- if (resizeP.width > height - 30)
12373
+ if (hideOnSmall && resizeP.width * 2 > height)
12362
12374
  resizeP.visible = false;
12363
12375
  }
12364
12376
  }
@@ -12368,7 +12380,7 @@ var LeaferUI = (function (exports) {
12368
12380
  this.layoutCircle(mergeConfig);
12369
12381
  if (rect.path)
12370
12382
  rect.path = null;
12371
- rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
12383
+ rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
12372
12384
  buttons.visible = showPoints && buttons.children.length > 0;
12373
12385
  if (buttons.visible)
12374
12386
  this.layoutButtons(mergeConfig);
@@ -12415,7 +12427,7 @@ var LeaferUI = (function (exports) {
12415
12427
  }
12416
12428
  getPointStyle(userStyle) {
12417
12429
  const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
12418
- const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0 };
12430
+ const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
12419
12431
  return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
12420
12432
  }
12421
12433
  getPointsStyle() {
@@ -12435,34 +12447,32 @@ var LeaferUI = (function (exports) {
12435
12447
  }
12436
12448
  onDragStart(e) {
12437
12449
  this.dragging = true;
12438
- const { editor } = this;
12439
- if (e.current.name === 'rect') {
12450
+ const point = this.dragPoint = e.current;
12451
+ const { editor, dragStartData } = this, { element } = editor;
12452
+ if (point.name === 'rect') {
12440
12453
  this.moving = true;
12441
- editor.dragStartPoint = { x: editor.element.x, y: editor.element.y };
12442
12454
  editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
12443
12455
  }
12444
- else if (e.current.pointType === 'resize') {
12445
- editor.dragStartBounds = Object.assign({}, editor.element.getLayoutBounds('box', 'local'));
12446
- editor.resizeDirection = e.current.direction;
12447
- }
12456
+ dragStartData.x = e.x;
12457
+ dragStartData.y = e.y;
12458
+ dragStartData.point = { x: element.x, y: element.y };
12459
+ dragStartData.bounds = Object.assign({}, element.getLayoutBounds('box', 'local'));
12460
+ dragStartData.rotation = element.rotation;
12448
12461
  }
12449
12462
  onDragEnd(e) {
12450
12463
  this.dragging = false;
12464
+ this.dragPoint = null;
12451
12465
  this.moving = false;
12452
12466
  if (e.current.name === 'rect')
12453
12467
  this.editor.opacity = 1;
12454
- this.editor.resizeDirection = undefined;
12455
12468
  }
12456
12469
  onDrag(e) {
12457
12470
  const { editor } = this;
12458
- const point = this.enterPoint = e.current;
12459
- if (point.pointType === 'rotate' || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
12460
- if (editor.mergeConfig.rotateable)
12461
- editor.onRotate(e);
12462
- }
12463
- else if (point.pointType === 'resize') {
12471
+ const { pointType } = this.enterPoint = e.current;
12472
+ if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable)
12473
+ editor.onRotate(e);
12474
+ if (pointType.includes('resize'))
12464
12475
  editor.onScale(e);
12465
- }
12466
12476
  updateCursor(editor, e);
12467
12477
  }
12468
12478
  onArrow(e) {
@@ -12640,6 +12650,7 @@ ${filterStyle}
12640
12650
  rotateCursor: { url: rotateSVG, x: 12, y: 12 },
12641
12651
  skewCursor: { url: skewSVG, x: 12, y: 12 },
12642
12652
  selector: true,
12653
+ editBox: true,
12643
12654
  hover: true,
12644
12655
  select: 'press',
12645
12656
  openInner: 'double',
@@ -12655,14 +12666,25 @@ ${filterStyle}
12655
12666
  function simulate(editor) {
12656
12667
  const { simulateTarget, list } = editor;
12657
12668
  const { zoomLayer } = list[0].leafer.zoomLayer;
12658
- simulateTarget.safeChange(() => simulateTarget.reset(bounds$1.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page')).get()));
12669
+ simulateTarget.safeChange(() => {
12670
+ bounds$1.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page'));
12671
+ if (bounds$1.width === 0)
12672
+ bounds$1.width = 0.1;
12673
+ if (bounds$1.height === 0)
12674
+ bounds$1.height = 0.1;
12675
+ simulateTarget.reset(bounds$1.get());
12676
+ });
12659
12677
  zoomLayer.add(simulateTarget);
12660
12678
  }
12661
12679
 
12662
12680
  function onTarget(editor, oldValue) {
12663
12681
  const { target } = editor;
12664
12682
  if (target) {
12665
- editor.leafList = target instanceof LeafList ? target : new LeafList(target instanceof Array ? target : target);
12683
+ const { list } = editor.leafList = target instanceof LeafList ? target : new LeafList(target instanceof Array ? target : target);
12684
+ if (!list.every(checkEditable)) {
12685
+ editor.target = list.filter(checkEditable);
12686
+ return;
12687
+ }
12666
12688
  if (editor.multiple)
12667
12689
  simulate(editor);
12668
12690
  }
@@ -12689,6 +12711,9 @@ ${filterStyle}
12689
12711
  function onHover(editor, oldValue) {
12690
12712
  editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
12691
12713
  }
12714
+ function checkEditable(item) {
12715
+ return item.editable && !item.locked;
12716
+ }
12692
12717
 
12693
12718
  const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
12694
12719
  const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
@@ -12786,10 +12811,13 @@ ${filterStyle}
12786
12811
  super(type, data);
12787
12812
  }
12788
12813
  }
12814
+ EditorGroupEvent.BEFORE_GROUP = 'editor.before_group';
12789
12815
  EditorGroupEvent.GROUP = 'editor.group';
12790
12816
  EditorGroupEvent.BEFORE_UNGROUP = 'editor.before_ungroup';
12791
12817
  EditorGroupEvent.UNGROUP = 'editor.ungroup';
12818
+ EditorGroupEvent.BEFORE_OPEN = 'editor.before_open_group';
12792
12819
  EditorGroupEvent.OPEN = 'editor.open_group';
12820
+ EditorGroupEvent.BEFORE_CLOSE = 'editor.before_close_group';
12793
12821
  EditorGroupEvent.CLOSE = 'editor.close_group';
12794
12822
 
12795
12823
  const { updateMatrix } = LeafHelper;
@@ -12852,8 +12880,20 @@ ${filterStyle}
12852
12880
 
12853
12881
  class Editor extends exports.Group {
12854
12882
  get mergeConfig() {
12855
- const { element, config } = this;
12856
- return this.single && element.editConfig ? Object.assign(Object.assign({}, config), element.editConfig) : config;
12883
+ const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
12884
+ if (element && element.editConfig)
12885
+ Object.assign(mergeConfig, element.editConfig);
12886
+ if (dragPoint) {
12887
+ if (dragPoint.editConfig)
12888
+ Object.assign(mergeConfig, dragPoint.editConfig);
12889
+ if (mergeConfig.editSize === 'font-size')
12890
+ mergeConfig.lockRatio = true;
12891
+ if (dragPoint.pointType === 'resize-rotate') {
12892
+ mergeConfig.around || (mergeConfig.around = 'center');
12893
+ isNull(mergeConfig.lockRatio) && (mergeConfig.lockRatio = true);
12894
+ }
12895
+ }
12896
+ return mergeConfig;
12857
12897
  }
12858
12898
  get list() { return this.leafList.list; }
12859
12899
  get dragHoverExclude() { return [this.editBox.rect]; }
@@ -12863,6 +12903,7 @@ ${filterStyle}
12863
12903
  get single() { return this.list.length === 1; }
12864
12904
  get dragging() { return this.editBox.dragging; }
12865
12905
  get moving() { return this.editBox.moving; }
12906
+ get dragPoint() { return this.editBox.dragPoint; }
12866
12907
  get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
12867
12908
  get buttons() { return this.editBox.buttons; }
12868
12909
  constructor(userConfig, data) {
@@ -12953,7 +12994,7 @@ ${filterStyle}
12953
12994
  else
12954
12995
  total.x = 0;
12955
12996
  }
12956
- this.move(exports.DragEvent.getValidMove(this.element, this.dragStartPoint, total));
12997
+ this.move(exports.DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total));
12957
12998
  }
12958
12999
  }
12959
13000
  onScale(e) {
@@ -12967,7 +13008,7 @@ ${filterStyle}
12967
13008
  const { direction } = e.current;
12968
13009
  if (e.shiftKey || element.lockRatio)
12969
13010
  lockRatio = true;
12970
- const data = EditDataHelper.getScaleData(element, this.dragStartBounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
13011
+ const data = EditDataHelper.getScaleData(element, this.editBox.dragStartData.bounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
12971
13012
  if (this.editTool.onScaleWithDrag) {
12972
13013
  data.drag = e;
12973
13014
  this.scaleWithDrag(data);
@@ -12982,26 +13023,29 @@ ${filterStyle}
12982
13023
  const { direction, name } = e.current;
12983
13024
  if (skewable && name === 'resize-line')
12984
13025
  return this.onSkew(e);
12985
- const { element } = this;
13026
+ const { element } = this, { dragStartData } = this.editBox;
12986
13027
  let origin, rotation;
12987
13028
  if (e instanceof exports.RotateEvent) {
12988
13029
  if (rotateable === 'rotate')
12989
13030
  e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e);
12990
13031
  else
12991
13032
  return;
13033
+ if (element.scaleX * element.scaleY < 0)
13034
+ rotation = -rotation;
12992
13035
  }
12993
13036
  else {
12994
- const last = { x: e.x - e.moveX, y: e.y - e.moveY };
12995
- const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(last), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
13037
+ const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(dragStartData), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
12996
13038
  rotation = data.rotation;
12997
13039
  origin = data.origin;
12998
13040
  }
12999
- rotation = MathHelper.getGapRotation(rotation, rotateGap, element.rotation);
13000
- if (!rotation)
13001
- return;
13002
13041
  if (element.scaleX * element.scaleY < 0)
13003
13042
  rotation = -rotation;
13004
- this.rotateOf(origin, MathHelper.float(rotation, 2));
13043
+ if (e instanceof exports.DragEvent)
13044
+ rotation = dragStartData.rotation + rotation - element.rotation;
13045
+ rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, element.rotation), 2);
13046
+ if (!rotation)
13047
+ return;
13048
+ this.rotateOf(origin, rotation);
13005
13049
  }
13006
13050
  onSkew(e) {
13007
13051
  const { element } = this;
@@ -13018,7 +13062,9 @@ ${filterStyle}
13018
13062
  const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
13019
13063
  if (this.multiple)
13020
13064
  element.safeChange(() => element.move(x, y));
13021
- const event = new EditorMoveEvent(EditorMoveEvent.MOVE, { target: element, editor: this, moveX: world.x, moveY: world.y });
13065
+ const data = { target: element, editor: this, moveX: world.x, moveY: world.y };
13066
+ this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
13067
+ const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
13022
13068
  this.editTool.onMove(event);
13023
13069
  this.emitEvent(event);
13024
13070
  }
@@ -13026,7 +13072,9 @@ ${filterStyle}
13026
13072
  if (!this.checkTransform('resizeable'))
13027
13073
  return;
13028
13074
  const { element } = this;
13029
- const event = new EditorScaleEvent(EditorScaleEvent.SCALE, Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) }));
13075
+ data = Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) });
13076
+ this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13077
+ const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13030
13078
  this.editTool.onScaleWithDrag(event);
13031
13079
  this.emitEvent(event);
13032
13080
  }
@@ -13036,7 +13084,9 @@ ${filterStyle}
13036
13084
  const { element } = this;
13037
13085
  const worldOrigin = this.getWorldOrigin(origin);
13038
13086
  const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.scaleOf(origin, scaleX, scaleY)));
13039
- const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX, scaleY, transform });
13087
+ const data = { target: element, editor: this, worldOrigin, scaleX, scaleY, transform };
13088
+ this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13089
+ const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13040
13090
  this.editTool.onScale(event);
13041
13091
  this.emitEvent(event);
13042
13092
  }
@@ -13046,7 +13096,9 @@ ${filterStyle}
13046
13096
  const { element } = this;
13047
13097
  const worldOrigin = this.getWorldOrigin('center');
13048
13098
  const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(element, axis));
13049
- const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform });
13099
+ const data = { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
13100
+ this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13101
+ const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13050
13102
  this.editTool.onScale(event);
13051
13103
  this.emitEvent(event);
13052
13104
  }
@@ -13056,7 +13108,9 @@ ${filterStyle}
13056
13108
  const { element } = this;
13057
13109
  const worldOrigin = this.getWorldOrigin(origin);
13058
13110
  const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.rotateOf(origin, rotation)));
13059
- const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, { target: element, editor: this, worldOrigin, rotation, transform });
13111
+ const data = { target: element, editor: this, worldOrigin, rotation, transform };
13112
+ this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
13113
+ const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
13060
13114
  this.editTool.onRotate(event);
13061
13115
  this.emitEvent(event);
13062
13116
  }
@@ -13066,7 +13120,9 @@ ${filterStyle}
13066
13120
  const { element } = this;
13067
13121
  const worldOrigin = this.getWorldOrigin(origin);
13068
13122
  const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.skewOf(origin, skewX, skewY)));
13069
- const event = new EditorSkewEvent(EditorSkewEvent.SKEW, { target: element, editor: this, worldOrigin, skewX, skewY, transform });
13123
+ const data = { target: element, editor: this, worldOrigin, skewX, skewY, transform };
13124
+ this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
13125
+ const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
13070
13126
  this.editTool.onSkew(event);
13071
13127
  this.emitEvent(event);
13072
13128
  }
@@ -13084,6 +13140,7 @@ ${filterStyle}
13084
13140
  }
13085
13141
  group(userGroup) {
13086
13142
  if (this.multiple) {
13143
+ this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
13087
13144
  this.target = EditorHelper.group(this.list, this.element, userGroup);
13088
13145
  this.emitGroupEvent(EditorGroupEvent.GROUP, this.target);
13089
13146
  }
@@ -13099,11 +13156,13 @@ ${filterStyle}
13099
13156
  return this.list;
13100
13157
  }
13101
13158
  openGroup(group) {
13159
+ this.emitGroupEvent(EditorGroupEvent.BEFORE_OPEN, group);
13102
13160
  this.openedGroupList.add(group);
13103
13161
  group.hitChildren = true;
13104
13162
  this.emitGroupEvent(EditorGroupEvent.OPEN, group);
13105
13163
  }
13106
13164
  closeGroup(group) {
13165
+ this.emitGroupEvent(EditorGroupEvent.BEFORE_CLOSE, group);
13107
13166
  this.openedGroupList.remove(group);
13108
13167
  group.hitChildren = false;
13109
13168
  this.emitGroupEvent(EditorGroupEvent.CLOSE, group);
@@ -13132,7 +13191,8 @@ ${filterStyle}
13132
13191
  emitGroupEvent(type, group) {
13133
13192
  const event = new EditorGroupEvent(type, { editTarget: group });
13134
13193
  this.emitEvent(event);
13135
- group.emitEvent(event);
13194
+ if (group)
13195
+ group.emitEvent(event);
13136
13196
  }
13137
13197
  openInnerEditor(target, select) {
13138
13198
  if (target && select)
@@ -13549,16 +13609,14 @@ ${filterStyle}
13549
13609
  leaf.height *= scaleY;
13550
13610
  }
13551
13611
  }
13552
- function scaleResizeFontSize(leaf, scaleX, scaleY) {
13553
- const { app } = leaf;
13554
- const editor = app && app.editor;
13612
+ function scaleResizeFontSize(leaf, scaleX, scaleY, direction) {
13555
13613
  let fontScale = scaleX;
13556
- if (editor.editing) {
13614
+ if (direction !== undefined) {
13557
13615
  const layout = leaf.__layout;
13558
13616
  let { width, height } = layout.boxBounds;
13559
13617
  width *= scaleY - scaleX;
13560
13618
  height *= scaleX - scaleY;
13561
- switch (editor.resizeDirection) {
13619
+ switch (direction) {
13562
13620
  case top:
13563
13621
  case bottom:
13564
13622
  fontScale = scaleY;
@@ -13626,8 +13684,9 @@ ${filterStyle}
13626
13684
  this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
13627
13685
  };
13628
13686
  exports.Text.prototype.__scaleResize = function (scaleX, scaleY) {
13629
- if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
13630
- scaleResizeFontSize(this, scaleX, scaleY);
13687
+ const { app, editConfig } = this, editor = app && app.editor, dragPoint = editor && editor.dragPoint;
13688
+ if (this.__.resizeFontSize || (editConfig && editConfig.editSize === 'font-size') || (dragPoint && editor.mergeConfig.editSize === 'font-size')) {
13689
+ scaleResizeFontSize(this, scaleX, scaleY, dragPoint && dragPoint.direction);
13631
13690
  }
13632
13691
  else {
13633
13692
  scaleResize(this, scaleX, scaleY);
@@ -13676,34 +13735,15 @@ ${filterStyle}
13676
13735
 
13677
13736
  Plugin.add('editor', 'resize');
13678
13737
  Creator.editor = function (options) { return new Editor(options); };
13679
- dataType(false)(exports.Box.prototype, 'textBox');
13680
- defineKey(exports.UI.prototype, 'editOuter', {
13681
- get() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
13682
- });
13683
- defineKey(exports.UI.prototype, 'editInner', {
13684
- get() { return 'PathEditor'; }
13685
- });
13686
- defineKey(exports.Group.prototype, 'editInner', {
13687
- get() { return ''; }
13688
- });
13689
- defineKey(exports.Text.prototype, 'editInner', {
13690
- get() { return 'TextEditor'; }
13691
- });
13692
- exports.UI.setEditConfig = function (config) {
13693
- defineKey(this.prototype, 'editConfig', {
13694
- get() { return typeof config === 'function' ? config(this) : config; }
13695
- });
13696
- };
13697
- exports.UI.setEditOuter = function (toolName) {
13698
- defineKey(this.prototype, 'editOuter', {
13699
- get() { return typeof toolName === 'string' ? toolName : toolName(this); }
13700
- });
13701
- };
13702
- exports.UI.setEditInner = function (editorName) {
13703
- defineKey(this.prototype, 'editInner', {
13704
- get() { return typeof editorName === 'string' ? editorName : editorName(this); }
13705
- });
13706
- };
13738
+ exports.Box.addAttr('textBox', false, dataType);
13739
+ exports.UI.addAttr('editConfig', undefined, dataType);
13740
+ exports.UI.addAttr('editOuter', (ui) => ui.__.__isLinePath ? 'LineEditTool' : 'EditTool', dataType);
13741
+ exports.UI.addAttr('editInner', 'PathEditor', dataType);
13742
+ exports.Group.addAttr('editInner', '', dataType);
13743
+ exports.Text.addAttr('editInner', 'TextEditor', dataType);
13744
+ exports.UI.setEditConfig = function (config) { this.changeAttr('editConfig', config); };
13745
+ exports.UI.setEditOuter = function (toolName) { this.changeAttr('editOuter', toolName); };
13746
+ exports.UI.setEditInner = function (editorName) { this.changeAttr('editInner', editorName); };
13707
13747
 
13708
13748
  function addViewport(leafer, mergeConfig, custom) {
13709
13749
  addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig);
@@ -13714,10 +13754,8 @@ ${filterStyle}
13714
13754
  }), leafer.on_(exports.ZoomEvent.BEFORE_ZOOM, (e) => {
13715
13755
  const { zoomLayer } = leafer;
13716
13756
  const changeScale = leafer.getValidScale(e.scale);
13717
- if (changeScale !== 1) {
13718
- PointHelper.scaleOf(zoomLayer, e, changeScale);
13719
- zoomLayer.scale = zoomLayer.__.scaleX * changeScale;
13720
- }
13757
+ if (changeScale !== 1)
13758
+ zoomLayer.scaleOfWorld(e, changeScale);
13721
13759
  }));
13722
13760
  }
13723
13761
  function addViewportConfig(leafer, mergeConfig) {
@@ -13944,7 +13982,7 @@ ${filterStyle}
13944
13982
  changeScale = min / scaleX;
13945
13983
  else if (max && absScale > max)
13946
13984
  changeScale = max / scaleX;
13947
- return disabled ? 1 : MathHelper.float(changeScale);
13985
+ return disabled ? 1 : changeScale;
13948
13986
  };
13949
13987
 
13950
13988
  function getMoveEventData(move, event) {
@@ -14085,7 +14123,7 @@ ${filterStyle}
14085
14123
  const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds();
14086
14124
  const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
14087
14125
  let changeScale;
14088
- const { scaleX } = this.__;
14126
+ const { x, y, scaleX, scaleY } = zoomLayer.__;
14089
14127
  if (typeof zoomType === 'string') {
14090
14128
  switch (zoomType) {
14091
14129
  case 'in':
@@ -14115,7 +14153,6 @@ ${filterStyle}
14115
14153
  zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition);
14116
14154
  }
14117
14155
  else if (typeof zoomType === 'object') {
14118
- const { x, y, scaleX, scaleY } = zoomLayer;
14119
14156
  const data = { x, y, scaleX, scaleY };
14120
14157
  const isArray = zoomType instanceof Array;
14121
14158
  if (isArray || zoomType.tag) {
@@ -14263,6 +14300,18 @@ ${filterStyle}
14263
14300
  class ArrowData extends LineData {
14264
14301
  }
14265
14302
 
14303
+ function arrowType(defaultValue) {
14304
+ return decorateLeafAttr(defaultValue, (key) => attr({
14305
+ set(value) {
14306
+ if (this.__setAttr(key, value)) {
14307
+ const data = this.__;
14308
+ data.__useArrow = data.startArrow !== 'none' || data.endArrow !== 'none';
14309
+ doStrokeType(this);
14310
+ }
14311
+ }
14312
+ }));
14313
+ }
14314
+
14266
14315
  exports.Arrow = class Arrow extends exports.Line {
14267
14316
  get __tag() { return 'Arrow'; }
14268
14317
  constructor(data) {
@@ -14274,7 +14323,7 @@ ${filterStyle}
14274
14323
  dataProcessor(ArrowData)
14275
14324
  ], exports.Arrow.prototype, "__", void 0);
14276
14325
  __decorate([
14277
- strokeType('angle')
14326
+ arrowType('angle')
14278
14327
  ], exports.Arrow.prototype, "endArrow", void 0);
14279
14328
  exports.Arrow = __decorate([
14280
14329
  registerUI()
@@ -14507,22 +14556,9 @@ ${filterStyle}
14507
14556
  data[startIndex + 1] = point.y;
14508
14557
  }
14509
14558
 
14510
- function arrowType(defaultValue) {
14511
- return decorateLeafAttr(defaultValue, (key) => attr({
14512
- set(value) {
14513
- if (this.__setAttr(key, value)) {
14514
- const data = this.__;
14515
- data.__useArrow = data.startArrow !== 'none' || data.endArrow !== 'none';
14516
- doStrokeType(this);
14517
- }
14518
- }
14519
- }));
14520
- }
14521
-
14522
14559
  Plugin.add('arrow');
14523
- const ui$1 = exports.UI.prototype;
14524
- arrowType('none')(ui$1, 'startArrow');
14525
- arrowType('none')(ui$1, 'endArrow');
14560
+ exports.UI.addAttr('startArrow', 'none', arrowType);
14561
+ exports.UI.addAttr('endArrow', 'none', arrowType);
14526
14562
  Object.assign(PathArrow, PathArrowModule);
14527
14563
 
14528
14564
  const { Yes, NoAndSkip, YesAndSkip } = exports.Answer;
@@ -14690,124 +14726,134 @@ ${filterStyle}
14690
14726
  }
14691
14727
 
14692
14728
  const ExportModule = {
14693
- export(leaf, filename, options) {
14729
+ syncExport(leaf, filename, options) {
14694
14730
  this.running = true;
14731
+ let result;
14695
14732
  const fileType = FileHelper.fileType(filename);
14696
14733
  const isDownload = filename.includes('.');
14697
14734
  options = FileHelper.getExportOptions(options);
14698
- return addTask((success) => new Promise((resolve) => {
14699
- const over = (result) => {
14700
- success(result);
14701
- resolve();
14702
- this.running = false;
14703
- };
14704
- const { toURL } = Platform;
14705
- const { download } = Platform.origin;
14706
- if (fileType === 'json') {
14707
- isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
14708
- return over({ data: isDownload ? true : leaf.toJSON(options.json) });
14709
- }
14710
- if (fileType === 'svg') {
14711
- isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
14712
- return over({ data: isDownload ? true : leaf.toSVG() });
14735
+ const { toURL } = Platform;
14736
+ const { download } = Platform.origin;
14737
+ if (fileType === 'json') {
14738
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
14739
+ result = { data: isDownload ? true : leaf.toJSON(options.json) };
14740
+ }
14741
+ else if (fileType === 'svg') {
14742
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
14743
+ result = { data: isDownload ? true : leaf.toSVG() };
14744
+ }
14745
+ else {
14746
+ let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
14747
+ const { worldTransform, isLeafer, leafer, isFrame } = leaf;
14748
+ const { slice, trim, padding, onCanvas } = options;
14749
+ const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
14750
+ const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
14751
+ const screenshot = options.screenshot || leaf.isApp;
14752
+ const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
14753
+ const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
14754
+ if (screenshot) {
14755
+ renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
14713
14756
  }
14714
- const { leafer } = leaf;
14715
- if (leafer) {
14716
- checkLazy(leaf);
14717
- leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
14718
- let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
14719
- const { worldTransform, isLeafer, isFrame } = leaf;
14720
- const { slice, trim, padding, onCanvas } = options;
14721
- const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
14722
- const contextSettings = options.contextSettings || leafer.config.contextSettings;
14723
- const screenshot = options.screenshot || leaf.isApp;
14724
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
14725
- const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
14726
- if (screenshot) {
14727
- renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
14728
- }
14729
- else {
14730
- let relative = options.relative || (isLeafer ? 'inner' : 'local');
14731
- scaleX = worldTransform.scaleX;
14732
- scaleY = worldTransform.scaleY;
14733
- switch (relative) {
14734
- case 'inner':
14735
- matrix.set(worldTransform);
14736
- break;
14737
- case 'local':
14738
- matrix.set(worldTransform).divide(leaf.localTransform);
14739
- scaleX /= leaf.scaleX;
14740
- scaleY /= leaf.scaleY;
14741
- break;
14742
- case 'world':
14743
- scaleX = 1;
14744
- scaleY = 1;
14745
- break;
14746
- case 'page':
14747
- relative = leaf.leafer;
14748
- default:
14749
- matrix.set(worldTransform).divide(leaf.getTransform(relative));
14750
- const l = relative.worldTransform;
14751
- scaleX /= scaleX / l.scaleX;
14752
- scaleY /= scaleY / l.scaleY;
14753
- }
14754
- renderBounds = leaf.getBounds('render', relative);
14755
- }
14756
- const scaleData = { scaleX: 1, scaleY: 1 };
14757
- MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
14758
- let pixelRatio = options.pixelRatio || 1;
14759
- if (leaf.isApp) {
14760
- scaleData.scaleX *= pixelRatio;
14761
- scaleData.scaleY *= pixelRatio;
14762
- pixelRatio = leaf.app.pixelRatio;
14763
- }
14764
- const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
14765
- const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
14766
- let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
14767
- let sliceLeaf;
14768
- if (slice) {
14769
- sliceLeaf = leaf;
14770
- sliceLeaf.__worldOpacity = 0;
14771
- leaf = leafer;
14772
- renderOptions.bounds = canvas.bounds;
14773
- }
14774
- canvas.save();
14775
- if (isFrame && fill !== undefined) {
14776
- const oldFill = leaf.get('fill');
14777
- leaf.fill = '';
14778
- leaf.__render(canvas, renderOptions);
14779
- leaf.fill = oldFill;
14780
- }
14781
- else {
14782
- leaf.__render(canvas, renderOptions);
14783
- }
14784
- canvas.restore();
14785
- if (sliceLeaf)
14786
- sliceLeaf.__updateWorldOpacity();
14787
- if (trim) {
14788
- trimBounds = getTrimBounds(canvas);
14789
- const old = canvas, { width, height } = trimBounds;
14790
- const config = { x: 0, y: 0, width, height, pixelRatio };
14791
- canvas = Creator.canvas(config);
14792
- canvas.copyWorld(old, trimBounds, config);
14793
- }
14794
- if (padding) {
14795
- const [top, right, bottom, left] = MathHelper.fourNumber(padding);
14796
- const old = canvas, { width, height } = old;
14797
- canvas = Creator.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
14798
- canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
14799
- }
14800
- if (needFill)
14801
- canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
14802
- if (onCanvas)
14803
- onCanvas(canvas);
14804
- const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
14805
- over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
14806
- }));
14757
+ else {
14758
+ let relative = options.relative || (isLeafer ? 'inner' : 'local');
14759
+ scaleX = worldTransform.scaleX;
14760
+ scaleY = worldTransform.scaleY;
14761
+ switch (relative) {
14762
+ case 'inner':
14763
+ matrix.set(worldTransform);
14764
+ break;
14765
+ case 'local':
14766
+ matrix.set(worldTransform).divide(leaf.localTransform);
14767
+ scaleX /= leaf.scaleX;
14768
+ scaleY /= leaf.scaleY;
14769
+ break;
14770
+ case 'world':
14771
+ scaleX = 1;
14772
+ scaleY = 1;
14773
+ break;
14774
+ case 'page':
14775
+ relative = leafer || leaf;
14776
+ default:
14777
+ matrix.set(worldTransform).divide(leaf.getTransform(relative));
14778
+ const l = relative.worldTransform;
14779
+ scaleX /= scaleX / l.scaleX;
14780
+ scaleY /= scaleY / l.scaleY;
14781
+ }
14782
+ renderBounds = leaf.getBounds('render', relative);
14783
+ }
14784
+ const scaleData = { scaleX: 1, scaleY: 1 };
14785
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
14786
+ let pixelRatio = options.pixelRatio || 1;
14787
+ if (leaf.isApp) {
14788
+ scaleData.scaleX *= pixelRatio;
14789
+ scaleData.scaleY *= pixelRatio;
14790
+ pixelRatio = leaf.app.pixelRatio;
14791
+ }
14792
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
14793
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
14794
+ let canvas = Creator.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
14795
+ let sliceLeaf;
14796
+ if (slice) {
14797
+ sliceLeaf = leaf;
14798
+ sliceLeaf.__worldOpacity = 0;
14799
+ leaf = leafer || leaf;
14800
+ renderOptions.bounds = canvas.bounds;
14801
+ }
14802
+ canvas.save();
14803
+ if (isFrame && fill !== undefined) {
14804
+ const oldFill = leaf.get('fill');
14805
+ leaf.fill = '';
14806
+ leaf.__render(canvas, renderOptions);
14807
+ leaf.fill = oldFill;
14807
14808
  }
14808
14809
  else {
14809
- over({ data: false });
14810
+ leaf.__render(canvas, renderOptions);
14811
+ }
14812
+ canvas.restore();
14813
+ if (sliceLeaf)
14814
+ sliceLeaf.__updateWorldOpacity();
14815
+ if (trim) {
14816
+ trimBounds = getTrimBounds(canvas);
14817
+ const old = canvas, { width, height } = trimBounds;
14818
+ const config = { x: 0, y: 0, width, height, pixelRatio };
14819
+ canvas = Creator.canvas(config);
14820
+ canvas.copyWorld(old, trimBounds, config);
14810
14821
  }
14822
+ if (padding) {
14823
+ const [top, right, bottom, left] = MathHelper.fourNumber(padding);
14824
+ const old = canvas, { width, height } = old;
14825
+ canvas = Creator.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
14826
+ canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
14827
+ }
14828
+ if (needFill)
14829
+ canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
14830
+ if (onCanvas)
14831
+ onCanvas(canvas);
14832
+ const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
14833
+ result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
14834
+ }
14835
+ this.running = false;
14836
+ return result;
14837
+ },
14838
+ export(leaf, filename, options) {
14839
+ this.running = true;
14840
+ return addTask((success) => new Promise((resolve) => {
14841
+ const getResult = () => __awaiter(this, void 0, void 0, function* () {
14842
+ if (!Resource.isComplete)
14843
+ return Platform.requestRender(getResult);
14844
+ const result = ExportModule.syncExport(leaf, filename, options);
14845
+ if (result.data instanceof Promise)
14846
+ result.data = yield result.data;
14847
+ success(result);
14848
+ resolve();
14849
+ });
14850
+ leaf.updateLayout();
14851
+ checkLazy(leaf);
14852
+ const { leafer } = leaf;
14853
+ if (leafer)
14854
+ leafer.waitViewCompleted(getResult);
14855
+ else
14856
+ getResult();
14811
14857
  }));
14812
14858
  }
14813
14859
  };
@@ -14866,6 +14912,9 @@ ${filterStyle}
14866
14912
  exports.UI.prototype.export = function (filename, options) {
14867
14913
  return Export.export(this, filename, options);
14868
14914
  };
14915
+ exports.UI.prototype.syncExport = function (filename, options) {
14916
+ return Export.syncExport(this, filename, options);
14917
+ };
14869
14918
 
14870
14919
  const textCaseMap = {
14871
14920
  'none': 'none',
@@ -14974,10 +15023,10 @@ ${filterStyle}
14974
15023
  this.onFocus = this.onFocus.bind(this);
14975
15024
  this.onInput = this.onInput.bind(this);
14976
15025
  this.onUpdate = this.onUpdate.bind(this);
14977
- this.onEscape = this.onEscape.bind(this);
15026
+ this.onKeydown = this.onKeydown.bind(this);
14978
15027
  div.addEventListener("focus", this.onFocus);
14979
15028
  div.addEventListener("input", this.onInput);
14980
- window.addEventListener('keydown', this.onEscape);
15029
+ window.addEventListener('keydown', this.onKeydown);
14981
15030
  window.addEventListener('scroll', this.onUpdate);
14982
15031
  const selection = window.getSelection();
14983
15032
  const range = document.createRange();
@@ -14995,14 +15044,25 @@ ${filterStyle}
14995
15044
  }
14996
15045
  onInput() {
14997
15046
  const { editDom } = this;
14998
- this.editTarget.text = this.isHTMLText ? editDom.innerHTML : editDom.innerText.replace(/\n\n/, '\n');
15047
+ this.editTarget.text = this.isHTMLText ? editDom.innerHTML : editDom.innerText;
14999
15048
  }
15000
15049
  onFocus() {
15001
15050
  this.editDom.style.outline = 'none';
15002
15051
  }
15003
- onEscape(e) {
15052
+ onKeydown(e) {
15004
15053
  if (e.code === 'Escape')
15005
15054
  this.editor.closeInnerEditor();
15055
+ if (e.key === 'Enter') {
15056
+ e.preventDefault();
15057
+ const br = document.createElement('br');
15058
+ const selection = window.getSelection();
15059
+ const range = selection.getRangeAt(0);
15060
+ range.deleteContents();
15061
+ range.insertNode(br);
15062
+ range.setStartAfter(br);
15063
+ range.setEndAfter(br);
15064
+ this.onInput();
15065
+ }
15006
15066
  }
15007
15067
  onUpdate() {
15008
15068
  const { editTarget: text } = this;
@@ -15058,7 +15118,7 @@ ${filterStyle}
15058
15118
  editor.off_(this.eventIds);
15059
15119
  dom.removeEventListener("focus", this.onFocus);
15060
15120
  dom.removeEventListener("input", this.onInput);
15061
- window.removeEventListener('keydown', this.onEscape);
15121
+ window.removeEventListener('keydown', this.onKeydown);
15062
15122
  window.removeEventListener('scroll', this.onUpdate);
15063
15123
  dom.remove();
15064
15124
  this.editDom = this.eventIds = undefined;
@@ -15080,7 +15140,6 @@ ${filterStyle}
15080
15140
 
15081
15141
  exports.HTMLText = class HTMLText extends exports.Image {
15082
15142
  get __tag() { return 'HTMLText'; }
15083
- get editInner() { return 'TextEditor'; }
15084
15143
  constructor(data) {
15085
15144
  super(data);
15086
15145
  }
@@ -15125,6 +15184,9 @@ ${filterStyle}
15125
15184
  __decorate([
15126
15185
  boundsType('')
15127
15186
  ], exports.HTMLText.prototype, "text", void 0);
15187
+ __decorate([
15188
+ dataType('TextEditor')
15189
+ ], exports.HTMLText.prototype, "editInner", void 0);
15128
15190
  exports.HTMLText = __decorate([
15129
15191
  registerUI()
15130
15192
  ], exports.HTMLText);