@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,74 @@
1
+ ---
2
+ import SeoHead from '../components/seo/SeoHead.astro';
3
+ import type { HTMLAttributes } from 'astro/types';
4
+ import type { BreadcrumbItem } from '../display/contracts';
5
+ import type { PageMeta } from '../config/pageMeta';
6
+ import type { SiteConfig } from '../config/siteConfig';
7
+ import type { JsonLdNode } from '../seo/structuredData';
8
+ import type { Tone } from '../theme/contracts';
9
+ import PageSurface from './PageSurface.astro';
10
+ import Breadcrumbs from '../components/navigation/Breadcrumbs/Breadcrumbs.astro';
11
+ import ScrollToTop from '../components/actions/ScrollToTop/ScrollToTop.astro';
12
+
13
+ type Props = HTMLAttributes<'html'> & {
14
+ meta: PageMeta;
15
+ site: SiteConfig;
16
+ currentPath?: string;
17
+ breadcrumbs?: readonly BreadcrumbItem[];
18
+ breadcrumbLabel: string;
19
+ scrollToTopLabel?: string;
20
+ structuredData?: readonly JsonLdNode[];
21
+ tone?: Tone;
22
+ };
23
+
24
+ const {
25
+ breadcrumbLabel,
26
+ breadcrumbs,
27
+ currentPath = Astro.url.pathname,
28
+ 'data-tone': dataTone,
29
+ meta,
30
+ scrollToTopLabel,
31
+ site,
32
+ structuredData,
33
+ tone,
34
+ ...htmlAttrs
35
+ } = Astro.props;
36
+ const lang = meta.lang ?? site.defaultMeta.lang;
37
+ const resolvedTone = tone ?? dataTone;
38
+ ---
39
+
40
+ <!doctype html>
41
+ <html {...htmlAttrs} lang={lang} data-tone={resolvedTone}>
42
+ <head>
43
+ <meta charset="utf-8" />
44
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
45
+ <SeoHead
46
+ breadcrumbs={breadcrumbs}
47
+ meta={meta}
48
+ pathname={currentPath}
49
+ site={site}
50
+ structuredData={structuredData}
51
+ />
52
+ <slot name="head" />
53
+ </head>
54
+ <body>
55
+ <slot name="skip-link" />
56
+ <slot name="header" />
57
+ <div class="site-viewport" data-site-viewport>
58
+ <main id="content" class="site-main" tabindex="-1">
59
+ <div class="site-main__content">
60
+ {
61
+ breadcrumbs?.length ? (
62
+ <Breadcrumbs items={breadcrumbs} label={breadcrumbLabel} />
63
+ ) : null
64
+ }
65
+
66
+ <PageSurface>
67
+ <slot />
68
+ </PageSurface>
69
+ </div>
70
+ </main>
71
+ </div>
72
+ {scrollToTopLabel ? <ScrollToTop label={scrollToTopLabel} /> : null}
73
+ </body>
74
+ </html>
@@ -0,0 +1,15 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types';
3
+
4
+ type Props = HTMLAttributes<'div'>;
5
+
6
+ const { class: className, ...attrs }: Props = Astro.props;
7
+ ---
8
+
9
+ <div
10
+ {...attrs}
11
+ class:list={['page-surface', className]}
12
+ data-layout="page-surface"
13
+ >
14
+ <slot />
15
+ </div>
@@ -0,0 +1,24 @@
1
+ .page-surface {
2
+ display: grid;
3
+ align-content: start;
4
+ width: 100%;
5
+ min-width: 0;
6
+ padding: var(--nox-page-surface-padding);
7
+ gap: var(--nox-space-5);
8
+ border: var(--nox-border-width) solid var(--nox-border);
9
+ border-radius: var(--nox-radius-lg);
10
+ background: transparent;
11
+ box-shadow: 0 1rem 2.5rem
12
+ color-mix(in srgb, var(--nox-tone-shadow) 4.5%, transparent);
13
+ }
14
+
15
+ @media (width < 48rem) {
16
+ .page-surface {
17
+ width: calc(100% + var(--nox-page-gutter) + var(--nox-page-gutter));
18
+ margin-inline: calc(0px - var(--nox-page-gutter));
19
+ border-inline-width: 0;
20
+ border-block-end-width: 0;
21
+ border-radius: 0;
22
+ box-shadow: none;
23
+ }
24
+ }
@@ -0,0 +1,2 @@
1
+ export { default as BaseLayout } from './BaseLayout.astro';
2
+ export { default as PageSurface } from './PageSurface.astro';
@@ -0,0 +1,93 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types';
3
+ import PuzzleGrid from '../PuzzleGrid/PuzzleGrid.astro';
4
+ import type { CircuitPuzzleLabels, CircuitPuzzleModel } from './contracts';
5
+
6
+ type Props = HTMLAttributes<'section'> & {
7
+ label: string;
8
+ labels: CircuitPuzzleLabels;
9
+ puzzles: readonly CircuitPuzzleModel[];
10
+ };
11
+
12
+ const {
13
+ class: className,
14
+ label,
15
+ labels,
16
+ puzzles,
17
+ ...attrs
18
+ }: Props = Astro.props;
19
+ ---
20
+
21
+ <section
22
+ {...attrs}
23
+ class:list={['circuit-puzzle', className]}
24
+ aria-label={label}
25
+ data-circuit-puzzle
26
+ >
27
+ {
28
+ puzzles.map((puzzle, puzzleIndex) => (
29
+ <div
30
+ class="circuit-puzzle__instance"
31
+ data-puzzle-id={puzzle.id}
32
+ data-puzzle-status="incomplete"
33
+ hidden={puzzleIndex !== 0}
34
+ >
35
+ <PuzzleGrid
36
+ class="circuit-puzzle__board"
37
+ label={puzzle.label}
38
+ rows={puzzle.rows}
39
+ columns={puzzle.columns}
40
+ >
41
+ {puzzle.cells.map((cell, cellIndex) => {
42
+ const cellLabel = [
43
+ labels.cellKinds[cell.kind],
44
+ `${labels.row} ${cell.row + 1}`,
45
+ `${labels.column} ${cell.column + 1}`,
46
+ ].join(', ');
47
+
48
+ return (
49
+ <button
50
+ class="puzzle-grid__cell circuit-puzzle__cell"
51
+ type="button"
52
+ aria-label={`${cellLabel} — ${labels.orientation} ${cell.initialRotation}°`}
53
+ data-puzzle-cell
54
+ data-puzzle-cell-interactive={cell.fixed ? undefined : ''}
55
+ data-puzzle-cell-disabled={cell.fixed ? '' : undefined}
56
+ data-circuit-cell={cell.id}
57
+ data-cell-kind={cell.kind}
58
+ data-cell-label={cellLabel}
59
+ data-orientation-label={labels.orientation}
60
+ data-cell-rotation={cell.initialRotation}
61
+ data-cell-visual-rotation={cell.initialRotation}
62
+ data-initial-rotation={cell.initialRotation}
63
+ data-cell-fixed={cell.fixed ? '' : undefined}
64
+ disabled={cell.fixed ? true : undefined}
65
+ style={`--cell-row: ${cell.row + 1}; --cell-column: ${cell.column + 1}; --cell-rotation: ${cell.initialRotation}deg; --cell-index: ${cellIndex};`}
66
+ >
67
+ <span class="circuit-puzzle__piece" aria-hidden="true">
68
+ {cell.connections.map((direction) => (
69
+ <span
70
+ class:list={[
71
+ 'circuit-puzzle__trace',
72
+ `circuit-puzzle__trace--${direction}`,
73
+ ]}
74
+ />
75
+ ))}
76
+ <span class="circuit-puzzle__node" />
77
+ </span>
78
+ </button>
79
+ );
80
+ })}
81
+ </PuzzleGrid>
82
+ </div>
83
+ ))
84
+ }
85
+ </section>
86
+
87
+ <script>
88
+ import { initCircuitPuzzle } from './circuitPuzzleController';
89
+
90
+ for (const root of document.querySelectorAll('[data-circuit-puzzle]')) {
91
+ if (root instanceof HTMLElement) initCircuitPuzzle(root);
92
+ }
93
+ </script>
@@ -0,0 +1,118 @@
1
+ .circuit-puzzle,
2
+ .circuit-puzzle__instance {
3
+ display: grid;
4
+ min-inline-size: 0;
5
+ }
6
+
7
+ .circuit-puzzle__instance[hidden] {
8
+ display: none;
9
+ }
10
+
11
+ .circuit-puzzle__cell {
12
+ --circuit-puzzle-symbol-color: var(--puzzle-cell-base-color);
13
+
14
+ appearance: none;
15
+ }
16
+
17
+ .circuit-puzzle__cell[data-cell-kind='core'] {
18
+ --puzzle-cell-base-border: var(--nox-source-tone-success);
19
+ --circuit-puzzle-symbol-color: var(--nox-source-tone-success);
20
+
21
+ border-style: dashed;
22
+ }
23
+
24
+ .circuit-puzzle__cell[data-puzzle-cell-state='valid'],
25
+ .circuit-puzzle__cell[data-puzzle-cell-state='invalid'] {
26
+ --puzzle-cell-state-background: var(--puzzle-cell-base-background);
27
+ --puzzle-cell-state-border: var(--puzzle-cell-base-border);
28
+ --puzzle-cell-state-color: var(--puzzle-cell-base-color);
29
+ }
30
+
31
+ .circuit-puzzle__cell[data-puzzle-cell-state='valid'] {
32
+ --circuit-puzzle-symbol-color: var(--nox-source-tone-success);
33
+ }
34
+
35
+ .circuit-puzzle__cell[data-puzzle-cell-state='invalid'] {
36
+ --circuit-puzzle-symbol-color: var(--nox-source-tone-danger);
37
+ }
38
+
39
+ .circuit-puzzle__piece {
40
+ position: relative;
41
+ display: grid;
42
+ inline-size: 72%;
43
+ block-size: 72%;
44
+ place-items: center;
45
+ transform: rotate(var(--cell-rotation));
46
+ color: var(--circuit-puzzle-symbol-color);
47
+ }
48
+
49
+ .circuit-puzzle__node {
50
+ z-index: 1;
51
+ inline-size: 32%;
52
+ block-size: 32%;
53
+ border: var(--nox-border-width) solid currentColor;
54
+ border-radius: var(--nox-radius-pill);
55
+ background: var(--nox-surface);
56
+ }
57
+
58
+ .circuit-puzzle__trace {
59
+ position: absolute;
60
+ background: currentColor;
61
+ }
62
+
63
+ .circuit-puzzle__trace--north,
64
+ .circuit-puzzle__trace--south {
65
+ inset-inline-start: 50%;
66
+ inline-size: 12%;
67
+ block-size: 50%;
68
+ transform: translateX(-50%);
69
+ }
70
+
71
+ .circuit-puzzle__trace--north {
72
+ inset-block-start: 0;
73
+ }
74
+
75
+ .circuit-puzzle__trace--south {
76
+ inset-block-end: 0;
77
+ }
78
+
79
+ .circuit-puzzle__trace--east,
80
+ .circuit-puzzle__trace--west {
81
+ inset-block-start: 50%;
82
+ inline-size: 50%;
83
+ block-size: 12%;
84
+ transform: translateY(-50%);
85
+ }
86
+
87
+ .circuit-puzzle__trace--east {
88
+ inset-inline-end: 0;
89
+ }
90
+
91
+ .circuit-puzzle__trace--west {
92
+ inset-inline-start: 0;
93
+ }
94
+
95
+ @media (prefers-reduced-motion: no-preference) {
96
+ .circuit-puzzle__piece {
97
+ transition: transform var(--nox-motion-duration-sm)
98
+ var(--nox-motion-easing-standard);
99
+ }
100
+
101
+ .circuit-puzzle__instance[data-puzzle-resetting] .circuit-puzzle__piece {
102
+ transition: none;
103
+ }
104
+
105
+ .circuit-puzzle__instance[data-puzzle-status='valid']
106
+ .circuit-puzzle__cell[data-puzzle-cell-state='valid']
107
+ .circuit-puzzle__piece {
108
+ animation: circuit-puzzle-power 600ms var(--nox-motion-easing-standard);
109
+ animation-delay: calc(var(--cell-index) * 24ms);
110
+ }
111
+ }
112
+
113
+ @keyframes circuit-puzzle-power {
114
+ 50% {
115
+ filter: drop-shadow(0 0 var(--nox-space-2) var(--nox-source-tone-success));
116
+ transform: rotate(var(--cell-rotation)) scale(1.08);
117
+ }
118
+ }
@@ -0,0 +1,205 @@
1
+ import {
2
+ setPuzzleGridCellState,
3
+ setPuzzleGridState,
4
+ } from '../PuzzleGrid/state';
5
+ import { initPuzzleSelectionDismissal } from '../PuzzleGrid/selectionDismissal';
6
+ import type {
7
+ CircuitPuzzleChangeDetail,
8
+ CircuitPuzzleEvaluation,
9
+ CircuitRotation,
10
+ } from './contracts';
11
+
12
+ type CircuitInstance = {
13
+ activeIndex: number;
14
+ };
15
+
16
+ const rotations: readonly CircuitRotation[] = [0, 90, 180, 270];
17
+ const instances = new WeakMap<HTMLElement, CircuitInstance>();
18
+
19
+ export function initCircuitPuzzle(root: HTMLElement): void {
20
+ if (instances.has(root)) return;
21
+ instances.set(root, { activeIndex: 0 });
22
+ initPuzzleSelectionDismissal(root, {
23
+ dismiss: () => {
24
+ const panel = getActivePanel(root);
25
+ if (panel) selectCell(panel, null);
26
+ },
27
+ isSelectionTarget: (target) => {
28
+ const panel = getActivePanel(root);
29
+ const cell = target.closest<HTMLElement>('[data-circuit-cell]');
30
+ return Boolean(
31
+ panel &&
32
+ panel.dataset.puzzleStatus !== 'valid' &&
33
+ cell &&
34
+ panel.contains(cell) &&
35
+ !cell.hasAttribute('data-cell-fixed'),
36
+ );
37
+ },
38
+ });
39
+
40
+ root.addEventListener('click', (event) => {
41
+ const target = event.target;
42
+ if (!(target instanceof Element)) return;
43
+
44
+ const cell = target.closest<HTMLButtonElement>('[data-circuit-cell]');
45
+ const panel = getActivePanel(root);
46
+ if (
47
+ !cell ||
48
+ !panel ||
49
+ panel.dataset.puzzleStatus === 'valid' ||
50
+ cell.hasAttribute('data-cell-fixed')
51
+ ) {
52
+ return;
53
+ }
54
+
55
+ const current = Number(cell.dataset.cellRotation) as CircuitRotation;
56
+ const currentIndex = rotations.indexOf(current);
57
+ const nextIndex = (currentIndex + 1) % rotations.length;
58
+ const visualRotation = Number(cell.dataset.cellVisualRotation ?? current);
59
+ selectCell(panel, cell);
60
+ setRotation(cell, rotations[nextIndex], visualRotation + 90);
61
+ emitChange(root);
62
+ });
63
+ }
64
+
65
+ export function selectCircuitPuzzle(root: HTMLElement, index: number): void {
66
+ initCircuitPuzzle(root);
67
+ const panels = getPanels(root);
68
+ const selectedIndex = Math.max(0, Math.min(index, panels.length - 1));
69
+ const instance = instances.get(root);
70
+ if (instance) instance.activeIndex = selectedIndex;
71
+
72
+ panels.forEach((panel, panelIndex) => {
73
+ panel.hidden = panelIndex !== selectedIndex;
74
+ });
75
+ resetCircuitPuzzle(root);
76
+ }
77
+
78
+ export function resetCircuitPuzzle(root: HTMLElement): void {
79
+ initCircuitPuzzle(root);
80
+ const panel = getActivePanel(root);
81
+ if (!panel) return;
82
+
83
+ panel.dataset.puzzleStatus = 'incomplete';
84
+ const grid = panel.querySelector<HTMLElement>('[data-puzzle-grid]');
85
+ if (grid) setPuzzleGridState(grid, null);
86
+
87
+ panel.setAttribute('data-puzzle-resetting', '');
88
+ for (const cell of panel.querySelectorAll<HTMLButtonElement>(
89
+ '[data-circuit-cell]',
90
+ )) {
91
+ const initialRotation = Number(
92
+ cell.dataset.initialRotation,
93
+ ) as CircuitRotation;
94
+ setRotation(cell, initialRotation, initialRotation);
95
+ setPuzzleGridCellState(cell, null);
96
+ cell.removeAttribute('data-puzzle-cell-selected');
97
+ }
98
+ requestAnimationFrame(() => {
99
+ requestAnimationFrame(() => {
100
+ panel.removeAttribute('data-puzzle-resetting');
101
+ });
102
+ });
103
+ emitChange(root);
104
+ }
105
+
106
+ export function setCircuitPuzzleEvaluation(
107
+ root: HTMLElement,
108
+ puzzleId: string,
109
+ evaluation: CircuitPuzzleEvaluation,
110
+ ): void {
111
+ const panel = getPanels(root).find(
112
+ (candidate) => candidate.dataset.puzzleId === puzzleId,
113
+ );
114
+ if (!panel) return;
115
+
116
+ const previous = panel.dataset.puzzleStatus;
117
+ panel.dataset.puzzleStatus = evaluation.status;
118
+ const energized = new Set(evaluation.energizedCellIds);
119
+ const invalid = new Set(evaluation.invalidCellIds);
120
+
121
+ for (const cell of panel.querySelectorAll<HTMLElement>(
122
+ '[data-circuit-cell]',
123
+ )) {
124
+ const cellId = cell.dataset.circuitCell ?? '';
125
+ setPuzzleGridCellState(
126
+ cell,
127
+ invalid.has(cellId) ? 'invalid' : energized.has(cellId) ? 'valid' : null,
128
+ );
129
+ }
130
+
131
+ const grid = panel.querySelector<HTMLElement>('[data-puzzle-grid]');
132
+ if (grid) {
133
+ setPuzzleGridState(grid, evaluation.status === 'valid' ? 'valid' : null);
134
+ }
135
+
136
+ if (evaluation.status === 'valid' && previous !== 'valid') {
137
+ root.dispatchEvent(
138
+ new CustomEvent('puzzle:complete', {
139
+ bubbles: true,
140
+ detail: { kind: 'circuit', puzzleId },
141
+ }),
142
+ );
143
+ }
144
+ }
145
+
146
+ function setRotation(
147
+ cell: HTMLButtonElement,
148
+ rotation: CircuitRotation,
149
+ visualRotation: number,
150
+ ): void {
151
+ cell.dataset.cellRotation = String(rotation);
152
+ cell.dataset.cellVisualRotation = String(visualRotation);
153
+ cell.style.setProperty('--cell-rotation', `${visualRotation}deg`);
154
+ const cellLabel = cell.dataset.cellLabel ?? '';
155
+ const orientationLabel = cell.dataset.orientationLabel ?? '';
156
+ cell.setAttribute(
157
+ 'aria-label',
158
+ `${cellLabel} — ${orientationLabel} ${rotation}°`,
159
+ );
160
+ }
161
+
162
+ function selectCell(
163
+ panel: HTMLElement,
164
+ selectedCell: HTMLButtonElement | null,
165
+ ): void {
166
+ for (const cell of panel.querySelectorAll<HTMLElement>(
167
+ '[data-circuit-cell]',
168
+ )) {
169
+ cell.toggleAttribute('data-puzzle-cell-selected', cell === selectedCell);
170
+ }
171
+ }
172
+
173
+ function emitChange(root: HTMLElement): void {
174
+ const panel = getActivePanel(root);
175
+ if (!panel?.dataset.puzzleId) return;
176
+
177
+ const rotationsByCell = Object.fromEntries(
178
+ [...panel.querySelectorAll<HTMLButtonElement>('[data-circuit-cell]')].map(
179
+ (cell) => [
180
+ cell.dataset.circuitCell ?? '',
181
+ Number(cell.dataset.cellRotation) as CircuitRotation,
182
+ ],
183
+ ),
184
+ );
185
+ const detail: CircuitPuzzleChangeDetail = {
186
+ kind: 'circuit',
187
+ puzzleId: panel.dataset.puzzleId,
188
+ rotations: rotationsByCell,
189
+ };
190
+ root.dispatchEvent(
191
+ new CustomEvent<CircuitPuzzleChangeDetail>('puzzle:change', {
192
+ bubbles: true,
193
+ detail,
194
+ }),
195
+ );
196
+ }
197
+
198
+ function getPanels(root: HTMLElement): HTMLElement[] {
199
+ return [...root.querySelectorAll<HTMLElement>(':scope > [data-puzzle-id]')];
200
+ }
201
+
202
+ function getActivePanel(root: HTMLElement): HTMLElement | undefined {
203
+ const index = instances.get(root)?.activeIndex ?? 0;
204
+ return getPanels(root)[index];
205
+ }
@@ -0,0 +1,42 @@
1
+ export type CircuitDirection = 'north' | 'east' | 'south' | 'west';
2
+ export type CircuitRotation = 0 | 90 | 180 | 270;
3
+ export type CircuitPuzzleStatus = 'incomplete' | 'contradictory' | 'valid';
4
+
5
+ export type CircuitCellKind = 'core' | 'wire' | 'module' | 'defense';
6
+
7
+ export type CircuitPuzzleCell = {
8
+ id: string;
9
+ row: number;
10
+ column: number;
11
+ kind: CircuitCellKind;
12
+ connections: readonly CircuitDirection[];
13
+ initialRotation: CircuitRotation;
14
+ fixed?: boolean;
15
+ };
16
+
17
+ export type CircuitPuzzleModel = {
18
+ id: string;
19
+ label: string;
20
+ rows: number;
21
+ columns: number;
22
+ cells: readonly CircuitPuzzleCell[];
23
+ };
24
+
25
+ export type CircuitPuzzleLabels = {
26
+ cellKinds: Readonly<Record<CircuitCellKind, string>>;
27
+ column: string;
28
+ orientation: string;
29
+ row: string;
30
+ };
31
+
32
+ export type CircuitPuzzleChangeDetail = {
33
+ kind: 'circuit';
34
+ puzzleId: string;
35
+ rotations: Readonly<Record<string, CircuitRotation>>;
36
+ };
37
+
38
+ export type CircuitPuzzleEvaluation = {
39
+ status: CircuitPuzzleStatus;
40
+ energizedCellIds: readonly string[];
41
+ invalidCellIds: readonly string[];
42
+ };