Socket
Socket
Sign inDemoInstall

html2canvas

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html2canvas - npm Package Compare versions

Comparing version 1.1.5 to 1.2.0

dist/lib/core/__mocks__/context.js

14

CHANGELOG.md

@@ -5,2 +5,16 @@ # Changelog

# [1.2.0](https://github.com/niklasvh/html2canvas/compare/v1.1.5...v1.2.0) (2021-08-04)
### fix
* element cropping & scrolling (#2625) ([878e37a](https://github.com/niklasvh/html2canvas/commit/878e37a24272d0412fe589975ef8eed931c56e0b)), closes [#2625](https://github.com/niklasvh/html2canvas/issues/2625)
* overflow-wrap break-word (#2626) ([95a46b0](https://github.com/niklasvh/html2canvas/commit/95a46b00c53563722c035a0e45fdf5fb507275e4)), closes [#2626](https://github.com/niklasvh/html2canvas/issues/2626)
### test
* element with scrolled window (#2624) ([1338c7b](https://github.com/niklasvh/html2canvas/commit/1338c7b203535d53509416358d74014200a994eb)), closes [#2624](https://github.com/niklasvh/html2canvas/issues/2624)
## [1.1.5](https://github.com/niklasvh/html2canvas/compare/v1.1.4...v1.1.5) (2021-08-02)

@@ -7,0 +21,0 @@

14

dist/lib/__tests__/index.js

@@ -75,2 +75,6 @@ "use strict";

expect(canvas_renderer_1.CanvasRenderer).toHaveBeenLastCalledWith(expect.objectContaining({
cache: expect.any(Object),
logger: expect.any(Object),
windowBounds: expect.objectContaining({ left: 12, top: 34 })
}), expect.objectContaining({
backgroundColor: 0xffffffff,

@@ -82,4 +86,2 @@ scale: 1,

y: 0,
scrollX: 12,
scrollY: 34,
canvas: undefined

@@ -98,3 +100,3 @@ }));

_a.sent();
expect(canvas_renderer_1.CanvasRenderer).toHaveBeenLastCalledWith(expect.objectContaining({
expect(canvas_renderer_1.CanvasRenderer).toHaveBeenLastCalledWith(expect.anything(), expect.objectContaining({
backgroundColor: color_1.COLORS.TRANSPARENT

@@ -115,3 +117,3 @@ }));

_a.sent();
expect(canvas_renderer_1.CanvasRenderer).toHaveBeenLastCalledWith(expect.objectContaining({
expect(canvas_renderer_1.CanvasRenderer).toHaveBeenLastCalledWith(expect.anything(), expect.objectContaining({
canvas: canvas

@@ -131,3 +133,3 @@ }));

_a.sent();
expect(canvas_renderer_1.CanvasRenderer).toHaveBeenLastCalledWith(expect.objectContaining({
expect(canvas_renderer_1.CanvasRenderer).toHaveBeenLastCalledWith(expect.anything(), expect.objectContaining({
backgroundColor: 0xffffffff,

@@ -139,4 +141,2 @@ scale: 1,

y: 0,
scrollX: 12,
scrollY: 34,
canvas: undefined

@@ -143,0 +143,0 @@ }));

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CacheStorage = void 0;
var MockCache = /** @class */ (function () {
function MockCache() {
this._cache = {};
}
MockCache.prototype.addImage = function (src) {
var result = Promise.resolve();
this._cache[src] = result;
return result;
};
return MockCache;
}());
var current = new MockCache();
var CacheStorage = /** @class */ (function () {
function CacheStorage() {
}
CacheStorage.getInstance = function () {
return current;
};
return CacheStorage;

@@ -23,0 +8,0 @@ }());

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
exports.logger = exports.Logger = void 0;
var Logger = /** @class */ (function () {

@@ -14,3 +14,3 @@ function Logger() {

Logger.getInstance = function () {
return logger;
return exports.logger;
};

@@ -24,3 +24,3 @@ // eslint-disable-next-line @typescript-eslint/no-empty-function

exports.Logger = Logger;
var logger = new Logger();
exports.logger = new Logger();
//# sourceMappingURL=logger.js.map

@@ -53,3 +53,4 @@ "use strict";

var cache_storage_1 = require("../cache-storage");
var logger_1 = require("../logger");
var context_1 = require("../context");
var bounds_1 = require("../../css/layout/bounds");
var proxy = 'http://example.com/proxy';

@@ -86,4 +87,3 @@ var createMockContext = function (origin, opts) {

cache_storage_1.CacheStorage.setContext(context);
logger_1.Logger.create({ id: 'test', enabled: false });
return cache_storage_1.CacheStorage.create('test', __assign({ imageTimeout: 0, useCORS: false, allowTaint: false, proxy: proxy }, opts));
return new context_1.Context(__assign({ logging: false, imageTimeout: 0, useCORS: false, allowTaint: false, proxy: proxy }, opts), new bounds_1.Bounds(0, 0, 0, 0));
};

@@ -169,3 +169,3 @@ var images = [];

case 0:
cache = createMockContext('http://example.com', { proxy: null });
cache = createMockContext('http://example.com', { proxy: null }).cache;
return [4 /*yield*/, cache.addImage('http://example.com/test.jpg')];

@@ -189,3 +189,3 @@ case 1:

case 0:
cache = createMockContext('http://example.com');
cache = createMockContext('http://example.com').cache;
return [4 /*yield*/, cache.addImage('http://example.com/test.jpg')];

@@ -209,3 +209,3 @@ case 1:

case 0:
cache = createMockContext('http://example.com');
cache = createMockContext('http://example.com').cache;
return [4 /*yield*/, cache.addImage('http://example.com/test.svg')];

@@ -230,3 +230,3 @@ case 1:

setFeatures({ SUPPORT_SVG_DRAWING: false });
cache = createMockContext('http://example.com');
cache = createMockContext('http://example.com').cache;
return [4 /*yield*/, cache.addImage('http://example.com/test.svg')];

@@ -252,3 +252,3 @@ case 1:

proxy: undefined
});
}).cache;
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];

@@ -270,3 +270,3 @@ case 1:

proxy: undefined
});
}).cache;
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];

@@ -287,3 +287,3 @@ case 1:

case 0:
cache = createMockContext('http://example.com', { useCORS: true });
cache = createMockContext('http://example.com', { useCORS: true }).cache;
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];

@@ -308,3 +308,3 @@ case 1:

proxy: undefined
});
}).cache;
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];

@@ -323,3 +323,3 @@ case 1:

case 0:
cache = createMockContext('http://example.com', { useCORS: true });
cache = createMockContext('http://example.com', { useCORS: true }).cache;
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];

@@ -340,3 +340,3 @@ case 1:

case 0:
cache = createMockContext('http://example.com');
cache = createMockContext('http://example.com').cache;
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];

@@ -363,3 +363,3 @@ case 1:

imageTimeout: 10
});
}).cache;
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];

@@ -395,3 +395,3 @@ case 1:

case 0:
cache = createMockContext('http://example.com');
cache = createMockContext('http://example.com').cache;
return [4 /*yield*/, cache.addImage('http://example.com/test.jpg')];

@@ -416,3 +416,3 @@ case 1:

case 0:
cache = createMockContext('http://example.com', { imageTimeout: 10 });
cache = createMockContext('http://example.com', { imageTimeout: 10 }).cache;
cache.addImage('http://example.com/test.jpg');

@@ -419,0 +419,0 @@ _a.label = 1;

@@ -41,19 +41,5 @@ "use strict";

var features_1 = require("./features");
var logger_1 = require("./logger");
var CacheStorage = /** @class */ (function () {
function CacheStorage() {
}
CacheStorage.create = function (name, options) {
return (CacheStorage._caches[name] = new Cache(name, options));
};
CacheStorage.destroy = function (name) {
delete CacheStorage._caches[name];
};
CacheStorage.open = function (name) {
var cache = CacheStorage._caches[name];
if (typeof cache !== 'undefined') {
return cache;
}
throw new Error("Cache with key \"" + name + "\" not found");
};
CacheStorage.getOrigin = function (url) {

@@ -75,18 +61,3 @@ var link = CacheStorage._link;

};
CacheStorage.getInstance = function () {
var current = CacheStorage._current;
if (current === null) {
throw new Error("No cache instance attached");
}
return current;
};
CacheStorage.attachInstance = function (cache) {
CacheStorage._current = cache;
};
CacheStorage.detachInstance = function () {
CacheStorage._current = null;
};
CacheStorage._caches = {};
CacheStorage._origin = 'about:blank';
CacheStorage._current = null;
return CacheStorage;

@@ -96,5 +67,6 @@ }());

