uikit 3.11.2-dev.244aa5c8c → 3.11.2-dev.31cd2ba38

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 (48) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/css/uikit-core-rtl.css +1 -1
  3. package/dist/css/uikit-core-rtl.min.css +1 -1
  4. package/dist/css/uikit-core.css +1 -1
  5. package/dist/css/uikit-core.min.css +1 -1
  6. package/dist/css/uikit-rtl.css +1 -1
  7. package/dist/css/uikit-rtl.min.css +1 -1
  8. package/dist/css/uikit.css +1 -1
  9. package/dist/css/uikit.min.css +1 -1
  10. package/dist/js/components/countdown.js +1 -1
  11. package/dist/js/components/countdown.min.js +1 -1
  12. package/dist/js/components/filter.js +1 -1
  13. package/dist/js/components/filter.min.js +1 -1
  14. package/dist/js/components/lightbox-panel.js +1 -1
  15. package/dist/js/components/lightbox-panel.min.js +1 -1
  16. package/dist/js/components/lightbox.js +1 -1
  17. package/dist/js/components/lightbox.min.js +1 -1
  18. package/dist/js/components/notification.js +1 -1
  19. package/dist/js/components/notification.min.js +1 -1
  20. package/dist/js/components/parallax.js +1 -1
  21. package/dist/js/components/parallax.min.js +1 -1
  22. package/dist/js/components/slider-parallax.js +1 -1
  23. package/dist/js/components/slider-parallax.min.js +1 -1
  24. package/dist/js/components/slider.js +1 -1
  25. package/dist/js/components/slider.min.js +1 -1
  26. package/dist/js/components/slideshow-parallax.js +1 -1
  27. package/dist/js/components/slideshow-parallax.min.js +1 -1
  28. package/dist/js/components/slideshow.js +1 -1
  29. package/dist/js/components/slideshow.min.js +1 -1
  30. package/dist/js/components/sortable.js +1 -1
  31. package/dist/js/components/sortable.min.js +1 -1
  32. package/dist/js/components/tooltip.js +1 -1
  33. package/dist/js/components/tooltip.min.js +1 -1
  34. package/dist/js/components/upload.js +1 -1
  35. package/dist/js/components/upload.min.js +1 -1
  36. package/dist/js/uikit-core.js +78 -120
  37. package/dist/js/uikit-core.min.js +1 -1
  38. package/dist/js/uikit-icons.js +1 -1
  39. package/dist/js/uikit-icons.min.js +1 -1
  40. package/dist/js/uikit.js +78 -120
  41. package/dist/js/uikit.min.js +1 -1
  42. package/package.json +1 -1
  43. package/src/js/api/state.js +4 -4
  44. package/src/js/core/img.js +68 -92
  45. package/src/js/util/options.js +5 -5
  46. package/tests/image.html +22 -38
  47. package/tests/images/test.avif +0 -0
  48. package/tests/images/test.webp +0 -0
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "uikit",
3
3
  "title": "UIkit",
4
4
  "description": "UIkit is a lightweight and modular front-end framework for developing fast and powerful web interfaces.",
5
- "version": "3.11.2-dev.244aa5c8c",
5
+ "version": "3.11.2-dev.31cd2ba38",
6
6
  "main": "dist/js/uikit.js",
7
7
  "style": "dist/css/uikit.css",
