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
This commit is contained in:
Niklas von Hertzen 2019-09-27 06:42:13 -07:00 committed by GitHub
parent 076492042a
commit 3f599103fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 11 deletions

View File

@ -30,17 +30,20 @@ export class CounterState {
parse(style: CSSParsedCounterDeclaration): string[] { parse(style: CSSParsedCounterDeclaration): string[] {
const counterIncrement = style.counterIncrement; const counterIncrement = style.counterIncrement;
const counterReset = style.counterReset; const counterReset = style.counterReset;
let canReset = true;
if (counterIncrement !== null) { if (counterIncrement !== null) {
counterIncrement.forEach(entry => { counterIncrement.forEach(entry => {
const counter = this.counters[entry.counter]; const counter = this.counters[entry.counter];
if (counter) { if (counter && entry.increment !== 0) {
canReset = false;
counter[Math.max(0, counter.length - 1)] += entry.increment; counter[Math.max(0, counter.length - 1)] += entry.increment;
} }
}); });
} }
const counterNames: string[] = []; const counterNames: string[] = [];
if (canReset) {
counterReset.forEach(entry => { counterReset.forEach(entry => {
let counter = this.counters[entry.counter]; let counter = this.counters[entry.counter];
counterNames.push(entry.counter); counterNames.push(entry.counter);
@ -49,6 +52,7 @@ export class CounterState {
} }
counter.push(entry.reset); counter.push(entry.reset);
}); });
}
return counterNames; return counterNames;
} }

View File

@ -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 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); this.scrolledElements.forEach(restoreNodeScroll);
if (cloneWindow) { if (cloneWindow) {
cloneWindow.scrollTo(windowSize.left, windowSize.top); 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`); 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') { if (typeof onclone === 'function') {
return Promise.resolve() return Promise.resolve()
.then(() => onclone(documentClone)) .then(() => onclone(documentClone))
@ -398,7 +402,8 @@ export class DocumentCloner {
); );
break; break;
default: default:
// console.log('ident', token, declaration); // safari doesn't parse string tokens correctly because of lack of quotes
anonymousReplacedElement.appendChild(document.createTextNode(token.value));
} }
} }
}); });

4
src/global.d.ts vendored
View File

@ -7,3 +7,7 @@ interface CSSStyleDeclaration {
interface DocumentType extends Node, ChildNode { interface DocumentType extends Node, ChildNode {
readonly internalSubset: string | null; readonly internalSubset: string | null;
} }
interface Document {
fonts: any;
}