uikit 3.11.2-dev.f2970ffaa → 3.11.2-dev.f3ade19c4
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/.eslintrc.json +4 -49
- package/.prettierignore +14 -0
- package/.prettierrc.json +13 -0
- package/.webstorm.js +3 -3
- package/CHANGELOG.md +54 -18
- package/build/.eslintrc.json +1 -3
- package/build/build.js +26 -28
- package/build/icons.js +7 -11
- package/build/less.js +48 -36
- package/build/package.json +2 -2
- package/build/prefix.js +21 -18
- package/build/publishDev.js +6 -8
- package/build/release.js +20 -17
- package/build/scope.js +21 -11
- package/build/scss.js +72 -39
- package/build/util.js +71 -62
- package/build/wrapper/icons.js +0 -2
- package/dist/css/uikit-core-rtl.css +133 -201
- package/dist/css/uikit-core-rtl.min.css +1 -1
- package/dist/css/uikit-core.css +133 -201
- package/dist/css/uikit-core.min.css +1 -1
- package/dist/css/uikit-rtl.css +135 -207
- package/dist/css/uikit-rtl.min.css +1 -1
- package/dist/css/uikit.css +135 -207
- package/dist/css/uikit.min.css +1 -1
- package/dist/js/components/countdown.js +88 -133
- package/dist/js/components/countdown.min.js +1 -1
- package/dist/js/components/filter.js +408 -439
- package/dist/js/components/filter.min.js +1 -1
- package/dist/js/components/lightbox-panel.js +1091 -1319
- package/dist/js/components/lightbox-panel.min.js +1 -1
- package/dist/js/components/lightbox.js +1137 -1396
- package/dist/js/components/lightbox.min.js +1 -1
- package/dist/js/components/notification.js +94 -114
- package/dist/js/components/notification.min.js +1 -1
- package/dist/js/components/parallax.js +347 -372
- package/dist/js/components/parallax.min.js +1 -1
- package/dist/js/components/slider-parallax.js +345 -360
- package/dist/js/components/slider-parallax.min.js +1 -1
- package/dist/js/components/slider.js +749 -843
- package/dist/js/components/slider.min.js +1 -1
- package/dist/js/components/slideshow-parallax.js +345 -360
- package/dist/js/components/slideshow-parallax.min.js +1 -1
- package/dist/js/components/slideshow.js +628 -798
- package/dist/js/components/slideshow.min.js +1 -1
- package/dist/js/components/sortable.js +587 -620
- package/dist/js/components/sortable.min.js +1 -1
- package/dist/js/components/tooltip.js +324 -356
- package/dist/js/components/tooltip.min.js +1 -1
- package/dist/js/components/upload.js +155 -167
- package/dist/js/components/upload.min.js +1 -1
- package/dist/js/uikit-core.js +5326 -6526
- package/dist/js/uikit-core.min.js +1 -1
- package/dist/js/uikit-icons.js +7 -9
- package/dist/js/uikit-icons.min.js +1 -1
- package/dist/js/uikit.js +8031 -9659
- package/dist/js/uikit.min.js +1 -1
- package/jsconfig.json +1 -1
- package/package.json +64 -60
- package/src/js/api/boot.js +25 -32
- package/src/js/api/component.js +15 -28
- package/src/js/api/global.js +6 -12
- package/src/js/api/hooks.js +14 -33
- package/src/js/api/instance.js +7 -15
- package/src/js/api/state.js +199 -187
- package/src/js/components/countdown.js +26 -52
- package/src/js/components/filter.js +70 -66
- package/src/js/components/index.js +13 -13
- package/src/js/components/internal/lightbox-animations.js +14 -25
- package/src/js/components/internal/slider-preload.js +9 -0
- package/src/js/components/internal/slider-transitioner.js +66 -45
- package/src/js/components/internal/slideshow-animations.js +46 -64
- package/src/js/components/lightbox-panel.js +107 -105
- package/src/js/components/lightbox.js +17 -39
- package/src/js/components/notification.js +49 -43
- package/src/js/components/parallax.js +21 -46
- package/src/js/components/slider-parallax.js +13 -23
- package/src/js/components/slider.js +117 -89
- package/src/js/components/slideshow-parallax.js +1 -1
- package/src/js/components/slideshow.js +15 -13
- package/src/js/components/sortable.js +125 -106
- package/src/js/components/tooltip.js +41 -31
- package/src/js/components/upload.js +52 -63
- package/src/js/core/accordion.js +58 -48
- package/src/js/core/alert.js +9 -17
- package/src/js/core/core.js +17 -69
- package/src/js/core/cover.js +15 -15
- package/src/js/core/drop.js +110 -94
- package/src/js/core/form-custom.js +22 -27
- package/src/js/core/gif.js +3 -7
- package/src/js/core/grid.js +57 -58
- package/src/js/core/height-match.js +16 -29
- package/src/js/core/height-viewport.js +30 -34
- package/src/js/core/icon.js +47 -52
- package/src/js/core/img.js +153 -143
- package/src/js/core/index.js +39 -39
- package/src/js/core/leader.js +9 -18
- package/src/js/core/margin.js +21 -37
- package/src/js/core/modal.js +49 -36
- package/src/js/core/nav.js +2 -4
- package/src/js/core/navbar.js +113 -85
- package/src/js/core/offcanvas.js +51 -54
- package/src/js/core/overflow-auto.js +13 -17
- package/src/js/core/responsive.js +14 -12
- package/src/js/core/scroll.js +10 -20
- package/src/js/core/scrollspy-nav.js +34 -31
- package/src/js/core/scrollspy.js +37 -54
- package/src/js/core/sticky.js +175 -123
- package/src/js/core/svg.js +68 -83
- package/src/js/core/switcher.js +56 -47
- package/src/js/core/tab.js +7 -10
- package/src/js/core/toggle.js +69 -68
- package/src/js/core/video.js +22 -21
- package/src/js/mixin/animate.js +19 -20
- package/src/js/mixin/class.js +2 -4
- package/src/js/mixin/container.js +7 -11
- package/src/js/mixin/internal/animate-fade.js +73 -30
- package/src/js/mixin/internal/animate-slide.js +58 -41
- package/src/js/mixin/internal/slideshow-animations.js +7 -14
- package/src/js/mixin/internal/slideshow-transitioner.js +10 -17
- package/src/js/mixin/lazyload.js +20 -0
- package/src/js/mixin/media.js +5 -10
- package/src/js/mixin/modal.js +89 -66
- package/src/js/mixin/parallax.js +149 -107
- package/src/js/mixin/position.js +26 -20
- package/src/js/mixin/slider-autoplay.js +12 -21
- package/src/js/mixin/slider-drag.js +64 -65
- package/src/js/mixin/slider-nav.js +26 -35
- package/src/js/mixin/slider-reactive.js +2 -8
- package/src/js/mixin/slider.js +47 -60
- package/src/js/mixin/slideshow.js +12 -22
- package/src/js/mixin/swipe.js +72 -0
- package/src/js/mixin/togglable.js +89 -63
- package/src/js/uikit-core.js +2 -4
- package/src/js/uikit.js +2 -4
- package/src/js/util/ajax.js +25 -40
- package/src/js/util/animation.js +77 -75
- package/src/js/util/attr.js +17 -21
- package/src/js/util/class.js +14 -52
- package/src/js/util/dimensions.js +78 -49
- package/src/js/util/dom.js +39 -66
- package/src/js/util/env.js +7 -12
- package/src/js/util/event.js +60 -59
- package/src/js/util/fastdom.js +1 -6
- package/src/js/util/filter.js +17 -34
- package/src/js/util/index.js +1 -1
- package/src/js/util/lang.js +82 -121
- package/src/js/util/mouse.js +19 -17
- package/src/js/util/observer.js +36 -0
- package/src/js/util/options.js +35 -49
- package/src/js/util/player.js +41 -36
- package/src/js/util/position.js +54 -46
- package/src/js/util/selector.js +43 -58
- package/src/js/util/style.js +39 -49
- package/src/js/util/viewport.js +75 -64
- package/src/less/components/base.less +10 -33
- package/src/less/components/flex.less +0 -9
- package/src/less/components/form-range.less +48 -95
- package/src/less/components/form.less +0 -1
- package/src/less/components/height.less +3 -0
- package/src/less/components/leader.less +0 -1
- package/src/less/components/lightbox.less +0 -1
- package/src/less/components/modal.less +3 -7
- package/src/less/components/navbar.less +0 -7
- package/src/less/components/progress.less +14 -36
- package/src/less/components/slider.less +0 -3
- package/src/less/components/slideshow.less +0 -3
- package/src/less/components/text.less +16 -32
- package/src/less/components/utility.less +25 -0
- package/src/scss/components/base.scss +10 -33
- package/src/scss/components/flex.scss +0 -9
- package/src/scss/components/form-range.scss +48 -95
- package/src/scss/components/form.scss +3 -4
- package/src/scss/components/height.scss +3 -0
- package/src/scss/components/icon.scss +2 -2
- package/src/scss/components/leader.scss +0 -1
- package/src/scss/components/lightbox.scss +0 -1
- package/src/scss/components/modal.scss +3 -7
- package/src/scss/components/navbar.scss +0 -7
- package/src/scss/components/progress.scss +14 -36
- package/src/scss/components/search.scss +1 -1
- package/src/scss/components/slider.scss +0 -3
- package/src/scss/components/slideshow.scss +0 -3
- package/src/scss/components/text.scss +16 -32
- package/src/scss/components/utility.scss +25 -0
- package/src/scss/mixins-theme.scss +1 -1
- package/src/scss/mixins.scss +1 -1
- package/src/scss/variables-theme.scss +9 -9
- package/src/scss/variables.scss +9 -9
- package/tests/align.html +10 -10
- package/tests/animation.html +2 -2
- package/tests/article.html +2 -2
- package/tests/base.html +3 -3
- package/tests/card.html +10 -10
- package/tests/column.html +3 -3
- package/tests/comment.html +9 -9
- package/tests/dotnav.html +3 -3
- package/tests/image.html +296 -64
- package/tests/images/image-type.avif +0 -0
- package/tests/images/image-type.jpeg +0 -0
- package/tests/images/image-type.webp +0 -0
- package/tests/index.html +8 -8
- package/tests/js/index.js +114 -85
- package/tests/lightbox.html +10 -10
- package/tests/marker.html +2 -2
- package/tests/modal.html +8 -9
- package/tests/navbar.html +2 -2
- package/tests/overlay.html +7 -7
- package/tests/parallax.html +16 -7
- package/tests/position.html +12 -12
- package/tests/slidenav.html +12 -12
- package/tests/slider.html +20 -20
- package/tests/sortable.html +1 -1
- package/tests/sticky-parallax.html +87 -99
- package/tests/sticky.html +56 -24
- package/tests/svg.html +6 -6
- package/tests/table.html +11 -11
- package/tests/thumbnav.html +12 -12
- package/tests/transition.html +30 -30
- package/tests/utility.html +50 -33
- package/tests/video.html +1 -1
- package/tests/width.html +1 -1
- package/src/js/mixin/flex-bug.js +0 -56
- package/src/js/util/promise.js +0 -191
- package/tests/images/animated.gif +0 -0
package/src/js/util/event.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {isArray, isBoolean, isFunction, isString, toNode, toNodes} from './lang';
|
|
1
|
+
import { findAll } from './selector';
|
|
2
|
+
import { closest, within } from './filter';
|
|
3
|
+
import { isArray, isFunction, isString, toNode, toNodes } from './lang';
|
|
5
4
|
|
|
6
5
|
export function on(...args) {
|
|
7
|
-
|
|
8
|
-
let [targets, type, selector, listener, useCapture] = getArgs(args);
|
|
9
|
-
|
|
10
|
-
targets = toEventTargets(targets);
|
|
6
|
+
let [targets, types, selector, listener, useCapture = false] = getArgs(args);
|
|
11
7
|
|
|
12
8
|
if (listener.length > 1) {
|
|
13
9
|
listener = detail(listener);
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
if (useCapture
|
|
12
|
+
if (useCapture?.self) {
|
|
17
13
|
listener = selfFilter(listener);
|
|
18
14
|
}
|
|
19
15
|
|
|
@@ -21,80 +17,92 @@ export function on(...args) {
|
|
|
21
17
|
listener = delegate(selector, listener);
|
|
22
18
|
}
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
for (const type of types) {
|
|
21
|
+
for (const target of targets) {
|
|
22
|
+
target.addEventListener(type, listener, useCapture);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
targets.forEach(target =>
|
|
28
|
-
target.addEventListener(type, listener, useCapture)
|
|
29
|
-
)
|
|
30
|
-
);
|
|
31
|
-
return () => off(targets, type, listener, useCapture);
|
|
26
|
+
return () => off(targets, types, listener, useCapture);
|
|
32
27
|
}
|
|
33
28
|
|
|
34
|
-
export function off(
|
|
35
|
-
useCapture =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
);
|
|
29
|
+
export function off(...args) {
|
|
30
|
+
let [targets, types, , listener, useCapture = false] = getArgs(args);
|
|
31
|
+
for (const type of types) {
|
|
32
|
+
for (const target of targets) {
|
|
33
|
+
target.removeEventListener(type, listener, useCapture);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
42
36
|
}
|
|
43
37
|
|
|
44
38
|
export function once(...args) {
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
const [element, types, selector, listener, useCapture = false, condition] = getArgs(args);
|
|
40
|
+
const off = on(
|
|
41
|
+
element,
|
|
42
|
+
types,
|
|
43
|
+
selector,
|
|
44
|
+
(e) => {
|
|
45
|
+
const result = !condition || condition(e);
|
|
46
|
+
if (result) {
|
|
47
|
+
off();
|
|
48
|
+
listener(e, result);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
useCapture
|
|
52
|
+
);
|
|
54
53
|
|
|
55
54
|
return off;
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
export function trigger(targets, event, detail) {
|
|
59
|
-
return toEventTargets(targets).
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
return toEventTargets(targets).every((target) =>
|
|
59
|
+
target.dispatchEvent(createEvent(event, true, true, detail))
|
|
60
|
+
);
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
export function createEvent(e, bubbles = true, cancelable = false, detail) {
|
|
65
64
|
if (isString(e)) {
|
|
66
|
-
|
|
67
|
-
event.initCustomEvent(e, bubbles, cancelable, detail);
|
|
68
|
-
e = event;
|
|
65
|
+
e = new CustomEvent(e, { bubbles, cancelable, detail });
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
return e;
|
|
72
69
|
}
|
|
73
70
|
|
|
74
71
|
function getArgs(args) {
|
|
72
|
+
// Event targets
|
|
73
|
+
args[0] = toEventTargets(args[0]);
|
|
74
|
+
|
|
75
|
+
// Event types
|
|
76
|
+
if (isString(args[1])) {
|
|
77
|
+
args[1] = args[1].split(' ');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Delegate?
|
|
75
81
|
if (isFunction(args[2])) {
|
|
76
82
|
args.splice(2, 0, false);
|
|
77
83
|
}
|
|
84
|
+
|
|
78
85
|
return args;
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
function delegate(selector, listener) {
|
|
82
|
-
return e => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
return (e) => {
|
|
90
|
+
const current =
|
|
91
|
+
selector[0] === '>'
|
|
92
|
+
? findAll(selector, e.currentTarget)
|
|
93
|
+
.reverse()
|
|
94
|
+
.filter((element) => within(e.target, element))[0]
|
|
95
|
+
: closest(e.target, selector);
|
|
87
96
|
|
|
88
97
|
if (current) {
|
|
89
98
|
e.current = current;
|
|
90
99
|
listener.call(this, e);
|
|
91
100
|
}
|
|
92
|
-
|
|
93
101
|
};
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
function detail(listener) {
|
|
97
|
-
return e => isArray(e.detail) ? listener(e, ...e.detail) : listener(e);
|
|
105
|
+
return (e) => (isArray(e.detail) ? listener(e, ...e.detail) : listener(e));
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
function selfFilter(listener) {
|
|
@@ -105,12 +113,6 @@ function selfFilter(listener) {
|
|
|
105
113
|
};
|
|
106
114
|
}
|
|
107
115
|
|
|
108
|
-
function useCaptureFilter(options) {
|
|
109
|
-
return options && isIE && !isBoolean(options)
|
|
110
|
-
? !!options.capture
|
|
111
|
-
: options;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
116
|
function isEventTarget(target) {
|
|
115
117
|
return target && 'addEventListener' in target;
|
|
116
118
|
}
|
|
@@ -123,10 +125,10 @@ export function toEventTargets(target) {
|
|
|
123
125
|
return isArray(target)
|
|
124
126
|
? target.map(toEventTarget).filter(Boolean)
|
|
125
127
|
: isString(target)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
? findAll(target)
|
|
129
|
+
: isEventTarget(target)
|
|
130
|
+
? [target]
|
|
131
|
+
: toNodes(target);
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
export function isTouch(e) {
|
|
@@ -134,8 +136,7 @@ export function isTouch(e) {
|
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
export function getEventPos(e) {
|
|
137
|
-
const {
|
|
138
|
-
const {clientX: x, clientY: y} = touches && touches[0] || changedTouches && changedTouches[0] || e;
|
|
139
|
+
const { clientX: x, clientY: y } = e.touches?.[0] || e.changedTouches?.[0] || e;
|
|
139
140
|
|
|
140
|
-
return {x, y};
|
|
141
|
+
return { x, y };
|
|
141
142
|
}
|
package/src/js/util/fastdom.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {Promise} from './promise';
|
|
2
1
|
/*
|
|
3
2
|
Based on:
|
|
4
3
|
Copyright (c) 2016 Wilson Page wilsonpage@me.com
|
|
@@ -6,7 +5,6 @@ import {Promise} from './promise';
|
|
|
6
5
|
*/
|
|
7
6
|
|
|
8
7
|
export const fastdom = {
|
|
9
|
-
|
|
10
8
|
reads: [],
|
|
11
9
|
writes: [],
|
|
12
10
|
|
|
@@ -27,8 +25,7 @@ export const fastdom = {
|
|
|
27
25
|
remove(this.writes, task);
|
|
28
26
|
},
|
|
29
27
|
|
|
30
|
-
flush
|
|
31
|
-
|
|
28
|
+
flush,
|
|
32
29
|
};
|
|
33
30
|
|
|
34
31
|
function flush(recursion) {
|
|
@@ -44,7 +41,6 @@ function flush(recursion) {
|
|
|
44
41
|
|
|
45
42
|
const RECURSION_LIMIT = 4;
|
|
46
43
|
function scheduleFlush(recursion) {
|
|
47
|
-
|
|
48
44
|
if (fastdom.scheduled) {
|
|
49
45
|
return;
|
|
50
46
|
}
|
|
@@ -55,7 +51,6 @@ function scheduleFlush(recursion) {
|
|
|
55
51
|
} else {
|
|
56
52
|
requestAnimationFrame(() => flush(1));
|
|
57
53
|
}
|
|
58
|
-
|
|
59
54
|
}
|
|
60
55
|
|
|
61
56
|
function runTasks(tasks) {
|
package/src/js/util/filter.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {isDocument, isElement, isString, noop, startsWith, toNode, toNodes} from './lang';
|
|
1
|
+
import { isElement, isString, startsWith, toNode, toNodes } from './lang';
|
|
3
2
|
|
|
4
3
|
const voidElements = {
|
|
5
4
|
area: true,
|
|
@@ -17,19 +16,21 @@ const voidElements = {
|
|
|
17
16
|
param: true,
|
|
18
17
|
source: true,
|
|
19
18
|
track: true,
|
|
20
|
-
wbr: true
|
|
19
|
+
wbr: true,
|
|
21
20
|
};
|
|
22
21
|
export function isVoidElement(element) {
|
|
23
|
-
return toNodes(element).some(element => voidElements[element.tagName.toLowerCase()]);
|
|
22
|
+
return toNodes(element).some((element) => voidElements[element.tagName.toLowerCase()]);
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
export function isVisible(element) {
|
|
27
|
-
return toNodes(element).some(
|
|
26
|
+
return toNodes(element).some(
|
|
27
|
+
(element) => element.offsetWidth || element.offsetHeight || element.getClientRects().length
|
|
28
|
+
);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export const selInput = 'input,select,textarea,button';
|
|
31
32
|
export function isInput(element) {
|
|
32
|
-
return toNodes(element).some(element => matches(element, selInput));
|
|
33
|
+
return toNodes(element).some((element) => matches(element, selInput));
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export const selFocusable = `${selInput},a[href],[tabindex]`;
|
|
@@ -43,45 +44,29 @@ export function parent(element) {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export function filter(element, selector) {
|
|
46
|
-
return toNodes(element).filter(element => matches(element, selector));
|
|
47
|
+
return toNodes(element).filter((element) => matches(element, selector));
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
const elProto = inBrowser ? Element.prototype : {};
|
|
50
|
-
const matchesFn = elProto.matches || elProto.webkitMatchesSelector || elProto.msMatchesSelector || noop;
|
|
51
|
-
|
|
52
50
|
export function matches(element, selector) {
|
|
53
|
-
return toNodes(element).some(element =>
|
|
51
|
+
return toNodes(element).some((element) => element.matches(selector));
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
const closestFn = elProto.closest || function (selector) {
|
|
57
|
-
let ancestor = this;
|
|
58
|
-
|
|
59
|
-
do {
|
|
60
|
-
|
|
61
|
-
if (matches(ancestor, selector)) {
|
|
62
|
-
return ancestor;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
} while ((ancestor = parent(ancestor)));
|
|
66
|
-
};
|
|
67
|
-
|
|
68
54
|
export function closest(element, selector) {
|
|
69
|
-
|
|
70
55
|
if (startsWith(selector, '>')) {
|
|
71
56
|
selector = selector.slice(1);
|
|
72
57
|
}
|
|
73
58
|
|
|
74
59
|
return isElement(element)
|
|
75
|
-
?
|
|
76
|
-
: toNodes(element)
|
|
60
|
+
? element.closest(selector)
|
|
61
|
+
: toNodes(element)
|
|
62
|
+
.map((element) => closest(element, selector))
|
|
63
|
+
.filter(Boolean);
|
|
77
64
|
}
|
|
78
65
|
|
|
79
66
|
export function within(element, selector) {
|
|
80
|
-
return
|
|
81
|
-
? element
|
|
82
|
-
|
|
83
|
-
: toNode(selector)).contains(toNode(element)) // IE 11 document does not implement contains
|
|
84
|
-
: matches(element, selector) || !!closest(element, selector);
|
|
67
|
+
return isString(selector)
|
|
68
|
+
? matches(element, selector) || !!closest(element, selector)
|
|
69
|
+
: element === selector || toNode(selector).contains(toNode(element));
|
|
85
70
|
}
|
|
86
71
|
|
|
87
72
|
export function parents(element, selector) {
|
|
@@ -103,7 +88,5 @@ export function children(element, selector) {
|
|
|
103
88
|
}
|
|
104
89
|
|
|
105
90
|
export function index(element, ref) {
|
|
106
|
-
return ref
|
|
107
|
-
? toNodes(element).indexOf(toNode(ref))
|
|
108
|
-
: children(parent(element)).indexOf(element);
|
|
91
|
+
return ref ? toNodes(element).indexOf(toNode(ref)) : children(parent(element)).indexOf(element);
|
|
109
92
|
}
|
package/src/js/util/index.js
CHANGED
|
@@ -10,10 +10,10 @@ export * from './fastdom';
|
|
|
10
10
|
export * from './filter';
|
|
11
11
|
export * from './lang';
|
|
12
12
|
export * from './mouse';
|
|
13
|
+
export * from './observer';
|
|
13
14
|
export * from './options';
|
|
14
15
|
export * from './player';
|
|
15
16
|
export * from './position';
|
|
16
|
-
export * from './promise';
|
|
17
17
|
export * from './selector';
|
|
18
18
|
export * from './style';
|
|
19
19
|
export * from './viewport';
|
package/src/js/util/lang.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
const {hasOwnProperty} = objPrototype;
|
|
1
|
+
const { hasOwnProperty, toString } = Object.prototype;
|
|
3
2
|
|
|
4
3
|
export function hasOwn(obj, key) {
|
|
5
4
|
return hasOwnProperty.call(obj, key);
|
|
@@ -7,18 +6,13 @@ export function hasOwn(obj, key) {
|
|
|
7
6
|
|
|
8
7
|
const hyphenateRe = /\B([A-Z])/g;
|
|
9
8
|
|
|
10
|
-
export const hyphenate = memoize(str => str
|
|
11
|
-
.replace(hyphenateRe, '-$1')
|
|
12
|
-
.toLowerCase()
|
|
13
|
-
);
|
|
9
|
+
export const hyphenate = memoize((str) => str.replace(hyphenateRe, '-$1').toLowerCase());
|
|
14
10
|
|
|
15
11
|
const camelizeRe = /-(\w)/g;
|
|
16
12
|
|
|
17
|
-
export const camelize = memoize(str =>
|
|
18
|
-
str.replace(camelizeRe, toUpper)
|
|
19
|
-
);
|
|
13
|
+
export const camelize = memoize((str) => str.replace(camelizeRe, toUpper));
|
|
20
14
|
|
|
21
|
-
export const ucfirst = memoize(str =>
|
|
15
|
+
export const ucfirst = memoize((str) =>
|
|
22
16
|
str.length ? toUpper(null, str.charAt(0)) + str.slice(1) : ''
|
|
23
17
|
);
|
|
24
18
|
|
|
@@ -26,43 +20,24 @@ function toUpper(_, c) {
|
|
|
26
20
|
return c ? c.toUpperCase() : '';
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
const strPrototype = String.prototype;
|
|
30
|
-
const startsWithFn = strPrototype.startsWith || function (search) { return this.lastIndexOf(search, 0) === 0; };
|
|
31
|
-
|
|
32
23
|
export function startsWith(str, search) {
|
|
33
|
-
return
|
|
24
|
+
return str?.startsWith?.(search);
|
|
34
25
|
}
|
|
35
26
|
|
|
36
|
-
const endsWithFn = strPrototype.endsWith || function (search) { return this.substr(-search.length) === search; };
|
|
37
|
-
|
|
38
27
|
export function endsWith(str, search) {
|
|
39
|
-
return
|
|
28
|
+
return str?.endsWith?.(search);
|
|
40
29
|
}
|
|
41
30
|
|
|
42
|
-
const arrPrototype = Array.prototype;
|
|
43
|
-
|
|
44
|
-
const includesFn = function (search, i) { return !!~this.indexOf(search, i); };
|
|
45
|
-
const includesStr = strPrototype.includes || includesFn;
|
|
46
|
-
const includesArray = arrPrototype.includes || includesFn;
|
|
47
|
-
|
|
48
31
|
export function includes(obj, search) {
|
|
49
|
-
return obj
|
|
32
|
+
return obj?.includes?.(search);
|
|
50
33
|
}
|
|
51
34
|
|
|
52
|
-
const findIndexFn = arrPrototype.findIndex || function (predicate) {
|
|
53
|
-
for (let i = 0; i < this.length; i++) {
|
|
54
|
-
if (predicate.call(arguments[1], this[i], i, this)) {
|
|
55
|
-
return i;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return -1;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
35
|
export function findIndex(array, predicate) {
|
|
62
|
-
return
|
|
36
|
+
return array?.findIndex?.(predicate);
|
|
63
37
|
}
|
|
64
38
|
|
|
65
|
-
export const {isArray} = Array;
|
|
39
|
+
export const { isArray, from: toArray } = Array;
|
|
40
|
+
export const { assign } = Object;
|
|
66
41
|
|
|
67
42
|
export function isFunction(obj) {
|
|
68
43
|
return typeof obj === 'function';
|
|
@@ -72,7 +47,6 @@ export function isObject(obj) {
|
|
|
72
47
|
return obj !== null && typeof obj === 'object';
|
|
73
48
|
}
|
|
74
49
|
|
|
75
|
-
const {toString} = objPrototype;
|
|
76
50
|
export function isPlainObject(obj) {
|
|
77
51
|
return toString.call(obj) === '[object Object]';
|
|
78
52
|
}
|
|
@@ -110,16 +84,11 @@ export function isNumber(value) {
|
|
|
110
84
|
}
|
|
111
85
|
|
|
112
86
|
export function isNumeric(value) {
|
|
113
|
-
return isNumber(value) || isString(value) && !isNaN(value - parseFloat(value));
|
|
87
|
+
return isNumber(value) || (isString(value) && !isNaN(value - parseFloat(value)));
|
|
114
88
|
}
|
|
115
89
|
|
|
116
90
|
export function isEmpty(obj) {
|
|
117
|
-
return !(isArray(obj)
|
|
118
|
-
? obj.length
|
|
119
|
-
: isObject(obj)
|
|
120
|
-
? Object.keys(obj).length
|
|
121
|
-
: false
|
|
122
|
-
);
|
|
91
|
+
return !(isArray(obj) ? obj.length : isObject(obj) ? Object.keys(obj).length : false);
|
|
123
92
|
}
|
|
124
93
|
|
|
125
94
|
export function isUndefined(value) {
|
|
@@ -130,10 +99,10 @@ export function toBoolean(value) {
|
|
|
130
99
|
return isBoolean(value)
|
|
131
100
|
? value
|
|
132
101
|
: value === 'true' || value === '1' || value === ''
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
102
|
+
? true
|
|
103
|
+
: value === 'false' || value === '0'
|
|
104
|
+
? false
|
|
105
|
+
: value;
|
|
137
106
|
}
|
|
138
107
|
|
|
139
108
|
export function toNumber(value) {
|
|
@@ -145,14 +114,12 @@ export function toFloat(value) {
|
|
|
145
114
|
return parseFloat(value) || 0;
|
|
146
115
|
}
|
|
147
116
|
|
|
148
|
-
export const toArray = Array.from || (value => arrPrototype.slice.call(value));
|
|
149
|
-
|
|
150
117
|
export function toNode(element) {
|
|
151
118
|
return toNodes(element)[0];
|
|
152
119
|
}
|
|
153
120
|
|
|
154
121
|
export function toNodes(element) {
|
|
155
|
-
return element && (isNode(element) ? [element] :
|
|
122
|
+
return (element && (isNode(element) ? [element] : Array.from(element).filter(isNode))) || [];
|
|
156
123
|
}
|
|
157
124
|
|
|
158
125
|
export function toWindow(element) {
|
|
@@ -161,53 +128,29 @@ export function toWindow(element) {
|
|
|
161
128
|
}
|
|
162
129
|
|
|
163
130
|
element = toNode(element);
|
|
131
|
+
const document = isDocument(element) ? element : element?.ownerDocument;
|
|
164
132
|
|
|
165
|
-
return
|
|
166
|
-
? (isDocument(element)
|
|
167
|
-
? element
|
|
168
|
-
: element.ownerDocument
|
|
169
|
-
).defaultView
|
|
170
|
-
: window;
|
|
133
|
+
return document?.defaultView || window;
|
|
171
134
|
}
|
|
172
135
|
|
|
173
136
|
export function toMs(time) {
|
|
174
|
-
return
|
|
175
|
-
? 0
|
|
176
|
-
: endsWith(time, 'ms')
|
|
177
|
-
? toFloat(time)
|
|
178
|
-
: toFloat(time) * 1000;
|
|
137
|
+
return time ? (endsWith(time, 'ms') ? toFloat(time) : toFloat(time) * 1000) : 0;
|
|
179
138
|
}
|
|
180
139
|
|
|
181
140
|
export function isEqual(value, other) {
|
|
182
|
-
return
|
|
183
|
-
||
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
141
|
+
return (
|
|
142
|
+
value === other ||
|
|
143
|
+
(isObject(value) &&
|
|
144
|
+
isObject(other) &&
|
|
145
|
+
Object.keys(value).length === Object.keys(other).length &&
|
|
146
|
+
each(value, (val, key) => val === other[key]))
|
|
147
|
+
);
|
|
187
148
|
}
|
|
188
149
|
|
|
189
150
|
export function swap(value, a, b) {
|
|
190
|
-
return value.replace(
|
|
191
|
-
new RegExp(`${a}|${b}`, 'g'),
|
|
192
|
-
match => match === a ? b : a
|
|
193
|
-
);
|
|
151
|
+
return value.replace(new RegExp(`${a}|${b}`, 'g'), (match) => (match === a ? b : a));
|
|
194
152
|
}
|
|
195
153
|
|
|
196
|
-
export const assign = Object.assign || function (target, ...args) {
|
|
197
|
-
target = Object(target);
|
|
198
|
-
for (let i = 0; i < args.length; i++) {
|
|
199
|
-
const source = args[i];
|
|
200
|
-
if (source !== null) {
|
|
201
|
-
for (const key in source) {
|
|
202
|
-
if (hasOwn(source, key)) {
|
|
203
|
-
target[key] = source[key];
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return target;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
154
|
export function last(array) {
|
|
212
155
|
return array[array.length - 1];
|
|
213
156
|
}
|
|
@@ -222,21 +165,16 @@ export function each(obj, cb) {
|
|
|
222
165
|
}
|
|
223
166
|
|
|
224
167
|
export function sortBy(array, prop) {
|
|
225
|
-
return array
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
: propB > propA
|
|
229
|
-
|
|
230
|
-
: 0
|
|
231
|
-
);
|
|
168
|
+
return array
|
|
169
|
+
.slice()
|
|
170
|
+
.sort(({ [prop]: propA = 0 }, { [prop]: propB = 0 }) =>
|
|
171
|
+
propA > propB ? 1 : propB > propA ? -1 : 0
|
|
172
|
+
);
|
|
232
173
|
}
|
|
233
174
|
|
|
234
175
|
export function uniqueBy(array, prop) {
|
|
235
176
|
const seen = new Set();
|
|
236
|
-
return array.filter(({[prop]: check}) => seen.has(check)
|
|
237
|
-
? false
|
|
238
|
-
: seen.add(check) || true // IE 11 does not return the Set object
|
|
239
|
-
);
|
|
177
|
+
return array.filter(({ [prop]: check }) => (seen.has(check) ? false : seen.add(check)));
|
|
240
178
|
}
|
|
241
179
|
|
|
242
180
|
export function clamp(number, min = 0, max = 1) {
|
|
@@ -246,36 +184,48 @@ export function clamp(number, min = 0, max = 1) {
|
|
|
246
184
|
export function noop() {}
|
|
247
185
|
|
|
248
186
|
export function intersectRect(...rects) {
|
|
249
|
-
return [
|
|
250
|
-
|
|
187
|
+
return [
|
|
188
|
+
['bottom', 'top'],
|
|
189
|
+
['right', 'left'],
|
|
190
|
+
].every(
|
|
191
|
+
([minProp, maxProp]) =>
|
|
192
|
+
Math.min(...rects.map(({ [minProp]: min }) => min)) -
|
|
193
|
+
Math.max(...rects.map(({ [maxProp]: max }) => max)) >
|
|
194
|
+
0
|
|
251
195
|
);
|
|
252
196
|
}
|
|
253
197
|
|
|
254
198
|
export function pointInRect(point, rect) {
|
|
255
|
-
return
|
|
199
|
+
return (
|
|
200
|
+
point.x <= rect.right &&
|
|
256
201
|
point.x >= rect.left &&
|
|
257
202
|
point.y <= rect.bottom &&
|
|
258
|
-
point.y >= rect.top
|
|
203
|
+
point.y >= rect.top
|
|
204
|
+
);
|
|
259
205
|
}
|
|
260
206
|
|
|
261
207
|
export const Dimensions = {
|
|
262
|
-
|
|
263
208
|
ratio(dimensions, prop, value) {
|
|
264
|
-
|
|
265
209
|
const aProp = prop === 'width' ? 'height' : 'width';
|
|
266
210
|
|
|
267
211
|
return {
|
|
268
|
-
[aProp]: dimensions[prop]
|
|
269
|
-
|
|
212
|
+
[aProp]: dimensions[prop]
|
|
213
|
+
? Math.round((value * dimensions[aProp]) / dimensions[prop])
|
|
214
|
+
: dimensions[aProp],
|
|
215
|
+
[prop]: value,
|
|
270
216
|
};
|
|
271
217
|
},
|
|
272
218
|
|
|
273
219
|
contain(dimensions, maxDimensions) {
|
|
274
|
-
dimensions =
|
|
275
|
-
|
|
276
|
-
each(
|
|
277
|
-
|
|
278
|
-
|
|
220
|
+
dimensions = { ...dimensions };
|
|
221
|
+
|
|
222
|
+
each(
|
|
223
|
+
dimensions,
|
|
224
|
+
(_, prop) =>
|
|
225
|
+
(dimensions =
|
|
226
|
+
dimensions[prop] > maxDimensions[prop]
|
|
227
|
+
? this.ratio(dimensions, prop, maxDimensions[prop])
|
|
228
|
+
: dimensions)
|
|
279
229
|
);
|
|
280
230
|
|
|
281
231
|
return dimensions;
|
|
@@ -284,21 +234,23 @@ export const Dimensions = {
|
|
|
284
234
|
cover(dimensions, maxDimensions) {
|
|
285
235
|
dimensions = this.contain(dimensions, maxDimensions);
|
|
286
236
|
|
|
287
|
-
each(
|
|
288
|
-
|
|
289
|
-
|
|
237
|
+
each(
|
|
238
|
+
dimensions,
|
|
239
|
+
(_, prop) =>
|
|
240
|
+
(dimensions =
|
|
241
|
+
dimensions[prop] < maxDimensions[prop]
|
|
242
|
+
? this.ratio(dimensions, prop, maxDimensions[prop])
|
|
243
|
+
: dimensions)
|
|
290
244
|
);
|
|
291
245
|
|
|
292
246
|
return dimensions;
|
|
293
|
-
}
|
|
294
|
-
|
|
247
|
+
},
|
|
295
248
|
};
|
|
296
249
|
|
|
297
250
|
export function getIndex(i, elements, current = 0, finite = false) {
|
|
298
|
-
|
|
299
251
|
elements = toNodes(elements);
|
|
300
252
|
|
|
301
|
-
const {length} = elements;
|
|
253
|
+
const { length } = elements;
|
|
302
254
|
|
|
303
255
|
if (!length) {
|
|
304
256
|
return -1;
|
|
@@ -307,10 +259,10 @@ export function getIndex(i, elements, current = 0, finite = false) {
|
|
|
307
259
|
i = isNumeric(i)
|
|
308
260
|
? toNumber(i)
|
|
309
261
|
: i === 'next'
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
262
|
+
? current + 1
|
|
263
|
+
: i === 'previous'
|
|
264
|
+
? current - 1
|
|
265
|
+
: elements.indexOf(toNode(i));
|
|
314
266
|
|
|
315
267
|
if (finite) {
|
|
316
268
|
return clamp(i, 0, length - 1);
|
|
@@ -323,5 +275,14 @@ export function getIndex(i, elements, current = 0, finite = false) {
|
|
|
323
275
|
|
|
324
276
|
export function memoize(fn) {
|
|
325
277
|
const cache = Object.create(null);
|
|
326
|
-
return key => cache[key] || (cache[key] = fn(key));
|
|
278
|
+
return (key) => cache[key] || (cache[key] = fn(key));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export class Deferred {
|
|
282
|
+
constructor() {
|
|
283
|
+
this.promise = new Promise((resolve, reject) => {
|
|
284
|
+
this.reject = reject;
|
|
285
|
+
this.resolve = resolve;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
327
288
|
}
|