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