@flowselections/floriday-klanten-module 1.0.62 → 1.0.64

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.
@@ -1 +1 @@
1
- {"version":3,"file":"BulkStickerUploadDialog.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/BulkStickerUploadDialog.tsx"],"names":[],"mappings":"AA2BA,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAiDF,wBAAgB,uBAAuB,CAAC,EACtC,WAAW,EACX,QAAQ,EACR,MAAM,GACP,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,+BA0cA"}
1
+ {"version":3,"file":"BulkStickerUploadDialog.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/BulkStickerUploadDialog.tsx"],"names":[],"mappings":"AA2BA,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAiDF,wBAAgB,uBAAuB,CAAC,EACtC,WAAW,EACX,QAAQ,EACR,MAAM,GACP,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,+BAgdA"}
@@ -203,6 +203,10 @@ export function BulkStickerUploadDialog({ customerKey, products, onDone, }) {
203
203
  res.failed.length ? `${res.failed.length} mislukt` : null,
204
204
  ].filter(Boolean);
205
205
  toast.success(`Stickers opgeslagen: ${parts.join(", ")}`);
206
+ const open = (res.sizes ?? []).filter((s) => !s.size).length;
207
+ if (open) {
208
+ toast.message(`Bij ${open} ${open === 1 ? "sticker" : "stickers"} is het formaat nog niet bekend. Klik op de sticker om het voorstel te bevestigen of de maat in te vullen.`);
209
+ }
206
210
  if (res.failed.length) {
207
211
  toast.error(res.failed.map((f) => `${f.fileName}: ${f.reason}`).join(" · "));
208
212
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CustomerStickerCell.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/CustomerStickerCell.tsx"],"names":[],"mappings":"AASA,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,mCAAmC,CAAC;AAgB3C,wBAAgB,mBAAmB,CAAC,EAClC,WAAW,EACX,YAAY,EACZ,OAAO,GACR,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;CACjC,+BAyKA"}
1
+ {"version":3,"file":"CustomerStickerCell.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/CustomerStickerCell.tsx"],"names":[],"mappings":"AASA,OAAO,EAIL,KAAK,eAAe,EAErB,MAAM,mCAAmC,CAAC;AAiB3C,wBAAgB,mBAAmB,CAAC,EAClC,WAAW,EACX,YAAY,EACZ,OAAO,GACR,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;CACjC,+BA2LA"}
@@ -7,6 +7,7 @@ import { Upload, FileText, Trash2, Eye, RefreshCw } from "lucide-react";
7
7
  import { toast } from "sonner";
8
8
  import { supabase } from "../../integrations/supabase/client.js";
9
9
  import { ALLOWED_STICKER_MIME, confirmStickerUpload, deleteCustomerSticker, } from "../../lib/customer-stickers.functions.js";
10
+ import { StickerSizeLine } from "./StickerSizeLine.js";
10
11
  import { friendlyError } from "../../lib/errors.js";
11
12
  const BUCKET = "customer-stickers";
12
13
  const MAX_SIZE = 10 * 1024 * 1024;
@@ -25,6 +26,7 @@ export function CustomerStickerCell({ customerKey, tradeItemKey, sticker, }) {
25
26
  const inputRef = useRef(null);
26
27
  const [open, setOpen] = useState(false);
27
28
  const [busy, setBusy] = useState(false);
29
+ const [lastDet, setLastDet] = useState(null);
28
30
  const invalidate = () => {
29
31
  qc.invalidateQueries({ queryKey: ["customer-stickers", customerKey] });
30
32
  };
@@ -47,7 +49,7 @@ export function CustomerStickerCell({ customerKey, tradeItemKey, sticker, }) {
47
49
  });
48
50
  if (error)
49
51
  throw error;
