qrdx 0.0.46 → 0.0.48

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 (212) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +358 -300
  3. package/dist/index.js +27 -7
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +27 -7
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/qr-code-canvas.js +12 -0
  8. package/dist/qr-code-canvas.js.map +1 -0
  9. package/dist/qr-code-canvas.mjs +12 -0
  10. package/dist/qr-code-canvas.mjs.map +1 -0
  11. package/dist/src/api.d.ts.map +1 -1
  12. package/dist/src/art-trace.d.ts +46 -0
  13. package/dist/src/art-trace.d.ts.map +1 -0
  14. package/dist/src/art.d.ts +138 -0
  15. package/dist/src/art.d.ts.map +1 -0
  16. package/dist/src/body-patterns.d.ts +34 -0
  17. package/dist/src/body-patterns.d.ts.map +1 -0
  18. package/dist/src/codegen.d.ts +5 -5
  19. package/dist/src/codegen.d.ts.map +1 -1
  20. package/dist/src/codeword-map.d.ts +40 -0
  21. package/dist/src/codeword-map.d.ts.map +1 -0
  22. package/dist/src/constants.d.ts +4 -7
  23. package/dist/src/constants.d.ts.map +1 -1
  24. package/dist/src/corner-dot.d.ts +3 -1
  25. package/dist/src/corner-dot.d.ts.map +1 -1
  26. package/dist/src/corner-eye.d.ts +5 -2
  27. package/dist/src/corner-eye.d.ts.map +1 -1
  28. package/dist/src/detection.d.ts.map +1 -1
  29. package/dist/src/download.d.ts +50 -6
  30. package/dist/src/download.d.ts.map +1 -1
  31. package/dist/src/eps.d.ts +62 -0
  32. package/dist/src/eps.d.ts.map +1 -0
  33. package/dist/src/frame-icons.d.ts +11 -0
  34. package/dist/src/frame-icons.d.ts.map +1 -0
  35. package/dist/src/frame-import.d.ts +61 -0
  36. package/dist/src/frame-import.d.ts.map +1 -0
  37. package/dist/src/frame-spec.d.ts +24 -0
  38. package/dist/src/frame-spec.d.ts.map +1 -0
  39. package/dist/src/frame-styles.d.ts +50 -0
  40. package/dist/src/frame-styles.d.ts.map +1 -0
  41. package/dist/src/frame.d.ts +126 -0
  42. package/dist/src/frame.d.ts.map +1 -0
  43. package/dist/src/frames/builtin.d.ts +8 -0
  44. package/dist/src/frames/builtin.d.ts.map +1 -0
  45. package/dist/src/frames/official.d.ts +18 -0
  46. package/dist/src/frames/official.d.ts.map +1 -0
  47. package/dist/src/helpers.d.ts +15 -2
  48. package/dist/src/helpers.d.ts.map +1 -1
  49. package/dist/src/index.d.ts +25 -13
  50. package/dist/src/index.d.ts.map +1 -1
  51. package/dist/src/logo-budget.d.ts +54 -0
  52. package/dist/src/logo-budget.d.ts.map +1 -0
  53. package/dist/src/logo-cleanup.d.ts +25 -0
  54. package/dist/src/logo-cleanup.d.ts.map +1 -0
  55. package/dist/src/logo.d.ts +28 -0
  56. package/dist/src/logo.d.ts.map +1 -0
  57. package/dist/src/print.d.ts +73 -0
  58. package/dist/src/print.d.ts.map +1 -0
  59. package/dist/src/qr-code-canvas.d.ts +13 -0
  60. package/dist/src/qr-code-canvas.d.ts.map +1 -0
  61. package/dist/src/qr-code.d.ts +4 -2
  62. package/dist/src/qr-code.d.ts.map +1 -1
  63. package/dist/src/qr-outline.d.ts +41 -0
  64. package/dist/src/qr-outline.d.ts.map +1 -0
  65. package/dist/src/qr-shape.d.ts +72 -0
  66. package/dist/src/qr-shape.d.ts.map +1 -0
  67. package/dist/src/scan-risk.d.ts +40 -0
  68. package/dist/src/scan-risk.d.ts.map +1 -0
  69. package/dist/src/scan-score.d.ts +154 -0
  70. package/dist/src/scan-score.d.ts.map +1 -0
  71. package/dist/src/shapes.d.ts +36 -0
  72. package/dist/src/shapes.d.ts.map +1 -0
  73. package/dist/src/silhouette.d.ts +28 -0
  74. package/dist/src/silhouette.d.ts.map +1 -0
  75. package/dist/src/utils/color.d.ts.map +1 -1
  76. package/dist/src/utils/fmt.d.ts +24 -0
  77. package/dist/src/utils/fmt.d.ts.map +1 -0
  78. package/dist/src/utils/paint.d.ts +80 -0
  79. package/dist/src/utils/paint.d.ts.map +1 -0
  80. package/dist/src/utils/parse-color.d.ts +21 -0
  81. package/dist/src/utils/parse-color.d.ts.map +1 -0
  82. package/dist/src/utils/path-data.d.ts +24 -0
  83. package/dist/src/utils/path-data.d.ts.map +1 -0
  84. package/dist/src/utils/png.d.ts +16 -0
  85. package/dist/src/utils/png.d.ts.map +1 -0
  86. package/dist/src/utils/polygon-clip.d.ts +26 -0
  87. package/dist/src/utils/polygon-clip.d.ts.map +1 -0
  88. package/dist/src/utils/print-shared.d.ts +20 -0
  89. package/dist/src/utils/print-shared.d.ts.map +1 -0
  90. package/dist/src/utils/svg-geometry.d.ts +49 -0
  91. package/dist/src/utils/svg-geometry.d.ts.map +1 -0
  92. package/dist/src/utils/svg-gradient.d.ts +59 -0
  93. package/dist/src/utils/svg-gradient.d.ts.map +1 -0
  94. package/dist/src/utils/svg-painter.d.ts +152 -0
  95. package/dist/src/utils/svg-painter.d.ts.map +1 -0
  96. package/dist/src/utils/webp.d.ts +25 -0
  97. package/dist/src/utils/webp.d.ts.map +1 -0
  98. package/dist/src/utils.d.ts +18 -2
  99. package/dist/src/utils.d.ts.map +1 -1
  100. package/dist/src/webp.d.ts +19 -0
  101. package/dist/src/webp.d.ts.map +1 -0
  102. package/dist/types/art.d.ts +64 -0
  103. package/dist/types/art.d.ts.map +1 -0
  104. package/dist/types/color.d.ts +125 -7
  105. package/dist/types/color.d.ts.map +1 -1
  106. package/dist/types/corner-dot.d.ts +52 -2
  107. package/dist/types/corner-dot.d.ts.map +1 -1
  108. package/dist/types/corner-eye.d.ts +43 -2
  109. package/dist/types/corner-eye.d.ts.map +1 -1
  110. package/dist/types/frame-spec.d.ts +3509 -0
  111. package/dist/types/frame-spec.d.ts.map +1 -0
  112. package/dist/types/frame.d.ts +68 -0
  113. package/dist/types/frame.d.ts.map +1 -0
  114. package/dist/types/image-pattern.d.ts +15 -1
  115. package/dist/types/image-pattern.d.ts.map +1 -1
  116. package/dist/types/index.d.ts +15 -9
  117. package/dist/types/index.d.ts.map +1 -1
  118. package/dist/types/index.js +6 -0
  119. package/dist/types/index.js.map +1 -0
  120. package/dist/types/index.mjs +6 -0
  121. package/dist/types/index.mjs.map +1 -0
  122. package/dist/types/qr.d.ts +1684 -4
  123. package/dist/types/qr.d.ts.map +1 -1
  124. package/dist/types/template.d.ts +2 -2
  125. package/dist/types/template.d.ts.map +1 -1
  126. package/package.json +70 -25
  127. package/src/api.tsx +67 -17
  128. package/src/art-trace.ts +554 -0
  129. package/src/art.tsx +2226 -0
  130. package/src/body-patterns.tsx +389 -0
  131. package/src/codegen.ts +10 -5
  132. package/src/codeword-map.ts +265 -0
  133. package/src/constants.ts +4 -8
  134. package/src/corner-dot.tsx +209 -33
  135. package/src/corner-eye.ts +328 -60
  136. package/src/detection.ts +5 -11
  137. package/src/download.tsx +174 -70
  138. package/src/eps.ts +701 -0
  139. package/src/frame-icons.ts +325 -0
  140. package/src/frame-import.ts +1198 -0
  141. package/src/frame-spec.ts +518 -0
  142. package/src/frame-styles.ts +1095 -0
  143. package/src/frame.tsx +630 -0
  144. package/src/frames/builtin/banner-bottom.json +58 -0
  145. package/src/frames/builtin/circle.json +81 -0
  146. package/src/frames/builtin/rounded-border.json +60 -0
  147. package/src/frames/builtin/ticket.json +51 -0
  148. package/src/frames/builtin.ts +20 -0
  149. package/src/frames/official/attendance.json +110 -0
  150. package/src/frames/official/audio-guide.json +95 -0
  151. package/src/frames/official/book-now.json +103 -0
  152. package/src/frames/official/check-in.json +110 -0
  153. package/src/frames/official/christmas.json +131 -0
  154. package/src/frames/official/donate.json +77 -0
  155. package/src/frames/official/event-ticket.json +77 -0
  156. package/src/frames/official/feedback-bubble.json +73 -0
  157. package/src/frames/official/follow-us.json +83 -0
  158. package/src/frames/official/get-the-app.json +107 -0
  159. package/src/frames/official/halloween.json +80 -0
  160. package/src/frames/official/new-year.json +94 -0
  161. package/src/frames/official/order-at-table.json +86 -0
  162. package/src/frames/official/product-info.json +119 -0
  163. package/src/frames/official/register-product.json +77 -0
  164. package/src/frames/official/review-us.json +127 -0
  165. package/src/frames/official/rsvp-card.json +112 -0
  166. package/src/frames/official/save-contact.json +117 -0
  167. package/src/frames/official/scan-to-pay.json +94 -0
  168. package/src/frames/official/shop-window.json +81 -0
  169. package/src/frames/official/sign-rider.json +81 -0
  170. package/src/frames/official/table-tent.json +75 -0
  171. package/src/frames/official/wifi-card.json +89 -0
  172. package/src/frames/official/winter.json +142 -0
  173. package/src/frames/official.ts +77 -0
  174. package/src/helpers.ts +168 -11
  175. package/src/index.tsx +150 -172
  176. package/src/logo-budget.ts +226 -0
  177. package/src/logo-cleanup.ts +146 -0
  178. package/src/logo.tsx +137 -0
  179. package/src/print.ts +794 -0
  180. package/src/qr-code-canvas.tsx +241 -0
  181. package/src/qr-code.tsx +51 -16
  182. package/src/qr-outline.ts +511 -0
  183. package/src/qr-shape.ts +255 -0
  184. package/src/scan-risk.ts +197 -0
  185. package/src/scan-score.ts +1629 -0
  186. package/src/shapes.ts +169 -0
  187. package/src/silhouette.ts +334 -0
  188. package/src/utils/color.ts +10 -1
  189. package/src/utils/fmt.ts +59 -0
  190. package/src/utils/paint.ts +317 -0
  191. package/src/utils/parse-color.ts +135 -0
  192. package/src/utils/path-data.ts +182 -0
  193. package/src/utils/png.ts +175 -0
  194. package/src/utils/polygon-clip.ts +163 -0
  195. package/src/utils/print-shared.ts +74 -0
  196. package/src/utils/svg-geometry.ts +838 -0
  197. package/src/utils/svg-gradient.ts +407 -0
  198. package/src/utils/svg-painter.ts +946 -0
  199. package/src/utils/webp.ts +556 -0
  200. package/src/utils.tsx +794 -385
  201. package/src/webp.ts +84 -0
  202. package/types/art.ts +74 -0
  203. package/types/color.ts +132 -12
  204. package/types/corner-dot.ts +41 -4
  205. package/types/corner-eye.ts +31 -4
  206. package/types/frame-spec.ts +748 -0
  207. package/types/frame.ts +67 -0
  208. package/types/image-pattern.ts +15 -0
  209. package/types/index.ts +106 -4
  210. package/types/qr.ts +180 -2
  211. package/types/template.ts +2 -2
  212. package/dist/cli.js +0 -4319
