@leafer-ui/core 1.9.8 → 1.9.10
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 +100 -2
- package/lib/core.esm.js +99 -3
- package/lib/core.esm.min.js +1 -1
- package/lib/core.esm.min.js.map +1 -1
- package/lib/core.min.cjs +1 -1
- package/lib/core.min.cjs.map +1 -1
- package/package.json +6 -6
package/lib/core.cjs
CHANGED
|
@@ -213,6 +213,102 @@ class UIEvent extends core.Event {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
const {float: float, sign: sign} = core.MathHelper, {min: min, max: max, abs: abs} = Math;
|
|
217
|
+
|
|
218
|
+
const tempContent = new core.Bounds, tempDragBounds = new core.Bounds;
|
|
219
|
+
|
|
220
|
+
const DragBoundsHelper = {
|
|
221
|
+
limitMove(leaf, move) {
|
|
222
|
+
const {dragBounds: dragBounds, dragBoundsType: dragBoundsType} = leaf;
|
|
223
|
+
if (dragBounds) D.getValidMove(leaf.__localBoxBounds, D.getDragBounds(leaf), dragBoundsType, move, true);
|
|
224
|
+
D.axisMove(leaf, move);
|
|
225
|
+
},
|
|
226
|
+
limitScaleOf(leaf, origin, scale, lockRatio) {
|
|
227
|
+
const {dragBounds: dragBounds, dragBoundsType: dragBoundsType} = leaf;
|
|
228
|
+
if (dragBounds) D.getValidScaleOf(leaf.__localBoxBounds, D.getDragBounds(leaf), dragBoundsType, leaf.getLocalPointByInner(leaf.getInnerPointByBox(origin)), scale, lockRatio, true);
|
|
229
|
+
},
|
|
230
|
+
axisMove(leaf, move) {
|
|
231
|
+
const {draggable: draggable} = leaf;
|
|
232
|
+
if (draggable === "x") move.y = 0;
|
|
233
|
+
if (draggable === "y") move.x = 0;
|
|
234
|
+
},
|
|
235
|
+
getDragBounds(leaf) {
|
|
236
|
+
const {dragBounds: dragBounds} = leaf;
|
|
237
|
+
return dragBounds === "parent" ? leaf.parent.boxBounds : dragBounds;
|
|
238
|
+
},
|
|
239
|
+
isInnerMode(content, dragBounds, dragBoundsType, sideType) {
|
|
240
|
+
return dragBoundsType === "inner" || dragBoundsType === "auto" && content[sideType] > dragBounds[sideType];
|
|
241
|
+
},
|
|
242
|
+
getValidMove(content, dragBounds, dragBoundsType, move, change) {
|
|
243
|
+
const x = content.x + move.x, y = content.y + move.y, right = x + content.width, bottom = y + content.height;
|
|
244
|
+
const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
|
|
245
|
+
if (!change) move = Object.assign({}, move);
|
|
246
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, "width")) {
|
|
247
|
+
if (x > dragBounds.x) move.x += dragBounds.x - x; else if (right < boundsRight) move.x += boundsRight - right;
|
|
248
|
+
} else {
|
|
249
|
+
if (x < dragBounds.x) move.x += dragBounds.x - x; else if (right > boundsRight) move.x += boundsRight - right;
|
|
250
|
+
}
|
|
251
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, "height")) {
|
|
252
|
+
if (y > dragBounds.y) move.y += dragBounds.y - y; else if (bottom < boundsBottom) move.y += boundsBottom - bottom;
|
|
253
|
+
} else {
|
|
254
|
+
if (y < dragBounds.y) move.y += dragBounds.y - y; else if (bottom > boundsBottom) move.y += boundsBottom - bottom;
|
|
255
|
+
}
|
|
256
|
+
move.x = float(move.x);
|
|
257
|
+
move.y = float(move.y);
|
|
258
|
+
return move;
|
|
259
|
+
},
|
|
260
|
+
getValidScaleOf(content, dragBounds, dragBoundsType, origin, scale, lockRatio, change) {
|
|
261
|
+
if (!change) scale = Object.assign({}, scale);
|
|
262
|
+
tempDragBounds.set(dragBounds);
|
|
263
|
+
tempContent.set(content).scaleOf(origin, scale.x, scale.y);
|
|
264
|
+
const originLeftScale = (origin.x - content.x) / content.width, originRightScale = 1 - originLeftScale;
|
|
265
|
+
const originTopScale = (origin.y - content.y) / content.height, originBottomScale = 1 - originTopScale;
|
|
266
|
+
let correctScaleX, correctScaleY, aScale, bScale, aSize, bSize;
|
|
267
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, "width")) {
|
|
268
|
+
correctScaleX = scale.x < 0 ? 1 / scale.x : 1;
|
|
269
|
+
if (scale.x < 0) tempContent.scaleOf(origin, correctScaleX, 1);
|
|
270
|
+
aSize = float(tempContent.minX - tempDragBounds.minX);
|
|
271
|
+
bSize = float(tempDragBounds.maxX - tempContent.maxX);
|
|
272
|
+
aScale = originLeftScale && aSize > 0 ? 1 + aSize / (originLeftScale * tempContent.width) : 1;
|
|
273
|
+
bScale = originRightScale && bSize > 0 ? 1 + bSize / (originRightScale * tempContent.width) : 1;
|
|
274
|
+
correctScaleX *= max(aScale, bScale);
|
|
275
|
+
} else {
|
|
276
|
+
if (scale.x < 0) tempContent.unsign();
|
|
277
|
+
aSize = float(tempDragBounds.minX - tempContent.minX);
|
|
278
|
+
bSize = float(tempContent.maxX - tempDragBounds.maxX);
|
|
279
|
+
aScale = originLeftScale && aSize > 0 ? 1 - aSize / (originLeftScale * tempContent.width) : 1;
|
|
280
|
+
bScale = originRightScale && bSize > 0 ? 1 - bSize / (originRightScale * tempContent.width) : 1;
|
|
281
|
+
correctScaleX = min(aScale, bScale);
|
|
282
|
+
}
|
|
283
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, "height")) {
|
|
284
|
+
correctScaleY = scale.y < 0 ? 1 / scale.y : 1;
|
|
285
|
+
if (scale.y < 0) tempContent.scaleOf(origin, 1, correctScaleY);
|
|
286
|
+
aSize = float(tempContent.minY - tempDragBounds.minY);
|
|
287
|
+
bSize = float(tempDragBounds.maxY - tempContent.maxY);
|
|
288
|
+
aScale = originTopScale && aSize > 0 ? 1 + aSize / (originTopScale * tempContent.height) : 1;
|
|
289
|
+
bScale = originBottomScale && bSize > 0 ? 1 + bSize / (originBottomScale * tempContent.height) : 1;
|
|
290
|
+
correctScaleY *= max(aScale, bScale);
|
|
291
|
+
if (lockRatio) {
|
|
292
|
+
aScale = max(abs(correctScaleX), abs(correctScaleY));
|
|
293
|
+
correctScaleX = sign(correctScaleX) * aScale;
|
|
294
|
+
correctScaleY = sign(correctScaleY) * aScale;
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
if (scale.y < 0) tempContent.unsign();
|
|
298
|
+
aSize = float(tempDragBounds.minY - tempContent.minY);
|
|
299
|
+
bSize = float(tempContent.maxY - tempDragBounds.maxY);
|
|
300
|
+
aScale = originTopScale && aSize > 0 ? 1 - aSize / (originTopScale * tempContent.height) : 1;
|
|
301
|
+
bScale = originBottomScale && bSize > 0 ? 1 - bSize / (originBottomScale * tempContent.height) : 1;
|
|
302
|
+
correctScaleY = min(aScale, bScale);
|
|
303
|
+
}
|
|
304
|
+
scale.x *= core.isFinite(correctScaleX) ? correctScaleX : 1;
|
|
305
|
+
scale.y *= core.isFinite(correctScaleY) ? correctScaleY : 1;
|
|
306
|
+
return scale;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const D = DragBoundsHelper;
|
|
311
|
+
|
|
216
312
|
exports.PointerEvent = class PointerEvent extends UIEvent {};
|
|
217
313
|
|
|
218
314
|
exports.PointerEvent.POINTER = "pointer";
|
|
@@ -270,11 +366,11 @@ exports.DragEvent = class DragEvent extends exports.PointerEvent {
|
|
|
270
366
|
const move = leaf.getLocalPoint(worldTotal, null, true);
|
|
271
367
|
core.PointHelper.move(move, localStart.x - leaf.x, localStart.y - leaf.y);
|
|
272
368
|
if (checkLimit) this.limitMove(leaf, move);
|
|
273
|
-
|
|
369
|
+
DragBoundsHelper.axisMove(leaf, move);
|
|
274
370
|
return move;
|
|
275
371
|
}
|
|
276
372
|
static limitMove(leaf, move) {
|
|
277
|
-
|
|
373
|
+
DragBoundsHelper.limitMove(leaf, move);
|
|
278
374
|
}
|
|
279
375
|
getPageMove(total) {
|
|
280
376
|
this.assignMove(total);
|
|
@@ -1406,6 +1502,8 @@ canvas.hitPixel = function(radiusPoint, offset, scale = 1) {
|
|
|
1406
1502
|
|
|
1407
1503
|
exports.Cursor = Cursor;
|
|
1408
1504
|
|
|
1505
|
+
exports.DragBoundsHelper = DragBoundsHelper;
|
|
1506
|
+
|
|
1409
1507
|
exports.Dragger = Dragger;
|
|
1410
1508
|
|
|
1411
1509
|
exports.HitCanvasManager = HitCanvasManager;
|
package/lib/core.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Leafer,
|
|
1
|
+
import { Leafer, State, UI, Rect, Box, Text, Group, emptyData } from "@leafer-ui/draw";
|
|
2
2
|
|
|
3
3
|
export * from "@leafer-ui/draw";
|
|
4
4
|
|
|
5
|
-
import { registerUI, Creator, isUndefined, DataHelper, canvasSizeAttrs, LayoutEvent, RenderEvent, Event, EventCreator, registerUIEvent, LeafList, PointHelper, BoundsHelper, LeafHelper, isString, isNumber, Debug, Platform,
|
|
5
|
+
import { registerUI, Creator, isUndefined, DataHelper, canvasSizeAttrs, LayoutEvent, RenderEvent, Event, EventCreator, MathHelper, Bounds, isFinite, registerUIEvent, LeafList, PointHelper, BoundsHelper, LeafHelper, isString, isNumber, Debug, Platform, ResizeEvent, LeaferEvent, CanvasManager, Leaf, Matrix, tempBounds, ImageManager, LeaferCanvasBase } from "@leafer/core";
|
|
6
6
|
|
|
7
7
|
function __decorate(decorators, target, key, desc) {
|
|
8
8
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -213,6 +213,102 @@ class UIEvent extends Event {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
const {float: float, sign: sign} = MathHelper, {min: min, max: max, abs: abs} = Math;
|
|
217
|
+
|
|
218
|
+
const tempContent = new Bounds, tempDragBounds = new Bounds;
|
|
219
|
+
|
|
220
|
+
const DragBoundsHelper = {
|
|
221
|
+
limitMove(leaf, move) {
|
|
222
|
+
const {dragBounds: dragBounds, dragBoundsType: dragBoundsType} = leaf;
|
|
223
|
+
if (dragBounds) D.getValidMove(leaf.__localBoxBounds, D.getDragBounds(leaf), dragBoundsType, move, true);
|
|
224
|
+
D.axisMove(leaf, move);
|
|
225
|
+
},
|
|
226
|
+
limitScaleOf(leaf, origin, scale, lockRatio) {
|
|
227
|
+
const {dragBounds: dragBounds, dragBoundsType: dragBoundsType} = leaf;
|
|
228
|
+
if (dragBounds) D.getValidScaleOf(leaf.__localBoxBounds, D.getDragBounds(leaf), dragBoundsType, leaf.getLocalPointByInner(leaf.getInnerPointByBox(origin)), scale, lockRatio, true);
|
|
229
|
+
},
|
|
230
|
+
axisMove(leaf, move) {
|
|
231
|
+
const {draggable: draggable} = leaf;
|
|
232
|
+
if (draggable === "x") move.y = 0;
|
|
233
|
+
if (draggable === "y") move.x = 0;
|
|
234
|
+
},
|
|
235
|
+
getDragBounds(leaf) {
|
|
236
|
+
const {dragBounds: dragBounds} = leaf;
|
|
237
|
+
return dragBounds === "parent" ? leaf.parent.boxBounds : dragBounds;
|
|
238
|
+
},
|
|
239
|
+
isInnerMode(content, dragBounds, dragBoundsType, sideType) {
|
|
240
|
+
return dragBoundsType === "inner" || dragBoundsType === "auto" && content[sideType] > dragBounds[sideType];
|
|
241
|
+
},
|
|
242
|
+
getValidMove(content, dragBounds, dragBoundsType, move, change) {
|
|
243
|
+
const x = content.x + move.x, y = content.y + move.y, right = x + content.width, bottom = y + content.height;
|
|
244
|
+
const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
|
|
245
|
+
if (!change) move = Object.assign({}, move);
|
|
246
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, "width")) {
|
|
247
|
+
if (x > dragBounds.x) move.x += dragBounds.x - x; else if (right < boundsRight) move.x += boundsRight - right;
|
|
248
|
+
} else {
|
|
249
|
+
if (x < dragBounds.x) move.x += dragBounds.x - x; else if (right > boundsRight) move.x += boundsRight - right;
|
|
250
|
+
}
|
|
251
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, "height")) {
|
|
252
|
+
if (y > dragBounds.y) move.y += dragBounds.y - y; else if (bottom < boundsBottom) move.y += boundsBottom - bottom;
|
|
253
|
+
} else {
|
|
254
|
+
if (y < dragBounds.y) move.y += dragBounds.y - y; else if (bottom > boundsBottom) move.y += boundsBottom - bottom;
|
|
255
|
+
}
|
|
256
|
+
move.x = float(move.x);
|
|
257
|
+
move.y = float(move.y);
|
|
258
|
+
return move;
|
|
259
|
+
},
|
|
260
|
+
getValidScaleOf(content, dragBounds, dragBoundsType, origin, scale, lockRatio, change) {
|
|
261
|
+
if (!change) scale = Object.assign({}, scale);
|
|
262
|
+
tempDragBounds.set(dragBounds);
|
|
263
|
+
tempContent.set(content).scaleOf(origin, scale.x, scale.y);
|
|
264
|
+
const originLeftScale = (origin.x - content.x) / content.width, originRightScale = 1 - originLeftScale;
|
|
265
|
+
const originTopScale = (origin.y - content.y) / content.height, originBottomScale = 1 - originTopScale;
|
|
266
|
+
let correctScaleX, correctScaleY, aScale, bScale, aSize, bSize;
|
|
267
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, "width")) {
|
|
268
|
+
correctScaleX = scale.x < 0 ? 1 / scale.x : 1;
|
|
269
|
+
if (scale.x < 0) tempContent.scaleOf(origin, correctScaleX, 1);
|
|
270
|
+
aSize = float(tempContent.minX - tempDragBounds.minX);
|
|
271
|
+
bSize = float(tempDragBounds.maxX - tempContent.maxX);
|
|
272
|
+
aScale = originLeftScale && aSize > 0 ? 1 + aSize / (originLeftScale * tempContent.width) : 1;
|
|
273
|
+
bScale = originRightScale && bSize > 0 ? 1 + bSize / (originRightScale * tempContent.width) : 1;
|
|
274
|
+
correctScaleX *= max(aScale, bScale);
|
|
275
|
+
} else {
|
|
276
|
+
if (scale.x < 0) tempContent.unsign();
|
|
277
|
+
aSize = float(tempDragBounds.minX - tempContent.minX);
|
|
278
|
+
bSize = float(tempContent.maxX - tempDragBounds.maxX);
|
|
279
|
+
aScale = originLeftScale && aSize > 0 ? 1 - aSize / (originLeftScale * tempContent.width) : 1;
|
|
280
|
+
bScale = originRightScale && bSize > 0 ? 1 - bSize / (originRightScale * tempContent.width) : 1;
|
|
281
|
+
correctScaleX = min(aScale, bScale);
|
|
282
|
+
}
|
|
283
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, "height")) {
|
|
284
|
+
correctScaleY = scale.y < 0 ? 1 / scale.y : 1;
|
|
285
|
+
if (scale.y < 0) tempContent.scaleOf(origin, 1, correctScaleY);
|
|
286
|
+
aSize = float(tempContent.minY - tempDragBounds.minY);
|
|
287
|
+
bSize = float(tempDragBounds.maxY - tempContent.maxY);
|
|
288
|
+
aScale = originTopScale && aSize > 0 ? 1 + aSize / (originTopScale * tempContent.height) : 1;
|
|
289
|
+
bScale = originBottomScale && bSize > 0 ? 1 + bSize / (originBottomScale * tempContent.height) : 1;
|
|
290
|
+
correctScaleY *= max(aScale, bScale);
|
|
291
|
+
if (lockRatio) {
|
|
292
|
+
aScale = max(abs(correctScaleX), abs(correctScaleY));
|
|
293
|
+
correctScaleX = sign(correctScaleX) * aScale;
|
|
294
|
+
correctScaleY = sign(correctScaleY) * aScale;
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
if (scale.y < 0) tempContent.unsign();
|
|
298
|
+
aSize = float(tempDragBounds.minY - tempContent.minY);
|
|
299
|
+
bSize = float(tempContent.maxY - tempDragBounds.maxY);
|
|
300
|
+
aScale = originTopScale && aSize > 0 ? 1 - aSize / (originTopScale * tempContent.height) : 1;
|
|
301
|
+
bScale = originBottomScale && bSize > 0 ? 1 - bSize / (originBottomScale * tempContent.height) : 1;
|
|
302
|
+
correctScaleY = min(aScale, bScale);
|
|
303
|
+
}
|
|
304
|
+
scale.x *= isFinite(correctScaleX) ? correctScaleX : 1;
|
|
305
|
+
scale.y *= isFinite(correctScaleY) ? correctScaleY : 1;
|
|
306
|
+
return scale;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const D = DragBoundsHelper;
|
|
311
|
+
|
|
216
312
|
let PointerEvent = class PointerEvent extends UIEvent {};
|
|
217
313
|
|
|
218
314
|
PointerEvent.POINTER = "pointer";
|
|
@@ -1404,4 +1500,4 @@ canvas.hitPixel = function(radiusPoint, offset, scale = 1) {
|
|
|
1404
1500
|
return data[3] > 0;
|
|
1405
1501
|
};
|
|
1406
1502
|
|
|
1407
|
-
export { App, Cursor, DragEvent, Dragger, DropEvent, HitCanvasManager, InteractionBase, InteractionHelper, KeyEvent, Keyboard, MoveEvent, MyDragEvent, MyPointerEvent, PointerButton, PointerEvent, RotateEvent, SwipeEvent, UIEvent, ZoomEvent };
|
|
1503
|
+
export { App, Cursor, DragBoundsHelper, DragEvent, Dragger, DropEvent, HitCanvasManager, InteractionBase, InteractionHelper, KeyEvent, Keyboard, MoveEvent, MyDragEvent, MyPointerEvent, PointerButton, PointerEvent, RotateEvent, SwipeEvent, UIEvent, ZoomEvent };
|
package/lib/core.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Leafer as t,DragBoundsHelper as e,State as i,UI as s,Rect as a,Box as r,Text as n,Group as h,emptyData as o}from"@leafer-ui/draw";export*from"@leafer-ui/draw";import{registerUI as d,Creator as g,isUndefined as l,DataHelper as c,canvasSizeAttrs as u,LayoutEvent as p,RenderEvent as _,Event as v,EventCreator as m,registerUIEvent as f,LeafList as E,PointHelper as y,BoundsHelper as P,LeafHelper as D,isString as w,isNumber as T,Debug as O,Platform as R,Bounds as L,ResizeEvent as C,LeaferEvent as x,CanvasManager as b,Leaf as S,Matrix as M,tempBounds as k,ImageManager as A,LeaferCanvasBase as H}from"@leafer/core";function B(t,e,i,s){var a,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var h=t.length-1;h>=0;h--)(a=t[h])&&(n=(r<3?a(n):r>3?a(e,i,n):a(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n}"function"==typeof SuppressedError&&SuppressedError;let F=class extends t{get __tag(){return"App"}get isApp(){return!0}constructor(t,e){super(t,e)}init(t,e){if(super.init(t,e),t){const{ground:e,tree:i,sky:s,editor:a}=t;e&&(this.ground=this.addLeafer(e)),(i||a)&&(this.tree=this.addLeafer(i||{type:t.type||"design"})),(s||a)&&(this.sky=this.addLeafer(s)),a&&g.editor(a,this)}}__setApp(){const{canvas:t}=this,{realCanvas:e,view:i}=this.config;e||i===this.canvas.view||!t.parentView?this.realCanvas=!0:t.unrealCanvas(),this.leafer=this,this.watcher.disable(),this.layouter.disable()}__updateLocalBounds(){this.forEach(t=>t.updateLayout()),super.__updateLocalBounds()}start(){super.start(),this.forEach(t=>t.start())}stop(){this.forEach(t=>t.stop()),super.stop()}unlockLayout(){super.unlockLayout(),this.forEach(t=>t.unlockLayout())}lockLayout(){super.lockLayout(),this.forEach(t=>t.lockLayout())}forceRender(t,e){this.forEach(i=>i.forceRender(t,e))}addLeafer(e){const i=new t(e);return this.add(i),i}add(t,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout(()=>this.add(t,e),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),l(e)||(t.canvas.childIndex=e),this.__listenChildEvents(t)}forEach(t){this.children.forEach(t)}__onCreated(){this.created=this.children.every(t=>t.created)}__onReady(){this.children.every(t=>t.ready)&&super.__onReady()}__onViewReady(){this.children.every(t=>t.viewReady)&&super.__onViewReady()}__onChildRenderEnd(t){this.renderer.addBlock(t.renderBounds),this.viewReady&&this.renderer.update()}__render(t,e){t.context&&this.forEach(i=>e.matrix?i.__render(t,e):t.copyWorld(i.canvas,e.bounds))}__onResize(t){this.forEach(e=>e.resize(t)),super.__onResize(t)}updateLayout(){this.forEach(t=>t.updateLayout())}__getChildConfig(t){const e=Object.assign({},this.config);return e.hittable=e.realCanvas=void 0,t&&c.assign(e,t),this.autoLayout&&c.copyAttrs(e,this,u),e.view=this.realCanvas?void 0:this.view,e.fill=void 0,e}__listenChildEvents(t){t.once([[p.END,this.__onReady,this],[_.START,this.__onCreated,this],[_.END,this.__onViewReady,this]]),this.realCanvas&&this.__eventIds.push(t.on_(_.END,this.__onChildRenderEnd,this))}};F=B([d()],F);const N={},I={isHoldSpaceKey:()=>I.isHold("Space"),isHold:t=>N[t],isHoldKeys:(t,e)=>e?t(e):void 0,setDownCode(t){N[t]||(N[t]=!0)},setUpCode(t){N[t]=!1}},K={LEFT:1,RIGHT:2,MIDDLE:4,defaultLeft(t){t.buttons||(t.buttons=1)},left:t=>1===t.buttons,right:t=>2===t.buttons,middle:t=>4===t.buttons};class W extends v{get spaceKey(){return I.isHoldSpaceKey()}get left(){return K.left(this)}get right(){return K.right(this)}get middle(){return K.middle(this)}constructor(t){super(t.type),this.bubbles=!0,Object.assign(this,t)}isHoldKeys(t){return I.isHoldKeys(t,this)}getBoxPoint(t){return(t||this.current).getBoxPoint(this)}getInnerPoint(t){return(t||this.current).getInnerPoint(this)}getLocalPoint(t){return(t||this.current).getLocalPoint(this)}getPagePoint(){return this.current.getPagePoint(this)}getInner(t){return this.getInnerPoint(t)}getLocal(t){return this.getLocalPoint(t)}getPage(){return this.getPagePoint()}static changeName(t,e){m.changeName(t,e)}}let U=class extends W{};U.POINTER="pointer",U.BEFORE_DOWN="pointer.before_down",U.BEFORE_MOVE="pointer.before_move",U.BEFORE_UP="pointer.before_up",U.DOWN="pointer.down",U.MOVE="pointer.move",U.UP="pointer.up",U.OVER="pointer.over",U.OUT="pointer.out",U.ENTER="pointer.enter",U.LEAVE="pointer.leave",U.TAP="tap",U.DOUBLE_TAP="double_tap",U.CLICK="click",U.DOUBLE_CLICK="double_click",U.LONG_PRESS="long_press",U.LONG_TAP="long_tap",U.MENU="pointer.menu",U.MENU_TAP="pointer.menu_tap",U=B([f()],U);const V=U,j={};let z=class extends U{static setList(t){this.list=t instanceof E?t:new E(t)}static setData(t){this.data=t}static getValidMove(t,i,s,a=!0){const r=t.getLocalPoint(s,null,!0);return y.move(r,i.x-t.x,i.y-t.y),a&&this.limitMove(t,r),e.axisMove(t,r),r}static limitMove(t,i){e.limitMove(t,i)}getPageMove(t){return this.assignMove(t),this.current.getPagePoint(j,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(j,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(j,null,!0)}getPageTotal(){return this.getPageMove(!0)}getInnerTotal(t){return this.getInnerMove(t,!0)}getLocalTotal(t){return this.getLocalMove(t,!0)}getPageBounds(){const t=this.getPageTotal(),e=this.getPagePoint(),i={};return P.set(i,e.x-t.x,e.y-t.y,t.x,t.y),P.unsign(i),i}assignMove(t){j.x=t?this.totalX:this.moveX,j.y=t?this.totalY:this.moveY}};z.BEFORE_DRAG="drag.before_drag",z.START="drag.start",z.DRAG="drag",z.END="drag.end",z.OVER="drag.over",z.OUT="drag.out",z.ENTER="drag.enter",z.LEAVE="drag.leave",z=B([f()],z);const G=z;let X=class extends U{static setList(t){z.setList(t)}static setData(t){z.setData(t)}};X.DROP="drop",X=B([f()],X);let Y=class extends z{};Y.BEFORE_MOVE="move.before_move",Y.START="move.start",Y.MOVE="move",Y.END="move.end",Y=B([f()],Y);let Z=class extends U{};Z.BEFORE_ROTATE="rotate.before_rotate",Z.START="rotate.start",Z.ROTATE="rotate",Z.END="rotate.end",Z=B([f()],Z);let q=class extends z{};q.SWIPE="swipe",q.LEFT="swipe.left",q.RIGHT="swipe.right",q.UP="swipe.up",q.DOWN="swipe.down",q=B([f()],q);let J=class extends U{};J.BEFORE_ZOOM="zoom.before_zoom",J.START="zoom.start",J.ZOOM="zoom",J.END="zoom.end",J=B([f()],J);let Q=class extends W{};Q.BEFORE_DOWN="key.before_down",Q.BEFORE_UP="key.before_up",Q.DOWN="key.down",Q.HOLD="key.hold",Q.UP="key.up",Q=B([f()],Q);const $={getDragEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:i.x,y:i.y,moveX:i.x-e.x,moveY:i.y-e.y,totalX:i.x-t.x,totalY:i.y-t.y}),getDropEventData:(t,e,i)=>Object.assign(Object.assign({},t),{list:e,data:i}),getSwipeDirection:t=>t<-45&&t>-135?q.UP:t>45&&t<135?q.DOWN:t<=45&&t>=-45?q.RIGHT:q.LEFT,getSwipeEventData:(t,e,i)=>Object.assign(Object.assign({},i),{moveX:e.moveX,moveY:e.moveY,totalX:i.x-t.x,totalY:i.y-t.y,type:tt.getSwipeDirection(y.getAngle(t,i))}),getBase(t){const e=1===t.button?4:t.button;return{altKey:t.altKey,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,metaKey:t.metaKey,buttons:l(t.buttons)?1:0===t.buttons?e:t.buttons,origin:t}},pathHasEventType(t,e){const{list:i}=t;for(let t=0,s=i.length;t<s;t++)if(i[t].hasEvent(e))return!0;return!1},filterPathByEventType(t,e){const i=new E,{list:s}=t;for(let t=0,a=s.length;t<a;t++)s[t].hasEvent(e)&&i.add(s[t]);return i},pathCanDrag:t=>t&&t.list.some(t=>D.draggable(t)||!t.isLeafer&&t.hasEvent(z.DRAG)),pathHasOutside:t=>t&&t.list.some(t=>t.isOutside)},tt=$,et=new E,{getDragEventData:it,getDropEventData:st,getSwipeEventData:at}=$;class rt{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=it(t,t,t),this.canAnimate=this.canDragOut=!0}getList(t,e){const{proxy:i}=this.interaction.selector,s=i&&i.list.length,a=z.list||this.draggableList||et;return this.dragging&&(s?t?et:new E(e?[...i.list,...i.dragHoverExclude]:i.list):a)}checkDrag(t,e){const{interaction:i}=this;if(this.moving&&t.buttons<1)return this.canAnimate=!1,void i.pointerCancel();!this.moving&&e&&(this.moving=i.canMove(this.downData)||i.isHoldRightKey||i.isMobileDragEmpty)&&(this.dragData.moveType="drag",i.emit(Y.START,this.dragData)),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&K.left(t),this.dragging&&(this.interaction.emit(z.START,this.dragData),this.getDraggableList(this.dragData.path),this.setDragStartPoints(this.realDraggableList=this.getList(!0))))}setDragStartPoints(t){this.dragStartPoints={},t.forEach(t=>this.dragStartPoints[t.innerId]={x:t.x,y:t.y})}getDraggableList(t){let e;for(let i=0,s=t.length;i<s;i++)if(e=t.list[i],D.draggable(e)){this.draggableList=new E(e);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:a,throughPath:r}=s;this.dragData=it(s,i,t),r&&(this.dragData.throughPath=r),this.dragData.path=a,this.moving?(this.dragData.moveType="drag",e.emit(Y.BEFORE_MOVE,this.dragData),e.emit(Y.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(z.BEFORE_DRAG,this.dragData),e.emit(z.DRAG,this.dragData))}dragReal(t){const{interaction:e}=this,{running:i}=e,s=this.realDraggableList;if(s.length&&i){const{totalX:i,totalY:a}=this.dragData,{dragLimitAnimate:r}=e.p,n=!r||!!t;s.forEach(e=>{if(e.draggable){const s=w(e.draggable),h=z.getValidMove(e,this.dragStartPoints[e.innerId],{x:i,y:a},n||s);r&&!s&&t?D.animateMove(e,h,T(r)?r:.3):e.move(h)}})}}dragOverOrOut(t){const{interaction:e}=this,{dragOverPath:i}=this,{path:s}=t;this.dragOverPath=s,i?s.indexAt(0)!==i.indexAt(0)&&(e.emit(z.OUT,t,i),e.emit(z.OVER,t,s)):e.emit(z.OVER,t,s)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:s}=t;e.emit(z.LEAVE,t,i,s),e.emit(z.ENTER,t,s,i),this.dragEnterPath=s}dragEnd(t,e){(this.dragging||this.moving)&&(this.checkDragEndAnimate(t,e)||this.dragEndReal(t))}dragEndReal(t){const{interaction:e,downData:i,dragData:s}=this;t||(t=s);const{path:a,throughPath:r}=i,n=it(i,t,t);if(r&&(n.throughPath=r),n.path=a,this.moving&&(this.moving=!1,n.moveType="drag",e.emit(Y.END,n)),this.dragging){const a=this.getList();this.dragging=!1,e.p.dragLimitAnimate&&this.dragReal(!0),e.emit(z.END,n),this.swipe(t,i,s,n),this.drop(t,a,this.dragEnterPath)}this.autoMoveCancel(),this.dragReset(),this.animate(null,"off")}swipe(t,e,i,s){const{interaction:a}=this;if(y.getDistance(e,t)>a.config.pointer.swipeDistance){const t=at(e,i,s);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=st(t,e,z.data);s.path=i,this.interaction.emit(X.DROP,s),this.interaction.emit(z.LEAVE,t,i)}dragReset(){z.list=z.data=this.draggableList=this.dragData=this.downData=this.dragOverPath=this.dragEnterPath=null}checkDragEndAnimate(t,e){return!1}animate(t,e){}checkDragOut(t){}autoMoveOnDragOut(t){}autoMoveCancel(){}destroy(){this.dragReset()}}const nt=O.get("emit");const ht=["move","zoom","rotate","key"];function ot(t,e,i,s,a){if(ht.some(t=>e.startsWith(t))&&t.__.hitChildren&&!gt(t,a)){let r;for(let n=0,h=t.children.length;n<h;n++)r=t.children[n],!i.path.has(r)&&r.__.hittable&&dt(r,e,i,s,a)}}function dt(t,e,s,a,r){if(t.destroyed)return!1;if(t.__.hitSelf&&!gt(t,r)&&(i.updateEventStyle&&!a&&i.updateEventStyle(t,e),t.hasEvent(e,a))){s.phase=a?1:t===s.target?2:3;const i=m.get(e,s);if(t.emitEvent(i,a),i.isStop)return!0}return!1}function gt(t,e){return e&&e.has(t)}const lt={wheel:{zoomSpeed:.5,moveSpeed:.5,rotateSpeed:.5,delta:{x:20,y:8}},pointer:{type:"pointer",snap:!0,hitRadius:5,tapTime:120,longPressTime:800,transformTime:500,hover:!0,dragHover:!0,dragDistance:2,swipeDistance:20},touch:{preventDefault:"auto"},multiTouch:{},move:{autoDistance:2},zoom:{},cursor:!0,keyEvent:!0},{pathHasEventType:ct,pathCanDrag:ut,pathHasOutside:pt}=$;class _t{get dragging(){return this.dragger.dragging}get transforming(){return this.transformer.transforming}get moveMode(){return!0===this.m.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get canHover(){return this.p.hover&&!this.config.mobile}get isDragEmpty(){return this.m.dragEmpty&&this.isRootPath(this.hoverData)&&(!this.downData||this.isRootPath(this.downData))}get isMobileDragEmpty(){return this.m.dragEmpty&&!this.canHover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.m.holdMiddleKey&&this.downData&&K.middle(this.downData)}get isHoldRightKey(){return this.m.holdRightKey&&this.downData&&K.right(this.downData)}get isHoldSpaceKey(){return this.m.holdSpaceKey&&I.isHoldSpaceKey()}get m(){return this.config.move}get p(){return this.config.pointer}get hitRadius(){return this.p.hitRadius}constructor(t,e,i,s){this.config=c.clone(lt),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new E(t),this.createTransformer(),this.dragger=new rt(this),s&&(this.config=c.default(s,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(K.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(U.BEFORE_DOWN,t),this.emit(U.DOWN,t),K.left(t)&&(this.tapWait(),this.longPressWait(t)),this.waitRightTap=K.right(t),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&K.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){if(this.emit(U.BEFORE_MOVE,t,this.defaultPath),this.downData){const e=y.getDistance(this.downData,t)>this.p.dragDistance;e&&(this.pointerWaitCancel(),this.waitRightTap=!1),this.dragger.checkDrag(t,e)}this.dragger.moving||(this.updateHoverData(t),this.checkPath(t),this.emit(U.MOVE,t),this.pointerHover(t),this.dragging&&(this.dragger.dragOverOrOut(t),this.dragger.dragEnterOrLeave(t))),this.updateCursor(this.downData||t)}pointerUp(t){const{downData:e}=this;if(t||(t=e),!e)return;K.defaultLeft(t),t.multiTouch=e.multiTouch,this.findPath(t);const i=Object.assign(Object.assign({},t),{path:t.path.clone()});t.path.addList(e.path.list),this.checkPath(t),this.downData=null,this.emit(U.BEFORE_UP,t),this.emit(U.UP,t),this.touchLeave(t),t.isCancel||(this.tap(t),this.menuTap(t)),this.dragger.dragEnd(t),this.updateCursor(i)}pointerCancel(){const t=Object.assign({},this.dragger.dragData);t.isCancel=!0,this.pointerUp(t)}menu(t){this.findPath(t),this.emit(U.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(U.MENU_TAP,t),this.waitRightTap=this.waitMenuTap=!1)}createTransformer(){}move(t){}zoom(t){}rotate(t){}transformEnd(){}wheel(t){}multiTouch(t,e){}keyDown(t){if(!this.config.keyEvent)return;this.emit(Q.BEFORE_DOWN,t,this.defaultPath);const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,I.setDownCode(e),this.emit(Q.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(Q.DOWN,t,this.defaultPath)}keyUp(t){if(!this.config.keyEvent)return;this.emit(Q.BEFORE_UP,t,this.defaultPath);const{code:e}=t;this.downKeyMap[e]=!1,I.setUpCode(e),this.emit(Q.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){!this.canHover||this.dragging&&!this.p.dragHover||(t.path||(t.path=new E),this.pointerOverOrOut(t),this.pointerEnterOrLeave(t))}pointerOverOrOut(t){const{path:e}=t,{overPath:i}=this;this.overPath=e,i?e.indexAt(0)!==i.indexAt(0)&&(this.emit(U.OUT,t,i),this.emit(U.OVER,t,e)):this.emit(U.OVER,t,e)}pointerEnterOrLeave(t){let{path:e}=t;this.downData&&!this.moveMode&&(e=e.clone(),this.downData.path.forEach(t=>e.add(t)));const{enterPath:i}=this;this.enterPath=e,this.emit(U.LEAVE,t,i,e),this.emit(U.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(U.LEAVE,t),this.dragger.dragging&&this.emit(X.LEAVE,t))}tap(t){const{pointer:e}=this.config,i=this.longTap(t);if(!e.tapMore&&i)return;if(!this.waitTap)return;e.tapMore&&this.emitTap(t);const s=Date.now()-this.downTime,a=[U.DOUBLE_TAP,U.DOUBLE_CLICK].some(e=>ct(t.path,e));s<e.tapTime+50&&a?(this.tapCount++,2===this.tapCount?(this.tapWaitCancel(),this.emitDoubleTap(t)):(clearTimeout(this.tapTimer),this.tapTimer=setTimeout(()=>{e.tapMore||(this.tapWaitCancel(),this.emitTap(t))},e.tapTime))):e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}findPath(t,e){const{hitRadius:i,through:s}=this.p,{bottomList:a,target:r}=this;R.backgrounder||t.origin||r&&r.updateLayout();const n=this.selector.getByPoint(t,i,Object.assign({bottomList:a,name:t.type},e||{through:s}));return n.throughPath&&(t.throughPath=n.throughPath),t.path=n.path,n.path}isRootPath(t){return t&&t.path.list[0].isLeafer}isTreePath(t){const e=this.target.app;return!(!e||!e.isApp)&&(e.editor&&!t.path.has(e.editor)&&t.path.has(e.tree)&&!t.target.syncEventer)}checkPath(t,e){(e||this.moveMode&&!pt(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.m.drag&&!ut(t.path))&&!pt(t.path)}isDrag(t){return this.dragger.getList().has(t)}isPress(t){return this.downData&&this.downData.path.has(t)}isHover(t){return this.enterPath&&this.enterPath.has(t)}isFocus(t){return this.focusData===t}cancelHover(){const{hoverData:t}=this;t&&(t.path=this.defaultPath,this.pointerHover(t))}updateDownData(t,e,i){const{downData:s}=this;!t&&s&&(t=s),t&&(this.findPath(t,e),i&&s&&t.path.addList(s.path.list),this.downData=t)}updateHoverData(t){t||(t=this.hoverData),t&&(this.findPath(t,{exclude:this.dragger.getList(!1,!0),name:U.MOVE}),this.hoverData=t)}updateCursor(t){if(!this.config.cursor||!this.canHover)return;if(t||(this.updateHoverData(),t=this.downData||this.hoverData),this.dragger.moving)return this.setCursor("grabbing");if(this.canMove(t))return this.setCursor(this.downData?"grabbing":"grab");if(!t)return;let e,i;const{path:s}=t;for(let t=0,a=s.length;t<a&&(e=s.list[t],i=e.syncEventer&&e.syncEventer.cursor||e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}getLocal(t,e){const i=this.canvas.getClientBounds(e),s={x:t.clientX-i.x,y:t.clientY-i.y},{bounds:a}=this.canvas;return s.x*=a.width/i.width,s.y*=a.height/i.height,this.p.snap&&y.round(s),s}emitTap(t){this.emit(U.TAP,t),this.emit(U.CLICK,t)}emitDoubleTap(t){this.emit(U.DOUBLE_TAP,t),this.emit(U.DOUBLE_CLICK,t)}pointerWaitCancel(){this.tapWaitCancel(),this.longPressWaitCancel()}tapWait(){clearTimeout(this.tapTimer),this.waitTap=!0}tapWaitCancel(){this.waitTap&&(clearTimeout(this.tapTimer),this.waitTap=!1,this.tapCount=0)}longPressWait(t){clearTimeout(this.longPressTimer),this.longPressTimer=setTimeout(()=>{this.longPressed=!0,this.emit(U.LONG_PRESS,t)},this.p.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(U.LONG_TAP,t),(ct(t.path,U.LONG_TAP)||ct(t.path,U.LONG_PRESS))&&(e=!0)),this.longPressWaitCancel(),e}longPressWaitCancel(){this.longPressTimer&&(clearTimeout(this.longPressTimer),this.longPressed=!1)}__onResize(){const{dragOut:t}=this.m;this.shrinkCanvasBounds=new L(this.canvas.bounds),this.shrinkCanvasBounds.spread(-(T(t)?t:2))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(C.RESIZE,this.__onResize,this)],t.once(x.READY,()=>this.__onResize())}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}emit(t,e,i,s){this.running&&function(t,e,i,s){if(!i&&!e.path)return;let a;e.type=t,i?e=Object.assign(Object.assign({},e),{path:i}):i=e.path,e.target=i.indexAt(0);try{for(let r=i.length-1;r>-1;r--){if(a=i.list[r],dt(a,t,e,!0,s))return;a.isApp&&ot(a,t,e,!0,s)}for(let r=0,n=i.length;r<n;r++)if(a=i.list[r],a.isApp&&ot(a,t,e,!1,s),dt(a,t,e,!1,s))return}catch(t){nt.error(t)}}(t,e,i,s)}destroy(){this.__eventIds.length&&(this.stop(),this.__removeListenEvents(),this.dragger.destroy(),this.transformer&&this.transformer.destroy(),this.downData=this.overPath=this.enterPath=null)}}class vt{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}vt.custom={};class mt extends b{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new E,this.pixelList=new E}getPixelType(t,e){return this.__autoClear(),this.pixelList.add(t),g.hitCanvas(e)}getPathType(t){return this.__autoClear(),this.pathList.add(t),g.hitCanvas()}clearImageType(){this.__clearLeafList(this.pixelList)}clearPathType(){this.__clearLeafList(this.pathList)}__clearLeafList(t){t.length&&(t.forEach(t=>{t.__hitCanvas&&(t.__hitCanvas.destroy(),t.__hitCanvas=null)}),t.reset())}__autoClear(){this.pathList.length+this.pixelList.length>this.maxTotal&&this.clear()}clear(){this.clearPathType(),this.clearImageType()}}R.getSelector=function(t){return t.leafer?t.leafer.selector:R.selector||(R.selector=g.selector())};const{toInnerRadiusPointOf:ft,copy:Et,setRadius:yt}=y,{hitRadiusPoint:Pt,hitPoint:Dt}=P,wt={},Tt={},Ot=S.prototype;Ot.hit=function(t,e=0){this.updateLayout(),Et(Tt,t),yt(Tt,e);const i=this.__world;return!!(e?Pt(i,Tt):Dt(i,Tt))&&(this.isBranch?R.getSelector(this).hitPoint(Object.assign({},Tt),e,{target:this}):this.__hitWorld(Tt))},Ot.__hitWorld=function(t){const e=this.__;if(!e.hitSelf)return!1;const i=this.__world,s=this.__layout,a=i.width<10&&i.height<10;if(e.hitRadius&&(Et(wt,t),yt(t=wt,e.hitRadius)),ft(t,i,wt),e.hitBox||a){if(P.hitRadiusPoint(s.boxBounds,wt))return!0;if(a)return!1}return!s.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),s.boundsChanged||(s.hitCanvasChanged=!1)),this.__hit(wt)},Ot.__hitFill=function(t){const e=this.__hitCanvas;return e&&e.hitFill(t,this.__.windingRule)},Ot.__hitStroke=function(t,e){const i=this.__hitCanvas;return i&&i.hitStroke(t,e)},Ot.__hitPixel=function(t){const e=this.__hitCanvas;return e&&e.hitPixel(t,this.__layout.renderBounds,e.hitScale)},Ot.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const Rt=new M,Lt=s.prototype;Lt.__updateHitCanvas=function(){this.__box&&this.__box.__updateHitCanvas();const t=this.leafer||this.parent&&this.parent.leafer;if(!t)return;const e=this.__,{hitCanvasManager:i}=t,s=(e.__isAlphaPixelFill||e.__isCanvas)&&"pixel"===e.hitFill,a=e.__isAlphaPixelStroke&&"pixel"===e.hitStroke,r=s||a;this.__hitCanvas||(this.__hitCanvas=r?i.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):i.getPathType(this));const n=this.__hitCanvas;if(r){const{renderBounds:t}=this.__layout,i=R.image.hitCanvasSize,r=n.hitScale=k.set(0,0,i,i).getFitMatrix(t).a,{x:h,y:o,width:d,height:g}=k.set(t).scale(r);n.resize({width:d,height:g,pixelRatio:1}),n.clear(),A.patternLocked=!0,this.__renderShape(n,{matrix:Rt.setWith(this.__world).scaleWith(1/r).invertWith().translate(-h,-o),ignoreFill:!s,ignoreStroke:!a}),A.patternLocked=!1,n.resetTransform(),e.__isHitPixel=!0}else e.__isHitPixel&&(e.__isHitPixel=!1);this.__drawHitPath(n),n.setStrokeOptions(e)},Lt.__hit=function(t){if(this.__box&&this.__box.__hit(t))return!0;const e=this.__;if(e.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:i}=e,s=(e.fill||e.__isCanvas)&&("path"===i||"pixel"===i&&!(e.__isAlphaPixelFill||e.__isCanvas))||"all"===i;if(s&&this.__hitFill(t))return!0;const{hitStroke:a,__maxStrokeWidth:r}=e,n=e.stroke&&("path"===a||"pixel"===a&&!e.__isAlphaPixelStroke)||"all"===a;if(!s&&!n)return!1;const h=2*t.radiusX;let o=h;if(n)switch(e.strokeAlign){case"inside":if(o+=2*r,!s&&this.__hitFill(t)&&this.__hitStroke(t,o))return!0;o=h;break;case"center":o+=r;break;case"outside":if(o+=2*r,!s){if(!this.__hitFill(t)&&this.__hitStroke(t,o))return!0;o=h}}return!!o&&this.__hitStroke(t,o)};const Ct=s.prototype,xt=a.prototype,bt=r.prototype;xt.__updateHitCanvas=bt.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?Ct.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},xt.__hitFill=bt.__hitFill=function(t){return this.__hitCanvas?Ct.__hitFill.call(this,t):P.hitRadiusPoint(this.__layout.boxBounds,t)},n.prototype.__drawHitPath=function(t){const{__lineHeight:e,fontSize:i,__baseLine:s,__letterSpacing:a,__textDrawData:r}=this.__;t.beginPath(),a<0?this.__drawPathByBox(t):r.rows.forEach(a=>t.rect(a.x,a.y-s,a.width,e<i?i:e))},h.prototype.pick=function(t,e){return e||(e=o),this.updateLayout(),R.getSelector(this).getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this}))};const St=H.prototype;St.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},St.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},St.hitPixel=function(t,e,i=1){let{x:s,y:a,radiusX:r,radiusY:n}=t;e&&(s-=e.x,a-=e.y),k.set(s-r,a-n,2*r,2*n).scale(i).ceil();const{data:h}=this.context.getImageData(k.x,k.y,k.width||1,k.height||1);for(let t=0,e=h.length;t<e;t+=4)if(h[t+3]>0)return!0;return h[3]>0};export{F as App,vt as Cursor,z as DragEvent,rt as Dragger,X as DropEvent,mt as HitCanvasManager,_t as InteractionBase,$ as InteractionHelper,Q as KeyEvent,I as Keyboard,Y as MoveEvent,G as MyDragEvent,V as MyPointerEvent,K as PointerButton,U as PointerEvent,Z as RotateEvent,q as SwipeEvent,W as UIEvent,J as ZoomEvent};
|
|
1
|
+
import{Leafer as t,State as e,UI as i,Rect as s,Box as a,Text as n,Group as r,emptyData as h}from"@leafer-ui/draw";export*from"@leafer-ui/draw";import{registerUI as o,Creator as d,isUndefined as g,DataHelper as l,canvasSizeAttrs as c,LayoutEvent as u,RenderEvent as p,Event as _,EventCreator as m,MathHelper as v,Bounds as f,isFinite as y,registerUIEvent as E,LeafList as D,PointHelper as P,BoundsHelper as x,LeafHelper as w,isString as O,isNumber as T,Debug as L,Platform as R,ResizeEvent as C,LeaferEvent as b,CanvasManager as M,Leaf as S,Matrix as k,tempBounds as B,ImageManager as A,LeaferCanvasBase as H}from"@leafer/core";function I(t,e,i,s){var a,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var h=t.length-1;h>=0;h--)(a=t[h])&&(r=(n<3?a(r):n>3?a(e,i,r):a(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}"function"==typeof SuppressedError&&SuppressedError;let F=class extends t{get __tag(){return"App"}get isApp(){return!0}constructor(t,e){super(t,e)}init(t,e){if(super.init(t,e),t){const{ground:e,tree:i,sky:s,editor:a}=t;e&&(this.ground=this.addLeafer(e)),(i||a)&&(this.tree=this.addLeafer(i||{type:t.type||"design"})),(s||a)&&(this.sky=this.addLeafer(s)),a&&d.editor(a,this)}}__setApp(){const{canvas:t}=this,{realCanvas:e,view:i}=this.config;e||i===this.canvas.view||!t.parentView?this.realCanvas=!0:t.unrealCanvas(),this.leafer=this,this.watcher.disable(),this.layouter.disable()}__updateLocalBounds(){this.forEach(t=>t.updateLayout()),super.__updateLocalBounds()}start(){super.start(),this.forEach(t=>t.start())}stop(){this.forEach(t=>t.stop()),super.stop()}unlockLayout(){super.unlockLayout(),this.forEach(t=>t.unlockLayout())}lockLayout(){super.lockLayout(),this.forEach(t=>t.lockLayout())}forceRender(t,e){this.forEach(i=>i.forceRender(t,e))}addLeafer(e){const i=new t(e);return this.add(i),i}add(t,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout(()=>this.add(t,e),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),g(e)||(t.canvas.childIndex=e),this.__listenChildEvents(t)}forEach(t){this.children.forEach(t)}__onCreated(){this.created=this.children.every(t=>t.created)}__onReady(){this.children.every(t=>t.ready)&&super.__onReady()}__onViewReady(){this.children.every(t=>t.viewReady)&&super.__onViewReady()}__onChildRenderEnd(t){this.renderer.addBlock(t.renderBounds),this.viewReady&&this.renderer.update()}__render(t,e){t.context&&this.forEach(i=>e.matrix?i.__render(t,e):t.copyWorld(i.canvas,e.bounds))}__onResize(t){this.forEach(e=>e.resize(t)),super.__onResize(t)}updateLayout(){this.forEach(t=>t.updateLayout())}__getChildConfig(t){const e=Object.assign({},this.config);return e.hittable=e.realCanvas=void 0,t&&l.assign(e,t),this.autoLayout&&l.copyAttrs(e,this,c),e.view=this.realCanvas?void 0:this.view,e.fill=void 0,e}__listenChildEvents(t){t.once([[u.END,this.__onReady,this],[p.START,this.__onCreated,this],[p.END,this.__onViewReady,this]]),this.realCanvas&&this.__eventIds.push(t.on_(p.END,this.__onChildRenderEnd,this))}};F=I([o()],F);const N={},K={isHoldSpaceKey:()=>K.isHold("Space"),isHold:t=>N[t],isHoldKeys:(t,e)=>e?t(e):void 0,setDownCode(t){N[t]||(N[t]=!0)},setUpCode(t){N[t]=!1}},W={LEFT:1,RIGHT:2,MIDDLE:4,defaultLeft(t){t.buttons||(t.buttons=1)},left:t=>1===t.buttons,right:t=>2===t.buttons,middle:t=>4===t.buttons};class V extends _{get spaceKey(){return K.isHoldSpaceKey()}get left(){return W.left(this)}get right(){return W.right(this)}get middle(){return W.middle(this)}constructor(t){super(t.type),this.bubbles=!0,Object.assign(this,t)}isHoldKeys(t){return K.isHoldKeys(t,this)}getBoxPoint(t){return(t||this.current).getBoxPoint(this)}getInnerPoint(t){return(t||this.current).getInnerPoint(this)}getLocalPoint(t){return(t||this.current).getLocalPoint(this)}getPagePoint(){return this.current.getPagePoint(this)}getInner(t){return this.getInnerPoint(t)}getLocal(t){return this.getLocalPoint(t)}getPage(){return this.getPagePoint()}static changeName(t,e){m.changeName(t,e)}}const{float:U,sign:j}=v,{min:X,max:Y,abs:z}=Math,G=new f,Z=new f,q={limitMove(t,e){const{dragBounds:i,dragBoundsType:s}=t;i&&J.getValidMove(t.__localBoxBounds,J.getDragBounds(t),s,e,!0),J.axisMove(t,e)},limitScaleOf(t,e,i,s){const{dragBounds:a,dragBoundsType:n}=t;a&&J.getValidScaleOf(t.__localBoxBounds,J.getDragBounds(t),n,t.getLocalPointByInner(t.getInnerPointByBox(e)),i,s,!0)},axisMove(t,e){const{draggable:i}=t;"x"===i&&(e.y=0),"y"===i&&(e.x=0)},getDragBounds(t){const{dragBounds:e}=t;return"parent"===e?t.parent.boxBounds:e},isInnerMode:(t,e,i,s)=>"inner"===i||"auto"===i&&t[s]>e[s],getValidMove(t,e,i,s,a){const n=t.x+s.x,r=t.y+s.y,h=n+t.width,o=r+t.height,d=e.x+e.width,g=e.y+e.height;return a||(s=Object.assign({},s)),J.isInnerMode(t,e,i,"width")?n>e.x?s.x+=e.x-n:h<d&&(s.x+=d-h):n<e.x?s.x+=e.x-n:h>d&&(s.x+=d-h),J.isInnerMode(t,e,i,"height")?r>e.y?s.y+=e.y-r:o<g&&(s.y+=g-o):r<e.y?s.y+=e.y-r:o>g&&(s.y+=g-o),s.x=U(s.x),s.y=U(s.y),s},getValidScaleOf(t,e,i,s,a,n,r){r||(a=Object.assign({},a)),Z.set(e),G.set(t).scaleOf(s,a.x,a.y);const h=(s.x-t.x)/t.width,o=1-h,d=(s.y-t.y)/t.height,g=1-d;let l,c,u,p,_,m;return J.isInnerMode(t,e,i,"width")?(l=a.x<0?1/a.x:1,a.x<0&&G.scaleOf(s,l,1),_=U(G.minX-Z.minX),m=U(Z.maxX-G.maxX),u=h&&_>0?1+_/(h*G.width):1,p=o&&m>0?1+m/(o*G.width):1,l*=Y(u,p)):(a.x<0&&G.unsign(),_=U(Z.minX-G.minX),m=U(G.maxX-Z.maxX),u=h&&_>0?1-_/(h*G.width):1,p=o&&m>0?1-m/(o*G.width):1,l=X(u,p)),J.isInnerMode(t,e,i,"height")?(c=a.y<0?1/a.y:1,a.y<0&&G.scaleOf(s,1,c),_=U(G.minY-Z.minY),m=U(Z.maxY-G.maxY),u=d&&_>0?1+_/(d*G.height):1,p=g&&m>0?1+m/(g*G.height):1,c*=Y(u,p),n&&(u=Y(z(l),z(c)),l=j(l)*u,c=j(c)*u)):(a.y<0&&G.unsign(),_=U(Z.minY-G.minY),m=U(G.maxY-Z.maxY),u=d&&_>0?1-_/(d*G.height):1,p=g&&m>0?1-m/(g*G.height):1,c=X(u,p)),a.x*=y(l)?l:1,a.y*=y(c)?c:1,a}},J=q;let Q=class extends V{};Q.POINTER="pointer",Q.BEFORE_DOWN="pointer.before_down",Q.BEFORE_MOVE="pointer.before_move",Q.BEFORE_UP="pointer.before_up",Q.DOWN="pointer.down",Q.MOVE="pointer.move",Q.UP="pointer.up",Q.OVER="pointer.over",Q.OUT="pointer.out",Q.ENTER="pointer.enter",Q.LEAVE="pointer.leave",Q.TAP="tap",Q.DOUBLE_TAP="double_tap",Q.CLICK="click",Q.DOUBLE_CLICK="double_click",Q.LONG_PRESS="long_press",Q.LONG_TAP="long_tap",Q.MENU="pointer.menu",Q.MENU_TAP="pointer.menu_tap",Q=I([E()],Q);const $=Q,tt={};let et=class extends Q{static setList(t){this.list=t instanceof D?t:new D(t)}static setData(t){this.data=t}static getValidMove(t,e,i,s=!0){const a=t.getLocalPoint(i,null,!0);return P.move(a,e.x-t.x,e.y-t.y),s&&this.limitMove(t,a),q.axisMove(t,a),a}static limitMove(t,e){q.limitMove(t,e)}getPageMove(t){return this.assignMove(t),this.current.getPagePoint(tt,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(tt,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(tt,null,!0)}getPageTotal(){return this.getPageMove(!0)}getInnerTotal(t){return this.getInnerMove(t,!0)}getLocalTotal(t){return this.getLocalMove(t,!0)}getPageBounds(){const t=this.getPageTotal(),e=this.getPagePoint(),i={};return x.set(i,e.x-t.x,e.y-t.y,t.x,t.y),x.unsign(i),i}assignMove(t){tt.x=t?this.totalX:this.moveX,tt.y=t?this.totalY:this.moveY}};et.BEFORE_DRAG="drag.before_drag",et.START="drag.start",et.DRAG="drag",et.END="drag.end",et.OVER="drag.over",et.OUT="drag.out",et.ENTER="drag.enter",et.LEAVE="drag.leave",et=I([E()],et);const it=et;let st=class extends Q{static setList(t){et.setList(t)}static setData(t){et.setData(t)}};st.DROP="drop",st=I([E()],st);let at=class extends et{};at.BEFORE_MOVE="move.before_move",at.START="move.start",at.MOVE="move",at.END="move.end",at=I([E()],at);let nt=class extends Q{};nt.BEFORE_ROTATE="rotate.before_rotate",nt.START="rotate.start",nt.ROTATE="rotate",nt.END="rotate.end",nt=I([E()],nt);let rt=class extends et{};rt.SWIPE="swipe",rt.LEFT="swipe.left",rt.RIGHT="swipe.right",rt.UP="swipe.up",rt.DOWN="swipe.down",rt=I([E()],rt);let ht=class extends Q{};ht.BEFORE_ZOOM="zoom.before_zoom",ht.START="zoom.start",ht.ZOOM="zoom",ht.END="zoom.end",ht=I([E()],ht);let ot=class extends V{};ot.BEFORE_DOWN="key.before_down",ot.BEFORE_UP="key.before_up",ot.DOWN="key.down",ot.HOLD="key.hold",ot.UP="key.up",ot=I([E()],ot);const dt={getDragEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:i.x,y:i.y,moveX:i.x-e.x,moveY:i.y-e.y,totalX:i.x-t.x,totalY:i.y-t.y}),getDropEventData:(t,e,i)=>Object.assign(Object.assign({},t),{list:e,data:i}),getSwipeDirection:t=>t<-45&&t>-135?rt.UP:t>45&&t<135?rt.DOWN:t<=45&&t>=-45?rt.RIGHT:rt.LEFT,getSwipeEventData:(t,e,i)=>Object.assign(Object.assign({},i),{moveX:e.moveX,moveY:e.moveY,totalX:i.x-t.x,totalY:i.y-t.y,type:gt.getSwipeDirection(P.getAngle(t,i))}),getBase(t){const e=1===t.button?4:t.button;return{altKey:t.altKey,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,metaKey:t.metaKey,buttons:g(t.buttons)?1:0===t.buttons?e:t.buttons,origin:t}},pathHasEventType(t,e){const{list:i}=t;for(let t=0,s=i.length;t<s;t++)if(i[t].hasEvent(e))return!0;return!1},filterPathByEventType(t,e){const i=new D,{list:s}=t;for(let t=0,a=s.length;t<a;t++)s[t].hasEvent(e)&&i.add(s[t]);return i},pathCanDrag:t=>t&&t.list.some(t=>w.draggable(t)||!t.isLeafer&&t.hasEvent(et.DRAG)),pathHasOutside:t=>t&&t.list.some(t=>t.isOutside)},gt=dt,lt=new D,{getDragEventData:ct,getDropEventData:ut,getSwipeEventData:pt}=dt;class _t{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=ct(t,t,t),this.canAnimate=this.canDragOut=!0}getList(t,e){const{proxy:i}=this.interaction.selector,s=i&&i.list.length,a=et.list||this.draggableList||lt;return this.dragging&&(s?t?lt:new D(e?[...i.list,...i.dragHoverExclude]:i.list):a)}checkDrag(t,e){const{interaction:i}=this;if(this.moving&&t.buttons<1)return this.canAnimate=!1,void i.pointerCancel();!this.moving&&e&&(this.moving=i.canMove(this.downData)||i.isHoldRightKey||i.isMobileDragEmpty)&&(this.dragData.moveType="drag",i.emit(at.START,this.dragData)),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&W.left(t),this.dragging&&(this.interaction.emit(et.START,this.dragData),this.getDraggableList(this.dragData.path),this.setDragStartPoints(this.realDraggableList=this.getList(!0))))}setDragStartPoints(t){this.dragStartPoints={},t.forEach(t=>this.dragStartPoints[t.innerId]={x:t.x,y:t.y})}getDraggableList(t){let e;for(let i=0,s=t.length;i<s;i++)if(e=t.list[i],w.draggable(e)){this.draggableList=new D(e);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:a,throughPath:n}=s;this.dragData=ct(s,i,t),n&&(this.dragData.throughPath=n),this.dragData.path=a,this.moving?(this.dragData.moveType="drag",e.emit(at.BEFORE_MOVE,this.dragData),e.emit(at.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(et.BEFORE_DRAG,this.dragData),e.emit(et.DRAG,this.dragData))}dragReal(t){const{interaction:e}=this,{running:i}=e,s=this.realDraggableList;if(s.length&&i){const{totalX:i,totalY:a}=this.dragData,{dragLimitAnimate:n}=e.p,r=!n||!!t;s.forEach(e=>{if(e.draggable){const s=O(e.draggable),h=et.getValidMove(e,this.dragStartPoints[e.innerId],{x:i,y:a},r||s);n&&!s&&t?w.animateMove(e,h,T(n)?n:.3):e.move(h)}})}}dragOverOrOut(t){const{interaction:e}=this,{dragOverPath:i}=this,{path:s}=t;this.dragOverPath=s,i?s.indexAt(0)!==i.indexAt(0)&&(e.emit(et.OUT,t,i),e.emit(et.OVER,t,s)):e.emit(et.OVER,t,s)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:s}=t;e.emit(et.LEAVE,t,i,s),e.emit(et.ENTER,t,s,i),this.dragEnterPath=s}dragEnd(t,e){(this.dragging||this.moving)&&(this.checkDragEndAnimate(t,e)||this.dragEndReal(t))}dragEndReal(t){const{interaction:e,downData:i,dragData:s}=this;t||(t=s);const{path:a,throughPath:n}=i,r=ct(i,t,t);if(n&&(r.throughPath=n),r.path=a,this.moving&&(this.moving=!1,r.moveType="drag",e.emit(at.END,r)),this.dragging){const a=this.getList();this.dragging=!1,e.p.dragLimitAnimate&&this.dragReal(!0),e.emit(et.END,r),this.swipe(t,i,s,r),this.drop(t,a,this.dragEnterPath)}this.autoMoveCancel(),this.dragReset(),this.animate(null,"off")}swipe(t,e,i,s){const{interaction:a}=this;if(P.getDistance(e,t)>a.config.pointer.swipeDistance){const t=pt(e,i,s);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=ut(t,e,et.data);s.path=i,this.interaction.emit(st.DROP,s),this.interaction.emit(et.LEAVE,t,i)}dragReset(){et.list=et.data=this.draggableList=this.dragData=this.downData=this.dragOverPath=this.dragEnterPath=null}checkDragEndAnimate(t,e){return!1}animate(t,e){}checkDragOut(t){}autoMoveOnDragOut(t){}autoMoveCancel(){}destroy(){this.dragReset()}}const mt=L.get("emit");const vt=["move","zoom","rotate","key"];function ft(t,e,i,s,a){if(vt.some(t=>e.startsWith(t))&&t.__.hitChildren&&!Et(t,a)){let n;for(let r=0,h=t.children.length;r<h;r++)n=t.children[r],!i.path.has(n)&&n.__.hittable&&yt(n,e,i,s,a)}}function yt(t,i,s,a,n){if(t.destroyed)return!1;if(t.__.hitSelf&&!Et(t,n)&&(e.updateEventStyle&&!a&&e.updateEventStyle(t,i),t.hasEvent(i,a))){s.phase=a?1:t===s.target?2:3;const e=m.get(i,s);if(t.emitEvent(e,a),e.isStop)return!0}return!1}function Et(t,e){return e&&e.has(t)}const Dt={wheel:{zoomSpeed:.5,moveSpeed:.5,rotateSpeed:.5,delta:{x:20,y:8}},pointer:{type:"pointer",snap:!0,hitRadius:5,tapTime:120,longPressTime:800,transformTime:500,hover:!0,dragHover:!0,dragDistance:2,swipeDistance:20},touch:{preventDefault:"auto"},multiTouch:{},move:{autoDistance:2},zoom:{},cursor:!0,keyEvent:!0},{pathHasEventType:Pt,pathCanDrag:xt,pathHasOutside:wt}=dt;class Ot{get dragging(){return this.dragger.dragging}get transforming(){return this.transformer.transforming}get moveMode(){return!0===this.m.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get canHover(){return this.p.hover&&!this.config.mobile}get isDragEmpty(){return this.m.dragEmpty&&this.isRootPath(this.hoverData)&&(!this.downData||this.isRootPath(this.downData))}get isMobileDragEmpty(){return this.m.dragEmpty&&!this.canHover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.m.holdMiddleKey&&this.downData&&W.middle(this.downData)}get isHoldRightKey(){return this.m.holdRightKey&&this.downData&&W.right(this.downData)}get isHoldSpaceKey(){return this.m.holdSpaceKey&&K.isHoldSpaceKey()}get m(){return this.config.move}get p(){return this.config.pointer}get hitRadius(){return this.p.hitRadius}constructor(t,e,i,s){this.config=l.clone(Dt),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new D(t),this.createTransformer(),this.dragger=new _t(this),s&&(this.config=l.default(s,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(W.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(Q.BEFORE_DOWN,t),this.emit(Q.DOWN,t),W.left(t)&&(this.tapWait(),this.longPressWait(t)),this.waitRightTap=W.right(t),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&W.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){if(this.emit(Q.BEFORE_MOVE,t,this.defaultPath),this.downData){const e=P.getDistance(this.downData,t)>this.p.dragDistance;e&&(this.pointerWaitCancel(),this.waitRightTap=!1),this.dragger.checkDrag(t,e)}this.dragger.moving||(this.updateHoverData(t),this.checkPath(t),this.emit(Q.MOVE,t),this.pointerHover(t),this.dragging&&(this.dragger.dragOverOrOut(t),this.dragger.dragEnterOrLeave(t))),this.updateCursor(this.downData||t)}pointerUp(t){const{downData:e}=this;if(t||(t=e),!e)return;W.defaultLeft(t),t.multiTouch=e.multiTouch,this.findPath(t);const i=Object.assign(Object.assign({},t),{path:t.path.clone()});t.path.addList(e.path.list),this.checkPath(t),this.downData=null,this.emit(Q.BEFORE_UP,t),this.emit(Q.UP,t),this.touchLeave(t),t.isCancel||(this.tap(t),this.menuTap(t)),this.dragger.dragEnd(t),this.updateCursor(i)}pointerCancel(){const t=Object.assign({},this.dragger.dragData);t.isCancel=!0,this.pointerUp(t)}menu(t){this.findPath(t),this.emit(Q.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(Q.MENU_TAP,t),this.waitRightTap=this.waitMenuTap=!1)}createTransformer(){}move(t){}zoom(t){}rotate(t){}transformEnd(){}wheel(t){}multiTouch(t,e){}keyDown(t){if(!this.config.keyEvent)return;this.emit(ot.BEFORE_DOWN,t,this.defaultPath);const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,K.setDownCode(e),this.emit(ot.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(ot.DOWN,t,this.defaultPath)}keyUp(t){if(!this.config.keyEvent)return;this.emit(ot.BEFORE_UP,t,this.defaultPath);const{code:e}=t;this.downKeyMap[e]=!1,K.setUpCode(e),this.emit(ot.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){!this.canHover||this.dragging&&!this.p.dragHover||(t.path||(t.path=new D),this.pointerOverOrOut(t),this.pointerEnterOrLeave(t))}pointerOverOrOut(t){const{path:e}=t,{overPath:i}=this;this.overPath=e,i?e.indexAt(0)!==i.indexAt(0)&&(this.emit(Q.OUT,t,i),this.emit(Q.OVER,t,e)):this.emit(Q.OVER,t,e)}pointerEnterOrLeave(t){let{path:e}=t;this.downData&&!this.moveMode&&(e=e.clone(),this.downData.path.forEach(t=>e.add(t)));const{enterPath:i}=this;this.enterPath=e,this.emit(Q.LEAVE,t,i,e),this.emit(Q.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(Q.LEAVE,t),this.dragger.dragging&&this.emit(st.LEAVE,t))}tap(t){const{pointer:e}=this.config,i=this.longTap(t);if(!e.tapMore&&i)return;if(!this.waitTap)return;e.tapMore&&this.emitTap(t);const s=Date.now()-this.downTime,a=[Q.DOUBLE_TAP,Q.DOUBLE_CLICK].some(e=>Pt(t.path,e));s<e.tapTime+50&&a?(this.tapCount++,2===this.tapCount?(this.tapWaitCancel(),this.emitDoubleTap(t)):(clearTimeout(this.tapTimer),this.tapTimer=setTimeout(()=>{e.tapMore||(this.tapWaitCancel(),this.emitTap(t))},e.tapTime))):e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}findPath(t,e){const{hitRadius:i,through:s}=this.p,{bottomList:a,target:n}=this;R.backgrounder||t.origin||n&&n.updateLayout();const r=this.selector.getByPoint(t,i,Object.assign({bottomList:a,name:t.type},e||{through:s}));return r.throughPath&&(t.throughPath=r.throughPath),t.path=r.path,r.path}isRootPath(t){return t&&t.path.list[0].isLeafer}isTreePath(t){const e=this.target.app;return!(!e||!e.isApp)&&(e.editor&&!t.path.has(e.editor)&&t.path.has(e.tree)&&!t.target.syncEventer)}checkPath(t,e){(e||this.moveMode&&!wt(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.m.drag&&!xt(t.path))&&!wt(t.path)}isDrag(t){return this.dragger.getList().has(t)}isPress(t){return this.downData&&this.downData.path.has(t)}isHover(t){return this.enterPath&&this.enterPath.has(t)}isFocus(t){return this.focusData===t}cancelHover(){const{hoverData:t}=this;t&&(t.path=this.defaultPath,this.pointerHover(t))}updateDownData(t,e,i){const{downData:s}=this;!t&&s&&(t=s),t&&(this.findPath(t,e),i&&s&&t.path.addList(s.path.list),this.downData=t)}updateHoverData(t){t||(t=this.hoverData),t&&(this.findPath(t,{exclude:this.dragger.getList(!1,!0),name:Q.MOVE}),this.hoverData=t)}updateCursor(t){if(!this.config.cursor||!this.canHover)return;if(t||(this.updateHoverData(),t=this.downData||this.hoverData),this.dragger.moving)return this.setCursor("grabbing");if(this.canMove(t))return this.setCursor(this.downData?"grabbing":"grab");if(!t)return;let e,i;const{path:s}=t;for(let t=0,a=s.length;t<a&&(e=s.list[t],i=e.syncEventer&&e.syncEventer.cursor||e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}getLocal(t,e){const i=this.canvas.getClientBounds(e),s={x:t.clientX-i.x,y:t.clientY-i.y},{bounds:a}=this.canvas;return s.x*=a.width/i.width,s.y*=a.height/i.height,this.p.snap&&P.round(s),s}emitTap(t){this.emit(Q.TAP,t),this.emit(Q.CLICK,t)}emitDoubleTap(t){this.emit(Q.DOUBLE_TAP,t),this.emit(Q.DOUBLE_CLICK,t)}pointerWaitCancel(){this.tapWaitCancel(),this.longPressWaitCancel()}tapWait(){clearTimeout(this.tapTimer),this.waitTap=!0}tapWaitCancel(){this.waitTap&&(clearTimeout(this.tapTimer),this.waitTap=!1,this.tapCount=0)}longPressWait(t){clearTimeout(this.longPressTimer),this.longPressTimer=setTimeout(()=>{this.longPressed=!0,this.emit(Q.LONG_PRESS,t)},this.p.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(Q.LONG_TAP,t),(Pt(t.path,Q.LONG_TAP)||Pt(t.path,Q.LONG_PRESS))&&(e=!0)),this.longPressWaitCancel(),e}longPressWaitCancel(){this.longPressTimer&&(clearTimeout(this.longPressTimer),this.longPressed=!1)}__onResize(){const{dragOut:t}=this.m;this.shrinkCanvasBounds=new f(this.canvas.bounds),this.shrinkCanvasBounds.spread(-(T(t)?t:2))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(C.RESIZE,this.__onResize,this)],t.once(b.READY,()=>this.__onResize())}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}emit(t,e,i,s){this.running&&function(t,e,i,s){if(!i&&!e.path)return;let a;e.type=t,i?e=Object.assign(Object.assign({},e),{path:i}):i=e.path,e.target=i.indexAt(0);try{for(let n=i.length-1;n>-1;n--){if(a=i.list[n],yt(a,t,e,!0,s))return;a.isApp&&ft(a,t,e,!0,s)}for(let n=0,r=i.length;n<r;n++)if(a=i.list[n],a.isApp&&ft(a,t,e,!1,s),yt(a,t,e,!1,s))return}catch(t){mt.error(t)}}(t,e,i,s)}destroy(){this.__eventIds.length&&(this.stop(),this.__removeListenEvents(),this.dragger.destroy(),this.transformer&&this.transformer.destroy(),this.downData=this.overPath=this.enterPath=null)}}class Tt{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}Tt.custom={};class Lt extends M{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new D,this.pixelList=new D}getPixelType(t,e){return this.__autoClear(),this.pixelList.add(t),d.hitCanvas(e)}getPathType(t){return this.__autoClear(),this.pathList.add(t),d.hitCanvas()}clearImageType(){this.__clearLeafList(this.pixelList)}clearPathType(){this.__clearLeafList(this.pathList)}__clearLeafList(t){t.length&&(t.forEach(t=>{t.__hitCanvas&&(t.__hitCanvas.destroy(),t.__hitCanvas=null)}),t.reset())}__autoClear(){this.pathList.length+this.pixelList.length>this.maxTotal&&this.clear()}clear(){this.clearPathType(),this.clearImageType()}}R.getSelector=function(t){return t.leafer?t.leafer.selector:R.selector||(R.selector=d.selector())};const{toInnerRadiusPointOf:Rt,copy:Ct,setRadius:bt}=P,{hitRadiusPoint:Mt,hitPoint:St}=x,kt={},Bt={},At=S.prototype;At.hit=function(t,e=0){this.updateLayout(),Ct(Bt,t),bt(Bt,e);const i=this.__world;return!!(e?Mt(i,Bt):St(i,Bt))&&(this.isBranch?R.getSelector(this).hitPoint(Object.assign({},Bt),e,{target:this}):this.__hitWorld(Bt))},At.__hitWorld=function(t){const e=this.__;if(!e.hitSelf)return!1;const i=this.__world,s=this.__layout,a=i.width<10&&i.height<10;if(e.hitRadius&&(Ct(kt,t),bt(t=kt,e.hitRadius)),Rt(t,i,kt),e.hitBox||a){if(x.hitRadiusPoint(s.boxBounds,kt))return!0;if(a)return!1}return!s.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),s.boundsChanged||(s.hitCanvasChanged=!1)),this.__hit(kt)},At.__hitFill=function(t){const e=this.__hitCanvas;return e&&e.hitFill(t,this.__.windingRule)},At.__hitStroke=function(t,e){const i=this.__hitCanvas;return i&&i.hitStroke(t,e)},At.__hitPixel=function(t){const e=this.__hitCanvas;return e&&e.hitPixel(t,this.__layout.renderBounds,e.hitScale)},At.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const Ht=new k,It=i.prototype;It.__updateHitCanvas=function(){this.__box&&this.__box.__updateHitCanvas();const t=this.leafer||this.parent&&this.parent.leafer;if(!t)return;const e=this.__,{hitCanvasManager:i}=t,s=(e.__isAlphaPixelFill||e.__isCanvas)&&"pixel"===e.hitFill,a=e.__isAlphaPixelStroke&&"pixel"===e.hitStroke,n=s||a;this.__hitCanvas||(this.__hitCanvas=n?i.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):i.getPathType(this));const r=this.__hitCanvas;if(n){const{renderBounds:t}=this.__layout,i=R.image.hitCanvasSize,n=r.hitScale=B.set(0,0,i,i).getFitMatrix(t).a,{x:h,y:o,width:d,height:g}=B.set(t).scale(n);r.resize({width:d,height:g,pixelRatio:1}),r.clear(),A.patternLocked=!0,this.__renderShape(r,{matrix:Ht.setWith(this.__world).scaleWith(1/n).invertWith().translate(-h,-o),ignoreFill:!s,ignoreStroke:!a}),A.patternLocked=!1,r.resetTransform(),e.__isHitPixel=!0}else e.__isHitPixel&&(e.__isHitPixel=!1);this.__drawHitPath(r),r.setStrokeOptions(e)},It.__hit=function(t){if(this.__box&&this.__box.__hit(t))return!0;const e=this.__;if(e.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:i}=e,s=(e.fill||e.__isCanvas)&&("path"===i||"pixel"===i&&!(e.__isAlphaPixelFill||e.__isCanvas))||"all"===i;if(s&&this.__hitFill(t))return!0;const{hitStroke:a,__maxStrokeWidth:n}=e,r=e.stroke&&("path"===a||"pixel"===a&&!e.__isAlphaPixelStroke)||"all"===a;if(!s&&!r)return!1;const h=2*t.radiusX;let o=h;if(r)switch(e.strokeAlign){case"inside":if(o+=2*n,!s&&this.__hitFill(t)&&this.__hitStroke(t,o))return!0;o=h;break;case"center":o+=n;break;case"outside":if(o+=2*n,!s){if(!this.__hitFill(t)&&this.__hitStroke(t,o))return!0;o=h}}return!!o&&this.__hitStroke(t,o)};const Ft=i.prototype,Nt=s.prototype,Kt=a.prototype;Nt.__updateHitCanvas=Kt.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?Ft.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},Nt.__hitFill=Kt.__hitFill=function(t){return this.__hitCanvas?Ft.__hitFill.call(this,t):x.hitRadiusPoint(this.__layout.boxBounds,t)},n.prototype.__drawHitPath=function(t){const{__lineHeight:e,fontSize:i,__baseLine:s,__letterSpacing:a,__textDrawData:n}=this.__;t.beginPath(),a<0?this.__drawPathByBox(t):n.rows.forEach(a=>t.rect(a.x,a.y-s,a.width,e<i?i:e))},r.prototype.pick=function(t,e){return e||(e=h),this.updateLayout(),R.getSelector(this).getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this}))};const Wt=H.prototype;Wt.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},Wt.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},Wt.hitPixel=function(t,e,i=1){let{x:s,y:a,radiusX:n,radiusY:r}=t;e&&(s-=e.x,a-=e.y),B.set(s-n,a-r,2*n,2*r).scale(i).ceil();const{data:h}=this.context.getImageData(B.x,B.y,B.width||1,B.height||1);for(let t=0,e=h.length;t<e;t+=4)if(h[t+3]>0)return!0;return h[3]>0};export{F as App,Tt as Cursor,q as DragBoundsHelper,et as DragEvent,_t as Dragger,st as DropEvent,Lt as HitCanvasManager,Ot as InteractionBase,dt as InteractionHelper,ot as KeyEvent,K as Keyboard,at as MoveEvent,it as MyDragEvent,$ as MyPointerEvent,W as PointerButton,Q as PointerEvent,nt as RotateEvent,rt as SwipeEvent,V as UIEvent,ht as ZoomEvent};
|
|
2
2
|
//# sourceMappingURL=core.esm.min.js.map
|