@vielzeug/sigil 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +40 -0
  2. package/dist/_dev.cjs +2 -0
  3. package/dist/_dev.cjs.map +1 -0
  4. package/dist/_dev.d.ts +2 -0
  5. package/dist/_dev.d.ts.map +1 -0
  6. package/dist/_dev.js +6 -0
  7. package/dist/_dev.js.map +1 -0
  8. package/dist/_format.cjs +2 -0
  9. package/dist/_format.cjs.map +1 -0
  10. package/dist/_format.d.ts +11 -0
  11. package/dist/_format.d.ts.map +1 -0
  12. package/dist/_format.js +37 -0
  13. package/dist/_format.js.map +1 -0
  14. package/dist/_galois.cjs +2 -0
  15. package/dist/_galois.cjs.map +1 -0
  16. package/dist/_galois.d.ts +13 -0
  17. package/dist/_galois.d.ts.map +1 -0
  18. package/dist/_galois.js +22 -0
  19. package/dist/_galois.js.map +1 -0
  20. package/dist/_mask.cjs +2 -0
  21. package/dist/_mask.cjs.map +1 -0
  22. package/dist/_mask.d.ts +14 -0
  23. package/dist/_mask.d.ts.map +1 -0
  24. package/dist/_mask.js +81 -0
  25. package/dist/_mask.js.map +1 -0
  26. package/dist/_matrix.cjs +2 -0
  27. package/dist/_matrix.cjs.map +1 -0
  28. package/dist/_matrix.d.ts +18 -0
  29. package/dist/_matrix.d.ts.map +1 -0
  30. package/dist/_matrix.js +65 -0
  31. package/dist/_matrix.js.map +1 -0
  32. package/dist/_reed-solomon.cjs +2 -0
  33. package/dist/_reed-solomon.cjs.map +1 -0
  34. package/dist/_reed-solomon.d.ts +3 -0
  35. package/dist/_reed-solomon.d.ts.map +1 -0
  36. package/dist/_reed-solomon.js +22 -0
  37. package/dist/_reed-solomon.js.map +1 -0
  38. package/dist/_segments.cjs +2 -0
  39. package/dist/_segments.cjs.map +1 -0
  40. package/dist/_segments.d.ts +32 -0
  41. package/dist/_segments.d.ts.map +1 -0
  42. package/dist/_segments.js +70 -0
  43. package/dist/_segments.js.map +1 -0
  44. package/dist/_tables.cjs +2 -0
  45. package/dist/_tables.cjs.map +1 -0
  46. package/dist/_tables.d.ts +46 -0
  47. package/dist/_tables.d.ts.map +1 -0
  48. package/dist/_tables.js +409 -0
  49. package/dist/_tables.js.map +1 -0
  50. package/dist/canvas.cjs +2 -0
  51. package/dist/canvas.cjs.map +1 -0
  52. package/dist/canvas.d.ts +9 -0
  53. package/dist/canvas.d.ts.map +1 -0
  54. package/dist/canvas.js +14 -0
  55. package/dist/canvas.js.map +1 -0
  56. package/dist/encode.cjs +2 -0
  57. package/dist/encode.cjs.map +1 -0
  58. package/dist/encode.d.ts +9 -0
  59. package/dist/encode.d.ts.map +1 -0
  60. package/dist/encode.js +112 -0
  61. package/dist/encode.js.map +1 -0
  62. package/dist/errors.cjs +2 -0
  63. package/dist/errors.cjs.map +1 -0
  64. package/dist/errors.d.ts +30 -0
  65. package/dist/errors.d.ts.map +1 -0
  66. package/dist/errors.js +17 -0
  67. package/dist/errors.js.map +1 -0
  68. package/dist/index.cjs +1 -0
  69. package/dist/index.d.ts +7 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +6 -0
  72. package/dist/scan.cjs +2 -0
  73. package/dist/scan.cjs.map +1 -0
  74. package/dist/scan.d.ts +12 -0
  75. package/dist/scan.d.ts.map +1 -0
  76. package/dist/scan.js +141 -0
  77. package/dist/scan.js.map +1 -0
  78. package/dist/sigil.cjs +2 -0
  79. package/dist/sigil.cjs.map +1 -0
  80. package/dist/sigil.iife.js +2 -0
  81. package/dist/sigil.iife.js.map +1 -0
  82. package/dist/sigil.js +2 -0
  83. package/dist/sigil.js.map +1 -0
  84. package/dist/svg.cjs +2 -0
  85. package/dist/svg.cjs.map +1 -0
  86. package/dist/svg.d.ts +3 -0
  87. package/dist/svg.d.ts.map +1 -0
  88. package/dist/svg.js +26 -0
  89. package/dist/svg.js.map +1 -0
  90. package/dist/types.d.ts +118 -0
  91. package/dist/types.d.ts.map +1 -0
  92. package/package.json +48 -0
