UNPKG

1.2 kBPlain TextView Raw
1import {ApplicationFallbackOptions} from '../static';
2import {OutputOptions} from './options';
3import {PathReference} from '../filesystem/contracts';
4import {Snapshot} from '../snapshot/snapshot';
5
6import {createModernWindow} from '../runtime/browser-emulation/create';
7import {inlineStylesheets} from './stylesheets';
8import {inlineVectorGraphics} from './svg';
9
10export const transformInplace = <V>(path: PathReference, snapshot: Snapshot<V>, options: OutputOptions): void => {
11 if (options.inlineStylesheets || options.inlineVectorGraphics) {
12 const uri = ApplicationFallbackOptions.fallbackUri;
13
14 const window = createModernWindow(snapshot.renderedDocument, uri);
15
16 try {
17 if (options.inlineStylesheets) {
18 inlineStylesheets(path, window.document);
19 }
20
21 if (options.inlineVectorGraphics) {
22 inlineVectorGraphics(window.document);
23 }
24
25 snapshot.renderedDocument = window.document.documentElement.outerHTML;
26 }
27 finally {
28 window.close();
29 }
30 }
31
32 if (/^<\!DOCTYPE html>/i.test(snapshot.renderedDocument) === false) { // ensure result has a doctype
33 snapshot.renderedDocument = `<!DOCTYPE html>${snapshot.renderedDocument}`;
34 }
35};
\No newline at end of file