@studiometa/js-toolkit 2.8.0 → 2.9.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/Base/Base.cjs +325 -0
- package/Base/Base.cjs.map +7 -0
- package/Base/Base.d.ts +197 -0
- package/Base/Base.js +304 -0
- package/Base/Base.js.map +7 -0
- package/Base/index.cjs +2 -292
- package/Base/index.cjs.map +3 -3
- package/Base/index.d.ts +1 -193
- package/Base/index.js +1 -290
- package/Base/index.js.map +2 -2
- package/Base/managers/AbstractManager.d.ts +2 -2
- package/Base/managers/ChildrenManager.cjs +11 -7
- package/Base/managers/ChildrenManager.cjs.map +2 -2
- package/Base/managers/ChildrenManager.d.ts +1 -1
- package/Base/managers/ChildrenManager.js +12 -8
- package/Base/managers/ChildrenManager.js.map +2 -2
- package/Base/managers/index.cjs +0 -2
- package/Base/managers/index.cjs.map +2 -2
- package/Base/managers/index.d.ts +0 -1
- package/Base/managers/index.js +0 -2
- package/Base/managers/index.js.map +2 -2
- package/Base/utils.cjs +13 -0
- package/Base/utils.cjs.map +2 -2
- package/Base/utils.d.ts +4 -0
- package/Base/utils.js +14 -1
- package/Base/utils.js.map +2 -2
- package/decorators/withScrolledInView/withScrolledInView.cjs +45 -55
- package/decorators/withScrolledInView/withScrolledInView.cjs.map +2 -2
- package/decorators/withScrolledInView/withScrolledInView.d.ts +1 -6
- package/decorators/withScrolledInView/withScrolledInView.js +45 -55
- package/decorators/withScrolledInView/withScrolledInView.js.map +2 -2
- package/helpers/createApp.cjs +21 -20
- package/helpers/createApp.cjs.map +2 -2
- package/helpers/createApp.js +21 -20
- package/helpers/createApp.js.map +2 -2
- package/helpers/getInstanceFromElement.cjs +1 -1
- package/helpers/getInstanceFromElement.cjs.map +2 -2
- package/helpers/getInstanceFromElement.js +1 -1
- package/helpers/getInstanceFromElement.js.map +2 -2
- package/package.json +1 -1
- package/services/drag.cjs +10 -3
- package/services/drag.cjs.map +2 -2
- package/services/drag.js +10 -3
- package/services/drag.js.map +2 -2
- package/utils/Queue.cjs +4 -1
- package/utils/Queue.cjs.map +2 -2
- package/utils/Queue.d.ts +1 -1
- package/utils/Queue.js +4 -1
- package/utils/Queue.js.map +2 -2
- package/utils/SmartQueue.cjs +57 -0
- package/utils/SmartQueue.cjs.map +7 -0
- package/utils/SmartQueue.d.ts +25 -0
- package/utils/SmartQueue.js +29 -0
- package/utils/SmartQueue.js.map +7 -0
- package/utils/index.cjs +3 -0
- package/utils/index.cjs.map +2 -2
- package/utils/index.d.ts +2 -0
- package/utils/index.js +3 -0
- package/utils/index.js.map +2 -2
- package/utils/nextTick.cjs +2 -5
- package/utils/nextTick.cjs.map +2 -2
- package/utils/nextTick.js +2 -5
- package/utils/nextTick.js.map +2 -2
- package/utils/wait.cjs +31 -0
- package/utils/wait.cjs.map +7 -0
- package/utils/wait.d.ts +1 -0
- package/utils/wait.js +9 -0
- package/utils/wait.js.map +7 -0
- package/Base/managers/AsyncChildrenManager.cjs +0 -61
- package/Base/managers/AsyncChildrenManager.cjs.map +0 -7
- package/Base/managers/AsyncChildrenManager.d.ts +0 -18
- package/Base/managers/AsyncChildrenManager.js +0 -39
- package/Base/managers/AsyncChildrenManager.js.map +0 -7
|
@@ -9,6 +9,11 @@ import {
|
|
|
9
9
|
} from "../../utils/index.js";
|
|
10
10
|
import { normalizeOffset, getEdges } from "./utils.js";
|
|
11
11
|
const scheduler = useScheduler(["update", "render"]);
|
|
12
|
+
function updateProgress(props, axis, progressKey, currentKey) {
|
|
13
|
+
props[progressKey][axis] = props.start[axis] === props.end[axis] ? 0 : clamp01(
|
|
14
|
+
(props[currentKey][axis] - props.start[axis]) / (props.end[axis] - props.start[axis])
|
|
15
|
+
);
|
|
16
|
+
}
|
|
12
17
|
function updateProps(props, dampFactor, dampPrecision, axis = "x") {
|
|
13
18
|
props.current[axis] = clamp(
|
|
14
19
|
axis === "x" ? window.pageXOffset : window.pageYOffset,
|
|
@@ -21,12 +26,8 @@ function updateProps(props, dampFactor, dampPrecision, axis = "x") {
|
|
|
21
26
|
dampFactor,
|
|
22
27
|
dampPrecision
|
|
23
28
|
);
|
|
24
|
-
props
|
|
25
|
-
|
|
26
|
-
);
|
|
27
|
-
props.dampedProgress[axis] = clamp01(
|
|
28
|
-
(props.dampedCurrent[axis] - props.start[axis]) / (props.end[axis] - props.start[axis])
|
|
29
|
-
);
|
|
29
|
+
updateProgress(props, axis, "progress", "current");
|
|
30
|
+
updateProgress(props, axis, "dampedProgress", "dampedCurrent");
|
|
30
31
|
}
|
|
31
32
|
function withScrolledInView(BaseClass, options = {}) {
|
|
32
33
|
class WithScrolledInView extends withMountWhenInView(
|
|
@@ -77,13 +78,48 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
77
78
|
y: 0
|
|
78
79
|
}
|
|
79
80
|
};
|
|
81
|
+
shouldEvaluateProps = true;
|
|
82
|
+
get props() {
|
|
83
|
+
if (this.shouldEvaluateProps) {
|
|
84
|
+
this.shouldEvaluateProps = false;
|
|
85
|
+
const targetSizes = options.useOffsetSizes ? getOffsetSizes(this.$el) : this.$el.getBoundingClientRect();
|
|
86
|
+
targetSizes.y += window.pageYOffset;
|
|
87
|
+
targetSizes.x += window.pageXOffset;
|
|
88
|
+
const containerSizes = {
|
|
89
|
+
x: 0,
|
|
90
|
+
y: 0,
|
|
91
|
+
height: window.innerHeight,
|
|
92
|
+
width: window.innerWidth
|
|
93
|
+
};
|
|
94
|
+
const offset = normalizeOffset(this.$options.offset);
|
|
95
|
+
const [yStart, yEnd] = getEdges("y", targetSizes, containerSizes, offset);
|
|
96
|
+
const yCurrent = clamp(window.pageYOffset, yStart, yEnd);
|
|
97
|
+
const yProgress = yStart === yEnd ? 0 : clamp01((yCurrent - yStart) / (yEnd - yStart));
|
|
98
|
+
const [xStart, xEnd] = getEdges("x", targetSizes, containerSizes, offset);
|
|
99
|
+
const xCurrent = clamp(window.pageXOffset, xStart, xEnd);
|
|
100
|
+
const xProgress = xStart === xEnd ? 0 : clamp01((xCurrent - xStart) / (xEnd - xStart));
|
|
101
|
+
this.__props.start.x = xStart;
|
|
102
|
+
this.__props.start.y = yStart;
|
|
103
|
+
this.__props.end.x = xEnd;
|
|
104
|
+
this.__props.end.y = yEnd;
|
|
105
|
+
this.__props.current.x = xCurrent;
|
|
106
|
+
this.__props.current.y = yCurrent;
|
|
107
|
+
this.__props.dampedCurrent.x = xCurrent;
|
|
108
|
+
this.__props.dampedCurrent.y = yCurrent;
|
|
109
|
+
this.__props.progress.x = xProgress;
|
|
110
|
+
this.__props.progress.y = yProgress;
|
|
111
|
+
this.__props.dampedProgress.x = xProgress;
|
|
112
|
+
this.__props.dampedProgress.y = yProgress;
|
|
113
|
+
}
|
|
114
|
+
return this.__props;
|
|
115
|
+
}
|
|
80
116
|
dampFactor = null;
|
|
81
117
|
dampPrecision = null;
|
|
82
118
|
constructor(element) {
|
|
83
119
|
super(element);
|
|
84
120
|
const render = () => {
|
|
85
121
|
scheduler.update(() => {
|
|
86
|
-
const renderFn = this.__callMethod("scrolledInView", this.
|
|
122
|
+
const renderFn = this.__callMethod("scrolledInView", this.props);
|
|
87
123
|
if (isFunction(renderFn)) {
|
|
88
124
|
scheduler.render(() => {
|
|
89
125
|
renderFn(this.__props);
|
|
@@ -96,7 +132,8 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
96
132
|
delegate[event.type](event.detail[0]);
|
|
97
133
|
},
|
|
98
134
|
resized: () => {
|
|
99
|
-
this.
|
|
135
|
+
this.shouldEvaluateProps = true;
|
|
136
|
+
render();
|
|
100
137
|
},
|
|
101
138
|
scrolled: (props) => {
|
|
102
139
|
if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
|
|
@@ -119,9 +156,6 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
119
156
|
this.$on("scrolled", delegate);
|
|
120
157
|
this.$on("ticked", delegate);
|
|
121
158
|
});
|
|
122
|
-
this.$on("mounted", () => {
|
|
123
|
-
this.__setProps();
|
|
124
|
-
});
|
|
125
159
|
this.$on("destroyed", () => {
|
|
126
160
|
this.$off("resized", delegate);
|
|
127
161
|
this.$off("scrolled", delegate);
|
|
@@ -158,50 +192,6 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
158
192
|
super.destroyed();
|
|
159
193
|
}
|
|
160
194
|
}
|
|
161
|
-
__setProps() {
|
|
162
|
-
const targetSizes = options.useOffsetSizes ? getOffsetSizes(this.$el) : this.$el.getBoundingClientRect();
|
|
163
|
-
targetSizes.y += window.pageYOffset;
|
|
164
|
-
targetSizes.x += window.pageXOffset;
|
|
165
|
-
const containerSizes = {
|
|
166
|
-
x: 0,
|
|
167
|
-
y: 0,
|
|
168
|
-
height: window.innerHeight,
|
|
169
|
-
width: window.innerWidth
|
|
170
|
-
};
|
|
171
|
-
const offset = normalizeOffset(this.$options.offset);
|
|
172
|
-
const [yStart, yEnd] = getEdges("y", targetSizes, containerSizes, offset);
|
|
173
|
-
const yCurrent = clamp(window.pageYOffset, yStart, yEnd);
|
|
174
|
-
const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));
|
|
175
|
-
const [xStart, xEnd] = getEdges("x", targetSizes, containerSizes, offset);
|
|
176
|
-
const xCurrent = clamp(window.pageXOffset, xStart, xEnd);
|
|
177
|
-
const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));
|
|
178
|
-
this.__props.start.x = xStart;
|
|
179
|
-
this.__props.start.y = yStart;
|
|
180
|
-
this.__props.end.x = xEnd;
|
|
181
|
-
this.__props.end.y = yEnd;
|
|
182
|
-
this.__props.current.x = xCurrent;
|
|
183
|
-
this.__props.current.y = yCurrent;
|
|
184
|
-
this.__props.dampedCurrent.x = damp(
|
|
185
|
-
xCurrent,
|
|
186
|
-
this.__props.dampedCurrent.x,
|
|
187
|
-
this.dampFactor,
|
|
188
|
-
this.dampPrecision
|
|
189
|
-
);
|
|
190
|
-
this.__props.dampedCurrent.y = damp(
|
|
191
|
-
yCurrent,
|
|
192
|
-
this.__props.dampedCurrent.y,
|
|
193
|
-
this.dampFactor,
|
|
194
|
-
this.dampPrecision
|
|
195
|
-
);
|
|
196
|
-
this.__props.progress.x = xProgress;
|
|
197
|
-
this.__props.progress.y = yProgress;
|
|
198
|
-
this.__props.dampedProgress.x = clamp01(
|
|
199
|
-
(this.__props.dampedCurrent.x - xStart) / (xEnd - xStart)
|
|
200
|
-
);
|
|
201
|
-
this.__props.dampedProgress.y = clamp01(
|
|
202
|
-
(this.__props.dampedCurrent.y - yStart) / (yEnd - yStart)
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
195
|
}
|
|
206
196
|
return WithScrolledInView;
|
|
207
197
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/decorators/withScrolledInView/withScrolledInView.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../../Base/index.js';\nimport type {\n RafServiceProps,\n ScrollServiceProps,\n ResizeServiceProps,\n} from '../../services/index.js';\nimport { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\n\nexport interface WithScrolledInViewProps extends BaseProps {\n $options: {\n dampFactor: number;\n dampPrecision: number;\n offset: string;\n };\n}\n\nexport type ScrollInViewProps = {\n start: {\n x: number;\n y: number;\n };\n end: {\n x: number;\n y: number;\n };\n current: {\n x: number;\n y: number;\n };\n dampedCurrent: {\n x: number;\n y: number;\n };\n progress: {\n x: number;\n y: number;\n };\n dampedProgress: {\n x: number;\n y: number;\n };\n};\n\nexport type WithScrolledInViewOptions = IntersectionObserverInit & {\n useOffsetSizes?: boolean;\n};\n\n/**\n * Update props on tick.\n */\nfunction updateProps(\n props: ScrollInViewProps,\n dampFactor: number,\n dampPrecision: number,\n axis: 'x' | 'y' = 'x',\n): void {\n props.current[axis] = clamp(\n axis === 'x' ? window.pageXOffset : window.pageYOffset,\n props.start[axis],\n props.end[axis],\n );\n props.dampedCurrent[axis] = damp(\n props.current[axis],\n props.dampedCurrent[axis],\n dampFactor,\n dampPrecision,\n );\n
|
|
5
|
-
"mappings": "AAOA,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB,gBAAgB;AAE1C,MAAM,YAAY,aAAa,CAAC,UAAU,QAAQ,CAAC;
|
|
4
|
+
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../../Base/index.js';\nimport type {\n RafServiceProps,\n ScrollServiceProps,\n ResizeServiceProps,\n} from '../../services/index.js';\nimport { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\n\nexport interface WithScrolledInViewProps extends BaseProps {\n $options: {\n dampFactor: number;\n dampPrecision: number;\n offset: string;\n };\n}\n\nexport type ScrollInViewProps = {\n start: {\n x: number;\n y: number;\n };\n end: {\n x: number;\n y: number;\n };\n current: {\n x: number;\n y: number;\n };\n dampedCurrent: {\n x: number;\n y: number;\n };\n progress: {\n x: number;\n y: number;\n };\n dampedProgress: {\n x: number;\n y: number;\n };\n};\n\nexport type WithScrolledInViewOptions = IntersectionObserverInit & {\n useOffsetSizes?: boolean;\n};\n\nfunction updateProgress(\n props: ScrollInViewProps,\n axis: 'x' | 'y',\n progressKey: 'progress' | 'dampedProgress',\n currentKey: 'current' | 'dampedCurrent',\n) {\n props[progressKey][axis] =\n props.start[axis] === props.end[axis]\n ? 0\n : clamp01(\n (props[currentKey][axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n}\n\n/**\n * Update props on tick.\n */\nfunction updateProps(\n props: ScrollInViewProps,\n dampFactor: number,\n dampPrecision: number,\n axis: 'x' | 'y' = 'x',\n): void {\n props.current[axis] = clamp(\n axis === 'x' ? window.pageXOffset : window.pageYOffset,\n props.start[axis],\n props.end[axis],\n );\n props.dampedCurrent[axis] = damp(\n props.current[axis],\n props.dampedCurrent[axis],\n dampFactor,\n dampPrecision,\n );\n updateProgress(props, axis, 'progress', 'current');\n updateProgress(props, axis, 'dampedProgress', 'dampedCurrent');\n}\n\nexport interface WithScrolledInViewInterface extends BaseInterface {\n /**\n * @type {ScrollInViewProps}\n */\n readonly props: ScrollInViewProps;\n dampFactor?: number;\n dampPrecision?: number;\n mounted(): void;\n resized(props: ResizeServiceProps): void;\n scrolled(props: ScrollServiceProps): void;\n ticked(props: RafServiceProps): void;\n destroyed(): void;\n}\n\n/**\n * Add scrolled in view capabilities to a component.\n */\nexport function withScrolledInView<S extends Base = Base>(\n BaseClass: typeof Base,\n options: WithScrolledInViewOptions = {},\n): BaseDecorator<WithScrolledInViewInterface, S, WithScrolledInViewProps> {\n /**\n * Class.\n */\n class WithScrolledInView<T extends BaseProps = BaseProps> extends withMountWhenInView(\n BaseClass,\n options,\n )<T & WithScrolledInViewProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: `${BaseClass.config.name}WithMountWhenInView`,\n emits: ['scrolledInView'],\n options: {\n dampFactor: {\n type: Number,\n default: 0.1,\n },\n dampPrecision: {\n type: Number,\n default: 0.001,\n },\n offset: {\n type: String,\n default: 'start end / end start',\n },\n },\n };\n\n __props: ScrollInViewProps = {\n start: {\n x: 0,\n y: 0,\n },\n end: {\n x: 0,\n y: 0,\n },\n current: {\n x: 0,\n y: 0,\n },\n dampedCurrent: {\n x: 0,\n y: 0,\n },\n progress: {\n x: 0,\n y: 0,\n },\n dampedProgress: {\n x: 0,\n y: 0,\n },\n };\n\n shouldEvaluateProps = true;\n\n get props() {\n if (this.shouldEvaluateProps) {\n this.shouldEvaluateProps = false;\n const targetSizes = options.useOffsetSizes\n ? getOffsetSizes(this.$el)\n : this.$el.getBoundingClientRect();\n\n targetSizes.y += window.pageYOffset;\n targetSizes.x += window.pageXOffset;\n\n const containerSizes = {\n x: 0,\n y: 0,\n height: window.innerHeight,\n width: window.innerWidth,\n };\n\n const offset = normalizeOffset(this.$options.offset);\n\n // Y axis\n const [yStart, yEnd] = getEdges('y', targetSizes, containerSizes, offset);\n const yCurrent = clamp(window.pageYOffset, yStart, yEnd);\n const yProgress = yStart === yEnd ? 0 : clamp01((yCurrent - yStart) / (yEnd - yStart));\n // X axis\n const [xStart, xEnd] = getEdges('x', targetSizes, containerSizes, offset);\n const xCurrent = clamp(window.pageXOffset, xStart, xEnd);\n const xProgress = xStart === xEnd ? 0 : clamp01((xCurrent - xStart) / (xEnd - xStart));\n\n this.__props.start.x = xStart;\n this.__props.start.y = yStart;\n this.__props.end.x = xEnd;\n this.__props.end.y = yEnd;\n this.__props.current.x = xCurrent;\n this.__props.current.y = yCurrent;\n this.__props.dampedCurrent.x = xCurrent;\n this.__props.dampedCurrent.y = yCurrent;\n this.__props.progress.x = xProgress;\n this.__props.progress.y = yProgress;\n this.__props.dampedProgress.x = xProgress;\n this.__props.dampedProgress.y = yProgress;\n }\n\n return this.__props;\n }\n\n /**\n * Factor used for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampFactor?: number = null;\n\n /**\n * Precision for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampPrecision?: number = null;\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.update(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.render(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props) => {\n if ((!this.$services.has('ticked') && props.changed.y) || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n ticked: () => {\n const dampFactor = this.dampFactor ?? this.$options.dampFactor;\n const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;\n updateProps(this.__props, dampFactor, dampPrecision, 'x');\n updateProps(this.__props, dampFactor, dampPrecision, 'y');\n\n if (\n this.__props.dampedCurrent.x === this.__props.current.x &&\n this.__props.dampedCurrent.y === this.__props.current.y\n ) {\n this.$services.disable('ticked');\n }\n\n render();\n },\n };\n\n this.$on('before-mounted', () => {\n this.$on('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\n this.$off('resized', delegate);\n this.$off('scrolled', delegate);\n this.$off('ticked', delegate);\n\n // Clamp damped values to their final value and trigger one last render on destroy\n this.__props.dampedCurrent.x = this.__props.current.x;\n this.__props.dampedCurrent.y = this.__props.current.y;\n this.__props.dampedProgress.x = this.__props.progress.x;\n this.__props.dampedProgress.y = this.__props.progress.y;\n render();\n });\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n // @ts-ignore\n if (isFunction(super.mounted)) {\n // @ts-ignore\n super.mounted();\n }\n }\n\n /**\n * Resized hook.\n */\n resized(props: ResizeServiceProps) {\n // @ts-ignore\n if (isFunction(super.resized)) {\n // @ts-ignore\n super.resized(props);\n }\n }\n\n /**\n * Scrolled hook.\n */\n scrolled(props: ScrollServiceProps) {\n // @ts-ignore\n if (isFunction(super.scrolled)) {\n // @ts-ignore\n super.scrolled(props);\n }\n }\n\n /**\n * Ticked hook.\n */\n ticked(props: RafServiceProps) {\n // @ts-ignore\n if (isFunction(super.ticked)) {\n // @ts-ignore\n super.ticked(props);\n }\n }\n\n /**\n * Destroyed hook.\n */\n destroyed() {\n // @ts-ignore\n if (isFunction(super.destroyed)) {\n // @ts-ignore\n super.destroyed();\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AAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/helpers/createApp.cjs
CHANGED
|
@@ -32,26 +32,27 @@ function createApp(App, rootElement = document.body) {
|
|
|
32
32
|
import_features.features.set(feature, value);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
35
|
+
function init() {
|
|
36
|
+
app = new App(options.root).$mount();
|
|
37
|
+
return app;
|
|
38
|
+
}
|
|
39
|
+
let p;
|
|
40
|
+
if (import_features.features.get("asyncChildren")) {
|
|
41
|
+
p = Promise.resolve(init());
|
|
42
|
+
} else {
|
|
43
|
+
p = new Promise((resolve) => {
|
|
44
|
+
if (document.readyState === "complete") {
|
|
45
|
+
resolve(init());
|
|
46
|
+
} else {
|
|
47
|
+
document.addEventListener("readystatechange", () => {
|
|
48
|
+
if (document.readyState === "complete") {
|
|
49
|
+
resolve(init());
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return () => p;
|
|
55
56
|
}
|
|
56
57
|
if (module.exports.default) module.exports = module.exports.default;
|
|
57
58
|
//# sourceMappingURL=createApp.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/createApp.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Features;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n */\nexport default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n rootElement: HTMLElement | Partial<CreateAppOptions> = document.body,\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const options =\n rootElement instanceof HTMLElement\n ? { root: rootElement, features: undefined }\n : { root: document.body, ...rootElement };\n\n if (isDefined(options.features)) {\n Object.entries(options.features).forEach(([feature, value]) => {\n features.set(feature as keyof Features, value);\n });\n }\n\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAyB;AACzB,mBAA0B;AAWX,SAAR,UACL,KACA,cAAuD,SAAS,MACpC;AAC5B,MAAI;AACJ,QAAM,UACJ,uBAAuB,cACnB,EAAE,MAAM,aAAa,UAAU,OAAU,IACzC,EAAE,MAAM,SAAS,MAAM,GAAG,YAAY;AAE5C,UAAI,wBAAU,QAAQ,QAAQ,GAAG;AAC/B,WAAO,QAAQ,QAAQ,
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Features;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n */\nexport default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n rootElement: HTMLElement | Partial<CreateAppOptions> = document.body,\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const options =\n rootElement instanceof HTMLElement\n ? { root: rootElement, features: undefined }\n : { root: document.body, ...rootElement };\n\n if (isDefined(options.features)) {\n Object.entries(options.features as Features).forEach(([feature, value]) => {\n features.set(feature as keyof Features, value);\n });\n }\n\n function init() {\n app = (new App(options.root) as S & Base<T>).$mount();\n return app;\n }\n\n let p: Promise<S & Base<T>>;\n\n if (features.get('asyncChildren')) {\n p = Promise.resolve(init());\n } else {\n p = new Promise<S & Base<T>>((resolve) => {\n if (document.readyState === 'complete') {\n resolve(init());\n } else {\n document.addEventListener('readystatechange', () => {\n if (document.readyState === 'complete') {\n resolve(init());\n }\n });\n }\n });\n }\n\n return () => p;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAyB;AACzB,mBAA0B;AAWX,SAAR,UACL,KACA,cAAuD,SAAS,MACpC;AAC5B,MAAI;AACJ,QAAM,UACJ,uBAAuB,cACnB,EAAE,MAAM,aAAa,UAAU,OAAU,IACzC,EAAE,MAAM,SAAS,MAAM,GAAG,YAAY;AAE5C,UAAI,wBAAU,QAAQ,QAAQ,GAAG;AAC/B,WAAO,QAAQ,QAAQ,QAAoB,EAAE,QAAQ,CAAC,CAAC,SAAS,KAAK,MAAM;AACzE,+BAAS,IAAI,SAA2B,KAAK;AAAA,IAC/C,CAAC;AAAA,EACH;AAEA,WAAS,OAAO;AACd,UAAO,IAAI,IAAI,QAAQ,IAAI,EAAkB,OAAO;AACpD,WAAO;AAAA,EACT;AAEA,MAAI;AAEJ,MAAI,yBAAS,IAAI,eAAe,GAAG;AACjC,QAAI,QAAQ,QAAQ,KAAK,CAAC;AAAA,EAC5B,OAAO;AACL,QAAI,IAAI,QAAqB,CAAC,YAAY;AACxC,UAAI,SAAS,eAAe,YAAY;AACtC,gBAAQ,KAAK,CAAC;AAAA,MAChB,OAAO;AACL,iBAAS,iBAAiB,oBAAoB,MAAM;AAClD,cAAI,SAAS,eAAe,YAAY;AACtC,oBAAQ,KAAK,CAAC;AAAA,UAChB;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO,MAAM;AACf;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/helpers/createApp.js
CHANGED
|
@@ -8,26 +8,27 @@ function createApp(App, rootElement = document.body) {
|
|
|
8
8
|
features.set(feature, value);
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
11
|
+
function init() {
|
|
12
|
+
app = new App(options.root).$mount();
|
|
13
|
+
return app;
|
|
14
|
+
}
|
|
15
|
+
let p;
|
|
16
|
+
if (features.get("asyncChildren")) {
|
|
17
|
+
p = Promise.resolve(init());
|
|
18
|
+
} else {
|
|
19
|
+
p = new Promise((resolve) => {
|
|
20
|
+
if (document.readyState === "complete") {
|
|
21
|
+
resolve(init());
|
|
22
|
+
} else {
|
|
23
|
+
document.addEventListener("readystatechange", () => {
|
|
24
|
+
if (document.readyState === "complete") {
|
|
25
|
+
resolve(init());
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return () => p;
|
|
31
32
|
}
|
|
32
33
|
export {
|
|
33
34
|
createApp as default
|
package/helpers/createApp.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/createApp.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Features;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n */\nexport default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n rootElement: HTMLElement | Partial<CreateAppOptions> = document.body,\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const options =\n rootElement instanceof HTMLElement\n ? { root: rootElement, features: undefined }\n : { root: document.body, ...rootElement };\n\n if (isDefined(options.features)) {\n Object.entries(options.features).forEach(([feature, value]) => {\n features.set(feature as keyof Features, value);\n });\n }\n\n
|
|
5
|
-
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAWX,SAAR,UACL,KACA,cAAuD,SAAS,MACpC;AAC5B,MAAI;AACJ,QAAM,UACJ,uBAAuB,cACnB,EAAE,MAAM,aAAa,UAAU,OAAU,IACzC,EAAE,MAAM,SAAS,MAAM,GAAG,YAAY;AAE5C,MAAI,UAAU,QAAQ,QAAQ,GAAG;AAC/B,WAAO,QAAQ,QAAQ,
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Features;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n */\nexport default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n rootElement: HTMLElement | Partial<CreateAppOptions> = document.body,\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const options =\n rootElement instanceof HTMLElement\n ? { root: rootElement, features: undefined }\n : { root: document.body, ...rootElement };\n\n if (isDefined(options.features)) {\n Object.entries(options.features as Features).forEach(([feature, value]) => {\n features.set(feature as keyof Features, value);\n });\n }\n\n function init() {\n app = (new App(options.root) as S & Base<T>).$mount();\n return app;\n }\n\n let p: Promise<S & Base<T>>;\n\n if (features.get('asyncChildren')) {\n p = Promise.resolve(init());\n } else {\n p = new Promise<S & Base<T>>((resolve) => {\n if (document.readyState === 'complete') {\n resolve(init());\n } else {\n document.addEventListener('readystatechange', () => {\n if (document.readyState === 'complete') {\n resolve(init());\n }\n });\n }\n });\n }\n\n return () => p;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAWX,SAAR,UACL,KACA,cAAuD,SAAS,MACpC;AAC5B,MAAI;AACJ,QAAM,UACJ,uBAAuB,cACnB,EAAE,MAAM,aAAa,UAAU,OAAU,IACzC,EAAE,MAAM,SAAS,MAAM,GAAG,YAAY;AAE5C,MAAI,UAAU,QAAQ,QAAQ,GAAG;AAC/B,WAAO,QAAQ,QAAQ,QAAoB,EAAE,QAAQ,CAAC,CAAC,SAAS,KAAK,MAAM;AACzE,eAAS,IAAI,SAA2B,KAAK;AAAA,IAC/C,CAAC;AAAA,EACH;AAEA,WAAS,OAAO;AACd,UAAO,IAAI,IAAI,QAAQ,IAAI,EAAkB,OAAO;AACpD,WAAO;AAAA,EACT;AAEA,MAAI;AAEJ,MAAI,SAAS,IAAI,eAAe,GAAG;AACjC,QAAI,QAAQ,QAAQ,KAAK,CAAC;AAAA,EAC5B,OAAO;AACL,QAAI,IAAI,QAAqB,CAAC,YAAY;AACxC,UAAI,SAAS,eAAe,YAAY;AACtC,gBAAQ,KAAK,CAAC;AAAA,MAChB,OAAO;AACL,iBAAS,iBAAiB,oBAAoB,MAAM;AAClD,cAAI,SAAS,eAAe,YAAY;AACtC,oBAAQ,KAAK,CAAC;AAAA,UAChB;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO,MAAM;AACf;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -23,7 +23,7 @@ __export(getInstanceFromElement_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(getInstanceFromElement_exports);
|
|
25
25
|
function getInstanceFromElement(element, Constructor) {
|
|
26
|
-
if (!element.__base__ || !element.__base__.has(Constructor)) {
|
|
26
|
+
if (!element || !element.__base__ || !element.__base__.has(Constructor)) {
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
29
|
return element.__base__.get(Constructor);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/getInstanceFromElement.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseConstructor, BaseEl } from '../Base/index.js';\n\n/**\n * Get a component instance from a DOM element.\n */\nexport default function getInstanceFromElement<T extends BaseConstructor>(\n element: BaseEl,\n Constructor: T,\n): InstanceType<T> | null {\n if (!element.__base__ || !element.__base__.has(Constructor)) {\n return null;\n }\n\n return element.__base__.get(Constructor) as InstanceType<T>;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKe,SAAR,uBACL,SACA,aACwB;AACxB,MAAI,CAAC,QAAQ,YAAY,CAAC,QAAQ,SAAS,IAAI,WAAW,GAAG;
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor, BaseEl } from '../Base/index.js';\n\n/**\n * Get a component instance from a DOM element.\n */\nexport default function getInstanceFromElement<T extends BaseConstructor>(\n element: BaseEl,\n Constructor: T,\n): InstanceType<T> | null {\n if (!element || !element.__base__ || !element.__base__.has(Constructor)) {\n return null;\n }\n\n return element.__base__.get(Constructor) as InstanceType<T>;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKe,SAAR,uBACL,SACA,aACwB;AACxB,MAAI,CAAC,WAAW,CAAC,QAAQ,YAAY,CAAC,QAAQ,SAAS,IAAI,WAAW,GAAG;AACvE,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,SAAS,IAAI,WAAW;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/getInstanceFromElement.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseConstructor, BaseEl } from '../Base/index.js';\n\n/**\n * Get a component instance from a DOM element.\n */\nexport default function getInstanceFromElement<T extends BaseConstructor>(\n element: BaseEl,\n Constructor: T,\n): InstanceType<T> | null {\n if (!element.__base__ || !element.__base__.has(Constructor)) {\n return null;\n }\n\n return element.__base__.get(Constructor) as InstanceType<T>;\n}\n"],
|
|
5
|
-
"mappings": "AAKe,SAAR,uBACL,SACA,aACwB;AACxB,MAAI,CAAC,QAAQ,YAAY,CAAC,QAAQ,SAAS,IAAI,WAAW,GAAG;
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor, BaseEl } from '../Base/index.js';\n\n/**\n * Get a component instance from a DOM element.\n */\nexport default function getInstanceFromElement<T extends BaseConstructor>(\n element: BaseEl,\n Constructor: T,\n): InstanceType<T> | null {\n if (!element || !element.__base__ || !element.__base__.has(Constructor)) {\n return null;\n }\n\n return element.__base__.get(Constructor) as InstanceType<T>;\n}\n"],
|
|
5
|
+
"mappings": "AAKe,SAAR,uBACL,SACA,aACwB;AACxB,MAAI,CAAC,WAAW,CAAC,QAAQ,YAAY,CAAC,QAAQ,SAAS,IAAI,WAAW,GAAG;AACvE,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,SAAS,IAAI,WAAW;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
package/services/drag.cjs
CHANGED
|
@@ -40,7 +40,8 @@ var MODES = {
|
|
|
40
40
|
STOP: "stop"
|
|
41
41
|
};
|
|
42
42
|
var count = 0;
|
|
43
|
-
var
|
|
43
|
+
var targetEvents = ["pointerdown"];
|
|
44
|
+
var windowEvents = ["pointerup", "touchend"];
|
|
44
45
|
var passiveEventOptions = { passive: true };
|
|
45
46
|
function getEventPosition(event) {
|
|
46
47
|
const eventOrTouch = (0, import_utils.isDefined)(event.touches) ? event.touches[0] : event;
|
|
@@ -188,16 +189,22 @@ function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}
|
|
|
188
189
|
}
|
|
189
190
|
},
|
|
190
191
|
init() {
|
|
191
|
-
|
|
192
|
+
targetEvents.forEach((event) => {
|
|
192
193
|
target.addEventListener(event, handleEvent, passiveEventOptions);
|
|
193
194
|
});
|
|
195
|
+
windowEvents.forEach((event) => {
|
|
196
|
+
window.addEventListener(event, handleEvent, passiveEventOptions);
|
|
197
|
+
});
|
|
194
198
|
target.addEventListener("dragstart", handleEvent, { capture: true });
|
|
195
199
|
target.addEventListener("click", handleEvent, { capture: true });
|
|
196
200
|
},
|
|
197
201
|
kill() {
|
|
198
|
-
|
|
202
|
+
targetEvents.forEach((event) => {
|
|
199
203
|
target.removeEventListener(event, handleEvent);
|
|
200
204
|
});
|
|
205
|
+
windowEvents.forEach((event) => {
|
|
206
|
+
window.removeEventListener(event, handleEvent);
|
|
207
|
+
});
|
|
201
208
|
target.removeEventListener("dragstart", handleEvent);
|
|
202
209
|
target.removeEventListener("click", handleEvent);
|
|
203
210
|
}
|
package/services/drag.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/services/drag.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */\nimport { useService } from './service.js';\nimport useRaf from './raf.js';\nimport inertiaFinalValue from '../utils/math/inertiaFinalValue.js';\nimport { isDefined } from '../utils/index.js';\nimport type { ServiceInterface } from './index.js';\n\nexport type DragService = ServiceInterface<DragServiceProps>;\n\ntype DragLifecycle = 'start' | 'drag' | 'drop' | 'inertia' | 'stop';\n\nexport interface DragServiceProps {\n /**\n * The current mode of the dragging logic.\n */\n mode: DragLifecycle;\n /**\n * The target element of the drag.\n */\n target: HTMLElement;\n /**\n * Whether the user is currently grabbing the targeted element or not.\n */\n isGrabbing: boolean;\n /**\n * Whether the drag currently has inertia or not.\n */\n hasInertia: boolean;\n /**\n * The current horizontal position in the viewport.\n */\n x: number;\n /**\n * The current vertical position in the viewport.\n */\n y: number;\n /**\n * The delta between the current position and the last.\n */\n delta: { x: number; y: number };\n /**\n * The initial position where the dragging started.\n */\n origin: { x: number; y: number };\n /**\n * The distance from the current position to the origin.\n */\n distance: { x: number; y: number };\n /**\n * The final position that will be reached at the end of the inertia.\n */\n final: { x: number; y: number };\n}\n\nexport interface DragServiceOptions {\n dampFactor?: number;\n dragTreshold?: number;\n}\n\nconst MODES: Record<Uppercase<DragLifecycle>, DragLifecycle> = {\n START: 'start',\n DRAG: 'drag',\n DROP: 'drop',\n INERTIA: 'inertia',\n STOP: 'stop',\n};\n\nlet count = 0;\nconst
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA2B;AAC3B,iBAAmB;AACnB,+BAA8B;AAC9B,mBAA0B;AAuD1B,IAAM,QAAyD;AAAA,EAC7D,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AACR;AAEA,IAAI,QAAQ;AACZ,IAAM,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */\nimport { useService } from './service.js';\nimport useRaf from './raf.js';\nimport inertiaFinalValue from '../utils/math/inertiaFinalValue.js';\nimport { isDefined } from '../utils/index.js';\nimport type { ServiceInterface } from './index.js';\n\nexport type DragService = ServiceInterface<DragServiceProps>;\n\ntype DragLifecycle = 'start' | 'drag' | 'drop' | 'inertia' | 'stop';\n\nexport interface DragServiceProps {\n /**\n * The current mode of the dragging logic.\n */\n mode: DragLifecycle;\n /**\n * The target element of the drag.\n */\n target: HTMLElement;\n /**\n * Whether the user is currently grabbing the targeted element or not.\n */\n isGrabbing: boolean;\n /**\n * Whether the drag currently has inertia or not.\n */\n hasInertia: boolean;\n /**\n * The current horizontal position in the viewport.\n */\n x: number;\n /**\n * The current vertical position in the viewport.\n */\n y: number;\n /**\n * The delta between the current position and the last.\n */\n delta: { x: number; y: number };\n /**\n * The initial position where the dragging started.\n */\n origin: { x: number; y: number };\n /**\n * The distance from the current position to the origin.\n */\n distance: { x: number; y: number };\n /**\n * The final position that will be reached at the end of the inertia.\n */\n final: { x: number; y: number };\n}\n\nexport interface DragServiceOptions {\n dampFactor?: number;\n dragTreshold?: number;\n}\n\nconst MODES: Record<Uppercase<DragLifecycle>, DragLifecycle> = {\n START: 'start',\n DRAG: 'drag',\n DROP: 'drop',\n INERTIA: 'inertia',\n STOP: 'stop',\n};\n\nlet count = 0;\nconst targetEvents = ['pointerdown'];\nconst windowEvents = ['pointerup', 'touchend'];\nconst passiveEventOptions = { passive: true };\n\n/**\n * Get the client value for the given axis.\n */\nfunction getEventPosition(event: MouseEvent | TouchEvent): { x: number; y: number } {\n // @ts-ignore\n const eventOrTouch = isDefined(event.touches) ? event.touches[0] : event;\n return {\n x: eventOrTouch.clientX,\n y: eventOrTouch.clientY,\n };\n}\n\n/**\n * Get drag service.\n */\nfunction createDragService(\n target: HTMLElement,\n { dampFactor = 0.85, dragTreshold = 10 }: DragServiceOptions = {},\n): DragService {\n count += 1;\n const id = `drag-${count}`;\n let previousEvent;\n\n /**\n * Test if we should allow click on links and buttons.\n */\n function shouldPreventClick(): boolean {\n return Math.abs(props.distance.x) > dragTreshold || Math.abs(props.distance.y) > dragTreshold;\n }\n\n /**\n * Start the drag.\n * @param {number} x The initial horizontal position.\n * @param {number} y The initial vertical position.\n * @returns {void}\n */\n function start(x: number, y: number) {\n if (props.isGrabbing) {\n return;\n }\n\n // Reset state\n props.x = x;\n props.y = y;\n props.origin.x = x;\n props.origin.y = y;\n props.delta.x = 0;\n props.delta.y = 0;\n props.distance.x = 0;\n props.distance.y = 0;\n props.final.x = x;\n props.final.y = y;\n\n props.mode = MODES.START;\n\n // Enable grabbing\n props.isGrabbing = true;\n\n trigger(props);\n\n document.addEventListener('touchmove', handleEvent, passiveEventOptions);\n document.addEventListener('mousemove', handleEvent, passiveEventOptions);\n }\n\n /**\n * Stop the drag, or drop.\n */\n function drop() {\n document.removeEventListener('touchmove', handleEvent);\n document.removeEventListener('mousemove', handleEvent);\n props.isGrabbing = false;\n props.mode = MODES.DROP;\n\n props.hasInertia = true;\n props.final.x = inertiaFinalValue(props.x, props.delta.x, dampFactor);\n props.final.y = inertiaFinalValue(props.y, props.delta.y, dampFactor);\n\n trigger(props);\n\n setTimeout(() => {\n const raf = useRaf();\n raf.remove(id);\n raf.add(id, rafHandler);\n }, 0);\n }\n\n /**\n * Stop the drag.\n */\n function stop() {\n useRaf().remove(id);\n props.isGrabbing = false;\n props.hasInertia = false;\n props.mode = MODES.STOP;\n trigger(props);\n }\n\n /**\n * Raf service handler.\n */\n function rafHandler() {\n if (!props.isGrabbing) {\n props.x += props.delta.x;\n props.y += props.delta.y;\n props.distance.x = props.x - props.origin.x;\n props.distance.y = props.y - props.origin.y;\n\n props.delta.x *= dampFactor;\n props.delta.y *= dampFactor;\n\n if (props.mode !== MODES.INERTIA) {\n props.mode = MODES.INERTIA;\n }\n\n trigger(props);\n\n if (Math.abs(props.delta.x) < 0.1 && Math.abs(props.delta.y) < 0.1) {\n stop();\n }\n }\n }\n\n /**\n * Pointer service handler.\n */\n function drag(event: TouchEvent | MouseEvent) {\n if (props.isGrabbing) {\n const position = getEventPosition(event);\n props.x = position.x;\n props.y = position.y;\n\n if (previousEvent) {\n const previousPosition = getEventPosition(previousEvent);\n props.delta.x = position.x - previousPosition.x;\n props.delta.y = position.y - previousPosition.y;\n }\n\n props.final.x = position.x;\n props.final.y = position.y;\n props.distance.x = props.x - props.origin.x;\n props.distance.y = props.y - props.origin.y;\n\n if (props.mode !== MODES.DRAG) {\n props.mode = MODES.DRAG;\n }\n\n trigger(props);\n previousEvent = event;\n }\n }\n\n /**\n * Handle any event.\n */\n function handleEvent(event: MouseEvent | PointerEvent | DragEvent) {\n switch (event.type) {\n case 'dragstart':\n event.preventDefault();\n break;\n case 'click':\n if (shouldPreventClick()) {\n event.stopImmediatePropagation();\n event.stopPropagation();\n event.preventDefault();\n }\n break;\n case 'pointerup':\n case 'touchend':\n drop();\n break;\n case 'touchmove':\n case 'mousemove':\n drag(event);\n break;\n default:\n if (event.button === 0) {\n start(event.x, event.y);\n }\n }\n }\n\n const { add, remove, has, trigger, props } = useService({\n props: {\n target,\n mode: undefined,\n isGrabbing: false,\n hasInertia: false,\n x: 0,\n y: 0,\n delta: {\n x: 0,\n y: 0,\n },\n origin: {\n x: 0,\n y: 0,\n },\n distance: {\n x: 0,\n y: 0,\n },\n final: {\n x: 0,\n y: 0,\n },\n } as DragServiceProps,\n init() {\n targetEvents.forEach((event) => {\n target.addEventListener(event, handleEvent, passiveEventOptions);\n });\n windowEvents.forEach((event) => {\n window.addEventListener(event, handleEvent, passiveEventOptions);\n });\n target.addEventListener('dragstart', handleEvent, { capture: true });\n target.addEventListener('click', handleEvent, { capture: true });\n },\n kill() {\n targetEvents.forEach((event) => {\n target.removeEventListener(event, handleEvent);\n });\n windowEvents.forEach((event) => {\n window.removeEventListener(event, handleEvent);\n });\n target.removeEventListener('dragstart', handleEvent);\n target.removeEventListener('click', handleEvent);\n },\n });\n\n return {\n add,\n remove,\n has,\n props: () => props,\n };\n}\n\nconst instances: WeakMap<HTMLElement, DragService | undefined> = new WeakMap();\n\n/**\n * Use the drag service.\n *\n * ```js\n * import { useDrag } from '@studiometa/js-toolkit/services';\n * const { add, remove, props } = useDrag();\n * const draggableElement = document.querySelector('.draggable');\n * add(draggableElement, (props) => {}, { factor: 0.8 });\n * remove(draggableElement);\n * props(draggableElement);\n * ```\n */\nexport default function useDrag(target: HTMLElement, options: DragServiceOptions): DragService {\n if (!instances.has(target)) {\n instances.set(target, createDragService(target, options));\n }\n\n return instances.get(target);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;A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ACL;AAAA,IACF;AAAA,IACA,OAAO;AACL,mBAAa,QAAQ,CAAC,UAAU;AAC9B,eAAO,iBAAiB,OAAO,aAAa,mBAAmB;AAAA,MACjE,CAAC;AACD,mBAAa,QAAQ,CAAC,UAAU;AAC9B,eAAO,iBAAiB,OAAO,aAAa,mBAAmB;AAAA,MACjE,CAAC;AACD,aAAO,iBAAiB,aAAa,aAAa,EAAE,SAAS,KAAK,CAAC;AACnE,aAAO,iBAAiB,SAAS,aAAa,EAAE,SAAS,KAAK,CAAC;AAAA,IACjE;AAAA,IACA,OAAO;AACL,mBAAa,QAAQ,CAAC,UAAU;AAC9B,eAAO,oBAAoB,OAAO,WAAW;AAAA,MAC/C,CAAC;AACD,mBAAa,QAAQ,CAAC,UAAU;AAC9B,eAAO,oBAAoB,OAAO,WAAW;AAAA,MAC/C,CAAC;AACD,aAAO,oBAAoB,aAAa,WAAW;AACnD,aAAO,oBAAoB,SAAS,WAAW;AAAA,IACjD;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,MAAM;AAAA,EACf;AACF;AAEA,IAAM,YAA2D,oBAAI,QAAQ;AAc9D,SAAR,QAAyB,QAAqB,SAA0C;AAC7F,MAAI,CAAC,UAAU,IAAI,MAAM,GAAG;AAC1B,cAAU,IAAI,QAAQ,kBAAkB,QAAQ,OAAO,CAAC;AAAA,EAC1D;AAEA,SAAO,UAAU,IAAI,MAAM;AAC7B;",
|
|
6
6
|
"names": ["inertiaFinalValue", "useRaf"]
|
|
7
7
|
}
|
package/services/drag.js
CHANGED
|
@@ -10,7 +10,8 @@ const MODES = {
|
|
|
10
10
|
STOP: "stop"
|
|
11
11
|
};
|
|
12
12
|
let count = 0;
|
|
13
|
-
const
|
|
13
|
+
const targetEvents = ["pointerdown"];
|
|
14
|
+
const windowEvents = ["pointerup", "touchend"];
|
|
14
15
|
const passiveEventOptions = { passive: true };
|
|
15
16
|
function getEventPosition(event) {
|
|
16
17
|
const eventOrTouch = isDefined(event.touches) ? event.touches[0] : event;
|
|
@@ -158,16 +159,22 @@ function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}
|
|
|
158
159
|
}
|
|
159
160
|
},
|
|
160
161
|
init() {
|
|
161
|
-
|
|
162
|
+
targetEvents.forEach((event) => {
|
|
162
163
|
target.addEventListener(event, handleEvent, passiveEventOptions);
|
|
163
164
|
});
|
|
165
|
+
windowEvents.forEach((event) => {
|
|
166
|
+
window.addEventListener(event, handleEvent, passiveEventOptions);
|
|
167
|
+
});
|
|
164
168
|
target.addEventListener("dragstart", handleEvent, { capture: true });
|
|
165
169
|
target.addEventListener("click", handleEvent, { capture: true });
|
|
166
170
|
},
|
|
167
171
|
kill() {
|
|
168
|
-
|
|
172
|
+
targetEvents.forEach((event) => {
|
|
169
173
|
target.removeEventListener(event, handleEvent);
|
|
170
174
|
});
|
|
175
|
+
windowEvents.forEach((event) => {
|
|
176
|
+
window.removeEventListener(event, handleEvent);
|
|
177
|
+
});
|
|
171
178
|
target.removeEventListener("dragstart", handleEvent);
|
|
172
179
|
target.removeEventListener("click", handleEvent);
|
|
173
180
|
}
|