uikit 3.11.2-dev.9433cd5fd → 3.11.2-dev.946d2efea

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 (226) 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 +46 -29
  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 -361
  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 +156 -167
  51. package/dist/js/components/upload.min.js +1 -1
  52. package/dist/js/uikit-core.js +5323 -6536
  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 +8181 -9810
  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 +16 -30
  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 +53 -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 +109 -93
  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 +96 -83
  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 +112 -88
  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 +161 -128
  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 +58 -45
  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 +32 -46
  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 -48
  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 +56 -71
  215. package/tests/svg.html +6 -6
  216. package/tests/table.html +11 -11
  217. package/tests/thumbnav.html +12 -12
  218. package/tests/transition.html +30 -30
  219. package/tests/utility.html +50 -33
  220. package/tests/video.html +1 -1
  221. package/tests/width.html +1 -1
  222. package/src/js/mixin/flex-bug.js +0 -56
  223. package/src/js/util/promise.js +0 -191
  224. package/tests/images/animated.gif +0 -0
  225. package/tests/images/test.avif +0 -0
  226. package/tests/images/test.webp +0 -0
@@ -1,11 +1,28 @@
1
- import {assign, camelize, data as getData, hasOwn, hyphenate, isArray, isEmpty, isFunction, isNumeric, isPlainObject, isString, isUndefined, mergeOptions, on, parseOptions, startsWith, toBoolean, toNumber} from 'uikit-util';
1
+ import {
2
+ assign,
3
+ camelize,
4
+ data as getData,
5
+ hasOwn,
6
+ hyphenate,
7
+ includes,
8
+ isArray,
9
+ isFunction,
10
+ isNumeric,
11
+ isPlainObject,
12
+ isString,
13
+ isUndefined,
14
+ mergeOptions,
15
+ on,
16
+ parseOptions,
17
+ startsWith,
18
+ toBoolean,
19
+ toNumber,
20
+ } from 'uikit-util';
2
21
 
