@sythos/js_barcode_universal 1.1.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +24 -18
  2. package/NOTICE.md +27 -22
  3. package/README.md +596 -460
  4. package/bundle/sythos-barcode.esm.js +4606 -228
  5. package/bundle/sythos-barcode.js +4586 -228
  6. package/examples/create.html +1011 -731
  7. package/licenses/README.md +23 -18
  8. package/licenses/aztec-code.license +9 -7
  9. package/licenses/codabar.license +16 -13
  10. package/licenses/code-11.license +11 -9
  11. package/licenses/code-128.license +8 -6
  12. package/licenses/code-39.license +8 -6
  13. package/licenses/code-93.license +13 -11
  14. package/licenses/data-matrix.license +11 -9
  15. package/licenses/ean-13.license +7 -5
  16. package/licenses/ean-8.license +7 -5
  17. package/licenses/frameqr.license +84 -0
  18. package/licenses/gs1-128.license +7 -5
  19. package/licenses/isbn.license +8 -6
  20. package/licenses/itf-14.license +7 -5
  21. package/licenses/itf.license +7 -5
  22. package/licenses/micro-qr.license +79 -0
  23. package/licenses/micropdf417.license +81 -0
  24. package/licenses/msi-plessey.license +12 -10
  25. package/licenses/pdf417.license +78 -0
  26. package/licenses/pharmacode.license +13 -11
  27. package/licenses/qr-code.license +7 -5
  28. package/licenses/rmqr.license +79 -0
  29. package/licenses/upc-a.license +9 -7
  30. package/licenses/upc-e.license +7 -5
  31. package/package.json +104 -88
  32. package/src/core/reed-solomon.js +326 -312
  33. package/src/datamatrix/decoder.js +262 -262
  34. package/src/datamatrix/detector.js +225 -225
  35. package/src/datamatrix/encoder.js +191 -191
  36. package/src/datamatrix/index.js +42 -42
  37. package/src/datamatrix/tables.js +123 -123
  38. package/src/frameqr/decoder.js +239 -0
  39. package/src/frameqr/detector.js +192 -0
  40. package/src/frameqr/encoder.js +156 -0
  41. package/src/frameqr/index.js +42 -0
  42. package/src/frameqr/tables.js +270 -0
  43. package/src/index.js +166 -3
  44. package/src/micropdf417/compaction.js +116 -0
  45. package/src/micropdf417/decoder.js +183 -0
  46. package/src/micropdf417/detector.js +149 -0
  47. package/src/micropdf417/encoder.js +209 -0
  48. package/src/micropdf417/error-correction.js +55 -0
  49. package/src/micropdf417/index.js +49 -0
  50. package/src/micropdf417/tables.js +184 -0
  51. package/src/microqr/decoder.js +245 -0
  52. package/src/microqr/detector.js +355 -0
  53. package/src/microqr/encoder.js +269 -0
  54. package/src/microqr/index.js +36 -0
  55. package/src/microqr/tables.js +316 -0
  56. package/src/oned/index.js +59 -59
  57. package/src/pdf417/compaction.js +298 -0
  58. package/src/pdf417/decoder.js +75 -0
  59. package/src/pdf417/detector.js +468 -0
  60. package/src/pdf417/encoder.js +91 -0
  61. package/src/pdf417/error-correction.js +47 -0
  62. package/src/pdf417/index.js +6 -0
  63. package/src/pdf417/tables.js +317 -0
  64. package/src/rmqr/decoder.js +101 -0
  65. package/src/rmqr/detector.js +90 -0
  66. package/src/rmqr/encoder.js +172 -0
  67. package/src/rmqr/index.js +37 -0
  68. package/src/rmqr/tables.js +154 -0
