@litecanvas/utils 0.36.0 → 0.38.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/actor.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var x=Object.defineProperty;var u=(o,t)=>{for(var s in t)x(o,s,{get:t[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(o=!0)=>{for(let t in globalThis.utils)t!=="global"&&(o||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var p={};u(p,{ANCHOR_BOT_LEFT:()=>g,ANCHOR_BOT_RIGHT:()=>_,ANCHOR_CENTER:()=>a,ANCHOR_TOP_LEFT:()=>y,ANCHOR_TOP_RIGHT:()=>f,Actor:()=>h});var T=2*Math.PI,i=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},l=o=>o instanceof i,e=(o=0,t=o)=>(l(o)&&(t=o.y,o=o.x),new i(o,t));var a=e(.5,.5),y=e(0,0),f=e(1,0),g=e(0,1),_=e(1,1),h=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,r=y){this.sprite=t,this.pos=s||e(0),this._o=e(r),this._s=e(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,s=t){this._s.x=t,this._s.y=s}scaleBy(t,s=t){this._s.x*=t,this._s.y*=s}getBounds(t=!0){let s=this.sprite.width*(t?this._s.x:1),r=this.sprite.height*(t?this._s.y:1),n=this.pos.x-s*this.anchor.x,c=this.pos.y-r*this.anchor.y;return[n,c,s,r]}draw(t=globalThis,s=!0){this.hidden||this.opacity<=0||(s&&t.push(),this.transform(t),this.drawImage(t),s&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,s=!0){let r=this.anchor,n=-this.sprite.width*(this.flipX?1-r.x:r.x),c=-this.sprite.height*(this.flipY?1-r.y:r.y);s&&t.alpha(this.opacity),t.image(n,c,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},p);})();
1
+ (()=>{var x=Object.defineProperty;var u=(o,t)=>{for(var s in t)x(o,s,{get:t[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(o=!0)=>{for(let t in globalThis.utils)t!=="global"&&(o||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var p={};u(p,{ANCHOR_BOT_LEFT:()=>g,ANCHOR_BOT_RIGHT:()=>_,ANCHOR_CENTER:()=>a,ANCHOR_TOP_LEFT:()=>y,ANCHOR_TOP_RIGHT:()=>f,Actor:()=>h});var T=2*Math.PI,i=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},l=o=>o instanceof i,r=(o=0,t=o)=>(l(o)&&(t=o.y,o=o.x),new i(o,t));var a=r(.5,.5),y=r(0,0),f=r(1,0),g=r(0,1),_=r(1,1),h=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,e=y){this.sprite=t,this.pos=s||r(0),this._o=r(e),this._s=r(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,s=t){this._s.x=t,this._s.y=s}scaleBy(t,s=t){this._s.x*=t,this._s.y*=s}getBounds(t=!0){let s=this.sprite.width*(t?this._s.x:1),e=this.sprite.height*(t?this._s.y:1),n=this.pos.x-s*this.anchor.x,c=this.pos.y-e*this.anchor.y;return[n,c,s,e]}draw(t=globalThis,s=!0){this.hidden||this.opacity<=0||(s&&t.push(),this.transform(t),this.drawImage(t),s&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,s=!0){let e=this.anchor,n=-this.sprite.width*(this.flipX?1-e.x:e.x),c=-this.sprite.height*(this.flipY?1-e.y:e.y);s&&t.alpha(this.opacity),t.image(n,c,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},p);})();
package/dist/all.js CHANGED
@@ -56,6 +56,7 @@
56
56
  diff: () => diff_default,
57
57
  dist: () => dist_default,
58
58
  flipImage: () => flip_default,
59
+ formatTime: () => format_time_default,
59
60
  fract: () => fract_default,
60
61
  head: () => head_default,
61
62
  intersection: () => intersection_default,
@@ -67,6 +68,7 @@
67
68
  mean: () => mean_default,
68
69
  median: () => median_default,
69
70
  mod: () => mod_default,
71
+ percent: () => percent_default,
70
72
  range: () => range_default,
71
73
  resolverect: () => resolverect_default,
72
74
  scaleImage: () => scale_default,
@@ -89,6 +91,7 @@
89
91
  vecDot: () => vecDot,
90
92
  vecEq: () => vecEq,
91
93
  vecFloor: () => vecFloor,
94
+ vecHeading: () => vecHeading,
92
95
  vecIsZero: () => vecIsZero,
93
96
  vecLerp: () => vecLerp,
94
97
  vecLimit: () => vecLimit,
@@ -578,7 +581,6 @@
578
581
  }
579
582
 
580
583
  // src/vector/index.js
581
- var sqrt = Math.sqrt;
582
584
  var cos = Math.cos;
583
585
  var sin = Math.sin;
584
586
  var PI2 = 2 * Math.PI;
@@ -684,8 +686,7 @@
684
686
  var vecLimit = (v, max = 1) => {
685
687
  const sq = vecMag2(v);
686
688
  if (sq > max * max) {
687
- vecDiv(v, sqrt(sq));
688
- vecMult(v, max);
689
+ vecSetMag(v, max);
689
690
  }
690
691
  return v;
691
692
  };
@@ -697,7 +698,8 @@
697
698
  const dy = a.y - b.y;
698
699
  return dx * dx + dy * dy;
699
700
  };
700
- var vecAngle = (v) => Math.atan2(v.y, v.x);
701
+ var vecHeading = (v) => Math.atan2(v.y, v.x);
702
+ var vecAngle = (v) => vecHeading(v);
701
703
  var vecAngleBetween = (v1, v2) => Math.atan2(v2.y - v1.y, v2.x - v1.x);
702
704
  var vecDot = (a, b) => a.x * b.x + a.y * b.y;
703
705
  var vecCross = (a, b) => a.x * b.y - a.y * b.x;
@@ -967,6 +969,9 @@
967
969
  return start + dif * amount;
968
970
  };
969
971
 
972
+ // src/math/percent.js
973
+ var percent_default = (value, min = 0, max = 1) => max - min ? (value - min) / (max - min) : 0;
974
+
970
975
  // src/tween/index.js
971
976
  var HALF_PI = Math.PI / 2;
972
977
  var tween = (object, prop, toValue, duration = 1, easing = LINEAR) => {
@@ -1412,6 +1417,9 @@
1412
1417
  // src/collection/tail.js
1413
1418
  var tail_default = (values) => values.slice(1);
1414
1419
 
1420
+ // src/time/format-time.js
1421
+ var format_time_default = (t) => ~~(t / 60) + ":" + (t % 60 < 10 ? "0" : "") + ~~(t % 60);
1422
+
1415
1423
  // src/_web.js
1416
1424
  globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
1417
1425
  })();
package/dist/all.min.js CHANGED
@@ -1,3 +1,3 @@
1
- (()=>{var It=Object.defineProperty;var Mt=(e,t)=>{for(var s in t)It(e,s,{get:t[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(e=!0)=>{for(let t in globalThis.utils)t!=="global"&&(e||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var Z={};Mt(Z,{ANCHOR_BOT_LEFT:()=>$t,ANCHOR_BOT_RIGHT:()=>Gt,ANCHOR_CENTER:()=>zt,ANCHOR_TOP_LEFT:()=>J,ANCHOR_TOP_RIGHT:()=>Kt,Actor:()=>O,BACK_IN:()=>ee,BACK_IN_OUT:()=>re,BACK_OUT:()=>se,BOUNCE_IN:()=>at,BOUNCE_IN_OUT:()=>ne,BOUNCE_OUT:()=>B,Camera:()=>y,DOWN:()=>jt,EASE_IN:()=>Qt,EASE_IN_OUT:()=>te,EASE_OUT:()=>vt,ELASTIC_IN:()=>ie,ELASTIC_IN_OUT:()=>he,ELASTIC_OUT:()=>oe,Grid:()=>b,LEFT:()=>qt,LINEAR:()=>nt,Noise:()=>Y,ONE:()=>Xt,RIGHT:()=>Vt,TypedGrid:()=>N,UP:()=>Dt,Vector:()=>I,ZERO:()=>G,advance:()=>tt,choose:()=>dt,colcirc:()=>X,colrect:()=>W,diff:()=>Q,dist:()=>st,flipImage:()=>lt,fract:()=>v,head:()=>mt,intersection:()=>w,last:()=>gt,lerpAngle:()=>ht,mag:()=>rt,makeCircle:()=>pt,makeRectangle:()=>ft,mean:()=>it,median:()=>ot,mod:()=>et,range:()=>_t,resolverect:()=>H,scaleImage:()=>ct,shuffle:()=>xt,sum:()=>R,tail:()=>yt,tintImage:()=>ut,tween:()=>Jt,vec:()=>h,vecAbs:()=>Bt,vecAdd:()=>L,vecAngle:()=>Lt,vecAngleBetween:()=>kt,vecCeil:()=>Ft,vecClamp:()=>Ut,vecCross:()=>St,vecDist:()=>Nt,vecDist2:()=>At,vecDiv:()=>P,vecDot:()=>$,vecEq:()=>A,vecFloor:()=>Yt,vecIsZero:()=>Wt,vecLerp:()=>Ot,vecLimit:()=>Tt,vecMag:()=>z,vecMag2:()=>K,vecMove:()=>Ht,vecMult:()=>M,vecNorm:()=>S,vecRand:()=>Ct,vecReflect:()=>Pt,vecRotate:()=>bt,vecRound:()=>Zt,vecSet:()=>q,vecSetMag:()=>Rt,vecSub:()=>k});var y=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;constructor(t=null,s=0,r=0,i=null,o=null){this._engine=t||globalThis,this.ox=s,this.oy=r,this.resize(i||this._engine.W-s,o||this._engine.H-r),this.x=this.width/2,this.y=this.height/2,this._shake={x:0,y:0,removeListener:null}}resize(t,s){this.width=t,this.height=s,this._engine.emit("camera-resized",this)}start(t=!1){this._engine.push(),t&&this._engine.clip(i=>{i.rect(this.ox,this.oy,this.width,this.height)});let s=this.ox+this.width/2,r=this.oy+this.height/2;this._engine.translate(s,r),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(t,s){this.x=t,this.y=s}move(t,s){this.x+=t,this.y+=s}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,s,r={}){let i=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,s=(s-this.height/2-this.oy)/this.scale,r.x=i*t-o*s+this.x,r.y=o*t+i*s+this.y,r}getCameraPoint(t,s,r={}){let i=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=i*t-o*s,s=o*t+i*s,r.x=t*this.scale+this.width/2+this.ox,r.y=s*this.scale+this.height/2+this.oy,r}getBounds(){return[this.ox,this.oy,this.width,this.height]}shake(t=1,s=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",r=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),s-=r,s<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};var w=(e,t,s,r,i,o,n,a)=>{let l=Math.max(e,i),x=Math.min(e+s,i+n)-l,u=Math.max(t,o),d=Math.min(t+r,o+a)-u;return[l,u,x,d]};var H=(e,t,s,r,i,o,n,a)=>{let[l,x,u,d]=w(e,t,s,r,i,o,n,a),_="",g=e,c=t;return u<d?e<i?(_="right",g=i-s):(_="left",g=i+n):t<o?(_="bottom",c=o-r):(_="top",c=o+a),{direction:_,x:g,y:c}};var W=(e,t,s,r,i,o,n,a)=>e<i+n&&e+s>i&&t<o+a&&t+r>o;var X=(e,t,s,r,i,o)=>(r-e)*(r-e)+(i-t)*(i-t)<=(s+o)*(s+o);var b=class e{_w;_h;_c;constructor(t,s,r=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~s),this._c=r}[Symbol.iterator](){let t=0;return{next:()=>({value:[this.indexToPointX(t),this.indexToPointY(t),this._c[t++]],done:t>this._c.length})}}clone(){return new e(this._w,this._h,this._c)}clear(){this.forEach((t,s)=>this.set(t,s,void 0))}get width(){return this._w}get height(){return this._h}set(t,s,r){this._c[this.pointToIndex(t,s)]=r}get(t,s){return this._c[this.pointToIndex(t,s)]}has(t,s){return this.get(t,s)!=null}check(t,s){return t>=0&&t<this._w&&s>=0&&s<this._h}get length(){return this._w*this._h}pointToIndex(t,s){return this.clampX(~~t)+this.clampY(~~s)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,s=!1){let r=s?this.length-1:0,i=s?-1:this.length,o=s?-1:1;for(;r!==i;){let n=this.indexToPointX(r),a=this.indexToPointY(r),l=this._c[r];if(t(n,a,l,this)===!1)break;r+=o}}fill(t){this.forEach((s,r)=>{this.set(s,r,t)})}clampX(t){return D(t,0,this._w-1)}clampY(t){return D(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",s=!0){if(!s)return this._c.join(t);let r=[];return this.forEach((i,o,n)=>{r[o]=r[o]||"",r[o]+=n+t}),r.join(`
2
- `)}},N=class e extends b{constructor(t,s,r=Uint8Array){super(t,s,null),this._c=new r(this._w*this._h)}has(t,s){return this.get(t,s)!==0}clone(){let t=new e(this._w,this._h,this._c.constructor);return this.forEach((s,r,i)=>{t.set(s,r,i)}),t}};function D(e,t,s){return e<t?t:e>s?s:e}var Et=Math.sqrt,V=Math.cos,j=Math.sin,wt=2*Math.PI,I=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},m=e=>e instanceof I,h=(e=0,t=e)=>(m(e)&&(t=e.y,e=e.x),new I(e,t)),A=(e,t,s=t)=>m(t)?A(e,t.x,t.y):e.x===t&&e.y===s,q=(e,t,s=t)=>(m(t)?q(e,t.x,t.y):(e.x=t,e.y=s),e),L=(e,t,s=t)=>m(t)?L(e,t.x,t.y):(e.x+=t,e.y+=s,e),k=(e,t,s=t)=>m(t)?k(e,t.x,t.y):(e.x-=t,e.y-=s,e),M=(e,t,s=t)=>m(t)?M(e,t.x,t.y):(e.x*=t,e.y*=s,e),P=(e,t,s=t)=>m(t)?P(e,t.x,t.y):(e.x/=t||1,e.y/=s||1,e),bt=(e,t)=>{let s=V(t),r=j(t);return e.x=s*e.x-r*e.y,e.y=r*e.x+s*e.y,e},Pt=(e,t)=>{let s=S(h(t));return k(e,M(s,2*$(e,s)))},Rt=(e,t)=>(S(e),M(e,t),e),z=e=>Math.hypot(e.x,e.y),K=e=>e.x*e.x+e.y*e.y,S=e=>{let t=z(e);return t>0&&P(e,t),e},Tt=(e,t=1)=>{let s=K(e);return s>t*t&&(P(e,Et(s)),M(e,t)),e},Nt=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),At=(e,t)=>{let s=e.x-t.x,r=e.y-t.y;return s*s+r*r},Lt=e=>Math.atan2(e.y,e.x),kt=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),$=(e,t)=>e.x*t.x+e.y*t.y,St=(e,t)=>e.x*t.y-e.y*t.x,Ot=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),Ct=(e=1,t=e,s=globalThis.rand||Math.random)=>{let r=s()*wt,i=s()*(t-e)+e;return h(V(r)*i,j(r)*i)},Bt=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Ft=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),Yt=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),Zt=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Ut=(e,t,s)=>(e.x<t.x&&(e.x=t.x),e.x>s.x&&(e.x=s.x),e.y<t.y&&(e.y=t.y),e.y>s.y&&(e.y=s.y),e),Ht=(e,t,s=1)=>L(e,t.x*s,t.y*s),Wt=e=>A(e,G),G=h(0,0),Xt=h(1,1),Dt=h(0,-1),Vt=h(1,0),jt=h(0,1),qt=h(-1,0);var zt=h(.5,.5),J=h(0,0),Kt=h(1,0),$t=h(0,1),Gt=h(1,1),O=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,r=J){this.sprite=t,this.pos=s||h(0),this._o=h(r),this._s=h(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,s=t){this._s.x=t,this._s.y=s}scaleBy(t,s=t){this._s.x*=t,this._s.y*=s}getBounds(t=!0){let s=this.sprite.width*(t?this._s.x:1),r=this.sprite.height*(t?this._s.y:1),i=this.pos.x-s*this.anchor.x,o=this.pos.y-r*this.anchor.y;return[i,o,s,r]}draw(t=globalThis,s=!0){this.hidden||this.opacity<=0||(s&&t.push(),this.transform(t),this.drawImage(t),s&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,s=!0){let r=this.anchor,i=-this.sprite.width*(this.flipX?1-r.x:r.x),o=-this.sprite.height*(this.flipY?1-r.y:r.y);s&&t.alpha(this.opacity),t.image(i,o,this.sprite)}};var Q=(e,t)=>Math.abs(t-e)||0;var v=e=>e%1||0;var tt=(e,t,s,r=1)=>{s&&(t.x+=s.x*r,t.y+=s.y*r),e.x+=t.x*r,e.y+=t.y*r};var et=(e,t)=>(t+e%t)%t;var st=(e,t,s,r)=>Math.hypot(s-e,r-t);var rt=(e,t)=>Math.hypot(e,t);var R=e=>{let t=0;for(let s=0;s<e.length;s++)t+=e[s];return t};var it=e=>R(e)/e.length;var ot=(...e)=>{let t=e.sort((r,i)=>r-i),s=Math.floor(t.length/2);return t.length%2===0?(t[s-1]+t[s])/2:t[s]};var ht=(e,t,s)=>{let r=(t-e)%360;return r>180?r-=360:r<-180&&(r+=360),e+r*s};var T=Math.PI/2,Jt=(e,t,s,r=1,i=nt)=>new C(e,t,s,r,i),nt=e=>e,Qt=e=>e*e,vt=e=>-e*(e-2),te=e=>e<.5?2*e*e:-2*e*e+4*e-1,ee=e=>e*e*e-e*Math.sin(e*Math.PI),se=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},re=e=>{if(e<.5){let s=2*e;return .5*(s*s*s-s*Math.sin(s*Math.PI))}let t=1-(2*e-1);return .5*(1-(t*t*t-t*Math.sin(e*Math.PI)))+.5},ie=e=>Math.sin(13*T*e)*Math.pow(2,10*(e-1)),oe=e=>Math.sin(-13*T*(e+1))*Math.pow(2,-10*e)+1,he=e=>{if(e<.5){let r=Math.sin(13*T*(2*e)),i=Math.pow(2,10*(2*e-1));return .5*r*i}let t=Math.sin(-13*T*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},at=e=>1-B(1-e),B=e=>e<4/11?121*e*e/16:e<8/11?363/40*e*e-99/10*e+17/5:e<9/10?4356/361*e*e-35442/1805*e+16061/1805:54/5*e*e-513/25*e+268/25,ne=e=>e<.5?.5*at(e*2):.5*B(e*2-1)+.5,C=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,s,r,i,o){this._o=t,this._p=s,this._x=r,this._d=i,this._e=o,this._w=0}start(t){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let s=this._o[this._p]||0,r=this._rel?s+this._x:this._x;return this._lc=this._lc||t||globalThis,this._u=this._lc.listen("update",i=>{if(this._t<=this._w){this._t+=i;return}let o=this._t-this._w;this._o[this._p]=this._lc.lerp(s,r,this._e(o/this._d)),this._t+=i,o>=this._d&&(this._o[this._p]=r,this.stop())}),this}stop(t=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,t)for(let s of this._cb)s(this._o);return this}restart(t=null,s=!1){return this.stop(s).restart(t)}onEnd(t){return this._cb.push(t),this}chain(t){return this._ch.onEnd(()=>{this._cu=t.start(this._lc)}),this._ch=t,this}reset(){return this._cb.length=0,this.stop()}relative(t=!0){return this._rel=t,this}delay(t){return this._w=t,this}get current(){return this._cu}get progress(){return this.running&&this._t>this._w?(this._t-this._w)/this._d:0}};var F=e=>.5*(1-Math.cos(e*Math.PI)),Y=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,s=0,r=0){t<0&&(t=-t),s<0&&(s=-s),r<0&&(r=-r);let i=Math.floor(t),o=Math.floor(s),n=Math.floor(r),a=t-i,l=s-o,x=r-n,u,d,_=0,g=.5,c,p,E;for(let U=0;U<this._po;U++){let f=i+(o<<4)+(n<<8);u=F(a),d=F(l),c=this._p[f&4095],c+=u*(this._p[f+1&4095]-c),p=this._p[f+16&4095],p+=u*(this._p[f+16+1&4095]-p),c+=d*(p-c),f+=256,p=this._p[f&4095],p+=u*(this._p[f+1&4095]-p),E=this._p[f+16&4095],E+=u*(this._p[f+16+1&4095]-E),p+=d*(E-p),c+=F(x)*(p-c),_+=c*g,g*=this._pf,i<<=1,a*=2,o<<=1,l*=2,n<<=1,x*=2,a>=1&&(i++,a--),l>=1&&(o++,l--),x>=1&&(n++,x--)}return _}noiseDetail(t,s){t>0&&(this._po=t),s>0&&(this._pf=s)}noiseSeed(t=null){t!=null&&this._e.rseed(t);let s=this._e.rand||Math.random;for(let r=0;r<4096;r++)this._p[r]=s()}};var lt=(e,t=!0,s=!1,r=globalThis)=>r.paint(e.width,e.height,i=>{r.push(),r.scale(t?-1:1,s?-1:1),r.image(t?-e.width:0,s?-e.height:0,e),r.pop()});var ct=(e,t,s=!0,r=globalThis)=>r.paint(e.width*t,e.height*t,i=>{r.push(),i.imageSmoothingEnabled=!s,r.scale(t),r.image(0,0,e),r.pop()});var ut=(e,t,s=1,r=globalThis)=>r.paint(e.width,e.height,i=>{r.push(),r.alpha(s),r.rectfill(0,0,e.width,e.height,t),i.globalCompositeOperation="destination-atop",r.alpha(1),r.image(0,0,e),r.pop()});var pt=(e,t,{borderWidth:s=0,borderColor:r=0,engine:i=globalThis}={})=>{let o=e*2+s;return i.paint(o,o,()=>{i.circfill(o/2,o/2,e,t),s>0&&(i.linewidth(s),i.stroke(r))})};var ft=(e,t,s,{borderWidth:r=0,borderColor:i=0,engine:o=globalThis}={})=>{let n=e+r*2,a=t+r*2;return o.paint(n,a,()=>{let l=r>0;l&&o.cls(i),o.rectfill(l?r:0,l?r:0,e,t,s)})};var _t=(e,t=0,s=1)=>[...new Array(e).keys()].map(r=>t+s*r);var xt=(e,t=globalThis.rand||Math.random)=>{e=[...e];for(let s=e.length-1;s>0;s--){let r=Math.floor(t()*(s+1)),i=e[s];e[s]=e[r],e[r]=i}return e};var dt=(e,t=globalThis.rand||Math.random)=>e[Math.floor(t()*e.length)];var mt=e=>e[0];var gt=e=>e[e.length-1];var yt=e=>e.slice(1);globalThis.utils=Object.assign(globalThis.utils||{},Z);})();
1
+ (()=>{var bt=Object.defineProperty;var Pt=(e,t)=>{for(var s in t)bt(e,s,{get:t[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(e=!0)=>{for(let t in globalThis.utils)t!=="global"&&(e||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var Z={};Pt(Z,{ANCHOR_BOT_LEFT:()=>Jt,ANCHOR_BOT_RIGHT:()=>Qt,ANCHOR_CENTER:()=>$t,ANCHOR_TOP_LEFT:()=>v,ANCHOR_TOP_RIGHT:()=>Gt,Actor:()=>O,BACK_IN:()=>re,BACK_IN_OUT:()=>oe,BACK_OUT:()=>ie,BOUNCE_IN:()=>pt,BOUNCE_IN_OUT:()=>le,BOUNCE_OUT:()=>B,Camera:()=>y,DOWN:()=>zt,EASE_IN:()=>te,EASE_IN_OUT:()=>se,EASE_OUT:()=>ee,ELASTIC_IN:()=>he,ELASTIC_IN_OUT:()=>ae,ELASTIC_OUT:()=>ne,Grid:()=>w,LEFT:()=>Kt,LINEAR:()=>ct,Noise:()=>Y,ONE:()=>Vt,RIGHT:()=>jt,TypedGrid:()=>T,UP:()=>qt,Vector:()=>I,ZERO:()=>Q,advance:()=>st,choose:()=>yt,colcirc:()=>X,colrect:()=>W,diff:()=>tt,dist:()=>it,flipImage:()=>ut,formatTime:()=>wt,fract:()=>et,head:()=>It,intersection:()=>E,last:()=>Mt,lerpAngle:()=>at,mag:()=>ot,makeCircle:()=>xt,makeRectangle:()=>dt,mean:()=>ht,median:()=>nt,mod:()=>rt,percent:()=>lt,range:()=>mt,resolverect:()=>H,scaleImage:()=>ft,shuffle:()=>gt,sum:()=>P,tail:()=>Et,tintImage:()=>_t,tween:()=>vt,vec:()=>h,vecAbs:()=>Yt,vecAdd:()=>A,vecAngle:()=>St,vecAngleBetween:()=>Ot,vecCeil:()=>Zt,vecClamp:()=>Wt,vecCross:()=>Ct,vecDist:()=>Lt,vecDist2:()=>kt,vecDiv:()=>k,vecDot:()=>J,vecEq:()=>N,vecFloor:()=>Ut,vecHeading:()=>G,vecIsZero:()=>Dt,vecLerp:()=>Bt,vecLimit:()=>At,vecMag:()=>K,vecMag2:()=>$,vecMove:()=>Xt,vecMult:()=>b,vecNorm:()=>S,vecRand:()=>Ft,vecReflect:()=>Nt,vecRotate:()=>Tt,vecRound:()=>Ht,vecSet:()=>j,vecSetMag:()=>z,vecSub:()=>L});var y=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;constructor(t=null,s=0,r=0,i=null,o=null){this._engine=t||globalThis,this.ox=s,this.oy=r,this.resize(i||this._engine.W-s,o||this._engine.H-r),this.x=this.width/2,this.y=this.height/2,this._shake={x:0,y:0,removeListener:null}}resize(t,s){this.width=t,this.height=s,this._engine.emit("camera-resized",this)}start(t=!1){this._engine.push(),t&&this._engine.clip(i=>{i.rect(this.ox,this.oy,this.width,this.height)});let s=this.ox+this.width/2,r=this.oy+this.height/2;this._engine.translate(s,r),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(t,s){this.x=t,this.y=s}move(t,s){this.x+=t,this.y+=s}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,s,r={}){let i=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,s=(s-this.height/2-this.oy)/this.scale,r.x=i*t-o*s+this.x,r.y=o*t+i*s+this.y,r}getCameraPoint(t,s,r={}){let i=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=i*t-o*s,s=o*t+i*s,r.x=t*this.scale+this.width/2+this.ox,r.y=s*this.scale+this.height/2+this.oy,r}getBounds(){return[this.ox,this.oy,this.width,this.height]}shake(t=1,s=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",r=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),s-=r,s<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};var E=(e,t,s,r,i,o,n,a)=>{let l=Math.max(e,i),x=Math.min(e+s,i+n)-l,p=Math.max(t,o),d=Math.min(t+r,o+a)-p;return[l,p,x,d]};var H=(e,t,s,r,i,o,n,a)=>{let[l,x,p,d]=E(e,t,s,r,i,o,n,a),_="",g=e,c=t;return p<d?e<i?(_="right",g=i-s):(_="left",g=i+n):t<o?(_="bottom",c=o-r):(_="top",c=o+a),{direction:_,x:g,y:c}};var W=(e,t,s,r,i,o,n,a)=>e<i+n&&e+s>i&&t<o+a&&t+r>o;var X=(e,t,s,r,i,o)=>(r-e)*(r-e)+(i-t)*(i-t)<=(s+o)*(s+o);var w=class e{_w;_h;_c;constructor(t,s,r=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~s),this._c=r}[Symbol.iterator](){let t=0;return{next:()=>({value:[this.indexToPointX(t),this.indexToPointY(t),this._c[t++]],done:t>this._c.length})}}clone(){return new e(this._w,this._h,this._c)}clear(){this.forEach((t,s)=>this.set(t,s,void 0))}get width(){return this._w}get height(){return this._h}set(t,s,r){this._c[this.pointToIndex(t,s)]=r}get(t,s){return this._c[this.pointToIndex(t,s)]}has(t,s){return this.get(t,s)!=null}check(t,s){return t>=0&&t<this._w&&s>=0&&s<this._h}get length(){return this._w*this._h}pointToIndex(t,s){return this.clampX(~~t)+this.clampY(~~s)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,s=!1){let r=s?this.length-1:0,i=s?-1:this.length,o=s?-1:1;for(;r!==i;){let n=this.indexToPointX(r),a=this.indexToPointY(r),l=this._c[r];if(t(n,a,l,this)===!1)break;r+=o}}fill(t){this.forEach((s,r)=>{this.set(s,r,t)})}clampX(t){return D(t,0,this._w-1)}clampY(t){return D(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",s=!0){if(!s)return this._c.join(t);let r=[];return this.forEach((i,o,n)=>{r[o]=r[o]||"",r[o]+=n+t}),r.join(`
2
+ `)}},T=class e extends w{constructor(t,s,r=Uint8Array){super(t,s,null),this._c=new r(this._w*this._h)}has(t,s){return this.get(t,s)!==0}clone(){let t=new e(this._w,this._h,this._c.constructor);return this.forEach((s,r,i)=>{t.set(s,r,i)}),t}};function D(e,t,s){return e<t?t:e>s?s:e}var V=Math.cos,q=Math.sin,Rt=2*Math.PI,I=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},m=e=>e instanceof I,h=(e=0,t=e)=>(m(e)&&(t=e.y,e=e.x),new I(e,t)),N=(e,t,s=t)=>m(t)?N(e,t.x,t.y):e.x===t&&e.y===s,j=(e,t,s=t)=>(m(t)?j(e,t.x,t.y):(e.x=t,e.y=s),e),A=(e,t,s=t)=>m(t)?A(e,t.x,t.y):(e.x+=t,e.y+=s,e),L=(e,t,s=t)=>m(t)?L(e,t.x,t.y):(e.x-=t,e.y-=s,e),b=(e,t,s=t)=>m(t)?b(e,t.x,t.y):(e.x*=t,e.y*=s,e),k=(e,t,s=t)=>m(t)?k(e,t.x,t.y):(e.x/=t||1,e.y/=s||1,e),Tt=(e,t)=>{let s=V(t),r=q(t);return e.x=s*e.x-r*e.y,e.y=r*e.x+s*e.y,e},Nt=(e,t)=>{let s=S(h(t));return L(e,b(s,2*J(e,s)))},z=(e,t)=>(S(e),b(e,t),e),K=e=>Math.hypot(e.x,e.y),$=e=>e.x*e.x+e.y*e.y,S=e=>{let t=K(e);return t>0&&k(e,t),e},At=(e,t=1)=>($(e)>t*t&&z(e,t),e),Lt=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),kt=(e,t)=>{let s=e.x-t.x,r=e.y-t.y;return s*s+r*r},G=e=>Math.atan2(e.y,e.x),St=e=>G(e),Ot=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),J=(e,t)=>e.x*t.x+e.y*t.y,Ct=(e,t)=>e.x*t.y-e.y*t.x,Bt=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),Ft=(e=1,t=e,s=globalThis.rand||Math.random)=>{let r=s()*Rt,i=s()*(t-e)+e;return h(V(r)*i,q(r)*i)},Yt=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Zt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),Ut=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),Ht=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Wt=(e,t,s)=>(e.x<t.x&&(e.x=t.x),e.x>s.x&&(e.x=s.x),e.y<t.y&&(e.y=t.y),e.y>s.y&&(e.y=s.y),e),Xt=(e,t,s=1)=>A(e,t.x*s,t.y*s),Dt=e=>N(e,Q),Q=h(0,0),Vt=h(1,1),qt=h(0,-1),jt=h(1,0),zt=h(0,1),Kt=h(-1,0);var $t=h(.5,.5),v=h(0,0),Gt=h(1,0),Jt=h(0,1),Qt=h(1,1),O=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,r=v){this.sprite=t,this.pos=s||h(0),this._o=h(r),this._s=h(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,s=t){this._s.x=t,this._s.y=s}scaleBy(t,s=t){this._s.x*=t,this._s.y*=s}getBounds(t=!0){let s=this.sprite.width*(t?this._s.x:1),r=this.sprite.height*(t?this._s.y:1),i=this.pos.x-s*this.anchor.x,o=this.pos.y-r*this.anchor.y;return[i,o,s,r]}draw(t=globalThis,s=!0){this.hidden||this.opacity<=0||(s&&t.push(),this.transform(t),this.drawImage(t),s&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,s=!0){let r=this.anchor,i=-this.sprite.width*(this.flipX?1-r.x:r.x),o=-this.sprite.height*(this.flipY?1-r.y:r.y);s&&t.alpha(this.opacity),t.image(i,o,this.sprite)}};var tt=(e,t)=>Math.abs(t-e)||0;var et=e=>e%1||0;var st=(e,t,s,r=1)=>{s&&(t.x+=s.x*r,t.y+=s.y*r),e.x+=t.x*r,e.y+=t.y*r};var rt=(e,t)=>(t+e%t)%t;var it=(e,t,s,r)=>Math.hypot(s-e,r-t);var ot=(e,t)=>Math.hypot(e,t);var P=e=>{let t=0;for(let s=0;s<e.length;s++)t+=e[s];return t};var ht=e=>P(e)/e.length;var nt=(...e)=>{let t=e.sort((r,i)=>r-i),s=Math.floor(t.length/2);return t.length%2===0?(t[s-1]+t[s])/2:t[s]};var at=(e,t,s)=>{let r=(t-e)%360;return r>180?r-=360:r<-180&&(r+=360),e+r*s};var lt=(e,t=0,s=1)=>s-t?(e-t)/(s-t):0;var R=Math.PI/2,vt=(e,t,s,r=1,i=ct)=>new C(e,t,s,r,i),ct=e=>e,te=e=>e*e,ee=e=>-e*(e-2),se=e=>e<.5?2*e*e:-2*e*e+4*e-1,re=e=>e*e*e-e*Math.sin(e*Math.PI),ie=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},oe=e=>{if(e<.5){let s=2*e;return .5*(s*s*s-s*Math.sin(s*Math.PI))}let t=1-(2*e-1);return .5*(1-(t*t*t-t*Math.sin(e*Math.PI)))+.5},he=e=>Math.sin(13*R*e)*Math.pow(2,10*(e-1)),ne=e=>Math.sin(-13*R*(e+1))*Math.pow(2,-10*e)+1,ae=e=>{if(e<.5){let r=Math.sin(13*R*(2*e)),i=Math.pow(2,10*(2*e-1));return .5*r*i}let t=Math.sin(-13*R*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},pt=e=>1-B(1-e),B=e=>e<4/11?121*e*e/16:e<8/11?363/40*e*e-99/10*e+17/5:e<9/10?4356/361*e*e-35442/1805*e+16061/1805:54/5*e*e-513/25*e+268/25,le=e=>e<.5?.5*pt(e*2):.5*B(e*2-1)+.5,C=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,s,r,i,o){this._o=t,this._p=s,this._x=r,this._d=i,this._e=o,this._w=0}start(t){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let s=this._o[this._p]||0,r=this._rel?s+this._x:this._x;return this._lc=this._lc||t||globalThis,this._u=this._lc.listen("update",i=>{if(this._t<=this._w){this._t+=i;return}let o=this._t-this._w;this._o[this._p]=this._lc.lerp(s,r,this._e(o/this._d)),this._t+=i,o>=this._d&&(this._o[this._p]=r,this.stop())}),this}stop(t=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,t)for(let s of this._cb)s(this._o);return this}restart(t=null,s=!1){return this.stop(s).restart(t)}onEnd(t){return this._cb.push(t),this}chain(t){return this._ch.onEnd(()=>{this._cu=t.start(this._lc)}),this._ch=t,this}reset(){return this._cb.length=0,this.stop()}relative(t=!0){return this._rel=t,this}delay(t){return this._w=t,this}get current(){return this._cu}get progress(){return this.running&&this._t>this._w?(this._t-this._w)/this._d:0}};var F=e=>.5*(1-Math.cos(e*Math.PI)),Y=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,s=0,r=0){t<0&&(t=-t),s<0&&(s=-s),r<0&&(r=-r);let i=Math.floor(t),o=Math.floor(s),n=Math.floor(r),a=t-i,l=s-o,x=r-n,p,d,_=0,g=.5,c,u,M;for(let U=0;U<this._po;U++){let f=i+(o<<4)+(n<<8);p=F(a),d=F(l),c=this._p[f&4095],c+=p*(this._p[f+1&4095]-c),u=this._p[f+16&4095],u+=p*(this._p[f+16+1&4095]-u),c+=d*(u-c),f+=256,u=this._p[f&4095],u+=p*(this._p[f+1&4095]-u),M=this._p[f+16&4095],M+=p*(this._p[f+16+1&4095]-M),u+=d*(M-u),c+=F(x)*(u-c),_+=c*g,g*=this._pf,i<<=1,a*=2,o<<=1,l*=2,n<<=1,x*=2,a>=1&&(i++,a--),l>=1&&(o++,l--),x>=1&&(n++,x--)}return _}noiseDetail(t,s){t>0&&(this._po=t),s>0&&(this._pf=s)}noiseSeed(t=null){t!=null&&this._e.rseed(t);let s=this._e.rand||Math.random;for(let r=0;r<4096;r++)this._p[r]=s()}};var ut=(e,t=!0,s=!1,r=globalThis)=>r.paint(e.width,e.height,i=>{r.push(),r.scale(t?-1:1,s?-1:1),r.image(t?-e.width:0,s?-e.height:0,e),r.pop()});var ft=(e,t,s=!0,r=globalThis)=>r.paint(e.width*t,e.height*t,i=>{r.push(),i.imageSmoothingEnabled=!s,r.scale(t),r.image(0,0,e),r.pop()});var _t=(e,t,s=1,r=globalThis)=>r.paint(e.width,e.height,i=>{r.push(),r.alpha(s),r.rectfill(0,0,e.width,e.height,t),i.globalCompositeOperation="destination-atop",r.alpha(1),r.image(0,0,e),r.pop()});var xt=(e,t,{borderWidth:s=0,borderColor:r=0,engine:i=globalThis}={})=>{let o=e*2+s;return i.paint(o,o,()=>{i.circfill(o/2,o/2,e,t),s>0&&(i.linewidth(s),i.stroke(r))})};var dt=(e,t,s,{borderWidth:r=0,borderColor:i=0,engine:o=globalThis}={})=>{let n=e+r*2,a=t+r*2;return o.paint(n,a,()=>{let l=r>0;l&&o.cls(i),o.rectfill(l?r:0,l?r:0,e,t,s)})};var mt=(e,t=0,s=1)=>[...new Array(e).keys()].map(r=>t+s*r);var gt=(e,t=globalThis.rand||Math.random)=>{e=[...e];for(let s=e.length-1;s>0;s--){let r=Math.floor(t()*(s+1)),i=e[s];e[s]=e[r],e[r]=i}return e};var yt=(e,t=globalThis.rand||Math.random)=>e[Math.floor(t()*e.length)];var It=e=>e[0];var Mt=e=>e[e.length-1];var Et=e=>e.slice(1);var wt=e=>~~(e/60)+":"+(e%60<10?"0":"")+~~(e%60);globalThis.utils=Object.assign(globalThis.utils||{},Z);})();
3
3
  /*! @litecanvas/utils by Luiz Bills | MIT Licensed */
