qrdx 0.0.59 → 0.0.60
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 +3 -3
- package/dist/core.js +7 -7
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +7 -7
- package/dist/core.mjs.map +1 -1
- package/dist/element.browser.mjs +6 -6
- package/dist/element.browser.mjs.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/index.mjs.map +1 -1
- package/dist/qr-code-canvas.js +1 -1
- package/dist/qr-code-canvas.js.map +1 -1
- package/dist/qr-code-canvas.mjs +1 -1
- package/dist/qr-code-canvas.mjs.map +1 -1
- package/dist/schemas.js +1 -1
- package/dist/schemas.js.map +1 -1
- package/dist/schemas.mjs +1 -1
- package/dist/schemas.mjs.map +1 -1
- package/dist/src/corner-dot.d.ts.map +1 -1
- package/dist/src/corner-eye.d.ts.map +1 -1
- package/dist/src/engine.d.ts +1 -1
- package/dist/src/engine.d.ts.map +1 -1
- package/dist/src/looks.d.ts +45 -17
- package/dist/src/looks.d.ts.map +1 -1
- package/dist/src/scan-risk.d.ts.map +1 -1
- package/dist/src/scan-score.d.ts.map +1 -1
- package/dist/src/shapes.d.ts +19 -0
- package/dist/src/shapes.d.ts.map +1 -1
- package/dist/src/utils/oklab.d.ts +16 -0
- package/dist/src/utils/oklab.d.ts.map +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/types/constants.d.ts +40 -5
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/corner-dot.d.ts +11 -6
- package/dist/types/corner-dot.d.ts.map +1 -1
- package/dist/types/corner-eye.d.ts +21 -8
- package/dist/types/corner-eye.d.ts.map +1 -1
- package/dist/types/frame-spec.d.ts +1 -1
- package/dist/types/frame.d.ts +2 -2
- package/dist/types/image-pattern.d.ts +3 -3
- package/dist/types/image-pattern.d.ts.map +1 -1
- package/dist/types/index.js +2 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +2 -2
- package/dist/types/index.mjs.map +1 -1
- package/dist/types/plain.d.ts +1 -1
- package/dist/types/plain.d.ts.map +1 -1
- package/dist/types/qr.d.ts +96 -46
- package/dist/types/qr.d.ts.map +1 -1
- package/dist/vanilla.browser.mjs +29 -29
- package/dist/vanilla.browser.mjs.map +1 -1
- package/package.json +1 -1
- package/src/corner-dot.tsx +15 -0
- package/src/corner-eye.ts +163 -72
- package/src/engine.ts +4 -0
- package/src/looks.ts +272 -69
- package/src/scan-risk.ts +19 -3
- package/src/scan-score.ts +11 -1
- package/src/shapes.ts +123 -0
- package/src/utils/oklab.ts +93 -0
- package/src/utils.tsx +20 -4
- package/types/constants.ts +59 -3
- package/types/corner-dot.ts +17 -7
- package/types/corner-eye.ts +26 -8
- package/types/image-pattern.ts +11 -4
- package/types/plain.ts +4 -0
- package/types/qr.ts +5 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qrdx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
4
4
|
"description": "Customizable QR code generator for React and plain JavaScript: SVG and canvas rendering, dot and eye patterns, gradients, logos, frames, Logo QR and Image QR art, PNG/JPG/WebP/SVG/PDF/EPS export, a scan score and QR scanning.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"qr-code",
|
package/src/corner-dot.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import type { EyeCorner } from "./corner-eye";
|
|
|
5
5
|
import type { QRNode } from "./jsx/runtime";
|
|
6
6
|
import {
|
|
7
7
|
circlePath,
|
|
8
|
+
cushionPath,
|
|
8
9
|
heartPath,
|
|
9
10
|
polygonPath,
|
|
10
11
|
regularPolygon,
|
|
@@ -181,6 +182,20 @@ export function generateCornerDotPath(
|
|
|
181
182
|
return <path d={dots.join("")} />;
|
|
182
183
|
}
|
|
183
184
|
|
|
185
|
+
// The centre added after 0.0.57 is 3 modules wide on the row and the
|
|
186
|
+
// column through its centre, so the finder's 1:1:3:1:1 runs hold, and
|
|
187
|
+
// keeps nearly all of its corners. Centres with teeth, bumps, a pill
|
|
188
|
+
// outline, a round top, a pointed bottom or one big round corner all
|
|
189
|
+
// read like a circle centre: missed inside some eyes in sharp renders
|
|
190
|
+
// or at 9 px per module, so they were not kept; neither were a cut-corner
|
|
191
|
+
// and a bitten-corner square, which looked like the square centre.
|
|
192
|
+
case "cushion":
|
|
193
|
+
return (
|
|
194
|
+
<path
|
|
195
|
+
d={cushionPath(cx - radius, cy - radius, size, 0.6 * m, 0.15 * m)}
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
|
|
184
199
|
case "square":
|
|
185
200
|
return (
|
|
186
201
|
<rect
|
package/src/corner-eye.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { CornerEyePattern } from "../types/corner-eye";
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
cushionPath,
|
|
4
|
+
notchedRectPath,
|
|
5
|
+
octagonPoints,
|
|
4
6
|
polygonPath,
|
|
5
7
|
roundedRectPath,
|
|
8
|
+
scoopedRectPath,
|
|
9
|
+
shieldPath,
|
|
6
10
|
superellipsePoints,
|
|
7
11
|
} from "./shapes";
|
|
8
12
|
import { compact, roundTo } from "./utils/fmt";
|
|
@@ -31,24 +35,6 @@ function facingRadii(
|
|
|
31
35
|
) as Radii;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
function octagonPoints(
|
|
35
|
-
x: number,
|
|
36
|
-
y: number,
|
|
37
|
-
size: number,
|
|
38
|
-
cut: number
|
|
39
|
-
): Point[] {
|
|
40
|
-
return [
|
|
41
|
-
[x + cut, y],
|
|
42
|
-
[x + size - cut, y],
|
|
43
|
-
[x + size, y + cut],
|
|
44
|
-
[x + size, y + size - cut],
|
|
45
|
-
[x + size - cut, y + size],
|
|
46
|
-
[x + cut, y + size],
|
|
47
|
-
[x, y + size - cut],
|
|
48
|
-
[x, y + cut],
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
38
|
/**
|
|
53
39
|
* Chamfered ring: `cut` modules off each outer corner, the hole cut so the
|
|
54
40
|
* ring stays one module thick across the chamfer too.
|
|
@@ -129,38 +115,6 @@ function generateCornerSquirclePattern(
|
|
|
129
115
|
);
|
|
130
116
|
}
|
|
131
117
|
|
|
132
|
-
/**
|
|
133
|
-
* Rounded square whose sides pinch in slightly, like a cushion. Sides meet
|
|
134
|
-
* the corners tangentially, so the outline has no kinks.
|
|
135
|
-
*/
|
|
136
|
-
function cushionPath(
|
|
137
|
-
x: number,
|
|
138
|
-
y: number,
|
|
139
|
-
size: number,
|
|
140
|
-
radius: number,
|
|
141
|
-
pinch: number
|
|
142
|
-
): string {
|
|
143
|
-
const r = radius;
|
|
144
|
-
const mid = size / 2;
|
|
145
|
-
const pull = (mid - r) * 0.55;
|
|
146
|
-
const P = (px: number, py: number) => compact`${x + px} ${y + py}`;
|
|
147
|
-
return (
|
|
148
|
-
compact`M${P(r, 0)}` +
|
|
149
|
-
compact`C${P(r + pull, 0)} ${P(mid - pull, pinch)} ${P(mid, pinch)}` +
|
|
150
|
-
compact`C${P(mid + pull, pinch)} ${P(size - r - pull, 0)} ${P(size - r, 0)}` +
|
|
151
|
-
compact`A${r} ${r} 0 0 1 ${P(size, r)}` +
|
|
152
|
-
compact`C${P(size, r + pull)} ${P(size - pinch, mid - pull)} ${P(size - pinch, mid)}` +
|
|
153
|
-
compact`C${P(size - pinch, mid + pull)} ${P(size, size - r - pull)} ${P(size, size - r)}` +
|
|
154
|
-
compact`A${r} ${r} 0 0 1 ${P(size - r, size)}` +
|
|
155
|
-
compact`C${P(size - r - pull, size)} ${P(mid + pull, size - pinch)} ${P(mid, size - pinch)}` +
|
|
156
|
-
compact`C${P(mid - pull, size - pinch)} ${P(r + pull, size)} ${P(r, size)}` +
|
|
157
|
-
compact`A${r} ${r} 0 0 1 ${P(0, size - r)}` +
|
|
158
|
-
compact`C${P(0, size - r - pull)} ${P(pinch, mid + pull)} ${P(pinch, mid)}` +
|
|
159
|
-
compact`C${P(pinch, mid - pull)} ${P(0, r + pull)} ${P(0, r)}` +
|
|
160
|
-
compact`A${r} ${r} 0 0 1 ${P(r, 0)}Z`
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
118
|
function generateCornerCushionPattern(
|
|
165
119
|
offsetX: number,
|
|
166
120
|
offsetY: number,
|
|
@@ -175,27 +129,6 @@ function generateCornerCushionPattern(
|
|
|
175
129
|
);
|
|
176
130
|
}
|
|
177
131
|
|
|
178
|
-
/** Shield: flat top, straight sides, curving to a point at the bottom. */
|
|
179
|
-
function shieldPath(
|
|
180
|
-
x: number,
|
|
181
|
-
y: number,
|
|
182
|
-
size: number,
|
|
183
|
-
radius: number,
|
|
184
|
-
shoulder: number,
|
|
185
|
-
m: number
|
|
186
|
-
): string {
|
|
187
|
-
const mid = size / 2;
|
|
188
|
-
const P = (px: number, py: number) => compact`${x + px} ${y + py}`;
|
|
189
|
-
return (
|
|
190
|
-
compact`M${P(radius, 0)}H${x + size - radius}` +
|
|
191
|
-
compact`A${radius} ${radius} 0 0 1 ${P(size, radius)}` +
|
|
192
|
-
compact`V${y + shoulder}` +
|
|
193
|
-
compact`C${P(size, shoulder + 1.55 * m)} ${P(mid + 1.6 * m, size)} ${P(mid, size)}` +
|
|
194
|
-
compact`C${P(mid - 1.6 * m, size)} ${P(0, shoulder + 1.55 * m)} ${P(0, shoulder)}` +
|
|
195
|
-
compact`V${y + radius}A${radius} ${radius} 0 0 1 ${P(radius, 0)}Z`
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
132
|
function generateCornerShieldPattern(
|
|
200
133
|
offsetX: number,
|
|
201
134
|
offsetY: number,
|
|
@@ -235,6 +168,154 @@ function generateCornerPetalPattern(
|
|
|
235
168
|
);
|
|
236
169
|
}
|
|
237
170
|
|
|
171
|
+
// Eye frames added after 0.0.57. Every one keeps the finder's 1:1:3:1:1
|
|
172
|
+
// runs along the rows and columns through its centre (outer edge at 3.5
|
|
173
|
+
// modules, hole edge at 2.5). On the diagonals the outer corners sit about
|
|
174
|
+
// 3.8 modules out and the hole's corners about 2.9 (round, radius 1.5, or
|
|
175
|
+
// a straight cut), which is what lets a circle centre read in sharp renders
|
|
176
|
+
// (tests/decode-sharp-centre.test.ts), keeps a light gap inside the ring for
|
|
177
|
+
// square centres, and reads light-on-dark at 4 px per module. Toothed or
|
|
178
|
+
// scalloped rims, holes rounder than that and asymmetric arches all failed
|
|
179
|
+
// one of those checks and were not kept.
|
|
180
|
+
|
|
181
|
+
/** The 5×5 hole with round corners (radius 1.5 modules). */
|
|
182
|
+
function roundHole(offsetX: number, offsetY: number, m: number): string {
|
|
183
|
+
return roundedRectPath(offsetX + m, offsetY + m, 5 * m, 5 * m, 1.5 * m);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** A superellipse rounder than the squircle eye (exponent 2.75). */
|
|
187
|
+
function pebbleOutline(cx: number, cy: number, m: number): string {
|
|
188
|
+
return polygonPath(superellipsePoints(cx, cy, 3.5 * m, 3.5 * m, 2.75, 96));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Porthole: a soft round outline around a square hole with cut corners. */
|
|
192
|
+
function generateCornerPortholePattern(
|
|
193
|
+
offsetX: number,
|
|
194
|
+
offsetY: number,
|
|
195
|
+
size: number
|
|
196
|
+
): string {
|
|
197
|
+
const m = size / 7;
|
|
198
|
+
return (
|
|
199
|
+
pebbleOutline(offsetX + size / 2, offsetY + size / 2, m) +
|
|
200
|
+
notchedRectPath(offsetX + m, offsetY + m, 5 * m, 5 * m, 0.52 * m)
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Notch: a square ring with a round bite out of each corner. */
|
|
205
|
+
function generateCornerNotchPattern(
|
|
206
|
+
offsetX: number,
|
|
207
|
+
offsetY: number,
|
|
208
|
+
size: number
|
|
209
|
+
): string {
|
|
210
|
+
const m = size / 7;
|
|
211
|
+
return (
|
|
212
|
+
scoopedRectPath(offsetX, offsetY, size, size, 1.15 * m) +
|
|
213
|
+
scoopedRectPath(offsetX + m, offsetY + m, 5 * m, 5 * m, 0.74 * m)
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Plus: a square ring with a square notch out of each corner. */
|
|
218
|
+
function generateCornerPlusPattern(
|
|
219
|
+
offsetX: number,
|
|
220
|
+
offsetY: number,
|
|
221
|
+
size: number
|
|
222
|
+
): string {
|
|
223
|
+
const m = size / 7;
|
|
224
|
+
return (
|
|
225
|
+
notchedRectPath(offsetX, offsetY, size, size, 0.8 * m) +
|
|
226
|
+
notchedRectPath(offsetX + m, offsetY + m, 5 * m, 5 * m, 0.52 * m)
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
type CornerStyle = ["round" | "cut", number];
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Square with a round or a cut (chamfered) corner each, clockwise from the
|
|
234
|
+
* top-left, drawn clockwise.
|
|
235
|
+
*/
|
|
236
|
+
function cornersPath(
|
|
237
|
+
x: number,
|
|
238
|
+
y: number,
|
|
239
|
+
size: number,
|
|
240
|
+
corners: [CornerStyle, CornerStyle, CornerStyle, CornerStyle]
|
|
241
|
+
): string {
|
|
242
|
+
const [tl, tr, br, bl] = corners;
|
|
243
|
+
const P = (px: number, py: number) => compact`${x + px} ${y + py}`;
|
|
244
|
+
const to = (corner: CornerStyle, toX: number, toY: number) =>
|
|
245
|
+
corner[0] === "round"
|
|
246
|
+
? compact`A${corner[1]} ${corner[1]} 0 0 1 ${P(toX, toY)}`
|
|
247
|
+
: compact`L${P(toX, toY)}`;
|
|
248
|
+
return (
|
|
249
|
+
compact`M${P(tl[1], 0)}L${P(size - tr[1], 0)}` +
|
|
250
|
+
to(tr, size, tr[1]) +
|
|
251
|
+
compact`L${P(size, size - br[1])}` +
|
|
252
|
+
to(br, size - br[1], size) +
|
|
253
|
+
compact`L${P(bl[1], size)}` +
|
|
254
|
+
to(bl, 0, size - bl[1]) +
|
|
255
|
+
compact`L${P(0, tl[1])}` +
|
|
256
|
+
to(tl, tl[1], 0) +
|
|
257
|
+
"Z"
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** The corner styles for a ring whose corners `pick` says are round. */
|
|
262
|
+
function ringCorners(
|
|
263
|
+
m: number,
|
|
264
|
+
round: (index: number) => boolean
|
|
265
|
+
): [
|
|
266
|
+
[CornerStyle, CornerStyle, CornerStyle, CornerStyle],
|
|
267
|
+
[CornerStyle, CornerStyle, CornerStyle, CornerStyle],
|
|
268
|
+
] {
|
|
269
|
+
const outer = [0, 1, 2, 3].map(
|
|
270
|
+
(i): CornerStyle => (round(i) ? ["round", 2.8 * m] : ["cut", 1.6 * m])
|
|
271
|
+
) as [CornerStyle, CornerStyle, CornerStyle, CornerStyle];
|
|
272
|
+
const inner = [0, 1, 2, 3].map(
|
|
273
|
+
(i): CornerStyle => (round(i) ? ["round", 1.5 * m] : ["cut", 1.01 * m])
|
|
274
|
+
) as [CornerStyle, CornerStyle, CornerStyle, CornerStyle];
|
|
275
|
+
return [outer, inner];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Bud: round at the corner pointing away from the code and at the one
|
|
280
|
+
* facing its centre, cut at the other two; it turns to face its corner of
|
|
281
|
+
* the code.
|
|
282
|
+
*/
|
|
283
|
+
function generateCornerBudPattern(
|
|
284
|
+
offsetX: number,
|
|
285
|
+
offsetY: number,
|
|
286
|
+
size: number,
|
|
287
|
+
corner: EyeCorner
|
|
288
|
+
): string {
|
|
289
|
+
const m = size / 7;
|
|
290
|
+
const outer = corner === "top-left" ? 0 : corner === "top-right" ? 1 : 3;
|
|
291
|
+
const opposite = (outer + 2) % 4;
|
|
292
|
+
const [outerCorners, innerCorners] = ringCorners(
|
|
293
|
+
m,
|
|
294
|
+
(i) => i === outer || i === opposite
|
|
295
|
+
);
|
|
296
|
+
return (
|
|
297
|
+
cornersPath(offsetX, offsetY, size, outerCorners) +
|
|
298
|
+
cornersPath(offsetX + m, offsetY + m, 5 * m, innerCorners)
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Bowl: cut at the top, round at the bottom, around a round hole. */
|
|
303
|
+
function generateCornerBowlPattern(
|
|
304
|
+
offsetX: number,
|
|
305
|
+
offsetY: number,
|
|
306
|
+
size: number
|
|
307
|
+
): string {
|
|
308
|
+
const m = size / 7;
|
|
309
|
+
return (
|
|
310
|
+
cornersPath(offsetX, offsetY, size, [
|
|
311
|
+
["cut", 1.6 * m],
|
|
312
|
+
["cut", 1.6 * m],
|
|
313
|
+
["round", 3 * m],
|
|
314
|
+
["round", 3 * m],
|
|
315
|
+
]) + roundHole(offsetX, offsetY, m)
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
238
319
|
/**
|
|
239
320
|
* Pattern 1: Basic square corners
|
|
240
321
|
*/
|
|
@@ -492,6 +573,16 @@ export function generateCornerSquarePath(
|
|
|
492
573
|
return generateCornerShieldPattern(offsetX, offsetY, size);
|
|
493
574
|
case "petal":
|
|
494
575
|
return generateCornerPetalPattern(offsetX, offsetY, size, corner);
|
|
576
|
+
case "porthole":
|
|
577
|
+
return generateCornerPortholePattern(offsetX, offsetY, size);
|
|
578
|
+
case "notch":
|
|
579
|
+
return generateCornerNotchPattern(offsetX, offsetY, size);
|
|
580
|
+
case "plus":
|
|
581
|
+
return generateCornerPlusPattern(offsetX, offsetY, size);
|
|
582
|
+
case "bud":
|
|
583
|
+
return generateCornerBudPattern(offsetX, offsetY, size, corner);
|
|
584
|
+
case "bowl":
|
|
585
|
+
return generateCornerBowlPattern(offsetX, offsetY, size);
|
|
495
586
|
case "gear":
|
|
496
587
|
return generateCornerGearPattern(offsetX, offsetY, size);
|
|
497
588
|
case "rounded":
|
package/src/engine.ts
CHANGED
|
@@ -196,10 +196,14 @@ export {
|
|
|
196
196
|
clampBgRadius,
|
|
197
197
|
colorAlpha,
|
|
198
198
|
eyeShapeOf,
|
|
199
|
+
fitHaloColor,
|
|
199
200
|
getBgRadiusLimit,
|
|
200
201
|
getEyeStyleRisk,
|
|
201
202
|
getHaloRisk,
|
|
203
|
+
type HaloAdjustment,
|
|
204
|
+
type HaloRefusal,
|
|
202
205
|
type HaloRisk,
|
|
206
|
+
haloTints,
|
|
203
207
|
isSeeThroughBackground,
|
|
204
208
|
resolveHalo,
|
|
205
209
|
resolveShadow,
|