50
- await confirm({
52
+ const res = await confirm({
51
53
  data: {
52
54
  customerKey,
53
55
  tradeItemKey,
@@ -57,9 +59,10 @@ export function CustomerStickerCell({ customerKey, tradeItemKey, sticker, }) {
57
59
  fileSize: file.size,
58
60
  },
59
61
  });
60
- invalidate();
62
+ setLastDet({ method: res.method, size: res.size, suggestion: res.suggestion });
63
+ await qc.invalidateQueries({ queryKey: ["customer-stickers", customerKey] });
61
64
  toast.success("Sticker opgeslagen");
62
- setOpen(false);
65
+ setOpen(true);
63
66
  }
64
67
  catch (e) {
65
68
  toast.error(friendlyError(e, "Uploaden mislukt"));
@@ -84,7 +87,10 @@ export function CustomerStickerCell({ customerKey, tradeItemKey, sticker, }) {
84
87
  const f = e.target.files?.[0];
85
88
  if (f)
86
89
  void upload(f);
87
- } }), sticker ? (_jsxs("button", { type: "button", onClick: () => setOpen(true), className: "flex items-center gap-2 text-left hover:opacity-80", title: sticker.file_name, children: [isImage && sticker.url ? (_jsx("img", { src: sticker.url, alt: "", className: "h-9 w-9 rounded border object-contain bg-muted" })) : (_jsx("div", { className: "h-9 w-9 rounded border bg-muted flex items-center justify-center", children: _jsx(FileText, { className: "h-4 w-4 text-muted-foreground" }) })), _jsx("span", { className: "text-xs max-w-[120px] truncate", children: sticker.file_name })] })) : (_jsxs(Button, { type: "button", variant: "outline", size: "sm", disabled: busy, onClick: () => inputRef.current?.click(), children: [_jsx(Upload, { className: "h-4 w-4 mr-1.5" }), "Uploaden"] })), _jsx(Dialog, { open: open, onOpenChange: setOpen, children: _jsxs(DialogContent, { className: "max-w-md", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: "Sticker" }) }), sticker && (_jsxs("div", { className: "space-y-3", children: [isImage && sticker.url ? (_jsx("img", { src: sticker.url, alt: sticker.file_name, className: "max-h-64 w-full rounded border object-contain bg-muted" })) : (_jsxs("div", { className: "rounded border bg-muted p-6 flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [_jsx(FileText, { className: "h-5 w-5" }), sticker.file_name] })), _jsxs("p", { className: "text-xs text-muted-foreground", children: [sticker.file_name, sticker.file_size != null
90
+ } }), sticker ? (_jsxs("button", { type: "button", onClick: () => setOpen(true), className: "flex items-center gap-2 text-left hover:opacity-80", title: sticker.file_name, children: [isImage && sticker.url ? (_jsx("img", { src: sticker.url, alt: "", className: "h-9 w-9 rounded border object-contain bg-muted" })) : (_jsx("div", { className: "h-9 w-9 rounded border bg-muted flex items-center justify-center", children: _jsx(FileText, { className: "h-4 w-4 text-muted-foreground" }) })), _jsxs("span", { className: "flex flex-col", children: [_jsx("span", { className: "text-xs max-w-[120px] truncate", children: sticker.file_name }), _jsx("span", { className: "text-[11px] text-muted-foreground", children: sticker.width_mm != null && sticker.height_mm != null
91
+ ? `${sticker.width_mm.toLocaleString("nl-NL")} × ${sticker.height_mm.toLocaleString("nl-NL")} mm`
92
+ : "Formaat nog onbekend" })] })] })) : (_jsxs(Button, { type: "button", variant: "outline", size: "sm", disabled: busy, onClick: () => inputRef.current?.click(), children: [_jsx(Upload, { className: "h-4 w-4 mr-1.5" }), "Uploaden"] })), _jsx(Dialog, { open: open, onOpenChange: (o) => { setOpen(o); if (!o)
93
+ setLastDet(null); }, children: _jsxs(DialogContent, { className: "max-w-md", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: "Sticker" }) }), sticker && (_jsxs("div", { className: "space-y-3", children: [isImage && sticker.url ? (_jsx("img", { src: sticker.url, alt: sticker.file_name, className: "max-h-64 w-full rounded border object-contain bg-muted" })) : (_jsxs("div", { className: "rounded border bg-muted p-6 flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [_jsx(FileText, { className: "h-5 w-5" }), sticker.file_name] })), _jsxs("p", { className: "text-xs text-muted-foreground", children: [sticker.file_name, sticker.file_size != null
88
94
  ? ` · ${(sticker.file_size / 1024).toFixed(0)} kB`
89
- : ""] })] })), _jsxs(DialogFooter, { className: "gap-2 sm:justify-between", children: [_jsxs(Button, { type: "button", variant: "destructive", disabled: del.isPending || busy, onClick: () => del.mutate(), children: [_jsx(Trash2, { className: "h-4 w-4 mr-1.5" }), "Verwijderen"] }), _jsxs("div", { className: "flex gap-2", children: [sticker?.url && (_jsx(Button, { type: "button", variant: "outline", asChild: true, children: _jsxs("a", { href: sticker.url, target: "_blank", rel: "noreferrer", children: [_jsx(Eye, { className: "h-4 w-4 mr-1.5" }), "Bekijken"] }) })), _jsxs(Button, { type: "button", disabled: busy, onClick: () => inputRef.current?.click(), children: [_jsx(RefreshCw, { className: "h-4 w-4 mr-1.5" }), "Vervangen"] })] })] })] }) })] }));
95
+ : ""] }), _jsx(StickerSizeLine, { customerKey: customerKey, tradeItemKey: tradeItemKey, widthMm: sticker.width_mm, heightMm: sticker.height_mm, initialDetection: lastDet, onSaved: invalidate }, sticker.file_path)] })), _jsxs(DialogFooter, { className: "gap-2 sm:justify-between", children: [_jsxs(Button, { type: "button", variant: "destructive", disabled: del.isPending || busy, onClick: () => del.mutate(), children: [_jsx(Trash2, { className: "h-4 w-4 mr-1.5" }), "Verwijderen"] }), _jsxs("div", { className: "flex gap-2", children: [sticker?.url && (_jsx(Button, { type: "button", variant: "outline", asChild: true, children: _jsxs("a", { href: sticker.url, target: "_blank", rel: "noreferrer", children: [_jsx(Eye, { className: "h-4 w-4 mr-1.5" }), "Bekijken"] }) })), _jsxs(Button, { type: "button", disabled: busy, onClick: () => inputRef.current?.click(), children: [_jsx(RefreshCw, { className: "h-4 w-4 mr-1.5" }), "Vervangen"] })] })] })] }) })] }));
90
96
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KlantenOverzicht.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/KlantenOverzicht.tsx"],"names":[],"mappings":"AAiEA,wBAAgB,gBAAgB,gCA02B/B"}
1
+ {"version":3,"file":"KlantenOverzicht.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/KlantenOverzicht.tsx"],"names":[],"mappings":"AAkEA,wBAAgB,gBAAgB,gCA22B/B"}
@@ -22,6 +22,7 @@ import { PriceGroupBadges } from "./PriceGroupBadges.js";
22
22
  import { KlantBewerkenDialog } from "./KlantBewerkenDialog.js";
23
23
  import { ChannelBadges } from "./ChannelBadges.js";
24
24
  import { FloridayAutoPromoteCard } from "./FloridayAutoPromoteCard.js";
25
+ import { StickerSizePreviewCard } from "./StickerSizePreviewCard.js";
25
26
  import { derivePaymentMethod, paymentToneClasses } from "../../lib/payment-method.js";
26
27
  import { formatCountry, getCountryFlagAndName, countryNameToFlag } from "../../lib/countries.js";
27
28
  import { MultiSearchableSelect } from "./MultiSearchableSelect.js";
@@ -473,7 +474,7 @@ export function KlantenOverzicht() {
473
474
  });
474
475
  const toggleSort = (col) => setSort((s) => (s.col === col ? { col, dir: s.dir === "asc" ? "desc" : "asc" } : { col, dir: "asc" }));
475
476
  const lastUpdated = externalData?.last_fetched_at ?? null;
