@m0-foundation/swap-component 0.0.1

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 (240) hide show
  1. package/dist/m0-swap-component/ConstantsUtil-btJ3XIXu.js +28 -0
  2. package/dist/m0-swap-component/ConstantsUtil-btJ3XIXu.js.map +1 -0
  3. package/dist/m0-swap-component/HelpersUtil-5wkO4kIW.js +142 -0
  4. package/dist/m0-swap-component/HelpersUtil-5wkO4kIW.js.map +1 -0
  5. package/dist/m0-swap-component/PhArrowCircleDown-BiDIiYXi.js +76 -0
  6. package/dist/m0-swap-component/PhArrowCircleDown-BiDIiYXi.js.map +1 -0
  7. package/dist/m0-swap-component/PhArrowClockwise-BRnlxNUR.js +76 -0
  8. package/dist/m0-swap-component/PhArrowClockwise-BRnlxNUR.js.map +1 -0
  9. package/dist/m0-swap-component/PhArrowDown-Co2hyXIs.js +76 -0
  10. package/dist/m0-swap-component/PhArrowDown-Co2hyXIs.js.map +1 -0
  11. package/dist/m0-swap-component/PhArrowLeft-Cb8ijwK6.js +76 -0
  12. package/dist/m0-swap-component/PhArrowLeft-Cb8ijwK6.js.map +1 -0
  13. package/dist/m0-swap-component/PhArrowRight-B9t--Gmh.js +76 -0
  14. package/dist/m0-swap-component/PhArrowRight-B9t--Gmh.js.map +1 -0
  15. package/dist/m0-swap-component/PhArrowSquareOut-eGBMEr5T.js +76 -0
  16. package/dist/m0-swap-component/PhArrowSquareOut-eGBMEr5T.js.map +1 -0
  17. package/dist/m0-swap-component/PhArrowUp-CjSpT-xh.js +76 -0
  18. package/dist/m0-swap-component/PhArrowUp-CjSpT-xh.js.map +1 -0
  19. package/dist/m0-swap-component/PhArrowUpRight-B8u6wk-A.js +76 -0
  20. package/dist/m0-swap-component/PhArrowUpRight-B8u6wk-A.js.map +1 -0
  21. package/dist/m0-swap-component/PhArrowsClockwise-CBcfV6j6.js +76 -0
  22. package/dist/m0-swap-component/PhArrowsClockwise-CBcfV6j6.js.map +1 -0
  23. package/dist/m0-swap-component/PhArrowsDownUp-CMVR84b1.js +76 -0
  24. package/dist/m0-swap-component/PhArrowsDownUp-CMVR84b1.js.map +1 -0
  25. package/dist/m0-swap-component/PhArrowsLeftRight-CmXk8rs2.js +76 -0
  26. package/dist/m0-swap-component/PhArrowsLeftRight-CmXk8rs2.js.map +1 -0
  27. package/dist/m0-swap-component/PhBank-BigtjnS8.js +76 -0
  28. package/dist/m0-swap-component/PhBank-BigtjnS8.js.map +1 -0
  29. package/dist/m0-swap-component/PhBrowser-BOulLD8D.js +76 -0
  30. package/dist/m0-swap-component/PhBrowser-BOulLD8D.js.map +1 -0
  31. package/dist/m0-swap-component/PhCaretDown-BvvZ65ad.js +76 -0
  32. package/dist/m0-swap-component/PhCaretDown-BvvZ65ad.js.map +1 -0
  33. package/dist/m0-swap-component/PhCaretLeft-DtwjZbZ7.js +76 -0
  34. package/dist/m0-swap-component/PhCaretLeft-DtwjZbZ7.js.map +1 -0
  35. package/dist/m0-swap-component/PhCaretRight-C8LuSZkO.js +76 -0
  36. package/dist/m0-swap-component/PhCaretRight-C8LuSZkO.js.map +1 -0
  37. package/dist/m0-swap-component/PhCaretUp-B2lAObip.js +76 -0
  38. package/dist/m0-swap-component/PhCaretUp-B2lAObip.js.map +1 -0
  39. package/dist/m0-swap-component/PhCheck-DQtuVrQf.js +76 -0
  40. package/dist/m0-swap-component/PhCheck-DQtuVrQf.js.map +1 -0
  41. package/dist/m0-swap-component/PhCircleHalf-CXfZ0QZv.js +76 -0
  42. package/dist/m0-swap-component/PhCircleHalf-CXfZ0QZv.js.map +1 -0
  43. package/dist/m0-swap-component/PhClock-CXsmuc_a.js +76 -0
  44. package/dist/m0-swap-component/PhClock-CXsmuc_a.js.map +1 -0
  45. package/dist/m0-swap-component/PhCompass-Cg-qnMon.js +76 -0
  46. package/dist/m0-swap-component/PhCompass-Cg-qnMon.js.map +1 -0
  47. package/dist/m0-swap-component/PhCopy-kGRKcvb4.js +76 -0
  48. package/dist/m0-swap-component/PhCopy-kGRKcvb4.js.map +1 -0
  49. package/dist/m0-swap-component/PhCreditCard-jYFausLO.js +76 -0
  50. package/dist/m0-swap-component/PhCreditCard-jYFausLO.js.map +1 -0
  51. package/dist/m0-swap-component/PhCurrencyDollar-C8vSY3fy.js +76 -0
  52. package/dist/m0-swap-component/PhCurrencyDollar-C8vSY3fy.js.map +1 -0
  53. package/dist/m0-swap-component/PhDesktop-AczlBCho.js +76 -0
  54. package/dist/m0-swap-component/PhDesktop-AczlBCho.js.map +1 -0
  55. package/dist/m0-swap-component/PhDeviceMobile-3rFbdWLA.js +76 -0
  56. package/dist/m0-swap-component/PhDeviceMobile-3rFbdWLA.js.map +1 -0
  57. package/dist/m0-swap-component/PhDotsThree-cJsXXsvY.js +76 -0
  58. package/dist/m0-swap-component/PhDotsThree-cJsXXsvY.js.map +1 -0
  59. package/dist/m0-swap-component/PhEnvelope-C1bxHVXw.js +76 -0
  60. package/dist/m0-swap-component/PhEnvelope-C1bxHVXw.js.map +1 -0
  61. package/dist/m0-swap-component/PhFunnelSimple-DhqB9fsu.js +76 -0
  62. package/dist/m0-swap-component/PhFunnelSimple-DhqB9fsu.js.map +1 -0
  63. package/dist/m0-swap-component/PhGlobe-BFp6kx95.js +76 -0
  64. package/dist/m0-swap-component/PhGlobe-BFp6kx95.js.map +1 -0
  65. package/dist/m0-swap-component/PhIdentificationCard-BdYxckWB.js +76 -0
  66. package/dist/m0-swap-component/PhIdentificationCard-BdYxckWB.js.map +1 -0
  67. package/dist/m0-swap-component/PhImage-CXxX5oq3.js +76 -0
  68. package/dist/m0-swap-component/PhImage-CXxX5oq3.js.map +1 -0
  69. package/dist/m0-swap-component/PhInfo-BcuP36hY.js +76 -0
  70. package/dist/m0-swap-component/PhInfo-BcuP36hY.js.map +1 -0
  71. package/dist/m0-swap-component/PhLightbulb-DkWwRl94.js +76 -0
  72. package/dist/m0-swap-component/PhLightbulb-DkWwRl94.js.map +1 -0
  73. package/dist/m0-swap-component/PhMagnifyingGlass-B_fFjslY.js +76 -0
  74. package/dist/m0-swap-component/PhMagnifyingGlass-B_fFjslY.js.map +1 -0
  75. package/dist/m0-swap-component/PhPaperPlaneRight-BIzGG3QW.js +76 -0
  76. package/dist/m0-swap-component/PhPaperPlaneRight-BIzGG3QW.js.map +1 -0
  77. package/dist/m0-swap-component/PhPlus-BGosT2zu.js +76 -0
  78. package/dist/m0-swap-component/PhPlus-BGosT2zu.js.map +1 -0
  79. package/dist/m0-swap-component/PhPower-BMqDnP1n.js +76 -0
  80. package/dist/m0-swap-component/PhPower-BMqDnP1n.js.map +1 -0
  81. package/dist/m0-swap-component/PhPuzzlePiece-DNMpiJNU.js +76 -0
  82. package/dist/m0-swap-component/PhPuzzlePiece-DNMpiJNU.js.map +1 -0
  83. package/dist/m0-swap-component/PhQrCode-DrHkqrU4.js +76 -0
  84. package/dist/m0-swap-component/PhQrCode-DrHkqrU4.js.map +1 -0
  85. package/dist/m0-swap-component/PhQuestion-zTfvwqNz.js +76 -0
  86. package/dist/m0-swap-component/PhQuestion-zTfvwqNz.js.map +1 -0
  87. package/dist/m0-swap-component/PhQuestionMark-h3Nk1Yf1.js +76 -0
  88. package/dist/m0-swap-component/PhQuestionMark-h3Nk1Yf1.js.map +1 -0
  89. package/dist/m0-swap-component/PhSealCheck-DPPqSt6G.js +76 -0
  90. package/dist/m0-swap-component/PhSealCheck-DPPqSt6G.js.map +1 -0
  91. package/dist/m0-swap-component/PhSignOut-CJgnrE_v.js +76 -0
  92. package/dist/m0-swap-component/PhSignOut-CJgnrE_v.js.map +1 -0
  93. package/dist/m0-swap-component/PhSpinner-CMTEIWbw.js +76 -0
  94. package/dist/m0-swap-component/PhSpinner-CMTEIWbw.js.map +1 -0
  95. package/dist/m0-swap-component/PhTrash-CeDVW4am.js +76 -0
  96. package/dist/m0-swap-component/PhTrash-CeDVW4am.js.map +1 -0
  97. package/dist/m0-swap-component/PhUser-lQ9WUtAV.js +76 -0
  98. package/dist/m0-swap-component/PhUser-lQ9WUtAV.js.map +1 -0
  99. package/dist/m0-swap-component/PhVault-EnLnS_IQ.js +76 -0
  100. package/dist/m0-swap-component/PhVault-EnLnS_IQ.js.map +1 -0
  101. package/dist/m0-swap-component/PhWallet-CUeDZydd.js +76 -0
  102. package/dist/m0-swap-component/PhWallet-CUeDZydd.js.map +1 -0
  103. package/dist/m0-swap-component/PhWarning-CokeGZs2.js +76 -0
  104. package/dist/m0-swap-component/PhWarning-CokeGZs2.js.map +1 -0
  105. package/dist/m0-swap-component/PhWarningCircle-vWtA7S0R.js +76 -0
  106. package/dist/m0-swap-component/PhWarningCircle-vWtA7S0R.js.map +1 -0
  107. package/dist/m0-swap-component/PhX-DwCRIvoc.js +76 -0
  108. package/dist/m0-swap-component/PhX-DwCRIvoc.js.map +1 -0
  109. package/dist/m0-swap-component/data-capture-BmovBbKV.js +573 -0
  110. package/dist/m0-swap-component/data-capture-BmovBbKV.js.map +1 -0
  111. package/dist/m0-swap-component/email-B4niz3Ms.js +445 -0
  112. package/dist/m0-swap-component/email-B4niz3Ms.js.map +1 -0
  113. package/dist/m0-swap-component/embedded-wallet-D6bzjX_K.js +988 -0
  114. package/dist/m0-swap-component/embedded-wallet-D6bzjX_K.js.map +1 -0
  115. package/dist/m0-swap-component/features-EhJNVE-M.js +355 -0
  116. package/dist/m0-swap-component/features-EhJNVE-M.js.map +1 -0
  117. package/dist/m0-swap-component/if-defined-2CMpVr2R.js +12 -0
  118. package/dist/m0-swap-component/if-defined-2CMpVr2R.js.map +1 -0
  119. package/dist/m0-swap-component/index-B4xuj7uR.js +965 -0
  120. package/dist/m0-swap-component/index-B4xuj7uR.js.map +1 -0
  121. package/dist/m0-swap-component/index-BVZ66GYf.js +206 -0
  122. package/dist/m0-swap-component/index-BVZ66GYf.js.map +1 -0
  123. package/dist/m0-swap-component/index-BZXyMieH.js +150 -0
  124. package/dist/m0-swap-component/index-BZXyMieH.js.map +1 -0
  125. package/dist/m0-swap-component/index-Bj5sA_Ri.js +252 -0
  126. package/dist/m0-swap-component/index-Bj5sA_Ri.js.map +1 -0
  127. package/dist/m0-swap-component/index-Bs-pPJYj.js +129 -0
  128. package/dist/m0-swap-component/index-Bs-pPJYj.js.map +1 -0
  129. package/dist/m0-swap-component/index-CMS76VPf.js +474 -0
  130. package/dist/m0-swap-component/index-CMS76VPf.js.map +1 -0
  131. package/dist/m0-swap-component/index-CoMTkqee.js +95 -0
  132. package/dist/m0-swap-component/index-CoMTkqee.js.map +1 -0
  133. package/dist/m0-swap-component/index-DE0OtbL2.js +3566 -0
  134. package/dist/m0-swap-component/index-DE0OtbL2.js.map +1 -0
  135. package/dist/m0-swap-component/index-DEG-YczD.js +231 -0
  136. package/dist/m0-swap-component/index-DEG-YczD.js.map +1 -0
  137. package/dist/m0-swap-component/index-DY_Ijq_4.js +4345 -0
  138. package/dist/m0-swap-component/index-DY_Ijq_4.js.map +1 -0
  139. package/dist/m0-swap-component/index-IRpGhIhy.js +9394 -0
  140. package/dist/m0-swap-component/index-IRpGhIhy.js.map +1 -0
  141. package/dist/m0-swap-component/index-Z70nBYWG.js +113 -0
  142. package/dist/m0-swap-component/index-Z70nBYWG.js.map +1 -0
  143. package/dist/m0-swap-component/index-iNFotRMa.js +73 -0
  144. package/dist/m0-swap-component/index-iNFotRMa.js.map +1 -0
  145. package/dist/m0-swap-component/index-n1fooC-v.js +37757 -0
  146. package/dist/m0-swap-component/index-n1fooC-v.js.map +1 -0
  147. package/dist/m0-swap-component/index.esm.js +2 -0
  148. package/dist/m0-swap-component/index.esm.js.map +1 -0
  149. package/dist/m0-swap-component/loader.esm.js.map +1 -0
  150. package/dist/m0-swap-component/m0-swap-component.esm.js +48 -0
  151. package/dist/m0-swap-component/m0-swap-component.esm.js.map +1 -0
  152. package/dist/m0-swap-component/native-CPtqJIn7.js +18 -0
  153. package/dist/m0-swap-component/native-CPtqJIn7.js.map +1 -0
  154. package/dist/m0-swap-component/onramp-BppY2eDR.js +1003 -0
  155. package/dist/m0-swap-component/onramp-BppY2eDR.js.map +1 -0
  156. package/dist/m0-swap-component/pay-with-exchange-BJYQgTMB.js +639 -0
  157. package/dist/m0-swap-component/pay-with-exchange-BJYQgTMB.js.map +1 -0
  158. package/dist/m0-swap-component/property-BN-VaT99.js +625 -0
  159. package/dist/m0-swap-component/property-BN-VaT99.js.map +1 -0
  160. package/dist/m0-swap-component/receive-BptRM_5_.js +281 -0
  161. package/dist/m0-swap-component/receive-BptRM_5_.js.map +1 -0
  162. package/dist/m0-swap-component/ref-3xALOvo5.js +25 -0
  163. package/dist/m0-swap-component/ref-3xALOvo5.js.map +1 -0
  164. package/dist/m0-swap-component/send-BCyHM4Zr.js +1408 -0
  165. package/dist/m0-swap-component/send-BCyHM4Zr.js.map +1 -0
  166. package/dist/m0-swap-component/socials-BbajCSWV.js +824 -0
  167. package/dist/m0-swap-component/socials-BbajCSWV.js.map +1 -0
  168. package/dist/m0-swap-component/swap-module-5ZLM-vAV.js +140887 -0
  169. package/dist/m0-swap-component/swap-module-5ZLM-vAV.js.map +1 -0
  170. package/dist/m0-swap-component/swap-module.entry.esm.js.map +1 -0
  171. package/dist/m0-swap-component/swap-module.entry.js +15 -0
  172. package/dist/m0-swap-component/swaps-DyGe65DR.js +2121 -0
  173. package/dist/m0-swap-component/swaps-DyGe65DR.js.map +1 -0
  174. package/dist/m0-swap-component/transactions-BZ9l4zt5.js +60 -0
  175. package/dist/m0-swap-component/transactions-BZ9l4zt5.js.map +1 -0
  176. package/dist/m0-swap-component/utils-RCeZbvdb.js +95 -0
  177. package/dist/m0-swap-component/utils-RCeZbvdb.js.map +1 -0
  178. package/dist/m0-swap-component/w3m-modal-D0HWVPsj.js +2097 -0
  179. package/dist/m0-swap-component/w3m-modal-D0HWVPsj.js.map +1 -0
  180. package/dist/m0-swap-component/wui-button-BeTWD3Va.js +223 -0
  181. package/dist/m0-swap-component/wui-button-BeTWD3Va.js.map +1 -0
  182. package/dist/m0-swap-component/wui-email-input-CgnfUH0c.js +65 -0
  183. package/dist/m0-swap-component/wui-email-input-CgnfUH0c.js.map +1 -0
  184. package/dist/m0-swap-component/wui-icon-B0uTDhW-.js +4 -0
  185. package/dist/m0-swap-component/wui-icon-B0uTDhW-.js.map +1 -0
  186. package/dist/m0-swap-component/wui-icon-box-s87lODBB.js +4 -0
  187. package/dist/m0-swap-component/wui-icon-box-s87lODBB.js.map +1 -0
  188. package/dist/m0-swap-component/wui-icon-link-BFpV9kPE.js +127 -0
  189. package/dist/m0-swap-component/wui-icon-link-BFpV9kPE.js.map +1 -0
  190. package/dist/m0-swap-component/wui-image-BvjxoR51.js +4 -0
  191. package/dist/m0-swap-component/wui-image-BvjxoR51.js.map +1 -0
  192. package/dist/m0-swap-component/wui-input-amount-CWQfP3RO.js +182 -0
  193. package/dist/m0-swap-component/wui-input-amount-CWQfP3RO.js.map +1 -0
  194. package/dist/m0-swap-component/wui-input-text-g0sN4B2y.js +4 -0
  195. package/dist/m0-swap-component/wui-input-text-g0sN4B2y.js.map +1 -0
  196. package/dist/m0-swap-component/wui-link-VqM3wLny.js +123 -0
  197. package/dist/m0-swap-component/wui-link-VqM3wLny.js.map +1 -0
  198. package/dist/m0-swap-component/wui-list-item-BIijofqN.js +170 -0
  199. package/dist/m0-swap-component/wui-list-item-BIijofqN.js.map +1 -0
  200. package/dist/m0-swap-component/wui-list-social-C7GhkRc8.js +119 -0
  201. package/dist/m0-swap-component/wui-list-social-C7GhkRc8.js.map +1 -0
  202. package/dist/m0-swap-component/wui-list-token-C94lmAbT.js +134 -0
  203. package/dist/m0-swap-component/wui-list-token-C94lmAbT.js.map +1 -0
  204. package/dist/m0-swap-component/wui-list-wallet-C7fnQvCW.js +622 -0
  205. package/dist/m0-swap-component/wui-list-wallet-C7fnQvCW.js.map +1 -0
  206. package/dist/m0-swap-component/wui-loading-spinner-CW2_5SKA.js +4 -0
  207. package/dist/m0-swap-component/wui-loading-spinner-CW2_5SKA.js.map +1 -0
  208. package/dist/m0-swap-component/wui-loading-thumbnail-y3sGkT5j.js +337 -0
  209. package/dist/m0-swap-component/wui-loading-thumbnail-y3sGkT5j.js.map +1 -0
  210. package/dist/m0-swap-component/wui-qr-code-DekJTDGf.js +3412 -0
  211. package/dist/m0-swap-component/wui-qr-code-DekJTDGf.js.map +1 -0
  212. package/dist/m0-swap-component/wui-separator-DMZIL_Av.js +67 -0
  213. package/dist/m0-swap-component/wui-separator-DMZIL_Av.js.map +1 -0
  214. package/dist/m0-swap-component/wui-shimmer-CVFC8fMx.js +4 -0
  215. package/dist/m0-swap-component/wui-shimmer-CVFC8fMx.js.map +1 -0
  216. package/dist/m0-swap-component/wui-text-BS_lZKY4.js +1127 -0
  217. package/dist/m0-swap-component/wui-text-BS_lZKY4.js.map +1 -0
  218. package/dist/m0-swap-component/wui-token-button-CsOFoNJG.js +214 -0
  219. package/dist/m0-swap-component/wui-token-button-CsOFoNJG.js.map +1 -0
  220. package/dist/m0-swap-component/wui-visual-hU2Mkyrv.js +565 -0
  221. package/dist/m0-swap-component/wui-visual-hU2Mkyrv.js.map +1 -0
  222. package/dist/m0-swap-component/wui-wallet-switch-CWbdtfbN.js +459 -0
  223. package/dist/m0-swap-component/wui-wallet-switch-CWbdtfbN.js.map +1 -0
  224. package/dist/types/components/swap-module/balances.d.ts +16 -0
  225. package/dist/types/components/swap-module/chains.d.ts +16 -0
  226. package/dist/types/components/swap-module/store.d.ts +34 -0
  227. package/dist/types/components/swap-module/swap-module.d.ts +113 -0
  228. package/dist/types/components/swap-module/utils/constants.d.ts +7 -0
  229. package/dist/types/components/swap-module/utils/formatters.d.ts +23 -0
  230. package/dist/types/components/swap-module/utils/reown.d.ts +59 -0
  231. package/dist/types/components/swap-module/utils/wallet.d.ts +83 -0
  232. package/dist/types/components.d.ts +165 -0
  233. package/dist/types/index.d.ts +1 -0
  234. package/dist/types/stencil-public-runtime.d.ts +1732 -0
  235. package/loader/cdn.js +1 -0
  236. package/loader/index.cjs.js +1 -0
  237. package/loader/index.d.ts +24 -0
  238. package/loader/index.es2017.js +1 -0
  239. package/loader/index.js +2 -0
  240. package/package.json +60 -0
