@leafer-ui/core 1.5.2 → 1.6.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/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,7 +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)
791
+ if (this.waitTap || this.longPressTimer)
793
792
  this.pointerWaitCancel();
794
793
  this.waitRightTap = false;
795
794
  }
@@ -1050,7 +1049,10 @@ class InteractionBase {
1050
1049
  }
1051
1050
  getLocal(clientPoint, updateClient) {
1052
1051
  const clientBounds = this.canvas.getClientBounds(updateClient);
1053
- 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
+ PointHelper.round(point);
1055
+ return point;
1054
1056
  }
1055
1057
  emitTap(data) {
1056
1058
  this.emit(PointerEvent.TAP, data);
@@ -1182,25 +1184,26 @@ const { toInnerRadiusPointOf, copy, setRadius } = PointHelper;
1182
1184
  const inner = {};
1183
1185
  const leaf = Leaf.prototype;
1184
1186
  leaf.__hitWorld = function (point) {
1185
- if (!this.__.hitSelf)
1187
+ const data = this.__;
1188
+ if (!data.hitSelf)
1186
1189
  return false;
1187
- if (this.__.hitRadius) {
1190
+ const world = this.__world, layout = this.__layout;
1191
+ const isSmall = world.width < 10 && world.height < 10;
1192
+ if (data.hitRadius) {
1188
1193
  copy(inner, point), point = inner;
1189
- setRadius(point, this.__.hitRadius);
1194
+ setRadius(point, data.hitRadius);
1190
1195
  }
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))
1196
+ toInnerRadiusPointOf(point, world, inner);
1197
+ if (data.hitBox || isSmall) {
1198
+ if (BoundsHelper.hitRadiusPoint(layout.boxBounds, inner))
1196
1199
  return true;
1197
1200
  if (isSmall)
1198
1201
  return false;
1199
1202
  }
1200
- if (this.__layout.hitCanvasChanged || !this.__hitCanvas) {
1203
+ if (layout.hitCanvasChanged || !this.__hitCanvas) {
1201
1204
  this.__updateHitCanvas();
1202
- if (!this.__layout.boundsChanged)
1203
- this.__layout.hitCanvasChanged = false;
1205
+ if (!layout.boundsChanged)
1206
+ layout.hitCanvasChanged = false;
1204
1207
  }
1205
1208
  return this.__hit(inner);
1206
1209
  };
@@ -1213,7 +1216,9 @@ leaf.__drawHitPath = function (canvas) { if (canvas)
1213
1216
  const matrix = new Matrix();
1214
1217
  const ui$1 = UI.prototype;
1215
1218
  ui$1.__updateHitCanvas = function () {
1216
- const data = this.__, { hitCanvasManager } = this.leafer;
1219
+ if (this.__box)
1220
+ this.__box.__updateHitCanvas();
1221
+ const data = this.__, { hitCanvasManager } = this.leafer || this.parent.leafer;
1217
1222
  const isHitPixelFill = (data.__pixelFill || data.__isCanvas) && data.hitFill === 'pixel';
1218
1223
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
1219
1224
  const isHitPixel = isHitPixelFill || isHitPixelStroke;
@@ -1240,6 +1245,8 @@ ui$1.__updateHitCanvas = function () {
1240
1245
  h.setStrokeOptions(data);
1241
1246
  };
1242
1247
  ui$1.__hit = function (inner) {
1248
+ if (this.__box && this.__box.__hit(inner))
1249
+ return true;
1243
1250
  const data = this.__;
1244
1251
  if (data.__isHitPixel && this.__hitPixel(inner))
1245
1252
  return true;
@@ -1288,6 +1295,15 @@ rect.__hitFill = box.__hitFill = function (inner) {
1288
1295
  return this.__hitCanvas ? ui.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
1289
1296
  };
1290
1297
 
1298
+ Text.prototype.__drawHitPath = function (canvas) {
1299
+ const { __lineHeight, fontSize, __baseLine, __letterSpacing, __textDrawData: data } = this.__;
1300
+ canvas.beginPath();
1301
+ if (__letterSpacing < 0)
1302
+ this.__drawPathByBox(canvas);
1303
+ else
1304
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
1305
+ };
1306
+
1291
1307
  function getSelector(ui) {
1292
1308
  return ui.leafer ? ui.leafer.selector : (Platform$1.selector || (Platform$1.selector = Creator$1.selector()));
1293
1309
  }