diff --git a/src/Font.js b/src/Font.js index 595adac..cd32f25 100644 --- a/src/Font.js +++ b/src/Font.js @@ -4,8 +4,7 @@ import type {Font} from './parsing/font'; const SAMPLE_TEXT = 'Hidden Text'; -const SMALL_IMAGE = - 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; +import {SMALL_IMAGE} from './Util'; export class FontMetrics { _data: {}; diff --git a/src/NodeParser.js b/src/NodeParser.js index 98c1665..661ce2b 100644 --- a/src/NodeParser.js +++ b/src/NodeParser.js @@ -46,6 +46,10 @@ const parseNodeTree = ( imageLoader: ImageLoader, index: number ): void => { + if (__DEV__ && index > 50000) { + throw new Error(`Recursion error while parsing node tree`); + } + for (let childNode = node.firstChild, nextNode; childNode; childNode = nextNode) { nextNode = childNode.nextSibling; const defaultView = childNode.ownerDocument.defaultView; diff --git a/src/Util.js b/src/Util.js index 4dac94d..217a2a1 100644 --- a/src/Util.js +++ b/src/Util.js @@ -4,13 +4,15 @@ export const contains = (bit: number, value: number): boolean => (bit & value) !== 0; export const copyCSSStyles = (style: CSSStyleDeclaration, target: HTMLElement): void => { - if (style.cssText) { - target.style.cssText = style.cssText; - } else { - // Edge does not provide value for cssText - for (let i = style.length - 1; i >= 0; i--) { - const property = style.item(i); + // Edge does not provide value for cssText + for (let i = style.length - 1; i >= 0; i--) { + const property = style.item(i); + // Safari shows pseudoelements if content is set + if (property !== 'content') { target.style.setProperty(property, style.getPropertyValue(property)); } } }; + +export const SMALL_IMAGE = + 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';