@7365admin1/layer-common 4.95.0 → 4.97.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -4
- package/components/InventoryHistoryDialog.vue +10 -3
- package/components/InventoryItemDetail.vue +18 -1
- package/components/InventoryItemDialog.vue +1 -1
- package/components/InventoryLinesDialog.vue +35 -9
- package/components/InventoryMain.vue +107 -5
- package/components/InventoryMyStockTab.vue +167 -12
- package/components/InventoryPoDialog.vue +2 -1
- package/components/InventoryReceiptActions.vue +67 -0
- package/components/InventoryReportsTab.vue +97 -6
- package/components/InventoryRequestsTab.vue +36 -14
- package/components/InventorySettingsTab.vue +27 -1
- package/components/InventoryStockTab.vue +52 -4
- package/components/InventoryTechniciansTab.vue +77 -4
- package/components/InventoryUsageDialog.vue +21 -2
- package/components/InventoryWriteOffDialog.vue +112 -0
- package/components/VehicleQrStickerDialog.vue +64 -4
- package/composables/useInventory.ts +24 -6
- package/package.json +1 -1
- package/types/inventory.d.ts +39 -2
- package/utils/inventory-ack.ts +172 -0
- package/utils/inventory-request-text.ts +5 -3
- package/utils/inventory-usage.ts +16 -1
- package/utils/notification-target.ts +9 -3
- package/utils/vehicle-qr-design.ts +304 -20
- package/utils/vehicle-qr-sticker.ts +126 -20
|
@@ -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
|
-
|
|
17
|
-
export type
|
|
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 = {
|
|
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,
|
|
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
|
-
|
|
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 = (
|
|
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
|
-
|
|
154
|
-
{
|
|
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.
|
|
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
|
-
/**
|
|
230
|
-
export
|
|
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 ${
|
|
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
|
}
|
|
@@ -8,16 +8,97 @@
|
|
|
8
8
|
* pasted on the car.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
DEFAULT_STICKER_DESIGN,
|
|
13
|
+
QR_MM,
|
|
14
|
+
cardSize,
|
|
15
|
+
isSilhouette,
|
|
16
|
+
qrTop,
|
|
17
|
+
silhouetteLayout,
|
|
18
|
+
stickerLabel,
|
|
19
|
+
stickerTheme,
|
|
20
|
+
type FrameShape,
|
|
21
|
+
type StickerDesign,
|
|
22
|
+
} from "./vehicle-qr-design.ts";
|
|
12
23
|
|
|
13
24
|
/** The server's most vehicles per request (POST /api/vehicles/qr/stickers). */
|
|
14
25
|
export const STICKER_MAX_PER_REQUEST = 500;
|
|
15
26
|
|
|
16
|
-
/** A4 sheet: 4 columns x 4 rows of 47 mm cells. */
|
|
27
|
+
/** A4 sheet with the classic cards: 4 columns x 4 rows of 47 mm cells. */
|
|
17
28
|
export const STICKER_COLUMNS = 4;
|
|
18
29
|
export const STICKER_ROWS = 4;
|
|
19
30
|
export const STICKERS_PER_PAGE = STICKER_COLUMNS * STICKER_ROWS;
|
|
20
31
|
|
|
32
|
+
/** Printer margin on every side of the A4 sheet, mm. */
|
|
33
|
+
export const SHEET_MARGIN = 5;
|
|
34
|
+
const PAGE_W = 210 - SHEET_MARGIN * 2;
|
|
35
|
+
const PAGE_H = 297 - SHEET_MARGIN * 2;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* How stickers sit on the A4 sheet. A cell = the sticker + the installer strip
|
|
39
|
+
* under it; `gap` is the empty cutting gap between cells (no ink in it except
|
|
40
|
+
* the small + cut marks in its middle).
|
|
41
|
+
*/
|
|
42
|
+
export type SheetLayout = { cols: number; rows: number; cellW: number; cardH: number; stripH: number; gap: number };
|
|
43
|
+
|
|
44
|
+
export function sheetLayout(frame: FrameShape): SheetLayout {
|
|
45
|
+
// Cut-out shapes are 62 mm wide: 3 across. Cards stay 4 x 4 = 16.
|
|
46
|
+
return isSilhouette(frame)
|
|
47
|
+
? { cols: 3, rows: 4, cellW: cardSize(frame).w, cardH: cardSize(frame).h, stripH: 10, gap: 4 }
|
|
48
|
+
: { cols: STICKER_COLUMNS, rows: STICKER_ROWS, cellW: cardSize(frame).w, cardH: cardSize(frame).h, stripH: 11, gap: 3 };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const perSheet = (l: SheetLayout) => l.cols * l.rows;
|
|
52
|
+
|
|
53
|
+
/** "12 stickers per A4 sheet with 4 mm cutting gaps" */
|
|
54
|
+
export function sheetSummary(frame: FrameShape): string {
|
|
55
|
+
const l = sheetLayout(frame);
|
|
56
|
+
return `${perSheet(l)} stickers per A4 sheet with ${l.gap} mm cutting gaps`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Top-left of the sticker grid inside the printable area, so it sits in the middle of the sheet. */
|
|
60
|
+
function gridOrigin(l: SheetLayout): { x: number; y: number; w: number; h: number } {
|
|
61
|
+
const w = l.cols * l.cellW + (l.cols - 1) * l.gap;
|
|
62
|
+
const h = l.rows * (l.cardH + l.stripH) + (l.rows - 1) * l.gap;
|
|
63
|
+
return { x: (PAGE_W - w) / 2, y: (PAGE_H - h) / 2, w, h };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Cut marks for one sheet, as SVG over the printable area: a small + in the
|
|
68
|
+
* middle of every cutting gap crossing, and short ticks just outside the grid
|
|
69
|
+
* where each gap meets its edge - line a ruler up on them to cut the sheet
|
|
70
|
+
* into pieces.
|
|
71
|
+
*/
|
|
72
|
+
export function cropMarksSvg(l: SheetLayout): string {
|
|
73
|
+
const g = gridOrigin(l);
|
|
74
|
+
const cellH = l.cardH + l.stripH;
|
|
75
|
+
const xs = Array.from({ length: l.cols - 1 }, (_, i) => g.x + (i + 1) * l.cellW + i * l.gap + l.gap / 2);
|
|
76
|
+
const ys = Array.from({ length: l.rows - 1 }, (_, i) => g.y + (i + 1) * cellH + i * l.gap + l.gap / 2);
|
|
77
|
+
const r = (v: number) => Math.round(v * 100) / 100;
|
|
78
|
+
const arm = Math.min(1.2, l.gap / 2 - 0.3);
|
|
79
|
+
const tickX = Math.max(0.6, g.y - 0.4);
|
|
80
|
+
const tickY = Math.max(0.6, g.x - 0.4);
|
|
81
|
+
const lines: string[] = [];
|
|
82
|
+
const line = (x1: number, y1: number, x2: number, y2: number) =>
|
|
83
|
+
lines.push(`<line x1="${r(x1)}" y1="${r(y1)}" x2="${r(x2)}" y2="${r(y2)}"/>`);
|
|
84
|
+
for (const x of xs) {
|
|
85
|
+
line(x, g.y - tickX, x, g.y - 0.2);
|
|
86
|
+
line(x, g.y + g.h + 0.2, x, g.y + g.h + tickX);
|
|
87
|
+
for (const y of ys) {
|
|
88
|
+
line(x - arm, y, x + arm, y);
|
|
89
|
+
line(x, y - arm, x, y + arm);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const y of ys) {
|
|
93
|
+
line(g.x - tickY, y, g.x - 0.2, y);
|
|
94
|
+
line(g.x + g.w + 0.2, y, g.x + g.w + tickY, y);
|
|
95
|
+
}
|
|
96
|
+
return (
|
|
97
|
+
`<svg class="marks" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${PAGE_W} ${PAGE_H}" width="${PAGE_W}mm" height="${PAGE_H}mm">` +
|
|
98
|
+
`<g stroke="#555" stroke-width="0.15">${lines.join("")}</g></svg>`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
21
102
|
export type StickerItem = {
|
|
22
103
|
vehicleId: string;
|
|
23
104
|
qr: string;
|
|
@@ -141,25 +222,38 @@ export function escapeHtml(value: unknown): string {
|
|
|
141
222
|
.replace(/'/g, "'");
|
|
142
223
|
}
|
|
143
224
|
|
|
144
|
-
|
|
145
|
-
|
|
225
|
+
// Printed at 100% ("Actual size"): every size below is real millimetres on paper.
|
|
226
|
+
function printCss(l: SheetLayout): string {
|
|
227
|
+
const g = gridOrigin(l);
|
|
228
|
+
return `
|
|
229
|
+
@page { size: A4; margin: ${SHEET_MARGIN}mm; }
|
|
146
230
|
* { box-sizing: border-box; }
|
|
147
231
|
html, body { margin: 0; padding: 0; background: #fff; color: #111; font-family: Arial, Helvetica, sans-serif; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
|
|
148
|
-
.page { display: grid; grid-template-columns: repeat(${
|
|
232
|
+
.page { position: relative; display: grid; grid-template-columns: repeat(${l.cols}, ${l.cellW}mm); grid-auto-rows: ${l.cardH + l.stripH}mm; gap: ${l.gap}mm; justify-content: start; align-content: start; padding: ${g.y}mm 0 0 ${g.x}mm; width: ${PAGE_W}mm; height: ${PAGE_H}mm; margin: 0 auto; overflow: hidden; break-after: page; }
|
|
149
233
|
.page:last-child { break-after: auto; }
|
|
150
|
-
.
|
|
151
|
-
.
|
|
152
|
-
.
|
|
234
|
+
.marks { position: absolute; left: 0; top: 0; width: ${PAGE_W}mm; height: ${PAGE_H}mm; pointer-events: none; }
|
|
235
|
+
.cell { width: ${l.cellW}mm; break-inside: avoid; }
|
|
236
|
+
.card { position: relative; width: ${l.cellW}mm; height: ${l.cardH}mm; }
|
|
237
|
+
.face, .face svg { position: absolute; inset: 0; width: ${l.cellW}mm; height: ${l.cardH}mm; display: block; overflow: visible; }
|
|
153
238
|
.words { position: absolute; left: 3mm; right: 3mm; bottom: 2mm; display: flex; flex-direction: column; align-items: center; justify-content: space-between; text-align: center; }
|
|
154
|
-
.
|
|
239
|
+
.words.band { bottom: auto; justify-content: center; gap: 0.6mm; }
|
|
240
|
+
.plate { font-size: 13pt; font-weight: 800; letter-spacing: 0.3mm; line-height: 1.1; white-space: nowrap; }
|
|
155
241
|
.hint { font-size: 5.8pt; line-height: 1.2; opacity: 0.85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
|
|
156
242
|
.brand { display: flex; align-items: center; justify-content: center; gap: 1mm; font-size: 6pt; border-top: 0.2mm solid #ccc; width: 100%; padding-top: 1mm; }
|
|
157
243
|
.mark { width: 3.2mm; height: 3.2mm; border-radius: 0.8mm; color: #fff; font-weight: 800; font-size: 5pt; line-height: 3.2mm; text-align: center; }
|
|
158
|
-
.cut { margin-top: 1.2mm; border-top: 0.3mm dashed #666; padding-top: 1mm; font-size: 6.5pt; line-height: 1.25; color: #111;
|
|
244
|
+
.cut { margin-top: 1.2mm; border-top: 0.3mm dashed #666; padding-top: 1mm; font-size: 6.5pt; line-height: 1.25; color: #111; height: ${l.stripH - 1.2}mm; overflow: hidden; }
|
|
245
|
+
.cut.free { margin-top: 1.6mm; border-top: 0; padding-top: 0; height: ${l.stripH - 1.6}mm; }
|
|
159
246
|
.cut .owner { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
160
247
|
.cut .note { color: #666; font-size: 5.5pt; }
|
|
161
|
-
@media screen { body { background: #e9e9e9; zoom: 0.75; padding: 4mm 0; } .page { background: #fff; margin-bottom: 4mm;
|
|
248
|
+
@media screen { body { background: #e9e9e9; zoom: 0.75; padding: 4mm 0; } .page { background: #fff; margin-bottom: 4mm; box-shadow: 0 0 2mm rgba(0,0,0,.25); } }
|
|
162
249
|
`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Plate font size (mm) that fits the cut-out shape's plate box. */
|
|
253
|
+
function plateSizeMm(plate: string, boxW: number): number {
|
|
254
|
+
// bold capitals are about 0.74 em wide, plus 0.3 mm letter spacing each
|
|
255
|
+
return Math.round(Math.min(4.6, (boxW / Math.max(plate.length, 1) - 0.3) / 0.74) * 100) / 100;
|
|
256
|
+
}
|
|
163
257
|
|
|
164
258
|
/**
|
|
165
259
|
* One full HTML document: A4 sheets of stickers. `faceSvgs` is parallel to
|
|
@@ -174,22 +268,34 @@ export function buildStickerDocument(
|
|
|
174
268
|
const design = opts.design ?? DEFAULT_STICKER_DESIGN;
|
|
175
269
|
const { ink } = stickerTheme(design.theme);
|
|
176
270
|
const label = stickerLabel(design, opts.siteName);
|
|
271
|
+
const layout = sheetLayout(design.frame);
|
|
272
|
+
const shape = isSilhouette(design.frame) ? silhouetteLayout(design.frame) : null;
|
|
177
273
|
const wordsTop = qrTop(design.frame) + QR_MM + 0.8;
|
|
178
274
|
const cells = items.map((item, i) => {
|
|
179
275
|
const { place, owner } = installerLine(item);
|
|
276
|
+
const plate = escapeHtml(item.plateNumber);
|
|
277
|
+
// Cut-out shapes: plate (and words) in the box under the QR; no brand line - there is no room.
|
|
278
|
+
const words = shape
|
|
279
|
+
? `<div class="words band" style="left:${shape.band.x}mm;right:auto;top:${shape.band.y}mm;width:${shape.band.w}mm;height:${shape.band.h}mm">` +
|
|
280
|
+
`<div class="plate" style="font-size:${plateSizeMm(text(item.plateNumber), shape.band.w)}mm">${plate}</div>` +
|
|
281
|
+
(label ? `<div class="hint">${escapeHtml(label)}</div>` : "") +
|
|
282
|
+
`</div>`
|
|
283
|
+
: `<div class="words" style="top:${wordsTop}mm">` +
|
|
284
|
+
`<div class="plate">${plate}</div>` +
|
|
285
|
+
(label ? `<div class="hint">${escapeHtml(label)}</div>` : "") +
|
|
286
|
+
`<div class="brand"><span class="mark" style="background:${ink}">7</span>Powered by Seven365</div>` +
|
|
287
|
+
`</div>`;
|
|
180
288
|
return (
|
|
181
289
|
`<div class="cell"><div class="card" style="color:${ink}">` +
|
|
182
290
|
`<div class="face">${faceSvgs[i] ?? ""}</div>` +
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
`<div class="brand"><span class="mark" style="background:${ink}">7</span>Powered by Seven365</div>` +
|
|
187
|
-
`</div></div>` +
|
|
188
|
-
`<div class="cut"><div><b>${escapeHtml(place || "-")}</b></div>` +
|
|
291
|
+
words +
|
|
292
|
+
`</div>` +
|
|
293
|
+
`<div class="cut${shape ? " free" : ""}"><div><b>${escapeHtml(place || "-")}</b></div>` +
|
|
189
294
|
`<div class="owner">Owner: ${escapeHtml(owner || "-")}</div>` +
|
|
190
|
-
`<div class="note"
|
|
295
|
+
`<div class="note">${shape ? "Installer: cut out the sticker, then paste on this car" : "Installer: cut here, then paste on this car"}</div></div></div>`
|
|
191
296
|
);
|
|
192
297
|
});
|
|
193
|
-
const
|
|
194
|
-
|
|
298
|
+
const marks = cropMarksSvg(layout);
|
|
299
|
+
const pages = stickerPages(cells, perSheet(layout)).map((p) => `<div class="page">${marks}${p.join("")}</div>`);
|
|
300
|
+
return `<!doctype html><html><head><meta charset="utf-8"><title>Vehicle QR stickers</title><style>${printCss(layout)}</style></head><body>${pages.join("")}</body></html>`;
|
|
195
301
|
}
|