@tdesign/uniapp 0.0.1-alpha.1 → 0.7.0

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 (700) hide show
  1. package/CHANGELOG.md +204 -0
  2. package/LICENSE +9 -0
  3. package/README.md +144 -0
  4. package/dist/.eslintrc.js +30 -0
  5. package/dist/action-sheet/README.en-US.md +60 -0
  6. package/dist/action-sheet/README.md +131 -0
  7. package/dist/action-sheet/action-sheet.css +162 -0
  8. package/dist/action-sheet/action-sheet.vue +350 -0
  9. package/dist/action-sheet/computed.js +15 -0
  10. package/dist/action-sheet/index.d.ts +11 -0
  11. package/dist/action-sheet/index.js +13 -0
  12. package/dist/action-sheet/props.ts +86 -0
  13. package/dist/action-sheet/show.d.ts +28 -0
  14. package/dist/action-sheet/show.js +33 -0
  15. package/dist/action-sheet/type.ts +93 -0
  16. package/dist/avatar/README.en-US.md +102 -0
  17. package/dist/avatar/README.md +152 -0
  18. package/dist/avatar/avatar.css +77 -0
  19. package/dist/avatar/avatar.vue +200 -0
  20. package/dist/avatar/computed.js +30 -0
  21. package/dist/avatar/props.ts +54 -0
  22. package/dist/avatar/type.ts +58 -0
  23. package/dist/avatar-group/avatar-group.css +187 -0
  24. package/dist/avatar-group/avatar-group.vue +121 -0
  25. package/dist/avatar-group/props.ts +44 -0
  26. package/dist/avatar-group/type.ts +38 -0
  27. package/dist/back-top/README.en-US.md +49 -0
  28. package/dist/back-top/README.md +67 -0
  29. package/dist/back-top/back-top.css +65 -0
  30. package/dist/back-top/back-top.vue +122 -0
  31. package/dist/back-top/props.ts +48 -0
  32. package/dist/back-top/type.ts +42 -0
  33. package/dist/badge/README.en-US.md +54 -0
  34. package/dist/badge/README.md +85 -0
  35. package/dist/badge/badge.css +140 -0
  36. package/dist/badge/badge.vue +134 -0
  37. package/dist/badge/computed.js +63 -0
  38. package/dist/badge/props.ts +55 -0
  39. package/dist/badge/type.ts +60 -0
  40. package/dist/button/README.en-US.md +238 -0
  41. package/dist/button/README.md +229 -0
  42. package/dist/button/button.css +514 -0
  43. package/dist/button/button.vue +244 -0
  44. package/dist/button/props.ts +207 -0
  45. package/dist/button/type.ts +192 -0
  46. package/dist/calendar/README.en-US.md +63 -0
  47. package/dist/calendar/README.md +113 -0
  48. package/dist/calendar/calendar-header.props.js +42 -0
  49. package/dist/calendar/calendar-header.vue +98 -0
  50. package/dist/calendar/calendar.css +205 -0
  51. package/dist/calendar/calendar.vue +454 -0
  52. package/dist/calendar/computed.js +42 -0
  53. package/dist/calendar/props.ts +113 -0
  54. package/dist/calendar/template.props.js +57 -0
  55. package/dist/calendar/template.vue +261 -0
  56. package/dist/calendar/type.ts +141 -0
  57. package/dist/calendar/utils.js +16 -0
  58. package/dist/cascader/README.en-US.md +56 -0
  59. package/dist/cascader/README.md +96 -0
  60. package/dist/cascader/cascader.css +102 -0
  61. package/dist/cascader/cascader.vue +519 -0
  62. package/dist/cascader/props.ts +73 -0
  63. package/dist/cascader/type.ts +77 -0
  64. package/dist/cell/README.en-US.md +116 -0
  65. package/dist/cell/README.md +147 -0
  66. package/dist/cell/cell.css +94 -0
  67. package/dist/cell/cell.vue +260 -0
  68. package/dist/cell/props.ts +87 -0
  69. package/dist/cell/type.ts +82 -0
  70. package/dist/cell-group/cell-group.css +44 -0
  71. package/dist/cell-group/cell-group.vue +69 -0
  72. package/dist/cell-group/props.ts +25 -0
  73. package/dist/cell-group/type.ts +23 -0
  74. package/dist/check-tag/check-tag.css +197 -0
  75. package/dist/check-tag/check-tag.vue +149 -0
  76. package/dist/check-tag/props.ts +67 -0
  77. package/dist/check-tag/type.ts +63 -0
  78. package/dist/checkbox/README.en-US.md +103 -0
  79. package/dist/checkbox/README.md +158 -0
  80. package/dist/checkbox/checkbox.css +174 -0
  81. package/dist/checkbox/checkbox.vue +238 -0
  82. package/dist/checkbox/props.ts +90 -0
  83. package/dist/checkbox/type.ts +96 -0
  84. package/dist/checkbox-group/checkbox-group.css +0 -0
  85. package/dist/checkbox-group/checkbox-group.vue +261 -0
  86. package/dist/checkbox-group/props.ts +58 -0
  87. package/dist/checkbox-group/type.ts +72 -0
  88. package/dist/col/README.en-US.md +31 -0
  89. package/dist/col/README.md +60 -0
  90. package/dist/col/col.css +149 -0
  91. package/dist/col/col.vue +58 -0
  92. package/dist/col/computed.js +14 -0
  93. package/dist/col/props.ts +16 -0
  94. package/dist/col/type.ts +16 -0
  95. package/dist/collapse/README.en-US.md +82 -0
  96. package/dist/collapse/README.md +119 -0
  97. package/dist/collapse/collapse.css +5 -0
  98. package/dist/collapse/collapse.vue +119 -0
  99. package/dist/collapse/props.ts +42 -0
  100. package/dist/collapse/type.ts +46 -0
  101. package/dist/collapse-panel/collapse-panel.css +154 -0
  102. package/dist/collapse-panel/collapse-panel.vue +238 -0
  103. package/dist/collapse-panel/props.ts +48 -0
  104. package/dist/collapse-panel/type.ts +41 -0
  105. package/dist/color-picker/README.en-US.md +62 -0
  106. package/dist/color-picker/README.md +110 -0
  107. package/dist/color-picker/color-picker.css +271 -0
  108. package/dist/color-picker/color-picker.vue +501 -0
  109. package/dist/color-picker/constants.ts +26 -0
  110. package/dist/color-picker/props.ts +75 -0
  111. package/dist/color-picker/template.props.js +58 -0
  112. package/dist/color-picker/template.vue +198 -0
  113. package/dist/color-picker/type.ts +96 -0
  114. package/dist/color-picker/utils.js +1 -0
  115. package/dist/common/bus.js +84 -0
  116. package/dist/common/canvas/index.js +53 -0
  117. package/dist/common/common.ts +173 -0
  118. package/dist/common/config.js +9 -0
  119. package/dist/common/dom/index.js +1 -0
  120. package/dist/common/dom/select-component.js +26 -0
  121. package/dist/common/event/dynamic.js +10 -0
  122. package/dist/common/functional/mixin.js +51 -0
  123. package/dist/common/relation/index.js +6 -0
  124. package/dist/common/relation/parent-map.js +26 -0
  125. package/dist/common/relation/relation.js +213 -0
  126. package/dist/common/route.js +13 -0
  127. package/dist/common/runtime/index.js +5 -0
  128. package/dist/common/runtime/relation.js +0 -0
  129. package/dist/common/runtime/wxs-polyfill.js +16 -0
  130. package/dist/common/shared/calendar/index.js +128 -0
  131. package/dist/common/shared/calendar/type.ts +14 -0
  132. package/dist/common/shared/color-picker/cmyk.js +78 -0
  133. package/dist/common/shared/color-picker/color.js +428 -0
  134. package/dist/common/shared/color-picker/gradient.js +180 -0
  135. package/dist/common/shared/color-picker/index.js +3 -0
  136. package/dist/common/shared/date.js +46 -0
  137. package/dist/common/shared/qrcode/qrcodegen.js +884 -0
  138. package/dist/common/shared/qrcode/utils.js +124 -0
  139. package/dist/common/src/control.js +66 -0
  140. package/dist/common/src/flatTool.js +99 -0
  141. package/dist/common/src/index.js +4 -0
  142. package/dist/common/src/instantiationDecorator.js +251 -0
  143. package/dist/common/src/superComponent.js +5 -0
  144. package/dist/common/style/_variables.less +232 -0
  145. package/dist/common/style/base.less +4 -0
  146. package/dist/common/style/icons.css +0 -0
  147. package/dist/common/style/index.css +13 -0
  148. package/dist/common/style/mixins/_border.less +34 -0
  149. package/dist/common/style/mixins/_clearfix.less +7 -0
  150. package/dist/common/style/mixins/_cursor.less +6 -0
  151. package/dist/common/style/mixins/_ellipsis.less +15 -0
  152. package/dist/common/style/mixins/_hairline.less +55 -0
  153. package/dist/common/style/mixins/_index.less +6 -0
  154. package/dist/common/style/mixins/_other.less +14 -0
  155. package/dist/common/style/theme/index.css +519 -0
  156. package/dist/common/style/theme/index.less +11 -0
  157. package/dist/common/style/theme/raw/_components.less +30 -0
  158. package/dist/common/style/theme/raw/_dark.less +178 -0
  159. package/dist/common/style/theme/raw/_font.less +90 -0
  160. package/dist/common/style/theme/raw/_light.less +182 -0
  161. package/dist/common/style/theme/raw/_radius.less +10 -0
  162. package/dist/common/style/theme/raw/_spacer.less +11 -0
  163. package/dist/common/style/utilities/index.css +13 -0
  164. package/dist/common/utils.js +358 -0
  165. package/dist/common/utils.wxs.js +139 -0
  166. package/dist/common/validator.js +38 -0
  167. package/dist/common/version.js +66 -0
  168. package/dist/common/wechat.js +22 -0
  169. package/dist/count-down/README.en-US.md +50 -0
  170. package/dist/count-down/README.md +76 -0
  171. package/dist/count-down/computed.js +3 -0
  172. package/dist/count-down/count-down.css +110 -0
  173. package/dist/count-down/count-down.vue +166 -0
  174. package/dist/count-down/props.ts +62 -0
  175. package/dist/count-down/type.ts +64 -0
  176. package/dist/count-down/utils.js +72 -0
  177. package/dist/date-time-picker/README.en-US.md +61 -0
  178. package/dist/date-time-picker/README.md +105 -0
  179. package/dist/date-time-picker/date-time-picker.css +4 -0
  180. package/dist/date-time-picker/date-time-picker.vue +570 -0
  181. package/dist/date-time-picker/locale/dayjs.js +81 -0
  182. package/dist/date-time-picker/locale/en.js +12 -0
  183. package/dist/date-time-picker/locale/ja.js +12 -0
  184. package/dist/date-time-picker/locale/ko.js +12 -0
  185. package/dist/date-time-picker/locale/ru.js +12 -0
  186. package/dist/date-time-picker/locale/tc.js +12 -0
  187. package/dist/date-time-picker/locale/zh.js +12 -0
  188. package/dist/date-time-picker/props.ts +114 -0
  189. package/dist/date-time-picker/type.ts +134 -0
  190. package/dist/demo/demo.vue +97 -0
  191. package/dist/demo/index.css +46 -0
  192. package/dist/demo-header/demo-header.vue +60 -0
  193. package/dist/demo-header/index.css +0 -0
  194. package/dist/demo-navbar/demo-navbar.vue +42 -0
  195. package/dist/dialog/README.en-US.md +69 -0
  196. package/dist/dialog/README.md +120 -0
  197. package/dist/dialog/computed.js +15 -0
  198. package/dist/dialog/dialog.css +102 -0
  199. package/dist/dialog/dialog.vue +422 -0
  200. package/dist/dialog/index.d.ts +42 -0
  201. package/dist/dialog/index.js +90 -0
  202. package/dist/dialog/props.ts +94 -0
  203. package/dist/dialog/type.ts +97 -0
  204. package/dist/divider/README.en-US.md +40 -0
  205. package/dist/divider/README.md +64 -0
  206. package/dist/divider/divider.css +56 -0
  207. package/dist/divider/divider.vue +79 -0
  208. package/dist/divider/props.ts +33 -0
  209. package/dist/divider/type.ts +27 -0
  210. package/dist/draggable/draggable.css +16 -0
  211. package/dist/draggable/draggable.vue +92 -0
  212. package/dist/draggable/props.js +19 -0
  213. package/dist/drawer/README.en-US.md +54 -0
  214. package/dist/drawer/README.md +80 -0
  215. package/dist/drawer/drawer.css +62 -0
  216. package/dist/drawer/drawer.vue +144 -0
  217. package/dist/drawer/props.ts +72 -0
  218. package/dist/drawer/type.ts +81 -0
  219. package/dist/dropdown-item/computed.js +6 -0
  220. package/dist/dropdown-item/dropdown-item.css +97 -0
  221. package/dist/dropdown-item/dropdown-item.vue +403 -0
  222. package/dist/dropdown-item/props.ts +71 -0
  223. package/dist/dropdown-item/type.ts +76 -0
  224. package/dist/dropdown-menu/README.en-US.md +95 -0
  225. package/dist/dropdown-menu/README.md +125 -0
  226. package/dist/dropdown-menu/dropdown-menu.css +59 -0
  227. package/dist/dropdown-menu/dropdown-menu.vue +188 -0
  228. package/dist/dropdown-menu/props.ts +44 -0
  229. package/dist/dropdown-menu/type.ts +41 -0
  230. package/dist/empty/README.en-US.md +39 -0
  231. package/dist/empty/README.md +69 -0
  232. package/dist/empty/empty.css +21 -0
  233. package/dist/empty/empty.vue +140 -0
  234. package/dist/empty/props.ts +20 -0
  235. package/dist/empty/type.ts +20 -0
  236. package/dist/fab/README.en-US.md +37 -0
  237. package/dist/fab/README.md +81 -0
  238. package/dist/fab/fab.css +9 -0
  239. package/dist/fab/fab.vue +238 -0
  240. package/dist/fab/props.ts +54 -0
  241. package/dist/fab/type.ts +57 -0
  242. package/dist/footer/README.en-US.md +33 -0
  243. package/dist/footer/README.md +61 -0
  244. package/dist/footer/footer.css +47 -0
  245. package/dist/footer/footer.vue +117 -0
  246. package/dist/footer/props.ts +23 -0
  247. package/dist/footer/type.ts +34 -0
  248. package/dist/form/README.en-US.md +137 -0
  249. package/dist/form/README.md +146 -0
  250. package/dist/form/form-item-props.ts +56 -0
  251. package/dist/form/form.css +169 -0
  252. package/dist/form/form.vue +287 -0
  253. package/dist/form/props.ts +109 -0
  254. package/dist/form/type.ts +387 -0
  255. package/dist/form-item/README.en-US.md +37 -0
  256. package/dist/form-item/README.md +37 -0
  257. package/dist/form-item/form-item.css +120 -0
  258. package/dist/form-item/form-item.vue +396 -0
  259. package/dist/form-item/form-model.ts +198 -0
  260. package/dist/form-item/props.ts +64 -0
  261. package/dist/form-item/type.ts +7 -0
  262. package/dist/grid/README.en-US.md +92 -0
  263. package/dist/grid/README.md +143 -0
  264. package/dist/grid/grid.css +13 -0
  265. package/dist/grid/grid.vue +94 -0
  266. package/dist/grid/props.ts +43 -0
  267. package/dist/grid/type.ts +43 -0
  268. package/dist/grid-item/README.en-US.md +65 -0
  269. package/dist/grid-item/README.md +65 -0
  270. package/dist/grid-item/grid-item.css +103 -0
  271. package/dist/grid-item/grid-item.vue +292 -0
  272. package/dist/grid-item/props.ts +63 -0
  273. package/dist/grid-item/type.ts +56 -0
  274. package/dist/guide/README.en-US.md +103 -0
  275. package/dist/guide/README.md +140 -0
  276. package/dist/guide/content.vue +325 -0
  277. package/dist/guide/guide.css +64 -0
  278. package/dist/guide/guide.vue +544 -0
  279. package/dist/guide/props.ts +98 -0
  280. package/dist/guide/type.ts +174 -0
  281. package/dist/icon/README.en-US.md +32 -0
  282. package/dist/icon/README.md +109 -0
  283. package/dist/icon/icon.css +7073 -0
  284. package/dist/icon/icon.vue +121 -0
  285. package/dist/icon/props.ts +35 -0
  286. package/dist/icon/type.ts +32 -0
  287. package/dist/image/README.en-US.md +51 -0
  288. package/dist/image/README.md +86 -0
  289. package/dist/image/image.css +44 -0
  290. package/dist/image/image.vue +207 -0
  291. package/dist/image/props.ts +71 -0
  292. package/dist/image/type.ts +85 -0
  293. package/dist/image-viewer/README.en-US.md +49 -0
  294. package/dist/image-viewer/README.md +78 -0
  295. package/dist/image-viewer/computed.js +4 -0
  296. package/dist/image-viewer/image-viewer.css +75 -0
  297. package/dist/image-viewer/image-viewer.vue +317 -0
  298. package/dist/image-viewer/props.ts +69 -0
  299. package/dist/image-viewer/type.ts +76 -0
  300. package/dist/indexes/README.en-US.md +76 -0
  301. package/dist/indexes/README.md +105 -0
  302. package/dist/indexes/computed.js +4 -0
  303. package/dist/indexes/indexes-anchor-props.ts +12 -0
  304. package/dist/indexes/indexes.css +50 -0
  305. package/dist/indexes/indexes.vue +371 -0
  306. package/dist/indexes/props.ts +40 -0
  307. package/dist/indexes/type.ts +38 -0
  308. package/dist/indexes-anchor/README.en-US.md +24 -0
  309. package/dist/indexes-anchor/README.md +28 -0
  310. package/dist/indexes-anchor/indexes-anchor.css +49 -0
  311. package/dist/indexes-anchor/indexes-anchor.vue +73 -0
  312. package/dist/indexes-anchor/props.ts +12 -0
  313. package/dist/indexes-anchor/type.ts +12 -0
  314. package/dist/input/README.en-US.md +121 -0
  315. package/dist/input/README.md +190 -0
  316. package/dist/input/computed.js +13 -0
  317. package/dist/input/input.css +161 -0
  318. package/dist/input/input.vue +407 -0
  319. package/dist/input/props.ts +247 -0
  320. package/dist/input/type.ts +237 -0
  321. package/dist/input/utils.js +38 -0
  322. package/dist/link/README.en-US.md +67 -0
  323. package/dist/link/README.md +115 -0
  324. package/dist/link/link.css +118 -0
  325. package/dist/link/link.vue +175 -0
  326. package/dist/link/props.ts +65 -0
  327. package/dist/link/type.ts +62 -0
  328. package/dist/loading/README.en-US.md +49 -0
  329. package/dist/loading/README.md +96 -0
  330. package/dist/loading/loading.css +203 -0
  331. package/dist/loading/loading.vue +157 -0
  332. package/dist/loading/props.ts +68 -0
  333. package/dist/loading/type.ts +70 -0
  334. package/dist/message/README.en-US.md +69 -0
  335. package/dist/message/README.md +105 -0
  336. package/dist/message/config.js +10 -0
  337. package/dist/message/index.d.ts +17 -0
  338. package/dist/message/index.js +39 -0
  339. package/dist/message/message.css +0 -0
  340. package/dist/message/message.interface.ts +30 -0
  341. package/dist/message/message.vue +275 -0
  342. package/dist/message/props.ts +101 -0
  343. package/dist/message/type.ts +101 -0
  344. package/dist/message-item/computed.js +23 -0
  345. package/dist/message-item/index.js +40 -0
  346. package/dist/message-item/message-item.css +63 -0
  347. package/dist/message-item/message-item.vue +353 -0
  348. package/dist/mixins/page-scroll.js +115 -0
  349. package/dist/mixins/skyline.js +12 -0
  350. package/dist/mixins/theme-change.js +16 -0
  351. package/dist/mixins/touch.js +29 -0
  352. package/dist/mixins/transition.js +133 -0
  353. package/dist/mixins/using-custom-navbar.js +38 -0
  354. package/dist/navbar/README.en-US.md +76 -0
  355. package/dist/navbar/README.md +121 -0
  356. package/dist/navbar/navbar.css +106 -0
  357. package/dist/navbar/navbar.vue +293 -0
  358. package/dist/navbar/props.ts +75 -0
  359. package/dist/navbar/type.ts +76 -0
  360. package/dist/notice-bar/README.en-US.md +62 -0
  361. package/dist/notice-bar/README.md +116 -0
  362. package/dist/notice-bar/notice-bar.css +75 -0
  363. package/dist/notice-bar/notice-bar.vue +326 -0
  364. package/dist/notice-bar/props.ts +71 -0
  365. package/dist/notice-bar/type.ts +71 -0
  366. package/dist/npm/dayjs/esm/constant.js +25 -0
  367. package/dist/npm/dayjs/esm/index.js +541 -0
  368. package/dist/npm/dayjs/esm/locale/en.js +12 -0
  369. package/dist/npm/dayjs/esm/locale/ja.js +45 -0
  370. package/dist/npm/dayjs/esm/locale/ko.js +45 -0
  371. package/dist/npm/dayjs/esm/locale/ru.js +99 -0
  372. package/dist/npm/dayjs/esm/locale/zh-cn.js +67 -0
  373. package/dist/npm/dayjs/esm/locale/zh-tw.js +65 -0
  374. package/dist/npm/dayjs/esm/plugin/localeData/index.js +114 -0
  375. package/dist/npm/dayjs/esm/plugin/localizedFormat/index.js +20 -0
  376. package/dist/npm/dayjs/esm/plugin/localizedFormat/utils.js +20 -0
  377. package/dist/npm/dayjs/esm/utils.js +58 -0
  378. package/dist/npm/tinycolor2/esm/tinycolor.js +1180 -0
  379. package/dist/overlay/README.en-US.md +34 -0
  380. package/dist/overlay/README.md +54 -0
  381. package/dist/overlay/overlay.css +17 -0
  382. package/dist/overlay/overlay.vue +105 -0
  383. package/dist/overlay/props.ts +37 -0
  384. package/dist/overlay/type.ts +42 -0
  385. package/dist/picker/README.en-US.md +77 -0
  386. package/dist/picker/README.md +112 -0
  387. package/dist/picker/picker.css +71 -0
  388. package/dist/picker/picker.vue +315 -0
  389. package/dist/picker/props.ts +95 -0
  390. package/dist/picker/type.ts +114 -0
  391. package/dist/picker-item/README.en-US.md +25 -0
  392. package/dist/picker-item/README.md +25 -0
  393. package/dist/picker-item/picker-item.css +32 -0
  394. package/dist/picker-item/picker-item.vue +446 -0
  395. package/dist/picker-item/props.ts +18 -0
  396. package/dist/picker-item/type.ts +23 -0
  397. package/dist/popover/README.en-US.md +55 -0
  398. package/dist/popover/README.md +85 -0
  399. package/dist/popover/popover.css +271 -0
  400. package/dist/popover/popover.vue +352 -0
  401. package/dist/popover/props.ts +58 -0
  402. package/dist/popover/type.ts +61 -0
  403. package/dist/popup/README.en-US.md +53 -0
  404. package/dist/popup/README.md +82 -0
  405. package/dist/popup/computed.js +14 -0
  406. package/dist/popup/popup.css +80 -0
  407. package/dist/popup/popup.vue +141 -0
  408. package/dist/popup/props.ts +67 -0
  409. package/dist/popup/type.ts +72 -0
  410. package/dist/progress/README.en-US.md +52 -0
  411. package/dist/progress/README.md +87 -0
  412. package/dist/progress/computed.js +81 -0
  413. package/dist/progress/progress.css +136 -0
  414. package/dist/progress/progress.vue +259 -0
  415. package/dist/progress/props.ts +55 -0
  416. package/dist/progress/type.ts +50 -0
  417. package/dist/progress/utils.js +19 -0
  418. package/dist/pull-down-refresh/README.en-US.md +60 -0
  419. package/dist/pull-down-refresh/README.md +83 -0
  420. package/dist/pull-down-refresh/props.ts +112 -0
  421. package/dist/pull-down-refresh/pull-down-refresh.css +29 -0
  422. package/dist/pull-down-refresh/pull-down-refresh.vue +366 -0
  423. package/dist/pull-down-refresh/type.ts +118 -0
  424. package/dist/qrcode/README.en-US.md +40 -0
  425. package/dist/qrcode/README.md +97 -0
  426. package/dist/qrcode/components/qrcode-canvas/props.ts +48 -0
  427. package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.css +7 -0
  428. package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +413 -0
  429. package/dist/qrcode/components/qrcode-status/props.ts +22 -0
  430. package/dist/qrcode/components/qrcode-status/qrcode-status.css +25 -0
  431. package/dist/qrcode/components/qrcode-status/qrcode-status.vue +94 -0
  432. package/dist/qrcode/components/qrcode-status/type.ts +25 -0
  433. package/dist/qrcode/hooks/useQRCode.js +25 -0
  434. package/dist/qrcode/props.ts +66 -0
  435. package/dist/qrcode/qrcode.css +31 -0
  436. package/dist/qrcode/qrcode.vue +144 -0
  437. package/dist/qrcode/type.ts +66 -0
  438. package/dist/radio/README.en-US.md +104 -0
  439. package/dist/radio/README.md +148 -0
  440. package/dist/radio/props.ts +86 -0
  441. package/dist/radio/radio.css +177 -0
  442. package/dist/radio/radio.vue +227 -0
  443. package/dist/radio/type.ts +89 -0
  444. package/dist/radio-group/props.ts +68 -0
  445. package/dist/radio-group/radio-group.css +0 -0
  446. package/dist/radio-group/radio-group.vue +205 -0
  447. package/dist/radio-group/type.ts +79 -0
  448. package/dist/rate/README.en-US.md +50 -0
  449. package/dist/rate/README.md +107 -0
  450. package/dist/rate/computed.js +66 -0
  451. package/dist/rate/props.ts +85 -0
  452. package/dist/rate/rate.css +81 -0
  453. package/dist/rate/rate.vue +276 -0
  454. package/dist/rate/type.ts +79 -0
  455. package/dist/result/README.en-US.md +47 -0
  456. package/dist/result/README.md +88 -0
  457. package/dist/result/props.ts +36 -0
  458. package/dist/result/result.css +35 -0
  459. package/dist/result/result.vue +128 -0
  460. package/dist/result/type.ts +31 -0
  461. package/dist/row/computed.js +13 -0
  462. package/dist/row/props.ts +12 -0
  463. package/dist/row/row.css +6 -0
  464. package/dist/row/row.vue +63 -0
  465. package/dist/row/type.ts +12 -0
  466. package/dist/script/postinstall.js +46 -0
  467. package/dist/scroll-view/scroll-view.css +0 -0
  468. package/dist/scroll-view/scroll-view.vue +52 -0
  469. package/dist/search/README.en-US.md +88 -0
  470. package/dist/search/README.md +126 -0
  471. package/dist/search/computed.js +3 -0
  472. package/dist/search/props.ts +171 -0
  473. package/dist/search/search.css +75 -0
  474. package/dist/search/search.vue +285 -0
  475. package/dist/search/type.ts +165 -0
  476. package/dist/side-bar/README.en-US.md +58 -0
  477. package/dist/side-bar/README.md +89 -0
  478. package/dist/side-bar/props.ts +26 -0
  479. package/dist/side-bar/side-bar-item-props.ts +27 -0
  480. package/dist/side-bar/side-bar.css +14 -0
  481. package/dist/side-bar/side-bar.vue +84 -0
  482. package/dist/side-bar/type.ts +24 -0
  483. package/dist/side-bar-item/props.ts +27 -0
  484. package/dist/side-bar-item/side-bar-item.css +66 -0
  485. package/dist/side-bar-item/side-bar-item.vue +168 -0
  486. package/dist/side-bar-item/type.ts +32 -0
  487. package/dist/skeleton/README.en-US.md +44 -0
  488. package/dist/skeleton/README.md +82 -0
  489. package/dist/skeleton/props.ts +41 -0
  490. package/dist/skeleton/skeleton.css +77 -0
  491. package/dist/skeleton/skeleton.vue +211 -0
  492. package/dist/skeleton/type.ts +44 -0
  493. package/dist/slider/README.en-US.md +63 -0
  494. package/dist/slider/README.md +127 -0
  495. package/dist/slider/computed.js +9 -0
  496. package/dist/slider/props.ts +79 -0
  497. package/dist/slider/slider.css +239 -0
  498. package/dist/slider/slider.vue +719 -0
  499. package/dist/slider/tool.js +43 -0
  500. package/dist/slider/type.ts +81 -0
  501. package/dist/step-item/computed.js +4 -0
  502. package/dist/step-item/props.ts +36 -0
  503. package/dist/step-item/step-item.css +182 -0
  504. package/dist/step-item/step-item.vue +175 -0
  505. package/dist/step-item/type.ts +33 -0
  506. package/dist/stepper/README.en-US.md +49 -0
  507. package/dist/stepper/README.md +90 -0
  508. package/dist/stepper/props.ts +88 -0
  509. package/dist/stepper/stepper.css +105 -0
  510. package/dist/stepper/stepper.vue +223 -0
  511. package/dist/stepper/type.ts +79 -0
  512. package/dist/steps/README.en-US.md +99 -0
  513. package/dist/steps/README.md +157 -0
  514. package/dist/steps/props.ts +63 -0
  515. package/dist/steps/steps.css +19 -0
  516. package/dist/steps/steps.vue +122 -0
  517. package/dist/steps/type.ts +44 -0
  518. package/dist/sticky/README.en-US.md +32 -0
  519. package/dist/sticky/README.md +66 -0
  520. package/dist/sticky/props.ts +30 -0
  521. package/dist/sticky/sticky.css +3 -0
  522. package/dist/sticky/sticky.vue +144 -0
  523. package/dist/sticky/type.ts +31 -0
  524. package/dist/swipe-cell/README.en-US.md +29 -0
  525. package/dist/swipe-cell/README.md +66 -0
  526. package/dist/swipe-cell/computed.js +166 -0
  527. package/dist/swipe-cell/props.ts +39 -0
  528. package/dist/swipe-cell/swipe-cell.css +31 -0
  529. package/dist/swipe-cell/swipe-cell.vue +245 -0
  530. package/dist/swipe-cell/type.ts +48 -0
  531. package/dist/swiper/README.en-US.md +89 -0
  532. package/dist/swiper/README.md +139 -0
  533. package/dist/swiper/computed.js +29 -0
  534. package/dist/swiper/props.ts +117 -0
  535. package/dist/swiper/swiper.css +21 -0
  536. package/dist/swiper/swiper.vue +193 -0
  537. package/dist/swiper/type.ts +112 -0
  538. package/dist/swiper-nav/props.ts +49 -0
  539. package/dist/swiper-nav/swiper-nav.css +130 -0
  540. package/dist/swiper-nav/swiper-nav.vue +93 -0
  541. package/dist/swiper-nav/type.ts +45 -0
  542. package/dist/switch/README.en-US.md +70 -0
  543. package/dist/switch/README.md +104 -0
  544. package/dist/switch/props.ts +53 -0
  545. package/dist/switch/switch.css +123 -0
  546. package/dist/switch/switch.vue +122 -0
  547. package/dist/switch/type.ts +51 -0
  548. package/dist/tab-bar/README.en-US.md +58 -0
  549. package/dist/tab-bar/README.md +104 -0
  550. package/dist/tab-bar/props.ts +62 -0
  551. package/dist/tab-bar/tab-bar.css +42 -0
  552. package/dist/tab-bar/tab-bar.vue +141 -0
  553. package/dist/tab-bar/type.ts +56 -0
  554. package/dist/tab-bar-item/props.ts +25 -0
  555. package/dist/tab-bar-item/tab-bar-item.css +117 -0
  556. package/dist/tab-bar-item/tab-bar-item.vue +222 -0
  557. package/dist/tab-bar-item/type.ts +32 -0
  558. package/dist/tab-panel/props.ts +34 -0
  559. package/dist/tab-panel/tab-panel.css +15 -0
  560. package/dist/tab-panel/tab-panel.vue +100 -0
  561. package/dist/tab-panel/type.ts +42 -0
  562. package/dist/tabs/README.en-US.md +89 -0
  563. package/dist/tabs/README.md +198 -0
  564. package/dist/tabs/computed.js +26 -0
  565. package/dist/tabs/props.ts +80 -0
  566. package/dist/tabs/tabs.css +183 -0
  567. package/dist/tabs/tabs.vue +494 -0
  568. package/dist/tabs/type.ts +77 -0
  569. package/dist/tag/README.en-US.md +113 -0
  570. package/dist/tag/README.md +151 -0
  571. package/dist/tag/props.ts +70 -0
  572. package/dist/tag/tag.css +208 -0
  573. package/dist/tag/tag.vue +161 -0
  574. package/dist/tag/type.ts +54 -0
  575. package/dist/tdesign-uniapp/tdesign-uniapp.vue +11 -0
  576. package/dist/textarea/README.en-US.md +78 -0
  577. package/dist/textarea/README.md +132 -0
  578. package/dist/textarea/computed.js +14 -0
  579. package/dist/textarea/props.ts +152 -0
  580. package/dist/textarea/textarea.css +67 -0
  581. package/dist/textarea/textarea.vue +227 -0
  582. package/dist/textarea/type.ts +167 -0
  583. package/dist/toast/README.en-US.md +51 -0
  584. package/dist/toast/README.md +78 -0
  585. package/dist/toast/index.d.ts +20 -0
  586. package/dist/toast/index.js +27 -0
  587. package/dist/toast/props.ts +68 -0
  588. package/dist/toast/toast.css +73 -0
  589. package/dist/toast/toast.vue +213 -0
  590. package/dist/toast/type.ts +64 -0
  591. package/dist/transition/README.en-US.md +13 -0
  592. package/dist/transition/README.md +45 -0
  593. package/dist/transition/props.js +22 -0
  594. package/dist/transition/transition.css +14 -0
  595. package/dist/transition/transition.vue +51 -0
  596. package/dist/tree-select/README.en-US.md +48 -0
  597. package/dist/tree-select/README.md +78 -0
  598. package/dist/tree-select/computed.js +6 -0
  599. package/dist/tree-select/props.ts +42 -0
  600. package/dist/tree-select/tree-select.css +44 -0
  601. package/dist/tree-select/tree-select.vue +319 -0
  602. package/dist/tree-select/type.ts +49 -0
  603. package/dist/tsconfig.eslint.json +13 -0
  604. package/dist/types/action-sheet.d.ts +7 -0
  605. package/dist/types/avatar-group.d.ts +7 -0
  606. package/dist/types/avatar.d.ts +7 -0
  607. package/dist/types/back-top.d.ts +7 -0
  608. package/dist/types/badge.d.ts +7 -0
  609. package/dist/types/button.d.ts +7 -0
  610. package/dist/types/calendar.d.ts +7 -0
  611. package/dist/types/cascader.d.ts +7 -0
  612. package/dist/types/cell-group.d.ts +7 -0
  613. package/dist/types/cell.d.ts +7 -0
  614. package/dist/types/check-tag.d.ts +7 -0
  615. package/dist/types/checkbox-group.d.ts +7 -0
  616. package/dist/types/checkbox.d.ts +7 -0
  617. package/dist/types/col.d.ts +7 -0
  618. package/dist/types/collapse-panel.d.ts +7 -0
  619. package/dist/types/collapse.d.ts +7 -0
  620. package/dist/types/color-picker.d.ts +7 -0
  621. package/dist/types/count-down.d.ts +7 -0
  622. package/dist/types/date-time-picker.d.ts +7 -0
  623. package/dist/types/dialog.d.ts +7 -0
  624. package/dist/types/divider.d.ts +7 -0
  625. package/dist/types/drawer.d.ts +7 -0
  626. package/dist/types/dropdown-item.d.ts +7 -0
  627. package/dist/types/dropdown-menu.d.ts +7 -0
  628. package/dist/types/empty.d.ts +7 -0
  629. package/dist/types/fab.d.ts +7 -0
  630. package/dist/types/footer.d.ts +7 -0
  631. package/dist/types/form-item.d.ts +7 -0
  632. package/dist/types/form.d.ts +7 -0
  633. package/dist/types/grid-item.d.ts +7 -0
  634. package/dist/types/grid.d.ts +7 -0
  635. package/dist/types/guide.d.ts +7 -0
  636. package/dist/types/icon.d.ts +7 -0
  637. package/dist/types/image-viewer.d.ts +7 -0
  638. package/dist/types/image.d.ts +7 -0
  639. package/dist/types/index.d.ts +77 -0
  640. package/dist/types/indexes-anchor.d.ts +7 -0
  641. package/dist/types/indexes.d.ts +7 -0
  642. package/dist/types/input.d.ts +7 -0
  643. package/dist/types/link.d.ts +7 -0
  644. package/dist/types/loading.d.ts +7 -0
  645. package/dist/types/message.d.ts +7 -0
  646. package/dist/types/navbar.d.ts +7 -0
  647. package/dist/types/notice-bar.d.ts +7 -0
  648. package/dist/types/overlay.d.ts +7 -0
  649. package/dist/types/picker-item.d.ts +7 -0
  650. package/dist/types/picker.d.ts +7 -0
  651. package/dist/types/popup.d.ts +7 -0
  652. package/dist/types/progress.d.ts +7 -0
  653. package/dist/types/pull-down-refresh.d.ts +7 -0
  654. package/dist/types/qrcode.d.ts +7 -0
  655. package/dist/types/radio-group.d.ts +7 -0
  656. package/dist/types/radio.d.ts +7 -0
  657. package/dist/types/rate.d.ts +7 -0
  658. package/dist/types/result.d.ts +7 -0
  659. package/dist/types/row.d.ts +7 -0
  660. package/dist/types/search.d.ts +7 -0
  661. package/dist/types/side-bar-item.d.ts +7 -0
  662. package/dist/types/side-bar.d.ts +7 -0
  663. package/dist/types/skeleton.d.ts +7 -0
  664. package/dist/types/slider.d.ts +7 -0
  665. package/dist/types/step-item.d.ts +7 -0
  666. package/dist/types/stepper.d.ts +7 -0
  667. package/dist/types/steps.d.ts +7 -0
  668. package/dist/types/sticky.d.ts +7 -0
  669. package/dist/types/swipe-cell.d.ts +7 -0
  670. package/dist/types/swiper-nav.d.ts +7 -0
  671. package/dist/types/swiper.d.ts +7 -0
  672. package/dist/types/switch.d.ts +7 -0
  673. package/dist/types/tab-bar-item.d.ts +7 -0
  674. package/dist/types/tab-bar.d.ts +7 -0
  675. package/dist/types/tab-panel.d.ts +7 -0
  676. package/dist/types/tabs.d.ts +7 -0
  677. package/dist/types/tag.d.ts +7 -0
  678. package/dist/types/textarea.d.ts +7 -0
  679. package/dist/types/toast.d.ts +7 -0
  680. package/dist/types/tree-select.d.ts +7 -0
  681. package/dist/types/upload.d.ts +7 -0
  682. package/dist/types/watermark.d.ts +7 -0
  683. package/dist/upload/README.en-US.md +63 -0
  684. package/dist/upload/README.md +116 -0
  685. package/dist/upload/drag.computed.js +227 -0
  686. package/dist/upload/props.ts +136 -0
  687. package/dist/upload/type.ts +197 -0
  688. package/dist/upload/upload.computed.js +13 -0
  689. package/dist/upload/upload.css +116 -0
  690. package/dist/upload/upload.vue +887 -0
  691. package/dist/watermark/README.en-US.md +63 -0
  692. package/dist/watermark/README.md +115 -0
  693. package/dist/watermark/props.ts +82 -0
  694. package/dist/watermark/type.ts +121 -0
  695. package/dist/watermark/utils/generateBase64Url.js +360 -0
  696. package/dist/watermark/utils/randomMovingStyle.js +27 -0
  697. package/dist/watermark/watermark.css +28 -0
  698. package/dist/watermark/watermark.vue +200 -0
  699. package/global.d.ts +84 -0
  700. package/package.json +504 -8
