@astronox/core 0.1.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/LICENSE +21 -0
- package/README.md +66 -0
- package/package.json +77 -0
- package/src/client/clipboard.ts +7 -0
- package/src/client/focus.ts +17 -0
- package/src/client/index.ts +3 -0
- package/src/client/scroll.ts +15 -0
- package/src/components/actions/ActionListItem/ActionListItem.astro +78 -0
- package/src/components/actions/ActionListItem/ActionListItem.css +43 -0
- package/src/components/actions/Button/Button.astro +100 -0
- package/src/components/actions/Button/Button.css +165 -0
- package/src/components/actions/CardAction/CardAction.astro +97 -0
- package/src/components/actions/CardAction/CardAction.css +188 -0
- package/src/components/actions/MediaTrigger/MediaTrigger.astro +55 -0
- package/src/components/actions/MediaTrigger/MediaTrigger.css +175 -0
- package/src/components/actions/ScrollToTop/ScrollToTop.astro +36 -0
- package/src/components/actions/ScrollToTop/ScrollToTop.css +19 -0
- package/src/components/actions/ScrollToTop/scrollToTopController.ts +32 -0
- package/src/components/content/CardBody/CardBody.astro +31 -0
- package/src/components/content/CardBody/CardBody.css +74 -0
- package/src/components/content/CardFooter/CardFooter.astro +58 -0
- package/src/components/content/CardFooter/CardFooter.css +102 -0
- package/src/components/content/CardHeader/CardHeader.astro +96 -0
- package/src/components/content/CardHeader/CardHeader.css +164 -0
- package/src/components/content/CardLink/CardLink.astro +138 -0
- package/src/components/content/CardLink/CardLink.css +362 -0
- package/src/components/content/CodeBlock/CodeBlock.astro +102 -0
- package/src/components/content/CodeBlock/CodeBlock.css +85 -0
- package/src/components/content/CodeBlock/codeBlockController.ts +60 -0
- package/src/components/content/CodeBlock/contracts.ts +8 -0
- package/src/components/content/InlineDefinition/InlineDefinition.astro +31 -0
- package/src/components/content/InlineDefinition/InlineDefinition.css +9 -0
- package/src/components/content/MarkdownContent/MarkdownContent.astro +32 -0
- package/src/components/content/MarkdownContent/MarkdownContent.css +358 -0
- package/src/components/content/MarkdownContent/MarkdownInline.astro +44 -0
- package/src/components/content/MarkdownContent/MarkdownNode.astro +280 -0
- package/src/components/content/MarkdownContent/MarkdownSymbol.astro +47 -0
- package/src/components/content/MarkdownContent/contracts.ts +181 -0
- package/src/components/data-display/BadgeList/BadgeList.astro +54 -0
- package/src/components/data-display/BadgeList/BadgeList.css +29 -0
- package/src/components/data-display/IconList/IconList.astro +64 -0
- package/src/components/data-display/IconList/IconList.css +55 -0
- package/src/components/data-display/MetricTile/MetricTile.astro +68 -0
- package/src/components/data-display/MetricTile/MetricTile.css +103 -0
- package/src/components/data-display/MetricTile/MetricTileContent.astro +70 -0
- package/src/components/data-display/MetricTile/metricTileController.ts +9 -0
- package/src/components/data-display/Tag/Tag.astro +67 -0
- package/src/components/data-display/Tag/Tag.css +134 -0
- package/src/components/data-display/Tag/TagAffix.astro +33 -0
- package/src/components/data-display/TextPair/TextPair.astro +63 -0
- package/src/components/data-display/TextPair/TextPair.css +99 -0
- package/src/components/feedback/Spinner/Spinner.astro +32 -0
- package/src/components/feedback/Spinner/Spinner.css +37 -0
- package/src/components/feedback/Tooltip/Tooltip.astro +66 -0
- package/src/components/feedback/Tooltip/Tooltip.css +67 -0
- package/src/components/feedback/Tooltip/tooltipController.ts +371 -0
- package/src/components/forms/FieldError/FieldError.astro +31 -0
- package/src/components/forms/FieldError/FieldError.css +12 -0
- package/src/components/forms/FieldError/fieldErrorState.ts +21 -0
- package/src/components/forms/FieldLabel/FieldLabel.astro +32 -0
- package/src/components/forms/FieldLabel/FieldLabel.css +17 -0
- package/src/components/forms/TextInput/TextInput.astro +79 -0
- package/src/components/forms/TextInput/TextInput.css +121 -0
- package/src/components/forms/TextInput/textInputController.ts +53 -0
- package/src/components/icons/ArrowDownIcon.astro +26 -0
- package/src/components/icons/ArrowLeftIcon.astro +26 -0
- package/src/components/icons/ArrowRightIcon.astro +26 -0
- package/src/components/icons/ArrowUpDownIcon.astro +26 -0
- package/src/components/icons/ArrowUpIcon.astro +26 -0
- package/src/components/icons/BulletIcon.astro +21 -0
- package/src/components/icons/BurnIcon.astro +24 -0
- package/src/components/icons/CircleSymbolIcon.css +66 -0
- package/src/components/icons/ClearIcon.astro +28 -0
- package/src/components/icons/CloseIcon.astro +21 -0
- package/src/components/icons/CopyIcon.astro +30 -0
- package/src/components/icons/CurrencyIcon.css +9 -0
- package/src/components/icons/DayIcon.astro +33 -0
- package/src/components/icons/DollarIcon.astro +28 -0
- package/src/components/icons/DownloadIcon.astro +22 -0
- package/src/components/icons/EnterFullscreenIcon.astro +22 -0
- package/src/components/icons/EqualIcon.astro +25 -0
- package/src/components/icons/ExitFullscreenIcon.astro +22 -0
- package/src/components/icons/ExternalLinkIcon.astro +22 -0
- package/src/components/icons/FieldIcon.astro +28 -0
- package/src/components/icons/GrassIcon.astro +29 -0
- package/src/components/icons/InfoIcon.astro +24 -0
- package/src/components/icons/MinusIcon.astro +21 -0
- package/src/components/icons/MountainIcon.astro +31 -0
- package/src/components/icons/NightIcon.astro +32 -0
- package/src/components/icons/PlayIcon.astro +22 -0
- package/src/components/icons/PlusIcon.astro +21 -0
- package/src/components/icons/PoisonIcon.astro +24 -0
- package/src/components/icons/RibbonIcon.astro +25 -0
- package/src/components/icons/SlashIcon.astro +22 -0
- package/src/components/icons/SlowIcon.astro +25 -0
- package/src/components/icons/StarIcon.astro +28 -0
- package/src/components/icons/StunIcon.astro +22 -0
- package/src/components/icons/TableSortIcon.astro +34 -0
- package/src/components/icons/WaterIcon.astro +30 -0
- package/src/components/index.ts +83 -0
- package/src/components/media/CanvasFrame/CanvasFrame.astro +130 -0
- package/src/components/media/CanvasFrame/CanvasFrame.css +59 -0
- package/src/components/media/CanvasFrame/canvasFrameController.ts +104 -0
- package/src/components/media/EmbedFrame/EmbedFrame.astro +147 -0
- package/src/components/media/EmbedFrame/EmbedFrame.css +51 -0
- package/src/components/media/EmbedFrame/embedFrameController.ts +66 -0
- package/src/components/media/MediaFrame/MediaFrame.astro +34 -0
- package/src/components/media/MediaFrame/MediaFrame.css +66 -0
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.astro +55 -0
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.css +89 -0
- package/src/components/navigation/DesktopNavigation.astro +92 -0
- package/src/components/navigation/DesktopNavigation.css +99 -0
- package/src/components/navigation/Header.astro +73 -0
- package/src/components/navigation/Header.css +20 -0
- package/src/components/navigation/MobileNavigation.astro +124 -0
- package/src/components/navigation/MobileNavigation.css +177 -0
- package/src/components/navigation/NavigationBrand.astro +63 -0
- package/src/components/navigation/NavigationBrand.css +52 -0
- package/src/components/navigation/NavigationControl.css +166 -0
- package/src/components/navigation/NavigationItemContent.astro +24 -0
- package/src/components/navigation/NavigationLink.astro +121 -0
- package/src/components/navigation/NavigationLinks.astro +27 -0
- package/src/components/navigation/NavigationMenuList.astro +37 -0
- package/src/components/navigation/NavigationMenuList.css +6 -0
- package/src/components/navigation/SkipLink/SkipLink.astro +18 -0
- package/src/components/navigation/SkipLink/SkipLink.css +26 -0
- package/src/components/navigation/SubNavigation/SubNavigation.astro +124 -0
- package/src/components/navigation/SubNavigation/SubNavigation.css +211 -0
- package/src/components/navigation/mobileNavigationController.ts +122 -0
- package/src/components/navigation/navigationState.ts +35 -0
- package/src/components/navigation/navigationTypes.ts +18 -0
- package/src/components/seo/SeoHead.astro +194 -0
- package/src/components/widgetTypes.ts +3 -0
- package/src/composition/Grid/Grid.astro +82 -0
- package/src/composition/Grid/Grid.css +314 -0
- package/src/composition/GridItem/GridItem.astro +50 -0
- package/src/composition/GridItem/GridItem.css +95 -0
- package/src/composition/Inline/Inline.astro +48 -0
- package/src/composition/Inline/Inline.css +65 -0
- package/src/composition/Stack/Stack.astro +37 -0
- package/src/composition/Stack/Stack.css +31 -0
- package/src/composition/SurfaceGroup/SurfaceGroup.astro +44 -0
- package/src/composition/SurfaceGroup/SurfaceGroup.css +76 -0
- package/src/composition/SurfaceGroup/stickySurfaceGroupController.ts +89 -0
- package/src/composition/index.ts +6 -0
- package/src/config/index.ts +2 -0
- package/src/config/pageMeta.ts +55 -0
- package/src/config/siteConfig.ts +90 -0
- package/src/data/collectionValidation.ts +61 -0
- package/src/data/index.ts +1 -0
- package/src/display/contracts.ts +284 -0
- package/src/display/index.ts +1 -0
- package/src/index.ts +6 -0
- package/src/layouts/BaseLayout.astro +74 -0
- package/src/layouts/PageSurface.astro +15 -0
- package/src/layouts/PageSurface.css +24 -0
- package/src/layouts/index.ts +2 -0
- package/src/patterns/CircuitPuzzle/CircuitPuzzle.astro +93 -0
- package/src/patterns/CircuitPuzzle/CircuitPuzzle.css +118 -0
- package/src/patterns/CircuitPuzzle/circuitPuzzleController.ts +205 -0
- package/src/patterns/CircuitPuzzle/contracts.ts +42 -0
- package/src/patterns/Combobox/Combobox.astro +462 -0
- package/src/patterns/Combobox/Combobox.css +403 -0
- package/src/patterns/Combobox/comboboxController.ts +788 -0
- package/src/patterns/Combobox/contracts.ts +18 -0
- package/src/patterns/Dropdown/Dropdown.astro +127 -0
- package/src/patterns/Dropdown/Dropdown.css +100 -0
- package/src/patterns/Dropdown/dropdownController.ts +157 -0
- package/src/patterns/Fullscreen/FullscreenControl.astro +103 -0
- package/src/patterns/Fullscreen/FullscreenControl.css +49 -0
- package/src/patterns/Fullscreen/fullscreenController.ts +73 -0
- package/src/patterns/GlitchOverlay/GlitchOverlay.astro +50 -0
- package/src/patterns/GlitchOverlay/GlitchOverlay.css +234 -0
- package/src/patterns/GlitchOverlay/glitchOverlayController.ts +152 -0
- package/src/patterns/GuidedFlow/GuidedFlow.astro +60 -0
- package/src/patterns/GuidedFlow/GuidedFlow.css +82 -0
- package/src/patterns/GuidedFlow/contracts.ts +3 -0
- package/src/patterns/GuidedFlow/guidedFlowController.ts +49 -0
- package/src/patterns/MagneticFieldPuzzle/MagneticFieldPuzzle.astro +217 -0
- package/src/patterns/MagneticFieldPuzzle/MagneticFieldPuzzle.css +383 -0
- package/src/patterns/MagneticFieldPuzzle/contracts.ts +81 -0
- package/src/patterns/MagneticFieldPuzzle/magneticFieldPuzzleController.ts +802 -0
- package/src/patterns/MagneticFieldPuzzle/simulation.ts +244 -0
- package/src/patterns/MapViewport/MapViewport.astro +296 -0
- package/src/patterns/MapViewport/MapViewport.css +257 -0
- package/src/patterns/MapViewport/contracts.ts +79 -0
- package/src/patterns/MapViewport/geometry.ts +80 -0
- package/src/patterns/MapViewport/mapViewportController.ts +636 -0
- package/src/patterns/Modal/Modal.astro +64 -0
- package/src/patterns/Modal/Modal.css +87 -0
- package/src/patterns/Modal/ModalClose.astro +37 -0
- package/src/patterns/Modal/ModalOpen.astro +36 -0
- package/src/patterns/Modal/modalController.ts +118 -0
- package/src/patterns/PuzzleGrid/PuzzleGrid.astro +22 -0
- package/src/patterns/PuzzleGrid/PuzzleGrid.css +149 -0
- package/src/patterns/PuzzleGrid/contracts.ts +2 -0
- package/src/patterns/PuzzleGrid/selectionDismissal.ts +27 -0
- package/src/patterns/PuzzleGrid/state.ts +25 -0
- package/src/patterns/SpriteProjectilePreview/SpriteProjectilePreview.astro +65 -0
- package/src/patterns/SpriteProjectilePreview/SpriteProjectilePreview.css +35 -0
- package/src/patterns/SpriteProjectilePreview/contracts.ts +33 -0
- package/src/patterns/SpriteProjectilePreview/spriteProjectilePreviewController.ts +586 -0
- package/src/patterns/StageFlow/StageFlow.astro +57 -0
- package/src/patterns/StageFlow/StageFlow.css +54 -0
- package/src/patterns/StageFlow/StageFlowAlternative.astro +23 -0
- package/src/patterns/StageFlow/StageFlowArrow.astro +22 -0
- package/src/patterns/StageFlow/StageFlowConnector.astro +7 -0
- package/src/patterns/StageFlow/StageFlowConnector.css +4 -0
- package/src/patterns/StageFlow/StageFlowStage.astro +51 -0
- package/src/patterns/StageFlow/StageFlowStage.css +106 -0
- package/src/patterns/StageFlow/StageFlowStep.astro +24 -0
- package/src/patterns/StageFlow/StageFlowStep.css +19 -0
- package/src/patterns/StageFlow/StageFlowSymbol.css +28 -0
- package/src/patterns/Table/Table.astro +176 -0
- package/src/patterns/Table/Table.css +70 -0
- package/src/patterns/Table/TableBody.astro +185 -0
- package/src/patterns/Table/TableBody.css +262 -0
- package/src/patterns/Table/TableCell.astro +59 -0
- package/src/patterns/Table/TableCell.css +99 -0
- package/src/patterns/Table/TableCellValue.astro +86 -0
- package/src/patterns/Table/TableFooter.astro +32 -0
- package/src/patterns/Table/TableFooter.css +31 -0
- package/src/patterns/Table/TableHeader.astro +118 -0
- package/src/patterns/Table/TableHeader.css +209 -0
- package/src/patterns/Table/TablePagination.astro +70 -0
- package/src/patterns/Table/TablePagination.css +133 -0
- package/src/patterns/Table/TableSkeleton.astro +36 -0
- package/src/patterns/Table/TableSkeleton.css +81 -0
- package/src/patterns/Table/tableCellController.ts +11 -0
- package/src/patterns/Table/tableFilterController.ts +206 -0
- package/src/patterns/Table/tableHeaderOverflowController.ts +105 -0
- package/src/patterns/Table/tableLayout.ts +113 -0
- package/src/patterns/Table/tableProgressiveController.ts +319 -0
- package/src/patterns/Table/tableRowNavigationController.ts +91 -0
- package/src/patterns/Table/tableScrollController.ts +192 -0
- package/src/patterns/Table/tableSortController.ts +272 -0
- package/src/patterns/index.ts +46 -0
- package/src/primitives/index.ts +4 -0
- package/src/primitives/layout/Separator/Separator.astro +29 -0
- package/src/primitives/layout/Separator/Separator.css +20 -0
- package/src/primitives/media/AmbientAudio/AmbientAudio.astro +28 -0
- package/src/primitives/media/Media/Media.astro +122 -0
- package/src/primitives/media/Media/Media.css +161 -0
- package/src/primitives/text/TextBlock/TextBlock.astro +46 -0
- package/src/primitives/text/TextBlock/TextBlock.css +21 -0
- package/src/seo/StaticRedirect.astro +32 -0
- package/src/seo/index.ts +6 -0
- package/src/seo/pageSeo.ts +99 -0
- package/src/seo/robots.ts +16 -0
- package/src/seo/sitemap.ts +38 -0
- package/src/seo/structuredData.ts +133 -0
- package/src/seo/url.ts +64 -0
- package/src/styles/base.css +148 -0
- package/src/styles/interaction.css +108 -0
- package/src/styles/style.css +93 -0
- package/src/styles/tokens.css +256 -0
- package/src/theme/contracts.ts +7 -0
- package/src/theme/index.ts +1 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DisplayMedia } from '../../display/contracts';
|
|
2
|
+
import type { AstroComponent } from '../../components/widgetTypes';
|
|
3
|
+
import type { Tone } from '../../theme/contracts';
|
|
4
|
+
|
|
5
|
+
export type ComboboxOption = {
|
|
6
|
+
value: string;
|
|
7
|
+
label: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
icon?: AstroComponent;
|
|
10
|
+
iconTone?: Tone;
|
|
11
|
+
media?: DisplayMedia;
|
|
12
|
+
keywords?: readonly string[];
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type ComboboxMode = 'number' | 'options';
|
|
17
|
+
export type ComboboxSelectionMode = 'multiple' | 'single';
|
|
18
|
+
export type ComboboxSize = 'lg' | 'md' | 'sm';
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
3
|
+
import type { DisplayMedia } from '../../display/contracts';
|
|
4
|
+
import ArrowDownIcon from '../../components/icons/ArrowDownIcon.astro';
|
|
5
|
+
import Media from '../../primitives/media/Media/Media.astro';
|
|
6
|
+
|
|
7
|
+
type DropdownAlignment = 'center' | 'end' | 'start';
|
|
8
|
+
type DropdownPlacement = 'bottom' | 'top';
|
|
9
|
+
type DropdownSize = 'sm' | 'md' | 'lg';
|
|
10
|
+
type DropdownTrigger = 'click' | 'hover';
|
|
11
|
+
type DropdownTriggerAppearance = 'bar' | 'default';
|
|
12
|
+
type DropdownTriggerIndicator = 'chevron-down';
|
|
13
|
+
type DropdownTriggerLabel = 'accessible' | 'visible';
|
|
14
|
+
type DropdownTriggerMediaFrame = 'bordered';
|
|
15
|
+
type DropdownTriggerMediaShape = 'circle' | 'rectangle';
|
|
16
|
+
|
|
17
|
+
type Props = Omit<HTMLAttributes<'div'>, 'id'> & {
|
|
18
|
+
id: string;
|
|
19
|
+
label: string;
|
|
20
|
+
align?: DropdownAlignment;
|
|
21
|
+
attached?: boolean;
|
|
22
|
+
active?: boolean;
|
|
23
|
+
indicator?: DropdownTriggerIndicator;
|
|
24
|
+
maxVisibleItems?: number;
|
|
25
|
+
placement?: DropdownPlacement;
|
|
26
|
+
size?: DropdownSize;
|
|
27
|
+
trigger?: DropdownTrigger;
|
|
28
|
+
triggerAppearance?: DropdownTriggerAppearance;
|
|
29
|
+
triggerLabel?: DropdownTriggerLabel;
|
|
30
|
+
triggerMedia?: DisplayMedia;
|
|
31
|
+
triggerMediaFrame?: DropdownTriggerMediaFrame;
|
|
32
|
+
triggerMediaShape?: DropdownTriggerMediaShape;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const {
|
|
36
|
+
align = 'start',
|
|
37
|
+
attached = false,
|
|
38
|
+
active = false,
|
|
39
|
+
id,
|
|
40
|
+
indicator,
|
|
41
|
+
label,
|
|
42
|
+
maxVisibleItems = 5,
|
|
43
|
+
placement = 'bottom',
|
|
44
|
+
size = 'md',
|
|
45
|
+
trigger: triggerMode = 'click',
|
|
46
|
+
triggerAppearance = 'default',
|
|
47
|
+
triggerLabel = 'visible',
|
|
48
|
+
triggerMedia,
|
|
49
|
+
triggerMediaFrame,
|
|
50
|
+
triggerMediaShape = 'rectangle',
|
|
51
|
+
class: className,
|
|
52
|
+
...attrs
|
|
53
|
+
} = Astro.props;
|
|
54
|
+
const contentId = `${id}-content`;
|
|
55
|
+
const triggerId = `${id}-trigger`;
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
<div
|
|
59
|
+
{...attrs}
|
|
60
|
+
class:list={['dropdown', className]}
|
|
61
|
+
data-dropdown
|
|
62
|
+
data-dropdown-align={align}
|
|
63
|
+
data-dropdown-attached={attached ? true : undefined}
|
|
64
|
+
data-dropdown-placement={placement}
|
|
65
|
+
data-dropdown-size={size}
|
|
66
|
+
data-dropdown-trigger-appearance={triggerAppearance}
|
|
67
|
+
data-dropdown-trigger-mode={triggerMode}
|
|
68
|
+
style={`--dropdown-visible-items: ${maxVisibleItems}`}
|
|
69
|
+
>
|
|
70
|
+
<button
|
|
71
|
+
class="dropdown__trigger"
|
|
72
|
+
id={triggerId}
|
|
73
|
+
type="button"
|
|
74
|
+
aria-controls={contentId}
|
|
75
|
+
aria-expanded="false"
|
|
76
|
+
data-dropdown-trigger
|
|
77
|
+
data-navigation-control={triggerAppearance === 'bar' ? true : undefined}
|
|
78
|
+
data-navigation-control-active={active ? true : undefined}
|
|
79
|
+
data-navigation-control-appearance={triggerAppearance}
|
|
80
|
+
aria-label={triggerLabel === 'accessible' ? label : undefined}
|
|
81
|
+
>
|
|
82
|
+
<span data-navigation-control-content>
|
|
83
|
+
{
|
|
84
|
+
triggerMedia ? (
|
|
85
|
+
<span
|
|
86
|
+
class="dropdown__trigger-media"
|
|
87
|
+
data-navigation-control-media
|
|
88
|
+
data-navigation-control-media-frame={triggerMediaFrame}
|
|
89
|
+
data-navigation-control-media-shape={triggerMediaShape}
|
|
90
|
+
aria-hidden="true"
|
|
91
|
+
>
|
|
92
|
+
<Media media={triggerMedia} fit="cover" size="fill" />
|
|
93
|
+
</span>
|
|
94
|
+
) : null
|
|
95
|
+
}
|
|
96
|
+
<span
|
|
97
|
+
data-navigation-control-label
|
|
98
|
+
data-navigation-control-label-accessible={triggerLabel === 'accessible'
|
|
99
|
+
? true
|
|
100
|
+
: undefined}
|
|
101
|
+
>
|
|
102
|
+
{label}
|
|
103
|
+
</span>
|
|
104
|
+
{
|
|
105
|
+
indicator ? (
|
|
106
|
+
<span data-navigation-control-indicator aria-hidden="true">
|
|
107
|
+
{indicator === 'chevron-down' ? <ArrowDownIcon /> : null}
|
|
108
|
+
</span>
|
|
109
|
+
) : null
|
|
110
|
+
}
|
|
111
|
+
</span>
|
|
112
|
+
</button>
|
|
113
|
+
|
|
114
|
+
<div class="dropdown__content" id={contentId} hidden data-dropdown-content>
|
|
115
|
+
<slot />
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
<script>
|
|
120
|
+
import { initDropdown } from './dropdownController';
|
|
121
|
+
|
|
122
|
+
for (const root of document.querySelectorAll('[data-dropdown]')) {
|
|
123
|
+
if (root instanceof HTMLElement) {
|
|
124
|
+
initDropdown(root);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
</script>
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
.dropdown {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-flex;
|
|
4
|
+
align-items: stretch;
|
|
5
|
+
min-width: 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.dropdown > [data-dropdown-trigger] {
|
|
9
|
+
block-size: 100%;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.dropdown__trigger[data-navigation-control-appearance='default'] {
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
border: var(--nox-border-width) solid var(--nox-border);
|
|
17
|
+
border-radius: var(--nox-radius-md);
|
|
18
|
+
background: var(--nox-surface);
|
|
19
|
+
color: var(--nox-text);
|
|
20
|
+
font: inherit;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.dropdown[data-dropdown-size='sm']
|
|
25
|
+
.dropdown__trigger[data-navigation-control-appearance='default'] {
|
|
26
|
+
min-block-size: 2.25rem;
|
|
27
|
+
padding-inline: var(--nox-space-3);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.dropdown[data-dropdown-size='md']
|
|
31
|
+
.dropdown__trigger[data-navigation-control-appearance='default'] {
|
|
32
|
+
min-block-size: 2.75rem;
|
|
33
|
+
padding-inline: var(--nox-space-4);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.dropdown[data-dropdown-size='lg']
|
|
37
|
+
.dropdown__trigger[data-navigation-control-appearance='default'] {
|
|
38
|
+
min-block-size: 3.25rem;
|
|
39
|
+
padding-inline: var(--nox-space-5);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.dropdown__trigger:focus-visible {
|
|
43
|
+
outline: var(--nox-focus-ring-width) solid var(--nox-focus-ring);
|
|
44
|
+
outline-offset: var(--nox-focus-ring-offset);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.dropdown__content {
|
|
48
|
+
position: absolute;
|
|
49
|
+
z-index: 90;
|
|
50
|
+
display: grid;
|
|
51
|
+
min-width: 11rem;
|
|
52
|
+
max-width: calc(100vw - var(--nox-page-gutter) * 2);
|
|
53
|
+
max-block-size: min(
|
|
54
|
+
calc(100dvh - var(--nox-space-4) * 2),
|
|
55
|
+
calc(var(--dropdown-visible-items, 5) * 2.75rem + var(--nox-space-2) * 2)
|
|
56
|
+
);
|
|
57
|
+
padding: var(--nox-space-2) 0;
|
|
58
|
+
gap: 0;
|
|
59
|
+
border: var(--nox-border-width) solid var(--nox-border);
|
|
60
|
+
border-top: 3px solid var(--nox-link-active);
|
|
61
|
+
border-radius: var(--nox-radius-md);
|
|
62
|
+
background: var(--nox-surface);
|
|
63
|
+
box-shadow: var(--nox-shadow-surface);
|
|
64
|
+
overflow-y: auto;
|
|
65
|
+
overscroll-behavior: contain;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.dropdown__content[hidden] {
|
|
69
|
+
display: none;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.dropdown[data-dropdown-placement='bottom'] .dropdown__content {
|
|
73
|
+
top: 100%;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.dropdown[data-dropdown-attached][data-dropdown-placement='bottom']
|
|
77
|
+
.dropdown__content {
|
|
78
|
+
top: calc(100% + var(--dropdown-attached-block-offset, 0px));
|
|
79
|
+
border-top: 3px solid var(--nox-link-active);
|
|
80
|
+
border-start-start-radius: 0;
|
|
81
|
+
border-start-end-radius: 0;
|
|
82
|
+
box-shadow: none;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.dropdown[data-dropdown-placement='top'] .dropdown__content {
|
|
86
|
+
bottom: calc(100% + var(--nox-space-2));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.dropdown[data-dropdown-align='start'] .dropdown__content {
|
|
90
|
+
left: 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.dropdown[data-dropdown-align='center'] .dropdown__content {
|
|
94
|
+
left: 50%;
|
|
95
|
+
transform: translateX(-50%);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.dropdown[data-dropdown-align='end'] .dropdown__content {
|
|
99
|
+
right: 0;
|
|
100
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { getFocusableElements } from '../../client/focus';
|
|
2
|
+
|
|
3
|
+
type DropdownTriggerMode = 'click' | 'hover';
|
|
4
|
+
|
|
5
|
+
const initializedAttribute = 'data-dropdown-initialized';
|
|
6
|
+
const noop = (): void => undefined;
|
|
7
|
+
|
|
8
|
+
const getTriggerMode = (root: HTMLElement): DropdownTriggerMode =>
|
|
9
|
+
root.dataset.dropdownTriggerMode === 'hover' ? 'hover' : 'click';
|
|
10
|
+
|
|
11
|
+
export function initDropdown(root: HTMLElement): () => void {
|
|
12
|
+
if (root.getAttribute(initializedAttribute) === 'true') {
|
|
13
|
+
return noop;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const trigger = root.querySelector<HTMLElement>('[data-dropdown-trigger]');
|
|
17
|
+
const content = root.querySelector<HTMLElement>('[data-dropdown-content]');
|
|
18
|
+
|
|
19
|
+
if (!trigger || !content) {
|
|
20
|
+
return noop;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
root.setAttribute(initializedAttribute, 'true');
|
|
24
|
+
|
|
25
|
+
const triggerMode = getTriggerMode(root);
|
|
26
|
+
const hoverMedia = window.matchMedia('(hover: hover)');
|
|
27
|
+
let isOpen = !content.hidden;
|
|
28
|
+
|
|
29
|
+
const canOpenOnHover = (): boolean =>
|
|
30
|
+
triggerMode === 'hover' && hoverMedia.matches;
|
|
31
|
+
|
|
32
|
+
const setOpen = (nextOpen: boolean, restoreFocus = false): void => {
|
|
33
|
+
isOpen = nextOpen;
|
|
34
|
+
trigger.setAttribute('aria-expanded', String(isOpen));
|
|
35
|
+
content.hidden = !isOpen;
|
|
36
|
+
root.toggleAttribute('data-dropdown-open', isOpen);
|
|
37
|
+
|
|
38
|
+
if (restoreFocus) {
|
|
39
|
+
trigger.focus();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const openAndFocusFirstItem = (): void => {
|
|
44
|
+
setOpen(true);
|
|
45
|
+
|
|
46
|
+
window.requestAnimationFrame(() => {
|
|
47
|
+
const firstFocusable = getFocusableElements(content)[0];
|
|
48
|
+
|
|
49
|
+
if (firstFocusable) {
|
|
50
|
+
firstFocusable.focus();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const close = (restoreFocus = false): void => {
|
|
56
|
+
if (!isOpen) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
setOpen(false, restoreFocus);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleTriggerClick = (): void => {
|
|
64
|
+
if (canOpenOnHover()) {
|
|
65
|
+
setOpen(true);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
setOpen(!isOpen);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const handleRootPointerEnter = (): void => {
|
|
73
|
+
if (canOpenOnHover()) {
|
|
74
|
+
setOpen(true);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const handleRootPointerLeave = (event: PointerEvent): void => {
|
|
79
|
+
const nextTarget = event.relatedTarget;
|
|
80
|
+
|
|
81
|
+
if (nextTarget instanceof Node && root.contains(nextTarget)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (canOpenOnHover() && !root.contains(document.activeElement)) {
|
|
86
|
+
close();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const handleTriggerFocus = (): void => {
|
|
91
|
+
if (triggerMode === 'hover') {
|
|
92
|
+
setOpen(true);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const handleTriggerKeydown = (event: KeyboardEvent): void => {
|
|
97
|
+
if (event.key === 'ArrowDown') {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
openAndFocusFirstItem();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const handleContentKeydown = (event: KeyboardEvent): void => {
|
|
104
|
+
if (event.key === 'Escape') {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
close(true);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const handleDocumentClick = (event: MouseEvent): void => {
|
|
111
|
+
const target = event.target;
|
|
112
|
+
|
|
113
|
+
if (target instanceof Node && !root.contains(target)) {
|
|
114
|
+
close();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const handleDocumentFocusin = (event: FocusEvent): void => {
|
|
119
|
+
const target = event.target;
|
|
120
|
+
|
|
121
|
+
if (target instanceof Node && !root.contains(target)) {
|
|
122
|
+
close();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const handleDocumentKeydown = (event: KeyboardEvent): void => {
|
|
127
|
+
if (event.key === 'Escape') {
|
|
128
|
+
close(true);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
setOpen(isOpen);
|
|
133
|
+
|
|
134
|
+
trigger.addEventListener('click', handleTriggerClick);
|
|
135
|
+
trigger.addEventListener('focus', handleTriggerFocus);
|
|
136
|
+
trigger.addEventListener('keydown', handleTriggerKeydown);
|
|
137
|
+
content.addEventListener('keydown', handleContentKeydown);
|
|
138
|
+
root.addEventListener('pointerenter', handleRootPointerEnter);
|
|
139
|
+
root.addEventListener('pointerleave', handleRootPointerLeave);
|
|
140
|
+
document.addEventListener('click', handleDocumentClick);
|
|
141
|
+
document.addEventListener('focusin', handleDocumentFocusin);
|
|
142
|
+
document.addEventListener('keydown', handleDocumentKeydown);
|
|
143
|
+
|
|
144
|
+
return () => {
|
|
145
|
+
close();
|
|
146
|
+
trigger.removeEventListener('click', handleTriggerClick);
|
|
147
|
+
trigger.removeEventListener('focus', handleTriggerFocus);
|
|
148
|
+
trigger.removeEventListener('keydown', handleTriggerKeydown);
|
|
149
|
+
content.removeEventListener('keydown', handleContentKeydown);
|
|
150
|
+
root.removeEventListener('pointerenter', handleRootPointerEnter);
|
|
151
|
+
root.removeEventListener('pointerleave', handleRootPointerLeave);
|
|
152
|
+
document.removeEventListener('click', handleDocumentClick);
|
|
153
|
+
document.removeEventListener('focusin', handleDocumentFocusin);
|
|
154
|
+
document.removeEventListener('keydown', handleDocumentKeydown);
|
|
155
|
+
root.removeAttribute(initializedAttribute);
|
|
156
|
+
};
|
|
157
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
3
|
+
import type { Tone } from '../../theme/contracts';
|
|
4
|
+
import Button from '../../components/actions/Button/Button.astro';
|
|
5
|
+
import EnterFullscreenIcon from '../../components/icons/EnterFullscreenIcon.astro';
|
|
6
|
+
import ExitFullscreenIcon from '../../components/icons/ExitFullscreenIcon.astro';
|
|
7
|
+
import ExternalLinkIcon from '../../components/icons/ExternalLinkIcon.astro';
|
|
8
|
+
|
|
9
|
+
type FullscreenControlPlacement = 'inline' | 'overlay';
|
|
10
|
+
type FullscreenOverlayOffset = 'default' | 'native-controls';
|
|
11
|
+
type FullscreenUnsupportedFallback = {
|
|
12
|
+
href: string;
|
|
13
|
+
label: string;
|
|
14
|
+
target?: '_blank' | '_self';
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type Props = Omit<HTMLAttributes<'button'>, 'aria-controls' | 'type'> & {
|
|
18
|
+
enterLabel: string;
|
|
19
|
+
exitLabel: string;
|
|
20
|
+
overlayOffset?: FullscreenOverlayOffset;
|
|
21
|
+
placement?: FullscreenControlPlacement;
|
|
22
|
+
targetId: string;
|
|
23
|
+
tone?: Tone;
|
|
24
|
+
unsupportedFallback?: FullscreenUnsupportedFallback;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
class: className,
|
|
29
|
+
enterLabel,
|
|
30
|
+
exitLabel,
|
|
31
|
+
overlayOffset = 'default',
|
|
32
|
+
placement = 'inline',
|
|
33
|
+
targetId,
|
|
34
|
+
tone,
|
|
35
|
+
unsupportedFallback,
|
|
36
|
+
...attrs
|
|
37
|
+
}: Props = Astro.props;
|
|
38
|
+
const resolvedClass = ['fullscreen-control', className]
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.join(' ');
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
<Button
|
|
44
|
+
{...attrs}
|
|
45
|
+
class={resolvedClass}
|
|
46
|
+
type="button"
|
|
47
|
+
borderless={placement === 'inline'}
|
|
48
|
+
full={placement === 'inline'}
|
|
49
|
+
iconOnly
|
|
50
|
+
size={placement === 'overlay' ? 'md' : undefined}
|
|
51
|
+
tone={tone}
|
|
52
|
+
aria-controls={targetId}
|
|
53
|
+
aria-label={enterLabel}
|
|
54
|
+
aria-pressed="false"
|
|
55
|
+
title={enterLabel}
|
|
56
|
+
data-fullscreen-control
|
|
57
|
+
data-fullscreen-enter-label={enterLabel}
|
|
58
|
+
data-fullscreen-exit-label={exitLabel}
|
|
59
|
+
data-fullscreen-overlay-offset={overlayOffset}
|
|
60
|
+
data-fullscreen-placement={placement}
|
|
61
|
+
data-fullscreen-target={targetId}
|
|
62
|
+
>
|
|
63
|
+
<span class="fullscreen-control__icon" data-fullscreen-enter-icon>
|
|
64
|
+
<EnterFullscreenIcon />
|
|
65
|
+
</span>
|
|
66
|
+
<span class="fullscreen-control__icon" data-fullscreen-exit-icon>
|
|
67
|
+
<ExitFullscreenIcon />
|
|
68
|
+
</span>
|
|
69
|
+
</Button>
|
|
70
|
+
|
|
71
|
+
{
|
|
72
|
+
unsupportedFallback ? (
|
|
73
|
+
<Button
|
|
74
|
+
href={unsupportedFallback.href}
|
|
75
|
+
target={unsupportedFallback.target ?? '_blank'}
|
|
76
|
+
borderless={placement === 'inline'}
|
|
77
|
+
full={placement === 'inline'}
|
|
78
|
+
iconOnly
|
|
79
|
+
size={placement === 'overlay' ? 'md' : undefined}
|
|
80
|
+
tone={tone}
|
|
81
|
+
aria-label={unsupportedFallback.label}
|
|
82
|
+
title={unsupportedFallback.label}
|
|
83
|
+
hidden
|
|
84
|
+
data-fullscreen-unsupported-fallback
|
|
85
|
+
>
|
|
86
|
+
<span class="fullscreen-control__icon">
|
|
87
|
+
<ExternalLinkIcon />
|
|
88
|
+
</span>
|
|
89
|
+
</Button>
|
|
90
|
+
) : null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
<script>
|
|
94
|
+
import { initFullscreenControl } from './fullscreenController';
|
|
95
|
+
|
|
96
|
+
for (const control of document.querySelectorAll(
|
|
97
|
+
'[data-fullscreen-control]',
|
|
98
|
+
)) {
|
|
99
|
+
if (control instanceof HTMLButtonElement) {
|
|
100
|
+
initFullscreenControl(control);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
</script>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
.fullscreen-control__icon {
|
|
2
|
+
display: grid;
|
|
3
|
+
place-items: center;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.fullscreen-control [data-fullscreen-exit-icon] {
|
|
7
|
+
display: none;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.fullscreen-control[aria-pressed='true'] [data-fullscreen-enter-icon] {
|
|
11
|
+
display: none;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.fullscreen-control[aria-pressed='true'] [data-fullscreen-exit-icon] {
|
|
15
|
+
display: grid;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.fullscreen-control[data-fullscreen-placement='overlay'].nox-button {
|
|
19
|
+
position: absolute;
|
|
20
|
+
z-index: 2;
|
|
21
|
+
display: none;
|
|
22
|
+
inset-inline-end: var(--nox-space-3);
|
|
23
|
+
inset-block-end: var(--nox-space-3);
|
|
24
|
+
inline-size: var(--nox-section-responsive-block-size);
|
|
25
|
+
block-size: var(--nox-section-responsive-block-size);
|
|
26
|
+
min-block-size: 0;
|
|
27
|
+
border-radius: var(--nox-radius-md);
|
|
28
|
+
box-shadow: var(--nox-shadow-surface);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
[data-fullscreen-region]:fullscreen
|
|
32
|
+
.fullscreen-control[data-fullscreen-placement='overlay'].nox-button {
|
|
33
|
+
display: inline-flex;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
[data-fullscreen-region]:fullscreen
|
|
37
|
+
.fullscreen-control[data-fullscreen-placement='overlay'][data-fullscreen-overlay-offset='native-controls'].nox-button {
|
|
38
|
+
inset-block-end: calc(
|
|
39
|
+
var(--nox-fullscreen-native-controls-block-size, 2.5rem) +
|
|
40
|
+
var(--nox-space-3)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
[data-fullscreen-region]:fullscreen {
|
|
45
|
+
inline-size: 100vw;
|
|
46
|
+
block-size: 100vh;
|
|
47
|
+
aspect-ratio: auto;
|
|
48
|
+
background: var(--nox-surface);
|
|
49
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const initializedAttribute = 'data-fullscreen-initialized';
|
|
2
|
+
const noop = (): void => undefined;
|
|
3
|
+
|
|
4
|
+
export function initFullscreenControl(
|
|
5
|
+
control: HTMLButtonElement,
|
|
6
|
+
): () => void {
|
|
7
|
+
if (control.getAttribute(initializedAttribute) === 'true') return noop;
|
|
8
|
+
|
|
9
|
+
const targetId = control.dataset.fullscreenTarget;
|
|
10
|
+
const target = targetId ? document.getElementById(targetId) : null;
|
|
11
|
+
const fallbackCandidate = control.nextElementSibling;
|
|
12
|
+
const fallback =
|
|
13
|
+
fallbackCandidate instanceof HTMLAnchorElement &&
|
|
14
|
+
fallbackCandidate.hasAttribute('data-fullscreen-unsupported-fallback')
|
|
15
|
+
? fallbackCandidate
|
|
16
|
+
: null;
|
|
17
|
+
const showUnsupportedFallback = (): void => {
|
|
18
|
+
control.hidden = true;
|
|
19
|
+
if (fallback instanceof HTMLAnchorElement) fallback.hidden = false;
|
|
20
|
+
};
|
|
21
|
+
if (
|
|
22
|
+
document.fullscreenEnabled !== true ||
|
|
23
|
+
!target ||
|
|
24
|
+
typeof target.requestFullscreen !== 'function'
|
|
25
|
+
) {
|
|
26
|
+
showUnsupportedFallback();
|
|
27
|
+
return noop;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
control.hidden = false;
|
|
31
|
+
if (fallback instanceof HTMLAnchorElement) fallback.hidden = true;
|
|
32
|
+
control.setAttribute(initializedAttribute, 'true');
|
|
33
|
+
|
|
34
|
+
const enterLabel = control.dataset.fullscreenEnterLabel ?? '';
|
|
35
|
+
const exitLabel = control.dataset.fullscreenExitLabel ?? '';
|
|
36
|
+
|
|
37
|
+
const sync = (): void => {
|
|
38
|
+
const active = document.fullscreenElement === target;
|
|
39
|
+
const label = active ? exitLabel : enterLabel;
|
|
40
|
+
|
|
41
|
+
control.setAttribute('aria-label', label);
|
|
42
|
+
control.setAttribute('aria-pressed', String(active));
|
|
43
|
+
control.title = label;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const toggle = async (): Promise<void> => {
|
|
47
|
+
try {
|
|
48
|
+
if (document.fullscreenElement === target) {
|
|
49
|
+
await document.exitFullscreen();
|
|
50
|
+
} else {
|
|
51
|
+
await target.requestFullscreen();
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
if (fallback instanceof HTMLAnchorElement) {
|
|
55
|
+
showUnsupportedFallback();
|
|
56
|
+
} else {
|
|
57
|
+
sync();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
control.addEventListener('click', toggle);
|
|
63
|
+
document.addEventListener('fullscreenchange', sync);
|
|
64
|
+
sync();
|
|
65
|
+
|
|
66
|
+
return () => {
|
|
67
|
+
control.removeEventListener('click', toggle);
|
|
68
|
+
document.removeEventListener('fullscreenchange', sync);
|
|
69
|
+
control.removeAttribute(initializedAttribute);
|
|
70
|
+
control.hidden = false;
|
|
71
|
+
if (fallback instanceof HTMLAnchorElement) fallback.hidden = true;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
3
|
+
|
|
4
|
+
type Props = HTMLAttributes<'div'>;
|
|
5
|
+
|
|
6
|
+
const { class: className, ...attrs }: Props = Astro.props;
|
|
7
|
+
const pixels = Array.from({ length: 28 }, (_, index) => ({
|
|
8
|
+
delay: (index * 97) % 1600,
|
|
9
|
+
duration: 1000 + ((index * 149) % 1800),
|
|
10
|
+
height: 2 + ((index * 7) % 9),
|
|
11
|
+
width: 8 + ((index * 11) % 34),
|
|
12
|
+
x: (index * 37 + 9) % 96,
|
|
13
|
+
y: (index * 23 + 7) % 96,
|
|
14
|
+
}));
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<div
|
|
18
|
+
{...attrs}
|
|
19
|
+
class:list={['glitch-overlay', className]}
|
|
20
|
+
aria-hidden="true"
|
|
21
|
+
data-glitch-overlay-root
|
|
22
|
+
data-widget="glitch-overlay"
|
|
23
|
+
>
|
|
24
|
+
<span class="glitch-overlay__scanlines"></span>
|
|
25
|
+
<span class="glitch-overlay__pixels">
|
|
26
|
+
{
|
|
27
|
+
pixels.map((pixel) => (
|
|
28
|
+
<span
|
|
29
|
+
class="glitch-overlay__pixel"
|
|
30
|
+
style={[
|
|
31
|
+
`--glitch-delay: ${pixel.delay}ms`,
|
|
32
|
+
`--glitch-duration: ${pixel.duration}ms`,
|
|
33
|
+
`--glitch-height: ${pixel.height}px`,
|
|
34
|
+
`--glitch-width: ${pixel.width}px`,
|
|
35
|
+
`--glitch-x: ${pixel.x}%`,
|
|
36
|
+
`--glitch-y: ${pixel.y}%`,
|
|
37
|
+
].join(';')}
|
|
38
|
+
/>
|
|
39
|
+
))
|
|
40
|
+
}
|
|
41
|
+
</span>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<script>
|
|
45
|
+
import { initGlitchOverlay } from './glitchOverlayController';
|
|
46
|
+
|
|
47
|
+
for (const root of document.querySelectorAll('[data-glitch-overlay-root]')) {
|
|
48
|
+
if (root instanceof HTMLElement) initGlitchOverlay(root);
|
|
49
|
+
}
|
|
50
|
+
</script>
|