@styleflow.app/flowpress-astro-core 1.0.0-beta.4 → 1.0.0-beta.41

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 (317) hide show
  1. package/CHANGELOG.md +249 -1
  2. package/README.md +104 -5
  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 +168 -0
  9. package/dist/astro/DefaultBlockAdapter.astro +37 -0
  10. package/dist/astro/FontStylesheets.astro +35 -0
  11. package/dist/astro/GutenbergRenderer.astro +267 -80
  12. package/dist/astro/Media.astro +27 -0
  13. package/dist/astro/StyleflowElement.astro +25 -0
  14. package/dist/astro/ThemeRuntime.astro +26 -0
  15. package/dist/astro/blocks/CarouselBlock.astro +11 -10
  16. package/dist/astro/blocks/CarouselItemBlock.astro +4 -4
  17. package/dist/astro/blocks/ColumnBlock.astro +4 -5
  18. package/dist/astro/blocks/CoverBlock.astro +158 -0
  19. package/dist/astro/blocks/FormBlock.astro +23 -20
  20. package/dist/astro/blocks/GridBlock.astro +5 -4
  21. package/dist/astro/blocks/HeroBlock.astro +6 -6
  22. package/dist/astro/blocks/ImageBlock.astro +6 -6
  23. package/dist/astro/blocks/ListItemFallback.astro +9 -7
  24. package/dist/astro/blocks/NumberSpinnerBlock.astro +29 -22
  25. package/dist/astro/blocks/SemanticElement.astro +35 -0
  26. package/dist/astro/blocks/SiteLogoBlock.astro +54 -0
  27. package/dist/astro/blocks/TextBlock.astro +33 -28
  28. package/dist/astro/blocks/ThemeToggleBlock.astro +13 -0
  29. package/dist/astro/blocks/cover.d.ts +13 -0
  30. package/dist/astro/blocks/cover.d.ts.map +1 -0
  31. package/dist/astro/blocks/cover.js +105 -0
  32. package/dist/astro/blocks/cover.js.map +1 -0
  33. package/dist/astro/blocks/cover.ts +119 -0
  34. package/dist/astro/blocks/helpers.d.ts +10 -1
  35. package/dist/astro/blocks/helpers.d.ts.map +1 -1
  36. package/dist/astro/blocks/helpers.js +55 -39
  37. package/dist/astro/blocks/helpers.js.map +1 -1
  38. package/dist/astro/blocks/helpers.ts +69 -44
  39. package/dist/astro/motion/AccordionRuntime.astro +9 -0
  40. package/dist/astro/motion/MotionBoot.astro +21 -0
  41. package/dist/astro/motion/MotionRuntime.astro +31 -0
  42. package/dist/astro/motion/accordion.css +163 -0
  43. package/dist/astro/motion/accordion.d.ts +3 -0
  44. package/dist/astro/motion/accordion.d.ts.map +1 -0
  45. package/dist/astro/motion/accordion.js +98 -0
  46. package/dist/astro/motion/accordion.js.map +1 -0
  47. package/dist/astro/motion/accordion.ts +109 -0
  48. package/dist/astro/motion/motion-controller.d.ts +12 -0
  49. package/dist/astro/motion/motion-controller.d.ts.map +1 -0
  50. package/dist/astro/motion/motion-controller.js +293 -0
  51. package/dist/astro/motion/motion-controller.js.map +1 -0
  52. package/dist/astro/motion/motion-controller.ts +377 -0
  53. package/dist/astro/motion/motion.css +546 -0
  54. package/dist/astro/motion/motion.d.ts +127 -0
  55. package/dist/astro/motion/motion.d.ts.map +1 -0
  56. package/dist/astro/motion/motion.js +255 -0
  57. package/dist/astro/motion/motion.js.map +1 -0
  58. package/dist/astro/motion/motion.ts +419 -0
  59. package/dist/astro/native/Blob.astro +113 -0
  60. package/dist/astro/native/BlobBlock.astro +52 -0
  61. package/dist/astro/native/CustomFieldValue.astro +88 -0
  62. package/dist/astro/native/LevelTag.astro +20 -0
  63. package/dist/astro/native/MapBlock.astro +41 -0
  64. package/dist/astro/native/NativeHtmlBlock.astro +12 -0
  65. package/dist/astro/native/NativeIconBlock.astro +42 -0
  66. package/dist/astro/native/ProjectTimelineBlock.astro +34 -0
  67. package/dist/astro/native/ReservedLogin.astro +107 -0
  68. package/dist/astro/native/ResolvedBlocks.astro +91 -0
  69. package/dist/astro/native/SyncedPatternContent.astro +94 -0
  70. package/dist/astro/native/TermFieldValue.astro +39 -0
  71. package/dist/astro/native/Timeline.astro +22 -0
  72. package/dist/astro/native/TimelineCardBlock.astro +7 -0
  73. package/dist/astro/native/blob/blob-shapes.generated.d.ts +2 -0
  74. package/dist/astro/native/blob/blob-shapes.generated.d.ts.map +1 -0
  75. package/dist/astro/native/blob/blob-shapes.generated.js +2 -0
  76. package/dist/astro/native/blob/blob-shapes.generated.js.map +1 -0
  77. package/dist/astro/native/blob/blob-shapes.generated.ts +1 -0
  78. package/dist/astro/native/blob/config.d.ts +49 -0
  79. package/dist/astro/native/blob/config.d.ts.map +1 -0
  80. package/dist/astro/native/blob/config.js +86 -0
  81. package/dist/astro/native/blob/config.js.map +1 -0
  82. package/dist/astro/native/blob/config.ts +132 -0
  83. package/dist/astro/native/blob/controller.d.ts +11 -0
  84. package/dist/astro/native/blob/controller.d.ts.map +1 -0
  85. package/dist/astro/native/blob/controller.js +240 -0
  86. package/dist/astro/native/blob/controller.js.map +1 -0
  87. package/dist/astro/native/blob/controller.ts +248 -0
  88. package/dist/astro/native/blob/geometry.d.ts +2 -0
  89. package/dist/astro/native/blob/geometry.d.ts.map +1 -0
  90. package/dist/astro/native/blob/geometry.js +2 -0
  91. package/dist/astro/native/blob/geometry.js.map +1 -0
  92. package/dist/astro/native/blob/geometry.ts +1 -0
  93. package/dist/astro/native/blob/ids.d.ts +7 -0
  94. package/dist/astro/native/blob/ids.d.ts.map +1 -0
  95. package/dist/astro/native/blob/ids.js +11 -0
  96. package/dist/astro/native/blob/ids.js.map +1 -0
  97. package/dist/astro/native/blob/ids.ts +11 -0
  98. package/dist/astro/native/blob.css +83 -0
  99. package/dist/astro/native/block-sizing.css +34 -0
  100. package/dist/astro/native/button-template.d.ts +31 -0
  101. package/dist/astro/native/button-template.d.ts.map +1 -0
  102. package/dist/astro/native/button-template.js +54 -0
  103. package/dist/astro/native/button-template.js.map +1 -0
  104. package/dist/astro/native/button-template.ts +92 -0
  105. package/dist/astro/native/button.d.ts +13 -0
  106. package/dist/astro/native/button.d.ts.map +1 -0
  107. package/dist/astro/native/button.js +26 -0
  108. package/dist/astro/native/button.js.map +1 -0
  109. package/dist/astro/native/button.ts +26 -0
  110. package/dist/astro/native/core-block.astro +18 -0
  111. package/dist/astro/native/core-button-fallback.astro +43 -0
  112. package/dist/astro/native/core-button.astro +65 -0
  113. package/dist/astro/native/core-buttons.astro +14 -0
  114. package/dist/astro/native/core-group.astro +25 -0
  115. package/dist/astro/native/core-home-link.astro +12 -0
  116. package/dist/astro/native/core-html.astro +8 -0
  117. package/dist/astro/native/core-icon.astro +7 -0
  118. package/dist/astro/native/core-image.astro +137 -0
  119. package/dist/astro/native/core-navigation-link.astro +71 -0
  120. package/dist/astro/native/core-navigation-submenu.astro +33 -0
  121. package/dist/astro/native/core-navigation.astro +101 -0
  122. package/dist/astro/native/core-page-list-data-item.astro +19 -0
  123. package/dist/astro/native/core-page-list-item.astro +8 -0
  124. package/dist/astro/native/core-page-list.astro +40 -0
  125. package/dist/astro/native/core-post-date.astro +21 -0
  126. package/dist/astro/native/core-post-excerpt.astro +26 -0
  127. package/dist/astro/native/core-post-featured-image.astro +40 -0
  128. package/dist/astro/native/core-post-template-fallback.astro +30 -0
  129. package/dist/astro/native/core-post-template.astro +23 -0
  130. package/dist/astro/native/core-post-terms.astro +47 -0
  131. package/dist/astro/native/core-post-title.astro +23 -0
  132. package/dist/astro/native/core-query-no-results.astro +12 -0
  133. package/dist/astro/native/core-query.astro +22 -0
  134. package/dist/astro/native/core-separator.astro +18 -0
  135. package/dist/astro/native/core-site-title.astro +16 -0
  136. package/dist/astro/native/core-term-description.astro +12 -0
  137. package/dist/astro/native/core-term-name.astro +21 -0
  138. package/dist/astro/native/core-term-template.astro +30 -0
  139. package/dist/astro/native/core-terms-query.astro +19 -0
  140. package/dist/astro/native/core-transparent.astro +11 -0
  141. package/dist/astro/native/flowpress-navigation-controller.d.ts +2 -0
  142. package/dist/astro/native/flowpress-navigation-controller.d.ts.map +1 -0
  143. package/dist/astro/native/flowpress-navigation-controller.js +217 -0
  144. package/dist/astro/native/flowpress-navigation-controller.js.map +1 -0
  145. package/dist/astro/native/flowpress-navigation-controller.ts +215 -0
  146. package/dist/astro/native/flowpress-navigation.css +17 -0
  147. package/dist/astro/native/grid-bleed.d.ts +2 -0
  148. package/dist/astro/native/grid-bleed.d.ts.map +1 -0
  149. package/dist/astro/native/grid-bleed.js +123 -0
  150. package/dist/astro/native/grid-bleed.js.map +1 -0
  151. package/dist/astro/native/grid.css +180 -0
  152. package/dist/astro/native/grid.d.ts +17 -0
  153. package/dist/astro/native/grid.d.ts.map +1 -0
  154. package/dist/astro/native/grid.js +103 -0
  155. package/dist/astro/native/grid.js.map +1 -0
  156. package/dist/astro/native/grid.ts +118 -0
  157. package/dist/astro/native/group.css +36 -0
  158. package/dist/astro/native/group.d.ts +15 -0
  159. package/dist/astro/native/group.d.ts.map +1 -0
  160. package/dist/astro/native/group.js +66 -0
  161. package/dist/astro/native/group.js.map +1 -0
  162. package/dist/astro/native/group.ts +61 -0
  163. package/dist/astro/native/html.d.ts +6 -0
  164. package/dist/astro/native/html.d.ts.map +1 -0
  165. package/dist/astro/native/html.js +10 -0
  166. package/dist/astro/native/html.js.map +1 -0
  167. package/dist/astro/native/html.ts +9 -0
  168. package/dist/astro/native/icon.d.ts +3 -0
  169. package/dist/astro/native/icon.d.ts.map +1 -0
  170. package/dist/astro/native/icon.js +23 -0
  171. package/dist/astro/native/icon.js.map +1 -0
  172. package/dist/astro/native/icon.ts +21 -0
  173. package/dist/astro/native/image.d.ts +5 -0
  174. package/dist/astro/native/image.d.ts.map +1 -0
  175. package/dist/astro/native/image.js +65 -0
  176. package/dist/astro/native/image.js.map +1 -0
  177. package/dist/astro/native/image.ts +56 -0
  178. package/dist/astro/native/inline-text.css +15 -0
  179. package/dist/astro/native/map.d.ts +14 -0
  180. package/dist/astro/native/map.d.ts.map +1 -0
  181. package/dist/astro/native/map.js +60 -0
  182. package/dist/astro/native/map.js.map +1 -0
  183. package/dist/astro/native/map.ts +70 -0
  184. package/dist/astro/native/motion-preference.d.ts +50 -0
  185. package/dist/astro/native/motion-preference.d.ts.map +1 -0
  186. package/dist/astro/native/motion-preference.js +132 -0
  187. package/dist/astro/native/motion-preference.js.map +1 -0
  188. package/dist/astro/native/motion-preference.ts +158 -0
  189. package/dist/astro/native/motion.d.ts +101 -0
  190. package/dist/astro/native/motion.d.ts.map +1 -0
  191. package/dist/astro/native/motion.js +168 -0
  192. package/dist/astro/native/motion.js.map +1 -0
  193. package/dist/astro/native/motion.ts +312 -0
  194. package/dist/astro/native/query-carousel.d.ts +12 -0
  195. package/dist/astro/native/query-carousel.d.ts.map +1 -0
  196. package/dist/astro/native/query-carousel.js +36 -0
  197. package/dist/astro/native/query-carousel.js.map +1 -0
  198. package/dist/astro/native/query-carousel.ts +56 -0
  199. package/dist/astro/native/query-loop.d.ts +38 -0
  200. package/dist/astro/native/query-loop.d.ts.map +1 -0
  201. package/dist/astro/native/query-loop.js +20 -0
  202. package/dist/astro/native/query-loop.js.map +1 -0
  203. package/dist/astro/native/query-loop.ts +67 -0
  204. package/dist/astro/native/registry.d.ts +3 -0
  205. package/dist/astro/native/registry.d.ts.map +1 -0
  206. package/dist/astro/native/registry.js +81 -0
  207. package/dist/astro/native/registry.js.map +1 -0
  208. package/dist/astro/native/registry.ts +82 -0
  209. package/dist/astro/native/sf-block-binding.astro +20 -0
  210. package/dist/astro/native/sf-post-field.astro +9 -0
  211. package/dist/astro/native/sf-term-field.astro +9 -0
  212. package/dist/astro/native/timeline.css +4 -0
  213. package/dist/astro/native/timeline.d.ts +28 -0
  214. package/dist/astro/native/timeline.d.ts.map +1 -0
  215. package/dist/astro/native/timeline.js +43 -0
  216. package/dist/astro/native/timeline.js.map +1 -0
  217. package/dist/astro/native/timeline.ts +79 -0
  218. package/dist/astro/preferences/AccessibilityPanel.astro +105 -0
  219. package/dist/astro/preferences/ColorModeToggle.astro +26 -0
  220. package/dist/astro/preferences/MotionToggle.astro +27 -0
  221. package/dist/astro/preferences/PreferencesRuntime.astro +9 -0
  222. package/dist/astro/preferences/ThemeToggle.astro +30 -0
  223. package/dist/astro/preferences/Toggle.astro +50 -0
  224. package/dist/astro/preferences/preferences.css +125 -0
  225. package/dist/block-renderers.d.ts +23 -3
  226. package/dist/block-renderers.d.ts.map +1 -1
  227. package/dist/block-renderers.js.map +1 -1
  228. package/dist/build-cache.d.ts +8 -0
  229. package/dist/build-cache.d.ts.map +1 -0
  230. package/dist/build-cache.js +81 -0
  231. package/dist/build-cache.js.map +1 -0
  232. package/dist/client.d.ts +23 -2
  233. package/dist/client.d.ts.map +1 -1
  234. package/dist/client.js +78 -39
  235. package/dist/client.js.map +1 -1
  236. package/dist/composition.d.ts +14 -0
  237. package/dist/composition.d.ts.map +1 -0
  238. package/dist/composition.js +125 -0
  239. package/dist/composition.js.map +1 -0
  240. package/dist/default-blocks.d.ts +9 -0
  241. package/dist/default-blocks.d.ts.map +1 -0
  242. package/dist/default-blocks.js +117 -0
  243. package/dist/default-blocks.js.map +1 -0
  244. package/dist/env.d.ts +9 -0
  245. package/dist/env.d.ts.map +1 -1
  246. package/dist/env.js +20 -0
  247. package/dist/env.js.map +1 -1
  248. package/dist/index.d.ts +7 -0
  249. package/dist/index.d.ts.map +1 -1
  250. package/dist/index.js +6 -0
  251. package/dist/index.js.map +1 -1
  252. package/dist/media.d.ts +20 -0
  253. package/dist/media.d.ts.map +1 -0
  254. package/dist/media.js +106 -0
  255. package/dist/media.js.map +1 -0
  256. package/dist/motion-preference.d.ts +50 -0
  257. package/dist/motion-preference.d.ts.map +1 -0
  258. package/dist/motion-preference.js +132 -0
  259. package/dist/motion-preference.js.map +1 -0
  260. package/dist/preferences-runtime.d.ts +3 -0
  261. package/dist/preferences-runtime.d.ts.map +1 -0
  262. package/dist/preferences-runtime.js +23 -0
  263. package/dist/preferences-runtime.js.map +1 -0
  264. package/dist/preferences-styleflow.d.ts +3 -0
  265. package/dist/preferences-styleflow.d.ts.map +1 -0
  266. package/dist/preferences-styleflow.js +14 -0
  267. package/dist/preferences-styleflow.js.map +1 -0
  268. package/dist/preferences.d.ts +4 -0
  269. package/dist/preferences.d.ts.map +1 -0
  270. package/dist/preferences.js +4 -0
  271. package/dist/preferences.js.map +1 -0
  272. package/dist/reserved-area.d.ts +10 -0
  273. package/dist/reserved-area.d.ts.map +1 -0
  274. package/dist/reserved-area.js +93 -0
  275. package/dist/reserved-area.js.map +1 -0
  276. package/dist/styleflow.d.ts +18 -1
  277. package/dist/styleflow.d.ts.map +1 -1
  278. package/dist/styleflow.js +82 -11
  279. package/dist/styleflow.js.map +1 -1
  280. package/dist/svg-media-runtime.d.ts +3 -0
  281. package/dist/svg-media-runtime.d.ts.map +1 -0
  282. package/dist/svg-media-runtime.js +33 -0
  283. package/dist/svg-media-runtime.js.map +1 -0
  284. package/dist/svg-media-types.d.ts +11 -0
  285. package/dist/svg-media-types.d.ts.map +1 -0
  286. package/dist/svg-media-types.js +2 -0
  287. package/dist/svg-media-types.js.map +1 -0
  288. package/dist/svg-media.d.ts +13 -0
  289. package/dist/svg-media.d.ts.map +1 -0
  290. package/dist/svg-media.js +47 -0
  291. package/dist/svg-media.js.map +1 -0
  292. package/dist/template-hierarchy.d.ts +0 -7
  293. package/dist/template-hierarchy.d.ts.map +1 -1
  294. package/dist/template-hierarchy.js +0 -21
  295. package/dist/template-hierarchy.js.map +1 -1
  296. package/dist/text.d.ts +3 -0
  297. package/dist/text.d.ts.map +1 -0
  298. package/dist/text.js +6 -0
  299. package/dist/text.js.map +1 -0
  300. package/dist/theme-runtime.d.ts +16 -0
  301. package/dist/theme-runtime.d.ts.map +1 -0
  302. package/dist/theme-runtime.js +100 -0
  303. package/dist/theme-runtime.js.map +1 -0
  304. package/dist/tsconfig.tsbuildinfo +1 -1
  305. package/dist/types.d.ts +75 -1
  306. package/dist/types.d.ts.map +1 -1
  307. package/dist/types.js.map +1 -1
  308. package/dist/vivid-colors-preference.d.ts +31 -0
  309. package/dist/vivid-colors-preference.d.ts.map +1 -0
  310. package/dist/vivid-colors-preference.js +102 -0
  311. package/dist/vivid-colors-preference.js.map +1 -0
  312. package/package.json +58 -7
  313. package/dist/astro/DefaultTemplate.astro +0 -42
  314. package/dist/templates.d.ts +0 -19
  315. package/dist/templates.d.ts.map +0 -1
  316. package/dist/templates.js +0 -20
  317. package/dist/templates.js.map +0 -1
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Single source of truth for "may this page animate?".
3
+ *
4
+ * The default follows the OS (`prefers-reduced-motion`). A visitor's explicit
5
+ * choice from the accessibility panel wins in both directions and is stored in
6
+ * localStorage. The resolved value is mirrored on
7
+ * `<html data-sf-motion-preference="full|reduce">`, so CSS and scripts read the
8
+ * same state, and every change is announced with `sf:motion-change`.
9
+ *
10
+ * Do not read `matchMedia("(prefers-reduced-motion)")` or write a bare
11
+ * `@media (prefers-reduced-motion)` rule elsewhere: neither can be overridden
12
+ * by the visitor.
13
+ */
14
+ export const MOTION_STORAGE_KEY = "sf:motion";
15
+ export const MOTION_ATTRIBUTE = "data-sf-motion-preference";
16
+ export const MOTION_CHANGE_EVENT = "sf:motion-change";
17
+ export const MOTION_TOGGLE_SELECTOR = "[data-sf-motion-toggle]";
18
+ export const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
19
+ export function isMotionPreference(value) {
20
+ return value === "full" || value === "reduce";
21
+ }
22
+ /** An explicit choice beats the OS; without one the OS decides. */
23
+ export function resolveMotionPreference(stored, systemReduces) {
24
+ if (isMotionPreference(stored))
25
+ return stored;
26
+ return systemReduces ? "reduce" : "full";
27
+ }
28
+ /**
29
+ * Inline script for `<head>`: mirrors the resolved preference on `<html>`
30
+ * before first paint, so nothing starts animating and then snaps to a stop.
31
+ */
32
+ export function motionPreferenceBootstrapScript() {
33
+ const key = JSON.stringify(MOTION_STORAGE_KEY);
34
+ const query = JSON.stringify(REDUCED_MOTION_QUERY);
35
+ const attribute = JSON.stringify(MOTION_ATTRIBUTE);
36
+ return `(()=>{let s=null,r=false;try{s=localStorage.getItem(${key})}catch{}try{r=matchMedia(${query}).matches}catch{}document.documentElement.setAttribute(${attribute},s==="full"||s==="reduce"?s:r?"reduce":"full")})()`;
37
+ }
38
+ export function browserMotionEnvironment() {
39
+ let storage = null;
40
+ try {
41
+ storage = localStorage;
42
+ }
43
+ catch {
44
+ // Blocked storage keeps the preference in memory for the page only.
45
+ }
46
+ return {
47
+ document,
48
+ storage,
49
+ media: typeof matchMedia === "function" ? matchMedia(REDUCED_MOTION_QUERY) : null,
50
+ };
51
+ }
52
+ function readStored(env) {
53
+ try {
54
+ return env.storage?.getItem(MOTION_STORAGE_KEY) ?? null;
55
+ }
56
+ catch {
57
+ return null;
58
+ }
59
+ }
60
+ function mirrored(env) {
61
+ const value = env.document.documentElement.getAttribute(MOTION_ATTRIBUTE);
62
+ return isMotionPreference(value) ? value : null;
63
+ }
64
+ /** The mirrored value when the bootstrap ran, otherwise resolved from storage and OS. */
65
+ export function getMotionPreference(env = browserMotionEnvironment()) {
66
+ return mirrored(env) ?? resolveMotionPreference(readStored(env), env.media?.matches ?? false);
67
+ }
68
+ function apply(preference, env) {
69
+ if (mirrored(env) === preference)
70
+ return;
71
+ env.document.documentElement.setAttribute(MOTION_ATTRIBUTE, preference);
72
+ env.document.dispatchEvent(new CustomEvent(MOTION_CHANGE_EVENT, { detail: { preference } }));
73
+ }
74
+ /** Store an explicit choice and announce it. */
75
+ export function setMotionPreference(preference, env = browserMotionEnvironment()) {
76
+ try {
77
+ env.storage?.setItem(MOTION_STORAGE_KEY, preference);
78
+ }
79
+ catch {
80
+ // The choice still applies to this page.
81
+ }
82
+ apply(preference, env);
83
+ }
84
+ /**
85
+ * Call `listener` whenever the effective preference changes: an explicit
86
+ * choice, or the OS setting while the visitor has not made one.
87
+ */
88
+ export function subscribeMotionPreference(listener, env = browserMotionEnvironment()) {
89
+ const onChange = (event) => {
90
+ const preference = event.detail?.preference;
91
+ if (isMotionPreference(preference))
92
+ listener(preference);
93
+ };
94
+ // Every subscriber may see the OS change; `apply` announces it only once.
95
+ const onSystemChange = () => {
96
+ if (readStored(env) === null)
97
+ apply(resolveMotionPreference(null, env.media?.matches ?? false), env);
98
+ };
99
+ env.document.addEventListener(MOTION_CHANGE_EVENT, onChange);
100
+ env.media?.addEventListener("change", onSystemChange);
101
+ return () => {
102
+ env.document.removeEventListener(MOTION_CHANGE_EVENT, onChange);
103
+ env.media?.removeEventListener("change", onSystemChange);
104
+ };
105
+ }
106
+ const TOGGLE_BOUND = "sfMotionToggleBound";
107
+ /**
108
+ * Wire every server-rendered `[data-sf-motion-toggle]` switch: a click flips
109
+ * the preference, `aria-checked` mirrors it (checked means animations on).
110
+ */
111
+ export function initializeMotionToggles(scope = document, env = browserMotionEnvironment()) {
112
+ const toggles = [...scope.querySelectorAll(MOTION_TOGGLE_SELECTOR)]
113
+ .filter((toggle) => toggle.dataset[TOGGLE_BOUND] !== "true");
114
+ const sync = (preference) => {
115
+ toggles.forEach((toggle) => toggle.setAttribute("aria-checked", String(preference === "full")));
116
+ };
117
+ const flip = () => setMotionPreference(getMotionPreference(env) === "full" ? "reduce" : "full", env);
118
+ toggles.forEach((toggle) => {
119
+ toggle.dataset[TOGGLE_BOUND] = "true";
120
+ toggle.addEventListener("click", flip);
121
+ });
122
+ sync(getMotionPreference(env));
123
+ const unsubscribe = subscribeMotionPreference(sync, env);
124
+ return () => {
125
+ unsubscribe();
126
+ toggles.forEach((toggle) => {
127
+ toggle.removeEventListener("click", flip);
128
+ delete toggle.dataset[TOGGLE_BOUND];
129
+ });
130
+ };
131
+ }
132
+ //# sourceMappingURL=motion-preference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motion-preference.js","sourceRoot":"","sources":["../../../src/astro/native/motion-preference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAC9C,MAAM,CAAC,MAAM,gBAAgB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AC,UAA4B,EAAE,EAAE;QAC5C,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;IAClG,CAAC,CAAC;IACF,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAErG,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACzB,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC;QACtC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,MAAM,WAAW,GAAG,yBAAyB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAEzD,OAAO,GAAG,EAAE;QACV,WAAW,EAAE,CAAC;QACd,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACzB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC1C,OAAO,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Single source of truth for \"may this page animate?\".\n *\n * The default follows the OS (`prefers-reduced-motion`). A visitor's explicit\n * choice from the accessibility panel wins in both directions and is stored in\n * localStorage. The resolved value is mirrored on\n * `<html data-sf-motion-preference=\"full|reduce\">`, so CSS and scripts read the\n * same state, and every change is announced with `sf:motion-change`.\n *\n * Do not read `matchMedia(\"(prefers-reduced-motion)\")` or write a bare\n * `@media (prefers-reduced-motion)` rule elsewhere: neither can be overridden\n * by the visitor.\n */\n\nexport const MOTION_STORAGE_KEY = \"sf:motion\";\nexport const MOTION_ATTRIBUTE = \"data-sf-motion-preference\";\nexport const MOTION_CHANGE_EVENT = \"sf:motion-change\";\nexport const MOTION_TOGGLE_SELECTOR = \"[data-sf-motion-toggle]\";\nexport const REDUCED_MOTION_QUERY = \"(prefers-reduced-motion: reduce)\";\n\n/** `full` animates, `reduce` keeps everything still. */\nexport type MotionPreference = \"full\" | \"reduce\";\n\nexport function isMotionPreference(value: unknown): value is MotionPreference {\n return value === \"full\" || value === \"reduce\";\n}\n\n/** An explicit choice beats the OS; without one the OS decides. */\nexport function resolveMotionPreference(stored: unknown, systemReduces: boolean): MotionPreference {\n if (isMotionPreference(stored)) return stored;\n return systemReduces ? \"reduce\" : \"full\";\n}\n\n/**\n * Inline script for `<head>`: mirrors the resolved preference on `<html>`\n * before first paint, so nothing starts animating and then snaps to a stop.\n */\nexport function motionPreferenceBootstrapScript(): string {\n const key = JSON.stringify(MOTION_STORAGE_KEY);\n const query = JSON.stringify(REDUCED_MOTION_QUERY);\n const attribute = JSON.stringify(MOTION_ATTRIBUTE);\n return `(()=>{let s=null,r=false;try{s=localStorage.getItem(${key})}catch{}try{r=matchMedia(${query}).matches}catch{}document.documentElement.setAttribute(${attribute},s===\"full\"||s===\"reduce\"?s:r?\"reduce\":\"full\")})()`;\n}\n\n/** The browser surface this module needs, injectable for tests. */\nexport interface MotionEnvironment {\n document: Pick<Document, \"documentElement\" | \"dispatchEvent\" | \"addEventListener\" | \"removeEventListener\">;\n storage: Pick<Storage, \"getItem\" | \"setItem\"> | null;\n media: Pick<MediaQueryList, \"matches\" | \"addEventListener\" | \"removeEventListener\"> | null;\n}\n\nexport function browserMotionEnvironment(): MotionEnvironment {\n let storage: MotionEnvironment[\"storage\"] = null;\n try {\n storage = localStorage;\n } catch {\n // Blocked storage keeps the preference in memory for the page only.\n }\n return {\n document,\n storage,\n media: typeof matchMedia === \"function\" ? matchMedia(REDUCED_MOTION_QUERY) : null,\n };\n}\n\nfunction readStored(env: MotionEnvironment): string | null {\n try {\n return env.storage?.getItem(MOTION_STORAGE_KEY) ?? null;\n } catch {\n return null;\n }\n}\n\nfunction mirrored(env: MotionEnvironment): MotionPreference | null {\n const value = env.document.documentElement.getAttribute(MOTION_ATTRIBUTE);\n return isMotionPreference(value) ? value : null;\n}\n\n/** The mirrored value when the bootstrap ran, otherwise resolved from storage and OS. */\nexport function getMotionPreference(env: MotionEnvironment = browserMotionEnvironment()): MotionPreference {\n return mirrored(env) ?? resolveMotionPreference(readStored(env), env.media?.matches ?? false);\n}\n\nfunction apply(preference: MotionPreference, env: MotionEnvironment): void {\n if (mirrored(env) === preference) return;\n env.document.documentElement.setAttribute(MOTION_ATTRIBUTE, preference);\n env.document.dispatchEvent(new CustomEvent(MOTION_CHANGE_EVENT, { detail: { preference } }));\n}\n\n/** Store an explicit choice and announce it. */\nexport function setMotionPreference(\n preference: MotionPreference,\n env: MotionEnvironment = browserMotionEnvironment(),\n): void {\n try {\n env.storage?.setItem(MOTION_STORAGE_KEY, preference);\n } catch {\n // The choice still applies to this page.\n }\n apply(preference, env);\n}\n\n/**\n * Call `listener` whenever the effective preference changes: an explicit\n * choice, or the OS setting while the visitor has not made one.\n */\nexport function subscribeMotionPreference(\n listener: (preference: MotionPreference) => void,\n env: MotionEnvironment = browserMotionEnvironment(),\n): () => void {\n const onChange = (event: Event) => {\n const preference = (event as CustomEvent<{ preference?: unknown }>).detail?.preference;\n if (isMotionPreference(preference)) listener(preference);\n };\n // Every subscriber may see the OS change; `apply` announces it only once.\n const onSystemChange = () => {\n if (readStored(env) === null) apply(resolveMotionPreference(null, env.media?.matches ?? false), env);\n };\n env.document.addEventListener(MOTION_CHANGE_EVENT, onChange);\n env.media?.addEventListener(\"change\", onSystemChange);\n return () => {\n env.document.removeEventListener(MOTION_CHANGE_EVENT, onChange);\n env.media?.removeEventListener(\"change\", onSystemChange);\n };\n}\n\nconst TOGGLE_BOUND = \"sfMotionToggleBound\";\n\n/**\n * Wire every server-rendered `[data-sf-motion-toggle]` switch: a click flips\n * the preference, `aria-checked` mirrors it (checked means animations on).\n */\nexport function initializeMotionToggles(\n scope: ParentNode = document,\n env: MotionEnvironment = browserMotionEnvironment(),\n): () => void {\n const toggles = [...scope.querySelectorAll<HTMLElement>(MOTION_TOGGLE_SELECTOR)]\n .filter((toggle) => toggle.dataset[TOGGLE_BOUND] !== \"true\");\n const sync = (preference: MotionPreference) => {\n toggles.forEach((toggle) => toggle.setAttribute(\"aria-checked\", String(preference === \"full\")));\n };\n const flip = () => setMotionPreference(getMotionPreference(env) === \"full\" ? \"reduce\" : \"full\", env);\n\n toggles.forEach((toggle) => {\n toggle.dataset[TOGGLE_BOUND] = \"true\";\n toggle.addEventListener(\"click\", flip);\n });\n sync(getMotionPreference(env));\n const unsubscribe = subscribeMotionPreference(sync, env);\n\n return () => {\n unsubscribe();\n toggles.forEach((toggle) => {\n toggle.removeEventListener(\"click\", flip);\n delete toggle.dataset[TOGGLE_BOUND];\n });\n };\n}\n"]}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Single source of truth for "may this page animate?".
3
+ *
4
+ * The default follows the OS (`prefers-reduced-motion`). A visitor's explicit
5
+ * choice from the accessibility panel wins in both directions and is stored in
6
+ * localStorage. The resolved value is mirrored on
7
+ * `<html data-sf-motion-preference="full|reduce">`, so CSS and scripts read the
8
+ * same state, and every change is announced with `sf:motion-change`.
9
+ *
10
+ * Do not read `matchMedia("(prefers-reduced-motion)")` or write a bare
11
+ * `@media (prefers-reduced-motion)` rule elsewhere: neither can be overridden
12
+ * by the visitor.
13
+ */
14
+
15
+ export const MOTION_STORAGE_KEY = "sf:motion";
16
+ export const MOTION_ATTRIBUTE = "data-sf-motion-preference";
17
+ export const MOTION_CHANGE_EVENT = "sf:motion-change";
18
+ export const MOTION_TOGGLE_SELECTOR = "[data-sf-motion-toggle]";
19
+ export const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
20
+
21
+ /** `full` animates, `reduce` keeps everything still. */
22
+ export type MotionPreference = "full" | "reduce";
23
+
24
+ export function isMotionPreference(value: unknown): value is MotionPreference {
25
+ return value === "full" || value === "reduce";
26
+ }
27
+
28
+ /** An explicit choice beats the OS; without one the OS decides. */
29
+ export function resolveMotionPreference(stored: unknown, systemReduces: boolean): MotionPreference {
30
+ if (isMotionPreference(stored)) return stored;
31
+ return systemReduces ? "reduce" : "full";
32
+ }
33
+
34
+ /**
35
+ * Inline script for `<head>`: mirrors the resolved preference on `<html>`
36
+ * before first paint, so nothing starts animating and then snaps to a stop.
37
+ */
38
+ export function motionPreferenceBootstrapScript(): string {
39
+ const key = JSON.stringify(MOTION_STORAGE_KEY);
40
+ const query = JSON.stringify(REDUCED_MOTION_QUERY);
41
+ const attribute = JSON.stringify(MOTION_ATTRIBUTE);
42
+ return `(()=>{let s=null,r=false;try{s=localStorage.getItem(${key})}catch{}try{r=matchMedia(${query}).matches}catch{}document.documentElement.setAttribute(${attribute},s==="full"||s==="reduce"?s:r?"reduce":"full")})()`;
43
+ }
44
+
45
+ /** The browser surface this module needs, injectable for tests. */
46
+ export interface MotionEnvironment {
47
+ document: Pick<Document, "documentElement" | "dispatchEvent" | "addEventListener" | "removeEventListener">;
48
+ storage: Pick<Storage, "getItem" | "setItem"> | null;
49
+ media: Pick<MediaQueryList, "matches" | "addEventListener" | "removeEventListener"> | null;
50
+ }
51
+
52
+ export function browserMotionEnvironment(): MotionEnvironment {
53
+ let storage: MotionEnvironment["storage"] = null;
54
+ try {
55
+ storage = localStorage;
56
+ } catch {
57
+ // Blocked storage keeps the preference in memory for the page only.
58
+ }
59
+ return {
60
+ document,
61
+ storage,
62
+ media: typeof matchMedia === "function" ? matchMedia(REDUCED_MOTION_QUERY) : null,
63
+ };
64
+ }
65
+
66
+ function readStored(env: MotionEnvironment): string | null {
67
+ try {
68
+ return env.storage?.getItem(MOTION_STORAGE_KEY) ?? null;
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+
74
+ function mirrored(env: MotionEnvironment): MotionPreference | null {
75
+ const value = env.document.documentElement.getAttribute(MOTION_ATTRIBUTE);
76
+ return isMotionPreference(value) ? value : null;
77
+ }
78
+
79
+ /** The mirrored value when the bootstrap ran, otherwise resolved from storage and OS. */
80
+ export function getMotionPreference(env: MotionEnvironment = browserMotionEnvironment()): MotionPreference {
81
+ return mirrored(env) ?? resolveMotionPreference(readStored(env), env.media?.matches ?? false);
82
+ }
83
+
84
+ function apply(preference: MotionPreference, env: MotionEnvironment): void {
85
+ if (mirrored(env) === preference) return;
86
+ env.document.documentElement.setAttribute(MOTION_ATTRIBUTE, preference);
87
+ env.document.dispatchEvent(new CustomEvent(MOTION_CHANGE_EVENT, { detail: { preference } }));
88
+ }
89
+
90
+ /** Store an explicit choice and announce it. */
91
+ export function setMotionPreference(
92
+ preference: MotionPreference,
93
+ env: MotionEnvironment = browserMotionEnvironment(),
94
+ ): void {
95
+ try {
96
+ env.storage?.setItem(MOTION_STORAGE_KEY, preference);
97
+ } catch {
98
+ // The choice still applies to this page.
99
+ }
100
+ apply(preference, env);
101
+ }
102
+
103
+ /**
104
+ * Call `listener` whenever the effective preference changes: an explicit
105
+ * choice, or the OS setting while the visitor has not made one.
106
+ */
107
+ export function subscribeMotionPreference(
108
+ listener: (preference: MotionPreference) => void,
109
+ env: MotionEnvironment = browserMotionEnvironment(),
110
+ ): () => void {
111
+ const onChange = (event: Event) => {
112
+ const preference = (event as CustomEvent<{ preference?: unknown }>).detail?.preference;
113
+ if (isMotionPreference(preference)) listener(preference);
114
+ };
115
+ // Every subscriber may see the OS change; `apply` announces it only once.
116
+ const onSystemChange = () => {
117
+ if (readStored(env) === null) apply(resolveMotionPreference(null, env.media?.matches ?? false), env);
118
+ };
119
+ env.document.addEventListener(MOTION_CHANGE_EVENT, onChange);
120
+ env.media?.addEventListener("change", onSystemChange);
121
+ return () => {
122
+ env.document.removeEventListener(MOTION_CHANGE_EVENT, onChange);
123
+ env.media?.removeEventListener("change", onSystemChange);
124
+ };
125
+ }
126
+
127
+ const TOGGLE_BOUND = "sfMotionToggleBound";
128
+
129
+ /**
130
+ * Wire every server-rendered `[data-sf-motion-toggle]` switch: a click flips
131
+ * the preference, `aria-checked` mirrors it (checked means animations on).
132
+ */
133
+ export function initializeMotionToggles(
134
+ scope: ParentNode = document,
135
+ env: MotionEnvironment = browserMotionEnvironment(),
136
+ ): () => void {
137
+ const toggles = [...scope.querySelectorAll<HTMLElement>(MOTION_TOGGLE_SELECTOR)]
138
+ .filter((toggle) => toggle.dataset[TOGGLE_BOUND] !== "true");
139
+ const sync = (preference: MotionPreference) => {
140
+ toggles.forEach((toggle) => toggle.setAttribute("aria-checked", String(preference === "full")));
141
+ };
142
+ const flip = () => setMotionPreference(getMotionPreference(env) === "full" ? "reduce" : "full", env);
143
+
144
+ toggles.forEach((toggle) => {
145
+ toggle.dataset[TOGGLE_BOUND] = "true";
146
+ toggle.addEventListener("click", flip);
147
+ });
148
+ sync(getMotionPreference(env));
149
+ const unsubscribe = subscribeMotionPreference(sync, env);
150
+
151
+ return () => {
152
+ unsubscribe();
153
+ toggles.forEach((toggle) => {
154
+ toggle.removeEventListener("click", flip);
155
+ delete toggle.dataset[TOGGLE_BOUND];
156
+ });
157
+ };
158
+ }
@@ -0,0 +1,101 @@
1
+ export declare const SF_REVEAL_SELECTOR = ".sf-reveal:not(.sf-motion-static)";
2
+ export declare const SF_REVEAL_CLASS = "sf-reveal";
3
+ export declare const SF_MOTION_STATIC_CLASS = "sf-motion-static";
4
+ export declare const SF_MOTION_DISABLE_CLASS = "sf-motion-disable";
5
+ export declare const SF_MOTION_DRAWER_EXIT_MS = 820;
6
+ export declare const SF_REVEAL_VISIBLE_RATIO = 0.2;
7
+ export declare const SF_REVEAL_STAGGER_SELECTOR = ".sf-reveal-stagger";
8
+ export declare const SF_REVEAL_STAGGER_STEP_MS = 90;
9
+ export declare const SF_REVEAL_STAGGER_MAX_MS = 450;
10
+ export type SfRevealModifier = `sf-reveal--${string}`;
11
+ export type SfDefaultReveal = false | SfRevealModifier;
12
+ export interface SfRevealRule {
13
+ /** Any selector accepted by `document.querySelectorAll`. */
14
+ selector: string;
15
+ /** Reveal modifier enforced on every matching element. */
16
+ reveal: SfRevealModifier;
17
+ }
18
+ export interface SfRevealClassChanges {
19
+ add: string[];
20
+ remove: SfRevealModifier[];
21
+ }
22
+ export interface SfMotionOptions {
23
+ /**
24
+ * Allows reveal elements already in the initial viewport to animate.
25
+ * Defaults to `false`, so initial content is immediately available.
26
+ */
27
+ revealAboveFold?: boolean;
28
+ /**
29
+ * Ordered selector-specific reveal rules. The first matching rule wins and
30
+ * enforces its modifier. Any valid CSS selector may be used.
31
+ */
32
+ revealRules?: readonly SfRevealRule[];
33
+ /**
34
+ * Preset applied to automatically selected elements. `false` keeps the
35
+ * reveal system strictly opt-in.
36
+ */
37
+ defaultReveal?: SfDefaultReveal;
38
+ /**
39
+ * Standard CSS selectors. Tags, classes, IDs, attributes and combinations
40
+ * can be mixed in the same array.
41
+ */
42
+ autoRevealSelectors?: readonly string[];
43
+ }
44
+ export interface ResolvedSfMotionOptions {
45
+ autoRevealSelectors: string[];
46
+ defaultReveal: SfDefaultReveal;
47
+ revealAboveFold: boolean;
48
+ revealRules: SfRevealRule[];
49
+ }
50
+ export type SfRevealState = "pending" | "visible" | "settled";
51
+ export interface InitialRevealStateInput {
52
+ bottom: number;
53
+ containsHashTarget: boolean;
54
+ protectedContent: boolean;
55
+ reducedMotion: boolean;
56
+ revealAboveFold: boolean;
57
+ top: number;
58
+ viewportHeight: number;
59
+ }
60
+ export interface RevealVisibilityInput {
61
+ bottom: number;
62
+ height: number;
63
+ top: number;
64
+ viewportHeight: number;
65
+ }
66
+ export declare function isSfRevealModifier(value: unknown): value is SfRevealModifier;
67
+ /**
68
+ * Normalizes server- or client-provided configuration. Invalid values fail
69
+ * open by disabling automatic reveals; empty and duplicate selectors are
70
+ * removed without changing their order.
71
+ */
72
+ export declare function resolveSfMotionOptions(options?: SfMotionOptions): ResolvedSfMotionOptions;
73
+ /** Exact class mutation required by an authoritative selector rule. */
74
+ export declare function ruleRevealClassChanges(existingClasses: Iterable<string>, reveal: SfRevealModifier): SfRevealClassChanges;
75
+ /** Delay for a zero-based participant index in a reveal stagger group. */
76
+ export declare function staggerRevealDelayMs(index: number): number;
77
+ /**
78
+ * Returns only the classes that automatic inheritance must add. Explicit
79
+ * modifiers win over the configured default and `sf-motion-static` remains a
80
+ * complete opt-out.
81
+ */
82
+ export declare function automaticRevealClasses(existingClasses: Iterable<string>, defaultReveal: SfDefaultReveal): string[];
83
+ /** Returns the longest combined CSS transition duration and delay. */
84
+ export declare function maximumTransitionTimeMs(transitionDuration: string, transitionDelay: string): number;
85
+ /**
86
+ * Initial viewport content stays static unless the project explicitly enables
87
+ * above-the-fold reveals. Deep links and protected content remain visible.
88
+ */
89
+ export declare function initialRevealState({ bottom, containsHashTarget, protectedContent, reducedMotion, revealAboveFold, top, viewportHeight, }: InitialRevealStateInput): SfRevealState;
90
+ /**
91
+ * Reveal ordinary content once 20% of its perceivable height is visible.
92
+ * For elements taller than the viewport, the viewport height is the reference.
93
+ */
94
+ export declare function hasEnoughVisibleArea({ bottom, height, top, viewportHeight, }: RevealVisibilityInput): boolean;
95
+ /**
96
+ * Reveal is deliberately one-way: focus and viewport entry can complete it,
97
+ * while leaving the viewport never conceals content again.
98
+ */
99
+ export declare function nextRevealState(current: SfRevealState, event: "focus" | "intersect" | "leave"): SfRevealState;
100
+ export declare function shouldInitializeMotion(initialized: string | undefined): boolean;
101
+ //# sourceMappingURL=motion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motion.d.ts","sourceRoot":"","sources":["../../../src/astro/native/motion.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,sCAAsC,CAAC;AAEtE,eAAO,MAAM,eAAe,cAAc,CAAC;AAE3C,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AAEzD,eAAO,MAAM,uBAAuB,s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,aAAa,CAQf;AAED,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,OAAO,CAET"}
@@ -0,0 +1,168 @@
1
+ export const SF_REVEAL_SELECTOR = ".sf-reveal:not(.sf-motion-static)";
2
+ export const SF_REVEAL_CLASS = "sf-reveal";
3
+ export const SF_MOTION_STATIC_CLASS = "sf-motion-static";
4
+ export const SF_MOTION_DISABLE_CLASS = "sf-motion-disable";
5
+ export const SF_MOTION_DRAWER_EXIT_MS = 820;
6
+ export const SF_REVEAL_VISIBLE_RATIO = 0.2;
7
+ export const SF_REVEAL_STAGGER_SELECTOR = ".sf-reveal-stagger";
8
+ export const SF_REVEAL_STAGGER_STEP_MS = 90;
9
+ export const SF_REVEAL_STAGGER_MAX_MS = 450;
10
+ const SF_REVEAL_MODIFIER_PATTERN = /^sf-reveal--\S+$/;
11
+ export function isSfRevealModifier(value) {
12
+ return typeof value === "string" && SF_REVEAL_MODIFIER_PATTERN.test(value);
13
+ }
14
+ function normalizeSelectors(value) {
15
+ if (!Array.isArray(value))
16
+ return [];
17
+ return Array.from(new Set(value
18
+ .filter((selector) => typeof selector === "string")
19
+ .map((selector) => selector.trim())
20
+ .filter(Boolean)));
21
+ }
22
+ function normalizeRevealRules(value) {
23
+ if (!Array.isArray(value))
24
+ return [];
25
+ const seenSelectors = new Set();
26
+ return value.flatMap((rule) => {
27
+ if (!rule || typeof rule !== "object")
28
+ return [];
29
+ const candidate = rule;
30
+ const selector = typeof candidate.selector === "string" ? candidate.selector.trim() : "";
31
+ if (!selector ||
32
+ seenSelectors.has(selector) ||
33
+ !isSfRevealModifier(candidate.reveal)) {
34
+ return [];
35
+ }
36
+ seenSelectors.add(selector);
37
+ return [{ selector, reveal: candidate.reveal }];
38
+ });
39
+ }
40
+ /**
41
+ * Normalizes server- or client-provided configuration. Invalid values fail
42
+ * open by disabling automatic reveals; empty and duplicate selectors are
43
+ * removed without changing their order.
44
+ */
45
+ export function resolveSfMotionOptions(options = {}) {
46
+ const defaultReveal = isSfRevealModifier(options.defaultReveal)
47
+ ? options.defaultReveal
48
+ : false;
49
+ return {
50
+ autoRevealSelectors: normalizeSelectors(options.autoRevealSelectors),
51
+ defaultReveal,
52
+ revealAboveFold: options.revealAboveFold === true,
53
+ revealRules: normalizeRevealRules(options.revealRules),
54
+ };
55
+ }
56
+ /** Exact class mutation required by an authoritative selector rule. */
57
+ export function ruleRevealClassChanges(existingClasses, reveal) {
58
+ const classes = Array.from(existingClasses);
59
+ if (classes.includes(SF_MOTION_STATIC_CLASS) ||
60
+ classes.includes(SF_MOTION_DISABLE_CLASS)) {
61
+ return { add: [], remove: [] };
62
+ }
63
+ return {
64
+ add: [
65
+ ...(classes.includes(SF_REVEAL_CLASS) ? [] : [SF_REVEAL_CLASS]),
66
+ ...(classes.includes(reveal) ? [] : [reveal]),
67
+ ],
68
+ remove: classes
69
+ .filter(isSfRevealModifier)
70
+ .filter((modifier) => modifier !== reveal),
71
+ };
72
+ }
73
+ /** Delay for a zero-based participant index in a reveal stagger group. */
74
+ export function staggerRevealDelayMs(index) {
75
+ if (!Number.isFinite(index) || index <= 0)
76
+ return 0;
77
+ return Math.min(Math.floor(index) * SF_REVEAL_STAGGER_STEP_MS, SF_REVEAL_STAGGER_MAX_MS);
78
+ }
79
+ /**
80
+ * Returns only the classes that automatic inheritance must add. Explicit
81
+ * modifiers win over the configured default and `sf-motion-static` remains a
82
+ * complete opt-out.
83
+ */
84
+ export function automaticRevealClasses(existingClasses, defaultReveal) {
85
+ if (defaultReveal === false)
86
+ return [];
87
+ const classes = Array.from(existingClasses);
88
+ if (classes.includes(SF_MOTION_STATIC_CLASS) ||
89
+ classes.includes(SF_MOTION_DISABLE_CLASS)) {
90
+ return [];
91
+ }
92
+ return [
93
+ ...(classes.includes(SF_REVEAL_CLASS) ? [] : [SF_REVEAL_CLASS]),
94
+ ...(classes.some(isSfRevealModifier) ? [] : [defaultReveal]),
95
+ ];
96
+ }
97
+ function cssTimeToMs(value) {
98
+ const normalized = value.trim();
99
+ const amount = Number.parseFloat(normalized);
100
+ if (!Number.isFinite(amount))
101
+ return 0;
102
+ return normalized.endsWith("ms") ? amount : amount * 1000;
103
+ }
104
+ /** Returns the longest combined CSS transition duration and delay. */
105
+ export function maximumTransitionTimeMs(transitionDuration, transitionDelay) {
106
+ const durations = transitionDuration.split(",").map(cssTimeToMs);
107
+ const delays = transitionDelay.split(",").map(cssTimeToMs);
108
+ const itemCount = Math.max(durations.length, delays.length);
109
+ return Array.from({ length: itemCount }, (_, index) => {
110
+ const duration = durations[index % durations.length] ?? 0;
111
+ const delay = delays[index % delays.length] ?? 0;
112
+ return Math.max(0, duration + delay);
113
+ }).reduce((maximum, value) => Math.max(maximum, value), 0);
114
+ }
115
+ /**
116
+ * Initial viewport content stays static unless the project explicitly enables
117
+ * above-the-fold reveals. Deep links and protected content remain visible.
118
+ */
119
+ export function initialRevealState({ bottom, containsHashTarget, protectedContent, reducedMotion, revealAboveFold, top, viewportHeight, }) {
120
+ if (reducedMotion ||
121
+ containsHashTarget ||
122
+ protectedContent) {
123
+ return "visible";
124
+ }
125
+ // DMO: content that only peeks into the initial viewport (less than the
126
+ // reveal share of its height) waits for the scroll instead of appearing
127
+ // statically; content already scrolled past the top stays visible.
128
+ if (!revealAboveFold &&
129
+ bottom > 0 &&
130
+ top < viewportHeight &&
131
+ (top < 0 ||
132
+ hasEnoughVisibleArea({
133
+ bottom,
134
+ height: Math.max(0, bottom - top),
135
+ top,
136
+ viewportHeight,
137
+ }))) {
138
+ return "visible";
139
+ }
140
+ return "pending";
141
+ }
142
+ /**
143
+ * Reveal ordinary content once 20% of its perceivable height is visible.
144
+ * For elements taller than the viewport, the viewport height is the reference.
145
+ */
146
+ export function hasEnoughVisibleArea({ bottom, height, top, viewportHeight, }) {
147
+ if (height <= 0 || viewportHeight <= 0)
148
+ return true;
149
+ const visibleHeight = Math.max(0, Math.min(bottom, viewportHeight) - Math.max(top, 0));
150
+ const requiredHeight = Math.min(height, viewportHeight) * SF_REVEAL_VISIBLE_RATIO;
151
+ return visibleHeight + 1 >= requiredHeight;
152
+ }
153
+ /**
154
+ * Reveal is deliberately one-way: focus and viewport entry can complete it,
155
+ * while leaving the viewport never conceals content again.
156
+ */
157
+ export function nextRevealState(current, event) {
158
+ if (current === "settled")
159
+ return "settled";
160
+ if (current === "visible" || event === "focus" || event === "intersect") {
161
+ return "visible";
162
+ }
163
+ return "pending";
164
+ }
165
+ export function shouldInitializeMotion(initialized) {
166
+ return initialized !== "true";
167
+ }
168
+ //# sourceMappingURL=motion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motion.js","sourceRoot":"","sources":["../../../src/astro/native/motion.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,mCAAmC,CAAC;AAEtE,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC;AAE3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AAEzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,mBAAmB,CAAC;AAE3D,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C,MAAM,CAAC,MAAM,0BAA0B,GAAG,oBAAoB,CAAC;AAE/D,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C,MAAM,0BAA0B,GAAG,kBAAkB,CAAC;AAmEtD,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACxC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAErC,OAAO,KAAK,CAAC,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D,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,EACnC,MAAM,EACN,MAAM,EACN,GAAG,EACH,cAAc,GACQ;IACtB,IAAI,MAAM,IAAI,CAAC,IAAI,cAAc,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAEpD,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAC5B,CAAC,EACD,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CACpD,CAAC;IACF,MAAM,cAAc,GAClB,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,uBAAuB,CAAC;IAE7D,OAAO,aAAa,GAAG,CAAC,IAAI,cAAc,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAsB,EACtB,KAAsC;IAEtC,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAE5C,IAAI,OAAO,KAAK,SAAS,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;QACxE,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,WAA+B;IAE/B,OAAO,WAAW,KAAK,MAAM,CAAC;AAChC,CAAC","sourcesContent":["export const SF_REVEAL_SELECTOR = \".sf-reveal:not(.sf-motion-static)\";\n\nexport const SF_REVEAL_CLASS = \"sf-reveal\";\n\nexport const SF_MOTION_STATIC_CLASS = \"sf-motion-static\";\n\nexport const SF_MOTION_DISABLE_CLASS = \"sf-motion-disable\";\n\nexport const SF_MOTION_DRAWER_EXIT_MS = 820;\n\nexport const SF_REVEAL_VISIBLE_RATIO = 0.2;\n\nexport const SF_REVEAL_STAGGER_SELECTOR = \".sf-reveal-stagger\";\n\nexport const SF_REVEAL_STAGGER_STEP_MS = 90;\n\nexport const SF_REVEAL_STAGGER_MAX_MS = 450;\n\nconst SF_REVEAL_MODIFIER_PATTERN = /^sf-reveal--\\S+$/;\n\nexport type SfRevealModifier = `sf-reveal--${string}`;\n\nexport type SfDefaultReveal = false | SfRevealModifier;\n\nexport interface SfRevealRule {\n /** Any selector accepted by `document.querySelectorAll`. */\n selector: string;\n /** Reveal modifier enforced on every matching element. */\n reveal: SfRevealModifier;\n}\n\nexport interface SfRevealClassChanges {\n add: string[];\n remove: SfRevealModifier[];\n}\n\nexport interface SfMotionOptions {\n /**\n * Allows reveal elements already in the initial viewport to animate.\n * Defaults to `false`, so initial content is immediately available.\n */\n revealAboveFold?: boolean;\n /**\n * Ordered selector-specific reveal rules. The first matching rule wins and\n * enforces its modifier. Any valid CSS selector may be used.\n */\n revealRules?: readonly SfRevealRule[];\n /**\n * Preset applied to automatically selected elements. `false` keeps the\n * reveal system strictly opt-in.\n */\n defaultReveal?: SfDefaultReveal;\n /**\n * Standard CSS selectors. Tags, classes, IDs, attributes and combinations\n * can be mixed in the same array.\n */\n autoRevealSelectors?: readonly string[];\n}\n\nexport interface ResolvedSfMotionOptions {\n autoRevealSelectors: string[];\n defaultReveal: SfDefaultReveal;\n revealAboveFold: boolean;\n revealRules: SfRevealRule[];\n}\n\nexport type SfRevealState = \"pending\" | \"visible\" | \"settled\";\n\nexport interface InitialRevealStateInput {\n bottom: number;\n containsHashTarget: boolean;\n protectedContent: boolean;\n reducedMotion: boolean;\n revealAboveFold: boolean;\n top: number;\n viewportHeight: number;\n}\n\nexport interface RevealVisibilityInput {\n bottom: number;\n height: number;\n top: number;\n viewportHeight: number;\n}\n\nexport function isSfRevealModifier(value: unknown): value is SfRevealModifier {\n return typeof value === \"string\" && SF_REVEAL_MODIFIER_PATTERN.test(value);\n}\n\nfunction normalizeSelectors(value: unknown): string[] {\n if (!Array.isArray(value)) return [];\n\n return Array.from(\n new Set(\n value\n .filter((selector): selector is string => typeof selector === \"string\")\n .map((selector) => selector.trim())\n .filter(Boolean),\n ),\n );\n}\n\nfunction normalizeRevealRules(value: unknown): SfRevealRule[] {\n if (!Array.isArray(value)) return [];\n\n const seenSelectors = new Set<string>();\n return value.flatMap((rule: unknown) => {\n if (!rule || typeof rule !== \"object\") return [];\n\n const candidate = rule as Partial<SfRevealRule>;\n const selector =\n typeof candidate.selector === \"string\" ? candidate.selector.trim() : \"\";\n if (\n !selector ||\n seenSelectors.has(selector) ||\n !isSfRevealModifier(candidate.reveal)\n ) {\n return [];\n }\n\n seenSelectors.add(selector);\n return [{ selector, reveal: candidate.reveal }];\n });\n}\n\n/**\n * Normalizes server- or client-provided configuration. Invalid values fail\n * open by disabling automatic reveals; empty and duplicate selectors are\n * removed without changing their order.\n */\nexport function resolveSfMotionOptions(\n options: SfMotionOptions = {},\n): ResolvedSfMotionOptions {\n const defaultReveal = isSfRevealModifier(options.defaultReveal)\n ? options.defaultReveal\n : false;\n return {\n autoRevealSelectors: normalizeSelectors(options.autoRevealSelectors),\n defaultReveal,\n revealAboveFold: options.revealAboveFold === true,\n revealRules: normalizeRevealRules(options.revealRules),\n };\n}\n\n/** Exact class mutation required by an authoritative selector rule. */\nexport function ruleRevealClassChanges(\n existingClasses: Iterable<string>,\n reveal: SfRevealModifier,\n): SfRevealClassChanges {\n const classes = Array.from(existingClasses);\n if (\n classes.includes(SF_MOTION_STATIC_CLASS) ||\n classes.includes(SF_MOTION_DISABLE_CLASS)\n ) {\n return { add: [], remove: [] };\n }\n\n return {\n add: [\n ...(classes.includes(SF_REVEAL_CLASS) ? [] : [SF_REVEAL_CLASS]),\n ...(classes.includes(reveal) ? [] : [reveal]),\n ],\n remove: classes\n .filter(isSfRevealModifier)\n .filter((modifier) => modifier !== reveal),\n };\n}\n\n/** Delay for a zero-based participant index in a reveal stagger group. */\nexport function staggerRevealDelayMs(index: number): number {\n if (!Number.isFinite(index) || index <= 0) return 0;\n return Math.min(\n Math.floor(index) * SF_REVEAL_STAGGER_STEP_MS,\n SF_REVEAL_STAGGER_MAX_MS,\n );\n}\n\n/**\n * Returns only the classes that automatic inheritance must add. Explicit\n * modifiers win over the configured default and `sf-motion-static` remains a\n * complete opt-out.\n */\nexport function automaticRevealClasses(\n existingClasses: Iterable<string>,\n defaultReveal: SfDefaultReveal,\n): string[] {\n if (defaultReveal === false) return [];\n\n const classes = Array.from(existingClasses);\n if (\n classes.includes(SF_MOTION_STATIC_CLASS) ||\n classes.includes(SF_MOTION_DISABLE_CLASS)\n ) {\n return [];\n }\n\n return [\n ...(classes.includes(SF_REVEAL_CLASS) ? [] : [SF_REVEAL_CLASS]),\n ...(classes.some(isSfRevealModifier) ? [] : [defaultReveal]),\n ];\n}\n\nfunction cssTimeToMs(value: string): number {\n const normalized = value.trim();\n const amount = Number.parseFloat(normalized);\n if (!Number.isFinite(amount)) return 0;\n\n return normalized.endsWith(\"ms\") ? amount : amount * 1000;\n}\n\n/** Returns the longest combined CSS transition duration and delay. */\nexport function maximumTransitionTimeMs(\n transitionDuration: string,\n transitionDelay: string,\n): number {\n const durations = transitionDuration.split(\",\").map(cssTimeToMs);\n const delays = transitionDelay.split(\",\").map(cssTimeToMs);\n const itemCount = Math.max(durations.length, delays.length);\n\n return Array.from({ length: itemCount }, (_, index) => {\n const duration = durations[index % durations.length] ?? 0;\n const delay = delays[index % delays.length] ?? 0;\n return Math.max(0, duration + delay);\n }).reduce((maximum, value) => Math.max(maximum, value), 0);\n}\n\n/**\n * Initial viewport content stays static unless the project explicitly enables\n * above-the-fold reveals. Deep links and protected content remain visible.\n */\nexport function initialRevealState({\n bottom,\n containsHashTarget,\n protectedContent,\n reducedMotion,\n revealAboveFold,\n top,\n viewportHeight,\n}: InitialRevealStateInput): SfRevealState {\n if (\n reducedMotion ||\n containsHashTarget ||\n protectedContent\n ) {\n return \"visible\";\n }\n\n // DMO: content that only peeks into the initial viewport (less than the\n // reveal share of its height) waits for the scroll instead of appearing\n // statically; content already scrolled past the top stays visible.\n if (\n !revealAboveFold &&\n bottom > 0 &&\n top < viewportHeight &&\n (top < 0 ||\n hasEnoughVisibleArea({\n bottom,\n height: Math.max(0, bottom - top),\n top,\n viewportHeight,\n }))\n ) {\n return \"visible\";\n }\n\n return \"pending\";\n}\n\n/**\n * Reveal ordinary content once 20% of its perceivable height is visible.\n * For elements taller than the viewport, the viewport height is the reference.\n */\nexport function hasEnoughVisibleArea({\n bottom,\n height,\n top,\n viewportHeight,\n}: RevealVisibilityInput): boolean {\n if (height <= 0 || viewportHeight <= 0) return true;\n\n const visibleHeight = Math.max(\n 0,\n Math.min(bottom, viewportHeight) - Math.max(top, 0),\n );\n const requiredHeight =\n Math.min(height, viewportHeight) * SF_REVEAL_VISIBLE_RATIO;\n\n return visibleHeight + 1 >= requiredHeight;\n}\n\n/**\n * Reveal is deliberately one-way: focus and viewport entry can complete it,\n * while leaving the viewport never conceals content again.\n */\nexport function nextRevealState(\n current: SfRevealState,\n event: \"focus\" | \"intersect\" | \"leave\",\n): SfRevealState {\n if (current === \"settled\") return \"settled\";\n\n if (current === \"visible\" || event === \"focus\" || event === \"intersect\") {\n return \"visible\";\n }\n\n return \"pending\";\n}\n\nexport function shouldInitializeMotion(\n initialized: string | undefined,\n): boolean {\n return initialized !== \"true\";\n}\n"]}