@bigbinary/neeto-molecules 4.1.41 → 4.1.43

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 (74) hide show
  1. package/dist/BrowserSupport.js +1 -1
  2. package/dist/DownloadMobileAppCallout.js +1 -1
  3. package/dist/ErrorPage.js +3 -3
  4. package/dist/ErrorPage.js.map +1 -1
  5. package/dist/FloatingActionMenu.js +3 -3
  6. package/dist/FloatingActionMenu.js.map +1 -1
  7. package/dist/KeyboardShortcuts.js +2 -2
  8. package/dist/ProductEmbed.js +15 -15
  9. package/dist/ProductEmbed.js.map +1 -1
  10. package/dist/ShareViaLink.js +446 -179
  11. package/dist/ShareViaLink.js.map +1 -1
  12. package/dist/Sidebar.js +1 -1
  13. package/dist/StickyRibbonsContainer.js +3 -3
  14. package/dist/StickyRibbonsContainer.js.map +1 -1
  15. package/dist/cjs/BrowserSupport.js +1 -1
  16. package/dist/cjs/DownloadMobileAppCallout.js +1 -1
  17. package/dist/cjs/ErrorPage.js +2 -2
  18. package/dist/cjs/ErrorPage.js.map +1 -1
  19. package/dist/cjs/FloatingActionMenu.js +3 -3
  20. package/dist/cjs/FloatingActionMenu.js.map +1 -1
  21. package/dist/cjs/KeyboardShortcuts.js +2 -2
  22. package/dist/cjs/ProductEmbed.js +14 -14
  23. package/dist/cjs/ProductEmbed.js.map +1 -1
  24. package/dist/cjs/ShareViaLink.js +446 -179
  25. package/dist/cjs/ShareViaLink.js.map +1 -1
  26. package/dist/cjs/Sidebar.js +1 -1
  27. package/dist/cjs/StickyRibbonsContainer.js +2 -2
  28. package/dist/cjs/StickyRibbonsContainer.js.map +1 -1
  29. package/dist/cjs/{ua-parser-E0eEtHJZ.js → ua-parser-DgQ3nYoO.js} +327 -306
  30. package/dist/cjs/ua-parser-DgQ3nYoO.js.map +1 -0
  31. package/dist/cjs/{useKeyboardShortcutsPaneState-YnXpWOcs.js → useKeyboardShortcutsPaneState-BrgdLb9F.js} +3 -3
  32. package/dist/cjs/{useKeyboardShortcutsPaneState-YnXpWOcs.js.map → useKeyboardShortcutsPaneState-BrgdLb9F.js.map} +1 -1
  33. package/dist/{ua-parser-rRwDJPFB.js → ua-parser-OzUiuIwt.js} +327 -306
  34. package/dist/ua-parser-OzUiuIwt.js.map +1 -0
  35. package/dist/{useKeyboardShortcutsPaneState-C_eLceJQ.js → useKeyboardShortcutsPaneState-Ckzn5mVZ.js} +4 -4
  36. package/dist/{useKeyboardShortcutsPaneState-C_eLceJQ.js.map → useKeyboardShortcutsPaneState-Ckzn5mVZ.js.map} +1 -1
  37. package/package.json +57 -57
  38. package/src/translations/ar.json +7 -0
  39. package/src/translations/bg.json +7 -0
  40. package/src/translations/ca.json +7 -0
  41. package/src/translations/cs.json +7 -0
  42. package/src/translations/da.json +7 -0
  43. package/src/translations/de.json +7 -0
  44. package/src/translations/es-MX.json +7 -0
  45. package/src/translations/es.json +7 -0
  46. package/src/translations/et.json +7 -0
  47. package/src/translations/fi.json +7 -0
  48. package/src/translations/fil.json +7 -0
  49. package/src/translations/fr.json +7 -0
  50. package/src/translations/he.json +7 -0
  51. package/src/translations/hi.json +7 -0
  52. package/src/translations/hr.json +7 -0
  53. package/src/translations/hu.json +7 -0
  54. package/src/translations/id.json +7 -0
  55. package/src/translations/it.json +7 -0
  56. package/src/translations/ja.json +7 -0
  57. package/src/translations/ko.json +7 -0
  58. package/src/translations/nl.json +7 -0
  59. package/src/translations/pl.json +7 -0
  60. package/src/translations/pt-BR.json +7 -0
  61. package/src/translations/pt.json +7 -0
  62. package/src/translations/ro.json +7 -0
  63. package/src/translations/ru.json +7 -0
  64. package/src/translations/sk.json +7 -0
  65. package/src/translations/sl.json +7 -0
  66. package/src/translations/sv.json +7 -0
  67. package/src/translations/th.json +7 -0
  68. package/src/translations/tr.json +7 -0
  69. package/src/translations/uk.json +7 -0
  70. package/src/translations/vi.json +7 -0
  71. package/src/translations/zh-CN.json +7 -0
  72. package/src/translations/zh-TW.json +7 -0
  73. package/dist/cjs/ua-parser-E0eEtHJZ.js.map +0 -1
  74. package/dist/ua-parser-rRwDJPFB.js.map +0 -1
