@algenium/blocks 1.21.0 → 1.23.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import * as React7 from 'react';
3
- import { createContext, useContext, useState, useCallback, useEffect, useRef, useMemo, useId } from 'react';
4
- import { ChevronsUpDown, CheckIcon, SearchIcon, Loader2, AlertTriangle, Inbox, CircleIcon, ChevronRightIcon, Monitor, Sun, Moon, Building2, Check, Plus, Languages, FlaskConical, X, Upload, Move, ZoomOut, ZoomIn, RotateCcw, RotateCw, Grid3X3, RefreshCw, XIcon, User, Pencil, Bell, CheckCheck, XCircle, CheckCircle, Info, Trash2, Clock, MapPin, Link, CalendarDays, ExternalLink, ChevronLeft, ChevronRight, Search, CheckCircle2, Link2, HelpCircle, Circle, Wifi, WifiOff, MessageSquare, FileIcon, Download, Paperclip, Send, Store, ArrowLeft, Flag, Hash, Lightbulb, Trophy, Plane, Apple, Leaf, Hand, Smile, Play, AlertCircle, VolumeX, Pause, Volume1, Volume2, Settings, PictureInPicture2, Minimize, Maximize, CreditCard, BadgeCheck, CircleCheck, CircleDollarSign, Users } from 'lucide-react';
3
+ import { createContext, useContext, useState, useCallback, useEffect, useRef, useMemo, useId, useLayoutEffect } from 'react';
4
+ import { ChevronsUpDown, CheckIcon, SearchIcon, Loader2, AlertTriangle, Inbox, CircleIcon, ChevronRightIcon, Monitor, Sun, Moon, Building2, Check, Plus, Languages, FlaskConical, X, Upload, Move, ZoomOut, ZoomIn, RotateCcw, RotateCw, Grid3X3, RefreshCw, XIcon, User, Pencil, Bell, CheckCheck, XCircle, CheckCircle, Info, Trash2, Clock, MapPin, Link, CalendarDays, ExternalLink, ChevronLeft, ChevronRight, Search, CheckCircle2, Link2, HelpCircle, Circle, Wifi, WifiOff, MessageSquare, FileIcon, Paperclip, Send, Store, ArrowLeft, Flag, Hash, Lightbulb, Trophy, Plane, Apple, Leaf, Hand, Smile, Play, AlertCircle, VolumeX, Pause, Volume1, Volume2, Settings, PictureInPicture2, Minimize, Maximize, CreditCard, PanelLeftOpen, PanelRightOpen, Maximize2, BadgeCheck, CircleCheck, CircleDollarSign, Users, Download } from 'lucide-react';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
6
  import { useTheme } from 'next-themes';
7
7
  import { AnimatePresence, motion } from 'framer-motion';
@@ -7958,6 +7958,94 @@ function useChatRoom(roomId, config, options = {}) {
7958
7958
  isInitialLoading
7959
7959
  };
7960
7960
  }
