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.
Files changed (84) hide show
  1. package/README.md +414 -0
  2. package/dist/index.js +11 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/index.mjs +11 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/dist/src/api.d.ts +3 -0
  7. package/dist/src/api.d.ts.map +1 -0
  8. package/dist/src/codegen.d.ts +101 -0
  9. package/dist/src/codegen.d.ts.map +1 -0
  10. package/dist/src/constants.d.ts +15 -0
  11. package/dist/src/constants.d.ts.map +1 -0
  12. package/dist/src/corner-dot.d.ts +4 -0
  13. package/dist/src/corner-dot.d.ts.map +1 -0
  14. package/dist/src/corner-eye.d.ts +3 -0
  15. package/dist/src/corner-eye.d.ts.map +1 -0
  16. package/dist/src/detection.d.ts +13 -0
  17. package/dist/src/detection.d.ts.map +1 -0
  18. package/dist/src/download.d.ts +36 -0
  19. package/dist/src/download.d.ts.map +1 -0
  20. package/dist/src/helpers.d.ts +36 -0
  21. package/dist/src/helpers.d.ts.map +1 -0
  22. package/dist/src/index.d.ts +25 -0
  23. package/dist/src/index.d.ts.map +1 -0
  24. package/dist/src/qr-code.d.ts +20 -0
  25. package/dist/src/qr-code.d.ts.map +1 -0
  26. package/dist/src/template/arrow.d.ts +3 -0
  27. package/dist/src/template/arrow.d.ts.map +1 -0
  28. package/dist/src/template/default.d.ts +3 -0
  29. package/dist/src/template/default.d.ts.map +1 -0
  30. package/dist/src/template/halloween.d.ts +3 -0
  31. package/dist/src/template/halloween.d.ts.map +1 -0
  32. package/dist/src/template/index.d.ts +7 -0
  33. package/dist/src/template/index.d.ts.map +1 -0
  34. package/dist/src/template/square-border.d.ts +3 -0
  35. package/dist/src/template/square-border.d.ts.map +1 -0
  36. package/dist/src/template/standard-box.d.ts +3 -0
  37. package/dist/src/template/standard-box.d.ts.map +1 -0
  38. package/dist/src/template/striked-box.d.ts +3 -0
  39. package/dist/src/template/striked-box.d.ts.map +1 -0
  40. package/dist/src/templates.d.ts +8 -0
  41. package/dist/src/templates.d.ts.map +1 -0
  42. package/dist/src/utils.d.ts +38 -0
  43. package/dist/src/utils.d.ts.map +1 -0
  44. package/dist/types/common.d.ts +9 -0
  45. package/dist/types/common.d.ts.map +1 -0
  46. package/dist/types/corner-dot.d.ts +3 -0
  47. package/dist/types/corner-dot.d.ts.map +1 -0
  48. package/dist/types/corner-eye.d.ts +3 -0
  49. package/dist/types/corner-eye.d.ts.map +1 -0
  50. package/dist/types/image-pattern.d.ts +3 -0
  51. package/dist/types/image-pattern.d.ts.map +1 -0
  52. package/dist/types/index.d.ts +10 -0
  53. package/dist/types/index.d.ts.map +1 -0
  54. package/dist/types/qr.d.ts +35 -0
  55. package/dist/types/qr.d.ts.map +1 -0
  56. package/dist/types/template.d.ts +34 -0
  57. package/dist/types/template.d.ts.map +1 -0
  58. package/package.json +51 -0
  59. package/src/api.tsx +85 -0
  60. package/src/codegen.ts +1043 -0
  61. package/src/constants.ts +26 -0
  62. package/src/corner-dot.tsx +101 -0
  63. package/src/corner-eye.ts +165 -0
  64. package/src/detection.ts +266 -0
  65. package/src/download.tsx +235 -0
  66. package/src/helpers.ts +59 -0
  67. package/src/index.tsx +306 -0
  68. package/src/qr-code.tsx +116 -0
  69. package/src/template/arrow.tsx +39 -0
  70. package/src/template/default.tsx +26 -0
  71. package/src/template/halloween.tsx +146 -0
  72. package/src/template/index.ts +6 -0
  73. package/src/template/square-border.tsx +42 -0
  74. package/src/template/standard-box.tsx +42 -0
  75. package/src/template/striked-box.tsx +41 -0
  76. package/src/templates.tsx +32 -0
  77. package/src/utils.tsx +750 -0
  78. package/types/common.ts +4 -0
  79. package/types/corner-dot.ts +13 -0
  80. package/types/corner-eye.ts +13 -0
  81. package/types/image-pattern.ts +12 -0
  82. package/types/index.ts +16 -0
  83. package/types/qr.ts +41 -0
  84. 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
+ }