@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,244 @@
1
+ import type {
2
+ MagneticFieldDirection,
3
+ MagneticFieldMove,
4
+ MagneticFieldMovement,
5
+ MagneticFieldPolarity,
6
+ MagneticFieldPosition,
7
+ MagneticFieldPuzzleModel,
8
+ MagneticFieldPuzzleState,
9
+ MagneticFieldSimulation,
10
+ } from './contracts';
11
+
12
+ const directions = [
13
+ 'north',
14
+ 'east',
15
+ 'south',
16
+ 'west',
17
+ ] as const satisfies readonly MagneticFieldDirection[];
18
+
19
+ const directionDelta = {
20
+ north: [-1, 0],
21
+ east: [0, 1],
22
+ south: [1, 0],
23
+ west: [0, -1],
24
+ } as const satisfies Readonly<
25
+ Record<MagneticFieldDirection, readonly [number, number]>
26
+ >;
27
+
28
+ type MagneticFieldMovementPuzzle = Pick<
29
+ MagneticFieldPuzzleModel,
30
+ 'rows' | 'columns' | 'pieces' | 'blockedCells' | 'inverters'
31
+ >;
32
+
33
+ const geometryByPuzzle = new WeakMap<
34
+ object,
35
+ {
36
+ blockedPositions: ReadonlySet<string>;
37
+ inverterIds: ReadonlyMap<string, string>;
38
+ }
39
+ >();
40
+
41
+ export function createMagneticFieldInitialState(
42
+ puzzle: Pick<MagneticFieldPuzzleModel, 'pieces'>,
43
+ ): MagneticFieldPuzzleState {
44
+ return Object.fromEntries(
45
+ puzzle.pieces.map((piece) => [
46
+ piece.id,
47
+ {
48
+ row: piece.row,
49
+ column: piece.column,
50
+ polarity: piece.polarity,
51
+ },
52
+ ]),
53
+ );
54
+ }
55
+
56
+ export function getMagneticFieldMoves(
57
+ puzzle: MagneticFieldMovementPuzzle,
58
+ state: MagneticFieldPuzzleState,
59
+ pieceId: string,
60
+ ): readonly MagneticFieldMovement[] {
61
+ const piece = puzzle.pieces.find((candidate) => candidate.id === pieceId);
62
+ const current = piece ? (state[piece.id] ?? piece) : undefined;
63
+ if (!piece || !current) return [];
64
+
65
+ const { blockedPositions, inverterIds } = getPuzzleGeometry(puzzle);
66
+ const occupiedPositions = new Set(
67
+ puzzle.pieces
68
+ .filter((candidate) => candidate.id !== pieceId)
69
+ .map((candidate) => positionKey(state[candidate.id] ?? candidate)),
70
+ );
71
+ return directions.flatMap((direction) => {
72
+ const movement = createMovement({
73
+ puzzle,
74
+ pieceId,
75
+ direction,
76
+ current,
77
+ blockedPositions,
78
+ occupiedPositions,
79
+ inverterIds,
80
+ });
81
+ return positionsMatch(movement.from, movement.to) ? [] : [movement];
82
+ });
83
+ }
84
+
85
+ export function simulateMagneticFieldMove(
86
+ puzzle: MagneticFieldMovementPuzzle,
87
+ state: MagneticFieldPuzzleState,
88
+ move: MagneticFieldMove,
89
+ ): MagneticFieldSimulation {
90
+ const movement = getMagneticFieldMoves(puzzle, state, move.pieceId).find(
91
+ ({ direction }) => direction === move.direction,
92
+ );
93
+ if (!movement) return { state, movement: null };
94
+
95
+ return applyMagneticFieldMovement(puzzle, state, movement);
96
+ }
97
+
98
+ export function applyMagneticFieldMovement(
99
+ puzzle: Pick<MagneticFieldPuzzleModel, 'pieces'>,
100
+ state: MagneticFieldPuzzleState,
101
+ movement: MagneticFieldMovement,
102
+ ): MagneticFieldSimulation {
103
+ const current = state[movement.pieceId];
104
+ const initialPiece = puzzle.pieces.find(
105
+ (candidate) => candidate.id === movement.pieceId,
106
+ );
107
+ const polarity = current?.polarity ?? initialPiece?.polarity;
108
+ if (!polarity) return { state, movement: null };
109
+
110
+ return {
111
+ state: {
112
+ ...state,
113
+ [movement.pieceId]: {
114
+ ...movement.to,
115
+ polarity:
116
+ movement.crossedInverterIds.length % 2 === 0
117
+ ? polarity
118
+ : oppositePolarity(polarity),
119
+ },
120
+ },
121
+ movement,
122
+ };
123
+ }
124
+
125
+ function getPuzzleGeometry(puzzle: MagneticFieldMovementPuzzle): {
126
+ blockedPositions: ReadonlySet<string>;
127
+ inverterIds: ReadonlyMap<string, string>;
128
+ } {
129
+ const cached = geometryByPuzzle.get(puzzle);
130
+ if (cached) return cached;
131
+
132
+ const geometry = {
133
+ blockedPositions: new Set(
134
+ puzzle.blockedCells.map(({ row, column }) =>
135
+ positionKey({ row, column }),
136
+ ),
137
+ ),
138
+ inverterIds: new Map(
139
+ puzzle.inverters.map(({ id, row, column }) => [
140
+ positionKey({ row, column }),
141
+ id,
142
+ ]),
143
+ ),
144
+ };
145
+ geometryByPuzzle.set(puzzle, geometry);
146
+ return geometry;
147
+ }
148
+
149
+ export function isMagneticFieldPuzzleComplete(
150
+ puzzle: Pick<MagneticFieldPuzzleModel, 'pieces' | 'targets'>,
151
+ state: MagneticFieldPuzzleState,
152
+ ): boolean {
153
+ return puzzle.targets.every((target) => {
154
+ const piece = state[target.pieceId];
155
+ return (
156
+ piece !== undefined &&
157
+ piece.row === target.row &&
158
+ piece.column === target.column &&
159
+ piece.polarity === target.polarity
160
+ );
161
+ });
162
+ }
163
+
164
+ function createMovement({
165
+ puzzle,
166
+ pieceId,
167
+ direction,
168
+ current,
169
+ blockedPositions,
170
+ occupiedPositions,
171
+ inverterIds,
172
+ }: {
173
+ puzzle: Pick<MagneticFieldPuzzleModel, 'rows' | 'columns'>;
174
+ pieceId: string;
175
+ direction: MagneticFieldDirection;
176
+ current: MagneticFieldPosition;
177
+ blockedPositions: ReadonlySet<string>;
178
+ occupiedPositions: ReadonlySet<string>;
179
+ inverterIds: ReadonlyMap<string, string>;
180
+ }): MagneticFieldMovement {
181
+ const [rowDelta, columnDelta] = directionDelta[direction];
182
+ let position = { row: current.row, column: current.column };
183
+ const crossedInverterIds: string[] = [];
184
+
185
+ while (true) {
186
+ const next = {
187
+ row: position.row + rowDelta,
188
+ column: position.column + columnDelta,
189
+ };
190
+ const nextKey = positionKey(next);
191
+ if (
192
+ outsidePuzzle(next, puzzle.rows, puzzle.columns) ||
193
+ blockedPositions.has(nextKey) ||
194
+ occupiedPositions.has(nextKey)
195
+ ) {
196
+ break;
197
+ }
198
+
199
+ position = next;
200
+ const inverterId = inverterIds.get(nextKey);
201
+ if (inverterId) crossedInverterIds.push(inverterId);
202
+ }
203
+
204
+ return {
205
+ pieceId,
206
+ direction,
207
+ from: {
208
+ row: current.row,
209
+ column: current.column,
210
+ },
211
+ to: position,
212
+ crossedInverterIds,
213
+ };
214
+ }
215
+
216
+ function outsidePuzzle(
217
+ position: MagneticFieldPosition,
218
+ rows: number,
219
+ columns: number,
220
+ ): boolean {
221
+ return (
222
+ position.row < 0 ||
223
+ position.row >= rows ||
224
+ position.column < 0 ||
225
+ position.column >= columns
226
+ );
227
+ }
228
+
229
+ function positionsMatch(
230
+ first: MagneticFieldPosition,
231
+ second: MagneticFieldPosition,
232
+ ): boolean {
233
+ return first.row === second.row && first.column === second.column;
234
+ }
235
+
236
+ function oppositePolarity(
237
+ polarity: MagneticFieldPolarity,
238
+ ): MagneticFieldPolarity {
239
+ return polarity === 'north' ? 'south' : 'north';
240
+ }
241
+
242
+ function positionKey(position: MagneticFieldPosition): string {
243
+ return `${position.row}:${position.column}`;
244
+ }
@@ -0,0 +1,296 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types';
3
+ import type { Tone } from '../../theme/contracts';
4
+ import type { DisplayMedia } from '../../display/contracts';
5
+ import CardBody from '../../components/content/CardBody/CardBody.astro';
6
+ import CardHeader from '../../components/content/CardHeader/CardHeader.astro';
7
+ import SurfaceGroup from '../../composition/SurfaceGroup/SurfaceGroup.astro';
8
+ import Modal from '../Modal/Modal.astro';
9
+ import ModalClose from '../Modal/ModalClose.astro';
10
+ import type {
11
+ MapViewportModel,
12
+ MapViewportShape,
13
+ MapViewportSizing,
14
+ } from './contracts';
15
+ import { getMapViewportSceneGeometry } from './geometry';
16
+
17
+ type MapViewportModal = {
18
+ id: string;
19
+ title: string;
20
+ closeLabel: string;
21
+ media?: DisplayMedia;
22
+ };
23
+
24
+ type MapViewportFraming = 'embedded' | 'standalone';
25
+
26
+ type Props = Omit<HTMLAttributes<'div'>, 'style'> & {
27
+ framing?: MapViewportFraming;
28
+ modal?: MapViewportModal;
29
+ model: MapViewportModel;
30
+ sizing?: MapViewportSizing;
31
+ tone?: Tone;
32
+ };
33
+
34
+ const {
35
+ class: className,
36
+ 'data-tone': dataTone,
37
+ framing = 'standalone',
38
+ modal,
39
+ model,
40
+ sizing = 'aspect',
41
+ tone,
42
+ ...attrs
43
+ }: Props = Astro.props;
44
+ const resolvedTone = tone ?? dataTone;
45
+ const backgroundLayers = model.layers
46
+ .filter((layer) => layer.plane === 'background')
47
+ .toSorted((left, right) => left.order - right.order);
48
+ const foregroundLayers = model.layers
49
+ .filter((layer) => layer.plane === 'foreground')
50
+ .toSorted((left, right) => left.order - right.order);
51
+ const isInteractive = (state: string): boolean =>
52
+ model.interaction === 'single-selection' &&
53
+ (state === 'available' || state === 'selected');
54
+ const ringPath = (shape: Extract<MapViewportShape, { kind: 'ring' }>): string =>
55
+ [
56
+ `M ${shape.x - shape.radius} ${shape.y}`,
57
+ `a ${shape.radius} ${shape.radius} 0 1 0 ${shape.radius * 2} 0`,
58
+ `a ${shape.radius} ${shape.radius} 0 1 0 ${-shape.radius * 2} 0`,
59
+ `M ${shape.x - shape.innerRadius} ${shape.y}`,
60
+ `a ${shape.innerRadius} ${shape.innerRadius} 0 1 1 ${shape.innerRadius * 2} 0`,
61
+ `a ${shape.innerRadius} ${shape.innerRadius} 0 1 1 ${-shape.innerRadius * 2} 0`,
62
+ ].join(' ');
63
+ const sceneGeometry = getMapViewportSceneGeometry(model, sizing);
64
+ const viewportStyle = [
65
+ `--map-viewport-reference-aspect-ratio: ${sceneGeometry.aspectRatio}`,
66
+ `--map-viewport-reference-ratio: ${sceneGeometry.referenceRatio}`,
67
+ `--map-viewport-scene-inline-size: ${sceneGeometry.inlineSize}`,
68
+ `--map-viewport-scene-block-size: ${sceneGeometry.blockSize}`,
69
+ ].join('; ');
70
+ ---
71
+
72
+ <div
73
+ class="map-viewport-frame"
74
+ data-framing={framing}
75
+ data-modal-source={modal?.id}
76
+ data-sizing={sizing}
77
+ data-tone={resolvedTone}
78
+ style={viewportStyle}
79
+ >
80
+ <div
81
+ {...attrs}
82
+ class:list={['map-viewport', className]}
83
+ data-widget="map-viewport"
84
+ data-map-viewport
85
+ data-map-interaction={model.interaction}
86
+ data-map-logical-overflow-block={String(sceneGeometry.overflowsBlock)}
87
+ data-map-logical-overflow-inline={String(sceneGeometry.overflowsInline)}
88
+ data-map-overflow-block={String(sceneGeometry.overflowsBlock)}
89
+ data-map-overflow-inline={String(sceneGeometry.overflowsInline)}
90
+ data-map-reference-ratio={sceneGeometry.referenceRatio}
91
+ data-sizing={sizing}
92
+ data-tone={resolvedTone}
93
+ role="region"
94
+ aria-label={model.label}
95
+ tabindex="0"
96
+ style={viewportStyle}
97
+ >
98
+ <div class="map-viewport__scene" data-map-viewport-scene>
99
+ <svg
100
+ class="map-viewport__svg"
101
+ data-map-viewport-svg
102
+ viewBox={`0 0 ${model.width} ${model.height}`}
103
+ preserveAspectRatio="xMinYMin meet"
104
+ role={model.interaction === 'none' ? 'img' : 'group'}
105
+ aria-label={model.label}
106
+ >
107
+ {
108
+ backgroundLayers.map((layer) => (
109
+ <image
110
+ data-map-layer={layer.id}
111
+ href={layer.media.src}
112
+ x="0"
113
+ y="0"
114
+ width={model.width}
115
+ height={model.height}
116
+ preserveAspectRatio="none"
117
+ />
118
+ ))
119
+ }
120
+
121
+ <g class="map-viewport__cells" data-map-cells>
122
+ {
123
+ model.cells.map((cell) => (
124
+ <g
125
+ class="map-viewport__cell"
126
+ data-map-cell={cell.id}
127
+ data-map-cell-state={cell.state}
128
+ data-map-cell-palette={cell.palette}
129
+ role={isInteractive(cell.state) ? 'button' : undefined}
130
+ tabindex={isInteractive(cell.state) ? '0' : undefined}
131
+ aria-label={isInteractive(cell.state) ? cell.label : undefined}
132
+ aria-pressed={
133
+ isInteractive(cell.state)
134
+ ? cell.state === 'selected'
135
+ ? 'true'
136
+ : 'false'
137
+ : undefined
138
+ }
139
+ >
140
+ <title>{cell.label}</title>
141
+ <rect
142
+ x={cell.x}
143
+ y={cell.y}
144
+ width={cell.width}
145
+ height={cell.height}
146
+ />
147
+ </g>
148
+ ))
149
+ }
150
+ </g>
151
+
152
+ <g class="map-viewport__shapes" data-map-shapes aria-hidden="true">
153
+ {
154
+ (model.shapes ?? []).map((shape) => (
155
+ <g
156
+ class="map-viewport__shape"
157
+ data-map-shape={shape.kind}
158
+ data-map-shape-palette={shape.palette}
159
+ >
160
+ {shape.kind === 'circle' ? (
161
+ <circle cx={shape.x} cy={shape.y} r={shape.radius} />
162
+ ) : null}
163
+ {shape.kind === 'ring' ? (
164
+ <path d={ringPath(shape)} fill-rule="evenodd" />
165
+ ) : null}
166
+ {shape.kind === 'polygon' ? (
167
+ <polygon
168
+ points={shape.points
169
+ .map((point) => `${point.x},${point.y}`)
170
+ .join(' ')}
171
+ />
172
+ ) : null}
173
+ {shape.kind === 'horizontal-line' || shape.kind === 'cross' ? (
174
+ <rect
175
+ x={shape.x - shape.radius}
176
+ y={shape.y - shape.halfWidth}
177
+ width={shape.radius * 2}
178
+ height={shape.halfWidth * 2}
179
+ />
180
+ ) : null}
181
+ {shape.kind === 'vertical-line' || shape.kind === 'cross' ? (
182
+ <rect
183
+ x={shape.x - shape.halfWidth}
184
+ y={shape.y - shape.radius}
185
+ width={shape.halfWidth * 2}
186
+ height={shape.radius * 2}
187
+ />
188
+ ) : null}
189
+ {shape.kind === 'diagonal-cross' ? (
190
+ <g transform={`rotate(45 ${shape.x} ${shape.y})`}>
191
+ <rect
192
+ x={shape.x - shape.halfWidth}
193
+ y={shape.y - shape.radius}
194
+ width={shape.halfWidth * 2}
195
+ height={shape.radius * 2}
196
+ />
197
+ <rect
198
+ x={shape.x - shape.radius}
199
+ y={shape.y - shape.halfWidth}
200
+ width={shape.radius * 2}
201
+ height={shape.halfWidth * 2}
202
+ />
203
+ </g>
204
+ ) : null}
205
+ </g>
206
+ ))
207
+ }
208
+ </g>
209
+
210
+ <g class="map-viewport__markers" data-map-markers>
211
+ {
212
+ (model.markers ?? []).map((marker) => (
213
+ <g class="map-viewport__marker" data-map-marker={marker.id}>
214
+ <title>{marker.label}</title>
215
+ <image
216
+ href={marker.media.src}
217
+ x={marker.x}
218
+ y={marker.y}
219
+ width={marker.width}
220
+ height={marker.height}
221
+ preserveAspectRatio="xMidYMid meet"
222
+ />
223
+ </g>
224
+ ))
225
+ }
226
+ </g>
227
+
228
+ {
229
+ foregroundLayers.map((layer) => (
230
+ <image
231
+ data-map-layer={layer.id}
232
+ href={layer.media.src}
233
+ x="0"
234
+ y="0"
235
+ width={model.width}
236
+ height={model.height}
237
+ preserveAspectRatio="none"
238
+ pointer-events="none"
239
+ />
240
+ ))
241
+ }
242
+ </svg>
243
+ </div>
244
+ <p
245
+ class="map-viewport__announcement"
246
+ data-map-announcement
247
+ aria-live="polite"
248
+ >
249
+ </p>
250
+ </div>
251
+ </div>
252
+
253
+ {
254
+ modal ? (
255
+ <Modal
256
+ id={modal.id}
257
+ label={modal.title}
258
+ closeLabel={modal.closeLabel}
259
+ closeControl="delegated"
260
+ sizing="content"
261
+ tone={resolvedTone}
262
+ >
263
+ <SurfaceGroup
264
+ class="map-viewport__modal-card"
265
+ data-map-viewport-modal-card={modal.id}
266
+ style={viewportStyle}
267
+ >
268
+ {modal.media ? (
269
+ <CardHeader title={modal.title} media={modal.media}>
270
+ <ModalClose slot="action" label={modal.closeLabel} />
271
+ </CardHeader>
272
+ ) : (
273
+ <CardHeader title={modal.title}>
274
+ <ModalClose slot="action" label={modal.closeLabel} />
275
+ </CardHeader>
276
+ )}
277
+ <CardBody
278
+ class="map-viewport__modal-body"
279
+ inset={framing === 'embedded' ? 'none' : 'default'}
280
+ >
281
+ <div class="map-viewport__modal-portal" data-modal-portal />
282
+ </CardBody>
283
+ </SurfaceGroup>
284
+ </Modal>
285
+ ) : null
286
+ }
287
+
288
+ <script>
289
+ import { initMapViewport } from './mapViewportController';
290
+
291
+ for (const root of document.querySelectorAll('[data-map-viewport]')) {
292
+ if (root instanceof HTMLElement) {
293
+ initMapViewport(root);
294
+ }
295
+ }
296
+ </script>