@algenium/blocks 1.7.0-rc.7 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import * as React2 from 'react';
2
- import { createContext, useContext, useState, useCallback, useEffect, useRef, useMemo, useId, useLayoutEffect } from 'react';
2
+ import { createContext, useContext, useState, useCallback, useEffect, useRef, useMemo, useId } from 'react';
3
3
  import { useTheme } from 'next-themes';
4
- import { CheckIcon, CircleIcon, ChevronRightIcon, Monitor, Sun, Moon, Languages, FlaskConical, X, Upload, Move, ZoomOut, ZoomIn, RotateCcw, RotateCw, Grid3X3, RefreshCw, XIcon, User, Pencil, Check, Loader2, Bell, CheckCheck, XCircle, AlertTriangle, CheckCircle, Info, Trash2, Clock, MapPin, Link, CalendarDays, ExternalLink, ChevronLeft, ChevronRight, Plus, HelpCircle, MessageSquare, Wifi, WifiOff, FileIcon, Download, Paperclip, Send, ArrowLeft, CreditCard, Search, CheckCircle2, PanelLeftOpen, PanelRightOpen, Maximize2 } from 'lucide-react';
4
+ import { CheckIcon, CircleIcon, ChevronRightIcon, Monitor, Sun, Moon, Languages, FlaskConical, X, Upload, Move, ZoomOut, ZoomIn, RotateCcw, RotateCw, Grid3X3, RefreshCw, XIcon, User, Pencil, Check, Loader2, Bell, CheckCheck, XCircle, AlertTriangle, CheckCircle, Info, Trash2, Clock, MapPin, Link, CalendarDays, ExternalLink, ChevronLeft, ChevronRight, Plus, HelpCircle, MessageSquare, Wifi, WifiOff, FileIcon, Download, Paperclip, Send, ArrowLeft, CreditCard, Search, CheckCircle2 } from 'lucide-react';
5
5
  import { AnimatePresence, motion } from 'framer-motion';
6
6
  import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
7
7
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
8
  import { Slot } from '@radix-ui/react-slot';
9
- import * as TooltipPrimitive from '@radix-ui/react-tooltip';
10
9
  import * as SliderPrimitive from '@radix-ui/react-slider';
11
10
  import * as TogglePrimitive from '@radix-ui/react-toggle';
12
11
  import * as DialogPrimitive from '@radix-ui/react-dialog';
13
12
  import { Drawer as Drawer$1 } from 'vaul';
14
13
  import * as PopoverPrimitive from '@radix-ui/react-popover';
15
14
  import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
15
+ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
16
16
  import { startOfMonth, endOfMonth, eachDayOfInterval, endOfWeek, startOfWeek, format, isSameDay, subMonths, addMonths } from 'date-fns';
17
17
  import { DayPicker } from 'react-day-picker';
18
18
  import valid from 'card-validator';
@@ -3084,6 +3084,11 @@ var twMerge = /* @__PURE__ */ createTailwindMerge(getDefaultConfig);
3084
3084
  function cn(...inputs) {
3085
3085
  return twMerge(clsx(inputs));
3086
3086
  }
3087
+ var miniMenuContentClassName = "max-h-none overflow-x-visible overflow-y-visible";
3088
+ var miniMenuContentDefaults = {
3089
+ sideOffset: 8,
3090
+ collisionPadding: 12
3091
+ };
3087
3092
  function DropdownMenu({
3088
3093
  ...props
3089
3094
  }) {
@@ -3382,52 +3387,6 @@ function Button({
3382
3387
  }
3383
3388
  );
3384
3389
  }
3385
- function TooltipProvider({
3386
- delayDuration = 0,
3387
- ...props
3388
- }) {
3389
- return /* @__PURE__ */ jsx(
3390
- TooltipPrimitive.Provider,
3391
- {
3392
- "data-slot": "tooltip-provider",
3393
- delayDuration,
3394
- ...props
3395
- }
3396
- );
3397
- }
3398
- function Tooltip({
3399
- ...props
3400
- }) {
3401
- return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(TooltipPrimitive.Root, { "data-slot": "tooltip", ...props }) });
3402
- }
3403
- function TooltipTrigger({
3404
- ...props
3405
- }) {
3406
- return /* @__PURE__ */ jsx(TooltipPrimitive.Trigger, { "data-slot": "tooltip-trigger", ...props });
3407
- }
3408
- function TooltipContent({
3409
- className,
3410
- sideOffset = 0,
3411
- children,
3412
- ...props
3413
- }) {
3414
- return /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
3415
- TooltipPrimitive.Content,
3416
- {
3417
- "data-slot": "tooltip-content",
3418
- sideOffset,
3419
- className: cn(
3420
- "bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
3421
- className
3422
- ),
3423
- ...props,
3424
- children: [
3425
- children,
3426
- /* @__PURE__ */ jsx(TooltipPrimitive.Arrow, { className: "bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" })
3427
- ]
3428
- }
3429
- ) });
3430
- }
3431
3390
  var defaultLabels = {
3432
3391
  theme: "Theme",
3433
3392
  system: "System",
@@ -3471,11 +3430,8 @@ function ThemeSwitcher({
3471
3430
  size = "sm",
3472
3431
  shape = "rounded",
3473
3432
  variant = "default",
3474
- align = "center",
3475
- side = "top",
3476
- tooltipSide = "bottom",
3477
- tooltipAlign = "center",
3478
- tooltipSideOffset = 8,
3433
+ align = "end",
3434
+ side = "bottom",
3479
3435
  labels: userLabels
3480
3436
  }) {
3481
3437
  const { theme, setTheme } = useTheme();
@@ -3509,43 +3465,42 @@ function ThemeSwitcher({
3509
3465
  const CurrentIcon = themes.find((t) => t.key === currentTheme)?.icon || Monitor;
3510
3466
  if (variant === "mini") {
3511
3467
  return /* @__PURE__ */ jsxs(DropdownMenu, { modal: false, children: [
3512
- /* @__PURE__ */ jsxs(Tooltip, { children: [
3513
- /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
3514
- Button,
3515
- {
3516
- "data-testid": "theme-switcher",
3517
- variant: "ghost",
3518
- size: "icon",
3519
- "aria-label": labels.theme,
3520
- className: cn(sizes.buttonMini, shapeClass, className),
3521
- children: /* @__PURE__ */ jsx(CurrentIcon, { className: sizes.iconMini })
3522
- }
3523
- ) }) }),
3524
- /* @__PURE__ */ jsx(
3525
- TooltipContent,
3526
- {
3527
- side: tooltipSide,
3528
- align: tooltipAlign,
3529
- sideOffset: tooltipSideOffset,
3530
- children: labels.theme
3531
- }
3532
- )
3533
- ] }),
3534
- /* @__PURE__ */ jsx(DropdownMenuContent, { side, align, sideOffset: 8, children: themes.map(({ key, icon: Icon }) => /* @__PURE__ */ jsxs(
3535
- DropdownMenuItem,
3468
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
3469
+ Button,
3536
3470
  {
3537
- onClick: () => handleThemeClick(key),
3538
- className: cn(
3539
- "gap-2 cursor-pointer",
3540
- currentTheme === key && "bg-accent text-accent-foreground [&_svg]:text-accent-foreground"
3541
- ),
3542
- children: [
3543
- /* @__PURE__ */ jsx(Icon, { className: "h-4 w-4" }),
3544
- /* @__PURE__ */ jsx("span", { children: labels[key] })
3545
- ]
3546
- },
3547
- key
3548
- )) })
3471
+ "data-testid": "theme-switcher",
3472
+ variant: "ghost",
3473
+ size: "icon",
3474
+ "aria-label": labels.theme,
3475
+ className: cn(sizes.buttonMini, shapeClass, className),
3476
+ children: /* @__PURE__ */ jsx(CurrentIcon, { className: sizes.iconMini })
3477
+ }
3478
+ ) }),
3479
+ /* @__PURE__ */ jsx(
3480
+ DropdownMenuContent,
3481
+ {
3482
+ side,
3483
+ align,
3484
+ sideOffset: miniMenuContentDefaults.sideOffset,
3485
+ collisionPadding: miniMenuContentDefaults.collisionPadding,
3486
+ className: miniMenuContentClassName,
3487
+ children: themes.map(({ key, icon: Icon }) => /* @__PURE__ */ jsxs(
3488
+ DropdownMenuItem,
3489
+ {
3490
+ onClick: () => handleThemeClick(key),
3491
+ className: cn(
3492
+ "gap-2 cursor-pointer",
3493
+ currentTheme === key && "bg-accent text-accent-foreground [&_svg]:text-accent-foreground"
3494
+ ),
3495
+ children: [
3496
+ /* @__PURE__ */ jsx(Icon, { className: "h-4 w-4" }),
3497
+ /* @__PURE__ */ jsx("span", { children: labels[key] })
3498
+ ]
3499
+ },
3500
+ key
3501
+ ))
3502
+ }
3503
+ )
3549
3504
  ] });
