@leafer-in/motion-path 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"motion-path.esm.min.js","sources":["../../../../../../src/in/packages/motion-path/src/HighBezierHelper.ts","../../../../../../src/in/packages/motion-path/src/HighCurveHelper.ts","../../../../../../src/in/packages/motion-path/src/decorator.ts","../../../../../../src/in/packages/motion-path/src/index.ts"],"sourcesContent":["import { IPathCommandData } from '@leafer-ui/interface'\nimport { BezierHelper, OneRadian, PathCommandMap } from '@leafer-ui/draw'\n\n\n// 高斯-勒让德积分节点和权重\nconst gaussNodes = [0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.9739065285]\nconst gaussWeights = [0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443]\n\nconst { sqrt } = Math\nconst { getDerivative } = BezierHelper\n\nexport const HighBezierHelper = {\n\n getDistance(fromX: number, fromY: number, x1: number, y1: number, x2: number, y2: number, toX: number, toY: number, t = 1): number {\n let distance = 0, t1: number, t2: number, d1X: number, d1Y: number, d2X: number, d2Y: number, half = t / 2\n for (let i = 0; i < gaussNodes.length; i++) {\n t1 = half * (1 + gaussNodes[i])\n t2 = half * (1 - gaussNodes[i])\n\n d1X = getDerivative(t1, fromX, x1, x2, toX)\n d1Y = getDerivative(t1, fromY, y1, y2, toY)\n\n d2X = getDerivative(t2, fromX, x1, x2, toX)\n d2Y = getDerivative(t2, fromY, y1, y2, toY)\n\n distance += gaussWeights[i] * (sqrt(d1X * d1X + d1Y * d1Y) + sqrt(d2X * d2X + d2Y * d2Y))\n }\n return distance * half\n },\n\n getRotation(t: number, fromX: number, fromY: number, x1: number, y1: number, x2: number, y2: number, toX: number, toY: number): number { // 切线角度\n const dx = getDerivative(t, fromX, x1, x2, toX)\n const dy = getDerivative(t, fromY, y1, y2, toY)\n return Math.atan2(dy, dx) / OneRadian\n },\n\n getT(distance: number, totalDistance: number, fromX: number, fromY: number, x1: number, y1: number, x2: number, y2: number, toX: number, toY: number, precision = 1): number { // 弧长反解 t\n let low = 0, high = 1, middle = distance / totalDistance, realPrecision = precision / totalDistance / 3\n\n if (middle >= 1) return 1\n if (middle <= 0) return 0\n\n while (high - low > realPrecision) { // 2分法快速对比\n getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, middle) < distance ? low = middle : high = middle\n middle = (low + high) / 2\n }\n\n return middle\n },\n\n cut(data: IPathCommandData, t: number, fromX: number, fromY: number, x1: number, y1: number, x2: number, y2: number, toX: number, toY: number) {\n const o = 1 - t\n const ax = o * fromX + t * x1, ay = o * fromY + t * y1\n const mbx = o * x1 + t * x2, mby = o * y1 + t * y2\n const mcx = o * x2 + t * toX, mcy = o * y2 + t * toY\n\n const bx = o * ax + t * mbx, by = o * ay + t * mby\n const mbcx = o * mbx + t * mcx, mbcy = o * mby + t * mcy\n\n const cx = o * bx + t * mbcx, cy = o * by + t * mbcy\n data.push(PathCommandMap.C, ax, ay, bx, by, cx, cy)\n }\n\n}\n\nconst { getDistance } = HighBezierHelper","import { IMatrixData, IPathCommandData, IMotionPathData, IRotationPointData, IPointData, IUnitData } from '@leafer-ui/interface'\nimport { BezierHelper, MatrixHelper, PathCommandMap, PointHelper, UnitConvert } from '@leafer-ui/draw'\n\nimport { HighBezierHelper } from './HighBezierHelper'\n\n\nconst { M, L, C, Z } = PathCommandMap\nconst tempPoint = {} as IPointData, tempFrom = {} as IPointData\n\nexport const HighCurveHelper = {\n\n transform(data: IPathCommandData, matrix: IMatrixData): void {\n let i: number = 0, command: number\n\n const len = data.length\n while (i < len) {\n command = data[i]\n switch (command) {\n case M: //moveto(x, y)\n case L: //lineto(x, y)\n HighCurveHelper.transformPoints(data, matrix, i, 1)\n i += 3\n break\n case C: //bezierCurveTo(x1, y1, x2, y2, x,y)\n HighCurveHelper.transformPoints(data, matrix, i, 3)\n i += 7\n break\n case Z: //closepath()\n i += 1\n }\n }\n },\n\n transformPoints(data: IPathCommandData, matrix: IMatrixData, start: number, pointCount: number): void {\n for (let i = start + 1, end = i + pointCount * 2; i < end; i += 2) {\n tempPoint.x = data[i]\n tempPoint.y = data[i + 1]\n MatrixHelper.toOuterPoint(matrix, tempPoint)\n data[i] = tempPoint.x\n data[i + 1] = tempPoint.y\n }\n },\n\n getMotionPathData(data: IPathCommandData): IMotionPathData {\n let total = 0, distance: number, segments: number[] = []\n let i = 0, x = 0, y = 0, toX: number, toY: number, command: number\n\n const len = data.length\n while (i < len) {\n command = data[i]\n switch (command) {\n case M: //moveto(x, y)\n case L: //lineto(x, y)\n toX = data[i + 1]\n toY = data[i + 2]\n distance = (command === L && i > 0) ? PointHelper.getDistanceFrom(x, y, toX, toY) : 0\n x = toX\n y = toY\n i += 3\n break\n case C: //bezierCurveTo(x1, y1, x2, y2, x,y)\n toX = data[i + 5]\n toY = data[i + 6]\n distance = HighBezierHelper.getDistance(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY)\n x = toX\n y = toY\n i += 7\n break\n case Z: //closepath()\n i += 1\n default:\n distance = 0\n\n }\n\n segments.push(distance)\n total += distance\n }\n\n return { total, segments, data }\n\n },\n\n\n getDistancePoint(distanceData: IMotionPathData, motionDistance: number | IUnitData, motionPrecision?: number): IRotationPointData {\n const { segments, data } = distanceData\n motionDistance = UnitConvert.number(motionDistance, distanceData.total)\n\n let total = 0, distance: number, to = {} as IRotationPointData\n let i = 0, index = 0, x: number = 0, y: number = 0, toX: number, toY: number, command: number\n let x1: number, y1: number, x2: number, y2: number, t: number\n\n const len = data.length\n while (i < len) {\n command = data[i]\n switch (command) {\n case M: //moveto(x, y)\n case L: //lineto(x, y)\n toX = data[i + 1]\n toY = data[i + 2]\n distance = segments[index]\n\n if (total + distance >= motionDistance || !distanceData.total) {\n if (!i) x = toX, y = toY // first M\n tempFrom.x = x\n tempFrom.y = y\n to.x = toX\n to.y = toY\n PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true)\n to.rotation = PointHelper.getAngle(tempFrom, to)\n return to\n }\n\n x = toX\n y = toY\n i += 3\n break\n case C: //bezierCurveTo(x1, y1, x2, y2, x,y)\n toX = data[i + 5]\n toY = data[i + 6]\n distance = segments[index]\n\n if (total + distance >= motionDistance) {\n x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4]\n t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision)\n BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to)\n to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY)\n return to\n }\n\n x = toX\n y = toY\n i += 7\n break\n case Z: //closepath()\n i += 1\n default:\n distance = 0\n }\n\n index++\n total += distance\n }\n\n return to\n },\n\n getDistancePath(distanceData: IMotionPathData, motionDistance: number | IUnitData, motionPrecision?: number): IPathCommandData {\n const { segments, data } = distanceData, path: IPathCommandData = []\n motionDistance = UnitConvert.number(motionDistance, distanceData.total)\n\n let total = 0, distance: number, to = {} as IRotationPointData\n let i = 0, index = 0, x: number = 0, y: number = 0, toX: number, toY: number, command: number\n let x1: number, y1: number, x2: number, y2: number, t: number\n\n const len = data.length\n while (i < len) {\n command = data[i]\n switch (command) {\n case M: //moveto(x, y)\n case L: //lineto(x, y)\n toX = data[i + 1]\n toY = data[i + 2]\n distance = segments[index]\n\n if (total + distance >= motionDistance || !distanceData.total) {\n if (!i) x = toX, y = toY // first M\n tempFrom.x = x\n tempFrom.y = y\n to.x = toX\n to.y = toY\n PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true)\n path.push(command, to.x, to.y)\n return path\n }\n\n x = toX\n y = toY\n i += 3\n path.push(command, x, y)\n break\n case C: //bezierCurveTo(x1, y1, x2, y2, x,y)\n x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4]\n toX = data[i + 5]\n toY = data[i + 6]\n distance = segments[index]\n\n if (total + distance >= motionDistance) {\n t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision)\n HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY)\n return path\n }\n\n x = toX\n y = toY\n i += 7\n path.push(command, x1, y1, x2, y2, toX, toY)\n break\n case Z: //closepath()\n i += 1\n path.push(command)\n default:\n distance = 0\n\n }\n\n index++\n total += distance\n }\n\n return path\n }\n\n}","import { IValue } from '@leafer-ui/interface'\nimport { decorateLeafAttr, attr, isNull } from '@leafer-ui/draw'\n\nexport function motionPathType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: any) {\n this.__setAttr(key, value)\n this.__hasMotionPath = this.motionPath || !isNull(this.motion)\n this.__layout.matrixChanged || this.__layout.matrixChange()\n }\n }))\n}","export { HighCurveHelper } from './HighCurveHelper'\nexport { HighBezierHelper } from './HighBezierHelper'\nexport { motionPathType } from './decorator'\n\nimport { IMotionPathData, IUI, IUnitData, IRotationPointData } from '@leafer-ui/interface'\nimport { isNull, MatrixHelper, LeafHelper, BranchHelper, Transition, UI, UnitConvert, Plugin } from '@leafer-ui/draw'\n\nimport { HighCurveHelper } from './HighCurveHelper'\nimport { motionPathType } from './decorator'\n\n\nPlugin.add('motion-path')\n\n\nTransition.register('motion', function (from: any, to: any, t: number, target: IUI): number {\n if (!from) from = 0\n else if (typeof from === 'object') from = UnitConvert.number(from, target.getMotionTotal())\n if (!to) to = 0\n else if (typeof to === 'object') to = UnitConvert.number(to, target.getMotionTotal())\n return Transition.number(from, to, t)\n})\n\nTransition.register('motionRotation', function (from: any, to: any, t: number): number {\n return Transition.number(from, to, t)\n})\n\n\nconst ui = UI.prototype\nconst { updateMatrix, updateAllMatrix } = LeafHelper\nconst { updateBounds } = BranchHelper\n\n\n// addAttr\nUI.addAttr('motionPath', undefined, motionPathType)\nUI.addAttr('motionPrecision', 1, motionPathType)\n\nUI.addAttr('motion', undefined, motionPathType)\nUI.addAttr('motionRotation', true, motionPathType)\n\n\nui.getMotionPathData = function (): IMotionPathData {\n return getMotionPathData(getMotionPath(this))\n}\n\nui.getMotionPoint = function (motionDistance: number | IUnitData): IRotationPointData {\n const path = getMotionPath(this)\n const data = getMotionPathData(path)\n if (!data.total) return {} as IRotationPointData\n\n const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision)\n MatrixHelper.toOuterPoint(path.localTransform, point)\n\n const { motionRotation } = this\n if (motionRotation === false) delete point.rotation\n else if (typeof motionRotation === 'number') point.rotation += motionRotation\n return point\n}\n\nui.getMotionTotal = function (): number {\n return this.getMotionPathData().total\n}\n\nui.__updateMotionPath = function (): void {\n const data = this.__\n if (this.__layout.resized && data.__pathForMotion) data.__pathForMotion = undefined\n\n if (this.motionPath) {\n let child: IUI\n const { children } = this.parent\n for (let i = 0; i < children.length; i++) {\n child = children[i]\n if (!isNull(child.motion) && !child.__layout.matrixChanged) {\n if (child !== this) child.__extraUpdate()\n updateMotion(child)\n }\n }\n } else updateMotion(this)\n}\n\n\nfunction updateMotion(leaf: IUI): void {\n const { motion, leaferIsCreated } = leaf\n if (isNull(motion)) return\n\n if (leaferIsCreated) leaf.leafer.created = false // 拦截布局更新通知,进行手动更新布局\n\n if (leaf.motionPath) {\n\n const data = getMotionPathData(leaf)\n if (data.total) leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision) // 生长路径\n\n } else {\n\n leaf.set(leaf.getMotionPoint(motion)) // 动画路径\n\n if (!leaf.__hasAutoLayout) { // 手动更新布局\n if (leaf.isBranch) updateAllMatrix(leaf), updateBounds(leaf, leaf)\n else updateMatrix(leaf)\n }\n\n }\n\n if (leaferIsCreated) leaf.leafer.created = true\n}\n\nfunction getMotionPath(leaf: IUI): IUI {\n const { parent } = leaf\n if (!leaf.motionPath && parent) {\n const { children } = parent\n for (let i = 0; i < children.length; i++) {\n if (children[i].motionPath) return children[i]\n }\n }\n return leaf\n}\n\nfunction getMotionPathData(leaf: IUI): IMotionPathData {\n const data = leaf.__\n if (data.__pathForMotion) return data.__pathForMotion\n return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true))\n}"],"names":["gaussNodes","gaussWeights","sqrt","Math","getDerivative","BezierHelper","HighBezierHelper","getDistance","fromX","fromY","x1","y1","x2","y2","toX","toY","t","t1","t2","d1X","d1Y","d2X","d2Y","distance","half","i","length","getRotation","dx","dy","atan2","OneRadian","getT","totalDistance","precision","low","high","middle","realPrecision","cut","data","o","ax","ay","mbx","mby","bx","by","cx","cy","push","PathCommandMap","C","M","L","Z","tempPoint","tempFrom","HighCurveHelper","transform","matrix","command","len","transformPoints","start","pointCount","end","x","y","MatrixHelper","toOuterPoint","getMotionPathData","total","segments","PointHelper","getDistanceFrom","getDistancePoint","distanceData","motionDistance","motionPrecision","UnitConvert","number","to","index","rotation","getAngle","getPointAndSet","getDistancePath","path","motionPathType","defaultValue","decorateLeafAttr","key","attr","set","value","this","__setAttr","__hasMotionPath","motionPath","isNull","motion","__layout","matrixChanged","matrixChange","Plugin","add","Transition","register","from","target","getMotionTotal","ui","UI","prototype","updateMatrix","updateAllMatrix","LeafHelper","updateBounds","BranchHelper","updateMotion","leaf","leaferIsCreated","leafer","created","__","__pathForRender","getMotionPoint","__hasAutoLayout","isBranch","getMotionPath","parent","children","__pathForMotion","getPath","addAttr","undefined","point","localTransform","motionRotation","__updateMotionPath","resized","child","__extraUpdate"],"mappings":"wPAKA,MAAMA,EAAa,CAAC,YAAc,YAAc,YAAc,YAAc,aACtEC,EAAe,CAAC,YAAc,YAAc,YAAc,YAAc,cAExEC,KAAEA,GAASC,MACXC,cAAEA,GAAkBC,EAEbC,EAAmB,CAE5B,WAAAC,CAAYC,EAAeC,EAAeC,EAAYC,EAAYC,EAAYC,EAAYC,EAAaC,EAAaC,EAAI,GACpH,IAAkBC,EAAYC,EAAYC,EAAaC,EAAaC,EAAaC,EAA7EC,EAAW,EAA+EC,EAAOR,EAAI,EACzG,IAAK,IAAIS,EAAI,EAA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nB2C,SAAiCF,EAAMrD,SACR,iBAAnBuD,IAA6BF,EAAMrD,UAAYuD,GACxDF,CACX,EAEAzB,EAAGD,eAAiB,WAChB,OAAOf,KAAKzB,oBAAoBC,KACpC,EAEAwC,EAAG4B,mBAAqB,WACpB,MAAMpG,EAAOwD,KAAK6B,GAGlB,GAFI7B,KAAKM,SAASuC,SAAWrG,EAAK6F,kBAAiB7F,EAAK6F,qBAAkBG,GAEtExC,KAAKG,WAAY,CACjB,IAAI2C,EACJ,MAAMV,SAAEA,GAAapC,KAAKmC,OAC1B,IAAK,IAAI1G,EAAI,EAAGA,EAAI2G,EAAS1G,OAAQD,IACjCqH,EAAQV,EAAS3G,GACZ2E,EAAO0C,EAAMzC,SAAYyC,EAAMxC,SAASC,gBACrCuC,IAAU9C,MAAM8C,EAAMC,gBAC1BvB,EAAasB,SAGlBtB,EAAaxB,KACxB"}
1
+ {"version":3,"file":"motion-path.esm.min.js","sources":["../../../../../../src/in/packages/motion-path/src/HighBezierHelper.ts","../../../../../../src/in/packages/motion-path/src/HighCurveHelper.ts","../../../../../../src/in/packages/motion-path/src/decorator.ts","../../../../../../src/in/packages/motion-path/src/index.ts"],"sourcesContent":["import { IPathCommandData } from '@leafer-ui/interface'\nimport { BezierHelper, OneRadian, PathCommandMap } from '@leafer-ui/draw'\n\n\n// 高斯-勒让德积分节点和权重\nconst gaussNodes = [0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.9739065285]\nconst gaussWeights = [0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443]\n\nconst { sqrt } = Math\nconst { getDerivative } = BezierHelper\n\nexport const HighBezierHelper = {\n\n getDistance(fromX: number, fromY: number, x1: number, y1: number, x2: number, y2: number, toX: number, toY: number, t = 1): number {\n let distance = 0, t1: number, t2: number, d1X: number, d1Y: number, d2X: number, d2Y: number, half = t / 2\n for (let i = 0; i < gaussNodes.length; i++) {\n t1 = half * (1 + gaussNodes[i])\n t2 = half * (1 - gaussNodes[i])\n\n d1X = getDerivative(t1, fromX, x1, x2, toX)\n d1Y = getDerivative(t1, fromY, y1, y2, toY)\n\n d2X = getDerivative(t2, fromX, x1, x2, toX)\n d2Y = getDerivative(t2, fromY, y1, y2, toY)\n\n distance += gaussWeights[i] * (sqrt(d1X * d1X + d1Y * d1Y) + sqrt(d2X * d2X + d2Y * d2Y))\n }\n return distance * half\n },\n\n getRotation(t: number, fromX: number, fromY: number, x1: number, y1: number, x2: number, y2: number, toX: number, toY: number): number { // 切线角度\n const dx = getDerivative(t, fromX, x1, x2, toX)\n const dy = getDerivative(t, fromY, y1, y2, toY)\n return Math.atan2(dy, dx) / OneRadian\n },\n\n getT(distance: number, totalDistance: number, fromX: number, fromY: number, x1: number, y1: number, x2: number, y2: number, toX: number, toY: number, precision = 1): number { // 弧长反解 t\n let low = 0, high = 1, middle = distance / totalDistance, realPrecision = precision / totalDistance / 3\n\n if (middle >= 1) return 1\n if (middle <= 0) return 0\n\n while (high - low > realPrecision) { // 2分法快速对比\n getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, middle) < distance ? low = middle : high = middle\n middle = (low + high) / 2\n }\n\n return middle\n },\n\n cut(data: IPathCommandData, t: number, fromX: number, fromY: number, x1: number, y1: number, x2: number, y2: number, toX: number, toY: number) {\n const o = 1 - t\n const ax = o * fromX + t * x1, ay = o * fromY + t * y1\n const mbx = o * x1 + t * x2, mby = o * y1 + t * y2\n const mcx = o * x2 + t * toX, mcy = o * y2 + t * toY\n\n const bx = o * ax + t * mbx, by = o * ay + t * mby\n const mbcx = o * mbx + t * mcx, mbcy = o * mby + t * mcy\n\n const cx = o * bx + t * mbcx, cy = o * by + t * mbcy\n data.push(PathCommandMap.C, ax, ay, bx, by, cx, cy)\n }\n\n}\n\nconst { getDistance } = HighBezierHelper","import { IMatrixData, IPathCommandData, IMotionPathData, IRotationPointData, IPointData, IUnitData } from '@leafer-ui/interface'\nimport { BezierHelper, MatrixHelper, PathCommandMap, PointHelper, UnitConvert } from '@leafer-ui/draw'\n\nimport { HighBezierHelper } from './HighBezierHelper'\n\n\nconst { M, L, C, Z } = PathCommandMap\nconst tempPoint = {} as IPointData, tempFrom = {} as IPointData\n\nexport const HighCurveHelper = {\n\n transform(data: IPathCommandData, matrix: IMatrixData): void {\n let i: number = 0, command: number\n\n const len = data.length\n while (i < len) {\n command = data[i]\n switch (command) {\n case M: //moveto(x, y)\n case L: //lineto(x, y)\n HighCurveHelper.transformPoints(data, matrix, i, 1)\n i += 3\n break\n case C: //bezierCurveTo(x1, y1, x2, y2, x,y)\n HighCurveHelper.transformPoints(data, matrix, i, 3)\n i += 7\n break\n case Z: //closepath()\n i += 1\n }\n }\n },\n\n transformPoints(data: IPathCommandData, matrix: IMatrixData, start: number, pointCount: number): void {\n for (let i = start + 1, end = i + pointCount * 2; i < end; i += 2) {\n tempPoint.x = data[i]\n tempPoint.y = data[i + 1]\n MatrixHelper.toOuterPoint(matrix, tempPoint)\n data[i] = tempPoint.x\n data[i + 1] = tempPoint.y\n }\n },\n\n getMotionPathData(data: IPathCommandData): IMotionPathData {\n let total = 0, distance: number, segments: number[] = []\n let i = 0, x = 0, y = 0, toX: number, toY: number, command: number\n\n const len = data.length\n while (i < len) {\n command = data[i]\n switch (command) {\n case M: //moveto(x, y)\n case L: //lineto(x, y)\n toX = data[i + 1]\n toY = data[i + 2]\n distance = (command === L && i > 0) ? PointHelper.getDistanceFrom(x, y, toX, toY) : 0\n x = toX\n y = toY\n i += 3\n break\n case C: //bezierCurveTo(x1, y1, x2, y2, x,y)\n toX = data[i + 5]\n toY = data[i + 6]\n distance = HighBezierHelper.getDistance(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY)\n x = toX\n y = toY\n i += 7\n break\n case Z: //closepath()\n i += 1\n default:\n distance = 0\n\n }\n\n segments.push(distance)\n total += distance\n }\n\n return { total, segments, data }\n\n },\n\n\n getDistancePoint(distanceData: IMotionPathData, motionDistance: number | IUnitData, motionPrecision?: number): IRotationPointData {\n const { segments, data } = distanceData\n motionDistance = UnitConvert.number(motionDistance, distanceData.total)\n\n let total = 0, distance: number, to = {} as IRotationPointData\n let i = 0, index = 0, x: number = 0, y: number = 0, toX: number, toY: number, command: number\n let x1: number, y1: number, x2: number, y2: number, t: number\n\n const len = data.length\n while (i < len) {\n command = data[i]\n switch (command) {\n case M: //moveto(x, y)\n case L: //lineto(x, y)\n toX = data[i + 1]\n toY = data[i + 2]\n distance = segments[index]\n\n if (total + distance >= motionDistance || !distanceData.total) {\n if (!i) x = toX, y = toY // first M\n tempFrom.x = x\n tempFrom.y = y\n to.x = toX\n to.y = toY\n PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true)\n to.rotation = PointHelper.getAngle(tempFrom, to)\n return to\n }\n\n x = toX\n y = toY\n i += 3\n break\n case C: //bezierCurveTo(x1, y1, x2, y2, x,y)\n toX = data[i + 5]\n toY = data[i + 6]\n distance = segments[index]\n\n if (total + distance >= motionDistance) {\n x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4]\n t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision)\n BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to)\n to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY)\n return to\n }\n\n x = toX\n y = toY\n i += 7\n break\n case Z: //closepath()\n i += 1\n default:\n distance = 0\n }\n\n index++\n total += distance\n }\n\n return to\n },\n\n getDistancePath(distanceData: IMotionPathData, motionDistance: number | IUnitData, motionPrecision?: number): IPathCommandData {\n const { segments, data } = distanceData, path: IPathCommandData = []\n motionDistance = UnitConvert.number(motionDistance, distanceData.total)\n\n let total = 0, distance: number, to = {} as IRotationPointData\n let i = 0, index = 0, x: number = 0, y: number = 0, toX: number, toY: number, command: number\n let x1: number, y1: number, x2: number, y2: number, t: number\n\n const len = data.length\n while (i < len) {\n command = data[i]\n switch (command) {\n case M: //moveto(x, y)\n case L: //lineto(x, y)\n toX = data[i + 1]\n toY = data[i + 2]\n distance = segments[index]\n\n if (total + distance >= motionDistance || !distanceData.total) {\n if (!i) x = toX, y = toY // first M\n tempFrom.x = x\n tempFrom.y = y\n to.x = toX\n to.y = toY\n PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true)\n path.push(command, to.x, to.y)\n return path\n }\n\n x = toX\n y = toY\n i += 3\n path.push(command, x, y)\n break\n case C: //bezierCurveTo(x1, y1, x2, y2, x,y)\n x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4]\n toX = data[i + 5]\n toY = data[i + 6]\n distance = segments[index]\n\n if (total + distance >= motionDistance) {\n t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision)\n HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY)\n return path\n }\n\n x = toX\n y = toY\n i += 7\n path.push(command, x1, y1, x2, y2, toX, toY)\n break\n case Z: //closepath()\n i += 1\n path.push(command)\n default:\n distance = 0\n\n }\n\n index++\n total += distance\n }\n\n return path\n }\n\n}","import { IValue } from '@leafer-ui/interface'\nimport { decorateLeafAttr, attr, isNull } from '@leafer-ui/draw'\n\nexport function motionPathType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: any) {\n this.__setAttr(key, value)\n this.__hasMotionPath = this.motionPath || !isNull(this.motion)\n this.__layout.matrixChanged || this.__layout.matrixChange()\n }\n }))\n}","export { HighCurveHelper } from './HighCurveHelper'\nexport { HighBezierHelper } from './HighBezierHelper'\nexport { motionPathType } from './decorator'\n\nimport { IMotionPathData, IUI, IUnitData, IRotationPointData, IPercentData } from '@leafer-ui/interface'\nimport { isNull, MatrixHelper, LeafHelper, BranchHelper, Transition, UI, UnitConvert, Plugin, isObject, isNumber } from '@leafer-ui/draw'\n\nimport { HighCurveHelper } from './HighCurveHelper'\nimport { motionPathType } from './decorator'\n\n\nPlugin.add('motion-path')\n\n\nTransition.register('motion', function (from: number | IPercentData, to: number | IPercentData, t: number, target: IUI): number {\n if (isObject(from)) from = UnitConvert.number(from, target.getMotionTotal())\n if (isObject(to)) to = UnitConvert.number(to, target.getMotionTotal())\n return Transition.number(from || 0, to || 0, t)\n})\n\nTransition.register('motionRotation', function (from: any, to: any, t: number): number {\n return Transition.number(from, to, t)\n})\n\n\nconst ui = UI.prototype\nconst { updateMatrix, updateAllMatrix } = LeafHelper\nconst { updateBounds } = BranchHelper\n\n\n// addAttr\nUI.addAttr('motionPath', undefined, motionPathType)\nUI.addAttr('motionPrecision', 1, motionPathType)\n\nUI.addAttr('motion', undefined, motionPathType)\nUI.addAttr('motionRotation', true, motionPathType)\n\n\nui.getMotionPathData = function (): IMotionPathData {\n return getMotionPathData(getMotionPath(this))\n}\n\nui.getMotionPoint = function (motionDistance: number | IUnitData): IRotationPointData {\n const path = getMotionPath(this)\n const data = getMotionPathData(path)\n if (!data.total) return {} as IRotationPointData\n\n const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision)\n MatrixHelper.toOuterPoint(path.localTransform, point)\n\n const { motionRotation } = this\n if (motionRotation === false) delete point.rotation\n else if (isNumber(motionRotation)) point.rotation += motionRotation\n return point\n}\n\nui.getMotionTotal = function (): number {\n return this.getMotionPathData().total\n}\n\nui.__updateMotionPath = function (): void {\n const data = this.__\n if (this.__layout.resized && data.__pathForMotion) data.__pathForMotion = undefined\n\n if (this.motionPath) {\n let child: IUI\n const { children } = this.parent\n for (let i = 0; i < children.length; i++) {\n child = children[i]\n if (!isNull(child.motion) && !child.__layout.matrixChanged) {\n if (child !== this) child.__extraUpdate()\n updateMotion(child)\n }\n }\n } else updateMotion(this)\n}\n\n\nfunction updateMotion(leaf: IUI): void {\n const { motion, leaferIsCreated } = leaf\n if (isNull(motion)) return\n\n if (leaferIsCreated) leaf.leafer.created = false // 拦截布局更新通知,进行手动更新布局\n\n if (leaf.motionPath) {\n\n const data = getMotionPathData(leaf)\n if (data.total) leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision) // 生长路径\n\n } else {\n\n leaf.set(leaf.getMotionPoint(motion)) // 动画路径\n\n if (!leaf.__hasAutoLayout) { // 手动更新布局\n if (leaf.isBranch) updateAllMatrix(leaf), updateBounds(leaf, leaf)\n else updateMatrix(leaf)\n }\n\n }\n\n if (leaferIsCreated) leaf.leafer.created = true\n}\n\nfunction getMotionPath(leaf: IUI): IUI {\n const { parent } = leaf\n if (!leaf.motionPath && parent) {\n const { children } = parent\n for (let i = 0; i < children.length; i++) {\n if (children[i].motionPath) return children[i]\n }\n }\n return leaf\n}\n\nfunction getMotionPathData(leaf: IUI): IMotionPathData {\n const data = leaf.__\n if (data.__pathForMotion) return data.__pathForMotion\n return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true))\n}"],"names":["gaussNodes","gaussWeights","sqrt","Math","getDerivative","BezierHelper","HighBezierHelper","getDistance","fromX","fromY","x1","y1","x2","y2","toX","toY","t","t1","t2","d1X","d1Y","d2X","d2Y","distance","half","i","length","getRotation","dx","dy","atan2","OneRadian","getT","totalDistance","precision","low","high","middle","realPrecision","cut","data","o","ax","ay","mbx","mby","bx","by","cx","cy","push","PathCommandMap","C","M","L","Z","tempPoint","tempFrom","HighCurveHelper","transform","matrix","command","len","transformPoints","start","pointCount","end","x","y","MatrixHelper","toOuterPoint","getMotionPathData","total","segments","PointHelper","getDistanceFrom","getDistancePoint","distanceData","motionDistance","motionPrecision","UnitConvert","number","to","index","rotation","getAngle","getPointAndSet","getDistancePath","path","motionPathType","defaultValue","decorateLeafAttr","key","attr","set","value","this","__setAttr","__hasMotionPath","motionPath","isNull","motion","__layout","matrixChanged","matrixChange","Plugin","add","Transition","register","from","target","isObject","getMotionTotal","ui","UI","prototype","updateMatrix","updateAllMatrix","LeafHelper","updateBounds","BranchHelper","updateMotion","leaf","leaferIsCreated","leafer","created","__","__pathForRender","getMotionPoint","__hasAutoLayout","isBranch","getMotionPath","parent","children","__pathForMotion","getPath","addAttr","undefined","point","localTransform","motionRotation","isNumber","__updateMotionPath","resized","child","__extraUpdate"],"mappings":"oRAKA,MAAMA,EAAa,CAAC,YAAc,YAAc,YAAc,YAAc,aACtEC,EAAe,CAAC,YAAc,YAAc,YAAc,YAAc,cAExEC,KAAEA,GAASC,MACXC,cAAEA,GAAkBC,EAEbC,EAAmB,CAE5B,WAAAC,CAAYC,EAAeC,EAAeC,EAAYC,EAAYC,EAAYC,EAAYC,EAAaC,EAAaC,EAAI,GACpH,IAAkBC,EAAYC,EAAYC,EAAaC,EAAaC,EAAaC,EAA7EC,EAAW,EAA+EC,EAAOR,EAAI,EACzG,IAAK,IAAIS,EAAI,EAAGA,EAAIzB,EAAW0B,OAAQD,IACnCR,EAAKO,GAAQ,EAAIxB,EAAWyB,IAC5BP,EAAKM,GAAQ,EAAIxB,EAAWyB,IAE5BN,EAAMf,EAAca,EAAIT,EAAOE,EAAIE,EAAIE,GACvCM,EAAMhB,EAAca,EAAIR,EAAOE,EAAIE,EAAIE,GAEvCM,EAAMjB,EAAcc,EAAIV,EAAOE,EAAIE,EAAIE,GACvCQ,EAAMlB,EAAcc,EAAIT,EAAOE,EAAIE,EAAIE,GAEvCQ,GAAYtB,EAAawB,IAAMvB,EAAKiB,EAAMA,EAAMC,EAAMA,GAAOlB,EAAKmB,EAAMA,EAAMC,EAAMA,IAExF,OAAOC,EAAWC,CACtB,EAEA,WAAAG,CAAYX,EAAWR,EAAeC,EAAeC,EAAYC,EAAYC,EAAYC,EAAYC,EAAaC,GAC9G,MAAMa,EAAKxB,EAAcY,EAAGR,EAAOE,EAAIE,EAAIE,GACrCe,EAAKzB,EAAcY,EAAGP,EAAOE,EAAIE,EAAIE,GAC3C,OAAOZ,KAAK2B,MAAMD,EAAID,GAAMG,CAChC,EAEA,IAAAC,CAAKT,EAAkBU,EAAuBzB,EAAeC,EAAeC,EAAYC,EAAYC,EAAYC,EAAYC,EAAaC,EAAamB,EAAY,GAC9J,IAA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G/C,GAEjCyB,EAAGsB,QAAQ,cAAUC,EAAWhD,GAChCyB,EAAGsB,QAAQ,kBAAkB,EAAM/C,GAGnCwB,EAAG1C,kBAAoB,WACnB,OAAOA,EAAkB4D,EAAcnC,MAC3C,EAEAiB,EAAGe,eAAiB,SAAUlD,GAC1B,MAAMU,EAAO2C,EAAcnC,MACrBxD,EAAO+B,EAAkBiB,GAC/B,IAAKhD,EAAKgC,MAAO,MAAO,CAAA,EAExB,MAAMkE,EAAQhF,EAAgBkB,iBAAiBpC,EAAMsC,EAAgBU,EAAKT,iBAC1EV,EAAaC,aAAakB,EAAKmD,eAAgBD,GAE/C,MAAME,eAAEA,GAAmB5C,KAG3B,OAFuB,IAAnB4C,SAAiCF,EAAMtD,SAClCyD,EAASD,KAAiBF,EAAMtD,UAAYwD,GAC9CF,CACX,EAEAzB,EAAGD,eAAiB,WAChB,OAAOhB,KAAKzB,oBAAoBC,KACpC,EAEAyC,EAAG6B,mBAAqB,WACpB,MAAMtG,EAAOwD,KAAK8B,GAGlB,GAFI9B,KAAKM,SAASyC,SAAWvG,EAAK8F,kBAAiB9F,EAAK8F,qBAAkBG,GAEtEzC,KAAKG,WAAY,CACjB,IAAI6C,EACJ,MAAMX,SAAEA,GAAarC,KAAKoC,OAC1B,IAAK,IAAI3G,EAAI,EAAGA,EAAI4G,EAAS3G,OAAQD,IACjCuH,EAAQX,EAAS5G,GACZ2E,EAAO4C,EAAM3C,SAAY2C,EAAM1C,SAASC,gBACrCyC,IAAUhD,MAAMgD,EAAMC,gBAC1BxB,EAAauB,GAGzB,MAAOvB,EAAazB,KACxB"}
@@ -1,11 +1,11 @@
1
1
  this.LeaferIN = this.LeaferIN || {};