@@ -0,0 +1,884 @@
1
+ /* eslint-disable */
2
+ // Copyright (c) Project Nayuki. (MIT License)
3
+ // https://www.nayuki.io/page/qr-code-generator-library
4
+ // Modification with code reorder and prettier
5
+ // --------------------------------------------
6
+ // Appends the given number of low-order bits of the given value
7
+ // to the given buffer. Requires 0 <= len <= 31 and 0 <= val < 2^len.
8
+ function appendBits(val, len, bb) {
9
+ if (len < 0 || len > 31 || val >>> len !== 0) {
10
+ throw new RangeError('Value out of range');
11
+ }
12
+ for (let i = len - 1; i >= 0; i-- // Append bit by bit
13
+ ) {
14
+ bb.push((val >>> i) & 1);
15
+ }
16
+ }
17
+ // Returns true iff the i'th bit of x is set to 1.
18
+ function getBit(x, i) {
19
+ return ((x >>> i) & 1) !== 0;
20
+ }
21
+ // Throws an exception if the given condition is false.
22
+ function assert(cond) {
23
+ if (!cond) {
24
+ throw new Error('Assertion error');
25
+ }
26
+ }
27
+ /* ---- Public helper enumeration ----*/
28
+ /*
29
+ * Describes how a segment's data bits are numbererpreted. Immutable.
30
+ */
31
+ export class Mode {
32
+ constructor(modeBits, numBitsCharCount) {
33
+ this.modeBits = modeBits;
34
+ this.numBitsCharCount = numBitsCharCount;
35
+ }
36
+ /* -- Method --*/
37
+ // (Package-private) Returns the bit width of the character count field for a segment in
38
+ // this mode in a QR Code at the given version number. The result is in the range [0, 16].
39
+ numCharCountBits(ver) {
40
+ return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
41
+ }
42
+ }
43
+ /* -- Constants --*/
44
+ Mode.NUMERIC = new Mode(0x1, [10, 12, 14]);
45
+ Mode.ALPHANUMERIC = new Mode(0x2, [9, 11, 13]);
46
+ Mode.BYTE = new Mode(0x4, [8, 16, 16]);
47
+ Mode.KANJI = new Mode(0x8, [8, 10, 12]);
48
+ Mode.ECI = new Mode(0x7, [0, 0, 0]);
49
+ /* ---- Public helper enumeration ----*/
50
+ /*
51
+ * The error correction level in a QR Code symbol. Immutable.
52
+ */
53
+ export class Ecc {
54
+ constructor(ordinal, formatBits) {
55
+ this.ordinal = ordinal;
56
+ this.formatBits = formatBits;
57
+ }
58
+ }
59
+ /* -- Constants --*/
60
+ Ecc.LOW = new Ecc(0, 1); // The QR Code can tolerate about 7% erroneous codewords
61
+ Ecc.MEDIUM = new Ecc(1, 0); // The QR Code can tolerate about 15% erroneous codewords
62
+ Ecc.QUARTILE = new Ecc(2, 3); // The QR Code can tolerate about 25% erroneous codewords
63
+ Ecc.HIGH = new Ecc(3, 2); // The QR Code can tolerate about 30% erroneous codewords
64
+ /*
65
+ * A segment of character/binary/control data in a QR Code symbol.
66
+ * Instances of this class are immutable.
67
+ * The mid-level way to create a segment is to take the payload data
68
+ * and call a static factory function such as QrSegment.makeNumeric().
69
+ * The low-level way to create a segment is to custom-make the bit buffer
70
+ * and call the QrSegment() constructor with appropriate values.
71
+ * This segment class imposes no length restrictions, but QR Codes have restrictions.
72
+ * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
73
+ * Any segment longer than this is meaningless for the purpose of generating QR Codes.
74
+ */
75
+ export class QrSegment {
76
+ // Creates a new QR Code segment with the given attributes and data.
77
+ // The character count (numChars) must agree with the mode and the bit buffer length,
78
+ // but the constranumber isn't checked. The given bit buffer is cloned and stored.
79
+ constructor(mode, numChars, bitData) {
80
+ this.mode = mode;
81
+ this.numChars = numChars;
82
+ this.bitData = bitData;
83
+ if (numChars < 0) {
84
+ throw new RangeError('Invalid argument');
85
+ }
86
+ this.bitData = bitData.slice(); // Make defensive copy
87
+ }
88
+ /* -- Static factory functions (mid level) --*/
89
+ // Returns a segment representing the given binary data encoded in
90
+ // byte mode. All input byte arrays are acceptable. Any text string
91
+ // can be converted to UTF-8 bytes and encoded as a byte mode segment.
92
+ static makeBytes(data) {
93
+ const bb = [];
94
+ for (const b of data) {
95
+ appendBits(b, 8, bb);
96
+ }
97
+ return new QrSegment(Mode.BYTE, data.length, bb);
98
+ }
99
+ // Returns a segment representing the given string of decimal digits encoded in numeric mode.
100
+ static makeNumeric(digits) {
101
+ if (!QrSegment.isNumeric(digits)) {
102
+ throw new RangeError('String contains non-numeric characters');
103
+ }
104
+ const bb = [];
105
+ for (let i = 0; i < digits.length;) {
106
+ // Consume up to 3 digits per iteration
107
+ const n = Math.min(digits.length - i, 3);
108
+ appendBits(parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
109
+ i += n;
110
+ }
111
+ return new QrSegment(Mode.NUMERIC, digits.length, bb);
112
+ }
113
+ // Returns a segment representing the given text string encoded in alphanumeric mode.
114
+ // The characters allowed are: 0 to 9, A to Z (uppercase only), space,
115
+ // dollar, percent, asterisk, plus, hyphen, period, slash, colon.
116
+ static makeAlphanumeric(text) {
117
+ if (!QrSegment.isAlphanumeric(text)) {
118
+ throw new RangeError('String contains unencodable characters in alphanumeric mode');
119
+ }
120
+ const bb = [];
121
+ let i;
122
+ for (i = 0; i + 2 <= text.length; i += 2) {
123
+ // Process groups of 2
124
+ let temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
125
+ temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
126
+ appendBits(temp, 11, bb);
127
+ }
128
+ if (i < text.length) {
129
+ // 1 character remaining
130
+ appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
131
+ }
132
+ return new QrSegment(Mode.ALPHANUMERIC, text.length, bb);
133
+ }
134
+ // Returns a new mutable list of zero or more segments to represent the given Unicode text string.
135
+ // The result may use various segment modes and switch modes to optimize the length of the bit stream.
136
+ static makeSegments(text) {
137
+ // Select the most efficient segment encoding automatically
138
+ if (text === '') {
139
+ return [];
140
+ }
141
+ if (QrSegment.isNumeric(text)) {
142
+ return [QrSegment.makeNumeric(text)];
143
+ }
144
+ if (QrSegment.isAlphanumeric(text)) {
145
+ return [QrSegment.makeAlphanumeric(text)];
146
+ }
147
+ return [QrSegment.makeBytes(QrSegment.toUtf8ByteArray(text))];
148
+ }
149
+ // Returns a segment representing an Extended Channel Interpretation
150
+ // (ECI) designator with the given assignment value.
151
+ static makeEci(assignVal) {
152
+ const bb = [];
153
+ if (assignVal < 0) {
154
+ throw new RangeError('ECI assignment value out of range');
155
+ }
156
+ else if (assignVal < 1 << 7) {
157
+ appendBits(assignVal, 8, bb);
158
+ }
159
+ else if (assignVal < 1 << 14) {
160
+ appendBits(0b10, 2, bb);
161
+ appendBits(assignVal, 14, bb);
162
+ }
163
+ else if (assignVal < 1000000) {
164
+ appendBits(0b110, 3, bb);
165
+ appendBits(assignVal, 21, bb);
166
+ }
167
+ else {
168
+ throw new RangeError('ECI assignment value out of range');
169
+ }
170
+ return new QrSegment(Mode.ECI, 0, bb);
171
+ }
172
+ // Tests whether the given string can be encoded as a segment in numeric mode.
173
+ // A string is encodable iff each character is in the range 0 to 9.
174
+ static isNumeric(text) {
175
+ return QrSegment.NUMERIC_REGEX.test(text);
176
+ }
177
+ // Tests whether the given string can be encoded as a segment in alphanumeric mode.
178
+ // A string is encodable iff each character is in the following set: 0 to 9, A to Z
179
+ // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
180
+ static isAlphanumeric(text) {
181
+ return QrSegment.ALPHANUMERIC_REGEX.test(text);
182
+ }
183
+ /* -- Methods --*/
184
+ // Returns a new copy of the data bits of this segment.
185
+ getData() {
186
+ return this.bitData.slice(); // Make defensive copy
187
+ }
188
+ // (Package-private) Calculates and returns the number of bits needed to encode the given segments at
189
+ // the given version. The result is infinity if a segment has too many characters to fit its length field.
190
+ static getTotalBits(segs, version) {
191
+ let result = 0;
192
+ for (const seg of segs) {
193
+ const ccbits = seg.mode.numCharCountBits(version);
194
+ if (seg.numChars >= 1 << ccbits) {
195
+ return Infinity; // The segment's length doesn't fit the field's bit width
196
+ }
197
+ result += 4 + ccbits + seg.bitData.length;
198
+ }
199
+ return result;
200
+ }
201
+ // Returns a new array of bytes representing the given string encoded in UTF-8.
202
+ static toUtf8ByteArray(input) {
203
+ const str = encodeURI(input);
204
+ const result = [];
205
+ for (let i = 0; i < str.length; i++) {
206
+ if (str.charAt(i) !== '%') {
207
+ result.push(str.charCodeAt(i));
208
+ }
209
+ else {
210
+ result.push(parseInt(str.substring(i + 1, i + 3), 16));
211
+ i += 2;
212
+ }
213
+ }
214
+ return result;
215
+ }
216
+ }
217
+ /* -- Constants --*/
218
+ // Describes precisely all strings that are encodable in numeric mode.
219
+ QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
220
+ // Describes precisely all strings that are encodable in alphanumeric mode.
221
+ QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
222
+ // The set of all legal characters in alphanumeric mode,
223
+ // where each character value maps to the index in the string.
224
+ QrSegment.ALPHANUMERIC_CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:';
225
+ /*
226
+ * A QR Code symbol, which is a type of two-dimension barcode.
227
+ * Invented by Denso Wave and described in the ISO/IEC 18004 standard.
228
+ * Instances of this class represent an immutable square grid of dark and light cells.
229
+ * The class provides static factory functions to create a QR Code from text or binary data.
230
+ * The class covers the QR Code Model 2 specification, supporting all versions (sizes)
231
+ * from 1 to 40, all 4 error correction levels, and 4 character encoding modes.
232
+ *
233
+ * Ways to create a QR Code object:
234
+ * - High level: Take the payload data and call QrCode.encodeText() or QrCode.encodeBinary().
235
+ * - Mid level: Custom-make the list of segments and call QrCode.encodeSegments().
236
+ * - Low level: Custom-make the array of data codeword bytes (including
237
+ * segment headers and final padding, excluding error correction codewords),
238
+ * supply the appropriate version number, and call the QrCode() constructor.
239
+ * (Note that all ways require supplying the desired error correction level.)
240
+ */
241
+ export class QrCode {
242
+ // Creates a new QR Code with the given version number,
243
+ // error correction level, data codeword bytes, and mask number.
244
+ // This is a low-level API that most users should not use directly.
245
+ // A mid-level API is the encodeSegments() function.
246
+ constructor(
247
+ // The version number of this QR Code, which is between 1 and 40 (inclusive).
248
+ // This determines the size of this barcode.
249
+ version,
250
+ // The error correction level used in this QR Code.
251
+ errorCorrectionLevel, dataCodewords, oriMsk) {
252
+ // The modules of this QR Code (false = light, true = dark).
253
+ // Immutable after constructor finishes. Accessed through getModule().
254
+ this.modules = [];
255
+ // Indicates function modules that are not subjected to masking. Discarded when constructor finishes.
256
+ this.isFunction = [];
257
+ let msk = oriMsk;
258
+ this.version = version;
259
+ this.errorCorrectionLevel = errorCorrectionLevel;
260
+ // Check scalar arguments
261
+ if (version < QrCode.MIN_VERSION || version > QrCode.MAX_VERSION) {
262
+ throw new RangeError('Version value out of range');
263
+ }
264
+ if (msk < -1 || msk > 7) {
265
+ throw new RangeError('Mask value out of range');
266
+ }
267
+ this.size = version * 4 + 17;
268
+ // Initialize both grids to be size*size arrays of Boolean false
269
+ const row = [];
270
+ for (let i = 0; i < this.size; i++) {
271
+ row.push(false);
272
+ }
273
+ for (let i = 0; i < this.size; i++) {
274
+ this.modules.push(row.slice()); // Initially all light
275
+ this.isFunction.push(row.slice());
276
+ }
277
+ // Compute ECC, draw modules
278
+ this.drawFunctionPatterns();
279
+ const allCodewords = this.addEccAndInterleave(dataCodewords);
280
+ this.drawCodewords(allCodewords);
281
+ // Do masking
282
+ if (msk === -1) {
283
+ // Automatically choose best mask
284
+ let minPenalty = 1000000000;
285
+ for (let i = 0; i < 8; i++) {
286
+ this.applyMask(i);
287
+ this.drawFormatBits(i);
288
+ const penalty = this.getPenaltyScore();
289
+ if (penalty < minPenalty) {
290
+ msk = i;
291
+ minPenalty = penalty;
292
+ }
293
+ this.applyMask(i); // Undoes the mask due to XOR
294
+ }
295
+ }
296
+ assert(msk >= 0 && msk <= 7);
297
+ this.mask = msk;
298
+ this.applyMask(msk); // Apply the final choice of mask
299
+ this.drawFormatBits(msk); // Overwrite old format bits
300
+ this.isFunction = [];
301
+ }
302
+ /* -- Static factory functions (high level) --*/
303
+ // Returns a QR Code representing the given Unicode text string at the given error correction level.
304
+ // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
305
+ // Unicode code ponumbers (not UTF-16 code units) if the low error correction level is used. The smallest possible
306
+ // QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
307
+ // ecl argument if it can be done without increasing the version.
308
+ static encodeText(text, ecl) {
309
+ const segs = QrSegment.makeSegments(text);
310
+ return QrCode.encodeSegments(segs, ecl);
311
+ }
312
+ // Returns a QR Code representing the given binary data at the given error correction level.
313
+ // This function always encodes using the binary segment mode, not any text mode. The maximum number of
314
+ // bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
315
+ // The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
316
+ static encodeBinary(data, ecl) {
317
+ const seg = QrSegment.makeBytes(data);
318
+ return QrCode.encodeSegments([seg], ecl);
319
+ }
320
+ /* -- Static factory functions (mid level) --*/
321
+ // Returns a QR Code representing the given segments with the given encoding parameters.
322
+ // The smallest possible QR Code version within the given range is automatically
323
+ // chosen for the output. Iff boostEcl is true, then the ECC level of the result
324
+ // may be higher than the ecl argument if it can be done without increasing the
325
+ // version. The mask number is either between 0 to 7 (inclusive) to force that
326
+ // mask, or -1 to automatically choose an appropriate mask (which may be slow).
327
+ // This function allows the user to create a custom sequence of segments that switches
328
+ // between modes (such as alphanumeric and byte) to encode text in less space.
329
+ // This is a mid-level API; the high-level API is encodeText() and encodeBinary().
330
+ static encodeSegments(segs, oriEcl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
331
+ if (!(QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= QrCode.MAX_VERSION) ||
332
+ mask < -1 ||
333
+ mask > 7) {
334
+ throw new RangeError('Invalid value');
335
+ }
336
+ // Find the minimal version number to use
337
+ let version;
338
+ let dataUsedBits;
339
+ for (version = minVersion;; version++) {
340
+ const dataCapacityBits = QrCode.getNumDataCodewords(version, oriEcl) * 8; // Number of data bits available
341
+ const usedBits = QrSegment.getTotalBits(segs, version);
342
+ if (usedBits <= dataCapacityBits) {
343
+ dataUsedBits = usedBits;
344
+ break; // This version number is found to be suitable
345
+ }
346
+ if (version >= maxVersion) {
347
+ // All versions in the range could not fit the given data
348
+ throw new RangeError('Data too long');
349
+ }
350
+ }
351
+ let ecl = oriEcl;
352
+ // Increase the error correction level while the data still fits in the current version number
353
+ for (const newEcl of [Ecc.MEDIUM, Ecc.QUARTILE, Ecc.HIGH]) {
354
+ // From low to high
355
+ if (boostEcl && dataUsedBits <= QrCode.getNumDataCodewords(version, newEcl) * 8) {
356
+ ecl = newEcl;
357
+ }
358
+ }
359
+ // Concatenate all segments to create the data bit string
360
+ const bb = [];
361
+ for (const seg of segs) {
362
+ appendBits(seg.mode.modeBits, 4, bb);
363
+ appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
364
+ for (const b of seg.getData()) {
365
+ bb.push(b);
366
+ }
367
+ }
368
+ assert(bb.length === dataUsedBits);
369
+ // Add terminator and pad up to a byte if applicable
370
+ const dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8;
371
+ assert(bb.length <= dataCapacityBits);
372
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
373
+ appendBits(0, (8 - (bb.length % 8)) % 8, bb);
374
+ assert(bb.length % 8 === 0);
375
+ // Pad with alternating bytes until data capacity is reached
376
+ for (let padByte = 0xec; bb.length < dataCapacityBits; padByte ^= 0xec ^ 0x11) {
377
+ appendBits(padByte, 8, bb);
378
+ }
379
+ // Pack bits numbero bytes in big endian
380
+ const dataCodewords = [];
381
+ while (dataCodewords.length * 8 < bb.length) {
382
+ dataCodewords.push(0);
383
+ }
384
+ bb.forEach((b, i) => {
385
+ dataCodewords[i >>> 3] |= b << (7 - (i & 7));
386
+ });
387
+ // Create the QR Code object
388
+ return new QrCode(version, ecl, dataCodewords, mask);
389
+ }
390
+ /* -- Accessor methods --*/
391
+ // Returns the color of the module (pixel) at the given coordinates, which is false
392
+ // for light or true for dark. The top left corner has the coordinates (x=0, y=0).
393
+ // If the given coordinates are out of bounds, then false (light) is returned.
394
+ getModule(x, y) {
395
+ return x >= 0 && x < this.size && y >= 0 && y < this.size && this.modules[y][x];
396
+ }
397
+ // Modified to expose modules for easy access
398
+ getModules() {
399
+ return this.modules;
400
+ }
401
+ /* -- Private helper methods for constructor: Drawing function modules --*/
402
+ // Reads this object's version field, and draws and marks all function modules.
403
+ drawFunctionPatterns() {
404
+ // Draw horizontal and vertical timing patterns
405
+ for (let i = 0; i < this.size; i++) {
406
+ this.setFunctionModule(6, i, i % 2 === 0);
407
+ this.setFunctionModule(i, 6, i % 2 === 0);
408
+ }
409
+ // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
410
+ this.drawFinderPattern(3, 3);
411
+ this.drawFinderPattern(this.size - 4, 3);
412
+ this.drawFinderPattern(3, this.size - 4);
413
+ // Draw numerous alignment patterns
414
+ const alignPatPos = this.getAlignmentPatternPositions();
415
+ const numAlign = alignPatPos.length;
416
+ for (let i = 0; i < numAlign; i++) {
417
+ for (let j = 0; j < numAlign; j++) {
418
+ // Don't draw on the three finder corners
419
+ if (!((i === 0 && j === 0) || (i === 0 && j === numAlign - 1) || (i === numAlign - 1 && j === 0))) {
420
+ this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
421
+ }
422
+ }
423
+ }
424
+ // Draw configuration data
425
+ this.drawFormatBits(0); // Dummy mask value; overwritten later in the constructor
426
+ this.drawVersion();
427
+ }
428
+ // Draws two copies of the format bits (with its own error correction code)
429
+ // based on the given mask and this object's error correction level field.
430
+ drawFormatBits(mask) {
431
+ // Calculate error correction code and pack bits
432
+ const data = (this.errorCorrectionLevel.formatBits << 3) | mask; // errCorrLvl is unumber2, mask is unumber3
433
+ let rem = data;
434
+ for (let i = 0; i < 10; i++) {
435
+ rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
436
+ }
437
+ const bits = ((data << 10) | rem) ^ 0x5412; // unumber15
438
+ assert(bits >>> 15 === 0);
439
+ // Draw first copy
440
+ for (let i = 0; i <= 5; i++) {
441
+ this.setFunctionModule(8, i, getBit(bits, i));
442
+ }
443
+ this.setFunctionModule(8, 7, getBit(bits, 6));
444
+ this.setFunctionModule(8, 8, getBit(bits, 7));
445
+ this.setFunctionModule(7, 8, getBit(bits, 8));
446
+ for (let i = 9; i < 15; i++) {
447
+ this.setFunctionModule(14 - i, 8, getBit(bits, i));
448
+ }
449
+ // Draw second copy
450
+ for (let i = 0; i < 8; i++) {
451
+ this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
452
+ }
453
+ for (let i = 8; i < 15; i++) {
454
+ this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
455
+ }
456
+ this.setFunctionModule(8, this.size - 8, true); // Always dark
457
+ }
458
+ // Draws two copies of the version bits (with its own error correction code),
459
+ // based on this object's version field, iff 7 <= version <= 40.
460
+ drawVersion() {
461
+ if (this.version < 7) {
462
+ return;
463
+ }
464
+ // Calculate error correction code and pack bits
465
+ let rem = this.version; // version is unumber6, in the range [7, 40]
466
+ for (let i = 0; i < 12; i++) {
467
+ rem = (rem << 1) ^ ((rem >>> 11) * 0x1f25);
468
+ }
469
+ const bits = (this.version << 12) | rem; // unumber18
470
+ assert(bits >>> 18 === 0);
471
+ // Draw two copies
472
+ for (let i = 0; i < 18; i++) {
473
+ const color = getBit(bits, i);
474
+ const a = this.size - 11 + (i % 3);
475
+ const b = Math.floor(i / 3);
476
+ this.setFunctionModule(a, b, color);
477
+ this.setFunctionModule(b, a, color);
478
+ }
479
+ }
480
+ // Draws a 9*9 finder pattern including the border separator,
481
+ // with the center module at (x, y). Modules can be out of bounds.
482
+ drawFinderPattern(x, y) {
483
+ for (let dy = -4; dy <= 4; dy++) {
484
+ for (let dx = -4; dx <= 4; dx++) {
485
+ const dist = Math.max(Math.abs(dx), Math.abs(dy)); // Chebyshev/infinity norm
486
+ const xx = x + dx;
487
+ const yy = y + dy;
488
+ if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size) {
489
+ this.setFunctionModule(xx, yy, dist !== 2 && dist !== 4);
490
+ }
491
+ }
492
+ }
493
+ }
494
+ // Draws a 5*5 alignment pattern, with the center module
495
+ // at (x, y). All modules must be in bounds.
496
+ drawAlignmentPattern(x, y) {
497
+ for (let dy = -2; dy <= 2; dy++) {
498
+ for (let dx = -2; dx <= 2; dx++) {
499
+ this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);
500
+ }
501
+ }
502
+ }
503
+ // Sets the color of a module and marks it as a function module.
504
+ // Only used by the constructor. Coordinates must be in bounds.
505
+ setFunctionModule(x, y, isDark) {
506
+ this.modules[y][x] = isDark;
507
+ this.isFunction[y][x] = true;
508
+ }
509
+ /* -- Private helper methods for constructor: Codewords and masking --*/
510
+ // Returns a new byte string representing the given data with the appropriate error correction
511
+ // codewords appended to it, based on this object's version and error correction level.
512
+ addEccAndInterleave(data) {
513
+ const ver = this.version;
514
+ const ecl = this.errorCorrectionLevel;
515
+ if (data.length !== QrCode.getNumDataCodewords(ver, ecl)) {
516
+ throw new RangeError('Invalid argument');
517
+ }
518
+ // Calculate parameter numbers
519
+ const numBlocks = QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
520
+ const blockEccLen = QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
521
+ const rawCodewords = Math.floor(QrCode.getNumRawDataModules(ver) / 8);
522
+ const numShortBlocks = numBlocks - (rawCodewords % numBlocks);
523
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
524
+ // Split data numbero blocks and append ECC to each block
525
+ const blocks = [];
526
+ const rsDiv = QrCode.reedSolomonComputeDivisor(blockEccLen);
527
+ for (let i = 0, k = 0; i < numBlocks; i++) {
528
+ const dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
529
+ k += dat.length;
530
+ const ecc = QrCode.reedSolomonComputeRemainder(dat, rsDiv);
531
+ if (i < numShortBlocks) {
532
+ dat.push(0);
533
+ }
534
+ blocks.push(dat.concat(ecc));
535
+ }
536
+ // Interleave (not concatenate) the bytes from every block numbero a single sequence
537
+ const result = [];
538
+ for (let i = 0; i < blocks[0].length; i++) {
539
+ blocks.forEach((block, j) => {
540
+ // Skip the padding byte in short blocks
541
+ if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks) {
542
+ result.push(block[i]);
543
+ }
544
+ });
545
+ }
546
+ assert(result.length === rawCodewords);
547
+ return result;
548
+ }
549
+ // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
550
+ // data area of this QR Code. Function modules need to be marked off before this is called.
551
+ drawCodewords(data) {
552
+ if (data.length !== Math.floor(QrCode.getNumRawDataModules(this.version) / 8)) {
553
+ throw new RangeError('Invalid argument');
554
+ }
555
+ let i = 0; // Bit index numbero the data
556
+ // Do the funny zigzag scan
557
+ for (let right = this.size - 1; right >= 1; right -= 2) {
558
+ // Index of right column in each column pair
559
+ if (right === 6) {
560
+ right = 5;
561
+ }
562
+ for (let vert = 0; vert < this.size; vert++) {
563
+ // Vertical counter
564
+ for (let j = 0; j < 2; j++) {
565
+ const x = right - j; // Actual x coordinate
566
+ const upward = ((right + 1) & 2) === 0;
567
+ const y = upward ? this.size - 1 - vert : vert; // Actual y coordinate
568
+ if (!this.isFunction[y][x] && i < data.length * 8) {
569
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
570
+ i++;
571
+ }
572
+ // If this QR Code has any remainder bits (0 to 7), they were assigned as
573
+ // 0/false/light by the constructor and are left unchanged by this method
574
+ }
575
+ }
576
+ }
577
+ assert(i === data.length * 8);
578
+ }
579
+ // XORs the codeword modules in this QR Code with the given mask pattern.
580
+ // The function modules must be marked and the codeword bits must be drawn
581
+ // before masking. Due to the arithmetic of XOR, calling applyMask() with
582
+ // the same mask value a second time will undo the mask. A final well-formed
583
+ // QR Code needs exactly one (not zero, two, etc.) mask applied.
584
+ applyMask(mask) {
585
+ if (mask < 0 || mask > 7) {
586
+ throw new RangeError('Mask value out of range');
587
+ }
588
+ for (let y = 0; y < this.size; y++) {
589
+ for (let x = 0; x < this.size; x++) {
590
+ let invert;
591
+ switch (mask) {
592
+ case 0:
593
+ invert = (x + y) % 2 === 0;
594
+ break;
595
+ case 1:
596
+ invert = y % 2 === 0;
597
+ break;
598
+ case 2:
599
+ invert = x % 3 === 0;
600
+ break;
601
+ case 3:
602
+ invert = (x + y) % 3 === 0;
603
+ break;
604
+ case 4:
605
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
606
+ break;
607
+ case 5:
608
+ invert = ((x * y) % 2) + ((x * y) % 3) === 0;
609
+ break;
610
+ case 6:
611
+ invert = (((x * y) % 2) + ((x * y) % 3)) % 2 === 0;
612
+ break;
613
+ case 7:
614
+ invert = (((x + y) % 2) + ((x * y) % 3)) % 2 === 0;
615
+ break;
616
+ default:
617
+ throw new Error('Unreachable');
618
+ }
619
+ if (!this.isFunction[y][x] && invert) {
620
+ this.modules[y][x] = !this.modules[y][x];
621
+ }
622
+ }
623
+ }
624
+ }
625
+ // Calculates and returns the penalty score based on state of this QR Code's current modules.
626
+ // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
627
+ getPenaltyScore() {
628
+ let result = 0;
629
+ // Adjacent modules in row having same color, and finder-like patterns
630
+ for (let y = 0; y < this.size; y++) {
631
+ let runColor = false;
632
+ let runX = 0;
633
+ const runHistory = [0, 0, 0, 0, 0, 0, 0];
634
+ for (let x = 0; x < this.size; x++) {
635
+ if (this.modules[y][x] === runColor) {
636
+ runX++;
637
+ if (runX === 5) {
638
+ result += QrCode.PENALTY_N1;
639
+ }
640
+ else if (runX > 5) {
641
+ result++;
642
+ }
643
+ }
644
+ else {
645
+ this.finderPenaltyAddHistory(runX, runHistory);
646
+ if (!runColor) {
647
+ result += this.finderPenaltyCountPatterns(runHistory) * QrCode.PENALTY_N3;
648
+ }
649
+ runColor = this.modules[y][x];
650
+ runX = 1;
651
+ }
652
+ }
653
+ result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * QrCode.PENALTY_N3;
654
+ }
655
+ // Adjacent modules in column having same color, and finder-like patterns
656
+ for (let x = 0; x < this.size; x++) {
657
+ let runColor = false;
658
+ let runY = 0;
659
+ const runHistory = [0, 0, 0, 0, 0, 0, 0];
660
+ for (let y = 0; y < this.size; y++) {
661
+ if (this.modules[y][x] === runColor) {
662
+ runY++;
663
+ if (runY === 5) {
664
+ result += QrCode.PENALTY_N1;
665
+ }
666
+ else if (runY > 5) {
667
+ result++;
668
+ }
669
+ }
670
+ else {
671
+ this.finderPenaltyAddHistory(runY, runHistory);
672
+ if (!runColor) {
673
+ result += this.finderPenaltyCountPatterns(runHistory) * QrCode.PENALTY_N3;
674
+ }
675
+ runColor = this.modules[y][x];
676
+ runY = 1;
677
+ }
678
+ }
679
+ result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * QrCode.PENALTY_N3;
680
+ }
681
+ // 2*2 blocks of modules having same color
682
+ for (let y = 0; y < this.size - 1; y++) {
683
+ for (let x = 0; x < this.size - 1; x++) {
684
+ const color = this.modules[y][x];
685
+ if (color === this.modules[y][x + 1] &&
686
+ color === this.modules[y + 1][x] &&
687
+ color === this.modules[y + 1][x + 1]) {
688
+ result += QrCode.PENALTY_N2;
689
+ }
690
+ }
691
+ }
692
+ // Balance of dark and light modules
693
+ let dark = 0;
694
+ for (const row of this.modules) {
695
+ dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
696
+ }
697
+ const total = this.size * this.size; // Note that size is odd, so dark/total !== 1/2
698
+ // Compute the smallest numbereger k >= 0 such that (45-5k)% <= dark/total <= (55+5k)%
699
+ const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
700
+ assert(k >= 0 && k <= 9);
701
+ result += k * QrCode.PENALTY_N4;
702
+ assert(result >= 0 && result <= 2568888); // Non-tight upper bound based on default values of PENALTY_N1, ..., N4
703
+ return result;
704
+ }
705
+ /* -- Private helper functions --*/
706
+ // Returns an ascending list of positions of alignment patterns for this version number.
707
+ // Each position is in the range [0,177), and are used on both the x and y axes.
708
+ // This could be implemented as lookup table of 40 variable-length lists of numberegers.
709
+ getAlignmentPatternPositions() {
710
+ if (this.version === 1) {
711
+ return [];
712
+ }
713
+ const numAlign = Math.floor(this.version / 7) + 2;
714
+ const step = this.version === 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
715
+ const result = [6];
716
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step) {
717
+ result.splice(1, 0, pos);
718
+ }
719
+ return result;
720
+ }
721
+ // Returns the number of data bits that can be stored in a QR Code of the given version number, after
722
+ // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
723
+ // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
724
+ static getNumRawDataModules(ver) {
725
+ if (ver < QrCode.MIN_VERSION || ver > QrCode.MAX_VERSION) {
726
+ throw new RangeError('Version number out of range');
727
+ }
728
+ let result = (16 * ver + 128) * ver + 64;
729
+ if (ver >= 2) {
730
+ const numAlign = Math.floor(ver / 7) + 2;
731
+ result -= (25 * numAlign - 10) * numAlign - 55;
732
+ if (ver >= 7) {
733
+ result -= 36;
734
+ }
735
+ }
736
+ assert(result >= 208 && result <= 29648);
737
+ return result;
738
+ }
739
+ // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
740
+ // QR Code of the given version number and error correction level, with remainder bits discarded.
741
+ // This stateless pure function could be implemented as a (40*4)-cell lookup table.
742
+ static getNumDataCodewords(ver, ecl) {
743
+ return (Math.floor(QrCode.getNumRawDataModules(ver) / 8) -
744
+ QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver]);
745
+ }
746
+ // Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
747
+ // implemented as a lookup table over all possible parameter values, instead of as an algorithm.
748
+ static reedSolomonComputeDivisor(degree) {
749
+ if (degree < 1 || degree > 255) {
750
+ throw new RangeError('Degree out of range');
751
+ }
752
+ // Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1.
753
+ // For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the unumber8 array [255, 8, 93].
754
+ const result = [];
755
+ for (let i = 0; i < degree - 1; i++) {
756
+ result.push(0);
757
+ }
758
+ result.push(1); // Start off with the monomial x^0
759
+ // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
760
+ // and drop the highest monomial term which is always 1x^degree.
761
+ // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
762
+ let root = 1;
763
+ for (let i = 0; i < degree; i++) {
764
+ // Multiply the current product by (x - r^i)
765
+ for (let j = 0; j < result.length; j++) {
766
+ result[j] = QrCode.reedSolomonMultiply(result[j], root);
767
+ if (j + 1 < result.length) {
768
+ result[j] ^= result[j + 1];
769
+ }
770
+ }
771
+ root = QrCode.reedSolomonMultiply(root, 0x02);
772
+ }
773
+ return result;
774
+ }
775
+ // Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
776
+ static reedSolomonComputeRemainder(data, divisor) {
777
+ const result = divisor.map(() => 0);
778
+ for (const b of data) {
779
+ // Polynomial division
780
+ const factor = b ^ result.shift();
781
+ result.push(0);
782
+ divisor.forEach((coef, i) => {
783
+ result[i] ^= QrCode.reedSolomonMultiply(coef, factor);
784
+ });
785
+ }
786
+ return result;
787
+ }
788
+ // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
789
+ // are unsigned 8-bit numberegers. This could be implemented as a lookup table of 256*256 entries of unumber8.
790
+ static reedSolomonMultiply(x, y) {
791
+ if (x >>> 8 !== 0 || y >>> 8 !== 0) {
792
+ throw new RangeError('Byte out of range');
793
+ }
794
+ // Russian peasant multiplication
795
+ let z = 0;
796
+ for (let i = 7; i >= 0; i--) {
797
+ z = (z << 1) ^ ((z >>> 7) * 0x11d);
798
+ z ^= ((y >>> i) & 1) * x;
799
+ }
800
+ assert(z >>> 8 === 0);
801
+ return z;
802
+ }
803
+ // Can only be called immediately after a light run is added, and
804
+ // returns either 0, 1, or 2. A helper function for getPenaltyScore().
805
+ finderPenaltyCountPatterns(runHistory) {
806
+ const n = runHistory[1];
807
+ assert(n <= this.size * 3);
808
+ const core = n > 0 && runHistory[2] === n && runHistory[3] === n * 3 && runHistory[4] === n && runHistory[5] === n;
809
+ return ((core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) +
810
+ (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0));
811
+ }
812
+ // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
813
+ finderPenaltyTerminateAndCount(currentRunColor, oriCurrentRunLength, runHistory) {
814
+ let currentRunLength = oriCurrentRunLength;
815
+ if (currentRunColor) {
816
+ // Terminate dark run
817
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
818
+ currentRunLength = 0;
819
+ }
820
+ currentRunLength += this.size; // Add light border to final run
821
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
822
+ return this.finderPenaltyCountPatterns(runHistory);
823
+ }
824
+ // Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
825
+ finderPenaltyAddHistory(oriCurrentRunLength, runHistory) {
826
+ let currentRunLength = oriCurrentRunLength;
827
+ if (runHistory[0] === 0) {
828
+ currentRunLength += this.size; // Add light border to initial run
829
+ }
830
+ runHistory.pop();
831
+ runHistory.unshift(currentRunLength);
832
+ }
833
+ }
834
+ /* -- Constants and tables --*/
835
+ // The minimum version number supported in the QR Code Model 2 standard.
836
+ QrCode.MIN_VERSION = 1;
837
+ // The maximum version number supported in the QR Code Model 2 standard.
838
+ QrCode.MAX_VERSION = 40;
839
+ // For use in getPenaltyScore(), when evaluating which mask is best.
840
+ QrCode.PENALTY_N1 = 3;
841
+ QrCode.PENALTY_N2 = 3;
842
+ QrCode.PENALTY_N3 = 40;
843
+ QrCode.PENALTY_N4 = 10;
844
+ QrCode.ECC_CODEWORDS_PER_BLOCK = [
845
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
846
+ // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
847
+ [
848
+ -1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30,
849
+ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
850
+ ],
851
+ [
852
+ -1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28,
853
+ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
854
+ ],
855
+ [
856
+ -1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30,
857
+ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
858
+ ],
859
+ [
860
+ -1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30,
861
+ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
862
+ ], // High
863
+ ];
864
+ QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
865
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
866
+ // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
867
+ [
868
+ -1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18,
869
+ 19, 19, 20, 21, 22, 24, 25,
870
+ ],
871
+ [
872
+ -1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31,
873
+ 33, 35, 37, 38, 40, 43, 45, 47, 49,
874
+ ],
875
+ [
876
+ -1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40,
877
+ 43, 45, 48, 51, 53, 56, 59, 62, 65, 68,
878
+ ],
879
+ [
880
+ -1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48,
881
+ 51, 54, 57, 60, 63, 66, 70, 74, 77, 81,
882
+ ], // High
883
+ ];
884
+