476
- return (_jsx(TooltipPrimitive.Provider, { delayDuration: 200, children: _jsxs("main", { className: "p-4 sm:p-6 space-y-5 min-w-0 max-w-full overflow-x-hidden", children: [_jsxs("div", { className: "flex items-start justify-between gap-4 flex-wrap", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h1", { className: "text-2xl font-bold tracking-tight", children: "Klanten" }), _jsx("p", { className: "text-sm text-muted-foreground mt-1", children: "Beheer en doorzoek al je klanten." })] }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsxs(Button, { variant: "outline", onClick: () => goTo({ to: "/klanten/import" }), children: [_jsx(Upload, { className: "h-4 w-4 mr-2" }), " Importeren"] }), _jsxs(Button, { onClick: () => goTo({ to: "/klanten/nieuw" }), children: [_jsx(Plus, { className: "h-4 w-4 mr-2" }), " Nieuwe klant"] })] })] }), _jsx(FloridayAutoPromoteCard, {}), loadError && (_jsxs("div", { className: "flex flex-wrap items-center gap-3 rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3", children: [_jsx(AlertCircle, { className: "h-5 w-5 text-destructive shrink-0" }), _jsxs("div", { className: "text-sm", children: [_jsx("div", { className: "font-medium", children: isBackendUnavailable(loadError)
477
+ return (_jsx(TooltipPrimitive.Provider, { delayDuration: 200, children: _jsxs("main", { className: "p-4 sm:p-6 space-y-5 min-w-0 max-w-full overflow-x-hidden", children: [_jsxs("div", { className: "flex items-start justify-between gap-4 flex-wrap", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h1", { className: "text-2xl font-bold tracking-tight", children: "Klanten" }), _jsx("p", { className: "text-sm text-muted-foreground mt-1", children: "Beheer en doorzoek al je klanten." })] }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsxs(Button, { variant: "outline", onClick: () => goTo({ to: "/klanten/import" }), children: [_jsx(Upload, { className: "h-4 w-4 mr-2" }), " Importeren"] }), _jsxs(Button, { onClick: () => goTo({ to: "/klanten/nieuw" }), children: [_jsx(Plus, { className: "h-4 w-4 mr-2" }), " Nieuwe klant"] })] })] }), _jsx(FloridayAutoPromoteCard, {}), _jsx(StickerSizePreviewCard, {}), loadError && (_jsxs("div", { className: "flex flex-wrap items-center gap-3 rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3", children: [_jsx(AlertCircle, { className: "h-5 w-5 text-destructive shrink-0" }), _jsxs("div", { className: "text-sm", children: [_jsx("div", { className: "font-medium", children: isBackendUnavailable(loadError)
477
478
  ? "De database is tijdelijk niet bereikbaar"
478
479
  : "De klanten konden niet geladen worden" }), _jsx("div", { className: "text-muted-foreground", children: isBackendUnavailable(loadError)
479
480
  ? "Je bent niet uitgelogd. Probeer het over een paar minuten opnieuw."
@@ -0,0 +1,14 @@
1
+ import { type StickerUploadSize } from "../../lib/customer-stickers.functions.js";
2
+ /**
3
+ * "Formaat: 48 × 48 mm (wijzigen)". Zonder maat: voorstel via geladen etiket
4
+ * (één klik bevestigen) of pas dan om breedte en hoogte vragen.
5
+ */
6
+ export declare function StickerSizeLine({ customerKey, tradeItemKey, widthMm, heightMm, initialDetection, onSaved, }: {
7
+ customerKey: string;
8
+ tradeItemKey: string;
9
+ widthMm: number | null;
10
+ heightMm: number | null;
11
+ initialDetection?: StickerUploadSize | null;
12
+ onSaved: () => void;
13
+ }): import("react").JSX.Element;
14
+ //# sourceMappingURL=StickerSizeLine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StickerSizeLine.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/StickerSizeLine.tsx"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,mCAAmC,CAAC;AAK3C;;;GAGG;AACH,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,gBAAgB,EAChB,OAAO,GACR,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,gBAAgB,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC5C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,+BA4GA"}
@@ -0,0 +1,74 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ import { useServerFn } from "@tanstack/react-start";
4
+ import { Button, Input } from "@flowselections/core";
5
+ import { toast } from "sonner";
6
+ import { setStickerSize, suggestStickerSize, } from "../../lib/customer-stickers.functions.js";
7
+ import { friendlyError } from "../../lib/errors.js";
8
+ const fmt = (v) => v.toLocaleString("nl-NL", { maximumFractionDigits: 1 });
9
+ /**
10
+ * "Formaat: 48 × 48 mm (wijzigen)". Zonder maat: voorstel via geladen etiket
11
+ * (één klik bevestigen) of pas dan om breedte en hoogte vragen.
12
+ */
13
+ export function StickerSizeLine({ customerKey, tradeItemKey, widthMm, heightMm, initialDetection, onSaved, }) {
14
+ const save = useServerFn(setStickerSize);
15
+ const suggest = useServerFn(suggestStickerSize);
16
+ const known = widthMm != null && heightMm != null;
17
+ const [editing, setEditing] = useState(false);
18
+ const [det, setDet] = useState(initialDetection ?? null);
19
+ const [w, setW] = useState("");
20
+ const [h, setH] = useState("");
21
+ const [busy, setBusy] = useState(false);
22
+ useEffect(() => {
23
+ if (known || det)
24
+ return;
25
+ let alive = true;
26
+ suggest({ data: { customerKey, tradeItemKey } })
27
+ .then((r) => alive && setDet(r))
28
+ .catch(() => alive && setDet({ method: "onbekend", size: null, suggestion: null }));
29
+ return () => {
30
+ alive = false;
31
+ };
32
+ }, [known, det, customerKey, tradeItemKey, suggest]);
33
+ const store = async (wm, hm) => {
34
+ setBusy(true);
35
+ try {
36
+ await save({ data: { customerKey, tradeItemKey, widthMm: wm, heightMm: hm } });
37
+ setEditing(false);
38
+ onSaved();
39
+ toast.success("Formaat opgeslagen");
40
+ }
41
+ catch (e) {
42
+ toast.error(friendlyError(e, "Opslaan mislukt"));
43
+ }
44
+ finally {
45
+ setBusy(false);
46
+ }
47
+ };
48
+ const parse = (v) => Number(v.replace(",", "."));
49
+ const manual = (_jsxs("form", { className: "flex items-center gap-2", onSubmit: (e) => {
50
+ e.preventDefault();
51
+ const wm = parse(w), hm = parse(h);
52
+ if (!(wm > 0 && hm > 0)) {
53
+ toast.error("Vul een breedte en hoogte in millimeters in.");
54
+ return;
55
+ }
56
+ void store(wm, hm);
57
+ }, children: [_jsx(Input, { "aria-label": "Breedte in mm", inputMode: "decimal", placeholder: "Breedte", value: w, onChange: (e) => setW(e.target.value), className: "h-8 w-20" }), _jsx("span", { className: "text-xs text-muted-foreground", children: "\u00D7" }), _jsx(Input, { "aria-label": "Hoogte in mm", inputMode: "decimal", placeholder: "Hoogte", value: h, onChange: (e) => setH(e.target.value), className: "h-8 w-20" }), _jsx("span", { className: "text-xs text-muted-foreground", children: "mm" }), _jsx(Button, { type: "submit", size: "sm", disabled: busy, children: "Opslaan" }), known && (_jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => setEditing(false), children: "Annuleren" }))] }));
58
+ if (known && !editing) {
59
+ return (_jsxs("p", { className: "text-sm", children: ["Formaat: ", fmt(widthMm), " \u00D7 ", fmt(heightMm), " mm", " ", _jsx("button", { type: "button", className: "text-xs text-primary underline-offset-2 hover:underline", onClick: () => {
60
+ setW(fmt(widthMm));
61
+ setH(fmt(heightMm));
62
+ setEditing(true);
63
+ }, children: "wijzigen" })] }));
64
+ }
65
+ if (editing)
66
+ return manual;
67
+ if (!det)
68
+ return _jsx("p", { className: "text-xs text-muted-foreground", children: "Formaat bepalen\u2026" });
69
+ if (det.suggestion) {
70
+ const s = det.suggestion;
71
+ return (_jsxs("div", { className: "space-y-2", children: [_jsxs("p", { className: "text-sm", children: ["Lijkt op ", fmt(s.width_mm), " \u00D7 ", fmt(s.height_mm), " mm", s.printer ? ` – etiket in ${s.printer}` : s.label ? ` – etiket ${s.label}` : ""] }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { type: "button", size: "sm", disabled: busy, onClick: () => void store(s.width_mm, s.height_mm), children: "Klopt" }), _jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => setDet({ ...det, suggestion: null }), children: "Andere maat" })] })] }));
72
+ }
73
+ return (_jsxs("div", { className: "space-y-2", children: [_jsx("p", { className: "text-sm", children: "We konden het formaat niet uit het bestand halen. Hoe groot is deze sticker?" }), manual] }));
74
+ }
@@ -0,0 +1,3 @@
1
+ /** Alleen beheerders, alleen lezen: welke maat bestaande stickers zonder maat zouden krijgen. */
2
+ export declare function StickerSizePreviewCard(): import("react").JSX.Element | null;
3
+ //# sourceMappingURL=StickerSizePreviewCard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StickerSizePreviewCard.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/StickerSizePreviewCard.tsx"],"names":[],"mappings":"AAeA,iGAAiG;AACjG,wBAAgB,sBAAsB,uCAIrC"}
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useQuery } from "@tanstack/react-query";
4
+ import { useServerFn } from "@tanstack/react-start";
5
+ import { useCustomerDefaults } from "./useCustomerDefaults.js";
6
+ import { previewStickerSizes } from "../../lib/customer-stickers.functions.js";
7
+ import { friendlyError } from "../../lib/errors.js";
8
+ const METHOD = {
9
+ pdf: "uit de PDF",
10
+ dpi: "uit de resolutie",
11
+ svg: "uit het bestand",
12
+ verhouding: "voorstel via etiket",
13
+ onbekend: "niet te bepalen",
14
+ };
15
+ /** Alleen beheerders, alleen lezen: welke maat bestaande stickers zonder maat zouden krijgen. */
16
+ export function StickerSizePreviewCard() {
17
+ const { isAdmin } = useCustomerDefaults();
18
+ if (isAdmin !== true)
19
+ return null;
20
+ return _jsx(Inner, {});
21
+ }
22
+ function Inner() {
23
+ const [open, setOpen] = useState(false);
24
+ const run = useServerFn(previewStickerSizes);
25
+ const q = useQuery({ queryKey: ["sticker-size-preview"], queryFn: () => run(), enabled: open });
26
+ return (_jsxs("div", { className: "text-xs text-muted-foreground", children: [_jsx("button", { type: "button", className: "underline", onClick: () => setOpen((v) => !v), children: "Details voor beheer: stickers zonder formaat" }), open && (_jsxs("div", { className: "mt-2 rounded border p-3 space-y-2", children: [_jsx("p", { children: "Overzicht, er wordt nog niets opgeslagen." }), q.isLoading && _jsx("p", { children: "Bestanden bekijken\u2026" }), q.error && _jsx("p", { className: "text-destructive", children: friendlyError(q.error) }), q.data && q.data.length === 0 && _jsx("p", { children: "Alle stickers hebben een formaat." }), q.data && q.data.length > 0 && (_jsxs("table", { className: "w-full", children: [_jsx("thead", { children: _jsxs("tr", { className: "text-left", children: [_jsx("th", { children: "Klant" }), _jsx("th", { children: "Artikel" }), _jsx("th", { children: "Bestand" }), _jsx("th", { children: "Formaat" }), _jsx("th", { children: "Hoe" })] }) }), _jsx("tbody", { children: q.data.map((r) => (_jsxs("tr", { children: [_jsx("td", { children: r.customer_key }), _jsx("td", { children: r.trade_item_key }), _jsx("td", { className: "max-w-[160px] truncate", children: r.file_name }), _jsx("td", { children: r.width_mm != null ? `${r.width_mm} × ${r.height_mm} mm` : "–" }), _jsxs("td", { children: [METHOD[r.method] ?? r.method, r.printer ? ` (${r.printer})` : ""] })] }, `${r.customer_key}|${r.trade_item_key}`))) })] }))] }))] }));
27
+ }
@@ -1,3 +1,4 @@
1
+ import { type StickerSizeResult } from "./sticker-size.js";
1
2
  export declare const ALLOWED_STICKER_MIME: readonly ["application/pdf", "image/png", "image/jpeg", "image/svg+xml"];
2
3
  export type CustomerSticker = {
3
4
  trade_item_key: string;
@@ -19,6 +20,7 @@ export type CustomerStickersResult = {
19
20
  stickers: CustomerSticker[];
20
21
  format: StickerFormat | null;
21
22
  };
23
+ export type StickerUploadSize = Pick<StickerSizeResult, "method" | "size" | "suggestion">;
22
24
  export declare const listCustomerStickers: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
23
25
  supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
24
26
  userId: string;
@@ -38,6 +40,17 @@ export declare const confirmStickerUpload: import("@tanstack/start-client-core")
38
40
  mimeType: string;
39
41
  fileSize?: number | null | undefined;
40
42
  }, Promise<{
43
+ method: import("./sticker-size.js").SizeMethod;
44
+ size: {
45
+ width_mm: number;
46
+ height_mm: number;
47
+ } | null;
48
+ suggestion: {
49
+ width_mm: number;
50
+ height_mm: number;
51
+ label: string | null;
52
+ printer: string | null;
53
+ } | null;
41
54
  ok: true;
42
55
  }>>;
43
56
  export declare const deleteCustomerSticker: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
@@ -137,6 +150,10 @@ export declare const commitStickerBatch: import("@tanstack/start-client-core").O
137
150
  fileName: string;
138
151
  reason: string;
139
152
  }[];
153
+ sizes: ({
154
+ fileName: string;
155
+ tradeItemKey: string;
156
+ } & StickerUploadSize)[];
140
157
  }>>;
141
158
  export declare const discardStickerBatch: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
142
159
  supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
@@ -148,4 +165,42 @@ export declare const discardStickerBatch: import("@tanstack/start-client-core").
148
165
  }, Promise<{
149
166
  removed: any;
150
167
  }>>;
168
+ /** Maat van één sticker vastleggen (bevestigd voorstel of "wijzigen"). */
169
+ export declare const setStickerSize: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
170
+ supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
171
+ userId: string;
172
+ claims: import("@supabase/auth-js").JwtPayload;
173
+ }, undefined, undefined, undefined>], (input: unknown) => {
174
+ customerKey: string;
175
+ tradeItemKey: string;
176
+ widthMm: number;
177
+ heightMm: number;
178
+ }, Promise<{
179
+ ok: true;
180
+ }>>;
181
+ /** Voorstel voor één sticker zonder maat (voor de knop in de stickercel). */
182
+ export declare const suggestStickerSize: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
183
+ supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
184
+ userId: string;
185
+ claims: import("@supabase/auth-js").JwtPayload;
186
+ }, undefined, undefined, undefined>], (input: unknown) => {
187
+ customerKey: string;
188
+ tradeItemKey: string;
189
+ }, Promise<StickerUploadSize>>;
190
+ export type StickerSizePreviewRow = {
191
+ customer_key: string;
192
+ trade_item_key: string;
193
+ file_name: string;
194
+ method: StickerUploadSize["method"];
195
+ width_mm: number | null;
196
+ height_mm: number | null;
197
+ label: string | null;
198
+ printer: string | null;
199
+ };
200
+ /** Alleen lezen: welke maat we bij bestaande stickers zonder maat zouden invullen. Alleen beheerders. */
201
+ export declare const previewStickerSizes: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
202
+ supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
203
+ userId: string;
204
+ claims: import("@supabase/auth-js").JwtPayload;
205
+ }, undefined, undefined, undefined>], undefined, Promise<StickerSizePreviewRow[]>>;
151
206
  //# sourceMappingURL=customer-stickers.functions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"customer-stickers.functions.d.ts","sourceRoot":"","sources":["../../src/lib/customer-stickers.functions.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,oBAAoB,0EAKvB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC9B,QAAQ,EAAE,MAAM,GAAG,IAAI,C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xB,CAAC;AAEF,yGAAyG;AACzG,eAAO,MAAM,mBAAmB;;;;kFA8B5B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { createServerFn } from "@tanstack/react-start";
