@molecule/app-qr-code-react 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +115 -0
- package/README.md +193 -0
- package/dist/QrCode.d.ts +72 -0
- package/dist/QrCode.d.ts.map +1 -0
- package/dist/QrCode.js +67 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
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,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising 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
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-08-04T00:40:51.605Z
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
# @molecule/app-qr-code-react
|
|
10
|
+
|
|
11
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
+
|
|
15
|
+
Render a QR code as a crisp scalable SVG with optional center logo.
|
|
16
|
+
|
|
17
|
+
Used across coupon-deals-platform (redemption codes), restaurant-ordering
|
|
18
|
+
(table tokens), event-ticketing (tickets), and voting-polling (ballot
|
|
19
|
+
links). Encoding is delegated to the lightweight `qrcode-generator`
|
|
20
|
+
library; rendering is a single SVG `<path>` of horizontal-run rectangles
|
|
21
|
+
(much smaller DOM than per-module rects) plus an optional `<image>`
|
|
22
|
+
overlay for a center logo.
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { QrCode } from '@molecule/app-qr-code-react'
|
|
28
|
+
|
|
29
|
+
// Simple link
|
|
30
|
+
<QrCode value="https://example.com/redeem/ABC123" />
|
|
31
|
+
|
|
32
|
+
// Larger code with high error-correction and a center logo
|
|
33
|
+
<QrCode
|
|
34
|
+
value="https://example.com/ticket/42"
|
|
35
|
+
size={320}
|
|
36
|
+
errorCorrection="H"
|
|
37
|
+
logo={{ src: '/logo.png', alt: 'Brand' }}
|
|
38
|
+
/>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Type
|
|
42
|
+
|
|
43
|
+
`feature`
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install @molecule/app-qr-code-react @molecule/app-react @molecule/app-ui qrcode-generator react
|
|
49
|
+
npm install -D @types/react
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## API
|
|
53
|
+
|
|
54
|
+
### Interfaces
|
|
55
|
+
|
|
56
|
+
#### `QrCodeLogo`
|
|
57
|
+
|
|
58
|
+
Optional center-logo overlay descriptor.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
interface QrCodeLogo {
|
|
62
|
+
/** Image URL or data URI to render in the center of the QR code. */
|
|
63
|
+
src: string
|
|
64
|
+
/**
|
|
65
|
+
* Pixel size of the (square) logo. Defaults to 20% of `size`. Caller is
|
|
66
|
+
* responsible for keeping the logo small enough that the code still scans;
|
|
67
|
+
* use `errorCorrection='H'` when overlaying a logo.
|
|
68
|
+
*/
|
|
69
|
+
size?: number
|
|
70
|
+
/** Alt text for the logo image (decorative if omitted). */
|
|
71
|
+
alt?: string
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### `QrCodeProps`
|
|
76
|
+
|
|
77
|
+
QrCode component props.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
interface QrCodeProps {
|
|
81
|
+
/** String value to encode (URL, ticket id, ballot link, etc.). */
|
|
82
|
+
value: string
|
|
83
|
+
/** Output SVG width/height in pixels. Defaults to 200. */
|
|
84
|
+
size?: number
|
|
85
|
+
/** Error-correction level. Defaults to `'M'`. Use `'H'` if overlaying a logo. */
|
|
86
|
+
errorCorrection?: QrErrorCorrectionLevel
|
|
87
|
+
/** Foreground (dark module) color. Defaults to `'#000'`. */
|
|
88
|
+
fgColor?: string
|
|
89
|
+
/** Background color. Defaults to `'#fff'`. */
|
|
90
|
+
bgColor?: string
|
|
91
|
+
/** Quiet-zone margin in modules. Defaults to 2. */
|
|
92
|
+
margin?: number
|
|
93
|
+
/** Optional center logo overlay. */
|
|
94
|
+
logo?: QrCodeLogo
|
|
95
|
+
/**
|
|
96
|
+
* Override the auto-generated `aria-label`. The default is the translated
|
|
97
|
+
* `qrCode.aria.label` key with `{{value}}` interpolated.
|
|
98
|
+
*/
|
|
99
|
+
ariaLabel?: string
|
|
100
|
+
/** Extra classes merged onto the SVG root via `cm.cn`. */
|
|
101
|
+
className?: string
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Types
|
|
106
|
+
|
|
107
|
+
#### `QrErrorCorrectionLevel`
|
|
108
|
+
|
|
109
|
+
QR error-correction level. `L` ≈ 7%, `M` ≈ 15%, `Q` ≈ 25%, `H` ≈ 30%.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
type QrErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H'
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Functions
|
|
116
|
+
|
|
117
|
+
#### `buildQrPath(qr, margin)`
|
|
118
|
+
|
|
119
|
+
Build the contiguous-run path data for the dark modules in a QR matrix. We
|
|
120
|
+
collapse horizontal runs of dark modules into a single `M h Z` instruction
|
|
121
|
+
per run, which is dramatically smaller than per-module rectangles while
|
|
122
|
+
still rendering pixel-perfect.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
function buildQrPath(
|
|
126
|
+
qr: { getModuleCount: () => number; isDark: (row: number, col: number) => boolean },
|
|
127
|
+
margin: number,
|
|
128
|
+
): string
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
- `qr` — The fully-built QR code object.
|
|
132
|
+
- `margin` — Quiet-zone margin in modules.
|
|
133
|
+
|
|
134
|
+
**Returns:** SVG path `d` attribute string.
|
|
135
|
+
|
|
136
|
+
#### `QrCode(props)`
|
|
137
|
+
|
|
138
|
+
Render a QR code as a crisp, scalable SVG. Accepts any string value
|
|
139
|
+
(URL, redemption code, ticket token, ballot link, etc.) and optionally
|
|
140
|
+
overlays a small center logo.
|
|
141
|
+
|
|
142
|
+
Styling routes through `@molecule/app-ui`'s `getClassMap()` for the
|
|
143
|
+
container; the only inline color attributes are the SVG `fill`s on the
|
|
144
|
+
background rect and the dark-modules path (real SVG attributes — not
|
|
145
|
+
Tailwind classes). Translations come from `@molecule/app-locales-qr-code`.
|
|
146
|
+
|
|
147
|
+
Used by coupon-deals-platform (redemption codes), restaurant-ordering
|
|
148
|
+
(table tokens), event-ticketing (tickets), voting-polling (ballot links).
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
function QrCode({
|
|
152
|
+
value,
|
|
153
|
+
size = 200,
|
|
154
|
+
errorCorrection = 'M',
|
|
155
|
+
fgColor = '#000',
|
|
156
|
+
bgColor = '#fff',
|
|
157
|
+
margin = 2,
|
|
158
|
+
logo,
|
|
159
|
+
ariaLabel,
|
|
160
|
+
className,
|
|
161
|
+
}: QrCodeProps): JSX.Element
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
- `props` — Component props.
|
|
165
|
+
|
|
166
|
+
**Returns:** The QR code SVG element.
|
|
167
|
+
|
|
168
|
+
## Injection Notes
|
|
169
|
+
|
|
170
|
+
### Requirements
|
|
171
|
+
|
|
172
|
+
Peer dependencies:
|
|
173
|
+
|
|
174
|
+
- `@molecule/app-react` ^1.0.0
|
|
175
|
+
- `@molecule/app-ui` ^1.0.0
|
|
176
|
+
- `react` ^18.0.0 || ^19.0.0
|
|
177
|
+
|
|
178
|
+
### Runtime Dependencies
|
|
179
|
+
|
|
180
|
+
- `@molecule/app-react`
|
|
181
|
+
- `@molecule/app-ui`
|
|
182
|
+
- `qrcode-generator`
|
|
183
|
+
- `react`
|
|
184
|
+
|
|
185
|
+
Center-logo overlay reduces scannability — always pair it with
|
|
186
|
+
`errorCorrection='H'` and keep the logo at or below ~20% of the QR size.
|
|
187
|
+
Container styling routes through `@molecule/app-ui`'s `getClassMap()`;
|
|
188
|
+
the only inline values are SVG `fill` color attributes (real SVG attrs,
|
|
189
|
+
not Tailwind). Translations come from `@molecule/app-locales-qr-code`.
|
|
190
|
+
|
|
191
|
+
## Translations
|
|
192
|
+
|
|
193
|
+
Translation strings are provided by `@molecule/app-locales-qr-code`.
|
package/dist/QrCode.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { JSX } from 'react';
|
|
2
|
+
/** QR error-correction level. `L` ≈ 7%, `M` ≈ 15%, `Q` ≈ 25%, `H` ≈ 30%. */
|
|
3
|
+
export type QrErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H';
|
|
4
|
+
/** Optional center-logo overlay descriptor. */
|
|
5
|
+
export interface QrCodeLogo {
|
|
6
|
+
/** Image URL or data URI to render in the center of the QR code. */
|
|
7
|
+
src: string;
|
|
8
|
+
/**
|
|
9
|
+
* Pixel size of the (square) logo. Defaults to 20% of `size`. Caller is
|
|
10
|
+
* responsible for keeping the logo small enough that the code still scans;
|
|
11
|
+
* use `errorCorrection='H'` when overlaying a logo.
|
|
12
|
+
*/
|
|
13
|
+
size?: number;
|
|
14
|
+
/** Alt text for the logo image (decorative if omitted). */
|
|
15
|
+
alt?: string;
|
|
16
|
+
}
|
|
17
|
+
/** QrCode component props. */
|
|
18
|
+
export interface QrCodeProps {
|
|
19
|
+
/** String value to encode (URL, ticket id, ballot link, etc.). */
|
|
20
|
+
value: string;
|
|
21
|
+
/** Output SVG width/height in pixels. Defaults to 200. */
|
|
22
|
+
size?: number;
|
|
23
|
+
/** Error-correction level. Defaults to `'M'`. Use `'H'` if overlaying a logo. */
|
|
24
|
+
errorCorrection?: QrErrorCorrectionLevel;
|
|
25
|
+
/** Foreground (dark module) color. Defaults to `'#000'`. */
|
|
26
|
+
fgColor?: string;
|
|
27
|
+
/** Background color. Defaults to `'#fff'`. */
|
|
28
|
+
bgColor?: string;
|
|
29
|
+
/** Quiet-zone margin in modules. Defaults to 2. */
|
|
30
|
+
margin?: number;
|
|
31
|
+
/** Optional center logo overlay. */
|
|
32
|
+
logo?: QrCodeLogo;
|
|
33
|
+
/**
|
|
34
|
+
* Override the auto-generated `aria-label`. The default is the translated
|
|
35
|
+
* `qrCode.aria.label` key with `{{value}}` interpolated.
|
|
36
|
+
*/
|
|
37
|
+
ariaLabel?: string;
|
|
38
|
+
/** Extra classes merged onto the SVG root via `cm.cn`. */
|
|
39
|
+
className?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build the contiguous-run path data for the dark modules in a QR matrix. We
|
|
43
|
+
* collapse horizontal runs of dark modules into a single `M h Z` instruction
|
|
44
|
+
* per run, which is dramatically smaller than per-module rectangles while
|
|
45
|
+
* still rendering pixel-perfect.
|
|
46
|
+
*
|
|
47
|
+
* @param qr - The fully-built QR code object.
|
|
48
|
+
* @param margin - Quiet-zone margin in modules.
|
|
49
|
+
* @returns SVG path `d` attribute string.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildQrPath(qr: {
|
|
52
|
+
getModuleCount: () => number;
|
|
53
|
+
isDark: (row: number, col: number) => boolean;
|
|
54
|
+
}, margin: number): string;
|
|
55
|
+
/**
|
|
56
|
+
* Render a QR code as a crisp, scalable SVG. Accepts any string value
|
|
57
|
+
* (URL, redemption code, ticket token, ballot link, etc.) and optionally
|
|
58
|
+
* overlays a small center logo.
|
|
59
|
+
*
|
|
60
|
+
* Styling routes through `@molecule/app-ui`'s `getClassMap()` for the
|
|
61
|
+
* container; the only inline color attributes are the SVG `fill`s on the
|
|
62
|
+
* background rect and the dark-modules path (real SVG attributes — not
|
|
63
|
+
* Tailwind classes). Translations come from `@molecule/app-locales-qr-code`.
|
|
64
|
+
*
|
|
65
|
+
* Used by coupon-deals-platform (redemption codes), restaurant-ordering
|
|
66
|
+
* (table tokens), event-ticketing (tickets), voting-polling (ballot links).
|
|
67
|
+
*
|
|
68
|
+
* @param props - Component props.
|
|
69
|
+
* @returns The QR code SVG element.
|
|
70
|
+
*/
|
|
71
|
+
export declare function QrCode({ value, size, errorCorrection, fgColor, bgColor, margin, logo, ariaLabel, className, }: QrCodeProps): JSX.Element;
|
|
72
|
+
//# sourceMappingURL=QrCode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QrCode.d.ts","sourceRoot":"","sources":["../src/QrCode.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAKhC,4EAA4E;AAC5E,MAAM,MAAM,sBAAsB,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAE1D,+CAA+C;AAC/C,MAAM,WAAW,UAAU;IACzB,oEAAoE;IACpE,GAAG,EAAE,MAAM,CAAA;IACX;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,8BAA8B;AAC9B,MAAM,WAAW,WAAW;IAC1B,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAA;IACb,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iFAAiF;IACjF,eAAe,CAAC,EAAE,sBAAsB,CAAA;IACxC,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,oCAAoC;IACpC,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,EAAE,EAAE;IAAE,cAAc,EAAE,MAAM,MAAM,CAAC;IAAC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,EACnF,MAAM,EAAE,MAAM,GACb,MAAM,CAiBR;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,EACrB,KAAK,EACL,IAAU,EACV,eAAqB,EACrB,OAAgB,EAChB,OAAgB,EAChB,MAAU,EACV,IAAI,EACJ,SAAS,EACT,SAAS,GACV,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CAuD3B"}
|
package/dist/QrCode.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import qrcode from 'qrcode-generator';
|
|
3
|
+
import { useTranslation } from '@molecule/app-react';
|
|
4
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
5
|
+
/**
|
|
6
|
+
* Build the contiguous-run path data for the dark modules in a QR matrix. We
|
|
7
|
+
* collapse horizontal runs of dark modules into a single `M h Z` instruction
|
|
8
|
+
* per run, which is dramatically smaller than per-module rectangles while
|
|
9
|
+
* still rendering pixel-perfect.
|
|
10
|
+
*
|
|
11
|
+
* @param qr - The fully-built QR code object.
|
|
12
|
+
* @param margin - Quiet-zone margin in modules.
|
|
13
|
+
* @returns SVG path `d` attribute string.
|
|
14
|
+
*/
|
|
15
|
+
export function buildQrPath(qr, margin) {
|
|
16
|
+
const moduleCount = qr.getModuleCount();
|
|
17
|
+
const segments = [];
|
|
18
|
+
for (let row = 0; row < moduleCount; row++) {
|
|
19
|
+
let col = 0;
|
|
20
|
+
while (col < moduleCount) {
|
|
21
|
+
if (qr.isDark(row, col)) {
|
|
22
|
+
const runStart = col;
|
|
23
|
+
while (col < moduleCount && qr.isDark(row, col))
|
|
24
|
+
col++;
|
|
25
|
+
const runLen = col - runStart;
|
|
26
|
+
segments.push(`M${runStart + margin} ${row + margin}h${runLen}v1h-${runLen}z`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
col++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return segments.join('');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Render a QR code as a crisp, scalable SVG. Accepts any string value
|
|
37
|
+
* (URL, redemption code, ticket token, ballot link, etc.) and optionally
|
|
38
|
+
* overlays a small center logo.
|
|
39
|
+
*
|
|
40
|
+
* Styling routes through `@molecule/app-ui`'s `getClassMap()` for the
|
|
41
|
+
* container; the only inline color attributes are the SVG `fill`s on the
|
|
42
|
+
* background rect and the dark-modules path (real SVG attributes — not
|
|
43
|
+
* Tailwind classes). Translations come from `@molecule/app-locales-qr-code`.
|
|
44
|
+
*
|
|
45
|
+
* Used by coupon-deals-platform (redemption codes), restaurant-ordering
|
|
46
|
+
* (table tokens), event-ticketing (tickets), voting-polling (ballot links).
|
|
47
|
+
*
|
|
48
|
+
* @param props - Component props.
|
|
49
|
+
* @returns The QR code SVG element.
|
|
50
|
+
*/
|
|
51
|
+
export function QrCode({ value, size = 200, errorCorrection = 'M', fgColor = '#000', bgColor = '#fff', margin = 2, logo, ariaLabel, className, }) {
|
|
52
|
+
const cm = getClassMap();
|
|
53
|
+
const { t } = useTranslation();
|
|
54
|
+
// typeNumber=0 lets the library pick the smallest type that fits.
|
|
55
|
+
const qr = qrcode(0, errorCorrection);
|
|
56
|
+
qr.addData(value);
|
|
57
|
+
qr.make();
|
|
58
|
+
const moduleCount = qr.getModuleCount();
|
|
59
|
+
const totalModules = moduleCount + margin * 2;
|
|
60
|
+
const pathData = buildQrPath(qr, margin);
|
|
61
|
+
const label = ariaLabel ?? t('qrCode.aria.label', { value }, { defaultValue: 'QR code for {{value}}' });
|
|
62
|
+
// Logo geometry computed in viewBox (module) units so it scales with the
|
|
63
|
+
// QR matrix regardless of `size`. Default to ~20% of the matrix.
|
|
64
|
+
const logoModuleSize = logo?.size ? (logo.size / size) * totalModules : totalModules * 0.2;
|
|
65
|
+
const logoOffset = (totalModules - logoModuleSize) / 2;
|
|
66
|
+
return (_jsxs("svg", { width: size, height: size, viewBox: `0 0 ${totalModules} ${totalModules}`, role: "img", "aria-label": label, "data-mol-id": "qr-code", className: cm.cn(className), shapeRendering: "crispEdges", children: [_jsx("rect", { x: 0, y: 0, width: totalModules, height: totalModules, fill: bgColor, "data-mol-id": "qr-code-bg" }), _jsx("path", { d: pathData, fill: fgColor, "data-mol-id": "qr-code-modules" }), logo ? (_jsx("image", { href: logo.src, x: logoOffset, y: logoOffset, width: logoModuleSize, height: logoModuleSize, preserveAspectRatio: "xMidYMid meet", "data-mol-id": "qr-code-logo", "aria-label": logo.alt })) : null] }));
|
|
67
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render a QR code as a crisp scalable SVG with optional center logo.
|
|
3
|
+
*
|
|
4
|
+
* Used across coupon-deals-platform (redemption codes), restaurant-ordering
|
|
5
|
+
* (table tokens), event-ticketing (tickets), and voting-polling (ballot
|
|
6
|
+
* links). Encoding is delegated to the lightweight `qrcode-generator`
|
|
7
|
+
* library; rendering is a single SVG `<path>` of horizontal-run rectangles
|
|
8
|
+
* (much smaller DOM than per-module rects) plus an optional `<image>`
|
|
9
|
+
* overlay for a center logo.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { QrCode } from '@molecule/app-qr-code-react'
|
|
14
|
+
*
|
|
15
|
+
* // Simple link
|
|
16
|
+
* <QrCode value="https://example.com/redeem/ABC123" />
|
|
17
|
+
*
|
|
18
|
+
* // Larger code with high error-correction and a center logo
|
|
19
|
+
* <QrCode
|
|
20
|
+
* value="https://example.com/ticket/42"
|
|
21
|
+
* size={320}
|
|
22
|
+
* errorCorrection="H"
|
|
23
|
+
* logo={{ src: '/logo.png', alt: 'Brand' }}
|
|
24
|
+
* />
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* Center-logo overlay reduces scannability — always pair it with
|
|
29
|
+
* `errorCorrection='H'` and keep the logo at or below ~20% of the QR size.
|
|
30
|
+
* Container styling routes through `@molecule/app-ui`'s `getClassMap()`;
|
|
31
|
+
* the only inline values are SVG `fill` color attributes (real SVG attrs,
|
|
32
|
+
* not Tailwind). Translations come from `@molecule/app-locales-qr-code`.
|
|
33
|
+
*
|
|
34
|
+
* @module
|
|
35
|
+
*/
|
|
36
|
+
export * from './QrCode.js';
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,cAAc,aAAa,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render a QR code as a crisp scalable SVG with optional center logo.
|
|
3
|
+
*
|
|
4
|
+
* Used across coupon-deals-platform (redemption codes), restaurant-ordering
|
|
5
|
+
* (table tokens), event-ticketing (tickets), and voting-polling (ballot
|
|
6
|
+
* links). Encoding is delegated to the lightweight `qrcode-generator`
|
|
7
|
+
* library; rendering is a single SVG `<path>` of horizontal-run rectangles
|
|
8
|
+
* (much smaller DOM than per-module rects) plus an optional `<image>`
|
|
9
|
+
* overlay for a center logo.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { QrCode } from '@molecule/app-qr-code-react'
|
|
14
|
+
*
|
|
15
|
+
* // Simple link
|
|
16
|
+
* <QrCode value="https://example.com/redeem/ABC123" />
|
|
17
|
+
*
|
|
18
|
+
* // Larger code with high error-correction and a center logo
|
|
19
|
+
* <QrCode
|
|
20
|
+
* value="https://example.com/ticket/42"
|
|
21
|
+
* size={320}
|
|
22
|
+
* errorCorrection="H"
|
|
23
|
+
* logo={{ src: '/logo.png', alt: 'Brand' }}
|
|
24
|
+
* />
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* Center-logo overlay reduces scannability — always pair it with
|
|
29
|
+
* `errorCorrection='H'` and keep the logo at or below ~20% of the QR size.
|
|
30
|
+
* Container styling routes through `@molecule/app-ui`'s `getClassMap()`;
|
|
31
|
+
* the only inline values are SVG `fill` color attributes (real SVG attrs,
|
|
32
|
+
* not Tailwind). Translations come from `@molecule/app-locales-qr-code`.
|
|
33
|
+
*
|
|
34
|
+
* @module
|
|
35
|
+
*/
|
|
36
|
+
export * from './QrCode.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/app-qr-code-react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Render a QR code as crisp scalable SVG with optional center logo",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"molecule",
|
|
25
|
+
"qr-code",
|
|
26
|
+
"qrcode",
|
|
27
|
+
"react"
|
|
28
|
+
],
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"qrcode-generator": "2.0.4"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@molecule/app-react": "^1.0.0",
|
|
35
|
+
"@molecule/app-ui": "^1.0.0",
|
|
36
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@molecule/app-i18n": "1.0.0",
|
|
40
|
+
"@molecule/app-react": "1.0.0",
|
|
41
|
+
"@molecule/app-ui": "1.0.0",
|
|
42
|
+
"@testing-library/react": "16.3.2",
|
|
43
|
+
"@types/node": "26.1.2",
|
|
44
|
+
"@types/react": "19.2.17",
|
|
45
|
+
"jsdom": "30.0.1",
|
|
46
|
+
"react": "19.2.8",
|
|
47
|
+
"react-dom": "19.2.8",
|
|
48
|
+
"typescript": "6.0.3",
|
|
49
|
+
"vitest": "4.1.10"
|
|
50
|
+
}
|
|
51
|
+
}
|