@studiometa/js-toolkit 2.4.7 → 2.6.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/Base/index.cjs +15 -21
- package/Base/index.d.ts +5 -5
- package/Base/index.js +5 -5
- package/Base/managers/AbstractManager.cjs +2 -2
- package/Base/managers/AbstractManager.d.ts +11 -21
- package/Base/managers/AbstractManager.js +1 -1
- package/Base/managers/ChildrenManager.cjs +3 -9
- package/Base/managers/ChildrenManager.d.ts +2 -2
- package/Base/managers/ChildrenManager.js +2 -2
- package/Base/managers/EventsManager.cjs +49 -9
- package/Base/managers/EventsManager.d.ts +26 -2
- package/Base/managers/EventsManager.js +48 -8
- package/Base/managers/OptionsManager.cjs +6 -8
- package/Base/managers/OptionsManager.d.ts +42 -55
- package/Base/managers/OptionsManager.js +4 -6
- package/Base/managers/RefsManager.cjs +9 -14
- package/Base/managers/RefsManager.d.ts +3 -11
- package/Base/managers/RefsManager.js +7 -6
- package/Base/managers/ResponsiveOptionsManager.cjs +3 -9
- package/Base/managers/ResponsiveOptionsManager.d.ts +8 -4
- package/Base/managers/ResponsiveOptionsManager.js +2 -2
- package/Base/managers/ServicesManager.cjs +19 -36
- package/Base/managers/ServicesManager.d.ts +33 -58
- package/Base/managers/ServicesManager.js +11 -22
- package/decorators/withResponsiveOptions.cjs +2 -8
- package/decorators/withResponsiveOptions.js +1 -1
- package/helpers/getClosestParent.cjs +48 -0
- package/helpers/getClosestParent.d.ts +5 -0
- package/helpers/getClosestParent.js +20 -0
- package/helpers/index.cjs +3 -1
- package/helpers/index.d.ts +2 -1
- package/helpers/index.js +11 -9
- package/package.json +1 -1
- package/services/drag.cjs +62 -37
- package/services/drag.js +62 -37
- package/utils/css/animate.cjs +29 -2
- package/utils/css/animate.d.ts +4 -24
- package/utils/css/animate.js +29 -2
- package/utils/css/classes.cjs +5 -2
- package/utils/css/classes.d.ts +6 -6
- package/utils/css/classes.js +5 -2
- package/utils/css/index.cjs +1 -1
- package/utils/css/index.d.ts +7 -7
- package/utils/css/styles.cjs +11 -8
- package/utils/css/styles.d.ts +4 -4
- package/utils/css/styles.js +11 -8
- package/utils/css/transform.cjs +5 -2
- package/utils/css/transform.d.ts +2 -2
- package/utils/css/transform.js +5 -2
- package/utils/css/transition.cjs +7 -1
- package/utils/css/transition.d.ts +5 -8
- package/utils/css/transition.js +7 -1
- package/utils/css/utils.cjs +31 -0
- package/utils/css/utils.d.ts +1 -0
- package/utils/css/utils.js +9 -0
- package/utils/index.cjs +1 -1
- package/utils/index.d.ts +19 -19
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
6
|
for (var name in all)
|
|
@@ -16,10 +14,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
14
|
}
|
|
17
15
|
return to;
|
|
18
16
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
18
|
|
|
25
19
|
// packages/js-toolkit/decorators/withResponsiveOptions.ts
|
|
@@ -28,13 +22,13 @@ __export(withResponsiveOptions_exports, {
|
|
|
28
22
|
withResponsiveOptions: () => withResponsiveOptions
|
|
29
23
|
});
|
|
30
24
|
module.exports = __toCommonJS(withResponsiveOptions_exports);
|
|
31
|
-
var import_ResponsiveOptionsManager =
|
|
25
|
+
var import_ResponsiveOptionsManager = require("../Base/managers/ResponsiveOptionsManager.cjs");
|
|
32
26
|
function withResponsiveOptions(BaseClass) {
|
|
33
27
|
class WithResponsiveOptions extends BaseClass {
|
|
34
28
|
get __managers() {
|
|
35
29
|
return {
|
|
36
30
|
...super.__managers,
|
|
37
|
-
OptionsManager: import_ResponsiveOptionsManager.
|
|
31
|
+
OptionsManager: import_ResponsiveOptionsManager.ResponsiveOptionsManager
|
|
38
32
|
};
|
|
39
33
|
}
|
|
40
34
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ResponsiveOptionsManager from "../Base/managers/ResponsiveOptionsManager.js";
|
|
1
|
+
import { ResponsiveOptionsManager } from "../Base/managers/ResponsiveOptionsManager.js";
|
|
2
2
|
function withResponsiveOptions(BaseClass) {
|
|
3
3
|
class WithResponsiveOptions extends BaseClass {
|
|
4
4
|
get __managers() {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// packages/js-toolkit/helpers/getClosestParent.ts
|
|
26
|
+
var getClosestParent_exports = {};
|
|
27
|
+
__export(getClosestParent_exports, {
|
|
28
|
+
default: () => getClosestParent
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(getClosestParent_exports);
|
|
31
|
+
var import_getInstanceFromElement = __toESM(require("./getInstanceFromElement.cjs"), 1);
|
|
32
|
+
function walkAncestorsWhile(element, condition, limit = 1e3) {
|
|
33
|
+
let parent = element.parentElement;
|
|
34
|
+
let count = 0;
|
|
35
|
+
while (parent && condition(parent) && count < limit) {
|
|
36
|
+
parent = parent.parentElement;
|
|
37
|
+
count += 1;
|
|
38
|
+
}
|
|
39
|
+
return parent;
|
|
40
|
+
}
|
|
41
|
+
function getClosestParent(childInstance, ParentConstructor) {
|
|
42
|
+
const parentEl = walkAncestorsWhile(
|
|
43
|
+
childInstance.$el,
|
|
44
|
+
(element) => !(0, import_getInstanceFromElement.default)(element, ParentConstructor)
|
|
45
|
+
);
|
|
46
|
+
return parentEl ? (0, import_getInstanceFromElement.default)(parentEl, ParentConstructor) : null;
|
|
47
|
+
}
|
|
48
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import getInstanceFromElement from "./getInstanceFromElement.js";
|
|
2
|
+
function walkAncestorsWhile(element, condition, limit = 1e3) {
|
|
3
|
+
let parent = element.parentElement;
|
|
4
|
+
let count = 0;
|
|
5
|
+
while (parent && condition(parent) && count < limit) {
|
|
6
|
+
parent = parent.parentElement;
|
|
7
|
+
count += 1;
|
|
8
|
+
}
|
|
9
|
+
return parent;
|
|
10
|
+
}
|
|
11
|
+
function getClosestParent(childInstance, ParentConstructor) {
|
|
12
|
+
const parentEl = walkAncestorsWhile(
|
|
13
|
+
childInstance.$el,
|
|
14
|
+
(element) => !getInstanceFromElement(element, ParentConstructor)
|
|
15
|
+
);
|
|
16
|
+
return parentEl ? getInstanceFromElement(parentEl, ParentConstructor) : null;
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
getClosestParent as default
|
|
20
|
+
};
|
package/helpers/index.cjs
CHANGED
|
@@ -27,14 +27,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
27
27
|
var helpers_exports = {};
|
|
28
28
|
__export(helpers_exports, {
|
|
29
29
|
createApp: () => import_createApp.default,
|
|
30
|
+
getClosestParent: () => import_getClosestParent.default,
|
|
30
31
|
getInstanceFromElement: () => import_getInstanceFromElement.default,
|
|
31
32
|
importOnInteraction: () => import_importOnInteraction.default,
|
|
32
33
|
importWhenIdle: () => import_importWhenIdle.default,
|
|
33
34
|
importWhenVisible: () => import_importWhenVisible.default
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(helpers_exports);
|
|
36
|
-
var import_createApp = __toESM(require("./createApp.cjs"), 1);
|
|
37
37
|
__reExport(helpers_exports, require("./getDirectChildren.cjs"), module.exports);
|
|
38
|
+
var import_createApp = __toESM(require("./createApp.cjs"), 1);
|
|
39
|
+
var import_getClosestParent = __toESM(require("./getClosestParent.cjs"), 1);
|
|
38
40
|
var import_getInstanceFromElement = __toESM(require("./getInstanceFromElement.cjs"), 1);
|
|
39
41
|
var import_importOnInteraction = __toESM(require("./importOnInteraction.cjs"), 1);
|
|
40
42
|
var import_importWhenIdle = __toESM(require("./importWhenIdle.cjs"), 1);
|
package/helpers/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { default as createApp } from './createApp.js';
|
|
2
1
|
export * from './getDirectChildren.js';
|
|
2
|
+
export { default as createApp } from './createApp.js';
|
|
3
|
+
export { default as getClosestParent } from './getClosestParent.js';
|
|
3
4
|
export { default as getInstanceFromElement } from './getInstanceFromElement.js';
|
|
4
5
|
export { default as importOnInteraction } from './importOnInteraction.js';
|
|
5
6
|
export { default as importWhenIdle } from './importWhenIdle.js';
|
package/helpers/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { default as default2 } from "./createApp.js";
|
|
2
1
|
export * from "./getDirectChildren.js";
|
|
3
|
-
import { default as
|
|
4
|
-
import { default as
|
|
5
|
-
import { default as
|
|
6
|
-
import { default as
|
|
2
|
+
import { default as default2 } from "./createApp.js";
|
|
3
|
+
import { default as default3 } from "./getClosestParent.js";
|
|
4
|
+
import { default as default4 } from "./getInstanceFromElement.js";
|
|
5
|
+
import { default as default5 } from "./importOnInteraction.js";
|
|
6
|
+
import { default as default6 } from "./importWhenIdle.js";
|
|
7
|
+
import { default as default7 } from "./importWhenVisible.js";
|
|
7
8
|
export {
|
|
8
9
|
default2 as createApp,
|
|
9
|
-
default3 as
|
|
10
|
-
default4 as
|
|
11
|
-
default5 as
|
|
12
|
-
default6 as
|
|
10
|
+
default3 as getClosestParent,
|
|
11
|
+
default4 as getInstanceFromElement,
|
|
12
|
+
default5 as importOnInteraction,
|
|
13
|
+
default6 as importWhenIdle,
|
|
14
|
+
default7 as importWhenVisible
|
|
13
15
|
};
|
package/package.json
CHANGED
package/services/drag.cjs
CHANGED
|
@@ -29,9 +29,9 @@ __export(drag_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(drag_exports);
|
|
31
31
|
var import_service = require("./service.cjs");
|
|
32
|
-
var import_pointer = __toESM(require("./pointer.cjs"), 1);
|
|
33
32
|
var import_raf = __toESM(require("./raf.cjs"), 1);
|
|
34
33
|
var import_inertiaFinalValue = __toESM(require("../utils/math/inertiaFinalValue.cjs"), 1);
|
|
34
|
+
var import_utils = require("../utils/index.cjs");
|
|
35
35
|
var MODES = {
|
|
36
36
|
START: "start",
|
|
37
37
|
DRAG: "drag",
|
|
@@ -40,13 +40,26 @@ var MODES = {
|
|
|
40
40
|
STOP: "stop"
|
|
41
41
|
};
|
|
42
42
|
var count = 0;
|
|
43
|
+
var events = ["pointerdown", "pointerup"];
|
|
44
|
+
var passiveEventOptions = { passive: true };
|
|
45
|
+
function getEventPosition(event) {
|
|
46
|
+
const eventOrTouch = (0, import_utils.isDefined)(event.touches) ? event.touches[0] : event;
|
|
47
|
+
return {
|
|
48
|
+
x: eventOrTouch.clientX,
|
|
49
|
+
y: eventOrTouch.clientY
|
|
50
|
+
};
|
|
51
|
+
}
|
|
43
52
|
function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}) {
|
|
44
53
|
count += 1;
|
|
45
54
|
const id = `drag-${count}`;
|
|
55
|
+
let previousEvent;
|
|
46
56
|
function shouldPreventClick() {
|
|
47
57
|
return Math.abs(props.distance.x) > dragTreshold || Math.abs(props.distance.y) > dragTreshold;
|
|
48
58
|
}
|
|
49
59
|
function start(x, y) {
|
|
60
|
+
if (props.isGrabbing) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
50
63
|
props.x = x;
|
|
51
64
|
props.y = y;
|
|
52
65
|
props.origin.x = x;
|
|
@@ -60,8 +73,12 @@ function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}
|
|
|
60
73
|
props.mode = MODES.START;
|
|
61
74
|
props.isGrabbing = true;
|
|
62
75
|
trigger(props);
|
|
76
|
+
document.addEventListener("touchmove", handleEvent, passiveEventOptions);
|
|
77
|
+
document.addEventListener("mousemove", handleEvent, passiveEventOptions);
|
|
63
78
|
}
|
|
64
79
|
function drop() {
|
|
80
|
+
document.removeEventListener("touchmove", handleEvent);
|
|
81
|
+
document.removeEventListener("mousemove", handleEvent);
|
|
65
82
|
props.isGrabbing = false;
|
|
66
83
|
props.mode = MODES.DROP;
|
|
67
84
|
props.hasInertia = true;
|
|
@@ -76,6 +93,7 @@ function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}
|
|
|
76
93
|
}
|
|
77
94
|
function stop() {
|
|
78
95
|
(0, import_raf.default)().remove(id);
|
|
96
|
+
props.isGrabbing = false;
|
|
79
97
|
props.hasInertia = false;
|
|
80
98
|
props.mode = MODES.STOP;
|
|
81
99
|
trigger(props);
|
|
@@ -97,41 +115,51 @@ function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}
|
|
|
97
115
|
}
|
|
98
116
|
}
|
|
99
117
|
}
|
|
100
|
-
function
|
|
118
|
+
function drag(event) {
|
|
101
119
|
if (props.isGrabbing) {
|
|
102
|
-
|
|
103
|
-
props.
|
|
104
|
-
props.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
120
|
+
const position = getEventPosition(event);
|
|
121
|
+
props.x = position.x;
|
|
122
|
+
props.y = position.y;
|
|
123
|
+
if (previousEvent) {
|
|
124
|
+
const previousPosition = getEventPosition(previousEvent);
|
|
125
|
+
props.delta.x = position.x - previousPosition.x;
|
|
126
|
+
props.delta.y = position.y - previousPosition.y;
|
|
127
|
+
}
|
|
128
|
+
props.final.x = position.x;
|
|
129
|
+
props.final.y = position.y;
|
|
108
130
|
props.distance.x = props.x - props.origin.x;
|
|
109
131
|
props.distance.y = props.y - props.origin.y;
|
|
110
132
|
if (props.mode !== MODES.DRAG) {
|
|
111
133
|
props.mode = MODES.DRAG;
|
|
112
134
|
}
|
|
113
135
|
trigger(props);
|
|
114
|
-
|
|
115
|
-
drop();
|
|
116
|
-
}
|
|
136
|
+
previousEvent = event;
|
|
117
137
|
}
|
|
118
138
|
}
|
|
119
139
|
function handleEvent(event) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (event.type === "click") {
|
|
125
|
-
if (shouldPreventClick()) {
|
|
126
|
-
event.stopImmediatePropagation();
|
|
127
|
-
event.stopPropagation();
|
|
140
|
+
switch (event.type) {
|
|
141
|
+
case "dragstart":
|
|
128
142
|
event.preventDefault();
|
|
129
|
-
|
|
130
|
-
|
|
143
|
+
break;
|
|
144
|
+
case "click":
|
|
145
|
+
if (shouldPreventClick()) {
|
|
146
|
+
event.stopImmediatePropagation();
|
|
147
|
+
event.stopPropagation();
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
case "pointerup":
|
|
152
|
+
drop();
|
|
153
|
+
break;
|
|
154
|
+
case "touchmove":
|
|
155
|
+
case "mousemove":
|
|
156
|
+
drag(event);
|
|
157
|
+
break;
|
|
158
|
+
default:
|
|
159
|
+
if (event.button === 0) {
|
|
160
|
+
start(event.x, event.y);
|
|
161
|
+
}
|
|
131
162
|
}
|
|
132
|
-
const x = event instanceof MouseEvent ? event.clientX : event.touches[0].clientX;
|
|
133
|
-
const y = event instanceof MouseEvent ? event.clientY : event.touches[0].clientY;
|
|
134
|
-
start(x, y);
|
|
135
163
|
}
|
|
136
164
|
const { add, remove, has, trigger, props } = (0, import_service.useService)({
|
|
137
165
|
props: {
|
|
@@ -159,21 +187,18 @@ function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}
|
|
|
159
187
|
}
|
|
160
188
|
},
|
|
161
189
|
init() {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const pointer = (0, import_pointer.default)();
|
|
168
|
-
pointer.add(id, pointerHandler);
|
|
190
|
+
events.forEach((event) => {
|
|
191
|
+
target.addEventListener(event, handleEvent, passiveEventOptions);
|
|
192
|
+
});
|
|
193
|
+
target.addEventListener("dragstart", handleEvent, { capture: true });
|
|
194
|
+
target.addEventListener("click", handleEvent, { capture: true });
|
|
169
195
|
},
|
|
170
196
|
kill() {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
pointer.remove(id);
|
|
197
|
+
events.forEach((event) => {
|
|
198
|
+
target.removeEventListener(event, handleEvent);
|
|
199
|
+
});
|
|
200
|
+
target.removeEventListener("dragstart", handleEvent);
|
|
201
|
+
target.removeEventListener("click", handleEvent);
|
|
177
202
|
}
|
|
178
203
|
});
|
|
179
204
|
return {
|
package/services/drag.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useService } from "./service.js";
|
|
2
|
-
import usePointer from "./pointer.js";
|
|
3
2
|
import useRaf from "./raf.js";
|
|
4
3
|
import inertiaFinalValue from "../utils/math/inertiaFinalValue.js";
|
|
4
|
+
import { isDefined } from "../utils/index.js";
|
|
5
5
|
const MODES = {
|
|
6
6
|
START: "start",
|
|
7
7
|
DRAG: "drag",
|
|
@@ -10,13 +10,26 @@ const MODES = {
|
|
|
10
10
|
STOP: "stop"
|
|
11
11
|
};
|
|
12
12
|
let count = 0;
|
|
13
|
+
const events = ["pointerdown", "pointerup"];
|
|
14
|
+
const passiveEventOptions = { passive: true };
|
|
15
|
+
function getEventPosition(event) {
|
|
16
|
+
const eventOrTouch = isDefined(event.touches) ? event.touches[0] : event;
|
|
17
|
+
return {
|
|
18
|
+
x: eventOrTouch.clientX,
|
|
19
|
+
y: eventOrTouch.clientY
|
|
20
|
+
};
|
|
21
|
+
}
|
|
13
22
|
function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}) {
|
|
14
23
|
count += 1;
|
|
15
24
|
const id = `drag-${count}`;
|
|
25
|
+
let previousEvent;
|
|
16
26
|
function shouldPreventClick() {
|
|
17
27
|
return Math.abs(props.distance.x) > dragTreshold || Math.abs(props.distance.y) > dragTreshold;
|
|
18
28
|
}
|
|
19
29
|
function start(x, y) {
|
|
30
|
+
if (props.isGrabbing) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
20
33
|
props.x = x;
|
|
21
34
|
props.y = y;
|
|
22
35
|
props.origin.x = x;
|
|
@@ -30,8 +43,12 @@ function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}
|
|
|
30
43
|
props.mode = MODES.START;
|
|
31
44
|
props.isGrabbing = true;
|
|
32
45
|
trigger(props);
|
|
46
|
+
document.addEventListener("touchmove", handleEvent, passiveEventOptions);
|
|
47
|
+
document.addEventListener("mousemove", handleEvent, passiveEventOptions);
|
|
33
48
|
}
|
|
34
49
|
function drop() {
|
|
50
|
+
document.removeEventListener("touchmove", handleEvent);
|
|
51
|
+
document.removeEventListener("mousemove", handleEvent);
|
|
35
52
|
props.isGrabbing = false;
|
|
36
53
|
props.mode = MODES.DROP;
|
|
37
54
|
props.hasInertia = true;
|
|
@@ -46,6 +63,7 @@ function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}
|
|
|
46
63
|
}
|
|
47
64
|
function stop() {
|
|
48
65
|
useRaf().remove(id);
|
|
66
|
+
props.isGrabbing = false;
|
|
49
67
|
props.hasInertia = false;
|
|
50
68
|
props.mode = MODES.STOP;
|
|
51
69
|
trigger(props);
|
|
@@ -67,41 +85,51 @@ function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}
|
|
|
67
85
|
}
|
|
68
86
|
}
|
|
69
87
|
}
|
|
70
|
-
function
|
|
88
|
+
function drag(event) {
|
|
71
89
|
if (props.isGrabbing) {
|
|
72
|
-
|
|
73
|
-
props.
|
|
74
|
-
props.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
const position = getEventPosition(event);
|
|
91
|
+
props.x = position.x;
|
|
92
|
+
props.y = position.y;
|
|
93
|
+
if (previousEvent) {
|
|
94
|
+
const previousPosition = getEventPosition(previousEvent);
|
|
95
|
+
props.delta.x = position.x - previousPosition.x;
|
|
96
|
+
props.delta.y = position.y - previousPosition.y;
|
|
97
|
+
}
|
|
98
|
+
props.final.x = position.x;
|
|
99
|
+
props.final.y = position.y;
|
|
78
100
|
props.distance.x = props.x - props.origin.x;
|
|
79
101
|
props.distance.y = props.y - props.origin.y;
|
|
80
102
|
if (props.mode !== MODES.DRAG) {
|
|
81
103
|
props.mode = MODES.DRAG;
|
|
82
104
|
}
|
|
83
105
|
trigger(props);
|
|
84
|
-
|
|
85
|
-
drop();
|
|
86
|
-
}
|
|
106
|
+
previousEvent = event;
|
|
87
107
|
}
|
|
88
108
|
}
|
|
89
109
|
function handleEvent(event) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (event.type === "click") {
|
|
95
|
-
if (shouldPreventClick()) {
|
|
96
|
-
event.stopImmediatePropagation();
|
|
97
|
-
event.stopPropagation();
|
|
110
|
+
switch (event.type) {
|
|
111
|
+
case "dragstart":
|
|
98
112
|
event.preventDefault();
|
|
99
|
-
|
|
100
|
-
|
|
113
|
+
break;
|
|
114
|
+
case "click":
|
|
115
|
+
if (shouldPreventClick()) {
|
|
116
|
+
event.stopImmediatePropagation();
|
|
117
|
+
event.stopPropagation();
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
case "pointerup":
|
|
122
|
+
drop();
|
|
123
|
+
break;
|
|
124
|
+
case "touchmove":
|
|
125
|
+
case "mousemove":
|
|
126
|
+
drag(event);
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
if (event.button === 0) {
|
|
130
|
+
start(event.x, event.y);
|
|
131
|
+
}
|
|
101
132
|
}
|
|
102
|
-
const x = event instanceof MouseEvent ? event.clientX : event.touches[0].clientX;
|
|
103
|
-
const y = event instanceof MouseEvent ? event.clientY : event.touches[0].clientY;
|
|
104
|
-
start(x, y);
|
|
105
133
|
}
|
|
106
134
|
const { add, remove, has, trigger, props } = useService({
|
|
107
135
|
props: {
|
|
@@ -129,21 +157,18 @@ function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}
|
|
|
129
157
|
}
|
|
130
158
|
},
|
|
131
159
|
init() {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const pointer = usePointer();
|
|
138
|
-
pointer.add(id, pointerHandler);
|
|
160
|
+
events.forEach((event) => {
|
|
161
|
+
target.addEventListener(event, handleEvent, passiveEventOptions);
|
|
162
|
+
});
|
|
163
|
+
target.addEventListener("dragstart", handleEvent, { capture: true });
|
|
164
|
+
target.addEventListener("click", handleEvent, { capture: true });
|
|
139
165
|
},
|
|
140
166
|
kill() {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
pointer.remove(id);
|
|
167
|
+
events.forEach((event) => {
|
|
168
|
+
target.removeEventListener(event, handleEvent);
|
|
169
|
+
});
|
|
170
|
+
target.removeEventListener("dragstart", handleEvent);
|
|
171
|
+
target.removeEventListener("click", handleEvent);
|
|
147
172
|
}
|
|
148
173
|
});
|
|
149
174
|
return {
|
package/utils/css/animate.cjs
CHANGED
|
@@ -33,6 +33,7 @@ var import_is = require("../is.cjs");
|
|
|
33
33
|
var import_transform = __toESM(require("./transform.cjs"), 1);
|
|
34
34
|
var import_scheduler = require("../scheduler.cjs");
|
|
35
35
|
var import_tween = require("../tween.cjs");
|
|
36
|
+
var import_utils = require("./utils.cjs");
|
|
36
37
|
var id = 0;
|
|
37
38
|
var running = /* @__PURE__ */ new WeakMap();
|
|
38
39
|
var CSSUnitConverter = {
|
|
@@ -52,7 +53,10 @@ function getAnimationStepValue(val, getSizeRef) {
|
|
|
52
53
|
return CSSUnitConverter[val[1]](val[0], getSizeRef);
|
|
53
54
|
}
|
|
54
55
|
var generateTranslateRenderStrategy = (sizeRef) => (element, fromValue, toValue, progress) => (0, import_math.lerp)(
|
|
55
|
-
getAnimationStepValue(
|
|
56
|
+
getAnimationStepValue(
|
|
57
|
+
fromValue != null ? fromValue : 0,
|
|
58
|
+
() => element[sizeRef]
|
|
59
|
+
),
|
|
56
60
|
getAnimationStepValue(toValue != null ? toValue : 0, () => element[sizeRef]),
|
|
57
61
|
progress
|
|
58
62
|
);
|
|
@@ -109,7 +113,7 @@ function render(element, from, to, progress) {
|
|
|
109
113
|
});
|
|
110
114
|
});
|
|
111
115
|
}
|
|
112
|
-
function
|
|
116
|
+
function singleAnimate(element, keyframes, options = {}) {
|
|
113
117
|
const keyframesCount = keyframes.length - 1;
|
|
114
118
|
const normalizedKeyframes = keyframes.map(
|
|
115
119
|
(keyframe, index) => {
|
|
@@ -150,4 +154,27 @@ function animate(element, keyframes, options = {}) {
|
|
|
150
154
|
});
|
|
151
155
|
return controls;
|
|
152
156
|
}
|
|
157
|
+
function animate(elementOrElements, keyframes, options = {}) {
|
|
158
|
+
const controls = (0, import_utils.eachElements)(
|
|
159
|
+
elementOrElements,
|
|
160
|
+
(element) => singleAnimate(element, keyframes, options)
|
|
161
|
+
);
|
|
162
|
+
const delegate = (key) => {
|
|
163
|
+
return (...args) => {
|
|
164
|
+
if (key === "progress" && args.length === 0) {
|
|
165
|
+
return controls[0][key]();
|
|
166
|
+
}
|
|
167
|
+
controls.forEach((control) => {
|
|
168
|
+
control[key](...args);
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
start: delegate("start"),
|
|
174
|
+
pause: delegate("pause"),
|
|
175
|
+
finish: delegate("finish"),
|
|
176
|
+
play: delegate("play"),
|
|
177
|
+
progress: delegate("progress")
|
|
178
|
+
};
|
|
179
|
+
}
|
|
153
180
|
if (module.exports.default) module.exports = module.exports.default;
|
package/utils/css/animate.d.ts
CHANGED
|
@@ -1,31 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @
|
|
4
|
-
* opacity?: number;
|
|
5
|
-
* transformOrigin?: string;
|
|
6
|
-
* easing?: import('../math/createEases.js').EasingFunction|import('../tween.js').BezierCurve;
|
|
7
|
-
* offset?: number;
|
|
8
|
-
* }} Keyframe
|
|
9
|
-
* @typedef {Keyframe & {
|
|
10
|
-
* easing: import('../math/createEases.js').EasingFunction;
|
|
11
|
-
* offset: number;
|
|
12
|
-
* }} NormalizedKeyframe
|
|
13
|
-
* @typedef {{
|
|
14
|
-
* start: () => void;
|
|
15
|
-
* pause: () => void;
|
|
16
|
-
* play: () => void;
|
|
17
|
-
* finish: () => void;
|
|
18
|
-
* progress: (value: number?) => number
|
|
19
|
-
* }} Animate
|
|
20
|
-
*/
|
|
21
|
-
/**
|
|
22
|
-
* Animate an element.
|
|
23
|
-
* @param {HTMLElement} element
|
|
2
|
+
* Animate one or more elements.
|
|
3
|
+
* @param {HTMLElement|HTMLElement[]|NodeListOf<HTMLElement>} elementOrElements
|
|
24
4
|
* @param {Keyframe[]} keyframes
|
|
25
5
|
* @param {import('../tween.js').TweenOptions} [options]
|
|
26
6
|
* @returns {Animate}
|
|
27
7
|
*/
|
|
28
|
-
export function animate(
|
|
8
|
+
export function animate(elementOrElements: HTMLElement | HTMLElement[] | NodeListOf<HTMLElement>, keyframes: Keyframe[], options?: import('../tween.js').TweenOptions): Animate;
|
|
29
9
|
export type TransformProps = import('./transform.js').TransformProps;
|
|
30
10
|
export type Keyframe = TransformProps & {
|
|
31
11
|
opacity?: number;
|
|
@@ -42,5 +22,5 @@ export type Animate = {
|
|
|
42
22
|
pause: () => void;
|
|
43
23
|
play: () => void;
|
|
44
24
|
finish: () => void;
|
|
45
|
-
progress: (value
|
|
25
|
+
progress: (value?: number) => number;
|
|
46
26
|
};
|
package/utils/css/animate.js
CHANGED
|
@@ -3,6 +3,7 @@ import { isDefined, isFunction, isNumber } from "../is.js";
|
|
|
3
3
|
import transform, { TRANSFORM_PROPS } from "./transform.js";
|
|
4
4
|
import { domScheduler as scheduler } from "../scheduler.js";
|
|
5
5
|
import { tween, normalizeEase } from "../tween.js";
|
|
6
|
+
import { eachElements } from "./utils.js";
|
|
6
7
|
let id = 0;
|
|
7
8
|
const running = /* @__PURE__ */ new WeakMap();
|
|
8
9
|
const CSSUnitConverter = {
|
|
@@ -22,7 +23,10 @@ function getAnimationStepValue(val, getSizeRef) {
|
|
|
22
23
|
return CSSUnitConverter[val[1]](val[0], getSizeRef);
|
|
23
24
|
}
|
|
24
25
|
const generateTranslateRenderStrategy = (sizeRef) => (element, fromValue, toValue, progress) => lerp(
|
|
25
|
-
getAnimationStepValue(
|
|
26
|
+
getAnimationStepValue(
|
|
27
|
+
fromValue != null ? fromValue : 0,
|
|
28
|
+
() => element[sizeRef]
|
|
29
|
+
),
|
|
26
30
|
getAnimationStepValue(toValue != null ? toValue : 0, () => element[sizeRef]),
|
|
27
31
|
progress
|
|
28
32
|
);
|
|
@@ -79,7 +83,7 @@ function render(element, from, to, progress) {
|
|
|
79
83
|
});
|
|
80
84
|
});
|
|
81
85
|
}
|
|
82
|
-
function
|
|
86
|
+
function singleAnimate(element, keyframes, options = {}) {
|
|
83
87
|
const keyframesCount = keyframes.length - 1;
|
|
84
88
|
const normalizedKeyframes = keyframes.map(
|
|
85
89
|
(keyframe, index) => {
|
|
@@ -120,6 +124,29 @@ function animate(element, keyframes, options = {}) {
|
|
|
120
124
|
});
|
|
121
125
|
return controls;
|
|
122
126
|
}
|
|
127
|
+
function animate(elementOrElements, keyframes, options = {}) {
|
|
128
|
+
const controls = eachElements(
|
|
129
|
+
elementOrElements,
|
|
130
|
+
(element) => singleAnimate(element, keyframes, options)
|
|
131
|
+
);
|
|
132
|
+
const delegate = (key) => {
|
|
133
|
+
return (...args) => {
|
|
134
|
+
if (key === "progress" && args.length === 0) {
|
|
135
|
+
return controls[0][key]();
|
|
136
|
+
}
|
|
137
|
+
controls.forEach((control) => {
|
|
138
|
+
control[key](...args);
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
start: delegate("start"),
|
|
144
|
+
pause: delegate("pause"),
|
|
145
|
+
finish: delegate("finish"),
|
|
146
|
+
play: delegate("play"),
|
|
147
|
+
progress: delegate("progress")
|
|
148
|
+
};
|
|
149
|
+
}
|
|
123
150
|
export {
|
|
124
151
|
animate
|
|
125
152
|
};
|