qarl 1.2.4 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -0
- package/package.json +18 -14
- package/types/Core.d.ts +48 -0
- package/types/Curve.d.ts +13 -0
- package/types/FromTo.d.ts +14 -0
- package/types/Loop.d.ts +18 -0
- package/types/Manager.d.ts +20 -0
- package/types/common.d.ts +71 -0
- package/types/defaults.d.ts +3 -0
- package/types/easings.d.ts +3 -0
- package/types/events.d.ts +3 -0
- package/types/index.d.ts +24 -0
- package/types/modes.d.ts +3 -0
- package/types/play.d.ts +5 -0
- package/dist/qarl.es.min.js +0 -1
- package/kill-port.js +0 -16
- package/src/behaviors/easings.js +0 -73
- package/src/behaviors/modes.js +0 -44
- package/src/controllers/Curve.js +0 -142
- package/src/controllers/FromTo.js +0 -90
- package/src/core/Core.js +0 -401
- package/src/core/Loop.js +0 -57
- package/src/core/Manager.js +0 -73
- package/src/core/defaults.js +0 -25
- package/src/core/events.js +0 -16
- package/src/core/getCreator.js +0 -30
- package/src/core/play.js +0 -13
- package/src/index.js +0 -10
- package/src/ultra/FromToUltra.js +0 -101
- package/test/index.html +0 -13
- package/test/styles.css +0 -15
- package/test/test-three-scene.js +0 -271
- package/webpack.config.js +0 -100
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var R=Object.create;var L=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(t,s,e)=>s in t?L(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e;var N=(t,s)=>()=>(s||t((s={exports:{}}).exports,s),s.exports);var Y=(t,s,e,i)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of V(s))!G.call(t,r)&&r!==e&&L(t,r,{get:()=>s[r],enumerable:!(i=j(s,r))||i.enumerable});return t};var z=(t,s,e)=>(e=t!=null?R(B(t)):{},Y(s||!t||!t.__esModule?L(e,"default",{value:t,enumerable:!0}):e,t));var y=(t,s,e)=>(q(t,typeof s!="symbol"?s+"":s,e),e);var k=N(($,b)=>{"use strict";var K=Object.prototype.hasOwnProperty,g="~";function T(){}Object.create&&(T.prototype=Object.create(null),new T().__proto__||(g=!1));function H(t,s,e){this.fn=t,this.context=s,this.once=e||!1}function F(t,s,e,i,r){if(typeof e!="function")throw new TypeError("The listener must be a function");var n=new H(e,i||t,r),a=g?g+s:s;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],n]:t._events[a].push(n):(t._events[a]=n,t._eventsCount++),t}function D(t,s){--t._eventsCount===0?t._events=new T:delete t._events[s]}function f(){this._events=new T,this._eventsCount=0}f.prototype.eventNames=function(){var s=[],e,i;if(this._eventsCount===0)return s;for(i in e=this._events)K.call(e,i)&&s.push(g?i.slice(1):i);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(e)):s};f.prototype.listeners=function(s){var e=g?g+s:s,i=this._events[e];if(!i)return[];if(i.fn)return[i.fn];for(var r=0,n=i.length,a=new Array(n);r<n;r++)a[r]=i[r].fn;return a};f.prototype.listenerCount=function(s){var e=g?g+s:s,i=this._events[e];return i?i.fn?1:i.length:0};f.prototype.emit=function(s,e,i,r,n,a){var p=g?g+s:s;if(!this._events[p])return!1;var o=this._events[p],l=arguments.length,m,h;if(o.fn){switch(o.once&&this.removeListener(s,o.fn,void 0,!0),l){case 1:return o.fn.call(o.context),!0;case 2:return o.fn.call(o.context,e),!0;case 3:return o.fn.call(o.context,e,i),!0;case 4:return o.fn.call(o.context,e,i,r),!0;case 5:return o.fn.call(o.context,e,i,r,n),!0;case 6:return o.fn.call(o.context,e,i,r,n,a),!0}for(h=1,m=new Array(l-1);h<l;h++)m[h-1]=arguments[h];o.fn.apply(o.context,m)}else{var I=o.length,c;for(h=0;h<I;h++)switch(o[h].once&&this.removeListener(s,o[h].fn,void 0,!0),l){case 1:o[h].fn.call(o[h].context);break;case 2:o[h].fn.call(o[h].context,e);break;case 3:o[h].fn.call(o[h].context,e,i);break;case 4:o[h].fn.call(o[h].context,e,i,r);break;default:if(!m)for(c=1,m=new Array(l-1);c<l;c++)m[c-1]=arguments[c];o[h].fn.apply(o[h].context,m)}}return!0};f.prototype.on=function(s,e,i){return F(this,s,e,i,!1)};f.prototype.once=function(s,e,i){return F(this,s,e,i,!0)};f.prototype.removeListener=function(s,e,i,r){var n=g?g+s:s;if(!this._events[n])return this;if(!e)return D(this,n),this;var a=this._events[n];if(a.fn)a.fn===e&&(!r||a.once)&&(!i||a.context===i)&&D(this,n);else{for(var p=0,o=[],l=a.length;p<l;p++)(a[p].fn!==e||r&&!a[p].once||i&&a[p].context!==i)&&o.push(a[p]);o.length?this._events[n]=o.length===1?o[0]:o:D(this,n)}return this};f.prototype.removeAllListeners=function(s){var e;return s?(e=g?g+s:s,this._events[e]&&D(this,e)):(this._events=new T,this._eventsCount=0),this};f.prototype.off=f.prototype.removeListener;f.prototype.addListener=f.prototype.on;f.prefixed=g;f.EventEmitter=f;typeof b<"u"&&(b.exports=f)});var U=z(k(),1);var Q=U.default;var C={processors:[],time:0,loop:!1,mode:null,delay:0,repeat:0,target:null,easing:t=>t,reversed:!1,repeatDelay:0,autoApplyProcessors:!0};var _={PLAY:"play",STOP:"stop",BEGIN:"begin",UPDATE:"update",REPEAT:"repeat",COMPLETE:"complete"};var x=Math.PI*2,v=Math.pow,E={reverse:t=>1-t,linear:t=>t,yoyo:t=>1-Math.abs(1-t*2),inQuad:t=>v(t,2),outQuad:t=>1-(1-t)*(1-t),inOutQuad:t=>t<.5?2*t*t:-1+(4-2*t)*t,inCubic:t=>v(t,3),outCubic:t=>--t*t*t+1,inOutCubic:t=>t<.5?4*v(t,3):(t-1)*(2*t-2)*(2*t-2)+1,inQuart:t=>v(t,4),outQuart:t=>1- --t*v(t,3),inOutQuart:t=>t<.5?8*v(t,4):1-8*--t*t*t*t,inQuint:t=>v(t,5),outQuint:t=>1+--t*v(t,4),inOutQuint:t=>t<.5?16*v(t,5):1+16*--t*t*t*t*t,inSine:t=>1-Math.cos(t*Math.PI/2),outSine:t=>Math.sin(t*Math.PI/2),inOutSine:t=>-(Math.cos(Math.PI*t)-1)/2,inBack:(t,s=1.70158)=>t*t*((s+1)*t-s),outBack:(t,s=1.70158)=>(t-=1)*t*((s+1)*t+s)+1,inOutBack:(t,s=1.70158)=>(t*=2)<1?.5*(t*t*((s*1.525+1)*t-s*1.525)):.5*((t-=2)*t*((s*1.525+1)*t+s*1.525)+2),inExpo:t=>t===0?0:Math.pow(2,10*(t-1)),outExpo:t=>t===1?1:1-Math.pow(2,-10*t),inOutExpo:t=>t===0?0:t===1?1:t<.5?.5*Math.pow(2,20*t-10):1-.5*Math.pow(2,-20*t+10),inElastic:(t,s=1,e=.5)=>t===0?0:t===1?1:-s*Math.pow(2,10*(t-1))*Math.sin((t-1-e/x*Math.asin(1/s))*x/e),outElastic:(t,s=1,e=.5)=>t===0?0:t===1?1:s*Math.pow(2,-10*t)*Math.sin((t-e/x*Math.asin(1/s))*x/e)+1,inOutElastic:(t,s=1,e=.5)=>t===0?0:t===1?1:t<.5?-.5*s*Math.pow(2,20*t-10)*Math.sin((20*t-11.125)*x/e):.5*s*Math.pow(2,-20*t+10)*Math.sin((20*t-11.125)*x/e)+1};var O={pingPong:function(t){return t<=.5?this._easing(t*2):1-this._easing((t-.5)*2)},yoyo:function(t){return this._easing(E.yoyo(t))},bounce:function(t){return E.yoyo(this._easing(t))}};var J=0,d=class d extends Q{constructor(e={},i){super();y(this,"_reversedEasing",e=>this.settings.easing(1-e));y(this,"_stepDelay",e=>{this.remainingDelay-=e,this.lastDeltaTime=e,!(this.remainingDelay>0)&&(this.emit(_.BEGIN),this.step=this._stepTime,this.step(Math.abs(this.remainingDelay)),this.remainingDelay=this.settings.delay)});y(this,"_stepTime",(e=0)=>{this.elapsedTime+=e,this.lastDeltaTime=e,this.elapsedTime>=this.time?(this.elapsedTime=this.time,this._update(),this._complete()):this._update()});this.index=J++,this.overrides=e,this.settings={},this.reset(e),i&&(this.manager=i),this.lastDeltaTime=0}on(...e){return super.on(...e),this}off(...e){return super.off(...e),this}once(...e){return super.once(...e),this}onComplete(...e){return super.on(_.COMPLETE,...e),this}onUpdate(...e){return super.on(_.UPDATE,...e),this}onceComplete(...e){return super.once(_.COMPLETE,...e),this}static _noop(){}static mergeConfigs(e,i){e!==i&&Object.keys(i).forEach(r=>{typeof i[r]=="object"&&i[r]!==null?((!e[r]||typeof e[r]!="object")&&(e[r]={}),d.mergeConfigs(e[r],i[r])):e[r]=i[r]})}static lerp(e,i,r){return e+(i-e)*r}_processState(){this.step=d._noop,this.progress=0,this.easeValue=0,this.elapsedTime=0,this.promise=null,this._resolve=d._noop,this._refreshDynamicProps()}_refreshDynamicProps(){this.applyProcessors(this.settings);let{target:e,time:i,repeat:r,loop:n,reversed:a,delay:p}=this.settings;this.target=e,this.time=Math.max(i,0),this.repeat=r>0?r:n?1/0:0,this.reversed=a,this.remainingDelay=p,this._processEasing()}_processEasing(){let e=typeof this.settings.easing=="string"?E[this.settings.easing]||E.linear:this.settings.easing;this._easing=this.reversed?this._reversedEasing:e;let i=typeof this.settings.mode=="string"?O[this.settings.mode]:this.settings.mode;this._calculateEasing=i?i.bind(this):this._easing}_update(){this.progress=this.elapsedTime/this.time,this.easeValue=this._calculateEasing(this.progress),this.emit(_.UPDATE,this)}_complete(){this.repeat-- >0?this._repeat():(this._resolve(),this.stop(!1),this.emit(_.COMPLETE))}_repeat(e=!0){this.remainingDelay=this.settings.repeatDelay,this.elapsedTime=0,this.remainingDelay>0&&(this.step=this._stepDelay),this._update(),e&&this.emit(_.REPEAT)}reset(e=this.constructor.DEFAULTS){return this.settings={...this.constructor.DEFAULTS,...e},this._processState(),this}applyProcessors(e=this.settings){e.processors.forEach(i=>{d.mergeConfigs(e,i.call(this,e)||{})})}tweak(e={}){return d.mergeConfigs(this.settings,e),this._refreshDynamicProps(),this}seek(e=0,i=!0){return this.elapsedTime=Math.min(Math.max(e,0),this.time),i&&this._update(),this}setProgress(e=0,i=!0){return this.seek(this.time*e,i)}reverse(e=!1){return this.reversed=!this.reversed,this.seek(this.time-this.elapsedTime,e),this._processEasing(),this}play(e=!0){return this.isPlaying?this:(this.settings.autoApplyProcessors&&this._refreshDynamicProps(),e&&this.emit(_.PLAY),this.remainingDelay>0?this.step=this._stepDelay:(this.step=this._stepTime,this.emit(_.BEGIN)),this.manager&&this.manager.addToActive(this),this)}playPromise(e=this.promise){return this.play(),this.promise=e||new Promise(i=>{this._resolve=i}),this.promise}stop(e=!0){return this._processState(),e&&this.emit(_.STOP),this.manager&&this.manager.removeFromActive(this),this}pause(){return this.step=d._noop,this.manager&&this.manager.removeFromActive(this),this}replay(e=!1){return this.stop(e),this.play(e),this}get isPlaying(){return this.step!==d._noop}remove(){this.stop(),this.manager.remove(this)}};y(d,"DEFAULTS",C);var u=d;var P=class extends u{_preparePropertySetters(){this.propertySetters=this.properties.map(s=>{let e=s.split("."),i=e.pop();return r=>{let n=this.target;for(let a=0;a<e.length;a++)n=n[e[a]];n[i]=r}})}_generatePath(){let s=this.settings.points,e=Math.max(this.settings.smoothing,1),i=[];this.totalLength=0;function r(n,a,p,o,l){let m=l*l,h=m*l;return n.map((I,c)=>.5*(2*a[c]+(-n[c]+p[c])*l+(2*n[c]-5*a[c]+4*p[c]-o[c])*m+(-n[c]+3*a[c]-3*p[c]+o[c])*h))}for(let n=0;n<s.length-1;n++){let a=s[n===0?n:n-1],p=s[n],o=s[n+1],l=s[n+2<s.length?n+2:n+1];for(let m=0;m<e;m++){let h=r(a,p,o,l,m/e);i.push(h),i.length>1&&(this.totalLength+=this._calculateDistance(i[i.length-2],h))}}return i.push(s[s.length-1]),i}_calculateDistance(s,e){return Math.sqrt(s.reduce((i,r,n)=>i+Math.pow(e[n]-s[n],2),0))}_refreshDynamicProps(){super._refreshDynamicProps(),this.path=this._generatePath(),!this.target||this.path.length===0?this._setTargetProperties=u._noop:(this._tryToSetupProperties(),this._preparePropertySetters())}_tryToSetupProperties(){if(this.settings.properties)this.properties=this.settings.properties;else if(this.path[0].length<=3){let s=[["position.x"],["position.x","position.y"],["position.x","position.y","position.z"]];this.properties=s[this.path[0].length-1]}else this.properties=[]}_setTargetProperties(s){for(let e=0;e<this.propertySetters.length;e++)this.propertySetters[e](s[e])}_clamp(s,e,i){return Math.max(e,Math.min(s,i))}_getInterpolatedPosition(){let s=this.path.length-1,e=this.easeValue*s,i=this._clamp(e,0,s),r=i>=s?s-1:Math.floor(i),n=Math.min(r+1,s),a=e-r,p=this.path[r],o=this.path[n];return p.map((l,m)=>u.lerp(l,o[m],a))}_update(){super._update(),this._setTargetProperties(this._getInterpolatedPosition())}};y(P,"DEFAULTS",{...u.DEFAULTS,properties:null,points:[],smoothing:20});var A=class extends u{_refreshDynamicProps(){super._refreshDynamicProps(),this._processFromTo()}_processFromTo(){this._lerps=[],this.target&&(this._setupStates(),this._createLerps())}_setupStates(){this._from=this.settings.from||this._createState(this.settings.to||{},this.target),this._to=this.settings.to||this._createState(this.settings.from||{},this.target)}_createState(s={},e={},i={}){let r=(n,a,p)=>{for(let o in n)typeof n[o]=="object"?(p[o]={},r(n[o],a[o],p[o])):p[o]=a[o]};return r(s,e,i),i}_createLerpStep(s,e,i,r){if(this.settings.dynamic)return()=>{s[r]=u.lerp(e[r],i[r],this.easeValue)};{let n=e[r],a=i[r]-n;return()=>{s[r]=n+a*this.easeValue}}}_createLerps(s=this.target,e=this._from,i=this._to){for(let r in i)typeof i[r]=="object"?this._createLerps(s[r],e[r],i[r]):this._lerps.push(this._createLerpStep(s,e,i,r))}_update(){super._update();for(let s of this._lerps)s()}from(s={}){return this.tweak({from:s}),this}to(s={}){return this.tweak({to:s}),this}swap(){return this.tweak({from:this.settings.to,to:this.settings.from}),this}};y(A,"DEFAULTS",{...u.DEFAULTS,dynamic:!1,from:null,to:null});function w(t){return t.target?t.creator?t.creator instanceof u?t.creator:(console.error("Invalid creator provided. Using default creator."),u):t.points?P:t.from||t.to?A:u:u}var S=class{constructor(){y(this,"update",s=>{this.activeAnimations.forEach(e=>{e.step(s)})});this.activeAnimations=new Map,this.allAnimations=new Map}create({on:s={},once:e={},...i}){let r=w(i),n=new r(i,this);return Object.keys(s).forEach(a=>{n.on(a,s[a])}),Object.keys(e).forEach(a=>{n.once(a,e[a])}),this.add(n),n}getActiveAnimations(){return Array.from(this.activeAnimations.values())}getAllAnimations(){return Array.from(this.allAnimations.values())}remove({index:s}={}){s&&(this.activeAnimations.delete(s),this.allAnimations.delete(s))}add(s){this.allAnimations.set(s.index,s)}addToActive(s){this.activeAnimations.set(s.index,s)}removeFromActive(s){this.activeAnimations.delete(s.index)}stopAll(){this.activeAnimations.forEach(s=>{s.stop()})}removeAll(){this.stopAll(),this.activeAnimations.clear(),this.allAnimations.clear()}};var W=new S;var M=class t{constructor(s,e={}){this.callback=s,this.options={maxDeltaTime:100,...e},this.isRunning=!1,this.lastTime=0,this.animationId=null}static start(s,e={}){let i=new t(s,e);return i.start(),i}start(){if(this.isRunning)return;this.isRunning=!0;let s=e=>{if(!this.isRunning)return;let i=Math.min(e-this.lastTime,this.options.maxDeltaTime);this.lastTime=e,this.callback(i),this.isRunning&&(this.animationId=requestAnimationFrame(s))};requestAnimationFrame(e=>{this.lastTime=e,s(e)})}stop(){this.isRunning=!1,this.animationId&&(cancelAnimationFrame(this.animationId),this.animationId=null)}get running(){return this.isRunning}};function X(t,s){let e=new w(t),i=new e(t);return M.start(i.step.bind(i)),s?i.playPromise():i.play()}export{u as Core,P as Curve,C as DEFAULTS,_ as EVENTS,A as FromTo,W as GlobalManager,M as Loop,S as Manager,E as easings,O as modes,X as play};
|
package/package.json
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qarl",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "simple animation library",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
7
9
|
"exports": {
|
|
8
|
-
".":
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./types/index.d.ts"
|
|
13
|
+
}
|
|
9
14
|
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"types"
|
|
18
|
+
],
|
|
10
19
|
"scripts": {
|
|
11
|
-
"build": "
|
|
12
|
-
"
|
|
13
|
-
"
|
|
20
|
+
"build": "esbuild src/index.js --bundle --format=esm --outfile=dist/index.js --minify --target=es2020 && npm run type-check",
|
|
21
|
+
"type-check": "tsc --noEmit",
|
|
22
|
+
"prepare": "npm run build"
|
|
14
23
|
},
|
|
15
24
|
"repository": {
|
|
16
25
|
"type": "git",
|
|
@@ -26,12 +35,7 @@
|
|
|
26
35
|
"eventemitter3": "^5.0.1"
|
|
27
36
|
},
|
|
28
37
|
"devDependencies": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"terser-webpack-plugin": "^5.3.14",
|
|
32
|
-
"three": "^0.180.0",
|
|
33
|
-
"webpack": "^5.102.1",
|
|
34
|
-
"webpack-cli": "^6.0.1",
|
|
35
|
-
"webpack-dev-server": "^5.2.2"
|
|
38
|
+
"esbuild": "^0.19.0",
|
|
39
|
+
"typescript": "^5.3.0"
|
|
36
40
|
}
|
|
37
41
|
}
|
package/types/Core.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import { CoreSettings } from './common';
|
|
3
|
+
|
|
4
|
+
export class Core extends EventEmitter {
|
|
5
|
+
static DEFAULTS: CoreSettings;
|
|
6
|
+
static lerp(a: number, b: number, t: number): number;
|
|
7
|
+
static mergeConfigs(target: object, source: object): void;
|
|
8
|
+
|
|
9
|
+
index: number;
|
|
10
|
+
overrides: Partial<CoreSettings>;
|
|
11
|
+
settings: CoreSettings;
|
|
12
|
+
progress: number;
|
|
13
|
+
easeValue: number;
|
|
14
|
+
elapsedTime: number;
|
|
15
|
+
target: any;
|
|
16
|
+
time: number;
|
|
17
|
+
repeat: number;
|
|
18
|
+
reversed: boolean;
|
|
19
|
+
remainingDelay: number;
|
|
20
|
+
lastDeltaTime: number;
|
|
21
|
+
manager?: import('./Manager').Manager;
|
|
22
|
+
|
|
23
|
+
constructor(overrides?: Partial<CoreSettings>, manager?: import('./Manager').Manager);
|
|
24
|
+
|
|
25
|
+
step(deltaTime: number): void;
|
|
26
|
+
|
|
27
|
+
on(event: string, fn: (...args: any[]) => void, context?: any): this;
|
|
28
|
+
off(event: string, fn: (...args: any[]) => void, context?: any): this;
|
|
29
|
+
once(event: string, fn: (...args: any[]) => void, context?: any): this;
|
|
30
|
+
onComplete(fn: (animation: this) => void, context?: any): this;
|
|
31
|
+
onUpdate(fn: (animation: this) => void, context?: any): this;
|
|
32
|
+
onceComplete(fn: (animation: this) => void, context?: any): this;
|
|
33
|
+
|
|
34
|
+
reset(newSettings?: Partial<CoreSettings>): this;
|
|
35
|
+
applyProcessors(settings?: CoreSettings): void;
|
|
36
|
+
tweak(newSettings?: Partial<CoreSettings>): this;
|
|
37
|
+
seek(time?: number, callUpdate?: boolean): this;
|
|
38
|
+
setProgress(progress?: number, callUpdate?: boolean): this;
|
|
39
|
+
reverse(callUpdate?: boolean): this;
|
|
40
|
+
play(withEvent?: boolean): this;
|
|
41
|
+
playPromise(promise?: Promise<void>): Promise<void>;
|
|
42
|
+
stop(withEvent?: boolean): this;
|
|
43
|
+
pause(): this;
|
|
44
|
+
replay(withEvent?: boolean): this;
|
|
45
|
+
remove(): void;
|
|
46
|
+
|
|
47
|
+
get isPlaying(): boolean;
|
|
48
|
+
}
|
package/types/Curve.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Core } from './Core';
|
|
2
|
+
import { CurveSettings } from './common';
|
|
3
|
+
|
|
4
|
+
export class Curve extends Core {
|
|
5
|
+
static DEFAULTS: CurveSettings;
|
|
6
|
+
|
|
7
|
+
settings: CurveSettings;
|
|
8
|
+
path: number[][];
|
|
9
|
+
totalLength: number;
|
|
10
|
+
properties: string[];
|
|
11
|
+
|
|
12
|
+
constructor(overrides?: Partial<CurveSettings>, manager?: import('./Manager').Manager);
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Core } from './Core';
|
|
2
|
+
import { FromToSettings } from './common';
|
|
3
|
+
|
|
4
|
+
export class FromTo extends Core {
|
|
5
|
+
static DEFAULTS: FromToSettings;
|
|
6
|
+
|
|
7
|
+
settings: FromToSettings;
|
|
8
|
+
|
|
9
|
+
constructor(overrides?: Partial<FromToSettings>, manager?: import('./Manager').Manager);
|
|
10
|
+
|
|
11
|
+
from(from?: Record<string, any>): this;
|
|
12
|
+
to(to?: Record<string, any>): this;
|
|
13
|
+
swap(): this;
|
|
14
|
+
}
|
package/types/Loop.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LoopOptions } from './common';
|
|
2
|
+
|
|
3
|
+
export class Loop {
|
|
4
|
+
callback: (dt: number) => void;
|
|
5
|
+
options: Required<LoopOptions>;
|
|
6
|
+
isRunning: boolean;
|
|
7
|
+
lastTime: number;
|
|
8
|
+
animationId: number | null;
|
|
9
|
+
|
|
10
|
+
constructor(callback: (dt: number) => void, options?: LoopOptions);
|
|
11
|
+
|
|
12
|
+
static start(callback: (dt: number) => void, options?: LoopOptions): Loop;
|
|
13
|
+
|
|
14
|
+
start(): void;
|
|
15
|
+
stop(): void;
|
|
16
|
+
|
|
17
|
+
get running(): boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Core } from './Core';
|
|
2
|
+
import { ManagerCreateConfig } from './common';
|
|
3
|
+
|
|
4
|
+
export class Manager {
|
|
5
|
+
activeAnimations: Map<number, Core>;
|
|
6
|
+
allAnimations: Map<number, Core>;
|
|
7
|
+
|
|
8
|
+
create(config: ManagerCreateConfig): Core;
|
|
9
|
+
update(dt: number): void;
|
|
10
|
+
getActiveAnimations(): Core[];
|
|
11
|
+
getAllAnimations(): Core[];
|
|
12
|
+
remove(animation: { index?: number }): void;
|
|
13
|
+
add(animation: Core): void;
|
|
14
|
+
addToActive(animation: Core): void;
|
|
15
|
+
removeFromActive(animation: Core): void;
|
|
16
|
+
stopAll(): void;
|
|
17
|
+
removeAll(): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const GlobalManager: Manager;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Core } from './Core';
|
|
2
|
+
|
|
3
|
+
export type EasingFunction = (t: number, ...args: number[]) => number;
|
|
4
|
+
|
|
5
|
+
export type ModeFunction = (this: Core, t: number) => number;
|
|
6
|
+
|
|
7
|
+
export type ProcessorFunction = (this: Core, settings: CoreSettings) => Partial<CoreSettings> | void;
|
|
8
|
+
|
|
9
|
+
export interface CoreSettings {
|
|
10
|
+
processors: ProcessorFunction[];
|
|
11
|
+
time: number;
|
|
12
|
+
loop: boolean;
|
|
13
|
+
mode: string | ModeFunction | null;
|
|
14
|
+
delay: number;
|
|
15
|
+
repeat: number;
|
|
16
|
+
target: any;
|
|
17
|
+
easing: string | EasingFunction;
|
|
18
|
+
reversed: boolean;
|
|
19
|
+
repeatDelay: number;
|
|
20
|
+
autoApplyProcessors: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface FromToSettings extends CoreSettings {
|
|
24
|
+
dynamic: boolean;
|
|
25
|
+
from: Record<string, any> | null;
|
|
26
|
+
to: Record<string, any> | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface CurveSettings extends CoreSettings {
|
|
30
|
+
properties: string[] | null;
|
|
31
|
+
points: number[][];
|
|
32
|
+
smoothing: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface LoopOptions {
|
|
36
|
+
maxDeltaTime?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ManagerCreateConfig extends Partial<CoreSettings> {
|
|
40
|
+
on?: Record<string, (...args: any[]) => void>;
|
|
41
|
+
once?: Record<string, (...args: any[]) => void>;
|
|
42
|
+
from?: Record<string, any>;
|
|
43
|
+
to?: Record<string, any>;
|
|
44
|
+
points?: number[][];
|
|
45
|
+
properties?: string[];
|
|
46
|
+
smoothing?: number;
|
|
47
|
+
dynamic?: boolean;
|
|
48
|
+
creator?: typeof Core;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type EasingName =
|
|
52
|
+
| 'linear' | 'reverse' | 'yoyo'
|
|
53
|
+
| 'inQuad' | 'outQuad' | 'inOutQuad'
|
|
54
|
+
| 'inCubic' | 'outCubic' | 'inOutCubic'
|
|
55
|
+
| 'inQuart' | 'outQuart' | 'inOutQuart'
|
|
56
|
+
| 'inQuint' | 'outQuint' | 'inOutQuint'
|
|
57
|
+
| 'inSine' | 'outSine' | 'inOutSine'
|
|
58
|
+
| 'inBack' | 'outBack' | 'inOutBack'
|
|
59
|
+
| 'inExpo' | 'outExpo' | 'inOutExpo'
|
|
60
|
+
| 'inElastic' | 'outElastic' | 'inOutElastic';
|
|
61
|
+
|
|
62
|
+
export type ModeName = 'pingPong' | 'yoyo' | 'bounce';
|
|
63
|
+
|
|
64
|
+
export interface EventTypes {
|
|
65
|
+
PLAY: 'play';
|
|
66
|
+
STOP: 'stop';
|
|
67
|
+
BEGIN: 'begin';
|
|
68
|
+
UPDATE: 'update';
|
|
69
|
+
REPEAT: 'repeat';
|
|
70
|
+
COMPLETE: 'complete';
|
|
71
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { Core } from './Core';
|
|
2
|
+
export { Curve } from './Curve';
|
|
3
|
+
export { FromTo } from './FromTo';
|
|
4
|
+
export { DEFAULTS } from './defaults';
|
|
5
|
+
export { easings } from './easings';
|
|
6
|
+
export { EVENTS } from './events';
|
|
7
|
+
export { modes } from './modes';
|
|
8
|
+
export { Manager, GlobalManager } from './Manager';
|
|
9
|
+
export { Loop } from './Loop';
|
|
10
|
+
export { play } from './play';
|
|
11
|
+
|
|
12
|
+
export type {
|
|
13
|
+
EasingFunction,
|
|
14
|
+
ModeFunction,
|
|
15
|
+
ProcessorFunction,
|
|
16
|
+
CoreSettings,
|
|
17
|
+
FromToSettings,
|
|
18
|
+
CurveSettings,
|
|
19
|
+
LoopOptions,
|
|
20
|
+
ManagerCreateConfig,
|
|
21
|
+
EasingName,
|
|
22
|
+
ModeName,
|
|
23
|
+
EventTypes,
|
|
24
|
+
} from './common';
|
package/types/modes.d.ts
ADDED
package/types/play.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Core } from './Core';
|
|
2
|
+
import { CoreSettings, FromToSettings, CurveSettings } from './common';
|
|
3
|
+
|
|
4
|
+
export function play(config: Partial<CoreSettings | FromToSettings | CurveSettings>, async?: false): Core;
|
|
5
|
+
export function play(config: Partial<CoreSettings | FromToSettings | CurveSettings>, async: true): Promise<void>;
|
package/dist/qarl.es.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t={228:t=>{var e=Object.prototype.hasOwnProperty,s="~";function i(){}function n(t,e,s){this.fn=t,this.context=e,this.once=s||!1}function r(t,e,i,r,o){if("function"!=typeof i)throw new TypeError("The listener must be a function");var a=new n(i,r||t,o),h=s?s+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],a]:t._events[h].push(a):(t._events[h]=a,t._eventsCount++),t}function o(t,e){0===--t._eventsCount?t._events=new i:delete t._events[e]}function a(){this._events=new i,this._eventsCount=0}Object.create&&(i.prototype=Object.create(null),(new i).__proto__||(s=!1)),a.prototype.eventNames=function(){var t,i,n=[];if(0===this._eventsCount)return n;for(i in t=this._events)e.call(t,i)&&n.push(s?i.slice(1):i);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(t)):n},a.prototype.listeners=function(t){var e=s?s+t:t,i=this._events[e];if(!i)return[];if(i.fn)return[i.fn];for(var n=0,r=i.length,o=new Array(r);n<r;n++)o[n]=i[n].fn;return o},a.prototype.listenerCount=function(t){var e=s?s+t:t,i=this._events[e];return i?i.fn?1:i.length:0},a.prototype.emit=function(t,e,i,n,r,o){var a=s?s+t:t;if(!this._events[a])return!1;var h,p,c=this._events[a],l=arguments.length;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,i),!0;case 4:return c.fn.call(c.context,e,i,n),!0;case 5:return c.fn.call(c.context,e,i,n,r),!0;case 6:return c.fn.call(c.context,e,i,n,r,o),!0}for(p=1,h=new Array(l-1);p<l;p++)h[p-1]=arguments[p];c.fn.apply(c.context,h)}else{var u,m=c.length;for(p=0;p<m;p++)switch(c[p].once&&this.removeListener(t,c[p].fn,void 0,!0),l){case 1:c[p].fn.call(c[p].context);break;case 2:c[p].fn.call(c[p].context,e);break;case 3:c[p].fn.call(c[p].context,e,i);break;case 4:c[p].fn.call(c[p].context,e,i,n);break;default:if(!h)for(u=1,h=new Array(l-1);u<l;u++)h[u-1]=arguments[u];c[p].fn.apply(c[p].context,h)}}return!0},a.prototype.on=function(t,e,s){return r(this,t,e,s,!1)},a.prototype.once=function(t,e,s){return r(this,t,e,s,!0)},a.prototype.removeListener=function(t,e,i,n){var r=s?s+t:t;if(!this._events[r])return this;if(!e)return o(this,r),this;var a=this._events[r];if(a.fn)a.fn!==e||n&&!a.once||i&&a.context!==i||o(this,r);else{for(var h=0,p=[],c=a.length;h<c;h++)(a[h].fn!==e||n&&!a[h].once||i&&a[h].context!==i)&&p.push(a[h]);p.length?this._events[r]=1===p.length?p[0]:p:o(this,r)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=s?s+t:t,this._events[e]&&o(this,e)):(this._events=new i,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=s,a.EventEmitter=a,t.exports=a}},e={};function s(i){var n=e[i];if(void 0!==n)return n.exports;var r=e[i]={exports:{}};return t[i](r,r.exports,s),r.exports}s.d=(t,e)=>{for(var i in e)s.o(e,i)&&!s.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const i=s(228),n={processors:[],time:0,loop:!1,mode:null,delay:0,repeat:0,target:null,easing:t=>t,reversed:!1,repeatDelay:0,autoApplyProcessors:!1},r={PLAY:"play",STOP:"stop",BEGIN:"begin",UPDATE:"update",REPEAT:"repeat",COMPLETE:"complete"},o=2*Math.PI,a=Math.pow,h={reverse:t=>1-t,linear:t=>t,yoyo:t=>1-Math.abs(1-2*t),inQuad:t=>a(t,2),outQuad:t=>t*(2-t),inOutQuad:t=>t<.5?2*t*t:(4-2*t)*t-1,inCubic:t=>a(t,3),outCubic:t=>--t*t*t+1,inOutCubic:t=>t<.5?4*a(t,3):(t-1)*(2*t-2)*(2*t-2)+1,inQuart:t=>a(t,4),outQuart:t=>1- --t*a(t,3),inOutQuart:t=>t<.5?8*a(t,4):1-8*--t*t*t*t,inQuint:t=>a(t,5),outQuint:t=>1+--t*a(t,4),inOutQuint:t=>t<.5?16*a(t,5):1+16*--t*t*t*t*t,inSine:t=>1-Math.cos(t*Math.PI/2),outSine:t=>Math.sin(t*Math.PI/2),inOutSine:t=>-(Math.cos(Math.PI*t)-1)/2,inBack:(t,e=1.70158)=>t*t*((e+1)*t-e),outBack:(t,e=1.70158)=>(t-=1)*t*((e+1)*t+e)+1,inOutBack:(t,e=1.70158)=>(t*=2)<1?t*t*((1.525*e+1)*t-1.525*e)*.5:.5*((t-=2)*t*((1.525*e+1)*t+1.525*e)+2),inExpo:t=>0===t?0:Math.pow(2,10*(t-1)),outExpo:t=>1===t?1:1-Math.pow(2,-10*t),inOutExpo:t=>0===t?0:1===t?1:t<.5?.5*Math.pow(2,20*t-10):1-.5*Math.pow(2,-20*t+10),inElastic:(t,e=1,s=.5)=>0===t?0:1===t?1:-e*Math.pow(2,10*(t-1))*Math.sin((t-1-s/o*Math.asin(1/e))*o/s),outElastic:(t,e=1,s=.5)=>0===t?0:1===t?1:e*Math.pow(2,-10*t)*Math.sin((t-s/o*Math.asin(1/e))*o/s)+1,inOutElastic:(t,e=1,s=.5)=>0===t?0:1===t?1:t<.5?-.5*e*Math.pow(2,20*t-10)*Math.sin((20*t-11.125)*o/s):.5*e*Math.pow(2,-20*t+10)*Math.sin((20*t-11.125)*o/s)+1},p={pingPong:function(t){return t<=.5?this._easing(2*t):1-this._easing(2*(t-.5))},yoyo:function(t){return this._easing(h.yoyo(t))},bounce:function(t){return h.yoyo(this._easing(t))}};let c=0;class l extends i{on(...t){return super.on(...t),this}off(...t){return super.off(...t),this}once(...t){return super.once(...t),this}onComplete(...t){return super.on(r.COMPLETE,...t),this}onUpdate(...t){return super.on(r.UPDATE,...t),this}onceComplete(...t){return super.once(r.COMPLETE,...t),this}static DEFAULTS=n;static _noop(){}static mergeConfigs(t,e){t!==e&&Object.keys(e).forEach(s=>{"object"==typeof e[s]&&null!==e[s]?(t[s]&&"object"==typeof t[s]||(t[s]={}),l.mergeConfigs(t[s],e[s])):t[s]=e[s]})}static lerp(t,e,s){return t+(e-t)*s}constructor(t={},e){super(),this.index=c++,this.overrides=t,this.settings={},this.reset(t),e&&(this.manager=e),this.lastDeltaTime=0}_processState(){this.step=l._noop,this.progress=0,this.easeValue=0,this.elapsedTime=0,this.promise=null,this._resolve=l._noop,this._refreshDynamicProps()}_refreshDynamicProps(){this.applyProcessors(this.settings);const{target:t,time:e,repeat:s,loop:i,reversed:n,delay:r}=this.settings;this.target=t,this.time=Math.max(e,0),this.repeat=s>0?s:i?1/0:0,this.reversed=n,this.remainingDelay=r,this._processEasing()}_processEasing(){const t="string"==typeof this.settings.easing?h[this.settings.easing]||h.linear:this.settings.easing;this._easing=this.reversed?this._reversedEasing:t;const e="string"==typeof this.settings.mode?p[this.settings.mode]:this.settings.mode;this._calculateEasing=e?e.bind(this):this._easing}_reversedEasing=t=>this.settings.easing(1-t);_update(){this.progress=this.elapsedTime/this.time,this.easeValue=this._calculateEasing(this.progress),this.emit(r.UPDATE,this)}_stepDelay=t=>{this.remainingDelay-=t,this.lastDeltaTime=t,this.remainingDelay>0||(this.emit(r.BEGIN),this.step=this._stepTime,this.step(Math.abs(this.remainingDelay)),this.remainingDelay=this.settings.delay)};_stepTime=(t=0)=>{this.elapsedTime+=t,this.lastDeltaTime=t,this.elapsedTime>=this.time?(this.elapsedTime=this.time,this._update(),this._complete()):this._update()};_complete(){this.repeat-- >0?this._repeat():(this._resolve(),this.stop(!1),this.emit(r.COMPLETE))}_repeat(t=!0){this.remainingDelay=this.settings.repeatDelay,this.elapsedTime=0,this.remainingDelay>0&&(this.step=this._stepDelay),this._update(),t&&this.emit(r.REPEAT)}reset(t=this.constructor.DEFAULTS){return this.settings={...this.constructor.DEFAULTS,...t},this._processState(),this}applyProcessors(t=this.settings){t.processors.forEach(e=>{l.mergeConfigs(t,e.call(this,t)||{})})}tweak(t={}){return l.mergeConfigs(this.settings,t),this._refreshDynamicProps(),this}seek(t=0,e=!0){return this.elapsedTime=Math.min(Math.max(t,0),this.time),e&&this._update(),this}setProgress(t=0,e=!0){return this.seek(this.time*t,e)}reverse(t=!1){return this.reversed=!this.reversed,this.seek(this.time-this.elapsedTime,t),this._processEasing(),this}play(t=!0){return this.isPlaying||(this.settings.autoApplyProcessors&&this._refreshDynamicProps(),t&&this.emit(r.PLAY),this.remainingDelay>0?this.step=this._stepDelay:(this.step=this._stepTime,this.emit(r.BEGIN)),this.manager&&this.manager.addToActive(this)),this}playPromise(t=this.promise){return this.play(),this.promise=t||new Promise(t=>{this._resolve=t}),this.promise}stop(t=!0){return this._processState(),t&&this.emit(r.STOP),this.manager&&this.manager.removeFromActive(this),this}pause(){return this.step=l._noop,this.manager&&this.manager.removeFromActive(this),this}replay(t=!1){return this.stop(t),this.play(t),this}get isPlaying(){return this.step!==l._noop}remove(){this.stop(),this.manager.remove(this)}}class u extends l{static DEFAULTS={...l.DEFAULTS,properties:null,points:[],smoothing:20};_preparePropertySetters(){this.propertySetters=this.properties.map(t=>{const e=t.split("."),s=e.pop();return t=>{let i=this.target;for(let t=0;t<e.length;t++)i=i[e[t]];i[s]=t}})}_generatePath(){const t=this.settings.points,e=Math.max(this.settings.smoothing,1),s=[];function i(t,e,s,i,n){const r=n*n,o=r*n;return t.map((a,h)=>.5*(2*e[h]+(-t[h]+s[h])*n+(2*t[h]-5*e[h]+4*s[h]-i[h])*r+(-t[h]+3*e[h]-3*s[h]+i[h])*o))}this.totalLength=0;for(let n=0;n<t.length-1;n++){const r=t[0===n?n:n-1],o=t[n],a=t[n+1],h=t[n+2<t.length?n+2:n+1];for(let t=0;t<e;t++){const n=i(r,o,a,h,t/e);s.push(n),s.length>1&&(this.totalLength+=this._calculateDistance(s[s.length-2],n))}}return s.push(t[t.length-1]),s}_calculateDistance(t,e){return Math.sqrt(t.reduce((s,i,n)=>s+Math.pow(e[n]-t[n],2),0))}_refreshDynamicProps(){super._refreshDynamicProps(),this.path=this._generatePath(),this.target&&0!==this.path.length?(this._tryToSetupProperties(),this._preparePropertySetters()):this._setTargetProperties=l._noop}_tryToSetupProperties(){if(this.settings.properties)this.properties=this.settings.properties;else if(this.path[0].length<=3){const t=[["position.x"],["position.x","position.y"],["position.x","position.y","position.z"]];this.properties=t[this.path[0].length-1]}else this.properties=[]}_setTargetProperties(t){for(let e=0;e<this.propertySetters.length;e++)this.propertySetters[e](t[e])}_clamp(t,e,s){return Math.max(e,Math.min(t,s))}_getInterpolatedPosition(){const t=this.path.length-1,e=this.easeValue*t,s=this._clamp(e,0,t),i=s>=t?t-1:Math.floor(s),n=Math.min(i+1,t),r=e-i,o=this.path[i],a=this.path[n];return o.map((t,e)=>l.lerp(t,a[e],r))}_update(){super._update(),this._setTargetProperties(this._getInterpolatedPosition())}}class m extends l{static DEFAULTS={...l.DEFAULTS,dynamic:!1,from:null,to:null};_refreshDynamicProps(){super._refreshDynamicProps(),this._processFromTo()}_processFromTo(){this._lerps=[],this.target&&(this._setupStates(),this._createLerps())}_setupStates(){this._from=this.settings.from||this._createState(this.settings.to||{},this.target),this._to=this.settings.to||this._createState(this.settings.from||{},this.target)}_createState(t={},e={},s={}){const i=(t,e,s)=>{for(const n in t)"object"==typeof t[n]?(s[n]={},i(t[n],e[n],s[n])):s[n]=e[n]};return i(t,e,s),s}_createLerpStep(t,e,s,i){if(this.settings.dynamic)return()=>{t[i]=l.lerp(e[i],s[i],this.easeValue)};{const n=e[i],r=s[i]-n;return()=>{t[i]=n+r*this.easeValue}}}_createLerps(t=this.target,e=this._from,s=this._to){for(const i in s)"object"==typeof s[i]?this._createLerps(t[i],e[i],s[i]):this._lerps.push(this._createLerpStep(t,e,s,i))}_update(){super._update();for(const t of this._lerps)t()}from(t={}){return this.tweak({from:t}),this}to(t={}){return this.tweak({to:t}),this}swap(){return this.tweak({from:this.settings.to,to:this.settings.from}),this}}function g(t){return t.target?t.creator?t.creator instanceof l?t.creator:(console.error("Invalid creator provided. Using default creator."),l):t.points?u:t.from||t.to?m:l:l}class f{constructor(){this.activeAnimations=new Map,this.allAnimations=new Map}create({on:t={},once:e={},...s}){const i=new(g(s))(s,this);return Object.keys(t).forEach(e=>{i.on(e,t[e])}),Object.keys(e).forEach(t=>{i.once(t,e[t])}),this.add(i),i}update=t=>{this.activeAnimations.forEach(e=>{e.step(t)})};getActiveAnimations(){return Array.from(this.activeAnimations.values())}getAllAnimations(){return Array.from(this.allAnimations.values())}remove({index:t}={}){t&&(this.activeAnimations.delete(t),this.allAnimations.delete(t))}add(t){this.allAnimations.set(t.index,t)}addToActive(t){this.activeAnimations.set(t.index,t)}removeFromActive(t){this.activeAnimations.delete(t.index)}stopAll(){this.activeAnimations.forEach(t=>{t.stop()})}removeAll(){this.stopAll(),this.activeAnimations.clear(),this.allAnimations.clear()}}const _=new f;class y{constructor(t,e={}){this.callback=t,this.options={maxDeltaTime:100,...e},this.isRunning=!1,this.lastTime=0,this.animationId=null}static start(t,e={}){const s=new y(t,e);return s.start(),s}start(){if(this.isRunning)return;this.isRunning=!0;const t=e=>{if(!this.isRunning)return;const s=Math.min(e-this.lastTime,this.options.maxDeltaTime);this.lastTime=e,this.callback(s),this.isRunning&&(this.animationId=requestAnimationFrame(t))};requestAnimationFrame(e=>{this.lastTime=e,t(e)})}stop(){this.isRunning=!1,this.animationId&&(cancelAnimationFrame(this.animationId),this.animationId=null)}get running(){return this.isRunning}}function v(t,e){const s=new new g(t)(t);return y.start(s.step.bind(s)),e?s.playPromise():s.play()}export{l as Core,u as Curve,n as DEFAULTS,r as EVENTS,m as FromTo,_ as GlobalManager,y as Loop,f as Manager,h as easings,p as modes,v as play};
|
package/kill-port.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const { exec } = require('child_process');
|
|
2
|
-
|
|
3
|
-
exec('netstat -ano | findstr :8081', (error, stdout) => {
|
|
4
|
-
if (stdout) {
|
|
5
|
-
const lines = stdout.trim().split('\n');
|
|
6
|
-
lines.forEach(line => {
|
|
7
|
-
const parts = line.trim().split(/\s+/);
|
|
8
|
-
const pid = parts[parts.length - 1];
|
|
9
|
-
if (pid && pid !== '0') {
|
|
10
|
-
exec(`taskkill /PID ${pid} /F`, (err) => {
|
|
11
|
-
if (!err) console.log(`Killed process ${pid} on port 8081`);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
});
|
package/src/behaviors/easings.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
// created by chatGPT
|
|
3
|
-
const PI2 = Math.PI * 2
|
|
4
|
-
const pow = Math.pow
|
|
5
|
-
|
|
6
|
-
export const easings = {
|
|
7
|
-
reverse: (t) => 1 - t,
|
|
8
|
-
linear: (t) => t,
|
|
9
|
-
yoyo: (t) => 1 - Math.abs(1 - t * 2),
|
|
10
|
-
|
|
11
|
-
inQuad: (t) => pow(t, 2),
|
|
12
|
-
outQuad: (t) => t * (2 - t),
|
|
13
|
-
inOutQuad: (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t,
|
|
14
|
-
|
|
15
|
-
inCubic: (t) => pow(t, 3),
|
|
16
|
-
outCubic: (t) => (--t) * t * t + 1,
|
|
17
|
-
inOutCubic: (t) => t < 0.5 ? 4 * pow(t, 3) : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1,
|
|
18
|
-
|
|
19
|
-
inQuart: (t) => pow(t, 4),
|
|
20
|
-
outQuart: (t) => 1 - (--t) * pow(t, 3),
|
|
21
|
-
inOutQuart: (t) => t < 0.5 ? 8 * pow(t, 4) : 1 - 8 * (--t) * t * t * t,
|
|
22
|
-
|
|
23
|
-
inQuint: (t) => pow(t, 5),
|
|
24
|
-
outQuint: (t) => 1 + (--t) * pow(t, 4),
|
|
25
|
-
inOutQuint: (t) => t < 0.5 ? 16 * pow(t, 5) : 1 + 16 * (--t) * t * t * t * t,
|
|
26
|
-
|
|
27
|
-
inSine: (t) => 1 - Math.cos((t * Math.PI) / 2),
|
|
28
|
-
outSine: (t) => Math.sin((t * Math.PI) / 2),
|
|
29
|
-
inOutSine: (t) => -(Math.cos(Math.PI * t) - 1) / 2,
|
|
30
|
-
|
|
31
|
-
inBack: (t, s = 1.70158) => t * t * ((s + 1) * t - s),
|
|
32
|
-
outBack: (t, s = 1.70158) => ((t -= 1) * t * ((s + 1) * t + s) + 1),
|
|
33
|
-
inOutBack: (t, s = 1.70158) =>
|
|
34
|
-
(t *= 2) < 1
|
|
35
|
-
? 0.5 * (t * t * ((s * 1.525 + 1) * t - s * 1.525))
|
|
36
|
-
: 0.5 * ((t -= 2) * t * ((s * 1.525 + 1) * t + s * 1.525) + 2),
|
|
37
|
-
|
|
38
|
-
inExpo: (t) => (t === 0 ? 0 : Math.pow(2, 10 * (t - 1))),
|
|
39
|
-
outExpo: (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)),
|
|
40
|
-
inOutExpo: (t) => (
|
|
41
|
-
t === 0
|
|
42
|
-
? 0
|
|
43
|
-
: t === 1
|
|
44
|
-
? 1
|
|
45
|
-
: t < 0.5
|
|
46
|
-
? 0.5 * Math.pow(2, 20 * t - 10)
|
|
47
|
-
: 1 - 0.5 * Math.pow(2, -20 * t + 10)
|
|
48
|
-
),
|
|
49
|
-
|
|
50
|
-
inElastic: (t, a = 1, p = 0.5) => (
|
|
51
|
-
t === 0
|
|
52
|
-
? 0
|
|
53
|
-
: t === 1
|
|
54
|
-
? 1
|
|
55
|
-
: -a * Math.pow(2, 10 * (t - 1)) * Math.sin(((t - 1 - p / PI2 * Math.asin(1 / a)) * PI2) / p)
|
|
56
|
-
),
|
|
57
|
-
outElastic: (t, a = 1, p = 0.5) => (
|
|
58
|
-
t === 0
|
|
59
|
-
? 0
|
|
60
|
-
: t === 1
|
|
61
|
-
? 1
|
|
62
|
-
: a * Math.pow(2, -10 * t) * Math.sin(((t - p / PI2 * Math.asin(1 / a)) * PI2) / p) + 1
|
|
63
|
-
),
|
|
64
|
-
inOutElastic: (t, a = 1, p = 0.5) => (
|
|
65
|
-
t === 0
|
|
66
|
-
? 0
|
|
67
|
-
: t === 1
|
|
68
|
-
? 1
|
|
69
|
-
: t < 0.5
|
|
70
|
-
? -0.5 * a * Math.pow(2, 20 * t - 10) * Math.sin(((20 * t - 11.125) * PI2) / p)
|
|
71
|
-
: 0.5 * a * Math.pow(2, -20 * t + 10) * Math.sin(((20 * t - 11.125) * PI2) / p) + 1
|
|
72
|
-
)
|
|
73
|
-
}
|
package/src/behaviors/modes.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { easings } from "./easings"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Object containing animation modifiers.
|
|
5
|
-
* @namespace
|
|
6
|
-
* @property {function} pingPong - Implements ping-pong effect for animation.
|
|
7
|
-
* @property {function} yoyo - Implements mirror reflection effect for animation.
|
|
8
|
-
* @property {function} bounce - Implements bounce effect for animation.
|
|
9
|
-
* @example
|
|
10
|
-
* const animation = new Core({ time: 1000, mode: modes.pingPong })
|
|
11
|
-
* animation.play()
|
|
12
|
-
* @see {@link Core}
|
|
13
|
-
* @see {@link easings}
|
|
14
|
-
*/
|
|
15
|
-
export const modes = {
|
|
16
|
-
/**
|
|
17
|
-
* Implements ping-pong effect for animation.
|
|
18
|
-
* @param {number} t - Current animation time.
|
|
19
|
-
* @returns {number} Modified time value for ping-pong effect.
|
|
20
|
-
*/
|
|
21
|
-
pingPong: function (t) {
|
|
22
|
-
return t <= 0.5
|
|
23
|
-
? this._easing(t * 2)
|
|
24
|
-
: 1 - this._easing((t - 0.5) * 2)
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Implements mirror reflection effect for animation.
|
|
29
|
-
* @param {number} t - Current animation time.
|
|
30
|
-
* @returns {number} Modified time value for mirror reflection effect.
|
|
31
|
-
*/
|
|
32
|
-
yoyo: function (t) {
|
|
33
|
-
return this._easing(easings.yoyo(t))
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Implements bounce effect for animation.
|
|
38
|
-
* @param {number} t - Current animation time.
|
|
39
|
-
* @returns {number} Modified time value for bounce effect.
|
|
40
|
-
*/
|
|
41
|
-
bounce: function (t) {
|
|
42
|
-
return easings.yoyo(this._easing(t))
|
|
43
|
-
},
|
|
44
|
-
}
|
package/src/controllers/Curve.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { Core } from "../core/Core"
|
|
2
|
-
|
|
3
|
-
export class Curve extends Core {
|
|
4
|
-
static DEFAULTS = {
|
|
5
|
-
...Core.DEFAULTS,
|
|
6
|
-
properties: null,
|
|
7
|
-
points: [],
|
|
8
|
-
smoothing: 20,
|
|
9
|
-
// useLerp: true,
|
|
10
|
-
// path: [],
|
|
11
|
-
// speed: 1,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
_preparePropertySetters() {
|
|
15
|
-
this.propertySetters = this.properties.map(property => {
|
|
16
|
-
const keys = property.split('.')
|
|
17
|
-
const lastKey = keys.pop()
|
|
18
|
-
|
|
19
|
-
return (value) => {
|
|
20
|
-
let obj = this.target
|
|
21
|
-
for (let i = 0; i < keys.length; i++) {
|
|
22
|
-
obj = obj[keys[i]]
|
|
23
|
-
}
|
|
24
|
-
obj[lastKey] = value
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
_generatePath() {
|
|
30
|
-
const points = this.settings.points
|
|
31
|
-
const smoothing = Math.max(this.settings.smoothing, 1)
|
|
32
|
-
|
|
33
|
-
const result = []
|
|
34
|
-
this.totalLength = 0
|
|
35
|
-
|
|
36
|
-
function interpolate(p0, p1, p2, p3, t) {
|
|
37
|
-
const t2 = t * t
|
|
38
|
-
const t3 = t2 * t
|
|
39
|
-
|
|
40
|
-
return p0.map((_, i) =>
|
|
41
|
-
0.5 * (
|
|
42
|
-
(2 * p1[i]) +
|
|
43
|
-
(-p0[i] + p2[i]) * t +
|
|
44
|
-
(2 * p0[i] - 5 * p1[i] + 4 * p2[i] - p3[i]) * t2 +
|
|
45
|
-
(-p0[i] + 3 * p1[i] - 3 * p2[i] + p3[i]) * t3
|
|
46
|
-
)
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
51
|
-
const p0 = points[i === 0 ? i : i - 1]
|
|
52
|
-
const p1 = points[i]
|
|
53
|
-
const p2 = points[i + 1]
|
|
54
|
-
const p3 = points[i + 2 < points.length ? i + 2 : i + 1]
|
|
55
|
-
|
|
56
|
-
for (let t = 0; t < smoothing; t++) {
|
|
57
|
-
const pt = interpolate(p0, p1, p2, p3, t / smoothing)
|
|
58
|
-
result.push(pt)
|
|
59
|
-
|
|
60
|
-
if (result.length > 1) {
|
|
61
|
-
this.totalLength += this._calculateDistance(result[result.length - 2], pt)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
result.push(points[points.length - 1])
|
|
67
|
-
|
|
68
|
-
return result
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
_calculateDistance(p1, p2) {
|
|
72
|
-
return Math.sqrt(p1.reduce((acc, _, i) => acc + Math.pow(p2[i] - p1[i], 2), 0))
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
_refreshDynamicProps() {
|
|
76
|
-
super._refreshDynamicProps()
|
|
77
|
-
this.path = this._generatePath()
|
|
78
|
-
|
|
79
|
-
if (!this.target || this.path.length === 0) {
|
|
80
|
-
this._setTargetProperties = Core._noop
|
|
81
|
-
|
|
82
|
-
} else {
|
|
83
|
-
this._tryToSetupProperties()
|
|
84
|
-
this._preparePropertySetters()
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
_tryToSetupProperties() {
|
|
90
|
-
if (this.settings.properties) {
|
|
91
|
-
this.properties = this.settings.properties
|
|
92
|
-
|
|
93
|
-
} else if (this.path[0].length <= 3) {
|
|
94
|
-
|
|
95
|
-
const propertiesLists = [
|
|
96
|
-
['position.x'],
|
|
97
|
-
['position.x', 'position.y'],
|
|
98
|
-
['position.x', 'position.y', 'position.z'],
|
|
99
|
-
]
|
|
100
|
-
|
|
101
|
-
this.properties = propertiesLists[this.path[0].length - 1]
|
|
102
|
-
|
|
103
|
-
} else {
|
|
104
|
-
this.properties = []
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
_setTargetProperties(values) {
|
|
110
|
-
for (let i = 0; i < this.propertySetters.length; i++) {
|
|
111
|
-
this.propertySetters[i](values[i])
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
_clamp(value, min, max) {
|
|
116
|
-
return Math.max(min, Math.min(value, max))
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
_getInterpolatedPosition() {
|
|
120
|
-
const maxIndex = this.path.length - 1
|
|
121
|
-
const exactIndex = this.easeValue * maxIndex
|
|
122
|
-
const clampedExactIndex = this._clamp(exactIndex, 0, maxIndex)
|
|
123
|
-
|
|
124
|
-
// Determine the indices of the two neighboring points
|
|
125
|
-
const lowerIndex = clampedExactIndex >= maxIndex ? maxIndex - 1 : Math.floor(clampedExactIndex)
|
|
126
|
-
const upperIndex = Math.min(lowerIndex + 1, maxIndex)
|
|
127
|
-
|
|
128
|
-
const interpolationFactor = exactIndex - lowerIndex
|
|
129
|
-
|
|
130
|
-
const lowerPoint = this.path[lowerIndex]
|
|
131
|
-
const upperPoint = this.path[upperIndex]
|
|
132
|
-
|
|
133
|
-
return lowerPoint.map((coord, i) =>
|
|
134
|
-
Core.lerp(coord, upperPoint[i], interpolationFactor)
|
|
135
|
-
)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
_update() {
|
|
139
|
-
super._update()
|
|
140
|
-
this._setTargetProperties(this._getInterpolatedPosition())
|
|
141
|
-
}
|
|
142
|
-
}
|