react-sharesheet 1.0.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/drawer.js ADDED
@@ -0,0 +1,960 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/drawer.ts
21
+ var drawer_exports = {};
22
+ __export(drawer_exports, {
23
+ CSS_VARS: () => CSS_VARS,
24
+ CSS_VARS_UI: () => CSS_VARS_UI,
25
+ CSS_VAR_DEFAULTS: () => CSS_VAR_DEFAULTS,
26
+ CSS_VAR_UI_DEFAULTS: () => CSS_VAR_UI_DEFAULTS,
27
+ PLATFORM_COLORS: () => PLATFORM_COLORS,
28
+ PLATFORM_CSS_VARS: () => PLATFORM_CSS_VARS,
29
+ ShareMenuDrawer: () => ShareMenuDrawer,
30
+ ShareSheetDrawer: () => ShareSheetDrawer
31
+ });
32
+ module.exports = __toCommonJS(drawer_exports);
33
+
34
+ // src/ShareSheetDrawer.tsx
35
+ var import_react3 = require("react");
36
+ var import_vaul = require("vaul");
37
+
38
+ // src/utils.ts
39
+ var import_clsx = require("clsx");
40
+ var import_tailwind_merge = require("tailwind-merge");
41
+ function cn(...inputs) {
42
+ return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
43
+ }
44
+ function openUrl(url) {
45
+ window.open(url, "_blank", "noopener,noreferrer");
46
+ }
47
+ function getSafeUrl(shareUrl) {
48
+ return shareUrl || (typeof window !== "undefined" ? window.location.href : "");
49
+ }
50
+
51
+ // src/ShareSheetContent.tsx
52
+ var import_react2 = require("react");
53
+ var import_lucide_react2 = require("lucide-react");
54
+
55
+ // src/hooks.ts
56
+ var import_react = require("react");
57
+
58
+ // src/share-functions.ts
59
+ function shareToWhatsApp(url, text) {
60
+ const encoded = encodeURIComponent(`${text}
61
+ ${url}`);
62
+ openUrl(`https://api.whatsapp.com/send?text=${encoded}`);
63
+ }
64
+ function shareToTelegram(url, text) {
65
+ const encodedText = encodeURIComponent(text);
66
+ const encodedUrl = encodeURIComponent(url);
67
+ openUrl(`https://t.me/share/url?url=${encodedUrl}&text=${encodedText}`);
68
+ }
69
+ function shareToX(url, text) {
70
+ const encodedText = encodeURIComponent(text);
71
+ const encodedUrl = encodeURIComponent(url);
72
+ openUrl(`https://x.com/intent/tweet?text=${encodedText}&url=${encodedUrl}`);
73
+ }
74
+ function shareToFacebook(url) {
75
+ const encodedUrl = encodeURIComponent(url);
76
+ openUrl(`https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}`);
77
+ }
78
+ function openInstagram() {
79
+ window.location.href = "instagram://";
80
+ }
81
+ function openTikTok() {
82
+ window.location.href = "tiktok://";
83
+ }
84
+ function openThreads() {
85
+ window.location.href = "threads://";
86
+ }
87
+ function shareToSnapchat(url) {
88
+ const encodedUrl = encodeURIComponent(url);
89
+ openUrl(`https://www.snapchat.com/scan?attachmentUrl=${encodedUrl}`);
90
+ }
91
+ function shareViaSMS(url, text) {
92
+ const body = encodeURIComponent(`${text}
93
+ ${url}`);
94
+ window.location.href = `sms:?body=${body}`;
95
+ }
96
+ function shareViaEmail(url, text, subject = "Share") {
97
+ const encodedSubject = encodeURIComponent(subject);
98
+ const body = encodeURIComponent(`${text}
99
+
100
+ ${url}`);
101
+ window.location.href = `mailto:?subject=${encodedSubject}&body=${body}`;
102
+ }
103
+ function shareToLinkedIn(url) {
104
+ const encodedUrl = encodeURIComponent(url);
105
+ openUrl(`https://www.linkedin.com/sharing/share-offsite/?url=${encodedUrl}`);
106
+ }
107
+ function shareToReddit(url, text) {
108
+ const encodedText = encodeURIComponent(text);
109
+ const encodedUrl = encodeURIComponent(url);
110
+ openUrl(`https://www.reddit.com/submit?url=${encodedUrl}&title=${encodedText}`);
111
+ }
112
+
113
+ // src/hooks.ts
114
+ function useShareSheet({
115
+ shareUrl,
116
+ shareText,
117
+ downloadUrl,
118
+ downloadFilename,
119
+ emailSubject = "Share",
120
+ onNativeShare,
121
+ onCopy,
122
+ onDownload
123
+ }) {
124
+ const [copied, setCopied] = (0, import_react.useState)(false);
125
+ const [downloading, setDownloading] = (0, import_react.useState)(false);
126
+ const canNativeShare = (0, import_react.useMemo)(() => {
127
+ return typeof navigator !== "undefined" && "share" in navigator;
128
+ }, []);
129
+ const safeUrl = getSafeUrl(shareUrl);
130
+ const copyLink = (0, import_react.useCallback)(async () => {
131
+ if (!safeUrl) return;
132
+ try {
133
+ await navigator.clipboard.writeText(safeUrl);
134
+ setCopied(true);
135
+ onCopy?.();
136
+ setTimeout(() => setCopied(false), 1200);
137
+ } catch {
138
+ }
139
+ }, [safeUrl, onCopy]);
140
+ const nativeShare = (0, import_react.useCallback)(async () => {
141
+ if (!safeUrl) return;
142
+ const nav = navigator;
143
+ if (!("share" in nav) || typeof nav.share !== "function") return;
144
+ try {
145
+ await nav.share({
146
+ title: shareText,
147
+ text: shareText,
148
+ url: safeUrl
149
+ });
150
+ onNativeShare?.();
151
+ } catch {
152
+ }
153
+ }, [safeUrl, shareText, onNativeShare]);
154
+ const downloadFile = (0, import_react.useCallback)(async () => {
155
+ const url = (downloadUrl ?? "").trim();
156
+ if (!url) return;
157
+ try {
158
+ setDownloading(true);
159
+ onDownload?.();
160
+ const res = await fetch(url);
161
+ if (!res.ok) throw new Error(`Failed to fetch file (${res.status})`);
162
+ const blob = await res.blob();
163
+ const href = URL.createObjectURL(blob);
164
+ const a = document.createElement("a");
165
+ a.href = href;
166
+ a.download = downloadFilename || "download";
167
+ document.body.appendChild(a);
168
+ a.click();
169
+ a.remove();
170
+ URL.revokeObjectURL(href);
171
+ } catch {
172
+ } finally {
173
+ setDownloading(false);
174
+ }
175
+ }, [downloadUrl, downloadFilename, onDownload]);
176
+ const shareWhatsApp = (0, import_react.useCallback)(() => {
177
+ shareToWhatsApp(safeUrl, shareText);
178
+ }, [safeUrl, shareText]);
179
+ const shareTelegram = (0, import_react.useCallback)(() => {
180
+ shareToTelegram(safeUrl, shareText);
181
+ }, [safeUrl, shareText]);
182
+ const shareX = (0, import_react.useCallback)(() => {
183
+ shareToX(safeUrl, shareText);
184
+ }, [safeUrl, shareText]);
185
+ const shareFacebook = (0, import_react.useCallback)(() => {
186
+ shareToFacebook(safeUrl);
187
+ }, [safeUrl]);
188
+ const shareInstagram = (0, import_react.useCallback)(() => {
189
+ openInstagram();
190
+ }, []);
191
+ const shareTikTok = (0, import_react.useCallback)(() => {
192
+ openTikTok();
193
+ }, []);
194
+ const shareThreads = (0, import_react.useCallback)(() => {
195
+ openThreads();
196
+ }, []);
197
+ const shareSnapchat = (0, import_react.useCallback)(() => {
198
+ shareToSnapchat(safeUrl);
199
+ }, [safeUrl]);
200
+ const shareSMS = (0, import_react.useCallback)(() => {
201
+ shareViaSMS(safeUrl, shareText);
202
+ }, [safeUrl, shareText]);
203
+ const shareEmail = (0, import_react.useCallback)(() => {
204
+ shareViaEmail(safeUrl, shareText, emailSubject);
205
+ }, [safeUrl, shareText, emailSubject]);
206
+ const shareLinkedIn = (0, import_react.useCallback)(() => {
207
+ shareToLinkedIn(safeUrl);
208
+ }, [safeUrl]);
209
+ const shareReddit = (0, import_react.useCallback)(() => {
210
+ shareToReddit(safeUrl, shareText);
211
+ }, [safeUrl, shareText]);
212
+ return {
213
+ canNativeShare,
214
+ copied,
215
+ downloading,
216
+ safeUrl,
217
+ copyLink,
218
+ nativeShare,
219
+ downloadFile,
220
+ shareWhatsApp,
221
+ shareTelegram,
222
+ shareX,
223
+ shareFacebook,
224
+ shareInstagram,
225
+ shareTikTok,
226
+ shareThreads,
227
+ shareSnapchat,
228
+ shareSMS,
229
+ shareEmail,
230
+ shareLinkedIn,
231
+ shareReddit
232
+ };
233
+ }
234
+
235
+ // src/platforms.tsx
236
+ var import_lucide_react = require("lucide-react");
237
+ var import_fa = require("react-icons/fa");
238
+ var import_fa6 = require("react-icons/fa6");
239
+ var import_jsx_runtime = require("react/jsx-runtime");
240
+ var PLATFORM_IDS = [
241
+ "native",
242
+ "copy",
243
+ "download",
244
+ "whatsapp",
245
+ "telegram",
246
+ "instagram",
247
+ "facebook",
248
+ "snapchat",
249
+ "sms",
250
+ "email",
251
+ "linkedin",
252
+ "reddit",
253
+ "x",
254
+ "tiktok",
255
+ "threads"
256
+ ];
257
+ var PLATFORM_COLORS = {
258
+ native: { bg: "#7c3aed", text: "#ffffff" },
259
+ copy: { bg: "#3b82f6", text: "#ffffff" },
260
+ download: { bg: "#ef4444", text: "#ffffff" },
261
+ whatsapp: { bg: "#25D366", text: "#ffffff" },
262
+ telegram: { bg: "#229ED9", text: "#ffffff" },
263
+ instagram: { bg: "#E1306C", text: "#ffffff" },
264
+ facebook: { bg: "#1877F2", text: "#ffffff" },
265
+ snapchat: { bg: "#FFFC00", text: "#000000" },
266
+ sms: { bg: "#22c55e", text: "#ffffff" },
267
+ email: { bg: "#f97316", text: "#ffffff" },
268
+ linkedin: { bg: "#0A66C2", text: "#ffffff" },
269
+ reddit: { bg: "#FF4500", text: "#ffffff" },
270
+ x: { bg: "#000000", text: "#ffffff" },
271
+ tiktok: { bg: "#000000", text: "#ffffff" },
272
+ threads: { bg: "#000000", text: "#ffffff" }
273
+ };
274
+ var PLATFORM_LABELS = {
275
+ native: "Share\u2026",
276
+ copy: "Copy",
277
+ download: "Download",
278
+ whatsapp: "WhatsApp",
279
+ telegram: "Telegram",
280
+ instagram: "Instagram",
281
+ facebook: "Facebook",
282
+ snapchat: "Snapchat",
283
+ sms: "SMS",
284
+ email: "Email",
285
+ linkedin: "LinkedIn",
286
+ reddit: "Reddit",
287
+ x: "X",
288
+ tiktok: "TikTok",
289
+ threads: "Threads"
290
+ };
291
+ var PLATFORM_ICONS = {
292
+ native: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Send, { size, className }),
293
+ copy: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Link, { size, className }),
294
+ download: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Download, { size, className }),
295
+ whatsapp: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaWhatsapp, { size, className }),
296
+ telegram: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaTelegramPlane, { size, className }),
297
+ instagram: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaInstagram, { size, className }),
298
+ facebook: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaFacebookF, { size, className }),
299
+ snapchat: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa6.FaSnapchat, { size, className }),
300
+ sms: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.MessageCircle, { size, className }),
301
+ email: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Mail, { size, className }),
302
+ linkedin: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaLinkedin, { size, className }),
303
+ reddit: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaReddit, { size, className }),
304
+ x: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa6.FaXTwitter, { size, className }),
305
+ tiktok: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa.FaTiktok, { size, className }),
306
+ threads: ({ size = 22, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fa6.FaThreads, { size, className })
307
+ };
308
+ var PLATFORM_CSS_VARS = {
309
+ native: "--sharesheet-native-bg",
310
+ copy: "--sharesheet-copy-bg",
311
+ download: "--sharesheet-download-bg",
312
+ whatsapp: "--sharesheet-whatsapp-bg",
313
+ telegram: "--sharesheet-telegram-bg",
314
+ instagram: "--sharesheet-instagram-bg",
315
+ facebook: "--sharesheet-facebook-bg",
316
+ snapchat: "--sharesheet-snapchat-bg",
317
+ sms: "--sharesheet-sms-bg",
318
+ email: "--sharesheet-email-bg",
319
+ linkedin: "--sharesheet-linkedin-bg",
320
+ reddit: "--sharesheet-reddit-bg",
321
+ x: "--sharesheet-x-bg",
322
+ tiktok: "--sharesheet-tiktok-bg",
323
+ threads: "--sharesheet-threads-bg"
324
+ };
325
+ var PLATFORMS = Object.fromEntries(
326
+ PLATFORM_IDS.map((id) => [
327
+ id,
328
+ {
329
+ id,
330
+ label: PLATFORM_LABELS[id],
331
+ colors: PLATFORM_COLORS[id],
332
+ Icon: PLATFORM_ICONS[id],
333
+ cssVar: PLATFORM_CSS_VARS[id]
334
+ }
335
+ ])
336
+ );
337
+
338
+ // src/types.ts
339
+ var CSS_VARS_UI = {
340
+ // Drawer
341
+ overlayBg: "--sharesheet-overlay-bg",
342
+ drawerBg: "--sharesheet-drawer-bg",
343
+ drawerBorder: "--sharesheet-drawer-border",
344
+ handleBg: "--sharesheet-handle-bg",
345
+ // Content
346
+ titleColor: "--sharesheet-title-color",
347
+ subtitleColor: "--sharesheet-subtitle-color",
348
+ buttonLabelColor: "--sharesheet-button-label-color",
349
+ // Preview
350
+ previewBg: "--sharesheet-preview-bg",
351
+ previewShimmer: "--sharesheet-preview-shimmer"
352
+ };
353
+ var CSS_VAR_UI_DEFAULTS = {
354
+ [CSS_VARS_UI.overlayBg]: "rgba(0, 0, 0, 0.7)",
355
+ [CSS_VARS_UI.drawerBg]: "#09090b",
356
+ [CSS_VARS_UI.drawerBorder]: "#27272a",
357
+ [CSS_VARS_UI.handleBg]: "#27272a",
358
+ [CSS_VARS_UI.titleColor]: "#ffffff",
359
+ [CSS_VARS_UI.subtitleColor]: "#a1a1aa",
360
+ [CSS_VARS_UI.buttonLabelColor]: "#ffffff",
361
+ [CSS_VARS_UI.previewBg]: "rgba(255, 255, 255, 0.05)",
362
+ [CSS_VARS_UI.previewShimmer]: "rgba(255, 255, 255, 0.1)"
363
+ };
364
+ var CSS_VARS = CSS_VARS_UI;
365
+ var CSS_VAR_DEFAULTS = CSS_VAR_UI_DEFAULTS;
366
+
367
+ // src/ShareSheetContent.tsx
368
+ var import_jsx_runtime2 = require("react/jsx-runtime");
369
+ var DEFAULT_BUTTON_SIZE = 45;
370
+ var DEFAULT_ICON_SIZE = 22;
371
+ var IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "gif", "webp", "svg", "bmp", "ico", "avif"];
372
+ var VIDEO_EXTENSIONS = ["mp4", "webm", "mov", "avi", "mkv", "m4v", "ogv"];
373
+ var AUDIO_EXTENSIONS = ["mp3", "wav", "ogg", "m4a", "aac", "flac", "wma"];
374
+ function detectPreviewType(url) {
375
+ try {
376
+ const pathname = new URL(url, "http://localhost").pathname;
377
+ const ext = pathname.split(".").pop()?.toLowerCase() || "";
378
+ if (IMAGE_EXTENSIONS.includes(ext)) return "image";
379
+ if (VIDEO_EXTENSIONS.includes(ext)) return "video";
380
+ if (AUDIO_EXTENSIONS.includes(ext)) return "audio";
381
+ if (url.includes("/api/og") || url.includes("og-image")) return "image";
382
+ if (url.includes("youtube.com") || url.includes("vimeo.com")) return "video";
383
+ return "link";
384
+ } catch {
385
+ return "link";
386
+ }
387
+ }
388
+ function getFilenameFromUrl(url) {
389
+ try {
390
+ const pathname = new URL(url, "http://localhost").pathname;
391
+ const filename = pathname.split("/").pop() || "";
392
+ return decodeURIComponent(filename);
393
+ } catch {
394
+ return url;
395
+ }
396
+ }
397
+ var defaultClasses = {
398
+ root: "max-w-md mx-auto",
399
+ header: "text-center mb-2",
400
+ title: "text-2xl font-black",
401
+ subtitle: "mt-1 text-sm",
402
+ preview: "flex justify-center mb-4 px-4",
403
+ previewSkeleton: "rounded-xl overflow-hidden",
404
+ previewImage: "",
405
+ previewVideo: "",
406
+ previewFile: "",
407
+ previewFileIcon: "",
408
+ previewFilename: "truncate",
409
+ previewLink: "",
410
+ grid: "px-2 py-6 flex flex-row items-center gap-4 gap-y-6 flex-wrap justify-center",
411
+ button: "flex flex-col items-center gap-0 text-xs w-[60px] outline-none cursor-pointer group",
412
+ buttonIcon: "p-2 rounded-full transition-all flex items-center justify-center group-hover:scale-110 group-active:scale-95 mb-2",
413
+ buttonLabel: ""
414
+ };
415
+ var shimmerKeyframes = `
416
+ @keyframes sharesheet-shimmer {
417
+ 0% { transform: translateX(-100%); }
418
+ 100% { transform: translateX(100%); }
419
+ }
420
+ `;
421
+ function cssVar(name, fallback) {
422
+ return `var(${name}, ${fallback})`;
423
+ }
424
+ function normalizePreview(preview) {
425
+ if (!preview) return null;
426
+ if (typeof preview === "string") {
427
+ const type2 = detectPreviewType(preview);
428
+ return {
429
+ url: preview,
430
+ type: type2,
431
+ filename: getFilenameFromUrl(preview)
432
+ };
433
+ }
434
+ const type = preview.type === "auto" || !preview.type ? detectPreviewType(preview.url) : preview.type;
435
+ return {
436
+ ...preview,
437
+ type,
438
+ filename: preview.filename || getFilenameFromUrl(preview.url)
439
+ };
440
+ }
441
+ function ShareSheetContent({
442
+ title = "Share",
443
+ shareUrl,
444
+ shareText,
445
+ preview,
446
+ downloadUrl,
447
+ downloadFilename,
448
+ className,
449
+ classNames = {},
450
+ buttonSize = DEFAULT_BUTTON_SIZE,
451
+ iconSize = DEFAULT_ICON_SIZE,
452
+ onNativeShare,
453
+ onCopy,
454
+ onDownload,
455
+ hide = [],
456
+ show,
457
+ labels = {},
458
+ icons = {}
459
+ }) {
460
+ const [mediaLoaded, setMediaLoaded] = (0, import_react2.useState)(false);
461
+ const [mediaError, setMediaError] = (0, import_react2.useState)(false);
462
+ const handleMediaLoad = (0, import_react2.useCallback)(() => {
463
+ setMediaLoaded(true);
464
+ }, []);
465
+ const handleMediaError = (0, import_react2.useCallback)(() => {
466
+ setMediaError(true);
467
+ }, []);
468
+ const previewConfig = (0, import_react2.useMemo)(() => normalizePreview(preview), [preview]);
469
+ const shareSheet = useShareSheet({
470
+ shareUrl,
471
+ shareText,
472
+ downloadUrl,
473
+ downloadFilename,
474
+ emailSubject: title,
475
+ onNativeShare,
476
+ onCopy,
477
+ onDownload
478
+ });
479
+ const shareActions = (0, import_react2.useMemo)(() => ({
480
+ native: () => void shareSheet.nativeShare(),
481
+ copy: () => void shareSheet.copyLink(),
482
+ download: () => void shareSheet.downloadFile(),
483
+ whatsapp: shareSheet.shareWhatsApp,
484
+ telegram: shareSheet.shareTelegram,
485
+ instagram: shareSheet.shareInstagram,
486
+ facebook: shareSheet.shareFacebook,
487
+ snapchat: shareSheet.shareSnapchat,
488
+ sms: shareSheet.shareSMS,
489
+ email: shareSheet.shareEmail,
490
+ linkedin: shareSheet.shareLinkedIn,
491
+ reddit: shareSheet.shareReddit,
492
+ x: shareSheet.shareX,
493
+ tiktok: shareSheet.shareTikTok,
494
+ threads: shareSheet.shareThreads
495
+ }), [shareSheet]);
496
+ const dynamicLabels = (0, import_react2.useMemo)(() => ({
497
+ copy: shareSheet.copied ? "Copied!" : PLATFORM_LABELS.copy,
498
+ download: shareSheet.downloading ? "..." : PLATFORM_LABELS.download
499
+ }), [shareSheet.copied, shareSheet.downloading]);
500
+ const buttons = (0, import_react2.useMemo)(() => {
501
+ return PLATFORM_IDS.map((id) => {
502
+ const Icon = PLATFORM_ICONS[id];
503
+ const defaultLabel = dynamicLabels[id] ?? PLATFORM_LABELS[id];
504
+ return {
505
+ id,
506
+ label: labels[id] ?? defaultLabel,
507
+ icon: icons[id] ?? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { size: iconSize }),
508
+ // Use CSS var with fallback to platform color
509
+ bgColor: cssVar(PLATFORM_CSS_VARS[id], PLATFORM_COLORS[id].bg),
510
+ textColor: PLATFORM_COLORS[id].text,
511
+ onClick: shareActions[id],
512
+ // Conditions for showing certain buttons
513
+ condition: id === "native" ? shareSheet.canNativeShare : id === "download" ? !!downloadUrl : true
514
+ };
515
+ });
516
+ }, [iconSize, labels, icons, dynamicLabels, shareActions, shareSheet.canNativeShare, downloadUrl]);
517
+ const visibleButtons = (0, import_react2.useMemo)(() => {
518
+ return buttons.filter((btn) => {
519
+ if (btn.condition === false) return false;
520
+ if (show && show.length > 0) return show.includes(btn.id);
521
+ if (hide.includes(btn.id)) return false;
522
+ return true;
523
+ });
524
+ }, [buttons, show, hide]);
525
+ const showPreview = !!previewConfig;
526
+ const renderPreview = () => {
527
+ if (!previewConfig) return null;
528
+ const { type, url, filename, alt, poster } = previewConfig;
529
+ const bgColor = cssVar(CSS_VARS_UI.previewBg, CSS_VAR_UI_DEFAULTS[CSS_VARS_UI.previewBg]);
530
+ const shimmerColor = cssVar(CSS_VARS_UI.previewShimmer, CSS_VAR_UI_DEFAULTS[CSS_VARS_UI.previewShimmer]);
531
+ const textColor = cssVar(CSS_VARS_UI.subtitleColor, CSS_VAR_UI_DEFAULTS[CSS_VARS_UI.subtitleColor]);
532
+ const UrlLabel = ({ displayUrl = url }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
533
+ "div",
534
+ {
535
+ className: cn(defaultClasses.previewFilename, classNames.previewFilename),
536
+ style: {
537
+ color: textColor,
538
+ fontSize: "10px",
539
+ opacity: 0.5,
540
+ textAlign: "center",
541
+ marginTop: "6px"
542
+ },
543
+ children: displayUrl
544
+ }
545
+ );
546
+ const PlaceholderCard = ({
547
+ icon: IconComponent,
548
+ isLoading = false,
549
+ label,
550
+ displayUrl
551
+ }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", flexDirection: "column", alignItems: "center" }, children: [
552
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
553
+ "div",
554
+ {
555
+ className: cn(defaultClasses.previewSkeleton, classNames.previewSkeleton),
556
+ style: {
557
+ position: "relative",
558
+ backgroundColor: bgColor,
559
+ width: "200px",
560
+ height: "120px",
561
+ overflow: "hidden",
562
+ display: "flex",
563
+ alignItems: "center",
564
+ justifyContent: "center"
565
+ },
566
+ children: [
567
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { position: "absolute", inset: 0, overflow: "hidden" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
568
+ "div",
569
+ {
570
+ style: {
571
+ position: "absolute",
572
+ inset: 0,
573
+ background: `linear-gradient(90deg, transparent, ${shimmerColor}, transparent)`,
574
+ animation: "sharesheet-shimmer 1.5s infinite"
575
+ }
576
+ }
577
+ ) }),
578
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
579
+ "div",
580
+ {
581
+ style: {
582
+ display: "flex",
583
+ flexDirection: "column",
584
+ alignItems: "center",
585
+ justifyContent: "center",
586
+ gap: "8px"
587
+ },
588
+ children: [
589
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconComponent, { size: 32, style: { color: textColor, opacity: 0.4 } }),
590
+ label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: textColor, fontSize: "11px", opacity: 0.4 }, children: label })
591
+ ]
592
+ }
593
+ )
594
+ ]
595
+ }
596
+ ),
597
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(UrlLabel, { displayUrl })
598
+ ] });
599
+ if (mediaError && (type === "image" || type === "video")) {
600
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PlaceholderCard, { icon: import_lucide_react2.Link2, displayUrl: url });
601
+ }
602
+ switch (type) {
603
+ case "image":
604
+ if (!mediaLoaded) {
605
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", flexDirection: "column", alignItems: "center" }, children: [
606
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
607
+ "div",
608
+ {
609
+ className: cn(defaultClasses.previewSkeleton, classNames.previewSkeleton),
610
+ style: {
611
+ position: "relative",
612
+ backgroundColor: bgColor,
613
+ width: "200px",
614
+ height: "120px",
615
+ overflow: "hidden",
616
+ display: "flex",
617
+ alignItems: "center",
618
+ justifyContent: "center"
619
+ },
620
+ children: [
621
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { position: "absolute", inset: 0, overflow: "hidden" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
622
+ "div",
623
+ {
624
+ style: {
625
+ position: "absolute",
626
+ inset: 0,
627
+ background: `linear-gradient(90deg, transparent, ${shimmerColor}, transparent)`,
628
+ animation: "sharesheet-shimmer 1.5s infinite"
629
+ }
630
+ }
631
+ ) }),
632
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react2.Image, { size: 32, style: { color: textColor, opacity: 0.4 } })
633
+ ]
634
+ }
635
+ ),
636
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(UrlLabel, {}),
637
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
638
+ "img",
639
+ {
640
+ src: url,
641
+ alt: alt || "Preview",
642
+ onLoad: handleMediaLoad,
643
+ onError: handleMediaError,
644
+ style: { display: "none" }
645
+ }
646
+ )
647
+ ] });
648
+ }
649
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", flexDirection: "column", alignItems: "center" }, children: [
650
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
651
+ "img",
652
+ {
653
+ src: url,
654
+ alt: alt || "Preview",
655
+ className: cn(defaultClasses.previewImage, classNames.previewImage),
656
+ style: {
657
+ maxWidth: "100%",
658
+ maxHeight: "180px",
659
+ borderRadius: "12px",
660
+ opacity: 1,
661
+ transition: "opacity 0.3s ease-in-out"
662
+ }
663
+ }
664
+ ),
665
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(UrlLabel, {})
666
+ ] });
667
+ case "video":
668
+ if (!mediaLoaded) {
669
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", flexDirection: "column", alignItems: "center" }, children: [
670
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
671
+ "div",
672
+ {
673
+ className: cn(defaultClasses.previewSkeleton, classNames.previewSkeleton),
674
+ style: {
675
+ position: "relative",
676
+ backgroundColor: bgColor,
677
+ width: "200px",
678
+ height: "120px",
679
+ overflow: "hidden",
680
+ display: "flex",
681
+ alignItems: "center",
682
+ justifyContent: "center"
683
+ },
684
+ children: [
685
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { position: "absolute", inset: 0, overflow: "hidden" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
686
+ "div",
687
+ {
688
+ style: {
689
+ position: "absolute",
690
+ inset: 0,
691
+ background: `linear-gradient(90deg, transparent, ${shimmerColor}, transparent)`,
692
+ animation: "sharesheet-shimmer 1.5s infinite"
693
+ }
694
+ }
695
+ ) }),
696
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react2.Film, { size: 32, style: { color: textColor, opacity: 0.4 } })
697
+ ]
698
+ }
699
+ ),
700
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(UrlLabel, {}),
701
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
702
+ "video",
703
+ {
704
+ src: url,
705
+ poster,
706
+ onLoadedData: handleMediaLoad,
707
+ onError: handleMediaError,
708
+ style: { display: "none" },
709
+ muted: true,
710
+ playsInline: true,
711
+ preload: "metadata"
712
+ }
713
+ )
714
+ ] });
715
+ }
716
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", flexDirection: "column", alignItems: "center" }, children: [
717
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { position: "relative", borderRadius: "12px", overflow: "hidden" }, children: [
718
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
719
+ "video",
720
+ {
721
+ src: url,
722
+ poster,
723
+ className: cn(defaultClasses.previewVideo, classNames.previewVideo),
724
+ style: {
725
+ maxWidth: "100%",
726
+ maxHeight: "180px",
727
+ display: "block"
728
+ },
729
+ muted: true,
730
+ playsInline: true,
731
+ preload: "metadata"
732
+ }
733
+ ),
734
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
735
+ "div",
736
+ {
737
+ style: {
738
+ position: "absolute",
739
+ inset: 0,
740
+ display: "flex",
741
+ alignItems: "center",
742
+ justifyContent: "center",
743
+ pointerEvents: "none"
744
+ },
745
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
746
+ "div",
747
+ {
748
+ style: {
749
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
750
+ borderRadius: "50%",
751
+ padding: "10px"
752
+ },
753
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react2.Play, { size: 20, fill: "white", color: "white" })
754
+ }
755
+ )
756
+ }
757
+ )
758
+ ] }),
759
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(UrlLabel, {})
760
+ ] });
761
+ case "audio":
762
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PlaceholderCard, { icon: import_lucide_react2.Music, label: filename || "Audio", displayUrl: url });
763
+ case "file":
764
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PlaceholderCard, { icon: import_lucide_react2.FileText, label: filename || "File", displayUrl: url });
765
+ case "link":
766
+ default:
767
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PlaceholderCard, { icon: import_lucide_react2.Link2, displayUrl: url });
768
+ }
769
+ };
770
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cn(defaultClasses.root, classNames.root, className), children: [
771
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { dangerouslySetInnerHTML: { __html: shimmerKeyframes } }),
772
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cn(defaultClasses.header, classNames.header), children: [
773
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
774
+ "div",
775
+ {
776
+ className: cn(defaultClasses.title, classNames.title),
777
+ style: { color: cssVar(CSS_VARS_UI.titleColor, CSS_VAR_UI_DEFAULTS[CSS_VARS_UI.titleColor]) },
778
+ children: title
779
+ }
780
+ ),
781
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
782
+ "div",
783
+ {
784
+ className: cn(defaultClasses.subtitle, classNames.subtitle),
785
+ style: { color: cssVar(CSS_VARS_UI.subtitleColor, CSS_VAR_UI_DEFAULTS[CSS_VARS_UI.subtitleColor]) },
786
+ children: shareText
787
+ }
788
+ )
789
+ ] }),
790
+ showPreview && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: cn(defaultClasses.preview, classNames.preview), children: renderPreview() }),
791
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: cn(defaultClasses.grid, classNames.grid), children: visibleButtons.map((btn) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
792
+ "button",
793
+ {
794
+ type: "button",
795
+ className: cn(defaultClasses.button, classNames.button),
796
+ onClick: btn.onClick,
797
+ children: [
798
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
799
+ "div",
800
+ {
801
+ className: cn(defaultClasses.buttonIcon, classNames.buttonIcon),
802
+ style: {
803
+ width: buttonSize,
804
+ height: buttonSize,
805
+ backgroundColor: btn.bgColor,
806
+ color: btn.textColor
807
+ },
808
+ children: btn.icon
809
+ }
810
+ ),
811
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
812
+ "div",
813
+ {
814
+ className: cn(defaultClasses.buttonLabel, classNames.buttonLabel),
815
+ style: { color: cssVar(CSS_VARS_UI.buttonLabelColor, CSS_VAR_UI_DEFAULTS[CSS_VARS_UI.buttonLabelColor]) },
816
+ children: btn.label
817
+ }
818
+ )
819
+ ]
820
+ },
821
+ btn.id
822
+ )) })
823
+ ] });
824
+ }
825
+
826
+ // src/ShareSheetDrawer.tsx
827
+ var import_jsx_runtime3 = require("react/jsx-runtime");
828
+ var defaultDrawerClasses = {
829
+ overlay: "fixed inset-0 z-[70]",
830
+ drawer: "flex flex-col rounded-t-[14px] h-[70%] mt-24 fixed bottom-0 left-0 right-0 z-[80] border-t outline-none",
831
+ drawerInner: "p-4 rounded-t-[14px] flex-1 overflow-auto",
832
+ handle: "mx-auto w-12 h-1.5 shrink-0 rounded-full mb-6",
833
+ trigger: ""
834
+ };
835
+ function cssVar2(name, fallback) {
836
+ return `var(${name}, ${fallback})`;
837
+ }
838
+ function ShareSheetDrawer({
839
+ title = "Share",
840
+ shareUrl,
841
+ shareText,
842
+ preview,
843
+ downloadUrl,
844
+ downloadFilename,
845
+ disabled,
846
+ children,
847
+ open: controlledOpen,
848
+ onOpenChange: controlledOnOpenChange,
849
+ className,
850
+ classNames = {},
851
+ buttonSize,
852
+ iconSize,
853
+ onNativeShare,
854
+ onCopy,
855
+ onDownload,
856
+ hide,
857
+ show,
858
+ labels,
859
+ icons
860
+ }) {
861
+ const [internalOpen, setInternalOpen] = (0, import_react3.useState)(false);
862
+ const isControlled = controlledOpen !== void 0;
863
+ const open = isControlled ? controlledOpen : internalOpen;
864
+ const setOpen = isControlled ? (value) => controlledOnOpenChange?.(value) : setInternalOpen;
865
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_vaul.Drawer.Root, { open, onOpenChange: setOpen, shouldScaleBackground: true, children: [
866
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_vaul.Drawer.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
867
+ "div",
868
+ {
869
+ className: cn(
870
+ defaultDrawerClasses.trigger,
871
+ classNames.trigger,
872
+ disabled ? "pointer-events-none opacity-50" : ""
873
+ ),
874
+ children
875
+ }
876
+ ) }),
877
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_vaul.Drawer.Portal, { children: [
878
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
879
+ import_vaul.Drawer.Overlay,
880
+ {
881
+ className: cn(defaultDrawerClasses.overlay, classNames.overlay),
882
+ style: {
883
+ backgroundColor: cssVar2(CSS_VARS_UI.overlayBg, CSS_VAR_UI_DEFAULTS[CSS_VARS_UI.overlayBg])
884
+ }
885
+ }
886
+ ),
887
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
888
+ import_vaul.Drawer.Content,
889
+ {
890
+ className: cn(defaultDrawerClasses.drawer, classNames.drawer),
891
+ style: {
892
+ backgroundColor: cssVar2(CSS_VARS_UI.drawerBg, CSS_VAR_UI_DEFAULTS[CSS_VARS_UI.drawerBg]),
893
+ borderColor: cssVar2(CSS_VARS_UI.drawerBorder, CSS_VAR_UI_DEFAULTS[CSS_VARS_UI.drawerBorder])
894
+ },
895
+ children: [
896
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_vaul.Drawer.Title, { className: "sr-only", children: title }),
897
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
898
+ "div",
899
+ {
900
+ className: cn(defaultDrawerClasses.drawerInner, classNames.drawerInner),
901
+ style: {
902
+ backgroundColor: cssVar2(CSS_VARS_UI.drawerBg, CSS_VAR_UI_DEFAULTS[CSS_VARS_UI.drawerBg])
903
+ },
904
+ children: [
905
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
906
+ "div",
907
+ {
908
+ className: cn(defaultDrawerClasses.handle, classNames.handle),
909
+ style: {
910
+ backgroundColor: cssVar2(CSS_VARS_UI.handleBg, CSS_VAR_UI_DEFAULTS[CSS_VARS_UI.handleBg])
911
+ }
912
+ }
913
+ ),
914
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
915
+ ShareSheetContent,
916
+ {
917
+ title,
918
+ shareUrl,
919
+ shareText,
920
+ preview,
921
+ downloadUrl,
922
+ downloadFilename,
923
+ className,
924
+ classNames,
925
+ buttonSize,
926
+ iconSize,
927
+ onNativeShare: () => {
928
+ onNativeShare?.();
929
+ setOpen(false);
930
+ },
931
+ onCopy,
932
+ onDownload,
933
+ hide,
934
+ show,
935
+ labels,
936
+ icons
937
+ }
938
+ )
939
+ ]
940
+ }
941
+ )
942
+ ]
943
+ }
944
+ )
945
+ ] })
946
+ ] });
947
+ }
948
+ var ShareMenuDrawer = ShareSheetDrawer;
949
+ // Annotate the CommonJS export names for ESM import in node:
950
+ 0 && (module.exports = {
951
+ CSS_VARS,
952
+ CSS_VARS_UI,
953
+ CSS_VAR_DEFAULTS,
954
+ CSS_VAR_UI_DEFAULTS,
955
+ PLATFORM_COLORS,
956
+ PLATFORM_CSS_VARS,
957
+ ShareMenuDrawer,
958
+ ShareSheetDrawer
959
+ });
960
+ //# sourceMappingURL=drawer.js.map