1 | import {ApplicationFallbackOptions} from '../static';
|
2 | import {OutputOptions} from './options';
|
3 | import {PathReference} from '../filesystem/contracts';
|
4 | import {Snapshot} from '../snapshot/snapshot';
|
5 |
|
6 | import {createModernWindow} from '../runtime/browser-emulation/create';
|
7 | import {inlineStylesheets} from './stylesheets';
|
8 | import {inlineVectorGraphics} from './svg';
|
9 |
|
10 | export 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) {
|
33 | snapshot.renderedDocument = `<!DOCTYPE html>${snapshot.renderedDocument}`;
|
34 | }
|
35 | }; |
\ | No newline at end of file |