@7365admin1/layer-common 4.155.1 → 4.156.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.156.0
4
+
5
+ ### Minor Changes
6
+
7
+ - fe3bb03: Vehicle QR stickers: new "Vehicle number on print-out" choice (Show / Hide). Hide leaves the plate number off the preview, print, saved sheet and PNG/JPEG pictures (file names use the sticker number); the serial number moves into the plate's place when it is on the sticker. Blank sticker codes are always printed.
8
+
3
9
  ## 4.155.1
4
10
 
5
11
  ### Patch Changes
@@ -3620,11 +3626,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
3620
3626
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
3621
3627
  own rule from two endpoints the console already calls, unprojected:
3622
3628
 
3623
- GET /api/members/user/:user/app/admin the Seven365 staff membership
3624
- GET /api/roles/id/:role that membership's role document
3629
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
3630
+ GET /api/roles/id/:role that membership's role document
3625
3631
 
3626
- owner = member.type === "admin" && role.type === "admin" && role.default === true
3627
- staff = member.type === "admin" && role.type === "admin"
3632
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
3633
+ staff = member.type === "admin" && role.type === "admin"
3628
3634
 
3629
3635
  `role.default` is the marker because it is the only property of a platform
3630
3636
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -157,13 +157,18 @@
157
157
  data-test="vehicle-qr-text" />
158
158
  </v-col>
159
159
  <v-col v-if="design.shape === 'square' || design.text !== 'none'" cols="12" sm="6" md="4">
160
- <v-select v-model="design.label" :items="LABEL_OPTIONS" label="Words under the plate" density="compact"
160
+ <v-select v-model="design.label" :items="LABEL_OPTIONS"
161
+ :label="design.plate === 'hide' ? 'Words on the sticker' : 'Words under the plate'" density="compact"
161
162
  hide-details />
162
163
  </v-col>
163
164
  <v-col cols="12" sm="6" md="4">
164
165
  <v-select v-model="design.serial" :items="SERIAL_OPTIONS" label="Serial number (No. 1, 2, 3 ...)" density="compact"
165
166
  hide-details data-test="vehicle-qr-serial" />
166
167
  </v-col>
168
+ <v-col v-if="!isBlank" cols="12" sm="6" md="4">
169
+ <v-select v-model="design.plate" :items="PLATE_OPTIONS" label="Vehicle number on print-out" density="compact"
170
+ hide-details data-test="vehicle-qr-plate" />
171
+ </v-col>
167
172
  </v-row>
168
173
  <div class="d-flex align-center flex-wrap">
169
174
  <v-switch v-model="design.cutLines" label="Show cut lines" color="primary" density="compact" hide-details
