@7365admin1/layer-common 4.96.0 → 4.97.1-staging.500

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 (65) hide show
  1. package/CHANGELOG.md +10 -4
  2. package/assets/css/primitives.css +57 -0
  3. package/assets/css/screens.css +8 -4
  4. package/components/AccessCardDetailsDialog.vue +59 -6
  5. package/components/AccessCardPreviewDialog.vue +371 -53
  6. package/components/AppSelect.vue +143 -4
  7. package/components/BuildingUnitFormEdit.vue +6 -0
  8. package/components/BuildingUnitManagement.vue +298 -0
  9. package/components/Dialog/UpdateMoreAction.vue +11 -1
  10. package/components/DocumentForm.vue +407 -112
  11. package/components/DocumentManagement.vue +213 -12
  12. package/components/Facility/BookingSetup.vue +63 -0
  13. package/components/HidAccessLogDashboard.vue +74 -17
  14. package/components/HidAccessPermissions.vue +424 -0
  15. package/components/HidIntercomManagement.vue +183 -14
  16. package/components/HidProfileQrCode.vue +332 -0
  17. package/components/HidQrCodeConfiguration.vue +17 -195
  18. package/components/HidReaderManagement.vue +398 -0
  19. package/components/HidReaderUserRoster.vue +44 -3
  20. package/components/HidUserEnrollment.vue +2239 -276
  21. package/components/InvitationClientForm.vue +19 -1
  22. package/components/Nfc/NFCPatrolRouteForm.vue +109 -58
  23. package/components/Nfc/NFCPatrolRouteMain.vue +3 -18
  24. package/components/Nfc/PatrolReport/PatrolActivityTable.vue +0 -8
  25. package/components/Nfc/PatrolReport/PatrolRouteSummary.vue +1 -1
  26. package/components/ServiceProviderMain.vue +48 -0
  27. package/components/SiteProviderChange.vue +371 -0
  28. package/components/TableMain.vue +22 -7
  29. package/components/VehicleQrStickerDialog.vue +64 -4
  30. package/components/VisitorForm.vue +12 -0
  31. package/components/VisitorManagement.vue +267 -5
  32. package/composables/useAccessManagement.ts +17 -1
  33. package/composables/useCustomerSite.ts +29 -0
  34. package/composables/useDocument.ts +7 -0
  35. package/composables/useFacility.ts +11 -0
  36. package/composables/useHidAmico.ts +165 -0
  37. package/composables/useHidNavigation.ts +25 -1
  38. package/composables/useHidReaderSelection.ts +50 -0
  39. package/composables/useMember.ts +12 -0
  40. package/composables/useNFCPatrolReport.ts +36 -32
  41. package/composables/useNFCPatrolReportFilters.ts +21 -3
  42. package/composables/useNFCPatrolRoute.ts +10 -3
  43. package/composables/usePeople.ts +19 -0
  44. package/composables/useServiceProvider.ts +45 -2
  45. package/composables/useSiteCategory.ts +45 -0
  46. package/package.json +1 -1
  47. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  48. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  49. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  50. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  51. package/types/document.d.ts +14 -0
  52. package/types/facility.d.ts +4 -0
  53. package/types/member.d.ts +4 -0
  54. package/types/nfc-patrol-report.ts +0 -2
  55. package/types/people.d.ts +28 -1
  56. package/types/service-provider.d.ts +5 -0
  57. package/types/site.d.ts +7 -1
  58. package/utils/hid-enrolment-subject.ts +344 -0
  59. package/utils/hid-permission-assignments.ts +198 -0
  60. package/utils/hid-reader-selection.ts +52 -0
  61. package/utils/nfc-patrol-time.ts +99 -0
  62. package/utils/occupancy-role.ts +109 -0
  63. package/utils/service-type.ts +30 -0
  64. package/utils/vehicle-qr-design.ts +304 -20
  65. package/utils/vehicle-qr-sticker.ts +126 -20
