@leafer-in/viewport 1.9.7 → 1.9.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"viewport.min.js","sources":["../../../../../../src/in/packages/viewport/src/type/viewport.ts","../../../../../../src/in/packages/viewport/src/LeaferTypeCreator.ts","../../../../../../src/in/packages/viewport/src/type/custom.ts","../../../../../../src/in/packages/viewport/src/type/design.ts","../../../../../../src/in/packages/viewport/src/type/document.ts","../../../../../../src/in/packages/viewport/src/interaction/MultiTouchHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/WheelEventHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/Transformer.ts","../../../../../../src/in/packages/viewport/src/Leafer.ts","../../../../../../src/in/packages/viewport/src/interaction/Interaction.ts","../../../../../../src/in/packages/viewport/src/interaction/Dragger.ts","../../../../../../src/in/packages/viewport/src/index.ts"],"sourcesContent":["import { ILeaferBase, ILeaferConfig } from '@leafer-ui/interface'\n\nimport { MoveEvent, ZoomEvent, DataHelper, LeafHelper } from '@leafer-ui/core'\n\n\nexport function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, custom?: boolean): void {\n addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig)\n if (leafer.isApp || custom) return\n\n leafer.__eventIds.push(\n leafer.on_(MoveEvent.BEFORE_MOVE, (e: MoveEvent) => {\n leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY, false))\n }),\n leafer.on_(MoveEvent.END, (e: MoveEvent) => {\n LeafHelper.animateMove(leafer.zoomLayer, leafer.getValidMove(e.moveX, e.moveY))\n }),\n leafer.on_(ZoomEvent.BEFORE_ZOOM, (e: ZoomEvent) => {\n const { zoomLayer } = leafer\n const changeScale = leafer.getValidScale(e.scale)\n if (changeScale !== 1) zoomLayer.scaleOfWorld(e, changeScale)\n })\n )\n}\n\nexport function addViewportConfig(leafer: ILeaferBase, mergeConfig?: ILeaferConfig): void {\n const viewportConfig: ILeaferConfig = {\n wheel: { preventDefault: true },\n touch: { preventDefault: true },\n pointer: { preventDefaultMenu: true }\n }\n if (mergeConfig) DataHelper.assign(viewportConfig, mergeConfig)\n DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig)\n}","import { ILeaferBase, ILeaferTypeList, ILeaferTypeFunction } from '@leafer-ui/interface'\n\nimport { Debug } from '@leafer-ui/core'\n\nimport { addViewport } from './type/viewport'\nimport { custom } from './type/custom'\nimport { design } from './type/design'\nimport { document } from './type/document'\n\n\nconst debug = Debug.get('LeaferTypeCreator')\n\nexport const LeaferTypeCreator = {\n\n list: {} as ILeaferTypeList,\n\n register(name: string, fn: ILeaferTypeFunction): void {\n list[name] && debug.repeat(name)\n list[name] = fn\n },\n\n run(name: string, leafer: ILeaferBase): void {\n const fn = list[name]\n fn && fn(leafer)\n }\n\n}\n\nconst { list, register } = LeaferTypeCreator\n\nregister('viewport', addViewport)\nregister('custom', custom)\nregister('design', design)\nregister('document', document)","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function custom(leafer: ILeaferBase): void {\n addViewport(leafer, null, true)\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function design(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: {\n min: 0.01,\n max: 256\n },\n move: {\n holdSpaceKey: true,\n holdMiddleKey: true,\n }\n })\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function document(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: { min: 1 },\n move: { scroll: 'limit' }\n })\n}\n","import { IMultiTouchData, IKeepTouchData } from '@leafer-ui/interface'\n\nimport { PointHelper } from '@leafer-ui/core'\n\n\nexport const MultiTouchHelper = {\n\n getData(list: IKeepTouchData[]): IMultiTouchData {\n const a = list[0], b = list[1]\n const lastCenter = PointHelper.getCenter(a.from, b.from)\n const center = PointHelper.getCenter(a.to, b.to)\n const move = { x: center.x - lastCenter.x, y: center.y - lastCenter.y }\n\n const lastDistance = PointHelper.getDistance(a.from, b.from)\n const distance = PointHelper.getDistance(a.to, b.to)\n const scale = distance / lastDistance\n\n const rotation = PointHelper.getRotation(a.from, b.from, a.to, b.to)\n\n return { move, scale, rotation, center }\n }\n\n}","import { IPointData, IWheelEvent, IWheelConfig } from '@leafer-ui/interface'\n\nimport { MathHelper, Platform } from '@leafer-ui/core'\n\n\nconst { abs, max } = Math, { sign, within } = MathHelper\n\nexport const WheelEventHelper = {\n\n getMove(event: IWheelEvent, config: IWheelConfig): IPointData {\n let { moveSpeed } = config\n let { deltaX, deltaY } = event\n if (event.shiftKey && !deltaX) { // Window\n deltaX = deltaY\n deltaY = 0\n }\n const absX = abs(deltaX), absY = abs(deltaY)\n if (absX > 50) deltaX = max(50, absX / 3) * sign(deltaX)\n if (absY > 50) deltaY = max(50, absY / 3) * sign(deltaY)\n return { x: -deltaX * moveSpeed * 2, y: -deltaY * moveSpeed * 2 }\n },\n\n getScale(event: IWheelEvent, config: IWheelConfig): number {\n\n let zoom: boolean\n let scale = 1\n let { zoomMode, zoomSpeed } = config\n\n const delta = event.deltaY || event.deltaX\n\n if (zoomMode) {\n // mac 触摸板滚动手势的deltaY是整数, 鼠标滚动/触摸板缩放的deltaY有小数点, firfox鼠标滚动为整数,为18或19的倍数\n // windows 始终是整数\n zoom = (zoomMode === 'mouse') ? true : (!event.deltaX && (Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta))\n if (event.shiftKey || event.metaKey || event.ctrlKey) zoom = true\n } else {\n zoom = !event.shiftKey && (event.metaKey || event.ctrlKey)\n }\n\n if (zoom) {\n zoomSpeed = within(zoomSpeed, 0, 1)\n const min = event.deltaY ? config.delta.y : config.delta.x\n const absScale = within(1 - abs(delta) / (min * 4) * zoomSpeed, 0.5, 2)\n scale = delta > 0 ? absScale : 1 / absScale // 让 scale 放大、缩小可以定位在有规律的刻度上\n }\n\n return scale\n }\n\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer } from '@leafer-ui/interface'\n\nimport { InteractionBase, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core'\n\n\nexport class Transformer {\n\n public get transforming(): boolean { return !!(this.moveData || this.zoomData || this.rotateData) }\n\n protected interaction: InteractionBase\n protected moveData: IMoveEvent\n protected zoomData: IZoomEvent\n protected rotateData: IRotateEvent\n protected transformTimer: ITimer\n\n constructor(interaction: InteractionBase) {\n this.interaction = interaction\n }\n\n public move(data: IMoveEvent): void {\n const { interaction } = this\n if (!data.moveType) data.moveType = 'move'\n\n if (!this.moveData) {\n this.setPath(data)\n this.moveData = { ...data, moveX: 0, moveY: 0 }\n interaction.emit(MoveEvent.START, this.moveData)\n }\n\n data.path = this.moveData.path\n interaction.emit(MoveEvent.BEFORE_MOVE, data)\n interaction.emit(MoveEvent.MOVE, data)\n\n this.transformEndWait()\n }\n\n public zoom(data: IZoomEvent): void {\n const { interaction } = this\n\n if (!this.zoomData) {\n this.setPath(data)\n this.zoomData = { ...data, scale: 1 }\n interaction.emit(ZoomEvent.START, this.zoomData)\n }\n\n data.path = this.zoomData.path\n interaction.emit(ZoomEvent.BEFORE_ZOOM, data)\n interaction.emit(ZoomEvent.ZOOM, data)\n\n this.transformEndWait()\n }\n\n public rotate(data: IRotateEvent): void {\n const { interaction } = this\n\n if (!this.rotateData) {\n this.setPath(data)\n this.rotateData = { ...data, rotation: 0 }\n interaction.emit(RotateEvent.START, this.rotateData)\n }\n\n data.path = this.rotateData.path\n interaction.emit(RotateEvent.BEFORE_ROTATE, data)\n interaction.emit(RotateEvent.ROTATE, data)\n\n this.transformEndWait()\n }\n\n public setPath(data: any): void {\n const { interaction } = this\n const { path } = interaction.selector.getByPoint(data, interaction.hitRadius)\n data.path = path\n interaction.cancelHover()\n }\n\n protected transformEndWait(): void {\n clearTimeout(this.transformTimer)\n this.transformTimer = setTimeout(() => {\n this.transformEnd()\n }, this.interaction.p.transformTime)\n }\n\n public transformEnd(): void {\n const { interaction, moveData, zoomData, rotateData } = this\n if (moveData) interaction.emit(MoveEvent.END, moveData)\n if (zoomData) interaction.emit(ZoomEvent.END, zoomData)\n if (rotateData) interaction.emit(RotateEvent.END, rotateData)\n this.reset()\n }\n\n public reset(): void {\n this.zoomData = this.moveData = this.rotateData = null\n }\n\n public destroy(): void {\n this.reset()\n }\n}","import { ILeaferType, IPointData } from '@leafer-ui/interface'\n\nimport { Leafer, Bounds, Point, DragBoundsHelper } from '@leafer-ui/core'\n\nimport { LeaferTypeCreator } from './LeaferTypeCreator'\n\n\nconst leafer = Leafer.prototype\nconst bounds = new Bounds(), move = new Point()\n\nleafer.initType = function (type: ILeaferType) {\n LeaferTypeCreator.run(type, this)\n}\n\nleafer.getValidMove = function (moveX: number, moveY: number, checkLimit = true): IPointData {\n const { scroll, disabled } = this.app.config.move\n move.set(moveX, moveY)\n\n if (scroll) {\n const type = scroll === true ? '' : scroll\n\n if (type.includes('x')) move.y = 0\n else if (type.includes('y')) move.x = 0\n else Math.abs(move.x) > Math.abs(move.y) ? move.y = 0 : move.x = 0\n\n if (checkLimit && type.includes('limit')) {\n bounds.set(this.__world).addPoint(this.zoomLayer as IPointData)\n DragBoundsHelper.getValidMove(bounds, this.canvas.bounds, 'inner', move, true)\n if (type.includes('x')) move.y = 0\n else if (type.includes('y')) move.x = 0\n }\n }\n\n return { x: disabled ? 0 : move.x, y: disabled ? 0 : move.y }\n}\n\nleafer.getValidScale = function (changeScale: number): number {\n const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale)\n if (min && absScale < min) changeScale = min / scaleX\n else if (max && absScale > max) changeScale = max / scaleX\n return disabled ? 1 : changeScale // fix 不能过滤小数位\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, IWheelEvent, IKeepTouchData, IPointData, IEvent, IPointerEvent } from '@leafer-ui/interface'\n\nimport { InteractionBase, PointHelper } from '@leafer-ui/core'\n\nimport { WheelEventHelper } from './WheelEventHelper'\nimport { Transformer } from './Transformer'\nimport { MultiTouchHelper } from './MultiTouchHelper'\n\n\nfunction getMoveEventData(move: IPointData, event: IEvent): IMoveEvent {\n return { ...event, moveX: move.x, moveY: move.y } as IMoveEvent\n}\n\nfunction getRotateEventData(rotation: number, event: IEvent): IRotateEvent {\n return { ...event, rotation } as IRotateEvent\n}\n\nfunction getZoomEventData(scale: number, event: IEvent): IZoomEvent {\n return { ...event, scale, } as IZoomEvent\n}\n\n\nconst interaction = InteractionBase.prototype\n\ninteraction.createTransformer = function (): void {\n this.transformer = new Transformer(this)\n}\n\ninteraction.move = function (data: IMoveEvent): void {\n this.transformer.move(data)\n}\n\ninteraction.zoom = function (data: IZoomEvent): void {\n this.transformer.zoom(data)\n}\n\ninteraction.rotate = function (data: IRotateEvent): void {\n this.transformer.rotate(data)\n}\n\ninteraction.transformEnd = function (): void {\n this.transformer.transformEnd()\n}\n\n\ninteraction.wheel = function (data: IWheelEvent): void {\n const { wheel, pointer } = this.config, { posDeltaSpeed, negDeltaSpeed } = wheel\n if (wheel.disabled) return\n\n if (data.deltaX > 0) posDeltaSpeed && (data.deltaX *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaX *= negDeltaSpeed)\n\n if (data.deltaY > 0) posDeltaSpeed && (data.deltaY *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaY *= negDeltaSpeed)\n\n const scale = wheel.getScale ? wheel.getScale(data, wheel) : WheelEventHelper.getScale(data, wheel)\n if (scale !== 1) this.zoom(getZoomEventData(scale, data))\n else {\n const move = wheel.getMove ? wheel.getMove(data, wheel) : WheelEventHelper.getMove(data, wheel)\n if (pointer.snap) PointHelper.round(move)\n this.move(getMoveEventData(move, data))\n }\n}\n\n\ninteraction.multiTouch = function (data: IPointerEvent, list: IKeepTouchData[]): void {\n if (this.config.multiTouch.disabled) return\n const { move, rotation, scale, center } = MultiTouchHelper.getData(list)\n\n Object.assign(data, center)\n data.multiTouch = true\n\n this.pointerWaitCancel()\n\n this.rotate(getRotateEventData(rotation, data))\n this.zoom(getZoomEventData(scale, data))\n this.move(getMoveEventData(move, data))\n}","import { IPointerEvent, IFunction } from '@leafer-ui/interface'\n\nimport { Dragger, BoundsHelper, PointHelper, isNumber } from '@leafer-ui/core'\n\n\nconst dragger = Dragger.prototype\nconst { abs } = Math\n\ndragger.checkDragEndAnimate = function (data: IPointerEvent, speed?: number): boolean | number {\n const { moveX, moveY } = this.dragData\n const absMoveX = abs(moveX), absMoveY = abs(moveY), minMove = speed ? 1 : 0.1\n const dragAnimate = this.canAnimate && this.moving && (absMoveX > minMove || absMoveY > minMove) && this.interaction.m.dragAnimate\n\n if (dragAnimate) {\n const inertia = data.pointerType === 'touch' ? 3 : 1, maxMove = 70\n speed = speed ? (isNumber(dragAnimate) ? dragAnimate : 0.95) : inertia\n if (absMoveX * speed > maxMove) speed = maxMove / absMoveX\n else if (absMoveY * speed > maxMove) speed = maxMove / absMoveY\n\n data = { ...data }\n PointHelper.move(data, moveX * speed, moveY * speed)\n\n this.drag(data)\n this.animate(() => { this.dragEnd(data, 1) })\n }\n\n return dragAnimate\n}\n\ndragger.animate = function (func?: IFunction, off?: 'off'): void { // dragEnd animation\n const animateWait = func || this.animateWait\n if (animateWait) this.interaction.target.nextRender(animateWait, null, off)\n this.animateWait = func\n}\n\ndragger.checkDragOut = function (data: IPointerEvent): void {\n const { interaction } = this\n this.autoMoveCancel()\n if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data)) this.autoMoveOnDragOut(data)\n}\n\ndragger.autoMoveOnDragOut = function (data: IPointerEvent): void {\n const { interaction, downData, canDragOut } = this\n const { autoDistance, dragOut } = interaction.m\n if (!dragOut || !canDragOut || !autoDistance) return\n\n const bounds = interaction.shrinkCanvasBounds\n const { x, y } = bounds\n const right = BoundsHelper.maxX(bounds)\n const bottom = BoundsHelper.maxY(bounds)\n\n const moveX = data.x < x ? autoDistance : (right < data.x ? -autoDistance : 0)\n const moveY = data.y < y ? autoDistance : (bottom < data.y ? -autoDistance : 0)\n let totalX = 0, totalY = 0\n\n this.autoMoveTimer = setInterval(() => {\n totalX += moveX\n totalY += moveY\n\n PointHelper.move(downData, moveX, moveY)\n PointHelper.move(this.dragData, moveX, moveY)\n\n interaction.move({ ...data, moveX, moveY, totalX, totalY, moveType: 'drag' })\n interaction.pointerMoveReal(data)\n }, 10)\n}\n\ndragger.autoMoveCancel = function (): void {\n if (this.autoMoveTimer) {\n clearInterval(this.autoMoveTimer)\n this.autoMoveTimer = 0\n }\n}","export { LeaferTypeCreator } from './LeaferTypeCreator'\nexport { addViewport, addViewportConfig } from './type/viewport'\nexport { MultiTouchHelper } from './interaction/MultiTouchHelper'\nexport { WheelEventHelper } from './interaction/WheelEventHelper'\nexport { Transformer } from './interaction/Transformer'\n\nimport { Plugin } from '@leafer-ui/core'\n\nimport './Leafer'\nimport './interaction/Interaction'\nimport './interaction/Dragger'\n\nPlugin.add('viewport')"],"names":["addViewport","leafer","mergeConfig","custom","addViewportConfig","parentApp","isApp","__eventIds","push","on_","MoveEvent","BEFORE_MOVE","e","zoomLayer","move","getValidMove","moveX","moveY","END","LeafHelper","animateMove","ZoomEvent","BEFORE_ZOOM","changeScale","getValidScale","scale","scaleOfWorld","viewportConfig","wheel","preventDefault","touch","pointer","preventDefaultMenu","DataHelper","assign","config","userConfig","debug","Debug","get","LeaferTypeCreator","list","register","name","fn","repeat","run","zoom","min","max","holdSpaceKey","holdMiddleKey","scroll","MultiTouchHelper","getData","a","b","lastCenter","PointHelper","getCenter","from","center","to","x","y","lastDistance","getDistance","rotation","getRotation","abs","Math","sign","within","MathHelper","WheelEventHelper","getMove","event","moveSpeed","deltaX","deltaY","shiftKey","absX","absY","getScale","zoomMode","zoomSpeed","delta","Platform","intWheelDeltaY","ceil","metaKey","ctrlKey","absScale","Transformer","transforming","this","moveData","zoomData","rotateData","constructor","interaction","data","moveType","setPath","Object","emit","START","path","MOVE","transformEndWait","ZOOM","rotate","RotateEvent","BEFORE_ROTATE","ROTATE","selector","getByPoint","hitRadius","cancelHover","clearTimeout","transformTimer","setTimeout","transformEnd","p","transformTime","reset","destroy","Leafer","prototype","bounds","Bounds","Point","getMoveEventData","getZoomEventData","initType","type","checkLimit","disabled","app","set","includes","__world","addPoint","DragBoundsHelper","canvas","scaleX","__","InteractionBase","createTransformer","transformer","posDeltaSpeed","negDeltaSpeed","snap","round","multiTouch","pointerWaitCancel","getRotateEventData","dragger","Dragger","checkDragEndAnimate","speed","dragData","absMoveX","absMoveY","minMove","dragAnimate","canAnimate","moving","m","inertia","pointerType","maxMove","isNumber","drag","animate","dragEnd","func","off","animateWait","target","nextRender","checkDragOut","autoMoveCancel","dragging","shrinkCanvasBounds","hitPoint","autoMoveOnDragOut","downData","canDragOut","autoDistance","dragOut","right","BoundsHelper","maxX","bottom","maxY","totalX","totalY","autoMoveTimer","setInterval","pointerMoveReal","clearInterval","Plugin","add"],"mappings":"2FAKgBA,EAAYC,EAAqBC,EAA6BC,GAC1EC,EAAkBH,EAAOI,UAAYJ,EAAOI,UAAYJ,EAAQC,GAC5DD,EAAOK,OAASH,GAEpBF,EAAOM,WAAWC,KACdP,EAAOQ,IAAIC,YAAUC,YAAcC,IAC/BX,EAAOY,UAAUC,KAAKb,EAAOc,aAAaH,EAAEI,MAAOJ,EAAEK,OAAO,MAEhEhB,EAAOQ,IAAIC,EAAAA,UAAUQ,IAAMN,IACvBO,EAAAA,WAAWC,YAAYnB,EAAOY,UAAWZ,EAAOc,aAAaH,EAAEI,MAAOJ,EAAEK,UAE5EhB,EAAOQ,IAAIY,EAAAA,UAAUC,YAAcV,IAC/B,MAAMC,UAAEA,GAAcZ,EAChBsB,EAActB,EAAOuB,cAAcZ,EAAEa,OACvB,IAAhBF,GAAmBV,EAAUa,aAAad,EAAGW,KAG7D,CAEM,SAAUnB,EAAkBH,EAAqBC,GACnD,MAAMyB,EAAgC,CAClCC,MAAO,CAAEC,gBAAgB,GACzBC,MA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MD,YAAEA,EAAWuF,SAAEA,EAAQC,WAAEA,GAAe7F,MACxC8F,aAAEA,EAAYC,QAAEA,GAAY1F,EAAYoE,EAC9C,IAAKsB,IAAYF,IAAeC,EAAc,OAE9C,MAAM5D,EAAS7B,EAAYoF,oBACrBzH,EAAEA,EAACC,EAAEA,GAAMiE,EACX8D,EAAQC,EAAAA,aAAaC,KAAKhE,GAC1BiE,EAASF,EAAAA,aAAaG,KAAKlE,GAE3BjH,EAAQqF,EAAKtC,EAAIA,EAAI8H,EAAgBE,EAAQ1F,EAAKtC,GAAK8H,EAAe,EACtE5K,EAAQoF,EAAKrC,EAAIA,EAAI6H,EAAgBK,EAAS7F,EAAKrC,GAAK6H,EAAe,EAC7E,IAAIO,EAAS,EAAGC,EAAS,EAEzBtG,KAAKuG,cAAgBC,YAAY,KAC7BH,GAAUpL,EACVqL,GAAUpL,EAEVyC,EAAAA,YAAY5C,KAAK6K,EAAU3K,EAAOC,GAClCyC,EAAAA,YAAY5C,KAAKiF,KAAKkE,SAAUjJ,EAAOC,GAEvCmF,EAAYtF,KAAI0F,OAAAtE,OAAAsE,OAAAtE,OAAA,GAAMmE,GAAI,CAAErF,QAAOC,QAAOmL,SAAQC,SAAQ/F,SAAU,UACpEF,EAAYoG,gBAAgBnG,IAC7B,GACP,EAEAwD,EAAQyB,eAAiB,WACjBvF,KAAKuG,gBACLG,cAAc1G,KAAKuG,eACnBvG,KAAKuG,cAAgB,EAE7B,EC5DAI,EAAAA,OAAOC,IAAI"}
1
+ {"version":3,"file":"viewport.min.js","sources":["../../../../../../src/in/packages/viewport/src/type/viewport.ts","../../../../../../src/in/packages/viewport/src/LeaferTypeCreator.ts","../../../../../../src/in/packages/viewport/src/type/custom.ts","../../../../../../src/in/packages/viewport/src/type/design.ts","../../../../../../src/in/packages/viewport/src/type/document.ts","../../../../../../src/in/packages/viewport/src/interaction/MultiTouchHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/WheelEventHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/Transformer.ts","../../../../../../src/in/packages/viewport/src/Leafer.ts","../../../../../../src/in/packages/viewport/src/interaction/Interaction.ts","../../../../../../src/in/packages/viewport/src/interaction/Dragger.ts","../../../../../../src/in/packages/viewport/src/index.ts"],"sourcesContent":["import { ILeaferBase, ILeaferConfig } from '@leafer-ui/interface'\n\nimport { MoveEvent, ZoomEvent, DataHelper, LeafHelper } from '@leafer-ui/core'\n\n\nexport function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, custom?: boolean): void {\n addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig)\n if (leafer.isApp || custom) return\n\n leafer.__eventIds.push(\n leafer.on_(MoveEvent.BEFORE_MOVE, (e: MoveEvent) => {\n leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY, false))\n }),\n leafer.on_(MoveEvent.END, (e: MoveEvent) => {\n LeafHelper.animateMove(leafer.zoomLayer, leafer.getValidMove(e.moveX, e.moveY))\n }),\n leafer.on_(ZoomEvent.BEFORE_ZOOM, (e: ZoomEvent) => {\n const { zoomLayer } = leafer\n const changeScale = leafer.getValidScale(e.scale)\n if (changeScale !== 1) zoomLayer.scaleOfWorld(e, changeScale)\n })\n )\n}\n\nexport function addViewportConfig(leafer: ILeaferBase, mergeConfig?: ILeaferConfig): void {\n const viewportConfig: ILeaferConfig = {\n wheel: { preventDefault: true },\n touch: { preventDefault: true },\n pointer: { preventDefaultMenu: true }\n }\n if (mergeConfig) DataHelper.assign(viewportConfig, mergeConfig)\n DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig)\n}","import { ILeaferBase, ILeaferTypeList, ILeaferTypeFunction } from '@leafer-ui/interface'\n\nimport { Debug } from '@leafer-ui/core'\n\nimport { addViewport } from './type/viewport'\nimport { custom } from './type/custom'\nimport { design } from './type/design'\nimport { document } from './type/document'\n\n\nconst debug = Debug.get('LeaferTypeCreator')\n\nexport const LeaferTypeCreator = {\n\n list: {} as ILeaferTypeList,\n\n register(name: string, fn: ILeaferTypeFunction): void {\n list[name] && debug.repeat(name)\n list[name] = fn\n },\n\n run(name: string, leafer: ILeaferBase): void {\n const fn = list[name]\n fn && fn(leafer)\n }\n\n}\n\nconst { list, register } = LeaferTypeCreator\n\nregister('viewport', addViewport)\nregister('custom', custom)\nregister('design', design)\nregister('document', document)","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function custom(leafer: ILeaferBase): void {\n addViewport(leafer, null, true)\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function design(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: {\n min: 0.01,\n max: 256\n },\n move: {\n holdSpaceKey: true,\n holdMiddleKey: true,\n }\n })\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function document(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: { min: 1 },\n move: { scroll: 'limit' }\n })\n}\n","import { IMultiTouchData, IKeepTouchData, IGestureType, IPointData, ISingleGestureConfig } from '@leafer-ui/interface'\n\nimport { PointHelper } from '@leafer-ui/core'\n\n\nexport const MultiTouchHelper = {\n\n state: { // 单一手势识别状态\n type: 'none' as IGestureType,\n typeCount: 0,\n startTime: 0,\n totalData: null as IMultiTouchData,\n center: {} as IPointData\n },\n\n getData(list: IKeepTouchData[]): IMultiTouchData {\n const a = list[0], b = list[1]\n const lastCenter = PointHelper.getCenter(a.from, b.from)\n const center = PointHelper.getCenter(a.to, b.to)\n const move = { x: center.x - lastCenter.x, y: center.y - lastCenter.y }\n\n const lastDistance = PointHelper.getDistance(a.from, b.from)\n const distance = PointHelper.getDistance(a.to, b.to)\n const scale = distance / lastDistance\n\n const rotation = PointHelper.getRotation(a.from, b.from, a.to, b.to)\n return { move, scale, rotation, center }\n },\n\n getType(data: IMultiTouchData, config: ISingleGestureConfig): IGestureType {\n const moveScore = Math.hypot(data.move.x, data.move.y) / (config.move || 5)\n const scaleScore = Math.abs(data.scale - 1) / (config.scale || 0.03)\n const rotateScore = Math.abs(data.rotation) / (config.rotation || 2)\n\n if (moveScore < 1 && scaleScore < 1 && rotateScore < 1) return 'none'\n if (moveScore >= scaleScore && moveScore >= rotateScore) return 'move'\n if (scaleScore >= rotateScore) return 'zoom'\n return 'rotate'\n },\n\n // 识别单一手势\n detect(data: IMultiTouchData, config: ISingleGestureConfig): IGestureType {\n const { state } = M\n const type = M.getType(data, config)\n\n if (!state.totalData) {\n state.startTime = Date.now()\n state.center = data.center\n }\n\n M.add(data, state.totalData)\n state.totalData = data\n\n if (type === state.type) { // 连续多帧一样的类型才进行锁定\n state.typeCount++\n if (state.typeCount >= (config.count || 3) && type !== 'none') return type\n } else {\n state.type = type\n state.typeCount = 1\n }\n\n if ((Date.now() - state.startTime) >= (config.time || 160)) return M.getType(state.totalData, config) // 限制最长识别时间\n\n return 'none'\n },\n\n add(data: IMultiTouchData, add: IMultiTouchData): void {\n if (!add) return\n PointHelper.move(data.move, add.move)\n data.scale *= add.scale\n data.rotation += add.rotation\n data.center = add.center\n },\n\n reset() {\n const { state } = M\n state.type = 'none'\n state.typeCount = 0\n state.startTime = 0\n state.totalData = null\n }\n\n}\n\nconst M = MultiTouchHelper","import { IPointData, IWheelEvent, IWheelConfig } from '@leafer-ui/interface'\n\nimport { MathHelper, Platform } from '@leafer-ui/core'\n\n\nconst { abs, max } = Math, { sign, within } = MathHelper\n\nexport const WheelEventHelper = {\n\n getMove(event: IWheelEvent, config: IWheelConfig): IPointData {\n let { moveSpeed } = config\n let { deltaX, deltaY } = event\n if (event.shiftKey && !deltaX) { // Window\n deltaX = deltaY\n deltaY = 0\n }\n const absX = abs(deltaX), absY = abs(deltaY)\n if (absX > 50) deltaX = max(50, absX / 3) * sign(deltaX)\n if (absY > 50) deltaY = max(50, absY / 3) * sign(deltaY)\n return { x: -deltaX * moveSpeed * 2, y: -deltaY * moveSpeed * 2 }\n },\n\n getScale(event: IWheelEvent, config: IWheelConfig): number {\n\n let zoom: boolean\n let scale = 1\n let { zoomMode, zoomSpeed } = config\n\n const delta = event.deltaY || event.deltaX\n\n if (zoomMode) {\n // mac 触摸板滚动手势的deltaY是整数, 鼠标滚动/触摸板缩放的deltaY有小数点, firfox鼠标滚动为整数,为18或19的倍数\n // windows 始终是整数\n zoom = (zoomMode === 'mouse') ? true : (!event.deltaX && (Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta))\n if (event.shiftKey || event.metaKey || event.ctrlKey) zoom = true\n } else {\n zoom = !event.shiftKey && (event.metaKey || event.ctrlKey)\n }\n\n if (zoom) {\n zoomSpeed = within(zoomSpeed, 0, 1)\n const min = event.deltaY ? config.delta.y : config.delta.x\n const absScale = within(1 - abs(delta) / (min * 4) * zoomSpeed, 0.5, 2)\n scale = delta > 0 ? absScale : 1 / absScale // 让 scale 放大、缩小可以定位在有规律的刻度上\n }\n\n return scale\n }\n\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer } from '@leafer-ui/interface'\n\nimport { InteractionBase, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core'\n\n\nlet totalX: number, totalY: number, totalScale: number, totalRotation: number\n\nexport class Transformer {\n\n public get transforming(): boolean { return this.moving || this.zooming || this.rotating }\n public get moving(): boolean { return !!this.moveData }\n public get zooming(): boolean { return !!this.zoomData }\n public get rotating(): boolean { return !!this.rotateData }\n\n public moveData: IMoveEvent\n public zoomData: IZoomEvent\n public rotateData: IRotateEvent\n\n protected interaction: InteractionBase\n protected transformTimer: ITimer\n\n constructor(interaction: InteractionBase) {\n this.interaction = interaction\n }\n\n public move(data: IMoveEvent): void {\n const { interaction } = this\n if (!data.moveType) data.moveType = 'move'\n\n if (!this.moveData) {\n this.setPath(data)\n totalX = 0, totalY = 0\n this.moveData = { ...data, moveX: 0, moveY: 0, totalX, totalY }\n interaction.emit(MoveEvent.START, this.moveData)\n }\n\n data.path = this.moveData.path\n data.totalX = totalX = totalX + data.moveX\n data.totalY = totalY = totalY + data.moveY\n interaction.emit(MoveEvent.BEFORE_MOVE, data)\n interaction.emit(MoveEvent.MOVE, data)\n\n this.transformEndWait()\n }\n\n public zoom(data: IZoomEvent): void {\n const { interaction } = this\n\n if (!this.zoomData) {\n this.setPath(data)\n totalScale = 1\n this.zoomData = { ...data, scale: 1, totalScale }\n interaction.emit(ZoomEvent.START, this.zoomData)\n }\n\n data.path = this.zoomData.path\n data.totalScale = totalScale = totalScale * data.scale\n interaction.emit(ZoomEvent.BEFORE_ZOOM, data)\n interaction.emit(ZoomEvent.ZOOM, data)\n\n this.transformEndWait()\n }\n\n public rotate(data: IRotateEvent): void {\n const { interaction } = this\n\n if (!this.rotateData) {\n this.setPath(data)\n totalRotation = 0\n this.rotateData = { ...data, rotation: 0, totalRotation }\n interaction.emit(RotateEvent.START, this.rotateData)\n }\n\n data.path = this.rotateData.path\n data.totalRotation = totalRotation = totalRotation + data.rotation\n interaction.emit(RotateEvent.BEFORE_ROTATE, data)\n interaction.emit(RotateEvent.ROTATE, data)\n\n this.transformEndWait()\n }\n\n public setPath(data: any): void {\n const { interaction } = this\n const { path } = interaction.selector.getByPoint(data, interaction.hitRadius)\n data.path = path\n interaction.cancelHover()\n }\n\n protected transformEndWait(): void {\n clearTimeout(this.transformTimer)\n this.transformTimer = setTimeout(() => {\n this.transformEnd()\n }, this.interaction.p.transformTime)\n }\n\n public transformEnd(): void {\n const { interaction, moveData, zoomData, rotateData } = this\n if (moveData) interaction.emit(MoveEvent.END, { ...moveData, totalX, totalY } as IMoveEvent)\n if (zoomData) interaction.emit(ZoomEvent.END, { ...zoomData, totalScale } as IZoomEvent)\n if (rotateData) interaction.emit(RotateEvent.END, { ...rotateData, totalRotation } as IRotateEvent)\n this.reset()\n }\n\n public reset(): void {\n this.zoomData = this.moveData = this.rotateData = null\n }\n\n public destroy(): void {\n this.reset()\n }\n}","import { ILeaferType, IPointData } from '@leafer-ui/interface'\n\nimport { Leafer, Bounds, Point, DragBoundsHelper } from '@leafer-ui/core'\n\nimport { LeaferTypeCreator } from './LeaferTypeCreator'\n\n\nconst leafer = Leafer.prototype\nconst bounds = new Bounds(), move = new Point()\n\nleafer.initType = function (type: ILeaferType) {\n LeaferTypeCreator.run(type, this)\n}\n\nleafer.getValidMove = function (moveX: number, moveY: number, checkLimit = true): IPointData {\n const { scroll, disabled } = this.app.config.move\n move.set(moveX, moveY)\n\n if (scroll) {\n const type = scroll === true ? '' : scroll\n\n if (type.includes('x')) move.y = 0\n else if (type.includes('y')) move.x = 0\n else Math.abs(move.x) > Math.abs(move.y) ? move.y = 0 : move.x = 0\n\n if (checkLimit && type.includes('limit')) {\n bounds.set(this.__world).addPoint(this.zoomLayer as IPointData)\n DragBoundsHelper.getValidMove(bounds, this.canvas.bounds, 'inner', move, true)\n if (type.includes('x')) move.y = 0\n else if (type.includes('y')) move.x = 0\n }\n }\n\n return { x: disabled ? 0 : move.x, y: disabled ? 0 : move.y }\n}\n\nleafer.getValidScale = function (changeScale: number): number {\n const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale)\n if (min && absScale < min) changeScale = min / scaleX\n else if (max && absScale > max) changeScale = max / scaleX\n return disabled ? 1 : changeScale // fix 不能过滤小数位\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, IWheelEvent, IKeepTouchData, IPointData, IEvent, IPointerEvent, ISingleGestureConfig } from '@leafer-ui/interface'\n\nimport { InteractionBase, PointHelper, isObject } from '@leafer-ui/core'\n\nimport { WheelEventHelper } from './WheelEventHelper'\nimport { Transformer } from './Transformer'\nimport { MultiTouchHelper } from './MultiTouchHelper'\n\n\nfunction getMoveEventData(move: IPointData, event: IEvent): IMoveEvent {\n return { ...event, moveX: move.x, moveY: move.y } as IMoveEvent\n}\n\nfunction getRotateEventData(rotation: number, event: IEvent): IRotateEvent {\n return { ...event, rotation } as IRotateEvent\n}\n\nfunction getZoomEventData(scale: number, event: IEvent): IZoomEvent {\n return { ...event, scale, } as IZoomEvent\n}\n\n\nconst interaction = InteractionBase.prototype\n\ninteraction.createTransformer = function (): void {\n this.transformer = new Transformer(this)\n}\n\ninteraction.move = function (data: IMoveEvent): void {\n this.transformer.move(data)\n}\n\ninteraction.zoom = function (data: IZoomEvent): void {\n this.transformer.zoom(data)\n}\n\ninteraction.rotate = function (data: IRotateEvent): void {\n this.transformer.rotate(data)\n}\n\ninteraction.transformEnd = function (): void {\n this.transformer.transformEnd()\n}\n\n\ninteraction.wheel = function (data: IWheelEvent): void {\n const { wheel, pointer } = this.config, { posDeltaSpeed, negDeltaSpeed } = wheel\n if (wheel.disabled) return\n\n if (data.deltaX > 0) posDeltaSpeed && (data.deltaX *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaX *= negDeltaSpeed)\n\n if (data.deltaY > 0) posDeltaSpeed && (data.deltaY *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaY *= negDeltaSpeed)\n\n const scale = wheel.getScale ? wheel.getScale(data, wheel) : WheelEventHelper.getScale(data, wheel)\n if (scale !== 1) this.zoom(getZoomEventData(scale, data))\n else {\n const move = wheel.getMove ? wheel.getMove(data, wheel) : WheelEventHelper.getMove(data, wheel)\n if (pointer.snap) PointHelper.round(move)\n this.move(getMoveEventData(move, data))\n }\n}\n\n\ninteraction.multiTouch = function (data: IPointerEvent, list: IKeepTouchData[]): void {\n const { disabled, singleGesture } = this.config.multiTouch\n if (disabled) return\n this.pointerWaitCancel()\n\n let gestureData = MultiTouchHelper.getData(list)\n let { moving, zooming, rotating } = this.transformer\n\n if (singleGesture) {\n\n if (!this.transformer.transforming) {\n\n const type = MultiTouchHelper.detect(gestureData, isObject(singleGesture) ? singleGesture : {} as ISingleGestureConfig)\n\n switch (type) {\n case 'move': moving = true; break\n case 'zoom': zooming = true; break\n case 'rotate': rotating = true; break\n default: return\n }\n\n MultiTouchHelper.reset()\n\n }\n\n if (!moving) gestureData.center = MultiTouchHelper.state.center\n\n } else moving = zooming = rotating = true\n\n Object.assign(data, gestureData.center)\n data.multiTouch = true\n\n if (rotating) this.rotate(getRotateEventData(gestureData.rotation, data))\n if (zooming) this.zoom(getZoomEventData(gestureData.scale, data))\n if (moving) this.move(getMoveEventData(gestureData.move, data))\n}","import { IPointerEvent, IFunction } from '@leafer-ui/interface'\n\nimport { Dragger, BoundsHelper, PointHelper, isNumber } from '@leafer-ui/core'\n\n\nconst dragger = Dragger.prototype\nconst { abs } = Math\n\ndragger.checkDragEndAnimate = function (data: IPointerEvent, speed?: number): boolean | number {\n const { moveX, moveY } = this.dragData\n const absMoveX = abs(moveX), absMoveY = abs(moveY), minMove = speed ? 1 : 0.1\n const dragAnimate = this.canAnimate && this.moving && (absMoveX > minMove || absMoveY > minMove) && this.interaction.m.dragAnimate\n\n if (dragAnimate) {\n const inertia = data.pointerType === 'touch' ? 3 : 1, maxMove = 70\n speed = speed ? (isNumber(dragAnimate) ? dragAnimate : 0.95) : inertia\n if (absMoveX * speed > maxMove) speed = maxMove / absMoveX\n else if (absMoveY * speed > maxMove) speed = maxMove / absMoveY\n\n data = { ...data }\n PointHelper.move(data, moveX * speed, moveY * speed)\n\n this.drag(data)\n this.animate(() => { this.dragEnd(data, 1) })\n }\n\n return dragAnimate\n}\n\ndragger.animate = function (func?: IFunction, off?: 'off'): void { // dragEnd animation\n const animateWait = func || this.animateWait\n if (animateWait) this.interaction.target.nextRender(animateWait, null, off)\n this.animateWait = func\n}\n\ndragger.checkDragOut = function (data: IPointerEvent): void {\n const { interaction } = this\n this.autoMoveCancel()\n if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data)) this.autoMoveOnDragOut(data)\n}\n\ndragger.autoMoveOnDragOut = function (data: IPointerEvent): void {\n const { interaction, downData, canDragOut } = this\n const { autoDistance, dragOut } = interaction.m\n if (!dragOut || !canDragOut || !autoDistance) return\n\n const bounds = interaction.shrinkCanvasBounds\n const { x, y } = bounds\n const right = BoundsHelper.maxX(bounds)\n const bottom = BoundsHelper.maxY(bounds)\n\n const moveX = data.x < x ? autoDistance : (right < data.x ? -autoDistance : 0)\n const moveY = data.y < y ? autoDistance : (bottom < data.y ? -autoDistance : 0)\n let totalX = 0, totalY = 0\n\n this.autoMoveTimer = setInterval(() => {\n totalX += moveX\n totalY += moveY\n\n PointHelper.move(downData, moveX, moveY)\n PointHelper.move(this.dragData, moveX, moveY)\n\n interaction.move({ ...data, moveX, moveY, totalX, totalY, moveType: 'drag' })\n interaction.pointerMoveReal(data)\n }, 10)\n}\n\ndragger.autoMoveCancel = function (): void {\n if (this.autoMoveTimer) {\n clearInterval(this.autoMoveTimer)\n this.autoMoveTimer = 0\n }\n}","export { LeaferTypeCreator } from './LeaferTypeCreator'\nexport { addViewport, addViewportConfig } from './type/viewport'\nexport { MultiTouchHelper } from './interaction/MultiTouchHelper'\nexport { WheelEventHelper } from './interaction/WheelEventHelper'\nexport { Transformer } from './interaction/Transformer'\n\nimport { Plugin } from '@leafer-ui/core'\n\nimport './Leafer'\nimport './interaction/Interaction'\nimport './interaction/Dragger'\n\nPlugin.add('viewport')"],"names":["addViewport","leafer","mergeConfig","custom","addViewportConfig","parentApp","isApp","__eventIds","push","on_","MoveEvent","BEFORE_MOVE","e","zoomLayer","move","getValidMove","moveX","moveY","END","LeafHelper","animateMove","ZoomEvent","BEFORE_ZOOM","changeScale","getValidScale","scale","scaleOfWorld","viewportConfig","wheel","preventDefault","touch","pointer","preventDefaultMenu","DataHelper","assign","config","userConfig","debug","Debug","get","LeaferTypeCreator","list","register","name","fn","repeat","run","zoom","min","max","holdSpaceKey","holdMiddleKey","scroll","MultiTouchHelper","state","type","typeCount","startTime","totalData","center","getData","a","b","lastCenter","PointHelper","getCenter","from","to","x","y","lastDistance","getDistance","rotation","getRotation","getType","data","moveScore","Math","hypot","scaleScore","abs","rotateScore","detect","M","Date","now","add","count","time","reset","sign","within","MathHelper","WheelEventHelper","getMove","event","moveSpeed","deltaX","deltaY","shiftKey","absX","absY","getScale","zoomMode","zoomSpeed","delta","Platform","intWheelDeltaY","ceil","metaKey","ctrlKey","absScale","totalX","totalY","totalScale","totalRotation","Transformer","transforming","this","moving","zooming","rotating","moveData","zoomData","rotateData","constructor","interaction","moveType","setPath","Object","emit","START","path","MOVE","transformEndWait","ZOOM","rotate","RotateEvent","BEFORE_ROTATE","ROTATE","selector","getByPoint","hitRadius","cancelHover","clearTimeout","transformTimer","setTimeout","transformEnd","p","transformTime","destroy","Leafer","prototype","bounds","Bounds","Point","getMoveEventData","getZoomEventData","initType","checkLimit","disabled","app","set","includes","__world","addPoint","DragBoundsHelper","canvas","scaleX","__","InteractionBase","createTransformer","transformer","posDeltaSpeed","negDeltaSpeed","snap","round","multiTouch","singleGesture","pointerWaitCancel","gestureData","isObject","dragger","Dragger","checkDragEndAnimate","speed","dragData","absMoveX","absMoveY","minMove","dragAnimate","canAnimate","m","inertia","pointerType","maxMove","isNumber","drag","animate","dragEnd","func","off","animateWait","target","nextRender","checkDragOut","autoMoveCancel","dragging","shrinkCanvasBounds","hitPoint","autoMoveOnDragOut","downData","canDragOut","autoDistance","dragOut","right","BoundsHelper","maxX","bottom","maxY","autoMoveTimer","setInterval","pointerMoveReal","clearInterval","Plugin"],"mappings":"2FAKgBA,EAAYC,EAAqBC,EAA6BC,GAC1EC,EAAkBH,EAAOI,UAAYJ,EAAOI,UAAYJ,EAAQC,GAC5DD,EAAOK,OAASH,GAEpBF,EAAOM,WAAWC,KACdP,EAAOQ,IAAIC,YAAUC,YAAcC,IAC/BX,EAAOY,UAAUC,KAAKb,EAAOc,aAAaH,EAAEI,MAAOJ,EAAEK,OAAO,MAEhEhB,EAAOQ,IAAIC,EAAAA,UAAUQ,IAAMN,IACvBO,EAAAA,WAAWC,YAAYnB,EAAOY,UAAWZ,EAAOc,aAAaH,EAAEI,MAAOJ,EAAEK,UAE5EhB,EAAOQ,IAAIY,EAAAA,UAAUC,YAAcV,IAC/B,MAAMC,UAAEA,GAAcZ,EAChBsB,EAActB,EAAOuB,cAAcZ,EAAEa,OACvB,IAAhBF,GAAm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WAAajF,EAAYkF,mBAAmBC,SAAStI,IAAO2C,KAAK4F,kBAAkBvI,EAChG,EAEA2G,EAAQ4B,kBAAoB,SAAUvI,GAClC,MAAMmD,YAAEA,EAAWqF,SAAEA,EAAQC,WAAEA,GAAe9F,MACxC+F,aAAEA,EAAYC,QAAEA,GAAYxF,EAAYkE,EAC9C,IAAKsB,IAAYF,IAAeC,EAAc,OAE9C,MAAM5D,EAAS3B,EAAYkF,oBACrB5I,EAAEA,EAACC,EAAEA,GAAMoF,EACX8D,EAAQC,EAAAA,aAAaC,KAAKhE,GAC1BiE,EAASF,EAAAA,aAAaG,KAAKlE,GAE3BzI,EAAQ2D,EAAKP,EAAIA,EAAIiJ,EAAgBE,EAAQ5I,EAAKP,GAAKiJ,EAAe,EACtEpM,EAAQ0D,EAAKN,EAAIA,EAAIgJ,EAAgBK,EAAS/I,EAAKN,GAAKgJ,EAAe,EAC7E,IAAIrG,EAAS,EAAGC,EAAS,EAEzBK,KAAKsG,cAAgBC,YAAY,KAC7B7G,GAAUhG,EACViG,GAAUhG,EAEV+C,EAAAA,YAAYlD,KAAKqM,EAAUnM,EAAOC,GAClC+C,EAAAA,YAAYlD,KAAKwG,KAAKoE,SAAU1K,EAAOC,GAEvC6G,EAAYhH,KAAImH,OAAA/F,OAAA+F,OAAA/F,OAAA,GAAMyC,GAAI,CAAE3D,QAAOC,QAAO+F,SAAQC,SAAQc,SAAU,UACpED,EAAYgG,gBAAgBnJ,IAC7B,GACP,EAEA2G,EAAQwB,eAAiB,WACjBxF,KAAKsG,gBACLG,cAAczG,KAAKsG,eACnBtG,KAAKsG,cAAgB,EAE7B,EC5DAI,EAAAA,OAAO1I,IAAI"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/viewport",
3
- "version": "1.9.7",
3
+ "version": "1.9.8",
4
4
  "description": "@leafer-in/viewport",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,8 +34,8 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@leafer-ui/core": "^1.9.7",
38
- "@leafer-ui/interface": "^1.9.7",
39
- "@leafer-in/interface": "^1.9.7"
37
+ "@leafer-ui/core": "^1.9.8",
38
+ "@leafer-ui/interface": "^1.9.8",
39
+ "@leafer-in/interface": "^1.9.8"
40
40
  }
