@leafer-editor/worker 1.4.2 → 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
@@ -4073,12 +4073,11 @@ var LeaferUI = (function (exports) {
4073
4073
  if (defaultValue === undefined) {
4074
4074
  property.get = function () { return this[computedKey]; };
4075
4075
  }
4076
- else if (typeof defaultValue === 'object') {
4077
- const { clone } = DataHelper;
4076
+ else if (typeof defaultValue === 'function') {
4078
4077
  property.get = function () {
4079
4078
  let v = this[computedKey];
4080
4079
  if (v === undefined)
4081
- this[computedKey] = v = clone(defaultValue);
4080
+ this[computedKey] = v = defaultValue(this.__leaf);
4082
4081
  return v;
4083
4082
  };
4084
4083
  }
@@ -5725,10 +5724,10 @@ var LeaferUI = (function (exports) {
5725
5724
  static changeAttr(attrName, defaultValue, fn) {
5726
5725
  fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5727
5726
  }
5728
- static addAttr(attrName, defaultValue, fn) {
5727
+ static addAttr(attrName, defaultValue, fn, helpValue) {
5729
5728
  if (!fn)
5730
5729
  fn = boundsType;
5731
- fn(defaultValue)(this.prototype, attrName);
5730
+ fn(defaultValue, helpValue)(this.prototype, attrName);
5732
5731
  }
5733
5732
  __emitLifeEvent(type) {
5734
5733
  if (this.hasEvent(type))
@@ -6055,7 +6054,7 @@ var LeaferUI = (function (exports) {
6055
6054
  }
6056
6055
  }
6057
6056
 
6058
- const version = "1.4.2";
6057
+ const version = "1.5.0";
6059
6058
 
6060
6059
  class LeaferCanvas extends LeaferCanvasBase {
6061
6060
  get allowBackgroundColor() { return true; }
@@ -6942,7 +6941,11 @@ var LeaferUI = (function (exports) {
6942
6941
  setStyleName() { return Plugin.need('state'); },
6943
6942
  set() { return Plugin.need('state'); }
6944
6943
  };
6945
- const Transition = {};
6944
+ const Transition = {
6945
+ list: {},
6946
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6947
+ get(attrName) { return Transition.list[attrName]; }
6948
+ };
6946
6949
 
6947
6950
  const { parse, objectToCanvasData } = PathConvert;
6948
6951
  const emptyPaint = {};
@@ -7366,9 +7369,6 @@ var LeaferUI = (function (exports) {
7366
7369
  this.__drawPathByBox(pen);
7367
7370
  return pen;
7368
7371
  }
7369
- get editConfig() { return undefined; }
7370
- get editOuter() { return ''; }
7371
- get editInner() { return ''; }
7372
7372
  constructor(data) {
7373
7373
  super(data);
7374
7374
  }
@@ -7450,8 +7450,11 @@ var LeaferUI = (function (exports) {
7450
7450
  export(_filename, _options) {
7451
7451
  return Plugin.need('export');
7452
7452
  }
7453
+ syncExport(_filename, _options) {
7454
+ return Plugin.need('export');
7455
+ }
7453
7456
  clone(data) {
7454
- const json = this.toJSON();
7457
+ const json = DataHelper.clone(this.toJSON());
7455
7458
  if (data)
7456
7459
  Object.assign(json, data);
7457
7460
  return UI_1.one(json);
@@ -7750,7 +7753,7 @@ var LeaferUI = (function (exports) {
7750
7753
  get layoutLocked() { return !this.layouter.running; }
7751
7754
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7752
7755
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7753
- get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
7756
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7754
7757
  constructor(userConfig, data) {
7755
7758
  super(data);
7756
7759
  this.config = {
@@ -8052,6 +8055,10 @@ var LeaferUI = (function (exports) {
8052
8055
  getPagePointByClient(clientPoint, updateClient) {
8053
8056
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8054
8057
  }
8058
+ getClientPointByWorld(worldPoint) {
8059
+ const { x, y } = this.clientBounds;
8060
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
8061
+ }
8055
8062
  updateClientBounds() {
8056
8063
  this.canvas && this.canvas.updateClientBounds();
8057
8064
  }
@@ -9991,8 +9998,8 @@ var LeaferUI = (function (exports) {
9991
9998
  this.__drawRenderPath(canvas); };
9992
9999
 
9993
10000
  const matrix$2 = new Matrix();
9994
- const ui$3 = exports.UI.prototype;
9995
- ui$3.__updateHitCanvas = function () {
10001
+ const ui$2 = exports.UI.prototype;
10002
+ ui$2.__updateHitCanvas = function () {
9996
10003
  const data = this.__, { hitCanvasManager } = this.leafer;
9997
10004
  const isHitPixelFill = (data.__pixelFill || data.__isCanvas) && data.hitFill === 'pixel';
9998
10005
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
@@ -10019,9 +10026,7 @@ var LeaferUI = (function (exports) {
10019
10026
  this.__drawHitPath(h);
10020
10027
  h.setStrokeOptions(data);
10021
10028
  };
10022
- ui$3.__hit = function (inner) {
10023
- if (Platform.name === 'miniapp')
10024
- this.__drawHitPath(this.__hitCanvas);
10029
+ ui$2.__hit = function (inner) {
10025
10030
  const data = this.__;
10026
10031
  if (data.__isHitPixel && this.__hitPixel(inner))
10027
10032
  return true;
@@ -10059,15 +10064,15 @@ var LeaferUI = (function (exports) {
10059
10064
  return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
10060
10065
  };
10061
10066
 
10062
- 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;
10063
10068
  rect.__updateHitCanvas = box$1.__updateHitCanvas = function () {
10064
10069
  if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
10065
- ui$2.__updateHitCanvas.call(this);
10070
+ ui$1.__updateHitCanvas.call(this);
10066
10071
  else if (this.__hitCanvas)
10067
10072
  this.__hitCanvas = null;
10068
10073
  };
10069
10074
  rect.__hitFill = box$1.__hitFill = function (inner) {
10070
- 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);
10071
10076
  };
10072
10077
 
10073
10078
  function getSelector$1(ui) {
@@ -11376,13 +11381,14 @@ var LeaferUI = (function (exports) {
11376
11381
  }
11377
11382
 
11378
11383
  function layoutText(drawData, style) {
11379
- const { rows, bounds } = drawData;
11384
+ const { rows, bounds } = drawData, countRows = rows.length;
11380
11385
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
11381
- 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);
11382
11387
  let starY = __baseLine;
11383
11388
  if (__clipText && realHeight > height) {
11384
11389
  realHeight = Math.max(height, __lineHeight);
11385
- drawData.overflow = rows.length;
11390
+ if (countRows > 1)
11391
+ drawData.overflow = countRows;
11386
11392
  }
11387
11393
  else if (height || autoSizeAlign) {
11388
11394
  switch (verticalAlign) {
@@ -11394,7 +11400,7 @@ var LeaferUI = (function (exports) {
11394
11400
  }
11395
11401
  starY += y;
11396
11402
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
11397
- for (let i = 0, len = rows.length; i < len; i++) {
11403
+ for (let i = 0, len = countRows; i < len; i++) {
11398
11404
  row = rows[i];
11399
11405
  row.x = x;
11400
11406
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -11463,7 +11469,7 @@ var LeaferUI = (function (exports) {
11463
11469
  if (i === end && charRight < right) {
11464
11470
  break;
11465
11471
  }
11466
- else if (charRight < right && char.char !== ' ') {
11472
+ else if ((charRight < right && char.char !== ' ') || !i) {
11467
11473
  row.data.splice(i + 1);
11468
11474
  row.width -= char.width;
11469
11475
  break;
@@ -11615,6 +11621,7 @@ var LeaferUI = (function (exports) {
11615
11621
  super(type, data);
11616
11622
  }
11617
11623
  }
11624
+ EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
11618
11625
  EditorMoveEvent.MOVE = 'editor.move';
11619
11626
 
11620
11627
  class EditorScaleEvent extends EditorEvent {
@@ -11622,6 +11629,7 @@ var LeaferUI = (function (exports) {
11622
11629
  super(type, data);
11623
11630
  }
11624
11631
  }
11632
+ EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
11625
11633
  EditorScaleEvent.SCALE = 'editor.scale';
11626
11634
 
11627
11635
  class EditorRotateEvent extends EditorEvent {
@@ -11629,6 +11637,7 @@ var LeaferUI = (function (exports) {
11629
11637
  super(type, data);
11630
11638
  }
11631
11639
  }
11640
+ EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
11632
11641
  EditorRotateEvent.ROTATE = 'editor.rotate';
11633
11642
 
11634
11643
  class EditorSkewEvent extends EditorEvent {
@@ -11636,6 +11645,7 @@ var LeaferUI = (function (exports) {
11636
11645
  super(type, data);
11637
11646
  }
11638
11647
  }
11648
+ EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
11639
11649
  EditorSkewEvent.SKEW = 'editor.skew';
11640
11650
 
11641
11651
  function targetAttr(fn) {
@@ -11688,7 +11698,7 @@ var LeaferUI = (function (exports) {
11688
11698
  for (let i = 0; i < list.length; i++) {
11689
11699
  leaf = list[i];
11690
11700
  const { worldTransform, worldRenderBounds } = leaf;
11691
- if (!bounds || bounds.hit(worldRenderBounds, options.matrix)) {
11701
+ if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
11692
11702
  const aScaleX = abs$1(worldTransform.scaleX), aScaleY = abs$1(worldTransform.scaleY);
11693
11703
  if (aScaleX !== aScaleY) {
11694
11704
  copy$2(matrix$1, worldTransform);
@@ -11814,9 +11824,9 @@ var LeaferUI = (function (exports) {
11814
11824
  }
11815
11825
  onSelect() {
11816
11826
  if (this.running) {
11817
- const { mergeConfig: config, list } = this.editor;
11818
- const { stroke, strokeWidth } = config;
11819
- 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 || {})));
11820
11830
  this.hoverStroker.target = null;
11821
11831
  }
11822
11832
  }
@@ -12003,7 +12013,7 @@ var LeaferUI = (function (exports) {
12003
12013
  const EditDataHelper = {
12004
12014
  getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
12005
12015
  let align, origin = {}, scaleX = 1, scaleY = 1;
12006
- const { boxBounds, widthRange, heightRange, dragBounds } = element;
12016
+ const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = element;
12007
12017
  const { width, height } = startBounds;
12008
12018
  if (around) {
12009
12019
  totalMove.x *= 2;
@@ -12017,10 +12027,6 @@ var LeaferUI = (function (exports) {
12017
12027
  const changedScaleY = scaleMode ? originChangedScaleY : signY * boxBounds.height / height;
12018
12028
  totalMove.x *= scaleMode ? originChangedScaleX : signX;
12019
12029
  totalMove.y *= scaleMode ? originChangedScaleY : signY;
12020
- if (Math.abs(totalMove.x) === width)
12021
- totalMove.x += 0.1;
12022
- if (Math.abs(totalMove.y) === height)
12023
- totalMove.y += 0.1;
12024
12030
  const topScale = (-totalMove.y + height) / height;
12025
12031
  const rightScale = (totalMove.x + width) / width;
12026
12032
  const bottomScale = (totalMove.y + height) / height;
@@ -12110,6 +12116,10 @@ var LeaferUI = (function (exports) {
12110
12116
  const nowHeight = boxBounds.height * element.scaleY;
12111
12117
  scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
12112
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;
12113
12123
  return { origin, scaleX, scaleY, direction, lockRatio, around };
12114
12124
  },
12115
12125
  getRotateData(bounds, direction, current, last, around) {
@@ -12238,7 +12248,7 @@ var LeaferUI = (function (exports) {
12238
12248
  let { rotation } = editBox;
12239
12249
  const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
12240
12250
  const { pointType } = point, { flippedX, flippedY } = editBox;
12241
- let showResize = pointType === 'resize';
12251
+ let showResize = pointType.includes('resize');
12242
12252
  if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
12243
12253
  showResize = false;
12244
12254
  const showSkew = skewable && !showResize && point.name === 'resize-line';
@@ -12265,7 +12275,7 @@ var LeaferUI = (function (exports) {
12265
12275
  class EditPoint extends exports.Box {
12266
12276
  }
12267
12277
 
12268
- const fourDirection = ['top', 'right', 'bottom', 'left'];
12278
+ const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
12269
12279
  class EditBox extends exports.Group {
12270
12280
  get flipped() { return this.flippedX || this.flippedY; }
12271
12281
  get flippedX() { return this.scaleX < 0; }
@@ -12280,6 +12290,7 @@ var LeaferUI = (function (exports) {
12280
12290
  this.resizePoints = [];
12281
12291
  this.rotatePoints = [];
12282
12292
  this.resizeLines = [];
12293
+ this.dragStartData = {};
12283
12294
  this.__eventIds = [];
12284
12295
  this.editor = editor;
12285
12296
  this.visible = false;
@@ -12321,7 +12332,7 @@ var LeaferUI = (function (exports) {
12321
12332
  resizeP.rotation = (i / 2) * 90;
12322
12333
  }
12323
12334
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
12324
- rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
12335
+ rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
12325
12336
  rect.hittable = !single;
12326
12337
  rect.syncEventer = single && this.editor;
12327
12338
  if (single) {
@@ -12330,14 +12341,14 @@ var LeaferUI = (function (exports) {
12330
12341
  }
12331
12342
  }
12332
12343
  update(bounds) {
12333
- 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;
12334
12347
  if (this.view.worldOpacity) {
12335
- const { mergeConfig } = this.editor;
12336
12348
  const { width, height } = bounds;
12337
12349
  const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
12338
- const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig;
12339
12350
  const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
12340
- const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
12351
+ const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
12341
12352
  let point = {}, rotateP, resizeP, resizeL;
12342
12353
  for (let i = 0; i < 8; i++) {
12343
12354
  AroundHelper.toPoint(AroundHelper.directionData[i], bounds, point);
@@ -12353,13 +12364,13 @@ var LeaferUI = (function (exports) {
12353
12364
  resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
12354
12365
  if (((i + 1) / 2) % 2) {
12355
12366
  resizeL.width = width;
12356
- if (resizeP.width > width - 30)
12367
+ if (hideOnSmall && resizeP.width * 2 > width)
12357
12368
  resizeP.visible = false;
12358
12369
  }
12359
12370
  else {
12360
12371
  resizeL.height = height;
12361
12372
  resizeP.rotation = 90;
12362
- if (resizeP.width > height - 30)
12373
+ if (hideOnSmall && resizeP.width * 2 > height)
12363
12374
  resizeP.visible = false;
12364
12375
  }
12365
12376
  }
@@ -12369,7 +12380,7 @@ var LeaferUI = (function (exports) {
12369
12380
  this.layoutCircle(mergeConfig);
12370
12381
  if (rect.path)
12371
12382
  rect.path = null;
12372
- rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
12383
+ rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
12373
12384
  buttons.visible = showPoints && buttons.children.length > 0;
12374
12385
  if (buttons.visible)
12375
12386
  this.layoutButtons(mergeConfig);
@@ -12416,7 +12427,7 @@ var LeaferUI = (function (exports) {
12416
12427
  }
12417
12428
  getPointStyle(userStyle) {
12418
12429
  const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
12419
- 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 };
12420
12431
  return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
12421
12432
  }
12422
12433
  getPointsStyle() {
@@ -12436,34 +12447,32 @@ var LeaferUI = (function (exports) {
12436
12447
  }
12437
12448
  onDragStart(e) {
12438
12449
  this.dragging = true;
12439
- const { editor } = this;
12440
- if (e.current.name === 'rect') {
12450
+ const point = this.dragPoint = e.current;
12451
+ const { editor, dragStartData } = this, { element } = editor;
12452
+ if (point.name === 'rect') {
12441
12453
  this.moving = true;
12442
- editor.dragStartPoint = { x: editor.element.x, y: editor.element.y };
12443
12454
  editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
12444
12455
  }
12445
- else if (e.current.pointType === 'resize') {
12446
- editor.dragStartBounds = Object.assign({}, editor.element.getLayoutBounds('box', 'local'));
12447
- editor.resizeDirection = e.current.direction;
12448
- }
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;
12449
12461
  }
12450
12462
  onDragEnd(e) {
12451
12463
  this.dragging = false;
12464
+ this.dragPoint = null;
12452
12465
  this.moving = false;
12453
12466
  if (e.current.name === 'rect')
12454
12467
  this.editor.opacity = 1;
12455
- this.editor.resizeDirection = undefined;
12456
12468
  }
12457
12469
  onDrag(e) {
12458
12470
  const { editor } = this;
12459
- const point = this.enterPoint = e.current;
12460
- if (point.pointType === 'rotate' || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
12461
- if (editor.mergeConfig.rotateable)
12462
- editor.onRotate(e);
12463
- }
12464
- 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'))
12465
12475
  editor.onScale(e);
12466
- }
12467
12476
  updateCursor(editor, e);
12468
12477
  }
12469
12478
  onArrow(e) {
@@ -12641,6 +12650,7 @@ ${filterStyle}
12641
12650
  rotateCursor: { url: rotateSVG, x: 12, y: 12 },
12642
12651
  skewCursor: { url: skewSVG, x: 12, y: 12 },
12643
12652
  selector: true,
12653
+ editBox: true,
12644
12654
  hover: true,
12645
12655
  select: 'press',
12646
12656
  openInner: 'double',
@@ -12670,7 +12680,11 @@ ${filterStyle}
12670
12680
  function onTarget(editor, oldValue) {
12671
12681
  const { target } = editor;
12672
12682
  if (target) {
12673
- 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
+ }
12674
12688
  if (editor.multiple)
12675
12689
  simulate(editor);
12676
12690
  }
@@ -12697,6 +12711,9 @@ ${filterStyle}
12697
12711
  function onHover(editor, oldValue) {
12698
12712
  editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
12699
12713
  }
12714
+ function checkEditable(item) {
12715
+ return item.editable && !item.locked;
12716
+ }
12700
12717
 
12701
12718
  const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
12702
12719
  const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
@@ -12794,10 +12811,13 @@ ${filterStyle}
12794
12811
  super(type, data);
12795
12812
  }
12796
12813
  }
12814
+ EditorGroupEvent.BEFORE_GROUP = 'editor.before_group';
12797
12815
  EditorGroupEvent.GROUP = 'editor.group';
12798
12816
  EditorGroupEvent.BEFORE_UNGROUP = 'editor.before_ungroup';
12799
12817
  EditorGroupEvent.UNGROUP = 'editor.ungroup';
12818
+ EditorGroupEvent.BEFORE_OPEN = 'editor.before_open_group';
12800
12819
  EditorGroupEvent.OPEN = 'editor.open_group';
12820
+ EditorGroupEvent.BEFORE_CLOSE = 'editor.before_close_group';
12801
12821
  EditorGroupEvent.CLOSE = 'editor.close_group';
12802
12822
 
12803
12823
  const { updateMatrix } = LeafHelper;
@@ -12860,8 +12880,20 @@ ${filterStyle}
12860
12880
 
12861
12881
  class Editor extends exports.Group {
12862
12882
  get mergeConfig() {
12863
- const { element, config } = this;
12864
- 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;
12865
12897
  }
12866
12898
  get list() { return this.leafList.list; }
12867
12899
  get dragHoverExclude() { return [this.editBox.rect]; }
@@ -12871,6 +12903,7 @@ ${filterStyle}
12871
12903
  get single() { return this.list.length === 1; }
12872
12904
  get dragging() { return this.editBox.dragging; }
12873
12905
  get moving() { return this.editBox.moving; }
12906
+ get dragPoint() { return this.editBox.dragPoint; }
12874
12907
  get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
12875
12908
  get buttons() { return this.editBox.buttons; }
12876
12909
  constructor(userConfig, data) {
@@ -12961,7 +12994,7 @@ ${filterStyle}
12961
12994
  else
12962
12995
  total.x = 0;
12963
12996
  }
12964
- this.move(exports.DragEvent.getValidMove(this.element, this.dragStartPoint, total));
12997
+ this.move(exports.DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total));
12965
12998
  }
12966
12999
  }
12967
13000
  onScale(e) {
@@ -12975,7 +13008,7 @@ ${filterStyle}
12975
13008
  const { direction } = e.current;
12976
13009
  if (e.shiftKey || element.lockRatio)
12977
13010
  lockRatio = true;
12978
- 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');
12979
13012
  if (this.editTool.onScaleWithDrag) {
12980
13013
  data.drag = e;
12981
13014
  this.scaleWithDrag(data);
@@ -12990,26 +13023,29 @@ ${filterStyle}
12990
13023
  const { direction, name } = e.current;
12991
13024
  if (skewable && name === 'resize-line')
12992
13025
  return this.onSkew(e);
12993
- const { element } = this;
13026
+ const { element } = this, { dragStartData } = this.editBox;
12994
13027
  let origin, rotation;
12995
13028
  if (e instanceof exports.RotateEvent) {
12996
13029
  if (rotateable === 'rotate')
12997
13030
  e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e);
12998
13031
  else
12999
13032
  return;
13033
+ if (element.scaleX * element.scaleY < 0)
13034
+ rotation = -rotation;
13000
13035
  }
13001
13036
  else {
13002
- const last = { x: e.x - e.moveX, y: e.y - e.moveY };
13003
- 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'));
13004
13038
  rotation = data.rotation;
13005
13039
  origin = data.origin;
13006
13040
  }
13007
- rotation = MathHelper.getGapRotation(rotation, rotateGap, element.rotation);
13008
- if (!rotation)
13009
- return;
13010
13041
  if (element.scaleX * element.scaleY < 0)
13011
13042
  rotation = -rotation;
13012
- 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);
13013
13049
  }
13014
13050
  onSkew(e) {
13015
13051
  const { element } = this;
@@ -13026,7 +13062,9 @@ ${filterStyle}
13026
13062
  const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
13027
13063
  if (this.multiple)
13028
13064
  element.safeChange(() => element.move(x, y));
13029
- 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);
13030
13068
  this.editTool.onMove(event);
13031
13069
  this.emitEvent(event);
13032
13070
  }
@@ -13034,7 +13072,9 @@ ${filterStyle}
13034
13072
  if (!this.checkTransform('resizeable'))
13035
13073
  return;
13036
13074
  const { element } = this;
13037
- 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);
13038
13078
  this.editTool.onScaleWithDrag(event);
13039
13079
  this.emitEvent(event);
13040
13080
  }
@@ -13044,7 +13084,9 @@ ${filterStyle}
13044
13084
  const { element } = this;
13045
13085
  const worldOrigin = this.getWorldOrigin(origin);
13046
13086
  const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.scaleOf(origin, scaleX, scaleY)));
13047
- 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);
13048
13090
  this.editTool.onScale(event);
13049
13091
  this.emitEvent(event);
13050
13092
  }
@@ -13054,7 +13096,9 @@ ${filterStyle}
13054
13096
  const { element } = this;
13055
13097
  const worldOrigin = this.getWorldOrigin('center');
13056
13098
  const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(element, axis));
13057
- 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);
13058
13102
  this.editTool.onScale(event);
13059
13103
  this.emitEvent(event);
13060
13104
  }
@@ -13064,7 +13108,9 @@ ${filterStyle}
13064
13108
  const { element } = this;
13065
13109
  const worldOrigin = this.getWorldOrigin(origin);
13066
13110
  const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.rotateOf(origin, rotation)));
13067
- 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);
13068
13114
  this.editTool.onRotate(event);
13069
13115
  this.emitEvent(event);
13070
13116
  }
@@ -13074,7 +13120,9 @@ ${filterStyle}
13074
13120
  const { element } = this;
13075
13121
  const worldOrigin = this.getWorldOrigin(origin);
13076
13122
  const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.skewOf(origin, skewX, skewY)));
13077
- 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);
13078
13126
  this.editTool.onSkew(event);
13079
13127
  this.emitEvent(event);
13080
13128
  }
@@ -13092,6 +13140,7 @@ ${filterStyle}
13092
13140
  }
13093
13141
  group(userGroup) {
13094
13142
  if (this.multiple) {
13143
+ this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
13095
13144
  this.target = EditorHelper.group(this.list, this.element, userGroup);
13096
13145
  this.emitGroupEvent(EditorGroupEvent.GROUP, this.target);
13097
13146
  }
@@ -13107,11 +13156,13 @@ ${filterStyle}
13107
13156
  return this.list;
13108
13157
  }
13109
13158
  openGroup(group) {
13159
+ this.emitGroupEvent(EditorGroupEvent.BEFORE_OPEN, group);
13110
13160
  this.openedGroupList.add(group);
13111
13161
  group.hitChildren = true;
13112
13162
  this.emitGroupEvent(EditorGroupEvent.OPEN, group);
13113
13163
  }
13114
13164
  closeGroup(group) {
13165
+ this.emitGroupEvent(EditorGroupEvent.BEFORE_CLOSE, group);
13115
13166
  this.openedGroupList.remove(group);
13116
13167
  group.hitChildren = false;
13117
13168
  this.emitGroupEvent(EditorGroupEvent.CLOSE, group);
@@ -13140,7 +13191,8 @@ ${filterStyle}
13140
13191
  emitGroupEvent(type, group) {
13141
13192
  const event = new EditorGroupEvent(type, { editTarget: group });
13142
13193
  this.emitEvent(event);
13143
- group.emitEvent(event);
13194
+ if (group)
13195
+ group.emitEvent(event);
13144
13196
  }
13145
13197
  openInnerEditor(target, select) {
13146
13198
  if (target && select)
@@ -13557,16 +13609,14 @@ ${filterStyle}
13557
13609
  leaf.height *= scaleY;
13558
13610
  }
13559
13611
  }
13560
- function scaleResizeFontSize(leaf, scaleX, scaleY) {
13561
- const { app } = leaf;
13562
- const editor = app && app.editor;
13612
+ function scaleResizeFontSize(leaf, scaleX, scaleY, direction) {
13563
13613
  let fontScale = scaleX;
13564
- if (editor.editing) {
13614
+ if (direction !== undefined) {
13565
13615
  const layout = leaf.__layout;
13566
13616
  let { width, height } = layout.boxBounds;
13567
13617
  width *= scaleY - scaleX;
13568
13618
  height *= scaleX - scaleY;
13569
- switch (editor.resizeDirection) {
13619
+ switch (direction) {
13570
13620
  case top:
13571
13621
  case bottom:
13572
13622
  fontScale = scaleY;
@@ -13634,8 +13684,9 @@ ${filterStyle}
13634
13684
  this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
13635
13685
  };
13636
13686
  exports.Text.prototype.__scaleResize = function (scaleX, scaleY) {
13637
- if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
13638
- 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);
13639
13690
  }
13640
13691
  else {
13641
13692
  scaleResize(this, scaleX, scaleY);
@@ -13684,34 +13735,15 @@ ${filterStyle}
13684
13735
 
13685
13736
  Plugin.add('editor', 'resize');
13686
13737
  Creator.editor = function (options) { return new Editor(options); };
13687
- dataType(false)(exports.Box.prototype, 'textBox');
13688
- defineKey(exports.UI.prototype, 'editOuter', {
13689
- get() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
13690
- });
13691
- defineKey(exports.UI.prototype, 'editInner', {
13692
- get() { return 'PathEditor'; }
13693
- });
13694
- defineKey(exports.Group.prototype, 'editInner', {
13695
- get() { return ''; }
13696
- });
13697
- defineKey(exports.Text.prototype, 'editInner', {
13698
- get() { return 'TextEditor'; }
13699
- });
13700
- exports.UI.setEditConfig = function (config) {
13701
- defineKey(this.prototype, 'editConfig', {
13702
- get() { return typeof config === 'function' ? config(this) : config; }
13703
- });
13704
- };
13705
- exports.UI.setEditOuter = function (toolName) {
13706
- defineKey(this.prototype, 'editOuter', {
13707
- get() { return typeof toolName === 'string' ? toolName : toolName(this); }
13708
- });
13709
- };
13710
- exports.UI.setEditInner = function (editorName) {
13711
- defineKey(this.prototype, 'editInner', {
13712
- get() { return typeof editorName === 'string' ? editorName : editorName(this); }
13713
- });
13714
- };
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); };
13715
13747
 
13716
13748
  function addViewport(leafer, mergeConfig, custom) {
13717
13749
  addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig);
@@ -13722,10 +13754,8 @@ ${filterStyle}
13722
13754
  }), leafer.on_(exports.ZoomEvent.BEFORE_ZOOM, (e) => {
13723
13755
  const { zoomLayer } = leafer;
13724
13756
  const changeScale = leafer.getValidScale(e.scale);
13725
- if (changeScale !== 1) {
13726
- PointHelper.scaleOf(zoomLayer, e, changeScale);
13727
- zoomLayer.scale = zoomLayer.__.scaleX * changeScale;
13728
- }
13757
+ if (changeScale !== 1)
13758
+ zoomLayer.scaleOfWorld(e, changeScale);
13729
13759
  }));
13730
13760
  }
13731
13761
  function addViewportConfig(leafer, mergeConfig) {
@@ -13952,7 +13982,7 @@ ${filterStyle}
13952
13982
  changeScale = min / scaleX;
13953
13983
  else if (max && absScale > max)
13954
13984
  changeScale = max / scaleX;
13955
- return disabled ? 1 : MathHelper.float(changeScale);
13985
+ return disabled ? 1 : changeScale;
13956
13986
  };
13957
13987
 
13958
13988
  function getMoveEventData(move, event) {
@@ -14093,7 +14123,7 @@ ${filterStyle}
14093
14123
  const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds();
14094
14124
  const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
14095
14125
  let changeScale;
14096
- const { scaleX } = this.__;
14126
+ const { x, y, scaleX, scaleY } = zoomLayer.__;
14097
14127
  if (typeof zoomType === 'string') {
14098
14128
  switch (zoomType) {
14099
14129
  case 'in':
@@ -14123,7 +14153,6 @@ ${filterStyle}
14123
14153
  zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition);
14124
14154
  }
14125
14155
  else if (typeof zoomType === 'object') {
14126
- const { x, y, scaleX, scaleY } = zoomLayer;
14127
14156
  const data = { x, y, scaleX, scaleY };
14128
14157
  const isArray = zoomType instanceof Array;
14129
14158
  if (isArray || zoomType.tag) {
@@ -14271,6 +14300,18 @@ ${filterStyle}
14271
14300
  class ArrowData extends LineData {
14272
14301
  }
14273
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
+
14274
14315
  exports.Arrow = class Arrow extends exports.Line {
14275
14316
  get __tag() { return 'Arrow'; }
14276
14317
  constructor(data) {
@@ -14282,7 +14323,7 @@ ${filterStyle}
14282
14323
  dataProcessor(ArrowData)
14283
14324
  ], exports.Arrow.prototype, "__", void 0);
14284
14325
  __decorate([
14285
- strokeType('angle')
14326
+ arrowType('angle')
14286
14327
  ], exports.Arrow.prototype, "endArrow", void 0);
14287
14328
  exports.Arrow = __decorate([
14288
14329
  registerUI()
@@ -14515,22 +14556,9 @@ ${filterStyle}
14515
14556
  data[startIndex + 1] = point.y;
14516
14557
  }
14517
14558
 
14518
- function arrowType(defaultValue) {
14519
- return decorateLeafAttr(defaultValue, (key) => attr({
14520
- set(value) {
14521
- if (this.__setAttr(key, value)) {
14522
- const data = this.__;
14523
- data.__useArrow = data.startArrow !== 'none' || data.endArrow !== 'none';
14524
- doStrokeType(this);
14525
- }
14526
- }
14527
- }));
14528
- }
14529
-
14530
14559
  Plugin.add('arrow');
14531
- const ui$1 = exports.UI.prototype;
14532
- arrowType('none')(ui$1, 'startArrow');
14533
- arrowType('none')(ui$1, 'endArrow');
14560
+ exports.UI.addAttr('startArrow', 'none', arrowType);
14561
+ exports.UI.addAttr('endArrow', 'none', arrowType);
14534
14562
  Object.assign(PathArrow, PathArrowModule);
14535
14563
 
14536
14564
  const { Yes, NoAndSkip, YesAndSkip } = exports.Answer;
@@ -14698,124 +14726,134 @@ ${filterStyle}
14698
14726
  }
14699
14727
 
14700
14728
  const ExportModule = {
14701
- export(leaf, filename, options) {
14729
+ syncExport(leaf, filename, options) {
14702
14730
  this.running = true;
14731
+ let result;
14703
14732
  const fileType = FileHelper.fileType(filename);
14704
14733
  const isDownload = filename.includes('.');
14705
14734
  options = FileHelper.getExportOptions(options);
14706
- return addTask((success) => new Promise((resolve) => {
14707
- const over = (result) => {
14708
- success(result);
14709
- resolve();
14710
- this.running = false;
14711
- };
14712
- const { toURL } = Platform;
14713
- const { download } = Platform.origin;
14714
- if (fileType === 'json') {
14715
- isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
14716
- return over({ data: isDownload ? true : leaf.toJSON(options.json) });
14717
- }
14718
- if (fileType === 'svg') {
14719
- isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
14720
- 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;
14721
14756
  }
14722
- const { leafer } = leaf;
14723
- if (leafer) {
14724
- checkLazy(leaf);
14725
- leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
14726
- let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
14727
- const { worldTransform, isLeafer, isFrame } = leaf;
14728
- const { slice, trim, padding, onCanvas } = options;
14729
- const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
14730
- const contextSettings = options.contextSettings || leafer.config.contextSettings;
14731
- const screenshot = options.screenshot || leaf.isApp;
14732
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
14733
- const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
14734
- if (screenshot) {
14735
- renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
14736
- }
14737
- else {
14738
- let relative = options.relative || (isLeafer ? 'inner' : 'local');
14739
- scaleX = worldTransform.scaleX;
14740
- scaleY = worldTransform.scaleY;
14741
- switch (relative) {
14742
- case 'inner':
14743
- matrix.set(worldTransform);
14744
- break;
14745
- case 'local':
14746
- matrix.set(worldTransform).divide(leaf.localTransform);
14747
- scaleX /= leaf.scaleX;
14748
- scaleY /= leaf.scaleY;
14749
- break;
14750
- case 'world':
14751
- scaleX = 1;
14752
- scaleY = 1;
14753
- break;
14754
- case 'page':
14755
- relative = leaf.leafer;
14756
- default:
14757
- matrix.set(worldTransform).divide(leaf.getTransform(relative));
14758
- const l = relative.worldTransform;
14759
- scaleX /= scaleX / l.scaleX;
14760
- scaleY /= scaleY / l.scaleY;
14761
- }
14762
- renderBounds = leaf.getBounds('render', relative);
14763
- }
14764
- const scaleData = { scaleX: 1, scaleY: 1 };
14765
- MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
14766
- let pixelRatio = options.pixelRatio || 1;
14767
- if (leaf.isApp) {
14768
- scaleData.scaleX *= pixelRatio;
14769
- scaleData.scaleY *= pixelRatio;
14770
- pixelRatio = leaf.app.pixelRatio;
14771
- }
14772
- const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
14773
- const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
14774
- let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
14775
- let sliceLeaf;
14776
- if (slice) {
14777
- sliceLeaf = leaf;
14778
- sliceLeaf.__worldOpacity = 0;
14779
- leaf = leafer;
14780
- renderOptions.bounds = canvas.bounds;
14781
- }
14782
- canvas.save();
14783
- if (isFrame && fill !== undefined) {
14784
- const oldFill = leaf.get('fill');
14785
- leaf.fill = '';
14786
- leaf.__render(canvas, renderOptions);
14787
- leaf.fill = oldFill;
14788
- }
14789
- else {
14790
- leaf.__render(canvas, renderOptions);
14791
- }
14792
- canvas.restore();
14793
- if (sliceLeaf)
14794
- sliceLeaf.__updateWorldOpacity();
14795
- if (trim) {
14796
- trimBounds = getTrimBounds(canvas);
14797
- const old = canvas, { width, height } = trimBounds;
14798
- const config = { x: 0, y: 0, width, height, pixelRatio };
14799
- canvas = Creator.canvas(config);
14800
- canvas.copyWorld(old, trimBounds, config);
14801
- }
14802
- if (padding) {
14803
- const [top, right, bottom, left] = MathHelper.fourNumber(padding);
14804
- const old = canvas, { width, height } = old;
14805
- canvas = Creator.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
14806
- canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
14807
- }
14808
- if (needFill)
14809
- canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
14810
- if (onCanvas)
14811
- onCanvas(canvas);
14812
- const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
14813
- over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
14814
- }));
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;
14815
14808
  }
14816
14809
  else {
14817
- 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);
14818
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();
14819
14857
  }));
14820
14858
  }
14821
14859
  };
@@ -14874,6 +14912,9 @@ ${filterStyle}
14874
14912
  exports.UI.prototype.export = function (filename, options) {
14875
14913
  return Export.export(this, filename, options);
14876
14914
  };
14915
+ exports.UI.prototype.syncExport = function (filename, options) {
14916
+ return Export.syncExport(this, filename, options);
14917
+ };
14877
14918
 
14878
14919
  const textCaseMap = {
14879
14920
  'none': 'none',
@@ -14982,10 +15023,10 @@ ${filterStyle}
14982
15023
  this.onFocus = this.onFocus.bind(this);
14983
15024
  this.onInput = this.onInput.bind(this);
14984
15025
  this.onUpdate = this.onUpdate.bind(this);
14985
- this.onEscape = this.onEscape.bind(this);
15026
+ this.onKeydown = this.onKeydown.bind(this);
14986
15027
  div.addEventListener("focus", this.onFocus);
14987
15028
  div.addEventListener("input", this.onInput);
14988
- window.addEventListener('keydown', this.onEscape);
15029
+ window.addEventListener('keydown', this.onKeydown);
14989
15030
  window.addEventListener('scroll', this.onUpdate);
14990
15031
  const selection = window.getSelection();
14991
15032
  const range = document.createRange();
@@ -15003,14 +15044,25 @@ ${filterStyle}
15003
15044
  }
15004
15045
  onInput() {
15005
15046
  const { editDom } = this;
15006
- this.editTarget.text = this.isHTMLText ? editDom.innerHTML : editDom.innerText.replace(/\n\n/, '\n');
15047
+ this.editTarget.text = this.isHTMLText ? editDom.innerHTML : editDom.innerText;
15007
15048
  }
15008
15049
  onFocus() {
15009
15050
  this.editDom.style.outline = 'none';
15010
15051
  }
15011
- onEscape(e) {
15052
+ onKeydown(e) {
15012
15053
  if (e.code === 'Escape')
15013
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
+ }
15014
15066
  }
15015
15067
  onUpdate() {
15016
15068
  const { editTarget: text } = this;
@@ -15066,7 +15118,7 @@ ${filterStyle}
15066
15118
  editor.off_(this.eventIds);
15067
15119
  dom.removeEventListener("focus", this.onFocus);
15068
15120
  dom.removeEventListener("input", this.onInput);
15069
- window.removeEventListener('keydown', this.onEscape);
15121
+ window.removeEventListener('keydown', this.onKeydown);
15070
15122
  window.removeEventListener('scroll', this.onUpdate);
15071
15123
  dom.remove();
15072
15124
  this.editDom = this.eventIds = undefined;
@@ -15088,7 +15140,6 @@ ${filterStyle}
15088
15140
 
15089
15141
  exports.HTMLText = class HTMLText extends exports.Image {
15090
15142
  get __tag() { return 'HTMLText'; }
15091
- get editInner() { return 'TextEditor'; }
15092
15143
  constructor(data) {
15093
15144
  super(data);
15094
15145
  }
@@ -15133,6 +15184,9 @@ ${filterStyle}
15133
15184
  __decorate([
15134
15185
  boundsType('')
15135
15186
  ], exports.HTMLText.prototype, "text", void 0);
15187
+ __decorate([
15188
+ dataType('TextEditor')
15189
+ ], exports.HTMLText.prototype, "editInner", void 0);
15136
15190
  exports.HTMLText = __decorate([
15137
15191
  registerUI()
15138
15192
  ], exports.HTMLText);