@7365admin1/layer-common 4.151.2 → 4.152.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 +16 -4
- package/components/FeedbackHandlingSettings.vue +20 -2
- package/components/SiteDataRetention.vue +5 -1
- package/components/VehicleQrCodeScanner.vue +4 -2
- package/components/VehicleQrStickerDialog.vue +6 -1
- package/package.json +1 -1
- package/utils/vehicle-qr-blank.ts +16 -5
- package/utils/vehicle-qr-design.ts +23 -2
- package/utils/vehicle-qr-sticker.ts +121 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @iservice365/layer-common
|
|
2
2
|
|
|
3
|
+
## 4.152.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 50336c9: Vehicle QR stickers: a "Serial number (No. 1, 2, 3 ...)" choice in the print dialog prints each sticker's site number ("No. 12") on the sticker, on the cut-off strip, on both, or not at all; stickers now carry the link QR (33 modules; the car shape at Small is no longer offered because its dots would print under 0.77 mm). Save as PNG / JPEG now draws the sticker as plain SVG instead of HTML inside the SVG, so it works in Safari (Mac, iPad, iPhone) - before, Safari refused to save the picture. The blank-sticker scanner and typed codes also accept the link form.
|
|
8
|
+
|
|
9
|
+
## 4.151.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 52574dd: Site Settings: Feedback handling's "Notify these people" list now loads the managing agent's staff (it was always empty - the members request was rejected), and Data retention says the removal records are owner-only instead of "No records have been removed" when the viewer may not see them.
|
|
14
|
+
|
|
3
15
|
## 4.151.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -3578,11 +3590,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
|
|
|
3578
3590
|
`utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
|
|
3579
3591
|
own rule from two endpoints the console already calls, unprojected:
|
|
3580
3592
|
|
|
3581
|
-
|
|
3582
|
-
|
|
3593
|
+
GET /api/members/user/:user/app/admin the Seven365 staff membership
|
|
3594
|
+
GET /api/roles/id/:role that membership's role document
|
|
3583
3595
|
|
|
3584
|
-
|
|
3585
|
-
|
|
3596
|
+
owner = member.type === "admin" && role.type === "admin" && role.default === true
|
|
3597
|
+
staff = member.type === "admin" && role.type === "admin"
|
|
3586
3598
|
|
|
3587
3599
|
`role.default` is the marker because it is the only property of a platform
|
|
3588
3600
|
staff role no API caller can set - `role.controller.ts` validates create and
|
|
@@ -266,8 +266,10 @@ const props = withDefaults(
|
|
|
266
266
|
siteId: string;
|
|
267
267
|
orgId?: string;
|
|
268
268
|
canEdit?: boolean;
|
|
269
|
+
/** Member type of `orgId`'s staff (the app hosting this card). */
|
|
270
|
+
memberType?: string;
|
|
269
271
|
}>(),
|
|
270
|
-
{ orgId: "", canEdit: false },
|
|
272
|
+
{ orgId: "", canEdit: false, memberType: "property_management_agency" },
|
|
271
273
|
);
|
|
272
274
|
|
|
273
275
|
const emit = defineEmits<{ saved: [] }>();
|
|
@@ -312,6 +314,22 @@ function notify(text: string, color: string) {
|
|
|
312
314
|
snackbar.value = true;
|
|
313
315
|
}
|
|
314
316
|
|
|
317
|
+
/**
|
|
318
|
+
* Everyone on `orgId`'s staff, page by page. The server needs `type` and caps
|
|
319
|
+
* `limit` at 50 (without them the list came back 400 and stayed empty). Staff
|
|
320
|
+
* are org-wide, so no `siteId`: that only matches members pinned to the site.
|
|
321
|
+
*/
|
|
322
|
+
async function orgMembers() {
|
|
323
|
+
const items: any[] = [];
|
|
324
|
+
// ponytail: 10 pages = 500 staff; raise if an org ever has more.
|
|
325
|
+
for (let page = 1; page <= 10; page++) {
|
|
326
|
+
const res: any = await getMembers({ org: props.orgId, type: props.memberType, status: "active", page, limit: 50 });
|
|
327
|
+
items.push(...(res?.items ?? []));
|
|
328
|
+
if (!res?.pages || page >= res.pages) break;
|
|
329
|
+
}
|
|
330
|
+
return { items };
|
|
331
|
+
}
|
|
332
|
+
|
|
315
333
|
async function load() {
|
|
316
334
|
loading.value = true;
|
|
317
335
|
try {
|
|
@@ -320,7 +338,7 @@ async function load() {
|
|
|
320
338
|
loaded.value = !!site;
|
|
321
339
|
const [p, m] = await Promise.allSettled([
|
|
322
340
|
getProviders({ siteId: props.siteId, limit: 100, status: "active" }),
|
|
323
|
-
|
|
341
|
+
orgMembers(),
|
|
324
342
|
]);
|
|
325
343
|
if (p.status === "fulfilled") {
|
|
326
344
|
providers.value = (p.value?.items ?? []).map((i: any) => ({
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
<div class="sdr-label mt-6">Data removal records</div>
|
|
49
49
|
<div class="sdr-sub">Each removal, with a certificate you can give your DPO (data protection lead).</div>
|
|
50
50
|
<div v-if="recordsLoading" class="sdr-sub">Loading...</div>
|
|
51
|
+
<div v-else-if="recordsDenied" class="sdr-sub" data-test="sdr-records-denied">Only the client that owns this site can see the removal records.</div>
|
|
51
52
|
<div v-else-if="!records.length" class="sdr-sub" data-test="sdr-no-records">No records have been removed at this site.</div>
|
|
52
53
|
<div v-for="r in records" :key="r._id" class="sdr-record" data-test="sdr-record">
|
|
53
54
|
<div>
|
|
@@ -86,6 +87,8 @@ const { listDataPurgeRecords, downloadDataPurgeCertificate } = useDataRetention(
|
|
|
86
87
|
|
|
87
88
|
const records = ref<Record<string, any>[]>([]);
|
|
88
89
|
const recordsLoading = ref(false);
|
|
90
|
+
/** 403: records are for the site's owner (and Seven365) only - not "nothing removed". */
|
|
91
|
+
const recordsDenied = ref(false);
|
|
89
92
|
const downloading = ref("");
|
|
90
93
|
const error = ref("");
|
|
91
94
|
|
|
@@ -121,8 +124,9 @@ async function loadRecords() {
|
|
|
121
124
|
recordsLoading.value = true;
|
|
122
125
|
try {
|
|
123
126
|
records.value = (await listDataPurgeRecords(props.siteId))?.items ?? [];
|
|
124
|
-
} catch {
|
|
127
|
+
} catch (e: any) {
|
|
125
128
|
records.value = [];
|
|
129
|
+
recordsDenied.value = (e?.statusCode ?? e?.status ?? e?.response?.status) === 403;
|
|
126
130
|
} finally {
|
|
127
131
|
recordsLoading.value = false;
|
|
128
132
|
}
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
</div>
|
|
10
10
|
</template>
|
|
11
11
|
<script setup lang="ts">
|
|
12
|
-
|
|
12
|
+
import { stickerQrToken } from "../utils/vehicle-qr-blank";
|
|
13
|
+
|
|
14
|
+
// Camera scan of a blank sticker: emits the code the QR carries ("S365V:" or the link is trimmed).
|
|
13
15
|
defineProps({ disabled: { type: Boolean, default: false } });
|
|
14
16
|
const emit = defineEmits<{ (e: "scanned", code: string): void }>();
|
|
15
17
|
const { $Html5Qrcode }: any = useNuxtApp();
|
|
@@ -28,7 +30,7 @@ async function start() {
|
|
|
28
30
|
{ facingMode: "environment" },
|
|
29
31
|
{ fps: 10, qrbox: { width: 220, height: 220 } },
|
|
30
32
|
async (text: string) => {
|
|
31
|
-
emit("scanned",
|
|
33
|
+
emit("scanned", stickerQrToken(text));
|
|
32
34
|
await stop();
|
|
33
35
|
},
|
|
34
36
|
() => {},
|
|
@@ -160,6 +160,10 @@
|
|
|
160
160
|
<v-select v-model="design.label" :items="LABEL_OPTIONS" label="Words under the plate" density="compact"
|
|
161
161
|
hide-details />
|
|
162
162
|
</v-col>
|
|
163
|
+
<v-col cols="12" sm="6" md="4">
|
|
164
|
+
<v-select v-model="design.serial" :items="SERIAL_OPTIONS" label="Serial number (No. 1, 2, 3 ...)" density="compact"
|
|
165
|
+
hide-details data-test="vehicle-qr-serial" />
|
|
166
|
+
</v-col>
|
|
163
167
|
</v-row>
|
|
164
168
|
<div class="d-flex align-center flex-wrap">
|
|
165
169
|
<v-switch v-model="design.cutLines" label="Show cut lines" color="primary" density="compact" hide-details
|
|
@@ -257,6 +261,7 @@ import {
|
|
|
257
261
|
DOT_OPTIONS,
|
|
258
262
|
EYE_OPTIONS,
|
|
259
263
|
LABEL_OPTIONS,
|
|
264
|
+
SERIAL_OPTIONS,
|
|
260
265
|
QR_SHAPE_OPTIONS,
|
|
261
266
|
QR_ECC,
|
|
262
267
|
STICKER_THEMES,
|
|
@@ -335,7 +340,7 @@ function resetDesign() {
|
|
|
335
340
|
}
|
|
336
341
|
|
|
337
342
|
// A small live picture of every QR shape in the current dots / corners / colours.
|
|
338
|
-
const SAMPLE = "
|
|
343
|
+
const SAMPLE = "HTTPS://APP.ISERVICE365.ORG/Q/SamplePreviewToken0000";
|
|
339
344
|
const sampleCode = QRCode.create(SAMPLE, { errorCorrectionLevel: QR_ECC as QRCode.QRCodeErrorCorrectionLevel }).modules;
|
|
340
345
|
const shapeThumbs = computed(() => {
|
|
341
346
|
const look = normalizeDesign(design);
|
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.
|
|
5
|
+
"version": "4.152.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.",
|
|
@@ -15,7 +15,7 @@ export const BLANK_TOKEN_LENGTH = 24;
|
|
|
15
15
|
/** What the installer strip says under a blank sticker. */
|
|
16
16
|
export const BLANK_STRIP_NOTE = "Not linked yet - link it in Vehicles > Link QR sticker, or scan it with iMA365 / iSecure365";
|
|
17
17
|
|
|
18
|
-
export type BlankItem = { token: string; qr: string; code: string };
|
|
18
|
+
export type BlankItem = { token: string; qr: string; code: string; serialNo?: number };
|
|
19
19
|
|
|
20
20
|
/** A whole number 1..500, or 0 when the field is empty or not a number. */
|
|
21
21
|
export function blankCount(value: unknown): number {
|
|
@@ -25,13 +25,24 @@ export function blankCount(value: unknown): number {
|
|
|
25
25
|
|
|
26
26
|
/** Sticker items for the normal sticker flow: token = the unique key, the code is printed in the plate slot. */
|
|
27
27
|
export function blankStickerItems(items: BlankItem[]): StickerItem[] {
|
|
28
|
-
return items.map((i) => ({ vehicleId: i.token, qr: i.qr, token: i.token, plateNumber: i.code, status: "active", blank: true }));
|
|
28
|
+
return items.map((i) => ({ vehicleId: i.token, qr: i.qr, token: i.token, plateNumber: i.code, status: "active", blank: true, ...(i.serialNo ? { serialNo: i.serialNo } : {}) }));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* The token a sticker's QR carries: older stickers hold "S365V:<token>", newer
|
|
33
|
+
* ones a link ".../q/<token>" (a phone camera opens a "no data" page).
|
|
34
|
+
*/
|
|
35
|
+
export function stickerQrToken(scanned: unknown): string {
|
|
36
|
+
return String(scanned ?? "")
|
|
37
|
+
.trim()
|
|
38
|
+
.replace(/^S365V:/i, "")
|
|
39
|
+
.replace(/^https?:\/\/[^/]+\/q\//i, "")
|
|
40
|
+
.trim();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** What staff type, as the server reads it: no spaces or dashes, capitals, I/L as 1, O as 0. A pasted "S365V:" or link is ignored. */
|
|
32
44
|
export function normalizeStickerCode(input: unknown): string {
|
|
33
|
-
return
|
|
34
|
-
.replace(/^\s*S365V:/i, "")
|
|
45
|
+
return stickerQrToken(input)
|
|
35
46
|
.replace(/[^0-9A-Za-z]/g, "")
|
|
36
47
|
.toUpperCase()
|
|
37
48
|
.replace(/[IL]/g, "1")
|
|
@@ -46,6 +46,8 @@ export type SizeChoice = "small" | "standard" | "large";
|
|
|
46
46
|
export type LabelChoice = "app" | "verify" | "scanme" | "site" | "none";
|
|
47
47
|
/** Shaped codes: the plate number on a tab under the shape, or no text at all. */
|
|
48
48
|
export type TextChoice = "below" | "none";
|
|
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
|
+
export type SerialChoice = "off" | "sticker" | "strip" | "both";
|
|
49
51
|
|
|
50
52
|
export type StickerTheme = { id: string; title: string; ink: string; eye: string; paper: string };
|
|
51
53
|
|
|
@@ -62,6 +64,7 @@ export type StickerDesign = {
|
|
|
62
64
|
text: TextChoice;
|
|
63
65
|
/** A thin grey line around each sticker to cut along. */
|
|
64
66
|
cutLines?: boolean;
|
|
67
|
+
serial?: SerialChoice;
|
|
65
68
|
};
|
|
66
69
|
|
|
67
70
|
export const DOT_OPTIONS: { value: DotShape; title: string }[] = [
|
|
@@ -120,6 +123,12 @@ export const sizeScale = (size: SizeChoice) => SIZE_OPTIONS.find((o) => o.value
|
|
|
120
123
|
|
|
121
124
|
/** The printed QR code (its data area, without the quiet zone) is never smaller than this. */
|
|
122
125
|
export const MIN_QR_DATA_MM = 25;
|
|
126
|
+
/**
|
|
127
|
+
* ...and no QR dot (module) smaller than this. The link code has 33 modules
|
|
128
|
+
* across: at 0.765 mm (the car shape at Small) ZXing missed 5 of 1722 blurred
|
|
129
|
+
* or 90%-printed reads; from 0.78 mm (the square at Standard) every read passed.
|
|
130
|
+
*/
|
|
131
|
+
export const MIN_MODULE_MM = 0.77;
|
|
123
132
|
|
|
124
133
|
export function isSilhouette(shape: unknown): shape is SilhouetteShape {
|
|
125
134
|
return SILHOUETTE_OPTIONS.some((o) => o.value === shape);
|
|
@@ -130,6 +139,13 @@ export const TEXT_OPTIONS: { value: TextChoice; title: string }[] = [
|
|
|
130
139
|
{ value: "none", title: "No text (only the shape)" },
|
|
131
140
|
];
|
|
132
141
|
|
|
142
|
+
export const SERIAL_OPTIONS: { value: SerialChoice; title: string }[] = [
|
|
143
|
+
{ value: "off", title: "Do not print" },
|
|
144
|
+
{ value: "sticker", title: "On the sticker (under the plate)" },
|
|
145
|
+
{ value: "strip", title: "On the cut-off strip only" },
|
|
146
|
+
{ value: "both", title: "On the sticker and the strip" },
|
|
147
|
+
];
|
|
148
|
+
|
|
133
149
|
export const LABEL_OPTIONS: { value: LabelChoice; title: string }[] = [
|
|
134
150
|
{ value: "app", title: "Scan with iSecure365 / iMA365" },
|
|
135
151
|
{ value: "verify", title: "Scan to verify vehicle" },
|
|
@@ -159,6 +175,7 @@ export const DEFAULT_STICKER_DESIGN: StickerDesign = {
|
|
|
159
175
|
label: "app",
|
|
160
176
|
text: "below",
|
|
161
177
|
cutLines: true,
|
|
178
|
+
serial: "off",
|
|
162
179
|
};
|
|
163
180
|
|
|
164
181
|
/** A saved or typed-in design with anything unknown replaced by the default. */
|
|
@@ -181,6 +198,7 @@ export function normalizeDesign(raw: unknown): StickerDesign {
|
|
|
181
198
|
label: pick(r.label, LABEL_OPTIONS, d.label),
|
|
182
199
|
text: pick(r.text, TEXT_OPTIONS, d.text),
|
|
183
200
|
cutLines: typeof r.cutLines === "boolean" ? r.cutLines : true,
|
|
201
|
+
serial: pick(r.serial, SERIAL_OPTIONS, "off"),
|
|
184
202
|
};
|
|
185
203
|
}
|
|
186
204
|
|
|
@@ -498,9 +516,12 @@ export function stickerGeometry(design: StickerDesign, n: number): StickerGeomet
|
|
|
498
516
|
};
|
|
499
517
|
}
|
|
500
518
|
|
|
501
|
-
/** Sizes that keep the printed code at least MIN_QR_DATA_MM. */
|
|
519
|
+
/** Sizes that keep the printed code at least MIN_QR_DATA_MM, with dots of at least MIN_MODULE_MM. */
|
|
502
520
|
export function sizeOptionsFor(design: StickerDesign, n: number) {
|
|
503
|
-
return SIZE_OPTIONS.filter((o) =>
|
|
521
|
+
return SIZE_OPTIONS.filter((o) => {
|
|
522
|
+
const { dataMm } = stickerGeometry({ ...design, size: o.value }, n);
|
|
523
|
+
return dataMm >= MIN_QR_DATA_MM - 1e-9 && dataMm / n >= MIN_MODULE_MM;
|
|
524
|
+
});
|
|
504
525
|
}
|
|
505
526
|
|
|
506
527
|
/** Same number for the same text + cell every time (no randomness between prints). */
|
|
@@ -23,8 +23,12 @@ import { BLANK_STRIP_NOTE, plateLines } from "./vehicle-qr-blank.ts";
|
|
|
23
23
|
/** The server's most vehicles per request (POST /api/vehicles/qr/stickers). */
|
|
24
24
|
export const STICKER_MAX_PER_REQUEST = 500;
|
|
25
25
|
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Modules across the sticker QR: the link "HTTPS://APP.ISERVICE365.ORG/Q/" + a
|
|
28
|
+
* 22- or 24-character token at ECC Q is always version 4. (Older stickers held
|
|
29
|
+
* "S365V:<token>", version 3 / 29 modules; they still scan.)
|
|
30
|
+
*/
|
|
31
|
+
export const STICKER_QR_MODULES = 33;
|
|
28
32
|
|
|
29
33
|
/** The classic card sheet at Standard size: 4 columns x 4 rows. */
|
|
30
34
|
export const STICKERS_PER_PAGE = 16;
|
|
@@ -173,6 +177,8 @@ export type StickerItem = {
|
|
|
173
177
|
status?: string;
|
|
174
178
|
/** A blank (pre-generated) sticker: `plateNumber` holds its printed code and it is not linked to a vehicle yet. */
|
|
175
179
|
blank?: boolean;
|
|
180
|
+
/** The sticker's running number at its site (1, 2, 3 ...). */
|
|
181
|
+
serialNo?: number;
|
|
176
182
|
};
|
|
177
183
|
|
|
178
184
|
export type StickerPlateRow = {
|
|
@@ -187,6 +193,18 @@ export type StickerPlateRow = {
|
|
|
187
193
|
|
|
188
194
|
const text = (v: unknown) => (v == null ? "" : String(v).trim());
|
|
189
195
|
|
|
196
|
+
/**
|
|
197
|
+
* The sticker's running number at its site, "No. 12": the server gives each
|
|
198
|
+
* sticker the next number when it is first printed (1, 2, 3 ...) and it never
|
|
199
|
+
* changes, so No. 1 stays Mrs Tan's sticker. "" when the server sent none.
|
|
200
|
+
*/
|
|
201
|
+
export function stickerSerial(item: Pick<StickerItem, "serialNo">): string {
|
|
202
|
+
const n = Number(item?.serialNo);
|
|
203
|
+
return Number.isInteger(n) && n > 0 ? `No. ${n}` : "";
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const serialOnSticker = (d: StickerDesign) => d.serial === "sticker" || d.serial === "both";
|
|
207
|
+
|
|
190
208
|
/** "Blk 4 #02-01". Tolerates a unit that already carries its level ("02-01"). */
|
|
191
209
|
export function stickerUnitLabel(parts: { block?: unknown; level?: unknown; unit?: unknown }): string {
|
|
192
210
|
const block = text(parts.block).replace(/^(blk|block)\.?\s*/i, "");
|
|
@@ -305,6 +323,8 @@ html, body { margin: 0; padding: 0; background: #fff; color: #111; font-family:
|
|
|
305
323
|
.words { position: absolute; left: 3mm; right: 3mm; bottom: 2mm; display: flex; flex-direction: column; align-items: center; justify-content: space-between; text-align: center; }
|
|
306
324
|
.words.band { bottom: auto; justify-content: center; gap: 0.6mm; }
|
|
307
325
|
.plate { font-size: 13pt; font-weight: 800; letter-spacing: 0.3mm; line-height: 1.1; white-space: nowrap; }
|
|
326
|
+
.serial { font-size: 5.8pt; font-weight: 700; letter-spacing: 0.15mm; line-height: 1.2; white-space: nowrap; }
|
|
327
|
+
.cut .sn { float: right; font-weight: 700; margin-left: 1mm; }
|
|
308
328
|
.hint { font-size: 5.8pt; line-height: 1.2; opacity: 0.85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
|
|
309
329
|
.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; }
|
|
310
330
|
.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; }
|
|
@@ -349,7 +369,7 @@ function plateSizeMm(plate: string, boxW: number, max = 4.6): number {
|
|
|
349
369
|
* `items` (each sticker's frame + QR, already drawn for the chosen design).
|
|
350
370
|
* Every value is HTML-escaped - an owner or site name is typed by a person.
|
|
351
371
|
*/
|
|
352
|
-
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 };
|
|
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 };
|
|
353
373
|
|
|
354
374
|
function cardContext(design: StickerDesign, siteName: string | undefined, n: number): CardContext {
|
|
355
375
|
const g = stickerGeometry(design, n);
|
|
@@ -366,6 +386,7 @@ function cardContext(design: StickerDesign, siteName: string | undefined, n: num
|
|
|
366
386
|
bare: shaped && design.frame === "none",
|
|
367
387
|
wordsTop: mm(((g.qrTop ?? 0) + QR_MM + 0.8) * k),
|
|
368
388
|
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
|
+
serial: serialOnSticker(design),
|
|
369
390
|
};
|
|
370
391
|
}
|
|
371
392
|
|
|
@@ -376,15 +397,20 @@ function cardHtml(item: StickerItem, face: string, c: CardContext): string {
|
|
|
376
397
|
const longest = lines.reduce((a, l) => (l.length > a.length ? l : a), "");
|
|
377
398
|
// a two-line code has no room for the words under it inside the tag
|
|
378
399
|
const label = c.label && !(c.tag && lines.length > 1) ? `<div class="hint">${escapeHtml(c.label)}</div>` : "";
|
|
400
|
+
// the serial takes the words' place inside a shape's tag (no room for both)
|
|
401
|
+
const serialText = c.serial ? stickerSerial(item) : "";
|
|
402
|
+
const serial = serialText ? `<div class="serial">${escapeHtml(serialText)}</div>` : "";
|
|
403
|
+
const tagWords = serial && c.tag ? (lines.length > 1 ? "" : serial) : label;
|
|
379
404
|
const words = c.shaped && !c.tag
|
|
380
405
|
? ""
|
|
381
406
|
: c.tag
|
|
382
407
|
? `<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">` +
|
|
383
408
|
`<div class="plate" style="font-size:${plateSizeMm(longest, c.tag.w, 4.6 * c.k)}mm">${plate}</div>` +
|
|
384
|
-
|
|
409
|
+
tagWords +
|
|
385
410
|
`</div>`
|
|
386
411
|
: `<div class="words" style="top:${c.wordsTop}mm">` +
|
|
387
412
|
`<div class="plate"${lines.length > 1 ? ` style="font-size:${plateSizeMm(longest, c.cardW - 6, 4.6)}mm"` : ""}>${plate}</div>` +
|
|
413
|
+
serial +
|
|
388
414
|
label +
|
|
389
415
|
`<div class="brand"><span class="mark" style="background:${c.ink}">7</span>Powered by Seven365</div>` +
|
|
390
416
|
`</div>`;
|
|
@@ -404,12 +430,17 @@ export function buildStickerDocument(
|
|
|
404
430
|
const design = opts.design ?? DEFAULT_STICKER_DESIGN;
|
|
405
431
|
const n = opts.modules ?? STICKER_QR_MODULES;
|
|
406
432
|
const c = cardContext(design, opts.siteName, n);
|
|
433
|
+
// the strip carries the number when chosen - and when the sticker has no room for it
|
|
434
|
+
// (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);
|
|
436
|
+
const stripSerial = (item: StickerItem) => design.serial === "strip" || design.serial === "both" || (c.serial && noRoom(item));
|
|
407
437
|
const cells = items.map((item, i) => {
|
|
408
438
|
const { place, owner } = installerLine(item);
|
|
409
439
|
const [noteHead, noteRest] = BLANK_STRIP_NOTE.split(" - ");
|
|
440
|
+
const sn = stripSerial(item) ? `<span class="sn">${escapeHtml(stickerSerial(item))}</span>` : "";
|
|
410
441
|
const strip = item.blank
|
|
411
|
-
? `<div class="cut${c.bare ? " free" : ""} blank"><div
|
|
412
|
-
: `<div class="cut${c.bare ? " free" : ""}"><div
|
|
442
|
+
? `<div class="cut${c.bare ? " free" : ""} blank"><div>${sn}<b>${escapeHtml(noteHead)}</b></div><div>${escapeHtml(noteRest)}</div></div>`
|
|
443
|
+
: `<div class="cut${c.bare ? " free" : ""}"><div>${sn}<b>${escapeHtml(place || "-")}</b></div><div class="owner">Owner: ${escapeHtml(owner || "-")}</div></div>`;
|
|
413
444
|
return (
|
|
414
445
|
`<div class="cell">${cardHtml(item, faceSvgs[i] ?? "", c)}` +
|
|
415
446
|
`${strip}</div>`
|
|
@@ -421,14 +452,85 @@ export function buildStickerDocument(
|
|
|
421
452
|
return `<!doctype html><html><head><meta charset="utf-8"><title>Vehicle QR stickers</title><style>${printCss(c.layout)}</style></head><body>${pages.join("")}</body></html>`;
|
|
422
453
|
}
|
|
423
454
|
|
|
424
|
-
|
|
425
|
-
const
|
|
455
|
+
const PT = 25.4 / 72;
|
|
456
|
+
const FONT = `font-family="Arial, Helvetica, sans-serif"`;
|
|
457
|
+
|
|
458
|
+
/** One centred line of SVG text; squeezed to `maxW` when Arial would run wider. */
|
|
459
|
+
function svgLine(t: string, x: number, baseline: number, size: number, maxW: number, extra = "", em = 0.55): string {
|
|
460
|
+
const fit = t.length * em * size > maxW ? ` textLength="${mm(maxW)}" lengthAdjust="spacingAndGlyphs"` : "";
|
|
461
|
+
return `<text x="${mm(x)}" y="${mm(baseline)}" font-size="${mm(size)}" text-anchor="middle"${fit} ${extra}>${escapeHtml(t)}</text>`;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* The words on a sticker (plate, serial, label, Seven365 line) as SVG text in
|
|
466
|
+
* mm, laid out like the print sheet's HTML. No foreignObject: Safari (every
|
|
467
|
+
* iPad and iPhone browser too) blocks saving a canvas that drew one, so a PNG
|
|
468
|
+
* or JPEG could not be made there.
|
|
469
|
+
*/
|
|
470
|
+
function cardWordsSvg(item: StickerItem, c: CardContext): string {
|
|
471
|
+
if (c.shaped && !c.tag) return "";
|
|
472
|
+
const lines = plateLines(text(item.plateNumber));
|
|
473
|
+
const longest = lines.reduce((a, l) => (l.length > a.length ? l : a), "");
|
|
474
|
+
const serialText = c.serial ? stickerSerial(item) : "";
|
|
475
|
+
const box = c.tag ?? { x: 3, y: c.wordsTop, w: c.cardW - 6, h: c.layout.cardH - 2 - c.wordsTop };
|
|
476
|
+
const plateSize = c.tag
|
|
477
|
+
? plateSizeMm(longest, c.tag.w, 4.6 * c.k)
|
|
478
|
+
: lines.length > 1 ? plateSizeMm(longest, c.cardW - 6, 4.6) : 13 * PT;
|
|
479
|
+
const small = 5.8 * PT;
|
|
480
|
+
type Row = { h: number; draw: (top: number) => string };
|
|
481
|
+
const rows: Row[] = [
|
|
482
|
+
{
|
|
483
|
+
h: 1.1 * plateSize * lines.length,
|
|
484
|
+
draw: (top) =>
|
|
485
|
+
lines
|
|
486
|
+
.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
|
+
.join(""),
|
|
488
|
+
},
|
|
489
|
+
];
|
|
490
|
+
const word = (t: string, bold: boolean): Row => ({
|
|
491
|
+
h: 1.2 * small,
|
|
492
|
+
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"`),
|
|
493
|
+
});
|
|
494
|
+
const label = c.label && !(c.tag && lines.length > 1) ? c.label : "";
|
|
495
|
+
if (c.tag) {
|
|
496
|
+
if (serialText && lines.length === 1) rows.push(word(serialText, true));
|
|
497
|
+
else if (!serialText && label) rows.push(word(label, false));
|
|
498
|
+
} else {
|
|
499
|
+
if (serialText) rows.push(word(serialText, true));
|
|
500
|
+
if (label) rows.push(word(label, false));
|
|
501
|
+
// the Seven365 line: grey rule, the ink "7" mark and the words, centred together
|
|
502
|
+
const textW = 10.061 * 6 * PT;
|
|
503
|
+
const groupW = 3.2 + 1 + textW;
|
|
504
|
+
rows.push({
|
|
505
|
+
h: 4.2,
|
|
506
|
+
draw: (top) => {
|
|
507
|
+
const left = box.x + (box.w - groupW) / 2;
|
|
508
|
+
return (
|
|
509
|
+
`<line x1="${mm(box.x)}" x2="${mm(box.x + box.w)}" y1="${mm(top + 0.1)}" y2="${mm(top + 0.1)}" stroke="#ccc" stroke-width="0.2"/>` +
|
|
510
|
+
`<rect x="${mm(left)}" y="${mm(top + 1)}" width="3.2" height="3.2" rx="0.8" fill="${c.ink}"/>` +
|
|
511
|
+
`<text x="${mm(left + 1.6)}" y="${mm(top + 3.2)}" font-size="${mm(5 * PT)}" font-weight="800" fill="#fff" text-anchor="middle">7</text>` +
|
|
512
|
+
`<text x="${mm(left + 4.2)}" y="${mm(top + 3.35)}" font-size="${mm(6 * PT)}">Powered by Seven365</text>`
|
|
513
|
+
);
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
const used = rows.reduce((n, r) => n + r.h, 0);
|
|
518
|
+
// the card spreads its rows top to bottom; a tag centres them with 0.6 mm between
|
|
519
|
+
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;
|
|
521
|
+
const out = rows.map((r) => {
|
|
522
|
+
const svg = r.draw(top);
|
|
523
|
+
top += r.h + gap;
|
|
524
|
+
return svg;
|
|
525
|
+
});
|
|
526
|
+
return `<g ${FONT} fill="${c.ink}">${out.join("")}</g>`;
|
|
527
|
+
}
|
|
426
528
|
|
|
427
529
|
/**
|
|
428
|
-
* Each sticker on its own, as a standalone SVG image (the
|
|
429
|
-
* as
|
|
430
|
-
*
|
|
431
|
-
*
|
|
530
|
+
* Each sticker on its own, as a standalone SVG image (the face plus its words
|
|
531
|
+
* as SVG text) sized `dpi` dots per inch - for turning into a PNG or JPEG.
|
|
532
|
+
* Clear outside the sticker; no installer strip (the file is named after the
|
|
533
|
+
* plate instead). A 1 mm border keeps the cut line in.
|
|
432
534
|
*/
|
|
433
535
|
export function stickerCardSvgs(
|
|
434
536
|
items: StickerItem[],
|
|
@@ -438,20 +540,18 @@ export function stickerCardSvgs(
|
|
|
438
540
|
const design = opts.design ?? DEFAULT_STICKER_DESIGN;
|
|
439
541
|
const c = cardContext(design, opts.siteName, opts.modules ?? STICKER_QR_MODULES);
|
|
440
542
|
const pad = CUT_LINE_GAP + 1;
|
|
441
|
-
const wMm = c.layout.cellW + pad * 2;
|
|
442
|
-
const hMm = c.layout.cardH + pad * 2;
|
|
443
|
-
const vw = mm(wMm * PX_PER_MM);
|
|
444
|
-
const vh = mm(hMm * PX_PER_MM);
|
|
543
|
+
const wMm = mm(c.layout.cellW + pad * 2);
|
|
544
|
+
const hMm = mm(c.layout.cardH + pad * 2);
|
|
445
545
|
const width = Math.round((wMm / 25.4) * (opts.dpi ?? 600));
|
|
446
546
|
const height = Math.round((hMm / 25.4) * (opts.dpi ?? 600));
|
|
447
|
-
|
|
547
|
+
// the face's own mm size becomes a place in this picture's mm grid
|
|
548
|
+
const place = `x="${pad}" y="${pad}" width="${c.layout.cellW}" height="${c.layout.cardH}"`;
|
|
448
549
|
return items.map((item, i) => ({
|
|
449
550
|
width,
|
|
450
551
|
height,
|
|
451
552
|
svg:
|
|
452
|
-
`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${
|
|
453
|
-
|
|
454
|
-
`<
|
|
455
|
-
`<style>${css}</style>${cardHtml(item, faceSvgs[i] ?? "", c)}</div></foreignObject></svg>`,
|
|
553
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${wMm} ${hMm}">` +
|
|
554
|
+
String(faceSvgs[i] ?? "").replace(/width="[^"]*" height="[^"]*"/, place) +
|
|
555
|
+
`<g transform="translate(${pad} ${pad})">${cardWordsSvg(item, c)}</g></svg>`,
|
|
456
556
|
}));
|
|
457
557
|
}
|