@krizaka/ui 3.76.0 → 3.77.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.
Files changed (52) hide show
  1. package/dist/blocks.css +14 -0
  2. package/dist/chunk-NM2DEHFZ.js +25 -0
  3. package/dist/chunk-NM2DEHFZ.js.map +1 -0
  4. package/dist/document-viewer.d.ts +23 -6
  5. package/dist/document-viewer.js +21 -5
  6. package/dist/document-viewer.js.map +1 -1
  7. package/dist/map/cards.d.ts +145 -0
  8. package/dist/map/cards.js +74 -0
  9. package/dist/map/cards.js.map +1 -0
  10. package/dist/map/pin.d.ts +57 -0
  11. package/dist/map/pin.js +53 -0
  12. package/dist/map/pin.js.map +1 -0
  13. package/dist/map/sheet.d.ts +80 -0
  14. package/dist/map/sheet.js +61 -0
  15. package/dist/map/sheet.js.map +1 -0
  16. package/dist/map.d.ts +41 -14
  17. package/dist/map.js +85 -112
  18. package/dist/map.js.map +1 -1
  19. package/dist/native/map.d.ts +29 -10
  20. package/dist/native/map.js +81 -107
  21. package/dist/native/map.js.map +1 -1
  22. package/dist/shop/services.js +1 -1
  23. package/dist/shop/services.js.map +1 -1
  24. package/dist/shop-composer.js +1 -1
  25. package/dist/shop-composer.js.map +1 -1
  26. package/dist/shop-gallery.js +2 -2
  27. package/dist/shop-gallery.js.map +1 -1
  28. package/dist/wall.d.ts +10 -5
  29. package/dist/wall.js +10 -4
  30. package/dist/wall.js.map +1 -1
  31. package/package.json +53 -8
  32. package/registry/app-frame.json +1 -1
  33. package/registry/document-viewer.json +9 -8
  34. package/registry/examples/document-viewer/highlights.js +2 -1
  35. package/registry/examples/document-viewer/highlights.tsx +3 -0
  36. package/registry/examples/map/pins.d.ts +4 -0
  37. package/registry/examples/map/pins.js +20 -0
  38. package/registry/examples/map/pins.tsx +27 -0
  39. package/registry/examples/map/place-sheet.d.ts +4 -0
  40. package/registry/examples/map/place-sheet.js +34 -0
  41. package/registry/examples/map/place-sheet.tsx +35 -0
  42. package/registry/examples/wall/tidy.d.ts +4 -0
  43. package/registry/examples/wall/tidy.js +27 -0
  44. package/registry/examples/wall/tidy.tsx +19 -0
  45. package/registry/index.json +9 -9
  46. package/registry/map.json +81 -13
  47. package/registry/nav-bar.json +1 -1
  48. package/registry/rail-nav.json +1 -1
  49. package/registry/shop-gallery.json +1 -1
  50. package/registry/shop.json +2 -2
  51. package/registry/site-footer.json +1 -1
  52. package/registry/wall.json +24 -2
package/dist/blocks.css CHANGED
@@ -131,7 +131,21 @@
131
131
  transform: translate(calc(-1 * var(--kz-wall-x)), calc(-1 * var(--kz-wall-y))) rotate(var(--kz-wall-rotation));
132
132
  }
133
133
  }
134
+ /* Tidy layout: the Cahier pinboard — dense grid, the tilt (from the id) on the item, no absolute placement */
135
+ .kz-wall[data-layout="tidy"] { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-flow: dense; gap: 1.5rem; aspect-ratio: auto; height: auto; padding: 1.5rem; align-items: start; }
136
+ .kz-wall[data-layout="tidy"] .kz-wall-item { position: relative; left: auto; top: auto; width: 100%; max-height: none; margin: 0; transform: rotate(var(--kz-wall-rotation, 0deg)); }
137
+ .kz-wall[data-layout="tidy"] .kz-wall-item[data-span="2"] { grid-column: span 2; }
138
+ .kz-wall[data-layout="tidy"] .kz-polaroid figcaption { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
139
+ @media (max-width: 22rem) {
140
+ .kz-wall[data-layout="tidy"] { grid-template-columns: minmax(0, 1fr); }
141
+ .kz-wall[data-layout="tidy"] .kz-wall-item[data-span="2"] { grid-column: auto; }
142
+ }
143
+ @media (min-width: 48rem) {
144
+ .kz-wall[data-layout="tidy"] { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); aspect-ratio: auto; }
145
+ .kz-wall[data-layout="tidy"] .kz-wall-item { position: relative; left: auto; top: auto; width: 100%; margin: 0; transform: rotate(var(--kz-wall-rotation, 0deg)); }
146
+ }
134
147
  @media (prefers-reduced-motion: reduce) {
148
+ .kz-wall[data-layout="tidy"] .kz-wall-item { transform: none; }
135
149
  .kz-polaroid .kz-polaroid-photo { animation: none; filter: none; opacity: 1; }
136
150
  .kz-shop-sign[data-variant="neon"][data-animated][data-lit] :is(.kz-shop-sign-logo, .kz-shop-sign-name) { animation: none; }
137
151
  }
@@ -0,0 +1,25 @@
1
+ "use client";
2
+
3
+ // src/tv.ts
4
+ import { createTV } from "tailwind-variants";
5
+
6
+ // src/cn.ts
7
+ import { clsx } from "clsx";
8
+ import { cnMerge } from "tailwind-variants";
9
+ var twMergeConfig = {
10
+ extend: {
11
+ classGroups: {
12
+ "bg-image": ["bg-sheen", "bg-fill-shade", "bg-halo"],
13
+ shadow: ["shadow-raised", "shadow-floating", "shadow-overlay", "shadow-glow", "shadow-glow-lg"],
14
+ "inset-shadow": ["inset-shadow-edge", "inset-shadow-edge-fill", "inset-shadow-well"]
15
+ }
16
+ }
17
+ };
18
+
19
+ // src/tv.ts
20
+ var tv = createTV({ twMergeConfig });
21
+
22
+ export {
23
+ tv
24
+ };
25
+ //# sourceMappingURL=chunk-NM2DEHFZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tv.ts","../src/cn.ts"],"sourcesContent":["import { createTV } from \"tailwind-variants\";\n\nimport { twMergeConfig } from \"./cn\";\n\n/** `tv` with the preset's utilities known to the merge engine (`twMergeConfig`): what a primitive wearing the material is styled with. */\nexport const tv = createTV({ twMergeConfig });\n","import { type ClassValue, clsx } from \"clsx\";\nimport { cnMerge, type TWMergeConfig } from \"tailwind-variants\";\n\nexport type { ClassValue };\n\n/**\n * The preset's own utilities, told to the merge engine: the material (BRAND.md §6: `bg-sheen`, `bg-fill-shade`,\n * `bg-halo` are background images; `shadow-raised` · `-floating` · `-overlay` · `-glow` are shadows; `inset-shadow-edge`\n * · `-edge-fill` · `-well` are inset shadows). Unknown, tailwind-merge would take `bg-sheen` for a colour and drop the\n * `bg-surface-2` it lies on.\n */\nexport const twMergeConfig: TWMergeConfig = {\n extend: {\n classGroups: {\n \"bg-image\": [\"bg-sheen\", \"bg-fill-shade\", \"bg-halo\"],\n shadow: [\"shadow-raised\", \"shadow-floating\", \"shadow-overlay\", \"shadow-glow\", \"shadow-glow-lg\"],\n \"inset-shadow\": [\"inset-shadow-edge\", \"inset-shadow-edge-fill\", \"inset-shadow-well\"],\n },\n },\n};\n\nconst mergeConfig = { twMergeConfig };\n\n/**\n * Merges Tailwind classes: the last one wins — a product's `className` overrides the primitive's. The merge engine is\n * tailwind-merge as tailwind-variants ships it (the one `tv` uses), so the platform carries a single copy of it.\n * tailwind-variants bundles that engine since 3.3 (it never imports the `tailwind-merge` package, an optional peer):\n * hence `tailwind-variants ^3.3.1` and no `tailwind-merge` dependency — `scripts/consumer.mjs` checks it on a clean\n * install of the packed package.\n */\nexport function cn(...inputs: ClassValue[]): string {\n return cnMerge(clsx(inputs))(mergeConfig) ?? \"\";\n}\n\n"],"mappings":";;;AAAA,SAAS,gBAAgB;;;ACAzB,SAA0B,YAAY;AACtC,SAAS,eAAmC;AAUrC,IAAM,gBAA+B;AAAA,EAC1C,QAAQ;AAAA,IACN,aAAa;AAAA,MACX,YAAY,CAAC,YAAY,iBAAiB,SAAS;AAAA,MACnD,QAAQ,CAAC,iBAAiB,mBAAmB,kBAAkB,eAAe,gBAAgB;AAAA,MAC9F,gBAAgB,CAAC,qBAAqB,0BAA0B,mBAAmB;AAAA,IACrF;AAAA,EACF;AACF;;;ADdO,IAAM,KAAK,SAAS,EAAE,cAAc,CAAC;","names":[]}
@@ -27,8 +27,12 @@ type Located = {
27
27
  page: number;
28
28
  /** One box per line of the passage (merged along a line); empty when only the page is known. */
29
29
  boxes: Box[];
30
- /** `exact`: the whole quote was found; `start`: only its opening words were (a quote cut by a different layout). */
31
- match: "exact" | "start" | "page";
30
+ /** `region`: the box the app gave, as it is; `exact`: the whole quote was found; `start`: only its opening words were (a quote cut by a different layout). */
31
+ match: "exact" | "start" | "page" | "region";
32
+ };
33
+ /** A region of a page the app already knows (a stamp, a font mismatch, a metadata area): its page and a box in fractions. */
34
+ type Region = Box & {
35
+ page: number;
32
36
  };
33
37
  /** The comparable form of a text: no whitespace, no soft hyphen, straight quotes, case and accents folded. */
34
38
  declare function fold(text: string): string;
@@ -39,6 +43,17 @@ declare function fold(text: string): string;
39
43
  * a rotated page has no boxes, only its page.
40
44
  */
41
45
  declare function locateQuote(pages: readonly PageText[], quote: string, hintPage?: number): Located | null;
46
+ /**
47
+ * A region of a page, as it is: one box, no text needed. Never drawn when it is not on the pages — an unknown page, a box
48
+ * outside 0–1 or empty, a value that is not a number — so a wrong box is `null`, not a guess.
49
+ */
50
+ declare function locateRegion(pages: readonly PageText[], region: Region): Located | null;
51
+ /** What to light for a highlight: its region when it has a valid one, otherwise its quote (if any). */
52
+ declare function resolveHighlight(pages: readonly PageText[], h: {
53
+ quote?: string;
54
+ page?: number;
55
+ region?: Region;
56
+ }): Located | null;
42
57
 
