1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
16 | return new (P || (P = Promise))(function (resolve, reject) {
|
17 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
18 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
19 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
20 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
21 | });
|
22 | };
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | const dom5 = require("dom5/lib/index-next");
|
25 | const parse5_1 = require("parse5");
|
26 | const model_1 = require("../model/model");
|
27 | const p = dom5.predicates;
|
28 | const isStyleElement = p.AND(p.hasTagName('style'), p.OR(p.NOT(p.hasAttr('type')), p.hasAttrValue('type', 'text/css')));
|
29 | const isStyleLink = p.AND(p.hasTagName('link'), p.hasSpaceSeparatedAttrValue('rel', 'stylesheet'), p.hasAttr('href'));
|
30 | const isStyleNode = p.OR(isStyleElement, isStyleLink);
|
31 | class HtmlStyleScanner {
|
32 | scan(document, visit) {
|
33 | return __awaiter(this, void 0, void 0, function* () {
|
34 | const features = [];
|
35 | const visitor = (node) => __awaiter(this, void 0, void 0, function* () {
|
36 | if (isStyleNode(node)) {
|
37 | const tagName = node.nodeName;
|
38 | if (tagName === 'link') {
|
39 | const href = dom5.getAttribute(node, 'href');
|
40 | features.push(new model_1.ScannedImport('html-style', href, document.sourceRangeForNode(node), document.sourceRangeForAttributeValue(node, 'href'), { language: 'html', node, containingDocument: document }, true));
|
41 | }
|
42 | else {
|
43 | const contents = dom5.getTextContent(node);
|
44 | const locationOffset = model_1.getLocationOffsetOfStartOfTextContent(node, document);
|
45 | const commentText = model_1.getAttachedCommentText(node) || '';
|
46 | features.push(new model_1.ScannedInlineDocument('css', contents, locationOffset, commentText, document.sourceRangeForNode(node), { language: 'html', node, containingDocument: document }));
|
47 | }
|
48 | }
|
49 |
|
50 | if (node.tagName === 'template') {
|
51 | const content = parse5_1.treeAdapters.default.getTemplateContent(node);
|
52 | if (content) {
|
53 | for (const n of dom5.depthFirst(content)) {
|
54 | visitor(n);
|
55 | }
|
56 | }
|
57 | }
|
58 | });
|
59 | yield visit(visitor);
|
60 | return { features };
|
61 | });
|
62 | }
|
63 | }
|
64 | exports.HtmlStyleScanner = HtmlStyleScanner;
|
65 |
|
\ | No newline at end of file |