@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,636 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MapViewportCell,
|
|
3
|
+
MapViewportImageLayer,
|
|
4
|
+
MapViewportMarker,
|
|
5
|
+
MapViewportModel,
|
|
6
|
+
MapViewportShape,
|
|
7
|
+
MapViewportSizing,
|
|
8
|
+
} from './contracts';
|
|
9
|
+
import { getMapViewportSceneGeometry } from './geometry';
|
|
10
|
+
|
|
11
|
+
const initializedAttribute = 'data-map-viewport-initialized';
|
|
12
|
+
const dragThreshold = 4;
|
|
13
|
+
const svgNamespace = 'http://www.w3.org/2000/svg';
|
|
14
|
+
const noop = (): void => undefined;
|
|
15
|
+
|
|
16
|
+
export type MapViewportSelectionDetail = {
|
|
17
|
+
cellId: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type MapViewportRenderOptions = {
|
|
21
|
+
revealSelected?: 'center' | 'nearest';
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type DragState = {
|
|
25
|
+
canScrollBlock: boolean;
|
|
26
|
+
canScrollInline: boolean;
|
|
27
|
+
pointerId: number;
|
|
28
|
+
startClientX: number;
|
|
29
|
+
startClientY: number;
|
|
30
|
+
startScrollLeft: number;
|
|
31
|
+
startScrollTop: number;
|
|
32
|
+
moved: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function createSvgElement<K extends keyof SVGElementTagNameMap>(
|
|
36
|
+
name: K,
|
|
37
|
+
): SVGElementTagNameMap[K] {
|
|
38
|
+
return document.createElementNS(svgNamespace, name);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function setAttributes(
|
|
42
|
+
element: Element,
|
|
43
|
+
attributes: Readonly<Record<string, string | number | undefined>>,
|
|
44
|
+
): void {
|
|
45
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
46
|
+
if (value !== undefined) element.setAttribute(name, String(value));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function applySceneGeometry(root: HTMLElement, model: MapViewportModel): void {
|
|
51
|
+
const sizing: MapViewportSizing =
|
|
52
|
+
root.dataset.sizing === 'fill' ? 'fill' : 'aspect';
|
|
53
|
+
const geometry = getMapViewportSceneGeometry(model, sizing);
|
|
54
|
+
const frame = root.closest<HTMLElement>('.map-viewport-frame');
|
|
55
|
+
const modalId = frame?.dataset.modalSource;
|
|
56
|
+
const modalCard = modalId
|
|
57
|
+
? document.querySelector<HTMLElement>(
|
|
58
|
+
`[data-map-viewport-modal-card="${CSS.escape(modalId)}"]`,
|
|
59
|
+
)
|
|
60
|
+
: null;
|
|
61
|
+
|
|
62
|
+
root.dataset.mapLogicalOverflowBlock = String(geometry.overflowsBlock);
|
|
63
|
+
root.dataset.mapLogicalOverflowInline = String(geometry.overflowsInline);
|
|
64
|
+
root.dataset.mapOverflowBlock = String(geometry.overflowsBlock);
|
|
65
|
+
root.dataset.mapOverflowInline = String(geometry.overflowsInline);
|
|
66
|
+
root.dataset.mapReferenceRatio = geometry.referenceRatio;
|
|
67
|
+
|
|
68
|
+
for (const element of [root, frame, modalCard]) {
|
|
69
|
+
if (!element) continue;
|
|
70
|
+
element.style.setProperty(
|
|
71
|
+
'--map-viewport-reference-aspect-ratio',
|
|
72
|
+
geometry.aspectRatio,
|
|
73
|
+
);
|
|
74
|
+
element.style.setProperty(
|
|
75
|
+
'--map-viewport-reference-ratio',
|
|
76
|
+
geometry.referenceRatio,
|
|
77
|
+
);
|
|
78
|
+
element.style.setProperty(
|
|
79
|
+
'--map-viewport-scene-inline-size',
|
|
80
|
+
geometry.inlineSize,
|
|
81
|
+
);
|
|
82
|
+
element.style.setProperty(
|
|
83
|
+
'--map-viewport-scene-block-size',
|
|
84
|
+
geometry.blockSize,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function appendTitle(element: SVGElement, label: string): void {
|
|
90
|
+
const title = createSvgElement('title');
|
|
91
|
+
title.textContent = label;
|
|
92
|
+
element.append(title);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function createLayer(
|
|
96
|
+
layer: MapViewportImageLayer,
|
|
97
|
+
model: MapViewportModel,
|
|
98
|
+
): SVGImageElement {
|
|
99
|
+
const image = createSvgElement('image');
|
|
100
|
+
setAttributes(image, {
|
|
101
|
+
'data-map-layer': layer.id,
|
|
102
|
+
href: layer.media.src,
|
|
103
|
+
x: 0,
|
|
104
|
+
y: 0,
|
|
105
|
+
width: model.width,
|
|
106
|
+
height: model.height,
|
|
107
|
+
preserveAspectRatio: 'none',
|
|
108
|
+
});
|
|
109
|
+
return image;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function createShape(shape: MapViewportShape): SVGGElement {
|
|
113
|
+
const group = createSvgElement('g');
|
|
114
|
+
setAttributes(group, {
|
|
115
|
+
class: 'map-viewport__shape',
|
|
116
|
+
'data-map-shape': shape.kind,
|
|
117
|
+
'data-map-shape-palette': shape.palette,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (shape.kind === 'circle') {
|
|
121
|
+
const circle = createSvgElement('circle');
|
|
122
|
+
setAttributes(circle, { cx: shape.x, cy: shape.y, r: shape.radius });
|
|
123
|
+
group.append(circle);
|
|
124
|
+
} else if (shape.kind === 'ring') {
|
|
125
|
+
const path = createSvgElement('path');
|
|
126
|
+
const data = [
|
|
127
|
+
`M ${shape.x - shape.radius} ${shape.y}`,
|
|
128
|
+
`a ${shape.radius} ${shape.radius} 0 1 0 ${shape.radius * 2} 0`,
|
|
129
|
+
`a ${shape.radius} ${shape.radius} 0 1 0 ${-shape.radius * 2} 0`,
|
|
130
|
+
`M ${shape.x - shape.innerRadius} ${shape.y}`,
|
|
131
|
+
`a ${shape.innerRadius} ${shape.innerRadius} 0 1 1 ${shape.innerRadius * 2} 0`,
|
|
132
|
+
`a ${shape.innerRadius} ${shape.innerRadius} 0 1 1 ${-shape.innerRadius * 2} 0`,
|
|
133
|
+
].join(' ');
|
|
134
|
+
setAttributes(path, { d: data, 'fill-rule': 'evenodd' });
|
|
135
|
+
group.append(path);
|
|
136
|
+
} else if (shape.kind === 'polygon') {
|
|
137
|
+
const polygon = createSvgElement('polygon');
|
|
138
|
+
setAttributes(polygon, {
|
|
139
|
+
points: shape.points.map((point) => `${point.x},${point.y}`).join(' '),
|
|
140
|
+
});
|
|
141
|
+
group.append(polygon);
|
|
142
|
+
} else if (shape.kind === 'diagonal-cross') {
|
|
143
|
+
const rotated = createSvgElement('g');
|
|
144
|
+
const vertical = createSvgElement('rect');
|
|
145
|
+
const horizontal = createSvgElement('rect');
|
|
146
|
+
setAttributes(rotated, {
|
|
147
|
+
transform: `rotate(45 ${shape.x} ${shape.y})`,
|
|
148
|
+
});
|
|
149
|
+
setAttributes(vertical, {
|
|
150
|
+
x: shape.x - shape.halfWidth,
|
|
151
|
+
y: shape.y - shape.radius,
|
|
152
|
+
width: shape.halfWidth * 2,
|
|
153
|
+
height: shape.radius * 2,
|
|
154
|
+
});
|
|
155
|
+
setAttributes(horizontal, {
|
|
156
|
+
x: shape.x - shape.radius,
|
|
157
|
+
y: shape.y - shape.halfWidth,
|
|
158
|
+
width: shape.radius * 2,
|
|
159
|
+
height: shape.halfWidth * 2,
|
|
160
|
+
});
|
|
161
|
+
rotated.append(vertical, horizontal);
|
|
162
|
+
group.append(rotated);
|
|
163
|
+
} else {
|
|
164
|
+
if (shape.kind === 'horizontal-line' || shape.kind === 'cross') {
|
|
165
|
+
const horizontal = createSvgElement('rect');
|
|
166
|
+
setAttributes(horizontal, {
|
|
167
|
+
x: shape.x - shape.radius,
|
|
168
|
+
y: shape.y - shape.halfWidth,
|
|
169
|
+
width: shape.radius * 2,
|
|
170
|
+
height: shape.halfWidth * 2,
|
|
171
|
+
});
|
|
172
|
+
group.append(horizontal);
|
|
173
|
+
}
|
|
174
|
+
if (shape.kind === 'vertical-line' || shape.kind === 'cross') {
|
|
175
|
+
const vertical = createSvgElement('rect');
|
|
176
|
+
setAttributes(vertical, {
|
|
177
|
+
x: shape.x - shape.halfWidth,
|
|
178
|
+
y: shape.y - shape.radius,
|
|
179
|
+
width: shape.halfWidth * 2,
|
|
180
|
+
height: shape.radius * 2,
|
|
181
|
+
});
|
|
182
|
+
group.append(vertical);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return group;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function createCell(
|
|
190
|
+
cell: MapViewportCell,
|
|
191
|
+
interaction: MapViewportModel['interaction'],
|
|
192
|
+
): SVGGElement {
|
|
193
|
+
const group = createSvgElement('g');
|
|
194
|
+
const interactive =
|
|
195
|
+
interaction === 'single-selection' &&
|
|
196
|
+
(cell.state === 'available' || cell.state === 'selected');
|
|
197
|
+
setAttributes(group, {
|
|
198
|
+
class: 'map-viewport__cell',
|
|
199
|
+
'data-map-cell': cell.id,
|
|
200
|
+
'data-map-cell-state': cell.state,
|
|
201
|
+
'data-map-cell-palette': cell.palette,
|
|
202
|
+
role: interactive ? 'button' : undefined,
|
|
203
|
+
tabindex: interactive ? 0 : undefined,
|
|
204
|
+
'aria-label': interactive ? cell.label : undefined,
|
|
205
|
+
'aria-pressed': interactive
|
|
206
|
+
? cell.state === 'selected'
|
|
207
|
+
? 'true'
|
|
208
|
+
: 'false'
|
|
209
|
+
: undefined,
|
|
210
|
+
});
|
|
211
|
+
appendTitle(group, cell.label);
|
|
212
|
+
const rect = createSvgElement('rect');
|
|
213
|
+
setAttributes(rect, {
|
|
214
|
+
x: cell.x,
|
|
215
|
+
y: cell.y,
|
|
216
|
+
width: cell.width,
|
|
217
|
+
height: cell.height,
|
|
218
|
+
});
|
|
219
|
+
group.append(rect);
|
|
220
|
+
return group;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function createMarker(marker: MapViewportMarker): SVGGElement {
|
|
224
|
+
const group = createSvgElement('g');
|
|
225
|
+
setAttributes(group, {
|
|
226
|
+
class: 'map-viewport__marker',
|
|
227
|
+
'data-map-marker': marker.id,
|
|
228
|
+
});
|
|
229
|
+
appendTitle(group, marker.label);
|
|
230
|
+
const image = createSvgElement('image');
|
|
231
|
+
setAttributes(image, {
|
|
232
|
+
href: marker.media.src,
|
|
233
|
+
x: marker.x,
|
|
234
|
+
y: marker.y,
|
|
235
|
+
width: marker.width,
|
|
236
|
+
height: marker.height,
|
|
237
|
+
preserveAspectRatio: 'xMidYMid meet',
|
|
238
|
+
});
|
|
239
|
+
group.append(image);
|
|
240
|
+
return group;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function refreshOverflowState(root: HTMLElement): void {
|
|
244
|
+
const logicalInline = root.dataset.mapLogicalOverflowInline === 'true';
|
|
245
|
+
const logicalBlock = root.dataset.mapLogicalOverflowBlock === 'true';
|
|
246
|
+
let canScrollInline = logicalInline;
|
|
247
|
+
let canScrollBlock = logicalBlock;
|
|
248
|
+
|
|
249
|
+
if (root.dataset.sizing === 'fill' && !logicalInline && !logicalBlock) {
|
|
250
|
+
const bounds = root.getBoundingClientRect();
|
|
251
|
+
const styles = window.getComputedStyle(root);
|
|
252
|
+
const inlineSize =
|
|
253
|
+
bounds.width -
|
|
254
|
+
parseCssLength(styles.borderInlineStartWidth) -
|
|
255
|
+
parseCssLength(styles.borderInlineEndWidth);
|
|
256
|
+
const blockSize =
|
|
257
|
+
bounds.height -
|
|
258
|
+
parseCssLength(styles.borderBlockStartWidth) -
|
|
259
|
+
parseCssLength(styles.borderBlockEndWidth);
|
|
260
|
+
const referenceRatio = Number(root.dataset.mapReferenceRatio);
|
|
261
|
+
|
|
262
|
+
if (
|
|
263
|
+
inlineSize > 0 &&
|
|
264
|
+
blockSize > 0 &&
|
|
265
|
+
Number.isFinite(referenceRatio) &&
|
|
266
|
+
referenceRatio > 0
|
|
267
|
+
) {
|
|
268
|
+
const referenceBlockSize = inlineSize / referenceRatio;
|
|
269
|
+
canScrollInline = blockSize > referenceBlockSize + 1;
|
|
270
|
+
canScrollBlock = referenceBlockSize > blockSize + 1;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
root.dataset.mapOverflowInline = String(canScrollInline);
|
|
275
|
+
root.dataset.mapOverflowBlock = String(canScrollBlock);
|
|
276
|
+
const maxScrollLeft = Math.max(0, root.scrollWidth - root.clientWidth);
|
|
277
|
+
const maxScrollTop = Math.max(0, root.scrollHeight - root.clientHeight);
|
|
278
|
+
|
|
279
|
+
root.scrollLeft = canScrollInline
|
|
280
|
+
? Math.max(0, Math.min(root.scrollLeft, maxScrollLeft))
|
|
281
|
+
: 0;
|
|
282
|
+
root.scrollTop = canScrollBlock
|
|
283
|
+
? Math.max(0, Math.min(root.scrollTop, maxScrollTop))
|
|
284
|
+
: 0;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function parseCssLength(value: string): number {
|
|
288
|
+
const parsed = Number.parseFloat(value);
|
|
289
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function scheduleSelectedCellReveal(
|
|
293
|
+
root: HTMLElement,
|
|
294
|
+
mode: 'center' | 'nearest',
|
|
295
|
+
): number {
|
|
296
|
+
return window.requestAnimationFrame(() => {
|
|
297
|
+
refreshOverflowState(root);
|
|
298
|
+
const svg = root.querySelector<SVGSVGElement>('[data-map-viewport-svg]');
|
|
299
|
+
const selectedRect = svg?.querySelector<SVGRectElement>(
|
|
300
|
+
'[data-map-cell-state="selected"] rect',
|
|
301
|
+
);
|
|
302
|
+
const viewBox = svg?.viewBox.baseVal;
|
|
303
|
+
if (
|
|
304
|
+
!svg ||
|
|
305
|
+
!selectedRect ||
|
|
306
|
+
!viewBox ||
|
|
307
|
+
viewBox.width <= 0 ||
|
|
308
|
+
viewBox.height <= 0
|
|
309
|
+
) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const scaleX = svg.clientWidth / viewBox.width;
|
|
314
|
+
const scaleY = svg.clientHeight / viewBox.height;
|
|
315
|
+
const rootBounds = root.getBoundingClientRect();
|
|
316
|
+
const svgBounds = svg.getBoundingClientRect();
|
|
317
|
+
const sceneLeft =
|
|
318
|
+
svgBounds.left - rootBounds.left - root.clientLeft + root.scrollLeft;
|
|
319
|
+
const sceneTop =
|
|
320
|
+
svgBounds.top - rootBounds.top - root.clientTop + root.scrollTop;
|
|
321
|
+
const left = sceneLeft + selectedRect.x.baseVal.value * scaleX;
|
|
322
|
+
const top = sceneTop + selectedRect.y.baseVal.value * scaleY;
|
|
323
|
+
const right = left + selectedRect.width.baseVal.value * scaleX;
|
|
324
|
+
const bottom = top + selectedRect.height.baseVal.value * scaleY;
|
|
325
|
+
const canScrollInline = root.dataset.mapOverflowInline === 'true';
|
|
326
|
+
const canScrollBlock = root.dataset.mapOverflowBlock === 'true';
|
|
327
|
+
|
|
328
|
+
if (mode === 'center') {
|
|
329
|
+
root.scrollLeft = canScrollInline
|
|
330
|
+
? (left + right - root.clientWidth) / 2
|
|
331
|
+
: 0;
|
|
332
|
+
root.scrollTop = canScrollBlock
|
|
333
|
+
? (top + bottom - root.clientHeight) / 2
|
|
334
|
+
: 0;
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (canScrollInline) {
|
|
339
|
+
if (left < root.scrollLeft) {
|
|
340
|
+
root.scrollLeft = left;
|
|
341
|
+
} else if (right > root.scrollLeft + root.clientWidth) {
|
|
342
|
+
root.scrollLeft = right - root.clientWidth;
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
root.scrollLeft = 0;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (canScrollBlock) {
|
|
349
|
+
if (top < root.scrollTop) {
|
|
350
|
+
root.scrollTop = top;
|
|
351
|
+
} else if (bottom > root.scrollTop + root.clientHeight) {
|
|
352
|
+
root.scrollTop = bottom - root.clientHeight;
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
root.scrollTop = 0;
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export function renderMapViewport(
|
|
361
|
+
root: HTMLElement,
|
|
362
|
+
model: MapViewportModel,
|
|
363
|
+
options: MapViewportRenderOptions = {},
|
|
364
|
+
): void {
|
|
365
|
+
const svg = root.querySelector<SVGSVGElement>('[data-map-viewport-svg]');
|
|
366
|
+
if (!svg) return;
|
|
367
|
+
|
|
368
|
+
const focusedCellId =
|
|
369
|
+
document.activeElement instanceof Element
|
|
370
|
+
? document.activeElement
|
|
371
|
+
.closest<SVGElement>('[data-map-cell]')
|
|
372
|
+
?.getAttribute('data-map-cell')
|
|
373
|
+
: null;
|
|
374
|
+
applySceneGeometry(root, model);
|
|
375
|
+
root.dataset.mapInteraction = model.interaction;
|
|
376
|
+
root.setAttribute('aria-label', model.label);
|
|
377
|
+
setAttributes(svg, {
|
|
378
|
+
viewBox: `0 0 ${model.width} ${model.height}`,
|
|
379
|
+
'aria-label': model.label,
|
|
380
|
+
role: model.interaction === 'none' ? 'img' : 'group',
|
|
381
|
+
});
|
|
382
|
+
svg.replaceChildren();
|
|
383
|
+
|
|
384
|
+
const background = model.layers
|
|
385
|
+
.filter((layer) => layer.plane === 'background')
|
|
386
|
+
.toSorted((left, right) => left.order - right.order)
|
|
387
|
+
.map((layer) => createLayer(layer, model));
|
|
388
|
+
const shapes = createSvgElement('g');
|
|
389
|
+
setAttributes(shapes, {
|
|
390
|
+
class: 'map-viewport__shapes',
|
|
391
|
+
'data-map-shapes': '',
|
|
392
|
+
'aria-hidden': 'true',
|
|
393
|
+
});
|
|
394
|
+
shapes.append(...(model.shapes ?? []).map(createShape));
|
|
395
|
+
const cells = createSvgElement('g');
|
|
396
|
+
setAttributes(cells, {
|
|
397
|
+
class: 'map-viewport__cells',
|
|
398
|
+
'data-map-cells': '',
|
|
399
|
+
});
|
|
400
|
+
cells.append(
|
|
401
|
+
...model.cells.map((cell) => createCell(cell, model.interaction)),
|
|
402
|
+
);
|
|
403
|
+
const markers = createSvgElement('g');
|
|
404
|
+
setAttributes(markers, {
|
|
405
|
+
class: 'map-viewport__markers',
|
|
406
|
+
'data-map-markers': '',
|
|
407
|
+
});
|
|
408
|
+
markers.append(...(model.markers ?? []).map(createMarker));
|
|
409
|
+
const foreground = model.layers
|
|
410
|
+
.filter((layer) => layer.plane === 'foreground')
|
|
411
|
+
.toSorted((left, right) => left.order - right.order)
|
|
412
|
+
.map((layer) => {
|
|
413
|
+
const image = createLayer(layer, model);
|
|
414
|
+
image.setAttribute('pointer-events', 'none');
|
|
415
|
+
return image;
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
svg.append(...background, cells, shapes, markers, ...foreground);
|
|
419
|
+
|
|
420
|
+
if (focusedCellId) {
|
|
421
|
+
svg
|
|
422
|
+
.querySelector<SVGElement>(
|
|
423
|
+
`[data-map-cell="${CSS.escape(focusedCellId)}"]`,
|
|
424
|
+
)
|
|
425
|
+
?.focus();
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
scheduleSelectedCellReveal(root, options.revealSelected ?? 'nearest');
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export function initMapViewport(root: HTMLElement): () => void {
|
|
432
|
+
if (root.getAttribute(initializedAttribute) === 'true') return noop;
|
|
433
|
+
|
|
434
|
+
const svg = root.querySelector<SVGSVGElement>('[data-map-viewport-svg]');
|
|
435
|
+
const scene = root.querySelector<HTMLElement>('[data-map-viewport-scene]');
|
|
436
|
+
const frame = root.closest<HTMLElement>('.map-viewport-frame');
|
|
437
|
+
if (!svg || !scene) return noop;
|
|
438
|
+
root.setAttribute(initializedAttribute, 'true');
|
|
439
|
+
let dragState: DragState | null = null;
|
|
440
|
+
let suppressClick = false;
|
|
441
|
+
let suppressClickTimeout: number | undefined;
|
|
442
|
+
let layoutFrame: number | null = null;
|
|
443
|
+
let revealFrame: number | null = scheduleSelectedCellReveal(root, 'center');
|
|
444
|
+
|
|
445
|
+
const scheduleLayoutRefresh = (): void => {
|
|
446
|
+
if (layoutFrame !== null) return;
|
|
447
|
+
layoutFrame = window.requestAnimationFrame(() => {
|
|
448
|
+
layoutFrame = null;
|
|
449
|
+
refreshOverflowState(root);
|
|
450
|
+
});
|
|
451
|
+
};
|
|
452
|
+
const revealSelection = (mode: 'center' | 'nearest'): void => {
|
|
453
|
+
if (revealFrame !== null) window.cancelAnimationFrame(revealFrame);
|
|
454
|
+
revealFrame = scheduleSelectedCellReveal(root, mode);
|
|
455
|
+
};
|
|
456
|
+
const handleModalLayoutChange = (): void => {
|
|
457
|
+
scheduleLayoutRefresh();
|
|
458
|
+
revealSelection('nearest');
|
|
459
|
+
};
|
|
460
|
+
const resizeObserver =
|
|
461
|
+
'ResizeObserver' in window
|
|
462
|
+
? new ResizeObserver(scheduleLayoutRefresh)
|
|
463
|
+
: null;
|
|
464
|
+
const handleWindowResize = (): void => scheduleLayoutRefresh();
|
|
465
|
+
|
|
466
|
+
if (resizeObserver) {
|
|
467
|
+
resizeObserver.observe(root);
|
|
468
|
+
resizeObserver.observe(scene);
|
|
469
|
+
} else {
|
|
470
|
+
window.addEventListener('resize', handleWindowResize);
|
|
471
|
+
}
|
|
472
|
+
frame?.addEventListener('modal:open', handleModalLayoutChange);
|
|
473
|
+
frame?.addEventListener('modal:restore', handleModalLayoutChange);
|
|
474
|
+
scheduleLayoutRefresh();
|
|
475
|
+
|
|
476
|
+
const select = (cell: SVGGElement): void => {
|
|
477
|
+
if (
|
|
478
|
+
root.dataset.mapInteraction !== 'single-selection' ||
|
|
479
|
+
cell.dataset.mapCellState !== 'available'
|
|
480
|
+
) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const announcement = root.querySelector<HTMLElement>(
|
|
485
|
+
'[data-map-announcement]',
|
|
486
|
+
);
|
|
487
|
+
if (announcement) {
|
|
488
|
+
announcement.textContent = cell.getAttribute('aria-label') ?? '';
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
root.dispatchEvent(
|
|
492
|
+
new CustomEvent<MapViewportSelectionDetail>('mapviewport:select', {
|
|
493
|
+
bubbles: true,
|
|
494
|
+
detail: { cellId: cell.dataset.mapCell ?? '' },
|
|
495
|
+
}),
|
|
496
|
+
);
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
const getCell = (target: EventTarget | null): SVGGElement | null =>
|
|
500
|
+
target instanceof Element
|
|
501
|
+
? target.closest<SVGGElement>('[data-map-cell]')
|
|
502
|
+
: null;
|
|
503
|
+
|
|
504
|
+
const handleClick = (event: MouseEvent): void => {
|
|
505
|
+
const cell = getCell(event.target);
|
|
506
|
+
if (cell && root.contains(cell)) select(cell);
|
|
507
|
+
};
|
|
508
|
+
const handleClickCapture = (event: MouseEvent): void => {
|
|
509
|
+
if (!suppressClick) return;
|
|
510
|
+
suppressClick = false;
|
|
511
|
+
event.preventDefault();
|
|
512
|
+
event.stopImmediatePropagation();
|
|
513
|
+
};
|
|
514
|
+
const handleMouseDown = (event: MouseEvent): void => {
|
|
515
|
+
const cell = getCell(event.target);
|
|
516
|
+
if (cell?.getAttribute('role') === 'button' && root.contains(cell)) {
|
|
517
|
+
event.preventDefault();
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
const handleKeydown = (event: KeyboardEvent): void => {
|
|
521
|
+
if (event.key !== 'Enter' && event.key !== ' ') return;
|
|
522
|
+
const cell = getCell(event.target);
|
|
523
|
+
if (!cell || !root.contains(cell)) return;
|
|
524
|
+
event.preventDefault();
|
|
525
|
+
select(cell);
|
|
526
|
+
};
|
|
527
|
+
const handlePointerDown = (event: PointerEvent): void => {
|
|
528
|
+
const canScrollInline =
|
|
529
|
+
root.dataset.mapOverflowInline === 'true' &&
|
|
530
|
+
root.scrollWidth > root.clientWidth;
|
|
531
|
+
const canScrollBlock =
|
|
532
|
+
root.dataset.mapOverflowBlock === 'true' &&
|
|
533
|
+
root.scrollHeight > root.clientHeight;
|
|
534
|
+
|
|
535
|
+
if (
|
|
536
|
+
event.pointerType !== 'mouse' ||
|
|
537
|
+
event.button !== 0 ||
|
|
538
|
+
event.isPrimary === false ||
|
|
539
|
+
(!canScrollInline && !canScrollBlock)
|
|
540
|
+
) {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
const bounds = root.getBoundingClientRect();
|
|
545
|
+
const overVerticalScrollbar =
|
|
546
|
+
event.clientX - bounds.left >= root.clientWidth;
|
|
547
|
+
const overHorizontalScrollbar =
|
|
548
|
+
event.clientY - bounds.top >= root.clientHeight;
|
|
549
|
+
if (overVerticalScrollbar || overHorizontalScrollbar) return;
|
|
550
|
+
|
|
551
|
+
dragState = {
|
|
552
|
+
canScrollBlock,
|
|
553
|
+
canScrollInline,
|
|
554
|
+
pointerId: event.pointerId,
|
|
555
|
+
startClientX: event.clientX,
|
|
556
|
+
startClientY: event.clientY,
|
|
557
|
+
startScrollLeft: root.scrollLeft,
|
|
558
|
+
startScrollTop: root.scrollTop,
|
|
559
|
+
moved: false,
|
|
560
|
+
};
|
|
561
|
+
};
|
|
562
|
+
const handlePointerMove = (event: PointerEvent): void => {
|
|
563
|
+
if (dragState?.pointerId !== event.pointerId) return;
|
|
564
|
+
|
|
565
|
+
const deltaX = event.clientX - dragState.startClientX;
|
|
566
|
+
const deltaY = event.clientY - dragState.startClientY;
|
|
567
|
+
if (!dragState.moved && Math.hypot(deltaX, deltaY) < dragThreshold) {
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
dragState.moved = true;
|
|
572
|
+
if (!root.hasPointerCapture(event.pointerId)) {
|
|
573
|
+
root.setPointerCapture(event.pointerId);
|
|
574
|
+
}
|
|
575
|
+
root.dataset.mapViewportDragging = 'true';
|
|
576
|
+
if (dragState.canScrollInline) {
|
|
577
|
+
root.scrollLeft = dragState.startScrollLeft - deltaX;
|
|
578
|
+
}
|
|
579
|
+
if (dragState.canScrollBlock) {
|
|
580
|
+
root.scrollTop = dragState.startScrollTop - deltaY;
|
|
581
|
+
}
|
|
582
|
+
event.preventDefault();
|
|
583
|
+
};
|
|
584
|
+
const finishDrag = (event: PointerEvent, canceled = false): void => {
|
|
585
|
+
if (dragState?.pointerId !== event.pointerId) return;
|
|
586
|
+
|
|
587
|
+
const moved = dragState.moved;
|
|
588
|
+
dragState = null;
|
|
589
|
+
delete root.dataset.mapViewportDragging;
|
|
590
|
+
if (root.hasPointerCapture(event.pointerId)) {
|
|
591
|
+
root.releasePointerCapture(event.pointerId);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (!moved || canceled) return;
|
|
595
|
+
suppressClick = true;
|
|
596
|
+
window.clearTimeout(suppressClickTimeout);
|
|
597
|
+
suppressClickTimeout = window.setTimeout(() => {
|
|
598
|
+
suppressClick = false;
|
|
599
|
+
}, 0);
|
|
600
|
+
};
|
|
601
|
+
const handlePointerUp = (event: PointerEvent): void => {
|
|
602
|
+
finishDrag(event);
|
|
603
|
+
};
|
|
604
|
+
const handlePointerCancel = (event: PointerEvent): void => {
|
|
605
|
+
finishDrag(event, true);
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
root.addEventListener('click', handleClickCapture, true);
|
|
609
|
+
root.addEventListener('pointerdown', handlePointerDown);
|
|
610
|
+
root.addEventListener('pointermove', handlePointerMove);
|
|
611
|
+
root.addEventListener('pointerup', handlePointerUp);
|
|
612
|
+
root.addEventListener('pointercancel', handlePointerCancel);
|
|
613
|
+
svg.addEventListener('mousedown', handleMouseDown);
|
|
614
|
+
svg.addEventListener('click', handleClick);
|
|
615
|
+
svg.addEventListener('keydown', handleKeydown);
|
|
616
|
+
|
|
617
|
+
return () => {
|
|
618
|
+
if (layoutFrame !== null) window.cancelAnimationFrame(layoutFrame);
|
|
619
|
+
if (revealFrame !== null) window.cancelAnimationFrame(revealFrame);
|
|
620
|
+
window.clearTimeout(suppressClickTimeout);
|
|
621
|
+
resizeObserver?.disconnect();
|
|
622
|
+
window.removeEventListener('resize', handleWindowResize);
|
|
623
|
+
frame?.removeEventListener('modal:open', handleModalLayoutChange);
|
|
624
|
+
frame?.removeEventListener('modal:restore', handleModalLayoutChange);
|
|
625
|
+
root.removeEventListener('click', handleClickCapture, true);
|
|
626
|
+
root.removeEventListener('pointerdown', handlePointerDown);
|
|
627
|
+
root.removeEventListener('pointermove', handlePointerMove);
|
|
628
|
+
root.removeEventListener('pointerup', handlePointerUp);
|
|
629
|
+
root.removeEventListener('pointercancel', handlePointerCancel);
|
|
630
|
+
svg.removeEventListener('mousedown', handleMouseDown);
|
|
631
|
+
svg.removeEventListener('click', handleClick);
|
|
632
|
+
svg.removeEventListener('keydown', handleKeydown);
|
|
633
|
+
delete root.dataset.mapViewportDragging;
|
|
634
|
+
root.removeAttribute(initializedAttribute);
|
|
635
|
+
};
|
|
636
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
3
|
+
import type { Tone } from '../../theme/contracts';
|
|
4
|
+
import ModalClose from './ModalClose.astro';
|
|
5
|
+
|
|
6
|
+
type ModalCloseControl = 'default' | 'delegated';
|
|
7
|
+
type ModalSizing = 'content' | 'viewport';
|
|
8
|
+
|
|
9
|
+
type Props = HTMLAttributes<'dialog'> & {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
closeLabel: string;
|
|
13
|
+
closeControl?: ModalCloseControl;
|
|
14
|
+
sizing?: ModalSizing;
|
|
15
|
+
tone?: Tone;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
class: className,
|
|
20
|
+
'data-tone': dataTone,
|
|
21
|
+
id,
|
|
22
|
+
label,
|
|
23
|
+
closeLabel,
|
|
24
|
+
closeControl = 'default',
|
|
25
|
+
sizing = 'viewport',
|
|
26
|
+
tone,
|
|
27
|
+
...attrs
|
|
28
|
+
}: Props = Astro.props;
|
|
29
|
+
const resolvedTone = tone ?? dataTone;
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
<dialog
|
|
33
|
+
{...attrs}
|
|
34
|
+
class:list={['modal', className]}
|
|
35
|
+
id={id}
|
|
36
|
+
data-pattern="modal"
|
|
37
|
+
data-modal
|
|
38
|
+
data-sizing={sizing}
|
|
39
|
+
data-tone={resolvedTone}
|
|
40
|
+
aria-label={label}
|
|
41
|
+
aria-modal="true"
|
|
42
|
+
tabindex="-1"
|
|
43
|
+
>
|
|
44
|
+
<div class="modal__content" data-modal-content>
|
|
45
|
+
{
|
|
46
|
+
closeControl === 'default' ? (
|
|
47
|
+
<div class="modal__default-close">
|
|
48
|
+
<ModalClose label={closeLabel} />
|
|
49
|
+
</div>
|
|
50
|
+
) : null
|
|
51
|
+
}
|
|
52
|
+
<slot />
|
|
53
|
+
</div>
|
|
54
|
+
</dialog>
|
|
55
|
+
|
|
56
|
+
<script>
|
|
57
|
+
import { initModal } from './modalController';
|
|
58
|
+
|
|
59
|
+
for (const root of document.querySelectorAll('[data-modal]')) {
|
|
60
|
+
if (root instanceof HTMLDialogElement) {
|
|
61
|
+
initModal(root);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
</script>
|