From 3f599103fb139f218ffe917800e74af2c7cc7ad5 Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Fri, 27 Sep 2019 06:42:13 -0700 Subject: [PATCH] fix: safari pseudo element content parsing (#2018) * fix: await for fonts to be ready in document clone * fix: safari pseudo element content parsing * fix: safari counter-increment / counter-reset --- src/css/types/functions/counter.ts | 22 +++++++++++++--------- src/dom/document-cloner.ts | 9 +++++++-- src/global.d.ts | 4 ++++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/css/types/functions/counter.ts b/src/css/types/functions/counter.ts index e8e1601..062d84e 100644 --- a/src/css/types/functions/counter.ts +++ b/src/css/types/functions/counter.ts @@ -30,25 +30,29 @@ export class CounterState { parse(style: CSSParsedCounterDeclaration): string[] { const counterIncrement = style.counterIncrement; const counterReset = style.counterReset; + let canReset = true; if (counterIncrement !== null) { counterIncrement.forEach(entry => { const counter = this.counters[entry.counter]; - if (counter) { + if (counter && entry.increment !== 0) { + canReset = false; counter[Math.max(0, counter.length - 1)] += entry.increment; } }); } const counterNames: string[] = []; - counterReset.forEach(entry => { - let counter = this.counters[entry.counter]; - counterNames.push(entry.counter); - if (!counter) { - counter = this.counters[entry.counter] = []; - } - counter.push(entry.reset); - }); + if (canReset) { + counterReset.forEach(entry => { + let counter = this.counters[entry.counter]; + counterNames.push(entry.counter); + if (!counter) { + counter = this.counters[entry.counter] = []; + } + counter.push(entry.reset); + }); + } return counterNames; } diff --git a/src/dom/document-cloner.ts b/src/dom/document-cloner.ts index 54e7ba4..ae1c4cf 100644 --- a/src/dom/document-cloner.ts +++ b/src/dom/document-cloner.ts @@ -71,7 +71,7 @@ export class DocumentCloner { if window url is about:blank, we can assign the url to current by writing onto the document */ - const iframeLoad = iframeLoader(iframe).then(() => { + const iframeLoad = iframeLoader(iframe).then(async () => { this.scrolledElements.forEach(restoreNodeScroll); if (cloneWindow) { cloneWindow.scrollTo(windowSize.left, windowSize.top); @@ -91,6 +91,10 @@ export class DocumentCloner { return Promise.reject(`Error finding the ${this.referenceElement.nodeName} in the cloned document`); } + if (documentClone.fonts && documentClone.fonts.ready) { + await documentClone.fonts.ready; + } + if (typeof onclone === 'function') { return Promise.resolve() .then(() => onclone(documentClone)) @@ -398,7 +402,8 @@ export class DocumentCloner { ); break; default: - // console.log('ident', token, declaration); + // safari doesn't parse string tokens correctly because of lack of quotes + anonymousReplacedElement.appendChild(document.createTextNode(token.value)); } } }); diff --git a/src/global.d.ts b/src/global.d.ts index 90096c4..a94aa96 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -7,3 +7,7 @@ interface CSSStyleDeclaration { interface DocumentType extends Node, ChildNode { readonly internalSubset: string | null; } + +interface Document { + fonts: any; +}