43
58
  declare const documentViewer: tailwind_variants.TVReturnType<{
44
59
  [key: string]: {
@@ -121,10 +136,12 @@ type DocumentViewerLabels = {
121
136
  notFound: string;
122
137
  };
123
138
  declare const documentViewerLabels: DocumentViewerLabels;
124
- /** A passage to light: its quote (as the text layer reads it), the page if the app knows it, a name for screen readers. */
139
+ /** A passage to light: its quote (as the text layer reads it) and/or a `region` of a page the app already knows (a stamp, a
140
+ mismatch — fractions of the page, origin top-left); the page if known, a name for screen readers. A valid region wins. */
125
141
  type DocumentHighlight = {
126
142
  id: string;
127
- quote: string;
143
+ quote?: string;
144
+ region?: Region;
128
145
  page?: number;
129
146
  label?: string;
130
147
  };
@@ -197,5 +214,5 @@ type DocumentViewerProps = Omit<React.ComponentProps<"div">, "children" | "onCha
197
214
  /** A PDF with its passages lit — see the file's header. Client. */
198
215
  declare function DocumentViewer({ src, loadPdfjs, workerSrc, highlights, activeId, onActiveChange, onLocate, onLoad, labels, className, ...props }: DocumentViewerProps): React.JSX.Element;
199
216
 
200
- export { DocumentViewer, documentViewer, documentViewerLabels, fold, locateQuote };
201
- export type { Box, DocumentHighlight, DocumentViewerLabels, DocumentViewerProps, Located, PageText, PdfDocument, PdfPage, PdfjsModule, TextItem };
217
+ export { DocumentViewer, documentViewer, documentViewerLabels, fold, locateQuote, locateRegion, resolveHighlight };
218
+ export type { Box, DocumentHighlight, DocumentViewerLabels, DocumentViewerProps, Located, PageText, PdfDocument, PdfPage, PdfjsModule, Region, TextItem };
@@ -97,6 +97,19 @@ function locateQuote(pages, quote, hintPage) {
97
97
  }
98
98
  return hintPage && pages.some((p) => p.page === hintPage) ? { page: hintPage, boxes: [], match: "page" } : null;
99
99
  }
100
+ var inUnit = (n) => Number.isFinite(n) && n >= 0 && n <= 1;
101
+ function locateRegion(pages, region) {
102
+ const { page, x, y, width, height } = region;
103
+ const valid = pages.some((p) => p.page === page) && inUnit(x) && inUnit(y) && width > 0 && height > 0 && inUnit(x + width) && inUnit(y + height);
104
+ return valid ? { page, boxes: [{ x, y, width, height }], match: "region" } : null;
105
+ }
106
+ function resolveHighlight(pages, h) {
107
+ const byRegion = h.region ? locateRegion(pages, h.region) : null;
108
+ if (byRegion) return byRegion;
109
+ if (h.quote) return locateQuote(pages, h.quote, h.page ?? h.region?.page);
110
+ const hinted = h.page !== void 0 && pages.some((p) => p.page === h.page);
111
+ return hinted ? { page: h.page, boxes: [], match: "page" } : null;
112
+ }
100
113
 
101
114
  // src/document-viewer/document-viewer.tsx
102
115
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -120,6 +133,7 @@ var documentViewerLabels = {
120
133
  onPage: "Passage on page {page}:",
121
134
  notFound: "This passage is not in the document's text layer:"
122
135
  };
136
+ var regionKey = (r) => r ? [r.page, r.x, r.y, r.width, r.height].join(",") : "";
123
137
  var fill = (template, vars) => template.replace(/\{(\w+)\}/g, (m, k) => k in vars ? String(vars[k]) : m);
124
138
  var isItem = (x) => typeof x === "object" && x !== null && typeof x.str === "string" && Array.isArray(x.transform);
125
139
  function PageCanvas({ page, doc, caption, onReady, className }) {
@@ -201,10 +215,10 @@ function DocumentViewer({ src, loadPdfjs, workerSrc, highlights = [], activeId =
201
215
  void opened?.destroy?.();
202
216
  };
203
217
  }, [bytes, loadPdfjs, workerSrc, callbacks]);
204
- const key = highlights.map((h) => `${h.id}\0${h.page ?? ""}\0${h.quote}`).join("");
218
+ const key = highlights.map((h) => `${h.id}\0${h.page ?? ""}\0${h.quote ?? ""}\0${regionKey(h.region)}`).join("");
205
219
  const found = React.useMemo(() => {
206
220
  const out = {};
207
- if (phase.state === "ready") for (const h of highlights) out[h.id] = locateQuote(phase.texts, h.quote, h.page);
221
+ if (phase.state === "ready") for (const h of highlights) out[h.id] = resolveHighlight(phase.texts, h);
208
222
  return out;
209
223
  }, [phase, key]);
210
224
  React.useEffect(() => {
@@ -219,10 +233,10 @@ function DocumentViewer({ src, loadPdfjs, workerSrc, highlights = [], activeId =
219
233
  target?.scrollIntoView?.({ block: where.boxes.length > 0 ? "center" : "start", behavior: reduce ? "auto" : "smooth" });
220
234
  }, [activeId, where, phase.state]);
221
235
  return /* @__PURE__ */ jsxs("div", { className: s.root({ className }), ...props, children: [
222
- active && where !== void 0 && where?.match !== "exact" && where?.match !== "start" ? /* @__PURE__ */ jsxs("p", { className: s.bar(), "data-testid": "document-viewer-bar", children: [
236
+ active && where !== void 0 && where?.match !== "exact" && where?.match !== "start" && where?.match !== "region" ? /* @__PURE__ */ jsxs("p", { className: s.bar(), "data-testid": "document-viewer-bar", children: [
223
237
  where?.match === "page" ? fill(words.onPage, { page: where.page }) : words.notFound,
224
238
  " ",
225
- /* @__PURE__ */ jsx("q", { children: active.quote })
239
+ active.quote ? /* @__PURE__ */ jsx("q", { children: active.quote }) : null
226
240
  ] }) : null,
227
241
  /* @__PURE__ */ jsxs("div", { ref: containerRef, className: s.pages(), role: "region", "aria-label": words.region, tabIndex: 0, children: [
228
242
  phase.state === "loading" ? /* @__PURE__ */ jsx("p", { className: s.status(), children: words.loading }) : null,
@@ -259,6 +273,8 @@ export {
259
273
  documentViewer,
260
274
  documentViewerLabels,
261
275
  fold,
262
- locateQuote
276
+ locateQuote,
277
+ locateRegion,
278
+ resolveHighlight
263
279
  };
264
280
  //# sourceMappingURL=document-viewer.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/document-viewer/document-viewer.tsx","../src/document-viewer/locate.ts"],"sourcesContent":["// Client. A PDF drawn page by page (pdf.js), and passages of it lit where they sit. The app hands over the engine\n// (`loadPdfjs={() => import(\"pdfjs-dist\")}` — an optional peer, loaded only on a page that shows a document) and the\n// worker's address; it hands over the passages as quotes (`highlights`), and the viewer finds their place from the\n// PDF's own text positions (`locateQuote`): one box per line, in fractions of the page, so they follow any zoom.\n// `activeId` (controlled) scrolls to a passage and strengthens it; a click on a box calls `onActiveChange`. A passage\n// the text layer cannot place is never drawn at a guessed place: the viewer goes to its page when it is known and shows\n// the quote in a bar — and tells the app (`onLocate`) so its list can say \"page 3\" or \"not found\".\nimport * as React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { useLatest, usePrefersReducedMotion } from \"../media\";\nimport { type Located, locateQuote, type PageText } from \"./locate\";\n\nexport const documentViewer = tv({\n slots: {\n root: \"relative flex min-w-0 flex-col gap-3\",\n pages: \"flex max-h-(--kz-document-viewer-height,70vh) flex-col gap-3 overflow-auto rounded-lg border border-border-default bg-surface-2 p-3 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent\",\n page: \"relative mx-auto w-full max-w-(--kz-document-viewer-page,56rem) shrink-0 overflow-hidden rounded-sm bg-white shadow-sm\",\n canvas: \"block h-auto w-full\",\n caption: \"absolute top-1 left-1 rounded-sm bg-surface-1/90 px-1.5 py-0.5 text-xs text-fg-secondary\",\n box: \"absolute cursor-pointer rounded-xs border border-warning/70 bg-warning/25 mix-blend-multiply transition-colors data-[active=true]:border-2 data-[active=true]:border-danger data-[active=true]:bg-danger/25 motion-reduce:transition-none\",\n bar: \"rounded-lg border border-border-default bg-surface-1 px-3 py-2 text-sm text-fg-secondary\",\n status: \"p-6 text-center text-sm text-fg-secondary\",\n },\n});\n\n/** The words of the viewer, passed translated. `{page}` and `{total}` are replaced. */\nexport type DocumentViewerLabels = {\n /** The accessible name of the pages' region. */\n region: string;\n loading: string;\n failed: string;\n /** A page's caption and accessible name: \"Page {page} of {total}\". */\n page: string;\n /** The bar above the pages when the active passage could only be placed on a page: \"Passage on page {page}:\". */\n onPage: string;\n /** The bar when the active passage is not in the text layer. */\n notFound: string;\n};\n\nexport const documentViewerLabels: DocumentViewerLabels = {\n region: \"Document pages\",\n loading: \"Loading the document…\",\n failed: \"The document could not be displayed.\",\n page: \"Page {page} of {total}\",\n onPage: \"Passage on page {page}:\",\n notFound: \"This passage is not in the document's text layer:\",\n};\n\n/** A passage to light: its quote (as the text layer reads it), the page if the app knows it, a name for screen readers. */\nexport type DocumentHighlight = { id: string; quote: string; page?: number; label?: string };\n\n/** What the viewer found for a passage. */\nexport type { Located };\n\n/** The members of pdf.js the viewer uses (`pdfjs-dist` ≥ 5), typed here so the package does not depend on it. */\nexport type PdfjsModule = {\n GlobalWorkerOptions: { workerSrc: string };\n getDocument(source: { url?: string; data?: Uint8Array }): { promise: Promise<PdfDocument>; destroy?: () => Promise<void> | void };\n};\nexport type PdfDocument = { numPages: number; getPage(n: number): Promise<PdfPage>; destroy?: () => Promise<void> | void };\nexport type PdfPage = {\n rotate: number;\n view: number[];\n getViewport(options: { scale: number }): { width: number; height: number };\n getTextContent(): Promise<{ items: readonly unknown[] }>;\n render(options: { canvas: HTMLCanvasElement; canvasContext: CanvasRenderingContext2D; viewport: { width: number; height: number } }): { promise: Promise<void>; cancel?: () => void };\n cleanup?: () => void;\n};\n\nexport type DocumentViewerProps = Omit<React.ComponentProps<\"div\">, \"children\" | \"onChange\"> & {\n /** The PDF: an address (same origin or CORS) or its bytes. */\n src: string | Uint8Array;\n /** Loads pdf.js: `() => import(\"pdfjs-dist\")`. An optional peer, never in a bundle without a document. */\n loadPdfjs: () => Promise<PdfjsModule>;\n /** The address of pdf.js's worker (`new URL(\"pdfjs-dist/build/pdf.worker.min.mjs\", import.meta.url).toString()`). */\n workerSrc: string;\n /** The passages to light. */\n highlights?: readonly DocumentHighlight[];\n /** The passage in focus: the viewer scrolls to it. */\n activeId?: string | null;\n /** A box was clicked (the id) or the focus was released (`null`). */\n onActiveChange?: (id: string | null) => void;\n /** Where each passage was found (`null`: nowhere) — once the text layer is read, and again if `highlights` change. */\n onLocate?: (found: Record<string, Located | null>) => void;\n /** Called when the document is open, with its page count. */\n onLoad?: (info: { pages: number }) => void;\n /** The words of the viewer, translated (English by default). */\n labels?: Partial<DocumentViewerLabels>;\n};\n\nconst fill = (template: string, vars: Record<string, string | number>) => template.replace(/\\{(\\w+)\\}/g, (m, k: string) => (k in vars ? String(vars[k]) : m));\n\ntype Loaded = { doc: PdfDocument; texts: PageText[]; sizes: { width: number; height: number }[] };\ntype Phase = { state: \"loading\" } | { state: \"error\"; key: string } | ({ state: \"ready\"; key: string } & Loaded);\n\nconst isItem = (x: unknown): x is PageText[\"items\"][number] => typeof x === \"object\" && x !== null && typeof (x as { str?: unknown }).str === \"string\" && Array.isArray((x as { transform?: unknown }).transform);\n\nfunction PageCanvas({ page, doc, caption, onReady, className }: { page: number; doc: PdfDocument; caption: string; onReady?: () => void; className: string }) {\n const ref = React.useRef<HTMLCanvasElement>(null);\n const wrapper = React.useRef<HTMLDivElement>(null);\n const [visible, setVisible] = React.useState(() => typeof IntersectionObserver === \"undefined\");\n const ready = useLatest(onReady);\n React.useEffect(() => {\n const node = wrapper.current?.parentElement;\n if (!node) return;\n if (typeof IntersectionObserver === \"undefined\") return;\n const observer = new IntersectionObserver((entries) => entries.some((e) => e.isIntersecting) && setVisible(true), { rootMargin: \"600px 0px\" });\n observer.observe(node);\n return () => observer.disconnect();\n }, []);\n React.useEffect(() => {\n if (!visible) return;\n let task: { promise: Promise<void>; cancel?: () => void } | undefined;\n let cancelled = false;\n void (async () => {\n const p = await doc.getPage(page);\n const canvas = ref.current;\n const ctx = canvas?.getContext(\"2d\");\n if (cancelled || !canvas || !ctx) return;\n const base = p.getViewport({ scale: 1 });\n const dpr = typeof window === \"undefined\" ? 1 : Math.min(2, window.devicePixelRatio || 1);\n const scale = Math.min(2.5, Math.max(1, (canvas.parentElement?.clientWidth || base.width) / base.width)) * dpr;\n const viewport = p.getViewport({ scale });\n canvas.width = Math.floor(viewport.width);\n canvas.height = Math.floor(viewport.height);\n task = p.render({ canvas, canvasContext: ctx, viewport });\n await task.promise.catch(() => undefined);\n if (!cancelled) ready.current?.();\n })().catch(() => undefined);\n return () => {\n cancelled = true;\n task?.cancel?.();\n };\n }, [visible, doc, page, ready]);\n return (\n <div ref={wrapper} className=\"contents\">\n <canvas ref={ref} aria-hidden=\"true\" className={className} />\n <span className=\"sr-only\">{caption}</span>\n </div>\n );\n}\n\n/** A PDF with its passages lit — see the file's header. Client. */\nexport function DocumentViewer({ src, loadPdfjs, workerSrc, highlights = [], activeId = null, onActiveChange, onLocate, onLoad, labels, className, ...props }: DocumentViewerProps) {\n const words = { ...documentViewerLabels, ...labels };\n const s = documentViewer();\n const reduce = usePrefersReducedMotion();\n const [loaded, setPhase] = React.useState<Phase>({ state: \"loading\" });\n const callbacks = useLatest({ onLoad, onLocate });\n const containerRef = React.useRef<HTMLDivElement>(null);\n const bytes = typeof src === \"string\" ? src : src.byteLength + \":\" + src[0] + \":\" + src[src.length - 1];\n // A result belongs to the document it was read from: another `src` is loading again, with no reset inside the effect.\n const phase: Phase = loaded.state !== \"loading\" && loaded.key !== bytes ? { state: \"loading\" } : loaded;\n\n // Open the document and read every page's text layer (positions only; nothing is sent anywhere).\n React.useEffect(() => {\n let cancelled = false;\n let opened: { destroy?: () => Promise<void> | void } | undefined;\n void (async () => {\n const pdfjs = await loadPdfjs();\n pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;\n const loading = pdfjs.getDocument(typeof src === \"string\" ? { url: src } : { data: src.slice() });\n opened = loading;\n const doc = await loading.promise;\n const texts: PageText[] = [];\n const sizes: Loaded[\"sizes\"] = [];\n for (let n = 1; n <= doc.numPages; n++) {\n const page = await doc.getPage(n);\n const vp = page.getViewport({ scale: 1 });\n sizes.push({ width: vp.width, height: vp.height });\n const content = await page.getTextContent();\n // A rotated page has no reliable boxes: it keeps its size and an empty text layer (the app's page hint still works).\n texts.push({ page: n, width: vp.width, height: vp.height, items: page.rotate % 360 === 0 ? content.items.filter(isItem) : [] });\n page.cleanup?.();\n }\n if (cancelled) return;\n setPhase({ state: \"ready\", key: bytes, doc, texts, sizes });\n callbacks.current.onLoad?.({ pages: doc.numPages });\n })().catch(() => !cancelled && setPhase({ state: \"error\", key: bytes }));\n return () => {\n cancelled = true;\n void opened?.destroy?.();\n };\n // `src` is compared by content (`bytes`) so a re-render with the same bytes does not reopen the file.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [bytes, loadPdfjs, workerSrc, callbacks]);\n\n const key = highlights.map((h) => `${h.id}\\u0000${h.page ?? \"\"}\\u0000${h.quote}`).join(\"\\u0001\");\n const found = React.useMemo(() => {\n const out: Record<string, Located | null> = {};\n if (phase.state === \"ready\") for (const h of highlights) out[h.id] = locateQuote(phase.texts, h.quote, h.page);\n return out;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [phase, key]);\n React.useEffect(() => {\n if (phase.state === \"ready\") callbacks.current.onLocate?.(found);\n }, [found, phase.state, callbacks]);\n\n // Go to the active passage.\n const active = activeId ? highlights.find((h) => h.id === activeId) : undefined;\n const where = activeId ? found[activeId] : undefined;\n React.useEffect(() => {\n if (phase.state !== \"ready\" || !where) return;\n const root = containerRef.current;\n const target = root?.querySelector<HTMLElement>(where.boxes.length > 0 ? `[data-highlight=\"${CSS.escape(activeId!)}\"]` : `[data-page=\"${where.page}\"]`) ?? null;\n target?.scrollIntoView?.({ block: where.boxes.length > 0 ? \"center\" : \"start\", behavior: reduce ? \"auto\" : \"smooth\" });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeId, where, phase.state]);\n\n return (\n <div className={s.root({ className })} {...props}>\n {active && where !== undefined && where?.match !== \"exact\" && where?.match !== \"start\" ? (\n <p className={s.bar()} data-testid=\"document-viewer-bar\">\n {where?.match === \"page\" ? fill(words.onPage, { page: where.page }) : words.notFound} <q>{active.quote}</q>\n </p>\n ) : null}\n <div ref={containerRef} className={s.pages()} role=\"region\" aria-label={words.region} tabIndex={0}>\n {phase.state === \"loading\" ? <p className={s.status()}>{words.loading}</p> : null}\n {phase.state === \"error\" ? <p role=\"alert\" className={s.status()}>{words.failed}</p> : null}\n {phase.state === \"ready\"\n ? phase.texts.map((t, i) => {\n const size = phase.sizes[i]!;\n const caption = fill(words.page, { page: t.page, total: phase.doc.numPages });\n return (\n <div key={t.page} className={s.page()} data-page={t.page} style={{ aspectRatio: `${size.width} / ${size.height}` }}>\n <PageCanvas page={t.page} doc={phase.doc} caption={caption} className={s.canvas()} />\n <span className={s.caption()} aria-hidden=\"true\">{caption}</span>\n {highlights.flatMap((h) => {\n const f = found[h.id];\n if (!f || f.page !== t.page) return [];\n return f.boxes.map((b, k) => (\n <div\n key={`${h.id}:${k}`}\n aria-hidden=\"true\"\n data-highlight={h.id}\n data-active={h.id === activeId}\n className={s.box()}\n style={{ left: `${b.x * 100}%`, top: `${b.y * 100}%`, width: `${b.width * 100}%`, height: `${b.height * 100}%` }}\n onClick={() => onActiveChange?.(h.id === activeId ? null : h.id)}\n />\n ));\n })}\n </div>\n );\n })\n : null}\n </div>\n </div>\n );\n}\n","// Pure: where a quoted passage sits on the pages of a PDF, from pdf.js's text positions. No DOM, no pdf.js import —\n// the viewer feeds it what `page.getTextContent()` returned, a test feeds it a fixture.\n\n/** A text item as pdf.js returns it (`TextItem`): the string, its matrix (`[a, b, c, d, x, baseline]`) and its size. */\nexport type TextItem = { str: string; transform: number[]; width: number; height: number };\n\n/** A rectangle in fractions of the page (0–1), origin top-left — independent of the zoom the page is drawn at. */\nexport type Box = { x: number; y: number; width: number; height: number };\n\n/** The text layer of one page: its size in PDF units (rotation 0) and its items in reading order. */\nexport type PageText = { page: number; width: number; height: number; items: readonly TextItem[] };\n\nexport type Located = {\n /** 1-based page where the passage starts. */\n page: number;\n /** One box per line of the passage (merged along a line); empty when only the page is known. */\n boxes: Box[];\n /** `exact`: the whole quote was found; `start`: only its opening words were (a quote cut by a different layout). */\n match: \"exact\" | \"start\" | \"page\";\n};\n\nconst FOLD: Record<string, string> = { \"’\": \"'\", \"‘\": \"'\", \"“\": '\"', \"”\": '\"', \"«\": '\"', \"»\": '\"', \"–\": \"-\", \"—\": \"-\", \" \": \" \", \" \": \" \", \"fi\": \"fi\", \"fl\": \"fl\" };\n\n/** The comparable form of a text: no whitespace, no soft hyphen, straight quotes, case and accents folded. */\nexport function fold(text: string): string {\n let out = \"\";\n for (const ch of text.normalize(\"NFKD\")) {\n if (/\\p{M}/u.test(ch) || /\\s/u.test(ch) || ch === \"­\" || ch === \"​\") continue;\n out += (FOLD[ch] ?? ch).toLowerCase();\n }\n return out;\n}\n\ntype Index = { text: string; at: { item: number; char: number }[] };\n\nfunction indexPage(items: readonly TextItem[]): Index {\n let text = \"\";\n const at: Index[\"at\"] = [];\n items.forEach((item, i) => {\n for (let c = 0; c < item.str.length; c++) {\n const piece = fold(item.str[c]!);\n for (let k = 0; k < piece.length; k++) {\n text += piece[k];\n at.push({ item: i, char: c });\n }\n }\n });\n return { text, at };\n}\n\n// Proportional faces: \"locataire\" is not as wide as nine capitals. pdf.js gives one width per item, so a position inside an\n// item is shared out by the Helvetica advance widths (per 1000 em) — close for any sans text, far better than a flat share.\nconst ADVANCE =\n \"278 278 355 556 556 889 667 191 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 278 278 584 584 584 556 1015 \" +\n \"667 667 722 722 667 611 778 722 278 500 667 556 833 722 778 667 778 722 667 611 722 667 944 667 667 611 278 278 278 469 556 333 \" +\n \"556 556 500 556 556 278 556 556 222 222 500 222 833 556 556 556 556 333 500 278 556 500 722 500 500 500\";\nconst ADVANCES = ADVANCE.split(\" \").map(Number);\nfunction advance(ch: string): number {\n const base = ch.normalize(\"NFD\")[0] ?? ch;\n const code = base.charCodeAt(0);\n return code >= 32 && code <= 126 ? (ADVANCES[code - 32] ?? 556) : 556;\n}\n/** The share (0–1) of an item's width that lies before character `n` of `text`. */\nfunction shareBefore(text: string, n: number): number {\n let before = 0;\n let total = 0;\n for (let i = 0; i < text.length; i++) {\n const a = advance(text[i]!);\n if (i < n) before += a;\n total += a;\n }\n return total > 0 ? before / total : n / Math.max(1, text.length);\n}\n\nfunction boxesOf(page: PageText, index: Index, from: number, to: number): Box[] {\n const spans = new Map<number, [number, number]>();\n for (let k = from; k < to; k++) {\n const { item, char } = index.at[k]!;\n const s = spans.get(item);\n spans.set(item, s ? [Math.min(s[0], char), Math.max(s[1], char + 1)] : [char, char + 1]);\n }\n const raw: Box[] = [];\n for (const [i, [c0, c1]] of [...spans].sort((a, b) => a[0] - b[0])) {\n const item = page.items[i]!;\n const size = item.height || Math.abs(item.transform[3] ?? 0) || 10;\n const x = (item.transform[4] ?? 0) + item.width * shareBefore(item.str, c0);\n const w = item.width * (shareBefore(item.str, c1) - shareBefore(item.str, c0));\n const top = page.height - ((item.transform[5] ?? 0) + size * 0.9);\n raw.push({ x: x / page.width, y: top / page.height, width: w / page.width, height: (size * 1.15) / page.height });\n }\n // Merge the pieces that sit on one line and touch (several items of one sentence) into one rectangle.\n const merged: Box[] = [];\n for (const b of raw) {\n const last = merged[merged.length - 1];\n const sameLine = last && Math.abs(last.y - b.y) < last.height * 0.5 && b.x - (last.x + last.width) < last.height * 1.5 && b.x >= last.x - 1e-9;\n if (last && sameLine) {\n const right = Math.max(last.x + last.width, b.x + b.width);\n last.y = Math.min(last.y, b.y);\n last.height = Math.max(last.height, b.height);\n last.width = right - last.x;\n } else merged.push({ ...b });\n }\n return merged.map((b) => ({ x: clamp01(b.x), y: clamp01(b.y), width: Math.min(b.width, 1 - clamp01(b.x)), height: Math.min(b.height, 1 - clamp01(b.y)) }));\n}\n\nconst clamp01 = (n: number) => Math.min(1, Math.max(0, n));\n\n/** The shortest opening worth highlighting alone: a few words, not a stray letter. */\nconst MIN_START = 24;\n\n/**\n * Where `quote` sits in the pages: the first page (starting with `hintPage`, if any) whose text contains it, and the\n * boxes of its lines. A quote that a different layout cut (a column break, a hyphen) is looked for by its opening\n * words (`match: \"start\"`); one that is nowhere gives `null`, or the hinted page alone (`match: \"page\"`). Never a guess:\n * a rotated page has no boxes, only its page.\n */\nexport function locateQuote(pages: readonly PageText[], quote: string, hintPage?: number): Located | null {\n const needle = fold(quote);\n const ordered = hintPage ? [...pages].sort((a, b) => Number(b.page === hintPage) - Number(a.page === hintPage)) : pages;\n if (needle.length > 0) {\n for (const mode of [\"exact\", \"start\"] as const) {\n const wanted = mode === \"exact\" ? needle : needle.slice(0, Math.max(MIN_START, Math.min(40, Math.floor(needle.length * 0.6))));\n if (mode === \"start\" && (needle.length <= wanted.length || wanted.length < MIN_START)) break;\n for (const page of ordered) {\n const index = indexPage(page.items);\n const found = index.text.indexOf(wanted);\n if (found < 0) continue;\n return { page: page.page, boxes: boxesOf(page, index, found, found + wanted.length), match: mode };\n }\n }\n }\n return hintPage && pages.some((p) => p.page === hintPage) ? { page: hintPage, boxes: [], match: \"page\" } : null;\n}\n"],"mappings":";;;;;;;AAOA,YAAY,WAAW;AACvB,SAAS,UAAU;;;ACanB,IAAM,OAA+B,EAAE,UAAK,KAAK,UAAK,KAAK,UAAK,KAAK,UAAK,KAAK,QAAK,KAAK,QAAK,KAAK,UAAK,KAAK,UAAK,KAAK,QAAK,KAAK,UAAK,KAAK,UAAK,MAAM,UAAK,KAAK;AAGzJ,SAAS,KAAK,MAAsB;AACzC,MAAI,MAAM;AACV,aAAW,MAAM,KAAK,UAAU,MAAM,GAAG;AACvC,QAAI,SAAS,KAAK,EAAE,KAAK,MAAM,KAAK,EAAE,KAAK,OAAO,UAAO,OAAO,SAAK;AACrE,YAAQ,KA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W,EAAE,OAAO,GAAG;AAAA,UACnF,oBAAC,UAAK,WAAW,EAAE,QAAQ,GAAG,eAAY,QAAQ,mBAAQ;AAAA,UACzD,WAAW,QAAQ,CAAC,MAAM;AACzB,kBAAM,IAAI,MAAM,EAAE,EAAE;AACpB,gBAAI,CAAC,KAAK,EAAE,SAAS,EAAE,KAAM,QAAO,CAAC;AACrC,mBAAO,EAAE,MAAM,IAAI,CAAC,GAAG,MACrB;AAAA,cAAC;AAAA;AAAA,gBAEC,eAAY;AAAA,gBACZ,kBAAgB,EAAE;AAAA,gBAClB,eAAa,EAAE,OAAO;AAAA,gBACtB,WAAW,EAAE,IAAI;AAAA,gBACjB,OAAO,EAAE,MAAM,GAAG,EAAE,IAAI,GAAG,KAAK,KAAK,GAAG,EAAE,IAAI,GAAG,KAAK,OAAO,GAAG,EAAE,QAAQ,GAAG,KAAK,QAAQ,GAAG,EAAE,SAAS,GAAG,IAAI;AAAA,gBAC/G,SAAS,MAAM,iBAAiB,EAAE,OAAO,WAAW,OAAO,EAAE,EAAE;AAAA;AAAA,cAN1D,GAAG,EAAE,EAAE,IAAI,CAAC;AAAA,YAOnB,CACD;AAAA,UACH,CAAC;AAAA,aAjBO,EAAE,IAkBZ;AAAA,MAEJ,CAAC,IACD;AAAA,OACN;AAAA,KACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../src/document-viewer/document-viewer.tsx","../src/document-viewer/locate.ts"],"sourcesContent":["// Client. A PDF drawn page by page (pdf.js), and passages of it lit where they sit. The app hands over the engine\n// (`loadPdfjs={() => import(\"pdfjs-dist\")}` — an optional peer, loaded only on a page that shows a document) and the\n// worker's address; it hands over the passages as quotes (`highlights`), and the viewer finds their place from the\n// PDF's own text positions (`locateQuote`): one box per line, in fractions of the page, so they follow any zoom.\n// `activeId` (controlled) scrolls to a passage and strengthens it; a click on a box calls `onActiveChange`. A passage\n// the text layer cannot place is never drawn at a guessed place: the viewer goes to its page when it is known and shows\n// the quote in a bar — and tells the app (`onLocate`) so its list can say \"page 3\" or \"not found\".\nimport * as React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { useLatest, usePrefersReducedMotion } from \"../media\";\nimport { type Located, type PageText, type Region, resolveHighlight } from \"./locate\";\n\nexport const documentViewer = tv({\n slots: {\n root: \"relative flex min-w-0 flex-col gap-3\",\n pages: \"flex max-h-(--kz-document-viewer-height,70vh) flex-col gap-3 overflow-auto rounded-lg border border-border-default bg-surface-2 p-3 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent\",\n page: \"relative mx-auto w-full max-w-(--kz-document-viewer-page,56rem) shrink-0 overflow-hidden rounded-sm bg-white shadow-sm\",\n canvas: \"block h-auto w-full\",\n caption: \"absolute top-1 left-1 rounded-sm bg-surface-1/90 px-1.5 py-0.5 text-xs text-fg-secondary\",\n box: \"absolute cursor-pointer rounded-xs border border-warning/70 bg-warning/25 mix-blend-multiply transition-colors data-[active=true]:border-2 data-[active=true]:border-danger data-[active=true]:bg-danger/25 motion-reduce:transition-none\",\n bar: \"rounded-lg border border-border-default bg-surface-1 px-3 py-2 text-sm text-fg-secondary\",\n status: \"p-6 text-center text-sm text-fg-secondary\",\n },\n});\n\n/** The words of the viewer, passed translated. `{page}` and `{total}` are replaced. */\nexport type DocumentViewerLabels = {\n /** The accessible name of the pages' region. */\n region: string;\n loading: string;\n failed: string;\n /** A page's caption and accessible name: \"Page {page} of {total}\". */\n page: string;\n /** The bar above the pages when the active passage could only be placed on a page: \"Passage on page {page}:\". */\n onPage: string;\n /** The bar when the active passage is not in the text layer. */\n notFound: string;\n};\n\nexport const documentViewerLabels: DocumentViewerLabels = {\n region: \"Document pages\",\n loading: \"Loading the document…\",\n failed: \"The document could not be displayed.\",\n page: \"Page {page} of {total}\",\n onPage: \"Passage on page {page}:\",\n notFound: \"This passage is not in the document's text layer:\",\n};\n\n/** A passage to light: its quote (as the text layer reads it) and/or a `region` of a page the app already knows (a stamp, a\n mismatch — fractions of the page, origin top-left); the page if known, a name for screen readers. A valid region wins. */\nexport type DocumentHighlight = { id: string; quote?: string; region?: Region; page?: number; label?: string };\n\n/** What the viewer found for a passage. */\nexport type { Located };\n\n/** The members of pdf.js the viewer uses (`pdfjs-dist` ≥ 5), typed here so the package does not depend on it. */\nexport type PdfjsModule = {\n GlobalWorkerOptions: { workerSrc: string };\n getDocument(source: { url?: string; data?: Uint8Array }): { promise: Promise<PdfDocument>; destroy?: () => Promise<void> | void };\n};\nexport type PdfDocument = { numPages: number; getPage(n: number): Promise<PdfPage>; destroy?: () => Promise<void> | void };\nexport type PdfPage = {\n rotate: number;\n view: number[];\n getViewport(options: { scale: number }): { width: number; height: number };\n getTextContent(): Promise<{ items: readonly unknown[] }>;\n render(options: { canvas: HTMLCanvasElement; canvasContext: CanvasRenderingContext2D; viewport: { width: number; height: number } }): { promise: Promise<void>; cancel?: () => void };\n cleanup?: () => void;\n};\n\nexport type DocumentViewerProps = Omit<React.ComponentProps<\"div\">, \"children\" | \"onChange\"> & {\n /** The PDF: an address (same origin or CORS) or its bytes. */\n src: string | Uint8Array;\n /** Loads pdf.js: `() => import(\"pdfjs-dist\")`. An optional peer, never in a bundle without a document. */\n loadPdfjs: () => Promise<PdfjsModule>;\n /** The address of pdf.js's worker (`new URL(\"pdfjs-dist/build/pdf.worker.min.mjs\", import.meta.url).toString()`). */\n workerSrc: string;\n /** The passages to light. */\n highlights?: readonly DocumentHighlight[];\n /** The passage in focus: the viewer scrolls to it. */\n activeId?: string | null;\n /** A box was clicked (the id) or the focus was released (`null`). */\n onActiveChange?: (id: string | null) => void;\n /** Where each passage was found (`null`: nowhere) — once the text layer is read, and again if `highlights` change. */\n onLocate?: (found: Record<string, Located | null>) => void;\n /** Called when the document is open, with its page count. */\n onLoad?: (info: { pages: number }) => void;\n /** The words of the viewer, translated (English by default). */\n labels?: Partial<DocumentViewerLabels>;\n};\n\nconst regionKey = (r: Region | undefined) => (r ? [r.page, r.x, r.y, r.width, r.height].join(\",\") : \"\");\nconst fill = (template: string, vars: Record<string, string | number>) => template.replace(/\\{(\\w+)\\}/g, (m, k: string) => (k in vars ? String(vars[k]) : m));\n\ntype Loaded = { doc: PdfDocument; texts: PageText[]; sizes: { width: number; height: number }[] };\ntype Phase = { state: \"loading\" } | { state: \"error\"; key: string } | ({ state: \"ready\"; key: string } & Loaded);\n\nconst isItem = (x: unknown): x is PageText[\"items\"][number] => typeof x === \"object\" && x !== null && typeof (x as { str?: unknown }).str === \"string\" && Array.isArray((x as { transform?: unknown }).transform);\n\nfunction PageCanvas({ page, doc, caption, onReady, className }: { page: number; doc: PdfDocument; caption: string; onReady?: () => void; className: string }) {\n const ref = React.useRef<HTMLCanvasElement>(null);\n const wrapper = React.useRef<HTMLDivElement>(null);\n const [visible, setVisible] = React.useState(() => typeof IntersectionObserver === \"undefined\");\n const ready = useLatest(onReady);\n React.useEffect(() => {\n const node = wrapper.current?.parentElement;\n if (!node) return;\n if (typeof IntersectionObserver === \"undefined\") return;\n const observer = new IntersectionObserver((entries) => entries.some((e) => e.isIntersecting) && setVisible(true), { rootMargin: \"600px 0px\" });\n observer.observe(node);\n return () => observer.disconnect();\n }, []);\n React.useEffect(() => {\n if (!visible) return;\n let task: { promise: Promise<void>; cancel?: () => void } | undefined;\n let cancelled = false;\n void (async () => {\n const p = await doc.getPage(page);\n const canvas = ref.current;\n const ctx = canvas?.getContext(\"2d\");\n if (cancelled || !canvas || !ctx) return;\n const base = p.getViewport({ scale: 1 });\n const dpr = typeof window === \"undefined\" ? 1 : Math.min(2, window.devicePixelRatio || 1);\n const scale = Math.min(2.5, Math.max(1, (canvas.parentElement?.clientWidth || base.width) / base.width)) * dpr;\n const viewport = p.getViewport({ scale });\n canvas.width = Math.floor(viewport.width);\n canvas.height = Math.floor(viewport.height);\n task = p.render({ canvas, canvasContext: ctx, viewport });\n await task.promise.catch(() => undefined);\n if (!cancelled) ready.current?.();\n })().catch(() => undefined);\n return () => {\n cancelled = true;\n task?.cancel?.();\n };\n }, [visible, doc, page, ready]);\n return (\n <div ref={wrapper} className=\"contents\">\n <canvas ref={ref} aria-hidden=\"true\" className={className} />\n <span className=\"sr-only\">{caption}</span>\n </div>\n );\n}\n\n/** A PDF with its passages lit — see the file's header. Client. */\nexport function DocumentViewer({ src, loadPdfjs, workerSrc, highlights = [], activeId = null, onActiveChange, onLocate, onLoad, labels, className, ...props }: DocumentViewerProps) {\n const words = { ...documentViewerLabels, ...labels };\n const s = documentViewer();\n const reduce = usePrefersReducedMotion();\n const [loaded, setPhase] = React.useState<Phase>({ state: \"loading\" });\n const callbacks = useLatest({ onLoad, onLocate });\n const containerRef = React.useRef<HTMLDivElement>(null);\n const bytes = typeof src === \"string\" ? src : src.byteLength + \":\" + src[0] + \":\" + src[src.length - 1];\n // A result belongs to the document it was read from: another `src` is loading again, with no reset inside the effect.\n const phase: Phase = loaded.state !== \"loading\" && loaded.key !== bytes ? { state: \"loading\" } : loaded;\n\n // Open the document and read every page's text layer (positions only; nothing is sent anywhere).\n React.useEffect(() => {\n let cancelled = false;\n let opened: { destroy?: () => Promise<void> | void } | undefined;\n void (async () => {\n const pdfjs = await loadPdfjs();\n pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;\n const loading = pdfjs.getDocument(typeof src === \"string\" ? { url: src } : { data: src.slice() });\n opened = loading;\n const doc = await loading.promise;\n const texts: PageText[] = [];\n const sizes: Loaded[\"sizes\"] = [];\n for (let n = 1; n <= doc.numPages; n++) {\n const page = await doc.getPage(n);\n const vp = page.getViewport({ scale: 1 });\n sizes.push({ width: vp.width, height: vp.height });\n const content = await page.getTextContent();\n // A rotated page has no reliable boxes: it keeps its size and an empty text layer (the app's page hint still works).\n texts.push({ page: n, width: vp.width, height: vp.height, items: page.rotate % 360 === 0 ? content.items.filter(isItem) : [] });\n page.cleanup?.();\n }\n if (cancelled) return;\n setPhase({ state: \"ready\", key: bytes, doc, texts, sizes });\n callbacks.current.onLoad?.({ pages: doc.numPages });\n })().catch(() => !cancelled && setPhase({ state: \"error\", key: bytes }));\n return () => {\n cancelled = true;\n void opened?.destroy?.();\n };\n // `src` is compared by content (`bytes`) so a re-render with the same bytes does not reopen the file.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [bytes, loadPdfjs, workerSrc, callbacks]);\n\n const key = highlights.map((h) => `${h.id}\\u0000${h.page ?? \"\"}\\u0000${h.quote ?? \"\"}\\u0000${regionKey(h.region)}`).join(\"\\u0001\");\n const found = React.useMemo(() => {\n const out: Record<string, Located | null> = {};\n if (phase.state === \"ready\") for (const h of highlights) out[h.id] = resolveHighlight(phase.texts, h);\n return out;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [phase, key]);\n React.useEffect(() => {\n if (phase.state === \"ready\") callbacks.current.onLocate?.(found);\n }, [found, phase.state, callbacks]);\n\n // Go to the active passage.\n const active = activeId ? highlights.find((h) => h.id === activeId) : undefined;\n const where = activeId ? found[activeId] : undefined;\n React.useEffect(() => {\n if (phase.state !== \"ready\" || !where) return;\n const root = containerRef.current;\n const target = root?.querySelector<HTMLElement>(where.boxes.length > 0 ? `[data-highlight=\"${CSS.escape(activeId!)}\"]` : `[data-page=\"${where.page}\"]`) ?? null;\n target?.scrollIntoView?.({ block: where.boxes.length > 0 ? \"center\" : \"start\", behavior: reduce ? \"auto\" : \"smooth\" });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeId, where, phase.state]);\n\n return (\n <div className={s.root({ className })} {...props}>\n {active && where !== undefined && where?.match !== \"exact\" && where?.match !== \"start\" && where?.match !== \"region\" ? (\n <p className={s.bar()} data-testid=\"document-viewer-bar\">\n {where?.match === \"page\" ? fill(words.onPage, { page: where.page }) : words.notFound} {active.quote ? <q>{active.quote}</q> : null}\n </p>\n ) : null}\n <div ref={containerRef} className={s.pages()} role=\"region\" aria-label={words.region} tabIndex={0}>\n {phase.state === \"loading\" ? <p className={s.status()}>{words.loading}</p> : null}\n {phase.state === \"error\" ? <p role=\"alert\" className={s.status()}>{words.failed}</p> : null}\n {phase.state === \"ready\"\n ? phase.texts.map((t, i) => {\n const size = phase.sizes[i]!;\n const caption = fill(words.page, { page: t.page, total: phase.doc.numPages });\n return (\n <div key={t.page} className={s.page()} data-page={t.page} style={{ aspectRatio: `${size.width} / ${size.height}` }}>\n <PageCanvas page={t.page} doc={phase.doc} caption={caption} className={s.canvas()} />\n <span className={s.caption()} aria-hidden=\"true\">{caption}</span>\n {highlights.flatMap((h) => {\n const f = found[h.id];\n if (!f || f.page !== t.page) return [];\n return f.boxes.map((b, k) => (\n <div\n key={`${h.id}:${k}`}\n aria-hidden=\"true\"\n data-highlight={h.id}\n data-active={h.id === activeId}\n className={s.box()}\n style={{ left: `${b.x * 100}%`, top: `${b.y * 100}%`, width: `${b.width * 100}%`, height: `${b.height * 100}%` }}\n onClick={() => onActiveChange?.(h.id === activeId ? null : h.id)}\n />\n ));\n })}\n </div>\n );\n })\n : null}\n </div>\n </div>\n );\n}\n","// Pure: where a quoted passage sits on the pages of a PDF, from pdf.js's text positions. No DOM, no pdf.js import —\n// the viewer feeds it what `page.getTextContent()` returned, a test feeds it a fixture.\n\n/** A text item as pdf.js returns it (`TextItem`): the string, its matrix (`[a, b, c, d, x, baseline]`) and its size. */\nexport type TextItem = { str: string; transform: number[]; width: number; height: number };\n\n/** A rectangle in fractions of the page (0–1), origin top-left — independent of the zoom the page is drawn at. */\nexport type Box = { x: number; y: number; width: number; height: number };\n\n/** The text layer of one page: its size in PDF units (rotation 0) and its items in reading order. */\nexport type PageText = { page: number; width: number; height: number; items: readonly TextItem[] };\n\nexport type Located = {\n /** 1-based page where the passage starts. */\n page: number;\n /** One box per line of the passage (merged along a line); empty when only the page is known. */\n boxes: Box[];\n /** `region`: the box the app gave, as it is; `exact`: the whole quote was found; `start`: only its opening words were (a quote cut by a different layout). */\n match: \"exact\" | \"start\" | \"page\" | \"region\";\n};\n\n/** A region of a page the app already knows (a stamp, a font mismatch, a metadata area): its page and a box in fractions. */\nexport type Region = Box & { page: number };\n\nconst FOLD: Record<string, string> = { \"’\": \"'\", \"‘\": \"'\", \"“\": '\"', \"”\": '\"', \"«\": '\"', \"»\": '\"', \"–\": \"-\", \"—\": \"-\", \" \": \" \", \" \": \" \", \"fi\": \"fi\", \"fl\": \"fl\" };\n\n/** The comparable form of a text: no whitespace, no soft hyphen, straight quotes, case and accents folded. */\nexport function fold(text: string): string {\n let out = \"\";\n for (const ch of text.normalize(\"NFKD\")) {\n if (/\\p{M}/u.test(ch) || /\\s/u.test(ch) || ch === \"­\" || ch === \"​\") continue;\n out += (FOLD[ch] ?? ch).toLowerCase();\n }\n return out;\n}\n\ntype Index = { text: string; at: { item: number; char: number }[] };\n\nfunction indexPage(items: readonly TextItem[]): Index {\n let text = \"\";\n const at: Index[\"at\"] = [];\n items.forEach((item, i) => {\n for (let c = 0; c < item.str.length; c++) {\n const piece = fold(item.str[c]!);\n for (let k = 0; k < piece.length; k++) {\n text += piece[k];\n at.push({ item: i, char: c });\n }\n }\n });\n return { text, at };\n}\n\n// Proportional faces: \"locataire\" is not as wide as nine capitals. pdf.js gives one width per item, so a position inside an\n// item is shared out by the Helvetica advance widths (per 1000 em) — close for any sans text, far better than a flat share.\nconst ADVANCE =\n \"278 278 355 556 556 889 667 191 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 278 278 584 584 584 556 1015 \" +\n \"667 667 722 722 667 611 778 722 278 500 667 556 833 722 778 667 778 722 667 611 722 667 944 667 667 611 278 278 278 469 556 333 \" +\n \"556 556 500 556 556 278 556 556 222 222 500 222 833 556 556 556 556 333 500 278 556 500 722 500 500 500\";\nconst ADVANCES = ADVANCE.split(\" \").map(Number);\nfunction advance(ch: string): number {\n const base = ch.normalize(\"NFD\")[0] ?? ch;\n const code = base.charCodeAt(0);\n return code >= 32 && code <= 126 ? (ADVANCES[code - 32] ?? 556) : 556;\n}\n/** The share (0–1) of an item's width that lies before character `n` of `text`. */\nfunction shareBefore(text: string, n: number): number {\n let before = 0;\n let total = 0;\n for (let i = 0; i < text.length; i++) {\n const a = advance(text[i]!);\n if (i < n) before += a;\n total += a;\n }\n return total > 0 ? before / total : n / Math.max(1, text.length);\n}\n\nfunction boxesOf(page: PageText, index: Index, from: number, to: number): Box[] {\n const spans = new Map<number, [number, number]>();\n for (let k = from; k < to; k++) {\n const { item, char } = index.at[k]!;\n const s = spans.get(item);\n spans.set(item, s ? [Math.min(s[0], char), Math.max(s[1], char + 1)] : [char, char + 1]);\n }\n const raw: Box[] = [];\n for (const [i, [c0, c1]] of [...spans].sort((a, b) => a[0] - b[0])) {\n const item = page.items[i]!;\n const size = item.height || Math.abs(item.transform[3] ?? 0) || 10;\n const x = (item.transform[4] ?? 0) + item.width * shareBefore(item.str, c0);\n const w = item.width * (shareBefore(item.str, c1) - shareBefore(item.str, c0));\n const top = page.height - ((item.transform[5] ?? 0) + size * 0.9);\n raw.push({ x: x / page.width, y: top / page.height, width: w / page.width, height: (size * 1.15) / page.height });\n }\n // Merge the pieces that sit on one line and touch (several items of one sentence) into one rectangle.\n const merged: Box[] = [];\n for (const b of raw) {\n const last = merged[merged.length - 1];\n const sameLine = last && Math.abs(last.y - b.y) < last.height * 0.5 && b.x - (last.x + last.width) < last.height * 1.5 && b.x >= last.x - 1e-9;\n if (last && sameLine) {\n const right = Math.max(last.x + last.width, b.x + b.width);\n last.y = Math.min(last.y, b.y);\n last.height = Math.max(last.height, b.height);\n last.width = right - last.x;\n } else merged.push({ ...b });\n }\n return merged.map((b) => ({ x: clamp01(b.x), y: clamp01(b.y), width: Math.min(b.width, 1 - clamp01(b.x)), height: Math.min(b.height, 1 - clamp01(b.y)) }));\n}\n\nconst clamp01 = (n: number) => Math.min(1, Math.max(0, n));\n\n/** The shortest opening worth highlighting alone: a few words, not a stray letter. */\nconst MIN_START = 24;\n\n/**\n * Where `quote` sits in the pages: the first page (starting with `hintPage`, if any) whose text contains it, and the\n * boxes of its lines. A quote that a different layout cut (a column break, a hyphen) is looked for by its opening\n * words (`match: \"start\"`); one that is nowhere gives `null`, or the hinted page alone (`match: \"page\"`). Never a guess:\n * a rotated page has no boxes, only its page.\n */\nexport function locateQuote(pages: readonly PageText[], quote: string, hintPage?: number): Located | null {\n const needle = fold(quote);\n const ordered = hintPage ? [...pages].sort((a, b) => Number(b.page === hintPage) - Number(a.page === hintPage)) : pages;\n if (needle.length > 0) {\n for (const mode of [\"exact\", \"start\"] as const) {\n const wanted = mode === \"exact\" ? needle : needle.slice(0, Math.max(MIN_START, Math.min(40, Math.floor(needle.length * 0.6))));\n if (mode === \"start\" && (needle.length <= wanted.length || wanted.length < MIN_START)) break;\n for (const page of ordered) {\n const index = indexPage(page.items);\n const found = index.text.indexOf(wanted);\n if (found < 0) continue;\n return { page: page.page, boxes: boxesOf(page, index, found, found + wanted.length), match: mode };\n }\n }\n }\n return hintPage && pages.some((p) => p.page === hintPage) ? { page: hintPage, boxes: [], match: \"page\" } : null;\n}\n\nconst inUnit = (n: number) => Number.isFinite(n) && n >= 0 && n <= 1;\n\n/**\n * A region of a page, as it is: one box, no text needed. Never drawn when it is not on the pages — an unknown page, a box\n * outside 0–1 or empty, a value that is not a number — so a wrong box is `null`, not a guess.\n */\nexport function locateRegion(pages: readonly PageText[], region: Region): Located | null {\n const { page, x, y, width, height } = region;\n const valid = pages.some((p) => p.page === page) && inUnit(x) && inUnit(y) && width > 0 && height > 0 && inUnit(x + width) && inUnit(y + height);\n return valid ? { page, boxes: [{ x, y, width, height }], match: \"region\" } : null;\n}\n\n/** What to light for a highlight: its region when it has a valid one, otherwise its quote (if any). */\nexport function resolveHighlight(pages: readonly PageText[], h: { quote?: string; page?: number; region?: Region }): Located | null {\n const byRegion = h.region ? locateRegion(pages, h.region) : null;\n if (byRegion) return byRegion;\n if (h.quote) return locateQuote(pages, h.quote, h.page ?? h.region?.page);\n const hinted = h.page !== undefined && pages.some((p) => p.page === h.page);\n return hinted ? { page: h.page!, boxes: [], match: \"page\" } : null;\n}\n"],"mappings":";;;;;;;AAOA,YAAY,WAAW;AACvB,SAAS,UAAU;;;ACgBnB,IAAM,OAA+B,EAAE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KAAK,MAAM,KAAK,MAAM,GAAG,GAC/G;AAAA,8BAAC,cAAW,MAAM,EAAE,MAAM,KAAK,MAAM,KAAK,SAAkB,WAAW,EAAE,OAAO,GAAG;AAAA,UACnF,oBAAC,UAAK,WAAW,EAAE,QAAQ,GAAG,eAAY,QAAQ,mBAAQ;AAAA,UACzD,WAAW,QAAQ,CAAC,MAAM;AACzB,kBAAM,IAAI,MAAM,EAAE,EAAE;AACpB,gBAAI,CAAC,KAAK,EAAE,SAAS,EAAE,KAAM,QAAO,CAAC;AACrC,mBAAO,EAAE,MAAM,IAAI,CAAC,GAAG,MACrB;AAAA,cAAC;AAAA;AAAA,gBAEC,eAAY;AAAA,gBACZ,kBAAgB,EAAE;AAAA,gBAClB,eAAa,EAAE,OAAO;AAAA,gBACtB,WAAW,EAAE,IAAI;AAAA,gBACjB,OAAO,EAAE,MAAM,GAAG,EAAE,IAAI,GAAG,KAAK,KAAK,GAAG,EAAE,IAAI,GAAG,KAAK,OAAO,GAAG,EAAE,QAAQ,GAAG,KAAK,QAAQ,GAAG,EAAE,SAAS,GAAG,IAAI;AAAA,gBAC/G,SAAS,MAAM,iBAAiB,EAAE,OAAO,WAAW,OAAO,EAAE,EAAE;AAAA;AAAA,cAN1D,GAAG,EAAE,EAAE,IAAI,CAAC;AAAA,YAOnB,CACD;AAAA,UACH,CAAC;AAAA,aAjBO,EAAE,IAkBZ;AAAA,MAEJ,CAAC,IACD;AAAA,OACN;AAAA,KACF;AAEJ;","names":[]}
@@ -0,0 +1,145 @@
1
+ import * as tailwind_variants from 'tailwind-variants';
2
+ import * as React from 'react';
3
+
4
+ /** A position: longitude, latitude (GeoJSON's order, MapLibre's `LngLat`). */
5
+ type LngLat = readonly [lng: number, lat: number];
6
+
7
+ type RouteLinks = {
8
+ apple: string;
9
+ google: string;
10
+ osm: string;
11
+ waze: string;
12
+ /** Google Maps in transit mode: the only one of the five that plans buses and metro without an account. */
13
+ transit: string;
14
+ };
15
+ type RouteApp = keyof RouteLinks;
16
+ /** The apps in the order a menu shows them. */
17
+ declare const ROUTE_APPS: readonly RouteApp[];
18
+ /** One URL per navigation app for a trip to `destination` (from `origin` when known, else from where the app finds the person). */
19
+ declare function routeLinks(destination: LngLat, origin?: LngLat): RouteLinks;
20
+
21
+ declare const mapCard: tailwind_variants.TVReturnType<{
22
+ [key: string]: {
23
+ [key: string]: tailwind_variants.ClassValue | {
24
+ root?: tailwind_variants.ClassValue;
25
+ photo?: tailwind_variants.ClassValue;
26
+ title?: tailwind_variants.ClassValue;
27
+ meta?: tailwind_variants.ClassValue;
28
+ status?: tailwind_variants.ClassValue;
29
+ action?: tailwind_variants.ClassValue;
30
+ times?: tailwind_variants.ClassValue;
31
+ time?: tailwind_variants.ClassValue;
32
+ timeLabel?: tailwind_variants.ClassValue;
33
+ menu?: tailwind_variants.ClassValue;
34
+ link?: tailwind_variants.ClassValue;
35
+ };
36
+ };
37
+ } | {
38
+ [x: string]: {
39
+ [x: string]: tailwind_variants.ClassValue | {
40
+ root?: tailwind_variants.ClassValue;
41
+ photo?: tailwind_variants.ClassValue;
42
+ title?: tailwind_variants.ClassValue;
43
+ meta?: tailwind_variants.ClassValue;
44
+ status?: tailwind_variants.ClassValue;
45
+ action?: tailwind_variants.ClassValue;
46
+ times?: tailwind_variants.ClassValue;
47
+ time?: tailwind_variants.ClassValue;
48
+ timeLabel?: tailwind_variants.ClassValue;
49
+ menu?: tailwind_variants.ClassValue;
50
+ link?: tailwind_variants.ClassValue;
51
+ };
52
+ };
53
+ } | {}, {
54
+ root: string;
55
+ photo: string;
56
+ title: string;
57
+ meta: string;
58
+ status: string;
59
+ action: string;
60
+ times: string;
61
+ time: string;
62
+ timeLabel: string;
63
+ menu: string;
64
+ link: string;
65
+ }, undefined, {
66
+ [key: string]: {
67
+ [key: string]: tailwind_variants.ClassValue | {
68
+ root?: tailwind_variants.ClassValue;
69
+ photo?: tailwind_variants.ClassValue;
70
+ title?: tailwind_variants.ClassValue;
71
+ meta?: tailwind_variants.ClassValue;
72
+ status?: tailwind_variants.ClassValue;
73
+ action?: tailwind_variants.ClassValue;
74
+ times?: tailwind_variants.ClassValue;
75
+ time?: tailwind_variants.ClassValue;
76
+ timeLabel?: tailwind_variants.ClassValue;
77
+ menu?: tailwind_variants.ClassValue;
78
+ link?: tailwind_variants.ClassValue;
79
+ };
80
+ };
81
+ } | {}, {
82
+ root: string;
83
+ photo: string;
84
+ title: string;
85
+ meta: string;
86
+ status: string;
87
+ action: string;
88
+ times: string;
89
+ time: string;
90
+ timeLabel: string;
91
+ menu: string;
92
+ link: string;
93
+ }, tailwind_variants.TVReturnTypeLike<unknown, {
94
+ root: string;
95
+ photo: string;
96
+ title: string;
97
+ meta: string;
98
+ status: string;
99
+ action: string;
100
+ times: string;
101
+ time: string;
102
+ timeLabel: string;
103
+ menu: string;
104
+ link: string;
105
+ }>>;
106
+ type MapInfoCardProps = Omit<React.ComponentProps<"article">, "title"> & {
107
+ title: React.ReactNode;
108
+ /** The heading level of the title. Default 3. */
109
+ titleLevel?: 2 | 3 | 4;
110
+ /** A picture (an img or next/image); supply its alt text. Absent: no photo area. */
111
+ photo?: React.ReactNode;
112
+ /** One line under the title: category, distance, hours. */
113
+ meta?: React.ReactNode;
114
+ /** A short honest status ("Open now", "In development"). */
115
+ status?: React.ReactNode;
116
+ /** The one action (a Button or a link); the card carries no second one. */
117
+ action?: React.ReactNode;
118
+ };
119
+ /** What a place says about itself on a map: photo, title, one meta line, a status and ONE action — every field optional. */
120
+ declare function MapInfoCard({ title, titleLevel, photo, meta, status, action, className, ...props }: MapInfoCardProps): React.JSX.Element;
121
+ type RouteTime = {
122
+ label: string; /** "12 min" — formatted by the host from a real source. */
123
+ value: string;
124
+ };
125
+ type RouteCardProps = Omit<React.ComponentProps<"section">, "title"> & {
126
+ /** The destination's name. */
127
+ destination: React.ReactNode;
128
+ /** Where it is, for the links. */
129
+ position: LngLat;
130
+ /** Where the person is, when known: the links then start there. */
131
+ origin?: LngLat;
132
+ /** The heading of the links ("Directions"). */
133
+ directionsLabel: string;
134
+ /** The apps' names, translated or not ("Apple Maps", "Google Maps", "OpenStreetMap", "Waze", "Transit"). */
135
+ appLabels: Record<RouteApp, string>;
136
+ /** Honest times, computed by the host from a real source (never invented here). Absent: no row. */
137
+ times?: readonly RouteTime[];
138
+ /** The apps shown, in order. Default all five. */
139
+ apps?: readonly RouteApp[];
140
+ };
141
+ /** A destination, the times the host knows, and the « Directions » links to the person's own navigation app. */
142
+ declare function RouteCard({ destination, position, origin, directionsLabel, appLabels, times, apps, className, ...props }: RouteCardProps): React.JSX.Element;
143
+
144
+ export { MapInfoCard, ROUTE_APPS, RouteCard, mapCard, routeLinks };
145
+ export type { MapInfoCardProps, RouteApp, RouteCardProps, RouteLinks, RouteTime };
@@ -0,0 +1,74 @@
1
+ "use client";
2
+ import {
3
+ tv
4
+ } from "../chunk-NM2DEHFZ.js";
5
+
6
+ // src/map/cards/map-cards.tsx
7
+ import * as React from "react";
8
+
9
+ // src/map/cards/route-links.ts
10
+ var ROUTE_APPS = ["apple", "google", "osm", "waze", "transit"];
11
+ var at = ([lng, lat]) => `${round(lat)},${round(lng)}`;
12
+ var round = (n) => Math.round(n * 1e6) / 1e6;
13
+ function routeLinks(destination, origin) {
14
+ const to = at(destination);
15
+ const from = origin ? at(origin) : void 0;
16
+ const google = (mode) => `https://www.google.com/maps/dir/?api=1&destination=${to}${from ? `&origin=${from}` : ""}&travelmode=${mode}`;
17
+ return {
18
+ apple: `https://maps.apple.com/?daddr=${to}${from ? `&saddr=${from}` : ""}&dirflg=d`,
19
+ google: google("driving"),
20
+ osm: from ? `https://www.openstreetmap.org/directions?engine=fossgis_osrm_car&route=${from};${to}` : `https://www.openstreetmap.org/?mlat=${round(destination[1])}&mlon=${round(destination[0])}#map=16/${to.replace(",", "/")}`,
21
+ waze: `https://waze.com/ul?ll=${to}&navigate=yes`,
22
+ transit: google("transit")
23
+ };
24
+ }
25
+
26
+ // src/map/cards/map-cards.tsx
27
+ import { jsx, jsxs } from "react/jsx-runtime";
28
+ var mapCard = tv({
29
+ slots: {
30
+ root: "flex flex-col gap-2 text-fg",
31
+ photo: "aspect-[16/9] w-full overflow-hidden rounded-xl bg-surface-2 [&>img]:h-full [&>img]:w-full [&>img]:object-cover",
32
+ title: "text-base font-semibold leading-snug",
33
+ meta: "text-sm text-fg-secondary",
34
+ status: "w-fit rounded-md bg-surface-2 px-2 py-0.5 text-xs font-medium text-fg-secondary",
35
+ action: "mt-1 flex",
36
+ times: "grid grid-cols-[repeat(auto-fit,minmax(5.5rem,1fr))] gap-2 text-sm",
37
+ time: "flex flex-col rounded-lg bg-surface-2 px-2.5 py-1.5",
38
+ timeLabel: "text-xs text-fg-secondary",
39
+ menu: "flex flex-wrap gap-2",
40
+ link: "rounded-md border border-border-default px-3 py-1.5 text-sm font-medium text-fg hover:bg-surface-2 focus-visible:outline-2 focus-visible:outline-border-focus"
41
+ }
42
+ });
43
+ function MapInfoCard({ title, titleLevel = 3, photo, meta, status, action, className, ...props }) {
44
+ const s = mapCard();
45
+ const Heading = `h${titleLevel}`;
46
+ return /* @__PURE__ */ jsxs("article", { ...props, className: s.root({ className }), children: [
47
+ photo ? /* @__PURE__ */ jsx("div", { className: s.photo(), children: photo }) : null,
48
+ /* @__PURE__ */ jsx(Heading, { className: s.title(), children: title }),
49
+ meta ? /* @__PURE__ */ jsx("p", { className: s.meta(), children: meta }) : null,
50
+ status ? /* @__PURE__ */ jsx("p", { className: s.status(), children: status }) : null,
51
+ action ? /* @__PURE__ */ jsx("div", { className: s.action(), children: action }) : null
52
+ ] });
53
+ }
54
+ function RouteCard({ destination, position, origin, directionsLabel, appLabels, times, apps = ROUTE_APPS, className, ...props }) {
55
+ const s = mapCard();
56
+ const links = routeLinks(position, origin);
57
+ const id = React.useId();
58
+ return /* @__PURE__ */ jsxs("section", { ...props, "aria-labelledby": id, className: s.root({ className }), children: [
59
+ /* @__PURE__ */ jsx("h3", { id, className: s.title(), children: destination }),
60
+ times?.length ? /* @__PURE__ */ jsx("dl", { className: s.times(), children: times.map((t) => /* @__PURE__ */ jsxs("div", { className: s.time(), children: [
61
+ /* @__PURE__ */ jsx("dt", { className: s.timeLabel(), children: t.label }),
62
+ /* @__PURE__ */ jsx("dd", { children: t.value })
63
+ ] }, t.label)) }) : null,
64
+ /* @__PURE__ */ jsx("nav", { "aria-label": directionsLabel, children: /* @__PURE__ */ jsx("ul", { className: s.menu(), children: apps.map((app) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("a", { className: s.link(), href: links[app], target: "_blank", rel: "noopener noreferrer", children: appLabels[app] }) }, app)) }) })
65
+ ] });
66
+ }
67
+ export {
68
+ MapInfoCard,
69
+ ROUTE_APPS,
70
+ RouteCard,
71
+ mapCard,
72
+ routeLinks
73
+ };
74
+ //# sourceMappingURL=cards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/map/cards/map-cards.tsx","../../src/map/cards/route-links.ts"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { tv } from \"../../tv\";\nimport type { LngLat } from \"../geo\";\nimport { ROUTE_APPS, type RouteApp, routeLinks } from \"./route-links\";\n\nexport const mapCard = tv({\n slots: {\n root: \"flex flex-col gap-2 text-fg\",\n photo: \"aspect-[16/9] w-full overflow-hidden rounded-xl bg-surface-2 [&>img]:h-full [&>img]:w-full [&>img]:object-cover\",\n title: \"text-base font-semibold leading-snug\",\n meta: \"text-sm text-fg-secondary\",\n status: \"w-fit rounded-md bg-surface-2 px-2 py-0.5 text-xs font-medium text-fg-secondary\",\n action: \"mt-1 flex\",\n times: \"grid grid-cols-[repeat(auto-fit,minmax(5.5rem,1fr))] gap-2 text-sm\",\n time: \"flex flex-col rounded-lg bg-surface-2 px-2.5 py-1.5\",\n timeLabel: \"text-xs text-fg-secondary\",\n menu: \"flex flex-wrap gap-2\",\n link: \"rounded-md border border-border-default px-3 py-1.5 text-sm font-medium text-fg hover:bg-surface-2 focus-visible:outline-2 focus-visible:outline-border-focus\",\n },\n});\n\nexport type MapInfoCardProps = Omit<React.ComponentProps<\"article\">, \"title\"> & {\n title: React.ReactNode;\n /** The heading level of the title. Default 3. */\n titleLevel?: 2 | 3 | 4;\n /** A picture (an img or next/image); supply its alt text. Absent: no photo area. */\n photo?: React.ReactNode;\n /** One line under the title: category, distance, hours. */\n meta?: React.ReactNode;\n /** A short honest status (\"Open now\", \"In development\"). */\n status?: React.ReactNode;\n /** The one action (a Button or a link); the card carries no second one. */\n action?: React.ReactNode;\n};\n\n/** What a place says about itself on a map: photo, title, one meta line, a status and ONE action — every field optional. */\nexport function MapInfoCard({ title, titleLevel = 3, photo, meta, status, action, className, ...props }: MapInfoCardProps) {\n const s = mapCard();\n const Heading = `h${titleLevel}` as \"h3\";\n return (\n <article {...props} className={s.root({ className })}>\n {photo ? <div className={s.photo()}>{photo}</div> : null}\n <Heading className={s.title()}>{title}</Heading>\n {meta ? <p className={s.meta()}>{meta}</p> : null}\n {status ? <p className={s.status()}>{status}</p> : null}\n {action ? <div className={s.action()}>{action}</div> : null}\n </article>\n );\n}\n\nexport type RouteTime = { /** \"On foot\", \"By bike\" — translated. */ label: string; /** \"12 min\" — formatted by the host from a real source. */ value: string };\n\nexport type RouteCardProps = Omit<React.ComponentProps<\"section\">, \"title\"> & {\n /** The destination's name. */\n destination: React.ReactNode;\n /** Where it is, for the links. */\n position: LngLat;\n /** Where the person is, when known: the links then start there. */\n origin?: LngLat;\n /** The heading of the links (\"Directions\"). */\n directionsLabel: string;\n /** The apps' names, translated or not (\"Apple Maps\", \"Google Maps\", \"OpenStreetMap\", \"Waze\", \"Transit\"). */\n appLabels: Record<RouteApp, string>;\n /** Honest times, computed by the host from a real source (never invented here). Absent: no row. */\n times?: readonly RouteTime[];\n /** The apps shown, in order. Default all five. */\n apps?: readonly RouteApp[];\n};\n\n/** A destination, the times the host knows, and the « Directions » links to the person's own navigation app. */\nexport function RouteCard({ destination, position, origin, directionsLabel, appLabels, times, apps = ROUTE_APPS, className, ...props }: RouteCardProps) {\n const s = mapCard();\n const links = routeLinks(position, origin);\n const id = React.useId();\n return (\n <section {...props} aria-labelledby={id} className={s.root({ className })}>\n <h3 id={id} className={s.title()}>{destination}</h3>\n {times?.length ? (\n <dl className={s.times()}>\n {times.map((t) => (\n <div key={t.label} className={s.time()}>\n <dt className={s.timeLabel()}>{t.label}</dt>\n <dd>{t.value}</dd>\n </div>\n ))}\n </dl>\n ) : null}\n <nav aria-label={directionsLabel}>\n <ul className={s.menu()}>\n {apps.map((app) => (\n <li key={app}>\n <a className={s.link()} href={links[app]} target=\"_blank\" rel=\"noopener noreferrer\">\n {appLabels[app]}\n </a>\n </li>\n ))}\n </ul>\n </nav>\n </section>\n );\n}\n","// Server-safe, pure. The links that open a destination in the person's own navigation app: Apple Maps, Google Maps,\n// OpenStreetMap, Waze and public transit. No key, no request: a URL each, opened by the person.\nimport type { LngLat } from \"../geo\";\n\nexport type RouteLinks = {\n apple: string;\n google: string;\n osm: string;\n waze: string;\n /** Google Maps in transit mode: the only one of the five that plans buses and metro without an account. */\n transit: string;\n};\n\nexport type RouteApp = keyof RouteLinks;\n\n/** The apps in the order a menu shows them. */\nexport const ROUTE_APPS: readonly RouteApp[] = [\"apple\", \"google\", \"osm\", \"waze\", \"transit\"];\n\nconst at = ([lng, lat]: LngLat) => `${round(lat)},${round(lng)}`;\nconst round = (n: number) => Math.round(n * 1e6) / 1e6;\n\n/** One URL per navigation app for a trip to `destination` (from `origin` when known, else from where the app finds the person). */\nexport function routeLinks(destination: LngLat, origin?: LngLat): RouteLinks {\n const to = at(destination);\n const from = origin ? at(origin) : undefined;\n const google = (mode: string) => `https://www.google.com/maps/dir/?api=1&destination=${to}${from ? `&origin=${from}` : \"\"}&travelmode=${mode}`;\n return {\n apple: `https://maps.apple.com/?daddr=${to}${from ? `&saddr=${from}` : \"\"}&dirflg=d`,\n google: google(\"driving\"),\n osm: from\n ? `https://www.openstreetmap.org/directions?engine=fossgis_osrm_car&route=${from};${to}`\n : `https://www.openstreetmap.org/?mlat=${round(destination[1])}&mlon=${round(destination[0])}#map=16/${to.replace(\",\", \"/\")}`,\n waze: `https://waze.com/ul?ll=${to}&navigate=yes`,\n transit: google(\"transit\"),\n };\n}\n"],"mappings":";;;;;;AAEA,YAAY,WAAW;;;ACchB,IAAM,aAAkC,CAAC,SAAS,UAAU,OAAO,QAAQ,SAAS;AAE3F,IAAM,KAAK,CAAC,CAAC,KAAK,GAAG,MAAc,GAAG,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,CAAC;AAC9D,IAAM,QAAQ,CAAC,MAAc,KAAK,MAAM,IAAI,GAAG,IAAI;AAG5C,SAAS,WAAW,aAAqB,QAA6B;AAC3E,QAAM,KAAK,GAAG,WAAW;AACzB,QAAM,OAAO,SAAS,GAAG,MAAM,IAAI;AACnC,QAAM,SAAS,CAAC,SAAiB,sDAAsD,EAAE,GAAG,OAAO,WAAW,IAAI,KAAK,EAAE,eAAe,IAAI;AAC5I,SAAO;AAAA,IACL,OAAO,iCAAiC,EAAE,GAAG,OAAO,UAAU,IAAI,KAAK,EAAE;AAAA,IACzE,QAAQ,OAAO,SAAS;AAAA,IACxB,KAAK,OACD,0EAA0E,IAAI,IAAI,EAAE,KACpF,uCAAuC,MAAM,YAAY,CAAC,CAAC,CAAC,SAAS,MAAM,YAAY,CAAC,CAAC,CAAC,WAAW,GAAG,QAAQ,KAAK,GAAG,CAAC;AAAA,IAC7H,MAAM,0BAA0B,EAAE;AAAA,IAClC,SAAS,OAAO,SAAS;AAAA,EAC3B;AACF;;;ADQI,SACW,KADX;AAnCG,IAAM,UAAU,GAAG;AAAA,EACxB,OAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,IACP,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,IACN,WAAW;AAAA,IACX,MAAM;AAAA,IACN,MAAM;AAAA,EACR;AACF,CAAC;AAiBM,SAAS,YA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,eAAK,IAAI,CAAC,QACT,oBAAC,QACC,8BAAC,OAAE,WAAW,EAAE,KAAK,GAAG,MAAM,MAAM,GAAG,GAAG,QAAO,UAAS,KAAI,uBAC3D,oBAAU,GAAG,GAChB,KAHO,GAIT,CACD,GACH,GACF;AAAA,KACF;AAEJ;","names":[]}
@@ -0,0 +1,57 @@
1
+ import * as tailwind_variants from 'tailwind-variants';
2
+ import * as React from 'react';
3
+
4
+ declare const mapPin: tailwind_variants.TVReturnType<{
5
+ selected: {
6
+ true: {
7
+ root: string;
8
+ };
9
+ };
10
+ }, {
11
+ root: string;
12
+ shape: string;
13
+ glyph: string;
14
+ }, undefined, {
15
+ selected: {
16
+ true: {
17
+ root: string;
18
+ };
19
+ };
20
+ }, {
21
+ root: string;
22
+ shape: string;
23
+ glyph: string;
24
+ }, tailwind_variants.TVReturnTypeLike<{
25
+ selected: {
26
+ true: {
27
+ root: string;
28
+ };
29
+ };
30
+ }, {
31
+ root: string;
32
+ shape: string;
33
+ glyph: string;
34
+ }>>;
35
+ type MapPinShape = "drop" | "disc" | "tag";
36
+ type MapPinState = "default" | "selected" | "visited" | "closed";
37
+ type MapPinProps = {
38
+ /** `drop` (a pin, its tip on the place), `disc` (a dot with a ring) or `tag` (the Cahier's manila tag with its eyelet). Default `drop`. */
39
+ shape?: MapPinShape;
40
+ /** `default`; `selected` (larger, the ring doubled); `visited` (hollow: seen already); `closed` (greyed: not available now). */
41
+ state?: MapPinState;
42
+ /** `accent` (the product's colour) or `margin` (the notebook's red). Default `accent`. */
43
+ tone?: "accent" | "margin";
44
+ /** Its size in pixels (the width). Default 28. */
45
+ size?: number;
46
+ /** A short mark or an icon in the head of the pin ("3", an icon). */
47
+ children?: React.ReactNode;
48
+ className?: string;
49
+ };
50
+ /**
51
+ * A pin for a `Marker`'s children: three shapes, four states, drawn from the tokens (both themes). Decorative by itself —
52
+ * the `Marker` carries the label — and the state is also said by shape (hollow, struck), never by colour alone.
53
+ */
54
+ declare function MapPin({ shape, state, tone, size, children, className }: Readonly<MapPinProps>): React.JSX.Element;
55
+
56
+ export { MapPin, mapPin };
57
+ export type { MapPinProps, MapPinShape, MapPinState };