3550
3505
  }
3551
3506
  return /* @__PURE__ */ jsx(
@@ -3639,11 +3594,8 @@ function LanguageSwitcher({
3639
3594
  shape = "rounded",
3640
3595
  variant = "default",
3641
3596
  showIcon = true,
3642
- align = "center",
3643
- side = "top",
3644
- tooltipSide = "bottom",
3645
- tooltipAlign = "center",
3646
- tooltipSideOffset = 8
3597
+ align = "end",
3598
+ side = "bottom"
3647
3599
  }) {
3648
3600
  const context = useLanguageContext();
3649
3601
  const contextLanguages = context?.languages?.map((lang) => ({
@@ -3661,34 +3613,24 @@ function LanguageSwitcher({
3661
3613
  };
3662
3614
  if (variant === "mini") {
3663
3615
  return /* @__PURE__ */ jsxs(DropdownMenu, { modal: false, children: [
3664
- /* @__PURE__ */ jsxs(Tooltip, { children: [
3665
- /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
3666
- Button,
3667
- {
3668
- variant: "ghost",
3669
- size: "icon",
3670
- "aria-label": defaultLabels4.language,
3671
- className: cn(sizes.buttonMini, shapeClass, className),
3672
- children: /* @__PURE__ */ jsx(Languages, { className: sizes.iconMini })
3673
- }
3674
- ) }) }),
3675
- /* @__PURE__ */ jsx(
3676
- TooltipContent,
3677
- {
3678
- side: tooltipSide,
3679
- align: tooltipAlign,
3680
- sideOffset: tooltipSideOffset,
3681
- children: defaultLabels4.language
3682
- }
3683
- )
3684
- ] }),
3616
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
3617
+ Button,
3618
+ {
3619
+ variant: "ghost",
3620
+ size: "icon",
3621
+ "aria-label": defaultLabels4.language,
3622
+ className: cn(sizes.buttonMini, shapeClass, className),
3623
+ children: /* @__PURE__ */ jsx(Languages, { className: sizes.iconMini })
3624
+ }
3625
+ ) }),
3685
3626
  /* @__PURE__ */ jsx(
3686
3627
  DropdownMenuContent,
3687
3628
  {
3688
3629
  side,
3689
3630
  align,
3690
- sideOffset: 8,
3691
- className: "min-w-0 w-auto",
3631
+ sideOffset: miniMenuContentDefaults.sideOffset,
3632
+ collisionPadding: miniMenuContentDefaults.collisionPadding,
3633
+ className: cn(miniMenuContentClassName, "min-w-0 w-auto"),
3692
3634
  children: languages.map(({ key, nativeName }) => /* @__PURE__ */ jsx(
3693
3635
  DropdownMenuItem,
3694
3636
  {
@@ -3888,10 +3830,7 @@ function EnvironmentSwitcher({
3888
3830
  shape = "rounded",
3889
3831
  variant = "mini",
3890
3832
  align = "end",
3891
- side = "bottom",
3892
- tooltipSide = "bottom",
3893
- tooltipAlign = "center",
3894
- tooltipSideOffset = 8
3833
+ side = "bottom"
3895
3834
  }) {
3896
3835
  const ctx = useEnvironmentContext();
3897
3836
  const labels = { ...defaultLabels2, ...userLabels };
@@ -3907,53 +3846,18 @@ function EnvironmentSwitcher({
3907
3846
  };
3908
3847
  if (variant === "mini") {
3909
3848
  return /* @__PURE__ */ jsxs(DropdownMenu, { modal: false, children: [
3910
- /* @__PURE__ */ jsxs(Tooltip, { children: [
3911
- /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
3912
- Button,
3913
- {
3914
- "data-testid": "environment-switcher",
3915
- variant: "outline",
3916
- size: "sm",
3917
- "aria-label": labels.environment,
3918
- className: cn(
3919
- sizes.buttonMini,
3920
- shapeClass,
3921
- "font-medium tabular-nums border-border bg-background",
3922
- className
3923
- ),
3924
- children: [
3925
- /* @__PURE__ */ jsx(
3926
- "span",
3927
- {
3928
- className: cn(
3929
- "rounded-full shrink-0 ring-1 ring-background",
3930
- sizes.dot,
3931
- getEnvironmentDotClass(environment)
3932
- ),
3933
- "aria-hidden": true
3934
- }
3935
- ),
3936
- /* @__PURE__ */ jsx("span", { className: "max-w-[5.5rem] truncate", children: getEnvironmentLabel(environment, labels) })
3937
- ]
3938
- }
3939
- ) }) }),
3940
- /* @__PURE__ */ jsx(
3941
- TooltipContent,
3942
- {
3943
- side: tooltipSide,
3944
- align: tooltipAlign,
3945
- sideOffset: tooltipSideOffset,
3946
- children: labels.environment
3947
- }
3948
- )
3949
- ] }),
3950
- /* @__PURE__ */ jsx(DropdownMenuContent, { side, align, sideOffset: 8, children: environments.map((env) => /* @__PURE__ */ jsxs(
3951
- DropdownMenuItem,
3849
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
3850
+ Button,
3952
3851
  {
3953
- onClick: () => handleSelect(env),
3852
+ "data-testid": "environment-switcher",
3853
+ variant: "outline",
3854
+ size: "sm",
3855
+ "aria-label": labels.environment,
3954
3856
  className: cn(
3955
- "gap-2 cursor-pointer",
3956
- environment === env && "bg-accent text-accent-foreground [&_svg]:text-accent-foreground"
3857
+ sizes.buttonMini,
3858
+ shapeClass,
3859
+ "font-medium tabular-nums border-border bg-background",
3860
+ className
3957
3861
  ),
3958
3862
  children: [
3959
3863
  /* @__PURE__ */ jsx(
@@ -3962,16 +3866,50 @@ function EnvironmentSwitcher({
3962
3866
  className: cn(
3963
3867
  "rounded-full shrink-0 ring-1 ring-background",
3964
3868
  sizes.dot,
3965
- getEnvironmentDotClass(env)
3869
+ getEnvironmentDotClass(environment)
3966
3870
  ),
3967
3871
  "aria-hidden": true
3968
3872
  }
3969
3873
  ),
3970
- /* @__PURE__ */ jsx("span", { children: getEnvironmentLabel(env, labels) })
3874
+ /* @__PURE__ */ jsx("span", { className: "max-w-[5.5rem] truncate", children: getEnvironmentLabel(environment, labels) })
3971
3875
  ]
3972
- },
3973
- env
3974
- )) })
3876
+ }
3877
+ ) }),
3878
+ /* @__PURE__ */ jsx(
3879
+ DropdownMenuContent,
3880
+ {
3881
+ side,
3882
+ align,
3883
+ sideOffset: miniMenuContentDefaults.sideOffset,
3884
+ collisionPadding: miniMenuContentDefaults.collisionPadding,
3885
+ className: miniMenuContentClassName,
3886
+ children: environments.map((env) => /* @__PURE__ */ jsxs(
3887
+ DropdownMenuItem,
3888
+ {
3889
+ onClick: () => handleSelect(env),
3890
+ className: cn(
3891
+ "gap-2 cursor-pointer",
3892
+ environment === env && "bg-accent text-accent-foreground [&_svg]:text-accent-foreground"
3893
+ ),
3894
+ children: [
3895
+ /* @__PURE__ */ jsx(
3896
+ "span",
3897
+ {
3898
+ className: cn(
3899
+ "rounded-full shrink-0 ring-1 ring-background",
3900
+ sizes.dot,
3901
+ getEnvironmentDotClass(env)
3902
+ ),
3903
+ "aria-hidden": true
3904
+ }
3905
+ ),
3906
+ /* @__PURE__ */ jsx("span", { children: getEnvironmentLabel(env, labels) })
3907
+ ]
3908
+ },
3909
+ env
3910
+ ))
3911
+ }
3912
+ )
3975
3913
  ] });
3976
3914
  }
3977
3915
  return /* @__PURE__ */ jsxs(
@@ -5829,6 +5767,52 @@ function UpcomingEvents({
5829
5767
  );
5830
5768
  }) });
5831
5769
  }
5770
+ function TooltipProvider({
5771
+ delayDuration = 0,
5772
+ ...props
5773
+ }) {
5774
+ return /* @__PURE__ */ jsx(
5775
+ TooltipPrimitive.Provider,
5776
+ {
5777
+ "data-slot": "tooltip-provider",
5778
+ delayDuration,
5779
+ ...props
5780
+ }
5781
+ );
5782
+ }
5783
+ function Tooltip({
5784
+ ...props
5785
+ }) {
5786
+ return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(TooltipPrimitive.Root, { "data-slot": "tooltip", ...props }) });
5787
+ }
5788
+ function TooltipTrigger({
5789
+ ...props
5790
+ }) {
5791
+ return /* @__PURE__ */ jsx(TooltipPrimitive.Trigger, { "data-slot": "tooltip-trigger", ...props });
5792
+ }
5793
+ function TooltipContent({
5794
+ className,
5795
+ sideOffset = 0,
5796
+ children,
5797
+ ...props
5798
+ }) {
5799
+ return /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
5800
+ TooltipPrimitive.Content,
5801
+ {
5802
+ "data-slot": "tooltip-content",
5803
+ sideOffset,
5804
+ className: cn(
5805
+ "bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
5806
+ className
5807
+ ),
5808
+ ...props,
5809
+ children: [
5810
+ children,
5811
+ /* @__PURE__ */ jsx(TooltipPrimitive.Arrow, { className: "bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" })
5812
+ ]
5813
+ }
5814
+ ) });
5815
+ }
5832
5816
  function CalendarSubscribeButton({
5833
5817
  feedUrl,
5834
5818
  label
@@ -7603,26 +7587,6 @@ function CardInput({
7603
7587
  )
7604
7588
  ] });
7605
7589
  }