2
2
  import { z } from "zod";
3
3
  import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
4
+ import { detectStickerSize, parseLoadedLabel, } from "./sticker-size.js";
4
5
  const BUCKET = "customer-stickers";
5
6
  const SIGNED_TTL = 60 * 60; // 1 uur
6
7
  export const ALLOWED_STICKER_MIME = [
@@ -9,6 +10,52 @@ export const ALLOWED_STICKER_MIME = [
9
10
  "image/jpeg",
10
11
  "image/svg+xml",
11
12
  ];
13
+ /** Geladen etiketten uit Layouts (printers + routes). Ontbreekt iets: lege lijst, geen fout. */
14
+ async function loadLabels(sb) {
15
+ const out = [];
16
+ try {
17
+ const { data: printers, error } = await sb
18
+ .from("printers")
19
+ .select("id, naam, weergavenaam, geladen_etiket")
20
+ .not("geladen_etiket", "is", null);
21
+ if (error)
22
+ return out;
23
+ const names = new Map();
24
+ for (const p of printers ?? []) {
25
+ const name = (p.weergavenaam || p.naam || null);
26
+ if (name)
27
+ names.set(p.id, name);
28
+ const l = parseLoadedLabel(p.geladen_etiket, name);
29
+ if (l)
30
+ out.push(l);
31
+ }
32
+ const { data: routes } = await sb
33
+ .from("printer_routes")
34
+ .select("printer_id, geladen_etiket")
35
+ .not("geladen_etiket", "is", null);
36
+ for (const r of routes ?? []) {
37
+ const l = parseLoadedLabel(r.geladen_etiket, names.get(r.printer_id) ?? null);
38
+ if (l)
39
+ out.push(l);
40
+ }
41
+ }
42
+ catch {
43
+ /* Layouts niet geïnstalleerd: stap verhouding overslaan */
44
+ }
45
+ return out;
46
+ }
47
+ async function detectForPath(sb, path, mime, labels) {
48
+ try {
49
+ const { data: blob, error } = await sb.storage.from(BUCKET).download(path);
50
+ if (error || !blob)
51
+ return { method: "onbekend", size: null, suggestion: null };
52
+ const bytes = new Uint8Array(await blob.arrayBuffer());
53
+ return detectStickerSize(bytes, mime, labels);
54
+ }
55
+ catch {
56
+ return { method: "onbekend", size: null, suggestion: null };
57
+ }
58
+ }
12
59
  async function signed(sb, path) {
13
60
  const { data } = await sb.storage.from(BUCKET).createSignedUrl(path, SIGNED_TTL);
14
61
  return data?.signedUrl ?? null;
@@ -77,9 +124,12 @@ export const confirmStickerUpload = createServerFn({ method: "POST" })
77
124
  .eq("customer_key", data.customerKey)
78
125
  .eq("trade_item_key", data.tradeItemKey)
79
126
  .maybeSingle();
127
+ const det = await detectForPath(sb, data.filePath, data.mimeType, await loadLabels(sb));
80
128
  const { error } = await sb.from("customer_product_stickers").upsert({
81
129
  customer_key: data.customerKey,
82
130
  trade_item_key: data.tradeItemKey,
131
+ width_mm: det.size?.width_mm ?? null,
132
+ height_mm: det.size?.height_mm ?? null,
83
133
  file_path: data.filePath,
84
134
  file_name: data.fileName,
85
135
  mime_type: data.mimeType,
@@ -95,7 +145,8 @@ export const confirmStickerUpload = createServerFn({ method: "POST" })
95
145
  if (existing?.file_path && existing.file_path !== data.filePath) {
96
146
  await sb.storage.from(BUCKET).remove([existing.file_path]);
97
147
  }
98
- return { ok: true };
148
+ const result = { method: det.method, size: det.size, suggestion: det.suggestion };
149
+ return { ok: true, ...result };
99
150
  });
100
151
  export const deleteCustomerSticker = createServerFn({ method: "POST" })
101
152
  .middleware([requireSupabaseAuth])
@@ -169,12 +220,13 @@ export const getStickerForPrint = createServerFn({ method: "POST" })
169
220
  const sb = context.supabase;
170
221
  const { data: row } = await sb
171
222
  .from("customer_product_stickers")
172
- .select("file_path, file_name, mime_type")
223
+ .select("file_path, file_name, mime_type, width_mm, height_mm")
173
224
  .eq("customer_key", data.customerKey)
174
225
  .eq("trade_item_key", data.tradeItemKey)
175
226
  .maybeSingle();
176
227
  if (!row?.file_path)
177
228
  return null;
229
+ const own = row.width_mm != null && row.height_mm != null;
178
230
  const { data: fmt } = await sb
179
231
  .from("customer_sticker_settings")
180
232
  .select("width_mm, height_mm")
@@ -184,8 +236,8 @@ export const getStickerForPrint = createServerFn({ method: "POST" })
184
236
  url: await signed(sb, row.file_path),
185
237
  file_name: row.file_name,
186
238
  mime_type: (row.mime_type ?? null),
187
- width_mm: fmt ? Number(fmt.width_mm) : null,
188
- height_mm: fmt ? Number(fmt.height_mm) : null,
239
+ width_mm: own ? Number(row.width_mm) : fmt ? Number(fmt.width_mm) : null,
240
+ height_mm: own ? Number(row.height_mm) : fmt ? Number(fmt.height_mm) : null,
189
241
  };
190
242
  });
