qrdx 0.0.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 +414 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +11 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src/api.d.ts +3 -0
- package/dist/src/api.d.ts.map +1 -0
- package/dist/src/codegen.d.ts +101 -0
- package/dist/src/codegen.d.ts.map +1 -0
- package/dist/src/constants.d.ts +15 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/corner-dot.d.ts +4 -0
- package/dist/src/corner-dot.d.ts.map +1 -0
- package/dist/src/corner-eye.d.ts +3 -0
- package/dist/src/corner-eye.d.ts.map +1 -0
- package/dist/src/detection.d.ts +13 -0
- package/dist/src/detection.d.ts.map +1 -0
- package/dist/src/download.d.ts +36 -0
- package/dist/src/download.d.ts.map +1 -0
- package/dist/src/helpers.d.ts +36 -0
- package/dist/src/helpers.d.ts.map +1 -0
- package/dist/src/index.d.ts +25 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/qr-code.d.ts +20 -0
- package/dist/src/qr-code.d.ts.map +1 -0
- package/dist/src/template/arrow.d.ts +3 -0
- package/dist/src/template/arrow.d.ts.map +1 -0
- package/dist/src/template/default.d.ts +3 -0
- package/dist/src/template/default.d.ts.map +1 -0
- package/dist/src/template/halloween.d.ts +3 -0
- package/dist/src/template/halloween.d.ts.map +1 -0
- package/dist/src/template/index.d.ts +7 -0
- package/dist/src/template/index.d.ts.map +1 -0
- package/dist/src/template/square-border.d.ts +3 -0
- package/dist/src/template/square-border.d.ts.map +1 -0
- package/dist/src/template/standard-box.d.ts +3 -0
- package/dist/src/template/standard-box.d.ts.map +1 -0
- package/dist/src/template/striked-box.d.ts +3 -0
- package/dist/src/template/striked-box.d.ts.map +1 -0
- package/dist/src/templates.d.ts +8 -0
- package/dist/src/templates.d.ts.map +1 -0
- package/dist/src/utils.d.ts +38 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/types/common.d.ts +9 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/corner-dot.d.ts +3 -0
- package/dist/types/corner-dot.d.ts.map +1 -0
- package/dist/types/corner-eye.d.ts +3 -0
- package/dist/types/corner-eye.d.ts.map +1 -0
- package/dist/types/image-pattern.d.ts +3 -0
- package/dist/types/image-pattern.d.ts.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/qr.d.ts +35 -0
- package/dist/types/qr.d.ts.map +1 -0
- package/dist/types/template.d.ts +34 -0
- package/dist/types/template.d.ts.map +1 -0
- package/package.json +51 -0
- package/src/api.tsx +85 -0
- package/src/codegen.ts +1043 -0
- package/src/constants.ts +26 -0
- package/src/corner-dot.tsx +101 -0
- package/src/corner-eye.ts +165 -0
- package/src/detection.ts +266 -0
- package/src/download.tsx +235 -0
- package/src/helpers.ts +59 -0
- package/src/index.tsx +306 -0
- package/src/qr-code.tsx +116 -0
- package/src/template/arrow.tsx +39 -0
- package/src/template/default.tsx +26 -0
- package/src/template/halloween.tsx +146 -0
- package/src/template/index.ts +6 -0
- package/src/template/square-border.tsx +42 -0
- package/src/template/standard-box.tsx +42 -0
- package/src/template/striked-box.tsx +41 -0
- package/src/templates.tsx +32 -0
- package/src/utils.tsx +750 -0
- package/types/common.ts +4 -0
- package/types/corner-dot.ts +13 -0
- package/types/corner-eye.ts +13 -0
- package/types/image-pattern.ts +12 -0
- package/types/index.ts +16 -0
- package/types/qr.ts +41 -0
- package/types/template.ts +41 -0
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "qrdx",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/src/index.d.ts",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/src/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"./types": {
|
|
19
|
+
"types": "./dist/types/index.d.ts",
|
|
20
|
+
"import": "./types/index.ts",
|
|
21
|
+
"require": "./types/index.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"types",
|
|
27
|
+
"src"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"preinstall": "pnpm build",
|
|
31
|
+
"build": "tsup && tsc --project tsconfig.build.json --emitDeclarationOnly",
|
|
32
|
+
"clean": "git clean -xdf .cache .turbo dist node_modules",
|
|
33
|
+
"typecheck": "tsc --noEmit"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"jsqr": "^1.4.0",
|
|
37
|
+
"react": "19.2.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@repo/typescript-config": "workspace:*",
|
|
41
|
+
"@types/node": "24.9.2",
|
|
42
|
+
"@types/react": "19.2.2",
|
|
43
|
+
"@types/react-dom": "19.2.2",
|
|
44
|
+
"next": "16.0.1",
|
|
45
|
+
"tsup": "^8.3.5",
|
|
46
|
+
"typescript": "5.9.3"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react-dom": ">=18.0.0"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/api.tsx
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { QRPropsSVG } from "../types";
|
|
2
|
+
import qrcodegen from "./codegen";
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_BGCOLOR,
|
|
5
|
+
DEFAULT_FGCOLOR,
|
|
6
|
+
DEFAULT_LEVEL,
|
|
7
|
+
DEFAULT_MARGIN,
|
|
8
|
+
DEFAULT_SIZE,
|
|
9
|
+
ERROR_LEVEL_MAP,
|
|
10
|
+
} from "./constants";
|
|
11
|
+
import { excavateModules, generatePath, getImageSettings } from "./utils";
|
|
12
|
+
|
|
13
|
+
export async function getQRAsSVG(props: QRPropsSVG) {
|
|
14
|
+
const {
|
|
15
|
+
value,
|
|
16
|
+
size = DEFAULT_SIZE,
|
|
17
|
+
level = DEFAULT_LEVEL,
|
|
18
|
+
bgColor = DEFAULT_BGCOLOR,
|
|
19
|
+
fgColor = DEFAULT_FGCOLOR,
|
|
20
|
+
margin = DEFAULT_MARGIN,
|
|
21
|
+
imageSettings,
|
|
22
|
+
...otherProps
|
|
23
|
+
} = props;
|
|
24
|
+
|
|
25
|
+
let cells = qrcodegen.QrCode.encodeText(
|
|
26
|
+
value,
|
|
27
|
+
ERROR_LEVEL_MAP[level]
|
|
28
|
+
).getModules();
|
|
29
|
+
|
|
30
|
+
const numCells = cells.length + margin * 2;
|
|
31
|
+
const calculatedImageSettings = getImageSettings(
|
|
32
|
+
cells,
|
|
33
|
+
size,
|
|
34
|
+
margin,
|
|
35
|
+
imageSettings
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
let image = <></>;
|
|
39
|
+
if (imageSettings != null && calculatedImageSettings != null) {
|
|
40
|
+
if (calculatedImageSettings.excavation != null) {
|
|
41
|
+
cells = excavateModules(cells, calculatedImageSettings.excavation);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const base64Image = await fetch(
|
|
45
|
+
`https://wsrv.nl/?url=${imageSettings.src}&w=100&h=100&encoding=base64`
|
|
46
|
+
).then((res) => res.text());
|
|
47
|
+
|
|
48
|
+
image = (
|
|
49
|
+
<image
|
|
50
|
+
height={calculatedImageSettings.h}
|
|
51
|
+
href={base64Image}
|
|
52
|
+
preserveAspectRatio="none"
|
|
53
|
+
width={calculatedImageSettings.w}
|
|
54
|
+
x={calculatedImageSettings.x + margin}
|
|
55
|
+
y={calculatedImageSettings.y + margin}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Drawing strategy: instead of a rect per module, we're going to create a
|
|
61
|
+
// single path for the dark modules and layer that on top of a light rect,
|
|
62
|
+
// for a total of 2 DOM nodes. We pay a bit more in string concat but that's
|
|
63
|
+
// way faster than DOM ops.
|
|
64
|
+
// For level 1, 441 nodes -> 2
|
|
65
|
+
// For level 40, 31329 -> 2
|
|
66
|
+
const fgPath = generatePath(cells, margin);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<svg
|
|
70
|
+
height={size}
|
|
71
|
+
viewBox={`0 0 ${numCells} ${numCells}`}
|
|
72
|
+
width={size}
|
|
73
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
74
|
+
{...otherProps}
|
|
75
|
+
>
|
|
76
|
+
<path
|
|
77
|
+
d={`M0,0 h${numCells}v${numCells}H0z`}
|
|
78
|
+
fill={bgColor}
|
|
79
|
+
shapeRendering="crispEdges"
|
|
80
|
+
/>
|
|
81
|
+
<path d={fgPath} fill={fgColor} shapeRendering="crispEdges" />
|
|
82
|
+
{image}
|
|
83
|
+
</svg>
|
|
84
|
+
);
|
|
85
|
+
}
|