@sythos/js_barcode_universal 1.5.7 → 1.5.9

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 (267) hide show
  1. package/LICENSE +5 -4
  2. package/NOTICE.md +2 -2
  3. package/README.md +50 -37
  4. package/bundle/sythos-barcode.esm.js +12051 -11484
  5. package/bundle/sythos-barcode.js +12051 -11484
  6. package/package.json +52 -45
  7. package/src/index.d.ts +363 -0
  8. package/src/index.js +573 -428
  9. package/src/js/aztec/decoder.js +326 -0
  10. package/src/js/aztec/detector.js +251 -0
  11. package/src/js/aztec/encoder.js +276 -0
  12. package/src/js/aztec/high-level.js +216 -0
  13. package/src/js/aztec/index.js +34 -0
  14. package/src/js/aztec/tables.js +196 -0
  15. package/src/js/aztecrune/decoder.js +146 -0
  16. package/src/js/aztecrune/detector.js +180 -0
  17. package/src/js/aztecrune/encoder.js +103 -0
  18. package/src/js/aztecrune/index.js +34 -0
  19. package/src/js/aztecrune/tables.js +142 -0
  20. package/src/js/compactpdf417/decoder.js +123 -0
  21. package/src/js/compactpdf417/detector.js +138 -0
  22. package/src/js/compactpdf417/encoder.js +127 -0
  23. package/src/js/compactpdf417/index.js +5 -0
  24. package/src/js/compactpdf417/tables.js +164 -0
  25. package/src/js/core/bit-buffer.js +158 -0
  26. package/src/js/core/bit-matrix.js +243 -0
  27. package/src/js/core/errors.js +59 -0
  28. package/src/js/core/galois-field.js +193 -0
  29. package/src/js/core/index.js +39 -0
  30. package/src/js/core/reed-solomon.js +318 -0
  31. package/src/js/databar/codec.js +166 -0
  32. package/src/js/databar/decoder.js +224 -0
  33. package/src/js/databar/encoder.js +88 -0
  34. package/src/js/databar/gs1.js +176 -0
  35. package/src/js/databar/index.js +36 -0
  36. package/src/js/databar/patterns.js +139 -0
  37. package/src/js/databar/tables.js +123 -0
  38. package/src/js/datamatrix/decoder.js +296 -0
  39. package/src/js/datamatrix/detector.js +254 -0
  40. package/src/js/datamatrix/encoder.js +250 -0
  41. package/src/js/datamatrix/index.js +34 -0
  42. package/src/js/datamatrix/tables.js +122 -0
  43. package/src/js/frameqr/decoder.js +216 -0
  44. package/src/js/frameqr/detector.js +199 -0
  45. package/src/js/frameqr/encoder.js +143 -0
  46. package/src/js/frameqr/index.js +33 -0
  47. package/src/js/frameqr/tables.js +252 -0
  48. package/src/js/image/binarizer.js +254 -0
  49. package/src/js/image/grid-sampler.js +148 -0
  50. package/src/js/image/index.js +38 -0
  51. package/src/js/image/luminance.js +185 -0
  52. package/src/js/image/perspective.js +158 -0
  53. package/src/js/micropdf417/compaction.js +115 -0
  54. package/src/js/micropdf417/decoder.js +180 -0
  55. package/src/js/micropdf417/detector.js +152 -0
  56. package/src/js/micropdf417/encoder.js +184 -0
  57. package/src/js/micropdf417/error-correction.js +50 -0
  58. package/src/js/micropdf417/index.js +35 -0
  59. package/src/js/micropdf417/tables.js +197 -0
  60. package/src/js/microqr/decoder.js +240 -0
  61. package/src/js/microqr/detector.js +339 -0
  62. package/src/js/microqr/encoder.js +314 -0
  63. package/src/js/microqr/index.js +34 -0
  64. package/src/js/microqr/tables.js +324 -0
  65. package/src/js/oned/addons.js +396 -0
  66. package/src/js/oned/index.js +75 -0
  67. package/src/js/oned/patterns.js +365 -0
  68. package/src/js/oned/reader.js +1383 -0
  69. package/src/js/oned/writers.js +691 -0
  70. package/src/js/pdf417/compaction.js +391 -0
  71. package/src/js/pdf417/decoder.js +110 -0
  72. package/src/js/pdf417/detector.js +484 -0
  73. package/src/js/pdf417/encoder.js +102 -0
  74. package/src/js/pdf417/error-correction.js +44 -0
  75. package/src/{pdf417 → js/pdf417}/index.js +0 -5
  76. package/src/js/pdf417/tables.js +315 -0
  77. package/src/js/qr/decoder.js +539 -0
  78. package/src/js/qr/detector.js +613 -0
  79. package/src/js/qr/encoder.js +873 -0
  80. package/src/js/qr/index.js +42 -0
  81. package/src/js/qr/tables.js +690 -0
  82. package/src/js/render/image-data.js +120 -0
  83. package/src/js/render/index.js +128 -0
  84. package/src/js/render/options.js +152 -0
  85. package/src/js/render/png.js +270 -0
  86. package/src/js/render/svg.js +117 -0
  87. package/src/js/render/webgl.js +200 -0
  88. package/src/js/render/webgpu.js +357 -0
  89. package/src/js/rmqr/decoder.js +209 -0
  90. package/src/js/rmqr/detector.js +122 -0
  91. package/src/js/rmqr/encoder.js +321 -0
  92. package/src/js/rmqr/index.js +33 -0
  93. package/src/js/rmqr/tables.js +177 -0
  94. package/src/{aztec/decoder.js → ts/aztec/decoder.ts} +0 -1
  95. package/{typings → src/ts}/aztec/detector.d.ts +2 -2
  96. package/src/{aztec/detector.js → ts/aztec/detector.ts} +0 -1
  97. package/src/{aztec/encoder.js → ts/aztec/encoder.ts} +0 -1
  98. package/src/{aztec/high-level.js → ts/aztec/high-level.ts} +0 -1
  99. package/src/{aztec/index.js → ts/aztec/index.ts} +0 -1
  100. package/src/{aztec/tables.js → ts/aztec/tables.ts} +0 -1
  101. package/src/{aztecrune/decoder.js → ts/aztecrune/decoder.ts} +0 -1
  102. package/src/{aztecrune/detector.js → ts/aztecrune/detector.ts} +0 -1
  103. package/src/{aztecrune/encoder.js → ts/aztecrune/encoder.ts} +0 -1
  104. package/src/{aztecrune/index.js → ts/aztecrune/index.ts} +0 -1
  105. package/src/{aztecrune/tables.js → ts/aztecrune/tables.ts} +0 -1
  106. package/src/{compactpdf417/decoder.js → ts/compactpdf417/decoder.ts} +0 -1
  107. package/src/{compactpdf417/detector.js → ts/compactpdf417/detector.ts} +0 -1
  108. package/src/{compactpdf417/encoder.js → ts/compactpdf417/encoder.ts} +0 -1
  109. package/src/{compactpdf417/index.js → ts/compactpdf417/index.ts} +0 -5
  110. package/src/{compactpdf417/tables.js → ts/compactpdf417/tables.ts} +0 -1
  111. package/src/{core/bit-buffer.js → ts/core/bit-buffer.ts} +0 -1
  112. package/src/{core/bit-matrix.js → ts/core/bit-matrix.ts} +0 -1
  113. package/src/{core/errors.js → ts/core/errors.ts} +0 -1
  114. package/src/{core/galois-field.js → ts/core/galois-field.ts} +0 -1
  115. package/src/{core/index.js → ts/core/index.ts} +0 -1
  116. package/src/{core/reed-solomon.js → ts/core/reed-solomon.ts} +0 -1
  117. package/src/{databar/codec.js → ts/databar/codec.ts} +0 -1
  118. package/src/{databar/decoder.js → ts/databar/decoder.ts} +0 -1
  119. package/src/{databar/encoder.js → ts/databar/encoder.ts} +0 -1
  120. package/src/{databar/gs1.js → ts/databar/gs1.ts} +0 -1
  121. package/src/{databar/index.js → ts/databar/index.ts} +0 -1
  122. package/src/{databar/patterns.js → ts/databar/patterns.ts} +0 -1
  123. package/src/{databar/tables.js → ts/databar/tables.ts} +0 -1
  124. package/src/{datamatrix/decoder.js → ts/datamatrix/decoder.ts} +0 -1
  125. package/{typings → src/ts}/datamatrix/detector.d.ts +2 -2
  126. package/src/{datamatrix/detector.js → ts/datamatrix/detector.ts} +0 -1
  127. package/src/{datamatrix/encoder.js → ts/datamatrix/encoder.ts} +0 -1
  128. package/src/{datamatrix/index.js → ts/datamatrix/index.ts} +0 -1
  129. package/src/{datamatrix/tables.js → ts/datamatrix/tables.ts} +0 -1
  130. package/src/{frameqr/decoder.js → ts/frameqr/decoder.ts} +15 -16
  131. package/src/{frameqr/detector.js → ts/frameqr/detector.ts} +2 -3
  132. package/src/{frameqr/encoder.js → ts/frameqr/encoder.ts} +7 -8
  133. package/src/{frameqr/index.js → ts/frameqr/index.ts} +0 -1
  134. package/src/{frameqr/tables.js → ts/frameqr/tables.ts} +10 -11
  135. package/src/{image/binarizer.js → ts/image/binarizer.ts} +0 -1
  136. package/src/{image/grid-sampler.js → ts/image/grid-sampler.ts} +0 -1
  137. package/src/{image/index.js → ts/image/index.ts} +0 -1
  138. package/src/{image/luminance.js → ts/image/luminance.ts} +0 -1
  139. package/src/{image/perspective.js → ts/image/perspective.ts} +0 -1
  140. package/{typings → src/ts}/index.d.ts +3 -3
  141. package/src/ts/index.ts +790 -0
  142. package/src/{micropdf417/compaction.js → ts/micropdf417/compaction.ts} +0 -1
  143. package/src/{micropdf417/decoder.js → ts/micropdf417/decoder.ts} +0 -1
  144. package/src/{micropdf417/detector.js → ts/micropdf417/detector.ts} +0 -1
  145. package/src/{micropdf417/encoder.js → ts/micropdf417/encoder.ts} +0 -1
  146. package/src/{micropdf417/error-correction.js → ts/micropdf417/error-correction.ts} +0 -1
  147. package/src/{micropdf417/index.js → ts/micropdf417/index.ts} +0 -1
  148. package/src/{micropdf417/tables.js → ts/micropdf417/tables.ts} +0 -1
  149. package/src/{microqr/decoder.js → ts/microqr/decoder.ts} +0 -1
  150. package/src/{microqr/detector.js → ts/microqr/detector.ts} +0 -1
  151. package/src/{microqr/encoder.js → ts/microqr/encoder.ts} +0 -1
  152. package/src/{microqr/index.js → ts/microqr/index.ts} +0 -1
  153. package/src/{microqr/tables.js → ts/microqr/tables.ts} +0 -1
  154. package/src/{oned/addons.js → ts/oned/addons.ts} +0 -1
  155. package/src/{oned/index.js → ts/oned/index.ts} +0 -1
  156. package/src/{oned/patterns.js → ts/oned/patterns.ts} +0 -1
  157. package/src/{oned/reader.js → ts/oned/reader.ts} +0 -1
  158. package/src/{oned/writers.js → ts/oned/writers.ts} +0 -1
  159. package/src/{pdf417/compaction.js → ts/pdf417/compaction.ts} +0 -1
  160. package/src/{pdf417/decoder.js → ts/pdf417/decoder.ts} +0 -1
  161. package/src/{pdf417/detector.js → ts/pdf417/detector.ts} +0 -1
  162. package/src/{pdf417/encoder.js → ts/pdf417/encoder.ts} +0 -1
  163. package/src/{pdf417/error-correction.js → ts/pdf417/error-correction.ts} +0 -1
  164. package/src/ts/pdf417/index.ts +6 -0
  165. package/src/{pdf417/tables.js → ts/pdf417/tables.ts} +0 -1
  166. package/src/{qr/decoder.js → ts/qr/decoder.ts} +0 -1
  167. package/src/{qr/detector.js → ts/qr/detector.ts} +0 -1
  168. package/src/{qr/encoder.js → ts/qr/encoder.ts} +0 -1
  169. package/src/{qr/index.js → ts/qr/index.ts} +0 -1
  170. package/src/{qr/tables.js → ts/qr/tables.ts} +0 -1
  171. package/src/{render/image-data.js → ts/render/image-data.ts} +0 -1
  172. package/src/{render/index.js → ts/render/index.ts} +0 -1
  173. package/src/{render/options.js → ts/render/options.ts} +0 -1
  174. package/src/{render/png.js → ts/render/png.ts} +0 -1
  175. package/src/{render/svg.js → ts/render/svg.ts} +0 -1
  176. package/src/{render/webgl.js → ts/render/webgl.ts} +0 -1
  177. package/src/{render/webgpu.js → ts/render/webgpu.ts} +0 -1
  178. package/src/{rmqr/decoder.js → ts/rmqr/decoder.ts} +0 -1
  179. package/src/{rmqr/detector.js → ts/rmqr/detector.ts} +0 -1
  180. package/src/{rmqr/encoder.js → ts/rmqr/encoder.ts} +0 -1
  181. package/src/{rmqr/index.js → ts/rmqr/index.ts} +0 -1
  182. package/src/{rmqr/tables.js → ts/rmqr/tables.ts} +0 -1
  183. /package/{typings → src/ts}/aztec/decoder.d.ts +0 -0
  184. /package/{typings → src/ts}/aztec/encoder.d.ts +0 -0
  185. /package/{typings → src/ts}/aztec/high-level.d.ts +0 -0
  186. /package/{typings → src/ts}/aztec/index.d.ts +0 -0
  187. /package/{typings → src/ts}/aztec/tables.d.ts +0 -0
  188. /package/{typings → src/ts}/aztecrune/decoder.d.ts +0 -0
  189. /package/{typings → src/ts}/aztecrune/detector.d.ts +0 -0
  190. /package/{typings → src/ts}/aztecrune/encoder.d.ts +0 -0
  191. /package/{typings → src/ts}/aztecrune/index.d.ts +0 -0
  192. /package/{typings → src/ts}/aztecrune/tables.d.ts +0 -0
  193. /package/{typings → src/ts}/bundle/sythos-barcode.d.ts +0 -0
  194. /package/{typings → src/ts}/bundle/sythos-barcode.esm.d.ts +0 -0
  195. /package/{typings → src/ts}/compactpdf417/decoder.d.ts +0 -0
  196. /package/{typings → src/ts}/compactpdf417/detector.d.ts +0 -0
  197. /package/{typings → src/ts}/compactpdf417/encoder.d.ts +0 -0
  198. /package/{typings → src/ts}/compactpdf417/index.d.ts +0 -0
  199. /package/{typings → src/ts}/compactpdf417/tables.d.ts +0 -0
  200. /package/{typings → src/ts}/core/bit-buffer.d.ts +0 -0
  201. /package/{typings → src/ts}/core/bit-matrix.d.ts +0 -0
  202. /package/{typings → src/ts}/core/errors.d.ts +0 -0
  203. /package/{typings → src/ts}/core/galois-field.d.ts +0 -0
  204. /package/{typings → src/ts}/core/index.d.ts +0 -0
  205. /package/{typings → src/ts}/core/reed-solomon.d.ts +0 -0
  206. /package/{typings → src/ts}/databar/codec.d.ts +0 -0
  207. /package/{typings → src/ts}/databar/decoder.d.ts +0 -0
  208. /package/{typings → src/ts}/databar/encoder.d.ts +0 -0
  209. /package/{typings → src/ts}/databar/gs1.d.ts +0 -0
  210. /package/{typings → src/ts}/databar/index.d.ts +0 -0
  211. /package/{typings → src/ts}/databar/patterns.d.ts +0 -0
  212. /package/{typings → src/ts}/databar/tables.d.ts +0 -0
  213. /package/{typings → src/ts}/datamatrix/decoder.d.ts +0 -0
  214. /package/{typings → src/ts}/datamatrix/encoder.d.ts +0 -0
  215. /package/{typings → src/ts}/datamatrix/index.d.ts +0 -0
  216. /package/{typings → src/ts}/datamatrix/tables.d.ts +0 -0
  217. /package/{typings → src/ts}/frameqr/decoder.d.ts +0 -0
  218. /package/{typings → src/ts}/frameqr/detector.d.ts +0 -0
  219. /package/{typings → src/ts}/frameqr/encoder.d.ts +0 -0
  220. /package/{typings → src/ts}/frameqr/index.d.ts +0 -0
  221. /package/{typings → src/ts}/frameqr/tables.d.ts +0 -0
  222. /package/{typings → src/ts}/image/binarizer.d.ts +0 -0
  223. /package/{typings → src/ts}/image/grid-sampler.d.ts +0 -0
  224. /package/{typings → src/ts}/image/index.d.ts +0 -0
  225. /package/{typings → src/ts}/image/luminance.d.ts +0 -0
  226. /package/{typings → src/ts}/image/perspective.d.ts +0 -0
  227. /package/{typings → src/ts}/micropdf417/compaction.d.ts +0 -0
  228. /package/{typings → src/ts}/micropdf417/decoder.d.ts +0 -0
  229. /package/{typings → src/ts}/micropdf417/detector.d.ts +0 -0
  230. /package/{typings → src/ts}/micropdf417/encoder.d.ts +0 -0
  231. /package/{typings → src/ts}/micropdf417/error-correction.d.ts +0 -0
  232. /package/{typings → src/ts}/micropdf417/index.d.ts +0 -0
  233. /package/{typings → src/ts}/micropdf417/tables.d.ts +0 -0
  234. /package/{typings → src/ts}/microqr/decoder.d.ts +0 -0
  235. /package/{typings → src/ts}/microqr/detector.d.ts +0 -0
  236. /package/{typings → src/ts}/microqr/encoder.d.ts +0 -0
  237. /package/{typings → src/ts}/microqr/index.d.ts +0 -0
  238. /package/{typings → src/ts}/microqr/tables.d.ts +0 -0
  239. /package/{typings → src/ts}/oned/addons.d.ts +0 -0
  240. /package/{typings → src/ts}/oned/index.d.ts +0 -0
  241. /package/{typings → src/ts}/oned/patterns.d.ts +0 -0
  242. /package/{typings → src/ts}/oned/reader.d.ts +0 -0
  243. /package/{typings → src/ts}/oned/writers.d.ts +0 -0
  244. /package/{typings → src/ts}/pdf417/compaction.d.ts +0 -0
  245. /package/{typings → src/ts}/pdf417/decoder.d.ts +0 -0
  246. /package/{typings → src/ts}/pdf417/detector.d.ts +0 -0
  247. /package/{typings → src/ts}/pdf417/encoder.d.ts +0 -0
  248. /package/{typings → src/ts}/pdf417/error-correction.d.ts +0 -0
  249. /package/{typings → src/ts}/pdf417/index.d.ts +0 -0
  250. /package/{typings → src/ts}/pdf417/tables.d.ts +0 -0
  251. /package/{typings → src/ts}/qr/decoder.d.ts +0 -0
  252. /package/{typings → src/ts}/qr/detector.d.ts +0 -0
  253. /package/{typings → src/ts}/qr/encoder.d.ts +0 -0
  254. /package/{typings → src/ts}/qr/index.d.ts +0 -0
  255. /package/{typings → src/ts}/qr/tables.d.ts +0 -0
  256. /package/{typings → src/ts}/render/image-data.d.ts +0 -0
  257. /package/{typings → src/ts}/render/index.d.ts +0 -0
  258. /package/{typings → src/ts}/render/options.d.ts +0 -0
  259. /package/{typings → src/ts}/render/png.d.ts +0 -0
  260. /package/{typings → src/ts}/render/svg.d.ts +0 -0
  261. /package/{typings → src/ts}/render/webgl.d.ts +0 -0
  262. /package/{typings → src/ts}/render/webgpu.d.ts +0 -0
  263. /package/{typings → src/ts}/rmqr/decoder.d.ts +0 -0
  264. /package/{typings → src/ts}/rmqr/detector.d.ts +0 -0
  265. /package/{typings → src/ts}/rmqr/encoder.d.ts +0 -0
  266. /package/{typings → src/ts}/rmqr/index.d.ts +0 -0
  267. /package/{typings → src/ts}/rmqr/tables.d.ts +0 -0
