完成世界书、骰子、apiconfig页面处理
This commit is contained in:
209
frontend/node_modules/entities/dist/commonjs/decode.d.ts
generated
vendored
Normal file
209
frontend/node_modules/entities/dist/commonjs/decode.d.ts
generated
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
export declare enum BinTrieFlags {
|
||||
VALUE_LENGTH = 49152,
|
||||
BRANCH_LENGTH = 16256,
|
||||
JUMP_TABLE = 127
|
||||
}
|
||||
export declare enum DecodingMode {
|
||||
/** Entities in text nodes that can end with any character. */
|
||||
Legacy = 0,
|
||||
/** Only allow entities terminated with a semicolon. */
|
||||
Strict = 1,
|
||||
/** Entities in attributes have limitations on ending characters. */
|
||||
Attribute = 2
|
||||
}
|
||||
/**
|
||||
* Producers for character reference errors as defined in the HTML spec.
|
||||
*/
|
||||
export interface EntityErrorProducer {
|
||||
missingSemicolonAfterCharacterReference(): void;
|
||||
absenceOfDigitsInNumericCharacterReference(consumedCharacters: number): void;
|
||||
validateNumericCharacterReference(code: number): void;
|
||||
}
|
||||
/**
|
||||
* Token decoder with support of writing partial entities.
|
||||
*/
|
||||
export declare class EntityDecoder {
|
||||
/** The tree used to decode entities. */
|
||||
private readonly decodeTree;
|
||||
/**
|
||||
* The function that is called when a codepoint is decoded.
|
||||
*
|
||||
* For multi-byte named entities, this will be called multiple times,
|
||||
* with the second codepoint, and the same `consumed` value.
|
||||
*
|
||||
* @param codepoint The decoded codepoint.
|
||||
* @param consumed The number of bytes consumed by the decoder.
|
||||
*/
|
||||
private readonly emitCodePoint;
|
||||
/** An object that is used to produce errors. */
|
||||
private readonly errors?;
|
||||
constructor(
|
||||
/** The tree used to decode entities. */
|
||||
decodeTree: Uint16Array,
|
||||
/**
|
||||
* The function that is called when a codepoint is decoded.
|
||||
*
|
||||
* For multi-byte named entities, this will be called multiple times,
|
||||
* with the second codepoint, and the same `consumed` value.
|
||||
*
|
||||
* @param codepoint The decoded codepoint.
|
||||
* @param consumed The number of bytes consumed by the decoder.
|
||||
*/
|
||||
emitCodePoint: (cp: number, consumed: number) => void,
|
||||
/** An object that is used to produce errors. */
|
||||
errors?: EntityErrorProducer | undefined);
|
||||
/** The current state of the decoder. */
|
||||
private state;
|
||||
/** Characters that were consumed while parsing an entity. */
|
||||
private consumed;
|
||||
/**
|
||||
* The result of the entity.
|
||||
*
|
||||
* Either the result index of a numeric entity, or the codepoint of a
|
||||
* numeric entity.
|
||||
*/
|
||||
private result;
|
||||
/** The current index in the decode tree. */
|
||||
private treeIndex;
|
||||
/** The number of characters that were consumed in excess. */
|
||||
private excess;
|
||||
/** The mode in which the decoder is operating. */
|
||||
private decodeMode;
|
||||
/** Resets the instance to make it reusable. */
|
||||
startEntity(decodeMode: DecodingMode): void;
|
||||
/**
|
||||
* Write an entity to the decoder. This can be called multiple times with partial entities.
|
||||
* If the entity is incomplete, the decoder will return -1.
|
||||
*
|
||||
* Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
|
||||
* entity is incomplete, and resume when the next string is written.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
write(input: string, offset: number): number;
|
||||
/**
|
||||
* Switches between the numeric decimal and hexadecimal states.
|
||||
*
|
||||
* Equivalent to the `Numeric character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNumericStart;
|
||||
private addToNumericResult;
|
||||
/**
|
||||
* Parses a hexadecimal numeric entity.
|
||||
*
|
||||
* Equivalent to the `Hexademical character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNumericHex;
|
||||
/**
|
||||
* Parses a decimal numeric entity.
|
||||
*
|
||||
* Equivalent to the `Decimal character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNumericDecimal;
|
||||
/**
|
||||
* Validate and emit a numeric entity.
|
||||
*
|
||||
* Implements the logic from the `Hexademical character reference start
|
||||
* state` and `Numeric character reference end state` in the HTML spec.
|
||||
*
|
||||
* @param lastCp The last code point of the entity. Used to see if the
|
||||
* entity was terminated with a semicolon.
|
||||
* @param expectedLength The minimum number of characters that should be
|
||||
* consumed. Used to validate that at least one digit
|
||||
* was consumed.
|
||||
* @returns The number of characters that were consumed.
|
||||
*/
|
||||
private emitNumericEntity;
|
||||
/**
|
||||
* Parses a named entity.
|
||||
*
|
||||
* Equivalent to the `Named character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNamedEntity;
|
||||
/**
|
||||
* Emit a named entity that was not terminated with a semicolon.
|
||||
*
|
||||
* @returns The number of characters consumed.
|
||||
*/
|
||||
private emitNotTerminatedNamedEntity;
|
||||
/**
|
||||
* Emit a named entity.
|
||||
*
|
||||
* @param result The index of the entity in the decode tree.
|
||||
* @param valueLength The number of bytes in the entity.
|
||||
* @param consumed The number of characters consumed.
|
||||
*
|
||||
* @returns The number of characters consumed.
|
||||
*/
|
||||
private emitNamedEntityData;
|
||||
/**
|
||||
* Signal to the parser that the end of the input was reached.
|
||||
*
|
||||
* Remaining data will be emitted and relevant errors will be produced.
|
||||
*
|
||||
* @returns The number of characters consumed.
|
||||
*/
|
||||
end(): number;
|
||||
}
|
||||
/**
|
||||
* Determines the branch of the current node that is taken given the current
|
||||
* character. This function is used to traverse the trie.
|
||||
*
|
||||
* @param decodeTree The trie.
|
||||
* @param current The current node.
|
||||
* @param nodeIdx The index right after the current node and its value.
|
||||
* @param char The current character.
|
||||
* @returns The index of the next node, or -1 if no branch is taken.
|
||||
*/
|
||||
export declare function determineBranch(decodeTree: Uint16Array, current: number, nodeIndex: number, char: number): number;
|
||||
/**
|
||||
* Decodes an HTML string.
|
||||
*
|
||||
* @param htmlString The string to decode.
|
||||
* @param mode The decoding mode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export declare function decodeHTML(htmlString: string, mode?: DecodingMode): string;
|
||||
/**
|
||||
* Decodes an HTML string in an attribute.
|
||||
*
|
||||
* @param htmlAttribute The string to decode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export declare function decodeHTMLAttribute(htmlAttribute: string): string;
|
||||
/**
|
||||
* Decodes an HTML string, requiring all entities to be terminated by a semicolon.
|
||||
*
|
||||
* @param htmlString The string to decode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export declare function decodeHTMLStrict(htmlString: string): string;
|
||||
/**
|
||||
* Decodes an XML string, requiring all entities to be terminated by a semicolon.
|
||||
*
|
||||
* @param xmlString The string to decode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export declare function decodeXML(xmlString: string): string;
|
||||
export { htmlDecodeTree } from "./generated/decode-data-html.js";
|
||||
export { xmlDecodeTree } from "./generated/decode-data-xml.js";
|
||||
export { decodeCodePoint, replaceCodePoint, fromCodePoint, } from "./decode-codepoint.js";
|
||||
//# sourceMappingURL=decode.d.ts.map
|
||||
1
frontend/node_modules/entities/dist/commonjs/encode.js.map
generated
vendored
Normal file
1
frontend/node_modules/entities/dist/commonjs/encode.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/encode.ts"],"names":[],"mappings":";;AAgBA,gCAEC;AASD,gDAEC;AA7BD,+DAAsD;AACtD,2CAAwD;AAExD,MAAM,YAAY,GAAG,sCAAsC,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CAAC,KAAa;IACpC,OAAO,gBAAgB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;AACjD,CAAC;AACD;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAC,KAAa;IAC5C,OAAO,gBAAgB,CAAC,uBAAW,EAAE,KAAK,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAc,EAAE,KAAa;IACnD,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,KAAK,CAAC;IAEV,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC3C,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QACxB,WAAW,IAAI,KAAK,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACjD,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,IAAI,GAAG,yBAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAE9B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,kDAAkD;YAClD,IAAI,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC3B,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;gBAC7C,MAAM,KAAK,GACP,OAAO,IAAI,CAAC,CAAC,KAAK,QAAQ;oBACtB,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,QAAQ;wBACjB,CAAC,CAAC,IAAI,CAAC,CAAC;wBACR,CAAC,CAAC,SAAS;oBACf,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAE/B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBACtB,WAAW,IAAI,KAAK,CAAC;oBACrB,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;oBAClC,SAAS;gBACb,CAAC;YACL,CAAC;YAED,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,4EAA4E;QAC5E,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,MAAM,EAAE,GAAG,IAAA,wBAAY,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YACtC,WAAW,IAAI,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC;YACxC,4CAA4C;YAC5C,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC;QACxD,CAAC;aAAM,CAAC;YACJ,WAAW,IAAI,IAAI,CAAC;YACpB,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC;QAC1B,CAAC;IACL,CAAC;IAED,OAAO,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACjD,CAAC"}
|
||||
1
frontend/node_modules/entities/dist/commonjs/escape.d.ts.map
generated
vendored
Normal file
1
frontend/node_modules/entities/dist/commonjs/escape.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../../src/escape.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,EAAE,MAAiC,CAAC;AAW5D,eAAO,MAAM,YAAY,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAWoB,CAAC;AAE9E;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA0B/C;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,EAAE,OAAO,SAAqB,CAAC;AAqClD;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAG1C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAQ3C,CAAC;AAEN;;;;;GAKG;AACH,eAAO,MAAM,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAQ1C,CAAC"}
|
||||
13
frontend/node_modules/entities/dist/commonjs/generated/encode-html.js
generated
vendored
Normal file
13
frontend/node_modules/entities/dist/commonjs/generated/encode-html.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
3
frontend/node_modules/entities/dist/commonjs/package.json
generated
vendored
Normal file
3
frontend/node_modules/entities/dist/commonjs/package.json
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
19
frontend/node_modules/entities/dist/esm/decode-codepoint.d.ts
generated
vendored
Normal file
19
frontend/node_modules/entities/dist/esm/decode-codepoint.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point.
|
||||
*/
|
||||
export declare const fromCodePoint: (...codePoints: number[]) => string;
|
||||
/**
|
||||
* Replace the given code point with a replacement character if it is a
|
||||
* surrogate or is outside the valid range. Otherwise return the code
|
||||
* point unchanged.
|
||||
*/
|
||||
export declare function replaceCodePoint(codePoint: number): number;
|
||||
/**
|
||||
* Replace the code point if relevant, then convert it to a string.
|
||||
*
|
||||
* @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead.
|
||||
* @param codePoint The code point to decode.
|
||||
* @returns The decoded code point.
|
||||
*/
|
||||
export declare function decodeCodePoint(codePoint: number): string;
|
||||
//# sourceMappingURL=decode-codepoint.d.ts.map
|
||||
209
frontend/node_modules/entities/dist/esm/decode.d.ts
generated
vendored
Normal file
209
frontend/node_modules/entities/dist/esm/decode.d.ts
generated
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
export declare enum BinTrieFlags {
|
||||
VALUE_LENGTH = 49152,
|
||||
BRANCH_LENGTH = 16256,
|
||||
JUMP_TABLE = 127
|
||||
}
|
||||
export declare enum DecodingMode {
|
||||
/** Entities in text nodes that can end with any character. */
|
||||
Legacy = 0,
|
||||
/** Only allow entities terminated with a semicolon. */
|
||||
Strict = 1,
|
||||
/** Entities in attributes have limitations on ending characters. */
|
||||
Attribute = 2
|
||||
}
|
||||
/**
|
||||
* Producers for character reference errors as defined in the HTML spec.
|
||||
*/
|
||||
export interface EntityErrorProducer {
|
||||
missingSemicolonAfterCharacterReference(): void;
|
||||
absenceOfDigitsInNumericCharacterReference(consumedCharacters: number): void;
|
||||
validateNumericCharacterReference(code: number): void;
|
||||
}
|
||||
/**
|
||||
* Token decoder with support of writing partial entities.
|
||||
*/
|
||||
export declare class EntityDecoder {
|
||||
/** The tree used to decode entities. */
|
||||
private readonly decodeTree;
|
||||
/**
|
||||
* The function that is called when a codepoint is decoded.
|
||||
*
|
||||
* For multi-byte named entities, this will be called multiple times,
|
||||
* with the second codepoint, and the same `consumed` value.
|
||||
*
|
||||
* @param codepoint The decoded codepoint.
|
||||
* @param consumed The number of bytes consumed by the decoder.
|
||||
*/
|
||||
private readonly emitCodePoint;
|
||||
/** An object that is used to produce errors. */
|
||||
private readonly errors?;
|
||||
constructor(
|
||||
/** The tree used to decode entities. */
|
||||
decodeTree: Uint16Array,
|
||||
/**
|
||||
* The function that is called when a codepoint is decoded.
|
||||
*
|
||||
* For multi-byte named entities, this will be called multiple times,
|
||||
* with the second codepoint, and the same `consumed` value.
|
||||
*
|
||||
* @param codepoint The decoded codepoint.
|
||||
* @param consumed The number of bytes consumed by the decoder.
|
||||
*/
|
||||
emitCodePoint: (cp: number, consumed: number) => void,
|
||||
/** An object that is used to produce errors. */
|
||||
errors?: EntityErrorProducer | undefined);
|
||||
/** The current state of the decoder. */
|
||||
private state;
|
||||
/** Characters that were consumed while parsing an entity. */
|
||||
private consumed;
|
||||
/**
|
||||
* The result of the entity.
|
||||
*
|
||||
* Either the result index of a numeric entity, or the codepoint of a
|
||||
* numeric entity.
|
||||
*/
|
||||
private result;
|
||||
/** The current index in the decode tree. */
|
||||
private treeIndex;
|
||||
/** The number of characters that were consumed in excess. */
|
||||
private excess;
|
||||
/** The mode in which the decoder is operating. */
|
||||
private decodeMode;
|
||||
/** Resets the instance to make it reusable. */
|
||||
startEntity(decodeMode: DecodingMode): void;
|
||||
/**
|
||||
* Write an entity to the decoder. This can be called multiple times with partial entities.
|
||||
* If the entity is incomplete, the decoder will return -1.
|
||||
*
|
||||
* Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
|
||||
* entity is incomplete, and resume when the next string is written.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
write(input: string, offset: number): number;
|
||||
/**
|
||||
* Switches between the numeric decimal and hexadecimal states.
|
||||
*
|
||||
* Equivalent to the `Numeric character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNumericStart;
|
||||
private addToNumericResult;
|
||||
/**
|
||||
* Parses a hexadecimal numeric entity.
|
||||
*
|
||||
* Equivalent to the `Hexademical character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNumericHex;
|
||||
/**
|
||||
* Parses a decimal numeric entity.
|
||||
*
|
||||
* Equivalent to the `Decimal character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNumericDecimal;
|
||||
/**
|
||||
* Validate and emit a numeric entity.
|
||||
*
|
||||
* Implements the logic from the `Hexademical character reference start
|
||||
* state` and `Numeric character reference end state` in the HTML spec.
|
||||
*
|
||||
* @param lastCp The last code point of the entity. Used to see if the
|
||||
* entity was terminated with a semicolon.
|
||||
* @param expectedLength The minimum number of characters that should be
|
||||
* consumed. Used to validate that at least one digit
|
||||
* was consumed.
|
||||
* @returns The number of characters that were consumed.
|
||||
*/
|
||||
private emitNumericEntity;
|
||||
/**
|
||||
* Parses a named entity.
|
||||
*
|
||||
* Equivalent to the `Named character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNamedEntity;
|
||||
/**
|
||||
* Emit a named entity that was not terminated with a semicolon.
|
||||
*
|
||||
* @returns The number of characters consumed.
|
||||
*/
|
||||
private emitNotTerminatedNamedEntity;
|
||||
/**
|
||||
* Emit a named entity.
|
||||
*
|
||||
* @param result The index of the entity in the decode tree.
|
||||
* @param valueLength The number of bytes in the entity.
|
||||
* @param consumed The number of characters consumed.
|
||||
*
|
||||
* @returns The number of characters consumed.
|
||||
*/
|
||||
private emitNamedEntityData;
|
||||
/**
|
||||
* Signal to the parser that the end of the input was reached.
|
||||
*
|
||||
* Remaining data will be emitted and relevant errors will be produced.
|
||||
*
|
||||
* @returns The number of characters consumed.
|
||||
*/
|
||||
end(): number;
|
||||
}
|
||||
/**
|
||||
* Determines the branch of the current node that is taken given the current
|
||||
* character. This function is used to traverse the trie.
|
||||
*
|
||||
* @param decodeTree The trie.
|
||||
* @param current The current node.
|
||||
* @param nodeIdx The index right after the current node and its value.
|
||||
* @param char The current character.
|
||||
* @returns The index of the next node, or -1 if no branch is taken.
|
||||
*/
|
||||
export declare function determineBranch(decodeTree: Uint16Array, current: number, nodeIndex: number, char: number): number;
|
||||
/**
|
||||
* Decodes an HTML string.
|
||||
*
|
||||
* @param htmlString The string to decode.
|
||||
* @param mode The decoding mode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export declare function decodeHTML(htmlString: string, mode?: DecodingMode): string;
|
||||
/**
|
||||
* Decodes an HTML string in an attribute.
|
||||
*
|
||||
* @param htmlAttribute The string to decode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export declare function decodeHTMLAttribute(htmlAttribute: string): string;
|
||||
/**
|
||||
* Decodes an HTML string, requiring all entities to be terminated by a semicolon.
|
||||
*
|
||||
* @param htmlString The string to decode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export declare function decodeHTMLStrict(htmlString: string): string;
|
||||
/**
|
||||
* Decodes an XML string, requiring all entities to be terminated by a semicolon.
|
||||
*
|
||||
* @param xmlString The string to decode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export declare function decodeXML(xmlString: string): string;
|
||||
export { htmlDecodeTree } from "./generated/decode-data-html.js";
|
||||
export { xmlDecodeTree } from "./generated/decode-data-xml.js";
|
||||
export { decodeCodePoint, replaceCodePoint, fromCodePoint, } from "./decode-codepoint.js";
|
||||
//# sourceMappingURL=decode.d.ts.map
|
||||
1
frontend/node_modules/entities/dist/esm/encode.d.ts.map
generated
vendored
Normal file
1
frontend/node_modules/entities/dist/esm/encode.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/encode.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AACD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
||||
1
frontend/node_modules/entities/dist/esm/generated/decode-data-html.js.map
generated
vendored
Normal file
1
frontend/node_modules/entities/dist/esm/generated/decode-data-html.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"decode-data-html.js","sourceRoot":"","sources":["../../../src/generated/decode-data-html.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAE9C,MAAM,CAAC,MAAM,cAAc,GAAgB,eAAe,CAAC,IAAI,WAAW;AACtE,kBAAkB;AAClB,eAAe,CAAC,268CAA268C;KACt78C,KAAK,CAAC,EAAE,CAAC;KACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CACnC,CAAC"}
|
||||
1
frontend/node_modules/entities/dist/esm/index.js.map
generated
vendored
Normal file
1
frontend/node_modules/entities/dist/esm/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EACH,SAAS,EACT,UAAU,EACV,eAAe,EACf,UAAU,GACb,MAAM,aAAa,CAAC;AAErB,wCAAwC;AACxC,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACnB,iCAAiC;IACjC,2CAAO,CAAA;IACP,mEAAmE;IACnE,6CAAQ,CAAA;AACZ,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB;AAED,MAAM,CAAN,IAAY,YA2BX;AA3BD,WAAY,YAAY;IACpB;;;OAGG;IACH,+CAAI,CAAA;IACJ;;;;OAIG;IACH,iDAAK,CAAA;IACL;;;OAGG;IACH,yDAAS,CAAA;IACT;;;OAGG;IACH,yDAAS,CAAA;IACT;;;OAGG;IACH,+CAAI,CAAA;AACR,CAAC,EA3BW,YAAY,KAAZ,YAAY,QA2BvB;AAsBD;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAClB,KAAa,EACb,UAAyC,WAAW,CAAC,GAAG;IAExD,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IAEpE,IAAI,KAAK,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QACpE,OAAO,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CACxB,KAAa,EACb,UAAyC,WAAW,CAAC,GAAG;;IAExD,MAAM,iBAAiB,GACnB,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/D,MAAA,iBAAiB,CAAC,IAAI,oCAAtB,iBAAiB,CAAC,IAAI,GAAK,YAAY,CAAC,MAAM,EAAC;IAE/C,OAAO,MAAM,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;AAC5C,CAAC;AAkBD;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAClB,KAAa,EACb,UAAyC,WAAW,CAAC,GAAG;IAExD,MAAM,EAAE,IAAI,GAAG,YAAY,CAAC,SAAS,EAAE,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,GAC5D,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAE/D,QAAQ,IAAI,EAAE,CAAC;QACX,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;YACrB,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;QACD,KAAK,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;YAC1B,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QACD,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;YACrB,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;QACD,KAAK,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;YACtB,OAAO,KAAK,KAAK,WAAW,CAAC,IAAI;gBAC7B,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC;gBAC3B,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;QACD,0DAA0D;QAC1D,KAAK,YAAY,CAAC,SAAS,CAAC;QAC5B,OAAO,CAAC,CAAC,CAAC;YACN,OAAO,KAAK,KAAK,WAAW,CAAC,IAAI;gBAC7B,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;gBACnB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;AACL,CAAC;AAED,OAAO,EACH,SAAS,EACT,MAAM,EACN,UAAU,EACV,eAAe,EACf,UAAU,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EACH,UAAU,EACV,kBAAkB;AAClB,8BAA8B;AAC9B,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,GAC5B,MAAM,aAAa,CAAC;AAErB,OAAO,EACH,aAAa,EACb,YAAY,EACZ,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,mBAAmB;AACnB,8BAA8B;AAC9B,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,EACzB,gBAAgB,IAAI,iBAAiB,EACrC,gBAAgB,IAAI,iBAAiB,EACrC,SAAS,IAAI,eAAe,GAC/B,MAAM,aAAa,CAAC"}
|
||||
3
frontend/node_modules/entities/dist/esm/package.json
generated
vendored
Normal file
3
frontend/node_modules/entities/dist/esm/package.json
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
320
frontend/node_modules/entities/src/decode.spec.ts
generated
vendored
Normal file
320
frontend/node_modules/entities/src/decode.spec.ts
generated
vendored
Normal file
@@ -0,0 +1,320 @@
|
||||
import { describe, it, expect, vitest } from "vitest";
|
||||
import * as entities from "./decode.js";
|
||||
|
||||
describe("Decode test", () => {
|
||||
const testcases = [
|
||||
{ input: "&", output: "&" },
|
||||
{ input: "&", output: "&" },
|
||||
{ input: "&", output: "&" },
|
||||
{ input: "&", output: "&" },
|
||||
{ input: "&", output: "&" },
|
||||
{ input: "&", output: "&" },
|
||||
{ input: "&", output: "&" },
|
||||
{ input: ":", output: ":" },
|
||||
{ input: ":", output: ":" },
|
||||
{ input: ":", output: ":" },
|
||||
{ input: ":", output: ":" },
|
||||
{ input: "&#", output: "&#" },
|
||||
{ input: "&>", output: "&>" },
|
||||
{ input: "id=770&#anchor", output: "id=770&#anchor" },
|
||||
];
|
||||
|
||||
for (const { input, output } of testcases) {
|
||||
it(`should XML decode ${input}`, () =>
|
||||
expect(entities.decodeXML(input)).toBe(output));
|
||||
it(`should HTML decode ${input}`, () =>
|
||||
expect(entities.decodeHTML(input)).toBe(output));
|
||||
}
|
||||
|
||||
it("should HTML decode partial legacy entity", () => {
|
||||
expect(entities.decodeHTMLStrict("×bar")).toBe("×bar");
|
||||
expect(entities.decodeHTML("×bar")).toBe("×bar");
|
||||
});
|
||||
|
||||
it("should HTML decode legacy entities according to spec", () =>
|
||||
expect(entities.decodeHTML("?&image_uri=1&ℑ=2&image=3")).toBe(
|
||||
"?&image_uri=1&ℑ=2&image=3",
|
||||
));
|
||||
|
||||
it("should back out of legacy entities", () =>
|
||||
expect(entities.decodeHTML("&a")).toBe("&a"));
|
||||
|
||||
it("should not parse numeric entities in strict mode", () =>
|
||||
expect(entities.decodeHTMLStrict("7")).toBe("7"));
|
||||
|
||||
it("should parse   followed by < (#852)", () =>
|
||||
expect(entities.decodeHTML(" <")).toBe("\u00A0<"));
|
||||
|
||||
it("should decode trailing legacy entities", () => {
|
||||
expect(entities.decodeHTML("⨱×bar")).toBe("⨱×bar");
|
||||
});
|
||||
|
||||
it("should decode multi-byte entities", () => {
|
||||
expect(entities.decodeHTML("≧̸")).toBe("≧̸");
|
||||
});
|
||||
|
||||
it("should not decode legacy entities followed by text in attribute mode", () => {
|
||||
expect(
|
||||
entities.decodeHTML("¬", entities.DecodingMode.Attribute),
|
||||
).toBe("¬");
|
||||
|
||||
expect(
|
||||
entities.decodeHTML("¬i", entities.DecodingMode.Attribute),
|
||||
).toBe("¬i");
|
||||
|
||||
expect(
|
||||
entities.decodeHTML("¬=", entities.DecodingMode.Attribute),
|
||||
).toBe("¬=");
|
||||
|
||||
expect(entities.decodeHTMLAttribute("¬p")).toBe("¬p");
|
||||
expect(entities.decodeHTMLAttribute("¬P")).toBe("¬P");
|
||||
expect(entities.decodeHTMLAttribute("¬3")).toBe("¬3");
|
||||
});
|
||||
});
|
||||
|
||||
describe("EntityDecoder", () => {
|
||||
it("should decode decimal entities", () => {
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
);
|
||||
|
||||
expect(decoder.write("", 1)).toBe(-1);
|
||||
expect(decoder.write("8;", 0)).toBe(5);
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
expect(callback).toHaveBeenCalledWith(":".charCodeAt(0), 5);
|
||||
});
|
||||
|
||||
it("should decode hex entities", () => {
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
);
|
||||
|
||||
expect(decoder.write(":", 1)).toBe(6);
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
expect(callback).toHaveBeenCalledWith(":".charCodeAt(0), 6);
|
||||
});
|
||||
|
||||
it("should decode named entities", () => {
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
);
|
||||
|
||||
expect(decoder.write("&", 1)).toBe(5);
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
expect(callback).toHaveBeenCalledWith("&".charCodeAt(0), 5);
|
||||
});
|
||||
|
||||
it("should decode legacy entities", () => {
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
);
|
||||
decoder.startEntity(entities.DecodingMode.Legacy);
|
||||
|
||||
expect(decoder.write("&", 1)).toBe(-1);
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(decoder.end()).toBe(4);
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
expect(callback).toHaveBeenCalledWith("&".charCodeAt(0), 4);
|
||||
});
|
||||
|
||||
it("should decode named entity written character by character", () => {
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
);
|
||||
|
||||
for (const c of "amp") {
|
||||
expect(decoder.write(c, 0)).toBe(-1);
|
||||
}
|
||||
expect(decoder.write(";", 0)).toBe(5);
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
expect(callback).toHaveBeenCalledWith("&".charCodeAt(0), 5);
|
||||
});
|
||||
|
||||
it("should decode numeric entity written character by character", () => {
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
);
|
||||
|
||||
for (const c of "#x3a") {
|
||||
expect(decoder.write(c, 0)).toBe(-1);
|
||||
}
|
||||
expect(decoder.write(";", 0)).toBe(6);
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
expect(callback).toHaveBeenCalledWith(":".charCodeAt(0), 6);
|
||||
});
|
||||
|
||||
it("should decode hex entities across several chunks", () => {
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
);
|
||||
|
||||
for (const chunk of ["#x", "cf", "ff", "d"]) {
|
||||
expect(decoder.write(chunk, 0)).toBe(-1);
|
||||
}
|
||||
|
||||
expect(decoder.write(";", 0)).toBe(9);
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
expect(callback).toHaveBeenCalledWith(0xc_ff_fd, 9);
|
||||
});
|
||||
|
||||
it("should not fail if nothing is written", () => {
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
);
|
||||
|
||||
expect(decoder.end()).toBe(0);
|
||||
expect(callback).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
it("should produce an error for a named entity without a semicolon", () => {
|
||||
const errorHandlers = {
|
||||
missingSemicolonAfterCharacterReference: vitest.fn(),
|
||||
absenceOfDigitsInNumericCharacterReference: vitest.fn(),
|
||||
validateNumericCharacterReference: vitest.fn(),
|
||||
};
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
errorHandlers,
|
||||
);
|
||||
|
||||
decoder.startEntity(entities.DecodingMode.Legacy);
|
||||
expect(decoder.write("&", 1)).toBe(5);
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
expect(callback).toHaveBeenCalledWith("&".charCodeAt(0), 5);
|
||||
expect(
|
||||
errorHandlers.missingSemicolonAfterCharacterReference,
|
||||
).toHaveBeenCalledTimes(0);
|
||||
|
||||
decoder.startEntity(entities.DecodingMode.Legacy);
|
||||
expect(decoder.write("&", 1)).toBe(-1);
|
||||
expect(decoder.end()).toBe(4);
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(2);
|
||||
expect(callback).toHaveBeenLastCalledWith("&".charCodeAt(0), 4);
|
||||
expect(
|
||||
errorHandlers.missingSemicolonAfterCharacterReference,
|
||||
).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("should produce an error for a numeric entity without a semicolon", () => {
|
||||
const errorHandlers = {
|
||||
missingSemicolonAfterCharacterReference: vitest.fn(),
|
||||
absenceOfDigitsInNumericCharacterReference: vitest.fn(),
|
||||
validateNumericCharacterReference: vitest.fn(),
|
||||
};
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
errorHandlers,
|
||||
);
|
||||
|
||||
decoder.startEntity(entities.DecodingMode.Legacy);
|
||||
expect(decoder.write(":", 1)).toBe(-1);
|
||||
expect(decoder.end()).toBe(5);
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
expect(callback).toHaveBeenCalledWith(0x3a, 5);
|
||||
expect(
|
||||
errorHandlers.missingSemicolonAfterCharacterReference,
|
||||
).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
errorHandlers.absenceOfDigitsInNumericCharacterReference,
|
||||
).toHaveBeenCalledTimes(0);
|
||||
expect(
|
||||
errorHandlers.validateNumericCharacterReference,
|
||||
).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
errorHandlers.validateNumericCharacterReference,
|
||||
).toHaveBeenCalledWith(0x3a);
|
||||
});
|
||||
|
||||
it("should produce an error for numeric entities without digits", () => {
|
||||
const errorHandlers = {
|
||||
missingSemicolonAfterCharacterReference: vitest.fn(),
|
||||
absenceOfDigitsInNumericCharacterReference: vitest.fn(),
|
||||
validateNumericCharacterReference: vitest.fn(),
|
||||
};
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
errorHandlers,
|
||||
);
|
||||
|
||||
decoder.startEntity(entities.DecodingMode.Legacy);
|
||||
expect(decoder.write("&#", 1)).toBe(-1);
|
||||
expect(decoder.end()).toBe(0);
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(0);
|
||||
expect(
|
||||
errorHandlers.missingSemicolonAfterCharacterReference,
|
||||
).toHaveBeenCalledTimes(0);
|
||||
expect(
|
||||
errorHandlers.absenceOfDigitsInNumericCharacterReference,
|
||||
).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
errorHandlers.absenceOfDigitsInNumericCharacterReference,
|
||||
).toHaveBeenCalledWith(2);
|
||||
expect(
|
||||
errorHandlers.validateNumericCharacterReference,
|
||||
).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it("should produce an error for hex entities without digits", () => {
|
||||
const errorHandlers = {
|
||||
missingSemicolonAfterCharacterReference: vitest.fn(),
|
||||
absenceOfDigitsInNumericCharacterReference: vitest.fn(),
|
||||
validateNumericCharacterReference: vitest.fn(),
|
||||
};
|
||||
const callback = vitest.fn();
|
||||
const decoder = new entities.EntityDecoder(
|
||||
entities.htmlDecodeTree,
|
||||
callback,
|
||||
errorHandlers,
|
||||
);
|
||||
|
||||
decoder.startEntity(entities.DecodingMode.Legacy);
|
||||
expect(decoder.write("&#x", 1)).toBe(-1);
|
||||
expect(decoder.end()).toBe(0);
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(0);
|
||||
expect(
|
||||
errorHandlers.missingSemicolonAfterCharacterReference,
|
||||
).toHaveBeenCalledTimes(0);
|
||||
expect(
|
||||
errorHandlers.absenceOfDigitsInNumericCharacterReference,
|
||||
).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
errorHandlers.validateNumericCharacterReference,
|
||||
).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
620
frontend/node_modules/entities/src/decode.ts
generated
vendored
Normal file
620
frontend/node_modules/entities/src/decode.ts
generated
vendored
Normal file
@@ -0,0 +1,620 @@
|
||||
import { htmlDecodeTree } from "./generated/decode-data-html.js";
|
||||
import { xmlDecodeTree } from "./generated/decode-data-xml.js";
|
||||
import { replaceCodePoint, fromCodePoint } from "./decode-codepoint.js";
|
||||
|
||||
const enum CharCodes {
|
||||
NUM = 35, // "#"
|
||||
SEMI = 59, // ";"
|
||||
EQUALS = 61, // "="
|
||||
ZERO = 48, // "0"
|
||||
NINE = 57, // "9"
|
||||
LOWER_A = 97, // "a"
|
||||
LOWER_F = 102, // "f"
|
||||
LOWER_X = 120, // "x"
|
||||
LOWER_Z = 122, // "z"
|
||||
UPPER_A = 65, // "A"
|
||||
UPPER_F = 70, // "F"
|
||||
UPPER_Z = 90, // "Z"
|
||||
}
|
||||
|
||||
/** Bit that needs to be set to convert an upper case ASCII character to lower case */
|
||||
const TO_LOWER_BIT = 0b10_0000;
|
||||
|
||||
export enum BinTrieFlags {
|
||||
VALUE_LENGTH = 0b1100_0000_0000_0000,
|
||||
BRANCH_LENGTH = 0b0011_1111_1000_0000,
|
||||
JUMP_TABLE = 0b0000_0000_0111_1111,
|
||||
}
|
||||
|
||||
function isNumber(code: number): boolean {
|
||||
return code >= CharCodes.ZERO && code <= CharCodes.NINE;
|
||||
}
|
||||
|
||||
function isHexadecimalCharacter(code: number): boolean {
|
||||
return (
|
||||
(code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F) ||
|
||||
(code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F)
|
||||
);
|
||||
}
|
||||
|
||||
function isAsciiAlphaNumeric(code: number): boolean {
|
||||
return (
|
||||
(code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z) ||
|
||||
(code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z) ||
|
||||
isNumber(code)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given character is a valid end character for an entity in an attribute.
|
||||
*
|
||||
* Attribute values that aren't terminated properly aren't parsed, and shouldn't lead to a parser error.
|
||||
* See the example in https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state
|
||||
*/
|
||||
function isEntityInAttributeInvalidEnd(code: number): boolean {
|
||||
return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code);
|
||||
}
|
||||
|
||||
const enum EntityDecoderState {
|
||||
EntityStart,
|
||||
NumericStart,
|
||||
NumericDecimal,
|
||||
NumericHex,
|
||||
NamedEntity,
|
||||
}
|
||||
|
||||
export enum DecodingMode {
|
||||
/** Entities in text nodes that can end with any character. */
|
||||
Legacy = 0,
|
||||
/** Only allow entities terminated with a semicolon. */
|
||||
Strict = 1,
|
||||
/** Entities in attributes have limitations on ending characters. */
|
||||
Attribute = 2,
|
||||
}
|
||||
|
||||
/**
|
||||
* Producers for character reference errors as defined in the HTML spec.
|
||||
*/
|
||||
export interface EntityErrorProducer {
|
||||
missingSemicolonAfterCharacterReference(): void;
|
||||
absenceOfDigitsInNumericCharacterReference(
|
||||
consumedCharacters: number,
|
||||
): void;
|
||||
validateNumericCharacterReference(code: number): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Token decoder with support of writing partial entities.
|
||||
*/
|
||||
export class EntityDecoder {
|
||||
constructor(
|
||||
/** The tree used to decode entities. */
|
||||
private readonly decodeTree: Uint16Array,
|
||||
/**
|
||||
* The function that is called when a codepoint is decoded.
|
||||
*
|
||||
* For multi-byte named entities, this will be called multiple times,
|
||||
* with the second codepoint, and the same `consumed` value.
|
||||
*
|
||||
* @param codepoint The decoded codepoint.
|
||||
* @param consumed The number of bytes consumed by the decoder.
|
||||
*/
|
||||
private readonly emitCodePoint: (cp: number, consumed: number) => void,
|
||||
/** An object that is used to produce errors. */
|
||||
private readonly errors?: EntityErrorProducer | undefined,
|
||||
) {}
|
||||
|
||||
/** The current state of the decoder. */
|
||||
private state = EntityDecoderState.EntityStart;
|
||||
/** Characters that were consumed while parsing an entity. */
|
||||
private consumed = 1;
|
||||
/**
|
||||
* The result of the entity.
|
||||
*
|
||||
* Either the result index of a numeric entity, or the codepoint of a
|
||||
* numeric entity.
|
||||
*/
|
||||
private result = 0;
|
||||
|
||||
/** The current index in the decode tree. */
|
||||
private treeIndex = 0;
|
||||
/** The number of characters that were consumed in excess. */
|
||||
private excess = 1;
|
||||
/** The mode in which the decoder is operating. */
|
||||
private decodeMode = DecodingMode.Strict;
|
||||
|
||||
/** Resets the instance to make it reusable. */
|
||||
startEntity(decodeMode: DecodingMode): void {
|
||||
this.decodeMode = decodeMode;
|
||||
this.state = EntityDecoderState.EntityStart;
|
||||
this.result = 0;
|
||||
this.treeIndex = 0;
|
||||
this.excess = 1;
|
||||
this.consumed = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an entity to the decoder. This can be called multiple times with partial entities.
|
||||
* If the entity is incomplete, the decoder will return -1.
|
||||
*
|
||||
* Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
|
||||
* entity is incomplete, and resume when the next string is written.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
write(input: string, offset: number): number {
|
||||
switch (this.state) {
|
||||
case EntityDecoderState.EntityStart: {
|
||||
if (input.charCodeAt(offset) === CharCodes.NUM) {
|
||||
this.state = EntityDecoderState.NumericStart;
|
||||
this.consumed += 1;
|
||||
return this.stateNumericStart(input, offset + 1);
|
||||
}
|
||||
this.state = EntityDecoderState.NamedEntity;
|
||||
return this.stateNamedEntity(input, offset);
|
||||
}
|
||||
|
||||
case EntityDecoderState.NumericStart: {
|
||||
return this.stateNumericStart(input, offset);
|
||||
}
|
||||
|
||||
case EntityDecoderState.NumericDecimal: {
|
||||
return this.stateNumericDecimal(input, offset);
|
||||
}
|
||||
|
||||
case EntityDecoderState.NumericHex: {
|
||||
return this.stateNumericHex(input, offset);
|
||||
}
|
||||
|
||||
case EntityDecoderState.NamedEntity: {
|
||||
return this.stateNamedEntity(input, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches between the numeric decimal and hexadecimal states.
|
||||
*
|
||||
* Equivalent to the `Numeric character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNumericStart(input: string, offset: number): number {
|
||||
if (offset >= input.length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((input.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) {
|
||||
this.state = EntityDecoderState.NumericHex;
|
||||
this.consumed += 1;
|
||||
return this.stateNumericHex(input, offset + 1);
|
||||
}
|
||||
|
||||
this.state = EntityDecoderState.NumericDecimal;
|
||||
return this.stateNumericDecimal(input, offset);
|
||||
}
|
||||
|
||||
private addToNumericResult(
|
||||
input: string,
|
||||
start: number,
|
||||
end: number,
|
||||
base: number,
|
||||
): void {
|
||||
if (start !== end) {
|
||||
const digitCount = end - start;
|
||||
this.result =
|
||||
this.result * Math.pow(base, digitCount) +
|
||||
Number.parseInt(input.substr(start, digitCount), base);
|
||||
this.consumed += digitCount;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a hexadecimal numeric entity.
|
||||
*
|
||||
* Equivalent to the `Hexademical character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNumericHex(input: string, offset: number): number {
|
||||
const startIndex = offset;
|
||||
|
||||
while (offset < input.length) {
|
||||
const char = input.charCodeAt(offset);
|
||||
if (isNumber(char) || isHexadecimalCharacter(char)) {
|
||||
offset += 1;
|
||||
} else {
|
||||
this.addToNumericResult(input, startIndex, offset, 16);
|
||||
return this.emitNumericEntity(char, 3);
|
||||
}
|
||||
}
|
||||
|
||||
this.addToNumericResult(input, startIndex, offset, 16);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a decimal numeric entity.
|
||||
*
|
||||
* Equivalent to the `Decimal character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNumericDecimal(input: string, offset: number): number {
|
||||
const startIndex = offset;
|
||||
|
||||
while (offset < input.length) {
|
||||
const char = input.charCodeAt(offset);
|
||||
if (isNumber(char)) {
|
||||
offset += 1;
|
||||
} else {
|
||||
this.addToNumericResult(input, startIndex, offset, 10);
|
||||
return this.emitNumericEntity(char, 2);
|
||||
}
|
||||
}
|
||||
|
||||
this.addToNumericResult(input, startIndex, offset, 10);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and emit a numeric entity.
|
||||
*
|
||||
* Implements the logic from the `Hexademical character reference start
|
||||
* state` and `Numeric character reference end state` in the HTML spec.
|
||||
*
|
||||
* @param lastCp The last code point of the entity. Used to see if the
|
||||
* entity was terminated with a semicolon.
|
||||
* @param expectedLength The minimum number of characters that should be
|
||||
* consumed. Used to validate that at least one digit
|
||||
* was consumed.
|
||||
* @returns The number of characters that were consumed.
|
||||
*/
|
||||
private emitNumericEntity(lastCp: number, expectedLength: number): number {
|
||||
// Ensure we consumed at least one digit.
|
||||
if (this.consumed <= expectedLength) {
|
||||
this.errors?.absenceOfDigitsInNumericCharacterReference(
|
||||
this.consumed,
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Figure out if this is a legit end of the entity
|
||||
if (lastCp === CharCodes.SEMI) {
|
||||
this.consumed += 1;
|
||||
} else if (this.decodeMode === DecodingMode.Strict) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
this.emitCodePoint(replaceCodePoint(this.result), this.consumed);
|
||||
|
||||
if (this.errors) {
|
||||
if (lastCp !== CharCodes.SEMI) {
|
||||
this.errors.missingSemicolonAfterCharacterReference();
|
||||
}
|
||||
|
||||
this.errors.validateNumericCharacterReference(this.result);
|
||||
}
|
||||
|
||||
return this.consumed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a named entity.
|
||||
*
|
||||
* Equivalent to the `Named character reference state` in the HTML spec.
|
||||
*
|
||||
* @param input The string containing the entity (or a continuation of the entity).
|
||||
* @param offset The current offset.
|
||||
* @returns The number of characters that were consumed, or -1 if the entity is incomplete.
|
||||
*/
|
||||
private stateNamedEntity(input: string, offset: number): number {
|
||||
const { decodeTree } = this;
|
||||
let current = decodeTree[this.treeIndex];
|
||||
// The mask is the number of bytes of the value, including the current byte.
|
||||
let valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;
|
||||
|
||||
for (; offset < input.length; offset++, this.excess++) {
|
||||
const char = input.charCodeAt(offset);
|
||||
|
||||
this.treeIndex = determineBranch(
|
||||
decodeTree,
|
||||
current,
|
||||
this.treeIndex + Math.max(1, valueLength),
|
||||
char,
|
||||
);
|
||||
|
||||
if (this.treeIndex < 0) {
|
||||
return this.result === 0 ||
|
||||
// If we are parsing an attribute
|
||||
(this.decodeMode === DecodingMode.Attribute &&
|
||||
// We shouldn't have consumed any characters after the entity,
|
||||
(valueLength === 0 ||
|
||||
// And there should be no invalid characters.
|
||||
isEntityInAttributeInvalidEnd(char)))
|
||||
? 0
|
||||
: this.emitNotTerminatedNamedEntity();
|
||||
}
|
||||
|
||||
current = decodeTree[this.treeIndex];
|
||||
valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;
|
||||
|
||||
// If the branch is a value, store it and continue
|
||||
if (valueLength !== 0) {
|
||||
// If the entity is terminated by a semicolon, we are done.
|
||||
if (char === CharCodes.SEMI) {
|
||||
return this.emitNamedEntityData(
|
||||
this.treeIndex,
|
||||
valueLength,
|
||||
this.consumed + this.excess,
|
||||
);
|
||||
}
|
||||
|
||||
// If we encounter a non-terminated (legacy) entity while parsing strictly, then ignore it.
|
||||
if (this.decodeMode !== DecodingMode.Strict) {
|
||||
this.result = this.treeIndex;
|
||||
this.consumed += this.excess;
|
||||
this.excess = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit a named entity that was not terminated with a semicolon.
|
||||
*
|
||||
* @returns The number of characters consumed.
|
||||
*/
|
||||
private emitNotTerminatedNamedEntity(): number {
|
||||
const { result, decodeTree } = this;
|
||||
|
||||
const valueLength =
|
||||
(decodeTree[result] & BinTrieFlags.VALUE_LENGTH) >> 14;
|
||||
|
||||
this.emitNamedEntityData(result, valueLength, this.consumed);
|
||||
this.errors?.missingSemicolonAfterCharacterReference();
|
||||
|
||||
return this.consumed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit a named entity.
|
||||
*
|
||||
* @param result The index of the entity in the decode tree.
|
||||
* @param valueLength The number of bytes in the entity.
|
||||
* @param consumed The number of characters consumed.
|
||||
*
|
||||
* @returns The number of characters consumed.
|
||||
*/
|
||||
private emitNamedEntityData(
|
||||
result: number,
|
||||
valueLength: number,
|
||||
consumed: number,
|
||||
): number {
|
||||
const { decodeTree } = this;
|
||||
|
||||
this.emitCodePoint(
|
||||
valueLength === 1
|
||||
? decodeTree[result] & ~BinTrieFlags.VALUE_LENGTH
|
||||
: decodeTree[result + 1],
|
||||
consumed,
|
||||
);
|
||||
if (valueLength === 3) {
|
||||
// For multi-byte values, we need to emit the second byte.
|
||||
this.emitCodePoint(decodeTree[result + 2], consumed);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal to the parser that the end of the input was reached.
|
||||
*
|
||||
* Remaining data will be emitted and relevant errors will be produced.
|
||||
*
|
||||
* @returns The number of characters consumed.
|
||||
*/
|
||||
end(): number {
|
||||
switch (this.state) {
|
||||
case EntityDecoderState.NamedEntity: {
|
||||
// Emit a named entity if we have one.
|
||||
return this.result !== 0 &&
|
||||
(this.decodeMode !== DecodingMode.Attribute ||
|
||||
this.result === this.treeIndex)
|
||||
? this.emitNotTerminatedNamedEntity()
|
||||
: 0;
|
||||
}
|
||||
// Otherwise, emit a numeric entity if we have one.
|
||||
case EntityDecoderState.NumericDecimal: {
|
||||
return this.emitNumericEntity(0, 2);
|
||||
}
|
||||
case EntityDecoderState.NumericHex: {
|
||||
return this.emitNumericEntity(0, 3);
|
||||
}
|
||||
case EntityDecoderState.NumericStart: {
|
||||
this.errors?.absenceOfDigitsInNumericCharacterReference(
|
||||
this.consumed,
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
case EntityDecoderState.EntityStart: {
|
||||
// Return 0 if we have no entity.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a function that decodes entities in a string.
|
||||
*
|
||||
* @param decodeTree The decode tree.
|
||||
* @returns A function that decodes entities in a string.
|
||||
*/
|
||||
function getDecoder(decodeTree: Uint16Array) {
|
||||
let returnValue = "";
|
||||
const decoder = new EntityDecoder(
|
||||
decodeTree,
|
||||
(data) => (returnValue += fromCodePoint(data)),
|
||||
);
|
||||
|
||||
return function decodeWithTrie(
|
||||
input: string,
|
||||
decodeMode: DecodingMode,
|
||||
): string {
|
||||
let lastIndex = 0;
|
||||
let offset = 0;
|
||||
|
||||
while ((offset = input.indexOf("&", offset)) >= 0) {
|
||||
returnValue += input.slice(lastIndex, offset);
|
||||
|
||||
decoder.startEntity(decodeMode);
|
||||
|
||||
const length = decoder.write(
|
||||
input,
|
||||
// Skip the "&"
|
||||
offset + 1,
|
||||
);
|
||||
|
||||
if (length < 0) {
|
||||
lastIndex = offset + decoder.end();
|
||||
break;
|
||||
}
|
||||
|
||||
lastIndex = offset + length;
|
||||
// If `length` is 0, skip the current `&` and continue.
|
||||
offset = length === 0 ? lastIndex + 1 : lastIndex;
|
||||
}
|
||||
|
||||
const result = returnValue + input.slice(lastIndex);
|
||||
|
||||
// Make sure we don't keep a reference to the final string.
|
||||
returnValue = "";
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the branch of the current node that is taken given the current
|
||||
* character. This function is used to traverse the trie.
|
||||
*
|
||||
* @param decodeTree The trie.
|
||||
* @param current The current node.
|
||||
* @param nodeIdx The index right after the current node and its value.
|
||||
* @param char The current character.
|
||||
* @returns The index of the next node, or -1 if no branch is taken.
|
||||
*/
|
||||
export function determineBranch(
|
||||
decodeTree: Uint16Array,
|
||||
current: number,
|
||||
nodeIndex: number,
|
||||
char: number,
|
||||
): number {
|
||||
const branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;
|
||||
const jumpOffset = current & BinTrieFlags.JUMP_TABLE;
|
||||
|
||||
// Case 1: Single branch encoded in jump offset
|
||||
if (branchCount === 0) {
|
||||
return jumpOffset !== 0 && char === jumpOffset ? nodeIndex : -1;
|
||||
}
|
||||
|
||||
// Case 2: Multiple branches encoded in jump table
|
||||
if (jumpOffset) {
|
||||
const value = char - jumpOffset;
|
||||
|
||||
return value < 0 || value >= branchCount
|
||||
? -1
|
||||
: decodeTree[nodeIndex + value] - 1;
|
||||
}
|
||||
|
||||
// Case 3: Multiple branches encoded in dictionary
|
||||
|
||||
// Binary search for the character.
|
||||
let lo = nodeIndex;
|
||||
let hi = lo + branchCount - 1;
|
||||
|
||||
while (lo <= hi) {
|
||||
const mid = (lo + hi) >>> 1;
|
||||
const midValue = decodeTree[mid];
|
||||
|
||||
if (midValue < char) {
|
||||
lo = mid + 1;
|
||||
} else if (midValue > char) {
|
||||
hi = mid - 1;
|
||||
} else {
|
||||
return decodeTree[mid + branchCount];
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const htmlDecoder = /* #__PURE__ */ getDecoder(htmlDecodeTree);
|
||||
const xmlDecoder = /* #__PURE__ */ getDecoder(xmlDecodeTree);
|
||||
|
||||
/**
|
||||
* Decodes an HTML string.
|
||||
*
|
||||
* @param htmlString The string to decode.
|
||||
* @param mode The decoding mode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export function decodeHTML(
|
||||
htmlString: string,
|
||||
mode: DecodingMode = DecodingMode.Legacy,
|
||||
): string {
|
||||
return htmlDecoder(htmlString, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes an HTML string in an attribute.
|
||||
*
|
||||
* @param htmlAttribute The string to decode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export function decodeHTMLAttribute(htmlAttribute: string): string {
|
||||
return htmlDecoder(htmlAttribute, DecodingMode.Attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes an HTML string, requiring all entities to be terminated by a semicolon.
|
||||
*
|
||||
* @param htmlString The string to decode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export function decodeHTMLStrict(htmlString: string): string {
|
||||
return htmlDecoder(htmlString, DecodingMode.Strict);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes an XML string, requiring all entities to be terminated by a semicolon.
|
||||
*
|
||||
* @param xmlString The string to decode.
|
||||
* @returns The decoded string.
|
||||
*/
|
||||
export function decodeXML(xmlString: string): string {
|
||||
return xmlDecoder(xmlString, DecodingMode.Strict);
|
||||
}
|
||||
|
||||
// Re-export for use by eg. htmlparser2
|
||||
export { htmlDecodeTree } from "./generated/decode-data-html.js";
|
||||
export { xmlDecodeTree } from "./generated/decode-data-xml.js";
|
||||
|
||||
export {
|
||||
decodeCodePoint,
|
||||
replaceCodePoint,
|
||||
fromCodePoint,
|
||||
} from "./decode-codepoint.js";
|
||||
14
frontend/node_modules/entities/src/escape.spec.ts
generated
vendored
Normal file
14
frontend/node_modules/entities/src/escape.spec.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import * as entities from "./index.js";
|
||||
|
||||
describe("escape HTML", () => {
|
||||
it("should escape HTML attribute values", () =>
|
||||
expect(entities.escapeAttribute('<a " attr > & value \u00A0!')).toBe(
|
||||
"<a " attr > & value !",
|
||||
));
|
||||
|
||||
it("should escape HTML text", () =>
|
||||
expect(entities.escapeText('<a " text > & value \u00A0!')).toBe(
|
||||
'<a " text > & value !',
|
||||
));
|
||||
});
|
||||
8
frontend/node_modules/entities/src/generated/decode-data-html.ts
generated
vendored
Normal file
8
frontend/node_modules/entities/src/generated/decode-data-html.ts
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
17
frontend/node_modules/entities/src/generated/encode-html.ts
generated
vendored
Normal file
17
frontend/node_modules/entities/src/generated/encode-html.ts
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
188
frontend/node_modules/entities/src/index.ts
generated
vendored
Normal file
188
frontend/node_modules/entities/src/index.ts
generated
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
import { decodeXML, decodeHTML, DecodingMode } from "./decode.js";
|
||||
import { encodeHTML, encodeNonAsciiHTML } from "./encode.js";
|
||||
import {
|
||||
encodeXML,
|
||||
escapeUTF8,
|
||||
escapeAttribute,
|
||||
escapeText,
|
||||
} from "./escape.js";
|
||||
|
||||
/** The level of entities to support. */
|
||||
export enum EntityLevel {
|
||||
/** Support only XML entities. */
|
||||
XML = 0,
|
||||
/** Support HTML entities, which are a superset of XML entities. */
|
||||
HTML = 1,
|
||||
}
|
||||
|
||||
export enum EncodingMode {
|
||||
/**
|
||||
* The output is UTF-8 encoded. Only characters that need escaping within
|
||||
* XML will be escaped.
|
||||
*/
|
||||
UTF8,
|
||||
/**
|
||||
* The output consists only of ASCII characters. Characters that need
|
||||
* escaping within HTML, and characters that aren't ASCII characters will
|
||||
* be escaped.
|
||||
*/
|
||||
ASCII,
|
||||
/**
|
||||
* Encode all characters that have an equivalent entity, as well as all
|
||||
* characters that are not ASCII characters.
|
||||
*/
|
||||
Extensive,
|
||||
/**
|
||||
* Encode all characters that have to be escaped in HTML attributes,
|
||||
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
||||
*/
|
||||
Attribute,
|
||||
/**
|
||||
* Encode all characters that have to be escaped in HTML text,
|
||||
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
||||
*/
|
||||
Text,
|
||||
}
|
||||
|
||||
export interface DecodingOptions {
|
||||
/**
|
||||
* The level of entities to support.
|
||||
* @default {@link EntityLevel.XML}
|
||||
*/
|
||||
level?: EntityLevel;
|
||||
/**
|
||||
* Decoding mode. If `Legacy`, will support legacy entities not terminated
|
||||
* with a semicolon (`;`).
|
||||
*
|
||||
* Always `Strict` for XML. For HTML, set this to `true` if you are parsing
|
||||
* an attribute value.
|
||||
*
|
||||
* The deprecated `decodeStrict` function defaults this to `Strict`.
|
||||
*
|
||||
* @default {@link DecodingMode.Legacy}
|
||||
*/
|
||||
mode?: DecodingMode | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a string with entities.
|
||||
*
|
||||
* @param input String to decode.
|
||||
* @param options Decoding options.
|
||||
*/
|
||||
export function decode(
|
||||
input: string,
|
||||
options: DecodingOptions | EntityLevel = EntityLevel.XML,
|
||||
): string {
|
||||
const level = typeof options === "number" ? options : options.level;
|
||||
|
||||
if (level === EntityLevel.HTML) {
|
||||
const mode = typeof options === "object" ? options.mode : undefined;
|
||||
return decodeHTML(input, mode);
|
||||
}
|
||||
|
||||
return decodeXML(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a string with entities. Does not allow missing trailing semicolons for entities.
|
||||
*
|
||||
* @param input String to decode.
|
||||
* @param options Decoding options.
|
||||
* @deprecated Use `decode` with the `mode` set to `Strict`.
|
||||
*/
|
||||
export function decodeStrict(
|
||||
input: string,
|
||||
options: DecodingOptions | EntityLevel = EntityLevel.XML,
|
||||
): string {
|
||||
const normalizedOptions =
|
||||
typeof options === "number" ? { level: options } : options;
|
||||
normalizedOptions.mode ??= DecodingMode.Strict;
|
||||
|
||||
return decode(input, normalizedOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for `encode`.
|
||||
*/
|
||||
export interface EncodingOptions {
|
||||
/**
|
||||
* The level of entities to support.
|
||||
* @default {@link EntityLevel.XML}
|
||||
*/
|
||||
level?: EntityLevel;
|
||||
/**
|
||||
* Output format.
|
||||
* @default {@link EncodingMode.Extensive}
|
||||
*/
|
||||
mode?: EncodingMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a string with entities.
|
||||
*
|
||||
* @param input String to encode.
|
||||
* @param options Encoding options.
|
||||
*/
|
||||
export function encode(
|
||||
input: string,
|
||||
options: EncodingOptions | EntityLevel = EntityLevel.XML,
|
||||
): string {
|
||||
const { mode = EncodingMode.Extensive, level = EntityLevel.XML } =
|
||||
typeof options === "number" ? { level: options } : options;
|
||||
|
||||
switch (mode) {
|
||||
case EncodingMode.UTF8: {
|
||||
return escapeUTF8(input);
|
||||
}
|
||||
case EncodingMode.Attribute: {
|
||||
return escapeAttribute(input);
|
||||
}
|
||||
case EncodingMode.Text: {
|
||||
return escapeText(input);
|
||||
}
|
||||
case EncodingMode.ASCII: {
|
||||
return level === EntityLevel.HTML
|
||||
? encodeNonAsciiHTML(input)
|
||||
: encodeXML(input);
|
||||
}
|
||||
// eslint-disable-next-line unicorn/no-useless-switch-case
|
||||
case EncodingMode.Extensive:
|
||||
default: {
|
||||
return level === EntityLevel.HTML
|
||||
? encodeHTML(input)
|
||||
: encodeXML(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
encodeXML,
|
||||
escape,
|
||||
escapeUTF8,
|
||||
escapeAttribute,
|
||||
escapeText,
|
||||
} from "./escape.js";
|
||||
|
||||
export {
|
||||
encodeHTML,
|
||||
encodeNonAsciiHTML,
|
||||
// Legacy aliases (deprecated)
|
||||
encodeHTML as encodeHTML4,
|
||||
encodeHTML as encodeHTML5,
|
||||
} from "./encode.js";
|
||||
|
||||
export {
|
||||
EntityDecoder,
|
||||
DecodingMode,
|
||||
decodeXML,
|
||||
decodeHTML,
|
||||
decodeHTMLStrict,
|
||||
decodeHTMLAttribute,
|
||||
// Legacy aliases (deprecated)
|
||||
decodeHTML as decodeHTML4,
|
||||
decodeHTML as decodeHTML5,
|
||||
decodeHTMLStrict as decodeHTML4Strict,
|
||||
decodeHTMLStrict as decodeHTML5Strict,
|
||||
decodeXML as decodeXMLStrict,
|
||||
} from "./decode.js";
|
||||
Reference in New Issue
Block a user