@fastkit/scroller 0.16.0-next.0 → 0.16.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/scroller.d.ts +820 -0
- package/dist/scroller.mjs +1344 -1285
- package/dist/scroller.mjs.map +1 -1
- package/package.json +8 -9
- package/dist/scroller.d.mts +0 -829
package/dist/scroller.mjs
CHANGED
|
@@ -1,1357 +1,1416 @@
|
|
|
1
|
-
import { EV } from
|
|
2
|
-
import { visibilityManager } from
|
|
3
|
-
import { IN_WINDOW, removeUndef } from
|
|
4
|
-
import { TinyLogger } from
|
|
5
|
-
import BezierEasing from "bezier-easing";
|
|
1
|
+
import { EV } from '@fastkit/ev';
|
|
2
|
+
import { visibilityManager } from '@fastkit/visibility';
|
|
3
|
+
import { IN_WINDOW, removeUndef } from '@fastkit/helpers';
|
|
4
|
+
import { TinyLogger } from '@fastkit/tiny-logger';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
// src/util.ts
|
|
8
7
|
function isDocumentElement(el) {
|
|
9
|
-
|
|
8
|
+
return el.constructor === HTMLHtmlElement;
|
|
10
9
|
}
|
|
11
|
-
function isBodyElement
|
|
12
|
-
|
|
10
|
+
function isBodyElement(el) {
|
|
11
|
+
return el.constructor === HTMLBodyElement;
|
|
13
12
|
}
|
|
13
|
+
var logger = new TinyLogger("scroller");
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/prevent-scroll.ts
|
|
21
|
-
const SCROLLABLE_KEY_CODES = [
|
|
22
|
-
32,
|
|
23
|
-
33,
|
|
24
|
-
34,
|
|
25
|
-
35,
|
|
26
|
-
36,
|
|
27
|
-
37,
|
|
28
|
-
38,
|
|
29
|
-
39,
|
|
30
|
-
40
|
|
31
|
-
];
|
|
32
|
-
const eventListenerOptions = { passive: false };
|
|
33
|
-
const handleWheel = (e) => {
|
|
34
|
-
e.preventDefault();
|
|
15
|
+
// src/prevent-scroll.ts
|
|
16
|
+
var SCROLLABLE_KEY_CODES = [32, 33, 34, 35, 36, 37, 38, 39, 40];
|
|
17
|
+
var eventListenerOptions = {
|
|
18
|
+
passive: false
|
|
35
19
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (el && el.__ps_ctx__) el.scrollTo(el.__ps_ctx__.lockPosition.x, el.__ps_ctx__.lockPosition.y);
|
|
20
|
+
var handleWheel = (e) => {
|
|
21
|
+
e.preventDefault();
|
|
39
22
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
23
|
+
var handleScroll = (e) => {
|
|
24
|
+
const el = e.target;
|
|
25
|
+
if (el && el.__ps_ctx__) {
|
|
26
|
+
el.scrollTo(el.__ps_ctx__.lockPosition.x, el.__ps_ctx__.lockPosition.y);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var handleKeydown = (e) => {
|
|
30
|
+
if (e.target && ["INPUT", "TEXTAREA"].includes(e.target.tagName)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (SCROLLABLE_KEY_CODES.includes(e.which)) {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
}
|
|
43
36
|
};
|
|
44
37
|
function enableScroll(el) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
const _el = el;
|
|
39
|
+
if (!_el.__ps_ctx__) return;
|
|
40
|
+
const { options } = _el.__ps_ctx__;
|
|
41
|
+
_el.removeEventListener("wheel", handleWheel, eventListenerOptions);
|
|
42
|
+
_el.removeEventListener("scroll", handleScroll, eventListenerOptions);
|
|
43
|
+
_el.removeEventListener("keydown", handleKeydown);
|
|
44
|
+
if (options.hideScrollbar) {
|
|
45
|
+
_el.style.overflow = _el.__ps_ctx__.overflowOrigin;
|
|
46
|
+
}
|
|
47
|
+
delete _el.__ps_ctx__;
|
|
53
48
|
}
|
|
54
49
|
function disableScroll(el, opts = {}) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
const { hideScrollbar = false } = opts;
|
|
51
|
+
const _el = el;
|
|
52
|
+
if (_el.__ps_ctx__) return;
|
|
53
|
+
const options = {
|
|
54
|
+
hideScrollbar
|
|
55
|
+
};
|
|
56
|
+
_el.__ps_ctx__ = {
|
|
57
|
+
options,
|
|
58
|
+
el: _el,
|
|
59
|
+
overflowOrigin: _el.style.overflow,
|
|
60
|
+
lockPosition: {
|
|
61
|
+
x: _el.scrollLeft || _el.scrollX,
|
|
62
|
+
y: _el.scrollTop || _el.scrollY
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
if (options.hideScrollbar) {
|
|
66
|
+
_el.style.overflow = "hidden";
|
|
67
|
+
}
|
|
68
|
+
_el.addEventListener("wheel", handleWheel, eventListenerOptions);
|
|
69
|
+
_el.addEventListener("scroll", handleScroll, eventListenerOptions);
|
|
70
|
+
_el.addEventListener("keydown", handleKeydown);
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
cancelable: true
|
|
73
|
+
// src/scroll/schemes.ts
|
|
74
|
+
var defaultBaseSettings = {
|
|
75
|
+
duration: 500,
|
|
76
|
+
easing: "ease",
|
|
77
|
+
cancelable: true
|
|
80
78
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
var defaultSettings = {
|
|
80
|
+
get container() {
|
|
81
|
+
return document.scrollingElement;
|
|
82
|
+
},
|
|
83
|
+
...defaultBaseSettings
|
|
86
84
|
};
|
|
87
85
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
86
|
+
// src/bezier-easing.ts
|
|
87
|
+
function LinearEasing(x) {
|
|
88
|
+
return x;
|
|
89
|
+
}
|
|
90
|
+
var { cbrt, sqrt, PI: \u03C0 } = Math;
|
|
91
|
+
var x2t = (x, a, b, c, d) => {
|
|
92
|
+
const q = a + b * x;
|
|
93
|
+
const s = q ** 2 + c;
|
|
94
|
+
if (s > 0) {
|
|
95
|
+
const root = sqrt(s);
|
|
96
|
+
return cbrt(q + root) + cbrt(q - root) - d;
|
|
97
|
+
}
|
|
98
|
+
const l = cbrt(sqrt(q * q - s));
|
|
99
|
+
const angle = q ? Math.atan(sqrt(-s) / q) : -\u03C0 / 2;
|
|
100
|
+
let \u03C6;
|
|
101
|
+
if (b < 0) {
|
|
102
|
+
\u03C6 = (q > 0 ? 2 * \u03C0 : \u03C0) - angle;
|
|
103
|
+
} else if (d < 0) {
|
|
104
|
+
\u03C6 = (q > 0 ? 2 * \u03C0 : -3 * \u03C0) + angle;
|
|
105
|
+
} else {
|
|
106
|
+
\u03C6 = (q > 0 ? 0 : \u03C0) + angle;
|
|
107
|
+
}
|
|
108
|
+
return 2 * l * Math.cos(\u03C6 / 3) - d;
|
|
109
|
+
};
|
|
110
|
+
var Y = (t, ay, by, cy) => ((ay * t + 3 * by) * t + cy) * t;
|
|
111
|
+
function bezier(mX1, mY1, mX2, mY2) {
|
|
112
|
+
if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) {
|
|
113
|
+
throw new Error("bezier x values must be in [0, 1] range");
|
|
114
|
+
}
|
|
115
|
+
if (mX1 === mY1 && mX2 === mY2) {
|
|
116
|
+
return LinearEasing;
|
|
117
|
+
}
|
|
118
|
+
const a = 6 * (3 * mX1 - 3 * mX2 + 1);
|
|
119
|
+
const b = 6 * (mX2 - 2 * mX1);
|
|
120
|
+
const c = 3 * mX1;
|
|
121
|
+
const a2 = a * a;
|
|
122
|
+
const b2 = b * b;
|
|
123
|
+
const d = b / a;
|
|
124
|
+
const e = 3 * b * c / a2 - b2 * b / (a2 * a);
|
|
125
|
+
const w1 = 2 * c / a - b2 / a2;
|
|
126
|
+
const w = w1 * w1 * w1;
|
|
127
|
+
const o = 3 / a;
|
|
128
|
+
const ay = 3 * mY1 - 3 * mY2 + 1;
|
|
129
|
+
const by = mY2 - 2 * mY1;
|
|
130
|
+
const cy = 3 * mY1;
|
|
131
|
+
const X2T = a ? x2t : LinearEasing;
|
|
132
|
+
return function BezierEasing(x) {
|
|
133
|
+
if (x === 0 || x === 1) {
|
|
134
|
+
return x;
|
|
135
|
+
}
|
|
136
|
+
return Y(X2T(x, e, o, w, d), ay, by, cy);
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/scroll/easings.ts
|
|
141
|
+
var easings = {
|
|
142
|
+
ease: [0.25, 0.1, 0.25, 1],
|
|
143
|
+
linear: [0, 0, 1, 1],
|
|
144
|
+
"ease-in": [0.42, 0, 1, 1],
|
|
145
|
+
"ease-out": [0, 0, 0.58, 1],
|
|
146
|
+
"ease-in-out": [0.42, 0, 0.58, 1]
|
|
121
147
|
};
|
|
122
148
|
var easings_default = easings;
|
|
123
149
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return el.tagName.toLowerCase() === "body";
|
|
150
|
+
// src/scroll/util.ts
|
|
151
|
+
function isBodyElement2(el) {
|
|
152
|
+
return el.tagName.toLowerCase() === "body";
|
|
128
153
|
}
|
|
129
154
|
function getContainerDimension(el) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
155
|
+
if (isBodyElement2(el)) {
|
|
156
|
+
const documentElement = document.documentElement;
|
|
157
|
+
return {
|
|
158
|
+
// width: window.innerWidth,
|
|
159
|
+
// height: window.innerHeight,
|
|
160
|
+
width: documentElement.clientWidth,
|
|
161
|
+
height: documentElement.clientWidth
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
width: el.clientWidth,
|
|
166
|
+
height: el.clientHeight
|
|
167
|
+
};
|
|
141
168
|
}
|
|
142
169
|
function $(selectorOrElement) {
|
|
143
|
-
|
|
144
|
-
|
|
170
|
+
if (typeof selectorOrElement !== "string")
|
|
171
|
+
return selectorOrElement;
|
|
172
|
+
return document.querySelector(selectorOrElement);
|
|
145
173
|
}
|
|
146
174
|
function cumulativeOffset(element) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
175
|
+
let top = 0;
|
|
176
|
+
let left = 0;
|
|
177
|
+
let el = element;
|
|
178
|
+
while (el) {
|
|
179
|
+
top += el.offsetTop || 0;
|
|
180
|
+
left += el.offsetLeft || 0;
|
|
181
|
+
el = el.offsetParent;
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
top,
|
|
185
|
+
left
|
|
186
|
+
};
|
|
159
187
|
}
|
|
160
188
|
function on(element, events, handler, opts = { passive: false }) {
|
|
161
|
-
|
|
162
|
-
|
|
189
|
+
if (!Array.isArray(events)) events = [events];
|
|
190
|
+
for (let i = 0; i < events.length; i++) {
|
|
191
|
+
element.addEventListener(events[i], handler, opts);
|
|
192
|
+
}
|
|
163
193
|
}
|
|
164
194
|
function off(element, events, handler) {
|
|
165
|
-
|
|
166
|
-
|
|
195
|
+
if (!Array.isArray(events)) events = [events];
|
|
196
|
+
for (let i = 0; i < events.length; i++) {
|
|
197
|
+
element.removeEventListener(events[i], handler);
|
|
198
|
+
}
|
|
167
199
|
}
|
|
168
200
|
function error(message) {
|
|
169
|
-
|
|
201
|
+
return new Error(`[scroll] ${message}`);
|
|
170
202
|
}
|
|
171
203
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
"touchmove"
|
|
204
|
+
// src/scroll/scroll-by-internal.ts
|
|
205
|
+
var abortEvents = [
|
|
206
|
+
"mousedown",
|
|
207
|
+
"wheel",
|
|
208
|
+
"DOMMouseScroll",
|
|
209
|
+
"mousewheel",
|
|
210
|
+
"keyup",
|
|
211
|
+
"touchmove"
|
|
181
212
|
];
|
|
182
213
|
function scroll(diffX, diffY, options = {}, _computedValues) {
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
214
|
+
let $container;
|
|
215
|
+
let initialX;
|
|
216
|
+
let initialY;
|
|
217
|
+
let targetX;
|
|
218
|
+
let targetY;
|
|
219
|
+
const _options = { ...defaultSettings, ...removeUndef(options) };
|
|
220
|
+
const {
|
|
221
|
+
container,
|
|
222
|
+
duration,
|
|
223
|
+
easing,
|
|
224
|
+
cancelable,
|
|
225
|
+
onProgress,
|
|
226
|
+
onCancel,
|
|
227
|
+
onDone
|
|
228
|
+
} = _options;
|
|
229
|
+
const x = diffX !== 0;
|
|
230
|
+
const y = diffY !== 0;
|
|
231
|
+
if (_computedValues) {
|
|
232
|
+
$container = _computedValues.$container;
|
|
233
|
+
initialX = _computedValues.initialX;
|
|
234
|
+
initialY = _computedValues.initialY;
|
|
235
|
+
targetX = _computedValues.targetX;
|
|
236
|
+
targetY = _computedValues.targetY;
|
|
237
|
+
} else {
|
|
238
|
+
$container = $(container);
|
|
239
|
+
if (!$container) throw error(`missing container ${container}`);
|
|
240
|
+
initialX = $container.scrollLeft;
|
|
241
|
+
initialY = $container.scrollTop;
|
|
242
|
+
targetX = initialX + diffX;
|
|
243
|
+
targetY = initialY + diffY;
|
|
244
|
+
}
|
|
245
|
+
const { scrollWidth, scrollHeight } = $container;
|
|
246
|
+
const { width, height } = getContainerDimension($container);
|
|
247
|
+
const overflowX = targetX + width - scrollWidth;
|
|
248
|
+
const overflowY = targetY + height - scrollHeight;
|
|
249
|
+
if (overflowX > 0) {
|
|
250
|
+
diffX -= overflowX;
|
|
251
|
+
targetX -= overflowX;
|
|
252
|
+
}
|
|
253
|
+
if (overflowY > 0) {
|
|
254
|
+
diffY -= overflowY;
|
|
255
|
+
targetY -= overflowY;
|
|
256
|
+
}
|
|
257
|
+
let doneResolver;
|
|
258
|
+
let timeStart = 0;
|
|
259
|
+
let timeElapsed;
|
|
260
|
+
const callbackValues = {
|
|
261
|
+
container: $container,
|
|
262
|
+
progress: 0,
|
|
263
|
+
aborted: false,
|
|
264
|
+
abortEventSource: null
|
|
265
|
+
};
|
|
266
|
+
const result = {
|
|
267
|
+
cancel: canceller,
|
|
268
|
+
promise: new Promise((resolve) => {
|
|
269
|
+
doneResolver = resolve;
|
|
270
|
+
}),
|
|
271
|
+
plans: {
|
|
272
|
+
x: diffX,
|
|
273
|
+
y: diffY
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
if (diffY === 0 && diffX === 0 || !!$container.__ps_ctx__)
|
|
277
|
+
return initialAbort();
|
|
278
|
+
let easingValues;
|
|
279
|
+
if (!easing) {
|
|
280
|
+
easingValues = easings_default.ease;
|
|
281
|
+
} else if (typeof easing === "string") {
|
|
282
|
+
easingValues = easings_default[_options.easing];
|
|
283
|
+
} else {
|
|
284
|
+
easingValues = easing;
|
|
285
|
+
}
|
|
286
|
+
const easingFn = bezier.apply(
|
|
287
|
+
bezier,
|
|
288
|
+
easingValues
|
|
289
|
+
);
|
|
290
|
+
on($container, abortEvents, abortFn, { passive: true });
|
|
291
|
+
window.requestAnimationFrame(step);
|
|
292
|
+
return result;
|
|
293
|
+
function doneResolve() {
|
|
294
|
+
doneResolver();
|
|
295
|
+
}
|
|
296
|
+
function canceller(e = null, checkCancelable = false) {
|
|
297
|
+
if (checkCancelable && !cancelable) return;
|
|
298
|
+
off($container, abortEvents, abortFn);
|
|
299
|
+
callbackValues.abortEventSource = e;
|
|
300
|
+
callbackValues.aborted = true;
|
|
301
|
+
onCancel && onCancel(callbackValues);
|
|
302
|
+
}
|
|
303
|
+
function abortFn(e) {
|
|
304
|
+
canceller(e, true);
|
|
305
|
+
}
|
|
306
|
+
function initialAbort(e = null) {
|
|
307
|
+
canceller(e);
|
|
308
|
+
doneResolve();
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
function step(timestamp) {
|
|
312
|
+
if (callbackValues.aborted) return done();
|
|
313
|
+
if (!timeStart) timeStart = timestamp;
|
|
314
|
+
timeElapsed = timestamp - timeStart;
|
|
315
|
+
let progress = Math.min(timeElapsed / duration, 1);
|
|
316
|
+
progress = easingFn(progress);
|
|
317
|
+
callbackValues.progress = progress;
|
|
318
|
+
topLeft(initialY + diffY * progress, initialX + diffX * progress);
|
|
319
|
+
onProgress && onProgress(callbackValues);
|
|
320
|
+
timeElapsed < duration ? window.requestAnimationFrame(step) : done();
|
|
321
|
+
}
|
|
322
|
+
function topLeft(top, left) {
|
|
323
|
+
if (y) $container.scrollTop = top;
|
|
324
|
+
if (x) $container.scrollLeft = left;
|
|
325
|
+
}
|
|
326
|
+
function done() {
|
|
327
|
+
if (!callbackValues.aborted) topLeft(targetY, targetX);
|
|
328
|
+
timeStart = 0;
|
|
329
|
+
off($container, abortEvents, abortFn);
|
|
330
|
+
callbackValues.progress = 1;
|
|
331
|
+
doneResolve();
|
|
332
|
+
if (!callbackValues.aborted && onDone) onDone(callbackValues);
|
|
333
|
+
}
|
|
290
334
|
}
|
|
291
335
|
|
|
292
|
-
|
|
293
|
-
//#region src/scroll/scroll-by.ts
|
|
294
|
-
/**
|
|
295
|
-
* 指定の差分だけコンテナをスクロールします。
|
|
296
|
-
* @param diffX - 横軸の移動量(px)です。デフォルトは0です。
|
|
297
|
-
* @param diffY - 縦軸の移動量(px)です。デフォルトは0です。
|
|
298
|
-
* @param options - スクロールオプション
|
|
299
|
-
*/
|
|
336
|
+
// src/scroll/scroll-by.ts
|
|
300
337
|
function scrollBy(diffX, diffY, options) {
|
|
301
|
-
|
|
338
|
+
return scroll(diffX, diffY, options);
|
|
302
339
|
}
|
|
303
340
|
|
|
304
|
-
|
|
305
|
-
//#region src/scroll/scroll-to.ts
|
|
306
|
-
/**
|
|
307
|
-
* 任意の位置(px)へコンテナをスクロールします。
|
|
308
|
-
* @param scrollPosition - スクロール先を指定します。x, y 共にオプショナルなるです。未指定の軸は現在のスクロール値のまま保持されます。
|
|
309
|
-
* @param options - スクロールオプション
|
|
310
|
-
*/
|
|
341
|
+
// src/scroll/scroll-to.ts
|
|
311
342
|
function scrollTo(scrollPosition, options = {}) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
343
|
+
let { x, y } = scrollPosition;
|
|
344
|
+
const container = options.container || defaultSettings.container;
|
|
345
|
+
const $container = $(container);
|
|
346
|
+
if (!$container) throw error(`missing container ${container}`);
|
|
347
|
+
const initialY = $container.scrollTop;
|
|
348
|
+
const initialX = $container.scrollLeft;
|
|
349
|
+
if (x === void 0) x = initialX;
|
|
350
|
+
if (y === void 0) y = initialY;
|
|
351
|
+
const diffX = x - initialX;
|
|
352
|
+
const diffY = y - initialY;
|
|
353
|
+
return scroll(diffX, diffY, options, {
|
|
354
|
+
$container,
|
|
355
|
+
initialX,
|
|
356
|
+
initialY,
|
|
357
|
+
targetX: x,
|
|
358
|
+
targetY: y
|
|
359
|
+
});
|
|
327
360
|
}
|
|
328
361
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
*/
|
|
335
|
-
const scrollToElementSettingsDefaults = {
|
|
336
|
-
offset: 0,
|
|
337
|
-
x: false,
|
|
338
|
-
y: true
|
|
362
|
+
// src/scroll/scroll-to-element.ts
|
|
363
|
+
var scrollToElementSettingsDefaults = {
|
|
364
|
+
offset: 0,
|
|
365
|
+
x: false,
|
|
366
|
+
y: true
|
|
339
367
|
};
|
|
340
|
-
/**
|
|
341
|
-
* 任意の要素の位置へスクロールします。
|
|
342
|
-
* @param target - スクロール先の要素
|
|
343
|
-
* @param options - スクロールオプション
|
|
344
|
-
*/
|
|
345
368
|
function scrollToElement(target, options = {}) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
initialY,
|
|
371
|
-
targetX,
|
|
372
|
-
targetY
|
|
373
|
-
});
|
|
369
|
+
const _options = { ...scrollToElementSettingsDefaults, ...options };
|
|
370
|
+
const { x, y } = _options;
|
|
371
|
+
const offsetSource = _options.offset;
|
|
372
|
+
const offset = typeof offsetSource === "number" ? { x: offsetSource, y: offsetSource } : offsetSource;
|
|
373
|
+
const $target = $(target);
|
|
374
|
+
if (!$target) throw error(`missing element ${target}`);
|
|
375
|
+
const container = _options.container || defaultSettings.container;
|
|
376
|
+
const $container = $(container);
|
|
377
|
+
if (!$container) throw error(`missing container ${container}`);
|
|
378
|
+
const cumulativeOffsetContainer = cumulativeOffset($container);
|
|
379
|
+
const cumulativeOffsetTarget = cumulativeOffset($target);
|
|
380
|
+
const initialY = $container.scrollTop;
|
|
381
|
+
const initialX = $container.scrollLeft;
|
|
382
|
+
const targetY = cumulativeOffsetTarget.top - cumulativeOffsetContainer.top + (offset.y || 0);
|
|
383
|
+
const targetX = cumulativeOffsetTarget.left - cumulativeOffsetContainer.left + (offset.x || 0);
|
|
384
|
+
const diffX = x ? targetX - initialX : 0;
|
|
385
|
+
const diffY = y ? targetY - initialY : 0;
|
|
386
|
+
return scroll(diffX, diffY, _options, {
|
|
387
|
+
$container,
|
|
388
|
+
initialX,
|
|
389
|
+
initialY,
|
|
390
|
+
targetX,
|
|
391
|
+
targetY
|
|
392
|
+
});
|
|
374
393
|
}
|
|
375
394
|
|
|
376
|
-
|
|
377
|
-
//#region src/scroll/scroll-to-side.ts
|
|
378
|
-
/**
|
|
379
|
-
* コンテナをいずれかの辺までスクロールします。
|
|
380
|
-
* @param targets - 辺を指定します。シングルの文字列、及び配列に対応しています。
|
|
381
|
-
* @param options - スクロールオプション
|
|
382
|
-
*/
|
|
395
|
+
// src/scroll/scroll-to-side.ts
|
|
383
396
|
function scrollToSide(targets, options) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
397
|
+
const sides = typeof targets === "string" ? [targets] : targets;
|
|
398
|
+
const position = {};
|
|
399
|
+
const hasRight = sides.includes("right");
|
|
400
|
+
const hasBottom = sides.includes("bottom");
|
|
401
|
+
if (sides.includes("top")) {
|
|
402
|
+
position.y = 0;
|
|
403
|
+
}
|
|
404
|
+
if (sides.includes("left")) {
|
|
405
|
+
position.x = 0;
|
|
406
|
+
}
|
|
407
|
+
if (hasRight || hasBottom) {
|
|
408
|
+
const container = options && options.container || defaultSettings.container;
|
|
409
|
+
const $container = $(container);
|
|
410
|
+
if (!$container) throw error(`missing container ${container}`);
|
|
411
|
+
if (hasRight) position.x = $container.scrollWidth;
|
|
412
|
+
if (hasBottom) position.y = $container.scrollHeight;
|
|
413
|
+
}
|
|
414
|
+
return scrollTo(position, options);
|
|
398
415
|
}
|
|
399
|
-
/**
|
|
400
|
-
* コンテナを上辺までスクロールします。
|
|
401
|
-
* @param options - スクロールオプション
|
|
402
|
-
*/
|
|
403
416
|
function scrollToTop(options) {
|
|
404
|
-
|
|
417
|
+
return scrollToSide("top", options);
|
|
405
418
|
}
|
|
406
|
-
/**
|
|
407
|
-
* コンテナを右辺までスクロールします。
|
|
408
|
-
* @param options - スクロールオプション
|
|
409
|
-
*/
|
|
410
419
|
function scrollToRight(options) {
|
|
411
|
-
|
|
420
|
+
return scrollToSide("right", options);
|
|
412
421
|
}
|
|
413
|
-
/**
|
|
414
|
-
* コンテナを下辺までスクロールします。
|
|
415
|
-
* @param options - スクロールオプション
|
|
416
|
-
*/
|
|
417
422
|
function scrollToBottom(options) {
|
|
418
|
-
|
|
423
|
+
return scrollToSide("bottom", options);
|
|
419
424
|
}
|
|
420
|
-
/**
|
|
421
|
-
* コンテナを左辺までスクロールします。
|
|
422
|
-
* @param options - スクロールオプション
|
|
423
|
-
*/
|
|
424
425
|
function scrollToLeft(options) {
|
|
425
|
-
|
|
426
|
+
return scrollToSide("left", options);
|
|
426
427
|
}
|
|
427
|
-
/**
|
|
428
|
-
* コンテナを左上コーナーまでスクロールします。
|
|
429
|
-
* @param options - スクロールオプション
|
|
430
|
-
*/
|
|
431
428
|
function scrollToLeftTop(options) {
|
|
432
|
-
|
|
429
|
+
return scrollToSide(["left", "top"], options);
|
|
433
430
|
}
|
|
434
|
-
/**
|
|
435
|
-
* コンテナを左下コーナーまでスクロールします。
|
|
436
|
-
* @param options - スクロールオプション
|
|
437
|
-
*/
|
|
438
431
|
function scrollToLeftBottom(options) {
|
|
439
|
-
|
|
432
|
+
return scrollToSide(["left", "bottom"], options);
|
|
440
433
|
}
|
|
441
|
-
/**
|
|
442
|
-
* コンテナを右上コーナーまでスクロールします。
|
|
443
|
-
* @param options - スクロールオプション
|
|
444
|
-
*/
|
|
445
434
|
function scrollToRightTop(options) {
|
|
446
|
-
|
|
435
|
+
return scrollToSide(["right", "top"], options);
|
|
447
436
|
}
|
|
448
|
-
/**
|
|
449
|
-
* コンテナを右下コーナーまでスクロールします。
|
|
450
|
-
* @param options - スクロールオプション
|
|
451
|
-
*/
|
|
452
437
|
function scrollToRightBottom(options) {
|
|
453
|
-
|
|
438
|
+
return scrollToSide(["right", "bottom"], options);
|
|
454
439
|
}
|
|
455
440
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
"scrollEnabled",
|
|
487
|
-
"containerWidth",
|
|
488
|
-
"containerHeight",
|
|
489
|
-
"scrollWidth",
|
|
490
|
-
"scrollHeight",
|
|
491
|
-
"scrollableX",
|
|
492
|
-
"scrollableY",
|
|
493
|
-
"scrollTop",
|
|
494
|
-
"scrollLeft",
|
|
495
|
-
"scrollRight",
|
|
496
|
-
"scrollBottom",
|
|
497
|
-
"lastAxis",
|
|
498
|
-
"lastDirection",
|
|
499
|
-
"lastYDirection",
|
|
500
|
-
"lastXDirection",
|
|
501
|
-
"nowScrolling"
|
|
441
|
+
// src/scroller.ts
|
|
442
|
+
var ScrollerState = /* @__PURE__ */ ((ScrollerState2) => {
|
|
443
|
+
ScrollerState2["Pending"] = "pending";
|
|
444
|
+
ScrollerState2["Ready"] = "ready";
|
|
445
|
+
ScrollerState2["Running"] = "running";
|
|
446
|
+
ScrollerState2["Destroyed"] = "destroyed";
|
|
447
|
+
return ScrollerState2;
|
|
448
|
+
})(ScrollerState || {});
|
|
449
|
+
var scrollerObservableKeys = [
|
|
450
|
+
"state",
|
|
451
|
+
"isPending",
|
|
452
|
+
"isReady",
|
|
453
|
+
"isRunning",
|
|
454
|
+
"isDestroyed",
|
|
455
|
+
"scrollEnabled",
|
|
456
|
+
"containerWidth",
|
|
457
|
+
"containerHeight",
|
|
458
|
+
"scrollWidth",
|
|
459
|
+
"scrollHeight",
|
|
460
|
+
"scrollableX",
|
|
461
|
+
"scrollableY",
|
|
462
|
+
"scrollTop",
|
|
463
|
+
"scrollLeft",
|
|
464
|
+
"scrollRight",
|
|
465
|
+
"scrollBottom",
|
|
466
|
+
"lastAxis",
|
|
467
|
+
"lastDirection",
|
|
468
|
+
"lastYDirection",
|
|
469
|
+
"lastXDirection",
|
|
470
|
+
"nowScrolling"
|
|
502
471
|
];
|
|
503
|
-
/**
|
|
504
|
-
* 任意のElement(or HTML Document)のスクロールやサイズ変更を監視し、その情報を通知するクラスです。<br>
|
|
505
|
-
* <a href="https://dadajam4.github.io/dadajam4/ev/classes/_ev_.ev.html" target="_blank">EV</a>を継承しており、イベントの購読[[Scroller.on]]等のインターフェースを利用するか、
|
|
506
|
-
* [[Scroller.observe]]メソッドを利用します。<br>
|
|
507
|
-
* [[Scroller.on]]、[[Scroller.once]]で購読可能なイベントについては[[ScrollerEventMap]]を参照してください。
|
|
508
|
-
*/
|
|
509
472
|
var Scroller = class extends EV {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
473
|
+
/**
|
|
474
|
+
* Scrollerクラスの状態を監視&同期するオブジェクトが
|
|
475
|
+
* 保有すべきプロパティ一のキーの配列です。
|
|
476
|
+
*/
|
|
477
|
+
static scrollerObservableKeys = scrollerObservableKeys;
|
|
478
|
+
/**
|
|
479
|
+
* Scrollerの状態を示すenum値です。
|
|
480
|
+
* {@link ScrollerState}
|
|
481
|
+
*/
|
|
482
|
+
static States = ScrollerState;
|
|
483
|
+
/**
|
|
484
|
+
* スクロールを検知してから、移動がなくなった際に、何ms後にスクロール終了と判定するかのインターバル値を示します。
|
|
485
|
+
* デフォルトは500です。
|
|
486
|
+
*/
|
|
487
|
+
scrollingJudgeInterval = 500;
|
|
488
|
+
/**
|
|
489
|
+
* 縦、横のどちらのスクロールを基準とするかを示します。
|
|
490
|
+
* デフォルトはyです。<br>
|
|
491
|
+
* この設定は[[Scroller.toElement]]のデフォルト値にも影響します。
|
|
492
|
+
*/
|
|
493
|
+
baseAxis = "y";
|
|
494
|
+
/**
|
|
495
|
+
* スクロール系メソッド[[Scroller.to]]等を利用する際のデフォルトの設定を示します。
|
|
496
|
+
*/
|
|
497
|
+
scrollSettingsDefaults = { ...defaultBaseSettings };
|
|
498
|
+
/**
|
|
499
|
+
* [[Scroller.toElement]]のデフォルトオプションの設定を示します。
|
|
500
|
+
*/
|
|
501
|
+
scrollToElementSettingsDefaults = {
|
|
502
|
+
...scrollToElementSettingsDefaults
|
|
503
|
+
};
|
|
504
|
+
scrollSizeObserver;
|
|
505
|
+
/**
|
|
506
|
+
* 設定されたElement要素です。
|
|
507
|
+
* 初期化が完了していない時には本getterはundefinedを返却する事に注意してください。
|
|
508
|
+
*/
|
|
509
|
+
get el() {
|
|
510
|
+
return this._el;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* 現在の状態です。<br>
|
|
514
|
+
* {@link ScrollerState}
|
|
515
|
+
*/
|
|
516
|
+
get state() {
|
|
517
|
+
return this._state;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* 未初期化である場合trueを示します。
|
|
521
|
+
*/
|
|
522
|
+
get isPending() {
|
|
523
|
+
return this._state === "pending" /* Pending */;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* 初期化済み&停止状態である場合trueを示します。
|
|
527
|
+
*/
|
|
528
|
+
get isReady() {
|
|
529
|
+
return this._state === "ready" /* Ready */;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* 初期化済み&動作中である場合trueを示します。
|
|
533
|
+
*/
|
|
534
|
+
get isRunning() {
|
|
535
|
+
return this._state === "running" /* Running */;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* インスタンスが破棄済みである場合trueを示します。
|
|
539
|
+
*/
|
|
540
|
+
get isDestroyed() {
|
|
541
|
+
return this._state === "destroyed" /* Destroyed */;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* スクロールの有効状態を取得します
|
|
545
|
+
*/
|
|
546
|
+
get scrollEnabled() {
|
|
547
|
+
return this._scrollStoppers.length === 0;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* スクロール要素の幅を示します。
|
|
551
|
+
*/
|
|
552
|
+
get containerWidth() {
|
|
553
|
+
return this._containerWidth;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* スクロール要素の高さを示します。
|
|
557
|
+
*/
|
|
558
|
+
get containerHeight() {
|
|
559
|
+
return this._containerHeight;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* スクロール要素内のコンテンツの幅を示します。
|
|
563
|
+
*/
|
|
564
|
+
get scrollWidth() {
|
|
565
|
+
return this._scrollWidth;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* スクロール要素内のコンテンツの高さを示します。
|
|
569
|
+
*/
|
|
570
|
+
get scrollHeight() {
|
|
571
|
+
return this._scrollHeight;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* x軸にスクロール可能な場合trueを示します
|
|
575
|
+
*/
|
|
576
|
+
get scrollableX() {
|
|
577
|
+
return this._scrollWidth > this._containerWidth;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* y軸にスクロール可能な場合trueを示します
|
|
581
|
+
*/
|
|
582
|
+
get scrollableY() {
|
|
583
|
+
return this._scrollHeight > this._containerHeight;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* 現在の上辺からのスクロール量を示します。
|
|
587
|
+
*/
|
|
588
|
+
get scrollTop() {
|
|
589
|
+
return this._scrollTop;
|
|
590
|
+
}
|
|
591
|
+
set scrollTop(scrollTop) {
|
|
592
|
+
if (!this.el) return;
|
|
593
|
+
this.el.scrollTop = scrollTop;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* 現在の右辺からのスクロール量を示します。
|
|
597
|
+
*/
|
|
598
|
+
get scrollRight() {
|
|
599
|
+
return this._scrollRight;
|
|
600
|
+
}
|
|
601
|
+
set scrollRight(scrollRight) {
|
|
602
|
+
if (!this.el) return;
|
|
603
|
+
this.el.scrollLeft = this._scrollWidth - this._containerWidth - scrollRight;
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* 現在の下辺からのスクロール量を示します。
|
|
607
|
+
*/
|
|
608
|
+
get scrollBottom() {
|
|
609
|
+
return this._scrollBottom;
|
|
610
|
+
}
|
|
611
|
+
set scrollBottom(scrollBottom) {
|
|
612
|
+
if (!this.el) return;
|
|
613
|
+
this.el.scrollTop = this._scrollHeight - this._containerHeight - scrollBottom;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* 現在の左辺からのスクロール量を示します。
|
|
617
|
+
*/
|
|
618
|
+
get scrollLeft() {
|
|
619
|
+
return this._scrollLeft;
|
|
620
|
+
}
|
|
621
|
+
set scrollLeft(scrollLeft) {
|
|
622
|
+
if (!this.el) return;
|
|
623
|
+
this.el.scrollLeft = scrollLeft;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* 現在スクロール中である場合trueを示します。
|
|
627
|
+
*/
|
|
628
|
+
get nowScrolling() {
|
|
629
|
+
return this._nowScrolling;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* 最後に検知したスクロールの軸を示します。
|
|
633
|
+
*/
|
|
634
|
+
get lastAxis() {
|
|
635
|
+
return this._lastAxis;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* 最後に検知したスクロールの方向を示します。
|
|
639
|
+
*/
|
|
640
|
+
get lastDirection() {
|
|
641
|
+
return this._lastDirection;
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* 最後に検知したスクロールの垂直方向を示します。
|
|
645
|
+
*/
|
|
646
|
+
get lastYDirection() {
|
|
647
|
+
return this._lastYDirection;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* 最後に検知したスクロールの水平方向を示します。
|
|
651
|
+
*/
|
|
652
|
+
get lastXDirection() {
|
|
653
|
+
return this._lastXDirection;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* 最後に検知したスクロールにより通知した情報を示します。
|
|
657
|
+
*/
|
|
658
|
+
get lastPayload() {
|
|
659
|
+
return {
|
|
660
|
+
top: this._scrollTop,
|
|
661
|
+
left: this._scrollLeft,
|
|
662
|
+
bottom: this._scrollBottom,
|
|
663
|
+
right: this._scrollRight,
|
|
664
|
+
axis: this._lastAxis,
|
|
665
|
+
direction: this._lastDirection,
|
|
666
|
+
directionX: this._lastXDirection,
|
|
667
|
+
directionY: this._lastYDirection,
|
|
668
|
+
tickedX: this._tickedX,
|
|
669
|
+
tickedY: this._tickedY,
|
|
670
|
+
totalX: this._lastTotalX,
|
|
671
|
+
totalY: this._lastTotalY
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
_el;
|
|
675
|
+
_eventTarget;
|
|
676
|
+
_isDocumentElement = false;
|
|
677
|
+
_isBodyElement = false;
|
|
678
|
+
_isRootElement = false;
|
|
679
|
+
_state = "pending" /* Pending */;
|
|
680
|
+
_containerWidth = 0;
|
|
681
|
+
_containerHeight = 0;
|
|
682
|
+
_scrollWidth = 0;
|
|
683
|
+
_scrollHeight = 0;
|
|
684
|
+
_scrollTop = 0;
|
|
685
|
+
_scrollRight = 0;
|
|
686
|
+
_scrollBottom = 0;
|
|
687
|
+
_scrollLeft = 0;
|
|
688
|
+
_lastAxis;
|
|
689
|
+
_lastDirection;
|
|
690
|
+
_lastYDirection = "top";
|
|
691
|
+
_lastXDirection = "left";
|
|
692
|
+
_nowScrolling = false;
|
|
693
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
694
|
+
_readyResolvers = [];
|
|
695
|
+
_scrollingJudgeTimerId = null;
|
|
696
|
+
_startX = 0;
|
|
697
|
+
_startY = 0;
|
|
698
|
+
_tickedX = 0;
|
|
699
|
+
_tickedY = 0;
|
|
700
|
+
_lastTotalX = 0;
|
|
701
|
+
_lastTotalY = 0;
|
|
702
|
+
_scrollListener;
|
|
703
|
+
_resizeListener;
|
|
704
|
+
_resizeObserver;
|
|
705
|
+
_scrollToResult = null;
|
|
706
|
+
_observers = [];
|
|
707
|
+
_scrollStoppers = [];
|
|
708
|
+
_scrollSizeObserverPollingId = null;
|
|
709
|
+
_scrollSizeObserverSuspended = false;
|
|
710
|
+
_visibilityListener;
|
|
711
|
+
/**
|
|
712
|
+
* Scrollerインスタンスを作成します。
|
|
713
|
+
* コンテキストとなるElementをこの時点で指定するか否かは任意です。
|
|
714
|
+
*
|
|
715
|
+
* @param settingOrElementOrQueryString - 任意です。{@link ScrollerSetting}か Element(or cssクエリセレクタ文字列)を直接指定します。この時点でElementを指定しない場合は、[[setElement]]を実行するまでインスタンスは動作しません。
|
|
716
|
+
*/
|
|
717
|
+
constructor(settingOrElementOrQueryString = {}) {
|
|
718
|
+
super();
|
|
719
|
+
const convertedSetting = typeof settingOrElementOrQueryString === "string" || settingOrElementOrQueryString === null || IN_WINDOW && settingOrElementOrQueryString instanceof Element ? settingOrElementOrQueryString = {
|
|
720
|
+
el: settingOrElementOrQueryString
|
|
721
|
+
} : settingOrElementOrQueryString;
|
|
722
|
+
if (convertedSetting.scrollingJudgeInterval !== void 0)
|
|
723
|
+
this.scrollingJudgeInterval = convertedSetting.scrollingJudgeInterval;
|
|
724
|
+
if (convertedSetting.baseAxis) this.baseAxis = convertedSetting.baseAxis;
|
|
725
|
+
this._lastAxis = this.baseAxis;
|
|
726
|
+
const { scrollSizeObserver } = convertedSetting;
|
|
727
|
+
if (scrollSizeObserver) {
|
|
728
|
+
this.scrollSizeObserver = {
|
|
729
|
+
interval: 500,
|
|
730
|
+
width: true,
|
|
731
|
+
height: true,
|
|
732
|
+
...scrollSizeObserver
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
this._visibilityListener = () => {
|
|
736
|
+
if (visibilityManager.isVisible) {
|
|
737
|
+
this.update();
|
|
738
|
+
if (this._scrollSizeObserverSuspended) {
|
|
739
|
+
this._scrollSizeObserverSuspended = false;
|
|
740
|
+
this._startScrollSizeObserver();
|
|
741
|
+
}
|
|
742
|
+
} else {
|
|
743
|
+
this._scrollSizeObserverSuspended = this._scrollSizeObserverPollingId !== null;
|
|
744
|
+
this._stopScrollSizeObserver();
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
this._lastDirection = this._lastAxis === "y" ? "top" : "left";
|
|
748
|
+
if (!IN_WINDOW) return;
|
|
749
|
+
visibilityManager.change(this._visibilityListener);
|
|
750
|
+
this.setElement(convertedSetting.el);
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* インスタンスにElementを設定します。特別な理由(SSRの利用等)によりコンストラクタでElementを指定できない場合、
|
|
754
|
+
* 本メソッドを利用しブラウザコンテキスト配下で本メソッドを実行してください。
|
|
755
|
+
* @param el - Element、もしくはCSSクエリセレクタ文字列を指定します。
|
|
756
|
+
*/
|
|
757
|
+
setElement(el) {
|
|
758
|
+
if (el === null) return;
|
|
759
|
+
if (!IN_WINDOW)
|
|
760
|
+
logger.error("Element can be set only when it is under DOM context.");
|
|
761
|
+
this.stop();
|
|
762
|
+
let _el;
|
|
763
|
+
if (typeof el === "string") {
|
|
764
|
+
_el = document.querySelector(el);
|
|
765
|
+
} else {
|
|
766
|
+
_el = el || document.scrollingElement;
|
|
767
|
+
}
|
|
768
|
+
if (!_el) {
|
|
769
|
+
const message = "missing scrolling element";
|
|
770
|
+
logger.error(message, el);
|
|
771
|
+
throw new Error(message);
|
|
772
|
+
}
|
|
773
|
+
this._el = _el;
|
|
774
|
+
this._isDocumentElement = isDocumentElement(_el);
|
|
775
|
+
this._isBodyElement = isBodyElement(_el);
|
|
776
|
+
this._isRootElement = this._isDocumentElement || this._isBodyElement;
|
|
777
|
+
this._eventTarget = this._isDocumentElement || this._isBodyElement ? window : this._el;
|
|
778
|
+
this._setup();
|
|
779
|
+
}
|
|
780
|
+
_scrollToElementAdditionalOffset;
|
|
781
|
+
setScrollToElementAdditionalOffset(offset) {
|
|
782
|
+
this._scrollToElementAdditionalOffset = offset;
|
|
783
|
+
}
|
|
784
|
+
deleteScrollToElementAdditionalOffset() {
|
|
785
|
+
delete this._scrollToElementAdditionalOffset;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* インスタンスが実行可能になった際にresolveされるPromiseインスタンスを返却します。
|
|
789
|
+
*/
|
|
790
|
+
ready() {
|
|
791
|
+
this._checkDestroyed();
|
|
792
|
+
if (!this.isPending) return Promise.resolve();
|
|
793
|
+
return new Promise((resolve) => this._readyResolvers.push(resolve));
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* インスタンスの動作を開始します。本インスタンスはElementが設定され初期化された際に自動で動作を開始しますが、
|
|
797
|
+
* [[Scroller.stop]]メソッドを利用し動作を停止した後に再開する場合に本メソッドを利用します。
|
|
798
|
+
*/
|
|
799
|
+
async start() {
|
|
800
|
+
this._checkDestroyed();
|
|
801
|
+
if (this.isRunning) return;
|
|
802
|
+
await this.ready();
|
|
803
|
+
this._startListeners();
|
|
804
|
+
this._setState("running" /* Running */);
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* インスタンスの動作(スクロール、リサイズイベントの検知等)を停止します。
|
|
808
|
+
* 何らかの理由で動作を停止させたい場合に利用してください。
|
|
809
|
+
* 本メソッドを実行後もインスタンス内の状態は保持されたままです。
|
|
810
|
+
* 完全にインスタンスを破棄するためには[[Scroller.destroy]]を利用してください。
|
|
811
|
+
*/
|
|
812
|
+
stop() {
|
|
813
|
+
this._checkDestroyed();
|
|
814
|
+
if (!this.isRunning) return;
|
|
815
|
+
this._stopListeners();
|
|
816
|
+
this._setState("ready" /* Ready */);
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* インスタンスの動作を停止し、内部情報を完全に破棄します。
|
|
820
|
+
* これに伴い、スクロール中であった場合にはキャンセルされ、以後イベント通知は完全に行われません。
|
|
821
|
+
* また[[Scroller.start]]メソッドでの再利用も不可となります。
|
|
822
|
+
* 本インスタンスの利用を完全に停止する場合に必ず実行し、利用側のオブジェクト等において本インスタンスへの参照を完全に削除してください。
|
|
823
|
+
* 本メソッドはSPA等でのサービスにおいては意識的に実行する事を強く推奨します。
|
|
824
|
+
*/
|
|
825
|
+
destroy() {
|
|
826
|
+
if (this.isDestroyed) return;
|
|
827
|
+
this.stop();
|
|
828
|
+
this.cancel();
|
|
829
|
+
this._readyResolvers = [];
|
|
830
|
+
this._scrollStoppers = [];
|
|
831
|
+
this._scrollEnable();
|
|
832
|
+
this._observers = [];
|
|
833
|
+
visibilityManager.remove(this._visibilityListener);
|
|
834
|
+
delete this._el;
|
|
835
|
+
delete this._eventTarget;
|
|
836
|
+
delete this._scrollListener;
|
|
837
|
+
delete this._resizeListener;
|
|
838
|
+
delete this._resizeObserver;
|
|
839
|
+
delete this._scrollToResult;
|
|
840
|
+
delete this._visibilityListener;
|
|
841
|
+
this.deleteScrollToElementAdditionalOffset();
|
|
842
|
+
this._setState("destroyed" /* Destroyed */);
|
|
843
|
+
this.offAll();
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* インスタンス内部のスクロール量や、Elementのサイズを強制的に更新します。
|
|
847
|
+
* 基本的に利用が必要なケースはありませんが、何らかの理由で更新をトリガーしたい場合に利用します。
|
|
848
|
+
*/
|
|
849
|
+
update() {
|
|
850
|
+
this._update();
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* インスタンス内の情報をjsonオブジェクトとして返却します。
|
|
854
|
+
* 情報の詳細は[[ScrollerObserver]]を参照してください。
|
|
855
|
+
*/
|
|
856
|
+
toJSON() {
|
|
857
|
+
const json = {};
|
|
858
|
+
for (const key of scrollerObservableKeys) {
|
|
859
|
+
json[key] = this[key];
|
|
860
|
+
}
|
|
861
|
+
return json;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* [[Scroller.toJSON]]の情報を文字列として返却します。
|
|
865
|
+
*/
|
|
866
|
+
toString() {
|
|
867
|
+
return JSON.stringify(this.toJSON());
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* 本インスタンスの情報を購読するためのオブジェクトを設定する事で、
|
|
871
|
+
* インスタンスの内部情報が変更される度にパラメータが同期されます。
|
|
872
|
+
* 設定するオブジェクトは[[ScrollerObserver]]のインターフェースを満たしていれば内容は問いません。
|
|
873
|
+
* 本機能により同期される方法は単純にオブジェクトプロパティへの変数代入です。
|
|
874
|
+
* 従って対象となるプロパティをgetterとして実装(Ex: Vue computed等、、)しておく事により、
|
|
875
|
+
* 同期を受け取るオブジェクト側でパラメータ変更後の動作をリアクティブに実装可能です。
|
|
876
|
+
* @param observer - 同期させたいオブジェクト
|
|
877
|
+
* @returns 同期を停止するためのメソッド
|
|
878
|
+
*/
|
|
879
|
+
observe(observer) {
|
|
880
|
+
if (!this._observers.includes(observer)) {
|
|
881
|
+
this._observers.push(observer);
|
|
882
|
+
}
|
|
883
|
+
this._syncToObserver(observer);
|
|
884
|
+
const unobserve = () => {
|
|
885
|
+
this.unobserve(observer);
|
|
886
|
+
};
|
|
887
|
+
return unobserve;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* [[Scroller.observe]]でパラメータ同期中のオブジェクトを停止します。
|
|
891
|
+
* [[Scroller.destroy]]実行時にも、同期中のオブジェクトは全停止されますが、destroy前に任意のタイミングで停止したい場合
|
|
892
|
+
* 本メソッドを利用します。
|
|
893
|
+
* @param observer - 同期中のオブジェクト
|
|
894
|
+
*/
|
|
895
|
+
unobserve(observer) {
|
|
896
|
+
const index = this._observers.indexOf(observer);
|
|
897
|
+
if (index !== -1) {
|
|
898
|
+
this._observers.splice(index, 1);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* スクロール中であった場合、スクロールをキャンセルします。
|
|
903
|
+
*/
|
|
904
|
+
cancel() {
|
|
905
|
+
if (!this._scrollToResult) return;
|
|
906
|
+
this._scrollToResult.cancel();
|
|
907
|
+
this._clearScrollToResult();
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* x, yの差分pxを指定しスクロールします。
|
|
911
|
+
* メソッド、パラメータの詳細は[[scrollBy]]を参照してください。
|
|
912
|
+
* @param diffX - 横移動量
|
|
913
|
+
* @param diffY - 縦移動量
|
|
914
|
+
* @param options - スクロールオプション
|
|
915
|
+
*/
|
|
916
|
+
by(diffX, diffY, options) {
|
|
917
|
+
return this._setScrollToResult(
|
|
918
|
+
scrollBy(diffX, diffY, this._createMergedScrollOptions(options))
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* 指定の座標へスクロールします。
|
|
923
|
+
* メソッド、パラメータの詳細は[[scrollTo]]を参照してください。
|
|
924
|
+
* @param scrollPosition - 座標
|
|
925
|
+
* @param options - スクロールオプション
|
|
926
|
+
*/
|
|
927
|
+
to(scrollPosition, options) {
|
|
928
|
+
return this._setScrollToResult(
|
|
929
|
+
scrollTo(scrollPosition, this._createMergedScrollOptions(options))
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* 指定の要素の位置へスクロールします。
|
|
934
|
+
* メソッド、パラメータの詳細は[[scrollToElement]]を参照してください。
|
|
935
|
+
* オプションのx, yが未設定であった場合、[[Scroller.baseAxis]]により自動設定されます。
|
|
936
|
+
* @param target - スクロール先の要素
|
|
937
|
+
* @param options - スクロールオプション
|
|
938
|
+
*/
|
|
939
|
+
toElement(target, options) {
|
|
940
|
+
const merged = this._createMergedScrollToElementOptions(options);
|
|
941
|
+
if (merged.x === void 0) merged.x = this.baseAxis === "x";
|
|
942
|
+
if (merged.y === void 0) merged.y = this.baseAxis === "y";
|
|
943
|
+
return this._setScrollToResult(scrollToElement(target, merged));
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* 指定の辺へスクロールします。
|
|
947
|
+
* メソッド、パラメータの詳細は[[scrollToSide]]を参照してください。
|
|
948
|
+
* @param targets - スクロール先
|
|
949
|
+
* @param options - スクロールオプション
|
|
950
|
+
*/
|
|
951
|
+
toSide(targets, options) {
|
|
952
|
+
return this._setScrollToResult(
|
|
953
|
+
scrollToSide(targets, this._createMergedScrollOptions(options))
|
|
954
|
+
);
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* 上辺へスクロールします。
|
|
958
|
+
* メソッド、パラメータの詳細は[[scrollToTop]]を参照してください。
|
|
959
|
+
* @param options - スクロールオプション
|
|
960
|
+
*/
|
|
961
|
+
toTop(options) {
|
|
962
|
+
return this._setScrollToResult(
|
|
963
|
+
scrollToTop(this._createMergedScrollOptions(options))
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* 右辺へスクロールします。
|
|
968
|
+
* メソッド、パラメータの詳細は[[scrollToRight]]を参照してください。
|
|
969
|
+
* @param options - スクロールオプション
|
|
970
|
+
*/
|
|
971
|
+
toRight(options) {
|
|
972
|
+
return this._setScrollToResult(
|
|
973
|
+
scrollToRight(this._createMergedScrollOptions(options))
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* 下辺へスクロールします。
|
|
978
|
+
* メソッド、パラメータの詳細は[[scrollToBottom]]を参照してください。
|
|
979
|
+
* @param options - スクロールオプション
|
|
980
|
+
*/
|
|
981
|
+
toBottom(options) {
|
|
982
|
+
return this._setScrollToResult(
|
|
983
|
+
scrollToBottom(this._createMergedScrollOptions(options))
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* 左辺へスクロールします。
|
|
988
|
+
* メソッド、パラメータの詳細は[[scrollToLeft]]を参照してください。
|
|
989
|
+
* @param options - スクロールオプション
|
|
990
|
+
*/
|
|
991
|
+
toLeft(options) {
|
|
992
|
+
return this._setScrollToResult(
|
|
993
|
+
scrollToLeft(this._createMergedScrollOptions(options))
|
|
994
|
+
);
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* 左上コーナーへスクロールします。
|
|
998
|
+
* メソッド、パラメータの詳細は[[scrollToLeftTop]]を参照してください。
|
|
999
|
+
* @param options - スクロールオプション
|
|
1000
|
+
*/
|
|
1001
|
+
toLeftTop(options) {
|
|
1002
|
+
return this._setScrollToResult(
|
|
1003
|
+
scrollToLeftTop(this._createMergedScrollOptions(options))
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* 左下コーナーへスクロールします。
|
|
1008
|
+
* メソッド、パラメータの詳細は[[scrollToLeftBottom]]を参照してください。
|
|
1009
|
+
* @param options - スクロールオプション
|
|
1010
|
+
*/
|
|
1011
|
+
toLeftBottom(options) {
|
|
1012
|
+
return this._setScrollToResult(
|
|
1013
|
+
scrollToLeftBottom(this._createMergedScrollOptions(options))
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* 右上コーナーへスクロールします。
|
|
1018
|
+
* メソッド、パラメータの詳細は[[scrollToRightTop]]を参照してください。
|
|
1019
|
+
* @param options - スクロールオプション
|
|
1020
|
+
*/
|
|
1021
|
+
toRightTop(options) {
|
|
1022
|
+
return this._setScrollToResult(
|
|
1023
|
+
scrollToRightTop(this._createMergedScrollOptions(options))
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* 右下コーナーへスクロールします。
|
|
1028
|
+
* メソッド、パラメータの詳細は[[scrollToRightBottom]]を参照してください。
|
|
1029
|
+
* @param options - スクロールオプション
|
|
1030
|
+
*/
|
|
1031
|
+
toRightBottom(options) {
|
|
1032
|
+
return this._setScrollToResult(
|
|
1033
|
+
scrollToRightBottom(this._createMergedScrollOptions(options))
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* スクロールの停止を要求します。
|
|
1038
|
+
* @param stopper - 停止要求ソース
|
|
1039
|
+
*/
|
|
1040
|
+
pushScrollStopper(stopper) {
|
|
1041
|
+
if (!this._scrollStoppers.includes(stopper)) {
|
|
1042
|
+
this._scrollStoppers.push(stopper);
|
|
1043
|
+
if (this._scrollStoppers.length === 1) {
|
|
1044
|
+
this._updateScrollable();
|
|
1045
|
+
this._syncToObservers(["scrollEnabled"]);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return () => {
|
|
1049
|
+
this.removeScrollStopper(stopper);
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* スクロールの停止要求を解除します。<br>
|
|
1054
|
+
* 別のプロセスにより異なる[[ScrollStopper]]が登録されている場合、
|
|
1055
|
+
* スクロールは再開されない事に注意してください。
|
|
1056
|
+
* @param stopper - 停止要求ソース
|
|
1057
|
+
*/
|
|
1058
|
+
removeScrollStopper(stopper) {
|
|
1059
|
+
const index = this._scrollStoppers.indexOf(stopper);
|
|
1060
|
+
if (index !== -1) {
|
|
1061
|
+
this._scrollStoppers.splice(index, 1);
|
|
1062
|
+
if (this._scrollStoppers.length === 0) {
|
|
1063
|
+
this._updateScrollable();
|
|
1064
|
+
this._syncToObservers(["scrollEnabled"]);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
async _setup() {
|
|
1069
|
+
this._updateScrollable();
|
|
1070
|
+
this._update();
|
|
1071
|
+
this._setState("ready" /* Ready */);
|
|
1072
|
+
this.start();
|
|
1073
|
+
this.emit("ready", void 0);
|
|
1074
|
+
this._readyResolvers.forEach((resolve) => resolve());
|
|
1075
|
+
this._readyResolvers = [];
|
|
1076
|
+
}
|
|
1077
|
+
_setState(state) {
|
|
1078
|
+
if (this._state !== state) {
|
|
1079
|
+
this._state = state;
|
|
1080
|
+
this._syncToObservers([
|
|
1081
|
+
"state",
|
|
1082
|
+
"isPending",
|
|
1083
|
+
"isReady",
|
|
1084
|
+
"isRunning",
|
|
1085
|
+
"isDestroyed"
|
|
1086
|
+
]);
|
|
1087
|
+
this.emit("changeState", state);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
_checkDestroyed() {
|
|
1091
|
+
if (this.isDestroyed) {
|
|
1092
|
+
const message = "already destroyed.";
|
|
1093
|
+
logger.error(message);
|
|
1094
|
+
throw new Error(message);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
_update(width, height) {
|
|
1098
|
+
this._updateContainerSize(width, height);
|
|
1099
|
+
this._updateScrollSize();
|
|
1100
|
+
this._updateScrollPositions();
|
|
1101
|
+
}
|
|
1102
|
+
_updateContainerSize(width, height) {
|
|
1103
|
+
const { el, _isBodyElement } = this;
|
|
1104
|
+
if (width === void 0) {
|
|
1105
|
+
if (!el) return;
|
|
1106
|
+
width = _isBodyElement ? document.documentElement.clientWidth : el.clientWidth;
|
|
1107
|
+
}
|
|
1108
|
+
if (height === void 0) {
|
|
1109
|
+
if (!el) return;
|
|
1110
|
+
height = _isBodyElement ? document.documentElement.clientHeight : el.clientHeight;
|
|
1111
|
+
}
|
|
1112
|
+
const { _containerWidth, _containerHeight } = this;
|
|
1113
|
+
this._containerWidth = width;
|
|
1114
|
+
this._containerHeight = height;
|
|
1115
|
+
if (width !== _containerWidth || height !== _containerHeight) {
|
|
1116
|
+
this._syncToObservers([
|
|
1117
|
+
"containerWidth",
|
|
1118
|
+
"containerHeight",
|
|
1119
|
+
"scrollableX",
|
|
1120
|
+
"scrollableY"
|
|
1121
|
+
]);
|
|
1122
|
+
this.emit("resize", { width, height });
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
_updateScrollSize() {
|
|
1126
|
+
const { el, _scrollWidth, _scrollHeight } = this;
|
|
1127
|
+
if (!el) return;
|
|
1128
|
+
this._scrollWidth = el.scrollWidth;
|
|
1129
|
+
this._scrollHeight = el.scrollHeight;
|
|
1130
|
+
if (_scrollWidth !== this._scrollWidth || _scrollHeight !== this._scrollHeight) {
|
|
1131
|
+
this._syncToObservers([
|
|
1132
|
+
"scrollWidth",
|
|
1133
|
+
"scrollHeight",
|
|
1134
|
+
"scrollableX",
|
|
1135
|
+
"scrollableY"
|
|
1136
|
+
]);
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
_startScrollSizeObserver() {
|
|
1140
|
+
if (!IN_WINDOW) return;
|
|
1141
|
+
this._stopScrollSizeObserver();
|
|
1142
|
+
if (this.scrollSizeObserver) {
|
|
1143
|
+
this._scrollSizeObserverPollingId = window.setInterval(() => {
|
|
1144
|
+
if (!this.scrollSizeObserver || this.isDestroyed) {
|
|
1145
|
+
this._stopScrollSizeObserver();
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
this._updateScrollSize();
|
|
1149
|
+
}, this.scrollSizeObserver.interval);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
_stopScrollSizeObserver() {
|
|
1153
|
+
if (this._scrollSizeObserverPollingId !== null) {
|
|
1154
|
+
clearInterval(this._scrollSizeObserverPollingId);
|
|
1155
|
+
this._scrollSizeObserverPollingId = null;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
_updateScrollPositions() {
|
|
1159
|
+
if (!this.el) return;
|
|
1160
|
+
this._scrollTop = this.el.scrollTop;
|
|
1161
|
+
this._scrollLeft = this.el.scrollLeft;
|
|
1162
|
+
this._scrollBottom = this._scrollHeight - this._scrollTop - this._containerHeight;
|
|
1163
|
+
this._scrollRight = this._scrollWidth - this._scrollLeft - this._containerWidth;
|
|
1164
|
+
this._syncToObservers([
|
|
1165
|
+
"scrollTop",
|
|
1166
|
+
"scrollRight",
|
|
1167
|
+
"scrollBottom",
|
|
1168
|
+
"scrollLeft"
|
|
1169
|
+
]);
|
|
1170
|
+
}
|
|
1171
|
+
_startListeners() {
|
|
1172
|
+
this._stopListeners();
|
|
1173
|
+
this._scrollListener = () => {
|
|
1174
|
+
this._onScroll();
|
|
1175
|
+
};
|
|
1176
|
+
this._eventTarget.addEventListener("scroll", this._scrollListener, false);
|
|
1177
|
+
if (this._isRootElement) {
|
|
1178
|
+
this._resizeListener = () => {
|
|
1179
|
+
this._onResize();
|
|
1180
|
+
};
|
|
1181
|
+
window.addEventListener("resize", this._resizeListener, false);
|
|
1182
|
+
} else {
|
|
1183
|
+
this._resizeObserver = new ResizeObserver((entries) => {
|
|
1184
|
+
for (const entry of entries) {
|
|
1185
|
+
const { width, height } = entry.contentRect;
|
|
1186
|
+
this._onResize(width, height);
|
|
1187
|
+
}
|
|
1188
|
+
});
|
|
1189
|
+
this._el && this._resizeObserver.observe(this._el);
|
|
1190
|
+
}
|
|
1191
|
+
if (visibilityManager.isVisible) {
|
|
1192
|
+
this._scrollSizeObserverSuspended = false;
|
|
1193
|
+
this._startScrollSizeObserver();
|
|
1194
|
+
} else {
|
|
1195
|
+
this._scrollSizeObserverSuspended = true;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
_stopListeners() {
|
|
1199
|
+
if (this._scrollListener) {
|
|
1200
|
+
this._eventTarget.removeEventListener(
|
|
1201
|
+
"scroll",
|
|
1202
|
+
this._scrollListener,
|
|
1203
|
+
false
|
|
1204
|
+
);
|
|
1205
|
+
delete this._scrollListener;
|
|
1206
|
+
}
|
|
1207
|
+
if (this._resizeListener) {
|
|
1208
|
+
if (this._isDocumentElement) {
|
|
1209
|
+
window.removeEventListener("resize", this._resizeListener, false);
|
|
1210
|
+
delete this._resizeListener;
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
if (this._resizeObserver && this._el) {
|
|
1214
|
+
this._resizeObserver.unobserve(this._el);
|
|
1215
|
+
this._resizeObserver.disconnect();
|
|
1216
|
+
delete this._resizeObserver;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
_clearScrollingJudgeTimer() {
|
|
1220
|
+
if (this._scrollingJudgeTimerId !== null) {
|
|
1221
|
+
clearTimeout(this._scrollingJudgeTimerId);
|
|
1222
|
+
this._scrollingJudgeTimerId = null;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
_onResize(width, height) {
|
|
1226
|
+
this._update(width, height);
|
|
1227
|
+
}
|
|
1228
|
+
_triggerScrollTick(event) {
|
|
1229
|
+
const { _nowScrolling } = this;
|
|
1230
|
+
if (event === "scrollStart") {
|
|
1231
|
+
this._startX = this._scrollLeft;
|
|
1232
|
+
this._startY = this._scrollTop;
|
|
1233
|
+
this._lastTotalX = 0;
|
|
1234
|
+
this._lastTotalY = 0;
|
|
1235
|
+
this._nowScrolling = true;
|
|
1236
|
+
} else if (event === "scrollEnd") {
|
|
1237
|
+
this._nowScrolling = false;
|
|
1238
|
+
}
|
|
1239
|
+
if (_nowScrolling !== this._nowScrolling) {
|
|
1240
|
+
this._syncToObservers("nowScrolling");
|
|
1241
|
+
}
|
|
1242
|
+
this.emit(event, this.lastPayload);
|
|
1243
|
+
}
|
|
1244
|
+
_onScroll() {
|
|
1245
|
+
if (!this.scrollEnabled && this._el) {
|
|
1246
|
+
this._el.scrollLeft = this._scrollLeft;
|
|
1247
|
+
this._el.scrollTop = this._scrollTop;
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
const {
|
|
1251
|
+
_scrollTop,
|
|
1252
|
+
_scrollLeft,
|
|
1253
|
+
_lastAxis,
|
|
1254
|
+
_lastDirection,
|
|
1255
|
+
_lastXDirection,
|
|
1256
|
+
_lastYDirection
|
|
1257
|
+
} = this;
|
|
1258
|
+
this._updateScrollPositions();
|
|
1259
|
+
const tickedX = this._scrollLeft - _scrollLeft;
|
|
1260
|
+
const tickedY = this._scrollTop - _scrollTop;
|
|
1261
|
+
this._tickedX = tickedX;
|
|
1262
|
+
this._tickedY = tickedY;
|
|
1263
|
+
if (tickedX === tickedY) {
|
|
1264
|
+
this._lastAxis = this.baseAxis;
|
|
1265
|
+
} else {
|
|
1266
|
+
this._lastAxis = Math.abs(tickedX) > Math.abs(tickedY) ? "x" : "y";
|
|
1267
|
+
}
|
|
1268
|
+
if (_scrollTop < this._scrollTop) {
|
|
1269
|
+
this._lastYDirection = "bottom";
|
|
1270
|
+
} else if (_scrollTop > this._scrollTop) {
|
|
1271
|
+
this._lastYDirection = "top";
|
|
1272
|
+
}
|
|
1273
|
+
if (_scrollLeft < this._scrollLeft) {
|
|
1274
|
+
this._lastXDirection = "right";
|
|
1275
|
+
} else if (_scrollLeft > this._scrollLeft) {
|
|
1276
|
+
this._lastXDirection = "left";
|
|
1277
|
+
}
|
|
1278
|
+
this._lastDirection = this._lastAxis === "y" ? this._lastYDirection : this._lastXDirection;
|
|
1279
|
+
const axisIsChanged = this._lastAxis !== _lastAxis;
|
|
1280
|
+
const lastXDirectionIsChanged = this._lastXDirection !== _lastXDirection;
|
|
1281
|
+
const lastYDirectionIsChanged = this._lastYDirection !== _lastYDirection;
|
|
1282
|
+
const lastDirectionIsChanged = this._lastDirection !== _lastDirection;
|
|
1283
|
+
if (axisIsChanged) {
|
|
1284
|
+
this.emit("changeAxis", this._lastAxis);
|
|
1285
|
+
}
|
|
1286
|
+
if (lastXDirectionIsChanged) {
|
|
1287
|
+
this.emit("changeLastXDirection", this._lastXDirection);
|
|
1288
|
+
}
|
|
1289
|
+
if (lastYDirectionIsChanged) {
|
|
1290
|
+
this.emit("changeLastYDirection", this._lastYDirection);
|
|
1291
|
+
}
|
|
1292
|
+
if (lastDirectionIsChanged) {
|
|
1293
|
+
this.emit("changeLastDirection", this._lastDirection);
|
|
1294
|
+
}
|
|
1295
|
+
if (axisIsChanged || lastXDirectionIsChanged || lastYDirectionIsChanged || lastDirectionIsChanged) {
|
|
1296
|
+
this._syncToObservers([
|
|
1297
|
+
"lastAxis",
|
|
1298
|
+
"lastDirection",
|
|
1299
|
+
"lastYDirection",
|
|
1300
|
+
"lastXDirection"
|
|
1301
|
+
]);
|
|
1302
|
+
}
|
|
1303
|
+
if (this._nowScrolling) {
|
|
1304
|
+
if (axisIsChanged || _lastAxis === "y" && lastYDirectionIsChanged || _lastAxis === "x" && lastXDirectionIsChanged) {
|
|
1305
|
+
this._triggerScrollTick("scrollEnd");
|
|
1306
|
+
} else {
|
|
1307
|
+
this._lastTotalX = this._scrollLeft - this._startX;
|
|
1308
|
+
this._lastTotalY = this._scrollTop - this._startY;
|
|
1309
|
+
this._triggerScrollTick("scroll");
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
if (!this._nowScrolling) {
|
|
1313
|
+
this._updateScrollSize();
|
|
1314
|
+
this._triggerScrollTick("scrollStart");
|
|
1315
|
+
}
|
|
1316
|
+
this._clearScrollingJudgeTimer();
|
|
1317
|
+
this._scrollingJudgeTimerId = window.setTimeout(() => {
|
|
1318
|
+
this._triggerScrollTick("scrollEnd");
|
|
1319
|
+
}, this.scrollingJudgeInterval);
|
|
1320
|
+
}
|
|
1321
|
+
_syncToObserver(observer, keys = scrollerObservableKeys) {
|
|
1322
|
+
for (const key of keys) {
|
|
1323
|
+
observer[key] = this[key];
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
_syncToObservers(keys) {
|
|
1327
|
+
if (this._observers.length === 0) return;
|
|
1328
|
+
keys = typeof keys === "string" ? [keys] : keys;
|
|
1329
|
+
for (const observer of this._observers) {
|
|
1330
|
+
this._syncToObserver(observer, keys);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
_checkElement() {
|
|
1334
|
+
const { _el } = this;
|
|
1335
|
+
if (!_el) {
|
|
1336
|
+
const message = "missing element";
|
|
1337
|
+
logger.error(message);
|
|
1338
|
+
throw new Error(message);
|
|
1339
|
+
}
|
|
1340
|
+
return _el;
|
|
1341
|
+
}
|
|
1342
|
+
_createMergedScrollOptions(source) {
|
|
1343
|
+
const el = this._checkElement();
|
|
1344
|
+
const merged = {
|
|
1345
|
+
container: el,
|
|
1346
|
+
...this.scrollSettingsDefaults,
|
|
1347
|
+
...source
|
|
1348
|
+
};
|
|
1349
|
+
return merged;
|
|
1350
|
+
}
|
|
1351
|
+
_createMergedScrollToElementOptions(source) {
|
|
1352
|
+
const el = this._checkElement();
|
|
1353
|
+
const merged = {
|
|
1354
|
+
container: el,
|
|
1355
|
+
...this.scrollToElementSettingsDefaults,
|
|
1356
|
+
...source
|
|
1357
|
+
};
|
|
1358
|
+
let { _scrollToElementAdditionalOffset: additionalOffset } = this;
|
|
1359
|
+
if (!additionalOffset) return merged;
|
|
1360
|
+
if (typeof additionalOffset === "function") {
|
|
1361
|
+
additionalOffset = additionalOffset(this);
|
|
1362
|
+
}
|
|
1363
|
+
if (!additionalOffset) return merged;
|
|
1364
|
+
if (typeof additionalOffset === "number") {
|
|
1365
|
+
additionalOffset = {
|
|
1366
|
+
x: additionalOffset,
|
|
1367
|
+
y: additionalOffset
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
let { offset } = merged;
|
|
1371
|
+
if (!offset) {
|
|
1372
|
+
merged.offset = additionalOffset;
|
|
1373
|
+
return merged;
|
|
1374
|
+
}
|
|
1375
|
+
if (typeof offset === "number") {
|
|
1376
|
+
offset = {
|
|
1377
|
+
x: offset,
|
|
1378
|
+
y: offset
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
offset.x = (offset.x || 0) + (additionalOffset.x || 0);
|
|
1382
|
+
offset.y = (offset.y || 0) + (additionalOffset.y || 0);
|
|
1383
|
+
merged.offset = offset;
|
|
1384
|
+
return merged;
|
|
1385
|
+
}
|
|
1386
|
+
_clearScrollToResult() {
|
|
1387
|
+
if (!this._scrollToResult) return;
|
|
1388
|
+
this._scrollToResult = null;
|
|
1389
|
+
}
|
|
1390
|
+
_setScrollToResult(result) {
|
|
1391
|
+
this._scrollToResult = result;
|
|
1392
|
+
result.promise.then(() => {
|
|
1393
|
+
this._clearScrollToResult();
|
|
1394
|
+
});
|
|
1395
|
+
return result;
|
|
1396
|
+
}
|
|
1397
|
+
_updateScrollable() {
|
|
1398
|
+
if (this.scrollEnabled) {
|
|
1399
|
+
this._scrollEnable();
|
|
1400
|
+
} else {
|
|
1401
|
+
this._scrollDisable();
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
_scrollEnable() {
|
|
1405
|
+
enableScroll(this._checkElement());
|
|
1406
|
+
}
|
|
1407
|
+
_scrollDisable() {
|
|
1408
|
+
const el = this._checkElement();
|
|
1409
|
+
this.cancel();
|
|
1410
|
+
disableScroll(el);
|
|
1411
|
+
}
|
|
1353
1412
|
};
|
|
1354
1413
|
|
|
1355
|
-
//#endregion
|
|
1356
1414
|
export { SCROLLABLE_KEY_CODES, Scroller, ScrollerState, defaultBaseSettings, defaultSettings, disableScroll, enableScroll, scrollBy, scrollTo, scrollToBottom, scrollToElement, scrollToElementSettingsDefaults, scrollToLeft, scrollToLeftBottom, scrollToLeftTop, scrollToRight, scrollToRightBottom, scrollToRightTop, scrollToSide, scrollToTop };
|
|
1415
|
+
//# sourceMappingURL=scroller.mjs.map
|
|
1357
1416
|
//# sourceMappingURL=scroller.mjs.map
|