entities 3.0.0 → 4.1.0
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.
- package/lib/decode.d.ts +6 -19
- package/lib/decode.d.ts.map +1 -1
- package/lib/decode.js +46 -59
- package/lib/decode.js.map +1 -0
- package/lib/decode_codepoint.d.ts +1 -0
- package/lib/decode_codepoint.d.ts.map +1 -1
- package/lib/decode_codepoint.js +9 -3
- package/lib/decode_codepoint.js.map +1 -0
- package/lib/encode-trie.d.ts +0 -5
- package/lib/encode-trie.d.ts.map +1 -1
- package/lib/encode-trie.js +28 -38
- package/lib/encode-trie.js.map +1 -0
- package/lib/encode.d.ts +15 -1
- package/lib/encode.d.ts.map +1 -1
- package/lib/encode.js +57 -58
- package/lib/encode.js.map +1 -0
- package/lib/esm/decode.d.ts +14 -0
- package/lib/esm/decode.d.ts.map +1 -0
- package/lib/esm/decode.js +135 -0
- package/lib/esm/decode.js.map +1 -0
- package/lib/esm/decode_codepoint.d.ts +3 -0
- package/lib/esm/decode_codepoint.d.ts.map +1 -0
- package/lib/esm/decode_codepoint.js +55 -0
- package/lib/esm/decode_codepoint.js.map +1 -0
- package/lib/esm/encode-trie.d.ts +3 -0
- package/lib/esm/encode-trie.d.ts.map +1 -0
- package/lib/esm/encode-trie.js +55 -0
- package/lib/esm/encode-trie.js.map +1 -0
- package/lib/esm/encode.d.ts +60 -0
- package/lib/esm/encode.d.ts.map +1 -0
- package/lib/esm/encode.js +119 -0
- package/lib/esm/encode.js.map +1 -0
- package/lib/esm/generated/decode-data-html.d.ts +3 -0
- package/lib/esm/generated/decode-data-html.d.ts.map +1 -0
- package/lib/esm/generated/decode-data-html.js +4 -0
- package/lib/esm/generated/decode-data-html.js.map +1 -0
- package/lib/esm/generated/decode-data-xml.d.ts +3 -0
- package/lib/esm/generated/decode-data-xml.d.ts.map +1 -0
- package/lib/esm/generated/decode-data-xml.js +4 -0
- package/lib/esm/generated/decode-data-xml.js.map +1 -0
- package/lib/esm/generated/encode-html.d.ts +8 -0
- package/lib/esm/generated/encode-html.d.ts.map +1 -0
- package/lib/esm/generated/encode-html.js +4 -0
- package/lib/esm/generated/encode-html.js.map +1 -0
- package/lib/esm/index.d.ts +101 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +111 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/generated/decode-data-html.d.ts.map +1 -1
- package/lib/generated/decode-data-html.js +2 -1
- package/lib/generated/decode-data-html.js.map +1 -0
- package/lib/generated/decode-data-xml.d.ts.map +1 -1
- package/lib/generated/decode-data-xml.js +2 -1
- package/lib/generated/decode-data-xml.js.map +1 -0
- package/lib/generated/encode-html.d.ts +8 -0
- package/lib/generated/encode-html.d.ts.map +1 -0
- package/lib/generated/encode-html.js +6 -0
- package/lib/generated/encode-html.js.map +1 -0
- package/lib/index.d.ts +18 -8
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +47 -30
- package/lib/index.js.map +1 -0
- package/package.json +34 -14
- package/readme.md +61 -13
- package/lib/maps/entities.json +0 -1
- package/lib/maps/legacy.json +0 -1
- package/lib/maps/xml.json +0 -1
package/lib/decode.d.ts
CHANGED
|
@@ -1,25 +1,12 @@
|
|
|
1
|
-
import htmlDecodeTree from "./generated/decode-data-html";
|
|
2
|
-
import xmlDecodeTree from "./generated/decode-data-xml";
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
NUM,
|
|
6
|
-
SEMI,
|
|
7
|
-
ZERO,
|
|
8
|
-
NINE,
|
|
9
|
-
LOWER_A,
|
|
10
|
-
UPPER_A,
|
|
11
|
-
LOWER_F,
|
|
12
|
-
UPPER_F,
|
|
13
|
-
LOWER_X,
|
|
14
|
-
UPPER_X
|
|
15
|
-
}
|
|
1
|
+
import htmlDecodeTree from "./generated/decode-data-html.js";
|
|
2
|
+
import xmlDecodeTree from "./generated/decode-data-xml.js";
|
|
3
|
+
import decodeCodePoint from "./decode_codepoint.js";
|
|
4
|
+
export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint };
|
|
16
5
|
export declare enum BinTrieFlags {
|
|
17
|
-
|
|
18
|
-
BRANCH_LENGTH =
|
|
19
|
-
MULTI_BYTE = 128,
|
|
6
|
+
VALUE_LENGTH = 49152,
|
|
7
|
+
BRANCH_LENGTH = 16256,
|
|
20
8
|
JUMP_TABLE = 127
|
|
21
9
|
}
|
|
22
|
-
export declare const JUMP_OFFSET_BASE: number;
|
|
23
10
|
export declare function determineBranch(decodeTree: Uint16Array, current: number, nodeIdx: number, char: number): number;
|
|
24
11
|
export declare function decodeHTML(str: string): string;
|
|
25
12
|
export declare function decodeHTMLStrict(str: string): string;
|
package/lib/decode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,iCAAiC,CAAC;AAC7D,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC;AAc1D,oBAAY,YAAY;IACpB,YAAY,QAAwB;IACpC,aAAa,QAAwB;IACrC,UAAU,MAAwB;CACrC;AA8GD,wBAAgB,eAAe,CAC3B,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,GACb,MAAM,CAsCR;AAKD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|
package/lib/decode.js
CHANGED
|
@@ -3,33 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTML = exports.determineBranch = exports.
|
|
7
|
-
var
|
|
8
|
-
exports.htmlDecodeTree =
|
|
9
|
-
var
|
|
10
|
-
exports.xmlDecodeTree =
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
(function (CharCodes) {
|
|
14
|
-
CharCodes[CharCodes["NUM"] = "#".charCodeAt(0)] = "NUM";
|
|
15
|
-
CharCodes[CharCodes["SEMI"] = ";".charCodeAt(0)] = "SEMI";
|
|
16
|
-
CharCodes[CharCodes["ZERO"] = "0".charCodeAt(0)] = "ZERO";
|
|
17
|
-
CharCodes[CharCodes["NINE"] = "9".charCodeAt(0)] = "NINE";
|
|
18
|
-
CharCodes[CharCodes["LOWER_A"] = "a".charCodeAt(0)] = "LOWER_A";
|
|
19
|
-
CharCodes[CharCodes["UPPER_A"] = "A".charCodeAt(0)] = "UPPER_A";
|
|
20
|
-
CharCodes[CharCodes["LOWER_F"] = "f".charCodeAt(0)] = "LOWER_F";
|
|
21
|
-
CharCodes[CharCodes["UPPER_F"] = "F".charCodeAt(0)] = "UPPER_F";
|
|
22
|
-
CharCodes[CharCodes["LOWER_X"] = "x".charCodeAt(0)] = "LOWER_X";
|
|
23
|
-
CharCodes[CharCodes["UPPER_X"] = "X".charCodeAt(0)] = "UPPER_X";
|
|
24
|
-
})(CharCodes = exports.CharCodes || (exports.CharCodes = {}));
|
|
6
|
+
exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTML = exports.determineBranch = exports.BinTrieFlags = exports.decodeCodePoint = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0;
|
|
7
|
+
var decode_data_html_js_1 = __importDefault(require("./generated/decode-data-html.js"));
|
|
8
|
+
exports.htmlDecodeTree = decode_data_html_js_1.default;
|
|
9
|
+
var decode_data_xml_js_1 = __importDefault(require("./generated/decode-data-xml.js"));
|
|
10
|
+
exports.xmlDecodeTree = decode_data_xml_js_1.default;
|
|
11
|
+
var decode_codepoint_js_1 = __importDefault(require("./decode_codepoint.js"));
|
|
12
|
+
exports.decodeCodePoint = decode_codepoint_js_1.default;
|
|
25
13
|
var BinTrieFlags;
|
|
26
14
|
(function (BinTrieFlags) {
|
|
27
|
-
BinTrieFlags[BinTrieFlags["
|
|
28
|
-
BinTrieFlags[BinTrieFlags["BRANCH_LENGTH"] =
|
|
29
|
-
BinTrieFlags[BinTrieFlags["MULTI_BYTE"] = 128] = "MULTI_BYTE";
|
|
15
|
+
BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH";
|
|
16
|
+
BinTrieFlags[BinTrieFlags["BRANCH_LENGTH"] = 16256] = "BRANCH_LENGTH";
|
|
30
17
|
BinTrieFlags[BinTrieFlags["JUMP_TABLE"] = 127] = "JUMP_TABLE";
|
|
31
18
|
})(BinTrieFlags = exports.BinTrieFlags || (exports.BinTrieFlags = {}));
|
|
32
|
-
exports.JUMP_OFFSET_BASE = CharCodes.ZERO - 1;
|
|
33
19
|
function getDecoder(decodeTree) {
|
|
34
20
|
return function decodeHTMLBinary(str, strict) {
|
|
35
21
|
var ret = "";
|
|
@@ -41,38 +27,37 @@ function getDecoder(decodeTree) {
|
|
|
41
27
|
// Skip the "&"
|
|
42
28
|
strIdx += 1;
|
|
43
29
|
// If we have a numeric entity, handle this separately.
|
|
44
|
-
if (str.charCodeAt(strIdx) ===
|
|
30
|
+
if (str.charCodeAt(strIdx) === 35 /* NUM */) {
|
|
45
31
|
// Skip the leading "&#". For hex entities, also skip the leading "x".
|
|
46
32
|
var start = strIdx + 1;
|
|
47
33
|
var base = 10;
|
|
48
34
|
var cp = str.charCodeAt(start);
|
|
49
|
-
if (cp
|
|
35
|
+
if ((cp | 32 /* To_LOWER_BIT */) === 120 /* LOWER_X */) {
|
|
50
36
|
base = 16;
|
|
51
37
|
strIdx += 1;
|
|
52
38
|
start += 1;
|
|
53
39
|
}
|
|
54
|
-
|
|
55
|
-
cp
|
|
40
|
+
do
|
|
41
|
+
cp = str.charCodeAt(++strIdx);
|
|
42
|
+
while ((cp >= 48 /* ZERO */ && cp <= 57 /* NINE */) ||
|
|
56
43
|
(base === 16 &&
|
|
57
|
-
(
|
|
58
|
-
|
|
59
|
-
cp <= CharCodes.UPPER_F))))
|
|
60
|
-
;
|
|
44
|
+
(cp | 32 /* To_LOWER_BIT */) >= 97 /* LOWER_A */ &&
|
|
45
|
+
(cp | 32 /* To_LOWER_BIT */) <= 102 /* LOWER_F */));
|
|
61
46
|
if (start !== strIdx) {
|
|
62
47
|
var entity = str.substring(start, strIdx);
|
|
63
48
|
var parsed = parseInt(entity, base);
|
|
64
|
-
if (str.charCodeAt(strIdx) ===
|
|
49
|
+
if (str.charCodeAt(strIdx) === 59 /* SEMI */) {
|
|
65
50
|
strIdx += 1;
|
|
66
51
|
}
|
|
67
52
|
else if (strict) {
|
|
68
53
|
continue;
|
|
69
54
|
}
|
|
70
|
-
ret +=
|
|
55
|
+
ret += (0, decode_codepoint_js_1.default)(parsed);
|
|
71
56
|
lastIdx = strIdx;
|
|
72
57
|
}
|
|
73
58
|
continue;
|
|
74
59
|
}
|
|
75
|
-
var
|
|
60
|
+
var resultIdx = 0;
|
|
76
61
|
var excess = 1;
|
|
77
62
|
var treeIdx = 0;
|
|
78
63
|
var current = decodeTree[treeIdx];
|
|
@@ -81,25 +66,29 @@ function getDecoder(decodeTree) {
|
|
|
81
66
|
if (treeIdx < 0)
|
|
82
67
|
break;
|
|
83
68
|
current = decodeTree[treeIdx];
|
|
69
|
+
var masked = current & BinTrieFlags.VALUE_LENGTH;
|
|
84
70
|
// If the branch is a value, store it and continue
|
|
85
|
-
if (
|
|
71
|
+
if (masked) {
|
|
86
72
|
// If we have a legacy entity while parsing strictly, just skip the number of bytes
|
|
87
|
-
if (strict
|
|
88
|
-
|
|
89
|
-
treeIdx += 1;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
// If this is a surrogate pair, combine the higher bits from the node with the next byte
|
|
93
|
-
result =
|
|
94
|
-
current & BinTrieFlags.MULTI_BYTE
|
|
95
|
-
? String.fromCharCode(decodeTree[++treeIdx], decodeTree[++treeIdx])
|
|
96
|
-
: String.fromCharCode(decodeTree[++treeIdx]);
|
|
73
|
+
if (!strict || str.charCodeAt(strIdx) === 59 /* SEMI */) {
|
|
74
|
+
resultIdx = treeIdx;
|
|
97
75
|
excess = 0;
|
|
98
76
|
}
|
|
77
|
+
// The mask is the number of bytes of the value, including the current byte.
|
|
78
|
+
var valueLength = (masked >> 14) - 1;
|
|
79
|
+
if (valueLength === 0)
|
|
80
|
+
break;
|
|
81
|
+
treeIdx += valueLength;
|
|
99
82
|
}
|
|
100
83
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
84
|
+
if (resultIdx !== 0) {
|
|
85
|
+
var valueLength = (decodeTree[resultIdx] & BinTrieFlags.VALUE_LENGTH) >> 14;
|
|
86
|
+
ret +=
|
|
87
|
+
valueLength === 1
|
|
88
|
+
? String.fromCharCode(decodeTree[resultIdx] & ~BinTrieFlags.VALUE_LENGTH)
|
|
89
|
+
: valueLength === 2
|
|
90
|
+
? String.fromCharCode(decodeTree[resultIdx + 1])
|
|
91
|
+
: String.fromCharCode(decodeTree[resultIdx + 1], decodeTree[resultIdx + 2]);
|
|
103
92
|
lastIdx = strIdx - excess + 1;
|
|
104
93
|
}
|
|
105
94
|
}
|
|
@@ -107,23 +96,20 @@ function getDecoder(decodeTree) {
|
|
|
107
96
|
};
|
|
108
97
|
}
|
|
109
98
|
function determineBranch(decodeTree, current, nodeIdx, char) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
var branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 8;
|
|
99
|
+
var branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;
|
|
100
|
+
var jumpOffset = current & BinTrieFlags.JUMP_TABLE;
|
|
101
|
+
// Case 1: Single branch encoded in jump offset
|
|
114
102
|
if (branchCount === 0) {
|
|
115
|
-
return -1;
|
|
103
|
+
return jumpOffset !== 0 && char === jumpOffset ? nodeIdx : -1;
|
|
116
104
|
}
|
|
117
|
-
|
|
118
|
-
return char === decodeTree[nodeIdx] ? nodeIdx + 1 : -1;
|
|
119
|
-
}
|
|
120
|
-
var jumpOffset = current & BinTrieFlags.JUMP_TABLE;
|
|
105
|
+
// Case 2: Multiple branches encoded in jump table
|
|
121
106
|
if (jumpOffset) {
|
|
122
|
-
var value = char -
|
|
107
|
+
var value = char - jumpOffset;
|
|
123
108
|
return value < 0 || value > branchCount
|
|
124
109
|
? -1
|
|
125
110
|
: decodeTree[nodeIdx + value] - 1;
|
|
126
111
|
}
|
|
112
|
+
// Case 3: Multiple branches encoded in dictionary
|
|
127
113
|
// Binary search for the character.
|
|
128
114
|
var lo = nodeIdx;
|
|
129
115
|
var hi = lo + branchCount - 1;
|
|
@@ -143,8 +129,8 @@ function determineBranch(decodeTree, current, nodeIdx, char) {
|
|
|
143
129
|
return -1;
|
|
144
130
|
}
|
|
145
131
|
exports.determineBranch = determineBranch;
|
|
146
|
-
var htmlDecoder = getDecoder(
|
|
147
|
-
var xmlDecoder = getDecoder(
|
|
132
|
+
var htmlDecoder = getDecoder(decode_data_html_js_1.default);
|
|
133
|
+
var xmlDecoder = getDecoder(decode_data_xml_js_1.default);
|
|
148
134
|
function decodeHTML(str) {
|
|
149
135
|
return htmlDecoder(str, false);
|
|
150
136
|
}
|
|
@@ -157,3 +143,4 @@ function decodeXML(str) {
|
|
|
157
143
|
return xmlDecoder(str, true);
|
|
158
144
|
}
|
|
159
145
|
exports.decodeXML = decodeXML;
|
|
146
|
+
//# sourceMappingURL=decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AAC;AAFD,gCAEC;AAED,SAAgB,gBAAgB,CAAC,GAAW;IACxC,OAAO,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;AAFD,4CAEC;AAED,SAAgB,SAAS,CAAC,GAAW;IACjC,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC;AAFD,8BAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode_codepoint.d.ts","sourceRoot":"","sources":["../src/decode_codepoint.ts"],"names":[],"mappings":"AAmDA,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"decode_codepoint.d.ts","sourceRoot":"","sources":["../src/decode_codepoint.ts"],"names":[],"mappings":"AAmDA,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,UAMjD;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEjE"}
|
package/lib/decode_codepoint.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.replaceCodePoint = void 0;
|
|
4
5
|
var decodeMap = new Map([
|
|
5
6
|
[0, 65533],
|
|
6
7
|
[128, 8364],
|
|
@@ -44,11 +45,16 @@ String.fromCodePoint ||
|
|
|
44
45
|
output += String.fromCharCode(codePoint);
|
|
45
46
|
return output;
|
|
46
47
|
};
|
|
47
|
-
function
|
|
48
|
+
function replaceCodePoint(codePoint) {
|
|
48
49
|
var _a;
|
|
49
50
|
if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
|
|
50
|
-
return
|
|
51
|
+
return 0xfffd;
|
|
51
52
|
}
|
|
52
|
-
return
|
|
53
|
+
return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;
|
|
54
|
+
}
|
|
55
|
+
exports.replaceCodePoint = replaceCodePoint;
|
|
56
|
+
function decodeCodePoint(codePoint) {
|
|
57
|
+
return fromCodePoint(replaceCodePoint(codePoint));
|
|
53
58
|
}
|
|
54
59
|
exports.default = decodeCodePoint;
|
|
60
|
+
//# sourceMappingURL=decode_codepoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode_codepoint.js","sourceRoot":"","sources":["../src/decode_codepoint.ts"],"names":[],"mappings":";AAAA,qHAAqH;;;AAErH,IAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACtB,CAAC,CAAC,EAAE,KAAK,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;CACb,CAAC,CAAC;AAEH,IAAM,aAAa;AACf,iHAAiH;AACjH,MAAM,CAAC,aAAa;IACpB,UAAU,SAAiB;QACvB,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,IAAI,SAAS,GAAG,MAAM,EAAE;YACpB,SAAS,IAAI,OAAO,CAAC;YACrB,MAAM,IAAI,MAAM,CAAC,YAAY,CACzB,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,GAAG,MAAM,CACxC,CAAC;YACF,SAAS,GAAG,MAAM,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC;SAC5C;QAED,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QACzC,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;AAEN,SAAgB,gBAAgB,CAAC,SAAiB;;IAC9C,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,SAAS,IAAI,MAAM,CAAC,IAAI,SAAS,GAAG,QAAQ,EAAE;QACtE,OAAO,MAAM,CAAC;KACjB;IAED,OAAO,MAAA,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,mCAAI,SAAS,CAAC;AACjD,CAAC;AAND,4CAMC;AAED,SAAwB,eAAe,CAAC,SAAiB;IACrD,OAAO,aAAa,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;AACtD,CAAC;AAFD,kCAEC"}
|
package/lib/encode-trie.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
export declare const getCodePoint: (str: string, index: number) => number;
|
|
2
2
|
export declare function encodeHTMLTrieRe(regExp: RegExp, str: string): string;
|
|
3
|
-
export interface TrieNode {
|
|
4
|
-
value?: string;
|
|
5
|
-
next?: Map<number, TrieNode>;
|
|
6
|
-
}
|
|
7
|
-
export declare function getTrie(map: Record<string, string>): Map<number, TrieNode>;
|
|
8
3
|
//# sourceMappingURL=encode-trie.d.ts.map
|
package/lib/encode-trie.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode-trie.d.ts","sourceRoot":"","sources":["../src/encode-trie.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encode-trie.d.ts","sourceRoot":"","sources":["../src/encode-trie.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,YAAY,QAGT,MAAM,SAAS,MAAM,KAAG,MAQD,CAAC;AAExC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CA6CpE"}
|
package/lib/encode-trie.js
CHANGED
|
@@ -3,8 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
var
|
|
6
|
+
exports.encodeHTMLTrieRe = exports.getCodePoint = void 0;
|
|
7
|
+
var encode_html_1 = __importDefault(require("./generated/encode-html"));
|
|
8
|
+
function isHighSurrugate(c) {
|
|
9
|
+
return (c & 64512 /* Mask */) === 55296 /* High */;
|
|
10
|
+
}
|
|
8
11
|
// For compatibility with node < 4, we wrap `codePointAt`
|
|
9
12
|
exports.getCodePoint =
|
|
10
13
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -12,14 +15,13 @@ String.prototype.codePointAt != null
|
|
|
12
15
|
? function (str, index) { return str.codePointAt(index); }
|
|
13
16
|
: // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
|
14
17
|
function (c, index) {
|
|
15
|
-
return (c.charCodeAt(index)
|
|
16
|
-
? (c.charCodeAt(index) -
|
|
18
|
+
return isHighSurrugate(c.charCodeAt(index))
|
|
19
|
+
? (c.charCodeAt(index) - 55296 /* High */) * 0x400 +
|
|
17
20
|
c.charCodeAt(index + 1) -
|
|
18
21
|
0xdc00 +
|
|
19
22
|
0x10000
|
|
20
23
|
: c.charCodeAt(index);
|
|
21
24
|
};
|
|
22
|
-
var htmlTrie = getTrie(entities_json_1.default);
|
|
23
25
|
function encodeHTMLTrieRe(regExp, str) {
|
|
24
26
|
var _a;
|
|
25
27
|
var ret = "";
|
|
@@ -28,47 +30,35 @@ function encodeHTMLTrieRe(regExp, str) {
|
|
|
28
30
|
while ((match = regExp.exec(str)) !== null) {
|
|
29
31
|
var i = match.index;
|
|
30
32
|
var char = str.charCodeAt(i);
|
|
31
|
-
var next =
|
|
32
|
-
if (next) {
|
|
33
|
-
if (next
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
var next = encode_html_1.default.get(char);
|
|
34
|
+
if (next != null) {
|
|
35
|
+
if (typeof next !== "string") {
|
|
36
|
+
// We are in a branch. Try to match the next char.
|
|
37
|
+
if (i + 1 < str.length) {
|
|
38
|
+
var value = typeof next.n === "number"
|
|
39
|
+
? next.n === str.charCodeAt(i + 1)
|
|
40
|
+
? next.o
|
|
41
|
+
: null
|
|
42
|
+
: next.n.get(str.charCodeAt(i + 1));
|
|
43
|
+
if (value) {
|
|
44
|
+
ret += str.substring(lastIdx, i) + value;
|
|
45
|
+
lastIdx = regExp.lastIndex += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
40
48
|
}
|
|
49
|
+
// If we have a character without a value, use a numeric entitiy.
|
|
50
|
+
next = (_a = next.v) !== null && _a !== void 0 ? _a : "&#x".concat(char.toString(16), ";");
|
|
41
51
|
}
|
|
42
|
-
ret += str.substring(lastIdx, i) + next
|
|
52
|
+
ret += str.substring(lastIdx, i) + next;
|
|
43
53
|
lastIdx = i + 1;
|
|
44
54
|
}
|
|
45
55
|
else {
|
|
46
|
-
ret += str.substring(lastIdx, i)
|
|
56
|
+
ret += "".concat(str.substring(lastIdx, i), "&#x").concat((0, exports.getCodePoint)(str, i).toString(16), ";");
|
|
47
57
|
// Increase by 1 if we have a surrogate pair
|
|
48
|
-
lastIdx = regExp.lastIndex += Number((char
|
|
58
|
+
lastIdx = regExp.lastIndex += Number(isHighSurrugate(char));
|
|
49
59
|
}
|
|
50
60
|
}
|
|
51
61
|
return ret + str.substr(lastIdx);
|
|
52
62
|
}
|
|
53
63
|
exports.encodeHTMLTrieRe = encodeHTMLTrieRe;
|
|
54
|
-
|
|
55
|
-
var _a, _b, _c, _d;
|
|
56
|
-
var trie = new Map();
|
|
57
|
-
for (var _i = 0, _e = Object.keys(map); _i < _e.length; _i++) {
|
|
58
|
-
var value = _e[_i];
|
|
59
|
-
var key = map[value];
|
|
60
|
-
// Resolve the key
|
|
61
|
-
var lastMap = trie;
|
|
62
|
-
for (var i = 0; i < key.length - 1; i++) {
|
|
63
|
-
var char = key.charCodeAt(i);
|
|
64
|
-
var next = (_a = lastMap.get(char)) !== null && _a !== void 0 ? _a : {};
|
|
65
|
-
lastMap.set(char, next);
|
|
66
|
-
lastMap = (_b = next.next) !== null && _b !== void 0 ? _b : (next.next = new Map());
|
|
67
|
-
}
|
|
68
|
-
var val = (_c = lastMap.get(key.charCodeAt(key.length - 1))) !== null && _c !== void 0 ? _c : {};
|
|
69
|
-
(_d = val.value) !== null && _d !== void 0 ? _d : (val.value = "&" + value + ";");
|
|
70
|
-
lastMap.set(key.charCodeAt(key.length - 1), val);
|
|
71
|
-
}
|
|
72
|
-
return trie;
|
|
73
|
-
}
|
|
74
|
-
exports.getTrie = getTrie;
|
|
64
|
+
//# sourceMappingURL=encode-trie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-trie.js","sourceRoot":"","sources":["../src/encode-trie.ts"],"names":[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42,5 +42,19 @@ export declare const escape: typeof encodeXML;
|
|
|
42
42
|
*
|
|
43
43
|
* @param data String to escape.
|
|
44
44
|
*/
|
|
45
|
-
export declare
|
|
45
|
+
export declare const escapeUTF8: (data: string) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Encodes all characters that have to be escaped in HTML attributes,
|
|
48
|
+
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
49
|
+
*
|
|
50
|
+
* @param data String to escape.
|
|
51
|
+
*/
|
|
52
|
+
export declare const escapeAttribute: (data: string) => string;
|
|
53
|
+
/**
|
|
54
|
+
* Encodes all characters that have to be escaped in HTML text,
|
|
55
|
+
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
56
|
+
*
|
|
57
|
+
* @param data String to escape.
|
|
58
|
+
*/
|
|
59
|
+
export declare const escapeText: (data: string) => string;
|
|
46
60
|
//# sourceMappingURL=encode.d.ts.map
|
package/lib/encode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAaA;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA0B7C;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AACD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,kBAAY,CAAC;AA2BhC;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,SA7Bb,MAAM,KAAK,MA6BuC,CAAC;AAE7D;;;;;GAKG;AACH,eAAO,MAAM,eAAe,SArClB,MAAM,KAAK,MA4CpB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,SApDb,MAAM,KAAK,MA4DpB,CAAC"}
|
package/lib/encode.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.escapeUTF8 = exports.escape = exports.encodeNonAsciiHTML = exports.encodeHTML = exports.encodeXML = void 0;
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"&
|
|
16
|
-
]
|
|
3
|
+
exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeNonAsciiHTML = exports.encodeHTML = exports.encodeXML = void 0;
|
|
4
|
+
var encode_trie_js_1 = require("./encode-trie.js");
|
|
5
|
+
var htmlReplacer = /[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g;
|
|
6
|
+
var xmlReplacer = /["&'<>$\x80-\uFFFF]/g;
|
|
7
|
+
var xmlCodeMap = new Map([
|
|
8
|
+
[34, """],
|
|
9
|
+
[38, "&"],
|
|
10
|
+
[39, "'"],
|
|
11
|
+
[60, "<"],
|
|
12
|
+
[62, ">"],
|
|
13
|
+
]);
|
|
17
14
|
/**
|
|
18
15
|
* Encodes all non-ASCII characters, as well as characters not valid in XML
|
|
19
16
|
* documents using XML entities.
|
|
@@ -34,9 +31,9 @@ function encodeXML(str) {
|
|
|
34
31
|
lastIdx = i + 1;
|
|
35
32
|
}
|
|
36
33
|
else {
|
|
37
|
-
ret += str.substring(lastIdx, i)
|
|
34
|
+
ret += "".concat(str.substring(lastIdx, i), "&#x").concat((0, encode_trie_js_1.getCodePoint)(str, i).toString(16), ";");
|
|
38
35
|
// Increase by 1 if we have a surrogate pair
|
|
39
|
-
lastIdx = xmlReplacer.lastIndex += Number((char &
|
|
36
|
+
lastIdx = xmlReplacer.lastIndex += Number((char & 65408) === 0xd800);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
return ret + str.substr(lastIdx);
|
|
@@ -53,7 +50,7 @@ exports.encodeXML = encodeXML;
|
|
|
53
50
|
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
54
51
|
*/
|
|
55
52
|
function encodeHTML(data) {
|
|
56
|
-
return
|
|
53
|
+
return (0, encode_trie_js_1.encodeHTMLTrieRe)(htmlReplacer, data);
|
|
57
54
|
}
|
|
58
55
|
exports.encodeHTML = encodeHTML;
|
|
59
56
|
/**
|
|
@@ -64,33 +61,9 @@ exports.encodeHTML = encodeHTML;
|
|
|
64
61
|
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
65
62
|
*/
|
|
66
63
|
function encodeNonAsciiHTML(data) {
|
|
67
|
-
return
|
|
64
|
+
return (0, encode_trie_js_1.encodeHTMLTrieRe)(xmlReplacer, data);
|
|
68
65
|
}
|
|
69
66
|
exports.encodeNonAsciiHTML = encodeNonAsciiHTML;
|
|
70
|
-
function getCharRegExp(map, nonAscii) {
|
|
71
|
-
// Collect the start characters of all entities
|
|
72
|
-
var chars = Object.keys(map)
|
|
73
|
-
.map(function (k) { return "\\" + map[k].charAt(0); })
|
|
74
|
-
.filter(function (v) { return !nonAscii || v.charCodeAt(1) < 128; })
|
|
75
|
-
.sort(function (a, b) { return a.charCodeAt(1) - b.charCodeAt(1); })
|
|
76
|
-
// Remove duplicates
|
|
77
|
-
.filter(function (v, i, a) { return v !== a[i + 1]; });
|
|
78
|
-
// Add ranges to single characters.
|
|
79
|
-
for (var start = 0; start < chars.length - 1; start++) {
|
|
80
|
-
// Find the end of a run of characters
|
|
81
|
-
var end = start;
|
|
82
|
-
while (end < chars.length - 1 &&
|
|
83
|
-
chars[end].charCodeAt(1) + 1 === chars[end + 1].charCodeAt(1)) {
|
|
84
|
-
end += 1;
|
|
85
|
-
}
|
|
86
|
-
var count = 1 + end - start;
|
|
87
|
-
// We want to replace at least three characters
|
|
88
|
-
if (count < 3)
|
|
89
|
-
continue;
|
|
90
|
-
chars.splice(start, count, chars[start] + "-" + chars[end]);
|
|
91
|
-
}
|
|
92
|
-
return new RegExp("[" + chars.join("") + (nonAscii ? "\\x80-\\uFFFF" : "") + "]", "g");
|
|
93
|
-
}
|
|
94
67
|
/**
|
|
95
68
|
* Encodes all non-ASCII characters, as well as characters not valid in XML
|
|
96
69
|
* documents using numeric hexadecimal reference (eg. `ü`).
|
|
@@ -101,6 +74,23 @@ function getCharRegExp(map, nonAscii) {
|
|
|
101
74
|
* @param data String to escape.
|
|
102
75
|
*/
|
|
103
76
|
exports.escape = encodeXML;
|
|
77
|
+
function getEscaper(regex, map) {
|
|
78
|
+
return function escape(data) {
|
|
79
|
+
var match;
|
|
80
|
+
var lastIdx = 0;
|
|
81
|
+
var result = "";
|
|
82
|
+
while ((match = regex.exec(data))) {
|
|
83
|
+
if (lastIdx !== match.index) {
|
|
84
|
+
result += data.substring(lastIdx, match.index);
|
|
85
|
+
}
|
|
86
|
+
// We know that this chararcter will be in the map.
|
|
87
|
+
result += map.get(match[0].charCodeAt(0));
|
|
88
|
+
// Every match will be of length 1
|
|
89
|
+
lastIdx = match.index + 1;
|
|
90
|
+
}
|
|
91
|
+
return result + data.substring(lastIdx);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
104
94
|
/**
|
|
105
95
|
* Encodes all characters not valid in XML documents using XML entities.
|
|
106
96
|
*
|
|
@@ -108,19 +98,28 @@ exports.escape = encodeXML;
|
|
|
108
98
|
*
|
|
109
99
|
* @param data String to escape.
|
|
110
100
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
101
|
+
exports.escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap);
|
|
102
|
+
/**
|
|
103
|
+
* Encodes all characters that have to be escaped in HTML attributes,
|
|
104
|
+
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
105
|
+
*
|
|
106
|
+
* @param data String to escape.
|
|
107
|
+
*/
|
|
108
|
+
exports.escapeAttribute = getEscaper(/["&\u00A0]/g, new Map([
|
|
109
|
+
[34, """],
|
|
110
|
+
[38, "&"],
|
|
111
|
+
[160, " "],
|
|
112
|
+
]));
|
|
113
|
+
/**
|
|
114
|
+
* Encodes all characters that have to be escaped in HTML text,
|
|
115
|
+
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
116
|
+
*
|
|
117
|
+
* @param data String to escape.
|
|
118
|
+
*/
|
|
119
|
+
exports.escapeText = getEscaper(/[&<>\u00A0]/g, new Map([
|
|
120
|
+
[38, "&"],
|
|
121
|
+
[60, "<"],
|
|
122
|
+
[62, ">"],
|
|
123
|
+
[160, " "],
|
|
124
|
+
]));
|
|
125
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":";;;AAAA,mDAAkE;AAElE,IAAM,YAAY,GAAG,qCAAqC,CAAC;AAC3D,IAAM,WAAW,GAAG,sBAAsB,CAAC;AAE3C,IAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACvB,CAAC,EAAE,EAAE,QAAQ,CAAC;IACd,CAAC,EAAE,EAAE,OAAO,CAAC;IACb,CAAC,EAAE,EAAE,QAAQ,CAAC;IACd,CAAC,EAAE,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,GAAW;IACjC,IAAI,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L,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import htmlDecodeTree from "./generated/decode-data-html.js";
|
|
2
|
+
import xmlDecodeTree from "./generated/decode-data-xml.js";
|
|
3
|
+
import decodeCodePoint from "./decode_codepoint.js";
|
|
4
|
+
export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint };
|
|
5
|
+
export declare enum BinTrieFlags {
|
|
6
|
+
VALUE_LENGTH = 49152,
|
|
7
|
+
BRANCH_LENGTH = 16256,
|
|
8
|
+
JUMP_TABLE = 127
|
|
9
|
+
}
|
|
10
|
+
export declare function determineBranch(decodeTree: Uint16Array, current: number, nodeIdx: number, char: number): number;
|
|
11
|
+
export declare function decodeHTML(str: string): string;
|
|
12
|
+
export declare function decodeHTMLStrict(str: string): string;
|
|
13
|
+
export declare function decodeXML(str: string): string;
|
|
14
|
+
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/decode.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,iCAAiC,CAAC;AAC7D,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC;AAc1D,oBAAY,YAAY;IACpB,YAAY,QAAwB;IACpC,aAAa,QAAwB;IACrC,UAAU,MAAwB;CACrC;AA8GD,wBAAgB,eAAe,CAC3B,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,GACb,MAAM,CAsCR;AAKD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|