@micromag/core 0.3.767 → 0.3.779
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/assets/css/vendor.css +2 -2
- package/es/components.js +11 -10
- package/es/contexts.js +23 -1
- package/es/hooks.js +1 -1
- package/lib/components.js +4501 -0
- package/lib/contexts.js +1824 -0
- package/lib/hooks.js +2474 -0
- package/lib/index.js +2436 -0
- package/lib/utils.js +1255 -0
- package/package.json +9 -4
package/lib/hooks.js
ADDED
|
@@ -0,0 +1,2474 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var core = require('@micromag/core');
|
|
6
|
+
var utils = require('@micromag/core/utils');
|
|
7
|
+
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
8
|
+
var core$1 = require('@react-spring/core');
|
|
9
|
+
var react$1 = require('@use-gesture/react');
|
|
10
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
11
|
+
var forms = require('@folklore/forms');
|
|
12
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
13
|
+
var classNames = require('classnames');
|
|
14
|
+
var screenfull = require('screenfull');
|
|
15
|
+
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
16
|
+
var isArray = require('lodash/isArray');
|
|
17
|
+
var isObject = require('lodash/isObject');
|
|
18
|
+
var createDebug = require('debug');
|
|
19
|
+
var isString = require('lodash/isString');
|
|
20
|
+
var raf = require('raf');
|
|
21
|
+
var contexts = require('@micromag/core/contexts');
|
|
22
|
+
var reactIntl = require('react-intl');
|
|
23
|
+
var dayjs = require('dayjs');
|
|
24
|
+
var cssMediaquery = require('css-mediaquery');
|
|
25
|
+
var clamp = require('lodash/clamp');
|
|
26
|
+
|
|
27
|
+
function useActivityDetector() {
|
|
28
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
29
|
+
_ref$element = _ref.element,
|
|
30
|
+
providedElement = _ref$element === void 0 ? null : _ref$element,
|
|
31
|
+
_ref$disabled = _ref.disabled,
|
|
32
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
33
|
+
_ref$timeout = _ref.timeout,
|
|
34
|
+
timeoutDelay = _ref$timeout === void 0 ? 2000 : _ref$timeout;
|
|
35
|
+
var ref = react.useRef(providedElement);
|
|
36
|
+
var _useState = react.useState(false),
|
|
37
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
38
|
+
detected = _useState2[0],
|
|
39
|
+
setDetected = _useState2[1];
|
|
40
|
+
var detectedRef = react.useRef(detected);
|
|
41
|
+
if (providedElement !== null && providedElement !== ref.current) {
|
|
42
|
+
ref.current = providedElement;
|
|
43
|
+
}
|
|
44
|
+
react.useEffect(function () {
|
|
45
|
+
var _ref$current = ref.current,
|
|
46
|
+
element = _ref$current === void 0 ? null : _ref$current;
|
|
47
|
+
if (element === null || disabled) {
|
|
48
|
+
return function () {};
|
|
49
|
+
}
|
|
50
|
+
var timeout = null;
|
|
51
|
+
function onActivity() {
|
|
52
|
+
if (timeout !== null) {
|
|
53
|
+
clearTimeout(timeout);
|
|
54
|
+
timeout = null;
|
|
55
|
+
}
|
|
56
|
+
if (!detectedRef.current) {
|
|
57
|
+
detectedRef.current = true;
|
|
58
|
+
setDetected(true);
|
|
59
|
+
}
|
|
60
|
+
timeout = setTimeout(function () {
|
|
61
|
+
detectedRef.current = false;
|
|
62
|
+
setDetected(false);
|
|
63
|
+
}, timeoutDelay);
|
|
64
|
+
}
|
|
65
|
+
element.addEventListener('keydown', onActivity);
|
|
66
|
+
element.addEventListener('mousedown', onActivity);
|
|
67
|
+
element.addEventListener('mousemove', onActivity);
|
|
68
|
+
element.addEventListener('mouseup', onActivity);
|
|
69
|
+
element.addEventListener('pointerdown', onActivity);
|
|
70
|
+
element.addEventListener('pointermove', onActivity);
|
|
71
|
+
element.addEventListener('pointerup', onActivity);
|
|
72
|
+
element.addEventListener('touchmove', onActivity);
|
|
73
|
+
element.addEventListener('touchstart', onActivity);
|
|
74
|
+
return function () {
|
|
75
|
+
if (timeout !== null) {
|
|
76
|
+
clearTimeout(timeout);
|
|
77
|
+
timeout = null;
|
|
78
|
+
}
|
|
79
|
+
element.removeEventListener('keydown', onActivity);
|
|
80
|
+
element.removeEventListener('mousedown', onActivity);
|
|
81
|
+
element.removeEventListener('mousemove', onActivity);
|
|
82
|
+
element.removeEventListener('mouseup', onActivity);
|
|
83
|
+
element.removeEventListener('pointerdown', onActivity);
|
|
84
|
+
element.removeEventListener('pointermove', onActivity);
|
|
85
|
+
element.removeEventListener('pointerup', onActivity);
|
|
86
|
+
element.removeEventListener('touchmove', onActivity);
|
|
87
|
+
element.removeEventListener('touchstart', onActivity);
|
|
88
|
+
};
|
|
89
|
+
}, [providedElement, disabled, timeoutDelay]);
|
|
90
|
+
return {
|
|
91
|
+
ref: ref,
|
|
92
|
+
detected: detected
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
var useAnimationFrame = function useAnimationFrame(onFrame) {
|
|
97
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
98
|
+
_ref$disabled = _ref.disabled,
|
|
99
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled;
|
|
100
|
+
var requestRef = react.useRef(null);
|
|
101
|
+
var startTimeRef = react.useRef(null);
|
|
102
|
+
var _callback = function callback(time) {
|
|
103
|
+
if (!startTimeRef.current) {
|
|
104
|
+
startTimeRef.current = time;
|
|
105
|
+
}
|
|
106
|
+
var progress = time - startTimeRef.current;
|
|
107
|
+
onFrame(progress);
|
|
108
|
+
requestRef.current = requestAnimationFrame(_callback);
|
|
109
|
+
};
|
|
110
|
+
react.useEffect(function () {
|
|
111
|
+
if (!disabled) {
|
|
112
|
+
requestRef.current = requestAnimationFrame(_callback);
|
|
113
|
+
}
|
|
114
|
+
return function () {
|
|
115
|
+
if (requestRef.current !== null) {
|
|
116
|
+
cancelAnimationFrame(requestRef.current);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}, [disabled]);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
var useFormattedDate = function useFormattedDate() {
|
|
123
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
124
|
+
_ref$format = _ref.format,
|
|
125
|
+
format = _ref$format === void 0 ? null : _ref$format,
|
|
126
|
+
_ref$showToday = _ref.showToday,
|
|
127
|
+
showToday = _ref$showToday === void 0 ? true : _ref$showToday;
|
|
128
|
+
var intl = reactIntl.useIntl();
|
|
129
|
+
var today = dayjs();
|
|
130
|
+
return react.useCallback(function (date) {
|
|
131
|
+
var dateToFormat = isString(date) ? dayjs(date) : date;
|
|
132
|
+
if (showToday && dateToFormat.format('YYYY-MM-DD') === today.format('YYYY-MM-DD')) {
|
|
133
|
+
return intl.formatMessage({
|
|
134
|
+
id: "v4Qtl9",
|
|
135
|
+
defaultMessage: [{
|
|
136
|
+
"type": 0,
|
|
137
|
+
"value": "Today"
|
|
138
|
+
}]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return intl.formatDate(dayjs(date).toDate(), _objectSpread({
|
|
142
|
+
year: 'numeric',
|
|
143
|
+
month: 'long',
|
|
144
|
+
day: '2-digit'
|
|
145
|
+
}, format));
|
|
146
|
+
}, [today, showToday, format]);
|
|
147
|
+
};
|
|
148
|
+
var useFormattedTime = function useFormattedTime() {
|
|
149
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
150
|
+
_ref2$format = _ref2.format,
|
|
151
|
+
format = _ref2$format === void 0 ? null : _ref2$format,
|
|
152
|
+
_ref2$showNow = _ref2.showNow,
|
|
153
|
+
showNow = _ref2$showNow === void 0 ? true : _ref2$showNow,
|
|
154
|
+
_ref2$timeGap = _ref2.timeGap,
|
|
155
|
+
timeGap = _ref2$timeGap === void 0 ? 2 : _ref2$timeGap;
|
|
156
|
+
var intl = reactIntl.useIntl();
|
|
157
|
+
var now = dayjs();
|
|
158
|
+
return react.useCallback(function (date) {
|
|
159
|
+
var dateToFormat = isString(date) ? dayjs(date) : date;
|
|
160
|
+
if (showNow && dateToFormat.format('YYYY-MM-DD') === now.format('YYYY-MM-DD') && dateToFormat.hour() === now.hour() && dateToFormat.minute() > now.minute() - timeGap && dateToFormat.minute() < now.minute() + timeGap) {
|
|
161
|
+
return intl.formatMessage({
|
|
162
|
+
id: "3na7F8",
|
|
163
|
+
defaultMessage: [{
|
|
164
|
+
"type": 0,
|
|
165
|
+
"value": "Now"
|
|
166
|
+
}]
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return intl.formatTime(dateToFormat.toDate(), _objectSpread({
|
|
170
|
+
hour: 'numeric',
|
|
171
|
+
minute: 'numeric'
|
|
172
|
+
}, format));
|
|
173
|
+
}, [now, showNow, timeGap, format]);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
var useDebounced = function useDebounced(handler, watchedValue) {
|
|
177
|
+
var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 300;
|
|
178
|
+
react.useEffect(function () {
|
|
179
|
+
var timeoutHandler = setTimeout(function () {
|
|
180
|
+
if (handler !== null) {
|
|
181
|
+
handler(watchedValue);
|
|
182
|
+
}
|
|
183
|
+
}, delay);
|
|
184
|
+
return function () {
|
|
185
|
+
clearTimeout(timeoutHandler);
|
|
186
|
+
};
|
|
187
|
+
}, [watchedValue, delay]);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
var eventsManager$1 = typeof document !== 'undefined' ? new core.EventsManager(document) : null;
|
|
191
|
+
var useDocumentEvent = utils.createUseEvent(eventsManager$1);
|
|
192
|
+
|
|
193
|
+
function useDragProgress() {
|
|
194
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
195
|
+
wantedProgress = _ref.progress,
|
|
196
|
+
_ref$onTap = _ref.onTap,
|
|
197
|
+
onTap = _ref$onTap === void 0 ? null : _ref$onTap,
|
|
198
|
+
_ref$disabled = _ref.disabled,
|
|
199
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
200
|
+
_ref$dragDisabled = _ref.dragDisabled,
|
|
201
|
+
dragDisabled = _ref$dragDisabled === void 0 ? false : _ref$dragDisabled,
|
|
202
|
+
_ref$computeProgress = _ref.computeProgress,
|
|
203
|
+
computeProgress = _ref$computeProgress === void 0 ? null : _ref$computeProgress,
|
|
204
|
+
_ref$onProgress = _ref.onProgress,
|
|
205
|
+
onProgress = _ref$onProgress === void 0 ? null : _ref$onProgress,
|
|
206
|
+
_ref$onPointerDown = _ref.onPointerDown,
|
|
207
|
+
onPointerDown = _ref$onPointerDown === void 0 ? null : _ref$onPointerDown,
|
|
208
|
+
_ref$springParams = _ref.springParams,
|
|
209
|
+
springParams = _ref$springParams === void 0 ? undefined : _ref$springParams,
|
|
210
|
+
_ref$dragOptions = _ref.dragOptions,
|
|
211
|
+
dragOptions = _ref$dragOptions === void 0 ? {
|
|
212
|
+
filterTaps: true
|
|
213
|
+
} : _ref$dragOptions;
|
|
214
|
+
var refDragging = react.useRef(false);
|
|
215
|
+
var refProgress = react.useRef(wantedProgress);
|
|
216
|
+
var wantedProgressRef = react.useRef(wantedProgress);
|
|
217
|
+
if (wantedProgress !== wantedProgressRef.current) {
|
|
218
|
+
wantedProgressRef.current = wantedProgress;
|
|
219
|
+
}
|
|
220
|
+
var _useState = react.useState(false),
|
|
221
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
222
|
+
dragging = _useState2[0],
|
|
223
|
+
setDragging = _useState2[1];
|
|
224
|
+
var _useState3 = react.useState(0),
|
|
225
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
226
|
+
direction = _useState4[0],
|
|
227
|
+
setDirection = _useState4[1];
|
|
228
|
+
var spring = react.useCallback(function () {
|
|
229
|
+
return _objectSpread({
|
|
230
|
+
progress: wantedProgress,
|
|
231
|
+
immediate: dragging || disabled,
|
|
232
|
+
onResolve: function onResolve() {
|
|
233
|
+
setDirection(0);
|
|
234
|
+
}
|
|
235
|
+
}, springParams);
|
|
236
|
+
}, [wantedProgress, disabled]);
|
|
237
|
+
var _useSpring = core$1.useSpring(spring),
|
|
238
|
+
_useSpring2 = _slicedToArray(_useSpring, 2),
|
|
239
|
+
progress = _useSpring2[0].progress,
|
|
240
|
+
api = _useSpring2[1];
|
|
241
|
+
var onDrag = react.useCallback(function (gestureState) {
|
|
242
|
+
var active = gestureState.active,
|
|
243
|
+
tap = gestureState.tap;
|
|
244
|
+
if (disabled) {
|
|
245
|
+
refDragging.current = false;
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (tap) {
|
|
249
|
+
refDragging.current = false;
|
|
250
|
+
if (onTap !== null) onTap(gestureState);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (dragDisabled) {
|
|
254
|
+
refDragging.current = false;
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
var newProgress = computeProgress(gestureState);
|
|
258
|
+
refDragging.current = active;
|
|
259
|
+
setDirection(newProgress < wantedProgressRef.current ? -1 : 1);
|
|
260
|
+
refProgress.current = newProgress;
|
|
261
|
+
if (active !== dragging) {
|
|
262
|
+
setDragging(active);
|
|
263
|
+
}
|
|
264
|
+
api.start({
|
|
265
|
+
progress: newProgress,
|
|
266
|
+
immediate: active,
|
|
267
|
+
onResolve: !active ? function () {
|
|
268
|
+
setDirection(0);
|
|
269
|
+
} : function () {}
|
|
270
|
+
});
|
|
271
|
+
if (onProgress !== null) {
|
|
272
|
+
onProgress(newProgress, gestureState);
|
|
273
|
+
}
|
|
274
|
+
}, [setDragging, disabled, onTap, computeProgress, dragging, onProgress]);
|
|
275
|
+
var bind = react$1.useGesture({
|
|
276
|
+
onDrag: onDrag,
|
|
277
|
+
onPointerDown: onPointerDown !== null ? onPointerDown : function () {}
|
|
278
|
+
}, {
|
|
279
|
+
drag: dragOptions
|
|
280
|
+
});
|
|
281
|
+
react.useEffect(function () {
|
|
282
|
+
if (!refDragging.current && wantedProgress !== refProgress.current) {
|
|
283
|
+
setDirection(wantedProgress < refProgress.current ? -1 : 1);
|
|
284
|
+
refProgress.current = wantedProgress;
|
|
285
|
+
api.start({
|
|
286
|
+
progress: wantedProgress,
|
|
287
|
+
immediate: false,
|
|
288
|
+
onResolve: function onResolve() {
|
|
289
|
+
setDirection(0);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}, [wantedProgress]);
|
|
294
|
+
var transitioning = react.useMemo(function () {
|
|
295
|
+
return wantedProgress !== progress.get() || progress.isAnimating || dragging;
|
|
296
|
+
}, [wantedProgress, progress.isAnimating, dragging]);
|
|
297
|
+
return {
|
|
298
|
+
transitioning: transitioning,
|
|
299
|
+
bind: bind,
|
|
300
|
+
dragging: dragging,
|
|
301
|
+
progress: progress,
|
|
302
|
+
direction: direction
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
var _excluded$3 = ["fields", "injectInFields"],
|
|
307
|
+
_excluded2 = ["fields"];
|
|
308
|
+
|
|
309
|
+
// eslint-disable-next-line
|
|
310
|
+
var useForm = function useForm() {
|
|
311
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
312
|
+
_ref$fields = _ref.fields,
|
|
313
|
+
providedFields = _ref$fields === void 0 ? [] : _ref$fields,
|
|
314
|
+
_ref$injectInFields = _ref.injectInFields,
|
|
315
|
+
injectInFields = _ref$injectInFields === void 0 ? false : _ref$injectInFields,
|
|
316
|
+
opts = _objectWithoutProperties(_ref, _excluded$3);
|
|
317
|
+
var fieldsNames = react.useMemo(function () {
|
|
318
|
+
return providedFields.length > 0 ? providedFields.map(function (_ref2) {
|
|
319
|
+
var name = _ref2.name;
|
|
320
|
+
return name;
|
|
321
|
+
}) : [];
|
|
322
|
+
}, [providedFields]);
|
|
323
|
+
var _useBaseForm = forms.useForm(_objectSpread({
|
|
324
|
+
fields: fieldsNames
|
|
325
|
+
}, opts)),
|
|
326
|
+
fields = _useBaseForm.fields,
|
|
327
|
+
form = _objectWithoutProperties(_useBaseForm, _excluded2);
|
|
328
|
+
return _objectSpread(_objectSpread({}, form), {}, {
|
|
329
|
+
fields: injectInFields ? providedFields.map(function (it) {
|
|
330
|
+
return _objectSpread(_objectSpread({}, it), fields[it.name] || null);
|
|
331
|
+
}) : providedFields
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
var useFormTransition = function useFormTransition() {
|
|
336
|
+
var paths = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
337
|
+
var styles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
338
|
+
var lastPageRef = react.useRef(paths || []);
|
|
339
|
+
var direction = react.useMemo(function () {
|
|
340
|
+
var currentPartsCount = paths.length;
|
|
341
|
+
if (lastPageRef.current) {
|
|
342
|
+
var previousPartsCount = lastPageRef.current.length;
|
|
343
|
+
lastPageRef.current = paths || [];
|
|
344
|
+
return currentPartsCount > previousPartsCount ? 'right' : 'left';
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
}, [paths]);
|
|
348
|
+
var name = react.useMemo(function () {
|
|
349
|
+
return {
|
|
350
|
+
enter: classNames(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.enterRight, direction === 'right'), styles.enterLeft, direction === 'left'), styles.enterTop, direction === 'top'), styles.enterBottom, direction === 'bottom')) || 'none',
|
|
351
|
+
enterActive: classNames(_defineProperty(_defineProperty({}, styles.enterActiveHorizontal, direction === 'left' || direction === 'right'), styles.enterActiveVertical, direction === 'top' || direction === 'bottom')) || 'none',
|
|
352
|
+
leave: styles.leave || 'none',
|
|
353
|
+
leaveActive: classNames(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.leaveActiveRight, direction === 'right'), styles.leaveActiveLeft, direction === 'left'), styles.leaveActiveTop, direction === 'top'), styles.leaveActiveBottom, direction === 'bottom')) || 'none'
|
|
354
|
+
};
|
|
355
|
+
}, [direction]);
|
|
356
|
+
return {
|
|
357
|
+
direction: direction,
|
|
358
|
+
name: name,
|
|
359
|
+
timeout: direction === 'left' || direction === 'right' ? 300 : 10
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
var useFullscreen = function useFullscreen(element) {
|
|
364
|
+
var enabled = screenfull.isEnabled;
|
|
365
|
+
var _useState = react.useState(false),
|
|
366
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
367
|
+
active = _useState2[0],
|
|
368
|
+
setActive = _useState2[1];
|
|
369
|
+
var fullscreen = react.useCallback(function () {
|
|
370
|
+
if (screenfull.isEnabled) {
|
|
371
|
+
if (typeof element !== 'undefined' && element !== null) {
|
|
372
|
+
screenfull.request(element);
|
|
373
|
+
} else {
|
|
374
|
+
screenfull.request();
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}, [element]);
|
|
378
|
+
var unFullscreen = react.useCallback(function () {
|
|
379
|
+
if (screenfull.isEnabled) {
|
|
380
|
+
screenfull.exit();
|
|
381
|
+
}
|
|
382
|
+
}, []);
|
|
383
|
+
var toggle = react.useCallback(function () {
|
|
384
|
+
if (!active) {
|
|
385
|
+
fullscreen();
|
|
386
|
+
} else {
|
|
387
|
+
unFullscreen();
|
|
388
|
+
}
|
|
389
|
+
}, [active, fullscreen, unFullscreen]);
|
|
390
|
+
react.useEffect(function () {
|
|
391
|
+
var onChange = function onChange() {
|
|
392
|
+
setActive(screenfull.isFullscreen);
|
|
393
|
+
};
|
|
394
|
+
if (screenfull.isEnabled) {
|
|
395
|
+
screenfull.on('change', onChange);
|
|
396
|
+
}
|
|
397
|
+
return function () {
|
|
398
|
+
if (screenfull.isEnabled) {
|
|
399
|
+
screenfull.off('change', onChange);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
}, []);
|
|
403
|
+
return {
|
|
404
|
+
toggle: toggle,
|
|
405
|
+
fullscreen: fullscreen,
|
|
406
|
+
unFullscreen: unFullscreen,
|
|
407
|
+
active: active,
|
|
408
|
+
enabled: enabled
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
var _excluded$2 = ["entry"];
|
|
413
|
+
var buildThresholdArray = function buildThresholdArray() {
|
|
414
|
+
return [0, 1.0];
|
|
415
|
+
};
|
|
416
|
+
var observersCache = new Map();
|
|
417
|
+
var getOptionsKey = function getOptionsKey(_ref) {
|
|
418
|
+
var _ref$root = _ref.root,
|
|
419
|
+
root = _ref$root === void 0 ? null : _ref$root,
|
|
420
|
+
rootMargin = _ref.rootMargin,
|
|
421
|
+
_ref$threshold = _ref.threshold,
|
|
422
|
+
threshold = _ref$threshold === void 0 ? null : _ref$threshold;
|
|
423
|
+
return "root_".concat(root, "_rootMargin_").concat(rootMargin || null, "_threshold_").concat(threshold);
|
|
424
|
+
};
|
|
425
|
+
var createObserver = function createObserver(Observer) {
|
|
426
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
427
|
+
var subscribers = [];
|
|
428
|
+
var addSubscriber = function addSubscriber(element, callback) {
|
|
429
|
+
var currentSubscriber = subscribers.find(function (it) {
|
|
430
|
+
return it.element === element;
|
|
431
|
+
}) || null;
|
|
432
|
+
if (currentSubscriber !== null) {
|
|
433
|
+
return subscribers.map(function (it) {
|
|
434
|
+
return it.element === element && it.callbacks.indexOf(callback) === -1 ? _objectSpread(_objectSpread({}, it), {}, {
|
|
435
|
+
callbacks: [].concat(_toConsumableArray(it.callbacks), [callback])
|
|
436
|
+
}) : it;
|
|
437
|
+
}).filter(function (it) {
|
|
438
|
+
return it.callbacks.length > 0;
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
return [].concat(_toConsumableArray(subscribers), [{
|
|
442
|
+
element: element,
|
|
443
|
+
callbacks: [callback]
|
|
444
|
+
}]);
|
|
445
|
+
};
|
|
446
|
+
var removeSubscriber = function removeSubscriber(element, callback) {
|
|
447
|
+
return subscribers.map(function (it) {
|
|
448
|
+
return it.element === element ? _objectSpread(_objectSpread({}, it), {}, {
|
|
449
|
+
callbacks: it.callbacks.filter(function (subCallback) {
|
|
450
|
+
return subCallback !== callback;
|
|
451
|
+
})
|
|
452
|
+
}) : it;
|
|
453
|
+
}).filter(function (it) {
|
|
454
|
+
return it.callbacks.length > 0;
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
var onUpdate = function onUpdate(entries) {
|
|
458
|
+
entries.forEach(function (entry) {
|
|
459
|
+
subscribers.forEach(function (_ref2) {
|
|
460
|
+
var element = _ref2.element,
|
|
461
|
+
callbacks = _ref2.callbacks;
|
|
462
|
+
if (element === entry.target) {
|
|
463
|
+
callbacks.forEach(function (callback) {
|
|
464
|
+
callback(entry);
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
};
|
|
470
|
+
var observer = new Observer(onUpdate, options);
|
|
471
|
+
var unsubscribe = function unsubscribe(element) {
|
|
472
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
473
|
+
subscribers = removeSubscriber(element, callback);
|
|
474
|
+
if (typeof observer.unobserve === 'undefined') {
|
|
475
|
+
observer.disconnect();
|
|
476
|
+
subscribers.forEach(function (subscriber) {
|
|
477
|
+
observer.observe(subscriber.element);
|
|
478
|
+
});
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
var currentSubscriber = subscribers.find(function (it) {
|
|
482
|
+
return it.element === element;
|
|
483
|
+
}) || null;
|
|
484
|
+
if (currentSubscriber === null) {
|
|
485
|
+
observer.unobserve(element);
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
var subscribe = function subscribe(element, callback) {
|
|
489
|
+
var currentSubscriber = subscribers.find(function (it) {
|
|
490
|
+
return it.element === element;
|
|
491
|
+
}) || null;
|
|
492
|
+
subscribers = addSubscriber(element, callback);
|
|
493
|
+
if (currentSubscriber === null) {
|
|
494
|
+
observer.observe(element);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
return {
|
|
498
|
+
subscribe: subscribe,
|
|
499
|
+
unsubscribe: unsubscribe,
|
|
500
|
+
observer: observer
|
|
501
|
+
};
|
|
502
|
+
};
|
|
503
|
+
var getObserver = function getObserver(Observer) {
|
|
504
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
505
|
+
var observerKey = getOptionsKey(options);
|
|
506
|
+
if (!observersCache.has(Observer)) {
|
|
507
|
+
observersCache.set(Observer, {});
|
|
508
|
+
}
|
|
509
|
+
var observers = observersCache.get(Observer);
|
|
510
|
+
if (typeof observers[observerKey] === 'undefined') {
|
|
511
|
+
observers[observerKey] = createObserver(Observer, options);
|
|
512
|
+
observersCache.set(Observer, observers);
|
|
513
|
+
}
|
|
514
|
+
return observers[observerKey];
|
|
515
|
+
};
|
|
516
|
+
var useObserver = function useObserver(Observer) {
|
|
517
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
518
|
+
var initialEntry = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
519
|
+
var _opts$root = opts.root,
|
|
520
|
+
root = _opts$root === void 0 ? null : _opts$root,
|
|
521
|
+
_opts$rootMargin = opts.rootMargin,
|
|
522
|
+
rootMargin = _opts$rootMargin === void 0 ? null : _opts$rootMargin,
|
|
523
|
+
_opts$threshold = opts.threshold,
|
|
524
|
+
threshold = _opts$threshold === void 0 ? null : _opts$threshold,
|
|
525
|
+
_opts$disabled = opts.disabled,
|
|
526
|
+
disabled = _opts$disabled === void 0 ? false : _opts$disabled;
|
|
527
|
+
var _useState = react.useState(initialEntry),
|
|
528
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
529
|
+
entry = _useState2[0],
|
|
530
|
+
setEntry = _useState2[1];
|
|
531
|
+
var nodeRef = react.useRef(null);
|
|
532
|
+
var currentElement = react.useRef(null);
|
|
533
|
+
var elementChanged = nodeRef.current !== currentElement.current;
|
|
534
|
+
react.useEffect(function () {
|
|
535
|
+
var nodeElement = nodeRef.current;
|
|
536
|
+
var callback = function callback(newEntry) {
|
|
537
|
+
return setEntry(newEntry);
|
|
538
|
+
};
|
|
539
|
+
var unsubscribe = null;
|
|
540
|
+
if (nodeElement !== null) {
|
|
541
|
+
var newOpts = {};
|
|
542
|
+
if (root !== null) {
|
|
543
|
+
newOpts.root = root;
|
|
544
|
+
}
|
|
545
|
+
if (rootMargin !== null) {
|
|
546
|
+
newOpts.rootMargin = rootMargin;
|
|
547
|
+
}
|
|
548
|
+
if (threshold !== null) {
|
|
549
|
+
newOpts.threshold = threshold;
|
|
550
|
+
}
|
|
551
|
+
var _getObserver = getObserver(Observer, newOpts),
|
|
552
|
+
subscribe = _getObserver.subscribe,
|
|
553
|
+
localUnsubscribe = _getObserver.unsubscribe;
|
|
554
|
+
unsubscribe = localUnsubscribe;
|
|
555
|
+
subscribe(nodeElement, callback);
|
|
556
|
+
}
|
|
557
|
+
currentElement.current = nodeElement;
|
|
558
|
+
return function () {
|
|
559
|
+
if (unsubscribe !== null) {
|
|
560
|
+
unsubscribe(nodeElement, callback);
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
}, [Observer, elementChanged, disabled, root, rootMargin, threshold]);
|
|
564
|
+
return {
|
|
565
|
+
ref: nodeRef,
|
|
566
|
+
entry: entry
|
|
567
|
+
};
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Intersection Observer
|
|
572
|
+
*/
|
|
573
|
+
var thresholdArray = buildThresholdArray();
|
|
574
|
+
var intersectionObserverInitialEntry = {
|
|
575
|
+
target: null,
|
|
576
|
+
time: null,
|
|
577
|
+
isVisible: false,
|
|
578
|
+
isIntersecting: false,
|
|
579
|
+
intersectionRatio: 0,
|
|
580
|
+
intersectionRect: null,
|
|
581
|
+
boundingClientRect: null,
|
|
582
|
+
rootBounds: null
|
|
583
|
+
};
|
|
584
|
+
var useIntersectionObserver = function useIntersectionObserver() {
|
|
585
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
586
|
+
_ref3$root = _ref3.root,
|
|
587
|
+
root = _ref3$root === void 0 ? null : _ref3$root,
|
|
588
|
+
_ref3$rootMargin = _ref3.rootMargin,
|
|
589
|
+
rootMargin = _ref3$rootMargin === void 0 ? '0px' : _ref3$rootMargin,
|
|
590
|
+
_ref3$threshold = _ref3.threshold,
|
|
591
|
+
threshold = _ref3$threshold === void 0 ? thresholdArray : _ref3$threshold,
|
|
592
|
+
_ref3$disabled = _ref3.disabled,
|
|
593
|
+
disabled = _ref3$disabled === void 0 ? false : _ref3$disabled;
|
|
594
|
+
return useObserver(typeof window !== 'undefined' ? IntersectionObserver : null, {
|
|
595
|
+
root: root,
|
|
596
|
+
rootMargin: rootMargin,
|
|
597
|
+
threshold: threshold,
|
|
598
|
+
disabled: disabled
|
|
599
|
+
}, intersectionObserverInitialEntry);
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Resize Observer
|
|
604
|
+
*/
|
|
605
|
+
var resizeObserverInitialEntry = {
|
|
606
|
+
target: null,
|
|
607
|
+
contentRect: null,
|
|
608
|
+
contentBoxSize: null,
|
|
609
|
+
borderBoxSize: null
|
|
610
|
+
};
|
|
611
|
+
var useResizeObserver = function useResizeObserver() {
|
|
612
|
+
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
613
|
+
_ref4$disabled = _ref4.disabled,
|
|
614
|
+
disabled = _ref4$disabled === void 0 ? false : _ref4$disabled;
|
|
615
|
+
return useObserver(typeof window !== 'undefined' ? ResizeObserver : null, {
|
|
616
|
+
disabled: disabled
|
|
617
|
+
}, resizeObserverInitialEntry);
|
|
618
|
+
};
|
|
619
|
+
var useDimensionObserver = function useDimensionObserver() {
|
|
620
|
+
var _useResizeObserver = useResizeObserver.apply(void 0, arguments),
|
|
621
|
+
entry = _useResizeObserver.entry,
|
|
622
|
+
rest = _objectWithoutProperties(_useResizeObserver, _excluded$2);
|
|
623
|
+
var _ref5 = entry || {},
|
|
624
|
+
_ref5$contentRect = _ref5.contentRect,
|
|
625
|
+
contentRect = _ref5$contentRect === void 0 ? null : _ref5$contentRect,
|
|
626
|
+
_ref5$borderBoxSize = _ref5.borderBoxSize,
|
|
627
|
+
borderBoxSize = _ref5$borderBoxSize === void 0 ? null : _ref5$borderBoxSize;
|
|
628
|
+
var _ref6 = contentRect || {},
|
|
629
|
+
_ref6$width = _ref6.width,
|
|
630
|
+
width = _ref6$width === void 0 ? 0 : _ref6$width,
|
|
631
|
+
_ref6$height = _ref6.height,
|
|
632
|
+
height = _ref6$height === void 0 ? 0 : _ref6$height;
|
|
633
|
+
var _ref7 = isArray(borderBoxSize) ? borderBoxSize[0] || {} : borderBoxSize || {},
|
|
634
|
+
_ref7$blockSize = _ref7.blockSize,
|
|
635
|
+
blockSize = _ref7$blockSize === void 0 ? null : _ref7$blockSize,
|
|
636
|
+
_ref7$inlineSize = _ref7.inlineSize,
|
|
637
|
+
inlineSize = _ref7$inlineSize === void 0 ? null : _ref7$inlineSize;
|
|
638
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
639
|
+
entry: entry,
|
|
640
|
+
width: inlineSize || width,
|
|
641
|
+
height: blockSize || height
|
|
642
|
+
});
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
var useIsVisible = function useIsVisible() {
|
|
646
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
647
|
+
rootMargin = _ref.rootMargin,
|
|
648
|
+
_ref$persist = _ref.persist,
|
|
649
|
+
persist = _ref$persist === void 0 ? false : _ref$persist;
|
|
650
|
+
var _useIntersectionObser = useIntersectionObserver({
|
|
651
|
+
rootMargin: rootMargin
|
|
652
|
+
}),
|
|
653
|
+
ref = _useIntersectionObser.ref,
|
|
654
|
+
isIntersecting = _useIntersectionObser.entry.isIntersecting;
|
|
655
|
+
var wasIntersecting = react.useRef(isIntersecting);
|
|
656
|
+
if (isIntersecting && !wasIntersecting.current) {
|
|
657
|
+
wasIntersecting.current = isIntersecting;
|
|
658
|
+
}
|
|
659
|
+
var isVisible = !persist && isIntersecting || persist && wasIntersecting.current;
|
|
660
|
+
return {
|
|
661
|
+
ref: ref,
|
|
662
|
+
visible: isVisible
|
|
663
|
+
};
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
var fontsMap = {
|
|
667
|
+
loading: [],
|
|
668
|
+
active: []
|
|
669
|
+
};
|
|
670
|
+
var isFontLoading = function isFontLoading(name) {
|
|
671
|
+
return fontsMap.loading.indexOf(name) !== -1;
|
|
672
|
+
};
|
|
673
|
+
var isFontActive = function isFontActive(name) {
|
|
674
|
+
return fontsMap.active.indexOf(name) !== -1;
|
|
675
|
+
};
|
|
676
|
+
var addFontLoading = function addFontLoading(name) {
|
|
677
|
+
fontsMap.active = fontsMap.active.filter(function (it) {
|
|
678
|
+
return it !== name;
|
|
679
|
+
});
|
|
680
|
+
fontsMap.loading = [].concat(_toConsumableArray(fontsMap.loading), [name]);
|
|
681
|
+
};
|
|
682
|
+
var removeFontLoading = function removeFontLoading(name) {
|
|
683
|
+
fontsMap.loading = fontsMap.loading.filter(function (it) {
|
|
684
|
+
return it !== name;
|
|
685
|
+
});
|
|
686
|
+
};
|
|
687
|
+
var addFontActive = function addFontActive(name) {
|
|
688
|
+
fontsMap.loading = fontsMap.loading.filter(function (it) {
|
|
689
|
+
return it !== name;
|
|
690
|
+
});
|
|
691
|
+
fontsMap.active = [].concat(_toConsumableArray(fontsMap.active), [name]);
|
|
692
|
+
};
|
|
693
|
+
var useLoadedFonts = function useLoadedFonts(fonts) {
|
|
694
|
+
var _useState = react.useState(false),
|
|
695
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
696
|
+
loaded = _useState2[0],
|
|
697
|
+
setLoaded = _useState2[1];
|
|
698
|
+
react.useEffect(function () {
|
|
699
|
+
var config = fonts.reduce(function (newConfig, font) {
|
|
700
|
+
var _ref = isObject(font) ? font : {
|
|
701
|
+
type: 'system',
|
|
702
|
+
name: font
|
|
703
|
+
},
|
|
704
|
+
type = _ref.type,
|
|
705
|
+
name = _ref.name,
|
|
706
|
+
_ref$variants = _ref.variants,
|
|
707
|
+
variants = _ref$variants === void 0 ? [] : _ref$variants;
|
|
708
|
+
if ((type === 'google' || type === 'custom') && !isFontLoading(name) && !isFontActive(name)) {
|
|
709
|
+
return _objectSpread(_objectSpread({}, newConfig), {}, _defineProperty({}, type, {
|
|
710
|
+
families: [].concat(_toConsumableArray(newConfig !== null ? (newConfig[type] || {}).families || [] : []), [type === 'google' ? [name, (variants || []).filter(function (it) {
|
|
711
|
+
return it !== null;
|
|
712
|
+
}).join(',')].filter(function (it) {
|
|
713
|
+
return it !== null && it.length > 0;
|
|
714
|
+
}).join(':') : [name, (variants !== null ? [{
|
|
715
|
+
fvd: 'n4'
|
|
716
|
+
}].concat(_toConsumableArray(variants)) : []).map(function (_ref2) {
|
|
717
|
+
var _ref2$fvd = _ref2.fvd,
|
|
718
|
+
fvd = _ref2$fvd === void 0 ? null : _ref2$fvd,
|
|
719
|
+
_ref2$weight = _ref2.weight,
|
|
720
|
+
weight = _ref2$weight === void 0 ? null : _ref2$weight,
|
|
721
|
+
_ref2$style = _ref2.style,
|
|
722
|
+
style = _ref2$style === void 0 ? null : _ref2$style;
|
|
723
|
+
return fvd || [style, weight].filter(function (it) {
|
|
724
|
+
return it !== null;
|
|
725
|
+
}).map(function (it) {
|
|
726
|
+
return "".concat(it).substr(0, 1);
|
|
727
|
+
}).join('');
|
|
728
|
+
}).filter(function (it) {
|
|
729
|
+
return it !== null && it.length > 0;
|
|
730
|
+
}).join(',')].filter(function (it) {
|
|
731
|
+
return it !== null && it.length > 0;
|
|
732
|
+
}).join(':')])
|
|
733
|
+
}));
|
|
734
|
+
}
|
|
735
|
+
return newConfig;
|
|
736
|
+
}, null);
|
|
737
|
+
var hasConfig = config !== null;
|
|
738
|
+
if (hasConfig && typeof window !== 'undefined') {
|
|
739
|
+
import('webfontloader').then(function (_ref3) {
|
|
740
|
+
var WebFont = _ref3["default"];
|
|
741
|
+
return WebFont.load(_objectSpread(_objectSpread({}, config), {}, {
|
|
742
|
+
timeout: 3000,
|
|
743
|
+
active: function active() {
|
|
744
|
+
return setLoaded(true);
|
|
745
|
+
},
|
|
746
|
+
fontloading: function fontloading(name) {
|
|
747
|
+
return addFontLoading(name);
|
|
748
|
+
},
|
|
749
|
+
fontactive: function fontactive(name) {
|
|
750
|
+
return addFontActive(name);
|
|
751
|
+
},
|
|
752
|
+
fontinactive: function fontinactive(name) {
|
|
753
|
+
return removeFontLoading(name);
|
|
754
|
+
}
|
|
755
|
+
}));
|
|
756
|
+
});
|
|
757
|
+
} else {
|
|
758
|
+
setLoaded(true);
|
|
759
|
+
}
|
|
760
|
+
}, [fonts, setLoaded]);
|
|
761
|
+
return {
|
|
762
|
+
loaded: loaded
|
|
763
|
+
};
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
var isTouchEvent = function isTouchEvent(event) {
|
|
767
|
+
return 'touches' in event;
|
|
768
|
+
};
|
|
769
|
+
var preventDefault = function preventDefault(event) {
|
|
770
|
+
if (!isTouchEvent(event)) return false;
|
|
771
|
+
if (event.touches.length < 2 && event.preventDefault) {
|
|
772
|
+
event.preventDefault();
|
|
773
|
+
}
|
|
774
|
+
return false;
|
|
775
|
+
};
|
|
776
|
+
var preventClickDefault = function preventClickDefault(e) {
|
|
777
|
+
if (e.preventDefault) {
|
|
778
|
+
e.preventDefault();
|
|
779
|
+
}
|
|
780
|
+
if (e.stopPropagation) {
|
|
781
|
+
e.stopPropagation();
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
var useLongPress = function useLongPress() {
|
|
785
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
786
|
+
_ref$onLongPress = _ref.onLongPress,
|
|
787
|
+
onLongPress = _ref$onLongPress === void 0 ? null : _ref$onLongPress,
|
|
788
|
+
_ref$onLongPressStart = _ref.onLongPressStart,
|
|
789
|
+
onLongPressStart = _ref$onLongPressStart === void 0 ? null : _ref$onLongPressStart,
|
|
790
|
+
_ref$onLongPressEnd = _ref.onLongPressEnd,
|
|
791
|
+
onLongPressEnd = _ref$onLongPressEnd === void 0 ? null : _ref$onLongPressEnd,
|
|
792
|
+
_ref$onClick = _ref.onClick,
|
|
793
|
+
onClick = _ref$onClick === void 0 ? null : _ref$onClick,
|
|
794
|
+
_ref$shouldPreventDef = _ref.shouldPreventDefault,
|
|
795
|
+
shouldPreventDefault = _ref$shouldPreventDef === void 0 ? true : _ref$shouldPreventDef,
|
|
796
|
+
_ref$shouldStopPropag = _ref.shouldStopPropagation,
|
|
797
|
+
shouldStopPropagation = _ref$shouldStopPropag === void 0 ? false : _ref$shouldStopPropag,
|
|
798
|
+
_ref$preventClick = _ref.preventClick,
|
|
799
|
+
preventClick = _ref$preventClick === void 0 ? false : _ref$preventClick,
|
|
800
|
+
_ref$delay = _ref.delay,
|
|
801
|
+
delay = _ref$delay === void 0 ? 350 : _ref$delay;
|
|
802
|
+
var _useState = react.useState(false),
|
|
803
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
804
|
+
pressed = _useState2[0],
|
|
805
|
+
setPressed = _useState2[1];
|
|
806
|
+
var _useState3 = react.useState(false),
|
|
807
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
808
|
+
triggered = _useState4[0],
|
|
809
|
+
setTriggered = _useState4[1];
|
|
810
|
+
var timeout = react.useRef(null);
|
|
811
|
+
var target = react.useRef(null);
|
|
812
|
+
var start = react.useCallback(function (event, props) {
|
|
813
|
+
setPressed(true);
|
|
814
|
+
if (shouldStopPropagation) {
|
|
815
|
+
event.stopPropagation();
|
|
816
|
+
}
|
|
817
|
+
if (event.target !== null) {
|
|
818
|
+
target.current = event.target;
|
|
819
|
+
}
|
|
820
|
+
if (onLongPressStart !== null) {
|
|
821
|
+
onLongPressStart(event, props);
|
|
822
|
+
}
|
|
823
|
+
timeout.current = setTimeout(function () {
|
|
824
|
+
if (shouldPreventDefault && target.current !== null) {
|
|
825
|
+
target.current.addEventListener('touchend', preventDefault, {
|
|
826
|
+
passive: false
|
|
827
|
+
});
|
|
828
|
+
target.current.addEventListener('click', preventClickDefault, {
|
|
829
|
+
passive: false
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
setTriggered(true);
|
|
833
|
+
if (onLongPress !== null) {
|
|
834
|
+
onLongPress(event, props);
|
|
835
|
+
setPressed(false);
|
|
836
|
+
}
|
|
837
|
+
timeout.current = null;
|
|
838
|
+
}, delay);
|
|
839
|
+
}, [onLongPress, onLongPressStart, delay, setPressed, shouldPreventDefault]);
|
|
840
|
+
var clear = react.useCallback(function (event, props) {
|
|
841
|
+
var shouldTriggerClick = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
842
|
+
setPressed(false);
|
|
843
|
+
if (preventClick && triggered) {
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
if (timeout.current !== null) {
|
|
847
|
+
clearTimeout(timeout.current);
|
|
848
|
+
} else if (shouldPreventDefault && target.current !== null) {
|
|
849
|
+
preventDefault(event);
|
|
850
|
+
target.current.removeEventListener('touchend', preventDefault);
|
|
851
|
+
setTimeout(function () {
|
|
852
|
+
target.current.removeEventListener('click', preventClickDefault);
|
|
853
|
+
}, 10);
|
|
854
|
+
}
|
|
855
|
+
if (shouldTriggerClick && !triggered && onClick !== null) {
|
|
856
|
+
onClick(props);
|
|
857
|
+
}
|
|
858
|
+
onLongPressEnd(event, props, triggered);
|
|
859
|
+
setTriggered(false);
|
|
860
|
+
}, [shouldPreventDefault, onClick, onLongPressEnd, setPressed, triggered, preventClick]);
|
|
861
|
+
var bind = function bind() {
|
|
862
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
863
|
+
return {
|
|
864
|
+
onMouseDown: function onMouseDown(e) {
|
|
865
|
+
return start(e, props);
|
|
866
|
+
},
|
|
867
|
+
onTouchStart: function onTouchStart(e) {
|
|
868
|
+
return start(e, props);
|
|
869
|
+
},
|
|
870
|
+
onMouseUp: function onMouseUp(e) {
|
|
871
|
+
return clear(e, props);
|
|
872
|
+
},
|
|
873
|
+
onMouseLeave: function onMouseLeave(e) {
|
|
874
|
+
return clear(e, props, false);
|
|
875
|
+
},
|
|
876
|
+
onTouchEnd: function onTouchEnd(e) {
|
|
877
|
+
return clear(e, props);
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
};
|
|
881
|
+
return {
|
|
882
|
+
bind: bind,
|
|
883
|
+
pressed: pressed,
|
|
884
|
+
triggered: triggered
|
|
885
|
+
};
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
var progressSteps = [0.1, 0.25, 0.5, 0.75, 0.9];
|
|
889
|
+
var useMediaApi = function useMediaApi() {
|
|
890
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
891
|
+
_ref$url = _ref.url,
|
|
892
|
+
url = _ref$url === void 0 ? null : _ref$url,
|
|
893
|
+
_ref$onTimeUpdate = _ref.onTimeUpdate,
|
|
894
|
+
onTimeUpdate = _ref$onTimeUpdate === void 0 ? null : _ref$onTimeUpdate,
|
|
895
|
+
_ref$onProgressStep = _ref.onProgressStep,
|
|
896
|
+
onProgressStep = _ref$onProgressStep === void 0 ? null : _ref$onProgressStep,
|
|
897
|
+
_ref$onDurationChange = _ref.onDurationChange,
|
|
898
|
+
onDurationChange = _ref$onDurationChange === void 0 ? null : _ref$onDurationChange,
|
|
899
|
+
_ref$onVolumeChange = _ref.onVolumeChange,
|
|
900
|
+
onVolumeChange = _ref$onVolumeChange === void 0 ? null : _ref$onVolumeChange,
|
|
901
|
+
_ref$onPlay = _ref.onPlay,
|
|
902
|
+
onPlay = _ref$onPlay === void 0 ? null : _ref$onPlay,
|
|
903
|
+
_ref$onPause = _ref.onPause,
|
|
904
|
+
onPause = _ref$onPause === void 0 ? null : _ref$onPause,
|
|
905
|
+
_ref$onEnded = _ref.onEnded,
|
|
906
|
+
onEnded = _ref$onEnded === void 0 ? null : _ref$onEnded,
|
|
907
|
+
_ref$onSeeked = _ref.onSeeked,
|
|
908
|
+
onSeeked = _ref$onSeeked === void 0 ? null : _ref$onSeeked,
|
|
909
|
+
_ref$onSuspend = _ref.onSuspend,
|
|
910
|
+
onSuspend = _ref$onSuspend === void 0 ? null : _ref$onSuspend,
|
|
911
|
+
_ref$onLoadStart = _ref.onLoadStart,
|
|
912
|
+
onLoadStart = _ref$onLoadStart === void 0 ? null : _ref$onLoadStart,
|
|
913
|
+
_ref$onCanPlayThough = _ref.onCanPlayThough,
|
|
914
|
+
onCanPlayThough = _ref$onCanPlayThough === void 0 ? null : _ref$onCanPlayThough,
|
|
915
|
+
_ref$onCanPlay = _ref.onCanPlay,
|
|
916
|
+
onCanPlay = _ref$onCanPlay === void 0 ? null : _ref$onCanPlay,
|
|
917
|
+
_ref$onLoadedData = _ref.onLoadedData,
|
|
918
|
+
onLoadedData = _ref$onLoadedData === void 0 ? null : _ref$onLoadedData,
|
|
919
|
+
_ref$onLoadedMetadata = _ref.onLoadedMetadata,
|
|
920
|
+
onLoadedMetadata = _ref$onLoadedMetadata === void 0 ? null : _ref$onLoadedMetadata;
|
|
921
|
+
var ref = react.useRef(null);
|
|
922
|
+
var _useState = react.useState(null),
|
|
923
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
924
|
+
currentTime = _useState2[0],
|
|
925
|
+
setCurrentTime = _useState2[1];
|
|
926
|
+
var _useState3 = react.useState(null),
|
|
927
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
928
|
+
duration = _useState4[0],
|
|
929
|
+
setDuration = _useState4[1];
|
|
930
|
+
var _useState5 = react.useState(false),
|
|
931
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
932
|
+
playing = _useState6[0],
|
|
933
|
+
setPlaying = _useState6[1];
|
|
934
|
+
var _useState7 = react.useState(false),
|
|
935
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
936
|
+
ready = _useState8[0],
|
|
937
|
+
setReady = _useState8[1];
|
|
938
|
+
var _useState9 = react.useState(false),
|
|
939
|
+
_useState0 = _slicedToArray(_useState9, 2),
|
|
940
|
+
dataReady = _useState0[0],
|
|
941
|
+
setDataReady = _useState0[1];
|
|
942
|
+
var _useState1 = react.useState(true),
|
|
943
|
+
_useState10 = _slicedToArray(_useState1, 2),
|
|
944
|
+
initialPlay = _useState10[0],
|
|
945
|
+
setInitialPlay = _useState10[1];
|
|
946
|
+
var _useState11 = react.useState(false),
|
|
947
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
948
|
+
suspended = _useState12[0],
|
|
949
|
+
setSuspended = _useState12[1];
|
|
950
|
+
var progressStepsReached = react.useRef({});
|
|
951
|
+
var paused = !playing;
|
|
952
|
+
|
|
953
|
+
// Exposed methods
|
|
954
|
+
|
|
955
|
+
var play = react.useCallback(function () {
|
|
956
|
+
var media = ref.current;
|
|
957
|
+
if (media !== null) {
|
|
958
|
+
media.play();
|
|
959
|
+
}
|
|
960
|
+
}, []);
|
|
961
|
+
var pause = react.useCallback(function () {
|
|
962
|
+
var media = ref.current;
|
|
963
|
+
if (media !== null) {
|
|
964
|
+
media.pause();
|
|
965
|
+
}
|
|
966
|
+
}, []);
|
|
967
|
+
var stop = react.useCallback(function () {
|
|
968
|
+
var media = ref.current;
|
|
969
|
+
if (media !== null) {
|
|
970
|
+
media.pause();
|
|
971
|
+
media.currentTime = 0;
|
|
972
|
+
}
|
|
973
|
+
}, []);
|
|
974
|
+
var seek = react.useCallback(function (time) {
|
|
975
|
+
var media = ref.current;
|
|
976
|
+
if (media !== null) {
|
|
977
|
+
media.currentTime = time;
|
|
978
|
+
}
|
|
979
|
+
}, []);
|
|
980
|
+
|
|
981
|
+
// const mute = useCallback(() => {
|
|
982
|
+
// const { current: media } = ref;
|
|
983
|
+
// if (media !== null) {
|
|
984
|
+
// media.muted = true;
|
|
985
|
+
// }
|
|
986
|
+
// }, []);
|
|
987
|
+
|
|
988
|
+
// const unMute = useCallback(() => {
|
|
989
|
+
// const { current: media } = ref;
|
|
990
|
+
// if (media !== null) {
|
|
991
|
+
// media.muted = false;
|
|
992
|
+
// }
|
|
993
|
+
// }, []);
|
|
994
|
+
|
|
995
|
+
// Media events callbacks
|
|
996
|
+
|
|
997
|
+
var onCustomPlay = react.useCallback(function () {
|
|
998
|
+
if (onPlay !== null) {
|
|
999
|
+
onPlay({
|
|
1000
|
+
initial: initialPlay
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
if (initialPlay) {
|
|
1004
|
+
setInitialPlay(false);
|
|
1005
|
+
}
|
|
1006
|
+
setPlaying(true);
|
|
1007
|
+
setSuspended(false);
|
|
1008
|
+
}, [initialPlay, setPlaying, onPlay]);
|
|
1009
|
+
var onCustomPlaying = react.useCallback(function () {
|
|
1010
|
+
setPlaying(true);
|
|
1011
|
+
setSuspended(false);
|
|
1012
|
+
}, []);
|
|
1013
|
+
var onCustomPause = react.useCallback(function (e) {
|
|
1014
|
+
var eventMedia = e.currentTarget;
|
|
1015
|
+
setPlaying(false);
|
|
1016
|
+
if (onPause !== null) {
|
|
1017
|
+
onPause({
|
|
1018
|
+
midway: eventMedia.currentTime > 0 && eventMedia.currentTime < eventMedia.duration
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
}, [setPlaying, onPause]);
|
|
1022
|
+
var onCustomEnded = react.useCallback(function (e) {
|
|
1023
|
+
var eventMedia = e.currentTarget;
|
|
1024
|
+
eventMedia.currentTime = 0;
|
|
1025
|
+
if (onEnded !== null) {
|
|
1026
|
+
onEnded();
|
|
1027
|
+
}
|
|
1028
|
+
setInitialPlay(true);
|
|
1029
|
+
}, [setInitialPlay, onEnded]);
|
|
1030
|
+
var onCustomTimeUpdate = react.useCallback(function (e) {
|
|
1031
|
+
var eventMedia = e.currentTarget;
|
|
1032
|
+
setCurrentTime(eventMedia.currentTime);
|
|
1033
|
+
if (onTimeUpdate !== null) {
|
|
1034
|
+
onTimeUpdate(eventMedia.currentTime);
|
|
1035
|
+
}
|
|
1036
|
+
var progress = eventMedia.currentTime / eventMedia.duration;
|
|
1037
|
+
var currentSteps = progressStepsReached.current;
|
|
1038
|
+
var stepsToTrack = progressSteps.filter(function (step) {
|
|
1039
|
+
return progress > step && typeof currentSteps[step] === 'undefined';
|
|
1040
|
+
});
|
|
1041
|
+
stepsToTrack.forEach(function (step) {
|
|
1042
|
+
if (onProgressStep !== null) {
|
|
1043
|
+
onProgressStep(step);
|
|
1044
|
+
}
|
|
1045
|
+
currentSteps[step] = true;
|
|
1046
|
+
});
|
|
1047
|
+
}, [setCurrentTime, onTimeUpdate, onProgressStep]);
|
|
1048
|
+
var onCustomDurationChange = react.useCallback(function (e) {
|
|
1049
|
+
var eventMedia = e.currentTarget;
|
|
1050
|
+
setDuration(eventMedia.duration);
|
|
1051
|
+
if (onDurationChange !== null) {
|
|
1052
|
+
onDurationChange(eventMedia.duration);
|
|
1053
|
+
}
|
|
1054
|
+
}, [setDuration, onDurationChange]);
|
|
1055
|
+
var onCustomSeeked = react.useCallback(function (e) {
|
|
1056
|
+
var eventMedia = e.currentTarget;
|
|
1057
|
+
if (onSeeked !== null) {
|
|
1058
|
+
onSeeked(eventMedia.currentTime);
|
|
1059
|
+
}
|
|
1060
|
+
}, [onSeeked]);
|
|
1061
|
+
var onCustomVolumeChange = react.useCallback(function (e) {
|
|
1062
|
+
var eventMedia = e.currentTarget;
|
|
1063
|
+
|
|
1064
|
+
// setMuted(eventMedia.muted);
|
|
1065
|
+
if (onVolumeChange !== null) {
|
|
1066
|
+
onVolumeChange(eventMedia.volume);
|
|
1067
|
+
}
|
|
1068
|
+
}, [onVolumeChange]);
|
|
1069
|
+
var onCustomLoadStart = react.useCallback(function () {
|
|
1070
|
+
if (onLoadStart !== null) {
|
|
1071
|
+
onLoadStart();
|
|
1072
|
+
}
|
|
1073
|
+
}, [setReady, onLoadStart]);
|
|
1074
|
+
var onCustomCanPlayThrough = react.useCallback(function () {
|
|
1075
|
+
setReady(true);
|
|
1076
|
+
if (onCanPlayThough !== null) {
|
|
1077
|
+
onCanPlayThough();
|
|
1078
|
+
}
|
|
1079
|
+
}, [setReady, onCanPlayThough]);
|
|
1080
|
+
var onCustomCanPlay = react.useCallback(function () {
|
|
1081
|
+
setReady(true);
|
|
1082
|
+
if (onCanPlay !== null) {
|
|
1083
|
+
onCanPlay();
|
|
1084
|
+
}
|
|
1085
|
+
}, [setReady, onCanPlay]);
|
|
1086
|
+
var onCustomLoadedMetadata = react.useCallback(function () {
|
|
1087
|
+
setReady(true);
|
|
1088
|
+
if (onLoadedMetadata !== null) {
|
|
1089
|
+
onLoadedMetadata();
|
|
1090
|
+
}
|
|
1091
|
+
}, [setReady, onLoadedMetadata]);
|
|
1092
|
+
var onCustomLoadedData = react.useCallback(function () {
|
|
1093
|
+
setDataReady(true);
|
|
1094
|
+
if (onLoadedData !== null) {
|
|
1095
|
+
onLoadedData();
|
|
1096
|
+
}
|
|
1097
|
+
}, [setDataReady, onLoadedData]);
|
|
1098
|
+
var onCustomSuspended = react.useCallback(function () {
|
|
1099
|
+
setSuspended(true);
|
|
1100
|
+
if (onSuspend !== null) {
|
|
1101
|
+
onSuspend();
|
|
1102
|
+
}
|
|
1103
|
+
}, [setSuspended, onSuspended]);
|
|
1104
|
+
react.useEffect(function () {
|
|
1105
|
+
var _ref$current = ref.current,
|
|
1106
|
+
media = _ref$current === void 0 ? null : _ref$current;
|
|
1107
|
+
|
|
1108
|
+
// console.log('actions', url);
|
|
1109
|
+
|
|
1110
|
+
if (media !== null) {
|
|
1111
|
+
media.addEventListener('volumechange', onCustomVolumeChange);
|
|
1112
|
+
media.addEventListener('play', onCustomPlay);
|
|
1113
|
+
media.addEventListener('playing', onCustomPlaying);
|
|
1114
|
+
media.addEventListener('pause', onCustomPause);
|
|
1115
|
+
media.addEventListener('ended', onCustomEnded);
|
|
1116
|
+
media.addEventListener('seeked', onCustomSeeked);
|
|
1117
|
+
// media.addEventListener('loadstart', onCustomLoadStart);
|
|
1118
|
+
// media.addEventListener('canplaythrough', onCustomCanPlayThrough);
|
|
1119
|
+
// media.addEventListener('canplay', onCustomCanPlay);
|
|
1120
|
+
// media.addEventListener('loadedmetadata', onCustomLoadedMetadata);
|
|
1121
|
+
// media.addEventListener('loadeddata', onCustomLoadedData);
|
|
1122
|
+
}
|
|
1123
|
+
return function () {
|
|
1124
|
+
if (media !== null) {
|
|
1125
|
+
media.removeEventListener('volumechange', onCustomVolumeChange);
|
|
1126
|
+
media.removeEventListener('play', onCustomPlay);
|
|
1127
|
+
media.removeEventListener('playing', onCustomPlaying);
|
|
1128
|
+
media.removeEventListener('pause', onCustomPause);
|
|
1129
|
+
media.removeEventListener('ended', onCustomEnded);
|
|
1130
|
+
media.removeEventListener('seeked', onCustomSeeked);
|
|
1131
|
+
// media.removeEventListener('loadstart', onCustomLoadStart);
|
|
1132
|
+
// media.removeEventListener('canplaythrough', onCustomCanPlayThrough);
|
|
1133
|
+
// media.removeEventListener('canplay', onCustomCanPlay);
|
|
1134
|
+
// media.removeEventListener('loadedmetadata', onCustomLoadedMetadata);
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
}, [url, onCustomVolumeChange, onCustomPlay, onCustomPause, onCustomEnded, onCustomSeeked, onCustomSuspended
|
|
1138
|
+
// onCustomLoadStart,
|
|
1139
|
+
// onCustomCanPlayThrough,
|
|
1140
|
+
// onCustomCanPlay,
|
|
1141
|
+
// onCustomLoadedMetadata,
|
|
1142
|
+
]);
|
|
1143
|
+
react.useEffect(function () {
|
|
1144
|
+
var _ref$current2 = ref.current,
|
|
1145
|
+
media = _ref$current2 === void 0 ? null : _ref$current2;
|
|
1146
|
+
if (media !== null) {
|
|
1147
|
+
media.addEventListener('loadstart', onCustomLoadStart);
|
|
1148
|
+
media.addEventListener('canplaythrough', onCustomCanPlayThrough);
|
|
1149
|
+
media.addEventListener('canplay', onCustomCanPlay);
|
|
1150
|
+
media.addEventListener('loadedmetadata', onCustomLoadedMetadata);
|
|
1151
|
+
media.addEventListener('loadeddata', onCustomLoadedData);
|
|
1152
|
+
media.addEventListener('suspend', onCustomSuspended);
|
|
1153
|
+
}
|
|
1154
|
+
return function () {
|
|
1155
|
+
if (media !== null) {
|
|
1156
|
+
media.removeEventListener('loadstart', onCustomLoadStart);
|
|
1157
|
+
media.removeEventListener('canplaythrough', onCustomCanPlayThrough);
|
|
1158
|
+
media.removeEventListener('canplay', onCustomCanPlay);
|
|
1159
|
+
media.removeEventListener('loadedmetadata', onCustomLoadedMetadata);
|
|
1160
|
+
media.removeEventListener('suspend', onCustomSuspended);
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
}, [url, onCustomLoadStart, onCustomCanPlayThrough, onCustomCanPlay, onCustomLoadedMetadata, onCustomSuspended]);
|
|
1164
|
+
|
|
1165
|
+
// Duration
|
|
1166
|
+
react.useEffect(function () {
|
|
1167
|
+
var _ref$current3 = ref.current,
|
|
1168
|
+
media = _ref$current3 === void 0 ? null : _ref$current3;
|
|
1169
|
+
if (media !== null) {
|
|
1170
|
+
media.addEventListener('durationchange', onCustomDurationChange);
|
|
1171
|
+
}
|
|
1172
|
+
return function () {
|
|
1173
|
+
if (media !== null) {
|
|
1174
|
+
media.removeEventListener('durationchange', onCustomDurationChange);
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
}, [url, onCustomDurationChange]);
|
|
1178
|
+
|
|
1179
|
+
// Timeupdate
|
|
1180
|
+
react.useEffect(function () {
|
|
1181
|
+
var _ref$current4 = ref.current,
|
|
1182
|
+
media = _ref$current4 === void 0 ? null : _ref$current4;
|
|
1183
|
+
// console.log('timeupdate', url);
|
|
1184
|
+
if (media !== null) {
|
|
1185
|
+
media.addEventListener('timeupdate', onCustomTimeUpdate);
|
|
1186
|
+
}
|
|
1187
|
+
return function () {
|
|
1188
|
+
if (media !== null) {
|
|
1189
|
+
media.removeEventListener('timeupdate', onCustomTimeUpdate);
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
}, [url, onCustomTimeUpdate, onCustomDurationChange]);
|
|
1193
|
+
react.useEffect(function () {
|
|
1194
|
+
var _ref$current5 = ref.current,
|
|
1195
|
+
media = _ref$current5 === void 0 ? null : _ref$current5;
|
|
1196
|
+
if (media !== null && media.readyState > 1) {
|
|
1197
|
+
setDataReady(true);
|
|
1198
|
+
} else {
|
|
1199
|
+
setDataReady(false);
|
|
1200
|
+
}
|
|
1201
|
+
if (media !== null && media.readyState > 3) {
|
|
1202
|
+
setReady(true);
|
|
1203
|
+
} else {
|
|
1204
|
+
setReady(false);
|
|
1205
|
+
}
|
|
1206
|
+
}, [url]);
|
|
1207
|
+
return {
|
|
1208
|
+
ref: ref,
|
|
1209
|
+
play: play,
|
|
1210
|
+
pause: pause,
|
|
1211
|
+
stop: stop,
|
|
1212
|
+
seek: seek,
|
|
1213
|
+
currentTime: currentTime,
|
|
1214
|
+
duration: duration,
|
|
1215
|
+
playing: playing,
|
|
1216
|
+
paused: paused,
|
|
1217
|
+
ready: ready,
|
|
1218
|
+
dataReady: dataReady,
|
|
1219
|
+
suspended: suspended
|
|
1220
|
+
};
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1223
|
+
var useMediaBuffering = function useMediaBuffering() {
|
|
1224
|
+
var mediaElement = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
1225
|
+
var _useState = react.useState(false),
|
|
1226
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1227
|
+
buffering = _useState2[0],
|
|
1228
|
+
setBuffering = _useState2[1];
|
|
1229
|
+
react.useEffect(function () {
|
|
1230
|
+
if (mediaElement === null) {
|
|
1231
|
+
return function () {};
|
|
1232
|
+
}
|
|
1233
|
+
function onBufferingEvent(e) {
|
|
1234
|
+
// networkstate
|
|
1235
|
+
if (mediaElement.networkState === mediaElement.NETWORK_LOADING) {
|
|
1236
|
+
// The user agent is actively trying to download data.
|
|
1237
|
+
setBuffering(true);
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// readystate
|
|
1241
|
+
if (mediaElement.readyState < mediaElement.HAVE_FUTURE_DATA) {
|
|
1242
|
+
// There is not enough data to keep playing from this point
|
|
1243
|
+
setBuffering(true);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
function onPlay() {
|
|
1247
|
+
setBuffering(false);
|
|
1248
|
+
}
|
|
1249
|
+
function onPlaying() {
|
|
1250
|
+
setBuffering(false);
|
|
1251
|
+
}
|
|
1252
|
+
function onPause() {
|
|
1253
|
+
setBuffering(false);
|
|
1254
|
+
}
|
|
1255
|
+
function onEnded() {
|
|
1256
|
+
setBuffering(false);
|
|
1257
|
+
}
|
|
1258
|
+
mediaElement.addEventListener('waiting', onBufferingEvent);
|
|
1259
|
+
mediaElement.addEventListener('stalled', onBufferingEvent);
|
|
1260
|
+
mediaElement.addEventListener('play', onPlay);
|
|
1261
|
+
mediaElement.addEventListener('playing', onPlaying);
|
|
1262
|
+
mediaElement.addEventListener('pause', onPause);
|
|
1263
|
+
mediaElement.addEventListener('ended', onEnded);
|
|
1264
|
+
return function () {
|
|
1265
|
+
mediaElement.removeEventListener('waiting', onBufferingEvent);
|
|
1266
|
+
mediaElement.removeEventListener('stalled', onBufferingEvent);
|
|
1267
|
+
mediaElement.removeEventListener('play', onPlay);
|
|
1268
|
+
mediaElement.removeEventListener('playing', onPlaying);
|
|
1269
|
+
mediaElement.removeEventListener('pause', onPause);
|
|
1270
|
+
mediaElement.removeEventListener('ended', onEnded);
|
|
1271
|
+
};
|
|
1272
|
+
}, [mediaElement]);
|
|
1273
|
+
|
|
1274
|
+
// useEffect(() => {
|
|
1275
|
+
// if (mediaElement === null) {
|
|
1276
|
+
// return () => {};
|
|
1277
|
+
// }
|
|
1278
|
+
// let lastPlayPos = 0;
|
|
1279
|
+
// let currentPlayPos = 0;
|
|
1280
|
+
// let bufferingDetected = false;
|
|
1281
|
+
|
|
1282
|
+
// function checkBuffering(player, checkInterval) {
|
|
1283
|
+
// currentPlayPos = player.currentTime;
|
|
1284
|
+
|
|
1285
|
+
// // checking offset should be at most the check interval
|
|
1286
|
+
// // but allow for some margin
|
|
1287
|
+
// const offset = (checkInterval - 20) / 1000;
|
|
1288
|
+
|
|
1289
|
+
// // if no buffering is currently detected,
|
|
1290
|
+
// // and the position does not seem to increase
|
|
1291
|
+
// // and the player isn't manually paused...
|
|
1292
|
+
// if (!bufferingDetected && currentPlayPos < lastPlayPos + offset && !player.paused) {
|
|
1293
|
+
// console.log('buffering!');
|
|
1294
|
+
// bufferingDetected = true;
|
|
1295
|
+
// }
|
|
1296
|
+
|
|
1297
|
+
// // if we were buffering but the player has advanced,
|
|
1298
|
+
// // then there is no buffering
|
|
1299
|
+
// if (bufferingDetected && currentPlayPos > lastPlayPos + offset && !player.paused) {
|
|
1300
|
+
// console.log('not buffering anymore!');
|
|
1301
|
+
// bufferingDetected = false;
|
|
1302
|
+
// }
|
|
1303
|
+
// lastPlayPos = currentPlayPos;
|
|
1304
|
+
|
|
1305
|
+
// return bufferingDetected;
|
|
1306
|
+
// }
|
|
1307
|
+
|
|
1308
|
+
// const id = setInterval(() => {
|
|
1309
|
+
// setBuffering(checkBuffering(mediaElement, interval));
|
|
1310
|
+
// }, interval);
|
|
1311
|
+
|
|
1312
|
+
// return () => {
|
|
1313
|
+
// clearInterval(id);
|
|
1314
|
+
// };
|
|
1315
|
+
// }, [mediaElement, interval]);
|
|
1316
|
+
|
|
1317
|
+
return {
|
|
1318
|
+
buffering: buffering
|
|
1319
|
+
};
|
|
1320
|
+
};
|
|
1321
|
+
|
|
1322
|
+
var useMediaState = function useMediaState() {
|
|
1323
|
+
var mediaElement = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
1324
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1325
|
+
_ref$playing = _ref.playing,
|
|
1326
|
+
wantedPlaying = _ref$playing === void 0 ? false : _ref$playing,
|
|
1327
|
+
_ref$muted = _ref.muted,
|
|
1328
|
+
wantedMuted = _ref$muted === void 0 ? false : _ref$muted;
|
|
1329
|
+
var debug = react.useMemo(function () {
|
|
1330
|
+
var mediaKey = mediaElement !== null && isString(mediaElement.src) ? mediaElement.src.split('/')[mediaElement.src.split('/').length - 1].split('#')[0] || null : null;
|
|
1331
|
+
return createDebug(mediaKey !== null ? "micromag:media:".concat(mediaKey) : 'micromag:media');
|
|
1332
|
+
}, [mediaElement]);
|
|
1333
|
+
var _useState = react.useState(wantedPlaying),
|
|
1334
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1335
|
+
playing = _useState2[0],
|
|
1336
|
+
setPlaying = _useState2[1];
|
|
1337
|
+
var _useState3 = react.useState(false),
|
|
1338
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
1339
|
+
buffering = _useState4[0],
|
|
1340
|
+
setBuffering = _useState4[1];
|
|
1341
|
+
var _useState5 = react.useState(mediaElement !== null && (mediaElement.muted || mediaElement.volume === 0) || wantedMuted),
|
|
1342
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
1343
|
+
muted = _useState6[0],
|
|
1344
|
+
setMuted = _useState6[1];
|
|
1345
|
+
react.useEffect(function () {
|
|
1346
|
+
debug('State change %o', {
|
|
1347
|
+
playing: playing,
|
|
1348
|
+
buffering: buffering,
|
|
1349
|
+
muted: muted
|
|
1350
|
+
});
|
|
1351
|
+
}, [playing, buffering, muted, debug]);
|
|
1352
|
+
react.useEffect(function () {
|
|
1353
|
+
if (mediaElement === null) {
|
|
1354
|
+
setPlaying(wantedPlaying);
|
|
1355
|
+
setBuffering(false);
|
|
1356
|
+
setMuted(wantedMuted);
|
|
1357
|
+
debug('Unset media: %o', {
|
|
1358
|
+
wantedPlaying: wantedPlaying,
|
|
1359
|
+
wantedMuted: wantedMuted
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
}, [mediaElement, debug, wantedPlaying, wantedMuted]);
|
|
1363
|
+
react.useEffect(function () {
|
|
1364
|
+
if (mediaElement === null) {
|
|
1365
|
+
return function () {};
|
|
1366
|
+
}
|
|
1367
|
+
function onBufferingEvent(e) {
|
|
1368
|
+
// networkstate
|
|
1369
|
+
if (mediaElement.networkState === mediaElement.NETWORK_LOADING) {
|
|
1370
|
+
debug('onBufferingEvent: NETWORK_LOADING');
|
|
1371
|
+
setBuffering(true);
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
// readystate
|
|
1375
|
+
if (mediaElement.readyState < mediaElement.HAVE_FUTURE_DATA) {
|
|
1376
|
+
debug('onBufferingEvent: HAVE_FUTURE_DATA');
|
|
1377
|
+
setBuffering(true);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
function onPlay() {
|
|
1381
|
+
debug('onPlay');
|
|
1382
|
+
setPlaying(true);
|
|
1383
|
+
setBuffering(false);
|
|
1384
|
+
}
|
|
1385
|
+
function onPlaying() {
|
|
1386
|
+
debug('onPlaying');
|
|
1387
|
+
setPlaying(true);
|
|
1388
|
+
setBuffering(false);
|
|
1389
|
+
}
|
|
1390
|
+
function onTimeUpdate(e) {
|
|
1391
|
+
debug('onTimeUpdate');
|
|
1392
|
+
setPlaying(!e.currentTarget.paused && !e.currentTarget.ended);
|
|
1393
|
+
setBuffering(false);
|
|
1394
|
+
}
|
|
1395
|
+
function onPause() {
|
|
1396
|
+
debug('onPause');
|
|
1397
|
+
setPlaying(false);
|
|
1398
|
+
setBuffering(false);
|
|
1399
|
+
}
|
|
1400
|
+
function onEnded() {
|
|
1401
|
+
debug('onEnded');
|
|
1402
|
+
setPlaying(false);
|
|
1403
|
+
setBuffering(false);
|
|
1404
|
+
}
|
|
1405
|
+
function onSuspend(e) {
|
|
1406
|
+
debug('onSuspend');
|
|
1407
|
+
setPlaying(!e.currentTarget.paused && !e.currentTarget.ended);
|
|
1408
|
+
setBuffering(false);
|
|
1409
|
+
}
|
|
1410
|
+
function onVolumeChange() {
|
|
1411
|
+
setMuted(mediaElement.muted || mediaElement.volume === 0);
|
|
1412
|
+
}
|
|
1413
|
+
if (mediaElement.paused || mediaElement.ended) {
|
|
1414
|
+
setPlaying(false);
|
|
1415
|
+
}
|
|
1416
|
+
if (muted !== mediaElement.muted) {
|
|
1417
|
+
setMuted(mediaElement.muted);
|
|
1418
|
+
}
|
|
1419
|
+
mediaElement.addEventListener('waiting', onBufferingEvent);
|
|
1420
|
+
mediaElement.addEventListener('stalled', onBufferingEvent);
|
|
1421
|
+
mediaElement.addEventListener('timeupdate', onTimeUpdate);
|
|
1422
|
+
mediaElement.addEventListener('play', onPlay);
|
|
1423
|
+
mediaElement.addEventListener('playing', onPlaying);
|
|
1424
|
+
mediaElement.addEventListener('pause', onPause);
|
|
1425
|
+
mediaElement.addEventListener('suspend', onSuspend);
|
|
1426
|
+
mediaElement.addEventListener('ended', onEnded);
|
|
1427
|
+
mediaElement.addEventListener('volumechange', onVolumeChange);
|
|
1428
|
+
return function () {
|
|
1429
|
+
mediaElement.removeEventListener('waiting', onBufferingEvent);
|
|
1430
|
+
mediaElement.removeEventListener('stalled', onBufferingEvent);
|
|
1431
|
+
mediaElement.removeEventListener('timeupdate', onTimeUpdate);
|
|
1432
|
+
mediaElement.removeEventListener('play', onPlay);
|
|
1433
|
+
mediaElement.removeEventListener('playing', onPlaying);
|
|
1434
|
+
mediaElement.removeEventListener('pause', onPause);
|
|
1435
|
+
mediaElement.removeEventListener('suspend', onSuspend);
|
|
1436
|
+
mediaElement.removeEventListener('ended', onEnded);
|
|
1437
|
+
mediaElement.removeEventListener('volumechange', onVolumeChange);
|
|
1438
|
+
};
|
|
1439
|
+
}, [mediaElement, debug]);
|
|
1440
|
+
return {
|
|
1441
|
+
playing: playing,
|
|
1442
|
+
muted: muted,
|
|
1443
|
+
buffering: buffering
|
|
1444
|
+
};
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1447
|
+
function useMediaTimestampOffset(element) {
|
|
1448
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1449
|
+
_ref$attributeName = _ref.attributeName,
|
|
1450
|
+
attributeName = _ref$attributeName === void 0 ? 'data-ts-offset' : _ref$attributeName;
|
|
1451
|
+
var getTimestampOffset = function getTimestampOffset() {
|
|
1452
|
+
return element !== null && element.hasAttribute(attributeName) ? parseFloat(element.getAttribute(attributeName)) : 0;
|
|
1453
|
+
};
|
|
1454
|
+
var _useState = react.useState(getTimestampOffset()),
|
|
1455
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1456
|
+
timestampOffset = _useState2[0],
|
|
1457
|
+
setTimestampOffset = _useState2[1];
|
|
1458
|
+
var observerRef = react.useRef(null);
|
|
1459
|
+
react.useEffect(function () {
|
|
1460
|
+
if (element !== null) {
|
|
1461
|
+
observerRef.current = new MutationObserver(function (mutations) {
|
|
1462
|
+
mutations.forEach(function (_ref2) {
|
|
1463
|
+
var mutationType = _ref2.type;
|
|
1464
|
+
if (mutationType === 'attributes') {
|
|
1465
|
+
setTimestampOffset(getTimestampOffset());
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1468
|
+
});
|
|
1469
|
+
observerRef.current.observe(element, {
|
|
1470
|
+
attributes: true,
|
|
1471
|
+
attributeFilter: [attributeName]
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
return function () {
|
|
1475
|
+
if (observerRef.current !== null) {
|
|
1476
|
+
observerRef.current.disconnect();
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
}, [element]);
|
|
1480
|
+
return timestampOffset;
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
function useMediaCurrentTime(element) {
|
|
1484
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1485
|
+
_ref$id = _ref.id,
|
|
1486
|
+
id = _ref$id === void 0 ? null : _ref$id,
|
|
1487
|
+
_ref$disabled = _ref.disabled,
|
|
1488
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
1489
|
+
_ref$updateInterval = _ref.updateInterval,
|
|
1490
|
+
updateInterval = _ref$updateInterval === void 0 ? 1000 : _ref$updateInterval,
|
|
1491
|
+
_ref$onUpdate = _ref.onUpdate,
|
|
1492
|
+
customOnUpdate = _ref$onUpdate === void 0 ? null : _ref$onUpdate;
|
|
1493
|
+
var _useState = react.useState(0),
|
|
1494
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1495
|
+
currentTime = _useState2[0],
|
|
1496
|
+
setCurrentTime = _useState2[1];
|
|
1497
|
+
var realCurrentTime = react.useRef(currentTime);
|
|
1498
|
+
var tsOffset = useMediaTimestampOffset(element);
|
|
1499
|
+
var finalId = id || element;
|
|
1500
|
+
var lastIdRef = react.useRef(finalId);
|
|
1501
|
+
var idChanged = lastIdRef.current !== finalId;
|
|
1502
|
+
var disabledRef = react.useRef(disabled);
|
|
1503
|
+
var disabledChanged = disabledRef.current !== disabled;
|
|
1504
|
+
if (idChanged || disabledChanged) {
|
|
1505
|
+
realCurrentTime.current = element !== null ? Math.max((element.currentTime || 0) - tsOffset, 0) : 0;
|
|
1506
|
+
lastIdRef.current = finalId;
|
|
1507
|
+
disabledRef.current = disabled;
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
// Check time update
|
|
1511
|
+
react.useEffect(function () {
|
|
1512
|
+
if (element === null) {
|
|
1513
|
+
return function () {};
|
|
1514
|
+
}
|
|
1515
|
+
function updateTime() {
|
|
1516
|
+
var time = Math.max((element.currentTime || 0) - tsOffset, 0);
|
|
1517
|
+
if (time !== realCurrentTime.current) {
|
|
1518
|
+
realCurrentTime.current = time;
|
|
1519
|
+
setCurrentTime(time);
|
|
1520
|
+
if (customOnUpdate !== null) {
|
|
1521
|
+
customOnUpdate(time);
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
return time;
|
|
1525
|
+
}
|
|
1526
|
+
if (disabled) {
|
|
1527
|
+
updateTime();
|
|
1528
|
+
return function () {};
|
|
1529
|
+
}
|
|
1530
|
+
var timeout = null;
|
|
1531
|
+
function loop() {
|
|
1532
|
+
var _element$duration = element.duration,
|
|
1533
|
+
duration = _element$duration === void 0 ? 0 : _element$duration;
|
|
1534
|
+
var time = updateTime();
|
|
1535
|
+
var remainingTime = Math.floor(((duration || 0) - time) * 1000);
|
|
1536
|
+
timeout = setTimeout(loop, Math.max(Math.min(updateInterval, remainingTime), updateInterval));
|
|
1537
|
+
}
|
|
1538
|
+
loop();
|
|
1539
|
+
return function () {
|
|
1540
|
+
if (element !== null) {
|
|
1541
|
+
realCurrentTime.current = element.currentTime - tsOffset;
|
|
1542
|
+
}
|
|
1543
|
+
if (timeout !== null) {
|
|
1544
|
+
clearInterval(timeout);
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
}, [id, element, setCurrentTime, disabled, updateInterval]);
|
|
1548
|
+
return realCurrentTime.current;
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
function useMediaDuration(element) {
|
|
1552
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1553
|
+
_ref$id = _ref.id,
|
|
1554
|
+
id = _ref$id === void 0 ? null : _ref$id;
|
|
1555
|
+
var _useState = react.useState(element !== null ? element.duration || 0 : 0),
|
|
1556
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1557
|
+
duration = _useState2[0],
|
|
1558
|
+
setDuration = _useState2[1];
|
|
1559
|
+
var tsOffset = useMediaTimestampOffset(element);
|
|
1560
|
+
var realDuration = react.useRef(duration);
|
|
1561
|
+
var finalId = id || element;
|
|
1562
|
+
var lastIdRef = react.useRef(finalId);
|
|
1563
|
+
var idChanged = lastIdRef.current !== finalId;
|
|
1564
|
+
if (idChanged) {
|
|
1565
|
+
realDuration.current = element !== null ? Math.max((element.duration || 0) - tsOffset, 0) : 0;
|
|
1566
|
+
lastIdRef.current = finalId;
|
|
1567
|
+
}
|
|
1568
|
+
react.useEffect(function () {
|
|
1569
|
+
if (element === null) {
|
|
1570
|
+
realDuration.current = 0;
|
|
1571
|
+
setDuration(0);
|
|
1572
|
+
return function () {};
|
|
1573
|
+
}
|
|
1574
|
+
function updateDuration() {
|
|
1575
|
+
var newDuration = Math.max((element.duration || 0) - tsOffset, 0);
|
|
1576
|
+
if (newDuration !== realDuration.current) {
|
|
1577
|
+
realDuration.current = newDuration;
|
|
1578
|
+
setDuration(newDuration);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
updateDuration();
|
|
1582
|
+
element.addEventListener('canplay', updateDuration);
|
|
1583
|
+
element.addEventListener('loadedmetadata', updateDuration);
|
|
1584
|
+
element.addEventListener('durationchange', updateDuration);
|
|
1585
|
+
return function () {
|
|
1586
|
+
element.removeEventListener('canplay', updateDuration);
|
|
1587
|
+
element.removeEventListener('loadedmetadata', updateDuration);
|
|
1588
|
+
element.removeEventListener('durationchange', updateDuration);
|
|
1589
|
+
};
|
|
1590
|
+
}, [element, id, setDuration]);
|
|
1591
|
+
return realDuration.current;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
function useMediaLoad(element) {
|
|
1595
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1596
|
+
_ref$preload = _ref.preload,
|
|
1597
|
+
preload = _ref$preload === void 0 ? 'auto' : _ref$preload,
|
|
1598
|
+
_ref$shouldLoad = _ref.shouldLoad,
|
|
1599
|
+
shouldLoad = _ref$shouldLoad === void 0 ? false : _ref$shouldLoad;
|
|
1600
|
+
var firstPreloadRef = react.useRef(preload);
|
|
1601
|
+
var firstShouldLoadRef = react.useRef(shouldLoad);
|
|
1602
|
+
var hasLoadedRef = react.useRef(preload !== 'none' && preload !== 'metadata' && shouldLoad);
|
|
1603
|
+
react.useEffect(function () {
|
|
1604
|
+
var canLoad = preload !== 'none' && preload !== 'metadata' && shouldLoad;
|
|
1605
|
+
var preloadHasChanged = firstPreloadRef.current !== preload;
|
|
1606
|
+
var shouldLoadHasChanged = firstShouldLoadRef.current !== shouldLoad;
|
|
1607
|
+
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current && element !== null && typeof element.load !== 'undefined') {
|
|
1608
|
+
hasLoadedRef.current = true;
|
|
1609
|
+
element.load();
|
|
1610
|
+
}
|
|
1611
|
+
}, [element, shouldLoad, preload]);
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
var _excluded$1 = ["disabled"];
|
|
1615
|
+
function useMediaProgress(media) {
|
|
1616
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1617
|
+
_ref$disabled = _ref.disabled,
|
|
1618
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
1619
|
+
props = _objectWithoutProperties(_ref, _excluded$1);
|
|
1620
|
+
var _useState = react.useState(!disabled),
|
|
1621
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1622
|
+
playing = _useState2[0],
|
|
1623
|
+
setPlaying = _useState2[1];
|
|
1624
|
+
var duration = useMediaDuration(media, _objectSpread({
|
|
1625
|
+
disabled: disabled || !playing
|
|
1626
|
+
}, props));
|
|
1627
|
+
var _useState3 = react.useState(0),
|
|
1628
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
1629
|
+
progress = _useState4[0],
|
|
1630
|
+
setProgress = _useState4[1];
|
|
1631
|
+
var realProgressRef = react.useRef(progress);
|
|
1632
|
+
var updateTimeRef = react.useRef(Date.now() / 1000);
|
|
1633
|
+
var updateProgress = react.useCallback(function (newProgress) {
|
|
1634
|
+
updateTimeRef.current = Date.now() / 1000;
|
|
1635
|
+
realProgressRef.current = newProgress;
|
|
1636
|
+
setProgress(newProgress);
|
|
1637
|
+
}, [setProgress]);
|
|
1638
|
+
react.useEffect(function () {
|
|
1639
|
+
if (media !== null) {
|
|
1640
|
+
var value = (media.currentTime || 0) > 0 && media.duration > 0 ? media.currentTime / media.duration : 0;
|
|
1641
|
+
updateProgress(value);
|
|
1642
|
+
setPlaying(!media.paused && media.readyState === 4);
|
|
1643
|
+
} else {
|
|
1644
|
+
updateProgress(0);
|
|
1645
|
+
setPlaying(false);
|
|
1646
|
+
}
|
|
1647
|
+
}, [media, disabled, setPlaying]);
|
|
1648
|
+
react.useEffect(function () {
|
|
1649
|
+
if (media === null) {
|
|
1650
|
+
return function () {};
|
|
1651
|
+
}
|
|
1652
|
+
function onResume(e) {
|
|
1653
|
+
setPlaying(true);
|
|
1654
|
+
var newProgress = media.currentTime / media.duration;
|
|
1655
|
+
updateProgress(newProgress);
|
|
1656
|
+
}
|
|
1657
|
+
function onUpdate(e) {
|
|
1658
|
+
setPlaying(!e.currentTarget.paused && !e.currentTarget.ended);
|
|
1659
|
+
var newProgress = media.currentTime / media.duration;
|
|
1660
|
+
updateProgress(newProgress);
|
|
1661
|
+
}
|
|
1662
|
+
function onPause() {
|
|
1663
|
+
setPlaying(false);
|
|
1664
|
+
var newProgress = media.currentTime / media.duration;
|
|
1665
|
+
updateProgress(newProgress);
|
|
1666
|
+
}
|
|
1667
|
+
media.addEventListener('play', onResume);
|
|
1668
|
+
media.addEventListener('playing', onResume);
|
|
1669
|
+
media.addEventListener('seeked', onUpdate);
|
|
1670
|
+
// media.addEventListener('timeupdate', onUpdate);
|
|
1671
|
+
media.addEventListener('pause', onPause);
|
|
1672
|
+
media.addEventListener('ended', onPause);
|
|
1673
|
+
media.addEventListener('waiting', onPause);
|
|
1674
|
+
media.addEventListener('stalled', onPause);
|
|
1675
|
+
media.addEventListener('seeking', onPause);
|
|
1676
|
+
media.addEventListener('suspend', onUpdate);
|
|
1677
|
+
// if (media.paused) {
|
|
1678
|
+
// onPause();
|
|
1679
|
+
// } else {
|
|
1680
|
+
// onResume();
|
|
1681
|
+
// }
|
|
1682
|
+
return function () {
|
|
1683
|
+
media.removeEventListener('play', onResume);
|
|
1684
|
+
media.removeEventListener('seeked', onResume);
|
|
1685
|
+
media.removeEventListener('playing', onResume);
|
|
1686
|
+
// media.removeEventListener('timeupdate', onResume);
|
|
1687
|
+
media.removeEventListener('pause', onPause);
|
|
1688
|
+
media.removeEventListener('ended', onPause);
|
|
1689
|
+
media.removeEventListener('waiting', onPause);
|
|
1690
|
+
media.removeEventListener('stalled', onPause);
|
|
1691
|
+
media.removeEventListener('seeking', onPause);
|
|
1692
|
+
media.removeEventListener('suspend', onUpdate);
|
|
1693
|
+
};
|
|
1694
|
+
}, [media, updateProgress, setPlaying, playing]);
|
|
1695
|
+
react.useEffect(function () {
|
|
1696
|
+
if (media === null || !playing || disabled) {
|
|
1697
|
+
return function () {};
|
|
1698
|
+
}
|
|
1699
|
+
var handle;
|
|
1700
|
+
var canceled = false;
|
|
1701
|
+
function tick() {
|
|
1702
|
+
if (canceled) {
|
|
1703
|
+
return;
|
|
1704
|
+
}
|
|
1705
|
+
var newTime = Date.now() / 1000;
|
|
1706
|
+
var elapsed = newTime - updateTimeRef.current;
|
|
1707
|
+
var step = elapsed / duration;
|
|
1708
|
+
var newProgress = realProgressRef.current < 0.1 ? media.currentTime / media.duration : realProgressRef.current + step;
|
|
1709
|
+
updateProgress(newProgress);
|
|
1710
|
+
handle = raf(tick);
|
|
1711
|
+
}
|
|
1712
|
+
tick();
|
|
1713
|
+
return function () {
|
|
1714
|
+
canceled = true;
|
|
1715
|
+
raf.cancel(handle);
|
|
1716
|
+
};
|
|
1717
|
+
}, [media, playing, disabled, duration, updateProgress]);
|
|
1718
|
+
return realProgressRef.current;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
function useMediaReady(element) {
|
|
1722
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1723
|
+
_ref$id = _ref.id,
|
|
1724
|
+
id = _ref$id === void 0 ? null : _ref$id;
|
|
1725
|
+
var _useState = react.useState(element !== null && element.readyState > 0),
|
|
1726
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1727
|
+
ready = _useState2[0],
|
|
1728
|
+
setReady = _useState2[1];
|
|
1729
|
+
var realReady = react.useRef(ready);
|
|
1730
|
+
var lastIdRef = react.useRef(id);
|
|
1731
|
+
var idChanged = lastIdRef.current !== id;
|
|
1732
|
+
if (idChanged) {
|
|
1733
|
+
realReady.current = false;
|
|
1734
|
+
lastIdRef.current = id;
|
|
1735
|
+
}
|
|
1736
|
+
react.useEffect(function () {
|
|
1737
|
+
if (element === null) {
|
|
1738
|
+
return function () {};
|
|
1739
|
+
}
|
|
1740
|
+
function updateReady() {
|
|
1741
|
+
var currentReady = ready;
|
|
1742
|
+
if (element.readyState > 0 && !ready) {
|
|
1743
|
+
setReady(true);
|
|
1744
|
+
currentReady = true;
|
|
1745
|
+
} else if (ready && element.readyState === 0) {
|
|
1746
|
+
setReady(false);
|
|
1747
|
+
currentReady = false;
|
|
1748
|
+
}
|
|
1749
|
+
realReady.current = currentReady;
|
|
1750
|
+
return currentReady;
|
|
1751
|
+
}
|
|
1752
|
+
var currentReady = updateReady();
|
|
1753
|
+
if (!currentReady) {
|
|
1754
|
+
element.addEventListener('loadedmetadata', updateReady);
|
|
1755
|
+
element.addEventListener('canplay', updateReady);
|
|
1756
|
+
element.addEventListener('canplaythrough', updateReady);
|
|
1757
|
+
}
|
|
1758
|
+
return function () {
|
|
1759
|
+
if (!currentReady) {
|
|
1760
|
+
element.removeEventListener('loadedmetadata', updateReady);
|
|
1761
|
+
element.removeEventListener('canplay', updateReady);
|
|
1762
|
+
element.removeEventListener('canplaythrough', updateReady);
|
|
1763
|
+
}
|
|
1764
|
+
};
|
|
1765
|
+
}, [element, id]);
|
|
1766
|
+
return realReady.current;
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
var useMediasParser = function useMediasParser() {
|
|
1770
|
+
var screensManager = contexts.useScreensManager();
|
|
1771
|
+
var fieldsManager = contexts.useFieldsManager();
|
|
1772
|
+
|
|
1773
|
+
// Convert medias object to path
|
|
1774
|
+
var parser = react.useMemo(function () {
|
|
1775
|
+
return new core.MediasParser({
|
|
1776
|
+
screensManager: screensManager,
|
|
1777
|
+
fieldsManager: fieldsManager
|
|
1778
|
+
});
|
|
1779
|
+
}, [screensManager, fieldsManager]);
|
|
1780
|
+
var toPath = react.useCallback(function (story) {
|
|
1781
|
+
return parser.toPath(story);
|
|
1782
|
+
}, [parser]);
|
|
1783
|
+
var fromPath = react.useCallback(function (story) {
|
|
1784
|
+
return parser.fromPath(story);
|
|
1785
|
+
}, [parser]);
|
|
1786
|
+
return {
|
|
1787
|
+
toPath: toPath,
|
|
1788
|
+
fromPath: fromPath,
|
|
1789
|
+
parser: parser
|
|
1790
|
+
};
|
|
1791
|
+
};
|
|
1792
|
+
|
|
1793
|
+
function useMediaThumbnail(media) {
|
|
1794
|
+
var file = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1795
|
+
var thumbnail = react.useMemo(function () {
|
|
1796
|
+
if (isObject(file)) {
|
|
1797
|
+
return file;
|
|
1798
|
+
}
|
|
1799
|
+
var _ref = media || {},
|
|
1800
|
+
_ref$thumbnail_url = _ref.thumbnail_url,
|
|
1801
|
+
defaultThumbnailUrl = _ref$thumbnail_url === void 0 ? null : _ref$thumbnail_url,
|
|
1802
|
+
_ref$files = _ref.files,
|
|
1803
|
+
files = _ref$files === void 0 ? null : _ref$files,
|
|
1804
|
+
_ref$metadata = _ref.metadata,
|
|
1805
|
+
metadata = _ref$metadata === void 0 ? null : _ref$metadata;
|
|
1806
|
+
var _ref2 = metadata || {},
|
|
1807
|
+
mediaWidth = _ref2.width,
|
|
1808
|
+
mediaHeight = _ref2.height;
|
|
1809
|
+
var filesArray = utils.getMediaFilesAsArray(files) || [];
|
|
1810
|
+
var _ref3 = (file !== null ? filesArray.find(function (_ref4) {
|
|
1811
|
+
var handle = _ref4.handle;
|
|
1812
|
+
return handle === file;
|
|
1813
|
+
}) || null : null) || {},
|
|
1814
|
+
_ref3$url = _ref3.url,
|
|
1815
|
+
url = _ref3$url === void 0 ? null : _ref3$url;
|
|
1816
|
+
return url !== null || defaultThumbnailUrl !== null ? {
|
|
1817
|
+
url: url || defaultThumbnailUrl,
|
|
1818
|
+
metadata: {
|
|
1819
|
+
width: mediaWidth,
|
|
1820
|
+
height: mediaHeight
|
|
1821
|
+
}
|
|
1822
|
+
} : null;
|
|
1823
|
+
}, [media, file]);
|
|
1824
|
+
return thumbnail;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
function useMediaWaveform(media) {
|
|
1828
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1829
|
+
_ref$fake = _ref.fake,
|
|
1830
|
+
fake = _ref$fake === void 0 ? false : _ref$fake,
|
|
1831
|
+
_ref$reduceBufferFact = _ref.reduceBufferFactor,
|
|
1832
|
+
reduceBufferFactor = _ref$reduceBufferFact === void 0 ? 100 : _ref$reduceBufferFact;
|
|
1833
|
+
var _ref2 = media || {},
|
|
1834
|
+
_ref2$url = _ref2.url,
|
|
1835
|
+
url = _ref2$url === void 0 ? null : _ref2$url,
|
|
1836
|
+
_ref2$metadata = _ref2.metadata,
|
|
1837
|
+
metadata = _ref2$metadata === void 0 ? null : _ref2$metadata;
|
|
1838
|
+
var _ref3 = metadata || {},
|
|
1839
|
+
_ref3$waveform = _ref3.waveform,
|
|
1840
|
+
waveform = _ref3$waveform === void 0 ? null : _ref3$waveform;
|
|
1841
|
+
var _useState = react.useState(null),
|
|
1842
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1843
|
+
audioLevels = _useState2[0],
|
|
1844
|
+
setAudioLevels = _useState2[1];
|
|
1845
|
+
react.useEffect(function () {
|
|
1846
|
+
var canceled = false;
|
|
1847
|
+
var AudioContext = typeof window !== 'undefined' ? window.AudioContext || window.webkitAudioContext : null;
|
|
1848
|
+
if (waveform !== null) {
|
|
1849
|
+
setAudioLevels(waveform.map(function (it) {
|
|
1850
|
+
return (it + 256 / 2) / 256;
|
|
1851
|
+
}));
|
|
1852
|
+
} else if (url !== null && fake) {
|
|
1853
|
+
var fakeLength = 1000;
|
|
1854
|
+
setAudioLevels(_toConsumableArray(new Array(fakeLength)).map(function () {
|
|
1855
|
+
return Math.random();
|
|
1856
|
+
}));
|
|
1857
|
+
} else if (url !== null && AudioContext !== null) {
|
|
1858
|
+
fetch(url, {
|
|
1859
|
+
mode: 'cors'
|
|
1860
|
+
}).then(function (response) {
|
|
1861
|
+
if (canceled) {
|
|
1862
|
+
throw new Error('Audio loading canceled');
|
|
1863
|
+
}
|
|
1864
|
+
return response.arrayBuffer();
|
|
1865
|
+
}).then(function (arrayBuffer) {
|
|
1866
|
+
if (canceled) {
|
|
1867
|
+
throw new Error('Audio loading canceled');
|
|
1868
|
+
}
|
|
1869
|
+
var audioCtx = new AudioContext();
|
|
1870
|
+
return audioCtx.decodeAudioData(arrayBuffer);
|
|
1871
|
+
}).then(function (buffer) {
|
|
1872
|
+
var channelsCount = buffer.numberOfChannels;
|
|
1873
|
+
if (channelsCount > 0) {
|
|
1874
|
+
var leftChannelData = buffer.getChannelData(0);
|
|
1875
|
+
setAudioLevels(leftChannelData.reduce(function (newArray, level) {
|
|
1876
|
+
// eslint-disable-next-line no-param-reassign
|
|
1877
|
+
newArray[newArray.length] = Math.abs(level);
|
|
1878
|
+
return newArray;
|
|
1879
|
+
}, []));
|
|
1880
|
+
}
|
|
1881
|
+
})["catch"](function (e) {
|
|
1882
|
+
throw e;
|
|
1883
|
+
});
|
|
1884
|
+
}
|
|
1885
|
+
return function () {
|
|
1886
|
+
if (url === null) {
|
|
1887
|
+
canceled = true;
|
|
1888
|
+
}
|
|
1889
|
+
};
|
|
1890
|
+
}, [url, waveform, setAudioLevels, reduceBufferFactor, fake]);
|
|
1891
|
+
return audioLevels;
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
// const debug = createDebug('core:useParsedStory');
|
|
1895
|
+
|
|
1896
|
+
var useParsedStory = function useParsedStory(story) {
|
|
1897
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1898
|
+
_ref$disabled = _ref.disabled,
|
|
1899
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
1900
|
+
_ref$withTheme = _ref.withTheme,
|
|
1901
|
+
withTheme = _ref$withTheme === void 0 ? true : _ref$withTheme,
|
|
1902
|
+
_ref$withMedias = _ref.withMedias,
|
|
1903
|
+
withMedias = _ref$withMedias === void 0 ? true : _ref$withMedias,
|
|
1904
|
+
_ref$withFonts = _ref.withFonts,
|
|
1905
|
+
withFonts = _ref$withFonts === void 0 ? true : _ref$withFonts,
|
|
1906
|
+
_ref$withMigrations = _ref.withMigrations,
|
|
1907
|
+
withMigrations = _ref$withMigrations === void 0 ? true : _ref$withMigrations;
|
|
1908
|
+
var screensManager = contexts.useScreensManager();
|
|
1909
|
+
var fieldsManager = contexts.useFieldsManager();
|
|
1910
|
+
var parser = react.useMemo(function () {
|
|
1911
|
+
return new core.StoryParser({
|
|
1912
|
+
screensManager: screensManager,
|
|
1913
|
+
fieldsManager: fieldsManager,
|
|
1914
|
+
fieldsPattern: screensManager.getFieldsPattern()
|
|
1915
|
+
});
|
|
1916
|
+
}, [screensManager, fieldsManager]);
|
|
1917
|
+
var newStory = react.useMemo(function () {
|
|
1918
|
+
if (disabled) {
|
|
1919
|
+
return story;
|
|
1920
|
+
}
|
|
1921
|
+
return parser.parse(story, {
|
|
1922
|
+
withMedias: withMedias,
|
|
1923
|
+
withTheme: withTheme,
|
|
1924
|
+
withFonts: withFonts,
|
|
1925
|
+
withMigrations: withMigrations
|
|
1926
|
+
});
|
|
1927
|
+
}, [parser, disabled, withMedias, withTheme, withFonts, story]);
|
|
1928
|
+
return newStory;
|
|
1929
|
+
};
|
|
1930
|
+
|
|
1931
|
+
var usePlaceholderStyle = function usePlaceholderStyle(className, placeholderStyle) {
|
|
1932
|
+
return "\n .".concat(className, "::placeholder {\n ").concat(placeholderStyle.color ? "color: ".concat(placeholderStyle.color, ";") : '', "\n ").concat(placeholderStyle.fontSize ? "font-size: ".concat(placeholderStyle.fontSize, ";") : '', "\n ").concat(placeholderStyle.fontStyle ? "font-style: ".concat(placeholderStyle.fontStyle, ";") : '', "\n ").concat(placeholderStyle.fontWeight ? "font-weight: ".concat(placeholderStyle.fontWeight, ";") : '', "\n ").concat(placeholderStyle.fontFamily ? "font-family: ".concat(placeholderStyle.fontFamily, ";") : '', "\n ").concat(placeholderStyle.textAlign ? "text-align: ".concat(placeholderStyle.textAlign, ";") : '', "\n }\n ");
|
|
1933
|
+
};
|
|
1934
|
+
|
|
1935
|
+
function useProgressSteps() {
|
|
1936
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1937
|
+
_ref$disabled = _ref.disabled,
|
|
1938
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
1939
|
+
currentTime = _ref.currentTime,
|
|
1940
|
+
duration = _ref.duration,
|
|
1941
|
+
_ref$onStep = _ref.onStep,
|
|
1942
|
+
onStep = _ref$onStep === void 0 ? null : _ref$onStep,
|
|
1943
|
+
_ref$steps = _ref.steps,
|
|
1944
|
+
steps = _ref$steps === void 0 ? [0.1, 0.25, 0.5, 0.75, 0.9] : _ref$steps;
|
|
1945
|
+
var progressStepsReached = react.useRef({});
|
|
1946
|
+
react.useEffect(function () {
|
|
1947
|
+
if (duration === 0 || disabled) {
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
var progress = currentTime / duration;
|
|
1951
|
+
var currentSteps = progressStepsReached.current;
|
|
1952
|
+
var stepsToTrack = steps.filter(function (step) {
|
|
1953
|
+
return progress > step && typeof currentSteps[step] === 'undefined';
|
|
1954
|
+
});
|
|
1955
|
+
stepsToTrack.forEach(function (step) {
|
|
1956
|
+
if (onStep !== null) {
|
|
1957
|
+
onStep(step, {
|
|
1958
|
+
duration: duration,
|
|
1959
|
+
currentTime: currentTime
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
currentSteps[step] = true;
|
|
1963
|
+
});
|
|
1964
|
+
}, [duration, currentTime, disabled]);
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
var _excluded = ["width", "height"];
|
|
1968
|
+
var useDevicePixelRatio = function useDevicePixelRatio() {
|
|
1969
|
+
var _useState = react.useState(1),
|
|
1970
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1971
|
+
pixelRatio = _useState2[0],
|
|
1972
|
+
setPixelRatio = _useState2[1];
|
|
1973
|
+
react.useEffect(function () {
|
|
1974
|
+
setPixelRatio(typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1);
|
|
1975
|
+
}, [setPixelRatio]);
|
|
1976
|
+
return pixelRatio;
|
|
1977
|
+
};
|
|
1978
|
+
var useScreenSize = function useScreenSize(_ref) {
|
|
1979
|
+
var _ref$width = _ref.width,
|
|
1980
|
+
width = _ref$width === void 0 ? null : _ref$width,
|
|
1981
|
+
_ref$height = _ref.height,
|
|
1982
|
+
height = _ref$height === void 0 ? null : _ref$height,
|
|
1983
|
+
_ref$landscape = _ref.landscape,
|
|
1984
|
+
landscape = _ref$landscape === void 0 ? false : _ref$landscape,
|
|
1985
|
+
_ref$menuOverScreen = _ref.menuOverScreen,
|
|
1986
|
+
menuOverScreen = _ref$menuOverScreen === void 0 ? false : _ref$menuOverScreen,
|
|
1987
|
+
_ref$screens = _ref.screens,
|
|
1988
|
+
screens = _ref$screens === void 0 ? [] : _ref$screens,
|
|
1989
|
+
_ref$mediaType = _ref.mediaType,
|
|
1990
|
+
mediaType = _ref$mediaType === void 0 ? 'screen' : _ref$mediaType,
|
|
1991
|
+
_ref$media = _ref.media,
|
|
1992
|
+
providedMedia = _ref$media === void 0 ? null : _ref$media,
|
|
1993
|
+
_ref$scale = _ref.scale,
|
|
1994
|
+
scale = _ref$scale === void 0 ? null : _ref$scale;
|
|
1995
|
+
var devicePixelRatio = useDevicePixelRatio();
|
|
1996
|
+
var screenSize = react.useMemo(function () {
|
|
1997
|
+
var media = providedMedia !== null ? providedMedia : {
|
|
1998
|
+
type: mediaType,
|
|
1999
|
+
width: "".concat(width, "px"),
|
|
2000
|
+
height: "".concat(height, "px")
|
|
2001
|
+
};
|
|
2002
|
+
var matchingScreens = _toConsumableArray(screens).reverse().filter(function (_ref2) {
|
|
2003
|
+
var _ref2$mediaQuery = _ref2.mediaQuery,
|
|
2004
|
+
mediaQuery = _ref2$mediaQuery === void 0 ? null : _ref2$mediaQuery;
|
|
2005
|
+
return mediaQuery === null || cssMediaquery.match(mediaQuery, media);
|
|
2006
|
+
});
|
|
2007
|
+
return {
|
|
2008
|
+
screen: matchingScreens.length > 0 ? matchingScreens[0].name : null,
|
|
2009
|
+
screens: _toConsumableArray(matchingScreens).reverse().map(function (_ref3) {
|
|
2010
|
+
var name = _ref3.name;
|
|
2011
|
+
return name;
|
|
2012
|
+
}),
|
|
2013
|
+
width: width,
|
|
2014
|
+
height: height,
|
|
2015
|
+
landscape: landscape,
|
|
2016
|
+
menuOverScreen: menuOverScreen,
|
|
2017
|
+
resolution: scale !== null ? scale * devicePixelRatio : devicePixelRatio,
|
|
2018
|
+
imageResolution: scale !== null ? Math.max(scale, devicePixelRatio) : devicePixelRatio
|
|
2019
|
+
};
|
|
2020
|
+
}, [screens, providedMedia, mediaType, width, height, landscape, menuOverScreen]);
|
|
2021
|
+
return screenSize;
|
|
2022
|
+
};
|
|
2023
|
+
var useScreenSizeFromElement = function useScreenSizeFromElement() {
|
|
2024
|
+
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
2025
|
+
_ref4$width = _ref4.width,
|
|
2026
|
+
width = _ref4$width === void 0 ? null : _ref4$width,
|
|
2027
|
+
_ref4$height = _ref4.height,
|
|
2028
|
+
height = _ref4$height === void 0 ? null : _ref4$height,
|
|
2029
|
+
opts = _objectWithoutProperties(_ref4, _excluded);
|
|
2030
|
+
var _useDimensionObserver = useDimensionObserver(),
|
|
2031
|
+
ref = _useDimensionObserver.ref,
|
|
2032
|
+
_useDimensionObserver2 = _useDimensionObserver.width,
|
|
2033
|
+
calculatedWidth = _useDimensionObserver2 === void 0 ? 0 : _useDimensionObserver2,
|
|
2034
|
+
_useDimensionObserver3 = _useDimensionObserver.height,
|
|
2035
|
+
calculatedHeight = _useDimensionObserver3 === void 0 ? 0 : _useDimensionObserver3;
|
|
2036
|
+
var devicePixelRatio = useDevicePixelRatio();
|
|
2037
|
+
var fullWidth = width !== null ? width : calculatedWidth;
|
|
2038
|
+
var fullHeight = height !== null ? height : calculatedHeight;
|
|
2039
|
+
var _ref5 = opts || {},
|
|
2040
|
+
_ref5$screenWidth = _ref5.screenWidth,
|
|
2041
|
+
screenWidth = _ref5$screenWidth === void 0 ? 320 : _ref5$screenWidth,
|
|
2042
|
+
_ref5$screenHeight = _ref5.screenHeight,
|
|
2043
|
+
screenHeight = _ref5$screenHeight === void 0 ? 480 : _ref5$screenHeight,
|
|
2044
|
+
_ref5$withoutMaxSize = _ref5.withoutMaxSize,
|
|
2045
|
+
withoutMaxSize = _ref5$withoutMaxSize === void 0 ? false : _ref5$withoutMaxSize,
|
|
2046
|
+
_ref5$landscapeMinHei = _ref5.landscapeMinHeight,
|
|
2047
|
+
landscapeMinHeight = _ref5$landscapeMinHei === void 0 ? 600 : _ref5$landscapeMinHei,
|
|
2048
|
+
_ref5$menuAlwaysOverS = _ref5.menuAlwaysOverScreen,
|
|
2049
|
+
menuAlwaysOverScreen = _ref5$menuAlwaysOverS === void 0 ? true : _ref5$menuAlwaysOverS,
|
|
2050
|
+
_ref5$landscapeMinRat = _ref5.landscapeMinRatio,
|
|
2051
|
+
landscapeMinRatio = _ref5$landscapeMinRat === void 0 ? 2 / 3 : _ref5$landscapeMinRat,
|
|
2052
|
+
_ref5$withoutScale = _ref5.withoutScale,
|
|
2053
|
+
withoutScale = _ref5$withoutScale === void 0 ? false : _ref5$withoutScale;
|
|
2054
|
+
var screenRatio = screenWidth / screenHeight;
|
|
2055
|
+
var elementRatio = fullWidth / fullHeight;
|
|
2056
|
+
var landscape = fullHeight > 0 && elementRatio > (landscapeMinRatio || screenRatio);
|
|
2057
|
+
var landscapeWithMaxSize = landscape && !withoutMaxSize;
|
|
2058
|
+
var finalWidth = fullWidth;
|
|
2059
|
+
var finalHeight = fullHeight;
|
|
2060
|
+
var menuOverScreen = !landscape;
|
|
2061
|
+
if (landscapeWithMaxSize) {
|
|
2062
|
+
if (fullHeight < landscapeMinHeight || menuAlwaysOverScreen) {
|
|
2063
|
+
menuOverScreen = true;
|
|
2064
|
+
} else {
|
|
2065
|
+
finalHeight = fullHeight - 100;
|
|
2066
|
+
}
|
|
2067
|
+
finalWidth = Math.round(finalHeight * screenRatio);
|
|
2068
|
+
}
|
|
2069
|
+
if (finalWidth % 2 === 1) {
|
|
2070
|
+
finalWidth -= 1;
|
|
2071
|
+
}
|
|
2072
|
+
if (finalHeight % 2 === 1) {
|
|
2073
|
+
finalHeight -= 1;
|
|
2074
|
+
}
|
|
2075
|
+
var scale = finalWidth > 0 ? finalWidth / screenWidth : null;
|
|
2076
|
+
var screenSize = useScreenSize(_objectSpread({
|
|
2077
|
+
width: withoutScale || scale === null ? finalWidth : screenWidth,
|
|
2078
|
+
height: withoutScale || scale === null ? finalHeight : finalHeight / scale,
|
|
2079
|
+
landscape: landscape,
|
|
2080
|
+
menuOverScreen: menuOverScreen,
|
|
2081
|
+
scale: !withoutScale ? scale : null
|
|
2082
|
+
}, opts));
|
|
2083
|
+
return {
|
|
2084
|
+
ref: ref,
|
|
2085
|
+
fullWidth: fullWidth,
|
|
2086
|
+
fullHeight: fullHeight,
|
|
2087
|
+
screenSize: screenSize,
|
|
2088
|
+
scale: !withoutScale ? scale : null,
|
|
2089
|
+
resolution: !withoutScale ? scale * devicePixelRatio : devicePixelRatio
|
|
2090
|
+
};
|
|
2091
|
+
};
|
|
2092
|
+
var getWindowSize = function getWindowSize() {
|
|
2093
|
+
return {
|
|
2094
|
+
width: typeof window !== 'undefined' ? window.innerWidth : null,
|
|
2095
|
+
height: typeof window !== 'undefined' ? window.innerHæeight : null
|
|
2096
|
+
};
|
|
2097
|
+
};
|
|
2098
|
+
var useScreenSizeFromWindow = function useScreenSizeFromWindow(opts) {
|
|
2099
|
+
var _useState3 = react.useState(getWindowSize()),
|
|
2100
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
2101
|
+
windowSize = _useState4[0],
|
|
2102
|
+
setWindowSize = _useState4[1];
|
|
2103
|
+
react.useEffect(function () {
|
|
2104
|
+
var onResize = function onResize() {
|
|
2105
|
+
return setWindowSize(getWindowSize());
|
|
2106
|
+
};
|
|
2107
|
+
if (typeof window !== 'undefined') {
|
|
2108
|
+
window.addEventListener('resize', onResize);
|
|
2109
|
+
}
|
|
2110
|
+
return function () {
|
|
2111
|
+
if (typeof window !== 'undefined') {
|
|
2112
|
+
window.removeEventListener('resize', onResize);
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
}, [setWindowSize]);
|
|
2116
|
+
return useScreenSize(_objectSpread(_objectSpread({}, opts), windowSize));
|
|
2117
|
+
};
|
|
2118
|
+
|
|
2119
|
+
var getValueFromSpring = function getValueFromSpring(s) {
|
|
2120
|
+
var _ref = s || {},
|
|
2121
|
+
_ref$value = _ref.value,
|
|
2122
|
+
v = _ref$value === void 0 ? null : _ref$value;
|
|
2123
|
+
var _ref2 = v || {},
|
|
2124
|
+
p = _ref2.progress;
|
|
2125
|
+
return p;
|
|
2126
|
+
};
|
|
2127
|
+
function useSpringValue(wantedProgress, immediate, params) {
|
|
2128
|
+
var _useState = react.useState(wantedProgress),
|
|
2129
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
2130
|
+
progress = _useState2[0],
|
|
2131
|
+
setProgress = _useState2[1];
|
|
2132
|
+
var onChange = react.useCallback(function (spring) {
|
|
2133
|
+
return setProgress(getValueFromSpring(spring));
|
|
2134
|
+
}, [setProgress]);
|
|
2135
|
+
core$1.useSpring(_objectSpread({
|
|
2136
|
+
progress: wantedProgress,
|
|
2137
|
+
onChange: onChange,
|
|
2138
|
+
immediate: immediate
|
|
2139
|
+
}, params));
|
|
2140
|
+
return immediate ? wantedProgress : progress;
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
var useSwipe = function useSwipe() {
|
|
2144
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
2145
|
+
_ref$width = _ref.width,
|
|
2146
|
+
width = _ref$width === void 0 ? null : _ref$width,
|
|
2147
|
+
_ref$items = _ref.items,
|
|
2148
|
+
items = _ref$items === void 0 ? [] : _ref$items,
|
|
2149
|
+
_ref$withSpring = _ref.withSpring,
|
|
2150
|
+
withSpring = _ref$withSpring === void 0 ? true : _ref$withSpring,
|
|
2151
|
+
_ref$swipeWidthThresh = _ref.swipeWidthThreshold,
|
|
2152
|
+
swipeWidthThreshold = _ref$swipeWidthThresh === void 0 ? 3 : _ref$swipeWidthThresh,
|
|
2153
|
+
_ref$animateScale = _ref.animateScale,
|
|
2154
|
+
animateScale = _ref$animateScale === void 0 ? false : _ref$animateScale,
|
|
2155
|
+
_ref$disabled = _ref.disabled,
|
|
2156
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
2157
|
+
_ref$lockAxis = _ref.lockAxis,
|
|
2158
|
+
lockAxis = _ref$lockAxis === void 0 ? false : _ref$lockAxis,
|
|
2159
|
+
_ref$onSwipeStart = _ref.onSwipeStart,
|
|
2160
|
+
onSwipeStart = _ref$onSwipeStart === void 0 ? null : _ref$onSwipeStart,
|
|
2161
|
+
_ref$onSwipeEnd = _ref.onSwipeEnd,
|
|
2162
|
+
onSwipeEnd = _ref$onSwipeEnd === void 0 ? null : _ref$onSwipeEnd,
|
|
2163
|
+
_ref$onSwipeCancel = _ref.onSwipeCancel,
|
|
2164
|
+
onSwipeCancel = _ref$onSwipeCancel === void 0 ? null : _ref$onSwipeCancel,
|
|
2165
|
+
_ref$onTap = _ref.onTap,
|
|
2166
|
+
onTap = _ref$onTap === void 0 ? null : _ref$onTap;
|
|
2167
|
+
var swipingIndex = react.useRef(null);
|
|
2168
|
+
var index = react.useRef(0);
|
|
2169
|
+
var lockedAxis = react.useRef(null);
|
|
2170
|
+
var hasWidth = width !== null;
|
|
2171
|
+
var windowWidth = typeof window !== 'undefined' && !hasWidth ? window.innerWidth : null;
|
|
2172
|
+
var currentWidth = hasWidth ? width : windowWidth;
|
|
2173
|
+
var count = items.length;
|
|
2174
|
+
var getItem = react.useCallback(function () {
|
|
2175
|
+
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
2176
|
+
var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
2177
|
+
var scale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
2178
|
+
return {
|
|
2179
|
+
x: x,
|
|
2180
|
+
zIndex: idx,
|
|
2181
|
+
scale: scale
|
|
2182
|
+
};
|
|
2183
|
+
});
|
|
2184
|
+
var getItems = react.useCallback(function () {
|
|
2185
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
2186
|
+
_ref2$down = _ref2.down,
|
|
2187
|
+
down = _ref2$down === void 0 ? false : _ref2$down,
|
|
2188
|
+
_ref2$mx = _ref2.mx,
|
|
2189
|
+
mx = _ref2$mx === void 0 ? 0 : _ref2$mx;
|
|
2190
|
+
return items.map(function (item, i) {
|
|
2191
|
+
var x = disabled ? 0 : (i - index.current) * currentWidth + (down ? mx : 0);
|
|
2192
|
+
var scale = !animateScale || disabled || !down ? 1 : 1 - Math.abs(mx) / currentWidth / 2;
|
|
2193
|
+
return getItem(x, i, scale);
|
|
2194
|
+
});
|
|
2195
|
+
}, [disabled, items, index, currentWidth, animateScale]);
|
|
2196
|
+
|
|
2197
|
+
// Initial items state
|
|
2198
|
+
var _useSprings = core$1.useSprings(items.length, function (i) {
|
|
2199
|
+
return {
|
|
2200
|
+
x: disabled ? 0 : i * currentWidth,
|
|
2201
|
+
y: 0,
|
|
2202
|
+
zIndex: i,
|
|
2203
|
+
config: _objectSpread({}, !withSpring ? {
|
|
2204
|
+
duration: 1
|
|
2205
|
+
} : null)
|
|
2206
|
+
};
|
|
2207
|
+
}),
|
|
2208
|
+
_useSprings2 = _slicedToArray(_useSprings, 2),
|
|
2209
|
+
itemsWithProps = _useSprings2[0],
|
|
2210
|
+
set = _useSprings2[1];
|
|
2211
|
+
var bind = react$1.useDrag(function (_ref3) {
|
|
2212
|
+
var down = _ref3.down,
|
|
2213
|
+
_ref3$movement = _slicedToArray(_ref3.movement, 2),
|
|
2214
|
+
mx = _ref3$movement[0],
|
|
2215
|
+
my = _ref3$movement[1],
|
|
2216
|
+
_ref3$direction = _slicedToArray(_ref3.direction, 1),
|
|
2217
|
+
xDir = _ref3$direction[0],
|
|
2218
|
+
cancel = _ref3.cancel,
|
|
2219
|
+
tap = _ref3.tap;
|
|
2220
|
+
if (disabled) {
|
|
2221
|
+
cancel();
|
|
2222
|
+
return;
|
|
2223
|
+
}
|
|
2224
|
+
if (!down && swipingIndex.current === index.current) {
|
|
2225
|
+
lockedAxis.current = null;
|
|
2226
|
+
if (onSwipeCancel !== null) {
|
|
2227
|
+
onSwipeCancel(index.current);
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
// Block first and last moves
|
|
2232
|
+
/*
|
|
2233
|
+
if (down && index.current === items.length - 1 && xDir < 0) {
|
|
2234
|
+
cancel();
|
|
2235
|
+
return;
|
|
2236
|
+
}
|
|
2237
|
+
if (down && index.current === 0 && xDir > 0) {
|
|
2238
|
+
cancel();
|
|
2239
|
+
return;
|
|
2240
|
+
}
|
|
2241
|
+
*/
|
|
2242
|
+
|
|
2243
|
+
var movementX = !lockAxis || lockedAxis.current === 'x' ? mx : 0;
|
|
2244
|
+
var movementY = !lockAxis || lockedAxis.current === 'y' ? my : 0;
|
|
2245
|
+
if (down) {
|
|
2246
|
+
// Snap to next slide
|
|
2247
|
+
if (Math.abs(movementX) > currentWidth / swipeWidthThreshold) {
|
|
2248
|
+
index.current = clamp(index.current + (xDir > 0 ? -1 : 1), 0, count - 1);
|
|
2249
|
+
lockedAxis.current = null;
|
|
2250
|
+
cancel();
|
|
2251
|
+
if (onSwipeEnd !== null) {
|
|
2252
|
+
onSwipeEnd(index.current);
|
|
2253
|
+
}
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
set(getItems({
|
|
2258
|
+
down: down,
|
|
2259
|
+
mx: movementX,
|
|
2260
|
+
my: movementY
|
|
2261
|
+
}));
|
|
2262
|
+
|
|
2263
|
+
// saving current swiping index in a ref in order to have a section called only once when swipe just started or a tap was detected
|
|
2264
|
+
if (swipingIndex.current !== index.current) {
|
|
2265
|
+
if (down && !tap) {
|
|
2266
|
+
if (onSwipeStart !== null) {
|
|
2267
|
+
onSwipeStart(index.current);
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
if (!down && tap) {
|
|
2271
|
+
if (onTap !== null) {
|
|
2272
|
+
onTap();
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
// lock swiping on axis from initial 3 pixels distance (Y axis requires to swipe down)
|
|
2278
|
+
if (lockAxis && down && lockedAxis.current === null) {
|
|
2279
|
+
var distanceX = Math.abs(mx);
|
|
2280
|
+
var distanceY = Math.abs(my);
|
|
2281
|
+
if (distanceX !== distanceY && (distanceY > 2 || distanceX > 2)) {
|
|
2282
|
+
lockedAxis.current = distanceY > distanceX ? 'y' : 'x';
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
swipingIndex.current = down && !tap ? index.current : null;
|
|
2286
|
+
}, {
|
|
2287
|
+
filterTaps: true
|
|
2288
|
+
});
|
|
2289
|
+
var reset = react.useCallback(function () {
|
|
2290
|
+
set(getItems());
|
|
2291
|
+
}, [disabled, items, index, currentWidth]);
|
|
2292
|
+
var setIndex = react.useCallback(function (idx) {
|
|
2293
|
+
index.current = idx;
|
|
2294
|
+
reset();
|
|
2295
|
+
}, [reset]);
|
|
2296
|
+
|
|
2297
|
+
// Reset on resize or others
|
|
2298
|
+
react.useEffect(function () {
|
|
2299
|
+
set(getItems());
|
|
2300
|
+
}, [items, width, set, disabled]);
|
|
2301
|
+
return {
|
|
2302
|
+
items: itemsWithProps,
|
|
2303
|
+
bind: bind,
|
|
2304
|
+
index: index.current,
|
|
2305
|
+
setIndex: setIndex
|
|
2306
|
+
};
|
|
2307
|
+
};
|
|
2308
|
+
|
|
2309
|
+
var useThemeParser = function useThemeParser() {
|
|
2310
|
+
var screensManager = contexts.useScreensManager();
|
|
2311
|
+
var parser = react.useMemo(function () {
|
|
2312
|
+
return new core.ThemeParser({
|
|
2313
|
+
screensManager: screensManager
|
|
2314
|
+
});
|
|
2315
|
+
}, [screensManager]);
|
|
2316
|
+
var parse = react.useCallback(function (story) {
|
|
2317
|
+
return parser.parse(story);
|
|
2318
|
+
}, [parser]);
|
|
2319
|
+
return parse;
|
|
2320
|
+
};
|
|
2321
|
+
|
|
2322
|
+
var getScreenOptions = function getScreenOptions(screenContext, opts) {
|
|
2323
|
+
var _ref = screenContext || {},
|
|
2324
|
+
_ref$data = _ref.data,
|
|
2325
|
+
ctxData = _ref$data === void 0 ? null : _ref$data;
|
|
2326
|
+
var _ref2 = ctxData || {},
|
|
2327
|
+
_ref2$id = _ref2.id,
|
|
2328
|
+
ctxScreenId = _ref2$id === void 0 ? null : _ref2$id,
|
|
2329
|
+
ctxScreenType = _ref2.type;
|
|
2330
|
+
var _ref3 = opts || {},
|
|
2331
|
+
_ref3$screenId = _ref3.screenId,
|
|
2332
|
+
optsScreenId = _ref3$screenId === void 0 ? null : _ref3$screenId,
|
|
2333
|
+
_ref3$screenType = _ref3.screenType,
|
|
2334
|
+
optsScreenType = _ref3$screenType === void 0 ? null : _ref3$screenType;
|
|
2335
|
+
var screenId = ctxScreenId !== null ? ctxScreenId : optsScreenId;
|
|
2336
|
+
var screenType = ctxScreenType !== null ? ctxScreenType : optsScreenType;
|
|
2337
|
+
return {
|
|
2338
|
+
screenId: screenId,
|
|
2339
|
+
screenType: screenType
|
|
2340
|
+
};
|
|
2341
|
+
};
|
|
2342
|
+
var hasTracking = function hasTracking(tracking) {
|
|
2343
|
+
return typeof tracking !== 'undefined';
|
|
2344
|
+
};
|
|
2345
|
+
var useTrackScreenView = function useTrackScreenView() {
|
|
2346
|
+
var tracking = contexts.useTracking();
|
|
2347
|
+
if (!hasTracking(tracking)) {
|
|
2348
|
+
return function () {};
|
|
2349
|
+
}
|
|
2350
|
+
return react.useCallback(function () {
|
|
2351
|
+
var screen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
2352
|
+
var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
2353
|
+
if (screen !== null && index !== null) {
|
|
2354
|
+
tracking.trackScreenView(screen, index);
|
|
2355
|
+
}
|
|
2356
|
+
}, []);
|
|
2357
|
+
};
|
|
2358
|
+
var useTrackScreenEvent = function useTrackScreenEvent() {
|
|
2359
|
+
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
2360
|
+
var tracking = contexts.useTracking();
|
|
2361
|
+
if (!hasTracking(tracking)) {
|
|
2362
|
+
return function () {};
|
|
2363
|
+
}
|
|
2364
|
+
var screenContext = contexts.useScreen();
|
|
2365
|
+
if (screenContext.renderContext !== 'view') {
|
|
2366
|
+
return function () {};
|
|
2367
|
+
}
|
|
2368
|
+
return react.useCallback(function () {
|
|
2369
|
+
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
2370
|
+
var label = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
2371
|
+
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
2372
|
+
if (type !== null && action !== null) {
|
|
2373
|
+
tracking.trackEvent("screen_".concat(type), action, label, _objectSpread(_objectSpread({}, opts), getScreenOptions(screenContext, opts)));
|
|
2374
|
+
}
|
|
2375
|
+
}, [screenContext]);
|
|
2376
|
+
};
|
|
2377
|
+
var useTrackScreenMedia = function useTrackScreenMedia() {
|
|
2378
|
+
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
2379
|
+
var tracking = contexts.useTracking();
|
|
2380
|
+
if (!hasTracking(tracking)) {
|
|
2381
|
+
return function () {};
|
|
2382
|
+
}
|
|
2383
|
+
var screenContext = contexts.useScreen();
|
|
2384
|
+
if (screenContext.renderContext !== 'view') {
|
|
2385
|
+
return function () {};
|
|
2386
|
+
}
|
|
2387
|
+
return react.useCallback(function () {
|
|
2388
|
+
var media = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
2389
|
+
var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
2390
|
+
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
2391
|
+
if (type !== null && media !== null && action !== null) {
|
|
2392
|
+
tracking.trackMedia("screen_".concat(type), media, action, _objectSpread(_objectSpread({}, opts), getScreenOptions(screenContext, opts)));
|
|
2393
|
+
}
|
|
2394
|
+
}, [screenContext]);
|
|
2395
|
+
};
|
|
2396
|
+
var useTrackEvent = function useTrackEvent() {
|
|
2397
|
+
var tracking = contexts.useTracking();
|
|
2398
|
+
if (!hasTracking(tracking)) {
|
|
2399
|
+
return function () {};
|
|
2400
|
+
}
|
|
2401
|
+
return react.useCallback(function () {
|
|
2402
|
+
var category = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
2403
|
+
var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
2404
|
+
var label = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
2405
|
+
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
2406
|
+
if (category !== null && action !== null) {
|
|
2407
|
+
tracking.trackEvent(category, action, label, opts);
|
|
2408
|
+
}
|
|
2409
|
+
}, []);
|
|
2410
|
+
};
|
|
2411
|
+
var useTrackMedia = function useTrackMedia() {
|
|
2412
|
+
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
2413
|
+
var tracking = contexts.useTracking();
|
|
2414
|
+
if (!hasTracking(tracking)) {
|
|
2415
|
+
return function () {};
|
|
2416
|
+
}
|
|
2417
|
+
return react.useCallback(function () {
|
|
2418
|
+
var media = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
2419
|
+
var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
2420
|
+
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
2421
|
+
if (type !== null && media !== null && action !== null) {
|
|
2422
|
+
tracking.trackMedia(type, media, action, opts);
|
|
2423
|
+
}
|
|
2424
|
+
}, []);
|
|
2425
|
+
};
|
|
2426
|
+
|
|
2427
|
+
var eventsManager = typeof window !== 'undefined' ? new core.EventsManager(window) : null;
|
|
2428
|
+
var useWindowEvent = utils.createUseEvent(eventsManager);
|
|
2429
|
+
|
|
2430
|
+
exports.getObserver = getObserver;
|
|
2431
|
+
exports.useActivityDetector = useActivityDetector;
|
|
2432
|
+
exports.useAnimationFrame = useAnimationFrame;
|
|
2433
|
+
exports.useDebounce = useDebounced;
|
|
2434
|
+
exports.useDevicePixelRatio = useDevicePixelRatio;
|
|
2435
|
+
exports.useDimensionObserver = useDimensionObserver;
|
|
2436
|
+
exports.useDocumentEvent = useDocumentEvent;
|
|
2437
|
+
exports.useDragProgress = useDragProgress;
|
|
2438
|
+
exports.useForm = useForm;
|
|
2439
|
+
exports.useFormTransition = useFormTransition;
|
|
2440
|
+
exports.useFormattedDate = useFormattedDate;
|
|
2441
|
+
exports.useFormattedTime = useFormattedTime;
|
|
2442
|
+
exports.useFullscreen = useFullscreen;
|
|
2443
|
+
exports.useIntersectionObserver = useIntersectionObserver;
|
|
2444
|
+
exports.useIsVisible = useIsVisible;
|
|
2445
|
+
exports.useLoadedFonts = useLoadedFonts;
|
|
2446
|
+
exports.useLongPress = useLongPress;
|
|
2447
|
+
exports.useMediaApi = useMediaApi;
|
|
2448
|
+
exports.useMediaBuffering = useMediaBuffering;
|
|
2449
|
+
exports.useMediaCurrentTime = useMediaCurrentTime;
|
|
2450
|
+
exports.useMediaDuration = useMediaDuration;
|
|
2451
|
+
exports.useMediaLoad = useMediaLoad;
|
|
2452
|
+
exports.useMediaProgress = useMediaProgress;
|
|
2453
|
+
exports.useMediaReady = useMediaReady;
|
|
2454
|
+
exports.useMediaState = useMediaState;
|
|
2455
|
+
exports.useMediaThumbnail = useMediaThumbnail;
|
|
2456
|
+
exports.useMediaTimestampOffset = useMediaTimestampOffset;
|
|
2457
|
+
exports.useMediaWaveform = useMediaWaveform;
|
|
2458
|
+
exports.useMediasParser = useMediasParser;
|
|
2459
|
+
exports.useObserver = useObserver;
|
|
2460
|
+
exports.useParsedStory = useParsedStory;
|
|
2461
|
+
exports.usePlaceholderStyle = usePlaceholderStyle;
|
|
2462
|
+
exports.useProgressSteps = useProgressSteps;
|
|
2463
|
+
exports.useResizeObserver = useResizeObserver;
|
|
2464
|
+
exports.useScreenSizeFromElement = useScreenSizeFromElement;
|
|
2465
|
+
exports.useScreenSizeFromWindow = useScreenSizeFromWindow;
|
|
2466
|
+
exports.useSpringValue = useSpringValue;
|
|
2467
|
+
exports.useSwipe = useSwipe;
|
|
2468
|
+
exports.useThemeParser = useThemeParser;
|
|
2469
|
+
exports.useTrackEvent = useTrackEvent;
|
|
2470
|
+
exports.useTrackMedia = useTrackMedia;
|
|
2471
|
+
exports.useTrackScreenEvent = useTrackScreenEvent;
|
|
2472
|
+
exports.useTrackScreenMedia = useTrackScreenMedia;
|
|
2473
|
+
exports.useTrackScreenView = useTrackScreenView;
|
|
2474
|
+
exports.useWindowEvent = useWindowEvent;
|