hcc2d-encoder 0.0.0-stage → 0.9.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 +19 -0
- package/LICENSE +186 -0
- package/README.md +311 -2
- package/bin/hcc2d-encoder.js +5 -0
- package/package.json +51 -4
- package/src/cli.js +156 -0
- package/src/encoder.js +646 -0
- package/src/index.js +15 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.9.0-rc.1
|
|
4
|
+
|
|
5
|
+
- added a pure JavaScript HCC2D reference encoder for Node.js
|
|
6
|
+
- aligned encoding behavior with the public C and Python reference encoders 0.9.0
|
|
7
|
+
- added standard QR, HCC2D4, and HCC2D8 output
|
|
8
|
+
- added raw and HCC2DF payload formats for text and files
|
|
9
|
+
- aligned defaults, validation limits, palettes, help, copyright, license,
|
|
10
|
+
disclaimer, and specification references with the other official encoders
|
|
11
|
+
- added an importable ES module API and the `hcc2d-encoder` console command
|
|
12
|
+
- added regression tests for known QR, HCC2D4, and HCC2D8 outputs
|
|
13
|
+
- added 842 C/Python/JavaScript parity cases covering every forced version,
|
|
14
|
+
binary capacity boundaries, automatic selection, multi-block symbols, and
|
|
15
|
+
decompressed PNG output, plus 12 exact overflow-rejection checks
|
|
16
|
+
- added GitHub Actions CI for supported Node.js 22 and 24 LTS releases and
|
|
17
|
+
Node.js 26 Current, with npm 12.2.1 for release automation
|
|
18
|
+
- added npm package smoke testing and an OIDC Trusted Publishing workflow with
|
|
19
|
+
immutable action and reference-encoder revisions
|
package/LICENSE
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the
|
|
13
|
+
copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other
|
|
16
|
+
entities that control, are controlled by, or are under common control with
|
|
17
|
+
that entity. For the purposes of this definition, "control" means (i) the
|
|
18
|
+
power, direct or indirect, to cause the direction or management of such
|
|
19
|
+
entity, whether by contract or otherwise, or (ii) ownership of fifty percent
|
|
20
|
+
(50%) or more of the outstanding shares, or (iii) beneficial ownership of
|
|
21
|
+
such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
24
|
+
permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation source, and
|
|
28
|
+
configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
31
|
+
translation of a Source form, including but not limited to compiled object
|
|
32
|
+
code, generated documentation, and conversions to other media types.
|
|
33
|
+
|
|
34
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
35
|
+
made available under the License, as indicated by a copyright notice that is
|
|
36
|
+
included in or attached to the work (an example is provided in the Appendix
|
|
37
|
+
below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object form,
|
|
40
|
+
that is based on (or derived from) the Work and for which the editorial
|
|
41
|
+
revisions, annotations, elaborations, or other modifications represent, as a
|
|
42
|
+
whole, an original work of authorship. For the purposes of this License,
|
|
43
|
+
Derivative Works shall not include works that remain separable from, or
|
|
44
|
+
merely link (or bind by name) to the interfaces of, the Work and Derivative
|
|
45
|
+
Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
48
|
+
version of the Work and any modifications or additions to that Work or
|
|
49
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
50
|
+
inclusion in the Work by the copyright owner or by an individual or Legal
|
|
51
|
+
Entity authorized to submit on behalf of the copyright owner. For the
|
|
52
|
+
purposes of this definition, "submitted" means any form of electronic, verbal,
|
|
53
|
+
or written communication sent to the Licensor or its representatives,
|
|
54
|
+
including but not limited to communication on electronic mailing lists, source
|
|
55
|
+
code control systems, and issue tracking systems that are managed by, or on
|
|
56
|
+
behalf of, the Licensor for the purpose of discussing and improving the Work,
|
|
57
|
+
but excluding communication that is conspicuously marked or otherwise
|
|
58
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
59
|
+
|
|
60
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
61
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
62
|
+
incorporated within the Work.
|
|
63
|
+
|
|
64
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
65
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
66
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
67
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
68
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
69
|
+
Object form.
|
|
70
|
+
|
|
71
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
72
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
73
|
+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
|
|
74
|
+
section) patent license to make, have made, use, offer to sell, sell, import,
|
|
75
|
+
and otherwise transfer the Work, where such license applies only to those
|
|
76
|
+
patent claims licensable by such Contributor that are necessarily infringed by
|
|
77
|
+
their Contribution(s) alone or by combination of their Contribution(s) with
|
|
78
|
+
the Work to which such Contribution(s) was submitted. If You institute patent
|
|
79
|
+
litigation against any entity (including a cross-claim or counterclaim in a
|
|
80
|
+
lawsuit) alleging that the Work or a Contribution incorporated within the Work
|
|
81
|
+
constitutes direct or contributory patent infringement, then any patent
|
|
82
|
+
licenses granted to You under this License for that Work shall terminate as of
|
|
83
|
+
the date such litigation is filed.
|
|
84
|
+
|
|
85
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
86
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
87
|
+
Source or Object form, provided that You meet the following conditions:
|
|
88
|
+
|
|
89
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy
|
|
90
|
+
of this License; and
|
|
91
|
+
|
|
92
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
93
|
+
You changed the files; and
|
|
94
|
+
|
|
95
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
96
|
+
distribute, all copyright, patent, trademark, and attribution notices from
|
|
97
|
+
the Source form of the Work, excluding those notices that do not pertain to
|
|
98
|
+
any part of the Derivative Works; and
|
|
99
|
+
|
|
100
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution,
|
|
101
|
+
then any Derivative Works that You distribute must include a readable copy of
|
|
102
|
+
the attribution notices contained within such NOTICE file, excluding those
|
|
103
|
+
notices that do not pertain to any part of the Derivative Works, in at least
|
|
104
|
+
one of the following places: within a NOTICE text file distributed as part of
|
|
105
|
+
the Derivative Works; within the Source form or documentation, if provided
|
|
106
|
+
along with the Derivative Works; or, within a display generated by the
|
|
107
|
+
Derivative Works, if and wherever such third-party notices normally appear.
|
|
108
|
+
The contents of the NOTICE file are for informational purposes only and do not
|
|
109
|
+
modify the License. You may add Your own attribution notices within Derivative
|
|
110
|
+
Works that You distribute, alongside or as an addendum to the NOTICE text from
|
|
111
|
+
the Work, provided that such additional attribution notices cannot be
|
|
112
|
+
construed as modifying the License.
|
|
113
|
+
|
|
114
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
115
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
116
|
+
distribution of Your modifications, or for any such Derivative Works as a
|
|
117
|
+
whole, provided Your use, reproduction, and distribution of the Work otherwise
|
|
118
|
+
complies with the conditions stated in this License.
|
|
119
|
+
|
|
120
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
121
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
122
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
123
|
+
additional terms or conditions. Notwithstanding the above, nothing herein
|
|
124
|
+
shall supersede or modify the terms of any separate license agreement you may
|
|
125
|
+
have executed with Licensor regarding such Contributions.
|
|
126
|
+
|
|
127
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
128
|
+
trademarks, service marks, or product names of the Licensor, except as
|
|
129
|
+
required for reasonable and customary use in describing the origin of the Work
|
|
130
|
+
and reproducing the content of the NOTICE file.
|
|
131
|
+
|
|
132
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
133
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
134
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
135
|
+
KIND, either express or implied, including, without limitation, any warranties
|
|
136
|
+
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
137
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
138
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
139
|
+
associated with Your exercise of permissions under this License.
|
|
140
|
+
|
|
141
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
142
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
143
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
144
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
145
|
+
direct, indirect, special, incidental, or consequential damages of any
|
|
146
|
+
character arising as a result of this License or out of the use or inability
|
|
147
|
+
to use the Work (including but not limited to damages for loss of goodwill,
|
|
148
|
+
work stoppage, computer failure or malfunction, or any and all other
|
|
149
|
+
commercial damages or losses), even if such Contributor has been advised of
|
|
150
|
+
the possibility of such damages.
|
|
151
|
+
|
|
152
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work
|
|
153
|
+
or Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
154
|
+
acceptance of support, warranty, indemnity, or other liability obligations
|
|
155
|
+
and/or rights consistent with this License. However, in accepting such
|
|
156
|
+
obligations, You may act only on Your own behalf and on Your sole
|
|
157
|
+
responsibility, not on behalf of any other Contributor, and only if You agree
|
|
158
|
+
to indemnify, defend, and hold each Contributor harmless for any liability
|
|
159
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
160
|
+
accepting any such warranty or additional liability.
|
|
161
|
+
|
|
162
|
+
END OF TERMS AND CONDITIONS
|
|
163
|
+
|
|
164
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
165
|
+
|
|
166
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
167
|
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
|
168
|
+
identifying information. (Don't include the brackets!) The text should be
|
|
169
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
170
|
+
recommend that a file or class name and description of purpose be included on
|
|
171
|
+
the same "printed page" as the copyright notice for easier identification
|
|
172
|
+
within third-party archives.
|
|
173
|
+
|
|
174
|
+
Copyright [yyyy] [name of copyright owner]
|
|
175
|
+
|
|
176
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
177
|
+
you may not use this file except in compliance with the License.
|
|
178
|
+
You may obtain a copy of the License at
|
|
179
|
+
|
|
180
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
181
|
+
|
|
182
|
+
Unless required by applicable law or agreed to in writing, software
|
|
183
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
184
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
185
|
+
See the License for the specific language governing permissions and
|
|
186
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,312 @@
|
|
|
1
|
-
#
|
|
1
|
+
# HCC2D JavaScript Encoder 0.9.0-rc.1
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/marco-querini/hcc2d-cli-javascript-encoder/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/hcc2d-encoder)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Written by Marco Querini.
|
|
8
|
+
|
|
9
|
+
Pure JavaScript reference encoder for standard QR Code, HCC2D4, and HCC2D8.
|
|
10
|
+
It provides both an importable ES module API and the `hcc2d-encoder` command.
|
|
11
|
+
The encoding algorithm is an independent JavaScript implementation: it does
|
|
12
|
+
not invoke the C or Python encoders and does not use WebAssembly or native npm
|
|
13
|
+
add-ons.
|
|
14
|
+
|
|
15
|
+
## Official links
|
|
16
|
+
|
|
17
|
+
- HCC2D website: <https://hcc2d.com/en/>
|
|
18
|
+
- HCC2D Code Specification 0.9.0: <https://doi.org/10.5281/zenodo.22206528>
|
|
19
|
+
- HCC2D API: <https://hcc2d.com/en/api>
|
|
20
|
+
- Source: <https://github.com/marco-querini/hcc2d-cli-javascript-encoder>
|
|
21
|
+
- npm package: <https://www.npmjs.com/package/hcc2d-encoder>
|
|
22
|
+
- C reference encoder: <https://github.com/marco-querini/hcc2d-cli-c-encoder>
|
|
23
|
+
- Python reference encoder: <https://github.com/marco-querini/hcc2d-cli-python-encoder>
|
|
24
|
+
- Client-side WebAssembly encoder: <https://marco-querini.github.io/hcc2d-web-encoder/>
|
|
25
|
+
- HCC2D Decoder:
|
|
26
|
+
- Google Play: <https://play.google.com/store/apps/details?id=com.hcc2d.decoder>
|
|
27
|
+
- Huawei AppGallery: <https://appgallery.cloud.huawei.com/marketshare/app/C117478101>
|
|
28
|
+
- App Store: <https://apps.apple.com/app/id6762202762>
|
|
29
|
+
- HCC2D Encoder on the Mac App Store: <https://apps.apple.com/app/id6767833986>
|
|
30
|
+
|
|
31
|
+
## Supported features
|
|
32
|
+
|
|
33
|
+
- standard black/white QR Code
|
|
34
|
+
- HCC2D4 with 4 colours and 2 bits per data module
|
|
35
|
+
- HCC2D8 with 8 colours and 3 bits per data module
|
|
36
|
+
- error-correction levels `L`, `M`, `Q`, and `H`
|
|
37
|
+
- versions `1..40`, or automatic selection
|
|
38
|
+
- screen-oriented Model 1 and print-oriented Model 2 palettes
|
|
39
|
+
- custom palettes through the JavaScript API, with normative black/white anchors
|
|
40
|
+
- raw payloads and optional HCC2DF file wrapping
|
|
41
|
+
- indexed PNG output
|
|
42
|
+
- importable modern ECMAScript module (ESM) API
|
|
43
|
+
- command-line interface for text and binary files
|
|
44
|
+
- no npm runtime dependencies
|
|
45
|
+
|
|
46
|
+
HCC2D16 is not included because it is not part of HCC2D Code Specification
|
|
47
|
+
0.9.0 or the public C and Python reference encoders 0.9.0.
|
|
48
|
+
|
|
49
|
+
## Requirements
|
|
50
|
+
|
|
51
|
+
- Node.js 22 or later
|
|
52
|
+
- npm 10 or later for installation and package management
|
|
53
|
+
|
|
54
|
+
Continuous integration covers the supported Node.js 22 and 24 LTS lines and
|
|
55
|
+
Node.js 26 Current. Development and release automation use npm 12.2.1.
|
|
56
|
+
|
|
57
|
+
The package uses only Node.js standard-library modules. There are no runtime
|
|
58
|
+
dependencies, native npm add-ons, post-install scripts, downloads, or
|
|
59
|
+
telemetry.
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
Install the release candidate into a project:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install hcc2d-encoder@next
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Install the CLI globally:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm install --global hcc2d-encoder@next
|
|
73
|
+
hcc2d-encoder --help
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Run the CLI without a permanent global installation:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npx hcc2d-encoder@next --help
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
For local development, install from a clone:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm install
|
|
86
|
+
npm link
|
|
87
|
+
hcc2d-encoder --help
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## JavaScript API
|
|
91
|
+
|
|
92
|
+
### Generate an HCC2D4 PNG
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
import { encodeHcc2d, writePng } from "hcc2d-encoder";
|
|
96
|
+
|
|
97
|
+
const payload = new TextEncoder().encode("hello");
|
|
98
|
+
const symbol = encodeHcc2d(payload, {
|
|
99
|
+
mode: "hcc2d4",
|
|
100
|
+
ecLevel: "Q",
|
|
101
|
+
version: 0,
|
|
102
|
+
scale: 12,
|
|
103
|
+
quietZone: 4,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
writePng("hello.png", symbol);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Generate an HCC2D8 PNG in memory
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
import { PALETTE_8_MODEL2, encodeHcc2d } from "hcc2d-encoder";
|
|
113
|
+
|
|
114
|
+
const symbol = encodeHcc2d(Buffer.from("Batch=2026-06-16;Unit=004271"), {
|
|
115
|
+
mode: "hcc2d8",
|
|
116
|
+
palette: PALETTE_8_MODEL2,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const png = symbol.toPng(); // Node.js Buffer
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Generate a standard QR Code
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
import { encodeQr } from "hcc2d-encoder";
|
|
126
|
+
|
|
127
|
+
const symbol = encodeQr(Buffer.from("https://hcc2d.com/"), {
|
|
128
|
+
ecLevel: "Q",
|
|
129
|
+
});
|
|
130
|
+
const png = symbol.toPng();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Wrap a file in HCC2DF
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
import { readFileSync } from "node:fs";
|
|
137
|
+
import { buildHcc2dfPayload, encodeHcc2d } from "hcc2d-encoder";
|
|
138
|
+
|
|
139
|
+
const wrapped = buildHcc2dfPayload("report.pdf", readFileSync("report.pdf"));
|
|
140
|
+
const symbol = encodeHcc2d(wrapped, { mode: "hcc2d8", ecLevel: "L" });
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The encoding functions accept `Buffer`, `Uint8Array`, or `ArrayBuffer`. They
|
|
144
|
+
return an `EncodedSymbol` with these public properties:
|
|
145
|
+
|
|
146
|
+
- `mode`
|
|
147
|
+
- `ecLevel`
|
|
148
|
+
- `version`
|
|
149
|
+
- `innerDimension`
|
|
150
|
+
- `fullDimension`
|
|
151
|
+
- `maskPattern`
|
|
152
|
+
- `palette`
|
|
153
|
+
- `pixels`
|
|
154
|
+
- `width`
|
|
155
|
+
- `height`
|
|
156
|
+
|
|
157
|
+
Call `symbol.toPng()` to obtain PNG bytes or `writePng(path, symbol)` to write
|
|
158
|
+
the PNG directly.
|
|
159
|
+
|
|
160
|
+
## Command-line usage
|
|
161
|
+
|
|
162
|
+
Show the complete help and legal notice:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
hcc2d-encoder --help
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Generate a standard QR Code containing raw UTF-8 text:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
hcc2d-encoder --text "https://hcc2d.com/spec" \
|
|
172
|
+
--mode qr --file-format raw qr-spec-url.png
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Generate an HCC2D4 symbol containing raw text bytes:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
hcc2d-encoder --text "Batch=2026-06-16;Line=A3;Unit=004271" \
|
|
179
|
+
--mode hcc2d4 --file-format raw hcc2d4-label.png
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Generate an HCC2D8 symbol carrying a file in an HCC2DF container:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
hcc2d-encoder --input-file report.pdf --mode hcc2d8 \
|
|
186
|
+
--file-format hcc2df --ec-level L hcc2d8-report.png
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Defaults are HCC2D4, EC level Q, automatic version selection, 12 pixels per
|
|
190
|
+
module, a 4-module quiet zone, Model 1 palette, and HCC2DF wrapping.
|
|
191
|
+
|
|
192
|
+
### Raw versus HCC2DF
|
|
193
|
+
|
|
194
|
+
Use `raw` when the bytes are already the complete payload and filename
|
|
195
|
+
metadata is unnecessary. This minimizes overhead.
|
|
196
|
+
|
|
197
|
+
Use `hcc2df` for file-oriented payloads. It preserves the basename and applies
|
|
198
|
+
zlib compression only when the content is at least 128 bytes and the compressed
|
|
199
|
+
representation is strictly smaller than 90% of the original size.
|
|
200
|
+
|
|
201
|
+
## Compatibility and validation
|
|
202
|
+
|
|
203
|
+
The JavaScript implementation is validated against both public reference
|
|
204
|
+
encoders. The forced-version matrix covers:
|
|
205
|
+
|
|
206
|
+
- all versions from 1 through 40
|
|
207
|
+
- QR, HCC2D4, and HCC2D8
|
|
208
|
+
- EC levels L, M, Q, and H
|
|
209
|
+
- Model 1 and Model 2 where applicable
|
|
210
|
+
- 800 structural combinations using a minimal payload
|
|
211
|
+
|
|
212
|
+
For every case, the comparison verifies identical PNG dimensions, palette
|
|
213
|
+
entries, and decompressed indexed pixels across JavaScript, C, and Python.
|
|
214
|
+
Compressed IDAT bytes are intentionally not required to match because different
|
|
215
|
+
zlib versions can produce different lossless streams for identical pixels.
|
|
216
|
+
|
|
217
|
+
An additional 42 binary-payload cases verify automatic version selection,
|
|
218
|
+
multi-block symbols, and the exact capacity boundary at representative
|
|
219
|
+
versions 1, 10, 27, and 40. Twelve corresponding overflow cases verify that
|
|
220
|
+
all three encoders reject the first byte beyond the supported capacity. The
|
|
221
|
+
complete reference suite therefore compares 842 generated PNGs and 12 exact
|
|
222
|
+
rejection boundaries.
|
|
223
|
+
|
|
224
|
+
Run the normal test suite:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
npm test
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
When sibling clones of the C and Python repositories are available, run the
|
|
231
|
+
full cross-implementation comparison:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
npm run test:reference
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Override their locations when required:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
HCC2D_C_REFERENCE_DIR=/path/to/hcc2d-cli-c-encoder \
|
|
241
|
+
HCC2D_PYTHON_REFERENCE_DIR=/path/to/hcc2d-cli-python-encoder \
|
|
242
|
+
npm run test:reference
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
GitHub Actions tests Node.js 22, 24, and 26. A separate packaging job
|
|
246
|
+
builds the exact npm tarball, installs it into a clean project, invokes its
|
|
247
|
+
published CLI entry point, and verifies a generated PNG.
|
|
248
|
+
|
|
249
|
+
## Architecture and independence
|
|
250
|
+
|
|
251
|
+
The JavaScript implementation independently performs:
|
|
252
|
+
|
|
253
|
+
1. byte-mode framing and capacity selection;
|
|
254
|
+
2. Reed-Solomon error-correction generation and interleaving;
|
|
255
|
+
3. QR-compatible function-pattern and data-module placement;
|
|
256
|
+
4. mask selection;
|
|
257
|
+
5. HCC2D plane construction and Color Palette Pattern rendering;
|
|
258
|
+
6. indexed raster generation and PNG serialization;
|
|
259
|
+
7. optional HCC2DF filename wrapping and compression.
|
|
260
|
+
|
|
261
|
+
The package does not execute the C or Python implementations. Those projects
|
|
262
|
+
are used only by the optional development-time reference comparison.
|
|
263
|
+
|
|
264
|
+
The current npm package targets Node.js. For a fully client-side browser build,
|
|
265
|
+
use the official HCC2D WebAssembly encoder linked above; it runs locally in a
|
|
266
|
+
Web Worker and does not upload payloads.
|
|
267
|
+
|
|
268
|
+
## Building and inspecting the npm package
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
npm ci
|
|
272
|
+
npm run check
|
|
273
|
+
npm pack
|
|
274
|
+
npm install --global ./hcc2d-encoder-0.9.0-rc.1.tgz
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
`npm pack --dry-run` shows every file that would be published. The `files`
|
|
278
|
+
allow-list in `package.json` prevents tests, workflows, local output, and
|
|
279
|
+
development scripts from entering the production package.
|
|
280
|
+
|
|
281
|
+
## Security and privacy
|
|
282
|
+
|
|
283
|
+
Encoding is local. The package contains no network requests, analytics,
|
|
284
|
+
advertising, dynamic code downloads, installation hooks, or credential access.
|
|
285
|
+
Input data is read only when explicitly supplied through the API or CLI.
|
|
286
|
+
|
|
287
|
+
See [SECURITY.md](SECURITY.md) for responsible vulnerability reporting.
|
|
288
|
+
|
|
289
|
+
## Publication
|
|
290
|
+
|
|
291
|
+
npm releases are immutable. Production publication is performed from a tagged
|
|
292
|
+
GitHub release using npm Trusted Publishing with short-lived OIDC credentials.
|
|
293
|
+
No long-lived npm token is stored in the repository. See
|
|
294
|
+
[PUBLISHING.md](PUBLISHING.md) for the complete release checklist.
|
|
295
|
+
|
|
296
|
+
## License and warranty
|
|
297
|
+
|
|
298
|
+
Copyright 2010-2026 Marco Querini.
|
|
299
|
+
|
|
300
|
+
SPDX-License-Identifier: Apache-2.0. See [LICENSE](LICENSE).
|
|
301
|
+
|
|
302
|
+
This software is provided "as is", without warranties or conditions of any
|
|
303
|
+
kind. Use is entirely at your own risk. The author assumes no responsibility
|
|
304
|
+
for unreadable or non-decodable codes, failed scans, data loss, or other
|
|
305
|
+
consequences arising from its use.
|
|
306
|
+
|
|
307
|
+
## Notice
|
|
308
|
+
|
|
309
|
+
The views expressed in connection with the HCC2D Code Specification, HCC2D
|
|
310
|
+
applications, and HCC2D source code are solely those of the author and do not
|
|
311
|
+
necessarily reflect the official position of any institution, organization,
|
|
312
|
+
or employer with which the author is or has been affiliated.
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hcc2d-encoder",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.9.0-rc.1",
|
|
4
|
+
"description": "Pure JavaScript reference encoder for QR, HCC2D4, and HCC2D8 symbols",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./src/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.js"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"hcc2d-encoder": "bin/hcc2d-encoder.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin/",
|
|
16
|
+
"src/",
|
|
17
|
+
"CHANGELOG.md",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "node --test",
|
|
23
|
+
"test:reference": "node scripts/compare-reference.mjs",
|
|
24
|
+
"check": "npm test && npm pack --dry-run",
|
|
25
|
+
"prepublishOnly": "npm run check"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22",
|
|
29
|
+
"npm": ">=10"
|
|
30
|
+
},
|
|
31
|
+
"packageManager": "npm@12.2.1",
|
|
32
|
+
"keywords": [
|
|
33
|
+
"hcc2d",
|
|
34
|
+
"qr-code",
|
|
35
|
+
"barcode",
|
|
36
|
+
"encoder",
|
|
37
|
+
"color-barcode"
|
|
38
|
+
],
|
|
39
|
+
"author": "Marco Querini",
|
|
40
|
+
"license": "Apache-2.0",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/marco-querini/hcc2d-cli-javascript-encoder.git"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/marco-querini/hcc2d-cli-javascript-encoder/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://hcc2d.com/en/",
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public",
|
|
51
|
+
"provenance": true
|
|
52
|
+
}
|
|
53
|
+
}
|