qrdx 0.0.56 → 0.0.58

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 (263) hide show
  1. package/README.md +27 -6
  2. package/dist/angular.js +33 -3
  3. package/dist/angular.js.map +1 -1
  4. package/dist/angular.mjs +33 -3
  5. package/dist/angular.mjs.map +1 -1
  6. package/dist/core.js +7 -7
  7. package/dist/core.js.map +1 -1
  8. package/dist/core.mjs +7 -7
  9. package/dist/core.mjs.map +1 -1
  10. package/dist/element.browser.mjs +6 -6
  11. package/dist/element.browser.mjs.map +1 -1
  12. package/dist/element.js +1 -1
  13. package/dist/element.js.map +1 -1
  14. package/dist/element.mjs +1 -1
  15. package/dist/element.mjs.map +1 -1
  16. package/dist/frames-index.js +1 -1
  17. package/dist/frames-index.js.map +1 -1
  18. package/dist/frames-index.mjs +1 -1
  19. package/dist/frames-index.mjs.map +1 -1
  20. package/dist/frames-official.js +1 -1
  21. package/dist/frames-official.js.map +1 -1
  22. package/dist/frames-official.mjs +1 -1
  23. package/dist/frames-official.mjs.map +1 -1
  24. package/dist/index.js +7 -7
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +7 -7
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/qr-code-canvas.js +1 -1
  29. package/dist/qr-code-canvas.js.map +1 -1
  30. package/dist/qr-code-canvas.mjs +1 -1
  31. package/dist/qr-code-canvas.mjs.map +1 -1
  32. package/dist/schemas.js +1 -1
  33. package/dist/schemas.js.map +1 -1
  34. package/dist/schemas.mjs +1 -1
  35. package/dist/schemas.mjs.map +1 -1
  36. package/dist/src/angular.d.ts +9 -3
  37. package/dist/src/bmp.d.ts +7 -0
  38. package/dist/src/bmp.d.ts.map +1 -0
  39. package/dist/src/download.d.ts +39 -6
  40. package/dist/src/download.d.ts.map +1 -1
  41. package/dist/src/element.d.ts +10 -1
  42. package/dist/src/element.d.ts.map +1 -1
  43. package/dist/src/engine.d.ts +6 -2
  44. package/dist/src/engine.d.ts.map +1 -1
  45. package/dist/src/eps.d.ts.map +1 -1
  46. package/dist/src/export.d.ts.map +1 -1
  47. package/dist/src/frame.d.ts +24 -0
  48. package/dist/src/frame.d.ts.map +1 -1
  49. package/dist/src/frames/catalogue/all.d.ts.map +1 -1
  50. package/dist/src/frames/catalogue/batches.d.ts +6 -0
  51. package/dist/src/frames/catalogue/batches.d.ts.map +1 -0
  52. package/dist/src/frames/catalogue/call-to-action.d.ts.map +1 -1
  53. package/dist/src/frames/catalogue/counts.d.ts +4 -2
  54. package/dist/src/frames/catalogue/counts.d.ts.map +1 -1
  55. package/dist/src/frames/catalogue/index.d.ts.map +1 -1
  56. package/dist/src/frames/catalogue/objects.d.ts +5 -0
  57. package/dist/src/frames/catalogue/objects.d.ts.map +1 -0
  58. package/dist/src/frames/catalogue/playful.d.ts +5 -0
  59. package/dist/src/frames/catalogue/playful.d.ts.map +1 -0
  60. package/dist/src/frames/catalogue/tags.d.ts.map +1 -1
  61. package/dist/src/frames/collections.d.ts.map +1 -1
  62. package/dist/src/frames/official-types.d.ts +1 -1
  63. package/dist/src/frames/official-types.d.ts.map +1 -1
  64. package/dist/src/frames/official.d.ts.map +1 -1
  65. package/dist/src/gif.d.ts +40 -0
  66. package/dist/src/gif.d.ts.map +1 -0
  67. package/dist/src/helpers.d.ts +1 -1
  68. package/dist/src/helpers.d.ts.map +1 -1
  69. package/dist/src/ico.d.ts +11 -0
  70. package/dist/src/ico.d.ts.map +1 -0
  71. package/dist/src/index.d.ts +2 -1
  72. package/dist/src/index.d.ts.map +1 -1
  73. package/dist/src/looks.d.ts +101 -0
  74. package/dist/src/looks.d.ts.map +1 -0
  75. package/dist/src/plain.d.ts.map +1 -1
  76. package/dist/src/print.d.ts.map +1 -1
  77. package/dist/src/qr-code-canvas.d.ts.map +1 -1
  78. package/dist/src/qr-code-props.d.ts.map +1 -1
  79. package/dist/src/qr-frame-svg.d.ts +10 -0
  80. package/dist/src/qr-frame-svg.d.ts.map +1 -0
  81. package/dist/src/scan-score.d.ts.map +1 -1
  82. package/dist/src/utils/bmp.d.ts +18 -0
  83. package/dist/src/utils/bmp.d.ts.map +1 -0
  84. package/dist/src/utils/gif.d.ts +61 -0
  85. package/dist/src/utils/gif.d.ts.map +1 -0
  86. package/dist/src/utils/ico.d.ts +30 -0
  87. package/dist/src/utils/ico.d.ts.map +1 -0
  88. package/dist/src/utils/parse-color.d.ts +1 -1
  89. package/dist/src/utils/parse-color.d.ts.map +1 -1
  90. package/dist/src/utils/print-shared.d.ts.map +1 -1
  91. package/dist/src/utils/svg-painter.d.ts +13 -0
  92. package/dist/src/utils/svg-painter.d.ts.map +1 -1
  93. package/dist/src/utils.d.ts.map +1 -1
  94. package/dist/src/vanilla-api.d.ts +2 -2
  95. package/dist/src/vanilla-api.d.ts.map +1 -1
  96. package/dist/src/vue.d.ts +2 -2
  97. package/dist/src/vue.d.ts.map +1 -1
  98. package/dist/types/constants.d.ts +41 -0
  99. package/dist/types/constants.d.ts.map +1 -1
  100. package/dist/types/index.js +2 -2
  101. package/dist/types/index.js.map +1 -1
  102. package/dist/types/index.mjs +2 -2
  103. package/dist/types/index.mjs.map +1 -1
  104. package/dist/types/plain.d.ts +2 -2
  105. package/dist/types/plain.d.ts.map +1 -1
  106. package/dist/types/qr.d.ts +399 -1
  107. package/dist/types/qr.d.ts.map +1 -1
  108. package/dist/types/react.d.ts +10 -1
  109. package/dist/types/react.d.ts.map +1 -1
  110. package/dist/types/schemas.d.ts +1 -1
  111. package/dist/types/schemas.d.ts.map +1 -1
  112. package/dist/vanilla.browser.mjs +34 -34
  113. package/dist/vanilla.browser.mjs.map +1 -1
  114. package/dist/vue.js +1 -1
  115. package/dist/vue.js.map +1 -1
  116. package/dist/vue.mjs +1 -1
  117. package/dist/vue.mjs.map +1 -1
  118. package/package.json +6 -2
  119. package/src/angular.ts +14 -2
  120. package/src/bmp.ts +25 -0
  121. package/src/download.tsx +128 -8
  122. package/src/element.ts +16 -1
  123. package/src/engine.ts +23 -0
  124. package/src/eps.ts +8 -1
  125. package/src/export.ts +22 -0
  126. package/src/frame.tsx +51 -0
  127. package/src/frames/catalogue/all.ts +202 -0
  128. package/src/frames/catalogue/batches.ts +114 -0
  129. package/src/frames/catalogue/call-to-action.ts +58 -0
  130. package/src/frames/catalogue/counts.ts +4 -2
  131. package/src/frames/catalogue/index.ts +808 -0
  132. package/src/frames/catalogue/objects.ts +65 -0
  133. package/src/frames/catalogue/playful.ts +97 -0
  134. package/src/frames/catalogue/tags.ts +137 -0
  135. package/src/frames/collections.ts +2 -0
  136. package/src/frames/official/badge-bottom-light.json +91 -0
  137. package/src/frames/official/badge-bottom.json +79 -0
  138. package/src/frames/official/billboard-campaign.json +274 -0
  139. package/src/frames/official/billboard-light.json +287 -0
  140. package/src/frames/official/bookmark-light.json +88 -0
  141. package/src/frames/official/bookmark-strip.json +83 -0
  142. package/src/frames/official/border-medium.json +71 -0
  143. package/src/frames/official/border-thick.json +71 -0
  144. package/src/frames/official/border-thin.json +71 -0
  145. package/src/frames/official/bottle-label.json +136 -0
  146. package/src/frames/official/bottle-light.json +133 -0
  147. package/src/frames/official/camera-viewfinder.json +174 -0
  148. package/src/frames/official/cassette-tape.json +236 -0
  149. package/src/frames/official/cat-with-card-light.json +246 -0
  150. package/src/frames/official/cat-with-card.json +234 -0
  151. package/src/frames/official/cinema-marquee.json +537 -0
  152. package/src/frames/official/circle-viewfinder.json +87 -0
  153. package/src/frames/official/clapperboard-light.json +163 -0
  154. package/src/frames/official/clapperboard-scene.json +151 -0
  155. package/src/frames/official/comic-panel.json +386 -0
  156. package/src/frames/official/corner-tab-light.json +101 -0
  157. package/src/frames/official/corner-tab.json +89 -0
  158. package/src/frames/official/crystal-ball.json +105 -0
  159. package/src/frames/official/delivery-box-light.json +132 -0
  160. package/src/frames/official/delivery-box-track.json +132 -0
  161. package/src/frames/official/fish-tank.json +276 -0
  162. package/src/frames/official/flag-light.json +136 -0
  163. package/src/frames/official/flag-team.json +127 -0
  164. package/src/frames/official/floppy-disk.json +106 -0
  165. package/src/frames/official/flying-saucer.json +128 -0
  166. package/src/frames/official/gallery-frame.json +195 -0
  167. package/src/frames/official/globe-stand.json +136 -0
  168. package/src/frames/official/gumball-machine.json +451 -0
  169. package/src/frames/official/heart-light.json +59 -0
  170. package/src/frames/official/heart-scan.json +51 -0
  171. package/src/frames/official/hexagon-light.json +87 -0
  172. package/src/frames/official/hexagon-scan.json +72 -0
  173. package/src/frames/official/hot-air-balloon.json +132 -0
  174. package/src/frames/official/jigsaw-piece-light.json +68 -0
  175. package/src/frames/official/jigsaw-piece.json +60 -0
  176. package/src/frames/official/laptop-screen.json +137 -0
  177. package/src/frames/official/lighthouse-tower.json +132 -0
  178. package/src/frames/official/magnifying-glass.json +85 -0
  179. package/src/frames/official/mailbox-flag.json +112 -0
  180. package/src/frames/official/mailbox-light.json +120 -0
  181. package/src/frames/official/map-pin-light.json +76 -0
  182. package/src/frames/official/map-pin.json +58 -0
  183. package/src/frames/official/matchbox-drawer.json +170 -0
  184. package/src/frames/official/microwave-door.json +220 -0
  185. package/src/frames/official/milk-carton.json +129 -0
  186. package/src/frames/official/monitor-screen.json +111 -0
  187. package/src/frames/official/monster-mouth.json +180 -0
  188. package/src/frames/official/mug-light.json +138 -0
  189. package/src/frames/official/mug-refill.json +125 -0
  190. package/src/frames/official/museum-plaque-light.json +187 -0
  191. package/src/frames/official/museum-plaque.json +187 -0
  192. package/src/frames/official/music-player-light.json +151 -0
  193. package/src/frames/official/music-player.json +136 -0
  194. package/src/frames/official/octagon-light.json +126 -0
  195. package/src/frames/official/octagon-sign.json +120 -0
  196. package/src/frames/official/open-book.json +156 -0
  197. package/src/frames/official/parking-meter.json +107 -0
  198. package/src/frames/official/passport-stamp.json +132 -0
  199. package/src/frames/official/pizza-box.json +122 -0
  200. package/src/frames/official/polka-dot-border.json +502 -0
  201. package/src/frames/official/popcorn-bucket.json +305 -0
  202. package/src/frames/official/porthole.json +264 -0
  203. package/src/frames/official/raised-card-thin.json +111 -0
  204. package/src/frames/official/raised-card.json +99 -0
  205. package/src/frames/official/retro-radio.json +180 -0
  206. package/src/frames/official/ribbon-top-light.json +125 -0
  207. package/src/frames/official/ribbon-top.json +113 -0
  208. package/src/frames/official/robot-chest.json +197 -0
  209. package/src/frames/official/roll-up-banner-light.json +137 -0
  210. package/src/frames/official/roll-up-banner.json +125 -0
  211. package/src/frames/official/round-tag-light.json +86 -0
  212. package/src/frames/official/round-tag.json +79 -0
  213. package/src/frames/official/sailboat-sail.json +99 -0
  214. package/src/frames/official/scroll-story.json +184 -0
  215. package/src/frames/official/sketch-border.json +92 -0
  216. package/src/frames/official/sketch-circle.json +57 -0
  217. package/src/frames/official/snow-globe.json +170 -0
  218. package/src/frames/official/soda-can.json +160 -0
  219. package/src/frames/official/spin-rays.json +126 -0
  220. package/src/frames/official/spiral-notebook.json +476 -0
  221. package/src/frames/official/stage-curtains.json +303 -0
  222. package/src/frames/official/starburst-light.json +128 -0
  223. package/src/frames/official/starburst.json +118 -0
  224. package/src/frames/official/swirl-border.json +122 -0
  225. package/src/frames/official/tablet-screen.json +130 -0
  226. package/src/frames/official/text-frame.json +79 -0
  227. package/src/frames/official/toaster-toast.json +114 -0
  228. package/src/frames/official/train-window.json +176 -0
  229. package/src/frames/official/treasure-map.json +207 -0
  230. package/src/frames/official/tv-set.json +256 -0
  231. package/src/frames/official/vending-machine.json +218 -0
  232. package/src/frames/official/video-player.json +118 -0
  233. package/src/frames/official/video-tape.json +137 -0
  234. package/src/frames/official/vinyl-sleeve-light.json +139 -0
  235. package/src/frames/official/vinyl-sleeve.json +127 -0
  236. package/src/frames/official/washing-machine.json +146 -0
  237. package/src/frames/official-types.ts +3 -1
  238. package/src/frames/official.ts +4 -3
  239. package/src/gif.ts +188 -0
  240. package/src/helpers.ts +12 -0
  241. package/src/ico.ts +55 -0
  242. package/src/index.tsx +2 -0
  243. package/src/looks.ts +467 -0
  244. package/src/plain.tsx +6 -0
  245. package/src/print.ts +12 -0
  246. package/src/qr-code-canvas.tsx +23 -2
  247. package/src/qr-code-props.ts +22 -0
  248. package/src/qr-frame-svg.tsx +26 -0
  249. package/src/scan-score.ts +38 -6
  250. package/src/utils/bmp.ts +126 -0
  251. package/src/utils/gif.ts +632 -0
  252. package/src/utils/ico.ts +150 -0
  253. package/src/utils/parse-color.ts +163 -23
  254. package/src/utils/print-shared.ts +25 -1
  255. package/src/utils/svg-painter.ts +18 -0
  256. package/src/utils.tsx +136 -17
  257. package/src/vanilla-api.ts +2 -2
  258. package/src/vue.ts +8 -2
  259. package/types/constants.ts +47 -0
  260. package/types/plain.ts +19 -0
  261. package/types/qr.ts +98 -0
  262. package/types/react.ts +11 -1
  263. package/types/schemas.ts +5 -0
