@scrabble-solver/scrabble-solver 2.12.2 → 2.12.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.
Files changed (85) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +6 -6
  3. package/.next/cache/.tsbuildinfo +1 -1
  4. package/.next/cache/eslint/.cache_8dgz12 +1 -1
  5. package/.next/cache/next-server.js.nft.json +1 -1
  6. package/.next/cache/webpack/client-production/0.pack +0 -0
  7. package/.next/cache/webpack/client-production/index.pack +0 -0
  8. package/.next/cache/webpack/edge-server-production/0.pack +0 -0
  9. package/.next/cache/webpack/edge-server-production/index.pack +0 -0
  10. package/.next/cache/webpack/server-production/0.pack +0 -0
  11. package/.next/cache/webpack/server-production/index.pack +0 -0
  12. package/.next/next-server.js.nft.json +1 -1
  13. package/.next/prerender-manifest.json +1 -1
  14. package/.next/routes-manifest.json +1 -1
  15. package/.next/server/chunks/131.js +478 -106
  16. package/.next/server/chunks/277.js +1132 -976
  17. package/.next/server/chunks/44.js +36 -6
  18. package/.next/server/chunks/865.js +478 -106
  19. package/.next/server/chunks/911.js +894 -773
  20. package/.next/server/middleware-build-manifest.js +1 -1
  21. package/.next/server/pages/404.html +1 -1
  22. package/.next/server/pages/404.js.nft.json +1 -1
  23. package/.next/server/pages/500.html +1 -1
  24. package/.next/server/pages/_app.js +3 -1
  25. package/.next/server/pages/_app.js.nft.json +1 -1
  26. package/.next/server/pages/api/dictionary/[locale]/[word].js +4 -2
  27. package/.next/server/pages/api/solve.js +23 -19
  28. package/.next/server/pages/api/verify.js +8 -5
  29. package/.next/server/pages/index.html +1 -1
  30. package/.next/server/pages/index.js +42 -55
  31. package/.next/server/pages/index.js.nft.json +1 -1
  32. package/.next/server/pages/index.json +1 -1
  33. package/.next/server/pages-manifest.json +1 -1
  34. package/.next/static/chunks/pages/_app-e7f3d1c9c09c8f91.js +32 -0
  35. package/.next/static/chunks/pages/index-82b2939158c7729f.js +1 -0
  36. package/.next/static/css/4e8b47fe382a8a8f.css +2 -0
  37. package/.next/static/css/cfae5256f1689f57.css +1 -0
  38. package/.next/static/{9dmPfnTc_AQTHBPvL7xQe → wNIKOJJzkMSJYb2nOL21o}/_buildManifest.js +1 -1
  39. package/.next/trace +51 -52
  40. package/package.json +9 -9
  41. package/src/components/Board/components/Cell/Cell.module.scss +4 -12
  42. package/src/components/Board/components/Cell/Cell.tsx +4 -0
  43. package/src/components/Board/hooks/useBackgroundImage.tsx +23 -0
  44. package/src/components/PlainTiles/lib/createPlainTile.ts +4 -4
  45. package/src/components/Radio/Radio.module.scss +4 -0
  46. package/src/components/Radio/Radio.tsx +1 -0
  47. package/src/components/SeoMessage/SeoMessage.tsx +3 -3
  48. package/src/hooks/useAppLayout.ts +1 -2
  49. package/src/hooks/useLocalStorage.ts +5 -5
  50. package/src/i18n/constants.ts +31 -61
  51. package/src/lib/extractCharacters.test.ts +3 -3
  52. package/src/lib/extractCharactersByCase.test.ts +3 -3
  53. package/src/lib/getCellSize.ts +2 -2
  54. package/src/modals/MenuModal/MenuModal.module.scss +0 -1
  55. package/src/modals/MenuModal/MenuModal.tsx +3 -3
  56. package/src/modals/SettingsModal/components/ConfigSetting/ConfigSetting.tsx +16 -7
  57. package/src/modals/SettingsModal/components/LocaleSetting/LocaleSetting.module.scss +1 -4
  58. package/src/modals/SettingsModal/components/LocaleSetting/LocaleSetting.tsx +8 -8
  59. package/src/pages/_app.tsx +3 -1
  60. package/src/pages/api/dictionary/[locale]/[word].ts +6 -3
  61. package/src/pages/api/solve.ts +11 -7
  62. package/src/pages/api/verify.ts +11 -7
  63. package/src/pages/index.module.scss +0 -1
  64. package/src/parameters/index.ts +4 -6
  65. package/src/sdk/solve.ts +3 -3
  66. package/src/sdk/verify.ts +3 -3
  67. package/src/service-worker/routeSolveRequests.ts +3 -3
  68. package/src/state/localStorage.ts +6 -6
  69. package/src/state/sagas.ts +18 -7
  70. package/src/state/selectors.ts +3 -3
  71. package/src/state/slices/boardInitialState.ts +3 -3
  72. package/src/state/slices/boardSlice.ts +20 -6
  73. package/src/state/slices/settingsInitialState.ts +3 -4
  74. package/src/state/slices/settingsSlice.ts +5 -5
  75. package/src/styles/variables.scss +0 -9
  76. package/.next/static/chunks/pages/_app-02851b06b95b19cb.js +0 -32
  77. package/.next/static/chunks/pages/index-0ba5607d1aad8a09.js +0 -1
  78. package/.next/static/css/09dfdea53eba31a9.css +0 -2
  79. package/.next/static/css/60e8258da7362a1a.css +0 -1
  80. package/src/i18n/i18n.module.scss +0 -27
  81. package/src/modals/SettingsModal/components/ConfigSetting/options.ts +0 -19
  82. package/src/modals/SettingsModal/components/ConfigSetting/types.ts +0 -9
  83. package/src/modals/SettingsModal/components/InputModeSetting/types.ts +0 -7
  84. package/src/modals/SettingsModal/components/LocaleSetting/types.ts +0 -9
  85. /package/.next/static/{9dmPfnTc_AQTHBPvL7xQe → wNIKOJJzkMSJYb2nOL21o}/_ssgManifest.js +0 -0