8
8
  "sideEffects": [
@@ -211,11 +211,11 @@ export default function (UIkit) {
211
211
  on(
212
212
  el,
213
213
  name,
214
- !delegate
215
- ? null
216
- : isString(delegate)
214
+ delegate
215
+ ? isString(delegate)
217
216
  ? delegate
218
- : delegate.call(component),
217
+ : delegate.call(component)
218
+ : null,
219
219
  isString(handler) ? component[handler] : handler.bind(component),
220
220
  {passive, capture, self}
221
221
  )
@@ -1,4 +1,4 @@
1
- import {createEvent, css, Dimensions, escape, getImage, includes, isUndefined, queryAll, startsWith, toFloat, toPx, trigger} from 'uikit-util';
1
+ import {append, attr, children, createEvent, css, data, escape, fragment, includes, isArray, isObject, isUndefined, parent, parseOptions, queryAll, startsWith, toFloat, toPx, trigger} from 'uikit-util';
2
2
 
3
3
  export default {
4
4
 
@@ -6,10 +6,7 @@ export default {
6
6
 
7
7
  props: {
8
8
  dataSrc: String,
9
- dataSrcset: Boolean,
10
- sizes: String,
11
- width: Number,
12
- height: Number,
9
+ dataSources: String,
13
10
  offsetTop: String,
14
11
  offsetLeft: String,
15
12
  target: String
@@ -17,10 +14,7 @@ export default {
17
14
 
18
15
  data: {
19
16
  dataSrc: '',
20
- dataSrcset: false,
21
- sizes: false,
22
- width: false,
23
- height: false,
17
+ dataSources: [],
24
18
  offsetTop: '50vh',
25
19
  offsetLeft: '50vw',
26
20
  target: false
@@ -28,26 +22,6 @@ export default {
28
22
 
29
23
  computed: {
30
24
 
31
- cacheKey({dataSrc}) {
32
- return `${this.$name}.${dataSrc}`;
33
- },
34
-
35
- width({width, dataWidth}) {
36
- return width || dataWidth;
37
- },
38
-
39
- height({height, dataHeight}) {
40
- return height || dataHeight;
41
- },
42
-
43
- sizes({sizes, dataSizes}) {
44
- return sizes || dataSizes;
45
- },
46
-
47
- isImg(_, $el) {
48
- return isImg($el);
49
- },
50
-
51
25
  target: {
52
26
 
53
27
  get({target}) {
@@ -58,14 +32,6 @@ export default {
58
32
  this.observe();
59
33
  }
60
34
 
61
- },
62
-
63
- offsetTop({offsetTop}) {
64
- return toPx(offsetTop, 'height');
65
- },
66
-
67
- offsetLeft({offsetLeft}) {
68
- return toPx(offsetLeft, 'width');
69
35
  }
70
36
 
71
37
  },
@@ -73,21 +39,13 @@ export default {
73
39
  connected() {
74
40
 
75
41
  if (!window.IntersectionObserver) {
76
- setSrcAttrs(this.$el, this.dataSrc, this.dataSrcset, this.sizes);
42
+ setSrcAttrs(this.$el, this.dataSrc);
77
43
  return;
78
44
  }
79
45
 
80
- if (storage[this.cacheKey]) {
81
- setSrcAttrs(this.$el, storage[this.cacheKey], this.dataSrcset, this.sizes);
82
- } else if (this.isImg && this.width && this.height) {
83
- setSrcAttrs(this.$el, getPlaceholderImage(this.width, this.height, this.sizes));
84
- }
85
-
86
- this.observer = new IntersectionObserver(this.load, {
87
- rootMargin: `${this.offsetTop}px ${this.offsetLeft}px`
88
- });
89
-
90
- requestAnimationFrame(this.observe);
46
+ const rootMargin = `${toPx(this.offsetTop, 'height')}px ${toPx(this.offsetLeft, 'width')}px`;
47
+ this.observer = new IntersectionObserver(this.load, {rootMargin});
48
+ this.observe();
91
49
 
92
50
  },
93
51
 
@@ -99,30 +57,23 @@ export default {
99
57
 
100
58
  read({image}) {
101
59
 
102
- if (!this.observer) {
103
- return false;
104
- }
105
-
106
- if (!image && document.readyState === 'complete') {
107
- this.load(this.observer.takeRecords());
108
- }
109
-
110
- if (this.isImg) {
60
+ if (!this.observer || isImg(this.$el)) {
111
61
  return false;
112
62
  }
113
63
 
114
- image && image.then(img => img && img.currentSrc !== '' && setSrcAttrs(this.$el, currentSrc(img)));
64
+ setSrcAttrs(this.$el, image && image.currentSrc);
115
65
 
116
66
  },
117
67
 
118
- write(data) {
68
+ write(store) {
119
69
 
120
- if (this.dataSrcset && window.devicePixelRatio !== 1) {
70
+ const srcset = data(this.$el, 'data-srcset');
71
+ if (srcset && window.devicePixelRatio !== 1) {
121
72
 
122
73
  const bgSize = css(this.$el, 'backgroundSize');
123
- if (bgSize.match(/^(auto\s?)+$/) || toFloat(bgSize) === data.bgSize) {
124
- data.bgSize = getSourceSize(this.dataSrcset, this.sizes);
125
- css(this.$el, 'backgroundSize', `${data.bgSize}px`);
74
+ if (bgSize.match(/^(auto\s?)+$/) || toFloat(bgSize) === store.bgSize) {
75
+ store.bgSize = getSourceSize(srcset, data(this.$el, 'sizes'));
76
+ css(this.$el, 'backgroundSize', `${store.bgSize}px`);
126
77
  }
127
78
 
128
79
  }
@@ -142,13 +93,16 @@ export default {
142
93
  return;
143
94
  }
144
95
 
145
- this._data.image = getImage(this.dataSrc, this.dataSrcset, this.sizes).then(img => {
96
+ if (this._data.image) {
97
+ return this._data.image;
98
+ }
146
99
 
147
- setSrcAttrs(this.$el, currentSrc(img), img.srcset, img.sizes);
148
- storage[this.cacheKey] = currentSrc(img);
149
- return img;
100
+ const image = isImg(this.$el)
101
+ ? this.$el
102
+ : getImageFromElement(this.$el, this.dataSrc, parseOptions(this.dataSources));
150
103
 
151
- }, e => trigger(this.$el, new e.constructor(e.type, e)));
104
+ this._data.image = image;
105
+ setSrcAttrs(this.$el, image.currentSrc || this.dataSrc);
152
106
 
153
107
  this.observer.disconnect();
154
108
  },
@@ -163,13 +117,15 @@ export default {
163
117
 
164
118
  };
165
119
 
166
- function setSrcAttrs(el, src, srcset, sizes) {
120
+ function setSrcAttrs(el, src) {
167
121
 
168
122
  if (isImg(el)) {
169
- const set = (prop, val) => val && val !== el[prop] && (el[prop] = val);
170
- set('sizes', sizes);
171
- set('srcset', srcset);
172
- set('src', src);
123
+
124
+ const parentNode = parent(el);
125
+ const elements = isPicture(parentNode) ? children(parentNode) : [el];
126
+ elements.forEach(el => setSourceProps(el, el));
127
+ src && attr(el, 'src', src);
128
+
173
129
  } else if (src) {
174
130
 
175
131
  const change = !includes(el.style.backgroundImage, src);
@@ -182,13 +138,41 @@ function setSrcAttrs(el, src, srcset, sizes) {
182
138
 
183
139
  }
184
140
 
185
- function getPlaceholderImage(width, height, sizes) {
141
+ const srcProps = ['data-src', 'data-srcset', 'sizes'];
142
+ function setSourceProps(sourceEl, targetEl) {
143
+ srcProps.forEach(prop => {
144
+ const value = data(sourceEl, prop);
145
+ if (value) {
146
+ attr(targetEl, prop.replace(/^(data-)+/, ''), value);
147
+ }
148
+ });
149
+ }
150
+
151
+ function getImageFromElement(el, src, sources = []) {
186
152
 
187
- if (sizes) {
188
- ({width, height} = Dimensions.ratio({width, height}, 'width', toPx(sizesToPixel(sizes))));
153
+ if (!src) {
154
+ return false;
189
155
  }
190
156
 
191
- return `data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}"></svg>`;
157
+ const img = new Image();
158
+
159
+ if (!isArray(sources) && isObject(sources)) {
160
+ sources = [sources];
161
+ }
162
+
163
+ if (sources.length) {
164
+ const picture = fragment('<picture>');
165
+ sources.forEach(attrs => {
166
+ const source = fragment('<source>');
167
+ attr(source, attrs);
168
+ append(picture, source);
169
+ });
170
+ append(picture, img);
171
+ }
172
+
173
+ setSourceProps(el, img);
174
+ attr(img, 'src', src);
175
+ return img;
192
176
  }
193
177
 
194
178
  const sizesRe = /\s*(.*?)\s*(\w+|calc\(.*?\))\s*(?:,|$)/g;
@@ -228,22 +212,14 @@ function getSourceSize(srcset, sizes) {
228
212
  return descriptors.filter(size => size >= srcSize)[0] || descriptors.pop() || '';
229
213
  }
230
214
 
231
- function isImg(el) {
232
- return el.tagName === 'IMG';
215
+ function isPicture(el) {
216
+ return isA(el, 'PICTURE');
233
217
  }
234
218
 
235
- function currentSrc(el) {
236
- return el.currentSrc || el.src;
219
+ function isImg(el) {
220
+ return isA(el, 'IMG');
237
221
  }
238
222
 
239
- const key = '__test__';
240
- let storage;
241
-
242
- // workaround for Safari's private browsing mode and accessing sessionStorage in Blink
243
- try {
244
- storage = window.sessionStorage || {};
245
- storage[key] = 1;
246
- delete storage[key];
247
- } catch (e) {
248
- storage = {};
223
+ function isA(el, tagName) {
224
+ return el && el.tagName === tagName;
249
225
  }
@@ -1,4 +1,4 @@
1
- import {assign, hasOwn, includes, isArray, isFunction, isUndefined, sortBy, startsWith} from './lang';
1
+ import {assign, hasOwn, includes, isArray, isFunction, isUndefined, sortBy} from './lang';
2
2
 
3
3
  const strats = {};
4
4
 
@@ -134,9 +134,8 @@ export function parseOptions(options, args = []) {
134
134
 
135
135
  try {
136
136
 
137
- return !options
138
- ? {}
139
- : startsWith(options, '{')
137
+ return options
138
+ ? options.match(/^[{[]/)
140
139
  ? JSON.parse(options)
141
140
  : args.length && !includes(options, ':')
142
141
  ? ({[args[0]]: options})
@@ -146,7 +145,8 @@ export function parseOptions(options, args = []) {
146
145
  options[key.trim()] = value.trim();
147
146
  }
148
147
  return options;
149
- }, {});
148
+ }, {})
149
+ : {};
150
150
 
151
151
  } catch (e) {
152
152
  return {};
package/tests/image.html CHANGED
@@ -14,8 +14,6 @@
14
14
 
15
15
  <h1>Image</h1>
16
16
 
17
- <p><button class="uk-button uk-button-default" onclick="sessionStorage.clear()">Clear Session Storage</button></p>
18
-
19
17
  <div class="uk-child-width-1-2@m" uk-grid>
20
18
  <div>
21
19
  <img data-src="https://images.unsplash.com/photo-1522201949034-507737bce479?fit=crop&w=900&h=600&q=80" width="900" height="600" alt="" uk-img>
@@ -25,7 +23,11 @@
25
23
  </div>
26
24
  </div>
27
25
 
28
- <div class="uk-height-large uk-background-cover uk-margin-medium uk-flex uk-flex-center uk-flex-middle uk-light" data-src="https://images.unsplash.com/photo-1490822180406-880c226c150b?fit=crop&w=1200&h=450&q=80" uk-img>
26
+ <div class="uk-height-large uk-background-cover uk-margin-medium uk-flex uk-flex-center uk-flex-middle uk-light" data-src="https://images.unsplash.com/photo-1490822180406-880c226c150b?fit=crop&w=1200&h=450&q=80" data-sources="srcset: images/test.avif; type: image/avif" uk-img>
27
+ <h1>Background Image</h1>
28
+ </div>
29
+
30
+ <div class="uk-height-large uk-background-cover uk-margin-medium uk-flex uk-flex-center uk-flex-middle uk-light" data-src="https://images.unsplash.com/photo-1490822180406-880c226c150b?fit=crop&w=1200&h=450&q=80" data-sources="[{&quot;srcset&quot;: &quot;images/test.avif&quot;, &quot;type&quot;: &quot;image/avif&quot;},{&quot;srcset&quot;: &quot;images/test.webp&quot;, &quot;type&quot;: &quot;image/webp&quot;}]" uk-img>
29
31
  <h1>Background Image</h1>
30
32
  </div>
31
33
 
@@ -255,28 +257,28 @@
255
257
 
256
258
  <ul class="uk-slideshow-items">
257
259
  <li>
258
- <img data-src="images/photo.jpg" alt="" uk-cover data-width="1800" data-height="1200" uk-img="target: !.uk-slideshow-items > :last-child, !* +*">
260
+ <img data-src="images/photo.jpg" alt="" uk-cover width="1800" height="1200" uk-img="target: !.uk-slideshow-items > :last-child, !* +*">
259
261
  <div class="uk-position-center uk-position-small uk-text-center">
260
262
  <h2 uk-slideshow-parallax="x: 100,-100">Heading</h2>
261
263
  <p uk-slideshow-parallax="x: 200,-200">Lorem ipsum dolor sit amet.</p>
262
264
  </div>
263
265
  </li>
264
266
  <li>
265
- <img data-src="images/dark.jpg" alt="" uk-cover data-width="1800" data-height="1200" uk-img="target: !* -*, !* +*">
267
+ <img data-src="images/dark.jpg" alt="" uk-cover width="1800" height="1200" uk-img="target: !* -*, !* +*">
266
268
  <div class="uk-position-center uk-position-small uk-text-center">
267
269
  <h2 uk-slideshow-parallax="x: 100,-100">Heading</h2>
268
270
  <p uk-slideshow-parallax="x: 200,-200">Lorem ipsum dolor sit amet.</p>
269
271
  </div>
270
272
  </li>
271
273
  <li>
272
- <img data-src="images/light.jpg" alt="" uk-cover data-width="1800" data-height="1200" uk-img="target: !* -*, !* +*">
274
+ <img data-src="images/light.jpg" alt="" uk-cover width="1800" height="1200" uk-img="target: !* -*, !* +*">
273
275
  <div class="uk-position-center uk-position-small uk-text-center">
274
276
  <h2 uk-slideshow-parallax="y: -50,0,0; opacity: 1,1,0">Heading</h2>
275
277
  <p uk-slideshow-parallax="y: 50,0,0; opacity: 1,1,0">Lorem ipsum dolor sit amet.</p>
276
278
  </div>
277
279
  </li>
278
280
  <li>
279
- <img data-src="images/photo2.jpg" alt="" uk-cover data-width="1800" data-height="1200" uk-img="target: !* -*, !.uk-slideshow-items > :first-child">
281
+ <img data-src="images/photo2.jpg" alt="" uk-cover width="1800" height="1200" uk-img="target: !* -*, !.uk-slideshow-items > :first-child">
280
282
  <div class="uk-position-center uk-position-small uk-text-center">
281
283
  <h2 uk-slideshow-parallax="x: 200,0,0">Heading</h2>
282
284
  <p uk-slideshow-parallax="x: 0,0,-200">Lorem ipsum dolor sit amet.</p>
@@ -296,43 +298,43 @@
296
298
 
297
299
  <ul class="uk-slider-items uk-child-width-1-2@s uk-child-width-1-3@m">
298
300
  <li>
299
- <img data-src="images/slider1.jpg" alt="" data-width="400" data-height="600" uk-img="target: !.uk-slider-items">
301
+ <img data-src="images/slider1.jpg" alt="" width="400" height="600" uk-img="target: !.uk-slider-items">
300
302
  <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">1</h1></div>
301
303
  </li>
302
304
  <li>
303
- <img data-src="images/slider2.jpg" alt="" data-width="400" data-height="600" uk-img="target: !.uk-slider-items">
305
+ <img data-src="images/slider2.jpg" alt="" width="400" height="600" uk-img="target: !.uk-slider-items">
304
306
  <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">2</h1></div>
305
307
  </li>
306
308
  <li>
307
- <img data-src="images/slider3.jpg" alt="" data-width="400" data-height="600" uk-img="target: !.uk-slider-items">
309
+ <img data-src="images/slider3.jpg" alt="" width="400" height="600" uk-img="target: !.uk-slider-items">
308
310
  <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">3</h1></div>
309
311
  </li>
310
312
  <li>
311
- <img data-src="images/slider4.jpg" alt="" data-width="400" data-height="600" uk-img="target: !.uk-slider-items">
313
+ <img data-src="images/slider4.jpg" alt="" width="400" height="600" uk-img="target: !.uk-slider-items">
312
314
  <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">4</h1></div>
313
315
  </li>
314
316
  <li>
315
- <img data-src="images/slider5.jpg" alt="" data-width="400" data-height="600" uk-img="target: !.uk-slider-items">
317
+ <img data-src="images/slider5.jpg" alt="" width="400" height="600" uk-img="target: !.uk-slider-items">
316
318
  <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">5</h1></div>
317
319
  </li>
318
320
  <li>
319
- <img data-src="images/slider1.jpg" alt="" data-width="400" data-height="600" uk-img="target: !.uk-slider-items">
321
+ <img data-src="images/slider1.jpg" alt="" width="400" height="600" uk-img="target: !.uk-slider-items">
320
322
  <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">6</h1></div>
321
323
  </li>
322
324
  <li>
323
- <img data-src="images/slider2.jpg" alt="" data-width="400" data-height="600" uk-img="target: !.uk-slider-items">
325
+ <img data-src="images/slider2.jpg" alt="" width="400" height="600" uk-img="target: !.uk-slider-items">
324
326
  <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">7</h1></div>
325
327
  </li>
326
328
  <li>
327
- <img data-src="images/slider3.jpg" alt="" data-width="400" data-height="600" uk-img="target: !.uk-slider-items">
329
+ <img data-src="images/slider3.jpg" alt="" width="400" height="600" uk-img="target: !.uk-slider-items">
328
330
  <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">8</h1></div>
329
331
  </li>
330
332
  <li>
331
- <img data-src="images/slider4.jpg" alt="" data-width="400" data-height="600" uk-img="target: !.uk-slider-items">
333
+ <img data-src="images/slider4.jpg" alt="" width="400" height="600" uk-img="target: !.uk-slider-items">
332
334
  <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">9</h1></div>
333
335
  </li>
334
336
  <li>
335
- <img data-src="images/slider5.jpg" alt="" data-width="400" data-height="600" uk-img="target: !.uk-slider-items">
337
+ <img data-src="images/slider5.jpg" alt="" width="400" height="600" uk-img="target: !.uk-slider-items">
336
338
  <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">10</h1></div>
337
339
  </li>
338
340
  </ul>
@@ -365,28 +367,10 @@
365
367
  <td>The image's `src` attribute.</td>
366
368
  </tr>
367
369
  <tr>
368
- <td><code>dataSrcset</code></td>
369
- <td>String</td>
370
- <td>false</td>
371
- <td>The image's `srcset` attribute.</td>
372
- </tr>
373
- <tr>
374
- <td><code>sizes</code></td>
375
- <td>String</td>
376
- <td>false</td>
377
- <td>The image's `sizes` attribute.</td>
378
- </tr>
379
- <tr>
380
- <td><code>width</code></td>
370
+ <td><code>dataSources</code></td>
381
371
  <td>String</td>
382
- <td>false</td>
383
- <td>The image's `width` attribute. It will be used to determine the placeholder's width and the images position in the document.</td>
384
- </tr>
385
- <tr>
386
- <td><code>height</code></td>
387
- <td>String</td>
388
- <td>false</td>
389
- <td>The image's `height` attribute. It will be used to determine the placeholder's height and the images position in the document.</td>
372
+ <td>''</td>
373
+ <td>The image's sources. This option is used for background images only. The sources attributes be passed in `key: value;` format for a single source. For multiple sources in JSON format.</td>
390
374
  </tr>
391
375
  <tr>
392
376
  <td><code>offsetTop</code></td>
Binary file
Binary file