@daoyi/nmtl-ui 2.0.1-beta.47 → 2.0.1-beta.49
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/lib/components/{Autocomplete-5439ff22.js → Autocomplete-aa4a8d6c.js} +4 -2
- package/lib/components/Autocomplete.js +7 -6
- package/lib/components/Avatar.js +2 -4
- package/lib/components/BackTop.js +28 -1
- package/lib/components/BarChart.js +634 -4
- package/lib/components/Breadcrumbs.js +2 -4
- package/lib/components/{Button-63c7e9f3.js → Button-2f8f0493.js} +2 -1
- package/lib/components/Button.js +3 -5
- package/lib/components/Carousel.js +4659 -7
- package/lib/components/CollapseContent.js +3 -5
- package/lib/components/ContactModal-a44e2a42.js +10759 -0
- package/lib/components/ContactModal.js +14 -9
- package/lib/components/{Drawer-af3ed21a.js → Drawer-dd8942f1.js} +2 -2
- package/lib/components/Drawer.js +5 -7
- package/lib/components/Dropdown.js +2 -3
- package/lib/components/{Empty-70f040a9.js → Empty-3637b766.js} +2 -1
- package/lib/components/Empty.js +3 -5
- package/lib/components/ExportButton.js +3 -5
- package/lib/components/ExtraTools-55dad795.js +3479 -0
- package/lib/components/ExtraTools.js +6 -7
- package/lib/components/Filter.js +691 -5
- package/lib/components/Footer.js +14 -9
- package/lib/components/ForwardLink-4759cf99.js +105 -0
- package/lib/components/ForwardLink.js +9 -106
- package/lib/components/Header.js +10 -9
- package/lib/components/Image.js +7 -4
- package/lib/components/Input.js +2 -4
- package/lib/components/InputMethod.js +10861 -4
- package/lib/components/{KeywordSearch-224f84c1.js → KeywordSearch-2d01266e.js} +3 -2
- package/lib/components/KeywordSearch.js +8 -7
- package/lib/components/KeywordTicker.js +24 -16
- package/lib/components/Keywords.js +30 -5
- package/lib/components/Loading.js +2 -4
- package/lib/components/MUITheme.js +2375 -3
- package/lib/components/{Modal-a7591b98.js → Modal-572e17ea.js} +4 -3
- package/lib/components/Modal.js +5 -7
- package/lib/components/{MoreButton-f15ca38e.js → MoreButton-80996b5f.js} +2 -1
- package/lib/components/MoreButton.js +3 -5
- package/lib/components/Radio.js +1 -4
- package/lib/components/SNA.js +1416 -5
- package/lib/components/{Select-98a8e973.js → Select-5533b506.js} +3 -2
- package/lib/components/Select.js +4 -6
- package/lib/components/{Spin-690a3597.js → Spin-ebf79c17.js} +2 -1
- package/lib/components/Spin.js +3 -5
- package/lib/components/{Tooltip-b7eb966d.js → Tooltip-907eaa2e.js} +2 -1
- package/lib/components/Tooltip.js +3 -5
- package/lib/components/_commonjsHelpers-70de2c37.js +28 -0
- package/lib/components/createSvgIcon-48da8b6e.js +576 -0
- package/lib/components/dataExport-d55d6fa3.js +92 -0
- package/lib/components/debounce-127da66c.js +355 -0
- package/lib/components/defaultTheme-19a14721.js +1485 -0
- package/lib/components/hoist-non-react-statics.cjs-3f408ad2.js +105 -0
- package/lib/components/index-7b60a97d.js +481 -0
- package/lib/components/index-f491ebce.js +61 -0
- package/lib/components/isObjectLike-e111475d.js +190 -0
- package/lib/components/style-inject.es-1f59c1d0.js +28 -0
- package/lib/components/transform-3a04288b.js +5475 -0
- package/lib/utils/domToImage.js +771 -1
- package/lib/utils/exportXlsx.js +36 -1
- package/lib/utils/historyAppendSearch.js +480 -1
- package/package.json +1 -1
- package/lib/components/ContactModal-a59bc808.js +0 -924
- package/lib/components/ExtraTools-f10a66a8.js +0 -818
- package/lib/components/dataExport-f418e6fe.js +0 -56
- package/lib/components/vendor-851c6356.js +0 -41940
- package/lib/utils/vendor-3ec75cc9.js +0 -1289
|
@@ -1,1289 +0,0 @@
|
|
|
1
|
-
var domToImage = {exports: {}};
|
|
2
|
-
|
|
3
|
-
(function (module) {
|
|
4
|
-
(function (global) {
|
|
5
|
-
|
|
6
|
-
var util = newUtil();
|
|
7
|
-
var inliner = newInliner();
|
|
8
|
-
var fontFaces = newFontFaces();
|
|
9
|
-
var images = newImages();
|
|
10
|
-
|
|
11
|
-
// Default impl options
|
|
12
|
-
var defaultOptions = {
|
|
13
|
-
// Default is to fail on error, no placeholder
|
|
14
|
-
imagePlaceholder: undefined,
|
|
15
|
-
// Default cache bust is false, it will use the cache
|
|
16
|
-
cacheBust: false
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
var domtoimage = {
|
|
20
|
-
toSvg: toSvg,
|
|
21
|
-
toPng: toPng,
|
|
22
|
-
toJpeg: toJpeg,
|
|
23
|
-
toBlob: toBlob,
|
|
24
|
-
toPixelData: toPixelData,
|
|
25
|
-
impl: {
|
|
26
|
-
fontFaces: fontFaces,
|
|
27
|
-
images: images,
|
|
28
|
-
util: util,
|
|
29
|
-
inliner: inliner,
|
|
30
|
-
options: {}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
module.exports = domtoimage;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {Node} node - The DOM Node object to render
|
|
39
|
-
* @param {Object} options - Rendering options
|
|
40
|
-
* @param {Function} options.filter - Should return true if passed node should be included in the output
|
|
41
|
-
* (excluding node means excluding it's children as well). Not called on the root node.
|
|
42
|
-
* @param {String} options.bgcolor - color for the background, any valid CSS color value.
|
|
43
|
-
* @param {Number} options.width - width to be applied to node before rendering.
|
|
44
|
-
* @param {Number} options.height - height to be applied to node before rendering.
|
|
45
|
-
* @param {Object} options.style - an object whose properties to be copied to node's style before rendering.
|
|
46
|
-
* @param {Number} options.quality - a Number between 0 and 1 indicating image quality (applicable to JPEG only),
|
|
47
|
-
defaults to 1.0.
|
|
48
|
-
* @param {String} options.imagePlaceholder - dataURL to use as a placeholder for failed images, default behaviour is to fail fast on images we can't fetch
|
|
49
|
-
* @param {Boolean} options.cacheBust - set to true to cache bust by appending the time to the request url
|
|
50
|
-
* @return {Promise} - A promise that is fulfilled with a SVG image data URL
|
|
51
|
-
* */
|
|
52
|
-
function toSvg(node, options) {
|
|
53
|
-
options = options || {};
|
|
54
|
-
copyOptions(options);
|
|
55
|
-
return Promise.resolve(node)
|
|
56
|
-
.then(function (node) {
|
|
57
|
-
return cloneNode(node, options.filter, true);
|
|
58
|
-
})
|
|
59
|
-
.then(embedFonts)
|
|
60
|
-
.then(inlineImages)
|
|
61
|
-
.then(applyOptions)
|
|
62
|
-
.then(function (clone) {
|
|
63
|
-
return makeSvgDataUri(clone,
|
|
64
|
-
options.width || util.width(node),
|
|
65
|
-
options.height || util.height(node)
|
|
66
|
-
);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
function applyOptions(clone) {
|
|
70
|
-
if (options.bgcolor) clone.style.backgroundColor = options.bgcolor;
|
|
71
|
-
|
|
72
|
-
if (options.width) clone.style.width = options.width + 'px';
|
|
73
|
-
if (options.height) clone.style.height = options.height + 'px';
|
|
74
|
-
|
|
75
|
-
if (options.style)
|
|
76
|
-
Object.keys(options.style).forEach(function (property) {
|
|
77
|
-
clone.style[property] = options.style[property];
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return clone;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @param {Node} node - The DOM Node object to render
|
|
86
|
-
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
87
|
-
* @return {Promise} - A promise that is fulfilled with a Uint8Array containing RGBA pixel data.
|
|
88
|
-
* */
|
|
89
|
-
function toPixelData(node, options) {
|
|
90
|
-
return draw(node, options || {})
|
|
91
|
-
.then(function (canvas) {
|
|
92
|
-
return canvas.getContext('2d').getImageData(
|
|
93
|
-
0,
|
|
94
|
-
0,
|
|
95
|
-
util.width(node),
|
|
96
|
-
util.height(node)
|
|
97
|
-
).data;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @param {Node} node - The DOM Node object to render
|
|
103
|
-
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
104
|
-
* @return {Promise} - A promise that is fulfilled with a PNG image data URL
|
|
105
|
-
* */
|
|
106
|
-
function toPng(node, options) {
|
|
107
|
-
return draw(node, options || {})
|
|
108
|
-
.then(function (canvas) {
|
|
109
|
-
return canvas.toDataURL();
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* @param {Node} node - The DOM Node object to render
|
|
115
|
-
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
116
|
-
* @return {Promise} - A promise that is fulfilled with a JPEG image data URL
|
|
117
|
-
* */
|
|
118
|
-
function toJpeg(node, options) {
|
|
119
|
-
options = options || {};
|
|
120
|
-
return draw(node, options)
|
|
121
|
-
.then(function (canvas) {
|
|
122
|
-
return canvas.toDataURL('image/jpeg', options.quality || 1.0);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* @param {Node} node - The DOM Node object to render
|
|
128
|
-
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
129
|
-
* @return {Promise} - A promise that is fulfilled with a PNG image blob
|
|
130
|
-
* */
|
|
131
|
-
function toBlob(node, options) {
|
|
132
|
-
return draw(node, options || {})
|
|
133
|
-
.then(util.canvasToBlob);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function copyOptions(options) {
|
|
137
|
-
// Copy options to impl options for use in impl
|
|
138
|
-
if(typeof(options.imagePlaceholder) === 'undefined') {
|
|
139
|
-
domtoimage.impl.options.imagePlaceholder = defaultOptions.imagePlaceholder;
|
|
140
|
-
} else {
|
|
141
|
-
domtoimage.impl.options.imagePlaceholder = options.imagePlaceholder;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if(typeof(options.cacheBust) === 'undefined') {
|
|
145
|
-
domtoimage.impl.options.cacheBust = defaultOptions.cacheBust;
|
|
146
|
-
} else {
|
|
147
|
-
domtoimage.impl.options.cacheBust = options.cacheBust;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function draw(domNode, options) {
|
|
152
|
-
return toSvg(domNode, options)
|
|
153
|
-
.then(util.makeImage)
|
|
154
|
-
.then(util.delay(100))
|
|
155
|
-
.then(function (image) {
|
|
156
|
-
var canvas = newCanvas(domNode);
|
|
157
|
-
canvas.getContext('2d').drawImage(image, 0, 0);
|
|
158
|
-
return canvas;
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
function newCanvas(domNode) {
|
|
162
|
-
var canvas = document.createElement('canvas');
|
|
163
|
-
canvas.width = options.width || util.width(domNode);
|
|
164
|
-
canvas.height = options.height || util.height(domNode);
|
|
165
|
-
|
|
166
|
-
if (options.bgcolor) {
|
|
167
|
-
var ctx = canvas.getContext('2d');
|
|
168
|
-
ctx.fillStyle = options.bgcolor;
|
|
169
|
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return canvas;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function cloneNode(node, filter, root) {
|
|
177
|
-
if (!root && filter && !filter(node)) return Promise.resolve();
|
|
178
|
-
|
|
179
|
-
return Promise.resolve(node)
|
|
180
|
-
.then(makeNodeCopy)
|
|
181
|
-
.then(function (clone) {
|
|
182
|
-
return cloneChildren(node, clone, filter);
|
|
183
|
-
})
|
|
184
|
-
.then(function (clone) {
|
|
185
|
-
return processClone(node, clone);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
function makeNodeCopy(node) {
|
|
189
|
-
if (node instanceof HTMLCanvasElement) return util.makeImage(node.toDataURL());
|
|
190
|
-
return node.cloneNode(false);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function cloneChildren(original, clone, filter) {
|
|
194
|
-
var children = original.childNodes;
|
|
195
|
-
if (children.length === 0) return Promise.resolve(clone);
|
|
196
|
-
|
|
197
|
-
return cloneChildrenInOrder(clone, util.asArray(children), filter)
|
|
198
|
-
.then(function () {
|
|
199
|
-
return clone;
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
function cloneChildrenInOrder(parent, children, filter) {
|
|
203
|
-
var done = Promise.resolve();
|
|
204
|
-
children.forEach(function (child) {
|
|
205
|
-
done = done
|
|
206
|
-
.then(function () {
|
|
207
|
-
return cloneNode(child, filter);
|
|
208
|
-
})
|
|
209
|
-
.then(function (childClone) {
|
|
210
|
-
if (childClone) parent.appendChild(childClone);
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
return done;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function processClone(original, clone) {
|
|
218
|
-
if (!(clone instanceof Element)) return clone;
|
|
219
|
-
|
|
220
|
-
return Promise.resolve()
|
|
221
|
-
.then(cloneStyle)
|
|
222
|
-
.then(clonePseudoElements)
|
|
223
|
-
.then(copyUserInput)
|
|
224
|
-
.then(fixSvg)
|
|
225
|
-
.then(function () {
|
|
226
|
-
return clone;
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
function cloneStyle() {
|
|
230
|
-
copyStyle(window.getComputedStyle(original), clone.style);
|
|
231
|
-
|
|
232
|
-
function copyStyle(source, target) {
|
|
233
|
-
if (source.cssText) target.cssText = source.cssText;
|
|
234
|
-
else copyProperties(source, target);
|
|
235
|
-
|
|
236
|
-
function copyProperties(source, target) {
|
|
237
|
-
util.asArray(source).forEach(function (name) {
|
|
238
|
-
target.setProperty(
|
|
239
|
-
name,
|
|
240
|
-
source.getPropertyValue(name),
|
|
241
|
-
source.getPropertyPriority(name)
|
|
242
|
-
);
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function clonePseudoElements() {
|
|
249
|
-
[':before', ':after'].forEach(function (element) {
|
|
250
|
-
clonePseudoElement(element);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
function clonePseudoElement(element) {
|
|
254
|
-
var style = window.getComputedStyle(original, element);
|
|
255
|
-
var content = style.getPropertyValue('content');
|
|
256
|
-
|
|
257
|
-
if (content === '' || content === 'none') return;
|
|
258
|
-
|
|
259
|
-
var className = util.uid();
|
|
260
|
-
clone.className = clone.className + ' ' + className;
|
|
261
|
-
var styleElement = document.createElement('style');
|
|
262
|
-
styleElement.appendChild(formatPseudoElementStyle(className, element, style));
|
|
263
|
-
clone.appendChild(styleElement);
|
|
264
|
-
|
|
265
|
-
function formatPseudoElementStyle(className, element, style) {
|
|
266
|
-
var selector = '.' + className + ':' + element;
|
|
267
|
-
var cssText = style.cssText ? formatCssText(style) : formatCssProperties(style);
|
|
268
|
-
return document.createTextNode(selector + '{' + cssText + '}');
|
|
269
|
-
|
|
270
|
-
function formatCssText(style) {
|
|
271
|
-
var content = style.getPropertyValue('content');
|
|
272
|
-
return style.cssText + ' content: ' + content + ';';
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function formatCssProperties(style) {
|
|
276
|
-
|
|
277
|
-
return util.asArray(style)
|
|
278
|
-
.map(formatProperty)
|
|
279
|
-
.join('; ') + ';';
|
|
280
|
-
|
|
281
|
-
function formatProperty(name) {
|
|
282
|
-
return name + ': ' +
|
|
283
|
-
style.getPropertyValue(name) +
|
|
284
|
-
(style.getPropertyPriority(name) ? ' !important' : '');
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function copyUserInput() {
|
|
292
|
-
if (original instanceof HTMLTextAreaElement) clone.innerHTML = original.value;
|
|
293
|
-
if (original instanceof HTMLInputElement) clone.setAttribute("value", original.value);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
function fixSvg() {
|
|
297
|
-
if (!(clone instanceof SVGElement)) return;
|
|
298
|
-
clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
299
|
-
|
|
300
|
-
if (!(clone instanceof SVGRectElement)) return;
|
|
301
|
-
['width', 'height'].forEach(function (attribute) {
|
|
302
|
-
var value = clone.getAttribute(attribute);
|
|
303
|
-
if (!value) return;
|
|
304
|
-
|
|
305
|
-
clone.style.setProperty(attribute, value);
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function embedFonts(node) {
|
|
312
|
-
return fontFaces.resolveAll()
|
|
313
|
-
.then(function (cssText) {
|
|
314
|
-
var styleNode = document.createElement('style');
|
|
315
|
-
node.appendChild(styleNode);
|
|
316
|
-
styleNode.appendChild(document.createTextNode(cssText));
|
|
317
|
-
return node;
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function inlineImages(node) {
|
|
322
|
-
return images.inlineAll(node)
|
|
323
|
-
.then(function () {
|
|
324
|
-
return node;
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function makeSvgDataUri(node, width, height) {
|
|
329
|
-
return Promise.resolve(node)
|
|
330
|
-
.then(function (node) {
|
|
331
|
-
node.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
|
|
332
|
-
return new XMLSerializer().serializeToString(node);
|
|
333
|
-
})
|
|
334
|
-
.then(util.escapeXhtml)
|
|
335
|
-
.then(function (xhtml) {
|
|
336
|
-
return '<foreignObject x="0" y="0" width="100%" height="100%">' + xhtml + '</foreignObject>';
|
|
337
|
-
})
|
|
338
|
-
.then(function (foreignObject) {
|
|
339
|
-
return '<svg xmlns="http://www.w3.org/2000/svg" width="' + width + '" height="' + height + '">' +
|
|
340
|
-
foreignObject + '</svg>';
|
|
341
|
-
})
|
|
342
|
-
.then(function (svg) {
|
|
343
|
-
return 'data:image/svg+xml;charset=utf-8,' + svg;
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function newUtil() {
|
|
348
|
-
return {
|
|
349
|
-
escape: escape,
|
|
350
|
-
parseExtension: parseExtension,
|
|
351
|
-
mimeType: mimeType,
|
|
352
|
-
dataAsUrl: dataAsUrl,
|
|
353
|
-
isDataUrl: isDataUrl,
|
|
354
|
-
canvasToBlob: canvasToBlob,
|
|
355
|
-
resolveUrl: resolveUrl,
|
|
356
|
-
getAndEncode: getAndEncode,
|
|
357
|
-
uid: uid(),
|
|
358
|
-
delay: delay,
|
|
359
|
-
asArray: asArray,
|
|
360
|
-
escapeXhtml: escapeXhtml,
|
|
361
|
-
makeImage: makeImage,
|
|
362
|
-
width: width,
|
|
363
|
-
height: height
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
function mimes() {
|
|
367
|
-
/*
|
|
368
|
-
* Only WOFF and EOT mime types for fonts are 'real'
|
|
369
|
-
* see http://www.iana.org/assignments/media-types/media-types.xhtml
|
|
370
|
-
*/
|
|
371
|
-
var WOFF = 'application/font-woff';
|
|
372
|
-
var JPEG = 'image/jpeg';
|
|
373
|
-
|
|
374
|
-
return {
|
|
375
|
-
'woff': WOFF,
|
|
376
|
-
'woff2': WOFF,
|
|
377
|
-
'ttf': 'application/font-truetype',
|
|
378
|
-
'eot': 'application/vnd.ms-fontobject',
|
|
379
|
-
'png': 'image/png',
|
|
380
|
-
'jpg': JPEG,
|
|
381
|
-
'jpeg': JPEG,
|
|
382
|
-
'gif': 'image/gif',
|
|
383
|
-
'tiff': 'image/tiff',
|
|
384
|
-
'svg': 'image/svg+xml'
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
function parseExtension(url) {
|
|
389
|
-
var match = /\.([^\.\/]*?)$/g.exec(url);
|
|
390
|
-
if (match) return match[1];
|
|
391
|
-
else return '';
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
function mimeType(url) {
|
|
395
|
-
var extension = parseExtension(url).toLowerCase();
|
|
396
|
-
return mimes()[extension] || '';
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
function isDataUrl(url) {
|
|
400
|
-
return url.search(/^(data:)/) !== -1;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
function toBlob(canvas) {
|
|
404
|
-
return new Promise(function (resolve) {
|
|
405
|
-
var binaryString = window.atob(canvas.toDataURL().split(',')[1]);
|
|
406
|
-
var length = binaryString.length;
|
|
407
|
-
var binaryArray = new Uint8Array(length);
|
|
408
|
-
|
|
409
|
-
for (var i = 0; i < length; i++)
|
|
410
|
-
binaryArray[i] = binaryString.charCodeAt(i);
|
|
411
|
-
|
|
412
|
-
resolve(new Blob([binaryArray], {
|
|
413
|
-
type: 'image/png'
|
|
414
|
-
}));
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
function canvasToBlob(canvas) {
|
|
419
|
-
if (canvas.toBlob)
|
|
420
|
-
return new Promise(function (resolve) {
|
|
421
|
-
canvas.toBlob(resolve);
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
return toBlob(canvas);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
function resolveUrl(url, baseUrl) {
|
|
428
|
-
var doc = document.implementation.createHTMLDocument();
|
|
429
|
-
var base = doc.createElement('base');
|
|
430
|
-
doc.head.appendChild(base);
|
|
431
|
-
var a = doc.createElement('a');
|
|
432
|
-
doc.body.appendChild(a);
|
|
433
|
-
base.href = baseUrl;
|
|
434
|
-
a.href = url;
|
|
435
|
-
return a.href;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
function uid() {
|
|
439
|
-
var index = 0;
|
|
440
|
-
|
|
441
|
-
return function () {
|
|
442
|
-
return 'u' + fourRandomChars() + index++;
|
|
443
|
-
|
|
444
|
-
function fourRandomChars() {
|
|
445
|
-
/* see http://stackoverflow.com/a/6248722/2519373 */
|
|
446
|
-
return ('0000' + (Math.random() * Math.pow(36, 4) << 0).toString(36)).slice(-4);
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
function makeImage(uri) {
|
|
452
|
-
return new Promise(function (resolve, reject) {
|
|
453
|
-
var image = new Image();
|
|
454
|
-
image.onload = function () {
|
|
455
|
-
resolve(image);
|
|
456
|
-
};
|
|
457
|
-
image.onerror = reject;
|
|
458
|
-
image.src = uri;
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
function getAndEncode(url) {
|
|
463
|
-
var TIMEOUT = 30000;
|
|
464
|
-
if(domtoimage.impl.options.cacheBust) {
|
|
465
|
-
// Cache bypass so we dont have CORS issues with cached images
|
|
466
|
-
// Source: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
|
|
467
|
-
url += ((/\?/).test(url) ? "&" : "?") + (new Date()).getTime();
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return new Promise(function (resolve) {
|
|
471
|
-
var request = new XMLHttpRequest();
|
|
472
|
-
|
|
473
|
-
request.onreadystatechange = done;
|
|
474
|
-
request.ontimeout = timeout;
|
|
475
|
-
request.responseType = 'blob';
|
|
476
|
-
request.timeout = TIMEOUT;
|
|
477
|
-
request.open('GET', url, true);
|
|
478
|
-
request.send();
|
|
479
|
-
|
|
480
|
-
var placeholder;
|
|
481
|
-
if(domtoimage.impl.options.imagePlaceholder) {
|
|
482
|
-
var split = domtoimage.impl.options.imagePlaceholder.split(/,/);
|
|
483
|
-
if(split && split[1]) {
|
|
484
|
-
placeholder = split[1];
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
function done() {
|
|
489
|
-
if (request.readyState !== 4) return;
|
|
490
|
-
|
|
491
|
-
if (request.status !== 200) {
|
|
492
|
-
if(placeholder) {
|
|
493
|
-
resolve(placeholder);
|
|
494
|
-
} else {
|
|
495
|
-
fail('cannot fetch resource: ' + url + ', status: ' + request.status);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
var encoder = new FileReader();
|
|
502
|
-
encoder.onloadend = function () {
|
|
503
|
-
var content = encoder.result.split(/,/)[1];
|
|
504
|
-
resolve(content);
|
|
505
|
-
};
|
|
506
|
-
encoder.readAsDataURL(request.response);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
function timeout() {
|
|
510
|
-
if(placeholder) {
|
|
511
|
-
resolve(placeholder);
|
|
512
|
-
} else {
|
|
513
|
-
fail('timeout of ' + TIMEOUT + 'ms occured while fetching resource: ' + url);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
function fail(message) {
|
|
518
|
-
console.error(message);
|
|
519
|
-
resolve('');
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
function dataAsUrl(content, type) {
|
|
525
|
-
return 'data:' + type + ';base64,' + content;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
function escape(string) {
|
|
529
|
-
return string.replace(/([.*+?^${}()|\[\]\/\\])/g, '\\$1');
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
function delay(ms) {
|
|
533
|
-
return function (arg) {
|
|
534
|
-
return new Promise(function (resolve) {
|
|
535
|
-
setTimeout(function () {
|
|
536
|
-
resolve(arg);
|
|
537
|
-
}, ms);
|
|
538
|
-
});
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
function asArray(arrayLike) {
|
|
543
|
-
var array = [];
|
|
544
|
-
var length = arrayLike.length;
|
|
545
|
-
for (var i = 0; i < length; i++) array.push(arrayLike[i]);
|
|
546
|
-
return array;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
function escapeXhtml(string) {
|
|
550
|
-
return string.replace(/#/g, '%23').replace(/\n/g, '%0A');
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function width(node) {
|
|
554
|
-
var leftBorder = px(node, 'border-left-width');
|
|
555
|
-
var rightBorder = px(node, 'border-right-width');
|
|
556
|
-
return node.scrollWidth + leftBorder + rightBorder;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
function height(node) {
|
|
560
|
-
var topBorder = px(node, 'border-top-width');
|
|
561
|
-
var bottomBorder = px(node, 'border-bottom-width');
|
|
562
|
-
return node.scrollHeight + topBorder + bottomBorder;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
function px(node, styleProperty) {
|
|
566
|
-
var value = window.getComputedStyle(node).getPropertyValue(styleProperty);
|
|
567
|
-
return parseFloat(value.replace('px', ''));
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
function newInliner() {
|
|
572
|
-
var URL_REGEX = /url\(['"]?([^'"]+?)['"]?\)/g;
|
|
573
|
-
|
|
574
|
-
return {
|
|
575
|
-
inlineAll: inlineAll,
|
|
576
|
-
shouldProcess: shouldProcess,
|
|
577
|
-
impl: {
|
|
578
|
-
readUrls: readUrls,
|
|
579
|
-
inline: inline
|
|
580
|
-
}
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
function shouldProcess(string) {
|
|
584
|
-
return string.search(URL_REGEX) !== -1;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
function readUrls(string) {
|
|
588
|
-
var result = [];
|
|
589
|
-
var match;
|
|
590
|
-
while ((match = URL_REGEX.exec(string)) !== null) {
|
|
591
|
-
result.push(match[1]);
|
|
592
|
-
}
|
|
593
|
-
return result.filter(function (url) {
|
|
594
|
-
return !util.isDataUrl(url);
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
function inline(string, url, baseUrl, get) {
|
|
599
|
-
return Promise.resolve(url)
|
|
600
|
-
.then(function (url) {
|
|
601
|
-
return baseUrl ? util.resolveUrl(url, baseUrl) : url;
|
|
602
|
-
})
|
|
603
|
-
.then(get || util.getAndEncode)
|
|
604
|
-
.then(function (data) {
|
|
605
|
-
return util.dataAsUrl(data, util.mimeType(url));
|
|
606
|
-
})
|
|
607
|
-
.then(function (dataUrl) {
|
|
608
|
-
return string.replace(urlAsRegex(url), '$1' + dataUrl + '$3');
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
function urlAsRegex(url) {
|
|
612
|
-
return new RegExp('(url\\([\'"]?)(' + util.escape(url) + ')([\'"]?\\))', 'g');
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
function inlineAll(string, baseUrl, get) {
|
|
617
|
-
if (nothingToInline()) return Promise.resolve(string);
|
|
618
|
-
|
|
619
|
-
return Promise.resolve(string)
|
|
620
|
-
.then(readUrls)
|
|
621
|
-
.then(function (urls) {
|
|
622
|
-
var done = Promise.resolve(string);
|
|
623
|
-
urls.forEach(function (url) {
|
|
624
|
-
done = done.then(function (string) {
|
|
625
|
-
return inline(string, url, baseUrl, get);
|
|
626
|
-
});
|
|
627
|
-
});
|
|
628
|
-
return done;
|
|
629
|
-
});
|
|
630
|
-
|
|
631
|
-
function nothingToInline() {
|
|
632
|
-
return !shouldProcess(string);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
function newFontFaces() {
|
|
638
|
-
return {
|
|
639
|
-
resolveAll: resolveAll,
|
|
640
|
-
impl: {
|
|
641
|
-
readAll: readAll
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
function resolveAll() {
|
|
646
|
-
return readAll()
|
|
647
|
-
.then(function (webFonts) {
|
|
648
|
-
return Promise.all(
|
|
649
|
-
webFonts.map(function (webFont) {
|
|
650
|
-
return webFont.resolve();
|
|
651
|
-
})
|
|
652
|
-
);
|
|
653
|
-
})
|
|
654
|
-
.then(function (cssStrings) {
|
|
655
|
-
return cssStrings.join('\n');
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
function readAll() {
|
|
660
|
-
return Promise.resolve(util.asArray(document.styleSheets))
|
|
661
|
-
.then(getCssRules)
|
|
662
|
-
.then(selectWebFontRules)
|
|
663
|
-
.then(function (rules) {
|
|
664
|
-
return rules.map(newWebFont);
|
|
665
|
-
});
|
|
666
|
-
|
|
667
|
-
function selectWebFontRules(cssRules) {
|
|
668
|
-
return cssRules
|
|
669
|
-
.filter(function (rule) {
|
|
670
|
-
return rule.type === CSSRule.FONT_FACE_RULE;
|
|
671
|
-
})
|
|
672
|
-
.filter(function (rule) {
|
|
673
|
-
return inliner.shouldProcess(rule.style.getPropertyValue('src'));
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
function getCssRules(styleSheets) {
|
|
678
|
-
var cssRules = [];
|
|
679
|
-
styleSheets.forEach(function (sheet) {
|
|
680
|
-
try {
|
|
681
|
-
util.asArray(sheet.cssRules || []).forEach(cssRules.push.bind(cssRules));
|
|
682
|
-
} catch (e) {
|
|
683
|
-
console.log('Error while reading CSS rules from ' + sheet.href, e.toString());
|
|
684
|
-
}
|
|
685
|
-
});
|
|
686
|
-
return cssRules;
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
function newWebFont(webFontRule) {
|
|
690
|
-
return {
|
|
691
|
-
resolve: function resolve() {
|
|
692
|
-
var baseUrl = (webFontRule.parentStyleSheet || {}).href;
|
|
693
|
-
return inliner.inlineAll(webFontRule.cssText, baseUrl);
|
|
694
|
-
},
|
|
695
|
-
src: function () {
|
|
696
|
-
return webFontRule.style.getPropertyValue('src');
|
|
697
|
-
}
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
function newImages() {
|
|
704
|
-
return {
|
|
705
|
-
inlineAll: inlineAll,
|
|
706
|
-
impl: {
|
|
707
|
-
newImage: newImage
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
|
|
711
|
-
function newImage(element) {
|
|
712
|
-
return {
|
|
713
|
-
inline: inline
|
|
714
|
-
};
|
|
715
|
-
|
|
716
|
-
function inline(get) {
|
|
717
|
-
if (util.isDataUrl(element.src)) return Promise.resolve();
|
|
718
|
-
|
|
719
|
-
return Promise.resolve(element.src)
|
|
720
|
-
.then(get || util.getAndEncode)
|
|
721
|
-
.then(function (data) {
|
|
722
|
-
return util.dataAsUrl(data, util.mimeType(element.src));
|
|
723
|
-
})
|
|
724
|
-
.then(function (dataUrl) {
|
|
725
|
-
return new Promise(function (resolve, reject) {
|
|
726
|
-
element.onload = resolve;
|
|
727
|
-
element.onerror = reject;
|
|
728
|
-
element.src = dataUrl;
|
|
729
|
-
});
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
function inlineAll(node) {
|
|
735
|
-
if (!(node instanceof Element)) return Promise.resolve(node);
|
|
736
|
-
|
|
737
|
-
return inlineBackground(node)
|
|
738
|
-
.then(function () {
|
|
739
|
-
if (node instanceof HTMLImageElement)
|
|
740
|
-
return newImage(node).inline();
|
|
741
|
-
else
|
|
742
|
-
return Promise.all(
|
|
743
|
-
util.asArray(node.childNodes).map(function (child) {
|
|
744
|
-
return inlineAll(child);
|
|
745
|
-
})
|
|
746
|
-
);
|
|
747
|
-
});
|
|
748
|
-
|
|
749
|
-
function inlineBackground(node) {
|
|
750
|
-
var background = node.style.getPropertyValue('background');
|
|
751
|
-
|
|
752
|
-
if (!background) return Promise.resolve(node);
|
|
753
|
-
|
|
754
|
-
return inliner.inlineAll(background)
|
|
755
|
-
.then(function (inlined) {
|
|
756
|
-
node.style.setProperty(
|
|
757
|
-
'background',
|
|
758
|
-
inlined,
|
|
759
|
-
node.style.getPropertyPriority('background')
|
|
760
|
-
);
|
|
761
|
-
})
|
|
762
|
-
.then(function () {
|
|
763
|
-
return node;
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
})();
|
|
769
|
-
} (domToImage));
|
|
770
|
-
|
|
771
|
-
var domtoimage = domToImage.exports;
|
|
772
|
-
|
|
773
|
-
var fileDownload = function(data, filename, mime, bom) {
|
|
774
|
-
var blobData = (typeof bom !== 'undefined') ? [bom, data] : [data];
|
|
775
|
-
var blob = new Blob(blobData, {type: mime || 'application/octet-stream'});
|
|
776
|
-
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
|
777
|
-
// IE workaround for "HTML7007: One or more blob URLs were
|
|
778
|
-
// revoked by closing the blob for which they were created.
|
|
779
|
-
// These URLs will no longer resolve as the data backing
|
|
780
|
-
// the URL has been freed."
|
|
781
|
-
window.navigator.msSaveBlob(blob, filename);
|
|
782
|
-
}
|
|
783
|
-
else {
|
|
784
|
-
var blobURL = (window.URL && window.URL.createObjectURL) ? window.URL.createObjectURL(blob) : window.webkitURL.createObjectURL(blob);
|
|
785
|
-
var tempLink = document.createElement('a');
|
|
786
|
-
tempLink.style.display = 'none';
|
|
787
|
-
tempLink.href = blobURL;
|
|
788
|
-
tempLink.setAttribute('download', filename);
|
|
789
|
-
|
|
790
|
-
// Safari thinks _blank anchor are pop ups. We only want to set _blank
|
|
791
|
-
// target if the browser does not support the HTML5 download attribute.
|
|
792
|
-
// This allows you to download files in desktop safari if pop up blocking
|
|
793
|
-
// is enabled.
|
|
794
|
-
if (typeof tempLink.download === 'undefined') {
|
|
795
|
-
tempLink.setAttribute('target', '_blank');
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
document.body.appendChild(tempLink);
|
|
799
|
-
tempLink.click();
|
|
800
|
-
|
|
801
|
-
// Fixes "webkit blob resource error 1"
|
|
802
|
-
setTimeout(function() {
|
|
803
|
-
document.body.removeChild(tempLink);
|
|
804
|
-
window.URL.revokeObjectURL(blobURL);
|
|
805
|
-
}, 200);
|
|
806
|
-
}
|
|
807
|
-
};
|
|
808
|
-
|
|
809
|
-
var queryString = {};
|
|
810
|
-
|
|
811
|
-
var strictUriEncode = str => encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
812
|
-
|
|
813
|
-
var token = '%[a-f0-9]{2}';
|
|
814
|
-
var singleMatcher = new RegExp(token, 'gi');
|
|
815
|
-
var multiMatcher = new RegExp('(' + token + ')+', 'gi');
|
|
816
|
-
|
|
817
|
-
function decodeComponents(components, split) {
|
|
818
|
-
try {
|
|
819
|
-
// Try to decode the entire string first
|
|
820
|
-
return decodeURIComponent(components.join(''));
|
|
821
|
-
} catch (err) {
|
|
822
|
-
// Do nothing
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
if (components.length === 1) {
|
|
826
|
-
return components;
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
split = split || 1;
|
|
830
|
-
|
|
831
|
-
// Split the array in 2 parts
|
|
832
|
-
var left = components.slice(0, split);
|
|
833
|
-
var right = components.slice(split);
|
|
834
|
-
|
|
835
|
-
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
function decode(input) {
|
|
839
|
-
try {
|
|
840
|
-
return decodeURIComponent(input);
|
|
841
|
-
} catch (err) {
|
|
842
|
-
var tokens = input.match(singleMatcher);
|
|
843
|
-
|
|
844
|
-
for (var i = 1; i < tokens.length; i++) {
|
|
845
|
-
input = decodeComponents(tokens, i).join('');
|
|
846
|
-
|
|
847
|
-
tokens = input.match(singleMatcher);
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
return input;
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
function customDecodeURIComponent(input) {
|
|
855
|
-
// Keep track of all the replacements and prefill the map with the `BOM`
|
|
856
|
-
var replaceMap = {
|
|
857
|
-
'%FE%FF': '\uFFFD\uFFFD',
|
|
858
|
-
'%FF%FE': '\uFFFD\uFFFD'
|
|
859
|
-
};
|
|
860
|
-
|
|
861
|
-
var match = multiMatcher.exec(input);
|
|
862
|
-
while (match) {
|
|
863
|
-
try {
|
|
864
|
-
// Decode as big chunks as possible
|
|
865
|
-
replaceMap[match[0]] = decodeURIComponent(match[0]);
|
|
866
|
-
} catch (err) {
|
|
867
|
-
var result = decode(match[0]);
|
|
868
|
-
|
|
869
|
-
if (result !== match[0]) {
|
|
870
|
-
replaceMap[match[0]] = result;
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
match = multiMatcher.exec(input);
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
// Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
|
|
878
|
-
replaceMap['%C2'] = '\uFFFD';
|
|
879
|
-
|
|
880
|
-
var entries = Object.keys(replaceMap);
|
|
881
|
-
|
|
882
|
-
for (var i = 0; i < entries.length; i++) {
|
|
883
|
-
// Replace all decoded components
|
|
884
|
-
var key = entries[i];
|
|
885
|
-
input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
return input;
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
var decodeUriComponent = function (encodedURI) {
|
|
892
|
-
if (typeof encodedURI !== 'string') {
|
|
893
|
-
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`');
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
try {
|
|
897
|
-
encodedURI = encodedURI.replace(/\+/g, ' ');
|
|
898
|
-
|
|
899
|
-
// Try the built in decoder first
|
|
900
|
-
return decodeURIComponent(encodedURI);
|
|
901
|
-
} catch (err) {
|
|
902
|
-
// Fallback to a more advanced decoder
|
|
903
|
-
return customDecodeURIComponent(encodedURI);
|
|
904
|
-
}
|
|
905
|
-
};
|
|
906
|
-
|
|
907
|
-
var splitOnFirst = (string, separator) => {
|
|
908
|
-
if (!(typeof string === 'string' && typeof separator === 'string')) {
|
|
909
|
-
throw new TypeError('Expected the arguments to be of type `string`');
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
if (separator === '') {
|
|
913
|
-
return [string];
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
const separatorIndex = string.indexOf(separator);
|
|
917
|
-
|
|
918
|
-
if (separatorIndex === -1) {
|
|
919
|
-
return [string];
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
return [
|
|
923
|
-
string.slice(0, separatorIndex),
|
|
924
|
-
string.slice(separatorIndex + separator.length)
|
|
925
|
-
];
|
|
926
|
-
};
|
|
927
|
-
|
|
928
|
-
(function (exports) {
|
|
929
|
-
const strictUriEncode$1 = strictUriEncode;
|
|
930
|
-
const decodeComponent = decodeUriComponent;
|
|
931
|
-
const splitOnFirst$1 = splitOnFirst;
|
|
932
|
-
|
|
933
|
-
const isNullOrUndefined = value => value === null || value === undefined;
|
|
934
|
-
|
|
935
|
-
function encoderForArrayFormat(options) {
|
|
936
|
-
switch (options.arrayFormat) {
|
|
937
|
-
case 'index':
|
|
938
|
-
return key => (result, value) => {
|
|
939
|
-
const index = result.length;
|
|
940
|
-
|
|
941
|
-
if (
|
|
942
|
-
value === undefined ||
|
|
943
|
-
(options.skipNull && value === null) ||
|
|
944
|
-
(options.skipEmptyString && value === '')
|
|
945
|
-
) {
|
|
946
|
-
return result;
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
if (value === null) {
|
|
950
|
-
return [...result, [encode(key, options), '[', index, ']'].join('')];
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
return [
|
|
954
|
-
...result,
|
|
955
|
-
[encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join('')
|
|
956
|
-
];
|
|
957
|
-
};
|
|
958
|
-
|
|
959
|
-
case 'bracket':
|
|
960
|
-
return key => (result, value) => {
|
|
961
|
-
if (
|
|
962
|
-
value === undefined ||
|
|
963
|
-
(options.skipNull && value === null) ||
|
|
964
|
-
(options.skipEmptyString && value === '')
|
|
965
|
-
) {
|
|
966
|
-
return result;
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
if (value === null) {
|
|
970
|
-
return [...result, [encode(key, options), '[]'].join('')];
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
return [...result, [encode(key, options), '[]=', encode(value, options)].join('')];
|
|
974
|
-
};
|
|
975
|
-
|
|
976
|
-
case 'comma':
|
|
977
|
-
case 'separator':
|
|
978
|
-
return key => (result, value) => {
|
|
979
|
-
if (value === null || value === undefined || value.length === 0) {
|
|
980
|
-
return result;
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
if (result.length === 0) {
|
|
984
|
-
return [[encode(key, options), '=', encode(value, options)].join('')];
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
|
|
988
|
-
};
|
|
989
|
-
|
|
990
|
-
default:
|
|
991
|
-
return key => (result, value) => {
|
|
992
|
-
if (
|
|
993
|
-
value === undefined ||
|
|
994
|
-
(options.skipNull && value === null) ||
|
|
995
|
-
(options.skipEmptyString && value === '')
|
|
996
|
-
) {
|
|
997
|
-
return result;
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
if (value === null) {
|
|
1001
|
-
return [...result, encode(key, options)];
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
return [...result, [encode(key, options), '=', encode(value, options)].join('')];
|
|
1005
|
-
};
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
function parserForArrayFormat(options) {
|
|
1010
|
-
let result;
|
|
1011
|
-
|
|
1012
|
-
switch (options.arrayFormat) {
|
|
1013
|
-
case 'index':
|
|
1014
|
-
return (key, value, accumulator) => {
|
|
1015
|
-
result = /\[(\d*)\]$/.exec(key);
|
|
1016
|
-
|
|
1017
|
-
key = key.replace(/\[\d*\]$/, '');
|
|
1018
|
-
|
|
1019
|
-
if (!result) {
|
|
1020
|
-
accumulator[key] = value;
|
|
1021
|
-
return;
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
if (accumulator[key] === undefined) {
|
|
1025
|
-
accumulator[key] = {};
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
accumulator[key][result[1]] = value;
|
|
1029
|
-
};
|
|
1030
|
-
|
|
1031
|
-
case 'bracket':
|
|
1032
|
-
return (key, value, accumulator) => {
|
|
1033
|
-
result = /(\[\])$/.exec(key);
|
|
1034
|
-
key = key.replace(/\[\]$/, '');
|
|
1035
|
-
|
|
1036
|
-
if (!result) {
|
|
1037
|
-
accumulator[key] = value;
|
|
1038
|
-
return;
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
if (accumulator[key] === undefined) {
|
|
1042
|
-
accumulator[key] = [value];
|
|
1043
|
-
return;
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
accumulator[key] = [].concat(accumulator[key], value);
|
|
1047
|
-
};
|
|
1048
|
-
|
|
1049
|
-
case 'comma':
|
|
1050
|
-
case 'separator':
|
|
1051
|
-
return (key, value, accumulator) => {
|
|
1052
|
-
const isArray = typeof value === 'string' && value.split('').indexOf(options.arrayFormatSeparator) > -1;
|
|
1053
|
-
const newValue = isArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options);
|
|
1054
|
-
accumulator[key] = newValue;
|
|
1055
|
-
};
|
|
1056
|
-
|
|
1057
|
-
default:
|
|
1058
|
-
return (key, value, accumulator) => {
|
|
1059
|
-
if (accumulator[key] === undefined) {
|
|
1060
|
-
accumulator[key] = value;
|
|
1061
|
-
return;
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
accumulator[key] = [].concat(accumulator[key], value);
|
|
1065
|
-
};
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
function validateArrayFormatSeparator(value) {
|
|
1070
|
-
if (typeof value !== 'string' || value.length !== 1) {
|
|
1071
|
-
throw new TypeError('arrayFormatSeparator must be single character string');
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
function encode(value, options) {
|
|
1076
|
-
if (options.encode) {
|
|
1077
|
-
return options.strict ? strictUriEncode$1(value) : encodeURIComponent(value);
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
return value;
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
function decode(value, options) {
|
|
1084
|
-
if (options.decode) {
|
|
1085
|
-
return decodeComponent(value);
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
return value;
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
function keysSorter(input) {
|
|
1092
|
-
if (Array.isArray(input)) {
|
|
1093
|
-
return input.sort();
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
if (typeof input === 'object') {
|
|
1097
|
-
return keysSorter(Object.keys(input))
|
|
1098
|
-
.sort((a, b) => Number(a) - Number(b))
|
|
1099
|
-
.map(key => input[key]);
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
return input;
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
function removeHash(input) {
|
|
1106
|
-
const hashStart = input.indexOf('#');
|
|
1107
|
-
if (hashStart !== -1) {
|
|
1108
|
-
input = input.slice(0, hashStart);
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
return input;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
function getHash(url) {
|
|
1115
|
-
let hash = '';
|
|
1116
|
-
const hashStart = url.indexOf('#');
|
|
1117
|
-
if (hashStart !== -1) {
|
|
1118
|
-
hash = url.slice(hashStart);
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
return hash;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
function extract(input) {
|
|
1125
|
-
input = removeHash(input);
|
|
1126
|
-
const queryStart = input.indexOf('?');
|
|
1127
|
-
if (queryStart === -1) {
|
|
1128
|
-
return '';
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
return input.slice(queryStart + 1);
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
function parseValue(value, options) {
|
|
1135
|
-
if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
|
|
1136
|
-
value = Number(value);
|
|
1137
|
-
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
|
|
1138
|
-
value = value.toLowerCase() === 'true';
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
return value;
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
function parse(input, options) {
|
|
1145
|
-
options = Object.assign({
|
|
1146
|
-
decode: true,
|
|
1147
|
-
sort: true,
|
|
1148
|
-
arrayFormat: 'none',
|
|
1149
|
-
arrayFormatSeparator: ',',
|
|
1150
|
-
parseNumbers: false,
|
|
1151
|
-
parseBooleans: false
|
|
1152
|
-
}, options);
|
|
1153
|
-
|
|
1154
|
-
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
1155
|
-
|
|
1156
|
-
const formatter = parserForArrayFormat(options);
|
|
1157
|
-
|
|
1158
|
-
// Create an object with no prototype
|
|
1159
|
-
const ret = Object.create(null);
|
|
1160
|
-
|
|
1161
|
-
if (typeof input !== 'string') {
|
|
1162
|
-
return ret;
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
input = input.trim().replace(/^[?#&]/, '');
|
|
1166
|
-
|
|
1167
|
-
if (!input) {
|
|
1168
|
-
return ret;
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
for (const param of input.split('&')) {
|
|
1172
|
-
let [key, value] = splitOnFirst$1(options.decode ? param.replace(/\+/g, ' ') : param, '=');
|
|
1173
|
-
|
|
1174
|
-
// Missing `=` should be `null`:
|
|
1175
|
-
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
|
|
1176
|
-
value = value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? value : decode(value, options);
|
|
1177
|
-
formatter(decode(key, options), value, ret);
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
for (const key of Object.keys(ret)) {
|
|
1181
|
-
const value = ret[key];
|
|
1182
|
-
if (typeof value === 'object' && value !== null) {
|
|
1183
|
-
for (const k of Object.keys(value)) {
|
|
1184
|
-
value[k] = parseValue(value[k], options);
|
|
1185
|
-
}
|
|
1186
|
-
} else {
|
|
1187
|
-
ret[key] = parseValue(value, options);
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
if (options.sort === false) {
|
|
1192
|
-
return ret;
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce((result, key) => {
|
|
1196
|
-
const value = ret[key];
|
|
1197
|
-
if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) {
|
|
1198
|
-
// Sort object keys, not values
|
|
1199
|
-
result[key] = keysSorter(value);
|
|
1200
|
-
} else {
|
|
1201
|
-
result[key] = value;
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
return result;
|
|
1205
|
-
}, Object.create(null));
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
exports.extract = extract;
|
|
1209
|
-
exports.parse = parse;
|
|
1210
|
-
|
|
1211
|
-
exports.stringify = (object, options) => {
|
|
1212
|
-
if (!object) {
|
|
1213
|
-
return '';
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
options = Object.assign({
|
|
1217
|
-
encode: true,
|
|
1218
|
-
strict: true,
|
|
1219
|
-
arrayFormat: 'none',
|
|
1220
|
-
arrayFormatSeparator: ','
|
|
1221
|
-
}, options);
|
|
1222
|
-
|
|
1223
|
-
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
1224
|
-
|
|
1225
|
-
const shouldFilter = key => (
|
|
1226
|
-
(options.skipNull && isNullOrUndefined(object[key])) ||
|
|
1227
|
-
(options.skipEmptyString && object[key] === '')
|
|
1228
|
-
);
|
|
1229
|
-
|
|
1230
|
-
const formatter = encoderForArrayFormat(options);
|
|
1231
|
-
|
|
1232
|
-
const objectCopy = {};
|
|
1233
|
-
|
|
1234
|
-
for (const key of Object.keys(object)) {
|
|
1235
|
-
if (!shouldFilter(key)) {
|
|
1236
|
-
objectCopy[key] = object[key];
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
const keys = Object.keys(objectCopy);
|
|
1241
|
-
|
|
1242
|
-
if (options.sort !== false) {
|
|
1243
|
-
keys.sort(options.sort);
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
return keys.map(key => {
|
|
1247
|
-
const value = object[key];
|
|
1248
|
-
|
|
1249
|
-
if (value === undefined) {
|
|
1250
|
-
return '';
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
if (value === null) {
|
|
1254
|
-
return encode(key, options);
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
if (Array.isArray(value)) {
|
|
1258
|
-
return value
|
|
1259
|
-
.reduce(formatter(key), [])
|
|
1260
|
-
.join('&');
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
return encode(key, options) + '=' + encode(value, options);
|
|
1264
|
-
}).filter(x => x.length > 0).join('&');
|
|
1265
|
-
};
|
|
1266
|
-
|
|
1267
|
-
exports.parseUrl = (input, options) => {
|
|
1268
|
-
return {
|
|
1269
|
-
url: removeHash(input).split('?')[0] || '',
|
|
1270
|
-
query: parse(extract(input), options)
|
|
1271
|
-
};
|
|
1272
|
-
};
|
|
1273
|
-
|
|
1274
|
-
exports.stringifyUrl = (input, options) => {
|
|
1275
|
-
const url = removeHash(input.url).split('?')[0] || '';
|
|
1276
|
-
const queryFromUrl = exports.extract(input.url);
|
|
1277
|
-
const parsedQueryFromUrl = exports.parse(queryFromUrl);
|
|
1278
|
-
const hash = getHash(input.url);
|
|
1279
|
-
const query = Object.assign(parsedQueryFromUrl, input.query);
|
|
1280
|
-
let queryString = exports.stringify(query, options);
|
|
1281
|
-
if (queryString) {
|
|
1282
|
-
queryString = `?${queryString}`;
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
return `${url}${queryString}${hash}`;
|
|
1286
|
-
};
|
|
1287
|
-
} (queryString));
|
|
1288
|
-
|
|
1289
|
-
export { domtoimage as d, fileDownload as f, queryString as q };
|