@@ -0,0 +1,70 @@
1
+ import { ALPHANUMERIC_CHARSET as e, CHAR_COUNT_BITS as t, MODE_BITS as n, dataCodewords as r, versionGroup as i } from "./_tables.js";
2
+ //#region src/_segments.ts
3
+ var a = class {
4
+ bits = [];
5
+ get length() {
6
+ return this.bits.length;
7
+ }
8
+ append(e, t) {
9
+ for (let n = t - 1; n >= 0; n--) this.bits.push(e >>> n & 1);
10
+ }
11
+ padToByte() {
12
+ for (; this.bits.length % 8 != 0;) this.bits.push(0);
13
+ }
14
+ toBytes() {
15
+ let e = [];
16
+ for (let t = 0; t < this.bits.length; t += 8) {
17
+ let n = 0;
18
+ for (let e = 0; e < 8; e++) n = n << 1 | this.bits[t + e];
19
+ e.push(n);
20
+ }
21
+ return e;
22
+ }
23
+ };
24
+ function o(e) {
25
+ if (/^\d+$/.test(e)) return "numeric";
26
+ for (let t of e) if (!"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:".includes(t)) return "byte";
27
+ return "alphanumeric";
28
+ }
29
+ var s = new TextEncoder();
30
+ function c(e, t) {
31
+ switch (t) {
32
+ case "numeric": return Math.floor(e.length / 3) * 10 + (e.length % 3 == 1 ? 4 : e.length % 3 == 2 ? 7 : 0);
33
+ case "alphanumeric": return Math.floor(e.length / 2) * 11 + e.length % 2 * 6;
34
+ case "byte": return s.encode(e).length * 8;
35
+ }
36
+ }
37
+ function l(r, a, o, c) {
38
+ switch (r.append(n[o], 4), r.append(u(a, o), t[o][i(c)]), o) {
39
+ case "numeric":
40
+ for (let e = 0; e < a.length;) {
41
+ let t = Math.min(3, a.length - e);
42
+ r.append(Number.parseInt(a.slice(e, e + t), 10), t === 3 ? 10 : t === 2 ? 7 : 4), e += t;
43
+ }
44
+ break;
45
+ case "alphanumeric":
46
+ for (let t = 0; t < a.length;) t + 1 < a.length ? (r.append(e.indexOf(a[t]) * 45 + e.indexOf(a[t + 1]), 11), t += 2) : (r.append(e.indexOf(a[t]), 6), t += 1);
47
+ break;
48
+ case "byte": for (let e of s.encode(a)) r.append(e, 8);
49
+ }
50
+ }
51
+ function u(e, t) {
52
+ return t === "byte" ? s.encode(e).length : e.length;
53
+ }
54
+ var d = (e, t) => r(e, t) * 8;
55
+ function f(e, n, r) {
56
+ return 4 + t[n][i(r)] + c(e, n);
57
+ }
58
+ function p(e, t, n, i) {
59
+ let o = new a();
60
+ l(o, e, t, n);
61
+ let s = d(n, i);
62
+ o.append(0, Math.min(4, s - o.length)), o.padToByte();
63
+ let c = o.toBytes(), u = [236, 17];
64
+ for (let e = 0; c.length < r(n, i); e++) c.push(u[e % 2]);
65
+ return c;
66
+ }
67
+ //#endregion
68
+ export { a as BitStream, l as appendSegment, p as buildDataCodewords, u as charCount, c as dataBitLength, d as dataCapacityBits, o as detectMode, f as segmentBits };
69
+
70
+ //# sourceMappingURL=_segments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_segments.js","names":[],"sources":["../src/_segments.ts"],"sourcesContent":["import { ALPHANUMERIC_CHARSET, CHAR_COUNT_BITS, dataCodewords, MODE_BITS, versionGroup } from './_tables';\nimport type { QrErrorCorrection, QrMode } from './types';\n\n/**\n * Data-segment assembly: one segment (single mode) covering the whole input,\n * followed by terminator, byte alignment, and 0xEC/0x11 padding (§7.4–7.5).\n * Kanji and multi-segment optimization are out of scope.\n */\n\n/** Growable bit stream; `bytes` is valid only after `padToByte()`. */\nexport class BitStream {\n private bits: number[] = [];\n\n get length(): number {\n return this.bits.length;\n }\n\n append(value: number, width: number): void {\n for (let i = width - 1; i >= 0; i--) this.bits.push((value >>> i) & 1);\n }\n\n padToByte(): void {\n while (this.bits.length % 8 !== 0) this.bits.push(0);\n }\n\n toBytes(): number[] {\n const out: number[] = [];\n for (let i = 0; i < this.bits.length; i += 8) {\n let b = 0;\n for (let j = 0; j < 8; j++) b = (b << 1) | this.bits[i + j];\n out.push(b);\n }\n return out;\n }\n}\n\n/** Most compact mode able to encode the whole input. */\nexport function detectMode(data: string): QrMode {\n if (/^\\d+$/.test(data)) return 'numeric';\n for (const ch of data) if (!ALPHANUMERIC_CHARSET.includes(ch)) return 'byte';\n return 'alphanumeric';\n}\n\nconst textEncoder = new TextEncoder();\n\n/** Payload bits for the segment body (without mode/count headers). */\nexport function dataBitLength(data: string, mode: QrMode): number {\n switch (mode) {\n case 'numeric':\n return Math.floor(data.length / 3) * 10 + (data.length % 3 === 1 ? 4 : data.length % 3 === 2 ? 7 : 0);\n case 'alphanumeric':\n return Math.floor(data.length / 2) * 11 + (data.length % 2) * 6;\n case 'byte':\n return textEncoder.encode(data).length * 8;\n }\n}\n\n/** Append mode indicator, char count, and payload bits. */\nexport function appendSegment(stream: BitStream, data: string, mode: QrMode, version: number): void {\n stream.append(MODE_BITS[mode], 4);\n stream.append(charCount(data, mode), CHAR_COUNT_BITS[mode][versionGroup(version)]);\n switch (mode) {\n case 'numeric':\n for (let i = 0; i < data.length; ) {\n const n = Math.min(3, data.length - i);\n stream.append(Number.parseInt(data.slice(i, i + n), 10), n === 3 ? 10 : n === 2 ? 7 : 4);\n i += n;\n }\n break;\n case 'alphanumeric':\n for (let i = 0; i < data.length; ) {\n if (i + 1 < data.length) {\n stream.append(ALPHANUMERIC_CHARSET.indexOf(data[i]) * 45 + ALPHANUMERIC_CHARSET.indexOf(data[i + 1]), 11);\n i += 2;\n } else {\n stream.append(ALPHANUMERIC_CHARSET.indexOf(data[i]), 6);\n i += 1;\n }\n }\n break;\n case 'byte':\n for (const b of textEncoder.encode(data)) stream.append(b, 8);\n break;\n }\n}\n\n/** Chars/bytes reported in the count field. Byte mode counts encoded bytes. */\nexport function charCount(data: string, mode: QrMode): number {\n return mode === 'byte' ? textEncoder.encode(data).length : data.length;\n}\n\n/** Capacity in bits for the data area of (version, level). */\nexport const dataCapacityBits = (version: number, level: QrErrorCorrection): number =>\n dataCodewords(version, level) * 8;\n\n/** Bits a segment occupies at `version`: header + payload, before terminator. */\nexport function segmentBits(data: string, mode: QrMode, version: number): number {\n return 4 + CHAR_COUNT_BITS[mode][versionGroup(version)] + dataBitLength(data, mode);\n}\n\n/**\n * Full data-codeword sequence for (version, level): segment + terminator +\n * alignment + pad bytes. Caller guarantees the segment fits.\n */\nexport function buildDataCodewords(data: string, mode: QrMode, version: number, level: QrErrorCorrection): number[] {\n const stream = new BitStream();\n appendSegment(stream, data, mode, version);\n const capacity = dataCapacityBits(version, level);\n stream.append(0, Math.min(4, capacity - stream.length)); // terminator\n stream.padToByte();\n const bytes = stream.toBytes();\n const pad = [0xec, 0x11];\n for (let i = 0; bytes.length < dataCodewords(version, level); i++) bytes.push(pad[i % 2]);\n return bytes;\n}\n"],"mappings":";;AAUA,IAAa,IAAb,MAAuB;CACrB,OAAyB,CAAC;CAE1B,IAAI,SAAiB;EACnB,OAAO,KAAK,KAAK;CACnB;CAEA,OAAO,GAAe,GAAqB;EACzC,KAAK,IAAI,IAAI,IAAQ,GAAG,KAAK,GAAG,KAAK,KAAK,KAAK,KAAM,MAAU,IAAK,CAAC;CACvE;CAEA,YAAkB;EAChB,OAAO,KAAK,KAAK,SAAS,KAAM,IAAG,KAAK,KAAK,KAAK,CAAC;CACrD;CAEA,UAAoB;EAClB,IAAM,IAAgB,CAAC;EACvB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,KAAK,QAAQ,KAAK,GAAG;GAC5C,IAAI,IAAI;GACR,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK,IAAK,KAAK,IAAK,KAAK,KAAK,IAAI;GACzD,EAAI,KAAK,CAAC;EACZ;EACA,OAAO;CACT;AACF;AAGA,SAAgB,EAAW,GAAsB;CAC/C,IAAI,QAAQ,KAAK,CAAI,GAAG,OAAO;CAC/B,KAAK,IAAM,KAAM,GAAM,IAAI,CAAA,gDAAsB,SAAS,CAAE,GAAG,OAAO;CACtE,OAAO;AACT;AAEA,IAAM,IAAc,IAAI,YAAY;AAGpC,SAAgB,EAAc,GAAc,GAAsB;CAChE,QAAQ,GAAR;EACE,KAAK,WACH,OA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SAAgB,EAAY,GAAc,GAAc,GAAyB;CAC/E,OAAO,IAAI,EAAgB,EAAK,CAAC,EAAa,CAAO,KAAK,EAAc,GAAM,CAAI;AACpF;AAMA,SAAgB,EAAmB,GAAc,GAAc,GAAiB,GAAoC;CAClH,IAAM,IAAS,IAAI,EAAU;CAC7B,EAAc,GAAQ,GAAM,GAAM,CAAO;CACzC,IAAM,IAAW,EAAiB,GAAS,CAAK;CAEhD,AADA,EAAO,OAAO,GAAG,KAAK,IAAI,GAAG,IAAW,EAAO,MAAM,CAAC,GACtD,EAAO,UAAU;CACjB,IAAM,IAAQ,EAAO,QAAQ,GACvB,IAAM,CAAC,KAAM,EAAI;CACvB,KAAK,IAAI,IAAI,GAAG,EAAM,SAAS,EAAc,GAAS,CAAK,GAAG,KAAK,EAAM,KAAK,EAAI,IAAI,EAAE;CACxF,OAAO;AACT"}
@@ -0,0 +1,2 @@
1
+ var e=[`L`,`M`,`Q`,`H`],t=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,n={alphanumeric:2,byte:4,numeric:1},r={alphanumeric:[9,11,13],byte:[8,16,16],numeric:[10,12,14]},i={H:2,L:1,M:0,Q:3},a=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],o=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,56,59,62,65,68,71,74,77,81]],s=t=>e.indexOf(t),c=e=>e*4+17;function l(e){if(e===1)return[];let t=Math.floor(e/7)+2,n=e===32?26:Math.ceil((e*4+4)/(t*2-2))*2,r=[6];for(let i=e*4+10;r.length<t;i-=n)r.splice(1,0,i);return r}function u(e){let t=(16*e+128)*e+64;if(e>=2){let n=Math.floor(e/7)+2;t-=(25*n-10)*n-55,e>=7&&(t-=36)}return t}var d=e=>Math.floor(u(e)/8);function f(e,t){return a[s(t)][e]}function p(e,t){return o[s(t)][e]}function m(e,t){return d(e)-f(e,t)*p(e,t)}function h(e){return e<=9?0:e<=26?1:2}exports.ALPHANUMERIC_CHARSET=t,exports.CHAR_COUNT_BITS=r,exports.EC_CODEWORDS_PER_BLOCK=a,exports.EC_LEVELS=e,exports.FORMAT_EC_BITS=i,exports.MODE_BITS=n,exports.NUM_EC_BLOCKS=o,exports.alignmentPatternPositions=l,exports.dataCodewords=m,exports.ecCodewordsPerBlock=f,exports.matrixSize=c,exports.numEcBlocks=p,exports.rawDataModules=u,exports.totalCodewords=d,exports.versionGroup=h;
2
+ //# sourceMappingURL=_tables.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_tables.cjs","names":[],"sources":["../src/_tables.ts"],"sourcesContent":["import type { QrErrorCorrection, QrMode } from './types';\n\n/**\n * QR Model 2 lookup tables, transcribed from ISO/IEC 18004:2015:\n * - `EC_CODEWORDS_PER_BLOCK` / `NUM_EC_BLOCKS` — Table 9 (error-correction\n * characteristics). Stored as per-block EC codewords and block count; the\n * group-1/group-2 split is derived, since all blocks share one EC length.\n * - `alignmentPatternPositions` — Table E.1, computed by the spec formula.\n * - `CHAR_COUNT_BITS` — Table 3 (character-count indicator bit widths).\n * - `FORMAT_EC_BITS` — Table 10 (2-bit level field inside format information).\n *\n * `tables.test.ts` cross-checks every entry against the raw-module formula, so\n * a transcription slip fails the consistency test before the decode oracle runs.\n */\n\n/** Index order used by the table rows below. */\nexport const EC_LEVELS = ['L', 'M', 'Q', 'H'] as const;\n\nexport const ALPHANUMERIC_CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:';\n\n/** Mode indicators (Table 2). */\nexport const MODE_BITS: Record<QrMode, number> = {\n alphanumeric: 0b0010,\n byte: 0b0100,\n numeric: 0b0001,\n};\n\n/** Character-count indicator widths for version groups 1–9 / 10–26 / 27–40. */\nexport const CHAR_COUNT_BITS: Record<QrMode, readonly [number, number, number]> = {\n alphanumeric: [9, 11, 13],\n byte: [8, 16, 16],\n numeric: [10, 12, 14],\n};\n\n/** EC level bits inside format information (L=01, M=00, Q=11, H=10). */\nexport const FORMAT_EC_BITS: Record<QrErrorCorrection, number> = { H: 0b10, L: 0b01, M: 0b00, Q: 0b11 };\n\n/** Row 0 = L, row 1 = M, row 2 = Q, row 3 = H; column 0 unused (versions start at 1). */\nexport const EC_CODEWORDS_PER_BLOCK: ReadonlyArray<ReadonlyArray<number>> = [\n // prettier-ignore\n [\n -1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n // prettier-ignore\n [\n -1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28,\n 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,\n ],\n // prettier-ignore\n [\n -1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n // prettier-ignore\n [\n -1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n];\n\nexport const NUM_EC_BLOCKS: ReadonlyArray<ReadonlyArray<number>> = [\n // prettier-ignore\n [\n -1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19,\n 19, 20, 21, 22, 24, 25,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31,\n 33, 35, 37, 38, 40, 43, 45, 47, 49,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43,\n 45, 48, 51, 53, 56, 59, 62, 65, 68,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48,\n 51, 56, 59, 62, 65, 68, 71, 74, 77, 81,\n ],\n];\n\nconst ecIndex = (level: QrErrorCorrection): number => EC_LEVELS.indexOf(level);\n\n/** Total modules per side. */\nexport const matrixSize = (version: number): number => version * 4 + 17;\n\n/** Alignment-pattern center coordinates (Table E.1 formula). */\nexport function alignmentPatternPositions(version: number): readonly number[] {\n if (version === 1) return [];\n const numAlign = Math.floor(version / 7) + 2;\n const step = version === 32 ? 26 : Math.ceil((version * 4 + 4) / (numAlign * 2 - 2)) * 2;\n const result = [6];\n for (let pos = version * 4 + 10; result.length < numAlign; pos -= step) result.splice(1, 0, pos);\n return result;\n}\n\n/**\n * Total raw modules available for data + EC + remainder bits, derived from the\n * symbol geometry (Table 1 / Annex A): full grid minus finders, separators,\n * timing, alignment, dark module, format and version information.\n */\nexport function rawDataModules(version: number): number {\n let result = (16 * version + 128) * version + 64;\n if (version >= 2) {\n const numAlign = Math.floor(version / 7) + 2;\n result -= (25 * numAlign - 10) * numAlign - 55;\n if (version >= 7) result -= 36;\n }\n return result;\n}\n\n/** Total codewords (data + EC) for a version. */\nexport const totalCodewords = (version: number): number => Math.floor(rawDataModules(version) / 8);\n\n/** Leftover bits after the codeword stream (0, 3, 4, or 7 by version). */\nexport const remainderBits = (version: number): number => rawDataModules(version) % 8;\n\nexport function ecCodewordsPerBlock(version: number, level: QrErrorCorrection): number {\n return EC_CODEWORDS_PER_BLOCK[ecIndex(level)][version];\n}\n\nexport function numEcBlocks(version: number, level: QrErrorCorrection): number {\n return NUM_EC_BLOCKS[ecIndex(level)][version];\n}\n\n/** Data codewords for a (version, level) pair. */\nexport function dataCodewords(version: number, level: QrErrorCorrection): number {\n return totalCodewords(version) - ecCodewordsPerBlock(version, level) * numEcBlocks(version, level);\n}\n\n/** Version group for the character-count indicator: 0 → 1–9, 1 → 10–26, 2 → 27–40. */\nexport function versionGroup(version: number): 0 | 1 | 2 {\n return version <= 9 ? 0 : version <= 26 ? 1 : 2;\n}\n"],"mappings":"AAgBA,IAAa,EAAY,CAAC,IAAK,IAAK,IAAK,GAAG,EAE/B,EAAuB,gDAGvB,EAAoC,CAC/C,aAAc,EACd,KAAM,EACN,QAAS,CACX,EAGa,EAAqE,CAChF,aAAc,CAAC,EAAG,GAAI,EAAE,EACxB,KAAM,CAAC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,EAAU,EAAI,IAAM,EAAW,EAAI,EAAE,EAAI,EACjF,EAAS,CAAC,CAAC,EACjB,IAAK,IAAI,EAAM,EAAU,EAAI,GAAI,EAAO,OAAS,EAAU,GAAO,EAAM,EAAO,OAAO,EAAG,EAAG,CAAG,EAC/F,OAAO,CACT,CAOA,SAAgB,EAAe,EAAyB,CACtD,IAAI,GAAU,GAAK,EAAU,KAAO,EAAU,GAC9C,GAAI,GAAW,EAAG,CAChB,IAAM,EAAW,KAAK,MAAM,EAAU,CAAC,EAAI,EAC3C,IAAW,GAAK,EAAW,IAAM,EAAW,GACxC,GAAW,IAAG,GAAU,GAC9B,CACA,OAAO,CACT,CAGA,IAAa,EAAkB,GAA4B,KAAK,MAAM,EAAe,CAAO,EAAI,CAAC,EAKjG,SAAgB,EAAoB,EAAiB,EAAkC,CACrF,OAAO,EAAuB,EAAQ,CAAK,EAAE,CAAC,EAChD,CAEA,SAAgB,EAAY,EAAiB,EAAkC,CAC7E,OAAO,EAAc,EAAQ,CAAK,EAAE,CAAC,EACvC,CAGA,SAAgB,EAAc,EAAiB,EAAkC,CAC/E,OAAO,EAAe,CAAO,EAAI,EAAoB,EAAS,CAAK,EAAI,EAAY,EAAS,CAAK,CACnG,CAGA,SAAgB,EAAa,EAA4B,CACvD,OAAO,GAAW,EAAI,EAAI,GAAW,GAAK,EAAI,CAChD"}
@@ -0,0 +1,46 @@
1
+ import type { QrErrorCorrection, QrMode } from './types';
2
+ /**
3
+ * QR Model 2 lookup tables, transcribed from ISO/IEC 18004:2015:
4
+ * - `EC_CODEWORDS_PER_BLOCK` / `NUM_EC_BLOCKS` — Table 9 (error-correction
5
+ * characteristics). Stored as per-block EC codewords and block count; the
6
+ * group-1/group-2 split is derived, since all blocks share one EC length.
7
+ * - `alignmentPatternPositions` — Table E.1, computed by the spec formula.
8
+ * - `CHAR_COUNT_BITS` — Table 3 (character-count indicator bit widths).
9
+ * - `FORMAT_EC_BITS` — Table 10 (2-bit level field inside format information).
10
+ *
11
+ * `tables.test.ts` cross-checks every entry against the raw-module formula, so
12
+ * a transcription slip fails the consistency test before the decode oracle runs.
13
+ */
14
+ /** Index order used by the table rows below. */
15
+ export declare const EC_LEVELS: readonly ["L", "M", "Q", "H"];
16
+ export declare const ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
17
+ /** Mode indicators (Table 2). */
18
+ export declare const MODE_BITS: Record<QrMode, number>;
19
+ /** Character-count indicator widths for version groups 1–9 / 10–26 / 27–40. */
20
+ export declare const CHAR_COUNT_BITS: Record<QrMode, readonly [number, number, number]>;
21
+ /** EC level bits inside format information (L=01, M=00, Q=11, H=10). */
22
+ export declare const FORMAT_EC_BITS: Record<QrErrorCorrection, number>;
23
+ /** Row 0 = L, row 1 = M, row 2 = Q, row 3 = H; column 0 unused (versions start at 1). */
24
+ export declare const EC_CODEWORDS_PER_BLOCK: ReadonlyArray<ReadonlyArray<number>>;
25
+ export declare const NUM_EC_BLOCKS: ReadonlyArray<ReadonlyArray<number>>;
26
+ /** Total modules per side. */
27
+ export declare const matrixSize: (version: number) => number;
28
+ /** Alignment-pattern center coordinates (Table E.1 formula). */
29
+ export declare function alignmentPatternPositions(version: number): readonly number[];
30
+ /**
31
+ * Total raw modules available for data + EC + remainder bits, derived from the
32
+ * symbol geometry (Table 1 / Annex A): full grid minus finders, separators,
33
+ * timing, alignment, dark module, format and version information.
34
+ */
35
+ export declare function rawDataModules(version: number): number;
36
+ /** Total codewords (data + EC) for a version. */
37
+ export declare const totalCodewords: (version: number) => number;
38
+ /** Leftover bits after the codeword stream (0, 3, 4, or 7 by version). */
39
+ export declare const remainderBits: (version: number) => number;
40
+ export declare function ecCodewordsPerBlock(version: number, level: QrErrorCorrection): number;
41
+ export declare function numEcBlocks(version: number, level: QrErrorCorrection): number;
42
+ /** Data codewords for a (version, level) pair. */
43
+ export declare function dataCodewords(version: number, level: QrErrorCorrection): number;
44
+ /** Version group for the character-count indicator: 0 → 1–9, 1 → 10–26, 2 → 27–40. */
45
+ export declare function versionGroup(version: number): 0 | 1 | 2;
46
+ //# sourceMappingURL=_tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_tables.d.ts","sourceRoot":"","sources":["../src/_tables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEzD;;;;;;;;;;;GAWG;AAEH,gDAAgD;AAChD,eAAO,MAAM,SAAS,+BAAgC,CAAC;AAEvD,eAAO,MAAM,oBAAoB,kDAAkD,CAAC;AAEpF,iCAAiC;AACjC,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAI5C,CAAC;AAEF,+EAA+E;AAC/E,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAI7E,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAA0C,CAAC;AAExG,yFAAyF;AACzF,eAAO,MAAM,sBAAsB,EAAE,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAqBvE,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAqB9D,CAAC;AAIF,8BAA8B;AAC9B,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,KAAG,MAA0B,CAAC;AAExE,gEAAgE;AAChE,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAO5E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQtD;AAED,iDAAiD;AACjD,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,MAAiD,CAAC;AAEnG,0EAA0E;AAC1E,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,KAAG,MAAqC,CAAC;AAEtF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAErF;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAE7E;AAED,kDAAkD;AAClD,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAE/E;AAED,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAEvD"}
@@ -0,0 +1,409 @@
1
+ //#region src/_tables.ts
2
+ var e = [
3
+ "L",
4
+ "M",
5
+ "Q",
6
+ "H"
7
+ ], t = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:", n = {
8
+ alphanumeric: 2,
9
+ byte: 4,
10
+ numeric: 1
11
+ }, r = {
12
+ alphanumeric: [
13
+ 9,
14
+ 11,
15
+ 13
16
+ ],
17
+ byte: [
18
+ 8,
19
+ 16,
20
+ 16
21
+ ],
22
+ numeric: [
23
+ 10,
24
+ 12,
25
+ 14
26
+ ]
27
+ }, i = {
28
+ H: 2,
29
+ L: 1,
30
+ M: 0,
31
+ Q: 3
32
+ }, a = [
33
+ [
34
+ -1,
35
+ 7,
36
+ 10,
37
+ 15,
38
+ 20,
39
+ 26,
40
+ 18,
41
+ 20,
42
+ 24,
43
+ 30,
44
+ 18,
45
+ 20,
46
+ 24,
47
+ 26,
48
+ 30,
49
+ 22,
50
+ 24,
51
+ 28,
52
+ 30,
53
+ 28,
54
+ 28,
55
+ 28,
56
+ 28,
57
+ 30,
58
+ 30,
59
+ 26,
60
+ 28,
61
+ 30,
62
+ 30,
63
+ 30,
64
+ 30,
65
+ 30,
66
+ 30,
67
+ 30,
68
+ 30,
69
+ 30,
70
+ 30,
71
+ 30,
72
+ 30,
73
+ 30,
74
+ 30
75
+ ],
76
+ [
77
+ -1,
78
+ 10,
79
+ 16,
80
+ 26,
81
+ 18,
82
+ 24,
83
+ 16,
84
+ 18,
85
+ 22,
86
+ 22,
87
+ 26,
88
+ 30,
89
+ 22,
90
+ 22,
91
+ 24,
92
+ 24,
93
+ 28,
94
+ 28,
95
+ 26,
96
+ 26,
97
+ 26,
98
+ 26,
99
+ 28,
100
+ 28,
101
+ 28,
102
+ 28,
103
+ 28,
104
+ 28,
105
+ 28,
106
+ 28,
107
+ 28,
108
+ 28,
109
+ 28,
110
+ 28,
111
+ 28,
112
+ 28,
113
+ 28,
114
+ 28,
115
+ 28,
116
+ 28,
117
+ 28
118
+ ],
119
+ [
120
+ -1,
121
+ 13,
122
+ 22,
123
+ 18,
124
+ 26,
125
+ 18,
126
+ 24,
127
+ 18,
128
+ 22,
129
+ 20,
130
+ 24,
131
+ 28,
132
+ 26,
133
+ 24,
134
+ 20,
135
+ 30,
136
+ 24,
137
+ 28,
138
+ 28,
139
+ 26,
140
+ 30,
141
+ 28,
142
+ 30,
143
+ 30,
144
+ 30,
145
+ 30,
146
+ 28,
147
+ 30,
148
+ 30,
149
+ 30,
150
+ 30,
151
+ 30,
152
+ 30,
153
+ 30,
154
+ 30,
155
+ 30,
156
+ 30,
157
+ 30,
158
+ 30,
159
+ 30,
160
+ 30
161
+ ],
162
+ [
163
+ -1,
164
+ 17,
165
+ 28,
166
+ 22,
167
+ 16,
168
+ 22,
169
+ 28,
170
+ 26,
171
+ 26,
172
+ 24,
173
+ 28,
174
+ 24,
175
+ 28,
176
+ 22,
177
+ 24,
178
+ 24,
179
+ 30,
180
+ 28,
181
+ 28,
182
+ 26,
183
+ 28,
184
+ 30,
185
+ 24,
186
+ 30,
187
+ 30,
188
+ 30,
189
+ 30,
190
+ 30,
191
+ 30,
192
+ 30,
193
+ 30,
194
+ 30,
195
+ 30,
196
+ 30,
197
+ 30,
198
+ 30,
199
+ 30,
200
+ 30,
201
+ 30,
202
+ 30,
203
+ 30
204
+ ]
205
+ ], o = [
206
+ [
207
+ -1,
208
+ 1,
209
+ 1,
210
+ 1,
211
+ 1,
212
+ 1,
213
+ 2,
214
+ 2,
215
+ 2,
216
+ 2,
217
+ 4,
218
+ 4,
219
+ 4,
220
+ 4,
221
+ 4,
222
+ 6,
223
+ 6,
224
+ 6,
225
+ 6,
226
+ 7,
227
+ 8,
228
+ 8,
229
+ 9,
230
+ 9,
231
+ 10,
232
+ 12,
233
+ 12,
234
+ 12,
235
+ 13,
236
+ 14,
237
+ 15,
238
+ 16,
239
+ 17,
240
+ 18,
241
+ 19,
242
+ 19,
243
+ 20,
244
+ 21,
245
+ 22,
246
+ 24,
247
+ 25
248
+ ],
249
+ [
250
+ -1,
251
+ 1,
252
+ 1,
253
+ 1,
254
+ 2,
255
+ 2,
256
+ 4,
257
+ 4,
258
+ 4,
259
+ 5,
260
+ 5,
261
+ 5,
262
+ 8,
263
+ 9,
264
+ 9,
265
+ 10,
266
+ 10,
267
+ 11,
268
+ 13,
269
+ 14,
270
+ 16,
271
+ 17,
272
+ 17,
273
+ 18,
274
+ 20,
275
+ 21,
276
+ 23,
277
+ 25,
278
+ 26,
279
+ 28,
280
+ 29,
281
+ 31,
282
+ 33,
283
+ 35,
284
+ 37,
285
+ 38,
286
+ 40,
287
+ 43,
288
+ 45,
289
+ 47,
290
+ 49
291
+ ],
292
+ [
293
+ -1,
294
+ 1,
295
+ 1,
296
+ 2,
297
+ 2,
298
+ 4,
299
+ 4,
300
+ 6,
301
+ 6,
302
+ 8,
303
+ 8,
304
+ 8,
305
+ 10,
306
+ 12,
307
+ 16,
308
+ 12,
309
+ 17,
310
+ 16,
311
+ 18,
312
+ 21,
313
+ 20,
314
+ 23,
315
+ 23,
316
+ 25,
317
+ 27,
318
+ 29,
319
+ 34,
320
+ 34,
321
+ 35,
322
+ 38,
323
+ 40,
324
+ 43,
325
+ 45,
326
+ 48,
327
+ 51,
328
+ 53,
329
+ 56,
330
+ 59,
331
+ 62,
332
+ 65,
333
+ 68
334
+ ],
335
+ [
336
+ -1,
337
+ 1,
338
+ 1,
339
+ 2,
340
+ 4,
341
+ 4,
342
+ 4,
343
+ 5,
344
+ 6,
345
+ 8,
346
+ 8,
347
+ 11,
348
+ 11,
349
+ 16,
350
+ 16,
351
+ 18,
352
+ 16,
353
+ 19,
354
+ 21,
355
+ 25,
356
+ 25,
357
+ 25,
358
+ 34,
359
+ 30,
360
+ 32,
361
+ 35,
362
+ 37,
363
+ 40,
364
+ 42,
365
+ 45,
366
+ 48,
367
+ 51,
368
+ 56,
369
+ 59,
370
+ 62,
371
+ 65,
372
+ 68,
373
+ 71,
374
+ 74,
375
+ 77,
376
+ 81
377
+ ]
378
+ ], s = (t) => e.indexOf(t), c = (e) => e * 4 + 17;
379
+ function l(e) {
380
+ if (e === 1) return [];
381
+ let t = Math.floor(e / 7) + 2, n = e === 32 ? 26 : Math.ceil((e * 4 + 4) / (t * 2 - 2)) * 2, r = [6];
382
+ for (let i = e * 4 + 10; r.length < t; i -= n) r.splice(1, 0, i);
383
+ return r;
384
+ }
385
+ function u(e) {
386
+ let t = (16 * e + 128) * e + 64;
387
+ if (e >= 2) {
388
+ let n = Math.floor(e / 7) + 2;
389
+ t -= (25 * n - 10) * n - 55, e >= 7 && (t -= 36);
390
+ }
391
+ return t;
392
+ }
393
+ var d = (e) => Math.floor(u(e) / 8);
394
+ function f(e, t) {
395
+ return a[s(t)][e];
396
+ }
397
+ function p(e, t) {
398
+ return o[s(t)][e];
399
+ }
400
+ function m(e, t) {
401
+ return d(e) - f(e, t) * p(e, t);
402
+ }
403
+ function h(e) {
404
+ return e <= 9 ? 0 : e <= 26 ? 1 : 2;
405
+ }
406
+ //#endregion
407
+ export { t as ALPHANUMERIC_CHARSET, r as CHAR_COUNT_BITS, a as EC_CODEWORDS_PER_BLOCK, e as EC_LEVELS, i as FORMAT_EC_BITS, n as MODE_BITS, o as NUM_EC_BLOCKS, l as alignmentPatternPositions, m as dataCodewords, f as ecCodewordsPerBlock, c as matrixSize, p as numEcBlocks, u as rawDataModules, d as totalCodewords, h as versionGroup };
408
+
409
+ //# sourceMappingURL=_tables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_tables.js","names":[],"sources":["../src/_tables.ts"],"sourcesContent":["import type { QrErrorCorrection, QrMode } from './types';\n\n/**\n * QR Model 2 lookup tables, transcribed from ISO/IEC 18004:2015:\n * - `EC_CODEWORDS_PER_BLOCK` / `NUM_EC_BLOCKS` — Table 9 (error-correction\n * characteristics). Stored as per-block EC codewords and block count; the\n * group-1/group-2 split is derived, since all blocks share one EC length.\n * - `alignmentPatternPositions` — Table E.1, computed by the spec formula.\n * - `CHAR_COUNT_BITS` — Table 3 (character-count indicator bit widths).\n * - `FORMAT_EC_BITS` — Table 10 (2-bit level field inside format information).\n *\n * `tables.test.ts` cross-checks every entry against the raw-module formula, so\n * a transcription slip fails the consistency test before the decode oracle runs.\n */\n\n/** Index order used by the table rows below. */\nexport const EC_LEVELS = ['L', 'M', 'Q', 'H'] as const;\n\nexport const ALPHANUMERIC_CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:';\n\n/** Mode indicators (Table 2). */\nexport const MODE_BITS: Record<QrMode, number> = {\n alphanumeric: 0b0010,\n byte: 0b0100,\n numeric: 0b0001,\n};\n\n/** Character-count indicator widths for version groups 1–9 / 10–26 / 27–40. */\nexport const CHAR_COUNT_BITS: Record<QrMode, readonly [number, number, number]> = {\n alphanumeric: [9, 11, 13],\n byte: [8, 16, 16],\n numeric: [10, 12, 14],\n};\n\n/** EC level bits inside format information (L=01, M=00, Q=11, H=10). */\nexport const FORMAT_EC_BITS: Record<QrErrorCorrection, number> = { H: 0b10, L: 0b01, M: 0b00, Q: 0b11 };\n\n/** Row 0 = L, row 1 = M, row 2 = Q, row 3 = H; column 0 unused (versions start at 1). */\nexport const EC_CODEWORDS_PER_BLOCK: ReadonlyArray<ReadonlyArray<number>> = [\n // prettier-ignore\n [\n -1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n // prettier-ignore\n [\n -1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28,\n 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,\n ],\n // prettier-ignore\n [\n -1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n // prettier-ignore\n [\n -1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n];\n\nexport const NUM_EC_BLOCKS: ReadonlyArray<ReadonlyArray<number>> = [\n // prettier-ignore\n [\n -1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19,\n 19, 20, 21, 22, 24, 25,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31,\n 33, 35, 37, 38, 40, 43, 45, 47, 49,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43,\n 45, 48, 51, 53, 56, 59, 62, 65, 68,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48,\n 51, 56, 59, 62, 65, 68, 71, 74, 77, 81,\n ],\n];\n\nconst ecIndex = (level: QrErrorCorrection): number => EC_LEVELS.indexOf(level);\n\n/** Total modules per side. */\nexport const matrixSize = (version: number): number => version * 4 + 17;\n\n/** Alignment-pattern center coordinates (Table E.1 formula). */\nexport function alignmentPatternPositions(version: number): readonly number[] {\n if (version === 1) return [];\n const numAlign = Math.floor(version / 7) + 2;\n const step = version === 32 ? 26 : Math.ceil((version * 4 + 4) / (numAlign * 2 - 2)) * 2;\n const result = [6];\n for (let pos = version * 4 + 10; result.length < numAlign; pos -= step) result.splice(1, 0, pos);\n return result;\n}\n\n/**\n * Total raw modules available for data + EC + remainder bits, derived from the\n * symbol geometry (Table 1 / Annex A): full grid minus finders, separators,\n * timing, alignment, dark module, format and version information.\n */\nexport function rawDataModules(version: number): number {\n let result = (16 * version + 128) * version + 64;\n if (version >= 2) {\n const numAlign = Math.floor(version / 7) + 2;\n result -= (25 * numAlign - 10) * numAlign - 55;\n if (version >= 7) result -= 36;\n }\n return result;\n}\n\n/** Total codewords (data + EC) for a version. */\nexport const totalCodewords = (version: number): number => Math.floor(rawDataModules(version) / 8);\n\n/** Leftover bits after the codeword stream (0, 3, 4, or 7 by version). */\nexport const remainderBits = (version: number): number => rawDataModules(version) % 8;\n\nexport function ecCodewordsPerBlock(version: number, level: QrErrorCorrection): number {\n return EC_CODEWORDS_PER_BLOCK[ecIndex(level)][version];\n}\n\nexport function numEcBlocks(version: number, level: QrErrorCorrection): number {\n return NUM_EC_BLOCKS[ecIndex(level)][version];\n}\n\n/** Data codewords for a (version, level) pair. */\nexport function dataCodewords(version: number, level: QrErrorCorrection): number {\n return totalCodewords(version) - ecCodewordsPerBlock(version, level) * numEcBlocks(version, level);\n}\n\n/** Version group for the character-count indicator: 0 → 1–9, 1 → 10–26, 2 → 27–40. */\nexport function versionGroup(version: number): 0 | 1 | 2 {\n return version <= 9 ? 0 : version <= 26 ? 1 : 2;\n}\n"],"mappings":";AAgBA,IAAa,IAAY;CAAC;CAAK;CAAK;CAAK;AAAG,GAE/B,IAAuB,iDAGvB,IAAoC;CAC/C,cAAc;CACd,MAAM;CACN,SAAS;AACX,GAGa,IAAqE;CAChF,cAAc;EAAC;EAAG;EAAI;CAAE;CACxB,MAAM;EAAC;EAAG;EAAI;CAAE;CAChB,SAAS;EAAC;EAAI;EAAI;CAAE;AACtB,GAGa,IAAoD;CAAE,GAAG;CAAM,GAAG;CAAM,GAAG;CAAM,GAAG;AAAK,GAGzF,IAA+D;CAE1E;EACE;EAAI;EAAG;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAC/G;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;CAC9C;CAEA;EACE;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAChH;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;CAC9C;CAEA;EACE;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAChH;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;EAAI;CAC9C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000000`,o=n.light??`#ffffff`,s=(e.size+r*2)*i,c=globalThis.devicePixelRatio||1;t.width=s*c,t.height=s*c,t.style.width=`${s}px`,t.style.height=`${s}px`;let l=t.getContext(`2d`);if(!l)throw Error(`Canvas 2D context unavailable`);l.scale(c,c),l.fillStyle=o,l.fillRect(0,0,s,s),l.fillStyle=a;for(let t=0;t<e.size;t++)for(let n=0;n<e.size;n++)e.get(n,t)&&l.fillRect((n+r)*i,(t+r)*i,i,i);return s}exports.drawToCanvas=e;
2
+ //# sourceMappingURL=canvas.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas.cjs","names":[],"sources":["../src/canvas.ts"],"sourcesContent":["import type { QrCanvasOptions, QrMatrix } from './types';\n\n/**\n * Canvas rendering — the only DOM-touching output path.\n * Resizes the canvas to `(size + 2*margin) * scale` CSS pixels, backing-store\n * scaled by `devicePixelRatio`, and paints one `fillRect` per dark module.\n * Returns the CSS pixel size so callers can size wrappers.\n */\nexport function drawToCanvas(matrix: QrMatrix, canvas: HTMLCanvasElement, options: QrCanvasOptions = {}): number {\n const margin = options.margin ?? 4;\n const scale = options.scale ?? 1;\n const dark = options.dark ?? '#000000';\n const light = options.light ?? '#ffffff';\n const cssSize = (matrix.size + margin * 2) * scale;\n const dpr = globalThis.devicePixelRatio || 1;\n\n canvas.width = cssSize * dpr;\n canvas.height = cssSize * dpr;\n canvas.style.width = `${cssSize}px`;\n canvas.style.height = `${cssSize}px`;\n\n const ctx = canvas.getContext('2d');\n if (!ctx) throw new Error('Canvas 2D context unavailable');\n ctx.scale(dpr, dpr);\n ctx.fillStyle = light;\n ctx.fillRect(0, 0, cssSize, cssSize);\n ctx.fillStyle = dark;\n for (let y = 0; y < matrix.size; y++)\n for (let x = 0; x < matrix.size; x++)\n if (matrix.get(x, y)) ctx.fillRect((x + margin) * scale, (y + margin) * scale, scale, scale);\n return cssSize;\n}\n"],"mappings":"AAQA,SAAgB,EAAa,EAAkB,EAA2B,EAA2B,CAAC,EAAW,CAC/G,IAAM,EAAS,EAAQ,QAAU,EAC3B,EAAQ,EAAQ,OAAS,EACzB,EAAO,EAAQ,MAAQ,UACvB,EAAQ,EAAQ,OAAS,UACzB,GAAW,EAAO,KAAO,EAAS,GAAK,EACvC,EAAM,WAAW,kBAAoB,EAE3C,EAAO,MAAQ,EAAU,EACzB,EAAO,OAAS,EAAU,EAC1B,EAAO,MAAM,MAAQ,GAAG,EAAQ,IAChC,EAAO,MAAM,OAAS,GAAG,EAAQ,IAEjC,IAAM,EAAM,EAAO,WAAW,IAAI,EAClC,GAAI,CAAC,EAAK,MAAU,MAAM,+BAA+B,EACzD,EAAI,MAAM,EAAK,CAAG,EAClB,EAAI,UAAY,EAChB,EAAI,SAAS,EAAG,EAAG,EAAS,CAAO,EACnC,EAAI,UAAY,EAChB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,KAAM,IAC/B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,KAAM,IAC3B,EAAO,IAAI,EAAG,CAAC,GAAG,EAAI,UAAU,EAAI,GAAU,GAAQ,EAAI,GAAU,EAAO,EAAO,CAAK,EAC/F,OAAO,CACT"}
@@ -0,0 +1,9 @@
1
+ import type { QrCanvasOptions, QrMatrix } from './types';
2
+ /**
3
+ * Canvas rendering — the only DOM-touching output path.
4
+ * Resizes the canvas to `(size + 2*margin) * scale` CSS pixels, backing-store
5
+ * scaled by `devicePixelRatio`, and paints one `fillRect` per dark module.
6
+ * Returns the CSS pixel size so callers can size wrappers.
7
+ */
8
+ export declare function drawToCanvas(matrix: QrMatrix, canvas: HTMLCanvasElement, options?: QrCanvasOptions): number;
9
+ //# sourceMappingURL=canvas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../src/canvas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,GAAE,eAAoB,GAAG,MAAM,CAuB/G"}
package/dist/canvas.js ADDED
@@ -0,0 +1,14 @@
1
+ //#region src/canvas.ts
2
+ function e(e, t, n = {}) {
3
+ let r = n.margin ?? 4, i = n.scale ?? 1, a = n.dark ?? "#000000", o = n.light ?? "#ffffff", s = (e.size + r * 2) * i, c = globalThis.devicePixelRatio || 1;
4
+ t.width = s * c, t.height = s * c, t.style.width = `${s}px`, t.style.height = `${s}px`;
5
+ let l = t.getContext("2d");
6
+ if (!l) throw Error("Canvas 2D context unavailable");
7
+ l.scale(c, c), l.fillStyle = o, l.fillRect(0, 0, s, s), l.fillStyle = a;
8
+ for (let t = 0; t < e.size; t++) for (let n = 0; n < e.size; n++) e.get(n, t) && l.fillRect((n + r) * i, (t + r) * i, i, i);
9
+ return s;
10
+ }
11
+ //#endregion
12
+ export { e as drawToCanvas };
13
+
14
+ //# sourceMappingURL=canvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas.js","names":[],"sources":["../src/canvas.ts"],"sourcesContent":["import type { QrCanvasOptions, QrMatrix } from './types';\n\n/**\n * Canvas rendering — the only DOM-touching output path.\n * Resizes the canvas to `(size + 2*margin) * scale` CSS pixels, backing-store\n * scaled by `devicePixelRatio`, and paints one `fillRect` per dark module.\n * Returns the CSS pixel size so callers can size wrappers.\n */\nexport function drawToCanvas(matrix: QrMatrix, canvas: HTMLCanvasElement, options: QrCanvasOptions = {}): number {\n const margin = options.margin ?? 4;\n const scale = options.scale ?? 1;\n const dark = options.dark ?? '#000000';\n const light = options.light ?? '#ffffff';\n const cssSize = (matrix.size + margin * 2) * scale;\n const dpr = globalThis.devicePixelRatio || 1;\n\n canvas.width = cssSize * dpr;\n canvas.height = cssSize * dpr;\n canvas.style.width = `${cssSize}px`;\n canvas.style.height = `${cssSize}px`;\n\n const ctx = canvas.getContext('2d');\n if (!ctx) throw new Error('Canvas 2D context unavailable');\n ctx.scale(dpr, dpr);\n ctx.fillStyle = light;\n ctx.fillRect(0, 0, cssSize, cssSize);\n ctx.fillStyle = dark;\n for (let y = 0; y < matrix.size; y++)\n for (let x = 0; x < matrix.size; x++)\n if (matrix.get(x, y)) ctx.fillRect((x + margin) * scale, (y + margin) * scale, scale, scale);\n return cssSize;\n}\n"],"mappings":";AAQA,SAAgB,EAAa,GAAkB,GAA2B,IAA2B,CAAC,GAAW;CAC/G,IAAM,IAAS,EAAQ,UAAU,GAC3B,IAAQ,EAAQ,SAAS,GACzB,IAAO,EAAQ,QAAQ,WACvB,IAAQ,EAAQ,SAAS,WACzB,KAAW,EAAO,OAAO,IAAS,KAAK,GACvC,IAAM,WAAW,oBAAoB;CAK3C,AAHA,EAAO,QAAQ,IAAU,GACzB,EAAO,SAAS,IAAU,GAC1B,EAAO,MAAM,QAAQ,GAAG,EAAQ,KAChC,EAAO,MAAM,SAAS,GAAG,EAAQ;CAEjC,IAAM,IAAM,EAAO,WAAW,IAAI;CAClC,IAAI,CAAC,GAAK,MAAU,MAAM,+BAA+B;CAIzD,AAHA,EAAI,MAAM,GAAK,CAAG,GAClB,EAAI,YAAY,GAChB,EAAI,SAAS,GAAG,GAAG,GAAS,CAAO,GACnC,EAAI,YAAY;CAChB,KAAK,IAAI,IAAI,GAAG,IAAI,EAAO,MAAM,KAC/B,KAAK,IAAI,IAAI,GAAG,IAAI,EAAO,MAAM,KAC/B,AAAI,EAAO,IAAI,GAAG,CAAC,KAAG,EAAI,UAAU,IAAI,KAAU,IAAQ,IAAI,KAAU,GAAO,GAAO,CAAK;CAC/F,OAAO;AACT"}
@@ -0,0 +1,2 @@
1
+ require("./_dev.cjs");const e=require("./_tables.cjs"),t=require("./_format.cjs"),n=require("./_mask.cjs"),r=require("./_matrix.cjs"),i=require("./_reed-solomon.cjs"),a=require("./_segments.cjs"),o=require("./errors.cjs");var s=40;function c(e){let{version:t,minVersion:n,mask:r,errorCorrection:i}=e,a=e=>Number.isInteger(e)&&e>=1&&e<=s;if(t!==void 0&&!a(t))throw new o.SigilOptionError(`version must be an integer 1–${s}, got ${t}`);if(n!==void 0&&!a(n))throw new o.SigilOptionError(`minVersion must be an integer 1–${s}, got ${n}`);if(t!==void 0&&n!==void 0&&n>t)throw new o.SigilOptionError(`minVersion (${n}) exceeds version (${t})`);if(r!==void 0&&(!Number.isInteger(r)||r<0||r>7))throw new o.SigilOptionError(`mask must be an integer 0–7, got ${r}`);if(i!==void 0&&!`LMQH`.includes(i))throw new o.SigilOptionError(`errorCorrection must be 'L', 'M', 'Q', or 'H'`)}function l(t,n,r){let i=e.CHAR_COUNT_BITS[r][e.versionGroup(t)],a=e.dataCodewords(t,n)*8-4-i;if(a<=0)return 0;switch(r){case`numeric`:return Math.floor(a/10)*3+(a%10>=7?2:+(a%10>=4));case`alphanumeric`:return Math.floor(a/11)*2+ +(a%11>=6);case`byte`:return Math.floor(a/8)}}function u(t,n,r,i){for(let o=i;o<=s;o++)if(a.segmentBits(t,n,o)<=e.dataCodewords(o,r)*8)return o;return-1}function d(t,n,r){let a=e.numEcBlocks(n,r),o=e.ecCodewordsPerBlock(n,r),s=e.totalCodewords(n),c=Math.floor(s/a)-o,l=s%a,u=[],d=0;for(let e=0;e<a;e++){let n=e>=a-l,r=t.slice(d,d+c+ +!!n);d+=r.length;let s=i.ecCodewords(r,o);u.push(n?[...r,...s]:[...r,0,...s])}let f=[];for(let e=0;e<u[0].length;e++)for(let t=0;t<a;t++)(e!==c||t>=a-l)&&f.push(u[t][e]);return f}function f(e,t){let n=e.map(e=>Object.freeze([...e]));return Object.freeze(n),Object.freeze({...t,get:(e,r)=>e>=0&&r>=0&&e<t.size&&r<t.size&&n[r][e],modules:n})}function p(i,p={}){c(p);let g=typeof i==`string`?i:new TextDecoder().decode(i);if(g.length===0)throw new o.SigilOptionError(`Cannot encode an empty input`);let _=p.errorCorrection??`M`,v=p.mode??a.detectMode(g);if(v!==`byte`&&a.detectMode(g)!==v&&!m(g,v))throw new o.SigilOptionError(`Input cannot be encoded in ${v} mode`);let y=p.version??u(g,v,_,p.minVersion??1);if(y===-1||a.segmentBits(g,v,y)>e.dataCodewords(y,_)*8){let e=new TextEncoder().encode(g).length,t=l(p.version??s,_,v);throw new o.SigilCapacityError(`Input of ${e} bytes exceeds QR capacity (${t} ${v===`byte`?`bytes`:`chars`} at version ${p.version??s}-${_})`,e,t,p.version??s)}let b=a.segmentBits(g,v,y),x=e.dataCodewords(y,_)*8;b/x>.9&&p.version===void 0&&`${Math.round(b/x*100)}${y}${_}`;let S=d(a.buildDataCodewords(g,v,y,_),y,_),C=r.createGrid(e.matrixSize(y));r.drawFunctionPatterns(C,y),r.placeData(C,S);let w=p.mask===void 0?[0,1,2,3,4,5,6,7]:[p.mask],T=w[0],E=1/0,D=null;for(let e of w){n.applyMask(C,e),t.drawFormatInfo(C,_,e);let r=n.penaltyScore(C);r<E&&(E=r,T=e,D=C.modules.map(e=>[...e])),n.applyMask(C,e),e!==w[w.length-1]&&h(C)}return C.modules=D,t.drawVersionInfo(C,y),f(C.modules,{errorCorrection:_,mask:T,mode:v,size:C.size,version:y})}function m(t,n){return n===`numeric`?/^\d+$/.test(t):n!==`alphanumeric`||[...t].every(t=>e.ALPHANUMERIC_CHARSET.includes(t))}function h(e){let t=e.size,n=[];for(let e=0;e<=8;e++)e!==6&&n.push([8,e],[e,8]);for(let e=0;e<8;e++)n.push([t-1-e,8]);for(let e=0;e<7;e++)n.push([8,t-1-e]);n.push([8,t-8]);for(let[t,r]of n)e.modules[r][t]=!1}function g(e,t,n){if(!Number.isInteger(e)||e<1||e>s)throw new o.SigilOptionError(`version must be an integer 1–${s}, got ${e}`);return l(e,t,n)}exports.encodeQr=p,exports.qrCapacity=g;
2
+ //# sourceMappingURL=encode.cjs.map