@carbon/charts 1.7.0 → 1.7.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.
- package/CHANGELOG.md +11 -0
- package/build/src/components/diagrams/buildPaths.d.ts +27 -3
- package/build/src/components/graphs/bubble.d.ts +1 -1
- package/build/src/components/graphs/wordcloud.d.ts +1 -1
- package/build/src/services/scales-cartesian.d.ts +1 -1
- package/bundle.js +3 -1
- package/components/essentials/threshold.js +2 -0
- package/components/essentials/threshold.js.map +1 -1
- package/components/essentials/tooltip.js +2 -0
- package/components/essentials/tooltip.js.map +1 -1
- package/components/graphs/bubble.d.ts +1 -1
- package/components/graphs/wordcloud.d.ts +1 -1
- package/demo/data/bundle.js +1 -1
- package/demo/styles.css +5813 -3083
- package/demo/styles.css.map +1 -1
- package/demo/styles.min.css +1 -1
- package/demo/styles.min.css.map +1 -1
- package/demo/tsconfig.tsbuildinfo +757 -1537
- package/package.json +15 -14
- package/services/essentials/dom-utils.js +1 -1
- package/services/essentials/dom-utils.js.map +1 -1
- package/styles.css +89 -37
- package/styles.css.map +1 -1
- package/styles.min.css +1 -1
- package/styles.min.css.map +1 -1
- package/tsconfig.tsbuildinfo +826 -2096
- package/services/essentials/dom-to-image.d.ts +0 -120
- package/services/essentials/dom-to-image.js +0 -720
- package/services/essentials/dom-to-image.js.map +0 -1
|
@@ -1,720 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
The MIT License (MIT)
|
|
3
|
-
|
|
4
|
-
Copyright 2015 Anatolii Saienko
|
|
5
|
-
https://github.com/tsayen
|
|
6
|
-
|
|
7
|
-
Copyright 2012 Paul Bakaus
|
|
8
|
-
http://paulbakaus.com/
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
11
|
-
a copy of this software and associated documentation files (the
|
|
12
|
-
"Software"), to deal in the Software without restriction, including
|
|
13
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
14
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
15
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
16
|
-
the following conditions:
|
|
17
|
-
|
|
18
|
-
The above copyright notice and this permission notice shall be
|
|
19
|
-
included in all copies or substantial portions of the Software.
|
|
20
|
-
|
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
22
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
23
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
24
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
25
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
27
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
*/
|
|
29
|
-
(function (global) {
|
|
30
|
-
'use strict';
|
|
31
|
-
var util = newUtil();
|
|
32
|
-
var inliner = newInliner();
|
|
33
|
-
var fontFaces = newFontFaces();
|
|
34
|
-
var images = newImages();
|
|
35
|
-
// Default impl options
|
|
36
|
-
var defaultOptions = {
|
|
37
|
-
// Default is to fail on error, no placeholder
|
|
38
|
-
imagePlaceholder: undefined,
|
|
39
|
-
// Default cache bust is false, it will use the cache
|
|
40
|
-
cacheBust: false,
|
|
41
|
-
};
|
|
42
|
-
var domtoimage = {
|
|
43
|
-
toSvg: toSvg,
|
|
44
|
-
toPng: toPng,
|
|
45
|
-
toJpeg: toJpeg,
|
|
46
|
-
toBlob: toBlob,
|
|
47
|
-
toPixelData: toPixelData,
|
|
48
|
-
impl: {
|
|
49
|
-
fontFaces: fontFaces,
|
|
50
|
-
images: images,
|
|
51
|
-
util: util,
|
|
52
|
-
inliner: inliner,
|
|
53
|
-
options: {},
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
if (typeof module !== 'undefined')
|
|
57
|
-
module.exports = domtoimage;
|
|
58
|
-
else
|
|
59
|
-
global.domtoimage = domtoimage;
|
|
60
|
-
/**
|
|
61
|
-
* @param {Node} node - The DOM Node object to render
|
|
62
|
-
* @param {Object} options - Rendering options
|
|
63
|
-
* @param {Function} options.filter - Should return true if passed node should be included in the output
|
|
64
|
-
* (excluding node means excluding it's children as well). Not called on the root node.
|
|
65
|
-
* @param {String} options.bgcolor - color for the background, any valid CSS color value.
|
|
66
|
-
* @param {Number} options.width - width to be applied to node before rendering.
|
|
67
|
-
* @param {Number} options.height - height to be applied to node before rendering.
|
|
68
|
-
* @param {Object} options.style - an object whose properties to be copied to node's style before rendering.
|
|
69
|
-
* @param {Number} options.quality - a Number between 0 and 1 indicating image quality (applicable to JPEG only),
|
|
70
|
-
defaults to 1.0.
|
|
71
|
-
* @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
|
|
72
|
-
* @param {Boolean} options.cacheBust - set to true to cache bust by appending the time to the request url
|
|
73
|
-
* @return {Promise} - A promise that is fulfilled with a SVG image data URL
|
|
74
|
-
* */
|
|
75
|
-
function toSvg(node, options) {
|
|
76
|
-
options = options || {};
|
|
77
|
-
copyOptions(options);
|
|
78
|
-
return Promise.resolve(node)
|
|
79
|
-
.then(function (node) {
|
|
80
|
-
return cloneNode(node, options.filter, true);
|
|
81
|
-
})
|
|
82
|
-
.then(embedFonts)
|
|
83
|
-
.then(inlineImages)
|
|
84
|
-
.then(applyOptions)
|
|
85
|
-
.then(function (clone) {
|
|
86
|
-
return makeSvgDataUri(clone, options.width || util.width(node), options.height || util.height(node));
|
|
87
|
-
});
|
|
88
|
-
function applyOptions(clone) {
|
|
89
|
-
if (options.bgcolor)
|
|
90
|
-
clone.style.backgroundColor = options.bgcolor;
|
|
91
|
-
if (options.width)
|
|
92
|
-
clone.style.width = options.width + 'px';
|
|
93
|
-
if (options.height)
|
|
94
|
-
clone.style.height = options.height + 'px';
|
|
95
|
-
if (options.style)
|
|
96
|
-
Object.keys(options.style).forEach(function (property) {
|
|
97
|
-
clone.style[property] = options.style[property];
|
|
98
|
-
});
|
|
99
|
-
return clone;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* @param {Node} node - The DOM Node object to render
|
|
104
|
-
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
105
|
-
* @return {Promise} - A promise that is fulfilled with a Uint8Array containing RGBA pixel data.
|
|
106
|
-
* */
|
|
107
|
-
function toPixelData(node, options) {
|
|
108
|
-
return draw(node, options || {}).then(function (canvas) {
|
|
109
|
-
return canvas
|
|
110
|
-
.getContext('2d')
|
|
111
|
-
.getImageData(0, 0, util.width(node), util.height(node)).data;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* @param {Node} node - The DOM Node object to render
|
|
116
|
-
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
117
|
-
* @return {Promise} - A promise that is fulfilled with a PNG image data URL
|
|
118
|
-
* */
|
|
119
|
-
function toPng(node, options) {
|
|
120
|
-
return draw(node, options || {}).then(function (canvas) {
|
|
121
|
-
return canvas.toDataURL();
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* @param {Node} node - The DOM Node object to render
|
|
126
|
-
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
127
|
-
* @return {Promise} - A promise that is fulfilled with a JPEG image data URL
|
|
128
|
-
* */
|
|
129
|
-
function toJpeg(node, options) {
|
|
130
|
-
options = options || {};
|
|
131
|
-
return draw(node, options).then(function (canvas) {
|
|
132
|
-
return canvas.toDataURL('image/jpeg', options.quality || 1.0);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* @param {Node} node - The DOM Node object to render
|
|
137
|
-
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
138
|
-
* @return {Promise} - A promise that is fulfilled with a PNG image blob
|
|
139
|
-
* */
|
|
140
|
-
function toBlob(node, options) {
|
|
141
|
-
return draw(node, options || {}).then(util.canvasToBlob);
|
|
142
|
-
}
|
|
143
|
-
function copyOptions(options) {
|
|
144
|
-
// Copy options to impl options for use in impl
|
|
145
|
-
if (typeof options.imagePlaceholder === 'undefined') {
|
|
146
|
-
domtoimage.impl.options.imagePlaceholder =
|
|
147
|
-
defaultOptions.imagePlaceholder;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
domtoimage.impl.options.imagePlaceholder = options.imagePlaceholder;
|
|
151
|
-
}
|
|
152
|
-
if (typeof options.cacheBust === 'undefined') {
|
|
153
|
-
domtoimage.impl.options.cacheBust = defaultOptions.cacheBust;
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
domtoimage.impl.options.cacheBust = options.cacheBust;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function draw(domNode, options) {
|
|
160
|
-
return toSvg(domNode, options)
|
|
161
|
-
.then(util.makeImage)
|
|
162
|
-
.then(util.delay(100))
|
|
163
|
-
.then(function (image) {
|
|
164
|
-
var canvas = newCanvas(domNode);
|
|
165
|
-
canvas.getContext('2d').drawImage(image, 0, 0);
|
|
166
|
-
return canvas;
|
|
167
|
-
});
|
|
168
|
-
function newCanvas(domNode) {
|
|
169
|
-
var canvas = document.createElement('canvas');
|
|
170
|
-
canvas.width = options.width || util.width(domNode);
|
|
171
|
-
canvas.height = options.height || util.height(domNode);
|
|
172
|
-
if (options.bgcolor) {
|
|
173
|
-
var ctx = canvas.getContext('2d');
|
|
174
|
-
ctx.fillStyle = options.bgcolor;
|
|
175
|
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
176
|
-
}
|
|
177
|
-
return canvas;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
function cloneNode(node, filter, root) {
|
|
181
|
-
if (!root && filter && !filter(node))
|
|
182
|
-
return Promise.resolve();
|
|
183
|
-
return Promise.resolve(node)
|
|
184
|
-
.then(makeNodeCopy)
|
|
185
|
-
.then(function (clone) {
|
|
186
|
-
return cloneChildren(node, clone, filter);
|
|
187
|
-
})
|
|
188
|
-
.then(function (clone) {
|
|
189
|
-
return processClone(node, clone);
|
|
190
|
-
});
|
|
191
|
-
function makeNodeCopy(node) {
|
|
192
|
-
if (node instanceof HTMLCanvasElement)
|
|
193
|
-
return util.makeImage(node.toDataURL());
|
|
194
|
-
return node.cloneNode(false);
|
|
195
|
-
}
|
|
196
|
-
function cloneChildren(original, clone, filter) {
|
|
197
|
-
var children = original.childNodes;
|
|
198
|
-
if (children.length === 0)
|
|
199
|
-
return Promise.resolve(clone);
|
|
200
|
-
return cloneChildrenInOrder(clone, util.asArray(children), filter).then(function () {
|
|
201
|
-
return clone;
|
|
202
|
-
});
|
|
203
|
-
function cloneChildrenInOrder(parent, children, filter) {
|
|
204
|
-
var done = Promise.resolve();
|
|
205
|
-
children.forEach(function (child) {
|
|
206
|
-
done = done
|
|
207
|
-
.then(function () {
|
|
208
|
-
return cloneNode(child, filter);
|
|
209
|
-
})
|
|
210
|
-
.then(function (childClone) {
|
|
211
|
-
if (childClone)
|
|
212
|
-
parent.appendChild(childClone);
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
return done;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
function processClone(original, clone) {
|
|
219
|
-
if (!(clone instanceof Element))
|
|
220
|
-
return clone;
|
|
221
|
-
return Promise.resolve()
|
|
222
|
-
.then(cloneStyle)
|
|
223
|
-
.then(clonePseudoElements)
|
|
224
|
-
.then(copyUserInput)
|
|
225
|
-
.then(fixSvg)
|
|
226
|
-
.then(function () {
|
|
227
|
-
return clone;
|
|
228
|
-
});
|
|
229
|
-
function cloneStyle() {
|
|
230
|
-
copyStyle(window.getComputedStyle(original), clone.style);
|
|
231
|
-
function copyStyle(source, target) {
|
|
232
|
-
if (source.cssText)
|
|
233
|
-
target.cssText = source.cssText;
|
|
234
|
-
else
|
|
235
|
-
copyProperties(source, target);
|
|
236
|
-
function copyProperties(source, target) {
|
|
237
|
-
util.asArray(source).forEach(function (name) {
|
|
238
|
-
target.setProperty(name, source.getPropertyValue(name), source.getPropertyPriority(name));
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
function clonePseudoElements() {
|
|
244
|
-
[':before', ':after'].forEach(function (element) {
|
|
245
|
-
clonePseudoElement(element);
|
|
246
|
-
});
|
|
247
|
-
function clonePseudoElement(element) {
|
|
248
|
-
var style = window.getComputedStyle(original, element);
|
|
249
|
-
var content = style.getPropertyValue('content');
|
|
250
|
-
if (content === '' || content === 'none')
|
|
251
|
-
return;
|
|
252
|
-
var className = util.uid();
|
|
253
|
-
clone.className = clone.className + ' ' + className;
|
|
254
|
-
var styleElement = document.createElement('style');
|
|
255
|
-
styleElement.appendChild(formatPseudoElementStyle(className, element, style));
|
|
256
|
-
clone.appendChild(styleElement);
|
|
257
|
-
function formatPseudoElementStyle(className, element, style) {
|
|
258
|
-
var selector = '.' + className + ':' + element;
|
|
259
|
-
var cssText = style.cssText
|
|
260
|
-
? formatCssText(style)
|
|
261
|
-
: formatCssProperties(style);
|
|
262
|
-
return document.createTextNode(selector + '{' + cssText + '}');
|
|
263
|
-
function formatCssText(style) {
|
|
264
|
-
var content = style.getPropertyValue('content');
|
|
265
|
-
return style.cssText + ' content: ' + content + ';';
|
|
266
|
-
}
|
|
267
|
-
function formatCssProperties(style) {
|
|
268
|
-
return (util
|
|
269
|
-
.asArray(style)
|
|
270
|
-
.map(formatProperty)
|
|
271
|
-
.join('; ') + ';');
|
|
272
|
-
function formatProperty(name) {
|
|
273
|
-
return (name +
|
|
274
|
-
': ' +
|
|
275
|
-
style.getPropertyValue(name) +
|
|
276
|
-
(style.getPropertyPriority(name)
|
|
277
|
-
? ' !important'
|
|
278
|
-
: ''));
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
function copyUserInput() {
|
|
285
|
-
if (original instanceof HTMLTextAreaElement)
|
|
286
|
-
clone.innerHTML = original.value;
|
|
287
|
-
if (original instanceof HTMLInputElement)
|
|
288
|
-
clone.setAttribute('value', original.value);
|
|
289
|
-
}
|
|
290
|
-
function fixSvg() {
|
|
291
|
-
if (!(clone instanceof SVGElement))
|
|
292
|
-
return;
|
|
293
|
-
clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
294
|
-
if (!(clone instanceof SVGRectElement))
|
|
295
|
-
return;
|
|
296
|
-
['width', 'height'].forEach(function (attribute) {
|
|
297
|
-
var value = clone.getAttribute(attribute);
|
|
298
|
-
if (!value)
|
|
299
|
-
return;
|
|
300
|
-
clone.style.setProperty(attribute, value);
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
function embedFonts(node) {
|
|
306
|
-
return fontFaces.resolveAll().then(function (cssText) {
|
|
307
|
-
var styleNode = document.createElement('style');
|
|
308
|
-
node.appendChild(styleNode);
|
|
309
|
-
styleNode.appendChild(document.createTextNode(cssText));
|
|
310
|
-
return node;
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
function inlineImages(node) {
|
|
314
|
-
return images.inlineAll(node).then(function () {
|
|
315
|
-
return node;
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
function makeSvgDataUri(node, width, height) {
|
|
319
|
-
return Promise.resolve(node)
|
|
320
|
-
.then(function (node) {
|
|
321
|
-
node.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
|
|
322
|
-
return new XMLSerializer().serializeToString(node);
|
|
323
|
-
})
|
|
324
|
-
.then(util.escapeXhtml)
|
|
325
|
-
.then(function (xhtml) {
|
|
326
|
-
return ('<foreignObject x="0" y="0" width="100%" height="100%">' +
|
|
327
|
-
xhtml +
|
|
328
|
-
'</foreignObject>');
|
|
329
|
-
})
|
|
330
|
-
.then(function (foreignObject) {
|
|
331
|
-
return ('<svg xmlns="http://www.w3.org/2000/svg" width="' +
|
|
332
|
-
width +
|
|
333
|
-
'" height="' +
|
|
334
|
-
height +
|
|
335
|
-
'">' +
|
|
336
|
-
foreignObject +
|
|
337
|
-
'</svg>');
|
|
338
|
-
})
|
|
339
|
-
.then(function (svg) {
|
|
340
|
-
return 'data:image/svg+xml;charset=utf-8,' + svg;
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
function newUtil() {
|
|
344
|
-
return {
|
|
345
|
-
escape: escape,
|
|
346
|
-
parseExtension: parseExtension,
|
|
347
|
-
mimeType: mimeType,
|
|
348
|
-
dataAsUrl: dataAsUrl,
|
|
349
|
-
isDataUrl: isDataUrl,
|
|
350
|
-
canvasToBlob: canvasToBlob,
|
|
351
|
-
resolveUrl: resolveUrl,
|
|
352
|
-
getAndEncode: getAndEncode,
|
|
353
|
-
uid: uid(),
|
|
354
|
-
delay: delay,
|
|
355
|
-
asArray: asArray,
|
|
356
|
-
escapeXhtml: escapeXhtml,
|
|
357
|
-
makeImage: makeImage,
|
|
358
|
-
width: width,
|
|
359
|
-
height: height,
|
|
360
|
-
};
|
|
361
|
-
function mimes() {
|
|
362
|
-
/*
|
|
363
|
-
* Only WOFF and EOT mime types for fonts are 'real'
|
|
364
|
-
* see http://www.iana.org/assignments/media-types/media-types.xhtml
|
|
365
|
-
*/
|
|
366
|
-
var WOFF = 'application/font-woff';
|
|
367
|
-
var JPEG = 'image/jpeg';
|
|
368
|
-
return {
|
|
369
|
-
woff: WOFF,
|
|
370
|
-
woff2: WOFF,
|
|
371
|
-
ttf: 'application/font-truetype',
|
|
372
|
-
eot: 'application/vnd.ms-fontobject',
|
|
373
|
-
png: 'image/png',
|
|
374
|
-
jpg: JPEG,
|
|
375
|
-
jpeg: JPEG,
|
|
376
|
-
gif: 'image/gif',
|
|
377
|
-
tiff: 'image/tiff',
|
|
378
|
-
svg: 'image/svg+xml',
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
function parseExtension(url) {
|
|
382
|
-
var match = /\.([^\.\/]*?)$/g.exec(url);
|
|
383
|
-
if (match)
|
|
384
|
-
return match[1];
|
|
385
|
-
else
|
|
386
|
-
return '';
|
|
387
|
-
}
|
|
388
|
-
function mimeType(url) {
|
|
389
|
-
var extension = parseExtension(url).toLowerCase();
|
|
390
|
-
return mimes()[extension] || '';
|
|
391
|
-
}
|
|
392
|
-
function isDataUrl(url) {
|
|
393
|
-
return url.search(/^(data:)/) !== -1;
|
|
394
|
-
}
|
|
395
|
-
function toBlob(canvas) {
|
|
396
|
-
return new Promise(function (resolve) {
|
|
397
|
-
var binaryString = window.atob(canvas.toDataURL().split(',')[1]);
|
|
398
|
-
var length = binaryString.length;
|
|
399
|
-
var binaryArray = new Uint8Array(length);
|
|
400
|
-
for (var i = 0; i < length; i++)
|
|
401
|
-
binaryArray[i] = binaryString.charCodeAt(i);
|
|
402
|
-
resolve(new Blob([binaryArray], {
|
|
403
|
-
type: 'image/png',
|
|
404
|
-
}));
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
function canvasToBlob(canvas) {
|
|
408
|
-
if (canvas.toBlob)
|
|
409
|
-
return new Promise(function (resolve) {
|
|
410
|
-
canvas.toBlob(resolve);
|
|
411
|
-
});
|
|
412
|
-
return toBlob(canvas);
|
|
413
|
-
}
|
|
414
|
-
function resolveUrl(url, baseUrl) {
|
|
415
|
-
var doc = document.implementation.createHTMLDocument();
|
|
416
|
-
var base = doc.createElement('base');
|
|
417
|
-
doc.head.appendChild(base);
|
|
418
|
-
var a = doc.createElement('a');
|
|
419
|
-
doc.body.appendChild(a);
|
|
420
|
-
base.href = baseUrl;
|
|
421
|
-
a.href = url;
|
|
422
|
-
return a.href;
|
|
423
|
-
}
|
|
424
|
-
function uid() {
|
|
425
|
-
var index = 0;
|
|
426
|
-
return function () {
|
|
427
|
-
return 'u' + fourRandomChars() + index++;
|
|
428
|
-
function fourRandomChars() {
|
|
429
|
-
/* see http://stackoverflow.com/a/6248722/2519373 */
|
|
430
|
-
return ('0000' +
|
|
431
|
-
((Math.random() * Math.pow(36, 4)) << 0).toString(36)).slice(-4);
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
function makeImage(uri) {
|
|
436
|
-
return new Promise(function (resolve, reject) {
|
|
437
|
-
var image = new Image();
|
|
438
|
-
image.onload = function () {
|
|
439
|
-
resolve(image);
|
|
440
|
-
};
|
|
441
|
-
image.onerror = reject;
|
|
442
|
-
image.src = uri;
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
function getAndEncode(url) {
|
|
446
|
-
var TIMEOUT = 30000;
|
|
447
|
-
if (domtoimage.impl.options.cacheBust) {
|
|
448
|
-
// Cache bypass so we dont have CORS issues with cached images
|
|
449
|
-
// Source: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
|
|
450
|
-
url += (/\?/.test(url) ? '&' : '?') + new Date().getTime();
|
|
451
|
-
}
|
|
452
|
-
return new Promise(function (resolve) {
|
|
453
|
-
var request = new XMLHttpRequest();
|
|
454
|
-
request.onreadystatechange = done;
|
|
455
|
-
request.ontimeout = timeout;
|
|
456
|
-
request.responseType = 'blob';
|
|
457
|
-
request.timeout = TIMEOUT;
|
|
458
|
-
request.open('GET', url, true);
|
|
459
|
-
request.send();
|
|
460
|
-
var placeholder;
|
|
461
|
-
if (domtoimage.impl.options.imagePlaceholder) {
|
|
462
|
-
var split = domtoimage.impl.options.imagePlaceholder.split(/,/);
|
|
463
|
-
if (split && split[1]) {
|
|
464
|
-
placeholder = split[1];
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
function done() {
|
|
468
|
-
if (request.readyState !== 4)
|
|
469
|
-
return;
|
|
470
|
-
if (request.status !== 200) {
|
|
471
|
-
if (placeholder) {
|
|
472
|
-
resolve(placeholder);
|
|
473
|
-
}
|
|
474
|
-
else {
|
|
475
|
-
fail('cannot fetch resource: ' +
|
|
476
|
-
url +
|
|
477
|
-
', status: ' +
|
|
478
|
-
request.status);
|
|
479
|
-
}
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
var encoder = new FileReader();
|
|
483
|
-
encoder.onloadend = function () {
|
|
484
|
-
var content = encoder.result.split(/,/)[1];
|
|
485
|
-
resolve(content);
|
|
486
|
-
};
|
|
487
|
-
encoder.readAsDataURL(request.response);
|
|
488
|
-
}
|
|
489
|
-
function timeout() {
|
|
490
|
-
if (placeholder) {
|
|
491
|
-
resolve(placeholder);
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
fail('timeout of ' +
|
|
495
|
-
TIMEOUT +
|
|
496
|
-
'ms occured while fetching resource: ' +
|
|
497
|
-
url);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
function fail(message) {
|
|
501
|
-
console.error(message);
|
|
502
|
-
resolve('');
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
function dataAsUrl(content, type) {
|
|
507
|
-
return 'data:' + type + ';base64,' + content;
|
|
508
|
-
}
|
|
509
|
-
function escape(string) {
|
|
510
|
-
return string.replace(/([.*+?^${}()|\[\]\/\\])/g, '\\$1');
|
|
511
|
-
}
|
|
512
|
-
function delay(ms) {
|
|
513
|
-
return function (arg) {
|
|
514
|
-
return new Promise(function (resolve) {
|
|
515
|
-
setTimeout(function () {
|
|
516
|
-
resolve(arg);
|
|
517
|
-
}, ms);
|
|
518
|
-
});
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
function asArray(arrayLike) {
|
|
522
|
-
var array = [];
|
|
523
|
-
var length = arrayLike.length;
|
|
524
|
-
for (var i = 0; i < length; i++)
|
|
525
|
-
array.push(arrayLike[i]);
|
|
526
|
-
return array;
|
|
527
|
-
}
|
|
528
|
-
function escapeXhtml(string) {
|
|
529
|
-
return string.replace(/#/g, '%23').replace(/\n/g, '%0A');
|
|
530
|
-
}
|
|
531
|
-
function width(node) {
|
|
532
|
-
var leftBorder = px(node, 'border-left-width');
|
|
533
|
-
var rightBorder = px(node, 'border-right-width');
|
|
534
|
-
return node.scrollWidth + leftBorder + rightBorder;
|
|
535
|
-
}
|
|
536
|
-
function height(node) {
|
|
537
|
-
var topBorder = px(node, 'border-top-width');
|
|
538
|
-
var bottomBorder = px(node, 'border-bottom-width');
|
|
539
|
-
return node.scrollHeight + topBorder + bottomBorder;
|
|
540
|
-
}
|
|
541
|
-
function px(node, styleProperty) {
|
|
542
|
-
var value = window
|
|
543
|
-
.getComputedStyle(node)
|
|
544
|
-
.getPropertyValue(styleProperty);
|
|
545
|
-
return parseFloat(value.replace('px', ''));
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
function newInliner() {
|
|
549
|
-
var URL_REGEX = /url\(['"]?([^'"]+?)['"]?\)/g;
|
|
550
|
-
return {
|
|
551
|
-
inlineAll: inlineAll,
|
|
552
|
-
shouldProcess: shouldProcess,
|
|
553
|
-
impl: {
|
|
554
|
-
readUrls: readUrls,
|
|
555
|
-
inline: inline,
|
|
556
|
-
},
|
|
557
|
-
};
|
|
558
|
-
function shouldProcess(string) {
|
|
559
|
-
return string.search(URL_REGEX) !== -1;
|
|
560
|
-
}
|
|
561
|
-
function readUrls(string) {
|
|
562
|
-
var result = [];
|
|
563
|
-
var match;
|
|
564
|
-
while ((match = URL_REGEX.exec(string)) !== null) {
|
|
565
|
-
result.push(match[1]);
|
|
566
|
-
}
|
|
567
|
-
return result.filter(function (url) {
|
|
568
|
-
return !util.isDataUrl(url);
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
function inline(string, url, baseUrl, get) {
|
|
572
|
-
return Promise.resolve(url)
|
|
573
|
-
.then(function (url) {
|
|
574
|
-
return baseUrl ? util.resolveUrl(url, baseUrl) : url;
|
|
575
|
-
})
|
|
576
|
-
.then(get || util.getAndEncode)
|
|
577
|
-
.then(function (data) {
|
|
578
|
-
return util.dataAsUrl(data, util.mimeType(url));
|
|
579
|
-
})
|
|
580
|
-
.then(function (dataUrl) {
|
|
581
|
-
return string.replace(urlAsRegex(url), '$1' + dataUrl + '$3');
|
|
582
|
-
});
|
|
583
|
-
function urlAsRegex(url) {
|
|
584
|
-
return new RegExp('(url\\([\'"]?)(' + util.escape(url) + ')([\'"]?\\))', 'g');
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
function inlineAll(string, baseUrl, get) {
|
|
588
|
-
if (nothingToInline())
|
|
589
|
-
return Promise.resolve(string);
|
|
590
|
-
return Promise.resolve(string)
|
|
591
|
-
.then(readUrls)
|
|
592
|
-
.then(function (urls) {
|
|
593
|
-
var done = Promise.resolve(string);
|
|
594
|
-
urls.forEach(function (url) {
|
|
595
|
-
done = done.then(function (string) {
|
|
596
|
-
return inline(string, url, baseUrl, get);
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
return done;
|
|
600
|
-
});
|
|
601
|
-
function nothingToInline() {
|
|
602
|
-
return !shouldProcess(string);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
function newFontFaces() {
|
|
607
|
-
return {
|
|
608
|
-
resolveAll: resolveAll,
|
|
609
|
-
impl: {
|
|
610
|
-
readAll: readAll,
|
|
611
|
-
},
|
|
612
|
-
};
|
|
613
|
-
function resolveAll() {
|
|
614
|
-
return readAll(document)
|
|
615
|
-
.then(function (webFonts) {
|
|
616
|
-
return Promise.all(webFonts.map(function (webFont) {
|
|
617
|
-
return webFont.resolve();
|
|
618
|
-
}));
|
|
619
|
-
})
|
|
620
|
-
.then(function (cssStrings) {
|
|
621
|
-
return cssStrings.join('\n');
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
function readAll() {
|
|
625
|
-
return Promise.resolve(util.asArray(document.styleSheets))
|
|
626
|
-
.then(getCssRules)
|
|
627
|
-
.then(selectWebFontRules)
|
|
628
|
-
.then(function (rules) {
|
|
629
|
-
return rules.map(newWebFont);
|
|
630
|
-
});
|
|
631
|
-
function selectWebFontRules(cssRules) {
|
|
632
|
-
return cssRules
|
|
633
|
-
.filter(function (rule) {
|
|
634
|
-
return rule.type === CSSRule.FONT_FACE_RULE;
|
|
635
|
-
})
|
|
636
|
-
.filter(function (rule) {
|
|
637
|
-
return inliner.shouldProcess(rule.style.getPropertyValue('src'));
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
function getCssRules(styleSheets) {
|
|
641
|
-
var cssRules = [];
|
|
642
|
-
styleSheets.forEach(function (sheet) {
|
|
643
|
-
try {
|
|
644
|
-
util.asArray(sheet.cssRules || []).forEach(cssRules.push.bind(cssRules));
|
|
645
|
-
}
|
|
646
|
-
catch (e) {
|
|
647
|
-
console.log('Error while reading CSS rules from ' + sheet.href, e.toString());
|
|
648
|
-
}
|
|
649
|
-
});
|
|
650
|
-
return cssRules;
|
|
651
|
-
}
|
|
652
|
-
function newWebFont(webFontRule) {
|
|
653
|
-
return {
|
|
654
|
-
resolve: function resolve() {
|
|
655
|
-
var baseUrl = (webFontRule.parentStyleSheet || {}).href;
|
|
656
|
-
return inliner.inlineAll(webFontRule.cssText, baseUrl);
|
|
657
|
-
},
|
|
658
|
-
src: function () {
|
|
659
|
-
return webFontRule.style.getPropertyValue('src');
|
|
660
|
-
},
|
|
661
|
-
};
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
function newImages() {
|
|
666
|
-
return {
|
|
667
|
-
inlineAll: inlineAll,
|
|
668
|
-
impl: {
|
|
669
|
-
newImage: newImage,
|
|
670
|
-
},
|
|
671
|
-
};
|
|
672
|
-
function newImage(element) {
|
|
673
|
-
return {
|
|
674
|
-
inline: inline,
|
|
675
|
-
};
|
|
676
|
-
function inline(get) {
|
|
677
|
-
if (util.isDataUrl(element.src))
|
|
678
|
-
return Promise.resolve();
|
|
679
|
-
return Promise.resolve(element.src)
|
|
680
|
-
.then(get || util.getAndEncode)
|
|
681
|
-
.then(function (data) {
|
|
682
|
-
return util.dataAsUrl(data, util.mimeType(element.src));
|
|
683
|
-
})
|
|
684
|
-
.then(function (dataUrl) {
|
|
685
|
-
return new Promise(function (resolve, reject) {
|
|
686
|
-
element.onload = resolve;
|
|
687
|
-
element.onerror = reject;
|
|
688
|
-
element.src = dataUrl;
|
|
689
|
-
});
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
function inlineAll(node) {
|
|
694
|
-
if (!(node instanceof Element))
|
|
695
|
-
return Promise.resolve(node);
|
|
696
|
-
return inlineBackground(node).then(function () {
|
|
697
|
-
if (node instanceof HTMLImageElement)
|
|
698
|
-
return newImage(node).inline();
|
|
699
|
-
else
|
|
700
|
-
return Promise.all(util.asArray(node.childNodes).map(function (child) {
|
|
701
|
-
return inlineAll(child);
|
|
702
|
-
}));
|
|
703
|
-
});
|
|
704
|
-
function inlineBackground(node) {
|
|
705
|
-
var background = node.style.getPropertyValue('background');
|
|
706
|
-
if (!background)
|
|
707
|
-
return Promise.resolve(node);
|
|
708
|
-
return inliner
|
|
709
|
-
.inlineAll(background)
|
|
710
|
-
.then(function (inlined) {
|
|
711
|
-
node.style.setProperty('background', inlined, node.style.getPropertyPriority('background'));
|
|
712
|
-
})
|
|
713
|
-
.then(function () {
|
|
714
|
-
return node;
|
|
715
|
-
});
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
})(this);
|
|
720
|
-
//# sourceMappingURL=../../../src/services/essentials/dom-to-image.js.map
|