@leafer-ui/core 1.9.10 → 1.9.12
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 +17 -13
- package/lib/core.esm.js +18 -14
- 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,7 +213,7 @@ class UIEvent extends core.Event {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
const {float: float, sign: sign} = core.MathHelper, {
|
|
216
|
+
const {min: min, max: max, abs: abs} = Math, {float: float, sign: sign} = core.MathHelper, {minX: minX, maxX: maxX, minY: minY, maxY: maxY} = core.BoundsHelper;
|
|
217
217
|
|
|
218
218
|
const tempContent = new core.Bounds, tempDragBounds = new core.Bounds;
|
|
219
219
|
|
|
@@ -263,26 +263,27 @@ const DragBoundsHelper = {
|
|
|
263
263
|
tempContent.set(content).scaleOf(origin, scale.x, scale.y);
|
|
264
264
|
const originLeftScale = (origin.x - content.x) / content.width, originRightScale = 1 - originLeftScale;
|
|
265
265
|
const originTopScale = (origin.y - content.y) / content.height, originBottomScale = 1 - originTopScale;
|
|
266
|
-
let correctScaleX, correctScaleY, aScale, bScale, aSize, bSize;
|
|
266
|
+
let correctScaleX = 1, correctScaleY = 1, aScale, bScale, aSize, bSize;
|
|
267
267
|
if (D.isInnerMode(content, dragBounds, dragBoundsType, "width")) {
|
|
268
|
-
|
|
269
|
-
if (scale.x < 0) tempContent.scaleOf(origin, correctScaleX, 1);
|
|
268
|
+
if (scale.x < 0) tempContent.scaleOf(origin, correctScaleX = 1 / scale.x, 1);
|
|
270
269
|
aSize = float(tempContent.minX - tempDragBounds.minX);
|
|
271
270
|
bSize = float(tempDragBounds.maxX - tempContent.maxX);
|
|
272
271
|
aScale = originLeftScale && aSize > 0 ? 1 + aSize / (originLeftScale * tempContent.width) : 1;
|
|
273
272
|
bScale = originRightScale && bSize > 0 ? 1 + bSize / (originRightScale * tempContent.width) : 1;
|
|
274
273
|
correctScaleX *= max(aScale, bScale);
|
|
275
274
|
} else {
|
|
276
|
-
if (scale.x < 0)
|
|
275
|
+
if (scale.x < 0) {
|
|
276
|
+
if (float(minX(content) - minX(dragBounds)) <= 0 || float(maxX(dragBounds) - maxX(content)) <= 0) tempContent.scaleOf(origin, correctScaleX = 1 / scale.x, 1);
|
|
277
|
+
tempContent.unsign();
|
|
278
|
+
}
|
|
277
279
|
aSize = float(tempDragBounds.minX - tempContent.minX);
|
|
278
280
|
bSize = float(tempContent.maxX - tempDragBounds.maxX);
|
|
279
281
|
aScale = originLeftScale && aSize > 0 ? 1 - aSize / (originLeftScale * tempContent.width) : 1;
|
|
280
282
|
bScale = originRightScale && bSize > 0 ? 1 - bSize / (originRightScale * tempContent.width) : 1;
|
|
281
|
-
correctScaleX
|
|
283
|
+
correctScaleX *= min(aScale, bScale);
|
|
282
284
|
}
|
|
283
285
|
if (D.isInnerMode(content, dragBounds, dragBoundsType, "height")) {
|
|
284
|
-
|
|
285
|
-
if (scale.y < 0) tempContent.scaleOf(origin, 1, correctScaleY);
|
|
286
|
+
if (scale.y < 0) tempContent.scaleOf(origin, 1, correctScaleY = 1 / scale.y);
|
|
286
287
|
aSize = float(tempContent.minY - tempDragBounds.minY);
|
|
287
288
|
bSize = float(tempDragBounds.maxY - tempContent.maxY);
|
|
288
289
|
aScale = originTopScale && aSize > 0 ? 1 + aSize / (originTopScale * tempContent.height) : 1;
|
|
@@ -294,12 +295,15 @@ const DragBoundsHelper = {
|
|
|
294
295
|
correctScaleY = sign(correctScaleY) * aScale;
|
|
295
296
|
}
|
|
296
297
|
} else {
|
|
297
|
-
if (scale.y < 0)
|
|
298
|
+
if (scale.y < 0) {
|
|
299
|
+
if (float(minY(content) - minY(dragBounds)) <= 0 || float(maxY(dragBounds) - maxY(content)) <= 0) tempContent.scaleOf(origin, 1, correctScaleY = 1 / scale.y);
|
|
300
|
+
tempContent.unsign();
|
|
301
|
+
}
|
|
298
302
|
aSize = float(tempDragBounds.minY - tempContent.minY);
|
|
299
303
|
bSize = float(tempContent.maxY - tempDragBounds.maxY);
|
|
300
304
|
aScale = originTopScale && aSize > 0 ? 1 - aSize / (originTopScale * tempContent.height) : 1;
|
|
301
305
|
bScale = originBottomScale && bSize > 0 ? 1 - bSize / (originBottomScale * tempContent.height) : 1;
|
|
302
|
-
correctScaleY
|
|
306
|
+
correctScaleY *= min(aScale, bScale);
|
|
303
307
|
}
|
|
304
308
|
scale.x *= core.isFinite(correctScaleX) ? correctScaleX : 1;
|
|
305
309
|
scale.y *= core.isFinite(correctScaleY) ? correctScaleY : 1;
|
|
@@ -1379,9 +1383,9 @@ const ui$1 = draw.UI.prototype;
|
|
|
1379
1383
|
|
|
1380
1384
|
ui$1.__updateHitCanvas = function() {
|
|
1381
1385
|
if (this.__box) this.__box.__updateHitCanvas();
|
|
1382
|
-
const
|
|
1383
|
-
if (!
|
|
1384
|
-
const data = this.__
|
|
1386
|
+
const {hitCanvasManager: hitCanvasManager} = this.leafer || this.parent && this.parent.leafer || {};
|
|
1387
|
+
if (!hitCanvasManager) return;
|
|
1388
|
+
const data = this.__;
|
|
1385
1389
|
const isHitPixelFill = (data.__isAlphaPixelFill || data.__isCanvas) && data.hitFill === "pixel";
|
|
1386
1390
|
const isHitPixelStroke = data.__isAlphaPixelStroke && data.hitStroke === "pixel";
|
|
1387
1391
|
const isHitPixel = isHitPixelFill || isHitPixelStroke;
|
package/lib/core.esm.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Leafer, State, UI, Rect, Box, Text, Group, emptyData } from "@leafer-ui
|
|
|
2
2
|
|
|
3
3
|
export * from "@leafer-ui/draw";
|
|
4
4
|
|
|
5
|
-
import { registerUI, Creator, isUndefined, DataHelper, canvasSizeAttrs, LayoutEvent, RenderEvent, Event, EventCreator, MathHelper, Bounds, isFinite, registerUIEvent, LeafList, PointHelper,
|
|
5
|
+
import { registerUI, Creator, isUndefined, DataHelper, canvasSizeAttrs, LayoutEvent, RenderEvent, Event, EventCreator, MathHelper, BoundsHelper, Bounds, isFinite, registerUIEvent, LeafList, PointHelper, 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,7 +213,7 @@ class UIEvent extends Event {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
const {float: float, sign: sign} = MathHelper, {
|
|
216
|
+
const {min: min, max: max, abs: abs} = Math, {float: float, sign: sign} = MathHelper, {minX: minX, maxX: maxX, minY: minY, maxY: maxY} = BoundsHelper;
|
|
217
217
|
|
|
218
218
|
const tempContent = new Bounds, tempDragBounds = new Bounds;
|
|
219
219
|
|
|
@@ -263,26 +263,27 @@ const DragBoundsHelper = {
|
|
|
263
263
|
tempContent.set(content).scaleOf(origin, scale.x, scale.y);
|
|
264
264
|
const originLeftScale = (origin.x - content.x) / content.width, originRightScale = 1 - originLeftScale;
|
|
265
265
|
const originTopScale = (origin.y - content.y) / content.height, originBottomScale = 1 - originTopScale;
|
|
266
|
-
let correctScaleX, correctScaleY, aScale, bScale, aSize, bSize;
|
|
266
|
+
let correctScaleX = 1, correctScaleY = 1, aScale, bScale, aSize, bSize;
|
|
267
267
|
if (D.isInnerMode(content, dragBounds, dragBoundsType, "width")) {
|
|
268
|
-
|
|
269
|
-
if (scale.x < 0) tempContent.scaleOf(origin, correctScaleX, 1);
|
|
268
|
+
if (scale.x < 0) tempContent.scaleOf(origin, correctScaleX = 1 / scale.x, 1);
|
|
270
269
|
aSize = float(tempContent.minX - tempDragBounds.minX);
|
|
271
270
|
bSize = float(tempDragBounds.maxX - tempContent.maxX);
|
|
272
271
|
aScale = originLeftScale && aSize > 0 ? 1 + aSize / (originLeftScale * tempContent.width) : 1;
|
|
273
272
|
bScale = originRightScale && bSize > 0 ? 1 + bSize / (originRightScale * tempContent.width) : 1;
|
|
274
273
|
correctScaleX *= max(aScale, bScale);
|
|
275
274
|
} else {
|
|
276
|
-
if (scale.x < 0)
|
|
275
|
+
if (scale.x < 0) {
|
|
276
|
+
if (float(minX(content) - minX(dragBounds)) <= 0 || float(maxX(dragBounds) - maxX(content)) <= 0) tempContent.scaleOf(origin, correctScaleX = 1 / scale.x, 1);
|
|
277
|
+
tempContent.unsign();
|
|
278
|
+
}
|
|
277
279
|
aSize = float(tempDragBounds.minX - tempContent.minX);
|
|
278
280
|
bSize = float(tempContent.maxX - tempDragBounds.maxX);
|
|
279
281
|
aScale = originLeftScale && aSize > 0 ? 1 - aSize / (originLeftScale * tempContent.width) : 1;
|
|
280
282
|
bScale = originRightScale && bSize > 0 ? 1 - bSize / (originRightScale * tempContent.width) : 1;
|
|
281
|
-
correctScaleX
|
|
283
|
+
correctScaleX *= min(aScale, bScale);
|
|
282
284
|
}
|
|
283
285
|
if (D.isInnerMode(content, dragBounds, dragBoundsType, "height")) {
|
|
284
|
-
|
|
285
|
-
if (scale.y < 0) tempContent.scaleOf(origin, 1, correctScaleY);
|
|
286
|
+
if (scale.y < 0) tempContent.scaleOf(origin, 1, correctScaleY = 1 / scale.y);
|
|
286
287
|
aSize = float(tempContent.minY - tempDragBounds.minY);
|
|
287
288
|
bSize = float(tempDragBounds.maxY - tempContent.maxY);
|
|
288
289
|
aScale = originTopScale && aSize > 0 ? 1 + aSize / (originTopScale * tempContent.height) : 1;
|
|
@@ -294,12 +295,15 @@ const DragBoundsHelper = {
|
|
|
294
295
|
correctScaleY = sign(correctScaleY) * aScale;
|
|
295
296
|
}
|
|
296
297
|
} else {
|
|
297
|
-
if (scale.y < 0)
|
|
298
|
+
if (scale.y < 0) {
|
|
299
|
+
if (float(minY(content) - minY(dragBounds)) <= 0 || float(maxY(dragBounds) - maxY(content)) <= 0) tempContent.scaleOf(origin, 1, correctScaleY = 1 / scale.y);
|
|
300
|
+
tempContent.unsign();
|
|
301
|
+
}
|
|
298
302
|
aSize = float(tempDragBounds.minY - tempContent.minY);
|
|
299
303
|
bSize = float(tempContent.maxY - tempDragBounds.maxY);
|
|
300
304
|
aScale = originTopScale && aSize > 0 ? 1 - aSize / (originTopScale * tempContent.height) : 1;
|
|
301
305
|
bScale = originBottomScale && bSize > 0 ? 1 - bSize / (originBottomScale * tempContent.height) : 1;
|
|
302
|
-
correctScaleY
|
|
306
|
+
correctScaleY *= min(aScale, bScale);
|
|
303
307
|
}
|
|
304
308
|
scale.x *= isFinite(correctScaleX) ? correctScaleX : 1;
|
|
305
309
|
scale.y *= isFinite(correctScaleY) ? correctScaleY : 1;
|
|
@@ -1379,9 +1383,9 @@ const ui$1 = UI.prototype;
|
|
|
1379
1383
|
|
|
1380
1384
|
ui$1.__updateHitCanvas = function() {
|
|
1381
1385
|
if (this.__box) this.__box.__updateHitCanvas();
|
|
1382
|
-
const
|
|
1383
|
-
if (!
|
|
1384
|
-
const data = this.__
|
|
1386
|
+
const {hitCanvasManager: hitCanvasManager} = this.leafer || this.parent && this.parent.leafer || {};
|
|
1387
|
+
if (!hitCanvasManager) return;
|
|
1388
|
+
const data = this.__;
|
|
1385
1389
|
const isHitPixelFill = (data.__isAlphaPixelFill || data.__isCanvas) && data.hitFill === "pixel";
|
|
1386
1390
|
const isHitPixelStroke = data.__isAlphaPixelStroke && data.hitStroke === "pixel";
|
|
1387
1391
|
const isHitPixel = isHitPixelFill || isHitPixelStroke;
|
package/lib/core.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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};
|
|
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,BoundsHelper as f,Bounds as y,isFinite as E,registerUIEvent as D,LeafList as P,PointHelper 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{min:U,max:j,abs:X}=Math,{float:Y,sign:z}=v,{minX:G,maxX:Z,minY:q,maxY:J}=f,Q=new y,$=new y,tt={limitMove(t,e){const{dragBounds:i,dragBoundsType:s}=t;i&&et.getValidMove(t.__localBoxBounds,et.getDragBounds(t),s,e,!0),et.axisMove(t,e)},limitScaleOf(t,e,i,s){const{dragBounds:a,dragBoundsType:n}=t;a&&et.getValidScaleOf(t.__localBoxBounds,et.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)),et.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),et.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=Y(s.x),s.y=Y(s.y),s},getValidScaleOf(t,e,i,s,a,n,r){r||(a=Object.assign({},a)),$.set(e),Q.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,_=1,m=1;return et.isInnerMode(t,e,i,"width")?(a.x<0&&Q.scaleOf(s,_=1/a.x,1),u=Y(Q.minX-$.minX),p=Y($.maxX-Q.maxX),l=h&&u>0?1+u/(h*Q.width):1,c=o&&p>0?1+p/(o*Q.width):1,_*=j(l,c)):(a.x<0&&((Y(G(t)-G(e))<=0||Y(Z(e)-Z(t))<=0)&&Q.scaleOf(s,_=1/a.x,1),Q.unsign()),u=Y($.minX-Q.minX),p=Y(Q.maxX-$.maxX),l=h&&u>0?1-u/(h*Q.width):1,c=o&&p>0?1-p/(o*Q.width):1,_*=U(l,c)),et.isInnerMode(t,e,i,"height")?(a.y<0&&Q.scaleOf(s,1,m=1/a.y),u=Y(Q.minY-$.minY),p=Y($.maxY-Q.maxY),l=d&&u>0?1+u/(d*Q.height):1,c=g&&p>0?1+p/(g*Q.height):1,m*=j(l,c),n&&(l=j(X(_),X(m)),_=z(_)*l,m=z(m)*l)):(a.y<0&&((Y(q(t)-q(e))<=0||Y(J(e)-J(t))<=0)&&Q.scaleOf(s,1,m=1/a.y),Q.unsign()),u=Y($.minY-Q.minY),p=Y(Q.maxY-$.maxY),l=d&&u>0?1-u/(d*Q.height):1,c=g&&p>0?1-p/(g*Q.height):1,m*=U(l,c)),a.x*=E(_)?_:1,a.y*=E(m)?m:1,a}},et=tt;let it=class extends V{};it.POINTER="pointer",it.BEFORE_DOWN="pointer.before_down",it.BEFORE_MOVE="pointer.before_move",it.BEFORE_UP="pointer.before_up",it.DOWN="pointer.down",it.MOVE="pointer.move",it.UP="pointer.up",it.OVER="pointer.over",it.OUT="pointer.out",it.ENTER="pointer.enter",it.LEAVE="pointer.leave",it.TAP="tap",it.DOUBLE_TAP="double_tap",it.CLICK="click",it.DOUBLE_CLICK="double_click",it.LONG_PRESS="long_press",it.LONG_TAP="long_tap",it.MENU="pointer.menu",it.MENU_TAP="pointer.menu_tap",it=I([D()],it);const st=it,at={};let nt=class extends it{static setList(t){this.list=t instanceof P?t:new P(t)}static setData(t){this.data=t}static getValidMove(t,e,i,s=!0){const a=t.getLocalPoint(i,null,!0);return x.move(a,e.x-t.x,e.y-t.y),s&&this.limitMove(t,a),tt.axisMove(t,a),a}static limitMove(t,e){tt.limitMove(t,e)}getPageMove(t){return this.assignMove(t),this.current.getPagePoint(at,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(at,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(at,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 f.set(i,e.x-t.x,e.y-t.y,t.x,t.y),f.unsign(i),i}assignMove(t){at.x=t?this.totalX:this.moveX,at.y=t?this.totalY:this.moveY}};nt.BEFORE_DRAG="drag.before_drag",nt.START="drag.start",nt.DRAG="drag",nt.END="drag.end",nt.OVER="drag.over",nt.OUT="drag.out",nt.ENTER="drag.enter",nt.LEAVE="drag.leave",nt=I([D()],nt);const rt=nt;let ht=class extends it{static setList(t){nt.setList(t)}static setData(t){nt.setData(t)}};ht.DROP="drop",ht=I([D()],ht);let ot=class extends nt{};ot.BEFORE_MOVE="move.before_move",ot.START="move.start",ot.MOVE="move",ot.END="move.end",ot=I([D()],ot);let dt=class extends it{};dt.BEFORE_ROTATE="rotate.before_rotate",dt.START="rotate.start",dt.ROTATE="rotate",dt.END="rotate.end",dt=I([D()],dt);let gt=class extends nt{};gt.SWIPE="swipe",gt.LEFT="swipe.left",gt.RIGHT="swipe.right",gt.UP="swipe.up",gt.DOWN="swipe.down",gt=I([D()],gt);let lt=class extends it{};lt.BEFORE_ZOOM="zoom.before_zoom",lt.START="zoom.start",lt.ZOOM="zoom",lt.END="zoom.end",lt=I([D()],lt);let ct=class extends V{};ct.BEFORE_DOWN="key.before_down",ct.BEFORE_UP="key.before_up",ct.DOWN="key.down",ct.HOLD="key.hold",ct.UP="key.up",ct=I([D()],ct);const ut={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?gt.UP:t>45&&t<135?gt.DOWN:t<=45&&t>=-45?gt.RIGHT:gt.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:pt.getSwipeDirection(x.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 P,{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(nt.DRAG)),pathHasOutside:t=>t&&t.list.some(t=>t.isOutside)},pt=ut,_t=new P,{getDragEventData:mt,getDropEventData:vt,getSwipeEventData:ft}=ut;class yt{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=mt(t,t,t),this.canAnimate=this.canDragOut=!0}getList(t,e){const{proxy:i}=this.interaction.selector,s=i&&i.list.length,a=nt.list||this.draggableList||_t;return this.dragging&&(s?t?_t:new P(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(ot.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(nt.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 P(e);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:a,throughPath:n}=s;this.dragData=mt(s,i,t),n&&(this.dragData.throughPath=n),this.dragData.path=a,this.moving?(this.dragData.moveType="drag",e.emit(ot.BEFORE_MOVE,this.dragData),e.emit(ot.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(nt.BEFORE_DRAG,this.dragData),e.emit(nt.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=nt.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(nt.OUT,t,i),e.emit(nt.OVER,t,s)):e.emit(nt.OVER,t,s)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:s}=t;e.emit(nt.LEAVE,t,i,s),e.emit(nt.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=mt(i,t,t);if(n&&(r.throughPath=n),r.path=a,this.moving&&(this.moving=!1,r.moveType="drag",e.emit(ot.END,r)),this.dragging){const a=this.getList();this.dragging=!1,e.p.dragLimitAnimate&&this.dragReal(!0),e.emit(nt.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(x.getDistance(e,t)>a.config.pointer.swipeDistance){const t=ft(e,i,s);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=vt(t,e,nt.data);s.path=i,this.interaction.emit(ht.DROP,s),this.interaction.emit(nt.LEAVE,t,i)}dragReset(){nt.list=nt.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 Et=L.get("emit");const Dt=["move","zoom","rotate","key"];function Pt(t,e,i,s,a){if(Dt.some(t=>e.startsWith(t))&&t.__.hitChildren&&!wt(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&&xt(n,e,i,s,a)}}function xt(t,i,s,a,n){if(t.destroyed)return!1;if(t.__.hitSelf&&!wt(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 wt(t,e){return e&&e.has(t)}const Ot={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:Tt,pathCanDrag:Lt,pathHasOutside:Rt}=ut;class Ct{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(Ot),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new P(t),this.createTransformer(),this.dragger=new yt(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(it.BEFORE_DOWN,t),this.emit(it.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(it.BEFORE_MOVE,t,this.defaultPath),this.downData){const e=x.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(it.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(it.BEFORE_UP,t),this.emit(it.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(it.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(it.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(ct.BEFORE_DOWN,t,this.defaultPath);const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,K.setDownCode(e),this.emit(ct.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(ct.DOWN,t,this.defaultPath)}keyUp(t){if(!this.config.keyEvent)return;this.emit(ct.BEFORE_UP,t,this.defaultPath);const{code:e}=t;this.downKeyMap[e]=!1,K.setUpCode(e),this.emit(ct.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){!this.canHover||this.dragging&&!this.p.dragHover||(t.path||(t.path=new P),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(it.OUT,t,i),this.emit(it.OVER,t,e)):this.emit(it.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(it.LEAVE,t,i,e),this.emit(it.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(it.LEAVE,t),this.dragger.dragging&&this.emit(ht.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=[it.DOUBLE_TAP,it.DOUBLE_CLICK].some(e=>Tt(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&&!Rt(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.m.drag&&!Lt(t.path))&&!Rt(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:it.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&&x.round(s),s}emitTap(t){this.emit(it.TAP,t),this.emit(it.CLICK,t)}emitDoubleTap(t){this.emit(it.DOUBLE_TAP,t),this.emit(it.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(it.LONG_PRESS,t)},this.p.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(it.LONG_TAP,t),(Tt(t.path,it.LONG_TAP)||Tt(t.path,it.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 y(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],xt(a,t,e,!0,s))return;a.isApp&&Pt(a,t,e,!0,s)}for(let n=0,r=i.length;n<r;n++)if(a=i.list[n],a.isApp&&Pt(a,t,e,!1,s),xt(a,t,e,!1,s))return}catch(t){Et.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 bt{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}bt.custom={};class Mt extends M{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new P,this.pixelList=new P}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:St,copy:kt,setRadius:Bt}=x,{hitRadiusPoint:At,hitPoint:Ht}=f,It={},Ft={},Nt=S.prototype;Nt.hit=function(t,e=0){this.updateLayout(),kt(Ft,t),Bt(Ft,e);const i=this.__world;return!!(e?At(i,Ft):Ht(i,Ft))&&(this.isBranch?R.getSelector(this).hitPoint(Object.assign({},Ft),e,{target:this}):this.__hitWorld(Ft))},Nt.__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&&(kt(It,t),Bt(t=It,e.hitRadius)),St(t,i,It),e.hitBox||a){if(f.hitRadiusPoint(s.boxBounds,It))return!0;if(a)return!1}return!s.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),s.boundsChanged||(s.hitCanvasChanged=!1)),this.__hit(It)},Nt.__hitFill=function(t){const e=this.__hitCanvas;return e&&e.hitFill(t,this.__.windingRule)},Nt.__hitStroke=function(t,e){const i=this.__hitCanvas;return i&&i.hitStroke(t,e)},Nt.__hitPixel=function(t){const e=this.__hitCanvas;return e&&e.hitPixel(t,this.__layout.renderBounds,e.hitScale)},Nt.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const Kt=new k,Wt=i.prototype;Wt.__updateHitCanvas=function(){this.__box&&this.__box.__updateHitCanvas();const{hitCanvasManager:t}=this.leafer||this.parent&&this.parent.leafer||{};if(!t)return;const e=this.__,i=(e.__isAlphaPixelFill||e.__isCanvas)&&"pixel"===e.hitFill,s=e.__isAlphaPixelStroke&&"pixel"===e.hitStroke,a=i||s;this.__hitCanvas||(this.__hitCanvas=a?t.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):t.getPathType(this));const n=this.__hitCanvas;if(a){const{renderBounds:t}=this.__layout,a=R.image.hitCanvasSize,r=n.hitScale=B.set(0,0,a,a).getFitMatrix(t).a,{x:h,y:o,width:d,height:g}=B.set(t).scale(r);n.resize({width:d,height:g,pixelRatio:1}),n.clear(),A.patternLocked=!0,this.__renderShape(n,{matrix:Kt.setWith(this.__world).scaleWith(1/r).invertWith().translate(-h,-o),ignoreFill:!i,ignoreStroke:!s}),A.patternLocked=!1,n.resetTransform(),e.__isHitPixel=!0}else e.__isHitPixel&&(e.__isHitPixel=!1);this.__drawHitPath(n),n.setStrokeOptions(e)},Wt.__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 Vt=i.prototype,Ut=s.prototype,jt=a.prototype;Ut.__updateHitCanvas=jt.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?Vt.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},Ut.__hitFill=jt.__hitFill=function(t){return this.__hitCanvas?Vt.__hitFill.call(this,t):f.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 Xt=H.prototype;Xt.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},Xt.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},Xt.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,bt as Cursor,tt as DragBoundsHelper,nt as DragEvent,yt as Dragger,ht as DropEvent,Mt as HitCanvasManager,Ct as InteractionBase,ut as InteractionHelper,ct as KeyEvent,K as Keyboard,ot as MoveEvent,rt as MyDragEvent,st as MyPointerEvent,W as PointerButton,it as PointerEvent,dt as RotateEvent,gt as SwipeEvent,V as UIEvent,lt as ZoomEvent};
|
|
2
2
|
//# sourceMappingURL=core.esm.min.js.map
|