@leafer-ui/core 1.5.3 → 1.6.1

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/core.esm.js CHANGED
@@ -1,6 +1,6 @@
1
- import { Leafer, State, UI, ImageManager, Rect, Box, Group, Platform as Platform$1, Creator as Creator$1, emptyData } from '@leafer-ui/draw';
1
+ import { Leafer, State, UI, Rect, Box, Text, Group, Platform as Platform$1, Creator as Creator$1, emptyData } from '@leafer-ui/draw';
2
2
  export * from '@leafer-ui/draw';
3
- import { registerUI, Creator, PropertyEvent, Debug, DataHelper, canvasSizeAttrs, LayoutEvent, RenderEvent, Event, EventCreator, registerUIEvent, LeafList, PointHelper, BoundsHelper, Platform, Bounds, ResizeEvent, LeaferEvent, CanvasManager, Leaf, Matrix, tempBounds, LeaferCanvasBase } from '@leafer/core';
3
+ import { registerUI, Creator, DataHelper, canvasSizeAttrs, LayoutEvent, RenderEvent, Event, EventCreator, registerUIEvent, LeafList, PointHelper, BoundsHelper, Debug, Platform, Bounds, ResizeEvent, LeaferEvent, CanvasManager, Leaf, Matrix, tempBounds, ImageManager, LeaferCanvasBase } from '@leafer/core';
4
4
 
