@studiocms/wysiwyg 0.1.0-experimental.1 → 0.1.0-experimental.3
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/dist/common/prepareRender.js +1 -1
- package/dist/wysiwyg/components/Editor.astro +24 -38
- package/dist/wysiwyg/editorPlugins/blocks/blocks.d.ts +3 -0
- package/dist/wysiwyg/editorPlugins/blocks/blocks.js +239 -0
- package/dist/wysiwyg/editorPlugins/blocks/index.d.ts +80 -0
- package/dist/wysiwyg/editorPlugins/blocks/index.js +26 -0
- package/dist/wysiwyg/editorPlugins/code/blocks.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/code/blocks.js +20 -0
- package/dist/wysiwyg/editorPlugins/code/commands.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/code/commands.js +109 -0
- package/dist/wysiwyg/editorPlugins/code/components.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/code/components.js +88 -0
- package/dist/wysiwyg/editorPlugins/code/index.d.ts +47 -0
- package/dist/wysiwyg/editorPlugins/code/index.js +28 -0
- package/dist/wysiwyg/editorPlugins/code/utils.d.ts +3 -0
- package/dist/wysiwyg/editorPlugins/code/utils.js +8 -0
- package/dist/wysiwyg/editorPlugins/countdown.d.ts +86 -0
- package/dist/wysiwyg/editorPlugins/countdown.js +163 -0
- package/dist/wysiwyg/editorPlugins/forms/blocks.d.ts +3 -0
- package/dist/wysiwyg/editorPlugins/forms/blocks.js +93 -0
- package/dist/wysiwyg/editorPlugins/forms/components.d.ts +11 -0
- package/dist/wysiwyg/editorPlugins/forms/components.js +284 -0
- package/dist/wysiwyg/editorPlugins/forms/index.d.ts +21 -0
- package/dist/wysiwyg/editorPlugins/forms/index.js +18 -0
- package/dist/wysiwyg/editorPlugins/forms/traits.d.ts +2 -0
- package/dist/wysiwyg/editorPlugins/forms/traits.js +47 -0
- package/dist/wysiwyg/editorPlugins/index.d.ts +9 -0
- package/dist/wysiwyg/editorPlugins/index.js +20 -0
- package/dist/wysiwyg/editorPlugins/rte/colorPicker.d.ts +95 -0
- package/dist/wysiwyg/editorPlugins/rte/colorPicker.js +185 -0
- package/dist/wysiwyg/editorPlugins/rte/index.d.ts +48 -0
- package/dist/wysiwyg/editorPlugins/rte/index.js +369 -0
- package/dist/wysiwyg/editorPlugins/rte/styles.css +63 -0
- package/dist/wysiwyg/editorPlugins/tabs/blocks.d.ts +3 -0
- package/dist/wysiwyg/editorPlugins/tabs/blocks.js +19 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/Tab.d.ts +10 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/Tab.js +100 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContainer.d.ts +5 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContainer.js +23 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContent.d.ts +5 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContent.js +23 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContents.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContents.js +19 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/Tabs.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/Tabs.js +169 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/index.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/index.js +29 -0
- package/dist/wysiwyg/editorPlugins/tabs/index.d.ts +5 -0
- package/dist/wysiwyg/editorPlugins/tabs/index.js +15 -0
- package/dist/wysiwyg/editorPlugins/tabs/options.d.ts +5 -0
- package/dist/wysiwyg/editorPlugins/tabs/options.js +80 -0
- package/dist/wysiwyg/editorPlugins/tabs/types.d.ts +81 -0
- package/dist/wysiwyg/editorPlugins/tabs/types.js +0 -0
- package/dist/wysiwyg/editorPlugins/tooltip.d.ts +68 -0
- package/dist/wysiwyg/editorPlugins/tooltip.js +318 -0
- package/dist/wysiwyg/editorPlugins/tuiImageEditor.d.ts +86 -0
- package/dist/wysiwyg/editorPlugins/tuiImageEditor.js +204 -0
- package/dist/wysiwyg/editorPlugins/typed/blocks.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/typed/blocks.js +15 -0
- package/dist/wysiwyg/editorPlugins/typed/components.d.ts +9 -0
- package/dist/wysiwyg/editorPlugins/typed/components.js +109 -0
- package/dist/wysiwyg/editorPlugins/typed/index.d.ts +35 -0
- package/dist/wysiwyg/editorPlugins/typed/index.js +18 -0
- package/dist/wysiwyg/editorPlugins/typed/traits.d.ts +3 -0
- package/dist/wysiwyg/editorPlugins/typed/traits.js +18 -0
- package/dist/wysiwyg/editorPlugins/typed/utils.d.ts +2 -0
- package/dist/wysiwyg/editorPlugins/typed/utils.js +6 -0
- package/package.json +5 -17
- package/dist/runtime/AstroComponentProxy.d.ts +0 -29
- package/dist/runtime/AstroComponentProxy.js +0 -47
- package/dist/runtime/decoder/decode-codepoint.d.ts +0 -18
- package/dist/runtime/decoder/decode-codepoint.js +0 -58
- package/dist/runtime/decoder/decode-data-html.d.ts +0 -1
- package/dist/runtime/decoder/decode-data-html.js +0 -7
- package/dist/runtime/decoder/decode-data-xml.d.ts +0 -1
- package/dist/runtime/decoder/decode-data-xml.js +0 -7
- package/dist/runtime/decoder/index.d.ts +0 -34
- package/dist/runtime/decoder/index.js +0 -18
- package/dist/runtime/decoder/util.d.ts +0 -208
- package/dist/runtime/decoder/util.js +0 -415
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
export declare enum BinTrieFlags {
|
|
2
|
-
VALUE_LENGTH = 49152,
|
|
3
|
-
BRANCH_LENGTH = 16256,
|
|
4
|
-
JUMP_TABLE = 127
|
|
5
|
-
}
|
|
6
|
-
export declare enum DecodingMode {
|
|
7
|
-
/** Entities in text nodes that can end with any character. */
|
|
8
|
-
Legacy = 0,
|
|
9
|
-
/** Only allow entities terminated with a semicolon. */
|
|
10
|
-
Strict = 1,
|
|
11
|
-
/** Entities in attributes have limitations on ending characters. */
|
|
12
|
-
Attribute = 2
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Producers for character reference errors as defined in the HTML spec.
|
|
16
|
-
*/
|
|
17
|
-
export interface EntityErrorProducer {
|
|
18
|
-
missingSemicolonAfterCharacterReference(): void;
|
|
19
|
-
absenceOfDigitsInNumericCharacterReference(consumedCharacters: number): void;
|
|
20
|
-
validateNumericCharacterReference(code: number): void;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Token decoder with support of writing partial entities.
|
|
24
|
-
*/
|
|
25
|
-
export declare class EntityDecoder {
|
|
26
|
-
/** The tree used to decode entities. */
|
|
27
|
-
private readonly decodeTree;
|
|
28
|
-
/**
|
|
29
|
-
* The function that is called when a codepoint is decoded.
|
|
30
|
-
*
|
|
31
|
-
* For multi-byte named entities, this will be called multiple times,
|
|
32
|
-
* with the second codepoint, and the same `consumed` value.
|
|
33
|
-
*
|
|
34
|
-
* @param codepoint The decoded codepoint.
|
|
35
|
-
* @param consumed The number of bytes consumed by the decoder.
|
|
36
|
-
*/
|
|
37
|
-
private readonly emitCodePoint;
|
|
38
|
-
/** An object that is used to produce errors. */
|
|
39
|
-
private readonly errors?;
|
|
40
|
-
constructor(
|
|
41
|
-
/** The tree used to decode entities. */
|
|
42
|
-
decodeTree: Uint16Array,
|
|
43
|
-
/**
|
|
44
|
-
* The function that is called when a codepoint is decoded.
|
|
45
|
-
*
|
|
46
|
-
* For multi-byte named entities, this will be called multiple times,
|
|
47
|
-
* with the second codepoint, and the same `consumed` value.
|
|
48
|
-
*
|
|
49
|
-
* @param codepoint The decoded codepoint.
|
|
50
|
-
* @param consumed The number of bytes consumed by the decoder.
|
|
51
|
-
*/
|
|
52
|
-
emitCodePoint: (cp: number, consumed: number) => void,
|
|
53
|
-
/** An object that is used to produce errors. */
|
|
54
|
-
errors?: EntityErrorProducer | undefined);
|
|
55
|
-
/** The current state of the decoder. */
|
|
56
|
-
private state;
|
|
57
|
-
/** Characters that were consumed while parsing an entity. */
|
|
58
|
-
private consumed;
|
|
59
|
-
/**
|
|
60
|
-
* The result of the entity.
|
|
61
|
-
*
|
|
62
|
-
* Either the result index of a numeric entity, or the codepoint of a
|
|
63
|
-
* numeric entity.
|
|
64
|
-
*/
|
|
65
|
-
private result;
|
|
66
|
-
/** The current index in the decode tree. */
|
|
67
|
-
private treeIndex;
|
|
68
|
-
/** The number of characters that were consumed in excess. */
|
|
69
|
-
private excess;
|
|
70
|
-
/** The mode in which the decoder is operating. */
|
|
71
|
-
private decodeMode;
|
|
72
|
-
/** Resets the instance to make it reusable. */
|
|
73
|
-
startEntity(decodeMode: DecodingMode): void;
|
|
74
|
-
/**
|
|
75
|
-
* Write an entity to the decoder. This can be called multiple times with partial entities.
|
|
76
|
-
* If the entity is incomplete, the decoder will return -1.
|
|
77
|
-
*
|
|
78
|
-
* Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
|
|
79
|
-
* entity is incomplete, and resume when the next string is written.
|
|
80
|
-
*
|
|
81
|
-
* @param input The string containing the entity (or a continuation of the entity).
|
|
82
|
-
* @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
|
|
83
|
-
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
84
|
-
*/
|
|
85
|
-
write(input: string, offset: number): number;
|
|
86
|
-
/**
|
|
87
|
-
* Switches between the numeric decimal and hexadecimal states.
|
|
88
|
-
*
|
|
89
|
-
* Equivalent to the `Numeric character reference state` in the HTML spec.
|
|
90
|
-
*
|
|
91
|
-
* @param input The string containing the entity (or a continuation of the entity).
|
|
92
|
-
* @param offset The current offset.
|
|
93
|
-
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
94
|
-
*/
|
|
95
|
-
private stateNumericStart;
|
|
96
|
-
private addToNumericResult;
|
|
97
|
-
/**
|
|
98
|
-
* Parses a hexadecimal numeric entity.
|
|
99
|
-
*
|
|
100
|
-
* Equivalent to the `Hexademical character reference state` in the HTML spec.
|
|
101
|
-
*
|
|
102
|
-
* @param input The string containing the entity (or a continuation of the entity).
|
|
103
|
-
* @param offset The current offset.
|
|
104
|
-
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
105
|
-
*/
|
|
106
|
-
private stateNumericHex;
|
|
107
|
-
/**
|
|
108
|
-
* Parses a decimal numeric entity.
|
|
109
|
-
*
|
|
110
|
-
* Equivalent to the `Decimal character reference state` in the HTML spec.
|
|
111
|
-
*
|
|
112
|
-
* @param input The string containing the entity (or a continuation of the entity).
|
|
113
|
-
* @param offset The current offset.
|
|
114
|
-
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
115
|
-
*/
|
|
116
|
-
private stateNumericDecimal;
|
|
117
|
-
/**
|
|
118
|
-
* Validate and emit a numeric entity.
|
|
119
|
-
*
|
|
120
|
-
* Implements the logic from the `Hexademical character reference start
|
|
121
|
-
* state` and `Numeric character reference end state` in the HTML spec.
|
|
122
|
-
*
|
|
123
|
-
* @param lastCp The last code point of the entity. Used to see if the
|
|
124
|
-
* entity was terminated with a semicolon.
|
|
125
|
-
* @param expectedLength The minimum number of characters that should be
|
|
126
|
-
* consumed. Used to validate that at least one digit
|
|
127
|
-
* was consumed.
|
|
128
|
-
* @returns The number of characters that were consumed.
|
|
129
|
-
*/
|
|
130
|
-
private emitNumericEntity;
|
|
131
|
-
/**
|
|
132
|
-
* Parses a named entity.
|
|
133
|
-
*
|
|
134
|
-
* Equivalent to the `Named character reference state` in the HTML spec.
|
|
135
|
-
*
|
|
136
|
-
* @param input The string containing the entity (or a continuation of the entity).
|
|
137
|
-
* @param offset The current offset.
|
|
138
|
-
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
139
|
-
*/
|
|
140
|
-
private stateNamedEntity;
|
|
141
|
-
/**
|
|
142
|
-
* Emit a named entity that was not terminated with a semicolon.
|
|
143
|
-
*
|
|
144
|
-
* @returns The number of characters consumed.
|
|
145
|
-
*/
|
|
146
|
-
private emitNotTerminatedNamedEntity;
|
|
147
|
-
/**
|
|
148
|
-
* Emit a named entity.
|
|
149
|
-
*
|
|
150
|
-
* @param result The index of the entity in the decode tree.
|
|
151
|
-
* @param valueLength The number of bytes in the entity.
|
|
152
|
-
* @param consumed The number of characters consumed.
|
|
153
|
-
*
|
|
154
|
-
* @returns The number of characters consumed.
|
|
155
|
-
*/
|
|
156
|
-
private emitNamedEntityData;
|
|
157
|
-
/**
|
|
158
|
-
* Signal to the parser that the end of the input was reached.
|
|
159
|
-
*
|
|
160
|
-
* Remaining data will be emitted and relevant errors will be produced.
|
|
161
|
-
*
|
|
162
|
-
* @returns The number of characters consumed.
|
|
163
|
-
*/
|
|
164
|
-
end(): number;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Determines the branch of the current node that is taken given the current
|
|
168
|
-
* character. This function is used to traverse the trie.
|
|
169
|
-
*
|
|
170
|
-
* @param decodeTree The trie.
|
|
171
|
-
* @param current The current node.
|
|
172
|
-
* @param nodeIdx The index right after the current node and its value.
|
|
173
|
-
* @param char The current character.
|
|
174
|
-
* @returns The index of the next node, or -1 if no branch is taken.
|
|
175
|
-
*/
|
|
176
|
-
export declare function determineBranch(decodeTree: Uint16Array, current: number, nodeIndex: number, char: number): number;
|
|
177
|
-
/**
|
|
178
|
-
* Decodes an HTML string.
|
|
179
|
-
*
|
|
180
|
-
* @param htmlString The string to decode.
|
|
181
|
-
* @param mode The decoding mode.
|
|
182
|
-
* @returns The decoded string.
|
|
183
|
-
*/
|
|
184
|
-
export declare function decodeHTML(htmlString: string, mode?: DecodingMode): string;
|
|
185
|
-
/**
|
|
186
|
-
* Decodes an HTML string in an attribute.
|
|
187
|
-
*
|
|
188
|
-
* @param htmlAttribute The string to decode.
|
|
189
|
-
* @returns The decoded string.
|
|
190
|
-
*/
|
|
191
|
-
export declare function decodeHTMLAttribute(htmlAttribute: string): string;
|
|
192
|
-
/**
|
|
193
|
-
* Decodes an HTML string, requiring all entities to be terminated by a semicolon.
|
|
194
|
-
*
|
|
195
|
-
* @param htmlString The string to decode.
|
|
196
|
-
* @returns The decoded string.
|
|
197
|
-
*/
|
|
198
|
-
export declare function decodeHTMLStrict(htmlString: string): string;
|
|
199
|
-
/**
|
|
200
|
-
* Decodes an XML string, requiring all entities to be terminated by a semicolon.
|
|
201
|
-
*
|
|
202
|
-
* @param xmlString The string to decode.
|
|
203
|
-
* @returns The decoded string.
|
|
204
|
-
*/
|
|
205
|
-
export declare function decodeXML(xmlString: string): string;
|
|
206
|
-
export { htmlDecodeTree } from './decode-data-html.js';
|
|
207
|
-
export { xmlDecodeTree } from './decode-data-xml.js';
|
|
208
|
-
export { decodeCodePoint, replaceCodePoint, fromCodePoint, } from './decode-codepoint.js';
|
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import { fromCodePoint, replaceCodePoint } from "./decode-codepoint.js";
|
|
2
|
-
import { htmlDecodeTree } from "./decode-data-html.js";
|
|
3
|
-
import { xmlDecodeTree } from "./decode-data-xml.js";
|
|
4
|
-
var CharCodes = /* @__PURE__ */ ((CharCodes2) => {
|
|
5
|
-
CharCodes2[CharCodes2["NUM"] = 35] = "NUM";
|
|
6
|
-
CharCodes2[CharCodes2["SEMI"] = 59] = "SEMI";
|
|
7
|
-
CharCodes2[CharCodes2["EQUALS"] = 61] = "EQUALS";
|
|
8
|
-
CharCodes2[CharCodes2["ZERO"] = 48] = "ZERO";
|
|
9
|
-
CharCodes2[CharCodes2["NINE"] = 57] = "NINE";
|
|
10
|
-
CharCodes2[CharCodes2["LOWER_A"] = 97] = "LOWER_A";
|
|
11
|
-
CharCodes2[CharCodes2["LOWER_F"] = 102] = "LOWER_F";
|
|
12
|
-
CharCodes2[CharCodes2["LOWER_X"] = 120] = "LOWER_X";
|
|
13
|
-
CharCodes2[CharCodes2["LOWER_Z"] = 122] = "LOWER_Z";
|
|
14
|
-
CharCodes2[CharCodes2["UPPER_A"] = 65] = "UPPER_A";
|
|
15
|
-
CharCodes2[CharCodes2["UPPER_F"] = 70] = "UPPER_F";
|
|
16
|
-
CharCodes2[CharCodes2["UPPER_Z"] = 90] = "UPPER_Z";
|
|
17
|
-
return CharCodes2;
|
|
18
|
-
})(CharCodes || {});
|
|
19
|
-
const TO_LOWER_BIT = 32;
|
|
20
|
-
var BinTrieFlags = /* @__PURE__ */ ((BinTrieFlags2) => {
|
|
21
|
-
BinTrieFlags2[BinTrieFlags2["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH";
|
|
22
|
-
BinTrieFlags2[BinTrieFlags2["BRANCH_LENGTH"] = 16256] = "BRANCH_LENGTH";
|
|
23
|
-
BinTrieFlags2[BinTrieFlags2["JUMP_TABLE"] = 127] = "JUMP_TABLE";
|
|
24
|
-
return BinTrieFlags2;
|
|
25
|
-
})(BinTrieFlags || {});
|
|
26
|
-
function isNumber(code) {
|
|
27
|
-
return code >= 48 /* ZERO */ && code <= 57 /* NINE */;
|
|
28
|
-
}
|
|
29
|
-
function isHexadecimalCharacter(code) {
|
|
30
|
-
return code >= 65 /* UPPER_A */ && code <= 70 /* UPPER_F */ || code >= 97 /* LOWER_A */ && code <= 102 /* LOWER_F */;
|
|
31
|
-
}
|
|
32
|
-
function isAsciiAlphaNumeric(code) {
|
|
33
|
-
return code >= 65 /* UPPER_A */ && code <= 90 /* UPPER_Z */ || code >= 97 /* LOWER_A */ && code <= 122 /* LOWER_Z */ || isNumber(code);
|
|
34
|
-
}
|
|
35
|
-
function isEntityInAttributeInvalidEnd(code) {
|
|
36
|
-
return code === 61 /* EQUALS */ || isAsciiAlphaNumeric(code);
|
|
37
|
-
}
|
|
38
|
-
var EntityDecoderState = /* @__PURE__ */ ((EntityDecoderState2) => {
|
|
39
|
-
EntityDecoderState2[EntityDecoderState2["EntityStart"] = 0] = "EntityStart";
|
|
40
|
-
EntityDecoderState2[EntityDecoderState2["NumericStart"] = 1] = "NumericStart";
|
|
41
|
-
EntityDecoderState2[EntityDecoderState2["NumericDecimal"] = 2] = "NumericDecimal";
|
|
42
|
-
EntityDecoderState2[EntityDecoderState2["NumericHex"] = 3] = "NumericHex";
|
|
43
|
-
EntityDecoderState2[EntityDecoderState2["NamedEntity"] = 4] = "NamedEntity";
|
|
44
|
-
return EntityDecoderState2;
|
|
45
|
-
})(EntityDecoderState || {});
|
|
46
|
-
var DecodingMode = /* @__PURE__ */ ((DecodingMode2) => {
|
|
47
|
-
DecodingMode2[DecodingMode2["Legacy"] = 0] = "Legacy";
|
|
48
|
-
DecodingMode2[DecodingMode2["Strict"] = 1] = "Strict";
|
|
49
|
-
DecodingMode2[DecodingMode2["Attribute"] = 2] = "Attribute";
|
|
50
|
-
return DecodingMode2;
|
|
51
|
-
})(DecodingMode || {});
|
|
52
|
-
class EntityDecoder {
|
|
53
|
-
constructor(decodeTree, emitCodePoint, errors) {
|
|
54
|
-
this.decodeTree = decodeTree;
|
|
55
|
-
this.emitCodePoint = emitCodePoint;
|
|
56
|
-
this.errors = errors;
|
|
57
|
-
}
|
|
58
|
-
/** The current state of the decoder. */
|
|
59
|
-
state = 0 /* EntityStart */;
|
|
60
|
-
/** Characters that were consumed while parsing an entity. */
|
|
61
|
-
consumed = 1;
|
|
62
|
-
/**
|
|
63
|
-
* The result of the entity.
|
|
64
|
-
*
|
|
65
|
-
* Either the result index of a numeric entity, or the codepoint of a
|
|
66
|
-
* numeric entity.
|
|
67
|
-
*/
|
|
68
|
-
result = 0;
|
|
69
|
-
/** The current index in the decode tree. */
|
|
70
|
-
treeIndex = 0;
|
|
71
|
-
/** The number of characters that were consumed in excess. */
|
|
72
|
-
excess = 1;
|
|
73
|
-
/** The mode in which the decoder is operating. */
|
|
74
|
-
decodeMode = 1 /* Strict */;
|
|
75
|
-
/** Resets the instance to make it reusable. */
|
|
76
|
-
startEntity(decodeMode) {
|
|
77
|
-
this.decodeMode = decodeMode;
|
|
78
|
-
this.state = 0 /* EntityStart */;
|
|
79
|
-
this.result = 0;
|
|
80
|
-
this.treeIndex = 0;
|
|
81
|
-
this.excess = 1;
|
|
82
|
-
this.consumed = 1;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Write an entity to the decoder. This can be called multiple times with partial entities.
|
|
86
|
-
* If the entity is incomplete, the decoder will return -1.
|
|
87
|
-
*
|
|
88
|
-
* Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
|
|
89
|
-
* entity is incomplete, and resume when the next string is written.
|
|
90
|
-
*
|
|
91
|
-
* @param input The string containing the entity (or a continuation of the entity).
|
|
92
|
-
* @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
|
|
93
|
-
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
94
|
-
*/
|
|
95
|
-
write(input, offset) {
|
|
96
|
-
switch (this.state) {
|
|
97
|
-
case 0 /* EntityStart */: {
|
|
98
|
-
if (input.charCodeAt(offset) === 35 /* NUM */) {
|
|
99
|
-
this.state = 1 /* NumericStart */;
|
|
100
|
-
this.consumed += 1;
|
|
101
|
-
return this.stateNumericStart(input, offset + 1);
|
|
102
|
-
}
|
|
103
|
-
this.state = 4 /* NamedEntity */;
|
|
104
|
-
return this.stateNamedEntity(input, offset);
|
|
105
|
-
}
|
|
106
|
-
case 1 /* NumericStart */: {
|
|
107
|
-
return this.stateNumericStart(input, offset);
|
|
108
|
-
}
|
|
109
|
-
case 2 /* NumericDecimal */: {
|
|
110
|
-
return this.stateNumericDecimal(input, offset);
|
|
111
|
-
}
|
|
112
|
-
case 3 /* NumericHex */: {
|
|
113
|
-
return this.stateNumericHex(input, offset);
|
|
114
|
-
}
|
|
115
|
-
case 4 /* NamedEntity */: {
|
|
116
|
-
return this.stateNamedEntity(input, offset);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Switches between the numeric decimal and hexadecimal states.
|
|
122
|
-
*
|
|
123
|
-
* Equivalent to the `Numeric character reference state` in the HTML spec.
|
|
124
|
-
*
|
|
125
|
-
* @param input The string containing the entity (or a continuation of the entity).
|
|
126
|
-
* @param offset The current offset.
|
|
127
|
-
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
128
|
-
*/
|
|
129
|
-
stateNumericStart(input, offset) {
|
|
130
|
-
if (offset >= input.length) {
|
|
131
|
-
return -1;
|
|
132
|
-
}
|
|
133
|
-
if ((input.charCodeAt(offset) | TO_LOWER_BIT) === 120 /* LOWER_X */) {
|
|
134
|
-
this.state = 3 /* NumericHex */;
|
|
135
|
-
this.consumed += 1;
|
|
136
|
-
return this.stateNumericHex(input, offset + 1);
|
|
137
|
-
}
|
|
138
|
-
this.state = 2 /* NumericDecimal */;
|
|
139
|
-
return this.stateNumericDecimal(input, offset);
|
|
140
|
-
}
|
|
141
|
-
addToNumericResult(input, start, end, base) {
|
|
142
|
-
if (start !== end) {
|
|
143
|
-
const digitCount = end - start;
|
|
144
|
-
this.result = this.result * base ** digitCount + Number.parseInt(input.substr(start, digitCount), base);
|
|
145
|
-
this.consumed += digitCount;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Parses a hexadecimal numeric entity.
|
|
150
|
-
*
|
|
151
|
-
* Equivalent to the `Hexademical character reference state` in the HTML spec.
|
|
152
|
-
*
|
|
153
|
-
* @param input The string containing the entity (or a continuation of the entity).
|
|
154
|
-
* @param offset The current offset.
|
|
155
|
-
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
156
|
-
*/
|
|
157
|
-
stateNumericHex(input, offset) {
|
|
158
|
-
const startIndex = offset;
|
|
159
|
-
while (offset < input.length) {
|
|
160
|
-
const char = input.charCodeAt(offset);
|
|
161
|
-
if (isNumber(char) || isHexadecimalCharacter(char)) {
|
|
162
|
-
offset += 1;
|
|
163
|
-
} else {
|
|
164
|
-
this.addToNumericResult(input, startIndex, offset, 16);
|
|
165
|
-
return this.emitNumericEntity(char, 3);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
this.addToNumericResult(input, startIndex, offset, 16);
|
|
169
|
-
return -1;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Parses a decimal numeric entity.
|
|
173
|
-
*
|
|
174
|
-
* Equivalent to the `Decimal character reference state` in the HTML spec.
|
|
175
|
-
*
|
|
176
|
-
* @param input The string containing the entity (or a continuation of the entity).
|
|
177
|
-
* @param offset The current offset.
|
|
178
|
-
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
179
|
-
*/
|
|
180
|
-
stateNumericDecimal(input, offset) {
|
|
181
|
-
const startIndex = offset;
|
|
182
|
-
while (offset < input.length) {
|
|
183
|
-
const char = input.charCodeAt(offset);
|
|
184
|
-
if (isNumber(char)) {
|
|
185
|
-
offset += 1;
|
|
186
|
-
} else {
|
|
187
|
-
this.addToNumericResult(input, startIndex, offset, 10);
|
|
188
|
-
return this.emitNumericEntity(char, 2);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
this.addToNumericResult(input, startIndex, offset, 10);
|
|
192
|
-
return -1;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Validate and emit a numeric entity.
|
|
196
|
-
*
|
|
197
|
-
* Implements the logic from the `Hexademical character reference start
|
|
198
|
-
* state` and `Numeric character reference end state` in the HTML spec.
|
|
199
|
-
*
|
|
200
|
-
* @param lastCp The last code point of the entity. Used to see if the
|
|
201
|
-
* entity was terminated with a semicolon.
|
|
202
|
-
* @param expectedLength The minimum number of characters that should be
|
|
203
|
-
* consumed. Used to validate that at least one digit
|
|
204
|
-
* was consumed.
|
|
205
|
-
* @returns The number of characters that were consumed.
|
|
206
|
-
*/
|
|
207
|
-
emitNumericEntity(lastCp, expectedLength) {
|
|
208
|
-
if (this.consumed <= expectedLength) {
|
|
209
|
-
this.errors?.absenceOfDigitsInNumericCharacterReference(this.consumed);
|
|
210
|
-
return 0;
|
|
211
|
-
}
|
|
212
|
-
if (lastCp === 59 /* SEMI */) {
|
|
213
|
-
this.consumed += 1;
|
|
214
|
-
} else if (this.decodeMode === 1 /* Strict */) {
|
|
215
|
-
return 0;
|
|
216
|
-
}
|
|
217
|
-
this.emitCodePoint(replaceCodePoint(this.result), this.consumed);
|
|
218
|
-
if (this.errors) {
|
|
219
|
-
if (lastCp !== 59 /* SEMI */) {
|
|
220
|
-
this.errors.missingSemicolonAfterCharacterReference();
|
|
221
|
-
}
|
|
222
|
-
this.errors.validateNumericCharacterReference(this.result);
|
|
223
|
-
}
|
|
224
|
-
return this.consumed;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Parses a named entity.
|
|
228
|
-
*
|
|
229
|
-
* Equivalent to the `Named character reference state` in the HTML spec.
|
|
230
|
-
*
|
|
231
|
-
* @param input The string containing the entity (or a continuation of the entity).
|
|
232
|
-
* @param offset The current offset.
|
|
233
|
-
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
|
234
|
-
*/
|
|
235
|
-
stateNamedEntity(input, offset) {
|
|
236
|
-
const { decodeTree } = this;
|
|
237
|
-
let current = decodeTree[this.treeIndex];
|
|
238
|
-
let valueLength = (current & 49152 /* VALUE_LENGTH */) >> 14;
|
|
239
|
-
for (; offset < input.length; offset++, this.excess++) {
|
|
240
|
-
const char = input.charCodeAt(offset);
|
|
241
|
-
this.treeIndex = determineBranch(
|
|
242
|
-
decodeTree,
|
|
243
|
-
current,
|
|
244
|
-
this.treeIndex + Math.max(1, valueLength),
|
|
245
|
-
char
|
|
246
|
-
);
|
|
247
|
-
if (this.treeIndex < 0) {
|
|
248
|
-
return this.result === 0 || // If we are parsing an attribute
|
|
249
|
-
this.decodeMode === 2 /* Attribute */ && // We shouldn't have consumed any characters after the entity,
|
|
250
|
-
(valueLength === 0 || // And there should be no invalid characters.
|
|
251
|
-
isEntityInAttributeInvalidEnd(char)) ? 0 : this.emitNotTerminatedNamedEntity();
|
|
252
|
-
}
|
|
253
|
-
current = decodeTree[this.treeIndex];
|
|
254
|
-
valueLength = (current & 49152 /* VALUE_LENGTH */) >> 14;
|
|
255
|
-
if (valueLength !== 0) {
|
|
256
|
-
if (char === 59 /* SEMI */) {
|
|
257
|
-
return this.emitNamedEntityData(this.treeIndex, valueLength, this.consumed + this.excess);
|
|
258
|
-
}
|
|
259
|
-
if (this.decodeMode !== 1 /* Strict */) {
|
|
260
|
-
this.result = this.treeIndex;
|
|
261
|
-
this.consumed += this.excess;
|
|
262
|
-
this.excess = 0;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return -1;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Emit a named entity that was not terminated with a semicolon.
|
|
270
|
-
*
|
|
271
|
-
* @returns The number of characters consumed.
|
|
272
|
-
*/
|
|
273
|
-
emitNotTerminatedNamedEntity() {
|
|
274
|
-
const { result, decodeTree } = this;
|
|
275
|
-
const valueLength = (decodeTree[result] & 49152 /* VALUE_LENGTH */) >> 14;
|
|
276
|
-
this.emitNamedEntityData(result, valueLength, this.consumed);
|
|
277
|
-
this.errors?.missingSemicolonAfterCharacterReference();
|
|
278
|
-
return this.consumed;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Emit a named entity.
|
|
282
|
-
*
|
|
283
|
-
* @param result The index of the entity in the decode tree.
|
|
284
|
-
* @param valueLength The number of bytes in the entity.
|
|
285
|
-
* @param consumed The number of characters consumed.
|
|
286
|
-
*
|
|
287
|
-
* @returns The number of characters consumed.
|
|
288
|
-
*/
|
|
289
|
-
emitNamedEntityData(result, valueLength, consumed) {
|
|
290
|
-
const { decodeTree } = this;
|
|
291
|
-
this.emitCodePoint(
|
|
292
|
-
valueLength === 1 ? decodeTree[result] & ~49152 /* VALUE_LENGTH */ : decodeTree[result + 1],
|
|
293
|
-
consumed
|
|
294
|
-
);
|
|
295
|
-
if (valueLength === 3) {
|
|
296
|
-
this.emitCodePoint(decodeTree[result + 2], consumed);
|
|
297
|
-
}
|
|
298
|
-
return consumed;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Signal to the parser that the end of the input was reached.
|
|
302
|
-
*
|
|
303
|
-
* Remaining data will be emitted and relevant errors will be produced.
|
|
304
|
-
*
|
|
305
|
-
* @returns The number of characters consumed.
|
|
306
|
-
*/
|
|
307
|
-
end() {
|
|
308
|
-
switch (this.state) {
|
|
309
|
-
case 4 /* NamedEntity */: {
|
|
310
|
-
return this.result !== 0 && (this.decodeMode !== 2 /* Attribute */ || this.result === this.treeIndex) ? this.emitNotTerminatedNamedEntity() : 0;
|
|
311
|
-
}
|
|
312
|
-
// Otherwise, emit a numeric entity if we have one.
|
|
313
|
-
case 2 /* NumericDecimal */: {
|
|
314
|
-
return this.emitNumericEntity(0, 2);
|
|
315
|
-
}
|
|
316
|
-
case 3 /* NumericHex */: {
|
|
317
|
-
return this.emitNumericEntity(0, 3);
|
|
318
|
-
}
|
|
319
|
-
case 1 /* NumericStart */: {
|
|
320
|
-
this.errors?.absenceOfDigitsInNumericCharacterReference(this.consumed);
|
|
321
|
-
return 0;
|
|
322
|
-
}
|
|
323
|
-
case 0 /* EntityStart */: {
|
|
324
|
-
return 0;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
function getDecoder(decodeTree) {
|
|
330
|
-
let returnValue = "";
|
|
331
|
-
const decoder = new EntityDecoder(decodeTree, (data) => returnValue += fromCodePoint(data));
|
|
332
|
-
return function decodeWithTrie(input, decodeMode) {
|
|
333
|
-
let lastIndex = 0;
|
|
334
|
-
let offset = 0;
|
|
335
|
-
while ((offset = input.indexOf("&", offset)) >= 0) {
|
|
336
|
-
returnValue += input.slice(lastIndex, offset);
|
|
337
|
-
decoder.startEntity(decodeMode);
|
|
338
|
-
const length = decoder.write(
|
|
339
|
-
input,
|
|
340
|
-
// Skip the "&"
|
|
341
|
-
offset + 1
|
|
342
|
-
);
|
|
343
|
-
if (length < 0) {
|
|
344
|
-
lastIndex = offset + decoder.end();
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
lastIndex = offset + length;
|
|
348
|
-
offset = length === 0 ? lastIndex + 1 : lastIndex;
|
|
349
|
-
}
|
|
350
|
-
const result = returnValue + input.slice(lastIndex);
|
|
351
|
-
returnValue = "";
|
|
352
|
-
return result;
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
function determineBranch(decodeTree, current, nodeIndex, char) {
|
|
356
|
-
const branchCount = (current & 16256 /* BRANCH_LENGTH */) >> 7;
|
|
357
|
-
const jumpOffset = current & 127 /* JUMP_TABLE */;
|
|
358
|
-
if (branchCount === 0) {
|
|
359
|
-
return jumpOffset !== 0 && char === jumpOffset ? nodeIndex : -1;
|
|
360
|
-
}
|
|
361
|
-
if (jumpOffset) {
|
|
362
|
-
const value = char - jumpOffset;
|
|
363
|
-
return value < 0 || value >= branchCount ? -1 : decodeTree[nodeIndex + value] - 1;
|
|
364
|
-
}
|
|
365
|
-
let lo = nodeIndex;
|
|
366
|
-
let hi = lo + branchCount - 1;
|
|
367
|
-
while (lo <= hi) {
|
|
368
|
-
const mid = lo + hi >>> 1;
|
|
369
|
-
const midValue = decodeTree[mid];
|
|
370
|
-
if (midValue < char) {
|
|
371
|
-
lo = mid + 1;
|
|
372
|
-
} else if (midValue > char) {
|
|
373
|
-
hi = mid - 1;
|
|
374
|
-
} else {
|
|
375
|
-
return decodeTree[mid + branchCount];
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return -1;
|
|
379
|
-
}
|
|
380
|
-
const htmlDecoder = /* @__PURE__ */ getDecoder(htmlDecodeTree);
|
|
381
|
-
const xmlDecoder = /* @__PURE__ */ getDecoder(xmlDecodeTree);
|
|
382
|
-
function decodeHTML(htmlString, mode = 0 /* Legacy */) {
|
|
383
|
-
return htmlDecoder(htmlString, mode);
|
|
384
|
-
}
|
|
385
|
-
function decodeHTMLAttribute(htmlAttribute) {
|
|
386
|
-
return htmlDecoder(htmlAttribute, 2 /* Attribute */);
|
|
387
|
-
}
|
|
388
|
-
function decodeHTMLStrict(htmlString) {
|
|
389
|
-
return htmlDecoder(htmlString, 1 /* Strict */);
|
|
390
|
-
}
|
|
391
|
-
function decodeXML(xmlString) {
|
|
392
|
-
return xmlDecoder(xmlString, 1 /* Strict */);
|
|
393
|
-
}
|
|
394
|
-
import { htmlDecodeTree as htmlDecodeTree2 } from "./decode-data-html.js";
|
|
395
|
-
import { xmlDecodeTree as xmlDecodeTree2 } from "./decode-data-xml.js";
|
|
396
|
-
import {
|
|
397
|
-
decodeCodePoint,
|
|
398
|
-
replaceCodePoint as replaceCodePoint2,
|
|
399
|
-
fromCodePoint as fromCodePoint2
|
|
400
|
-
} from "./decode-codepoint.js";
|
|
401
|
-
export {
|
|
402
|
-
BinTrieFlags,
|
|
403
|
-
DecodingMode,
|
|
404
|
-
EntityDecoder,
|
|
405
|
-
decodeCodePoint,
|
|
406
|
-
decodeHTML,
|
|
407
|
-
decodeHTMLAttribute,
|
|
408
|
-
decodeHTMLStrict,
|
|
409
|
-
decodeXML,
|
|
410
|
-
determineBranch,
|
|
411
|
-
fromCodePoint2 as fromCodePoint,
|
|
412
|
-
htmlDecodeTree2 as htmlDecodeTree,
|
|
413
|
-
replaceCodePoint2 as replaceCodePoint,
|
|
414
|
-
xmlDecodeTree2 as xmlDecodeTree
|
|
415
|
-
};
|