uikit 3.11.1 → 3.11.2-dev.03e47c2ff
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 +59 -17
- 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 +127 -201
- package/dist/css/uikit-core-rtl.min.css +1 -1
- package/dist/css/uikit-core.css +127 -201
- package/dist/css/uikit-core.min.css +1 -1
- package/dist/css/uikit-rtl.css +129 -207
- package/dist/css/uikit-rtl.min.css +1 -1
- package/dist/css/uikit.css +129 -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 +1098 -1316
- package/dist/js/components/lightbox-panel.min.js +1 -1
- package/dist/js/components/lightbox.js +1144 -1393
- 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 +345 -362
- package/dist/js/components/parallax.min.js +1 -1
- package/dist/js/components/slider-parallax.js +343 -350
- package/dist/js/components/slider-parallax.min.js +1 -1
- package/dist/js/components/slider.js +768 -843
- package/dist/js/components/slider.min.js +1 -1
- package/dist/js/components/slideshow-parallax.js +343 -350
- package/dist/js/components/slideshow-parallax.min.js +1 -1
- package/dist/js/components/slideshow.js +645 -793
- package/dist/js/components/slideshow.min.js +1 -1
- package/dist/js/components/sortable.js +587 -621
- 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 +5430 -6690
- 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 +8143 -9784
- 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 +79 -100
- package/src/js/components/countdown.js +24 -50
- 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 +37 -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 +95 -64
- package/src/js/components/slideshow-parallax.js +1 -1
- package/src/js/components/slideshow.js +15 -13
- package/src/js/components/sortable.js +126 -108
- package/src/js/components/tooltip.js +41 -31
- package/src/js/components/upload.js +52 -63
- package/src/js/core/accordion.js +53 -48
- package/src/js/core/alert.js +9 -17
- package/src/js/core/core.js +74 -53
- package/src/js/core/cover.js +11 -15
- package/src/js/core/drop.js +107 -93
- package/src/js/core/form-custom.js +20 -25
- 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 +29 -36
- package/src/js/core/icon.js +47 -52
- package/src/js/core/img.js +156 -138
- 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 +49 -53
- 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 +194 -123
- package/src/js/core/svg.js +68 -83
- package/src/js/core/switcher.js +47 -46
- package/src/js/core/tab.js +7 -10
- package/src/js/core/toggle.js +66 -67
- package/src/js/core/video.js +11 -22
- 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/media.js +5 -10
- package/src/js/mixin/modal.js +89 -66
- package/src/js/mixin/parallax.js +175 -121
- 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 +48 -55
- package/src/js/mixin/slideshow.js +13 -19
- 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 +3 -8
- package/src/js/util/filter.js +17 -34
- package/src/js/util/index.js +0 -1
- package/src/js/util/lang.js +82 -121
- package/src/js/util/mouse.js +19 -17
- 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 +81 -66
- 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 +22 -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 +22 -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 +14 -5
- 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 +86 -98
- 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 +33 -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/class.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {attr} from './attr';
|
|
2
|
-
import {isUndefined, toNodes} from './lang';
|
|
1
|
+
import { attr } from './attr';
|
|
2
|
+
import { isUndefined, toNodes } from './lang';
|
|
3
3
|
|
|
4
4
|
export function addClass(element, ...args) {
|
|
5
5
|
apply(element, args, 'add');
|
|
@@ -10,7 +10,7 @@ export function removeClass(element, ...args) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function removeClasses(element, cls) {
|
|
13
|
-
attr(element, 'class', value => (value || '').replace(new RegExp(`\\b${cls}\\b`, 'g'), ''));
|
|
13
|
+
attr(element, 'class', (value) => (value || '').replace(new RegExp(`\\b${cls}\\b`, 'g'), ''));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function replaceClass(element, ...args) {
|
|
@@ -20,9 +20,8 @@ export function replaceClass(element, ...args) {
|
|
|
20
20
|
|
|
21
21
|
export function hasClass(element, cls) {
|
|
22
22
|
[cls] = getClasses(cls);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
if (cls && nodes[n].classList.contains(cls)) {
|
|
23
|
+
for (const node of toNodes(element)) {
|
|
24
|
+
if (cls && node.classList.contains(cls)) {
|
|
26
25
|
return true;
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -30,64 +29,27 @@ export function hasClass(element, cls) {
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
export function toggleClass(element, cls, force) {
|
|
32
|
+
const classes = getClasses(cls);
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
if (!isUndefined(force)) {
|
|
35
|
+
force = !!force;
|
|
36
|
+
}
|
|
35
37
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
for (let i = 0; i < cls.length; i++) {
|
|
40
|
-
if (isUndefined(force)) {
|
|
41
|
-
list.toggle(cls[i]);
|
|
42
|
-
} else if (supports.Force) {
|
|
43
|
-
list.toggle(cls[i], !!force);
|
|
44
|
-
} else {
|
|
45
|
-
list[force ? 'add' : 'remove'](cls[i]);
|
|
46
|
-
}
|
|
38
|
+
for (const node of toNodes(element)) {
|
|
39
|
+
for (const cls of classes) {
|
|
40
|
+
node.classList.toggle(cls, force);
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
43
|
}
|
|
50
44
|
|
|
51
45
|
function apply(element, args, fn) {
|
|
52
|
-
|
|
53
46
|
args = args.reduce((args, arg) => args.concat(getClasses(arg)), []);
|
|
54
47
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
if (supports.Multiple) {
|
|
58
|
-
nodes[n].classList[fn](...args);
|
|
59
|
-
} else {
|
|
60
|
-
args.forEach(cls => nodes[n].classList[fn](cls));
|
|
61
|
-
}
|
|
48
|
+
for (const node of toNodes(element)) {
|
|
49
|
+
node.classList[fn](...args);
|
|
62
50
|
}
|
|
63
51
|
}
|
|
64
52
|
|
|
65
53
|
function getClasses(str) {
|
|
66
54
|
return String(str).split(/\s|,/).filter(Boolean);
|
|
67
55
|
}
|
|
68
|
-
|
|
69
|
-
// IE 11
|
|
70
|
-
let supports = {
|
|
71
|
-
|
|
72
|
-
get Multiple() {
|
|
73
|
-
return this.get('Multiple');
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
get Force() {
|
|
77
|
-
return this.get('Force');
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
get(key) {
|
|
81
|
-
|
|
82
|
-
const {classList} = document.createElement('_');
|
|
83
|
-
classList.add('a', 'b');
|
|
84
|
-
classList.toggle('c', false);
|
|
85
|
-
supports = {
|
|
86
|
-
Multiple: classList.contains('b'),
|
|
87
|
-
Force: !classList.contains('c')
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
return supports[key];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
};
|
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
import {css} from './style';
|
|
2
|
-
import {
|
|
1
|
+
import { css } from './style';
|
|
2
|
+
import {
|
|
3
|
+
each,
|
|
4
|
+
isDocument,
|
|
5
|
+
isElement,
|
|
6
|
+
isString,
|
|
7
|
+
isUndefined,
|
|
8
|
+
isWindow,
|
|
9
|
+
memoize,
|
|
10
|
+
toFloat,
|
|
11
|
+
toNode,
|
|
12
|
+
toWindow,
|
|
13
|
+
ucfirst,
|
|
14
|
+
} from './lang';
|
|
3
15
|
|
|
4
16
|
const dirs = {
|
|
5
17
|
width: ['left', 'right'],
|
|
6
|
-
height: ['top', 'bottom']
|
|
18
|
+
height: ['top', 'bottom'],
|
|
7
19
|
};
|
|
8
20
|
|
|
9
21
|
export function dimensions(element) {
|
|
10
|
-
|
|
11
22
|
const rect = isElement(element)
|
|
12
23
|
? toNode(element).getBoundingClientRect()
|
|
13
|
-
: {height: height(element), width: width(element), top: 0, left: 0};
|
|
24
|
+
: { height: height(element), width: width(element), top: 0, left: 0 };
|
|
14
25
|
|
|
15
26
|
return {
|
|
16
27
|
height: rect.height,
|
|
@@ -18,17 +29,16 @@ export function dimensions(element) {
|
|
|
18
29
|
top: rect.top,
|
|
19
30
|
left: rect.left,
|
|
20
31
|
bottom: rect.top + rect.height,
|
|
21
|
-
right: rect.left + rect.width
|
|
32
|
+
right: rect.left + rect.width,
|
|
22
33
|
};
|
|
23
34
|
}
|
|
24
35
|
|
|
25
36
|
export function offset(element, coordinates) {
|
|
26
|
-
|
|
27
37
|
const currentOffset = dimensions(element);
|
|
28
38
|
|
|
29
39
|
if (element) {
|
|
30
|
-
const {
|
|
31
|
-
const offsetBy = {height:
|
|
40
|
+
const { scrollY, scrollX } = toWindow(element);
|
|
41
|
+
const offsetBy = { height: scrollY, width: scrollX };
|
|
32
42
|
|
|
33
43
|
for (const dir in dirs) {
|
|
34
44
|
for (const i in dirs[dir]) {
|
|
@@ -44,23 +54,30 @@ export function offset(element, coordinates) {
|
|
|
44
54
|
const pos = css(element, 'position');
|
|
45
55
|
|
|
46
56
|
each(css(element, ['left', 'top']), (value, prop) =>
|
|
47
|
-
css(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
css(
|
|
58
|
+
element,
|
|
59
|
+
prop,
|
|
60
|
+
coordinates[prop] -
|
|
61
|
+
currentOffset[prop] +
|
|
62
|
+
toFloat(pos === 'absolute' && value === 'auto' ? position(element)[prop] : value)
|
|
52
63
|
)
|
|
53
64
|
);
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
export function position(element) {
|
|
68
|
+
let { top, left } = offset(element);
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
const {
|
|
71
|
+
ownerDocument: { body, documentElement },
|
|
72
|
+
offsetParent,
|
|
73
|
+
} = toNode(element);
|
|
61
74
|
let parent = offsetParent || documentElement;
|
|
62
75
|
|
|
63
|
-
while (
|
|
76
|
+
while (
|
|
77
|
+
parent &&
|
|
78
|
+
(parent === body || parent === documentElement) &&
|
|
79
|
+
css(parent, 'position') === 'static'
|
|
80
|
+
) {
|
|
64
81
|
parent = parent.parentNode;
|
|
65
82
|
}
|
|
66
83
|
|
|
@@ -72,7 +89,7 @@ export function position(element) {
|
|
|
72
89
|
|
|
73
90
|
return {
|
|
74
91
|
top: top - toFloat(css(element, 'marginTop')),
|
|
75
|
-
left: left - toFloat(css(element, 'marginLeft'))
|
|
92
|
+
left: left - toFloat(css(element, 'marginLeft')),
|
|
76
93
|
};
|
|
77
94
|
}
|
|
78
95
|
|
|
@@ -82,17 +99,15 @@ export function offsetPosition(element) {
|
|
|
82
99
|
element = toNode(element);
|
|
83
100
|
|
|
84
101
|
do {
|
|
85
|
-
|
|
86
102
|
offset[0] += element.offsetTop;
|
|
87
103
|
offset[1] += element.offsetLeft;
|
|
88
104
|
|
|
89
105
|
if (css(element, 'position') === 'fixed') {
|
|
90
106
|
const win = toWindow(element);
|
|
91
|
-
offset[0] += win.
|
|
92
|
-
offset[1] += win.
|
|
107
|
+
offset[0] += win.scrollY;
|
|
108
|
+
offset[1] += win.scrollX;
|
|
93
109
|
return offset;
|
|
94
110
|
}
|
|
95
|
-
|
|
96
111
|
} while ((element = element.offsetParent));
|
|
97
112
|
|
|
98
113
|
return offset;
|
|
@@ -104,9 +119,7 @@ export const width = dimension('width');
|
|
|
104
119
|
function dimension(prop) {
|
|
105
120
|
const propName = ucfirst(prop);
|
|
106
121
|
return (element, value) => {
|
|
107
|
-
|
|
108
122
|
if (isUndefined(value)) {
|
|
109
|
-
|
|
110
123
|
if (isWindow(element)) {
|
|
111
124
|
return element[`inner${propName}`];
|
|
112
125
|
}
|
|
@@ -122,26 +135,27 @@ function dimension(prop) {
|
|
|
122
135
|
value = value === 'auto' ? element[`offset${propName}`] : toFloat(value) || 0;
|
|
123
136
|
|
|
124
137
|
return value - boxModelAdjust(element, prop);
|
|
125
|
-
|
|
126
138
|
} else {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
: +value + boxModelAdjust(element, prop) + 'px'
|
|
139
|
+
return css(
|
|
140
|
+
element,
|
|
141
|
+
prop,
|
|
142
|
+
!value && value !== 0 ? '' : +value + boxModelAdjust(element, prop) + 'px'
|
|
131
143
|
);
|
|
132
|
-
|
|
133
144
|
}
|
|
134
|
-
|
|
135
145
|
};
|
|
136
146
|
}
|
|
137
147
|
|
|
138
148
|
export function boxModelAdjust(element, prop, sizing = 'border-box') {
|
|
139
149
|
return css(element, 'boxSizing') === sizing
|
|
140
|
-
? dirs[prop]
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
150
|
+
? dirs[prop]
|
|
151
|
+
.map(ucfirst)
|
|
152
|
+
.reduce(
|
|
153
|
+
(value, prop) =>
|
|
154
|
+
value +
|
|
155
|
+
toFloat(css(element, `padding${prop}`)) +
|
|
156
|
+
toFloat(css(element, `border${prop}Width`)),
|
|
157
|
+
0
|
|
158
|
+
)
|
|
145
159
|
: 0;
|
|
146
160
|
}
|
|
147
161
|
|
|
@@ -157,19 +171,34 @@ export function flipPosition(pos) {
|
|
|
157
171
|
}
|
|
158
172
|
|
|
159
173
|
export function toPx(value, property = 'width', element = window, offsetDim = false) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
:
|
|
174
|
+
if (!isString(value)) {
|
|
175
|
+
return toFloat(value);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return parseCalc(value).reduce((result, value) => {
|
|
179
|
+
const unit = parseUnit(value);
|
|
180
|
+
if (unit) {
|
|
181
|
+
value = percent(
|
|
182
|
+
unit === 'vh'
|
|
183
|
+
? height(toWindow(element))
|
|
184
|
+
: unit === 'vw'
|
|
185
|
+
? width(toWindow(element))
|
|
186
|
+
: offsetDim
|
|
187
|
+
? element[`offset${ucfirst(property)}`]
|
|
188
|
+
: dimensions(element)[property],
|
|
189
|
+
value
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return result + toFloat(value);
|
|
194
|
+
}, 0);
|
|
171
195
|
}
|
|
172
196
|
|
|
197
|
+
const calcRe = /-?\d+(?:\.\d+)?(?:v[wh]|%|px)?/g;
|
|
198
|
+
const parseCalc = memoize((calc) => calc.toString().replace(/\s/g, '').match(calcRe) || []);
|
|
199
|
+
const unitRe = /(?:v[hw]|%)$/;
|
|
200
|
+
const parseUnit = memoize((str) => (str.match(unitRe) || [])[0]);
|
|
201
|
+
|
|
173
202
|
function percent(base, value) {
|
|
174
|
-
return base * toFloat(value) / 100;
|
|
203
|
+
return (base * toFloat(value)) / 100;
|
|
175
204
|
}
|
package/src/js/util/dom.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {once} from './event';
|
|
2
|
-
import {parent} from './filter';
|
|
3
|
-
import {find, findAll} from './selector';
|
|
4
|
-
import {isElement, isString, isUndefined, toNode, toNodes} from './lang';
|
|
1
|
+
import { once } from './event';
|
|
2
|
+
import { parent } from './filter';
|
|
3
|
+
import { find, findAll } from './selector';
|
|
4
|
+
import { isElement, isString, isUndefined, startsWith, toNode, toNodes } from './lang';
|
|
5
5
|
|
|
6
6
|
export function ready(fn) {
|
|
7
|
-
|
|
8
7
|
if (document.readyState !== 'loading') {
|
|
9
8
|
fn();
|
|
10
9
|
return;
|
|
@@ -13,63 +12,39 @@ export function ready(fn) {
|
|
|
13
12
|
once(document, 'DOMContentLoaded', fn);
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
export function
|
|
17
|
-
element
|
|
18
|
-
element.innerHTML = '';
|
|
19
|
-
return element;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function html(parent, html) {
|
|
23
|
-
parent = $(parent);
|
|
24
|
-
return isUndefined(html)
|
|
25
|
-
? parent.innerHTML
|
|
26
|
-
: append(parent.hasChildNodes() ? empty(parent) : parent, html);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function prepend(parent, element) {
|
|
30
|
-
|
|
31
|
-
parent = $(parent);
|
|
32
|
-
|
|
33
|
-
if (parent.hasChildNodes()) {
|
|
34
|
-
return insertNodes(element, element => parent.insertBefore(element, parent.firstChild));
|
|
35
|
-
} else {
|
|
36
|
-
return append(parent, element);
|
|
37
|
-
}
|
|
15
|
+
export function isTag(element, tagName) {
|
|
16
|
+
return element?.tagName?.toLowerCase() === tagName.toLowerCase();
|
|
38
17
|
}
|
|
39
18
|
|
|
40
|
-
export function
|
|
41
|
-
|
|
42
|
-
return insertNodes(element, element => parent.appendChild(element));
|
|
19
|
+
export function empty(element) {
|
|
20
|
+
return replaceChildren(element, '');
|
|
43
21
|
}
|
|
44
22
|
|
|
45
|
-
export function
|
|
46
|
-
|
|
47
|
-
return insertNodes(element, element => ref.parentNode.insertBefore(element, ref));
|
|
23
|
+
export function html(parent, html) {
|
|
24
|
+
return isUndefined(html) ? $(parent).innerHTML : replaceChildren(parent, html);
|
|
48
25
|
}
|
|
49
26
|
|
|
50
|
-
export
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
56
|
-
}
|
|
27
|
+
export const replaceChildren = applyFn('replaceChildren');
|
|
28
|
+
export const prepend = applyFn('prepend');
|
|
29
|
+
export const append = applyFn('append');
|
|
30
|
+
export const before = applyFn('before');
|
|
31
|
+
export const after = applyFn('after');
|
|
57
32
|
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
33
|
+
function applyFn(fn) {
|
|
34
|
+
return function (ref, element) {
|
|
35
|
+
const nodes = toNodes(isString(element) ? fragment(element) : element);
|
|
36
|
+
if (nodes.length) {
|
|
37
|
+
$(ref)[fn](...nodes);
|
|
38
|
+
}
|
|
39
|
+
return unwrapSingle(nodes);
|
|
40
|
+
};
|
|
65
41
|
}
|
|
66
42
|
|
|
67
43
|
export function remove(element) {
|
|
68
|
-
toNodes(element).forEach(element => element.
|
|
44
|
+
toNodes(element).forEach((element) => element.remove());
|
|
69
45
|
}
|
|
70
46
|
|
|
71
47
|
export function wrapAll(element, structure) {
|
|
72
|
-
|
|
73
48
|
structure = toNode(before(element, structure));
|
|
74
49
|
|
|
75
50
|
while (structure.firstChild) {
|
|
@@ -82,26 +57,26 @@ export function wrapAll(element, structure) {
|
|
|
82
57
|
}
|
|
83
58
|
|
|
84
59
|
export function wrapInner(element, structure) {
|
|
85
|
-
return toNodes(
|
|
86
|
-
element.
|
|
87
|
-
|
|
60
|
+
return toNodes(
|
|
61
|
+
toNodes(element).map((element) =>
|
|
62
|
+
element.hasChildNodes
|
|
63
|
+
? wrapAll(toNodes(element.childNodes), structure)
|
|
64
|
+
: append(element, structure)
|
|
65
|
+
)
|
|
66
|
+
);
|
|
88
67
|
}
|
|
89
68
|
|
|
90
69
|
export function unwrap(element) {
|
|
91
70
|
toNodes(element)
|
|
92
71
|
.map(parent)
|
|
93
72
|
.filter((value, index, self) => self.indexOf(value) === index)
|
|
94
|
-
.forEach(parent =>
|
|
95
|
-
before(parent, parent.childNodes);
|
|
96
|
-
remove(parent);
|
|
97
|
-
});
|
|
73
|
+
.forEach((parent) => parent.replaceWith(...parent.childNodes));
|
|
98
74
|
}
|
|
99
75
|
|
|
100
76
|
const fragmentRe = /^\s*<(\w+|!)[^>]*>/;
|
|
101
77
|
const singleTagRe = /^<(\w+)\s*\/?>(?:<\/\1>)?$/;
|
|
102
78
|
|
|
103
79
|
export function fragment(html) {
|
|
104
|
-
|
|
105
80
|
const matches = singleTagRe.exec(html);
|
|
106
81
|
if (matches) {
|
|
107
82
|
return document.createElement(matches[1]);
|
|
@@ -114,12 +89,14 @@ export function fragment(html) {
|
|
|
114
89
|
container.textContent = html;
|
|
115
90
|
}
|
|
116
91
|
|
|
117
|
-
return
|
|
92
|
+
return unwrapSingle(container.childNodes);
|
|
93
|
+
}
|
|
118
94
|
|
|
95
|
+
function unwrapSingle(nodes) {
|
|
96
|
+
return nodes.length > 1 ? nodes : nodes[0];
|
|
119
97
|
}
|
|
120
98
|
|
|
121
99
|
export function apply(node, fn) {
|
|
122
|
-
|
|
123
100
|
if (!isElement(node)) {
|
|
124
101
|
return;
|
|
125
102
|
}
|
|
@@ -134,17 +111,13 @@ export function apply(node, fn) {
|
|
|
134
111
|
}
|
|
135
112
|
|
|
136
113
|
export function $(selector, context) {
|
|
137
|
-
return isHtml(selector)
|
|
138
|
-
? toNode(fragment(selector))
|
|
139
|
-
: find(selector, context);
|
|
114
|
+
return isHtml(selector) ? toNode(fragment(selector)) : find(selector, context);
|
|
140
115
|
}
|
|
141
116
|
|
|
142
117
|
export function $$(selector, context) {
|
|
143
|
-
return isHtml(selector)
|
|
144
|
-
? toNodes(fragment(selector))
|
|
145
|
-
: findAll(selector, context);
|
|
118
|
+
return isHtml(selector) ? toNodes(fragment(selector)) : findAll(selector, context);
|
|
146
119
|
}
|
|
147
120
|
|
|
148
121
|
function isHtml(str) {
|
|
149
|
-
return isString(str) && (str
|
|
122
|
+
return isString(str) && startsWith(str.trim(), '<');
|
|
150
123
|
}
|
package/src/js/util/env.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import {attr} from './attr';
|
|
1
|
+
import { attr } from './attr';
|
|
3
2
|
|
|
4
3
|
export const inBrowser = typeof window !== 'undefined';
|
|
5
|
-
export const isIE = inBrowser && /msie|trident/i.test(window.navigator.userAgent);
|
|
6
4
|
export const isRtl = inBrowser && attr(document.documentElement, 'dir') === 'rtl';
|
|
7
5
|
|
|
8
|
-
const
|
|
6
|
+
export const hasTouch = inBrowser && 'ontouchstart' in window;
|
|
9
7
|
const hasPointerEvents = inBrowser && window.PointerEvent;
|
|
10
|
-
export const hasTouch = inBrowser && (hasTouchEvents
|
|
11
|
-
|| window.DocumentTouch && document instanceof DocumentTouch
|
|
12
|
-
|| navigator.maxTouchPoints); // IE >=11
|
|
13
8
|
|
|
14
|
-
export const pointerDown = hasPointerEvents ? 'pointerdown' :
|
|
15
|
-
export const pointerMove = hasPointerEvents ? 'pointermove' :
|
|
16
|
-
export const pointerUp = hasPointerEvents ? 'pointerup' :
|
|
17
|
-
export const pointerEnter = hasPointerEvents ? 'pointerenter' :
|
|
18
|
-
export const pointerLeave = hasPointerEvents ? 'pointerleave' :
|
|
9
|
+
export const pointerDown = hasPointerEvents ? 'pointerdown' : hasTouch ? 'touchstart' : 'mousedown';
|
|
10
|
+
export const pointerMove = hasPointerEvents ? 'pointermove' : hasTouch ? 'touchmove' : 'mousemove';
|
|
11
|
+
export const pointerUp = hasPointerEvents ? 'pointerup' : hasTouch ? 'touchend' : 'mouseup';
|
|
12
|
+
export const pointerEnter = hasPointerEvents ? 'pointerenter' : hasTouch ? '' : 'mouseenter';
|
|
13
|
+
export const pointerLeave = hasPointerEvents ? 'pointerleave' : hasTouch ? '' : 'mouseleave';
|
|
19
14
|
export const pointerCancel = hasPointerEvents ? 'pointercancel' : 'touchcancel';
|