@dogsbay/ui 0.2.0-beta.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/package.json +38 -0
- package/src/accordion/Accordion.astro +38 -0
- package/src/accordion/AccordionContent.astro +25 -0
- package/src/accordion/AccordionItem.astro +26 -0
- package/src/accordion/AccordionTrigger.astro +38 -0
- package/src/accordion/accordion.ts +189 -0
- package/src/accordion/index.ts +4 -0
- package/src/alert/Alert.astro +69 -0
- package/src/alert/AlertDescription.astro +17 -0
- package/src/alert/AlertTitle.astro +21 -0
- package/src/alert/CollapsibleAlert.astro +103 -0
- package/src/alert/icon.ts +32 -0
- package/src/alert/index.ts +4 -0
- package/src/alert/variants.ts +29 -0
- package/src/alert-dialog/AlertDialog.astro +16 -0
- package/src/alert-dialog/AlertDialogAction.astro +23 -0
- package/src/alert-dialog/AlertDialogCancel.astro +23 -0
- package/src/alert-dialog/AlertDialogContent.astro +37 -0
- package/src/alert-dialog/AlertDialogDescription.astro +18 -0
- package/src/alert-dialog/AlertDialogFooter.astro +18 -0
- package/src/alert-dialog/AlertDialogHeader.astro +18 -0
- package/src/alert-dialog/AlertDialogTitle.astro +18 -0
- package/src/alert-dialog/AlertDialogTrigger.astro +24 -0
- package/src/alert-dialog/alert-dialog.ts +154 -0
- package/src/alert-dialog/index.ts +9 -0
- package/src/api-doc/ApiDoc.astro +52 -0
- package/src/api-doc/index.ts +1 -0
- package/src/api-layout/ApiCodePanel.astro +21 -0
- package/src/api-layout/ApiLayout.astro +29 -0
- package/src/api-layout/ExampleBlock.astro +63 -0
- package/src/api-params/ApiParams.astro +96 -0
- package/src/api-params/index.ts +1 -0
- package/src/api-source/ApiSource.astro +20 -0
- package/src/api-source/api-source.css +32 -0
- package/src/api-source/index.ts +1 -0
- package/src/api-symbol/ApiSymbol.astro +48 -0
- package/src/api-symbol/api-symbol.css +89 -0
- package/src/api-symbol/index.ts +1 -0
- package/src/api-url-bar/ApiUrlBar.astro +63 -0
- package/src/avatar/Avatar.astro +57 -0
- package/src/avatar/index.ts +1 -0
- package/src/badge/Badge.astro +37 -0
- package/src/badge/index.ts +1 -0
- package/src/breadcrumb/Breadcrumb.astro +32 -0
- package/src/breadcrumb/BreadcrumbEllipsis.astro +32 -0
- package/src/breadcrumb/BreadcrumbItem.astro +41 -0
- package/src/breadcrumb/BreadcrumbSeparator.astro +33 -0
- package/src/breadcrumb/index.ts +4 -0
- package/src/button/Button.astro +70 -0
- package/src/button/index.ts +1 -0
- package/src/card/Card.astro +17 -0
- package/src/card/CardContent.astro +17 -0
- package/src/card/CardDescription.astro +17 -0
- package/src/card/CardFooter.astro +17 -0
- package/src/card/CardHeader.astro +17 -0
- package/src/card/CardTitle.astro +17 -0
- package/src/card/index.ts +6 -0
- package/src/checkbox/Checkbox.astro +70 -0
- package/src/checkbox/index.ts +1 -0
- package/src/checkbox-group/CheckboxGroup.astro +38 -0
- package/src/checkbox-group/checkbox-group.ts +53 -0
- package/src/checkbox-group/index.ts +1 -0
- package/src/code-block/CodeBlock.astro +160 -0
- package/src/code-rich/CodeRich.astro +267 -0
- package/src/code-rich/code-rich.css +68 -0
- package/src/code-rich/index.ts +1 -0
- package/src/code-samples/CodeSamples.astro +59 -0
- package/src/collapsible/Collapsible.astro +35 -0
- package/src/collapsible/CollapsibleContent.astro +24 -0
- package/src/collapsible/CollapsibleTrigger.astro +23 -0
- package/src/collapsible/collapsible.ts +42 -0
- package/src/collapsible/index.ts +3 -0
- package/src/combobox/Combobox.astro +53 -0
- package/src/combobox/ComboboxEmpty.astro +18 -0
- package/src/combobox/ComboboxItem.astro +28 -0
- package/src/combobox/combobox.ts +179 -0
- package/src/combobox/index.ts +3 -0
- package/src/command/Command.astro +22 -0
- package/src/command/CommandEmpty.astro +18 -0
- package/src/command/CommandGroup.astro +24 -0
- package/src/command/CommandInput.astro +49 -0
- package/src/command/CommandItem.astro +26 -0
- package/src/command/CommandList.astro +19 -0
- package/src/command/CommandSeparator.astro +16 -0
- package/src/command/CommandShortcut.astro +18 -0
- package/src/command/command.ts +212 -0
- package/src/command/index.ts +8 -0
- package/src/content-renderer/ContentRenderer.astro +410 -0
- package/src/content-renderer/InlineRenderer.astro +149 -0
- package/src/context-menu/ContextMenu.astro +22 -0
- package/src/context-menu/ContextMenuContent.astro +24 -0
- package/src/context-menu/ContextMenuItem.astro +49 -0
- package/src/context-menu/ContextMenuSeparator.astro +14 -0
- package/src/context-menu/ContextMenuShortcut.astro +14 -0
- package/src/context-menu/ContextMenuTrigger.astro +22 -0
- package/src/context-menu/context-menu.ts +238 -0
- package/src/context-menu/index.ts +6 -0
- package/src/copy-button/CopyButton.astro +88 -0
- package/src/copy-button/index.ts +1 -0
- package/src/diagram/Diagram.astro +15 -0
- package/src/diagram/index.ts +1 -0
- package/src/dialog/Dialog.astro +22 -0
- package/src/dialog/DialogClose.astro +32 -0
- package/src/dialog/DialogContent.astro +37 -0
- package/src/dialog/DialogDescription.astro +22 -0
- package/src/dialog/DialogFooter.astro +18 -0
- package/src/dialog/DialogHeader.astro +18 -0
- package/src/dialog/DialogTitle.astro +18 -0
- package/src/dialog/DialogTrigger.astro +33 -0
- package/src/dialog/dialog.ts +291 -0
- package/src/dialog/index.ts +8 -0
- package/src/docs-footer/DocsFooter.astro +50 -0
- package/src/docs-header/DocsHeader.astro +32 -0
- package/src/docs-layout/DocsLayout.astro +187 -0
- package/src/docs-layout/index.ts +1 -0
- package/src/drawer/Drawer.astro +12 -0
- package/src/drawer/DrawerClose.astro +12 -0
- package/src/drawer/DrawerContent.astro +46 -0
- package/src/drawer/DrawerDescription.astro +10 -0
- package/src/drawer/DrawerFooter.astro +10 -0
- package/src/drawer/DrawerHandle.astro +16 -0
- package/src/drawer/DrawerHeader.astro +10 -0
- package/src/drawer/DrawerTitle.astro +10 -0
- package/src/drawer/DrawerTrigger.astro +25 -0
- package/src/drawer/drawer.ts +262 -0
- package/src/drawer/index.ts +9 -0
- package/src/dropdown-menu/DropdownMenu.astro +22 -0
- package/src/dropdown-menu/DropdownMenuContent.astro +33 -0
- package/src/dropdown-menu/DropdownMenuGroup.astro +17 -0
- package/src/dropdown-menu/DropdownMenuItem.astro +48 -0
- package/src/dropdown-menu/DropdownMenuLabel.astro +28 -0
- package/src/dropdown-menu/DropdownMenuSeparator.astro +21 -0
- package/src/dropdown-menu/DropdownMenuShortcut.astro +18 -0
- package/src/dropdown-menu/DropdownMenuTrigger.astro +34 -0
- package/src/dropdown-menu/dropdown-menu.ts +348 -0
- package/src/dropdown-menu/index.ts +8 -0
- package/src/endpoint-card/EndpointCard.astro +60 -0
- package/src/endpoint-card/EndpointCardSection.astro +22 -0
- package/src/endpoint-card/EndpointSection.astro +35 -0
- package/src/field/Field.astro +31 -0
- package/src/field/FieldDescription.astro +22 -0
- package/src/field/FieldLabel.astro +24 -0
- package/src/field/field.ts +61 -0
- package/src/field/index.ts +3 -0
- package/src/fieldset/Fieldset.astro +24 -0
- package/src/fieldset/FieldsetLegend.astro +18 -0
- package/src/fieldset/index.ts +2 -0
- package/src/footnote/Footnote.astro +37 -0
- package/src/footnote/footnote.ts +79 -0
- package/src/footnote/index.ts +1 -0
- package/src/form/Form.astro +27 -0
- package/src/form/form.ts +160 -0
- package/src/form/index.ts +1 -0
- package/src/grid/Grid.astro +117 -0
- package/src/grid/GridItem.astro +95 -0
- package/src/grid/index.ts +2 -0
- package/src/image/Image.astro +115 -0
- package/src/image/index.ts +1 -0
- package/src/input/Input.astro +34 -0
- package/src/input/index.ts +1 -0
- package/src/kbd/Kbd.astro +17 -0
- package/src/kbd/index.ts +1 -0
- package/src/label/Label.astro +17 -0
- package/src/label/index.ts +1 -0
- package/src/link-card/LinkCard.astro +47 -0
- package/src/link-card/index.ts +1 -0
- package/src/map-view/MapView.astro +88 -0
- package/src/map-view/index.ts +1 -0
- package/src/map-view/map-view.ts +194 -0
- package/src/markdown-example/MarkdownExample.astro +138 -0
- package/src/markdown-example/index.ts +1 -0
- package/src/math/MathKatex.astro +35 -0
- package/src/math/index.ts +1 -0
- package/src/menubar/Menubar.astro +25 -0
- package/src/menubar/MenubarContent.astro +24 -0
- package/src/menubar/MenubarItem.astro +26 -0
- package/src/menubar/MenubarMenu.astro +12 -0
- package/src/menubar/MenubarSeparator.astro +11 -0
- package/src/menubar/MenubarShortcut.astro +11 -0
- package/src/menubar/MenubarTrigger.astro +27 -0
- package/src/menubar/index.ts +7 -0
- package/src/menubar/menubar.ts +258 -0
- package/src/meter/Meter.astro +75 -0
- package/src/meter/index.ts +1 -0
- package/src/method-badge/MethodBadge.astro +32 -0
- package/src/navigation-menu/NavigationMenu.astro +24 -0
- package/src/navigation-menu/NavigationMenuContent.astro +24 -0
- package/src/navigation-menu/NavigationMenuItem.astro +22 -0
- package/src/navigation-menu/NavigationMenuLink.astro +26 -0
- package/src/navigation-menu/NavigationMenuList.astro +22 -0
- package/src/navigation-menu/NavigationMenuTrigger.astro +40 -0
- package/src/navigation-menu/index.ts +6 -0
- package/src/navigation-menu/navigation-menu.ts +192 -0
- package/src/number-field/NumberField.astro +84 -0
- package/src/number-field/index.ts +1 -0
- package/src/number-field/number-field.ts +68 -0
- package/src/pagination/Pagination.astro +59 -0
- package/src/pagination/index.ts +1 -0
- package/src/parameter-table/ParameterTable.astro +75 -0
- package/src/popover/Popover.astro +21 -0
- package/src/popover/PopoverContent.astro +31 -0
- package/src/popover/PopoverTrigger.astro +31 -0
- package/src/popover/index.ts +3 -0
- package/src/popover/popover.ts +144 -0
- package/src/preview-card/PreviewCard.astro +24 -0
- package/src/preview-card/PreviewCardContent.astro +24 -0
- package/src/preview-card/PreviewCardTrigger.astro +23 -0
- package/src/preview-card/index.ts +3 -0
- package/src/preview-card/preview-card.ts +91 -0
- package/src/progress/Progress.astro +61 -0
- package/src/progress/index.ts +1 -0
- package/src/property-item/PropertyItem.astro +183 -0
- package/src/property-list/PropertyList.astro +68 -0
- package/src/radio-group/RadioGroup.astro +41 -0
- package/src/radio-group/RadioGroupItem.astro +36 -0
- package/src/radio-group/index.ts +2 -0
- package/src/radio-group/radio-group.ts +126 -0
- package/src/response-tabs/ResponseTabs.astro +60 -0
- package/src/schema-viewer/SchemaViewer.astro +42 -0
- package/src/scroll-area/ScrollArea.astro +44 -0
- package/src/scroll-area/index.ts +1 -0
- package/src/scroll-area/scroll-area.ts +176 -0
- package/src/select/Select.astro +34 -0
- package/src/select/SelectContent.astro +24 -0
- package/src/select/SelectGroup.astro +23 -0
- package/src/select/SelectItem.astro +28 -0
- package/src/select/SelectLabel.astro +18 -0
- package/src/select/SelectSeparator.astro +22 -0
- package/src/select/SelectTrigger.astro +28 -0
- package/src/select/SelectValue.astro +18 -0
- package/src/select/index.ts +8 -0
- package/src/select/select.ts +381 -0
- package/src/separator/Separator.astro +35 -0
- package/src/separator/index.ts +1 -0
- package/src/sheet/Sheet.astro +12 -0
- package/src/sheet/SheetClose.astro +35 -0
- package/src/sheet/SheetContent.astro +52 -0
- package/src/sheet/SheetDescription.astro +18 -0
- package/src/sheet/SheetFooter.astro +18 -0
- package/src/sheet/SheetHeader.astro +18 -0
- package/src/sheet/SheetTitle.astro +18 -0
- package/src/sheet/SheetTrigger.astro +32 -0
- package/src/sheet/index.ts +8 -0
- package/src/sheet/sheet.ts +173 -0
- package/src/sidebar/Sidebar.astro +113 -0
- package/src/sidebar/SidebarContent.astro +18 -0
- package/src/sidebar/SidebarFooter.astro +18 -0
- package/src/sidebar/SidebarGroup.astro +18 -0
- package/src/sidebar/SidebarGroupContent.astro +18 -0
- package/src/sidebar/SidebarGroupLabel.astro +18 -0
- package/src/sidebar/SidebarHeader.astro +18 -0
- package/src/sidebar/SidebarInset.astro +18 -0
- package/src/sidebar/SidebarMenu.astro +18 -0
- package/src/sidebar/SidebarMenuBadge.astro +18 -0
- package/src/sidebar/SidebarMenuButton.astro +71 -0
- package/src/sidebar/SidebarMenuItem.astro +18 -0
- package/src/sidebar/SidebarMenuSub.astro +18 -0
- package/src/sidebar/SidebarMenuSubButton.astro +45 -0
- package/src/sidebar/SidebarMenuSubItem.astro +12 -0
- package/src/sidebar/SidebarNavTree.astro +106 -0
- package/src/sidebar/SidebarProvider.astro +23 -0
- package/src/sidebar/SidebarRail.astro +25 -0
- package/src/sidebar/SidebarSeparator.astro +21 -0
- package/src/sidebar/SidebarTrigger.astro +40 -0
- package/src/sidebar/index.ts +19 -0
- package/src/sidebar/sidebar.ts +265 -0
- package/src/skeleton/Skeleton.astro +16 -0
- package/src/skeleton/index.ts +1 -0
- package/src/skip-link/SkipLink.astro +24 -0
- package/src/slider/Slider.astro +61 -0
- package/src/slider/index.ts +1 -0
- package/src/slider/slider.ts +111 -0
- package/src/spinner/Spinner.astro +54 -0
- package/src/spinner/index.ts +1 -0
- package/src/steps/Step.astro +16 -0
- package/src/steps/Steps.astro +122 -0
- package/src/steps/SubSteps.astro +73 -0
- package/src/switch/Switch.astro +52 -0
- package/src/switch/index.ts +1 -0
- package/src/switch/switch.ts +109 -0
- package/src/table/Table.astro +24 -0
- package/src/table/TableBody.astro +18 -0
- package/src/table/TableCaption.astro +18 -0
- package/src/table/TableCell.astro +18 -0
- package/src/table/TableFooter.astro +18 -0
- package/src/table/TableHead.astro +18 -0
- package/src/table/TableHeader.astro +18 -0
- package/src/table/TableRow.astro +18 -0
- package/src/table/index.ts +8 -0
- package/src/tabs/Tabs.astro +37 -0
- package/src/tabs/TabsContent.astro +32 -0
- package/src/tabs/TabsList.astro +23 -0
- package/src/tabs/TabsTrigger.astro +29 -0
- package/src/tabs/index.ts +4 -0
- package/src/tabs/tabs.ts +220 -0
- package/src/textarea/Textarea.astro +25 -0
- package/src/textarea/index.ts +1 -0
- package/src/theme-toggle/ThemeToggle.astro +67 -0
- package/src/theme-toggle/index.ts +1 -0
- package/src/toast/Toaster.astro +39 -0
- package/src/toast/index.ts +3 -0
- package/src/toast/toast.ts +104 -0
- package/src/toc/TableOfContents.astro +225 -0
- package/src/toggle/Toggle.astro +56 -0
- package/src/toggle/index.ts +1 -0
- package/src/toggle/toggle.ts +38 -0
- package/src/toggle-group/ToggleGroup.astro +39 -0
- package/src/toggle-group/ToggleGroupItem.astro +56 -0
- package/src/toggle-group/index.ts +2 -0
- package/src/toggle-group/toggle-group.ts +121 -0
- package/src/toolbar/Toolbar.astro +26 -0
- package/src/toolbar/ToolbarButton.astro +29 -0
- package/src/toolbar/ToolbarSeparator.astro +14 -0
- package/src/toolbar/index.ts +3 -0
- package/src/toolbar/toolbar.ts +65 -0
- package/src/tooltip/Tooltip.astro +21 -0
- package/src/tooltip/TooltipContent.astro +25 -0
- package/src/tooltip/TooltipTrigger.astro +31 -0
- package/src/tooltip/index.ts +3 -0
- package/src/tooltip/tooltip.ts +156 -0
- package/src/youtube/YouTube.astro +119 -0
- package/src/youtube/index.ts +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { tv } from "tailwind-variants";
|
|
3
|
+
|
|
4
|
+
const tooltip = tv({
|
|
5
|
+
base: "relative inline-block",
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
class?: string;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
const { class: className, ...rest } = Astro.props;
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
<div
|
|
16
|
+
class={tooltip({ class: className })}
|
|
17
|
+
data-component="tooltip"
|
|
18
|
+
{...rest}
|
|
19
|
+
>
|
|
20
|
+
<slot />
|
|
21
|
+
</div>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { tv } from "tailwind-variants";
|
|
3
|
+
|
|
4
|
+
const tooltipContent = tv({
|
|
5
|
+
base: "z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md",
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
side?: "top" | "bottom" | "left" | "right";
|
|
10
|
+
class?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
const { side = "top", class: className, ...rest } = Astro.props;
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
<div
|
|
17
|
+
class={tooltipContent({ class: className })}
|
|
18
|
+
data-part="content"
|
|
19
|
+
data-side={side}
|
|
20
|
+
role="tooltip"
|
|
21
|
+
hidden
|
|
22
|
+
{...rest}
|
|
23
|
+
>
|
|
24
|
+
<slot />
|
|
25
|
+
</div>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { tv } from "tailwind-variants";
|
|
3
|
+
|
|
4
|
+
const tooltipTrigger = tv({
|
|
5
|
+
base: "inline-flex items-center justify-center",
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
asChild?: boolean;
|
|
10
|
+
class?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
const { asChild = false, class: className, ...rest } = Astro.props;
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
{
|
|
17
|
+
asChild ? (
|
|
18
|
+
<span data-part="trigger" data-as-child>
|
|
19
|
+
<slot />
|
|
20
|
+
</span>
|
|
21
|
+
) : (
|
|
22
|
+
<button
|
|
23
|
+
class={tooltipTrigger({ class: className })}
|
|
24
|
+
data-part="trigger"
|
|
25
|
+
type="button"
|
|
26
|
+
{...rest}
|
|
27
|
+
>
|
|
28
|
+
<slot />
|
|
29
|
+
</button>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { setupFloating } from "@dogsbay/primitives/floating";
|
|
2
|
+
import type { Placement } from "@floating-ui/dom";
|
|
3
|
+
|
|
4
|
+
interface TooltipInstance {
|
|
5
|
+
root: HTMLElement;
|
|
6
|
+
trigger: HTMLElement;
|
|
7
|
+
content: HTMLElement;
|
|
8
|
+
cleanupFloating: (() => void) | null;
|
|
9
|
+
open: boolean;
|
|
10
|
+
showTimeout: ReturnType<typeof setTimeout> | null;
|
|
11
|
+
hideTimeout: ReturnType<typeof setTimeout> | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const instances = new WeakMap<HTMLElement, TooltipInstance>();
|
|
15
|
+
|
|
16
|
+
let idCounter = 0;
|
|
17
|
+
function uniqueId(prefix: string) {
|
|
18
|
+
return `${prefix}-${++idCounter}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const SHOW_DELAY = 200;
|
|
22
|
+
const HIDE_DELAY = 0;
|
|
23
|
+
|
|
24
|
+
function resolveAsChild(wrapper: HTMLElement): HTMLElement {
|
|
25
|
+
const child = wrapper.firstElementChild as HTMLElement | null;
|
|
26
|
+
if (child) {
|
|
27
|
+
const part = wrapper.getAttribute("data-part");
|
|
28
|
+
if (part) child.setAttribute("data-part", part);
|
|
29
|
+
return child;
|
|
30
|
+
}
|
|
31
|
+
return wrapper;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function initTooltip(root: HTMLElement) {
|
|
35
|
+
if (instances.has(root)) return;
|
|
36
|
+
|
|
37
|
+
const triggerWrapper = root.querySelector(
|
|
38
|
+
"[data-part='trigger']",
|
|
39
|
+
) as HTMLElement | null;
|
|
40
|
+
const content = root.querySelector(
|
|
41
|
+
"[data-part='content']",
|
|
42
|
+
) as HTMLElement | null;
|
|
43
|
+
if (!triggerWrapper || !content) return;
|
|
44
|
+
|
|
45
|
+
let trigger = triggerWrapper;
|
|
46
|
+
if (triggerWrapper.hasAttribute("data-as-child")) {
|
|
47
|
+
trigger = resolveAsChild(triggerWrapper);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const contentId = content.id || uniqueId("base-tooltip");
|
|
51
|
+
content.id = contentId;
|
|
52
|
+
trigger.setAttribute("aria-describedby", contentId);
|
|
53
|
+
|
|
54
|
+
const instance: TooltipInstance = {
|
|
55
|
+
root,
|
|
56
|
+
trigger,
|
|
57
|
+
content,
|
|
58
|
+
cleanupFloating: null,
|
|
59
|
+
open: false,
|
|
60
|
+
showTimeout: null,
|
|
61
|
+
hideTimeout: null,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
instances.set(root, instance);
|
|
65
|
+
|
|
66
|
+
// Mouse events
|
|
67
|
+
trigger.addEventListener("mouseenter", () => scheduleShow(root));
|
|
68
|
+
trigger.addEventListener("mouseleave", () => scheduleHide(root));
|
|
69
|
+
|
|
70
|
+
// Focus events (keyboard accessibility)
|
|
71
|
+
trigger.addEventListener("focus", () => showTooltip(root));
|
|
72
|
+
trigger.addEventListener("blur", () => hideTooltip(root));
|
|
73
|
+
|
|
74
|
+
// Escape closes
|
|
75
|
+
trigger.addEventListener("keydown", (e) => {
|
|
76
|
+
if (e.key === "Escape" && instance.open) {
|
|
77
|
+
hideTooltip(root);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function scheduleShow(root: HTMLElement) {
|
|
83
|
+
const instance = instances.get(root);
|
|
84
|
+
if (!instance) return;
|
|
85
|
+
|
|
86
|
+
clearTimeouts(instance);
|
|
87
|
+
instance.showTimeout = setTimeout(() => showTooltip(root), SHOW_DELAY);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function scheduleHide(root: HTMLElement) {
|
|
91
|
+
const instance = instances.get(root);
|
|
92
|
+
if (!instance) return;
|
|
93
|
+
|
|
94
|
+
clearTimeouts(instance);
|
|
95
|
+
instance.hideTimeout = setTimeout(() => hideTooltip(root), HIDE_DELAY);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function clearTimeouts(instance: TooltipInstance) {
|
|
99
|
+
if (instance.showTimeout) {
|
|
100
|
+
clearTimeout(instance.showTimeout);
|
|
101
|
+
instance.showTimeout = null;
|
|
102
|
+
}
|
|
103
|
+
if (instance.hideTimeout) {
|
|
104
|
+
clearTimeout(instance.hideTimeout);
|
|
105
|
+
instance.hideTimeout = null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function showTooltip(root: HTMLElement) {
|
|
110
|
+
const instance = instances.get(root);
|
|
111
|
+
if (!instance || instance.open) return;
|
|
112
|
+
instance.open = true;
|
|
113
|
+
|
|
114
|
+
clearTimeouts(instance);
|
|
115
|
+
|
|
116
|
+
instance.content.hidden = false;
|
|
117
|
+
instance.content.setAttribute("data-state", "open");
|
|
118
|
+
|
|
119
|
+
const side = (instance.content.dataset.side || "top") as Placement;
|
|
120
|
+
|
|
121
|
+
instance.cleanupFloating = setupFloating(instance.trigger, instance.content, {
|
|
122
|
+
placement: side,
|
|
123
|
+
offset: 8,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function hideTooltip(root: HTMLElement) {
|
|
128
|
+
const instance = instances.get(root);
|
|
129
|
+
if (!instance || !instance.open) return;
|
|
130
|
+
instance.open = false;
|
|
131
|
+
|
|
132
|
+
clearTimeouts(instance);
|
|
133
|
+
|
|
134
|
+
instance.content.setAttribute("data-state", "closed");
|
|
135
|
+
instance.content.hidden = true;
|
|
136
|
+
|
|
137
|
+
if (instance.cleanupFloating) {
|
|
138
|
+
instance.cleanupFloating();
|
|
139
|
+
instance.cleanupFloating = null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function init() {
|
|
144
|
+
document.querySelectorAll("[data-component='tooltip']").forEach((el) => {
|
|
145
|
+
initTooltip(el as HTMLElement);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (document.readyState === "loading") {
|
|
150
|
+
document.addEventListener("DOMContentLoaded", init);
|
|
151
|
+
} else {
|
|
152
|
+
init();
|
|
153
|
+
}
|
|
154
|
+
document.addEventListener("astro:page-load", init);
|
|
155
|
+
|
|
156
|
+
export { initTooltip, showTooltip, hideTooltip };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* YouTube component — lightweight facade that shows a thumbnail placeholder
|
|
4
|
+
* and loads the full YouTube iframe only when clicked.
|
|
5
|
+
*
|
|
6
|
+
* Inspired by lite-youtube-embed. Uses youtube-nocookie.com for privacy.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* <YouTube id="xlABhbnNrfI" title="How to set up Material for MkDocs" />
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
/** YouTube video ID (the part after v= in the URL) */
|
|
14
|
+
id: string;
|
|
15
|
+
/** Accessible title for the video */
|
|
16
|
+
title?: string;
|
|
17
|
+
/** Custom poster image URL. Defaults to YouTube's maxresdefault thumbnail. */
|
|
18
|
+
poster?: string;
|
|
19
|
+
/** Poster quality when using default YouTube thumbnails */
|
|
20
|
+
posterQuality?: "default" | "hqdefault" | "mqdefault" | "sddefault" | "maxresdefault";
|
|
21
|
+
/** Additional YouTube player parameters (e.g. "start=30&autoplay=1") */
|
|
22
|
+
params?: string;
|
|
23
|
+
/** Embed domain. Default: "www.youtube.com". Use "www.youtube-nocookie.com" for enhanced privacy. */
|
|
24
|
+
domain?: string;
|
|
25
|
+
/** Aspect ratio class (default: aspect-video = 16:9) */
|
|
26
|
+
aspectRatio?: string;
|
|
27
|
+
class?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
id,
|
|
32
|
+
title = "YouTube video",
|
|
33
|
+
poster,
|
|
34
|
+
posterQuality = "hqdefault",
|
|
35
|
+
params = "",
|
|
36
|
+
domain = "www.youtube.com",
|
|
37
|
+
aspectRatio = "aspect-video",
|
|
38
|
+
class: className,
|
|
39
|
+
} = Astro.props;
|
|
40
|
+
|
|
41
|
+
const posterUrl = poster || `https://i.ytimg.com/vi/${id}/${posterQuality}.jpg`;
|
|
42
|
+
const embedUrl = `https://${domain}/embed/${id}?autoplay=1${params ? "&" + params : ""}`;
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
<div
|
|
46
|
+
class:list={[
|
|
47
|
+
"group/yt relative w-full cursor-pointer overflow-hidden rounded-lg bg-black",
|
|
48
|
+
aspectRatio,
|
|
49
|
+
className,
|
|
50
|
+
]}
|
|
51
|
+
data-youtube={id}
|
|
52
|
+
data-embed-url={embedUrl}
|
|
53
|
+
data-title={title}
|
|
54
|
+
role="button"
|
|
55
|
+
tabindex="0"
|
|
56
|
+
aria-label={`Play: ${title}`}
|
|
57
|
+
>
|
|
58
|
+
{/* Thumbnail */}
|
|
59
|
+
<img
|
|
60
|
+
src={posterUrl}
|
|
61
|
+
alt={title}
|
|
62
|
+
loading="lazy"
|
|
63
|
+
class="absolute inset-0 h-full w-full object-cover transition-opacity duration-300 group-hover/yt:opacity-80"
|
|
64
|
+
/>
|
|
65
|
+
|
|
66
|
+
{/* Play button overlay */}
|
|
67
|
+
<div class="absolute inset-0 flex items-center justify-center">
|
|
68
|
+
<div class="flex h-16 w-16 items-center justify-center rounded-full bg-red-600 shadow-lg transition-transform duration-200 group-hover/yt:scale-110">
|
|
69
|
+
<svg viewBox="0 0 24 24" fill="white" class="ml-1 h-8 w-8">
|
|
70
|
+
<path d="M8 5v14l11-7z" />
|
|
71
|
+
</svg>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
{/* Title bar */}
|
|
76
|
+
<div class="absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/70 to-transparent px-4 py-3">
|
|
77
|
+
<span class="text-sm font-medium text-white">{title}</span>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<script>
|
|
82
|
+
function initYouTube() {
|
|
83
|
+
document.querySelectorAll<HTMLElement>("[data-youtube]").forEach((el) => {
|
|
84
|
+
if ((el as any).__ytBound) return;
|
|
85
|
+
(el as any).__ytBound = true;
|
|
86
|
+
|
|
87
|
+
function activate() {
|
|
88
|
+
const embedUrl = el.getAttribute("data-embed-url") || "";
|
|
89
|
+
const videoTitle = el.getAttribute("data-title") || "YouTube video";
|
|
90
|
+
|
|
91
|
+
const iframe = document.createElement("iframe");
|
|
92
|
+
iframe.src = embedUrl;
|
|
93
|
+
iframe.title = videoTitle;
|
|
94
|
+
iframe.allow = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share";
|
|
95
|
+
iframe.allowFullscreen = true;
|
|
96
|
+
iframe.className = "absolute inset-0 h-full w-full";
|
|
97
|
+
iframe.style.border = "none";
|
|
98
|
+
|
|
99
|
+
// Replace content with iframe
|
|
100
|
+
el.innerHTML = "";
|
|
101
|
+
el.appendChild(iframe);
|
|
102
|
+
el.style.cursor = "default";
|
|
103
|
+
el.removeAttribute("role");
|
|
104
|
+
el.removeAttribute("tabindex");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
el.addEventListener("click", activate, { once: true });
|
|
108
|
+
el.addEventListener("keydown", (e) => {
|
|
109
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
activate();
|
|
112
|
+
}
|
|
113
|
+
}, { once: true });
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
initYouTube();
|
|
118
|
+
document.addEventListener("astro:page-load", initYouTube);
|
|
119
|
+
</script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as YouTube } from "./YouTube.astro";
|