@indielayer/ui 1.5.1 → 1.6.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 (253) hide show
  1. package/README.md +1 -1
  2. package/docs/components/common/DocumentPage.vue +0 -30
  3. package/docs/components/menu/DocsMenu.vue +2 -0
  4. package/docs/components/toolbar/Toolbar.vue +2 -9
  5. package/docs/pages/component/datepicker/index.vue +35 -0
  6. package/docs/pages/component/datepicker/usage.vue +22 -0
  7. package/docs/pages/component/form/usage.vue +29 -19
  8. package/docs/pages/component/menu/usage.vue +7 -3
  9. package/docs/pages/component/qrCode/index.vue +25 -0
  10. package/docs/pages/component/qrCode/usage.vue +20 -0
  11. package/docs/pages/component/slider/usage.vue +8 -10
  12. package/docs/pages/index.vue +9 -19
  13. package/exports/nuxt.plugin.js +9 -2
  14. package/lib/components/accordion/AccordionItem.vue.js +25 -24
  15. package/lib/components/accordion/theme/AccordionItem.base.theme.js +7 -7
  16. package/lib/components/alert/Alert.vue2.js +4 -3
  17. package/lib/components/button/Button.vue.d.ts +3 -3
  18. package/lib/components/button/Button.vue.js +2 -2
  19. package/lib/components/button/Button.vue2.js +10 -10
  20. package/lib/components/carousel/Carousel.vue.d.ts +8 -2
  21. package/lib/components/carousel/Carousel.vue.js +51 -48
  22. package/lib/components/checkbox/theme/Checkbox.base.theme.js +35 -35
  23. package/lib/components/datepicker/Datepicker.vue.d.ts +1886 -0
  24. package/lib/components/datepicker/Datepicker.vue.js +328 -0
  25. package/lib/components/datepicker/Datepicker.vue2.js +4 -0
  26. package/lib/components/datepicker/Datepicker.vue3.js +5 -0
  27. package/lib/components/datepicker/__tests__/Datepicker.spec.d.ts +1 -0
  28. package/lib/components/datepicker/index.d.ts +2 -0
  29. package/lib/components/datepicker/theme/Datepicker.base.theme.d.ts +3 -0
  30. package/lib/components/datepicker/theme/Datepicker.base.theme.js +65 -0
  31. package/lib/components/datepicker/theme/Datepicker.carbon.theme.d.ts +3 -0
  32. package/lib/components/datepicker/theme/Datepicker.carbon.theme.js +5 -0
  33. package/lib/components/drawer/Drawer.vue.js +1 -1
  34. package/lib/components/drawer/theme/Drawer.base.theme.js +1 -1
  35. package/lib/components/formGroup/FormGroup.vue.js +42 -36
  36. package/lib/components/index.d.ts +2 -0
  37. package/lib/components/index.js +99 -94
  38. package/lib/components/inputFooter/theme/InputFooter.base.theme.js +1 -1
  39. package/lib/components/label/theme/Label.base.theme.js +1 -1
  40. package/lib/components/menu/Menu.vue.d.ts +4 -0
  41. package/lib/components/menu/Menu.vue.js +40 -34
  42. package/lib/components/menu/MenuItem.vue.d.ts +4 -0
  43. package/lib/components/menu/MenuItem.vue.js +1 -1
  44. package/lib/components/menu/MenuItem.vue2.js +43 -39
  45. package/lib/components/menu/theme/MenuItem.base.theme.js +1 -1
  46. package/lib/components/notifications/Notifications.vue.js +1 -0
  47. package/lib/components/popover/Popover.vue.d.ts +7 -25
  48. package/lib/components/popover/Popover.vue.js +12 -12
  49. package/lib/components/qrCode/QrCode.vue.d.ts +68 -0
  50. package/lib/components/qrCode/QrCode.vue.js +93 -0
  51. package/lib/components/qrCode/QrCode.vue2.js +4 -0
  52. package/lib/components/qrCode/__tests__/QrCode.spec.d.ts +1 -0
  53. package/lib/components/qrCode/index.d.ts +2 -0
  54. package/lib/components/qrCode/qrcodegen.d.ts +94 -0
  55. package/lib/components/qrCode/qrcodegen.js +571 -0
  56. package/lib/components/qrCode/theme/QrCode.base.theme.d.ts +3 -0
  57. package/lib/components/qrCode/theme/QrCode.base.theme.js +8 -0
  58. package/lib/components/qrCode/theme/QrCode.carbon.theme.d.ts +3 -0
  59. package/lib/components/qrCode/theme/QrCode.carbon.theme.js +5 -0
  60. package/lib/components/radio/theme/Radio.base.theme.js +27 -27
  61. package/lib/components/scroll/Scroll.vue2.js +4 -4
  62. package/lib/components/slider/Slider.vue.d.ts +31 -31
  63. package/lib/components/slider/Slider.vue.js +5 -146
  64. package/lib/components/slider/Slider.vue2.js +101 -2
  65. package/lib/components/slider/Slider.vue3.js +4 -0
  66. package/lib/components/slider/theme/Slider.base.theme.js +14 -10
  67. package/lib/components/slider/theme/Slider.carbon.theme.js +3 -14
  68. package/lib/components/stepper/Stepper.vue.js +35 -34
  69. package/lib/components/tab/Tab.vue.js +7 -6
  70. package/lib/components/table/Table.vue.js +16 -15
  71. package/lib/components/tooltip/Tooltip.vue.js +1 -1
  72. package/lib/create.d.ts +5 -1
  73. package/lib/create.js +18 -15
  74. package/lib/index.js +117 -113
  75. package/lib/index.umd.js +40 -3
  76. package/lib/node_modules/.pnpm/@vuepic_vue-datepicker@8.0.0_vue@3.3.9/node_modules/@vuepic/vue-datepicker/dist/main.css.js +4 -0
  77. package/lib/node_modules/.pnpm/@vuepic_vue-datepicker@8.0.0_vue@3.3.9/node_modules/@vuepic/vue-datepicker/dist/vue-datepicker.js +5011 -0
  78. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/_lib/addLeadingZeros.js +7 -0
  79. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/_lib/defaultOptions.js +7 -0
  80. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/_lib/format/formatters.js +518 -0
  81. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/_lib/format/lightFormatters.js +59 -0
  82. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/_lib/format/longFormatters.js +52 -0
  83. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js +18 -0
  84. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/_lib/protectedTokens.js +21 -0
  85. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/add.js +20 -0
  86. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/addDays.js +10 -0
  87. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/addMonths.js +21 -0
  88. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/addQuarters.js +9 -0
  89. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/addYears.js +8 -0
  90. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/constants.js +8 -0
  91. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/constructFrom.js +7 -0
  92. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/differenceInCalendarDays.js +11 -0
  93. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/eachDayOfInterval.js +19 -0
  94. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/eachQuarterOfInterval.js +20 -0
  95. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/endOfQuarter.js +9 -0
  96. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/endOfWeek.js +11 -0
  97. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/endOfYear.js +9 -0
  98. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/format.js +60 -0
  99. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getDay.js +8 -0
  100. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getDayOfYear.js +11 -0
  101. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getDaysInMonth.js +10 -0
  102. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getDefaultOptions.js +8 -0
  103. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getHours.js +8 -0
  104. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getISODay.js +9 -0
  105. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getISOWeek.js +12 -0
  106. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getISOWeekYear.js +15 -0
  107. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getMinutes.js +8 -0
  108. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getMonth.js +8 -0
  109. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getQuarter.js +9 -0
  110. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getSeconds.js +8 -0
  111. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getWeek.js +12 -0
  112. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getWeekYear.js +17 -0
  113. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/getYear.js +8 -0
  114. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/isAfter.js +9 -0
  115. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/isBefore.js +9 -0
  116. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/isDate.js +7 -0
  117. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/isEqual.js +9 -0
  118. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/isSameQuarter.js +9 -0
  119. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/isValid.js +12 -0
  120. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/locale/_lib/buildFormatLongFn.js +9 -0
  121. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/locale/_lib/buildLocalizeFn.js +18 -0
  122. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/locale/_lib/buildMatchFn.js +31 -0
  123. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js +17 -0
  124. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/locale/en-US/_lib/formatDistance.js +70 -0
  125. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/locale/en-US/_lib/formatLong.js +33 -0
  126. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/locale/en-US/_lib/formatRelative.js +11 -0
  127. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/locale/en-US/_lib/localize.js +155 -0
  128. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/locale/en-US/_lib/match.js +110 -0
  129. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/locale/en-US.js +21 -0
  130. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/Parser.js +22 -0
  131. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/Setter.js +40 -0
  132. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/constants.js +49 -0
  133. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/AMPMMidnightParser.js +49 -0
  134. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/AMPMParser.js +49 -0
  135. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/DateParser.js +61 -0
  136. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/DayOfYearParser.js +51 -0
  137. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/DayParser.js +45 -0
  138. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/DayPeriodParser.js +49 -0
  139. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/EraParser.js +30 -0
  140. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/ExtendedYearParser.js +21 -0
  141. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/FractionOfSecondParser.js +22 -0
  142. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/Hour0To11Parser.js +32 -0
  143. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/Hour0to23Parser.js +32 -0
  144. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/Hour1To24Parser.js +33 -0
  145. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/Hour1to12Parser.js +33 -0
  146. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/ISODayParser.js +99 -0
  147. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/ISOTimezoneParser.js +48 -0
  148. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/ISOTimezoneWithZParser.js +48 -0
  149. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/ISOWeekParser.js +49 -0
  150. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/ISOWeekYearParser.js +40 -0
  151. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/LocalDayParser.js +74 -0
  152. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/LocalWeekParser.js +48 -0
  153. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/LocalWeekYearParser.js +69 -0
  154. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/MinuteParser.js +32 -0
  155. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/MonthParser.js +71 -0
  156. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/QuarterParser.js +70 -0
  157. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/SecondParser.js +32 -0
  158. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/StandAloneLocalDayParser.js +74 -0
  159. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/StandAloneMonthParser.js +71 -0
  160. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/StandAloneQuarterParser.js +70 -0
  161. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/TimestampMillisecondsParser.js +22 -0
  162. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/TimestampSecondsParser.js +22 -0
  163. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers/YearParser.js +49 -0
  164. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/parsers.js +67 -0
  165. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse/_lib/utils.js +103 -0
  166. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parse.js +90 -0
  167. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/parseISO.js +128 -0
  168. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/set.js +11 -0
  169. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/setDay.js +12 -0
  170. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/setHours.js +9 -0
  171. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/setISODay.js +11 -0
  172. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/setISOWeek.js +10 -0
  173. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/setMilliseconds.js +9 -0
  174. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/setMinutes.js +9 -0
  175. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/setMonth.js +13 -0
  176. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/setSeconds.js +9 -0
  177. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/setWeek.js +10 -0
  178. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/setYear.js +10 -0
  179. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/startOfDay.js +9 -0
  180. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/startOfISOWeek.js +8 -0
  181. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/startOfISOWeekYear.js +11 -0
  182. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/startOfQuarter.js +9 -0
  183. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/startOfWeek.js +11 -0
  184. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/startOfWeekYear.js +13 -0
  185. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/startOfYear.js +10 -0
  186. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/sub.js +19 -0
  187. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/subDays.js +8 -0
  188. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/subMonths.js +8 -0
  189. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/subYears.js +8 -0
  190. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/toDate.js +8 -0
  191. package/lib/node_modules/.pnpm/date-fns@3.3.1/node_modules/date-fns/transpose.js +18 -0
  192. package/lib/node_modules/.pnpm/{floating-vue@5.2.0_vue@3.3.9 → floating-vue@5.2.2_vue@3.3.9}/node_modules/floating-vue/dist/floating-vue.js +208 -183
  193. package/lib/nuxt.plugin.js +9 -2
  194. package/lib/theme.d.ts +3 -1
  195. package/lib/themes/base/components.d.ts +2 -0
  196. package/lib/themes/base/components.js +82 -78
  197. package/lib/themes/base/index.js +2 -2
  198. package/lib/themes/base/styles.d.ts +2 -0
  199. package/{src/themes/base/styles.css → lib/themes/base/styles.js} +5 -1
  200. package/lib/themes/carbon/components.d.ts +2 -0
  201. package/lib/themes/carbon/components.js +82 -78
  202. package/lib/themes/carbon/index.js +2 -2
  203. package/lib/themes/carbon/styles.d.ts +2 -0
  204. package/lib/themes/carbon/{styles.css.js → styles.js} +2 -1
  205. package/lib/version.d.ts +1 -1
  206. package/lib/version.js +1 -1
  207. package/package.json +3 -2
  208. package/src/components/accordion/AccordionItem.vue +1 -0
  209. package/src/components/accordion/theme/AccordionItem.base.theme.ts +2 -2
  210. package/src/components/alert/Alert.vue +1 -1
  211. package/src/components/button/Button.vue +1 -1
  212. package/src/components/carousel/Carousel.vue +8 -3
  213. package/src/components/checkbox/theme/Checkbox.base.theme.ts +6 -4
  214. package/src/components/datepicker/Datepicker.vue +414 -0
  215. package/src/components/datepicker/__tests__/Datepicker.spec.ts +11 -0
  216. package/src/components/datepicker/index.ts +2 -0
  217. package/src/components/datepicker/theme/Datepicker.base.theme.ts +72 -0
  218. package/src/components/datepicker/theme/Datepicker.carbon.theme.ts +7 -0
  219. package/src/components/drawer/Drawer.vue +1 -1
  220. package/src/components/drawer/theme/Drawer.base.theme.ts +1 -1
  221. package/src/components/formGroup/FormGroup.vue +5 -0
  222. package/src/components/index.ts +2 -0
  223. package/src/components/inputFooter/theme/InputFooter.base.theme.ts +1 -1
  224. package/src/components/label/theme/Label.base.theme.ts +1 -1
  225. package/src/components/menu/Menu.vue +6 -0
  226. package/src/components/menu/MenuItem.vue +2 -1
  227. package/src/components/menu/theme/MenuItem.base.theme.ts +1 -1
  228. package/src/components/notifications/Notifications.vue +1 -0
  229. package/src/components/popover/Popover.vue +2 -2
  230. package/src/components/qrCode/QrCode.vue +120 -0
  231. package/src/components/qrCode/__tests__/QrCode.spec.ts +14 -0
  232. package/src/components/qrCode/index.ts +2 -0
  233. package/src/components/qrCode/qrcodegen.ts +991 -0
  234. package/src/components/qrCode/theme/QrCode.base.theme.ts +9 -0
  235. package/src/components/qrCode/theme/QrCode.carbon.theme.ts +7 -0
  236. package/src/components/radio/theme/Radio.base.theme.ts +5 -3
  237. package/src/components/scroll/Scroll.vue +1 -1
  238. package/src/components/slider/Slider.vue +63 -137
  239. package/src/components/slider/theme/Slider.base.theme.ts +10 -5
  240. package/src/components/slider/theme/Slider.carbon.theme.ts +2 -16
  241. package/src/components/stepper/Stepper.vue +1 -0
  242. package/src/components/tab/Tab.vue +1 -0
  243. package/src/components/table/Table.vue +1 -1
  244. package/src/create.ts +11 -4
  245. package/src/theme.ts +4 -0
  246. package/src/themes/base/components.ts +2 -0
  247. package/src/themes/base/index.ts +2 -2
  248. package/{lib/themes/base/styles.css.js → src/themes/base/styles.ts} +2 -5
  249. package/src/themes/carbon/components.ts +2 -0
  250. package/src/themes/carbon/index.ts +2 -2
  251. package/src/themes/carbon/{styles.css → styles.ts} +2 -0
  252. package/src/version.ts +1 -1
  253. package/volar.d.ts +2 -0
