@leafer-in/motion-path 1.12.0 → 1.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/motion-path.cjs +14 -8
- package/dist/motion-path.esm.js +15 -9
- package/dist/motion-path.esm.min.js +1 -1
- package/dist/motion-path.esm.min.js.map +1 -1
- package/dist/motion-path.js +14 -8
- package/dist/motion-path.min.cjs +1 -1
- package/dist/motion-path.min.cjs.map +1 -1
- package/dist/motion-path.min.js +1 -1
- package/dist/motion-path.min.js.map +1 -1
- package/package.json +4 -4
- package/src/HighCurveHelper.ts +15 -9
package/dist/motion-path.cjs
CHANGED
|
@@ -53,7 +53,7 @@ const HighBezierHelper = {
|
|
|
53
53
|
|
|
54
54
|
const {getDistance: getDistance} = HighBezierHelper;
|
|
55
55
|
|
|
56
|
-
const {M: M, L: L, C: C, Z: Z} = draw.PathCommandMap;
|
|
56
|
+
const {M: M, L: L, C: C, Z: Z} = draw.PathCommandMap, {float: float} = draw.MathHelper;
|
|
57
57
|
|
|
58
58
|
const tempPoint = {}, tempFrom = {};
|
|
59
59
|
|
|
@@ -190,7 +190,7 @@ const HighCurveHelper = {
|
|
|
190
190
|
getDistancePath(distanceData, motionDistance, motionPrecision) {
|
|
191
191
|
const {segments: segments, data: data} = distanceData, path = [];
|
|
192
192
|
motionDistance = draw.UnitConvert.number(motionDistance, distanceData.total);
|
|
193
|
-
let total = 0, distance, to = {};
|
|
193
|
+
let total = 0, distance, cutDistance, to = {};
|
|
194
194
|
let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
|
|
195
195
|
let x1, y1, x2, y2, t;
|
|
196
196
|
const len = data.length;
|
|
@@ -202,14 +202,17 @@ const HighCurveHelper = {
|
|
|
202
202
|
toX = data[i + 1];
|
|
203
203
|
toY = data[i + 2];
|
|
204
204
|
distance = segments[index];
|
|
205
|
-
if (total + distance
|
|
205
|
+
if (total + distance > motionDistance || !distanceData.total) {
|
|
206
206
|
if (!i) x = toX, y = toY;
|
|
207
207
|
tempFrom.x = x;
|
|
208
208
|
tempFrom.y = y;
|
|
209
209
|
to.x = toX;
|
|
210
210
|
to.y = toY;
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
cutDistance = float(motionDistance - total);
|
|
212
|
+
if (cutDistance) {
|
|
213
|
+
draw.PointHelper.getDistancePoint(tempFrom, to, cutDistance, true);
|
|
214
|
+
path.push(command, to.x, to.y);
|
|
215
|
+
}
|
|
213
216
|
return path;
|
|
214
217
|
}
|
|
215
218
|
x = toX;
|
|
@@ -223,9 +226,12 @@ const HighCurveHelper = {
|
|
|
223
226
|
toX = data[i + 5];
|
|
224
227
|
toY = data[i + 6];
|
|
225
228
|
distance = segments[index];
|
|
226
|
-
if (total + distance
|
|
227
|
-
|
|
228
|
-
|
|
229
|
+
if (total + distance > motionDistance) {
|
|
230
|
+
cutDistance = float(motionDistance - total);
|
|
231
|
+
if (cutDistance) {
|
|
232
|
+
t = HighBezierHelper.getT(cutDistance, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
|
|
233
|
+
HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
|
|
234
|
+
}
|
|
229
235
|
return path;
|
|
230
236
|
}
|
|
231
237
|
x = toX;
|
package/dist/motion-path.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BezierHelper, PathCommandMap, OneRadian, UnitConvert, PointHelper, MatrixHelper, decorateLeafAttr, attr, isNull, Plugin, Transition, isObject, UI, LeafHelper, BranchHelper, isNumber } from "@leafer-ui/draw";
|
|
1
|
+
import { BezierHelper, PathCommandMap, OneRadian, MathHelper, UnitConvert, PointHelper, MatrixHelper, decorateLeafAttr, attr, isNull, Plugin, Transition, isObject, UI, LeafHelper, BranchHelper, isNumber } from "@leafer-ui/draw";
|
|
2
2
|
|
|
3
3
|
const gaussNodes = [ .1488743389, .4333953941, .6794095682, .8650633666, .9739065285 ];
|
|
4
4
|
|
|
@@ -51,7 +51,7 @@ const HighBezierHelper = {
|
|
|
51
51
|
|
|
52
52
|
const {getDistance: getDistance} = HighBezierHelper;
|
|
53
53
|
|
|
54
|
-
const {M: M, L: L, C: C, Z: Z} = PathCommandMap;
|
|
54
|
+
const {M: M, L: L, C: C, Z: Z} = PathCommandMap, {float: float} = MathHelper;
|
|
55
55
|
|
|
56
56
|
const tempPoint = {}, tempFrom = {};
|
|
57
57
|
|
|
@@ -188,7 +188,7 @@ const HighCurveHelper = {
|
|
|
188
188
|
getDistancePath(distanceData, motionDistance, motionPrecision) {
|
|
189
189
|
const {segments: segments, data: data} = distanceData, path = [];
|
|
190
190
|
motionDistance = UnitConvert.number(motionDistance, distanceData.total);
|
|
191
|
-
let total = 0, distance, to = {};
|
|
191
|
+
let total = 0, distance, cutDistance, to = {};
|
|
192
192
|
let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
|
|
193
193
|
let x1, y1, x2, y2, t;
|
|
194
194
|
const len = data.length;
|
|
@@ -200,14 +200,17 @@ const HighCurveHelper = {
|
|
|
200
200
|
toX = data[i + 1];
|
|
201
201
|
toY = data[i + 2];
|
|
202
202
|
distance = segments[index];
|
|
203
|
-
if (total + distance
|
|
203
|
+
if (total + distance > motionDistance || !distanceData.total) {
|
|
204
204
|
if (!i) x = toX, y = toY;
|
|
205
205
|
tempFrom.x = x;
|
|
206
206
|
tempFrom.y = y;
|
|
207
207
|
to.x = toX;
|
|
208
208
|
to.y = toY;
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
cutDistance = float(motionDistance - total);
|
|
210
|
+
if (cutDistance) {
|
|
211
|
+
PointHelper.getDistancePoint(tempFrom, to, cutDistance, true);
|
|
212
|
+
path.push(command, to.x, to.y);
|
|
213
|
+
}
|
|
211
214
|
return path;
|
|
212
215
|
}
|
|
213
216
|
x = toX;
|
|
@@ -221,9 +224,12 @@ const HighCurveHelper = {
|
|
|
221
224
|
toX = data[i + 5];
|
|
222
225
|
toY = data[i + 6];
|
|
223
226
|
distance = segments[index];
|
|
224
|
-
if (total + distance
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
if (total + distance > motionDistance) {
|
|
228
|
+
cutDistance = float(motionDistance - total);
|
|
229
|
+
if (cutDistance) {
|
|
230
|
+
t = HighBezierHelper.getT(cutDistance, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
|
|
231
|
+
HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
|
|
232
|
+
}
|
|
227
233
|
return path;
|
|
228
234
|
}
|
|
229
235
|
x = toX;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{BezierHelper as t,PathCommandMap as o,OneRadian as e,
|
|
1
|
+
import{BezierHelper as t,PathCommandMap as o,OneRadian as e,MathHelper as n,UnitConvert as a,PointHelper as i,MatrixHelper as r,decorateLeafAttr as s,attr as c,isNull as h,Plugin as u,Transition as l,isObject as f,UI as g,LeafHelper as m,BranchHelper as d,isNumber as _}from"@leafer-ui/draw";const P=[.1488743389,.4333953941,.6794095682,.8650633666,.9739065285],p=[.2955242247,.2692667193,.2190863625,.1494513491,.0666713443],{sqrt:M}=Math,{getDerivative:D}=t,b={getDistance(t,o,e,n,a,i,r,s,c=1){let h,u,l,f,g,m,d=0,_=c/2;for(let c=0;c<P.length;c++)h=_*(1+P[c]),u=_*(1-P[c]),l=D(h,t,e,a,r),f=D(h,o,n,i,s),g=D(u,t,e,a,r),m=D(u,o,n,i,s),d+=p[c]*(M(l*l+f*f)+M(g*g+m*m));return d*_},getRotation(t,o,n,a,i,r,s,c,h){const u=D(t,o,a,r,c),l=D(t,n,i,s,h);return Math.atan2(l,u)/e},getT(t,o,e,n,a,i,r,s,c,h,u=1){let l=0,f=1,g=t/o,m=u/o/3;if(g>=1)return 1;if(g<=0)return 0;for(;f-l>m;)x(e,n,a,i,r,s,c,h,g)<t?l=g:f=g,g=(l+f)/2;return g},cut(t,e,n,a,i,r,s,c,h,u){const l=1-e,f=l*n+e*i,g=l*a+e*r,m=l*i+e*s,d=l*r+e*c,_=l*f+e*m,P=l*g+e*d,p=l*_+e*(l*m+e*(l*s+e*h)),M=l*P+e*(l*d+e*(l*c+e*u));t.push(o.C,f,g,_,P,p,M)}},{getDistance:x}=b,{M:y,L:A,C:k,Z:F}=o,{float:T}=n,C={},R={},v={transform(t,o){let e,n=0;const a=t.length;for(;n<a;)switch(e=t[n],e){case y:case A:v.transformPoints(t,o,n,1),n+=3;break;case k:v.transformPoints(t,o,n,3),n+=7;break;case F:n+=1}},transformPoints(t,o,e,n){for(let a=e+1,i=a+2*n;a<i;a+=2)C.x=t[a],C.y=t[a+1],r.toOuterPoint(o,C),t[a]=C.x,t[a+1]=C.y},getMotionPathData(t){let o,e,n,a,r=0,s=[],c=0,h=0,u=0;const l=t.length;for(;c<l;){switch(a=t[c],a){case y:case A:e=t[c+1],n=t[c+2],o=a===A&&c>0?i.getDistanceFrom(h,u,e,n):0,h=e,u=n,c+=3;break;case k:e=t[c+5],n=t[c+6],o=b.getDistance(h,u,t[c+1],t[c+2],t[c+3],t[c+4],e,n),h=e,u=n,c+=7;break;case F:c+=1;default:o=0}s.push(o),r+=o}return{total:r,segments:s,data:t}},getDistancePoint(o,e,n){const{segments:r,data:s}=o;e=a.number(e,o.total);let c,h,u,l,f,g,m,d,_,P=0,p={},M=0,D=0,x=0,T=0;const C=s.length;for(;M<C;){switch(l=s[M],l){case y:case A:if(h=s[M+1],u=s[M+2],c=r[D],P+c>=e||!o.total)return M||(x=h,T=u),R.x=x,R.y=T,p.x=h,p.y=u,i.getDistancePoint(R,p,e-P,!0),p.rotation=i.getAngle(R,p),p;x=h,T=u,M+=3;break;case k:if(h=s[M+5],u=s[M+6],c=r[D],P+c>=e)return f=s[M+1],g=s[M+2],m=s[M+3],d=s[M+4],_=b.getT(e-P,c,x,T,f,g,m,d,h,u,n),t.getPointAndSet(_,x,T,f,g,m,d,h,u,p),p.rotation=b.getRotation(_,x,T,f,g,m,d,h,u),p;x=h,T=u,M+=7;break;case F:M+=1;default:c=0}D++,P+=c}return p},getDistancePath(t,o,e){const{segments:n,data:r}=t,s=[];o=a.number(o,t.total);let c,h,u,l,f,g,m,d,_,P,p=0,M={},D=0,x=0,C=0,v=0;const w=r.length;for(;D<w;){switch(f=r[D],f){case y:case A:if(u=r[D+1],l=r[D+2],c=n[x],p+c>o||!t.total)return D||(C=u,v=l),R.x=C,R.y=v,M.x=u,M.y=l,h=T(o-p),h&&(i.getDistancePoint(R,M,h,!0),s.push(f,M.x,M.y)),s;C=u,v=l,D+=3,s.push(f,C,v);break;case k:if(g=r[D+1],m=r[D+2],d=r[D+3],_=r[D+4],u=r[D+5],l=r[D+6],c=n[x],p+c>o)return h=T(o-p),h&&(P=b.getT(h,c,C,v,g,m,d,_,u,l,e),b.cut(s,P,C,v,g,m,d,_,u,l)),s;C=u,v=l,D+=7,s.push(f,g,m,d,_,u,l);break;case F:D+=1,s.push(f);default:c=0}x++,p+=c}return s}};function w(t){return s(t,t=>c({set(o){this.__setAttr(t,o),this.__hasMotionPath=this.motionPath||!h(this.motion),this.__layout.matrixChanged||this.__layout.matrixChange()}}))}u.add("motion-path"),l.register("motion",function(t,o,e,n){return f(t)&&(t=a.number(t,n.getMotionTotal())),f(o)&&(o=a.number(o,n.getMotionTotal())),l.number(t||0,o||0,e)}),l.register("motionRotation",function(t,o,e){return l.number(t,o,e)});const B=g.prototype,{updateMatrix:L,updateAllMatrix:O}=m,{updateBounds:q}=d;function z(t){const{motion:o,leaferIsCreated:e}=t;if(!h(o)){if(e&&(t.leafer.created=!1),t.motionPath){const e=S(t);e.total&&(t.__.__pathForRender=v.getDistancePath(e,o,t.motionPrecision))}else t.set(t.getMotionPoint(o)),t.__hasAutoLayout||(t.isBranch?(O(t),q(t,t)):L(t));e&&(t.leafer.created=!0)}}function I(t){const{parent:o}=t;if(!t.motionPath&&o){const{children:t}=o;for(let o=0;o<t.length;o++)if(t[o].motionPath)return t[o]}return t}function S(t){const o=t.__;return o.__pathForMotion?o.__pathForMotion:o.__pathForMotion=v.getMotionPathData(t.getPath(!0,!0))}g.addAttr("motionPath",void 0,w),g.addAttr("motionPrecision",1,w),g.addAttr("motion",void 0,w),g.addAttr("motionRotation",!0,w),B.getMotionPathData=function(){return S(I(this))},B.getMotionPoint=function(t){const o=I(this),e=S(o);if(!e.total)return{};const n=v.getDistancePoint(e,t,o.motionPrecision);r.toOuterPoint(o.localTransform,n);const{motionRotation:a}=this;return!1===a?delete n.rotation:_(a)&&(n.rotation+=a),n},B.getMotionTotal=function(){return this.getMotionPathData().total},B.__updateMotionPath=function(){const t=this.__;if(this.__layout.resized&&t.__pathForMotion&&(t.__pathForMotion=void 0),this.motionPath){let t;const{children:o}=this.parent;for(let e=0;e<o.length;e++)t=o[e],h(t.motion)||t.__layout.matrixChanged||(t!==this&&t.__extraUpdate(),z(t))}else z(this)};export{b as HighBezierHelper,v as HighCurveHelper,w as motionPathType};
|
|
2
2
|
//# sourceMappingURL=motion-path.esm.min.js.map
|
|
@@ -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, 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,E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AGsB,QAAQ,kBAAcC,EAAWhD,GACpCyB,EAAGsB,QAAQ,kBAAmB,EAAG/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
|
+
{"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, MathHelper, PathCommandMap, PointHelper, UnitConvert } from '@leafer-ui/draw'\n\nimport { HighBezierHelper } from './HighBezierHelper'\n\n\nconst { M, L, C, Z } = PathCommandMap, { float } = MathHelper\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, cutDistance: 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 cutDistance = float(motionDistance - total)\n if (cutDistance) {\n PointHelper.getDistancePoint(tempFrom, to, cutDistance, true)\n path.push(command, to.x, to.y)\n }\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 cutDistance = float(motionDistance - total)\n if (cutDistance) {\n t = HighBezierHelper.getT(cutDistance, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision)\n HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY)\n }\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","float","MathHelper","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","cutDistance","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":"oSAKA,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,GAC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C9CF,CACX,EAEAzB,EAAGD,eAAiB,WAChB,OAAOhB,KAAK1B,oBAAoBC,KACpC,EAEA0C,EAAG6B,mBAAqB,WACpB,MAAMzG,EAAO2D,KAAK8B,GAGlB,GAFI9B,KAAKM,SAASyC,SAAW1G,EAAKiG,kBAAiBjG,EAAKiG,qBAAkBG,GAEtEzC,KAAKG,WAAY,CACjB,IAAI6C,EACJ,MAAMX,SAAEA,GAAarC,KAAKoC,OAC1B,IAAK,IAAI9G,EAAI,EAAGA,EAAI+G,EAAS9G,OAAQD,IACjC0H,EAAQX,EAAS/G,GACZ8E,EAAO4C,EAAM3C,SAAY2C,EAAM1C,SAASC,gBACrCyC,IAAUhD,MAAMgD,EAAMC,gBAC1BxB,EAAauB,GAGzB,MAAOvB,EAAazB,KACxB"}
|
package/dist/motion-path.js
CHANGED
|
@@ -47,7 +47,7 @@ this.LeaferIN.motionPath = function(exports, draw) {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
const {getDistance: getDistance} = HighBezierHelper;
|
|
50
|
-
const {M: M, L: L, C: C, Z: Z} = draw.PathCommandMap;
|
|
50
|
+
const {M: M, L: L, C: C, Z: Z} = draw.PathCommandMap, {float: float} = draw.MathHelper;
|
|
51
51
|
const tempPoint = {}, tempFrom = {};
|
|
52
52
|
const HighCurveHelper = {
|
|
53
53
|
transform(data, matrix) {
|
|
@@ -182,7 +182,7 @@ this.LeaferIN.motionPath = function(exports, draw) {
|
|
|
182
182
|
getDistancePath(distanceData, motionDistance, motionPrecision) {
|
|
183
183
|
const {segments: segments, data: data} = distanceData, path = [];
|
|
184
184
|
motionDistance = draw.UnitConvert.number(motionDistance, distanceData.total);
|
|
185
|
-
let total = 0, distance, to = {};
|
|
185
|
+
let total = 0, distance, cutDistance, to = {};
|
|
186
186
|
let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
|
|
187
187
|
let x1, y1, x2, y2, t;
|
|
188
188
|
const len = data.length;
|
|
@@ -194,14 +194,17 @@ this.LeaferIN.motionPath = function(exports, draw) {
|
|
|
194
194
|
toX = data[i + 1];
|
|
195
195
|
toY = data[i + 2];
|
|
196
196
|
distance = segments[index];
|
|
197
|
-
if (total + distance
|
|
197
|
+
if (total + distance > motionDistance || !distanceData.total) {
|
|
198
198
|
if (!i) x = toX, y = toY;
|
|
199
199
|
tempFrom.x = x;
|
|
200
200
|
tempFrom.y = y;
|
|
201
201
|
to.x = toX;
|
|
202
202
|
to.y = toY;
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
cutDistance = float(motionDistance - total);
|
|
204
|
+
if (cutDistance) {
|
|
205
|
+
draw.PointHelper.getDistancePoint(tempFrom, to, cutDistance, true);
|
|
206
|
+
path.push(command, to.x, to.y);
|
|
207
|
+
}
|
|
205
208
|
return path;
|
|
206
209
|
}
|
|
207
210
|
x = toX;
|
|
@@ -215,9 +218,12 @@ this.LeaferIN.motionPath = function(exports, draw) {
|
|
|
215
218
|
toX = data[i + 5];
|
|
216
219
|
toY = data[i + 6];
|
|
217
220
|
distance = segments[index];
|
|
218
|
-
if (total + distance
|
|
219
|
-
|
|
220
|
-
|
|
221
|
+
if (total + distance > motionDistance) {
|
|
222
|
+
cutDistance = float(motionDistance - total);
|
|
223
|
+
if (cutDistance) {
|
|
224
|
+
t = HighBezierHelper.getT(cutDistance, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
|
|
225
|
+
HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
|
|
226
|
+
}
|
|
221
227
|
return path;
|
|
222
228
|
}
|
|
223
229
|
x = toX;
|
package/dist/motion-path.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("@leafer-ui/draw");const e=[.1488743389,.4333953941,.6794095682,.8650633666,.9739065285],o=[.2955242247,.2692667193,.2190863625,.1494513491,.0666713443],{sqrt:n}=Math,{getDerivative:
|
|
1
|
+
"use strict";var t=require("@leafer-ui/draw");const e=[.1488743389,.4333953941,.6794095682,.8650633666,.9739065285],o=[.2955242247,.2692667193,.2190863625,.1494513491,.0666713443],{sqrt:n}=Math,{getDerivative:r}=t.BezierHelper,a={getDistance(t,a,i,s,c,h,l,u,g=1){let f,m,d,p,P,_,M=0,x=g/2;for(let g=0;g<e.length;g++)f=x*(1+e[g]),m=x*(1-e[g]),d=r(f,t,i,c,l),p=r(f,a,s,h,u),P=r(m,t,i,c,l),_=r(m,a,s,h,u),M+=o[g]*(n(d*d+p*p)+n(P*P+_*_));return M*x},getRotation(e,o,n,a,i,s,c,h,l){const u=r(e,o,a,s,h),g=r(e,n,i,c,l);return Math.atan2(g,u)/t.OneRadian},getT(t,e,o,n,r,a,s,c,h,l,u=1){let g=0,f=1,m=t/e,d=u/e/3;if(m>=1)return 1;if(m<=0)return 0;for(;f-g>d;)i(o,n,r,a,s,c,h,l,m)<t?g=m:f=m,m=(g+f)/2;return m},cut(e,o,n,r,a,i,s,c,h,l){const u=1-o,g=u*n+o*a,f=u*r+o*i,m=u*a+o*s,d=u*i+o*c,p=u*g+o*m,P=u*f+o*d,_=u*p+o*(u*m+o*(u*s+o*h)),M=u*P+o*(u*d+o*(u*c+o*l));e.push(t.PathCommandMap.C,g,f,p,P,_,M)}},{getDistance:i}=a,{M:s,L:c,C:h,Z:l}=t.PathCommandMap,{float:u}=t.MathHelper,g={},f={},m={transform(t,e){let o,n=0;const r=t.length;for(;n<r;)switch(o=t[n],o){case s:case c:m.transformPoints(t,e,n,1),n+=3;break;case h:m.transformPoints(t,e,n,3),n+=7;break;case l:n+=1}},transformPoints(e,o,n,r){for(let a=n+1,i=a+2*r;a<i;a+=2)g.x=e[a],g.y=e[a+1],t.MatrixHelper.toOuterPoint(o,g),e[a]=g.x,e[a+1]=g.y},getMotionPathData(e){let o,n,r,i,u=0,g=[],f=0,m=0,d=0;const p=e.length;for(;f<p;){switch(i=e[f],i){case s:case c:n=e[f+1],r=e[f+2],o=i===c&&f>0?t.PointHelper.getDistanceFrom(m,d,n,r):0,m=n,d=r,f+=3;break;case h:n=e[f+5],r=e[f+6],o=a.getDistance(m,d,e[f+1],e[f+2],e[f+3],e[f+4],n,r),m=n,d=r,f+=7;break;case l:f+=1;default:o=0}g.push(o),u+=o}return{total:u,segments:g,data:e}},getDistancePoint(e,o,n){const{segments:r,data:i}=e;o=t.UnitConvert.number(o,e.total);let u,g,m,d,p,P,_,M,x,b=0,D={},H=0,y=0,C=0,T=0;const v=i.length;for(;H<v;){switch(d=i[H],d){case s:case c:if(g=i[H+1],m=i[H+2],u=r[y],b+u>=o||!e.total)return H||(C=g,T=m),f.x=C,f.y=T,D.x=g,D.y=m,t.PointHelper.getDistancePoint(f,D,o-b,!0),D.rotation=t.PointHelper.getAngle(f,D),D;C=g,T=m,H+=3;break;case h:if(g=i[H+5],m=i[H+6],u=r[y],b+u>=o)return p=i[H+1],P=i[H+2],_=i[H+3],M=i[H+4],x=a.getT(o-b,u,C,T,p,P,_,M,g,m,n),t.BezierHelper.getPointAndSet(x,C,T,p,P,_,M,g,m,D),D.rotation=a.getRotation(x,C,T,p,P,_,M,g,m),D;C=g,T=m,H+=7;break;case l:H+=1;default:u=0}y++,b+=u}return D},getDistancePath(e,o,n){const{segments:r,data:i}=e,g=[];o=t.UnitConvert.number(o,e.total);let m,d,p,P,_,M,x,b,D,H,y=0,C={},T=0,v=0,A=0,U=0;const k=i.length;for(;T<k;){switch(_=i[T],_){case s:case c:if(p=i[T+1],P=i[T+2],m=r[v],y+m>o||!e.total)return T||(A=p,U=P),f.x=A,f.y=U,C.x=p,C.y=P,d=u(o-y),d&&(t.PointHelper.getDistancePoint(f,C,d,!0),g.push(_,C.x,C.y)),g;A=p,U=P,T+=3,g.push(_,A,U);break;case h:if(M=i[T+1],x=i[T+2],b=i[T+3],D=i[T+4],p=i[T+5],P=i[T+6],m=r[v],y+m>o)return d=u(o-y),d&&(H=a.getT(d,m,A,U,M,x,b,D,p,P,n),a.cut(g,H,A,U,M,x,b,D,p,P)),g;A=p,U=P,T+=7,g.push(_,M,x,b,D,p,P);break;case l:T+=1,g.push(_);default:m=0}v++,y+=m}return g}};function d(e){return t.decorateLeafAttr(e,e=>t.attr({set(o){this.__setAttr(e,o),this.__hasMotionPath=this.motionPath||!t.isNull(this.motion),this.__layout.matrixChanged||this.__layout.matrixChange()}}))}t.Plugin.add("motion-path"),t.Transition.register("motion",function(e,o,n,r){return t.isObject(e)&&(e=t.UnitConvert.number(e,r.getMotionTotal())),t.isObject(o)&&(o=t.UnitConvert.number(o,r.getMotionTotal())),t.Transition.number(e||0,o||0,n)}),t.Transition.register("motionRotation",function(e,o,n){return t.Transition.number(e,o,n)});const p=t.UI.prototype,{updateMatrix:P,updateAllMatrix:_}=t.LeafHelper,{updateBounds:M}=t.BranchHelper;function x(e){const{motion:o,leaferIsCreated:n}=e;if(!t.isNull(o)){if(n&&(e.leafer.created=!1),e.motionPath){const t=D(e);t.total&&(e.__.__pathForRender=m.getDistancePath(t,o,e.motionPrecision))}else e.set(e.getMotionPoint(o)),e.__hasAutoLayout||(e.isBranch?(_(e),M(e,e)):P(e));n&&(e.leafer.created=!0)}}function b(t){const{parent:e}=t;if(!t.motionPath&&e){const{children:t}=e;for(let e=0;e<t.length;e++)if(t[e].motionPath)return t[e]}return t}function D(t){const e=t.__;return e.__pathForMotion?e.__pathForMotion:e.__pathForMotion=m.getMotionPathData(t.getPath(!0,!0))}t.UI.addAttr("motionPath",void 0,d),t.UI.addAttr("motionPrecision",1,d),t.UI.addAttr("motion",void 0,d),t.UI.addAttr("motionRotation",!0,d),p.getMotionPathData=function(){return D(b(this))},p.getMotionPoint=function(e){const o=b(this),n=D(o);if(!n.total)return{};const r=m.getDistancePoint(n,e,o.motionPrecision);t.MatrixHelper.toOuterPoint(o.localTransform,r);const{motionRotation:a}=this;return!1===a?delete r.rotation:t.isNumber(a)&&(r.rotation+=a),r},p.getMotionTotal=function(){return this.getMotionPathData().total},p.__updateMotionPath=function(){const e=this.__;if(this.__layout.resized&&e.__pathForMotion&&(e.__pathForMotion=void 0),this.motionPath){let e;const{children:o}=this.parent;for(let n=0;n<o.length;n++)e=o[n],t.isNull(e.motion)||e.__layout.matrixChanged||(e!==this&&e.__extraUpdate(),x(e))}else x(this)},exports.HighBezierHelper=a,exports.HighCurveHelper=m,exports.motionPathType=d;
|
|
2
2
|
//# sourceMappingURL=motion-path.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"motion-path.min.cjs","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":"8CAKA,MAAMA,EAAa,CAAC,YAAc,YAAc,YAAc,YAAc,aACtEC,EAAe,CAAC,YAAc,YAAc,YAAc,YAAc,cAExEC,KAAEA,GAASC,MACXC,cAAEA,GAAkBC,EAAAA,aAEbC,EAAmB,CAE5B,WAAAC,CAAYC,EAAeC,EAAeC,EAAYC,EAAYC,EAAYC,EAAYC,EAAaC,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AG1C,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,EAAAA,aAAaC,aAAakB,EAAKmD,eAAgBD,GAE/C,MAAME,eAAEA,GAAmB5C,KAG3B,OAFuB,IAAnB4C,SAAiCF,EAAMtD,SAClCyD,EAAAA,SAASD,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,EAAAA,OAAO4C,EAAM3C,SAAY2C,EAAM1C,SAASC,gBACrCyC,IAAUhD,MAAMgD,EAAMC,gBAC1BxB,EAAauB,GAGzB,MAAOvB,EAAazB,KACxB"}
|
|
1
|
+
{"version":3,"file":"motion-path.min.cjs","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, MathHelper, PathCommandMap, PointHelper, UnitConvert } from '@leafer-ui/draw'\n\nimport { HighBezierHelper } from './HighBezierHelper'\n\n\nconst { M, L, C, Z } = PathCommandMap, { float } = MathHelper\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, cutDistance: 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 cutDistance = float(motionDistance - total)\n if (cutDistance) {\n PointHelper.getDistancePoint(tempFrom, to, cutDistance, true)\n path.push(command, to.x, to.y)\n }\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 cutDistance = float(motionDistance - total)\n if (cutDistance) {\n t = HighBezierHelper.getT(cutDistance, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision)\n HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY)\n }\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","float","MathHelper","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","cutDistance","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":"8CAKA,MAAMA,EAAa,CAAC,YAAc,YAAc,YAAc,YAAc,aACtEC,EAAe,CAAC,YAAc,YAAc,YAAc,YAAc,cAExEC,KAAEA,GAASC,MACXC,cAAEA,GAAkBC,EAAAA,aAEbC,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,EAAO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AG3B,OAFuB,IAAnB4C,SAAiCF,EAAMvD,SAClC0D,EAAAA,SAASD,KAAiBF,EAAMvD,UAAYyD,GAC9CF,CACX,EAEAzB,EAAGD,eAAiB,WAChB,OAAOhB,KAAK1B,oBAAoBC,KACpC,EAEA0C,EAAG6B,mBAAqB,WACpB,MAAMzG,EAAO2D,KAAK8B,GAGlB,GAFI9B,KAAKM,SAASyC,SAAW1G,EAAKiG,kBAAiBjG,EAAKiG,qBAAkBG,GAEtEzC,KAAKG,WAAY,CACjB,IAAI6C,EACJ,MAAMX,SAAEA,GAAarC,KAAKoC,OAC1B,IAAK,IAAI9G,EAAI,EAAGA,EAAI+G,EAAS9G,OAAQD,IACjC0H,EAAQX,EAAS/G,GACZ8E,EAAAA,OAAO4C,EAAM3C,SAAY2C,EAAM1C,SAASC,gBACrCyC,IAAUhD,MAAMgD,EAAMC,gBAC1BxB,EAAauB,GAGzB,MAAOvB,EAAazB,KACxB"}
|
package/dist/motion-path.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.motionPath=function(t,e){"use strict";const o=[.1488743389,.4333953941,.6794095682,.8650633666,.9739065285],n=[.2955242247,.2692667193,.2190863625,.1494513491,.0666713443],{sqrt:i}=Math,{getDerivative:a}=e.BezierHelper,r={getDistance(t,e,r,s,c,h,u,l,f=1){let g,m,d,P,p,_,M=0,b=f/2;for(let f=0;f<o.length;f++)g=b*(1+o[f]),m=b*(1-o[f]),d=a(g,t,r,c,u),P=a(g,e,s,h,l),p=a(m,t,r,c,u),_=a(m,e,s,h,l),M+=n[f]*(i(d*d+P*P)+i(p*p+_*_));return M*b},getRotation(t,o,n,i,r,s,c,h,u){const l=a(t,o,i,s,h),f=a(t,n,r,c,u);return Math.atan2(f,l)/e.OneRadian},getT(t,e,o,n,i,a,r,c,h,u,l=1){let f=0,g=1,m=t/e,d=l/e/3;if(m>=1)return 1;if(m<=0)return 0;for(;g-f>d;)s(o,n,i,a,r,c,h,u,m)<t?f=m:g=m,m=(f+g)/2;return m},cut(t,o,n,i,a,r,s,c,h,u){const l=1-o,f=l*n+o*a,g=l*i+o*r,m=l*a+o*s,d=l*r+o*c,P=l*f+o*m,p=l*g+o*d,_=l*P+o*(l*m+o*(l*s+o*h)),M=l*p+o*(l*d+o*(l*c+o*u));t.push(e.PathCommandMap.C,f,g,P,p,_,M)}},{getDistance:s}=r,{M:c,L:h,C:u,Z:l}=e.PathCommandMap,f=
|
|
1
|
+
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.motionPath=function(t,e){"use strict";const o=[.1488743389,.4333953941,.6794095682,.8650633666,.9739065285],n=[.2955242247,.2692667193,.2190863625,.1494513491,.0666713443],{sqrt:i}=Math,{getDerivative:a}=e.BezierHelper,r={getDistance(t,e,r,s,c,h,u,l,f=1){let g,m,d,P,p,_,M=0,b=f/2;for(let f=0;f<o.length;f++)g=b*(1+o[f]),m=b*(1-o[f]),d=a(g,t,r,c,u),P=a(g,e,s,h,l),p=a(m,t,r,c,u),_=a(m,e,s,h,l),M+=n[f]*(i(d*d+P*P)+i(p*p+_*_));return M*b},getRotation(t,o,n,i,r,s,c,h,u){const l=a(t,o,i,s,h),f=a(t,n,r,c,u);return Math.atan2(f,l)/e.OneRadian},getT(t,e,o,n,i,a,r,c,h,u,l=1){let f=0,g=1,m=t/e,d=l/e/3;if(m>=1)return 1;if(m<=0)return 0;for(;g-f>d;)s(o,n,i,a,r,c,h,u,m)<t?f=m:g=m,m=(f+g)/2;return m},cut(t,o,n,i,a,r,s,c,h,u){const l=1-o,f=l*n+o*a,g=l*i+o*r,m=l*a+o*s,d=l*r+o*c,P=l*f+o*m,p=l*g+o*d,_=l*P+o*(l*m+o*(l*s+o*h)),M=l*p+o*(l*d+o*(l*c+o*u));t.push(e.PathCommandMap.C,f,g,P,p,_,M)}},{getDistance:s}=r,{M:c,L:h,C:u,Z:l}=e.PathCommandMap,{float:f}=e.MathHelper,g={},m={},d={transform(t,e){let o,n=0;const i=t.length;for(;n<i;)switch(o=t[n],o){case c:case h:d.transformPoints(t,e,n,1),n+=3;break;case u:d.transformPoints(t,e,n,3),n+=7;break;case l:n+=1}},transformPoints(t,o,n,i){for(let a=n+1,r=a+2*i;a<r;a+=2)g.x=t[a],g.y=t[a+1],e.MatrixHelper.toOuterPoint(o,g),t[a]=g.x,t[a+1]=g.y},getMotionPathData(t){let o,n,i,a,s=0,f=[],g=0,m=0,d=0;const P=t.length;for(;g<P;){switch(a=t[g],a){case c:case h:n=t[g+1],i=t[g+2],o=a===h&&g>0?e.PointHelper.getDistanceFrom(m,d,n,i):0,m=n,d=i,g+=3;break;case u:n=t[g+5],i=t[g+6],o=r.getDistance(m,d,t[g+1],t[g+2],t[g+3],t[g+4],n,i),m=n,d=i,g+=7;break;case l:g+=1;default:o=0}f.push(o),s+=o}return{total:s,segments:f,data:t}},getDistancePoint(t,o,n){const{segments:i,data:a}=t;o=e.UnitConvert.number(o,t.total);let s,f,g,d,P,p,_,M,b,x=0,D={},H=0,y=0,C=0,T=0;const U=a.length;for(;H<U;){switch(d=a[H],d){case c:case h:if(f=a[H+1],g=a[H+2],s=i[y],x+s>=o||!t.total)return H||(C=f,T=g),m.x=C,m.y=T,D.x=f,D.y=g,e.PointHelper.getDistancePoint(m,D,o-x,!0),D.rotation=e.PointHelper.getAngle(m,D),D;C=f,T=g,H+=3;break;case u:if(f=a[H+5],g=a[H+6],s=i[y],x+s>=o)return P=a[H+1],p=a[H+2],_=a[H+3],M=a[H+4],b=r.getT(o-x,s,C,T,P,p,_,M,f,g,n),e.BezierHelper.getPointAndSet(b,C,T,P,p,_,M,f,g,D),D.rotation=r.getRotation(b,C,T,P,p,_,M,f,g),D;C=f,T=g,H+=7;break;case l:H+=1;default:s=0}y++,x+=s}return D},getDistancePath(t,o,n){const{segments:i,data:a}=t,s=[];o=e.UnitConvert.number(o,t.total);let g,d,P,p,_,M,b,x,D,H,y=0,C={},T=0,U=0,v=0,A=0;const I=a.length;for(;T<I;){switch(_=a[T],_){case c:case h:if(P=a[T+1],p=a[T+2],g=i[U],y+g>o||!t.total)return T||(v=P,A=p),m.x=v,m.y=A,C.x=P,C.y=p,d=f(o-y),d&&(e.PointHelper.getDistancePoint(m,C,d,!0),s.push(_,C.x,C.y)),s;v=P,A=p,T+=3,s.push(_,v,A);break;case u:if(M=a[T+1],b=a[T+2],x=a[T+3],D=a[T+4],P=a[T+5],p=a[T+6],g=i[U],y+g>o)return d=f(o-y),d&&(H=r.getT(d,g,v,A,M,b,x,D,P,p,n),r.cut(s,H,v,A,M,b,x,D,P,p)),s;v=P,A=p,T+=7,s.push(_,M,b,x,D,P,p);break;case l:T+=1,s.push(_);default:g=0}U++,y+=g}return s}};function P(t){return e.decorateLeafAttr(t,t=>e.attr({set(o){this.__setAttr(t,o),this.__hasMotionPath=this.motionPath||!e.isNull(this.motion),this.__layout.matrixChanged||this.__layout.matrixChange()}}))}e.Plugin.add("motion-path"),e.Transition.register("motion",function(t,o,n,i){return e.isObject(t)&&(t=e.UnitConvert.number(t,i.getMotionTotal())),e.isObject(o)&&(o=e.UnitConvert.number(o,i.getMotionTotal())),e.Transition.number(t||0,o||0,n)}),e.Transition.register("motionRotation",function(t,o,n){return e.Transition.number(t,o,n)});const p=e.UI.prototype,{updateMatrix:_,updateAllMatrix:M}=e.LeafHelper,{updateBounds:b}=e.BranchHelper;function x(t){const{motion:o,leaferIsCreated:n}=t;if(!e.isNull(o)){if(n&&(t.leafer.created=!1),t.motionPath){const e=H(t);e.total&&(t.__.__pathForRender=d.getDistancePath(e,o,t.motionPrecision))}else t.set(t.getMotionPoint(o)),t.__hasAutoLayout||(t.isBranch?(M(t),b(t,t)):_(t));n&&(t.leafer.created=!0)}}function D(t){const{parent:e}=t;if(!t.motionPath&&e){const{children:t}=e;for(let e=0;e<t.length;e++)if(t[e].motionPath)return t[e]}return t}function H(t){const e=t.__;return e.__pathForMotion?e.__pathForMotion:e.__pathForMotion=d.getMotionPathData(t.getPath(!0,!0))}return e.UI.addAttr("motionPath",void 0,P),e.UI.addAttr("motionPrecision",1,P),e.UI.addAttr("motion",void 0,P),e.UI.addAttr("motionRotation",!0,P),p.getMotionPathData=function(){return H(D(this))},p.getMotionPoint=function(t){const o=D(this),n=H(o);if(!n.total)return{};const i=d.getDistancePoint(n,t,o.motionPrecision);e.MatrixHelper.toOuterPoint(o.localTransform,i);const{motionRotation:a}=this;return!1===a?delete i.rotation:e.isNumber(a)&&(i.rotation+=a),i},p.getMotionTotal=function(){return this.getMotionPathData().total},p.__updateMotionPath=function(){const t=this.__;if(this.__layout.resized&&t.__pathForMotion&&(t.__pathForMotion=void 0),this.motionPath){let t;const{children:o}=this.parent;for(let n=0;n<o.length;n++)t=o[n],e.isNull(t.motion)||t.__layout.matrixChanged||(t!==this&&t.__extraUpdate(),x(t))}else x(this)},t.HighBezierHelper=r,t.HighCurveHelper=d,t.motionPathType=P,t}({},LeaferUI);
|
|
2
2
|
//# sourceMappingURL=motion-path.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"motion-path.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":"oFAKA,MAAMA,EAAa,CAAC,YAAc,YAAc,YAAc,YAAc,aACtEC,EAAe,CAAC,YAAc,YAAc,YAAc,YAAc,cAExEC,KAAEA,GAASC,MACXC,cAAEA,GAAkBC,EAAAA,aAEbC,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,EAAAA,SAChC,EAEA,IAAAC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,SAASC,gBACrCyC,IAAUhD,MAAMgD,EAAMC,gBAC1BxB,EAAauB,GAGzB,MAAOvB,EAAazB,KACxB"}
|
|
1
|
+
{"version":3,"file":"motion-path.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, MathHelper, PathCommandMap, PointHelper, UnitConvert } from '@leafer-ui/draw'\n\nimport { HighBezierHelper } from './HighBezierHelper'\n\n\nconst { M, L, C, Z } = PathCommandMap, { float } = MathHelper\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, cutDistance: 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 cutDistance = float(motionDistance - total)\n if (cutDistance) {\n PointHelper.getDistancePoint(tempFrom, to, cutDistance, true)\n path.push(command, to.x, to.y)\n }\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 cutDistance = float(motionDistance - total)\n if (cutDistance) {\n t = HighBezierHelper.getT(cutDistance, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision)\n HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY)\n }\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","float","MathHelper","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","cutDistance","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":"oFAKA,MAAMA,EAAa,CAAC,YAAc,YAAc,YAAc,YAAc,aACtEC,EAAe,CAAC,YAAc,YAAc,YAAc,YAAc,cAExEC,KAAEA,GAASC,MACXC,cAAEA,GAAkBC,EAAAA,aAEbC,EAAmB,CAE5B,WAAAC,CAAYC,EAAeC,EAAeC,EAAYC,EAAYC,EAAYC,EAAYC,EAAaC,EAAaC,EAAI,GACpH,IAAk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,EAAWhD,GAChCyB,EAAAA,GAAGsB,QAAQ,kBAAkB,EAAM/C,GAGnCwB,EAAG3C,kBAAoB,WACnB,OAAOA,EAAkB6D,EAAcnC,MAC3C,EAEAiB,EAAGe,eAAiB,SAAUnD,GAC1B,MAAMU,EAAO4C,EAAcnC,MACrB3D,EAAOiC,EAAkBiB,GAC/B,IAAKlD,EAAKkC,MAAO,MAAO,CAAA,EAExB,MAAMmE,EAAQjF,EAAgBkB,iBAAiBtC,EAAMwC,EAAgBU,EAAKT,iBAC1EV,EAAAA,aAAaC,aAAakB,EAAKoD,eAAgBD,GAE/C,MAAME,eAAEA,GAAmB5C,KAG3B,OAFuB,IAAnB4C,SAAiCF,EAAMvD,SAClC0D,EAAAA,SAASD,KAAiBF,EAAMvD,UAAYyD,GAC9CF,CACX,EAEAzB,EAAGD,eAAiB,WAChB,OAAOhB,KAAK1B,oBAAoBC,KACpC,EAEA0C,EAAG6B,mBAAqB,WACpB,MAAMzG,EAAO2D,KAAK8B,GAGlB,GAFI9B,KAAKM,SAASyC,SAAW1G,EAAKiG,kBAAiBjG,EAAKiG,qBAAkBG,GAEtEzC,KAAKG,WAAY,CACjB,IAAI6C,EACJ,MAAMX,SAAEA,GAAarC,KAAKoC,OAC1B,IAAK,IAAI9G,EAAI,EAAGA,EAAI+G,EAAS9G,OAAQD,IACjC0H,EAAQX,EAAS/G,GACZ8E,EAAAA,OAAO4C,EAAM3C,SAAY2C,EAAM1C,SAASC,gBACrCyC,IAAUhD,MAAMgD,EAAMC,gBAC1BxB,EAAauB,GAGzB,MAAOvB,EAAazB,KACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/motion-path",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.2",
|
|
4
4
|
"description": "@leafer-in/motion-path",
|
|
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/draw": "^1.12.
|
|
38
|
-
"@leafer-ui/interface": "^1.12.
|
|
39
|
-
"@leafer-in/interface": "^1.12.
|
|
37
|
+
"@leafer-ui/draw": "^1.12.2",
|
|
38
|
+
"@leafer-ui/interface": "^1.12.2",
|
|
39
|
+
"@leafer-in/interface": "^1.12.2"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/HighCurveHelper.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IMatrixData, IPathCommandData, IMotionPathData, IRotationPointData, IPointData, IUnitData } from '@leafer-ui/interface'
|
|
2
|
-
import { BezierHelper, MatrixHelper, PathCommandMap, PointHelper, UnitConvert } from '@leafer-ui/draw'
|
|
2
|
+
import { BezierHelper, MatrixHelper, MathHelper, PathCommandMap, PointHelper, UnitConvert } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { HighBezierHelper } from './HighBezierHelper'
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
const { M, L, C, Z } = PathCommandMap
|
|
7
|
+
const { M, L, C, Z } = PathCommandMap, { float } = MathHelper
|
|
8
8
|
const tempPoint = {} as IPointData, tempFrom = {} as IPointData
|
|
9
9
|
|
|
10
10
|
export const HighCurveHelper = {
|
|
@@ -149,7 +149,7 @@ export const HighCurveHelper = {
|
|
|
149
149
|
const { segments, data } = distanceData, path: IPathCommandData = []
|
|
150
150
|
motionDistance = UnitConvert.number(motionDistance, distanceData.total)
|
|
151
151
|
|
|
152
|
-
let total = 0, distance: number, to = {} as IRotationPointData
|
|
152
|
+
let total = 0, distance: number, cutDistance: number, to = {} as IRotationPointData
|
|
153
153
|
let i = 0, index = 0, x: number = 0, y: number = 0, toX: number, toY: number, command: number
|
|
154
154
|
let x1: number, y1: number, x2: number, y2: number, t: number
|
|
155
155
|
|
|
@@ -163,14 +163,17 @@ export const HighCurveHelper = {
|
|
|
163
163
|
toY = data[i + 2]
|
|
164
164
|
distance = segments[index]
|
|
165
165
|
|
|
166
|
-
if (total + distance
|
|
166
|
+
if (total + distance > motionDistance || !distanceData.total) {
|
|
167
167
|
if (!i) x = toX, y = toY // first M
|
|
168
168
|
tempFrom.x = x
|
|
169
169
|
tempFrom.y = y
|
|
170
170
|
to.x = toX
|
|
171
171
|
to.y = toY
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
cutDistance = float(motionDistance - total)
|
|
173
|
+
if (cutDistance) {
|
|
174
|
+
PointHelper.getDistancePoint(tempFrom, to, cutDistance, true)
|
|
175
|
+
path.push(command, to.x, to.y)
|
|
176
|
+
}
|
|
174
177
|
return path
|
|
175
178
|
}
|
|
176
179
|
|
|
@@ -185,9 +188,12 @@ export const HighCurveHelper = {
|
|
|
185
188
|
toY = data[i + 6]
|
|
186
189
|
distance = segments[index]
|
|
187
190
|
|
|
188
|
-
if (total + distance
|
|
189
|
-
|
|
190
|
-
|
|
191
|
+
if (total + distance > motionDistance) {
|
|
192
|
+
cutDistance = float(motionDistance - total)
|
|
193
|
+
if (cutDistance) {
|
|
194
|
+
t = HighBezierHelper.getT(cutDistance, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision)
|
|
195
|
+
HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY)
|
|
196
|
+
}
|
|
191
197
|
return path
|
|
192
198
|
}
|
|
193
199
|
|