191
243
  // ---------------------------------------------------------------------------
@@ -442,6 +494,8 @@ export const commitStickerBatch = createServerFn({ method: "POST" })
442
494
  let replaced = 0;
443
495
  let skipped = 0;
444
496
  const failed = [];
497
+ const sizes = [];
498
+ const labels = await loadLabels(sb);
445
499
  for (const it of data.items) {
446
500
  try {
447
501
  if (!it.inboxPath.startsWith(prefix))
@@ -466,10 +520,14 @@ export const commitStickerBatch = createServerFn({ method: "POST" })
466
520
  const { error: moveErr } = await sb.storage.from(BUCKET).move(it.inboxPath, target);
467
521
  if (moveErr)
468
522
  throw new Error(moveErr.message);
523
+ const det = await detectForPath(sb, target, it.mimeType, labels);
524
+ sizes.push({ fileName: it.fileName, tradeItemKey: it.tradeItemKey, method: det.method, size: det.size, suggestion: det.suggestion });
469
525
  const { error: upErr } = await sb.from("customer_product_stickers").upsert({
470
526
  customer_key: data.customerKey,
471
527
  trade_item_key: it.tradeItemKey,
472
528
  file_path: target,
529
+ width_mm: det.size?.width_mm ?? null,
530
+ height_mm: det.size?.height_mm ?? null,
473
531
  file_name: it.fileName,
474
532
  mime_type: it.mimeType,
475
533
  file_size: it.fileSize ?? null,
@@ -498,7 +556,7 @@ export const commitStickerBatch = createServerFn({ method: "POST" })
498
556
  const paths = (leftovers ?? []).map((o) => `${prefix}${o.name}`);
499
557
  if (paths.length)
500
558
  await sb.storage.from(BUCKET).remove(paths);
501
- return { linked, replaced, skipped, failed };
559
+ return { linked, replaced, skipped, failed, sizes };
502
560
  });
503
561
  export const discardStickerBatch = createServerFn({ method: "POST" })
504
562
  .middleware([requireSupabaseAuth])
@@ -512,3 +570,77 @@ export const discardStickerBatch = createServerFn({ method: "POST" })
512
570
  await sb.storage.from(BUCKET).remove(paths);
513
571
  return { removed: paths.length };
514
572
  });
