Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Bug] fix image export failing (#155)

Shan Hef55c7ee613d5
diff --git a/.gitignore b/.gitignore
index 77c597679..8335d325c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@ node_modules/
coverage/
.nyc_output/
dist/
+*/**/dist/
*/**/yarn.lock
yarn-error.log
diff --git a/examples/demo-app/index.html b/examples/demo-app/index.html
index e3473055d..f3daab553 100644
--- a/examples/demo-app/index.html
+++ b/examples/demo-app/index.html
@@ -3,8 +3,8 @@
<head>
<meta charset='UTF-8' />
<title>kepler.gl demo</title>
- <link href="https://d1a3f4spazzrp4.cloudfront.net/uber-fonts/4.0.0/superfine.css" rel="stylesheet">
- <link href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.42.0/mapbox-gl.css" rel="stylesheet">
+ <link href="//d1a3f4spazzrp4.cloudfront.net/uber-fonts/4.0.0/superfine.css" rel="stylesheet">
+ <link href="//api.tiles.mapbox.com/mapbox-gl-js/v0.42.0/mapbox-gl.css" rel="stylesheet">
<style type="text/css">
body {margin: 0; padding: 0; overflow: hidden;}
</style>
diff --git a/examples/demo-app/package.json b/examples/demo-app/package.json
index e231ff64f..c4d786f32 100644
--- a/examples/demo-app/package.json
+++ b/examples/demo-app/package.json
@@ -7,7 +7,7 @@
"dependencies": {
"d3-request": "^1.0.6",
"global": "^4.3.0",
- "kepler.gl": "^0.0.22",
+ "kepler.gl": "^0.0.23",
"lodash.debounce": "^4.0.8",
"react": "^15.3.1",
"react-dom": "^15.6.1",
diff --git a/examples/open-modal/package.json b/examples/open-modal/package.json
index 40e694fb8..3cf87178b 100644
--- a/examples/open-modal/package.json
+++ b/examples/open-modal/package.json
@@ -6,7 +6,7 @@
},
"dependencies": {
"global": "^4.3.0",
- "kepler.gl": "^0.0.22",
+ "kepler.gl": "^0.0.23",
"react": "^15.3.1",
"react-dom": "^15.6.1",
"react-modal": "^3.1.10",
diff --git a/package.json b/package.json
index 412a3e231..887c14054 100644
--- a/package.json
+++ b/package.json
@@ -70,7 +70,6 @@
"d3-request": "^1.0.6",
"d3-scale": "^1.0.6",
"deck.gl": "4.1.6",
- "dom-to-image": "github:heshan0131/dom-to-image",
"fuzzy": "^0.1.3",
"global": "^4.3.0",
"keymirror": "^0.1.1",
diff --git a/src/components/common/logo.js b/src/components/common/logo.js
index 64d14d7a1..9481f538a 100644
--- a/src/components/common/logo.js
+++ b/src/components/common/logo.js
@@ -64,7 +64,7 @@ const LogoSvg = () => (
</svg>
);
-const KeplerGlLogo = ({appName=KEPLER_GL_NAME, version=KEPLER_GL_VERSION}) => (
+const KeplerGlLogo = ({appName = KEPLER_GL_NAME, version = KEPLER_GL_VERSION}) => (
<LogoWrapper className="side-panel-logo">
<LogoSvgWrapper>
<LogoSvg />
diff --git a/src/components/map/map-control.js b/src/components/map/map-control.js
index fd8aae171..5b1d18832 100644
--- a/src/components/map/map-control.js
+++ b/src/components/map/map-control.js
@@ -310,7 +310,7 @@ const MapControlPanel = ({children, header, onClick, scale = 1, isExport}) => (
>
<StyledMapControlPanelHeader style={{position: 'relative'}}>
{isExport ? (
- <KeplerGlLogo version={false} />
+ <KeplerGlLogo version={false} appName="kepler.gl"/>
) : (
<span style={{verticalAlign: 'middle'}}>{header}</span>
)}
diff --git a/src/utils/dom-to-image.js b/src/utils/dom-to-image.js
new file mode 100644
index 000000000..1fafd703f
--- /dev/null
+++ b/src/utils/dom-to-image.js
@@ -0,0 +1,868 @@
+// Copyright (c) 2018 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+/**
+ * This file is copied from https://github.com/tsayen/dom-to-image
+ * Modified by heshan0131 to allow loading external stylesheets and inline webfonts
+ */
+
+import window, {
+ Blob,
+ Image,
+ XMLHttpRequest,
+ FileReader,
+ setTimeout,
+ HTMLInputElement,
+ HTMLTextAreaElement,
+ HTMLCanvasElement,
+ SVGElement,
+ Element,
+ HTMLImageElement,
+ SVGRectElement,
+ document,
+ XMLSerializer,
+ console,
+ CSSRule,
+ fetch
+} from 'global/window';
+
+const util = newUtil();
+const inliner = newInliner();
+const fontFaces = newFontFaces();
+const images = newImages();
+
+// Default impl options
+const defaultOptions = {
+ // Default is to fail on error, no placeholder
+ imagePlaceholder: undefined,
+ // Default cache bust is false, it will use the cache
+ cacheBust: false
+};
+
+const domtoimage = {
+ toSvg,
+ toPng,
+ toJpeg,
+ toBlob,
+ toPixelData,
+ impl: {
+ fontFaces,
+ images,
+ util,
+ inliner,
+ options: {}
+ }
+};
+
+/**
+ * @param {Node} node - The DOM Node object to render
+ * @param {Object} options - Rendering options
+ * @param {Function} options.filter - Should return true if passed node should be included in the output
+ * (excluding node means excluding it's children as well). Not called on the root node.
+ * @param {String} options.bgcolor - color for the background, any valid CSS color value.
+ * @param {Number} options.width - width to be applied to node before rendering.
+ * @param {Number} options.height - height to be applied to node before rendering.
+ * @param {Object} options.style - an object whose properties to be copied to node's style before rendering.
+ * @param {Number} options.quality - a Number between 0 and 1 indicating image quality (applicable to JPEG only),
+ defaults to 1.0.
+ * @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
+ * @param {Boolean} options.cacheBust - set to true to cache bust by appending the time to the request url
+ * @return {Promise} - A promise that is fulfilled with a SVG image data URL
+ * */
+function toSvg(node, options) {
+ options = options || {};
+ copyOptions(options);
+ return Promise.resolve(node)
+ .then(nd => cloneNode(nd, options.filter, true))
+ .then(embedFonts)
+ .then(inlineImages)
+ .then(applyOptions)
+ .then(clone =>
+ makeSvgDataUri(
+ clone,
+ options.width || util.width(node),
+ options.height || util.height(node)
+ )
+ );
+
+ function applyOptions(clone) {
+ if (options.bgcolor) clone.style.backgroundColor = options.bgcolor;
+
+ if (options.width) clone.style.width = `${options.width}px`;
+ if (options.height) clone.style.height = `${options.height}px`;
+
+ if (options.style)
+ Object.keys(options.style).forEach((property) => {
+ clone.style[property] = options.style[property];
+ });
+
+ return clone;
+ }
+}
+
+/**
+ * @param {Node} node - The DOM Node object to render
+ * @param {Object} options - Rendering options, @see {@link toSvg}
+ * @return {Promise} - A promise that is fulfilled with a Uint8Array containing RGBA pixel data.
+ * */
+function toPixelData(node, options) {
+ return draw(node, options || {}).then(canvas =>
+ canvas
+ .getContext('2d')
+ .getImageData(0, 0, util.width(node), util.height(node)).data
+ );
+}
+
+/**
+ * @param {Node} node - The DOM Node object to render
+ * @param {Object} options - Rendering options, @see {@link toSvg}
+ * @return {Promise} - A promise that is fulfilled with a PNG image data URL
+ * */
+function toPng(node, options) {
+ return draw(node, options || {}).then(canvas => canvas.toDataURL());
+}
+
+/**
+ * @param {Node} node - The DOM Node object to render
+ * @param {Object} options - Rendering options, @see {@link toSvg}
+ * @return {Promise} - A promise that is fulfilled with a JPEG image data URL
+ * */
+function toJpeg(node, options) {
+ options = options || {};
+ return draw(node, options).then(canvas => canvas.toDataURL('image/jpeg', options.quality || 1.0));
+}
+
+/**
+ * @param {Node} node - The DOM Node object to render
+ * @param {Object} options - Rendering options, @see {@link toSvg}
+ * @return {Promise} - A promise that is fulfilled with a PNG image blob
+ * */
+function toBlob(node, options) {
+ return draw(node, options || {}).then(util.canvasToBlob);
+}
+
+function copyOptions(options) {
+ // Copy options to impl options for use in impl
+ if (typeof options.imagePlaceholder === 'undefined') {
+ domtoimage.impl.options.imagePlaceholder =
+ defaultOptions.imagePlaceholder;
+ } else {
+ domtoimage.impl.options.imagePlaceholder = options.imagePlaceholder;
+ }
+
+ if (typeof options.cacheBust === 'undefined') {
+ domtoimage.impl.options.cacheBust = defaultOptions.cacheBust;
+ } else {
+ domtoimage.impl.options.cacheBust = options.cacheBust;
+ }
+}
+
+function draw(domNode, options) {
+ return toSvg(domNode, options)
+ .then(util.makeImage)
+ .then(util.delay(100))
+ .then(image => {
+ const canvas = newCanvas(domNode);
+ canvas.getContext('2d').drawImage(image, 0, 0);
+ return canvas;
+ });
+
+ function newCanvas(dNode) {
+ const canvas = document.createElement('canvas');
+ canvas.width = options.width || util.width(dNode);
+ canvas.height = options.height || util.height(dNode);
+
+ if (options.bgcolor) {
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = options.bgcolor;
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
+ }
+
+ return canvas;
+ }
+}
+
+function cloneNode(node, filter, root) {
+ if (!root && filter && !filter(node)) {
+ return Promise.resolve();
+ }
+
+ return Promise.resolve(node)
+ .then(makeNodeCopy)
+ .then(clone => cloneChildren(node, clone, filter))
+ .then(clone => processClone(node, clone));
+
+ function makeNodeCopy(nd) {
+ if (nd instanceof HTMLCanvasElement) {
+ return util.makeImage(nd.toDataURL());
+ }
+ return nd.cloneNode(false);
+ }
+
+ function cloneChildren(original, clone, flt) {
+ const children = original.childNodes;
+ if (children.length === 0) {
+ return Promise.resolve(clone);
+ }
+
+ return cloneChildrenInOrder(clone, util.asArray(children))
+ .then(() => clone);
+
+ function cloneChildrenInOrder(parent, arrChildren) {
+ let done = Promise.resolve();
+ arrChildren.forEach(child => {
+ done = done
+ .then(() => cloneNode(child, flt))
+ .then(childClone => {
+ if (childClone) parent.appendChild(childClone);
+ });
+ });
+ return done;
+ }
+ }
+
+ function processClone(original, clone) {
+ if (!(clone instanceof Element)) {
+ return clone
+ };
+
+ return Promise.resolve()
+ .then(cloneStyle)
+ .then(clonePseudoElements)
+ .then(copyUserInput)
+ .then(fixSvg)
+ .then(() => clone);
+
+ function cloneStyle() {
+ const originalStyle = window.getComputedStyle(original);
+ copyStyle(originalStyle, clone.style);
+ function copyStyle(source, target) {
+ if (source.cssText) {
+ target.cssText = source.cssText;
+ // add additional copy of composite styles
+ if (source.font) {
+ target.font = source.font;
+ }
+ } else {
+ copyProperties(source, target);
+ }
+ function copyProperties(sourceStyle, targetStyle) {
+ const propertyKeys = util.asArray(sourceStyle);
+ propertyKeys.forEach(name => {
+ targetStyle.setProperty(
+ name,
+ sourceStyle.getPropertyValue(name),
+ sourceStyle.getPropertyPriority(name)
+ );
+ });
+ }
+ }
+ }
+
+ function clonePseudoElements() {
+ [':before', ':after'].forEach(element => clonePseudoElement(element));
+
+ function clonePseudoElement(element) {
+ const style = window.getComputedStyle(original, element);
+ const content = style.getPropertyValue('content');
+
+ if (content === '' || content === 'none') {
+ return;
+ }
+
+ const className = util.uid();
+ clone.className = `${clone.className} ${className}`;
+ const styleElement = document.createElement('style');
+ styleElement.appendChild(
+ formatPseudoElementStyle(className, element, style)
+ );
+ clone.appendChild(styleElement);
+
+ function formatPseudoElementStyle(cln, elm, stl) {
+ const selector = `.${cln}:${elm}`;
+ const cssText = stl.cssText
+ ? formatCssText(stl)
+ : formatCssProperties(stl);
+ return document.createTextNode(`${selector}{${cssText}}`);
+
+ function formatCssText(stl1) {
+ const cnt = stl1.getPropertyValue('content');
+ return `${stl.cssText} content: ${cnt};`;
+ }
+
+ function formatCssProperties(stl2) {
+ return `${util.asArray(stl2).map(formatProperty).join('; ')};`;
+
+ function formatProperty(name) {
+ return (
+ `${name}:${stl.getPropertyValue(name)}${stl.getPropertyPriority(name) ? ' !important' : ''}`
+ );
+ }
+ }
+ }
+ }
+ }
+
+ function copyUserInput() {
+ if (original instanceof HTMLTextAreaElement)
+ clone.innerHTML = original.value;
+ if (original instanceof HTMLInputElement)
+ clone.setAttribute('value', original.value);
+ }
+
+ function fixSvg() {
+ if (!(clone instanceof SVGElement)) return;
+ clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
+
+ if (!(clone instanceof SVGRectElement)) return;
+ ['width', 'height'].forEach(attribute => {
+ const value = clone.getAttribute(attribute);
+ if (!value) return;
+
+ clone.style.setProperty(attribute, value);
+ });
+ }
+ }
+}
+
+function embedFonts(node) {
+ return fontFaces.resolveAll().then((cssText) => {
+ const styleNode = document.createElement('style');
+ node.appendChild(styleNode);
+ styleNode.appendChild(document.createTextNode(cssText));
+ return node;
+ });
+}
+
+function inlineImages(node) {
+ return images.inlineAll(node).then(() => node);
+}
+
+function makeSvgDataUri(node, width, height) {
+ return Promise.resolve(node)
+ .then(nd => {
+ nd.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
+ return new XMLSerializer().serializeToString(nd);
+ })
+ .then(util.escapeXhtml)
+ .then(xhtml =>
+ `<foreignObject x="0" y="0" width="100%" height="100%">${xhtml}</foreignObject>`
+ )
+ .then(foreignObject =>
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">${foreignObject}</svg>`
+ )
+ .then(svg => `data:image/svg+xml;charset=utf-8,${svg}`);
+}
+
+function newUtil() {
+ return {
+ escape,
+ parseExtension,
+ mimeType,
+ dataAsUrl,
+ isDataUrl,
+ isSrcAsDataUrl,
+ canvasToBlob,
+ resolveUrl,
+ getAndEncode,
+ uid: uid(),
+ delay,
+ asArray,
+ escapeXhtml,
+ makeImage,
+ width,
+ height
+ };
+
+ function mimes() {
+ /*
+ * Only WOFF and EOT mime types for fonts are 'real'
+ * see http://www.iana.org/assignments/media-types/media-types.xhtml
+ */
+ const WOFF = 'application/font-woff';
+ const JPEG = 'image/jpeg';
+
+ return {
+ woff: WOFF,
+ woff2: WOFF,
+ ttf: 'application/font-truetype',
+ eot: 'application/vnd.ms-fontobject',
+ png: 'image/png',
+ jpg: JPEG,
+ jpeg: JPEG,
+ gif: 'image/gif',
+ tiff: 'image/tiff',
+ svg: 'image/svg+xml'
+ };
+ }
+
+ function parseExtension(url) {
+ const match = /\.([^\.\/]*?)$/g.exec(url);
+ if (match) {
+ return match[1];
+ }
+ return '';
+ }
+
+ function mimeType(url) {
+ const extension = parseExtension(url).toLowerCase();
+ return mimes()[extension] || '';
+ }
+
+ function isDataUrl(url) {
+ return url.search(/^(data:)/) !== -1;
+ }
+
+ function isSrcAsDataUrl(text) {
+ const DATA_URL_REGEX = /url\(['"]?(data:)([^'"]+?)['"]?\)/;
+
+ return text.search(DATA_URL_REGEX) !== -1;
+ }
+ function cvToBlob(canvas) {
+ return new Promise(resolve => {
+ const binaryString = window.atob(canvas.toDataURL().split(',')[1]);
+ const length = binaryString.length;
+ const binaryArray = new Uint8Array(length);
+
+ for (let i = 0; i < length; i++)
+ binaryArray[i] = binaryString.charCodeAt(i);
+
+ resolve(
+ new Blob([binaryArray], {type: 'image/png'})
+ );
+ });
+ }
+
+ function canvasToBlob(canvas) {
+ if (canvas.toBlob)
+ return new Promise(resolve => {
+ canvas.toBlob(resolve);
+ });
+
+ return cvToBlob(canvas);
+ }
+
+ function resolveUrl(url, baseUrl) {
+ const doc = document.implementation.createHTMLDocument();
+ const base = doc.createElement('base');
+ doc.head.appendChild(base);
+ const a = doc.createElement('a');
+ doc.body.appendChild(a);
+ base.href = baseUrl;
+ a.href = url;
+ return a.href;
+ }
+
+ function fourRandomChars() {
+ /* see http://stackoverflow.com/a/6248722/2519373 */
+ return `0000${((Math.random() * Math.pow(36, 4)) << 0).toString(36)}`.slice(-4);
+ }
+
+ function uid() {
+ let index = 0;
+
+ return () => `u${fourRandomChars()}${index++}`;
+ }
+
+ function makeImage(uri) {
+ return new Promise((resolve, reject) => {
+ const image = new Image();
+ image.onload = () => {
+ resolve(image);
+ };
+ image.onerror = reject;
+ image.src = uri;
+ });
+ }
+
+ function getAndEncode(url) {
+ const TIMEOUT = 30000;
+ if (domtoimage.impl.options.cacheBust) {
+ // Cache bypass so we dont have CORS issues with cached images
+ // Source: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
+ url += (/\?/.test(url) ? '&' : '?') + new Date().getTime();
+ }
+
+ return new Promise(resolve => {
+ const request = new XMLHttpRequest();
+
+ request.onreadystatechange = done;
+ request.ontimeout = timeout;
+ request.responseType = 'blob';
+ request.timeout = TIMEOUT;
+ request.open('GET', url, true);
+ request.send();
+
+ let placeholder;
+ if (domtoimage.impl.options.imagePlaceholder) {
+ const split = domtoimage.impl.options.imagePlaceholder.split(/,/);
+ if (split && split[1]) {
+ placeholder = split[1];
+ }
+ }
+
+ function done() {
+ if (request.readyState !== 4) return;
+
+ if (request.status !== 200) {
+ if (placeholder) {
+ resolve(placeholder);
+ } else {
+ fail(`cannot fetch resource: ${url}, status: ${request.status}`);
+ }
+
+ return;
+ }
+
+ const encoder = new FileReader();
+ encoder.onloadend = () => {
+ const content = encoder.result.split(/,/)[1];
+ resolve(content);
+ };
+ encoder.readAsDataURL(request.response);
+ }
+
+ function timeout() {
+ if (placeholder) {
+ resolve(placeholder);
+ } else {
+ fail(
+ `timeout of ${TIMEOUT}ms occured while fetching resource: ${url}`
+ );
+ }
+ }
+
+ function fail(message) {
+ console.error(message);
+ resolve('');
+ }
+ });
+ }
+
+ function dataAsUrl(content, type) {
+ return `data:${type};base64,${content}`;
+ }
+
+ function escape(string) {
+ return string.replace(/([.*+?^${}()|\[\]\/\\])/g, '\\$1');
+ }
+
+ function delay(ms) {
+ return arg => {
+ return new Promise((resolve) => {
+ setTimeout(() => {
+ resolve(arg);
+ }, ms);
+ });
+ };
+ }
+
+ function asArray(arrayLike) {
+ const array = [];
+ const length = arrayLike.length;
+ for (let i = 0; i < length; i++) array.push(arrayLike[i]);
+ return array;
+ }
+
+ function escapeXhtml(string) {
+ return string.replace(/#/g, '%23').replace(/\n/g, '%0A');
+ }
+
+ function width(node) {
+ const leftBorder = px(node, 'border-left-width');
+ const rightBorder = px(node, 'border-right-width');
+ return node.scrollWidth + leftBorder + rightBorder;
+ }
+
+ function height(node) {
+ const topBorder = px(node, 'border-top-width');
+ const bottomBorder = px(node, 'border-bottom-width');
+ return node.scrollHeight + topBorder + bottomBorder;
+ }
+
+ function px(node, styleProperty) {
+ const value = window.getComputedStyle(node).getPropertyValue(styleProperty);
+ return parseFloat(value.replace('px', ''));
+ }
+}
+
+function newInliner() {
+ const URL_REGEX = /url\(['"]?([^'"]+?)['"]?\)/g;
+
+ return {
+ inlineAll,
+ shouldProcess,
+ impl: {
+ readUrls,
+ inline
+ }
+ };
+
+ function shouldProcess(string) {
+ return string.search(URL_REGEX) !== -1;
+ }
+
+ function readUrls(string) {
+ const result = [];
+ let match;
+ while ((match = URL_REGEX.exec(string)) !== null) {
+ result.push(match[1]);
+ }
+ return result.filter((url) => {
+ return !util.isDataUrl(url);
+ });
+ }
+
+ function inline(string, url, baseUrl, get) {
+ return Promise.resolve(url)
+ .then(ul => baseUrl ? util.resolveUrl(ul, baseUrl) : ul)
+ .then(get || util.getAndEncode)
+ .then(data => util.dataAsUrl(data, util.mimeType(url)))
+ .then(dataUrl => string.replace(urlAsRegex(url), `$1${dataUrl}$3`));
+
+ function urlAsRegex(url0) {
+ return new RegExp(
+ `(url\\([\'"]?)(${util.escape(url0)})([\'"]?\\))`,
+ 'g'
+ );
+ }
+ }
+
+ function inlineAll(string, baseUrl, get) {
+ if (nothingToInline() || util.isSrcAsDataUrl(string)) {
+ return Promise.resolve(string);
+ }
+ return Promise.resolve(string)
+ .then(readUrls)
+ .then(urls => {
+ let done = Promise.resolve(string);
+ urls.forEach(url => {
+ done = done.then(str => inline(str, url, baseUrl, get));
+ });
+ return done;
+ });
+
+ function nothingToInline() {
+ return !shouldProcess(string);
+ }
+ }
+}
+
+function newFontFaces() {
+ return {
+ resolveAll,
+ impl: {readAll}
+ };
+
+ function resolveAll() {
+ return readAll(document)
+ .then(webFonts => {
+ return Promise.all(
+ webFonts.map(webFont => webFont.resolve())
+ );
+ })
+ .then(cssStrings => cssStrings.join('\n'));
+ }
+
+ function readAll() {
+ return Promise.resolve(util.asArray(document.styleSheets))
+ .then(loadExternalStyleSheets)
+ .then(getCssRules)
+ .then(selectWebFontRules)
+ .then(rules => rules.map(newWebFont));
+
+ function selectWebFontRules(cssRules) {
+ return cssRules
+ .filter(rule => rule.type === CSSRule.FONT_FACE_RULE)
+ .filter(rule => inliner.shouldProcess(rule.style.getPropertyValue('src')));
+ }
+
+ function loadExternalStyleSheets(styleSheets) {
+ return Promise.all(
+ styleSheets.map(sheet => {
+ if (sheet.href) {
+ return fetch(sheet.href)
+ .then(toText)
+ .then(setBaseHref(sheet.href))
+ .then(toStyleSheet)
+ .catch(err => {
+ // Handle any error that occurred in any of the previous
+ // promises in the chain.
+ console.log(err)
+ return sheet;
+ });
+ }
+ return Promise.resolve(sheet);
+ })
+ );
+
+ function toText(response) {
+ return response.text();
+ }
+
+ function setBaseHref(base) {
+ base = base.split('/');
+ base.pop();
+ base = base.join('/');
+
+ return text => {
+ return util.isSrcAsDataUrl(text)
+ ? text
+ : text.replace(/url\(['"]?([^'"]+?)['"]?\)/g, addBaseHrefToUrl);
+ };
+
+ function addBaseHrefToUrl(match, p1) {
+ const url = /^http/i.test(p1) ? p1 : concatAndResolveUrl(base, p1);
+ return `url('${url}')`;
+ }
+
+ // Source: http://stackoverflow.com/a/2676231/3786856
+ function concatAndResolveUrl(url, concat) {
+ const url1 = url.split('/');
+ const url2 = concat.split('/');
+ const url3 = [];
+ for (let i = 0, l = url1.length; i < l; i++) {
+ if (url1[i] === '..') {
+ url3.pop();
+ } else if (url1[i] !== '.') {
+ url3.push(url1[i]);
+ }
+ }
+ for (let i = 0, l = url2.length; i < l; i++) {
+ if (url2[i] === '..') {
+ url3.pop();
+ } else if (url2[i] !== '.') {
+ url3.push(url2[i]);
+ }
+ }
+ return url3.join('/');
+ }
+ }
+
+ function toStyleSheet(text) {
+ const doc = document.implementation.createHTMLDocument('');
+ const styleElement = document.createElement('style');
+
+ styleElement.textContent = text;
+ doc.body.appendChild(styleElement);
+
+ return styleElement.sheet;
+ }
+ }
+
+ function getCssRules(styleSheets) {
+ const cssRules = [];
+ styleSheets.forEach((sheet) => {
+ if (sheet.cssRules && typeof sheet.cssRules === 'object') {
+ try {
+ util
+ .asArray(sheet.cssRules || [])
+ .forEach(cssRules.push.bind(cssRules));
+ } catch (e) {
+ console.log(
+ `Error while reading CSS rules from ${sheet.href}`,
+ e.toString()
+ );
+ }
+ } else {
+ console.log('getCssRules can not fint cssRules')
+ }
+ });
+ return cssRules;
+ }
+
+ function newWebFont(webFontRule) {
+ return {
+ resolve: () => {
+ const baseUrl = (webFontRule.parentStyleSheet || {}).href;
+ return inliner.inlineAll(webFontRule.cssText, baseUrl);
+ },
+ src: () => webFontRule.style.getPropertyValue('src')
+ };
+ }
+ }
+}
+
+function newImages() {
+ return {
+ inlineAll,
+ impl: {
+ newImage
+ }
+ };
+
+ function newImage(element) {
+ return {
+ inline
+ };
+
+ function inline(get) {
+ if (util.isDataUrl(element.src)) {
+ return Promise.resolve();
+ }
+ return Promise.resolve(element.src)
+ .then(get || util.getAndEncode)
+ .then(data => util.dataAsUrl(data, util.mimeType(element.src)))
+ .then(dataUrl =>
+ new Promise((resolve, reject) => {
+ element.onload = resolve;
+ element.onerror = reject;
+ element.src = dataUrl;
+ })
+ );
+ }
+ }
+
+ function inlineAll(node) {
+ if (!(node instanceof Element)) {
+ return Promise.resolve(node);
+ }
+
+ return inlineBackground(node).then(() => {
+ if (node instanceof HTMLImageElement) {
+ return newImage(node).inline();
+ }
+ return Promise.all(
+ util.asArray(node.childNodes).map(child => inlineAll(child))
+ );
+ });
+
+ function inlineBackground(nd) {
+ const background = nd.style.getPropertyValue('background');
+
+ if (!background) {
+ return Promise.resolve(nd);
+ }
+
+ return inliner
+ .inlineAll(background)
+ .then(inlined => {
+ nd.style.setProperty(
+ 'background',
+ inlined,
+ nd.style.getPropertyPriority('background')
+ );
+ })
+ .then(() => nd);
+ }
+ }
+}
+
+export default domtoimage;
diff --git a/src/utils/export-image-utils.js b/src/utils/export-image-utils.js
index a81641ec1..4f62bc28b 100644
--- a/src/utils/export-image-utils.js
+++ b/src/utils/export-image-utils.js
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import domtoimage from 'dom-to-image';
+import domtoimage from 'utils/dom-to-image';
import {
Blob,
URL,
diff --git a/website/.babelrc b/website/.babelrc
index 77335da09..12903c39b 100644
--- a/website/.babelrc
+++ b/website/.babelrc
@@ -1,7 +1,7 @@
{
- presets: [
+ "presets": [
"babel-preset-es2015",
"babel-preset-react",
"babel-preset-stage-0"
-]
+ ]
}
diff --git a/website/package.json b/website/package.json
index e1e34cc2f..ad70fb302 100644
--- a/website/package.json
+++ b/website/package.json
@@ -54,7 +54,7 @@
"prettier": "^1.7.0",
"source-map-loader": "^0.2.1",
"url-loader": "^0.5.9",
- "webpack": "^2.2.0",
+ "webpack": "2.2.0",
"webpack-dev-server": "^2.2.0"
},
"peerDependencies": {
diff --git a/website/src/static/index.html b/website/src/static/index.html
index c54d5efe0..d17796488 100644
--- a/website/src/static/index.html
+++ b/website/src/static/index.html
@@ -6,8 +6,8 @@
<meta name="description" content="Kepler.gl is a data agnostic, WebGL empowered, high-performance web application for geospatial analytic visualizations.">
<title>kepler.gl</title>
<link rel="shortcut icon" href="favicon.png">
- <link rel="stylesheet" id="font-link" href="https://d1a3f4spazzrp4.cloudfront.net/uber-fonts/3.1.0/refresh.css">
- <link href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.42.0/mapbox-gl.css" rel="stylesheet">
+ <link rel="stylesheet" id="font-link" href="//d1a3f4spazzrp4.cloudfront.net/uber-fonts/3.1.0/refresh.css">
+ <link href="//api.tiles.mapbox.com/mapbox-gl-js/v0.42.0/mapbox-gl.css" rel="stylesheet">
<!-— facebook open graph tags -->
<meta property="og:url" content="https://uber.github.io/kepler.gl/" />
diff --git a/yarn.lock b/yarn.lock
index d91b4adb3..b70859070 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2458,10 +2458,6 @@ dom-serializer@0, dom-serializer@~0.1.0:
domelementtype "~1.1.1"
entities "~1.1.1"
-"dom-to-image@github:heshan0131/dom-to-image":
- version "2.6.0"
- resolved "https://codeload.github.com/heshan0131/dom-to-image/tar.gz/f125ad908824ca31f00aea4dc02c552f0b4a7595"
-
dom-walk@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018"
@@ -5873,7 +5869,7 @@ react-map-gl@^3.2.1:
dependencies:
babel-runtime "^6.23.0"
bowser "^1.2.0"
- immutable "*"
+ immutable "^3.8.2"
mapbox-gl "0.44"
math.gl "^1.1.3"
mjolnir.js "^1.1.0"