specqr 1.0.0-rc.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/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +254 -0
- package/docs/api.md +226 -0
- package/docs/spec-scope.md +75 -0
- package/docs/test-plan.md +119 -0
- package/fixtures/decode-cases.json +116 -0
- package/fixtures/golden-cases.json +5363 -0
- package/package.json +67 -0
- package/src/browser.d.ts +8 -0
- package/src/browser.js +99 -0
- package/src/core/codewords.js +52 -0
- package/src/core/galois-field.js +41 -0
- package/src/core/mask.js +123 -0
- package/src/core/matrix.js +239 -0
- package/src/core/reed-solomon.js +41 -0
- package/src/core/tables.js +112 -0
- package/src/diagnostics.js +208 -0
- package/src/encoding/bit-buffer.js +54 -0
- package/src/encoding/modes.js +666 -0
- package/src/encoding/shift-jis.js +97 -0
- package/src/errors.js +61 -0
- package/src/gs1.js +167 -0
- package/src/index.d.ts +215 -0
- package/src/index.js +255 -0
- package/src/node.d.ts +7 -0
- package/src/node.js +26 -0
- package/src/options.js +117 -0
- package/src/render/base64.js +25 -0
- package/src/render/canvas.js +51 -0
- package/src/render/color.js +68 -0
- package/src/render/png.js +156 -0
- package/src/render/svg.js +38 -0
- package/tools/decode-vision.swift +24 -0
- package/tools/update-golden-fixtures.js +378 -0
- package/tools/verify-decode-optional.js +394 -0
- package/tools/verify-decode.js +84 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# テスト計画
|
|
2
|
+
|
|
3
|
+
## Unit Tests
|
|
4
|
+
|
|
5
|
+
- Bit buffer が指定 bit を正確に書き込むこと。
|
|
6
|
+
- UTF-8 byte encoding が ASCII と multi-byte characters を扱うこと。
|
|
7
|
+
- Numeric / alphanumeric mode selection が QR character set に従うこと。
|
|
8
|
+
- Shift_JIS-compatible Japanese text が QR Kanji mode を使えること。
|
|
9
|
+
- Mixed-segment optimization が byte / numeric / alphanumeric / kanji runs の bit length を減らすこと。
|
|
10
|
+
- Manual segments が呼び出し側の mode selection を保つこと。
|
|
11
|
+
- Binary input が UTF-8 text conversion を通らず byte mode になること。
|
|
12
|
+
- `ArrayBufferView` input が `byteOffset` と `byteLength` を尊重すること。
|
|
13
|
+
- Error correction boosting が、同じ Version に収まる場合だけ ECC を上げること。
|
|
14
|
+
- ECI metadata が leading control segment として追加され、decode 可能な output を保つこと。
|
|
15
|
+
- ECI capacity accounting が option-driven ECI、manual ECI segments、mixed segments、exact-fit payloads、max+1 `DataTooLongError` を覆うこと。
|
|
16
|
+
- GS1/FNC1 first position が `0101` mode indicator を encode し、diagnostics、API collision、supported human-readable parser、GS1 element-string helper を検証すること。
|
|
17
|
+
- Kanji mode が Shift_JIS `TextDecoder` のない環境で明確に fallback / reject すること。
|
|
18
|
+
- Diagnostics が capacity、mask/version selection reasons、quiet-zone status、contrast、print hints、warnings を出すこと。
|
|
19
|
+
- Node helpers が PNG buffers を返し、PNG file を書き出すこと。
|
|
20
|
+
- Browser helpers が platform support のある環境で Blob/ImageData/Object URL output を返すこと。
|
|
21
|
+
- Root、Node、browser subpath exports が import 可能であること。
|
|
22
|
+
- Deterministic random payloads が matrix shape、capacity、masking、diagnostics invariants を満たすこと。
|
|
23
|
+
- Reed-Solomon arithmetic が安定した correction bytes を生成すること。
|
|
24
|
+
- Version capacity selection が fitting payloads を受け入れ、oversized payloads を reject すること。
|
|
25
|
+
- Matrix size が `21 + 4 * (version - 1)` に従うこと。
|
|
26
|
+
- Version range boundaries 9/10 と 26/27 で numeric、alphanumeric、byte、Kanji mode の character count indicator width が正しいこと。
|
|
27
|
+
- Fixed-version capacity edges で最大 payload を受け入れ、1 character / 1 byte 超過を reject すること。
|
|
28
|
+
- Mask penalty conformance が N1/N2/N3/N4 penalty rules と fixed/auto mask diagnostics consistency を覆うこと。
|
|
29
|
+
- SVG output が quiet zone と期待寸法を含むこと。
|
|
30
|
+
- PNG output が valid PNG signature と期待寸法を持つこと。
|
|
31
|
+
- SVG/PNG Data URL output が正しい media type を含むこと。
|
|
32
|
+
- Canvas drawing が canvas dimensions を設定し、background/modules を描画すること。
|
|
33
|
+
|
|
34
|
+
## Golden Tests
|
|
35
|
+
|
|
36
|
+
Golden tests は、fixed version、error correction level、mask settings のもとで deterministic な QR construction を固定します。目的は generated matrix と codeword stream の意図しない変化を検出することで、decoder validation の代替ではありません。
|
|
37
|
+
|
|
38
|
+
Golden fixtures は `fixtures/golden-cases.json` にあり、`tests/golden-conformance.test.js` で検証します。各 fixture は次を保持します。
|
|
39
|
+
|
|
40
|
+
- fixed input または manual segments
|
|
41
|
+
- fixed `version`, `errorCorrectionLevel`, `maskPattern`
|
|
42
|
+
- version、mask、capacity、segment bit lengths、codeword counts の diagnostics fields
|
|
43
|
+
- padded data codewords と final interleaved data/ECC codewords
|
|
44
|
+
- full matrix rows、SHA-256 hash、dark-module count
|
|
45
|
+
- independently computed format information bits
|
|
46
|
+
- version 7+ の independently computed version information bits
|
|
47
|
+
- function-module、data-module、remainder-bit counts
|
|
48
|
+
|
|
49
|
+
現在の golden coverage は、numeric、alphanumeric、byte URL、UTF-8 byte text、QR Kanji mode、manual mixed segments、ECI-prefixed UTF-8 byte text、ECI-prefixed auto mixed exact-fit fixture、GS1/FNC1 first-position exact-fit fixture、raw binary byte data、version information modules を使う version 7 symbol、version 10 / version 27 の exact-fit boundary fixtures を含みます。
|
|
50
|
+
|
|
51
|
+
Version boundary conformance は `tests/version-boundaries.test.js` でも検証します。この test は 1-9、10-26、27-40 の version ranges で numeric、alphanumeric、byte、Kanji mode の payload bit length を独立に計算し、automatic input と manual segments の両方を確認します。そのうえで fixed-version max payloads と max+1 `DataTooLongError` failure を検証します。
|
|
52
|
+
|
|
53
|
+
`tests/eci-mixed-capacity.test.js` と `tests/mask-penalty.test.js` は、ECI bit accounting、mixed-segment boundaries、individual mask penalty rules、auto/fixed mask diagnostics consistency を固定します。
|
|
54
|
+
|
|
55
|
+
GS1/FNC1 first-position coverage は `tests/gs1.test.js` にあります。raw element strings、manual FNC1 segments、supported human-readable parser cases、fixed/variable AI validation、separator insertion、invalid-input rejection を検証します。decoder によって FNC1 control mode や symbology identifier の露出方法が異なるため、GS1 semantics の唯一の根拠を decoder validation には置きません。
|
|
56
|
+
|
|
57
|
+
snapshot は QR construction change を意図的に受け入れる場合だけ再生成します。
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
npm run fixtures:golden
|
|
61
|
+
npm test
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Golden tests は、すべての scanner が output image を受け入れることを証明しません。下記の Vision / jsQR decode checks と併せて解釈します。
|
|
65
|
+
|
|
66
|
+
## Decoder Validation
|
|
67
|
+
|
|
68
|
+
より高い信頼性のため、generated SVG または rasterized output を少なくとも 1 つの独立 decoder で検証します。
|
|
69
|
+
|
|
70
|
+
### Required Baseline: macOS Vision
|
|
71
|
+
|
|
72
|
+
macOS では fixture-based Vision validation を実行できます。
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
npm run verify:decode
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
fixture set は、URL、numeric、alphanumeric、UTF-8 byte、ECI、auto Kanji、manual segments、manual Kanji segments、fixed version boundaries、error-correction boosting、ASCII binary payloads の SVG / PNG output を覆います。
|
|
79
|
+
|
|
80
|
+
### Required Independent Decoder: jsQR
|
|
81
|
+
|
|
82
|
+
release-gate independent decoder check は devDependency の `jsqr` を使います。
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
npm run verify:decode:jsqr
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
この script は `jsqr` が import できない場合に失敗し、対応 fixture artifact を decode できない場合も失敗します。すべての decode fixture の generated PNG output を検証します。ImageMagick `magick` が利用できる場合は、generated SVG output を PNG に render して検証します。
|
|
89
|
+
|
|
90
|
+
現在の jsQR fixture coverage は、URL、numeric、alphanumeric、UTF-8 byte、ECI text、auto Kanji、manual segments、manual Kanji segments、fixed version boundaries、error-correction boosting、ASCII binary payloads を含みます。jsQR は decoded data を text として返すため、arbitrary binary bytes は jsQR assertion の対象にしません。
|
|
91
|
+
|
|
92
|
+
## Optional Multi-Decoder Validation
|
|
93
|
+
|
|
94
|
+
追加の decoder validation は optional script として提供します。
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
npm run verify:decode:optional
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
この script はすべての decode fixture の PNG output を生成し、ImageMagick `magick` が利用できる場合は SVG output も PNG に render します。そのうえで、ローカル環境で使える decoder を実行します。
|
|
101
|
+
|
|
102
|
+
- `jsQR`: `jsqr` package が install されている場合。
|
|
103
|
+
- `zbarimg`: command が install されている場合。
|
|
104
|
+
- ZXing-style CLI commands: `ZXingReader`, `zxing`, `zxing-cpp`, `zxingscan` のいずれかが install されている場合。
|
|
105
|
+
|
|
106
|
+
これらの decoder は package の hard dependency ではありません。存在しない decoder は `skip` として報告され、script failure にはしません。少なくとも 1 つの optional decoder が利用できる場合、decode mismatch は failure になります。
|
|
107
|
+
|
|
108
|
+
Optional script は local release checks や decoder environment を制御できる CI job に向いています。portable baseline としては `npm test` と `npm run verify:decode:jsqr` を保ちます。
|
|
109
|
+
|
|
110
|
+
## CI
|
|
111
|
+
|
|
112
|
+
repository には minimal GitHub Actions workflow `.github/workflows/ci.yml` があります。実行内容は次の通りです。
|
|
113
|
+
|
|
114
|
+
- `npm ci`
|
|
115
|
+
- `npm test`
|
|
116
|
+
- `npm run verify:decode:jsqr`
|
|
117
|
+
- `npm pack --dry-run`
|
|
118
|
+
|
|
119
|
+
macOS Vision validation は Swift、Vision、ImageMagick に依存するため、local/macOS release check として扱います。
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "ascii-url",
|
|
4
|
+
"text": "https://example.com",
|
|
5
|
+
"options": {
|
|
6
|
+
"errorCorrectionLevel": "M"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "numeric-auto",
|
|
11
|
+
"text": "123456789012345678901234567890",
|
|
12
|
+
"options": {
|
|
13
|
+
"errorCorrectionLevel": "Q"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "alphanumeric-auto",
|
|
18
|
+
"text": "HELLO WORLD 123",
|
|
19
|
+
"options": {
|
|
20
|
+
"errorCorrectionLevel": "M"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"id": "utf8-byte",
|
|
25
|
+
"text": "こんにちは",
|
|
26
|
+
"options": {
|
|
27
|
+
"mode": "byte",
|
|
28
|
+
"errorCorrectionLevel": "M"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": "kanji-auto",
|
|
33
|
+
"text": "こんにちは漢字",
|
|
34
|
+
"options": {
|
|
35
|
+
"errorCorrectionLevel": "M"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "utf8-eci",
|
|
40
|
+
"text": "こんにちは",
|
|
41
|
+
"options": {
|
|
42
|
+
"eci": true,
|
|
43
|
+
"errorCorrectionLevel": "M"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"id": "mixed-segments-eci",
|
|
48
|
+
"text": "ORDER-1234567890-こんにちは",
|
|
49
|
+
"options": {
|
|
50
|
+
"eci": true,
|
|
51
|
+
"errorCorrectionLevel": "M"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "manual-segments",
|
|
56
|
+
"segments": [
|
|
57
|
+
{
|
|
58
|
+
"mode": "alphanumeric",
|
|
59
|
+
"data": "ORDER-"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"mode": "numeric",
|
|
63
|
+
"data": "1234567890"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"mode": "byte",
|
|
67
|
+
"data": "-こんにちは"
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
"expected": "ORDER-1234567890-こんにちは",
|
|
71
|
+
"options": {
|
|
72
|
+
"errorCorrectionLevel": "M"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"id": "manual-kanji-segments",
|
|
77
|
+
"segments": [
|
|
78
|
+
{
|
|
79
|
+
"mode": "alphanumeric",
|
|
80
|
+
"data": "KANJI "
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"mode": "kanji",
|
|
84
|
+
"data": "漢字"
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
"expected": "KANJI 漢字",
|
|
88
|
+
"options": {
|
|
89
|
+
"errorCorrectionLevel": "M"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"id": "binary-ascii",
|
|
94
|
+
"binaryHex": "414243313233",
|
|
95
|
+
"expected": "ABC123",
|
|
96
|
+
"options": {
|
|
97
|
+
"errorCorrectionLevel": "M"
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"id": "version-7-format-boundary",
|
|
102
|
+
"text": "Version 7",
|
|
103
|
+
"options": {
|
|
104
|
+
"version": 7,
|
|
105
|
+
"errorCorrectionLevel": "L"
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"id": "boosted-ecc",
|
|
110
|
+
"text": "HELLO",
|
|
111
|
+
"options": {
|
|
112
|
+
"errorCorrectionLevel": "L",
|
|
113
|
+
"boostErrorCorrection": true
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
]
|