@styleflow.app/flowpress-astro-core 1.0.0-beta.5 → 1.0.0-beta.50

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 (340) hide show
  1. package/CHANGELOG.md +307 -1
  2. package/README.md +121 -6
  3. package/dist/accessibility-panel.d.ts +2 -0
  4. package/dist/accessibility-panel.d.ts.map +1 -0
  5. package/dist/accessibility-panel.js +81 -0
  6. package/dist/accessibility-panel.js.map +1 -0
  7. package/dist/astro/BaseLayout.astro +34 -17
  8. package/dist/astro/CompositionRenderer.astro +170 -0
  9. package/dist/astro/DefaultBlockAdapter.astro +37 -0
  10. package/dist/astro/EditorialMedia.astro +47 -0
  11. package/dist/astro/FontStylesheets.astro +35 -0
  12. package/dist/astro/GutenbergRenderer.astro +270 -84
  13. package/dist/astro/Media.astro +27 -0
  14. package/dist/astro/StyleflowElement.astro +25 -0
  15. package/dist/astro/ThemeRuntime.astro +26 -0
  16. package/dist/astro/blocks/CarouselBlock.astro +72 -101
  17. package/dist/astro/blocks/CarouselItemBlock.astro +4 -4
  18. package/dist/astro/blocks/ColumnBlock.astro +4 -5
  19. package/dist/astro/blocks/CoverBlock.astro +158 -0
  20. package/dist/astro/blocks/FormBlock.astro +23 -20
  21. package/dist/astro/blocks/GridBlock.astro +5 -4
  22. package/dist/astro/blocks/HeroBlock.astro +6 -6
  23. package/dist/astro/blocks/ImageBlock.astro +6 -6
  24. package/dist/astro/blocks/ListItemFallback.astro +9 -7
  25. package/dist/astro/blocks/NumberSpinnerBlock.astro +29 -22
  26. package/dist/astro/blocks/SemanticElement.astro +35 -0
  27. package/dist/astro/blocks/SiteLogoBlock.astro +54 -0
  28. package/dist/astro/blocks/TextBlock.astro +33 -28
  29. package/dist/astro/blocks/ThemeToggleBlock.astro +13 -0
  30. package/dist/astro/blocks/cover.d.ts +13 -0
  31. package/dist/astro/blocks/cover.d.ts.map +1 -0
  32. package/dist/astro/blocks/cover.js +105 -0
  33. package/dist/astro/blocks/cover.js.map +1 -0
  34. package/dist/astro/blocks/cover.ts +119 -0
  35. package/dist/astro/blocks/helpers.d.ts +10 -1
  36. package/dist/astro/blocks/helpers.d.ts.map +1 -1
  37. package/dist/astro/blocks/helpers.js +55 -39
  38. package/dist/astro/blocks/helpers.js.map +1 -1
  39. package/dist/astro/blocks/helpers.ts +69 -44
  40. package/dist/astro/motion/AccordionRuntime.astro +9 -0
  41. package/dist/astro/motion/MotionBoot.astro +21 -0
  42. package/dist/astro/motion/MotionRuntime.astro +31 -0
  43. package/dist/astro/motion/accordion.css +163 -0
  44. package/dist/astro/motion/accordion.d.ts +3 -0
  45. package/dist/astro/motion/accordion.d.ts.map +1 -0
  46. package/dist/astro/motion/accordion.js +98 -0
  47. package/dist/astro/motion/accordion.js.map +1 -0
  48. package/dist/astro/motion/accordion.ts +109 -0
  49. package/dist/astro/motion/motion-controller.d.ts +12 -0
  50. package/dist/astro/motion/motion-controller.d.ts.map +1 -0
  51. package/dist/astro/motion/motion-controller.js +312 -0
  52. package/dist/astro/motion/motion-controller.js.map +1 -0
  53. package/dist/astro/motion/motion-controller.ts +393 -0
  54. package/dist/astro/motion/motion.css +600 -0
  55. package/dist/astro/motion/motion.d.ts +132 -0
  56. package/dist/astro/motion/motion.d.ts.map +1 -0
  57. package/dist/astro/motion/motion.js +265 -0
  58. package/dist/astro/motion/motion.js.map +1 -0
  59. package/dist/astro/motion/motion.ts +430 -0
  60. package/dist/astro/native/AccordionRuntime.astro +11 -0
  61. package/dist/astro/native/Blob.astro +113 -0
  62. package/dist/astro/native/BlobBlock.astro +52 -0
  63. package/dist/astro/native/CustomFieldValue.astro +88 -0
  64. package/dist/astro/native/LevelTag.astro +20 -0
  65. package/dist/astro/native/MapBlock.astro +41 -0
  66. package/dist/astro/native/NativeHtmlBlock.astro +12 -0
  67. package/dist/astro/native/NativeIconBlock.astro +42 -0
  68. package/dist/astro/native/ProjectTimelineBlock.astro +34 -0
  69. package/dist/astro/native/ReservedLogin.astro +107 -0
  70. package/dist/astro/native/ResolvedBlocks.astro +91 -0
  71. package/dist/astro/native/SyncedPatternContent.astro +94 -0
  72. package/dist/astro/native/TermFieldValue.astro +39 -0
  73. package/dist/astro/native/Timeline.astro +22 -0
  74. package/dist/astro/native/TimelineCardBlock.astro +7 -0
  75. package/dist/astro/native/accordion-controller.d.ts +3 -0
  76. package/dist/astro/native/accordion-controller.d.ts.map +1 -0
  77. package/dist/astro/native/accordion-controller.js +143 -0
  78. package/dist/astro/native/accordion-controller.js.map +1 -0
  79. package/dist/astro/native/accordion-controller.ts +108 -0
  80. package/dist/astro/native/accordion.css +36 -0
  81. package/dist/astro/native/accordion.d.ts +24 -0
  82. package/dist/astro/native/accordion.d.ts.map +1 -0
  83. package/dist/astro/native/accordion.js +82 -0
  84. package/dist/astro/native/accordion.js.map +1 -0
  85. package/dist/astro/native/accordion.ts +91 -0
  86. package/dist/astro/native/blob/blob-shapes.generated.d.ts +2 -0
  87. package/dist/astro/native/blob/blob-shapes.generated.d.ts.map +1 -0
  88. package/dist/astro/native/blob/blob-shapes.generated.js +2 -0
  89. package/dist/astro/native/blob/blob-shapes.generated.js.map +1 -0
  90. package/dist/astro/native/blob/blob-shapes.generated.ts +1 -0
  91. package/dist/astro/native/blob/config.d.ts +49 -0
  92. package/dist/astro/native/blob/config.d.ts.map +1 -0
  93. package/dist/astro/native/blob/config.js +86 -0
  94. package/dist/astro/native/blob/config.js.map +1 -0
  95. package/dist/astro/native/blob/config.ts +132 -0
  96. package/dist/astro/native/blob/controller.d.ts +11 -0
  97. package/dist/astro/native/blob/controller.d.ts.map +1 -0
  98. package/dist/astro/native/blob/controller.js +240 -0
  99. package/dist/astro/native/blob/controller.js.map +1 -0
  100. package/dist/astro/native/blob/controller.ts +248 -0
  101. package/dist/astro/native/blob/geometry.d.ts +2 -0
  102. package/dist/astro/native/blob/geometry.d.ts.map +1 -0
  103. package/dist/astro/native/blob/geometry.js +2 -0
  104. package/dist/astro/native/blob/geometry.js.map +1 -0
  105. package/dist/astro/native/blob/geometry.ts +1 -0
  106. package/dist/astro/native/blob/ids.d.ts +7 -0
  107. package/dist/astro/native/blob/ids.d.ts.map +1 -0
  108. package/dist/astro/native/blob/ids.js +11 -0
  109. package/dist/astro/native/blob/ids.js.map +1 -0
  110. package/dist/astro/native/blob/ids.ts +11 -0
  111. package/dist/astro/native/blob.css +83 -0
  112. package/dist/astro/native/block-sizing.css +34 -0
  113. package/dist/astro/native/button-template.d.ts +31 -0
  114. package/dist/astro/native/button-template.d.ts.map +1 -0
  115. package/dist/astro/native/button-template.js +54 -0
  116. package/dist/astro/native/button-template.js.map +1 -0
  117. package/dist/astro/native/button-template.ts +92 -0
  118. package/dist/astro/native/button.d.ts +13 -0
  119. package/dist/astro/native/button.d.ts.map +1 -0
  120. package/dist/astro/native/button.js +26 -0
  121. package/dist/astro/native/button.js.map +1 -0
  122. package/dist/astro/native/button.ts +26 -0
  123. package/dist/astro/native/carousel.css +323 -0
  124. package/dist/astro/native/core-accordion-heading.astro +23 -0
  125. package/dist/astro/native/core-accordion-item.astro +8 -0
  126. package/dist/astro/native/core-accordion-panel.astro +8 -0
  127. package/dist/astro/native/core-accordion.astro +8 -0
  128. package/dist/astro/native/core-block.astro +18 -0
  129. package/dist/astro/native/core-button-fallback.astro +43 -0
  130. package/dist/astro/native/core-button.astro +65 -0
  131. package/dist/astro/native/core-buttons.astro +14 -0
  132. package/dist/astro/native/core-group.astro +25 -0
  133. package/dist/astro/native/core-home-link.astro +12 -0
  134. package/dist/astro/native/core-html.astro +8 -0
  135. package/dist/astro/native/core-icon.astro +7 -0
  136. package/dist/astro/native/core-image.astro +136 -0
  137. package/dist/astro/native/core-navigation-link.astro +71 -0
  138. package/dist/astro/native/core-navigation-submenu.astro +33 -0
  139. package/dist/astro/native/core-navigation.astro +101 -0
  140. package/dist/astro/native/core-page-list-data-item.astro +19 -0
  141. package/dist/astro/native/core-page-list-item.astro +8 -0
  142. package/dist/astro/native/core-page-list.astro +40 -0
  143. package/dist/astro/native/core-post-date.astro +21 -0
  144. package/dist/astro/native/core-post-excerpt.astro +26 -0
  145. package/dist/astro/native/core-post-featured-image.astro +40 -0
  146. package/dist/astro/native/core-post-template-fallback.astro +30 -0
  147. package/dist/astro/native/core-post-template.astro +23 -0
  148. package/dist/astro/native/core-post-terms.astro +47 -0
  149. package/dist/astro/native/core-post-title.astro +23 -0
  150. package/dist/astro/native/core-query-no-results.astro +12 -0
  151. package/dist/astro/native/core-query.astro +22 -0
  152. package/dist/astro/native/core-separator.astro +18 -0
  153. package/dist/astro/native/core-site-title.astro +16 -0
  154. package/dist/astro/native/core-term-description.astro +12 -0
  155. package/dist/astro/native/core-term-name.astro +21 -0
  156. package/dist/astro/native/core-term-template.astro +30 -0
  157. package/dist/astro/native/core-terms-query.astro +19 -0
  158. package/dist/astro/native/core-transparent.astro +11 -0
  159. package/dist/astro/native/flowpress-navigation-controller.d.ts +2 -0
  160. package/dist/astro/native/flowpress-navigation-controller.d.ts.map +1 -0
  161. package/dist/astro/native/flowpress-navigation-controller.js +217 -0
  162. package/dist/astro/native/flowpress-navigation-controller.js.map +1 -0
  163. package/dist/astro/native/flowpress-navigation-controller.ts +215 -0
  164. package/dist/astro/native/flowpress-navigation.css +18 -0
  165. package/dist/astro/native/grid-bleed.d.ts +2 -0
  166. package/dist/astro/native/grid-bleed.d.ts.map +1 -0
  167. package/dist/astro/native/grid-bleed.js +123 -0
  168. package/dist/astro/native/grid-bleed.js.map +1 -0
  169. package/dist/astro/native/grid.css +180 -0
  170. package/dist/astro/native/grid.d.ts +17 -0
  171. package/dist/astro/native/grid.d.ts.map +1 -0
  172. package/dist/astro/native/grid.js +108 -0
  173. package/dist/astro/native/grid.js.map +1 -0
  174. package/dist/astro/native/grid.ts +132 -0
  175. package/dist/astro/native/group.css +36 -0
  176. package/dist/astro/native/group.d.ts +15 -0
  177. package/dist/astro/native/group.d.ts.map +1 -0
  178. package/dist/astro/native/group.js +66 -0
  179. package/dist/astro/native/group.js.map +1 -0
  180. package/dist/astro/native/group.ts +61 -0
  181. package/dist/astro/native/html.d.ts +6 -0
  182. package/dist/astro/native/html.d.ts.map +1 -0
  183. package/dist/astro/native/html.js +10 -0
  184. package/dist/astro/native/html.js.map +1 -0
  185. package/dist/astro/native/html.ts +9 -0
  186. package/dist/astro/native/icon.d.ts +3 -0
  187. package/dist/astro/native/icon.d.ts.map +1 -0
  188. package/dist/astro/native/icon.js +23 -0
  189. package/dist/astro/native/icon.js.map +1 -0
  190. package/dist/astro/native/icon.ts +21 -0
  191. package/dist/astro/native/image.d.ts +5 -0
  192. package/dist/astro/native/image.d.ts.map +1 -0
  193. package/dist/astro/native/image.js +65 -0
  194. package/dist/astro/native/image.js.map +1 -0
  195. package/dist/astro/native/image.ts +56 -0
  196. package/dist/astro/native/inline-text.css +15 -0
  197. package/dist/astro/native/map.d.ts +14 -0
  198. package/dist/astro/native/map.d.ts.map +1 -0
  199. package/dist/astro/native/map.js +60 -0
  200. package/dist/astro/native/map.js.map +1 -0
  201. package/dist/astro/native/map.ts +70 -0
  202. package/dist/astro/native/motion-preference.d.ts +50 -0
  203. package/dist/astro/native/motion-preference.d.ts.map +1 -0
  204. package/dist/astro/native/motion-preference.js +132 -0
  205. package/dist/astro/native/motion-preference.js.map +1 -0
  206. package/dist/astro/native/motion-preference.ts +158 -0
  207. package/dist/astro/native/motion.d.ts +101 -0
  208. package/dist/astro/native/motion.d.ts.map +1 -0
  209. package/dist/astro/native/motion.js +168 -0
  210. package/dist/astro/native/motion.js.map +1 -0
  211. package/dist/astro/native/motion.ts +312 -0
  212. package/dist/astro/native/query-carousel.d.ts +13 -0
  213. package/dist/astro/native/query-carousel.d.ts.map +1 -0
  214. package/dist/astro/native/query-carousel.js +36 -0
  215. package/dist/astro/native/query-carousel.js.map +1 -0
  216. package/dist/astro/native/query-carousel.ts +60 -0
  217. package/dist/astro/native/query-loop.d.ts +38 -0
  218. package/dist/astro/native/query-loop.d.ts.map +1 -0
  219. package/dist/astro/native/query-loop.js +20 -0
  220. package/dist/astro/native/query-loop.js.map +1 -0
  221. package/dist/astro/native/query-loop.ts +67 -0
  222. package/dist/astro/native/registry.d.ts +3 -0
  223. package/dist/astro/native/registry.d.ts.map +1 -0
  224. package/dist/astro/native/registry.js +91 -0
  225. package/dist/astro/native/registry.js.map +1 -0
  226. package/dist/astro/native/registry.ts +93 -0
  227. package/dist/astro/native/sf-block-binding.astro +20 -0
  228. package/dist/astro/native/sf-post-field.astro +9 -0
  229. package/dist/astro/native/sf-slot.astro +6 -0
  230. package/dist/astro/native/sf-term-field.astro +9 -0
  231. package/dist/astro/native/timeline.css +4 -0
  232. package/dist/astro/native/timeline.d.ts +28 -0
  233. package/dist/astro/native/timeline.d.ts.map +1 -0
  234. package/dist/astro/native/timeline.js +43 -0
  235. package/dist/astro/native/timeline.js.map +1 -0
  236. package/dist/astro/native/timeline.ts +79 -0
  237. package/dist/astro/preferences/AccessibilityPanel.astro +105 -0
  238. package/dist/astro/preferences/ColorModeToggle.astro +26 -0
  239. package/dist/astro/preferences/MotionToggle.astro +27 -0
  240. package/dist/astro/preferences/PreferencesRuntime.astro +9 -0
  241. package/dist/astro/preferences/ThemeToggle.astro +30 -0
  242. package/dist/astro/preferences/Toggle.astro +50 -0
  243. package/dist/astro/preferences/preferences.css +125 -0
  244. package/dist/block-renderers.d.ts +23 -3
  245. package/dist/block-renderers.d.ts.map +1 -1
  246. package/dist/block-renderers.js.map +1 -1
  247. package/dist/build-cache.d.ts +8 -0
  248. package/dist/build-cache.d.ts.map +1 -0
  249. package/dist/build-cache.js +82 -0
  250. package/dist/build-cache.js.map +1 -0
  251. package/dist/carousel.d.ts +56 -6
  252. package/dist/carousel.d.ts.map +1 -1
  253. package/dist/carousel.js +183 -27
  254. package/dist/carousel.js.map +1 -1
  255. package/dist/client.d.ts +34 -2
  256. package/dist/client.d.ts.map +1 -1
  257. package/dist/client.js +124 -42
  258. package/dist/client.js.map +1 -1
  259. package/dist/composition.d.ts +14 -0
  260. package/dist/composition.d.ts.map +1 -0
  261. package/dist/composition.js +125 -0
  262. package/dist/composition.js.map +1 -0
  263. package/dist/default-blocks.d.ts +9 -0
  264. package/dist/default-blocks.d.ts.map +1 -0
  265. package/dist/default-blocks.js +122 -0
  266. package/dist/default-blocks.js.map +1 -0
  267. package/dist/env.d.ts +21 -0
  268. package/dist/env.d.ts.map +1 -1
  269. package/dist/env.js +53 -0
  270. package/dist/env.js.map +1 -1
  271. package/dist/index.d.ts +7 -0
  272. package/dist/index.d.ts.map +1 -1
  273. package/dist/index.js +6 -0
  274. package/dist/index.js.map +1 -1
  275. package/dist/media.d.ts +20 -0
  276. package/dist/media.d.ts.map +1 -0
  277. package/dist/media.js +106 -0
  278. package/dist/media.js.map +1 -0
  279. package/dist/motion-preference.d.ts +50 -0
  280. package/dist/motion-preference.d.ts.map +1 -0
  281. package/dist/motion-preference.js +132 -0
  282. package/dist/motion-preference.js.map +1 -0
  283. package/dist/preferences-runtime.d.ts +3 -0
  284. package/dist/preferences-runtime.d.ts.map +1 -0
  285. package/dist/preferences-runtime.js +23 -0
  286. package/dist/preferences-runtime.js.map +1 -0
  287. package/dist/preferences-styleflow.d.ts +3 -0
  288. package/dist/preferences-styleflow.d.ts.map +1 -0
  289. package/dist/preferences-styleflow.js +14 -0
  290. package/dist/preferences-styleflow.js.map +1 -0
  291. package/dist/preferences.d.ts +4 -0
  292. package/dist/preferences.d.ts.map +1 -0
  293. package/dist/preferences.js +4 -0
  294. package/dist/preferences.js.map +1 -0
  295. package/dist/reserved-area.d.ts +10 -0
  296. package/dist/reserved-area.d.ts.map +1 -0
  297. package/dist/reserved-area.js +93 -0
  298. package/dist/reserved-area.js.map +1 -0
  299. package/dist/styleflow.d.ts +18 -1
  300. package/dist/styleflow.d.ts.map +1 -1
  301. package/dist/styleflow.js +82 -11
  302. package/dist/styleflow.js.map +1 -1
  303. package/dist/svg-media-runtime.d.ts +3 -0
  304. package/dist/svg-media-runtime.d.ts.map +1 -0
  305. package/dist/svg-media-runtime.js +33 -0
  306. package/dist/svg-media-runtime.js.map +1 -0
  307. package/dist/svg-media-types.d.ts +11 -0
  308. package/dist/svg-media-types.d.ts.map +1 -0
  309. package/dist/svg-media-types.js +2 -0
  310. package/dist/svg-media-types.js.map +1 -0
  311. package/dist/svg-media.d.ts +13 -0
  312. package/dist/svg-media.d.ts.map +1 -0
  313. package/dist/svg-media.js +47 -0
  314. package/dist/svg-media.js.map +1 -0
  315. package/dist/template-hierarchy.d.ts +0 -7
  316. package/dist/template-hierarchy.d.ts.map +1 -1
  317. package/dist/template-hierarchy.js +0 -21
  318. package/dist/template-hierarchy.js.map +1 -1
  319. package/dist/text.d.ts +3 -0
  320. package/dist/text.d.ts.map +1 -0
  321. package/dist/text.js +6 -0
  322. package/dist/text.js.map +1 -0
  323. package/dist/theme-runtime.d.ts +16 -0
  324. package/dist/theme-runtime.d.ts.map +1 -0
  325. package/dist/theme-runtime.js +100 -0
  326. package/dist/theme-runtime.js.map +1 -0
  327. package/dist/tsconfig.tsbuildinfo +1 -1
  328. package/dist/types.d.ts +75 -1
  329. package/dist/types.d.ts.map +1 -1
  330. package/dist/types.js.map +1 -1
  331. package/dist/vivid-colors-preference.d.ts +31 -0
  332. package/dist/vivid-colors-preference.d.ts.map +1 -0
  333. package/dist/vivid-colors-preference.js +102 -0
  334. package/dist/vivid-colors-preference.js.map +1 -0
  335. package/package.json +58 -7
  336. package/dist/astro/DefaultTemplate.astro +0 -42
  337. package/dist/templates.d.ts +0 -19
  338. package/dist/templates.d.ts.map +0 -1
  339. package/dist/templates.js +0 -20
  340. package/dist/templates.js.map +0 -1
