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