@@ -252,6 +257,7 @@ import {
252
257
  stickerSizeInfo,
253
258
  stickerSizeLines,
254
259
  stickerCardSvgs,
260
+ stickerFileLabel,
255
261
  stickerWarning,
256
262
  type StickerItem,
257
263
  type StickerPlateRow,
@@ -262,12 +268,14 @@ import {
262
268
  EYE_OPTIONS,
263
269
  LABEL_OPTIONS,
264
270
  SERIAL_OPTIONS,
271
+ PLATE_OPTIONS,
265
272
  QR_SHAPE_OPTIONS,
266
273
  QR_ECC,
267
274
  STICKER_THEMES,
268
275
  TEXT_OPTIONS,
269
276
  frameOptionsFor,
270
277
  normalizeDesign,
278
+ printedDesign,
271
279
  rememberedDesign,
272
280
  sizeOptionsFor,
273
281
  stickerFaceSvg,
@@ -385,13 +393,13 @@ watch(
385
393
  );
386
394
  const frameItems = computed(() => frameOptionsFor(design.shape));
387
395
  const sizeItems = computed(() => {
388
- const look = normalizeDesign(design);
396
+ const look = printedDesign(design, isBlank.value, siteName.value);
389
397
  return sizeOptionsFor(look, STICKER_QR_MODULES).map((o) => {
390
398
  const info = stickerSizeInfo({ ...look, size: o.value });
391
399
  return { value: o.value, title: `${o.title} - ${Math.round(info.shapeW)} mm wide, QR ${Math.round(info.qrMm)} mm` };
392
400
  });
393
401
  });
394
- const sizeLines = computed(() => stickerSizeLines(normalizeDesign(design)));
402
+ const sizeLines = computed(() => stickerSizeLines(printedDesign(design, isBlank.value, siteName.value)));
395
403
 
396
404
  const onlyWithSticker = ref(false);
397
405
  const shownPlates = computed(() => (onlyWithSticker.value ? plates.value.filter((p) => p.hasSticker) : plates.value));
@@ -504,7 +512,7 @@ function chosenItems() {
504
512
 
505
513
  // The QR content and error correction (Q) are the same on every design.
506
514
  function faceArgs(chosen: StickerItem[]) {
507
- const look = normalizeDesign(design);
515
+ const look = printedDesign(design, isBlank.value, siteName.value);
508
516
  const codes = chosen.map((i) => QRCode.create(i.qr, { errorCorrectionLevel: QR_ECC as QRCode.QRCodeErrorCorrectionLevel }).modules);
509
517
  const faces = chosen.map((i, k) => stickerFaceSvg(codes[k], look, i.qr));
510
518
  return [faces, { design: look, siteName: siteName.value, modules: codes[0].size }] as const;
@@ -533,7 +541,7 @@ async function saveImages(format: ImageFormat, dpi: number) {
533
541
  const [faces, opts] = faceArgs(chosen);
534
542
  const cards = stickerCardSvgs(chosen, faces, { ...opts, dpi });
535
543
  const ext = format === "jpeg" ? "jpg" : "png";
536
- const names = stickerFileNames(chosen.map((i) => i.plateNumber), ext);
544
+ const names = stickerFileNames(chosen.map((i) => stickerFileLabel(i, opts.design)), ext);
537
545
  const files = [];
538
546
  for (const [k, c] of cards.entries()) files.push({ name: names[k], data: await svgToImage(c.svg, c.width, c.height, format, dpi) });
539
547
  if (files.length === 1) saveFile(files[0].name, files[0].data, `image/${format}`);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.155.1",
5
+ "version": "4.156.0",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
@@ -48,6 +48,8 @@ export type LabelChoice = "app" | "verify" | "scanme" | "site" | "none";
48
48
  export type TextChoice = "below" | "none";
49
49
  /** Where the sticker's running number ("No. 12") is printed: not at all, on the sticker, on the cut-off strip, or both. */
50
50
  export type SerialChoice = "off" | "sticker" | "strip" | "both";
51
+ /** The vehicle's plate number on the print-out: shown, or left off (a blank sticker's code is always printed). */
52
+ export type PlateChoice = "show" | "hide";
51
53
 
52
54
  export type StickerTheme = { id: string; title: string; ink: string; eye: string; paper: string };
53
55
 
@@ -65,6 +67,7 @@ export type StickerDesign = {
65
67
  /** A thin grey line around each sticker to cut along. */
66
68
  cutLines?: boolean;
67
69
  serial?: SerialChoice;
70
+ plate?: PlateChoice;
68
71
  };
69
72
 
70
73
  export const DOT_OPTIONS: { value: DotShape; title: string }[] = [
@@ -146,6 +149,11 @@ export const SERIAL_OPTIONS: { value: SerialChoice; title: string }[] = [
146
149
  { value: "both", title: "On the sticker and the strip" },
147
150
  ];
148
151
 
152
+ export const PLATE_OPTIONS: { value: PlateChoice; title: string }[] = [
153
+ { value: "show", title: "Show" },
154
+ { value: "hide", title: "Hide (not printed)" },
155
+ ];
156
+
149
157
  export const LABEL_OPTIONS: { value: LabelChoice; title: string }[] = [
150
158
  { value: "app", title: "Scan with iSecure365 / iMA365" },
151
159
  { value: "verify", title: "Scan to verify vehicle" },
@@ -176,6 +184,7 @@ export const DEFAULT_STICKER_DESIGN: StickerDesign = {
176
184
  text: "below",
177
185
  cutLines: true,
178
186
  serial: "sticker",
187
+ plate: "show",
179
188
  };
180
189
 
181
190
  /** A saved or typed-in design with anything unknown replaced by the default. */
@@ -199,6 +208,7 @@ export function normalizeDesign(raw: unknown): StickerDesign {
199
208
  text: pick(r.text, TEXT_OPTIONS, d.text),
200
209
  cutLines: typeof r.cutLines === "boolean" ? r.cutLines : true,
201
210
  serial: pick(r.serial, SERIAL_OPTIONS, d.serial),
211
+ plate: pick(r.plate, PLATE_OPTIONS, d.plate!),
202
212
  };
203
213
  }
204
214
 
@@ -212,6 +222,18 @@ export function rememberedDesign(saved: unknown, savedSerial: unknown): StickerD
212
222
  return normalizeDesign({ ...r, serial: savedSerial });
213
223
  }
214
224
 
225
+ /**
226
+ * The design as printed. With the plate hidden on vehicle stickers, a shaped
227
+ * code whose tab under the shape would be left empty (no serial or words on
228
+ * it) is printed with no tab, so no bare paper tab hangs under the shape.
229
+ * Blank stickers always print their code in the tab, so they keep it.
230
+ */
231
+ export function printedDesign(design: unknown, blank = false, siteName = ""): StickerDesign {
232
+ const d = normalizeDesign(design);
233
+ const tabEmpty = d.serial !== "sticker" && d.serial !== "both" && !stickerLabel(d, siteName);
234
+ return !blank && d.plate === "hide" && isSilhouette(d.shape) && d.text === "below" && tabEmpty ? { ...d, text: "none" } : d;
235
+ }
236
+
215
237
  export function stickerTheme(id: string): StickerTheme {
216
238
  return STICKER_THEMES.find((t) => t.id === id) ?? STICKER_THEMES[0];
217
239
  }
@@ -18,7 +18,7 @@ import {
18
18
  stickerTheme,
19
19
  type StickerDesign,
20
20
  } from "./vehicle-qr-design.ts";
21
- import { BLANK_STRIP_NOTE, plateLines } from "./vehicle-qr-blank.ts";
21
+ import { BLANK_STRIP_NOTE, isBlankCode, plateLines } from "./vehicle-qr-blank.ts";
22
22
 
23
23
  /** The server's most vehicles per request (POST /api/vehicles/qr/stickers). */
24
24
  export const STICKER_MAX_PER_REQUEST = 500;
@@ -203,6 +203,28 @@ export function stickerSerial(item: Pick<StickerItem, "serialNo">): string {
203
203
  return Number.isInteger(n) && n > 0 ? `No. ${n}` : "";
204
204
  }
205
205
 
206
+ /** What a saved picture is named after: the plate - or, with the plate hidden, the sticker's number (the file name must not give the plate away either). */
207
+ export function stickerFileLabel(item: StickerItem, design: Pick<StickerDesign, "plate">): string {
208
+ return shownPlateLines(item, design.plate === "hide").length ? text(item.plateNumber) : stickerSerial(item) || "sticker";
209
+ }
210
+
211
+ /** The plate lines printed on a sticker: none when the plate is hidden - but a blank sticker's code is always printed (it is typed to link it). */
212
+ function shownPlateLines(item: StickerItem, hidePlate: boolean): string[] {
213
+ const plate = text(item.plateNumber);
214
+ return hidePlate && !item.blank && !isBlankCode(plate) ? [] : plateLines(plate);
215
+ }
216
+
217
+ /**
218
+ * The big line(s) on the sticker and the small serial under them. With the
219
+ * plate hidden, the serial (when it is on the sticker) moves up into the
220
+ * plate's place, so the sticker keeps its usual look with no hole in it.
221
+ */
222
+ function headLines(item: StickerItem, c: CardContext): { lines: string[]; serialText: string } {
223
+ const lines = shownPlateLines(item, c.hidePlate);
224
+ const serialText = c.serial ? stickerSerial(item) : "";
225
+ return lines.length || !serialText ? { lines, serialText } : { lines: [serialText], serialText: "" };
226
+ }
227
+
206
228
  const serialOnSticker = (d: StickerDesign) => d.serial === "sticker" || d.serial === "both";
207
229
 
208
230
  /** "Blk 4 #02-01". Tolerates a unit that already carries its level ("02-01"). */
@@ -369,7 +391,7 @@ function plateSizeMm(plate: string, boxW: number, max = 4.6): number {
369
391
  * `items` (each sticker's frame + QR, already drawn for the chosen design).
370
392
  * Every value is HTML-escaped - an owner or site name is typed by a person.
371
393
  */
372
- type CardContext = { cardW: number; ink: string; label: string; layout: SheetLayout; k: number; shaped: boolean; bare: boolean; wordsTop: number; tag: { x: number; y: number; w: number; h: number } | null; serial: boolean };
394
+ type CardContext = { cardW: number; ink: string; label: string; layout: SheetLayout; k: number; shaped: boolean; bare: boolean; wordsTop: number; tag: { x: number; y: number; w: number; h: number } | null; serial: boolean; hidePlate: boolean };
373
395
 
374
396
  function cardContext(design: StickerDesign, siteName: string | undefined, n: number): CardContext {
375
397
  const g = stickerGeometry(design, n);
@@ -387,29 +409,29 @@ function cardContext(design: StickerDesign, siteName: string | undefined, n: num
387
409
  wordsTop: mm(((g.qrTop ?? 0) + QR_MM + 0.8) * k),
388
410
  tag: g.band ? { x: mm(g.band.x * k), y: mm(g.band.y * k), w: mm(g.band.w * k), h: mm(g.band.h * k) } : null,
389
411
  serial: serialOnSticker(design),
412
+ hidePlate: design.plate === "hide",
390
413
  };
391
414
  }
392
415
 
393
416
  /** The sticker itself (frame + QR + plate words) - what goes on the car. */
394
417
  function cardHtml(item: StickerItem, face: string, c: CardContext): string {
395
- const lines = plateLines(text(item.plateNumber));
418
+ const { lines, serialText } = headLines(item, c);
396
419
  const plate = lines.map(escapeHtml).join("<br>");
397
420
  const longest = lines.reduce((a, l) => (l.length > a.length ? l : a), "");
398
421
  // a two-line code has no room for the words under it inside the tag
399
422
  const label = c.label && !(c.tag && lines.length > 1) ? `<div class="hint">${escapeHtml(c.label)}</div>` : "";
400
423
  // the serial takes the words' place inside a shape's tag (no room for both)
401
- const serialText = c.serial ? stickerSerial(item) : "";
402
424
  const serial = serialText ? `<div class="serial">${escapeHtml(serialText)}</div>` : "";
403
425
  const tagWords = serial && c.tag ? (lines.length > 1 ? "" : serial) : label;
404
426
  const words = c.shaped && !c.tag
405
427
  ? ""
406
428
  : c.tag
407
429
  ? `<div class="words band" style="left:${c.tag.x}mm;right:auto;top:${c.tag.y}mm;width:${c.tag.w}mm;height:${c.tag.h}mm">` +
408
- `<div class="plate" style="font-size:${plateSizeMm(longest, c.tag.w, 4.6 * c.k)}mm">${plate}</div>` +
430
+ (lines.length ? `<div class="plate" style="font-size:${plateSizeMm(longest, c.tag.w, 4.6 * c.k)}mm">${plate}</div>` : "") +
409
431
  tagWords +
410
432
  `</div>`
411
- : `<div class="words" style="top:${c.wordsTop}mm">` +
412
- `<div class="plate"${lines.length > 1 ? ` style="font-size:${plateSizeMm(longest, c.cardW - 6, 4.6)}mm"` : ""}>${plate}</div>` +
433
+ : `<div class="words" style="top:${c.wordsTop}mm${!lines.length && !label ? ";justify-content:center" : ""}">` +
434
+ (lines.length ? `<div class="plate"${lines.length > 1 ? ` style="font-size:${plateSizeMm(longest, c.cardW - 6, 4.6)}mm"` : ""}>${plate}</div>` : "") +
413
435
  serial +
414
436
  label +
415
437
  `<div class="brand"><span class="mark" style="background:${c.ink}">7</span>Powered by Seven365</div>` +
@@ -432,7 +454,7 @@ export function buildStickerDocument(
432
454
  const c = cardContext(design, opts.siteName, n);
433
455
  // the strip carries the number when chosen - and when the sticker has no room for it
434
456
  // (a bare shape, or a two-line blank code filling a shape's tag)
435
- const noRoom = (item: StickerItem) => (c.shaped && !c.tag) || (!!c.tag && plateLines(text(item.plateNumber)).length > 1);
457
+ const noRoom = (item: StickerItem) => (c.shaped && !c.tag) || (!!c.tag && shownPlateLines(item, c.hidePlate).length > 1);
436
458
  const stripSerial = (item: StickerItem) => design.serial === "strip" || design.serial === "both" || (c.serial && noRoom(item));
437
459
  const cells = items.map((item, i) => {
438
460
  const { place, owner } = installerLine(item);
@@ -469,24 +491,23 @@ function svgLine(t: string, x: number, baseline: number, size: number, maxW: num
469
491
  */
470
492
  function cardWordsSvg(item: StickerItem, c: CardContext): string {
471
493
  if (c.shaped && !c.tag) return "";
472
- const lines = plateLines(text(item.plateNumber));
494
+ const { lines, serialText } = headLines(item, c);
473
495
  const longest = lines.reduce((a, l) => (l.length > a.length ? l : a), "");
474
- const serialText = c.serial ? stickerSerial(item) : "";
475
496
  const box = c.tag ?? { x: 3, y: c.wordsTop, w: c.cardW - 6, h: c.layout.cardH - 2 - c.wordsTop };
476
497
  const plateSize = c.tag
477
498
  ? plateSizeMm(longest, c.tag.w, 4.6 * c.k)
478
499
  : lines.length > 1 ? plateSizeMm(longest, c.cardW - 6, 4.6) : 13 * PT;
479
500
  const small = 5.8 * PT;
480
501
  type Row = { h: number; draw: (top: number) => string };
481
- const rows: Row[] = [
482
- {
502
+ const rows: Row[] = [];
503
+ if (lines.length)
504
+ rows.push({
483
505
  h: 1.1 * plateSize * lines.length,
484
506
  draw: (top) =>
485
507
  lines
486
508
  .map((l, n) => svgLine(l, box.x + box.w / 2, top + (0.955 + 1.1 * n) * plateSize, plateSize, box.w, `font-weight="800" letter-spacing="0.3"`, 0.7))
487
509
  .join(""),
488
- },
489
- ];
510
+ });
490
511
  const word = (t: string, bold: boolean): Row => ({
491
512
  h: 1.2 * small,
492
513
  draw: (top) => svgLine(t, box.x + box.w / 2, top + small, small, box.w, bold ? `font-weight="700" letter-spacing="0.15"` : `opacity="0.85"`),
@@ -517,7 +538,8 @@ function cardWordsSvg(item: StickerItem, c: CardContext): string {
517
538
  const used = rows.reduce((n, r) => n + r.h, 0);
518
539
  // the card spreads its rows top to bottom; a tag centres them with 0.6 mm between
519
540
  const gap = c.tag ? 0.6 : rows.length > 1 ? Math.max(0, (box.h - used) / (rows.length - 1)) : 0;
520
- let top = c.tag ? box.y + (box.h - used - gap * (rows.length - 1)) / 2 : box.y;
541
+ // (a lone Seven365 line - plate hidden, nothing else - sits in the middle of the card)
542
+ let top = c.tag || rows.length === 1 ? box.y + (box.h - used - gap * (rows.length - 1)) / 2 : box.y;
521
543
  const out = rows.map((r) => {
522
544
  const svg = r.draw(top);
523
545
  top += r.h + gap;