@@ -785,11 +785,19 @@ var __objRest = (source, exclude) => {
785
785
  */
786
786
  var qrcodegen;
787
787
  ((qrcodegen2) => {
788
- const _QrCode = class {
788
+ const _QrCode = class _QrCode {
789
+ /*-- Constructor (low level) and fields --*/
790
+ // Creates a new QR Code with the given version number,
791
+ // error correction level, data codeword bytes, and mask number.
792
+ // This is a low-level API that most users should not use directly.
793
+ // A mid-level API is the encodeSegments() function.
789
794
  constructor(version, errorCorrectionLevel, dataCodewords, msk) {
790
795
  this.version = version;
791
796
  this.errorCorrectionLevel = errorCorrectionLevel;
797
+ // The modules of this QR Code (false = light, true = dark).
798
+ // Immutable after constructor finishes. Accessed through getModule().
792
799
  this.modules = [];
800
+ // Indicates function modules that are not subjected to masking. Discarded when constructor finishes.
793
801
  this.isFunction = [];
794
802
  if (version < _QrCode.MIN_VERSION || version > _QrCode.MAX_VERSION)
795
803
  throw new RangeError("Version value out of range");
@@ -825,14 +833,34 @@ var qrcodegen;
825
833
  this.drawFormatBits(msk);
826
834
  this.isFunction = [];
827
835
  }
836
+ /*-- Static factory functions (high level) --*/
837
+ // Returns a QR Code representing the given Unicode text string at the given error correction level.
838
+ // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
839
+ // Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
840
+ // QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
841
+ // ecl argument if it can be done without increasing the version.
828
842
  static encodeText(text, ecl) {
829
843
  const segs = qrcodegen2.QrSegment.makeSegments(text);
830
844
  return _QrCode.encodeSegments(segs, ecl);
831
845
  }
846
+ // Returns a QR Code representing the given binary data at the given error correction level.
847
+ // This function always encodes using the binary segment mode, not any text mode. The maximum number of
848
+ // bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
849
+ // The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
832
850
  static encodeBinary(data, ecl) {
833
851
  const seg = qrcodegen2.QrSegment.makeBytes(data);
834
852
  return _QrCode.encodeSegments([seg], ecl);
835
853
  }
854
+ /*-- Static factory functions (mid level) --*/
855
+ // Returns a QR Code representing the given segments with the given encoding parameters.
856
+ // The smallest possible QR Code version within the given range is automatically
857
+ // chosen for the output. Iff boostEcl is true, then the ECC level of the result
858
+ // may be higher than the ecl argument if it can be done without increasing the
859
+ // version. The mask number is either between 0 to 7 (inclusive) to force that
860
+ // mask, or -1 to automatically choose an appropriate mask (which may be slow).
861
+ // This function allows the user to create a custom sequence of segments that switches
862
+ // between modes (such as alphanumeric and byte) to encode text in less space.
863
+ // This is a mid-level API; the high-level API is encodeText() and encodeBinary().
836
864
  static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
837
865
  if (!(_QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= _QrCode.MAX_VERSION) || mask < -1 || mask > 7)
838
866
  throw new RangeError("Invalid value");
@@ -873,12 +901,19 @@ var qrcodegen;
873
901
  bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
874
902
  return new _QrCode(version, ecl, dataCodewords, mask);
875
903
  }
904
+ /*-- Accessor methods --*/
905
+ // Returns the color of the module (pixel) at the given coordinates, which is false
906
+ // for light or true for dark. The top left corner has the coordinates (x=0, y=0).
907
+ // If the given coordinates are out of bounds, then false (light) is returned.
876
908
  getModule(x, y) {
877
909
  return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
878
910
  }
911
+ // Modified to expose modules for easy access
879
912
  getModules() {
880
913
  return this.modules;
881
914
  }
915
+ /*-- Private helper methods for constructor: Drawing function modules --*/
916
+ // Reads this object's version field, and draws and marks all function modules.
882
917
  drawFunctionPatterns() {
883
918
  for (let i = 0; i < this.size; i++) {
884
919
  this.setFunctionModule(6, i, i % 2 == 0);
@@ -898,6 +933,8 @@ var qrcodegen;
898
933
  this.drawFormatBits(0);
899
934
  this.drawVersion();
900
935
  }
936
+ // Draws two copies of the format bits (with its own error correction code)
937
+ // based on the given mask and this object's error correction level field.
901
938
  drawFormatBits(mask) {
902
939
  const data = this.errorCorrectionLevel.formatBits << 3 | mask;
903
940
  let rem = data;
@@ -918,6 +955,8 @@ var qrcodegen;
918
955
  this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
919
956
  this.setFunctionModule(8, this.size - 8, true);
920
957
  }
958
+ // Draws two copies of the version bits (with its own error correction code),
959
+ // based on this object's version field, iff 7 <= version <= 40.
921
960
  drawVersion() {
922
961
  if (this.version < 7)
923
962
  return;
@@ -934,6 +973,8 @@ var qrcodegen;
934
973
  this.setFunctionModule(b, a, color);
935
974
  }
936
975
  }
976
+ // Draws a 9*9 finder pattern including the border separator,
977
+ // with the center module at (x, y). Modules can be out of bounds.
937
978
  drawFinderPattern(x, y) {
938
979
  for (let dy = -4; dy <= 4; dy++) {
939
980
  for (let dx = -4; dx <= 4; dx++) {
@@ -945,16 +986,23 @@ var qrcodegen;
945
986
  }
946
987
  }
947
988
  }
989
+ // Draws a 5*5 alignment pattern, with the center module
990
+ // at (x, y). All modules must be in bounds.
948
991
  drawAlignmentPattern(x, y) {
949
992
  for (let dy = -2; dy <= 2; dy++) {
950
993
  for (let dx = -2; dx <= 2; dx++)
951
994
  this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
952
995
  }
953
996
  }
997
+ // Sets the color of a module and marks it as a function module.
998
+ // Only used by the constructor. Coordinates must be in bounds.
954
999
  setFunctionModule(x, y, isDark) {
955
1000
  this.modules[y][x] = isDark;
956
1001
  this.isFunction[y][x] = true;
957
1002
  }
1003
+ /*-- Private helper methods for constructor: Codewords and masking --*/
1004
+ // Returns a new byte string representing the given data with the appropriate error correction
1005
+ // codewords appended to it, based on this object's version and error correction level.
958
1006
  addEccAndInterleave(data) {
959
1007
  const ver = this.version;
960
1008
  const ecl = this.errorCorrectionLevel;
@@ -985,6 +1033,8 @@ var qrcodegen;
985
1033
  assert(result.length == rawCodewords);
986
1034
  return result;
987
1035
  }
1036
+ // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
1037
+ // data area of this QR Code. Function modules need to be marked off before this is called.
988
1038
  drawCodewords(data) {
989
1039
  if (data.length != Math.floor(_QrCode.getNumRawDataModules(this.version) / 8))
990
1040
  throw new RangeError("Invalid argument");
@@ -1006,6 +1056,11 @@ var qrcodegen;
1006
1056
  }
1007
1057
  assert(i == data.length * 8);
1008
1058
  }
1059
+ // XORs the codeword modules in this QR Code with the given mask pattern.
1060
+ // The function modules must be marked and the codeword bits must be drawn
1061
+ // before masking. Due to the arithmetic of XOR, calling applyMask() with
1062
+ // the same mask value a second time will undo the mask. A final well-formed
1063
+ // QR Code needs exactly one (not zero, two, etc.) mask applied.
1009
1064
  applyMask(mask) {
1010
1065
  if (mask < 0 || mask > 7)
1011
1066
  throw new RangeError("Mask value out of range");
@@ -1045,6 +1100,8 @@ var qrcodegen;
1045
1100
  }
1046
1101
  }
1047
1102
  }
1103
+ // Calculates and returns the penalty score based on state of this QR Code's current modules.
1104
+ // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
1048
1105
  getPenaltyScore() {
1049
1106
  let result = 0;
1050
1107
  for (let y = 0; y < this.size; y++) {
@@ -1106,6 +1163,10 @@ var qrcodegen;
1106
1163
  assert(0 <= result && result <= 2568888);
1107
1164
  return result;
1108
1165
  }
1166
+ /*-- Private helper functions --*/
1167
+ // Returns an ascending list of positions of alignment patterns for this version number.
1168
+ // Each position is in the range [0,177), and are used on both the x and y axes.
1169
+ // This could be implemented as lookup table of 40 variable-length lists of integers.
1109
1170
  getAlignmentPatternPositions() {
1110
1171
  if (this.version == 1)
1111
1172
  return [];
@@ -1118,6 +1179,9 @@ var qrcodegen;
1118
1179
  return result;
1119
1180
  }
1120
1181
  }
1182
+ // Returns the number of data bits that can be stored in a QR Code of the given version number, after
1183
+ // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
1184
+ // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
1121
1185
  static getNumRawDataModules(ver) {
1122
1186
  if (ver < _QrCode.MIN_VERSION || ver > _QrCode.MAX_VERSION)
1123
1187
  throw new RangeError("Version number out of range");
@@ -1131,9 +1195,14 @@ var qrcodegen;
1131
1195
  assert(208 <= result && result <= 29648);
1132
1196
  return result;
1133
1197
  }
1198
+ // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
1199
+ // QR Code of the given version number and error correction level, with remainder bits discarded.
1200
+ // This stateless pure function could be implemented as a (40*4)-cell lookup table.
1134
1201
  static getNumDataCodewords(ver, ecl) {
1135
1202
  return Math.floor(_QrCode.getNumRawDataModules(ver) / 8) - _QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * _QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
1136
1203
  }
1204
+ // Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
1205
+ // implemented as a lookup table over all possible parameter values, instead of as an algorithm.
1137
1206
  static reedSolomonComputeDivisor(degree) {
1138
1207
  if (degree < 1 || degree > 255)
1139
1208
  throw new RangeError("Degree out of range");
@@ -1152,6 +1221,7 @@ var qrcodegen;
1152
1221
  }
1153
1222
  return result;
1154
1223
  }
