@starwind-ui/core 1.15.0 → 1.15.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/package.json +1 -1
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -108
- package/dist/index.js.map +0 -1
- package/dist/src/components/accordion/Accordion.astro +0 -254
- package/dist/src/components/accordion/AccordionContent.astro +0 -33
- package/dist/src/components/accordion/AccordionItem.astro +0 -27
- package/dist/src/components/accordion/AccordionTrigger.astro +0 -32
- package/dist/src/components/accordion/index.ts +0 -15
- package/dist/src/components/alert/Alert.astro +0 -31
- package/dist/src/components/alert/AlertDescription.astro +0 -14
- package/dist/src/components/alert/AlertTitle.astro +0 -16
- package/dist/src/components/alert/index.ts +0 -13
- package/dist/src/components/alert-dialog/AlertDialog.astro +0 -275
- package/dist/src/components/alert-dialog/AlertDialogAction.astro +0 -44
- package/dist/src/components/alert-dialog/AlertDialogCancel.astro +0 -45
- package/dist/src/components/alert-dialog/AlertDialogContent.astro +0 -52
- package/dist/src/components/alert-dialog/AlertDialogDescription.astro +0 -18
- package/dist/src/components/alert-dialog/AlertDialogFooter.astro +0 -16
- package/dist/src/components/alert-dialog/AlertDialogHeader.astro +0 -14
- package/dist/src/components/alert-dialog/AlertDialogTitle.astro +0 -20
- package/dist/src/components/alert-dialog/AlertDialogTrigger.astro +0 -47
- package/dist/src/components/alert-dialog/index.ts +0 -46
- package/dist/src/components/aspect-ratio/AspectRatio.astro +0 -32
- package/dist/src/components/aspect-ratio/index.ts +0 -7
- package/dist/src/components/avatar/Avatar.astro +0 -29
- package/dist/src/components/avatar/AvatarFallback.astro +0 -18
- package/dist/src/components/avatar/AvatarImage.astro +0 -49
- package/dist/src/components/avatar/index.ts +0 -13
- package/dist/src/components/badge/Badge.astro +0 -55
- package/dist/src/components/badge/index.ts +0 -7
- package/dist/src/components/breadcrumb/Breadcrumb.astro +0 -11
- package/dist/src/components/breadcrumb/BreadcrumbEllipsis.astro +0 -28
- package/dist/src/components/breadcrumb/BreadcrumbItem.astro +0 -14
- package/dist/src/components/breadcrumb/BreadcrumbLink.astro +0 -22
- package/dist/src/components/breadcrumb/BreadcrumbList.astro +0 -16
- package/dist/src/components/breadcrumb/BreadcrumbPage.astro +0 -21
- package/dist/src/components/breadcrumb/BreadcrumbSeparator.astro +0 -23
- package/dist/src/components/breadcrumb/index.ts +0 -37
- package/dist/src/components/button/Button.astro +0 -55
- package/dist/src/components/button/index.ts +0 -7
- package/dist/src/components/button-group/ButtonGroup.astro +0 -62
- package/dist/src/components/button-group/ButtonGroupSeparator.astro +0 -27
- package/dist/src/components/button-group/ButtonGroupText.astro +0 -19
- package/dist/src/components/button-group/index.ts +0 -17
- package/dist/src/components/card/Card.astro +0 -14
- package/dist/src/components/card/CardContent.astro +0 -14
- package/dist/src/components/card/CardDescription.astro +0 -14
- package/dist/src/components/card/CardFooter.astro +0 -14
- package/dist/src/components/card/CardHeader.astro +0 -14
- package/dist/src/components/card/CardTitle.astro +0 -14
- package/dist/src/components/card/index.ts +0 -26
- package/dist/src/components/carousel/Carousel.astro +0 -55
- package/dist/src/components/carousel/CarouselContent.astro +0 -26
- package/dist/src/components/carousel/CarouselItem.astro +0 -26
- package/dist/src/components/carousel/CarouselNext.astro +0 -37
- package/dist/src/components/carousel/CarouselPrevious.astro +0 -37
- package/dist/src/components/carousel/carousel-script.ts +0 -191
- package/dist/src/components/carousel/index.ts +0 -32
- package/dist/src/components/checkbox/Checkbox.astro +0 -128
- package/dist/src/components/checkbox/index.ts +0 -7
- package/dist/src/components/collapsible/Collapsible.astro +0 -161
- package/dist/src/components/collapsible/CollapsibleContent.astro +0 -22
- package/dist/src/components/collapsible/CollapsibleTrigger.astro +0 -44
- package/dist/src/components/collapsible/index.ts +0 -13
- package/dist/src/components/dialog/Dialog.astro +0 -389
- package/dist/src/components/dialog/DialogClose.astro +0 -35
- package/dist/src/components/dialog/DialogContent.astro +0 -78
- package/dist/src/components/dialog/DialogDescription.astro +0 -14
- package/dist/src/components/dialog/DialogFooter.astro +0 -14
- package/dist/src/components/dialog/DialogHeader.astro +0 -14
- package/dist/src/components/dialog/DialogTitle.astro +0 -22
- package/dist/src/components/dialog/DialogTrigger.astro +0 -47
- package/dist/src/components/dialog/index.ts +0 -45
- package/dist/src/components/dropdown/Dropdown.astro +0 -377
- package/dist/src/components/dropdown/DropdownContent.astro +0 -81
- package/dist/src/components/dropdown/DropdownItem.astro +0 -48
- package/dist/src/components/dropdown/DropdownLabel.astro +0 -29
- package/dist/src/components/dropdown/DropdownSeparator.astro +0 -21
- package/dist/src/components/dropdown/DropdownTrigger.astro +0 -52
- package/dist/src/components/dropdown/index.ts +0 -33
- package/dist/src/components/dropzone/Dropzone.astro +0 -236
- package/dist/src/components/dropzone/DropzoneFilesList.astro +0 -26
- package/dist/src/components/dropzone/DropzoneLoadingIndicator.astro +0 -10
- package/dist/src/components/dropzone/DropzoneUploadIndicator.astro +0 -10
- package/dist/src/components/dropzone/index.ts +0 -24
- package/dist/src/components/image/Image.astro +0 -24
- package/dist/src/components/image/index.ts +0 -9
- package/dist/src/components/input/Input.astro +0 -25
- package/dist/src/components/input/index.ts +0 -7
- package/dist/src/components/input-otp/InputOtp.astro +0 -319
- package/dist/src/components/input-otp/InputOtpGroup.astro +0 -16
- package/dist/src/components/input-otp/InputOtpSeparator.astro +0 -25
- package/dist/src/components/input-otp/InputOtpSlot.astro +0 -48
- package/dist/src/components/input-otp/InputOtpTypes.ts +0 -6
- package/dist/src/components/input-otp/index.ts +0 -33
- package/dist/src/components/item/Item.astro +0 -52
- package/dist/src/components/item/ItemActions.astro +0 -16
- package/dist/src/components/item/ItemContent.astro +0 -16
- package/dist/src/components/item/ItemDescription.astro +0 -19
- package/dist/src/components/item/ItemFooter.astro +0 -16
- package/dist/src/components/item/ItemGroup.astro +0 -16
- package/dist/src/components/item/ItemHeader.astro +0 -16
- package/dist/src/components/item/ItemMedia.astro +0 -40
- package/dist/src/components/item/ItemSeparator.astro +0 -21
- package/dist/src/components/item/ItemTitle.astro +0 -16
- package/dist/src/components/item/index.ts +0 -50
- package/dist/src/components/kbd/Kbd.astro +0 -21
- package/dist/src/components/kbd/KbdGroup.astro +0 -16
- package/dist/src/components/kbd/index.ts +0 -11
- package/dist/src/components/label/Label.astro +0 -22
- package/dist/src/components/label/index.ts +0 -7
- package/dist/src/components/pagination/Pagination.astro +0 -20
- package/dist/src/components/pagination/PaginationContent.astro +0 -16
- package/dist/src/components/pagination/PaginationEllipsis.astro +0 -35
- package/dist/src/components/pagination/PaginationItem.astro +0 -16
- package/dist/src/components/pagination/PaginationLink.astro +0 -24
- package/dist/src/components/pagination/PaginationNext.astro +0 -30
- package/dist/src/components/pagination/PaginationPrevious.astro +0 -30
- package/dist/src/components/pagination/index.ts +0 -38
- package/dist/src/components/progress/Progress.astro +0 -155
- package/dist/src/components/progress/index.ts +0 -10
- package/dist/src/components/prose/Prose.astro +0 -617
- package/dist/src/components/prose/index.ts +0 -9
- package/dist/src/components/radio-group/RadioGroup.astro +0 -162
- package/dist/src/components/radio-group/RadioGroupItem.astro +0 -129
- package/dist/src/components/radio-group/RadioGroupTypes.ts +0 -6
- package/dist/src/components/radio-group/index.ts +0 -23
- package/dist/src/components/select/Select.astro +0 -751
- package/dist/src/components/select/SelectContent.astro +0 -94
- package/dist/src/components/select/SelectGroup.astro +0 -9
- package/dist/src/components/select/SelectItem.astro +0 -51
- package/dist/src/components/select/SelectLabel.astro +0 -14
- package/dist/src/components/select/SelectSearch.astro +0 -49
- package/dist/src/components/select/SelectSeparator.astro +0 -12
- package/dist/src/components/select/SelectTrigger.astro +0 -54
- package/dist/src/components/select/SelectTypes.ts +0 -13
- package/dist/src/components/select/SelectValue.astro +0 -19
- package/dist/src/components/select/index.ts +0 -49
- package/dist/src/components/separator/Separator.astro +0 -36
- package/dist/src/components/separator/index.ts +0 -7
- package/dist/src/components/sheet/Sheet.astro +0 -13
- package/dist/src/components/sheet/SheetClose.astro +0 -13
- package/dist/src/components/sheet/SheetContent.astro +0 -92
- package/dist/src/components/sheet/SheetDescription.astro +0 -16
- package/dist/src/components/sheet/SheetFooter.astro +0 -16
- package/dist/src/components/sheet/SheetHeader.astro +0 -16
- package/dist/src/components/sheet/SheetTitle.astro +0 -16
- package/dist/src/components/sheet/SheetTrigger.astro +0 -13
- package/dist/src/components/sheet/index.ts +0 -41
- package/dist/src/components/sidebar/Sidebar.astro +0 -213
- package/dist/src/components/sidebar/SidebarContent.astro +0 -24
- package/dist/src/components/sidebar/SidebarFooter.astro +0 -21
- package/dist/src/components/sidebar/SidebarGroup.astro +0 -21
- package/dist/src/components/sidebar/SidebarGroupContent.astro +0 -21
- package/dist/src/components/sidebar/SidebarGroupLabel.astro +0 -52
- package/dist/src/components/sidebar/SidebarHeader.astro +0 -21
- package/dist/src/components/sidebar/SidebarInput.astro +0 -22
- package/dist/src/components/sidebar/SidebarInset.astro +0 -21
- package/dist/src/components/sidebar/SidebarMenu.astro +0 -21
- package/dist/src/components/sidebar/SidebarMenuAction.astro +0 -59
- package/dist/src/components/sidebar/SidebarMenuBadge.astro +0 -30
- package/dist/src/components/sidebar/SidebarMenuButton.astro +0 -129
- package/dist/src/components/sidebar/SidebarMenuItem.astro +0 -21
- package/dist/src/components/sidebar/SidebarMenuSkeleton.astro +0 -40
- package/dist/src/components/sidebar/SidebarMenuSub.astro +0 -24
- package/dist/src/components/sidebar/SidebarMenuSubButton.astro +0 -49
- package/dist/src/components/sidebar/SidebarMenuSubItem.astro +0 -16
- package/dist/src/components/sidebar/SidebarProvider.astro +0 -213
- package/dist/src/components/sidebar/SidebarRail.astro +0 -71
- package/dist/src/components/sidebar/SidebarSeparator.astro +0 -22
- package/dist/src/components/sidebar/SidebarTrigger.astro +0 -66
- package/dist/src/components/sidebar/index.ts +0 -103
- package/dist/src/components/skeleton/Skeleton.astro +0 -14
- package/dist/src/components/skeleton/index.ts +0 -9
- package/dist/src/components/slider/Slider.astro +0 -411
- package/dist/src/components/slider/index.ts +0 -9
- package/dist/src/components/spinner/Spinner.astro +0 -21
- package/dist/src/components/spinner/index.ts +0 -7
- package/dist/src/components/switch/Switch.astro +0 -192
- package/dist/src/components/switch/SwitchTypes.ts +0 -6
- package/dist/src/components/switch/index.ts +0 -12
- package/dist/src/components/table/Table.astro +0 -18
- package/dist/src/components/table/TableBody.astro +0 -16
- package/dist/src/components/table/TableCaption.astro +0 -16
- package/dist/src/components/table/TableCell.astro +0 -16
- package/dist/src/components/table/TableFoot.astro +0 -16
- package/dist/src/components/table/TableHead.astro +0 -16
- package/dist/src/components/table/TableHeader.astro +0 -16
- package/dist/src/components/table/TableRow.astro +0 -16
- package/dist/src/components/table/index.ts +0 -42
- package/dist/src/components/tabs/Tabs.astro +0 -271
- package/dist/src/components/tabs/TabsContent.astro +0 -28
- package/dist/src/components/tabs/TabsList.astro +0 -22
- package/dist/src/components/tabs/TabsTrigger.astro +0 -34
- package/dist/src/components/tabs/index.ts +0 -20
- package/dist/src/components/textarea/Textarea.astro +0 -29
- package/dist/src/components/textarea/index.ts +0 -9
- package/dist/src/components/theme-toggle/ThemeToggle.astro +0 -208
- package/dist/src/components/theme-toggle/index.ts +0 -7
- package/dist/src/components/toast/ToastDescription.astro +0 -21
- package/dist/src/components/toast/ToastItem.astro +0 -54
- package/dist/src/components/toast/ToastTemplate.astro +0 -25
- package/dist/src/components/toast/ToastTitle.astro +0 -57
- package/dist/src/components/toast/Toaster.astro +0 -982
- package/dist/src/components/toast/index.ts +0 -29
- package/dist/src/components/toast/toast-manager.ts +0 -216
- package/dist/src/components/toggle/Toggle.astro +0 -174
- package/dist/src/components/toggle/ToggleTypes.ts +0 -14
- package/dist/src/components/toggle/index.ts +0 -8
- package/dist/src/components/tooltip/Tooltip.astro +0 -282
- package/dist/src/components/tooltip/TooltipContent.astro +0 -89
- package/dist/src/components/tooltip/TooltipTrigger.astro +0 -10
- package/dist/src/components/tooltip/index.ts +0 -16
- package/dist/src/components/video/Video.astro +0 -120
- package/dist/src/components/video/index.ts +0 -9
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div"> & {
|
|
6
|
-
/**
|
|
7
|
-
* Time in milliseconds to wait before showing the tooltip
|
|
8
|
-
*/
|
|
9
|
-
openDelay?: number;
|
|
10
|
-
/**
|
|
11
|
-
* Time in milliseconds to wait before hiding the tooltip
|
|
12
|
-
*/
|
|
13
|
-
closeDelay?: number;
|
|
14
|
-
/**
|
|
15
|
-
* When true, prevents the tooltip from staying open when hovering over its content
|
|
16
|
-
*/
|
|
17
|
-
disableHoverableContent?: boolean;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const tooltip = tv({ base: "starwind-tooltip relative inline-block" });
|
|
21
|
-
|
|
22
|
-
const {
|
|
23
|
-
openDelay = 200,
|
|
24
|
-
closeDelay = 200,
|
|
25
|
-
disableHoverableContent = false,
|
|
26
|
-
class: className,
|
|
27
|
-
} = Astro.props;
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
<div
|
|
31
|
-
class={tooltip({ class: className })}
|
|
32
|
-
data-slot="tooltip"
|
|
33
|
-
data-state="closed"
|
|
34
|
-
data-open-delay={openDelay}
|
|
35
|
-
data-close-delay={closeDelay}
|
|
36
|
-
{...!disableHoverableContent && { "data-content-hoverable": "" }}
|
|
37
|
-
>
|
|
38
|
-
<slot />
|
|
39
|
-
</div>
|
|
40
|
-
|
|
41
|
-
<script>
|
|
42
|
-
class TooltipHandler {
|
|
43
|
-
private tooltip: HTMLElement;
|
|
44
|
-
private trigger: HTMLElement | null;
|
|
45
|
-
private content: HTMLElement | null;
|
|
46
|
-
private openTimerRef: number | null = null;
|
|
47
|
-
private closeTimerRef: number | null = null;
|
|
48
|
-
private contentId: string;
|
|
49
|
-
private animationDuration = 150;
|
|
50
|
-
|
|
51
|
-
constructor(tooltip: HTMLElement, idx: number) {
|
|
52
|
-
this.contentId = `starwind-tooltip${idx}`;
|
|
53
|
-
this.tooltip = tooltip;
|
|
54
|
-
this.content = tooltip.querySelector(".starwind-tooltip-content");
|
|
55
|
-
|
|
56
|
-
// if tooltip.firstElementChild is this.content, then get the next element
|
|
57
|
-
this.trigger = tooltip.firstElementChild as HTMLElement;
|
|
58
|
-
if (this.trigger === this.content) {
|
|
59
|
-
this.trigger = this.trigger.nextElementSibling as HTMLElement;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this.trigger.classList.add("starwind-tooltip-trigger");
|
|
63
|
-
|
|
64
|
-
if (!this.trigger || !this.content) return;
|
|
65
|
-
|
|
66
|
-
// animationDuration is set with inline styles through passed prop to TooltipContent
|
|
67
|
-
const animationDurationString = this.content.style.animationDuration;
|
|
68
|
-
if (animationDurationString.endsWith("ms")) {
|
|
69
|
-
this.animationDuration = parseFloat(animationDurationString);
|
|
70
|
-
} else if (animationDurationString.endsWith("s")) {
|
|
71
|
-
// using something like @playform/compress might optimize to use "s" instead of "ms"
|
|
72
|
-
this.animationDuration = parseFloat(animationDurationString) * 1000;
|
|
73
|
-
}
|
|
74
|
-
this.init();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private init() {
|
|
78
|
-
this.setupAccessibility();
|
|
79
|
-
this.setupEvents();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private setupAccessibility() {
|
|
83
|
-
if (!this.trigger || !this.content) return;
|
|
84
|
-
this.trigger.setAttribute("aria-describedby", this.contentId);
|
|
85
|
-
this.content.id = this.contentId;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private setupEvents() {
|
|
89
|
-
if (!this.trigger || !this.content) return;
|
|
90
|
-
|
|
91
|
-
// Trigger events
|
|
92
|
-
this.trigger.addEventListener("mouseenter", () => this.show());
|
|
93
|
-
this.trigger.addEventListener("mouseleave", () => this.hide());
|
|
94
|
-
this.trigger.addEventListener("focus", () => this.show(true));
|
|
95
|
-
this.trigger.addEventListener("blur", () => this.hide(true));
|
|
96
|
-
|
|
97
|
-
// Content events
|
|
98
|
-
if (this.tooltip.hasAttribute("data-content-hoverable")) {
|
|
99
|
-
this.content.addEventListener("mouseenter", () => this.show());
|
|
100
|
-
this.content.addEventListener("mouseleave", () => this.hide());
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Document events
|
|
104
|
-
document.addEventListener("keydown", (e) => {
|
|
105
|
-
if (e.key === "Escape" && this.tooltip.getAttribute("data-state") === "open") {
|
|
106
|
-
this.hide(true);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
document.addEventListener("click", (e) => {
|
|
111
|
-
if (
|
|
112
|
-
!this.tooltip.contains(e.target as Node) &&
|
|
113
|
-
this.tooltip.getAttribute("data-state") === "open"
|
|
114
|
-
) {
|
|
115
|
-
this.hide(true);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private show(immediate: boolean = false) {
|
|
121
|
-
if (!this.content || !this.trigger) return;
|
|
122
|
-
if (immediate) {
|
|
123
|
-
this.tooltip.setAttribute("data-state", "open");
|
|
124
|
-
this.content.setAttribute("data-state", "open");
|
|
125
|
-
this.content.style.display = "block";
|
|
126
|
-
this.positionTooltip();
|
|
127
|
-
this.clearOpenTimer();
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
this.clearCloseTimer();
|
|
132
|
-
|
|
133
|
-
const delay = parseInt(this.tooltip.getAttribute("data-open-delay") || "700");
|
|
134
|
-
this.openTimerRef = window.setTimeout(() => {
|
|
135
|
-
if (!this.content || !this.trigger) return;
|
|
136
|
-
this.tooltip.setAttribute("data-state", "open");
|
|
137
|
-
this.content.setAttribute("data-state", "open");
|
|
138
|
-
this.content.style.display = "block";
|
|
139
|
-
this.positionTooltip();
|
|
140
|
-
this.openTimerRef = null;
|
|
141
|
-
}, delay);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private positionTooltip() {
|
|
145
|
-
if (!this.content || !this.trigger) return;
|
|
146
|
-
|
|
147
|
-
const triggerRect = this.trigger.getBoundingClientRect();
|
|
148
|
-
const contentRect = this.content.getBoundingClientRect();
|
|
149
|
-
const side = this.content.dataset.side || "top";
|
|
150
|
-
const align = this.content.dataset.align || "center";
|
|
151
|
-
const sideOffset = parseInt(this.content.dataset.sideOffset || "8");
|
|
152
|
-
|
|
153
|
-
let top = 0;
|
|
154
|
-
let left = 0;
|
|
155
|
-
|
|
156
|
-
// Calculate position based on side
|
|
157
|
-
switch (side) {
|
|
158
|
-
case "top":
|
|
159
|
-
top = triggerRect.top - contentRect.height - sideOffset;
|
|
160
|
-
break;
|
|
161
|
-
case "bottom":
|
|
162
|
-
top = triggerRect.bottom + sideOffset;
|
|
163
|
-
break;
|
|
164
|
-
case "left":
|
|
165
|
-
left = triggerRect.left - contentRect.width - sideOffset;
|
|
166
|
-
break;
|
|
167
|
-
case "right":
|
|
168
|
-
left = triggerRect.right + sideOffset;
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Calculate alignment
|
|
173
|
-
if (side === "top" || side === "bottom") {
|
|
174
|
-
switch (align) {
|
|
175
|
-
case "center":
|
|
176
|
-
left = triggerRect.left + (triggerRect.width - contentRect.width) / 2;
|
|
177
|
-
break;
|
|
178
|
-
case "start":
|
|
179
|
-
left = triggerRect.left;
|
|
180
|
-
break;
|
|
181
|
-
case "end":
|
|
182
|
-
left = triggerRect.right - contentRect.width;
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
} else {
|
|
186
|
-
switch (align) {
|
|
187
|
-
case "center":
|
|
188
|
-
top = triggerRect.top + (triggerRect.height - contentRect.height) / 2;
|
|
189
|
-
break;
|
|
190
|
-
case "start":
|
|
191
|
-
top = triggerRect.top;
|
|
192
|
-
break;
|
|
193
|
-
case "end":
|
|
194
|
-
top = triggerRect.bottom - contentRect.height;
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Apply collision avoidance if enabled
|
|
200
|
-
if (this.content.hasAttribute("data-avoid-collisions")) {
|
|
201
|
-
const padding = 8;
|
|
202
|
-
const viewportWidth = window.innerWidth;
|
|
203
|
-
const viewportHeight = window.innerHeight;
|
|
204
|
-
|
|
205
|
-
// Horizontal bounds
|
|
206
|
-
if (left < padding) left = padding;
|
|
207
|
-
if (left + contentRect.width > viewportWidth - padding) {
|
|
208
|
-
left = viewportWidth - contentRect.width - padding;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Vertical bounds
|
|
212
|
-
if (top < padding) top = padding;
|
|
213
|
-
if (top + contentRect.height > viewportHeight - padding) {
|
|
214
|
-
top = viewportHeight - contentRect.height - padding;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
this.content.style.top = `${top}px`;
|
|
219
|
-
this.content.style.left = `${left}px`;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private hide(immediate: boolean = false) {
|
|
223
|
-
if (!this.content || !this.trigger) return;
|
|
224
|
-
this.clearOpenTimer();
|
|
225
|
-
|
|
226
|
-
if (immediate) {
|
|
227
|
-
this.clearCloseTimer();
|
|
228
|
-
this.tooltip.setAttribute("data-state", "closed");
|
|
229
|
-
setTimeout(() => {
|
|
230
|
-
if (!this.content) return;
|
|
231
|
-
this.content.style.display = "none";
|
|
232
|
-
}, this.animationDuration);
|
|
233
|
-
this.content.setAttribute("data-state", "closed");
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
this.closeTimerRef = window.setTimeout(
|
|
238
|
-
() => {
|
|
239
|
-
this.tooltip.setAttribute("data-state", "closed");
|
|
240
|
-
setTimeout(() => {
|
|
241
|
-
if (!this.content) return;
|
|
242
|
-
this.content.style.display = "none";
|
|
243
|
-
}, this.animationDuration);
|
|
244
|
-
if (!this.content) return;
|
|
245
|
-
this.content.setAttribute("data-state", "closed");
|
|
246
|
-
this.closeTimerRef = null;
|
|
247
|
-
},
|
|
248
|
-
parseInt(this.tooltip.getAttribute("data-close-delay") || "300"),
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
private clearOpenTimer() {
|
|
253
|
-
if (this.openTimerRef) {
|
|
254
|
-
window.clearTimeout(this.openTimerRef);
|
|
255
|
-
this.openTimerRef = null;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
private clearCloseTimer() {
|
|
260
|
-
if (this.closeTimerRef) {
|
|
261
|
-
window.clearTimeout(this.closeTimerRef);
|
|
262
|
-
this.closeTimerRef = null;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Store instances in a WeakMap to avoid memory leaks
|
|
268
|
-
const tooltipInstances = new WeakMap<HTMLElement, TooltipHandler>();
|
|
269
|
-
let tooltipCounter = 0;
|
|
270
|
-
|
|
271
|
-
const setupTooltips = () => {
|
|
272
|
-
document.querySelectorAll<HTMLElement>(".starwind-tooltip").forEach((tooltip) => {
|
|
273
|
-
if (!tooltipInstances.has(tooltip)) {
|
|
274
|
-
tooltipInstances.set(tooltip, new TooltipHandler(tooltip, tooltipCounter++));
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
setupTooltips();
|
|
280
|
-
document.addEventListener("astro:after-swap", setupTooltips);
|
|
281
|
-
document.addEventListener("starwind:init", setupTooltips);
|
|
282
|
-
</script>
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import CaretUp from "@tabler/icons/filled/caret-up.svg";
|
|
3
|
-
import type { HTMLAttributes } from "astro/types";
|
|
4
|
-
import { tv } from "tailwind-variants";
|
|
5
|
-
|
|
6
|
-
type Props = HTMLAttributes<"div"> & {
|
|
7
|
-
/**
|
|
8
|
-
* Side of the tooltip
|
|
9
|
-
* @default top
|
|
10
|
-
*/
|
|
11
|
-
side?: "top" | "right" | "bottom" | "left";
|
|
12
|
-
/**
|
|
13
|
-
* Alignment of the tooltip
|
|
14
|
-
* @default center
|
|
15
|
-
*/
|
|
16
|
-
align?: "start" | "center" | "end";
|
|
17
|
-
/**
|
|
18
|
-
* Offset distance in pixels
|
|
19
|
-
* @default 8
|
|
20
|
-
*/
|
|
21
|
-
sideOffset?: number;
|
|
22
|
-
/**
|
|
23
|
-
* Prevent the tooltip from colliding with other elements
|
|
24
|
-
* @default true
|
|
25
|
-
*/
|
|
26
|
-
avoidCollisions?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Open and close animation duration in milliseconds
|
|
29
|
-
* @default 150
|
|
30
|
-
*/
|
|
31
|
-
animationDuration?: number;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const tooltipContent = tv({
|
|
35
|
-
base: [
|
|
36
|
-
"starwind-tooltip-content",
|
|
37
|
-
"fixed z-50 hidden w-fit px-3 py-1.5",
|
|
38
|
-
"bg-foreground text-background rounded-md",
|
|
39
|
-
"animate-in fade-in zoom-in-95",
|
|
40
|
-
"data-[state=closed]:animate-out data-[state=closed]:fill-mode-forwards fade-out zoom-out-95",
|
|
41
|
-
],
|
|
42
|
-
variants: {
|
|
43
|
-
side: {
|
|
44
|
-
left: "slide-in-from-right-2",
|
|
45
|
-
right: "slide-in-from-left-2",
|
|
46
|
-
bottom: "slide-in-from-top-2",
|
|
47
|
-
top: "slide-in-from-bottom-2",
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
defaultVariants: { side: "top" },
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
export const tooltipCaret = tv({
|
|
54
|
-
base: ["text-foreground absolute z-50 size-4"],
|
|
55
|
-
variants: {
|
|
56
|
-
side: {
|
|
57
|
-
top: "bottom-0 left-1/2 -translate-x-1/2 translate-y-[calc(50%+1px)] rotate-180",
|
|
58
|
-
bottom: "top-0 left-1/2 -translate-x-1/2 -translate-y-[calc(50%+1px)]",
|
|
59
|
-
left: "top-1/2 right-0 translate-x-[calc(50%+1px)] -translate-y-1/2 rotate-90",
|
|
60
|
-
right: "top-1/2 left-0 -translate-x-[calc(50%+1px)] -translate-y-1/2 -rotate-90",
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
defaultVariants: { side: "top" },
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const {
|
|
67
|
-
side = "top",
|
|
68
|
-
align = "center",
|
|
69
|
-
sideOffset = 8,
|
|
70
|
-
avoidCollisions = true,
|
|
71
|
-
animationDuration = 150,
|
|
72
|
-
class: className,
|
|
73
|
-
} = Astro.props;
|
|
74
|
-
---
|
|
75
|
-
|
|
76
|
-
<div
|
|
77
|
-
class={tooltipContent({ side, class: className })}
|
|
78
|
-
data-slot="tooltip-content"
|
|
79
|
-
data-state="closed"
|
|
80
|
-
data-side={side}
|
|
81
|
-
data-align={align}
|
|
82
|
-
data-side-offset={sideOffset}
|
|
83
|
-
{...avoidCollisions && { "data-avoid-collisions": "" }}
|
|
84
|
-
role="tooltip"
|
|
85
|
-
style={{ animationDuration: `${animationDuration}ms` }}
|
|
86
|
-
>
|
|
87
|
-
<slot> My tooltip! </slot>
|
|
88
|
-
<CaretUp class={tooltipCaret({ side })} />
|
|
89
|
-
</div>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import Tooltip, { tooltip } from "./Tooltip.astro";
|
|
2
|
-
import TooltipContent, { tooltipContent } from "./TooltipContent.astro";
|
|
3
|
-
import TooltipTrigger from "./TooltipTrigger.astro";
|
|
4
|
-
|
|
5
|
-
const TooltipVariants = {
|
|
6
|
-
tooltip,
|
|
7
|
-
tooltipContent,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export { Tooltip, TooltipContent, TooltipTrigger, TooltipVariants };
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
Root: Tooltip,
|
|
14
|
-
Trigger: TooltipTrigger,
|
|
15
|
-
Content: TooltipContent,
|
|
16
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
export const video = tv({
|
|
6
|
-
base: "starwind-video aspect-video h-auto w-full",
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
type Props = HTMLAttributes<"video"> &
|
|
10
|
-
HTMLAttributes<"iframe"> & {
|
|
11
|
-
src: string;
|
|
12
|
-
title?: string;
|
|
13
|
-
autoplay?: boolean;
|
|
14
|
-
muted?: boolean;
|
|
15
|
-
loop?: boolean;
|
|
16
|
-
controls?: boolean;
|
|
17
|
-
poster?: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
class: className,
|
|
22
|
-
src,
|
|
23
|
-
title = "Video",
|
|
24
|
-
autoplay = false,
|
|
25
|
-
muted = false,
|
|
26
|
-
loop = false,
|
|
27
|
-
controls = true,
|
|
28
|
-
poster,
|
|
29
|
-
...rest
|
|
30
|
-
} = Astro.props;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Detects the video type from the src URL
|
|
34
|
-
*/
|
|
35
|
-
function getVideoType(url: string): "youtube" | "youtube-shorts" | "native" {
|
|
36
|
-
if (url.includes("youtube.com/shorts/") || url.includes("youtu.be/shorts/")) {
|
|
37
|
-
return "youtube-shorts";
|
|
38
|
-
}
|
|
39
|
-
if (
|
|
40
|
-
url.includes("youtube.com") ||
|
|
41
|
-
url.includes("youtu.be") ||
|
|
42
|
-
url.includes("youtube-nocookie.com")
|
|
43
|
-
) {
|
|
44
|
-
return "youtube";
|
|
45
|
-
}
|
|
46
|
-
return "native";
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Extracts YouTube video ID from various URL formats
|
|
51
|
-
*/
|
|
52
|
-
function getYouTubeId(url: string): string | null {
|
|
53
|
-
const patterns = [
|
|
54
|
-
/youtube\.com\/shorts\/([^?&]+)/,
|
|
55
|
-
/youtube\.com\/watch\?v=([^&]+)/,
|
|
56
|
-
/youtube\.com\/embed\/([^?&]+)/,
|
|
57
|
-
/youtu\.be\/([^?&]+)/,
|
|
58
|
-
/youtube-nocookie\.com\/embed\/([^?&]+)/,
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
for (const pattern of patterns) {
|
|
62
|
-
const match = url.match(pattern);
|
|
63
|
-
if (match) return match[1];
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Builds YouTube embed URL with parameters
|
|
70
|
-
*/
|
|
71
|
-
function buildYouTubeEmbedUrl(videoId: string, isShort: boolean): string {
|
|
72
|
-
const params = new URLSearchParams();
|
|
73
|
-
if (autoplay) params.set("autoplay", "1");
|
|
74
|
-
if (muted) params.set("mute", "1");
|
|
75
|
-
if (loop) {
|
|
76
|
-
params.set("loop", "1");
|
|
77
|
-
params.set("playlist", videoId);
|
|
78
|
-
}
|
|
79
|
-
if (!controls) params.set("controls", "0");
|
|
80
|
-
|
|
81
|
-
const baseUrl = `https://www.youtube-nocookie.com/embed/${videoId}`;
|
|
82
|
-
const queryString = params.toString();
|
|
83
|
-
return queryString ? `${baseUrl}?${queryString}` : baseUrl;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const videoType = getVideoType(src);
|
|
87
|
-
const youtubeId = videoType !== "native" ? getYouTubeId(src) : null;
|
|
88
|
-
const isShort = videoType === "youtube-shorts";
|
|
89
|
-
const embedUrl = youtubeId ? buildYouTubeEmbedUrl(youtubeId, isShort) : null;
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
videoType === "native" || !embedUrl ? (
|
|
94
|
-
<video
|
|
95
|
-
class={video({ class: className })}
|
|
96
|
-
src={src}
|
|
97
|
-
autoplay={autoplay}
|
|
98
|
-
muted={muted}
|
|
99
|
-
loop={loop}
|
|
100
|
-
controls={controls}
|
|
101
|
-
poster={poster}
|
|
102
|
-
data-slot="video"
|
|
103
|
-
{...rest}
|
|
104
|
-
>
|
|
105
|
-
<track kind="captions" />
|
|
106
|
-
</video>
|
|
107
|
-
) : (
|
|
108
|
-
<iframe
|
|
109
|
-
class={video({ class: className })}
|
|
110
|
-
src={embedUrl}
|
|
111
|
-
title={title}
|
|
112
|
-
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
|
113
|
-
referrerpolicy="strict-origin-when-cross-origin"
|
|
114
|
-
allowfullscreen
|
|
115
|
-
data-slot="video"
|
|
116
|
-
data-video-type={isShort ? "youtube-shorts" : "youtube"}
|
|
117
|
-
{...rest}
|
|
118
|
-
/>
|
|
119
|
-
)
|
|
120
|
-
}
|