@@ -8093,16 +8093,39 @@ exports.prevElementSibling = prevElementSibling;
8093
8093
 
8094
8094
  "use strict";
8095
8095
 
8096
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8097
+ if (k2 === undefined) k2 = k;
8098
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8099
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8100
+ desc = { enumerable: true, get: function() { return m[k]; } };
8101
+ }
8102
+ Object.defineProperty(o, k2, desc);
8103
+ }) : (function(o, m, k, k2) {
8104
+ if (k2 === undefined) k2 = k;
8105
+ o[k2] = m[k];
8106
+ }));
8107
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
8108
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
8109
+ }) : function(o, v) {
8110
+ o["default"] = v;
8111
+ });
8112
+ var __importStar = (this && this.__importStar) || function (mod) {
8113
+ if (mod && mod.__esModule) return mod;
8114
+ var result = {};
8115
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
8116
+ __setModuleDefault(result, mod);
8117
+ return result;
8118
+ };
8096
8119
  var __importDefault = (this && this.__importDefault) || function (mod) {
8097
8120
  return (mod && mod.__esModule) ? mod : { "default": mod };
8098
8121
  };
8099
8122
  Object.defineProperty(exports, "__esModule", ({ value: true }));
8100
- exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTML = exports.determineBranch = exports.BinTrieFlags = exports.fromCodePoint = exports.replaceCodePoint = exports.decodeCodePoint = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0;
8123
+ exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTMLAttribute = exports.decodeHTML = exports.determineBranch = exports.EntityDecoder = exports.DecodingMode = exports.BinTrieFlags = exports.fromCodePoint = exports.replaceCodePoint = exports.decodeCodePoint = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0;
8101
8124
  var decode_data_html_js_1 = __importDefault(__webpack_require__(18910));
8102
8125
  exports.htmlDecodeTree = decode_data_html_js_1.default;
8103
8126
  var decode_data_xml_js_1 = __importDefault(__webpack_require__(77247));
8104
8127
  exports.xmlDecodeTree = decode_data_xml_js_1.default;
8105
- var decode_codepoint_js_1 = __importDefault(__webpack_require__(79233));
8128
+ var decode_codepoint_js_1 = __importStar(__webpack_require__(79233));
8106
8129
  exports.decodeCodePoint = decode_codepoint_js_1.default;
8107
8130
  var decode_codepoint_js_2 = __webpack_require__(79233);
8108
8131
  Object.defineProperty(exports, "replaceCodePoint", ({ enumerable: true, get: function () { return decode_codepoint_js_2.replaceCodePoint; } }));
@@ -8111,99 +8134,421 @@ var CharCodes;
8111
8134
  (function (CharCodes) {
8112
8135
  CharCodes[CharCodes["NUM"] = 35] = "NUM";
8113
8136
  CharCodes[CharCodes["SEMI"] = 59] = "SEMI";
8137
+ CharCodes[CharCodes["EQUALS"] = 61] = "EQUALS";
8114
8138
  CharCodes[CharCodes["ZERO"] = 48] = "ZERO";
8115
8139
  CharCodes[CharCodes["NINE"] = 57] = "NINE";
8116
8140
  CharCodes[CharCodes["LOWER_A"] = 97] = "LOWER_A";
8117
8141
  CharCodes[CharCodes["LOWER_F"] = 102] = "LOWER_F";
8118
8142
  CharCodes[CharCodes["LOWER_X"] = 120] = "LOWER_X";
8119
- /** Bit that needs to be set to convert an upper case ASCII character to lower case */
8120
- CharCodes[CharCodes["To_LOWER_BIT"] = 32] = "To_LOWER_BIT";
8143
+ CharCodes[CharCodes["LOWER_Z"] = 122] = "LOWER_Z";
8144
+ CharCodes[CharCodes["UPPER_A"] = 65] = "UPPER_A";
8145
+ CharCodes[CharCodes["UPPER_F"] = 70] = "UPPER_F";
8146
+ CharCodes[CharCodes["UPPER_Z"] = 90] = "UPPER_Z";
8121
8147
  })(CharCodes || (CharCodes = {}));
8148
+ /** Bit that needs to be set to convert an upper case ASCII character to lower case */
8149
+ var TO_LOWER_BIT = 32;
8122
8150
  var BinTrieFlags;
8123
8151
  (function (BinTrieFlags) {
8124
8152
  BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH";
8125
8153
  BinTrieFlags[BinTrieFlags["BRANCH_LENGTH"] = 16256] = "BRANCH_LENGTH";
8126
8154
  BinTrieFlags[BinTrieFlags["JUMP_TABLE"] = 127] = "JUMP_TABLE";
8127
8155
  })(BinTrieFlags = exports.BinTrieFlags || (exports.BinTrieFlags = {}));