1224
+ // Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
1155
1225
  static reedSolomonComputeRemainder(data, divisor) {
1156
1226
  let result = divisor.map((_) => 0);
1157
1227
  for (const b of data) {
@@ -1161,6 +1231,8 @@ var qrcodegen;
1161
1231
  }
1162
1232
  return result;
1163
1233
  }
1234
+ // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
1235
+ // are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
1164
1236
  static reedSolomonMultiply(x, y) {
1165
1237
  if (x >>> 8 != 0 || y >>> 8 != 0)
1166
1238
  throw new RangeError("Byte out of range");
@@ -1172,12 +1244,15 @@ var qrcodegen;
1172
1244
  assert(z >>> 8 == 0);
1173
1245
  return z;
1174
1246
  }
1247
+ // Can only be called immediately after a light run is added, and
1248
+ // returns either 0, 1, or 2. A helper function for getPenaltyScore().
1175
1249
  finderPenaltyCountPatterns(runHistory) {
1176
1250
  const n = runHistory[1];
1177
1251
  assert(n <= this.size * 3);
1178
1252
  const core = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n;
1179
1253
  return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
1180
1254
  }
1255
+ // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
1181
1256
  finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
1182
1257
  if (currentRunColor) {
1183
1258
  this.finderPenaltyAddHistory(currentRunLength, runHistory);
@@ -1187,6 +1262,7 @@ var qrcodegen;
1187
1262
  this.finderPenaltyAddHistory(currentRunLength, runHistory);
1188
1263
  return this.finderPenaltyCountPatterns(runHistory);
1189
1264
  }
1265
+ // Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
1190
1266
  finderPenaltyAddHistory(currentRunLength, runHistory) {
1191
1267
  if (runHistory[0] == 0)
1192
1268
  currentRunLength += this.size;
@@ -1194,26 +1270,41 @@ var qrcodegen;
1194
1270
  runHistory.unshift(currentRunLength);
1195
1271
  }
1196
1272
  };
