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
package/src/js/util/options.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
assign,
|
|
3
|
+
hasOwn,
|
|
4
|
+
includes,
|
|
5
|
+
isArray,
|
|
6
|
+
isFunction,
|
|
7
|
+
isUndefined,
|
|
8
|
+
sortBy,
|
|
9
|
+
startsWith,
|
|
10
|
+
} from './lang';
|
|
2
11
|
|
|
3
12
|
const strats = {};
|
|
4
13
|
|
|
5
14
|
strats.events =
|
|
6
|
-
strats.created =
|
|
7
|
-
strats.beforeConnect =
|
|
8
|
-
strats.connected =
|
|
9
|
-
strats.beforeDisconnect =
|
|
10
|
-
strats.disconnected =
|
|
11
|
-
strats.destroy =
|
|
15
|
+
strats.created =
|
|
16
|
+
strats.beforeConnect =
|
|
17
|
+
strats.connected =
|
|
18
|
+
strats.beforeDisconnect =
|
|
19
|
+
strats.disconnected =
|
|
20
|
+
strats.destroy =
|
|
21
|
+
concatStrat;
|
|
12
22
|
|
|
13
23
|
// args strategy
|
|
14
24
|
strats.args = function (parentVal, childVal) {
|
|
@@ -17,37 +27,33 @@ strats.args = function (parentVal, childVal) {
|
|
|
17
27
|
|
|
18
28
|
// update strategy
|
|
19
29
|
strats.update = function (parentVal, childVal) {
|
|
20
|
-
return sortBy(
|
|
30
|
+
return sortBy(
|
|
31
|
+
concatStrat(parentVal, isFunction(childVal) ? { read: childVal } : childVal),
|
|
32
|
+
'order'
|
|
33
|
+
);
|
|
21
34
|
};
|
|
22
35
|
|
|
23
36
|
// property strategy
|
|
24
37
|
strats.props = function (parentVal, childVal) {
|
|
25
|
-
|
|
26
38
|
if (isArray(childVal)) {
|
|
27
|
-
|
|
39
|
+
const value = {};
|
|
40
|
+
for (const key of childVal) {
|
|
28
41
|
value[key] = String;
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
}
|
|
43
|
+
childVal = value;
|
|
31
44
|
}
|
|
32
45
|
|
|
33
46
|
return strats.methods(parentVal, childVal);
|
|
34
47
|
};
|
|
35
48
|
|
|
36
49
|
// extend strategy
|
|
37
|
-
strats.computed =
|
|
38
|
-
|
|
39
|
-
return childVal
|
|
40
|
-
? parentVal
|
|
41
|
-
? assign({}, parentVal, childVal)
|
|
42
|
-
: childVal
|
|
43
|
-
: parentVal;
|
|
50
|
+
strats.computed = strats.methods = function (parentVal, childVal) {
|
|
51
|
+
return childVal ? (parentVal ? assign({}, parentVal, childVal) : childVal) : parentVal;
|
|
44
52
|
};
|
|
45
53
|
|
|
46
54
|
// data strategy
|
|
47
55
|
strats.data = function (parentVal, childVal, vm) {
|
|
48
|
-
|
|
49
56
|
if (!vm) {
|
|
50
|
-
|
|
51
57
|
if (!childVal) {
|
|
52
58
|
return parentVal;
|
|
53
59
|
}
|
|
@@ -59,7 +65,6 @@ strats.data = function (parentVal, childVal, vm) {
|
|
|
59
65
|
return function (vm) {
|
|
60
66
|
return mergeFnData(parentVal, childVal, vm);
|
|
61
67
|
};
|
|
62
|
-
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
return mergeFnData(parentVal, childVal, vm);
|
|
@@ -67,26 +72,21 @@ strats.data = function (parentVal, childVal, vm) {
|
|
|
67
72
|
|
|
68
73
|
function mergeFnData(parentVal, childVal, vm) {
|
|
69
74
|
return strats.computed(
|
|
70
|
-
isFunction(parentVal)
|
|
71
|
-
|
|
72
|
-
: parentVal,
|
|
73
|
-
isFunction(childVal)
|
|
74
|
-
? childVal.call(vm, vm)
|
|
75
|
-
: childVal
|
|
75
|
+
isFunction(parentVal) ? parentVal.call(vm, vm) : parentVal,
|
|
76
|
+
isFunction(childVal) ? childVal.call(vm, vm) : childVal
|
|
76
77
|
);
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
// concat strategy
|
|
80
81
|
function concatStrat(parentVal, childVal) {
|
|
81
|
-
|
|
82
82
|
parentVal = parentVal && !isArray(parentVal) ? [parentVal] : parentVal;
|
|
83
83
|
|
|
84
84
|
return childVal
|
|
85
85
|
? parentVal
|
|
86
86
|
? parentVal.concat(childVal)
|
|
87
87
|
: isArray(childVal)
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
? childVal
|
|
89
|
+
: [childVal]
|
|
90
90
|
: parentVal;
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -96,7 +96,6 @@ function defaultStrat(parentVal, childVal) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export function mergeOptions(parent, child, vm) {
|
|
99
|
-
|
|
100
99
|
const options = {};
|
|
101
100
|
|
|
102
101
|
if (isFunction(child)) {
|
|
@@ -108,8 +107,8 @@ export function mergeOptions(parent, child, vm) {
|
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
if (child.mixins) {
|
|
111
|
-
for (
|
|
112
|
-
parent = mergeOptions(parent,
|
|
110
|
+
for (const mixin of child.mixins) {
|
|
111
|
+
parent = mergeOptions(parent, mixin, vm);
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
|
|
@@ -131,25 +130,21 @@ export function mergeOptions(parent, child, vm) {
|
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
export function parseOptions(options, args = []) {
|
|
134
|
-
|
|
135
133
|
try {
|
|
136
|
-
|
|
137
134
|
return options
|
|
138
|
-
? options
|
|
135
|
+
? startsWith(options, '{')
|
|
139
136
|
? JSON.parse(options)
|
|
140
137
|
: args.length && !includes(options, ':')
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
138
|
+
? { [args[0]]: options }
|
|
139
|
+
: options.split(';').reduce((options, option) => {
|
|
140
|
+
const [key, value] = option.split(/:(.*)/);
|
|
141
|
+
if (key && !isUndefined(value)) {
|
|
142
|
+
options[key.trim()] = value.trim();
|
|
143
|
+
}
|
|
144
|
+
return options;
|
|
145
|
+
}, {})
|
|
149
146
|
: {};
|
|
150
|
-
|
|
151
147
|
} catch (e) {
|
|
152
148
|
return {};
|
|
153
149
|
}
|
|
154
|
-
|
|
155
150
|
}
|
package/src/js/util/player.js
CHANGED
|
@@ -1,43 +1,38 @@
|
|
|
1
|
-
import {once} from './event';
|
|
2
|
-
import {
|
|
3
|
-
import {assign, includes, noop} from './lang';
|
|
1
|
+
import { once } from './event';
|
|
2
|
+
import { assign, includes, noop } from './lang';
|
|
4
3
|
|
|
5
4
|
export function play(el) {
|
|
6
|
-
|
|
7
5
|
if (isIFrame(el)) {
|
|
8
|
-
call(el, {func: 'playVideo', method: 'play'});
|
|
6
|
+
call(el, { func: 'playVideo', method: 'play' });
|
|
9
7
|
}
|
|
10
8
|
|
|
11
9
|
if (isHTML5(el)) {
|
|
12
10
|
try {
|
|
13
11
|
el.play().catch(noop);
|
|
14
|
-
} catch (e) {
|
|
12
|
+
} catch (e) {
|
|
13
|
+
// noop
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
|
-
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
export function pause(el) {
|
|
20
|
-
|
|
21
19
|
if (isIFrame(el)) {
|
|
22
|
-
call(el, {func: 'pauseVideo', method: 'pause'});
|
|
20
|
+
call(el, { func: 'pauseVideo', method: 'pause' });
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
if (isHTML5(el)) {
|
|
26
24
|
el.pause();
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
}
|
|
30
27
|
|
|
31
28
|
export function mute(el) {
|
|
32
|
-
|
|
33
29
|
if (isIFrame(el)) {
|
|
34
|
-
call(el, {func: 'mute', method: 'setVolume', value: 0});
|
|
30
|
+
call(el, { func: 'mute', method: 'setVolume', value: 0 });
|
|
35
31
|
}
|
|
36
32
|
|
|
37
33
|
if (isHTML5(el)) {
|
|
38
34
|
el.muted = true;
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
export function isVideo(el) {
|
|
@@ -45,35 +40,39 @@ export function isVideo(el) {
|
|
|
45
40
|
}
|
|
46
41
|
|
|
47
42
|
function isHTML5(el) {
|
|
48
|
-
return el
|
|
43
|
+
return el?.tagName === 'VIDEO';
|
|
49
44
|
}
|
|
50
45
|
|
|
51
46
|
function isIFrame(el) {
|
|
52
|
-
return el
|
|
47
|
+
return el?.tagName === 'IFRAME' && (isYoutube(el) || isVimeo(el));
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
function isYoutube(el) {
|
|
56
|
-
return !!el.src.match(
|
|
51
|
+
return !!el.src.match(
|
|
52
|
+
/\/\/.*?youtube(-nocookie)?\.[a-z]+\/(watch\?v=[^&\s]+|embed)|youtu\.be\/.*/
|
|
53
|
+
);
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
function isVimeo(el) {
|
|
60
57
|
return !!el.src.match(/vimeo\.com\/video\/.*/);
|
|
61
58
|
}
|
|
62
59
|
|
|
63
|
-
function call(el, cmd) {
|
|
64
|
-
enableApi(el)
|
|
60
|
+
async function call(el, cmd) {
|
|
61
|
+
await enableApi(el);
|
|
62
|
+
post(el, cmd);
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
function post(el, cmd) {
|
|
68
66
|
try {
|
|
69
|
-
el.contentWindow.postMessage(JSON.stringify(assign({event: 'command'}, cmd)), '*');
|
|
70
|
-
} catch (e) {
|
|
67
|
+
el.contentWindow.postMessage(JSON.stringify(assign({ event: 'command' }, cmd)), '*');
|
|
68
|
+
} catch (e) {
|
|
69
|
+
// noop
|
|
70
|
+
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
const stateKey = '_ukPlayer';
|
|
74
74
|
let counter = 0;
|
|
75
75
|
function enableApi(el) {
|
|
76
|
-
|
|
77
76
|
if (el[stateKey]) {
|
|
78
77
|
return el[stateKey];
|
|
79
78
|
}
|
|
@@ -84,24 +83,29 @@ function enableApi(el) {
|
|
|
84
83
|
const id = ++counter;
|
|
85
84
|
let poller;
|
|
86
85
|
|
|
87
|
-
return el[stateKey] = new Promise(resolve => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
once(window, 'message', resolve, false, ({data}) => {
|
|
86
|
+
return (el[stateKey] = new Promise((resolve) => {
|
|
87
|
+
youtube &&
|
|
88
|
+
once(el, 'load', () => {
|
|
89
|
+
const listener = () => post(el, { event: 'listening', id });
|
|
90
|
+
poller = setInterval(listener, 100);
|
|
91
|
+
listener();
|
|
92
|
+
});
|
|
96
93
|
|
|
94
|
+
once(window, 'message', resolve, false, ({ data }) => {
|
|
97
95
|
try {
|
|
98
96
|
data = JSON.parse(data);
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
return (
|
|
98
|
+
data &&
|
|
99
|
+
((youtube && data.id === id && data.event === 'onReady') ||
|
|
100
|
+
(vimeo && Number(data.player_id) === id))
|
|
101
|
+
);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
// noop
|
|
104
|
+
}
|
|
102
105
|
});
|
|
103
106
|
|
|
104
|
-
el.src = `${el.src}${includes(el.src, '?') ? '&' : '?'}${
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
el.src = `${el.src}${includes(el.src, '?') ? '&' : '?'}${
|
|
108
|
+
youtube ? 'enablejsapi=1' : `api=1&player_id=${id}`
|
|
109
|
+
}`;
|
|
110
|
+
}).then(() => clearInterval(poller)));
|
|
107
111
|
}
|
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/promise.js
CHANGED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/* global setImmediate */
|
|
2
|
-
import {inBrowser} from './env';
|
|
3
|
-
import {isFunction, isObject} from './lang';
|
|
4
|
-
|
|
5
|
-
export const Promise = inBrowser && window.Promise || PromiseFn;
|
|
6
|
-
|
|
7
|
-
export class Deferred {
|
|
8
|
-
constructor() {
|
|
9
|
-
this.promise = new Promise((resolve, reject) => {
|
|
10
|
-
this.reject = reject;
|
|
11
|
-
this.resolve = resolve;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis)
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
const RESOLVED = 0;
|
|
21
|
-
const REJECTED = 1;
|
|
22
|
-
const PENDING = 2;
|
|
23
|
-
|
|
24
|
-
const async = inBrowser && window.setImmediate || setTimeout;
|
|
25
|
-
|
|
26
|
-
function PromiseFn(executor) {
|
|
27
|
-
|
|
28
|
-
this.state = PENDING;
|
|
29
|
-
this.value = undefined;
|
|
30
|
-
this.deferred = [];
|
|
31
|
-
|
|
32
|
-
const promise = this;
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
executor(
|
|
36
|
-
x => {
|
|
37
|
-
promise.resolve(x);
|
|
38
|
-
},
|
|
39
|
-
r => {
|
|
40
|
-
promise.reject(r);
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
} catch (e) {
|
|
44
|
-
promise.reject(e);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
PromiseFn.reject = function (r) {
|
|
49
|
-
return new PromiseFn((resolve, reject) => {
|
|
50
|
-
reject(r);
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
PromiseFn.resolve = function (x) {
|
|
55
|
-
return new PromiseFn((resolve, reject) => {
|
|
56
|
-
resolve(x);
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
PromiseFn.all = function all(iterable) {
|
|
61
|
-
return new PromiseFn((resolve, reject) => {
|
|
62
|
-
const result = [];
|
|
63
|
-
let count = 0;
|
|
64
|
-
|
|
65
|
-
if (iterable.length === 0) {
|
|
66
|
-
resolve(result);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function resolver(i) {
|
|
70
|
-
return function (x) {
|
|
71
|
-
result[i] = x;
|
|
72
|
-
count += 1;
|
|
73
|
-
|
|
74
|
-
if (count === iterable.length) {
|
|
75
|
-
resolve(result);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
for (let i = 0; i < iterable.length; i += 1) {
|
|
81
|
-
PromiseFn.resolve(iterable[i]).then(resolver(i), reject);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
PromiseFn.race = function race(iterable) {
|
|
87
|
-
return new PromiseFn((resolve, reject) => {
|
|
88
|
-
for (let i = 0; i < iterable.length; i += 1) {
|
|
89
|
-
PromiseFn.resolve(iterable[i]).then(resolve, reject);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const p = PromiseFn.prototype;
|
|
95
|
-
|
|
96
|
-
p.resolve = function resolve(x) {
|
|
97
|
-
const promise = this;
|
|
98
|
-
|
|
99
|
-
if (promise.state === PENDING) {
|
|
100
|
-
if (x === promise) {
|
|
101
|
-
throw new TypeError('Promise settled with itself.');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let called = false;
|
|
105
|
-
|
|
106
|
-
try {
|
|
107
|
-
const then = x && x.then;
|
|
108
|
-
|
|
109
|
-
if (x !== null && isObject(x) && isFunction(then)) {
|
|
110
|
-
then.call(
|
|
111
|
-
x,
|
|
112
|
-
x => {
|
|
113
|
-
if (!called) {
|
|
114
|
-
promise.resolve(x);
|
|
115
|
-
}
|
|
116
|
-
called = true;
|
|
117
|
-
},
|
|
118
|
-
r => {
|
|
119
|
-
if (!called) {
|
|
120
|
-
promise.reject(r);
|
|
121
|
-
}
|
|
122
|
-
called = true;
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
} catch (e) {
|
|
128
|
-
if (!called) {
|
|
129
|
-
promise.reject(e);
|
|
130
|
-
}
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
promise.state = RESOLVED;
|
|
135
|
-
promise.value = x;
|
|
136
|
-
promise.notify();
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
p.reject = function reject(reason) {
|
|
141
|
-
const promise = this;
|
|
142
|
-
|
|
143
|
-
if (promise.state === PENDING) {
|
|
144
|
-
if (reason === promise) {
|
|
145
|
-
throw new TypeError('Promise settled with itself.');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
promise.state = REJECTED;
|
|
149
|
-
promise.value = reason;
|
|
150
|
-
promise.notify();
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
p.notify = function notify() {
|
|
155
|
-
async(() => {
|
|
156
|
-
if (this.state !== PENDING) {
|
|
157
|
-
while (this.deferred.length) {
|
|
158
|
-
const [onResolved, onRejected, resolve, reject] = this.deferred.shift();
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
if (this.state === RESOLVED) {
|
|
162
|
-
if (isFunction(onResolved)) {
|
|
163
|
-
resolve(onResolved.call(undefined, this.value));
|
|
164
|
-
} else {
|
|
165
|
-
resolve(this.value);
|
|
166
|
-
}
|
|
167
|
-
} else if (this.state === REJECTED) {
|
|
168
|
-
if (isFunction(onRejected)) {
|
|
169
|
-
resolve(onRejected.call(undefined, this.value));
|
|
170
|
-
} else {
|
|
171
|
-
reject(this.value);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
} catch (e) {
|
|
175
|
-
reject(e);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
p.then = function then(onResolved, onRejected) {
|
|
183
|
-
return new PromiseFn((resolve, reject) => {
|
|
184
|
-
this.deferred.push([onResolved, onRejected, resolve, reject]);
|
|
185
|
-
this.notify();
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
p.catch = function (onRejected) {
|
|
190
|
-
return this.then(undefined, onRejected);
|
|
191
|
-
};
|