@andrew_l/dom 0.3.21 → 0.4.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/dist/index.d.mts +36 -33
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +162 -228
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -8
- package/dist/index.cjs +0 -281
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -219
- package/dist/index.d.ts +0 -219
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
interface AnimationInstance {
|
|
2
|
-
|
|
2
|
+
isCancelled: boolean;
|
|
3
3
|
}
|
|
4
4
|
/**
|
|
5
5
|
* Animates a single tick of an animation, running repeatedly until cancelled or the tick function returns `false`.
|
|
@@ -54,30 +54,30 @@ declare function animate(tick: Function): void;
|
|
|
54
54
|
declare function animateInstantly(tick: Function): void;
|
|
55
55
|
type TimingFn = (t: number) => number;
|
|
56
56
|
type AnimateNumberProps = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
to: number | number[];
|
|
58
|
+
from: number | number[];
|
|
59
|
+
duration: number;
|
|
60
|
+
onUpdate: (value: any) => void;
|
|
61
|
+
timing?: TimingFn;
|
|
62
|
+
onEnd?: () => void;
|
|
63
63
|
};
|
|
64
64
|
declare const timingFunctions: {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
65
|
+
linear: (t: number) => number;
|
|
66
|
+
easeIn: (t: number) => number;
|
|
67
|
+
easeOut: (t: number) => number;
|
|
68
|
+
easeInOut: (t: number) => number;
|
|
69
|
+
easeInQuad: (t: number) => number;
|
|
70
|
+
easeOutQuad: (t: number) => number;
|
|
71
|
+
easeInOutQuad: (t: number) => number;
|
|
72
|
+
easeInCubic: (t: number) => number;
|
|
73
|
+
easeOutCubic: (t: number) => number;
|
|
74
|
+
easeInOutCubic: (t: number) => number;
|
|
75
|
+
easeInQuart: (t: number) => number;
|
|
76
|
+
easeOutQuart: (t: number) => number;
|
|
77
|
+
easeInOutQuart: (t: number) => number;
|
|
78
|
+
easeInQuint: (t: number) => number;
|
|
79
|
+
easeOutQuint: (t: number) => number;
|
|
80
|
+
easeInOutQuint: (t: number) => number;
|
|
81
81
|
};
|
|
82
82
|
/**
|
|
83
83
|
* Animates a numeric value from `from` to `to` over a specified duration, applying an optional timing function.
|
|
@@ -109,8 +109,14 @@ declare const timingFunctions: {
|
|
|
109
109
|
*
|
|
110
110
|
* @group Animation
|
|
111
111
|
*/
|
|
112
|
-
declare function animateNumber({
|
|
113
|
-
|
|
112
|
+
declare function animateNumber({
|
|
113
|
+
timing,
|
|
114
|
+
onUpdate,
|
|
115
|
+
duration,
|
|
116
|
+
onEnd,
|
|
117
|
+
from,
|
|
118
|
+
to
|
|
119
|
+
}: AnimateNumberProps): () => void;
|
|
114
120
|
/**
|
|
115
121
|
* Copies the provided text to the system clipboard.
|
|
116
122
|
*
|
|
@@ -134,16 +140,15 @@ declare function animateNumber({ timing, onUpdate, duration, onEnd, from, to, }:
|
|
|
134
140
|
* @group Clipboard
|
|
135
141
|
*/
|
|
136
142
|
declare function copyTextToClipboard(text: string): Promise<boolean>;
|
|
137
|
-
|
|
138
143
|
declare const FAST_SMOOTH_MAX_DISTANCE = 1500;
|
|
139
144
|
declare const FAST_SMOOTH_MIN_DURATION = 250;
|
|
140
145
|
declare const FAST_SMOOTH_MAX_DURATION = 600;
|
|
141
146
|
declare const FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE = 500;
|
|
142
147
|
type ScrollCompleteCallback = (target: HTMLElement) => void;
|
|
143
148
|
declare enum FocusDirection {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
Up = 0,
|
|
150
|
+
Down = 1,
|
|
151
|
+
Static = 2
|
|
147
152
|
}
|
|
148
153
|
/**
|
|
149
154
|
* Smoothly scrolls the specified container to bring the given element into view,
|
|
@@ -169,7 +174,6 @@ declare enum FocusDirection {
|
|
|
169
174
|
* @group Scrolling
|
|
170
175
|
*/
|
|
171
176
|
declare function fastSmoothScroll(container: HTMLElement, element: HTMLElement, position: ScrollLogicalPosition | 'centerOrTop', margin?: number, maxDistance?: number, forceDirection?: FocusDirection, forceDuration?: number, forceNormalContainerHeight?: boolean, onComplete?: ScrollCompleteCallback): void;
|
|
172
|
-
|
|
173
177
|
/**
|
|
174
178
|
* Determines if the specified element or the document/window is scrolled near the bottom.
|
|
175
179
|
*
|
|
@@ -196,7 +200,6 @@ declare function fastSmoothScroll(container: HTMLElement, element: HTMLElement,
|
|
|
196
200
|
* @group Scrolling
|
|
197
201
|
*/
|
|
198
202
|
declare function isScrolledToDown(target: HTMLElement | Document | Window, threshold?: number): boolean;
|
|
199
|
-
|
|
200
203
|
/**
|
|
201
204
|
* Resets the scroll position of the specified container element.
|
|
202
205
|
*
|
|
@@ -215,5 +218,5 @@ declare function isScrolledToDown(target: HTMLElement | Document | Window, thres
|
|
|
215
218
|
* @group Scrolling
|
|
216
219
|
*/
|
|
217
220
|
declare function resetScroll(container: HTMLDivElement, scrollTop?: number): void;
|
|
218
|
-
|
|
219
|
-
|
|
221
|
+
export { AnimateNumberProps, FAST_SMOOTH_MAX_DISTANCE, FAST_SMOOTH_MAX_DURATION, FAST_SMOOTH_MIN_DURATION, FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE, FocusDirection, ScrollCompleteCallback, TimingFn, animate, animateInstantly, animateNumber, animateSingle, copyTextToClipboard, fastSmoothScroll, isScrolledToDown, resetScroll, timingFunctions };
|
|
222
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["isCancelled","Function","tick","AnimationInstance","instance","t","to","from","duration","onUpdate","value","timing","TimingFn","onEnd","linear","easeIn","easeOut","easeInOut","easeInQuad","easeOutQuad","easeInOutQuad","easeInCubic","easeOutCubic","easeInOutCubic","easeInQuart","easeOutQuart","easeInOutQuart","easeInQuint","easeOutQuint","easeInOutQuint","AnimateNumberProps","text","Promise","HTMLElement","target","Up","Down","Static","container","element","ScrollLogicalPosition","position","margin","maxDistance","FocusDirection","forceDirection","forceDuration","forceNormalContainerHeight","ScrollCompleteCallback","onComplete","HTMLElement","Document","Window","target","threshold","HTMLDivElement","container","scrollTop"],"sources":["../src/animation.d.ts","../src/copyTextToClipboard.d.ts","../src/fastSmoothScroll.d.ts","../src/isScrolledToDown.d.ts","../src/resetScroll.d.ts"],"mappings":"UAAU,iBAAA;EACNA,WAAW;AAAA;;AAAA;AAoBf;;;;;;;;;AAAkF;AAgBlF;;;;AAA8C;AAgB9C;iBAhCwB,aAAA,CAAcE,IAAAA,EAAM,QAAA,EAAUE,QAAAA,GAAW,iBAAiB;;;AAgC3B;AACvD;;;;AAAiC;AACjC;;;;;;;iBAlBwB,OAAA,CAAQF,IAAc,EAAR,QAAQ;;;;;;AAwBrC;AAET;;;;;;;;;iBAVwB,gBAAA,CAAiBA,IAAc,EAAR,QAAQ;AAAA,KAC3C,QAAA,IAAYG,CAAS;AAAA,KACrB,kBAAA;EACRC,EAAAA;EACAC,IAAAA;EACAC,QAAAA;EACAC,QAAAA,GAAWC,KAAAA;EACXC,MAAAA,GAAS,QAAQ;EACjBE,KAAAA;AAAAA;AAAAA,cAEiB,eAAA;EACjBC,MAAAA,GAAST,CAAAA;EACTU,MAAAA,GAASV,CAAAA;EACTW,OAAAA,GAAUX,CAAAA;EACVY,SAAAA,GAAYZ,CAAAA;EACZa,UAAAA,GAAab,CAAAA;EACbc,WAAAA,GAAcd,CAAAA;EACde,aAAAA,GAAgBf,CAAAA;EAChBgB,WAAAA,GAAchB,CAAAA;EACdiB,YAAAA,GAAejB,CAAAA;EACfkB,cAAAA,GAAiBlB,CAAAA;EACjBmB,WAAAA,GAAcnB,CAAAA;EACdoB,YAAAA,GAAepB,CAAAA;EACfqB,cAAAA,GAAiBrB,CAAAA;EACjBsB,WAAAA,GAActB,CAAAA;EACduB,YAAAA,GAAevB,CAAAA;EACfwB,cAAAA,GAAiBxB,CAAAA;AAAAA;AAAS;AAgC9B;;;;;;;;;;;;;;;;;;;;;;;;;;AAA0G;;ACzF1G;ADyD8B,iBAgCN,aAAA;EAAgBM,MAAAA;EAAQF,QAAAA;EAAUD,QAAAA;EAAUK,KAAAA;EAAON,IAAAA;EAAMD;AAAAA,GAAO,kBAAA;;;;;AA9GzE;AAoBf;;;;;;;;;AAAkF;AAgBlF;;;;AAA8C;AAgB9C;;iBC/BwB,mBAAA,CAAoByB,IAAAA,WAAe,OAAO;AAAA,cCtB7C,wBAAA;AAAA,cACA,wBAAA;AAAA,cACA,wBAAA;AAAA,cACA,yCAAA;AAAA,KACT,sBAAA,IAA0BG,MAAmB,EAAX,WAAW;AAAA,aACrC,cAAA;EAChBC,EAAAA;EACAC,IAAAA;EACAC,MAAAA;AAAAA;;;;;AFa8E;AAgBlF;;;;AAA8C;AAgB9C;;;;AAAuD;AACvD;;;;AAAiC;AACjC;;;iBEtBwB,gBAAA,CAAiBC,SAAAA,EAAW,WAAA,EAAaC,OAAAA,EAAS,WAAA,EAAaE,QAAAA,EAAU,qBAAA,kBAAuCC,MAAAA,WAAiBC,WAAAA,WAAsBE,cAAAA,GAAiB,cAAA,EAAgBC,aAAAA,WAAwBC,0BAAAA,YAAsCE,UAAAA,GAAa,sBAAA;;;;;AFhC5Q;AAoBf;;;;;;;;;AAAkF;AAgBlF;;;;AAA8C;AAgB9C;;;;AAAuD;iBG5B/B,gBAAA,CAAiBI,MAAAA,EAAQ,WAAA,GAAc,QAAA,GAAW,MAAA,EAAQC,SAAAA;;;;;AHxBnE;AAoBf;;;;;;;;;AAAkF;AAgBlF;;iBIpBwB,WAAA,CAAYE,SAAAA,EAAW,cAAc,EAAEC,SAAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,266 +1,200 @@
|
|
|
1
|
-
import { fastRaf } from
|
|
2
|
-
|
|
1
|
+
import { fastRaf } from "@andrew_l/toolkit";
|
|
3
2
|
let currentInstance;
|
|
4
3
|
function animateSingle(tick, instance) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
fastRaf(() => {
|
|
14
|
-
animateSingle(tick, instance);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
4
|
+
if (!instance) {
|
|
5
|
+
if (currentInstance && !currentInstance.isCancelled) currentInstance.isCancelled = true;
|
|
6
|
+
instance = { isCancelled: false };
|
|
7
|
+
currentInstance = instance;
|
|
8
|
+
}
|
|
9
|
+
if (!instance.isCancelled && tick()) fastRaf(() => {
|
|
10
|
+
animateSingle(tick, instance);
|
|
11
|
+
});
|
|
17
12
|
}
|
|
18
13
|
function animate(tick) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
});
|
|
14
|
+
fastRaf(() => {
|
|
15
|
+
if (tick()) animate(tick);
|
|
16
|
+
});
|
|
24
17
|
}
|
|
25
18
|
function animateInstantly(tick) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
}
|
|
19
|
+
if (tick()) fastRaf(() => {
|
|
20
|
+
animateInstantly(tick);
|
|
21
|
+
});
|
|
31
22
|
}
|
|
32
23
|
const timingFunctions = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
24
|
+
linear: (t) => t,
|
|
25
|
+
easeIn: (t) => t ** 1.675,
|
|
26
|
+
easeOut: (t) => -1 * t ** 1.675,
|
|
27
|
+
easeInOut: (t) => .5 * (Math.sin((t - .5) * Math.PI) + 1),
|
|
28
|
+
easeInQuad: (t) => t * t,
|
|
29
|
+
easeOutQuad: (t) => t * (2 - t),
|
|
30
|
+
easeInOutQuad: (t) => t < .5 ? 2 * t * t : -1 + (4 - 2 * t) * t,
|
|
31
|
+
easeInCubic: (t) => t ** 3,
|
|
32
|
+
easeOutCubic: (t) => --t * t * t + 1,
|
|
33
|
+
easeInOutCubic: (t) => t < .5 ? 4 * t ** 3 : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1,
|
|
34
|
+
easeInQuart: (t) => t ** 4,
|
|
35
|
+
easeOutQuart: (t) => 1 - --t * t ** 3,
|
|
36
|
+
easeInOutQuart: (t) => t < .5 ? 8 * t ** 4 : 1 - 8 * --t * t ** 3,
|
|
37
|
+
easeInQuint: (t) => t ** 5,
|
|
38
|
+
easeOutQuint: (t) => 1 + --t * t ** 4,
|
|
39
|
+
easeInOutQuint: (t) => t < .5 ? 16 * t ** 5 : 1 + 16 * --t * t ** 4
|
|
49
40
|
};
|
|
50
|
-
function animateNumber({
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
onUpdate(from + (to - from) * progress);
|
|
68
|
-
} else if (Array.isArray(from) && Array.isArray(to)) {
|
|
69
|
-
const result = from.map((f, i) => f + (to[i] - f) * progress);
|
|
70
|
-
onUpdate(result);
|
|
71
|
-
}
|
|
72
|
-
if (t === 1 && onEnd) onEnd();
|
|
73
|
-
return t < 1;
|
|
74
|
-
});
|
|
75
|
-
return () => {
|
|
76
|
-
canceled = true;
|
|
77
|
-
if (onEnd) onEnd();
|
|
78
|
-
};
|
|
41
|
+
function animateNumber({ timing = timingFunctions.linear, onUpdate, duration, onEnd, from, to }) {
|
|
42
|
+
const t0 = Date.now();
|
|
43
|
+
let canceled = false;
|
|
44
|
+
animateInstantly(() => {
|
|
45
|
+
if (canceled) return false;
|
|
46
|
+
let t = (Date.now() - t0) / duration;
|
|
47
|
+
if (t > 1) t = 1;
|
|
48
|
+
const progress = timing(t);
|
|
49
|
+
if (typeof from === "number" && typeof to === "number") onUpdate(from + (to - from) * progress);
|
|
50
|
+
else if (Array.isArray(from) && Array.isArray(to)) onUpdate(from.map((f, i) => f + (to[i] - f) * progress));
|
|
51
|
+
if (t === 1 && onEnd) onEnd();
|
|
52
|
+
return t < 1;
|
|
53
|
+
});
|
|
54
|
+
return () => {
|
|
55
|
+
canceled = true;
|
|
56
|
+
if (onEnd) onEnd();
|
|
57
|
+
};
|
|
79
58
|
}
|
|
80
|
-
|
|
81
59
|
const defaultWindow = globalThis?.window;
|
|
82
60
|
const defaultDocument = globalThis?.document;
|
|
83
61
|
const defaultNavigator = globalThis?.navigator;
|
|
84
|
-
|
|
62
|
+
globalThis?.window?.location;
|
|
85
63
|
function copyTextToClipboard(text) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
} else {
|
|
89
|
-
return copyWithFakeElement(text);
|
|
90
|
-
}
|
|
64
|
+
if (defaultNavigator?.clipboard) return copyWithNavigator(text);
|
|
65
|
+
else return copyWithFakeElement(text);
|
|
91
66
|
}
|
|
92
67
|
function copyWithNavigator(text) {
|
|
93
|
-
|
|
94
|
-
|
|
68
|
+
if (!defaultNavigator) return Promise.resolve(false);
|
|
69
|
+
return navigator.clipboard.writeText(text).then(() => true);
|
|
95
70
|
}
|
|
96
71
|
function copyWithFakeElement(text) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
if (selection) {
|
|
126
|
-
selection.removeAllRanges();
|
|
127
|
-
}
|
|
128
|
-
defaultDocument.body.removeChild(textareaEl);
|
|
129
|
-
});
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
if (!defaultDocument) return resolve(false);
|
|
74
|
+
if (!defaultWindow) return resolve(false);
|
|
75
|
+
const textareaEl = defaultDocument.createElement("textarea");
|
|
76
|
+
const range = defaultDocument.createRange();
|
|
77
|
+
textareaEl.value = text;
|
|
78
|
+
textareaEl.style.position = "fixed";
|
|
79
|
+
textareaEl.contentEditable = "true";
|
|
80
|
+
defaultDocument.body.appendChild(textareaEl);
|
|
81
|
+
textareaEl.focus();
|
|
82
|
+
textareaEl.select();
|
|
83
|
+
range.selectNodeContents(textareaEl);
|
|
84
|
+
const selection = defaultWindow.getSelection();
|
|
85
|
+
if (selection) {
|
|
86
|
+
selection.removeAllRanges();
|
|
87
|
+
selection.addRange(range);
|
|
88
|
+
}
|
|
89
|
+
textareaEl.setSelectionRange(0, 999999);
|
|
90
|
+
try {
|
|
91
|
+
if (defaultDocument.execCommand("copy")) resolve(true);
|
|
92
|
+
else reject(/* @__PURE__ */ new Error("copy failed"));
|
|
93
|
+
} catch (error) {
|
|
94
|
+
reject(error);
|
|
95
|
+
}
|
|
96
|
+
if (selection) selection.removeAllRanges();
|
|
97
|
+
defaultDocument.body.removeChild(textareaEl);
|
|
98
|
+
});
|
|
130
99
|
}
|
|
131
|
-
|
|
132
100
|
const FAST_SMOOTH_MAX_DISTANCE = 1500;
|
|
133
101
|
const FAST_SMOOTH_MIN_DURATION = 250;
|
|
134
102
|
const FAST_SMOOTH_MAX_DURATION = 600;
|
|
135
103
|
const FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE = 500;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
104
|
+
let FocusDirection = /* @__PURE__ */ function(FocusDirection) {
|
|
105
|
+
FocusDirection[FocusDirection["Up"] = 0] = "Up";
|
|
106
|
+
FocusDirection[FocusDirection["Down"] = 1] = "Down";
|
|
107
|
+
FocusDirection[FocusDirection["Static"] = 2] = "Static";
|
|
108
|
+
return FocusDirection;
|
|
109
|
+
}({});
|
|
142
110
|
function fastSmoothScroll(container, element, position, margin = 0, maxDistance = FAST_SMOOTH_MAX_DISTANCE, forceDirection, forceDuration, forceNormalContainerHeight, onComplete) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (forceDirection === 2 /* Static */) {
|
|
150
|
-
scrollWithJs(container, element, scrollFrom, position, margin, 0);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
scrollWithJs(
|
|
154
|
-
container,
|
|
155
|
-
element,
|
|
156
|
-
scrollFrom,
|
|
157
|
-
position,
|
|
158
|
-
margin,
|
|
159
|
-
forceDuration,
|
|
160
|
-
forceNormalContainerHeight,
|
|
161
|
-
onComplete
|
|
162
|
-
);
|
|
111
|
+
const scrollFrom = calculateScrollFrom(container, element, maxDistance, forceDirection);
|
|
112
|
+
if (forceDirection === 2) {
|
|
113
|
+
scrollWithJs(container, element, scrollFrom, position, margin, 0);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
scrollWithJs(container, element, scrollFrom, position, margin, forceDuration, forceNormalContainerHeight, onComplete);
|
|
163
117
|
}
|
|
164
118
|
function calculateScrollFrom(container, element, maxDistance = FAST_SMOOTH_MAX_DISTANCE, forceDirection) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
} else if (forceDirection === 0 /* Up */) {
|
|
175
|
-
return elementTop + maxDistance;
|
|
176
|
-
} else if (forceDirection === 1 /* Down */) {
|
|
177
|
-
return Math.max(0, elementTop - maxDistance);
|
|
178
|
-
}
|
|
179
|
-
return scrollTop;
|
|
119
|
+
const { offsetTop: elementTop } = element;
|
|
120
|
+
const { scrollTop } = container;
|
|
121
|
+
if (forceDirection === void 0) {
|
|
122
|
+
const offset = elementTop - container.scrollTop;
|
|
123
|
+
if (offset < -maxDistance) return scrollTop + (offset + maxDistance);
|
|
124
|
+
else if (offset > maxDistance) return scrollTop + (offset - maxDistance);
|
|
125
|
+
} else if (forceDirection === 0) return elementTop + maxDistance;
|
|
126
|
+
else if (forceDirection === 1) return Math.max(0, elementTop - maxDistance);
|
|
127
|
+
return scrollTop;
|
|
180
128
|
}
|
|
181
129
|
function scrollWithJs(container, element, scrollFrom, position, margin = 0, forceDuration, forceNormalContainerHeight, onComplete) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const currentPath = path * (1 - transition(t));
|
|
232
|
-
container.scrollTop = Math.round(target - currentPath);
|
|
233
|
-
if (t > 0) {
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
onComplete?.(container);
|
|
237
|
-
return false;
|
|
238
|
-
});
|
|
239
|
-
});
|
|
130
|
+
const { offsetTop: elementTop, offsetHeight: elementHeight } = element;
|
|
131
|
+
const { scrollTop: currentScrollTop, offsetHeight: containerHeight, scrollHeight } = container;
|
|
132
|
+
const targetContainerHeight = forceNormalContainerHeight && container.dataset.normalHeight ? Number(container.dataset.normalHeight) : containerHeight;
|
|
133
|
+
if (currentScrollTop !== scrollFrom) container.scrollTop = scrollFrom;
|
|
134
|
+
let path;
|
|
135
|
+
switch (position) {
|
|
136
|
+
case "start":
|
|
137
|
+
path = elementTop - margin - scrollFrom;
|
|
138
|
+
break;
|
|
139
|
+
case "end":
|
|
140
|
+
path = elementTop + elementHeight + margin - (scrollFrom + targetContainerHeight);
|
|
141
|
+
break;
|
|
142
|
+
case "nearest":
|
|
143
|
+
case "center":
|
|
144
|
+
case "centerOrTop":
|
|
145
|
+
path = elementHeight < targetContainerHeight ? elementTop + elementHeight / 2 - (scrollFrom + targetContainerHeight / 2) : elementTop - margin - scrollFrom;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
if (path < 0) {
|
|
149
|
+
const remainingPath = -scrollFrom;
|
|
150
|
+
path = Math.max(path, remainingPath);
|
|
151
|
+
} else if (path > 0) {
|
|
152
|
+
const remainingPath = scrollHeight - (scrollFrom + targetContainerHeight);
|
|
153
|
+
path = Math.min(path, remainingPath);
|
|
154
|
+
}
|
|
155
|
+
if (path === 0) {
|
|
156
|
+
onComplete?.(container);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const target = scrollFrom + path;
|
|
160
|
+
if (forceDuration === 0) {
|
|
161
|
+
container.scrollTop = target;
|
|
162
|
+
onComplete?.(container);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const absPath = Math.abs(path);
|
|
166
|
+
const transition = absPath < 500 ? shortTransition : longTransition;
|
|
167
|
+
const duration = forceDuration || 250 + absPath / 1500 * 350;
|
|
168
|
+
const startAt = Date.now();
|
|
169
|
+
fastRaf(() => {
|
|
170
|
+
animateSingle(() => {
|
|
171
|
+
const t = Math.min((Date.now() - startAt) / duration, 1);
|
|
172
|
+
const currentPath = path * (1 - transition(t));
|
|
173
|
+
container.scrollTop = Math.round(target - currentPath);
|
|
174
|
+
if (t > 0) return true;
|
|
175
|
+
onComplete?.(container);
|
|
176
|
+
return false;
|
|
177
|
+
});
|
|
178
|
+
});
|
|
240
179
|
}
|
|
241
180
|
function longTransition(t) {
|
|
242
|
-
|
|
181
|
+
return 1 - (1 - t) ** 5;
|
|
243
182
|
}
|
|
244
183
|
function shortTransition(t) {
|
|
245
|
-
|
|
184
|
+
return 1 - (1 - t) ** 3.5;
|
|
246
185
|
}
|
|
247
|
-
|
|
248
186
|
function isScrolledToDown(target, threshold = 10) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return scrollBottom <= threshold;
|
|
187
|
+
let scrollBottom;
|
|
188
|
+
if (target === defaultDocument) scrollBottom = (defaultDocument?.body?.offsetHeight || 0) - ((defaultWindow?.innerHeight || 0) + (defaultWindow?.scrollY || 0));
|
|
189
|
+
else {
|
|
190
|
+
const el = target;
|
|
191
|
+
scrollBottom = el.scrollHeight - (el.offsetHeight + el.scrollTop);
|
|
192
|
+
}
|
|
193
|
+
return scrollBottom <= threshold;
|
|
257
194
|
}
|
|
258
|
-
|
|
259
195
|
function resetScroll(container, scrollTop) {
|
|
260
|
-
|
|
261
|
-
container.scrollTop = scrollTop;
|
|
262
|
-
}
|
|
196
|
+
if (scrollTop !== void 0) container.scrollTop = scrollTop;
|
|
263
197
|
}
|
|
264
|
-
|
|
265
198
|
export { FAST_SMOOTH_MAX_DISTANCE, FAST_SMOOTH_MAX_DURATION, FAST_SMOOTH_MIN_DURATION, FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE, FocusDirection, animate, animateInstantly, animateNumber, animateSingle, copyTextToClipboard, fastSmoothScroll, isScrolledToDown, resetScroll, timingFunctions };
|
|
266
|
-
|
|
199
|
+
|
|
200
|
+
//# sourceMappingURL=index.mjs.map
|