1197
- let QrCode = _QrCode;
1198
- QrCode.MIN_VERSION = 1;
1199
- QrCode.MAX_VERSION = 40;
1200
- QrCode.PENALTY_N1 = 3;
1201
- QrCode.PENALTY_N2 = 3;
1202
- QrCode.PENALTY_N3 = 40;
1203
- QrCode.PENALTY_N4 = 10;
1204
- QrCode.ECC_CODEWORDS_PER_BLOCK = [
1273
+ /*-- Constants and tables --*/
1274
+ // The minimum version number supported in the QR Code Model 2 standard.
1275
+ _QrCode.MIN_VERSION = 1;
1276
+ // The maximum version number supported in the QR Code Model 2 standard.
1277
+ _QrCode.MAX_VERSION = 40;
1278
+ // For use in getPenaltyScore(), when evaluating which mask is best.
1279
+ _QrCode.PENALTY_N1 = 3;
1280
+ _QrCode.PENALTY_N2 = 3;
1281
+ _QrCode.PENALTY_N3 = 40;
1282
+ _QrCode.PENALTY_N4 = 10;
1283
+ _QrCode.ECC_CODEWORDS_PER_BLOCK = [
1284
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
1285
+ //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
1205
1286
  [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
1287
+ // Low
1206
1288
  [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
1289
+ // Medium
1207
1290
  [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
1291
+ // Quartile
1208
1292
  [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
1293
+ // High
1209
1294
  ];
1210
- QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
1295
+ _QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
1296
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
1297
+ //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
1211
1298
  [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
1299
+ // Low
1212
1300
  [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
1301
+ // Medium
1213
1302
  [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
1303
+ // Quartile
1214
1304
  [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81]
1305
+ // High
1215
1306
  ];
1216
- qrcodegen2.QrCode = QrCode;
1307
+ qrcodegen2.QrCode = _QrCode;
1217
1308
  function appendBits(val, len, bb) {
1218
1309
  if (len < 0 || len > 31 || val >>> len != 0)
1219
1310
  throw new RangeError("Value out of range");
@@ -1227,7 +1318,11 @@ var qrcodegen;
1227
1318
  if (!cond)
1228
1319
  throw new Error("Assertion error");
1229
1320
  }
1230
- const _QrSegment = class {
1321
+ const _QrSegment = class _QrSegment {
1322
+ /*-- Constructor (low level) and fields --*/
1323
+ // Creates a new QR Code segment with the given attributes and data.
1324
+ // The character count (numChars) must agree with the mode and the bit buffer length,
1325
+ // but the constraint isn't checked. The given bit buffer is cloned and stored.
1231
1326
  constructor(mode, numChars, bitData) {
1232
1327
  this.mode = mode;
1233
1328
  this.numChars = numChars;
@@ -1236,23 +1331,31 @@ var qrcodegen;
1236
1331
  throw new RangeError("Invalid argument");
1237
1332
  this.bitData = bitData.slice();
1238
1333
  }
1334
+ /*-- Static factory functions (mid level) --*/
1335
+ // Returns a segment representing the given binary data encoded in
1336
+ // byte mode. All input byte arrays are acceptable. Any text string
1337
+ // can be converted to UTF-8 bytes and encoded as a byte mode segment.
1239
1338
  static makeBytes(data) {
1240
1339
  let bb = [];
1241
1340
  for (const b of data)
1242
1341
  appendBits(b, 8, bb);
1243
1342
  return new _QrSegment(_QrSegment.Mode.BYTE, data.length, bb);
1244
1343
  }
1344
+ // Returns a segment representing the given string of decimal digits encoded in numeric mode.
1245
1345
  static makeNumeric(digits) {
1246
1346
  if (!_QrSegment.isNumeric(digits))
1247
1347
  throw new RangeError("String contains non-numeric characters");
1248
1348
  let bb = [];
1249
1349
  for (let i = 0; i < digits.length; ) {
1250
1350
  const n = Math.min(digits.length - i, 3);
1251
- appendBits(parseInt(digits.substr(i, n), 10), n * 3 + 1, bb);
1351
+ appendBits(parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
1252
1352
  i += n;
1253
1353
  }
1254
1354
  return new _QrSegment(_QrSegment.Mode.NUMERIC, digits.length, bb);
1255
1355
  }
1356
+ // Returns a segment representing the given text string encoded in alphanumeric mode.
1357
+ // The characters allowed are: 0 to 9, A to Z (uppercase only), space,
1358
+ // dollar, percent, asterisk, plus, hyphen, period, slash, colon.
1256
1359
  static makeAlphanumeric(text) {
1257
1360
  if (!_QrSegment.isAlphanumeric(text))
1258
1361
  throw new RangeError("String contains unencodable characters in alphanumeric mode");
@@ -1267,6 +1370,8 @@ var qrcodegen;
1267
1370
  appendBits(_QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
1268
1371
  return new _QrSegment(_QrSegment.Mode.ALPHANUMERIC, text.length, bb);
1269
1372
  }
1373
+ // Returns a new mutable list of zero or more segments to represent the given Unicode text string.
1374
+ // The result may use various segment modes and switch modes to optimize the length of the bit stream.
1270
1375
  static makeSegments(text) {
1271
1376
  if (text == "")
1272
1377
  return [];
@@ -1277,6 +1382,8 @@ var qrcodegen;
1277
1382
  else
1278
1383
  return [_QrSegment.makeBytes(_QrSegment.toUtf8ByteArray(text))];
1279
1384
  }
1385
+ // Returns a segment representing an Extended Channel Interpretation
1386
+ // (ECI) designator with the given assignment value.
1280
1387
  static makeEci(assignVal) {
1281
1388
  let bb = [];
1282
1389
  if (assignVal < 0)
@@ -1293,15 +1400,24 @@ var qrcodegen;
1293
1400
  throw new RangeError("ECI assignment value out of range");
1294
1401
  return new _QrSegment(_QrSegment.Mode.ECI, 0, bb);
1295
1402
  }
1403
+ // Tests whether the given string can be encoded as a segment in numeric mode.
1404
+ // A string is encodable iff each character is in the range 0 to 9.
1296
1405
  static isNumeric(text) {
1297
1406
  return _QrSegment.NUMERIC_REGEX.test(text);
1298
1407
  }
1408
+ // Tests whether the given string can be encoded as a segment in alphanumeric mode.
1409
+ // A string is encodable iff each character is in the following set: 0 to 9, A to Z
1410
+ // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
1299
1411
  static isAlphanumeric(text) {
1300
1412
  return _QrSegment.ALPHANUMERIC_REGEX.test(text);
1301
1413
  }
1414
+ /*-- Methods --*/
1415
+ // Returns a new copy of the data bits of this segment.
1302
1416
  getData() {
1303
1417
  return this.bitData.slice();
1304
1418
  }
1419
+ // (Package-private) Calculates and returns the number of bits needed to encode the given segments at
1420
+ // the given version. The result is infinity if a segment has too many characters to fit its length field.
1305
1421
  static getTotalBits(segs, version) {
1306
1422
  let result = 0;
1307
1423
  for (const seg of segs) {
@@ -1312,6 +1428,7 @@ var qrcodegen;
1312
1428
  }
1313
1429
  return result;
1314
1430
  }
1431
+ // Returns a new array of bytes representing the given string encoded in UTF-8.
1315
1432
  static toUtf8ByteArray(str) {
1316
1433
  str = encodeURI(str);
1317
1434
  let result = [];
@@ -1319,53 +1436,67 @@ var qrcodegen;
1319
1436
  if (str.charAt(i) != "%")
1320
1437
  result.push(str.charCodeAt(i));
1321
1438
  else {
1322
- result.push(parseInt(str.substr(i + 1, 2), 16));
1439
+ result.push(parseInt(str.substring(i + 1, i + 3), 16));
1323
1440
  i += 2;
1324
1441
  }
1325
1442
  }
1326
1443
  return result;
1327
1444
  }
1328
1445
  };
1446
+ /*-- Constants --*/
1447
+ // Describes precisely all strings that are encodable in numeric mode.
1448
+ _QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
1449
+ // Describes precisely all strings that are encodable in alphanumeric mode.
1450
+ _QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
1451
+ // The set of all legal characters in alphanumeric mode,
1452
+ // where each character value maps to the index in the string.
1453
+ _QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
1329
1454
  let QrSegment = _QrSegment;
1330
- QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
1331
- QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
1332
- QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
1333
- qrcodegen2.QrSegment = QrSegment;
1455
+ qrcodegen2.QrSegment = _QrSegment;
1334
1456
  })(qrcodegen || (qrcodegen = {}));
1335
1457
  ((qrcodegen2) => {
1336
1458
  ((QrCode2) => {
1337
- const _Ecc = class {
1459
+ const _Ecc = class _Ecc {
1460
+ // The QR Code can tolerate about 30% erroneous codewords
1461
+ /*-- Constructor and fields --*/
1338
1462
  constructor(ordinal, formatBits) {
1339
1463
  this.ordinal = ordinal;
1340
1464
  this.formatBits = formatBits;
1341
1465
  }
1342
1466
  };
1343
- let Ecc = _Ecc;
1344
- Ecc.LOW = new _Ecc(0, 1);
1345
- Ecc.MEDIUM = new _Ecc(1, 0);
1346
- Ecc.QUARTILE = new _Ecc(2, 3);
1347
- Ecc.HIGH = new _Ecc(3, 2);
1348
- QrCode2.Ecc = Ecc;
1467
+ /*-- Constants --*/
1468
+ _Ecc.LOW = new _Ecc(0, 1);
1469
+ // The QR Code can tolerate about 7% erroneous codewords
1470
+ _Ecc.MEDIUM = new _Ecc(1, 0);
1471
+ // The QR Code can tolerate about 15% erroneous codewords
1472
+ _Ecc.QUARTILE = new _Ecc(2, 3);
1473
+ // The QR Code can tolerate about 25% erroneous codewords
1474
+ _Ecc.HIGH = new _Ecc(3, 2);
1475
+ QrCode2.Ecc = _Ecc;
1349
1476
  })(qrcodegen2.QrCode || (qrcodegen2.QrCode = {}));
1350
1477
  })(qrcodegen || (qrcodegen = {}));
1351
1478
  ((qrcodegen2) => {
1352
1479
  ((QrSegment2) => {
1353
- const _Mode = class {
1480
+ const _Mode = class _Mode {
1481
+ /*-- Constructor and fields --*/
1354
1482
  constructor(modeBits, numBitsCharCount) {
1355
1483
  this.modeBits = modeBits;
1356
1484
  this.numBitsCharCount = numBitsCharCount;
1357
1485
  }
1486
+ /*-- Method --*/
1487
+ // (Package-private) Returns the bit width of the character count field for a segment in
1488
+ // this mode in a QR Code at the given version number. The result is in the range [0, 16].
1358
1489
  numCharCountBits(ver) {
1359
1490
  return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
1360
1491
  }
1361
1492
  };
1362
- let Mode = _Mode;
1363
- Mode.NUMERIC = new _Mode(1, [10, 12, 14]);
1364
- Mode.ALPHANUMERIC = new _Mode(2, [9, 11, 13]);
1365
- Mode.BYTE = new _Mode(4, [8, 16, 16]);
1366
- Mode.KANJI = new _Mode(8, [8, 10, 12]);
1367
- Mode.ECI = new _Mode(7, [0, 0, 0]);
1368
- QrSegment2.Mode = Mode;
1493
+ /*-- Constants --*/
1494
+ _Mode.NUMERIC = new _Mode(1, [10, 12, 14]);
1495
+ _Mode.ALPHANUMERIC = new _Mode(2, [9, 11, 13]);
1496
+ _Mode.BYTE = new _Mode(4, [8, 16, 16]);
1497
+ _Mode.KANJI = new _Mode(8, [8, 10, 12]);
1498
+ _Mode.ECI = new _Mode(7, [0, 0, 0]);
1499
+ QrSegment2.Mode = _Mode;
1369
1500
  })(qrcodegen2.QrSegment || (qrcodegen2.QrSegment = {}));
1370
1501
  })(qrcodegen || (qrcodegen = {}));
1371
1502
  var qrcodegen_default = qrcodegen;
@@ -1387,7 +1518,9 @@ var DEFAULT_LEVEL = "L";
1387
1518
  var DEFAULT_BGCOLOR = "#FFFFFF";
1388
1519
  var DEFAULT_FGCOLOR = "#000000";
1389
1520
  var DEFAULT_INCLUDEMARGIN = false;
1390
- var MARGIN_SIZE = 4;
1521
+ var DEFAULT_MINVERSION = 1;
1522
+ var SPEC_MARGIN_SIZE = 4;
1523
+ var DEFAULT_MARGIN_SIZE = 0;
1391
1524
  var DEFAULT_IMG_SCALE = 0.1;
1392
1525
  function generatePath(modules, margin = 0) {
1393
1526
  const ops = [];
@@ -1395,7 +1528,9 @@ function generatePath(modules, margin = 0) {
1395
1528
  let start = null;
1396
1529
  row.forEach(function(cell, x) {
1397
1530
  if (!cell && start !== null) {
1398
- ops.push(`M${start + margin} ${y + margin}h${x - start}v1H${start + margin}z`);
1531
+ ops.push(
1532
+ `M${start + margin} ${y + margin}h${x - start}v1H${start + margin}z`
1533
+ );
1399
1534
  start = null;
1400
1535
  return;
1401
1536
  }
@@ -1406,7 +1541,9 @@ function generatePath(modules, margin = 0) {
1406
1541
  if (start === null) {
1407
1542
  ops.push(`M${x + margin},${y + margin} h1v1H${x + margin}z`);
1408
1543
  } else {
1409
- ops.push(`M${start + margin},${y + margin} h${x + 1 - start}v1H${start + margin}z`);
1544
+ ops.push(
1545
+ `M${start + margin},${y + margin} h${x + 1 - start}v1H${start + margin}z`
1546
+ );
1410
1547
  }
1411
1548
  return;
1412
1549
  }
@@ -1430,11 +1567,10 @@ function excavateModules(modules, excavation) {
1430
1567
  });
1431
1568
  });
1432
1569
  }
1433
- function getImageSettings(cells, size, includeMargin, imageSettings) {
1570
+ function getImageSettings(cells, size, margin, imageSettings) {
1434
1571
  if (imageSettings == null) {
1435
1572
  return null;
1436
1573
  }
1437
- const margin = includeMargin ? MARGIN_SIZE : 0;
1438
1574
  const numCells = cells.length + margin * 2;
1439
1575
  const defaultSize = Math.floor(size * DEFAULT_IMG_SCALE);
1440
1576
  const scale = numCells / size;
@@ -1442,6 +1578,7 @@ function getImageSettings(cells, size, includeMargin, imageSettings) {
1442
1578
  const h = (imageSettings.height || defaultSize) * scale;
1443
1579
  const x = imageSettings.x == null ? cells.length / 2 - w / 2 : imageSettings.x * scale;
1444
1580
  const y = imageSettings.y == null ? cells.length / 2 - h / 2 : imageSettings.y * scale;
1581
+ const opacity = imageSettings.opacity == null ? 1 : imageSettings.opacity;
1445
1582
  let excavation = null;
1446
1583
  if (imageSettings.excavate) {
1447
1584
  let floorX = Math.floor(x);
@@ -1450,7 +1587,64 @@ function getImageSettings(cells, size, includeMargin, imageSettings) {
1450
1587
  let ceilH = Math.ceil(h + y - floorY);
1451
1588
  excavation = { x: floorX, y: floorY, w: ceilW, h: ceilH };
1452
1589
  }
1453
- return { x, y, h, w, excavation };
1590
+ const crossOrigin = imageSettings.crossOrigin;
1591
+ return { x, y, h, w, excavation, opacity, crossOrigin };
1592
+ }
1593
+ function getMarginSize(includeMargin, marginSize) {
1594
+ if (marginSize != null) {
1595
+ return Math.max(Math.floor(marginSize), 0);
1596
+ }
1597
+ return includeMargin ? SPEC_MARGIN_SIZE : DEFAULT_MARGIN_SIZE;
1598
+ }
1599
+ function useQRCode({
1600
+ value,
1601
+ level,
1602
+ minVersion,
1603
+ includeMargin,
1604
+ marginSize,
1605
+ imageSettings,
1606
+ size,
1607
+ boostLevel
1608
+ }) {
1609
+ let qrcode = React__default.useMemo(() => {
1610
+ const values = Array.isArray(value) ? value : [value];
1611
+ const segments = values.reduce((accum, v) => {
1612
+ accum.push(...qrcodegen_default.QrSegment.makeSegments(v));
1613
+ return accum;
1614
+ }, []);
1615
+ return qrcodegen_default.QrCode.encodeSegments(
1616
+ segments,
1617
+ ERROR_LEVEL_MAP[level],
1618
+ minVersion,
1619
+ void 0,
1620
+ void 0,
1621
+ boostLevel
1622
+ );
1623
+ }, [value, level, minVersion, boostLevel]);
1624
+ const { cells, margin, numCells, calculatedImageSettings } = React__default.useMemo(() => {
1625
+ let cells2 = qrcode.getModules();
1626
+ const margin2 = getMarginSize(includeMargin, marginSize);
1627
+ const numCells2 = cells2.length + margin2 * 2;
1628
+ const calculatedImageSettings2 = getImageSettings(
1629
+ cells2,
1630
+ size,
1631
+ margin2,
1632
+ imageSettings
1633
+ );
1634
+ return {
1635
+ cells: cells2,
1636
+ margin: margin2,
1637
+ numCells: numCells2,
1638
+ calculatedImageSettings: calculatedImageSettings2
1639
+ };
1640
+ }, [qrcode, size, imageSettings, includeMargin, marginSize]);
1641
+ return {
1642
+ qrcode,
1643
+ margin,
1644
+ cells,
1645
+ numCells,
1646
+ calculatedImageSettings
1647
+ };
1454
1648
  }
1455
1649
  var SUPPORTS_PATH2D = function() {
1456
1650
  try {
@@ -1460,152 +1654,225 @@ var SUPPORTS_PATH2D = function() {
1460
1654
  }
1461
1655
  return true;
1462
1656
  }();
1463
- function QRCodeCanvas(props) {
1464
- const _a = props, {
1465
- value,
1466
- size = DEFAULT_SIZE,
1467
- level = DEFAULT_LEVEL,
1468
- bgColor = DEFAULT_BGCOLOR,
1469
- fgColor = DEFAULT_FGCOLOR,
1470
- includeMargin = DEFAULT_INCLUDEMARGIN,
1471
- style,
1472
- imageSettings
1473
- } = _a, otherProps = __objRest(_a, [
1474
- "value",
1475
- "size",
1476
- "level",
1477
- "bgColor",
1478
- "fgColor",
1479
- "includeMargin",
1480
- "style",
1481
- "imageSettings"
1482
- ]);
1483
- const imgSrc = imageSettings == null ? void 0 : imageSettings.src;
1484
- const _canvas = React__default.useRef(null);
1485
- const _image = React__default.useRef(null);
1486
- const [isImgLoaded, setIsImageLoaded] = React__default.useState(false);
1487
- React__default.useEffect(() => {
1488
- if (_canvas.current != null) {
1489
- const canvas = _canvas.current;
1490
- const ctx = canvas.getContext("2d");
1491
- if (!ctx) {
1492
- return;
1493
- }
1494
- let cells = qrcodegen_default.QrCode.encodeText(value, ERROR_LEVEL_MAP[level]).getModules();
1495
- const margin = includeMargin ? MARGIN_SIZE : 0;
1496
- const numCells = cells.length + margin * 2;
1497
- const calculatedImageSettings = getImageSettings(cells, size, includeMargin, imageSettings);
1498
- const image = _image.current;
1499
- const haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
1500
- if (haveImageToRender) {
1501
- if (calculatedImageSettings.excavation != null) {
1502
- cells = excavateModules(cells, calculatedImageSettings.excavation);
1657
+ var QRCodeCanvas = React__default.forwardRef(
1658
+ function QRCodeCanvas2(props, forwardedRef) {
1659
+ const _a = props, {
1660
+ value,
1661
+ size = DEFAULT_SIZE,
1662
+ level = DEFAULT_LEVEL,
1663
+ bgColor = DEFAULT_BGCOLOR,
1664
+ fgColor = DEFAULT_FGCOLOR,
1665
+ includeMargin = DEFAULT_INCLUDEMARGIN,
1666
+ minVersion = DEFAULT_MINVERSION,
1667
+ boostLevel,
1668
+ marginSize,
1669
+ imageSettings
1670
+ } = _a, extraProps = __objRest(_a, [
1671
+ "value",
1672
+ "size",
1673
+ "level",
1674
+ "bgColor",
1675
+ "fgColor",
1676
+ "includeMargin",
1677
+ "minVersion",
1678
+ "boostLevel",
1679
+ "marginSize",
1680
+ "imageSettings"
1681
+ ]);
1682
+ const _b = extraProps, { style } = _b, otherProps = __objRest(_b, ["style"]);
1683
+ const imgSrc = imageSettings == null ? void 0 : imageSettings.src;
1684
+ const _canvas = React__default.useRef(null);
1685
+ const _image = React__default.useRef(null);
1686
+ const setCanvasRef = React__default.useCallback(
1687
+ (node) => {
1688
+ _canvas.current = node;
1689
+ if (typeof forwardedRef === "function") {
1690
+ forwardedRef(node);
1691
+ } else if (forwardedRef) {
1692
+ forwardedRef.current = node;
1503
1693
  }
1504
- }
1505
- const pixelRatio = window.devicePixelRatio || 1;
1506
- canvas.height = canvas.width = size * pixelRatio;
1507
- const scale = size / numCells * pixelRatio;
1508
- ctx.scale(scale, scale);
1509
- ctx.fillStyle = bgColor;
1510
- ctx.fillRect(0, 0, numCells, numCells);
1511
- ctx.fillStyle = fgColor;
1512
- if (SUPPORTS_PATH2D) {
1513
- ctx.fill(new Path2D(generatePath(cells, margin)));
1514
- } else {
1515
- cells.forEach(function(row, rdx) {
1516
- row.forEach(function(cell, cdx) {
1517
- if (cell) {
1518
- ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
1519
- }
1694
+ },
1695
+ [forwardedRef]
1696
+ );
1697
+ const [isImgLoaded, setIsImageLoaded] = React__default.useState(false);
1698
+ const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
1699
+ value,
1700
+ level,
1701
+ minVersion,
1702
+ boostLevel,
1703
+ includeMargin,
1704
+ marginSize,
1705
+ imageSettings,
1706
+ size
1707
+ });
1708
+ React__default.useEffect(() => {
1709
+ if (_canvas.current != null) {
1710
+ const canvas = _canvas.current;
1711
+ const ctx = canvas.getContext("2d");
1712
+ if (!ctx) {
1713
+ return;
1714
+ }
1715
+ let cellsToDraw = cells;
1716
+ const image = _image.current;
1717
+ const haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
1718
+ if (haveImageToRender) {
1719
+ if (calculatedImageSettings.excavation != null) {
1720
+ cellsToDraw = excavateModules(
1721
+ cells,
1722
+ calculatedImageSettings.excavation
1723
+ );
1724
+ }
1725
+ }
1726
+ const pixelRatio = window.devicePixelRatio || 1;
1727
+ canvas.height = canvas.width = size * pixelRatio;
1728
+ const scale = size / numCells * pixelRatio;
1729
+ ctx.scale(scale, scale);
1730
+ ctx.fillStyle = bgColor;
1731
+ ctx.fillRect(0, 0, numCells, numCells);
1732
+ ctx.fillStyle = fgColor;
1733
+ if (SUPPORTS_PATH2D) {
1734
+ ctx.fill(new Path2D(generatePath(cellsToDraw, margin)));
1735
+ } else {
1736
+ cells.forEach(function(row, rdx) {
1737
+ row.forEach(function(cell, cdx) {
1738
+ if (cell) {
1739
+ ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
1740
+ }
1741
+ });
1520
1742
  });
1521
- });
1522
- }
1523
- if (haveImageToRender) {
1524
- ctx.drawImage(image, calculatedImageSettings.x + margin, calculatedImageSettings.y + margin, calculatedImageSettings.w, calculatedImageSettings.h);
1743
+ }
1744
+ if (calculatedImageSettings) {
1745
+ ctx.globalAlpha = calculatedImageSettings.opacity;
1746
+ }
1747
+ if (haveImageToRender) {
1748
+ ctx.drawImage(
1749
+ image,
1750
+ calculatedImageSettings.x + margin,
1751
+ calculatedImageSettings.y + margin,
1752
+ calculatedImageSettings.w,
1753
+ calculatedImageSettings.h
1754
+ );
1755
+ }
1525
1756
  }
1526
- }
1527
- });
1528
- React__default.useEffect(() => {
1529
- setIsImageLoaded(false);
1530
- }, [imgSrc]);
1531
- const canvasStyle = __spreadValues({ height: size, width: size }, style);
1532
- let img = null;
1533
- if (imgSrc != null) {
1534
- img = /* @__PURE__ */ React__default.createElement("img", {
1535
- src: imgSrc,
1536
- key: imgSrc,
1537
- style: { display: "none" },
1538
- onLoad: () => {
1539
- setIsImageLoaded(true);
1540
- },
1541
- ref: _image
1542
1757
  });
1543
- }
1544
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement("canvas", __spreadValues({
1545
- style: canvasStyle,
1546
- height: size,
1547
- width: size,
1548
- ref: _canvas
1549
- }, otherProps)), img);
1550
- }
1551
- function QRCodeSVG(props) {
1552
- const _a = props, {
1553
- value,
1554
- size = DEFAULT_SIZE,
1555
- level = DEFAULT_LEVEL,
1556
- bgColor = DEFAULT_BGCOLOR,
1557
- fgColor = DEFAULT_FGCOLOR,
1558
- includeMargin = DEFAULT_INCLUDEMARGIN,
1559
- imageSettings
1560
- } = _a, otherProps = __objRest(_a, [
1561
- "value",
1562
- "size",
1563
- "level",
1564
- "bgColor",
1565
- "fgColor",
1566
- "includeMargin",
1567
- "imageSettings"
1568
- ]);
1569
- let cells = qrcodegen_default.QrCode.encodeText(value, ERROR_LEVEL_MAP[level]).getModules();
1570
- const margin = includeMargin ? MARGIN_SIZE : 0;
1571
- const numCells = cells.length + margin * 2;
1572
- const calculatedImageSettings = getImageSettings(cells, size, includeMargin, imageSettings);
1573
- let image = null;
1574
- if (imageSettings != null && calculatedImageSettings != null) {
1575
- if (calculatedImageSettings.excavation != null) {
1576
- cells = excavateModules(cells, calculatedImageSettings.excavation);
1758
+ React__default.useEffect(() => {
1759
+ setIsImageLoaded(false);
1760
+ }, [imgSrc]);
1761
+ const canvasStyle = __spreadValues({ height: size, width: size }, style);
1762
+ let img = null;
1763
+ if (imgSrc != null) {
1764
+ img = /* @__PURE__ */ React__default.createElement(
1765
+ "img",
1766
+ {
1767
+ src: imgSrc,
1768
+ key: imgSrc,
1769
+ style: { display: "none" },
1770
+ onLoad: () => {
1771
+ setIsImageLoaded(true);
1772
+ },
1773
+ ref: _image,
1774
+ crossOrigin: calculatedImageSettings == null ? void 0 : calculatedImageSettings.crossOrigin
1775
+ }
1776
+ );
1577
1777
  }
1578
- image = /* @__PURE__ */ React__default.createElement("image", {
1579
- xlinkHref: imageSettings.src,
1580
- height: calculatedImageSettings.h,
1581
- width: calculatedImageSettings.w,
1582
- x: calculatedImageSettings.x + margin,
1583
- y: calculatedImageSettings.y + margin,
1584
- preserveAspectRatio: "none"
1585
- });
1778
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
1779
+ "canvas",
1780
+ __spreadValues({
1781
+ style: canvasStyle,
1782
+ height: size,
1783
+ width: size,
1784
+ ref: setCanvasRef,
1785
+ role: "img"
1786
+ }, otherProps)
1787
+ ), img);
1586
1788
  }
1587
- const fgPath = generatePath(cells, margin);
1588
- return /* @__PURE__ */ React__default.createElement("svg", __spreadValues({
1589
- height: size,
1590
- width: size,
1591
- viewBox: `0 0 ${numCells} ${numCells}`
1592
- }, otherProps), /* @__PURE__ */ React__default.createElement("path", {
1593
- fill: bgColor,
1594
- d: `M0,0 h${numCells}v${numCells}H0z`,
1595
- shapeRendering: "crispEdges"
1596
- }), /* @__PURE__ */ React__default.createElement("path", {
1597
- fill: fgColor,
1598
- d: fgPath,
1599
- shapeRendering: "crispEdges"
1600
- }), image);
1601
- }
1602
- var QRCode$1 = (props) => {
1603
- const _a = props, { renderAs } = _a, otherProps = __objRest(_a, ["renderAs"]);
1604
- if (renderAs === "svg") {
1605
- return /* @__PURE__ */ React__default.createElement(QRCodeSVG, __spreadValues({}, otherProps));
1789
+ );
1790
+ QRCodeCanvas.displayName = "QRCodeCanvas";
1791
+ var QRCodeSVG = React__default.forwardRef(
1792
+ function QRCodeSVG2(props, forwardedRef) {
1793
+ const _a = props, {
1794
+ value,
1795
+ size = DEFAULT_SIZE,
1796
+ level = DEFAULT_LEVEL,
1797
+ bgColor = DEFAULT_BGCOLOR,
1798
+ fgColor = DEFAULT_FGCOLOR,
1799
+ includeMargin = DEFAULT_INCLUDEMARGIN,
1800
+ minVersion = DEFAULT_MINVERSION,
1801
+ boostLevel,
1802
+ title,
1803
+ marginSize,
1804
+ imageSettings
1805
+ } = _a, otherProps = __objRest(_a, [
1806
+ "value",
1807
+ "size",
1808
+ "level",
1809
+ "bgColor",
1810
+ "fgColor",
1811
+ "includeMargin",
1812
+ "minVersion",
1813
+ "boostLevel",
1814
+ "title",
1815
+ "marginSize",
1816
+ "imageSettings"
1817
+ ]);
1818
+ const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
1819
+ value,
1820
+ level,
1821
+ minVersion,
1822
+ boostLevel,
1823
+ includeMargin,
1824
+ marginSize,
1825
+ imageSettings,
1826
+ size
1827
+ });
1828
+ let cellsToDraw = cells;
1829
+ let image = null;
1830
+ if (imageSettings != null && calculatedImageSettings != null) {
1831
+ if (calculatedImageSettings.excavation != null) {
1832
+ cellsToDraw = excavateModules(
1833
+ cells,
1834
+ calculatedImageSettings.excavation
1835
+ );
1836
+ }
1837
+ image = /* @__PURE__ */ React__default.createElement(
1838
+ "image",
1839
+ {
1840
+ href: imageSettings.src,
1841
+ height: calculatedImageSettings.h,
1842
+ width: calculatedImageSettings.w,
1843
+ x: calculatedImageSettings.x + margin,
1844
+ y: calculatedImageSettings.y + margin,
1845
+ preserveAspectRatio: "none",
1846
+ opacity: calculatedImageSettings.opacity,
1847
+ crossOrigin: calculatedImageSettings.crossOrigin
1848
+ }
1849
+ );
1850
+ }
1851
+ const fgPath = generatePath(cellsToDraw, margin);
1852
+ return /* @__PURE__ */ React__default.createElement(
1853
+ "svg",
1854
+ __spreadValues({
1855
+ height: size,
1856
+ width: size,
1857
+ viewBox: `0 0 ${numCells} ${numCells}`,
1858
+ ref: forwardedRef,
1859
+ role: "img"
1860
+ }, otherProps),
1861
+ !!title && /* @__PURE__ */ React__default.createElement("title", null, title),
1862
+ /* @__PURE__ */ React__default.createElement(
1863
+ "path",
1864
+ {
1865
+ fill: bgColor,
1866
+ d: `M0,0 h${numCells}v${numCells}H0z`,
1867
+ shapeRendering: "crispEdges"
1868
+ }
1869
+ ),
1870
+ /* @__PURE__ */ React__default.createElement("path", { fill: fgColor, d: fgPath, shapeRendering: "crispEdges" }),
1871
+ image
1872
+ );
1606
1873
  }
1607
- return /* @__PURE__ */ React__default.createElement(QRCodeCanvas, __spreadValues({}, otherProps));
1608
- };
1874
+ );
1875
+ QRCodeSVG.displayName = "QRCodeSVG";
1609
1876
 
1610
1877
  var QRCode = function QRCode(_ref) {
1611
1878
  var entity = _ref.entity,
@@ -1661,7 +1928,7 @@ var QRCode = function QRCode(_ref) {
1661
1928
  onClick: handleCopyQRCode
1662
1929
  })]
1663
1930
  }),
1664
- children: /*#__PURE__*/jsx(QRCode$1, {
1931
+ children: /*#__PURE__*/jsx(QRCodeCanvas, {
1665
1932
  className: "mt-6 cursor-pointer",
1666
1933
  "data-testid": "qr-code-image",
1667
1934
  id: canvasId,