parse5 7.3.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/tokenizer/index.js +3 -1
  2. package/package.json +13 -10
  3. package/dist/cjs/common/doctype.d.ts +0 -4
  4. package/dist/cjs/common/doctype.js +0 -118
  5. package/dist/cjs/common/error-codes.d.ts +0 -67
  6. package/dist/cjs/common/error-codes.js +0 -66
  7. package/dist/cjs/common/foreign-content.d.ts +0 -9
  8. package/dist/cjs/common/foreign-content.js +0 -237
  9. package/dist/cjs/common/html.d.ts +0 -289
  10. package/dist/cjs/common/html.js +0 -528
  11. package/dist/cjs/common/token.d.ts +0 -84
  12. package/dist/cjs/common/token.js +0 -24
  13. package/dist/cjs/common/unicode.d.ts +0 -42
  14. package/dist/cjs/common/unicode.js +0 -70
  15. package/dist/cjs/index.d.ts +0 -71
  16. package/dist/cjs/index.js +0 -54
  17. package/dist/cjs/package.json +0 -1
  18. package/dist/cjs/parser/formatting-element-list.d.ts +0 -36
  19. package/dist/cjs/parser/formatting-element-list.js +0 -114
  20. package/dist/cjs/parser/index.d.ts +0 -221
  21. package/dist/cjs/parser/index.js +0 -3240
  22. package/dist/cjs/parser/open-element-stack.d.ts +0 -53
  23. package/dist/cjs/parser/open-element-stack.js +0 -328
  24. package/dist/cjs/serializer/index.d.ts +0 -60
  25. package/dist/cjs/serializer/index.js +0 -172
  26. package/dist/cjs/tokenizer/index.d.ts +0 -247
  27. package/dist/cjs/tokenizer/index.js +0 -2714
  28. package/dist/cjs/tokenizer/preprocessor.d.ts +0 -36
  29. package/dist/cjs/tokenizer/preprocessor.js +0 -200
  30. package/dist/cjs/tree-adapters/default.d.ts +0 -84
  31. package/dist/cjs/tree-adapters/default.js +0 -176
  32. package/dist/cjs/tree-adapters/interface.d.ts +0 -255
  33. package/dist/cjs/tree-adapters/interface.js +0 -2
@@ -459,7 +459,9 @@ export class Tokenizer {
459
459
  : cp === $.NULL
460
460
  ? TokenType.NULL_CHARACTER
461
461
  : TokenType.CHARACTER;
462
- this._appendCharToCurrentCharacterToken(type, String.fromCodePoint(cp));
462
+ // OPTIMIZATION: Use String.fromCharCode for BMP characters (< 0x10000) which is faster
463
+ // than String.fromCodePoint. Characters outside BMP are rare in HTML.
464
+ this._appendCharToCurrentCharacterToken(type, cp < 65536 ? String.fromCharCode(cp) : String.fromCodePoint(cp));
463
465
  }
464
466
  //NOTE: used when we emit characters explicitly.
465
467
  //This is always for non-whitespace and non-null characters, which allows us to avoid additional checks.
package/package.json CHANGED
@@ -2,13 +2,18 @@
2
2
  "name": "parse5",
3
3
  "type": "module",
4
4
  "description": "HTML parser and serializer.",
5
- "version": "7.3.0",
5
+ "version": "8.0.1",
6
6
  "author": "Ivan Nikulin <ifaaan@gmail.com> (https://github.com/inikulin)",
7
- "contributors": "https://github.com/inikulin/parse5/graphs/contributors",
7
+ "contributors": [
8
+ "James Garbutt (https://github.com/43081j)",
9
+ "Felix Boehm (https://github.com/fb55)",
10
+ "Ivan Nikulin (https://github.com/inikulin)",
11
+ "Titus (https://github.com/wooorm)"
12
+ ],
8
13
  "homepage": "https://parse5.js.org",
9
14
  "funding": "https://github.com/inikulin/parse5?sponsor=1",
10
15
  "dependencies": {
11
- "entities": "^6.0.0"
16
+ "entities": "^8.0.0"
12
17
  },
13
18
  "keywords": [
14
19
  "html",
@@ -28,22 +33,20 @@
28
33
  "serialize"
29
34
  ],
30
35
  "license": "MIT",
31
- "main": "dist/cjs/index.js",
36
+ "main": "dist/index.js",
32
37
  "module": "dist/index.js",
33
38
  "types": "dist/index.d.ts",