@@ -0,0 +1,317 @@
1
+ /*!
2
+ * Sythos Barcode Suite
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2026 Sythos
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *
26
+ * SPDX-License-Identifier: MIT
27
+ *
28
+ * Original work. No code from any other barcode implementation.
29
+ */
30
+
31
+ /** PDF417 symbol-character pattern table. @module pdf417/tables */
32
+
33
+ export const PDF417_CLUSTER_NUMBERS = Object.freeze([0, 3, 6]);
34
+ export const PDF417_CODEWORDS_PER_CLUSTER = 929;
35
+
36
+ // Transcribed from the normative AIM USS PDF417 specification, Appendix H,
37
+ // Table H1 (Bar-Space Sequence Table), from a publicly accessible copy hosted
38
+ // at https://expresscorp.com/wp-content/uploads/2023/02/USS-PDF-417.pdf.
39
+ // ISO/IEC 15438:2015 is the current ISO specification for PDF417.
40
+ // Each eight-digit sequence is ordered bar, space, bar, space, bar, space,
41
+ // bar, space and is indexed by its codeword value from 0 through 928.
42
+ const WIDTH_SEQUENCES = Object.freeze([
43
+ '3111113641111144511111523111123541111243511112512111132631111334211114251111151621111524111116152111213631112144' +
44
+ '4111215221112235311122434111225111112326211123341111242511113136211131443111315211113235211132433111325111113334' +
45
+ '2111334211114144211141521111424321114251111151525111611131121135411211435112115121121226311212344112124221121325' +
46
+ '3112133311121416211214243112143211121515211215231112161421122135311221434112215111122226211222343112224211122325' +
47
+ '2112233331122341111224242112243211123135211231433112315111123234211232421112333321123341111241432112415111124242' +
48
+ '1112434121131126311311344113114221131225311312334113124111131316211313243113133211131415211314231113151411131613' +
49
+ '1113212621132134311321421113222521132233311322411113232421132332111324231113252211133134211331421113323321133241' +
50
+ '1113333211134142211411253114113341141141111412162114122431141232111413152114132331141331111414142114142211141513' +
51
+ '2114152111142125211421333114214111142224211422321114232321142331111424221114252121143141111433311115111621151124' +
52
+ '3115113211151215211512233115123111151314211513221115141321151421111515121115212411152223111523221116111531161131' +
53
+ '2116122221161321111615113211113542111143521111512211122632111234421112422211132532111333421113411211141622111424' +
54
+ '1211151522112135321121434211215112112226221122343211224212112325221123331211242412112523121131352211314332113151' +
55
+ '1211323422113242121133331211343212114143221141511211424212115151312111264121113451211142312112254121123351211241' +
56
+ '2121131631211324412113322121141531211423412114312121151431211522221211263212113442121142212121262212122532121233' +
57
+ '4212124121212225312122334121224111212316121214152212142332121431112124152121242311212514121221262212213432122142' +
58
+ '1121312612122225221222333212224111213225212132333121324111213324121224231121342312123134221231421121413412123233' +
59
+ '2212324111214233212142411121433212124142112151421212424111215241312211254122113351221141212212163122122441221232' +
60
+ '2122131531221323412213312122141431221422212215132122161222131125321311334213114121222125221312243213123211222216' +
61
+ '1213131531222232321313311122231512131414221314221122241421222422221315211213161212132125221321333213214111223125' +
62
+ '1213222422132232112232242122323222132331112233231213242212132521121331332213314111224133121332321122423212133331' +
63
+ '1122433111225141212311163123112441231132212312153123122341231231212313143123132221231413312314212123151221231611' +
64
+ '1214111622141124321411321123211612141215221412233214123111232215212322233123223111232314121414132214142111232413' +
65
+ '2123242111232512121421242214213211233124121422232214223111233223212332311123332212142421112334211123413211234231' +
66
+ '2124111531241123412411312124121431241222212413133124132121241412212415111215111522151123321511311124211512151214' +
67
+ '2215122211242214212422222215132111242313121514121124241212151511121521231124312311243222112433213125112231251221' +
68
+ '2125141122161122121612131125221311252312112524112311112633111134431111422311122533111233131113162311132433111332' +
69
+ '1311141523111423131115141311161313112126231121343311214213112225231122333311224113112324231123321311242313112522' +
70
+ '1311313423113142131132332311324113113332131141421311424132211125422111335221114122211216322112244221123222211315' +
71
+ '3221132342211331222114143221142222211513322115212312112533121133431211412221212523121224331212321221221613121315' +
72
+ '3221223233121331122123152221232323121422122124141312151312212513131221252312213333122141122131251312222432213141' +
73
+ '1221322422213232231223311221332313122422122134221312313323123141122141331312323212214232131233311312414112215141' +
74
+ '3131111641311124513111323131121541311223513112313131131441311322313114134131142131311512222211163222112442221132' +
75
+ '2131211622221215413121324222123121312215313122234131223121312314222214133222142121312413313124212222161113131116' +
76
+ '2313112433131132122221161313121523131223331312311131311612222215222222233222223111313215213132233131323123131421' +
77
+ '1131331412222413222224211131341313131611131321242313213212223124131322232313223111314124122232232222323111314223' +
78
+ '2131423113132421122234211313313212224132131332311131513212224231313211154132112351321131313212144132122231321313' +
79
+ '4132132131321412313215112223111532231123422311312132211522231214413221312132221431322222322313212132231322231412' +
80
+ '2132241222231511213225111314111523141123331411311223211513141214231412221132311512232214222322222314132111323214' +
81
+ '2132322213141412113233131223241213141511122325111314212323142131122331231314222211324123122332221314232111324222' +
82
+ '1223332113143131113251313133111441331122313312134133122131331312313314112224111432241122213321142224121332241221' +
83
+ '2133221331332221213323122224141121332411131511142315112212242114131512132315122111333114122422132224222111333213' +
84
+ '2133322113151411113333121224241111333411122431221133412211334221413411213134131132251121222512122225131113161113' +
85
+ '1225211311343113131613111225231124111125141112162411122414111315241113233411133114111414241114221411151324111521' +
86
+ '1411212524112133341121411411222424112232141123232411233114112422141125211411313324113141141132321411333114114141' +
87
+ '2321111633211124432111322321121533211223232113143321132223211413332114212321151214121116241211243412113213212116' +
88
+ '1412121533212132341212311321221523212223332122311321231414121413241214211321241323212421141216111412212424122132' +
89
+ '1321312414122223241222311321322323213231132133221412242114123132132141321412323113214231323111154231112352311131' +
90
+ '3231121442311222323113134231132132311412323115112322111533221123223121152322121433221222223122143231222233221321' +
91
+ '2231231323221412223124122322151122312511141311152413112313222115141312143322213112313115132222142322222224131321' +
92
+ '1231321422313222141314121231331313222412141315111322251114132123241321311322312314132222123141231322322214132321' +
93
+ '1231422213223321141331311322413112315131414111145141112241411213514112214141131241411411323211144232112231412114' +
94
+ '4141212242321221314122134141222131412312323214113141241123231114332311222232211423231213332312212141311422322213' +
95
+ '3232222121413213314132212323141121413312223224112141341114141114241411221323211414141213241412211232311413232213' +
96
+ '2323222111414114123232132232322114141411114142132141422113232411114143121414212213233122141422211232412213233221' +
97
+ '1141512212324221114152214142111351421121414212124142131132331113423311213142211341422121314222123233131131422311' +
98
+ '2324111333241121223321132324121221423113223322122324131121423212223323112142331114151113241511211324211323242121' +
99
+ '1233311313242212141513111142411312333212132423111142421212333311114243111324312111425121414312113143211231432211' +
100
+ '2234211221433112214332111325211212343112114341121143421115111116151112152511122315111314151114131511151215112124' +
101
+ '1511222315112322151124211511313215113231242111152421121434211222242113133421132124211412242115111512111525121123' +
102
+ '1421211524212123251212221421221424212222142123132421232114212412151215111421251115122123251221311421312324213131' +
103
+ '1421322215122321142133211512313114214131333111143331121333311312333114112422111423312114333121223422122123312213' +
104
+ '3331222123312312242214112331241115131114142221141513121325131221133131141422221315131312133132131422231215131411' +
105
+ '1331331214222411151321221422312215132221133141221422322113314221424111134241121242411311333211133241211342412121' +
106
+ '3241221233321311324123112423111334231121233221133332212122413113233222122423131122413212233223112241331115141113' +
107
+ '2514112114232113242321211332311314232212151413111241411313323212142323111241421213323311151421211423312113324121' +
108
+ '1241512151511112515112114242111241512112424212114151221133331112324221123333121131513112324222113151321124241112' +
109
+ '2333211224241211224231122333221121514112',
110
+ '5111112561111133411112165111122461111232411113155111132361111331411114145111142241111513511115214111161241112125' +
111
+ '5111213361112141311122164111222451112232311123154111232351112331311124144111242231112513411125213111261231113125' +
112
+ '4111313351113141211132163111322441113232211133153111332341113331211134143111342221113513311135212111361221114125' +
113
+ '3111413341114141111142162111422431114232111143152111432331114331111144142111442211114513211145211111512521115133' +
114
+ '3111514111115224211152321111532321115331111154221111613321116141111162321111633141121116511211246112113241121215' +
115
+ '5112122361121231411213145112132241121413511214214112151241121611311221164112212451122132311222154112222351122231' +
116
+ '3112231441122322311224134112242131122512311226112112311631123124411231322112321531123223411232312112331431123322' +
117
+ '2112341331123421211235122112361111124116211241243112413211124215211242233112423111124314211243221112441321124421' +
118
+ '1112451211125124211251321112522321125231111253221112542111126132111262314113111551131123611311314113121451131222' +
119
+ '4113131351131321411314124113151131132115411321235113213131132214411322223113231341132321311324123113251121133115' +
120
+ '3113312341133131211332143113322221133313311333212113341221133511111341152113412331134131111342142113422211134313' +
121
+ '2113432111134412111345111113512321135131111352221113532111136131411411145114112241141213511412214114131241141411' +
122
+ '3114211441142122311422134114222131142312311424112114311431143122211432133114322121143312211434111114411421144122' +
123
+ '1114421321144221111443121114441111145122111452214115111351151121411512124115131131152113411521213115221231152311' +
124
+ '2115311331153121211532122115331111154113211541211115421211154311411611124116121131162112311622112116311221163211' +
125
+ '4211111652111124621111324211121552111223621112314211131452111322421114135211142142111512421116113211211642112124' +
126
+ '5211213232112215421122235211223132112314421123223211241342112421321125123211261122113116321131244211313222113215' +
127
+ '3211322342113231221133143211332222113413321134212211351222113611121141162211412432114132121142152211422332114231' +
128
+ '1211431422114322121144132211442112114512121151242211513212115223221152311211532212115421121161321211623151211115' +
129
+ '6121112311211164512112146121122211211263512113136121132111211362512114125121151142121115521211236212113141212115' +
130
+ '4212121461212131412122145121222252121321412123134212141241212412421215114121251132122115421221235212213131213115' +
131
+ '3212221442122222312132144121322242122321312133133212241231213412321225113121351122123115321231234212313121214115' +
132
+ '2212321432123222212142143121422232123321212143132212341221214412221235112121451112124115221241233212413111215115' +
133
+ '1212421422124222112152142121522222124321112153131212441211215412121245111212512322125131112161231212522211216222' +
134
+ '1212532111216321121261315122111461221122112211635122121361221221112212625122131211221361512214114213111452131122' +
135
+ '4122211442131213521312214122221351222221412223124213141141222411321321144213212231223114321322134213222131223213' +
136
+ '4122322131223312321324113122341122133114321331222122411422133213321332212122421331224221212243122213341121224411' +
137
+ '1213411422134122112251141213421322134221112252132122522111225312121344111122541112135122112261221213522111226221' +
138
+ '5123111361231121112311625123121211231261512313114214111352141121412321135123212141232212421413114123231132142113' +
139
+ '4214212131233113321422123123321232142311312333112214311332143121212341133123412121234212221433112123431112144113' +
140
+ '2214412111235113121442121123521212144311112353111214512111236121512411121124116151241211421511124124211242151211' +
141
+ '4124221132152112312431123215221131243211221531122124411222153211212442111215411211245112121542111124521151251111' +
142
+ '4216111141252111321621113125311122163111212541114311111553111123631111314311121453111222431113135311132143111412' +
143
+ '4311151133112115431121235311213133112214431122223311231343112321331124123311251123113115331131234311313123113214' +
144
+ '3311322223113313331133212311341223113511131141152311412333114131131142142311422213114313231143211311441213114511' +
145
+ '1311512323115131131152221311532113116131522111146221112212211163522112136221122112211262522113121221136152211411' +
146
+ '4312111453121122422121144312121353121221422122135221222142212312431214114221241133122114431221223221311433122213' +
147
+ '4312222132213213422132213221331233122411322134112312311433123122222141142312321333123221222142133221422122214312' +
148
+ '2312341122214411131241142312412212215114131242132312422112215213222152211221531213124411122154111312512212216122' +
149
+ '1312522112216221613111131131115421311162613112121131125321311261613113111131135211311451522211136222112112221162' +
150
+ '5131211361312121113121621222126151312212522213111131226151312311431311135313112142222113431312124131311351313121' +
151
+ '4313131141313212422223114131331133132113431321213222311333132212313141133222321233132311313142123222331131314311' +
152
+ '2313311333133121222241132313321221315113222242122313331121315212222243112131531113134113231341211222511313134212' +
153
+ '1131611312225212131343111131621212225311113163111313512112226121613211121132115321321161613212111132125211321351' +
154
+ '5223111212231161513221125223121111322161513222114314111242232112431412114132311242232211413232113314211232233112' +
155
+ '3314221131324112322332113132421123143112222341122314321121325112222342112132521113144112122351121314421111326112' +
156
+ '1223521111326211613311111133115211331251522411115133211143151111422421114133311133152111322431113133411123153111' +
157
+ '2224411121335111131541111224511111336111113411514411111454111122441112135411122144111312441114113411211444112122' +
158
+ '3411221344112221341123123411241124113114341131222411321334113221241133122411341114114114241141221411421324114221' +
159
+ '1411431214114411141151221411522153211113632111211321116253211212132112615321131144121113541211214321211344121212' +
160
+ '4321221244121311432123113412211344122121332131133412221233213212341223113321331124123113341231212321411324123212' +
161
+ '2321421224123311232143111412411324124121132151131412421213215212141243111321531114125121132161216231111212311153' +
162
+ '2231116162311211123112521231135153221112132211615231211253221211123121615231221144131112432221124413121142313112' +
163
+ '4322221142313211341321123322311234132211323141123322321132314211241331122322411224133211223151122322421122315211' +
164
+ '1413411213225112141342111231611213225211123162111141114421411152114112432141125111411342114114416232111112321152' +
165
+ '6141211111412152123212511141225153231111523221115141311144141111432321114232311141414111341421113323311132324111' +
166
+ '3141511124143111232341112232511121416111141441111323511112326111114211432142115111421242114213411233115111422151' +
167
+ '1143114211431241114411414511111345111212451113113511211345112121351122123511231125113113351131212511321225113311' +
168
+ '1511411325114121151142121511431115115121542111121421116154211211451211124421211245121211442122113512211234213112' +
169
+ '3512221134213211251231122421411225123211242142111512411214215112151242111421521163311111133111521331125154221111' +
170
+ '5331211145131111442221114331311135132111342231113331411125133111242241112331511115134111142251111331611112411143' +
171
+ '2241115112411242124113411332115112412151115111342151114211511233215112411151133211511431124211421151214212421241' +
172
+ '1151224111521133215211411152123211521331124311411152214111531132115312311154113136112112361122112611311226113211' +
173
+ '1611411216114211452121113612211135213111261231112521411116124111152151111431115113411142134112411251113322511141' +
174
+ '1251123212511331134211411251214111611124216111321161122321611231116113221161142112521132116121321252123111612231' +
175
+ '1162112321621131116212221162132112531131116221311163112211631221144111411351113213511231126111232261113112611222' +
176
+ '1261132113521131126121311262112212621221',
177
+ '2111115531111163111112462111125431111262111113452111135331111361111114442111145211111543611121141111215521112163' +
178
+ '6111221311112254211122626111231211112353211123616111241111112452511131146111312211113163511132136111322111113262' +
179
+ '5111331211113361511134114111411451114122411142135111422141114312411144113111511441115122311152134111522131115312' +
180
+ '3111541121116114311161222111621331116221211163121112114621121154311211621112124521121253311212611112134421121352' +
181
+ '1112144321121451111215426112211311122154211221626112221211122253211222616112231111122352111224515112311361123121' +
182
+ '1112316251123212111232615112331141124113511241214112421241124311311251134112512131125212311253112112611331126121' +
183
+ '2112621221126311111311452113115331131161111312442113125211131343211313511113144211131541611321121113215321132161' +
184
+ '6113221111132252111323515113311211133161511332114113411241134211311351123113521121136112211362111114114421141152' +
185
+ '1114124321141251111413421114144161142111111421521114225151143111411441113114511111151143211511511115124211151341' +
186
+ '1115215111161142111612411211114622111154321111621211124522111253321112611211134422111352121114432211145112111542' +
187
+ '6211211312112154221121626211221212112253221122616211231112112352121124515211311362113121121131625211321212113261' +
188
+ '5211331142114113521141214211421242114311321151134211512132115212321153112211611332116121221162122211631121211145' +
189
+ '3121115341211161112112362121124431211252112113352121134331211351112114342121144211211533212115411121163212121145' +
190
+ '2212115332121161112121451212124422121252112122442121225222121351112123431212144211212442121215411121254162122112' +
191
+ '1212215322122161612131126212221111213153121222526121321111213252121223511121335152123112121231615121411252123211' +
192
+ '1121416151214211421241124121511242124211412152113212511231216112321252113121621122126112221262111122113621221144' +
193
+ '3122115211221235212212433122125111221334212213421122143321221441112215321122163112131144221311521122214412131243' +
194
+ '2213125111222243212222511122234212131441112224416213211112132152612231111122315212132251112232515213311151224111' +
195
+ '4213411141225111321351113122611122136111112311352123114331231151112312342123124211231333212313411123143211231531' +
196
+ '1214114322141151112321431214124211232242121413411123234112142151112331511124113421241142112412332124124111241332' +
197
+ '1124143112151142112421421215124111242241112511332125114111251232112513311216114111252141112611321126123113111145' +
198
+ '2311115333111161131112442311125213111343231113511311144213111541631121121311215323112161631122111311225213112351' +
199
+ '5311311213113161531132114311411243114211331151123311521123116112231162111221113622211144322111521221123522211243' +
200
+ '3221125112211334222113421221143322211441122115321221163113121144231211521221214413121243231212511221224322212251' +
201
+ '1221234213121441122124416312211113122152622131111221315213122251122132515312311152214111431241114221511133125111' +
202
+ '3221611123126111213111353131114341311151113112262131123431311242113113252131133331311341113114242131143211311523' +
203
+ '2131153111311622122211352222114332221151113121351222123422221242113122342131224222221341113123331222143211312432' +
204
+ '1222153111312531131311432313115112222143131312421131314312222242131313411131324212222341113133411313215112223151' +
205
+ '1131415111321126213211343132114211321225213212333132124111321324213213321132142321321431113215221132162112231134' +
206
+ '2223114211322134122312332223124111322233213222411132233212231431113224311314114212232142131412411132314212232241' +
207
+ '1132324111331125213311333133114111331224213312321133132321331331113314221133152112241133222411411133213312241232' +
208
+ '1133223212241331113323311315114112242141113331411134112421341132113412232134123111341322113414211225113211342132' +
209
+ '1225123111342231113511232135113111351222113513211226113111352131113611221136122114111144241111521411124324111251' +
210
+ '1411134214111441141121521411225154113111441141113411511124116111132111352321114333211151132112342321124213211333' +
211
+ '2321134113211432132115311412114324121151132121431412124213212242141213411321234114122151132131511231112622311134' +
212
+ '3231114212311225223112333231124112311324223113321231142322311431123115221231162113221134232211421231213413221233' +
213
+ '2322124112312233132213321231233213221431123124311413114213222142141312411231314213222241123132412141112531411133' +
214
+ '4141114111411216214112243141123211411315214113233141133111411414214114221141151321411521114116121232112522321133' +
215
+ '3232114111412125123212242232123211412224214122322232133111412323123214221141242212321521114125211323113323231141' +
216
+ '1232213313231232114131331232223213231331114132321232233111413331141411411323214112323141114141411142111621421124' +
217
+ '3142113211421215214212233142123111421314214213221142141321421421114215121142161112331124223311321142212412331223' +
218
+ '2233123111422223214222311142232212331421114224211324113212332132132412311142313212332231114232311143111521431123' +
219
+ '3143113111431214214312221143131321431321114314121143151112341123223411311143212312341222114322221234132111432321' +
220
+ '1325113112342131114331311144111421441122114412132144122111441312114414111235112211442122123512211144222111451113' +
221
+ '2145112111451212114513111236112111452121151111432511115115111242151113411511215114211134242111421421123324211241' +
222
+ '1421133214211431151211421421214215121241142122411331112523311133333111411331122423311232133113232331133113311422' +
223
+ '1331152114221133242211411331213314221232133122321422133113312331151311411422214113313141124111162241112432411132' +
224
+ '1241121522411223324112311241131422411322124114132241142112411512124116111332112423321132124121241332122323321231' +
225
+ '1241222322412231124123221332142112412421142311321332213214231231124131321332223112413231215111153151112341511131' +
226
+ '2151121431511222215113133151132121511412215115111242111522421123324211311151211512421214224212221151221421512222' +
227
+ '2242132111512313124214121151241212421511115125111333112323331131124221231333122211513123124222221333132111513222' +
228
+ '1242232111513321142411311333213112423131115141312152111431521122215212133152122121521312215214111243111422431122' +
229
+ '1152211412431213224312211152221321522221115223121243141111522411133411221243212213341221115231221243222111523221' +
230
+ '2153111331531121215312122153131112441113224411211153211312441212115322121244131111532311133511211244212111533121' +
231
+ '2154111221541211124511121154211212451211115422111611114216111241152111332521114115211232152113311612114115212141' +
232
+ '1431112424311132143112232431123114311322143114211522113214312132152212311431223113411115234111233341113113411214' +
233
+ '2341122213411313234113211341141213411511143211232432113113412123234121311341222214321321134123211523113114322131' +
234
+ '1341313122511114325111222251121332511221225113122251141113421114234211221251211422512122234212211251221313421312' +
235
+ '1251231213421411125124111433112213422122143312211251312213422221125132213161111341611121316112123161131122521113' +
236
+ '3252112121612113225212122161221222521311216123111343111323431121125221131343121211613113125222121343131111613212' +
237
+ '1252231111613311143411211343212112523121116141213162111231621211225311122162211222531211216222111344111212532112' +
238
+ '1344121111623112125322111162321131631111225411112163211113451111125421111163311116211132162112311531112325311131' +
239
+ '1531122215311321162211311531213114411114244111221441121324411221144113121441141115321122144121221532122114412221' +
240
+ '2351111333511121235112122351131114421113244211211351211323512121135122121442131113512311153311211442212113513121' +
241
+ '3261111232611211235211122261211223521211226122111443111213522112144312111261311213522211126132113262111123531111' +
242
+ '2262211114441111135321111262311116311122163112211541111325411121154112121541131116321121154121212451111224511211' +
243
+ '1542111214512112154212111451221133611111',
244
+ ]);
245
+
246
+ function patternFromWidths(sequence) {
247
+ let pattern = 0;
248
+ for (let element = 0; element < 8; element++) {
249
+ const width = sequence.charCodeAt(element) - 48;
250
+ const dark = (element & 1) === 0;
251
+ for (let i = 0; i < width; i++) pattern = (pattern << 1) | (dark ? 1 : 0);
252
+ }
253
+ return pattern;
254
+ }
255
+
256
+ /** Return the cluster discriminator for an eight-element bar/space sequence. */
257
+ export function pdf417ClusterForWidths(widths) {
258
+ if (!widths || widths.length !== 8) throw new Error('PDF417: a character requires eight element widths');
259
+ return ((widths[0] - widths[2] + widths[4] - widths[6]) % 9 + 9) % 9;
260
+ }
261
+
262
+ function buildPatternTable() {
263
+ const tables = WIDTH_SEQUENCES.map((source, tableIndex) => {
264
+ if (source.length !== PDF417_CODEWORDS_PER_CLUSTER * 8) throw new Error('PDF417: corrupt pattern-table length');
265
+ const expectedCluster = PDF417_CLUSTER_NUMBERS[tableIndex];
266
+ const table = new Int32Array(PDF417_CODEWORDS_PER_CLUSTER);
267
+ const seen = new Set();
268
+ for (let codeword = 0; codeword < PDF417_CODEWORDS_PER_CLUSTER; codeword++) {
269
+ const sequence = source.slice(codeword * 8, codeword * 8 + 8);
270
+ const widths = Array.from(sequence, (digit) => digit.charCodeAt(0) - 48);
271
+ if (widths.some((width) => width < 1 || width > 6) || widths.reduce((sum, width) => sum + width, 0) !== 17) {
272
+ throw new Error('PDF417: corrupt pattern-table width');
273
+ }
274
+ if (pdf417ClusterForWidths(widths) !== expectedCluster) throw new Error('PDF417: corrupt pattern-table cluster');
275
+ const pattern = patternFromWidths(sequence);
276
+ if (seen.has(pattern)) throw new Error('PDF417: duplicate pattern in cluster');
277
+ seen.add(pattern);
278
+ table[codeword] = pattern;
279
+ }
280
+ return Object.freeze(Array.from(table));
281
+ });
282
+ return Object.freeze(tables);
283
+ }
284
+
285
+ /** Pattern table indexed by cluster index (0, 1, 2) and codeword value. */
286
+ export const PDF417_PATTERN_TABLE = buildPatternTable();
287
+ const PATTERN_TO_CODEWORD = new Map();
288
+ for (let index = 0; index < PDF417_PATTERN_TABLE.length; index++) {
289
+ for (let codeword = 0; codeword < PDF417_CODEWORDS_PER_CLUSTER; codeword++) {
290
+ PATTERN_TO_CODEWORD.set(PDF417_PATTERN_TABLE[index][codeword], Object.freeze({
291
+ codeword, cluster: PDF417_CLUSTER_NUMBERS[index],
292
+ }));
293
+ }
294
+ }
295
+
296
+ /**
297
+ * Return the 17-bit bar/space pattern for a codeword in a row cluster.
298
+ * @param {number} codeword
299
+ * @param {number} cluster Cluster number 0, 3 or 6.
300
+ * @returns {number}
301
+ */
302
+ export function pdf417PatternForCodeword(codeword, cluster) {
303
+ if (!Number.isInteger(codeword) || codeword < 0 || codeword >= PDF417_CODEWORDS_PER_CLUSTER) throw new Error('PDF417: codeword must be in 0..928');
304
+ const index = PDF417_CLUSTER_NUMBERS.indexOf(cluster);
305
+ if (index < 0) throw new Error('PDF417: cluster must be 0, 3 or 6');
306
+ return PDF417_PATTERN_TABLE[index][codeword];
307
+ }
308
+
309
+ /**
310
+ * Decode an exact 17-bit symbol-character pattern to its codeword and cluster.
311
+ * @param {number} pattern
312
+ * @returns {{codeword: number, cluster: number} | null}
313
+ */
314
+ export function pdf417CodewordForPattern(pattern) {
315
+ const result = PATTERN_TO_CODEWORD.get(pattern);
316
+ return result ? { ...result } : null;
317
+ }
@@ -0,0 +1,101 @@
1
+ /*!
2
+ * Sythos Barcode Suite
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2026 Sythos
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *
26
+ * SPDX-License-Identifier: MIT
27
+ *
28
+ * Original work. No code from any other barcode implementation.
29
+ */
30
+
31
+ import { BitReader } from '../core/bit-buffer.js';
32
+ import { ChecksumError, FormatError } from '../core/errors.js';
33
+ import { GF256_QR } from '../core/galois-field.js';
34
+ import { rsDecode } from '../core/reed-solomon.js';
35
+ import {
36
+ FORMAT_MASK_FINDER, FORMAT_MASK_SUB, dataModuleOrder, functionModules, maskBit,
37
+ versionForSize, versionInfo, formatBits,
38
+ } from './tables.js';
39
+ import { ALPHANUMERIC_CHARS, MODE } from './encoder.js';
40
+
41
+ function hamming(a, b) { let v = a ^ b, n = 0; while (v) { v &= v - 1; n++; } return n; }
42
+ function readFormat(matrix, v) {
43
+ let a = 0; for (let n = 0; n < 18; n++) if (matrix.get(8 + Math.floor(n / 5), 1 + (n % 5))) a |= 1 << n;
44
+ let b = 0; for (let n = 0; n < 15; n++) if (matrix.get(v.width - 8 + Math.floor(n / 5), v.height - 6 + (n % 5))) b |= 1 << n;
45
+ for (let n = 15; n < 18; n++) if (matrix.get(v.width - 5 + (n - 15), v.height - 6)) b |= 1 << n;
46
+ const candidates = [];
47
+ for (let version = 1; version <= 32; version++) for (const ecc of ['M', 'H']) {
48
+ candidates.push({ version, ecc, finder: formatBits(version, ecc) ^ FORMAT_MASK_FINDER, sub: formatBits(version, ecc) ^ FORMAT_MASK_SUB });
49
+ }
50
+ let best = null;
51
+ for (const c of candidates) for (const [value, expected] of [[a, c.finder], [b, c.sub]]) { const distance = hamming(value, expected); if (!best || distance < best.distance) best = { ...c, distance }; }
52
+ if (!best || best.distance > 3) throw new FormatError('rMQR: format information is unreadable');
53
+ return best;
54
+ }
55
+
56
+ function readCodewords(matrix, v, mask, total) {
57
+ const order = dataModuleOrder(v.version); const out = new Uint8Array(total); let bit = 0;
58
+ for (const [x, y] of order) { if (bit >= total * 8) break; let on = matrix.get(x, y); if (maskBit(x, y)) on = !on; if (on) out[bit >>> 3] |= 0x80 >>> (bit & 7); bit++; }
59
+ return out;
60
+ }
61
+
62
+ function deinterleave(codewords, v, ecc) {
63
+ const blocks = v.blockLayout(ecc).blocks; const arrays = blocks.map((b) => new Array(b.total).fill(0)); let offset = 0;
64
+ const maxData = Math.max(...blocks.map((b) => b.data)); for (let i = 0; i < maxData; i++) for (let b = 0; b < blocks.length; b++) if (i < blocks[b].data) arrays[b][i] = codewords[offset++];
65
+ const maxEcc = Math.max(...blocks.map((b) => b.ecc)); for (let i = 0; i < maxEcc; i++) for (let b = 0; b < blocks.length; b++) if (i < blocks[b].ecc) arrays[b][blocks[b].data + i] = codewords[offset++];
66
+ const data = []; let corrections = 0;
67
+ for (let b = 0; b < arrays.length; b++) { corrections += rsDecode(arrays[b], blocks[b].ecc, GF256_QR, 0); data.push(...arrays[b].slice(0, blocks[b].data)); }
68
+ return { data: Uint8Array.from(data), corrections };
69
+ }
70
+
71
+ function decodeBytes(bytes, eci) {
72
+ try { return new TextDecoder(eci === 26 ? 'utf-8' : 'iso-8859-1', { fatal: false }).decode(bytes); } catch { return String.fromCharCode(...bytes); }
73
+ }
74
+ function parseSegments(data, v) {
75
+ const reader = new BitReader(data); let text = ''; const raw = []; let eci = 3; let mode;
76
+ while (reader.available() >= 3) {
77
+ const peek = (() => { const save = { byteOffset: reader.byteOffset, bitOffset: reader.bitOffset }; const n = reader.read(3); reader.byteOffset = save.byteOffset; reader.bitOffset = save.bitOffset; return n; })();
78
+ if (peek === 0) break;
79
+ mode = reader.read(3);
80
+ if (mode === MODE.ECI) { const first = reader.read(8); let value; if (!(first & 0x80)) value = first; else if ((first & 0xc0) === 0x80) value = ((first & 0x3f) << 8) | reader.read(8); else if ((first & 0xe0) === 0xc0) value = ((first & 0x1f) << 16) | reader.read(16); else throw new FormatError('rMQR: invalid ECI'); eci = value; continue; }
81
+ const kind = mode === MODE.NUMERIC ? 'numeric' : mode === MODE.ALPHANUMERIC ? 'alphanumeric' : mode === MODE.BYTE ? 'byte' : mode === MODE.KANJI ? 'kanji' : null;
82
+ if (!kind) throw new FormatError(`rMQR: unsupported mode ${mode}`);
83
+ const count = reader.read(v.countBits(kind));
84
+ if (kind === 'numeric') { let remaining = count; while (remaining >= 3) { const n = reader.read(10).toString().padStart(3, '0'); text += n; remaining -= 3; } if (remaining === 2) text += reader.read(7).toString().padStart(2, '0'); else if (remaining === 1) text += reader.read(4).toString(); }
85
+ else if (kind === 'alphanumeric') { let remaining = count; while (remaining >= 2) { const n = reader.read(11); text += ALPHANUMERIC_CHARS[Math.floor(n / 45)] + ALPHANUMERIC_CHARS[n % 45]; remaining -= 2; } if (remaining) text += ALPHANUMERIC_CHARS[reader.read(6)]; }
86
+ else if (kind === 'byte') { const b = new Uint8Array(count); for (let i = 0; i < count; i++) { b[i] = reader.read(8); raw.push(b[i]); } text += decodeBytes(b, eci); }
87
+ else { const bytes = new Uint8Array(count * 2); for (let i = 0; i < count; i++) { const n = reader.read(13); const v2 = n; const high = Math.floor(v2 / 0xc0); const low = v2 % 0xc0; const sjis = high < 0x1f ? 0x8140 + (high << 8) + low : 0xc140 + (high << 8) + low; bytes[i * 2] = sjis >> 8; bytes[i * 2 + 1] = sjis & 255; } try { text += new TextDecoder('shift_jis').decode(bytes); } catch { text += String.fromCharCode(...bytes); } }
88
+ }
89
+ return { text, bytes: Uint8Array.from(raw) };
90
+ }
91
+
92
+ /** Decode an exact rMQR module matrix (without quiet zone). */
93
+ export function decodeRMQR(matrix) {
94
+ if (!matrix || !matrix.width || !matrix.height) throw new FormatError('rMQR: no matrix supplied');
95
+ const v = versionForSize(matrix.width, matrix.height); if (!v) throw new FormatError(`rMQR: unsupported symbol size ${matrix.width}x${matrix.height}`);
96
+ const info = readFormat(matrix, v); if (info.version !== v.version) throw new FormatError('rMQR: format/version mismatch');
97
+ const codewords = readCodewords(matrix, v, 4, v.totalCodewords); const corrected = deinterleave(codewords, v, info.ecc); const parsed = parseSegments(corrected.data, v);
98
+ return { ...parsed, version: v.version, name: v.name, ecc: info.ecc, mask: 4, corrections: corrected.corrections };
99
+ }
100
+
101
+ export { ChecksumError };
@@ -0,0 +1,90 @@
1
+ /*!
2
+ * Sythos Barcode Suite
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2026 Sythos
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *
26
+ * SPDX-License-Identifier: MIT
27
+ *
28
+ * Original work. No code from any other barcode implementation.
29
+ */
30
+
31
+ import { BitMatrix } from '../core/bit-matrix.js';
32
+ import { NotFoundError } from '../core/errors.js';
33
+ import { decodeRMQR } from './decoder.js';
34
+ import { versionForSize } from './tables.js';
35
+
36
+ function rotate90(source) {
37
+ const out = new BitMatrix(source.height, source.width);
38
+ for (let y = 0; y < source.height; y++) for (let x = 0; x < source.width; x++) if (source.get(x, y)) out.set(source.height - 1 - y, x);
39
+ return out;
40
+ }
41
+ function rotate180(source) { const out = new BitMatrix(source.width, source.height); for (let y = 0; y < source.height; y++) for (let x = 0; x < source.width; x++) if (source.get(x, y)) out.set(source.width - 1 - x, source.height - 1 - y); return out; }
42
+ function rotate270(source) { return rotate90(rotate180(source)); }
43
+ function crop(source, box) {
44
+ const out = new BitMatrix(box.width, box.height); for (let y = 0; y < box.height; y++) for (let x = 0; x < box.width; x++) if (source.get(box.x + x, box.y + y)) out.set(x, y); return out;
45
+ }
46
+ function sample(matrix, width, height, scale, offsetX, offsetY) {
47
+ const out = new BitMatrix(width, height); const half = Math.max(0, Math.floor(scale / 2));
48
+ for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
49
+ let dark = 0, count = 0; const x0 = offsetX + x * scale, y0 = offsetY + y * scale;
50
+ for (let yy = 0; yy < scale; yy++) for (let xx = 0; xx < scale; xx++) { if (matrix.get(x0 + xx, y0 + yy)) dark++; count++; }
51
+ if (dark * 2 >= count) out.set(x, y);
52
+ }
53
+ return out;
54
+ }
55
+ function bounds(matrix) { return matrix.getBounds(); }
56
+
57
+ /** Detect an axis-aligned, clean rMQR raster and return the exact module matrix. */
58
+ export function detectRMQR(image, options = {}) {
59
+ if (!image || !image.width || !image.height) throw new NotFoundError('rMQR: no raster supplied');
60
+ if (options.perspective) throw new NotFoundError('rMQR: perspective detection is not available for clean-raster mode');
61
+ const orientations = [image, rotate90(image), rotate180(image), rotate270(image)];
62
+ for (let rotation = 0; rotation < orientations.length; rotation++) {
63
+ const source = orientations[rotation]; const box = bounds(source); if (!box) continue;
64
+ for (let version = 1; version <= 32; version++) {
65
+ const v = versionForSize(box.width, box.height); // exact modules, scale 1
66
+ if (v && v.version === version) {
67
+ try { const matrix = crop(source, box); const result = decodeRMQR(matrix); return { matrix, result, rotation, corners: { x: box.x, y: box.y, width: box.width, height: box.height } }; } catch { /* try next orientation/candidate */ }
68
+ }
69
+ // Integer nearest-neighbour scale. The dark bounding box must still be an
70
+ // exact multiple of the standard geometry; this rejects arbitrary text.
71
+ const candidate = versionForSize(box.width, box.height);
72
+ if (candidate) continue;
73
+ const canonical = (awaitableVersion(version));
74
+ const wScale = box.width / canonical.width;
75
+ const hScale = box.height / canonical.height;
76
+ if (!Number.isInteger(wScale) || wScale < 1 || wScale !== hScale) continue;
77
+ const info = canonical;
78
+ try { const matrix = sample(source, info.width, info.height, wScale, box.x, box.y); const result = decodeRMQR(matrix); return { matrix, result, rotation, scale: wScale, corners: { x: box.x, y: box.y, width: box.width, height: box.height } }; } catch { /* continue */ }
79
+ }
80
+ }
81
+ throw new NotFoundError('rMQR: no clean axis-aligned symbol found');
82
+ }
83
+
84
+ function awaitableVersion(version) {
85
+ const sizes = [[43, 7], [59, 7], [77, 7], [99, 7], [139, 7], [43, 9], [59, 9], [77, 9], [99, 9], [139, 9], [27, 11], [43, 11], [59, 11], [77, 11], [99, 11], [139, 11], [27, 13], [43, 13], [59, 13], [77, 13], [99, 13], [139, 13], [43, 15], [59, 15], [77, 15], [99, 15], [139, 15], [43, 17], [59, 17], [77, 17], [99, 17], [139, 17]];
86
+ return { version, width: sizes[version - 1][0], height: sizes[version - 1][1] };
87
+ }
88
+
89
+ /** Detect and decode a raster in one call. */
90
+ export function detectAndDecodeRMQR(image, options = {}) { return detectRMQR(image, options).result; }