@leafer-ui/draw 1.0.0-rc.22 → 1.0.0-rc.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/draw.cjs CHANGED
@@ -53,10 +53,11 @@ function stateType(defaultValue) {
53
53
  function arrowType(defaultValue) {
54
54
  return core.decorateLeafAttr(defaultValue, (key) => core.attr({
55
55
  set(value) {
56
- this.__setAttr(key, value);
57
- const data = this.__;
58
- data.__useArrow = data.startArrow !== 'none' || data.endArrow !== 'none';
59
- core.doStrokeType(this);
56
+ if (this.__setAttr(key, value)) {
57
+ const data = this.__;
58
+ data.__useArrow = data.startArrow !== 'none' || data.endArrow !== 'none';
59
+ core.doStrokeType(this);
60
+ }
60
61
  }
61
62
  }));
62
63
  }
@@ -229,7 +230,7 @@ class UIData extends core.LeafData {
229
230
  const UnitConvert = {
230
231
  number(value, percentRefer) {
231
232
  if (typeof value === 'object')
232
- return value.type === 'percent' ? value.value / 100 * percentRefer : value.value;
233
+ return value.type === 'percent' ? value.value * percentRefer : value.value;
233
234
  return value;
234
235
  }
235
236
  };
@@ -238,7 +239,7 @@ class GroupData extends UIData {
238
239
  }
239
240
 
240
241
  class BoxData extends GroupData {
241
- get __boxStroke() { return true; }
242
+ get __boxStroke() { return !this.__pathInputed; }
242
243
  }
243
244
 
244
245
  class LeaferData extends GroupData {
@@ -251,11 +252,11 @@ class LineData extends UIData {
251
252
  }
252
253
 
253
254
  class RectData extends UIData {
254
- get __boxStroke() { return true; }
255
+ get __boxStroke() { return !this.__pathInputed; }
255
256
  }
256
257
 
257
258
  class EllipseData extends UIData {
258
- get __boxStroke() { return true; }
259
+ get __boxStroke() { return !this.__pathInputed; }
259
260
  }
260
261
 
261
262
  class PolygonData extends UIData {
@@ -282,6 +283,7 @@ const fontWeightMap = {
282
283
  'black': 900
283
284
  };
284
285
  class TextData extends UIData {
286
+ get __useNaturalRatio() { return false; }
285
287
  setFontWeight(value) {
286
288
  if (typeof value === 'string') {
287
289
  this.__setInput('fontWeight', value);
@@ -323,19 +325,18 @@ class CanvasData extends RectData {
323
325
  const UIBounds = {
324
326
  __updateStrokeSpread() {
325
327
  let width = 0, boxWidth = 0;
326
- const { stroke, hitStroke, strokeAlign, strokeWidth } = this.__;
327
- if ((stroke || hitStroke === 'all') && strokeWidth && strokeAlign !== 'inside') {
328
+ const data = this.__, { strokeAlign, strokeWidth } = data;
329
+ if ((data.stroke || data.hitStroke === 'all') && strokeWidth && strokeAlign !== 'inside') {
328
330
  boxWidth = width = strokeAlign === 'center' ? strokeWidth / 2 : strokeWidth;
329
- if (!this.__.__boxStroke) {
330
- const { miterLimit, strokeCap } = this.__;
331
- const miterLimitAddWidth = this.__tag !== 'Line' ? 1 / Math.sin(miterLimit * core.OneRadian / 2) * Math.sqrt(strokeWidth) - width : 0;
332
- const storkeCapAddWidth = strokeCap === 'none' ? 0 : strokeWidth;
331
+ if (!data.__boxStroke) {
332
+ const miterLimitAddWidth = data.__isLinePath ? 0 : 10 * width;
333
+ const storkeCapAddWidth = data.strokeCap === 'none' ? 0 : strokeWidth;
333
334
  width += Math.max(miterLimitAddWidth, storkeCapAddWidth);
334
335
  }
335
336
  }
336
- this.__layout.strokeBoxSpread = boxWidth;
337
- if (this.__.__useArrow)
337
+ if (data.__useArrow)
338
338
  width += strokeWidth * 5;
339
+ this.__layout.strokeBoxSpread = boxWidth;
339
340
  return width;
340
341
  },
341
342
  __updateRenderSpread() {
@@ -355,7 +356,7 @@ const UIBounds = {
355
356
  if (backgroundBlur)
356
357
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
357
358
  this.__layout.renderShapeSpread = shapeWidth;
358
- return width;
359
+ return width + (this.__layout.strokeSpread || 0);
359
360
  }
360
361
  };
361
362
 
@@ -446,7 +447,7 @@ function drawFast(ui, canvas, options) {
446
447
 
447
448
  const RectRender = {
448
449
  __drawFast(canvas, options) {
449
- const { width, height, fill, stroke, __drawAfterFill } = this.__;
450
+ let { width, height, fill, stroke, __drawAfterFill } = this.__;
450
451
  if (fill) {
451
452
  canvas.fillStyle = fill;
452
453
  canvas.fillRect(0, 0, width, height);
@@ -464,7 +465,16 @@ const RectRender = {
464
465
  canvas.strokeRect(0, 0, width, height);
465
466
  break;
466
467
  case 'inside':
467
- canvas.strokeRect(half, half, width - __strokeWidth, height - __strokeWidth);
468
+ width -= __strokeWidth, height -= __strokeWidth;
469
+ if (width < 0 || height < 0) {
470
+ canvas.save();
471
+ this.__clip(canvas, options);
472
+ canvas.strokeRect(half, half, width, height);
473
+ canvas.restore();
474
+ }
475
+ else {
476
+ canvas.strokeRect(half, half, width, height);
477
+ }
468
478
  break;
469
479
  case 'outside':
470
480
  canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
@@ -492,11 +502,14 @@ exports.UI = UI_1 = class UI extends core.Leaf {
492
502
  return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX;
493
503
  }
494
504
  get pen() {
495
- core.pen.set(this.path = this.__.path || []);
505
+ const { path } = this.__;
506
+ core.pen.set(this.path = path || []);
507
+ if (!path)
508
+ this.__drawPathByBox(core.pen);
496
509
  return core.pen;
497
510
  }
498
511
  get editConfig() { return undefined; }
499
- get editOuter() { return 'EditTool'; }
512
+ get editOuter() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
500
513
  get editInner() { return 'PathEditor'; }
501
514
  constructor(data) {
502
515
  super(data);
@@ -510,22 +523,22 @@ exports.UI = UI_1 = class UI extends core.Leaf {
510
523
  }
511
524
  createProxyData() { return undefined; }
512
525
  find(_condition, _options) { return undefined; }
526
+ findTag(tag) { return this.find({ tag }); }
513
527
  findOne(_condition, _options) { return undefined; }
528
+ findId(id) { return this.findOne({ id }); }
514
529
  getPath(curve, pathForRender) {
515
530
  this.__layout.update();
516
531
  let path = pathForRender ? this.__.__pathForRender : this.__.path;
517
- if (!path) {
518
- const { width, height } = this.boxBounds;
519
- if (width || height) {
520
- core.pen.set(path = []);
521
- this.__drawPathByBox(core.pen);
522
- }
523
- }
532
+ if (!path)
533
+ core.pen.set(path = []), this.__drawPathByBox(core.pen);
524
534
  return curve ? core.PathConvert.toCanvasData(path, true) : path;
525
535
  }
526
536
  getPathString(curve, pathForRender) {
527
537
  return core.PathConvert.stringify(this.getPath(curve, pathForRender));
528
538
  }
539
+ load() {
540
+ this.__.__computePaint();
541
+ }
529
542
  __onUpdateSize() {
530
543
  if (this.__.__input) {
531
544
  const data = this.__;
@@ -611,7 +624,7 @@ __decorate([
611
624
  core.opacityType(1)
612
625
  ], exports.UI.prototype, "opacity", void 0);
613
626
  __decorate([
614
- core.opacityType(true)
627
+ core.visibleType(true)
615
628
  ], exports.UI.prototype, "visible", void 0);
616
629
  __decorate([
617
630
  stateType(false)
@@ -628,9 +641,6 @@ __decorate([
628
641
  __decorate([
629
642
  core.maskType(false)
630
643
  ], exports.UI.prototype, "mask", void 0);
631
- __decorate([
632
- core.surfaceType('pixel')
633
- ], exports.UI.prototype, "maskType", void 0);
634
644
  __decorate([
635
645
  core.eraserType(false)
636
646
  ], exports.UI.prototype, "eraser", void 0);
@@ -661,9 +671,75 @@ __decorate([
661
671
  __decorate([
662
672
  core.rotationType(0, true)
663
673
  ], exports.UI.prototype, "skewY", void 0);
674
+ __decorate([
675
+ core.positionType(0, true)
676
+ ], exports.UI.prototype, "offsetX", void 0);
677
+ __decorate([
678
+ core.positionType(0, true)
679
+ ], exports.UI.prototype, "offsetY", void 0);
680
+ __decorate([
681
+ core.positionType(0, true)
682
+ ], exports.UI.prototype, "scrollX", void 0);
683
+ __decorate([
684
+ core.positionType(0, true)
685
+ ], exports.UI.prototype, "scrollY", void 0);
686
+ __decorate([
687
+ core.autoLayoutType()
688
+ ], exports.UI.prototype, "origin", void 0);
664
689
  __decorate([
665
690
  core.autoLayoutType()
666
691
  ], exports.UI.prototype, "around", void 0);
692
+ __decorate([
693
+ core.dataType(false)
694
+ ], exports.UI.prototype, "lazy", void 0);
695
+ __decorate([
696
+ core.naturalBoundsType(1)
697
+ ], exports.UI.prototype, "pixelRatio", void 0);
698
+ __decorate([
699
+ core.pathInputType()
700
+ ], exports.UI.prototype, "path", void 0);
701
+ __decorate([
702
+ core.pathType()
703
+ ], exports.UI.prototype, "windingRule", void 0);
704
+ __decorate([
705
+ core.pathType(true)
706
+ ], exports.UI.prototype, "closed", void 0);
707
+ __decorate([
708
+ core.autoLayoutType(false)
709
+ ], exports.UI.prototype, "flow", void 0);
710
+ __decorate([
711
+ core.boundsType(0)
712
+ ], exports.UI.prototype, "padding", void 0);
713
+ __decorate([
714
+ core.boundsType(0)
715
+ ], exports.UI.prototype, "gap", void 0);
716
+ __decorate([
717
+ core.boundsType('top-left')
718
+ ], exports.UI.prototype, "align", void 0);
719
+ __decorate([
720
+ core.boundsType(false)
721
+ ], exports.UI.prototype, "wrap", void 0);
722
+ __decorate([
723
+ core.boundsType('box')
724
+ ], exports.UI.prototype, "itemBox", void 0);
725
+ __decorate([
726
+ core.boundsType(true)
727
+ ], exports.UI.prototype, "inFlow", void 0);
728
+ __decorate([
729
+ core.boundsType()
730
+ ], exports.UI.prototype, "autoWidth", void 0);
731
+ __decorate([
732
+ core.boundsType()
733
+ ], exports.UI.prototype, "autoHeight", void 0);
734
+ __decorate([
735
+ core.boundsType()
736
+ ], exports.UI.prototype, "autoBox", void 0);
737
+ __decorate([
738
+ core.boundsType()
739
+ ], exports.UI.prototype, "widthRange", void 0);
740
+ __decorate([
741
+ core.boundsType()
742
+ ], exports.UI.prototype, "heightRange", void 0);
667
743
  __decorate([
668
744
  core.dataType(false)
669
745
  ], exports.UI.prototype, "draggable", void 0);
@@ -673,9 +749,6 @@ __decorate([
673
749
  __decorate([
674
750
  core.dataType(false)
675
751
  ], exports.UI.prototype, "editable", void 0);
676
- __decorate([
677
- core.dataType('size')
678
- ], exports.UI.prototype, "editSize", void 0);
679
752
  __decorate([
680
753
  core.hitType(true)
681
754
  ], exports.UI.prototype, "hittable", void 0);
@@ -730,21 +803,6 @@ __decorate([
730
803
  __decorate([
731
804
  core.strokeType(10)
732
805
  ], exports.UI.prototype, "miterLimit", void 0);
733
- __decorate([
734
- core.dataType(false)
735
- ], exports.UI.prototype, "lazy", void 0);
736
- __decorate([
737
- core.naturalBoundsType(1)
738
- ], exports.UI.prototype, "pixelRatio", void 0);
739
- __decorate([
740
- core.pathInputType()
741
- ], exports.UI.prototype, "path", void 0);
742
- __decorate([
743
- core.pathType()
744
- ], exports.UI.prototype, "windingRule", void 0);
745
- __decorate([
746
- core.pathType(true)
747
- ], exports.UI.prototype, "closed", void 0);
748
806
  __decorate([
749
807
  arrowType('none')
750
808
  ], exports.UI.prototype, "startArrow", void 0);
@@ -875,6 +933,7 @@ exports.Leafer = Leafer_1 = class Leafer extends exports.Group {
875
933
  get layoutLocked() { return !this.layouter.running; }
876
934
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
877
935
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
936
+ get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
878
937
  constructor(userConfig, data) {
879
938
  super(data);
880
939
  this.config = {
@@ -978,9 +1037,6 @@ exports.Leafer = Leafer_1 = class Leafer extends exports.Group {
978
1037
  const data = core.DataHelper.copyAttrs({}, size, core.canvasSizeAttrs);
979
1038
  Object.keys(data).forEach(key => this[key] = data[key]);
980
1039
  }
981
- forceFullRender() {
982
- this.forceRender();
983
- }
984
1040
  forceRender(bounds) {
985
1041
  this.renderer.addBlock(bounds ? new core.Bounds(bounds) : this.canvas.bounds);
986
1042
  if (this.viewReady)
@@ -1035,7 +1091,8 @@ exports.Leafer = Leafer_1 = class Leafer extends exports.Group {
1035
1091
  this.__changeFill(newValue);
1036
1092
  }
1037
1093
  else if (attrName === 'hittable') {
1038
- this.canvas.hittable = newValue;
1094
+ if (!this.parent)
1095
+ this.canvas.hittable = newValue;
1039
1096
  }
1040
1097
  }
1041
1098
  return super.__setAttr(attrName, newValue);
@@ -1058,7 +1115,7 @@ exports.Leafer = Leafer_1 = class Leafer extends exports.Group {
1058
1115
  this.canvas.backgroundColor = newValue;
1059
1116
  }
1060
1117
  else {
1061
- this.forceFullRender();
1118
+ this.forceRender();
1062
1119
  }
1063
1120
  }
1064
1121
  __onCreated() {
@@ -1153,6 +1210,9 @@ exports.Leafer = Leafer_1 = class Leafer extends exports.Group {
1153
1210
  zoom(_zoomType, _padding, _fixedScale) { return undefined; }
1154
1211
  getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
1155
1212
  getValidScale(changeScale) { return changeScale; }
1213
+ getWorldPointByClient(clientPoint, updateClient) {
1214
+ return this.interaction && this.interaction.getLocal(clientPoint, updateClient);
1215
+ }
1156
1216
  __checkUpdateLayout() {
1157
1217
  this.__layout.update();
1158
1218
  }
@@ -1235,8 +1295,8 @@ exports.Rect = __decorate([
1235
1295
 
1236
1296
  const rect = exports.Rect.prototype;
1237
1297
  const group = exports.Group.prototype;
1238
- const bounds = {};
1239
- const { copy, add } = core.BoundsHelper;
1298
+ const childrenRenderBounds = {};
1299
+ const { copy, add, includes: includes$1 } = core.BoundsHelper;
1240
1300
  exports.Box = class Box extends exports.Group {
1241
1301
  get __tag() { return 'Box'; }
1242
1302
  get isBranchLeaf() { return true; }
@@ -1247,24 +1307,29 @@ exports.Box = class Box extends exports.Group {
1247
1307
  __updateStrokeSpread() { return 0; }
1248
1308
  __updateRectRenderSpread() { return 0; }
1249
1309
  __updateRenderSpread() {
1250
- const width = this.__updateRectRenderSpread();
1251
- const hide = this.__.__drawAfterFill = this.__.overflow === 'hide';
1252
- return (width || hide) ? width : -1;
1310
+ return this.__updateRectRenderSpread() || -1;
1253
1311
  }
1254
1312
  __updateRectBoxBounds() { }
1255
1313
  __updateBoxBounds() {
1256
1314
  const data = this.__;
1257
- if (data.__autoSide && this.children.length) {
1258
- if (this.leafer)
1259
- this.leafer.layouter.addExtra(this);
1260
- super.__updateBoxBounds();
1261
- if (!data.__autoSize) {
1262
- const b = this.__layout.boxBounds;
1263
- if (!data.__autoWidth)
1264
- b.x = 0, b.width = data.width;
1265
- if (!data.__autoHeight)
1266
- b.y = 0, b.height = data.height;
1315
+ if (this.children.length) {
1316
+ if (data.__autoSide) {
1317
+ if (this.leafer && this.leafer.ready)
1318
+ this.leafer.layouter.addExtra(this);
1319
+ super.__updateBoxBounds();
1320
+ if (!data.__autoSize) {
1321
+ const b = this.__layout.boxBounds;
1322
+ if (!data.__autoWidth)
1323
+ b.x = 0, b.width = data.width;
1324
+ if (!data.__autoHeight)
1325
+ b.y = 0, b.height = data.height;
1326
+ }
1267
1327
  }
1328
+ else {
1329
+ this.__updateRectBoxBounds();
1330
+ }
1331
+ if (data.flow)
1332
+ this.__updateContentBounds();
1268
1333
  }
1269
1334
  else {
1270
1335
  this.__updateRectBoxBounds();
@@ -1272,13 +1337,20 @@ exports.Box = class Box extends exports.Group {
1272
1337
  }
1273
1338
  __updateStrokeBounds() { }
1274
1339
  __updateRenderBounds() {
1275
- this.__updateRectRenderBounds();
1276
- if (!this.__.__drawAfterFill) {
1277
- const { renderBounds } = this.__layout;
1278
- copy(bounds, renderBounds);
1340
+ let isOverflow;
1341
+ const { renderBounds } = this.__layout;
1342
+ if (this.children.length) {
1279
1343
  super.__updateRenderBounds();
1280
- add(renderBounds, bounds);
1344
+ copy(childrenRenderBounds, renderBounds);
1345
+ this.__updateRectRenderBounds();
1346
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
1347
+ }
1348
+ else {
1349
+ this.__updateRectRenderBounds();
1281
1350
  }
1351
+ this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
1352
+ if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide'))
1353
+ add(renderBounds, childrenRenderBounds);
1282
1354
  }
1283
1355
  __updateRectRenderBounds() { }
1284
1356
  __updateRectChange() { }
@@ -1294,16 +1366,27 @@ exports.Box = class Box extends exports.Group {
1294
1366
  }
1295
1367
  else {
1296
1368
  this.__renderRect(canvas, options);
1297
- this.__renderGroup(canvas, options);
1369
+ if (this.children.length)
1370
+ this.__renderGroup(canvas, options);
1298
1371
  }
1299
1372
  }
1300
1373
  __drawAfterFill(canvas, options) {
1301
- canvas.save();
1302
- canvas.clip();
1303
- this.__renderGroup(canvas, options);
1304
- canvas.restore();
1305
- if (this.__.stroke)
1374
+ const { length } = this.children;
1375
+ if (this.isOverflow) {
1376
+ canvas.save();
1377
+ canvas.clip();
1378
+ if (length)
1379
+ this.__renderGroup(canvas, options);
1380
+ canvas.restore();
1381
+ }
1382
+ else {
1383
+ if (length)
1384
+ this.__renderGroup(canvas, options);
1385
+ }
1386
+ if (this.__.stroke && length) {
1387
+ canvas.setWorld(this.__nowWorld);
1306
1388
  this.__drawRenderPath(canvas);
1389
+ }
1307
1390
  }
1308
1391
  };
1309
1392
  __decorate([
@@ -1441,9 +1524,10 @@ exports.Line = class Line extends exports.UI {
1441
1524
  super(data);
1442
1525
  }
1443
1526
  __updatePath() {
1444
- const path = this.__.path = [];
1445
- if (this.__.points) {
1446
- drawPoints$1(path, this.__.points, this.__.closed);
1527
+ const data = this.__;
1528
+ const path = data.path = [];
1529
+ if (data.points) {
1530
+ drawPoints$1(path, data.points, false, data.closed);
1447
1531
  }
1448
1532
  else {
1449
1533
  moveTo$2(path, 0, 0);
@@ -1678,7 +1762,7 @@ exports.Canvas = __decorate([
1678
1762
  core.registerUI()
1679
1763
  ], exports.Canvas);
1680
1764
 
1681
- const { copyAndSpread, includes, spread, setList } = core.BoundsHelper;
1765
+ const { copyAndSpread, includes, isSame, spread, setList } = core.BoundsHelper;
1682
1766
  exports.Text = class Text extends exports.UI {
1683
1767
  get __tag() { return 'Text'; }
1684
1768
  get editInner() { return 'TextEditor'; }
@@ -1751,7 +1835,7 @@ exports.Text = class Text extends exports.UI {
1751
1835
  if (italic)
1752
1836
  b.width += fontSize * 0.16;
1753
1837
  const contentBounds = includes(b, bounds) ? b : bounds;
1754
- if (contentBounds !== layout.contentBounds) {
1838
+ if (!isSame(contentBounds, layout.contentBounds)) {
1755
1839
  layout.contentBounds = contentBounds;
1756
1840
  layout.renderChanged = true;
1757
1841
  setList(data.__textBoxBounds = {}, [b, bounds]);
@@ -1779,9 +1863,6 @@ __decorate([
1779
1863
  __decorate([
1780
1864
  core.boundsType(0)
1781
1865
  ], exports.Text.prototype, "height", void 0);
1782
- __decorate([
1783
- core.boundsType(0)
1784
- ], exports.Text.prototype, "padding", void 0);
1785
1866
  __decorate([
1786
1867
  core.surfaceType('#000000')
1787
1868
  ], exports.Text.prototype, "fill", void 0);
@@ -1816,7 +1897,7 @@ __decorate([
1816
1897
  core.boundsType(0)
1817
1898
  ], exports.Text.prototype, "letterSpacing", void 0);
1818
1899
  __decorate([
1819
- core.boundsType({ type: 'percent', value: 150 })
1900
+ core.boundsType({ type: 'percent', value: 1.5 })
1820
1901
  ], exports.Text.prototype, "lineHeight", void 0);
1821
1902
  __decorate([
1822
1903
  core.boundsType(0)
@@ -1910,8 +1991,6 @@ function penPathType() {
1910
1991
  };
1911
1992
  }
1912
1993
 
1913
- const version = "1.0.0-rc.21";
1914
-
1915
1994
  exports.BoxData = BoxData;
1916
1995
  exports.CanvasData = CanvasData;
1917
1996
  exports.ColorConvert = ColorConvert;
@@ -1944,7 +2023,6 @@ exports.arrowType = arrowType;
1944
2023
  exports.effectType = effectType;
1945
2024
  exports.resizeType = resizeType;
1946
2025
  exports.stateType = stateType;
1947
- exports.version = version;
1948
2026
  exports.zoomLayerType = zoomLayerType;
1949
2027
  Object.keys(core).forEach(function (k) {
1950
2028
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {