uikit 3.11.2-dev.f2970ffaa → 3.11.2-dev.f3ade19c4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/.eslintrc.json +4 -49
  2. package/.prettierignore +14 -0
  3. package/.prettierrc.json +13 -0
  4. package/.webstorm.js +3 -3
  5. package/CHANGELOG.md +54 -18
  6. package/build/.eslintrc.json +1 -3
  7. package/build/build.js +26 -28
  8. package/build/icons.js +7 -11
  9. package/build/less.js +48 -36
  10. package/build/package.json +2 -2
  11. package/build/prefix.js +21 -18
  12. package/build/publishDev.js +6 -8
  13. package/build/release.js +20 -17
  14. package/build/scope.js +21 -11
  15. package/build/scss.js +72 -39
  16. package/build/util.js +71 -62
  17. package/build/wrapper/icons.js +0 -2
  18. package/dist/css/uikit-core-rtl.css +133 -201
  19. package/dist/css/uikit-core-rtl.min.css +1 -1
  20. package/dist/css/uikit-core.css +133 -201
  21. package/dist/css/uikit-core.min.css +1 -1
  22. package/dist/css/uikit-rtl.css +135 -207
  23. package/dist/css/uikit-rtl.min.css +1 -1
  24. package/dist/css/uikit.css +135 -207
  25. package/dist/css/uikit.min.css +1 -1
  26. package/dist/js/components/countdown.js +88 -133
  27. package/dist/js/components/countdown.min.js +1 -1
  28. package/dist/js/components/filter.js +408 -439
  29. package/dist/js/components/filter.min.js +1 -1
  30. package/dist/js/components/lightbox-panel.js +1091 -1319
  31. package/dist/js/components/lightbox-panel.min.js +1 -1
  32. package/dist/js/components/lightbox.js +1137 -1396
  33. package/dist/js/components/lightbox.min.js +1 -1
  34. package/dist/js/components/notification.js +94 -114
  35. package/dist/js/components/notification.min.js +1 -1
  36. package/dist/js/components/parallax.js +347 -372
  37. package/dist/js/components/parallax.min.js +1 -1
  38. package/dist/js/components/slider-parallax.js +345 -360
  39. package/dist/js/components/slider-parallax.min.js +1 -1
  40. package/dist/js/components/slider.js +749 -843
  41. package/dist/js/components/slider.min.js +1 -1
  42. package/dist/js/components/slideshow-parallax.js +345 -360
  43. package/dist/js/components/slideshow-parallax.min.js +1 -1
  44. package/dist/js/components/slideshow.js +628 -798
  45. package/dist/js/components/slideshow.min.js +1 -1
  46. package/dist/js/components/sortable.js +587 -620
  47. package/dist/js/components/sortable.min.js +1 -1
  48. package/dist/js/components/tooltip.js +324 -356
  49. package/dist/js/components/tooltip.min.js +1 -1
  50. package/dist/js/components/upload.js +155 -167
  51. package/dist/js/components/upload.min.js +1 -1
  52. package/dist/js/uikit-core.js +5326 -6526
  53. package/dist/js/uikit-core.min.js +1 -1
  54. package/dist/js/uikit-icons.js +7 -9
  55. package/dist/js/uikit-icons.min.js +1 -1
  56. package/dist/js/uikit.js +8031 -9659
  57. package/dist/js/uikit.min.js +1 -1
  58. package/jsconfig.json +1 -1
  59. package/package.json +64 -60
  60. package/src/js/api/boot.js +25 -32
  61. package/src/js/api/component.js +15 -28
  62. package/src/js/api/global.js +6 -12
  63. package/src/js/api/hooks.js +14 -33
  64. package/src/js/api/instance.js +7 -15
  65. package/src/js/api/state.js +199 -187
  66. package/src/js/components/countdown.js +26 -52
  67. package/src/js/components/filter.js +70 -66
  68. package/src/js/components/index.js +13 -13
  69. package/src/js/components/internal/lightbox-animations.js +14 -25
  70. package/src/js/components/internal/slider-preload.js +9 -0
  71. package/src/js/components/internal/slider-transitioner.js +66 -45
  72. package/src/js/components/internal/slideshow-animations.js +46 -64
  73. package/src/js/components/lightbox-panel.js +107 -105
  74. package/src/js/components/lightbox.js +17 -39
  75. package/src/js/components/notification.js +49 -43
  76. package/src/js/components/parallax.js +21 -46
  77. package/src/js/components/slider-parallax.js +13 -23
  78. package/src/js/components/slider.js +117 -89
  79. package/src/js/components/slideshow-parallax.js +1 -1
  80. package/src/js/components/slideshow.js +15 -13
  81. package/src/js/components/sortable.js +125 -106
  82. package/src/js/components/tooltip.js +41 -31
  83. package/src/js/components/upload.js +52 -63
  84. package/src/js/core/accordion.js +58 -48
  85. package/src/js/core/alert.js +9 -17
  86. package/src/js/core/core.js +17 -69
  87. package/src/js/core/cover.js +15 -15
  88. package/src/js/core/drop.js +110 -94
  89. package/src/js/core/form-custom.js +22 -27
  90. package/src/js/core/gif.js +3 -7
  91. package/src/js/core/grid.js +57 -58
  92. package/src/js/core/height-match.js +16 -29
  93. package/src/js/core/height-viewport.js +30 -34
  94. package/src/js/core/icon.js +47 -52
  95. package/src/js/core/img.js +153 -143
  96. package/src/js/core/index.js +39 -39
  97. package/src/js/core/leader.js +9 -18
  98. package/src/js/core/margin.js +21 -37
  99. package/src/js/core/modal.js +49 -36
  100. package/src/js/core/nav.js +2 -4
  101. package/src/js/core/navbar.js +113 -85
  102. package/src/js/core/offcanvas.js +51 -54
  103. package/src/js/core/overflow-auto.js +13 -17
  104. package/src/js/core/responsive.js +14 -12
  105. package/src/js/core/scroll.js +10 -20
  106. package/src/js/core/scrollspy-nav.js +34 -31
  107. package/src/js/core/scrollspy.js +37 -54
  108. package/src/js/core/sticky.js +175 -123
  109. package/src/js/core/svg.js +68 -83
  110. package/src/js/core/switcher.js +56 -47
  111. package/src/js/core/tab.js +7 -10
  112. package/src/js/core/toggle.js +69 -68
  113. package/src/js/core/video.js +22 -21
  114. package/src/js/mixin/animate.js +19 -20
  115. package/src/js/mixin/class.js +2 -4
  116. package/src/js/mixin/container.js +7 -11
  117. package/src/js/mixin/internal/animate-fade.js +73 -30
  118. package/src/js/mixin/internal/animate-slide.js +58 -41
  119. package/src/js/mixin/internal/slideshow-animations.js +7 -14
  120. package/src/js/mixin/internal/slideshow-transitioner.js +10 -17
  121. package/src/js/mixin/lazyload.js +20 -0
  122. package/src/js/mixin/media.js +5 -10
  123. package/src/js/mixin/modal.js +89 -66
  124. package/src/js/mixin/parallax.js +149 -107
  125. package/src/js/mixin/position.js +26 -20
  126. package/src/js/mixin/slider-autoplay.js +12 -21
  127. package/src/js/mixin/slider-drag.js +64 -65
  128. package/src/js/mixin/slider-nav.js +26 -35
  129. package/src/js/mixin/slider-reactive.js +2 -8
  130. package/src/js/mixin/slider.js +47 -60
  131. package/src/js/mixin/slideshow.js +12 -22
  132. package/src/js/mixin/swipe.js +72 -0
  133. package/src/js/mixin/togglable.js +89 -63
  134. package/src/js/uikit-core.js +2 -4
  135. package/src/js/uikit.js +2 -4
  136. package/src/js/util/ajax.js +25 -40
  137. package/src/js/util/animation.js +77 -75
  138. package/src/js/util/attr.js +17 -21
  139. package/src/js/util/class.js +14 -52
  140. package/src/js/util/dimensions.js +78 -49
  141. package/src/js/util/dom.js +39 -66
  142. package/src/js/util/env.js +7 -12
  143. package/src/js/util/event.js +60 -59
  144. package/src/js/util/fastdom.js +1 -6
  145. package/src/js/util/filter.js +17 -34
  146. package/src/js/util/index.js +1 -1
  147. package/src/js/util/lang.js +82 -121
  148. package/src/js/util/mouse.js +19 -17
  149. package/src/js/util/observer.js +36 -0
  150. package/src/js/util/options.js +35 -49
  151. package/src/js/util/player.js +41 -36
  152. package/src/js/util/position.js +54 -46
  153. package/src/js/util/selector.js +43 -58
  154. package/src/js/util/style.js +39 -49
  155. package/src/js/util/viewport.js +75 -64
  156. package/src/less/components/base.less +10 -33
  157. package/src/less/components/flex.less +0 -9
  158. package/src/less/components/form-range.less +48 -95
  159. package/src/less/components/form.less +0 -1
  160. package/src/less/components/height.less +3 -0
  161. package/src/less/components/leader.less +0 -1
  162. package/src/less/components/lightbox.less +0 -1
  163. package/src/less/components/modal.less +3 -7
  164. package/src/less/components/navbar.less +0 -7
  165. package/src/less/components/progress.less +14 -36
  166. package/src/less/components/slider.less +0 -3
  167. package/src/less/components/slideshow.less +0 -3
  168. package/src/less/components/text.less +16 -32
  169. package/src/less/components/utility.less +25 -0
  170. package/src/scss/components/base.scss +10 -33
  171. package/src/scss/components/flex.scss +0 -9
  172. package/src/scss/components/form-range.scss +48 -95
  173. package/src/scss/components/form.scss +3 -4
  174. package/src/scss/components/height.scss +3 -0
  175. package/src/scss/components/icon.scss +2 -2
  176. package/src/scss/components/leader.scss +0 -1
  177. package/src/scss/components/lightbox.scss +0 -1
  178. package/src/scss/components/modal.scss +3 -7
  179. package/src/scss/components/navbar.scss +0 -7
  180. package/src/scss/components/progress.scss +14 -36
  181. package/src/scss/components/search.scss +1 -1
  182. package/src/scss/components/slider.scss +0 -3
  183. package/src/scss/components/slideshow.scss +0 -3
  184. package/src/scss/components/text.scss +16 -32
  185. package/src/scss/components/utility.scss +25 -0
  186. package/src/scss/mixins-theme.scss +1 -1
  187. package/src/scss/mixins.scss +1 -1
  188. package/src/scss/variables-theme.scss +9 -9
  189. package/src/scss/variables.scss +9 -9
  190. package/tests/align.html +10 -10
  191. package/tests/animation.html +2 -2
  192. package/tests/article.html +2 -2
  193. package/tests/base.html +3 -3
  194. package/tests/card.html +10 -10
  195. package/tests/column.html +3 -3
  196. package/tests/comment.html +9 -9
  197. package/tests/dotnav.html +3 -3
  198. package/tests/image.html +296 -64
  199. package/tests/images/image-type.avif +0 -0
  200. package/tests/images/image-type.jpeg +0 -0
  201. package/tests/images/image-type.webp +0 -0
  202. package/tests/index.html +8 -8
  203. package/tests/js/index.js +114 -85
  204. package/tests/lightbox.html +10 -10
  205. package/tests/marker.html +2 -2
  206. package/tests/modal.html +8 -9
  207. package/tests/navbar.html +2 -2
  208. package/tests/overlay.html +7 -7
  209. package/tests/parallax.html +16 -7
  210. package/tests/position.html +12 -12
  211. package/tests/slidenav.html +12 -12
  212. package/tests/slider.html +20 -20
  213. package/tests/sortable.html +1 -1
  214. package/tests/sticky-parallax.html +87 -99
  215. package/tests/sticky.html +56 -24
  216. package/tests/svg.html +6 -6
  217. package/tests/table.html +11 -11
  218. package/tests/thumbnav.html +12 -12
  219. package/tests/transition.html +30 -30
  220. package/tests/utility.html +50 -33
  221. package/tests/video.html +1 -1
  222. package/tests/width.html +1 -1
  223. package/src/js/mixin/flex-bug.js +0 -56
  224. package/src/js/util/promise.js +0 -191
  225. package/tests/images/animated.gif +0 -0
@@ -1,20 +1,17 @@
1
- import {getEventPos, on} from './event';
2
- import {last, pointInRect} from './lang';
1
+ import { getEventPos, on } from './event';
2
+ import { last, pointInRect } from './lang';
3
3
 
4
4
  export function MouseTracker() {}
5
5
 
6
6
  MouseTracker.prototype = {
7
-
8
7
  positions: [],
9
8
 
10
9
  init() {
11
-
12
10
  this.positions = [];
13
11
 
14
12
  let position;
15
- this.unbind = on(document, 'mousemove', e => position = getEventPos(e));
13
+ this.unbind = on(document, 'mousemove', (e) => (position = getEventPos(e)));
16
14
  this.interval = setInterval(() => {
17
-
18
15
  if (!position) {
19
16
  return;
20
17
  }
@@ -25,7 +22,6 @@ MouseTracker.prototype = {
25
22
  this.positions.shift();
26
23
  }
27
24
  }, 50);
28
-
29
25
  },
30
26
 
31
27
  cancel() {
@@ -34,13 +30,12 @@ MouseTracker.prototype = {
34
30
  },
35
31
 
36
32
  movesTo(target) {
37
-
38
33
  if (this.positions.length < 2) {
39
34
  return false;
40
35
  }
41
36
 
42
37
  const p = target.getBoundingClientRect();
43
- const {left, right, top, bottom} = p;
38
+ const { left, right, top, bottom } = p;
44
39
 
45
40
  const [prevPosition] = this.positions;
46
41
  const position = last(this.positions);
@@ -50,19 +45,26 @@ MouseTracker.prototype = {
50
45
  return false;
51
46
  }
52
47
 
53
- const diagonals = [[{x: left, y: top}, {x: right, y: bottom}], [{x: left, y: bottom}, {x: right, y: top}]];
54
-
55
- return diagonals.some(diagonal => {
48
+ const diagonals = [
49
+ [
50
+ { x: left, y: top },
51
+ { x: right, y: bottom },
52
+ ],
53
+ [
54
+ { x: left, y: bottom },
55
+ { x: right, y: top },
56
+ ],
57
+ ];
58
+
59
+ return diagonals.some((diagonal) => {
56
60
  const intersection = intersect(path, diagonal);
57
61
  return intersection && pointInRect(intersection, p);
58
62
  });
59
- }
60
-
63
+ },
61
64
  };
62
65
 
63
66
  // Inspired by http://paulbourke.net/geometry/pointlineplane/
64
- function intersect([{x: x1, y: y1}, {x: x2, y: y2}], [{x: x3, y: y3}, {x: x4, y: y4}]) {
65
-
67
+ function intersect([{ x: x1, y: y1 }, { x: x2, y: y2 }], [{ x: x3, y: y3 }, { x: x4, y: y4 }]) {
66
68
  const denominator = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
67
69
 
68
70
  // Lines are parallel
@@ -77,5 +79,5 @@ function intersect([{x: x1, y: y1}, {x: x2, y: y2}], [{x: x3, y: y3}, {x: x4, y:
77
79
  }
78
80
 
79
81
  // Return an object with the x and y coordinates of the intersection
80
- return {x: x1 + ua * (x2 - x1), y: y1 + ua * (y2 - y1)};
82
+ return { x: x1 + ua * (x2 - x1), y: y1 + ua * (y2 - y1) };
81
83
  }
@@ -0,0 +1,36 @@
1
+ import { toNodes } from './lang';
2
+
3
+ // Old chromium based browsers (UC Browser) did not implement `isIntersecting`
4
+ export const hasIntersectionObserver =
5
+ window.IntersectionObserver && 'isIntersecting' in IntersectionObserverEntry.prototype;
6
+ export function observeIntersection(targets, cb, options, intersecting = true) {
7
+ if (!hasIntersectionObserver) {
8
+ return;
9
+ }
10
+
11
+ const observer = new IntersectionObserver((entries, observer) => {
12
+ if (!intersecting || entries.some((entry) => entry.isIntersecting)) {
13
+ cb(entries, observer);
14
+ }
15
+ }, options);
16
+ for (const el of toNodes(targets)) {
17
+ observer.observe(el);
18
+ }
19
+ return observer;
20
+ }
21
+
22
+ const hasResizeObserver = window.ResizeObserver;
23
+ export function observeResize(targets, cb, options = { box: 'border-box' }) {
24
+ if (!hasResizeObserver) {
25
+ return;
26
+ }
27
+
28
+ const observer = new ResizeObserver((entries, observer) => {
29
+ cb(entries, observer);
30
+ });
31
+ for (const el of toNodes(targets)) {
32
+ observer.observe(el, options);
33
+ }
34
+
35
+ return observer;
36
+ }
@@ -1,14 +1,15 @@
1
- import {assign, hasOwn, includes, isArray, isFunction, isUndefined, sortBy, startsWith} from './lang';
1
+ import { hasOwn, includes, isArray, isFunction, isUndefined, sortBy, startsWith } from './lang';
2
2
 
3
3
  const strats = {};
4
4
 
5
5
  strats.events =
6
- strats.created =
7
- strats.beforeConnect =
8
- strats.connected =
9
- strats.beforeDisconnect =
10
- strats.disconnected =
11
- strats.destroy = concatStrat;
6
+ strats.created =
7
+ strats.beforeConnect =
8
+ strats.connected =
9
+ strats.beforeDisconnect =
10
+ strats.disconnected =
11
+ strats.destroy =
12
+ concatStrat;
12
13
 
13
14
  // args strategy
14
15
  strats.args = function (parentVal, childVal) {
@@ -17,37 +18,33 @@ strats.args = function (parentVal, childVal) {
17
18
 
18
19
  // update strategy
19
20
  strats.update = function (parentVal, childVal) {
20
- return sortBy(concatStrat(parentVal, isFunction(childVal) ? {read: childVal} : childVal), 'order');
21
+ return sortBy(
22
+ concatStrat(parentVal, isFunction(childVal) ? { read: childVal } : childVal),
23
+ 'order'
24
+ );
21
25
  };
22
26
 
23
27
  // property strategy
24
28
  strats.props = function (parentVal, childVal) {
25
-
26
29
  if (isArray(childVal)) {
27
- childVal = childVal.reduce((value, key) => {
30
+ const value = {};
31
+ for (const key of childVal) {
28
32
  value[key] = String;
29
- return value;
30
- }, {});
33
+ }
34
+ childVal = value;
31
35
  }
32
36
 
33
37
  return strats.methods(parentVal, childVal);
34
38
  };
35
39
 
36
40
  // extend strategy
37
- strats.computed =
38
- strats.methods = function (parentVal, childVal) {
39
- return childVal
40
- ? parentVal
41
- ? assign({}, parentVal, childVal)
42
- : childVal
43
- : parentVal;
41
+ strats.computed = strats.methods = function (parentVal, childVal) {
42
+ return childVal ? (parentVal ? { ...parentVal, ...childVal } : childVal) : parentVal;
44
43
  };
45
44
 
46
45
  // data strategy
47
46
  strats.data = function (parentVal, childVal, vm) {
48
-
49
47
  if (!vm) {
50
-
51
48
  if (!childVal) {
52
49
  return parentVal;
53
50
  }
@@ -59,7 +56,6 @@ strats.data = function (parentVal, childVal, vm) {
59
56
  return function (vm) {
60
57
  return mergeFnData(parentVal, childVal, vm);
61
58
  };
62
-
63
59
  }
64
60
 
65
61
  return mergeFnData(parentVal, childVal, vm);
@@ -67,26 +63,21 @@ strats.data = function (parentVal, childVal, vm) {
67
63
 
68
64
  function mergeFnData(parentVal, childVal, vm) {
69
65
  return strats.computed(
70
- isFunction(parentVal)
71
- ? parentVal.call(vm, vm)
72
- : parentVal,
73
- isFunction(childVal)
74
- ? childVal.call(vm, vm)
75
- : childVal
66
+ isFunction(parentVal) ? parentVal.call(vm, vm) : parentVal,
67
+ isFunction(childVal) ? childVal.call(vm, vm) : childVal
76
68
  );
77
69
  }
78
70
 
79
71
  // concat strategy
80
72
  function concatStrat(parentVal, childVal) {
81
-
82
73
  parentVal = parentVal && !isArray(parentVal) ? [parentVal] : parentVal;
83
74
 
84
75
  return childVal
85
76
  ? parentVal
86
77
  ? parentVal.concat(childVal)
87
78
  : isArray(childVal)
88
- ? childVal
89
- : [childVal]
79
+ ? childVal
80
+ : [childVal]
90
81
  : parentVal;
91
82
  }
92
83
 
@@ -96,7 +87,6 @@ function defaultStrat(parentVal, childVal) {
96
87
  }
97
88
 
98
89
  export function mergeOptions(parent, child, vm) {
99
-
100
90
  const options = {};
101
91
 
102
92
  if (isFunction(child)) {
@@ -108,8 +98,8 @@ export function mergeOptions(parent, child, vm) {
108
98
  }
109
99
 
110
100
  if (child.mixins) {
111
- for (let i = 0, l = child.mixins.length; i < l; i++) {
112
- parent = mergeOptions(parent, child.mixins[i], vm);
101
+ for (const mixin of child.mixins) {
102
+ parent = mergeOptions(parent, mixin, vm);
113
103
  }
114
104
  }
115
105
 
@@ -131,25 +121,21 @@ export function mergeOptions(parent, child, vm) {
131
121
  }
132
122
 
133
123
  export function parseOptions(options, args = []) {
134
-
135
124
  try {
136
-
137
- return !options
138
- ? {}
139
- : startsWith(options, '{')
125
+ return options
126
+ ? startsWith(options, '{')
140
127
  ? JSON.parse(options)
141
128
  : args.length && !includes(options, ':')
142
- ? ({[args[0]]: options})
143
- : options.split(';').reduce((options, option) => {
144
- const [key, value] = option.split(/:(.*)/);
145
- if (key && !isUndefined(value)) {
146
- options[key.trim()] = value.trim();
147
- }
148
- return options;
149
- }, {});
150
-
129
+ ? { [args[0]]: options }
130
+ : options.split(';').reduce((options, option) => {
131
+ const [key, value] = option.split(/:(.*)/);
132
+ if (key && !isUndefined(value)) {
133
+ options[key.trim()] = value.trim();
134
+ }
135
+ return options;
136
+ }, {})
137
+ : {};
151
138
  } catch (e) {
152
139
  return {};
153
140
  }
154
-
155
141
  }
@@ -1,43 +1,39 @@
1
- import {once} from './event';
2
- import {Promise} from './promise';
3
- import {assign, includes, noop} from './lang';
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 && el.tagName === 'VIDEO';
44
+ return isTag(el, 'video');
49
45
  }
50
46
 
51
47
  function isIFrame(el) {
52
- return el && el.tagName === 'IFRAME' && (isYoutube(el) || isVimeo(el));
48
+ return isTag(el, 'iframe') && (isYoutube(el) || isVimeo(el));
53
49
  }
54
50
 
55
51
  function isYoutube(el) {
56
- return !!el.src.match(/\/\/.*?youtube(-nocookie)?\.[a-z]+\/(watch\?v=[^&\s]+|embed)|youtu\.be\/.*/);
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).then(() => post(el, cmd));
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(assign({event: 'command'}, cmd)), '*');
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
- youtube && once(el, 'load', () => {
90
- const listener = () => post(el, {event: 'listening', id});
91
- poller = setInterval(listener, 100);
92
- listener();
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 data && (youtube && data.id === id && data.event === 'onReady' || vimeo && Number(data.player_id) === id);
100
- } catch (e) {}
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, '?') ? '&' : '?'}${youtube ? 'enablejsapi=1' : `api=1&player_id=${id}`}`;
105
-
106
- }).then(() => clearInterval(poller));
108
+ el.src = `${el.src}${includes(el.src, '?') ? '&' : '?'}${
109
+ youtube ? 'enablejsapi=1' : `api=1&player_id=${id}`
110
+ }`;
111
+ }).then(() => clearInterval(poller)));
107
112
  }
@@ -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(element, target, elAttach, targetAttach, elOffset, targetOffset, flip, boundary) {
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
- const elemOffset = elAttach[dir] === align
56
- ? -dim[prop]
57
- : elAttach[dir] === alignFlip
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 = targetAttach[dir] === align
62
- ? targetDim[prop]
63
- : targetAttach[dir] === alignFlip
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 (position[align] < boundary[align] || position[align] + dim[prop] > boundary[alignFlip]) {
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 = targetAttach[dir] === 'center' ? -targetDim[prop] / 2 : 0;
71
-
72
- return elAttach[dir] === 'center' && (
73
- apply(centerOffset, centerTargetOffset)
74
- || apply(-centerOffset, -centerTargetOffset)
75
- ) || apply(elemOffset, targetOffset);
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
- const newVal = toFloat((position[align] + elemOffset + targetOffset - elOffset[dir] * 2).toFixed(4));
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'].forEach(el => {
87
- flipped[el][dir] = !elemOffset
88
- ? flipped[el][dir]
89
- : flipped[el][dir] === dirs[prop][1]
90
- ? dirs[prop][2]
91
- : dirs[prop][1];
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
- ? ['center'].concat(pos)
131
- : ['center', 'center'];
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
  }