@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.
Files changed (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -0
  3. package/package.json +77 -0
  4. package/src/client/clipboard.ts +7 -0
  5. package/src/client/focus.ts +17 -0
  6. package/src/client/index.ts +3 -0
  7. package/src/client/scroll.ts +15 -0
  8. package/src/components/actions/ActionListItem/ActionListItem.astro +78 -0
  9. package/src/components/actions/ActionListItem/ActionListItem.css +43 -0
  10. package/src/components/actions/Button/Button.astro +100 -0
  11. package/src/components/actions/Button/Button.css +165 -0
  12. package/src/components/actions/CardAction/CardAction.astro +97 -0
  13. package/src/components/actions/CardAction/CardAction.css +188 -0
  14. package/src/components/actions/MediaTrigger/MediaTrigger.astro +55 -0
  15. package/src/components/actions/MediaTrigger/MediaTrigger.css +175 -0
  16. package/src/components/actions/ScrollToTop/ScrollToTop.astro +36 -0
  17. package/src/components/actions/ScrollToTop/ScrollToTop.css +19 -0
  18. package/src/components/actions/ScrollToTop/scrollToTopController.ts +32 -0
  19. package/src/components/content/CardBody/CardBody.astro +31 -0
  20. package/src/components/content/CardBody/CardBody.css +74 -0
  21. package/src/components/content/CardFooter/CardFooter.astro +58 -0
  22. package/src/components/content/CardFooter/CardFooter.css +102 -0
  23. package/src/components/content/CardHeader/CardHeader.astro +96 -0
  24. package/src/components/content/CardHeader/CardHeader.css +164 -0
  25. package/src/components/content/CardLink/CardLink.astro +138 -0
  26. package/src/components/content/CardLink/CardLink.css +362 -0
  27. package/src/components/content/CodeBlock/CodeBlock.astro +102 -0
  28. package/src/components/content/CodeBlock/CodeBlock.css +85 -0
  29. package/src/components/content/CodeBlock/codeBlockController.ts +60 -0
  30. package/src/components/content/CodeBlock/contracts.ts +8 -0
  31. package/src/components/content/InlineDefinition/InlineDefinition.astro +31 -0
  32. package/src/components/content/InlineDefinition/InlineDefinition.css +9 -0
  33. package/src/components/content/MarkdownContent/MarkdownContent.astro +32 -0
  34. package/src/components/content/MarkdownContent/MarkdownContent.css +358 -0
  35. package/src/components/content/MarkdownContent/MarkdownInline.astro +44 -0
  36. package/src/components/content/MarkdownContent/MarkdownNode.astro +280 -0
  37. package/src/components/content/MarkdownContent/MarkdownSymbol.astro +47 -0
  38. package/src/components/content/MarkdownContent/contracts.ts +181 -0
  39. package/src/components/data-display/BadgeList/BadgeList.astro +54 -0
  40. package/src/components/data-display/BadgeList/BadgeList.css +29 -0
  41. package/src/components/data-display/IconList/IconList.astro +64 -0
  42. package/src/components/data-display/IconList/IconList.css +55 -0
  43. package/src/components/data-display/MetricTile/MetricTile.astro +68 -0
  44. package/src/components/data-display/MetricTile/MetricTile.css +103 -0
  45. package/src/components/data-display/MetricTile/MetricTileContent.astro +70 -0
  46. package/src/components/data-display/MetricTile/metricTileController.ts +9 -0
  47. package/src/components/data-display/Tag/Tag.astro +67 -0
  48. package/src/components/data-display/Tag/Tag.css +134 -0
  49. package/src/components/data-display/Tag/TagAffix.astro +33 -0
  50. package/src/components/data-display/TextPair/TextPair.astro +63 -0
  51. package/src/components/data-display/TextPair/TextPair.css +99 -0
  52. package/src/components/feedback/Spinner/Spinner.astro +32 -0
  53. package/src/components/feedback/Spinner/Spinner.css +37 -0
  54. package/src/components/feedback/Tooltip/Tooltip.astro +66 -0
  55. package/src/components/feedback/Tooltip/Tooltip.css +67 -0
  56. package/src/components/feedback/Tooltip/tooltipController.ts +371 -0
  57. package/src/components/forms/FieldError/FieldError.astro +31 -0
  58. package/src/components/forms/FieldError/FieldError.css +12 -0
  59. package/src/components/forms/FieldError/fieldErrorState.ts +21 -0
  60. package/src/components/forms/FieldLabel/FieldLabel.astro +32 -0
  61. package/src/components/forms/FieldLabel/FieldLabel.css +17 -0
  62. package/src/components/forms/TextInput/TextInput.astro +79 -0
  63. package/src/components/forms/TextInput/TextInput.css +121 -0
  64. package/src/components/forms/TextInput/textInputController.ts +53 -0
  65. package/src/components/icons/ArrowDownIcon.astro +26 -0
  66. package/src/components/icons/ArrowLeftIcon.astro +26 -0
  67. package/src/components/icons/ArrowRightIcon.astro +26 -0
  68. package/src/components/icons/ArrowUpDownIcon.astro +26 -0
  69. package/src/components/icons/ArrowUpIcon.astro +26 -0
  70. package/src/components/icons/BulletIcon.astro +21 -0
  71. package/src/components/icons/BurnIcon.astro +24 -0
  72. package/src/components/icons/CircleSymbolIcon.css +66 -0
  73. package/src/components/icons/ClearIcon.astro +28 -0
  74. package/src/components/icons/CloseIcon.astro +21 -0
  75. package/src/components/icons/CopyIcon.astro +30 -0
  76. package/src/components/icons/CurrencyIcon.css +9 -0
  77. package/src/components/icons/DayIcon.astro +33 -0
  78. package/src/components/icons/DollarIcon.astro +28 -0
  79. package/src/components/icons/DownloadIcon.astro +22 -0
  80. package/src/components/icons/EnterFullscreenIcon.astro +22 -0
  81. package/src/components/icons/EqualIcon.astro +25 -0
  82. package/src/components/icons/ExitFullscreenIcon.astro +22 -0
  83. package/src/components/icons/ExternalLinkIcon.astro +22 -0
  84. package/src/components/icons/FieldIcon.astro +28 -0
  85. package/src/components/icons/GrassIcon.astro +29 -0
  86. package/src/components/icons/InfoIcon.astro +24 -0
  87. package/src/components/icons/MinusIcon.astro +21 -0
  88. package/src/components/icons/MountainIcon.astro +31 -0
  89. package/src/components/icons/NightIcon.astro +32 -0
  90. package/src/components/icons/PlayIcon.astro +22 -0
  91. package/src/components/icons/PlusIcon.astro +21 -0
  92. package/src/components/icons/PoisonIcon.astro +24 -0
  93. package/src/components/icons/RibbonIcon.astro +25 -0
  94. package/src/components/icons/SlashIcon.astro +22 -0
  95. package/src/components/icons/SlowIcon.astro +25 -0
  96. package/src/components/icons/StarIcon.astro +28 -0
  97. package/src/components/icons/StunIcon.astro +22 -0
  98. package/src/components/icons/TableSortIcon.astro +34 -0
  99. package/src/components/icons/WaterIcon.astro +30 -0
  100. package/src/components/index.ts +83 -0
  101. package/src/components/media/CanvasFrame/CanvasFrame.astro +130 -0
  102. package/src/components/media/CanvasFrame/CanvasFrame.css +59 -0
  103. package/src/components/media/CanvasFrame/canvasFrameController.ts +104 -0
  104. package/src/components/media/EmbedFrame/EmbedFrame.astro +147 -0
  105. package/src/components/media/EmbedFrame/EmbedFrame.css +51 -0
  106. package/src/components/media/EmbedFrame/embedFrameController.ts +66 -0
  107. package/src/components/media/MediaFrame/MediaFrame.astro +34 -0
  108. package/src/components/media/MediaFrame/MediaFrame.css +66 -0
  109. package/src/components/navigation/Breadcrumbs/Breadcrumbs.astro +55 -0
  110. package/src/components/navigation/Breadcrumbs/Breadcrumbs.css +89 -0
  111. package/src/components/navigation/DesktopNavigation.astro +92 -0
  112. package/src/components/navigation/DesktopNavigation.css +99 -0
  113. package/src/components/navigation/Header.astro +73 -0
  114. package/src/components/navigation/Header.css +20 -0
  115. package/src/components/navigation/MobileNavigation.astro +124 -0
  116. package/src/components/navigation/MobileNavigation.css +177 -0
  117. package/src/components/navigation/NavigationBrand.astro +63 -0
  118. package/src/components/navigation/NavigationBrand.css +52 -0
  119. package/src/components/navigation/NavigationControl.css +166 -0
  120. package/src/components/navigation/NavigationItemContent.astro +24 -0
  121. package/src/components/navigation/NavigationLink.astro +121 -0
  122. package/src/components/navigation/NavigationLinks.astro +27 -0
  123. package/src/components/navigation/NavigationMenuList.astro +37 -0
  124. package/src/components/navigation/NavigationMenuList.css +6 -0
  125. package/src/components/navigation/SkipLink/SkipLink.astro +18 -0
  126. package/src/components/navigation/SkipLink/SkipLink.css +26 -0
  127. package/src/components/navigation/SubNavigation/SubNavigation.astro +124 -0
  128. package/src/components/navigation/SubNavigation/SubNavigation.css +211 -0
  129. package/src/components/navigation/mobileNavigationController.ts +122 -0
  130. package/src/components/navigation/navigationState.ts +35 -0
  131. package/src/components/navigation/navigationTypes.ts +18 -0
  132. package/src/components/seo/SeoHead.astro +194 -0
  133. package/src/components/widgetTypes.ts +3 -0
  134. package/src/composition/Grid/Grid.astro +82 -0
  135. package/src/composition/Grid/Grid.css +314 -0
  136. package/src/composition/GridItem/GridItem.astro +50 -0
  137. package/src/composition/GridItem/GridItem.css +95 -0
  138. package/src/composition/Inline/Inline.astro +48 -0
  139. package/src/composition/Inline/Inline.css +65 -0
  140. package/src/composition/Stack/Stack.astro +37 -0
  141. package/src/composition/Stack/Stack.css +31 -0
  142. package/src/composition/SurfaceGroup/SurfaceGroup.astro +44 -0
  143. package/src/composition/SurfaceGroup/SurfaceGroup.css +76 -0
  144. package/src/composition/SurfaceGroup/stickySurfaceGroupController.ts +89 -0
  145. package/src/composition/index.ts +6 -0
  146. package/src/config/index.ts +2 -0
  147. package/src/config/pageMeta.ts +55 -0
  148. package/src/config/siteConfig.ts +90 -0
  149. package/src/data/collectionValidation.ts +61 -0
  150. package/src/data/index.ts +1 -0
  151. package/src/display/contracts.ts +284 -0
  152. package/src/display/index.ts +1 -0
  153. package/src/index.ts +6 -0
  154. package/src/layouts/BaseLayout.astro +74 -0
  155. package/src/layouts/PageSurface.astro +15 -0
  156. package/src/layouts/PageSurface.css +24 -0
  157. package/src/layouts/index.ts +2 -0
  158. package/src/patterns/CircuitPuzzle/CircuitPuzzle.astro +93 -0
  159. package/src/patterns/CircuitPuzzle/CircuitPuzzle.css +118 -0
  160. package/src/patterns/CircuitPuzzle/circuitPuzzleController.ts +205 -0
  161. package/src/patterns/CircuitPuzzle/contracts.ts +42 -0
  162. package/src/patterns/Combobox/Combobox.astro +462 -0
  163. package/src/patterns/Combobox/Combobox.css +403 -0
  164. package/src/patterns/Combobox/comboboxController.ts +788 -0
  165. package/src/patterns/Combobox/contracts.ts +18 -0
  166. package/src/patterns/Dropdown/Dropdown.astro +127 -0
  167. package/src/patterns/Dropdown/Dropdown.css +100 -0
  168. package/src/patterns/Dropdown/dropdownController.ts +157 -0
  169. package/src/patterns/Fullscreen/FullscreenControl.astro +103 -0
  170. package/src/patterns/Fullscreen/FullscreenControl.css +49 -0
  171. package/src/patterns/Fullscreen/fullscreenController.ts +73 -0
  172. package/src/patterns/GlitchOverlay/GlitchOverlay.astro +50 -0
  173. package/src/patterns/GlitchOverlay/GlitchOverlay.css +234 -0
  174. package/src/patterns/GlitchOverlay/glitchOverlayController.ts +152 -0
  175. package/src/patterns/GuidedFlow/GuidedFlow.astro +60 -0
  176. package/src/patterns/GuidedFlow/GuidedFlow.css +82 -0
  177. package/src/patterns/GuidedFlow/contracts.ts +3 -0
  178. package/src/patterns/GuidedFlow/guidedFlowController.ts +49 -0
  179. package/src/patterns/MagneticFieldPuzzle/MagneticFieldPuzzle.astro +217 -0
  180. package/src/patterns/MagneticFieldPuzzle/MagneticFieldPuzzle.css +383 -0
  181. package/src/patterns/MagneticFieldPuzzle/contracts.ts +81 -0
  182. package/src/patterns/MagneticFieldPuzzle/magneticFieldPuzzleController.ts +802 -0
  183. package/src/patterns/MagneticFieldPuzzle/simulation.ts +244 -0
  184. package/src/patterns/MapViewport/MapViewport.astro +296 -0
  185. package/src/patterns/MapViewport/MapViewport.css +257 -0
  186. package/src/patterns/MapViewport/contracts.ts +79 -0
  187. package/src/patterns/MapViewport/geometry.ts +80 -0
  188. package/src/patterns/MapViewport/mapViewportController.ts +636 -0
  189. package/src/patterns/Modal/Modal.astro +64 -0
  190. package/src/patterns/Modal/Modal.css +87 -0
  191. package/src/patterns/Modal/ModalClose.astro +37 -0
  192. package/src/patterns/Modal/ModalOpen.astro +36 -0
  193. package/src/patterns/Modal/modalController.ts +118 -0
  194. package/src/patterns/PuzzleGrid/PuzzleGrid.astro +22 -0
  195. package/src/patterns/PuzzleGrid/PuzzleGrid.css +149 -0
  196. package/src/patterns/PuzzleGrid/contracts.ts +2 -0
  197. package/src/patterns/PuzzleGrid/selectionDismissal.ts +27 -0
  198. package/src/patterns/PuzzleGrid/state.ts +25 -0
  199. package/src/patterns/SpriteProjectilePreview/SpriteProjectilePreview.astro +65 -0
  200. package/src/patterns/SpriteProjectilePreview/SpriteProjectilePreview.css +35 -0
  201. package/src/patterns/SpriteProjectilePreview/contracts.ts +33 -0
  202. package/src/patterns/SpriteProjectilePreview/spriteProjectilePreviewController.ts +586 -0
  203. package/src/patterns/StageFlow/StageFlow.astro +57 -0
  204. package/src/patterns/StageFlow/StageFlow.css +54 -0
  205. package/src/patterns/StageFlow/StageFlowAlternative.astro +23 -0
  206. package/src/patterns/StageFlow/StageFlowArrow.astro +22 -0
  207. package/src/patterns/StageFlow/StageFlowConnector.astro +7 -0
  208. package/src/patterns/StageFlow/StageFlowConnector.css +4 -0
  209. package/src/patterns/StageFlow/StageFlowStage.astro +51 -0
  210. package/src/patterns/StageFlow/StageFlowStage.css +106 -0
  211. package/src/patterns/StageFlow/StageFlowStep.astro +24 -0
  212. package/src/patterns/StageFlow/StageFlowStep.css +19 -0
  213. package/src/patterns/StageFlow/StageFlowSymbol.css +28 -0
  214. package/src/patterns/Table/Table.astro +176 -0
  215. package/src/patterns/Table/Table.css +70 -0
  216. package/src/patterns/Table/TableBody.astro +185 -0
  217. package/src/patterns/Table/TableBody.css +262 -0
  218. package/src/patterns/Table/TableCell.astro +59 -0
  219. package/src/patterns/Table/TableCell.css +99 -0
  220. package/src/patterns/Table/TableCellValue.astro +86 -0
  221. package/src/patterns/Table/TableFooter.astro +32 -0
  222. package/src/patterns/Table/TableFooter.css +31 -0
  223. package/src/patterns/Table/TableHeader.astro +118 -0
  224. package/src/patterns/Table/TableHeader.css +209 -0
  225. package/src/patterns/Table/TablePagination.astro +70 -0
  226. package/src/patterns/Table/TablePagination.css +133 -0
  227. package/src/patterns/Table/TableSkeleton.astro +36 -0
  228. package/src/patterns/Table/TableSkeleton.css +81 -0
  229. package/src/patterns/Table/tableCellController.ts +11 -0
  230. package/src/patterns/Table/tableFilterController.ts +206 -0
  231. package/src/patterns/Table/tableHeaderOverflowController.ts +105 -0
  232. package/src/patterns/Table/tableLayout.ts +113 -0
  233. package/src/patterns/Table/tableProgressiveController.ts +319 -0
  234. package/src/patterns/Table/tableRowNavigationController.ts +91 -0
  235. package/src/patterns/Table/tableScrollController.ts +192 -0
  236. package/src/patterns/Table/tableSortController.ts +272 -0
  237. package/src/patterns/index.ts +46 -0
  238. package/src/primitives/index.ts +4 -0
  239. package/src/primitives/layout/Separator/Separator.astro +29 -0
  240. package/src/primitives/layout/Separator/Separator.css +20 -0
  241. package/src/primitives/media/AmbientAudio/AmbientAudio.astro +28 -0
  242. package/src/primitives/media/Media/Media.astro +122 -0
  243. package/src/primitives/media/Media/Media.css +161 -0
  244. package/src/primitives/text/TextBlock/TextBlock.astro +46 -0
  245. package/src/primitives/text/TextBlock/TextBlock.css +21 -0
  246. package/src/seo/StaticRedirect.astro +32 -0
  247. package/src/seo/index.ts +6 -0
  248. package/src/seo/pageSeo.ts +99 -0
  249. package/src/seo/robots.ts +16 -0
  250. package/src/seo/sitemap.ts +38 -0
  251. package/src/seo/structuredData.ts +133 -0
  252. package/src/seo/url.ts +64 -0
  253. package/src/styles/base.css +148 -0
  254. package/src/styles/interaction.css +108 -0
  255. package/src/styles/style.css +93 -0
  256. package/src/styles/tokens.css +256 -0
  257. package/src/theme/contracts.ts +7 -0
  258. package/src/theme/index.ts +1 -0
  259. package/tsconfig.json +20 -0
@@ -0,0 +1,87 @@
1
+ html:has(.modal[open]) {
2
+ overflow: hidden;
3
+ }
4
+
5
+ html:has(.modal[open]) [data-site-viewport] {
6
+ overflow-y: hidden;
7
+ }
8
+
9
+ .modal {
10
+ position: fixed;
11
+ inset: 0;
12
+ inline-size: 100%;
13
+ block-size: 100%;
14
+ max-inline-size: none;
15
+ max-block-size: none;
16
+ margin: 0;
17
+ padding: 0;
18
+ overflow: hidden;
19
+ overscroll-behavior: contain;
20
+ border: 0;
21
+ background: transparent;
22
+ color: var(--nox-text);
23
+ }
24
+
25
+ .modal[open] {
26
+ display: grid;
27
+ place-items: center;
28
+ }
29
+
30
+ .modal::backdrop {
31
+ background: color-mix(in srgb, var(--nox-mix-dark) 58%, transparent);
32
+ }
33
+
34
+ .modal__content {
35
+ position: relative;
36
+ display: grid;
37
+ inline-size: var(--nox-page-width);
38
+ block-size: 100%;
39
+ min-inline-size: 0;
40
+ min-block-size: 0;
41
+ padding: var(--nox-page-surface-padding);
42
+ }
43
+
44
+ .modal[data-sizing='content'] .modal__content {
45
+ block-size: auto;
46
+ max-block-size: 100%;
47
+ align-self: center;
48
+ overflow: auto;
49
+ }
50
+
51
+ .modal__default-close {
52
+ position: absolute;
53
+ z-index: 1;
54
+ inset-block-start: var(--nox-space-3);
55
+ inset-inline-end: var(--nox-space-3);
56
+ display: grid;
57
+ inline-size: var(--nox-section-compact-block-size);
58
+ block-size: var(--nox-section-compact-block-size);
59
+ overflow: hidden;
60
+ border: var(--nox-border-width) solid var(--nox-border);
61
+ border-radius: var(--nox-radius-md);
62
+ background: var(--nox-surface);
63
+ box-shadow: var(--nox-shadow-surface);
64
+ }
65
+
66
+ [data-modal-source-placeholder] {
67
+ inline-size: min(100%, var(--modal-source-placeholder-inline-size));
68
+ block-size: var(--modal-source-placeholder-block-size);
69
+ min-inline-size: 0;
70
+ visibility: hidden;
71
+ pointer-events: none;
72
+ }
73
+
74
+ .modal-close.nox-button {
75
+ --nox-button-background: transparent;
76
+ }
77
+
78
+ @media (width < 48rem) {
79
+ .modal__content {
80
+ inline-size: 100%;
81
+ padding-inline: 0;
82
+ }
83
+
84
+ .modal__content [data-surface] {
85
+ border-radius: 0;
86
+ }
87
+ }
@@ -0,0 +1,37 @@
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 CloseIcon from '../../components/icons/CloseIcon.astro';
6
+
7
+ type Props = Omit<HTMLAttributes<'button'>, 'disabled' | 'type'> & {
8
+ disabled?: boolean;
9
+ label: string;
10
+ tone?: Tone;
11
+ type?: 'button' | 'reset' | 'submit';
12
+ };
13
+
14
+ const {
15
+ class: className,
16
+ label,
17
+ tone = 'danger',
18
+ type = 'button',
19
+ ...attrs
20
+ }: Props = Astro.props;
21
+ const resolvedClass = ['modal-close', className].filter(Boolean).join(' ');
22
+ ---
23
+
24
+ <Button
25
+ {...attrs}
26
+ class={resolvedClass}
27
+ type={type}
28
+ data-modal-close
29
+ aria-label={label}
30
+ title={label}
31
+ tone={tone}
32
+ borderless
33
+ full
34
+ iconOnly
35
+ >
36
+ <CloseIcon />
37
+ </Button>
@@ -0,0 +1,36 @@
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
+
6
+ type Props = Omit<HTMLAttributes<'button'>, 'aria-controls' | 'type'> & {
7
+ label: string;
8
+ targetId: string;
9
+ tone?: Tone;
10
+ };
11
+
12
+ const {
13
+ class: className,
14
+ label,
15
+ targetId,
16
+ tone,
17
+ ...attrs
18
+ }: Props = Astro.props;
19
+ ---
20
+
21
+ <Button
22
+ {...attrs}
23
+ class={className}
24
+ type="button"
25
+ borderless
26
+ full
27
+ iconOnly
28
+ tone={tone}
29
+ aria-controls={targetId}
30
+ aria-haspopup="dialog"
31
+ aria-label={label}
32
+ title={label}
33
+ data-modal-open={targetId}
34
+ >
35
+ <slot />
36
+ </Button>
@@ -0,0 +1,118 @@
1
+ const initializedAttribute = 'data-modal-initialized';
2
+ const portaledAttribute = 'data-modal-portaled';
3
+ const noop = (): void => undefined;
4
+
5
+ type PortalState = {
6
+ placeholder: HTMLElement;
7
+ source: HTMLElement;
8
+ };
9
+
10
+ const getModalSelector = (id: string): string =>
11
+ `[data-modal-open="${CSS.escape(id)}"]`;
12
+
13
+ const getSourceSelector = (id: string): string =>
14
+ `[data-modal-source="${CSS.escape(id)}"]`;
15
+
16
+ export function initModal(root: HTMLDialogElement): () => void {
17
+ if (root.getAttribute(initializedAttribute) === 'true' || !root.id) {
18
+ return noop;
19
+ }
20
+
21
+ root.setAttribute(initializedAttribute, 'true');
22
+ let activeTrigger: HTMLElement | null = null;
23
+ let portalState: PortalState | null = null;
24
+
25
+ const moveSourceIntoModal = (): void => {
26
+ const portal = root.querySelector<HTMLElement>('[data-modal-portal]');
27
+ const source = document.querySelector<HTMLElement>(
28
+ getSourceSelector(root.id),
29
+ );
30
+ if (!portal || !source || root.contains(source)) return;
31
+
32
+ const sourceBounds = source.getBoundingClientRect();
33
+ const placeholder = document.createElement('div');
34
+ placeholder.dataset.modalSourcePlaceholder = '';
35
+ placeholder.setAttribute('aria-hidden', 'true');
36
+ placeholder.style.setProperty(
37
+ '--modal-source-placeholder-block-size',
38
+ `${sourceBounds.height}px`,
39
+ );
40
+ placeholder.style.setProperty(
41
+ '--modal-source-placeholder-inline-size',
42
+ `${sourceBounds.width}px`,
43
+ );
44
+ source.before(placeholder);
45
+ portal.append(source);
46
+ source.setAttribute(portaledAttribute, 'true');
47
+ portalState = { placeholder, source };
48
+ };
49
+
50
+ const restoreSource = (): void => {
51
+ if (!portalState) return;
52
+
53
+ const { placeholder, source } = portalState;
54
+ placeholder.parentNode?.insertBefore(source, placeholder);
55
+ placeholder.remove();
56
+ source.removeAttribute(portaledAttribute);
57
+ portalState = null;
58
+ source.dispatchEvent(new CustomEvent('modal:restore'));
59
+ };
60
+
61
+ const open = (trigger: HTMLElement): void => {
62
+ if (root.open) return;
63
+
64
+ activeTrigger = trigger;
65
+ moveSourceIntoModal();
66
+ root.showModal();
67
+ portalState?.source.dispatchEvent(new CustomEvent('modal:open'));
68
+
69
+ window.requestAnimationFrame(() => {
70
+ root.querySelector<HTMLElement>('[data-modal-close]')?.focus();
71
+ });
72
+ };
73
+
74
+ const close = (): void => {
75
+ if (root.open) root.close();
76
+ };
77
+
78
+ const handleDocumentClick = (event: MouseEvent): void => {
79
+ const trigger =
80
+ event.target instanceof Element
81
+ ? event.target.closest<HTMLElement>(getModalSelector(root.id))
82
+ : null;
83
+ if (trigger) {
84
+ event.preventDefault();
85
+ open(trigger);
86
+ }
87
+ };
88
+
89
+ const handleRootClick = (event: MouseEvent): void => {
90
+ if (
91
+ event.target === root ||
92
+ (event.target instanceof Element &&
93
+ (event.target.matches('[data-modal-content]') ||
94
+ event.target.closest('[data-modal-close]')))
95
+ ) {
96
+ close();
97
+ }
98
+ };
99
+
100
+ const handleClose = (): void => {
101
+ restoreSource();
102
+ activeTrigger?.focus();
103
+ activeTrigger = null;
104
+ };
105
+
106
+ document.addEventListener('click', handleDocumentClick);
107
+ root.addEventListener('click', handleRootClick);
108
+ root.addEventListener('close', handleClose);
109
+
110
+ return () => {
111
+ document.removeEventListener('click', handleDocumentClick);
112
+ root.removeEventListener('click', handleRootClick);
113
+ root.removeEventListener('close', handleClose);
114
+ if (root.open) root.close();
115
+ restoreSource();
116
+ root.removeAttribute(initializedAttribute);
117
+ };
118
+ }
@@ -0,0 +1,22 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types';
3
+
4
+ type Props = Omit<HTMLAttributes<'div'>, 'aria-label' | 'role' | 'style'> & {
5
+ label: string;
6
+ rows: number;
7
+ columns: number;
8
+ };
9
+
10
+ const { class: className, label, rows, columns, ...attrs }: Props = Astro.props;
11
+ ---
12
+
13
+ <div
14
+ {...attrs}
15
+ class:list={['puzzle-grid', className]}
16
+ role="group"
17
+ aria-label={label}
18
+ data-puzzle-grid
19
+ style={`--puzzle-columns: ${columns}; --puzzle-rows: ${rows};`}
20
+ >
21
+ <slot />
22
+ </div>
@@ -0,0 +1,149 @@
1
+ .puzzle-grid {
2
+ display: grid;
3
+ grid-template-columns: repeat(var(--puzzle-columns), minmax(0, 1fr));
4
+ grid-template-rows: repeat(var(--puzzle-rows), minmax(0, 1fr));
5
+ overflow: hidden;
6
+ inline-size: min(100%, 36rem);
7
+ aspect-ratio: var(--puzzle-columns) / var(--puzzle-rows);
8
+ justify-self: center;
9
+ border: var(--nox-border-width) solid var(--nox-border);
10
+ border-radius: var(--nox-radius-md);
11
+ background:
12
+ linear-gradient(var(--nox-border-muted) 1px, transparent 1px),
13
+ linear-gradient(90deg, var(--nox-border-muted) 1px, transparent 1px),
14
+ var(--nox-surface-muted);
15
+ background-size: calc(100% / var(--puzzle-columns))
16
+ calc(100% / var(--puzzle-rows));
17
+ }
18
+
19
+ .puzzle-grid[data-puzzle-grid-state='valid'] {
20
+ border-color: var(--nox-source-tone-success);
21
+ }
22
+
23
+ .puzzle-grid__cell {
24
+ --puzzle-cell-base-background: var(--nox-surface);
25
+ --puzzle-cell-base-border: var(--nox-border);
26
+ --puzzle-cell-base-color: var(--nox-text-muted);
27
+ --puzzle-cell-state-background: var(--puzzle-cell-base-background);
28
+ --puzzle-cell-state-border: var(--puzzle-cell-base-border);
29
+ --puzzle-cell-state-color: var(--puzzle-cell-base-color);
30
+ --puzzle-cell-interaction-overlay: transparent;
31
+ --puzzle-cell-ring-width: 0px;
32
+ --puzzle-cell-ring-color: transparent;
33
+
34
+ position: relative;
35
+ display: grid;
36
+ grid-row: var(--cell-row);
37
+ grid-column: var(--cell-column);
38
+ min-inline-size: 0;
39
+ min-block-size: 0;
40
+ margin: var(--nox-space-1);
41
+ padding: 0;
42
+ place-items: center;
43
+ overflow: hidden;
44
+ border: var(--nox-border-width) solid var(--puzzle-cell-state-border);
45
+ border-radius: var(--nox-radius-sm);
46
+ background:
47
+ linear-gradient(
48
+ var(--puzzle-cell-interaction-overlay),
49
+ var(--puzzle-cell-interaction-overlay)
50
+ ),
51
+ var(--puzzle-cell-state-background);
52
+ box-shadow: 0 0 0 var(--puzzle-cell-ring-width) var(--puzzle-cell-ring-color);
53
+ color: var(--puzzle-cell-state-color);
54
+ font: inherit;
55
+ }
56
+
57
+ .puzzle-grid__cell[data-puzzle-cell-interactive] {
58
+ cursor: pointer;
59
+ }
60
+
61
+ .puzzle-grid__cell[data-puzzle-cell-state='available'] {
62
+ --puzzle-cell-state-background: color-mix(
63
+ in srgb,
64
+ var(--nox-source-tone-info) 10%,
65
+ var(--nox-surface)
66
+ );
67
+ --puzzle-cell-state-border: var(--nox-source-tone-info);
68
+ --puzzle-cell-state-color: var(--nox-source-tone-info);
69
+ }
70
+
71
+ .puzzle-grid__cell[data-puzzle-cell-state='valid'] {
72
+ --puzzle-cell-state-background: color-mix(
73
+ in srgb,
74
+ var(--nox-source-tone-success) 14%,
75
+ var(--nox-surface)
76
+ );
77
+ --puzzle-cell-state-border: var(--nox-source-tone-success);
78
+ --puzzle-cell-state-color: var(--nox-source-tone-success);
79
+ }
80
+
81
+ .puzzle-grid__cell[data-puzzle-cell-state='invalid'] {
82
+ --puzzle-cell-state-background: color-mix(
83
+ in srgb,
84
+ var(--nox-source-tone-danger) 12%,
85
+ var(--nox-surface)
86
+ );
87
+ --puzzle-cell-state-border: var(--nox-source-tone-danger);
88
+ --puzzle-cell-state-color: var(--nox-source-tone-danger);
89
+ }
90
+
91
+ .puzzle-grid__cell[data-puzzle-cell][data-puzzle-cell-disabled] {
92
+ --puzzle-cell-base-background: var(--nox-surface-strong);
93
+ --puzzle-cell-base-border: var(--nox-border);
94
+ --puzzle-cell-base-color: var(--nox-text-disabled);
95
+
96
+ cursor: not-allowed;
97
+ }
98
+
99
+ .puzzle-grid__cell[data-puzzle-cell][data-puzzle-cell-selected] {
100
+ --puzzle-cell-ring-width: var(--nox-focus-ring-width);
101
+ --puzzle-cell-ring-color: var(--nox-source-tone-info);
102
+
103
+ z-index: 1;
104
+ }
105
+
106
+ .puzzle-grid__cell:focus-visible {
107
+ --puzzle-cell-ring-width: var(--nox-focus-ring-width);
108
+ --puzzle-cell-ring-color: var(--nox-source-tone-info);
109
+
110
+ z-index: 1;
111
+ outline: none;
112
+ }
113
+
114
+ @media (hover: hover) {
115
+ .puzzle-grid__cell[data-puzzle-cell][data-puzzle-cell-interactive]:hover {
116
+ --puzzle-cell-interaction-overlay: color-mix(
117
+ in srgb,
118
+ var(--nox-tone-color) 10%,
119
+ transparent
120
+ );
121
+ }
122
+ }
123
+
124
+ .puzzle-grid__cell[data-puzzle-cell][data-puzzle-cell-interactive]:active {
125
+ --puzzle-cell-interaction-overlay: color-mix(
126
+ in srgb,
127
+ var(--nox-tone-color) 16%,
128
+ transparent
129
+ );
130
+ }
131
+
132
+ @media (prefers-reduced-motion: no-preference) {
133
+ .puzzle-grid[data-puzzle-grid-state='valid'] {
134
+ animation: puzzle-grid-complete 700ms var(--nox-motion-easing-standard);
135
+ }
136
+ }
137
+
138
+ @keyframes puzzle-grid-complete {
139
+ 50% {
140
+ box-shadow: 0 0 0 var(--nox-space-2)
141
+ color-mix(in srgb, var(--nox-source-tone-success) 24%, transparent);
142
+ }
143
+ }
144
+
145
+ @media (width < 34rem) {
146
+ .puzzle-grid__cell {
147
+ margin: 2px;
148
+ }
149
+ }
@@ -0,0 +1,2 @@
1
+ export type PuzzleGridCellState = 'available' | 'valid' | 'invalid';
2
+ export type PuzzleGridState = 'valid';
@@ -0,0 +1,27 @@
1
+ type PuzzleSelectionDismissalOptions = {
2
+ dismiss: () => void;
3
+ isSelectionTarget: (target: Element) => boolean;
4
+ };
5
+
6
+ export function initPuzzleSelectionDismissal(
7
+ root: HTMLElement,
8
+ { dismiss, isSelectionTarget }: PuzzleSelectionDismissalOptions,
9
+ ): void {
10
+ document.addEventListener(
11
+ 'pointerdown',
12
+ (event) => {
13
+ if (!event.isPrimary || event.button !== 0) return;
14
+ const target = event.target;
15
+ if (!(target instanceof Node)) return;
16
+ const element = target instanceof Element ? target : target.parentElement;
17
+ if (element && isSelectionTarget(element)) return;
18
+
19
+ dismiss();
20
+ const focused = document.activeElement;
21
+ if (focused instanceof HTMLElement && root.contains(focused)) {
22
+ focused.blur();
23
+ }
24
+ },
25
+ true,
26
+ );
27
+ }
@@ -0,0 +1,25 @@
1
+ import type { PuzzleGridCellState, PuzzleGridState } from './contracts';
2
+
3
+ export function setPuzzleGridCellState(
4
+ element: HTMLElement,
5
+ state: PuzzleGridCellState | null,
6
+ ): void {
7
+ if (state) {
8
+ element.dataset.puzzleCellState = state;
9
+ return;
10
+ }
11
+
12
+ delete element.dataset.puzzleCellState;
13
+ }
14
+
15
+ export function setPuzzleGridState(
16
+ element: HTMLElement,
17
+ state: PuzzleGridState | null,
18
+ ): void {
19
+ if (state) {
20
+ element.dataset.puzzleGridState = state;
21
+ return;
22
+ }
23
+
24
+ delete element.dataset.puzzleGridState;
25
+ }
@@ -0,0 +1,65 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types';
3
+ import type { Tone } from '../../theme/contracts';
4
+ import type { SpriteProjectilePreviewModel } from './contracts';
5
+
6
+ type SpriteProjectilePreviewFraming = 'embedded' | 'standalone';
7
+
8
+ type Props = HTMLAttributes<'div'> & {
9
+ framing?: SpriteProjectilePreviewFraming;
10
+ model: SpriteProjectilePreviewModel;
11
+ sizing?: 'auto' | 'fill';
12
+ tone?: Tone;
13
+ };
14
+
15
+ const {
16
+ class: className,
17
+ 'data-tone': dataTone,
18
+ framing = 'standalone',
19
+ model,
20
+ sizing = 'auto',
21
+ tone,
22
+ ...attrs
23
+ }: Props = Astro.props;
24
+ const resolvedTone = tone ?? dataTone;
25
+ const serializedModel = JSON.stringify(model).replaceAll('<', '\\u003c');
26
+ ---
27
+
28
+ <div
29
+ {...attrs}
30
+ class:list={['sprite-projectile-preview', className]}
31
+ data-pattern="sprite-projectile-preview"
32
+ data-sprite-projectile-preview
33
+ data-framing={framing}
34
+ data-sizing={sizing}
35
+ data-tone={resolvedTone}
36
+ >
37
+ <canvas
38
+ class="sprite-projectile-preview__canvas"
39
+ width="1"
40
+ height="1"
41
+ role="img"
42
+ aria-label={model.label}
43
+ data-sprite-projectile-preview-canvas
44
+ >
45
+ {model.label}
46
+ </canvas>
47
+ <script
48
+ is:inline
49
+ type="application/json"
50
+ data-sprite-projectile-preview-config
51
+ set:html={serializedModel}
52
+ />
53
+ </div>
54
+
55
+ <script>
56
+ import { initSpriteProjectilePreview } from './spriteProjectilePreviewController';
57
+
58
+ for (const root of document.querySelectorAll(
59
+ '[data-sprite-projectile-preview]',
60
+ )) {
61
+ if (root instanceof HTMLElement) {
62
+ initSpriteProjectilePreview(root);
63
+ }
64
+ }
65
+ </script>
@@ -0,0 +1,35 @@
1
+ .sprite-projectile-preview {
2
+ --sprite-projectile-preview-block-size: clamp(14rem, 34cqi, 22rem);
3
+
4
+ position: relative;
5
+ container-type: inline-size;
6
+ display: grid;
7
+ inline-size: 100%;
8
+ block-size: var(--sprite-projectile-preview-block-size);
9
+ min-inline-size: 0;
10
+ overflow: hidden;
11
+ border: var(--nox-border-width) solid var(--nox-data-surface-border);
12
+ border-radius: var(--nox-radius-md);
13
+ background: var(--nox-data-surface-background);
14
+ }
15
+
16
+ .sprite-projectile-preview[data-framing='embedded'] {
17
+ border: 0;
18
+ border-radius: 0;
19
+ background: transparent;
20
+ }
21
+
22
+ .sprite-projectile-preview[data-sizing='fill'] {
23
+ block-size: 100%;
24
+ min-block-size: var(--sprite-projectile-preview-block-size);
25
+ }
26
+
27
+ .sprite-projectile-preview__canvas {
28
+ position: absolute;
29
+ inset: 0;
30
+ display: block;
31
+ inline-size: 100%;
32
+ block-size: 100%;
33
+ min-inline-size: 0;
34
+ min-block-size: 0;
35
+ }
@@ -0,0 +1,33 @@
1
+ export type SpriteContentBounds = {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ };
7
+
8
+ export type SpriteSheetAnimation = {
9
+ src: string;
10
+ width: number;
11
+ height: number;
12
+ baseScale: number;
13
+ frames: number;
14
+ rows: number;
15
+ row: number;
16
+ frameDurationMs: number;
17
+ contentBounds: SpriteContentBounds;
18
+ };
19
+
20
+ export type SpriteScaleReference = {
21
+ width: number;
22
+ height: number;
23
+ };
24
+
25
+ export type SpriteProjectilePreviewModel = {
26
+ label: string;
27
+ scaleReference: SpriteScaleReference;
28
+ actor: SpriteSheetAnimation;
29
+ projectile?: SpriteSheetAnimation & {
30
+ intervalMs: number;
31
+ travelDurationMs: number;
32
+ };
33
+ };