@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.cjs +984 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +156 -2
- package/dist/index.d.ts +156 -2
- package/dist/index.js +981 -50
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -7991,6 +7991,94 @@ function useChatRoom(roomId, config, options = {}) {
|
|
|
7991
7991
|
isInitialLoading
|
|
7992
7992
|
};
|
|
7993
7993
|
}
|
|
7994
|
+
function AuthenticatedAttachment({
|
|
7995
|
+
url,
|
|
7996
|
+
getToken,
|
|
7997
|
+
fileName,
|
|
7998
|
+
fileSize,
|
|
7999
|
+
mimeType,
|
|
8000
|
+
formatFileSize
|
|
8001
|
+
}) {
|
|
8002
|
+
const [blobUrl, setBlobUrl] = React7.useState(null);
|
|
8003
|
+
const [failed, setFailed] = React7.useState(false);
|
|
8004
|
+
const isImage2 = mimeType.startsWith("image/");
|
|
8005
|
+
React7.useEffect(() => {
|
|
8006
|
+
let cancelled = false;
|
|
8007
|
+
let objectUrl = null;
|
|
8008
|
+
void (async () => {
|
|
8009
|
+
try {
|
|
8010
|
+
const jwt = await getToken();
|
|
8011
|
+
if (!jwt) throw new Error("No auth token");
|
|
8012
|
+
const res = await fetch(url, {
|
|
8013
|
+
headers: { Authorization: `Bearer ${jwt}` }
|
|
8014
|
+
});
|
|
8015
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
8016
|
+
const blob = await res.blob();
|
|
8017
|
+
if (cancelled) return;
|
|
8018
|
+
objectUrl = URL.createObjectURL(blob);
|
|
8019
|
+
setBlobUrl(objectUrl);
|
|
8020
|
+
} catch {
|
|
8021
|
+
if (!cancelled) setFailed(true);
|
|
8022
|
+
}
|
|
8023
|
+
})();
|
|
8024
|
+
return () => {
|
|
8025
|
+
cancelled = true;
|
|
8026
|
+
if (objectUrl) URL.revokeObjectURL(objectUrl);
|
|
8027
|
+
};
|
|
8028
|
+
}, [url, getToken]);
|
|
8029
|
+
if (failed) {
|
|
8030
|
+
return /* @__PURE__ */ jsxRuntime.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: [
|
|
8031
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0" }),
|
|
8032
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: fileName })
|
|
8033
|
+
] });
|
|
8034
|
+
}
|
|
8035
|
+
if (!blobUrl) {
|
|
8036
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8037
|
+
"div",
|
|
8038
|
+
{
|
|
8039
|
+
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",
|
|
8040
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 animate-spin text-muted-foreground" })
|
|
8041
|
+
}
|
|
8042
|
+
);
|
|
8043
|
+
}
|
|
8044
|
+
if (isImage2) {
|
|
8045
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8046
|
+
"a",
|
|
8047
|
+
{
|
|
8048
|
+
href: blobUrl,
|
|
8049
|
+
target: "_blank",
|
|
8050
|
+
rel: "noopener noreferrer",
|
|
8051
|
+
className: "block max-w-[200px] overflow-hidden rounded-lg border",
|
|
8052
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8053
|
+
"img",
|
|
8054
|
+
{
|
|
8055
|
+
src: blobUrl,
|
|
8056
|
+
alt: fileName,
|
|
8057
|
+
className: "h-auto w-full object-cover"
|
|
8058
|
+
}
|
|
8059
|
+
)
|
|
8060
|
+
}
|
|
8061
|
+
);
|
|
8062
|
+
}
|
|
8063
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8064
|
+
"a",
|
|
8065
|
+
{
|
|
8066
|
+
href: blobUrl,
|
|
8067
|
+
download: fileName,
|
|
8068
|
+
target: "_blank",
|
|
8069
|
+
rel: "noopener noreferrer",
|
|
8070
|
+
className: "flex items-center gap-2 rounded-lg border bg-muted/50 px-2 py-1.5 text-xs transition-colors hover:bg-muted",
|
|
8071
|
+
children: [
|
|
8072
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" }),
|
|
8073
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
8074
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate font-medium", children: fileName }),
|
|
8075
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-[10px] text-muted-foreground", children: formatFileSize(fileSize) })
|
|
8076
|
+
] }),
|
|
8077
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" })
|
|
8078
|
+
]
|
|
8079
|
+
}
|
|
8080
|
+
);
|
|
8081
|
+
}
|
|
7994
8082
|
var roleColors = {
|
|
7995
8083
|
client: "bg-blue-500/10 text-blue-600 dark:text-blue-400",
|
|
7996
8084
|
seller: "bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",
|
|
@@ -8278,44 +8366,18 @@ function ChatRoomView({
|
|
|
8278
8366
|
children: message.content
|
|
8279
8367
|
}
|
|
8280
8368
|
),
|
|
8281
|
-
message.attachments.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 flex flex-col gap-1", children: message.attachments.map(
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8293
|
-
alt: att.fileName,
|
|
8294
|
-
className: "h-auto w-full object-cover",
|
|
8295
|
-
loading: "lazy"
|
|
8296
|
-
}
|
|
8297
|
-
)
|
|
8298
|
-
},
|
|
8299
|
-
att.id
|
|
8300
|
-
) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8301
|
-
"a",
|
|
8302
|
-
{
|
|
8303
|
-
href: getAttachmentUrl(att.id),
|
|
8304
|
-
target: "_blank",
|
|
8305
|
-
rel: "noopener noreferrer",
|
|
8306
|
-
className: "flex items-center gap-2 rounded-lg border bg-muted/50 px-2 py-1.5 text-xs transition-colors hover:bg-muted",
|
|
8307
|
-
children: [
|
|
8308
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" }),
|
|
8309
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
8310
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate font-medium", children: att.fileName }),
|
|
8311
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-[10px] text-muted-foreground", children: formatFileSize(att.fileSize) })
|
|
8312
|
-
] }),
|
|
8313
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" })
|
|
8314
|
-
]
|
|
8315
|
-
},
|
|
8316
|
-
att.id
|
|
8317
|
-
)
|
|
8318
|
-
) }),
|
|
8369
|
+
message.attachments.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 flex flex-col gap-1", children: message.attachments.map((att) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
8370
|
+
AuthenticatedAttachment,
|
|
8371
|
+
{
|
|
8372
|
+
url: getAttachmentUrl(att.id),
|
|
8373
|
+
getToken: config.getToken,
|
|
8374
|
+
fileName: att.fileName,
|
|
8375
|
+
fileSize: att.fileSize,
|
|
8376
|
+
mimeType: att.mimeType,
|
|
8377
|
+
formatFileSize
|
|
8378
|
+
},
|
|
8379
|
+
att.id
|
|
8380
|
+
)) }),
|
|
8319
8381
|
isCurrentUser && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-0.5 flex items-center gap-0.5 text-[10px] text-muted-foreground", children: seen ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
8320
8382
|
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckCheck, { className: "h-3 w-3 text-primary" }),
|
|
8321
8383
|
/* @__PURE__ */ jsxRuntime.jsx("span", { children: labels.seen ?? "Seen" })
|
|
@@ -10899,6 +10961,26 @@ function CardInput({
|
|
|
10899
10961
|
)
|
|
10900
10962
|
] });
|
|
10901
10963
|
}
|
|
10964
|
+
|
|
10965
|
+
// src/lib/usAddress.ts
|
|
10966
|
+
function splitStreet(street) {
|
|
10967
|
+
const trimmed = street.trim();
|
|
10968
|
+
const m = trimmed.match(/^(\S+)\s+(.+)$/);
|
|
10969
|
+
if (m && /^\d/.test(m[1])) {
|
|
10970
|
+
return { number: m[1], name: m[2].trim() };
|
|
10971
|
+
}
|
|
10972
|
+
return { number: "", name: trimmed };
|
|
10973
|
+
}
|
|
10974
|
+
function joinStreet(streetNumber, streetName) {
|
|
10975
|
+
return [streetNumber, streetName].map((s) => s.trim()).filter((s) => s.length > 0).join(" ");
|
|
10976
|
+
}
|
|
10977
|
+
function sanitizeForNls(input) {
|
|
10978
|
+
return input.replace(/[^A-Za-z0-9 .,'#\-/]/g, " ").replace(/\s+/g, " ").trim();
|
|
10979
|
+
}
|
|
10980
|
+
function composeAddressLine1ForNls(v) {
|
|
10981
|
+
const line = [v.streetNumber, v.streetName, v.apt].filter((s) => typeof s === "string" && s.trim().length > 0).join(" ");
|
|
10982
|
+
return sanitizeForNls(line).slice(0, 40);
|
|
10983
|
+
}
|
|
10902
10984
|
function parseInitial(value) {
|
|
10903
10985
|
if (!value) {
|
|
10904
10986
|
return {
|
|
@@ -10919,6 +11001,28 @@ function parseInitial(value) {
|
|
|
10919
11001
|
country: "US"
|
|
10920
11002
|
};
|
|
10921
11003
|
}
|
|
11004
|
+
function legacyToModern(legacy) {
|
|
11005
|
+
return {
|
|
11006
|
+
street: joinStreet(legacy.streetNumber, legacy.streetName),
|
|
11007
|
+
street2: legacy.apt ?? "",
|
|
11008
|
+
city: legacy.city,
|
|
11009
|
+
state: legacy.state,
|
|
11010
|
+
zip: legacy.zipCode,
|
|
11011
|
+
country: "US"
|
|
11012
|
+
};
|
|
11013
|
+
}
|
|
11014
|
+
function toLegacy(modern) {
|
|
11015
|
+
const parts = splitStreet(modern.street);
|
|
11016
|
+
return {
|
|
11017
|
+
streetNumber: sanitizeForNls(parts.number),
|
|
11018
|
+
streetName: sanitizeForNls(parts.name),
|
|
11019
|
+
apt: modern.street2 ? sanitizeForNls(modern.street2) : void 0,
|
|
11020
|
+
city: modern.city.trim(),
|
|
11021
|
+
state: modern.state.trim().toUpperCase(),
|
|
11022
|
+
zipCode: modern.zip.replace(/\D/g, "").slice(0, 5),
|
|
11023
|
+
country: "US"
|
|
11024
|
+
};
|
|
11025
|
+
}
|
|
10922
11026
|
function addressSig(a) {
|
|
10923
11027
|
return JSON.stringify({
|
|
10924
11028
|
street: a.street.trim(),
|
|
@@ -10944,14 +11048,19 @@ function USAddressInput({
|
|
|
10944
11048
|
disabled = false,
|
|
10945
11049
|
largeText = false,
|
|
10946
11050
|
className,
|
|
10947
|
-
onError
|
|
11051
|
+
onError,
|
|
11052
|
+
legacyMode = false,
|
|
11053
|
+
valueLegacy,
|
|
11054
|
+
onChangeLegacy
|
|
10948
11055
|
}) {
|
|
10949
11056
|
const [searchQuery, setSearchQuery] = React7.useState("");
|
|
10950
11057
|
const [showSuggestions, setShowSuggestions] = React7.useState(false);
|
|
10951
11058
|
const [suggestions, setSuggestions] = React7.useState([]);
|
|
10952
|
-
const [address, setAddress] = React7.useState(
|
|
10953
|
-
()
|
|
10954
|
-
|
|
11059
|
+
const [address, setAddress] = React7.useState(() => {
|
|
11060
|
+
if (value != null) return parseInitial(value);
|
|
11061
|
+
if (valueLegacy != null) return legacyToModern(valueLegacy);
|
|
11062
|
+
return parseInitial(void 0);
|
|
11063
|
+
});
|
|
10955
11064
|
const [sessionToken] = React7.useState(
|
|
10956
11065
|
() => typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`
|
|
10957
11066
|
);
|
|
@@ -10973,6 +11082,22 @@ function USAddressInput({
|
|
|
10973
11082
|
const addressRef = React7.useRef(address);
|
|
10974
11083
|
addressRef.current = address;
|
|
10975
11084
|
const lastValidatedSigRef = React7.useRef("");
|
|
11085
|
+
const onChangeLegacyRef = React7.useRef(onChangeLegacy);
|
|
11086
|
+
onChangeLegacyRef.current = onChangeLegacy;
|
|
11087
|
+
const legacyModeRef = React7.useRef(legacyMode);
|
|
11088
|
+
legacyModeRef.current = legacyMode;
|
|
11089
|
+
const emitChange = React7.useRef((next) => {
|
|
11090
|
+
onChange(next);
|
|
11091
|
+
if (legacyModeRef.current && onChangeLegacyRef.current) {
|
|
11092
|
+
onChangeLegacyRef.current(toLegacy(next));
|
|
11093
|
+
}
|
|
11094
|
+
});
|
|
11095
|
+
emitChange.current = (next) => {
|
|
11096
|
+
onChange(next);
|
|
11097
|
+
if (legacyModeRef.current && onChangeLegacyRef.current) {
|
|
11098
|
+
onChangeLegacyRef.current(toLegacy(next));
|
|
11099
|
+
}
|
|
11100
|
+
};
|
|
10976
11101
|
const debouncedSearch = useDebouncedValue(searchQuery, 400);
|
|
10977
11102
|
const zipDigits = address.zip.replace(/\D/g, "").slice(0, 5);
|
|
10978
11103
|
const debouncedZip = useDebouncedValue(zipDigits, 400);
|
|
@@ -10989,13 +11114,18 @@ function USAddressInput({
|
|
|
10989
11114
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
10990
11115
|
}, []);
|
|
10991
11116
|
const valueSyncKey = value == null ? "" : `o:${JSON.stringify(value)}`;
|
|
11117
|
+
const valueLegacySyncKey = value != null || valueLegacy == null ? null : `l:${JSON.stringify(valueLegacy)}`;
|
|
10992
11118
|
React7.useEffect(() => {
|
|
10993
11119
|
setAddress(parseInitial(value));
|
|
10994
11120
|
}, [valueSyncKey]);
|
|
11121
|
+
React7.useEffect(() => {
|
|
11122
|
+
if (valueLegacySyncKey == null) return;
|
|
11123
|
+
setAddress(legacyToModern(valueLegacy));
|
|
11124
|
+
}, [valueLegacySyncKey]);
|
|
10995
11125
|
const handleFieldChange = (field, fieldValue) => {
|
|
10996
11126
|
setAddress((prev) => {
|
|
10997
11127
|
const next = field === "country" ? { ...prev, country: "US" } : { ...prev, [field]: fieldValue };
|
|
10998
|
-
|
|
11128
|
+
emitChange.current(next);
|
|
10999
11129
|
return next;
|
|
11000
11130
|
});
|
|
11001
11131
|
};
|
|
@@ -11067,7 +11197,7 @@ function USAddressInput({
|
|
|
11067
11197
|
if (cityEmpty && data.city) next.city = data.city;
|
|
11068
11198
|
if (stateEmpty && data.state) next.state = data.state;
|
|
11069
11199
|
next.country = "US";
|
|
11070
|
-
|
|
11200
|
+
emitChange.current(next);
|
|
11071
11201
|
return next;
|
|
11072
11202
|
});
|
|
11073
11203
|
}).catch(() => {
|
|
@@ -11081,7 +11211,6 @@ function USAddressInput({
|
|
|
11081
11211
|
debouncedZip,
|
|
11082
11212
|
allowZipLookup,
|
|
11083
11213
|
lookupZip,
|
|
11084
|
-
onChange,
|
|
11085
11214
|
labels.zipLookupFailed,
|
|
11086
11215
|
onError
|
|
11087
11216
|
]);
|
|
@@ -11143,7 +11272,7 @@ function USAddressInput({
|
|
|
11143
11272
|
country: "US"
|
|
11144
11273
|
};
|
|
11145
11274
|
setAddress(normalized);
|
|
11146
|
-
|
|
11275
|
+
emitChange.current(normalized);
|
|
11147
11276
|
setShowSuggestions(false);
|
|
11148
11277
|
setSearchQuery("");
|
|
11149
11278
|
setUspsSuggestion(null);
|
|
@@ -11156,7 +11285,7 @@ function USAddressInput({
|
|
|
11156
11285
|
const applyUspsSuggestion = () => {
|
|
11157
11286
|
if (!uspsSuggestion) return;
|
|
11158
11287
|
setAddress(uspsSuggestion);
|
|
11159
|
-
|
|
11288
|
+
emitChange.current(uspsSuggestion);
|
|
11160
11289
|
setUspsSuggestion(null);
|
|
11161
11290
|
lastValidatedSigRef.current = addressSig(uspsSuggestion);
|
|
11162
11291
|
setUspsVerifiedNoChange(true);
|
|
@@ -11544,6 +11673,808 @@ var FlagComponent = ({ country, countryName }) => {
|
|
|
11544
11673
|
const Flag2 = flags__default.default[country];
|
|
11545
11674
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex h-4 w-6 overflow-hidden rounded-sm bg-foreground/20 [&_svg:not([class*='size-'])]:size-full", children: Flag2 && /* @__PURE__ */ jsxRuntime.jsx(Flag2, { title: countryName }) });
|
|
11546
11675
|
};
|
|
11676
|
+
function defaultPageOf(page, total) {
|
|
11677
|
+
return `${page} / ${total}`;
|
|
11678
|
+
}
|
|
11679
|
+
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)`.";
|
|
11680
|
+
function buildGetDocumentArgs(src, documentOptions) {
|
|
11681
|
+
const rest = documentOptions ?? {};
|
|
11682
|
+
if (typeof src === "string") {
|
|
11683
|
+
return { url: src, ...rest };
|
|
11684
|
+
}
|
|
11685
|
+
return { data: src, ...rest };
|
|
11686
|
+
}
|
|
11687
|
+
function PdfPageCanvas({
|
|
11688
|
+
page,
|
|
11689
|
+
layout,
|
|
11690
|
+
scale,
|
|
11691
|
+
visible,
|
|
11692
|
+
pageClassName
|
|
11693
|
+
}) {
|
|
11694
|
+
const canvasRef = React7.useRef(null);
|
|
11695
|
+
const taskRef = React7.useRef(null);
|
|
11696
|
+
React7.useEffect(() => {
|
|
11697
|
+
if (!visible || !canvasRef.current) {
|
|
11698
|
+
taskRef.current?.cancel();
|
|
11699
|
+
taskRef.current = null;
|
|
11700
|
+
const c = canvasRef.current;
|
|
11701
|
+
if (c) {
|
|
11702
|
+
const ctx2 = c.getContext("2d");
|
|
11703
|
+
if (ctx2) {
|
|
11704
|
+
ctx2.setTransform(1, 0, 0, 1, 0, 0);
|
|
11705
|
+
ctx2.clearRect(0, 0, c.width, c.height);
|
|
11706
|
+
}
|
|
11707
|
+
}
|
|
11708
|
+
return;
|
|
11709
|
+
}
|
|
11710
|
+
const canvas = canvasRef.current;
|
|
11711
|
+
const ctx = canvas.getContext("2d");
|
|
11712
|
+
if (!ctx) return;
|
|
11713
|
+
const viewport = page.getViewport({ scale });
|
|
11714
|
+
canvas.width = viewport.width;
|
|
11715
|
+
canvas.height = viewport.height;
|
|
11716
|
+
const task = page.render({
|
|
11717
|
+
canvasContext: ctx,
|
|
11718
|
+
viewport,
|
|
11719
|
+
canvas
|
|
11720
|
+
});
|
|
11721
|
+
taskRef.current = task;
|
|
11722
|
+
task.promise.catch(() => {
|
|
11723
|
+
});
|
|
11724
|
+
return () => {
|
|
11725
|
+
task.cancel();
|
|
11726
|
+
if (taskRef.current === task) {
|
|
11727
|
+
taskRef.current = null;
|
|
11728
|
+
}
|
|
11729
|
+
};
|
|
11730
|
+
}, [page, visible, scale]);
|
|
11731
|
+
const w = layout.widthPt * scale;
|
|
11732
|
+
const h = layout.heightPt * scale;
|
|
11733
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11734
|
+
"div",
|
|
11735
|
+
{
|
|
11736
|
+
className: cn("relative flex justify-center bg-muted/40", pageClassName),
|
|
11737
|
+
style: { width: w, height: h },
|
|
11738
|
+
"data-page": layout.pageNumber,
|
|
11739
|
+
children: visible ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
11740
|
+
"canvas",
|
|
11741
|
+
{
|
|
11742
|
+
ref: canvasRef,
|
|
11743
|
+
className: "block max-h-full shadow-sm",
|
|
11744
|
+
"aria-hidden": "true"
|
|
11745
|
+
}
|
|
11746
|
+
) : null
|
|
11747
|
+
}
|
|
11748
|
+
);
|
|
11749
|
+
}
|
|
11750
|
+
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";
|
|
11751
|
+
function touchPairDistance(touches) {
|
|
11752
|
+
if (touches.length < 2) return 0;
|
|
11753
|
+
const a = touches.item(0);
|
|
11754
|
+
const b = touches.item(1);
|
|
11755
|
+
return Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY);
|
|
11756
|
+
}
|
|
11757
|
+
function PdfThumbnailStrip({
|
|
11758
|
+
page,
|
|
11759
|
+
pageNumber,
|
|
11760
|
+
active,
|
|
11761
|
+
onPick,
|
|
11762
|
+
label
|
|
11763
|
+
}) {
|
|
11764
|
+
const canvasRef = React7.useRef(null);
|
|
11765
|
+
React7.useEffect(() => {
|
|
11766
|
+
const canvas = canvasRef.current;
|
|
11767
|
+
if (!canvas) return;
|
|
11768
|
+
const viewport = page.getViewport({ scale: 1 });
|
|
11769
|
+
const thumbMax = 176;
|
|
11770
|
+
const s = thumbMax / Math.max(viewport.width, viewport.height);
|
|
11771
|
+
const vp = page.getViewport({ scale: s });
|
|
11772
|
+
const ctx = canvas.getContext("2d");
|
|
11773
|
+
if (!ctx) return;
|
|
11774
|
+
canvas.width = vp.width;
|
|
11775
|
+
canvas.height = vp.height;
|
|
11776
|
+
const task = page.render({
|
|
11777
|
+
canvasContext: ctx,
|
|
11778
|
+
viewport: vp,
|
|
11779
|
+
canvas
|
|
11780
|
+
});
|
|
11781
|
+
task.promise.catch(() => {
|
|
11782
|
+
});
|
|
11783
|
+
return () => {
|
|
11784
|
+
task.cancel();
|
|
11785
|
+
};
|
|
11786
|
+
}, [page]);
|
|
11787
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11788
|
+
"button",
|
|
11789
|
+
{
|
|
11790
|
+
type: "button",
|
|
11791
|
+
onClick: () => onPick(pageNumber),
|
|
11792
|
+
className: cn(
|
|
11793
|
+
"flex w-full flex-col items-center gap-1 rounded-md p-2 transition-colors hover:bg-white/5",
|
|
11794
|
+
active ? "bg-white/10" : ""
|
|
11795
|
+
),
|
|
11796
|
+
"aria-label": label,
|
|
11797
|
+
"aria-current": active ? "page" : void 0,
|
|
11798
|
+
children: [
|
|
11799
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11800
|
+
"canvas",
|
|
11801
|
+
{
|
|
11802
|
+
ref: canvasRef,
|
|
11803
|
+
className: "block max-w-full overflow-hidden rounded-sm bg-black",
|
|
11804
|
+
"aria-hidden": true
|
|
11805
|
+
}
|
|
11806
|
+
),
|
|
11807
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px] tabular-nums text-neutral-400", children: pageNumber })
|
|
11808
|
+
]
|
|
11809
|
+
}
|
|
11810
|
+
);
|
|
11811
|
+
}
|
|
11812
|
+
function PdfViewer({
|
|
11813
|
+
src,
|
|
11814
|
+
workerSrc,
|
|
11815
|
+
documentOptions,
|
|
11816
|
+
initialPage = 1,
|
|
11817
|
+
initialScale = 1,
|
|
11818
|
+
minScale = 0.5,
|
|
11819
|
+
maxScale = 4,
|
|
11820
|
+
scaleStep = 0.2,
|
|
11821
|
+
enableKeyboardShortcuts = true,
|
|
11822
|
+
enablePinchZoom = true,
|
|
11823
|
+
enableThumbnailSidebar = true,
|
|
11824
|
+
thumbnailSidebarDefaultOpen = true,
|
|
11825
|
+
labels,
|
|
11826
|
+
onLoad,
|
|
11827
|
+
onError,
|
|
11828
|
+
onPageChange,
|
|
11829
|
+
onScaleChange,
|
|
11830
|
+
className,
|
|
11831
|
+
toolbarClassName,
|
|
11832
|
+
pageClassName,
|
|
11833
|
+
toolbarEndSlot
|
|
11834
|
+
}) {
|
|
11835
|
+
const mergedLabels = labels ?? {};
|
|
11836
|
+
const toolbarLabel = mergedLabels.toolbar ?? "PDF controls";
|
|
11837
|
+
const loadingLabel = mergedLabels.loading ?? "Loading PDF\u2026";
|
|
11838
|
+
const workerErrorMessage = mergedLabels.workerMissing ?? DEFAULT_WORKER_MSG;
|
|
11839
|
+
const errorLabelFallback = mergedLabels.error ?? "Failed to load PDF";
|
|
11840
|
+
const toolbarId = React7.useId();
|
|
11841
|
+
const pageInputId = `${toolbarId}-page`;
|
|
11842
|
+
const thumbnailNavId = `${toolbarId}-thumbnails`;
|
|
11843
|
+
const scrollRef = React7.useRef(null);
|
|
11844
|
+
const observerRef = React7.useRef(null);
|
|
11845
|
+
const lastReportedPage = React7.useRef(0);
|
|
11846
|
+
const loadedPdfRef = React7.useRef(null);
|
|
11847
|
+
const [loadError, setLoadError] = React7.useState(null);
|
|
11848
|
+
const [busy, setBusy] = React7.useState(false);
|
|
11849
|
+
const [layouts, setLayouts] = React7.useState([]);
|
|
11850
|
+
const [pagesMap, setPagesMap] = React7.useState(
|
|
11851
|
+
null
|
|
11852
|
+
);
|
|
11853
|
+
const [scale, setScale] = React7.useState(initialScale);
|
|
11854
|
+
const [ratios, setRatios] = React7.useState({});
|
|
11855
|
+
const [pageInput, setPageInput] = React7.useState(String(initialPage));
|
|
11856
|
+
const [thumbnailSidebarOpen, setThumbnailSidebarOpen] = React7.useState(
|
|
11857
|
+
thumbnailSidebarDefaultOpen
|
|
11858
|
+
);
|
|
11859
|
+
const baselineScaleRef = React7.useRef(initialScale);
|
|
11860
|
+
React7.useEffect(() => {
|
|
11861
|
+
baselineScaleRef.current = initialScale;
|
|
11862
|
+
}, [initialScale]);
|
|
11863
|
+
const pageOfFormatter = mergedLabels.pageOf ?? defaultPageOf;
|
|
11864
|
+
const resolvedGoToLabel = mergedLabels.goToPage ?? "Go to page";
|
|
11865
|
+
const zoomInLabel = mergedLabels.zoomIn ?? "Zoom in";
|
|
11866
|
+
const zoomOutLabel = mergedLabels.zoomOut ?? "Zoom out";
|
|
11867
|
+
const resetZoomLabel = mergedLabels.resetZoom ?? "Reset zoom";
|
|
11868
|
+
const fitWidthLabel = mergedLabels.fitToWidth ?? "Fit to width";
|
|
11869
|
+
const thumbnailSidebarLabel = mergedLabels.thumbnailSidebar ?? "Page thumbnails";
|
|
11870
|
+
const toggleThumbLabel = mergedLabels.toggleThumbnailSidebar ?? "Toggle page thumbnails";
|
|
11871
|
+
const pageThumbLabel = mergedLabels.pageThumbnail ?? ((n) => `Page ${n}, show in document`);
|
|
11872
|
+
const pageCount = layouts.length;
|
|
11873
|
+
const currentVisiblePage = React7.useMemo(() => {
|
|
11874
|
+
let bestPage = 1;
|
|
11875
|
+
let bestRatio = -1;
|
|
11876
|
+
for (const layout of layouts) {
|
|
11877
|
+
const r2 = ratios[layout.pageNumber] ?? 0;
|
|
11878
|
+
if (r2 > bestRatio) {
|
|
11879
|
+
bestRatio = r2;
|
|
11880
|
+
bestPage = layout.pageNumber;
|
|
11881
|
+
}
|
|
11882
|
+
}
|
|
11883
|
+
return bestRatio >= 0.01 ? bestPage : 1;
|
|
11884
|
+
}, [layouts, ratios]);
|
|
11885
|
+
const clampScaleValue = React7.useCallback(
|
|
11886
|
+
(v) => Math.min(maxScale, Math.max(minScale, v)),
|
|
11887
|
+
[minScale, maxScale]
|
|
11888
|
+
);
|
|
11889
|
+
const zoomInAct = React7.useCallback(() => {
|
|
11890
|
+
setScale((prev) => {
|
|
11891
|
+
const c = clampScaleValue(prev + scaleStep);
|
|
11892
|
+
onScaleChange?.(c);
|
|
11893
|
+
return c;
|
|
11894
|
+
});
|
|
11895
|
+
}, [clampScaleValue, onScaleChange, scaleStep]);
|
|
11896
|
+
const zoomOutAct = React7.useCallback(() => {
|
|
11897
|
+
setScale((prev) => {
|
|
11898
|
+
const c = clampScaleValue(prev - scaleStep);
|
|
11899
|
+
onScaleChange?.(c);
|
|
11900
|
+
return c;
|
|
11901
|
+
});
|
|
11902
|
+
}, [clampScaleValue, onScaleChange, scaleStep]);
|
|
11903
|
+
const resetZoomAct = React7.useCallback(() => {
|
|
11904
|
+
const c = clampScaleValue(baselineScaleRef.current);
|
|
11905
|
+
setScale(c);
|
|
11906
|
+
onScaleChange?.(c);
|
|
11907
|
+
}, [clampScaleValue, onScaleChange]);
|
|
11908
|
+
const fitToWidthAct = React7.useCallback(() => {
|
|
11909
|
+
const root = scrollRef.current;
|
|
11910
|
+
if (!root || layouts.length === 0) return;
|
|
11911
|
+
const avail = Math.max(root.clientWidth - 32, 120);
|
|
11912
|
+
const maxW = Math.max(...layouts.map((l) => l.widthPt), 1);
|
|
11913
|
+
const next = clampScaleValue(avail / maxW);
|
|
11914
|
+
setScale(next);
|
|
11915
|
+
onScaleChange?.(next);
|
|
11916
|
+
}, [clampScaleValue, layouts, onScaleChange]);
|
|
11917
|
+
React7.useEffect(() => {
|
|
11918
|
+
setPageInput(String(currentVisiblePage));
|
|
11919
|
+
if (lastReportedPage.current !== currentVisiblePage) {
|
|
11920
|
+
lastReportedPage.current = currentVisiblePage;
|
|
11921
|
+
onPageChange?.(currentVisiblePage);
|
|
11922
|
+
}
|
|
11923
|
+
}, [currentVisiblePage, onPageChange]);
|
|
11924
|
+
const scrollToPage = React7.useCallback((pageNum) => {
|
|
11925
|
+
const root = scrollRef.current;
|
|
11926
|
+
if (!root || pageNum < 1) return;
|
|
11927
|
+
const el = root.querySelector(`[data-page="${pageNum}"]`);
|
|
11928
|
+
if (el instanceof HTMLElement) {
|
|
11929
|
+
el.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
11930
|
+
}
|
|
11931
|
+
}, []);
|
|
11932
|
+
React7.useEffect(() => {
|
|
11933
|
+
if (!busy && pagesMap && pageCount > 0) {
|
|
11934
|
+
const p = Math.min(Math.max(1, initialPage), pageCount);
|
|
11935
|
+
requestAnimationFrame(() => scrollToPage(p));
|
|
11936
|
+
}
|
|
11937
|
+
}, [busy, pagesMap, pageCount, initialPage, scrollToPage]);
|
|
11938
|
+
const loadKey = React7.useMemo(() => {
|
|
11939
|
+
if (typeof src === "string") return src;
|
|
11940
|
+
if (src instanceof ArrayBuffer) return `ab:${src.byteLength}`;
|
|
11941
|
+
return `ua:${src.byteLength}:${src.byteOffset}:${src.buffer.byteLength}`;
|
|
11942
|
+
}, [src]);
|
|
11943
|
+
React7.useEffect(() => {
|
|
11944
|
+
let cancelled = false;
|
|
11945
|
+
let activeDoc = null;
|
|
11946
|
+
setLoadError(null);
|
|
11947
|
+
if (loadedPdfRef.current) {
|
|
11948
|
+
void loadedPdfRef.current.destroy();
|
|
11949
|
+
loadedPdfRef.current = null;
|
|
11950
|
+
}
|
|
11951
|
+
setLayouts([]);
|
|
11952
|
+
setPagesMap(null);
|
|
11953
|
+
setRatios({});
|
|
11954
|
+
const trimmedWorker = workerSrc?.trim?.() ?? "";
|
|
11955
|
+
if (!trimmedWorker) {
|
|
11956
|
+
setLoadError(workerErrorMessage);
|
|
11957
|
+
onError?.(new Error(workerErrorMessage));
|
|
11958
|
+
return () => {
|
|
11959
|
+
cancelled = true;
|
|
11960
|
+
};
|
|
11961
|
+
}
|
|
11962
|
+
void (async () => {
|
|
11963
|
+
try {
|
|
11964
|
+
setBusy(true);
|
|
11965
|
+
const pdfjs = await import('pdfjs-dist');
|
|
11966
|
+
if (cancelled) return;
|
|
11967
|
+
pdfjs.GlobalWorkerOptions.workerSrc = trimmedWorker;
|
|
11968
|
+
const loadingTask = pdfjs.getDocument(
|
|
11969
|
+
buildGetDocumentArgs(src, documentOptions)
|
|
11970
|
+
);
|
|
11971
|
+
activeDoc = await loadingTask.promise;
|
|
11972
|
+
if (cancelled) {
|
|
11973
|
+
void activeDoc.destroy();
|
|
11974
|
+
activeDoc = null;
|
|
11975
|
+
return;
|
|
11976
|
+
}
|
|
11977
|
+
const layoutsLocal = [];
|
|
11978
|
+
const mapLocal = /* @__PURE__ */ new Map();
|
|
11979
|
+
for (let p = 1; p <= activeDoc.numPages; p++) {
|
|
11980
|
+
const page = await activeDoc.getPage(p);
|
|
11981
|
+
mapLocal.set(p, page);
|
|
11982
|
+
const viewport = page.getViewport({ scale: 1 });
|
|
11983
|
+
layoutsLocal.push({
|
|
11984
|
+
pageNumber: p,
|
|
11985
|
+
widthPt: viewport.width,
|
|
11986
|
+
heightPt: viewport.height
|
|
11987
|
+
});
|
|
11988
|
+
}
|
|
11989
|
+
if (cancelled) {
|
|
11990
|
+
void activeDoc.destroy();
|
|
11991
|
+
activeDoc = null;
|
|
11992
|
+
return;
|
|
11993
|
+
}
|
|
11994
|
+
onLoad?.(activeDoc);
|
|
11995
|
+
loadedPdfRef.current = activeDoc;
|
|
11996
|
+
setLayouts(layoutsLocal);
|
|
11997
|
+
setPagesMap(mapLocal);
|
|
11998
|
+
activeDoc = null;
|
|
11999
|
+
} catch (e) {
|
|
12000
|
+
const err = e instanceof Error ? e : new Error(String(e));
|
|
12001
|
+
if (!cancelled) {
|
|
12002
|
+
setLoadError(errorLabelFallback);
|
|
12003
|
+
onError?.(err);
|
|
12004
|
+
}
|
|
12005
|
+
if (activeDoc) {
|
|
12006
|
+
void activeDoc.destroy();
|
|
12007
|
+
activeDoc = null;
|
|
12008
|
+
}
|
|
12009
|
+
} finally {
|
|
12010
|
+
if (!cancelled) setBusy(false);
|
|
12011
|
+
}
|
|
12012
|
+
})();
|
|
12013
|
+
return () => {
|
|
12014
|
+
cancelled = true;
|
|
12015
|
+
if (observerRef.current) {
|
|
12016
|
+
observerRef.current.disconnect();
|
|
12017
|
+
observerRef.current = null;
|
|
12018
|
+
}
|
|
12019
|
+
if (activeDoc) {
|
|
12020
|
+
void activeDoc.destroy();
|
|
12021
|
+
}
|
|
12022
|
+
if (loadedPdfRef.current) {
|
|
12023
|
+
void loadedPdfRef.current.destroy();
|
|
12024
|
+
loadedPdfRef.current = null;
|
|
12025
|
+
}
|
|
12026
|
+
};
|
|
12027
|
+
}, [workerSrc, loadKey, documentOptions]);
|
|
12028
|
+
React7.useEffect(() => {
|
|
12029
|
+
setScale(clampScaleValue(initialScale));
|
|
12030
|
+
}, [initialScale, clampScaleValue]);
|
|
12031
|
+
React7.useEffect(() => {
|
|
12032
|
+
const el = scrollRef.current;
|
|
12033
|
+
if (!el || !enablePinchZoom) return;
|
|
12034
|
+
let pinchDist = 0;
|
|
12035
|
+
const onWheel = (e) => {
|
|
12036
|
+
if (!e.ctrlKey) return;
|
|
12037
|
+
e.preventDefault();
|
|
12038
|
+
const delta = -e.deltaY;
|
|
12039
|
+
const factor = Math.exp(delta * 2e-3);
|
|
12040
|
+
setScale((prev) => {
|
|
12041
|
+
const c = clampScaleValue(prev * factor);
|
|
12042
|
+
onScaleChange?.(c);
|
|
12043
|
+
return c;
|
|
12044
|
+
});
|
|
12045
|
+
};
|
|
12046
|
+
const onTouchStart = (e) => {
|
|
12047
|
+
if (e.touches.length === 2) {
|
|
12048
|
+
pinchDist = touchPairDistance(e.touches);
|
|
12049
|
+
}
|
|
12050
|
+
};
|
|
12051
|
+
const onTouchMove = (e) => {
|
|
12052
|
+
if (e.touches.length !== 2 || pinchDist <= 0) return;
|
|
12053
|
+
e.preventDefault();
|
|
12054
|
+
const d = touchPairDistance(e.touches);
|
|
12055
|
+
const ratio = d / pinchDist;
|
|
12056
|
+
pinchDist = d;
|
|
12057
|
+
setScale((prev) => {
|
|
12058
|
+
const c = clampScaleValue(prev * ratio);
|
|
12059
|
+
onScaleChange?.(c);
|
|
12060
|
+
return c;
|
|
12061
|
+
});
|
|
12062
|
+
};
|
|
12063
|
+
const endPinch = (e) => {
|
|
12064
|
+
if (e.touches.length < 2) pinchDist = 0;
|
|
12065
|
+
};
|
|
12066
|
+
el.addEventListener("wheel", onWheel, { passive: false });
|
|
12067
|
+
el.addEventListener("touchstart", onTouchStart, { passive: true });
|
|
12068
|
+
el.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
12069
|
+
el.addEventListener("touchend", endPinch);
|
|
12070
|
+
el.addEventListener("touchcancel", endPinch);
|
|
12071
|
+
return () => {
|
|
12072
|
+
el.removeEventListener("wheel", onWheel);
|
|
12073
|
+
el.removeEventListener("touchstart", onTouchStart);
|
|
12074
|
+
el.removeEventListener("touchmove", onTouchMove);
|
|
12075
|
+
el.removeEventListener("touchend", endPinch);
|
|
12076
|
+
el.removeEventListener("touchcancel", endPinch);
|
|
12077
|
+
};
|
|
12078
|
+
}, [enablePinchZoom, clampScaleValue, onScaleChange]);
|
|
12079
|
+
React7.useEffect(() => {
|
|
12080
|
+
if (layouts.length === 0) return;
|
|
12081
|
+
const frame = requestAnimationFrame(() => {
|
|
12082
|
+
const root = scrollRef.current;
|
|
12083
|
+
if (!root) return;
|
|
12084
|
+
if (observerRef.current) {
|
|
12085
|
+
observerRef.current.disconnect();
|
|
12086
|
+
}
|
|
12087
|
+
const io = new IntersectionObserver(
|
|
12088
|
+
(entries) => {
|
|
12089
|
+
setRatios((prev) => {
|
|
12090
|
+
const next = { ...prev };
|
|
12091
|
+
for (const e of entries) {
|
|
12092
|
+
const tgt = e.target;
|
|
12093
|
+
const p = Number(tgt.dataset.page);
|
|
12094
|
+
if (Number.isFinite(p)) next[p] = e.intersectionRatio;
|
|
12095
|
+
}
|
|
12096
|
+
return next;
|
|
12097
|
+
});
|
|
12098
|
+
},
|
|
12099
|
+
{
|
|
12100
|
+
root,
|
|
12101
|
+
rootMargin: "200px 0px",
|
|
12102
|
+
threshold: [0, 0.05, 0.25, 0.5, 0.75, 1]
|
|
12103
|
+
}
|
|
12104
|
+
);
|
|
12105
|
+
observerRef.current = io;
|
|
12106
|
+
root.querySelectorAll("[data-page]").forEach((el) => io.observe(el));
|
|
12107
|
+
});
|
|
12108
|
+
return () => {
|
|
12109
|
+
cancelAnimationFrame(frame);
|
|
12110
|
+
if (observerRef.current) {
|
|
12111
|
+
observerRef.current.disconnect();
|
|
12112
|
+
observerRef.current = null;
|
|
12113
|
+
}
|
|
12114
|
+
};
|
|
12115
|
+
}, [layouts]);
|
|
12116
|
+
const handleSubmitPage = React7.useCallback(() => {
|
|
12117
|
+
const n = Number.parseInt(pageInput, 10);
|
|
12118
|
+
if (!Number.isFinite(n) || pageCount === 0) return;
|
|
12119
|
+
const clamped = Math.min(Math.max(1, n), pageCount);
|
|
12120
|
+
scrollToPage(clamped);
|
|
12121
|
+
setPageInput(String(clamped));
|
|
12122
|
+
}, [pageInput, pageCount, scrollToPage]);
|
|
12123
|
+
const handleKeyDown = React7.useCallback(
|
|
12124
|
+
(e) => {
|
|
12125
|
+
if (!enableKeyboardShortcuts) return;
|
|
12126
|
+
if (e.target !== e.currentTarget && e.target instanceof HTMLInputElement) {
|
|
12127
|
+
return;
|
|
12128
|
+
}
|
|
12129
|
+
let handled = false;
|
|
12130
|
+
switch (e.key) {
|
|
12131
|
+
case "PageDown": {
|
|
12132
|
+
scrollToPage(Math.min(pageCount || 1, currentVisiblePage + 1));
|
|
12133
|
+
handled = true;
|
|
12134
|
+
break;
|
|
12135
|
+
}
|
|
12136
|
+
case "PageUp": {
|
|
12137
|
+
scrollToPage(Math.max(1, currentVisiblePage - 1));
|
|
12138
|
+
handled = true;
|
|
12139
|
+
break;
|
|
12140
|
+
}
|
|
12141
|
+
case "Home": {
|
|
12142
|
+
scrollToPage(1);
|
|
12143
|
+
handled = true;
|
|
12144
|
+
break;
|
|
12145
|
+
}
|
|
12146
|
+
case "End": {
|
|
12147
|
+
if (pageCount) scrollToPage(pageCount);
|
|
12148
|
+
handled = true;
|
|
12149
|
+
break;
|
|
12150
|
+
}
|
|
12151
|
+
case "+":
|
|
12152
|
+
case "=": {
|
|
12153
|
+
zoomInAct();
|
|
12154
|
+
handled = true;
|
|
12155
|
+
break;
|
|
12156
|
+
}
|
|
12157
|
+
case "-":
|
|
12158
|
+
case "_": {
|
|
12159
|
+
zoomOutAct();
|
|
12160
|
+
handled = true;
|
|
12161
|
+
break;
|
|
12162
|
+
}
|
|
12163
|
+
case "0": {
|
|
12164
|
+
resetZoomAct();
|
|
12165
|
+
handled = true;
|
|
12166
|
+
break;
|
|
12167
|
+
}
|
|
12168
|
+
}
|
|
12169
|
+
if (handled) {
|
|
12170
|
+
e.preventDefault();
|
|
12171
|
+
e.stopPropagation();
|
|
12172
|
+
}
|
|
12173
|
+
},
|
|
12174
|
+
[
|
|
12175
|
+
enableKeyboardShortcuts,
|
|
12176
|
+
pageCount,
|
|
12177
|
+
currentVisiblePage,
|
|
12178
|
+
scrollToPage,
|
|
12179
|
+
zoomInAct,
|
|
12180
|
+
zoomOutAct,
|
|
12181
|
+
resetZoomAct
|
|
12182
|
+
]
|
|
12183
|
+
);
|
|
12184
|
+
const thumbnailsRailEligible = enableThumbnailSidebar && !busy && pagesMap !== null && pageCount > 0;
|
|
12185
|
+
if (loadError) {
|
|
12186
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12187
|
+
"div",
|
|
12188
|
+
{
|
|
12189
|
+
className: cn("rounded-md border border-destructive/50 p-4", className),
|
|
12190
|
+
role: "alert",
|
|
12191
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-destructive text-sm", children: loadError })
|
|
12192
|
+
}
|
|
12193
|
+
);
|
|
12194
|
+
}
|
|
12195
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12196
|
+
"div",
|
|
12197
|
+
{
|
|
12198
|
+
className: cn(
|
|
12199
|
+
"flex min-h-0 flex-col overflow-hidden rounded-md border",
|
|
12200
|
+
className
|
|
12201
|
+
),
|
|
12202
|
+
children: [
|
|
12203
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
12204
|
+
"div",
|
|
12205
|
+
{
|
|
12206
|
+
id: toolbarId,
|
|
12207
|
+
role: "toolbar",
|
|
12208
|
+
"aria-label": toolbarLabel,
|
|
12209
|
+
className: cn(
|
|
12210
|
+
"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",
|
|
12211
|
+
toolbarClassName
|
|
12212
|
+
),
|
|
12213
|
+
children: [
|
|
12214
|
+
thumbnailsRailEligible ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
12215
|
+
Button,
|
|
12216
|
+
{
|
|
12217
|
+
type: "button",
|
|
12218
|
+
variant: "outline",
|
|
12219
|
+
size: "icon-sm",
|
|
12220
|
+
className: "hidden md:inline-flex",
|
|
12221
|
+
onClick: () => setThumbnailSidebarOpen((v) => !v),
|
|
12222
|
+
"aria-label": toggleThumbLabel,
|
|
12223
|
+
"aria-expanded": thumbnailSidebarOpen,
|
|
12224
|
+
"aria-controls": thumbnailNavId,
|
|
12225
|
+
children: thumbnailSidebarOpen ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.PanelLeftOpen, { className: "size-4", "aria-hidden": true }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.PanelRightOpen, { className: "size-4", "aria-hidden": true })
|
|
12226
|
+
}
|
|
12227
|
+
) : null,
|
|
12228
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-xs tabular-nums sm:text-sm", children: busy || pagesMap === null ? "\u2014" : pageOfFormatter(currentVisiblePage, pageCount) }),
|
|
12229
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: pageInputId, className: "sr-only", children: resolvedGoToLabel }),
|
|
12230
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12231
|
+
"input",
|
|
12232
|
+
{
|
|
12233
|
+
id: pageInputId,
|
|
12234
|
+
type: "number",
|
|
12235
|
+
min: 1,
|
|
12236
|
+
max: Math.max(pageCount, 1),
|
|
12237
|
+
disabled: busy || pageCount === 0,
|
|
12238
|
+
className: PAGE_INPUT_CLASS,
|
|
12239
|
+
"aria-label": resolvedGoToLabel,
|
|
12240
|
+
value: pageInput,
|
|
12241
|
+
onChange: (ev) => setPageInput(ev.target.value),
|
|
12242
|
+
onKeyDown: (ev) => {
|
|
12243
|
+
if (ev.key === "Enter") {
|
|
12244
|
+
ev.preventDefault();
|
|
12245
|
+
handleSubmitPage();
|
|
12246
|
+
}
|
|
12247
|
+
}
|
|
12248
|
+
}
|
|
12249
|
+
),
|
|
12250
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12251
|
+
Button,
|
|
12252
|
+
{
|
|
12253
|
+
type: "button",
|
|
12254
|
+
variant: "outline",
|
|
12255
|
+
size: "icon-sm",
|
|
12256
|
+
onClick: zoomOutAct,
|
|
12257
|
+
disabled: busy || scale <= minScale,
|
|
12258
|
+
"aria-label": zoomOutLabel,
|
|
12259
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ZoomOut, { "aria-hidden": true })
|
|
12260
|
+
}
|
|
12261
|
+
),
|
|
12262
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12263
|
+
Button,
|
|
12264
|
+
{
|
|
12265
|
+
type: "button",
|
|
12266
|
+
variant: "outline",
|
|
12267
|
+
size: "icon-sm",
|
|
12268
|
+
onClick: zoomInAct,
|
|
12269
|
+
disabled: busy || scale >= maxScale,
|
|
12270
|
+
"aria-label": zoomInLabel,
|
|
12271
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ZoomIn, { "aria-hidden": true })
|
|
12272
|
+
}
|
|
12273
|
+
),
|
|
12274
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12275
|
+
Button,
|
|
12276
|
+
{
|
|
12277
|
+
type: "button",
|
|
12278
|
+
variant: "outline",
|
|
12279
|
+
size: "icon-sm",
|
|
12280
|
+
onClick: resetZoomAct,
|
|
12281
|
+
disabled: busy,
|
|
12282
|
+
"aria-label": resetZoomLabel,
|
|
12283
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { "aria-hidden": true })
|
|
12284
|
+
}
|
|
12285
|
+
),
|
|
12286
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12287
|
+
Button,
|
|
12288
|
+
{
|
|
12289
|
+
type: "button",
|
|
12290
|
+
variant: "outline",
|
|
12291
|
+
size: "icon-sm",
|
|
12292
|
+
onClick: fitToWidthAct,
|
|
12293
|
+
disabled: busy || pageCount === 0,
|
|
12294
|
+
"aria-label": fitWidthLabel,
|
|
12295
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Maximize2, { "aria-hidden": true })
|
|
12296
|
+
}
|
|
12297
|
+
),
|
|
12298
|
+
toolbarEndSlot
|
|
12299
|
+
]
|
|
12300
|
+
}
|
|
12301
|
+
),
|
|
12302
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-0 flex-1 overflow-hidden", children: [
|
|
12303
|
+
thumbnailsRailEligible && thumbnailSidebarOpen ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
12304
|
+
"nav",
|
|
12305
|
+
{
|
|
12306
|
+
id: thumbnailNavId,
|
|
12307
|
+
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",
|
|
12308
|
+
"aria-label": thumbnailSidebarLabel,
|
|
12309
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: layouts.map((layout) => {
|
|
12310
|
+
const pg = pagesMap.get(layout.pageNumber);
|
|
12311
|
+
return pg ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
12312
|
+
PdfThumbnailStrip,
|
|
12313
|
+
{
|
|
12314
|
+
page: pg,
|
|
12315
|
+
pageNumber: layout.pageNumber,
|
|
12316
|
+
active: layout.pageNumber === currentVisiblePage,
|
|
12317
|
+
onPick: scrollToPage,
|
|
12318
|
+
label: pageThumbLabel(layout.pageNumber)
|
|
12319
|
+
},
|
|
12320
|
+
`thumb-${layout.pageNumber}`
|
|
12321
|
+
) : null;
|
|
12322
|
+
}) })
|
|
12323
|
+
}
|
|
12324
|
+
) : null,
|
|
12325
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12326
|
+
"div",
|
|
12327
|
+
{
|
|
12328
|
+
ref: scrollRef,
|
|
12329
|
+
tabIndex: 0,
|
|
12330
|
+
onKeyDown: handleKeyDown,
|
|
12331
|
+
className: "relative min-h-[240px] min-w-0 flex-1 overflow-auto outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
12332
|
+
"aria-busy": busy,
|
|
12333
|
+
"aria-label": busy ? loadingLabel : "PDF pages",
|
|
12334
|
+
children: busy || pagesMap === null ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground p-6 text-sm", children: loadingLabel }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-center gap-4 pb-8 pt-2", children: layouts.map((layout) => {
|
|
12335
|
+
const pg = pagesMap.get(layout.pageNumber);
|
|
12336
|
+
const visible = (ratios[layout.pageNumber] ?? 0) >= 1e-3;
|
|
12337
|
+
return pg ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
12338
|
+
PdfPageCanvas,
|
|
12339
|
+
{
|
|
12340
|
+
page: pg,
|
|
12341
|
+
layout,
|
|
12342
|
+
scale,
|
|
12343
|
+
visible,
|
|
12344
|
+
pageClassName
|
|
12345
|
+
},
|
|
12346
|
+
layout.pageNumber
|
|
12347
|
+
) : null;
|
|
12348
|
+
}) })
|
|
12349
|
+
}
|
|
12350
|
+
)
|
|
12351
|
+
] })
|
|
12352
|
+
]
|
|
12353
|
+
}
|
|
12354
|
+
);
|
|
12355
|
+
}
|
|
12356
|
+
function usePdfViewerDialogScrollLock(active) {
|
|
12357
|
+
React7.useLayoutEffect(() => {
|
|
12358
|
+
if (!active || typeof document === "undefined") return;
|
|
12359
|
+
const html = document.documentElement;
|
|
12360
|
+
const body = document.body;
|
|
12361
|
+
const scrollRoots = [
|
|
12362
|
+
...document.querySelectorAll("[data-scroll-lock-root]")
|
|
12363
|
+
];
|
|
12364
|
+
const scrollTopSnapshot = scrollRoots.map((el) => ({
|
|
12365
|
+
el,
|
|
12366
|
+
scrollTop: el.scrollTop
|
|
12367
|
+
}));
|
|
12368
|
+
const targets = /* @__PURE__ */ new Set([html, body, ...scrollRoots]);
|
|
12369
|
+
const snapshot = [...targets].map((el) => ({
|
|
12370
|
+
el,
|
|
12371
|
+
overflow: el.style.overflow,
|
|
12372
|
+
overscrollBehavior: el.style.overscrollBehavior
|
|
12373
|
+
}));
|
|
12374
|
+
const windowScrollY = window.scrollY;
|
|
12375
|
+
for (const el of targets) {
|
|
12376
|
+
el.style.overflow = "hidden";
|
|
12377
|
+
el.style.overscrollBehavior = "none";
|
|
12378
|
+
}
|
|
12379
|
+
const dialogSurfaceSelector = '[data-slot="dialog-content"]';
|
|
12380
|
+
const shouldAllowEventTarget = (target) => target instanceof Element && Boolean(target.closest(dialogSurfaceSelector));
|
|
12381
|
+
const onWheel = (e) => {
|
|
12382
|
+
if (shouldAllowEventTarget(e.target)) return;
|
|
12383
|
+
e.preventDefault();
|
|
12384
|
+
};
|
|
12385
|
+
const onTouchMove = (e) => {
|
|
12386
|
+
if (shouldAllowEventTarget(e.target)) return;
|
|
12387
|
+
e.preventDefault();
|
|
12388
|
+
};
|
|
12389
|
+
window.addEventListener("wheel", onWheel, {
|
|
12390
|
+
capture: true,
|
|
12391
|
+
passive: false
|
|
12392
|
+
});
|
|
12393
|
+
window.addEventListener("touchmove", onTouchMove, {
|
|
12394
|
+
capture: true,
|
|
12395
|
+
passive: false
|
|
12396
|
+
});
|
|
12397
|
+
return () => {
|
|
12398
|
+
window.removeEventListener("wheel", onWheel, { capture: true });
|
|
12399
|
+
window.removeEventListener("touchmove", onTouchMove, {
|
|
12400
|
+
capture: true
|
|
12401
|
+
});
|
|
12402
|
+
for (const { el, overflow, overscrollBehavior } of snapshot) {
|
|
12403
|
+
el.style.overflow = overflow;
|
|
12404
|
+
el.style.overscrollBehavior = overscrollBehavior;
|
|
12405
|
+
}
|
|
12406
|
+
for (const { el, scrollTop } of scrollTopSnapshot) {
|
|
12407
|
+
el.scrollTop = scrollTop;
|
|
12408
|
+
}
|
|
12409
|
+
window.scrollTo(0, windowScrollY);
|
|
12410
|
+
};
|
|
12411
|
+
}, [active]);
|
|
12412
|
+
}
|
|
12413
|
+
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";
|
|
12414
|
+
function PdfViewerDialog({
|
|
12415
|
+
open,
|
|
12416
|
+
onOpenChange,
|
|
12417
|
+
src,
|
|
12418
|
+
workerSrc,
|
|
12419
|
+
documentOptions,
|
|
12420
|
+
trigger,
|
|
12421
|
+
title,
|
|
12422
|
+
labels,
|
|
12423
|
+
forwardedProps
|
|
12424
|
+
}) {
|
|
12425
|
+
const closeLabel = labels?.close ?? "Close";
|
|
12426
|
+
const dialogTitle = labels?.dialogTitle ?? title ?? "PDF document";
|
|
12427
|
+
const dialogDescription = labels?.dialogDescription ?? "Document viewer with zoom and page navigation.";
|
|
12428
|
+
usePdfViewerDialogScrollLock(open);
|
|
12429
|
+
const {
|
|
12430
|
+
className: forwardedClassName,
|
|
12431
|
+
toolbarClassName: forwardedToolbarClassName,
|
|
12432
|
+
...restForwarded
|
|
12433
|
+
} = forwardedProps ?? {};
|
|
12434
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Dialog, { open, onOpenChange, children: [
|
|
12435
|
+
trigger ? /* @__PURE__ */ jsxRuntime.jsx(DialogTrigger, { asChild: true, children: trigger }) : null,
|
|
12436
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
12437
|
+
DialogContent,
|
|
12438
|
+
{
|
|
12439
|
+
className: fullscreenDialogContentClass,
|
|
12440
|
+
showCloseButton: false,
|
|
12441
|
+
children: [
|
|
12442
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "sr-only", children: dialogTitle }),
|
|
12443
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogDescription, { className: "sr-only", children: dialogDescription }),
|
|
12444
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12445
|
+
PdfViewer,
|
|
12446
|
+
{
|
|
12447
|
+
...restForwarded,
|
|
12448
|
+
src,
|
|
12449
|
+
workerSrc,
|
|
12450
|
+
documentOptions,
|
|
12451
|
+
className: cn(
|
|
12452
|
+
"min-h-0 flex-1 rounded-none border-0 bg-transparent text-white",
|
|
12453
|
+
forwardedClassName
|
|
12454
|
+
),
|
|
12455
|
+
toolbarClassName: cn(
|
|
12456
|
+
"border-white/10 bg-black/80 text-white backdrop-blur",
|
|
12457
|
+
forwardedToolbarClassName
|
|
12458
|
+
),
|
|
12459
|
+
toolbarEndSlot: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12460
|
+
Button,
|
|
12461
|
+
{
|
|
12462
|
+
type: "button",
|
|
12463
|
+
variant: "ghost",
|
|
12464
|
+
size: "icon-sm",
|
|
12465
|
+
className: "ml-auto text-white hover:bg-white/10 hover:text-white",
|
|
12466
|
+
onClick: () => onOpenChange(false),
|
|
12467
|
+
"aria-label": closeLabel,
|
|
12468
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "size-5", "aria-hidden": true })
|
|
12469
|
+
}
|
|
12470
|
+
)
|
|
12471
|
+
}
|
|
12472
|
+
)
|
|
12473
|
+
]
|
|
12474
|
+
}
|
|
12475
|
+
)
|
|
12476
|
+
] });
|
|
12477
|
+
}
|
|
11547
12478
|
|
|
11548
12479
|
// src/data/mexicoStates.ts
|
|
11549
12480
|
var MEXICO_STATES = [
|
|
@@ -11802,6 +12733,8 @@ exports.MiniCalendar = MiniCalendar;
|
|
|
11802
12733
|
exports.NotificationsContext = NotificationsContext;
|
|
11803
12734
|
exports.NotificationsWidget = NotificationsWidget;
|
|
11804
12735
|
exports.OrgSwitcher = OrgSwitcher;
|
|
12736
|
+
exports.PdfViewer = PdfViewer;
|
|
12737
|
+
exports.PdfViewerDialog = PdfViewerDialog;
|
|
11805
12738
|
exports.PhoneInput = PhoneInput;
|
|
11806
12739
|
exports.Popover = Popover;
|
|
11807
12740
|
exports.PopoverAnchor = PopoverAnchor;
|
|
@@ -11823,6 +12756,7 @@ exports.VerifiedProfessionalBadge = VerifiedProfessionalBadge;
|
|
|
11823
12756
|
exports.VideoPlayer = VideoPlayer;
|
|
11824
12757
|
exports.buttonVariants = buttonVariants;
|
|
11825
12758
|
exports.cn = cn;
|
|
12759
|
+
exports.composeAddressLine1ForNls = composeAddressLine1ForNls;
|
|
11826
12760
|
exports.createLiveHlsConfig = createLiveHlsConfig;
|
|
11827
12761
|
exports.createVodHlsConfig = createVodHlsConfig;
|
|
11828
12762
|
exports.defaultLanguages = defaultLanguages;
|
|
@@ -11831,8 +12765,11 @@ exports.fuzzyMatch = fuzzyMatch;
|
|
|
11831
12765
|
exports.getEnvironmentDotClass = getEnvironmentDotClass;
|
|
11832
12766
|
exports.getEnvironmentLabel = getEnvironmentLabel;
|
|
11833
12767
|
exports.isBlocksDataEnvironment = isBlocksDataEnvironment;
|
|
12768
|
+
exports.joinStreet = joinStreet;
|
|
11834
12769
|
exports.normalizeEmojiQuery = normalizeEmojiQuery;
|
|
12770
|
+
exports.sanitizeForNls = sanitizeForNls;
|
|
11835
12771
|
exports.shouldRetryLiveEdge404 = shouldRetryLiveEdge404;
|
|
12772
|
+
exports.splitStreet = splitStreet;
|
|
11836
12773
|
exports.toggleVariants = toggleVariants;
|
|
11837
12774
|
exports.useCalendarContext = useCalendarContext;
|
|
11838
12775
|
exports.useChatRoom = useChatRoom;
|