@@ -0,0 +1,1095 @@
1
+ /** biome-ignore-all lint/style/noMagicNumbers: frame proportions */
2
+ // Layouts for the frame styles added after the original five. Each returns
3
+ // plain shapes (rects, polygons, path data) and labels, so the SVG, canvas,
4
+ // PDF and EPS outputs draw the same artwork. Colors are always opaque (tints
5
+ // are mixed, not layered with transparency) because EPS has no transparency.
6
+ import type { FrameStyle, QRFrame } from "../types";
7
+ import type {
8
+ FrameBox,
9
+ FrameLabel,
10
+ FrameLayout,
11
+ FramePath,
12
+ FramePolygon,
13
+ FrameRect,
14
+ } from "./frame";
15
+ import { circlePath, type Point, roundedRectPath } from "./shapes";
16
+ import { compact, roundTo } from "./utils/fmt";
17
+ import { parseColor } from "./utils/parse-color";
18
+
19
+ export const SHAPED_FRAME_STYLES = [
20
+ "banner-top-bottom",
21
+ "speech-bubble-top",
22
+ "chat-bubble",
23
+ "circle",
24
+ "polaroid",
25
+ "phone",
26
+ "ticket",
27
+ "badge",
28
+ "envelope",
29
+ "tag",
30
+ "menu-card",
31
+ "sticker",
32
+ "gradient-border",
33
+ "focus",
34
+ ] as const satisfies readonly FrameStyle[];
35
+
36
+ export type ShapedFrameStyle = (typeof SHAPED_FRAME_STYLES)[number];
37
+
38
+ export function isShapedFrameStyle(
39
+ style: FrameStyle
40
+ ): style is ShapedFrameStyle {
41
+ return (SHAPED_FRAME_STYLES as readonly string[]).includes(style);
42
+ }
43
+
44
+ /** Default colors of "gradient-border" when `color` / `secondaryColor` are unset. */
45
+ export const GRADIENT_FRAME_DEFAULTS = { from: "#7c3aed", to: "#db2777" };
46
+
47
+ const WHITE = "#FFFFFF";
48
+
49
+ // ── Text measuring ────────────────────────────────────────────────────────
50
+
51
+ /** Rough em width of one character in a bold sans-serif. */
52
+ export function charEm(char: string): number {
53
+ if (char === " ") {
54
+ return 0.3;
55
+ }
56
+ if (/[MWmw@%]/.test(char)) {
57
+ return 0.92;
58
+ }
59
+ if (/[A-Z0-9#&]/.test(char)) {
60
+ return 0.72;
61
+ }
62
+ if (/[il.,:;!'|1]/.test(char)) {
63
+ return 0.32;
64
+ }
65
+ return 0.6;
66
+ }
67
+
68
+ // Rough em widths for a bold sans-serif, used to fit labels without
69
+ // measuring text (measuring needs a DOM).
70
+ export function estimateTextEm(text: string): number {
71
+ let em = 0;
72
+ for (const char of text) {
73
+ em += charEm(char);
74
+ }
75
+ return Math.max(em, 1);
76
+ }
77
+
78
+ // ── Color ─────────────────────────────────────────────────────────────────
79
+
80
+ const hex = (value: number) =>
81
+ Math.round(Math.min(255, Math.max(0, value)))
82
+ .toString(16)
83
+ .padStart(2, "0");
84
+
85
+ /**
86
+ * Opaque mix of two colors (`amount` 0 = `from`, 1 = `to`). Frames use solid
87
+ * tints instead of transparency, because EPS has no transparency.
88
+ */
89
+ export function mixFrameColors(
90
+ from: string,
91
+ to: string,
92
+ amount: number
93
+ ): string {
94
+ const a = parseColor(from) ?? { r: 0, g: 0, b: 0, a: 1 };
95
+ const b = parseColor(to) ?? { r: 255, g: 255, b: 255, a: 1 };
96
+ const t = Math.min(1, Math.max(0, amount));
97
+ return `#${hex(a.r + (b.r - a.r) * t)}${hex(a.g + (b.g - a.g) * t)}${hex(a.b + (b.b - a.b) * t)}`;
98
+ }
99
+
100
+ // ── Shape helpers ─────────────────────────────────────────────────────────
101
+
102
+ const box = (
103
+ x: number,
104
+ y: number,
105
+ width: number,
106
+ height: number,
107
+ radius = 0
108
+ ): FrameBox => ({ x, y, width, height, radius });
109
+
110
+ const rect = (
111
+ x: number,
112
+ y: number,
113
+ width: number,
114
+ height: number,
115
+ radius: number,
116
+ fill: string
117
+ ): FrameRect => ({ type: "rect", ...box(x, y, width, height, radius), fill });
118
+
119
+ const ring = (outer: FrameBox, hole: FrameBox, fill: string): FrameRect => ({
120
+ type: "rect",
121
+ ...outer,
122
+ fill,
123
+ hole,
124
+ });
125
+
126
+ const polygon = (points: Point[], fill: string): FramePolygon => ({
127
+ type: "polygon",
128
+ points,
129
+ fill,
130
+ });
131
+
132
+ const path = (
133
+ d: string,
134
+ fill: string,
135
+ fillRule: "nonzero" | "evenodd" = "nonzero"
136
+ ): FramePath => ({ type: "path", d, fill, fillRule });
137
+
138
+ const present = (...labels: (FrameLabel | null)[]): FrameLabel[] =>
139
+ labels.filter((label): label is FrameLabel => label !== null);
140
+
141
+ // ── Layouts ───────────────────────────────────────────────────────────────
142
+
143
+ export interface FrameStyleContext {
144
+ /** Width of the QR code (margin included) */
145
+ size: number;
146
+ frame: QRFrame;
147
+ /** Frame color (`frame.color` or black) */
148
+ color: string;
149
+ /** Solid page color behind the code */
150
+ background: string;
151
+ text: string;
152
+ secondaryText: string;
153
+ gap: number;
154
+ border: number;
155
+ band: number;
156
+ fontScale: number;
157
+ /**
158
+ * Label fitted in a row: font from the row height, shrunk to `maxWidth`.
159
+ * `field` is the frame text it draws ("text" unless given).
160
+ */
161
+ fitLabel: (
162
+ text: string,
163
+ centerX: number,
164
+ centerY: number,
165
+ rowHeight: number,
166
+ maxWidth: number,
167
+ color: string,
168
+ field?: "text" | "secondaryText"
169
+ ) => FrameLabel | null;
170
+ }
171
+
172
+ type Layout = (ctx: FrameStyleContext) => FrameLayout;
173
+
174
+ const bannerTopBottom: Layout = (ctx) => {
175
+ const { size, gap, border, band, color, background, frame, fitLabel } = ctx;
176
+ const width = size + 2 * (border + gap);
177
+ const innerWidth = width - 2 * border;
178
+ const innerHeight = size + 2 * gap;
179
+ const height = band + innerHeight + band;
180
+ const labelWidth = innerWidth - 2 * gap;
181
+ const textColor = frame.textColor || WHITE;
182
+ return {
183
+ width,
184
+ height,
185
+ qrX: border + gap,
186
+ qrY: band + gap,
187
+ qrSize: size,
188
+ shapes: [
189
+ rect(border, band, innerWidth, innerHeight, 0, background),
190
+ ring(
191
+ box(0, 0, width, height),
192
+ box(border, band, innerWidth, innerHeight),
193
+ color
194
+ ),
195
+ ],
196
+ label: fitLabel(ctx.text, width / 2, band / 2, band, labelWidth, textColor),
197
+ extraLabels: present(
198
+ fitLabel(
199
+ ctx.secondaryText,
200
+ width / 2,
201
+ band + innerHeight + band / 2,
202
+ band,
203
+ labelWidth,
204
+ textColor,
205
+ "secondaryText"
206
+ )
207
+ ),
208
+ squareEdges: true,
209
+ color,
210
+ };
211
+ };
212
+
213
+ const speechBubbleTop: Layout = (ctx) => {
214
+ const { size, gap, border, band, color, background, frame, fitLabel } = ctx;
215
+ const width = size + 2 * (border + gap);
216
+ const innerWidth = width - 2 * border;
217
+ const radius = size * 0.07;
218
+ const innerRadius = Math.max(radius - border, 0);
219
+ const spacing = size * 0.025;
220
+ const pointer = size * 0.08;
221
+ const cardY = band + pointer + spacing;
222
+ return {
223
+ width,
224
+ height: cardY + width,
225
+ qrX: border + gap,
226
+ qrY: cardY + border + gap,
227
+ qrSize: size,
228
+ shapes: [
229
+ rect(0, 0, width, band, band / 2, color),
230
+ polygon(
231
+ [
232
+ // Base dips into the pill so no hairline shows between them
233
+ [width / 2 - pointer, band - pointer / 2],
234
+ [width / 2 + pointer, band - pointer / 2],
235
+ [width / 2, band + pointer],
236
+ ],
237
+ color
238
+ ),
239
+ rect(
240
+ border,
241
+ cardY + border,
242
+ innerWidth,
243
+ innerWidth,
244
+ innerRadius,
245
+ background
246
+ ),
247
+ ring(
248
+ box(0, cardY, width, width, radius),
249
+ box(border, cardY + border, innerWidth, innerWidth, innerRadius),
250
+ color
251
+ ),
252
+ ],
253
+ label: fitLabel(
254
+ ctx.text,
255
+ width / 2,
256
+ band / 2,
257
+ band,
258
+ innerWidth - 2 * gap,
259
+ frame.textColor || WHITE
260
+ ),
261
+ squareEdges: false,
262
+ color,
263
+ };
264
+ };
265
+
266
+ const chatBubble: Layout = (ctx) => {
267
+ const { size, gap, border, color, background, frame, fitLabel } = ctx;
268
+ const width = size + 2 * (border + gap);
269
+ const innerWidth = width - 2 * border;
270
+ const radius = size * 0.12;
271
+ const windowHeight = size + 2 * gap;
272
+ const row = ctx.text ? size * 0.2 : border;
273
+ const bubbleHeight = border + windowHeight + row;
274
+ const tail = size * 0.13;
275
+ const top = bubbleHeight - size * 0.02;
276
+ return {
277
+ width,
278
+ height: bubbleHeight + tail,
279
+ qrX: border + gap,
280
+ qrY: border + gap,
281
+ qrSize: size,
282
+ shapes: [
283
+ rect(0, 0, width, bubbleHeight, radius, color),
284
+ path(
285
+ compact`M${width * 0.13} ${top}L${width * 0.05} ${bubbleHeight + tail}` +
286
+ compact`Q${width * 0.16} ${bubbleHeight + tail * 0.45} ${width * 0.32} ${top}Z`,
287
+ color
288
+ ),
289
+ rect(
290
+ border,
291
+ border,
292
+ innerWidth,
293
+ windowHeight,
294
+ Math.max(radius - border, 0),
295
+ background
296
+ ),
297
+ ],
298
+ label: fitLabel(
299
+ ctx.text,
300
+ width / 2,
301
+ border + windowHeight + row / 2,
302
+ row,
303
+ innerWidth - 2 * gap,
304
+ frame.textColor || WHITE
305
+ ),
306
+ squareEdges: false,
307
+ color,
308
+ };
309
+ };
310
+
311
+ /**
312
+ * Letters of `text` set along a circle of `radius` around (cx, cy): over the
313
+ * top reading clockwise, or along the bottom reading left to right, upright.
314
+ */
315
+ export function arcLabels(
316
+ text: string,
317
+ cx: number,
318
+ cy: number,
319
+ radius: number,
320
+ fontSize: number,
321
+ where: "top" | "bottom",
322
+ color: string,
323
+ /** The frame text the letters draw (FrameLabel.field) */
324
+ field: string
325
+ ): FrameLabel[] {
326
+ const chars = [...text];
327
+ const spacing = fontSize * 0.08;
328
+ const widths = chars.map((char) => charEm(char) * fontSize);
329
+ const total =
330
+ widths.reduce((sum, width) => sum + width, 0) +
331
+ spacing * Math.max(0, chars.length - 1);
332
+ // Center the capitals on `radius`: the baseline sits half a cap height in
333
+ // from the outside of the glyphs.
334
+ const baseline =
335
+ where === "top" ? radius - fontSize * 0.35 : radius + fontSize * 0.35;
336
+ const labels: FrameLabel[] = [];
337
+ let offset = 0;
338
+ chars.forEach((char, index) => {
339
+ const width = widths[index] as number;
340
+ const along = (offset + width / 2) / baseline;
341
+ offset += width + spacing;
342
+ if (char.trim() === "") {
343
+ return;
344
+ }
345
+ const angle =
346
+ where === "top"
347
+ ? -Math.PI / 2 - total / 2 / baseline + along
348
+ : Math.PI / 2 + total / 2 / baseline - along;
349
+ labels.push({
350
+ text: char,
351
+ x: cx + baseline * Math.cos(angle),
352
+ y: cy + baseline * Math.sin(angle),
353
+ fontSize,
354
+ maxWidth: fontSize * 2,
355
+ color,
356
+ rotate: (angle * 180) / Math.PI + (where === "top" ? 90 : -90),
357
+ field,
358
+ });
359
+ });
360
+ return labels;
361
+ }
362
+
363
+ const circle: Layout = (ctx) => {
364
+ const { size, gap, color, background, frame, fontScale } = ctx;
365
+ // Light disc that clears the code's corners by most of a frame gap
366
+ const inner = size * Math.SQRT1_2 + gap * 0.9;
367
+ const thickness = size * 0.21;
368
+ const outer = inner + thickness;
369
+ const middle = inner + thickness / 2;
370
+ const center = outer;
371
+ const textColor = frame.textColor || WHITE;
372
+ // Each label may use up to 140° of the ring
373
+ const arc = middle * ((140 * Math.PI) / 180);
374
+ const fontFor = (text: string) =>
375
+ Math.min(
376
+ thickness * 0.5 * fontScale,
377
+ arc / (estimateTextEm(text) + 0.08 * text.length)
378
+ );
379
+ const top = ctx.text
380
+ ? arcLabels(
381
+ ctx.text,
382
+ center,
383
+ center,
384
+ middle,
385
+ fontFor(ctx.text),
386
+ "top",
387
+ textColor,
388
+ "text"
389
+ )
390
+ : [];
391
+ const bottom = ctx.secondaryText
392
+ ? arcLabels(
393
+ ctx.secondaryText,
394
+ center,
395
+ center,
396
+ middle,
397
+ fontFor(ctx.secondaryText),
398
+ "bottom",
399
+ textColor,
400
+ "secondaryText"
401
+ )
402
+ : [];
403
+ const dot = thickness * 0.07;
404
+ return {
405
+ width: 2 * outer,
406
+ height: 2 * outer,
407
+ qrX: center - size / 2,
408
+ qrY: center - size / 2,
409
+ qrSize: size,
410
+ shapes: [
411
+ path(circlePath(center, center, inner), background),
412
+ path(
413
+ circlePath(center, center, outer) + circlePath(center, center, inner),
414
+ color,
415
+ "evenodd"
416
+ ),
417
+ path(
418
+ circlePath(center - middle, center, dot) +
419
+ circlePath(center + middle, center, dot),
420
+ textColor
421
+ ),
422
+ ],
423
+ label: null,
424
+ extraLabels: [...top, ...bottom],
425
+ squareEdges: false,
426
+ color,
427
+ };
428
+ };
429
+
430
+ const polaroid: Layout = (ctx) => {
431
+ const { size, gap, color, background, frame, fitLabel } = ctx;
432
+ const side = size * 0.07;
433
+ const photo = size + 2 * gap;
434
+ const bottom = size * 0.3;
435
+ const shadow = size * 0.025;
436
+ const cardWidth = photo + 2 * side;
437
+ const cardHeight = side + photo + bottom;
438
+ const radius = size * 0.015;
439
+ return {
440
+ width: cardWidth + shadow,
441
+ height: cardHeight + shadow,
442
+ qrX: side + gap,
443
+ qrY: side + gap,
444
+ qrSize: size,
445
+ shapes: [
446
+ rect(
447
+ shadow,
448
+ shadow,
449
+ cardWidth,
450
+ cardHeight,
451
+ radius,
452
+ mixFrameColors(color, WHITE, 0.72)
453
+ ),
454
+ rect(0, 0, cardWidth, cardHeight, radius, color),
455
+ rect(side, side, photo, photo, 0, background),
456
+ ],
457
+ label: fitLabel(
458
+ ctx.text,
459
+ cardWidth / 2,
460
+ side + photo + bottom / 2,
461
+ bottom * 0.8,
462
+ photo - 2 * gap,
463
+ frame.textColor || WHITE
464
+ ),
465
+ squareEdges: false,
466
+ color,
467
+ };
468
+ };
469
+
470
+ const phone: Layout = (ctx) => {
471
+ const { size, gap, color, background, frame, fitLabel } = ctx;
472
+ const side = size * 0.05;
473
+ const topBezel = size * 0.17;
474
+ const bottomBezel = size * 0.15;
475
+ const row = ctx.text ? size * 0.17 : 0;
476
+ const screenWidth = size + 2 * gap;
477
+ const screenHeight = gap + size + (ctx.text ? gap * 0.5 + row : gap);
478
+ const width = screenWidth + 2 * side;
479
+ const height = topBezel + screenHeight + bottomBezel;
480
+ const speaker = size * 0.036;
481
+ const homeBar = size * 0.03;
482
+ return {
483
+ width,
484
+ height,
485
+ qrX: side + gap,
486
+ qrY: topBezel + gap,
487
+ qrSize: size,
488
+ shapes: [
489
+ rect(0, 0, width, height, size * 0.17, color),
490
+ rect(side, topBezel, screenWidth, screenHeight, size * 0.06, background),
491
+ rect(
492
+ width / 2 - size * 0.11,
493
+ topBezel / 2 - speaker / 2,
494
+ size * 0.22,
495
+ speaker,
496
+ speaker / 2,
497
+ background
498
+ ),
499
+ rect(
500
+ width / 2 - size * 0.15,
501
+ topBezel + screenHeight + bottomBezel / 2 - homeBar / 2,
502
+ size * 0.3,
503
+ homeBar,
504
+ homeBar / 2,
505
+ background
506
+ ),
507
+ ],
508
+ label: fitLabel(
509
+ ctx.text,
510
+ width / 2,
511
+ topBezel + gap + size + gap * 0.5 + row / 2,
512
+ row,
513
+ screenWidth - 2 * gap,
514
+ frame.textColor || color
515
+ ),
516
+ squareEdges: false,
517
+ color,
518
+ };
519
+ };
520
+
521
+ const ticket: Layout = (ctx) => {
522
+ const { size, gap, band, color, background, frame, fitLabel } = ctx;
523
+ const side = size * 0.05;
524
+ const windowWidth = size + 2 * gap;
525
+ const width = windowWidth + 2 * side;
526
+ // Rounded first: the notches are half circles from perforation − notch to
527
+ // perforation + notch, which must be exactly twice their radius apart
528
+ const perforation = roundTo(side + windowWidth + side * 1.2);
529
+ const height = perforation + band;
530
+ const notch = roundTo(size * 0.055);
531
+ const r = size * 0.04;
532
+ const body =
533
+ compact`M${r} 0H${width - r}A${r} ${r} 0 0 1 ${width} ${r}` +
534
+ compact`V${perforation - notch}A${notch} ${notch} 0 0 0 ${width} ${perforation + notch}` +
535
+ compact`V${height - r}A${r} ${r} 0 0 1 ${width - r} ${height}` +
536
+ compact`H${r}A${r} ${r} 0 0 1 0 ${height - r}` +
537
+ compact`V${perforation + notch}A${notch} ${notch} 0 0 0 0 ${perforation - notch}` +
538
+ compact`V${r}A${r} ${r} 0 0 1 ${r} 0Z`;
539
+ const dashes: string[] = [];
540
+ const dash = size * 0.03;
541
+ const dashGap = size * 0.022;
542
+ const thickness = size * 0.012;
543
+ for (
544
+ let x = notch + dashGap;
545
+ x + dash <= width - notch - dashGap / 2;
546
+ x += dash + dashGap
547
+ ) {
548
+ dashes.push(
549
+ roundedRectPath(x, perforation - thickness / 2, dash, thickness)
550
+ );
551
+ }
552
+ return {
553
+ width,
554
+ height,
555
+ qrX: side + gap,
556
+ qrY: side + gap,
557
+ qrSize: size,
558
+ shapes: [
559
+ path(body, color),
560
+ rect(side, side, windowWidth, windowWidth, size * 0.02, background),
561
+ path(dashes.join(""), background),
562
+ ],
563
+ label: fitLabel(
564
+ ctx.text,
565
+ width / 2,
566
+ perforation + band / 2,
567
+ band,
568
+ windowWidth - 2 * gap,
569
+ frame.textColor || WHITE
570
+ ),
571
+ squareEdges: false,
572
+ color,
573
+ };
574
+ };
575
+
576
+ const badge: Layout = (ctx) => {
577
+ const { size, gap, border, band, color, background, frame, fitLabel } = ctx;
578
+ const extend = size * 0.18;
579
+ const fold = size * 0.05;
580
+ const cardWidth = size + 2 * (border + gap);
581
+ const radius = size * 0.06;
582
+ const innerRadius = Math.max(radius - border, 0);
583
+ const width = cardWidth + 2 * extend;
584
+ const ribbonY = cardWidth - border;
585
+ const frontX = extend * 0.5;
586
+ const tailY = ribbonY + fold;
587
+ const tailX = frontX + fold * 2;
588
+ const notch = extend * 0.28;
589
+ const tail = mixFrameColors(color, "#000000", 0.28);
590
+ const crease = mixFrameColors(color, "#000000", 0.5);
591
+ return {
592
+ width,
593
+ height: tailY + band,
594
+ qrX: extend + border + gap,
595
+ qrY: border + gap,
596
+ qrSize: size,
597
+ shapes: [
598
+ polygon(
599
+ [
600
+ [0, tailY],
601
+ [tailX, tailY],
602
+ [tailX, tailY + band],
603
+ [0, tailY + band],
604
+ [notch, tailY + band / 2],
605
+ ],
606
+ tail
607
+ ),
608
+ polygon(
609
+ [
610
+ [width, tailY],
611
+ [width - notch, tailY + band / 2],
612
+ [width, tailY + band],
613
+ [width - tailX, tailY + band],
614
+ [width - tailX, tailY],
615
+ ],
616
+ tail
617
+ ),
618
+ polygon(
619
+ [
620
+ [frontX, ribbonY + band],
621
+ [frontX + fold * 1.6, ribbonY + band + fold],
622
+ [frontX, ribbonY + band + fold],
623
+ ],
624
+ crease
625
+ ),
626
+ polygon(
627
+ [
628
+ [width - frontX, ribbonY + band],
629
+ [width - frontX, ribbonY + band + fold],
630
+ [width - frontX - fold * 1.6, ribbonY + band + fold],
631
+ ],
632
+ crease
633
+ ),
634
+ rect(
635
+ extend + border,
636
+ border,
637
+ cardWidth - 2 * border,
638
+ cardWidth - 2 * border,
639
+ innerRadius,
640
+ background
641
+ ),
642
+ ring(
643
+ box(extend, 0, cardWidth, cardWidth, radius),
644
+ box(
645
+ extend + border,
646
+ border,
647
+ cardWidth - 2 * border,
648
+ cardWidth - 2 * border,
649
+ innerRadius
650
+ ),
651
+ color
652
+ ),
653
+ rect(frontX, ribbonY, width - 2 * frontX, band, 0, color),
654
+ ],
655
+ label: fitLabel(
656
+ ctx.text,
657
+ width / 2,
658
+ ribbonY + band / 2,
659
+ band,
660
+ width - 2 * frontX - 2 * gap,
661
+ frame.textColor || WHITE
662
+ ),
663
+ squareEdges: false,
664
+ color,
665
+ };
666
+ };
667
+
668
+ const envelope: Layout = (ctx) => {
669
+ const { size, gap, band, color, background, frame, fitLabel } = ctx;
670
+ const side = size * 0.08;
671
+ const letterWidth = size + 2 * gap;
672
+ const width = letterWidth + 2 * side;
673
+ const letterY = size * 0.05;
674
+ const pocketY = letterY + gap + size + gap * 0.6;
675
+ const dip = size * 0.14;
676
+ const height = pocketY + dip + band + size * 0.02;
677
+ const backY = letterY + size * 0.32;
678
+ const outline = size * 0.012;
679
+ const letterHeight = pocketY + dip - letterY;
680
+ return {
681
+ width,
682
+ height,
683
+ qrX: side + gap,
684
+ qrY: letterY + gap,
685
+ qrSize: size,
686
+ shapes: [
687
+ rect(
688
+ 0,
689
+ backY,
690
+ width,
691
+ height - backY,
692
+ 0,
693
+ mixFrameColors(color, WHITE, 0.45)
694
+ ),
695
+ polygon(
696
+ [
697
+ [0, backY],
698
+ [width / 2, 0],
699
+ [width, backY],
700
+ ],
701
+ mixFrameColors(color, WHITE, 0.25)
702
+ ),
703
+ rect(side, letterY, letterWidth, letterHeight, 0, background),
704
+ ring(
705
+ box(
706
+ side - outline,
707
+ letterY - outline,
708
+ letterWidth + 2 * outline,
709
+ letterHeight + outline
710
+ ),
711
+ box(side, letterY, letterWidth, letterHeight),
712
+ color
713
+ ),
714
+ polygon(
715
+ [
716
+ [0, pocketY],
717
+ [width / 2, pocketY + dip],
718
+ [width, pocketY],
719
+ [width, height],
720
+ [0, height],
721
+ ],
722
+ color
723
+ ),
724
+ ],
725
+ label: fitLabel(
726
+ ctx.text,
727
+ width / 2,
728
+ pocketY + dip + band / 2,
729
+ band,
730
+ letterWidth - 2 * gap,
731
+ frame.textColor || WHITE
732
+ ),
733
+ squareEdges: false,
734
+ color,
735
+ };
736
+ };
737
+
738
+ const tag: Layout = (ctx) => {
739
+ const { size, gap, band, color, background, frame, fitLabel } = ctx;
740
+ const side = size * 0.06;
741
+ const windowWidth = size + 2 * gap;
742
+ const width = windowWidth + 2 * side;
743
+ const top = size * 0.24;
744
+ const hole = size * 0.04;
745
+ const holeY = top * 0.48;
746
+ const chamfer = size * 0.14;
747
+ const row = ctx.text ? band : side;
748
+ const height = top + windowWidth + row;
749
+ const r = size * 0.04;
750
+ const body =
751
+ compact`M${chamfer} 0H${width - chamfer}L${width} ${chamfer}` +
752
+ compact`V${height - r}A${r} ${r} 0 0 1 ${width - r} ${height}` +
753
+ compact`H${r}A${r} ${r} 0 0 1 0 ${height - r}V${chamfer}Z` +
754
+ circlePath(width / 2, holeY, hole);
755
+ return {
756
+ width,
757
+ height,
758
+ qrX: side + gap,
759
+ qrY: top + gap,
760
+ qrSize: size,
761
+ shapes: [
762
+ path(body, color, "evenodd"),
763
+ path(
764
+ circlePath(width / 2, holeY, hole * 1.7) +
765
+ circlePath(width / 2, holeY, hole),
766
+ mixFrameColors(color, WHITE, 0.35),
767
+ "evenodd"
768
+ ),
769
+ rect(side, top, windowWidth, windowWidth, size * 0.02, background),
770
+ ],
771
+ label: fitLabel(
772
+ ctx.text,
773
+ width / 2,
774
+ top + windowWidth + row / 2,
775
+ row,
776
+ windowWidth - 2 * gap,
777
+ frame.textColor || WHITE
778
+ ),
779
+ squareEdges: false,
780
+ color,
781
+ };
782
+ };
783
+
784
+ const menuCard: Layout = (ctx) => {
785
+ const { size, color, background, frame, fitLabel } = ctx;
786
+ const pad = size * 0.13;
787
+ const header = ctx.text ? size * 0.26 : pad;
788
+ const footer = ctx.secondaryText ? size * 0.2 : pad;
789
+ const width = size + 2 * pad;
790
+ const height = header + size + footer;
791
+ const radius = size * 0.03;
792
+ const rule = size * 0.022;
793
+ const inset = size * 0.045;
794
+ const hairline = size * 0.008;
795
+ const textColor = frame.textColor || color;
796
+ const shapes: FrameLayout["shapes"] = [
797
+ rect(0, 0, width, height, radius, background),
798
+ ring(
799
+ box(0, 0, width, height, radius),
800
+ box(
801
+ rule,
802
+ rule,
803
+ width - 2 * rule,
804
+ height - 2 * rule,
805
+ Math.max(radius - rule, 0)
806
+ ),
807
+ color
808
+ ),
809
+ ring(
810
+ box(inset, inset, width - 2 * inset, height - 2 * inset),
811
+ box(
812
+ inset + hairline,
813
+ inset + hairline,
814
+ width - 2 * (inset + hairline),
815
+ height - 2 * (inset + hairline)
816
+ ),
817
+ color
818
+ ),
819
+ ];
820
+ if (ctx.text) {
821
+ const y = header - size * 0.075;
822
+ const diamond = size * 0.022;
823
+ shapes.push(
824
+ rect(width * 0.3, y - hairline / 2, width * 0.4, hairline, 0, color),
825
+ polygon(
826
+ [
827
+ [width / 2, y - diamond],
828
+ [width / 2 + diamond, y],
829
+ [width / 2, y + diamond],
830
+ [width / 2 - diamond, y],
831
+ ],
832
+ color
833
+ )
834
+ );
835
+ }
836
+ return {
837
+ width,
838
+ height,
839
+ qrX: pad,
840
+ qrY: header,
841
+ qrSize: size,
842
+ shapes,
843
+ label: fitLabel(
844
+ ctx.text,
845
+ width / 2,
846
+ size * 0.115,
847
+ size * 0.17,
848
+ width - 2 * pad,
849
+ textColor
850
+ ),
851
+ extraLabels: present(
852
+ fitLabel(
853
+ ctx.secondaryText,
854
+ width / 2,
855
+ header + size + footer * 0.45,
856
+ footer * 0.8,
857
+ width - 2 * pad,
858
+ textColor,
859
+ "secondaryText"
860
+ )
861
+ ),
862
+ squareEdges: false,
863
+ color,
864
+ };
865
+ };
866
+
867
+ const sticker: Layout = (ctx) => {
868
+ const { size, gap, color, background, frame, fitLabel } = ctx;
869
+ const cut = size * 0.025;
870
+ const thick = size * 0.07;
871
+ const shadow = size * 0.03;
872
+ const radius = size * 0.13;
873
+ const row = ctx.text ? size * 0.17 : 0;
874
+ // A wider light gap than other frames: the thick dark rim sits close to
875
+ // the finder corners otherwise
876
+ const inset = gap * 1.25;
877
+ const face = size + 2 * inset;
878
+ const bodyWidth = face + 2 * thick;
879
+ const bodyHeight = face + 2 * thick + row;
880
+ const outerWidth = bodyWidth + 2 * cut;
881
+ const outerHeight = bodyHeight + 2 * cut;
882
+ return {
883
+ width: outerWidth + shadow,
884
+ height: outerHeight + shadow,
885
+ qrX: cut + thick + inset,
886
+ qrY: cut + thick + inset,
887
+ qrSize: size,
888
+ shapes: [
889
+ rect(
890
+ shadow,
891
+ shadow,
892
+ outerWidth,
893
+ outerHeight,
894
+ radius + cut,
895
+ mixFrameColors(color, WHITE, 0.7)
896
+ ),
897
+ rect(0, 0, outerWidth, outerHeight, radius + cut, WHITE),
898
+ rect(cut, cut, bodyWidth, bodyHeight, radius, color),
899
+ rect(cut + thick, cut + thick, face, face, size * 0.04, background),
900
+ ],
901
+ label: fitLabel(
902
+ ctx.text,
903
+ cut + bodyWidth / 2,
904
+ cut + thick + face + (thick + row) / 2,
905
+ thick + row,
906
+ face - 2 * gap,
907
+ frame.textColor || WHITE
908
+ ),
909
+ squareEdges: false,
910
+ color,
911
+ };
912
+ };
913
+
914
+ /**
915
+ * Distance from the top edge of a rounded rect (x0..x0+width, corner radius
916
+ * r) down to its outline at `x`.
917
+ */
918
+ function edgeInset(x: number, x0: number, width: number, r: number): number {
919
+ const dx =
920
+ x < x0 + r ? x0 + r - x : x > x0 + width - r ? x - (x0 + width - r) : 0;
921
+ return r - Math.sqrt(Math.max(0, r * r - Math.min(dx, r) ** 2));
922
+ }
923
+
924
+ /**
925
+ * A rounded ring split into thin vertical strips, each a solid color stepped
926
+ * from `from` to `to`, so the gradient looks the same in every output.
927
+ */
928
+ function gradientRing(
929
+ width: number,
930
+ height: number,
931
+ radius: number,
932
+ border: number,
933
+ from: string,
934
+ to: string,
935
+ steps = 48
936
+ ): FramePolygon[] {
937
+ const innerRadius = Math.max(radius - border, 0);
938
+ const innerWidth = width - 2 * border;
939
+ const cuts = new Set<number>([border, width - border]);
940
+ for (let i = 0; i <= steps; i++) {
941
+ cuts.add((width * i) / steps);
942
+ }
943
+ const xs = [...cuts].sort((a, b) => a - b);
944
+ // Overlap neighbours slightly so no anti-aliasing seam shows
945
+ const overlap = width * 0.002;
946
+ const samples = 5;
947
+ const outerTop = (x: number) => edgeInset(x, 0, width, radius);
948
+ const innerTop = (x: number) =>
949
+ border + edgeInset(x, border, innerWidth, innerRadius);
950
+ const strips: FramePolygon[] = [];
951
+ for (let i = 0; i + 1 < xs.length; i++) {
952
+ const a = xs[i] as number;
953
+ const b = Math.min(
954
+ width,
955
+ (xs[i + 1] as number) + (i + 2 < xs.length ? overlap : 0)
956
+ );
957
+ const fill = mixFrameColors(from, to, (a + b) / 2 / width);
958
+ const along = (reverse: boolean) =>
959
+ Array.from({ length: samples }, (_, k) => {
960
+ const t = k / (samples - 1);
961
+ return reverse ? b + (a - b) * t : a + (b - a) * t;
962
+ });
963
+ const middle =
964
+ a >= border - 1e-9 && (xs[i + 1] as number) <= width - border + 1e-9;
965
+ if (middle) {
966
+ strips.push(
967
+ polygon(
968
+ [
969
+ ...along(false).map((x): Point => [x, outerTop(x)]),
970
+ ...along(true).map((x): Point => [x, innerTop(x)]),
971
+ ],
972
+ fill
973
+ ),
974
+ polygon(
975
+ [
976
+ ...along(false).map((x): Point => [x, height - innerTop(x)]),
977
+ ...along(true).map((x): Point => [x, height - outerTop(x)]),
978
+ ],
979
+ fill
980
+ )
981
+ );
982
+ } else {
983
+ strips.push(
984
+ polygon(
985
+ [
986
+ ...along(false).map((x): Point => [x, outerTop(x)]),
987
+ ...along(true).map((x): Point => [x, height - outerTop(x)]),
988
+ ],
989
+ fill
990
+ )
991
+ );
992
+ }
993
+ }
994
+ return strips;
995
+ }
996
+
997
+ const gradientBorder: Layout = (ctx) => {
998
+ const { size, gap, background, frame, fitLabel } = ctx;
999
+ const from = frame.color || GRADIENT_FRAME_DEFAULTS.from;
1000
+ const to = frame.secondaryColor || GRADIENT_FRAME_DEFAULTS.to;
1001
+ const border = size * 0.05;
1002
+ const width = size + 2 * (border + gap);
1003
+ const row = ctx.text ? size * 0.18 : 0;
1004
+ const innerHeight = size + (ctx.text ? gap + row : 2 * gap);
1005
+ const height = innerHeight + 2 * border;
1006
+ const radius = size * 0.1;
1007
+ return {
1008
+ width,
1009
+ height,
1010
+ qrX: border + gap,
1011
+ qrY: border + gap,
1012
+ qrSize: size,
1013
+ shapes: [
1014
+ rect(
1015
+ border,
1016
+ border,
1017
+ width - 2 * border,
1018
+ innerHeight,
1019
+ radius - border,
1020
+ background
1021
+ ),
1022
+ ...gradientRing(width, height, radius, border, from, to),
1023
+ ],
1024
+ label: fitLabel(
1025
+ ctx.text,
1026
+ width / 2,
1027
+ border + gap + size + row / 2,
1028
+ row,
1029
+ width - 2 * border - 2 * gap,
1030
+ frame.textColor || mixFrameColors(from, to, 0.5)
1031
+ ),
1032
+ squareEdges: false,
1033
+ color: from,
1034
+ };
1035
+ };
1036
+
1037
+ /** Focus: four corner brackets around the code, the label underneath. */
1038
+ const focus: Layout = (ctx) => {
1039
+ const { size, gap, color, background, frame, fitLabel } = ctx;
1040
+ const thick = size * 0.035;
1041
+ const arm = size * 0.2;
1042
+ const width = size + 2 * (gap + thick);
1043
+ const row = ctx.text ? size * 0.2 : 0;
1044
+ const box = width;
1045
+ const height = box + row;
1046
+ const bracket = (x: number, y: number, dx: number, dy: number): Point[] => [
1047
+ [x, y],
1048
+ [x + dx * arm, y],
1049
+ [x + dx * arm, y + dy * thick],
1050
+ [x + dx * thick, y + dy * thick],
1051
+ [x + dx * thick, y + dy * arm],
1052
+ [x, y + dy * arm],
1053
+ ];
1054
+ return {
1055
+ width,
1056
+ height,
1057
+ qrX: thick + gap,
1058
+ qrY: thick + gap,
1059
+ qrSize: size,
1060
+ shapes: [
1061
+ rect(0, 0, width, height, 0, background),
1062
+ polygon(bracket(0, 0, 1, 1), color),
1063
+ polygon(bracket(box, 0, -1, 1), color),
1064
+ polygon(bracket(box, box, -1, -1), color),
1065
+ polygon(bracket(0, box, 1, -1), color),
1066
+ ],
1067
+ label: fitLabel(
1068
+ ctx.text,
1069
+ width / 2,
1070
+ box + row * 0.4,
1071
+ row,
1072
+ width - 2 * gap,
1073
+ frame.textColor || color
1074
+ ),
1075
+ squareEdges: false,
1076
+ color,
1077
+ };
1078
+ };
1079
+
1080
+ export const SHAPED_FRAMES: Record<ShapedFrameStyle, Layout> = {
1081
+ "banner-top-bottom": bannerTopBottom,
1082
+ "speech-bubble-top": speechBubbleTop,
1083
+ "chat-bubble": chatBubble,
1084
+ circle,
1085
+ polaroid,
1086
+ phone,
1087
+ ticket,
1088
+ badge,
1089
+ envelope,
1090
+ tag,
1091
+ "menu-card": menuCard,
1092
+ sticker,
1093
+ "gradient-border": gradientBorder,
1094
+ focus,
1095
+ };