@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,319 @@
1
+ const initializedAttribute = 'data-table-progressive-initialized';
2
+
3
+ type ProgressiveState = 'idle' | 'loading' | 'error' | 'complete';
4
+
5
+ export type TableRowsAppendedDetail = {
6
+ rows: readonly HTMLElement[];
7
+ };
8
+
9
+ export function initTableProgressive(root: HTMLElement): () => void {
10
+ if (root.getAttribute(initializedAttribute) === 'true') {
11
+ return () => undefined;
12
+ }
13
+
14
+ const tableKey = root.dataset.tableKey;
15
+ const rowsRoot = root.querySelector<HTMLElement>('[data-table-rows]');
16
+ const pagination = root.querySelector<HTMLElement>('[data-table-pagination]');
17
+ const link = pagination?.querySelector<HTMLAnchorElement>(
18
+ '[data-table-pagination-link]',
19
+ );
20
+ const sentinel = pagination?.querySelector<HTMLElement>(
21
+ '[data-table-pagination-sentinel]',
22
+ );
23
+ const status = pagination?.querySelector<HTMLElement>(
24
+ '[data-table-pagination-status]',
25
+ );
26
+ const skeletonTemplate = pagination?.querySelector<HTMLTemplateElement>(
27
+ '[data-table-skeleton-template]',
28
+ );
29
+
30
+ if (
31
+ !tableKey ||
32
+ !rowsRoot ||
33
+ !pagination ||
34
+ !link ||
35
+ !sentinel ||
36
+ !status ||
37
+ !skeletonTemplate ||
38
+ !('IntersectionObserver' in window)
39
+ ) {
40
+ return () => undefined;
41
+ }
42
+
43
+ root.setAttribute(initializedAttribute, 'true');
44
+ const activePagination = pagination;
45
+ const activeLink = link;
46
+ const activeStatus = status;
47
+ activePagination.setAttribute('data-table-progressive-enhanced', 'true');
48
+ activePagination.removeAttribute('data-surface');
49
+ setState(activePagination, activeStatus, 'idle');
50
+
51
+ const loadedUrls = new Set<string>();
52
+ let request: AbortController | null = null;
53
+ let skeletonRows: HTMLElement[] = [];
54
+ let batchedRows: HTMLElement[] = [];
55
+ let disposed = false;
56
+ let completed = false;
57
+ let loadAllRequested = false;
58
+
59
+ const observer = new IntersectionObserver(
60
+ (entries) => {
61
+ if (entries.some((entry) => entry.isIntersecting)) {
62
+ void loadNextPage();
63
+ }
64
+ },
65
+ { rootMargin: '600px 0px' },
66
+ );
67
+
68
+ const removeSkeleton = (): void => {
69
+ skeletonRows.forEach((row) => row.remove());
70
+ skeletonRows = [];
71
+ };
72
+
73
+ const addSkeleton = (): void => {
74
+ if (skeletonRows.length > 0) return;
75
+
76
+ const templateRows = skeletonTemplate.content.querySelectorAll<HTMLElement>(
77
+ '[data-table-skeleton-row]',
78
+ );
79
+
80
+ skeletonRows = Array.from(templateRows, (row) =>
81
+ document.importNode(row, true),
82
+ );
83
+ rowsRoot.append(...skeletonRows);
84
+ };
85
+
86
+ const appendRows = (rows: readonly HTMLElement[]): void => {
87
+ if (rows.length === 0) return;
88
+
89
+ const fragment = document.createDocumentFragment();
90
+ for (const row of rows) fragment.append(row);
91
+ rowsRoot.append(fragment);
92
+ root.dispatchEvent(
93
+ new CustomEvent<TableRowsAppendedDetail>('table:rows-appended', {
94
+ bubbles: true,
95
+ detail: { rows },
96
+ }),
97
+ );
98
+ };
99
+
100
+ const flushBatchedRows = (): void => {
101
+ if (batchedRows.length === 0) {
102
+ removeSkeleton();
103
+ return;
104
+ }
105
+
106
+ const rows = batchedRows;
107
+ batchedRows = [];
108
+ removeSkeleton();
109
+ appendRows(rows);
110
+ };
111
+
112
+ const complete = (): void => {
113
+ completed = true;
114
+ flushBatchedRows();
115
+ loadAllRequested = false;
116
+ observer.disconnect();
117
+ activePagination.removeAttribute('data-surface');
118
+ activePagination.hidden = true;
119
+ setState(activePagination, activeStatus, 'complete');
120
+ root.removeAttribute('data-table-progressive-loading-all');
121
+ root.dispatchEvent(
122
+ new CustomEvent('table:progressive-complete', { bubbles: true }),
123
+ );
124
+ };
125
+
126
+ const showFallback = (): void => {
127
+ activePagination.removeAttribute('data-table-progressive-enhanced');
128
+ activePagination.setAttribute('data-surface', '');
129
+ };
130
+
131
+ async function loadNextPage(): Promise<void> {
132
+ if (request || disposed || completed) {
133
+ return;
134
+ }
135
+
136
+ const nextUrl = new URL(activeLink.href, window.location.href);
137
+ if (nextUrl.origin !== window.location.origin) {
138
+ setState(activePagination, activeStatus, 'error');
139
+ showFallback();
140
+ observer.disconnect();
141
+ return;
142
+ }
143
+
144
+ const requestKey = nextUrl.href;
145
+ if (loadedUrls.has(requestKey)) {
146
+ return;
147
+ }
148
+
149
+ request = new AbortController();
150
+ setState(activePagination, activeStatus, 'loading');
151
+ root.setAttribute('aria-busy', 'true');
152
+
153
+ let continueLoading = false;
154
+
155
+ try {
156
+ addSkeleton();
157
+ const response = await fetch(nextUrl, {
158
+ credentials: 'same-origin',
159
+ headers: { Accept: 'text/html' },
160
+ signal: request.signal,
161
+ });
162
+
163
+ if (!response.ok) {
164
+ throw new Error(`Unable to load table page: ${response.status}`);
165
+ }
166
+
167
+ const nextDocument = new DOMParser().parseFromString(
168
+ await response.text(),
169
+ 'text/html',
170
+ );
171
+ const nextTable = Array.from(
172
+ nextDocument.querySelectorAll<HTMLElement>('[data-table-key]'),
173
+ ).find((table) => table.dataset.tableKey === tableKey);
174
+ const nextRowsRoot =
175
+ nextTable?.querySelector<HTMLElement>('[data-table-rows]');
176
+
177
+ if (!nextTable || !nextRowsRoot) {
178
+ throw new Error(`Missing paginated table: ${tableKey}`);
179
+ }
180
+
181
+ const nextRows = Array.from(
182
+ nextRowsRoot.querySelectorAll<HTMLElement>(':scope > [data-table-row]'),
183
+ );
184
+ if (nextRows.length === 0) {
185
+ throw new Error(`Missing paginated table rows: ${tableKey}`);
186
+ }
187
+
188
+ const nextPagination = nextTable.querySelector<HTMLElement>(
189
+ '[data-table-pagination]',
190
+ );
191
+ const nextLink = nextPagination?.querySelector<HTMLAnchorElement>(
192
+ '[data-table-pagination-link]',
193
+ );
194
+
195
+ const importedRows = nextRows.map((row) =>
196
+ document.importNode(row, true),
197
+ );
198
+ if (loadAllRequested) {
199
+ batchedRows.push(...importedRows);
200
+ } else {
201
+ removeSkeleton();
202
+ appendRows(importedRows);
203
+ }
204
+ loadedUrls.add(requestKey);
205
+
206
+ if (!nextPagination || !nextLink) {
207
+ complete();
208
+ return;
209
+ }
210
+
211
+ const nextHref = nextLink.getAttribute('href');
212
+ if (!nextHref) {
213
+ complete();
214
+ return;
215
+ }
216
+
217
+ activeLink.href = nextHref;
218
+ copyDatasetValue(activePagination, nextPagination, 'tablePage');
219
+ copyDatasetValue(activePagination, nextPagination, 'tableTotalPages');
220
+ continueLoading = loadAllRequested;
221
+ if (!continueLoading) setState(activePagination, activeStatus, 'idle');
222
+ } catch (error) {
223
+ if (error instanceof DOMException && error.name === 'AbortError') {
224
+ return;
225
+ }
226
+ flushBatchedRows();
227
+ loadAllRequested = false;
228
+ root.removeAttribute('data-table-progressive-loading-all');
229
+ setState(activePagination, activeStatus, 'error');
230
+ showFallback();
231
+ observer.disconnect();
232
+ } finally {
233
+ request = null;
234
+ if (!loadAllRequested) root.removeAttribute('aria-busy');
235
+ if (continueLoading && !disposed) void loadNextPage();
236
+ }
237
+ }
238
+
239
+ const handleLoadAll = (): void => {
240
+ if (completed) return;
241
+ loadAllRequested = true;
242
+ root.setAttribute('data-table-progressive-loading-all', 'true');
243
+ void loadNextPage();
244
+ };
245
+
246
+ const handleClick = (event: MouseEvent): void => {
247
+ if (
248
+ event.defaultPrevented ||
249
+ event.button !== 0 ||
250
+ event.metaKey ||
251
+ event.ctrlKey ||
252
+ event.shiftKey ||
253
+ event.altKey
254
+ ) {
255
+ return;
256
+ }
257
+
258
+ if (activePagination.dataset.tableProgressiveState === 'error') {
259
+ return;
260
+ }
261
+
262
+ event.preventDefault();
263
+ observer.observe(sentinel);
264
+ void loadNextPage();
265
+ };
266
+
267
+ activeLink.addEventListener('click', handleClick);
268
+ root.addEventListener('table:load-all', handleLoadAll);
269
+ observer.observe(sentinel);
270
+
271
+ return () => {
272
+ disposed = true;
273
+ request?.abort();
274
+ observer.disconnect();
275
+ activeLink.removeEventListener('click', handleClick);
276
+ root.removeEventListener('table:load-all', handleLoadAll);
277
+ flushBatchedRows();
278
+ activePagination.hidden = false;
279
+ activePagination.setAttribute('data-surface', '');
280
+ activePagination.removeAttribute('data-table-progressive-enhanced');
281
+ activePagination.removeAttribute('data-table-progressive-state');
282
+ activeStatus.hidden = true;
283
+ activeStatus.textContent = '';
284
+ root.removeAttribute('data-table-progressive-loading-all');
285
+ root.removeAttribute('aria-busy');
286
+ root.removeAttribute(initializedAttribute);
287
+ };
288
+ }
289
+
290
+ function setState(
291
+ pagination: HTMLElement,
292
+ status: HTMLElement,
293
+ state: ProgressiveState,
294
+ ): void {
295
+ pagination.dataset.tableProgressiveState = state;
296
+ status.hidden = state !== 'loading' && state !== 'error';
297
+
298
+ if (state === 'loading') {
299
+ status.textContent = pagination.dataset.tableLoadingLabel ?? '';
300
+ } else if (state === 'error') {
301
+ status.textContent = pagination.dataset.tableErrorLabel ?? '';
302
+ } else {
303
+ status.textContent = '';
304
+ }
305
+ }
306
+
307
+ function copyDatasetValue(
308
+ target: HTMLElement,
309
+ source: HTMLElement,
310
+ key: 'tablePage' | 'tableTotalPages',
311
+ ): void {
312
+ const value = source.dataset[key];
313
+
314
+ if (value === undefined) {
315
+ delete target.dataset[key];
316
+ } else {
317
+ target.dataset[key] = value;
318
+ }
319
+ }
@@ -0,0 +1,91 @@
1
+ const interactiveSelector = [
2
+ 'a',
3
+ 'button',
4
+ 'input',
5
+ 'label',
6
+ 'select',
7
+ 'textarea',
8
+ 'summary',
9
+ '[role="button"]',
10
+ '[role="checkbox"]',
11
+ '[role="combobox"]',
12
+ '[role="link"]',
13
+ '[role="menuitem"]',
14
+ '[role="menuitemcheckbox"]',
15
+ '[role="menuitemradio"]',
16
+ '[role="option"]',
17
+ '[role="radio"]',
18
+ '[role="slider"]',
19
+ '[role="spinbutton"]',
20
+ '[role="switch"]',
21
+ '[role="tab"]',
22
+ '[role="textbox"]',
23
+ '[role="treeitem"]',
24
+ '[contenteditable="true"]',
25
+ ].join(',');
26
+
27
+ const initializedAttribute = 'data-table-row-navigation-initialized';
28
+
29
+ function isInteractiveTarget(target: EventTarget | null): boolean {
30
+ return (
31
+ target instanceof Element && Boolean(target.closest(interactiveSelector))
32
+ );
33
+ }
34
+
35
+ function getNavigationUrl(row: HTMLElement): string | undefined {
36
+ const link = row.querySelector<HTMLAnchorElement>(
37
+ '[data-table-row-primary-link]',
38
+ );
39
+
40
+ return link?.href ?? row.dataset.tableRowHref;
41
+ }
42
+
43
+ export function initTableRowNavigation(root: HTMLElement): () => void {
44
+ if (root.getAttribute(initializedAttribute) === 'true') {
45
+ return () => undefined;
46
+ }
47
+
48
+ root.setAttribute(initializedAttribute, 'true');
49
+
50
+ const handleClick = (event: MouseEvent): void => {
51
+ if (event.defaultPrevented || event.button !== 0) {
52
+ return;
53
+ }
54
+
55
+ if (isInteractiveTarget(event.target)) {
56
+ return;
57
+ }
58
+
59
+ const target = event.target;
60
+
61
+ if (!(target instanceof Element)) {
62
+ return;
63
+ }
64
+
65
+ const row = target.closest<HTMLElement>('[data-table-row-href]');
66
+
67
+ if (!row || !root.contains(row)) {
68
+ return;
69
+ }
70
+
71
+ const url = getNavigationUrl(row);
72
+
73
+ if (!url) {
74
+ return;
75
+ }
76
+
77
+ if (event.metaKey || event.ctrlKey) {
78
+ window.open(url, '_blank', 'noopener');
79
+ return;
80
+ }
81
+
82
+ window.location.assign(url);
83
+ };
84
+
85
+ root.addEventListener('click', handleClick);
86
+
87
+ return () => {
88
+ root.removeEventListener('click', handleClick);
89
+ root.removeAttribute(initializedAttribute);
90
+ };
91
+ }
@@ -0,0 +1,192 @@
1
+ const initializedAttribute = 'data-table-scroll-initialized';
2
+ const headerScrollportSelector = '[data-table-scrollport="header"]';
3
+ const bodyScrollportSelector = '[data-table-scrollport="body"]';
4
+ const bodyColumnGridSelector = '[data-table-column-grid]';
5
+ const headerColumnTemplateProperty = '--table-header-column-template';
6
+ const headerInlineSizeProperty = '--table-header-content-inline-size';
7
+
8
+ const noop = (): void => undefined;
9
+
10
+ export function initTableScroll(root: HTMLElement): () => void {
11
+ if (root.getAttribute(initializedAttribute) === 'true') {
12
+ return noop;
13
+ }
14
+
15
+ const headerScrollport = root.querySelector<HTMLElement>(
16
+ headerScrollportSelector,
17
+ );
18
+ const bodyScrollport = root.querySelector<HTMLElement>(
19
+ bodyScrollportSelector,
20
+ );
21
+
22
+ if (!headerScrollport || !bodyScrollport) {
23
+ return noop;
24
+ }
25
+
26
+ root.setAttribute(initializedAttribute, 'true');
27
+
28
+ const bodyColumnGrid =
29
+ bodyScrollport.querySelector<HTMLElement>(bodyColumnGridSelector);
30
+ const hasStableColumns = root.dataset.tableLayout === 'index';
31
+ let isActive = true;
32
+ let layoutFrame: number | null = null;
33
+ let scrollFrame: number | null = null;
34
+ let scrollSource: HTMLElement | null = null;
35
+ let expectedHeaderScrollLeft: number | null = null;
36
+ let expectedBodyScrollLeft: number | null = null;
37
+
38
+ const syncIndexOverflowState = (): void => {
39
+ if (!hasStableColumns) return;
40
+
41
+ const minimumRem = Number.parseFloat(
42
+ root.dataset.tableIndexMinimumRem ?? '',
43
+ );
44
+ const rootFontSize = Number.parseFloat(
45
+ window.getComputedStyle(document.documentElement).fontSize,
46
+ );
47
+ if (!Number.isFinite(minimumRem) || !Number.isFinite(rootFontSize)) {
48
+ return;
49
+ }
50
+
51
+ root.toggleAttribute(
52
+ 'data-table-index-overflow',
53
+ bodyScrollport.clientWidth + 0.5 < minimumRem * rootFontSize,
54
+ );
55
+ };
56
+
57
+ const syncScrollLeft = (source: HTMLElement, target: HTMLElement): void => {
58
+ if (Math.abs(target.scrollLeft - source.scrollLeft) >= 0.5) {
59
+ if (target === headerScrollport) {
60
+ expectedHeaderScrollLeft = source.scrollLeft;
61
+ } else {
62
+ expectedBodyScrollLeft = source.scrollLeft;
63
+ }
64
+ target.scrollLeft = source.scrollLeft;
65
+ }
66
+ };
67
+
68
+ const syncHeaderLayout = (): void => {
69
+ layoutFrame = null;
70
+
71
+ if (!bodyColumnGrid) {
72
+ return;
73
+ }
74
+
75
+ syncIndexOverflowState();
76
+ const inlineSize = bodyColumnGrid.getBoundingClientRect().width;
77
+ const columnTemplate =
78
+ window.getComputedStyle(bodyColumnGrid).gridTemplateColumns;
79
+
80
+ if (inlineSize <= 0 || columnTemplate === 'none') {
81
+ return;
82
+ }
83
+
84
+ root.style.setProperty(headerInlineSizeProperty, `${inlineSize}px`);
85
+ root.style.setProperty(headerColumnTemplateProperty, columnTemplate);
86
+ syncScrollLeft(bodyScrollport, headerScrollport);
87
+ };
88
+
89
+ const scheduleHeaderLayoutSync = (): void => {
90
+ if (layoutFrame !== null) {
91
+ return;
92
+ }
93
+
94
+ layoutFrame = window.requestAnimationFrame(syncHeaderLayout);
95
+ };
96
+
97
+ const flushScrollSync = (): void => {
98
+ scrollFrame = null;
99
+ const source = scrollSource;
100
+ scrollSource = null;
101
+ if (!source) return;
102
+
103
+ const target =
104
+ source === bodyScrollport ? headerScrollport : bodyScrollport;
105
+ syncScrollLeft(source, target);
106
+ };
107
+
108
+ const scheduleScrollSync = (source: HTMLElement): void => {
109
+ scrollSource = source;
110
+ if (scrollFrame === null) {
111
+ scrollFrame = window.requestAnimationFrame(flushScrollSync);
112
+ }
113
+ };
114
+
115
+ const handleHeaderScroll = (): void => {
116
+ if (
117
+ expectedHeaderScrollLeft !== null &&
118
+ Math.abs(headerScrollport.scrollLeft - expectedHeaderScrollLeft) < 0.5
119
+ ) {
120
+ expectedHeaderScrollLeft = null;
121
+ return;
122
+ }
123
+
124
+ expectedHeaderScrollLeft = null;
125
+ scheduleScrollSync(headerScrollport);
126
+ };
127
+
128
+ const handleBodyScroll = (): void => {
129
+ if (
130
+ expectedBodyScrollLeft !== null &&
131
+ Math.abs(bodyScrollport.scrollLeft - expectedBodyScrollLeft) < 0.5
132
+ ) {
133
+ expectedBodyScrollLeft = null;
134
+ return;
135
+ }
136
+
137
+ expectedBodyScrollLeft = null;
138
+ scheduleScrollSync(bodyScrollport);
139
+ };
140
+
141
+ headerScrollport.addEventListener('scroll', handleHeaderScroll, {
142
+ passive: true,
143
+ });
144
+ bodyScrollport.addEventListener('scroll', handleBodyScroll, {
145
+ passive: true,
146
+ });
147
+ syncIndexOverflowState();
148
+ syncScrollLeft(bodyScrollport, headerScrollport);
149
+
150
+ const resizeObserver =
151
+ bodyColumnGrid && 'ResizeObserver' in window
152
+ ? new ResizeObserver(scheduleHeaderLayoutSync)
153
+ : null;
154
+ if (bodyColumnGrid && !hasStableColumns) {
155
+ resizeObserver?.observe(bodyColumnGrid);
156
+ }
157
+ resizeObserver?.observe(bodyScrollport);
158
+
159
+ if (bodyColumnGrid) {
160
+ if (!hasStableColumns) {
161
+ root.addEventListener('table:rows-appended', scheduleHeaderLayoutSync);
162
+ }
163
+ scheduleHeaderLayoutSync();
164
+ if (!hasStableColumns) {
165
+ void document.fonts.ready.then(() => {
166
+ if (isActive) {
167
+ scheduleHeaderLayoutSync();
168
+ }
169
+ });
170
+ }
171
+ }
172
+
173
+ return () => {
174
+ isActive = false;
175
+ if (layoutFrame !== null) {
176
+ window.cancelAnimationFrame(layoutFrame);
177
+ }
178
+ if (scrollFrame !== null) {
179
+ window.cancelAnimationFrame(scrollFrame);
180
+ }
181
+ resizeObserver?.disconnect();
182
+ if (!hasStableColumns) {
183
+ root.removeEventListener('table:rows-appended', scheduleHeaderLayoutSync);
184
+ }
185
+ headerScrollport.removeEventListener('scroll', handleHeaderScroll);
186
+ bodyScrollport.removeEventListener('scroll', handleBodyScroll);
187
+ root.style.removeProperty(headerInlineSizeProperty);
188
+ root.style.removeProperty(headerColumnTemplateProperty);
189
+ root.removeAttribute('data-table-index-overflow');
190
+ root.removeAttribute(initializedAttribute);
191
+ };
192
+ }