34
39
  "exports": {
35
- "import": "./dist/index.js",
36
- "require": "./dist/cjs/index.js"
37
- },
38
- "scripts": {
39
- "build:cjs": "tsc --noCheck --moduleResolution node10 --module CommonJS --target ES6 --outDir dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json"
40
+ ".": {
41
+ "default": "./dist/index.js"
42
+ }
40
43
  },
44
+ "scripts": {},
41
45
  "repository": {
42
46
  "type": "git",
43
47
  "url": "git://github.com/inikulin/parse5.git"
44
48
  },
45
49
  "files": [
46
- "dist/cjs/package.json",
47
50
  "dist/**/*.js",
48
51
  "dist/**/*.d.ts"
49
52
  ]
@@ -1,4 +0,0 @@
1
- import { DOCUMENT_MODE } from './html.js';
2
- import type { DoctypeToken } from './token.js';
3
- export declare function isConforming(token: DoctypeToken): boolean;
4
- export declare function getDocumentMode(token: DoctypeToken): DOCUMENT_MODE;
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isConforming = isConforming;
4
- exports.getDocumentMode = getDocumentMode;
5
- const html_js_1 = require("./html.js");
6
- //Const
7
- const VALID_DOCTYPE_NAME = 'html';
8
- const VALID_SYSTEM_ID = 'about:legacy-compat';
9
- const QUIRKS_MODE_SYSTEM_ID = 'http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd';
10
- const QUIRKS_MODE_PUBLIC_ID_PREFIXES = [
11
- '+//silmaril//dtd html pro v0r11 19970101//',
12
- '-//as//dtd html 3.0 aswedit + extensions//',
13
- '-//advasoft ltd//dtd html 3.0 aswedit + extensions//',
14
- '-//ietf//dtd html 2.0 level 1//',
15
- '-//ietf//dtd html 2.0 level 2//',
16
- '-//ietf//dtd html 2.0 strict level 1//',
17
- '-//ietf//dtd html 2.0 strict level 2//',
18
- '-//ietf//dtd html 2.0 strict//',
19
- '-//ietf//dtd html 2.0//',
20
- '-//ietf//dtd html 2.1e//',
21
- '-//ietf//dtd html 3.0//',
22
- '-//ietf//dtd html 3.2 final//',
23
- '-//ietf//dtd html 3.2//',
24
- '-//ietf//dtd html 3//',
25
- '-//ietf//dtd html level 0//',
26
- '-//ietf//dtd html level 1//',
27
- '-//ietf//dtd html level 2//',
28
- '-//ietf//dtd html level 3//',
29
- '-//ietf//dtd html strict level 0//',
30
- '-//ietf//dtd html strict level 1//',
31
- '-//ietf//dtd html strict level 2//',
32
- '-//ietf//dtd html strict level 3//',
33
- '-//ietf//dtd html strict//',
34
- '-//ietf//dtd html//',
35
- '-//metrius//dtd metrius presentational//',
36
- '-//microsoft//dtd internet explorer 2.0 html strict//',
37
- '-//microsoft//dtd internet explorer 2.0 html//',
38
- '-//microsoft//dtd internet explorer 2.0 tables//',
39
- '-//microsoft//dtd internet explorer 3.0 html strict//',
40
- '-//microsoft//dtd internet explorer 3.0 html//',
41
- '-//microsoft//dtd internet explorer 3.0 tables//',
42
- '-//netscape comm. corp.//dtd html//',
43
- '-//netscape comm. corp.//dtd strict html//',
44
- "-//o'reilly and associates//dtd html 2.0//",
45
- "-//o'reilly and associates//dtd html extended 1.0//",
46
- "-//o'reilly and associates//dtd html extended relaxed 1.0//",
47
- '-//sq//dtd html 2.0 hotmetal + extensions//',
48
- '-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//',
49
- '-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//',
50
- '-//spyglass//dtd html 2.0 extended//',
51
- '-//sun microsystems corp.//dtd hotjava html//',
52
- '-//sun microsystems corp.//dtd hotjava strict html//',
53
- '-//w3c//dtd html 3 1995-03-24//',
54
- '-//w3c//dtd html 3.2 draft//',
55
- '-//w3c//dtd html 3.2 final//',
56
- '-//w3c//dtd html 3.2//',
57
- '-//w3c//dtd html 3.2s draft//',
58
- '-//w3c//dtd html 4.0 frameset//',
59
- '-//w3c//dtd html 4.0 transitional//',
60
- '-//w3c//dtd html experimental 19960712//',
61
- '-//w3c//dtd html experimental 970421//',
62
- '-//w3c//dtd w3 html//',
63
- '-//w3o//dtd w3 html 3.0//',
64
- '-//webtechs//dtd mozilla html 2.0//',
65
- '-//webtechs//dtd mozilla html//',
66
- ];
67
- const QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES = [
68
- ...QUIRKS_MODE_PUBLIC_ID_PREFIXES,
69
- '-//w3c//dtd html 4.01 frameset//',
70
- '-//w3c//dtd html 4.01 transitional//',
71
- ];
72
- const QUIRKS_MODE_PUBLIC_IDS = new Set([
73
- '-//w3o//dtd w3 html strict 3.0//en//',
74
- '-/w3c/dtd html 4.0 transitional/en',
75
- 'html',
76
- ]);
77
- const LIMITED_QUIRKS_PUBLIC_ID_PREFIXES = ['-//w3c//dtd xhtml 1.0 frameset//', '-//w3c//dtd xhtml 1.0 transitional//'];
78
- const LIMITED_QUIRKS_WITH_SYSTEM_ID_PUBLIC_ID_PREFIXES = [
79
- ...LIMITED_QUIRKS_PUBLIC_ID_PREFIXES,
80
- '-//w3c//dtd html 4.01 frameset//',
81
- '-//w3c//dtd html 4.01 transitional//',
82
- ];
83
- //Utils
84
- function hasPrefix(publicId, prefixes) {
85
- return prefixes.some((prefix) => publicId.startsWith(prefix));
86
- }
87
- //API
88
- function isConforming(token) {
89
- return (token.name === VALID_DOCTYPE_NAME &&
90
- token.publicId === null &&
91
- (token.systemId === null || token.systemId === VALID_SYSTEM_ID));
92
- }
93
- function getDocumentMode(token) {
94
- if (token.name !== VALID_DOCTYPE_NAME) {
95
- return html_js_1.DOCUMENT_MODE.QUIRKS;
96
- }
97
- const { systemId } = token;
98
- if (systemId && systemId.toLowerCase() === QUIRKS_MODE_SYSTEM_ID) {
99
- return html_js_1.DOCUMENT_MODE.QUIRKS;
100
- }
101
- let { publicId } = token;
102
- if (publicId !== null) {
103
- publicId = publicId.toLowerCase();
104
- if (QUIRKS_MODE_PUBLIC_IDS.has(publicId)) {
105
- return html_js_1.DOCUMENT_MODE.QUIRKS;
106
- }
107
- let prefixes = systemId === null ? QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES : QUIRKS_MODE_PUBLIC_ID_PREFIXES;
108
- if (hasPrefix(publicId, prefixes)) {
109
- return html_js_1.DOCUMENT_MODE.QUIRKS;
110
- }
111
- prefixes =
112
- systemId === null ? LIMITED_QUIRKS_PUBLIC_ID_PREFIXES : LIMITED_QUIRKS_WITH_SYSTEM_ID_PUBLIC_ID_PREFIXES;
113
- if (hasPrefix(publicId, prefixes)) {
114
- return html_js_1.DOCUMENT_MODE.LIMITED_QUIRKS;
115
- }
116
- }
117
- return html_js_1.DOCUMENT_MODE.NO_QUIRKS;
118
- }
@@ -1,67 +0,0 @@
1
- import type { Location } from './token.js';
2
- export interface ParserError extends Location {
3
- code: ERR;
4
- }
5
- export type ParserErrorHandler = (error: ParserError) => void;
6
- export declare enum ERR {
7
- controlCharacterInInputStream = "control-character-in-input-stream",
8
- noncharacterInInputStream = "noncharacter-in-input-stream",
9
- surrogateInInputStream = "surrogate-in-input-stream",
10
- nonVoidHtmlElementStartTagWithTrailingSolidus = "non-void-html-element-start-tag-with-trailing-solidus",
11
- endTagWithAttributes = "end-tag-with-attributes",
12
- endTagWithTrailingSolidus = "end-tag-with-trailing-solidus",
13
- unexpectedSolidusInTag = "unexpected-solidus-in-tag",
14
- unexpectedNullCharacter = "unexpected-null-character",
15
- unexpectedQuestionMarkInsteadOfTagName = "unexpected-question-mark-instead-of-tag-name",
16
- invalidFirstCharacterOfTagName = "invalid-first-character-of-tag-name",
17
- unexpectedEqualsSignBeforeAttributeName = "unexpected-equals-sign-before-attribute-name",
18
- missingEndTagName = "missing-end-tag-name",
19
- unexpectedCharacterInAttributeName = "unexpected-character-in-attribute-name",
20
- unknownNamedCharacterReference = "unknown-named-character-reference",
21
- missingSemicolonAfterCharacterReference = "missing-semicolon-after-character-reference",
22
- unexpectedCharacterAfterDoctypeSystemIdentifier = "unexpected-character-after-doctype-system-identifier",
23
- unexpectedCharacterInUnquotedAttributeValue = "unexpected-character-in-unquoted-attribute-value",
24
- eofBeforeTagName = "eof-before-tag-name",
25
- eofInTag = "eof-in-tag",
26
- missingAttributeValue = "missing-attribute-value",
27
- missingWhitespaceBetweenAttributes = "missing-whitespace-between-attributes",
28
- missingWhitespaceAfterDoctypePublicKeyword = "missing-whitespace-after-doctype-public-keyword",
29
- missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers = "missing-whitespace-between-doctype-public-and-system-identifiers",
30
- missingWhitespaceAfterDoctypeSystemKeyword = "missing-whitespace-after-doctype-system-keyword",
31
- missingQuoteBeforeDoctypePublicIdentifier = "missing-quote-before-doctype-public-identifier",
32
- missingQuoteBeforeDoctypeSystemIdentifier = "missing-quote-before-doctype-system-identifier",
33
- missingDoctypePublicIdentifier = "missing-doctype-public-identifier",
34
- missingDoctypeSystemIdentifier = "missing-doctype-system-identifier",
35
- abruptDoctypePublicIdentifier = "abrupt-doctype-public-identifier",
36
- abruptDoctypeSystemIdentifier = "abrupt-doctype-system-identifier",
37
- cdataInHtmlContent = "cdata-in-html-content",
38
- incorrectlyOpenedComment = "incorrectly-opened-comment",
39
- eofInScriptHtmlCommentLikeText = "eof-in-script-html-comment-like-text",
40
- eofInDoctype = "eof-in-doctype",
41
- nestedComment = "nested-comment",
42
- abruptClosingOfEmptyComment = "abrupt-closing-of-empty-comment",
43
- eofInComment = "eof-in-comment",
44
- incorrectlyClosedComment = "incorrectly-closed-comment",
45
- eofInCdata = "eof-in-cdata",
46
- absenceOfDigitsInNumericCharacterReference = "absence-of-digits-in-numeric-character-reference",
47
- nullCharacterReference = "null-character-reference",
48
- surrogateCharacterReference = "surrogate-character-reference",
49
- characterReferenceOutsideUnicodeRange = "character-reference-outside-unicode-range",
50
- controlCharacterReference = "control-character-reference",
51
- noncharacterCharacterReference = "noncharacter-character-reference",
52
- missingWhitespaceBeforeDoctypeName = "missing-whitespace-before-doctype-name",
53
- missingDoctypeName = "missing-doctype-name",
54
- invalidCharacterSequenceAfterDoctypeName = "invalid-character-sequence-after-doctype-name",
55
- duplicateAttribute = "duplicate-attribute",
56
- nonConformingDoctype = "non-conforming-doctype",
57
- missingDoctype = "missing-doctype",
58
- misplacedDoctype = "misplaced-doctype",
59
- endTagWithoutMatchingOpenElement = "end-tag-without-matching-open-element",
60
- closingOfElementWithOpenChildElements = "closing-of-element-with-open-child-elements",
61
- disallowedContentInNoscriptInHead = "disallowed-content-in-noscript-in-head",
62
- openElementsLeftAfterEof = "open-elements-left-after-eof",
63
- abandonedHeadElementChild = "abandoned-head-element-child",
64
- misplacedStartTagForHeadElement = "misplaced-start-tag-for-head-element",
65
- nestedNoscriptInHead = "nested-noscript-in-head",
66
- eofInElementThatCanContainOnlyText = "eof-in-element-that-can-contain-only-text"
67
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ERR = void 0;
4
- var ERR;
5
- (function (ERR) {
6
- ERR["controlCharacterInInputStream"] = "control-character-in-input-stream";
7
- ERR["noncharacterInInputStream"] = "noncharacter-in-input-stream";
8
- ERR["surrogateInInputStream"] = "surrogate-in-input-stream";
9
- ERR["nonVoidHtmlElementStartTagWithTrailingSolidus"] = "non-void-html-element-start-tag-with-trailing-solidus";
10
- ERR["endTagWithAttributes"] = "end-tag-with-attributes";
11
- ERR["endTagWithTrailingSolidus"] = "end-tag-with-trailing-solidus";
12
- ERR["unexpectedSolidusInTag"] = "unexpected-solidus-in-tag";
13
- ERR["unexpectedNullCharacter"] = "unexpected-null-character";
14
- ERR["unexpectedQuestionMarkInsteadOfTagName"] = "unexpected-question-mark-instead-of-tag-name";
15
- ERR["invalidFirstCharacterOfTagName"] = "invalid-first-character-of-tag-name";
16
- ERR["unexpectedEqualsSignBeforeAttributeName"] = "unexpected-equals-sign-before-attribute-name";
17
- ERR["missingEndTagName"] = "missing-end-tag-name";
18
- ERR["unexpectedCharacterInAttributeName"] = "unexpected-character-in-attribute-name";
19
- ERR["unknownNamedCharacterReference"] = "unknown-named-character-reference";
20
- ERR["missingSemicolonAfterCharacterReference"] = "missing-semicolon-after-character-reference";
21
- ERR["unexpectedCharacterAfterDoctypeSystemIdentifier"] = "unexpected-character-after-doctype-system-identifier";
22
- ERR["unexpectedCharacterInUnquotedAttributeValue"] = "unexpected-character-in-unquoted-attribute-value";
23
- ERR["eofBeforeTagName"] = "eof-before-tag-name";
24
- ERR["eofInTag"] = "eof-in-tag";
25
- ERR["missingAttributeValue"] = "missing-attribute-value";
26
- ERR["missingWhitespaceBetweenAttributes"] = "missing-whitespace-between-attributes";
27
- ERR["missingWhitespaceAfterDoctypePublicKeyword"] = "missing-whitespace-after-doctype-public-keyword";
28
- ERR["missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers"] = "missing-whitespace-between-doctype-public-and-system-identifiers";
29
- ERR["missingWhitespaceAfterDoctypeSystemKeyword"] = "missing-whitespace-after-doctype-system-keyword";
30
- ERR["missingQuoteBeforeDoctypePublicIdentifier"] = "missing-quote-before-doctype-public-identifier";
31
- ERR["missingQuoteBeforeDoctypeSystemIdentifier"] = "missing-quote-before-doctype-system-identifier";
32
- ERR["missingDoctypePublicIdentifier"] = "missing-doctype-public-identifier";
33
- ERR["missingDoctypeSystemIdentifier"] = "missing-doctype-system-identifier";
34
- ERR["abruptDoctypePublicIdentifier"] = "abrupt-doctype-public-identifier";
35
- ERR["abruptDoctypeSystemIdentifier"] = "abrupt-doctype-system-identifier";
36
- ERR["cdataInHtmlContent"] = "cdata-in-html-content";
37
- ERR["incorrectlyOpenedComment"] = "incorrectly-opened-comment";
38
- ERR["eofInScriptHtmlCommentLikeText"] = "eof-in-script-html-comment-like-text";
39
- ERR["eofInDoctype"] = "eof-in-doctype";
40
- ERR["nestedComment"] = "nested-comment";
41
- ERR["abruptClosingOfEmptyComment"] = "abrupt-closing-of-empty-comment";
42
- ERR["eofInComment"] = "eof-in-comment";
43
- ERR["incorrectlyClosedComment"] = "incorrectly-closed-comment";
44
- ERR["eofInCdata"] = "eof-in-cdata";
45
- ERR["absenceOfDigitsInNumericCharacterReference"] = "absence-of-digits-in-numeric-character-reference";
46
- ERR["nullCharacterReference"] = "null-character-reference";
47
- ERR["surrogateCharacterReference"] = "surrogate-character-reference";
48
- ERR["characterReferenceOutsideUnicodeRange"] = "character-reference-outside-unicode-range";
49
- ERR["controlCharacterReference"] = "control-character-reference";
50
- ERR["noncharacterCharacterReference"] = "noncharacter-character-reference";
51
- ERR["missingWhitespaceBeforeDoctypeName"] = "missing-whitespace-before-doctype-name";
52
- ERR["missingDoctypeName"] = "missing-doctype-name";
53
- ERR["invalidCharacterSequenceAfterDoctypeName"] = "invalid-character-sequence-after-doctype-name";
54
- ERR["duplicateAttribute"] = "duplicate-attribute";
55
- ERR["nonConformingDoctype"] = "non-conforming-doctype";
56
- ERR["missingDoctype"] = "missing-doctype";
57
- ERR["misplacedDoctype"] = "misplaced-doctype";
58
- ERR["endTagWithoutMatchingOpenElement"] = "end-tag-without-matching-open-element";
59
- ERR["closingOfElementWithOpenChildElements"] = "closing-of-element-with-open-child-elements";
60
- ERR["disallowedContentInNoscriptInHead"] = "disallowed-content-in-noscript-in-head";
61
- ERR["openElementsLeftAfterEof"] = "open-elements-left-after-eof";
62
- ERR["abandonedHeadElementChild"] = "abandoned-head-element-child";
63
- ERR["misplacedStartTagForHeadElement"] = "misplaced-start-tag-for-head-element";
64
- ERR["nestedNoscriptInHead"] = "nested-noscript-in-head";
65
- ERR["eofInElementThatCanContainOnlyText"] = "eof-in-element-that-can-contain-only-text";
66
- })(ERR || (exports.ERR = ERR = {}));
@@ -1,9 +0,0 @@
1
- import { TAG_ID as $, NS } from './html.js';
2
- import type { TagToken, Attribute } from './token.js';
3
- export declare const SVG_TAG_NAMES_ADJUSTMENT_MAP: Map<string, string>;
4
- export declare function causesExit(startTagToken: TagToken): boolean;
5
- export declare function adjustTokenMathMLAttrs(token: TagToken): void;
6
- export declare function adjustTokenSVGAttrs(token: TagToken): void;
7
- export declare function adjustTokenXMLAttrs(token: TagToken): void;
8
- export declare function adjustTokenSVGTagName(token: TagToken): void;
9
- export declare function isIntegrationPoint(tn: $, ns: NS, attrs: Attribute[], foreignNS?: NS): boolean;
@@ -1,237 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SVG_TAG_NAMES_ADJUSTMENT_MAP = void 0;
4
- exports.causesExit = causesExit;
5
- exports.adjustTokenMathMLAttrs = adjustTokenMathMLAttrs;
6
- exports.adjustTokenSVGAttrs = adjustTokenSVGAttrs;
7
- exports.adjustTokenXMLAttrs = adjustTokenXMLAttrs;
8
- exports.adjustTokenSVGTagName = adjustTokenSVGTagName;
9
- exports.isIntegrationPoint = isIntegrationPoint;
10
- const html_js_1 = require("./html.js");
11
- //MIME types
12
- const MIME_TYPES = {
13
- TEXT_HTML: 'text/html',
14
- APPLICATION_XML: 'application/xhtml+xml',
15
- };
16
- //Attributes
17
- const DEFINITION_URL_ATTR = 'definitionurl';
18
- const ADJUSTED_DEFINITION_URL_ATTR = 'definitionURL';
19
- const SVG_ATTRS_ADJUSTMENT_MAP = new Map([
20
- 'attributeName',
21
- 'attributeType',
22
- 'baseFrequency',
23
- 'baseProfile',
24
- 'calcMode',
25
- 'clipPathUnits',
26
- 'diffuseConstant',
27
- 'edgeMode',
28
- 'filterUnits',
29
- 'glyphRef',
30
- 'gradientTransform',
31
- 'gradientUnits',
32
- 'kernelMatrix',
33
- 'kernelUnitLength',
34
- 'keyPoints',
35
- 'keySplines',
36
- 'keyTimes',
37
- 'lengthAdjust',
38
- 'limitingConeAngle',
39
- 'markerHeight',
40
- 'markerUnits',
41
- 'markerWidth',
42
- 'maskContentUnits',
43
- 'maskUnits',
44
- 'numOctaves',
45
- 'pathLength',
46
- 'patternContentUnits',
47
- 'patternTransform',
48
- 'patternUnits',
49
- 'pointsAtX',
50
- 'pointsAtY',
51
- 'pointsAtZ',
52
- 'preserveAlpha',
53
- 'preserveAspectRatio',
54
- 'primitiveUnits',
55
- 'refX',
56
- 'refY',
57
- 'repeatCount',
58
- 'repeatDur',
59
- 'requiredExtensions',
60
- 'requiredFeatures',
61
- 'specularConstant',
62
- 'specularExponent',
63
- 'spreadMethod',
64
- 'startOffset',
65
- 'stdDeviation',
66
- 'stitchTiles',
67
- 'surfaceScale',
68
- 'systemLanguage',
69
- 'tableValues',
70
- 'targetX',
71
- 'targetY',
72
- 'textLength',
73
- 'viewBox',
74
- 'viewTarget',
75
- 'xChannelSelector',
76
- 'yChannelSelector',
77
- 'zoomAndPan',
78
- ].map((attr) => [attr.toLowerCase(), attr]));
79
- const XML_ATTRS_ADJUSTMENT_MAP = new Map([
80
- ['xlink:actuate', { prefix: 'xlink', name: 'actuate', namespace: html_js_1.NS.XLINK }],
81
- ['xlink:arcrole', { prefix: 'xlink', name: 'arcrole', namespace: html_js_1.NS.XLINK }],
82
- ['xlink:href', { prefix: 'xlink', name: 'href', namespace: html_js_1.NS.XLINK }],
83
- ['xlink:role', { prefix: 'xlink', name: 'role', namespace: html_js_1.NS.XLINK }],
84
- ['xlink:show', { prefix: 'xlink', name: 'show', namespace: html_js_1.NS.XLINK }],
85
- ['xlink:title', { prefix: 'xlink', name: 'title', namespace: html_js_1.NS.XLINK }],
86
- ['xlink:type', { prefix: 'xlink', name: 'type', namespace: html_js_1.NS.XLINK }],
87
- ['xml:lang', { prefix: 'xml', name: 'lang', namespace: html_js_1.NS.XML }],
88
- ['xml:space', { prefix: 'xml', name: 'space', namespace: html_js_1.NS.XML }],
89
- ['xmlns', { prefix: '', name: 'xmlns', namespace: html_js_1.NS.XMLNS }],
90
- ['xmlns:xlink', { prefix: 'xmlns', name: 'xlink', namespace: html_js_1.NS.XMLNS }],
91
- ]);
92
- //SVG tag names adjustment map
93
- exports.SVG_TAG_NAMES_ADJUSTMENT_MAP = new Map([
94
- 'altGlyph',
95
- 'altGlyphDef',
96
- 'altGlyphItem',
97
- 'animateColor',
98
- 'animateMotion',
99
- 'animateTransform',
100
- 'clipPath',
101
- 'feBlend',
102
- 'feColorMatrix',
103
- 'feComponentTransfer',
104
- 'feComposite',
105
- 'feConvolveMatrix',
106
- 'feDiffuseLighting',
107
- 'feDisplacementMap',
108
- 'feDistantLight',
109
- 'feFlood',
110
- 'feFuncA',
111
- 'feFuncB',
112
- 'feFuncG',
113
- 'feFuncR',
114
- 'feGaussianBlur',
115
- 'feImage',
116
- 'feMerge',
117
- 'feMergeNode',
118
- 'feMorphology',
119
- 'feOffset',
120
- 'fePointLight',
121
- 'feSpecularLighting',
122
- 'feSpotLight',
123
- 'feTile',
124
- 'feTurbulence',
125
- 'foreignObject',
126
- 'glyphRef',
127
- 'linearGradient',
128
- 'radialGradient',
129
- 'textPath',
130
- ].map((tn) => [tn.toLowerCase(), tn]));
131
- //Tags that causes exit from foreign content
132
- const EXITS_FOREIGN_CONTENT = new Set([
133
- html_js_1.TAG_ID.B,
134
- html_js_1.TAG_ID.BIG,
135
- html_js_1.TAG_ID.BLOCKQUOTE,
136
- html_js_1.TAG_ID.BODY,
137
- html_js_1.TAG_ID.BR,
138
- html_js_1.TAG_ID.CENTER,
139
- html_js_1.TAG_ID.CODE,
140
- html_js_1.TAG_ID.DD,
141
- html_js_1.TAG_ID.DIV,
142
- html_js_1.TAG_ID.DL,
143
- html_js_1.TAG_ID.DT,
144
- html_js_1.TAG_ID.EM,
145
- html_js_1.TAG_ID.EMBED,
146
- html_js_1.TAG_ID.H1,
147
- html_js_1.TAG_ID.H2,
148
- html_js_1.TAG_ID.H3,
149
- html_js_1.TAG_ID.H4,
150
- html_js_1.TAG_ID.H5,
151
- html_js_1.TAG_ID.H6,
152
- html_js_1.TAG_ID.HEAD,
153
- html_js_1.TAG_ID.HR,
154
- html_js_1.TAG_ID.I,
155
- html_js_1.TAG_ID.IMG,
156
- html_js_1.TAG_ID.LI,
157
- html_js_1.TAG_ID.LISTING,
158
- html_js_1.TAG_ID.MENU,
159
- html_js_1.TAG_ID.META,
160
- html_js_1.TAG_ID.NOBR,
161
- html_js_1.TAG_ID.OL,
162
- html_js_1.TAG_ID.P,
163
- html_js_1.TAG_ID.PRE,
164
- html_js_1.TAG_ID.RUBY,
165
- html_js_1.TAG_ID.S,
166
- html_js_1.TAG_ID.SMALL,
167
- html_js_1.TAG_ID.SPAN,
168
- html_js_1.TAG_ID.STRONG,
169
- html_js_1.TAG_ID.STRIKE,
170
- html_js_1.TAG_ID.SUB,
171
- html_js_1.TAG_ID.SUP,
172
- html_js_1.TAG_ID.TABLE,
173
- html_js_1.TAG_ID.TT,
174
- html_js_1.TAG_ID.U,
175
- html_js_1.TAG_ID.UL,
176
- html_js_1.TAG_ID.VAR,
177
- ]);
178
- //Check exit from foreign content
179
- function causesExit(startTagToken) {
180
- const tn = startTagToken.tagID;
181
- const isFontWithAttrs = tn === html_js_1.TAG_ID.FONT &&
182
- startTagToken.attrs.some(({ name }) => name === html_js_1.ATTRS.COLOR || name === html_js_1.ATTRS.SIZE || name === html_js_1.ATTRS.FACE);
183
- return isFontWithAttrs || EXITS_FOREIGN_CONTENT.has(tn);
184
- }
185
- //Token adjustments
186
- function adjustTokenMathMLAttrs(token) {
187
- for (let i = 0; i < token.attrs.length; i++) {
188
- if (token.attrs[i].name === DEFINITION_URL_ATTR) {
189
- token.attrs[i].name = ADJUSTED_DEFINITION_URL_ATTR;
190
- break;
191
- }
192
- }
193
- }
194
- function adjustTokenSVGAttrs(token) {
195
- for (let i = 0; i < token.attrs.length; i++) {
196
- const adjustedAttrName = SVG_ATTRS_ADJUSTMENT_MAP.get(token.attrs[i].name);
197
- if (adjustedAttrName != null) {
198
- token.attrs[i].name = adjustedAttrName;
199
- }
200
- }
201
- }
202
- function adjustTokenXMLAttrs(token) {
203
- for (let i = 0; i < token.attrs.length; i++) {
204
- const adjustedAttrEntry = XML_ATTRS_ADJUSTMENT_MAP.get(token.attrs[i].name);
205
- if (adjustedAttrEntry) {
206
- token.attrs[i].prefix = adjustedAttrEntry.prefix;
207
- token.attrs[i].name = adjustedAttrEntry.name;
208
- token.attrs[i].namespace = adjustedAttrEntry.namespace;
209
- }
210
- }
211
- }
212
- function adjustTokenSVGTagName(token) {
213
- const adjustedTagName = exports.SVG_TAG_NAMES_ADJUSTMENT_MAP.get(token.tagName);
214
- if (adjustedTagName != null) {
215
- token.tagName = adjustedTagName;
216
- token.tagID = (0, html_js_1.getTagID)(token.tagName);
217
- }
218
- }
219
- //Integration points
220
- function isMathMLTextIntegrationPoint(tn, ns) {
221
- return ns === html_js_1.NS.MATHML && (tn === html_js_1.TAG_ID.MI || tn === html_js_1.TAG_ID.MO || tn === html_js_1.TAG_ID.MN || tn === html_js_1.TAG_ID.MS || tn === html_js_1.TAG_ID.MTEXT);
222
- }
223
- function isHtmlIntegrationPoint(tn, ns, attrs) {
224
- if (ns === html_js_1.NS.MATHML && tn === html_js_1.TAG_ID.ANNOTATION_XML) {
225
- for (let i = 0; i < attrs.length; i++) {
226
- if (attrs[i].name === html_js_1.ATTRS.ENCODING) {
227
- const value = attrs[i].value.toLowerCase();
228
- return value === MIME_TYPES.TEXT_HTML || value === MIME_TYPES.APPLICATION_XML;
229
- }
230
- }
231
- }
232
- return ns === html_js_1.NS.SVG && (tn === html_js_1.TAG_ID.FOREIGN_OBJECT || tn === html_js_1.TAG_ID.DESC || tn === html_js_1.TAG_ID.TITLE);
233
- }
234
- function isIntegrationPoint(tn, ns, attrs, foreignNS) {
235
- return (((!foreignNS || foreignNS === html_js_1.NS.HTML) && isHtmlIntegrationPoint(tn, ns, attrs)) ||
236
- ((!foreignNS || foreignNS === html_js_1.NS.MATHML) && isMathMLTextIntegrationPoint(tn, ns)));
237
- }