@@ -0,0 +1,3412 @@
1
+ import { a3 as getDefaultExportFromCjs, a4 as w, d as css, a as i, b, r as resetStyles, c as customElement } from './swap-module-5ZLM-vAV.js';
2
+ import { n } from './wui-text-BS_lZKY4.js';
3
+ import './index-BZXyMieH.js';
4
+
5
+ var browser = {};
6
+
7
+ var canPromise;
8
+ var hasRequiredCanPromise;
9
+
10
+ function requireCanPromise () {
11
+ if (hasRequiredCanPromise) return canPromise;
12
+ hasRequiredCanPromise = 1;
13
+ // can-promise has a crash in some versions of react native that dont have
14
+ // standard global objects
15
+ // https://github.com/soldair/node-qrcode/issues/157
16
+
17
+ canPromise = function () {
18
+ return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then
19
+ };
20
+ return canPromise;
21
+ }
22
+
23
+ var qrcode = {};
24
+
25
+ var utils$1 = {};
26
+
27
+ var hasRequiredUtils$1;
28
+
29
+ function requireUtils$1 () {
30
+ if (hasRequiredUtils$1) return utils$1;
31
+ hasRequiredUtils$1 = 1;
32
+ let toSJISFunction;
33
+ const CODEWORDS_COUNT = [
34
+ 0, // Not used
35
+ 26, 44, 70, 100, 134, 172, 196, 242, 292, 346,
36
+ 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,
37
+ 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,
38
+ 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
39
+ ];
40
+
41
+ /**
42
+ * Returns the QR Code size for the specified version
43
+ *
44
+ * @param {Number} version QR Code version
45
+ * @return {Number} size of QR code
46
+ */
47
+ utils$1.getSymbolSize = function getSymbolSize (version) {
48
+ if (!version) throw new Error('"version" cannot be null or undefined')
49
+ if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40')
50
+ return version * 4 + 17
51
+ };
52
+
53
+ /**
54
+ * Returns the total number of codewords used to store data and EC information.
55
+ *
56
+ * @param {Number} version QR Code version
57
+ * @return {Number} Data length in bits
58
+ */
59
+ utils$1.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {
60
+ return CODEWORDS_COUNT[version]
61
+ };
62
+
63
+ /**
64
+ * Encode data with Bose-Chaudhuri-Hocquenghem
65
+ *
66
+ * @param {Number} data Value to encode
67
+ * @return {Number} Encoded value
68
+ */
69
+ utils$1.getBCHDigit = function (data) {
70
+ let digit = 0;
71
+
72
+ while (data !== 0) {
73
+ digit++;
74
+ data >>>= 1;
75
+ }
76
+
77
+ return digit
78
+ };
79
+
80
+ utils$1.setToSJISFunction = function setToSJISFunction (f) {
81
+ if (typeof f !== 'function') {
82
+ throw new Error('"toSJISFunc" is not a valid function.')
83
+ }
84
+
85
+ toSJISFunction = f;
86
+ };
87
+
88
+ utils$1.isKanjiModeEnabled = function () {
89
+ return typeof toSJISFunction !== 'undefined'
90
+ };
91
+
92
+ utils$1.toSJIS = function toSJIS (kanji) {
93
+ return toSJISFunction(kanji)
94
+ };
95
+ return utils$1;
96
+ }
97
+
98
+ var errorCorrectionLevel = {};
99
+
100
+ var hasRequiredErrorCorrectionLevel;
101
+
102
+ function requireErrorCorrectionLevel () {
103
+ if (hasRequiredErrorCorrectionLevel) return errorCorrectionLevel;
104
+ hasRequiredErrorCorrectionLevel = 1;
105
+ (function (exports) {
106
+ exports.L = { bit: 1 };
107
+ exports.M = { bit: 0 };
108
+ exports.Q = { bit: 3 };
109
+ exports.H = { bit: 2 };
110
+
111
+ function fromString (string) {
112
+ if (typeof string !== 'string') {
113
+ throw new Error('Param is not a string')
114
+ }
115
+
116
+ const lcStr = string.toLowerCase();
117
+
118
+ switch (lcStr) {
119
+ case 'l':
120
+ case 'low':
121
+ return exports.L
122
+
123
+ case 'm':
124
+ case 'medium':
125
+ return exports.M
126
+
127
+ case 'q':
128
+ case 'quartile':
129
+ return exports.Q
130
+
131
+ case 'h':
132
+ case 'high':
133
+ return exports.H
134
+
135
+ default:
136
+ throw new Error('Unknown EC Level: ' + string)
137
+ }
138
+ }
139
+
140
+ exports.isValid = function isValid (level) {
141
+ return level && typeof level.bit !== 'undefined' &&
142
+ level.bit >= 0 && level.bit < 4
143
+ };
144
+
145
+ exports.from = function from (value, defaultValue) {
146
+ if (exports.isValid(value)) {
147
+ return value
148
+ }
149
+
150
+ try {
151
+ return fromString(value)
152
+ } catch (e) {
153
+ return defaultValue
154
+ }
155
+ };
156
+ } (errorCorrectionLevel));
157
+ return errorCorrectionLevel;
158
+ }
159
+
160
+ var bitBuffer;
161
+ var hasRequiredBitBuffer;
162
+
163
+ function requireBitBuffer () {
164
+ if (hasRequiredBitBuffer) return bitBuffer;
165
+ hasRequiredBitBuffer = 1;
166
+ function BitBuffer () {
167
+ this.buffer = [];
168
+ this.length = 0;
169
+ }
170
+
171
+ BitBuffer.prototype = {
172
+
173
+ get: function (index) {
174
+ const bufIndex = Math.floor(index / 8);
175
+ return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
176
+ },
177
+
178
+ put: function (num, length) {
179
+ for (let i = 0; i < length; i++) {
180
+ this.putBit(((num >>> (length - i - 1)) & 1) === 1);
181
+ }
182
+ },
183
+
184
+ getLengthInBits: function () {
185
+ return this.length
186
+ },
187
+
188
+ putBit: function (bit) {
189
+ const bufIndex = Math.floor(this.length / 8);
190
+ if (this.buffer.length <= bufIndex) {
191
+ this.buffer.push(0);
192
+ }
193
+
194
+ if (bit) {
195
+ this.buffer[bufIndex] |= (0x80 >>> (this.length % 8));
196
+ }
197
+
198
+ this.length++;
199
+ }
200
+ };
201
+
202
+ bitBuffer = BitBuffer;
203
+ return bitBuffer;
204
+ }
205
+
206
+ /**
207
+ * Helper class to handle QR Code symbol modules
208
+ *
209
+ * @param {Number} size Symbol size
210
+ */
211
+
212
+ var bitMatrix;
213
+ var hasRequiredBitMatrix;
214
+
215
+ function requireBitMatrix () {
216
+ if (hasRequiredBitMatrix) return bitMatrix;
217
+ hasRequiredBitMatrix = 1;
218
+ function BitMatrix (size) {
219
+ if (!size || size < 1) {
220
+ throw new Error('BitMatrix size must be defined and greater than 0')
221
+ }
222
+
223
+ this.size = size;
224
+ this.data = new Uint8Array(size * size);
225
+ this.reservedBit = new Uint8Array(size * size);
226
+ }
227
+
228
+ /**
229
+ * Set bit value at specified location
230
+ * If reserved flag is set, this bit will be ignored during masking process
231
+ *
232
+ * @param {Number} row
233
+ * @param {Number} col
234
+ * @param {Boolean} value
235
+ * @param {Boolean} reserved
236
+ */
237
+ BitMatrix.prototype.set = function (row, col, value, reserved) {
238
+ const index = row * this.size + col;
239
+ this.data[index] = value;
240
+ if (reserved) this.reservedBit[index] = true;
241
+ };
242
+
243
+ /**
244
+ * Returns bit value at specified location
245
+ *
246
+ * @param {Number} row
247
+ * @param {Number} col
248
+ * @return {Boolean}
249
+ */
250
+ BitMatrix.prototype.get = function (row, col) {
251
+ return this.data[row * this.size + col]
252
+ };
253
+
254
+ /**
255
+ * Applies xor operator at specified location
256
+ * (used during masking process)
257
+ *
258
+ * @param {Number} row
259
+ * @param {Number} col
260
+ * @param {Boolean} value
261
+ */
262
+ BitMatrix.prototype.xor = function (row, col, value) {
263
+ this.data[row * this.size + col] ^= value;
264
+ };
265
+
266
+ /**
267
+ * Check if bit at specified location is reserved
268
+ *
269
+ * @param {Number} row
270
+ * @param {Number} col
271
+ * @return {Boolean}
272
+ */
273
+ BitMatrix.prototype.isReserved = function (row, col) {
274
+ return this.reservedBit[row * this.size + col]
275
+ };
276
+
277
+ bitMatrix = BitMatrix;
278
+ return bitMatrix;
279
+ }
280
+
281
+ var alignmentPattern = {};
282
+
283
+ /**
284
+ * Alignment pattern are fixed reference pattern in defined positions
285
+ * in a matrix symbology, which enables the decode software to re-synchronise
286
+ * the coordinate mapping of the image modules in the event of moderate amounts
287
+ * of distortion of the image.
288
+ *
289
+ * Alignment patterns are present only in QR Code symbols of version 2 or larger
290
+ * and their number depends on the symbol version.
291
+ */
292
+
293
+ var hasRequiredAlignmentPattern;
294
+
295
+ function requireAlignmentPattern () {
296
+ if (hasRequiredAlignmentPattern) return alignmentPattern;
297
+ hasRequiredAlignmentPattern = 1;
298
+ (function (exports) {
299
+ const getSymbolSize = requireUtils$1().getSymbolSize;
300
+
301
+ /**
302
+ * Calculate the row/column coordinates of the center module of each alignment pattern
303
+ * for the specified QR Code version.
304
+ *
305
+ * The alignment patterns are positioned symmetrically on either side of the diagonal
306
+ * running from the top left corner of the symbol to the bottom right corner.
307
+ *
308
+ * Since positions are simmetrical only half of the coordinates are returned.
309
+ * Each item of the array will represent in turn the x and y coordinate.
310
+ * @see {@link getPositions}
311
+ *
312
+ * @param {Number} version QR Code version
313
+ * @return {Array} Array of coordinate
314
+ */
315
+ exports.getRowColCoords = function getRowColCoords (version) {
316
+ if (version === 1) return []
317
+
318
+ const posCount = Math.floor(version / 7) + 2;
319
+ const size = getSymbolSize(version);
320
+ const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
321
+ const positions = [size - 7]; // Last coord is always (size - 7)
322
+
323
+ for (let i = 1; i < posCount - 1; i++) {
324
+ positions[i] = positions[i - 1] - intervals;
325
+ }
326
+
327
+ positions.push(6); // First coord is always 6
328
+
329
+ return positions.reverse()
330
+ };
331
+
332
+ /**
333
+ * Returns an array containing the positions of each alignment pattern.
334
+ * Each array's element represent the center point of the pattern as (x, y) coordinates
335
+ *
336
+ * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
337
+ * and filtering out the items that overlaps with finder pattern
338
+ *
339
+ * @example
340
+ * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
341
+ * The alignment patterns, therefore, are to be centered on (row, column)
342
+ * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
343
+ * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
344
+ * and are not therefore used for alignment patterns.
345
+ *
346
+ * let pos = getPositions(7)
347
+ * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
348
+ *
349
+ * @param {Number} version QR Code version
350
+ * @return {Array} Array of coordinates
351
+ */
352
+ exports.getPositions = function getPositions (version) {
353
+ const coords = [];
354
+ const pos = exports.getRowColCoords(version);
355
+ const posLength = pos.length;
356
+
357
+ for (let i = 0; i < posLength; i++) {
358
+ for (let j = 0; j < posLength; j++) {
359
+ // Skip if position is occupied by finder patterns
360
+ if ((i === 0 && j === 0) || // top-left
361
+ (i === 0 && j === posLength - 1) || // bottom-left
362
+ (i === posLength - 1 && j === 0)) { // top-right
363
+ continue
364
+ }
365
+
366
+ coords.push([pos[i], pos[j]]);
367
+ }
368
+ }
369
+
370
+ return coords
371
+ };
372
+ } (alignmentPattern));
373
+ return alignmentPattern;
374
+ }
375
+
376
+ var finderPattern = {};
377
+
378
+ var hasRequiredFinderPattern;
379
+
380
+ function requireFinderPattern () {
381
+ if (hasRequiredFinderPattern) return finderPattern;
382
+ hasRequiredFinderPattern = 1;
383
+ const getSymbolSize = requireUtils$1().getSymbolSize;
384
+ const FINDER_PATTERN_SIZE = 7;
385
+
386
+ /**
387
+ * Returns an array containing the positions of each finder pattern.
388
+ * Each array's element represent the top-left point of the pattern as (x, y) coordinates
389
+ *
390
+ * @param {Number} version QR Code version
391
+ * @return {Array} Array of coordinates
392
+ */
393
+ finderPattern.getPositions = function getPositions (version) {
394
+ const size = getSymbolSize(version);
395
+
396
+ return [
397
+ // top-left
398
+ [0, 0],
399
+ // top-right
400
+ [size - FINDER_PATTERN_SIZE, 0],
401
+ // bottom-left
402
+ [0, size - FINDER_PATTERN_SIZE]
403
+ ]
404
+ };
405
+ return finderPattern;
406
+ }
407
+
408
+ var maskPattern = {};
409
+
410
+ /**
411
+ * Data mask pattern reference
412
+ * @type {Object}
413
+ */
414
+
415
+ var hasRequiredMaskPattern;
416
+
417
+ function requireMaskPattern () {
418
+ if (hasRequiredMaskPattern) return maskPattern;
419
+ hasRequiredMaskPattern = 1;
420
+ (function (exports) {
421
+ exports.Patterns = {
422
+ PATTERN000: 0,
423
+ PATTERN001: 1,
424
+ PATTERN010: 2,
425
+ PATTERN011: 3,
426
+ PATTERN100: 4,
427
+ PATTERN101: 5,
428
+ PATTERN110: 6,
429
+ PATTERN111: 7
430
+ };
431
+
432
+ /**
433
+ * Weighted penalty scores for the undesirable features
434
+ * @type {Object}
435
+ */
436
+ const PenaltyScores = {
437
+ N1: 3,
438
+ N2: 3,
439
+ N3: 40,
440
+ N4: 10
441
+ };
442
+
443
+ /**
444
+ * Check if mask pattern value is valid
445
+ *
446
+ * @param {Number} mask Mask pattern
447
+ * @return {Boolean} true if valid, false otherwise
448
+ */
449
+ exports.isValid = function isValid (mask) {
450
+ return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7
451
+ };
452
+
453
+ /**
454
+ * Returns mask pattern from a value.
455
+ * If value is not valid, returns undefined
456
+ *
457
+ * @param {Number|String} value Mask pattern value
458
+ * @return {Number} Valid mask pattern or undefined
459
+ */
460
+ exports.from = function from (value) {
461
+ return exports.isValid(value) ? parseInt(value, 10) : undefined
462
+ };
463
+
464
+ /**
465
+ * Find adjacent modules in row/column with the same color
466
+ * and assign a penalty value.
467
+ *
468
+ * Points: N1 + i
469
+ * i is the amount by which the number of adjacent modules of the same color exceeds 5
470
+ */
471
+ exports.getPenaltyN1 = function getPenaltyN1 (data) {
472
+ const size = data.size;
473
+ let points = 0;
474
+ let sameCountCol = 0;
475
+ let sameCountRow = 0;
476
+ let lastCol = null;
477
+ let lastRow = null;
478
+
479
+ for (let row = 0; row < size; row++) {
480
+ sameCountCol = sameCountRow = 0;
481
+ lastCol = lastRow = null;
482
+
483
+ for (let col = 0; col < size; col++) {
484
+ let module = data.get(row, col);
485
+ if (module === lastCol) {
486
+ sameCountCol++;
487
+ } else {
488
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
489
+ lastCol = module;
490
+ sameCountCol = 1;
491
+ }
492
+
493
+ module = data.get(col, row);
494
+ if (module === lastRow) {
495
+ sameCountRow++;
496
+ } else {
497
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
498
+ lastRow = module;
499
+ sameCountRow = 1;
500
+ }
501
+ }
502
+
503
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
504
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
505
+ }
506
+
507
+ return points
508
+ };
509
+
510
+ /**
511
+ * Find 2x2 blocks with the same color and assign a penalty value
512
+ *
513
+ * Points: N2 * (m - 1) * (n - 1)
514
+ */
515
+ exports.getPenaltyN2 = function getPenaltyN2 (data) {
516
+ const size = data.size;
517
+ let points = 0;
518
+
519
+ for (let row = 0; row < size - 1; row++) {
520
+ for (let col = 0; col < size - 1; col++) {
521
+ const last = data.get(row, col) +
522
+ data.get(row, col + 1) +
523
+ data.get(row + 1, col) +
524
+ data.get(row + 1, col + 1);
525
+
526
+ if (last === 4 || last === 0) points++;
527
+ }
528
+ }
529
+
530
+ return points * PenaltyScores.N2
531
+ };
532
+
533
+ /**
534
+ * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
535
+ * preceded or followed by light area 4 modules wide
536
+ *
537
+ * Points: N3 * number of pattern found
538
+ */
539
+ exports.getPenaltyN3 = function getPenaltyN3 (data) {
540
+ const size = data.size;
541
+ let points = 0;
542
+ let bitsCol = 0;
543
+ let bitsRow = 0;
544
+
545
+ for (let row = 0; row < size; row++) {
546
+ bitsCol = bitsRow = 0;
547
+ for (let col = 0; col < size; col++) {
548
+ bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col);
549
+ if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++;
550
+
551
+ bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row);
552
+ if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++;
553
+ }
554
+ }
555
+
556
+ return points * PenaltyScores.N3
557
+ };
558
+
559
+ /**
560
+ * Calculate proportion of dark modules in entire symbol
561
+ *
562
+ * Points: N4 * k
563
+ *
564
+ * k is the rating of the deviation of the proportion of dark modules
565
+ * in the symbol from 50% in steps of 5%
566
+ */
567
+ exports.getPenaltyN4 = function getPenaltyN4 (data) {
568
+ let darkCount = 0;
569
+ const modulesCount = data.data.length;
570
+
571
+ for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
572
+
573
+ const k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10);
574
+
575
+ return k * PenaltyScores.N4
576
+ };
577
+
578
+ /**
579
+ * Return mask value at given position
580
+ *
581
+ * @param {Number} maskPattern Pattern reference value
582
+ * @param {Number} i Row
583
+ * @param {Number} j Column
584
+ * @return {Boolean} Mask value
585
+ */
586
+ function getMaskAt (maskPattern, i, j) {
587
+ switch (maskPattern) {
588
+ case exports.Patterns.PATTERN000: return (i + j) % 2 === 0
589
+ case exports.Patterns.PATTERN001: return i % 2 === 0
590
+ case exports.Patterns.PATTERN010: return j % 3 === 0
591
+ case exports.Patterns.PATTERN011: return (i + j) % 3 === 0
592
+ case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0
593
+ case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0
594
+ case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0
595
+ case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0
596
+
597
+ default: throw new Error('bad maskPattern:' + maskPattern)
598
+ }
599
+ }
600
+
601
+ /**
602
+ * Apply a mask pattern to a BitMatrix
603
+ *
604
+ * @param {Number} pattern Pattern reference number
605
+ * @param {BitMatrix} data BitMatrix data
606
+ */
607
+ exports.applyMask = function applyMask (pattern, data) {
608
+ const size = data.size;
609
+
610
+ for (let col = 0; col < size; col++) {
611
+ for (let row = 0; row < size; row++) {
612
+ if (data.isReserved(row, col)) continue
613
+ data.xor(row, col, getMaskAt(pattern, row, col));
614
+ }
615
+ }
616
+ };
617
+
618
+ /**
619
+ * Returns the best mask pattern for data
620
+ *
621
+ * @param {BitMatrix} data
622
+ * @return {Number} Mask pattern reference number
623
+ */
624
+ exports.getBestMask = function getBestMask (data, setupFormatFunc) {
625
+ const numPatterns = Object.keys(exports.Patterns).length;
626
+ let bestPattern = 0;
627
+ let lowerPenalty = Infinity;
628
+
629
+ for (let p = 0; p < numPatterns; p++) {
630
+ setupFormatFunc(p);
631
+ exports.applyMask(p, data);
632
+
633
+ // Calculate penalty
634
+ const penalty =
635
+ exports.getPenaltyN1(data) +
636
+ exports.getPenaltyN2(data) +
637
+ exports.getPenaltyN3(data) +
638
+ exports.getPenaltyN4(data);
639
+
640
+ // Undo previously applied mask
641
+ exports.applyMask(p, data);
642
+
643
+ if (penalty < lowerPenalty) {
644
+ lowerPenalty = penalty;
645
+ bestPattern = p;
646
+ }
647
+ }
648
+
649
+ return bestPattern
650
+ };
651
+ } (maskPattern));
652
+ return maskPattern;
653
+ }
654
+
655
+ var errorCorrectionCode = {};
656
+
657
+ var hasRequiredErrorCorrectionCode;
658
+
659
+ function requireErrorCorrectionCode () {
660
+ if (hasRequiredErrorCorrectionCode) return errorCorrectionCode;
661
+ hasRequiredErrorCorrectionCode = 1;
662
+ const ECLevel = requireErrorCorrectionLevel();
663
+
664
+ const EC_BLOCKS_TABLE = [
665
+ // L M Q H
666
+ 1, 1, 1, 1,
667
+ 1, 1, 1, 1,
668
+ 1, 1, 2, 2,
669
+ 1, 2, 2, 4,
670
+ 1, 2, 4, 4,
671
+ 2, 4, 4, 4,
672
+ 2, 4, 6, 5,
673
+ 2, 4, 6, 6,
674
+ 2, 5, 8, 8,
675
+ 4, 5, 8, 8,
676
+ 4, 5, 8, 11,
677
+ 4, 8, 10, 11,
678
+ 4, 9, 12, 16,
679
+ 4, 9, 16, 16,
680
+ 6, 10, 12, 18,
681
+ 6, 10, 17, 16,
682
+ 6, 11, 16, 19,
683
+ 6, 13, 18, 21,
684
+ 7, 14, 21, 25,
685
+ 8, 16, 20, 25,
686
+ 8, 17, 23, 25,
687
+ 9, 17, 23, 34,
688
+ 9, 18, 25, 30,
689
+ 10, 20, 27, 32,
690
+ 12, 21, 29, 35,
691
+ 12, 23, 34, 37,
692
+ 12, 25, 34, 40,
693
+ 13, 26, 35, 42,
694
+ 14, 28, 38, 45,
695
+ 15, 29, 40, 48,
696
+ 16, 31, 43, 51,
697
+ 17, 33, 45, 54,
698
+ 18, 35, 48, 57,
699
+ 19, 37, 51, 60,
700
+ 19, 38, 53, 63,
701
+ 20, 40, 56, 66,
702
+ 21, 43, 59, 70,
703
+ 22, 45, 62, 74,
704
+ 24, 47, 65, 77,
705
+ 25, 49, 68, 81
706
+ ];
707
+
708
+ const EC_CODEWORDS_TABLE = [
709
+ // L M Q H
710
+ 7, 10, 13, 17,
711
+ 10, 16, 22, 28,
712
+ 15, 26, 36, 44,
713
+ 20, 36, 52, 64,
714
+ 26, 48, 72, 88,
715
+ 36, 64, 96, 112,
716
+ 40, 72, 108, 130,
717
+ 48, 88, 132, 156,
718
+ 60, 110, 160, 192,
719
+ 72, 130, 192, 224,
720
+ 80, 150, 224, 264,
721
+ 96, 176, 260, 308,
722
+ 104, 198, 288, 352,
723
+ 120, 216, 320, 384,
724
+ 132, 240, 360, 432,
725
+ 144, 280, 408, 480,
726
+ 168, 308, 448, 532,
727
+ 180, 338, 504, 588,
728
+ 196, 364, 546, 650,
729
+ 224, 416, 600, 700,
730
+ 224, 442, 644, 750,
731
+ 252, 476, 690, 816,
732
+ 270, 504, 750, 900,
733
+ 300, 560, 810, 960,
734
+ 312, 588, 870, 1050,
735
+ 336, 644, 952, 1110,
736
+ 360, 700, 1020, 1200,
737
+ 390, 728, 1050, 1260,
738
+ 420, 784, 1140, 1350,
739
+ 450, 812, 1200, 1440,
740
+ 480, 868, 1290, 1530,
741
+ 510, 924, 1350, 1620,
742
+ 540, 980, 1440, 1710,
743
+ 570, 1036, 1530, 1800,
744
+ 570, 1064, 1590, 1890,
745
+ 600, 1120, 1680, 1980,
746
+ 630, 1204, 1770, 2100,
747
+ 660, 1260, 1860, 2220,
748
+ 720, 1316, 1950, 2310,
749
+ 750, 1372, 2040, 2430
750
+ ];
751
+
752
+ /**
753
+ * Returns the number of error correction block that the QR Code should contain
754
+ * for the specified version and error correction level.
755
+ *
756
+ * @param {Number} version QR Code version
757
+ * @param {Number} errorCorrectionLevel Error correction level
758
+ * @return {Number} Number of error correction blocks
759
+ */
760
+ errorCorrectionCode.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {
761
+ switch (errorCorrectionLevel) {
762
+ case ECLevel.L:
763
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]
764
+ case ECLevel.M:
765
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]
766
+ case ECLevel.Q:
767
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]
768
+ case ECLevel.H:
769
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]
770
+ default:
771
+ return undefined
772
+ }
773
+ };
774
+
775
+ /**
776
+ * Returns the number of error correction codewords to use for the specified
777
+ * version and error correction level.
778
+ *
779
+ * @param {Number} version QR Code version
780
+ * @param {Number} errorCorrectionLevel Error correction level
781
+ * @return {Number} Number of error correction codewords
782
+ */
783
+ errorCorrectionCode.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {
784
+ switch (errorCorrectionLevel) {
785
+ case ECLevel.L:
786
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]
787
+ case ECLevel.M:
788
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]
789
+ case ECLevel.Q:
790
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]
791
+ case ECLevel.H:
792
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]
793
+ default:
794
+ return undefined
795
+ }
796
+ };
797
+ return errorCorrectionCode;
798
+ }
799
+
800
+ var polynomial = {};
801
+
802
+ var galoisField = {};
803
+
804
+ var hasRequiredGaloisField;
805
+
806
+ function requireGaloisField () {
807
+ if (hasRequiredGaloisField) return galoisField;
808
+ hasRequiredGaloisField = 1;
809
+ const EXP_TABLE = new Uint8Array(512);
810
+ const LOG_TABLE = new Uint8Array(256)
811
+ /**
812
+ * Precompute the log and anti-log tables for faster computation later
813
+ *
814
+ * For each possible value in the galois field 2^8, we will pre-compute
815
+ * the logarithm and anti-logarithm (exponential) of this value
816
+ *
817
+ * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}
818
+ */
819
+ ;(function initTables () {
820
+ let x = 1;
821
+ for (let i = 0; i < 255; i++) {
822
+ EXP_TABLE[i] = x;
823
+ LOG_TABLE[x] = i;
824
+
825
+ x <<= 1; // multiply by 2
826
+
827
+ // The QR code specification says to use byte-wise modulo 100011101 arithmetic.
828
+ // This means that when a number is 256 or larger, it should be XORed with 0x11D.
829
+ if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)
830
+ x ^= 0x11D;
831
+ }
832
+ }
833
+
834
+ // Optimization: double the size of the anti-log table so that we don't need to mod 255 to
835
+ // stay inside the bounds (because we will mainly use this table for the multiplication of
836
+ // two GF numbers, no more).
837
+ // @see {@link mul}
838
+ for (let i = 255; i < 512; i++) {
839
+ EXP_TABLE[i] = EXP_TABLE[i - 255];
840
+ }
841
+ }());
842
+
843
+ /**
844
+ * Returns log value of n inside Galois Field
845
+ *
846
+ * @param {Number} n
847
+ * @return {Number}
848
+ */
849
+ galoisField.log = function log (n) {
850
+ if (n < 1) throw new Error('log(' + n + ')')
851
+ return LOG_TABLE[n]
852
+ };
853
+
854
+ /**
855
+ * Returns anti-log value of n inside Galois Field
856
+ *
857
+ * @param {Number} n
858
+ * @return {Number}
859
+ */
860
+ galoisField.exp = function exp (n) {
861
+ return EXP_TABLE[n]
862
+ };
863
+
864
+ /**
865
+ * Multiplies two number inside Galois Field
866
+ *
867
+ * @param {Number} x
868
+ * @param {Number} y
869
+ * @return {Number}
870
+ */
871
+ galoisField.mul = function mul (x, y) {
872
+ if (x === 0 || y === 0) return 0
873
+
874
+ // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
875
+ // @see {@link initTables}
876
+ return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]
877
+ };
878
+ return galoisField;
879
+ }
880
+
881
+ var hasRequiredPolynomial;
882
+
883
+ function requirePolynomial () {
884
+ if (hasRequiredPolynomial) return polynomial;
885
+ hasRequiredPolynomial = 1;
886
+ (function (exports) {
887
+ const GF = requireGaloisField();
888
+
889
+ /**
890
+ * Multiplies two polynomials inside Galois Field
891
+ *
892
+ * @param {Uint8Array} p1 Polynomial
893
+ * @param {Uint8Array} p2 Polynomial
894
+ * @return {Uint8Array} Product of p1 and p2
895
+ */
896
+ exports.mul = function mul (p1, p2) {
897
+ const coeff = new Uint8Array(p1.length + p2.length - 1);
898
+
899
+ for (let i = 0; i < p1.length; i++) {
900
+ for (let j = 0; j < p2.length; j++) {
901
+ coeff[i + j] ^= GF.mul(p1[i], p2[j]);
902
+ }
903
+ }
904
+
905
+ return coeff
906
+ };
907
+
908
+ /**
909
+ * Calculate the remainder of polynomials division
910
+ *
911
+ * @param {Uint8Array} divident Polynomial
912
+ * @param {Uint8Array} divisor Polynomial
913
+ * @return {Uint8Array} Remainder
914
+ */
915
+ exports.mod = function mod (divident, divisor) {
916
+ let result = new Uint8Array(divident);
917
+
918
+ while ((result.length - divisor.length) >= 0) {
919
+ const coeff = result[0];
920
+
921
+ for (let i = 0; i < divisor.length; i++) {
922
+ result[i] ^= GF.mul(divisor[i], coeff);
923
+ }
924
+
925
+ // remove all zeros from buffer head
926
+ let offset = 0;
927
+ while (offset < result.length && result[offset] === 0) offset++;
928
+ result = result.slice(offset);
929
+ }
930
+
931
+ return result
932
+ };
933
+
934
+ /**
935
+ * Generate an irreducible generator polynomial of specified degree
936
+ * (used by Reed-Solomon encoder)
937
+ *
938
+ * @param {Number} degree Degree of the generator polynomial
939
+ * @return {Uint8Array} Buffer containing polynomial coefficients
940
+ */
941
+ exports.generateECPolynomial = function generateECPolynomial (degree) {
942
+ let poly = new Uint8Array([1]);
943
+ for (let i = 0; i < degree; i++) {
944
+ poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]));
945
+ }
946
+
947
+ return poly
948
+ };
949
+ } (polynomial));
950
+ return polynomial;
951
+ }
952
+
953
+ var reedSolomonEncoder;
954
+ var hasRequiredReedSolomonEncoder;
955
+
956
+ function requireReedSolomonEncoder () {
957
+ if (hasRequiredReedSolomonEncoder) return reedSolomonEncoder;
958
+ hasRequiredReedSolomonEncoder = 1;
959
+ const Polynomial = requirePolynomial();
960
+
961
+ function ReedSolomonEncoder (degree) {
962
+ this.genPoly = undefined;
963
+ this.degree = degree;
964
+
965
+ if (this.degree) this.initialize(this.degree);
966
+ }
967
+
968
+ /**
969
+ * Initialize the encoder.
970
+ * The input param should correspond to the number of error correction codewords.
971
+ *
972
+ * @param {Number} degree
973
+ */
974
+ ReedSolomonEncoder.prototype.initialize = function initialize (degree) {
975
+ // create an irreducible generator polynomial
976
+ this.degree = degree;
977
+ this.genPoly = Polynomial.generateECPolynomial(this.degree);
978
+ };
979
+
980
+ /**
981
+ * Encodes a chunk of data
982
+ *
983
+ * @param {Uint8Array} data Buffer containing input data
984
+ * @return {Uint8Array} Buffer containing encoded data
985
+ */
986
+ ReedSolomonEncoder.prototype.encode = function encode (data) {
987
+ if (!this.genPoly) {
988
+ throw new Error('Encoder not initialized')
989
+ }
990
+
991
+ // Calculate EC for this data block
992
+ // extends data size to data+genPoly size
993
+ const paddedData = new Uint8Array(data.length + this.degree);
994
+ paddedData.set(data);
995
+
996
+ // The error correction codewords are the remainder after dividing the data codewords
997
+ // by a generator polynomial
998
+ const remainder = Polynomial.mod(paddedData, this.genPoly);
999
+
1000
+ // return EC data blocks (last n byte, where n is the degree of genPoly)
1001
+ // If coefficients number in remainder are less than genPoly degree,
1002
+ // pad with 0s to the left to reach the needed number of coefficients
1003
+ const start = this.degree - remainder.length;
1004
+ if (start > 0) {
1005
+ const buff = new Uint8Array(this.degree);
1006
+ buff.set(remainder, start);
1007
+
1008
+ return buff
1009
+ }
1010
+
1011
+ return remainder
1012
+ };
1013
+
1014
+ reedSolomonEncoder = ReedSolomonEncoder;
1015
+ return reedSolomonEncoder;
1016
+ }
1017
+
1018
+ var version = {};
1019
+
1020
+ var mode = {};
1021
+
1022
+ var versionCheck = {};
1023
+
1024
+ /**
1025
+ * Check if QR Code version is valid
1026
+ *
1027
+ * @param {Number} version QR Code version
1028
+ * @return {Boolean} true if valid version, false otherwise
1029
+ */
1030
+
1031
+ var hasRequiredVersionCheck;
1032
+
1033
+ function requireVersionCheck () {
1034
+ if (hasRequiredVersionCheck) return versionCheck;
1035
+ hasRequiredVersionCheck = 1;
1036
+ versionCheck.isValid = function isValid (version) {
1037
+ return !isNaN(version) && version >= 1 && version <= 40
1038
+ };
1039
+ return versionCheck;
1040
+ }
1041
+
1042
+ var regex = {};
1043
+
1044
+ var hasRequiredRegex;
1045
+
1046
+ function requireRegex () {
1047
+ if (hasRequiredRegex) return regex;
1048
+ hasRequiredRegex = 1;
1049
+ const numeric = '[0-9]+';
1050
+ const alphanumeric = '[A-Z $%*+\\-./:]+';
1051
+ let kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +
1052
+ '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +
1053
+ '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +
1054
+ '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+';
1055
+ kanji = kanji.replace(/u/g, '\\u');
1056
+
1057
+ const byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+';
1058
+
1059
+ regex.KANJI = new RegExp(kanji, 'g');
1060
+ regex.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g');
1061
+ regex.BYTE = new RegExp(byte, 'g');
1062
+ regex.NUMERIC = new RegExp(numeric, 'g');
1063
+ regex.ALPHANUMERIC = new RegExp(alphanumeric, 'g');
1064
+
1065
+ const TEST_KANJI = new RegExp('^' + kanji + '$');
1066
+ const TEST_NUMERIC = new RegExp('^' + numeric + '$');
1067
+ const TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$');
1068
+
1069
+ regex.testKanji = function testKanji (str) {
1070
+ return TEST_KANJI.test(str)
1071
+ };
1072
+
1073
+ regex.testNumeric = function testNumeric (str) {
1074
+ return TEST_NUMERIC.test(str)
1075
+ };
1076
+
1077
+ regex.testAlphanumeric = function testAlphanumeric (str) {
1078
+ return TEST_ALPHANUMERIC.test(str)
1079
+ };
1080
+ return regex;
1081
+ }
1082
+
1083
+ var hasRequiredMode;
1084
+
1085
+ function requireMode () {
1086
+ if (hasRequiredMode) return mode;
1087
+ hasRequiredMode = 1;
1088
+ (function (exports) {
1089
+ const VersionCheck = requireVersionCheck();
1090
+ const Regex = requireRegex();
1091
+
1092
+ /**
1093
+ * Numeric mode encodes data from the decimal digit set (0 - 9)
1094
+ * (byte values 30HEX to 39HEX).
1095
+ * Normally, 3 data characters are represented by 10 bits.
1096
+ *
1097
+ * @type {Object}
1098
+ */
1099
+ exports.NUMERIC = {
1100
+ id: 'Numeric',
1101
+ bit: 1 << 0,
1102
+ ccBits: [10, 12, 14]
1103
+ };
1104
+
1105
+ /**
1106
+ * Alphanumeric mode encodes data from a set of 45 characters,
1107
+ * i.e. 10 numeric digits (0 - 9),
1108
+ * 26 alphabetic characters (A - Z),
1109
+ * and 9 symbols (SP, $, %, *, +, -, ., /, :).
1110
+ * Normally, two input characters are represented by 11 bits.
1111
+ *
1112
+ * @type {Object}
1113
+ */
1114
+ exports.ALPHANUMERIC = {
1115
+ id: 'Alphanumeric',
1116
+ bit: 1 << 1,
1117
+ ccBits: [9, 11, 13]
1118
+ };
1119
+
1120
+ /**
1121
+ * In byte mode, data is encoded at 8 bits per character.
1122
+ *
1123
+ * @type {Object}
1124
+ */
1125
+ exports.BYTE = {
1126
+ id: 'Byte',
1127
+ bit: 1 << 2,
1128
+ ccBits: [8, 16, 16]
1129
+ };
1130
+
1131
+ /**
1132
+ * The Kanji mode efficiently encodes Kanji characters in accordance with
1133
+ * the Shift JIS system based on JIS X 0208.
1134
+ * The Shift JIS values are shifted from the JIS X 0208 values.
1135
+ * JIS X 0208 gives details of the shift coded representation.
1136
+ * Each two-byte character value is compacted to a 13-bit binary codeword.
1137
+ *
1138
+ * @type {Object}
1139
+ */
1140
+ exports.KANJI = {
1141
+ id: 'Kanji',
1142
+ bit: 1 << 3,
1143
+ ccBits: [8, 10, 12]
1144
+ };
1145
+
1146
+ /**
1147
+ * Mixed mode will contain a sequences of data in a combination of any of
1148
+ * the modes described above
1149
+ *
1150
+ * @type {Object}
1151
+ */
1152
+ exports.MIXED = {
1153
+ bit: -1
1154
+ };
1155
+
1156
+ /**
1157
+ * Returns the number of bits needed to store the data length
1158
+ * according to QR Code specifications.
1159
+ *
1160
+ * @param {Mode} mode Data mode
1161
+ * @param {Number} version QR Code version
1162
+ * @return {Number} Number of bits
1163
+ */
1164
+ exports.getCharCountIndicator = function getCharCountIndicator (mode, version) {
1165
+ if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)
1166
+
1167
+ if (!VersionCheck.isValid(version)) {
1168
+ throw new Error('Invalid version: ' + version)
1169
+ }
1170
+
1171
+ if (version >= 1 && version < 10) return mode.ccBits[0]
1172
+ else if (version < 27) return mode.ccBits[1]
1173
+ return mode.ccBits[2]
1174
+ };
1175
+
1176
+ /**
1177
+ * Returns the most efficient mode to store the specified data
1178
+ *
1179
+ * @param {String} dataStr Input data string
1180
+ * @return {Mode} Best mode
1181
+ */
1182
+ exports.getBestModeForData = function getBestModeForData (dataStr) {
1183
+ if (Regex.testNumeric(dataStr)) return exports.NUMERIC
1184
+ else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC
1185
+ else if (Regex.testKanji(dataStr)) return exports.KANJI
1186
+ else return exports.BYTE
1187
+ };
1188
+
1189
+ /**
1190
+ * Return mode name as string
1191
+ *
1192
+ * @param {Mode} mode Mode object
1193
+ * @returns {String} Mode name
1194
+ */
1195
+ exports.toString = function toString (mode) {
1196
+ if (mode && mode.id) return mode.id
1197
+ throw new Error('Invalid mode')
1198
+ };
1199
+
1200
+ /**
1201
+ * Check if input param is a valid mode object
1202
+ *
1203
+ * @param {Mode} mode Mode object
1204
+ * @returns {Boolean} True if valid mode, false otherwise
1205
+ */
1206
+ exports.isValid = function isValid (mode) {
1207
+ return mode && mode.bit && mode.ccBits
1208
+ };
1209
+
1210
+ /**
1211
+ * Get mode object from its name
1212
+ *
1213
+ * @param {String} string Mode name
1214
+ * @returns {Mode} Mode object
1215
+ */
1216
+ function fromString (string) {
1217
+ if (typeof string !== 'string') {
1218
+ throw new Error('Param is not a string')
1219
+ }
1220
+
1221
+ const lcStr = string.toLowerCase();
1222
+
1223
+ switch (lcStr) {
1224
+ case 'numeric':
1225
+ return exports.NUMERIC
1226
+ case 'alphanumeric':
1227
+ return exports.ALPHANUMERIC
1228
+ case 'kanji':
1229
+ return exports.KANJI
1230
+ case 'byte':
1231
+ return exports.BYTE
1232
+ default:
1233
+ throw new Error('Unknown mode: ' + string)
1234
+ }
1235
+ }
1236
+
1237
+ /**
1238
+ * Returns mode from a value.
1239
+ * If value is not a valid mode, returns defaultValue
1240
+ *
1241
+ * @param {Mode|String} value Encoding mode
1242
+ * @param {Mode} defaultValue Fallback value
1243
+ * @return {Mode} Encoding mode
1244
+ */
1245
+ exports.from = function from (value, defaultValue) {
1246
+ if (exports.isValid(value)) {
1247
+ return value
1248
+ }
1249
+
1250
+ try {
1251
+ return fromString(value)
1252
+ } catch (e) {
1253
+ return defaultValue
1254
+ }
1255
+ };
1256
+ } (mode));
1257
+ return mode;
1258
+ }
1259
+
1260
+ var hasRequiredVersion;
1261
+
1262
+ function requireVersion () {
1263
+ if (hasRequiredVersion) return version;
1264
+ hasRequiredVersion = 1;
1265
+ (function (exports) {
1266
+ const Utils = requireUtils$1();
1267
+ const ECCode = requireErrorCorrectionCode();
1268
+ const ECLevel = requireErrorCorrectionLevel();
1269
+ const Mode = requireMode();
1270
+ const VersionCheck = requireVersionCheck();
1271
+
1272
+ // Generator polynomial used to encode version information
1273
+ const G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
1274
+ const G18_BCH = Utils.getBCHDigit(G18);
1275
+
1276
+ function getBestVersionForDataLength (mode, length, errorCorrectionLevel) {
1277
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1278
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
1279
+ return currentVersion
1280
+ }
1281
+ }
1282
+
1283
+ return undefined
1284
+ }
1285
+
1286
+ function getReservedBitsCount (mode, version) {
1287
+ // Character count indicator + mode indicator bits
1288
+ return Mode.getCharCountIndicator(mode, version) + 4
1289
+ }
1290
+
1291
+ function getTotalBitsFromDataArray (segments, version) {
1292
+ let totalBits = 0;
1293
+
1294
+ segments.forEach(function (data) {
1295
+ const reservedBits = getReservedBitsCount(data.mode, version);
1296
+ totalBits += reservedBits + data.getBitsLength();
1297
+ });
1298
+
1299
+ return totalBits
1300
+ }
1301
+
1302
+ function getBestVersionForMixedData (segments, errorCorrectionLevel) {
1303
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1304
+ const length = getTotalBitsFromDataArray(segments, currentVersion);
1305
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
1306
+ return currentVersion
1307
+ }
1308
+ }
1309
+
1310
+ return undefined
1311
+ }
1312
+
1313
+ /**
1314
+ * Returns version number from a value.
1315
+ * If value is not a valid version, returns defaultValue
1316
+ *
1317
+ * @param {Number|String} value QR Code version
1318
+ * @param {Number} defaultValue Fallback value
1319
+ * @return {Number} QR Code version number
1320
+ */
1321
+ exports.from = function from (value, defaultValue) {
1322
+ if (VersionCheck.isValid(value)) {
1323
+ return parseInt(value, 10)
1324
+ }
1325
+
1326
+ return defaultValue
1327
+ };
1328
+
1329
+ /**
1330
+ * Returns how much data can be stored with the specified QR code version
1331
+ * and error correction level
1332
+ *
1333
+ * @param {Number} version QR Code version (1-40)
1334
+ * @param {Number} errorCorrectionLevel Error correction level
1335
+ * @param {Mode} mode Data mode
1336
+ * @return {Number} Quantity of storable data
1337
+ */
1338
+ exports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {
1339
+ if (!VersionCheck.isValid(version)) {
1340
+ throw new Error('Invalid QR Code version')
1341
+ }
1342
+
1343
+ // Use Byte mode as default
1344
+ if (typeof mode === 'undefined') mode = Mode.BYTE;
1345
+
1346
+ // Total codewords for this QR code version (Data + Error correction)
1347
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
1348
+
1349
+ // Total number of error correction codewords
1350
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
1351
+
1352
+ // Total number of data codewords
1353
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
1354
+
1355
+ if (mode === Mode.MIXED) return dataTotalCodewordsBits
1356
+
1357
+ const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
1358
+
1359
+ // Return max number of storable codewords
1360
+ switch (mode) {
1361
+ case Mode.NUMERIC:
1362
+ return Math.floor((usableBits / 10) * 3)
1363
+
1364
+ case Mode.ALPHANUMERIC:
1365
+ return Math.floor((usableBits / 11) * 2)
1366
+
1367
+ case Mode.KANJI:
1368
+ return Math.floor(usableBits / 13)
1369
+
1370
+ case Mode.BYTE:
1371
+ default:
1372
+ return Math.floor(usableBits / 8)
1373
+ }
1374
+ };
1375
+
1376
+ /**
1377
+ * Returns the minimum version needed to contain the amount of data
1378
+ *
1379
+ * @param {Segment} data Segment of data
1380
+ * @param {Number} [errorCorrectionLevel=H] Error correction level
1381
+ * @param {Mode} mode Data mode
1382
+ * @return {Number} QR Code version
1383
+ */
1384
+ exports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {
1385
+ let seg;
1386
+
1387
+ const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
1388
+
1389
+ if (Array.isArray(data)) {
1390
+ if (data.length > 1) {
1391
+ return getBestVersionForMixedData(data, ecl)
1392
+ }
1393
+
1394
+ if (data.length === 0) {
1395
+ return 1
1396
+ }
1397
+
1398
+ seg = data[0];
1399
+ } else {
1400
+ seg = data;
1401
+ }
1402
+
1403
+ return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)
1404
+ };
1405
+
1406
+ /**
1407
+ * Returns version information with relative error correction bits
1408
+ *
1409
+ * The version information is included in QR Code symbols of version 7 or larger.
1410
+ * It consists of an 18-bit sequence containing 6 data bits,
1411
+ * with 12 error correction bits calculated using the (18, 6) Golay code.
1412
+ *
1413
+ * @param {Number} version QR Code version
1414
+ * @return {Number} Encoded version info bits
1415
+ */
1416
+ exports.getEncodedBits = function getEncodedBits (version) {
1417
+ if (!VersionCheck.isValid(version) || version < 7) {
1418
+ throw new Error('Invalid QR Code version')
1419
+ }
1420
+
1421
+ let d = version << 12;
1422
+
1423
+ while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
1424
+ d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH));
1425
+ }
1426
+
1427
+ return (version << 12) | d
1428
+ };
1429
+ } (version));
1430
+ return version;
1431
+ }
1432
+
1433
+ var formatInfo = {};
1434
+
1435
+ var hasRequiredFormatInfo;
1436
+
1437
+ function requireFormatInfo () {
1438
+ if (hasRequiredFormatInfo) return formatInfo;
1439
+ hasRequiredFormatInfo = 1;
1440
+ const Utils = requireUtils$1();
1441
+
1442
+ const G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
1443
+ const G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
1444
+ const G15_BCH = Utils.getBCHDigit(G15);
1445
+
1446
+ /**
1447
+ * Returns format information with relative error correction bits
1448
+ *
1449
+ * The format information is a 15-bit sequence containing 5 data bits,
1450
+ * with 10 error correction bits calculated using the (15, 5) BCH code.
1451
+ *
1452
+ * @param {Number} errorCorrectionLevel Error correction level
1453
+ * @param {Number} mask Mask pattern
1454
+ * @return {Number} Encoded format information bits
1455
+ */
1456
+ formatInfo.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
1457
+ const data = ((errorCorrectionLevel.bit << 3) | mask);
1458
+ let d = data << 10;
1459
+
1460
+ while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
1461
+ d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH));
1462
+ }
1463
+
1464
+ // xor final data with mask pattern in order to ensure that
1465
+ // no combination of Error Correction Level and data mask pattern
1466
+ // will result in an all-zero data string
1467
+ return ((data << 10) | d) ^ G15_MASK
1468
+ };
1469
+ return formatInfo;
1470
+ }
1471
+
1472
+ var segments = {};
1473
+
1474
+ var numericData;
1475
+ var hasRequiredNumericData;
1476
+
1477
+ function requireNumericData () {
1478
+ if (hasRequiredNumericData) return numericData;
1479
+ hasRequiredNumericData = 1;
1480
+ const Mode = requireMode();
1481
+
1482
+ function NumericData (data) {
1483
+ this.mode = Mode.NUMERIC;
1484
+ this.data = data.toString();
1485
+ }
1486
+
1487
+ NumericData.getBitsLength = function getBitsLength (length) {
1488
+ return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
1489
+ };
1490
+
1491
+ NumericData.prototype.getLength = function getLength () {
1492
+ return this.data.length
1493
+ };
1494
+
1495
+ NumericData.prototype.getBitsLength = function getBitsLength () {
1496
+ return NumericData.getBitsLength(this.data.length)
1497
+ };
1498
+
1499
+ NumericData.prototype.write = function write (bitBuffer) {
1500
+ let i, group, value;
1501
+
1502
+ // The input data string is divided into groups of three digits,
1503
+ // and each group is converted to its 10-bit binary equivalent.
1504
+ for (i = 0; i + 3 <= this.data.length; i += 3) {
1505
+ group = this.data.substr(i, 3);
1506
+ value = parseInt(group, 10);
1507
+
1508
+ bitBuffer.put(value, 10);
1509
+ }
1510
+
1511
+ // If the number of input digits is not an exact multiple of three,
1512
+ // the final one or two digits are converted to 4 or 7 bits respectively.
1513
+ const remainingNum = this.data.length - i;
1514
+ if (remainingNum > 0) {
1515
+ group = this.data.substr(i);
1516
+ value = parseInt(group, 10);
1517
+
1518
+ bitBuffer.put(value, remainingNum * 3 + 1);
1519
+ }
1520
+ };
1521
+
1522
+ numericData = NumericData;
1523
+ return numericData;
1524
+ }
1525
+
1526
+ var alphanumericData;
1527
+ var hasRequiredAlphanumericData;
1528
+
1529
+ function requireAlphanumericData () {
1530
+ if (hasRequiredAlphanumericData) return alphanumericData;
1531
+ hasRequiredAlphanumericData = 1;
1532
+ const Mode = requireMode();
1533
+
1534
+ /**
1535
+ * Array of characters available in alphanumeric mode
1536
+ *
1537
+ * As per QR Code specification, to each character
1538
+ * is assigned a value from 0 to 44 which in this case coincides
1539
+ * with the array index
1540
+ *
1541
+ * @type {Array}
1542
+ */
1543
+ const ALPHA_NUM_CHARS = [
1544
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
1545
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
1546
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
1547
+ ' ', '$', '%', '*', '+', '-', '.', '/', ':'
1548
+ ];
1549
+
1550
+ function AlphanumericData (data) {
1551
+ this.mode = Mode.ALPHANUMERIC;
1552
+ this.data = data;
1553
+ }
1554
+
1555
+ AlphanumericData.getBitsLength = function getBitsLength (length) {
1556
+ return 11 * Math.floor(length / 2) + 6 * (length % 2)
1557
+ };
1558
+
1559
+ AlphanumericData.prototype.getLength = function getLength () {
1560
+ return this.data.length
1561
+ };
1562
+
1563
+ AlphanumericData.prototype.getBitsLength = function getBitsLength () {
1564
+ return AlphanumericData.getBitsLength(this.data.length)
1565
+ };
1566
+
1567
+ AlphanumericData.prototype.write = function write (bitBuffer) {
1568
+ let i;
1569
+
1570
+ // Input data characters are divided into groups of two characters
1571
+ // and encoded as 11-bit binary codes.
1572
+ for (i = 0; i + 2 <= this.data.length; i += 2) {
1573
+ // The character value of the first character is multiplied by 45
1574
+ let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
1575
+
1576
+ // The character value of the second digit is added to the product
1577
+ value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
1578
+
1579
+ // The sum is then stored as 11-bit binary number
1580
+ bitBuffer.put(value, 11);
1581
+ }
1582
+
1583
+ // If the number of input data characters is not a multiple of two,
1584
+ // the character value of the final character is encoded as a 6-bit binary number.
1585
+ if (this.data.length % 2) {
1586
+ bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
1587
+ }
1588
+ };
1589
+
1590
+ alphanumericData = AlphanumericData;
1591
+ return alphanumericData;
1592
+ }
1593
+
1594
+ var encodeUtf8;
1595
+ var hasRequiredEncodeUtf8;
1596
+
1597
+ function requireEncodeUtf8 () {
1598
+ if (hasRequiredEncodeUtf8) return encodeUtf8;
1599
+ hasRequiredEncodeUtf8 = 1;
1600
+ 'use strict';
1601
+
1602
+ encodeUtf8 = function encodeUtf8 (input) {
1603
+ var result = [];
1604
+ var size = input.length;
1605
+
1606
+ for (var index = 0; index < size; index++) {
1607
+ var point = input.charCodeAt(index);
1608
+
1609
+ if (point >= 0xD800 && point <= 0xDBFF && size > index + 1) {
1610
+ var second = input.charCodeAt(index + 1);
1611
+
1612
+ if (second >= 0xDC00 && second <= 0xDFFF) {
1613
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
1614
+ point = (point - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
1615
+ index += 1;
1616
+ }
1617
+ }
1618
+
1619
+ // US-ASCII
1620
+ if (point < 0x80) {
1621
+ result.push(point);
1622
+ continue
1623
+ }
1624
+
1625
+ // 2-byte UTF-8
1626
+ if (point < 0x800) {
1627
+ result.push((point >> 6) | 192);
1628
+ result.push((point & 63) | 128);
1629
+ continue
1630
+ }
1631
+
1632
+ // 3-byte UTF-8
1633
+ if (point < 0xD800 || (point >= 0xE000 && point < 0x10000)) {
1634
+ result.push((point >> 12) | 224);
1635
+ result.push(((point >> 6) & 63) | 128);
1636
+ result.push((point & 63) | 128);
1637
+ continue
1638
+ }
1639
+
1640
+ // 4-byte UTF-8
1641
+ if (point >= 0x10000 && point <= 0x10FFFF) {
1642
+ result.push((point >> 18) | 240);
1643
+ result.push(((point >> 12) & 63) | 128);
1644
+ result.push(((point >> 6) & 63) | 128);
1645
+ result.push((point & 63) | 128);
1646
+ continue
1647
+ }
1648
+
1649
+ // Invalid character
1650
+ result.push(0xEF, 0xBF, 0xBD);
1651
+ }
1652
+
1653
+ return new Uint8Array(result).buffer
1654
+ };
1655
+ return encodeUtf8;
1656
+ }
1657
+
1658
+ var byteData;
1659
+ var hasRequiredByteData;
1660
+
1661
+ function requireByteData () {
1662
+ if (hasRequiredByteData) return byteData;
1663
+ hasRequiredByteData = 1;
1664
+ const encodeUtf8 = requireEncodeUtf8();
1665
+ const Mode = requireMode();
1666
+
1667
+ function ByteData (data) {
1668
+ this.mode = Mode.BYTE;
1669
+ if (typeof (data) === 'string') {
1670
+ data = encodeUtf8(data);
1671
+ }
1672
+ this.data = new Uint8Array(data);
1673
+ }
1674
+
1675
+ ByteData.getBitsLength = function getBitsLength (length) {
1676
+ return length * 8
1677
+ };
1678
+
1679
+ ByteData.prototype.getLength = function getLength () {
1680
+ return this.data.length
1681
+ };
1682
+
1683
+ ByteData.prototype.getBitsLength = function getBitsLength () {
1684
+ return ByteData.getBitsLength(this.data.length)
1685
+ };
1686
+
1687
+ ByteData.prototype.write = function (bitBuffer) {
1688
+ for (let i = 0, l = this.data.length; i < l; i++) {
1689
+ bitBuffer.put(this.data[i], 8);
1690
+ }
1691
+ };
1692
+
1693
+ byteData = ByteData;
1694
+ return byteData;
1695
+ }
1696
+
1697
+ var kanjiData;
1698
+ var hasRequiredKanjiData;
1699
+
1700
+ function requireKanjiData () {
1701
+ if (hasRequiredKanjiData) return kanjiData;
1702
+ hasRequiredKanjiData = 1;
1703
+ const Mode = requireMode();
1704
+ const Utils = requireUtils$1();
1705
+
1706
+ function KanjiData (data) {
1707
+ this.mode = Mode.KANJI;
1708
+ this.data = data;
1709
+ }
1710
+
1711
+ KanjiData.getBitsLength = function getBitsLength (length) {
1712
+ return length * 13
1713
+ };
1714
+
1715
+ KanjiData.prototype.getLength = function getLength () {
1716
+ return this.data.length
1717
+ };
1718
+
1719
+ KanjiData.prototype.getBitsLength = function getBitsLength () {
1720
+ return KanjiData.getBitsLength(this.data.length)
1721
+ };
1722
+
1723
+ KanjiData.prototype.write = function (bitBuffer) {
1724
+ let i;
1725
+
1726
+ // In the Shift JIS system, Kanji characters are represented by a two byte combination.
1727
+ // These byte values are shifted from the JIS X 0208 values.
1728
+ // JIS X 0208 gives details of the shift coded representation.
1729
+ for (i = 0; i < this.data.length; i++) {
1730
+ let value = Utils.toSJIS(this.data[i]);
1731
+
1732
+ // For characters with Shift JIS values from 0x8140 to 0x9FFC:
1733
+ if (value >= 0x8140 && value <= 0x9FFC) {
1734
+ // Subtract 0x8140 from Shift JIS value
1735
+ value -= 0x8140;
1736
+
1737
+ // For characters with Shift JIS values from 0xE040 to 0xEBBF
1738
+ } else if (value >= 0xE040 && value <= 0xEBBF) {
1739
+ // Subtract 0xC140 from Shift JIS value
1740
+ value -= 0xC140;
1741
+ } else {
1742
+ throw new Error(
1743
+ 'Invalid SJIS character: ' + this.data[i] + '\n' +
1744
+ 'Make sure your charset is UTF-8')
1745
+ }
1746
+
1747
+ // Multiply most significant byte of result by 0xC0
1748
+ // and add least significant byte to product
1749
+ value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff);
1750
+
1751
+ // Convert result to a 13-bit binary string
1752
+ bitBuffer.put(value, 13);
1753
+ }
1754
+ };
1755
+
1756
+ kanjiData = KanjiData;
1757
+ return kanjiData;
1758
+ }
1759
+
1760
+ var dijkstra = {exports: {}};
1761
+
1762
+ var dijkstra_1 = dijkstra.exports;
1763
+
1764
+ var hasRequiredDijkstra;
1765
+
1766
+ function requireDijkstra () {
1767
+ if (hasRequiredDijkstra) return dijkstra.exports;
1768
+ hasRequiredDijkstra = 1;
1769
+ (function (module) {
1770
+ 'use strict';
1771
+
1772
+ /******************************************************************************
1773
+ * Created 2008-08-19.
1774
+ *
1775
+ * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
1776
+ *
1777
+ * Copyright (C) 2008
1778
+ * Wyatt Baldwin <self@wyattbaldwin.com>
1779
+ * All rights reserved
1780
+ *
1781
+ * Licensed under the MIT license.
1782
+ *
1783
+ * http://www.opensource.org/licenses/mit-license.php
1784
+ *
1785
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1786
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1787
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1788
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1789
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1790
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1791
+ * THE SOFTWARE.
1792
+ *****************************************************************************/
1793
+ var dijkstra = {
1794
+ single_source_shortest_paths: function(graph, s, d) {
1795
+ // Predecessor map for each node that has been encountered.
1796
+ // node ID => predecessor node ID
1797
+ var predecessors = {};
1798
+
1799
+ // Costs of shortest paths from s to all nodes encountered.
1800
+ // node ID => cost
1801
+ var costs = {};
1802
+ costs[s] = 0;
1803
+
1804
+ // Costs of shortest paths from s to all nodes encountered; differs from
1805
+ // `costs` in that it provides easy access to the node that currently has
1806
+ // the known shortest path from s.
1807
+ // XXX: Do we actually need both `costs` and `open`?
1808
+ var open = dijkstra.PriorityQueue.make();
1809
+ open.push(s, 0);
1810
+
1811
+ var closest,
1812
+ u, v,
1813
+ cost_of_s_to_u,
1814
+ adjacent_nodes,
1815
+ cost_of_e,
1816
+ cost_of_s_to_u_plus_cost_of_e,
1817
+ cost_of_s_to_v,
1818
+ first_visit;
1819
+ while (!open.empty()) {
1820
+ // In the nodes remaining in graph that have a known cost from s,
1821
+ // find the node, u, that currently has the shortest path from s.
1822
+ closest = open.pop();
1823
+ u = closest.value;
1824
+ cost_of_s_to_u = closest.cost;
1825
+
1826
+ // Get nodes adjacent to u...
1827
+ adjacent_nodes = graph[u] || {};
1828
+
1829
+ // ...and explore the edges that connect u to those nodes, updating
1830
+ // the cost of the shortest paths to any or all of those nodes as
1831
+ // necessary. v is the node across the current edge from u.
1832
+ for (v in adjacent_nodes) {
1833
+ if (adjacent_nodes.hasOwnProperty(v)) {
1834
+ // Get the cost of the edge running from u to v.
1835
+ cost_of_e = adjacent_nodes[v];
1836
+
1837
+ // Cost of s to u plus the cost of u to v across e--this is *a*
1838
+ // cost from s to v that may or may not be less than the current
1839
+ // known cost to v.
1840
+ cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
1841
+
1842
+ // If we haven't visited v yet OR if the current known cost from s to
1843
+ // v is greater than the new cost we just found (cost of s to u plus
1844
+ // cost of u to v across e), update v's cost in the cost list and
1845
+ // update v's predecessor in the predecessor list (it's now u).
1846
+ cost_of_s_to_v = costs[v];
1847
+ first_visit = (typeof costs[v] === 'undefined');
1848
+ if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
1849
+ costs[v] = cost_of_s_to_u_plus_cost_of_e;
1850
+ open.push(v, cost_of_s_to_u_plus_cost_of_e);
1851
+ predecessors[v] = u;
1852
+ }
1853
+ }
1854
+ }
1855
+ }
1856
+
1857
+ if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {
1858
+ var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');
1859
+ throw new Error(msg);
1860
+ }
1861
+
1862
+ return predecessors;
1863
+ },
1864
+
1865
+ extract_shortest_path_from_predecessor_list: function(predecessors, d) {
1866
+ var nodes = [];
1867
+ var u = d;
1868
+ var predecessor;
1869
+ while (u) {
1870
+ nodes.push(u);
1871
+ predecessor = predecessors[u];
1872
+ u = predecessors[u];
1873
+ }
1874
+ nodes.reverse();
1875
+ return nodes;
1876
+ },
1877
+
1878
+ find_path: function(graph, s, d) {
1879
+ var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
1880
+ return dijkstra.extract_shortest_path_from_predecessor_list(
1881
+ predecessors, d);
1882
+ },
1883
+
1884
+ /**
1885
+ * A very naive priority queue implementation.
1886
+ */
1887
+ PriorityQueue: {
1888
+ make: function (opts) {
1889
+ var T = dijkstra.PriorityQueue,
1890
+ t = {},
1891
+ key;
1892
+ opts = opts || {};
1893
+ for (key in T) {
1894
+ if (T.hasOwnProperty(key)) {
1895
+ t[key] = T[key];
1896
+ }
1897
+ }
1898
+ t.queue = [];
1899
+ t.sorter = opts.sorter || T.default_sorter;
1900
+ return t;
1901
+ },
1902
+
1903
+ default_sorter: function (a, b) {
1904
+ return a.cost - b.cost;
1905
+ },
1906
+
1907
+ /**
1908
+ * Add a new item to the queue and ensure the highest priority element
1909
+ * is at the front of the queue.
1910
+ */
1911
+ push: function (value, cost) {
1912
+ var item = {value: value, cost: cost};
1913
+ this.queue.push(item);
1914
+ this.queue.sort(this.sorter);
1915
+ },
1916
+
1917
+ /**
1918
+ * Return the highest priority element in the queue.
1919
+ */
1920
+ pop: function () {
1921
+ return this.queue.shift();
1922
+ },
1923
+
1924
+ empty: function () {
1925
+ return this.queue.length === 0;
1926
+ }
1927
+ }
1928
+ };
1929
+
1930
+
1931
+ // node.js module exports
1932
+ if ('object' !== 'undefined') {
1933
+ module.exports = dijkstra;
1934
+ }
1935
+ } (dijkstra));
1936
+ return dijkstra.exports;
1937
+ }
1938
+
1939
+ var hasRequiredSegments;
1940
+
1941
+ function requireSegments () {
1942
+ if (hasRequiredSegments) return segments;
1943
+ hasRequiredSegments = 1;
1944
+ (function (exports) {
1945
+ const Mode = requireMode();
1946
+ const NumericData = requireNumericData();
1947
+ const AlphanumericData = requireAlphanumericData();
1948
+ const ByteData = requireByteData();
1949
+ const KanjiData = requireKanjiData();
1950
+ const Regex = requireRegex();
1951
+ const Utils = requireUtils$1();
1952
+ const dijkstra = requireDijkstra();
1953
+
1954
+ /**
1955
+ * Returns UTF8 byte length
1956
+ *
1957
+ * @param {String} str Input string
1958
+ * @return {Number} Number of byte
1959
+ */
1960
+ function getStringByteLength (str) {
1961
+ return unescape(encodeURIComponent(str)).length
1962
+ }
1963
+
1964
+ /**
1965
+ * Get a list of segments of the specified mode
1966
+ * from a string
1967
+ *
1968
+ * @param {Mode} mode Segment mode
1969
+ * @param {String} str String to process
1970
+ * @return {Array} Array of object with segments data
1971
+ */
1972
+ function getSegments (regex, mode, str) {
1973
+ const segments = [];
1974
+ let result;
1975
+
1976
+ while ((result = regex.exec(str)) !== null) {
1977
+ segments.push({
1978
+ data: result[0],
1979
+ index: result.index,
1980
+ mode: mode,
1981
+ length: result[0].length
1982
+ });
1983
+ }
1984
+
1985
+ return segments
1986
+ }
1987
+
1988
+ /**
1989
+ * Extracts a series of segments with the appropriate
1990
+ * modes from a string
1991
+ *
1992
+ * @param {String} dataStr Input string
1993
+ * @return {Array} Array of object with segments data
1994
+ */
1995
+ function getSegmentsFromString (dataStr) {
1996
+ const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
1997
+ const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
1998
+ let byteSegs;
1999
+ let kanjiSegs;
2000
+
2001
+ if (Utils.isKanjiModeEnabled()) {
2002
+ byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
2003
+ kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
2004
+ } else {
2005
+ byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
2006
+ kanjiSegs = [];
2007
+ }
2008
+
2009
+ const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
2010
+
2011
+ return segs
2012
+ .sort(function (s1, s2) {
2013
+ return s1.index - s2.index
2014
+ })
2015
+ .map(function (obj) {
2016
+ return {
2017
+ data: obj.data,
2018
+ mode: obj.mode,
2019
+ length: obj.length
2020
+ }
2021
+ })
2022
+ }
2023
+
2024
+ /**
2025
+ * Returns how many bits are needed to encode a string of
2026
+ * specified length with the specified mode
2027
+ *
2028
+ * @param {Number} length String length
2029
+ * @param {Mode} mode Segment mode
2030
+ * @return {Number} Bit length
2031
+ */
2032
+ function getSegmentBitsLength (length, mode) {
2033
+ switch (mode) {
2034
+ case Mode.NUMERIC:
2035
+ return NumericData.getBitsLength(length)
2036
+ case Mode.ALPHANUMERIC:
2037
+ return AlphanumericData.getBitsLength(length)
2038
+ case Mode.KANJI:
2039
+ return KanjiData.getBitsLength(length)
2040
+ case Mode.BYTE:
2041
+ return ByteData.getBitsLength(length)
2042
+ }
2043
+ }
2044
+
2045
+ /**
2046
+ * Merges adjacent segments which have the same mode
2047
+ *
2048
+ * @param {Array} segs Array of object with segments data
2049
+ * @return {Array} Array of object with segments data
2050
+ */
2051
+ function mergeSegments (segs) {
2052
+ return segs.reduce(function (acc, curr) {
2053
+ const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
2054
+ if (prevSeg && prevSeg.mode === curr.mode) {
2055
+ acc[acc.length - 1].data += curr.data;
2056
+ return acc
2057
+ }
2058
+
2059
+ acc.push(curr);
2060
+ return acc
2061
+ }, [])
2062
+ }
2063
+
2064
+ /**
2065
+ * Generates a list of all possible nodes combination which
2066
+ * will be used to build a segments graph.
2067
+ *
2068
+ * Nodes are divided by groups. Each group will contain a list of all the modes
2069
+ * in which is possible to encode the given text.
2070
+ *
2071
+ * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
2072
+ * The group for '12345' will contain then 3 objects, one for each
2073
+ * possible encoding mode.
2074
+ *
2075
+ * Each node represents a possible segment.
2076
+ *
2077
+ * @param {Array} segs Array of object with segments data
2078
+ * @return {Array} Array of object with segments data
2079
+ */
2080
+ function buildNodes (segs) {
2081
+ const nodes = [];
2082
+ for (let i = 0; i < segs.length; i++) {
2083
+ const seg = segs[i];
2084
+
2085
+ switch (seg.mode) {
2086
+ case Mode.NUMERIC:
2087
+ nodes.push([seg,
2088
+ { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
2089
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
2090
+ ]);
2091
+ break
2092
+ case Mode.ALPHANUMERIC:
2093
+ nodes.push([seg,
2094
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
2095
+ ]);
2096
+ break
2097
+ case Mode.KANJI:
2098
+ nodes.push([seg,
2099
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
2100
+ ]);
2101
+ break
2102
+ case Mode.BYTE:
2103
+ nodes.push([
2104
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
2105
+ ]);
2106
+ }
2107
+ }
2108
+
2109
+ return nodes
2110
+ }
2111
+
2112
+ /**
2113
+ * Builds a graph from a list of nodes.
2114
+ * All segments in each node group will be connected with all the segments of
2115
+ * the next group and so on.
2116
+ *
2117
+ * At each connection will be assigned a weight depending on the
2118
+ * segment's byte length.
2119
+ *
2120
+ * @param {Array} nodes Array of object with segments data
2121
+ * @param {Number} version QR Code version
2122
+ * @return {Object} Graph of all possible segments
2123
+ */
2124
+ function buildGraph (nodes, version) {
2125
+ const table = {};
2126
+ const graph = { start: {} };
2127
+ let prevNodeIds = ['start'];
2128
+
2129
+ for (let i = 0; i < nodes.length; i++) {
2130
+ const nodeGroup = nodes[i];
2131
+ const currentNodeIds = [];
2132
+
2133
+ for (let j = 0; j < nodeGroup.length; j++) {
2134
+ const node = nodeGroup[j];
2135
+ const key = '' + i + j;
2136
+
2137
+ currentNodeIds.push(key);
2138
+ table[key] = { node: node, lastCount: 0 };
2139
+ graph[key] = {};
2140
+
2141
+ for (let n = 0; n < prevNodeIds.length; n++) {
2142
+ const prevNodeId = prevNodeIds[n];
2143
+
2144
+ if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
2145
+ graph[prevNodeId][key] =
2146
+ getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -
2147
+ getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
2148
+
2149
+ table[prevNodeId].lastCount += node.length;
2150
+ } else {
2151
+ if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
2152
+
2153
+ graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +
2154
+ 4 + Mode.getCharCountIndicator(node.mode, version); // switch cost
2155
+ }
2156
+ }
2157
+ }
2158
+
2159
+ prevNodeIds = currentNodeIds;
2160
+ }
2161
+
2162
+ for (let n = 0; n < prevNodeIds.length; n++) {
2163
+ graph[prevNodeIds[n]].end = 0;
2164
+ }
2165
+
2166
+ return { map: graph, table: table }
2167
+ }
2168
+
2169
+ /**
2170
+ * Builds a segment from a specified data and mode.
2171
+ * If a mode is not specified, the more suitable will be used.
2172
+ *
2173
+ * @param {String} data Input data
2174
+ * @param {Mode | String} modesHint Data mode
2175
+ * @return {Segment} Segment
2176
+ */
2177
+ function buildSingleSegment (data, modesHint) {
2178
+ let mode;
2179
+ const bestMode = Mode.getBestModeForData(data);
2180
+
2181
+ mode = Mode.from(modesHint, bestMode);
2182
+
2183
+ // Make sure data can be encoded
2184
+ if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
2185
+ throw new Error('"' + data + '"' +
2186
+ ' cannot be encoded with mode ' + Mode.toString(mode) +
2187
+ '.\n Suggested mode is: ' + Mode.toString(bestMode))
2188
+ }
2189
+
2190
+ // Use Mode.BYTE if Kanji support is disabled
2191
+ if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
2192
+ mode = Mode.BYTE;
2193
+ }
2194
+
2195
+ switch (mode) {
2196
+ case Mode.NUMERIC:
2197
+ return new NumericData(data)
2198
+
2199
+ case Mode.ALPHANUMERIC:
2200
+ return new AlphanumericData(data)
2201
+
2202
+ case Mode.KANJI:
2203
+ return new KanjiData(data)
2204
+
2205
+ case Mode.BYTE:
2206
+ return new ByteData(data)
2207
+ }
2208
+ }
2209
+
2210
+ /**
2211
+ * Builds a list of segments from an array.
2212
+ * Array can contain Strings or Objects with segment's info.
2213
+ *
2214
+ * For each item which is a string, will be generated a segment with the given
2215
+ * string and the more appropriate encoding mode.
2216
+ *
2217
+ * For each item which is an object, will be generated a segment with the given
2218
+ * data and mode.
2219
+ * Objects must contain at least the property "data".
2220
+ * If property "mode" is not present, the more suitable mode will be used.
2221
+ *
2222
+ * @param {Array} array Array of objects with segments data
2223
+ * @return {Array} Array of Segments
2224
+ */
2225
+ exports.fromArray = function fromArray (array) {
2226
+ return array.reduce(function (acc, seg) {
2227
+ if (typeof seg === 'string') {
2228
+ acc.push(buildSingleSegment(seg, null));
2229
+ } else if (seg.data) {
2230
+ acc.push(buildSingleSegment(seg.data, seg.mode));
2231
+ }
2232
+
2233
+ return acc
2234
+ }, [])
2235
+ };
2236
+
2237
+ /**
2238
+ * Builds an optimized sequence of segments from a string,
2239
+ * which will produce the shortest possible bitstream.
2240
+ *
2241
+ * @param {String} data Input string
2242
+ * @param {Number} version QR Code version
2243
+ * @return {Array} Array of segments
2244
+ */
2245
+ exports.fromString = function fromString (data, version) {
2246
+ const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
2247
+
2248
+ const nodes = buildNodes(segs);
2249
+ const graph = buildGraph(nodes, version);
2250
+ const path = dijkstra.find_path(graph.map, 'start', 'end');
2251
+
2252
+ const optimizedSegs = [];
2253
+ for (let i = 1; i < path.length - 1; i++) {
2254
+ optimizedSegs.push(graph.table[path[i]].node);
2255
+ }
2256
+
2257
+ return exports.fromArray(mergeSegments(optimizedSegs))
2258
+ };
2259
+
2260
+ /**
2261
+ * Splits a string in various segments with the modes which
2262
+ * best represent their content.
2263
+ * The produced segments are far from being optimized.
2264
+ * The output of this function is only used to estimate a QR Code version
2265
+ * which may contain the data.
2266
+ *
2267
+ * @param {string} data Input string
2268
+ * @return {Array} Array of segments
2269
+ */
2270
+ exports.rawSplit = function rawSplit (data) {
2271
+ return exports.fromArray(
2272
+ getSegmentsFromString(data, Utils.isKanjiModeEnabled())
2273
+ )
2274
+ };
2275
+ } (segments));
2276
+ return segments;
2277
+ }
2278
+
2279
+ var hasRequiredQrcode;
2280
+
2281
+ function requireQrcode () {
2282
+ if (hasRequiredQrcode) return qrcode;
2283
+ hasRequiredQrcode = 1;
2284
+ const Utils = requireUtils$1();
2285
+ const ECLevel = requireErrorCorrectionLevel();
2286
+ const BitBuffer = requireBitBuffer();
2287
+ const BitMatrix = requireBitMatrix();
2288
+ const AlignmentPattern = requireAlignmentPattern();
2289
+ const FinderPattern = requireFinderPattern();
2290
+ const MaskPattern = requireMaskPattern();
2291
+ const ECCode = requireErrorCorrectionCode();
2292
+ const ReedSolomonEncoder = requireReedSolomonEncoder();
2293
+ const Version = requireVersion();
2294
+ const FormatInfo = requireFormatInfo();
2295
+ const Mode = requireMode();
2296
+ const Segments = requireSegments();
2297
+
2298
+ /**
2299
+ * QRCode for JavaScript
2300
+ *
2301
+ * modified by Ryan Day for nodejs support
2302
+ * Copyright (c) 2011 Ryan Day
2303
+ *
2304
+ * Licensed under the MIT license:
2305
+ * http://www.opensource.org/licenses/mit-license.php
2306
+ *
2307
+ //---------------------------------------------------------------------
2308
+ // QRCode for JavaScript
2309
+ //
2310
+ // Copyright (c) 2009 Kazuhiko Arase
2311
+ //
2312
+ // URL: http://www.d-project.com/
2313
+ //
2314
+ // Licensed under the MIT license:
2315
+ // http://www.opensource.org/licenses/mit-license.php
2316
+ //
2317
+ // The word "QR Code" is registered trademark of
2318
+ // DENSO WAVE INCORPORATED
2319
+ // http://www.denso-wave.com/qrcode/faqpatent-e.html
2320
+ //
2321
+ //---------------------------------------------------------------------
2322
+ */
2323
+
2324
+ /**
2325
+ * Add finder patterns bits to matrix
2326
+ *
2327
+ * @param {BitMatrix} matrix Modules matrix
2328
+ * @param {Number} version QR Code version
2329
+ */
2330
+ function setupFinderPattern (matrix, version) {
2331
+ const size = matrix.size;
2332
+ const pos = FinderPattern.getPositions(version);
2333
+
2334
+ for (let i = 0; i < pos.length; i++) {
2335
+ const row = pos[i][0];
2336
+ const col = pos[i][1];
2337
+
2338
+ for (let r = -1; r <= 7; r++) {
2339
+ if (row + r <= -1 || size <= row + r) continue
2340
+
2341
+ for (let c = -1; c <= 7; c++) {
2342
+ if (col + c <= -1 || size <= col + c) continue
2343
+
2344
+ if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||
2345
+ (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||
2346
+ (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {
2347
+ matrix.set(row + r, col + c, true, true);
2348
+ } else {
2349
+ matrix.set(row + r, col + c, false, true);
2350
+ }
2351
+ }
2352
+ }
2353
+ }
2354
+ }
2355
+
2356
+ /**
2357
+ * Add timing pattern bits to matrix
2358
+ *
2359
+ * Note: this function must be called before {@link setupAlignmentPattern}
2360
+ *
2361
+ * @param {BitMatrix} matrix Modules matrix
2362
+ */
2363
+ function setupTimingPattern (matrix) {
2364
+ const size = matrix.size;
2365
+
2366
+ for (let r = 8; r < size - 8; r++) {
2367
+ const value = r % 2 === 0;
2368
+ matrix.set(r, 6, value, true);
2369
+ matrix.set(6, r, value, true);
2370
+ }
2371
+ }
2372
+
2373
+ /**
2374
+ * Add alignment patterns bits to matrix
2375
+ *
2376
+ * Note: this function must be called after {@link setupTimingPattern}
2377
+ *
2378
+ * @param {BitMatrix} matrix Modules matrix
2379
+ * @param {Number} version QR Code version
2380
+ */
2381
+ function setupAlignmentPattern (matrix, version) {
2382
+ const pos = AlignmentPattern.getPositions(version);
2383
+
2384
+ for (let i = 0; i < pos.length; i++) {
2385
+ const row = pos[i][0];
2386
+ const col = pos[i][1];
2387
+
2388
+ for (let r = -2; r <= 2; r++) {
2389
+ for (let c = -2; c <= 2; c++) {
2390
+ if (r === -2 || r === 2 || c === -2 || c === 2 ||
2391
+ (r === 0 && c === 0)) {
2392
+ matrix.set(row + r, col + c, true, true);
2393
+ } else {
2394
+ matrix.set(row + r, col + c, false, true);
2395
+ }
2396
+ }
2397
+ }
2398
+ }
2399
+ }
2400
+
2401
+ /**
2402
+ * Add version info bits to matrix
2403
+ *
2404
+ * @param {BitMatrix} matrix Modules matrix
2405
+ * @param {Number} version QR Code version
2406
+ */
2407
+ function setupVersionInfo (matrix, version) {
2408
+ const size = matrix.size;
2409
+ const bits = Version.getEncodedBits(version);
2410
+ let row, col, mod;
2411
+
2412
+ for (let i = 0; i < 18; i++) {
2413
+ row = Math.floor(i / 3);
2414
+ col = i % 3 + size - 8 - 3;
2415
+ mod = ((bits >> i) & 1) === 1;
2416
+
2417
+ matrix.set(row, col, mod, true);
2418
+ matrix.set(col, row, mod, true);
2419
+ }
2420
+ }
2421
+
2422
+ /**
2423
+ * Add format info bits to matrix
2424
+ *
2425
+ * @param {BitMatrix} matrix Modules matrix
2426
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2427
+ * @param {Number} maskPattern Mask pattern reference value
2428
+ */
2429
+ function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {
2430
+ const size = matrix.size;
2431
+ const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
2432
+ let i, mod;
2433
+
2434
+ for (i = 0; i < 15; i++) {
2435
+ mod = ((bits >> i) & 1) === 1;
2436
+
2437
+ // vertical
2438
+ if (i < 6) {
2439
+ matrix.set(i, 8, mod, true);
2440
+ } else if (i < 8) {
2441
+ matrix.set(i + 1, 8, mod, true);
2442
+ } else {
2443
+ matrix.set(size - 15 + i, 8, mod, true);
2444
+ }
2445
+
2446
+ // horizontal
2447
+ if (i < 8) {
2448
+ matrix.set(8, size - i - 1, mod, true);
2449
+ } else if (i < 9) {
2450
+ matrix.set(8, 15 - i - 1 + 1, mod, true);
2451
+ } else {
2452
+ matrix.set(8, 15 - i - 1, mod, true);
2453
+ }
2454
+ }
2455
+
2456
+ // fixed module
2457
+ matrix.set(size - 8, 8, 1, true);
2458
+ }
2459
+
2460
+ /**
2461
+ * Add encoded data bits to matrix
2462
+ *
2463
+ * @param {BitMatrix} matrix Modules matrix
2464
+ * @param {Uint8Array} data Data codewords
2465
+ */
2466
+ function setupData (matrix, data) {
2467
+ const size = matrix.size;
2468
+ let inc = -1;
2469
+ let row = size - 1;
2470
+ let bitIndex = 7;
2471
+ let byteIndex = 0;
2472
+
2473
+ for (let col = size - 1; col > 0; col -= 2) {
2474
+ if (col === 6) col--;
2475
+
2476
+ while (true) {
2477
+ for (let c = 0; c < 2; c++) {
2478
+ if (!matrix.isReserved(row, col - c)) {
2479
+ let dark = false;
2480
+
2481
+ if (byteIndex < data.length) {
2482
+ dark = (((data[byteIndex] >>> bitIndex) & 1) === 1);
2483
+ }
2484
+
2485
+ matrix.set(row, col - c, dark);
2486
+ bitIndex--;
2487
+
2488
+ if (bitIndex === -1) {
2489
+ byteIndex++;
2490
+ bitIndex = 7;
2491
+ }
2492
+ }
2493
+ }
2494
+
2495
+ row += inc;
2496
+
2497
+ if (row < 0 || size <= row) {
2498
+ row -= inc;
2499
+ inc = -inc;
2500
+ break
2501
+ }
2502
+ }
2503
+ }
2504
+ }
2505
+
2506
+ /**
2507
+ * Create encoded codewords from data input
2508
+ *
2509
+ * @param {Number} version QR Code version
2510
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2511
+ * @param {ByteData} data Data input
2512
+ * @return {Uint8Array} Buffer containing encoded codewords
2513
+ */
2514
+ function createData (version, errorCorrectionLevel, segments) {
2515
+ // Prepare data buffer
2516
+ const buffer = new BitBuffer();
2517
+
2518
+ segments.forEach(function (data) {
2519
+ // prefix data with mode indicator (4 bits)
2520
+ buffer.put(data.mode.bit, 4);
2521
+
2522
+ // Prefix data with character count indicator.
2523
+ // The character count indicator is a string of bits that represents the
2524
+ // number of characters that are being encoded.
2525
+ // The character count indicator must be placed after the mode indicator
2526
+ // and must be a certain number of bits long, depending on the QR version
2527
+ // and data mode
2528
+ // @see {@link Mode.getCharCountIndicator}.
2529
+ buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
2530
+
2531
+ // add binary data sequence to buffer
2532
+ data.write(buffer);
2533
+ });
2534
+
2535
+ // Calculate required number of bits
2536
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2537
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2538
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
2539
+
2540
+ // Add a terminator.
2541
+ // If the bit string is shorter than the total number of required bits,
2542
+ // a terminator of up to four 0s must be added to the right side of the string.
2543
+ // If the bit string is more than four bits shorter than the required number of bits,
2544
+ // add four 0s to the end.
2545
+ if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
2546
+ buffer.put(0, 4);
2547
+ }
2548
+
2549
+ // If the bit string is fewer than four bits shorter, add only the number of 0s that
2550
+ // are needed to reach the required number of bits.
2551
+
2552
+ // After adding the terminator, if the number of bits in the string is not a multiple of 8,
2553
+ // pad the string on the right with 0s to make the string's length a multiple of 8.
2554
+ while (buffer.getLengthInBits() % 8 !== 0) {
2555
+ buffer.putBit(0);
2556
+ }
2557
+
2558
+ // Add pad bytes if the string is still shorter than the total number of required bits.
2559
+ // Extend the buffer to fill the data capacity of the symbol corresponding to
2560
+ // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
2561
+ // and 00010001 (0x11) alternately.
2562
+ const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
2563
+ for (let i = 0; i < remainingByte; i++) {
2564
+ buffer.put(i % 2 ? 0x11 : 0xEC, 8);
2565
+ }
2566
+
2567
+ return createCodewords(buffer, version, errorCorrectionLevel)
2568
+ }
2569
+
2570
+ /**
2571
+ * Encode input data with Reed-Solomon and return codewords with
2572
+ * relative error correction bits
2573
+ *
2574
+ * @param {BitBuffer} bitBuffer Data to encode
2575
+ * @param {Number} version QR Code version
2576
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2577
+ * @return {Uint8Array} Buffer containing encoded codewords
2578
+ */
2579
+ function createCodewords (bitBuffer, version, errorCorrectionLevel) {
2580
+ // Total codewords for this QR code version (Data + Error correction)
2581
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2582
+
2583
+ // Total number of error correction codewords
2584
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2585
+
2586
+ // Total number of data codewords
2587
+ const dataTotalCodewords = totalCodewords - ecTotalCodewords;
2588
+
2589
+ // Total number of blocks
2590
+ const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
2591
+
2592
+ // Calculate how many blocks each group should contain
2593
+ const blocksInGroup2 = totalCodewords % ecTotalBlocks;
2594
+ const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
2595
+
2596
+ const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
2597
+
2598
+ const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
2599
+ const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
2600
+
2601
+ // Number of EC codewords is the same for both groups
2602
+ const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
2603
+
2604
+ // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
2605
+ const rs = new ReedSolomonEncoder(ecCount);
2606
+
2607
+ let offset = 0;
2608
+ const dcData = new Array(ecTotalBlocks);
2609
+ const ecData = new Array(ecTotalBlocks);
2610
+ let maxDataSize = 0;
2611
+ const buffer = new Uint8Array(bitBuffer.buffer);
2612
+
2613
+ // Divide the buffer into the required number of blocks
2614
+ for (let b = 0; b < ecTotalBlocks; b++) {
2615
+ const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
2616
+
2617
+ // extract a block of data from buffer
2618
+ dcData[b] = buffer.slice(offset, offset + dataSize);
2619
+
2620
+ // Calculate EC codewords for this data block
2621
+ ecData[b] = rs.encode(dcData[b]);
2622
+
2623
+ offset += dataSize;
2624
+ maxDataSize = Math.max(maxDataSize, dataSize);
2625
+ }
2626
+
2627
+ // Create final data
2628
+ // Interleave the data and error correction codewords from each block
2629
+ const data = new Uint8Array(totalCodewords);
2630
+ let index = 0;
2631
+ let i, r;
2632
+
2633
+ // Add data codewords
2634
+ for (i = 0; i < maxDataSize; i++) {
2635
+ for (r = 0; r < ecTotalBlocks; r++) {
2636
+ if (i < dcData[r].length) {
2637
+ data[index++] = dcData[r][i];
2638
+ }
2639
+ }
2640
+ }
2641
+
2642
+ // Apped EC codewords
2643
+ for (i = 0; i < ecCount; i++) {
2644
+ for (r = 0; r < ecTotalBlocks; r++) {
2645
+ data[index++] = ecData[r][i];
2646
+ }
2647
+ }
2648
+
2649
+ return data
2650
+ }
2651
+
2652
+ /**
2653
+ * Build QR Code symbol
2654
+ *
2655
+ * @param {String} data Input string
2656
+ * @param {Number} version QR Code version
2657
+ * @param {ErrorCorretionLevel} errorCorrectionLevel Error level
2658
+ * @param {MaskPattern} maskPattern Mask pattern
2659
+ * @return {Object} Object containing symbol data
2660
+ */
2661
+ function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
2662
+ let segments;
2663
+
2664
+ if (Array.isArray(data)) {
2665
+ segments = Segments.fromArray(data);
2666
+ } else if (typeof data === 'string') {
2667
+ let estimatedVersion = version;
2668
+
2669
+ if (!estimatedVersion) {
2670
+ const rawSegments = Segments.rawSplit(data);
2671
+
2672
+ // Estimate best version that can contain raw splitted segments
2673
+ estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
2674
+ }
2675
+
2676
+ // Build optimized segments
2677
+ // If estimated version is undefined, try with the highest version
2678
+ segments = Segments.fromString(data, estimatedVersion || 40);
2679
+ } else {
2680
+ throw new Error('Invalid data')
2681
+ }
2682
+
2683
+ // Get the min version that can contain data
2684
+ const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
2685
+
2686
+ // If no version is found, data cannot be stored
2687
+ if (!bestVersion) {
2688
+ throw new Error('The amount of data is too big to be stored in a QR Code')
2689
+ }
2690
+
2691
+ // If not specified, use min version as default
2692
+ if (!version) {
2693
+ version = bestVersion;
2694
+
2695
+ // Check if the specified version can contain the data
2696
+ } else if (version < bestVersion) {
2697
+ throw new Error('\n' +
2698
+ 'The chosen QR Code version cannot contain this amount of data.\n' +
2699
+ 'Minimum version required to store current data is: ' + bestVersion + '.\n'
2700
+ )
2701
+ }
2702
+
2703
+ const dataBits = createData(version, errorCorrectionLevel, segments);
2704
+
2705
+ // Allocate matrix buffer
2706
+ const moduleCount = Utils.getSymbolSize(version);
2707
+ const modules = new BitMatrix(moduleCount);
2708
+
2709
+ // Add function modules
2710
+ setupFinderPattern(modules, version);
2711
+ setupTimingPattern(modules);
2712
+ setupAlignmentPattern(modules, version);
2713
+
2714
+ // Add temporary dummy bits for format info just to set them as reserved.
2715
+ // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
2716
+ // since the masking operation must be performed only on the encoding region.
2717
+ // These blocks will be replaced with correct values later in code.
2718
+ setupFormatInfo(modules, errorCorrectionLevel, 0);
2719
+
2720
+ if (version >= 7) {
2721
+ setupVersionInfo(modules, version);
2722
+ }
2723
+
2724
+ // Add data codewords
2725
+ setupData(modules, dataBits);
2726
+
2727
+ if (isNaN(maskPattern)) {
2728
+ // Find best mask pattern
2729
+ maskPattern = MaskPattern.getBestMask(modules,
2730
+ setupFormatInfo.bind(null, modules, errorCorrectionLevel));
2731
+ }
2732
+
2733
+ // Apply mask pattern
2734
+ MaskPattern.applyMask(maskPattern, modules);
2735
+
2736
+ // Replace format info bits with correct values
2737
+ setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
2738
+
2739
+ return {
2740
+ modules: modules,
2741
+ version: version,
2742
+ errorCorrectionLevel: errorCorrectionLevel,
2743
+ maskPattern: maskPattern,
2744
+ segments: segments
2745
+ }
2746
+ }
2747
+
2748
+ /**
2749
+ * QR Code
2750
+ *
2751
+ * @param {String | Array} data Input data
2752
+ * @param {Object} options Optional configurations
2753
+ * @param {Number} options.version QR Code version
2754
+ * @param {String} options.errorCorrectionLevel Error correction level
2755
+ * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
2756
+ */
2757
+ qrcode.create = function create (data, options) {
2758
+ if (typeof data === 'undefined' || data === '') {
2759
+ throw new Error('No input text')
2760
+ }
2761
+
2762
+ let errorCorrectionLevel = ECLevel.M;
2763
+ let version;
2764
+ let mask;
2765
+
2766
+ if (typeof options !== 'undefined') {
2767
+ // Use higher error correction level as default
2768
+ errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
2769
+ version = Version.from(options.version);
2770
+ mask = MaskPattern.from(options.maskPattern);
2771
+
2772
+ if (options.toSJISFunc) {
2773
+ Utils.setToSJISFunction(options.toSJISFunc);
2774
+ }
2775
+ }
2776
+
2777
+ return createSymbol(data, version, errorCorrectionLevel, mask)
2778
+ };
2779
+ return qrcode;
2780
+ }
2781
+
2782
+ var canvas = {};
2783
+
2784
+ var utils = {};
2785
+
2786
+ var hasRequiredUtils;
2787
+
2788
+ function requireUtils () {
2789
+ if (hasRequiredUtils) return utils;
2790
+ hasRequiredUtils = 1;
2791
+ (function (exports) {
2792
+ function hex2rgba (hex) {
2793
+ if (typeof hex === 'number') {
2794
+ hex = hex.toString();
2795
+ }
2796
+
2797
+ if (typeof hex !== 'string') {
2798
+ throw new Error('Color should be defined as hex string')
2799
+ }
2800
+
2801
+ let hexCode = hex.slice().replace('#', '').split('');
2802
+ if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
2803
+ throw new Error('Invalid hex color: ' + hex)
2804
+ }
2805
+
2806
+ // Convert from short to long form (fff -> ffffff)
2807
+ if (hexCode.length === 3 || hexCode.length === 4) {
2808
+ hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
2809
+ return [c, c]
2810
+ }));
2811
+ }
2812
+
2813
+ // Add default alpha value
2814
+ if (hexCode.length === 6) hexCode.push('F', 'F');
2815
+
2816
+ const hexValue = parseInt(hexCode.join(''), 16);
2817
+
2818
+ return {
2819
+ r: (hexValue >> 24) & 255,
2820
+ g: (hexValue >> 16) & 255,
2821
+ b: (hexValue >> 8) & 255,
2822
+ a: hexValue & 255,
2823
+ hex: '#' + hexCode.slice(0, 6).join('')
2824
+ }
2825
+ }
2826
+
2827
+ exports.getOptions = function getOptions (options) {
2828
+ if (!options) options = {};
2829
+ if (!options.color) options.color = {};
2830
+
2831
+ const margin = typeof options.margin === 'undefined' ||
2832
+ options.margin === null ||
2833
+ options.margin < 0
2834
+ ? 4
2835
+ : options.margin;
2836
+
2837
+ const width = options.width && options.width >= 21 ? options.width : undefined;
2838
+ const scale = options.scale || 4;
2839
+
2840
+ return {
2841
+ width: width,
2842
+ scale: width ? 4 : scale,
2843
+ margin: margin,
2844
+ color: {
2845
+ dark: hex2rgba(options.color.dark || '#000000ff'),
2846
+ light: hex2rgba(options.color.light || '#ffffffff')
2847
+ },
2848
+ type: options.type,
2849
+ rendererOpts: options.rendererOpts || {}
2850
+ }
2851
+ };
2852
+
2853
+ exports.getScale = function getScale (qrSize, opts) {
2854
+ return opts.width && opts.width >= qrSize + opts.margin * 2
2855
+ ? opts.width / (qrSize + opts.margin * 2)
2856
+ : opts.scale
2857
+ };
2858
+
2859
+ exports.getImageWidth = function getImageWidth (qrSize, opts) {
2860
+ const scale = exports.getScale(qrSize, opts);
2861
+ return Math.floor((qrSize + opts.margin * 2) * scale)
2862
+ };
2863
+
2864
+ exports.qrToImageData = function qrToImageData (imgData, qr, opts) {
2865
+ const size = qr.modules.size;
2866
+ const data = qr.modules.data;
2867
+ const scale = exports.getScale(size, opts);
2868
+ const symbolSize = Math.floor((size + opts.margin * 2) * scale);
2869
+ const scaledMargin = opts.margin * scale;
2870
+ const palette = [opts.color.light, opts.color.dark];
2871
+
2872
+ for (let i = 0; i < symbolSize; i++) {
2873
+ for (let j = 0; j < symbolSize; j++) {
2874
+ let posDst = (i * symbolSize + j) * 4;
2875
+ let pxColor = opts.color.light;
2876
+
2877
+ if (i >= scaledMargin && j >= scaledMargin &&
2878
+ i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
2879
+ const iSrc = Math.floor((i - scaledMargin) / scale);
2880
+ const jSrc = Math.floor((j - scaledMargin) / scale);
2881
+ pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
2882
+ }
2883
+
2884
+ imgData[posDst++] = pxColor.r;
2885
+ imgData[posDst++] = pxColor.g;
2886
+ imgData[posDst++] = pxColor.b;
2887
+ imgData[posDst] = pxColor.a;
2888
+ }
2889
+ }
2890
+ };
2891
+ } (utils));
2892
+ return utils;
2893
+ }
2894
+
2895
+ var hasRequiredCanvas;
2896
+
2897
+ function requireCanvas () {
2898
+ if (hasRequiredCanvas) return canvas;
2899
+ hasRequiredCanvas = 1;
2900
+ (function (exports) {
2901
+ const Utils = requireUtils();
2902
+
2903
+ function clearCanvas (ctx, canvas, size) {
2904
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
2905
+
2906
+ if (!canvas.style) canvas.style = {};
2907
+ canvas.height = size;
2908
+ canvas.width = size;
2909
+ canvas.style.height = size + 'px';
2910
+ canvas.style.width = size + 'px';
2911
+ }
2912
+
2913
+ function getCanvasElement () {
2914
+ try {
2915
+ return document.createElement('canvas')
2916
+ } catch (e) {
2917
+ throw new Error('You need to specify a canvas element')
2918
+ }
2919
+ }
2920
+
2921
+ exports.render = function render (qrData, canvas, options) {
2922
+ let opts = options;
2923
+ let canvasEl = canvas;
2924
+
2925
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2926
+ opts = canvas;
2927
+ canvas = undefined;
2928
+ }
2929
+
2930
+ if (!canvas) {
2931
+ canvasEl = getCanvasElement();
2932
+ }
2933
+
2934
+ opts = Utils.getOptions(opts);
2935
+ const size = Utils.getImageWidth(qrData.modules.size, opts);
2936
+
2937
+ const ctx = canvasEl.getContext('2d');
2938
+ const image = ctx.createImageData(size, size);
2939
+ Utils.qrToImageData(image.data, qrData, opts);
2940
+
2941
+ clearCanvas(ctx, canvasEl, size);
2942
+ ctx.putImageData(image, 0, 0);
2943
+
2944
+ return canvasEl
2945
+ };
2946
+
2947
+ exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
2948
+ let opts = options;
2949
+
2950
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2951
+ opts = canvas;
2952
+ canvas = undefined;
2953
+ }
2954
+
2955
+ if (!opts) opts = {};
2956
+
2957
+ const canvasEl = exports.render(qrData, canvas, opts);
2958
+
2959
+ const type = opts.type || 'image/png';
2960
+ const rendererOpts = opts.rendererOpts || {};
2961
+
2962
+ return canvasEl.toDataURL(type, rendererOpts.quality)
2963
+ };
2964
+ } (canvas));
2965
+ return canvas;
2966
+ }
2967
+
2968
+ var svgTag = {};
2969
+
2970
+ var hasRequiredSvgTag;
2971
+
2972
+ function requireSvgTag () {
2973
+ if (hasRequiredSvgTag) return svgTag;
2974
+ hasRequiredSvgTag = 1;
2975
+ const Utils = requireUtils();
2976
+
2977
+ function getColorAttrib (color, attrib) {
2978
+ const alpha = color.a / 255;
2979
+ const str = attrib + '="' + color.hex + '"';
2980
+
2981
+ return alpha < 1
2982
+ ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"'
2983
+ : str
2984
+ }
2985
+
2986
+ function svgCmd (cmd, x, y) {
2987
+ let str = cmd + x;
2988
+ if (typeof y !== 'undefined') str += ' ' + y;
2989
+
2990
+ return str
2991
+ }
2992
+
2993
+ function qrToPath (data, size, margin) {
2994
+ let path = '';
2995
+ let moveBy = 0;
2996
+ let newRow = false;
2997
+ let lineLength = 0;
2998
+
2999
+ for (let i = 0; i < data.length; i++) {
3000
+ const col = Math.floor(i % size);
3001
+ const row = Math.floor(i / size);
3002
+
3003
+ if (!col && !newRow) newRow = true;
3004
+
3005
+ if (data[i]) {
3006
+ lineLength++;
3007
+
3008
+ if (!(i > 0 && col > 0 && data[i - 1])) {
3009
+ path += newRow
3010
+ ? svgCmd('M', col + margin, 0.5 + row + margin)
3011
+ : svgCmd('m', moveBy, 0);
3012
+
3013
+ moveBy = 0;
3014
+ newRow = false;
3015
+ }
3016
+
3017
+ if (!(col + 1 < size && data[i + 1])) {
3018
+ path += svgCmd('h', lineLength);
3019
+ lineLength = 0;
3020
+ }
3021
+ } else {
3022
+ moveBy++;
3023
+ }
3024
+ }
3025
+
3026
+ return path
3027
+ }
3028
+
3029
+ svgTag.render = function render (qrData, options, cb) {
3030
+ const opts = Utils.getOptions(options);
3031
+ const size = qrData.modules.size;
3032
+ const data = qrData.modules.data;
3033
+ const qrcodesize = size + opts.margin * 2;
3034
+
3035
+ const bg = !opts.color.light.a
3036
+ ? ''
3037
+ : '<path ' + getColorAttrib(opts.color.light, 'fill') +
3038
+ ' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>';
3039
+
3040
+ const path =
3041
+ '<path ' + getColorAttrib(opts.color.dark, 'stroke') +
3042
+ ' d="' + qrToPath(data, size, opts.margin) + '"/>';
3043
+
3044
+ const viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"';
3045
+
3046
+ const width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" ';
3047
+
3048
+ const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n';
3049
+
3050
+ if (typeof cb === 'function') {
3051
+ cb(null, svgTag);
3052
+ }
3053
+
3054
+ return svgTag
3055
+ };
3056
+ return svgTag;
3057
+ }
3058
+
3059
+ var hasRequiredBrowser;
3060
+
3061
+ function requireBrowser () {
3062
+ if (hasRequiredBrowser) return browser;
3063
+ hasRequiredBrowser = 1;
3064
+ const canPromise = requireCanPromise();
3065
+
3066
+ const QRCode = requireQrcode();
3067
+ const CanvasRenderer = requireCanvas();
3068
+ const SvgRenderer = requireSvgTag();
3069
+
3070
+ function renderCanvas (renderFunc, canvas, text, opts, cb) {
3071
+ const args = [].slice.call(arguments, 1);
3072
+ const argsNum = args.length;
3073
+ const isLastArgCb = typeof args[argsNum - 1] === 'function';
3074
+
3075
+ if (!isLastArgCb && !canPromise()) {
3076
+ throw new Error('Callback required as last argument')
3077
+ }
3078
+
3079
+ if (isLastArgCb) {
3080
+ if (argsNum < 2) {
3081
+ throw new Error('Too few arguments provided')
3082
+ }
3083
+
3084
+ if (argsNum === 2) {
3085
+ cb = text;
3086
+ text = canvas;
3087
+ canvas = opts = undefined;
3088
+ } else if (argsNum === 3) {
3089
+ if (canvas.getContext && typeof cb === 'undefined') {
3090
+ cb = opts;
3091
+ opts = undefined;
3092
+ } else {
3093
+ cb = opts;
3094
+ opts = text;
3095
+ text = canvas;
3096
+ canvas = undefined;
3097
+ }
3098
+ }
3099
+ } else {
3100
+ if (argsNum < 1) {
3101
+ throw new Error('Too few arguments provided')
3102
+ }
3103
+
3104
+ if (argsNum === 1) {
3105
+ text = canvas;
3106
+ canvas = opts = undefined;
3107
+ } else if (argsNum === 2 && !canvas.getContext) {
3108
+ opts = text;
3109
+ text = canvas;
3110
+ canvas = undefined;
3111
+ }
3112
+
3113
+ return new Promise(function (resolve, reject) {
3114
+ try {
3115
+ const data = QRCode.create(text, opts);
3116
+ resolve(renderFunc(data, canvas, opts));
3117
+ } catch (e) {
3118
+ reject(e);
3119
+ }
3120
+ })
3121
+ }
3122
+
3123
+ try {
3124
+ const data = QRCode.create(text, opts);
3125
+ cb(null, renderFunc(data, canvas, opts));
3126
+ } catch (e) {
3127
+ cb(e);
3128
+ }
3129
+ }
3130
+
3131
+ browser.create = QRCode.create;
3132
+ browser.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
3133
+ browser.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
3134
+
3135
+ // only svg for now.
3136
+ browser.toString = renderCanvas.bind(null, function (data, _, opts) {
3137
+ return SvgRenderer.render(data, opts)
3138
+ });
3139
+ return browser;
3140
+ }
3141
+
3142
+ var browserExports = requireBrowser();
3143
+ var QRCodeUtil = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
3144
+
3145
+ const CONNECTING_ERROR_MARGIN = 0.1;
3146
+ const CIRCLE_SIZE_MODIFIER = 2.5;
3147
+ const QRCODE_MATRIX_MARGIN = 7;
3148
+ function isAdjecentDots(cy, otherCy, cellSize) {
3149
+ if (cy === otherCy) {
3150
+ return false;
3151
+ }
3152
+ const diff = cy - otherCy < 0 ? otherCy - cy : cy - otherCy;
3153
+ return diff <= cellSize + CONNECTING_ERROR_MARGIN;
3154
+ }
3155
+ function getMatrix(value, errorCorrectionLevel) {
3156
+ const arr = Array.prototype.slice.call(QRCodeUtil.create(value, { errorCorrectionLevel }).modules.data, 0);
3157
+ const sqrt = Math.sqrt(arr.length);
3158
+ return arr.reduce((rows, key, index) => (index % sqrt === 0 ? rows.push([key]) : rows[rows.length - 1].push(key)) && rows, []);
3159
+ }
3160
+ const QrCodeUtil = {
3161
+ generate({ uri, size, logoSize, padding = 8, dotColor = 'var(--apkt-colors-black)' }) {
3162
+ const strokeWidth = 10;
3163
+ const dots = [];
3164
+ const matrix = getMatrix(uri, 'Q');
3165
+ const cellSize = (size - 2 * padding) / matrix.length;
3166
+ const qrList = [
3167
+ { x: 0, y: 0 },
3168
+ { x: 1, y: 0 },
3169
+ { x: 0, y: 1 }
3170
+ ];
3171
+ qrList.forEach(({ x, y }) => {
3172
+ const x1 = (matrix.length - QRCODE_MATRIX_MARGIN) * cellSize * x + padding;
3173
+ const y1 = (matrix.length - QRCODE_MATRIX_MARGIN) * cellSize * y + padding;
3174
+ const borderRadius = 0.45;
3175
+ for (let i = 0; i < qrList.length; i += 1) {
3176
+ const dotSize = cellSize * (QRCODE_MATRIX_MARGIN - i * 2);
3177
+ dots.push(w `
3178
+ <rect
3179
+ fill=${i === 2 ? 'var(--apkt-colors-black)' : 'var(--apkt-colors-white)'}
3180
+ width=${i === 0 ? dotSize - strokeWidth : dotSize}
3181
+ rx= ${i === 0 ? (dotSize - strokeWidth) * borderRadius : dotSize * borderRadius}
3182
+ ry= ${i === 0 ? (dotSize - strokeWidth) * borderRadius : dotSize * borderRadius}
3183
+ stroke=${dotColor}
3184
+ stroke-width=${i === 0 ? strokeWidth : 0}
3185
+ height=${i === 0 ? dotSize - strokeWidth : dotSize}
3186
+ x= ${i === 0 ? y1 + cellSize * i + strokeWidth / 2 : y1 + cellSize * i}
3187
+ y= ${i === 0 ? x1 + cellSize * i + strokeWidth / 2 : x1 + cellSize * i}
3188
+ />
3189
+ `);
3190
+ }
3191
+ });
3192
+ const clearArenaSize = Math.floor((logoSize + 25) / cellSize);
3193
+ const matrixMiddleStart = matrix.length / 2 - clearArenaSize / 2;
3194
+ const matrixMiddleEnd = matrix.length / 2 + clearArenaSize / 2 - 1;
3195
+ const circles = [];
3196
+ matrix.forEach((row, i) => {
3197
+ row.forEach((_, j) => {
3198
+ if (matrix[i][j]) {
3199
+ if (!((i < QRCODE_MATRIX_MARGIN && j < QRCODE_MATRIX_MARGIN) ||
3200
+ (i > matrix.length - (QRCODE_MATRIX_MARGIN + 1) && j < QRCODE_MATRIX_MARGIN) ||
3201
+ (i < QRCODE_MATRIX_MARGIN && j > matrix.length - (QRCODE_MATRIX_MARGIN + 1)))) {
3202
+ if (!(i > matrixMiddleStart &&
3203
+ i < matrixMiddleEnd &&
3204
+ j > matrixMiddleStart &&
3205
+ j < matrixMiddleEnd)) {
3206
+ const cx = i * cellSize + cellSize / 2 + padding;
3207
+ const cy = j * cellSize + cellSize / 2 + padding;
3208
+ circles.push([cx, cy]);
3209
+ }
3210
+ }
3211
+ }
3212
+ });
3213
+ });
3214
+ const circlesToConnect = {};
3215
+ circles.forEach(([cx, cy]) => {
3216
+ if (circlesToConnect[cx]) {
3217
+ circlesToConnect[cx]?.push(cy);
3218
+ }
3219
+ else {
3220
+ circlesToConnect[cx] = [cy];
3221
+ }
3222
+ });
3223
+ Object.entries(circlesToConnect)
3224
+ .map(([cx, cys]) => {
3225
+ const newCys = cys.filter(cy => cys.every(otherCy => !isAdjecentDots(cy, otherCy, cellSize)));
3226
+ return [Number(cx), newCys];
3227
+ })
3228
+ .forEach(([cx, cys]) => {
3229
+ cys.forEach(cy => {
3230
+ dots.push(w `<circle cx=${cx} cy=${cy} fill=${dotColor} r=${cellSize / CIRCLE_SIZE_MODIFIER} />`);
3231
+ });
3232
+ });
3233
+ Object.entries(circlesToConnect)
3234
+ .filter(([_, cys]) => cys.length > 1)
3235
+ .map(([cx, cys]) => {
3236
+ const newCys = cys.filter(cy => cys.some(otherCy => isAdjecentDots(cy, otherCy, cellSize)));
3237
+ return [Number(cx), newCys];
3238
+ })
3239
+ .map(([cx, cys]) => {
3240
+ cys.sort((a, b) => (a < b ? -1 : 1));
3241
+ const groups = [];
3242
+ for (const cy of cys) {
3243
+ const group = groups.find(item => item.some(otherCy => isAdjecentDots(cy, otherCy, cellSize)));
3244
+ if (group) {
3245
+ group.push(cy);
3246
+ }
3247
+ else {
3248
+ groups.push([cy]);
3249
+ }
3250
+ }
3251
+ return [cx, groups.map(item => [item[0], item[item.length - 1]])];
3252
+ })
3253
+ .forEach(([cx, groups]) => {
3254
+ groups.forEach(([y1, y2]) => {
3255
+ dots.push(w `
3256
+ <line
3257
+ x1=${cx}
3258
+ x2=${cx}
3259
+ y1=${y1}
3260
+ y2=${y2}
3261
+ stroke=${dotColor}
3262
+ stroke-width=${cellSize / (CIRCLE_SIZE_MODIFIER / 2)}
3263
+ stroke-linecap="round"
3264
+ />
3265
+ `);
3266
+ });
3267
+ });
3268
+ return dots;
3269
+ }
3270
+ };
3271
+
3272
+ var styles = css `
3273
+ :host {
3274
+ position: relative;
3275
+ user-select: none;
3276
+ display: block;
3277
+ overflow: hidden;
3278
+ aspect-ratio: 1 / 1;
3279
+ width: 100%;
3280
+ height: 100%;
3281
+ background-color: ${({ colors }) => colors.white};
3282
+ border: 1px solid ${({ tokens }) => tokens.theme.borderPrimary};
3283
+ }
3284
+
3285
+ :host {
3286
+ border-radius: ${({ borderRadius }) => borderRadius[4]};
3287
+ display: flex;
3288
+ align-items: center;
3289
+ justify-content: center;
3290
+ }
3291
+
3292
+ :host([data-clear='true']) > wui-icon {
3293
+ display: none;
3294
+ }
3295
+
3296
+ svg:first-child,
3297
+ wui-image,
3298
+ wui-icon {
3299
+ position: absolute;
3300
+ top: 50%;
3301
+ left: 50%;
3302
+ transform: translateY(-50%) translateX(-50%);
3303
+ background-color: ${({ tokens }) => tokens.theme.backgroundPrimary};
3304
+ box-shadow: inset 0 0 0 4px ${({ tokens }) => tokens.theme.backgroundPrimary};
3305
+ border-radius: ${({ borderRadius }) => borderRadius[6]};
3306
+ }
3307
+
3308
+ wui-image {
3309
+ width: 25%;
3310
+ height: 25%;
3311
+ border-radius: ${({ borderRadius }) => borderRadius[2]};
3312
+ }
3313
+
3314
+ wui-icon {
3315
+ width: 100%;
3316
+ height: 100%;
3317
+ color: #3396ff !important;
3318
+ transform: translateY(-50%) translateX(-50%) scale(0.25);
3319
+ }
3320
+
3321
+ wui-icon > svg {
3322
+ width: inherit;
3323
+ height: inherit;
3324
+ }
3325
+ `;
3326
+
3327
+ var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
3328
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3329
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3330
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3331
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
3332
+ };
3333
+ let WuiQrCode = class WuiQrCode extends i {
3334
+ constructor() {
3335
+ super(...arguments);
3336
+ this.uri = '';
3337
+ this.size = 500;
3338
+ this.theme = 'dark';
3339
+ this.imageSrc = undefined;
3340
+ this.alt = undefined;
3341
+ this.arenaClear = undefined;
3342
+ this.farcaster = undefined;
3343
+ }
3344
+ render() {
3345
+ this.dataset['theme'] = this.theme;
3346
+ this.dataset['clear'] = String(this.arenaClear);
3347
+ return b `<wui-flex
3348
+ alignItems="center"
3349
+ justifyContent="center"
3350
+ class="wui-qr-code"
3351
+ direction="column"
3352
+ gap="4"
3353
+ width="100%"
3354
+ style="height: 100%"
3355
+ >
3356
+ ${this.templateVisual()} ${this.templateSvg()}
3357
+ </wui-flex>`;
3358
+ }
3359
+ templateSvg() {
3360
+ return w `
3361
+ <svg viewBox="0 0 ${this.size} ${this.size}" width="100%" height="100%">
3362
+ ${QrCodeUtil.generate({
3363
+ uri: this.uri,
3364
+ size: this.size,
3365
+ logoSize: this.arenaClear ? 0 : this.size / 4
3366
+ })}
3367
+ </svg>
3368
+ `;
3369
+ }
3370
+ templateVisual() {
3371
+ if (this.imageSrc) {
3372
+ return b `<wui-image src=${this.imageSrc} alt=${this.alt ?? 'logo'}></wui-image>`;
3373
+ }
3374
+ if (this.farcaster) {
3375
+ return b `<wui-icon
3376
+ class="farcaster"
3377
+ size="inherit"
3378
+ color="inherit"
3379
+ name="farcaster"
3380
+ ></wui-icon>`;
3381
+ }
3382
+ return b `<wui-icon size="inherit" color="inherit" name="walletConnect"></wui-icon>`;
3383
+ }
3384
+ };
3385
+ WuiQrCode.styles = [resetStyles, styles];
3386
+ __decorate([
3387
+ n()
3388
+ ], WuiQrCode.prototype, "uri", void 0);
3389
+ __decorate([
3390
+ n({ type: Number })
3391
+ ], WuiQrCode.prototype, "size", void 0);
3392
+ __decorate([
3393
+ n()
3394
+ ], WuiQrCode.prototype, "theme", void 0);
3395
+ __decorate([
3396
+ n()
3397
+ ], WuiQrCode.prototype, "imageSrc", void 0);
3398
+ __decorate([
3399
+ n()
3400
+ ], WuiQrCode.prototype, "alt", void 0);
3401
+ __decorate([
3402
+ n({ type: Boolean })
3403
+ ], WuiQrCode.prototype, "arenaClear", void 0);
3404
+ __decorate([
3405
+ n({ type: Boolean })
3406
+ ], WuiQrCode.prototype, "farcaster", void 0);
3407
+ WuiQrCode = __decorate([
3408
+ customElement('wui-qr-code')
3409
+ ], WuiQrCode);
3410
+ //# sourceMappingURL=wui-qr-code-DekJTDGf.js.map
3411
+
3412
+ //# sourceMappingURL=wui-qr-code-DekJTDGf.js.map