@@ -0,0 +1,150 @@
1
+ /** biome-ignore-all lint/style/noMagicNumbers: ICO and PNG format constants */
2
+ // An ICO writer in plain TypeScript with no DOM. Canvases can't encode ICO
3
+ // (toBlob("image/x-icon") returns a PNG), so every browser, the CLI and the
4
+ // server use this one.
5
+ //
6
+ // An ICO file is a 6-byte header, one 16-byte directory entry per image, then
7
+ // the images. Each image here is a whole PNG file: Windows Vista and later,
8
+ // and every browser, read PNG-in-ICO, and it keeps the alpha channel and
9
+ // needs no pixel conversion. The sizes are 1 to 256 px: the directory stores a
10
+ // size as one byte, with 0 meaning 256.
11
+
12
+ /** The sizes a favicon holds: 16 and 32 px for tabs, 48 for Windows, 256 for large icons. */
13
+ export const ICO_SIZES: readonly number[] = [16, 32, 48, 256];
14
+
15
+ /** The MIME type of an ICO (the one IANA registers; some servers send image/x-icon). */
16
+ export const ICO_MIME = "image/vnd.microsoft.icon";
17
+
18
+ /** Largest width or height an ICO image can have. */
19
+ export const ICO_MAX_DIMENSION = 256;
20
+
21
+ /** Most images one file can list (a 16-bit count; this keeps it sane). */
22
+ export const ICO_MAX_IMAGES = 64;
23
+
24
+ const HEADER_SIZE = 6;
25
+ const ENTRY_SIZE = 16;
26
+ const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
27
+ /** Where a PNG's IHDR width and height sit: after the signature, length and type. */
28
+ const PNG_WIDTH_AT = 16;
29
+ const PNG_HEIGHT_AT = 20;
30
+ /** 32 bits a pixel: PNG-in-ICO entries say so, and keep their alpha. */
31
+ const BITS_PER_PIXEL = 32;
32
+
33
+ /** One image of an ICO: a PNG file and its size. */
34
+ export interface IcoImage {
35
+ width: number;
36
+ height: number;
37
+ png: Uint8Array;
38
+ }
39
+
40
+ const isPng = (bytes: Uint8Array): boolean =>
41
+ bytes.length >= PNG_HEIGHT_AT + 4 &&
42
+ PNG_SIGNATURE.every((value, index) => bytes[index] === value);
43
+
44
+ const pngSize = (bytes: Uint8Array): { width: number; height: number } => {
45
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
46
+ return {
47
+ width: view.getUint32(PNG_WIDTH_AT),
48
+ height: view.getUint32(PNG_HEIGHT_AT),
49
+ };
50
+ };
51
+
52
+ /**
53
+ * PNG images (each a whole PNG file, 1 to 256 px a side, the size they say
54
+ * they are) as one ICO file, in the order given. Throws a RangeError for no
55
+ * images, too many, a size outside 1 to 256, or a file that isn't a PNG of the
56
+ * size stated: a mislabelled image would make a file readers reject.
57
+ */
58
+ export function encodeICO(images: readonly IcoImage[]): Uint8Array {
59
+ if (images.length < 1 || images.length > ICO_MAX_IMAGES) {
60
+ throw new RangeError(
61
+ `An ICO holds 1 to ${ICO_MAX_IMAGES} images, got ${images.length}`
62
+ );
63
+ }
64
+ for (const { width, height, png } of images) {
65
+ const sizeOk = (value: number) =>
66
+ Number.isInteger(value) && value >= 1 && value <= ICO_MAX_DIMENSION;
67
+ if (!(sizeOk(width) && sizeOk(height))) {
68
+ throw new RangeError(
69
+ `ICO images must be whole numbers from 1 to ${ICO_MAX_DIMENSION} px, got ${width} x ${height}`
70
+ );
71
+ }
72
+ if (!isPng(png)) {
73
+ throw new RangeError("Every ICO image must be a PNG file");
74
+ }
75
+ const actual = pngSize(png);
76
+ if (actual.width !== width || actual.height !== height) {
77
+ throw new RangeError(
78
+ `An ICO image says ${width} x ${height} but its PNG is ${actual.width} x ${actual.height}`
79
+ );
80
+ }
81
+ }
82
+
83
+ const directorySize = HEADER_SIZE + ENTRY_SIZE * images.length;
84
+ const total = images.reduce((sum, image) => sum + image.png.length, 0);
85
+ const file = new Uint8Array(directorySize + total);
86
+ const view = new DataView(file.buffer);
87
+
88
+ view.setUint16(0, 0, true); // reserved
89
+ view.setUint16(2, 1, true); // type: 1 is an icon, 2 a cursor
90
+ view.setUint16(4, images.length, true);
91
+
92
+ let offset = directorySize;
93
+ images.forEach(({ width, height, png }, index) => {
94
+ const at = HEADER_SIZE + ENTRY_SIZE * index;
95
+ // A byte a side, where 0 means 256
96
+ file[at] = width === ICO_MAX_DIMENSION ? 0 : width;
97
+ file[at + 1] = height === ICO_MAX_DIMENSION ? 0 : height;
98
+ file[at + 2] = 0; // colours in the palette: none
99
+ file[at + 3] = 0; // reserved
100
+ view.setUint16(at + 4, 1, true); // colour planes
101
+ view.setUint16(at + 6, BITS_PER_PIXEL, true);
102
+ view.setUint32(at + 8, png.length, true); // size of the image data
103
+ view.setUint32(at + 12, offset, true); // where the image data starts
104
+ file.set(png, offset);
105
+ offset += png.length;
106
+ });
107
+ return file;
108
+ }
109
+
110
+ /**
111
+ * True when `bytes` is an ICO this writer would make: the icon header, a
112
+ * directory whose entries fit the file, and a PNG of the stated size at each
113
+ * offset. Used to check a file before it is saved, so nothing else is handed
114
+ * out as an ICO.
115
+ */
116
+ export function isICOFile(bytes: Uint8Array): boolean {
117
+ if (bytes.length < HEADER_SIZE + ENTRY_SIZE) {
118
+ return false;
119
+ }
120
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
121
+ const count = view.getUint16(4, true);
122
+ if (
123
+ view.getUint16(0, true) !== 0 ||
124
+ view.getUint16(2, true) !== 1 ||
125
+ count < 1 ||
126
+ count > ICO_MAX_IMAGES ||
127
+ bytes.length < HEADER_SIZE + ENTRY_SIZE * count
128
+ ) {
129
+ return false;
130
+ }
131
+ for (let index = 0; index < count; index++) {
132
+ const at = HEADER_SIZE + ENTRY_SIZE * index;
133
+ const width = bytes[at] || ICO_MAX_DIMENSION;
134
+ const height = bytes[at + 1] || ICO_MAX_DIMENSION;
135
+ const length = view.getUint32(at + 8, true);
136
+ const offset = view.getUint32(at + 12, true);
137
+ if (offset + length > bytes.length) {
138
+ return false;
139
+ }
140
+ const png = bytes.subarray(offset, offset + length);
141
+ if (!isPng(png)) {
142
+ return false;
143
+ }
144
+ const actual = pngSize(png);
145
+ if (actual.width !== width || actual.height !== height) {
146
+ return false;
147
+ }
148
+ }
149
+ return true;
150
+ }
@@ -10,30 +10,170 @@ export interface RGBAColor {
10
10
  a: number;
11
11
  }