package/dist/math.js CHANGED
@@ -28,6 +28,7 @@
28
28
  mean: () => mean_default,
29
29
  median: () => median_default,
30
30
  mod: () => mod_default,
31
+ percent: () => percent_default,
31
32
  sum: () => sum_default
32
33
  });
33
34
 
@@ -98,6 +99,9 @@
98
99
  return start + dif * amount;
99
100
  };
100
101
 
102
+ // src/math/percent.js
103
+ var percent_default = (value, min = 0, max = 1) => max - min ? (value - min) / (max - min) : 0;
104
+
101
105
  // src/math/_web.js
102
106
  globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
103
107
  })();
package/dist/math.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var d=Object.defineProperty;var M=(e,t)=>{for(var r in t)d(e,r,{get:t[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(e=!0)=>{for(let t in globalThis.utils)t!=="global"&&(e||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var n={};M(n,{advance:()=>u,diff:()=>c,dist:()=>p,fract:()=>x,lerpAngle:()=>i,mag:()=>a,mean:()=>f,median:()=>y,mod:()=>l,sum:()=>s});var c=(e,t)=>Math.abs(t-e)||0;var x=e=>e%1||0;var T=2*Math.PI;var u=(e,t,r,o=1)=>{r&&(t.x+=r.x*o,t.y+=r.y*o),e.x+=t.x*o,e.y+=t.y*o};var l=(e,t)=>(t+e%t)%t;var p=(e,t,r,o)=>Math.hypot(r-e,o-t);var a=(e,t)=>Math.hypot(e,t);var s=e=>{let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t};var f=e=>s(e)/e.length;var y=(...e)=>{let t=e.sort((o,h)=>o-h),r=Math.floor(t.length/2);return t.length%2===0?(t[r-1]+t[r])/2:t[r]};var i=(e,t,r)=>{let o=(t-e)%360;return o>180?o-=360:o<-180&&(o+=360),e+o*r};globalThis.utils=Object.assign(globalThis.utils||{},n);})();
1
+ (()=>{var M=Object.defineProperty;var g=(e,t)=>{for(var r in t)M(e,r,{get:t[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(e=!0)=>{for(let t in globalThis.utils)t!=="global"&&(e||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var n={};g(n,{advance:()=>u,diff:()=>c,dist:()=>l,fract:()=>x,lerpAngle:()=>i,mag:()=>a,mean:()=>f,median:()=>y,mod:()=>p,percent:()=>h,sum:()=>s});var c=(e,t)=>Math.abs(t-e)||0;var x=e=>e%1||0;var R=2*Math.PI;var u=(e,t,r,o=1)=>{r&&(t.x+=r.x*o,t.y+=r.y*o),e.x+=t.x*o,e.y+=t.y*o};var p=(e,t)=>(t+e%t)%t;var l=(e,t,r,o)=>Math.hypot(r-e,o-t);var a=(e,t)=>Math.hypot(e,t);var s=e=>{let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t};var f=e=>s(e)/e.length;var y=(...e)=>{let t=e.sort((o,d)=>o-d),r=Math.floor(t.length/2);return t.length%2===0?(t[r-1]+t[r])/2:t[r]};var i=(e,t,r)=>{let o=(t-e)%360;return o>180?o-=360:o<-180&&(o+=360),e+o*r};var h=(e,t=0,r=1)=>r-t?(e-t)/(r-t):0;globalThis.utils=Object.assign(globalThis.utils||{},n);})();
package/dist/time.js ADDED
@@ -0,0 +1,30 @@
1
+ (() => {
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
7
+
8
+ // src/_global.js
9
+ globalThis.utils = globalThis.utils || {};
10
+ globalThis.utils.global = (overrides = true) => {
11
+ for (const key in globalThis.utils) {
12
+ if ("global" === key) continue;
13
+ if (overrides || globalThis[key] === void 0) {
14
+ globalThis[key] = globalThis.utils[key];
15
+ }
16
+ }
17
+ };
18
+
19
+ // src/time/index.js
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ formatTime: () => format_time_default
23
+ });
24
+
25
+ // src/time/format-time.js
26
+ var format_time_default = (t) => ~~(t / 60) + ":" + (t % 60 < 10 ? "0" : "") + ~~(t % 60);
27
+
28
+ // src/time/_web.js
29
+ globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
30
+ })();
@@ -0,0 +1 @@
1
+ (()=>{var a=Object.defineProperty;var b=(l,i)=>{for(var o in i)a(l,o,{get:i[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(l=!0)=>{for(let i in globalThis.utils)i!=="global"&&(l||globalThis[i]===void 0)&&(globalThis[i]=globalThis.utils[i])};var s={};b(s,{formatTime:()=>t});var t=l=>~~(l/60)+":"+(l%60<10?"0":"")+~~(l%60);globalThis.utils=Object.assign(globalThis.utils||{},s);})();
package/dist/vector.js CHANGED
@@ -29,6 +29,7 @@
29
29
  vecDot: () => vecDot,
30
30
  vecEq: () => vecEq,
31
31
  vecFloor: () => vecFloor,
32
+ vecHeading: () => vecHeading,
32
33
  vecIsZero: () => vecIsZero,
33
34
  vecLerp: () => vecLerp,
34
35
  vecLimit: () => vecLimit,
@@ -45,7 +46,6 @@
45
46
  vecSetMag: () => vecSetMag,
46
47
  vecSub: () => vecSub
47
48
  });
48
- var sqrt = Math.sqrt;
49
49
  var cos = Math.cos;
50
50
  var sin = Math.sin;
51
51
  var PI2 = 2 * Math.PI;
@@ -151,8 +151,7 @@
151
151
  var vecLimit = (v, max = 1) => {
152
152
  const sq = vecMag2(v);
153
153
  if (sq > max * max) {
154
- vecDiv(v, sqrt(sq));
155
- vecMult(v, max);
154
+ vecSetMag(v, max);
156
155
  }
157
156
  return v;
158
157
  };
@@ -164,7 +163,8 @@
164
163
  const dy = a.y - b.y;
165
164
  return dx * dx + dy * dy;
166
165
  };
167
- var vecAngle = (v) => Math.atan2(v.y, v.x);
166
+ var vecHeading = (v) => Math.atan2(v.y, v.x);
167
+ var vecAngle = (v) => vecHeading(v);
168
168
  var vecAngleBetween = (v1, v2) => Math.atan2(v2.y - v1.y, v2.x - v1.x);
169
169
  var vecDot = (a, b) => a.x * b.x + a.y * b.y;
170
170
  var vecCross = (a, b) => a.x * b.y - a.y * b.x;
@@ -1 +1 @@
1
- (()=>{var q=Object.defineProperty;var A=(t,e)=>{for(var o in e)q(t,o,{get:e[o],enumerable:!0})};var h={};A(h,{DOWN:()=>K,LEFT:()=>Q,ONE:()=>k,RIGHT:()=>J,UP:()=>z,Vector:()=>s,ZERO:()=>T,vec:()=>r,vecAbs:()=>$,vecAdd:()=>u,vecAngle:()=>P,vecAngleBetween:()=>w,vecCeil:()=>j,vecClamp:()=>H,vecCross:()=>F,vecDist:()=>L,vecDist2:()=>N,vecDiv:()=>x,vecDot:()=>D,vecEq:()=>p,vecFloor:()=>B,vecIsZero:()=>W,vecLerp:()=>U,vecLimit:()=>b,vecMag:()=>g,vecMag2:()=>R,vecMove:()=>V,vecMult:()=>y,vecNorm:()=>a,vecRand:()=>Z,vecReflect:()=>O,vecRotate:()=>I,vecRound:()=>G,vecSet:()=>d,vecSetMag:()=>S,vecSub:()=>i});var C=Math.sqrt,M=Math.cos,f=Math.sin,E=2*Math.PI,s=class{x;y;constructor(e=0,o=e){this.x=e,this.y=o}toString(){return`Vector (${this.x}, ${this.y})`}},n=t=>t instanceof s,r=(t=0,e=t)=>(n(t)&&(e=t.y,t=t.x),new s(t,e)),p=(t,e,o=e)=>n(e)?p(t,e.x,e.y):t.x===e&&t.y===o,d=(t,e,o=e)=>(n(e)?d(t,e.x,e.y):(t.x=e,t.y=o),t),u=(t,e,o=e)=>n(e)?u(t,e.x,e.y):(t.x+=e,t.y+=o,t),i=(t,e,o=e)=>n(e)?i(t,e.x,e.y):(t.x-=e,t.y-=o,t),y=(t,e,o=e)=>n(e)?y(t,e.x,e.y):(t.x*=e,t.y*=o,t),x=(t,e,o=e)=>n(e)?x(t,e.x,e.y):(t.x/=e||1,t.y/=o||1,t),I=(t,e)=>{let o=M(e),c=f(e);return t.x=o*t.x-c*t.y,t.y=c*t.x+o*t.y,t},O=(t,e)=>{let o=a(r(e));return i(t,y(o,2*D(t,o)))},S=(t,e)=>(a(t),y(t,e),t),g=t=>Math.hypot(t.x,t.y),R=t=>t.x*t.x+t.y*t.y,a=t=>{let e=g(t);return e>0&&x(t,e),t},b=(t,e=1)=>{let o=R(t);return o>e*e&&(x(t,C(o)),y(t,e)),t},L=(t,e)=>Math.hypot(e.x-t.x,e.y-t.y),N=(t,e)=>{let o=t.x-e.x,c=t.y-e.y;return o*o+c*c},P=t=>Math.atan2(t.y,t.x),w=(t,e)=>Math.atan2(e.y-t.y,e.x-t.x),D=(t,e)=>t.x*e.x+t.y*e.y,F=(t,e)=>t.x*e.y-t.y*e.x,U=(t,e,o)=>(t.x+=(e.x-t.x)*o||0,t.y+=(e.y-t.y)*o||0,t),Z=(t=1,e=t,o=globalThis.rand||Math.random)=>{let c=o()*E,l=o()*(e-t)+t;return r(M(c)*l,f(c)*l)},$=t=>(t.x=Math.abs(t.x),t.y=Math.abs(t.y),t),j=t=>(t.x=Math.ceil(t.x),t.y=Math.ceil(t.y),t),B=t=>(t.x=Math.floor(t.x),t.y=Math.floor(t.y),t),G=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t),H=(t,e,o)=>(t.x<e.x&&(t.x=e.x),t.x>o.x&&(t.x=o.x),t.y<e.y&&(t.y=e.y),t.y>o.y&&(t.y=o.y),t),V=(t,e,o=1)=>u(t,e.x*o,e.y*o),W=t=>p(t,T),T=r(0,0),k=r(1,1),z=r(0,-1),J=r(1,0),K=r(0,1),Q=r(-1,0);globalThis.utils=Object.assign(globalThis.utils||{},h);})();
1
+ (()=>{var C=Object.defineProperty;var E=(t,e)=>{for(var o in e)C(t,o,{get:e[o],enumerable:!0})};var h={};E(h,{DOWN:()=>K,LEFT:()=>Q,ONE:()=>k,RIGHT:()=>J,UP:()=>z,Vector:()=>s,ZERO:()=>A,vec:()=>r,vecAbs:()=>Z,vecAdd:()=>p,vecAngle:()=>P,vecAngleBetween:()=>w,vecCeil:()=>$,vecClamp:()=>G,vecCross:()=>F,vecDist:()=>L,vecDist2:()=>N,vecDiv:()=>i,vecDot:()=>T,vecEq:()=>y,vecFloor:()=>j,vecHeading:()=>D,vecIsZero:()=>W,vecLerp:()=>H,vecLimit:()=>b,vecMag:()=>R,vecMag2:()=>q,vecMove:()=>V,vecMult:()=>x,vecNorm:()=>a,vecRand:()=>U,vecReflect:()=>S,vecRotate:()=>O,vecRound:()=>B,vecSet:()=>d,vecSetMag:()=>g,vecSub:()=>u});var M=Math.cos,f=Math.sin,I=2*Math.PI,s=class{x;y;constructor(e=0,o=e){this.x=e,this.y=o}toString(){return`Vector (${this.x}, ${this.y})`}},n=t=>t instanceof s,r=(t=0,e=t)=>(n(t)&&(e=t.y,t=t.x),new s(t,e)),y=(t,e,o=e)=>n(e)?y(t,e.x,e.y):t.x===e&&t.y===o,d=(t,e,o=e)=>(n(e)?d(t,e.x,e.y):(t.x=e,t.y=o),t),p=(t,e,o=e)=>n(e)?p(t,e.x,e.y):(t.x+=e,t.y+=o,t),u=(t,e,o=e)=>n(e)?u(t,e.x,e.y):(t.x-=e,t.y-=o,t),x=(t,e,o=e)=>n(e)?x(t,e.x,e.y):(t.x*=e,t.y*=o,t),i=(t,e,o=e)=>n(e)?i(t,e.x,e.y):(t.x/=e||1,t.y/=o||1,t),O=(t,e)=>{let o=M(e),c=f(e);return t.x=o*t.x-c*t.y,t.y=c*t.x+o*t.y,t},S=(t,e)=>{let o=a(r(e));return u(t,x(o,2*T(t,o)))},g=(t,e)=>(a(t),x(t,e),t),R=t=>Math.hypot(t.x,t.y),q=t=>t.x*t.x+t.y*t.y,a=t=>{let e=R(t);return e>0&&i(t,e),t},b=(t,e=1)=>(q(t)>e*e&&g(t,e),t),L=(t,e)=>Math.hypot(e.x-t.x,e.y-t.y),N=(t,e)=>{let o=t.x-e.x,c=t.y-e.y;return o*o+c*c},D=t=>Math.atan2(t.y,t.x),P=t=>D(t),w=(t,e)=>Math.atan2(e.y-t.y,e.x-t.x),T=(t,e)=>t.x*e.x+t.y*e.y,F=(t,e)=>t.x*e.y-t.y*e.x,H=(t,e,o)=>(t.x+=(e.x-t.x)*o||0,t.y+=(e.y-t.y)*o||0,t),U=(t=1,e=t,o=globalThis.rand||Math.random)=>{let c=o()*I,l=o()*(e-t)+t;return r(M(c)*l,f(c)*l)},Z=t=>(t.x=Math.abs(t.x),t.y=Math.abs(t.y),t),$=t=>(t.x=Math.ceil(t.x),t.y=Math.ceil(t.y),t),j=t=>(t.x=Math.floor(t.x),t.y=Math.floor(t.y),t),B=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t),G=(t,e,o)=>(t.x<e.x&&(t.x=e.x),t.x>o.x&&(t.x=o.x),t.y<e.y&&(t.y=e.y),t.y>o.y&&(t.y=o.y),t),V=(t,e,o=1)=>p(t,e.x*o,e.y*o),W=t=>y(t,A),A=r(0,0),k=r(1,1),z=r(0,-1),J=r(1,0),K=r(0,1),Q=r(-1,0);globalThis.utils=Object.assign(globalThis.utils||{},h);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litecanvas/utils",
3
- "version": "0.36.0",
3
+ "version": "0.38.0",
4
4
  "description": "Utilities to help build litecanvas games",
5
5
  "author": "Luiz Bills <luizbills@pm.me>",
6
6
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  "litecanvas": "latest"
38
38
  },
39
39
  "devDependencies": {
40
- "esbuild": "^0.25.6",
40
+ "esbuild": "^0.25.8",
41
41
  "gzip-size": "^7.0.0",
42
42
  "prettier": "^3.6.2"
43
43
  }
package/src/index.js CHANGED
@@ -8,3 +8,4 @@ export * from "./tween/index.js"
8
8
  export * from "./noise/index.js"
9
9
  export * from "./image/index.js"
10
10
  export * from "./collection/index.js"
11
+ export * from "./time/index.js"
package/src/math/index.js CHANGED
@@ -8,3 +8,4 @@ export { default as mean } from "./mean.js"
8
8
  export { default as median } from "./median.js"
9
9
  export { default as sum } from "./sum.js"
10
10
  export { default as lerpAngle } from "./lerp-angle.js"
11
+ export { default as percent } from "./percent.js"
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Returns what percentage the value is between min and max.
3
+ *
4
+ * Based on https://github.com/KilledByAPixel/LittleJS/blob/v1.11.7/src/engineUtilities.js#L66
5
+ *
6
+ * @param {number} value
7
+ * @param {number} [min=0]
8
+ * @param {number} [max=1]
9
+ * @return {number}
10
+ */
11
+ export default (value, min = 0, max = 1) =>
12
+ max - min ? (value - min) / (max - min) : 0
@@ -0,0 +1,4 @@
1
+ import "../_global.js"
2
+ import * as timeUtils from "./index.js"
3
+
4
+ globalThis.utils = Object.assign(globalThis.utils || {}, timeUtils)
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Formats seconds to mm:ss style for display purposes.
3
+ *
4
+ * Based on https://github.com/KilledByAPixel/LittleJS/blob/v1.11.7/src/engineUtilities.js#L190
5
+ *
6
+ * @param {number} t - the time in seconds
7
+ * @return {string}
8
+ */
9
+ export default (t) => ~~(t / 60) + ":" + (t % 60 < 10 ? "0" : "") + ~~(t % 60)
@@ -0,0 +1 @@
1
+ export { default as formatTime } from "./format-time.js"
@@ -239,8 +239,7 @@ export const vecNorm = (v) => {
239
239
  export const vecLimit = (v, max = 1) => {
240
240
  const sq = vecMag2(v)
241
241
  if (sq > max * max) {
242
- vecDiv(v, sqrt(sq)) //normalize it
243
- vecMult(v, max)
242
+ vecSetMag(v, max)
244
243
  }
245
244
  return v
246
245
  }
@@ -275,7 +274,15 @@ export const vecDist2 = (a, b) => {
275
274
  * @param {Vector} v
276
275
  * @returns {number}
277
276
  */
278
- export const vecAngle = (v) => Math.atan2(v.y, v.x)
277
+ export const vecHeading = (v) => Math.atan2(v.y, v.x)
278
+
279
+ /**
280
+ * `vecHeading` alias.
281
+ *
282
+ * @param {Vector} v
283
+ * @returns {number}
284
+ */
285
+ export const vecAngle = (v) => vecHeading(v)
279
286
 
280
287
  /**
281
288
  * Calculates the angle between two vectors.