@pageboard/html 0.15.14 → 0.16.1

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.
@@ -1,243 +0,0 @@
1
- var objectFitImages = (function () {
2
- 'use strict';
3
-
4
- function getDefaultExportFromCjs (x) {
5
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
6
- }
7
-
8
- /*! npm.im/object-fit-images 3.2.4 */
9
-
10
- var OFI = 'bfred-it:object-fit-images';
11
- var propRegex = /(object-fit|object-position)\s*:\s*([-.\w\s%]+)/g;
12
- var testImg = typeof Image === 'undefined' ? {style: {'object-position': 1}} : new Image();
13
- var supportsObjectFit = 'object-fit' in testImg.style;
14
- var supportsObjectPosition = 'object-position' in testImg.style;
15
- var supportsOFI = 'background-size' in testImg.style;
16
- var supportsCurrentSrc = typeof testImg.currentSrc === 'string';
17
- var nativeGetAttribute = testImg.getAttribute;
18
- var nativeSetAttribute = testImg.setAttribute;
19
- var autoModeEnabled = false;
20
-
21
- function createPlaceholder(w, h) {
22
- return ("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='" + w + "' height='" + h + "'%3E%3C/svg%3E");
23
- }
24
-
25
- function polyfillCurrentSrc(el) {
26
- if (el.srcset && !supportsCurrentSrc && window.picturefill) {
27
- var pf = window.picturefill._;
28
- // parse srcset with picturefill where currentSrc isn't available
29
- if (!el[pf.ns] || !el[pf.ns].evaled) {
30
- // force synchronous srcset parsing
31
- pf.fillImg(el, {reselect: true});
32
- }
33
-
34
- if (!el[pf.ns].curSrc) {
35
- // force picturefill to parse srcset
36
- el[pf.ns].supported = false;
37
- pf.fillImg(el, {reselect: true});
38
- }
39
-
40
- // retrieve parsed currentSrc, if any
41
- el.currentSrc = el[pf.ns].curSrc || el.src;
42
- }
43
- }
44
-
45
- function getStyle(el) {
46
- var style = getComputedStyle(el).fontFamily;
47
- var parsed;
48
- var props = {};
49
- while ((parsed = propRegex.exec(style)) !== null) {
50
- props[parsed[1]] = parsed[2];
51
- }
52
- return props;
53
- }
54
-
55
- function setPlaceholder(img, width, height) {
56
- // Default: fill width, no height
57
- var placeholder = createPlaceholder(width || 1, height || 0);
58
-
59
- // Only set placeholder if it's different
60
- if (nativeGetAttribute.call(img, 'src') !== placeholder) {
61
- nativeSetAttribute.call(img, 'src', placeholder);
62
- }
63
- }
64
-
65
- function onImageReady(img, callback) {
66
- // naturalWidth is only available when the image headers are loaded,
67
- // this loop will poll it every 100ms.
68
- if (img.naturalWidth) {
69
- callback(img);
70
- } else {
71
- setTimeout(onImageReady, 100, img, callback);
72
- }
73
- }
74
-
75
- function fixOne(el) {
76
- var style = getStyle(el);
77
- var ofi = el[OFI];
78
- style['object-fit'] = style['object-fit'] || 'fill'; // default value
79
-
80
- // Avoid running where unnecessary, unless OFI had already done its deed
81
- if (!ofi.img) {
82
- // fill is the default behavior so no action is necessary
83
- if (style['object-fit'] === 'fill') {
84
- return;
85
- }
86
-
87
- // Where object-fit is supported and object-position isn't (Safari < 10)
88
- if (
89
- !ofi.skipTest && // unless user wants to apply regardless of browser support
90
- supportsObjectFit && // if browser already supports object-fit
91
- !style['object-position'] // unless object-position is used
92
- ) {
93
- return;
94
- }
95
- }
96
-
97
- // keep a clone in memory while resetting the original to a blank
98
- if (!ofi.img) {
99
- ofi.img = new Image(el.width, el.height);
100
- ofi.img.srcset = nativeGetAttribute.call(el, "data-ofi-srcset") || el.srcset;
101
- ofi.img.src = nativeGetAttribute.call(el, "data-ofi-src") || el.src;
102
-
103
- // preserve for any future cloneNode calls
104
- // https://github.com/bfred-it/object-fit-images/issues/53
105
- nativeSetAttribute.call(el, "data-ofi-src", el.src);
106
- if (el.srcset) {
107
- nativeSetAttribute.call(el, "data-ofi-srcset", el.srcset);
108
- }
109
-
110
- setPlaceholder(el, el.naturalWidth || el.width, el.naturalHeight || el.height);
111
-
112
- // remove srcset because it overrides src
113
- if (el.srcset) {
114
- el.srcset = '';
115
- }
116
- try {
117
- keepSrcUsable(el);
118
- } catch (err) {
119
- if (window.console) {
120
- console.warn('https://bit.ly/ofi-old-browser');
121
- }
122
- }
123
- }
124
-
125
- polyfillCurrentSrc(ofi.img);
126
-
127
- el.style.backgroundImage = "url(\"" + ((ofi.img.currentSrc || ofi.img.src).replace(/"/g, '\\"')) + "\")";
128
- el.style.backgroundPosition = style['object-position'] || 'center';
129
- el.style.backgroundRepeat = 'no-repeat';
130
- el.style.backgroundOrigin = 'content-box';
131
-
132
- if (/scale-down/.test(style['object-fit'])) {
133
- onImageReady(ofi.img, function () {
134
- if (ofi.img.naturalWidth > el.width || ofi.img.naturalHeight > el.height) {
135
- el.style.backgroundSize = 'contain';
136
- } else {
137
- el.style.backgroundSize = 'auto';
138
- }
139
- });
140
- } else {
141
- el.style.backgroundSize = style['object-fit'].replace('none', 'auto').replace('fill', '100% 100%');
142
- }
143
-
144
- onImageReady(ofi.img, function (img) {
145
- setPlaceholder(el, img.naturalWidth, img.naturalHeight);
146
- });
147
- }
148
-
149
- function keepSrcUsable(el) {
150
- var descriptors = {
151
- get: function get(prop) {
152
- return el[OFI].img[prop ? prop : 'src'];
153
- },
154
- set: function set(value, prop) {
155
- el[OFI].img[prop ? prop : 'src'] = value;
156
- nativeSetAttribute.call(el, ("data-ofi-" + prop), value); // preserve for any future cloneNode
157
- fixOne(el);
158
- return value;
159
- }
160
- };
161
- Object.defineProperty(el, 'src', descriptors);
162
- Object.defineProperty(el, 'currentSrc', {
163
- get: function () { return descriptors.get('currentSrc'); }
164
- });
165
- Object.defineProperty(el, 'srcset', {
166
- get: function () { return descriptors.get('srcset'); },
167
- set: function (ss) { return descriptors.set(ss, 'srcset'); }
168
- });
169
- }
170
-
171
- function hijackAttributes() {
172
- function getOfiImageMaybe(el, name) {
173
- return el[OFI] && el[OFI].img && (name === 'src' || name === 'srcset') ? el[OFI].img : el;
174
- }
175
- if (!supportsObjectPosition) {
176
- HTMLImageElement.prototype.getAttribute = function (name) {
177
- return nativeGetAttribute.call(getOfiImageMaybe(this, name), name);
178
- };
179
-
180
- HTMLImageElement.prototype.setAttribute = function (name, value) {
181
- return nativeSetAttribute.call(getOfiImageMaybe(this, name), name, String(value));
182
- };
183
- }
184
- }
185
-
186
- function fix(imgs, opts) {
187
- var startAutoMode = !autoModeEnabled && !imgs;
188
- opts = opts || {};
189
- imgs = imgs || 'img';
190
-
191
- if ((supportsObjectPosition && !opts.skipTest) || !supportsOFI) {
192
- return false;
193
- }
194
-
195
- // use imgs as a selector or just select all images
196
- if (imgs === 'img') {
197
- imgs = document.getElementsByTagName('img');
198
- } else if (typeof imgs === 'string') {
199
- imgs = document.querySelectorAll(imgs);
200
- } else if (!('length' in imgs)) {
201
- imgs = [imgs];
202
- }
203
-
204
- // apply fix to all
205
- for (var i = 0; i < imgs.length; i++) {
206
- imgs[i][OFI] = imgs[i][OFI] || {
207
- skipTest: opts.skipTest
208
- };
209
- fixOne(imgs[i]);
210
- }
211
-
212
- if (startAutoMode) {
213
- document.body.addEventListener('load', function (e) {
214
- if (e.target.tagName === 'IMG') {
215
- fix(e.target, {
216
- skipTest: opts.skipTest
217
- });
218
- }
219
- }, true);
220
- autoModeEnabled = true;
221
- imgs = 'img'; // reset to a generic selector for watchMQ
222
- }
223
-
224
- // if requested, watch media queries for object-fit change
225
- if (opts.watchMQ) {
226
- window.addEventListener('resize', fix.bind(null, imgs, {
227
- skipTest: opts.skipTest
228
- }));
229
- }
230
- }
231
-
232
- fix.supportsObjectFit = supportsObjectFit;
233
- fix.supportsObjectPosition = supportsObjectPosition;
234
-
235
- hijackAttributes();
236
-
237
- var ofi_commonJs = fix;
238
-
239
- var ofi_commonJs$1 = /*@__PURE__*/getDefaultExportFromCjs(ofi_commonJs);
240
-
241
- return ofi_commonJs$1;
242
-
243
- })();