5
5
  /******************************************************************************
6
6
  Copyright (c) Microsoft Corporation.
@@ -61,26 +61,25 @@ let App = class App extends Leafer {
61
61
  this.leafer = this;
62
62
  this.watcher.disable();
63
63
  this.layouter.disable();
64
- this.__eventIds.push(this.on_(PropertyEvent.CHANGE, this.__onPropertyChange, this));
65
64
  }
66
65
  start() {
67
66
  super.start();
68
- this.children.forEach(leafer => leafer.start());
67
+ this.forEach(leafer => leafer.start());
69
68
  }
70
69
  stop() {
71
- this.children.forEach(leafer => leafer.stop());
70
+ this.forEach(leafer => leafer.stop());
72
71
  super.stop();
73
72
  }
74
73
  unlockLayout() {
75
74
  super.unlockLayout();
76
- this.children.forEach(leafer => leafer.unlockLayout());
75
+ this.forEach(leafer => leafer.unlockLayout());
77
76
  }
78
77
  lockLayout() {
79
78
  super.lockLayout();
80
- this.children.forEach(leafer => leafer.lockLayout());
79
+ this.forEach(leafer => leafer.lockLayout());
81
80
  }
82
81
  forceRender(bounds, sync) {
83
- this.children.forEach(leafer => leafer.forceRender(bounds, sync));
82
+ this.forEach(leafer => leafer.forceRender(bounds, sync));
84
83
  }
85
84
  addLeafer(merge) {
86
85
  const leafer = new Leafer(merge);
@@ -100,9 +99,8 @@ let App = class App extends Leafer {
100
99
  leafer.canvas.childIndex = index;
101
100
  this.__listenChildEvents(leafer);
102
101
  }
103
- __onPropertyChange() {
104
- if (Debug.showHitView)
105
- this.children.forEach(leafer => leafer.forceUpdate('surface'));
102
+ forEach(fn) {
103
+ this.children.forEach(fn);
106
104
  }
107
105
  __onCreated() {
108
106
  this.created = this.children.every(child => child.created);
@@ -125,18 +123,18 @@ let App = class App extends Leafer {
125
123
  const m = options.matrix;
126
124
  if (m)
127
125
  canvas.setTransform(m.a, m.b, m.c, m.d, m.e, m.f);
128
- this.children.forEach(leafer => canvas.copyWorld(leafer.canvas));
126
+ this.forEach(leafer => canvas.copyWorld(leafer.canvas));
129
127
  }
130
128
  }
131
129
  __onResize(event) {
132
- this.children.forEach(leafer => leafer.resize(event));
130
+ this.forEach(leafer => leafer.resize(event));
133
131
  super.__onResize(event);
134
132
  }
135
133
  updateLayout() {
136
- this.children.forEach(leafer => leafer.updateLayout());
134
+ this.forEach(leafer => leafer.updateLayout());
137
135
  }
138
136
  __getChildConfig(userConfig) {
139
- let config = Object.assign({}, this.config);
137
+ const config = Object.assign({}, this.config);
140
138
  config.hittable = config.realCanvas = undefined;
141
139
  if (userConfig)
142
140
  DataHelper.assign(config, userConfig);
@@ -695,6 +693,7 @@ const config = {
695
693
  delta: { x: 80 / 4, y: 8.0 },
696
694
  },
697
695
  pointer: {
696
+ snap: true,
698
697
  hitRadius: 5,
699
698
  tapTime: 120,
700
699
  longPressTime: 800,
@@ -789,8 +788,7 @@ class InteractionBase {
789
788
  if (this.downData) {
790
789
  const canDrag = PointHelper.getDistance(this.downData, data) > this.p.dragDistance;
791
790
  if (canDrag) {
792
- if (this.waitTap)
793
- this.pointerWaitCancel();
791
+ this.pointerWaitCancel();
794
792
  this.waitRightTap = false;
795
793
  }
796
794
  this.dragger.checkDrag(data, canDrag);
@@ -1050,7 +1048,10 @@ class InteractionBase {
1050
1048
  }
1051
1049
  getLocal(clientPoint, updateClient) {
1052
1050
  const clientBounds = this.canvas.getClientBounds(updateClient);
1053
- return { x: clientPoint.clientX - clientBounds.x, y: clientPoint.clientY - clientBounds.y };
1051
+ const point = { x: clientPoint.clientX - clientBounds.x, y: clientPoint.clientY - clientBounds.y };
1052
+ if (this.p.snap)
1053
+ PointHelper.round(point);
1054
+ return point;
1054
1055
  }
1055
1056
  emitTap(data) {
1056
1057
  this.emit(PointerEvent.TAP, data);
@@ -1069,9 +1070,11 @@ class InteractionBase {
1069
1070
  this.waitTap = true;
1070
1071
  }
1071
1072
  tapWaitCancel() {
1072
- clearTimeout(this.tapTimer);
1073
- this.waitTap = false;
1074
- this.tapCount = 0;
1073
+ if (this.waitTap) {
1074
+ clearTimeout(this.tapTimer);
1075
+ this.waitTap = false;
1076
+ this.tapCount = 0;
1077
+ }
1075
1078
  }
1076
1079
  longPressWait(data) {
1077
1080
  clearTimeout(this.longPressTimer);
@@ -1091,8 +1094,10 @@ class InteractionBase {
1091
1094
  return hasLong;
1092
1095
  }
1093
1096
  longPressWaitCancel() {
1094
- clearTimeout(this.longPressTimer);
1095
- this.longPressed = false;
1097
+ if (this.longPressTimer) {
1098
+ clearTimeout(this.longPressTimer);
1099
+ this.longPressed = false;
1100
+ }
1096
1101
  }
1097
1102
  __onResize() {
1098
1103
  const { dragOut } = this.m;
@@ -1182,25 +1187,26 @@ const { toInnerRadiusPointOf, copy, setRadius } = PointHelper;
1182
1187
  const inner = {};
1183
1188
  const leaf = Leaf.prototype;
1184
1189
  leaf.__hitWorld = function (point) {
1185
- if (!this.__.hitSelf)
1190
+ const data = this.__;
1191
+ if (!data.hitSelf)
1186
1192
  return false;
1187
- if (this.__.hitRadius) {
1193
+ const world = this.__world, layout = this.__layout;
1194
+ const isSmall = world.width < 10 && world.height < 10;
1195
+ if (data.hitRadius) {
1188
1196
  copy(inner, point), point = inner;
1189
- setRadius(point, this.__.hitRadius);
1197
+ setRadius(point, data.hitRadius);
1190
1198
  }
1191
- toInnerRadiusPointOf(point, this.__world, inner);
1192
- const { width, height } = this.__world;
1193
- const isSmall = width < 10 && height < 10;
1194
- if (this.__.hitBox || isSmall) {
1195
- if (BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner))
1199
+ toInnerRadiusPointOf(point, world, inner);
1200
+ if (data.hitBox || isSmall) {
1201
+ if (BoundsHelper.hitRadiusPoint(layout.boxBounds, inner))
1196
1202
  return true;
1197
1203
  if (isSmall)
1198
1204
  return false;
1199
1205
  }
1200
- if (this.__layout.hitCanvasChanged || !this.__hitCanvas) {
1206
+ if (layout.hitCanvasChanged || !this.__hitCanvas) {
1201
1207
  this.__updateHitCanvas();
1202
- if (!this.__layout.boundsChanged)
1203
- this.__layout.hitCanvasChanged = false;
1208
+ if (!layout.boundsChanged)
1209
+ layout.hitCanvasChanged = false;
1204
1210
  }
1205
1211
  return this.__hit(inner);
1206
1212
  };
@@ -1213,7 +1219,9 @@ leaf.__drawHitPath = function (canvas) { if (canvas)
1213
1219
  const matrix = new Matrix();
1214
1220
  const ui$1 = UI.prototype;
1215
1221
  ui$1.__updateHitCanvas = function () {
1216
- const data = this.__, { hitCanvasManager } = this.leafer;
1222
+ if (this.__box)
1223
+ this.__box.__updateHitCanvas();
1224
+ const data = this.__, { hitCanvasManager } = this.leafer || this.parent.leafer;
1217
1225
  const isHitPixelFill = (data.__pixelFill || data.__isCanvas) && data.hitFill === 'pixel';
1218
1226
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
1219
1227
  const isHitPixel = isHitPixelFill || isHitPixelStroke;
@@ -1240,6 +1248,8 @@ ui$1.__updateHitCanvas = function () {
1240
1248
  h.setStrokeOptions(data);
1241
1249
  };
1242
1250
  ui$1.__hit = function (inner) {
1251
+ if (this.__box && this.__box.__hit(inner))
1252
+ return true;
1243
1253
  const data = this.__;
1244
1254
  if (data.__isHitPixel && this.__hitPixel(inner))
1245
1255
  return true;
@@ -1288,6 +1298,15 @@ rect.__hitFill = box.__hitFill = function (inner) {
1288
1298
  return this.__hitCanvas ? ui.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
1289
1299
  };
1290
1300
 
1301
+ Text.prototype.__drawHitPath = function (canvas) {
1302
+ const { __lineHeight, fontSize, __baseLine, __letterSpacing, __textDrawData: data } = this.__;
1303
+ canvas.beginPath();
1304
+ if (__letterSpacing < 0)
1305
+ this.__drawPathByBox(canvas);
1306
+ else
1307
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
1308
+ };
1309
+
1291
1310
  function getSelector(ui) {
1292
1311
  return ui.leafer ? ui.leafer.selector : (Platform$1.selector || (Platform$1.selector = Creator$1.selector()));
1293
1312
  }