UNPKG

html2canvas-pro

Version:

Screenshots with JavaScript. Next generation!

113 lines 4.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const assert_1 = require("assert"); const dom_normalizer_1 = require("../dom-normalizer"); const css_1 = require("../../css"); const context_1 = require("../../core/context"); const bounds_1 = require("../../css/layout/bounds"); const config_1 = require("../../config"); describe('DOMNormalizer', () => { let context; let mockElement; beforeEach(() => { const mockWindow = { document: { createElement: (_name) => { let _href = ''; return { set href(value) { _href = value; }, get href() { return _href; }, get protocol() { return 'http:'; }, get hostname() { return 'localhost'; }, get port() { return ''; } }; } }, location: { href: 'http://localhost/' }, getComputedStyle: () => ({ animationDuration: '1s', transform: 'rotate(45deg)', rotate: '45deg' }) }; const config = new config_1.Html2CanvasConfig({ window: mockWindow }); context = new context_1.Context({ logging: false, imageTimeout: 15000, useCORS: false, allowTaint: false }, new bounds_1.Bounds(0, 0, 800, 600), config); // Create a mock HTMLElement with style property mockElement = { nodeType: 1, // Node.ELEMENT_NODE tagName: 'DIV', style: { animationDuration: '1s', transform: 'rotate(45deg)', rotate: '45deg' } }; }); it('should disable animations on element', () => { const styles = new css_1.CSSParsedDeclaration(context, { animationDuration: '1s', transform: null, rotate: null }); dom_normalizer_1.DOMNormalizer.normalizeElement(mockElement, styles); (0, assert_1.strictEqual)(mockElement.style.animationDuration, '0s'); }); it('should replace transform with identity translate (preserves containing block, Issue #101)', () => { const styles = new css_1.CSSParsedDeclaration(context, { animationDuration: '0s', transform: 'rotate(45deg)', rotate: null }); dom_normalizer_1.DOMNormalizer.normalizeElement(mockElement, styles); (0, assert_1.strictEqual)(mockElement.style.transform, 'translate(0, 0)'); }); it('should replace rotate with 0deg (preserves containing block, Issue #101)', () => { const styles = new css_1.CSSParsedDeclaration(context, { animationDuration: '0s', transform: null, rotate: '45deg' }); dom_normalizer_1.DOMNormalizer.normalizeElement(mockElement, styles); (0, assert_1.strictEqual)(mockElement.style.rotate, '0deg'); }); it('should normalize all properties when all are set', () => { const styles = new css_1.CSSParsedDeclaration(context, { animationDuration: '2s', transform: 'rotate(90deg)', rotate: '90deg' }); dom_normalizer_1.DOMNormalizer.normalizeElement(mockElement, styles); (0, assert_1.strictEqual)(mockElement.style.animationDuration, '0s'); (0, assert_1.strictEqual)(mockElement.style.transform, 'translate(0, 0)'); (0, assert_1.strictEqual)(mockElement.style.rotate, '0deg'); }); it('should not modify element if it is not an HTMLElement', () => { const svgElement = { nodeType: 1, tagName: 'svg' }; const styles = new css_1.CSSParsedDeclaration(context, { animationDuration: '1s', transform: 'rotate(45deg)', rotate: '45deg' }); // Should not throw and should not try to access style dom_normalizer_1.DOMNormalizer.normalizeElement(svgElement, styles); }); }); //# sourceMappingURL=dom-normalizer.test.js.map