7606
-
7607
- // src/lib/usAddress.ts
7608
- function splitStreet(street) {
7609
- const trimmed = street.trim();
7610
- const m = trimmed.match(/^(\S+)\s+(.+)$/);
7611
- if (m && /^\d/.test(m[1])) {
7612
- return { number: m[1], name: m[2].trim() };
7613
- }
7614
- return { number: "", name: trimmed };
7615
- }
7616
- function joinStreet(streetNumber, streetName) {
7617
- return [streetNumber, streetName].map((s) => s.trim()).filter((s) => s.length > 0).join(" ");
7618
- }
7619
- function sanitizeForNls(input) {
7620
- return input.replace(/[^A-Za-z0-9 .,'#\-/]/g, " ").replace(/\s+/g, " ").trim();
7621
- }
7622
- function composeAddressLine1ForNls(v) {
7623
- const line = [v.streetNumber, v.streetName, v.apt].filter((s) => typeof s === "string" && s.trim().length > 0).join(" ");
7624
- return sanitizeForNls(line).slice(0, 40);
7625
- }
7626
7590
  function parseInitial(value) {
7627
7591
  if (!value) {
7628
7592
  return {
@@ -7643,28 +7607,6 @@ function parseInitial(value) {
7643
7607
  country: "US"
7644
7608
  };
7645
7609
  }
7646
- function legacyToModern(legacy) {
7647
- return {
7648
- street: joinStreet(legacy.streetNumber, legacy.streetName),
7649
- street2: legacy.apt ?? "",
7650
- city: legacy.city,
7651
- state: legacy.state,
7652
- zip: legacy.zipCode,
7653
- country: "US"
7654
- };
7655
- }
7656
- function toLegacy(modern) {
7657
- const parts = splitStreet(modern.street);
7658
- return {
7659
- streetNumber: sanitizeForNls(parts.number),
7660
- streetName: sanitizeForNls(parts.name),
7661
- apt: modern.street2 ? sanitizeForNls(modern.street2) : void 0,
7662
- city: modern.city.trim(),
7663
- state: modern.state.trim().toUpperCase(),
7664
- zipCode: modern.zip.replace(/\D/g, "").slice(0, 5),
7665
- country: "US"
7666
- };
7667
- }
7668
7610
  function addressSig(a) {
7669
7611
  return JSON.stringify({
7670
7612
  street: a.street.trim(),
@@ -7690,19 +7632,14 @@ function USAddressInput({
7690
7632
  disabled = false,
7691
7633
  largeText = false,
7692
7634
  className,
7693
- onError,
7694
- legacyMode = false,
7695
- valueLegacy,
7696
- onChangeLegacy
7635
+ onError
7697
7636
  }) {
7698
7637
  const [searchQuery, setSearchQuery] = useState("");
7699
7638
  const [showSuggestions, setShowSuggestions] = useState(false);
7700
7639
  const [suggestions, setSuggestions] = useState([]);
7701
- const [address, setAddress] = useState(() => {
7702
- if (value != null) return parseInitial(value);
7703
- if (valueLegacy != null) return legacyToModern(valueLegacy);
7704
- return parseInitial(void 0);
7705
- });
7640
+ const [address, setAddress] = useState(
7641
+ () => parseInitial(value)
7642
+ );
7706
7643
  const [sessionToken] = useState(
7707
7644
  () => typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`
7708
7645
  );
@@ -7724,22 +7661,6 @@ function USAddressInput({
7724
7661
  const addressRef = useRef(address);
7725
7662
  addressRef.current = address;
7726
7663
  const lastValidatedSigRef = useRef("");
7727
- const onChangeLegacyRef = useRef(onChangeLegacy);
7728
- onChangeLegacyRef.current = onChangeLegacy;
7729
- const legacyModeRef = useRef(legacyMode);
7730
- legacyModeRef.current = legacyMode;
7731
- const emitChange = useRef((next) => {
7732
- onChange(next);
7733
- if (legacyModeRef.current && onChangeLegacyRef.current) {
7734
- onChangeLegacyRef.current(toLegacy(next));
7735
- }
7736
- });
7737
- emitChange.current = (next) => {
7738
- onChange(next);
7739
- if (legacyModeRef.current && onChangeLegacyRef.current) {
7740
- onChangeLegacyRef.current(toLegacy(next));
7741
- }
7742
- };
7743
7664
  const debouncedSearch = useDebouncedValue(searchQuery, 400);
7744
7665
  const zipDigits = address.zip.replace(/\D/g, "").slice(0, 5);
7745
7666
  const debouncedZip = useDebouncedValue(zipDigits, 400);
@@ -7756,18 +7677,13 @@ function USAddressInput({
7756
7677
  return () => document.removeEventListener("mousedown", handleClickOutside);
7757
7678
  }, []);
7758
7679
  const valueSyncKey = value == null ? "" : `o:${JSON.stringify(value)}`;
7759
- const valueLegacySyncKey = value != null || valueLegacy == null ? null : `l:${JSON.stringify(valueLegacy)}`;
7760
7680
  useEffect(() => {
7761
7681
  setAddress(parseInitial(value));
7762
7682
  }, [valueSyncKey]);
7763
- useEffect(() => {
7764
- if (valueLegacySyncKey == null) return;
7765
- setAddress(legacyToModern(valueLegacy));
7766
- }, [valueLegacySyncKey]);
7767
7683
  const handleFieldChange = (field, fieldValue) => {
7768
7684
  setAddress((prev) => {
7769
7685
  const next = field === "country" ? { ...prev, country: "US" } : { ...prev, [field]: fieldValue };
7770
- emitChange.current(next);
7686
+ onChange(next);
7771
7687
  return next;
7772
7688
  });
7773
7689
  };
@@ -7839,7 +7755,7 @@ function USAddressInput({
7839
7755
  if (cityEmpty && data.city) next.city = data.city;
7840
7756
  if (stateEmpty && data.state) next.state = data.state;
7841
7757
  next.country = "US";
7842
- emitChange.current(next);
7758
+ onChange(next);
7843
7759
  return next;
7844
7760
  });
7845
7761
  }).catch(() => {
@@ -7853,6 +7769,7 @@ function USAddressInput({
7853
7769
  debouncedZip,
7854
7770
  allowZipLookup,
7855
7771
  lookupZip,
7772
+ onChange,
7856
7773
  labels.zipLookupFailed,
7857
7774
  onError
7858
7775
  ]);
@@ -7914,7 +7831,7 @@ function USAddressInput({
7914
7831
  country: "US"
7915
7832
  };
7916
7833
  setAddress(normalized);
7917
- emitChange.current(normalized);
7834
+ onChange(normalized);
7918
7835
  setShowSuggestions(false);
7919
7836
  setSearchQuery("");
7920
7837
  setUspsSuggestion(null);
@@ -7927,7 +7844,7 @@ function USAddressInput({
7927
7844
  const applyUspsSuggestion = () => {
7928
7845
  if (!uspsSuggestion) return;
7929
7846
  setAddress(uspsSuggestion);
7930
- emitChange.current(uspsSuggestion);
7847
+ onChange(uspsSuggestion);
7931
7848
  setUspsSuggestion(null);
7932
7849
  lastValidatedSigRef.current = addressSig(uspsSuggestion);
7933
7850
  setUspsVerifiedNoChange(true);
@@ -8167,809 +8084,7 @@ function USAddressInput({
8167
8084
  ] })
8168
8085
  ] });
8169
8086
  }
8170
- function defaultPageOf(page, total) {
8171
- return `${page} / ${total}`;
8172
- }
8173
- 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)`.";
8174
- function buildGetDocumentArgs(src, documentOptions) {
8175
- const rest = documentOptions ?? {};
8176
- if (typeof src === "string") {
8177
- return { url: src, ...rest };
8178
- }
8179
- return { data: src, ...rest };
8180
- }
8181
- function PdfPageCanvas({
8182
- page,
8183
- layout,
8184
- scale,
8185
- visible,
8186
- pageClassName
8187
- }) {
8188
- const canvasRef = useRef(null);
8189
- const taskRef = useRef(null);
8190
- useEffect(() => {
8191
- if (!visible || !canvasRef.current) {
8192
- taskRef.current?.cancel();
8193
- taskRef.current = null;
8194
- const c = canvasRef.current;
8195
- if (c) {
8196
- const ctx2 = c.getContext("2d");
8197
- if (ctx2) {
8198
- ctx2.setTransform(1, 0, 0, 1, 0, 0);
8199
- ctx2.clearRect(0, 0, c.width, c.height);
8200
- }
8201
- }
8202
- return;
8203
- }
8204
- const canvas = canvasRef.current;
8205
- const ctx = canvas.getContext("2d");
8206
- if (!ctx) return;
8207
- const viewport = page.getViewport({ scale });
8208
- canvas.width = viewport.width;
8209
- canvas.height = viewport.height;
8210
- const task = page.render({
8211
- canvasContext: ctx,
8212
- viewport,
8213
- canvas
8214
- });
8215
- taskRef.current = task;
8216
- task.promise.catch(() => {
8217
- });
8218
- return () => {
8219
- task.cancel();
8220
- if (taskRef.current === task) {
8221
- taskRef.current = null;
8222
- }
8223
- };
8224
- }, [page, visible, scale]);
8225
- const w = layout.widthPt * scale;
8226
- const h = layout.heightPt * scale;
8227
- return /* @__PURE__ */ jsx(
8228
- "div",
8229
- {
8230
- className: cn("relative flex justify-center bg-muted/40", pageClassName),
8231
- style: { width: w, height: h },
8232
- "data-page": layout.pageNumber,
8233
- children: visible ? /* @__PURE__ */ jsx(
8234
- "canvas",
8235
- {
8236
- ref: canvasRef,
8237
- className: "block max-h-full shadow-sm",
8238
- "aria-hidden": "true"
8239
- }
8240
- ) : null
8241
- }
8242
- );
8243
- }
8244
- 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";
8245
- function touchPairDistance(touches) {
8246
- if (touches.length < 2) return 0;
8247
- const a = touches.item(0);
8248
- const b = touches.item(1);
8249
- return Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY);
8250
- }
8251
- function PdfThumbnailStrip({
8252
- page,
8253
- pageNumber,
8254
- active,
8255
- onPick,
8256
- label
8257
- }) {
8258
- const canvasRef = useRef(null);
8259
- useEffect(() => {
8260
- const canvas = canvasRef.current;
8261
- if (!canvas) return;
8262
- const viewport = page.getViewport({ scale: 1 });
8263
- const thumbMax = 176;
8264
- const s = thumbMax / Math.max(viewport.width, viewport.height);
8265
- const vp = page.getViewport({ scale: s });
8266
- const ctx = canvas.getContext("2d");
8267
- if (!ctx) return;
8268
- canvas.width = vp.width;
8269
- canvas.height = vp.height;
8270
- const task = page.render({
8271
- canvasContext: ctx,
8272
- viewport: vp,
8273
- canvas
8274
- });
8275
- task.promise.catch(() => {
8276
- });
8277
- return () => {
8278
- task.cancel();
8279
- };
8280
- }, [page]);
8281
- return /* @__PURE__ */ jsxs(
8282
- "button",
8283
- {
8284
- type: "button",
8285
- onClick: () => onPick(pageNumber),
8286
- className: cn(
8287
- "flex w-full flex-col items-center gap-1 rounded-md p-2 transition-colors hover:bg-white/5",
8288
- active ? "bg-white/10" : ""
8289
- ),
8290
- "aria-label": label,
8291
- "aria-current": active ? "page" : void 0,
8292
- children: [
8293
- /* @__PURE__ */ jsx(
8294
- "canvas",
8295
- {
8296
- ref: canvasRef,
8297
- className: "block max-w-full overflow-hidden rounded-sm bg-black",
8298
- "aria-hidden": true
8299
- }
8300
- ),
8301
- /* @__PURE__ */ jsx("span", { className: "text-[10px] tabular-nums text-neutral-400", children: pageNumber })
8302
- ]
8303
- }
8304
- );
8305
- }
8306
- function PdfViewer({
8307
- src,
8308
- workerSrc,
8309
- documentOptions,
8310
- initialPage = 1,
8311
- initialScale = 1,
8312
- minScale = 0.5,
8313
- maxScale = 4,
8314
- scaleStep = 0.2,
8315
- enableKeyboardShortcuts = true,
8316
- enablePinchZoom = true,
8317
- enableThumbnailSidebar = true,
8318
- thumbnailSidebarDefaultOpen = true,
8319
- labels,
8320
- onLoad,
8321
- onError,
8322
- onPageChange,
8323
- onScaleChange,
8324
- className,
8325
- toolbarClassName,
8326
- pageClassName,
8327
- toolbarEndSlot
8328
- }) {
8329
- const mergedLabels = labels ?? {};
8330
- const toolbarLabel = mergedLabels.toolbar ?? "PDF controls";
8331
- const loadingLabel = mergedLabels.loading ?? "Loading PDF\u2026";
8332
- const workerErrorMessage = mergedLabels.workerMissing ?? DEFAULT_WORKER_MSG;
8333
- const errorLabelFallback = mergedLabels.error ?? "Failed to load PDF";
8334
- const toolbarId = useId();
8335
- const pageInputId = `${toolbarId}-page`;
8336
- const thumbnailNavId = `${toolbarId}-thumbnails`;
8337
- const scrollRef = useRef(null);
8338
- const observerRef = useRef(null);
8339
- const lastReportedPage = useRef(0);
8340
- const loadedPdfRef = useRef(null);
8341
- const [loadError, setLoadError] = useState(null);
8342
- const [busy, setBusy] = useState(false);
8343
- const [layouts, setLayouts] = useState([]);
8344
- const [pagesMap, setPagesMap] = useState(
8345
- null
8346
- );
8347
- const [scale, setScale] = useState(initialScale);
8348
- const [ratios, setRatios] = useState({});
8349
- const [pageInput, setPageInput] = useState(String(initialPage));
8350
- const [thumbnailSidebarOpen, setThumbnailSidebarOpen] = useState(
8351
- thumbnailSidebarDefaultOpen
8352
- );
8353
- const baselineScaleRef = useRef(initialScale);
8354
- useEffect(() => {
8355
- baselineScaleRef.current = initialScale;
8356
- }, [initialScale]);
8357
- const pageOfFormatter = mergedLabels.pageOf ?? defaultPageOf;
8358
- const resolvedGoToLabel = mergedLabels.goToPage ?? "Go to page";
8359
- const zoomInLabel = mergedLabels.zoomIn ?? "Zoom in";
8360
- const zoomOutLabel = mergedLabels.zoomOut ?? "Zoom out";
8361
- const resetZoomLabel = mergedLabels.resetZoom ?? "Reset zoom";
8362
- const fitWidthLabel = mergedLabels.fitToWidth ?? "Fit to width";
8363
- const thumbnailSidebarLabel = mergedLabels.thumbnailSidebar ?? "Page thumbnails";
8364
- const toggleThumbLabel = mergedLabels.toggleThumbnailSidebar ?? "Toggle page thumbnails";
8365
- const pageThumbLabel = mergedLabels.pageThumbnail ?? ((n) => `Page ${n}, show in document`);
8366
- const pageCount = layouts.length;
8367
- const currentVisiblePage = useMemo(() => {
8368
- let bestPage = 1;
8369
- let bestRatio = -1;
8370
- for (const layout of layouts) {
8371
- const r2 = ratios[layout.pageNumber] ?? 0;
8372
- if (r2 > bestRatio) {
8373
- bestRatio = r2;
8374
- bestPage = layout.pageNumber;
8375
- }
8376
- }
8377
- return bestRatio >= 0.01 ? bestPage : 1;
8378
- }, [layouts, ratios]);
8379
- const clampScaleValue = useCallback(
8380
- (v) => Math.min(maxScale, Math.max(minScale, v)),
8381
- [minScale, maxScale]
8382
- );
8383
- const zoomInAct = useCallback(() => {
8384
- setScale((prev) => {
8385
- const c = clampScaleValue(prev + scaleStep);
8386
- onScaleChange?.(c);
8387
- return c;
8388
- });
8389
- }, [clampScaleValue, onScaleChange, scaleStep]);
8390
- const zoomOutAct = useCallback(() => {
8391
- setScale((prev) => {
8392
- const c = clampScaleValue(prev - scaleStep);
8393
- onScaleChange?.(c);
8394
- return c;
8395
- });
8396
- }, [clampScaleValue, onScaleChange, scaleStep]);
8397
- const resetZoomAct = useCallback(() => {
8398
- const c = clampScaleValue(baselineScaleRef.current);
8399
- setScale(c);
8400
- onScaleChange?.(c);
8401
- }, [clampScaleValue, onScaleChange]);
8402
- const fitToWidthAct = useCallback(() => {
8403
- const root = scrollRef.current;
8404
- if (!root || layouts.length === 0) return;
8405
- const avail = Math.max(root.clientWidth - 32, 120);
8406
- const maxW = Math.max(...layouts.map((l) => l.widthPt), 1);
8407
- const next = clampScaleValue(avail / maxW);
8408
- setScale(next);
8409
- onScaleChange?.(next);
8410
- }, [clampScaleValue, layouts, onScaleChange]);
8411
- useEffect(() => {
8412
- setPageInput(String(currentVisiblePage));
8413
- if (lastReportedPage.current !== currentVisiblePage) {
8414
- lastReportedPage.current = currentVisiblePage;
8415
- onPageChange?.(currentVisiblePage);
8416
- }
8417
- }, [currentVisiblePage, onPageChange]);
8418
- const scrollToPage = useCallback((pageNum) => {
8419
- const root = scrollRef.current;
8420
- if (!root || pageNum < 1) return;
8421
- const el = root.querySelector(`[data-page="${pageNum}"]`);
8422
- if (el instanceof HTMLElement) {
8423
- el.scrollIntoView({ behavior: "smooth", block: "start" });
8424
- }
8425
- }, []);
8426
- useEffect(() => {
8427
- if (!busy && pagesMap && pageCount > 0) {
8428
- const p = Math.min(Math.max(1, initialPage), pageCount);
8429
- requestAnimationFrame(() => scrollToPage(p));
8430
- }
8431
- }, [busy, pagesMap, pageCount, initialPage, scrollToPage]);
8432
- const loadKey = useMemo(() => {
8433
- if (typeof src === "string") return src;
8434
- if (src instanceof ArrayBuffer) return `ab:${src.byteLength}`;
8435
- return `ua:${src.byteLength}:${src.byteOffset}:${src.buffer.byteLength}`;
8436
- }, [src]);
8437
- useEffect(() => {
8438
- let cancelled = false;
8439
- let activeDoc = null;
8440
- setLoadError(null);
8441
- if (loadedPdfRef.current) {
8442
- void loadedPdfRef.current.destroy();
8443
- loadedPdfRef.current = null;
8444
- }
8445
- setLayouts([]);
8446
- setPagesMap(null);
8447
- setRatios({});
8448
- const trimmedWorker = workerSrc?.trim?.() ?? "";
8449
- if (!trimmedWorker) {
8450
- setLoadError(workerErrorMessage);
8451
- onError?.(new Error(workerErrorMessage));
8452
- return () => {
8453
- cancelled = true;
8454
- };
8455
- }
8456
- void (async () => {
8457
- try {
8458
- setBusy(true);
8459
- const pdfjs = await import('pdfjs-dist');
8460
- if (cancelled) return;
8461
- pdfjs.GlobalWorkerOptions.workerSrc = trimmedWorker;
8462
- const loadingTask = pdfjs.getDocument(
8463
- buildGetDocumentArgs(src, documentOptions)
8464
- );
8465
- activeDoc = await loadingTask.promise;
8466
- if (cancelled) {
8467
- void activeDoc.destroy();
8468
- activeDoc = null;
8469
- return;
8470
- }
8471
- const layoutsLocal = [];
8472
- const mapLocal = /* @__PURE__ */ new Map();
8473
- for (let p = 1; p <= activeDoc.numPages; p++) {
8474
- const page = await activeDoc.getPage(p);
8475
- mapLocal.set(p, page);
8476
- const viewport = page.getViewport({ scale: 1 });
8477
- layoutsLocal.push({
8478
- pageNumber: p,
8479
- widthPt: viewport.width,
8480
- heightPt: viewport.height
8481
- });
8482
- }
8483
- if (cancelled) {
8484
- void activeDoc.destroy();
8485
- activeDoc = null;
8486
- return;
8487
- }
8488
- onLoad?.(activeDoc);
8489
- loadedPdfRef.current = activeDoc;
8490
- setLayouts(layoutsLocal);
8491
- setPagesMap(mapLocal);
8492
- activeDoc = null;
8493
- } catch (e) {
8494
- const err = e instanceof Error ? e : new Error(String(e));
8495
- if (!cancelled) {
8496
- setLoadError(errorLabelFallback);
8497
- onError?.(err);
8498
- }
8499
- if (activeDoc) {
8500
- void activeDoc.destroy();
8501
- activeDoc = null;
8502
- }
8503
- } finally {
8504
- if (!cancelled) setBusy(false);
8505
- }
8506
- })();
8507
- return () => {
8508
- cancelled = true;
8509
- if (observerRef.current) {
8510
- observerRef.current.disconnect();
8511
- observerRef.current = null;
8512
- }
8513
- if (activeDoc) {
8514
- void activeDoc.destroy();
8515
- }
8516
- if (loadedPdfRef.current) {
8517
- void loadedPdfRef.current.destroy();
8518
- loadedPdfRef.current = null;
8519
- }
8520
- };
8521
- }, [workerSrc, loadKey, documentOptions]);
8522
- useEffect(() => {
8523
- setScale(clampScaleValue(initialScale));
8524
- }, [initialScale, clampScaleValue]);
8525
- useEffect(() => {
8526
- const el = scrollRef.current;
8527
- if (!el || !enablePinchZoom) return;
8528
- let pinchDist = 0;
8529
- const onWheel = (e) => {
8530
- if (!e.ctrlKey) return;
8531
- e.preventDefault();
8532
- const delta = -e.deltaY;
8533
- const factor = Math.exp(delta * 2e-3);
8534
- setScale((prev) => {
8535
- const c = clampScaleValue(prev * factor);
8536
- onScaleChange?.(c);
8537
- return c;
8538
- });
8539
- };
8540
- const onTouchStart = (e) => {
8541
- if (e.touches.length === 2) {
8542
- pinchDist = touchPairDistance(e.touches);
8543
- }
8544
- };
8545
- const onTouchMove = (e) => {
8546
- if (e.touches.length !== 2 || pinchDist <= 0) return;
8547
- e.preventDefault();
8548
- const d = touchPairDistance(e.touches);
8549
- const ratio = d / pinchDist;
8550
- pinchDist = d;
8551
- setScale((prev) => {
8552
- const c = clampScaleValue(prev * ratio);
8553
- onScaleChange?.(c);
8554
- return c;
8555
- });
8556
- };
8557
- const endPinch = (e) => {
8558
- if (e.touches.length < 2) pinchDist = 0;
8559
- };
8560
- el.addEventListener("wheel", onWheel, { passive: false });
8561
- el.addEventListener("touchstart", onTouchStart, { passive: true });
8562
- el.addEventListener("touchmove", onTouchMove, { passive: false });
8563
- el.addEventListener("touchend", endPinch);
8564
- el.addEventListener("touchcancel", endPinch);
8565
- return () => {
8566
- el.removeEventListener("wheel", onWheel);
8567
- el.removeEventListener("touchstart", onTouchStart);
8568
- el.removeEventListener("touchmove", onTouchMove);
8569
- el.removeEventListener("touchend", endPinch);
8570
- el.removeEventListener("touchcancel", endPinch);
8571
- };
8572
- }, [enablePinchZoom, clampScaleValue, onScaleChange]);
8573
- useEffect(() => {
8574
- if (layouts.length === 0) return;
8575
- const frame = requestAnimationFrame(() => {
8576
- const root = scrollRef.current;
8577
- if (!root) return;
8578
- if (observerRef.current) {
8579
- observerRef.current.disconnect();
8580
- }
8581
- const io = new IntersectionObserver(
8582
- (entries) => {
8583
- setRatios((prev) => {
8584
- const next = { ...prev };
8585
- for (const e of entries) {
8586
- const tgt = e.target;
8587
- const p = Number(tgt.dataset.page);
8588
- if (Number.isFinite(p)) next[p] = e.intersectionRatio;
8589
- }
8590
- return next;
8591
- });
8592
- },
8593
- {
8594
- root,
8595
- rootMargin: "200px 0px",
8596
- threshold: [0, 0.05, 0.25, 0.5, 0.75, 1]
8597
- }
8598
- );
8599
- observerRef.current = io;
8600
- root.querySelectorAll("[data-page]").forEach((el) => io.observe(el));
8601
- });
8602
- return () => {
8603
- cancelAnimationFrame(frame);
8604
- if (observerRef.current) {
8605
- observerRef.current.disconnect();
8606
- observerRef.current = null;
8607
- }
8608
- };
8609
- }, [layouts]);
8610
- const handleSubmitPage = useCallback(() => {
8611
- const n = Number.parseInt(pageInput, 10);
8612
- if (!Number.isFinite(n) || pageCount === 0) return;
8613
- const clamped = Math.min(Math.max(1, n), pageCount);
8614
- scrollToPage(clamped);
8615
- setPageInput(String(clamped));
8616
- }, [pageInput, pageCount, scrollToPage]);
8617
- const handleKeyDown = useCallback(
8618
- (e) => {
8619
- if (!enableKeyboardShortcuts) return;
8620
- if (e.target !== e.currentTarget && e.target instanceof HTMLInputElement) {
8621
- return;
8622
- }
8623
- let handled = false;
8624
- switch (e.key) {
8625
- case "PageDown": {
8626
- scrollToPage(Math.min(pageCount || 1, currentVisiblePage + 1));
8627
- handled = true;
8628
- break;
8629
- }
8630
- case "PageUp": {
8631
- scrollToPage(Math.max(1, currentVisiblePage - 1));
8632
- handled = true;
8633
- break;
8634
- }
8635
- case "Home": {
8636
- scrollToPage(1);
8637
- handled = true;
8638
- break;
8639
- }
8640
- case "End": {
8641
- if (pageCount) scrollToPage(pageCount);
8642
- handled = true;
8643
- break;
8644
- }
8645
- case "+":
8646
- case "=": {
8647
- zoomInAct();
8648
- handled = true;
8649
- break;
8650
- }
8651
- case "-":
8652
- case "_": {
8653
- zoomOutAct();
8654
- handled = true;
8655
- break;
8656
- }
8657
- case "0": {
8658
- resetZoomAct();
8659
- handled = true;
8660
- break;
8661
- }
8662
- }
8663
- if (handled) {
8664
- e.preventDefault();
8665
- e.stopPropagation();
8666
- }
8667
- },
8668
- [
8669
- enableKeyboardShortcuts,
8670
- pageCount,
8671
- currentVisiblePage,
8672
- scrollToPage,
8673
- zoomInAct,
8674
- zoomOutAct,
8675
- resetZoomAct
8676
- ]
8677
- );
8678
- const thumbnailsRailEligible = enableThumbnailSidebar && !busy && pagesMap !== null && pageCount > 0;
8679
- if (loadError) {
8680
- return /* @__PURE__ */ jsx(
8681
- "div",
8682
- {
8683
- className: cn("rounded-md border border-destructive/50 p-4", className),
8684
- role: "alert",
8685
- children: /* @__PURE__ */ jsx("p", { className: "text-destructive text-sm", children: loadError })
8686
- }
8687
- );
8688
- }
8689
- return /* @__PURE__ */ jsxs(
8690
- "div",
8691
- {
8692
- className: cn(
8693
- "flex min-h-0 flex-col overflow-hidden rounded-md border",
8694
- className
8695
- ),
8696
- children: [
8697
- /* @__PURE__ */ jsxs(
8698
- "div",
8699
- {
8700
- id: toolbarId,
8701
- role: "toolbar",
8702
- "aria-label": toolbarLabel,
8703
- className: cn(
8704
- "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",
8705
- toolbarClassName
8706
- ),
8707
- children: [
8708
- thumbnailsRailEligible ? /* @__PURE__ */ jsx(
8709
- Button,
8710
- {
8711
- type: "button",
8712
- variant: "outline",
8713
- size: "icon-sm",
8714
- className: "hidden md:inline-flex",
8715
- onClick: () => setThumbnailSidebarOpen((v) => !v),
8716
- "aria-label": toggleThumbLabel,
8717
- "aria-expanded": thumbnailSidebarOpen,
8718
- "aria-controls": thumbnailNavId,
8719
- children: thumbnailSidebarOpen ? /* @__PURE__ */ jsx(PanelLeftOpen, { className: "size-4", "aria-hidden": true }) : /* @__PURE__ */ jsx(PanelRightOpen, { className: "size-4", "aria-hidden": true })
8720
- }
8721
- ) : null,
8722
- /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs tabular-nums sm:text-sm", children: busy || pagesMap === null ? "\u2014" : pageOfFormatter(currentVisiblePage, pageCount) }),
8723
- /* @__PURE__ */ jsx("label", { htmlFor: pageInputId, className: "sr-only", children: resolvedGoToLabel }),
8724
- /* @__PURE__ */ jsx(
8725
- "input",
8726
- {
8727
- id: pageInputId,
8728
- type: "number",
8729
- min: 1,
8730
- max: Math.max(pageCount, 1),
8731
- disabled: busy || pageCount === 0,
8732
- className: PAGE_INPUT_CLASS,
8733
- "aria-label": resolvedGoToLabel,
8734
- value: pageInput,
8735
- onChange: (ev) => setPageInput(ev.target.value),
8736
- onKeyDown: (ev) => {
8737
- if (ev.key === "Enter") {
8738
- ev.preventDefault();
8739
- handleSubmitPage();
8740
- }
8741
- }
8742
- }
8743
- ),
8744
- /* @__PURE__ */ jsx(
8745
- Button,
8746
- {
8747
- type: "button",
8748
- variant: "outline",
8749
- size: "icon-sm",
8750
- onClick: zoomOutAct,
8751
- disabled: busy || scale <= minScale,
8752
- "aria-label": zoomOutLabel,
8753
- children: /* @__PURE__ */ jsx(ZoomOut, { "aria-hidden": true })
8754
- }
8755
- ),
8756
- /* @__PURE__ */ jsx(
8757
- Button,
8758
- {
8759
- type: "button",
8760
- variant: "outline",
8761
- size: "icon-sm",
8762
- onClick: zoomInAct,
8763
- disabled: busy || scale >= maxScale,
8764
- "aria-label": zoomInLabel,
8765
- children: /* @__PURE__ */ jsx(ZoomIn, { "aria-hidden": true })
8766
- }
8767
- ),
8768
- /* @__PURE__ */ jsx(
8769
- Button,
8770
- {
8771
- type: "button",
8772
- variant: "outline",
8773
- size: "icon-sm",
8774
- onClick: resetZoomAct,
8775
- disabled: busy,
8776
- "aria-label": resetZoomLabel,
8777
- children: /* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": true })
8778
- }
8779
- ),
8780
- /* @__PURE__ */ jsx(
8781
- Button,
8782
- {
8783
- type: "button",
8784
- variant: "outline",
8785
- size: "icon-sm",
8786
- onClick: fitToWidthAct,
8787
- disabled: busy || pageCount === 0,
8788
- "aria-label": fitWidthLabel,
8789
- children: /* @__PURE__ */ jsx(Maximize2, { "aria-hidden": true })
8790
- }
8791
- ),
8792
- toolbarEndSlot
8793
- ]
8794
- }
8795
- ),
8796
- /* @__PURE__ */ jsxs("div", { className: "flex min-h-0 flex-1 overflow-hidden", children: [
8797
- thumbnailsRailEligible && thumbnailSidebarOpen ? /* @__PURE__ */ jsx(
8798
- "nav",
8799
- {
8800
- id: thumbnailNavId,
8801
- 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",
8802
- "aria-label": thumbnailSidebarLabel,
8803
- children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: layouts.map((layout) => {
8804
- const pg = pagesMap.get(layout.pageNumber);
8805
- return pg ? /* @__PURE__ */ jsx(
8806
- PdfThumbnailStrip,
8807
- {
8808
- page: pg,
8809
- pageNumber: layout.pageNumber,
8810
- active: layout.pageNumber === currentVisiblePage,
8811
- onPick: scrollToPage,
8812
- label: pageThumbLabel(layout.pageNumber)
8813
- },
8814
- `thumb-${layout.pageNumber}`
8815
- ) : null;
8816
- }) })
8817
- }
8818
- ) : null,
8819
- /* @__PURE__ */ jsx(
8820
- "div",
8821
- {
8822
- ref: scrollRef,
8823
- tabIndex: 0,
8824
- onKeyDown: handleKeyDown,
8825
- className: "relative min-h-[240px] min-w-0 flex-1 overflow-auto outline-none focus-visible:ring-2 focus-visible:ring-ring",
8826
- "aria-busy": busy,
8827
- "aria-label": busy ? loadingLabel : "PDF pages",
8828
- 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) => {
8829
- const pg = pagesMap.get(layout.pageNumber);
8830
- const visible = (ratios[layout.pageNumber] ?? 0) >= 1e-3;
8831
- return pg ? /* @__PURE__ */ jsx(
8832
- PdfPageCanvas,
8833
- {
8834
- page: pg,
8835
- layout,
8836
- scale,
8837
- visible,
8838
- pageClassName
8839
- },
8840
- layout.pageNumber
8841
- ) : null;
8842
- }) })
8843
- }
8844
- )
8845
- ] })
8846
- ]
8847
- }
8848
- );
8849
- }
8850
- function usePdfViewerDialogScrollLock(active) {
8851
- useLayoutEffect(() => {
8852
- if (!active || typeof document === "undefined") return;
8853
- const html = document.documentElement;
8854
- const body = document.body;
8855
- const scrollRoots = [
8856
- ...document.querySelectorAll("[data-scroll-lock-root]")
8857
- ];
8858
- const scrollTopSnapshot = scrollRoots.map((el) => ({
8859
- el,
8860
- scrollTop: el.scrollTop
8861
- }));
8862
- const targets = /* @__PURE__ */ new Set([html, body, ...scrollRoots]);
8863
- const snapshot = [...targets].map((el) => ({
8864
- el,
8865
- overflow: el.style.overflow,
8866
- overscrollBehavior: el.style.overscrollBehavior
8867
- }));
8868
- const windowScrollY = window.scrollY;
8869
- for (const el of targets) {
8870
- el.style.overflow = "hidden";
8871
- el.style.overscrollBehavior = "none";
8872
- }
8873
- const dialogSurfaceSelector = '[data-slot="dialog-content"]';
8874
- const shouldAllowEventTarget = (target) => target instanceof Element && Boolean(target.closest(dialogSurfaceSelector));
8875
- const onWheel = (e) => {
8876
- if (shouldAllowEventTarget(e.target)) return;
8877
- e.preventDefault();
8878
- };
8879
- const onTouchMove = (e) => {
8880
- if (shouldAllowEventTarget(e.target)) return;
8881
- e.preventDefault();
8882
- };
8883
- window.addEventListener("wheel", onWheel, {
8884
- capture: true,
8885
- passive: false
8886
- });
8887
- window.addEventListener("touchmove", onTouchMove, {
8888
- capture: true,
8889
- passive: false
8890
- });
8891
- return () => {
8892
- window.removeEventListener("wheel", onWheel, { capture: true });
8893
- window.removeEventListener("touchmove", onTouchMove, {
8894
- capture: true
8895
- });
8896
- for (const { el, overflow, overscrollBehavior } of snapshot) {
8897
- el.style.overflow = overflow;
8898
- el.style.overscrollBehavior = overscrollBehavior;
8899
- }
8900
- for (const { el, scrollTop } of scrollTopSnapshot) {
8901
- el.scrollTop = scrollTop;
8902
- }
8903
- window.scrollTo(0, windowScrollY);
8904
- };
8905
- }, [active]);
8906
- }
8907
- 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";
8908
- function PdfViewerDialog({
8909
- open,
8910
- onOpenChange,
8911
- src,
8912
- workerSrc,
8913
- documentOptions,
8914
- trigger,
8915
- title,
8916
- labels,
8917
- forwardedProps
8918
- }) {
8919
- const closeLabel = labels?.close ?? "Close";
8920
- const dialogTitle = labels?.dialogTitle ?? title ?? "PDF document";
8921
- const dialogDescription = labels?.dialogDescription ?? "Document viewer with zoom and page navigation.";
8922
- usePdfViewerDialogScrollLock(open);
8923
- const {
8924
- className: forwardedClassName,
8925
- toolbarClassName: forwardedToolbarClassName,
8926
- ...restForwarded
8927
- } = forwardedProps ?? {};
8928
- return /* @__PURE__ */ jsxs(Dialog, { open, onOpenChange, children: [
8929
- trigger ? /* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: trigger }) : null,
8930
- /* @__PURE__ */ jsxs(
8931
- DialogContent,
8932
- {
8933
- className: fullscreenDialogContentClass,
8934
- showCloseButton: false,
8935
- children: [
8936
- /* @__PURE__ */ jsx(DialogTitle, { className: "sr-only", children: dialogTitle }),
8937
- /* @__PURE__ */ jsx(DialogDescription, { className: "sr-only", children: dialogDescription }),
8938
- /* @__PURE__ */ jsx(
8939
- PdfViewer,
8940
- {
8941
- ...restForwarded,
8942
- src,
8943
- workerSrc,
8944
- documentOptions,
8945
- className: cn(
8946
- "min-h-0 flex-1 rounded-none border-0 bg-transparent text-white",
8947
- forwardedClassName
8948
- ),
8949
- toolbarClassName: cn(
8950
- "border-white/10 bg-black/80 text-white backdrop-blur",
8951
- forwardedToolbarClassName
8952
- ),
8953
- toolbarEndSlot: /* @__PURE__ */ jsx(
8954
- Button,
8955
- {
8956
- type: "button",
8957
- variant: "ghost",
8958
- size: "icon-sm",
8959
- className: "ml-auto text-white hover:bg-white/10 hover:text-white",
8960
- onClick: () => onOpenChange(false),
8961
- "aria-label": closeLabel,
8962
- children: /* @__PURE__ */ jsx(X, { className: "size-5", "aria-hidden": true })
8963
- }
8964
- )
8965
- }
8966
- )
8967
- ]
8968
- }
8969
- )
8970
- ] });
8971
- }
8972
8087
 
8973
- export { AvatarEditor, AvatarEditorDialog, BLOCKS_DATA_ENVIRONMENTS, Button, CalendarContext, CalendarSubscribeButton, CalendarView, CalendarWidget, CardInput, ChatRoomView, ChatSidebar, ChatSidebarContext, ChatSidebarProvider, 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, EnvironmentBanner, EnvironmentContext, EnvironmentDot, EnvironmentMiniBadge, EnvironmentSwitcher, EventDialog, EventRsvpBadge, LanguageContext, LanguageSwitcher, MiniCalendar, NotificationsContext, NotificationsWidget, PdfViewer, PdfViewerDialog, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, ScrollArea, ScrollBar, Slider, ThemeSwitcher, Toggle, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, USAddressInput, UpcomingEvents, buttonVariants, cn, composeAddressLine1ForNls, defaultLanguages, getEnvironmentDotClass, getEnvironmentLabel, isBlocksDataEnvironment, joinStreet, sanitizeForNls, splitStreet, toggleVariants, useCalendarContext, useChatRoom, useChatSidebar, useDebouncedValue, useDebouncedValueStrict, useEnvironmentContext, useLanguageContext, useNotificationsContext };
8088
+ export { AvatarEditor, AvatarEditorDialog, BLOCKS_DATA_ENVIRONMENTS, Button, CalendarContext, CalendarSubscribeButton, CalendarView, CalendarWidget, CardInput, ChatRoomView, ChatSidebar, ChatSidebarContext, ChatSidebarProvider, 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, EnvironmentBanner, EnvironmentContext, EnvironmentDot, EnvironmentMiniBadge, EnvironmentSwitcher, EventDialog, EventRsvpBadge, LanguageContext, LanguageSwitcher, MiniCalendar, NotificationsContext, NotificationsWidget, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, ScrollArea, ScrollBar, Slider, ThemeSwitcher, Toggle, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, USAddressInput, UpcomingEvents, buttonVariants, cn, defaultLanguages, getEnvironmentDotClass, getEnvironmentLabel, isBlocksDataEnvironment, toggleVariants, useCalendarContext, useChatRoom, useChatSidebar, useDebouncedValue, useDebouncedValueStrict, useEnvironmentContext, useLanguageContext, useNotificationsContext };
8974
8089
  //# sourceMappingURL=index.js.map
8975
8090
  //# sourceMappingURL=index.js.map