@maru-ui/core 0.0.1
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/calculateVelocity.d.ts +13 -0
- package/dist/calculateVelocity.js +3 -0
- package/dist/calculateVelocity.js.map +1 -0
- package/dist/calculateVelocity.mjs +12 -0
- package/dist/calculateVelocity.mjs.map +1 -0
- package/dist/decideSnap.d.ts +25 -0
- package/dist/decideSnap.js +3 -0
- package/dist/decideSnap.js.map +1 -0
- package/dist/decideSnap.mjs +19 -0
- package/dist/decideSnap.mjs.map +1 -0
- package/dist/getClampedPosition.d.ts +10 -0
- package/dist/getClampedPosition.js +3 -0
- package/dist/getClampedPosition.js.map +1 -0
- package/dist/getClampedPosition.mjs +8 -0
- package/dist/getClampedPosition.mjs.map +1 -0
- package/dist/getNextIndexByKey.d.ts +11 -0
- package/dist/getNextIndexByKey.js +3 -0
- package/dist/getNextIndexByKey.js.map +1 -0
- package/dist/getNextIndexByKey.mjs +32 -0
- package/dist/getNextIndexByKey.mjs.map +1 -0
- package/dist/getSnapIndex.d.ts +10 -0
- package/dist/getSnapIndex.js +3 -0
- package/dist/getSnapIndex.js.map +1 -0
- package/dist/getSnapIndex.mjs +10 -0
- package/dist/getSnapIndex.mjs.map +1 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +17 -0
- package/dist/momentum.types.d.ts +1 -0
- package/dist/momentum.types.js +0 -0
- package/dist/momentum.types.mjs +0 -0
- package/dist/momentumEngine.d.ts +54 -0
- package/dist/momentumEngine.js +3 -0
- package/dist/momentumEngine.js.map +1 -0
- package/dist/momentumEngine.mjs +69 -0
- package/dist/momentumEngine.mjs.map +1 -0
- package/dist/stepMomentum.d.ts +15 -0
- package/dist/stepMomentum.js +3 -0
- package/dist/stepMomentum.js.map +1 -0
- package/dist/stepMomentum.mjs +18 -0
- package/dist/stepMomentum.mjs.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare function calculateVelocity(samples: Array<VelocitySample>, options?: CalculateVelocityOptions): number;
|
|
2
|
+
export default calculateVelocity;
|
|
3
|
+
|
|
4
|
+
declare interface CalculateVelocityOptions {
|
|
5
|
+
maxVelocity?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare interface VelocitySample {
|
|
9
|
+
time: number;
|
|
10
|
+
value: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { }
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function o(t,e={}){if(t.length<2)return 0;const c=t[0],n=t[t.length-1],i=n.time-c.time,r=n.value-c.value;if(i<=0)return 0;const I=r/i;return Math.max(-(e.maxVelocity??Number.POSITIVE_INFINITY),Math.min(e.maxVelocity??Number.POSITIVE_INFINITY,I))}module.exports=o;
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=calculateVelocity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculateVelocity.js","names":[],"sources":["../src/momentum/calculateVelocity/calculateVelocity.ts"],"sourcesContent":["import type { VelocitySample } from '../momentum.types';\n\nexport interface CalculateVelocityOptions {\n maxVelocity?: number;\n}\n\nexport default function calculateVelocity(\n samples: Array<VelocitySample>,\n options: CalculateVelocityOptions = {},\n) {\n if (samples.length < 2) return 0;\n\n const first = samples[0];\n const last = samples[samples.length - 1];\n const time = last.time - first.time;\n const distance = last.value - first.value;\n\n if (time <= 0) return 0;\n\n const velocity = distance / time;\n\n return Math.max(\n -(options.maxVelocity ?? Number.POSITIVE_INFINITY),\n Math.min(options.maxVelocity ?? Number.POSITIVE_INFINITY, velocity),\n );\n}\n\n"],"mappings":"AAMA,SAAwB,EACtB,EACA,EAAoC,CAAA,EACpC,CACA,GAAI,EAAQ,OAAS,EAAG,MAAO,GAE/B,MAAM,EAAQ,EAAQ,CAAA,EAChB,EAAO,EAAQ,EAAQ,OAAS,CAAA,EAChC,EAAO,EAAK,KAAO,EAAM,KACzB,EAAW,EAAK,MAAQ,EAAM,MAEpC,GAAI,GAAQ,EAAG,MAAO,GAEtB,MAAM,EAAW,EAAW,EAE5B,OAAO,KAAK,IACV,EAAE,EAAQ,aAAe,OAAO,mBAChC,KAAK,IAAI,EAAQ,aAAe,OAAO,kBAAmB,CAAA,CAAS"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function u(t, e = {}) {
|
|
2
|
+
if (t.length < 2) return 0;
|
|
3
|
+
const c = t[0], n = t[t.length - 1], i = n.time - c.time, a = n.value - c.value;
|
|
4
|
+
if (i <= 0) return 0;
|
|
5
|
+
const r = a / i;
|
|
6
|
+
return Math.max(-(e.maxVelocity ?? Number.POSITIVE_INFINITY), Math.min(e.maxVelocity ?? Number.POSITIVE_INFINITY, r));
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
u as default
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=calculateVelocity.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculateVelocity.mjs","names":[],"sources":["../src/momentum/calculateVelocity/calculateVelocity.ts"],"sourcesContent":["import type { VelocitySample } from '../momentum.types';\n\nexport interface CalculateVelocityOptions {\n maxVelocity?: number;\n}\n\nexport default function calculateVelocity(\n samples: Array<VelocitySample>,\n options: CalculateVelocityOptions = {},\n) {\n if (samples.length < 2) return 0;\n\n const first = samples[0];\n const last = samples[samples.length - 1];\n const time = last.time - first.time;\n const distance = last.value - first.value;\n\n if (time <= 0) return 0;\n\n const velocity = distance / time;\n\n return Math.max(\n -(options.maxVelocity ?? Number.POSITIVE_INFINITY),\n Math.min(options.maxVelocity ?? Number.POSITIVE_INFINITY, velocity),\n );\n}\n\n"],"mappings":"AAMA,SAAwB,EACtB,GACA,IAAoC,CAAA,GACpC;AACA,MAAI,EAAQ,SAAS,EAAG,QAAO;AAE/B,QAAM,IAAQ,EAAQ,CAAA,GAChB,IAAO,EAAQ,EAAQ,SAAS,CAAA,GAChC,IAAO,EAAK,OAAO,EAAM,MACzB,IAAW,EAAK,QAAQ,EAAM;AAEpC,MAAI,KAAQ,EAAG,QAAO;AAEtB,QAAM,IAAW,IAAW;AAE5B,SAAO,KAAK,IACV,EAAE,EAAQ,eAAe,OAAO,oBAChC,KAAK,IAAI,EAAQ,eAAe,OAAO,mBAAmB,CAAA,CAAS"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare function decideSnap({ position, velocity, itemHeight, length, config, }: DecideSnapOptions): DecideSnapResult;
|
|
2
|
+
export default decideSnap;
|
|
3
|
+
|
|
4
|
+
declare interface DecideSnapConfig {
|
|
5
|
+
nearZeroVelocity: number;
|
|
6
|
+
snapVelocityThreshold: number;
|
|
7
|
+
boundaryPx: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare interface DecideSnapOptions {
|
|
11
|
+
position: number;
|
|
12
|
+
velocity: number;
|
|
13
|
+
itemHeight: number;
|
|
14
|
+
length: number;
|
|
15
|
+
config: DecideSnapConfig;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare interface DecideSnapResult {
|
|
19
|
+
shouldSnap: boolean;
|
|
20
|
+
snapIndex: number;
|
|
21
|
+
snapPosition: number;
|
|
22
|
+
distance: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { }
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const p=require("./getSnapIndex.js");function y({position:s,velocity:c,itemHeight:e,length:d,config:n}){const o=p({position:s,itemHeight:e,length:d}),a=o*e,t=Math.abs(s-a),r=Math.abs(c),i=r<=n.nearZeroVelocity,u=r<=n.snapVelocityThreshold,l=t<=n.boundaryPx;return{shouldSnap:i&&l||u,snapIndex:o,snapPosition:a,distance:t}}module.exports=y;
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=decideSnap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decideSnap.js","names":[],"sources":["../src/momentum/decideSnap/decideSnap.ts"],"sourcesContent":["import getSnapIndex from '../getSnapIndex/getSnapIndex';\n\nexport interface DecideSnapConfig {\n nearZeroVelocity: number;\n snapVelocityThreshold: number;\n boundaryPx: number;\n}\n\nexport interface DecideSnapOptions {\n position: number;\n velocity: number;\n itemHeight: number;\n length: number;\n config: DecideSnapConfig;\n}\n\nexport interface DecideSnapResult {\n shouldSnap: boolean;\n snapIndex: number;\n snapPosition: number;\n distance: number;\n}\n\nexport default function decideSnap({\n position,\n velocity,\n itemHeight,\n length,\n config,\n}: DecideSnapOptions): DecideSnapResult {\n const snapIndex = getSnapIndex({ position, itemHeight, length });\n const snapPosition = snapIndex * itemHeight;\n const distance = Math.abs(position - snapPosition);\n\n const absVelocity = Math.abs(velocity);\n const isNearZeroVelocity = absVelocity <= config.nearZeroVelocity;\n const isSlowEnough = absVelocity <= config.snapVelocityThreshold;\n const isNearBoundary = distance <= config.boundaryPx;\n\n const shouldSnap = (isNearZeroVelocity && isNearBoundary) || isSlowEnough;\n\n return {\n shouldSnap,\n snapIndex,\n snapPosition,\n distance,\n };\n}\n\n"],"mappings":"qCAuBA,SAAwB,EAAW,CACjC,SAAA,EACA,SAAA,EACA,WAAA,EACA,OAAA,EACA,OAAA,CAAA,EACsC,CACtC,MAAM,EAAY,EAAa,CAAE,SAAA,EAAU,WAAA,EAAY,OAAA,EAAQ,EACzD,EAAe,EAAY,EAC3B,EAAW,KAAK,IAAI,EAAW,CAAA,EAE/B,EAAc,KAAK,IAAI,CAAA,EACvB,EAAqB,GAAe,EAAO,iBAC3C,EAAe,GAAe,EAAO,sBACrC,EAAiB,GAAY,EAAO,WAI1C,MAAO,CACL,WAHkB,GAAsB,GAAmB,EAI3D,UAAA,EACA,aAAA,EACA,SAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import u from "./getSnapIndex.mjs";
|
|
2
|
+
function h({ position: o, velocity: c, itemHeight: s, length: d, config: n }) {
|
|
3
|
+
const a = u({
|
|
4
|
+
position: o,
|
|
5
|
+
itemHeight: s,
|
|
6
|
+
length: d
|
|
7
|
+
}), t = a * s, e = Math.abs(o - t), r = Math.abs(c), l = r <= n.nearZeroVelocity, i = r <= n.snapVelocityThreshold, p = e <= n.boundaryPx;
|
|
8
|
+
return {
|
|
9
|
+
shouldSnap: l && p || i,
|
|
10
|
+
snapIndex: a,
|
|
11
|
+
snapPosition: t,
|
|
12
|
+
distance: e
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
h as default
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=decideSnap.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decideSnap.mjs","names":[],"sources":["../src/momentum/decideSnap/decideSnap.ts"],"sourcesContent":["import getSnapIndex from '../getSnapIndex/getSnapIndex';\n\nexport interface DecideSnapConfig {\n nearZeroVelocity: number;\n snapVelocityThreshold: number;\n boundaryPx: number;\n}\n\nexport interface DecideSnapOptions {\n position: number;\n velocity: number;\n itemHeight: number;\n length: number;\n config: DecideSnapConfig;\n}\n\nexport interface DecideSnapResult {\n shouldSnap: boolean;\n snapIndex: number;\n snapPosition: number;\n distance: number;\n}\n\nexport default function decideSnap({\n position,\n velocity,\n itemHeight,\n length,\n config,\n}: DecideSnapOptions): DecideSnapResult {\n const snapIndex = getSnapIndex({ position, itemHeight, length });\n const snapPosition = snapIndex * itemHeight;\n const distance = Math.abs(position - snapPosition);\n\n const absVelocity = Math.abs(velocity);\n const isNearZeroVelocity = absVelocity <= config.nearZeroVelocity;\n const isSlowEnough = absVelocity <= config.snapVelocityThreshold;\n const isNearBoundary = distance <= config.boundaryPx;\n\n const shouldSnap = (isNearZeroVelocity && isNearBoundary) || isSlowEnough;\n\n return {\n shouldSnap,\n snapIndex,\n snapPosition,\n distance,\n };\n}\n\n"],"mappings":";AAuBA,SAAwB,EAAW,EACjC,UAAA,GACA,UAAA,GACA,YAAA,GACA,QAAA,GACA,QAAA,EAAA,GACsC;AACtC,QAAM,IAAY,EAAa;AAAA,IAAE,UAAA;AAAA,IAAU,YAAA;AAAA,IAAY,QAAA;AAAA,GAAQ,GACzD,IAAe,IAAY,GAC3B,IAAW,KAAK,IAAI,IAAW,CAAA,GAE/B,IAAc,KAAK,IAAI,CAAA,GACvB,IAAqB,KAAe,EAAO,kBAC3C,IAAe,KAAe,EAAO,uBACrC,IAAiB,KAAY,EAAO;AAI1C,SAAO;AAAA,IACL,YAHkB,KAAsB,KAAmB;AAAA,IAI3D,WAAA;AAAA,IACA,cAAA;AAAA,IACA,UAAA;AAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getClampedPosition.js","names":[],"sources":["../src/momentum/getClampedPosition/getClampedPosition.ts"],"sourcesContent":["export interface GetClampedPositionOptions {\n position: number;\n min: number;\n max: number;\n}\n\nexport default function getClampedPosition({\n position,\n min,\n max,\n}: GetClampedPositionOptions): number {\n if (min > max) {\n [min, max] = [max, min];\n }\n\n if (position < min) return min;\n if (position > max) return max;\n\n return position;\n}\n"],"mappings":"AAMA,SAAwB,EAAmB,CACzC,SAAA,EACA,IAAA,EACA,IAAA,CAAA,EACoC,CAKpC,OAJI,EAAM,IACR,CAAC,EAAK,CAAA,EAAO,CAAC,EAAK,CAAA,GAGjB,EAAW,EAAY,EACvB,EAAW,EAAY,EAEpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getClampedPosition.mjs","names":[],"sources":["../src/momentum/getClampedPosition/getClampedPosition.ts"],"sourcesContent":["export interface GetClampedPositionOptions {\n position: number;\n min: number;\n max: number;\n}\n\nexport default function getClampedPosition({\n position,\n min,\n max,\n}: GetClampedPositionOptions): number {\n if (min > max) {\n [min, max] = [max, min];\n }\n\n if (position < min) return min;\n if (position > max) return max;\n\n return position;\n}\n"],"mappings":"AAMA,SAAwB,EAAmB,EACzC,UAAA,GACA,KAAA,GACA,KAAA,EAAA,GACoC;AAKpC,SAJI,IAAM,MACR,CAAC,GAAK,CAAA,IAAO,CAAC,GAAK,CAAA,IAGjB,IAAW,IAAY,IACvB,IAAW,IAAY,IAEpB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function getNextIndexByKey({ key, currentIndex, length, pageSize, }: GetNextIndexByKeyOptions): number;
|
|
2
|
+
export default getNextIndexByKey;
|
|
3
|
+
|
|
4
|
+
declare interface GetNextIndexByKeyOptions {
|
|
5
|
+
key: string;
|
|
6
|
+
currentIndex: number;
|
|
7
|
+
length: number;
|
|
8
|
+
pageSize?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { }
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function f({key:c,currentIndex:a,length:r,pageSize:s=5}){if(r<=0)return 0;let e=a;switch(c){case"ArrowUp":e=e+1,e>r-1&&(e=0);break;case"ArrowDown":e=e-1,e<0&&(e=r-1);break;case"PageUp":e=e+s,e>r-1&&(e=r-1);break;case"PageDown":e=e-s,e<0&&(e=0);break;case"Home":e=0;break;case"End":e=r-1;break;default:return a}return e}module.exports=f;
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=getNextIndexByKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getNextIndexByKey.js","names":[],"sources":["../src/momentum/getNextIndexByKey/getNextIndexByKey.ts"],"sourcesContent":["export interface GetNextIndexByKeyOptions {\n key: string;\n currentIndex: number;\n length: number;\n pageSize?: number;\n}\n\nexport default function getNextIndexByKey({\n key,\n currentIndex,\n length,\n pageSize = 5,\n}: GetNextIndexByKeyOptions): number {\n if (length <= 0) return 0;\n\n let nextIndex = currentIndex;\n\n switch (key) {\n case 'ArrowUp':\n nextIndex = nextIndex + 1;\n if (nextIndex > length - 1) nextIndex = 0;\n break;\n case 'ArrowDown':\n nextIndex = nextIndex - 1;\n if (nextIndex < 0) nextIndex = length - 1;\n break;\n case 'PageUp':\n nextIndex = nextIndex + pageSize;\n if (nextIndex > length - 1) nextIndex = length - 1;\n break;\n case 'PageDown':\n nextIndex = nextIndex - pageSize;\n if (nextIndex < 0) nextIndex = 0;\n break;\n case 'Home':\n nextIndex = 0;\n break;\n case 'End':\n nextIndex = length - 1;\n break;\n default:\n return currentIndex;\n }\n\n return nextIndex;\n}\n\n"],"mappings":"AAOA,SAAwB,EAAkB,CACxC,IAAA,EACA,aAAA,EACA,OAAA,EACA,SAAA,EAAW,CAAA,EACwB,CACnC,GAAI,GAAU,EAAG,MAAO,GAExB,IAAI,EAAY,EAEhB,OAAQ,EAAR,CACE,IAAK,UACH,EAAY,EAAY,EACpB,EAAY,EAAS,IAAG,EAAY,GACxC,MACF,IAAK,YACH,EAAY,EAAY,EACpB,EAAY,IAAG,EAAY,EAAS,GACxC,MACF,IAAK,SACH,EAAY,EAAY,EACpB,EAAY,EAAS,IAAG,EAAY,EAAS,GACjD,MACF,IAAK,WACH,EAAY,EAAY,EACpB,EAAY,IAAG,EAAY,GAC/B,MACF,IAAK,OACH,EAAY,EACZ,MACF,IAAK,MACH,EAAY,EAAS,EACrB,MACF,QACE,OAAO,EAGX,OAAO"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function c({ key: s, currentIndex: r, length: a, pageSize: f = 5 }) {
|
|
2
|
+
if (a <= 0) return 0;
|
|
3
|
+
let e = r;
|
|
4
|
+
switch (s) {
|
|
5
|
+
case "ArrowUp":
|
|
6
|
+
e = e + 1, e > a - 1 && (e = 0);
|
|
7
|
+
break;
|
|
8
|
+
case "ArrowDown":
|
|
9
|
+
e = e - 1, e < 0 && (e = a - 1);
|
|
10
|
+
break;
|
|
11
|
+
case "PageUp":
|
|
12
|
+
e = e + f, e > a - 1 && (e = a - 1);
|
|
13
|
+
break;
|
|
14
|
+
case "PageDown":
|
|
15
|
+
e = e - f, e < 0 && (e = 0);
|
|
16
|
+
break;
|
|
17
|
+
case "Home":
|
|
18
|
+
e = 0;
|
|
19
|
+
break;
|
|
20
|
+
case "End":
|
|
21
|
+
e = a - 1;
|
|
22
|
+
break;
|
|
23
|
+
default:
|
|
24
|
+
return r;
|
|
25
|
+
}
|
|
26
|
+
return e;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
c as default
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=getNextIndexByKey.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getNextIndexByKey.mjs","names":[],"sources":["../src/momentum/getNextIndexByKey/getNextIndexByKey.ts"],"sourcesContent":["export interface GetNextIndexByKeyOptions {\n key: string;\n currentIndex: number;\n length: number;\n pageSize?: number;\n}\n\nexport default function getNextIndexByKey({\n key,\n currentIndex,\n length,\n pageSize = 5,\n}: GetNextIndexByKeyOptions): number {\n if (length <= 0) return 0;\n\n let nextIndex = currentIndex;\n\n switch (key) {\n case 'ArrowUp':\n nextIndex = nextIndex + 1;\n if (nextIndex > length - 1) nextIndex = 0;\n break;\n case 'ArrowDown':\n nextIndex = nextIndex - 1;\n if (nextIndex < 0) nextIndex = length - 1;\n break;\n case 'PageUp':\n nextIndex = nextIndex + pageSize;\n if (nextIndex > length - 1) nextIndex = length - 1;\n break;\n case 'PageDown':\n nextIndex = nextIndex - pageSize;\n if (nextIndex < 0) nextIndex = 0;\n break;\n case 'Home':\n nextIndex = 0;\n break;\n case 'End':\n nextIndex = length - 1;\n break;\n default:\n return currentIndex;\n }\n\n return nextIndex;\n}\n\n"],"mappings":"AAOA,SAAwB,EAAkB,EACxC,KAAA,GACA,cAAA,GACA,QAAA,GACA,UAAA,IAAW,EAAA,GACwB;AACnC,MAAI,KAAU,EAAG,QAAO;AAExB,MAAI,IAAY;AAEhB,UAAQ,GAAR;AAAA,IACE,KAAK;AACH,MAAA,IAAY,IAAY,GACpB,IAAY,IAAS,MAAG,IAAY;AACxC;AAAA,IACF,KAAK;AACH,MAAA,IAAY,IAAY,GACpB,IAAY,MAAG,IAAY,IAAS;AACxC;AAAA,IACF,KAAK;AACH,MAAA,IAAY,IAAY,GACpB,IAAY,IAAS,MAAG,IAAY,IAAS;AACjD;AAAA,IACF,KAAK;AACH,MAAA,IAAY,IAAY,GACpB,IAAY,MAAG,IAAY;AAC/B;AAAA,IACF,KAAK;AACH,MAAA,IAAY;AACZ;AAAA,IACF,KAAK;AACH,MAAA,IAAY,IAAS;AACrB;AAAA,IACF;AACE,aAAO;AAAA;AAGX,SAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSnapIndex.js","names":[],"sources":["../src/momentum/getSnapIndex/getSnapIndex.ts"],"sourcesContent":["export interface GetSnapIndexOptions {\n position: number;\n itemHeight: number;\n length: number;\n}\n\nexport default function getSnapIndex({ position, itemHeight, length }: GetSnapIndexOptions) {\n if (length <= 0 || itemHeight <= 0) return 0;\n\n const rawIndex = Math.abs(Math.round(position / itemHeight));\n\n if (rawIndex > length - 1) return length - 1;\n\n return rawIndex;\n}\n\n"],"mappings":"AAMA,SAAwB,EAAa,CAAE,SAAA,EAAU,WAAA,EAAY,OAAA,CAAA,EAA+B,CAC1F,GAAI,GAAU,GAAK,GAAc,EAAG,MAAO,GAE3C,MAAM,EAAW,KAAK,IAAI,KAAK,MAAM,EAAW,CAAA,CAAW,EAE3D,OAAI,EAAW,EAAS,EAAU,EAAS,EAEpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSnapIndex.mjs","names":[],"sources":["../src/momentum/getSnapIndex/getSnapIndex.ts"],"sourcesContent":["export interface GetSnapIndexOptions {\n position: number;\n itemHeight: number;\n length: number;\n}\n\nexport default function getSnapIndex({ position, itemHeight, length }: GetSnapIndexOptions) {\n if (length <= 0 || itemHeight <= 0) return 0;\n\n const rawIndex = Math.abs(Math.round(position / itemHeight));\n\n if (rawIndex > length - 1) return length - 1;\n\n return rawIndex;\n}\n\n"],"mappings":"AAMA,SAAwB,EAAa,EAAE,UAAA,GAAU,YAAA,GAAY,QAAA,EAAA,GAA+B;AAC1F,MAAI,KAAU,KAAK,KAAc,EAAG,QAAO;AAE3C,QAAM,IAAW,KAAK,IAAI,KAAK,MAAM,IAAW,CAAA,CAAW;AAE3D,SAAI,IAAW,IAAS,IAAU,IAAS,IAEpC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export declare function calculateVelocity(samples: Array<VelocitySample>, options?: CalculateVelocityOptions): number;
|
|
2
|
+
|
|
3
|
+
declare interface CalculateVelocityOptions {
|
|
4
|
+
maxVelocity?: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export declare function decideSnap({ position, velocity, itemHeight, length, config, }: DecideSnapOptions): DecideSnapResult;
|
|
8
|
+
|
|
9
|
+
export declare interface DecideSnapConfig {
|
|
10
|
+
nearZeroVelocity: number;
|
|
11
|
+
snapVelocityThreshold: number;
|
|
12
|
+
boundaryPx: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare interface DecideSnapOptions {
|
|
16
|
+
position: number;
|
|
17
|
+
velocity: number;
|
|
18
|
+
itemHeight: number;
|
|
19
|
+
length: number;
|
|
20
|
+
config: DecideSnapConfig;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare interface DecideSnapResult {
|
|
24
|
+
shouldSnap: boolean;
|
|
25
|
+
snapIndex: number;
|
|
26
|
+
snapPosition: number;
|
|
27
|
+
distance: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export declare function getClampedPosition({ position, min, max, }: GetClampedPositionOptions): number;
|
|
31
|
+
|
|
32
|
+
declare interface GetClampedPositionOptions {
|
|
33
|
+
position: number;
|
|
34
|
+
min: number;
|
|
35
|
+
max: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export declare function getNextIndexByKey({ key, currentIndex, length, pageSize, }: GetNextIndexByKeyOptions): number;
|
|
39
|
+
|
|
40
|
+
declare interface GetNextIndexByKeyOptions {
|
|
41
|
+
key: string;
|
|
42
|
+
currentIndex: number;
|
|
43
|
+
length: number;
|
|
44
|
+
pageSize?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export declare function getSnapIndex({ position, itemHeight, length }: GetSnapIndexOptions): number;
|
|
48
|
+
|
|
49
|
+
declare interface GetSnapIndexOptions {
|
|
50
|
+
position: number;
|
|
51
|
+
itemHeight: number;
|
|
52
|
+
length: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export declare class MomentumEngine {
|
|
56
|
+
private config;
|
|
57
|
+
private state;
|
|
58
|
+
private samples;
|
|
59
|
+
private running;
|
|
60
|
+
private snapping;
|
|
61
|
+
constructor(config: MomentumEngineConfig);
|
|
62
|
+
configure(partial: Partial<MomentumEngineConfig>): void;
|
|
63
|
+
pushSample(sample: VelocitySample): void;
|
|
64
|
+
clearSamples(): void;
|
|
65
|
+
getVelocityFromSamples(): number;
|
|
66
|
+
start(state: MomentumEngineState): void;
|
|
67
|
+
stop(): void;
|
|
68
|
+
isRunning(): boolean;
|
|
69
|
+
step(dt: number): MomentumStepResult;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export declare interface MomentumEngineConfig extends DecideSnapConfig {
|
|
73
|
+
min: number;
|
|
74
|
+
max: number;
|
|
75
|
+
friction: number;
|
|
76
|
+
itemHeight: number;
|
|
77
|
+
length: number;
|
|
78
|
+
maxVelocity: number;
|
|
79
|
+
sampleWindowMs?: number;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export declare interface MomentumEngineState {
|
|
83
|
+
position: number;
|
|
84
|
+
velocity: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export declare interface MomentumStepResult extends MomentumEngineState {
|
|
88
|
+
shouldSnap: boolean;
|
|
89
|
+
snapIndex: number;
|
|
90
|
+
snapPosition: number;
|
|
91
|
+
distance: number;
|
|
92
|
+
isRunning: boolean;
|
|
93
|
+
isSnapping: boolean;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export declare function stepMomentum({ position, velocity }: StepMomentumState, dt: number, { min, max, friction }: StepMomentumConfig): StepMomentumState;
|
|
97
|
+
|
|
98
|
+
export declare interface StepMomentumConfig {
|
|
99
|
+
min: number;
|
|
100
|
+
max: number;
|
|
101
|
+
friction: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export declare interface StepMomentumState {
|
|
105
|
+
position: number;
|
|
106
|
+
velocity: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export declare interface VelocitySample {
|
|
110
|
+
time: number;
|
|
111
|
+
value: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./momentum.types.js");const e=require("./calculateVelocity.js"),r=require("./getSnapIndex.js"),t=require("./getClampedPosition.js"),i=require("./getNextIndexByKey.js"),n=require("./stepMomentum.js"),u=require("./decideSnap.js"),o=require("./momentumEngine.js");exports.MomentumEngine=o;exports.calculateVelocity=e;exports.decideSnap=u;exports.getClampedPosition=t;exports.getNextIndexByKey=i;exports.getSnapIndex=r;exports.stepMomentum=n;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "./momentum.types.mjs";
|
|
2
|
+
import t from "./calculateVelocity.mjs";
|
|
3
|
+
import r from "./getSnapIndex.mjs";
|
|
4
|
+
import p from "./getClampedPosition.mjs";
|
|
5
|
+
import f from "./getNextIndexByKey.mjs";
|
|
6
|
+
import d from "./stepMomentum.mjs";
|
|
7
|
+
import g from "./decideSnap.mjs";
|
|
8
|
+
import x from "./momentumEngine.mjs";
|
|
9
|
+
export {
|
|
10
|
+
x as MomentumEngine,
|
|
11
|
+
t as calculateVelocity,
|
|
12
|
+
g as decideSnap,
|
|
13
|
+
p as getClampedPosition,
|
|
14
|
+
f as getNextIndexByKey,
|
|
15
|
+
r as getSnapIndex,
|
|
16
|
+
d as stepMomentum
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { }
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
declare interface DecideSnapConfig {
|
|
2
|
+
nearZeroVelocity: number;
|
|
3
|
+
snapVelocityThreshold: number;
|
|
4
|
+
boundaryPx: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare class MomentumEngine {
|
|
8
|
+
private config;
|
|
9
|
+
private state;
|
|
10
|
+
private samples;
|
|
11
|
+
private running;
|
|
12
|
+
private snapping;
|
|
13
|
+
constructor(config: MomentumEngineConfig);
|
|
14
|
+
configure(partial: Partial<MomentumEngineConfig>): void;
|
|
15
|
+
pushSample(sample: VelocitySample): void;
|
|
16
|
+
clearSamples(): void;
|
|
17
|
+
getVelocityFromSamples(): number;
|
|
18
|
+
start(state: MomentumEngineState): void;
|
|
19
|
+
stop(): void;
|
|
20
|
+
isRunning(): boolean;
|
|
21
|
+
step(dt: number): MomentumStepResult;
|
|
22
|
+
}
|
|
23
|
+
export default MomentumEngine;
|
|
24
|
+
|
|
25
|
+
declare interface MomentumEngineConfig extends DecideSnapConfig {
|
|
26
|
+
min: number;
|
|
27
|
+
max: number;
|
|
28
|
+
friction: number;
|
|
29
|
+
itemHeight: number;
|
|
30
|
+
length: number;
|
|
31
|
+
maxVelocity: number;
|
|
32
|
+
sampleWindowMs?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare interface MomentumEngineState {
|
|
36
|
+
position: number;
|
|
37
|
+
velocity: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare interface MomentumStepResult extends MomentumEngineState {
|
|
41
|
+
shouldSnap: boolean;
|
|
42
|
+
snapIndex: number;
|
|
43
|
+
snapPosition: number;
|
|
44
|
+
distance: number;
|
|
45
|
+
isRunning: boolean;
|
|
46
|
+
isSnapping: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare interface VelocitySample {
|
|
50
|
+
time: number;
|
|
51
|
+
value: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { }
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const e=require("./calculateVelocity.js"),o=require("./stepMomentum.js"),r=require("./decideSnap.js");var a=class{constructor(i){this.state={position:0,velocity:0},this.samples=[],this.running=!1,this.snapping=!1,this.config={...i,sampleWindowMs:i.sampleWindowMs??100}}configure(i){this.config={...this.config,...i}}pushSample(i){const s=i.time,t=this.config.sampleWindowMs??100;this.samples=[...this.samples.filter(n=>s-n.time<=t),i]}clearSamples(){this.samples=[]}getVelocityFromSamples(){return e(this.samples,{maxVelocity:this.config.maxVelocity})}start(i){this.state=i,this.running=!0,this.snapping=!1}stop(){this.running=!1}isRunning(){return this.running}step(i){const s=o(this.state,i,{min:this.config.min,max:this.config.max,friction:this.config.friction});this.state=s;const t=r({position:s.position,velocity:s.velocity,itemHeight:this.config.itemHeight,length:this.config.length,config:{nearZeroVelocity:this.config.nearZeroVelocity,snapVelocityThreshold:this.config.snapVelocityThreshold,boundaryPx:this.config.boundaryPx}});return t.shouldSnap&&(this.running=!1,this.snapping=!0),{...s,...t,isRunning:this.running,isSnapping:this.snapping}}};module.exports=a;
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=momentumEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"momentumEngine.js","names":[],"sources":["../src/momentum/momentumEngine.ts"],"sourcesContent":["import calculateVelocity from './calculateVelocity/calculateVelocity';\nimport decideSnap from './decideSnap/decideSnap';\nimport type {\n MomentumEngineConfig,\n MomentumEngineState,\n MomentumStepResult,\n VelocitySample,\n} from './momentum.types';\nimport stepMomentum from './stepMomentum/stepMomentum';\n\nexport default class MomentumEngine {\n private config: MomentumEngineConfig;\n private state: MomentumEngineState = { position: 0, velocity: 0 };\n private samples: VelocitySample[] = [];\n private running = false;\n private snapping = false;\n\n constructor(config: MomentumEngineConfig) {\n this.config = {\n ...config,\n sampleWindowMs: config.sampleWindowMs ?? 100,\n };\n }\n\n configure(partial: Partial<MomentumEngineConfig>) {\n this.config = { ...this.config, ...partial };\n }\n\n pushSample(sample: VelocitySample) {\n const now = sample.time;\n const sampleWindowMs = this.config.sampleWindowMs ?? 100;\n\n this.samples = [...this.samples.filter((s) => now - s.time <= sampleWindowMs), sample];\n }\n\n clearSamples() {\n this.samples = [];\n }\n\n getVelocityFromSamples() {\n return calculateVelocity(this.samples, { maxVelocity: this.config.maxVelocity });\n }\n\n start(state: MomentumEngineState) {\n this.state = state;\n this.running = true;\n this.snapping = false;\n }\n\n stop() {\n this.running = false;\n }\n\n isRunning() {\n return this.running;\n }\n\n step(dt: number): MomentumStepResult {\n const next = stepMomentum(this.state, dt, {\n min: this.config.min,\n max: this.config.max,\n friction: this.config.friction,\n });\n this.state = next;\n\n const snap = decideSnap({\n position: next.position,\n velocity: next.velocity,\n itemHeight: this.config.itemHeight,\n length: this.config.length,\n config: {\n nearZeroVelocity: this.config.nearZeroVelocity,\n snapVelocityThreshold: this.config.snapVelocityThreshold,\n boundaryPx: this.config.boundaryPx,\n },\n });\n\n if (snap.shouldSnap) {\n this.running = false;\n this.snapping = true;\n }\n\n return {\n ...next,\n ...snap,\n isRunning: this.running,\n isSnapping: this.snapping,\n };\n }\n}\n"],"mappings":"sGAUA,IAAqB,EAArB,KAAoC,CAOlC,YAAY,EAA8B,YALL,CAAE,SAAU,EAAG,SAAU,gBAC1B,CAAA,eAClB,iBACC,GAGjB,KAAK,OAAS,CACZ,GAAG,EACH,eAAgB,EAAO,gBAAkB,KAI7C,UAAU,EAAwC,CAChD,KAAK,OAAS,CAAE,GAAG,KAAK,OAAQ,GAAG,GAGrC,WAAW,EAAwB,CACjC,MAAM,EAAM,EAAO,KACb,EAAiB,KAAK,OAAO,gBAAkB,IAErD,KAAK,QAAU,CAAC,GAAG,KAAK,QAAQ,OAAQ,GAAM,EAAM,EAAE,MAAQ,CAAA,EAAiB,CAAA,EAGjF,cAAe,CACb,KAAK,QAAU,CAAA,EAGjB,wBAAyB,CACvB,OAAO,EAAkB,KAAK,QAAS,CAAE,YAAa,KAAK,OAAO,WAAA,CAAa,EAGjF,MAAM,EAA4B,CAChC,KAAK,MAAQ,EACb,KAAK,QAAU,GACf,KAAK,SAAW,GAGlB,MAAO,CACL,KAAK,QAAU,GAGjB,WAAY,CACV,OAAO,KAAK,QAGd,KAAK,EAAgC,CACnC,MAAM,EAAO,EAAa,KAAK,MAAO,EAAI,CACxC,IAAK,KAAK,OAAO,IACjB,IAAK,KAAK,OAAO,IACjB,SAAU,KAAK,OAAO,SACvB,EACD,KAAK,MAAQ,EAEb,MAAM,EAAO,EAAW,CACtB,SAAU,EAAK,SACf,SAAU,EAAK,SACf,WAAY,KAAK,OAAO,WACxB,OAAQ,KAAK,OAAO,OACpB,OAAQ,CACN,iBAAkB,KAAK,OAAO,iBAC9B,sBAAuB,KAAK,OAAO,sBACnC,WAAY,KAAK,OAAO,YAE3B,EAED,OAAI,EAAK,aACP,KAAK,QAAU,GACf,KAAK,SAAW,IAGX,CACL,GAAG,EACH,GAAG,EACH,UAAW,KAAK,QAChB,WAAY,KAAK"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import e from "./calculateVelocity.mjs";
|
|
2
|
+
import o from "./stepMomentum.mjs";
|
|
3
|
+
import a from "./decideSnap.mjs";
|
|
4
|
+
var l = class {
|
|
5
|
+
constructor(i) {
|
|
6
|
+
this.state = {
|
|
7
|
+
position: 0,
|
|
8
|
+
velocity: 0
|
|
9
|
+
}, this.samples = [], this.running = !1, this.snapping = !1, this.config = {
|
|
10
|
+
...i,
|
|
11
|
+
sampleWindowMs: i.sampleWindowMs ?? 100
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
configure(i) {
|
|
15
|
+
this.config = {
|
|
16
|
+
...this.config,
|
|
17
|
+
...i
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
pushSample(i) {
|
|
21
|
+
const t = i.time, s = this.config.sampleWindowMs ?? 100;
|
|
22
|
+
this.samples = [...this.samples.filter((n) => t - n.time <= s), i];
|
|
23
|
+
}
|
|
24
|
+
clearSamples() {
|
|
25
|
+
this.samples = [];
|
|
26
|
+
}
|
|
27
|
+
getVelocityFromSamples() {
|
|
28
|
+
return e(this.samples, { maxVelocity: this.config.maxVelocity });
|
|
29
|
+
}
|
|
30
|
+
start(i) {
|
|
31
|
+
this.state = i, this.running = !0, this.snapping = !1;
|
|
32
|
+
}
|
|
33
|
+
stop() {
|
|
34
|
+
this.running = !1;
|
|
35
|
+
}
|
|
36
|
+
isRunning() {
|
|
37
|
+
return this.running;
|
|
38
|
+
}
|
|
39
|
+
step(i) {
|
|
40
|
+
const t = o(this.state, i, {
|
|
41
|
+
min: this.config.min,
|
|
42
|
+
max: this.config.max,
|
|
43
|
+
friction: this.config.friction
|
|
44
|
+
});
|
|
45
|
+
this.state = t;
|
|
46
|
+
const s = a({
|
|
47
|
+
position: t.position,
|
|
48
|
+
velocity: t.velocity,
|
|
49
|
+
itemHeight: this.config.itemHeight,
|
|
50
|
+
length: this.config.length,
|
|
51
|
+
config: {
|
|
52
|
+
nearZeroVelocity: this.config.nearZeroVelocity,
|
|
53
|
+
snapVelocityThreshold: this.config.snapVelocityThreshold,
|
|
54
|
+
boundaryPx: this.config.boundaryPx
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return s.shouldSnap && (this.running = !1, this.snapping = !0), {
|
|
58
|
+
...t,
|
|
59
|
+
...s,
|
|
60
|
+
isRunning: this.running,
|
|
61
|
+
isSnapping: this.snapping
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
export {
|
|
66
|
+
l as default
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=momentumEngine.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"momentumEngine.mjs","names":[],"sources":["../src/momentum/momentumEngine.ts"],"sourcesContent":["import calculateVelocity from './calculateVelocity/calculateVelocity';\nimport decideSnap from './decideSnap/decideSnap';\nimport type {\n MomentumEngineConfig,\n MomentumEngineState,\n MomentumStepResult,\n VelocitySample,\n} from './momentum.types';\nimport stepMomentum from './stepMomentum/stepMomentum';\n\nexport default class MomentumEngine {\n private config: MomentumEngineConfig;\n private state: MomentumEngineState = { position: 0, velocity: 0 };\n private samples: VelocitySample[] = [];\n private running = false;\n private snapping = false;\n\n constructor(config: MomentumEngineConfig) {\n this.config = {\n ...config,\n sampleWindowMs: config.sampleWindowMs ?? 100,\n };\n }\n\n configure(partial: Partial<MomentumEngineConfig>) {\n this.config = { ...this.config, ...partial };\n }\n\n pushSample(sample: VelocitySample) {\n const now = sample.time;\n const sampleWindowMs = this.config.sampleWindowMs ?? 100;\n\n this.samples = [...this.samples.filter((s) => now - s.time <= sampleWindowMs), sample];\n }\n\n clearSamples() {\n this.samples = [];\n }\n\n getVelocityFromSamples() {\n return calculateVelocity(this.samples, { maxVelocity: this.config.maxVelocity });\n }\n\n start(state: MomentumEngineState) {\n this.state = state;\n this.running = true;\n this.snapping = false;\n }\n\n stop() {\n this.running = false;\n }\n\n isRunning() {\n return this.running;\n }\n\n step(dt: number): MomentumStepResult {\n const next = stepMomentum(this.state, dt, {\n min: this.config.min,\n max: this.config.max,\n friction: this.config.friction,\n });\n this.state = next;\n\n const snap = decideSnap({\n position: next.position,\n velocity: next.velocity,\n itemHeight: this.config.itemHeight,\n length: this.config.length,\n config: {\n nearZeroVelocity: this.config.nearZeroVelocity,\n snapVelocityThreshold: this.config.snapVelocityThreshold,\n boundaryPx: this.config.boundaryPx,\n },\n });\n\n if (snap.shouldSnap) {\n this.running = false;\n this.snapping = true;\n }\n\n return {\n ...next,\n ...snap,\n isRunning: this.running,\n isSnapping: this.snapping,\n };\n }\n}\n"],"mappings":";;;AAUA,IAAqB,IAArB,MAAoC;AAAA,EAOlC,YAAY,GAA8B;iBALL;AAAA,MAAE,UAAU;AAAA,MAAG,UAAU;AAAA,sBAC1B,CAAA,kBAClB,oBACC,IAGjB,KAAK,SAAS;AAAA,MACZ,GAAG;AAAA,MACH,gBAAgB,EAAO,kBAAkB;AAAA;;EAI7C,UAAU,GAAwC;AAChD,SAAK,SAAS;AAAA,MAAE,GAAG,KAAK;AAAA,MAAQ,GAAG;AAAA;;EAGrC,WAAW,GAAwB;AACjC,UAAM,IAAM,EAAO,MACb,IAAiB,KAAK,OAAO,kBAAkB;AAErD,SAAK,UAAU,CAAC,GAAG,KAAK,QAAQ,OAAA,CAAQ,MAAM,IAAM,EAAE,QAAQ,CAAA,GAAiB,CAAA;AAAA;EAGjF,eAAe;AACb,SAAK,UAAU,CAAA;AAAA;EAGjB,yBAAyB;AACvB,WAAO,EAAkB,KAAK,SAAS,EAAE,aAAa,KAAK,OAAO,YAAA,CAAa;AAAA;EAGjF,MAAM,GAA4B;AAChC,SAAK,QAAQ,GACb,KAAK,UAAU,IACf,KAAK,WAAW;AAAA;EAGlB,OAAO;AACL,SAAK,UAAU;AAAA;EAGjB,YAAY;AACV,WAAO,KAAK;AAAA;EAGd,KAAK,GAAgC;AACnC,UAAM,IAAO,EAAa,KAAK,OAAO,GAAI;AAAA,MACxC,KAAK,KAAK,OAAO;AAAA,MACjB,KAAK,KAAK,OAAO;AAAA,MACjB,UAAU,KAAK,OAAO;AAAA,KACvB;AACD,SAAK,QAAQ;AAEb,UAAM,IAAO,EAAW;AAAA,MACtB,UAAU,EAAK;AAAA,MACf,UAAU,EAAK;AAAA,MACf,YAAY,KAAK,OAAO;AAAA,MACxB,QAAQ,KAAK,OAAO;AAAA,MACpB,QAAQ;AAAA,QACN,kBAAkB,KAAK,OAAO;AAAA,QAC9B,uBAAuB,KAAK,OAAO;AAAA,QACnC,YAAY,KAAK,OAAO;AAAA;KAE3B;AAED,WAAI,EAAK,eACP,KAAK,UAAU,IACf,KAAK,WAAW,KAGX;AAAA,MACL,GAAG;AAAA,MACH,GAAG;AAAA,MACH,WAAW,KAAK;AAAA,MAChB,YAAY,KAAK;AAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare function stepMomentum({ position, velocity }: StepMomentumState, dt: number, { min, max, friction }: StepMomentumConfig): StepMomentumState;
|
|
2
|
+
export default stepMomentum;
|
|
3
|
+
|
|
4
|
+
declare interface StepMomentumConfig {
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
friction: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare interface StepMomentumState {
|
|
11
|
+
position: number;
|
|
12
|
+
velocity: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { }
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function w({position:s,velocity:e},n,{min:t,max:f,friction:p}){if(n<=0)return{position:s,velocity:e};t>f&&([t,f]=[f,t]);const l=s+e*n;let u=!1,r=l;return r<t?(r=t,u=!0):r>f&&(r=f,u=!0),e*=p,u&&(e=0),{position:r,velocity:e}}module.exports=w;
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=stepMomentum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stepMomentum.js","names":[],"sources":["../src/momentum/stepMomentum/stepMomentum.ts"],"sourcesContent":["export interface StepMomentumState {\n position: number;\n velocity: number;\n}\n\nexport interface StepMomentumConfig {\n min: number;\n max: number;\n friction: number;\n}\n\nexport default function stepMomentum(\n { position, velocity }: StepMomentumState,\n dt: number,\n { min, max, friction }: StepMomentumConfig,\n): StepMomentumState {\n if (dt <= 0) return { position, velocity };\n\n if (min > max) {\n [min, max] = [max, min];\n }\n\n const nextRaw = position + velocity * dt;\n let clamped = false;\n let next = nextRaw;\n\n if (next < min) {\n next = min;\n clamped = true;\n } else if (next > max) {\n next = max;\n clamped = true;\n }\n\n velocity *= friction;\n\n if (clamped) velocity = 0;\n\n return { position: next, velocity };\n}\n"],"mappings":"AAWA,SAAwB,EACtB,CAAE,SAAA,EAAU,SAAA,CAAA,EACZ,EACA,CAAE,IAAA,EAAK,IAAA,EAAK,SAAA,CAAA,EACO,CACnB,GAAI,GAAM,EAAG,MAAO,CAAE,SAAA,EAAU,SAAA,GAE5B,EAAM,IACR,CAAC,EAAK,CAAA,EAAO,CAAC,EAAK,CAAA,GAGrB,MAAM,EAAU,EAAW,EAAW,EACtC,IAAI,EAAU,GACV,EAAO,EAEX,OAAI,EAAO,GACT,EAAO,EACP,EAAU,IACD,EAAO,IAChB,EAAO,EACP,EAAU,IAGZ,GAAY,EAER,IAAS,EAAW,GAEjB,CAAE,SAAU,EAAM,SAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function a({ position: s, velocity: e }, n, { min: t, max: f, friction: p }) {
|
|
2
|
+
if (n <= 0) return {
|
|
3
|
+
position: s,
|
|
4
|
+
velocity: e
|
|
5
|
+
};
|
|
6
|
+
t > f && ([t, f] = [f, t]);
|
|
7
|
+
const l = s + e * n;
|
|
8
|
+
let u = !1, r = l;
|
|
9
|
+
return r < t ? (r = t, u = !0) : r > f && (r = f, u = !0), e *= p, u && (e = 0), {
|
|
10
|
+
position: r,
|
|
11
|
+
velocity: e
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
a as default
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=stepMomentum.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stepMomentum.mjs","names":[],"sources":["../src/momentum/stepMomentum/stepMomentum.ts"],"sourcesContent":["export interface StepMomentumState {\n position: number;\n velocity: number;\n}\n\nexport interface StepMomentumConfig {\n min: number;\n max: number;\n friction: number;\n}\n\nexport default function stepMomentum(\n { position, velocity }: StepMomentumState,\n dt: number,\n { min, max, friction }: StepMomentumConfig,\n): StepMomentumState {\n if (dt <= 0) return { position, velocity };\n\n if (min > max) {\n [min, max] = [max, min];\n }\n\n const nextRaw = position + velocity * dt;\n let clamped = false;\n let next = nextRaw;\n\n if (next < min) {\n next = min;\n clamped = true;\n } else if (next > max) {\n next = max;\n clamped = true;\n }\n\n velocity *= friction;\n\n if (clamped) velocity = 0;\n\n return { position: next, velocity };\n}\n"],"mappings":"AAWA,SAAwB,EACtB,EAAE,UAAA,GAAU,UAAA,EAAA,GACZ,GACA,EAAE,KAAA,GAAK,KAAA,GAAK,UAAA,EAAA,GACO;AACnB,MAAI,KAAM,EAAG,QAAO;AAAA,IAAE,UAAA;AAAA,IAAU,UAAA;AAAA;AAEhC,EAAI,IAAM,MACR,CAAC,GAAK,CAAA,IAAO,CAAC,GAAK,CAAA;AAGrB,QAAM,IAAU,IAAW,IAAW;AACtC,MAAI,IAAU,IACV,IAAO;AAEX,SAAI,IAAO,KACT,IAAO,GACP,IAAU,MACD,IAAO,MAChB,IAAO,GACP,IAAU,KAGZ,KAAY,GAER,MAAS,IAAW,IAEjB;AAAA,IAAE,UAAU;AAAA,IAAM,UAAA;AAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@maru-ui/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Framework-agnostic core utilities and engine for Maru UI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.mjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"default": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./*": {
|
|
17
|
+
"types": "./dist/*.d.ts",
|
|
18
|
+
"import": "./dist/*.mjs",
|
|
19
|
+
"default": "./dist/*.mjs",
|
|
20
|
+
"require": "./dist/*.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "vite build",
|
|
28
|
+
"dev": "vite build --watch",
|
|
29
|
+
"type-check": "tsc --noEmit",
|
|
30
|
+
"clean": "rm -rf dist",
|
|
31
|
+
"test": "vitest"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@maru-ui/config-typescript": "workspace:*",
|
|
35
|
+
"@maru-ui/config-vitest": "workspace:*",
|
|
36
|
+
"glob": "^13.0.6",
|
|
37
|
+
"typescript": "^5.8.3",
|
|
38
|
+
"vite": "^8.0.0",
|
|
39
|
+
"vite-plugin-dts": "^4.5.4",
|
|
40
|
+
"vitest": "^4.1.0"
|
|
41
|
+
}
|
|
42
|
+
}
|