@@ -0,0 +1,109 @@
1
+ /**
2
+ * OWNER / OCCUPANT / PERSON IN CHARGE - the three standings a business
3
+ * tenancy has, and everything the product says about them.
4
+ *
5
+ * One list, because three screens read it: the form that asks the question
6
+ * (`PeopleFormMgmt`), the list and preview that print the answer back, and
7
+ * the row menu that reassigns it (`people-mgmt`). The values are the ones the
8
+ * server stores and validates - `OccupancyRoles` in core's `person.model.ts`
9
+ * - so a value added on one side has to be added on the other.
10
+ */
11
+ export const OCCUPANCY_ROLE_OPTIONS: TOccupancyRoleOption[] = [
12
+ {
13
+ value: "owner",
14
+ title: "Owner",
15
+ action: "Assign Owner",
16
+ prompt: "Assign Owner",
17
+ description:
18
+ "The legal titleholder or primary deed owner of the property.",
19
+ },
20
+ {
21
+ value: "occupant",
22
+ title: "Occupant",
23
+ action: "Assign Occupant",
24
+ prompt: "Assign Occupant",
25
+ description:
26
+ "The person currently living in, renting, or utilizing the physical unit.",
27
+ },
28
+ {
29
+ value: "person-in-charge",
30
+ title: "Person in Charge",
31
+ action: "Assign Person in Charge",
32
+ prompt: "Assign Person in Charge (PIC)",
33
+ description:
34
+ "The designated manager responsible for maintenance, emergencies, and daily operations.",
35
+ },
36
+ ];
37
+
38
+ /**
39
+ * The same three, in the order the ROW MENU draws them, which is not the
40
+ * order the form's radio does. Derived rather than re-typed so the wording
41
+ * cannot drift between the two.
42
+ */
43
+ export const OCCUPANCY_ROLE_ACTIONS: TOccupancyRoleOption[] = (
44
+ ["person-in-charge", "owner", "occupant"] as TOccupancyRole[]
45
+ ).map(
46
+ (value) =>
47
+ OCCUPANCY_ROLE_OPTIONS.find(
48
+ (option) => option.value === value,
49
+ ) as TOccupancyRoleOption,
50
+ );
51
+
52
+ /**
53
+ * The label for a stored role, or "" for a person who was never asked - which
54
+ * is everyone on a residential site and everyone saved before the question
55
+ * existed. Callers decide what to print instead; nobody should print a raw
56
+ * `person-in-charge` at a user.
57
+ */
58
+ export function occupancyRoleLabel(role?: string | null): string {
59
+ return (
60
+ OCCUPANCY_ROLE_OPTIONS.find((option) => option.value === role)?.title ?? ""
61
+ );
62
+ }
63
+
64
+ /**
65
+ * Does this person hold OWNER at their unit?
66
+ *
67
+ * The role when there is one, `isOwner` when there is not - the same test the
68
+ * server applies (`holdsUnitOwner` in core's `unit-owner.util.ts`). A person
69
+ * recorded before the role existed carries only the flag, and the people list
70
+ * already prints them as "Owner".
71
+ */
72
+ export function holdsUnitOwner(person?: {
73
+ occupancyRole?: string | null;
74
+ isOwner?: boolean;
75
+ }): boolean {
76
+ if (!person) return false;
77
+
78
+ if (person.occupancyRole) return person.occupancyRole === "owner";
79
+
80
+ return person.isOwner === true;
81
+ }
82
+
83
+ /**
84
+ * MUST THIS PERSON HAND THE UNIT OVER BEFORE THEY CAN BE DEACTIVATED?
85
+ *
86
+ * The owner of a unit does not leave while they still own it - the standing
87
+ * moves to another tenant at the same block, level and unit first.
88
+ *
89
+ * Keyed to the ROLE and never to `isOwner`, exactly as the server keys it
90
+ * (`mustHandOverBeforeDeactivating` in core): the flag is on every resident in
91
+ * the estate, and no residential screen can change it, so a rule keyed to it
92
+ * would trap records that can never satisfy it.
93
+ */
94
+ export function mustHandOverBeforeDeactivating(person?: {
95
+ occupancyRole?: string | null;
96
+ }): boolean {
97
+ return person?.occupancyRole === "owner";
98
+ }
99
+
100
+ /**
101
+ * Why a deactivation was held back. The SERVER carries the enforcing copy of
102
+ * this rule and of these words (core `unit-owner.util.ts`); this one exists so
103
+ * the console can say it before the round trip rather than after.
104
+ */
105
+ export function ownerHandoverRequiredMessage(name?: string): string {
106
+ const who = name?.trim() ? `"${name.trim()}"` : "This person";
107
+
108
+ return `${who} is the owner of this unit. Assign the owner role to another tenant at the same block, level and unit before deactivating them.`;
109
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A SERVICE PROVIDER'S LINE OF BUSINESS, AS PEOPLE NAME IT.
3
+ *
4
+ * `/api/service-providers` returns the service CODE (`mechanical_electrical_services`),
5
+ * which is a database value, not something to show an operator. This is the same
6
+ * mapping `API-core src/utils/converter.ts spmServiceNewToOld` applies — copied
7
+ * rather than imported, because that is a server package this layer does not
8
+ * depend on.
9
+ *
10
+ * NOT the same labels as `utils/module-applications.ts APPLICATIONS`. Those name
11
+ * the seven role-permission applications ("Mechanical & electrical", "Pest
12
+ * control") and are keyed `mechanical-electrical`, not `*_services`. These are
13
+ * the shorter names the service-provider screens use ("M&E", "Pest Control").
14
+ *
15
+ * An unknown code is returned untouched: a new service type shows as its raw
16
+ * code, which is visibly odd, rather than vanishing from the row.
17
+ */
18
+ const SERVICE_TYPE_LABELS: Readonly<Record<string, string>> = Object.freeze({
19
+ security_agency: "Security",
20
+ cleaning_services: "Cleaning",
21
+ pool_maintenance_services: "Pool Maintenance",
22
+ pest_control_services: "Pest Control",
23
+ landscaping_services: "Landscape",
24
+ mechanical_electrical_services: "Mechanical & Electrical",
25
+ });
26
+
27
+ export function serviceTypeLabel(service: string | null | undefined): string {
28
+ const code = String(service ?? "");
29
+ return SERVICE_TYPE_LABELS[code] ?? code;
30
+ }
@@ -13,12 +13,31 @@ export type QrMatrix = { size: number; get(row: number, col: number): number | b
13
13
 
14
14
  export type DotShape = "square" | "rounded" | "dots";
15
15
  export type EyeShape = "square" | "rounded" | "circle";
16
- export type FrameShape = "rounded" | "square" | "soft" | "arch" | "ticket";
17
- export type LabelChoice = "app" | "verify" | "site" | "none";
16
+ /** Cut-out shapes: the QR sits whole inside, the rest of the shape is a dot pattern. */
17
+ export type SilhouetteShape =
18
+ | "circle"
19
+ | "heart"
20
+ | "star"
21
+ | "hexagon"
22
+ | "octagon"
23
+ | "shield"
24
+ | "bubble"
25
+ | "roundsquare"
26
+ | "car";
27
+ export type FrameShape = "rounded" | "square" | "soft" | "arch" | "ticket" | SilhouetteShape;
28
+ export type LabelChoice = "app" | "verify" | "scanme" | "site" | "none";
18
29
 
19
30
  export type StickerTheme = { id: string; title: string; ink: string; eye: string; paper: string };
20
31
 
21
- export type StickerDesign = { dots: DotShape; eyes: EyeShape; theme: string; frame: FrameShape; label: LabelChoice };
32
+ export type StickerDesign = {
33
+ dots: DotShape;
34
+ eyes: EyeShape;
35
+ theme: string;
36
+ frame: FrameShape;
37
+ label: LabelChoice;
38
+ /** A thin grey line around each sticker to cut along. */
39
+ cutLines?: boolean;
40
+ };
22
41
 
23
42
  export const DOT_OPTIONS: { value: DotShape; title: string }[] = [
24
43
  { value: "square", title: "Squares (classic)" },
@@ -40,9 +59,29 @@ export const FRAME_OPTIONS: { value: FrameShape; title: string }[] = [
40
59
  { value: "ticket", title: "Ticket (cut corners)" },
41
60
  ];
42
61
 
62
+ export const SILHOUETTE_OPTIONS: { value: SilhouetteShape; title: string }[] = [
63
+ { value: "circle", title: "Circle" },
64
+ { value: "heart", title: "Heart" },
65
+ { value: "star", title: "Star badge" },
66
+ { value: "hexagon", title: "Hexagon" },
67
+ { value: "octagon", title: "Octagon" },
68
+ { value: "shield", title: "Shield" },
69
+ { value: "bubble", title: "Speech bubble" },
70
+ { value: "roundsquare", title: "Rounded square" },
71
+ { value: "car", title: "Car" },
72
+ ];
73
+
74
+ /** Every shape the user can pick: the cards first, then the cut-out shapes. */
75
+ export const SHAPE_OPTIONS: { value: FrameShape; title: string }[] = [...FRAME_OPTIONS, ...SILHOUETTE_OPTIONS];
76
+
77
+ export function isSilhouette(frame: unknown): frame is SilhouetteShape {
78
+ return SILHOUETTE_OPTIONS.some((o) => o.value === frame);
79
+ }
80
+
43
81
  export const LABEL_OPTIONS: { value: LabelChoice; title: string }[] = [
44
82
  { value: "app", title: "Scan with iSecure365 / iMA365" },
45
83
  { value: "verify", title: "Scan to verify vehicle" },
84
+ { value: "scanme", title: "Scan me" },
46
85
  { value: "site", title: "Site name" },
47
86
  { value: "none", title: "No extra words" },
48
87
  ];
@@ -64,6 +103,7 @@ export const DEFAULT_STICKER_DESIGN: StickerDesign = {
64
103
  theme: "black",
65
104
  frame: "rounded",
66
105
  label: "app",
106
+ cutLines: true,
67
107
  };
68
108
 
69
109
  /** A saved or typed-in design with anything unknown replaced by the default. */
@@ -76,8 +116,9 @@ export function normalizeDesign(raw: unknown): StickerDesign {
76
116
  dots: pick(r.dots, DOT_OPTIONS, d.dots),
77
117
  eyes: pick(r.eyes, EYE_OPTIONS, d.eyes),
78
118
  theme: STICKER_THEMES.some((t) => t.id === r.theme) ? String(r.theme) : d.theme,
79
- frame: pick(r.frame, FRAME_OPTIONS, d.frame),
119
+ frame: pick(r.frame, SHAPE_OPTIONS, d.frame),
80
120
  label: pick(r.label, LABEL_OPTIONS, d.label),
121
+ cutLines: typeof r.cutLines === "boolean" ? r.cutLines : true,
81
122
  };
82
123
  }
83
124
 
@@ -110,15 +151,203 @@ const STROKE = 0.35;
110
151
  /** A rectangle with per-corner radii [tl, tr, br, bl], or concave cut corners. */
111
152
  export type Box = { t: "box"; x: number; y: number; w: number; h: number; r?: number[]; notch?: number };
112
153
  export type Circle = { t: "circle"; cx: number; cy: number; r: number };
113
- export type Shape = Box | Circle;
154
+ /** A closed outline, points in mm (the cut-out shapes). */
155
+ export type Poly = { t: "poly"; pts: [number, number][] };
156
+ export type Shape = Box | Circle | Poly;
114
157
  /** A filled shape; `hole` is cut out of it (rings, the frame line). */
115
158
  export type Paint = { shape: Shape; hole?: Shape; fill: string };
116
159
 
117
160
  /** Top of the QR on the card: lower on the badge so the round top keeps clear of the code. */
118
161
  export function qrTop(frame: FrameShape): number {
162
+ if (isSilhouette(frame)) return silhouetteLayout(frame).qrTop;
119
163
  return frame === "arch" ? 7 : 2.5;
120
164
  }
121
165
 
166
+ /** Size of the sticker face in mm. */
167
+ export function cardSize(frame: FrameShape): { w: number; h: number } {
168
+ return isSilhouette(frame) ? { w: SHAPE_W, h: SHAPE_H } : { w: CARD_W, h: CARD_H };
169
+ }
170
+
171
+ // ---- cut-out shapes (all in mm; each fits a 62 x 58 box) ---------------------
172
+
173
+ export const SHAPE_W = 62;
174
+ export const SHAPE_H = 58;
175
+ /** The 32 mm QR square keeps at least this much paper to the shape's edge, so a slightly-off cut never eats the quiet zone. */
176
+ export const SHAPE_EDGE_MARGIN = 1;
177
+ /** The box under the QR for the plate number (and the optional words). */
178
+ export const BAND_H = 8.5;
179
+ const BAND_MIN_W = 24;
180
+ const BAND_MAX_W = 36;
181
+ /** Share of the allowed (chessboard) pattern cells that get a dot. */
182
+ const PATTERN_DENSITY = 0.7;
183
+
184
+ type Pt = [number, number];
185
+ const MID = SHAPE_W / 2;
186
+
187
+ function arcPts(cx: number, cy: number, r: number, a0: number, a1: number, steps = 24): Pt[] {
188
+ return Array.from({ length: steps + 1 }, (_, i) => {
189
+ const a = a0 + ((a1 - a0) * i) / steps;
190
+ return [cx + r * Math.cos(a), cy + r * Math.sin(a)] as Pt;
191
+ });
192
+ }
193
+
194
+ /** Right half (top middle -> bottom middle, clockwise) plus its mirror image = the whole outline. */
195
+ const mirror = (half: Pt[]): Pt[] => [...half, ...half.slice().reverse().map(([x, y]) => [SHAPE_W - x, y] as Pt)];
196
+
197
+ function roundRectPts(x: number, y: number, w: number, h: number, r: number): Pt[] {
198
+ const q = Math.PI / 2;
199
+ return [
200
+ ...arcPts(x + r, y + r, r, 2 * q, 3 * q, 8),
201
+ ...arcPts(x + w - r, y + r, r, 3 * q, 4 * q, 8),
202
+ ...arcPts(x + w - r, y + h - r, r, 0, q, 8),
203
+ ...arcPts(x + r, y + h - r, r, q, 2 * q, 8),
204
+ ];
205
+ }
206
+
207
+ function regularPts(sides: number, r: number, cx: number, cy: number, start: number): Pt[] {
208
+ return Array.from({ length: sides }, (_, i) => {
209
+ const a = start + (i * 2 * Math.PI) / sides;
210
+ return [cx + r * Math.cos(a), cy + r * Math.sin(a)] as Pt;
211
+ });
212
+ }
213
+
214
+ function bezierPts(p0: Pt, c: Pt, p1: Pt, steps = 20): Pt[] {
215
+ return Array.from({ length: steps + 1 }, (_, i) => {
216
+ const t = i / steps;
217
+ const u = 1 - t;
218
+ return [u * u * p0[0] + 2 * u * t * c[0] + t * t * p1[0], u * u * p0[1] + 2 * u * t * c[1] + t * t * p1[1]] as Pt;
219
+ });
220
+ }
221
+
222
+ function heartPts(): Pt[] {
223
+ // Two round lobes and a point; lobes wide enough that the 32 mm QR fits between them.
224
+ const c = 11;
225
+ const r = 20;
226
+ const cx = MID + c;
227
+ const tip: Pt = [MID, SHAPE_H];
228
+ const base = Math.atan2(tip[1] - r, tip[0] - cx);
229
+ const tangent = base - Math.acos(r / Math.hypot(tip[0] - cx, tip[1] - r));
230
+ const dip = Math.atan2(-Math.sqrt(r * r - c * c), -c);
231
+ return mirror([...arcPts(cx, r, r, dip, tangent, 48), tip]);
232
+ }
233
+
234
+ function starPts(): Pt[] {
235
+ // A star badge (seal): 14 short points round a circle. A thin five-point
236
+ // star has no room for a whole 32 mm code at this size.
237
+ const R = SHAPE_H / 2;
238
+ return Array.from({ length: 28 }, (_, i) => {
239
+ const a = -Math.PI / 2 + (i * Math.PI) / 14;
240
+ const k = i % 2 ? 0.88 * R : R;
241
+ return [MID + k * Math.cos(a), R + k * Math.sin(a)] as Pt;
242
+ });
243
+ }
244
+
245
+ function bubblePts(): Pt[] {
246
+ // Rounded box with a tail at the bottom left.
247
+ const [x, y, w, h, r] = [1, 1, 60, 47, 9];
248
+ const box = roundRectPts(x, y, w, h, r);
249
+ const split = 27; // first point of the bottom-left corner arc
250
+ const tail: Pt[] = [[25, y + h], [12, SHAPE_H], [17, y + h]];
251
+ return [...box.slice(0, split), ...tail, ...box.slice(split)];
252
+ }
253
+
254
+ function carPts(): Pt[] {
255
+ // Front view: roof, windscreen, wing mirrors, body and the two front wheels.
256
+ return mirror([
257
+ [MID, 2.5], [44.5, 2.5], [46.8, 3.2], [47.8, 4.6], [54, 20.5],
258
+ [56, 20.2], [60.6, 19.2], [61.6, 21], [61.4, 23], [59.4, 24.2],
259
+ [60.6, 26], [61.5, 29.5], [61.5, 47], [60.2, 49],
260
+ [58.5, 49], [58.5, 56.2], [57.6, 57.4], [49.4, 57.4], [48.5, 56.2], [48.5, 49.8], [MID, 49.8],
261
+ ]);
262
+ }
263
+
264
+ const SILHOUETTE_BUILDERS: Record<SilhouetteShape, () => Pt[]> = {
265
+ circle: () => arcPts(MID, SHAPE_H / 2, SHAPE_H / 2, 0, 2 * Math.PI, 144).slice(0, -1),
266
+ heart: heartPts,
267
+ star: starPts,
268
+ hexagon: () => regularPts(6, MID, MID, SHAPE_H / 2, 0),
269
+ octagon: () => regularPts(8, SHAPE_H / 2 / Math.cos(Math.PI / 8), MID, SHAPE_H / 2, Math.PI / 8),
270
+ shield: () =>
271
+ mirror([
272
+ [MID, 1],
273
+ [56, 1],
274
+ ...arcPts(56, 5, 4, -Math.PI / 2, 0, 6).slice(1),
275
+ [60, 28],
276
+ ...bezierPts([60, 28], [60, 48], [MID, SHAPE_H]).slice(1),
277
+ ]),
278
+ bubble: bubblePts,
279
+ roundsquare: () => roundRectPts(2, 0, 58, 58, 14),
280
+ car: carPts,
281
+ };
282
+
283
+ export function pointInPoly(pts: Pt[], x: number, y: number): boolean {
284
+ let inside = false;
285
+ for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {
286
+ const [xi, yi] = pts[i];
287
+ const [xj, yj] = pts[j];
288
+ if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) inside = !inside;
289
+ }
290
+ return inside;
291
+ }
292
+
293
+ /** True when the rectangle (edge sampled every 0.5 mm) is inside the outline and no point of the outline pokes into it. */
294
+ export function rectInside(pts: Pt[], x: number, y: number, w: number, h: number): boolean {
295
+ if (pts.some(([px, py]) => px > x && px < x + w && py > y && py < y + h)) return false;
296
+ const steps = Math.ceil(Math.max(w, h) / 0.5);
297
+ for (let i = 0; i <= steps; i++) {
298
+ const tx = x + (w * i) / steps;
299
+ const ty = y + (h * i) / steps;
300
+ if (!pointInPoly(pts, tx, y) || !pointInPoly(pts, tx, y + h) || !pointInPoly(pts, x, ty) || !pointInPoly(pts, x + w, ty)) {
301
+ return false;
302
+ }
303
+ }
304
+ return true;
305
+ }
306
+
307
+ export type SilhouetteLayout = { pts: Pt[]; qrTop: number; band: { x: number; y: number; w: number; h: number } };
308
+ const layoutCache = new Map<SilhouetteShape, SilhouetteLayout>();
309
+
310
+ /**
311
+ * Where the 32 mm QR and the plate box go inside a cut-out shape: the widest
312
+ * plate box that fits, then the middle of the heights where both fit. The QR
313
+ * keeps SHAPE_EDGE_MARGIN of paper to the edge; the plate box 0.5 mm.
314
+ */
315
+ export function silhouetteLayout(shape: SilhouetteShape): SilhouetteLayout {
316
+ const cached = layoutCache.get(shape);
317
+ if (cached) return cached;
318
+ const pts = SILHOUETTE_BUILDERS[shape]();
319
+ const e = SHAPE_EDGE_MARGIN;
320
+ const x0 = (SHAPE_W - QR_MM) / 2;
321
+ let best = { w: 0, tops: [] as number[] };
322
+ for (let top = e; top + QR_MM + BAND_H <= SHAPE_H; top += 0.25) {
323
+ if (!rectInside(pts, x0 - e, top - e, QR_MM + 2 * e, QR_MM + 2 * e)) continue;
324
+ let w = BAND_MAX_W;
325
+ while (w >= BAND_MIN_W && !rectInside(pts, MID - w / 2 - 0.5, top + QR_MM - 0.5, w + 1, BAND_H + 1)) w -= 1;
326
+ if (w < BAND_MIN_W || w < best.w) continue;
327
+ if (w > best.w) best = { w, tops: [] };
328
+ best.tops.push(top);
329
+ }
330
+ if (!best.tops.length) throw new Error(`QR does not fit the ${shape} shape`);
331
+ const top = best.tops[Math.floor(best.tops.length / 2)];
332
+ const layout = { pts, qrTop: top, band: { x: MID - best.w / 2, y: top + QR_MM, w: best.w, h: BAND_H } };
333
+ layoutCache.set(shape, layout);
334
+ return layout;
335
+ }
336
+
337
+ /**
338
+ * Same dots every time for a cell (a fixed hash, no randomness between prints).
339
+ * Dots only sit on every other cell, like a chessboard, so no two ever touch
340
+ * side by side: even blurred, a row of them never joins into the solid bars a
341
+ * scanner takes for a QR corner.
342
+ */
343
+ function patternDot(row: number, col: number): boolean {
344
+ if ((row + col) % 2 !== 0) return false;
345
+ let h = Math.imul(row + 1000, 73856093) ^ Math.imul(col + 1000, 19349663);
346
+ h = Math.imul(h ^ (h >>> 16), 0x85ebca6b);
347
+ h = Math.imul(h ^ (h >>> 13), 0xc2b2ae35);
348
+ return ((h ^ (h >>> 16)) >>> 0) / 4294967296 < PATTERN_DENSITY;
349
+ }
350
+
122
351
  function cardBox(frame: FrameShape, inset: number): Box {
123
352
  const x = inset;
124
353
  const w = CARD_W - inset * 2;
@@ -147,28 +376,58 @@ export function stickerFacePaints(matrix: QrMatrix, design: StickerDesign): Pain
147
376
  const theme = stickerTheme(design.theme);
148
377
  const n = matrix.size;
149
378
  const m = QR_MM / (n + QUIET_MODULES * 2);
150
- const ox = (CARD_W - QR_MM) / 2 + QUIET_MODULES * m;
379
+ const ox = (cardSize(design.frame).w - QR_MM) / 2 + QUIET_MODULES * m;
151
380
  const oy = qrTop(design.frame) + QUIET_MODULES * m;
152
- const paints: Paint[] = [
153
- { shape: cardBox(design.frame, 0), fill: theme.paper },
154
- { shape: cardBox(design.frame, 0), hole: cardBox(design.frame, STROKE), fill: theme.ink },
155
- ];
381
+ const paints: Paint[] = [];
382
+ if (isSilhouette(design.frame)) {
383
+ const { pts, band } = silhouetteLayout(design.frame);
384
+ paints.push({ shape: { t: "poly", pts }, fill: theme.paper });
385
+ // The rest of the shape: small round dots on the QR's grid, kept off the
386
+ // quiet zone, the plate box and the edge. Small separate dots never join
387
+ // into the solid bars a scanner looks for in a QR corner.
388
+ const near = 0.4; // mm of paper kept inside the edge
389
+ const clear = 1.2; // mm of paper kept round the plate box
390
+ const clearRing = QUIET_MODULES + 3; // pattern starts three modules beyond the quiet zone
391
+ for (let row = Math.floor(-oy / m) - 1; oy + row * m < SHAPE_H; row++) {
392
+ for (let col = Math.floor(-ox / m) - 1; ox + col * m < SHAPE_W; col++) {
393
+ if (row >= -clearRing && row < n + clearRing && col >= -clearRing && col < n + clearRing) continue;
394
+ if (!patternDot(row, col)) continue;
395
+ const x = ox + col * m;
396
+ const y = oy + row * m;
397
+ if (x + m > band.x - clear && x < band.x + band.w + clear && y + m > band.y - clear && y < band.y + band.h + clear) continue;
398
+ const corners: Pt[] = [[x - near, y - near], [x + m + near, y - near], [x - near, y + m + near], [x + m + near, y + m + near]];
399
+ if (!corners.every(([px, py]) => pointInPoly(pts, px, py))) continue;
400
+ paints.push({ shape: { t: "circle", cx: x + m / 2, cy: y + m / 2, r: m * 0.28 }, fill: theme.ink });
401
+ }
402
+ }
403
+ } else {
404
+ paints.push(
405
+ { shape: cardBox(design.frame, 0), fill: theme.paper },
406
+ { shape: cardBox(design.frame, 0), hole: cardBox(design.frame, STROKE), fill: theme.ink },
407
+ );
408
+ }
156
409
  const box = (x: number, y: number, w: number, h: number, rad = 0): Box => ({ t: "box", x, y, w, h, r: [rad, rad, rad, rad] });
157
410
 
411
+ // Round dots break the small alignment square (bottom right) into a ring of
412
+ // separate dots that some readers miss, so with dots it is drawn solid.
413
+ // ponytail: versions 2-6 only (one alignment square); the sticker payload is version 3.
414
+ const version = (n - 17) / 4;
415
+ const align = design.dots === "dots" && version >= 2 && version <= 6 ? n - 7 : -1;
416
+ const inAlign = (row: number, col: number) => align > 0 && Math.abs(row - align) <= 2 && Math.abs(col - align) <= 2;
417
+
158
418
  for (let row = 0; row < n; row++) {
159
419
  for (let col = 0; col < n; col++) {
160
- if (!matrix.get(row, col) || isFinder(n, row, col)) continue;
420
+ if (!matrix.get(row, col) || isFinder(n, row, col) || inAlign(row, col)) continue;
161
421
  const x = ox + col * m;
162
422
  const y = oy + row * m;
163
423
  if (design.dots === "dots") {
164
- paints.push({ shape: { t: "circle", cx: x + m / 2, cy: y + m / 2, r: m * 0.45 }, fill: theme.ink });
165
- } else if (design.dots === "rounded") {
166
- paints.push({ shape: box(x, y, m, m, m * 0.3), fill: theme.ink });
424
+ paints.push({ shape: { t: "circle", cx: x + m / 2, cy: y + m / 2, r: m * 0.48 }, fill: theme.ink });
167
425
  } else {
168
426
  // ponytail: one rect per horizontal run, so adjacent squares never show a hairline seam
427
+ // (rounded: a run is one pill, no notches between neighbours for a camera to trip on)
169
428
  let end = col;
170
- while (end + 1 < n && matrix.get(row, end + 1) && !isFinder(n, row, end + 1)) end++;
171
- paints.push({ shape: box(x, y, (end - col + 1) * m, m), fill: theme.ink });
429
+ while (end + 1 < n && matrix.get(row, end + 1) && !isFinder(n, row, end + 1) && !inAlign(row, end + 1)) end++;
430
+ paints.push({ shape: box(x, y, (end - col + 1) * m, m, design.dots === "rounded" ? m * 0.3 : 0), fill: theme.ink });
172
431
  col = end;
173
432
  }
174
433
  }
@@ -192,6 +451,12 @@ export function stickerFacePaints(matrix: QrMatrix, design: StickerDesign): Pain
192
451
  paints.push({ shape: box(x + 2 * m, y + 2 * m, 3 * m, 3 * m, round ? 0.9 * m : 0), fill: theme.eye });
193
452
  }
194
453
  }
454
+ if (align > 0) {
455
+ const x = ox + (align - 2) * m;
456
+ const y = oy + (align - 2) * m;
457
+ paints.push({ shape: box(x, y, 5 * m, 5 * m, 1.2 * m), hole: box(x + m, y + m, 3 * m, 3 * m, 0.6 * m), fill: theme.ink });
458
+ paints.push({ shape: { t: "circle", cx: x + 2.5 * m, cy: y + 2.5 * m, r: 0.55 * m }, fill: theme.ink });
459
+ }
195
460
  return paints;
196
461
  }
197
462
 
@@ -222,13 +487,31 @@ function boxPath(b: Box): string {
222
487
 
223
488
  function shapePath(s: Shape): string {
224
489
  if (s.t === "box") return boxPath(s);
490
+ if (s.t === "poly") return `M${s.pts.map(([x, y]) => `${f(x)} ${f(y)}`).join("L")}Z`;
225
491
  const { cx, cy, r } = s;
226
492
  return `M${f(cx - r)} ${f(cy)}A${f(r)} ${f(r)} 0 1 0 ${f(cx + r)} ${f(cy)}A${f(r)} ${f(r)} 0 1 0 ${f(cx - r)} ${f(cy)}Z`;
227
493
  }
228
494
 
229
- /** The face as one SVG, 47 x 58 mm. Runs of same-colour shapes share one path. */
230
- export function paintsToSvg(paints: Paint[]): string {
495
+ /** Gap between the sticker's edge and its grey cut line, mm. */
496
+ export const CUT_LINE_GAP = 1;
497
+
498
+ /**
499
+ * The face as one SVG (47 x 58 mm card, 62 x 58 mm cut-out shape). Runs of
500
+ * same-colour shapes share one path. `cutLine` adds a thin grey line
501
+ * CUT_LINE_GAP outside the edge: a wide grey stroke under a white one, so it
502
+ * follows any outline, with rounded corners that are easy to cut.
503
+ */
504
+ export function paintsToSvg(paints: Paint[], opts: { w?: number; h?: number; cutLine?: boolean } = {}): string {
505
+ const w = opts.w ?? CARD_W;
506
+ const h = opts.h ?? CARD_H;
231
507
  const out: string[] = [];
508
+ if (opts.cutLine && paints[0]) {
509
+ const edge = shapePath(paints[0].shape);
510
+ out.push(
511
+ `<path fill="none" stroke="#8c8c8c" stroke-linejoin="round" stroke-width="${f(CUT_LINE_GAP * 2 + 0.5)}" d="${edge}"/>`,
512
+ `<path fill="none" stroke="#ffffff" stroke-linejoin="round" stroke-width="${f(CUT_LINE_GAP * 2)}" d="${edge}"/>`,
513
+ );
514
+ }
232
515
  let fill = "";
233
516
  let d = "";
234
517
  const flush = () => d && out.push(`<path fill="${fill}" d="${d}"/>`);
@@ -249,20 +532,21 @@ export function paintsToSvg(paints: Paint[]): string {
249
532
  }
250
533
  flush();
251
534
  return (
252
- `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${CARD_W} ${CARD_H}" width="${CARD_W}mm" height="${CARD_H}mm">` +
535
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" width="${w}mm" height="${h}mm" overflow="visible">` +
253
536
  out.join("") +
254
537
  `</svg>`
255
538
  );
256
539
  }
257
540
 
258
541
  export function stickerFaceSvg(matrix: QrMatrix, design: StickerDesign): string {
259
- return paintsToSvg(stickerFacePaints(matrix, design));
542
+ return paintsToSvg(stickerFacePaints(matrix, design), { ...cardSize(design.frame), cutLine: design.cutLines !== false });
260
543
  }
261
544
 
262
545
  /** The words under the plate for this design ("" = none). */
263
546
  export function stickerLabel(design: StickerDesign, siteName = ""): string {
264
547
  if (design.label === "none") return "";
265
548
  if (design.label === "verify") return "Scan to verify vehicle";
549
+ if (design.label === "scanme") return "Scan me";
266
550
  if (design.label === "site") return String(siteName ?? "").trim();
267
551
  return "Scan with iSecure365 / iMA365";
268
552
  }