7961
+ function AuthenticatedAttachment({
7962
+ url,
7963
+ getToken,
7964
+ fileName,
7965
+ fileSize,
7966
+ mimeType,
7967
+ formatFileSize
7968
+ }) {
7969
+ const [blobUrl, setBlobUrl] = useState(null);
7970
+ const [failed, setFailed] = useState(false);
7971
+ const isImage2 = mimeType.startsWith("image/");
7972
+ useEffect(() => {
7973
+ let cancelled = false;
7974
+ let objectUrl = null;
7975
+ void (async () => {
7976
+ try {
7977
+ const jwt = await getToken();
7978
+ if (!jwt) throw new Error("No auth token");
7979
+ const res = await fetch(url, {
7980
+ headers: { Authorization: `Bearer ${jwt}` }
7981
+ });
7982
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
7983
+ const blob = await res.blob();
7984
+ if (cancelled) return;
7985
+ objectUrl = URL.createObjectURL(blob);
7986
+ setBlobUrl(objectUrl);
7987
+ } catch {
7988
+ if (!cancelled) setFailed(true);
7989
+ }
7990
+ })();
7991
+ return () => {
7992
+ cancelled = true;
7993
+ if (objectUrl) URL.revokeObjectURL(objectUrl);
7994
+ };
7995
+ }, [url, getToken]);
7996
+ if (failed) {
7997
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 rounded-lg border border-destructive/30 bg-destructive/5 px-2 py-1.5 text-xs text-destructive", children: [
7998
+ /* @__PURE__ */ jsx(FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0" }),
7999
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: fileName })
8000
+ ] });
8001
+ }
8002
+ if (!blobUrl) {
8003
+ return /* @__PURE__ */ jsx(
8004
+ "div",
8005
+ {
8006
+ className: isImage2 ? "flex h-24 w-[200px] items-center justify-center rounded-lg border bg-muted/30" : "flex items-center gap-2 rounded-lg border bg-muted/30 px-2 py-1.5 text-xs",
8007
+ children: /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin text-muted-foreground" })
8008
+ }
8009
+ );
8010
+ }
8011
+ if (isImage2) {
8012
+ return /* @__PURE__ */ jsx(
8013
+ "a",
8014
+ {
8015
+ href: blobUrl,
8016
+ target: "_blank",
8017
+ rel: "noopener noreferrer",
8018
+ className: "block max-w-[200px] overflow-hidden rounded-lg border",
8019
+ children: /* @__PURE__ */ jsx(
8020
+ "img",
8021
+ {
8022
+ src: blobUrl,
8023
+ alt: fileName,
8024
+ className: "h-auto w-full object-cover"
8025
+ }
8026
+ )
8027
+ }
8028
+ );
8029
+ }
8030
+ return /* @__PURE__ */ jsxs(
8031
+ "a",
8032
+ {
8033
+ href: blobUrl,
8034
+ download: fileName,
8035
+ target: "_blank",
8036
+ rel: "noopener noreferrer",
8037
+ className: "flex items-center gap-2 rounded-lg border bg-muted/50 px-2 py-1.5 text-xs transition-colors hover:bg-muted",
8038
+ children: [
8039
+ /* @__PURE__ */ jsx(FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" }),
8040
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
8041
+ /* @__PURE__ */ jsx("p", { className: "truncate font-medium", children: fileName }),
8042
+ /* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: formatFileSize(fileSize) })
8043
+ ] }),
8044
+ /* @__PURE__ */ jsx(Download, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" })
8045
+ ]
8046
+ }
8047
+ );
8048
+ }
7961
8049
  var roleColors = {
7962
8050
  client: "bg-blue-500/10 text-blue-600 dark:text-blue-400",
7963
8051
  seller: "bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",
@@ -8245,44 +8333,18 @@ function ChatRoomView({
8245
8333
  children: message.content
8246
8334
  }
8247
8335
  ),
8248
- message.attachments.length > 0 && /* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-col gap-1", children: message.attachments.map(
8249
- (att) => att.mimeType.startsWith("image/") ? /* @__PURE__ */ jsx(
8250
- "a",
8251
- {
8252
- href: getAttachmentUrl(att.id),
8253
- target: "_blank",
8254
- rel: "noopener noreferrer",
8255
- className: "block max-w-[200px] overflow-hidden rounded-lg border",
8256
- children: /* @__PURE__ */ jsx(
8257
- "img",
8258
- {
8259
- src: getAttachmentUrl(att.id),
8260
- alt: att.fileName,
8261
- className: "h-auto w-full object-cover",
8262
- loading: "lazy"
8263
- }
8264
- )
8265
- },
8266
- att.id
8267
- ) : /* @__PURE__ */ jsxs(
8268
- "a",
8269
- {
8270
- href: getAttachmentUrl(att.id),
8271
- target: "_blank",
8272
- rel: "noopener noreferrer",
8273
- className: "flex items-center gap-2 rounded-lg border bg-muted/50 px-2 py-1.5 text-xs transition-colors hover:bg-muted",
8274
- children: [
8275
- /* @__PURE__ */ jsx(FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" }),
8276
- /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
8277
- /* @__PURE__ */ jsx("p", { className: "truncate font-medium", children: att.fileName }),
8278
- /* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: formatFileSize(att.fileSize) })
8279
- ] }),
8280
- /* @__PURE__ */ jsx(Download, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" })
8281
- ]
8282
- },
8283
- att.id
8284
- )
8285
- ) }),
8336
+ message.attachments.length > 0 && /* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-col gap-1", children: message.attachments.map((att) => /* @__PURE__ */ jsx(
8337
+ AuthenticatedAttachment,
8338
+ {
8339
+ url: getAttachmentUrl(att.id),
8340
+ getToken: config.getToken,
8341
+ fileName: att.fileName,
8342
+ fileSize: att.fileSize,
8343
+ mimeType: att.mimeType,
8344
+ formatFileSize
8345
+ },
8346
+ att.id
8347
+ )) }),
8286
8348
  isCurrentUser && /* @__PURE__ */ jsx("div", { className: "mt-0.5 flex items-center gap-0.5 text-[10px] text-muted-foreground", children: seen ? /* @__PURE__ */ jsxs(Fragment, { children: [
8287
8349
  /* @__PURE__ */ jsx(CheckCheck, { className: "h-3 w-3 text-primary" }),
8288
8350
  /* @__PURE__ */ jsx("span", { children: labels.seen ?? "Seen" })
@@ -10866,6 +10928,26 @@ function CardInput({
10866
10928
  )
10867
10929
  ] });
10868
10930
  }
10931
+
10932
+ // src/lib/usAddress.ts
10933
+ function splitStreet(street) {
10934
+ const trimmed = street.trim();
10935
+ const m = trimmed.match(/^(\S+)\s+(.+)$/);
10936
+ if (m && /^\d/.test(m[1])) {
10937
+ return { number: m[1], name: m[2].trim() };
10938
+ }
10939
+ return { number: "", name: trimmed };
10940
+ }
10941
+ function joinStreet(streetNumber, streetName) {
10942
+ return [streetNumber, streetName].map((s) => s.trim()).filter((s) => s.length > 0).join(" ");
10943
+ }
10944
+ function sanitizeForNls(input) {
10945
+ return input.replace(/[^A-Za-z0-9 .,'#\-/]/g, " ").replace(/\s+/g, " ").trim();
10946
+ }
10947
+ function composeAddressLine1ForNls(v) {
10948
+ const line = [v.streetNumber, v.streetName, v.apt].filter((s) => typeof s === "string" && s.trim().length > 0).join(" ");
10949
+ return sanitizeForNls(line).slice(0, 40);
10950
+ }
10869
10951
  function parseInitial(value) {
10870
10952
  if (!value) {
10871
10953
  return {
@@ -10886,6 +10968,28 @@ function parseInitial(value) {
10886
10968
  country: "US"
10887
10969
  };
10888
10970
  }
10971
+ function legacyToModern(legacy) {
10972
+ return {
10973
+ street: joinStreet(legacy.streetNumber, legacy.streetName),
10974
+ street2: legacy.apt ?? "",
10975
+ city: legacy.city,
10976
+ state: legacy.state,
10977
+ zip: legacy.zipCode,
10978
+ country: "US"
10979
+ };
10980
+ }
10981
+ function toLegacy(modern) {
10982
+ const parts = splitStreet(modern.street);
10983
+ return {
10984
+ streetNumber: sanitizeForNls(parts.number),
10985
+ streetName: sanitizeForNls(parts.name),
10986
+ apt: modern.street2 ? sanitizeForNls(modern.street2) : void 0,
10987
+ city: modern.city.trim(),
10988
+ state: modern.state.trim().toUpperCase(),
10989
+ zipCode: modern.zip.replace(/\D/g, "").slice(0, 5),
10990
+ country: "US"
10991
+ };
10992
+ }
10889
10993
  function addressSig(a) {
10890
10994
  return JSON.stringify({
10891
10995
  street: a.street.trim(),
@@ -10911,14 +11015,19 @@ function USAddressInput({
10911
11015
  disabled = false,
10912
11016
  largeText = false,
10913
11017
  className,
10914
- onError
11018
+ onError,
11019
+ legacyMode = false,
11020
+ valueLegacy,
11021
+ onChangeLegacy
10915
11022
  }) {
10916
11023
  const [searchQuery, setSearchQuery] = useState("");
10917
11024
  const [showSuggestions, setShowSuggestions] = useState(false);
10918
11025
  const [suggestions, setSuggestions] = useState([]);
10919
- const [address, setAddress] = useState(
10920
- () => parseInitial(value)
10921
- );
11026
+ const [address, setAddress] = useState(() => {
11027
+ if (value != null) return parseInitial(value);
11028
+ if (valueLegacy != null) return legacyToModern(valueLegacy);
11029
+ return parseInitial(void 0);
11030
+ });
10922
11031
  const [sessionToken] = useState(
10923
11032
  () => typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`
10924
11033
  );
@@ -10940,6 +11049,22 @@ function USAddressInput({
10940
11049
  const addressRef = useRef(address);
10941
11050
  addressRef.current = address;
10942
11051
  const lastValidatedSigRef = useRef("");
11052
+ const onChangeLegacyRef = useRef(onChangeLegacy);
11053
+ onChangeLegacyRef.current = onChangeLegacy;
11054
+ const legacyModeRef = useRef(legacyMode);
11055
+ legacyModeRef.current = legacyMode;
11056
+ const emitChange = useRef((next) => {
11057
+ onChange(next);
11058
+ if (legacyModeRef.current && onChangeLegacyRef.current) {
11059
+ onChangeLegacyRef.current(toLegacy(next));
11060
+ }
11061
+ });
11062
+ emitChange.current = (next) => {
11063
+ onChange(next);
11064
+ if (legacyModeRef.current && onChangeLegacyRef.current) {
11065
+ onChangeLegacyRef.current(toLegacy(next));
11066
+ }
11067
+ };
10943
11068
  const debouncedSearch = useDebouncedValue(searchQuery, 400);
10944
11069
  const zipDigits = address.zip.replace(/\D/g, "").slice(0, 5);
10945
11070
  const debouncedZip = useDebouncedValue(zipDigits, 400);
@@ -10956,13 +11081,18 @@ function USAddressInput({
10956
11081
  return () => document.removeEventListener("mousedown", handleClickOutside);
10957
11082
  }, []);
10958
11083
  const valueSyncKey = value == null ? "" : `o:${JSON.stringify(value)}`;
11084
+ const valueLegacySyncKey = value != null || valueLegacy == null ? null : `l:${JSON.stringify(valueLegacy)}`;
10959
11085
  useEffect(() => {
10960
11086
  setAddress(parseInitial(value));
10961
11087
  }, [valueSyncKey]);
11088
+ useEffect(() => {
11089
+ if (valueLegacySyncKey == null) return;
11090
+ setAddress(legacyToModern(valueLegacy));
11091
+ }, [valueLegacySyncKey]);
10962
11092
  const handleFieldChange = (field, fieldValue) => {
10963
11093
  setAddress((prev) => {
10964
11094
  const next = field === "country" ? { ...prev, country: "US" } : { ...prev, [field]: fieldValue };
10965
- onChange(next);
11095
+ emitChange.current(next);
10966
11096
  return next;
10967
11097
  });
10968
11098
  };
@@ -11034,7 +11164,7 @@ function USAddressInput({
11034
11164
  if (cityEmpty && data.city) next.city = data.city;
11035
11165
  if (stateEmpty && data.state) next.state = data.state;
11036
11166
  next.country = "US";
11037
- onChange(next);
11167
+ emitChange.current(next);
11038
11168
  return next;
11039
11169
  });
11040
11170
  }).catch(() => {
@@ -11048,7 +11178,6 @@ function USAddressInput({
11048
11178
  debouncedZip,
11049
11179
  allowZipLookup,
11050
11180
  lookupZip,
11051
- onChange,
11052
11181
  labels.zipLookupFailed,
11053
11182
  onError
11054
11183
  ]);
@@ -11110,7 +11239,7 @@ function USAddressInput({
11110
11239
  country: "US"
11111
11240
  };
11112
11241
  setAddress(normalized);
11113
- onChange(normalized);
11242
+ emitChange.current(normalized);
11114
11243
  setShowSuggestions(false);
11115
11244
  setSearchQuery("");
11116
11245
  setUspsSuggestion(null);
@@ -11123,7 +11252,7 @@ function USAddressInput({
11123
11252
  const applyUspsSuggestion = () => {
11124
11253
  if (!uspsSuggestion) return;
11125
11254
  setAddress(uspsSuggestion);
11126
- onChange(uspsSuggestion);
11255
+ emitChange.current(uspsSuggestion);
11127
11256
  setUspsSuggestion(null);
11128
11257
  lastValidatedSigRef.current = addressSig(uspsSuggestion);
11129
11258
  setUspsVerifiedNoChange(true);
@@ -11511,6 +11640,808 @@ var FlagComponent = ({ country, countryName }) => {
11511
11640
  const Flag2 = flags[country];
11512
11641
  return /* @__PURE__ */ jsx("span", { className: "flex h-4 w-6 overflow-hidden rounded-sm bg-foreground/20 [&_svg:not([class*='size-'])]:size-full", children: Flag2 && /* @__PURE__ */ jsx(Flag2, { title: countryName }) });
11513
11642
  };
11643
+ function defaultPageOf(page, total) {
11644
+ return `${page} / ${total}`;
11645
+ }
11646
+ var DEFAULT_WORKER_MSG = "PdfViewer requires a non-empty workerSrc pointing at pdf.worker matching your project's pdfjs-dist version. Example: `new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url)`.";
11647
+ function buildGetDocumentArgs(src, documentOptions) {
11648
+ const rest = documentOptions ?? {};
11649
+ if (typeof src === "string") {
11650
+ return { url: src, ...rest };
11651
+ }
11652
+ return { data: src, ...rest };
11653
+ }
11654
+ function PdfPageCanvas({
11655
+ page,
11656
+ layout,
11657
+ scale,
11658
+ visible,
11659
+ pageClassName
11660
+ }) {
11661
+ const canvasRef = useRef(null);
11662
+ const taskRef = useRef(null);
11663
+ useEffect(() => {
11664
+ if (!visible || !canvasRef.current) {
11665
+ taskRef.current?.cancel();
11666
+ taskRef.current = null;
11667
+ const c = canvasRef.current;
11668
+ if (c) {
11669
+ const ctx2 = c.getContext("2d");
11670
+ if (ctx2) {
11671
+ ctx2.setTransform(1, 0, 0, 1, 0, 0);
11672
+ ctx2.clearRect(0, 0, c.width, c.height);
11673
+ }
11674
+ }
11675
+ return;
11676
+ }
11677
+ const canvas = canvasRef.current;
11678
+ const ctx = canvas.getContext("2d");
11679
+ if (!ctx) return;
11680
+ const viewport = page.getViewport({ scale });
11681
+ canvas.width = viewport.width;
11682
+ canvas.height = viewport.height;
11683
+ const task = page.render({
11684
+ canvasContext: ctx,
11685
+ viewport,
11686
+ canvas
11687
+ });
11688
+ taskRef.current = task;
11689
+ task.promise.catch(() => {
11690
+ });
11691
+ return () => {
11692
+ task.cancel();
11693
+ if (taskRef.current === task) {
11694
+ taskRef.current = null;
11695
+ }
11696
+ };
11697
+ }, [page, visible, scale]);
11698
+ const w = layout.widthPt * scale;
11699
+ const h = layout.heightPt * scale;
11700
+ return /* @__PURE__ */ jsx(
11701
+ "div",
11702
+ {
11703
+ className: cn("relative flex justify-center bg-muted/40", pageClassName),
11704
+ style: { width: w, height: h },
11705
+ "data-page": layout.pageNumber,
11706
+ children: visible ? /* @__PURE__ */ jsx(
11707
+ "canvas",
11708
+ {
11709
+ ref: canvasRef,
11710
+ className: "block max-h-full shadow-sm",
11711
+ "aria-hidden": "true"
11712
+ }
11713
+ ) : null
11714
+ }
11715
+ );
11716
+ }
11717
+ var PAGE_INPUT_CLASS = "h-8 w-14 rounded-md border px-2 text-sm tabular-nums shadow-sm border-neutral-300 bg-white text-neutral-950 caret-neutral-950 selection:bg-neutral-200 selection:text-neutral-950 dark:border-neutral-600 dark:bg-neutral-950 dark:text-neutral-50 dark:caret-neutral-50 dark:selection:bg-neutral-700 dark:selection:text-neutral-50";
11718
+ function touchPairDistance(touches) {
11719
+ if (touches.length < 2) return 0;
11720
+ const a = touches.item(0);
11721
+ const b = touches.item(1);
11722
+ return Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY);
11723
+ }
11724
+ function PdfThumbnailStrip({
11725
+ page,
11726
+ pageNumber,
11727
+ active,
11728
+ onPick,
11729
+ label
11730
+ }) {
11731
+ const canvasRef = useRef(null);
11732
+ useEffect(() => {
11733
+ const canvas = canvasRef.current;
11734
+ if (!canvas) return;
11735
+ const viewport = page.getViewport({ scale: 1 });
11736
+ const thumbMax = 176;
11737
+ const s = thumbMax / Math.max(viewport.width, viewport.height);
11738
+ const vp = page.getViewport({ scale: s });
11739
+ const ctx = canvas.getContext("2d");
11740
+ if (!ctx) return;
11741
+ canvas.width = vp.width;
11742
+ canvas.height = vp.height;
11743
+ const task = page.render({
11744
+ canvasContext: ctx,
11745
+ viewport: vp,
11746
+ canvas
11747
+ });
11748
+ task.promise.catch(() => {
11749
+ });
11750
+ return () => {
11751
+ task.cancel();
11752
+ };
11753
+ }, [page]);
11754
+ return /* @__PURE__ */ jsxs(
11755
+ "button",
11756
+ {
11757
+ type: "button",
11758
+ onClick: () => onPick(pageNumber),
11759
+ className: cn(
11760
+ "flex w-full flex-col items-center gap-1 rounded-md p-2 transition-colors hover:bg-white/5",
11761
+ active ? "bg-white/10" : ""
11762
+ ),
11763
+ "aria-label": label,
11764
+ "aria-current": active ? "page" : void 0,
11765
+ children: [
11766
+ /* @__PURE__ */ jsx(
11767
+ "canvas",
11768
+ {
11769
+ ref: canvasRef,
11770
+ className: "block max-w-full overflow-hidden rounded-sm bg-black",
11771
+ "aria-hidden": true
11772
+ }
11773
+ ),
11774
+ /* @__PURE__ */ jsx("span", { className: "text-[10px] tabular-nums text-neutral-400", children: pageNumber })
11775
+ ]
11776
+ }
11777
+ );
11778
+ }
11779
+ function PdfViewer({
11780
+ src,
11781
+ workerSrc,
11782
+ documentOptions,
11783
+ initialPage = 1,
11784
+ initialScale = 1,
11785
+ minScale = 0.5,
11786
+ maxScale = 4,
11787
+ scaleStep = 0.2,
11788
+ enableKeyboardShortcuts = true,
11789
+ enablePinchZoom = true,
11790
+ enableThumbnailSidebar = true,
11791
+ thumbnailSidebarDefaultOpen = true,
11792
+ labels,
11793
+ onLoad,
11794
+ onError,
11795
+ onPageChange,
11796
+ onScaleChange,
11797
+ className,
11798
+ toolbarClassName,
11799
+ pageClassName,
11800
+ toolbarEndSlot
11801
+ }) {
11802
+ const mergedLabels = labels ?? {};
11803
+ const toolbarLabel = mergedLabels.toolbar ?? "PDF controls";
11804
+ const loadingLabel = mergedLabels.loading ?? "Loading PDF\u2026";
11805
+ const workerErrorMessage = mergedLabels.workerMissing ?? DEFAULT_WORKER_MSG;
11806
+ const errorLabelFallback = mergedLabels.error ?? "Failed to load PDF";
11807
+ const toolbarId = useId();
11808
+ const pageInputId = `${toolbarId}-page`;
11809
+ const thumbnailNavId = `${toolbarId}-thumbnails`;
11810
+ const scrollRef = useRef(null);
11811
+ const observerRef = useRef(null);
11812
+ const lastReportedPage = useRef(0);
11813
+ const loadedPdfRef = useRef(null);
11814
+ const [loadError, setLoadError] = useState(null);
11815
+ const [busy, setBusy] = useState(false);
11816
+ const [layouts, setLayouts] = useState([]);
11817
+ const [pagesMap, setPagesMap] = useState(
11818
+ null
11819
+ );
11820
+ const [scale, setScale] = useState(initialScale);
11821
+ const [ratios, setRatios] = useState({});
11822
+ const [pageInput, setPageInput] = useState(String(initialPage));
11823
+ const [thumbnailSidebarOpen, setThumbnailSidebarOpen] = useState(
11824
+ thumbnailSidebarDefaultOpen
11825
+ );
11826
+ const baselineScaleRef = useRef(initialScale);
11827
+ useEffect(() => {
11828
+ baselineScaleRef.current = initialScale;
11829
+ }, [initialScale]);
11830
+ const pageOfFormatter = mergedLabels.pageOf ?? defaultPageOf;
11831
+ const resolvedGoToLabel = mergedLabels.goToPage ?? "Go to page";
11832
+ const zoomInLabel = mergedLabels.zoomIn ?? "Zoom in";
11833
+ const zoomOutLabel = mergedLabels.zoomOut ?? "Zoom out";
11834
+ const resetZoomLabel = mergedLabels.resetZoom ?? "Reset zoom";
11835
+ const fitWidthLabel = mergedLabels.fitToWidth ?? "Fit to width";
11836
+ const thumbnailSidebarLabel = mergedLabels.thumbnailSidebar ?? "Page thumbnails";
11837
+ const toggleThumbLabel = mergedLabels.toggleThumbnailSidebar ?? "Toggle page thumbnails";
11838
+ const pageThumbLabel = mergedLabels.pageThumbnail ?? ((n) => `Page ${n}, show in document`);
11839
+ const pageCount = layouts.length;
11840
+ const currentVisiblePage = useMemo(() => {
11841
+ let bestPage = 1;
11842
+ let bestRatio = -1;
11843
+ for (const layout of layouts) {
11844
+ const r2 = ratios[layout.pageNumber] ?? 0;
11845
+ if (r2 > bestRatio) {
11846
+ bestRatio = r2;
11847
+ bestPage = layout.pageNumber;
11848
+ }
11849
+ }
11850
+ return bestRatio >= 0.01 ? bestPage : 1;
11851
+ }, [layouts, ratios]);
11852
+ const clampScaleValue = useCallback(
11853
+ (v) => Math.min(maxScale, Math.max(minScale, v)),
11854
+ [minScale, maxScale]
11855
+ );
11856
+ const zoomInAct = useCallback(() => {
11857
+ setScale((prev) => {
11858
+ const c = clampScaleValue(prev + scaleStep);
11859
+ onScaleChange?.(c);
11860
+ return c;
11861
+ });
11862
+ }, [clampScaleValue, onScaleChange, scaleStep]);
11863
+ const zoomOutAct = useCallback(() => {
11864
+ setScale((prev) => {
11865
+ const c = clampScaleValue(prev - scaleStep);
11866
+ onScaleChange?.(c);
11867
+ return c;
11868
+ });
11869
+ }, [clampScaleValue, onScaleChange, scaleStep]);
11870
+ const resetZoomAct = useCallback(() => {
11871
+ const c = clampScaleValue(baselineScaleRef.current);
11872
+ setScale(c);
11873
+ onScaleChange?.(c);
11874
+ }, [clampScaleValue, onScaleChange]);
11875
+ const fitToWidthAct = useCallback(() => {
11876
+ const root = scrollRef.current;
11877
+ if (!root || layouts.length === 0) return;
11878
+ const avail = Math.max(root.clientWidth - 32, 120);
11879
+ const maxW = Math.max(...layouts.map((l) => l.widthPt), 1);
11880
+ const next = clampScaleValue(avail / maxW);
11881
+ setScale(next);
11882
+ onScaleChange?.(next);
11883
+ }, [clampScaleValue, layouts, onScaleChange]);
11884
+ useEffect(() => {
11885
+ setPageInput(String(currentVisiblePage));
11886
+ if (lastReportedPage.current !== currentVisiblePage) {
11887
+ lastReportedPage.current = currentVisiblePage;
11888
+ onPageChange?.(currentVisiblePage);
11889
+ }
11890
+ }, [currentVisiblePage, onPageChange]);
11891
+ const scrollToPage = useCallback((pageNum) => {
11892
+ const root = scrollRef.current;
11893
+ if (!root || pageNum < 1) return;
11894
+ const el = root.querySelector(`[data-page="${pageNum}"]`);
11895
+ if (el instanceof HTMLElement) {
11896
+ el.scrollIntoView({ behavior: "smooth", block: "start" });
11897
+ }
11898
+ }, []);
11899
+ useEffect(() => {
11900
+ if (!busy && pagesMap && pageCount > 0) {
11901
+ const p = Math.min(Math.max(1, initialPage), pageCount);
11902
+ requestAnimationFrame(() => scrollToPage(p));
11903
+ }
11904
+ }, [busy, pagesMap, pageCount, initialPage, scrollToPage]);
11905
+ const loadKey = useMemo(() => {
11906
+ if (typeof src === "string") return src;
11907
+ if (src instanceof ArrayBuffer) return `ab:${src.byteLength}`;
11908
+ return `ua:${src.byteLength}:${src.byteOffset}:${src.buffer.byteLength}`;
11909
+ }, [src]);
11910
+ useEffect(() => {
11911
+ let cancelled = false;
11912
+ let activeDoc = null;
11913
+ setLoadError(null);
11914
+ if (loadedPdfRef.current) {
11915
+ void loadedPdfRef.current.destroy();
11916
+ loadedPdfRef.current = null;
11917
+ }
11918
+ setLayouts([]);
11919
+ setPagesMap(null);
11920
+ setRatios({});
11921
+ const trimmedWorker = workerSrc?.trim?.() ?? "";
11922
+ if (!trimmedWorker) {
11923
+ setLoadError(workerErrorMessage);
11924
+ onError?.(new Error(workerErrorMessage));
11925
+ return () => {
11926
+ cancelled = true;
11927
+ };
11928
+ }
11929
+ void (async () => {
11930
+ try {
11931
+ setBusy(true);
11932
+ const pdfjs = await import('pdfjs-dist');
11933
+ if (cancelled) return;
11934
+ pdfjs.GlobalWorkerOptions.workerSrc = trimmedWorker;
11935
+ const loadingTask = pdfjs.getDocument(
11936
+ buildGetDocumentArgs(src, documentOptions)
11937
+ );
11938
+ activeDoc = await loadingTask.promise;
11939
+ if (cancelled) {
11940
+ void activeDoc.destroy();
11941
+ activeDoc = null;
11942
+ return;
11943
+ }
11944
+ const layoutsLocal = [];
11945
+ const mapLocal = /* @__PURE__ */ new Map();
11946
+ for (let p = 1; p <= activeDoc.numPages; p++) {
11947
+ const page = await activeDoc.getPage(p);
11948
+ mapLocal.set(p, page);
11949
+ const viewport = page.getViewport({ scale: 1 });
11950
+ layoutsLocal.push({
11951
+ pageNumber: p,
11952
+ widthPt: viewport.width,
11953
+ heightPt: viewport.height
11954
+ });
11955
+ }
11956
+ if (cancelled) {
11957
+ void activeDoc.destroy();
11958
+ activeDoc = null;
11959
+ return;
11960
+ }
11961
+ onLoad?.(activeDoc);
11962
+ loadedPdfRef.current = activeDoc;
11963
+ setLayouts(layoutsLocal);
11964
+ setPagesMap(mapLocal);
11965
+ activeDoc = null;
11966
+ } catch (e) {
11967
+ const err = e instanceof Error ? e : new Error(String(e));
11968
+ if (!cancelled) {
11969
+ setLoadError(errorLabelFallback);
11970
+ onError?.(err);
11971
+ }
11972
+ if (activeDoc) {
11973
+ void activeDoc.destroy();
11974
+ activeDoc = null;
11975
+ }
11976
+ } finally {
11977
+ if (!cancelled) setBusy(false);
11978
+ }
11979
+ })();
11980
+ return () => {
11981
+ cancelled = true;
11982
+ if (observerRef.current) {
11983
+ observerRef.current.disconnect();
11984
+ observerRef.current = null;
11985
+ }
11986
+ if (activeDoc) {
11987
+ void activeDoc.destroy();
11988
+ }
11989
+ if (loadedPdfRef.current) {
11990
+ void loadedPdfRef.current.destroy();
11991
+ loadedPdfRef.current = null;
11992
+ }
11993
+ };
11994
+ }, [workerSrc, loadKey, documentOptions]);
11995
+ useEffect(() => {
11996
+ setScale(clampScaleValue(initialScale));
11997
+ }, [initialScale, clampScaleValue]);
11998
+ useEffect(() => {
11999
+ const el = scrollRef.current;
12000
+ if (!el || !enablePinchZoom) return;
12001
+ let pinchDist = 0;
12002
+ const onWheel = (e) => {
12003
+ if (!e.ctrlKey) return;
12004
+ e.preventDefault();
12005
+ const delta = -e.deltaY;
12006
+ const factor = Math.exp(delta * 2e-3);
12007
+ setScale((prev) => {
12008
+ const c = clampScaleValue(prev * factor);
12009
+ onScaleChange?.(c);
12010
+ return c;
12011
+ });
12012
+ };
12013
+ const onTouchStart = (e) => {
12014
+ if (e.touches.length === 2) {
12015
+ pinchDist = touchPairDistance(e.touches);
12016
+ }
12017
+ };
12018
+ const onTouchMove = (e) => {
12019
+ if (e.touches.length !== 2 || pinchDist <= 0) return;
12020
+ e.preventDefault();
12021
+ const d = touchPairDistance(e.touches);
12022
+ const ratio = d / pinchDist;
12023
+ pinchDist = d;
12024
+ setScale((prev) => {
12025
+ const c = clampScaleValue(prev * ratio);
12026
+ onScaleChange?.(c);
12027
+ return c;
12028
+ });
12029
+ };
12030
+ const endPinch = (e) => {
12031
+ if (e.touches.length < 2) pinchDist = 0;
12032
+ };
12033
+ el.addEventListener("wheel", onWheel, { passive: false });
12034
+ el.addEventListener("touchstart", onTouchStart, { passive: true });
12035
+ el.addEventListener("touchmove", onTouchMove, { passive: false });
12036
+ el.addEventListener("touchend", endPinch);
12037
+ el.addEventListener("touchcancel", endPinch);
12038
+ return () => {
12039
+ el.removeEventListener("wheel", onWheel);
12040
+ el.removeEventListener("touchstart", onTouchStart);
12041
+ el.removeEventListener("touchmove", onTouchMove);
12042
+ el.removeEventListener("touchend", endPinch);
12043
+ el.removeEventListener("touchcancel", endPinch);
12044
+ };
12045
+ }, [enablePinchZoom, clampScaleValue, onScaleChange]);
12046
+ useEffect(() => {
12047
+ if (layouts.length === 0) return;
12048
+ const frame = requestAnimationFrame(() => {
12049
+ const root = scrollRef.current;
12050
+ if (!root) return;
12051
+ if (observerRef.current) {
12052
+ observerRef.current.disconnect();
12053
+ }
12054
+ const io = new IntersectionObserver(
12055
+ (entries) => {
12056
+ setRatios((prev) => {
12057
+ const next = { ...prev };
12058
+ for (const e of entries) {
12059
+ const tgt = e.target;
12060
+ const p = Number(tgt.dataset.page);
12061
+ if (Number.isFinite(p)) next[p] = e.intersectionRatio;
12062
+ }
12063
+ return next;
12064
+ });
12065
+ },
12066
+ {
12067
+ root,
12068
+ rootMargin: "200px 0px",
12069
+ threshold: [0, 0.05, 0.25, 0.5, 0.75, 1]
12070
+ }
12071
+ );
12072
+ observerRef.current = io;
12073
+ root.querySelectorAll("[data-page]").forEach((el) => io.observe(el));
12074
+ });
12075
+ return () => {
12076
+ cancelAnimationFrame(frame);
12077
+ if (observerRef.current) {
12078
+ observerRef.current.disconnect();
12079
+ observerRef.current = null;
12080
+ }
12081
+ };
12082
+ }, [layouts]);
12083
+ const handleSubmitPage = useCallback(() => {
12084
+ const n = Number.parseInt(pageInput, 10);
12085
+ if (!Number.isFinite(n) || pageCount === 0) return;
12086
+ const clamped = Math.min(Math.max(1, n), pageCount);
12087
+ scrollToPage(clamped);
12088
+ setPageInput(String(clamped));
12089
+ }, [pageInput, pageCount, scrollToPage]);
12090
+ const handleKeyDown = useCallback(
12091
+ (e) => {
12092
+ if (!enableKeyboardShortcuts) return;
12093
+ if (e.target !== e.currentTarget && e.target instanceof HTMLInputElement) {
12094
+ return;
12095
+ }
12096
+ let handled = false;
12097
+ switch (e.key) {
12098
+ case "PageDown": {
12099
+ scrollToPage(Math.min(pageCount || 1, currentVisiblePage + 1));
12100
+ handled = true;
12101
+ break;
12102
+ }
12103
+ case "PageUp": {
12104
+ scrollToPage(Math.max(1, currentVisiblePage - 1));
12105
+ handled = true;
12106
+ break;
12107
+ }
12108
+ case "Home": {
12109
+ scrollToPage(1);
12110
+ handled = true;
12111
+ break;
12112
+ }
12113
+ case "End": {
12114
+ if (pageCount) scrollToPage(pageCount);
12115
+ handled = true;
12116
+ break;
12117
+ }
12118
+ case "+":
12119
+ case "=": {
12120
+ zoomInAct();
12121
+ handled = true;
12122
+ break;
12123
+ }
12124
+ case "-":
12125
+ case "_": {
12126
+ zoomOutAct();
12127
+ handled = true;
12128
+ break;
12129
+ }
12130
+ case "0": {
12131
+ resetZoomAct();
12132
+ handled = true;
12133
+ break;
12134
+ }
12135
+ }
12136
+ if (handled) {
12137
+ e.preventDefault();
12138
+ e.stopPropagation();
12139
+ }
12140
+ },
12141
+ [
12142
+ enableKeyboardShortcuts,
12143
+ pageCount,
12144
+ currentVisiblePage,
12145
+ scrollToPage,
12146
+ zoomInAct,
12147
+ zoomOutAct,
12148
+ resetZoomAct
12149
+ ]
12150
+ );
12151
+ const thumbnailsRailEligible = enableThumbnailSidebar && !busy && pagesMap !== null && pageCount > 0;
12152
+ if (loadError) {
12153
+ return /* @__PURE__ */ jsx(
12154
+ "div",
12155
+ {
12156
+ className: cn("rounded-md border border-destructive/50 p-4", className),
12157
+ role: "alert",
12158
+ children: /* @__PURE__ */ jsx("p", { className: "text-destructive text-sm", children: loadError })
12159
+ }
12160
+ );
12161
+ }
12162
+ return /* @__PURE__ */ jsxs(
12163
+ "div",
12164
+ {
12165
+ className: cn(
12166
+ "flex min-h-0 flex-col overflow-hidden rounded-md border",
12167
+ className
12168
+ ),
12169
+ children: [
12170
+ /* @__PURE__ */ jsxs(
12171
+ "div",
12172
+ {
12173
+ id: toolbarId,
12174
+ role: "toolbar",
12175
+ "aria-label": toolbarLabel,
12176
+ className: cn(
12177
+ "sticky top-0 z-10 flex shrink-0 flex-wrap items-center gap-2 border-b bg-background/95 px-2 py-2 backdrop-blur supports-[backdrop-filter]:bg-background/80",
12178
+ toolbarClassName
12179
+ ),
12180
+ children: [
12181
+ thumbnailsRailEligible ? /* @__PURE__ */ jsx(
12182
+ Button,
12183
+ {
12184
+ type: "button",
12185
+ variant: "outline",
12186
+ size: "icon-sm",
12187
+ className: "hidden md:inline-flex",
12188
+ onClick: () => setThumbnailSidebarOpen((v) => !v),
12189
+ "aria-label": toggleThumbLabel,
12190
+ "aria-expanded": thumbnailSidebarOpen,
12191
+ "aria-controls": thumbnailNavId,
12192
+ children: thumbnailSidebarOpen ? /* @__PURE__ */ jsx(PanelLeftOpen, { className: "size-4", "aria-hidden": true }) : /* @__PURE__ */ jsx(PanelRightOpen, { className: "size-4", "aria-hidden": true })
12193
+ }
12194
+ ) : null,
12195
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs tabular-nums sm:text-sm", children: busy || pagesMap === null ? "\u2014" : pageOfFormatter(currentVisiblePage, pageCount) }),
12196
+ /* @__PURE__ */ jsx("label", { htmlFor: pageInputId, className: "sr-only", children: resolvedGoToLabel }),
12197
+ /* @__PURE__ */ jsx(
12198
+ "input",
12199
+ {
12200
+ id: pageInputId,
12201
+ type: "number",
12202
+ min: 1,
12203
+ max: Math.max(pageCount, 1),
12204
+ disabled: busy || pageCount === 0,
12205
+ className: PAGE_INPUT_CLASS,
12206
+ "aria-label": resolvedGoToLabel,
12207
+ value: pageInput,
12208
+ onChange: (ev) => setPageInput(ev.target.value),
12209
+ onKeyDown: (ev) => {
12210
+ if (ev.key === "Enter") {
12211
+ ev.preventDefault();
12212
+ handleSubmitPage();
12213
+ }
12214
+ }
12215
+ }
12216
+ ),
12217
+ /* @__PURE__ */ jsx(
12218
+ Button,
12219
+ {
12220
+ type: "button",
12221
+ variant: "outline",
12222
+ size: "icon-sm",
12223
+ onClick: zoomOutAct,
12224
+ disabled: busy || scale <= minScale,
12225
+ "aria-label": zoomOutLabel,
12226
+ children: /* @__PURE__ */ jsx(ZoomOut, { "aria-hidden": true })
12227
+ }
12228
+ ),
12229
+ /* @__PURE__ */ jsx(
12230
+ Button,
12231
+ {
12232
+ type: "button",
12233
+ variant: "outline",
12234
+ size: "icon-sm",
12235
+ onClick: zoomInAct,
12236
+ disabled: busy || scale >= maxScale,
12237
+ "aria-label": zoomInLabel,
12238
+ children: /* @__PURE__ */ jsx(ZoomIn, { "aria-hidden": true })
12239
+ }
12240
+ ),
12241
+ /* @__PURE__ */ jsx(
12242
+ Button,
12243
+ {
12244
+ type: "button",
12245
+ variant: "outline",
12246
+ size: "icon-sm",
12247
+ onClick: resetZoomAct,
12248
+ disabled: busy,
12249
+ "aria-label": resetZoomLabel,
12250
+ children: /* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": true })
12251
+ }
12252
+ ),
12253
+ /* @__PURE__ */ jsx(
12254
+ Button,
12255
+ {
12256
+ type: "button",
12257
+ variant: "outline",
12258
+ size: "icon-sm",
12259
+ onClick: fitToWidthAct,
12260
+ disabled: busy || pageCount === 0,
12261
+ "aria-label": fitWidthLabel,
12262
+ children: /* @__PURE__ */ jsx(Maximize2, { "aria-hidden": true })
12263
+ }
12264
+ ),
12265
+ toolbarEndSlot
12266
+ ]
12267
+ }
12268
+ ),
12269
+ /* @__PURE__ */ jsxs("div", { className: "flex min-h-0 flex-1 overflow-hidden", children: [
12270
+ thumbnailsRailEligible && thumbnailSidebarOpen ? /* @__PURE__ */ jsx(
12271
+ "nav",
12272
+ {
12273
+ id: thumbnailNavId,
12274
+ className: "hidden w-[220px] shrink-0 flex-col overflow-y-auto border-r border-neutral-900 bg-black py-3 pl-3 pr-2 md:flex",
12275
+ "aria-label": thumbnailSidebarLabel,
12276
+ children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: layouts.map((layout) => {
12277
+ const pg = pagesMap.get(layout.pageNumber);
12278
+ return pg ? /* @__PURE__ */ jsx(
12279
+ PdfThumbnailStrip,
12280
+ {
12281
+ page: pg,
12282
+ pageNumber: layout.pageNumber,
12283
+ active: layout.pageNumber === currentVisiblePage,
12284
+ onPick: scrollToPage,
12285
+ label: pageThumbLabel(layout.pageNumber)
12286
+ },
12287
+ `thumb-${layout.pageNumber}`
12288
+ ) : null;
12289
+ }) })
12290
+ }
12291
+ ) : null,
12292
+ /* @__PURE__ */ jsx(
12293
+ "div",
12294
+ {
12295
+ ref: scrollRef,
12296
+ tabIndex: 0,
12297
+ onKeyDown: handleKeyDown,
12298
+ className: "relative min-h-[240px] min-w-0 flex-1 overflow-auto outline-none focus-visible:ring-2 focus-visible:ring-ring",
12299
+ "aria-busy": busy,
12300
+ "aria-label": busy ? loadingLabel : "PDF pages",
12301
+ children: busy || pagesMap === null ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground p-6 text-sm", children: loadingLabel }) : /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center gap-4 pb-8 pt-2", children: layouts.map((layout) => {
12302
+ const pg = pagesMap.get(layout.pageNumber);
12303
+ const visible = (ratios[layout.pageNumber] ?? 0) >= 1e-3;
12304
+ return pg ? /* @__PURE__ */ jsx(
12305
+ PdfPageCanvas,
12306
+ {
12307
+ page: pg,
12308
+ layout,
12309
+ scale,
12310
+ visible,
12311
+ pageClassName
12312
+ },
12313
+ layout.pageNumber
12314
+ ) : null;
12315
+ }) })
12316
+ }
12317
+ )
12318
+ ] })
12319
+ ]
12320
+ }
12321
+ );
12322
+ }
12323
+ function usePdfViewerDialogScrollLock(active) {
12324
+ useLayoutEffect(() => {
12325
+ if (!active || typeof document === "undefined") return;
12326
+ const html = document.documentElement;
12327
+ const body = document.body;
12328
+ const scrollRoots = [
12329
+ ...document.querySelectorAll("[data-scroll-lock-root]")
12330
+ ];
12331
+ const scrollTopSnapshot = scrollRoots.map((el) => ({
12332
+ el,
12333
+ scrollTop: el.scrollTop
12334
+ }));
12335
+ const targets = /* @__PURE__ */ new Set([html, body, ...scrollRoots]);
12336
+ const snapshot = [...targets].map((el) => ({
12337
+ el,
12338
+ overflow: el.style.overflow,
12339
+ overscrollBehavior: el.style.overscrollBehavior
12340
+ }));
12341
+ const windowScrollY = window.scrollY;
12342
+ for (const el of targets) {
12343
+ el.style.overflow = "hidden";
12344
+ el.style.overscrollBehavior = "none";
12345
+ }
12346
+ const dialogSurfaceSelector = '[data-slot="dialog-content"]';
12347
+ const shouldAllowEventTarget = (target) => target instanceof Element && Boolean(target.closest(dialogSurfaceSelector));
12348
+ const onWheel = (e) => {
12349
+ if (shouldAllowEventTarget(e.target)) return;
12350
+ e.preventDefault();
12351
+ };
12352
+ const onTouchMove = (e) => {
12353
+ if (shouldAllowEventTarget(e.target)) return;
12354
+ e.preventDefault();
12355
+ };
12356
+ window.addEventListener("wheel", onWheel, {
12357
+ capture: true,
12358
+ passive: false
12359
+ });
12360
+ window.addEventListener("touchmove", onTouchMove, {
12361
+ capture: true,
12362
+ passive: false
12363
+ });
12364
+ return () => {
12365
+ window.removeEventListener("wheel", onWheel, { capture: true });
12366
+ window.removeEventListener("touchmove", onTouchMove, {
12367
+ capture: true
12368
+ });
12369
+ for (const { el, overflow, overscrollBehavior } of snapshot) {
12370
+ el.style.overflow = overflow;
12371
+ el.style.overscrollBehavior = overscrollBehavior;
12372
+ }
12373
+ for (const { el, scrollTop } of scrollTopSnapshot) {
12374
+ el.scrollTop = scrollTop;
12375
+ }
12376
+ window.scrollTo(0, windowScrollY);
12377
+ };
12378
+ }, [active]);
12379
+ }
12380
+ var fullscreenDialogContentClass = "!max-w-none !w-screen !h-screen !p-0 !border-0 !bg-black/95 !rounded-none !top-0 !left-0 !translate-x-0 !translate-y-0 !gap-0 !shadow-none !flex !flex-col data-[state=open]:!zoom-in-100 data-[state=closed]:!zoom-out-100";
12381
+ function PdfViewerDialog({
12382
+ open,
12383
+ onOpenChange,
12384
+ src,
12385
+ workerSrc,
12386
+ documentOptions,
12387
+ trigger,
12388
+ title,
12389
+ labels,
12390
+ forwardedProps
12391
+ }) {
12392
+ const closeLabel = labels?.close ?? "Close";
12393
+ const dialogTitle = labels?.dialogTitle ?? title ?? "PDF document";
12394
+ const dialogDescription = labels?.dialogDescription ?? "Document viewer with zoom and page navigation.";
12395
+ usePdfViewerDialogScrollLock(open);
12396
+ const {
12397
+ className: forwardedClassName,
12398
+ toolbarClassName: forwardedToolbarClassName,
12399
+ ...restForwarded
12400
+ } = forwardedProps ?? {};
12401
+ return /* @__PURE__ */ jsxs(Dialog, { open, onOpenChange, children: [
12402
+ trigger ? /* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: trigger }) : null,
12403
+ /* @__PURE__ */ jsxs(
12404
+ DialogContent,
12405
+ {
12406
+ className: fullscreenDialogContentClass,
12407
+ showCloseButton: false,
12408
+ children: [
12409
+ /* @__PURE__ */ jsx(DialogTitle, { className: "sr-only", children: dialogTitle }),
12410
+ /* @__PURE__ */ jsx(DialogDescription, { className: "sr-only", children: dialogDescription }),
12411
+ /* @__PURE__ */ jsx(
12412
+ PdfViewer,
12413
+ {
12414
+ ...restForwarded,
12415
+ src,
12416
+ workerSrc,
12417
+ documentOptions,
12418
+ className: cn(
12419
+ "min-h-0 flex-1 rounded-none border-0 bg-transparent text-white",
12420
+ forwardedClassName
12421
+ ),
12422
+ toolbarClassName: cn(
12423
+ "border-white/10 bg-black/80 text-white backdrop-blur",
12424
+ forwardedToolbarClassName
12425
+ ),
12426
+ toolbarEndSlot: /* @__PURE__ */ jsx(
12427
+ Button,
12428
+ {
12429
+ type: "button",
12430
+ variant: "ghost",
12431
+ size: "icon-sm",
12432
+ className: "ml-auto text-white hover:bg-white/10 hover:text-white",
12433
+ onClick: () => onOpenChange(false),
12434
+ "aria-label": closeLabel,
12435
+ children: /* @__PURE__ */ jsx(X, { className: "size-5", "aria-hidden": true })
12436
+ }
12437
+ )
12438
+ }
12439
+ )
12440
+ ]
12441
+ }
12442
+ )
12443
+ ] });
12444
+ }
11514
12445
 
11515
12446
  // src/data/mexicoStates.ts
11516
12447
  var MEXICO_STATES = [
@@ -11691,6 +12622,6 @@ function VerifiedProfessionalBadge({
11691
12622
  );
11692
12623
  }
11693
12624
 
11694
- export { AvatarEditor, AvatarEditorDialog, BLOCKS_DATA_ENVIRONMENTS, Button, CalendarContext, CalendarSubscribeButton, CalendarView, CalendarWidget, CardInput, ChatRoomView, ChatSidebar, ChatSidebarContext, ChatSidebarProvider, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EmojiPicker, EmojiPickerPopover, EmptyState, EnvironmentBanner, EnvironmentContext, EnvironmentDot, EnvironmentMiniBadge, EnvironmentSwitcher, ErrorState, EventDialog, EventRsvpBadge, LanguageContext, LanguageSwitcher, LoadingState, MEXICO_STATES, MEXICO_STATE_PATHS, MexicoMap, MiniCalendar, NotificationsContext, NotificationsWidget, OrgSwitcher, PhoneInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, ScrollArea, ScrollBar, SearchCommand, Slider, ThemeSwitcher, Toggle, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, USAddressInput, UpcomingEvents, VerifiedProfessionalBadge, VideoPlayer, buttonVariants, cn, createLiveHlsConfig, createVodHlsConfig, defaultLanguages, describePlaybackError, fuzzyMatch, getEnvironmentDotClass, getEnvironmentLabel, isBlocksDataEnvironment, normalizeEmojiQuery, shouldRetryLiveEdge404, toggleVariants, useCalendarContext, useChatRoom, useChatSidebar, useDebouncedValue, useDebouncedValueStrict, useEnvironmentContext, useHlsPlayback, useLanguageContext, useNotificationsContext, usePlaybackStats, useSearchHotkey };
12625
+ export { AvatarEditor, AvatarEditorDialog, BLOCKS_DATA_ENVIRONMENTS, Button, CalendarContext, CalendarSubscribeButton, CalendarView, CalendarWidget, CardInput, ChatRoomView, ChatSidebar, ChatSidebarContext, ChatSidebarProvider, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EmojiPicker, EmojiPickerPopover, EmptyState, EnvironmentBanner, EnvironmentContext, EnvironmentDot, EnvironmentMiniBadge, EnvironmentSwitcher, ErrorState, EventDialog, EventRsvpBadge, LanguageContext, LanguageSwitcher, LoadingState, MEXICO_STATES, MEXICO_STATE_PATHS, MexicoMap, MiniCalendar, NotificationsContext, NotificationsWidget, OrgSwitcher, PdfViewer, PdfViewerDialog, PhoneInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, ScrollArea, ScrollBar, SearchCommand, Slider, ThemeSwitcher, Toggle, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, USAddressInput, UpcomingEvents, VerifiedProfessionalBadge, VideoPlayer, buttonVariants, cn, composeAddressLine1ForNls, createLiveHlsConfig, createVodHlsConfig, defaultLanguages, describePlaybackError, fuzzyMatch, getEnvironmentDotClass, getEnvironmentLabel, isBlocksDataEnvironment, joinStreet, normalizeEmojiQuery, sanitizeForNls, shouldRetryLiveEdge404, splitStreet, toggleVariants, useCalendarContext, useChatRoom, useChatSidebar, useDebouncedValue, useDebouncedValueStrict, useEnvironmentContext, useHlsPlayback, useLanguageContext, useNotificationsContext, usePlaybackStats, useSearchHotkey };
11695
12626
  //# sourceMappingURL=index.js.map
11696
12627
  //# sourceMappingURL=index.js.map