41
41
  }
@@ -1,6 +1,6 @@
1
- import { IMoveEvent, IZoomEvent, IRotateEvent, IWheelEvent, IKeepTouchData, IPointData, IEvent, IPointerEvent } from '@leafer-ui/interface'
1
+ import { IMoveEvent, IZoomEvent, IRotateEvent, IWheelEvent, IKeepTouchData, IPointData, IEvent, IPointerEvent, ISingleGestureConfig } from '@leafer-ui/interface'
2
2
 
3
- import { InteractionBase, PointHelper } from '@leafer-ui/core'
3
+ import { InteractionBase, PointHelper, isObject } from '@leafer-ui/core'
4
4
 
5
5
  import { WheelEventHelper } from './WheelEventHelper'
6
6
  import { Transformer } from './Transformer'
@@ -64,15 +64,38 @@ interaction.wheel = function (data: IWheelEvent): void {
64
64
 
65
65
 
66
66
  interaction.multiTouch = function (data: IPointerEvent, list: IKeepTouchData[]): void {
67
- if (this.config.multiTouch.disabled) return
68
- const { move, rotation, scale, center } = MultiTouchHelper.getData(list)
67
+ const { disabled, singleGesture } = this.config.multiTouch
68
+ if (disabled) return
69
+ this.pointerWaitCancel()
69
70
 
70
- Object.assign(data, center)
71
- data.multiTouch = true
71
+ let gestureData = MultiTouchHelper.getData(list)
72
+ let { moving, zooming, rotating } = this.transformer
72
73
 
73
- this.pointerWaitCancel()
74
+ if (singleGesture) {
75
+
76
+ if (!this.transformer.transforming) {
77
+
78
+ const type = MultiTouchHelper.detect(gestureData, isObject(singleGesture) ? singleGesture : {} as ISingleGestureConfig)
79
+
80
+ switch (type) {
81
+ case 'move': moving = true; break
82
+ case 'zoom': zooming = true; break
83
+ case 'rotate': rotating = true; break
84
+ default: return
85
+ }
86
+
87
+ MultiTouchHelper.reset()
88
+
89
+ }
90
+
91
+ if (!moving) gestureData.center = MultiTouchHelper.state.center
92
+
93
+ } else moving = zooming = rotating = true
94
+
95
+ Object.assign(data, gestureData.center)
96
+ data.multiTouch = true
74
97
 
75
- this.rotate(getRotateEventData(rotation, data))
76
- this.zoom(getZoomEventData(scale, data))
77
- this.move(getMoveEventData(move, data))
98
+ if (rotating) this.rotate(getRotateEventData(gestureData.rotation, data))
99
+ if (zooming) this.zoom(getZoomEventData(gestureData.scale, data))
100
+ if (moving) this.move(getMoveEventData(gestureData.move, data))
78
101
  }
@@ -1,10 +1,18 @@
1
- import { IMultiTouchData, IKeepTouchData } from '@leafer-ui/interface'
1
+ import { IMultiTouchData, IKeepTouchData, IGestureType, IPointData, ISingleGestureConfig } from '@leafer-ui/interface'
2
2
 
3
3
  import { PointHelper } from '@leafer-ui/core'
4
4
 
5
5
 
6
6
  export const MultiTouchHelper = {
7
7
 
8
+ state: { // 单一手势识别状态
9
+ type: 'none' as IGestureType,
10
+ typeCount: 0,
11
+ startTime: 0,
12
+ totalData: null as IMultiTouchData,
13
+ center: {} as IPointData
14
+ },
15
+
8
16
  getData(list: IKeepTouchData[]): IMultiTouchData {
9
17
  const a = list[0], b = list[1]
10
18
  const lastCenter = PointHelper.getCenter(a.from, b.from)
@@ -16,8 +24,62 @@ export const MultiTouchHelper = {
16
24
  const scale = distance / lastDistance
17
25
 
18
26
  const rotation = PointHelper.getRotation(a.from, b.from, a.to, b.to)
19
-
20
27
  return { move, scale, rotation, center }
28
+ },
29
+
30
+ getType(data: IMultiTouchData, config: ISingleGestureConfig): IGestureType {
31
+ const moveScore = Math.hypot(data.move.x, data.move.y) / (config.move || 5)
32
+ const scaleScore = Math.abs(data.scale - 1) / (config.scale || 0.03)
33
+ const rotateScore = Math.abs(data.rotation) / (config.rotation || 2)
34
+
35
+ if (moveScore < 1 && scaleScore < 1 && rotateScore < 1) return 'none'
36
+ if (moveScore >= scaleScore && moveScore >= rotateScore) return 'move'
37
+ if (scaleScore >= rotateScore) return 'zoom'
38
+ return 'rotate'
39
+ },
40
+
41
+ // 识别单一手势
42
+ detect(data: IMultiTouchData, config: ISingleGestureConfig): IGestureType {
43
+ const { state } = M
44
+ const type = M.getType(data, config)
45
+
46
+ if (!state.totalData) {
47
+ state.startTime = Date.now()
48
+ state.center = data.center
49
+ }
50
+
51
+ M.add(data, state.totalData)
52
+ state.totalData = data
53
+
54
+ if (type === state.type) { // 连续多帧一样的类型才进行锁定
55
+ state.typeCount++
56
+ if (state.typeCount >= (config.count || 3) && type !== 'none') return type
57
+ } else {
58
+ state.type = type
59
+ state.typeCount = 1
60
+ }
61
+
62
+ if ((Date.now() - state.startTime) >= (config.time || 160)) return M.getType(state.totalData, config) // 限制最长识别时间
63
+
64
+ return 'none'
65
+ },
66
+
67
+ add(data: IMultiTouchData, add: IMultiTouchData): void {
68
+ if (!add) return
69
+ PointHelper.move(data.move, add.move)
70
+ data.scale *= add.scale
71
+ data.rotation += add.rotation
72
+ data.center = add.center
73
+ },
74
+
75
+ reset() {
76
+ const { state } = M
77
+ state.type = 'none'
78
+ state.typeCount = 0
79
+ state.startTime = 0
80
+ state.totalData = null
21
81
  }
22
82
 
23
- }
83
+ }
84
+
85
+ const M = MultiTouchHelper
@@ -3,14 +3,20 @@ import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer } from '@leafer-ui/interfa
3
3
  import { InteractionBase, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core'
4
4
 
5
5
 
6
+ let totalX: number, totalY: number, totalScale: number, totalRotation: number
7
+
6
8
  export class Transformer {
7
9
 
8
- public get transforming(): boolean { return !!(this.moveData || this.zoomData || this.rotateData) }
10
+ public get transforming(): boolean { return this.moving || this.zooming || this.rotating }
11
+ public get moving(): boolean { return !!this.moveData }
12
+ public get zooming(): boolean { return !!this.zoomData }
13
+ public get rotating(): boolean { return !!this.rotateData }
14
+
15
+ public moveData: IMoveEvent
16
+ public zoomData: IZoomEvent
17
+ public rotateData: IRotateEvent
9
18
 
10
19
  protected interaction: InteractionBase
11
- protected moveData: IMoveEvent
12
- protected zoomData: IZoomEvent
13
- protected rotateData: IRotateEvent
14
20
  protected transformTimer: ITimer
15
21
 
16
22
  constructor(interaction: InteractionBase) {
@@ -23,11 +29,14 @@ export class Transformer {
23
29
 
24
30
  if (!this.moveData) {
25
31
  this.setPath(data)
26
- this.moveData = { ...data, moveX: 0, moveY: 0 }
32
+ totalX = 0, totalY = 0
33
+ this.moveData = { ...data, moveX: 0, moveY: 0, totalX, totalY }
27
34
  interaction.emit(MoveEvent.START, this.moveData)
28
35
  }
29
36
 
30
37
  data.path = this.moveData.path
38
+ data.totalX = totalX = totalX + data.moveX
39
+ data.totalY = totalY = totalY + data.moveY
31
40
  interaction.emit(MoveEvent.BEFORE_MOVE, data)
32
41
  interaction.emit(MoveEvent.MOVE, data)
33
42
 
@@ -39,11 +48,13 @@ export class Transformer {
39
48
 
40
49
  if (!this.zoomData) {
41
50
  this.setPath(data)
42
- this.zoomData = { ...data, scale: 1 }
51
+ totalScale = 1
52
+ this.zoomData = { ...data, scale: 1, totalScale }
43
53
  interaction.emit(ZoomEvent.START, this.zoomData)
44
54
  }
45
55
 
46
56
  data.path = this.zoomData.path
57
+ data.totalScale = totalScale = totalScale * data.scale
47
58
  interaction.emit(ZoomEvent.BEFORE_ZOOM, data)
48
59
  interaction.emit(ZoomEvent.ZOOM, data)
49
60
 
@@ -55,11 +66,13 @@ export class Transformer {
55
66
 
56
67
  if (!this.rotateData) {
57
68
  this.setPath(data)
58
- this.rotateData = { ...data, rotation: 0 }
69
+ totalRotation = 0
70
+ this.rotateData = { ...data, rotation: 0, totalRotation }
59
71
  interaction.emit(RotateEvent.START, this.rotateData)
60
72
  }
61
73
 
62
74
  data.path = this.rotateData.path
75
+ data.totalRotation = totalRotation = totalRotation + data.rotation
63
76
  interaction.emit(RotateEvent.BEFORE_ROTATE, data)
64
77
  interaction.emit(RotateEvent.ROTATE, data)
65
78
 
@@ -82,9 +95,9 @@ export class Transformer {
82
95
 
83
96
  public transformEnd(): void {
84
97
  const { interaction, moveData, zoomData, rotateData } = this
85
- if (moveData) interaction.emit(MoveEvent.END, moveData)
86
- if (zoomData) interaction.emit(ZoomEvent.END, zoomData)
87
- if (rotateData) interaction.emit(RotateEvent.END, rotateData)
98
+ if (moveData) interaction.emit(MoveEvent.END, { ...moveData, totalX, totalY } as IMoveEvent)
99
+ if (zoomData) interaction.emit(ZoomEvent.END, { ...zoomData, totalScale } as IZoomEvent)
100
+ if (rotateData) interaction.emit(RotateEvent.END, { ...rotateData, totalRotation } as IRotateEvent)
88
101
  this.reset()
89
102
  }
90
103
 
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaferTypeList, ILeaferTypeFunction, ILeaferBase, ILeaferConfig, IKeepTouchData, IMultiTouchData, IWheelEvent, IWheelConfig, IPointData, IMoveEvent, IZoomEvent, IRotateEvent, ITimer } from '@leafer-ui/interface';
1
+ import { ILeaferTypeList, ILeaferTypeFunction, ILeaferBase, ILeaferConfig, IGestureType, IMultiTouchData, IPointData, IKeepTouchData, ISingleGestureConfig, IWheelEvent, IWheelConfig, IMoveEvent, IZoomEvent, IRotateEvent, ITimer } from '@leafer-ui/interface';
2
2
  import { InteractionBase } from '@leafer-ui/core';
3
3
 
4
4
  declare const LeaferTypeCreator: {
@@ -11,7 +11,18 @@ declare function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, c
11
11
  declare function addViewportConfig(leafer: ILeaferBase, mergeConfig?: ILeaferConfig): void;
12
12
 
13
13
  declare const MultiTouchHelper: {
14
+ state: {
15
+ type: IGestureType;
16
+ typeCount: number;
17
+ startTime: number;
18
+ totalData: IMultiTouchData;
19
+ center: IPointData;
20
+ };
14
21
  getData(list: IKeepTouchData[]): IMultiTouchData;
22
+ getType(data: IMultiTouchData, config: ISingleGestureConfig): IGestureType;
23
+ detect(data: IMultiTouchData, config: ISingleGestureConfig): IGestureType;
24
+ add(data: IMultiTouchData, add: IMultiTouchData): void;
25
+ reset(): void;
15
26
  };
16
27
 
17
28
  declare const WheelEventHelper: {
@@ -21,10 +32,13 @@ declare const WheelEventHelper: {
21
32
 
22
33
  declare class Transformer {
23
34
  get transforming(): boolean;
35
+ get moving(): boolean;
36
+ get zooming(): boolean;
37
+ get rotating(): boolean;
38
+ moveData: IMoveEvent;
39
+ zoomData: IZoomEvent;
40
+ rotateData: IRotateEvent;
24
41
  protected interaction: InteractionBase;
25
- protected moveData: IMoveEvent;
26
- protected zoomData: IZoomEvent;
27
- protected rotateData: IRotateEvent;
28
42
  protected transformTimer: ITimer;
29
43
  constructor(interaction: InteractionBase);
30
44
  move(data: IMoveEvent): void;