573
+ /** Maat van één sticker vastleggen (bevestigd voorstel of "wijzigen"). */
574
+ export const setStickerSize = createServerFn({ method: "POST" })
575
+ .middleware([requireSupabaseAuth])
576
+ .inputValidator((input) => z
577
+ .object({
578
+ customerKey: z.string().min(1),
579
+ tradeItemKey: z.string().min(1),
580
+ widthMm: z.number().positive().max(1000),
581
+ heightMm: z.number().positive().max(1000),
582
+ })
583
+ .parse(input))
584
+ .handler(async ({ data, context }) => {
585
+ const sb = context.supabase;
586
+ const r = (v) => Math.round(v * 10) / 10;
587
+ const { error } = await sb
588
+ .from("customer_product_stickers")
589
+ .update({ width_mm: r(data.widthMm), height_mm: r(data.heightMm), updated_at: new Date().toISOString() })
590
+ .eq("customer_key", data.customerKey)
591
+ .eq("trade_item_key", data.tradeItemKey);
592
+ if (error)
593
+ throw new Error(error.message);
594
+ return { ok: true };
595
+ });
596
+ /** Voorstel voor één sticker zonder maat (voor de knop in de stickercel). */
597
+ export const suggestStickerSize = createServerFn({ method: "POST" })
598
+ .middleware([requireSupabaseAuth])
599
+ .inputValidator((input) => z.object({ customerKey: z.string().min(1), tradeItemKey: z.string().min(1) }).parse(input))
600
+ .handler(async ({ data, context }) => {
601
+ const sb = context.supabase;
602
+ const { data: row } = await sb
603
+ .from("customer_product_stickers")
604
+ .select("file_path, mime_type")
605
+ .eq("customer_key", data.customerKey)
606
+ .eq("trade_item_key", data.tradeItemKey)
607
+ .maybeSingle();
608
+ if (!row?.file_path)
609
+ return { method: "onbekend", size: null, suggestion: null };
610
+ const d = await detectForPath(sb, row.file_path, row.mime_type, await loadLabels(sb));
611
+ return { method: d.method, size: d.size, suggestion: d.suggestion };
612
+ });
613
+ /** Alleen lezen: welke maat we bij bestaande stickers zonder maat zouden invullen. Alleen beheerders. */
614
+ export const previewStickerSizes = createServerFn({ method: "POST" })
615
+ .middleware([requireSupabaseAuth])
616
+ .handler(async ({ context }) => {
617
+ const sb = context.supabase;
618
+ const { data: isAdmin } = await sb.rpc("has_role", { _user_id: context.userId, _role: "admin" });
619
+ if (isAdmin !== true)
620
+ throw new Error("Alleen voor beheerders.");
621
+ const { data: rows, error } = await sb
622
+ .from("customer_product_stickers")
623
+ .select("customer_key, trade_item_key, file_name, file_path, mime_type")
624
+ .or("width_mm.is.null,height_mm.is.null")
625
+ .order("customer_key")
626
+ .limit(500);
627
+ if (error)
628
+ throw new Error(error.message);
629
+ const labels = await loadLabels(sb);
630
+ const out = [];
631
+ for (const r of rows ?? []) {
632
+ const d = await detectForPath(sb, r.file_path, r.mime_type, labels);
633
+ const v = d.size ?? d.suggestion;
634
+ out.push({
635
+ customer_key: r.customer_key,
636
+ trade_item_key: r.trade_item_key,
637
+ file_name: r.file_name,
638
+ method: d.method,
639
+ width_mm: v?.width_mm ?? null,
640
+ height_mm: v?.height_mm ?? null,
641
+ label: d.suggestion?.label ?? null,
642
+ printer: d.suggestion?.printer ?? null,
643
+ });
644
+ }
645
+ return out;
646
+ });
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Bepaalt de fysieke maat (mm) van een stickerbestand zonder externe libraries.
3
+ * Volgorde: PDF-paginamaat → DPI (PNG pHYs / JPG JFIF / EXIF) → verhouding met
4
+ * een geladen etiket (±3%, alleen voorstel bij precies één maat) → onbekend.
5
+ */
6
+ export type LoadedLabel = {
7
+ naam: string | null;
8
+ breedte_mm: number;
9
+ hoogte_mm: number;
10
+ printer: string | null;
11
+ };
12
+ export type SizeMethod = "pdf" | "dpi" | "svg" | "verhouding" | "onbekend";
13
+ export type StickerSizeResult = {
14
+ method: SizeMethod;
15
+ /** Zeker gevonden maat (pdf/dpi/svg) – direct op te slaan. */
16
+ size: {
17
+ width_mm: number;
18
+ height_mm: number;
19
+ } | null;
20
+ /** Voorstel via verhouding – pas opslaan na bevestiging. */
21
+ suggestion: {
22
+ width_mm: number;
23
+ height_mm: number;
24
+ label: string | null;
25
+ printer: string | null;
26
+ } | null;
27
+ /** Pixelmaat als bekend (voor verhouding). */
28
+ pixels?: {
29
+ w: number;
30
+ h: number;
31
+ } | null;
32
+ };
33
+ export declare const RATIO_TOLERANCE = 0.03;
34
+ export declare function pdfPageSizeMm(bytes: Uint8Array): {
35
+ width_mm: number;
36
+ height_mm: number;
37
+ } | null;
38
+ type ImgInfo = {
39
+ w: number;
40
+ h: number;
41
+ dpiX: number | null;
42
+ dpiY: number | null;
43
+ };
44
+ export declare function pngInfo(b: Uint8Array): ImgInfo | null;
45
+ export declare function jpegInfo(b: Uint8Array): ImgInfo | null;
46
+ export declare function svgInfo(b: Uint8Array): {
47
+ size: {
48
+ width_mm: number;
49
+ height_mm: number;
50
+ } | null;
51
+ ratio: number | null;
52
+ };
53
+ /** Eén unieke etiketmaat met dezelfde verhouding (staand of liggend), anders null. */
54
+ export declare function matchLabelByRatio(ratio: number, labels: LoadedLabel[], tolerance?: number): StickerSizeResult["suggestion"];
55
+ export declare function detectStickerSize(bytes: Uint8Array, mime: string | null, labels: LoadedLabel[]): StickerSizeResult;
56
+ /** Zet geladen_etiket-jsonb uit Layouts om; onbruikbare waarden worden genegeerd. */
57
+ export declare function parseLoadedLabel(raw: unknown, printer: string | null): LoadedLabel | null;
58
+ export {};
59
+ //# sourceMappingURL=sticker-size.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sticker-size.d.ts","sourceRoot":"","sources":["../../src/lib/sticker-size.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AACjH,MAAM,MAAM,UAAU,GAAG,KAAK,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AAI,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAerH;AAED,sFAAsF;AACtF,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,WAAW,EAAE,EACrB,SAAS,SAAkB,GAC1B,iBAAiB,CAAC,YAAY,CAAC,CAkBjC;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,iBAAiB,CA6BlH;AAED,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAMzF"}
@@ -0,0 +1,233 @@
1
+ /**
2
+ * Bepaalt de fysieke maat (mm) van een stickerbestand zonder externe libraries.
3
+ * Volgorde: PDF-paginamaat → DPI (PNG pHYs / JPG JFIF / EXIF) → verhouding met
4
+ * een geladen etiket (±3%, alleen voorstel bij precies één maat) → onbekend.
5
+ */
6
+ export const RATIO_TOLERANCE = 0.03;
7
+ const r1 = (v) => Math.round(v * 10) / 10;
8
+ function latin1(bytes, max = bytes.length) {
9
+ let s = "";
10
+ const n = Math.min(max, bytes.length);
11
+ for (let i = 0; i < n; i += 8192)
12
+ s += String.fromCharCode(...bytes.subarray(i, Math.min(n, i + 8192)));
13
+ return s;
14
+ }
15
+ export function pdfPageSizeMm(bytes) {
16
+ const text = latin1(bytes);
17
+ // Eerste pagina-object met MediaBox; anders de eerste MediaBox (bv. in /Pages)
18
+ const num = "(-?\\d+(?:\\.\\d+)?)";
19
+ const re = new RegExp(`/MediaBox\\s*\\[\\s*${num}\\s+${num}\\s+${num}\\s+${num}\\s*\\]`);
20
+ const pageIdx = text.search(/\/Type\s*\/Page(?![s\w])/);
21
+ let m = null;
22
+ if (pageIdx >= 0) {
23
+ const start = text.lastIndexOf(" obj", pageIdx);
24
+ const end = text.indexOf("endobj", pageIdx);
25
+ if (start >= 0 && end > start)
26
+ m = re.exec(text.slice(start, end));
27
+ }
28
+ if (!m)
29
+ m = re.exec(text);
30
+ if (!m)
31
+ return null;
32
+ const [x0, y0, x1, y1] = m.slice(1, 5).map(Number);
33
+ const w = Math.abs(x1 - x0), h = Math.abs(y1 - y0);
34
+ if (!(w > 0 && h > 0))
35
+ return null;
36
+ // /Rotate 90/270 op de pagina wisselt breedte en hoogte
37
+ const rot = /\/Rotate\s+(-?\d+)/.exec(text);
38
+ const swap = rot && Math.abs(Number(rot[1])) % 180 === 90;
39
+ const wmm = r1((w * 25.4) / 72), hmm = r1((h * 25.4) / 72);
40
+ return swap ? { width_mm: hmm, height_mm: wmm } : { width_mm: wmm, height_mm: hmm };
41
+ }
42
+ export function pngInfo(b) {
43
+ if (b.length < 24 || b[0] !== 0x89 || b[1] !== 0x50 || b[2] !== 0x4e || b[3] !== 0x47)
44
+ return null;
45
+ const dv = new DataView(b.buffer, b.byteOffset, b.byteLength);
46
+ const w = dv.getUint32(16), h = dv.getUint32(20);
47
+ let dpiX = null, dpiY = null;
48
+ let p = 8;
49
+ while (p + 8 <= b.length) {
50
+ const len = dv.getUint32(p);
51
+ const type = String.fromCharCode(b[p + 4], b[p + 5], b[p + 6], b[p + 7]);
52
+ if (type === "pHYs" && p + 17 <= b.length) {
53
+ const px = dv.getUint32(p + 8), py = dv.getUint32(p + 12), unit = b[p + 16];
54
+ if (unit === 1 && px > 0 && py > 0) {
55
+ dpiX = px * 0.0254;
56
+ dpiY = py * 0.0254;
57
+ }
58
+ break;
59
+ }
60
+ if (type === "IDAT" || type === "IEND")
61
+ break;
62
+ p += 12 + len;
63
+ }
64
+ return { w, h, dpiX, dpiY };
65
+ }
66
+ function exifDpi(b, start, len) {
67
+ const t = start; // TIFF-header
68
+ if (t + 8 > b.length)
69
+ return null;
70
+ const le = b[t] === 0x49;
71
+ const dv = new DataView(b.buffer, b.byteOffset, b.byteLength);
72
+ const u16 = (o) => dv.getUint16(t + o, le);
73
+ const u32 = (o) => dv.getUint32(t + o, le);
74
+ const ifd = u32(4);
75
+ if (t + ifd + 2 > start + len)
76
+ return null;
77
+ const n = u16(ifd);
78
+ let x = null, y = null, unit = 2;
79
+ for (let i = 0; i < n; i++) {
80
+ const e = ifd + 2 + i * 12;
81
+ if (t + e + 12 > b.length)
82
+ break;
83
+ const tag = u16(e);
84
+ if (tag === 0x011a || tag === 0x011b) {
85
+ const off = u32(e + 8);
86
+ const den = u32(off + 4);
87
+ const v = den ? u32(off) / den : 0;
88
+ if (tag === 0x011a)
89
+ x = v;
90
+ else
91
+ y = v;
92
+ }
93
+ else if (tag === 0x0128)
94
+ unit = u16(e + 8);
95
+ }
96
+ if (!x || !y || unit === 1)
97
+ return null;
98
+ return unit === 3 ? { x: x * 2.54, y: y * 2.54 } : { x, y };
99
+ }
100
+ export function jpegInfo(b) {
101
+ if (b.length < 4 || b[0] !== 0xff || b[1] !== 0xd8)
102
+ return null;
103
+ let p = 2, w = 0, h = 0;
104
+ let dpiX = null, dpiY = null;
105
+ let exif = null;
106
+ while (p + 4 <= b.length) {
107
+ if (b[p] !== 0xff) {
108
+ p++;
109
+ continue;
110
+ }
111
+ const marker = b[p + 1];
112
+ if (marker === 0xd8 || (marker >= 0xd0 && marker <= 0xd7) || marker === 0x01) {
113
+ p += 2;
114
+ continue;
115
+ }
116
+ const len = (b[p + 2] << 8) | b[p + 3];
117
+ const seg = p + 4;
118
+ if (marker === 0xe0 && latin1(b.subarray(seg, seg + 5)) === "JFIF\0") {
119
+ const unit = b[seg + 7];
120
+ const xd = (b[seg + 8] << 8) | b[seg + 9], yd = (b[seg + 10] << 8) | b[seg + 11];
121
+ if ((unit === 1 || unit === 2) && xd > 0 && yd > 0) {
122
+ dpiX = unit === 2 ? xd * 2.54 : xd;
123
+ dpiY = unit === 2 ? yd * 2.54 : yd;
124
+ }
125
+ }
126
+ else if (marker === 0xe1 && latin1(b.subarray(seg, seg + 6)) === "Exif\0\0") {
127
+ try {
128
+ exif = exifDpi(b, seg + 6, len - 8);
129
+ }
130
+ catch {
131
+ exif = null;
132
+ }
133
+ }
134
+ else if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
135
+ h = (b[seg + 1] << 8) | b[seg + 2];
136
+ w = (b[seg + 3] << 8) | b[seg + 4];
137
+ break;
138
+ }
139
+ p += 2 + len;
140
+ }
141
+ if (!w || !h)
142
+ return null;
143
+ if (dpiX == null && exif) {
144
+ dpiX = exif.x;
145
+ dpiY = exif.y;
146
+ }
147
+ return { w, h, dpiX, dpiY };
148
+ }
149
+ const UNIT_MM = { mm: 1, cm: 10, in: 25.4, pt: 25.4 / 72 };
150
+ export function svgInfo(b) {
151
+ const head = latin1(b, 4096);
152
+ const tag = /<svg\b[^>]*>/i.exec(head)?.[0] ?? "";
153
+ const attr = (n) => new RegExp(`\\b${n}\\s*=\\s*["']\\s*([\\d.]+)\\s*([a-z%]*)`, "i").exec(tag);
154
+ const wa = attr("width"), ha = attr("height");
155
+ if (wa && ha && UNIT_MM[wa[2].toLowerCase()] && UNIT_MM[ha[2].toLowerCase()]) {
156
+ return {
157
+ size: { width_mm: r1(Number(wa[1]) * UNIT_MM[wa[2].toLowerCase()]), height_mm: r1(Number(ha[1]) * UNIT_MM[ha[2].toLowerCase()]) },
158
+ ratio: null,
159
+ };
160
+ }
161
+ const vb = /viewBox\s*=\s*["']\s*[-\d.]+[\s,]+[-\d.]+[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(tag);
162
+ if (vb && Number(vb[2]) > 0)
163
+ return { size: null, ratio: Number(vb[1]) / Number(vb[2]) };
164
+ if (wa && ha && Number(ha[1]) > 0)
165
+ return { size: null, ratio: Number(wa[1]) / Number(ha[1]) };
166
+ return { size: null, ratio: null };
167
+ }
168
+ /** Eén unieke etiketmaat met dezelfde verhouding (staand of liggend), anders null. */
169
+ export function matchLabelByRatio(ratio, labels, tolerance = RATIO_TOLERANCE) {
170
+ if (!(ratio > 0))
171
+ return null;
172
+ const hits = new Map();
173
+ for (const l of labels) {
174
+ if (!(l.breedte_mm > 0 && l.hoogte_mm > 0))
175
+ continue;
176
+ const opts = [
177
+ { w: l.breedte_mm, h: l.hoogte_mm },
178
+ { w: l.hoogte_mm, h: l.breedte_mm },
179
+ ];
180
+ for (const o of opts) {
181
+ if (Math.abs(o.w / o.h - ratio) / ratio <= tolerance) {
182
+ const key = `${r1(o.w)}x${r1(o.h)}`;
183
+ if (!hits.has(key))
184
+ hits.set(key, { width_mm: r1(o.w), height_mm: r1(o.h), label: l.naam?.trim() || null, printer: l.printer });
185
+ break;
186
+ }
187
+ }
188
+ }
189
+ return hits.size === 1 ? [...hits.values()][0] : null;
190
+ }
191
+ export function detectStickerSize(bytes, mime, labels) {
192
+ const none = { method: "onbekend", size: null, suggestion: null, pixels: null };
193
+ try {
194
+ if (mime === "application/pdf") {
195
+ const s = pdfPageSizeMm(bytes);
196
+ return s ? { method: "pdf", size: s, suggestion: null } : none;
197
+ }
198
+ if (mime === "image/svg+xml") {
199
+ const s = svgInfo(bytes);
200
+ if (s.size)
201
+ return { method: "svg", size: s.size, suggestion: null };
202
+ const sug = s.ratio ? matchLabelByRatio(s.ratio, labels) : null;
203
+ return sug ? { method: "verhouding", size: null, suggestion: sug } : none;
204
+ }
205
+ const info = mime === "image/png" ? pngInfo(bytes) : mime === "image/jpeg" ? jpegInfo(bytes) : null;
206
+ if (!info)
207
+ return none;
208
+ const pixels = { w: info.w, h: info.h };
209
+ if (info.dpiX && info.dpiY) {
210
+ return {
211
+ method: "dpi",
212
+ size: { width_mm: r1((info.w / info.dpiX) * 25.4), height_mm: r1((info.h / info.dpiY) * 25.4) },
213
+ suggestion: null,
214
+ pixels,
215
+ };
216
+ }
217
+ const sug = matchLabelByRatio(info.w / info.h, labels);
218
+ return sug ? { method: "verhouding", size: null, suggestion: sug, pixels } : { ...none, pixels };
219
+ }
220
+ catch {
221
+ return none;
222
+ }
223
+ }
224
+ /** Zet geladen_etiket-jsonb uit Layouts om; onbruikbare waarden worden genegeerd. */
225
+ export function parseLoadedLabel(raw, printer) {
226
+ if (!raw || typeof raw !== "object")
227
+ return null;
228
+ const o = raw;
229
+ const b = Number(o.breedte_mm), h = Number(o.hoogte_mm);
230
+ if (!(b > 0 && h > 0))
231
+ return null;
232
+ return { naam: typeof o.naam === "string" ? o.naam : null, breedte_mm: b, hoogte_mm: h, printer };
233
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowselections/floriday-klanten-module",
3
- "version": "1.0.62",
3
+ "version": "1.0.64",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "type": "module",