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