@ac-kit/ui-gesture 0.0.0-stage → 0.1.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/CHANGELOG.md +107 -0
- package/LICENSE +28 -0
- package/README.md +310 -2
- package/dist/_validate.d.ts +4 -0
- package/dist/_validate.d.ts.map +1 -0
- package/dist/_validate.js +10 -0
- package/dist/_validate.js.map +1 -0
- package/dist/dom/_claim.d.ts +8 -0
- package/dist/dom/_claim.d.ts.map +1 -0
- package/dist/dom/_claim.js +14 -0
- package/dist/dom/_claim.js.map +1 -0
- package/dist/dom/_pointer-engine.d.ts +121 -0
- package/dist/dom/_pointer-engine.d.ts.map +1 -0
- package/dist/dom/_pointer-engine.js +559 -0
- package/dist/dom/_pointer-engine.js.map +1 -0
- package/dist/dom/_press-driver.d.ts +39 -0
- package/dist/dom/_press-driver.d.ts.map +1 -0
- package/dist/dom/_press-driver.js +121 -0
- package/dist/dom/_press-driver.js.map +1 -0
- package/dist/dom/index.d.ts +5 -0
- package/dist/dom/index.d.ts.map +1 -0
- package/dist/dom/index.js +5 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/dom/pointer-binding.d.ts +111 -0
- package/dist/dom/pointer-binding.d.ts.map +1 -0
- package/dist/dom/pointer-binding.js +35 -0
- package/dist/dom/pointer-binding.js.map +1 -0
- package/dist/dom/press-binding.d.ts +29 -0
- package/dist/dom/press-binding.d.ts.map +1 -0
- package/dist/dom/press-binding.js +53 -0
- package/dist/dom/press-binding.js.map +1 -0
- package/dist/dom/transform-binding.d.ts +81 -0
- package/dist/dom/transform-binding.d.ts.map +1 -0
- package/dist/dom/transform-binding.js +349 -0
- package/dist/dom/transform-binding.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/inertia/inertia.d.ts +32 -0
- package/dist/inertia/inertia.d.ts.map +1 -0
- package/dist/inertia/inertia.js +62 -0
- package/dist/inertia/inertia.js.map +1 -0
- package/dist/keys/key-step.d.ts +25 -0
- package/dist/keys/key-step.d.ts.map +1 -0
- package/dist/keys/key-step.js +30 -0
- package/dist/keys/key-step.js.map +1 -0
- package/dist/pointer/_slop.d.ts +26 -0
- package/dist/pointer/_slop.d.ts.map +1 -0
- package/dist/pointer/_slop.js +74 -0
- package/dist/pointer/_slop.js.map +1 -0
- package/dist/pointer/pointer-input.d.ts +61 -0
- package/dist/pointer/pointer-input.d.ts.map +1 -0
- package/dist/pointer/pointer-input.js +6 -0
- package/dist/pointer/pointer-input.js.map +1 -0
- package/dist/press/press-gesture.d.ts +282 -0
- package/dist/press/press-gesture.d.ts.map +1 -0
- package/dist/press/press-gesture.js +579 -0
- package/dist/press/press-gesture.js.map +1 -0
- package/dist/transform/transform-gesture.d.ts +174 -0
- package/dist/transform/transform-gesture.d.ts.map +1 -0
- package/dist/transform/transform-gesture.js +415 -0
- package/dist/transform/transform-gesture.js.map +1 -0
- package/dist/velocity/velocity-tracker.d.ts +69 -0
- package/dist/velocity/velocity-tracker.d.ts.map +1 -0
- package/dist/velocity/velocity-tracker.js +152 -0
- package/dist/velocity/velocity-tracker.js.map +1 -0
- package/dist/wheel/wheel.d.ts +115 -0
- package/dist/wheel/wheel.d.ts.map +1 -0
- package/dist/wheel/wheel.js +162 -0
- package/dist/wheel/wheel.js.map +1 -0
- package/package.json +79 -3
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** A velocity, in units per millisecond. */
|
|
2
|
+
export type Velocity = {
|
|
3
|
+
readonly x: number;
|
|
4
|
+
readonly y: number;
|
|
5
|
+
};
|
|
6
|
+
/** Options of {@link VelocityTracker}. */
|
|
7
|
+
export type VelocityTrackerOptions = {
|
|
8
|
+
/** How far back samples count, in ms. Default 100. */
|
|
9
|
+
readonly horizon?: number;
|
|
10
|
+
/**
|
|
11
|
+
* How many samples are kept. Default `ceil(horizon) + 1` (101): the whole
|
|
12
|
+
* horizon at 1 kHz.
|
|
13
|
+
*/
|
|
14
|
+
readonly capacity?: number;
|
|
15
|
+
/** Fewer samples in the horizon give a zero velocity. Default 3. */
|
|
16
|
+
readonly minSamples?: number;
|
|
17
|
+
/**
|
|
18
|
+
* A last sample older than this at the time asked gives a zero velocity, and
|
|
19
|
+
* a gap longer than this between two samples ends the window, in ms. Default 40.
|
|
20
|
+
*/
|
|
21
|
+
readonly stopAfter?: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Estimates a pointer's velocity from its recent positions, by a least-squares
|
|
25
|
+
* line through the samples of the last `horizon` ms (`math-stats`'
|
|
26
|
+
* `linearRegressionSlope`). `add` is O(1) and allocates nothing; `velocity` is
|
|
27
|
+
* O(capacity).
|
|
28
|
+
*
|
|
29
|
+
* The samples live in a `TypedColumnRing`, so a stream of any rate keeps the
|
|
30
|
+
* newest `capacity` of them. A sample older than the horizon, or newer than the
|
|
31
|
+
* time asked, takes no part in the line, and neither does one before a gap
|
|
32
|
+
* longer than `stopAfter` between two consecutive samples: a hold followed by a
|
|
33
|
+
* flick reports the flick. A pointer that has not changed position for longer
|
|
34
|
+
* than `stopAfter` has stopped, however recent the last sample that repeats its
|
|
35
|
+
* position: a release at the spot where it stopped says nothing about how fast
|
|
36
|
+
* it was going.
|
|
37
|
+
*
|
|
38
|
+
* Positions are taken relative to the newest sample, so a stream standing still
|
|
39
|
+
* at any distance from the origin has a velocity of zero; a velocity beyond the
|
|
40
|
+
* double range saturates at `±Number.MAX_VALUE`.
|
|
41
|
+
*/
|
|
42
|
+
export declare class VelocityTracker {
|
|
43
|
+
private readonly horizon_;
|
|
44
|
+
private readonly minSamples_;
|
|
45
|
+
private readonly stopAfter_;
|
|
46
|
+
private readonly samples_;
|
|
47
|
+
private readonly times_;
|
|
48
|
+
private readonly xs_;
|
|
49
|
+
private readonly ys_;
|
|
50
|
+
private readonly reached_;
|
|
51
|
+
private readonly scratchTimes_;
|
|
52
|
+
private readonly scratchXs_;
|
|
53
|
+
private readonly scratchYs_;
|
|
54
|
+
constructor(options?: VelocityTrackerOptions);
|
|
55
|
+
/** @throws {RangeError} For a non-finite value or a time before the last one. */
|
|
56
|
+
add(time: number, x: number, y: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* The velocity at `time`, usually a release's: per ms, in the units of the
|
|
59
|
+
* positions. Zero when fewer than `minSamples` samples fall within `horizon`
|
|
60
|
+
* ms before `time`, or when the pointer last changed position more than
|
|
61
|
+
* `stopAfter` ms before `time`.
|
|
62
|
+
*
|
|
63
|
+
* @throws {RangeError} For a non-finite `time`.
|
|
64
|
+
*/
|
|
65
|
+
velocity(time: number): Velocity;
|
|
66
|
+
/** Forgets every sample. */
|
|
67
|
+
reset(): void;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=velocity-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"velocity-tracker.d.ts","sourceRoot":"","sources":["../../src/velocity/velocity-tracker.ts"],"names":[],"mappings":"AAUA,4CAA4C;AAC5C,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,0CAA0C;AAC1C,MAAM,MAAM,sBAAsB,GAAG;IACpC,sDAAsD;IACtD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,oEAAoE;IACpE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAOF;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,eAAe;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAGpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA2C;IACpE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IAExC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE3C,YAAY,OAAO,CAAC,EAAE,sBAAsB,EAqB3C;IAED,iFAAiF;IACjF,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAsB5C;IAED;;;;;;;OAOG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAkD/B;IAED,4BAA4B;IAC5B,KAAK,IAAI,IAAI,CAEZ;CACD"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { assertFinite, assertInteger, assertNonNegative, assertPositive, clamp, } from "@ac-kit/core";
|
|
2
|
+
import { TypedColumnRing } from "@ac-kit/data";
|
|
3
|
+
import { linearRegressionSlope } from "@ac-kit/math-stats";
|
|
4
|
+
const DEFAULT_HORIZON_ = 100;
|
|
5
|
+
const DEFAULT_MIN_SAMPLES_ = 3;
|
|
6
|
+
const DEFAULT_STOP_AFTER_ = 40;
|
|
7
|
+
const ZERO_VELOCITY_ = Object.freeze({ x: 0, y: 0 });
|
|
8
|
+
/**
|
|
9
|
+
* Estimates a pointer's velocity from its recent positions, by a least-squares
|
|
10
|
+
* line through the samples of the last `horizon` ms (`math-stats`'
|
|
11
|
+
* `linearRegressionSlope`). `add` is O(1) and allocates nothing; `velocity` is
|
|
12
|
+
* O(capacity).
|
|
13
|
+
*
|
|
14
|
+
* The samples live in a `TypedColumnRing`, so a stream of any rate keeps the
|
|
15
|
+
* newest `capacity` of them. A sample older than the horizon, or newer than the
|
|
16
|
+
* time asked, takes no part in the line, and neither does one before a gap
|
|
17
|
+
* longer than `stopAfter` between two consecutive samples: a hold followed by a
|
|
18
|
+
* flick reports the flick. A pointer that has not changed position for longer
|
|
19
|
+
* than `stopAfter` has stopped, however recent the last sample that repeats its
|
|
20
|
+
* position: a release at the spot where it stopped says nothing about how fast
|
|
21
|
+
* it was going.
|
|
22
|
+
*
|
|
23
|
+
* Positions are taken relative to the newest sample, so a stream standing still
|
|
24
|
+
* at any distance from the origin has a velocity of zero; a velocity beyond the
|
|
25
|
+
* double range saturates at `±Number.MAX_VALUE`.
|
|
26
|
+
*/
|
|
27
|
+
export class VelocityTracker {
|
|
28
|
+
horizon_;
|
|
29
|
+
minSamples_;
|
|
30
|
+
stopAfter_;
|
|
31
|
+
// Four columns: time, x, y, and when the position was reached — the sample's
|
|
32
|
+
// own time, or that of the sample before it when the position did not change.
|
|
33
|
+
samples_;
|
|
34
|
+
times_;
|
|
35
|
+
xs_;
|
|
36
|
+
ys_;
|
|
37
|
+
reached_;
|
|
38
|
+
// Reused by `velocity`, which hands the regression plain arrays.
|
|
39
|
+
scratchTimes_ = [];
|
|
40
|
+
scratchXs_ = [];
|
|
41
|
+
scratchYs_ = [];
|
|
42
|
+
constructor(options) {
|
|
43
|
+
const horizon = options?.horizon ?? DEFAULT_HORIZON_;
|
|
44
|
+
assertPositive(horizon, "horizon");
|
|
45
|
+
const capacity = options?.capacity ?? Math.ceil(horizon) + 1;
|
|
46
|
+
assertInteger(capacity, "capacity", 1);
|
|
47
|
+
const minSamples = options?.minSamples ?? DEFAULT_MIN_SAMPLES_;
|
|
48
|
+
assertInteger(minSamples, "minSamples", 1);
|
|
49
|
+
const stopAfter = options?.stopAfter ?? DEFAULT_STOP_AFTER_;
|
|
50
|
+
assertNonNegative(stopAfter, "stopAfter");
|
|
51
|
+
this.horizon_ = horizon;
|
|
52
|
+
this.minSamples_ = minSamples;
|
|
53
|
+
this.stopAfter_ = stopAfter;
|
|
54
|
+
this.samples_ = new TypedColumnRing(Float64Array, {
|
|
55
|
+
columnCount: 4,
|
|
56
|
+
capacity,
|
|
57
|
+
});
|
|
58
|
+
this.times_ = this.samples_.column(0);
|
|
59
|
+
this.xs_ = this.samples_.column(1);
|
|
60
|
+
this.ys_ = this.samples_.column(2);
|
|
61
|
+
this.reached_ = this.samples_.column(3);
|
|
62
|
+
}
|
|
63
|
+
/** @throws {RangeError} For a non-finite value or a time before the last one. */
|
|
64
|
+
add(time, x, y) {
|
|
65
|
+
assertFinite(time, "time");
|
|
66
|
+
assertFinite(x, "x");
|
|
67
|
+
assertFinite(y, "y");
|
|
68
|
+
let reached = time;
|
|
69
|
+
if (this.samples_.length > 0) {
|
|
70
|
+
const newest = this.samples_.slotAt(-1);
|
|
71
|
+
if (time < this.times_[newest]) {
|
|
72
|
+
throw new RangeError(`time must not go backwards, got ${time} after ${this.times_[newest]}`);
|
|
73
|
+
}
|
|
74
|
+
if (x === this.xs_[newest] && y === this.ys_[newest]) {
|
|
75
|
+
reached = this.reached_[newest];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const slot = this.samples_.pushSlot();
|
|
79
|
+
this.times_[slot] = time;
|
|
80
|
+
this.xs_[slot] = x;
|
|
81
|
+
this.ys_[slot] = y;
|
|
82
|
+
this.reached_[slot] = reached;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The velocity at `time`, usually a release's: per ms, in the units of the
|
|
86
|
+
* positions. Zero when fewer than `minSamples` samples fall within `horizon`
|
|
87
|
+
* ms before `time`, or when the pointer last changed position more than
|
|
88
|
+
* `stopAfter` ms before `time`.
|
|
89
|
+
*
|
|
90
|
+
* @throws {RangeError} For a non-finite `time`.
|
|
91
|
+
*/
|
|
92
|
+
velocity(time) {
|
|
93
|
+
assertFinite(time, "time");
|
|
94
|
+
const samples = this.samples_;
|
|
95
|
+
let included = 0;
|
|
96
|
+
let sinceMoved = Number.POSITIVE_INFINITY;
|
|
97
|
+
let anchorX = 0;
|
|
98
|
+
let anchorY = 0;
|
|
99
|
+
let previousTime = time;
|
|
100
|
+
// Newest to oldest: the times never decrease, so the first sample past the
|
|
101
|
+
// horizon ends the walk.
|
|
102
|
+
for (let age = 1; age <= samples.length; age++) {
|
|
103
|
+
const slot = samples.slotAt(-age);
|
|
104
|
+
const sampleTime = this.times_[slot];
|
|
105
|
+
if (sampleTime > time) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (time - sampleTime > this.horizon_) {
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
// The window ends at a gap longer than `stopAfter` between two samples
|
|
112
|
+
// (Flutter's `VelocityTracker`, Android's impulse strategy): what came
|
|
113
|
+
// before the pointer paused is not part of this movement.
|
|
114
|
+
if (included > 0 && previousTime - sampleTime > this.stopAfter_) {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
previousTime = sampleTime;
|
|
118
|
+
if (included === 0) {
|
|
119
|
+
sinceMoved = time - this.reached_[slot];
|
|
120
|
+
anchorX = this.xs_[slot] * 0.5;
|
|
121
|
+
anchorY = this.ys_[slot] * 0.5;
|
|
122
|
+
}
|
|
123
|
+
// Halved, so that the difference of two finite positions is finite.
|
|
124
|
+
this.scratchTimes_[included] = sampleTime - time;
|
|
125
|
+
this.scratchXs_[included] = this.xs_[slot] * 0.5 - anchorX;
|
|
126
|
+
this.scratchYs_[included] = this.ys_[slot] * 0.5 - anchorY;
|
|
127
|
+
included++;
|
|
128
|
+
}
|
|
129
|
+
if (included < this.minSamples_ || sinceMoved > this.stopAfter_) {
|
|
130
|
+
return ZERO_VELOCITY_;
|
|
131
|
+
}
|
|
132
|
+
this.scratchTimes_.length = included;
|
|
133
|
+
this.scratchXs_.length = included;
|
|
134
|
+
this.scratchYs_.length = included;
|
|
135
|
+
return {
|
|
136
|
+
x: slope_(this.scratchTimes_, this.scratchXs_),
|
|
137
|
+
y: slope_(this.scratchTimes_, this.scratchYs_),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** Forgets every sample. */
|
|
141
|
+
reset() {
|
|
142
|
+
this.samples_.clear();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The regression's slope of positions halved and relative to the newest,
|
|
147
|
+
* doubled back and saturating at `±Number.MAX_VALUE`.
|
|
148
|
+
*/
|
|
149
|
+
function slope_(times, halved) {
|
|
150
|
+
return clamp(2 * linearRegressionSlope(times, halved), -Number.MAX_VALUE, Number.MAX_VALUE);
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=velocity-tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"velocity-tracker.js","sourceRoot":"","sources":["../../src/velocity/velocity-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,KAAK,GACL,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAuB3D,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,cAAc,GAAa,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAE/D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,eAAe;IACV,QAAQ,CAAS;IACjB,WAAW,CAAS;IACpB,UAAU,CAAS;IACpC,6EAA6E;IAC7E,8EAA8E;IAC7D,QAAQ,CAA2C;IACnD,MAAM,CAAe;IACrB,GAAG,CAAe;IAClB,GAAG,CAAe;IAClB,QAAQ,CAAe;IAC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C,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAE,GAAG,GAAG,GAAG,OAAO,CAAC;YAC5D,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAE,GAAG,GAAG,GAAG,OAAO,CAAC;YAC5D,QAAQ,EAAE,CAAC;QACZ,CAAC;QACD,IAAI,QAAQ,GAAG,IAAI,CAAC,WAAW,IAAI,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YACjE,OAAO,cAAc,CAAC;QACvB,CAAC;QAED,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,QAAQ,CAAC;QACrC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,QAAQ,CAAC;QAClC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,QAAQ,CAAC;QAElC,OAAO;YACN,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC;YAC9C,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC;SAC9C,CAAC;IACH,CAAC;IAED,4BAA4B;IAC5B,KAAK;QACJ,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACD;AAED;;;GAGG;AACH,SAAS,MAAM,CAAC,KAAwB,EAAE,MAAyB;IAClE,OAAO,KAAK,CACX,CAAC,GAAG,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,EACxC,CAAC,MAAM,CAAC,SAAS,EACjB,MAAM,CAAC,SAAS,CAChB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { ModifierKeys } from "../pointer/pointer-input.js";
|
|
2
|
+
import type { TransformStep } from "../transform/transform-gesture.js";
|
|
3
|
+
/** UI Events' `deltaMode` values, so the root reads no `WheelEvent` global. */
|
|
4
|
+
export declare const WHEEL_DELTA_PIXEL = 0;
|
|
5
|
+
export declare const WHEEL_DELTA_LINE = 1;
|
|
6
|
+
export declare const WHEEL_DELTA_PAGE = 2;
|
|
7
|
+
/**
|
|
8
|
+
* Pixels per line of a line-mode wheel delta (Firefox's mouse wheel): 40, as
|
|
9
|
+
* Facebook's normalizeWheel, @use-gesture, OpenLayers and MapLibre use, so a
|
|
10
|
+
* three-line notch is 120 px.
|
|
11
|
+
*/
|
|
12
|
+
export declare const WHEEL_LINE_PIXELS = 40;
|
|
13
|
+
/**
|
|
14
|
+
* Pixels per page of a page-mode delta when the page size is not given: 800, as
|
|
15
|
+
* normalizeWheel and @use-gesture.
|
|
16
|
+
*/
|
|
17
|
+
export declare const WHEEL_PAGE_PIXELS = 800;
|
|
18
|
+
/**
|
|
19
|
+
* Mouse-wheel pixels for a zoom of a factor e: 450, MapLibre's `wheelZoomRate`
|
|
20
|
+
* of 1/450.
|
|
21
|
+
*/
|
|
22
|
+
export declare const WHEEL_ZOOM_PIXELS = 450;
|
|
23
|
+
/**
|
|
24
|
+
* Pinch-wheel pixels for a factor e: 100, exactly Chromium's trackpad pinch
|
|
25
|
+
* (`deltaY = −100·ln(scale)`).
|
|
26
|
+
*/
|
|
27
|
+
export declare const PINCH_WHEEL_ZOOM_PIXELS = 100;
|
|
28
|
+
/**
|
|
29
|
+
* Largest pixel-mode `ctrlKey` delta read as a pinch is just under this: 50, a
|
|
30
|
+
* 65 % zoom in one event, which no pinch reaches and a Ctrl-held mouse notch
|
|
31
|
+
* (about 100 px) exceeds. A speed choice only: it never decides what the wheel
|
|
32
|
+
* does.
|
|
33
|
+
*/
|
|
34
|
+
export declare const PINCH_WHEEL_MAX_PIXELS = 50;
|
|
35
|
+
/**
|
|
36
|
+
* Largest zoom factor, or its inverse, one wheel event may give: 2, as
|
|
37
|
+
* MapLibre's `maxScalePerFrame`.
|
|
38
|
+
*/
|
|
39
|
+
export declare const WHEEL_ZOOM_MAX_FACTOR = 2;
|
|
40
|
+
/**
|
|
41
|
+
* A wheel event's fields, as {@link wheelPixels} reads them. Read `deltaMode`
|
|
42
|
+
* before the deltas from a `WheelEvent`.
|
|
43
|
+
*/
|
|
44
|
+
export type WheelInput = ModifierKeys & {
|
|
45
|
+
readonly deltaX: number;
|
|
46
|
+
readonly deltaY: number;
|
|
47
|
+
readonly deltaMode: number;
|
|
48
|
+
readonly x: number;
|
|
49
|
+
readonly y: number;
|
|
50
|
+
readonly time: number;
|
|
51
|
+
};
|
|
52
|
+
export type WheelPixelsOptions = {
|
|
53
|
+
/** Default {@link WHEEL_LINE_PIXELS}. */
|
|
54
|
+
readonly linePixels?: number;
|
|
55
|
+
/**
|
|
56
|
+
* A page's size for page-mode deltas, usually the element's. Default
|
|
57
|
+
* {@link WHEEL_PAGE_PIXELS}, which a zero size (an element with no box) also
|
|
58
|
+
* reads as.
|
|
59
|
+
*/
|
|
60
|
+
readonly pageWidth?: number;
|
|
61
|
+
readonly pageHeight?: number;
|
|
62
|
+
};
|
|
63
|
+
export type WheelPixels = {
|
|
64
|
+
readonly x: number;
|
|
65
|
+
readonly y: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* A wheel delta in pixels, whatever its `deltaMode`. O(1).
|
|
69
|
+
*
|
|
70
|
+
* @throws {RangeError} For a non-finite delta or a `deltaMode` other than 0, 1
|
|
71
|
+
* or 2, and for a negative or non-finite page size.
|
|
72
|
+
*/
|
|
73
|
+
export declare function wheelPixels(input: WheelInput, options?: WheelPixelsOptions): WheelPixels;
|
|
74
|
+
export type WheelTransformOptions = WheelPixelsOptions & {
|
|
75
|
+
/**
|
|
76
|
+
* What an unmodified wheel does. A `ctrlKey` wheel (a trackpad pinch, or Ctrl
|
|
77
|
+
* with a wheel) always zooms. Default `zoom`.
|
|
78
|
+
*/
|
|
79
|
+
readonly action?: "zoom" | "pan";
|
|
80
|
+
/**
|
|
81
|
+
* Cooperative gestures, for a view inside a scrolling page: only a wheel with
|
|
82
|
+
* Ctrl or Meta acts; an unmodified one gives `undefined` and is left to the
|
|
83
|
+
* page. Default false.
|
|
84
|
+
*/
|
|
85
|
+
readonly cooperative?: boolean;
|
|
86
|
+
/** Default {@link WHEEL_ZOOM_PIXELS}. */
|
|
87
|
+
readonly zoomPixels?: number;
|
|
88
|
+
/** Default {@link PINCH_WHEEL_ZOOM_PIXELS}. */
|
|
89
|
+
readonly pinchZoomPixels?: number;
|
|
90
|
+
/**
|
|
91
|
+
* A pixel-mode `ctrlKey` delta smaller than this is a pinch. Finite and not
|
|
92
|
+
* negative; default {@link PINCH_WHEEL_MAX_PIXELS}.
|
|
93
|
+
*/
|
|
94
|
+
readonly pinchMaxPixels?: number;
|
|
95
|
+
/** Default {@link WHEEL_ZOOM_MAX_FACTOR}. */
|
|
96
|
+
readonly maxZoomFactor?: number;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The view change a wheel event asks for, about the pointer: a zoom by
|
|
100
|
+
* `exp(−deltaY / rate)` (wheel down zooms out), capped, at the pinch rate for a
|
|
101
|
+
* small pixel-mode `ctrlKey` delta and at the wheel rate otherwise; or, with
|
|
102
|
+
* `action: "pan"`, a pan by the negated deltas, Shift turning a vertical-only
|
|
103
|
+
* wheel horizontal. `undefined` for a zero delta, and for an unmodified wheel
|
|
104
|
+
* when `cooperative`. O(1), allocating only the step.
|
|
105
|
+
*
|
|
106
|
+
* A zoom reads the vertical delta only: a purely horizontal wheel gives
|
|
107
|
+
* `undefined` when it zooms. Ctrl or Meta held makes any wheel a zoom, as a
|
|
108
|
+
* trackpad pinch (`ctrlKey` with a pixel delta under
|
|
109
|
+
* {@link PINCH_WHEEL_MAX_PIXELS}) or a Ctrl-wheel at the wheel rate.
|
|
110
|
+
*
|
|
111
|
+
* @throws {RangeError} As {@link wheelPixels}, and for a non-finite position or
|
|
112
|
+
* time, an `action` other than `zoom` or `pan`, and unusable options.
|
|
113
|
+
*/
|
|
114
|
+
export declare function wheelTransform(input: WheelInput, options?: WheelTransformOptions): TransformStep | undefined;
|
|
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AM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErE;;;;;GAKG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,kBAAkB,GAC1B,WAAW,CAuBb;AAkCD,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,GAAG;IACxD;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACjC;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,yCAAyC;IACzC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,+CAA+C;IAC/C,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,6CAA6C;IAC7C,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAOF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,qBAAqB,GAC7B,aAAa,GAAG,SAAS,CAyF3B"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { assertFinite, assertInteger, assertNonNegative, assertPositive, clamp, describeValue, } from "@ac-kit/core";
|
|
2
|
+
/** UI Events' `deltaMode` values, so the root reads no `WheelEvent` global. */
|
|
3
|
+
export const WHEEL_DELTA_PIXEL = 0;
|
|
4
|
+
export const WHEEL_DELTA_LINE = 1;
|
|
5
|
+
export const WHEEL_DELTA_PAGE = 2;
|
|
6
|
+
/**
|
|
7
|
+
* Pixels per line of a line-mode wheel delta (Firefox's mouse wheel): 40, as
|
|
8
|
+
* Facebook's normalizeWheel, @use-gesture, OpenLayers and MapLibre use, so a
|
|
9
|
+
* three-line notch is 120 px.
|
|
10
|
+
*/
|
|
11
|
+
export const WHEEL_LINE_PIXELS = 40;
|
|
12
|
+
/**
|
|
13
|
+
* Pixels per page of a page-mode delta when the page size is not given: 800, as
|
|
14
|
+
* normalizeWheel and @use-gesture.
|
|
15
|
+
*/
|
|
16
|
+
export const WHEEL_PAGE_PIXELS = 800;
|
|
17
|
+
/**
|
|
18
|
+
* Mouse-wheel pixels for a zoom of a factor e: 450, MapLibre's `wheelZoomRate`
|
|
19
|
+
* of 1/450.
|
|
20
|
+
*/
|
|
21
|
+
export const WHEEL_ZOOM_PIXELS = 450;
|
|
22
|
+
/**
|
|
23
|
+
* Pinch-wheel pixels for a factor e: 100, exactly Chromium's trackpad pinch
|
|
24
|
+
* (`deltaY = −100·ln(scale)`).
|
|
25
|
+
*/
|
|
26
|
+
export const PINCH_WHEEL_ZOOM_PIXELS = 100;
|
|
27
|
+
/**
|
|
28
|
+
* Largest pixel-mode `ctrlKey` delta read as a pinch is just under this: 50, a
|
|
29
|
+
* 65 % zoom in one event, which no pinch reaches and a Ctrl-held mouse notch
|
|
30
|
+
* (about 100 px) exceeds. A speed choice only: it never decides what the wheel
|
|
31
|
+
* does.
|
|
32
|
+
*/
|
|
33
|
+
export const PINCH_WHEEL_MAX_PIXELS = 50;
|
|
34
|
+
/**
|
|
35
|
+
* Largest zoom factor, or its inverse, one wheel event may give: 2, as
|
|
36
|
+
* MapLibre's `maxScalePerFrame`.
|
|
37
|
+
*/
|
|
38
|
+
export const WHEEL_ZOOM_MAX_FACTOR = 2;
|
|
39
|
+
/**
|
|
40
|
+
* A wheel delta in pixels, whatever its `deltaMode`. O(1).
|
|
41
|
+
*
|
|
42
|
+
* @throws {RangeError} For a non-finite delta or a `deltaMode` other than 0, 1
|
|
43
|
+
* or 2, and for a negative or non-finite page size.
|
|
44
|
+
*/
|
|
45
|
+
export function wheelPixels(input, options) {
|
|
46
|
+
assertFinite(input.deltaX, "deltaX");
|
|
47
|
+
assertFinite(input.deltaY, "deltaY");
|
|
48
|
+
assertInteger(input.deltaMode, "deltaMode");
|
|
49
|
+
return {
|
|
50
|
+
x: input.deltaX *
|
|
51
|
+
pixelsPerUnit_(input.deltaMode, options?.linePixels, "pageWidth", options?.pageWidth),
|
|
52
|
+
y: input.deltaY *
|
|
53
|
+
pixelsPerUnit_(input.deltaMode, options?.linePixels, "pageHeight", options?.pageHeight),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The pixels in one unit of `deltaMode` along an axis whose page size is
|
|
58
|
+
* `page`.
|
|
59
|
+
*/
|
|
60
|
+
function pixelsPerUnit_(deltaMode, linePixels, pageName, page) {
|
|
61
|
+
switch (deltaMode) {
|
|
62
|
+
case WHEEL_DELTA_PIXEL:
|
|
63
|
+
return 1;
|
|
64
|
+
case WHEEL_DELTA_LINE: {
|
|
65
|
+
const pixels = linePixels ?? WHEEL_LINE_PIXELS;
|
|
66
|
+
assertPositive(pixels, "linePixels");
|
|
67
|
+
return pixels;
|
|
68
|
+
}
|
|
69
|
+
case WHEEL_DELTA_PAGE: {
|
|
70
|
+
const size = page ?? WHEEL_PAGE_PIXELS;
|
|
71
|
+
assertNonNegative(size, pageName);
|
|
72
|
+
return size === 0 ? WHEEL_PAGE_PIXELS : size;
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
throw new RangeError(`deltaMode must be 0, 1 or 2, got ${describeValue(deltaMode)}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** `0 - value`, which unlike `-value` never gives `-0`. */
|
|
79
|
+
function negate_(value) {
|
|
80
|
+
return 0 - value;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The view change a wheel event asks for, about the pointer: a zoom by
|
|
84
|
+
* `exp(−deltaY / rate)` (wheel down zooms out), capped, at the pinch rate for a
|
|
85
|
+
* small pixel-mode `ctrlKey` delta and at the wheel rate otherwise; or, with
|
|
86
|
+
* `action: "pan"`, a pan by the negated deltas, Shift turning a vertical-only
|
|
87
|
+
* wheel horizontal. `undefined` for a zero delta, and for an unmodified wheel
|
|
88
|
+
* when `cooperative`. O(1), allocating only the step.
|
|
89
|
+
*
|
|
90
|
+
* A zoom reads the vertical delta only: a purely horizontal wheel gives
|
|
91
|
+
* `undefined` when it zooms. Ctrl or Meta held makes any wheel a zoom, as a
|
|
92
|
+
* trackpad pinch (`ctrlKey` with a pixel delta under
|
|
93
|
+
* {@link PINCH_WHEEL_MAX_PIXELS}) or a Ctrl-wheel at the wheel rate.
|
|
94
|
+
*
|
|
95
|
+
* @throws {RangeError} As {@link wheelPixels}, and for a non-finite position or
|
|
96
|
+
* time, an `action` other than `zoom` or `pan`, and unusable options.
|
|
97
|
+
*/
|
|
98
|
+
export function wheelTransform(input, options) {
|
|
99
|
+
assertFinite(input.x, "x");
|
|
100
|
+
assertFinite(input.y, "y");
|
|
101
|
+
assertFinite(input.time, "time");
|
|
102
|
+
const zoomPixels = options?.zoomPixels ?? WHEEL_ZOOM_PIXELS;
|
|
103
|
+
assertPositive(zoomPixels, "zoomPixels");
|
|
104
|
+
const pinchZoomPixels = options?.pinchZoomPixels ?? PINCH_WHEEL_ZOOM_PIXELS;
|
|
105
|
+
assertPositive(pinchZoomPixels, "pinchZoomPixels");
|
|
106
|
+
const pinchMaxPixels = options?.pinchMaxPixels ?? PINCH_WHEEL_MAX_PIXELS;
|
|
107
|
+
assertNonNegative(pinchMaxPixels, "pinchMaxPixels");
|
|
108
|
+
const maxZoomFactor = options?.maxZoomFactor ?? WHEEL_ZOOM_MAX_FACTOR;
|
|
109
|
+
if (!(Number.isFinite(maxZoomFactor) && maxZoomFactor >= 1)) {
|
|
110
|
+
throw new RangeError(`maxZoomFactor must be finite and at least 1, got ${describeValue(maxZoomFactor)}`);
|
|
111
|
+
}
|
|
112
|
+
const action = options?.action === undefined ? "zoom" : options.action;
|
|
113
|
+
if (action !== "zoom" && action !== "pan") {
|
|
114
|
+
throw new RangeError(`action must be "zoom" or "pan", got ${describeValue(action)}`);
|
|
115
|
+
}
|
|
116
|
+
assertFinite(input.deltaX, "deltaX");
|
|
117
|
+
assertFinite(input.deltaY, "deltaY");
|
|
118
|
+
assertInteger(input.deltaMode, "deltaMode");
|
|
119
|
+
// Scalars, not a `WheelPixels` record: this runs on every wheel event.
|
|
120
|
+
const pixelsX = input.deltaX *
|
|
121
|
+
pixelsPerUnit_(input.deltaMode, options?.linePixels, "pageWidth", options?.pageWidth);
|
|
122
|
+
const pixelsY = input.deltaY *
|
|
123
|
+
pixelsPerUnit_(input.deltaMode, options?.linePixels, "pageHeight", options?.pageHeight);
|
|
124
|
+
const modified = input.ctrlKey === true || input.metaKey === true;
|
|
125
|
+
if (options?.cooperative === true && !modified) {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
if (pixelsX === 0 && pixelsY === 0) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
if (modified || action === "zoom") {
|
|
132
|
+
if (pixelsY === 0) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
const isPinch = input.ctrlKey === true &&
|
|
136
|
+
input.deltaMode === WHEEL_DELTA_PIXEL &&
|
|
137
|
+
Math.abs(pixelsY) < pinchMaxPixels;
|
|
138
|
+
const rate = isPinch ? pinchZoomPixels : zoomPixels;
|
|
139
|
+
return {
|
|
140
|
+
source: isPinch ? "pinch-wheel" : modified ? "modified-wheel" : "wheel",
|
|
141
|
+
originX: input.x,
|
|
142
|
+
originY: input.y,
|
|
143
|
+
deltaX: 0,
|
|
144
|
+
deltaY: 0,
|
|
145
|
+
scaleFactor: clamp(Math.exp(-pixelsY / rate), 1 / maxZoomFactor, maxZoomFactor),
|
|
146
|
+
rotationDelta: 0,
|
|
147
|
+
time: input.time,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const horizontal = input.shiftKey === true && pixelsX === 0;
|
|
151
|
+
return {
|
|
152
|
+
source: "wheel",
|
|
153
|
+
originX: input.x,
|
|
154
|
+
originY: input.y,
|
|
155
|
+
deltaX: negate_(horizontal ? pixelsY : pixelsX),
|
|
156
|
+
deltaY: horizontal ? 0 : negate_(pixelsY),
|
|
157
|
+
scaleFactor: 1,
|
|
158
|
+
rotationDelta: 0,
|
|
159
|
+
time: input.time,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=wheel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wheel.js","sourceRoot":"","sources":["../../src/wheel/wheel.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,KAAK,EACL,aAAa,GACb,MAAM,cAAc,CAAC;AAKtB,+EAA+E;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAClC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AACrC;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AACrC;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AACzC;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AA6BvC;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAC1B,KAAiB,EACjB,OAA4B;IAE5B,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACrC,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC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AAW,EAAE,KAAK,CACjB,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,EACzB,CAAC,GAAG,aAAa,EACjB,aAAa,CACb;YACD,aAAa,EAAE,CAAC;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;SAChB,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,OAAO,KAAK,CAAC,CAAC;IAE5D,OAAO;QACN,MAAM,EAAE,OAAO;QACf,OAAO,EAAE,KAAK,CAAC,CAAC;QAChB,OAAO,EAAE,KAAK,CAAC,CAAC;QAChB,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;QAC/C,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;QACzC,WAAW,EAAE,CAAC;QACd,aAAa,EAAE,CAAC;QAChB,IAAI,EAAE,KAAK,CAAC,IAAI;KAChB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,82 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-kit/ui-gesture",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Headless pointer gesture recognisers for the browser: taps, double taps, long presses, drags, swipes, pinches and twists, with velocity, inertia, wheel and key steps.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"double-tap",
|
|
7
|
+
"drag",
|
|
8
|
+
"gesture",
|
|
9
|
+
"headless",
|
|
10
|
+
"inertia",
|
|
11
|
+
"long-press",
|
|
12
|
+
"pinch",
|
|
13
|
+
"pointer-events",
|
|
14
|
+
"swipe",
|
|
15
|
+
"ui"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://anthochamp.pages.grenadine.io/node-essentials/api/ui-gesture/",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://git.grenadine.io/anthochamp/node-essentials/issues"
|
|
20
|
+
},
|
|
21
|
+
"license": "BSD-3-Clause",
|
|
22
|
+
"author": "Anthony Champagne <dev@anthonychampagne.fr>",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://git.grenadine.io/anthochamp/node-essentials.git",
|
|
26
|
+
"directory": "packages/ui-gesture"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": "./dist/index.js",
|
|
36
|
+
"./dom": "./dist/dom/index.js"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"main": "./dist/index.js",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": "./dist/index.js",
|
|
42
|
+
"./dom": "./dist/dom/index.js"
|
|
43
|
+
},
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"compile": "tsc -p ./tsconfig.build.json -outDir dist",
|
|
48
|
+
"compile:check": "tsc -noEmit -p ./tsconfig.json",
|
|
49
|
+
"clean": "rimraf dist",
|
|
50
|
+
"build": "yarn clean && yarn compile",
|
|
51
|
+
"test": "yarn run -T vitest run",
|
|
52
|
+
"test:browser": "yarn run -T vitest run --config vitest.browser.config.ts",
|
|
53
|
+
"prepack": "yarn build"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@ac-kit/core": "^0.12.0",
|
|
57
|
+
"@ac-kit/data": "^0.4.0",
|
|
58
|
+
"@ac-kit/math-linear": "^0.3.0",
|
|
59
|
+
"@ac-kit/math-scalar": "^0.3.0",
|
|
60
|
+
"@ac-kit/math-stats": "^0.5.0",
|
|
61
|
+
"@types/web": "^0.0.367"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@ac-kit/algo": "0.5.0",
|
|
65
|
+
"@ac-kit/math-random": "0.4.0",
|
|
66
|
+
"@ac-kit/tsconfig": "0.1.0",
|
|
67
|
+
"@ac-kit/typedoc-config": "0.1.0",
|
|
68
|
+
"@ac-kit/vitest-config": "0.2.0",
|
|
69
|
+
"@typescript/native": "typescript@7.0.2",
|
|
70
|
+
"@vitest/browser-playwright": "5.1.1",
|
|
71
|
+
"happy-dom": "21.0.4",
|
|
72
|
+
"playwright": "1.65.1",
|
|
73
|
+
"rimraf": "6.1.4",
|
|
74
|
+
"typedoc": "0.28.20",
|
|
75
|
+
"typescript": "@typescript/typescript6@6.0.2",
|
|
76
|
+
"vite": "8.4.0",
|
|
77
|
+
"vitest": "5.1.2"
|
|
78
|
+
},
|
|
79
|
+
"engines": {
|
|
80
|
+
"node": ">=24"
|
|
81
|
+
}
|
|
6
82
|
}
|