uikit 3.11.2-dev.fb043abc2 → 3.12.2
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 +63 -20
- 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 +144 -202
- package/dist/css/uikit-core-rtl.min.css +1 -1
- package/dist/css/uikit-core.css +144 -202
- package/dist/css/uikit-core.min.css +1 -1
- package/dist/css/uikit-rtl.css +146 -208
- package/dist/css/uikit-rtl.min.css +1 -1
- package/dist/css/uikit.css +146 -208
- package/dist/css/uikit.min.css +1 -1
- package/dist/js/components/countdown.js +66 -138
- 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 -361
- 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 +156 -167
- package/dist/js/components/upload.min.js +1 -1
- package/dist/js/uikit-core.js +5317 -6554
- 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 +8018 -9698
- 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 +32 -85
- 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 +16 -30
- 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 +53 -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 +161 -128
- 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 +58 -45
- package/src/js/util/dom.js +37 -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 +18 -36
- 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/list.less +5 -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 +3 -3
- package/src/less/components/slideshow.less +3 -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/list.scss +5 -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 +3 -3
- package/src/scss/components/slideshow.scss +3 -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/countdown.html +10 -8
- 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 +57 -72
- package/tests/sticky.html +14 -3
- 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/player.js
CHANGED
|
@@ -1,43 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { isTag } from './dom';
|
|
2
|
+
import { once } from './event';
|
|
3
|
+
import { includes, noop } from './lang';
|
|
4
4
|
|
|
5
5
|
export function play(el) {
|
|
6
|
-
|
|
7
6
|
if (isIFrame(el)) {
|
|
8
|
-
call(el, {func: 'playVideo', method: 'play'});
|
|
7
|
+
call(el, { func: 'playVideo', method: 'play' });
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
if (isHTML5(el)) {
|
|
12
11
|
try {
|
|
13
12
|
el.play().catch(noop);
|
|
14
|
-
} catch (e) {
|
|
13
|
+
} catch (e) {
|
|
14
|
+
// noop
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
|
-
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function pause(el) {
|
|
20
|
-
|
|
21
20
|
if (isIFrame(el)) {
|
|
22
|
-
call(el, {func: 'pauseVideo', method: 'pause'});
|
|
21
|
+
call(el, { func: 'pauseVideo', method: 'pause' });
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
if (isHTML5(el)) {
|
|
26
25
|
el.pause();
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
export function mute(el) {
|
|
32
|
-
|
|
33
30
|
if (isIFrame(el)) {
|
|
34
|
-
call(el, {func: 'mute', method: 'setVolume', value: 0});
|
|
31
|
+
call(el, { func: 'mute', method: 'setVolume', value: 0 });
|
|
35
32
|
}
|
|
36
33
|
|
|
37
34
|
if (isHTML5(el)) {
|
|
38
35
|
el.muted = true;
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
export function isVideo(el) {
|
|
@@ -45,35 +41,39 @@ export function isVideo(el) {
|
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
function isHTML5(el) {
|
|
48
|
-
return el
|
|
44
|
+
return isTag(el, 'video');
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
function isIFrame(el) {
|
|
52
|
-
return el
|
|
48
|
+
return isTag(el, 'iframe') && (isYoutube(el) || isVimeo(el));
|
|
53
49
|
}
|
|
54
50
|
|
|
55
51
|
function isYoutube(el) {
|
|
56
|
-
return !!el.src.match(
|
|
52
|
+
return !!el.src.match(
|
|
53
|
+
/\/\/.*?youtube(-nocookie)?\.[a-z]+\/(watch\?v=[^&\s]+|embed)|youtu\.be\/.*/
|
|
54
|
+
);
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
function isVimeo(el) {
|
|
60
58
|
return !!el.src.match(/vimeo\.com\/video\/.*/);
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
function call(el, cmd) {
|
|
64
|
-
enableApi(el)
|
|
61
|
+
async function call(el, cmd) {
|
|
62
|
+
await enableApi(el);
|
|
63
|
+
post(el, cmd);
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
function post(el, cmd) {
|
|
68
67
|
try {
|
|
69
|
-
el.contentWindow.postMessage(JSON.stringify(
|
|
70
|
-
} catch (e) {
|
|
68
|
+
el.contentWindow.postMessage(JSON.stringify({ event: 'command', ...cmd }), '*');
|
|
69
|
+
} catch (e) {
|
|
70
|
+
// noop
|
|
71
|
+
}
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
const stateKey = '_ukPlayer';
|
|
74
75
|
let counter = 0;
|
|
75
76
|
function enableApi(el) {
|
|
76
|
-
|
|
77
77
|
if (el[stateKey]) {
|
|
78
78
|
return el[stateKey];
|
|
79
79
|
}
|
|
@@ -84,24 +84,29 @@ function enableApi(el) {
|
|
|
84
84
|
const id = ++counter;
|
|
85
85
|
let poller;
|
|
86
86
|
|
|
87
|
-
return el[stateKey] = new Promise(resolve => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
once(window, 'message', resolve, false, ({data}) => {
|
|
87
|
+
return (el[stateKey] = new Promise((resolve) => {
|
|
88
|
+
youtube &&
|
|
89
|
+
once(el, 'load', () => {
|
|
90
|
+
const listener = () => post(el, { event: 'listening', id });
|
|
91
|
+
poller = setInterval(listener, 100);
|
|
92
|
+
listener();
|
|
93
|
+
});
|
|
96
94
|
|
|
95
|
+
once(window, 'message', resolve, false, ({ data }) => {
|
|
97
96
|
try {
|
|
98
97
|
data = JSON.parse(data);
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
return (
|
|
99
|
+
data &&
|
|
100
|
+
((youtube && data.id === id && data.event === 'onReady') ||
|
|
101
|
+
(vimeo && Number(data.player_id) === id))
|
|
102
|
+
);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
// noop
|
|
105
|
+
}
|
|
102
106
|
});
|
|
103
107
|
|
|
104
|
-
el.src = `${el.src}${includes(el.src, '?') ? '&' : '?'}${
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
el.src = `${el.src}${includes(el.src, '?') ? '&' : '?'}${
|
|
109
|
+
youtube ? 'enablejsapi=1' : `api=1&player_id=${id}`
|
|
110
|
+
}`;
|
|
111
|
+
}).then(() => clearInterval(poller)));
|
|
107
112
|
}
|
package/src/js/util/position.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import {offset} from './dimensions';
|
|
2
|
-
import {each, endsWith, includes, toFloat} from './lang';
|
|
3
|
-
import {getViewport, scrollParents} from './viewport';
|
|
1
|
+
import { offset } from './dimensions';
|
|
2
|
+
import { each, endsWith, includes, toFloat } from './lang';
|
|
3
|
+
import { getViewport, scrollParents } from './viewport';
|
|
4
4
|
|
|
5
5
|
const dirs = {
|
|
6
6
|
width: ['x', 'left', 'right'],
|
|
7
|
-
height: ['y', 'top', 'bottom']
|
|
7
|
+
height: ['y', 'top', 'bottom'],
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export function positionAt(
|
|
11
|
-
|
|
10
|
+
export function positionAt(
|
|
11
|
+
element,
|
|
12
|
+
target,
|
|
13
|
+
elAttach,
|
|
14
|
+
targetAttach,
|
|
15
|
+
elOffset,
|
|
16
|
+
targetOffset,
|
|
17
|
+
flip,
|
|
18
|
+
boundary
|
|
19
|
+
) {
|
|
12
20
|
elAttach = getPos(elAttach);
|
|
13
21
|
targetAttach = getPos(targetAttach);
|
|
14
22
|
|
|
15
|
-
const flipped = {element: elAttach, target: targetAttach};
|
|
23
|
+
const flipped = { element: elAttach, target: targetAttach };
|
|
16
24
|
|
|
17
25
|
if (!element || !target) {
|
|
18
26
|
return flipped;
|
|
@@ -35,69 +43,71 @@ export function positionAt(element, target, elAttach, targetAttach, elOffset, ta
|
|
|
35
43
|
position.top += elOffset['y'];
|
|
36
44
|
|
|
37
45
|
if (flip) {
|
|
38
|
-
|
|
39
46
|
let boundaries = scrollParents(element).map(getViewport);
|
|
40
47
|
|
|
41
48
|
if (boundary && !includes(boundaries, boundary)) {
|
|
42
49
|
boundaries.unshift(boundary);
|
|
43
50
|
}
|
|
44
51
|
|
|
45
|
-
boundaries = boundaries.map(el => offset(el));
|
|
52
|
+
boundaries = boundaries.map((el) => offset(el));
|
|
46
53
|
|
|
47
54
|
each(dirs, ([dir, align, alignFlip], prop) => {
|
|
48
|
-
|
|
49
55
|
if (!(flip === true || includes(flip, dir))) {
|
|
50
56
|
return;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
boundaries.some(boundary => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
boundaries.some((boundary) => {
|
|
60
|
+
const elemOffset =
|
|
61
|
+
elAttach[dir] === align
|
|
62
|
+
? -dim[prop]
|
|
63
|
+
: elAttach[dir] === alignFlip
|
|
58
64
|
? dim[prop]
|
|
59
65
|
: 0;
|
|
60
66
|
|
|
61
|
-
const targetOffset =
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
const targetOffset =
|
|
68
|
+
targetAttach[dir] === align
|
|
69
|
+
? targetDim[prop]
|
|
70
|
+
: targetAttach[dir] === alignFlip
|
|
64
71
|
? -targetDim[prop]
|
|
65
72
|
: 0;
|
|
66
73
|
|
|
67
|
-
if (
|
|
68
|
-
|
|
74
|
+
if (
|
|
75
|
+
position[align] < boundary[align] ||
|
|
76
|
+
position[align] + dim[prop] > boundary[alignFlip]
|
|
77
|
+
) {
|
|
69
78
|
const centerOffset = dim[prop] / 2;
|
|
70
|
-
const centerTargetOffset =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
const centerTargetOffset =
|
|
80
|
+
targetAttach[dir] === 'center' ? -targetDim[prop] / 2 : 0;
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
(elAttach[dir] === 'center' &&
|
|
84
|
+
(apply(centerOffset, centerTargetOffset) ||
|
|
85
|
+
apply(-centerOffset, -centerTargetOffset))) ||
|
|
86
|
+
apply(elemOffset, targetOffset)
|
|
87
|
+
);
|
|
77
88
|
}
|
|
78
89
|
|
|
79
90
|
function apply(elemOffset, targetOffset) {
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
const newVal = toFloat(
|
|
92
|
+
(position[align] + elemOffset + targetOffset - elOffset[dir] * 2).toFixed(4)
|
|
93
|
+
);
|
|
82
94
|
|
|
83
95
|
if (newVal >= boundary[align] && newVal + dim[prop] <= boundary[alignFlip]) {
|
|
84
96
|
position[align] = newVal;
|
|
85
97
|
|
|
86
|
-
['element', 'target']
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
for (const el of ['element', 'target']) {
|
|
99
|
+
if (elemOffset) {
|
|
100
|
+
flipped[el][dir] =
|
|
101
|
+
flipped[el][dir] === dirs[prop][1]
|
|
102
|
+
? dirs[prop][2]
|
|
103
|
+
: dirs[prop][1];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
93
106
|
|
|
94
107
|
return true;
|
|
95
108
|
}
|
|
96
|
-
|
|
97
109
|
}
|
|
98
|
-
|
|
99
110
|
});
|
|
100
|
-
|
|
101
111
|
});
|
|
102
112
|
}
|
|
103
113
|
|
|
@@ -111,13 +121,12 @@ function moveTo(position, attach, dim, factor) {
|
|
|
111
121
|
if (attach[dir] === alignFlip) {
|
|
112
122
|
position[align] += dim[prop] * factor;
|
|
113
123
|
} else if (attach[dir] === 'center') {
|
|
114
|
-
position[align] += dim[prop] * factor / 2;
|
|
124
|
+
position[align] += (dim[prop] * factor) / 2;
|
|
115
125
|
}
|
|
116
126
|
});
|
|
117
127
|
}
|
|
118
128
|
|
|
119
129
|
function getPos(pos) {
|
|
120
|
-
|
|
121
130
|
const x = /left|center|right/;
|
|
122
131
|
const y = /top|center|bottom/;
|
|
123
132
|
|
|
@@ -127,22 +136,21 @@ function getPos(pos) {
|
|
|
127
136
|
pos = x.test(pos[0])
|
|
128
137
|
? pos.concat('center')
|
|
129
138
|
: y.test(pos[0])
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
? ['center'].concat(pos)
|
|
140
|
+
: ['center', 'center'];
|
|
132
141
|
}
|
|
133
142
|
|
|
134
143
|
return {
|
|
135
144
|
x: x.test(pos[0]) ? pos[0] : 'center',
|
|
136
|
-
y: y.test(pos[1]) ? pos[1] : 'center'
|
|
145
|
+
y: y.test(pos[1]) ? pos[1] : 'center',
|
|
137
146
|
};
|
|
138
147
|
}
|
|
139
148
|
|
|
140
149
|
function getOffsets(offsets, width, height) {
|
|
141
|
-
|
|
142
150
|
const [x, y] = (offsets || '').split(' ');
|
|
143
151
|
|
|
144
152
|
return {
|
|
145
153
|
x: x ? toFloat(x) * (endsWith(x, '%') ? width / 100 : 1) : 0,
|
|
146
|
-
y: y ? toFloat(y) * (endsWith(y, '%') ? height / 100 : 1) : 0
|
|
154
|
+
y: y ? toFloat(y) * (endsWith(y, '%') ? height / 100 : 1) : 0,
|
|
147
155
|
};
|
|
148
156
|
}
|
package/src/js/util/selector.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {attr} from './attr';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {isDocument, isString, memoize, toNode, toNodes} from './lang';
|
|
1
|
+
import { attr } from './attr';
|
|
2
|
+
import { closest, index, matches, parent } from './filter';
|
|
3
|
+
import { isDocument, isString, memoize, toNode, toNodes } from './lang';
|
|
5
4
|
|
|
6
5
|
export function query(selector, context) {
|
|
7
6
|
return find(selector, getContext(selector, context));
|
|
@@ -11,12 +10,6 @@ export function queryAll(selector, context) {
|
|
|
11
10
|
return findAll(selector, getContext(selector, context));
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
function getContext(selector, context = document) {
|
|
15
|
-
return isString(selector) && isContextSelector(selector) || isDocument(context)
|
|
16
|
-
? context
|
|
17
|
-
: context.ownerDocument;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
13
|
export function find(selector, context) {
|
|
21
14
|
return toNode(_query(selector, context, 'querySelector'));
|
|
22
15
|
}
|
|
@@ -25,8 +18,18 @@ export function findAll(selector, context) {
|
|
|
25
18
|
return toNodes(_query(selector, context, 'querySelectorAll'));
|
|
26
19
|
}
|
|
27
20
|
|
|
28
|
-
|
|
21
|
+
const contextSelectorRe = /(^|[^\\],)\s*[!>+~-]/;
|
|
22
|
+
const isContextSelector = memoize((selector) => selector.match(contextSelectorRe));
|
|
23
|
+
|
|
24
|
+
function getContext(selector, context = document) {
|
|
25
|
+
return (isString(selector) && isContextSelector(selector)) || isDocument(context)
|
|
26
|
+
? context
|
|
27
|
+
: context.ownerDocument;
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
+
const contextSanitizeRe = /([!>+~-])(?=\s+[!>+~-]|\s*$)/g;
|
|
31
|
+
|
|
32
|
+
function _query(selector, context = document, queryFn) {
|
|
30
33
|
if (!selector || !isString(selector)) {
|
|
31
34
|
return selector;
|
|
32
35
|
}
|
|
@@ -34,63 +37,46 @@ function _query(selector, context = document, queryFn) {
|
|
|
34
37
|
selector = selector.replace(contextSanitizeRe, '$1 *');
|
|
35
38
|
|
|
36
39
|
if (isContextSelector(selector)) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return `${domPath(ctx)} ${selector}`;
|
|
64
|
-
|
|
65
|
-
}).filter(Boolean).join(',');
|
|
40
|
+
selector = splitSelector(selector)
|
|
41
|
+
.map((selector) => {
|
|
42
|
+
let ctx = context;
|
|
43
|
+
|
|
44
|
+
if (selector[0] === '!') {
|
|
45
|
+
const selectors = selector.substr(1).trim().split(' ');
|
|
46
|
+
ctx = closest(parent(context), selectors[0]);
|
|
47
|
+
selector = selectors.slice(1).join(' ').trim();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (selector[0] === '-') {
|
|
51
|
+
const selectors = selector.substr(1).trim().split(' ');
|
|
52
|
+
const prev = (ctx || context).previousElementSibling;
|
|
53
|
+
ctx = matches(prev, selector.substr(1)) ? prev : null;
|
|
54
|
+
selector = selectors.slice(1).join(' ');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!ctx) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return `${domPath(ctx)} ${selector}`;
|
|
62
|
+
})
|
|
63
|
+
.filter(Boolean)
|
|
64
|
+
.join(',');
|
|
66
65
|
|
|
67
66
|
context = document;
|
|
68
|
-
|
|
69
67
|
}
|
|
70
68
|
|
|
71
69
|
try {
|
|
72
|
-
|
|
73
70
|
return context[queryFn](selector);
|
|
74
|
-
|
|
75
71
|
} catch (e) {
|
|
76
|
-
|
|
77
72
|
return null;
|
|
78
|
-
|
|
79
73
|
}
|
|
80
|
-
|
|
81
74
|
}
|
|
82
75
|
|
|
83
|
-
const contextSelectorRe = /(^|[^\\],)\s*[!>+~-]/;
|
|
84
|
-
const contextSanitizeRe = /([!>+~-])(?=\s+[!>+~-]|\s*$)/g;
|
|
85
|
-
|
|
86
|
-
const isContextSelector = memoize(selector => selector.match(contextSelectorRe));
|
|
87
|
-
|
|
88
76
|
const selectorRe = /.*?[^\\](?:,|$)/g;
|
|
89
77
|
|
|
90
|
-
const splitSelector = memoize(selector =>
|
|
91
|
-
selector.match(selectorRe).map(selector =>
|
|
92
|
-
selector.replace(/,$/, '').trim()
|
|
93
|
-
)
|
|
78
|
+
const splitSelector = memoize((selector) =>
|
|
79
|
+
selector.match(selectorRe).map((selector) => selector.replace(/,$/, '').trim())
|
|
94
80
|
);
|
|
95
81
|
|
|
96
82
|
function domPath(element) {
|
|
@@ -101,7 +87,7 @@ function domPath(element) {
|
|
|
101
87
|
names.unshift(`#${escape(id)}`);
|
|
102
88
|
break;
|
|
103
89
|
} else {
|
|
104
|
-
let {tagName} = element;
|
|
90
|
+
let { tagName } = element;
|
|
105
91
|
if (tagName !== 'HTML') {
|
|
106
92
|
tagName += `:nth-child(${index(element) + 1})`;
|
|
107
93
|
}
|
|
@@ -112,7 +98,6 @@ function domPath(element) {
|
|
|
112
98
|
return names.join(' > ');
|
|
113
99
|
}
|
|
114
100
|
|
|
115
|
-
const escapeFn = inBrowser && window.CSS && CSS.escape || function (css) { return css.replace(/([^\x7f-\uFFFF\w-])/g, match => `\\${match}`); };
|
|
116
101
|
export function escape(css) {
|
|
117
|
-
return isString(css) ?
|
|
102
|
+
return isString(css) ? CSS.escape(css) : '';
|
|
118
103
|
}
|
package/src/js/util/style.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
each,
|
|
3
|
+
hyphenate,
|
|
4
|
+
isArray,
|
|
5
|
+
isNumber,
|
|
6
|
+
isNumeric,
|
|
7
|
+
isObject,
|
|
8
|
+
isString,
|
|
9
|
+
isUndefined,
|
|
10
|
+
memoize,
|
|
11
|
+
toNodes,
|
|
12
|
+
toWindow,
|
|
13
|
+
} from './lang';
|
|
5
14
|
|
|
6
15
|
const cssNumber = {
|
|
7
16
|
'animation-iteration-count': true,
|
|
@@ -11,22 +20,20 @@ const cssNumber = {
|
|
|
11
20
|
'flex-shrink': true,
|
|
12
21
|
'font-weight': true,
|
|
13
22
|
'line-height': true,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
opacity: true,
|
|
24
|
+
order: true,
|
|
25
|
+
orphans: true,
|
|
17
26
|
'stroke-dasharray': true,
|
|
18
27
|
'stroke-dashoffset': true,
|
|
19
|
-
|
|
28
|
+
widows: true,
|
|
20
29
|
'z-index': true,
|
|
21
|
-
|
|
30
|
+
zoom: true,
|
|
22
31
|
};
|
|
23
32
|
|
|
24
33
|
export function css(element, property, value, priority = '') {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
const elements = toNodes(element);
|
|
35
|
+
for (const element of elements) {
|
|
28
36
|
if (isString(property)) {
|
|
29
|
-
|
|
30
37
|
property = propName(property);
|
|
31
38
|
|
|
32
39
|
if (isUndefined(value)) {
|
|
@@ -34,27 +41,25 @@ export function css(element, property, value, priority = '') {
|
|
|
34
41
|
} else if (!value && !isNumber(value)) {
|
|
35
42
|
element.style.removeProperty(property);
|
|
36
43
|
} else {
|
|
37
|
-
element.style.setProperty(
|
|
44
|
+
element.style.setProperty(
|
|
45
|
+
property,
|
|
46
|
+
isNumeric(value) && !cssNumber[property] ? `${value}px` : value,
|
|
47
|
+
priority
|
|
48
|
+
);
|
|
38
49
|
}
|
|
39
|
-
|
|
40
50
|
} else if (isArray(property)) {
|
|
41
|
-
|
|
42
51
|
const styles = getStyles(element);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
props[
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
const props = {};
|
|
53
|
+
for (const prop of property) {
|
|
54
|
+
props[prop] = styles[propName(prop)];
|
|
55
|
+
}
|
|
56
|
+
return props;
|
|
49
57
|
} else if (isObject(property)) {
|
|
50
58
|
priority = value;
|
|
51
59
|
each(property, (value, property) => css(element, property, value, priority));
|
|
52
60
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
})[0];
|
|
57
|
-
|
|
61
|
+
}
|
|
62
|
+
return elements[0];
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
function getStyles(element, pseudoElt) {
|
|
@@ -65,44 +70,29 @@ function getStyle(element, property, pseudoElt) {
|
|
|
65
70
|
return getStyles(element, pseudoElt)[property];
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
const parseCssVar = memoize(name => {
|
|
69
|
-
/* usage in css: .uk-name:before { content:"xyz" } */
|
|
70
|
-
|
|
71
|
-
const element = append(document.documentElement, fragment('<div>'));
|
|
72
|
-
|
|
73
|
-
addClass(element, `uk-${name}`);
|
|
74
|
-
|
|
75
|
-
const value = getStyle(element, 'content', ':before');
|
|
76
|
-
|
|
77
|
-
remove(element);
|
|
78
|
-
|
|
79
|
-
return value;
|
|
80
|
-
});
|
|
81
|
-
|
|
82
73
|
const propertyRe = /^\s*(["'])?(.*?)\1\s*$/;
|
|
83
74
|
export function getCssVar(name) {
|
|
84
|
-
return (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
).replace(propertyRe, '$2');
|
|
75
|
+
return getStyles(document.documentElement)
|
|
76
|
+
.getPropertyValue(`--uk-${name}`)
|
|
77
|
+
.replace(propertyRe, '$2');
|
|
88
78
|
}
|
|
89
79
|
|
|
90
80
|
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty
|
|
91
|
-
export const propName = memoize(name => vendorPropName(name));
|
|
81
|
+
export const propName = memoize((name) => vendorPropName(name));
|
|
92
82
|
|
|
93
83
|
const cssPrefixes = ['webkit', 'moz', 'ms'];
|
|
94
84
|
|
|
95
85
|
function vendorPropName(name) {
|
|
96
|
-
|
|
97
86
|
name = hyphenate(name);
|
|
98
87
|
|
|
99
|
-
const {style} = document.documentElement;
|
|
88
|
+
const { style } = document.documentElement;
|
|
100
89
|
|
|
101
90
|
if (name in style) {
|
|
102
91
|
return name;
|
|
103
92
|
}
|
|
104
93
|
|
|
105
|
-
let i = cssPrefixes.length,
|
|
94
|
+
let i = cssPrefixes.length,
|
|
95
|
+
prefixedName;
|
|
106
96
|
|
|
107
97
|
while (i--) {
|
|
108
98
|
prefixedName = `-${cssPrefixes[i]}-${name}`;
|