@@ -0,0 +1,216 @@
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
+ * Decoder for the Sythos Canvas QR profile.
32
+ *
33
+ * This is intentionally not a DENSO FrameQR decoder. The profile is a QR
34
+ * symbol with a bounded artwork reservation and an explicit `frameqr` marker.
35
+ * A normal QR matrix is rejected unless a detector (or another trusted
36
+ * caller) supplies the profile and explicitly opts in to an unmarked matrix.
37
+ *
38
+ * The QR decoder is deliberately kept as the single payload decoder. It can
39
+ * repair the bounded modules removed for the canvas because the encoder fixes
40
+ * error correction to H and validates the reservation before clearing it.
41
+ *
42
+ * @module frameqr/decoder
43
+ */
44
+ import { FormatError } from '../core/errors.js';
45
+ import { decodeQR } from '../qr/decoder.js';
46
+ import { FRAMEQR_PROFILE, normalizeCanvasSpec, validateCanvasSpec, analyzeCanvasDamage, } from './tables.js';
47
+ /** @param {unknown} value @returns {boolean} */
48
+ function isObject(value) {
49
+ return value !== null && typeof value === 'object';
50
+ }
51
+ /**
52
+ * Return the profile marker attached by the encoder. Older callers sometimes
53
+ * use camel case, so accepting it here is harmless while the emitted marker
54
+ * remains the canonical `frameqr` property.
55
+ *
56
+ * @param {import('../core/bit-matrix.js').BitMatrix} matrix
57
+ * @returns {object|null}
58
+ */
59
+ function markerOf(matrix) {
60
+ const marker = matrix && (matrix.frameqr ?? matrix.frameQR);
61
+ return isObject(marker) ? marker : null;
62
+ }
63
+ /** @param {unknown} profile @returns {boolean} */
64
+ function isExpectedProfile(profile) {
65
+ if (profile === FRAMEQR_PROFILE.id)
66
+ return true;
67
+ return isObject(profile) && profile.id === FRAMEQR_PROFILE.id;
68
+ }
69
+ /**
70
+ * Normalize and validate the canvas metadata. Validation functions in the
71
+ * table module throw on invalid input; a few consumers also return `false` or
72
+ * a problem list, so those forms are handled defensively here.
73
+ *
74
+ * @param {number} symbolSize
75
+ * @param {number} version
76
+ * @param {object} canvas
77
+ * @returns {{canvas: object, damage: object}}
78
+ */
79
+ function validateCanvas(symbolSize, version, canvas) {
80
+ if (!isObject(canvas))
81
+ throw new FormatError('Sythos Canvas QR: canvas metadata is missing');
82
+ let normalized;
83
+ try {
84
+ normalized = normalizeCanvasSpec(symbolSize, canvas);
85
+ const validation = validateCanvasSpec(version, normalized);
86
+ if (validation === false ||
87
+ (Array.isArray(validation) && validation.length > 0) ||
88
+ (isObject(validation) && validation.valid === false) ||
89
+ (isObject(validation) && validation.safe === false)) {
90
+ throw new Error('canvas geometry is outside the profile limits');
91
+ }
92
+ }
93
+ catch (error) {
94
+ if (error instanceof FormatError)
95
+ throw error;
96
+ throw new FormatError(`Sythos Canvas QR: invalid canvas metadata: ${error.message}`);
97
+ }
98
+ let damage;
99
+ try {
100
+ damage = analyzeCanvasDamage(version, normalized);
101
+ }
102
+ catch (error) {
103
+ throw new FormatError(`Sythos Canvas QR: cannot analyse canvas damage: ${error.message}`);
104
+ }
105
+ return { canvas: normalized, damage };
106
+ }
107
+ /**
108
+ * Resolve the profile marker and canvas from the matrix/options pair.
109
+ *
110
+ * `allowUnmarked` is deliberately opt-in. It exists for a detector that has
111
+ * already verified the canvas signature after sampling a photograph; it is
112
+ * not enabled by the public default and therefore cannot silently relabel an
113
+ * ordinary QR Code as FrameQR.
114
+ *
115
+ * @param {import('../core/bit-matrix.js').BitMatrix} matrix
116
+ * @param {object} options
117
+ * @returns {{profile: string, canvas: object, damage: object, certified: false}}
118
+ */
119
+ function resolveProfile(matrix, options) {
120
+ const marker = markerOf(matrix);
121
+ const suppliedProfile = options.profile;
122
+ const markerProfile = marker ? marker.profile : undefined;
123
+ if (markerProfile !== undefined && suppliedProfile !== undefined) {
124
+ const markerId = isObject(markerProfile) ? markerProfile.id : markerProfile;
125
+ const suppliedId = isObject(suppliedProfile) ? suppliedProfile.id : suppliedProfile;
126
+ if (markerId !== suppliedId) {
127
+ throw new FormatError('Sythos Canvas QR: matrix and requested profile markers disagree');
128
+ }
129
+ }
130
+ const profile = markerProfile ?? suppliedProfile;
131
+ if (!isExpectedProfile(profile)) {
132
+ throw new FormatError('Sythos Canvas QR: profile marker is missing or is not the Sythos Canvas QR profile');
133
+ }
134
+ if (marker && marker.certified === true) {
135
+ throw new FormatError('Sythos Canvas QR: certified FrameQR input is not supported by this profile decoder');
136
+ }
137
+ if (!marker && !options.allowUnmarked) {
138
+ throw new FormatError('Sythos Canvas QR: unmarked QR matrix rejected; provide a verified profile marker');
139
+ }
140
+ const markerCanvas = marker ? marker.canvas : undefined;
141
+ const canvas = options.canvas ?? markerCanvas;
142
+ const version = (matrix.width - 17) / 4;
143
+ if (!Number.isInteger(version) || version < 1 || version > 40) {
144
+ throw new FormatError(`Sythos Canvas QR: invalid QR symbol size ${matrix.width}`);
145
+ }
146
+ const checked = validateCanvas(matrix.width, version, canvas);
147
+ if (markerCanvas && options.canvas) {
148
+ let marked;
149
+ try {
150
+ marked = normalizeCanvasSpec(matrix.width, markerCanvas);
151
+ }
152
+ catch (error) {
153
+ throw new FormatError(`Sythos Canvas QR: invalid marker canvas: ${error.message}`);
154
+ }
155
+ const fields = ['shape', 'centerX', 'centerY', 'width', 'height', 'angle'];
156
+ if (fields.some((field) => marked[field] !== checked.canvas[field])) {
157
+ throw new FormatError('Sythos Canvas QR: matrix and requested canvas metadata disagree');
158
+ }
159
+ }
160
+ return {
161
+ profile: FRAMEQR_PROFILE.id,
162
+ canvas: checked.canvas,
163
+ damage: checked.damage,
164
+ certified: false,
165
+ };
166
+ }
167
+ /**
168
+ * Decode a Sythos Canvas QR matrix.
169
+ *
170
+ * @param {import('../core/bit-matrix.js').BitMatrix} matrix
171
+ * Square QR modules, normally returned by `encodeFrameQR` or a FrameQR
172
+ * detector. The encoder's `frameqr` metadata is required by default.
173
+ * @param {object} [options]
174
+ * @param {object} [options.canvas] Explicit canvas metadata for a sampled
175
+ * matrix when the source marker was not preserved.
176
+ * @param {string|object} [options.profile] Expected profile identifier.
177
+ * @param {boolean} [options.allowUnmarked=false] Explicit detector opt-in for
178
+ * a matrix whose marker was lost during image sampling.
179
+ * @returns {import('../qr/decoder.js').DecodeResult & {
180
+ * format: 'frameqr', profile: string, certified: false,
181
+ * frame: object, canvas: object, canvasDamage: object
182
+ * }}
183
+ * @throws {FormatError} If the profile marker/canvas is invalid or the input
184
+ * is an ordinary QR Code.
185
+ */
186
+ export function decodeFrameQR(matrix, options = {}) {
187
+ if (!matrix || !Number.isInteger(matrix.width) || !Number.isInteger(matrix.height)) {
188
+ throw new FormatError('Sythos Canvas QR: no matrix supplied');
189
+ }
190
+ if (matrix.width !== matrix.height) {
191
+ throw new FormatError(`Sythos Canvas QR: symbol must be square, got ${matrix.width}x${matrix.height}`);
192
+ }
193
+ const profile = resolveProfile(matrix, options);
194
+ let decoded;
195
+ try {
196
+ decoded = decodeQR(matrix);
197
+ }
198
+ catch (error) {
199
+ // Preserve the original QR/RS error when possible, but give callers a
200
+ // profile-specific context without exposing implementation details.
201
+ if (error instanceof FormatError) {
202
+ throw new FormatError(`Sythos Canvas QR: payload is not recoverable: ${error.message}`);
203
+ }
204
+ throw error;
205
+ }
206
+ return {
207
+ ...decoded,
208
+ format: 'frameqr',
209
+ profile: profile.profile,
210
+ certified: profile.certified,
211
+ frame: profile.canvas,
212
+ canvas: profile.canvas,
213
+ canvasDamage: profile.damage,
214
+ };
215
+ }
216
+ export { isExpectedProfile };
@@ -0,0 +1,199 @@
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
+ * Detector for the non-certified Sythos Canvas QR profile.
32
+ *
33
+ * The profile deliberately reuses QR Model 2 geometry. Finder localisation and
34
+ * projective sampling therefore use the QR detector; the additional profile
35
+ * check is the light canvas signature. A sampled image cannot carry the
36
+ * encoder's in-memory marker, so the detector reconstructs the expected
37
+ * metadata, verifies that every reserved canvas module is light, and only then
38
+ * opts into the profile decoder. This rejects ordinary QR symbols whose centre
39
+ * merely happens to contain a plausible payload.
40
+ *
41
+ * Detection is verified for clean binarized rasters, integer scaling, quiet
42
+ * zones, and in-plane quarter turns. Arbitrary photographic perspective is not
43
+ * claimed by this module.
44
+ *
45
+ * @module frameqr/detector
46
+ */
47
+ import { NotFoundError } from '../core/errors.js';
48
+ import { sampleQuad } from '../image/grid-sampler.js';
49
+ import { detectQR } from '../qr/detector.js';
50
+ import { decodeFrameQR } from './decoder.js';
51
+ import { FRAMEQR_PROFILE, canvasModules, normalizeCanvasSpec, } from './tables.js';
52
+ /** @typedef {{x:number, y:number}} Point */
53
+ /** @typedef {object} FrameQRDetection
54
+ * @property {Point[]} corners Outer corners in reading order.
55
+ * @property {number} dimension QR modules per side.
56
+ * @property {number} version QR Model 2 version.
57
+ * @property {number} moduleSize Estimated pixels per module.
58
+ * @property {number} rotation Clockwise in-plane orientation in degrees.
59
+ * @property {BitMatrix} matrix Rectified profile matrix.
60
+ * @property {object} canvas Normalized canvas specification.
61
+ * @property {string} profile Profile identifier.
62
+ * @property {false} certified Always false for this implementation.
63
+ */
64
+ function orientationDegrees(corners) {
65
+ const [tl, tr] = corners;
66
+ const angle = Math.atan2(tr.y - tl.y, tr.x - tl.x) * 180 / Math.PI;
67
+ return ((Math.round(angle / 90) * 90) % 360 + 360) % 360;
68
+ }
69
+ /**
70
+ * Return the number of canvas modules that are dark in a sampled matrix.
71
+ *
72
+ * Encoded profile symbols clear the whole reserved canvas. A non-zero count
73
+ * means either a normal QR symbol or a raster whose canvas was overwritten by
74
+ * artwork; both are rejected because decoding that image would be speculative.
75
+ */
76
+ function canvasDarkCount(matrix, canvas) {
77
+ let dark = 0;
78
+ for (const [x, y] of canvasModules(matrix.width, canvas)) {
79
+ if (matrix.get(x, y))
80
+ dark++;
81
+ }
82
+ return dark;
83
+ }
84
+ function sameCandidate(left, right) {
85
+ if (left.dimension !== right.dimension)
86
+ return false;
87
+ const a = left.corners[0];
88
+ const b = right.corners[0];
89
+ return Math.hypot(a.x - b.x, a.y - b.y) <= Math.max(left.moduleSize, right.moduleSize) * 2;
90
+ }
91
+ /**
92
+ * Detect Sythos Canvas QR symbols in a binarized raster.
93
+ *
94
+ * @param {import('../core/bit-matrix.js').BitMatrix} binaryImage Set bit = dark.
95
+ * @param {object} [options]
96
+ * @param {object} [options.canvas] Explicit canvas metadata for non-default
97
+ * shapes/size. Without it, the profile's canonical centered square is used.
98
+ * @param {boolean} [options.voting=false] Use majority sampling per module.
99
+ * @returns {FrameQRDetection[]} Best candidate first; empty when no verified
100
+ * profile signature is found.
101
+ */
102
+ export function detectFrameQR(binaryImage, options = {}) {
103
+ if (!binaryImage || !binaryImage.width || !binaryImage.height) {
104
+ throw new NotFoundError('detectFrameQR: no image supplied');
105
+ }
106
+ let candidates;
107
+ try {
108
+ candidates = detectQR(binaryImage);
109
+ }
110
+ catch {
111
+ return [];
112
+ }
113
+ const detections = [];
114
+ for (const candidate of candidates) {
115
+ // QR detector dimensions are already constrained to legal Model 2 sizes.
116
+ let canvas;
117
+ try {
118
+ canvas = normalizeCanvasSpec(candidate.dimension, options.canvas);
119
+ }
120
+ catch {
121
+ continue;
122
+ }
123
+ for (const voting of [Boolean(options.voting), !Boolean(options.voting)]) {
124
+ let matrix;
125
+ try {
126
+ matrix = sampleQuad(binaryImage, candidate.dimension, candidate.corners, voting);
127
+ }
128
+ catch {
129
+ continue;
130
+ }
131
+ // The signature check is intentionally strict. It prevents an ordinary
132
+ // QR symbol from being relabelled as Canvas QR by the decoder's explicit
133
+ // allowUnmarked escape hatch.
134
+ if (canvasDarkCount(matrix, canvas) !== 0)
135
+ continue;
136
+ const marked = matrix;
137
+ marked.frameqr = {
138
+ profile: FRAMEQR_PROFILE.id,
139
+ certified: false,
140
+ canvas,
141
+ };
142
+ let decoded;
143
+ try {
144
+ decoded = decodeFrameQR(marked, {
145
+ profile: FRAMEQR_PROFILE.id,
146
+ canvas,
147
+ allowUnmarked: true,
148
+ });
149
+ }
150
+ catch {
151
+ continue;
152
+ }
153
+ const detection = {
154
+ corners: candidate.corners,
155
+ dimension: candidate.dimension,
156
+ version: candidate.version,
157
+ moduleSize: candidate.moduleSize,
158
+ rotation: orientationDegrees(candidate.corners),
159
+ matrix: marked,
160
+ canvas,
161
+ profile: FRAMEQR_PROFILE.id,
162
+ certified: false,
163
+ result: decoded,
164
+ };
165
+ if (!detections.some((entry) => sameCandidate(entry, detection)))
166
+ detections.push(detection);
167
+ break;
168
+ }
169
+ }
170
+ detections.sort((a, b) => b.moduleSize - a.moduleSize);
171
+ return detections;
172
+ }
173
+ /**
174
+ * Detect and decode all verified Canvas QR symbols in one call.
175
+ *
176
+ * @param {import('../core/bit-matrix.js').BitMatrix} binaryImage
177
+ * @param {object} [options]
178
+ * @returns {Array<object>}
179
+ */
180
+ export function detectAndDecodeFrameQR(binaryImage, options = {}) {
181
+ let detections;
182
+ try {
183
+ detections = detectFrameQR(binaryImage, options);
184
+ }
185
+ catch {
186
+ return [];
187
+ }
188
+ const results = [];
189
+ const seen = new Set();
190
+ for (const detection of detections) {
191
+ const result = detection.result;
192
+ const key = `${result.version}|${result.text}`;
193
+ if (seen.has(key))
194
+ continue;
195
+ seen.add(key);
196
+ results.push({ ...result, corners: detection.corners, rotation: detection.rotation });
197
+ }
198
+ return results;
199
+ }
@@ -0,0 +1,143 @@
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
+ * Sythos Canvas QR profile encoder.
32
+ *
33
+ * This encoder deliberately builds on this project's QR Code implementation
34
+ * and then removes a conservatively bounded set of data modules for artwork.
35
+ * It is not an implementation of DENSO FrameQR and makes no interoperability
36
+ * claim for that proprietary format.
37
+ *
38
+ * @module frameqr/encoder
39
+ */
40
+ import { EncodeError } from '../core/errors.js';
41
+ import { encodeQR } from '../qr/encoder.js';
42
+ import { FRAMEQR_PROFILE, canvasModules, normalizeCanvasSpec, validateCanvasSpec, } from './tables.js';
43
+ /**
44
+ * @typedef {object} FrameQrEncodeOptions
45
+ * @property {'H'} [ecc] The profile always uses QR error correction H.
46
+ * @property {number} [version] Force a QR version 1-40.
47
+ * @property {number} [mask] Force a QR mask 0-7.
48
+ * @property {'auto'|'utf-8'|'iso-8859-1'} [charset] Byte mode interpretation.
49
+ * @property {boolean} [kanji] Allow QR kanji mode.
50
+ * @property {object} [canvas] Profile artwork reservation.
51
+ */
52
+ function versionFor(matrix) {
53
+ return (matrix.width - 17) / 4;
54
+ }
55
+ function clearCanvas(matrix, modules) {
56
+ for (const [x, y] of modules)
57
+ matrix.unset(x, y);
58
+ }
59
+ /**
60
+ * Encode a QR Code with a conservative artwork canvas according to the
61
+ * non-certified Sythos Canvas QR profile.
62
+ *
63
+ * The profile forces QR H error correction and rejects a canvas whenever its
64
+ * known codeword damage exceeds the per-block correction budget. When a
65
+ * version is not forced, the smallest QR version that holds both payload and
66
+ * safe canvas is selected. A decoder can reconstruct the reserved modules from
67
+ * the returned profile metadata.
68
+ *
69
+ * @param {string} text
70
+ * @param {FrameQrEncodeOptions} [options]
71
+ * @returns {import('../core/bit-matrix.js').BitMatrix}
72
+ * @throws {EncodeError} When the QR payload/options are invalid or the canvas
73
+ * cannot safely fit the selected QR version.
74
+ */
75
+ export function encodeFrameQR(text, options = {}) {
76
+ if (typeof text !== 'string') {
77
+ throw new EncodeError('Sythos Canvas QR: text must be a string');
78
+ }
79
+ if (options.ecc !== undefined && options.ecc !== 'H') {
80
+ throw new EncodeError('Sythos Canvas QR: ecc is fixed to H for this profile');
81
+ }
82
+ const qrOptions = {
83
+ mask: options.mask,
84
+ charset: options.charset,
85
+ kanji: options.kanji,
86
+ ecc: 'H',
87
+ };
88
+ for (const key of Object.keys(qrOptions)) {
89
+ if (qrOptions[key] === undefined)
90
+ delete qrOptions[key];
91
+ }
92
+ const versions = options.version === undefined
93
+ ? Array.from({ length: 40 }, (_, index) => index + 1)
94
+ : [options.version];
95
+ let capacityError = null;
96
+ let unsafeAnalysis = null;
97
+ let selected = null;
98
+ for (const version of versions) {
99
+ let matrix;
100
+ try {
101
+ matrix = encodeQR(text, { ...qrOptions, version });
102
+ }
103
+ catch (error) {
104
+ capacityError = error;
105
+ continue;
106
+ }
107
+ let canvas;
108
+ let analysis;
109
+ try {
110
+ canvas = normalizeCanvasSpec(matrix.width, options.canvas);
111
+ analysis = validateCanvasSpec(versionFor(matrix), canvas);
112
+ }
113
+ catch (error) {
114
+ if (error instanceof EncodeError)
115
+ throw error;
116
+ throw new EncodeError(`Sythos Canvas QR: invalid canvas: ${error.message}`);
117
+ }
118
+ if (!analysis.safe) {
119
+ unsafeAnalysis = analysis;
120
+ continue;
121
+ }
122
+ selected = { matrix, canvas };
123
+ break;
124
+ }
125
+ if (!selected) {
126
+ if (unsafeAnalysis) {
127
+ throw new EncodeError('Sythos Canvas QR: canvas is not safe for the selected QR version; ' +
128
+ `it touches ${unsafeAnalysis.touchedCodewordCount} codewords and has ` +
129
+ `a per-block correction budget of ${unsafeAnalysis.correctionBudgetPerBlock}`);
130
+ }
131
+ if (capacityError)
132
+ throw capacityError;
133
+ throw new EncodeError('Sythos Canvas QR: unable to select a QR version');
134
+ }
135
+ const { matrix, canvas } = selected;
136
+ clearCanvas(matrix, canvasModules(matrix.width, canvas));
137
+ matrix.frameqr = {
138
+ profile: FRAMEQR_PROFILE.id,
139
+ certified: false,
140
+ canvas,
141
+ };
142
+ return matrix;
143
+ }
@@ -0,0 +1,33 @@
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
+ export { encodeFrameQR } from './encoder.js';
31
+ export { decodeFrameQR } from './decoder.js';
32
+ export { detectFrameQR, detectAndDecodeFrameQR } from './detector.js';
33
+ export { FRAMEQR_PROFILE, FRAMEQR_CANVAS_SHAPES, canvasModules, normalizeCanvasSpec, analyzeCanvasDamage, validateCanvasSpec, validateFrameQrTables, } from './tables.js';