3
22
  export default function (UIkit) {
4
-
5
23
  let uid = 0;
6
24
 
7
25
  UIkit.prototype._init = function (options) {
8
-
9
26
  options = options || {};
10
27
  options.data = normalizeData(options, this.constructor.options);
11
28
 
@@ -25,8 +42,7 @@ export default function (UIkit) {
25
42
  };
26
43
 
27
44
  UIkit.prototype._initData = function () {
28
-
29
- const {data = {}} = this.$options;
45
+ const { data = {} } = this.$options;
30
46
 
31
47
  for (const key in data) {
32
48
  this.$props[key] = this[key] = data[key];
@@ -34,8 +50,7 @@ export default function (UIkit) {
34
50
  };
35
51
 
36
52
  UIkit.prototype._initMethods = function () {
37
-
38
- const {methods} = this.$options;
53
+ const { methods } = this.$options;
39
54
 
40
55
  if (methods) {
41
56
  for (const key in methods) {
@@ -45,8 +60,7 @@ export default function (UIkit) {
45
60
  };
46
61
 
47
62
  UIkit.prototype._initComputeds = function () {
48
-
49
- const {computed} = this.$options;
63
+ const { computed } = this.$options;
50
64
 
51
65
  this._computeds = {};
52
66
 
@@ -58,7 +72,6 @@ export default function (UIkit) {
58
72
  };
59
73
 
60
74
  UIkit.prototype._initProps = function (props) {
61
-
62
75
  let key;
63
76
 
64
77
  props = props || getProps(this.$options, this.$name);
@@ -78,246 +91,245 @@ export default function (UIkit) {
78
91
  };
79
92
 
80
93
  UIkit.prototype._initEvents = function () {
81
-
82
94
  this._events = [];
83
-
84
- const {events} = this.$options;
85
-
86
- if (events) {
87
-
88
- events.forEach(event => {
89
-
90
- if (hasOwn(event, 'handler')) {
91
- registerEvent(this, event);
92
- } else {
93
- for (const key in event) {
94
- registerEvent(this, event[key], key);
95
- }
95
+ for (const event of this.$options.events || []) {
96
+ if (hasOwn(event, 'handler')) {
97
+ registerEvent(this, event);
98
+ } else {
99
+ for (const key in event) {
100
+ registerEvent(this, event[key], key);
96
101
  }
97
-
98
- });
102
+ }
103
+ }
104
+ for (const { events = [] } of this.$options.update || []) {
105
+ if (includes(events, 'scroll')) {
106
+ registerScrollListener(this._uid, () => this.$emit('scroll'));
107
+ break;
108
+ }
99
109
  }
100
110
  };
101
111
 
102
112
  UIkit.prototype._unbindEvents = function () {
103
- this._events.forEach(unbind => unbind());
113
+ this._events.forEach((unbind) => unbind());
104
114
  delete this._events;
115
+ unregisterScrollListener(this._uid);
105
116
  };
106
117
 
107
118
  UIkit.prototype._initObservers = function () {
108
- this._observers = [
109
- initChildListObserver(this),
110
- initPropsObserver(this)
111
- ];
119
+ this._observers = [initChildListObserver(this), initPropsObserver(this)];
112
120
  };
113
121
 
114
- UIkit.prototype._disconnectObservers = function () {
115
- this._observers.forEach(observer =>
116
- observer && observer.disconnect()
117
- );
122
+ UIkit.prototype.registerObserver = function (observer) {
123
+ this._observers.push(observer);
118
124
  };
119
125
 
120
- function getProps(opts, name) {
121
-
122
- const data = {};
123
- const {args = [], props = {}, el} = opts;
124
-
125
- if (!props) {
126
- return data;
127
- }
128
-
129
- for (const key in props) {
130
- const prop = hyphenate(key);
131
- let value = getData(el, prop);
126
+ UIkit.prototype._disconnectObservers = function () {
127
+ this._observers.forEach((observer) => observer?.disconnect());
128
+ };
129
+ }
132
130
 
133
- if (isUndefined(value)) {
134
- continue;
135
- }
131
+ function getProps(opts, name) {
132
+ const data = {};
133
+ const { args = [], props = {}, el } = opts;
136
134
 
137
- value = props[key] === Boolean && value === ''
138
- ? true
139
- : coerce(props[key], value);
135
+ if (!props) {
136
+ return data;
137
+ }
140
138
 
141
- if (prop === 'target' && (!value || startsWith(value, '_'))) {
142
- continue;
143
- }
139
+ for (const key in props) {
140
+ const prop = hyphenate(key);
141
+ let value = getData(el, prop);
144
142
 
145
- data[key] = value;
143
+ if (isUndefined(value)) {
144
+ continue;
146
145
  }
147
146
 
148
- const options = parseOptions(getData(el, name), args);
147
+ value = props[key] === Boolean && value === '' ? true : coerce(props[key], value);
149
148
 
150
- for (const key in options) {
151
- const prop = camelize(key);
152
- if (props[prop] !== undefined) {
153
- data[prop] = coerce(props[prop], options[key]);
154
- }
149
+ if (prop === 'target' && (!value || startsWith(value, '_'))) {
150
+ continue;
155
151
  }
156
152
 
157
- return data;
153
+ data[key] = value;
158
154
  }
159
155
 
160
- function registerComputed(component, key, cb) {
161
- Object.defineProperty(component, key, {
156
+ const options = parseOptions(getData(el, name), args);
162
157
 
163
- enumerable: true,
158
+ for (const key in options) {
159
+ const prop = camelize(key);
160
+ if (props[prop] !== undefined) {
161
+ data[prop] = coerce(props[prop], options[key]);
162
+ }
163
+ }
164
164
 
165
- get() {
165
+ return data;
166
+ }
166
167
 
167
- const {_computeds, $props, $el} = component;
168
+ function registerComputed(component, key, cb) {
169
+ Object.defineProperty(component, key, {
170
+ enumerable: true,
168
171
 
169
- if (!hasOwn(_computeds, key)) {
170
- _computeds[key] = (cb.get || cb).call(component, $props, $el);
171
- }
172
+ get() {
173
+ const { _computeds, $props, $el } = component;
172
174
 
173
- return _computeds[key];
174
- },
175
+ if (!hasOwn(_computeds, key)) {
176
+ _computeds[key] = (cb.get || cb).call(component, $props, $el);
177
+ }
175
178
 
176
- set(value) {
179
+ return _computeds[key];
180
+ },
177
181
 
178
- const {_computeds} = component;
182
+ set(value) {
183
+ const { _computeds } = component;
179
184
 
180
- _computeds[key] = cb.set ? cb.set.call(component, value) : value;
185
+ _computeds[key] = cb.set ? cb.set.call(component, value) : value;
181
186
 
182
- if (isUndefined(_computeds[key])) {
183
- delete _computeds[key];
184
- }
187
+ if (isUndefined(_computeds[key])) {
188
+ delete _computeds[key];
185
189
  }
190
+ },
191
+ });
192
+ }
186
193
 
187
- });
194
+ export function registerEvent(component, event, key) {
195
+ if (!isPlainObject(event)) {
196
+ event = { name: key, handler: event };
188
197
  }
189
198
 
190
- function registerEvent(component, event, key) {
191
-
192
- if (!isPlainObject(event)) {
193
- event = ({name: key, handler: event});
194
- }
195
-
196
- let {name, el, handler, capture, passive, delegate, filter, self} = event;
197
- el = isFunction(el)
198
- ? el.call(component)
199
- : el || component.$el;
199
+ let { name, el, handler, capture, passive, delegate, filter, self } = event;
200
+ el = isFunction(el) ? el.call(component) : el || component.$el;
200
201
 
201
- if (isArray(el)) {
202
- el.forEach(el => registerEvent(component, assign({}, event, {el}), key));
203
- return;
204
- }
202
+ if (isArray(el)) {
203
+ el.forEach((el) => registerEvent(component, { ...event, el }, key));
204
+ return;
205
+ }
205
206
 
206
- if (!el || filter && !filter.call(component)) {
207
- return;
208
- }
207
+ if (!el || (filter && !filter.call(component))) {
208
+ return;
209
+ }
209
210
 
210
- component._events.push(
211
- on(
212
- el,
213
- name,
214
- delegate
215
- ? isString(delegate)
216
- ? delegate
217
- : delegate.call(component)
218
- : null,
219
- isString(handler) ? component[handler] : handler.bind(component),
220
- {passive, capture, self}
221
- )
222
- );
211
+ component._events.push(
212
+ on(
213
+ el,
214
+ name,
215
+ delegate ? (isString(delegate) ? delegate : delegate.call(component)) : null,
216
+ isString(handler) ? component[handler] : handler.bind(component),
217
+ { passive, capture, self }
218
+ )
219
+ );
220
+ }
223
221
 
224
- }
222
+ function notIn(options, key) {
223
+ return options.every((arr) => !arr || !hasOwn(arr, key));
224
+ }
225
225
 
226
- function notIn(options, key) {
227
- return options.every(arr => !arr || !hasOwn(arr, key));
226
+ function coerce(type, value) {
227
+ if (type === Boolean) {
228
+ return toBoolean(value);
229
+ } else if (type === Number) {
230
+ return toNumber(value);
231
+ } else if (type === 'list') {
232
+ return toList(value);
228
233
  }
229
234
 
230
- function coerce(type, value) {
235
+ return type ? type(value) : value;
236
+ }
231
237
 
232
- if (type === Boolean) {
233
- return toBoolean(value);
234
- } else if (type === Number) {
235
- return toNumber(value);
236
- } else if (type === 'list') {
237
- return toList(value);
238
- }
238
+ function toList(value) {
239
+ return isArray(value)
240
+ ? value
241
+ : isString(value)
242
+ ? value
243
+ .split(/,(?![^(]*\))/)
244
+ .map((value) => (isNumeric(value) ? toNumber(value) : toBoolean(value.trim())))
245
+ : [value];
246
+ }
239
247
 
240
- return type ? type(value) : value;
248
+ function normalizeData({ data = {} }, { args = [], props = {} }) {
249
+ if (isArray(data)) {
250
+ data = data.slice(0, args.length).reduce((data, value, index) => {
251
+ if (isPlainObject(value)) {
252
+ assign(data, value);
253
+ } else {
254
+ data[args[index]] = value;
255
+ }
256
+ return data;
257
+ }, {});
241
258
  }
242
259
 
243
- function toList(value) {
244
- return isArray(value)
245
- ? value
246
- : isString(value)
247
- ? value.split(/,(?![^(]*\))/).map(value => isNumeric(value)
248
- ? toNumber(value)
249
- : toBoolean(value.trim()))
250
- : [value];
260
+ for (const key in data) {
261
+ if (isUndefined(data[key])) {
262
+ delete data[key];
263
+ } else if (props[key]) {
264
+ data[key] = coerce(props[key], data[key]);
265
+ }
251
266
  }
252
267
 
253
- function normalizeData({data}, {args, props = {}}) {
254
- data = isArray(data)
255
- ? !isEmpty(args)
256
- ? data.slice(0, args.length).reduce((data, value, index) => {
257
- if (isPlainObject(value)) {
258
- assign(data, value);
259
- } else {
260
- data[args[index]] = value;
261
- }
262
- return data;
263
- }, {})
264
- : undefined
265
- : data;
266
-
267
- if (data) {
268
- for (const key in data) {
269
- if (isUndefined(data[key])) {
270
- delete data[key];
271
- } else {
272
- data[key] = props[key] ? coerce(props[key], data[key]) : data[key];
273
- }
274
- }
275
- }
268
+ return data;
269
+ }
276
270
 
277
- return data;
278
- }
271
+ function initChildListObserver(component) {
272
+ const { el } = component.$options;
279
273
 
280
- function initChildListObserver(component) {
281
- const {el} = component.$options;
274
+ const observer = new MutationObserver(() => component.$emit());
275
+ observer.observe(el, {
276
+ childList: true,
277
+ subtree: true,
278
+ });
282
279
 
283
- const observer = new MutationObserver(() => component.$emit());
284
- observer.observe(el, {
285
- childList: true,
286
- subtree: true
287
- });
280
+ return observer;
281
+ }
288
282
 
289
- return observer;
290
- }
283
+ function initPropsObserver(component) {
284
+ const { $name, $options, $props } = component;
285
+ const { attrs, props, el } = $options;
291
286
 
292
- function initPropsObserver(component) {
287
+ if (!props || attrs === false) {
288
+ return;
289
+ }
293
290
 
294
- const {$name, $options, $props} = component;
295
- const {attrs, props, el} = $options;
291
+ const attributes = isArray(attrs) ? attrs : Object.keys(props);
292
+ const filter = attributes.map((key) => hyphenate(key)).concat($name);
296
293
 
297
- if (!props || attrs === false) {
298
- return;
294
+ const observer = new MutationObserver((records) => {
295
+ const data = getProps($options, $name);
296
+ if (
297
+ records.some(({ attributeName }) => {
298
+ const prop = attributeName.replace('data-', '');
299
+ return (
300
+ prop === $name ? attributes : [camelize(prop), camelize(attributeName)]
301
+ ).some((prop) => !isUndefined(data[prop]) && data[prop] !== $props[prop]);
302
+ })
303
+ ) {
304
+ component.$reset();
299
305
  }
306
+ });
300
307
 
301
- const attributes = isArray(attrs) ? attrs : Object.keys(props);
302
- const filter = attributes.map(key => hyphenate(key)).concat($name);
308
+ observer.observe(el, {
309
+ attributes: true,
310
+ attributeFilter: filter.concat(filter.map((key) => `data-${key}`)),
311
+ });
303
312
 
304
- const observer = new MutationObserver(records => {
305
- const data = getProps($options, $name);
306
- if (records.some(({attributeName}) => {
307
- const prop = attributeName.replace('data-', '');
308
- return (prop === $name ? attributes : [camelize(prop), camelize(attributeName)]).some(prop =>
309
- !isUndefined(data[prop]) && data[prop] !== $props[prop]
310
- );
311
- })) {
312
- component.$reset();
313
- }
314
- });
313
+ return observer;
314
+ }
315
315
 
316
- observer.observe(el, {
317
- attributes: true,
318
- attributeFilter: filter.concat(filter.map(key => `data-${key}`))
316
+ const scrollListeners = new Map();
317
+ let unbindScrollListener;
318
+ function registerScrollListener(id, listener) {
319
+ unbindScrollListener =
320
+ unbindScrollListener ||
321
+ on(window, 'scroll', () => scrollListeners.forEach((listener) => listener()), {
322
+ passive: true,
323
+ capture: true,
319
324
  });
320
325
 
321
- return observer;
326
+ scrollListeners.set(id, listener);
327
+ }
328
+
329
+ function unregisterScrollListener(id) {
330
+ scrollListeners.delete(id);
331
+ if (unbindScrollListener && !scrollListeners.size) {
332
+ unbindScrollListener();
333
+ unbindScrollListener = null;
322
334
  }
323
335
  }
@@ -1,46 +1,43 @@
1
1
  import Class from '../mixin/class';
2
- import {$, empty, html} from 'uikit-util';
2
+ import { $, empty, html } from 'uikit-util';
3
3
 
4
4
  export default {
5
-
6
5
  mixins: [Class],
7
6
 
8
7
  props: {
9
8
  date: String,
10
- clsWrapper: String
9
+ clsWrapper: String,
11
10
  },
12
11
 
13
12
  data: {
14
13
  date: '',
15
- clsWrapper: '.uk-countdown-%unit%'
14
+ clsWrapper: '.uk-countdown-%unit%',
16
15
  },
17
16
 
18
17
  computed: {
19
-
20
- date({date}) {
18
+ date({ date }) {
21
19
  return Date.parse(date);
22
20
  },
23
21
 
24
- days({clsWrapper}, $el) {
22
+ days({ clsWrapper }, $el) {
25
23
  return $(clsWrapper.replace('%unit%', 'days'), $el);
26
24
  },
27
25
 
28
- hours({clsWrapper}, $el) {
26
+ hours({ clsWrapper }, $el) {
29
27
  return $(clsWrapper.replace('%unit%', 'hours'), $el);
30
28
  },
31
29
 
32
- minutes({clsWrapper}, $el) {
30
+ minutes({ clsWrapper }, $el) {
33
31
  return $(clsWrapper.replace('%unit%', 'minutes'), $el);
34
32
  },
35
33
 
36
- seconds({clsWrapper}, $el) {
34
+ seconds({ clsWrapper }, $el) {
37
35
  return $(clsWrapper.replace('%unit%', 'seconds'), $el);
38
36
  },
39
37
 
40
38
  units() {
41
- return ['days', 'hours', 'minutes', 'seconds'].filter(unit => this[unit]);
42
- }
43
-
39
+ return ['days', 'hours', 'minutes', 'seconds'].filter((unit) => this[unit]);
40
+ },
44
41
  },
45
42
 
46
43
  connected() {
@@ -49,13 +46,11 @@ export default {
49
46
 
50
47
  disconnected() {
51
48
  this.stop();
52
- this.units.forEach(unit => empty(this[unit]));
49
+ this.units.forEach((unit) => empty(this[unit]));
53
50
  },
54
51
 
55
52
  events: [
56
-
57
53
  {
58
-
59
54
  name: 'visibilitychange',
60
55
 
61
56
  el() {
@@ -68,31 +63,21 @@ export default {
68
63
  } else {
69
64
  this.start();
70
65
  }
71
- }
72
-
73
- }
74
-
66
+ },
67
+ },
75
68
  ],
76
69
 
77
70
  update: {
78
-
79
71
  write() {
80
-
81
72
  const timespan = getTimeSpan(this.date);
82
73
 
83
74
  if (timespan.total <= 0) {
84
-
85
75
  this.stop();
86
76
 
87
- timespan.days
88
- = timespan.hours
89
- = timespan.minutes
90
- = timespan.seconds
91
- = 0;
77
+ timespan.days = timespan.hours = timespan.minutes = timespan.seconds = 0;
92
78
  }
93
79
 
94
- this.units.forEach(unit => {
95
-
80
+ for (const unit of this.units) {
96
81
  let digits = String(Math.floor(timespan[unit]));
97
82
 
98
83
  digits = digits.length < 2 ? `0${digits}` : digits;
@@ -105,50 +90,39 @@ export default {
105
90
  html(el, digits.map(() => '<span></span>').join(''));
106
91
  }
107
92
 
108
- digits.forEach((digit, i) => el.children[i].textContent = digit);
93
+ digits.forEach((digit, i) => (el.children[i].textContent = digit));
109
94
  }
110
-
111
- });
112
-
113
- }
114
-
95
+ }
96
+ },
115
97
  },
116
98
 
117
99
  methods: {
118
-
119
100
  start() {
120
-
121
101
  this.stop();
122
102
 
123
103
  if (this.date && this.units.length) {
124
- this.$update();
125
- this.timer = setInterval(this.$update, 1000);
104
+ this.$emit();
105
+ this.timer = setInterval(() => this.$emit(), 1000);
126
106
  }
127
-
128
107
  },
129
108
 
130
109
  stop() {
131
-
132
110
  if (this.timer) {
133
111
  clearInterval(this.timer);
134
112
  this.timer = null;
135
113
  }
136
-
137
- }
138
-
139
- }
140
-
114
+ },
115
+ },
141
116
  };
142
117
 
143
118
  function getTimeSpan(date) {
144
-
145
119
  const total = date - Date.now();
146
120
 
147
121
  return {
148
122
  total,
149
- seconds: total / 1000 % 60,
150
- minutes: total / 1000 / 60 % 60,
151
- hours: total / 1000 / 60 / 60 % 24,
152
- days: total / 1000 / 60 / 60 / 24
123
+ seconds: (total / 1000) % 60,
124
+ minutes: (total / 1000 / 60) % 60,
125
+ hours: (total / 1000 / 60 / 60) % 24,
126
+ days: total / 1000 / 60 / 60 / 24,
153
127
  };
154
128
  }