wedux-ui 0.1.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 (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +184 -0
  3. package/miniprogram_dist/behaviors/formField.js +35 -0
  4. package/miniprogram_dist/components/avatar/avatar.js +70 -0
  5. package/miniprogram_dist/components/avatar/avatar.json +4 -0
  6. package/miniprogram_dist/components/avatar/avatar.scss +68 -0
  7. package/miniprogram_dist/components/avatar/avatar.wxml +15 -0
  8. package/miniprogram_dist/components/avatar-group/avatar-group.js +45 -0
  9. package/miniprogram_dist/components/avatar-group/avatar-group.json +7 -0
  10. package/miniprogram_dist/components/avatar-group/avatar-group.scss +4 -0
  11. package/miniprogram_dist/components/avatar-group/avatar-group.wxml +3 -0
  12. package/miniprogram_dist/components/back-top/back-top.js +68 -0
  13. package/miniprogram_dist/components/back-top/back-top.json +4 -0
  14. package/miniprogram_dist/components/back-top/back-top.scss +43 -0
  15. package/miniprogram_dist/components/back-top/back-top.wxml +10 -0
  16. package/miniprogram_dist/components/badge/badge.js +100 -0
  17. package/miniprogram_dist/components/badge/badge.json +4 -0
  18. package/miniprogram_dist/components/badge/badge.scss +98 -0
  19. package/miniprogram_dist/components/badge/badge.wxml +11 -0
  20. package/miniprogram_dist/components/button/button.js +152 -0
  21. package/miniprogram_dist/components/button/button.json +4 -0
  22. package/miniprogram_dist/components/button/button.scss +499 -0
  23. package/miniprogram_dist/components/button/button.wxml +21 -0
  24. package/miniprogram_dist/components/button-group/button-group.js +51 -0
  25. package/miniprogram_dist/components/button-group/button-group.json +4 -0
  26. package/miniprogram_dist/components/button-group/button-group.scss +8 -0
  27. package/miniprogram_dist/components/button-group/button-group.wxml +3 -0
  28. package/miniprogram_dist/components/calendar/calendar.js +308 -0
  29. package/miniprogram_dist/components/calendar/calendar.json +4 -0
  30. package/miniprogram_dist/components/calendar/calendar.scss +141 -0
  31. package/miniprogram_dist/components/calendar/calendar.wxml +47 -0
  32. package/miniprogram_dist/components/card/card.js +44 -0
  33. package/miniprogram_dist/components/card/card.json +4 -0
  34. package/miniprogram_dist/components/card/card.scss +143 -0
  35. package/miniprogram_dist/components/card/card.wxml +31 -0
  36. package/miniprogram_dist/components/checkbox/checkbox.js +43 -0
  37. package/miniprogram_dist/components/checkbox/checkbox.json +4 -0
  38. package/miniprogram_dist/components/checkbox/checkbox.scss +77 -0
  39. package/miniprogram_dist/components/checkbox/checkbox.wxml +13 -0
  40. package/miniprogram_dist/components/checkbox-button/checkbox-button.js +43 -0
  41. package/miniprogram_dist/components/checkbox-button/checkbox-button.json +4 -0
  42. package/miniprogram_dist/components/checkbox-button/checkbox-button.scss +39 -0
  43. package/miniprogram_dist/components/checkbox-button/checkbox-button.wxml +8 -0
  44. package/miniprogram_dist/components/checkbox-group/checkbox-group.js +84 -0
  45. package/miniprogram_dist/components/checkbox-group/checkbox-group.json +4 -0
  46. package/miniprogram_dist/components/checkbox-group/checkbox-group.scss +9 -0
  47. package/miniprogram_dist/components/checkbox-group/checkbox-group.wxml +3 -0
  48. package/miniprogram_dist/components/color-picker/color-picker.js +348 -0
  49. package/miniprogram_dist/components/color-picker/color-picker.json +7 -0
  50. package/miniprogram_dist/components/color-picker/color-picker.scss +383 -0
  51. package/miniprogram_dist/components/color-picker/color-picker.wxml +232 -0
  52. package/miniprogram_dist/components/date-picker/date-picker.js +1289 -0
  53. package/miniprogram_dist/components/date-picker/date-picker.json +7 -0
  54. package/miniprogram_dist/components/date-picker/date-picker.scss +468 -0
  55. package/miniprogram_dist/components/date-picker/date-picker.wxml +214 -0
  56. package/miniprogram_dist/components/divider/divider.js +34 -0
  57. package/miniprogram_dist/components/divider/divider.json +4 -0
  58. package/miniprogram_dist/components/divider/divider.scss +75 -0
  59. package/miniprogram_dist/components/divider/divider.wxml +8 -0
  60. package/miniprogram_dist/components/drawer/drawer.js +104 -0
  61. package/miniprogram_dist/components/drawer/drawer.json +4 -0
  62. package/miniprogram_dist/components/drawer/drawer.scss +171 -0
  63. package/miniprogram_dist/components/drawer/drawer.wxml +22 -0
  64. package/miniprogram_dist/components/ellipsis/ellipsis.js +38 -0
  65. package/miniprogram_dist/components/ellipsis/ellipsis.json +4 -0
  66. package/miniprogram_dist/components/ellipsis/ellipsis.scss +22 -0
  67. package/miniprogram_dist/components/ellipsis/ellipsis.wxml +7 -0
  68. package/miniprogram_dist/components/flex/flex.js +81 -0
  69. package/miniprogram_dist/components/flex/flex.json +4 -0
  70. package/miniprogram_dist/components/flex/flex.scss +4 -0
  71. package/miniprogram_dist/components/flex/flex.wxml +3 -0
  72. package/miniprogram_dist/components/float-button/float-button.js +78 -0
  73. package/miniprogram_dist/components/float-button/float-button.json +4 -0
  74. package/miniprogram_dist/components/float-button/float-button.scss +54 -0
  75. package/miniprogram_dist/components/float-button/float-button.wxml +9 -0
  76. package/miniprogram_dist/components/form/form.js +142 -0
  77. package/miniprogram_dist/components/form/form.json +4 -0
  78. package/miniprogram_dist/components/form/form.scss +11 -0
  79. package/miniprogram_dist/components/form/form.wxml +3 -0
  80. package/miniprogram_dist/components/form/validator.js +220 -0
  81. package/miniprogram_dist/components/form-item/form-item.js +240 -0
  82. package/miniprogram_dist/components/form-item/form-item.json +4 -0
  83. package/miniprogram_dist/components/form-item/form-item.scss +59 -0
  84. package/miniprogram_dist/components/form-item/form-item.wxml +33 -0
  85. package/miniprogram_dist/components/gradient-text/gradient-text.js +54 -0
  86. package/miniprogram_dist/components/gradient-text/gradient-text.json +4 -0
  87. package/miniprogram_dist/components/gradient-text/gradient-text.scss +7 -0
  88. package/miniprogram_dist/components/gradient-text/gradient-text.wxml +1 -0
  89. package/miniprogram_dist/components/h/h.js +60 -0
  90. package/miniprogram_dist/components/h/h.json +4 -0
  91. package/miniprogram_dist/components/h/h.scss +53 -0
  92. package/miniprogram_dist/components/h/h.wxml +1 -0
  93. package/miniprogram_dist/components/highlight/highlight.js +77 -0
  94. package/miniprogram_dist/components/highlight/highlight.json +4 -0
  95. package/miniprogram_dist/components/highlight/highlight.scss +8 -0
  96. package/miniprogram_dist/components/highlight/highlight.wxml +12 -0
  97. package/miniprogram_dist/components/infinite-scroll/infinite-scroll.js +31 -0
  98. package/miniprogram_dist/components/infinite-scroll/infinite-scroll.json +4 -0
  99. package/miniprogram_dist/components/infinite-scroll/infinite-scroll.scss +31 -0
  100. package/miniprogram_dist/components/infinite-scroll/infinite-scroll.wxml +12 -0
  101. package/miniprogram_dist/components/input/input.js +59 -0
  102. package/miniprogram_dist/components/input/input.json +4 -0
  103. package/miniprogram_dist/components/input/input.scss +96 -0
  104. package/miniprogram_dist/components/input/input.wxml +34 -0
  105. package/miniprogram_dist/components/input-otp/input-otp.js +106 -0
  106. package/miniprogram_dist/components/input-otp/input-otp.json +4 -0
  107. package/miniprogram_dist/components/input-otp/input-otp.scss +122 -0
  108. package/miniprogram_dist/components/input-otp/input-otp.wxml +38 -0
  109. package/miniprogram_dist/components/layout/layout.js +50 -0
  110. package/miniprogram_dist/components/layout/layout.json +4 -0
  111. package/miniprogram_dist/components/layout/layout.scss +10 -0
  112. package/miniprogram_dist/components/layout/layout.wxml +3 -0
  113. package/miniprogram_dist/components/layout-content/layout-content.js +47 -0
  114. package/miniprogram_dist/components/layout-content/layout-content.json +4 -0
  115. package/miniprogram_dist/components/layout-content/layout-content.scss +5 -0
  116. package/miniprogram_dist/components/layout-content/layout-content.wxml +13 -0
  117. package/miniprogram_dist/components/layout-footer/layout-footer.js +59 -0
  118. package/miniprogram_dist/components/layout-footer/layout-footer.json +4 -0
  119. package/miniprogram_dist/components/layout-footer/layout-footer.scss +23 -0
  120. package/miniprogram_dist/components/layout-footer/layout-footer.wxml +16 -0
  121. package/miniprogram_dist/components/layout-header/layout-header.js +59 -0
  122. package/miniprogram_dist/components/layout-header/layout-header.json +4 -0
  123. package/miniprogram_dist/components/layout-header/layout-header.scss +23 -0
  124. package/miniprogram_dist/components/layout-header/layout-header.wxml +16 -0
  125. package/miniprogram_dist/components/layout-sider/layout-sider.js +48 -0
  126. package/miniprogram_dist/components/layout-sider/layout-sider.json +4 -0
  127. package/miniprogram_dist/components/layout-sider/layout-sider.scss +13 -0
  128. package/miniprogram_dist/components/layout-sider/layout-sider.wxml +5 -0
  129. package/miniprogram_dist/components/list/list.js +55 -0
  130. package/miniprogram_dist/components/list/list.json +4 -0
  131. package/miniprogram_dist/components/list/list.scss +51 -0
  132. package/miniprogram_dist/components/list/list.wxml +9 -0
  133. package/miniprogram_dist/components/list-item/list-item.js +24 -0
  134. package/miniprogram_dist/components/list-item/list-item.json +4 -0
  135. package/miniprogram_dist/components/list-item/list-item.scss +51 -0
  136. package/miniprogram_dist/components/list-item/list-item.wxml +14 -0
  137. package/miniprogram_dist/components/navigation-bar/navigation-bar.js +77 -0
  138. package/miniprogram_dist/components/navigation-bar/navigation-bar.json +4 -0
  139. package/miniprogram_dist/components/navigation-bar/navigation-bar.scss +63 -0
  140. package/miniprogram_dist/components/navigation-bar/navigation-bar.wxml +35 -0
  141. package/miniprogram_dist/components/number-animation/number-animation.js +124 -0
  142. package/miniprogram_dist/components/number-animation/number-animation.json +4 -0
  143. package/miniprogram_dist/components/number-animation/number-animation.scss +3 -0
  144. package/miniprogram_dist/components/number-animation/number-animation.wxml +1 -0
  145. package/miniprogram_dist/components/popover/popover.js +183 -0
  146. package/miniprogram_dist/components/popover/popover.json +4 -0
  147. package/miniprogram_dist/components/popover/popover.scss +69 -0
  148. package/miniprogram_dist/components/popover/popover.wxml +19 -0
  149. package/miniprogram_dist/components/qr-code/qr-code.js +216 -0
  150. package/miniprogram_dist/components/qr-code/qr-code.json +4 -0
  151. package/miniprogram_dist/components/qr-code/qr-code.scss +8 -0
  152. package/miniprogram_dist/components/qr-code/qr-code.wxml +16 -0
  153. package/miniprogram_dist/components/radio/radio.js +38 -0
  154. package/miniprogram_dist/components/radio/radio.json +4 -0
  155. package/miniprogram_dist/components/radio/radio.scss +50 -0
  156. package/miniprogram_dist/components/radio/radio.wxml +12 -0
  157. package/miniprogram_dist/components/radio-button/radio-button.js +39 -0
  158. package/miniprogram_dist/components/radio-button/radio-button.json +4 -0
  159. package/miniprogram_dist/components/radio-button/radio-button.scss +39 -0
  160. package/miniprogram_dist/components/radio-button/radio-button.wxml +8 -0
  161. package/miniprogram_dist/components/radio-group/radio-group.js +72 -0
  162. package/miniprogram_dist/components/radio-group/radio-group.json +4 -0
  163. package/miniprogram_dist/components/radio-group/radio-group.scss +9 -0
  164. package/miniprogram_dist/components/radio-group/radio-group.wxml +3 -0
  165. package/miniprogram_dist/components/rate/rate.js +90 -0
  166. package/miniprogram_dist/components/rate/rate.json +4 -0
  167. package/miniprogram_dist/components/rate/rate.scss +59 -0
  168. package/miniprogram_dist/components/rate/rate.wxml +16 -0
  169. package/miniprogram_dist/components/select/select.js +201 -0
  170. package/miniprogram_dist/components/select/select.json +7 -0
  171. package/miniprogram_dist/components/select/select.scss +235 -0
  172. package/miniprogram_dist/components/select/select.wxml +79 -0
  173. package/miniprogram_dist/components/stepper/stepper.js +113 -0
  174. package/miniprogram_dist/components/stepper/stepper.json +4 -0
  175. package/miniprogram_dist/components/stepper/stepper.scss +73 -0
  176. package/miniprogram_dist/components/stepper/stepper.wxml +23 -0
  177. package/miniprogram_dist/components/switch/switch.js +42 -0
  178. package/miniprogram_dist/components/switch/switch.json +4 -0
  179. package/miniprogram_dist/components/switch/switch.scss +77 -0
  180. package/miniprogram_dist/components/switch/switch.wxml +10 -0
  181. package/miniprogram_dist/components/tab-bar/tab-bar.js +53 -0
  182. package/miniprogram_dist/components/tab-bar/tab-bar.json +4 -0
  183. package/miniprogram_dist/components/tab-bar/tab-bar.scss +53 -0
  184. package/miniprogram_dist/components/tab-bar/tab-bar.wxml +12 -0
  185. package/miniprogram_dist/components/tag/tag.js +87 -0
  186. package/miniprogram_dist/components/tag/tag.json +4 -0
  187. package/miniprogram_dist/components/tag/tag.scss +138 -0
  188. package/miniprogram_dist/components/tag/tag.wxml +12 -0
  189. package/miniprogram_dist/components/textarea/textarea.js +46 -0
  190. package/miniprogram_dist/components/textarea/textarea.json +4 -0
  191. package/miniprogram_dist/components/textarea/textarea.scss +51 -0
  192. package/miniprogram_dist/components/textarea/textarea.wxml +20 -0
  193. package/miniprogram_dist/components/theme-provider/presets.js +101 -0
  194. package/miniprogram_dist/components/theme-provider/theme-provider.js +34 -0
  195. package/miniprogram_dist/components/theme-provider/theme-provider.json +4 -0
  196. package/miniprogram_dist/components/theme-provider/theme-provider.scss +3 -0
  197. package/miniprogram_dist/components/theme-provider/theme-provider.wxml +3 -0
  198. package/miniprogram_dist/components/time-picker/time-picker.js +136 -0
  199. package/miniprogram_dist/components/time-picker/time-picker.json +7 -0
  200. package/miniprogram_dist/components/time-picker/time-picker.scss +135 -0
  201. package/miniprogram_dist/components/time-picker/time-picker.wxml +47 -0
  202. package/miniprogram_dist/components/tooltip/tooltip.js +179 -0
  203. package/miniprogram_dist/components/tooltip/tooltip.json +4 -0
  204. package/miniprogram_dist/components/tooltip/tooltip.scss +66 -0
  205. package/miniprogram_dist/components/tooltip/tooltip.wxml +17 -0
  206. package/miniprogram_dist/components/tree/tree.js +647 -0
  207. package/miniprogram_dist/components/tree/tree.json +4 -0
  208. package/miniprogram_dist/components/tree/tree.scss +178 -0
  209. package/miniprogram_dist/components/tree/tree.wxml +59 -0
  210. package/miniprogram_dist/components/tree-select/tree-select.js +260 -0
  211. package/miniprogram_dist/components/tree-select/tree-select.json +8 -0
  212. package/miniprogram_dist/components/tree-select/tree-select.scss +250 -0
  213. package/miniprogram_dist/components/tree-select/tree-select.wxml +118 -0
  214. package/miniprogram_dist/components/upload/upload.js +387 -0
  215. package/miniprogram_dist/components/upload/upload.json +4 -0
  216. package/miniprogram_dist/components/upload/upload.scss +258 -0
  217. package/miniprogram_dist/components/upload/upload.wxml +142 -0
  218. package/miniprogram_dist/components/watermark/watermark.js +260 -0
  219. package/miniprogram_dist/components/watermark/watermark.json +4 -0
  220. package/miniprogram_dist/components/watermark/watermark.scss +35 -0
  221. package/miniprogram_dist/components/watermark/watermark.wxml +13 -0
  222. package/miniprogram_dist/libs/qrcodegen.js +714 -0
  223. package/miniprogram_dist/libs/seemly.min.js +547 -0
  224. package/miniprogram_dist/libs/tempo_1_0_0.js +1264 -0
  225. package/miniprogram_dist/libs/validator_13_56_26.min.js +5282 -0
  226. package/miniprogram_dist/styles/demo.scss +96 -0
  227. package/miniprogram_dist/styles/iconfont.scss +91 -0
  228. package/miniprogram_dist/styles/theme.scss +126 -0
  229. package/miniprogram_dist/styles/tokens.scss +292 -0
  230. package/miniprogram_dist/utils/relations.js +21 -0
  231. package/package.json +25 -0
@@ -0,0 +1,714 @@
1
+ /*
2
+ * QR Code generator library (JavaScript ES6+)
3
+ *
4
+ * Copyright (c) Project Nayuki. (MIT License)
5
+ * https://www.nayuki.io/page/qr-code-generator-library
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
8
+ * this software and associated documentation files (the "Software"), to deal in
9
+ * the Software without restriction, including without limitation the rights to
10
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
+ * the Software, and to permit persons to whom the Software is furnished to do so,
12
+ * subject to the following conditions and the above copyright notice and this
13
+ * permission notice shall be included in all copies or substantial portions of
14
+ * the Software.
15
+ */
16
+
17
+ 'use strict';
18
+
19
+ /* ---- Helper enumeration: Error Correction Level ---- */
20
+
21
+ class Ecc {
22
+ static LOW = new Ecc(0, 1);
23
+ static MEDIUM = new Ecc(1, 0);
24
+ static QUARTILE = new Ecc(2, 3);
25
+ static HIGH = new Ecc(3, 2);
26
+
27
+ constructor(ordinal, formatBits) {
28
+ this.ordinal = ordinal;
29
+ this.formatBits = formatBits;
30
+ }
31
+ }
32
+
33
+ /* ---- Helper enumeration: Segment Mode ---- */
34
+
35
+ class Mode {
36
+ static NUMERIC = new Mode(0x1, [10, 12, 14]);
37
+ static ALPHANUMERIC = new Mode(0x2, [9, 11, 13]);
38
+ static BYTE = new Mode(0x4, [8, 16, 16]);
39
+ static KANJI = new Mode(0x8, [8, 10, 12]);
40
+ static ECI = new Mode(0x7, [0, 0, 0]);
41
+
42
+ constructor(modeBits, numBitsCharCount) {
43
+ this.modeBits = modeBits;
44
+ this._numBitsCharCount = numBitsCharCount;
45
+ }
46
+
47
+ numCharCountBits(ver) {
48
+ return this._numBitsCharCount[Math.floor((ver + 7) / 17)];
49
+ }
50
+ }
51
+
52
+ /* ---- Private helper functions ---- */
53
+
54
+ const appendBits = (val, len, bb) => {
55
+ if (len < 0 || len > 31 || val >>> len !== 0) {
56
+ throw new RangeError('Value out of range');
57
+ }
58
+ for (let i = len - 1; i >= 0; i--) {
59
+ bb.push((val >>> i) & 1);
60
+ }
61
+ };
62
+
63
+ const getBit = (x, i) => ((x >>> i) & 1) !== 0;
64
+
65
+ /* ---- Data segment class ---- */
66
+
67
+ class QrSegment {
68
+ static NUMERIC_REGEX = /^[0-9]*$/;
69
+ static ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+./:-]*$/;
70
+ static ALPHANUMERIC_CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:';
71
+
72
+ static makeBytes(data) {
73
+ const bb = [];
74
+ for (const b of data) {
75
+ appendBits(b, 8, bb);
76
+ }
77
+ return new QrSegment(Mode.BYTE, data.length, bb);
78
+ }
79
+
80
+ static makeNumeric(digits) {
81
+ if (!QrSegment.isNumeric(digits)) {
82
+ throw new RangeError('String contains non-numeric characters');
83
+ }
84
+ const bb = [];
85
+ for (let i = 0; i < digits.length; ) {
86
+ const n = Math.min(digits.length - i, 3);
87
+ appendBits(parseInt(digits.substr(i, n), 10), n * 3 + 1, bb);
88
+ i += n;
89
+ }
90
+ return new QrSegment(Mode.NUMERIC, digits.length, bb);
91
+ }
92
+
93
+ static makeAlphanumeric(text) {
94
+ if (!QrSegment.isAlphanumeric(text)) {
95
+ throw new RangeError('String contains unencodable characters in alphanumeric mode');
96
+ }
97
+ const bb = [];
98
+ let i;
99
+ for (i = 0; i + 2 <= text.length; i += 2) {
100
+ let temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
101
+ temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
102
+ appendBits(temp, 11, bb);
103
+ }
104
+ if (i < text.length) {
105
+ appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
106
+ }
107
+ return new QrSegment(Mode.ALPHANUMERIC, text.length, bb);
108
+ }
109
+
110
+ static makeSegments(text) {
111
+ if (text === '') {
112
+ return [];
113
+ } else if (QrSegment.isNumeric(text)) {
114
+ return [QrSegment.makeNumeric(text)];
115
+ } else if (QrSegment.isAlphanumeric(text)) {
116
+ return [QrSegment.makeAlphanumeric(text)];
117
+ } else {
118
+ return [QrSegment.makeBytes(QrSegment.toUtf8ByteArray(text))];
119
+ }
120
+ }
121
+
122
+ static isNumeric(text) {
123
+ return QrSegment.NUMERIC_REGEX.test(text);
124
+ }
125
+
126
+ static isAlphanumeric(text) {
127
+ return QrSegment.ALPHANUMERIC_REGEX.test(text);
128
+ }
129
+
130
+ static getTotalBits(segs, version) {
131
+ let result = 0;
132
+ for (const seg of segs) {
133
+ const ccbits = seg.mode.numCharCountBits(version);
134
+ if (seg.numChars >= 1 << ccbits) {
135
+ return Infinity;
136
+ }
137
+ result += 4 + ccbits + seg._bitData.length;
138
+ }
139
+ return result;
140
+ }
141
+
142
+ static toUtf8ByteArray(str) {
143
+ str = encodeURI(str);
144
+ const result = [];
145
+ for (let i = 0; i < str.length; i++) {
146
+ if (str.charAt(i) !== '%') {
147
+ result.push(str.charCodeAt(i));
148
+ } else {
149
+ result.push(parseInt(str.substr(i + 1, 2), 16));
150
+ i += 2;
151
+ }
152
+ }
153
+ return result;
154
+ }
155
+
156
+ constructor(mode, numChars, bitData) {
157
+ if (numChars < 0) {
158
+ throw new RangeError('Invalid argument');
159
+ }
160
+ this.mode = mode;
161
+ this.numChars = numChars;
162
+ this._bitData = bitData.slice();
163
+ }
164
+
165
+ getData() {
166
+ return this._bitData.slice();
167
+ }
168
+ }
169
+
170
+ /* ---- QR Code symbol class ---- */
171
+
172
+ const MIN_VERSION = 1;
173
+ const MAX_VERSION = 40;
174
+
175
+ const PENALTY_N1 = 3;
176
+ const PENALTY_N2 = 3;
177
+ const PENALTY_N3 = 40;
178
+ const PENALTY_N4 = 10;
179
+
180
+ const ECC_CODEWORDS_PER_BLOCK = [
181
+ [
182
+ -1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30,
183
+ 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
184
+ ],
185
+ [
186
+ -1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28,
187
+ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
188
+ ],
189
+ [
190
+ -1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30,
191
+ 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
192
+ ],
193
+ [
194
+ -1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30,
195
+ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
196
+ ],
197
+ ];
198
+
199
+ const NUM_ERROR_CORRECTION_BLOCKS = [
200
+ [
201
+ -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,
202
+ 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25,
203
+ ],
204
+ [
205
+ -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,
206
+ 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49,
207
+ ],
208
+ [
209
+ -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,
210
+ 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68,
211
+ ],
212
+ [
213
+ -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,
214
+ 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81,
215
+ ],
216
+ ];
217
+
218
+ class QrCode {
219
+ static encodeText(text, ecl) {
220
+ const segs = QrSegment.makeSegments(text);
221
+ return QrCode.encodeSegments(segs, ecl);
222
+ }
223
+
224
+ static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
225
+ if (
226
+ !(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) ||
227
+ mask < -1 ||
228
+ mask > 7
229
+ ) {
230
+ throw new RangeError('Invalid value');
231
+ }
232
+
233
+ let version, dataUsedBits;
234
+ for (version = minVersion; ; version++) {
235
+ const dataCapacityBits = QrCode._getNumDataCodewords(version, ecl) * 8;
236
+ const usedBits = QrSegment.getTotalBits(segs, version);
237
+ if (usedBits <= dataCapacityBits) {
238
+ dataUsedBits = usedBits;
239
+ break;
240
+ }
241
+ if (version >= maxVersion) {
242
+ throw new RangeError('Data too long');
243
+ }
244
+ }
245
+
246
+ for (const newEcl of [Ecc.MEDIUM, Ecc.QUARTILE, Ecc.HIGH]) {
247
+ if (boostEcl && dataUsedBits <= QrCode._getNumDataCodewords(version, newEcl) * 8) {
248
+ ecl = newEcl;
249
+ }
250
+ }
251
+
252
+ const bb = [];
253
+ for (const seg of segs) {
254
+ appendBits(seg.mode.modeBits, 4, bb);
255
+ appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
256
+ for (const b of seg.getData()) {
257
+ bb.push(b);
258
+ }
259
+ }
260
+
261
+ const dataCapacityBits = QrCode._getNumDataCodewords(version, ecl) * 8;
262
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
263
+ appendBits(0, (8 - (bb.length % 8)) % 8, bb);
264
+
265
+ for (let padByte = 0xec; bb.length < dataCapacityBits; padByte ^= 0xec ^ 0x11) {
266
+ appendBits(padByte, 8, bb);
267
+ }
268
+
269
+ const dataCodewords = [];
270
+ while (dataCodewords.length * 8 < bb.length) {
271
+ dataCodewords.push(0);
272
+ }
273
+ bb.forEach((b, i) => {
274
+ dataCodewords[i >>> 3] |= b << (7 - (i & 7));
275
+ });
276
+
277
+ return new QrCode(version, ecl, dataCodewords, mask);
278
+ }
279
+
280
+ constructor(version, errorCorrectionLevel, dataCodewords, msk) {
281
+ if (version < MIN_VERSION || version > MAX_VERSION) {
282
+ throw new RangeError('Version value out of range');
283
+ }
284
+ if (msk < -1 || msk > 7) {
285
+ throw new RangeError('Mask value out of range');
286
+ }
287
+ this.version = version;
288
+ this.errorCorrectionLevel = errorCorrectionLevel;
289
+ this.size = version * 4 + 17;
290
+
291
+ const row = [];
292
+ for (let i = 0; i < this.size; i++) {
293
+ row.push(false);
294
+ }
295
+ this._modules = [];
296
+ this._isFunction = [];
297
+ for (let i = 0; i < this.size; i++) {
298
+ this._modules.push(row.slice());
299
+ this._isFunction.push(row.slice());
300
+ }
301
+
302
+ this._drawFunctionPatterns();
303
+ const allCodewords = this._addEccAndInterleave(dataCodewords);
304
+ this._drawCodewords(allCodewords);
305
+
306
+ if (msk === -1) {
307
+ let minPenalty = 1000000000;
308
+ for (let i = 0; i < 8; i++) {
309
+ this._applyMask(i);
310
+ this._drawFormatBits(i);
311
+ const penalty = this._getPenaltyScore();
312
+ if (penalty < minPenalty) {
313
+ msk = i;
314
+ minPenalty = penalty;
315
+ }
316
+ this._applyMask(i);
317
+ }
318
+ }
319
+ this.mask = msk;
320
+ this._applyMask(msk);
321
+ this._drawFormatBits(msk);
322
+
323
+ this._isFunction = [];
324
+ }
325
+
326
+ getModule(x, y) {
327
+ return x >= 0 && x < this.size && y >= 0 && y < this.size && this._modules[y][x];
328
+ }
329
+
330
+ getModules() {
331
+ return this._modules;
332
+ }
333
+
334
+ _drawFunctionPatterns() {
335
+ for (let i = 0; i < this.size; i++) {
336
+ this._setFunctionModule(6, i, i % 2 === 0);
337
+ this._setFunctionModule(i, 6, i % 2 === 0);
338
+ }
339
+
340
+ this._drawFinderPattern(3, 3);
341
+ this._drawFinderPattern(this.size - 4, 3);
342
+ this._drawFinderPattern(3, this.size - 4);
343
+
344
+ const alignPatPos = this._getAlignmentPatternPositions();
345
+ const numAlign = alignPatPos.length;
346
+ for (let i = 0; i < numAlign; i++) {
347
+ for (let j = 0; j < numAlign; j++) {
348
+ if (
349
+ !(
350
+ (i === 0 && j === 0) ||
351
+ (i === 0 && j === numAlign - 1) ||
352
+ (i === numAlign - 1 && j === 0)
353
+ )
354
+ ) {
355
+ this._drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
356
+ }
357
+ }
358
+ }
359
+
360
+ this._drawFormatBits(0);
361
+ this._drawVersion();
362
+ }
363
+
364
+ _drawFormatBits(mask) {
365
+ const data = (this.errorCorrectionLevel.formatBits << 3) | mask;
366
+ let rem = data;
367
+ for (let i = 0; i < 10; i++) {
368
+ rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
369
+ }
370
+ const bits = ((data << 10) | rem) ^ 0x5412;
371
+
372
+ for (let i = 0; i <= 5; i++) {
373
+ this._setFunctionModule(8, i, getBit(bits, i));
374
+ }
375
+ this._setFunctionModule(8, 7, getBit(bits, 6));
376
+ this._setFunctionModule(8, 8, getBit(bits, 7));
377
+ this._setFunctionModule(7, 8, getBit(bits, 8));
378
+ for (let i = 9; i < 15; i++) {
379
+ this._setFunctionModule(14 - i, 8, getBit(bits, i));
380
+ }
381
+
382
+ for (let i = 0; i < 8; i++) {
383
+ this._setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
384
+ }
385
+ for (let i = 8; i < 15; i++) {
386
+ this._setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
387
+ }
388
+ this._setFunctionModule(8, this.size - 8, true);
389
+ }
390
+
391
+ _drawVersion() {
392
+ if (this.version < 7) return;
393
+
394
+ let rem = this.version;
395
+ for (let i = 0; i < 12; i++) {
396
+ rem = (rem << 1) ^ ((rem >>> 11) * 0x1f25);
397
+ }
398
+ const bits = (this.version << 12) | rem;
399
+
400
+ for (let i = 0; i < 18; i++) {
401
+ const color = getBit(bits, i);
402
+ const a = this.size - 11 + (i % 3);
403
+ const b = Math.floor(i / 3);
404
+ this._setFunctionModule(a, b, color);
405
+ this._setFunctionModule(b, a, color);
406
+ }
407
+ }
408
+
409
+ _drawFinderPattern(x, y) {
410
+ for (let dy = -4; dy <= 4; dy++) {
411
+ for (let dx = -4; dx <= 4; dx++) {
412
+ const dist = Math.max(Math.abs(dx), Math.abs(dy));
413
+ const xx = x + dx;
414
+ const yy = y + dy;
415
+ if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size) {
416
+ this._setFunctionModule(xx, yy, dist !== 2 && dist !== 4);
417
+ }
418
+ }
419
+ }
420
+ }
421
+
422
+ _drawAlignmentPattern(x, y) {
423
+ for (let dy = -2; dy <= 2; dy++) {
424
+ for (let dx = -2; dx <= 2; dx++) {
425
+ this._setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);
426
+ }
427
+ }
428
+ }
429
+
430
+ _setFunctionModule(x, y, isDark) {
431
+ this._modules[y][x] = isDark;
432
+ this._isFunction[y][x] = true;
433
+ }
434
+
435
+ _addEccAndInterleave(data) {
436
+ const ver = this.version;
437
+ const ecl = this.errorCorrectionLevel;
438
+ if (data.length !== QrCode._getNumDataCodewords(ver, ecl)) {
439
+ throw new RangeError('Invalid argument');
440
+ }
441
+
442
+ const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
443
+ const blockEccLen = ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
444
+ const rawCodewords = Math.floor(QrCode._getNumRawDataModules(ver) / 8);
445
+ const numShortBlocks = numBlocks - (rawCodewords % numBlocks);
446
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
447
+
448
+ const blocks = [];
449
+ const rsDiv = QrCode._reedSolomonComputeDivisor(blockEccLen);
450
+ for (let i = 0, k = 0; i < numBlocks; i++) {
451
+ const dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
452
+ k += dat.length;
453
+ const ecc = QrCode._reedSolomonComputeRemainder(dat, rsDiv);
454
+ if (i < numShortBlocks) {
455
+ dat.push(0);
456
+ }
457
+ blocks.push(dat.concat(ecc));
458
+ }
459
+
460
+ const result = [];
461
+ for (let i = 0; i < blocks[0].length; i++) {
462
+ blocks.forEach((block, j) => {
463
+ if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks) {
464
+ result.push(block[i]);
465
+ }
466
+ });
467
+ }
468
+ return result;
469
+ }
470
+
471
+ _drawCodewords(data) {
472
+ if (data.length !== Math.floor(QrCode._getNumRawDataModules(this.version) / 8)) {
473
+ throw new RangeError('Invalid argument');
474
+ }
475
+ let i = 0;
476
+ for (let right = this.size - 1; right >= 1; right -= 2) {
477
+ if (right === 6) right = 5;
478
+ for (let vert = 0; vert < this.size; vert++) {
479
+ for (let j = 0; j < 2; j++) {
480
+ const x = right - j;
481
+ const upward = ((right + 1) & 2) === 0;
482
+ const y = upward ? this.size - 1 - vert : vert;
483
+ if (!this._isFunction[y][x] && i < data.length * 8) {
484
+ this._modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
485
+ i++;
486
+ }
487
+ }
488
+ }
489
+ }
490
+ }
491
+
492
+ _applyMask(mask) {
493
+ if (mask < 0 || mask > 7) {
494
+ throw new RangeError('Mask value out of range');
495
+ }
496
+ for (let y = 0; y < this.size; y++) {
497
+ for (let x = 0; x < this.size; x++) {
498
+ let invert;
499
+ switch (mask) {
500
+ case 0:
501
+ invert = (x + y) % 2 === 0;
502
+ break;
503
+ case 1:
504
+ invert = y % 2 === 0;
505
+ break;
506
+ case 2:
507
+ invert = x % 3 === 0;
508
+ break;
509
+ case 3:
510
+ invert = (x + y) % 3 === 0;
511
+ break;
512
+ case 4:
513
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
514
+ break;
515
+ case 5:
516
+ invert = ((x * y) % 2) + ((x * y) % 3) === 0;
517
+ break;
518
+ case 6:
519
+ invert = (((x * y) % 2) + ((x * y) % 3)) % 2 === 0;
520
+ break;
521
+ case 7:
522
+ invert = (((x + y) % 2) + ((x * y) % 3)) % 2 === 0;
523
+ break;
524
+ default:
525
+ throw new Error('Unreachable');
526
+ }
527
+ if (!this._isFunction[y][x] && invert) {
528
+ this._modules[y][x] = !this._modules[y][x];
529
+ }
530
+ }
531
+ }
532
+ }
533
+
534
+ _getPenaltyScore() {
535
+ let result = 0;
536
+
537
+ for (let y = 0; y < this.size; y++) {
538
+ let runColor = false;
539
+ let runX = 0;
540
+ const runHistory = [0, 0, 0, 0, 0, 0, 0];
541
+ for (let x = 0; x < this.size; x++) {
542
+ if (this._modules[y][x] === runColor) {
543
+ runX++;
544
+ if (runX === 5) result += PENALTY_N1;
545
+ else if (runX > 5) result++;
546
+ } else {
547
+ this._finderPenaltyAddHistory(runX, runHistory);
548
+ if (!runColor) {
549
+ result += this._finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
550
+ }
551
+ runColor = this._modules[y][x];
552
+ runX = 1;
553
+ }
554
+ }
555
+ result += this._finderPenaltyTerminateAndCount(runColor, runX, runHistory) * PENALTY_N3;
556
+ }
557
+
558
+ for (let x = 0; x < this.size; x++) {
559
+ let runColor = false;
560
+ let runY = 0;
561
+ const runHistory = [0, 0, 0, 0, 0, 0, 0];
562
+ for (let y = 0; y < this.size; y++) {
563
+ if (this._modules[y][x] === runColor) {
564
+ runY++;
565
+ if (runY === 5) result += PENALTY_N1;
566
+ else if (runY > 5) result++;
567
+ } else {
568
+ this._finderPenaltyAddHistory(runY, runHistory);
569
+ if (!runColor) {
570
+ result += this._finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
571
+ }
572
+ runColor = this._modules[y][x];
573
+ runY = 1;
574
+ }
575
+ }
576
+ result += this._finderPenaltyTerminateAndCount(runColor, runY, runHistory) * PENALTY_N3;
577
+ }
578
+
579
+ for (let y = 0; y < this.size - 1; y++) {
580
+ for (let x = 0; x < this.size - 1; x++) {
581
+ const color = this._modules[y][x];
582
+ if (
583
+ color === this._modules[y][x + 1] &&
584
+ color === this._modules[y + 1][x] &&
585
+ color === this._modules[y + 1][x + 1]
586
+ ) {
587
+ result += PENALTY_N2;
588
+ }
589
+ }
590
+ }
591
+
592
+ let dark = 0;
593
+ for (const row of this._modules) {
594
+ dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
595
+ }
596
+ const total = this.size * this.size;
597
+ const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
598
+ result += k * PENALTY_N4;
599
+ return result;
600
+ }
601
+
602
+ _getAlignmentPatternPositions() {
603
+ if (this.version === 1) return [];
604
+ const numAlign = Math.floor(this.version / 7) + 2;
605
+ const step =
606
+ this.version === 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
607
+ const result = [6];
608
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step) {
609
+ result.splice(1, 0, pos);
610
+ }
611
+ return result;
612
+ }
613
+
614
+ _finderPenaltyCountPatterns(runHistory) {
615
+ const n = runHistory[1];
616
+ const core =
617
+ n > 0 &&
618
+ runHistory[2] === n &&
619
+ runHistory[3] === n * 3 &&
620
+ runHistory[4] === n &&
621
+ runHistory[5] === n;
622
+ return (
623
+ (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) +
624
+ (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0)
625
+ );
626
+ }
627
+
628
+ _finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
629
+ if (currentRunColor) {
630
+ this._finderPenaltyAddHistory(currentRunLength, runHistory);
631
+ currentRunLength = 0;
632
+ }
633
+ currentRunLength += this.size;
634
+ this._finderPenaltyAddHistory(currentRunLength, runHistory);
635
+ return this._finderPenaltyCountPatterns(runHistory);
636
+ }
637
+
638
+ _finderPenaltyAddHistory(currentRunLength, runHistory) {
639
+ if (runHistory[0] === 0) {
640
+ currentRunLength += this.size;
641
+ }
642
+ runHistory.pop();
643
+ runHistory.unshift(currentRunLength);
644
+ }
645
+
646
+ static _getNumRawDataModules(ver) {
647
+ if (ver < MIN_VERSION || ver > MAX_VERSION) {
648
+ throw new RangeError('Version number out of range');
649
+ }
650
+ let result = (16 * ver + 128) * ver + 64;
651
+ if (ver >= 2) {
652
+ const numAlign = Math.floor(ver / 7) + 2;
653
+ result -= (25 * numAlign - 10) * numAlign - 55;
654
+ if (ver >= 7) result -= 36;
655
+ }
656
+ return result;
657
+ }
658
+
659
+ static _getNumDataCodewords(ver, ecl) {
660
+ return (
661
+ Math.floor(QrCode._getNumRawDataModules(ver) / 8) -
662
+ ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver]
663
+ );
664
+ }
665
+
666
+ static _reedSolomonComputeDivisor(degree) {
667
+ if (degree < 1 || degree > 255) {
668
+ throw new RangeError('Degree out of range');
669
+ }
670
+ const result = [];
671
+ for (let i = 0; i < degree - 1; i++) {
672
+ result.push(0);
673
+ }
674
+ result.push(1);
675
+
676
+ let root = 1;
677
+ for (let i = 0; i < degree; i++) {
678
+ for (let j = 0; j < result.length; j++) {
679
+ result[j] = QrCode._reedSolomonMultiply(result[j], root);
680
+ if (j + 1 < result.length) {
681
+ result[j] ^= result[j + 1];
682
+ }
683
+ }
684
+ root = QrCode._reedSolomonMultiply(root, 0x02);
685
+ }
686
+ return result;
687
+ }
688
+
689
+ static _reedSolomonComputeRemainder(data, divisor) {
690
+ const result = divisor.map(() => 0);
691
+ for (const b of data) {
692
+ const factor = b ^ result.shift();
693
+ result.push(0);
694
+ divisor.forEach((coef, i) => {
695
+ result[i] ^= QrCode._reedSolomonMultiply(coef, factor);
696
+ });
697
+ }
698
+ return result;
699
+ }
700
+
701
+ static _reedSolomonMultiply(x, y) {
702
+ if (x >>> 8 !== 0 || y >>> 8 !== 0) {
703
+ throw new RangeError('Byte out of range');
704
+ }
705
+ let z = 0;
706
+ for (let i = 7; i >= 0; i--) {
707
+ z = (z << 1) ^ ((z >>> 7) * 0x11d);
708
+ z ^= ((y >>> i) & 1) * x;
709
+ }
710
+ return z;
711
+ }
712
+ }
713
+
714
+ module.exports = { QrCode, QrSegment, Ecc };