@@ -0,0 +1,393 @@
1
+ import {
2
+ SF_MOTION_DISABLE_CLASS,
3
+ SF_MOTION_PROTECTED_CONTENT_SELECTOR,
4
+ SF_REVEAL_SKIP_CLASS,
5
+ SF_REVEAL_SELECTOR,
6
+ SF_REVEAL_STAGGER_SELECTOR,
7
+ automaticRevealClasses,
8
+ hasEnoughVisibleArea,
9
+ initialRevealState,
10
+ maximumTransitionTimeMs,
11
+ nextRevealState,
12
+ resolveSfMotionOptions,
13
+ ruleRevealClassChanges,
14
+ staggerRevealDelayMs,
15
+ shouldInitializeMotion,
16
+ type ResolvedSfMotionOptions,
17
+ type SfMotionOptions,
18
+ type SfRevealState,
19
+ } from "./motion.js";
20
+ import {
21
+ getMotionPreference,
22
+ subscribeMotionPreference,
23
+ type MotionPreference,
24
+ } from "../../motion-preference.js";
25
+
26
+ const REVEAL_STATE_ATTRIBUTE = "data-sf-reveal-state";
27
+ const REVEAL_THRESHOLDS = Array.from({ length: 41 }, (_, index) => index / 40);
28
+ const REVEAL_SETTLE_BUFFER_MS = 50;
29
+
30
+ function hashTarget(): HTMLElement | null {
31
+ if (!window.location.hash || window.location.hash === "#") return null;
32
+
33
+ try {
34
+ return document.getElementById(
35
+ decodeURIComponent(window.location.hash.slice(1)),
36
+ );
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
41
+
42
+ function containsTarget(
43
+ element: HTMLElement,
44
+ target: HTMLElement | null,
45
+ ): boolean {
46
+ return Boolean(target && (element === target || element.contains(target)));
47
+ }
48
+
49
+ function containsProtectedContent(element: HTMLElement): boolean {
50
+ return (
51
+ element.matches(SF_MOTION_PROTECTED_CONTENT_SELECTOR) ||
52
+ Boolean(element.querySelector(SF_MOTION_PROTECTED_CONTENT_SELECTOR))
53
+ );
54
+ }
55
+
56
+ function revealState(element: HTMLElement): SfRevealState {
57
+ const state = element.getAttribute(REVEAL_STATE_ATTRIBUTE);
58
+ if (state === "visible" || state === "settled") return state;
59
+ return "pending";
60
+ }
61
+
62
+ function isMotionDisabled(element: HTMLElement): boolean {
63
+ return Boolean(element.closest(`.${SF_MOTION_DISABLE_CLASS}, .${SF_REVEAL_SKIP_CLASS}`));
64
+ }
65
+
66
+ function selectElements(selector: string): NodeListOf<HTMLElement> | null {
67
+ try {
68
+ return document.querySelectorAll<HTMLElement>(selector);
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+
74
+ function inheritAutomaticReveals({
75
+ autoRevealSelectors,
76
+ defaultReveal,
77
+ revealRules,
78
+ }: ResolvedSfMotionOptions): void {
79
+ const ruleMatchedElements = new WeakSet<HTMLElement>();
80
+ revealRules.forEach(({ selector, reveal }) => {
81
+ selectElements(selector)?.forEach((element) => {
82
+ if (isMotionDisabled(element) || ruleMatchedElements.has(element)) return;
83
+
84
+ const classChanges = ruleRevealClassChanges(element.classList, reveal);
85
+ element.classList.remove(...classChanges.remove);
86
+ element.classList.add(...classChanges.add);
87
+ ruleMatchedElements.add(element);
88
+ });
89
+ });
90
+
91
+ if (defaultReveal === false) return;
92
+ autoRevealSelectors.forEach((selector) => {
93
+ selectElements(selector)?.forEach((element) => {
94
+ if (isMotionDisabled(element)) return;
95
+
96
+ element.classList.add(
97
+ ...automaticRevealClasses(element.classList, defaultReveal),
98
+ );
99
+ });
100
+ });
101
+ }
102
+
103
+ /**
104
+ * Assigns delay by participating reveal, not by direct-child position. A
105
+ * reveal belongs only to its nearest stagger group, so nested groups keep an
106
+ * autonomous sequence even through arbitrary Gutenberg wrappers.
107
+ */
108
+ function applyRevealStaggers(): void {
109
+ document
110
+ .querySelectorAll<HTMLElement>(SF_REVEAL_STAGGER_SELECTOR)
111
+ .forEach((group) => {
112
+ const owned = Array.from(
113
+ group.querySelectorAll<HTMLElement>(".sf-reveal"),
114
+ ).filter((element) => element.closest(SF_REVEAL_STAGGER_SELECTOR) === group);
115
+
116
+ owned.forEach((element) => {
117
+ element.style.removeProperty("--sf-reveal-delay");
118
+ });
119
+ owned
120
+ .filter((element) => (
121
+ !element.classList.contains("sf-motion-static") &&
122
+ !isMotionDisabled(element) &&
123
+ !containsProtectedContent(element)
124
+ ))
125
+ .forEach((element, index) => {
126
+ element.style.setProperty(
127
+ "--sf-reveal-delay",
128
+ `${staggerRevealDelayMs(index)}ms`,
129
+ );
130
+ });
131
+ });
132
+ }
133
+
134
+ /**
135
+ * Initializes the project reveal system once per document.
136
+ *
137
+ * Markup is visible by default. Initial-viewport content remains visible unless
138
+ * `revealAboveFold` explicitly opts it into motion; every reveal completes once.
139
+ * Reveals follow the shared motion preference (see `motion-preference.ts`):
140
+ * reduced motion shows everything at once, and allowing it again re-arms the
141
+ * reveals still below the fold without a reload.
142
+ */
143
+ export function initializeSfMotion(options: SfMotionOptions = {}): void {
144
+ const root = document.documentElement;
145
+ if (!shouldInitializeMotion(root.dataset.sfMotionInitialized)) return;
146
+ root.dataset.sfMotionInitialized = "true";
147
+
148
+ const resolvedOptions = resolveSfMotionOptions(options);
149
+ inheritAutomaticReveals(resolvedOptions);
150
+ applyRevealStaggers();
151
+
152
+ // Custom media classes may round the image instead of its block. Keep that
153
+ // authored edge on the stationary frame while the inner pixels zoom.
154
+ document.querySelectorAll<HTMLElement>(".sf-reveal--zoom-in [data-flowpress-media-frame]").forEach(frame => {
155
+ const media = frame.querySelector("img, svg");
156
+ if (!media) return;
157
+ const radius = window.getComputedStyle(media).borderRadius;
158
+ if (radius && !/^0px(?: 0px)*$/.test(radius)) frame.style.borderRadius = radius;
159
+ });
160
+
161
+ const revealElements = (): HTMLElement[] =>
162
+ Array.from(document.querySelectorAll<HTMLElement>(".sf-reveal"));
163
+ const revealAll = (): void => {
164
+ revealElements().forEach((element) => {
165
+ element.setAttribute(REVEAL_STATE_ATTRIBUTE, "settled");
166
+ });
167
+ };
168
+
169
+ const observed = new WeakSet<HTMLElement>();
170
+ const pending = new Set<HTMLElement>();
171
+ const settleTimers = new WeakMap<HTMLElement, number>();
172
+ let observer: IntersectionObserver | null = null;
173
+ let visibilityFrame = 0;
174
+
175
+ const settleReveal = (element: HTMLElement): void => {
176
+ const existingTimer = settleTimers.get(element);
177
+ if (existingTimer !== undefined) window.clearTimeout(existingTimer);
178
+
179
+ // Zoom animates the media inside an unmoving reveal box. Its transition,
180
+ // including stagger delay, must finish before entering `settled`.
181
+ const transitioning = element.classList.contains("sf-reveal--zoom-in")
182
+ ? [element, ...element.querySelectorAll<HTMLElement>("[data-flowpress-media-frame] > img, [data-flowpress-media-frame] > svg")]
183
+ : [element];
184
+ const transitionTime = Math.max(...transitioning.map(target => {
185
+ const styles = window.getComputedStyle(target);
186
+ return maximumTransitionTimeMs(styles.transitionDuration, styles.transitionDelay);
187
+ }));
188
+ const settle = (): void => {
189
+ if (revealState(element) === "visible") {
190
+ element.setAttribute(REVEAL_STATE_ATTRIBUTE, "settled");
191
+ }
192
+ settleTimers.delete(element);
193
+ };
194
+
195
+ if (transitionTime === 0) {
196
+ settle();
197
+ return;
198
+ }
199
+
200
+ settleTimers.set(
201
+ element,
202
+ window.setTimeout(settle, transitionTime + REVEAL_SETTLE_BUFFER_MS),
203
+ );
204
+ };
205
+
206
+ const revealOne = (
207
+ element: HTMLElement,
208
+ event: "focus" | "intersect",
209
+ ): void => {
210
+ const state = event === "focus" && element.classList.contains("sf-reveal--zoom-in")
211
+ ? "settled"
212
+ : nextRevealState(revealState(element), event);
213
+ element.setAttribute(REVEAL_STATE_ATTRIBUTE, state);
214
+ pending.delete(element);
215
+ if (state === "visible") settleReveal(element);
216
+ if (observed.has(element)) {
217
+ observer?.unobserve(element);
218
+ observed.delete(element);
219
+ }
220
+ };
221
+
222
+ /**
223
+ * A reveal's opacity/filter/clip-path apply only to itself, but those
224
+ * properties compose down the DOM: painted inside a still-pending ancestor,
225
+ * an element renders invisible regardless of its own state. Revealing an
226
+ * element therefore also reveals every pending `.sf-reveal` ancestor, so a
227
+ * nested reveal can never end up stuck under a hidden parent.
228
+ */
229
+ const reveal = (
230
+ element: HTMLElement,
231
+ event: "focus" | "intersect" = "focus",
232
+ ): void => {
233
+ revealOne(element, event);
234
+ let ancestor =
235
+ element.parentElement?.closest<HTMLElement>(SF_REVEAL_SELECTOR) ?? null;
236
+ while (ancestor) {
237
+ if (revealState(ancestor) === "pending") revealOne(ancestor, event);
238
+ ancestor =
239
+ ancestor.parentElement?.closest<HTMLElement>(SF_REVEAL_SELECTOR) ??
240
+ null;
241
+ }
242
+ };
243
+
244
+ /**
245
+ * A fully clipped reveal can intersect with a zero-area rectangle. Its first
246
+ * observer entry may arrive before 20% of its height is in view, and no more
247
+ * entries follow while that intersection ratio stays at zero. Check layout
248
+ * bounds on scroll as well so those reveals cannot remain pending in view.
249
+ */
250
+ const checkPendingVisibility = (): void => {
251
+ visibilityFrame = 0;
252
+ const ready: HTMLElement[] = [];
253
+ for (const element of pending) {
254
+ const bounds = element.getBoundingClientRect();
255
+ if (
256
+ bounds.width <= 0 ||
257
+ bounds.height <= 0 ||
258
+ bounds.right <= 0 ||
259
+ bounds.left >= window.innerWidth ||
260
+ !hasEnoughVisibleArea({
261
+ bottom: bounds.bottom,
262
+ height: bounds.height,
263
+ top: bounds.top,
264
+ viewportHeight: window.innerHeight,
265
+ })
266
+ ) {
267
+ continue;
268
+ }
269
+
270
+ ready.push(element);
271
+ }
272
+ ready.forEach((element) => {
273
+ if (pending.has(element)) reveal(element, "intersect");
274
+ });
275
+ };
276
+
277
+ const scheduleVisibilityCheck = (): void => {
278
+ if (pending.size === 0 || visibilityFrame !== 0) return;
279
+ visibilityFrame = window.requestAnimationFrame(checkPendingVisibility);
280
+ };
281
+
282
+ window.addEventListener("scroll", scheduleVisibilityCheck, { passive: true });
283
+ document.addEventListener("scroll", scheduleVisibilityCheck, {
284
+ capture: true,
285
+ passive: true,
286
+ });
287
+ window.addEventListener("resize", scheduleVisibilityCheck);
288
+
289
+ /** Motion reduced: every reveal is simply there, nothing is hidden or animated. */
290
+ const disarm = (): void => {
291
+ observer?.disconnect();
292
+ observer = null;
293
+ pending.clear();
294
+ revealAll();
295
+ root.dataset.sfMotion = "static";
296
+ };
297
+
298
+ /**
299
+ * Motion allowed: hide what is still below the fold and let it enter with the
300
+ * viewport. When motion is allowed again mid-visit (`initial` is false)
301
+ * everything already in view or behind stays put instead of replaying.
302
+ */
303
+ const arm = (initial: boolean): void => {
304
+ if (typeof window.IntersectionObserver !== "function") {
305
+ disarm();
306
+ return;
307
+ }
308
+
309
+ observer?.disconnect();
310
+ pending.clear();
311
+ const entering = new IntersectionObserver(
312
+ (entries) => {
313
+ entries.forEach((entry) => {
314
+ if (
315
+ !entry.isIntersecting ||
316
+ !(entry.target instanceof HTMLElement) ||
317
+ !hasEnoughVisibleArea({
318
+ bottom: entry.boundingClientRect.bottom,
319
+ height: entry.boundingClientRect.height,
320
+ top: entry.boundingClientRect.top,
321
+ viewportHeight: window.innerHeight,
322
+ })
323
+ ) {
324
+ return;
325
+ }
326
+
327
+ reveal(entry.target, "intersect");
328
+ });
329
+ },
330
+ {
331
+ rootMargin: "0px",
332
+ threshold: REVEAL_THRESHOLDS,
333
+ },
334
+ );
335
+ observer = entering;
336
+
337
+ const target = hashTarget();
338
+ document
339
+ .querySelectorAll<HTMLElement>(SF_REVEAL_SELECTOR)
340
+ .forEach((element) => {
341
+ if (isMotionDisabled(element)) return;
342
+
343
+ const bounds = element.getBoundingClientRect();
344
+ const state = !initial && bounds.top < window.innerHeight
345
+ ? "visible"
346
+ : initialRevealState({
347
+ bottom: bounds.bottom,
348
+ containsHashTarget: containsTarget(element, target),
349
+ protectedContent: containsProtectedContent(element),
350
+ reducedMotion: false,
351
+ revealAboveFold: resolvedOptions.revealAboveFold,
352
+ top: bounds.top,
353
+ viewportHeight: window.innerHeight,
354
+ });
355
+ element.setAttribute(
356
+ REVEAL_STATE_ATTRIBUTE,
357
+ state === "visible" ? "settled" : state,
358
+ );
359
+
360
+ if (state === "pending") {
361
+ observed.add(element);
362
+ pending.add(element);
363
+ entering.observe(element);
364
+ }
365
+ });
366
+
367
+ root.dataset.sfMotion = "ready";
368
+ scheduleVisibilityCheck();
369
+ };
370
+
371
+ let initial = true;
372
+ const applyPreference = (preference: MotionPreference): void => {
373
+ if (preference === "reduce") disarm();
374
+ else arm(initial);
375
+ initial = false;
376
+ };
377
+
378
+ document.addEventListener("focusin", (event) => {
379
+ if (!observer || !(event.target instanceof Element)) return;
380
+ const element = event.target.closest<HTMLElement>(SF_REVEAL_SELECTOR);
381
+ if (element && !isMotionDisabled(element)) reveal(element);
382
+ });
383
+
384
+ window.addEventListener("hashchange", () => {
385
+ if (!observer) return;
386
+ const targetElement = hashTarget();
387
+ const element = targetElement?.closest<HTMLElement>(SF_REVEAL_SELECTOR);
388
+ if (element && !isMotionDisabled(element)) reveal(element);
389
+ });
390
+
391
+ applyPreference(getMotionPreference());
392
+ subscribeMotionPreference(applyPreference);
393
+ }