@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,217 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types';
3
+ import MinusIcon from '../../components/icons/MinusIcon.astro';
4
+ import PlusIcon from '../../components/icons/PlusIcon.astro';
5
+ import SlashIcon from '../../components/icons/SlashIcon.astro';
6
+ import PuzzleGrid from '../PuzzleGrid/PuzzleGrid.astro';
7
+ import type {
8
+ MagneticFieldPuzzleLabels,
9
+ MagneticFieldPuzzleModel,
10
+ } from './contracts';
11
+
12
+ type Props = HTMLAttributes<'section'> & {
13
+ label: string;
14
+ labels: MagneticFieldPuzzleLabels;
15
+ puzzles: readonly MagneticFieldPuzzleModel[];
16
+ };
17
+
18
+ const {
19
+ class: className,
20
+ label,
21
+ labels,
22
+ puzzles,
23
+ ...attrs
24
+ }: Props = Astro.props;
25
+ ---
26
+
27
+ <section
28
+ {...attrs}
29
+ class:list={['magnetic-field-puzzle', className]}
30
+ aria-label={label}
31
+ data-magnetic-field-puzzle
32
+ >
33
+ {
34
+ puzzles.map((puzzle, puzzleIndex) => {
35
+ const cells = Array.from(
36
+ { length: puzzle.rows * puzzle.columns },
37
+ (_, index) => ({
38
+ row: Math.floor(index / puzzle.columns),
39
+ column: index % puzzle.columns,
40
+ }),
41
+ );
42
+
43
+ return (
44
+ <div
45
+ class="magnetic-field-puzzle__instance"
46
+ data-puzzle-id={puzzle.id}
47
+ data-puzzle-status="incomplete"
48
+ hidden={puzzleIndex !== 0}
49
+ >
50
+ <PuzzleGrid
51
+ class="magnetic-field-puzzle__board"
52
+ label={puzzle.label}
53
+ rows={puzzle.rows}
54
+ columns={puzzle.columns}
55
+ data-field-board
56
+ data-field-rows={puzzle.rows}
57
+ data-field-columns={puzzle.columns}
58
+ >
59
+ {cells.map(({ row, column }) => {
60
+ const target = puzzle.targets.find(
61
+ (candidate) =>
62
+ candidate.row === row && candidate.column === column,
63
+ );
64
+ const inverter = puzzle.inverters.find(
65
+ (candidate) =>
66
+ candidate.row === row && candidate.column === column,
67
+ );
68
+ const blockedCell = puzzle.blockedCells.find(
69
+ (candidate) =>
70
+ candidate.row === row && candidate.column === column,
71
+ );
72
+ const targetPiece = target
73
+ ? puzzle.pieces.find(
74
+ (candidate) => candidate.id === target.pieceId,
75
+ )
76
+ : undefined;
77
+ const cellLabel =
78
+ blockedCell?.label ??
79
+ (target
80
+ ? `${target.label} — ${labels.polarities[target.polarity]}`
81
+ : undefined) ??
82
+ inverter?.label ??
83
+ '';
84
+
85
+ return (
86
+ <button
87
+ class="puzzle-grid__cell magnetic-field-puzzle__cell"
88
+ type="button"
89
+ aria-label={cellLabel || undefined}
90
+ disabled={blockedCell ? true : undefined}
91
+ tabindex={blockedCell ? undefined : -1}
92
+ data-puzzle-cell
93
+ data-puzzle-cell-disabled={blockedCell ? '' : undefined}
94
+ data-field-cell
95
+ data-field-blocked-cell={blockedCell?.id}
96
+ data-field-target-cell={target?.id}
97
+ data-field-target-polarity={target?.polarity}
98
+ data-field-inverter-cell={inverter?.id}
99
+ data-cell-row={row}
100
+ data-cell-column={column}
101
+ data-cell-label={cellLabel || undefined}
102
+ style={`--cell-row: ${row + 1}; --cell-column: ${column + 1};`}
103
+ >
104
+ {target ? (
105
+ <span
106
+ class="magnetic-field-puzzle__target"
107
+ data-field-target={target.id}
108
+ data-target-label={target.label}
109
+ data-target-piece={target.pieceId}
110
+ data-target-polarity={target.polarity}
111
+ data-target-row={target.row}
112
+ data-target-column={target.column}
113
+ aria-hidden="true"
114
+ >
115
+ <span
116
+ class="magnetic-field-puzzle__identity"
117
+ data-polarity={target.polarity}
118
+ >
119
+ {targetPiece?.shortLabel}
120
+ </span>
121
+ </span>
122
+ ) : null}
123
+
124
+ {inverter ? (
125
+ <span
126
+ class="magnetic-field-puzzle__inverter"
127
+ data-field-inverter={inverter.id}
128
+ data-inverter-label={inverter.label}
129
+ data-inverter-row={inverter.row}
130
+ data-inverter-column={inverter.column}
131
+ aria-hidden="true"
132
+ >
133
+ <span
134
+ class="magnetic-field-puzzle__polarity-icon"
135
+ data-polarity="south"
136
+ >
137
+ <PlusIcon />
138
+ </span>
139
+ <span class="magnetic-field-puzzle__inverter-separator">
140
+ <SlashIcon />
141
+ </span>
142
+ <span
143
+ class="magnetic-field-puzzle__polarity-icon"
144
+ data-polarity="north"
145
+ >
146
+ <MinusIcon />
147
+ </span>
148
+ </span>
149
+ ) : null}
150
+ </button>
151
+ );
152
+ })}
153
+
154
+ {puzzle.pieces.map((piece) => (
155
+ <button
156
+ class="magnetic-field-puzzle__piece"
157
+ type="button"
158
+ aria-label={`${piece.label} — ${labels.polarities[piece.polarity]}`}
159
+ aria-pressed="false"
160
+ data-field-piece={piece.id}
161
+ data-piece-label={piece.label}
162
+ data-piece-short-label={piece.shortLabel}
163
+ data-piece-row={piece.row}
164
+ data-piece-column={piece.column}
165
+ data-piece-polarity={piece.polarity}
166
+ data-piece-pupil-position={piece.pupilPosition}
167
+ data-polarity-label-north={labels.polarities.north}
168
+ data-polarity-label-south={labels.polarities.south}
169
+ data-initial-row={piece.row}
170
+ data-initial-column={piece.column}
171
+ data-initial-polarity={piece.polarity}
172
+ style={`--piece-row: ${piece.row + 1}; --piece-column: ${piece.column + 1};`}
173
+ >
174
+ <span
175
+ class="magnetic-field-puzzle__piece-core"
176
+ aria-hidden="true"
177
+ >
178
+ <span class="magnetic-field-puzzle__piece-iris">
179
+ <span class="magnetic-field-puzzle__piece-pupil" />
180
+ </span>
181
+ <span class="magnetic-field-puzzle__piece-identity-region">
182
+ <span
183
+ class="magnetic-field-puzzle__identity"
184
+ data-polarity={piece.polarity}
185
+ data-piece-polarity-identity
186
+ >
187
+ {piece.shortLabel}
188
+ </span>
189
+ </span>
190
+ </span>
191
+ </button>
192
+ ))}
193
+ </PuzzleGrid>
194
+
195
+ <span
196
+ hidden
197
+ data-direction-label-north={labels.directions.north}
198
+ data-direction-label-east={labels.directions.east}
199
+ data-direction-label-south={labels.directions.south}
200
+ data-direction-label-west={labels.directions.west}
201
+ data-move-template={labels.moveTemplate}
202
+ />
203
+ </div>
204
+ );
205
+ })
206
+ }
207
+ </section>
208
+
209
+ <script>
210
+ import { initMagneticFieldPuzzle } from './magneticFieldPuzzleController';
211
+
212
+ for (const root of document.querySelectorAll(
213
+ '[data-magnetic-field-puzzle]',
214
+ )) {
215
+ if (root instanceof HTMLElement) initMagneticFieldPuzzle(root);
216
+ }
217
+ </script>
@@ -0,0 +1,383 @@
1
+ .magnetic-field-puzzle {
2
+ --magnetic-piece-structure-color: #1f2838;
3
+ --magnetic-piece-shell-background: #a5c4d0;
4
+ --magnetic-piece-iris-background: #f4de62;
5
+ --magnetic-piece-pupil-background: #000;
6
+ --magnetic-piece-shell-border-width: calc(var(--nox-border-width) * 2);
7
+ --magnetic-piece-iris-border-width: var(--nox-border-width);
8
+ --magnetic-polarity-gap: calc(var(--nox-space-1) / 2);
9
+ --magnetic-polarity-size: var(--nox-font-size-md);
10
+ }
11
+
12
+ .magnetic-field-puzzle,
13
+ .magnetic-field-puzzle__instance {
14
+ display: grid;
15
+ min-inline-size: 0;
16
+ }
17
+
18
+ .magnetic-field-puzzle__instance[hidden] {
19
+ display: none;
20
+ }
21
+
22
+ .magnetic-field-puzzle__board {
23
+ isolation: isolate;
24
+ touch-action: manipulation;
25
+ }
26
+
27
+ .magnetic-field-puzzle__cell {
28
+ appearance: none;
29
+ }
30
+
31
+ .magnetic-field-puzzle__cell[data-field-target-cell],
32
+ .magnetic-field-puzzle__cell[data-field-inverter-cell] {
33
+ --puzzle-cell-base-background: var(--nox-surface);
34
+ --puzzle-cell-base-color: var(--nox-text);
35
+
36
+ border-style: dashed;
37
+ }
38
+
39
+ .magnetic-field-puzzle__cell[data-field-target-polarity='north'] {
40
+ --puzzle-cell-base-border: var(--nox-source-tone-info);
41
+ }
42
+
43
+ .magnetic-field-puzzle__cell[data-field-target-polarity='south'] {
44
+ --puzzle-cell-base-border: var(--nox-source-tone-danger);
45
+ }
46
+
47
+ .magnetic-field-puzzle__cell[data-field-inverter-cell] {
48
+ border-block-start-color: var(--nox-source-tone-info);
49
+ border-inline-start-color: var(--nox-source-tone-info);
50
+ border-block-end-color: var(--nox-source-tone-danger);
51
+ border-inline-end-color: var(--nox-source-tone-danger);
52
+ }
53
+
54
+ .magnetic-field-puzzle__cell[data-puzzle-cell-state='invalid'] {
55
+ --puzzle-cell-state-background: color-mix(
56
+ in srgb,
57
+ var(--nox-source-tone-warning) 12%,
58
+ var(--nox-surface)
59
+ );
60
+ --puzzle-cell-state-border: var(--nox-source-tone-warning);
61
+ --puzzle-cell-state-color: var(--nox-source-tone-warning);
62
+ }
63
+
64
+ .magnetic-field-puzzle__target {
65
+ position: relative;
66
+ z-index: 3;
67
+ display: inline-grid;
68
+ place-items: center;
69
+ min-inline-size: 0;
70
+ }
71
+
72
+ .magnetic-field-puzzle__inverter {
73
+ position: relative;
74
+ z-index: 3;
75
+ display: inline-flex;
76
+ align-items: center;
77
+ justify-content: center;
78
+ min-inline-size: 0;
79
+ gap: var(--magnetic-polarity-gap);
80
+ font-size: var(--magnetic-polarity-size);
81
+ font-weight: var(--nox-font-weight-strong);
82
+ }
83
+
84
+ .magnetic-field-puzzle__identity {
85
+ color: var(--magnetic-piece-structure-color);
86
+ display: inline-grid;
87
+ place-items: center;
88
+ font-size: var(--magnetic-polarity-size);
89
+ font-weight: var(--nox-font-weight-strong);
90
+ line-height: 1;
91
+ }
92
+
93
+ .magnetic-field-puzzle__identity[data-polarity='north'] {
94
+ color: var(--nox-source-tone-info);
95
+ }
96
+
97
+ .magnetic-field-puzzle__identity[data-polarity='south'] {
98
+ color: var(--nox-source-tone-danger);
99
+ }
100
+
101
+ .magnetic-field-puzzle__polarity-icon {
102
+ display: grid;
103
+ inline-size: 1em;
104
+ block-size: 1em;
105
+ aspect-ratio: 1;
106
+ place-items: center;
107
+ color: var(--nox-source-tone-info);
108
+ }
109
+
110
+ .magnetic-field-puzzle__polarity-icon > svg {
111
+ display: block;
112
+ inline-size: 100%;
113
+ block-size: 100%;
114
+ }
115
+
116
+ .magnetic-field-puzzle__polarity-icon[data-polarity='south'] {
117
+ color: var(--nox-source-tone-danger);
118
+ }
119
+
120
+ .magnetic-field-puzzle__inverter-separator {
121
+ display: grid;
122
+ inline-size: 0.75em;
123
+ block-size: 1em;
124
+ place-items: center;
125
+ color: var(--nox-text-muted);
126
+ }
127
+
128
+ .magnetic-field-puzzle__inverter-separator > svg {
129
+ display: block;
130
+ inline-size: 100%;
131
+ block-size: 100%;
132
+ }
133
+
134
+ @media (width < 34rem) {
135
+ .magnetic-field-puzzle {
136
+ --magnetic-piece-shell-border-width: var(--nox-border-width);
137
+ --magnetic-piece-iris-border-width: calc(var(--nox-border-width) / 2);
138
+ --magnetic-polarity-gap: 0px;
139
+ --magnetic-polarity-size: var(--nox-font-size-sm);
140
+ }
141
+ }
142
+
143
+ .magnetic-field-puzzle__cell[data-field-destination] {
144
+ --puzzle-cell-ring-width: var(--nox-focus-ring-width);
145
+ --puzzle-cell-ring-color: var(--nox-source-tone-info);
146
+
147
+ z-index: 3;
148
+ overflow: visible;
149
+ }
150
+
151
+ .magnetic-field-puzzle__path-stream {
152
+ --field-path-rotation: 0deg;
153
+
154
+ position: relative;
155
+ z-index: 3;
156
+ grid-row: var(--field-path-row);
157
+ grid-column: var(--field-path-column);
158
+ min-inline-size: 0;
159
+ min-block-size: 0;
160
+ overflow: visible;
161
+ pointer-events: none;
162
+ }
163
+
164
+ .magnetic-field-puzzle__path-chevron {
165
+ --field-path-chevron-opacity: 0.38;
166
+
167
+ position: absolute;
168
+ display: grid;
169
+ inset-block-start: var(--field-path-static-block);
170
+ inset-inline-start: var(--field-path-static-inline);
171
+ inline-size: 1em;
172
+ block-size: 1em;
173
+ place-items: center;
174
+ color: var(--nox-source-tone-success);
175
+ font-size: var(--nox-font-size-xl);
176
+ opacity: var(--field-path-chevron-opacity);
177
+ pointer-events: none;
178
+ transform: translate(-50%, -50%) rotate(var(--field-path-rotation));
179
+ }
180
+
181
+ .magnetic-field-puzzle__path-chevron::before {
182
+ content: '';
183
+ inline-size: 0.46em;
184
+ block-size: 0.46em;
185
+ border-block-start: calc(var(--nox-border-width) * 2) solid currentColor;
186
+ border-inline-end: calc(var(--nox-border-width) * 2) solid currentColor;
187
+ transform: rotate(45deg);
188
+ }
189
+
190
+ .magnetic-field-puzzle__path-stream[data-field-path-direction='north'] {
191
+ --field-path-rotation: -90deg;
192
+ }
193
+
194
+ .magnetic-field-puzzle__path-stream[data-field-path-direction='south'] {
195
+ --field-path-rotation: 90deg;
196
+ }
197
+
198
+ .magnetic-field-puzzle__path-stream[data-field-path-direction='west'] {
199
+ --field-path-rotation: 180deg;
200
+ }
201
+
202
+ .magnetic-field-puzzle__piece {
203
+ --piece-pupil-block-position: 35%;
204
+ --piece-pupil-inline-position: 68%;
205
+
206
+ position: relative;
207
+ z-index: 4;
208
+ display: grid;
209
+ grid-row: var(--piece-row);
210
+ grid-column: var(--piece-column);
211
+ min-inline-size: 0;
212
+ min-block-size: 0;
213
+ margin: var(--nox-space-1);
214
+ padding: 0;
215
+ place-items: center;
216
+ border: 0;
217
+ background: transparent;
218
+ color: var(--nox-text);
219
+ font: inherit;
220
+ cursor: grab;
221
+ touch-action: none;
222
+ user-select: none;
223
+ }
224
+
225
+ .magnetic-field-puzzle__piece[data-piece-pupil-position='center'] {
226
+ --piece-pupil-block-position: 50%;
227
+ --piece-pupil-inline-position: 50%;
228
+ }
229
+
230
+ .magnetic-field-puzzle__piece[data-piece-pupil-position='lower-start'] {
231
+ --piece-pupil-block-position: 65%;
232
+ --piece-pupil-inline-position: 32%;
233
+ }
234
+
235
+ .magnetic-field-puzzle__piece-core {
236
+ --piece-interaction-overlay: transparent;
237
+ --piece-ring-width: 0px;
238
+ --piece-ring-color: transparent;
239
+
240
+ position: relative;
241
+ display: grid;
242
+ place-items: center;
243
+ inline-size: 72%;
244
+ aspect-ratio: 1;
245
+ padding: 0;
246
+ border: var(--magnetic-piece-shell-border-width) solid
247
+ var(--magnetic-piece-structure-color);
248
+ border-radius: var(--nox-radius-pill);
249
+ background:
250
+ linear-gradient(
251
+ var(--piece-interaction-overlay),
252
+ var(--piece-interaction-overlay)
253
+ ),
254
+ var(--magnetic-piece-shell-background);
255
+ box-shadow: 0 0 0 var(--piece-ring-width) var(--piece-ring-color);
256
+ font-size: var(--nox-font-size-xs);
257
+ font-weight: var(--nox-font-weight-strong);
258
+ transition:
259
+ background var(--nox-motion-duration-sm) var(--nox-motion-easing-standard),
260
+ box-shadow var(--nox-motion-duration-sm) var(--nox-motion-easing-standard);
261
+ }
262
+
263
+ .magnetic-field-puzzle__piece-iris {
264
+ position: absolute;
265
+ inset-block-start: 10%;
266
+ display: grid;
267
+ inline-size: 40%;
268
+ aspect-ratio: 1;
269
+ place-items: center;
270
+ border: var(--magnetic-piece-iris-border-width) solid
271
+ var(--magnetic-piece-structure-color);
272
+ border-radius: var(--nox-radius-pill);
273
+ background: var(--magnetic-piece-iris-background);
274
+ }
275
+
276
+ .magnetic-field-puzzle__piece-pupil {
277
+ position: absolute;
278
+ inset-block-start: var(--piece-pupil-block-position);
279
+ inset-inline-start: var(--piece-pupil-inline-position);
280
+ inline-size: 16%;
281
+ aspect-ratio: 1;
282
+ border-radius: var(--nox-radius-pill);
283
+ background: var(--magnetic-piece-pupil-background);
284
+ transform: translate(-50%, -50%);
285
+ }
286
+
287
+ .magnetic-field-puzzle__piece-identity-region {
288
+ position: absolute;
289
+ inset-block: 56% 6%;
290
+ inset-inline: 0;
291
+ display: grid;
292
+ place-items: center;
293
+ }
294
+
295
+ .magnetic-field-puzzle__piece[data-piece-selected]
296
+ .magnetic-field-puzzle__piece-core {
297
+ --piece-ring-width: var(--nox-focus-ring-width);
298
+ --piece-ring-color: var(--nox-source-tone-info);
299
+ }
300
+
301
+ .magnetic-field-puzzle__piece[data-piece-dragging] {
302
+ z-index: 6;
303
+ cursor: grabbing;
304
+ }
305
+
306
+ .magnetic-field-puzzle__piece[data-piece-dragging]
307
+ .magnetic-field-puzzle__piece-core {
308
+ transform: translate3d(var(--piece-drag-x, 0px), var(--piece-drag-y, 0px), 0)
309
+ scale(1.04);
310
+ transition: none;
311
+ will-change: transform;
312
+ }
313
+
314
+ .magnetic-field-puzzle__piece:focus-visible {
315
+ outline: none;
316
+ }
317
+
318
+ .magnetic-field-puzzle__piece:focus-visible .magnetic-field-puzzle__piece-core {
319
+ --piece-ring-width: var(--nox-focus-ring-width);
320
+ --piece-ring-color: var(--nox-source-tone-info);
321
+ }
322
+
323
+ @media (hover: hover) {
324
+ .magnetic-field-puzzle__piece:hover .magnetic-field-puzzle__piece-core {
325
+ --piece-interaction-overlay: color-mix(
326
+ in srgb,
327
+ var(--nox-tone-color) 10%,
328
+ transparent
329
+ );
330
+ }
331
+ }
332
+
333
+ .magnetic-field-puzzle__piece:active .magnetic-field-puzzle__piece-core {
334
+ --piece-interaction-overlay: color-mix(
335
+ in srgb,
336
+ var(--nox-tone-color) 16%,
337
+ transparent
338
+ );
339
+ }
340
+
341
+ @media (prefers-reduced-motion: no-preference) {
342
+ .magnetic-field-puzzle__piece[data-piece-moved] {
343
+ animation: magnetic-field-slide 260ms var(--nox-motion-easing-standard);
344
+ }
345
+
346
+ .magnetic-field-puzzle__path-chevron {
347
+ animation: magnetic-field-path var(--field-path-duration) linear infinite
348
+ both;
349
+ animation-delay: calc(var(--field-path-chevron-index) * -700ms);
350
+ }
351
+ }
352
+
353
+ @keyframes magnetic-field-slide {
354
+ from {
355
+ transform: translate3d(
356
+ var(--piece-move-inline-distance),
357
+ var(--piece-move-block-distance),
358
+ 0
359
+ );
360
+ }
361
+ }
362
+
363
+ @keyframes magnetic-field-path {
364
+ 0% {
365
+ inset-block-start: 50%;
366
+ inset-inline-start: 50%;
367
+ opacity: 0;
368
+ transform: translate(-50%, -50%) rotate(var(--field-path-rotation))
369
+ scale(0.9);
370
+ }
371
+
372
+ 12%,
373
+ 82% {
374
+ opacity: var(--field-path-chevron-opacity);
375
+ }
376
+
377
+ 100% {
378
+ inset-block-start: var(--field-path-target-block);
379
+ inset-inline-start: var(--field-path-target-inline);
380
+ opacity: 0;
381
+ transform: translate(-50%, -50%) rotate(var(--field-path-rotation)) scale(1);
382
+ }
383
+ }
@@ -0,0 +1,81 @@
1
+ export type MagneticFieldDirection = 'north' | 'east' | 'south' | 'west';
2
+ export type MagneticFieldPolarity = 'north' | 'south';
3
+ export type MagneticFieldPupilPosition = 'upper-end' | 'center' | 'lower-start';
4
+ export type MagneticFieldPuzzleStatus = 'incomplete' | 'valid';
5
+
6
+ export type MagneticFieldPosition = {
7
+ row: number;
8
+ column: number;
9
+ };
10
+
11
+ export type MagneticFieldPiece = MagneticFieldPosition & {
12
+ id: string;
13
+ label: string;
14
+ shortLabel: string;
15
+ polarity: MagneticFieldPolarity;
16
+ pupilPosition: MagneticFieldPupilPosition;
17
+ };
18
+
19
+ export type MagneticFieldTarget = MagneticFieldPosition & {
20
+ id: string;
21
+ label: string;
22
+ pieceId: string;
23
+ polarity: MagneticFieldPolarity;
24
+ };
25
+
26
+ export type MagneticFieldBlockedCell = MagneticFieldPosition & {
27
+ id: string;
28
+ label: string;
29
+ };
30
+
31
+ export type MagneticFieldInverter = MagneticFieldPosition & {
32
+ id: string;
33
+ label: string;
34
+ };
35
+
36
+ export type MagneticFieldMove = {
37
+ pieceId: string;
38
+ direction: MagneticFieldDirection;
39
+ };
40
+
41
+ export type MagneticFieldPuzzleModel = {
42
+ id: string;
43
+ label: string;
44
+ rows: number;
45
+ columns: number;
46
+ pieces: readonly MagneticFieldPiece[];
47
+ targets: readonly MagneticFieldTarget[];
48
+ blockedCells: readonly MagneticFieldBlockedCell[];
49
+ inverters: readonly MagneticFieldInverter[];
50
+ };
51
+
52
+ export type MagneticFieldPieceState = MagneticFieldPosition & {
53
+ polarity: MagneticFieldPolarity;
54
+ };
55
+
56
+ export type MagneticFieldPuzzleState = Readonly<
57
+ Record<string, MagneticFieldPieceState>
58
+ >;
59
+
60
+ export type MagneticFieldMovement = MagneticFieldMove & {
61
+ from: MagneticFieldPosition;
62
+ to: MagneticFieldPosition;
63
+ crossedInverterIds: readonly string[];
64
+ };
65
+
66
+ export type MagneticFieldSimulation = {
67
+ state: MagneticFieldPuzzleState;
68
+ movement: MagneticFieldMovement | null;
69
+ };
70
+
71
+ export type MagneticFieldPuzzleLabels = {
72
+ directions: Readonly<Record<MagneticFieldDirection, string>>;
73
+ polarities: Readonly<Record<MagneticFieldPolarity, string>>;
74
+ moveTemplate: string;
75
+ };
76
+
77
+ export type MagneticFieldPuzzleChangeDetail = {
78
+ kind: 'magnetic-field';
79
+ puzzleId: string;
80
+ state: MagneticFieldPuzzleState;
81
+ };