2
- this.LeaferIN.motionPath = (function (exports, draw) {
3
- 'use strict';
4
2
 
5
- const gaussNodes = [0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.9739065285];
6
- const gaussWeights = [0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443];
7
- const { sqrt } = Math;
8
- const { getDerivative } = draw.BezierHelper;
3
+ this.LeaferIN.motionPath = function(exports, draw) {
4
+ "use strict";
5
+ const gaussNodes = [ .1488743389, .4333953941, .6794095682, .8650633666, .9739065285 ];
6
+ const gaussWeights = [ .2955242247, .2692667193, .2190863625, .1494513491, .0666713443 ];
7
+ const {sqrt: sqrt} = Math;
8
+ const {getDerivative: getDerivative} = draw.BezierHelper;
9
9
  const HighBezierHelper = {
10
10
  getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, t = 1) {
11
11
  let distance = 0, t1, t2, d1X, d1Y, d2X, d2Y, half = t / 2;
@@ -27,10 +27,8 @@ this.LeaferIN.motionPath = (function (exports, draw) {
27
27
  },
28
28
  getT(distance, totalDistance, fromX, fromY, x1, y1, x2, y2, toX, toY, precision = 1) {
29
29
  let low = 0, high = 1, middle = distance / totalDistance, realPrecision = precision / totalDistance / 3;
30
- if (middle >= 1)
31
- return 1;
32
- if (middle <= 0)
33
- return 0;
30
+ if (middle >= 1) return 1;
31
+ if (middle <= 0) return 0;
34
32
  while (high - low > realPrecision) {
35
33
  getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, middle) < distance ? low = middle : high = middle;
36
34
  middle = (low + high) / 2;
@@ -48,9 +46,8 @@ this.LeaferIN.motionPath = (function (exports, draw) {
48
46
  data.push(draw.PathCommandMap.C, ax, ay, bx, by, cx, cy);
49
47
  }
50
48
  };
51
- const { getDistance } = HighBezierHelper;
52
-
53
- const { M, L, C, Z } = draw.PathCommandMap;
49
+ const {getDistance: getDistance} = HighBezierHelper;
50
+ const {M: M, L: L, C: C, Z: Z} = draw.PathCommandMap;
54
51
  const tempPoint = {}, tempFrom = {};
55
52
  const HighCurveHelper = {
56
53
  transform(data, matrix) {
@@ -59,17 +56,19 @@ this.LeaferIN.motionPath = (function (exports, draw) {
59
56
  while (i < len) {
60
57
  command = data[i];
61
58
  switch (command) {
62
- case M:
63
- case L:
64
- HighCurveHelper.transformPoints(data, matrix, i, 1);
65
- i += 3;
66
- break;
67
- case C:
68
- HighCurveHelper.transformPoints(data, matrix, i, 3);
69
- i += 7;
70
- break;
71
- case Z:
72
- i += 1;
59
+ case M:
60
+ case L:
61
+ HighCurveHelper.transformPoints(data, matrix, i, 1);
62
+ i += 3;
63
+ break;
64
+
65
+ case C:
66
+ HighCurveHelper.transformPoints(data, matrix, i, 3);
67
+ i += 7;
68
+ break;
69
+
70
+ case Z:
71
+ i += 1;
73
72
  }
74
73
  }
75
74
  },
@@ -89,35 +88,42 @@ this.LeaferIN.motionPath = (function (exports, draw) {
89
88
  while (i < len) {
90
89
  command = data[i];
91
90
  switch (command) {
92
- case M:
93
- case L:
94
- toX = data[i + 1];
95
- toY = data[i + 2];
96
- distance = (command === L && i > 0) ? draw.PointHelper.getDistanceFrom(x, y, toX, toY) : 0;
97
- x = toX;
98
- y = toY;
99
- i += 3;
100
- break;
101
- case C:
102
- toX = data[i + 5];
103
- toY = data[i + 6];
104
- distance = HighBezierHelper.getDistance(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY);
105
- x = toX;
106
- y = toY;
107
- i += 7;
108
- break;
109
- case Z:
110
- i += 1;
111
- default:
112
- distance = 0;
91
+ case M:
92
+ case L:
93
+ toX = data[i + 1];
94
+ toY = data[i + 2];
95
+ distance = command === L && i > 0 ? draw.PointHelper.getDistanceFrom(x, y, toX, toY) : 0;
96
+ x = toX;
97
+ y = toY;
98
+ i += 3;
99
+ break;
100
+
101
+ case C:
102
+ toX = data[i + 5];
103
+ toY = data[i + 6];
104
+ distance = HighBezierHelper.getDistance(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY);
105
+ x = toX;
106
+ y = toY;
107
+ i += 7;
108
+ break;
109
+
110
+ case Z:
111
+ i += 1;
112
+
113
+ default:
114
+ distance = 0;
113
115
  }
114
116
  segments.push(distance);
115
117
  total += distance;
116
118
  }
117
- return { total, segments, data };
119
+ return {
120
+ total: total,
121
+ segments: segments,
122
+ data: data
123
+ };
118
124
  },
119
125
  getDistancePoint(distanceData, motionDistance, motionPrecision) {
120
- const { segments, data } = distanceData;
126
+ const {segments: segments, data: data} = distanceData;
121
127
  motionDistance = draw.UnitConvert.number(motionDistance, distanceData.total);
122
128
  let total = 0, distance, to = {};
123
129
  let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
@@ -126,45 +132,47 @@ this.LeaferIN.motionPath = (function (exports, draw) {
126
132
  while (i < len) {
127
133
  command = data[i];
128
134
  switch (command) {
129
- case M:
130
- case L:
131
- toX = data[i + 1];
132
- toY = data[i + 2];
133
- distance = segments[index];
134
- if (total + distance >= motionDistance || !distanceData.total) {
135
- if (!i)
136
- x = toX, y = toY;
137
- tempFrom.x = x;
138
- tempFrom.y = y;
139
- to.x = toX;
140
- to.y = toY;
141
- draw.PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true);
142
- to.rotation = draw.PointHelper.getAngle(tempFrom, to);
143
- return to;
144
- }
145
- x = toX;
146
- y = toY;
147
- i += 3;
148
- break;
149
- case C:
150
- toX = data[i + 5];
151
- toY = data[i + 6];
152
- distance = segments[index];
153
- if (total + distance >= motionDistance) {
154
- x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
155
- t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
156
- draw.BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
157
- to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY);
158
- return to;
159
- }
160
- x = toX;
161
- y = toY;
162
- i += 7;
163
- break;
164
- case Z:
165
- i += 1;
166
- default:
167
- distance = 0;
135
+ case M:
136
+ case L:
137
+ toX = data[i + 1];
138
+ toY = data[i + 2];
139
+ distance = segments[index];
140
+ if (total + distance >= motionDistance || !distanceData.total) {
141
+ if (!i) x = toX, y = toY;
142
+ tempFrom.x = x;
143
+ tempFrom.y = y;
144
+ to.x = toX;
145
+ to.y = toY;
146
+ draw.PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true);
147
+ to.rotation = draw.PointHelper.getAngle(tempFrom, to);
148
+ return to;
149
+ }
150
+ x = toX;
151
+ y = toY;
152
+ i += 3;
153
+ break;
154
+
155
+ case C:
156
+ toX = data[i + 5];
157
+ toY = data[i + 6];
158
+ distance = segments[index];
159
+ if (total + distance >= motionDistance) {
160
+ x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
161
+ t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
162
+ draw.BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
163
+ to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY);
164
+ return to;
165
+ }
166
+ x = toX;
167
+ y = toY;
168
+ i += 7;
169
+ break;
170
+
171
+ case Z:
172
+ i += 1;
173
+
174
+ default:
175
+ distance = 0;
168
176
  }
169
177
  index++;
170
178
  total += distance;
@@ -172,7 +180,7 @@ this.LeaferIN.motionPath = (function (exports, draw) {
172
180
  return to;
173
181
  },
174
182
  getDistancePath(distanceData, motionDistance, motionPrecision) {
175
- const { segments, data } = distanceData, path = [];
183
+ const {segments: segments, data: data} = distanceData, path = [];
176
184
  motionDistance = draw.UnitConvert.number(motionDistance, distanceData.total);
177
185
  let total = 0, distance, to = {};
178
186
  let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
@@ -181,47 +189,49 @@ this.LeaferIN.motionPath = (function (exports, draw) {
181
189
  while (i < len) {
182
190
  command = data[i];
183
191
  switch (command) {
184
- case M:
185
- case L:
186
- toX = data[i + 1];
187
- toY = data[i + 2];
188
- distance = segments[index];
189
- if (total + distance >= motionDistance || !distanceData.total) {
190
- if (!i)
191
- x = toX, y = toY;
192
- tempFrom.x = x;
193
- tempFrom.y = y;
194
- to.x = toX;
195
- to.y = toY;
196
- draw.PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true);
197
- path.push(command, to.x, to.y);
198
- return path;
199
- }
200
- x = toX;
201
- y = toY;
202
- i += 3;
203
- path.push(command, x, y);
204
- break;
205
- case C:
206
- x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
207
- toX = data[i + 5];
208
- toY = data[i + 6];
209
- distance = segments[index];
210
- if (total + distance >= motionDistance) {
211
- t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
212
- HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
213
- return path;
214
- }
215
- x = toX;
216
- y = toY;
217
- i += 7;
218
- path.push(command, x1, y1, x2, y2, toX, toY);
219
- break;
220
- case Z:
221
- i += 1;
222
- path.push(command);
223
- default:
224
- distance = 0;
192
+ case M:
193
+ case L:
194
+ toX = data[i + 1];
195
+ toY = data[i + 2];
196
+ distance = segments[index];
197
+ if (total + distance >= motionDistance || !distanceData.total) {
198
+ if (!i) x = toX, y = toY;
199
+ tempFrom.x = x;
200
+ tempFrom.y = y;
201
+ to.x = toX;
202
+ to.y = toY;
203
+ draw.PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true);
204
+ path.push(command, to.x, to.y);
205
+ return path;
206
+ }
207
+ x = toX;
208
+ y = toY;
209
+ i += 3;
210
+ path.push(command, x, y);
211
+ break;
212
+
213
+ case C:
214
+ x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
215
+ toX = data[i + 5];
216
+ toY = data[i + 6];
217
+ distance = segments[index];
218
+ if (total + distance >= motionDistance) {
219
+ t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
220
+ HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
221
+ return path;
222
+ }
223
+ x = toX;
224
+ y = toY;
225
+ i += 7;
226
+ path.push(command, x1, y1, x2, y2, toX, toY);
227
+ break;
228
+
229
+ case Z:
230
+ i += 1;
231
+ path.push(command);
232
+
233
+ default:
234
+ distance = 0;
225
235
  }
226
236
  index++;
227
237
  total += distance;
@@ -229,9 +239,8 @@ this.LeaferIN.motionPath = (function (exports, draw) {
229
239
  return path;
230
240
  }
231
241
  };
232
-
233
242
  function motionPathType(defaultValue) {
234
- return draw.decorateLeafAttr(defaultValue, (key) => draw.attr({
243
+ return draw.decorateLeafAttr(defaultValue, key => draw.attr({
235
244
  set(value) {
236
245
  this.__setAttr(key, value);
237
246
  this.__hasMotionPath = this.motionPath || !draw.isNull(this.motion);
@@ -239,113 +248,85 @@ this.LeaferIN.motionPath = (function (exports, draw) {
239
248
  }
240
249
  }));
241
250
  }
242
-
243
- draw.Plugin.add('motion-path');
244
- draw.Transition.register('motion', function (from, to, t, target) {
245
- if (!from)
246
- from = 0;
247
- else if (typeof from === 'object')
248
- from = draw.UnitConvert.number(from, target.getMotionTotal());
249
- if (!to)
250
- to = 0;
251
- else if (typeof to === 'object')
252
- to = draw.UnitConvert.number(to, target.getMotionTotal());
253
- return draw.Transition.number(from, to, t);
251
+ draw.Plugin.add("motion-path");
252
+ draw.Transition.register("motion", function(from, to, t, target) {
253
+ if (draw.isObject(from)) from = draw.UnitConvert.number(from, target.getMotionTotal());
254
+ if (draw.isObject(to)) to = draw.UnitConvert.number(to, target.getMotionTotal());
255
+ return draw.Transition.number(from || 0, to || 0, t);
254
256
  });
255
- draw.Transition.register('motionRotation', function (from, to, t) {
257
+ draw.Transition.register("motionRotation", function(from, to, t) {
256
258
  return draw.Transition.number(from, to, t);
257
259
  });
258
260
  const ui = draw.UI.prototype;
259
- const { updateMatrix, updateAllMatrix } = draw.LeafHelper;
260
- const { updateBounds } = draw.BranchHelper;
261
- draw.UI.addAttr('motionPath', undefined, motionPathType);
262
- draw.UI.addAttr('motionPrecision', 1, motionPathType);
263
- draw.UI.addAttr('motion', undefined, motionPathType);
264
- draw.UI.addAttr('motionRotation', true, motionPathType);
265
- ui.getMotionPathData = function () {
261
+ const {updateMatrix: updateMatrix, updateAllMatrix: updateAllMatrix} = draw.LeafHelper;
262
+ const {updateBounds: updateBounds} = draw.BranchHelper;
263
+ draw.UI.addAttr("motionPath", undefined, motionPathType);
264
+ draw.UI.addAttr("motionPrecision", 1, motionPathType);
265
+ draw.UI.addAttr("motion", undefined, motionPathType);
266
+ draw.UI.addAttr("motionRotation", true, motionPathType);
267
+ ui.getMotionPathData = function() {
266
268
  return getMotionPathData(getMotionPath(this));
267
269
  };
268
- ui.getMotionPoint = function (motionDistance) {
270
+ ui.getMotionPoint = function(motionDistance) {
269
271
  const path = getMotionPath(this);
270
272
  const data = getMotionPathData(path);
271
- if (!data.total)
272
- return {};
273
+ if (!data.total) return {};
273
274
  const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision);
274
275
  draw.MatrixHelper.toOuterPoint(path.localTransform, point);
275
- const { motionRotation } = this;
276
- if (motionRotation === false)
277
- delete point.rotation;
278
- else if (typeof motionRotation === 'number')
279
- point.rotation += motionRotation;
276
+ const {motionRotation: motionRotation} = this;
277
+ if (motionRotation === false) delete point.rotation; else if (draw.isNumber(motionRotation)) point.rotation += motionRotation;
280
278
  return point;
281
279
  };
282
- ui.getMotionTotal = function () {
280
+ ui.getMotionTotal = function() {
283
281
  return this.getMotionPathData().total;
284
282
  };
285
- ui.__updateMotionPath = function () {
283
+ ui.__updateMotionPath = function() {
286
284
  const data = this.__;
287
- if (this.__layout.resized && data.__pathForMotion)
288
- data.__pathForMotion = undefined;
285
+ if (this.__layout.resized && data.__pathForMotion) data.__pathForMotion = undefined;
289
286
  if (this.motionPath) {
290
287
  let child;
291
- const { children } = this.parent;
288
+ const {children: children} = this.parent;
292
289
  for (let i = 0; i < children.length; i++) {
293
290
  child = children[i];
294
291
  if (!draw.isNull(child.motion) && !child.__layout.matrixChanged) {
295
- if (child !== this)
296
- child.__extraUpdate();
292
+ if (child !== this) child.__extraUpdate();
297
293
  updateMotion(child);
298
294
  }
299
295
  }
300
- }
301
- else
302
- updateMotion(this);
296
+ } else updateMotion(this);
303
297
  };
304
298
  function updateMotion(leaf) {
305
- const { motion, leaferIsCreated } = leaf;
306
- if (draw.isNull(motion))
307
- return;
308
- if (leaferIsCreated)
309
- leaf.leafer.created = false;
299
+ const {motion: motion, leaferIsCreated: leaferIsCreated} = leaf;
300
+ if (draw.isNull(motion)) return;
301
+ if (leaferIsCreated) leaf.leafer.created = false;
310
302
  if (leaf.motionPath) {
311
303
  const data = getMotionPathData(leaf);
312
- if (data.total)
313
- leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision);
314
- }
315
- else {
304
+ if (data.total) leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision);
305
+ } else {
316
306
  leaf.set(leaf.getMotionPoint(motion));
317
307
  if (!leaf.__hasAutoLayout) {
318
- if (leaf.isBranch)
319
- updateAllMatrix(leaf), updateBounds(leaf, leaf);
320
- else
321
- updateMatrix(leaf);
308
+ if (leaf.isBranch) updateAllMatrix(leaf), updateBounds(leaf, leaf); else updateMatrix(leaf);
322
309
  }
323
310
  }
324
- if (leaferIsCreated)
325
- leaf.leafer.created = true;
311
+ if (leaferIsCreated) leaf.leafer.created = true;
326
312
  }
327
313
  function getMotionPath(leaf) {
328
- const { parent } = leaf;
314
+ const {parent: parent} = leaf;
329
315
  if (!leaf.motionPath && parent) {
330
- const { children } = parent;
316
+ const {children: children} = parent;
331
317
  for (let i = 0; i < children.length; i++) {
332
- if (children[i].motionPath)
333
- return children[i];
318
+ if (children[i].motionPath) return children[i];
334
319
  }
335
320
  }
336
321
  return leaf;
337
322
  }
338
323
  function getMotionPathData(leaf) {
339
324
  const data = leaf.__;
340
- if (data.__pathForMotion)
341
- return data.__pathForMotion;
325
+ if (data.__pathForMotion) return data.__pathForMotion;
342
326
  return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
343
327
  }
344
-
345
328
  exports.HighBezierHelper = HighBezierHelper;
346
329
  exports.HighCurveHelper = HighCurveHelper;
347
330
  exports.motionPathType = motionPathType;
348
-
349
331
  return exports;
350
-
351
- })({}, LeaferUI);
332
+ }({}, LeaferUI);