@stroke-stabilizer/core 0.1.3
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/README.md +397 -0
- package/dist/StabilizedPointer.d.ts +246 -0
- package/dist/StabilizedPointer.d.ts.map +1 -0
- package/dist/filters/EmaFilter.d.ts +25 -0
- package/dist/filters/EmaFilter.d.ts.map +1 -0
- package/dist/filters/KalmanFilter.d.ts +21 -0
- package/dist/filters/KalmanFilter.d.ts.map +1 -0
- package/dist/filters/LinearPredictionFilter.d.ts +54 -0
- package/dist/filters/LinearPredictionFilter.d.ts.map +1 -0
- package/dist/filters/MovingAverageFilter.d.ts +16 -0
- package/dist/filters/MovingAverageFilter.d.ts.map +1 -0
- package/dist/filters/NoiseFilter.d.ts +16 -0
- package/dist/filters/NoiseFilter.d.ts.map +1 -0
- package/dist/filters/OneEuroFilter.d.ts +45 -0
- package/dist/filters/OneEuroFilter.d.ts.map +1 -0
- package/dist/filters/StringFilter.d.ts +16 -0
- package/dist/filters/StringFilter.d.ts.map +1 -0
- package/dist/filters/index.d.ts +15 -0
- package/dist/filters/index.d.ts.map +1 -0
- package/dist/index.cjs +1086 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1086 -0
- package/dist/index.js.map +1 -0
- package/dist/kernels/BilateralKernel.d.ts +48 -0
- package/dist/kernels/BilateralKernel.d.ts.map +1 -0
- package/dist/kernels/boxKernel.d.ts +16 -0
- package/dist/kernels/boxKernel.d.ts.map +1 -0
- package/dist/kernels/gaussianKernel.d.ts +17 -0
- package/dist/kernels/gaussianKernel.d.ts.map +1 -0
- package/dist/kernels/index.d.ts +11 -0
- package/dist/kernels/index.d.ts.map +1 -0
- package/dist/kernels/triangleKernel.d.ts +16 -0
- package/dist/kernels/triangleKernel.d.ts.map +1 -0
- package/dist/kernels/types.d.ts +38 -0
- package/dist/kernels/types.d.ts.map +1 -0
- package/dist/presets.d.ts +36 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/smooth.d.ts +27 -0
- package/dist/smooth.d.ts.map +1 -0
- package/dist/types.d.ts +33 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Filter } from '../types';
|
|
2
|
+
export interface LinearPredictionFilterParams {
|
|
3
|
+
/**
|
|
4
|
+
* Number of points used for prediction
|
|
5
|
+
* More points = more stable but higher computation cost
|
|
6
|
+
* Recommended: 3-5
|
|
7
|
+
*/
|
|
8
|
+
historySize: number;
|
|
9
|
+
/**
|
|
10
|
+
* Prediction strength (0-1)
|
|
11
|
+
* - 0: No prediction (returns current position as-is)
|
|
12
|
+
* - 1: Full prediction (maximally considers velocity/acceleration)
|
|
13
|
+
* Recommended: 0.3-0.7
|
|
14
|
+
*/
|
|
15
|
+
predictionFactor: number;
|
|
16
|
+
/**
|
|
17
|
+
* Smoothing coefficient (0-1)
|
|
18
|
+
* EMA coefficient applied to prediction output
|
|
19
|
+
* Recommended: 0.5-0.8
|
|
20
|
+
*/
|
|
21
|
+
smoothing?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a linear prediction filter
|
|
25
|
+
*
|
|
26
|
+
* Compensates for filter-induced latency by estimating velocity and
|
|
27
|
+
* acceleration from past positions to predict the next position.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Standard settings
|
|
32
|
+
* const pointer = new StabilizedPointer()
|
|
33
|
+
* .addFilter(linearPredictionFilter({
|
|
34
|
+
* historySize: 4,
|
|
35
|
+
* predictionFactor: 0.5
|
|
36
|
+
* }))
|
|
37
|
+
*
|
|
38
|
+
* // Strong prediction (prioritize latency reduction)
|
|
39
|
+
* const responsive = linearPredictionFilter({
|
|
40
|
+
* historySize: 3,
|
|
41
|
+
* predictionFactor: 0.8,
|
|
42
|
+
* smoothing: 0.7
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
45
|
+
* // Stability focused
|
|
46
|
+
* const stable = linearPredictionFilter({
|
|
47
|
+
* historySize: 5,
|
|
48
|
+
* predictionFactor: 0.3,
|
|
49
|
+
* smoothing: 0.5
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function linearPredictionFilter(params: LinearPredictionFilterParams): Filter;
|
|
54
|
+
//# sourceMappingURL=LinearPredictionFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinearPredictionFilter.d.ts","sourceRoot":"","sources":["../../src/filters/LinearPredictionFilter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,UAAU,CAAA;AAErE,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;;;;OAKG;IACH,gBAAgB,EAAE,MAAM,CAAA;IACxB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AA8OD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,4BAA4B,GACnC,MAAM,CAER"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Filter } from '../types';
|
|
2
|
+
export interface MovingAverageFilterParams {
|
|
3
|
+
/** Number of points to average */
|
|
4
|
+
windowSize: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Create a moving average filter
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const pointer = new StabilizedPointer()
|
|
12
|
+
* .addFilter(movingAverageFilter({ windowSize: 5 }))
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function movingAverageFilter(params: MovingAverageFilterParams): Filter;
|
|
16
|
+
//# sourceMappingURL=MovingAverageFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MovingAverageFilter.d.ts","sourceRoot":"","sources":["../../src/filters/MovingAverageFilter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,UAAU,CAAA;AAErE,MAAM,WAAW,yBAAyB;IACxC,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAA;CACnB;AAoED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,yBAAyB,GAAG,MAAM,CAE7E"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Filter } from '../types';
|
|
2
|
+
export interface NoiseFilterParams {
|
|
3
|
+
/** Minimum movement distance (px). Movements smaller than this are rejected */
|
|
4
|
+
minDistance: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Create a noise filter
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const pointer = new StabilizedPointer()
|
|
12
|
+
* .addFilter(noiseFilter({ minDistance: 2 }))
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function noiseFilter(params: NoiseFilterParams): Filter;
|
|
16
|
+
//# sourceMappingURL=NoiseFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NoiseFilter.d.ts","sourceRoot":"","sources":["../../src/filters/NoiseFilter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,UAAU,CAAA;AAErE,MAAM,WAAW,iBAAiB;IAChC,+EAA+E;IAC/E,WAAW,EAAE,MAAM,CAAA;CACpB;AA8CD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAE7D"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Filter } from '../types';
|
|
2
|
+
export interface OneEuroFilterParams {
|
|
3
|
+
/**
|
|
4
|
+
* Minimum cutoff frequency (Hz)
|
|
5
|
+
* Smoothing strength at low speed. Lower = smoother.
|
|
6
|
+
* Recommended: 0.5 - 2.0
|
|
7
|
+
*/
|
|
8
|
+
minCutoff: number;
|
|
9
|
+
/**
|
|
10
|
+
* Speed coefficient
|
|
11
|
+
* Rate of cutoff frequency increase based on speed.
|
|
12
|
+
* Higher = more responsive at high speed.
|
|
13
|
+
* Recommended: 0.001 - 0.01
|
|
14
|
+
*/
|
|
15
|
+
beta: number;
|
|
16
|
+
/**
|
|
17
|
+
* Derivative cutoff frequency (Hz)
|
|
18
|
+
* Smoothing for velocity estimation. Usually fixed at 1.0.
|
|
19
|
+
*/
|
|
20
|
+
dCutoff?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a One Euro Filter
|
|
24
|
+
*
|
|
25
|
+
* Speed-adaptive low-pass filter.
|
|
26
|
+
* Strong smoothing at low speed, responsive at high speed.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // Balanced settings
|
|
31
|
+
* const pointer = new StabilizedPointer()
|
|
32
|
+
* .addFilter(oneEuroFilter({
|
|
33
|
+
* minCutoff: 1.0,
|
|
34
|
+
* beta: 0.007
|
|
35
|
+
* }))
|
|
36
|
+
*
|
|
37
|
+
* // Smoother (higher latency)
|
|
38
|
+
* const smooth = oneEuroFilter({ minCutoff: 0.5, beta: 0.001 })
|
|
39
|
+
*
|
|
40
|
+
* // More responsive (may have jitter)
|
|
41
|
+
* const responsive = oneEuroFilter({ minCutoff: 2.0, beta: 0.01 })
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function oneEuroFilter(params: OneEuroFilterParams): Filter;
|
|
45
|
+
//# sourceMappingURL=OneEuroFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OneEuroFilter.d.ts","sourceRoot":"","sources":["../../src/filters/OneEuroFilter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,UAAU,CAAA;AAErE,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;;;;OAKG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAqKD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAEjE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Filter } from '../types';
|
|
2
|
+
export interface StringFilterParams {
|
|
3
|
+
/** String length (px): Dead zone radius */
|
|
4
|
+
stringLength: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Create a string stabilization filter
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const pointer = new StabilizedPointer()
|
|
12
|
+
* .addFilter(stringFilter({ stringLength: 10 }))
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function stringFilter(params: StringFilterParams): Filter;
|
|
16
|
+
//# sourceMappingURL=StringFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StringFilter.d.ts","sourceRoot":"","sources":["../../src/filters/StringFilter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,UAAU,CAAA;AAErE,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAA;CACrB;AA8DD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAE/D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { noiseFilter } from './NoiseFilter';
|
|
2
|
+
export type { NoiseFilterParams } from './NoiseFilter';
|
|
3
|
+
export { kalmanFilter } from './KalmanFilter';
|
|
4
|
+
export type { KalmanFilterParams } from './KalmanFilter';
|
|
5
|
+
export { movingAverageFilter } from './MovingAverageFilter';
|
|
6
|
+
export type { MovingAverageFilterParams } from './MovingAverageFilter';
|
|
7
|
+
export { stringFilter } from './StringFilter';
|
|
8
|
+
export type { StringFilterParams } from './StringFilter';
|
|
9
|
+
export { emaFilter } from './EmaFilter';
|
|
10
|
+
export type { EmaFilterParams } from './EmaFilter';
|
|
11
|
+
export { oneEuroFilter } from './OneEuroFilter';
|
|
12
|
+
export type { OneEuroFilterParams } from './OneEuroFilter';
|
|
13
|
+
export { linearPredictionFilter } from './LinearPredictionFilter';
|
|
14
|
+
export type { LinearPredictionFilterParams } from './LinearPredictionFilter';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/filters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,YAAY,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AAEtE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,YAAY,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAA"}
|