var Cache = /** @class */ (function () {
function Cache(id, options) {
this.id = id;
this._options = options;
function Cache(context, _options) {
this.context = context;
this._options = _options;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this._cache = {};

@@ -149,3 +121,3 @@ }

case 2:
logger_1.Logger.getInstance(this.id).debug("Added image " + key.substring(0, 256));
this.context.logger.debug("Added image " + key.substring(0, 256));
return [4 /*yield*/, new Promise(function (resolve, reject) {

@@ -152,0 +124,0 @@ var img = new Image();

@@ -36,15 +36,2 @@ "use strict";

};
Logger.create = function (options) {
Logger.instances[options.id] = new Logger(options);
};
Logger.destroy = function (id) {
delete Logger.instances[id];
};
Logger.getInstance = function (id) {
var instance = Logger.instances[id];
if (typeof instance === 'undefined') {
throw new Error("No logger instance found with id " + id);
}
return instance;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any

@@ -65,2 +52,19 @@ Logger.prototype.info = function () {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Logger.prototype.warn = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (this.enabled) {
// eslint-disable-next-line no-console
if (typeof window !== 'undefined' && window.console && typeof console.warn === 'function') {
// eslint-disable-next-line no-console
console.warn.apply(console, __spreadArray([this.id, this.getTime() + "ms"], args));
}
else {
this.info.apply(this, args);
}
}
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Logger.prototype.error = function () {

@@ -67,0 +71,0 @@ var args = [];

@@ -63,69 +63,69 @@ "use strict";

var CSSParsedDeclaration = /** @class */ (function () {
function CSSParsedDeclaration(declaration) {
function CSSParsedDeclaration(context, declaration) {
var _a, _b;
this.backgroundClip = parse(background_clip_1.backgroundClip, declaration.backgroundClip);
this.backgroundColor = parse(background_color_1.backgroundColor, declaration.backgroundColor);
this.backgroundImage = parse(background_image_1.backgroundImage, declaration.backgroundImage);
this.backgroundOrigin = parse(background_origin_1.backgroundOrigin, declaration.backgroundOrigin);
this.backgroundPosition = parse(background_position_1.backgroundPosition, declaration.backgroundPosition);
this.backgroundRepeat = parse(background_repeat_1.backgroundRepeat, declaration.backgroundRepeat);
this.backgroundSize = parse(background_size_1.backgroundSize, declaration.backgroundSize);
this.borderTopColor = parse(border_color_1.borderTopColor, declaration.borderTopColor);
this.borderRightColor = parse(border_color_1.borderRightColor, declaration.borderRightColor);
this.borderBottomColor = parse(border_color_1.borderBottomColor, declaration.borderBottomColor);
this.borderLeftColor = parse(border_color_1.borderLeftColor, declaration.borderLeftColor);
this.borderTopLeftRadius = parse(border_radius_1.borderTopLeftRadius, declaration.borderTopLeftRadius);
this.borderTopRightRadius = parse(border_radius_1.borderTopRightRadius, declaration.borderTopRightRadius);
this.borderBottomRightRadius = parse(border_radius_1.borderBottomRightRadius, declaration.borderBottomRightRadius);
this.borderBottomLeftRadius = parse(border_radius_1.borderBottomLeftRadius, declaration.borderBottomLeftRadius);
this.borderTopStyle = parse(border_style_1.borderTopStyle, declaration.borderTopStyle);
this.borderRightStyle = parse(border_style_1.borderRightStyle, declaration.borderRightStyle);
this.borderBottomStyle = parse(border_style_1.borderBottomStyle, declaration.borderBottomStyle);
this.borderLeftStyle = parse(border_style_1.borderLeftStyle, declaration.borderLeftStyle);
this.borderTopWidth = parse(border_width_1.borderTopWidth, declaration.borderTopWidth);
this.borderRightWidth = parse(border_width_1.borderRightWidth, declaration.borderRightWidth);
this.borderBottomWidth = parse(border_width_1.borderBottomWidth, declaration.borderBottomWidth);
this.borderLeftWidth = parse(border_width_1.borderLeftWidth, declaration.borderLeftWidth);
this.boxShadow = parse(box_shadow_1.boxShadow, declaration.boxShadow);
this.color = parse(color_1.color, declaration.color);
this.display = parse(display_1.display, declaration.display);
this.float = parse(float_1.float, declaration.cssFloat);
this.fontFamily = parse(font_family_1.fontFamily, declaration.fontFamily);
this.fontSize = parse(font_size_1.fontSize, declaration.fontSize);
this.fontStyle = parse(font_style_1.fontStyle, declaration.fontStyle);
this.fontVariant = parse(font_variant_1.fontVariant, declaration.fontVariant);
this.fontWeight = parse(font_weight_1.fontWeight, declaration.fontWeight);
this.letterSpacing = parse(letter_spacing_1.letterSpacing, declaration.letterSpacing);
this.lineBreak = parse(line_break_1.lineBreak, declaration.lineBreak);
this.lineHeight = parse(line_height_1.lineHeight, declaration.lineHeight);
this.listStyleImage = parse(list_style_image_1.listStyleImage, declaration.listStyleImage);
this.listStylePosition = parse(list_style_position_1.listStylePosition, declaration.listStylePosition);
this.listStyleType = parse(list_style_type_1.listStyleType, declaration.listStyleType);
this.marginTop = parse(margin_1.marginTop, declaration.marginTop);
this.marginRight = parse(margin_1.marginRight, declaration.marginRight);
this.marginBottom = parse(margin_1.marginBottom, declaration.marginBottom);
this.marginLeft = parse(margin_1.marginLeft, declaration.marginLeft);
this.opacity = parse(opacity_1.opacity, declaration.opacity);
var overflowTuple = parse(overflow_1.overflow, declaration.overflow);
this.backgroundClip = parse(context, background_clip_1.backgroundClip, declaration.backgroundClip);
this.backgroundColor = parse(context, background_color_1.backgroundColor, declaration.backgroundColor);
this.backgroundImage = parse(context, background_image_1.backgroundImage, declaration.backgroundImage);
this.backgroundOrigin = parse(context, background_origin_1.backgroundOrigin, declaration.backgroundOrigin);
this.backgroundPosition = parse(context, background_position_1.backgroundPosition, declaration.backgroundPosition);
this.backgroundRepeat = parse(context, background_repeat_1.backgroundRepeat, declaration.backgroundRepeat);
this.backgroundSize = parse(context, background_size_1.backgroundSize, declaration.backgroundSize);
this.borderTopColor = parse(context, border_color_1.borderTopColor, declaration.borderTopColor);
this.borderRightColor = parse(context, border_color_1.borderRightColor, declaration.borderRightColor);
this.borderBottomColor = parse(context, border_color_1.borderBottomColor, declaration.borderBottomColor);
this.borderLeftColor = parse(context, border_color_1.borderLeftColor, declaration.borderLeftColor);
this.borderTopLeftRadius = parse(context, border_radius_1.borderTopLeftRadius, declaration.borderTopLeftRadius);
this.borderTopRightRadius = parse(context, border_radius_1.borderTopRightRadius, declaration.borderTopRightRadius);
this.borderBottomRightRadius = parse(context, border_radius_1.borderBottomRightRadius, declaration.borderBottomRightRadius);
this.borderBottomLeftRadius = parse(context, border_radius_1.borderBottomLeftRadius, declaration.borderBottomLeftRadius);
this.borderTopStyle = parse(context, border_style_1.borderTopStyle, declaration.borderTopStyle);
this.borderRightStyle = parse(context, border_style_1.borderRightStyle, declaration.borderRightStyle);
this.borderBottomStyle = parse(context, border_style_1.borderBottomStyle, declaration.borderBottomStyle);
this.borderLeftStyle = parse(context, border_style_1.borderLeftStyle, declaration.borderLeftStyle);
this.borderTopWidth = parse(context, border_width_1.borderTopWidth, declaration.borderTopWidth);
this.borderRightWidth = parse(context, border_width_1.borderRightWidth, declaration.borderRightWidth);
this.borderBottomWidth = parse(context, border_width_1.borderBottomWidth, declaration.borderBottomWidth);
this.borderLeftWidth = parse(context, border_width_1.borderLeftWidth, declaration.borderLeftWidth);
this.boxShadow = parse(context, box_shadow_1.boxShadow, declaration.boxShadow);
this.color = parse(context, color_1.color, declaration.color);
this.display = parse(context, display_1.display, declaration.display);
this.float = parse(context, float_1.float, declaration.cssFloat);
this.fontFamily = parse(context, font_family_1.fontFamily, declaration.fontFamily);
this.fontSize = parse(context, font_size_1.fontSize, declaration.fontSize);
this.fontStyle = parse(context, font_style_1.fontStyle, declaration.fontStyle);
this.fontVariant = parse(context, font_variant_1.fontVariant, declaration.fontVariant);
this.fontWeight = parse(context, font_weight_1.fontWeight, declaration.fontWeight);
this.letterSpacing = parse(context, letter_spacing_1.letterSpacing, declaration.letterSpacing);
this.lineBreak = parse(context, line_break_1.lineBreak, declaration.lineBreak);
this.lineHeight = parse(context, line_height_1.lineHeight, declaration.lineHeight);
this.listStyleImage = parse(context, list_style_image_1.listStyleImage, declaration.listStyleImage);
this.listStylePosition = parse(context, list_style_position_1.listStylePosition, declaration.listStylePosition);
this.listStyleType = parse(context, list_style_type_1.listStyleType, declaration.listStyleType);
this.marginTop = parse(context, margin_1.marginTop, declaration.marginTop);
this.marginRight = parse(context, margin_1.marginRight, declaration.marginRight);
this.marginBottom = parse(context, margin_1.marginBottom, declaration.marginBottom);
this.marginLeft = parse(context, margin_1.marginLeft, declaration.marginLeft);
this.opacity = parse(context, opacity_1.opacity, declaration.opacity);
var overflowTuple = parse(context, overflow_1.overflow, declaration.overflow);
this.overflowX = overflowTuple[0];
this.overflowY = overflowTuple[overflowTuple.length > 1 ? 1 : 0];
this.overflowWrap = parse(overflow_wrap_1.overflowWrap, declaration.overflowWrap);
this.paddingTop = parse(padding_1.paddingTop, declaration.paddingTop);
this.paddingRight = parse(padding_1.paddingRight, declaration.paddingRight);
this.paddingBottom = parse(padding_1.paddingBottom, declaration.paddingBottom);
this.paddingLeft = parse(padding_1.paddingLeft, declaration.paddingLeft);
this.paintOrder = parse(paint_order_1.paintOrder, declaration.paintOrder);
this.position = parse(position_1.position, declaration.position);
this.textAlign = parse(text_align_1.textAlign, declaration.textAlign);
this.textDecorationColor = parse(text_decoration_color_1.textDecorationColor, (_a = declaration.textDecorationColor) !== null && _a !== void 0 ? _a : declaration.color);
this.textDecorationLine = parse(text_decoration_line_1.textDecorationLine, (_b = declaration.textDecorationLine) !== null && _b !== void 0 ? _b : declaration.textDecoration);
this.textShadow = parse(text_shadow_1.textShadow, declaration.textShadow);
this.textTransform = parse(text_transform_1.textTransform, declaration.textTransform);
this.transform = parse(transform_1.transform, declaration.transform);
this.transformOrigin = parse(transform_origin_1.transformOrigin, declaration.transformOrigin);
this.visibility = parse(visibility_1.visibility, declaration.visibility);
this.webkitTextStrokeColor = parse(webkit_text_stroke_color_1.webkitTextStrokeColor, declaration.webkitTextStrokeColor);
this.webkitTextStrokeWidth = parse(webkit_text_stroke_width_1.webkitTextStrokeWidth, declaration.webkitTextStrokeWidth);
this.wordBreak = parse(word_break_1.wordBreak, declaration.wordBreak);
this.zIndex = parse(z_index_1.zIndex, declaration.zIndex);
this.overflowWrap = parse(context, overflow_wrap_1.overflowWrap, declaration.overflowWrap);
this.paddingTop = parse(context, padding_1.paddingTop, declaration.paddingTop);
this.paddingRight = parse(context, padding_1.paddingRight, declaration.paddingRight);
this.paddingBottom = parse(context, padding_1.paddingBottom, declaration.paddingBottom);
this.paddingLeft = parse(context, padding_1.paddingLeft, declaration.paddingLeft);
this.paintOrder = parse(context, paint_order_1.paintOrder, declaration.paintOrder);
this.position = parse(context, position_1.position, declaration.position);
this.textAlign = parse(context, text_align_1.textAlign, declaration.textAlign);
this.textDecorationColor = parse(context, text_decoration_color_1.textDecorationColor, (_a = declaration.textDecorationColor) !== null && _a !== void 0 ? _a : declaration.color);
this.textDecorationLine = parse(context, text_decoration_line_1.textDecorationLine, (_b = declaration.textDecorationLine) !== null && _b !== void 0 ? _b : declaration.textDecoration);
this.textShadow = parse(context, text_shadow_1.textShadow, declaration.textShadow);
this.textTransform = parse(context, text_transform_1.textTransform, declaration.textTransform);
this.transform = parse(context, transform_1.transform, declaration.transform);
this.transformOrigin = parse(context, transform_origin_1.transformOrigin, declaration.transformOrigin);
this.visibility = parse(context, visibility_1.visibility, declaration.visibility);
this.webkitTextStrokeColor = parse(context, webkit_text_stroke_color_1.webkitTextStrokeColor, declaration.webkitTextStrokeColor);
this.webkitTextStrokeWidth = parse(context, webkit_text_stroke_width_1.webkitTextStrokeWidth, declaration.webkitTextStrokeWidth);
this.wordBreak = parse(context, word_break_1.wordBreak, declaration.wordBreak);
this.zIndex = parse(context, z_index_1.zIndex, declaration.zIndex);
}

@@ -162,5 +162,5 @@ CSSParsedDeclaration.prototype.isVisible = function () {

var CSSParsedPseudoDeclaration = /** @class */ (function () {
function CSSParsedPseudoDeclaration(declaration) {
this.content = parse(content_1.content, declaration.content);
this.quotes = parse(quotes_1.quotes, declaration.quotes);
function CSSParsedPseudoDeclaration(context, declaration) {
this.content = parse(context, content_1.content, declaration.content);
this.quotes = parse(context, quotes_1.quotes, declaration.quotes);
}

@@ -171,5 +171,5 @@ return CSSParsedPseudoDeclaration;

var CSSParsedCounterDeclaration = /** @class */ (function () {
function CSSParsedCounterDeclaration(declaration) {
this.counterIncrement = parse(counter_increment_1.counterIncrement, declaration.counterIncrement);
this.counterReset = parse(counter_reset_1.counterReset, declaration.counterReset);
function CSSParsedCounterDeclaration(context, declaration) {
this.counterIncrement = parse(context, counter_increment_1.counterIncrement, declaration.counterIncrement);
this.counterReset = parse(context, counter_reset_1.counterReset, declaration.counterReset);
}

@@ -180,3 +180,3 @@ return CSSParsedCounterDeclaration;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
var parse = function (descriptor, style) {
var parse = function (context, descriptor, style) {
var tokenizer = new tokenizer_1.Tokenizer();

@@ -189,7 +189,7 @@ var value = style !== null && typeof style !== 'undefined' ? style.toString() : descriptor.initialValue;

var token = parser.parseComponentValue();
return descriptor.parse(parser_1.isIdentToken(token) ? token.value : descriptor.initialValue);
return descriptor.parse(context, parser_1.isIdentToken(token) ? token.value : descriptor.initialValue);
case IPropertyDescriptor_1.PropertyDescriptorParsingType.VALUE:
return descriptor.parse(parser.parseComponentValue());
return descriptor.parse(context, parser.parseComponentValue());
case IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST:
return descriptor.parse(parser.parseComponentValues());
return descriptor.parse(context, parser.parseComponentValues());
case IPropertyDescriptor_1.PropertyDescriptorParsingType.TOKEN_VALUE:

@@ -200,7 +200,7 @@ return parser.parseComponentValue();

case 'angle':
return angle_1.angle.parse(parser.parseComponentValue());
return angle_1.angle.parse(context, parser.parseComponentValue());
case 'color':
return color_2.color.parse(parser.parseComponentValue());
return color_2.color.parse(context, parser.parseComponentValue());
case 'image':
return image_1.image.parse(parser.parseComponentValue());
return image_1.image.parse(context, parser.parseComponentValue());
case 'length':

@@ -207,0 +207,0 @@ var length_2 = parser.parseComponentValue();

@@ -5,7 +5,7 @@ "use strict";

var Bounds = /** @class */ (function () {
function Bounds(x, y, w, h) {
this.left = x;
this.top = y;
this.width = w;
this.height = h;
function Bounds(left, top, width, height) {
this.left = left;
this.top = top;
this.width = width;
this.height = height;
}

@@ -15,4 +15,4 @@ Bounds.prototype.add = function (x, y, w, h) {

};
Bounds.fromClientRect = function (clientRect) {
return new Bounds(clientRect.left, clientRect.top, clientRect.width, clientRect.height);
Bounds.fromClientRect = function (context, clientRect) {
return new Bounds(clientRect.left + context.windowBounds.left, clientRect.top + context.windowBounds.top, clientRect.width, clientRect.height);
};

@@ -22,4 +22,4 @@ return Bounds;

exports.Bounds = Bounds;
var parseBounds = function (node) {
return Bounds.fromClientRect(node.getBoundingClientRect());
var parseBounds = function (context, node) {
return Bounds.fromClientRect(context, node.getBoundingClientRect());
};

@@ -26,0 +26,0 @@ exports.parseBounds = parseBounds;

@@ -16,3 +16,3 @@ "use strict";

exports.TextBounds = TextBounds;
var parseTextBounds = function (value, styles, node) {
var parseTextBounds = function (context, value, styles, node) {
var textList = breakText(value, styles);

@@ -24,7 +24,7 @@ var textBounds = [];

if (features_1.FEATURES.SUPPORT_RANGE_BOUNDS) {
textBounds.push(new TextBounds(text, getRangeBounds(node, offset, text.length)));
textBounds.push(new TextBounds(text, getRangeBounds(context, node, offset, text.length)));
}
else {
var replacementNode = node.splitText(text.length);
textBounds.push(new TextBounds(text, getWrapperBounds(node)));
textBounds.push(new TextBounds(text, getWrapperBounds(context, node)));
node = replacementNode;

@@ -41,3 +41,3 @@ }

exports.parseTextBounds = parseTextBounds;
var getWrapperBounds = function (node) {
var getWrapperBounds = function (context, node) {
var ownerDocument = node.ownerDocument;

@@ -50,3 +50,3 @@ if (ownerDocument) {

parentNode.replaceChild(wrapper, node);
var bounds = bounds_1.parseBounds(wrapper);
var bounds = bounds_1.parseBounds(context, wrapper);
if (wrapper.firstChild) {

@@ -60,3 +60,3 @@ parentNode.replaceChild(wrapper.firstChild, wrapper);

};
var getRangeBounds = function (node, offset, length) {
var getRangeBounds = function (context, node, offset, length) {
var ownerDocument = node.ownerDocument;

@@ -69,3 +69,3 @@ if (!ownerDocument) {

range.setEnd(node, offset + length);
return bounds_1.Bounds.fromClientRect(range.getBoundingClientRect());
return bounds_1.Bounds.fromClientRect(context, range.getBoundingClientRect());
};

@@ -72,0 +72,0 @@ var breakText = function (value, styles) {

@@ -9,16 +9,29 @@ "use strict";

var angle_1 = require("../../types/angle");
jest.mock('../../../core/cache-storage');
jest.mock('../../../core/context');
var context_1 = require("../../../core/context");
jest.mock('../../../core/features');
var backgroundImageParse = function (value) { return background_image_1.backgroundImage.parse(parser_1.Parser.parseValues(value)); };
var backgroundImageParse = function (context, value) {
return background_image_1.backgroundImage.parse(context, parser_1.Parser.parseValues(value));
};
describe('property-descriptors', function () {
var context;
beforeEach(function () {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
context = new context_1.Context({}, {});
});
describe('background-image', function () {
it('none', function () { return assert_1.deepStrictEqual(backgroundImageParse('none'), []); });
it('none', function () {
assert_1.deepStrictEqual(backgroundImageParse(context, 'none'), []);
expect(context.cache.addImage).not.toHaveBeenCalled();
});
it('url(test.jpg), url(test2.jpg)', function () {
return assert_1.deepStrictEqual(backgroundImageParse('url(http://example.com/test.jpg), url(http://example.com/test2.jpg)'), [
assert_1.deepStrictEqual(backgroundImageParse(context, 'url(http://example.com/test.jpg), url(http://example.com/test2.jpg)'), [
{ url: 'http://example.com/test.jpg', type: image_1.CSSImageType.URL },
{ url: 'http://example.com/test2.jpg', type: image_1.CSSImageType.URL }
]);
expect(context.cache.addImage).toHaveBeenCalledWith('http://example.com/test.jpg');
expect(context.cache.addImage).toHaveBeenCalledWith('http://example.com/test2.jpg');
});
it("linear-gradient(to bottom, rgba(255,255,0,0.5), rgba(0,0,255,0.5)), url('https://html2canvas.hertzen.com')", function () {
return assert_1.deepStrictEqual(backgroundImageParse("linear-gradient(to bottom, rgba(255,255,0,0.5), rgba(0,0,255,0.5)), url('https://html2canvas.hertzen.com')"), [
return assert_1.deepStrictEqual(backgroundImageParse(context, "linear-gradient(to bottom, rgba(255,255,0,0.5), rgba(0,0,255,0.5)), url('https://html2canvas.hertzen.com')"), [
{

@@ -25,0 +38,0 @@ angle: angle_1.deg(180),

@@ -6,3 +6,3 @@ "use strict";

var font_family_1 = require("../font-family");
var fontFamilyParse = function (value) { return font_family_1.fontFamily.parse(parser_1.Parser.parseValues(value)); };
var fontFamilyParse = function (value) { return font_family_1.fontFamily.parse({}, parser_1.Parser.parseValues(value)); };
describe('property-descriptors', function () {

@@ -9,0 +9,0 @@ describe('font-family', function () {

@@ -6,3 +6,3 @@ "use strict";

var paint_order_1 = require("../paint-order");
var paintOrderParse = function (value) { return paint_order_1.paintOrder.parse(parser_1.Parser.parseValues(value)); };
var paintOrderParse = function (value) { return paint_order_1.paintOrder.parse({}, parser_1.Parser.parseValues(value)); };
describe('property-descriptors', function () {

@@ -9,0 +9,0 @@ describe('paint-order', function () {

@@ -9,4 +9,4 @@ "use strict";

var length_percentage_1 = require("../../types/length-percentage");
var textShadowParse = function (value) { return text_shadow_1.textShadow.parse(parser_1.Parser.parseValues(value)); };
var colorParse = function (value) { return color_1.color.parse(parser_1.Parser.parseValue(value)); };
var textShadowParse = function (value) { return text_shadow_1.textShadow.parse({}, parser_1.Parser.parseValues(value)); };
var colorParse = function (value) { return color_1.color.parse({}, parser_1.Parser.parseValue(value)); };
var dimension = function (number, unit) { return ({

@@ -13,0 +13,0 @@ flags: tokenizer_1.FLAG_INTEGER,

@@ -6,3 +6,3 @@ "use strict";

var assert_1 = require("assert");
var parseValue = function (value) { return transform_1.transform.parse(parser_1.Parser.parseValue(value)); };
var parseValue = function (value) { return transform_1.transform.parse({}, parser_1.Parser.parseValue(value)); };
describe('property-descriptors', function () {

@@ -9,0 +9,0 @@ describe('transform', function () {

@@ -17,3 +17,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
return tokens.map(function (token) {

@@ -20,0 +20,0 @@ if (parser_1.isIdentToken(token)) {

@@ -13,3 +13,3 @@ "use strict";

prefix: false,
parse: function (tokens) {
parse: function (context, tokens) {
if (tokens.length === 0) {

@@ -22,5 +22,7 @@ return [];

}
return tokens.filter(function (value) { return parser_1.nonFunctionArgSeparator(value) && image_1.isSupportedImage(value); }).map(image_1.image.parse);
return tokens
.filter(function (value) { return parser_1.nonFunctionArgSeparator(value) && image_1.isSupportedImage(value); })
.map(function (value) { return image_1.image.parse(context, value); });
}
};
//# sourceMappingURL=background-image.js.map

@@ -11,3 +11,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
return tokens.map(function (token) {

@@ -14,0 +14,0 @@ if (parser_1.isIdentToken(token)) {

@@ -12,3 +12,3 @@ "use strict";

prefix: false,
parse: function (tokens) {
parse: function (_context, tokens) {
return parser_1.parseFunctionArgs(tokens)

@@ -15,0 +15,0 @@ .map(function (values) { return values.filter(length_percentage_1.isLengthPercentage); })

@@ -18,3 +18,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
return parser_1.parseFunctionArgs(tokens)

@@ -21,0 +21,0 @@ .map(function (values) {

@@ -18,3 +18,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
return parser_1.parseFunctionArgs(tokens).map(function (values) { return values.filter(isBackgroundSizeInfoToken); });

@@ -21,0 +21,0 @@ }

@@ -11,3 +11,5 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) { return length_percentage_1.parseLengthPercentageTuple(tokens.filter(length_percentage_1.isLengthPercentage)); }
parse: function (_context, tokens) {
return length_percentage_1.parseLengthPercentageTuple(tokens.filter(length_percentage_1.isLengthPercentage));
}
}); };

@@ -14,0 +16,0 @@ exports.borderTopLeftRadius = borderRadiusForSide('top-left');

@@ -18,3 +18,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (style) {
parse: function (_context, style) {
switch (style) {

@@ -21,0 +21,0 @@ case 'none':

@@ -11,3 +11,3 @@ "use strict";

prefix: false,
parse: function (token) {
parse: function (_context, token) {
if (parser_1.isDimensionToken(token)) {

@@ -14,0 +14,0 @@ return token.number;

@@ -14,3 +14,3 @@ "use strict";

prefix: false,
parse: function (tokens) {
parse: function (context, tokens) {
if (tokens.length === 1 && parser_1.isIdentWithValue(tokens[0], 'none')) {

@@ -50,3 +50,3 @@ return [];

else {
shadow.color = color_1.color.parse(token);
shadow.color = color_1.color.parse(context, token);
}

@@ -53,0 +53,0 @@ }

@@ -11,3 +11,3 @@ "use strict";

prefix: false,
parse: function (tokens) {
parse: function (_context, tokens) {
if (tokens.length === 0) {

@@ -14,0 +14,0 @@ return [];

@@ -12,3 +12,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
if (tokens.length === 0) {

@@ -15,0 +15,0 @@ return null;

@@ -11,3 +11,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
if (tokens.length === 0) {

@@ -14,0 +14,0 @@ return [];

@@ -11,3 +11,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
return tokens.filter(parser_1.isIdentToken).reduce(function (bit, token) {

@@ -14,0 +14,0 @@ return bit | parseDisplayValue(token.value);

@@ -18,3 +18,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (float) {
parse: function (_context, float) {
switch (float) {

@@ -21,0 +21,0 @@ case 'left':

@@ -11,3 +11,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
var accumulator = [];

@@ -14,0 +14,0 @@ var results = [];

@@ -16,3 +16,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (overflow) {
parse: function (_context, overflow) {
switch (overflow) {

@@ -19,0 +19,0 @@ case 'oblique':

@@ -11,3 +11,3 @@ "use strict";

prefix: false,
parse: function (tokens) {
parse: function (_context, tokens) {
return tokens.filter(parser_1.isIdentToken).map(function (token) { return token.value; });

@@ -14,0 +14,0 @@ }

@@ -11,3 +11,3 @@ "use strict";

prefix: false,
parse: function (token) {
parse: function (_context, token) {
if (parser_1.isNumberToken(token)) {

@@ -14,0 +14,0 @@ return token.number;

@@ -11,3 +11,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.VALUE,
parse: function (token) {
parse: function (_context, token) {
if (token.type === tokenizer_1.TokenType.IDENT_TOKEN && token.value === 'normal') {

@@ -14,0 +14,0 @@ return 0;

@@ -15,3 +15,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (lineBreak) {
parse: function (_context, lineBreak) {
switch (lineBreak) {

@@ -18,0 +18,0 @@ case 'strict':

@@ -12,9 +12,9 @@ "use strict";

prefix: false,
parse: function (token) {
parse: function (context, token) {
if (token.type === tokenizer_1.TokenType.IDENT_TOKEN && token.value === 'none') {
return null;
}
return image_1.image.parse(token);
return image_1.image.parse(context, token);
}
};
//# sourceMappingURL=list-style-image.js.map

@@ -15,3 +15,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (position) {
parse: function (_context, position) {
switch (position) {

@@ -18,0 +18,0 @@ case 'inside':

@@ -67,3 +67,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (type) {
parse: function (_context, type) {
switch (type) {

@@ -70,0 +70,0 @@ case 'disc':

@@ -11,3 +11,3 @@ "use strict";

prefix: false,
parse: function (token) {
parse: function (_context, token) {
if (parser_1.isNumberToken(token)) {

@@ -14,0 +14,0 @@ return token.number;

@@ -15,3 +15,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (overflow) {
parse: function (_context, overflow) {
switch (overflow) {

@@ -18,0 +18,0 @@ case 'break-word':

@@ -18,3 +18,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
return tokens.filter(parser_1.isIdentToken).map(function (overflow) {

@@ -21,0 +21,0 @@ switch (overflow.value) {

@@ -17,3 +17,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
var DEFAULT_VALUE = [PAINT_ORDER_LAYER.FILL, PAINT_ORDER_LAYER.STROKE, PAINT_ORDER_LAYER.MARKERS];

@@ -20,0 +20,0 @@ var layers = [];

@@ -18,3 +18,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (position) {
parse: function (_context, position) {
switch (position) {

@@ -21,0 +21,0 @@ case 'relative':

@@ -12,3 +12,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
if (tokens.length === 0) {

@@ -15,0 +15,0 @@ return null;

@@ -16,3 +16,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (textAlign) {
parse: function (_context, textAlign) {
switch (textAlign) {

@@ -19,0 +19,0 @@ case 'right':

@@ -11,3 +11,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
return tokens

@@ -14,0 +14,0 @@ .filter(parser_1.isIdentToken)

@@ -14,3 +14,3 @@ "use strict";

prefix: false,
parse: function (tokens) {
parse: function (context, tokens) {
if (tokens.length === 1 && parser_1.isIdentWithValue(tokens[0], 'none')) {

@@ -42,3 +42,3 @@ return [];

else {
shadow.color = color_1.color.parse(token);
shadow.color = color_1.color.parse(context, token);
}

@@ -45,0 +45,0 @@ }

@@ -17,3 +17,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (textTransform) {
parse: function (_context, textTransform) {
switch (textTransform) {

@@ -20,0 +20,0 @@ case 'uppercase':

@@ -18,3 +18,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST,
parse: function (tokens) {
parse: function (_context, tokens) {
var origins = tokens.filter(length_percentage_1.isLengthPercentage);

@@ -21,0 +21,0 @@ if (origins.length !== 2) {

@@ -11,3 +11,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.VALUE,
parse: function (token) {
parse: function (_context, token) {
if (token.type === tokenizer_1.TokenType.IDENT_TOKEN && token.value === 'none') {

@@ -14,0 +14,0 @@ return null;

@@ -16,3 +16,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (visibility) {
parse: function (_context, visibility) {
switch (visibility) {

@@ -19,0 +19,0 @@ case 'hidden':

@@ -11,3 +11,3 @@ "use strict";

prefix: false,
parse: function (token) {
parse: function (_context, token) {
if (parser_1.isDimensionToken(token)) {

@@ -14,0 +14,0 @@ return token.number;

@@ -16,3 +16,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE,
parse: function (wordBreak) {
parse: function (_context, wordBreak) {
switch (wordBreak) {

@@ -19,0 +19,0 @@ case 'break-all':

@@ -12,3 +12,3 @@ "use strict";

type: IPropertyDescriptor_1.PropertyDescriptorParsingType.VALUE,
parse: function (token) {
parse: function (_context, token) {
if (token.type === tokenizer_1.TokenType.IDENT_TOKEN) {

@@ -15,0 +15,0 @@ return { auto: true, order: 0 };

@@ -6,3 +6,3 @@ "use strict";

var parser_1 = require("../../syntax/parser");
var parse = function (value) { return color_1.color.parse(parser_1.Parser.parseValue(value)); };
var parse = function (value) { return color_1.color.parse({}, parser_1.Parser.parseValue(value)); };
describe('types', function () {

@@ -9,0 +9,0 @@ describe('<color>', function () {

@@ -9,7 +9,13 @@ "use strict";

var angle_1 = require("../angle");
var parse = function (value) { return image_1.image.parse(parser_1.Parser.parseValue(value)); };
var colorParse = function (value) { return color_1.color.parse(parser_1.Parser.parseValue(value)); };
jest.mock('../../../core/cache-storage');
var parse = function (context, value) { return image_1.image.parse(context, parser_1.Parser.parseValue(value)); };
var colorParse = function (context, value) { return color_1.color.parse(context, parser_1.Parser.parseValue(value)); };
jest.mock('../../../core/features');
jest.mock('../../../core/context');
var context_1 = require("../../../core/context");
describe('types', function () {
var context;
beforeEach(function () {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
context = new context_1.Context({}, {});
});
describe('<image>', function () {

@@ -19,3 +25,3 @@ describe('parsing', function () {

it('url(test.jpg)', function () {
return assert_1.deepStrictEqual(parse('url(http://example.com/test.jpg)'), {
return assert_1.deepStrictEqual(parse(context, 'url(http://example.com/test.jpg)'), {
url: 'http://example.com/test.jpg',

@@ -26,3 +32,3 @@ type: image_1.CSSImageType.URL

it('url("test.jpg")', function () {
return assert_1.deepStrictEqual(parse('url("http://example.com/test.jpg")'), {
return assert_1.deepStrictEqual(parse(context, 'url("http://example.com/test.jpg")'), {
url: 'http://example.com/test.jpg',

@@ -35,3 +41,3 @@ type: image_1.CSSImageType.URL

it('linear-gradient(#f69d3c, #3f87a6)', function () {
return assert_1.deepStrictEqual(parse('linear-gradient(#f69d3c, #3f87a6)'), {
return assert_1.deepStrictEqual(parse(context, 'linear-gradient(#f69d3c, #3f87a6)'), {
angle: angle_1.deg(180),

@@ -46,8 +52,8 @@ type: image_1.CSSImageType.LINEAR_GRADIENT,

it('linear-gradient(yellow, blue)', function () {
return assert_1.deepStrictEqual(parse('linear-gradient(yellow, blue)'), {
return assert_1.deepStrictEqual(parse(context, 'linear-gradient(yellow, blue)'), {
angle: angle_1.deg(180),
type: image_1.CSSImageType.LINEAR_GRADIENT,
stops: [
{ color: colorParse('yellow'), stop: null },
{ color: colorParse('blue'), stop: null }
{ color: colorParse(context, 'yellow'), stop: null },
{ color: colorParse(context, 'blue'), stop: null }
]

@@ -57,8 +63,8 @@ });

it('linear-gradient(to bottom, yellow, blue)', function () {
return assert_1.deepStrictEqual(parse('linear-gradient(to bottom, yellow, blue)'), {
return assert_1.deepStrictEqual(parse(context, 'linear-gradient(to bottom, yellow, blue)'), {
angle: angle_1.deg(180),
type: image_1.CSSImageType.LINEAR_GRADIENT,
stops: [
{ color: colorParse('yellow'), stop: null },
{ color: colorParse('blue'), stop: null }
{ color: colorParse(context, 'yellow'), stop: null },
{ color: colorParse(context, 'blue'), stop: null }
]

@@ -68,8 +74,8 @@ });

it('linear-gradient(180deg, yellow, blue)', function () {
return assert_1.deepStrictEqual(parse('linear-gradient(180deg, yellow, blue)'), {
return assert_1.deepStrictEqual(parse(context, 'linear-gradient(180deg, yellow, blue)'), {
angle: angle_1.deg(180),
type: image_1.CSSImageType.LINEAR_GRADIENT,
stops: [
{ color: colorParse('yellow'), stop: null },
{ color: colorParse('blue'), stop: null }
{ color: colorParse(context, 'yellow'), stop: null },
{ color: colorParse(context, 'blue'), stop: null }
]

@@ -79,8 +85,8 @@ });

it('linear-gradient(to top, blue, yellow)', function () {
return assert_1.deepStrictEqual(parse('linear-gradient(to top, blue, yellow)'), {
return assert_1.deepStrictEqual(parse(context, 'linear-gradient(to top, blue, yellow)'), {
angle: 0,
type: image_1.CSSImageType.LINEAR_GRADIENT,
stops: [
{ color: colorParse('blue'), stop: null },
{ color: colorParse('yellow'), stop: null }
{ color: colorParse(context, 'blue'), stop: null },
{ color: colorParse(context, 'yellow'), stop: null }
]

@@ -90,3 +96,3 @@ });

it('linear-gradient(to top right, blue, yellow)', function () {
return assert_1.deepStrictEqual(parse('linear-gradient(to top right, blue, yellow)'), {
return assert_1.deepStrictEqual(parse(context, 'linear-gradient(to top right, blue, yellow)'), {
angle: [

@@ -98,4 +104,4 @@ { type: tokenizer_1.TokenType.PERCENTAGE_TOKEN, number: 100, flags: 4 },

stops: [
{ color: colorParse('blue'), stop: null },
{ color: colorParse('yellow'), stop: null }
{ color: colorParse(context, 'blue'), stop: null },
{ color: colorParse(context, 'yellow'), stop: null }
]

@@ -105,3 +111,3 @@ });

it('linear-gradient(to bottom, yellow 0%, blue 100%)', function () {
return assert_1.deepStrictEqual(parse('linear-gradient(to bottom, yellow 0%, blue 100%)'), {
return assert_1.deepStrictEqual(parse(context, 'linear-gradient(to bottom, yellow 0%, blue 100%)'), {
angle: angle_1.deg(180),

@@ -111,3 +117,3 @@ type: image_1.CSSImageType.LINEAR_GRADIENT,

{
color: colorParse('yellow'),
color: colorParse(context, 'yellow'),
stop: {

@@ -120,3 +126,3 @@ type: tokenizer_1.TokenType.PERCENTAGE_TOKEN,

{
color: colorParse('blue'),
color: colorParse(context, 'blue'),
stop: {

@@ -132,3 +138,3 @@ type: tokenizer_1.TokenType.PERCENTAGE_TOKEN,

it('linear-gradient(to top left, lightpink, lightpink 5px, white 5px, white 10px)', function () {
return assert_1.deepStrictEqual(parse('linear-gradient(to top left, lightpink, lightpink 5px, white 5px, white 10px)'), {
return assert_1.deepStrictEqual(parse(context, 'linear-gradient(to top left, lightpink, lightpink 5px, white 5px, white 10px)'), {
angle: [

@@ -140,5 +146,5 @@ { type: tokenizer_1.TokenType.PERCENTAGE_TOKEN, number: 100, flags: 4 },

stops: [
{ color: colorParse('lightpink'), stop: null },
{ color: colorParse(context, 'lightpink'), stop: null },
{
color: colorParse('lightpink'),
color: colorParse(context, 'lightpink'),
stop: {

@@ -152,3 +158,3 @@ type: tokenizer_1.TokenType.DIMENSION_TOKEN,

{
color: colorParse('white'),
color: colorParse(context, 'white'),
stop: {

@@ -162,3 +168,3 @@ type: tokenizer_1.TokenType.DIMENSION_TOKEN,

{
color: colorParse('white'),
color: colorParse(context, 'white'),
stop: {

@@ -177,3 +183,3 @@ type: tokenizer_1.TokenType.DIMENSION_TOKEN,

it('-webkit-linear-gradient(left, #cedbe9 0%, #aac5de 17%, #3a8bc2 84%, #26558b 100%)', function () {
return assert_1.deepStrictEqual(parse('-webkit-linear-gradient(left, #cedbe9 0%, #aac5de 17%, #3a8bc2 84%, #26558b 100%)'), {
return assert_1.deepStrictEqual(parse(context, '-webkit-linear-gradient(left, #cedbe9 0%, #aac5de 17%, #3a8bc2 84%, #26558b 100%)'), {
angle: angle_1.deg(90),

@@ -183,3 +189,3 @@ type: image_1.CSSImageType.LINEAR_GRADIENT,

{
color: colorParse('#cedbe9'),
color: colorParse(context, '#cedbe9'),
stop: {

@@ -192,3 +198,3 @@ type: tokenizer_1.TokenType.PERCENTAGE_TOKEN,

{
color: colorParse('#aac5de'),
color: colorParse(context, '#aac5de'),
stop: {

@@ -201,3 +207,3 @@ type: tokenizer_1.TokenType.PERCENTAGE_TOKEN,

{
color: colorParse('#3a8bc2'),
color: colorParse(context, '#3a8bc2'),
stop: {

@@ -210,3 +216,3 @@ type: tokenizer_1.TokenType.PERCENTAGE_TOKEN,

{
color: colorParse('#26558b'),
color: colorParse(context, '#26558b'),
stop: {

@@ -222,3 +228,3 @@ type: tokenizer_1.TokenType.PERCENTAGE_TOKEN,

it('-moz-linear-gradient(top, #cce5f4 0%, #00263c 100%)', function () {
return assert_1.deepStrictEqual(parse('-moz-linear-gradient(top, #cce5f4 0%, #00263c 100%)'), {
return assert_1.deepStrictEqual(parse(context, '-moz-linear-gradient(top, #cce5f4 0%, #00263c 100%)'), {
angle: angle_1.deg(180),

@@ -228,3 +234,3 @@ type: image_1.CSSImageType.LINEAR_GRADIENT,

{
color: colorParse('#cce5f4'),
color: colorParse(context, '#cce5f4'),
stop: {

@@ -237,3 +243,3 @@ type: tokenizer_1.TokenType.PERCENTAGE_TOKEN,

{
color: colorParse('#00263c'),
color: colorParse(context, '#00263c'),
stop: {

@@ -240,0 +246,0 @@ type: tokenizer_1.TokenType.PERCENTAGE_TOKEN,

@@ -13,3 +13,3 @@ "use strict";

name: 'angle',
parse: function (value) {
parse: function (_context, value) {
if (value.type === tokenizer_1.TokenType.DIMENSION_TOKEN) {

@@ -16,0 +16,0 @@ switch (value.unit) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.COLORS = exports.pack = exports.asString = exports.isTransparent = exports.color = void 0;
exports.COLORS = exports.parseColor = exports.pack = exports.asString = exports.isTransparent = exports.color = void 0;
var parser_1 = require("../syntax/parser");

@@ -10,3 +10,3 @@ var tokenizer_1 = require("../syntax/tokenizer");

name: 'color',
parse: function (value) {
parse: function (context, value) {
if (value.type === tokenizer_1.TokenType.FUNCTION) {

@@ -17,3 +17,3 @@ var colorFunction = SUPPORTED_COLOR_FUNCTIONS[value.name];

}
return colorFunction(value.values);
return colorFunction(context, value.values);
}

@@ -81,3 +81,3 @@ if (value.type === tokenizer_1.TokenType.HASH_TOKEN) {

};
var rgb = function (args) {
var rgb = function (_context, args) {
var tokens = args.filter(parser_1.nonFunctionArgSeparator);

@@ -114,6 +114,6 @@ if (tokens.length === 3) {

}
var hsl = function (args) {
var hsl = function (context, args) {
var tokens = args.filter(parser_1.nonFunctionArgSeparator);
var hue = tokens[0], saturation = tokens[1], lightness = tokens[2], alpha = tokens[3];
var h = (hue.type === tokenizer_1.TokenType.NUMBER_TOKEN ? angle_1.deg(hue.number) : angle_1.angle.parse(hue)) / (Math.PI * 2);
var h = (hue.type === tokenizer_1.TokenType.NUMBER_TOKEN ? angle_1.deg(hue.number) : angle_1.angle.parse(context, hue)) / (Math.PI * 2);
var s = length_percentage_1.isLengthPercentage(saturation) ? saturation.number / 100 : 0;

@@ -138,2 +138,6 @@ var l = length_percentage_1.isLengthPercentage(lightness) ? lightness.number / 100 : 0;

};
var parseColor = function (context, value) {
return exports.color.parse(context, parser_1.Parser.create(value).parseComponentValue());
};
exports.parseColor = parseColor;
exports.COLORS = {

@@ -140,0 +144,0 @@ ALICEBLUE: 0xf0f8ffff,

@@ -10,4 +10,4 @@ "use strict";

var length_percentage_1 = require("../../length-percentage");
var parse = function (value) { return radial_gradient_1.radialGradient(parser_1.Parser.parseValues(value)[0].values); };
var colorParse = function (value) { return color_1.color.parse(parser_1.Parser.parseValue(value)); };
var parse = function (value) { return radial_gradient_1.radialGradient({}, parser_1.Parser.parseValues(value)[0].values); };
var colorParse = function (value) { return color_1.color.parse({}, parser_1.Parser.parseValue(value)); };
describe('functions', function () {

@@ -14,0 +14,0 @@ describe('radial-gradient', function () {

@@ -9,3 +9,3 @@ "use strict";

var gradient_1 = require("./gradient");
var prefixLinearGradient = function (tokens) {
var prefixLinearGradient = function (context, tokens) {
var angle = angle_1.deg(180);

@@ -22,7 +22,7 @@ var stops = [];

else if (angle_1.isAngle(firstToken)) {
angle = (angle_1.angle.parse(firstToken) + angle_1.deg(270)) % angle_1.deg(360);
angle = (angle_1.angle.parse(context, firstToken) + angle_1.deg(270)) % angle_1.deg(360);
return;
}
}
var colorStop = gradient_1.parseColorStop(arg);
var colorStop = gradient_1.parseColorStop(context, arg);
stops.push(colorStop);

@@ -29,0 +29,0 @@ });

@@ -10,3 +10,3 @@ "use strict";

var radial_gradient_1 = require("./radial-gradient");
var prefixRadialGradient = function (tokens) {
var prefixRadialGradient = function (context, tokens) {
var shape = image_1.CSSRadialShape.CIRCLE;

@@ -79,3 +79,3 @@ var size = image_1.CSSRadialExtent.FARTHEST_CORNER;

if (isColorStop) {
var colorStop = gradient_1.parseColorStop(arg);
var colorStop = gradient_1.parseColorStop(context, arg);
stops.push(colorStop);

@@ -82,0 +82,0 @@ }

@@ -10,3 +10,3 @@ "use strict";

var length_percentage_1 = require("../length-percentage");
var webkitGradient = function (tokens) {
var webkitGradient = function (context, tokens) {
var angle = angle_1.deg(180);

@@ -32,7 +32,7 @@ var stops = [];

if (firstToken.name === 'from') {
var color = color_1.color.parse(firstToken.values[0]);
var color = color_1.color.parse(context, firstToken.values[0]);
stops.push({ stop: length_percentage_1.ZERO_LENGTH, color: color });
}
else if (firstToken.name === 'to') {
var color = color_1.color.parse(firstToken.values[0]);
var color = color_1.color.parse(context, firstToken.values[0]);
stops.push({ stop: length_percentage_1.HUNDRED_PERCENT, color: color });

@@ -43,3 +43,3 @@ }

if (values.length === 2) {
var color = color_1.color.parse(values[1]);
var color = color_1.color.parse(context, values[1]);
var stop_1 = values[0];

@@ -46,0 +46,0 @@ if (parser_1.isNumberToken(stop_1)) {

@@ -7,4 +7,4 @@ "use strict";

var length_percentage_1 = require("../length-percentage");
var parseColorStop = function (args) {
var color = color_1.color.parse(args[0]);
var parseColorStop = function (context, args) {
var color = color_1.color.parse(context, args[0]);
var stop = args[1];

@@ -11,0 +11,0 @@ return stop && length_percentage_1.isLengthPercentage(stop) ? { color: color, stop: stop } : { color: color, stop: null };

@@ -9,3 +9,3 @@ "use strict";

var gradient_1 = require("./gradient");
var linearGradient = function (tokens) {
var linearGradient = function (context, tokens) {
var angle = angle_1.deg(180);

@@ -21,7 +21,7 @@ var stops = [];

else if (angle_1.isAngle(firstToken)) {
angle = angle_1.angle.parse(firstToken);
angle = angle_1.angle.parse(context, firstToken);
return;
}
}
var colorStop = gradient_1.parseColorStop(arg);
var colorStop = gradient_1.parseColorStop(context, arg);
stops.push(colorStop);

@@ -28,0 +28,0 @@ });

@@ -17,3 +17,3 @@ "use strict";

exports.CONTAIN = 'contain';
var radialGradient = function (tokens) {
var radialGradient = function (context, tokens) {
var shape = image_1.CSSRadialShape.CIRCLE;

@@ -86,3 +86,3 @@ var size = image_1.CSSRadialExtent.FARTHEST_CORNER;

if (isColorStop) {
var colorStop = gradient_1.parseColorStop(arg);
var colorStop = gradient_1.parseColorStop(context, arg);
stops.push(colorStop);

@@ -89,0 +89,0 @@ }

@@ -7,3 +7,2 @@ "use strict";

var _prefix_linear_gradient_1 = require("./functions/-prefix-linear-gradient");
var cache_storage_1 = require("../../core/cache-storage");
var _webkit_gradient_1 = require("./functions/-webkit-gradient");

@@ -40,6 +39,6 @@ var radial_gradient_1 = require("./functions/radial-gradient");

name: 'image',
parse: function (value) {
parse: function (context, value) {
if (value.type === tokenizer_1.TokenType.URL_TOKEN) {
var image_1 = { url: value.value, type: CSSImageType.URL };
cache_storage_1.CacheStorage.getInstance().addImage(value.value);
context.cache.addImage(value.value);
return image_1;

@@ -52,3 +51,3 @@ }

}
return imageFunction(value.values);
return imageFunction(context, value.values);
}

@@ -55,0 +54,0 @@ throw new Error("Unsupported image type");

@@ -6,3 +6,10 @@ "use strict";

function DocumentCloner() {
this.clonedReferenceElement = {};
this.clonedReferenceElement = {
ownerDocument: {
defaultView: {
pageXOffset: 12,
pageYOffset: 34
}
}
};
}

@@ -9,0 +16,0 @@ DocumentCloner.prototype.toIFrame = function () {

@@ -41,3 +41,2 @@ "use strict";

var node_parser_1 = require("./node-parser");
var logger_1 = require("../core/logger");
var parser_1 = require("../css/syntax/parser");

@@ -51,3 +50,4 @@ var tokenizer_1 = require("../css/syntax/tokenizer");

var DocumentCloner = /** @class */ (function () {
function DocumentCloner(element, options) {
function DocumentCloner(context, element, options) {
this.context = context;
this.options = options;

@@ -86,5 +86,4 @@ this.scrolledElements = [];

(cloneWindow.scrollY !== windowSize.top || cloneWindow.scrollX !== windowSize.left)) {
documentClone.documentElement.style.top = -windowSize.top + 'px';
documentClone.documentElement.style.left = -windowSize.left + 'px';
documentClone.documentElement.style.position = 'absolute';
this.context.logger.warn('Unable to restore scroll position for cloned document');
this.context.windowBounds = this.context.windowBounds.add(cloneWindow.scrollX - windowSize.left, cloneWindow.scrollY - windowSize.top, 0, 0);
}

@@ -162,3 +161,3 @@ }

// accessing node.sheet.cssRules throws a DOMException
logger_1.Logger.getInstance(this.options.id).error('Unable to access cssRules property', e);
this.context.logger.error('Unable to access cssRules property', e);
if (e.name !== 'SecurityError') {

@@ -178,3 +177,3 @@ throw e;

catch (e) {
logger_1.Logger.getInstance(this.options.id).info("Unable to clone canvas contents, canvas is tainted");
this.context.logger.info("Unable to clone canvas contents, canvas is tainted");
}

@@ -220,3 +219,3 @@ }

}
var counters = this.counters.parse(new index_1.CSSParsedCounterDeclaration(style));
var counters = this.counters.parse(new index_1.CSSParsedCounterDeclaration(this.context, style));
var before = this.resolvePseudoContent(node, clone, styleBefore, PseudoElementType.BEFORE);

@@ -265,4 +264,4 @@ for (var child = node.firstChild; child; child = child.nextSibling) {

}
this.counters.parse(new index_1.CSSParsedCounterDeclaration(style));
var declaration = new index_1.CSSParsedPseudoDeclaration(style);
this.counters.parse(new index_1.CSSParsedCounterDeclaration(this.context, style));
var declaration = new index_1.CSSParsedPseudoDeclaration(this.context, style);
var anonymousReplacedElement = document.createElement('html2canvaspseudoelement');

@@ -292,3 +291,3 @@ exports.copyCSSStyles(style, anonymousReplacedElement);

var counterType = counterStyle && parser_1.isIdentToken(counterStyle)
? list_style_type_1.listStyleType.parse(counterStyle.value)
? list_style_type_1.listStyleType.parse(_this.context, counterStyle.value)
: list_style_type_1.LIST_STYLE_TYPE.DECIMAL;

@@ -303,3 +302,3 @@ anonymousReplacedElement.appendChild(document.createTextNode(counter_1.createCounterText(counterState, counterType, false)));

var counterType_1 = counterStyle && parser_1.isIdentToken(counterStyle)
? list_style_type_1.listStyleType.parse(counterStyle.value)
? list_style_type_1.listStyleType.parse(_this.context, counterStyle.value)
: list_style_type_1.LIST_STYLE_TYPE.DECIMAL;

@@ -306,0 +305,0 @@ var separator = delim && delim.type === tokenizer_1.TokenType.STRING_TOKEN ? delim.value : '';

@@ -8,4 +8,5 @@ "use strict";

var ElementContainer = /** @class */ (function () {
function ElementContainer(element) {
this.styles = new index_1.CSSParsedDeclaration(window.getComputedStyle(element, null));
function ElementContainer(context, element) {
this.context = context;
this.styles = new index_1.CSSParsedDeclaration(context, window.getComputedStyle(element, null));
this.textNodes = [];

@@ -17,3 +18,3 @@ this.elements = [];

}
this.bounds = bounds_1.parseBounds(element);
this.bounds = bounds_1.parseBounds(this.context, element);
this.flags = 0;

@@ -20,0 +21,0 @@ }

@@ -22,4 +22,4 @@ "use strict";

__extends(LIElementContainer, _super);
function LIElementContainer(element) {
var _this = _super.call(this, element) || this;
function LIElementContainer(context, element) {
var _this = _super.call(this, context, element) || this;
_this.value = element.value;

@@ -26,0 +26,0 @@ return _this;

@@ -22,4 +22,4 @@ "use strict";

__extends(OLElementContainer, _super);
function OLElementContainer(element) {
var _this = _super.call(this, element) || this;
function OLElementContainer(context, element) {
var _this = _super.call(this, context, element) || this;
_this.start = element.start;

@@ -26,0 +26,0 @@ _this.reversed = typeof element.reversed === 'boolean' && element.reversed === true;

@@ -22,4 +22,4 @@ "use strict";

__extends(SelectElementContainer, _super);
function SelectElementContainer(element) {
var _this = _super.call(this, element) || this;
function SelectElementContainer(context, element) {
var _this = _super.call(this, context, element) || this;
var option = element.options[element.selectedIndex || 0];

@@ -26,0 +26,0 @@ _this.value = option ? option.text || '' : '';

@@ -22,4 +22,4 @@ "use strict";

__extends(TextareaElementContainer, _super);
function TextareaElementContainer(element) {
var _this = _super.call(this, element) || this;
function TextareaElementContainer(context, element) {
var _this = _super.call(this, context, element) || this;
_this.value = element.value;

@@ -26,0 +26,0 @@ return _this;

@@ -16,14 +16,14 @@ "use strict";

var LIST_OWNERS = ['OL', 'UL', 'MENU'];
var parseNodeTree = function (node, parent, root) {
var parseNodeTree = function (context, node, parent, root) {
for (var childNode = node.firstChild, nextNode = void 0; childNode; childNode = nextNode) {
nextNode = childNode.nextSibling;
if (exports.isTextNode(childNode) && childNode.data.trim().length > 0) {
parent.textNodes.push(new text_container_1.TextContainer(childNode, parent.styles));
parent.textNodes.push(new text_container_1.TextContainer(context, childNode, parent.styles));
}
else if (exports.isElementNode(childNode)) {
if (exports.isSlotElement(childNode) && childNode.assignedNodes) {
childNode.assignedNodes().forEach(function (childNode) { return parseNodeTree(childNode, parent, root); });
childNode.assignedNodes().forEach(function (childNode) { return parseNodeTree(context, childNode, parent, root); });
}
else {
var container = createContainer(childNode);
var container = createContainer(context, childNode);
if (container.styles.isVisible()) {

@@ -42,3 +42,3 @@ if (createsRealStackingContext(childNode, container, root)) {

if (childNode.shadowRoot) {
parseNodeTree(childNode.shadowRoot, container, root);
parseNodeTree(context, childNode.shadowRoot, container, root);
}

@@ -48,3 +48,3 @@ else if (!exports.isTextareaElement(childNode) &&

!exports.isSelectElement(childNode)) {
parseNodeTree(childNode, container, root);
parseNodeTree(context, childNode, container, root);
}

@@ -56,36 +56,36 @@ }

};
var createContainer = function (element) {
var createContainer = function (context, element) {
if (exports.isImageElement(element)) {
return new image_element_container_1.ImageElementContainer(element);
return new image_element_container_1.ImageElementContainer(context, element);
}
if (exports.isCanvasElement(element)) {
return new canvas_element_container_1.CanvasElementContainer(element);
return new canvas_element_container_1.CanvasElementContainer(context, element);
}
if (exports.isSVGElement(element)) {
return new svg_element_container_1.SVGElementContainer(element);
return new svg_element_container_1.SVGElementContainer(context, element);
}
if (exports.isLIElement(element)) {
return new li_element_container_1.LIElementContainer(element);
return new li_element_container_1.LIElementContainer(context, element);
}
if (exports.isOLElement(element)) {
return new ol_element_container_1.OLElementContainer(element);
return new ol_element_container_1.OLElementContainer(context, element);
}
if (exports.isInputElement(element)) {
return new input_element_container_1.InputElementContainer(element);
return new input_element_container_1.InputElementContainer(context, element);
}
if (exports.isSelectElement(element)) {
return new select_element_container_1.SelectElementContainer(element);
return new select_element_container_1.SelectElementContainer(context, element);
}
if (exports.isTextareaElement(element)) {
return new textarea_element_container_1.TextareaElementContainer(element);
return new textarea_element_container_1.TextareaElementContainer(context, element);
}
if (exports.isIFrameElement(element)) {
return new iframe_element_container_1.IFrameElementContainer(element);
return new iframe_element_container_1.IFrameElementContainer(context, element);
}
return new element_container_1.ElementContainer(element);
return new element_container_1.ElementContainer(context, element);
};
var parseTree = function (element) {
var container = createContainer(element);
var parseTree = function (context, element) {
var container = createContainer(context, element);
container.flags |= 4 /* CREATES_REAL_STACKING_CONTEXT */;
parseNodeTree(element, container, container);
parseNodeTree(context, element, container, container);
return container;

@@ -92,0 +92,0 @@ };

@@ -22,4 +22,4 @@ "use strict";

__extends(CanvasElementContainer, _super);
function CanvasElementContainer(canvas) {
var _this = _super.call(this, canvas) || this;
function CanvasElementContainer(context, canvas) {
var _this = _super.call(this, context, canvas) || this;
_this.canvas = canvas;

@@ -26,0 +26,0 @@ _this.intrinsicWidth = canvas.width;

@@ -22,8 +22,6 @@ "use strict";

var color_1 = require("../../css/types/color");
var parser_1 = require("../../css/syntax/parser");
var parseColor = function (value) { return color_1.color.parse(parser_1.Parser.create(value).parseComponentValue()); };
var IFrameElementContainer = /** @class */ (function (_super) {
__extends(IFrameElementContainer, _super);
function IFrameElementContainer(iframe) {
var _this = _super.call(this, iframe) || this;
function IFrameElementContainer(context, iframe) {
var _this = _super.call(this, context, iframe) || this;
_this.src = iframe.src;

@@ -37,9 +35,9 @@ _this.width = parseInt(iframe.width, 10) || 0;

iframe.contentWindow.document.documentElement) {
_this.tree = node_parser_1.parseTree(iframe.contentWindow.document.documentElement);
_this.tree = node_parser_1.parseTree(context, iframe.contentWindow.document.documentElement);
// http://www.w3.org/TR/css3-background/#special-backgrounds
var documentBackgroundColor = iframe.contentWindow.document.documentElement
? parseColor(getComputedStyle(iframe.contentWindow.document.documentElement).backgroundColor)
? color_1.parseColor(context, getComputedStyle(iframe.contentWindow.document.documentElement).backgroundColor)
: color_1.COLORS.TRANSPARENT;
var bodyBackgroundColor = iframe.contentWindow.document.body
? parseColor(getComputedStyle(iframe.contentWindow.document.body).backgroundColor)
? color_1.parseColor(context, getComputedStyle(iframe.contentWindow.document.body).backgroundColor)
: color_1.COLORS.TRANSPARENT;

@@ -46,0 +44,0 @@ _this.backgroundColor = color_1.isTransparent(documentBackgroundColor)

@@ -20,11 +20,10 @@ "use strict";

var element_container_1 = require("../element-container");
var cache_storage_1 = require("../../core/cache-storage");
var ImageElementContainer = /** @class */ (function (_super) {
__extends(ImageElementContainer, _super);
function ImageElementContainer(img) {
var _this = _super.call(this, img) || this;
function ImageElementContainer(context, img) {
var _this = _super.call(this, context, img) || this;
_this.src = img.currentSrc || img.src;
_this.intrinsicWidth = img.naturalWidth;
_this.intrinsicHeight = img.naturalHeight;
cache_storage_1.CacheStorage.getInstance().addImage(_this.src);
_this.context.cache.addImage(_this.src);
return _this;

@@ -31,0 +30,0 @@ }

@@ -58,4 +58,4 @@ "use strict";

__extends(InputElementContainer, _super);
function InputElementContainer(input) {
var _this = _super.call(this, input) || this;
function InputElementContainer(context, input) {
var _this = _super.call(this, context, input) || this;
_this.type = input.type.toLowerCase();

@@ -62,0 +62,0 @@ _this.checked = input.checked;

@@ -20,10 +20,9 @@ "use strict";

var element_container_1 = require("../element-container");
var cache_storage_1 = require("../../core/cache-storage");
var bounds_1 = require("../../css/layout/bounds");
var SVGElementContainer = /** @class */ (function (_super) {
__extends(SVGElementContainer, _super);
function SVGElementContainer(img) {
var _this = _super.call(this, img) || this;
function SVGElementContainer(context, img) {
var _this = _super.call(this, context, img) || this;
var s = new XMLSerializer();
var bounds = bounds_1.parseBounds(img);
var bounds = bounds_1.parseBounds(context, img);
img.setAttribute('width', bounds.width + "px");

@@ -34,3 +33,3 @@ img.setAttribute('height', bounds.height + "px");

_this.intrinsicHeight = img.height.baseVal.value;
cache_storage_1.CacheStorage.getInstance().addImage(_this.svg);
_this.context.cache.addImage(_this.svg);
return _this;

@@ -37,0 +36,0 @@ }

@@ -7,5 +7,5 @@ "use strict";

var TextContainer = /** @class */ (function () {
function TextContainer(node, styles) {
function TextContainer(context, node, styles) {
this.text = transform(node.data, styles.textTransform);
this.textBounds = text_1.parseTextBounds(this.text, styles, node);
this.textBounds = text_1.parseTextBounds(context, this.text, styles, node);
}

@@ -12,0 +12,0 @@ return TextContainer;

@@ -52,10 +52,8 @@ "use strict";

var color_1 = require("./css/types/color");
var parser_1 = require("./css/syntax/parser");
var document_cloner_1 = require("./dom/document-cloner");
var node_parser_1 = require("./dom/node-parser");
var logger_1 = require("./core/logger");
var cache_storage_1 = require("./core/cache-storage");
var canvas_renderer_1 = require("./render/canvas/canvas-renderer");
var foreignobject_renderer_1 = require("./render/canvas/foreignobject-renderer");
var parseColor = function (value) { return color_1.color.parse(parser_1.Parser.create(value).parseComponentValue()); };
var context_1 = require("./core/context");
var html2canvas = function (element, options) {

@@ -69,7 +67,7 @@ if (options === void 0) { options = {}; }

}
var instanceCount = 1;
var renderElement = function (element, opts) { return __awaiter(void 0, void 0, void 0, function () {
var ownerDocument, defaultView, instanceName, _a, width, height, left, top, defaultResourceOptions, resourceOptions, defaultOptions, options, windowBounds, documentCloner, clonedElement, container, documentBackgroundColor, bodyBackgroundColor, bgColor, defaultBackgroundColor, backgroundColor, renderOptions, canvas, renderer, root, renderer;
return __generator(this, function (_b) {
switch (_b.label) {
var ownerDocument, defaultView, resourceOptions, contextOptions, windowOptions, windowBounds, context, foreignObjectRendering, cloneOptions, documentCloner, clonedElement, container, _a, width, height, left, top, backgroundColor, renderOptions, canvas, renderer, root, renderer;
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
return __generator(this, function (_t) {
switch (_t.label) {
case 0:

@@ -87,39 +85,26 @@ if (!element || typeof element !== 'object') {

}
instanceName = "#" + instanceCount++;
_a = node_parser_1.isBodyElement(element) || node_parser_1.isHTMLElement(element) ? bounds_1.parseDocumentSize(ownerDocument) : bounds_1.parseBounds(element), width = _a.width, height = _a.height, left = _a.left, top = _a.top;
defaultResourceOptions = {
allowTaint: false,
imageTimeout: 15000,
proxy: undefined,
useCORS: false
resourceOptions = {
allowTaint: (_b = opts.allowTaint) !== null && _b !== void 0 ? _b : false,
imageTimeout: (_c = opts.imageTimeout) !== null && _c !== void 0 ? _c : 15000,
proxy: opts.proxy,
useCORS: (_d = opts.useCORS) !== null && _d !== void 0 ? _d : false
};
resourceOptions = __assign(__assign({}, defaultResourceOptions), opts);
defaultOptions = {
backgroundColor: '#ffffff',
cache: opts.cache ? opts.cache : cache_storage_1.CacheStorage.create(instanceName, resourceOptions),
logging: true,
removeContainer: true,
foreignObjectRendering: false,
scale: defaultView.devicePixelRatio || 1,
windowWidth: defaultView.innerWidth,
windowHeight: defaultView.innerHeight,
scrollX: defaultView.pageXOffset,
scrollY: defaultView.pageYOffset,
x: left,
y: top,
width: Math.ceil(width),
height: Math.ceil(height),
id: instanceName
contextOptions = __assign({ logging: (_e = opts.logging) !== null && _e !== void 0 ? _e : true, cache: opts.cache }, resourceOptions);
windowOptions = {
windowWidth: (_f = opts.windowWidth) !== null && _f !== void 0 ? _f : defaultView.innerWidth,
windowHeight: (_g = opts.windowHeight) !== null && _g !== void 0 ? _g : defaultView.innerHeight,
scrollX: (_h = opts.scrollX) !== null && _h !== void 0 ? _h : defaultView.pageXOffset,
scrollY: (_j = opts.scrollY) !== null && _j !== void 0 ? _j : defaultView.pageYOffset
};
options = __assign(__assign(__assign({}, defaultOptions), resourceOptions), opts);
windowBounds = new bounds_1.Bounds(options.scrollX, options.scrollY, options.windowWidth, options.windowHeight);
logger_1.Logger.create({ id: instanceName, enabled: options.logging });
logger_1.Logger.getInstance(instanceName).debug("Starting document clone");
documentCloner = new document_cloner_1.DocumentCloner(element, {
id: instanceName,
onclone: options.onclone,
ignoreElements: options.ignoreElements,
inlineImages: options.foreignObjectRendering,
copyStyles: options.foreignObjectRendering
});
windowBounds = new bounds_1.Bounds(windowOptions.scrollX, windowOptions.scrollY, windowOptions.windowWidth, windowOptions.windowHeight);
context = new context_1.Context(contextOptions, windowBounds);
foreignObjectRendering = (_k = opts.foreignObjectRendering) !== null && _k !== void 0 ? _k : false;
cloneOptions = {
onclone: opts.onclone,
ignoreElements: opts.ignoreElements,
inlineImages: foreignObjectRendering,
copyStyles: foreignObjectRendering
};
context.logger.debug("Starting document clone with size " + windowBounds.width + "x" + windowBounds.height + " scrolled to " + -windowBounds.left + "," + -windowBounds.top);
documentCloner = new document_cloner_1.DocumentCloner(context, element, cloneOptions);
clonedElement = documentCloner.clonedReferenceElement;

@@ -131,64 +116,43 @@ if (!clonedElement) {

case 1:
container = _b.sent();
documentBackgroundColor = ownerDocument.documentElement
? parseColor(getComputedStyle(ownerDocument.documentElement).backgroundColor)
: color_1.COLORS.TRANSPARENT;
bodyBackgroundColor = ownerDocument.body
? parseColor(getComputedStyle(ownerDocument.body).backgroundColor)
: color_1.COLORS.TRANSPARENT;
bgColor = opts.backgroundColor;
defaultBackgroundColor = typeof bgColor === 'string' ? parseColor(bgColor) : bgColor === null ? color_1.COLORS.TRANSPARENT : 0xffffffff;
backgroundColor = element === ownerDocument.documentElement
? color_1.isTransparent(documentBackgroundColor)
? color_1.isTransparent(bodyBackgroundColor)
? defaultBackgroundColor
: bodyBackgroundColor
: documentBackgroundColor
: defaultBackgroundColor;
container = _t.sent();
_a = node_parser_1.isBodyElement(clonedElement) || node_parser_1.isHTMLElement(clonedElement)
? bounds_1.parseDocumentSize(clonedElement.ownerDocument)
: bounds_1.parseBounds(context, clonedElement), width = _a.width, height = _a.height, left = _a.left, top = _a.top;
backgroundColor = parseBackgroundColor(context, clonedElement, opts.backgroundColor);
renderOptions = {
id: instanceName,
cache: options.cache,
canvas: options.canvas,
canvas: opts.canvas,
backgroundColor: backgroundColor,
scale: options.scale,
x: options.x,
y: options.y,
scrollX: options.scrollX,
scrollY: options.scrollY,
width: options.width,
height: options.height,
windowWidth: options.windowWidth,
windowHeight: options.windowHeight
scale: (_m = (_l = opts.scale) !== null && _l !== void 0 ? _l : defaultView.devicePixelRatio) !== null && _m !== void 0 ? _m : 1,
x: ((_o = opts.x) !== null && _o !== void 0 ? _o : 0) + left,
y: ((_p = opts.y) !== null && _p !== void 0 ? _p : 0) + top,
width: (_q = opts.width) !== null && _q !== void 0 ? _q : Math.ceil(width),
height: (_r = opts.height) !== null && _r !== void 0 ? _r : Math.ceil(height)
};
if (!options.foreignObjectRendering) return [3 /*break*/, 3];
logger_1.Logger.getInstance(instanceName).debug("Document cloned, using foreign object rendering");
renderer = new foreignobject_renderer_1.ForeignObjectRenderer(renderOptions);
if (!foreignObjectRendering) return [3 /*break*/, 3];
context.logger.debug("Document cloned, using foreign object rendering");
renderer = new foreignobject_renderer_1.ForeignObjectRenderer(context, renderOptions);
return [4 /*yield*/, renderer.render(clonedElement)];
case 2:
canvas = _b.sent();
canvas = _t.sent();
return [3 /*break*/, 5];
case 3:
logger_1.Logger.getInstance(instanceName).debug("Document cloned, using computed rendering");
cache_storage_1.CacheStorage.attachInstance(options.cache);
logger_1.Logger.getInstance(instanceName).debug("Starting DOM parsing");
root = node_parser_1.parseTree(clonedElement);
cache_storage_1.CacheStorage.detachInstance();
context.logger.debug("Document cloned, element located at " + left + "," + top + " with size " + width + "x" + height + " using computed rendering");
context.logger.debug("Starting DOM parsing");
root = node_parser_1.parseTree(context, clonedElement);
if (backgroundColor === root.styles.backgroundColor) {
root.styles.backgroundColor = color_1.COLORS.TRANSPARENT;
}
logger_1.Logger.getInstance(instanceName).debug("Starting renderer");
renderer = new canvas_renderer_1.CanvasRenderer(renderOptions);
context.logger.debug("Starting renderer for element at " + renderOptions.x + "," + renderOptions.y + " with size " + renderOptions.width + "x" + renderOptions.height);
renderer = new canvas_renderer_1.CanvasRenderer(context, renderOptions);
return [4 /*yield*/, renderer.render(root)];
case 4:
canvas = _b.sent();
_b.label = 5;
canvas = _t.sent();
_t.label = 5;
case 5:
if (options.removeContainer === true) {
if ((_s = opts.removeContainer) !== null && _s !== void 0 ? _s : true) {
if (!document_cloner_1.DocumentCloner.destroy(container)) {
logger_1.Logger.getInstance(instanceName).error("Cannot detach cloned iframe as it is not in the DOM anymore");
context.logger.error("Cannot detach cloned iframe as it is not in the DOM anymore");
}
}
logger_1.Logger.getInstance(instanceName).debug("Finished rendering");
logger_1.Logger.destroy(instanceName);
cache_storage_1.CacheStorage.destroy(instanceName);
context.logger.debug("Finished rendering");
return [2 /*return*/, canvas];

@@ -198,2 +162,24 @@ }

}); };
var parseBackgroundColor = function (context, element, backgroundColorOverride) {
var ownerDocument = element.ownerDocument;
// http://www.w3.org/TR/css3-background/#special-backgrounds
var documentBackgroundColor = ownerDocument.documentElement
? color_1.parseColor(context, getComputedStyle(ownerDocument.documentElement).backgroundColor)
: color_1.COLORS.TRANSPARENT;
var bodyBackgroundColor = ownerDocument.body
? color_1.parseColor(context, getComputedStyle(ownerDocument.body).backgroundColor)
: color_1.COLORS.TRANSPARENT;
var defaultBackgroundColor = typeof backgroundColorOverride === 'string'
? color_1.parseColor(context, backgroundColorOverride)
: backgroundColorOverride === null
? color_1.COLORS.TRANSPARENT
: 0xffffffff;
return element === ownerDocument.documentElement
? color_1.isTransparent(documentBackgroundColor)
? color_1.isTransparent(bodyBackgroundColor)
? defaultBackgroundColor
: bodyBackgroundColor
: documentBackgroundColor
: defaultBackgroundColor;
};
//# sourceMappingURL=index.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -42,3 +57,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

var color_1 = require("../../css/types/color");
var logger_1 = require("../../core/logger");
var border_style_1 = require("../../css/property-descriptors/border-style");

@@ -74,21 +88,24 @@ var path_1 = require("../path");

var paint_order_1 = require("../../css/property-descriptors/paint-order");
var renderer_1 = require("../renderer");
var MASK_OFFSET = 10000;
var CanvasRenderer = /** @class */ (function () {
function CanvasRenderer(options) {
this._activeEffects = [];
this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
this.ctx = this.canvas.getContext('2d');
this.options = options;
var CanvasRenderer = /** @class */ (function (_super) {
__extends(CanvasRenderer, _super);
function CanvasRenderer(context, options) {
var _this = _super.call(this, context, options) || this;
_this._activeEffects = [];
_this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
_this.ctx = _this.canvas.getContext('2d');
if (!options.canvas) {
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.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.fontMetrics = new font_metrics_1.FontMetrics(document);
this.ctx.scale(this.options.scale, this.options.scale);
this.ctx.translate(-options.x + options.scrollX, -options.y + options.scrollY);
this.ctx.textBaseline = 'bottom';
this._activeEffects = [];
logger_1.Logger.getInstance(options.id).debug("Canvas renderer initialized (" + options.width + "x" + options.height + " at " + options.x + "," + options.y + ") with scale " + options.scale);
_this.fontMetrics = new font_metrics_1.FontMetrics(document);
_this.ctx.scale(_this.options.scale, _this.options.scale);
_this.ctx.translate(-options.x, -options.y);
_this.ctx.textBaseline = 'bottom';
_this._activeEffects = [];
_this.context.logger.debug("Canvas renderer initialized (" + options.width + "x" + options.height + ") with scale " + options.scale);
return _this;
}

@@ -242,2 +259,3 @@ CanvasRenderer.prototype.applyEffects = function (effects, target) {

_this.ctx.lineWidth = styles.webkitTextStrokeWidth;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_this.ctx.lineJoin = !!window.chrome ? 'miter' : 'round';

@@ -295,3 +313,3 @@ _this.ctx.strokeText(text.text, text.bounds.left, text.bounds.top + baseline);

_c.trys.push([5, 7, , 8]);
return [4 /*yield*/, this.options.cache.match(container.src)];
return [4 /*yield*/, this.context.cache.match(container.src)];
case 6:

@@ -303,3 +321,3 @@ image = _c.sent();

e_1 = _c.sent();
logger_1.Logger.getInstance(this.options.id).error("Error loading image " + container.src);
this.context.logger.error("Error loading image " + container.src);
return [3 /*break*/, 8];

@@ -314,3 +332,3 @@ case 8:

_c.trys.push([9, 11, , 12]);
return [4 /*yield*/, this.options.cache.match(container.svg)];
return [4 /*yield*/, this.context.cache.match(container.svg)];
case 10:

@@ -322,8 +340,7 @@ image = _c.sent();

e_2 = _c.sent();
logger_1.Logger.getInstance(this.options.id).error("Error loading svg " + container.svg.substring(0, 255));
this.context.logger.error("Error loading svg " + container.svg.substring(0, 255));
return [3 /*break*/, 12];
case 12:
if (!(container instanceof iframe_element_container_1.IFrameElementContainer && container.tree)) return [3 /*break*/, 14];
iframeRenderer = new CanvasRenderer({
id: this.options.id,
iframeRenderer = new CanvasRenderer(this.context, {
scale: this.options.scale,

@@ -333,9 +350,4 @@ backgroundColor: container.backgroundColor,

y: 0,
scrollX: 0,
scrollY: 0,
width: container.width,
height: container.height,
cache: this.options.cache,
windowWidth: container.width,
windowHeight: container.height
height: container.height
});

@@ -420,3 +432,3 @@ return [4 /*yield*/, iframeRenderer.render(container.tree)];

_c.trys.push([15, 17, , 18]);
return [4 /*yield*/, this.options.cache.match(url)];
return [4 /*yield*/, this.context.cache.match(url)];
case 16:

@@ -428,3 +440,3 @@ image = _c.sent();

e_3 = _c.sent();
logger_1.Logger.getInstance(this.options.id).error("Error loading list-style-image " + url);
this.context.logger.error("Error loading list-style-image " + url);
return [3 /*break*/, 18];

@@ -631,3 +643,3 @@ case 18: return [3 /*break*/, 20];

_h.trys.push([1, 3, , 4]);
return [4 /*yield*/, this_1.options.cache.match(url)];
return [4 /*yield*/, this_1.context.cache.match(url)];
case 2:

@@ -638,3 +650,3 @@ image = _h.sent();

e_4 = _h.sent();
logger_1.Logger.getInstance(this_1.options.id).error("Error loading background-image " + url);
this_1.context.logger.error("Error loading background-image " + url);
return [3 /*break*/, 4];

@@ -972,3 +984,3 @@ case 4:

this.ctx.fillStyle = color_1.asString(this.options.backgroundColor);
this.ctx.fillRect(this.options.x - this.options.scrollX, this.options.y - this.options.scrollY, this.options.width, this.options.height);
this.ctx.fillRect(this.options.x, this.options.y, this.options.width, this.options.height);
}

@@ -986,3 +998,3 @@ stack = stacking_context_1.parseStackingContexts(element);

return CanvasRenderer;
}());
}(renderer_1.Renderer));
exports.CanvasRenderer = CanvasRenderer;

@@ -989,0 +1001,0 @@ var isTextInputElement = function (container) {

"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -40,17 +55,20 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

exports.loadSerializedSVG = exports.ForeignObjectRenderer = void 0;
var logger_1 = require("../../core/logger");
var features_1 = require("../../core/features");
var color_1 = require("../../css/types/color");
var ForeignObjectRenderer = /** @class */ (function () {
function ForeignObjectRenderer(options) {
this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
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.scrollX, -options.y + options.scrollY);
logger_1.Logger.getInstance(options.id).debug("EXPERIMENTAL ForeignObject renderer initialized (" + options.width + "x" + options.height + " at " + options.x + "," + options.y + ") with scale " + options.scale);
var renderer_1 = require("../renderer");
var ForeignObjectRenderer = /** @class */ (function (_super) {
__extends(ForeignObjectRenderer, _super);
function ForeignObjectRenderer(context, options) {
var _this = _super.call(this, context, options) || this;
_this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
_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.context.logger.debug("EXPERIMENTAL ForeignObject renderer initialized (" + options.width + "x" + options.height + " at " + options.x + "," + options.y + ") with scale " + options.scale);
return _this;
}

@@ -63,3 +81,3 @@ ForeignObjectRenderer.prototype.render = function (element) {

case 0:
svg = features_1.createForeignObjectSVG(Math.max(this.options.windowWidth, this.options.width) * this.options.scale, Math.max(this.options.windowHeight, this.options.height) * this.options.scale, this.options.scrollX * this.options.scale, this.options.scrollY * this.options.scale, element);
svg = features_1.createForeignObjectSVG(this.options.width * this.options.scale, this.options.height * this.options.scale, this.options.scale, this.options.scale, element);
return [4 /*yield*/, exports.loadSerializedSVG(svg)];

@@ -79,3 +97,3 @@ case 1:

return ForeignObjectRenderer;
}());
}(renderer_1.Renderer));
exports.ForeignObjectRenderer = ForeignObjectRenderer;

@@ -82,0 +100,0 @@ var loadSerializedSVG = function (svg) {

@@ -1,9 +0,2 @@

declare class MockCache {
private readonly _cache;
constructor();
addImage(src: string): Promise<void>;
}
export declare class CacheStorage {
static getInstance(): MockCache;
}
export {};

@@ -9,1 +9,2 @@ export declare class Logger {

}
export declare const logger: Logger;

@@ -0,15 +1,8 @@

import type { Context } from './context';
export declare class CacheStorage {
private static _caches;
private static _link?;
private static _origin;
private static _current;
static create(name: string, options: ResourceOptions): Cache;
static destroy(name: string): void;
static open(name: string): Cache;
static getOrigin(url: string): string;
static isSameOrigin(src: string): boolean;
static setContext(window: Window): void;
static getInstance(): Cache;
static attachInstance(cache: Cache): void;
static detachInstance(): void;
}

@@ -23,6 +16,6 @@ export interface ResourceOptions {

export declare class Cache {
private readonly context;
private readonly _options;
private readonly _cache;
private readonly _options;
private readonly id;
constructor(id: string, options: ResourceOptions);
constructor(context: Context, _options: ResourceOptions);
addImage(src: string): Promise<void>;

@@ -29,0 +22,0 @@ match(src: string): Promise<any>;

@@ -15,7 +15,5 @@ export interface LoggerOptions {

getTime(): number;
static create(options: LoggerOptions): void;
static destroy(id: string): void;
static getInstance(id: string): Logger;
info(...args: unknown[]): void;
warn(...args: unknown[]): void;
error(...args: unknown[]): void;
}

@@ -44,2 +44,3 @@ import { backgroundClip } from './property-descriptors/background-clip';

import { webkitTextStrokeWidth } from './property-descriptors/webkit-text-stroke-width';
import { Context } from '../core/context';
export declare class CSSParsedDeclaration {

@@ -110,3 +111,3 @@ backgroundClip: ReturnType<typeof backgroundClip.parse>;

zIndex: ReturnType<typeof zIndex.parse>;
constructor(declaration: CSSStyleDeclaration);
constructor(context: Context, declaration: CSSStyleDeclaration);
isVisible(): boolean;

@@ -123,3 +124,3 @@ isTransparent(): boolean;

quotes: ReturnType<typeof quotes.parse>;
constructor(declaration: CSSStyleDeclaration);
constructor(context: Context, declaration: CSSStyleDeclaration);
}

@@ -129,3 +130,3 @@ export declare class CSSParsedCounterDeclaration {

counterReset: ReturnType<typeof counterReset.parse>;
constructor(declaration: CSSStyleDeclaration);
constructor(context: Context, declaration: CSSStyleDeclaration);
}
import { CSSValue } from './syntax/parser';
import { CSSTypes } from './types/index';
import { Context } from '../core/context';
export declare enum PropertyDescriptorParsingType {

@@ -18,3 +19,3 @@ VALUE = 0,

type: PropertyDescriptorParsingType.IDENT_VALUE;
parse: (token: string) => T;
parse: (context: Context, token: string) => T;
}

@@ -27,7 +28,7 @@ export interface IPropertyTypeValueDescriptor extends IPropertyDescriptor {

type: PropertyDescriptorParsingType.VALUE;
parse: (token: CSSValue) => T;
parse: (context: Context, token: CSSValue) => T;
}
export interface IPropertyListDescriptor<T> extends IPropertyDescriptor {
type: PropertyDescriptorParsingType.LIST;
parse: (tokens: CSSValue[]) => T;
parse: (context: Context, tokens: CSSValue[]) => T;
}

@@ -34,0 +35,0 @@ export interface IPropertyTokenValueDescriptor extends IPropertyDescriptor {

import { CSSValue } from './syntax/parser';
import { Context } from '../core/context';
export interface ITypeDescriptor<T> {
name: string;
parse: (value: CSSValue) => T;
parse: (context: Context, value: CSSValue) => T;
}

@@ -0,11 +1,12 @@

import { Context } from '../../core/context';
export declare class Bounds {
readonly left: number;
readonly top: number;
readonly left: number;
readonly width: number;
readonly height: number;
constructor(x: number, y: number, w: number, h: number);
constructor(left: number, top: number, width: number, height: number);
add(x: number, y: number, w: number, h: number): Bounds;
static fromClientRect(clientRect: ClientRect): Bounds;
static fromClientRect(context: Context, clientRect: ClientRect): Bounds;
}
export declare const parseBounds: (node: Element) => Bounds;
export declare const parseBounds: (context: Context, node: Element) => Bounds;
export declare const parseDocumentSize: (document: Document) => Bounds;
import { CSSParsedDeclaration } from '../index';
import { Bounds } from './bounds';
import { Context } from '../../core/context';
export declare class TextBounds {

@@ -8,2 +9,2 @@ readonly text: string;

}
export declare const parseTextBounds: (value: string, styles: CSSParsedDeclaration, node: Text) => TextBounds[];
export declare const parseTextBounds: (context: Context, value: string, styles: CSSParsedDeclaration, node: Text) => TextBounds[];
import { ITypeDescriptor } from '../ITypeDescriptor';
import { Context } from '../../core/context';
export declare type Color = number;

@@ -7,4 +8,5 @@ export declare const color: ITypeDescriptor<Color>;

export declare const pack: (r: number, g: number, b: number, a: number) => Color;
export declare const parseColor: (context: Context, value: string) => Color;
export declare const COLORS: {
[key: string]: Color;
};
import { CSSValue } from '../../syntax/parser';
import { CSSLinearGradientImage } from '../image';
export declare const prefixLinearGradient: (tokens: CSSValue[]) => CSSLinearGradientImage;
import { Context } from '../../../core/context';
export declare const prefixLinearGradient: (context: Context, tokens: CSSValue[]) => CSSLinearGradientImage;
import { CSSValue } from '../../syntax/parser';
import { CSSRadialGradientImage } from '../image';
export declare const prefixRadialGradient: (tokens: CSSValue[]) => CSSRadialGradientImage;
import { Context } from '../../../core/context';
export declare const prefixRadialGradient: (context: Context, tokens: CSSValue[]) => CSSRadialGradientImage;
import { CSSValue } from '../../syntax/parser';
import { CSSLinearGradientImage, CSSRadialGradientImage } from '../image';
export declare const webkitGradient: (tokens: CSSValue[]) => CSSLinearGradientImage | CSSRadialGradientImage;
import { Context } from '../../../core/context';
export declare const webkitGradient: (context: Context, tokens: CSSValue[]) => CSSLinearGradientImage | CSSRadialGradientImage;
import { CSSValue } from '../../syntax/parser';
import { CSSRadialGradientImage, GradientColorStop, GradientCorner, UnprocessedGradientColorStop } from '../image';
export declare const parseColorStop: (args: CSSValue[]) => UnprocessedGradientColorStop;
import { Context } from '../../../core/context';
export declare const parseColorStop: (context: Context, args: CSSValue[]) => UnprocessedGradientColorStop;
export declare const processColorStops: (stops: UnprocessedGradientColorStop[], lineLength: number) => GradientColorStop[];
export declare const calculateGradientDirection: (angle: number | GradientCorner, width: number, height: number) => [number, number, number, number, number];
export declare const calculateRadius: (gradient: CSSRadialGradientImage, x: number, y: number, width: number, height: number) => [number, number];
import { CSSValue } from '../../syntax/parser';
import { CSSLinearGradientImage } from '../image';
export declare const linearGradient: (tokens: CSSValue[]) => CSSLinearGradientImage;
import { Context } from '../../../core/context';
export declare const linearGradient: (context: Context, tokens: CSSValue[]) => CSSLinearGradientImage;
import { CSSValue } from '../../syntax/parser';
import { CSSRadialGradientImage } from '../image';
import { Context } from '../../../core/context';
export declare const CLOSEST_SIDE = "closest-side";

@@ -11,2 +12,2 @@ export declare const FARTHEST_SIDE = "farthest-side";

export declare const CONTAIN = "contain";
export declare const radialGradient: (tokens: CSSValue[]) => CSSRadialGradientImage;
export declare const radialGradient: (context: Context, tokens: CSSValue[]) => CSSRadialGradientImage;
import { Bounds } from '../css/layout/bounds';
import { Context } from '../core/context';
export interface CloneOptions {
id: string;
ignoreElements?: (element: Element) => boolean;
onclone?: (document: Document, element: HTMLElement) => void;
}
export interface WindowOptions {
scrollX: number;
scrollY: number;
windowWidth: number;
windowHeight: number;
}
export declare type CloneConfigurations = CloneOptions & {

@@ -12,4 +18,5 @@ inlineImages: boolean;

export declare class DocumentCloner {
private readonly context;
private readonly options;
private readonly scrolledElements;
private readonly options;
private readonly referenceElement;

@@ -20,3 +27,3 @@ clonedReferenceElement?: HTMLElement;

private quoteDepth;
constructor(element: HTMLElement, options: CloneConfigurations);
constructor(context: Context, element: HTMLElement, options: CloneConfigurations);
toIFrame(ownerDocument: Document, windowSize: Bounds): Promise<HTMLIFrameElement>;

@@ -23,0 +30,0 @@ createElementClone<T extends HTMLElement | SVGElement>(node: T): HTMLElement | SVGElement;

import { CSSParsedDeclaration } from '../css/index';
import { TextContainer } from './text-container';
import { Bounds } from '../css/layout/bounds';
import { Context } from '../core/context';
export declare const enum FLAGS {

@@ -10,2 +11,3 @@ CREATES_STACKING_CONTEXT = 2,

export declare class ElementContainer {
protected readonly context: Context;
readonly styles: CSSParsedDeclaration;

@@ -16,3 +18,3 @@ readonly textNodes: TextContainer[];

flags: number;
constructor(element: Element);
constructor(context: Context, element: Element);
}
import { ElementContainer } from '../element-container';
import { Context } from '../../core/context';
export declare class LIElementContainer extends ElementContainer {
readonly value: number;
constructor(element: HTMLLIElement);
constructor(context: Context, element: HTMLLIElement);
}
import { ElementContainer } from '../element-container';
import { Context } from '../../core/context';
export declare class OLElementContainer extends ElementContainer {
readonly start: number;
readonly reversed: boolean;
constructor(element: HTMLOListElement);
constructor(context: Context, element: HTMLOListElement);
}
import { ElementContainer } from '../element-container';
import { Context } from '../../core/context';
export declare class SelectElementContainer extends ElementContainer {
readonly value: string;
constructor(element: HTMLSelectElement);
constructor(context: Context, element: HTMLSelectElement);
}
import { ElementContainer } from '../element-container';
import { Context } from '../../core/context';
export declare class TextareaElementContainer extends ElementContainer {
readonly value: string;
constructor(element: HTMLTextAreaElement);
constructor(context: Context, element: HTMLTextAreaElement);
}
import { ElementContainer } from './element-container';
export declare const parseTree: (element: HTMLElement) => ElementContainer;
import { Context } from '../core/context';
export declare const parseTree: (context: Context, element: HTMLElement) => ElementContainer;
export declare const isTextNode: (node: Node) => node is Text;

@@ -4,0 +5,0 @@ export declare const isElementNode: (node: Node) => node is Element;

import { ElementContainer } from '../element-container';
import { Context } from '../../core/context';
export declare class CanvasElementContainer extends ElementContainer {

@@ -6,3 +7,3 @@ canvas: HTMLCanvasElement;

intrinsicHeight: number;
constructor(canvas: HTMLCanvasElement);
constructor(context: Context, canvas: HTMLCanvasElement);
}
import { ElementContainer } from '../element-container';
import { Color } from '../../css/types/color';
import { Context } from '../../core/context';
export declare class IFrameElementContainer extends ElementContainer {

@@ -9,3 +10,3 @@ src: string;

backgroundColor: Color;
constructor(iframe: HTMLIFrameElement);
constructor(context: Context, iframe: HTMLIFrameElement);
}
import { ElementContainer } from '../element-container';
import { Context } from '../../core/context';
export declare class ImageElementContainer extends ElementContainer {

@@ -6,3 +7,3 @@ src: string;

intrinsicHeight: number;
constructor(img: HTMLImageElement);
constructor(context: Context, img: HTMLImageElement);
}
import { ElementContainer } from '../element-container';
import { Context } from '../../core/context';
export declare const CHECKBOX = "checkbox";

@@ -10,3 +11,3 @@ export declare const RADIO = "radio";

readonly value: string;
constructor(input: HTMLInputElement);
constructor(context: Context, input: HTMLInputElement);
}
import { ElementContainer } from '../element-container';
import { Context } from '../../core/context';
export declare class SVGElementContainer extends ElementContainer {

@@ -6,3 +7,3 @@ svg: string;

intrinsicHeight: number;
constructor(img: SVGSVGElement);
constructor(context: Context, img: SVGSVGElement);
}
import { CSSParsedDeclaration } from '../css/index';
import { TextBounds } from '../css/layout/text';
import { Context } from '../core/context';
export declare class TextContainer {
text: string;
textBounds: TextBounds[];
constructor(node: Text, styles: CSSParsedDeclaration);
constructor(context: Context, node: Text, styles: CSSParsedDeclaration);
}

@@ -1,8 +0,7 @@

import { CloneOptions } from './dom/document-cloner';
import { ResourceOptions } from './core/cache-storage';
import { CloneOptions, WindowOptions } from './dom/document-cloner';
import { RenderOptions } from './render/canvas/canvas-renderer';
export declare type Options = CloneOptions & RenderOptions & ResourceOptions & {
import { ContextOptions } from './core/context';
export declare type Options = CloneOptions & WindowOptions & RenderOptions & ContextOptions & {
backgroundColor: string | null;
foreignObjectRendering: boolean;
logging: boolean;
removeContainer?: boolean;

@@ -9,0 +8,0 @@ };

@@ -9,6 +9,7 @@ import { ElementPaint, StackingContext } from '../stacking-context';

import { BoundCurves } from '../bound-curves';
import { Cache } from '../../core/cache-storage';
import { TextBounds } from '../../css/layout/text';
import { ReplacedElementContainer } from '../../dom/replaced-elements/index';
import { EffectTarget, IElementEffect } from '../effects';
import { Renderer } from '../renderer';
import { Context } from '../../core/context';
export declare type RenderConfigurations = RenderOptions & {

@@ -18,3 +19,2 @@ backgroundColor: Color | null;

export interface RenderOptions {
id: string;
scale: number;

@@ -24,17 +24,11 @@ canvas?: HTMLCanvasElement;

y: number;
scrollX: number;
scrollY: number;
width: number;
height: number;
windowWidth: number;
windowHeight: number;
cache: Cache;
}
export declare class CanvasRenderer {
export declare class CanvasRenderer extends Renderer {
canvas: HTMLCanvasElement;
ctx: CanvasRenderingContext2D;
options: RenderConfigurations;
private readonly _activeEffects;
private readonly fontMetrics;
constructor(options: RenderConfigurations);
constructor(context: Context, options: RenderConfigurations);
applyEffects(effects: IElementEffect[], target: EffectTarget): void;

@@ -41,0 +35,0 @@ applyEffect(effect: IElementEffect): void;

import { RenderConfigurations } from './canvas-renderer';
export declare class ForeignObjectRenderer {
import { Renderer } from '../renderer';
import { Context } from '../../core/context';
export declare class ForeignObjectRenderer extends Renderer {
canvas: HTMLCanvasElement;
ctx: CanvasRenderingContext2D;
options: RenderConfigurations;
constructor(options: RenderConfigurations);
constructor(context: Context, options: RenderConfigurations);
render(element: HTMLElement): Promise<HTMLCanvasElement>;
}
export declare const loadSerializedSVG: (svg: Node) => Promise<HTMLImageElement>;

@@ -9,3 +9,3 @@ {

"browser": "dist/html2canvas.js",
"version": "1.1.5",
"version": "1.2.0",
"author": {

@@ -122,4 +122,4 @@ "name": "Niklas von Hertzen",

"dependencies": {
"css-line-break": "2.0.0"
"css-line-break": "2.0.1"
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc