@leafer-in/motion-path 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/motion-path.cjs +50 -38
- package/dist/motion-path.esm.js +51 -39
- package/dist/motion-path.esm.min.js +1 -1
- package/dist/motion-path.js +50 -38
- package/dist/motion-path.min.cjs +1 -1
- package/dist/motion-path.min.js +1 -1
- package/package.json +9 -5
- package/src/index.ts +52 -39
package/dist/motion-path.cjs
CHANGED
|
@@ -235,28 +235,30 @@ draw.Transition.register('motion', function (from, to, t, target) {
|
|
|
235
235
|
to = draw.UnitConvert.number(to, target.getMotionTotal());
|
|
236
236
|
return draw.Transition.number(from, to, t);
|
|
237
237
|
});
|
|
238
|
+
draw.Transition.register('motionRotation', function (from, to, t) {
|
|
239
|
+
return draw.Transition.number(from, to, t);
|
|
240
|
+
});
|
|
238
241
|
const ui = draw.UI.prototype;
|
|
242
|
+
const { updateMatrix, updateAllMatrix } = draw.LeafHelper;
|
|
243
|
+
const { updateBounds } = draw.BranchHelper;
|
|
239
244
|
motionPathType()(ui, 'motionPath');
|
|
240
245
|
motionPathType()(ui, 'motion');
|
|
241
246
|
motionPathType(true)(ui, 'motionRotation');
|
|
242
247
|
ui.getMotionPathData = function () {
|
|
243
|
-
|
|
244
|
-
if (!this.motionPath && parent) {
|
|
245
|
-
const { children } = parent;
|
|
246
|
-
for (let i = 0; i < children.length; i++) {
|
|
247
|
-
if (children[i].motionPath)
|
|
248
|
-
return children[i].getMotionPathData();
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
const data = this.__;
|
|
252
|
-
if (data.__pathForMotion)
|
|
253
|
-
return data.__pathForMotion;
|
|
254
|
-
return data.__pathForMotion = HighCurveHelper.getMotionPathData(this.getPath(true, true));
|
|
248
|
+
return getMotionPathData(getMotionPath(this));
|
|
255
249
|
};
|
|
256
250
|
ui.getMotionPoint = function (motionDistance) {
|
|
257
|
-
const
|
|
251
|
+
const path = getMotionPath(this);
|
|
252
|
+
const data = getMotionPathData(path);
|
|
253
|
+
if (!data.total)
|
|
254
|
+
return {};
|
|
258
255
|
const point = HighCurveHelper.getDistancePoint(data, motionDistance);
|
|
259
|
-
draw.MatrixHelper.toOuterPoint(
|
|
256
|
+
draw.MatrixHelper.toOuterPoint(path.localTransform, point);
|
|
257
|
+
const { motionRotation } = this;
|
|
258
|
+
if (motionRotation === false)
|
|
259
|
+
delete point.rotation;
|
|
260
|
+
else if (typeof motionRotation === 'number')
|
|
261
|
+
point.rotation += motionRotation;
|
|
260
262
|
return point;
|
|
261
263
|
};
|
|
262
264
|
ui.getMotionTotal = function () {
|
|
@@ -268,48 +270,58 @@ ui.__updateMotionPath = function () {
|
|
|
268
270
|
data.__pathForMotion = undefined;
|
|
269
271
|
if (this.motionPath) {
|
|
270
272
|
let child;
|
|
271
|
-
const { children } = this.parent;
|
|
273
|
+
const { children } = this.parent, { leaferIsReady } = this;
|
|
272
274
|
for (let i = 0; i < children.length; i++) {
|
|
273
275
|
child = children[i];
|
|
274
|
-
if (!draw.isNull(child.motion))
|
|
276
|
+
if (!draw.isNull(child.motion) && !child.__layout.matrixChanged) {
|
|
277
|
+
if (leaferIsReady && child !== this)
|
|
278
|
+
this.leafer.layouter.addExtra(child);
|
|
275
279
|
updateMotion(child);
|
|
280
|
+
}
|
|
276
281
|
}
|
|
277
282
|
}
|
|
278
|
-
else
|
|
283
|
+
else
|
|
279
284
|
updateMotion(this);
|
|
280
|
-
}
|
|
281
285
|
};
|
|
282
286
|
function updateMotion(leaf) {
|
|
283
|
-
const { motion,
|
|
287
|
+
const { motion, leaferIsCreated } = leaf;
|
|
284
288
|
if (draw.isNull(motion))
|
|
285
289
|
return;
|
|
290
|
+
if (leaferIsCreated)
|
|
291
|
+
leaf.leafer.created = false;
|
|
286
292
|
if (leaf.motionPath) {
|
|
287
|
-
const data =
|
|
293
|
+
const data = getMotionPathData(leaf);
|
|
288
294
|
if (data.total)
|
|
289
295
|
leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion);
|
|
290
296
|
}
|
|
291
297
|
else {
|
|
292
|
-
|
|
293
|
-
|
|
298
|
+
leaf.set(leaf.getMotionPoint(motion));
|
|
299
|
+
if (!leaf.__hasAutoLayout) {
|
|
300
|
+
if (leaf.isBranch)
|
|
301
|
+
updateAllMatrix(leaf), updateBounds(leaf, leaf);
|
|
302
|
+
else
|
|
303
|
+
updateMatrix(leaf);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (leaferIsCreated)
|
|
307
|
+
leaf.leafer.created = true;
|
|
308
|
+
}
|
|
309
|
+
function getMotionPath(leaf) {
|
|
310
|
+
const { parent } = leaf;
|
|
311
|
+
if (!leaf.motionPath && parent) {
|
|
312
|
+
const { children } = parent;
|
|
294
313
|
for (let i = 0; i < children.length; i++) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const data = child.getMotionPathData();
|
|
298
|
-
if (!data.total)
|
|
299
|
-
return;
|
|
300
|
-
const point = child.getMotionPoint(motion);
|
|
301
|
-
if (motionRotation === false)
|
|
302
|
-
delete point.rotation;
|
|
303
|
-
else {
|
|
304
|
-
point.rotation += child.rotation;
|
|
305
|
-
if (typeof motionRotation === 'number')
|
|
306
|
-
point.rotation += motionRotation;
|
|
307
|
-
}
|
|
308
|
-
leaf.set(point);
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
314
|
+
if (children[i].motionPath)
|
|
315
|
+
return children[i];
|
|
311
316
|
}
|
|
312
317
|
}
|
|
318
|
+
return leaf;
|
|
319
|
+
}
|
|
320
|
+
function getMotionPathData(leaf) {
|
|
321
|
+
const data = leaf.__;
|
|
322
|
+
if (data.__pathForMotion)
|
|
323
|
+
return data.__pathForMotion;
|
|
324
|
+
return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
|
|
313
325
|
}
|
|
314
326
|
|
|
315
327
|
exports.HighBezierHelper = HighBezierHelper;
|
package/dist/motion-path.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PathCommandMap, MatrixHelper, PointHelper, UnitConvert, BezierHelper, decorateLeafAttr, attr, isNull, Transition, UI } from '@leafer-ui/draw';
|
|
1
|
+
import { PathCommandMap, MatrixHelper, PointHelper, UnitConvert, BezierHelper, decorateLeafAttr, attr, isNull, Transition, UI, LeafHelper, BranchHelper } from '@leafer-ui/draw';
|
|
2
2
|
|
|
3
3
|
const gaussNodes = [0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.9739065285];
|
|
4
4
|
const gaussWeights = [0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443];
|
|
@@ -233,28 +233,30 @@ Transition.register('motion', function (from, to, t, target) {
|
|
|
233
233
|
to = UnitConvert.number(to, target.getMotionTotal());
|
|
234
234
|
return Transition.number(from, to, t);
|
|
235
235
|
});
|
|
236
|
+
Transition.register('motionRotation', function (from, to, t) {
|
|
237
|
+
return Transition.number(from, to, t);
|
|
238
|
+
});
|
|
236
239
|
const ui = UI.prototype;
|
|
240
|
+
const { updateMatrix, updateAllMatrix } = LeafHelper;
|
|
241
|
+
const { updateBounds } = BranchHelper;
|
|
237
242
|
motionPathType()(ui, 'motionPath');
|
|
238
243
|
motionPathType()(ui, 'motion');
|
|
239
244
|
motionPathType(true)(ui, 'motionRotation');
|
|
240
245
|
ui.getMotionPathData = function () {
|
|
241
|
-
|
|
242
|
-
if (!this.motionPath && parent) {
|
|
243
|
-
const { children } = parent;
|
|
244
|
-
for (let i = 0; i < children.length; i++) {
|
|
245
|
-
if (children[i].motionPath)
|
|
246
|
-
return children[i].getMotionPathData();
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
const data = this.__;
|
|
250
|
-
if (data.__pathForMotion)
|
|
251
|
-
return data.__pathForMotion;
|
|
252
|
-
return data.__pathForMotion = HighCurveHelper.getMotionPathData(this.getPath(true, true));
|
|
246
|
+
return getMotionPathData(getMotionPath(this));
|
|
253
247
|
};
|
|
254
248
|
ui.getMotionPoint = function (motionDistance) {
|
|
255
|
-
const
|
|
249
|
+
const path = getMotionPath(this);
|
|
250
|
+
const data = getMotionPathData(path);
|
|
251
|
+
if (!data.total)
|
|
252
|
+
return {};
|
|
256
253
|
const point = HighCurveHelper.getDistancePoint(data, motionDistance);
|
|
257
|
-
MatrixHelper.toOuterPoint(
|
|
254
|
+
MatrixHelper.toOuterPoint(path.localTransform, point);
|
|
255
|
+
const { motionRotation } = this;
|
|
256
|
+
if (motionRotation === false)
|
|
257
|
+
delete point.rotation;
|
|
258
|
+
else if (typeof motionRotation === 'number')
|
|
259
|
+
point.rotation += motionRotation;
|
|
258
260
|
return point;
|
|
259
261
|
};
|
|
260
262
|
ui.getMotionTotal = function () {
|
|
@@ -266,48 +268,58 @@ ui.__updateMotionPath = function () {
|
|
|
266
268
|
data.__pathForMotion = undefined;
|
|
267
269
|
if (this.motionPath) {
|
|
268
270
|
let child;
|
|
269
|
-
const { children } = this.parent;
|
|
271
|
+
const { children } = this.parent, { leaferIsReady } = this;
|
|
270
272
|
for (let i = 0; i < children.length; i++) {
|
|
271
273
|
child = children[i];
|
|
272
|
-
if (!isNull(child.motion))
|
|
274
|
+
if (!isNull(child.motion) && !child.__layout.matrixChanged) {
|
|
275
|
+
if (leaferIsReady && child !== this)
|
|
276
|
+
this.leafer.layouter.addExtra(child);
|
|
273
277
|
updateMotion(child);
|
|
278
|
+
}
|
|
274
279
|
}
|
|
275
280
|
}
|
|
276
|
-
else
|
|
281
|
+
else
|
|
277
282
|
updateMotion(this);
|
|
278
|
-
}
|
|
279
283
|
};
|
|
280
284
|
function updateMotion(leaf) {
|
|
281
|
-
const { motion,
|
|
285
|
+
const { motion, leaferIsCreated } = leaf;
|
|
282
286
|
if (isNull(motion))
|
|
283
287
|
return;
|
|
288
|
+
if (leaferIsCreated)
|
|
289
|
+
leaf.leafer.created = false;
|
|
284
290
|
if (leaf.motionPath) {
|
|
285
|
-
const data =
|
|
291
|
+
const data = getMotionPathData(leaf);
|
|
286
292
|
if (data.total)
|
|
287
293
|
leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion);
|
|
288
294
|
}
|
|
289
295
|
else {
|
|
290
|
-
|
|
291
|
-
|
|
296
|
+
leaf.set(leaf.getMotionPoint(motion));
|
|
297
|
+
if (!leaf.__hasAutoLayout) {
|
|
298
|
+
if (leaf.isBranch)
|
|
299
|
+
updateAllMatrix(leaf), updateBounds(leaf, leaf);
|
|
300
|
+
else
|
|
301
|
+
updateMatrix(leaf);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (leaferIsCreated)
|
|
305
|
+
leaf.leafer.created = true;
|
|
306
|
+
}
|
|
307
|
+
function getMotionPath(leaf) {
|
|
308
|
+
const { parent } = leaf;
|
|
309
|
+
if (!leaf.motionPath && parent) {
|
|
310
|
+
const { children } = parent;
|
|
292
311
|
for (let i = 0; i < children.length; i++) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const data = child.getMotionPathData();
|
|
296
|
-
if (!data.total)
|
|
297
|
-
return;
|
|
298
|
-
const point = child.getMotionPoint(motion);
|
|
299
|
-
if (motionRotation === false)
|
|
300
|
-
delete point.rotation;
|
|
301
|
-
else {
|
|
302
|
-
point.rotation += child.rotation;
|
|
303
|
-
if (typeof motionRotation === 'number')
|
|
304
|
-
point.rotation += motionRotation;
|
|
305
|
-
}
|
|
306
|
-
leaf.set(point);
|
|
307
|
-
break;
|
|
308
|
-
}
|
|
312
|
+
if (children[i].motionPath)
|
|
313
|
+
return children[i];
|
|
309
314
|
}
|
|
310
315
|
}
|
|
316
|
+
return leaf;
|
|
317
|
+
}
|
|
318
|
+
function getMotionPathData(leaf) {
|
|
319
|
+
const data = leaf.__;
|
|
320
|
+
if (data.__pathForMotion)
|
|
321
|
+
return data.__pathForMotion;
|
|
322
|
+
return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
|
|
311
323
|
}
|
|
312
324
|
|
|
313
325
|
export { HighBezierHelper, HighCurveHelper, motionPathType };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PathCommandMap as t,MatrixHelper as
|
|
1
|
+
import{PathCommandMap as t,MatrixHelper as e,PointHelper as o,UnitConvert as n,BezierHelper as a,decorateLeafAttr as r,attr as i,isNull as s,Transition as c,UI as h,LeafHelper as u,BranchHelper as l}from"@leafer-ui/draw";const f=[.1488743389,.4333953941,.6794095682,.8650633666,.9739065285],g=[.2955242247,.2692667193,.2190863625,.1494513491,.0666713443],{sqrt:m}=Math,_={getDistance(t,e,o,n,a,r,i,s){let c,h,u,l,_,P,p=0;for(let M=0;M<f.length;M++)c=.5*(1+f[M]),h=.5*(1-f[M]),u=d(c,t,o,a,i),l=d(c,e,n,r,s),_=d(h,t,o,a,i),P=d(h,e,n,r,s),p+=g[M]*(m(u*u+l*l)+m(_*_+P*P));return.5*p},getDerivative(t,e,o,n,a){const r=1-t;return 3*r*r*(o-e)+6*r*t*(n-o)+3*t*t*(a-n)},cut(e,o,n,a,r,i,s,c,h,u){const l=1-o,f=l*n+o*r,g=l*a+o*i,m=l*r+o*s,_=l*i+o*c,d=l*f+o*m,P=l*g+o*_,p=l*d+o*(l*m+o*(l*s+o*h)),M=l*P+o*(l*_+o*(l*c+o*u));e.push(t.C,f,g,d,P,p,M)}},{getDerivative:d}=_,{M:P,L:p,C:M,Z:y}=t,b={},x={},D={transform(t,e){let o,n=0;const a=t.length;for(;n<a;)switch(o=t[n],o){case P:case p:D.transformPoints(t,e,n,1),n+=3;break;case M:D.transformPoints(t,e,n,3),n+=7;break;case y:n+=1}},transformPoints(t,o,n,a){for(let r=n+1,i=r+2*a;r<i;r+=2)b.x=t[r],b.y=t[r+1],e.toOuterPoint(o,b),t[r]=b.x,t[r+1]=b.y},getMotionPathData(t){let e,n,a,r,i=0,s=[],c=0,h=0,u=0;const l=t.length;for(;c<l;){switch(r=t[c],r){case P:case p:n=t[c+1],a=t[c+2],e=r===p&&c>0?o.getDistanceFrom(h,u,n,a):0,h=n,u=a,c+=3;break;case M:n=t[c+5],a=t[c+6],e=_.getDistance(h,u,t[c+1],t[c+2],t[c+3],t[c+4],n,a),h=n,u=a,c+=7;break;case y:c+=1;default:e=0}s.push(e),i+=e}return{total:i,segments:s,data:t}},getDistancePoint(t,e){const{segments:r,data:i}=t;e=n.number(e,t.total);let s,c,h,u,l=0,f={},g=0,m=0,_=0,d=0;const b=i.length;for(;g<b;){switch(u=i[g],u){case P:case p:if(c=i[g+1],h=i[g+2],s=r[m],l+s>e||!t.total)return g||(_=c,d=h),x.x=_,x.y=d,f.x=c,f.y=h,o.getDistancePoint(x,f,e-l,!0),f.rotation=o.getAngle(x,f),f;_=c,d=h,g+=3;break;case M:if(c=i[g+5],h=i[g+6],s=r[m],l+s>e){const t=i[g+1],n=i[g+2],r=i[g+3],u=i[g+4];return e-=l,a.getPointAndSet(e/s,_,d,t,n,r,u,c,h,f),a.getPointAndSet(Math.max(0,e-.1)/s,_,d,t,n,r,u,c,h,x),f.rotation=o.getAngle(x,f),f}_=c,d=h,g+=7;break;case y:g+=1;default:s=0}m++,l+=s}return f},getDistancePath(t,e){const{segments:a,data:r}=t,i=[];e=n.number(e,t.total);let s,c,h,u,l=0,f={},g=0,m=0,d=0,b=0;const D=r.length;for(;g<D;){switch(u=r[g],u){case P:case p:if(c=r[g+1],h=r[g+2],s=a[m],l+s>e||!t.total)return g||(d=c,b=h),x.x=d,x.y=b,f.x=c,f.y=h,o.getDistancePoint(x,f,e-l,!0),i.push(u,f.x,f.y),i;d=c,b=h,g+=3,i.push(u,d,b);break;case M:const n=r[g+1],D=r[g+2],k=r[g+3],A=r[g+4];if(c=r[g+5],h=r[g+6],s=a[m],l+s>e)return _.cut(i,(e-l)/s,d,b,n,D,k,A,c,h),i;d=c,b=h,g+=7,i.push(u,n,D,k,A,c,h);break;case y:g+=1,i.push(u);default:s=0}m++,l+=s}return i}};function k(t){return r(t,(t=>i({set(e){this.__setAttr(t,e),this.__hasMotionPath=this.motionPath||!s(this.motion),this.__layout.matrixChanged||this.__layout.matrixChange()}})))}c.register("motion",(function(t,e,o,a){return t?"object"==typeof t&&(t=n.number(t,a.getMotionTotal())):t=0,e?"object"==typeof e&&(e=n.number(e,a.getMotionTotal())):e=0,c.number(t,e,o)})),c.register("motionRotation",(function(t,e,o){return c.number(t,e,o)}));const A=h.prototype,{updateMatrix:F,updateAllMatrix:C}=u,{updateBounds:v}=l;function w(t){const{motion:e,leaferIsCreated:o}=t;if(!s(e)){if(o&&(t.leafer.created=!1),t.motionPath){const o=T(t);o.total&&(t.__.__pathForRender=D.getDistancePath(o,e))}else t.set(t.getMotionPoint(e)),t.__hasAutoLayout||(t.isBranch?(C(t),v(t,t)):F(t));o&&(t.leafer.created=!0)}}function R(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 T(t){const e=t.__;return e.__pathForMotion?e.__pathForMotion:e.__pathForMotion=D.getMotionPathData(t.getPath(!0,!0))}k()(A,"motionPath"),k()(A,"motion"),k(!0)(A,"motionRotation"),A.getMotionPathData=function(){return T(R(this))},A.getMotionPoint=function(t){const o=R(this),n=T(o);if(!n.total)return{};const a=D.getDistancePoint(n,t);e.toOuterPoint(o.localTransform,a);const{motionRotation:r}=this;return!1===r?delete a.rotation:"number"==typeof r&&(a.rotation+=r),a},A.getMotionTotal=function(){return this.getMotionPathData().total},A.__updateMotionPath=function(){const t=this.__;if(this.__layout.resized&&t.__pathForMotion&&(t.__pathForMotion=void 0),this.motionPath){let t;const{children:e}=this.parent,{leaferIsReady:o}=this;for(let n=0;n<e.length;n++)t=e[n],s(t.motion)||t.__layout.matrixChanged||(o&&t!==this&&this.leafer.layouter.addExtra(t),w(t))}else w(this)};export{_ as HighBezierHelper,D as HighCurveHelper,k as motionPathType};
|
package/dist/motion-path.js
CHANGED
|
@@ -235,28 +235,30 @@ this.LeaferIN.motionPath = (function (exports, draw) {
|
|
|
235
235
|
to = draw.UnitConvert.number(to, target.getMotionTotal());
|
|
236
236
|
return draw.Transition.number(from, to, t);
|
|
237
237
|
});
|
|
238
|
+
draw.Transition.register('motionRotation', function (from, to, t) {
|
|
239
|
+
return draw.Transition.number(from, to, t);
|
|
240
|
+
});
|
|
238
241
|
const ui = draw.UI.prototype;
|
|
242
|
+
const { updateMatrix, updateAllMatrix } = draw.LeafHelper;
|
|
243
|
+
const { updateBounds } = draw.BranchHelper;
|
|
239
244
|
motionPathType()(ui, 'motionPath');
|
|
240
245
|
motionPathType()(ui, 'motion');
|
|
241
246
|
motionPathType(true)(ui, 'motionRotation');
|
|
242
247
|
ui.getMotionPathData = function () {
|
|
243
|
-
|
|
244
|
-
if (!this.motionPath && parent) {
|
|
245
|
-
const { children } = parent;
|
|
246
|
-
for (let i = 0; i < children.length; i++) {
|
|
247
|
-
if (children[i].motionPath)
|
|
248
|
-
return children[i].getMotionPathData();
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
const data = this.__;
|
|
252
|
-
if (data.__pathForMotion)
|
|
253
|
-
return data.__pathForMotion;
|
|
254
|
-
return data.__pathForMotion = HighCurveHelper.getMotionPathData(this.getPath(true, true));
|
|
248
|
+
return getMotionPathData(getMotionPath(this));
|
|
255
249
|
};
|
|
256
250
|
ui.getMotionPoint = function (motionDistance) {
|
|
257
|
-
const
|
|
251
|
+
const path = getMotionPath(this);
|
|
252
|
+
const data = getMotionPathData(path);
|
|
253
|
+
if (!data.total)
|
|
254
|
+
return {};
|
|
258
255
|
const point = HighCurveHelper.getDistancePoint(data, motionDistance);
|
|
259
|
-
draw.MatrixHelper.toOuterPoint(
|
|
256
|
+
draw.MatrixHelper.toOuterPoint(path.localTransform, point);
|
|
257
|
+
const { motionRotation } = this;
|
|
258
|
+
if (motionRotation === false)
|
|
259
|
+
delete point.rotation;
|
|
260
|
+
else if (typeof motionRotation === 'number')
|
|
261
|
+
point.rotation += motionRotation;
|
|
260
262
|
return point;
|
|
261
263
|
};
|
|
262
264
|
ui.getMotionTotal = function () {
|
|
@@ -268,48 +270,58 @@ this.LeaferIN.motionPath = (function (exports, draw) {
|
|
|
268
270
|
data.__pathForMotion = undefined;
|
|
269
271
|
if (this.motionPath) {
|
|
270
272
|
let child;
|
|
271
|
-
const { children } = this.parent;
|
|
273
|
+
const { children } = this.parent, { leaferIsReady } = this;
|
|
272
274
|
for (let i = 0; i < children.length; i++) {
|
|
273
275
|
child = children[i];
|
|
274
|
-
if (!draw.isNull(child.motion))
|
|
276
|
+
if (!draw.isNull(child.motion) && !child.__layout.matrixChanged) {
|
|
277
|
+
if (leaferIsReady && child !== this)
|
|
278
|
+
this.leafer.layouter.addExtra(child);
|
|
275
279
|
updateMotion(child);
|
|
280
|
+
}
|
|
276
281
|
}
|
|
277
282
|
}
|
|
278
|
-
else
|
|
283
|
+
else
|
|
279
284
|
updateMotion(this);
|
|
280
|
-
}
|
|
281
285
|
};
|
|
282
286
|
function updateMotion(leaf) {
|
|
283
|
-
const { motion,
|
|
287
|
+
const { motion, leaferIsCreated } = leaf;
|
|
284
288
|
if (draw.isNull(motion))
|
|
285
289
|
return;
|
|
290
|
+
if (leaferIsCreated)
|
|
291
|
+
leaf.leafer.created = false;
|
|
286
292
|
if (leaf.motionPath) {
|
|
287
|
-
const data =
|
|
293
|
+
const data = getMotionPathData(leaf);
|
|
288
294
|
if (data.total)
|
|
289
295
|
leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion);
|
|
290
296
|
}
|
|
291
297
|
else {
|
|
292
|
-
|
|
293
|
-
|
|
298
|
+
leaf.set(leaf.getMotionPoint(motion));
|
|
299
|
+
if (!leaf.__hasAutoLayout) {
|
|
300
|
+
if (leaf.isBranch)
|
|
301
|
+
updateAllMatrix(leaf), updateBounds(leaf, leaf);
|
|
302
|
+
else
|
|
303
|
+
updateMatrix(leaf);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (leaferIsCreated)
|
|
307
|
+
leaf.leafer.created = true;
|
|
308
|
+
}
|
|
309
|
+
function getMotionPath(leaf) {
|
|
310
|
+
const { parent } = leaf;
|
|
311
|
+
if (!leaf.motionPath && parent) {
|
|
312
|
+
const { children } = parent;
|
|
294
313
|
for (let i = 0; i < children.length; i++) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const data = child.getMotionPathData();
|
|
298
|
-
if (!data.total)
|
|
299
|
-
return;
|
|
300
|
-
const point = child.getMotionPoint(motion);
|
|
301
|
-
if (motionRotation === false)
|
|
302
|
-
delete point.rotation;
|
|
303
|
-
else {
|
|
304
|
-
point.rotation += child.rotation;
|
|
305
|
-
if (typeof motionRotation === 'number')
|
|
306
|
-
point.rotation += motionRotation;
|
|
307
|
-
}
|
|
308
|
-
leaf.set(point);
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
314
|
+
if (children[i].motionPath)
|
|
315
|
+
return children[i];
|
|
311
316
|
}
|
|
312
317
|
}
|
|
318
|
+
return leaf;
|
|
319
|
+
}
|
|
320
|
+
function getMotionPathData(leaf) {
|
|
321
|
+
const data = leaf.__;
|
|
322
|
+
if (data.__pathForMotion)
|
|
323
|
+
return data.__pathForMotion;
|
|
324
|
+
return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
|
|
313
325
|
}
|
|
314
326
|
|
|
315
327
|
exports.HighBezierHelper = HighBezierHelper;
|
package/dist/motion-path.min.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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,a={getDistance(t,a,
|
|
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,a={getDistance(t,a,i,s,c,h,l,u){let f,g,p,m,P,_,d=0;for(let M=0;M<e.length;M++)f=.5*(1+e[M]),g=.5*(1-e[M]),p=r(f,t,i,c,l),m=r(f,a,s,h,u),P=r(g,t,i,c,l),_=r(g,a,s,h,u),d+=o[M]*(n(p*p+m*m)+n(P*P+_*_));return.5*d},getDerivative(t,e,o,n,a){const r=1-t;return 3*r*r*(o-e)+6*r*t*(n-o)+3*t*t*(a-n)},cut(e,o,n,a,r,i,s,c,h,l){const u=1-o,f=u*n+o*r,g=u*a+o*i,p=u*r+o*s,m=u*i+o*c,P=u*f+o*p,_=u*g+o*m,d=u*P+o*(u*p+o*(u*s+o*h)),M=u*_+o*(u*m+o*(u*c+o*l));e.push(t.PathCommandMap.C,f,g,P,_,d,M)}},{getDerivative:r}=a,{M:i,L:s,C:c,Z:h}=t.PathCommandMap,l={},u={},f={transform(t,e){let o,n=0;const a=t.length;for(;n<a;)switch(o=t[n],o){case i:case s:f.transformPoints(t,e,n,1),n+=3;break;case c:f.transformPoints(t,e,n,3),n+=7;break;case h:n+=1}},transformPoints(e,o,n,a){for(let r=n+1,i=r+2*a;r<i;r+=2)l.x=e[r],l.y=e[r+1],t.MatrixHelper.toOuterPoint(o,l),e[r]=l.x,e[r+1]=l.y},getMotionPathData(e){let o,n,r,l,u=0,f=[],g=0,p=0,m=0;const P=e.length;for(;g<P;){switch(l=e[g],l){case i:case s:n=e[g+1],r=e[g+2],o=l===s&&g>0?t.PointHelper.getDistanceFrom(p,m,n,r):0,p=n,m=r,g+=3;break;case c:n=e[g+5],r=e[g+6],o=a.getDistance(p,m,e[g+1],e[g+2],e[g+3],e[g+4],n,r),p=n,m=r,g+=7;break;case h:g+=1;default:o=0}f.push(o),u+=o}return{total:u,segments:f,data:e}},getDistancePoint(e,o){const{segments:n,data:a}=e;o=t.UnitConvert.number(o,e.total);let r,l,f,g,p=0,m={},P=0,_=0,d=0,M=0;const x=a.length;for(;P<x;){switch(g=a[P],g){case i:case s:if(l=a[P+1],f=a[P+2],r=n[_],p+r>o||!e.total)return P||(d=l,M=f),u.x=d,u.y=M,m.x=l,m.y=f,t.PointHelper.getDistancePoint(u,m,o-p,!0),m.rotation=t.PointHelper.getAngle(u,m),m;d=l,M=f,P+=3;break;case c:if(l=a[P+5],f=a[P+6],r=n[_],p+r>o){const e=a[P+1],n=a[P+2],i=a[P+3],s=a[P+4];return o-=p,t.BezierHelper.getPointAndSet(o/r,d,M,e,n,i,s,l,f,m),t.BezierHelper.getPointAndSet(Math.max(0,o-.1)/r,d,M,e,n,i,s,l,f,u),m.rotation=t.PointHelper.getAngle(u,m),m}d=l,M=f,P+=7;break;case h:P+=1;default:r=0}_++,p+=r}return m},getDistancePath(e,o){const{segments:n,data:r}=e,l=[];o=t.UnitConvert.number(o,e.total);let f,g,p,m,P=0,_={},d=0,M=0,x=0,y=0;const b=r.length;for(;d<b;){switch(m=r[d],m){case i:case s:if(g=r[d+1],p=r[d+2],f=n[M],P+f>o||!e.total)return d||(x=g,y=p),u.x=x,u.y=y,_.x=g,_.y=p,t.PointHelper.getDistancePoint(u,_,o-P,!0),l.push(m,_.x,_.y),l;x=g,y=p,d+=3,l.push(m,x,y);break;case c:const b=r[d+1],D=r[d+2],H=r[d+3],C=r[d+4];if(g=r[d+5],p=r[d+6],f=n[M],P+f>o)return a.cut(l,(o-P)/f,x,y,b,D,H,C,g,p),l;x=g,y=p,d+=7,l.push(m,b,D,H,C,g,p);break;case h:d+=1,l.push(m);default:f=0}M++,P+=f}return l}};function g(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.Transition.register("motion",(function(e,o,n,a){return e?"object"==typeof e&&(e=t.UnitConvert.number(e,a.getMotionTotal())):e=0,o?"object"==typeof o&&(o=t.UnitConvert.number(o,a.getMotionTotal())):o=0,t.Transition.number(e,o,n)})),t.Transition.register("motionRotation",(function(e,o,n){return t.Transition.number(e,o,n)}));const p=t.UI.prototype,{updateMatrix:m,updateAllMatrix:P}=t.LeafHelper,{updateBounds:_}=t.BranchHelper;function d(e){const{motion:o,leaferIsCreated:n}=e;if(!t.isNull(o)){if(n&&(e.leafer.created=!1),e.motionPath){const t=x(e);t.total&&(e.__.__pathForRender=f.getDistancePath(t,o))}else e.set(e.getMotionPoint(o)),e.__hasAutoLayout||(e.isBranch?(P(e),_(e,e)):m(e));n&&(e.leafer.created=!0)}}function M(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 x(t){const e=t.__;return e.__pathForMotion?e.__pathForMotion:e.__pathForMotion=f.getMotionPathData(t.getPath(!0,!0))}g()(p,"motionPath"),g()(p,"motion"),g(!0)(p,"motionRotation"),p.getMotionPathData=function(){return x(M(this))},p.getMotionPoint=function(e){const o=M(this),n=x(o);if(!n.total)return{};const a=f.getDistancePoint(n,e);t.MatrixHelper.toOuterPoint(o.localTransform,a);const{motionRotation:r}=this;return!1===r?delete a.rotation:"number"==typeof r&&(a.rotation+=r),a},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,{leaferIsReady:n}=this;for(let a=0;a<o.length;a++)e=o[a],t.isNull(e.motion)||e.__layout.matrixChanged||(n&&e!==this&&this.leafer.layouter.addExtra(e),d(e))}else d(this)},exports.HighBezierHelper=a,exports.HighCurveHelper=f,exports.motionPathType=g;
|
package/dist/motion-path.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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:a}=Math,
|
|
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:a}=Math,r={getDistance(t,e,r,s,h,c,l,u){let f,g,m,p,P,_,d=0;for(let M=0;M<o.length;M++)f=.5*(1+o[M]),g=.5*(1-o[M]),m=i(f,t,r,h,l),p=i(f,e,s,c,u),P=i(g,t,r,h,l),_=i(g,e,s,c,u),d+=n[M]*(a(m*m+p*p)+a(P*P+_*_));return.5*d},getDerivative(t,e,o,n,a){const r=1-t;return 3*r*r*(o-e)+6*r*t*(n-o)+3*t*t*(a-n)},cut(t,o,n,a,r,i,s,h,c,l){const u=1-o,f=u*n+o*r,g=u*a+o*i,m=u*r+o*s,p=u*i+o*h,P=u*f+o*m,_=u*g+o*p,d=u*P+o*(u*m+o*(u*s+o*c)),M=u*_+o*(u*p+o*(u*h+o*l));t.push(e.PathCommandMap.C,f,g,P,_,d,M)}},{getDerivative:i}=r,{M:s,L:h,C:c,Z:l}=e.PathCommandMap,u={},f={},g={transform(t,e){let o,n=0;const a=t.length;for(;n<a;)switch(o=t[n],o){case s:case h:g.transformPoints(t,e,n,1),n+=3;break;case c:g.transformPoints(t,e,n,3),n+=7;break;case l:n+=1}},transformPoints(t,o,n,a){for(let r=n+1,i=r+2*a;r<i;r+=2)u.x=t[r],u.y=t[r+1],e.MatrixHelper.toOuterPoint(o,u),t[r]=u.x,t[r+1]=u.y},getMotionPathData(t){let o,n,a,i,u=0,f=[],g=0,m=0,p=0;const P=t.length;for(;g<P;){switch(i=t[g],i){case s:case h:n=t[g+1],a=t[g+2],o=i===h&&g>0?e.PointHelper.getDistanceFrom(m,p,n,a):0,m=n,p=a,g+=3;break;case c:n=t[g+5],a=t[g+6],o=r.getDistance(m,p,t[g+1],t[g+2],t[g+3],t[g+4],n,a),m=n,p=a,g+=7;break;case l:g+=1;default:o=0}f.push(o),u+=o}return{total:u,segments:f,data:t}},getDistancePoint(t,o){const{segments:n,data:a}=t;o=e.UnitConvert.number(o,t.total);let r,i,u,g,m=0,p={},P=0,_=0,d=0,M=0;const y=a.length;for(;P<y;){switch(g=a[P],g){case s:case h:if(i=a[P+1],u=a[P+2],r=n[_],m+r>o||!t.total)return P||(d=i,M=u),f.x=d,f.y=M,p.x=i,p.y=u,e.PointHelper.getDistancePoint(f,p,o-m,!0),p.rotation=e.PointHelper.getAngle(f,p),p;d=i,M=u,P+=3;break;case c:if(i=a[P+5],u=a[P+6],r=n[_],m+r>o){const t=a[P+1],n=a[P+2],s=a[P+3],h=a[P+4];return o-=m,e.BezierHelper.getPointAndSet(o/r,d,M,t,n,s,h,i,u,p),e.BezierHelper.getPointAndSet(Math.max(0,o-.1)/r,d,M,t,n,s,h,i,u,f),p.rotation=e.PointHelper.getAngle(f,p),p}d=i,M=u,P+=7;break;case l:P+=1;default:r=0}_++,m+=r}return p},getDistancePath(t,o){const{segments:n,data:a}=t,i=[];o=e.UnitConvert.number(o,t.total);let u,g,m,p,P=0,_={},d=0,M=0,y=0,b=0;const x=a.length;for(;d<x;){switch(p=a[d],p){case s:case h:if(g=a[d+1],m=a[d+2],u=n[M],P+u>o||!t.total)return d||(y=g,b=m),f.x=y,f.y=b,_.x=g,_.y=m,e.PointHelper.getDistancePoint(f,_,o-P,!0),i.push(p,_.x,_.y),i;y=g,b=m,d+=3,i.push(p,y,b);break;case c:const x=a[d+1],D=a[d+2],H=a[d+3],C=a[d+4];if(g=a[d+5],m=a[d+6],u=n[M],P+u>o)return r.cut(i,(o-P)/u,y,b,x,D,H,C,g,m),i;y=g,b=m,d+=7,i.push(p,x,D,H,C,g,m);break;case l:d+=1,i.push(p);default:u=0}M++,P+=u}return i}};function m(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.Transition.register("motion",(function(t,o,n,a){return t?"object"==typeof t&&(t=e.UnitConvert.number(t,a.getMotionTotal())):t=0,o?"object"==typeof o&&(o=e.UnitConvert.number(o,a.getMotionTotal())):o=0,e.Transition.number(t,o,n)})),e.Transition.register("motionRotation",(function(t,o,n){return e.Transition.number(t,o,n)}));const p=e.UI.prototype,{updateMatrix:P,updateAllMatrix:_}=e.LeafHelper,{updateBounds:d}=e.BranchHelper;function M(t){const{motion:o,leaferIsCreated:n}=t;if(!e.isNull(o)){if(n&&(t.leafer.created=!1),t.motionPath){const e=b(t);e.total&&(t.__.__pathForRender=g.getDistancePath(e,o))}else t.set(t.getMotionPoint(o)),t.__hasAutoLayout||(t.isBranch?(_(t),d(t,t)):P(t));n&&(t.leafer.created=!0)}}function y(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 b(t){const e=t.__;return e.__pathForMotion?e.__pathForMotion:e.__pathForMotion=g.getMotionPathData(t.getPath(!0,!0))}return m()(p,"motionPath"),m()(p,"motion"),m(!0)(p,"motionRotation"),p.getMotionPathData=function(){return b(y(this))},p.getMotionPoint=function(t){const o=y(this),n=b(o);if(!n.total)return{};const a=g.getDistancePoint(n,t);e.MatrixHelper.toOuterPoint(o.localTransform,a);const{motionRotation:r}=this;return!1===r?delete a.rotation:"number"==typeof r&&(a.rotation+=r),a},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,{leaferIsReady:n}=this;for(let a=0;a<o.length;a++)t=o[a],e.isNull(t.motion)||t.__layout.matrixChanged||(n&&t!==this&&this.leafer.layouter.addExtra(t),M(t))}else M(this)},t.HighBezierHelper=r,t.HighCurveHelper=g,t.motionPathType=m,t}({},LeaferUI);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/motion-path",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "@leafer-in/motion-path",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
"types": "types/index.d.ts",
|
|
15
15
|
"unpkg": "dist/motion-path.js",
|
|
16
16
|
"jsdelivr": "dist/motion-path.js",
|
|
17
|
-
"files": [
|
|
17
|
+
"files": [
|
|
18
|
+
"src",
|
|
19
|
+
"types",
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
18
22
|
"repository": {
|
|
19
23
|
"type": "git",
|
|
20
24
|
"url": "https://github.com/leaferjs/leafer-in.git"
|
|
@@ -30,8 +34,8 @@
|
|
|
30
34
|
"leaferjs"
|
|
31
35
|
],
|
|
32
36
|
"dependencies": {
|
|
33
|
-
"@leafer-ui/draw": "^1.0.
|
|
34
|
-
"@leafer-ui/interface": "^1.0.
|
|
35
|
-
"@leafer-in/interface": "^1.0.
|
|
37
|
+
"@leafer-ui/draw": "^1.0.8",
|
|
38
|
+
"@leafer-ui/interface": "^1.0.8",
|
|
39
|
+
"@leafer-in/interface": "^1.0.8"
|
|
36
40
|
}
|
|
37
41
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { HighBezierHelper } from './HighBezierHelper'
|
|
|
3
3
|
export { motionPathType } from './decorator'
|
|
4
4
|
|
|
5
5
|
import { IMotionPathData, IUI, IUnitData, IRotationPointData } from '@leafer-ui/interface'
|
|
6
|
-
import { isNull, MatrixHelper, Transition, UI, UnitConvert } from '@leafer-ui/draw'
|
|
6
|
+
import { isNull, MatrixHelper, LeafHelper, BranchHelper, Transition, UI, UnitConvert } from '@leafer-ui/draw'
|
|
7
7
|
|
|
8
8
|
import { HighCurveHelper } from './HighCurveHelper'
|
|
9
9
|
import { motionPathType } from './decorator'
|
|
@@ -17,8 +17,14 @@ Transition.register('motion', function (from: any, to: any, t: number, target: I
|
|
|
17
17
|
return Transition.number(from, to, t)
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
+
Transition.register('motionRotation', function (from: any, to: any, t: number): number {
|
|
21
|
+
return Transition.number(from, to, t)
|
|
22
|
+
})
|
|
23
|
+
|
|
20
24
|
|
|
21
25
|
const ui = UI.prototype
|
|
26
|
+
const { updateMatrix, updateAllMatrix } = LeafHelper
|
|
27
|
+
const { updateBounds } = BranchHelper
|
|
22
28
|
|
|
23
29
|
|
|
24
30
|
// addAttr
|
|
@@ -28,24 +34,20 @@ motionPathType(true)(ui, 'motionRotation')
|
|
|
28
34
|
|
|
29
35
|
|
|
30
36
|
ui.getMotionPathData = function (): IMotionPathData {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!this.motionPath && parent) {
|
|
34
|
-
const { children } = parent
|
|
35
|
-
for (let i = 0; i < children.length; i++) {
|
|
36
|
-
if (children[i].motionPath) return children[i].getMotionPathData()
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const data = this.__
|
|
41
|
-
if (data.__pathForMotion) return data.__pathForMotion
|
|
42
|
-
return data.__pathForMotion = HighCurveHelper.getMotionPathData(this.getPath(true, true))
|
|
37
|
+
return getMotionPathData(getMotionPath(this))
|
|
43
38
|
}
|
|
44
39
|
|
|
45
40
|
ui.getMotionPoint = function (motionDistance: number | IUnitData): IRotationPointData {
|
|
46
|
-
const
|
|
41
|
+
const path = getMotionPath(this)
|
|
42
|
+
const data = getMotionPathData(path)
|
|
43
|
+
if (!data.total) return {} as IRotationPointData
|
|
44
|
+
|
|
47
45
|
const point = HighCurveHelper.getDistancePoint(data, motionDistance)
|
|
48
|
-
MatrixHelper.toOuterPoint(
|
|
46
|
+
MatrixHelper.toOuterPoint(path.localTransform, point)
|
|
47
|
+
|
|
48
|
+
const { motionRotation } = this
|
|
49
|
+
if (motionRotation === false) delete point.rotation
|
|
50
|
+
else if (typeof motionRotation === 'number') point.rotation += motionRotation
|
|
49
51
|
return point
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -59,45 +61,56 @@ ui.__updateMotionPath = function (): void {
|
|
|
59
61
|
|
|
60
62
|
if (this.motionPath) {
|
|
61
63
|
let child: IUI
|
|
62
|
-
const { children } = this.parent
|
|
64
|
+
const { children } = this.parent, { leaferIsReady } = this
|
|
63
65
|
for (let i = 0; i < children.length; i++) {
|
|
64
66
|
child = children[i]
|
|
65
|
-
if (!isNull(child.motion)
|
|
67
|
+
if (!isNull(child.motion) && !child.__layout.matrixChanged) {
|
|
68
|
+
if (leaferIsReady && child !== this) this.leafer.layouter.addExtra(child) // add part
|
|
69
|
+
updateMotion(child)
|
|
70
|
+
}
|
|
66
71
|
}
|
|
67
|
-
} else
|
|
68
|
-
updateMotion(this)
|
|
69
|
-
}
|
|
72
|
+
} else updateMotion(this)
|
|
70
73
|
}
|
|
71
74
|
|
|
75
|
+
|
|
72
76
|
function updateMotion(leaf: IUI): void {
|
|
73
|
-
const { motion,
|
|
77
|
+
const { motion, leaferIsCreated } = leaf
|
|
74
78
|
if (isNull(motion)) return
|
|
75
79
|
|
|
80
|
+
if (leaferIsCreated) leaf.leafer.created = false // 拦截布局更新通知,进行手动更新布局
|
|
81
|
+
|
|
76
82
|
if (leaf.motionPath) {
|
|
77
83
|
|
|
78
|
-
const data =
|
|
84
|
+
const data = getMotionPathData(leaf)
|
|
79
85
|
if (data.total) leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion) // 生长路径
|
|
80
86
|
|
|
81
87
|
} else {
|
|
82
88
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const data = child.getMotionPathData()
|
|
89
|
-
if (!data.total) return
|
|
90
|
-
const point = child.getMotionPoint(motion)
|
|
91
|
-
if (motionRotation === false) delete point.rotation
|
|
92
|
-
else {
|
|
93
|
-
point.rotation += child.rotation
|
|
94
|
-
if (typeof motionRotation === 'number') point.rotation += motionRotation
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
leaf.set(point) // 动画路径
|
|
98
|
-
break
|
|
99
|
-
}
|
|
89
|
+
leaf.set(leaf.getMotionPoint(motion)) // 动画路径
|
|
90
|
+
|
|
91
|
+
if (!leaf.__hasAutoLayout) { // 手动更新布局
|
|
92
|
+
if (leaf.isBranch) updateAllMatrix(leaf), updateBounds(leaf, leaf)
|
|
93
|
+
else updateMatrix(leaf)
|
|
100
94
|
}
|
|
101
95
|
|
|
102
96
|
}
|
|
97
|
+
|
|
98
|
+
if (leaferIsCreated) leaf.leafer.created = true
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getMotionPath(leaf: IUI): IUI {
|
|
102
|
+
const { parent } = leaf
|
|
103
|
+
if (!leaf.motionPath && parent) {
|
|
104
|
+
const { children } = parent
|
|
105
|
+
for (let i = 0; i < children.length; i++) {
|
|
106
|
+
if (children[i].motionPath) return children[i]
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return leaf
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getMotionPathData(leaf: IUI): IMotionPathData {
|
|
113
|
+
const data = leaf.__
|
|
114
|
+
if (data.__pathForMotion) return data.__pathForMotion
|
|
115
|
+
return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true))
|
|
103
116
|
}
|