1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
---|
10 | if (k2 === undefined) k2 = k;
|
---|
11 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
---|
12 | }) : (function(o, m, k, k2) {
|
---|
13 | if (k2 === undefined) k2 = k;
|
---|
14 | o[k2] = m[k];
|
---|
15 | }));
|
---|
16 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
---|
17 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
---|
18 | }) : function(o, v) {
|
---|
19 | o["default"] = v;
|
---|
20 | });
|
---|
21 | var __importStar = (this && this.__importStar) || function (mod) {
|
---|
22 | if (mod && mod.__esModule) return mod;
|
---|
23 | var result = {};
|
---|
24 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
---|
25 | __setModuleDefault(result, mod);
|
---|
26 | return result;
|
---|
27 | };
|
---|
28 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
29 | exports.htmlRewritingStream = void 0;
|
---|
30 | const stream_1 = require("stream");
|
---|
31 | async function htmlRewritingStream(content) {
|
---|
32 | const chunks = [];
|
---|
33 | const rewriter = new (await Promise.resolve().then(() => __importStar(require('parse5-html-rewriting-stream')))).default();
|
---|
34 | return {
|
---|
35 | rewriter,
|
---|
36 | transformedContent: new Promise((resolve) => {
|
---|
37 | new stream_1.Readable({
|
---|
38 | encoding: 'utf8',
|
---|
39 | read() {
|
---|
40 | this.push(Buffer.from(content));
|
---|
41 | this.push(null);
|
---|
42 | },
|
---|
43 | })
|
---|
44 | .pipe(rewriter)
|
---|
45 | .pipe(new stream_1.Writable({
|
---|
46 | write(chunk, encoding, callback) {
|
---|
47 | chunks.push(typeof chunk === 'string' ? Buffer.from(chunk, encoding) : chunk);
|
---|
48 | callback();
|
---|
49 | },
|
---|
50 | final(callback) {
|
---|
51 | callback();
|
---|
52 | resolve(Buffer.concat(chunks).toString());
|
---|
53 | },
|
---|
54 | }));
|
---|
55 | }),
|
---|
56 | };
|
---|
57 | }
|
---|
58 | exports.htmlRewritingStream = htmlRewritingStream;
|
---|