Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
html2canvas cors & cache workaround
/*!
* html2canvas 1.0.0-alpha.12-rc2 <https://html2canvas.hertzen.com>
* Copyright (c) 2018 Niklas von Hertzen <https://hertzen.com>
* Released under MIT License
* Editted By William Crandell
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["html2canvas"] = factory();
else
root["html2canvas"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 27);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
// http://dev.w3.org/csswg/css-color/
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var HEX3 = /^#([a-f0-9]{3})$/i;
var hex3 = function hex3(value) {
var match = value.match(HEX3);
if (match) {
return [parseInt(match[1][0] + match[1][0], 16), parseInt(match[1][1] + match[1][1], 16), parseInt(match[1][2] + match[1][2], 16), null];
}
return false;
};
var HEX6 = /^#([a-f0-9]{6})$/i;
var hex6 = function hex6(value) {
var match = value.match(HEX6);
if (match) {
return [parseInt(match[1].substring(0, 2), 16), parseInt(match[1].substring(2, 4), 16), parseInt(match[1].substring(4, 6), 16), null];
}
return false;
};
var RGB = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/;
var rgb = function rgb(value) {
var match = value.match(RGB);
if (match) {
return [Number(match[1]), Number(match[2]), Number(match[3]), null];
}
return false;
};
var RGBA = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d?\.?\d+)\s*\)$/;
var rgba = function rgba(value) {
var match = value.match(RGBA);
if (match && match.length > 4) {
return [Number(match[1]), Number(match[2]), Number(match[3]), Number(match[4])];
}
return false;
};
var fromArray = function fromArray(array) {
return [Math.min(array[0], 255), Math.min(array[1], 255), Math.min(array[2], 255), array.length > 3 ? array[3] : null];
};
var namedColor = function namedColor(name) {
var color = NAMED_COLORS[name.toLowerCase()];
return color ? color : false;
};
var Color = function () {
function Color(value) {
_classCallCheck(this, Color);
var _ref = Array.isArray(value) ? fromArray(value) : hex3(value) || rgb(value) || rgba(value) || namedColor(value) || hex6(value) || [0, 0, 0, null],
_ref2 = _slicedToArray(_ref, 4),
r = _ref2[0],
g = _ref2[1],
b = _ref2[2],
a = _ref2[3];
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
_createClass(Color, [{
key: 'isTransparent',
value: function isTransparent() {
return this.a === 0;
}
}, {
key: 'toString',
value: function toString() {
return this.a !== null && this.a !== 1 ? 'rgba(' + this.r + ',' + this.g + ',' + this.b + ',' + this.a + ')' : 'rgb(' + this.r + ',' + this.g + ',' + this.b + ')';
}
}]);
return Color;
}();
exports.default = Color;
var NAMED_COLORS = {
transparent: [0, 0, 0, 0],
aliceblue: [240, 248, 255, null],
antiquewhite: [250, 235, 215, null],
aqua: [0, 255, 255, null],
aquamarine: [127, 255, 212, null],
azure: [240, 255, 255, null],
beige: [245, 245, 220, null],
bisque: [255, 228, 196, null],
black: [0, 0, 0, null],
blanchedalmond: [255, 235, 205, null],
blue: [0, 0, 255, null],
blueviolet: [138, 43, 226, null],
brown: [165, 42, 42, null],
burlywood: [222, 184, 135, null],
cadetblue: [95, 158, 160, null],
chartreuse: [127, 255, 0, null],
chocolate: [210, 105, 30, null],
coral: [255, 127, 80, null],
cornflowerblue: [100, 149, 237, null],
cornsilk: [255, 248, 220, null],
crimson: [220, 20, 60, null],
cyan: [0, 255, 255, null],
darkblue: [0, 0, 139, null],
darkcyan: [0, 139, 139, null],
darkgoldenrod: [184, 134, 11, null],
darkgray: [169, 169, 169, null],
darkgreen: [0, 100, 0, null],
darkgrey: [169, 169, 169, null],
darkkhaki: [189, 183, 107, null],
darkmagenta: [139, 0, 139, null],
darkolivegreen: [85, 107, 47, null],
darkorange: [255, 140, 0, null],
darkorchid: [153, 50, 204, null],
darkred: [139, 0, 0, null],
darksalmon: [233, 150, 122, null],
darkseagreen: [143, 188, 143, null],
darkslateblue: [72, 61, 139, null],
darkslategray: [47, 79, 79, null],
darkslategrey: [47, 79, 79, null],
darkturquoise: [0, 206, 209, null],
darkviolet: [148, 0, 211, null],
deeppink: [255, 20, 147, null],
deepskyblue: [0, 191, 255, null],
dimgray: [105, 105, 105, null],
dimgrey: [105, 105, 105, null],
dodgerblue: [30, 144, 255, null],
firebrick: [178, 34, 34, null],
floralwhite: [255, 250, 240, null],
forestgreen: [34, 139, 34, null],
fuchsia: [255, 0, 255, null],
gainsboro: [220, 220, 220, null],
ghostwhite: [248, 248, 255, null],
gold: [255, 215, 0, null],
goldenrod: [218, 165, 32, null],
gray: [128, 128, 128, null],
green: [0, 128, 0, null],
greenyellow: [173, 255, 47, null],
grey: [128, 128, 128, null],
honeydew: [240, 255, 240, null],
hotpink: [255, 105, 180, null],
indianred: [205, 92, 92, null],
indigo: [75, 0, 130, null],
ivory: [255, 255, 240, null],
khaki: [240, 230, 140, null],
lavender: [230, 230, 250, null],
lavenderblush: [255, 240, 245, null],
lawngreen: [124, 252, 0, null],
lemonchiffon: [255, 250, 205, null],
lightblue: [173, 216, 230, null],
lightcoral: [240, 128, 128, null],
lightcyan: [224, 255, 255, null],
lightgoldenrodyellow: [250, 250, 210, null],
lightgray: [211, 211, 211, null],
lightgreen: [144, 238, 144, null],
lightgrey: [211, 211, 211, null],
lightpink: [255, 182, 193, null],
lightsalmon: [255, 160, 122, null],
lightseagreen: [32, 178, 170, null],
lightskyblue: [135, 206, 250, null],
lightslategray: [119, 136, 153, null],
lightslategrey: [119, 136, 153, null],
lightsteelblue: [176, 196, 222, null],
lightyellow: [255, 255, 224, null],
lime: [0, 255, 0, null],
limegreen: [50, 205, 50, null],
linen: [250, 240, 230, null],
magenta: [255, 0, 255, null],
maroon: [128, 0, 0, null],
mediumaquamarine: [102, 205, 170, null],
mediumblue: [0, 0, 205, null],
mediumorchid: [186, 85, 211, null],
mediumpurple: [147, 112, 219, null],
mediumseagreen: [60, 179, 113, null],
mediumslateblue: [123, 104, 238, null],
mediumspringgreen: [0, 250, 154, null],
mediumturquoise: [72, 209, 204, null],
mediumvioletred: [199, 21, 133, null],
midnightblue: [25, 25, 112, null],
mintcream: [245, 255, 250, null],
mistyrose: [255, 228, 225, null],
moccasin: [255, 228, 181, null],
navajowhite: [255, 222, 173, null],
navy: [0, 0, 128, null],
oldlace: [253, 245, 230, null],
olive: [128, 128, 0, null],
olivedrab: [107, 142, 35, null],
orange: [255, 165, 0, null],
orangered: [255, 69, 0, null],
orchid: [218, 112, 214, null],
palegoldenrod: [238, 232, 170, null],
palegreen: [152, 251, 152, null],
paleturquoise: [175, 238, 238, null],
palevioletred: [219, 112, 147, null],
papayawhip: [255, 239, 213, null],
peachpuff: [255, 218, 185, null],
peru: [205, 133, 63, null],
pink: [255, 192, 203, null],
plum: [221, 160, 221, null],
powderblue: [176, 224, 230, null],
purple: [128, 0, 128, null],
rebeccapurple: [102, 51, 153, null],
red: [255, 0, 0, null],
rosybrown: [188, 143, 143, null],
royalblue: [65, 105, 225, null],
saddlebrown: [139, 69, 19, null],
salmon: [250, 128, 114, null],
sandybrown: [244, 164, 96, null],
seagreen: [46, 139, 87, null],
seashell: [255, 245, 238, null],
sienna: [160, 82, 45, null],
silver: [192, 192, 192, null],
skyblue: [135, 206, 235, null],
slateblue: [106, 90, 205, null],
slategray: [112, 128, 144, null],
slategrey: [112, 128, 144, null],
snow: [255, 250, 250, null],
springgreen: [0, 255, 127, null],
steelblue: [70, 130, 180, null],
tan: [210, 180, 140, null],
teal: [0, 128, 128, null],
thistle: [216, 191, 216, null],
tomato: [255, 99, 71, null],
turquoise: [64, 224, 208, null],
violet: [238, 130, 238, null],
wheat: [245, 222, 179, null],
white: [255, 255, 255, null],
whitesmoke: [245, 245, 245, null],
yellow: [255, 255, 0, null],
yellowgreen: [154, 205, 50, null]
};
var TRANSPARENT = exports.TRANSPARENT = new Color([0, 0, 0, 0]);
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var LENGTH_WITH_UNIT = /([\d.]+)(px|r?em|%)/i;
var LENGTH_TYPE = exports.LENGTH_TYPE = {
PX: 0,
PERCENTAGE: 1
};
var Length = function () {
function Length(value) {
_classCallCheck(this, Length);
this.type = value.substr(value.length - 1) === '%' ? LENGTH_TYPE.PERCENTAGE : LENGTH_TYPE.PX;
var parsedValue = parseFloat(value);
if (true && isNaN(parsedValue)) {
console.error('Invalid value given for Length: "' + value + '"');
}
this.value = isNaN(parsedValue) ? 0 : parsedValue;
}
_createClass(Length, [{
key: 'isPercentage',
value: function isPercentage() {
return this.type === LENGTH_TYPE.PERCENTAGE;
}
}, {
key: 'getAbsoluteValue',
value: function getAbsoluteValue(parentLength) {
return this.isPercentage() ? parentLength * (this.value / 100) : this.value;
}
}], [{
key: 'create',
value: function create(v) {
return new Length(v);
}
}]);
return Length;
}();
exports.default = Length;
var getRootFontSize = function getRootFontSize(container) {
var parent = container.parent;
return parent ? getRootFontSize(parent) : parseFloat(container.style.font.fontSize);
};
var calculateLengthFromValueWithUnit = exports.calculateLengthFromValueWithUnit = function calculateLengthFromValueWithUnit(container, value, unit) {
switch (unit) {
case 'px':
case '%':
return new Length(value + unit);
case 'em':
case 'rem':
var length = new Length(value);
length.value *= unit === 'em' ? parseFloat(container.style.font.fontSize) : getRootFontSize(container);
return length;
default:
// TODO: handle correctly if unknown unit is used
return new Length('0');
}
};
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseBoundCurves = exports.calculatePaddingBoxPath = exports.calculateBorderBoxPath = exports.parsePathForBorder = exports.parseDocumentSize = exports.calculateContentBox = exports.calculatePaddingBox = exports.parseBounds = exports.Bounds = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Vector = __webpack_require__(7);
var _Vector2 = _interopRequireDefault(_Vector);
var _BezierCurve = __webpack_require__(32);
var _BezierCurve2 = _interopRequireDefault(_BezierCurve);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var TOP = 0;
var RIGHT = 1;
var BOTTOM = 2;
var LEFT = 3;
var H = 0;
var V = 1;
var Bounds = exports.Bounds = function () {
function Bounds(x, y, w, h) {
_classCallCheck(this, Bounds);
this.left = x;
this.top = y;
this.width = w;
this.height = h;
}
_createClass(Bounds, null, [{
key: 'fromClientRect',
value: function fromClientRect(clientRect, scrollX, scrollY) {
return new Bounds(clientRect.left + scrollX, clientRect.top + scrollY, clientRect.width, clientRect.height);
}
}]);
return Bounds;
}();
var parseBounds = exports.parseBounds = function parseBounds(node, scrollX, scrollY) {
return Bounds.fromClientRect(node.getBoundingClientRect(), scrollX, scrollY);
};
var calculatePaddingBox = exports.calculatePaddingBox = function calculatePaddingBox(bounds, borders) {
return new Bounds(bounds.left + borders[LEFT].borderWidth, bounds.top + borders[TOP].borderWidth, bounds.width - (borders[RIGHT].borderWidth + borders[LEFT].borderWidth), bounds.height - (borders[TOP].borderWidth + borders[BOTTOM].borderWidth));
};
var calculateContentBox = exports.calculateContentBox = function calculateContentBox(bounds, padding, borders) {
// TODO support percentage paddings
var paddingTop = padding[TOP].value;
var paddingRight = padding[RIGHT].value;
var paddingBottom = padding[BOTTOM].value;
var paddingLeft = padding[LEFT].value;
return new Bounds(bounds.left + paddingLeft + borders[LEFT].borderWidth, bounds.top + paddingTop + borders[TOP].borderWidth, bounds.width - (borders[RIGHT].borderWidth + borders[LEFT].borderWidth + paddingLeft + paddingRight), bounds.height - (borders[TOP].borderWidth + borders[BOTTOM].borderWidth + paddingTop + paddingBottom));
};
var parseDocumentSize = exports.parseDocumentSize = function parseDocumentSize(document) {
var body = document.body;
var documentElement = document.documentElement;
if (!body || !documentElement) {
throw new Error( true ? 'Unable to get document size' : '');
}
var width = Math.max(Math.max(body.scrollWidth, documentElement.scrollWidth), Math.max(body.offsetWidth, documentElement.offsetWidth), Math.max(body.clientWidth, documentElement.clientWidth));
var height = Math.max(Math.max(body.scrollHeight, documentElement.scrollHeight), Math.max(body.offsetHeight, documentElement.offsetHeight), Math.max(body.clientHeight, documentElement.clientHeight));
return new Bounds(0, 0, width, height);
};
var parsePathForBorder = exports.parsePathForBorder = function parsePathForBorder(curves, borderSide) {
switch (borderSide) {
case TOP:
return createPathFromCurves(curves.topLeftOuter, curves.topLeftInner, curves.topRightOuter, curves.topRightInner);
case RIGHT:
return createPathFromCurves(curves.topRightOuter, curves.topRightInner, curves.bottomRightOuter, curves.bottomRightInner);
case BOTTOM:
return createPathFromCurves(curves.bottomRightOuter, curves.bottomRightInner, curves.bottomLeftOuter, curves.bottomLeftInner);
case LEFT:
default:
return createPathFromCurves(curves.bottomLeftOuter, curves.bottomLeftInner, curves.topLeftOuter, curves.topLeftInner);
}
};
var createPathFromCurves = function createPathFromCurves(outer1, inner1, outer2, inner2) {
var path = [];
if (outer1 instanceof _BezierCurve2.default) {
path.push(outer1.subdivide(0.5, false));
} else {
path.push(outer1);
}
if (outer2 instanceof _BezierCurve2.default) {
path.push(outer2.subdivide(0.5, true));
} else {
path.push(outer2);
}
if (inner2 instanceof _BezierCurve2.default) {
path.push(inner2.subdivide(0.5, true).reverse());
} else {
path.push(inner2);
}
if (inner1 instanceof _BezierCurve2.default) {
path.push(inner1.subdivide(0.5, false).reverse());
} else {
path.push(inner1);
}
return path;
};
var calculateBorderBoxPath = exports.calculateBorderBoxPath = function calculateBorderBoxPath(curves) {
return [curves.topLeftOuter, curves.topRightOuter, curves.bottomRightOuter, curves.bottomLeftOuter];
};
var calculatePaddingBoxPath = exports.calculatePaddingBoxPath = function calculatePaddingBoxPath(curves) {
return [curves.topLeftInner, curves.topRightInner, curves.bottomRightInner, curves.bottomLeftInner];
};
var parseBoundCurves = exports.parseBoundCurves = function parseBoundCurves(bounds, borders, borderRadius) {
var tlh = borderRadius[CORNER.TOP_LEFT][H].getAbsoluteValue(bounds.width);
var tlv = borderRadius[CORNER.TOP_LEFT][V].getAbsoluteValue(bounds.height);
var trh = borderRadius[CORNER.TOP_RIGHT][H].getAbsoluteValue(bounds.width);
var trv = borderRadius[CORNER.TOP_RIGHT][V].getAbsoluteValue(bounds.height);
var brh = borderRadius[CORNER.BOTTOM_RIGHT][H].getAbsoluteValue(bounds.width);
var brv = borderRadius[CORNER.BOTTOM_RIGHT][V].getAbsoluteValue(bounds.height);
var blh = borderRadius[CORNER.BOTTOM_LEFT][H].getAbsoluteValue(bounds.width);
var blv = borderRadius[CORNER.BOTTOM_LEFT][V].getAbsoluteValue(bounds.height);
var factors = [];
factors.push((tlh + trh) / bounds.width);
factors.push((blh + brh) / bounds.width);
factors.push((tlv + blv) / bounds.height);
factors.push((trv + brv) / bounds.height);
var maxFactor = Math.max.apply(Math, factors);
if (maxFactor > 1) {
tlh /= maxFactor;
tlv /= maxFactor;
trh /= maxFactor;
trv /= maxFactor;
brh /= maxFactor;
brv /= maxFactor;
blh /= maxFactor;
blv /= maxFactor;
}
var topWidth = bounds.width - trh;
var rightHeight = bounds.height - brv;
var bottomWidth = bounds.width - brh;
var leftHeight = bounds.height - blv;
return {
topLeftOuter: tlh > 0 || tlv > 0 ? getCurvePoints(bounds.left, bounds.top, tlh, tlv, CORNER.TOP_LEFT) : new _Vector2.default(bounds.left, bounds.top),
topLeftInner: tlh > 0 || tlv > 0 ? getCurvePoints(bounds.left + borders[LEFT].borderWidth, bounds.top + borders[TOP].borderWidth, Math.max(0, tlh - borders[LEFT].borderWidth), Math.max(0, tlv - borders[TOP].borderWidth), CORNER.TOP_LEFT) : new _Vector2.default(bounds.left + borders[LEFT].borderWidth, bounds.top + borders[TOP].borderWidth),
topRightOuter: trh > 0 || trv > 0 ? getCurvePoints(bounds.left + topWidth, bounds.top, trh, trv, CORNER.TOP_RIGHT) : new _Vector2.default(bounds.left + bounds.width, bounds.top),
topRightInner: trh > 0 || trv > 0 ? getCurvePoints(bounds.left + Math.min(topWidth, bounds.width + borders[LEFT].borderWidth), bounds.top + borders[TOP].borderWidth, topWidth > bounds.width + borders[LEFT].borderWidth ? 0 : trh - borders[LEFT].borderWidth, trv - borders[TOP].borderWidth, CORNER.TOP_RIGHT) : new _Vector2.default(bounds.left + bounds.width - borders[RIGHT].borderWidth, bounds.top + borders[TOP].borderWidth),
bottomRightOuter: brh > 0 || brv > 0 ? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh, brv, CORNER.BOTTOM_RIGHT) : new _Vector2.default(bounds.left + bounds.width, bounds.top + bounds.height),
bottomRightInner: brh > 0 || brv > 0 ? getCurvePoints(bounds.left + Math.min(bottomWidth, bounds.width - borders[LEFT].borderWidth), bounds.top + Math.min(rightHeight, bounds.height + borders[TOP].borderWidth), Math.max(0, brh - borders[RIGHT].borderWidth), brv - borders[BOTTOM].borderWidth, CORNER.BOTTOM_RIGHT) : new _Vector2.default(bounds.left + bounds.width - borders[RIGHT].borderWidth, bounds.top + bounds.height - borders[BOTTOM].borderWidth),
bottomLeftOuter: blh > 0 || blv > 0 ? getCurvePoints(bounds.left, bounds.top + leftHeight, blh, blv, CORNER.BOTTOM_LEFT) : new _Vector2.default(bounds.left, bounds.top + bounds.height),
bottomLeftInner: blh > 0 || blv > 0 ? getCurvePoints(bounds.left + borders[LEFT].borderWidth, bounds.top + leftHeight, Math.max(0, blh - borders[LEFT].borderWidth), blv - borders[BOTTOM].borderWidth, CORNER.BOTTOM_LEFT) : new _Vector2.default(bounds.left + borders[LEFT].borderWidth, bounds.top + bounds.height - borders[BOTTOM].borderWidth)
};
};
var CORNER = {
TOP_LEFT: 0,
TOP_RIGHT: 1,
BOTTOM_RIGHT: 2,
BOTTOM_LEFT: 3
};
var getCurvePoints = function getCurvePoints(x, y, r1, r2, position) {
var kappa = 4 * ((Math.sqrt(2) - 1) / 3);
var ox = r1 * kappa; // control point offset horizontal
var oy = r2 * kappa; // control point offset vertical
var xm = x + r1; // x-middle
var ym = y + r2; // y-middle
switch (position) {
case CORNER.TOP_LEFT:
return new _BezierCurve2.default(new _Vector2.default(x, ym), new _Vector2.default(x, ym - oy), new _Vector2.default(xm - ox, y), new _Vector2.default(xm, y));
case CORNER.TOP_RIGHT:
return new _BezierCurve2.default(new _Vector2.default(x, y), new _Vector2.default(x + ox, y), new _Vector2.default(xm, ym - oy), new _Vector2.default(xm, ym));
case CORNER.BOTTOM_RIGHT:
return new _BezierCurve2.default(new _Vector2.default(xm, y), new _Vector2.default(xm, y + oy), new _Vector2.default(x + ox, ym), new _Vector2.default(x, ym));
case CORNER.BOTTOM_LEFT:
default:
return new _BezierCurve2.default(new _Vector2.default(xm, ym), new _Vector2.default(xm - ox, ym), new _Vector2.default(x, y + oy), new _Vector2.default(x, y));
}
};
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var contains = exports.contains = function contains(bit, value) {
return (bit & value) !== 0;
};
var distance = exports.distance = function distance(a, b) {
return Math.sqrt(a * a + b * b);
};
var copyCSSStyles = exports.copyCSSStyles = function copyCSSStyles(style, target) {
// Edge does not provide value for cssText
for (var i = style.length - 1; i >= 0; i--) {
var property = style.item(i);
// Safari shows pseudoelements if content is set
if (property !== 'content') {
target.style.setProperty(property, style.getPropertyValue(property));
}
}
return target;
};
var SMALL_IMAGE = exports.SMALL_IMAGE = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseBackgroundImage = exports.parseBackground = exports.calculateBackgroundRepeatPath = exports.calculateBackgroundPosition = exports.calculateBackgroungPositioningArea = exports.calculateBackgroungPaintingArea = exports.calculateGradientBackgroundSize = exports.calculateBackgroundSize = exports.BACKGROUND_ORIGIN = exports.BACKGROUND_CLIP = exports.BACKGROUND_SIZE = exports.BACKGROUND_REPEAT = undefined;
var _Color = __webpack_require__(0);
var _Color2 = _interopRequireDefault(_Color);
var _Length = __webpack_require__(1);
var _Length2 = _interopRequireDefault(_Length);
var _Size = __webpack_require__(31);
var _Size2 = _interopRequireDefault(_Size);
var _Vector = __webpack_require__(7);
var _Vector2 = _interopRequireDefault(_Vector);
var _Bounds = __webpack_require__(2);
var _padding = __webpack_require__(17);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var BACKGROUND_REPEAT = exports.BACKGROUND_REPEAT = {
REPEAT: 0,
NO_REPEAT: 1,
REPEAT_X: 2,
REPEAT_Y: 3
};
var BACKGROUND_SIZE = exports.BACKGROUND_SIZE = {
AUTO: 0,
CONTAIN: 1,
COVER: 2,
LENGTH: 3
};
var BACKGROUND_CLIP = exports.BACKGROUND_CLIP = {
BORDER_BOX: 0,
PADDING_BOX: 1,
CONTENT_BOX: 2
};
var BACKGROUND_ORIGIN = exports.BACKGROUND_ORIGIN = BACKGROUND_CLIP;
var AUTO = 'auto';
var BackgroundSize = function BackgroundSize(size) {
_classCallCheck(this, BackgroundSize);
switch (size) {
case 'contain':
this.size = BACKGROUND_SIZE.CONTAIN;
break;
case 'cover':
this.size = BACKGROUND_SIZE.COVER;
break;
case 'auto':
this.size = BACKGROUND_SIZE.AUTO;
break;
default:
this.value = new _Length2.default(size);
}
};
var calculateBackgroundSize = exports.calculateBackgroundSize = function calculateBackgroundSize(backgroundImage, image, bounds) {
var width = 0;
var height = 0;
var size = backgroundImage.size;
if (size[0].size === BACKGROUND_SIZE.CONTAIN || size[0].size === BACKGROUND_SIZE.COVER) {
var targetRatio = bounds.width / bounds.height;
var currentRatio = image.width / image.height;
return targetRatio < currentRatio !== (size[0].size === BACKGROUND_SIZE.COVER) ? new _Size2.default(bounds.width, bounds.width / currentRatio) : new _Size2.default(bounds.height * currentRatio, bounds.height);
}
if (size[0].value) {
width = size[0].value.getAbsoluteValue(bounds.width);
}
if (size[0].size === BACKGROUND_SIZE.AUTO && size[1].size === BACKGROUND_SIZE.AUTO) {
height = image.height;
} else if (size[1].size === BACKGROUND_SIZE.AUTO) {
height = width / image.width * image.height;
} else if (size[1].value) {
height = size[1].value.getAbsoluteValue(bounds.height);
}
if (size[0].size === BACKGROUND_SIZE.AUTO) {
width = height / image.height * image.width;
}
return new _Size2.default(width, height);
};
var calculateGradientBackgroundSize = exports.calculateGradientBackgroundSize = function calculateGradientBackgroundSize(backgroundImage, bounds) {
var size = backgroundImage.size;
var width = size[0].value ? size[0].value.getAbsoluteValue(bounds.width) : bounds.width;
var height = size[1].value ? size[1].value.getAbsoluteValue(bounds.height) : size[0].value ? width : bounds.height;
return new _Size2.default(width, height);
};
var AUTO_SIZE = new BackgroundSize(AUTO);
var calculateBackgroungPaintingArea = exports.calculateBackgroungPaintingArea = function calculateBackgroungPaintingArea(curves, clip) {
switch (clip) {
case BACKGROUND_CLIP.BORDER_BOX:
return (0, _Bounds.calculateBorderBoxPath)(curves);
case BACKGROUND_CLIP.PADDING_BOX:
default:
return (0, _Bounds.calculatePaddingBoxPath)(curves);
}
};
var calculateBackgroungPositioningArea = exports.calculateBackgroungPositioningArea = function calculateBackgroungPositioningArea(backgroundOrigin, bounds, padding, border) {
var paddingBox = (0, _Bounds.calculatePaddingBox)(bounds, border);
switch (backgroundOrigin) {
case BACKGROUND_ORIGIN.BORDER_BOX:
return bounds;
case BACKGROUND_ORIGIN.CONTENT_BOX:
var paddingLeft = padding[_padding.PADDING_SIDES.LEFT].getAbsoluteValue(bounds.width);
var paddingRight = padding[_padding.PADDING_SIDES.RIGHT].getAbsoluteValue(bounds.width);
var paddingTop = padding[_padding.PADDING_SIDES.TOP].getAbsoluteValue(bounds.width);
var paddingBottom = padding[_padding.PADDING_SIDES.BOTTOM].getAbsoluteValue(bounds.width);
return new _Bounds.Bounds(paddingBox.left + paddingLeft, paddingBox.top + paddingTop, paddingBox.width - paddingLeft - paddingRight, paddingBox.height - paddingTop - paddingBottom);
case BACKGROUND_ORIGIN.PADDING_BOX:
default:
return paddingBox;
}
};
var calculateBackgroundPosition = exports.calculateBackgroundPosition = function calculateBackgroundPosition(position, size, bounds) {
return new _Vector2.default(position[0].getAbsoluteValue(bounds.width - size.width), position[1].getAbsoluteValue(bounds.height - size.height));
};
var calculateBackgroundRepeatPath = exports.calculateBackgroundRepeatPath = function calculateBackgroundRepeatPath(background, position, size, backgroundPositioningArea, bounds) {
var repeat = background.repeat;
switch (repeat) {
case BACKGROUND_REPEAT.REPEAT_X:
return [new _Vector2.default(Math.round(bounds.left), Math.round(backgroundPositioningArea.top + position.y)), new _Vector2.default(Math.round(bounds.left + bounds.width), Math.round(backgroundPositioningArea.top + position.y)), new _Vector2.default(Math.round(bounds.left + bounds.width), Math.round(size.height + backgroundPositioningArea.top + position.y)), new _Vector2.default(Math.round(bounds.left), Math.round(size.height + backgroundPositioningArea.top + position.y))];
case BACKGROUND_REPEAT.REPEAT_Y:
return [new _Vector2.default(Math.round(backgroundPositioningArea.left + position.x), Math.round(bounds.top)), new _Vector2.default(Math.round(backgroundPositioningArea.left + position.x + size.width), Math.round(bounds.top)), new _Vector2.default(Math.round(backgroundPositioningArea.left + position.x + size.width), Math.round(bounds.height + bounds.top)), new _Vector2.default(Math.round(backgroundPositioningArea.left + position.x), Math.round(bounds.height + bounds.top))];
case BACKGROUND_REPEAT.NO_REPEAT:
return [new _Vector2.default(Math.round(backgroundPositioningArea.left + position.x), Math.round(backgroundPositioningArea.top + position.y)), new _Vector2.default(Math.round(backgroundPositioningArea.left + position.x + size.width), Math.round(backgroundPositioningArea.top + position.y)), new _Vector2.default(Math.round(backgroundPositioningArea.left + position.x + size.width), Math.round(backgroundPositioningArea.top + position.y + size.height)), new _Vector2.default(Math.round(backgroundPositioningArea.left + position.x), Math.round(backgroundPositioningArea.top + position.y + size.height))];
default:
return [new _Vector2.default(Math.round(bounds.left), Math.round(bounds.top)), new _Vector2.default(Math.round(bounds.left + bounds.width), Math.round(bounds.top)), new _Vector2.default(Math.round(bounds.left + bounds.width), Math.round(bounds.height + bounds.top)), new _Vector2.default(Math.round(bounds.left), Math.round(bounds.height + bounds.top))];
}
};
var parseBackground = exports.parseBackground = function parseBackground(style, resourceLoader) {
return {
backgroundColor: new _Color2.default(style.backgroundColor),
backgroundImage: parseBackgroundImages(style, resourceLoader),
backgroundClip: parseBackgroundClip(style.backgroundClip),
backgroundOrigin: parseBackgroundOrigin(style.backgroundOrigin)
};
};
var parseBackgroundClip = function parseBackgroundClip(backgroundClip) {
switch (backgroundClip) {
case 'padding-box':
return BACKGROUND_CLIP.PADDING_BOX;
case 'content-box':
return BACKGROUND_CLIP.CONTENT_BOX;
}
return BACKGROUND_CLIP.BORDER_BOX;
};
var parseBackgroundOrigin = function parseBackgroundOrigin(backgroundOrigin) {
switch (backgroundOrigin) {
case 'padding-box':
return BACKGROUND_ORIGIN.PADDING_BOX;
case 'content-box':
return BACKGROUND_ORIGIN.CONTENT_BOX;
}
return BACKGROUND_ORIGIN.BORDER_BOX;
};
var parseBackgroundRepeat = function parseBackgroundRepeat(backgroundRepeat) {
switch (backgroundRepeat.trim()) {
case 'no-repeat':
return BACKGROUND_REPEAT.NO_REPEAT;
case 'repeat-x':
case 'repeat no-repeat':
return BACKGROUND_REPEAT.REPEAT_X;
case 'repeat-y':
case 'no-repeat repeat':
return BACKGROUND_REPEAT.REPEAT_Y;
case 'repeat':
return BACKGROUND_REPEAT.REPEAT;
}
if (true) {
console.error('Invalid background-repeat value "' + backgroundRepeat + '"');
}
return BACKGROUND_REPEAT.REPEAT;
};
var parseBackgroundImages = function parseBackgroundImages(style, resourceLoader) {
var sources = parseBackgroundImage(style.backgroundImage).map(function (backgroundImage) {
if (backgroundImage.method === 'url') {
var key = resourceLoader.loadImage(backgroundImage.args[0]);
backgroundImage.args = key ? [key] : [];
}
return backgroundImage;
});
var positions = style.backgroundPosition.split(',');
var repeats = style.backgroundRepeat.split(',');
var sizes = style.backgroundSize.split(',');
return sources.map(function (source, index) {
var size = (sizes[index] || AUTO).trim().split(' ').map(parseBackgroundSize);
var position = (positions[index] || AUTO).trim().split(' ').map(parseBackgoundPosition);
return {
source: source,
repeat: parseBackgroundRepeat(typeof repeats[index] === 'string' ? repeats[index] : repeats[0]),
size: size.length < 2 ? [size[0], AUTO_SIZE] : [size[0], size[1]],
position: position.length < 2 ? [position[0], position[0]] : [position[0], position[1]]
};
});
};
var parseBackgroundSize = function parseBackgroundSize(size) {
return size === 'auto' ? AUTO_SIZE : new BackgroundSize(size);
};
var parseBackgoundPosition = function parseBackgoundPosition(position) {
switch (position) {
case 'bottom':
case 'right':
return new _Length2.default('100%');
case 'left':
case 'top':
return new _Length2.default('0%');
case 'auto':
return new _Length2.default('0');
}
return new _Length2.default(position);
};
var parseBackgroundImage = exports.parseBackgroundImage = function parseBackgroundImage(image) {
var whitespace = /^\s$/;
var results = [];
var args = [];
var method = '';
var quote = null;
var definition = '';
var mode = 0;
var numParen = 0;
var appendResult = function appendResult() {
var prefix = '';
if (method) {
if (definition.substr(0, 1) === '"') {
definition = definition.substr(1, definition.length - 2);
}
if (definition) {
args.push(definition.trim());
}
var prefix_i = method.indexOf('-', 1) + 1;
if (method.substr(0, 1) === '-' && prefix_i > 0) {
prefix = method.substr(0, prefix_i).toLowerCase();
method = method.substr(prefix_i);
}
method = method.toLowerCase();
if (method !== 'none') {
results.push({
prefix: prefix,
method: method,
args: args
});
}
}
args = [];
method = definition = '';
};
image.split('').forEach(function (c) {
if (mode === 0 && whitespace.test(c)) {
return;
}
switch (c) {
case '"':
if (!quote) {
quote = c;
} else if (quote === c) {
quote = null;
}
break;
case '(':
if (quote) {
break;
} else if (mode === 0) {
mode = 1;
return;
} else {
numParen++;
}
break;
case ')':
if (quote) {
break;
} else if (mode === 1) {
if (numParen === 0) {
mode = 0;
appendResult();
return;
} else {
numParen--;
}
}
break;
case ',':
if (quote) {
break;
} else if (mode === 0) {
appendResult();
return;
} else if (mode === 1) {
if (numParen === 0 && !method.match(/^url$/i)) {
args.push(definition.trim());
definition = '';
return;
}
}
break;
}
if (mode === 0) {
method += c;
} else {
definition += c;
}
});
appendResult();
return results;
};
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var PATH = exports.PATH = {
VECTOR: 0,
BEZIER_CURVE: 1,
CIRCLE: 2
};
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Color = __webpack_require__(0);
var _Color2 = _interopRequireDefault(_Color);
var _Util = __webpack_require__(3);
var _background = __webpack_require__(4);
var _border = __webpack_require__(12);
var _borderRadius = __webpack_require__(33);
var _display = __webpack_require__(34);
var _float = __webpack_require__(35);
var _font = __webpack_require__(36);
var _letterSpacing = __webpack_require__(37);
var _lineBreak = __webpack_require__(38);
var _listStyle = __webpack_require__(8);
var _margin = __webpack_require__(39);
var _overflow = __webpack_require__(40);
var _overflowWrap = __webpack_require__(18);
var _padding = __webpack_require__(17);
var _position = __webpack_require__(19);
var _textDecoration = __webpack_require__(11);
var _textShadow = __webpack_require__(41);
var _textTransform = __webpack_require__(20);
var _transform = __webpack_require__(42);
var _visibility = __webpack_require__(43);
var _wordBreak = __webpack_require__(44);
var _zIndex = __webpack_require__(45);
var _Bounds = __webpack_require__(2);
var _Input = __webpack_require__(21);
var _ListItem = __webpack_require__(14);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
var NodeContainer = function () {
function NodeContainer(node, parent, resourceLoader, index) {
var _this = this;
_classCallCheck(this, NodeContainer);
this.parent = parent;
this.tagName = node.tagName;
this.index = index;
this.childNodes = [];
this.listItems = [];
if (typeof node.start === 'number') {
this.listStart = node.start;
}
var defaultView = node.ownerDocument.defaultView;
var scrollX = defaultView.pageXOffset;
var scrollY = defaultView.pageYOffset;
var style = defaultView.getComputedStyle(node, null);
var display = (0, _display.parseDisplay)(style.display);
var IS_INPUT = node.type === 'radio' || node.type === 'checkbox';
var position = (0, _position.parsePosition)(style.position);
this.style = {
background: IS_INPUT ? _Input.INPUT_BACKGROUND : (0, _background.parseBackground)(style, resourceLoader),
border: IS_INPUT ? _Input.INPUT_BORDERS : (0, _border.parseBorder)(style),
borderRadius: (node instanceof defaultView.HTMLInputElement || node instanceof HTMLInputElement) && IS_INPUT ? (0, _Input.getInputBorderRadius)(node) : (0, _borderRadius.parseBorderRadius)(style),
color: IS_INPUT ? _Input.INPUT_COLOR : new _Color2.default(style.color),
display: display,
float: (0, _float.parseCSSFloat)(style.float),
font: (0, _font.parseFont)(style),
letterSpacing: (0, _letterSpacing.parseLetterSpacing)(style.letterSpacing),
listStyle: display === _display.DISPLAY.LIST_ITEM ? (0, _listStyle.parseListStyle)(style) : null,
lineBreak: (0, _lineBreak.parseLineBreak)(style.lineBreak),
margin: (0, _margin.parseMargin)(style),
opacity: parseFloat(style.opacity),
overflow: INPUT_TAGS.indexOf(node.tagName) === -1 ? (0, _overflow.parseOverflow)(style.overflow) : _overflow.OVERFLOW.HIDDEN,
overflowWrap: (0, _overflowWrap.parseOverflowWrap)(style.overflowWrap ? style.overflowWrap : style.wordWrap),
padding: (0, _padding.parsePadding)(style),
position: position,
textDecoration: (0, _textDecoration.parseTextDecoration)(style),
textShadow: (0, _textShadow.parseTextShadow)(style.textShadow),
textTransform: (0, _textTransform.parseTextTransform)(style.textTransform),
transform: (0, _transform.parseTransform)(style),
visibility: (0, _visibility.parseVisibility)(style.visibility),
wordBreak: (0, _wordBreak.parseWordBreak)(style.wordBreak),
zIndex: (0, _zIndex.parseZIndex)(position !== _position.POSITION.STATIC ? style.zIndex : 'auto')
};
if (this.isTransformed()) {
// getBoundingClientRect provides values post-transform, we want them without the transformation
node.style.transform = 'matrix(1,0,0,1,0,0)';
}
if (display === _display.DISPLAY.LIST_ITEM) {
var listOwner = (0, _ListItem.getListOwner)(this);
if (listOwner) {
var listIndex = listOwner.listItems.length;
listOwner.listItems.push(this);
this.listIndex = node.hasAttribute('value') && typeof node.value === 'number' ? node.value : listIndex === 0 ? typeof listOwner.listStart === 'number' ? listOwner.listStart : 1 : listOwner.listItems[listIndex - 1].listIndex + 1;
}
}
// TODO move bound retrieval for all nodes to a later stage?
if (node.tagName === 'IMG') {
node.addEventListener('load', function () {
_this.bounds = (0, _Bounds.parseBounds)(node, scrollX, scrollY);
_this.curvedBounds = (0, _Bounds.parseBoundCurves)(_this.bounds, _this.style.border, _this.style.borderRadius);
});
}
this.image = getImage(node, resourceLoader);
this.bounds = IS_INPUT ? (0, _Input.reformatInputBounds)((0, _Bounds.parseBounds)(node, scrollX, scrollY)) : (0, _Bounds.parseBounds)(node, scrollX, scrollY);
this.curvedBounds = (0, _Bounds.parseBoundCurves)(this.bounds, this.style.border, this.style.borderRadius);
if (true) {
this.name = '' + node.tagName.toLowerCase() + (node.id ? '#' + node.id : '') + node.className.toString().split(' ').map(function (s) {
return s.length ? '.' + s : '';
}).join('');
}
}
_createClass(NodeContainer, [{
key: 'getClipPaths',
value: function getClipPaths() {
var parentClips = this.parent ? this.parent.getClipPaths() : [];
var isClipped = this.style.overflow !== _overflow.OVERFLOW.VISIBLE;
return isClipped ? parentClips.concat([(0, _Bounds.calculatePaddingBoxPath)(this.curvedBounds)]) : parentClips;
}
}, {
key: 'isInFlow',
value: function isInFlow() {
return this.isRootElement() && !this.isFloating() && !this.isAbsolutelyPositioned();
}
}, {
key: 'isVisible',
value: function isVisible() {
return !(0, _Util.contains)(this.style.display, _display.DISPLAY.NONE) && this.style.opacity > 0 && this.style.visibility === _visibility.VISIBILITY.VISIBLE;
}
}, {
key: 'isAbsolutelyPositioned',
value: function isAbsolutelyPositioned() {
return this.style.position !== _position.POSITION.STATIC && this.style.position !== _position.POSITION.RELATIVE;
}
}, {
key: 'isPositioned',
value: function isPositioned() {
return this.style.position !== _position.POSITION.STATIC;
}
}, {
key: 'isFloating',
value: function isFloating() {
return this.style.float !== _float.FLOAT.NONE;
}
}, {
key: 'isRootElement',
value: function isRootElement() {
return this.parent === null;
}
}, {
key: 'isTransformed',
value: function isTransformed() {
return this.style.transform !== null;
}
}, {
key: 'isPositionedWithZIndex',
value: function isPositionedWithZIndex() {
return this.isPositioned() && !this.style.zIndex.auto;
}
}, {
key: 'isInlineLevel',
value: function isInlineLevel() {
return (0, _Util.contains)(this.style.display, _display.DISPLAY.INLINE) || (0, _Util.contains)(this.style.display, _display.DISPLAY.INLINE_BLOCK) || (0, _Util.contains)(this.style.display, _display.DISPLAY.INLINE_FLEX) || (0, _Util.contains)(this.style.display, _display.DISPLAY.INLINE_GRID) || (0, _Util.contains)(this.style.display, _display.DISPLAY.INLINE_LIST_ITEM) || (0, _Util.contains)(this.style.display, _display.DISPLAY.INLINE_TABLE);
}
}, {
key: 'isInlineBlockOrInlineTable',
value: function isInlineBlockOrInlineTable() {
return (0, _Util.contains)(this.style.display, _display.DISPLAY.INLINE_BLOCK) || (0, _Util.contains)(this.style.display, _display.DISPLAY.INLINE_TABLE);
}
}]);
return NodeContainer;
}();
exports.default = NodeContainer;
var getImage = function getImage(node, resourceLoader) {
if (node instanceof node.ownerDocument.defaultView.SVGSVGElement || node instanceof SVGSVGElement) {
var s = new XMLSerializer();
return resourceLoader.loadImage('data:image/svg+xml,' + encodeURIComponent(s.serializeToString(node)));
}
switch (node.tagName) {
case 'IMG':
// $FlowFixMe
var img = node;
return resourceLoader.loadImage(img.currentSrc || img.src);
case 'CANVAS':
// $FlowFixMe
var canvas = node;
return resourceLoader.loadCanvas(canvas);
case 'IFRAME':
var iframeKey = node.getAttribute('data-html2canvas-internal-iframe-key');
if (iframeKey) {
return iframeKey;
}
break;
}
return null;
};
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _Path = __webpack_require__(5);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Vector = function Vector(x, y) {
_classCallCheck(this, Vector);
this.type = _Path.PATH.VECTOR;
this.x = x;
this.y = y;
if (true) {
if (isNaN(x)) {
console.error('Invalid x value given for Vector');
}
if (isNaN(y)) {
console.error('Invalid y value given for Vector');
}
}
};
exports.default = Vector;
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseListStyle = exports.parseListStyleType = exports.LIST_STYLE_TYPE = exports.LIST_STYLE_POSITION = undefined;
var _background = __webpack_require__(4);
var LIST_STYLE_POSITION = exports.LIST_STYLE_POSITION = {
INSIDE: 0,
OUTSIDE: 1
};
var LIST_STYLE_TYPE = exports.LIST_STYLE_TYPE = {
NONE: -1,
DISC: 0,
CIRCLE: 1,
SQUARE: 2,
DECIMAL: 3,
CJK_DECIMAL: 4,
DECIMAL_LEADING_ZERO: 5,
LOWER_ROMAN: 6,
UPPER_ROMAN: 7,
LOWER_GREEK: 8,
LOWER_ALPHA: 9,
UPPER_ALPHA: 10,
ARABIC_INDIC: 11,
ARMENIAN: 12,
BENGALI: 13,
CAMBODIAN: 14,
CJK_EARTHLY_BRANCH: 15,
CJK_HEAVENLY_STEM: 16,
CJK_IDEOGRAPHIC: 17,
DEVANAGARI: 18,
ETHIOPIC_NUMERIC: 19,
GEORGIAN: 20,
GUJARATI: 21,
GURMUKHI: 22,
HEBREW: 22,
HIRAGANA: 23,
HIRAGANA_IROHA: 24,
JAPANESE_FORMAL: 25,
JAPANESE_INFORMAL: 26,
KANNADA: 27,
KATAKANA: 28,
KATAKANA_IROHA: 29,
KHMER: 30,
KOREAN_HANGUL_FORMAL: 31,
KOREAN_HANJA_FORMAL: 32,
KOREAN_HANJA_INFORMAL: 33,
LAO: 34,
LOWER_ARMENIAN: 35,
MALAYALAM: 36,
MONGOLIAN: 37,
MYANMAR: 38,
ORIYA: 39,
PERSIAN: 40,
SIMP_CHINESE_FORMAL: 41,
SIMP_CHINESE_INFORMAL: 42,
TAMIL: 43,
TELUGU: 44,
THAI: 45,
TIBETAN: 46,
TRAD_CHINESE_FORMAL: 47,
TRAD_CHINESE_INFORMAL: 48,
UPPER_ARMENIAN: 49,
DISCLOSURE_OPEN: 50,
DISCLOSURE_CLOSED: 51
};
var parseListStyleType = exports.parseListStyleType = function parseListStyleType(type) {
switch (type) {
case 'disc':
return LIST_STYLE_TYPE.DISC;
case 'circle':
return LIST_STYLE_TYPE.CIRCLE;
case 'square':
return LIST_STYLE_TYPE.SQUARE;
case 'decimal':
return LIST_STYLE_TYPE.DECIMAL;
case 'cjk-decimal':
return LIST_STYLE_TYPE.CJK_DECIMAL;
case 'decimal-leading-zero':
return LIST_STYLE_TYPE.DECIMAL_LEADING_ZERO;
case 'lower-roman':
return LIST_STYLE_TYPE.LOWER_ROMAN;
case 'upper-roman':
return LIST_STYLE_TYPE.UPPER_ROMAN;
case 'lower-greek':
return LIST_STYLE_TYPE.LOWER_GREEK;
case 'lower-alpha':
return LIST_STYLE_TYPE.LOWER_ALPHA;
case 'upper-alpha':
return LIST_STYLE_TYPE.UPPER_ALPHA;
case 'arabic-indic':
return LIST_STYLE_TYPE.ARABIC_INDIC;
case 'armenian':
return LIST_STYLE_TYPE.ARMENIAN;
case 'bengali':
return LIST_STYLE_TYPE.BENGALI;
case 'cambodian':
return LIST_STYLE_TYPE.CAMBODIAN;
case 'cjk-earthly-branch':
return LIST_STYLE_TYPE.CJK_EARTHLY_BRANCH;
case 'cjk-heavenly-stem':
return LIST_STYLE_TYPE.CJK_HEAVENLY_STEM;
case 'cjk-ideographic':
return LIST_STYLE_TYPE.CJK_IDEOGRAPHIC;
case 'devanagari':
return LIST_STYLE_TYPE.DEVANAGARI;
case 'ethiopic-numeric':
return LIST_STYLE_TYPE.ETHIOPIC_NUMERIC;
case 'georgian':
return LIST_STYLE_TYPE.GEORGIAN;
case 'gujarati':
return LIST_STYLE_TYPE.GUJARATI;
case 'gurmukhi':
return LIST_STYLE_TYPE.GURMUKHI;
case 'hebrew':
return LIST_STYLE_TYPE.HEBREW;
case 'hiragana':
return LIST_STYLE_TYPE.HIRAGANA;
case 'hiragana-iroha':
return LIST_STYLE_TYPE.HIRAGANA_IROHA;
case 'japanese-formal':
return LIST_STYLE_TYPE.JAPANESE_FORMAL;
case 'japanese-informal':
return LIST_STYLE_TYPE.JAPANESE_INFORMAL;
case 'kannada':
return LIST_STYLE_TYPE.KANNADA;
case 'katakana':
return LIST_STYLE_TYPE.KATAKANA;
case 'katakana-iroha':
return LIST_STYLE_TYPE.KATAKANA_IROHA;
case 'khmer':
return LIST_STYLE_TYPE.KHMER;
case 'korean-hangul-formal':
return LIST_STYLE_TYPE.KOREAN_HANGUL_FORMAL;
case 'korean-hanja-formal':
return LIST_STYLE_TYPE.KOREAN_HANJA_FORMAL;
case 'korean-hanja-informal':
return LIST_STYLE_TYPE.KOREAN_HANJA_INFORMAL;
case 'lao':
return LIST_STYLE_TYPE.LAO;
case 'lower-armenian':
return LIST_STYLE_TYPE.LOWER_ARMENIAN;
case 'malayalam':
return LIST_STYLE_TYPE.MALAYALAM;
case 'mongolian':
return LIST_STYLE_TYPE.MONGOLIAN;
case 'myanmar':
return LIST_STYLE_TYPE.MYANMAR;
case 'oriya':
return LIST_STYLE_TYPE.ORIYA;
case 'persian':
return LIST_STYLE_TYPE.PERSIAN;
case 'simp-chinese-formal':
return LIST_STYLE_TYPE.SIMP_CHINESE_FORMAL;
case 'simp-chinese-informal':
return LIST_STYLE_TYPE.SIMP_CHINESE_INFORMAL;
case 'tamil':
return LIST_STYLE_TYPE.TAMIL;
case 'telugu':
return LIST_STYLE_TYPE.TELUGU;
case 'thai':
return LIST_STYLE_TYPE.THAI;
case 'tibetan':
return LIST_STYLE_TYPE.TIBETAN;
case 'trad-chinese-formal':
return LIST_STYLE_TYPE.TRAD_CHINESE_FORMAL;
case 'trad-chinese-informal':
return LIST_STYLE_TYPE.TRAD_CHINESE_INFORMAL;
case 'upper-armenian':
return LIST_STYLE_TYPE.UPPER_ARMENIAN;
case 'disclosure-open':
return LIST_STYLE_TYPE.DISCLOSURE_OPEN;
case 'disclosure-closed':
return LIST_STYLE_TYPE.DISCLOSURE_CLOSED;
case 'none':
default:
return LIST_STYLE_TYPE.NONE;
}
};
var parseListStyle = exports.parseListStyle = function parseListStyle(style) {
var listStyleImage = (0, _background.parseBackgroundImage)(style.getPropertyValue('list-style-image'));
return {
listStyleType: parseListStyleType(style.getPropertyValue('list-style-type')),
listStyleImage: listStyleImage.length ? listStyleImage[0] : null,
listStylePosition: parseListStylePosition(style.getPropertyValue('list-style-position'))
};
};
var parseListStylePosition = function parseListStylePosition(position) {
switch (position) {
case 'inside':
return LIST_STYLE_POSITION.INSIDE;
case 'outside':
default:
return LIST_STYLE_POSITION.OUTSIDE;
}
};
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _textTransform = __webpack_require__(20);
var _TextBounds = __webpack_require__(22);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var TextContainer = function () {
function TextContainer(text, parent, bounds) {
_classCallCheck(this, TextContainer);
this.text = text;
this.parent = parent;
this.bounds = bounds;
}
_createClass(TextContainer, null, [{
key: 'fromTextNode',
value: function fromTextNode(node, parent) {
var text = transform(node.data, parent.style.textTransform);
return new TextContainer(text, parent, (0, _TextBounds.parseTextBounds)(text, parent, node));
}
}]);
return TextContainer;
}();
exports.default = TextContainer;
var CAPITALIZE = /(^|\s|:|-|\(|\))([a-z])/g;
var transform = function transform(text, _transform) {
switch (_transform) {
case _textTransform.TEXT_TRANSFORM.LOWERCASE:
return text.toLowerCase();
case _textTransform.TEXT_TRANSFORM.CAPITALIZE:
return text.replace(CAPITALIZE, capitalize);
case _textTransform.TEXT_TRANSFORM.UPPERCASE:
return text.toUpperCase();
default:
return text;
}
};
function capitalize(m, p1, p2) {
if (m.length > 0) {
return p1 + p2.toUpperCase();
}
return m;
}
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _ForeignObjectRenderer = __webpack_require__(23);
var testRangeBounds = function testRangeBounds(document) {
var TEST_HEIGHT = 123;
if (document.createRange) {
var range = document.createRange();
if (range.getBoundingClientRect) {
var testElement = document.createElement('boundtest');
testElement.style.height = TEST_HEIGHT + 'px';
testElement.style.display = 'block';
document.body.appendChild(testElement);
range.selectNode(testElement);
var rangeBounds = range.getBoundingClientRect();
var rangeHeight = Math.round(rangeBounds.height);
document.body.removeChild(testElement);
if (rangeHeight === TEST_HEIGHT) {
return true;
}
}
}
return false;
};
// iOS 10.3 taints canvas with base64 images unless crossOrigin = 'anonymous'
var testBase64 = function testBase64(document, src) {
var img = new Image();
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
return new Promise(function (resolve) {
// Single pixel base64 image renders fine on iOS 10.3???
img.src = src;
//ios safari 10.3 taints canvas with data urls unless crossOrigin is set to anonymous
if (!supportsDataImages || useCORS) {
img.setAttribute('crossOrigin', 'anonymous');
img.crossOrigin = 'anonymous';
}
var onload = function onload() {
try {
ctx.drawImage(img, 0, 0);
canvas.toDataURL();
} catch (e) {
return resolve(false);
}
return resolve(true);
};
img.onload = onload;
img.onerror = function () {
return resolve(false);
};
if (img.complete === true) {
setTimeout(function () {
onload();
}, 500);
}
});
};
var testCORS = function testCORS() {
return typeof new Image().crossOrigin !== 'undefined';
};
var testResponseType = function testResponseType() {
return typeof new XMLHttpRequest().responseType === 'string';
};
var testSVG = function testSVG(document) {
var img = new Image();
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
img.src = 'data:image/svg+xml,<svg xmlns=\'http://www.w3.org/2000/svg\'></svg>';
try {
ctx.drawImage(img, 0, 0);
canvas.toDataURL();
} catch (e) {
return false;
}
return true;
};
var isGreenPixel = function isGreenPixel(data) {
return data[0] === 0 && data[1] === 255 && data[2] === 0 && data[3] === 255;
};
var testForeignObject = function testForeignObject(document) {
var canvas = document.createElement('canvas');
var size = 100;
canvas.width = size;
canvas.height = size;
var ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgb(0, 255, 0)';
ctx.fillRect(0, 0, size, size);
var img = new Image();
var greenImageSrc = canvas.toDataURL();
img.src = greenImageSrc;
var svg = (0, _ForeignObjectRenderer.createForeignObjectSVG)(size, size, 0, 0, img);
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, size, size);
return (0, _ForeignObjectRenderer.loadSerializedSVG)(svg).then(function (img) {
ctx.drawImage(img, 0, 0);
var data = ctx.getImageData(0, 0, size, size).data;
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, size, size);
var node = document.createElement('div');
node.style.backgroundImage = 'url(' + greenImageSrc + ')';
node.style.height = size + 'px';
// Firefox 55 does not render inline <img /> tags
return isGreenPixel(data) ? (0, _ForeignObjectRenderer.loadSerializedSVG)((0, _ForeignObjectRenderer.createForeignObjectSVG)(size, size, 0, 0, node)) : Promise.reject(false);
}).then(function (img) {
ctx.drawImage(img, 0, 0);
// Edge does not render background-images
return isGreenPixel(ctx.getImageData(0, 0, size, size).data);
}).catch(function (e) {
return false;
});
};
var FEATURES = {
// $FlowFixMe - get/set properties not yet supported
get SUPPORT_RANGE_BOUNDS() {
'use strict';
var value = testRangeBounds(document);
Object.defineProperty(FEATURES, 'SUPPORT_RANGE_BOUNDS', { value: value });
return value;
},
// $FlowFixMe - get/set properties not yet supported
get SUPPORT_SVG_DRAWING() {
'use strict';
var value = testSVG(document);
Object.defineProperty(FEATURES, 'SUPPORT_SVG_DRAWING', { value: value });
return value;
},
// $FlowFixMe - get/set properties not yet supported
get SUPPORT_BASE64_DRAWING() {
'use strict';
return function (src) {
var _value = testBase64(document, src);
Object.defineProperty(FEATURES, 'SUPPORT_BASE64_DRAWING', { value: function value() {
return _value;
} });
return _value;
};
},
// $FlowFixMe - get/set properties not yet supported
get SUPPORT_FOREIGNOBJECT_DRAWING() {
'use strict';
var value = typeof Array.from === 'function' && typeof window.fetch === 'function' ? testForeignObject(document) : Promise.resolve(false);
Object.defineProperty(FEATURES, 'SUPPORT_FOREIGNOBJECT_DRAWING', { value: value });
return value;
},
// $FlowFixMe - get/set properties not yet supported
get SUPPORT_CORS_IMAGES() {
'use strict';
var value = testCORS();
Object.defineProperty(FEATURES, 'SUPPORT_CORS_IMAGES', { value: value });
return value;
},
// $FlowFixMe - get/set properties not yet supported
get SUPPORT_RESPONSE_TYPE() {
'use strict';
var value = testResponseType();
Object.defineProperty(FEATURES, 'SUPPORT_RESPONSE_TYPE', { value: value });
return value;
},
// $FlowFixMe - get/set properties not yet supported
get SUPPORT_CORS_XHR() {
'use strict';
var value = 'withCredentials' in new XMLHttpRequest();
Object.defineProperty(FEATURES, 'SUPPORT_CORS_XHR', { value: value });
return value;
}
};
exports.default = FEATURES;
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseTextDecoration = exports.TEXT_DECORATION_LINE = exports.TEXT_DECORATION = exports.TEXT_DECORATION_STYLE = undefined;
var _Color = __webpack_require__(0);
var _Color2 = _interopRequireDefault(_Color);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var TEXT_DECORATION_STYLE = exports.TEXT_DECORATION_STYLE = {
SOLID: 0,
DOUBLE: 1,
DOTTED: 2,
DASHED: 3,
WAVY: 4
};
var TEXT_DECORATION = exports.TEXT_DECORATION = {
NONE: null
};
var TEXT_DECORATION_LINE = exports.TEXT_DECORATION_LINE = {
UNDERLINE: 1,
OVERLINE: 2,
LINE_THROUGH: 3,
BLINK: 4
};
var parseLine = function parseLine(line) {
switch (line) {
case 'underline':
return TEXT_DECORATION_LINE.UNDERLINE;
case 'overline':
return TEXT_DECORATION_LINE.OVERLINE;
case 'line-through':
return TEXT_DECORATION_LINE.LINE_THROUGH;
}
return TEXT_DECORATION_LINE.BLINK;
};
var parseTextDecorationLine = function parseTextDecorationLine(line) {
if (line === 'none') {
return null;
}
return line.split(' ').map(parseLine);
};
var parseTextDecorationStyle = function parseTextDecorationStyle(style) {
switch (style) {
case 'double':
return TEXT_DECORATION_STYLE.DOUBLE;
case 'dotted':
return TEXT_DECORATION_STYLE.DOTTED;
case 'dashed':
return TEXT_DECORATION_STYLE.DASHED;
case 'wavy':
return TEXT_DECORATION_STYLE.WAVY;
}
return TEXT_DECORATION_STYLE.SOLID;
};
var parseTextDecoration = exports.parseTextDecoration = function parseTextDecoration(style) {
var textDecorationLine = parseTextDecorationLine(style.textDecorationLine ? style.textDecorationLine : style.textDecoration);
if (textDecorationLine === null) {
return TEXT_DECORATION.NONE;
}
var textDecorationColor = style.textDecorationColor ? new _Color2.default(style.textDecorationColor) : null;
var textDecorationStyle = parseTextDecorationStyle(style.textDecorationStyle);
return {
textDecorationLine: textDecorationLine,
textDecorationColor: textDecorationColor,
textDecorationStyle: textDecorationStyle
};
};
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseBorder = exports.BORDER_SIDES = exports.BORDER_STYLE = undefined;
var _Color = __webpack_require__(0);
var _Color2 = _interopRequireDefault(_Color);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var BORDER_STYLE = exports.BORDER_STYLE = {
NONE: 0,
SOLID: 1
};
var BORDER_SIDES = exports.BORDER_SIDES = {
TOP: 0,
RIGHT: 1,
BOTTOM: 2,
LEFT: 3
};
var SIDES = Object.keys(BORDER_SIDES).map(function (s) {
return s.toLowerCase();
});
var parseBorderStyle = function parseBorderStyle(style) {
switch (style) {
case 'none':
return BORDER_STYLE.NONE;
}
return BORDER_STYLE.SOLID;
};
var parseBorder = exports.parseBorder = function parseBorder(style) {
return SIDES.map(function (side) {
var borderColor = new _Color2.default(style.getPropertyValue('border-' + side + '-color'));
var borderStyle = parseBorderStyle(style.getPropertyValue('border-' + side + '-style'));
var borderWidth = parseFloat(style.getPropertyValue('border-' + side + '-width'));
return {
borderColor: borderColor,
borderStyle: borderStyle,
borderWidth: isNaN(borderWidth) ? 0 : borderWidth
};
});
};
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var toCodePoints = exports.toCodePoints = function toCodePoints(str) {
var codePoints = [];
var i = 0;
var length = str.length;
while (i < length) {
var value = str.charCodeAt(i++);
if (value >= 0xd800 && value <= 0xdbff && i < length) {
var extra = str.charCodeAt(i++);
if ((extra & 0xfc00) === 0xdc00) {
codePoints.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);
} else {
codePoints.push(value);
i--;
}
} else {
codePoints.push(value);
}
}
return codePoints;
};
var fromCodePoint = exports.fromCodePoint = function fromCodePoint() {
if (String.fromCodePoint) {
return String.fromCodePoint.apply(String, arguments);
}
var length = arguments.length;
if (!length) {
return '';
}
var codeUnits = [];
var index = -1;
var result = '';
while (++index < length) {
var codePoint = arguments.length <= index ? undefined : arguments[index];
if (codePoint <= 0xffff) {
codeUnits.push(codePoint);
} else {
codePoint -= 0x10000;
codeUnits.push((codePoint >> 10) + 0xd800, codePoint % 0x400 + 0xdc00);
}
if (index + 1 === length || codeUnits.length > 0x4000) {
result += String.fromCharCode.apply(String, codeUnits);
codeUnits.length = 0;
}
}
return result;
};
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
var decode = exports.decode = function decode(base64) {
var bufferLength = base64.length * 0.75,
len = base64.length,
i = void 0,
p = 0,
encoded1 = void 0,
encoded2 = void 0,
encoded3 = void 0,
encoded4 = void 0;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var buffer = typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined' && typeof Uint8Array.prototype.slice !== 'undefined' ? new ArrayBuffer(bufferLength) : new Array(bufferLength);
var bytes = Array.isArray(buffer) ? buffer : new Uint8Array(buffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = encoded1 << 2 | encoded2 >> 4;
bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
}
return buffer;
};
var polyUint16Array = exports.polyUint16Array = function polyUint16Array(buffer) {
var length = buffer.length;
var bytes = [];
for (var _i = 0; _i < length; _i += 2) {
bytes.push(buffer[_i + 1] << 8 | buffer[_i]);
}
return bytes;
};
var polyUint32Array = exports.polyUint32Array = function polyUint32Array(buffer) {
var length = buffer.length;
var bytes = [];
for (var _i2 = 0; _i2 < length; _i2 += 4) {
bytes.push(buffer[_i2 + 3] << 24 | buffer[_i2 + 2] << 16 | buffer[_i2 + 1] << 8 | buffer[_i2]);
}
return bytes;
};
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createCounterText = exports.inlineListItemElement = exports.getListOwner = undefined;
var _Util = __webpack_require__(3);
var _NodeContainer = __webpack_require__(6);
var _NodeContainer2 = _interopRequireDefault(_NodeContainer);
var _TextContainer = __webpack_require__(9);
var _TextContainer2 = _interopRequireDefault(_TextContainer);
var _listStyle = __webpack_require__(8);
var _Unicode = __webpack_require__(24);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Margin between the enumeration and the list item content
var MARGIN_RIGHT = 7;
var ancestorTypes = ['OL', 'UL', 'MENU'];
var getListOwner = exports.getListOwner = function getListOwner(container) {
var parent = container.parent;
if (!parent) {
return null;
}
do {
var isAncestor = ancestorTypes.indexOf(parent.tagName) !== -1;
if (isAncestor) {
return parent;
}
parent = parent.parent;
} while (parent);
return container.parent;
};
var inlineListItemElement = exports.inlineListItemElement = function inlineListItemElement(node, container, resourceLoader) {
var listStyle = container.style.listStyle;
if (!listStyle) {
return;
}
var style = node.ownerDocument.defaultView.getComputedStyle(node, null);
var wrapper = node.ownerDocument.createElement('html2canvaswrapper');
(0, _Util.copyCSSStyles)(style, wrapper);
wrapper.style.position = 'absolute';
wrapper.style.bottom = 'auto';
wrapper.style.display = 'block';
wrapper.style.letterSpacing = 'normal';
switch (listStyle.listStylePosition) {
case _listStyle.LIST_STYLE_POSITION.OUTSIDE:
wrapper.style.left = 'auto';
wrapper.style.right = node.ownerDocument.defaultView.innerWidth - container.bounds.left - container.style.margin[1].getAbsoluteValue(container.bounds.width) + MARGIN_RIGHT + 'px';
wrapper.style.textAlign = 'right';
break;
case _listStyle.LIST_STYLE_POSITION.INSIDE:
wrapper.style.left = container.bounds.left - container.style.margin[3].getAbsoluteValue(container.bounds.width) + 'px';
wrapper.style.right = 'auto';
wrapper.style.textAlign = 'left';
break;
}
var text = void 0;
var MARGIN_TOP = container.style.margin[0].getAbsoluteValue(container.bounds.width);
var styleImage = listStyle.listStyleImage;
if (styleImage) {
if (styleImage.method === 'url') {
var image = node.ownerDocument.createElement('img');
image.src = styleImage.args[0];
wrapper.style.top = container.bounds.top - MARGIN_TOP + 'px';
wrapper.style.width = 'auto';
wrapper.style.height = 'auto';
wrapper.appendChild(image);
} else {
var size = parseFloat(container.style.font.fontSize) * 0.5;
wrapper.style.top = container.bounds.top - MARGIN_TOP + container.bounds.height - 1.5 * size + 'px';
wrapper.style.width = size + 'px';
wrapper.style.height = size + 'px';
wrapper.style.backgroundImage = style.listStyleImage;
}
} else if (typeof container.listIndex === 'number') {
text = node.ownerDocument.createTextNode(createCounterText(container.listIndex, listStyle.listStyleType, true));
wrapper.appendChild(text);
wrapper.style.top = container.bounds.top - MARGIN_TOP + 'px';
}
// $FlowFixMe
var body = node.ownerDocument.body;
body.appendChild(wrapper);
if (text) {
container.childNodes.push(_TextContainer2.default.fromTextNode(text, container));
body.removeChild(wrapper);
} else {
// $FlowFixMe
container.childNodes.push(new _NodeContainer2.default(wrapper, container, resourceLoader, 0));
}
};
var ROMAN_UPPER = {
integers: [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1],
values: ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
};
var ARMENIAN = {
integers: [9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
values: ['Ք', 'Փ', 'Ւ', 'Ց', 'Ր', 'Տ', 'Վ', 'Ս', 'Ռ', 'Ջ', 'Պ', 'Չ', 'Ո', 'Շ', 'Ն', 'Յ', 'Մ', 'Ճ', 'Ղ', 'Ձ', 'Հ', 'Կ', 'Ծ', 'Խ', 'Լ', 'Ի', 'Ժ', 'Թ', 'Ը', 'Է', 'Զ', 'Ե', 'Դ', 'Գ', 'Բ', 'Ա']
};
var HEBREW = {
integers: [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, 19, 18, 17, 16, 15, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
values: ['י׳', 'ט׳', 'ח׳', 'ז׳', 'ו׳', 'ה׳', 'ד׳', 'ג׳', 'ב׳', 'א׳', 'ת', 'ש', 'ר', 'ק', 'צ', 'פ', 'ע', 'ס', 'נ', 'מ', 'ל', 'כ', 'יט', 'יח', 'יז', 'טז', 'טו', 'י', 'ט', 'ח', 'ז', 'ו', 'ה', 'ד', 'ג', 'ב', 'א']
};
var GEORGIAN = {
integers: [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
values: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
};
var createAdditiveCounter = function createAdditiveCounter(value, min, max, symbols, fallback, suffix) {
if (value < min || value > max) {
return createCounterText(value, fallback, suffix.length > 0);
}
return symbols.integers.reduce(function (string, integer, index) {
while (value >= integer) {
value -= integer;
string += symbols.values[index];
}
return string;
}, '') + suffix;
};
var createCounterStyleWithSymbolResolver = function createCounterStyleWithSymbolResolver(value, codePointRangeLength, isNumeric, resolver) {
var string = '';
do {
if (!isNumeric) {
value--;
}
string = resolver(value) + string;
value /= codePointRangeLength;
} while (value * codePointRangeLength >= codePointRangeLength);
return string;
};
var createCounterStyleFromRange = function createCounterStyleFromRange(value, codePointRangeStart, codePointRangeEnd, isNumeric, suffix) {
var codePointRangeLength = codePointRangeEnd - codePointRangeStart + 1;
return (value < 0 ? '-' : '') + (createCounterStyleWithSymbolResolver(Math.abs(value), codePointRangeLength, isNumeric, function (codePoint) {
return (0, _Unicode.fromCodePoint)(Math.floor(codePoint % codePointRangeLength) + codePointRangeStart);
}) + suffix);
};
var createCounterStyleFromSymbols = function createCounterStyleFromSymbols(value, symbols) {
var suffix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '. ';
var codePointRangeLength = symbols.length;
return createCounterStyleWithSymbolResolver(Math.abs(value), codePointRangeLength, false, function (codePoint) {
return symbols[Math.floor(codePoint % codePointRangeLength)];
}) + suffix;
};
var CJK_ZEROS = 1 << 0;
var CJK_TEN_COEFFICIENTS = 1 << 1;
var CJK_TEN_HIGH_COEFFICIENTS = 1 << 2;
var CJK_HUNDRED_COEFFICIENTS = 1 << 3;
var createCJKCounter = function createCJKCounter(value, numbers, multipliers, negativeSign, suffix, flags) {
if (value < -9999 || value > 9999) {
return createCounterText(value, _listStyle.LIST_STYLE_TYPE.CJK_DECIMAL, suffix.length > 0);
}
var tmp = Math.abs(value);
var string = suffix;
if (tmp === 0) {
return numbers[0] + string;
}
for (var digit = 0; tmp > 0 && digit <= 4; digit++) {
var coefficient = tmp % 10;
if (coefficient === 0 && (0, _Util.contains)(flags, CJK_ZEROS) && string !== '') {
string = numbers[coefficient] + string;
} else if (coefficient > 1 || coefficient === 1 && digit === 0 || coefficient === 1 && digit === 1 && (0, _Util.contains)(flags, CJK_TEN_COEFFICIENTS) || coefficient === 1 && digit === 1 && (0, _Util.contains)(flags, CJK_TEN_HIGH_COEFFICIENTS) && value > 100 || coefficient === 1 && digit > 1 && (0, _Util.contains)(flags, CJK_HUNDRED_COEFFICIENTS)) {
string = numbers[coefficient] + (digit > 0 ? multipliers[digit - 1] : '') + string;
} else if (coefficient === 1 && digit > 0) {
string = multipliers[digit - 1] + string;
}
tmp = Math.floor(tmp / 10);
}
return (value < 0 ? negativeSign : '') + string;
};
var CHINESE_INFORMAL_MULTIPLIERS = '十百千萬';
var CHINESE_FORMAL_MULTIPLIERS = '拾佰仟萬';
var JAPANESE_NEGATIVE = 'マイナス';
var KOREAN_NEGATIVE = '마이너스 ';
var createCounterText = exports.createCounterText = function createCounterText(value, type, appendSuffix) {
var defaultSuffix = appendSuffix ? '. ' : '';
var cjkSuffix = appendSuffix ? '' : '';
var koreanSuffix = appendSuffix ? ', ' : '';
switch (type) {
case _listStyle.LIST_STYLE_TYPE.DISC:
return '';
case _listStyle.LIST_STYLE_TYPE.CIRCLE:
return '';
case _listStyle.LIST_STYLE_TYPE.SQUARE:
return '';
case _listStyle.LIST_STYLE_TYPE.DECIMAL_LEADING_ZERO:
var string = createCounterStyleFromRange(value, 48, 57, true, defaultSuffix);
return string.length < 4 ? '0' + string : string;
case _listStyle.LIST_STYLE_TYPE.CJK_DECIMAL:
return createCounterStyleFromSymbols(value, '〇一二三四五六七八九', cjkSuffix);
case _listStyle.LIST_STYLE_TYPE.LOWER_ROMAN:
return createAdditiveCounter(value, 1, 3999, ROMAN_UPPER, _listStyle.LIST_STYLE_TYPE.DECIMAL, defaultSuffix).toLowerCase();
case _listStyle.LIST_STYLE_TYPE.UPPER_ROMAN:
return createAdditiveCounter(value, 1, 3999, ROMAN_UPPER, _listStyle.LIST_STYLE_TYPE.DECIMAL, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.LOWER_GREEK:
return createCounterStyleFromRange(value, 945, 969, false, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.LOWER_ALPHA:
return createCounterStyleFromRange(value, 97, 122, false, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.UPPER_ALPHA:
return createCounterStyleFromRange(value, 65, 90, false, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.ARABIC_INDIC:
return createCounterStyleFromRange(value, 1632, 1641, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.ARMENIAN:
case _listStyle.LIST_STYLE_TYPE.UPPER_ARMENIAN:
return createAdditiveCounter(value, 1, 9999, ARMENIAN, _listStyle.LIST_STYLE_TYPE.DECIMAL, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.LOWER_ARMENIAN:
return createAdditiveCounter(value, 1, 9999, ARMENIAN, _listStyle.LIST_STYLE_TYPE.DECIMAL, defaultSuffix).toLowerCase();
case _listStyle.LIST_STYLE_TYPE.BENGALI:
return createCounterStyleFromRange(value, 2534, 2543, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.CAMBODIAN:
case _listStyle.LIST_STYLE_TYPE.KHMER:
return createCounterStyleFromRange(value, 6112, 6121, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.CJK_EARTHLY_BRANCH:
return createCounterStyleFromSymbols(value, '子丑寅卯辰巳午未申酉戌亥', cjkSuffix);
case _listStyle.LIST_STYLE_TYPE.CJK_HEAVENLY_STEM:
return createCounterStyleFromSymbols(value, '甲乙丙丁戊己庚辛壬癸', cjkSuffix);
case _listStyle.LIST_STYLE_TYPE.CJK_IDEOGRAPHIC:
case _listStyle.LIST_STYLE_TYPE.TRAD_CHINESE_INFORMAL:
return createCJKCounter(value, '零一二三四五六七八九', CHINESE_INFORMAL_MULTIPLIERS, '', cjkSuffix, CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
case _listStyle.LIST_STYLE_TYPE.TRAD_CHINESE_FORMAL:
return createCJKCounter(value, '零壹貳參肆伍陸柒捌玖', CHINESE_FORMAL_MULTIPLIERS, '', cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
case _listStyle.LIST_STYLE_TYPE.SIMP_CHINESE_INFORMAL:
return createCJKCounter(value, '零一二三四五六七八九', CHINESE_INFORMAL_MULTIPLIERS, '', cjkSuffix, CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
case _listStyle.LIST_STYLE_TYPE.SIMP_CHINESE_FORMAL:
return createCJKCounter(value, '零壹贰叁肆伍陆柒捌玖', CHINESE_FORMAL_MULTIPLIERS, '', cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
case _listStyle.LIST_STYLE_TYPE.JAPANESE_INFORMAL:
return createCJKCounter(value, '〇一二三四五六七八九', '十百千万', JAPANESE_NEGATIVE, cjkSuffix, 0);
case _listStyle.LIST_STYLE_TYPE.JAPANESE_FORMAL:
return createCJKCounter(value, '零壱弐参四伍六七八九', '拾百千万', JAPANESE_NEGATIVE, cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS);
case _listStyle.LIST_STYLE_TYPE.KOREAN_HANGUL_FORMAL:
return createCJKCounter(value, '영일이삼사오육칠팔구', '십백천만', KOREAN_NEGATIVE, koreanSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS);
case _listStyle.LIST_STYLE_TYPE.KOREAN_HANJA_INFORMAL:
return createCJKCounter(value, '零一二三四五六七八九', '十百千萬', KOREAN_NEGATIVE, koreanSuffix, 0);
case _listStyle.LIST_STYLE_TYPE.KOREAN_HANJA_FORMAL:
return createCJKCounter(value, '零壹貳參四五六七八九', '拾百千', KOREAN_NEGATIVE, koreanSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS);
case _listStyle.LIST_STYLE_TYPE.DEVANAGARI:
return createCounterStyleFromRange(value, 0x966, 0x96f, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.GEORGIAN:
return createAdditiveCounter(value, 1, 19999, GEORGIAN, _listStyle.LIST_STYLE_TYPE.DECIMAL, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.GUJARATI:
return createCounterStyleFromRange(value, 0xae6, 0xaef, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.GURMUKHI:
return createCounterStyleFromRange(value, 0xa66, 0xa6f, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.HEBREW:
return createAdditiveCounter(value, 1, 10999, HEBREW, _listStyle.LIST_STYLE_TYPE.DECIMAL, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.HIRAGANA:
return createCounterStyleFromSymbols(value, 'あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわゐゑをん');
case _listStyle.LIST_STYLE_TYPE.HIRAGANA_IROHA:
return createCounterStyleFromSymbols(value, 'いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす');
case _listStyle.LIST_STYLE_TYPE.KANNADA:
return createCounterStyleFromRange(value, 0xce6, 0xcef, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.KATAKANA:
return createCounterStyleFromSymbols(value, 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヰヱヲン', cjkSuffix);
case _listStyle.LIST_STYLE_TYPE.KATAKANA_IROHA:
return createCounterStyleFromSymbols(value, 'イロハニホヘトチリヌルヲワカヨタレソツネナラムウヰノオクヤマケフコエテアサキユメミシヱヒモセス', cjkSuffix);
case _listStyle.LIST_STYLE_TYPE.LAO:
return createCounterStyleFromRange(value, 0xed0, 0xed9, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.MONGOLIAN:
return createCounterStyleFromRange(value, 0x1810, 0x1819, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.MYANMAR:
return createCounterStyleFromRange(value, 0x1040, 0x1049, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.ORIYA:
return createCounterStyleFromRange(value, 0xb66, 0xb6f, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.PERSIAN:
return createCounterStyleFromRange(value, 0x6f0, 0x6f9, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.TAMIL:
return createCounterStyleFromRange(value, 0xbe6, 0xbef, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.TELUGU:
return createCounterStyleFromRange(value, 0xc66, 0xc6f, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.THAI:
return createCounterStyleFromRange(value, 0xe50, 0xe59, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.TIBETAN:
return createCounterStyleFromRange(value, 0xf20, 0xf29, true, defaultSuffix);
case _listStyle.LIST_STYLE_TYPE.DECIMAL:
default:
return createCounterStyleFromRange(value, 48, 57, true, defaultSuffix);
}
};
/***/ }),
/* 15 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Path = __webpack_require__(5);
var _textDecoration = __webpack_require__(11);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var addColorStops = function addColorStops(gradient, canvasGradient) {
var maxStop = Math.max.apply(null, gradient.colorStops.map(function (colorStop) {
return colorStop.stop;
}));
var f = 1 / Math.max(1, maxStop);
gradient.colorStops.forEach(function (colorStop) {
canvasGradient.addColorStop(f * colorStop.stop, colorStop.color.toString());
});
};
var CanvasRenderer = function () {
function CanvasRenderer(canvas) {
_classCallCheck(this, CanvasRenderer);
this.canvas = canvas ? canvas : document.createElement('canvas');
}
_createClass(CanvasRenderer, [{
key: 'render',
value: function render(options) {
this.ctx = this.canvas.getContext('2d');
this.options = options;
this.canvas.width = Math.floor(options.width * options.scale);
this.canvas.height = Math.floor(options.height * options.scale);
this.canvas.style.width = options.width + 'px';
this.canvas.style.height = options.height + 'px';
this.ctx.scale(this.options.scale, this.options.scale);
this.ctx.translate(-options.x, -options.y);
this.ctx.textBaseline = 'bottom';
options.logger.log('Canvas renderer initialized (' + options.width + 'x' + options.height + ' at ' + options.x + ',' + options.y + ') with scale ' + this.options.scale);
}
}, {
key: 'clip',
value: function clip(clipPaths, callback) {
var _this = this;
if (clipPaths.length) {
this.ctx.save();
clipPaths.forEach(function (path) {
_this.path(path);
_this.ctx.clip();
});
}
callback();
if (clipPaths.length) {
this.ctx.restore();
}
}
}, {
// key: 'drawImage',
// value: function drawImage(image, source, destination) {
// this.ctx.drawImage(image, source.left, source.top, source.width, source.height, destination.left, destination.top, destination.width, destination.height);
// }
key: 'drawImage',
value: function drawImage(image, source, destination) {
/**START CUSTOM CODE**/
var newWidth = 30;
var newHeight = 30;
var newX = destination.left;
var newY = destination.top;
// console.log(image, source, destination);
if (source.width/destination.width > source.height/destination.height) {
newWidth = destination.width;
newHeight = source.height * (destination.width / source.width);
newY = destination.top + (destination.height - newHeight) / 2;
} else {
newWidth = source.width * (destination.height / source.height);
newHeight = destination.height;
newX = destination.left + (destination.width - newWidth) / 2;
}
// console.log(newWidth, newHeight);
this.ctx.drawImage(image, source.left, source.top, source.width, source.height, newX, newY, newWidth, newHeight);
/**END CUSTOM CODE**/
}
}, {
key: 'drawShape',
value: function drawShape(path, color) {
this.path(path);
this.ctx.fillStyle = color.toString();
this.ctx.fill();
}
}, {
key: 'fill',
value: function fill(color) {
this.ctx.fillStyle = color.toString();
this.ctx.fill();
}
}, {
key: 'getTarget',
value: function getTarget() {
this.canvas.getContext('2d').setTransform(1, 0, 0, 1, 0, 0);
return Promise.resolve(this.canvas);
}
}, {
key: 'path',
value: function path(_path) {
var _this2 = this;
this.ctx.beginPath();
if (Array.isArray(_path)) {
_path.forEach(function (point, index) {
var start = point.type === _Path.PATH.VECTOR ? point : point.start;
if (index === 0) {
_this2.ctx.moveTo(start.x, start.y);
} else {
_this2.ctx.lineTo(start.x, start.y);
}
if (point.type === _Path.PATH.BEZIER_CURVE) {
_this2.ctx.bezierCurveTo(point.startControl.x, point.startControl.y, point.endControl.x, point.endControl.y, point.end.x, point.end.y);
}
});
} else {
this.ctx.arc(_path.x + _path.radius, _path.y + _path.radius, _path.radius, 0, Math.PI * 2, true);
}
this.ctx.closePath();
}
}, {
key: 'rectangle',
value: function rectangle(x, y, width, height, color) {
this.ctx.fillStyle = color.toString();
this.ctx.fillRect(x, y, width, height);
}
}, {
key: 'renderLinearGradient',
value: function renderLinearGradient(bounds, gradient) {
var linearGradient = this.ctx.createLinearGradient(bounds.left + gradient.direction.x1, bounds.top + gradient.direction.y1, bounds.left + gradient.direction.x0, bounds.top + gradient.direction.y0);
addColorStops(gradient, linearGradient);
this.ctx.fillStyle = linearGradient;
this.ctx.fillRect(bounds.left, bounds.top, bounds.width, bounds.height);
}
}, {
key: 'renderRadialGradient',
value: function renderRadialGradient(bounds, gradient) {
var _this3 = this;
var x = bounds.left + gradient.center.x;
var y = bounds.top + gradient.center.y;
var radialGradient = this.ctx.createRadialGradient(x, y, 0, x, y, gradient.radius.x);
if (!radialGradient) {
return;
}
addColorStops(gradient, radialGradient);
this.ctx.fillStyle = radialGradient;
if (gradient.radius.x !== gradient.radius.y) {
// transforms for elliptical radial gradient
var midX = bounds.left + 0.5 * bounds.width;
var midY = bounds.top + 0.5 * bounds.height;
var f = gradient.radius.y / gradient.radius.x;
var invF = 1 / f;
this.transform(midX, midY, [1, 0, 0, f, 0, 0], function () {
return _this3.ctx.fillRect(bounds.left, invF * (bounds.top - midY) + midY, bounds.width, bounds.height * invF);
});
} else {
this.ctx.fillRect(bounds.left, bounds.top, bounds.width, bounds.height);
}
}
}, {
key: 'renderRepeat',
value: function renderRepeat(path, image, imageSize, offsetX, offsetY) {
this.path(path);
this.ctx.fillStyle = this.ctx.createPattern(this.resizeImage(image, imageSize), 'repeat');
this.ctx.translate(offsetX, offsetY);
this.ctx.fill();
this.ctx.translate(-offsetX, -offsetY);
}
}, {
key: 'renderTextNode',
value: function renderTextNode(textBounds, color, font, textDecoration, textShadows) {
var _this4 = this;
this.ctx.font = [font.fontStyle, font.fontVariant, font.fontWeight, font.fontSize, font.fontFamily].join(' ');
textBounds.forEach(function (text) {
_this4.ctx.fillStyle = color.toString();
if (textShadows && text.text.trim().length) {
textShadows.slice(0).reverse().forEach(function (textShadow) {
_this4.ctx.shadowColor = textShadow.color.toString();
_this4.ctx.shadowOffsetX = textShadow.offsetX * _this4.options.scale;
_this4.ctx.shadowOffsetY = textShadow.offsetY * _this4.options.scale;
_this4.ctx.shadowBlur = textShadow.blur;
_this4.ctx.fillText(text.text, text.bounds.left, text.bounds.top + text.bounds.height);
});
} else {
_this4.ctx.fillText(text.text, text.bounds.left, text.bounds.top + text.bounds.height);
}
if (textDecoration !== null) {
var textDecorationColor = textDecoration.textDecorationColor || color;
textDecoration.textDecorationLine.forEach(function (textDecorationLine) {
switch (textDecorationLine) {
case _textDecoration.TEXT_DECORATION_LINE.UNDERLINE:
// Draws a line at the baseline of the font
// TODO As some browsers display the line as more than 1px if the font-size is big,
// need to take that into account both in position and size
var _options$fontMetrics$ = _this4.options.fontMetrics.getMetrics(font),
baseline = _options$fontMetrics$.baseline;
_this4.rectangle(text.bounds.left, Math.round(text.bounds.top + baseline), text.bounds.width, 1, textDecorationColor);
break;
case _textDecoration.TEXT_DECORATION_LINE.OVERLINE:
_this4.rectangle(text.bounds.left, Math.round(text.bounds.top), text.bounds.width, 1, textDecorationColor);
break;
case _textDecoration.TEXT_DECORATION_LINE.LINE_THROUGH:
// TODO try and find exact position for line-through
var _options$fontMetrics$2 = _this4.options.fontMetrics.getMetrics(font),
middle = _options$fontMetrics$2.middle;
_this4.rectangle(text.bounds.left, Math.ceil(text.bounds.top + middle), text.bounds.width, 1, textDecorationColor);
break;
}
});
}
});
}
}, {
key: 'resizeImage',
value: function resizeImage(image, size) {
if (image.width === size.width && image.height === size.height) {
return image;
}
var canvas = this.canvas.ownerDocument.createElement('canvas');
canvas.width = size.width;
canvas.height = size.height;
var ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, size.width, size.height);
return canvas;
}
}, {
key: 'setOpacity',
value: function setOpacity(opacity) {
this.ctx.globalAlpha = opacity;
}
}, {
key: 'transform',
value: function transform(offsetX, offsetY, matrix, callback) {
this.ctx.save();
this.ctx.translate(offsetX, offsetY);
this.ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
this.ctx.translate(-offsetX, -offsetY);
callback();
this.ctx.restore();
}
}]);
return CanvasRenderer;
}();
exports.default = CanvasRenderer;
/***/ }),
/* 16 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Logger = function () {
function Logger(enabled, id, start) {
_classCallCheck(this, Logger);
this.enabled = typeof window !== 'undefined' && enabled;
this.start = start ? start : Date.now();
this.id = id;
}
_createClass(Logger, [{
key: 'child',
value: function child(id) {
return new Logger(this.enabled, id, this.start);
}
// eslint-disable-next-line flowtype/no-weak-types
}, {
key: 'log',
value: function log() {