uikit 3.11.2-dev.31cd2ba38 → 3.11.2-dev.3dfa2c50b
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 +7 -11
- 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 +42 -17
- package/dist/css/uikit-core-rtl.min.css +1 -1
- package/dist/css/uikit-core.css +42 -17
- package/dist/css/uikit-core.min.css +1 -1
- package/dist/css/uikit-rtl.css +42 -17
- package/dist/css/uikit-rtl.min.css +1 -1
- package/dist/css/uikit.css +42 -17
- 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 +409 -438
- package/dist/js/components/filter.min.js +1 -1
- package/dist/js/components/lightbox-panel.js +1116 -1305
- package/dist/js/components/lightbox-panel.min.js +1 -1
- package/dist/js/components/lightbox.js +1164 -1383
- 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 +294 -345
- package/dist/js/components/parallax.min.js +1 -1
- package/dist/js/components/slider-parallax.js +292 -344
- package/dist/js/components/slider-parallax.min.js +1 -1
- package/dist/js/components/slider.js +727 -850
- package/dist/js/components/slider.min.js +1 -1
- package/dist/js/components/slideshow-parallax.js +292 -344
- package/dist/js/components/slideshow-parallax.min.js +1 -1
- package/dist/js/components/slideshow.js +615 -799
- package/dist/js/components/slideshow.min.js +1 -1
- package/dist/js/components/sortable.js +588 -619
- 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 +5266 -6572
- 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 +8126 -9876
- 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 +23 -27
- package/src/js/api/global.js +6 -12
- package/src/js/api/hooks.js +13 -32
- 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 +71 -66
- package/src/js/components/index.js +13 -13
- package/src/js/components/internal/lightbox-animations.js +11 -23
- package/src/js/components/internal/slider-transitioner.js +66 -45
- package/src/js/components/internal/slideshow-animations.js +42 -61
- package/src/js/components/lightbox-panel.js +135 -109
- package/src/js/components/lightbox.js +18 -39
- package/src/js/components/notification.js +49 -43
- package/src/js/components/parallax.js +16 -30
- package/src/js/components/slider-parallax.js +13 -23
- package/src/js/components/slider.js +75 -64
- package/src/js/components/slideshow-parallax.js +1 -1
- package/src/js/components/slideshow.js +8 -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 +53 -48
- package/src/js/core/alert.js +10 -17
- package/src/js/core/core.js +74 -53
- package/src/js/core/cover.js +11 -15
- package/src/js/core/drop.js +106 -92
- 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 +28 -35
- package/src/js/core/icon.js +38 -50
- package/src/js/core/img.js +130 -105
- 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 +50 -36
- package/src/js/core/nav.js +2 -4
- package/src/js/core/navbar.js +112 -88
- 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 +130 -91
- package/src/js/core/svg.js +60 -79
- package/src/js/core/switcher.js +47 -46
- package/src/js/core/tab.js +7 -10
- package/src/js/core/toggle.js +64 -66
- 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 +61 -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 +53 -48
- 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 +51 -50
- package/src/js/mixin/slideshow.js +13 -19
- package/src/js/mixin/togglable.js +90 -63
- package/src/js/uikit-core.js +2 -4
- package/src/js/uikit.js +2 -4
- package/src/js/util/ajax.js +27 -43
- package/src/js/util/animation.js +82 -75
- package/src/js/util/attr.js +17 -21
- package/src/js/util/class.js +14 -52
- package/src/js/util/dimensions.js +56 -43
- package/src/js/util/dom.js +40 -73
- 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 +0 -1
- package/src/js/util/lang.js +79 -119
- package/src/js/util/mouse.js +19 -17
- package/src/js/util/options.js +42 -47
- package/src/js/util/player.js +40 -36
- package/src/js/util/position.js +54 -46
- package/src/js/util/promise.js +0 -191
- package/src/js/util/selector.js +39 -48
- package/src/js/util/style.js +36 -46
- package/src/js/util/viewport.js +75 -64
- package/src/less/components/flex.less +0 -9
- package/src/less/components/navbar.less +0 -7
- package/src/less/components/utility.less +22 -0
- package/src/scss/components/flex.scss +0 -9
- package/src/scss/components/form.scss +3 -3
- package/src/scss/components/icon.scss +2 -2
- package/src/scss/components/navbar.scss +0 -7
- package/src/scss/components/search.scss +1 -1
- package/src/scss/components/utility.scss +22 -0
- package/src/scss/variables-theme.scss +6 -6
- package/src/scss/variables.scss +6 -6
- package/tests/image.html +38 -22
- package/tests/js/index.js +114 -85
- package/src/js/mixin/flex-bug.js +0 -56
- package/tests/images/test.avif +0 -0
- package/tests/images/test.webp +0 -0
|
@@ -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 {pageYOffset, pageXOffset} = toWindow(element);
|
|
31
|
-
const offsetBy = {height: pageYOffset, width: pageXOffset};
|
|
40
|
+
const { pageYOffset, pageXOffset } = toWindow(element);
|
|
41
|
+
const offsetBy = { height: pageYOffset, width: pageXOffset };
|
|
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,7 +99,6 @@ 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
|
|
|
@@ -92,7 +108,6 @@ export function offsetPosition(element) {
|
|
|
92
108
|
offset[1] += win.pageXOffset;
|
|
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,7 +171,6 @@ export function flipPosition(pos) {
|
|
|
157
171
|
}
|
|
158
172
|
|
|
159
173
|
export function toPx(value, property = 'width', element = window, offsetDim = false) {
|
|
160
|
-
|
|
161
174
|
if (!isString(value)) {
|
|
162
175
|
return toFloat(value);
|
|
163
176
|
}
|
|
@@ -169,10 +182,10 @@ export function toPx(value, property = 'width', element = window, offsetDim = fa
|
|
|
169
182
|
unit === 'vh'
|
|
170
183
|
? height(toWindow(element))
|
|
171
184
|
: unit === 'vw'
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
185
|
+
? width(toWindow(element))
|
|
186
|
+
: offsetDim
|
|
187
|
+
? element[`offset${ucfirst(property)}`]
|
|
188
|
+
: dimensions(element)[property],
|
|
176
189
|
value
|
|
177
190
|
);
|
|
178
191
|
}
|
|
@@ -182,10 +195,10 @@ export function toPx(value, property = 'width', element = window, offsetDim = fa
|
|
|
182
195
|
}
|
|
183
196
|
|
|
184
197
|
const calcRe = /-?\d+(?:\.\d+)?(?:v[wh]|%|px)?/g;
|
|
185
|
-
const parseCalc = memoize(calc => calc.toString().replace(/\s/g, '').match(calcRe) || []);
|
|
198
|
+
const parseCalc = memoize((calc) => calc.toString().replace(/\s/g, '').match(calcRe) || []);
|
|
186
199
|
const unitRe = /(?:v[hw]|%)$/;
|
|
187
|
-
const parseUnit = memoize(str => (str.match(unitRe) || [])[0]);
|
|
200
|
+
const parseUnit = memoize((str) => (str.match(unitRe) || [])[0]);
|
|
188
201
|
|
|
189
202
|
function percent(base, value) {
|
|
190
|
-
return base * toFloat(value) / 100;
|
|
203
|
+
return (base * toFloat(value)) / 100;
|
|
191
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;
|
|
@@ -14,62 +13,48 @@ export function ready(fn) {
|
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
export function empty(element) {
|
|
17
|
-
|
|
18
|
-
element.innerHTML = '';
|
|
19
|
-
return element;
|
|
16
|
+
return replaceChildren(element, '');
|
|
20
17
|
}
|
|
21
18
|
|
|
22
19
|
export function html(parent, html) {
|
|
23
|
-
|
|
24
|
-
return isUndefined(html)
|
|
25
|
-
? parent.innerHTML
|
|
26
|
-
: append(parent.hasChildNodes() ? empty(parent) : parent, html);
|
|
20
|
+
return isUndefined(html) ? $(parent).innerHTML : replaceChildren(parent, html);
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
export function
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
export function replaceChildren(parent, element) {
|
|
24
|
+
const nodes = $$(element);
|
|
25
|
+
$(parent).replaceChildren(...nodes);
|
|
26
|
+
return nodes;
|
|
27
|
+
}
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
29
|
+
export function prepend(parent, element) {
|
|
30
|
+
const nodes = $$(element);
|
|
31
|
+
$(parent).prepend(...nodes);
|
|
32
|
+
return nodes;
|
|
38
33
|
}
|
|
39
34
|
|
|
40
35
|
export function append(parent, element) {
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
const nodes = $$(element);
|
|
37
|
+
$(parent).append(...nodes);
|
|
38
|
+
return nodes;
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
export function before(ref, element) {
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
const nodes = $$(element);
|
|
43
|
+
$(ref).before(...nodes);
|
|
44
|
+
return nodes;
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
export function after(ref, element) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
: append(ref.parentNode, element)
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function insertNodes(element, fn) {
|
|
59
|
-
element = isString(element) ? fragment(element) : element;
|
|
60
|
-
return element
|
|
61
|
-
? 'length' in element
|
|
62
|
-
? toNodes(element).map(fn)
|
|
63
|
-
: fn(element)
|
|
64
|
-
: null;
|
|
48
|
+
const nodes = $$(element);
|
|
49
|
+
$(ref).after(...nodes);
|
|
50
|
+
return nodes;
|
|
65
51
|
}
|
|
66
52
|
|
|
67
53
|
export function remove(element) {
|
|
68
|
-
toNodes(element).forEach(element => element.
|
|
54
|
+
toNodes(element).forEach((element) => element.remove());
|
|
69
55
|
}
|
|
70
56
|
|
|
71
57
|
export function wrapAll(element, structure) {
|
|
72
|
-
|
|
73
58
|
structure = toNode(before(element, structure));
|
|
74
59
|
|
|
75
60
|
while (structure.firstChild) {
|
|
@@ -82,44 +67,30 @@ export function wrapAll(element, structure) {
|
|
|
82
67
|
}
|
|
83
68
|
|
|
84
69
|
export function wrapInner(element, structure) {
|
|
85
|
-
return toNodes(
|
|
86
|
-
element.
|
|
87
|
-
|
|
70
|
+
return toNodes(
|
|
71
|
+
toNodes(element).map((element) =>
|
|
72
|
+
element.hasChildNodes
|
|
73
|
+
? wrapAll(toNodes(element.childNodes), structure)
|
|
74
|
+
: append(element, structure)
|
|
75
|
+
)
|
|
76
|
+
);
|
|
88
77
|
}
|
|
89
78
|
|
|
90
79
|
export function unwrap(element) {
|
|
91
80
|
toNodes(element)
|
|
92
81
|
.map(parent)
|
|
93
82
|
.filter((value, index, self) => self.indexOf(value) === index)
|
|
94
|
-
.forEach(parent =>
|
|
95
|
-
before(parent, parent.childNodes);
|
|
96
|
-
remove(parent);
|
|
97
|
-
});
|
|
83
|
+
.forEach((parent) => parent.replaceWith(...parent.childNodes));
|
|
98
84
|
}
|
|
99
85
|
|
|
100
|
-
const fragmentRe = /^\s*<(\w+|!)[^>]*>/;
|
|
101
|
-
const singleTagRe = /^<(\w+)\s*\/?>(?:<\/\1>)?$/;
|
|
102
|
-
|
|
103
86
|
export function fragment(html) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const container = document.createElement('div');
|
|
111
|
-
if (fragmentRe.test(html)) {
|
|
112
|
-
container.insertAdjacentHTML('beforeend', html.trim());
|
|
113
|
-
} else {
|
|
114
|
-
container.textContent = html;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return container.childNodes.length > 1 ? toNodes(container.childNodes) : container.firstChild;
|
|
118
|
-
|
|
87
|
+
const template = document.createElement('template');
|
|
88
|
+
template.innerHTML = html;
|
|
89
|
+
const { childNodes } = template.content;
|
|
90
|
+
return childNodes.length > 1 ? toNodes(childNodes) : childNodes[0];
|
|
119
91
|
}
|
|
120
92
|
|
|
121
93
|
export function apply(node, fn) {
|
|
122
|
-
|
|
123
94
|
if (!isElement(node)) {
|
|
124
95
|
return;
|
|
125
96
|
}
|
|
@@ -134,17 +105,13 @@ export function apply(node, fn) {
|
|
|
134
105
|
}
|
|
135
106
|
|
|
136
107
|
export function $(selector, context) {
|
|
137
|
-
return isHtml(selector)
|
|
138
|
-
? toNode(fragment(selector))
|
|
139
|
-
: find(selector, context);
|
|
108
|
+
return isHtml(selector) ? toNode(fragment(selector)) : find(selector, context);
|
|
140
109
|
}
|
|
141
110
|
|
|
142
111
|
export function $$(selector, context) {
|
|
143
|
-
return isHtml(selector)
|
|
144
|
-
? toNodes(fragment(selector))
|
|
145
|
-
: findAll(selector, context);
|
|
112
|
+
return isHtml(selector) ? toNodes(fragment(selector)) : findAll(selector, context);
|
|
146
113
|
}
|
|
147
114
|
|
|
148
115
|
function isHtml(str) {
|
|
149
|
-
return isString(str) && (str
|
|
116
|
+
return isString(str) && startsWith(str.trim(), '<');
|
|
150
117
|
}
|
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';
|
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) {
|