8128
- function getDecoder(decodeTree) {
8129
- return function decodeHTMLBinary(str, strict) {
8130
- var ret = "";
8131
- var lastIdx = 0;
8132
- var strIdx = 0;
8133
- while ((strIdx = str.indexOf("&", strIdx)) >= 0) {
8134
- ret += str.slice(lastIdx, strIdx);
8135
- lastIdx = strIdx;
8136
- // Skip the "&"
8137
- strIdx += 1;
8138
- // If we have a numeric entity, handle this separately.
8139
- if (str.charCodeAt(strIdx) === CharCodes.NUM) {
8140
- // Skip the leading "&#". For hex entities, also skip the leading "x".
8141
- var start = strIdx + 1;
8142
- var base = 10;
8143
- var cp = str.charCodeAt(start);
8144
- if ((cp | CharCodes.To_LOWER_BIT) === CharCodes.LOWER_X) {
8145
- base = 16;
8146
- strIdx += 1;
8147
- start += 1;
8148
- }
8149
- do
8150
- cp = str.charCodeAt(++strIdx);
8151
- while ((cp >= CharCodes.ZERO && cp <= CharCodes.NINE) ||
8152
- (base === 16 &&
8153
- (cp | CharCodes.To_LOWER_BIT) >= CharCodes.LOWER_A &&
8154
- (cp | CharCodes.To_LOWER_BIT) <= CharCodes.LOWER_F));
8155
- if (start !== strIdx) {
8156
- var entity = str.substring(start, strIdx);
8157
- var parsed = parseInt(entity, base);
8158
- if (str.charCodeAt(strIdx) === CharCodes.SEMI) {
8159
- strIdx += 1;
8160
- }
8161
- else if (strict) {
8162
- continue;
8163
- }
8164
- ret += (0, decode_codepoint_js_1.default)(parsed);
8165
- lastIdx = strIdx;
8156
+ function isNumber(code) {
8157
+ return code >= CharCodes.ZERO && code <= CharCodes.NINE;
8158
+ }
8159
+ function isHexadecimalCharacter(code) {
8160
+ return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F) ||
8161
+ (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F));
8162
+ }
8163
+ function isAsciiAlphaNumeric(code) {
8164
+ return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z) ||
8165
+ (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z) ||
8166
+ isNumber(code));
8167
+ }
8168
+ /**
8169
+ * Checks if the given character is a valid end character for an entity in an attribute.
8170
+ *
8171
+ * Attribute values that aren't terminated properly aren't parsed, and shouldn't lead to a parser error.
8172
+ * See the example in https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state
8173
+ */
8174
+ function isEntityInAttributeInvalidEnd(code) {
8175
+ return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code);
8176
+ }
8177
+ var EntityDecoderState;
8178
+ (function (EntityDecoderState) {
8179
+ EntityDecoderState[EntityDecoderState["EntityStart"] = 0] = "EntityStart";
8180
+ EntityDecoderState[EntityDecoderState["NumericStart"] = 1] = "NumericStart";
8181
+ EntityDecoderState[EntityDecoderState["NumericDecimal"] = 2] = "NumericDecimal";
8182
+ EntityDecoderState[EntityDecoderState["NumericHex"] = 3] = "NumericHex";
8183
+ EntityDecoderState[EntityDecoderState["NamedEntity"] = 4] = "NamedEntity";
8184
+ })(EntityDecoderState || (EntityDecoderState = {}));
8185
+ var DecodingMode;
8186
+ (function (DecodingMode) {
8187
+ /** Entities in text nodes that can end with any character. */
8188
+ DecodingMode[DecodingMode["Legacy"] = 0] = "Legacy";
8189
+ /** Only allow entities terminated with a semicolon. */
8190
+ DecodingMode[DecodingMode["Strict"] = 1] = "Strict";
8191
+ /** Entities in attributes have limitations on ending characters. */
8192
+ DecodingMode[DecodingMode["Attribute"] = 2] = "Attribute";
8193
+ })(DecodingMode = exports.DecodingMode || (exports.DecodingMode = {}));
8194
+ /**
8195
+ * Token decoder with support of writing partial entities.
8196
+ */
8197
+ var EntityDecoder = /** @class */ (function () {
8198
+ function EntityDecoder(
8199
+ /** The tree used to decode entities. */
8200
+ decodeTree,
8201
+ /**
8202
+ * The function that is called when a codepoint is decoded.
8203
+ *
8204
+ * For multi-byte named entities, this will be called multiple times,
8205
+ * with the second codepoint, and the same `consumed` value.
8206
+ *
8207
+ * @param codepoint The decoded codepoint.
8208
+ * @param consumed The number of bytes consumed by the decoder.
8209
+ */
8210
+ emitCodePoint,
8211
+ /** An object that is used to produce errors. */
8212
+ errors) {
8213
+ this.decodeTree = decodeTree;
8214
+ this.emitCodePoint = emitCodePoint;
8215
+ this.errors = errors;
8216
+ /** The current state of the decoder. */
8217
+ this.state = EntityDecoderState.EntityStart;
8218
+ /** Characters that were consumed while parsing an entity. */
8219
+ this.consumed = 1;
8220
+ /**
8221
+ * The result of the entity.
8222
+ *
8223
+ * Either the result index of a numeric entity, or the codepoint of a
8224
+ * numeric entity.
8225
+ */
8226
+ this.result = 0;
8227
+ /** The current index in the decode tree. */
8228
+ this.treeIndex = 0;
8229
+ /** The number of characters that were consumed in excess. */
8230
+ this.excess = 1;
8231
+ /** The mode in which the decoder is operating. */
8232
+ this.decodeMode = DecodingMode.Strict;
8233
+ }
8234
+ /** Resets the instance to make it reusable. */
8235
+ EntityDecoder.prototype.startEntity = function (decodeMode) {
8236
+ this.decodeMode = decodeMode;
8237
+ this.state = EntityDecoderState.EntityStart;
8238
+ this.result = 0;
8239
+ this.treeIndex = 0;
8240
+ this.excess = 1;
8241
+ this.consumed = 1;
8242
+ };
8243
+ /**
8244
+ * Write an entity to the decoder. This can be called multiple times with partial entities.
8245
+ * If the entity is incomplete, the decoder will return -1.
8246
+ *
8247
+ * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
8248
+ * entity is incomplete, and resume when the next string is written.
8249
+ *
8250
+ * @param string The string containing the entity (or a continuation of the entity).
8251
+ * @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
8252
+ * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
8253
+ */
8254
+ EntityDecoder.prototype.write = function (str, offset) {
8255
+ switch (this.state) {
8256
+ case EntityDecoderState.EntityStart: {
8257
+ if (str.charCodeAt(offset) === CharCodes.NUM) {
8258
+ this.state = EntityDecoderState.NumericStart;
8259
+ this.consumed += 1;
8260
+ return this.stateNumericStart(str, offset + 1);
8166
8261
  }
8167
- continue;
8262
+ this.state = EntityDecoderState.NamedEntity;
8263
+ return this.stateNamedEntity(str, offset);
8168
8264
  }
8169
- var resultIdx = 0;
8170
- var excess = 1;
8171
- var treeIdx = 0;
8172
- var current = decodeTree[treeIdx];
8173
- for (; strIdx < str.length; strIdx++, excess++) {
8174
- treeIdx = determineBranch(decodeTree, current, treeIdx + 1, str.charCodeAt(strIdx));
8175
- if (treeIdx < 0)
8176
- break;
8177
- current = decodeTree[treeIdx];
8178
- var masked = current & BinTrieFlags.VALUE_LENGTH;
8179
- // If the branch is a value, store it and continue
8180
- if (masked) {
8181
- // If we have a legacy entity while parsing strictly, just skip the number of bytes
8182
- if (!strict || str.charCodeAt(strIdx) === CharCodes.SEMI) {
8183
- resultIdx = treeIdx;
8184
- excess = 0;
8185
- }
8186
- // The mask is the number of bytes of the value, including the current byte.
8187
- var valueLength = (masked >> 14) - 1;
8188
- if (valueLength === 0)
8189
- break;
8190
- treeIdx += valueLength;
8265
+ case EntityDecoderState.NumericStart: {
8266
+ return this.stateNumericStart(str, offset);
8267
+ }
8268
+ case EntityDecoderState.NumericDecimal: {
8269
+ return this.stateNumericDecimal(str, offset);
8270
+ }
8271
+ case EntityDecoderState.NumericHex: {
8272
+ return this.stateNumericHex(str, offset);
8273
+ }
8274
+ case EntityDecoderState.NamedEntity: {
8275
+ return this.stateNamedEntity(str, offset);
8276
+ }
8277
+ }
8278
+ };
8279
+ /**
8280
+ * Switches between the numeric decimal and hexadecimal states.
8281
+ *
8282
+ * Equivalent to the `Numeric character reference state` in the HTML spec.
8283
+ *
8284
+ * @param str The string containing the entity (or a continuation of the entity).
8285
+ * @param offset The current offset.
8286
+ * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
8287
+ */
8288
+ EntityDecoder.prototype.stateNumericStart = function (str, offset) {
8289
+ if (offset >= str.length) {
8290
+ return -1;
8291
+ }
8292
+ if ((str.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) {
8293
+ this.state = EntityDecoderState.NumericHex;
8294
+ this.consumed += 1;
8295
+ return this.stateNumericHex(str, offset + 1);
8296
+ }
8297
+ this.state = EntityDecoderState.NumericDecimal;
8298
+ return this.stateNumericDecimal(str, offset);
8299
+ };
8300
+ EntityDecoder.prototype.addToNumericResult = function (str, start, end, base) {
8301
+ if (start !== end) {
8302
+ var digitCount = end - start;
8303
+ this.result =
8304
+ this.result * Math.pow(base, digitCount) +
8305
+ parseInt(str.substr(start, digitCount), base);
8306
+ this.consumed += digitCount;
8307
+ }
8308
+ };
8309
+ /**
8310
+ * Parses a hexadecimal numeric entity.
8311
+ *
8312
+ * Equivalent to the `Hexademical character reference state` in the HTML spec.
8313
+ *
8314
+ * @param str The string containing the entity (or a continuation of the entity).
8315
+ * @param offset The current offset.
8316
+ * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
8317
+ */
8318
+ EntityDecoder.prototype.stateNumericHex = function (str, offset) {
8319
+ var startIdx = offset;
8320
+ while (offset < str.length) {
8321
+ var char = str.charCodeAt(offset);
8322
+ if (isNumber(char) || isHexadecimalCharacter(char)) {
8323
+ offset += 1;
8324
+ }
8325
+ else {
8326
+ this.addToNumericResult(str, startIdx, offset, 16);
8327
+ return this.emitNumericEntity(char, 3);
8328
+ }
8329
+ }
8330
+ this.addToNumericResult(str, startIdx, offset, 16);
8331
+ return -1;
8332
+ };
8333
+ /**
8334
+ * Parses a decimal numeric entity.
8335
+ *
8336
+ * Equivalent to the `Decimal character reference state` in the HTML spec.
8337
+ *
8338
+ * @param str The string containing the entity (or a continuation of the entity).
8339
+ * @param offset The current offset.
8340
+ * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
8341
+ */
8342
+ EntityDecoder.prototype.stateNumericDecimal = function (str, offset) {
8343
+ var startIdx = offset;
8344
+ while (offset < str.length) {
8345
+ var char = str.charCodeAt(offset);
8346
+ if (isNumber(char)) {
8347
+ offset += 1;
8348
+ }
8349
+ else {
8350
+ this.addToNumericResult(str, startIdx, offset, 10);
8351
+ return this.emitNumericEntity(char, 2);
8352
+ }
8353
+ }
8354
+ this.addToNumericResult(str, startIdx, offset, 10);
8355
+ return -1;
8356
+ };
8357
+ /**
8358
+ * Validate and emit a numeric entity.
8359
+ *
8360
+ * Implements the logic from the `Hexademical character reference start
8361
+ * state` and `Numeric character reference end state` in the HTML spec.
8362
+ *
8363
+ * @param lastCp The last code point of the entity. Used to see if the
8364
+ * entity was terminated with a semicolon.
8365
+ * @param expectedLength The minimum number of characters that should be
8366
+ * consumed. Used to validate that at least one digit
8367
+ * was consumed.
8368
+ * @returns The number of characters that were consumed.
8369
+ */
8370
+ EntityDecoder.prototype.emitNumericEntity = function (lastCp, expectedLength) {
8371
+ var _a;
8372
+ // Ensure we consumed at least one digit.
8373
+ if (this.consumed <= expectedLength) {
8374
+ (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);
8375
+ return 0;
8376
+ }
8377
+ // Figure out if this is a legit end of the entity
8378
+ if (lastCp === CharCodes.SEMI) {
8379
+ this.consumed += 1;
8380
+ }
8381
+ else if (this.decodeMode === DecodingMode.Strict) {
8382
+ return 0;
8383
+ }
8384
+ this.emitCodePoint((0, decode_codepoint_js_1.replaceCodePoint)(this.result), this.consumed);
8385
+ if (this.errors) {
8386
+ if (lastCp !== CharCodes.SEMI) {
8387
+ this.errors.missingSemicolonAfterCharacterReference();
8388
+ }
8389
+ this.errors.validateNumericCharacterReference(this.result);
8390
+ }
8391
+ return this.consumed;
8392
+ };
8393
+ /**
8394
+ * Parses a named entity.
8395
+ *
8396
+ * Equivalent to the `Named character reference state` in the HTML spec.
8397
+ *
8398
+ * @param str The string containing the entity (or a continuation of the entity).
8399
+ * @param offset The current offset.
8400
+ * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
8401
+ */
8402
+ EntityDecoder.prototype.stateNamedEntity = function (str, offset) {
8403
+ var decodeTree = this.decodeTree;
8404
+ var current = decodeTree[this.treeIndex];
8405
+ // The mask is the number of bytes of the value, including the current byte.
8406
+ var valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;
8407
+ for (; offset < str.length; offset++, this.excess++) {
8408
+ var char = str.charCodeAt(offset);
8409
+ this.treeIndex = determineBranch(decodeTree, current, this.treeIndex + Math.max(1, valueLength), char);
8410
+ if (this.treeIndex < 0) {
8411
+ return this.result === 0 ||
8412
+ // If we are parsing an attribute
8413
+ (this.decodeMode === DecodingMode.Attribute &&
8414
+ // We shouldn't have consumed any characters after the entity,
8415
+ (valueLength === 0 ||
8416
+ // And there should be no invalid characters.
8417
+ isEntityInAttributeInvalidEnd(char)))
8418
+ ? 0
8419
+ : this.emitNotTerminatedNamedEntity();
8420
+ }
8421
+ current = decodeTree[this.treeIndex];
8422
+ valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;
8423
+ // If the branch is a value, store it and continue
8424
+ if (valueLength !== 0) {
8425
+ // If the entity is terminated by a semicolon, we are done.
8426
+ if (char === CharCodes.SEMI) {
8427
+ return this.emitNamedEntityData(this.treeIndex, valueLength, this.consumed + this.excess);
8191
8428
  }
8429
+ // If we encounter a non-terminated (legacy) entity while parsing strictly, then ignore it.
8430
+ if (this.decodeMode !== DecodingMode.Strict) {
8431
+ this.result = this.treeIndex;
8432
+ this.consumed += this.excess;
8433
+ this.excess = 0;
8434
+ }
8435
+ }
8436
+ }
8437
+ return -1;
8438
+ };
8439
+ /**
8440
+ * Emit a named entity that was not terminated with a semicolon.
8441
+ *
8442
+ * @returns The number of characters consumed.
8443
+ */
8444
+ EntityDecoder.prototype.emitNotTerminatedNamedEntity = function () {
8445
+ var _a;
8446
+ var _b = this, result = _b.result, decodeTree = _b.decodeTree;
8447
+ var valueLength = (decodeTree[result] & BinTrieFlags.VALUE_LENGTH) >> 14;
8448
+ this.emitNamedEntityData(result, valueLength, this.consumed);
8449
+ (_a = this.errors) === null || _a === void 0 ? void 0 : _a.missingSemicolonAfterCharacterReference();
8450
+ return this.consumed;
8451
+ };
8452
+ /**
8453
+ * Emit a named entity.
8454
+ *
8455
+ * @param result The index of the entity in the decode tree.
8456
+ * @param valueLength The number of bytes in the entity.
8457
+ * @param consumed The number of characters consumed.
8458
+ *
8459
+ * @returns The number of characters consumed.
8460
+ */
8461
+ EntityDecoder.prototype.emitNamedEntityData = function (result, valueLength, consumed) {
8462
+ var decodeTree = this.decodeTree;
8463
+ this.emitCodePoint(valueLength === 1
8464
+ ? decodeTree[result] & ~BinTrieFlags.VALUE_LENGTH
8465
+ : decodeTree[result + 1], consumed);
8466
+ if (valueLength === 3) {
8467
+ // For multi-byte values, we need to emit the second byte.
8468
+ this.emitCodePoint(decodeTree[result + 2], consumed);
8469
+ }
8470
+ return consumed;
8471
+ };
8472
+ /**
8473
+ * Signal to the parser that the end of the input was reached.
8474
+ *
8475
+ * Remaining data will be emitted and relevant errors will be produced.
8476
+ *
8477
+ * @returns The number of characters consumed.
8478
+ */
8479
+ EntityDecoder.prototype.end = function () {
8480
+ var _a;
8481
+ switch (this.state) {
8482
+ case EntityDecoderState.NamedEntity: {
8483
+ // Emit a named entity if we have one.
8484
+ return this.result !== 0 &&
8485
+ (this.decodeMode !== DecodingMode.Attribute ||
8486
+ this.result === this.treeIndex)
8487
+ ? this.emitNotTerminatedNamedEntity()
8488
+ : 0;
8489
+ }
8490
+ // Otherwise, emit a numeric entity if we have one.
8491
+ case EntityDecoderState.NumericDecimal: {
8492
+ return this.emitNumericEntity(0, 2);
8493
+ }
8494
+ case EntityDecoderState.NumericHex: {
8495
+ return this.emitNumericEntity(0, 3);
8496
+ }
8497
+ case EntityDecoderState.NumericStart: {
8498
+ (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);
8499
+ return 0;
8192
8500
  }
8193
- if (resultIdx !== 0) {
8194
- var valueLength = (decodeTree[resultIdx] & BinTrieFlags.VALUE_LENGTH) >> 14;
8195
- ret +=
8196
- valueLength === 1
8197
- ? String.fromCharCode(decodeTree[resultIdx] & ~BinTrieFlags.VALUE_LENGTH)
8198
- : valueLength === 2
8199
- ? String.fromCharCode(decodeTree[resultIdx + 1])
8200
- : String.fromCharCode(decodeTree[resultIdx + 1], decodeTree[resultIdx + 2]);
8201
- lastIdx = strIdx - excess + 1;
8501
+ case EntityDecoderState.EntityStart: {
8502
+ // Return 0 if we have no entity.
8503
+ return 0;
8202
8504
  }
8203
8505
  }
8204
- return ret + str.slice(lastIdx);
8506
+ };
8507
+ return EntityDecoder;
8508
+ }());
8509
+ exports.EntityDecoder = EntityDecoder;
8510
+ /**
8511
+ * Creates a function that decodes entities in a string.
8512
+ *
8513
+ * @param decodeTree The decode tree.
8514
+ * @returns A function that decodes entities in a string.
8515
+ */
8516
+ function getDecoder(decodeTree) {
8517
+ var ret = "";
8518
+ var decoder = new EntityDecoder(decodeTree, function (str) { return (ret += (0, decode_codepoint_js_1.fromCodePoint)(str)); });
8519
+ return function decodeWithTrie(str, decodeMode) {
8520
+ var lastIndex = 0;
8521
+ var offset = 0;
8522
+ while ((offset = str.indexOf("&", offset)) >= 0) {
8523
+ ret += str.slice(lastIndex, offset);
8524
+ decoder.startEntity(decodeMode);
8525
+ var len = decoder.write(str,
8526
+ // Skip the "&"
8527
+ offset + 1);
8528
+ if (len < 0) {
8529
+ lastIndex = offset + decoder.end();
8530
+ break;
8531
+ }
8532
+ lastIndex = offset + len;
8533
+ // If `len` is 0, skip the current `&` and continue.
8534
+ offset = len === 0 ? lastIndex + 1 : lastIndex;
8535
+ }
8536
+ var result = ret + str.slice(lastIndex);
8537
+ // Make sure we don't keep a reference to the final string.
8538
+ ret = "";
8539
+ return result;
8205
8540
  };
8206
8541
  }
8542
+ /**
8543
+ * Determines the branch of the current node that is taken given the current
8544
+ * character. This function is used to traverse the trie.
8545
+ *
8546
+ * @param decodeTree The trie.
8547
+ * @param current The current node.
8548
+ * @param nodeIdx The index right after the current node and its value.
8549
+ * @param char The current character.
8550
+ * @returns The index of the next node, or -1 if no branch is taken.
8551
+ */
8207
8552
  function determineBranch(decodeTree, current, nodeIdx, char) {
8208
8553
  var branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;
8209
8554
  var jumpOffset = current & BinTrieFlags.JUMP_TABLE;
@@ -8241,33 +8586,45 @@ exports.determineBranch = determineBranch;
8241
8586
  var htmlDecoder = getDecoder(decode_data_html_js_1.default);
8242
8587
  var xmlDecoder = getDecoder(decode_data_xml_js_1.default);
8243
8588
  /**
8244
- * Decodes an HTML string, allowing for entities not terminated by a semi-colon.
8589
+ * Decodes an HTML string.
8245
8590
  *
8246
8591
  * @param str The string to decode.
8592
+ * @param mode The decoding mode.
8247
8593
  * @returns The decoded string.
8248
8594
  */
8249
- function decodeHTML(str) {
8250
- return htmlDecoder(str, false);
8595
+ function decodeHTML(str, mode) {
8596
+ if (mode === void 0) { mode = DecodingMode.Legacy; }
8597
+ return htmlDecoder(str, mode);
8251
8598
  }
8252
8599
  exports.decodeHTML = decodeHTML;
8253
8600
  /**
8254
- * Decodes an HTML string, requiring all entities to be terminated by a semi-colon.
8601
+ * Decodes an HTML string in an attribute.
8602
+ *
8603
+ * @param str The string to decode.
8604
+ * @returns The decoded string.
8605
+ */
8606
+ function decodeHTMLAttribute(str) {
8607
+ return htmlDecoder(str, DecodingMode.Attribute);
8608
+ }
8609
+ exports.decodeHTMLAttribute = decodeHTMLAttribute;
8610
+ /**
8611
+ * Decodes an HTML string, requiring all entities to be terminated by a semicolon.
8255
8612
  *
8256
8613
  * @param str The string to decode.
8257
8614
  * @returns The decoded string.
8258
8615
  */
8259
8616
  function decodeHTMLStrict(str) {
8260
- return htmlDecoder(str, true);
8617
+ return htmlDecoder(str, DecodingMode.Strict);
8261
8618
  }
8262
8619
  exports.decodeHTMLStrict = decodeHTMLStrict;
8263
8620
  /**
8264
- * Decodes an XML string, requiring all entities to be terminated by a semi-colon.
8621
+ * Decodes an XML string, requiring all entities to be terminated by a semicolon.
8265
8622
  *
8266
8623
  * @param str The string to decode.
8267
8624
  * @returns The decoded string.
8268
8625
  */
8269
8626
  function decodeXML(str) {
8270
- return xmlDecoder(str, true);
8627
+ return xmlDecoder(str, DecodingMode.Strict);
8271
8628
  }
8272
8629
  exports.decodeXML = decodeXML;
8273
8630
  //# sourceMappingURL=decode.js.map
@@ -8285,6 +8642,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
8285
8642
  exports.replaceCodePoint = exports.fromCodePoint = void 0;
8286
8643
  var decodeMap = new Map([
8287
8644
  [0, 65533],
8645
+ // C1 Unicode control character reference replacements
8288
8646
  [128, 8364],
8289
8647
  [130, 8218],
8290
8648
  [131, 402],
@@ -8313,6 +8671,9 @@ var decodeMap = new Map([
8313
8671
  [158, 382],
8314
8672
  [159, 376],
8315
8673
  ]);
8674
+ /**
8675
+ * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point.
8676
+ */
8316
8677
  exports.fromCodePoint =
8317
8678
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins
8318
8679
  (_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (codePoint) {
@@ -8325,6 +8686,11 @@ exports.fromCodePoint =
8325
8686
  output += String.fromCharCode(codePoint);
8326
8687
  return output;
8327
8688
  };
8689
+ /**
8690
+ * Replace the given code point with a replacement character if it is a
8691
+ * surrogate or is outside the valid range. Otherwise return the code
8692
+ * point unchanged.
8693
+ */
8328
8694
  function replaceCodePoint(codePoint) {
8329
8695
  var _a;
8330
8696
  if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
@@ -8333,6 +8699,13 @@ function replaceCodePoint(codePoint) {
8333
8699
  return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;
8334
8700
  }
8335
8701
  exports.replaceCodePoint = replaceCodePoint;
8702
+ /**
8703
+ * Replace the code point if relevant, then convert it to a string.
8704
+ *
8705
+ * @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead.
8706
+ * @param codePoint The code point to decode.
8707
+ * @returns The decoded code point.
8708
+ */
8336
8709
  function decodeCodePoint(codePoint) {
8337
8710
  return (0, exports.fromCodePoint)(replaceCodePoint(codePoint));
8338
8711
  }
@@ -8407,7 +8780,7 @@ function encodeHTMLTrieRe(regExp, str) {
8407
8780
  }
8408
8781
  next = next.v;
8409
8782
  }
8410
- // We might have a tree node without a value; skip and use a numeric entitiy.
8783
+ // We might have a tree node without a value; skip and use a numeric entity.
8411
8784
  if (next !== undefined) {
8412
8785
  ret += next;
8413
8786
  lastIdx = i + 1;
@@ -8492,6 +8865,16 @@ exports.encodeXML = encodeXML;
8492
8865
  * @param data String to escape.
8493
8866
  */
8494
8867
  exports.escape = encodeXML;
8868
+ /**
8869
+ * Creates a function that escapes all characters matched by the given regular
8870
+ * expression using the given map of characters to escape to their entities.
8871
+ *
8872
+ * @param regex Regular expression to match characters to escape.
8873
+ * @param map Map of characters to escape to their entities.
8874
+ *
8875
+ * @returns Function that escapes all characters matched by the given regular
8876
+ * expression using the given map of characters to escape to their entities.
8877
+ */
8495
8878
  function getEscaper(regex, map) {
8496
8879
  return function escape(data) {
8497
8880
  var match;
@@ -8501,7 +8884,7 @@ function getEscaper(regex, map) {
8501
8884
  if (lastIdx !== match.index) {
8502
8885
  result += data.substring(lastIdx, match.index);
8503
8886
  }
8504
- // We know that this chararcter will be in the map.
8887
+ // We know that this character will be in the map.
8505
8888
  result += map.get(match[0].charCodeAt(0));
8506
8889
  // Every match will be of length 1
8507
8890
  lastIdx = match.index + 1;
@@ -8601,7 +8984,7 @@ exports["default"] = new Map(/* #__PURE__ */ restoreDiff([[9, "&Tab;"], [0, "&Ne
8601
8984
  "use strict";
8602
8985
 
8603
8986
  Object.defineProperty(exports, "__esModule", ({ value: true }));
8604
- exports.decodeXMLStrict = exports.decodeHTML5Strict = exports.decodeHTML4Strict = exports.decodeHTML5 = exports.decodeHTML4 = exports.decodeHTMLStrict = exports.decodeHTML = exports.decodeXML = exports.encodeHTML5 = exports.encodeHTML4 = exports.encodeNonAsciiHTML = exports.encodeHTML = exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeXML = exports.encode = exports.decodeStrict = exports.decode = exports.EncodingMode = exports.DecodingMode = exports.EntityLevel = void 0;
8987
+ exports.decodeXMLStrict = exports.decodeHTML5Strict = exports.decodeHTML4Strict = exports.decodeHTML5 = exports.decodeHTML4 = exports.decodeHTMLAttribute = exports.decodeHTMLStrict = exports.decodeHTML = exports.decodeXML = exports.DecodingMode = exports.EntityDecoder = exports.encodeHTML5 = exports.encodeHTML4 = exports.encodeNonAsciiHTML = exports.encodeHTML = exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeXML = exports.encode = exports.decodeStrict = exports.decode = exports.EncodingMode = exports.EntityLevel = void 0;
8605
8988
  var decode_js_1 = __webpack_require__(80624);
8606
8989
  var encode_js_1 = __webpack_require__(12031);
8607
8990
  var escape_js_1 = __webpack_require__(60170);
@@ -8613,14 +8996,6 @@ var EntityLevel;
8613
8996
  /** Support HTML entities, which are a superset of XML entities. */
8614
8997
  EntityLevel[EntityLevel["HTML"] = 1] = "HTML";
8615
8998
  })(EntityLevel = exports.EntityLevel || (exports.EntityLevel = {}));
8616
- /** Determines whether some entities are allowed to be written without a trailing `;`. */
8617
- var DecodingMode;
8618
- (function (DecodingMode) {
8619
- /** Support legacy HTML entities. */
8620
- DecodingMode[DecodingMode["Legacy"] = 0] = "Legacy";
8621
- /** Do not support legacy HTML entities. */
8622
- DecodingMode[DecodingMode["Strict"] = 1] = "Strict";
8623
- })(DecodingMode = exports.DecodingMode || (exports.DecodingMode = {}));
8624
8999
  var EncodingMode;
8625
9000
  (function (EncodingMode) {
8626
9001
  /**
@@ -8658,12 +9033,10 @@ var EncodingMode;
8658
9033
  */
8659
9034
  function decode(data, options) {
8660
9035
  if (options === void 0) { options = EntityLevel.XML; }
8661
- var opts = typeof options === "number" ? { level: options } : options;
8662
- if (opts.level === EntityLevel.HTML) {
8663
- if (opts.mode === DecodingMode.Strict) {
8664
- return (0, decode_js_1.decodeHTMLStrict)(data);
8665
- }
8666
- return (0, decode_js_1.decodeHTML)(data);
9036
+ var level = typeof options === "number" ? options : options.level;
9037
+ if (level === EntityLevel.HTML) {
9038
+ var mode = typeof options === "object" ? options.mode : undefined;
9039
+ return (0, decode_js_1.decodeHTML)(data, mode);
8667
9040
  }
8668
9041
  return (0, decode_js_1.decodeXML)(data);
8669
9042
  }
@@ -8676,15 +9049,11 @@ exports.decode = decode;
8676
9049
  * @deprecated Use `decode` with the `mode` set to `Strict`.
8677
9050
  */
8678
9051
  function decodeStrict(data, options) {
9052
+ var _a;
8679
9053
  if (options === void 0) { options = EntityLevel.XML; }
8680
9054
  var opts = typeof options === "number" ? { level: options } : options;
8681
- if (opts.level === EntityLevel.HTML) {
8682
- if (opts.mode === DecodingMode.Legacy) {
8683
- return (0, decode_js_1.decodeHTML)(data);
8684
- }
8685
- return (0, decode_js_1.decodeHTMLStrict)(data);
8686
- }
8687
- return (0, decode_js_1.decodeXML)(data);
9055
+ (_a = opts.mode) !== null && _a !== void 0 ? _a : (opts.mode = decode_js_1.DecodingMode.Strict);
9056
+ return decode(data, opts);
8688
9057
  }
8689
9058
  exports.decodeStrict = decodeStrict;
8690
9059
  /**
@@ -8726,9 +9095,12 @@ Object.defineProperty(exports, "encodeNonAsciiHTML", ({ enumerable: true, get: f
8726
9095
  Object.defineProperty(exports, "encodeHTML4", ({ enumerable: true, get: function () { return encode_js_2.encodeHTML; } }));
8727
9096
  Object.defineProperty(exports, "encodeHTML5", ({ enumerable: true, get: function () { return encode_js_2.encodeHTML; } }));
8728
9097
  var decode_js_2 = __webpack_require__(80624);
9098
+ Object.defineProperty(exports, "EntityDecoder", ({ enumerable: true, get: function () { return decode_js_2.EntityDecoder; } }));
9099
+ Object.defineProperty(exports, "DecodingMode", ({ enumerable: true, get: function () { return decode_js_2.DecodingMode; } }));
8729
9100
  Object.defineProperty(exports, "decodeXML", ({ enumerable: true, get: function () { return decode_js_2.decodeXML; } }));
8730
9101
  Object.defineProperty(exports, "decodeHTML", ({ enumerable: true, get: function () { return decode_js_2.decodeHTML; } }));
8731
9102
  Object.defineProperty(exports, "decodeHTMLStrict", ({ enumerable: true, get: function () { return decode_js_2.decodeHTMLStrict; } }));
9103
+ Object.defineProperty(exports, "decodeHTMLAttribute", ({ enumerable: true, get: function () { return decode_js_2.decodeHTMLAttribute; } }));
8732
9104
  // Legacy aliases (deprecated)
8733
9105
  Object.defineProperty(exports, "decodeHTML4", ({ enumerable: true, get: function () { return decode_js_2.decodeHTML; } }));
8734
9106
  Object.defineProperty(exports, "decodeHTML5", ({ enumerable: true, get: function () { return decode_js_2.decodeHTML; } }));