@vielzeug/sigil 3.1.0 → 26.10.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.
- package/README.md +5 -5
- package/dist/_format.cjs +1 -1
- package/dist/_format.cjs.map +1 -1
- package/dist/_format.js +1 -36
- package/dist/_format.js.map +1 -1
- package/dist/_galois.cjs +1 -1
- package/dist/_galois.cjs.map +1 -1
- package/dist/_galois.d.ts +1 -1
- package/dist/_galois.d.ts.map +1 -1
- package/dist/_galois.js +1 -21
- package/dist/_galois.js.map +1 -1
- package/dist/_mask.cjs +1 -1
- package/dist/_mask.cjs.map +1 -1
- package/dist/_mask.js +1 -80
- package/dist/_mask.js.map +1 -1
- package/dist/_matrix.cjs +1 -1
- package/dist/_matrix.cjs.map +1 -1
- package/dist/_matrix.d.ts +1 -1
- package/dist/_matrix.d.ts.map +1 -1
- package/dist/_matrix.js +1 -64
- package/dist/_matrix.js.map +1 -1
- package/dist/_reed-solomon.cjs +1 -1
- package/dist/_reed-solomon.cjs.map +1 -1
- package/dist/_reed-solomon.js +1 -21
- package/dist/_reed-solomon.js.map +1 -1
- package/dist/_segments.cjs +1 -1
- package/dist/_segments.cjs.map +1 -1
- package/dist/_segments.d.ts +22 -11
- package/dist/_segments.d.ts.map +1 -1
- package/dist/_segments.js +1 -69
- package/dist/_segments.js.map +1 -1
- package/dist/_tables.cjs +1 -1
- package/dist/_tables.cjs.map +1 -1
- package/dist/_tables.d.ts +4 -4
- package/dist/_tables.js +1 -408
- package/dist/_tables.js.map +1 -1
- package/dist/canvas.cjs +1 -1
- package/dist/canvas.cjs.map +1 -1
- package/dist/canvas.d.ts +1 -1
- package/dist/canvas.d.ts.map +1 -1
- package/dist/canvas.js +1 -13
- package/dist/canvas.js.map +1 -1
- package/dist/encode.cjs +1 -1
- package/dist/encode.cjs.map +1 -1
- package/dist/encode.d.ts +3 -1
- package/dist/encode.d.ts.map +1 -1
- package/dist/encode.js +1 -111
- package/dist/encode.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +1 -16
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -6
- package/dist/scan.cjs +1 -1
- package/dist/scan.cjs.map +1 -1
- package/dist/scan.d.ts.map +1 -1
- package/dist/scan.js +1 -140
- package/dist/scan.js.map +1 -1
- package/dist/sigil.cjs +1 -1
- package/dist/sigil.cjs.map +1 -1
- package/dist/sigil.iife.js +1 -1
- package/dist/sigil.iife.js.map +1 -1
- package/dist/sigil.js +1 -1
- package/dist/sigil.js.map +1 -1
- package/dist/svg.cjs +1 -1
- package/dist/svg.cjs.map +1 -1
- package/dist/svg.js +1 -25
- package/dist/svg.js.map +1 -1
- package/dist/types.d.ts +5 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/_dev.cjs +0 -2
- package/dist/_dev.cjs.map +0 -1
- package/dist/_dev.d.ts +0 -2
- package/dist/_dev.d.ts.map +0 -1
- package/dist/_dev.js +0 -6
- package/dist/_dev.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vielzeug/sigil
|
|
2
2
|
|
|
3
|
-
> QR code generation and scanning
|
|
3
|
+
> QR code generation and scanning: pure matrix encoder, SVG and canvas renderers, native BarcodeDetector scanning
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -15,18 +15,18 @@ yarn add @vielzeug/sigil
|
|
|
15
15
|
```ts
|
|
16
16
|
import { createQrScanner, encodeQr, toSvg } from '@vielzeug/sigil';
|
|
17
17
|
|
|
18
|
-
// Encode to an inline SVG string
|
|
18
|
+
// Encode to an inline SVG string: works in Node and the browser.
|
|
19
19
|
const matrix = encodeQr('https://vielzeug.dev');
|
|
20
20
|
document.querySelector('#qr').innerHTML = toSvg(matrix, { label: 'Vielzeug link' });
|
|
21
21
|
|
|
22
|
-
// Scan with the camera (browser only
|
|
22
|
+
// Scan with the camera (browser only: feature-detect first).
|
|
23
23
|
const scanner = createQrScanner({ video: document.querySelector('video') });
|
|
24
24
|
scanner.onResult(({ value }) => console.log('scanned:', value));
|
|
25
25
|
await scanner.start();
|
|
26
26
|
scanner.dispose();
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
`toSvg` output uses `currentColor` modules by default
|
|
29
|
+
`toSvg` output uses `currentColor` modules by default: the code themes with ordinary CSS. Scanning requires `BarcodeDetector` and a secure context; call `qrScanSupport()` before showing a scan affordance.
|
|
30
30
|
|
|
31
31
|
## Documentation
|
|
32
32
|
|
|
@@ -37,4 +37,4 @@ scanner.dispose();
|
|
|
37
37
|
|
|
38
38
|
## License
|
|
39
39
|
|
|
40
|
-
MIT © [Helmuth Saatkamp](https://github.com/helmuthdu)
|
|
40
|
+
MIT © [Helmuth Saatkamp](https://github.com/helmuthdu): part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
|
package/dist/_format.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./_tables.cjs");var t=1335,n=21522,r=7973;function
|
|
1
|
+
const e=require("./_tables.cjs");var t=1335,n=21522,r=7973;function formatInfoBits(r,i){let a=e.FORMAT_EC_BITS[r]<<3|i,o=a;for(let e=0;e<10;e++)o=o<<1^(o>>>9&1)*t;return(a<<10|o&1023)^n}function versionInfoBits(e){let t=e;for(let e=0;e<12;e++)t=t<<1^(t>>>11&1)*r;return e<<12|t&4095}var setFunction=(e,t,n,r)=>{e.modules[n][t]=r,e.isFunction[n][t]=!0};function drawFormatInfo(e,t,n){let r=e.size,i=formatInfoBits(t,n),bit=e=>(i>>>e&1)==1;for(let t=0;t<=5;t++)setFunction(e,8,t,bit(t));setFunction(e,8,7,bit(6)),setFunction(e,8,8,bit(7)),setFunction(e,7,8,bit(8));for(let t=9;t<15;t++)setFunction(e,14-t,8,bit(t));for(let t=0;t<8;t++)setFunction(e,r-1-t,8,bit(t));for(let t=8;t<15;t++)setFunction(e,8,r-15+t,bit(t));setFunction(e,8,r-8,!0)}function drawVersionInfo(e,t){if(t<7)return;let n=e.size,r=versionInfoBits(t);for(let t=0;t<18;t++){let i=(r>>>t&1)==1,a=n-11+t%3,o=Math.floor(t/3);setFunction(e,a,o,i),setFunction(e,o,a,i)}}exports.drawFormatInfo=drawFormatInfo,exports.drawVersionInfo=drawVersionInfo,exports.formatInfoBits=formatInfoBits,exports.versionInfoBits=versionInfoBits;
|
|
2
2
|
//# sourceMappingURL=_format.cjs.map
|
package/dist/_format.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_format.cjs","names":[],"sources":["../src/_format.ts"],"sourcesContent":["import type { QrGrid } from './_matrix';\nimport { FORMAT_EC_BITS } from './_tables';\nimport type { QrErrorCorrection } from './types';\n\n/**\n * Format and version information (§7.9, Annexes C–D):\n * - Format: 5 data bits (2 EC + 3 mask) → BCH(15,5) remainder → XOR 0x5412,\n * written twice around the finders.\n * - Version (v≥7): 6 data bits → BCH(18,6) remainder, written twice in the\n * 6×3 blocks at top-right and bottom-left.\n */\n\nconst BCH_FORMAT_POLY = 0b10100110111; // x¹⁰+x⁸+x⁵+x⁴+x²+x+1\nconst BCH_FORMAT_MASK = 0b101010000010010; // 0x5412\nconst BCH_VERSION_POLY = 0b1111100100101; // x¹²+x¹¹+x¹⁰+x⁹+x⁸+x⁵+x²+1\n\n/** 15-bit format information word for (level, mask). */\nexport function formatInfoBits(level: QrErrorCorrection, mask: number): number {\n const data = (FORMAT_EC_BITS[level] << 3) | mask;\n let rem = data;\n for (let i = 0; i < 10; i++) rem = (rem << 1) ^ (((rem >>> 9) & 1) * BCH_FORMAT_POLY);\n return ((data << 10) | (rem & 0x3ff)) ^ BCH_FORMAT_MASK;\n}\n\n/** 18-bit version information word (version ≥ 7). */\nexport function versionInfoBits(version: number): number {\n let rem = version;\n for (let i = 0; i < 12; i++) rem = (rem << 1) ^ (((rem >>> 11) & 1) * BCH_VERSION_POLY);\n return (version << 12) | (rem & 0xfff);\n}\n\nconst setFunction = (grid: QrGrid, x: number, y: number, dark: boolean): void => {\n grid.modules[y][x] = dark;\n grid.isFunction[y][x] = true;\n};\n\n/** Write both copies of the 15-bit format word plus the dark module. */\nexport function drawFormatInfo(grid: QrGrid, level: QrErrorCorrection, mask: number): void {\n const size = grid.size;\n const bits = formatInfoBits(level, mask);\n const bit = (i: number) => ((bits >>> i) & 1) === 1;\n\n // First copy around the top-left finder.\n for (let i = 0; i <= 5; i++) setFunction(grid, 8, i, bit(i));\n setFunction(grid, 8, 7, bit(6));\n setFunction(grid, 8, 8, bit(7));\n setFunction(grid, 7, 8, bit(8));\n for (let i = 9; i < 15; i++) setFunction(grid, 14 - i, 8, bit(i));\n\n // Second copy: row 8 beside the top-right finder (bits 0–7),\n // column 8 beside the bottom-left finder (bits 8–14).\n for (let i = 0; i < 8; i++) setFunction(grid, size - 1 - i, 8, bit(i));\n for (let i = 8; i < 15; i++) setFunction(grid, 8, size - 15 + i, bit(i));\n\n // Always-dark module below the bottom-left strip.\n setFunction(grid, 8, size - 8, true);\n}\n\n/** Write both 6×3 version-information blocks (v≥7). */\nexport function drawVersionInfo(grid: QrGrid, version: number): void {\n if (version < 7) return;\n const size = grid.size;\n const bits = versionInfoBits(version);\n for (let i = 0; i < 18; i++) {\n const dark = ((bits >>> i) & 1) === 1;\n const a = size - 11 + (i % 3);\n const b = Math.floor(i / 3);\n setFunction(grid, a, b, dark); // top-right\n setFunction(grid, b, a, dark); // bottom-left\n }\n}\n"],"mappings":"iCAYA,IAAM,EAAkB,KAClB,EAAkB,MAClB,EAAmB,KAGzB,SAAgB,
|
|
1
|
+
{"version":3,"file":"_format.cjs","names":[],"sources":["../src/_format.ts"],"sourcesContent":["import type { QrGrid } from './_matrix';\nimport { FORMAT_EC_BITS } from './_tables';\nimport type { QrErrorCorrection } from './types';\n\n/**\n * Format and version information (§7.9, Annexes C–D):\n * - Format: 5 data bits (2 EC + 3 mask) → BCH(15,5) remainder → XOR 0x5412,\n * written twice around the finders.\n * - Version (v≥7): 6 data bits → BCH(18,6) remainder, written twice in the\n * 6×3 blocks at top-right and bottom-left.\n */\n\nconst BCH_FORMAT_POLY = 0b10100110111; // x¹⁰+x⁸+x⁵+x⁴+x²+x+1\nconst BCH_FORMAT_MASK = 0b101010000010010; // 0x5412\nconst BCH_VERSION_POLY = 0b1111100100101; // x¹²+x¹¹+x¹⁰+x⁹+x⁸+x⁵+x²+1\n\n/** 15-bit format information word for (level, mask). */\nexport function formatInfoBits(level: QrErrorCorrection, mask: number): number {\n const data = (FORMAT_EC_BITS[level] << 3) | mask;\n let rem = data;\n for (let i = 0; i < 10; i++) rem = (rem << 1) ^ (((rem >>> 9) & 1) * BCH_FORMAT_POLY);\n return ((data << 10) | (rem & 0x3ff)) ^ BCH_FORMAT_MASK;\n}\n\n/** 18-bit version information word (version ≥ 7). */\nexport function versionInfoBits(version: number): number {\n let rem = version;\n for (let i = 0; i < 12; i++) rem = (rem << 1) ^ (((rem >>> 11) & 1) * BCH_VERSION_POLY);\n return (version << 12) | (rem & 0xfff);\n}\n\nconst setFunction = (grid: QrGrid, x: number, y: number, dark: boolean): void => {\n grid.modules[y][x] = dark;\n grid.isFunction[y][x] = true;\n};\n\n/** Write both copies of the 15-bit format word plus the dark module. */\nexport function drawFormatInfo(grid: QrGrid, level: QrErrorCorrection, mask: number): void {\n const size = grid.size;\n const bits = formatInfoBits(level, mask);\n const bit = (i: number) => ((bits >>> i) & 1) === 1;\n\n // First copy around the top-left finder.\n for (let i = 0; i <= 5; i++) setFunction(grid, 8, i, bit(i));\n setFunction(grid, 8, 7, bit(6));\n setFunction(grid, 8, 8, bit(7));\n setFunction(grid, 7, 8, bit(8));\n for (let i = 9; i < 15; i++) setFunction(grid, 14 - i, 8, bit(i));\n\n // Second copy: row 8 beside the top-right finder (bits 0–7),\n // column 8 beside the bottom-left finder (bits 8–14).\n for (let i = 0; i < 8; i++) setFunction(grid, size - 1 - i, 8, bit(i));\n for (let i = 8; i < 15; i++) setFunction(grid, 8, size - 15 + i, bit(i));\n\n // Always-dark module below the bottom-left strip.\n setFunction(grid, 8, size - 8, true);\n}\n\n/** Write both 6×3 version-information blocks (v≥7). */\nexport function drawVersionInfo(grid: QrGrid, version: number): void {\n if (version < 7) return;\n const size = grid.size;\n const bits = versionInfoBits(version);\n for (let i = 0; i < 18; i++) {\n const dark = ((bits >>> i) & 1) === 1;\n const a = size - 11 + (i % 3);\n const b = Math.floor(i / 3);\n setFunction(grid, a, b, dark); // top-right\n setFunction(grid, b, a, dark); // bottom-left\n }\n}\n"],"mappings":"iCAYA,IAAM,EAAkB,KAClB,EAAkB,MAClB,EAAmB,KAGzB,SAAgB,eAAe,EAA0B,EAAsB,CAC7E,IAAM,EAAQ,EAAA,eAAe,IAAU,EAAK,EACxC,EAAM,EACV,IAAK,IAAI,EAAI,EAAG,EAAI,GAAI,IAAK,EAAO,GAAO,GAAQ,IAAQ,EAAK,GAAK,EACrE,OAAS,GAAQ,GAAO,EAAM,MAAU,CAC1C,CAGA,SAAgB,gBAAgB,EAAyB,CACvD,IAAI,EAAM,EACV,IAAK,IAAI,EAAI,EAAG,EAAI,GAAI,IAAK,EAAO,GAAO,GAAQ,IAAQ,GAAM,GAAK,EACtE,OAAQ,GAAW,GAAO,EAAM,IAClC,CAEA,IAAM,aAAe,EAAc,EAAW,EAAW,IAAwB,CAC/E,EAAK,QAAQ,EAAE,CAAC,GAAK,EACrB,EAAK,WAAW,EAAE,CAAC,GAAK,EAC1B,EAGA,SAAgB,eAAe,EAAc,EAA0B,EAAoB,CACzF,IAAM,EAAO,EAAK,KACZ,EAAO,eAAe,EAAO,CAAI,EACjC,IAAO,IAAgB,IAAS,EAAK,IAAO,EAGlD,IAAK,IAAI,EAAI,EAAG,GAAK,EAAG,IAAK,YAAY,EAAM,EAAG,EAAG,IAAI,CAAC,CAAC,EAC3D,YAAY,EAAM,EAAG,EAAG,IAAI,CAAC,CAAC,EAC9B,YAAY,EAAM,EAAG,EAAG,IAAI,CAAC,CAAC,EAC9B,YAAY,EAAM,EAAG,EAAG,IAAI,CAAC,CAAC,EAC9B,IAAK,IAAI,EAAI,EAAG,EAAI,GAAI,IAAK,YAAY,EAAM,GAAK,EAAG,EAAG,IAAI,CAAC,CAAC,EAIhE,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,YAAY,EAAM,EAAO,EAAI,EAAG,EAAG,IAAI,CAAC,CAAC,EACrE,IAAK,IAAI,EAAI,EAAG,EAAI,GAAI,IAAK,YAAY,EAAM,EAAG,EAAO,GAAK,EAAG,IAAI,CAAC,CAAC,EAGvE,YAAY,EAAM,EAAG,EAAO,EAAG,EAAI,CACrC,CAGA,SAAgB,gBAAgB,EAAc,EAAuB,CACnE,GAAI,EAAU,EAAG,OACjB,IAAM,EAAO,EAAK,KACZ,EAAO,gBAAgB,CAAO,EACpC,IAAK,IAAI,EAAI,EAAG,EAAI,GAAI,IAAK,CAC3B,IAAM,GAAS,IAAS,EAAK,IAAO,EAC9B,EAAI,EAAO,GAAM,EAAI,EACrB,EAAI,KAAK,MAAM,EAAI,CAAC,EAC1B,YAAY,EAAM,EAAG,EAAG,CAAI,EAC5B,YAAY,EAAM,EAAG,EAAG,CAAI,CAC9B,CACF"}
|
package/dist/_format.js
CHANGED
|
@@ -1,37 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
//#region src/_format.ts
|
|
3
|
-
var t = 1335, n = 21522, r = 7973;
|
|
4
|
-
function i(r, i) {
|
|
5
|
-
let a = e[r] << 3 | i, o = a;
|
|
6
|
-
for (let e = 0; e < 10; e++) o = o << 1 ^ (o >>> 9 & 1) * t;
|
|
7
|
-
return (a << 10 | o & 1023) ^ n;
|
|
8
|
-
}
|
|
9
|
-
function a(e) {
|
|
10
|
-
let t = e;
|
|
11
|
-
for (let e = 0; e < 12; e++) t = t << 1 ^ (t >>> 11 & 1) * r;
|
|
12
|
-
return e << 12 | t & 4095;
|
|
13
|
-
}
|
|
14
|
-
var o = (e, t, n, r) => {
|
|
15
|
-
e.modules[n][t] = r, e.isFunction[n][t] = !0;
|
|
16
|
-
};
|
|
17
|
-
function s(e, t, n) {
|
|
18
|
-
let r = e.size, a = i(t, n), s = (e) => (a >>> e & 1) == 1;
|
|
19
|
-
for (let t = 0; t <= 5; t++) o(e, 8, t, s(t));
|
|
20
|
-
o(e, 8, 7, s(6)), o(e, 8, 8, s(7)), o(e, 7, 8, s(8));
|
|
21
|
-
for (let t = 9; t < 15; t++) o(e, 14 - t, 8, s(t));
|
|
22
|
-
for (let t = 0; t < 8; t++) o(e, r - 1 - t, 8, s(t));
|
|
23
|
-
for (let t = 8; t < 15; t++) o(e, 8, r - 15 + t, s(t));
|
|
24
|
-
o(e, 8, r - 8, !0);
|
|
25
|
-
}
|
|
26
|
-
function c(e, t) {
|
|
27
|
-
if (t < 7) return;
|
|
28
|
-
let n = e.size, r = a(t);
|
|
29
|
-
for (let t = 0; t < 18; t++) {
|
|
30
|
-
let i = (r >>> t & 1) == 1, a = n - 11 + t % 3, s = Math.floor(t / 3);
|
|
31
|
-
o(e, a, s, i), o(e, s, a, i);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
export { s as drawFormatInfo, c as drawVersionInfo, i as formatInfoBits, a as versionInfoBits };
|
|
36
|
-
|
|
1
|
+
import{FORMAT_EC_BITS as e}from"./_tables.js";var t=1335,n=21522,r=7973;function formatInfoBits(r,i){let a=e[r]<<3|i,o=a;for(let e=0;e<10;e++)o=o<<1^(o>>>9&1)*t;return(a<<10|o&1023)^n}function versionInfoBits(e){let t=e;for(let e=0;e<12;e++)t=t<<1^(t>>>11&1)*r;return e<<12|t&4095}var setFunction=(e,t,n,r)=>{e.modules[n][t]=r,e.isFunction[n][t]=!0};function drawFormatInfo(e,t,n){let r=e.size,i=formatInfoBits(t,n),bit=e=>(i>>>e&1)==1;for(let t=0;t<=5;t++)setFunction(e,8,t,bit(t));setFunction(e,8,7,bit(6)),setFunction(e,8,8,bit(7)),setFunction(e,7,8,bit(8));for(let t=9;t<15;t++)setFunction(e,14-t,8,bit(t));for(let t=0;t<8;t++)setFunction(e,r-1-t,8,bit(t));for(let t=8;t<15;t++)setFunction(e,8,r-15+t,bit(t));setFunction(e,8,r-8,!0)}function drawVersionInfo(e,t){if(t<7)return;let n=e.size,r=versionInfoBits(t);for(let t=0;t<18;t++){let i=(r>>>t&1)==1,a=n-11+t%3,o=Math.floor(t/3);setFunction(e,a,o,i),setFunction(e,o,a,i)}}export{drawFormatInfo,drawVersionInfo,formatInfoBits,versionInfoBits};
|
|
37
2
|
//# sourceMappingURL=_format.js.map
|
package/dist/_format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_format.js","names":[],"sources":["../src/_format.ts"],"sourcesContent":["import type { QrGrid } from './_matrix';\nimport { FORMAT_EC_BITS } from './_tables';\nimport type { QrErrorCorrection } from './types';\n\n/**\n * Format and version information (§7.9, Annexes C–D):\n * - Format: 5 data bits (2 EC + 3 mask) → BCH(15,5) remainder → XOR 0x5412,\n * written twice around the finders.\n * - Version (v≥7): 6 data bits → BCH(18,6) remainder, written twice in the\n * 6×3 blocks at top-right and bottom-left.\n */\n\nconst BCH_FORMAT_POLY = 0b10100110111; // x¹⁰+x⁸+x⁵+x⁴+x²+x+1\nconst BCH_FORMAT_MASK = 0b101010000010010; // 0x5412\nconst BCH_VERSION_POLY = 0b1111100100101; // x¹²+x¹¹+x¹⁰+x⁹+x⁸+x⁵+x²+1\n\n/** 15-bit format information word for (level, mask). */\nexport function formatInfoBits(level: QrErrorCorrection, mask: number): number {\n const data = (FORMAT_EC_BITS[level] << 3) | mask;\n let rem = data;\n for (let i = 0; i < 10; i++) rem = (rem << 1) ^ (((rem >>> 9) & 1) * BCH_FORMAT_POLY);\n return ((data << 10) | (rem & 0x3ff)) ^ BCH_FORMAT_MASK;\n}\n\n/** 18-bit version information word (version ≥ 7). */\nexport function versionInfoBits(version: number): number {\n let rem = version;\n for (let i = 0; i < 12; i++) rem = (rem << 1) ^ (((rem >>> 11) & 1) * BCH_VERSION_POLY);\n return (version << 12) | (rem & 0xfff);\n}\n\nconst setFunction = (grid: QrGrid, x: number, y: number, dark: boolean): void => {\n grid.modules[y][x] = dark;\n grid.isFunction[y][x] = true;\n};\n\n/** Write both copies of the 15-bit format word plus the dark module. */\nexport function drawFormatInfo(grid: QrGrid, level: QrErrorCorrection, mask: number): void {\n const size = grid.size;\n const bits = formatInfoBits(level, mask);\n const bit = (i: number) => ((bits >>> i) & 1) === 1;\n\n // First copy around the top-left finder.\n for (let i = 0; i <= 5; i++) setFunction(grid, 8, i, bit(i));\n setFunction(grid, 8, 7, bit(6));\n setFunction(grid, 8, 8, bit(7));\n setFunction(grid, 7, 8, bit(8));\n for (let i = 9; i < 15; i++) setFunction(grid, 14 - i, 8, bit(i));\n\n // Second copy: row 8 beside the top-right finder (bits 0–7),\n // column 8 beside the bottom-left finder (bits 8–14).\n for (let i = 0; i < 8; i++) setFunction(grid, size - 1 - i, 8, bit(i));\n for (let i = 8; i < 15; i++) setFunction(grid, 8, size - 15 + i, bit(i));\n\n // Always-dark module below the bottom-left strip.\n setFunction(grid, 8, size - 8, true);\n}\n\n/** Write both 6×3 version-information blocks (v≥7). */\nexport function drawVersionInfo(grid: QrGrid, version: number): void {\n if (version < 7) return;\n const size = grid.size;\n const bits = versionInfoBits(version);\n for (let i = 0; i < 18; i++) {\n const dark = ((bits >>> i) & 1) === 1;\n const a = size - 11 + (i % 3);\n const b = Math.floor(i / 3);\n setFunction(grid, a, b, dark); // top-right\n setFunction(grid, b, a, dark); // bottom-left\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"_format.js","names":[],"sources":["../src/_format.ts"],"sourcesContent":["import type { QrGrid } from './_matrix';\nimport { FORMAT_EC_BITS } from './_tables';\nimport type { QrErrorCorrection } from './types';\n\n/**\n * Format and version information (§7.9, Annexes C–D):\n * - Format: 5 data bits (2 EC + 3 mask) → BCH(15,5) remainder → XOR 0x5412,\n * written twice around the finders.\n * - Version (v≥7): 6 data bits → BCH(18,6) remainder, written twice in the\n * 6×3 blocks at top-right and bottom-left.\n */\n\nconst BCH_FORMAT_POLY = 0b10100110111; // x¹⁰+x⁸+x⁵+x⁴+x²+x+1\nconst BCH_FORMAT_MASK = 0b101010000010010; // 0x5412\nconst BCH_VERSION_POLY = 0b1111100100101; // x¹²+x¹¹+x¹⁰+x⁹+x⁸+x⁵+x²+1\n\n/** 15-bit format information word for (level, mask). */\nexport function formatInfoBits(level: QrErrorCorrection, mask: number): number {\n const data = (FORMAT_EC_BITS[level] << 3) | mask;\n let rem = data;\n for (let i = 0; i < 10; i++) rem = (rem << 1) ^ (((rem >>> 9) & 1) * BCH_FORMAT_POLY);\n return ((data << 10) | (rem & 0x3ff)) ^ BCH_FORMAT_MASK;\n}\n\n/** 18-bit version information word (version ≥ 7). */\nexport function versionInfoBits(version: number): number {\n let rem = version;\n for (let i = 0; i < 12; i++) rem = (rem << 1) ^ (((rem >>> 11) & 1) * BCH_VERSION_POLY);\n return (version << 12) | (rem & 0xfff);\n}\n\nconst setFunction = (grid: QrGrid, x: number, y: number, dark: boolean): void => {\n grid.modules[y][x] = dark;\n grid.isFunction[y][x] = true;\n};\n\n/** Write both copies of the 15-bit format word plus the dark module. */\nexport function drawFormatInfo(grid: QrGrid, level: QrErrorCorrection, mask: number): void {\n const size = grid.size;\n const bits = formatInfoBits(level, mask);\n const bit = (i: number) => ((bits >>> i) & 1) === 1;\n\n // First copy around the top-left finder.\n for (let i = 0; i <= 5; i++) setFunction(grid, 8, i, bit(i));\n setFunction(grid, 8, 7, bit(6));\n setFunction(grid, 8, 8, bit(7));\n setFunction(grid, 7, 8, bit(8));\n for (let i = 9; i < 15; i++) setFunction(grid, 14 - i, 8, bit(i));\n\n // Second copy: row 8 beside the top-right finder (bits 0–7),\n // column 8 beside the bottom-left finder (bits 8–14).\n for (let i = 0; i < 8; i++) setFunction(grid, size - 1 - i, 8, bit(i));\n for (let i = 8; i < 15; i++) setFunction(grid, 8, size - 15 + i, bit(i));\n\n // Always-dark module below the bottom-left strip.\n setFunction(grid, 8, size - 8, true);\n}\n\n/** Write both 6×3 version-information blocks (v≥7). */\nexport function drawVersionInfo(grid: QrGrid, version: number): void {\n if (version < 7) return;\n const size = grid.size;\n const bits = versionInfoBits(version);\n for (let i = 0; i < 18; i++) {\n const dark = ((bits >>> i) & 1) === 1;\n const a = size - 11 + (i % 3);\n const b = Math.floor(i / 3);\n setFunction(grid, a, b, dark); // top-right\n setFunction(grid, b, a, dark); // bottom-left\n }\n}\n"],"mappings":"8CAYA,IAAM,EAAkB,KAClB,EAAkB,MAClB,EAAmB,KAGzB,SAAgB,eAAe,EAA0B,EAAsB,CAC7E,IAAM,EAAQ,EAAe,IAAU,EAAK,EACxC,EAAM,EACV,IAAK,IAAI,EAAI,EAAG,EAAI,GAAI,IAAK,EAAO,GAAO,GAAQ,IAAQ,EAAK,GAAK,EACrE,OAAS,GAAQ,GAAO,EAAM,MAAU,CAC1C,CAGA,SAAgB,gBAAgB,EAAyB,CACvD,IAAI,EAAM,EACV,IAAK,IAAI,EAAI,EAAG,EAAI,GAAI,IAAK,EAAO,GAAO,GAAQ,IAAQ,GAAM,GAAK,EACtE,OAAQ,GAAW,GAAO,EAAM,IAClC,CAEA,IAAM,aAAe,EAAc,EAAW,EAAW,IAAwB,CAC/E,EAAK,QAAQ,EAAE,CAAC,GAAK,EACrB,EAAK,WAAW,EAAE,CAAC,GAAK,EAC1B,EAGA,SAAgB,eAAe,EAAc,EAA0B,EAAoB,CACzF,IAAM,EAAO,EAAK,KACZ,EAAO,eAAe,EAAO,CAAI,EACjC,IAAO,IAAgB,IAAS,EAAK,IAAO,EAGlD,IAAK,IAAI,EAAI,EAAG,GAAK,EAAG,IAAK,YAAY,EAAM,EAAG,EAAG,IAAI,CAAC,CAAC,EAC3D,YAAY,EAAM,EAAG,EAAG,IAAI,CAAC,CAAC,EAC9B,YAAY,EAAM,EAAG,EAAG,IAAI,CAAC,CAAC,EAC9B,YAAY,EAAM,EAAG,EAAG,IAAI,CAAC,CAAC,EAC9B,IAAK,IAAI,EAAI,EAAG,EAAI,GAAI,IAAK,YAAY,EAAM,GAAK,EAAG,EAAG,IAAI,CAAC,CAAC,EAIhE,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,YAAY,EAAM,EAAO,EAAI,EAAG,EAAG,IAAI,CAAC,CAAC,EACrE,IAAK,IAAI,EAAI,EAAG,EAAI,GAAI,IAAK,YAAY,EAAM,EAAG,EAAO,GAAK,EAAG,IAAI,CAAC,CAAC,EAGvE,YAAY,EAAM,EAAG,EAAO,EAAG,EAAI,CACrC,CAGA,SAAgB,gBAAgB,EAAc,EAAuB,CACnE,GAAI,EAAU,EAAG,OACjB,IAAM,EAAO,EAAK,KACZ,EAAO,gBAAgB,CAAO,EACpC,IAAK,IAAI,EAAI,EAAG,EAAI,GAAI,IAAK,CAC3B,IAAM,GAAS,IAAS,EAAK,IAAO,EAC9B,EAAI,EAAO,GAAM,EAAI,EACrB,EAAI,KAAK,MAAM,EAAI,CAAC,EAC1B,YAAY,EAAM,EAAG,EAAG,CAAI,EAC5B,YAAY,EAAM,EAAG,EAAG,CAAI,CAC9B,CACF"}
|
package/dist/_galois.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=285,t=new Uint8Array(512),n=new Uint8Array(256);{let r=1;for(let i=0;i<255;i++)t[i]=r,n[r]=i,r<<=1,r&256&&(r^=e);for(let e=255;e<512;e++)t[e]=t[e-255]}function
|
|
1
|
+
var e=285,t=new Uint8Array(512),n=new Uint8Array(256);{let r=1;for(let i=0;i<255;i++)t[i]=r,n[r]=i,r<<=1,r&256&&(r^=e);for(let e=255;e<512;e++)t[e]=t[e-255]}function gfMultiply(e,r){return e===0||r===0?0:t[n[e]+n[r]]}function gfExp(e){return t[e%255]}function gfPolyMultiply(e,t){let n=Array(e.length+t.length-1).fill(0);for(let r=0;r<e.length;r++)for(let i=0;i<t.length;i++)n[r+i]^=gfMultiply(e[r],t[i]);return n}exports.gfExp=gfExp,exports.gfMultiply=gfMultiply,exports.gfPolyMultiply=gfPolyMultiply;
|
|
2
2
|
//# sourceMappingURL=_galois.cjs.map
|
package/dist/_galois.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_galois.cjs","names":[],"sources":["../src/_galois.ts"],"sourcesContent":["/**\n * GF(2⁸) arithmetic over the QR primitive polynomial x⁸+x⁴+x³+x²+1 (0x11D).\n * Tables are built once at module load: `EXP[i] = αⁱ` for generator α = 2.\n */\n\nconst PRIMITIVE = 0x11d;\n\nconst EXP = new Uint8Array(512);\nconst LOG = new Uint8Array(256);\n\n{\n let x = 1;\n for (let i = 0; i < 255; i++) {\n EXP[i] = x;\n LOG[x] = i;\n x <<= 1;\n if (x & 0x100) x ^= PRIMITIVE;\n }\n // Duplicate the cycle so `EXP[log(a) + log(b)]` never needs a mod.\n for (let i = 255; i < 512; i++) EXP[i] = EXP[i - 255];\n}\n\n/** `a * b` in GF(256); `0` when either operand is 0. */\nexport function gfMultiply(a: number, b: number): number {\n return a === 0 || b === 0 ? 0 : EXP[LOG[a] + LOG[b]];\n}\n\n/**
|
|
1
|
+
{"version":3,"file":"_galois.cjs","names":[],"sources":["../src/_galois.ts"],"sourcesContent":["/**\n * GF(2⁸) arithmetic over the QR primitive polynomial x⁸+x⁴+x³+x²+1 (0x11D).\n * Tables are built once at module load: `EXP[i] = αⁱ` for generator α = 2.\n */\n\nconst PRIMITIVE = 0x11d;\n\nconst EXP = new Uint8Array(512);\nconst LOG = new Uint8Array(256);\n\n{\n let x = 1;\n for (let i = 0; i < 255; i++) {\n EXP[i] = x;\n LOG[x] = i;\n x <<= 1;\n if (x & 0x100) x ^= PRIMITIVE;\n }\n // Duplicate the cycle so `EXP[log(a) + log(b)]` never needs a mod.\n for (let i = 255; i < 512; i++) EXP[i] = EXP[i - 255];\n}\n\n/** `a * b` in GF(256); `0` when either operand is 0. */\nexport function gfMultiply(a: number, b: number): number {\n return a === 0 || b === 0 ? 0 : EXP[LOG[a] + LOG[b]];\n}\n\n/** `αⁱ`: the i-th power of the generator. `i` may exceed 254 (wraps). */\nexport function gfExp(i: number): number {\n return EXP[i % 255];\n}\n\n/** Polynomial evaluation in GF(256): Σ coeffᵢ·xⁱ with coeff[0] highest-degree. */\nexport function gfPolyEval(coeffs: readonly number[], x: number): number {\n let y = 0;\n for (const c of coeffs) y = gfMultiply(y, x) ^ c;\n return y;\n}\n\n/** Multiply two polynomials (coefficients highest-degree first). */\nexport function gfPolyMultiply(p: readonly number[], q: readonly number[]): number[] {\n const out = new Array<number>(p.length + q.length - 1).fill(0);\n for (let i = 0; i < p.length; i++) for (let j = 0; j < q.length; j++) out[i + j] ^= gfMultiply(p[i], q[j]);\n return out;\n}\n"],"mappings":"AAKA,IAAM,EAAY,IAEZ,EAAM,IAAI,WAAW,GAAG,EACxB,EAAM,IAAI,WAAW,GAAG,EAE9B,CACE,IAAI,EAAI,EACR,IAAK,IAAI,EAAI,EAAG,EAAI,IAAK,IACvB,EAAI,GAAK,EACT,EAAI,GAAK,EACT,IAAM,EACF,EAAI,MAAO,GAAK,GAGtB,IAAK,IAAI,EAAI,IAAK,EAAI,IAAK,IAAK,EAAI,GAAK,EAAI,EAAI,IACnD,CAGA,SAAgB,WAAW,EAAW,EAAmB,CACvD,OAAO,IAAM,GAAK,IAAM,EAAI,EAAI,EAAI,EAAI,GAAK,EAAI,GACnD,CAGA,SAAgB,MAAM,EAAmB,CACvC,OAAO,EAAI,EAAI,IACjB,CAUA,SAAgB,eAAe,EAAsB,EAAgC,CACnF,IAAM,EAAU,MAAc,EAAE,OAAS,EAAE,OAAS,CAAC,CAAC,CAAC,KAAK,CAAC,EAC7D,IAAK,IAAI,EAAI,EAAG,EAAI,EAAE,OAAQ,IAAK,IAAK,IAAI,EAAI,EAAG,EAAI,EAAE,OAAQ,IAAK,EAAI,EAAI,IAAM,WAAW,EAAE,GAAI,EAAE,EAAE,EACzG,OAAO,CACT"}
|
package/dist/_galois.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/** `a * b` in GF(256); `0` when either operand is 0. */
|
|
6
6
|
export declare function gfMultiply(a: number, b: number): number;
|
|
7
|
-
/**
|
|
7
|
+
/** `αⁱ`: the i-th power of the generator. `i` may exceed 254 (wraps). */
|
|
8
8
|
export declare function gfExp(i: number): number;
|
|
9
9
|
/** Polynomial evaluation in GF(256): Σ coeffᵢ·xⁱ with coeff[0] highest-degree. */
|
|
10
10
|
export declare function gfPolyEval(coeffs: readonly number[], x: number): number;
|
package/dist/_galois.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_galois.d.ts","sourceRoot":"","sources":["../src/_galois.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmBH,wDAAwD;AACxD,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,
|
|
1
|
+
{"version":3,"file":"_galois.d.ts","sourceRoot":"","sources":["../src/_galois.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmBH,wDAAwD;AACxD,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,yEAAyE;AACzE,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEvC;AAED,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAIvE;AAED,oEAAoE;AACpE,wBAAgB,cAAc,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAInF"}
|
package/dist/_galois.js
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var e = 285, t = /* @__PURE__ */ new Uint8Array(512), n = /* @__PURE__ */ new Uint8Array(256);
|
|
3
|
-
{
|
|
4
|
-
let r = 1;
|
|
5
|
-
for (let i = 0; i < 255; i++) t[i] = r, n[r] = i, r <<= 1, r & 256 && (r ^= e);
|
|
6
|
-
for (let e = 255; e < 512; e++) t[e] = t[e - 255];
|
|
7
|
-
}
|
|
8
|
-
function r(e, r) {
|
|
9
|
-
return e === 0 || r === 0 ? 0 : t[n[e] + n[r]];
|
|
10
|
-
}
|
|
11
|
-
function i(e) {
|
|
12
|
-
return t[e % 255];
|
|
13
|
-
}
|
|
14
|
-
function a(e, t) {
|
|
15
|
-
let n = Array(e.length + t.length - 1).fill(0);
|
|
16
|
-
for (let i = 0; i < e.length; i++) for (let a = 0; a < t.length; a++) n[i + a] ^= r(e[i], t[a]);
|
|
17
|
-
return n;
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
export { i as gfExp, r as gfMultiply, a as gfPolyMultiply };
|
|
21
|
-
|
|
1
|
+
var e=285,t=new Uint8Array(512),n=new Uint8Array(256);{let r=1;for(let i=0;i<255;i++)t[i]=r,n[r]=i,r<<=1,r&256&&(r^=e);for(let e=255;e<512;e++)t[e]=t[e-255]}function gfMultiply(e,r){return e===0||r===0?0:t[n[e]+n[r]]}function gfExp(e){return t[e%255]}function gfPolyMultiply(e,t){let n=Array(e.length+t.length-1).fill(0);for(let r=0;r<e.length;r++)for(let i=0;i<t.length;i++)n[r+i]^=gfMultiply(e[r],t[i]);return n}export{gfExp,gfMultiply,gfPolyMultiply};
|
|
22
2
|
//# sourceMappingURL=_galois.js.map
|
package/dist/_galois.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_galois.js","names":[],"sources":["../src/_galois.ts"],"sourcesContent":["/**\n * GF(2⁸) arithmetic over the QR primitive polynomial x⁸+x⁴+x³+x²+1 (0x11D).\n * Tables are built once at module load: `EXP[i] = αⁱ` for generator α = 2.\n */\n\nconst PRIMITIVE = 0x11d;\n\nconst EXP = new Uint8Array(512);\nconst LOG = new Uint8Array(256);\n\n{\n let x = 1;\n for (let i = 0; i < 255; i++) {\n EXP[i] = x;\n LOG[x] = i;\n x <<= 1;\n if (x & 0x100) x ^= PRIMITIVE;\n }\n // Duplicate the cycle so `EXP[log(a) + log(b)]` never needs a mod.\n for (let i = 255; i < 512; i++) EXP[i] = EXP[i - 255];\n}\n\n/** `a * b` in GF(256); `0` when either operand is 0. */\nexport function gfMultiply(a: number, b: number): number {\n return a === 0 || b === 0 ? 0 : EXP[LOG[a] + LOG[b]];\n}\n\n/**
|
|
1
|
+
{"version":3,"file":"_galois.js","names":[],"sources":["../src/_galois.ts"],"sourcesContent":["/**\n * GF(2⁸) arithmetic over the QR primitive polynomial x⁸+x⁴+x³+x²+1 (0x11D).\n * Tables are built once at module load: `EXP[i] = αⁱ` for generator α = 2.\n */\n\nconst PRIMITIVE = 0x11d;\n\nconst EXP = new Uint8Array(512);\nconst LOG = new Uint8Array(256);\n\n{\n let x = 1;\n for (let i = 0; i < 255; i++) {\n EXP[i] = x;\n LOG[x] = i;\n x <<= 1;\n if (x & 0x100) x ^= PRIMITIVE;\n }\n // Duplicate the cycle so `EXP[log(a) + log(b)]` never needs a mod.\n for (let i = 255; i < 512; i++) EXP[i] = EXP[i - 255];\n}\n\n/** `a * b` in GF(256); `0` when either operand is 0. */\nexport function gfMultiply(a: number, b: number): number {\n return a === 0 || b === 0 ? 0 : EXP[LOG[a] + LOG[b]];\n}\n\n/** `αⁱ`: the i-th power of the generator. `i` may exceed 254 (wraps). */\nexport function gfExp(i: number): number {\n return EXP[i % 255];\n}\n\n/** Polynomial evaluation in GF(256): Σ coeffᵢ·xⁱ with coeff[0] highest-degree. */\nexport function gfPolyEval(coeffs: readonly number[], x: number): number {\n let y = 0;\n for (const c of coeffs) y = gfMultiply(y, x) ^ c;\n return y;\n}\n\n/** Multiply two polynomials (coefficients highest-degree first). */\nexport function gfPolyMultiply(p: readonly number[], q: readonly number[]): number[] {\n const out = new Array<number>(p.length + q.length - 1).fill(0);\n for (let i = 0; i < p.length; i++) for (let j = 0; j < q.length; j++) out[i + j] ^= gfMultiply(p[i], q[j]);\n return out;\n}\n"],"mappings":"AAKA,IAAM,EAAY,IAEZ,EAAM,IAAI,WAAW,GAAG,EACxB,EAAM,IAAI,WAAW,GAAG,EAE9B,CACE,IAAI,EAAI,EACR,IAAK,IAAI,EAAI,EAAG,EAAI,IAAK,IACvB,EAAI,GAAK,EACT,EAAI,GAAK,EACT,IAAM,EACF,EAAI,MAAO,GAAK,GAGtB,IAAK,IAAI,EAAI,IAAK,EAAI,IAAK,IAAK,EAAI,GAAK,EAAI,EAAI,IACnD,CAGA,SAAgB,WAAW,EAAW,EAAmB,CACvD,OAAO,IAAM,GAAK,IAAM,EAAI,EAAI,EAAI,EAAI,GAAK,EAAI,GACnD,CAGA,SAAgB,MAAM,EAAmB,CACvC,OAAO,EAAI,EAAI,IACjB,CAUA,SAAgB,eAAe,EAAsB,EAAgC,CACnF,IAAM,EAAU,MAAc,EAAE,OAAS,EAAE,OAAS,CAAC,CAAC,CAAC,KAAK,CAAC,EAC7D,IAAK,IAAI,EAAI,EAAG,EAAI,EAAE,OAAQ,IAAK,IAAK,IAAI,EAAI,EAAG,EAAI,EAAE,OAAQ,IAAK,EAAI,EAAI,IAAM,WAAW,EAAE,GAAI,EAAE,EAAE,EACzG,OAAO,CACT"}
|
package/dist/_mask.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=[(e,t)=>(e+t)%2==0,(e,t)=>t%2==0,e=>e%3==0,(e,t)=>(e+t)%3==0,(e,t)=>(Math.floor(e/3)+Math.floor(t/2))%2==0,(e,t)=>e*t%2+e*t%3==0,(e,t)=>(e*t%2+e*t%3)%2==0,(e,t)=>((e+t)%2+e*t%3)%2==0];function
|
|
1
|
+
var e=[(e,t)=>(e+t)%2==0,(e,t)=>t%2==0,e=>e%3==0,(e,t)=>(e+t)%3==0,(e,t)=>(Math.floor(e/3)+Math.floor(t/2))%2==0,(e,t)=>e*t%2+e*t%3==0,(e,t)=>(e*t%2+e*t%3)%2==0,(e,t)=>((e+t)%2+e*t%3)%2==0];function applyMask(t,n){let r=e[n];for(let e=0;e<t.size;e++)for(let n=0;n<t.size;n++)!t.isFunction[e][n]&&r(n,e)&&(t.modules[e][n]=!t.modules[e][n])}var t=3,n=3,r=40,i=10;function penaltyRuns(e){let n=0,line=(e,r)=>(!e&&r>=5&&(n+=t+r-5),e?r+1:1);for(let r=0;r<e.size;r++){let i=1,a=1;for(let t=1;t<e.size;t++)i=line(e.modules[r][t]===e.modules[r][t-1],i),a=line(e.modules[t][r]===e.modules[t-1][r],a);i>=5&&(n+=t+i-5),a>=5&&(n+=t+a-5)}return n}function penaltyBlocks(e){let t=0;for(let r=0;r<e.size-1;r++)for(let i=0;i<e.size-1;i++){let a=e.modules[r][i];a===e.modules[r][i+1]&&a===e.modules[r+1][i]&&a===e.modules[r+1][i+1]&&(t+=n)}return t}function penaltyFinderLike(e){let t=e.size,n=0,checkLine=e=>{for(let i=0;i+11<=t;i++){let t=Array.from({length:11},(t,n)=>e(i+n)),a=[!1,!1,!1,!1,!0,!1,!0,!0,!0,!1,!0],o=[!0,!1,!0,!0,!0,!1,!0,!1,!1,!1,!1];(t.every((e,t)=>e===a[t])||t.every((e,t)=>e===o[t]))&&(n+=r)}};for(let n=0;n<t;n++)checkLine(t=>e.modules[n][t]);for(let n=0;n<t;n++)checkLine(t=>e.modules[t][n]);return n}function penaltyRatio(e){let t=0;for(let n of e.modules)for(let e of n)e&&t++;let n=e.size*e.size;return Math.floor(Math.abs(t*20-n*10)/n)*i}function penaltyScore(e){return penaltyRuns(e)+penaltyBlocks(e)+penaltyFinderLike(e)+penaltyRatio(e)}exports.MASK_FNS=e,exports.applyMask=applyMask,exports.penaltyScore=penaltyScore;
|
|
2
2
|
//# sourceMappingURL=_mask.cjs.map
|
package/dist/_mask.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_mask.cjs","names":[],"sources":["../src/_mask.ts"],"sourcesContent":["import type { QrGrid } from './_matrix';\n\n/**\n * Data masks and penalty scoring (§7.8.2–7.8.3):\n * eight mask functions XORed onto data modules only, then four penalty rules\n * (N1=3 runs, N2=3 blocks, N3=40 finder-like patterns, N4=10 dark ratio).\n */\n\ntype MaskFn = (x: number, y: number) => boolean;\n\nexport const MASK_FNS: readonly MaskFn[] = [\n (x, y) => (x + y) % 2 === 0,\n (_x, y) => y % 2 === 0,\n (x) => x % 3 === 0,\n (x, y) => (x + y) % 3 === 0,\n (x, y) => (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0,\n (x, y) => ((x * y) % 2) + ((x * y) % 3) === 0,\n (x, y) => (((x * y) % 2) + ((x * y) % 3)) % 2 === 0,\n (x, y) => (((x + y) % 2) + ((x * y) % 3)) % 2 === 0,\n];\n\n/** XOR mask `m` onto every non-function module. Idempotent per mask. */\nexport function applyMask(grid: QrGrid, mask: number): void {\n const fn = MASK_FNS[mask];\n for (let y = 0; y < grid.size; y++)\n for (let x = 0; x < grid.size; x++)\n if (!grid.isFunction[y][x] && fn(x, y)) grid.modules[y][x] = !grid.modules[y][x];\n}\n\nconst PENALTY_N1 = 3;\nconst PENALTY_N2 = 3;\nconst PENALTY_N3 = 40;\nconst PENALTY_N4 = 10;\n\n// Runs of ≥5 same-color modules in a row or column: N1 + (run − 5).\nfunction penaltyRuns(grid: QrGrid): number {\n let penalty = 0;\n const line = (same: boolean, run: number): number => {\n if (!same && run >= 5) penalty += PENALTY_N1 + run - 5;\n return same ? run + 1 : 1;\n };\n for (let i = 0; i < grid.size; i++) {\n let runRow = 1;\n let runCol = 1;\n for (let j = 1; j < grid.size; j++) {\n runRow = line(grid.modules[i][j] === grid.modules[i][j - 1], runRow);\n runCol = line(grid.modules[j][i] === grid.modules[j - 1][i], runCol);\n }\n if (runRow >= 5) penalty += PENALTY_N1 + runRow - 5;\n if (runCol >= 5) penalty += PENALTY_N1 + runCol - 5;\n }\n return penalty;\n}\n\n// 2×2 blocks of a single color.\nfunction penaltyBlocks(grid: QrGrid): number {\n let penalty = 0;\n for (let y = 0; y < grid.size - 1; y++)\n for (let x = 0; x < grid.size - 1; x++) {\n const c = grid.modules[y][x];\n if (c === grid.modules[y][x + 1] && c === grid.modules[y + 1][x] && c === grid.modules[y + 1][x + 1])\n penalty += PENALTY_N2;\n }\n return penalty;\n}\n\n// 1:1:3:1:1 finder-like patterns with a 4-module light border on either side.\nfunction penaltyFinderLike(grid: QrGrid): number {\n const size = grid.size;\n let penalty = 0;\n const checkLine = (get: (i: number) => boolean): void => {\n for (let i = 0; i + 11 <= size; i++) {\n const window = Array.from({ length: 11 }, (_, k) => get(i + k));\n const coreA = [false, false, false, false, true, false, true, true, true, false, true];\n const coreB = [true, false, true, true, true, false, true, false, false, false, false];\n if (window.every((v, k) => v === coreA[k]) || window.every((v, k) => v === coreB[k])) penalty += PENALTY_N3;\n }\n };\n for (let y = 0; y < size; y++) checkLine((i) => grid.modules[y][i]);\n for (let x = 0; x < size; x++) checkLine((i) => grid.modules[i][x]);\n return penalty;\n}\n\n// Ratio of dark modules: each 5% step away from 50% costs N4.\nfunction penaltyRatio(grid: QrGrid): number {\n let dark = 0;\n for (const row of grid.modules) for (const m of row) if (m) dark++;\n const total = grid.size * grid.size;\n const k = Math.floor(Math.abs(dark * 20 - total * 10) / total);\n return k * PENALTY_N4;\n}\n\n/** Total penalty score for a fully masked matrix. */\nexport function penaltyScore(grid: QrGrid): number {\n return penaltyRuns(grid) + penaltyBlocks(grid) + penaltyFinderLike(grid) + penaltyRatio(grid);\n}\n"],"mappings":"AAUA,IAAa,EAA8B,EACxC,EAAG,KAAO,EAAI,GAAK,GAAM,GACzB,EAAI,IAAM,EAAI,GAAM,EACpB,GAAM,EAAI,GAAM,GAChB,EAAG,KAAO,EAAI,GAAK,GAAM,GACzB,EAAG,KAAO,KAAK,MAAM,EAAI,CAAC,EAAI,KAAK,MAAM,EAAI,CAAC,GAAK,GAAM,GACzD,EAAG,IAAQ,EAAI,EAAK,EAAO,EAAI,EAAK,GAAO,GAC3C,EAAG,KAAS,EAAI,EAAK,EAAO,EAAI,EAAK,GAAM,GAAM,GACjD,EAAG,MAAS,EAAI,GAAK,EAAO,EAAI,EAAK,GAAM,GAAM,CACpD,EAGA,SAAgB,
|
|
1
|
+
{"version":3,"file":"_mask.cjs","names":[],"sources":["../src/_mask.ts"],"sourcesContent":["import type { QrGrid } from './_matrix';\n\n/**\n * Data masks and penalty scoring (§7.8.2–7.8.3):\n * eight mask functions XORed onto data modules only, then four penalty rules\n * (N1=3 runs, N2=3 blocks, N3=40 finder-like patterns, N4=10 dark ratio).\n */\n\ntype MaskFn = (x: number, y: number) => boolean;\n\nexport const MASK_FNS: readonly MaskFn[] = [\n (x, y) => (x + y) % 2 === 0,\n (_x, y) => y % 2 === 0,\n (x) => x % 3 === 0,\n (x, y) => (x + y) % 3 === 0,\n (x, y) => (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0,\n (x, y) => ((x * y) % 2) + ((x * y) % 3) === 0,\n (x, y) => (((x * y) % 2) + ((x * y) % 3)) % 2 === 0,\n (x, y) => (((x + y) % 2) + ((x * y) % 3)) % 2 === 0,\n];\n\n/** XOR mask `m` onto every non-function module. Idempotent per mask. */\nexport function applyMask(grid: QrGrid, mask: number): void {\n const fn = MASK_FNS[mask];\n for (let y = 0; y < grid.size; y++)\n for (let x = 0; x < grid.size; x++)\n if (!grid.isFunction[y][x] && fn(x, y)) grid.modules[y][x] = !grid.modules[y][x];\n}\n\nconst PENALTY_N1 = 3;\nconst PENALTY_N2 = 3;\nconst PENALTY_N3 = 40;\nconst PENALTY_N4 = 10;\n\n// Runs of ≥5 same-color modules in a row or column: N1 + (run − 5).\nfunction penaltyRuns(grid: QrGrid): number {\n let penalty = 0;\n const line = (same: boolean, run: number): number => {\n if (!same && run >= 5) penalty += PENALTY_N1 + run - 5;\n return same ? run + 1 : 1;\n };\n for (let i = 0; i < grid.size; i++) {\n let runRow = 1;\n let runCol = 1;\n for (let j = 1; j < grid.size; j++) {\n runRow = line(grid.modules[i][j] === grid.modules[i][j - 1], runRow);\n runCol = line(grid.modules[j][i] === grid.modules[j - 1][i], runCol);\n }\n if (runRow >= 5) penalty += PENALTY_N1 + runRow - 5;\n if (runCol >= 5) penalty += PENALTY_N1 + runCol - 5;\n }\n return penalty;\n}\n\n// 2×2 blocks of a single color.\nfunction penaltyBlocks(grid: QrGrid): number {\n let penalty = 0;\n for (let y = 0; y < grid.size - 1; y++)\n for (let x = 0; x < grid.size - 1; x++) {\n const c = grid.modules[y][x];\n if (c === grid.modules[y][x + 1] && c === grid.modules[y + 1][x] && c === grid.modules[y + 1][x + 1])\n penalty += PENALTY_N2;\n }\n return penalty;\n}\n\n// 1:1:3:1:1 finder-like patterns with a 4-module light border on either side.\nfunction penaltyFinderLike(grid: QrGrid): number {\n const size = grid.size;\n let penalty = 0;\n const checkLine = (get: (i: number) => boolean): void => {\n for (let i = 0; i + 11 <= size; i++) {\n const window = Array.from({ length: 11 }, (_, k) => get(i + k));\n const coreA = [false, false, false, false, true, false, true, true, true, false, true];\n const coreB = [true, false, true, true, true, false, true, false, false, false, false];\n if (window.every((v, k) => v === coreA[k]) || window.every((v, k) => v === coreB[k])) penalty += PENALTY_N3;\n }\n };\n for (let y = 0; y < size; y++) checkLine((i) => grid.modules[y][i]);\n for (let x = 0; x < size; x++) checkLine((i) => grid.modules[i][x]);\n return penalty;\n}\n\n// Ratio of dark modules: each 5% step away from 50% costs N4.\nfunction penaltyRatio(grid: QrGrid): number {\n let dark = 0;\n for (const row of grid.modules) for (const m of row) if (m) dark++;\n const total = grid.size * grid.size;\n const k = Math.floor(Math.abs(dark * 20 - total * 10) / total);\n return k * PENALTY_N4;\n}\n\n/** Total penalty score for a fully masked matrix. */\nexport function penaltyScore(grid: QrGrid): number {\n return penaltyRuns(grid) + penaltyBlocks(grid) +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C1C,IAAI,EAAO,EACX,IAAK,IAAM,KAAO,EAAK,QAAS,IAAK,IAAM,KAAK,EAAS,GAAG,IAC5D,IAAM,EAAQ,EAAK,KAAO,EAAK,KAE/B,OADU,KAAK,MAAM,KAAK,IAAI,EAAO,GAAK,EAAQ,EAAE,EAAI,CACjD,EAAI,CACb,CAGA,SAAgB,aAAa,EAAsB,CACjD,OAAO,YAAY,CAAI,EAAI,cAAc,CAAI,EAAI,kBAAkB,CAAI,EAAI,aAAa,CAAI,CAC9F"}
|
package/dist/_mask.js
CHANGED
|
@@ -1,81 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var e = [
|
|
3
|
-
(e, t) => (e + t) % 2 == 0,
|
|
4
|
-
(e, t) => t % 2 == 0,
|
|
5
|
-
(e) => e % 3 == 0,
|
|
6
|
-
(e, t) => (e + t) % 3 == 0,
|
|
7
|
-
(e, t) => (Math.floor(e / 3) + Math.floor(t / 2)) % 2 == 0,
|
|
8
|
-
(e, t) => e * t % 2 + e * t % 3 == 0,
|
|
9
|
-
(e, t) => (e * t % 2 + e * t % 3) % 2 == 0,
|
|
10
|
-
(e, t) => ((e + t) % 2 + e * t % 3) % 2 == 0
|
|
11
|
-
];
|
|
12
|
-
function t(t, n) {
|
|
13
|
-
let r = e[n];
|
|
14
|
-
for (let e = 0; e < t.size; e++) for (let n = 0; n < t.size; n++) !t.isFunction[e][n] && r(n, e) && (t.modules[e][n] = !t.modules[e][n]);
|
|
15
|
-
}
|
|
16
|
-
var n = 3, r = 3, i = 40, a = 10;
|
|
17
|
-
function o(e) {
|
|
18
|
-
let t = 0, r = (e, r) => (!e && r >= 5 && (t += n + r - 5), e ? r + 1 : 1);
|
|
19
|
-
for (let i = 0; i < e.size; i++) {
|
|
20
|
-
let a = 1, o = 1;
|
|
21
|
-
for (let t = 1; t < e.size; t++) a = r(e.modules[i][t] === e.modules[i][t - 1], a), o = r(e.modules[t][i] === e.modules[t - 1][i], o);
|
|
22
|
-
a >= 5 && (t += n + a - 5), o >= 5 && (t += n + o - 5);
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
}
|
|
26
|
-
function s(e) {
|
|
27
|
-
let t = 0;
|
|
28
|
-
for (let n = 0; n < e.size - 1; n++) for (let i = 0; i < e.size - 1; i++) {
|
|
29
|
-
let a = e.modules[n][i];
|
|
30
|
-
a === e.modules[n][i + 1] && a === e.modules[n + 1][i] && a === e.modules[n + 1][i + 1] && (t += r);
|
|
31
|
-
}
|
|
32
|
-
return t;
|
|
33
|
-
}
|
|
34
|
-
function c(e) {
|
|
35
|
-
let t = e.size, n = 0, r = (e) => {
|
|
36
|
-
for (let r = 0; r + 11 <= t; r++) {
|
|
37
|
-
let t = Array.from({ length: 11 }, (t, n) => e(r + n)), a = [
|
|
38
|
-
!1,
|
|
39
|
-
!1,
|
|
40
|
-
!1,
|
|
41
|
-
!1,
|
|
42
|
-
!0,
|
|
43
|
-
!1,
|
|
44
|
-
!0,
|
|
45
|
-
!0,
|
|
46
|
-
!0,
|
|
47
|
-
!1,
|
|
48
|
-
!0
|
|
49
|
-
], o = [
|
|
50
|
-
!0,
|
|
51
|
-
!1,
|
|
52
|
-
!0,
|
|
53
|
-
!0,
|
|
54
|
-
!0,
|
|
55
|
-
!1,
|
|
56
|
-
!0,
|
|
57
|
-
!1,
|
|
58
|
-
!1,
|
|
59
|
-
!1,
|
|
60
|
-
!1
|
|
61
|
-
];
|
|
62
|
-
(t.every((e, t) => e === a[t]) || t.every((e, t) => e === o[t])) && (n += i);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
for (let n = 0; n < t; n++) r((t) => e.modules[n][t]);
|
|
66
|
-
for (let n = 0; n < t; n++) r((t) => e.modules[t][n]);
|
|
67
|
-
return n;
|
|
68
|
-
}
|
|
69
|
-
function l(e) {
|
|
70
|
-
let t = 0;
|
|
71
|
-
for (let n of e.modules) for (let e of n) e && t++;
|
|
72
|
-
let n = e.size * e.size;
|
|
73
|
-
return Math.floor(Math.abs(t * 20 - n * 10) / n) * a;
|
|
74
|
-
}
|
|
75
|
-
function u(e) {
|
|
76
|
-
return o(e) + s(e) + c(e) + l(e);
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
export { e as MASK_FNS, t as applyMask, u as penaltyScore };
|
|
80
|
-
|
|
1
|
+
var e=[(e,t)=>(e+t)%2==0,(e,t)=>t%2==0,e=>e%3==0,(e,t)=>(e+t)%3==0,(e,t)=>(Math.floor(e/3)+Math.floor(t/2))%2==0,(e,t)=>e*t%2+e*t%3==0,(e,t)=>(e*t%2+e*t%3)%2==0,(e,t)=>((e+t)%2+e*t%3)%2==0];function applyMask(t,n){let r=e[n];for(let e=0;e<t.size;e++)for(let n=0;n<t.size;n++)!t.isFunction[e][n]&&r(n,e)&&(t.modules[e][n]=!t.modules[e][n])}var t=3,n=3,r=40,i=10;function penaltyRuns(e){let n=0,line=(e,r)=>(!e&&r>=5&&(n+=t+r-5),e?r+1:1);for(let r=0;r<e.size;r++){let i=1,a=1;for(let t=1;t<e.size;t++)i=line(e.modules[r][t]===e.modules[r][t-1],i),a=line(e.modules[t][r]===e.modules[t-1][r],a);i>=5&&(n+=t+i-5),a>=5&&(n+=t+a-5)}return n}function penaltyBlocks(e){let t=0;for(let r=0;r<e.size-1;r++)for(let i=0;i<e.size-1;i++){let a=e.modules[r][i];a===e.modules[r][i+1]&&a===e.modules[r+1][i]&&a===e.modules[r+1][i+1]&&(t+=n)}return t}function penaltyFinderLike(e){let t=e.size,n=0,checkLine=e=>{for(let i=0;i+11<=t;i++){let t=Array.from({length:11},(t,n)=>e(i+n)),a=[!1,!1,!1,!1,!0,!1,!0,!0,!0,!1,!0],o=[!0,!1,!0,!0,!0,!1,!0,!1,!1,!1,!1];(t.every((e,t)=>e===a[t])||t.every((e,t)=>e===o[t]))&&(n+=r)}};for(let n=0;n<t;n++)checkLine(t=>e.modules[n][t]);for(let n=0;n<t;n++)checkLine(t=>e.modules[t][n]);return n}function penaltyRatio(e){let t=0;for(let n of e.modules)for(let e of n)e&&t++;let n=e.size*e.size;return Math.floor(Math.abs(t*20-n*10)/n)*i}function penaltyScore(e){return penaltyRuns(e)+penaltyBlocks(e)+penaltyFinderLike(e)+penaltyRatio(e)}export{e as MASK_FNS,applyMask,penaltyScore};
|
|
81
2
|
//# sourceMappingURL=_mask.js.map
|
package/dist/_mask.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_mask.js","names":[],"sources":["../src/_mask.ts"],"sourcesContent":["import type { QrGrid } from './_matrix';\n\n/**\n * Data masks and penalty scoring (§7.8.2–7.8.3):\n * eight mask functions XORed onto data modules only, then four penalty rules\n * (N1=3 runs, N2=3 blocks, N3=40 finder-like patterns, N4=10 dark ratio).\n */\n\ntype MaskFn = (x: number, y: number) => boolean;\n\nexport const MASK_FNS: readonly MaskFn[] = [\n (x, y) => (x + y) % 2 === 0,\n (_x, y) => y % 2 === 0,\n (x) => x % 3 === 0,\n (x, y) => (x + y) % 3 === 0,\n (x, y) => (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0,\n (x, y) => ((x * y) % 2) + ((x * y) % 3) === 0,\n (x, y) => (((x * y) % 2) + ((x * y) % 3)) % 2 === 0,\n (x, y) => (((x + y) % 2) + ((x * y) % 3)) % 2 === 0,\n];\n\n/** XOR mask `m` onto every non-function module. Idempotent per mask. */\nexport function applyMask(grid: QrGrid, mask: number): void {\n const fn = MASK_FNS[mask];\n for (let y = 0; y < grid.size; y++)\n for (let x = 0; x < grid.size; x++)\n if (!grid.isFunction[y][x] && fn(x, y)) grid.modules[y][x] = !grid.modules[y][x];\n}\n\nconst PENALTY_N1 = 3;\nconst PENALTY_N2 = 3;\nconst PENALTY_N3 = 40;\nconst PENALTY_N4 = 10;\n\n// Runs of ≥5 same-color modules in a row or column: N1 + (run − 5).\nfunction penaltyRuns(grid: QrGrid): number {\n let penalty = 0;\n const line = (same: boolean, run: number): number => {\n if (!same && run >= 5) penalty += PENALTY_N1 + run - 5;\n return same ? run + 1 : 1;\n };\n for (let i = 0; i < grid.size; i++) {\n let runRow = 1;\n let runCol = 1;\n for (let j = 1; j < grid.size; j++) {\n runRow = line(grid.modules[i][j] === grid.modules[i][j - 1], runRow);\n runCol = line(grid.modules[j][i] === grid.modules[j - 1][i], runCol);\n }\n if (runRow >= 5) penalty += PENALTY_N1 + runRow - 5;\n if (runCol >= 5) penalty += PENALTY_N1 + runCol - 5;\n }\n return penalty;\n}\n\n// 2×2 blocks of a single color.\nfunction penaltyBlocks(grid: QrGrid): number {\n let penalty = 0;\n for (let y = 0; y < grid.size - 1; y++)\n for (let x = 0; x < grid.size - 1; x++) {\n const c = grid.modules[y][x];\n if (c === grid.modules[y][x + 1] && c === grid.modules[y + 1][x] && c === grid.modules[y + 1][x + 1])\n penalty += PENALTY_N2;\n }\n return penalty;\n}\n\n// 1:1:3:1:1 finder-like patterns with a 4-module light border on either side.\nfunction penaltyFinderLike(grid: QrGrid): number {\n const size = grid.size;\n let penalty = 0;\n const checkLine = (get: (i: number) => boolean): void => {\n for (let i = 0; i + 11 <= size; i++) {\n const window = Array.from({ length: 11 }, (_, k) => get(i + k));\n const coreA = [false, false, false, false, true, false, true, true, true, false, true];\n const coreB = [true, false, true, true, true, false, true, false, false, false, false];\n if (window.every((v, k) => v === coreA[k]) || window.every((v, k) => v === coreB[k])) penalty += PENALTY_N3;\n }\n };\n for (let y = 0; y < size; y++) checkLine((i) => grid.modules[y][i]);\n for (let x = 0; x < size; x++) checkLine((i) => grid.modules[i][x]);\n return penalty;\n}\n\n// Ratio of dark modules: each 5% step away from 50% costs N4.\nfunction penaltyRatio(grid: QrGrid): number {\n let dark = 0;\n for (const row of grid.modules) for (const m of row) if (m) dark++;\n const total = grid.size * grid.size;\n const k = Math.floor(Math.abs(dark * 20 - total * 10) / total);\n return k * PENALTY_N4;\n}\n\n/** Total penalty score for a fully masked matrix. */\nexport function penaltyScore(grid: QrGrid): number {\n return penaltyRuns(grid) + penaltyBlocks(grid) + penaltyFinderLike(grid) + penaltyRatio(grid);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"_mask.js","names":[],"sources":["../src/_mask.ts"],"sourcesContent":["import type { QrGrid } from './_matrix';\n\n/**\n * Data masks and penalty scoring (§7.8.2–7.8.3):\n * eight mask functions XORed onto data modules only, then four penalty rules\n * (N1=3 runs, N2=3 blocks, N3=40 finder-like patterns, N4=10 dark ratio).\n */\n\ntype MaskFn = (x: number, y: number) => boolean;\n\nexport const MASK_FNS: readonly MaskFn[] = [\n (x, y) => (x + y) % 2 === 0,\n (_x, y) => y % 2 === 0,\n (x) => x % 3 === 0,\n (x, y) => (x + y) % 3 === 0,\n (x, y) => (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0,\n (x, y) => ((x * y) % 2) + ((x * y) % 3) === 0,\n (x, y) => (((x * y) % 2) + ((x * y) % 3)) % 2 === 0,\n (x, y) => (((x + y) % 2) + ((x * y) % 3)) % 2 === 0,\n];\n\n/** XOR mask `m` onto every non-function module. Idempotent per mask. */\nexport function applyMask(grid: QrGrid, mask: number): void {\n const fn = MASK_FNS[mask];\n for (let y = 0; y < grid.size; y++)\n for (let x = 0; x < grid.size; x++)\n if (!grid.isFunction[y][x] && fn(x, y)) grid.modules[y][x] = !grid.modules[y][x];\n}\n\nconst PENALTY_N1 = 3;\nconst PENALTY_N2 = 3;\nconst PENALTY_N3 = 40;\nconst PENALTY_N4 = 10;\n\n// Runs of ≥5 same-color modules in a row or column: N1 + (run − 5).\nfunction penaltyRuns(grid: QrGrid): number {\n let penalty = 0;\n const line = (same: boolean, run: number): number => {\n if (!same && run >= 5) penalty += PENALTY_N1 + run - 5;\n return same ? run + 1 : 1;\n };\n for (let i = 0; i < grid.size; i++) {\n let runRow = 1;\n let runCol = 1;\n for (let j = 1; j < grid.size; j++) {\n runRow = line(grid.modules[i][j] === grid.modules[i][j - 1], runRow);\n runCol = line(grid.modules[j][i] === grid.modules[j - 1][i], runCol);\n }\n if (runRow >= 5) penalty += PENALTY_N1 + runRow - 5;\n if (runCol >= 5) penalty += PENALTY_N1 + runCol - 5;\n }\n return penalty;\n}\n\n// 2×2 blocks of a single color.\nfunction penaltyBlocks(grid: QrGrid): number {\n let penalty = 0;\n for (let y = 0; y < grid.size - 1; y++)\n for (let x = 0; x < grid.size - 1; x++) {\n const c = grid.modules[y][x];\n if (c === grid.modules[y][x + 1] && c === grid.modules[y + 1][x] && c === grid.modules[y + 1][x + 1])\n penalty += PENALTY_N2;\n }\n return penalty;\n}\n\n// 1:1:3:1:1 finder-like patterns with a 4-module light border on either side.\nfunction penaltyFinderLike(grid: QrGrid): number {\n const size = grid.size;\n let penalty = 0;\n const checkLine = (get: (i: number) => boolean): void => {\n for (let i = 0; i + 11 <= size; i++) {\n const window = Array.from({ length: 11 }, (_, k) => get(i + k));\n const coreA = [false, false, false, false, true, false, true, true, true, false, true];\n const coreB = [true, false, true, true, true, false, true, false, false, false, false];\n if (window.every((v, k) => v === coreA[k]) || window.every((v, k) => v === coreB[k])) penalty += PENALTY_N3;\n }\n };\n for (let y = 0; y < size; y++) checkLine((i) => grid.modules[y][i]);\n for (let x = 0; x < size; x++) checkLine((i) => grid.modules[i][x]);\n return penalty;\n}\n\n// Ratio of dark modules: each 5% step away from 50% costs N4.\nfunction penaltyRatio(grid: QrGrid): number {\n let dark = 0;\n for (const row of grid.modules) for (const m of row) if (m) dark++;\n const total = grid.size * grid.size;\n const k = Math.floor(Math.abs(dark * 20 - total * 10) / total);\n return k * PENALTY_N4;\n}\n\n/** Total penalty score for a fully masked matrix. */\nexport function penaltyScore(grid: QrGrid): number {\n return penaltyRuns(grid) + penaltyBlocks(grid) + penaltyFinderLike(grid) + penaltyRatio(grid);\n}\n"],"mappings":"AAUA,IAAa,EAA8B,EACxC,EAAG,KAAO,EAAI,GAAK,GAAM,GACzB,EAAI,IAAM,EAAI,GAAM,EACpB,GAAM,EAAI,GAAM,GAChB,EAAG,KAAO,EAAI,GAAK,GAAM,GACzB,EAAG,KAAO,KAAK,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B,aAAa,EAAsB,CACjD,OAAO,YAAY,CAAI,EAAI,cAAc,CAAI,EAAI,kBAAkB,CAAI,EAAI,aAAa,CAAI,CAC9F"}
|
package/dist/_matrix.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./_tables.cjs");function
|
|
1
|
+
const e=require("./_tables.cjs");function createGrid(e){return{isFunction:Array.from({length:e},()=>Array(e).fill(!1)),modules:Array.from({length:e},()=>Array(e).fill(!1)),size:e}}var setFunction=(e,t,n,r)=>{e.modules[n][t]=r,e.isFunction[n][t]=!0};function drawFinder(e,t,n){for(let r=-4;r<=4;r++)for(let i=-4;i<=4;i++){let a=t+3+i,o=n+3+r;if(a<0||o<0||a>=e.size||o>=e.size)continue;let s=Math.max(Math.abs(i),Math.abs(r));setFunction(e,a,o,s!==2&&s!==4)}}function drawTiming(e){for(let t=8;t<e.size-8;t++){let n=t%2==0;e.isFunction[6][t]||setFunction(e,t,6,n),e.isFunction[t][6]||setFunction(e,6,t,n)}}function drawAlignment(e,t,n){for(let r=-2;r<=2;r++)for(let i=-2;i<=2;i++)setFunction(e,t+i,n+r,Math.max(Math.abs(i),Math.abs(r))!==1)}function reserveFormatAreas(e){let t=e.size;for(let t=0;t<=8;t++)t!==6&&(e.isFunction[8][t]=!0,e.isFunction[t][8]=!0);for(let n=0;n<7;n++)e.isFunction[t-1-n][8]=!0;for(let n=0;n<8;n++)e.isFunction[8][t-1-n]=!0;e.isFunction[t-8][8]=!0}function reserveVersionAreas(e,t){if(t<7)return;let n=e.size;for(let t=0;t<18;t++){let r=n-11+t%3,i=Math.floor(t/3);e.isFunction[i][r]=!0,e.isFunction[r][i]=!0}}function drawFunctionPatterns(t,n){drawFinder(t,0,0),drawFinder(t,t.size-7,0),drawFinder(t,0,t.size-7),drawTiming(t);let r=e.alignmentPatternPositions(n);for(let e of r)for(let n of r)n===6&&e===6||n===6&&e===t.size-7||n===t.size-7&&e===6||drawAlignment(t,n,e);reserveFormatAreas(t),reserveVersionAreas(t,n)}function placeData(e,t){let n=e.size,r=t.length*8,i=0,a=!0;for(let o=n-1;o>=1;o-=2){o===6&&(o=5);for(let s=0;s<n;s++)for(let c=0;c<2;c++){let l=o-c,u=a?n-1-s:s;e.isFunction[u][l]||(e.modules[u][l]=i<r&&(t[i>>>3]>>>7-(i&7)&1)==1,i++)}a=!a}}exports.createGrid=createGrid,exports.drawFunctionPatterns=drawFunctionPatterns,exports.placeData=placeData;
|
|
2
2
|
//# sourceMappingURL=_matrix.cjs.map
|
package/dist/_matrix.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_matrix.cjs","names":[],"sources":["../src/_matrix.ts"],"sourcesContent":["import { alignmentPatternPositions } from './_tables';\n\n/**\n * Module placement (§7.7–7.9, Annex E): function patterns are drawn first and\n * recorded in `isFunction`, then the codeword bit stream fills the remaining\n * modules in a two-column zigzag starting bottom-right, skipping column 6.\n */\n\nexport interface QrGrid {\n /** Modules owned by function patterns
|
|
1
|
+
{"version":3,"file":"_matrix.cjs","names":[],"sources":["../src/_matrix.ts"],"sourcesContent":["import { alignmentPatternPositions } from './_tables';\n\n/**\n * Module placement (§7.7–7.9, Annex E): function patterns are drawn first and\n * recorded in `isFunction`, then the codeword bit stream fills the remaining\n * modules in a two-column zigzag starting bottom-right, skipping column 6.\n */\n\nexport interface QrGrid {\n /** Modules owned by function patterns: skipped by data placement and masks. */\n readonly isFunction: boolean[][];\n /** Final module colors; `true` = dark. Mutable during construction. */\n modules: boolean[][];\n readonly size: number;\n}\n\nexport function createGrid(size: number): QrGrid {\n return {\n isFunction: Array.from({ length: size }, () => new Array<boolean>(size).fill(false)),\n modules: Array.from({ length: size }, () => new Array<boolean>(size).fill(false)),\n size,\n };\n}\n\nconst setFunction = (grid: QrGrid, x: number, y: number, dark: boolean): void => {\n grid.modules[y][x] = dark;\n grid.isFunction[y][x] = true;\n};\n\n/** 7×7 finder pattern plus the one-module separator ring, centered at (x+3, y+3). */\nfunction drawFinder(grid: QrGrid, x: number, y: number): void {\n for (let dy = -4; dy <= 4; dy++)\n for (let dx = -4; dx <= 4; dx++) {\n const xx = x + 3 + dx;\n const yy = y + 3 + dy;\n if (xx < 0 || yy < 0 || xx >= grid.size || yy >= grid.size) continue;\n const dist = Math.max(Math.abs(dx), Math.abs(dy));\n setFunction(grid, xx, yy, dist !== 2 && dist !== 4);\n }\n}\n\n/** Alternating timing pattern along row/col 6, between the finders. */\nfunction drawTiming(grid: QrGrid): void {\n for (let i = 8; i < grid.size - 8; i++) {\n const dark = i % 2 === 0;\n if (!grid.isFunction[6][i]) setFunction(grid, i, 6, dark);\n if (!grid.isFunction[i][6]) setFunction(grid, 6, i, dark);\n }\n}\n\n/** 5×5 alignment pattern centered at (cx, cy). */\nfunction drawAlignment(grid: QrGrid, cx: number, cy: number): void {\n for (let dy = -2; dy <= 2; dy++)\n for (let dx = -2; dx <= 2; dx++) setFunction(grid, cx + dx, cy + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);\n}\n\n/**\n * Reserve the 15 format-info modules around each finder (both copies) and the\n * 6×3 version-info blocks for v≥7: drawn later by `_format.ts`, but data\n * placement must skip them now.\n */\nfunction reserveFormatAreas(grid: QrGrid): void {\n const size = grid.size;\n // Around the top-left finder.\n for (let i = 0; i <= 8; i++) {\n if (i !== 6) {\n grid.isFunction[8][i] = true;\n grid.isFunction[i][8] = true;\n }\n }\n // Second copy: column 8 rows size-1..size-7 beside the bottom-left finder,\n // row 8 columns size-1..size-8 beside the top-right finder.\n for (let i = 0; i < 7; i++) grid.isFunction[size - 1 - i][8] = true;\n for (let i = 0; i < 8; i++) grid.isFunction[8][size - 1 - i] = true;\n // Always-dark module below the bottom-left format strip.\n grid.isFunction[size - 8][8] = true;\n}\n\nfunction reserveVersionAreas(grid: QrGrid, version: number): void {\n if (version < 7) return;\n const size = grid.size;\n for (let i = 0; i < 18; i++) {\n const a = size - 11 + (i % 3);\n const b = Math.floor(i / 3);\n grid.isFunction[b][a] = true; // top-right block\n grid.isFunction[a][b] = true; // bottom-left block\n }\n}\n\n/** Draw every function pattern and mark reserved areas. */\nexport function drawFunctionPatterns(grid: QrGrid, version: number): void {\n drawFinder(grid, 0, 0);\n drawFinder(grid, grid.size - 7, 0);\n drawFinder(grid, 0, grid.size - 7);\n drawTiming(grid);\n const positions = alignmentPatternPositions(version);\n for (const cy of positions)\n for (const cx of positions) {\n // Skip the three corners covered by finder patterns.\n const isCorner =\n (cx === 6 && cy === 6) || (cx === 6 && cy === grid.size - 7) || (cx === grid.size - 7 && cy === 6);\n if (!isCorner) drawAlignment(grid, cx, cy);\n }\n reserveFormatAreas(grid);\n reserveVersionAreas(grid, version);\n}\n\n/** Place codeword bits into non-function modules via the zigzag scan. */\nexport function placeData(grid: QrGrid, codewords: readonly number[]): void {\n const size = grid.size;\n const totalBits = codewords.length * 8;\n let bitIndex = 0;\n let upward = true;\n for (let right = size - 1; right >= 1; right -= 2) {\n if (right === 6) right = 5; // skip the vertical timing column\n for (let vert = 0; vert < size; vert++) {\n for (let j = 0; j < 2; j++) {\n const x = right - j;\n const y = upward ? size - 1 - vert : vert;\n if (grid.isFunction[y][x]) continue;\n grid.modules[y][x] = bitIndex < totalBits && ((codewords[bitIndex >>> 3] >>> (7 - (bitIndex & 7))) & 1) === 1;\n bitIndex++;\n }\n }\n upward = !upward;\n }\n}\n"],"mappings":"iCAgBA,SAAgB,WAAW,EAAsB,CAC/C,MAAO,CACL,WAAY,MAAM,KAAK,CAAE,OAAQ,CAAK,MAAa,MAAe,CAAI,CAAC,CAAC,KAAK,EAAK,CAAC,EACnF,QAAS,MAAM,KAAK,CAAE,OAAQ,CAAK,MAAa,MAAe,CAAI,CAAC,CAAC,KAAK,EAAK,CAAC,EAChF,MACF,CACF,CAEA,IAAM,aAAe,EAAc,EAAW,EAAW,IAAwB,CAC/E,EAAK,QAAQ,EAAE,CAAC,GAAK,EACrB,EAAK,WAAW,EAAE,CAAC,GAAK,EAC1B,EAGA,SAAS,WAAW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AAK,EAAW,GAAO,IAAO,EAC5G,IACF,CAEF,EAAS,CAAC,CACZ,CACF"}
|
package/dist/_matrix.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* modules in a two-column zigzag starting bottom-right, skipping column 6.
|
|
5
5
|
*/
|
|
6
6
|
export interface QrGrid {
|
|
7
|
-
/** Modules owned by function patterns
|
|
7
|
+
/** Modules owned by function patterns: skipped by data placement and masks. */
|
|
8
8
|
readonly isFunction: boolean[][];
|
|
9
9
|
/** Final module colors; `true` = dark. Mutable during construction. */
|
|
10
10
|
modules: boolean[][];
|
package/dist/_matrix.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_matrix.d.ts","sourceRoot":"","sources":["../src/_matrix.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,MAAM,WAAW,MAAM;IACrB
|
|
1
|
+
{"version":3,"file":"_matrix.d.ts","sourceRoot":"","sources":["../src/_matrix.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,MAAM,WAAW,MAAM;IACrB,+EAA+E;IAC/E,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;IACjC,uEAAuE;IACvE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM/C;AAmED,2DAA2D;AAC3D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAexE;AAED,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAkB1E"}
|
package/dist/_matrix.js
CHANGED
|
@@ -1,65 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
//#region src/_matrix.ts
|
|
3
|
-
function t(e) {
|
|
4
|
-
return {
|
|
5
|
-
isFunction: Array.from({ length: e }, () => Array(e).fill(!1)),
|
|
6
|
-
modules: Array.from({ length: e }, () => Array(e).fill(!1)),
|
|
7
|
-
size: e
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
var n = (e, t, n, r) => {
|
|
11
|
-
e.modules[n][t] = r, e.isFunction[n][t] = !0;
|
|
12
|
-
};
|
|
13
|
-
function r(e, t, r) {
|
|
14
|
-
for (let i = -4; i <= 4; i++) for (let a = -4; a <= 4; a++) {
|
|
15
|
-
let o = t + 3 + a, s = r + 3 + i;
|
|
16
|
-
if (o < 0 || s < 0 || o >= e.size || s >= e.size) continue;
|
|
17
|
-
let c = Math.max(Math.abs(a), Math.abs(i));
|
|
18
|
-
n(e, o, s, c !== 2 && c !== 4);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function i(e) {
|
|
22
|
-
for (let t = 8; t < e.size - 8; t++) {
|
|
23
|
-
let r = t % 2 == 0;
|
|
24
|
-
e.isFunction[6][t] || n(e, t, 6, r), e.isFunction[t][6] || n(e, 6, t, r);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function a(e, t, r) {
|
|
28
|
-
for (let i = -2; i <= 2; i++) for (let a = -2; a <= 2; a++) n(e, t + a, r + i, Math.max(Math.abs(a), Math.abs(i)) !== 1);
|
|
29
|
-
}
|
|
30
|
-
function o(e) {
|
|
31
|
-
let t = e.size;
|
|
32
|
-
for (let t = 0; t <= 8; t++) t !== 6 && (e.isFunction[8][t] = !0, e.isFunction[t][8] = !0);
|
|
33
|
-
for (let n = 0; n < 7; n++) e.isFunction[t - 1 - n][8] = !0;
|
|
34
|
-
for (let n = 0; n < 8; n++) e.isFunction[8][t - 1 - n] = !0;
|
|
35
|
-
e.isFunction[t - 8][8] = !0;
|
|
36
|
-
}
|
|
37
|
-
function s(e, t) {
|
|
38
|
-
if (t < 7) return;
|
|
39
|
-
let n = e.size;
|
|
40
|
-
for (let t = 0; t < 18; t++) {
|
|
41
|
-
let r = n - 11 + t % 3, i = Math.floor(t / 3);
|
|
42
|
-
e.isFunction[i][r] = !0, e.isFunction[r][i] = !0;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function c(t, n) {
|
|
46
|
-
r(t, 0, 0), r(t, t.size - 7, 0), r(t, 0, t.size - 7), i(t);
|
|
47
|
-
let c = e(n);
|
|
48
|
-
for (let e of c) for (let n of c) n === 6 && e === 6 || n === 6 && e === t.size - 7 || n === t.size - 7 && e === 6 || a(t, n, e);
|
|
49
|
-
o(t), s(t, n);
|
|
50
|
-
}
|
|
51
|
-
function l(e, t) {
|
|
52
|
-
let n = e.size, r = t.length * 8, i = 0, a = !0;
|
|
53
|
-
for (let o = n - 1; o >= 1; o -= 2) {
|
|
54
|
-
o === 6 && (o = 5);
|
|
55
|
-
for (let s = 0; s < n; s++) for (let c = 0; c < 2; c++) {
|
|
56
|
-
let l = o - c, u = a ? n - 1 - s : s;
|
|
57
|
-
e.isFunction[u][l] || (e.modules[u][l] = i < r && (t[i >>> 3] >>> 7 - (i & 7) & 1) == 1, i++);
|
|
58
|
-
}
|
|
59
|
-
a = !a;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
export { t as createGrid, c as drawFunctionPatterns, l as placeData };
|
|
64
|
-
|
|
1
|
+
import{alignmentPatternPositions as e}from"./_tables.js";function createGrid(e){return{isFunction:Array.from({length:e},()=>Array(e).fill(!1)),modules:Array.from({length:e},()=>Array(e).fill(!1)),size:e}}var setFunction=(e,t,n,r)=>{e.modules[n][t]=r,e.isFunction[n][t]=!0};function drawFinder(e,t,n){for(let r=-4;r<=4;r++)for(let i=-4;i<=4;i++){let a=t+3+i,o=n+3+r;if(a<0||o<0||a>=e.size||o>=e.size)continue;let s=Math.max(Math.abs(i),Math.abs(r));setFunction(e,a,o,s!==2&&s!==4)}}function drawTiming(e){for(let t=8;t<e.size-8;t++){let n=t%2==0;e.isFunction[6][t]||setFunction(e,t,6,n),e.isFunction[t][6]||setFunction(e,6,t,n)}}function drawAlignment(e,t,n){for(let r=-2;r<=2;r++)for(let i=-2;i<=2;i++)setFunction(e,t+i,n+r,Math.max(Math.abs(i),Math.abs(r))!==1)}function reserveFormatAreas(e){let t=e.size;for(let t=0;t<=8;t++)t!==6&&(e.isFunction[8][t]=!0,e.isFunction[t][8]=!0);for(let n=0;n<7;n++)e.isFunction[t-1-n][8]=!0;for(let n=0;n<8;n++)e.isFunction[8][t-1-n]=!0;e.isFunction[t-8][8]=!0}function reserveVersionAreas(e,t){if(t<7)return;let n=e.size;for(let t=0;t<18;t++){let r=n-11+t%3,i=Math.floor(t/3);e.isFunction[i][r]=!0,e.isFunction[r][i]=!0}}function drawFunctionPatterns(t,n){drawFinder(t,0,0),drawFinder(t,t.size-7,0),drawFinder(t,0,t.size-7),drawTiming(t);let r=e(n);for(let e of r)for(let n of r)n===6&&e===6||n===6&&e===t.size-7||n===t.size-7&&e===6||drawAlignment(t,n,e);reserveFormatAreas(t),reserveVersionAreas(t,n)}function placeData(e,t){let n=e.size,r=t.length*8,i=0,a=!0;for(let o=n-1;o>=1;o-=2){o===6&&(o=5);for(let s=0;s<n;s++)for(let c=0;c<2;c++){let l=o-c,u=a?n-1-s:s;e.isFunction[u][l]||(e.modules[u][l]=i<r&&(t[i>>>3]>>>7-(i&7)&1)==1,i++)}a=!a}}export{createGrid,drawFunctionPatterns,placeData};
|
|
65
2
|
//# sourceMappingURL=_matrix.js.map
|
package/dist/_matrix.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_matrix.js","names":[],"sources":["../src/_matrix.ts"],"sourcesContent":["import { alignmentPatternPositions } from './_tables';\n\n/**\n * Module placement (§7.7–7.9, Annex E): function patterns are drawn first and\n * recorded in `isFunction`, then the codeword bit stream fills the remaining\n * modules in a two-column zigzag starting bottom-right, skipping column 6.\n */\n\nexport interface QrGrid {\n /** Modules owned by function patterns
|
|
1
|
+
{"version":3,"file":"_matrix.js","names":[],"sources":["../src/_matrix.ts"],"sourcesContent":["import { alignmentPatternPositions } from './_tables';\n\n/**\n * Module placement (§7.7–7.9, Annex E): function patterns are drawn first and\n * recorded in `isFunction`, then the codeword bit stream fills the remaining\n * modules in a two-column zigzag starting bottom-right, skipping column 6.\n */\n\nexport interface QrGrid {\n /** Modules owned by function patterns: skipped by data placement and masks. */\n readonly isFunction: boolean[][];\n /** Final module colors; `true` = dark. Mutable during construction. */\n modules: boolean[][];\n readonly size: number;\n}\n\nexport function createGrid(size: number): QrGrid {\n return {\n isFunction: Array.from({ length: size }, () => new Array<boolean>(size).fill(false)),\n modules: Array.from({ length: size }, () => new Array<boolean>(size).fill(false)),\n size,\n };\n}\n\nconst setFunction = (grid: QrGrid, x: number, y: number, dark: boolean): void => {\n grid.modules[y][x] = dark;\n grid.isFunction[y][x] = true;\n};\n\n/** 7×7 finder pattern plus the one-module separator ring, centered at (x+3, y+3). */\nfunction drawFinder(grid: QrGrid, x: number, y: number): void {\n for (let dy = -4; dy <= 4; dy++)\n for (let dx = -4; dx <= 4; dx++) {\n const xx = x + 3 + dx;\n const yy = y + 3 + dy;\n if (xx < 0 || yy < 0 || xx >= grid.size || yy >= grid.size) continue;\n const dist = Math.max(Math.abs(dx), Math.abs(dy));\n setFunction(grid, xx, yy, dist !== 2 && dist !== 4);\n }\n}\n\n/** Alternating timing pattern along row/col 6, between the finders. */\nfunction drawTiming(grid: QrGrid): void {\n for (let i = 8; i < grid.size - 8; i++) {\n const dark = i % 2 === 0;\n if (!grid.isFunction[6][i]) setFunction(grid, i, 6, dark);\n if (!grid.isFunction[i][6]) setFunction(grid, 6, i, dark);\n }\n}\n\n/** 5×5 alignment pattern centered at (cx, cy). */\nfunction drawAlignment(grid: QrGrid, cx: number, cy: number): void {\n for (let dy = -2; dy <= 2; dy++)\n for (let dx = -2; dx <= 2; dx++) setFunction(grid, cx + dx, cy + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);\n}\n\n/**\n * Reserve the 15 format-info modules around each finder (both copies) and the\n * 6×3 version-info blocks for v≥7: drawn later by `_format.ts`, but data\n * placement must skip them now.\n */\nfunction reserveFormatAreas(grid: QrGrid): void {\n const size = grid.size;\n // Around the top-left finder.\n for (let i = 0; i <= 8; i++) {\n if (i !== 6) {\n grid.isFunction[8][i] = true;\n grid.isFunction[i][8] = true;\n }\n }\n // Second copy: column 8 rows size-1..size-7 beside the bottom-left finder,\n // row 8 columns size-1..size-8 beside the top-right finder.\n for (let i = 0; i < 7; i++) grid.isFunction[size - 1 - i][8] = true;\n for (let i = 0; i < 8; i++) grid.isFunction[8][size - 1 - i] = true;\n // Always-dark module below the bottom-left format strip.\n grid.isFunction[size - 8][8] = true;\n}\n\nfunction reserveVersionAreas(grid: QrGrid, version: number): void {\n if (version < 7) return;\n const size = grid.size;\n for (let i = 0; i < 18; i++) {\n const a = size - 11 + (i % 3);\n const b = Math.floor(i / 3);\n grid.isFunction[b][a] = true; // top-right block\n grid.isFunction[a][b] = true; // bottom-left block\n }\n}\n\n/** Draw every function pattern and mark reserved areas. */\nexport function drawFunctionPatterns(grid: QrGrid, version: number): void {\n drawFinder(grid, 0, 0);\n drawFinder(grid, grid.size - 7, 0);\n drawFinder(grid, 0, grid.size - 7);\n drawTiming(grid);\n const positions = alignmentPatternPositions(version);\n for (const cy of positions)\n for (const cx of positions) {\n // Skip the three corners covered by finder patterns.\n const isCorner =\n (cx === 6 && cy === 6) || (cx === 6 && cy === grid.size - 7) || (cx === grid.size - 7 && cy === 6);\n if (!isCorner) drawAlignment(grid, cx, cy);\n }\n reserveFormatAreas(grid);\n reserveVersionAreas(grid, version);\n}\n\n/** Place codeword bits into non-function modules via the zigzag scan. */\nexport function placeData(grid: QrGrid, codewords: readonly number[]): void {\n const size = grid.size;\n const totalBits = codewords.length * 8;\n let bitIndex = 0;\n let upward = true;\n for (let right = size - 1; right >= 1; right -= 2) {\n if (right === 6) right = 5; // skip the vertical timing column\n for (let vert = 0; vert < size; vert++) {\n for (let j = 0; j < 2; j++) {\n const x = right - j;\n const y = upward ? size - 1 - vert : vert;\n if (grid.isFunction[y][x]) continue;\n grid.modules[y][x] = bitIndex < totalBits && ((codewords[bitIndex >>> 3] >>> (7 - (bitIndex & 7))) & 1) === 1;\n bitIndex++;\n }\n }\n upward = !upward;\n }\n}\n"],"mappings":"yDAgBA,SAAgB,WAAW,EAAsB,CAC/C,MAAO,CACL,WAAY,MAAM,KAAK,CAAE,OAAQ,CAAK,MAAa,MAAe,CAAI,CAAC,CAAC,KAAK,EAAK,CAAC,EACnF,QAAS,MAAM,KAAK,CAAE,OAAQ,CAAK,MAAa,MAAe,CAAI,CAAC,CAAC,KAAK,EAAK,CAAC,EAChF,MACF,CACF,CAEA,IAAM,aAAe,EAAc,EAAW,EAAW,IAAwB,CAC/E,EAAK,QAAQ,EAAE,CAAC,GAAK,EACrB,EAAK,WAAW,EAAE,CAAC,GAAK,EAC1B,EAGA,SAAS,WAAW,EAAc,EAAW,EAAiB,CAC5D,IAAK,IAAI,EAAK,GAAI,GAAM,EAAG,IACzB,IAAK,IAAI,EAAK,GAAI,GAAM,EAAG,IAAM,CAC/B,IAAM,EAAK,EAAI,EAAI,EACb,EAAK,EAAI,EAAI,EACnB,GAAI,EAAK,GAAK,EAAK,GAAK,GAAM,EAAK,MAAQ,GAAM,EAAK,KAAM,SAC5D,IAAM,EAAO,KAAK,IAAI,KAAK,IAAI,CAAE,EAAG,KAAK,IAAI,CAAE,CAAC,EAChD,YAAY,EAAM,EAAI,EAAI,IAAS,GAAK,IAAS,CAAC,CACpD,CACJ,CAGA,SAAS,WAAW,EAAoB,CACtC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,KAAO,EAAG,IAAK,CACtC,IAAM,EAAO,EAAI,GAAM,EAClB,EAAK,WAAW,EAAE,CAAC,IAAI,YAAY,EAAM,EAAG,EAAG,CAAI,EACnD,EAAK,WAAW,EAAE,CAAC,IAAI,YAAY,EAAM,EAAG,EAAG,CAAI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AO,GAAK,IAAO,EAAK,KAAO,GAAO,IAAO,EAAK,KAAO,GAAK,IAAO,GACnF,cAAc,EAAM,EAAI,CAAE,EAE7C,mBAAmB,CAAI,EACvB,oBAAoB,EAAM,CAAO,CACnC,CAGA,SAAgB,UAAU,EAAc,EAAoC,CAC1E,IAAM,EAAO,EAAK,KACZ,EAAY,EAAU,OAAS,EACjC,EAAW,EACX,EAAS,GACb,IAAK,IAAI,EAAQ,EAAO,EAAG,GAAS,EAAG,GAAS,EAAG,CAC7C,IAAU,IAAG,EAAQ,GACzB,IAAK,IAAI,EAAO,EAAG,EAAO,EAAM,IAC9B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,CAC1B,IAAM,EAAI,EAAQ,EACZ,EAAI,EAAS,EAAO,EAAI,EAAO,EACjC,EAAK,WAAW,EAAE,CAAC,KACvB,EAAK,QAAQ,EAAE,CAAC,GAAK,EAAW,IAAe,EAAU,IAAa,KAAQ,GAAK,EAAW,GAAO,IAAO,EAC5G,IACF,CAEF,EAAS,CAAC,CACZ,CACF"}
|
package/dist/_reed-solomon.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./_galois.cjs");var t=new Map;function
|
|
1
|
+
const e=require("./_galois.cjs");var t=new Map;function generatorPoly(n){let r=t.get(n);if(r)return r;let i=[1];for(let t=0;t<n;t++)i=e.gfPolyMultiply(i,[1,e.gfExp(t)]);return t.set(n,i),i}function ecCodewords(t,n){let r=generatorPoly(n),i=Array(n).fill(0);for(let a of t){let t=a^i[0];if(i.copyWithin(0,1),i[n-1]=0,t!==0)for(let a=0;a<n;a++)i[a]^=e.gfMultiply(r[a+1],t)}return i}exports.ecCodewords=ecCodewords;
|
|
2
2
|
//# sourceMappingURL=_reed-solomon.cjs.map
|