@@ -0,0 +1,991 @@
1
+ /* eslint-disable */
2
+ /*
3
+ * QR Code generator library (TypeScript)
4
+ *
5
+ * Copyright (c) Project Nayuki. (MIT License)
6
+ * https://www.nayuki.io/page/qr-code-generator-library
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
9
+ * this software and associated documentation files (the "Software"), to deal in
10
+ * the Software without restriction, including without limitation the rights to
11
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12
+ * the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ * - The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ * - The Software is provided "as is", without warranty of any kind, express or
17
+ * implied, including but not limited to the warranties of merchantability,
18
+ * fitness for a particular purpose and noninfringement. In no event shall the
19
+ * authors or copyright holders be liable for any claim, damages or other
20
+ * liability, whether in an action of contract, tort or otherwise, arising from,
21
+ * out of or in connection with the Software or the use or other dealings in the
22
+ * Software.
23
+ */
24
+
25
+ namespace qrcodegen {
26
+
27
+ type bit = number;
28
+ type byte = number;
29
+ type int = number;
30
+
31
+
32
+ /*---- QR Code symbol class ----*/
33
+
34
+ /*
35
+ * A QR Code symbol, which is a type of two-dimension barcode.
36
+ * Invented by Denso Wave and described in the ISO/IEC 18004 standard.
37
+ * Instances of this class represent an immutable square grid of dark and light cells.
38
+ * The class provides static factory functions to create a QR Code from text or binary data.
39
+ * The class covers the QR Code Model 2 specification, supporting all versions (sizes)
40
+ * from 1 to 40, all 4 error correction levels, and 4 character encoding modes.
41
+ *
42
+ * Ways to create a QR Code object:
43
+ * - High level: Take the payload data and call QrCode.encodeText() or QrCode.encodeBinary().
44
+ * - Mid level: Custom-make the list of segments and call QrCode.encodeSegments().
45
+ * - Low level: Custom-make the array of data codeword bytes (including
46
+ * segment headers and final padding, excluding error correction codewords),
47
+ * supply the appropriate version number, and call the QrCode() constructor.
48
+ * (Note that all ways require supplying the desired error correction level.)
49
+ */
50
+ export class QrCode {
51
+
52
+ /*-- Static factory functions (high level) --*/
53
+
54
+ // Returns a QR Code representing the given Unicode text string at the given error correction level.
55
+ // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
56
+ // Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
57
+ // QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
58
+ // ecl argument if it can be done without increasing the version.
59
+ public static encodeText(text: string, ecl: QrCode.Ecc): QrCode {
60
+ const segs: Array<QrSegment> = qrcodegen.QrSegment.makeSegments(text);
61
+ return QrCode.encodeSegments(segs, ecl);
62
+ }
63
+
64
+
65
+ // Returns a QR Code representing the given binary data at the given error correction level.
66
+ // This function always encodes using the binary segment mode, not any text mode. The maximum number of
67
+ // bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
68
+ // The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
69
+ public static encodeBinary(data: Readonly<Array<byte>>, ecl: QrCode.Ecc): QrCode {
70
+ const seg: QrSegment = qrcodegen.QrSegment.makeBytes(data);
71
+ return QrCode.encodeSegments([seg], ecl);
72
+ }
73
+
74
+
75
+ /*-- Static factory functions (mid level) --*/
76
+
77
+ // Returns a QR Code representing the given segments with the given encoding parameters.
78
+ // The smallest possible QR Code version within the given range is automatically
79
+ // chosen for the output. Iff boostEcl is true, then the ECC level of the result
80
+ // may be higher than the ecl argument if it can be done without increasing the
81
+ // version. The mask number is either between 0 to 7 (inclusive) to force that
82
+ // mask, or -1 to automatically choose an appropriate mask (which may be slow).
83
+ // This function allows the user to create a custom sequence of segments that switches
84
+ // between modes (such as alphanumeric and byte) to encode text in less space.
85
+ // This is a mid-level API; the high-level API is encodeText() and encodeBinary().
86
+ public static encodeSegments(segs: Readonly<Array<QrSegment>>, ecl: QrCode.Ecc,
87
+ minVersion: int = 1, maxVersion: int = 40,
88
+ mask: int = -1, boostEcl: boolean = true): QrCode {
89
+
90
+ if (!(QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= QrCode.MAX_VERSION)
91
+ || mask < -1 || mask > 7)
92
+ throw new RangeError("Invalid value");
93
+
94
+ // Find the minimal version number to use
95
+ let version: int;
96
+ let dataUsedBits: int;
97
+ for (version = minVersion; ; version++) {
98
+ const dataCapacityBits: int = QrCode.getNumDataCodewords(version, ecl) * 8; // Number of data bits available
99
+ const usedBits: number = QrSegment.getTotalBits(segs, version);
100
+ if (usedBits <= dataCapacityBits) {
101
+ dataUsedBits = usedBits;
102
+ break; // This version number is found to be suitable
103
+ }
104
+ if (version >= maxVersion) // All versions in the range could not fit the given data
105
+ throw new RangeError("Data too long");
106
+ }
107
+
108
+ // Increase the error correction level while the data still fits in the current version number
109
+ for (const newEcl of [QrCode.Ecc.MEDIUM, QrCode.Ecc.QUARTILE, QrCode.Ecc.HIGH]) { // From low to high
110
+ if (boostEcl && dataUsedBits <= QrCode.getNumDataCodewords(version, newEcl) * 8)
111
+ ecl = newEcl;
112
+ }
113
+
114
+ // Concatenate all segments to create the data bit string
115
+ let bb: Array<bit> = []
116
+ for (const seg of segs) {
117
+ appendBits(seg.mode.modeBits, 4, bb);
118
+ appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
119
+ for (const b of seg.getData())
120
+ bb.push(b);
121
+ }
122
+ assert(bb.length == dataUsedBits);
123
+
124
+ // Add terminator and pad up to a byte if applicable
125
+ const dataCapacityBits: int = QrCode.getNumDataCodewords(version, ecl) * 8;
126
+ assert(bb.length <= dataCapacityBits);
127
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
128
+ appendBits(0, (8 - bb.length % 8) % 8, bb);
129
+ assert(bb.length % 8 == 0);
130
+
131
+ // Pad with alternating bytes until data capacity is reached
132
+ for (let padByte = 0xEC; bb.length < dataCapacityBits; padByte ^= 0xEC ^ 0x11)
133
+ appendBits(padByte, 8, bb);
134
+
135
+ // Pack bits into bytes in big endian
136
+ let dataCodewords: Array<byte> = [];
137
+ while (dataCodewords.length * 8 < bb.length)
138
+ dataCodewords.push(0);
139
+ bb.forEach((b: bit, i: int) =>
140
+ dataCodewords[i >>> 3] |= b << (7 - (i & 7)));
141
+
142
+ // Create the QR Code object
143
+ return new QrCode(version, ecl, dataCodewords, mask);
144
+ }
145
+
146
+
147
+ /*-- Fields --*/
148
+
149
+ // The width and height of this QR Code, measured in modules, between
150
+ // 21 and 177 (inclusive). This is equal to version * 4 + 17.
151
+ public readonly size: int;
152
+
153
+ // The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
154
+ // Even if a QR Code is created with automatic masking requested (mask = -1),
155
+ // the resulting object still has a mask value between 0 and 7.
156
+ public readonly mask: int;
157
+
158
+ // The modules of this QR Code (false = light, true = dark).
159
+ // Immutable after constructor finishes. Accessed through getModule().
160
+ private readonly modules : Array<Array<boolean>> = [];
161
+
162
+ // Indicates function modules that are not subjected to masking. Discarded when constructor finishes.
163
+ private readonly isFunction: Array<Array<boolean>> = [];
164
+
165
+
166
+ /*-- Constructor (low level) and fields --*/
167
+
168
+ // Creates a new QR Code with the given version number,
169
+ // error correction level, data codeword bytes, and mask number.
170
+ // This is a low-level API that most users should not use directly.
171
+ // A mid-level API is the encodeSegments() function.
172
+ public constructor(
173
+ // The version number of this QR Code, which is between 1 and 40 (inclusive).
174
+ // This determines the size of this barcode.
175
+ public readonly version: int,
176
+
177
+ // The error correction level used in this QR Code.
178
+ public readonly errorCorrectionLevel: QrCode.Ecc,
179
+
180
+ dataCodewords: Readonly<Array<byte>>,
181
+
182
+ msk: int) {
183
+
184
+ // Check scalar arguments
185
+ if (version < QrCode.MIN_VERSION || version > QrCode.MAX_VERSION)
186
+ throw new RangeError("Version value out of range");
187
+ if (msk < -1 || msk > 7)
188
+ throw new RangeError("Mask value out of range");
189
+ this.size = version * 4 + 17;
190
+
191
+ // Initialize both grids to be size*size arrays of Boolean false
192
+ let row: Array<boolean> = [];
193
+ for (let i = 0; i < this.size; i++)
194
+ row.push(false);
195
+ for (let i = 0; i < this.size; i++) {
196
+ this.modules .push(row.slice()); // Initially all light
197
+ this.isFunction.push(row.slice());
198
+ }
199
+
200
+ // Compute ECC, draw modules
201
+ this.drawFunctionPatterns();
202
+ const allCodewords: Array<byte> = this.addEccAndInterleave(dataCodewords);
203
+ this.drawCodewords(allCodewords);
204
+
205
+ // Do masking
206
+ if (msk == -1) { // Automatically choose best mask
207
+ let minPenalty: int = 1000000000;
208
+ for (let i = 0; i < 8; i++) {
209
+ this.applyMask(i);
210
+ this.drawFormatBits(i);
211
+ const penalty: int = this.getPenaltyScore();
212
+ if (penalty < minPenalty) {
213
+ msk = i;
214
+ minPenalty = penalty;
215
+ }
216
+ this.applyMask(i); // Undoes the mask due to XOR
217
+ }
218
+ }
219
+ assert(0 <= msk && msk <= 7);
220
+ this.mask = msk;
221
+ this.applyMask(msk); // Apply the final choice of mask
222
+ this.drawFormatBits(msk); // Overwrite old format bits
223
+
224
+ this.isFunction = [];
225
+ }
226
+
227
+
228
+ /*-- Accessor methods --*/
229
+
230
+ // Returns the color of the module (pixel) at the given coordinates, which is false
231
+ // for light or true for dark. The top left corner has the coordinates (x=0, y=0).
232
+ // If the given coordinates are out of bounds, then false (light) is returned.
233
+ public getModule(x: int, y: int): boolean {
234
+ return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
235
+ }
236
+
237
+
238
+ /*-- Private helper methods for constructor: Drawing function modules --*/
239
+
240
+ // Reads this object's version field, and draws and marks all function modules.
241
+ private drawFunctionPatterns(): void {
242
+ // Draw horizontal and vertical timing patterns
243
+ for (let i = 0; i < this.size; i++) {
244
+ this.setFunctionModule(6, i, i % 2 == 0);
245
+ this.setFunctionModule(i, 6, i % 2 == 0);
246
+ }
247
+
248
+ // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
249
+ this.drawFinderPattern(3, 3);
250
+ this.drawFinderPattern(this.size - 4, 3);
251
+ this.drawFinderPattern(3, this.size - 4);
252
+
253
+ // Draw numerous alignment patterns
254
+ const alignPatPos: Array<int> = this.getAlignmentPatternPositions();
255
+ const numAlign: int = alignPatPos.length;
256
+ for (let i = 0; i < numAlign; i++) {
257
+ for (let j = 0; j < numAlign; j++) {
258
+ // Don't draw on the three finder corners
259
+ if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
260
+ this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
261
+ }
262
+ }
263
+
264
+ // Draw configuration data
265
+ this.drawFormatBits(0); // Dummy mask value; overwritten later in the constructor
266
+ this.drawVersion();
267
+ }
268
+
269
+
270
+ // Draws two copies of the format bits (with its own error correction code)
271
+ // based on the given mask and this object's error correction level field.
272
+ private drawFormatBits(mask: int): void {
273
+ // Calculate error correction code and pack bits
274
+ const data: int = this.errorCorrectionLevel.formatBits << 3 | mask; // errCorrLvl is uint2, mask is uint3
275
+ let rem: int = data;
276
+ for (let i = 0; i < 10; i++)
277
+ rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
278
+ const bits = (data << 10 | rem) ^ 0x5412; // uint15
279
+ assert(bits >>> 15 == 0);
280
+
281
+ // Draw first copy
282
+ for (let i = 0; i <= 5; i++)
283
+ this.setFunctionModule(8, i, getBit(bits, i));
284
+ this.setFunctionModule(8, 7, getBit(bits, 6));
285
+ this.setFunctionModule(8, 8, getBit(bits, 7));
286
+ this.setFunctionModule(7, 8, getBit(bits, 8));
287
+ for (let i = 9; i < 15; i++)
288
+ this.setFunctionModule(14 - i, 8, getBit(bits, i));
289
+
290
+ // Draw second copy
291
+ for (let i = 0; i < 8; i++)
292
+ this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
293
+ for (let i = 8; i < 15; i++)
294
+ this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
295
+ this.setFunctionModule(8, this.size - 8, true); // Always dark
296
+ }
297
+
298
+
299
+ // Draws two copies of the version bits (with its own error correction code),
300
+ // based on this object's version field, iff 7 <= version <= 40.
301
+ private drawVersion(): void {
302
+ if (this.version < 7)
303
+ return;
304
+
305
+ // Calculate error correction code and pack bits
306
+ let rem: int = this.version; // version is uint6, in the range [7, 40]
307
+ for (let i = 0; i < 12; i++)
308
+ rem = (rem << 1) ^ ((rem >>> 11) * 0x1F25);
309
+ const bits: int = this.version << 12 | rem; // uint18
310
+ assert(bits >>> 18 == 0);
311
+
312
+ // Draw two copies
313
+ for (let i = 0; i < 18; i++) {
314
+ const color: boolean = getBit(bits, i);
315
+ const a: int = this.size - 11 + i % 3;
316
+ const b: int = Math.floor(i / 3);
317
+ this.setFunctionModule(a, b, color);
318
+ this.setFunctionModule(b, a, color);
319
+ }
320
+ }
321
+
322
+
323
+ // Draws a 9*9 finder pattern including the border separator,
324
+ // with the center module at (x, y). Modules can be out of bounds.
325
+ private drawFinderPattern(x: int, y: int): void {
326
+ for (let dy = -4; dy <= 4; dy++) {
327
+ for (let dx = -4; dx <= 4; dx++) {
328
+ const dist: int = Math.max(Math.abs(dx), Math.abs(dy)); // Chebyshev/infinity norm
329
+ const xx: int = x + dx;
330
+ const yy: int = y + dy;
331
+ if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size)
332
+ this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
333
+ }
334
+ }
335
+ }
336
+
337
+
338
+ // Draws a 5*5 alignment pattern, with the center module
339
+ // at (x, y). All modules must be in bounds.
340
+ private drawAlignmentPattern(x: int, y: int): void {
341
+ for (let dy = -2; dy <= 2; dy++) {
342
+ for (let dx = -2; dx <= 2; dx++)
343
+ this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
344
+ }
345
+ }
346
+
347
+
348
+ // Sets the color of a module and marks it as a function module.
349
+ // Only used by the constructor. Coordinates must be in bounds.
350
+ private setFunctionModule(x: int, y: int, isDark: boolean): void {
351
+ this.modules[y][x] = isDark;
352
+ this.isFunction[y][x] = true;
353
+ }
354
+
355
+
356
+ /*-- Private helper methods for constructor: Codewords and masking --*/
357
+
358
+ // Returns a new byte string representing the given data with the appropriate error correction
359
+ // codewords appended to it, based on this object's version and error correction level.
360
+ private addEccAndInterleave(data: Readonly<Array<byte>>): Array<byte> {
361
+ const ver: int = this.version;
362
+ const ecl: QrCode.Ecc = this.errorCorrectionLevel;
363
+ if (data.length != QrCode.getNumDataCodewords(ver, ecl))
364
+ throw new RangeError("Invalid argument");
365
+
366
+ // Calculate parameter numbers
367
+ const numBlocks: int = QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
368
+ const blockEccLen: int = QrCode.ECC_CODEWORDS_PER_BLOCK [ecl.ordinal][ver];
369
+ const rawCodewords: int = Math.floor(QrCode.getNumRawDataModules(ver) / 8);
370
+ const numShortBlocks: int = numBlocks - rawCodewords % numBlocks;
371
+ const shortBlockLen: int = Math.floor(rawCodewords / numBlocks);
372
+
373
+ // Split data into blocks and append ECC to each block
374
+ let blocks: Array<Array<byte>> = [];
375
+ const rsDiv: Array<byte> = QrCode.reedSolomonComputeDivisor(blockEccLen);
376
+ for (let i = 0, k = 0; i < numBlocks; i++) {
377
+ let dat: Array<byte> = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
378
+ k += dat.length;
379
+ const ecc: Array<byte> = QrCode.reedSolomonComputeRemainder(dat, rsDiv);
380
+ if (i < numShortBlocks)
381
+ dat.push(0);
382
+ blocks.push(dat.concat(ecc));
383
+ }
384
+
385
+ // Interleave (not concatenate) the bytes from every block into a single sequence
386
+ let result: Array<byte> = [];
387
+ for (let i = 0; i < blocks[0].length; i++) {
388
+ blocks.forEach((block, j) => {
389
+ // Skip the padding byte in short blocks
390
+ if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
391
+ result.push(block[i]);
392
+ });
393
+ }
394
+ assert(result.length == rawCodewords);
395
+ return result;
396
+ }
397
+
398
+
399
+ // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
400
+ // data area of this QR Code. Function modules need to be marked off before this is called.
401
+ private drawCodewords(data: Readonly<Array<byte>>): void {
402
+ if (data.length != Math.floor(QrCode.getNumRawDataModules(this.version) / 8))
403
+ throw new RangeError("Invalid argument");
404
+ let i: int = 0; // Bit index into the data
405
+ // Do the funny zigzag scan
406
+ for (let right = this.size - 1; right >= 1; right -= 2) { // Index of right column in each column pair
407
+ if (right == 6)
408
+ right = 5;
409
+ for (let vert = 0; vert < this.size; vert++) { // Vertical counter
410
+ for (let j = 0; j < 2; j++) {
411
+ const x: int = right - j; // Actual x coordinate
412
+ const upward: boolean = ((right + 1) & 2) == 0;
413
+ const y: int = upward ? this.size - 1 - vert : vert; // Actual y coordinate
414
+ if (!this.isFunction[y][x] && i < data.length * 8) {
415
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
416
+ i++;
417
+ }
418
+ // If this QR Code has any remainder bits (0 to 7), they were assigned as
419
+ // 0/false/light by the constructor and are left unchanged by this method
420
+ }
421
+ }
422
+ }
423
+ assert(i == data.length * 8);
424
+ }
425
+
426
+
427
+ // XORs the codeword modules in this QR Code with the given mask pattern.
428
+ // The function modules must be marked and the codeword bits must be drawn
429
+ // before masking. Due to the arithmetic of XOR, calling applyMask() with
430
+ // the same mask value a second time will undo the mask. A final well-formed
431
+ // QR Code needs exactly one (not zero, two, etc.) mask applied.
432
+ private applyMask(mask: int): void {
433
+ if (mask < 0 || mask > 7)
434
+ throw new RangeError("Mask value out of range");
435
+ for (let y = 0; y < this.size; y++) {
436
+ for (let x = 0; x < this.size; x++) {
437
+ let invert: boolean;
438
+ switch (mask) {
439
+ case 0: invert = (x + y) % 2 == 0; break;
440
+ case 1: invert = y % 2 == 0; break;
441
+ case 2: invert = x % 3 == 0; break;
442
+ case 3: invert = (x + y) % 3 == 0; break;
443
+ case 4: invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0; break;
444
+ case 5: invert = x * y % 2 + x * y % 3 == 0; break;
445
+ case 6: invert = (x * y % 2 + x * y % 3) % 2 == 0; break;
446
+ case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break;
447
+ default: throw new Error("Unreachable");
448
+ }
449
+ if (!this.isFunction[y][x] && invert)
450
+ this.modules[y][x] = !this.modules[y][x];
451
+ }
452
+ }
453
+ }
454
+
455
+
456
+ // Calculates and returns the penalty score based on state of this QR Code's current modules.
457
+ // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
458
+ private getPenaltyScore(): int {
459
+ let result: int = 0;
460
+
461
+ // Adjacent modules in row having same color, and finder-like patterns
462
+ for (let y = 0; y < this.size; y++) {
463
+ let runColor = false;
464
+ let runX = 0;
465
+ let runHistory = [0,0,0,0,0,0,0];
466
+ for (let x = 0; x < this.size; x++) {
467
+ if (this.modules[y][x] == runColor) {
468
+ runX++;
469
+ if (runX == 5)
470
+ result += QrCode.PENALTY_N1;
471
+ else if (runX > 5)
472
+ result++;
473
+ } else {
474
+ this.finderPenaltyAddHistory(runX, runHistory);
475
+ if (!runColor)
476
+ result += this.finderPenaltyCountPatterns(runHistory) * QrCode.PENALTY_N3;
477
+ runColor = this.modules[y][x];
478
+ runX = 1;
479
+ }
480
+ }
481
+ result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * QrCode.PENALTY_N3;
482
+ }
483
+ // Adjacent modules in column having same color, and finder-like patterns
484
+ for (let x = 0; x < this.size; x++) {
485
+ let runColor = false;
486
+ let runY = 0;
487
+ let runHistory = [0,0,0,0,0,0,0];
488
+ for (let y = 0; y < this.size; y++) {
489
+ if (this.modules[y][x] == runColor) {
490
+ runY++;
491
+ if (runY == 5)
492
+ result += QrCode.PENALTY_N1;
493
+ else if (runY > 5)
494
+ result++;
495
+ } else {
496
+ this.finderPenaltyAddHistory(runY, runHistory);
497
+ if (!runColor)
498
+ result += this.finderPenaltyCountPatterns(runHistory) * QrCode.PENALTY_N3;
499
+ runColor = this.modules[y][x];
500
+ runY = 1;
501
+ }
502
+ }
503
+ result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * QrCode.PENALTY_N3;
504
+ }
505
+
506
+ // 2*2 blocks of modules having same color
507
+ for (let y = 0; y < this.size - 1; y++) {
508
+ for (let x = 0; x < this.size - 1; x++) {
509
+ const color: boolean = this.modules[y][x];
510
+ if ( color == this.modules[y][x + 1] &&
511
+ color == this.modules[y + 1][x] &&
512
+ color == this.modules[y + 1][x + 1])
513
+ result += QrCode.PENALTY_N2;
514
+ }
515
+ }
516
+
517
+ // Balance of dark and light modules
518
+ let dark: int = 0;
519
+ for (const row of this.modules)
520
+ dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
521
+ const total: int = this.size * this.size; // Note that size is odd, so dark/total != 1/2
522
+ // Compute the smallest integer k >= 0 such that (45-5k)% <= dark/total <= (55+5k)%
523
+ const k: int = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
524
+ assert(0 <= k && k <= 9);
525
+ result += k * QrCode.PENALTY_N4;
526
+ assert(0 <= result && result <= 2568888); // Non-tight upper bound based on default values of PENALTY_N1, ..., N4
527
+ return result;
528
+ }
529
+
530
+
531
+ /*-- Private helper functions --*/
532
+
533
+ // Returns an ascending list of positions of alignment patterns for this version number.
534
+ // Each position is in the range [0,177), and are used on both the x and y axes.
535
+ // This could be implemented as lookup table of 40 variable-length lists of integers.
536
+ private getAlignmentPatternPositions(): Array<int> {
537
+ if (this.version == 1)
538
+ return [];
539
+ else {
540
+ const numAlign: int = Math.floor(this.version / 7) + 2;
541
+ const step: int = (this.version == 32) ? 26 :
542
+ Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
543
+ let result: Array<int> = [6];
544
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step)
545
+ result.splice(1, 0, pos);
546
+ return result;
547
+ }
548
+ }
549
+
550
+
551
+ // Returns the number of data bits that can be stored in a QR Code of the given version number, after
552
+ // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
553
+ // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
554
+ private static getNumRawDataModules(ver: int): int {
555
+ if (ver < QrCode.MIN_VERSION || ver > QrCode.MAX_VERSION)
556
+ throw new RangeError("Version number out of range");
557
+ let result: int = (16 * ver + 128) * ver + 64;
558
+ if (ver >= 2) {
559
+ const numAlign: int = Math.floor(ver / 7) + 2;
560
+ result -= (25 * numAlign - 10) * numAlign - 55;
561
+ if (ver >= 7)
562
+ result -= 36;
563
+ }
564
+ assert(208 <= result && result <= 29648);
565
+ return result;
566
+ }
567
+
568
+
569
+ // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
570
+ // QR Code of the given version number and error correction level, with remainder bits discarded.
571
+ // This stateless pure function could be implemented as a (40*4)-cell lookup table.
572
+ private static getNumDataCodewords(ver: int, ecl: QrCode.Ecc): int {
573
+ return Math.floor(QrCode.getNumRawDataModules(ver) / 8) -
574
+ QrCode.ECC_CODEWORDS_PER_BLOCK [ecl.ordinal][ver] *
575
+ QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
576
+ }
577
+
578
+
579
+ // Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
580
+ // implemented as a lookup table over all possible parameter values, instead of as an algorithm.
581
+ private static reedSolomonComputeDivisor(degree: int): Array<byte> {
582
+ if (degree < 1 || degree > 255)
583
+ throw new RangeError("Degree out of range");
584
+ // Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1.
585
+ // For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array [255, 8, 93].
586
+ let result: Array<byte> = [];
587
+ for (let i = 0; i < degree - 1; i++)
588
+ result.push(0);
589
+ result.push(1); // Start off with the monomial x^0
590
+
591
+ // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
592
+ // and drop the highest monomial term which is always 1x^degree.
593
+ // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
594
+ let root = 1;
595
+ for (let i = 0; i < degree; i++) {
596
+ // Multiply the current product by (x - r^i)
597
+ for (let j = 0; j < result.length; j++) {
598
+ result[j] = QrCode.reedSolomonMultiply(result[j], root);
599
+ if (j + 1 < result.length)
600
+ result[j] ^= result[j + 1];
601
+ }
602
+ root = QrCode.reedSolomonMultiply(root, 0x02);
603
+ }
604
+ return result;
605
+ }
606
+
607
+
608
+ // Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
609
+ private static reedSolomonComputeRemainder(data: Readonly<Array<byte>>, divisor: Readonly<Array<byte>>): Array<byte> {
610
+ let result: Array<byte> = divisor.map(_ => 0);
611
+ for (const b of data) { // Polynomial division
612
+ const factor: byte = b ^ (result.shift() as byte);
613
+ result.push(0);
614
+ divisor.forEach((coef, i) =>
615
+ result[i] ^= QrCode.reedSolomonMultiply(coef, factor));
616
+ }
617
+ return result;
618
+ }
619
+
620
+
621
+ // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
622
+ // are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
623
+ private static reedSolomonMultiply(x: byte, y: byte): byte {
624
+ if (x >>> 8 != 0 || y >>> 8 != 0)
625
+ throw new RangeError("Byte out of range");
626
+ // Russian peasant multiplication
627
+ let z: int = 0;
628
+ for (let i = 7; i >= 0; i--) {
629
+ z = (z << 1) ^ ((z >>> 7) * 0x11D);
630
+ z ^= ((y >>> i) & 1) * x;
631
+ }
632
+ assert(z >>> 8 == 0);
633
+ return z as byte;
634
+ }
635
+
636
+
637
+ // Can only be called immediately after a light run is added, and
638
+ // returns either 0, 1, or 2. A helper function for getPenaltyScore().
639
+ private finderPenaltyCountPatterns(runHistory: Readonly<Array<int>>): int {
640
+ const n: int = runHistory[1];
641
+ assert(n <= this.size * 3);
642
+ const core: boolean = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n;
643
+ return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0)
644
+ + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
645
+ }
646
+
647
+
648
+ // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
649
+ private finderPenaltyTerminateAndCount(currentRunColor: boolean, currentRunLength: int, runHistory: Array<int>): int {
650
+ if (currentRunColor) { // Terminate dark run
651
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
652
+ currentRunLength = 0;
653
+ }
654
+ currentRunLength += this.size; // Add light border to final run
655
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
656
+ return this.finderPenaltyCountPatterns(runHistory);
657
+ }
658
+
659
+
660
+ // Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
661
+ private finderPenaltyAddHistory(currentRunLength: int, runHistory: Array<int>): void {
662
+ if (runHistory[0] == 0)
663
+ currentRunLength += this.size; // Add light border to initial run
664
+ runHistory.pop();
665
+ runHistory.unshift(currentRunLength);
666
+ }
667
+
668
+
669
+ /*-- Constants and tables --*/
670
+
671
+ // The minimum version number supported in the QR Code Model 2 standard.
672
+ public static readonly MIN_VERSION: int = 1;
673
+ // The maximum version number supported in the QR Code Model 2 standard.
674
+ public static readonly MAX_VERSION: int = 40;
675
+
676
+ // For use in getPenaltyScore(), when evaluating which mask is best.
677
+ private static readonly PENALTY_N1: int = 3;
678
+ private static readonly PENALTY_N2: int = 3;
679
+ private static readonly PENALTY_N3: int = 40;
680
+ private static readonly PENALTY_N4: int = 10;
681
+
682
+ private static readonly ECC_CODEWORDS_PER_BLOCK: Array<Array<int>> = [
683
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
684
+ //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
685
+ [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Low
686
+ [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28], // Medium
687
+ [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Quartile
688
+ [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // High
689
+ ];
690
+
691
+ private static readonly NUM_ERROR_CORRECTION_BLOCKS: Array<Array<int>> = [
692
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
693
+ //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
694
+ [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25], // Low
695
+ [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49], // Medium
696
+ [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68], // Quartile
697
+ [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81], // High
698
+ ];
699
+
700
+ }
701
+
702
+
703
+ // Appends the given number of low-order bits of the given value
704
+ // to the given buffer. Requires 0 <= len <= 31 and 0 <= val < 2^len.
705
+ function appendBits(val: int, len: int, bb: Array<bit>): void {
706
+ if (len < 0 || len > 31 || val >>> len != 0)
707
+ throw new RangeError("Value out of range");
708
+ for (let i = len - 1; i >= 0; i--) // Append bit by bit
709
+ bb.push((val >>> i) & 1);
710
+ }
711
+
712
+
713
+ // Returns true iff the i'th bit of x is set to 1.
714
+ function getBit(x: int, i: int): boolean {
715
+ return ((x >>> i) & 1) != 0;
716
+ }
717
+
718
+
719
+ // Throws an exception if the given condition is false.
720
+ function assert(cond: boolean): void {
721
+ if (!cond)
722
+ throw new Error("Assertion error");
723
+ }
724
+
725
+
726
+
727
+ /*---- Data segment class ----*/
728
+
729
+ /*
730
+ * A segment of character/binary/control data in a QR Code symbol.
731
+ * Instances of this class are immutable.
732
+ * The mid-level way to create a segment is to take the payload data
733
+ * and call a static factory function such as QrSegment.makeNumeric().
734
+ * The low-level way to create a segment is to custom-make the bit buffer
735
+ * and call the QrSegment() constructor with appropriate values.
736
+ * This segment class imposes no length restrictions, but QR Codes have restrictions.
737
+ * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
738
+ * Any segment longer than this is meaningless for the purpose of generating QR Codes.
739
+ */
740
+ export class QrSegment {
741
+
742
+ /*-- Static factory functions (mid level) --*/
743
+
744
+ // Returns a segment representing the given binary data encoded in
745
+ // byte mode. All input byte arrays are acceptable. Any text string
746
+ // can be converted to UTF-8 bytes and encoded as a byte mode segment.
747
+ public static makeBytes(data: Readonly<Array<byte>>): QrSegment {
748
+ let bb: Array<bit> = []
749
+ for (const b of data)
750
+ appendBits(b, 8, bb);
751
+ return new QrSegment(QrSegment.Mode.BYTE, data.length, bb);
752
+ }
753
+
754
+
755
+ // Returns a segment representing the given string of decimal digits encoded in numeric mode.
756
+ public static makeNumeric(digits: string): QrSegment {
757
+ if (!QrSegment.isNumeric(digits))
758
+ throw new RangeError("String contains non-numeric characters");
759
+ let bb: Array<bit> = []
760
+ for (let i = 0; i < digits.length; ) { // Consume up to 3 digits per iteration
761
+ const n: int = Math.min(digits.length - i, 3);
762
+ appendBits(parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
763
+ i += n;
764
+ }
765
+ return new QrSegment(QrSegment.Mode.NUMERIC, digits.length, bb);
766
+ }
767
+
768
+
769
+ // Returns a segment representing the given text string encoded in alphanumeric mode.
770
+ // The characters allowed are: 0 to 9, A to Z (uppercase only), space,
771
+ // dollar, percent, asterisk, plus, hyphen, period, slash, colon.
772
+ public static makeAlphanumeric(text: string): QrSegment {
773
+ if (!QrSegment.isAlphanumeric(text))
774
+ throw new RangeError("String contains unencodable characters in alphanumeric mode");
775
+ let bb: Array<bit> = []
776
+ let i: int;
777
+ for (i = 0; i + 2 <= text.length; i += 2) { // Process groups of 2
778
+ let temp: int = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
779
+ temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
780
+ appendBits(temp, 11, bb);
781
+ }
782
+ if (i < text.length) // 1 character remaining
783
+ appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
784
+ return new QrSegment(QrSegment.Mode.ALPHANUMERIC, text.length, bb);
785
+ }
786
+
787
+
788
+ // Returns a new mutable list of zero or more segments to represent the given Unicode text string.
789
+ // The result may use various segment modes and switch modes to optimize the length of the bit stream.
790
+ public static makeSegments(text: string): Array<QrSegment> {
791
+ // Select the most efficient segment encoding automatically
792
+ if (text == "")
793
+ return [];
794
+ else if (QrSegment.isNumeric(text))
795
+ return [QrSegment.makeNumeric(text)];
796
+ else if (QrSegment.isAlphanumeric(text))
797
+ return [QrSegment.makeAlphanumeric(text)];
798
+ else
799
+ return [QrSegment.makeBytes(QrSegment.toUtf8ByteArray(text))];
800
+ }
801
+
802
+
803
+ // Returns a segment representing an Extended Channel Interpretation
804
+ // (ECI) designator with the given assignment value.
805
+ public static makeEci(assignVal: int): QrSegment {
806
+ let bb: Array<bit> = []
807
+ if (assignVal < 0)
808
+ throw new RangeError("ECI assignment value out of range");
809
+ else if (assignVal < (1 << 7))
810
+ appendBits(assignVal, 8, bb);
811
+ else if (assignVal < (1 << 14)) {
812
+ appendBits(0b10, 2, bb);
813
+ appendBits(assignVal, 14, bb);
814
+ } else if (assignVal < 1000000) {
815
+ appendBits(0b110, 3, bb);
816
+ appendBits(assignVal, 21, bb);
817
+ } else
818
+ throw new RangeError("ECI assignment value out of range");
819
+ return new QrSegment(QrSegment.Mode.ECI, 0, bb);
820
+ }
821
+
822
+
823
+ // Tests whether the given string can be encoded as a segment in numeric mode.
824
+ // A string is encodable iff each character is in the range 0 to 9.
825
+ public static isNumeric(text: string): boolean {
826
+ return QrSegment.NUMERIC_REGEX.test(text);
827
+ }
828
+
829
+
830
+ // Tests whether the given string can be encoded as a segment in alphanumeric mode.
831
+ // A string is encodable iff each character is in the following set: 0 to 9, A to Z
832
+ // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
833
+ public static isAlphanumeric(text: string): boolean {
834
+ return QrSegment.ALPHANUMERIC_REGEX.test(text);
835
+ }
836
+
837
+
838
+ /*-- Constructor (low level) and fields --*/
839
+
840
+ // Creates a new QR Code segment with the given attributes and data.
841
+ // The character count (numChars) must agree with the mode and the bit buffer length,
842
+ // but the constraint isn't checked. The given bit buffer is cloned and stored.
843
+ public constructor(
844
+ // The mode indicator of this segment.
845
+ public readonly mode: QrSegment.Mode,
846
+
847
+ // The length of this segment's unencoded data. Measured in characters for
848
+ // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
849
+ // Always zero or positive. Not the same as the data's bit length.
850
+ public readonly numChars: int,
851
+
852
+ // The data bits of this segment. Accessed through getData().
853
+ private readonly bitData: Array<bit>) {
854
+
855
+ if (numChars < 0)
856
+ throw new RangeError("Invalid argument");
857
+ this.bitData = bitData.slice(); // Make defensive copy
858
+ }
859
+
860
+
861
+ /*-- Methods --*/
862
+
863
+ // Returns a new copy of the data bits of this segment.
864
+ public getData(): Array<bit> {
865
+ return this.bitData.slice(); // Make defensive copy
866
+ }
867
+
868
+
869
+ // (Package-private) Calculates and returns the number of bits needed to encode the given segments at
870
+ // the given version. The result is infinity if a segment has too many characters to fit its length field.
871
+ public static getTotalBits(segs: Readonly<Array<QrSegment>>, version: int): number {
872
+ let result: number = 0;
873
+ for (const seg of segs) {
874
+ const ccbits: int = seg.mode.numCharCountBits(version);
875
+ if (seg.numChars >= (1 << ccbits))
876
+ return Infinity; // The segment's length doesn't fit the field's bit width
877
+ result += 4 + ccbits + seg.bitData.length;
878
+ }
879
+ return result;
880
+ }
881
+
882
+
883
+ // Returns a new array of bytes representing the given string encoded in UTF-8.
884
+ private static toUtf8ByteArray(str: string): Array<byte> {
885
+ str = encodeURI(str);
886
+ let result: Array<byte> = [];
887
+ for (let i = 0; i < str.length; i++) {
888
+ if (str.charAt(i) != "%")
889
+ result.push(str.charCodeAt(i));
890
+ else {
891
+ result.push(parseInt(str.substring(i + 1, i + 3), 16));
892
+ i += 2;
893
+ }
894
+ }
895
+ return result;
896
+ }
897
+
898
+
899
+ /*-- Constants --*/
900
+
901
+ // Describes precisely all strings that are encodable in numeric mode.
902
+ private static readonly NUMERIC_REGEX: RegExp = /^[0-9]*$/;
903
+
904
+ // Describes precisely all strings that are encodable in alphanumeric mode.
905
+ private static readonly ALPHANUMERIC_REGEX: RegExp = /^[A-Z0-9 $%*+.\/:-]*$/;
906
+
907
+ // The set of all legal characters in alphanumeric mode,
908
+ // where each character value maps to the index in the string.
909
+ private static readonly ALPHANUMERIC_CHARSET: string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
910
+
911
+ }
912
+
913
+ }
914
+
915
+
916
+
917
+ /*---- Public helper enumeration ----*/
918
+
919
+ namespace qrcodegen.QrCode {
920
+
921
+ type int = number;
922
+
923
+
924
+ /*
925
+ * The error correction level in a QR Code symbol. Immutable.
926
+ */
927
+ export class Ecc {
928
+
929
+ /*-- Constants --*/
930
+
931
+ public static readonly LOW = new Ecc(0, 1); // The QR Code can tolerate about 7% erroneous codewords
932
+ public static readonly MEDIUM = new Ecc(1, 0); // The QR Code can tolerate about 15% erroneous codewords
933
+ public static readonly QUARTILE = new Ecc(2, 3); // The QR Code can tolerate about 25% erroneous codewords
934
+ public static readonly HIGH = new Ecc(3, 2); // The QR Code can tolerate about 30% erroneous codewords
935
+
936
+
937
+ /*-- Constructor and fields --*/
938
+
939
+ private constructor(
940
+ // In the range 0 to 3 (unsigned 2-bit integer).
941
+ public readonly ordinal: int,
942
+ // (Package-private) In the range 0 to 3 (unsigned 2-bit integer).
943
+ public readonly formatBits: int) {}
944
+
945
+ }
946
+ }
947
+
948
+
949
+
950
+ /*---- Public helper enumeration ----*/
951
+
952
+ namespace qrcodegen.QrSegment {
953
+
954
+ type int = number;
955
+
956
+
957
+ /*
958
+ * Describes how a segment's data bits are interpreted. Immutable.
959
+ */
960
+ export class Mode {
961
+
962
+ /*-- Constants --*/
963
+
964
+ public static readonly NUMERIC = new Mode(0x1, [10, 12, 14]);
965
+ public static readonly ALPHANUMERIC = new Mode(0x2, [ 9, 11, 13]);
966
+ public static readonly BYTE = new Mode(0x4, [ 8, 16, 16]);
967
+ public static readonly KANJI = new Mode(0x8, [ 8, 10, 12]);
968
+ public static readonly ECI = new Mode(0x7, [ 0, 0, 0]);
969
+
970
+
971
+ /*-- Constructor and fields --*/
972
+
973
+ private constructor(
974
+ // The mode indicator bits, which is a uint4 value (range 0 to 15).
975
+ public readonly modeBits: int,
976
+ // Number of character count bits for three different version ranges.
977
+ private readonly numBitsCharCount: [int,int,int]) {}
978
+
979
+
980
+ /*-- Method --*/
981
+
982
+ // (Package-private) Returns the bit width of the character count field for a segment in
983
+ // this mode in a QR Code at the given version number. The result is in the range [0, 16].
984
+ public numCharCountBits(ver: int): int {
985
+ return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
986
+ }
987
+
988
+ }
989
+ }
990
+
991
+ export default qrcodegen