12
12
 
13
- const NAMED_COLORS: Record<string, [number, number, number]> = {
14
- black: [0, 0, 0],
15
- white: [255, 255, 255],
16
- red: [255, 0, 0],
17
- green: [0, 128, 0],
18
- lime: [0, 255, 0],
19
- blue: [0, 0, 255],
20
- navy: [0, 0, 128],
21
- yellow: [255, 255, 0],
22
- orange: [255, 165, 0],
23
- purple: [128, 0, 128],
24
- pink: [255, 192, 203],
25
- gray: [128, 128, 128],
26
- grey: [128, 128, 128],
27
- silver: [192, 192, 192],
28
- maroon: [128, 0, 0],
29
- olive: [128, 128, 0],
30
- teal: [0, 128, 128],
31
- aqua: [0, 255, 255],
32
- cyan: [0, 255, 255],
33
- fuchsia: [255, 0, 255],
34
- magenta: [255, 0, 255],
13
+ /** The CSS named colors (CSS Color 4: 148 names), as rrggbb. */
14
+ const CSS_NAMED_COLORS: Record<string, string> = {
15
+ aliceblue: "f0f8ff",
16
+ antiquewhite: "faebd7",
17
+ aqua: "00ffff",
18
+ aquamarine: "7fffd4",
19
+ azure: "f0ffff",
20
+ beige: "f5f5dc",
21
+ bisque: "ffe4c4",
22
+ black: "000000",
23
+ blanchedalmond: "ffebcd",
24
+ blue: "0000ff",
25
+ blueviolet: "8a2be2",
26
+ brown: "a52a2a",
27
+ burlywood: "deb887",
28
+ cadetblue: "5f9ea0",
29
+ chartreuse: "7fff00",
30
+ chocolate: "d2691e",
31
+ coral: "ff7f50",
32
+ cornflowerblue: "6495ed",
33
+ cornsilk: "fff8dc",
34
+ crimson: "dc143c",
35
+ cyan: "00ffff",
36
+ darkblue: "00008b",
37
+ darkcyan: "008b8b",
38
+ darkgoldenrod: "b8860b",
39
+ darkgray: "a9a9a9",
40
+ darkgreen: "006400",
41
+ darkgrey: "a9a9a9",
42
+ darkkhaki: "bdb76b",
43
+ darkmagenta: "8b008b",
44
+ darkolivegreen: "556b2f",
45
+ darkorange: "ff8c00",
46
+ darkorchid: "9932cc",
47
+ darkred: "8b0000",
48
+ darksalmon: "e9967a",
49
+ darkseagreen: "8fbc8f",
50
+ darkslateblue: "483d8b",
51
+ darkslategray: "2f4f4f",
52
+ darkslategrey: "2f4f4f",
53
+ darkturquoise: "00ced1",
54
+ darkviolet: "9400d3",
55
+ deeppink: "ff1493",
56
+ deepskyblue: "00bfff",
57
+ dimgray: "696969",
58
+ dimgrey: "696969",
59
+ dodgerblue: "1e90ff",
60
+ firebrick: "b22222",
61
+ floralwhite: "fffaf0",
62
+ forestgreen: "228b22",
63
+ fuchsia: "ff00ff",
64
+ gainsboro: "dcdcdc",
65
+ ghostwhite: "f8f8ff",
66
+ gold: "ffd700",
67
+ goldenrod: "daa520",
68
+ gray: "808080",
69
+ green: "008000",
70
+ greenyellow: "adff2f",
71
+ grey: "808080",
72
+ honeydew: "f0fff0",
73
+ hotpink: "ff69b4",
74
+ indianred: "cd5c5c",
75
+ indigo: "4b0082",
76
+ ivory: "fffff0",
77
+ khaki: "f0e68c",
78
+ lavender: "e6e6fa",
79
+ lavenderblush: "fff0f5",
80
+ lawngreen: "7cfc00",
81
+ lemonchiffon: "fffacd",
82
+ lightblue: "add8e6",
83
+ lightcoral: "f08080",
84
+ lightcyan: "e0ffff",
85
+ lightgoldenrodyellow: "fafad2",
86
+ lightgray: "d3d3d3",
87
+ lightgreen: "90ee90",
88
+ lightgrey: "d3d3d3",
89
+ lightpink: "ffb6c1",
90
+ lightsalmon: "ffa07a",
91
+ lightseagreen: "20b2aa",
92
+ lightskyblue: "87cefa",
93
+ lightslategray: "778899",
94
+ lightslategrey: "778899",
95
+ lightsteelblue: "b0c4de",
96
+ lightyellow: "ffffe0",
97
+ lime: "00ff00",
98
+ limegreen: "32cd32",
99
+ linen: "faf0e6",
100
+ magenta: "ff00ff",
101
+ maroon: "800000",
102
+ mediumaquamarine: "66cdaa",
103
+ mediumblue: "0000cd",
104
+ mediumorchid: "ba55d3",
105
+ mediumpurple: "9370db",
106
+ mediumseagreen: "3cb371",
107
+ mediumslateblue: "7b68ee",
108
+ mediumspringgreen: "00fa9a",
109
+ mediumturquoise: "48d1cc",
110
+ mediumvioletred: "c71585",
111
+ midnightblue: "191970",
112
+ mintcream: "f5fffa",
113
+ mistyrose: "ffe4e1",
114
+ moccasin: "ffe4b5",
115
+ navajowhite: "ffdead",
116
+ navy: "000080",
117
+ oldlace: "fdf5e6",
118
+ olive: "808000",
119
+ olivedrab: "6b8e23",
120
+ orange: "ffa500",
121
+ orangered: "ff4500",
122
+ orchid: "da70d6",
123
+ palegoldenrod: "eee8aa",
124
+ palegreen: "98fb98",
125
+ paleturquoise: "afeeee",
126
+ palevioletred: "db7093",
127
+ papayawhip: "ffefd5",
128
+ peachpuff: "ffdab9",
129
+ peru: "cd853f",
130
+ pink: "ffc0cb",
131
+ plum: "dda0dd",
132
+ powderblue: "b0e0e6",
133
+ purple: "800080",
134
+ rebeccapurple: "663399",
135
+ red: "ff0000",
136
+ rosybrown: "bc8f8f",
137
+ royalblue: "4169e1",
138
+ saddlebrown: "8b4513",
139
+ salmon: "fa8072",
140
+ sandybrown: "f4a460",
141
+ seagreen: "2e8b57",
142
+ seashell: "fff5ee",
143
+ sienna: "a0522d",
144
+ silver: "c0c0c0",
145
+ skyblue: "87ceeb",
146
+ slateblue: "6a5acd",
147
+ slategray: "708090",
148
+ slategrey: "708090",
149
+ snow: "fffafa",
150
+ springgreen: "00ff7f",
151
+ steelblue: "4682b4",
152
+ tan: "d2b48c",
153
+ teal: "008080",
154
+ thistle: "d8bfd8",
155
+ tomato: "ff6347",
156
+ turquoise: "40e0d0",
157
+ violet: "ee82ee",
158
+ wheat: "f5deb3",
159
+ white: "ffffff",
160
+ whitesmoke: "f5f5f5",
161
+ yellow: "ffff00",
162
+ yellowgreen: "9acd32",
35
163
  };
36
164
 
165
+ const NAMED_COLORS: Record<string, [number, number, number]> =
166
+ Object.fromEntries(
167
+ Object.entries(CSS_NAMED_COLORS).map(([name, hex]) => [
168
+ name,
169
+ [
170
+ Number.parseInt(hex.slice(0, 2), 16),
171
+ Number.parseInt(hex.slice(2, 4), 16),
172
+ Number.parseInt(hex.slice(4, 6), 16),
173
+ ],
174
+ ])
175
+ );
176
+
37
177
  function parseChannel(value: string, max: number): number {
38
178
  const trimmed = value.trim();
39
179
  const number = Number.parseFloat(trimmed);
@@ -45,7 +185,7 @@ function parseChannel(value: string, max: number): number {
45
185
 
46
186
  /**
47
187
  * Parses hex (#rgb, #rgba, #rrggbb, #rrggbbaa), rgb()/rgba(), `transparent`
48
- * and common color names. Returns null for anything else.
188
+ * and the CSS color names. Returns null for anything else.
49
189
  */
50
190
  export function parseColor(input: string | null | undefined): RGBAColor | null {
51
191
  if (!input) {
@@ -1,9 +1,18 @@
1
1
  import type { QRProps } from "../../types";
2
2
  import { isGradient } from "../../types/color-helpers";
3
- import { DEFAULT_BGCOLOR, DEFAULT_SIZE } from "../constants";
3
+ import qrcodegen from "../codegen";
4
+ import {
5
+ DEFAULT_BGCOLOR,
6
+ DEFAULT_MARGIN,
7
+ DEFAULT_SIZE,
8
+ ERROR_LEVEL_MAP,
9
+ } from "../constants";
4
10
  import { withQRSize } from "../download";
5
11
  import { getQRAsSVGDataUri } from "../export";
6
12
  import { getFrameLayout, isFrameActive } from "../frame";
13
+ import { clampBgRadius } from "../looks";
14
+ import { getLayoutMargin } from "../qr-shape";
15
+ import { resolveErrorLevel } from "../utils";
7
16
  import { getSolidColor } from "./color";
8
17
  import { flattenOver } from "./paint";
9
18
  import { parseColor } from "./parse-color";
@@ -32,6 +41,21 @@ export function getPrintBleedColor(props: QRProps): string | null {
32
41
  const frame = getFrameLayout(PRINT_RENDER_SIZE, props.frame);
33
42
  return frame.squareEdges ? frame.color : null;
34
43
  }
44
+ // Outside rounded corners the backdrop shows, so the bleed continues it
45
+ if (props.backdrop && props.bgRadius) {
46
+ const modules = qrcodegen.QrCode.encodeText(
47
+ props.value,
48
+ ERROR_LEVEL_MAP[resolveErrorLevel(props)]
49
+ ).size;
50
+ const margin = getLayoutMargin(
51
+ modules,
52
+ props.margin ?? DEFAULT_MARGIN,
53
+ props.shape
54
+ );
55
+ if (clampBgRadius(props.bgRadius, modules, margin, props.shape) > 0) {
56
+ return getSolidColor(props.backdrop, DEFAULT_BGCOLOR);
57
+ }
58
+ }
35
59
  return getSolidColor(props.bgColor, DEFAULT_BGCOLOR);
36
60
  }
37
61
 
@@ -45,6 +45,10 @@ export interface PaintState {
45
45
  fillRule: string;
46
46
  stroke: string;
47
47
  strokeWidth: number;
48
+ /** Inherited `stroke-linejoin` (SVG's miter when unset) */
49
+ strokeLinejoin?: string;
50
+ /** Inherited `stroke-linecap` (SVG's butt when unset) */
51
+ strokeLinecap?: string;
48
52
  fontSize: number;
49
53
  fontWeight: string;
50
54
  textAnchor: string;
@@ -59,6 +63,17 @@ export interface PaintState {
59
63
  opacity?: number;
60
64
  }
61
65
 
66
+ /**
67
+ * A stroke's line join and cap as PDF and PostScript number them (0 miter
68
+ * or butt, 1 round, 2 bevel or square), for painters that draw SVG strokes.
69
+ * Both are 0 for SVG's defaults, which are also PDF's and PostScript's.
70
+ */
71
+ export function lineStyleOf(state: PaintState): { join: number; cap: number } {
72
+ const join = { round: 1, bevel: 2 }[state.strokeLinejoin?.trim() ?? ""];
73
+ const cap = { round: 1, square: 2 }[state.strokeLinecap?.trim() ?? ""];
74
+ return { join: join ?? 0, cap: cap ?? 0 };
75
+ }
76
+
62
77
  export type PaintColor = RGBAColor | null;
63
78
 
64
79
  /**
@@ -824,6 +839,9 @@ export abstract class SvgPainter {
824
839
  readStyle(node, "stroke-width") === undefined
825
840
  ? parent.strokeWidth
826
841
  : length(readStyle(node, "stroke-width"), viewport[0], 1),
842
+ strokeLinejoin:
843
+ readStyle(node, "stroke-linejoin") ?? parent.strokeLinejoin,
844
+ strokeLinecap: readStyle(node, "stroke-linecap") ?? parent.strokeLinecap,
827
845
  fontSize:
828
846
  fontSize === undefined ? parent.fontSize : length(fontSize, 16, 16),
829
847
  fontWeight: readStyle(node, "font-weight") ?? parent.fontWeight,
package/src/utils.tsx CHANGED
@@ -44,6 +44,7 @@ import { isFrameActive, wrapWithFrame } from "./frame";
44
44
  import { cloneElement, type QRNode } from "./jsx/runtime";
45
45
  import { LOGO_PLATE_INSET, LOGO_ROUNDED_RADIUS, renderLogo } from "./logo";
46
46
  import { capImageSettings } from "./logo-budget";
47
+ import { clampBgRadius, eyeShapeOf, resolveHalo, resolveShadow } from "./looks";
47
48
  import { partMarker, type QRPart, type QRPartEye } from "./part-markers";
48
49
  import { getLayoutMargin, shapeBackground, shapeDecoration } from "./qr-shape";
49
50
  import { hashString } from "./shapes";
@@ -968,6 +969,12 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
968
969
  moduleScale,
969
970
  autoLevel,
970
971
  shape,
972
+ eyeShapes,
973
+ eyeGradient,
974
+ bgRadius,
975
+ backdrop,
976
+ halo,
977
+ shadow,
971
978
  frameLabelMarkers,
972
979
  partMarkers,
973
980
  ...otherProps
@@ -1017,9 +1024,46 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
1017
1024
  // Editors find each part by its marker (partMarkers, part-markers.ts)
1018
1025
  const part = (name: QRPart, eye?: QRPartEye) =>
1019
1026
  partMarker(partMarkers, name, eye);
1027
+ // Rounded corners on a square code's background, capped by its quiet zone
1028
+ // (looks.ts); the backdrop shows outside them
1029
+ const radiusShare = clampBgRadius(
1030
+ bgRadius,
1031
+ cells.length,
1032
+ layoutMargin,
1033
+ shape
1034
+ );
1020
1035
  const outline = (px: number, fill: FillProps) => {
1021
1036
  const background = shapeBackground(shape, px);
1022
1037
  if (!background) {
1038
+ if (radiusShare > 0) {
1039
+ const radius = fmt(radiusShare * px);
1040
+ const backdropFill = backdrop ? splitAlpha(backdrop) : null;
1041
+ return (
1042
+ <>
1043
+ {backdropFill && (
1044
+ <rect
1045
+ data-qrdx-look="backdrop"
1046
+ fill={backdropFill.color}
1047
+ fillOpacity={backdropFill.opacity}
1048
+ height={px}
1049
+ width={px}
1050
+ x={0}
1051
+ y={0}
1052
+ />
1053
+ )}
1054
+ <rect
1055
+ {...fill}
1056
+ height={px}
1057
+ rx={radius}
1058
+ ry={radius}
1059
+ width={px}
1060
+ x={0}
1061
+ y={0}
1062
+ {...part("background")}
1063
+ />
1064
+ </>
1065
+ );
1066
+ }
1023
1067
  return (
1024
1068
  <rect
1025
1069
  {...fill}
@@ -1229,17 +1273,30 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
1229
1273
  idPrefix: string
1230
1274
  ) => {
1231
1275
  const normalized = normalizeColorConfig(color, fgSolid);
1232
- return hasPaintDef(normalized)
1233
- ? generateCornerGradientDef(
1234
- normalized,
1235
- cornerX,
1236
- cornerY,
1237
- cornerSize,
1238
- cornerType,
1239
- idPrefix,
1240
- size
1241
- )
1242
- : null;
1276
+ if (!hasPaintDef(normalized)) {
1277
+ return null;
1278
+ }
1279
+ // eyeGradient "code": the eye's gradient is laid over the whole code,
1280
+ // like the dots' (an eye painted with the dots' gradient shares its
1281
+ // definition, so it continues it)
1282
+ if (eyeGradient === "code" && isGradient(normalized)) {
1283
+ const sameAsDots =
1284
+ JSON.stringify(normalized) === JSON.stringify(normalizedFgColor);
1285
+ return generateGradientDef(
1286
+ normalized,
1287
+ size,
1288
+ sameAsDots ? "fg-color" : idPrefix
1289
+ );
1290
+ }
1291
+ return generateCornerGradientDef(
1292
+ normalized,
1293
+ cornerX,
1294
+ cornerY,
1295
+ cornerSize,
1296
+ cornerType,
1297
+ idPrefix,
1298
+ size
1299
+ );
1243
1300
  };
1244
1301
 
1245
1302
  // Gradient definitions for the corner squares and dots, per corner
@@ -1319,11 +1376,13 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
1319
1376
  fgSolid
1320
1377
  );
1321
1378
 
1379
+ // Each eye's frame and centre: its own shapes, else the code's
1380
+ const eyeShapeProps = { cornerEyePattern, cornerEyeDotPattern, eyeShapes };
1322
1381
  const topLeftEye = generateCornerSquarePath(
1323
1382
  topLeftX,
1324
1383
  topLeftY,
1325
1384
  cornerSize,
1326
- cornerEyePattern,
1385
+ eyeShapeOf(eyeShapeProps, "topLeft").outer,
1327
1386
  "top-left"
1328
1387
  );
1329
1388
 
@@ -1331,7 +1390,7 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
1331
1390
  topLeftX + cornerSize / 2,
1332
1391
  topLeftY + cornerSize / 2,
1333
1392
  cornerDotRadius,
1334
- cornerEyeDotPattern,
1393
+ eyeShapeOf(eyeShapeProps, "topLeft").inner,
1335
1394
  "top-left"
1336
1395
  );
1337
1396
 
@@ -1339,7 +1398,7 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
1339
1398
  topRightX,
1340
1399
  topRightY,
1341
1400
  cornerSize,
1342
- cornerEyePattern,
1401
+ eyeShapeOf(eyeShapeProps, "topRight").outer,
1343
1402
  "top-right"
1344
1403
  );
1345
1404
 
@@ -1347,7 +1406,7 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
1347
1406
  topRightX + cornerSize / 2,
1348
1407
  topRightY + cornerSize / 2,
1349
1408
  cornerDotRadius,
1350
- cornerEyeDotPattern,
1409
+ eyeShapeOf(eyeShapeProps, "topRight").inner,
1351
1410
  "top-right"
1352
1411
  );
1353
1412
 
@@ -1355,7 +1414,7 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
1355
1414
  bottomLeftX,
1356
1415
  bottomLeftY,
1357
1416
  cornerSize,
1358
- cornerEyePattern,
1417
+ eyeShapeOf(eyeShapeProps, "bottomLeft").outer,
1359
1418
  "bottom-left"
1360
1419
  );
1361
1420
 
@@ -1363,10 +1422,63 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
1363
1422
  bottomLeftX + cornerSize / 2,
1364
1423
  bottomLeftY + cornerSize / 2,
1365
1424
  cornerDotRadius,
1366
- cornerEyeDotPattern,
1425
+ eyeShapeOf(eyeShapeProps, "bottomLeft").inner,
1367
1426
  "bottom-left"
1368
1427
  );
1369
1428
 
1429
+ // The halo and the shadow (looks.ts): the dark shapes drawn once more
1430
+ // under themselves. Art modes draw their own body, so only the eyes (and
1431
+ // a shaped code's decoration) get them there. Neither carries a part
1432
+ // marker: a click lands on the shape above it.
1433
+ const resolvedHalo = resolveHalo(halo, { bgColor });
1434
+ const resolvedShadow = resolveShadow(shadow);
1435
+ const darkShapes = (eyeFillRule: "evenodd" | "nonzero") => (
1436
+ <>
1437
+ {artLayer ? null : dataCircles}
1438
+ {decorationShapes}
1439
+ <path d={topLeftEye} fillRule={eyeFillRule} />
1440
+ {topLeftDot}
1441
+ <path d={topRightEye} fillRule={eyeFillRule} />
1442
+ {topRightDot}
1443
+ <path d={bottomLeftEye} fillRule={eyeFillRule} />
1444
+ {bottomLeftDot}
1445
+ </>
1446
+ );
1447
+ let haloLayer: QRNode | null = null;
1448
+ if (resolvedHalo) {
1449
+ // A rim of the halo color: the shapes filled and stroked with it, the
1450
+ // stroke twice the width since half of it lies under the shape. The eye
1451
+ // frames fill their hole too, so the ring's light gap is halo-colored.
1452
+ const { color } = resolvedHalo;
1453
+ haloLayer = (
1454
+ <g
1455
+ data-qrdx-look="halo"
1456
+ fill={color}
1457
+ stroke={color}
1458
+ strokeLinecap="round"
1459
+ strokeLinejoin="round"
1460
+ strokeWidth={fmt(2 * resolvedHalo.width * pixelSize)}
1461
+ >
1462
+ {darkShapes("nonzero")}
1463
+ </g>
1464
+ );
1465
+ }
1466
+ let shadowLayer: QRNode | null = null;
1467
+ if (resolvedShadow) {
1468
+ // One see-through group, so overlapping shadows don't darken twice
1469
+ const { color } = splitAlpha(resolvedShadow.color);
1470
+ shadowLayer = (
1471
+ <g
1472
+ data-qrdx-look="shadow"
1473
+ fill={color}
1474
+ opacity={fmt(resolvedShadow.opacity)}
1475
+ transform={compact`translate(${resolvedShadow.dx * pixelSize},${resolvedShadow.dy * pixelSize})`}
1476
+ >
1477
+ {darkShapes("evenodd")}
1478
+ </g>
1479
+ );
1480
+ }
1481
+
1370
1482
  // QR Code content (can be used standalone or inside wrapper)
1371
1483
  const qrContent = (
1372
1484
  <>
@@ -1387,6 +1499,10 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
1387
1499
  {/* Background: the square, or a shaped code's outline */}
1388
1500
  {outline(size, bgFillValue)}
1389
1501
 
1502
+ {/* The halo and the shadow, under the shapes they copy */}
1503
+ {haloLayer}
1504
+ {shadowLayer}
1505
+
1390
1506
  {/* Data module circles */}
1391
1507
  {dataLayer}
1392
1508
 
@@ -1486,6 +1602,9 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
1486
1602
 
1487
1603
  {/* Scale all QR elements to fit template coordinate system */}
1488
1604
  <g transform={`scale(${fmt(templateSize / size, SCALE_DECIMALS)})`}>
1605
+ {haloLayer}
1606
+ {shadowLayer}
1607
+
1489
1608
  {/* Data module circles */}
1490
1609
  {dataLayer}
1491
1610
 
@@ -21,7 +21,7 @@ export interface QRCodeExportOptions {
21
21
  }
22
22
 
23
23
  export interface QRCodeDownloadOptions extends QRCodeExportOptions {
24
- /** "png" (default), "jpg", "webp", "svg", "pdf" (needs jspdf) or "eps" */
24
+ /** "png" (default), "jpg", "webp", "bmp", "ico", "gif", "svg", "pdf" (needs jspdf) or "eps" */
25
25
  format?: DownloadFormat;
26
26
  /** File name; defaults to one with the format and pixel size */
27
27
  filename?: string;
@@ -40,7 +40,7 @@ export interface QRCodeInstance {
40
40
  update(options: Partial<QRSVGOptions>): void;
41
41
  /** The code's SVG markup, as `toSVGString` writes it */
42
42
  toSVGString(): string;
43
- /** The code as a data URL: "png" (default), "jpg", "webp", "svg", "pdf" or "eps" */
43
+ /** The code as a data URL: "png" (default), "jpg", "webp", "bmp", "ico", "gif", "svg", "pdf" or "eps" */
44
44
  toDataURL(
45
45
  format?: DownloadFormat,
46
46
  options?: QRCodeExportOptions