@styleflow.app/flowpress-astro-core 1.0.0-beta.3 → 1.0.0-beta.30
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 +190 -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 +157 -0
- package/dist/astro/DefaultBlockAdapter.astro +35 -0
- package/dist/astro/DefaultTemplate.astro +12 -7
- package/dist/astro/GutenbergRenderer.astro +240 -80
- package/dist/astro/StyleflowElement.astro +23 -0
- package/dist/astro/ThemeRuntime.astro +26 -0
- package/dist/astro/blocks/CarouselBlock.astro +8 -10
- package/dist/astro/blocks/CarouselItemBlock.astro +4 -4
- package/dist/astro/blocks/ColumnBlock.astro +4 -5
- package/dist/astro/blocks/CoverBlock.astro +155 -0
- package/dist/astro/blocks/FormBlock.astro +23 -20
- package/dist/astro/blocks/GridBlock.astro +4 -4
- package/dist/astro/blocks/HeroBlock.astro +4 -5
- package/dist/astro/blocks/ImageBlock.astro +4 -5
- package/dist/astro/blocks/ListItemFallback.astro +10 -7
- package/dist/astro/blocks/NumberSpinnerBlock.astro +29 -22
- package/dist/astro/blocks/SemanticElement.astro +35 -0
- package/dist/astro/blocks/SiteLogoBlock.astro +53 -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 +7 -0
- package/dist/astro/blocks/helpers.d.ts.map +1 -1
- package/dist/astro/blocks/helpers.js +52 -41
- package/dist/astro/blocks/helpers.js.map +1 -1
- package/dist/astro/blocks/helpers.ts +64 -45
- package/dist/astro/native/Blob.astro +113 -0
- package/dist/astro/native/BlobBlock.astro +52 -0
- package/dist/astro/native/CustomFieldValue.astro +87 -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/ResolvedBlocks.astro +89 -0
- package/dist/astro/native/SyncedPatternContent.astro +92 -0
- package/dist/astro/native/TermFieldValue.astro +38 -0
- package/dist/astro/native/Timeline.astro +21 -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.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.astro +43 -0
- package/dist/astro/native/core-buttons.astro +14 -0
- package/dist/astro/native/core-group.astro +23 -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 +124 -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 +94 -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 +37 -0
- package/dist/astro/native/core-post-template.astro +30 -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.js +106 -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/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/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-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 +81 -0
- package/dist/astro/native/registry.js.map +1 -0
- package/dist/astro/native/registry.ts +81 -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 +118 -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 +20 -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 +124 -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 +118 -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/styleflow.d.ts +16 -1
- package/dist/styleflow.d.ts.map +1 -1
- package/dist/styleflow.js +76 -7
- package/dist/styleflow.js.map +1 -1
- 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 +26 -4
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser controller for morphing blobs. The server always renders a correct
|
|
3
|
+
* static shape; this only animates the `d` of the clip and outline paths.
|
|
4
|
+
*
|
|
5
|
+
* - `auto`: after each pause, morph into a random target and repeat.
|
|
6
|
+
* - `hover`: morph into a random target while hovered/focused, back on leave.
|
|
7
|
+
*
|
|
8
|
+
* One shared requestAnimationFrame loop drives every blob. Morphing pauses
|
|
9
|
+
* off-screen and in hidden tabs, and follows the shared motion preference
|
|
10
|
+
* (OS `prefers-reduced-motion`, overridable from the accessibility panel): with
|
|
11
|
+
* motion reduced every blob rests on its authored shape and never morphs, and
|
|
12
|
+
* it picks up again, live, when motion is allowed.
|
|
13
|
+
*/
|
|
14
|
+
import { getMotionPreference, subscribeMotionPreference, } from "../motion-preference.js";
|
|
15
|
+
import { BLOB_BOX, BLOB_VARIANTS } from "./blob-shapes.generated.js";
|
|
16
|
+
import { pickMorphTarget, morphConfigFromDataset } from "./config.js";
|
|
17
|
+
import { easeInOutCubic, lerpShape, shapeToPath } from "./geometry.js";
|
|
18
|
+
export const BLOB_ROOT_SELECTOR = "[data-sf-blob]";
|
|
19
|
+
export const CARD_ANIMATION_CLASS = "card__animation";
|
|
20
|
+
export const CARD_ANIMATION_TRIGGER_SELECTOR = ".card__has_animations";
|
|
21
|
+
const INITIALIZED = "blobReady";
|
|
22
|
+
class MorphingBlob {
|
|
23
|
+
root;
|
|
24
|
+
config;
|
|
25
|
+
scheduler;
|
|
26
|
+
fill;
|
|
27
|
+
ring;
|
|
28
|
+
settled;
|
|
29
|
+
transition = null;
|
|
30
|
+
timer;
|
|
31
|
+
visible = true;
|
|
32
|
+
hovered = false;
|
|
33
|
+
allowed = false;
|
|
34
|
+
clipPath;
|
|
35
|
+
ringPath;
|
|
36
|
+
disposers = [];
|
|
37
|
+
constructor(root, config, scheduler) {
|
|
38
|
+
this.root = root;
|
|
39
|
+
this.config = config;
|
|
40
|
+
this.scheduler = scheduler;
|
|
41
|
+
const base = BLOB_VARIANTS[config.base] ?? BLOB_VARIANTS[0];
|
|
42
|
+
this.fill = base.fill;
|
|
43
|
+
this.ring = base.ring;
|
|
44
|
+
this.settled = config.base;
|
|
45
|
+
this.clipPath = root.querySelector("[data-blob-clip-path]");
|
|
46
|
+
this.ringPath = root.querySelector("[data-blob-ring-path]");
|
|
47
|
+
}
|
|
48
|
+
start() {
|
|
49
|
+
if (this.config.mode === "auto") {
|
|
50
|
+
this.watchVisibility();
|
|
51
|
+
this.queueNext();
|
|
52
|
+
}
|
|
53
|
+
else if (this.config.mode === "hover") {
|
|
54
|
+
// A marked blob delegates its hover/focus state to the closest card.
|
|
55
|
+
// Unmarked blobs keep their original, local hover behaviour.
|
|
56
|
+
const card = this.root.classList.contains(CARD_ANIMATION_CLASS)
|
|
57
|
+
? this.root.closest(CARD_ANIMATION_TRIGGER_SELECTOR)
|
|
58
|
+
: null;
|
|
59
|
+
const area = card ?? this.root.querySelector("[data-blob-shape]") ?? this.root;
|
|
60
|
+
this.listen(area, "pointerenter", () => this.hover(true));
|
|
61
|
+
this.listen(area, "pointerleave", () => this.hover(false));
|
|
62
|
+
this.listen(area, "focusin", () => this.hover(true));
|
|
63
|
+
this.listen(area, "focusout", (event) => {
|
|
64
|
+
const next = event.relatedTarget;
|
|
65
|
+
if (!(next instanceof Node) || !area.contains(next))
|
|
66
|
+
this.hover(false);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
destroy() {
|
|
71
|
+
window.clearTimeout(this.timer);
|
|
72
|
+
this.scheduler.remove(this);
|
|
73
|
+
this.disposers.splice(0).forEach((dispose) => dispose());
|
|
74
|
+
delete this.root.dataset[INITIALIZED];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Motion allowed: resume the automatic cycle. Motion reduced: drop back to
|
|
78
|
+
* the authored shape at once, and stay there until allowed again.
|
|
79
|
+
*/
|
|
80
|
+
setMotionAllowed(allowed) {
|
|
81
|
+
if (this.allowed === allowed)
|
|
82
|
+
return;
|
|
83
|
+
this.allowed = allowed;
|
|
84
|
+
if (allowed) {
|
|
85
|
+
this.queueNext();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
window.clearTimeout(this.timer);
|
|
89
|
+
this.scheduler.remove(this);
|
|
90
|
+
this.transition = null;
|
|
91
|
+
this.settled = this.config.base;
|
|
92
|
+
const base = BLOB_VARIANTS[this.config.base];
|
|
93
|
+
if (base)
|
|
94
|
+
this.apply(base.fill, base.ring);
|
|
95
|
+
}
|
|
96
|
+
/** Jump to the resting state and stop: used off-screen and in hidden tabs. */
|
|
97
|
+
freeze() {
|
|
98
|
+
window.clearTimeout(this.timer);
|
|
99
|
+
this.scheduler.remove(this);
|
|
100
|
+
if (this.transition) {
|
|
101
|
+
const target = BLOB_VARIANTS[this.transition.to];
|
|
102
|
+
if (target)
|
|
103
|
+
this.apply(target.fill, target.ring);
|
|
104
|
+
this.settled = this.transition.to;
|
|
105
|
+
this.transition = null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Advance the active transition. Returns `false` once it has finished. */
|
|
109
|
+
step(now) {
|
|
110
|
+
const transition = this.transition;
|
|
111
|
+
const target = transition ? BLOB_VARIANTS[transition.to] : undefined;
|
|
112
|
+
if (!transition || !target)
|
|
113
|
+
return false;
|
|
114
|
+
const progress = Math.min(1, (now - transition.startedAt) / this.config.duration);
|
|
115
|
+
const eased = easeInOutCubic(progress);
|
|
116
|
+
this.apply(lerpShape(transition.from.fill, target.fill, eased), lerpShape(transition.from.ring, target.ring, eased));
|
|
117
|
+
if (progress < 1)
|
|
118
|
+
return true;
|
|
119
|
+
this.settled = transition.to;
|
|
120
|
+
this.transition = null;
|
|
121
|
+
if (this.config.mode === "auto")
|
|
122
|
+
this.queueNext();
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
listen(target, type, handler) {
|
|
126
|
+
target.addEventListener(type, handler);
|
|
127
|
+
this.disposers.push(() => target.removeEventListener(type, handler));
|
|
128
|
+
}
|
|
129
|
+
watchVisibility() {
|
|
130
|
+
if (typeof IntersectionObserver === "function") {
|
|
131
|
+
const observer = new IntersectionObserver((entries) => {
|
|
132
|
+
this.visible = entries[entries.length - 1]?.isIntersecting ?? true;
|
|
133
|
+
if (this.visible)
|
|
134
|
+
this.queueNext();
|
|
135
|
+
else
|
|
136
|
+
this.freeze();
|
|
137
|
+
});
|
|
138
|
+
observer.observe(this.root);
|
|
139
|
+
this.disposers.push(() => observer.disconnect());
|
|
140
|
+
}
|
|
141
|
+
const onVisibility = () => (document.hidden ? this.freeze() : this.queueNext());
|
|
142
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
143
|
+
this.disposers.push(() => document.removeEventListener("visibilitychange", onVisibility));
|
|
144
|
+
}
|
|
145
|
+
queueNext() {
|
|
146
|
+
window.clearTimeout(this.timer);
|
|
147
|
+
if (!this.allowed || this.config.mode !== "auto" || this.transition || !this.visible || document.hidden)
|
|
148
|
+
return;
|
|
149
|
+
this.timer = window.setTimeout(() => {
|
|
150
|
+
const next = pickMorphTarget(this.config.targets, this.settled);
|
|
151
|
+
if (next !== null)
|
|
152
|
+
this.morphTo(next);
|
|
153
|
+
}, this.config.interval);
|
|
154
|
+
}
|
|
155
|
+
hover(active) {
|
|
156
|
+
if (this.hovered === active)
|
|
157
|
+
return;
|
|
158
|
+
this.hovered = active;
|
|
159
|
+
if (!this.allowed)
|
|
160
|
+
return;
|
|
161
|
+
if (active) {
|
|
162
|
+
const next = pickMorphTarget(this.config.targets, this.config.base);
|
|
163
|
+
if (next !== null)
|
|
164
|
+
this.morphTo(next);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this.morphTo(this.config.base);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
morphTo(index) {
|
|
171
|
+
if (!this.allowed || !BLOB_VARIANTS[index])
|
|
172
|
+
return;
|
|
173
|
+
// Restarting mid-flight continues from the shape currently on screen.
|
|
174
|
+
this.transition = {
|
|
175
|
+
startedAt: performance.now(),
|
|
176
|
+
from: { fill: this.fill, ring: this.ring },
|
|
177
|
+
to: index,
|
|
178
|
+
};
|
|
179
|
+
this.scheduler.add(this);
|
|
180
|
+
}
|
|
181
|
+
apply(fill, ring) {
|
|
182
|
+
this.fill = fill;
|
|
183
|
+
this.ring = ring;
|
|
184
|
+
this.clipPath?.setAttribute("d", shapeToPath(fill, BLOB_BOX));
|
|
185
|
+
this.ringPath?.setAttribute("d", shapeToPath(ring, BLOB_BOX));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/** A single rAF loop shared by every blob on the page. */
|
|
189
|
+
class Scheduler {
|
|
190
|
+
active = new Set();
|
|
191
|
+
frame = 0;
|
|
192
|
+
add(blob) {
|
|
193
|
+
this.active.add(blob);
|
|
194
|
+
if (!this.frame)
|
|
195
|
+
this.frame = requestAnimationFrame(this.tick);
|
|
196
|
+
}
|
|
197
|
+
remove(blob) {
|
|
198
|
+
this.active.delete(blob);
|
|
199
|
+
}
|
|
200
|
+
tick = (now) => {
|
|
201
|
+
this.frame = 0;
|
|
202
|
+
for (const blob of [...this.active]) {
|
|
203
|
+
if (!blob.step(now))
|
|
204
|
+
this.active.delete(blob);
|
|
205
|
+
}
|
|
206
|
+
if (this.active.size > 0)
|
|
207
|
+
this.frame = requestAnimationFrame(this.tick);
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Wire every `[data-sf-blob]` with `data-blob-morph` set to `auto` or `hover`.
|
|
212
|
+
* Blobs are wired even while motion is reduced, so allowing it again starts
|
|
213
|
+
* them without a reload. Returns a disposer that restores the static state
|
|
214
|
+
* (for tests and view swaps).
|
|
215
|
+
*/
|
|
216
|
+
export function initializeSfBlobs(scope = document) {
|
|
217
|
+
const scheduler = new Scheduler();
|
|
218
|
+
const blobs = [];
|
|
219
|
+
scope.querySelectorAll(BLOB_ROOT_SELECTOR).forEach((root) => {
|
|
220
|
+
if (root.dataset[INITIALIZED] === "true")
|
|
221
|
+
return;
|
|
222
|
+
const config = morphConfigFromDataset(root.dataset, BLOB_VARIANTS.length);
|
|
223
|
+
if (config.mode === "none")
|
|
224
|
+
return;
|
|
225
|
+
root.dataset[INITIALIZED] = "true";
|
|
226
|
+
const blob = new MorphingBlob(root, config, scheduler);
|
|
227
|
+
blobs.push(blob);
|
|
228
|
+
blob.start();
|
|
229
|
+
});
|
|
230
|
+
const applyPreference = (preference) => {
|
|
231
|
+
blobs.forEach((blob) => blob.setMotionAllowed(preference === "full"));
|
|
232
|
+
};
|
|
233
|
+
applyPreference(getMotionPreference());
|
|
234
|
+
const unsubscribe = subscribeMotionPreference(applyPreference);
|
|
235
|
+
return () => {
|
|
236
|
+
unsubscribe();
|
|
237
|
+
blobs.forEach((blob) => blob.destroy());
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../src/astro/native/blob/controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAE1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAwB,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAkB,MAAM,eAAe,CAAC;AAEvF,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AACnD,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AACtD,MAAM,CAAC,MAAM,+BAA+B,GAAG,uBAAuB,CAAC;AACvE,MAAM,WAAW,GAAG,WAAW,CAAC;AAQhC,MAAM,YAAY;IAcG;IACA;IACA;IAfX,IAAI,CAAY;IAChB,IAAI,CAAY;IAChB,OAAO,CAAS;IAChB,UAAU,GAAsB,IAAI,CAAC;IACrC,KAAK,CAAqB;IAC1B,OAAO,GAAG,IAAI,CAAC;IACf,OAAO,GAAG,KAAK,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IACP,QAAQ,CAAwB;IAChC,QAAQ,CAAw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AAI,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC;QACnC,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QACvD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,CAAC,UAA4B,EAAE,EAAE;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC;IACF,eAAe,CAAC,mBAAmB,EAAE,CAAC,CAAC;IACvC,MAAM,WAAW,GAAG,yBAAyB,CAAC,eAAe,CAAC,CAAC;IAC/D,OAAO,GAAG,EAAE;QACV,WAAW,EAAE,CAAC;QACd,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1C,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Browser controller for morphing blobs. The server always renders a correct\n * static shape; this only animates the `d` of the clip and outline paths.\n *\n * - `auto`: after each pause, morph into a random target and repeat.\n * - `hover`: morph into a random target while hovered/focused, back on leave.\n *\n * One shared requestAnimationFrame loop drives every blob. Morphing pauses\n * off-screen and in hidden tabs, and follows the shared motion preference\n * (OS `prefers-reduced-motion`, overridable from the accessibility panel): with\n * motion reduced every blob rests on its authored shape and never morphs, and\n * it picks up again, live, when motion is allowed.\n */\nimport {\n getMotionPreference,\n subscribeMotionPreference,\n type MotionPreference,\n} from \"../motion-preference.js\";\nimport { BLOB_BOX, BLOB_VARIANTS } from \"./blob-shapes.generated.js\";\nimport { pickMorphTarget, morphConfigFromDataset, type BlobMorphConfig } from \"./config.js\";\nimport { easeInOutCubic, lerpShape, shapeToPath, type BlobShape } from \"./geometry.js\";\n\nexport const BLOB_ROOT_SELECTOR = \"[data-sf-blob]\";\nexport const CARD_ANIMATION_CLASS = \"card__animation\";\nexport const CARD_ANIMATION_TRIGGER_SELECTOR = \".card__has_animations\";\nconst INITIALIZED = \"blobReady\";\n\ninterface Transition {\n startedAt: number;\n from: { fill: BlobShape; ring: BlobShape };\n to: number;\n}\n\nclass MorphingBlob {\n private fill: BlobShape;\n private ring: BlobShape;\n private settled: number;\n private transition: Transition | null = null;\n private timer: number | undefined;\n private visible = true;\n private hovered = false;\n private allowed = false;\n private readonly clipPath: SVGPathElement | null;\n private readonly ringPath: SVGPathElement | null;\n private readonly disposers: Array<() => void> = [];\n\n constructor(\n private readonly root: HTMLElement,\n private readonly config: BlobMorphConfig,\n private readonly scheduler: Scheduler,\n ) {\n const base = BLOB_VARIANTS[config.base] ?? (BLOB_VARIANTS[0] as (typeof BLOB_VARIANTS)[number]);\n this.fill = base.fill;\n this.ring = base.ring;\n this.settled = config.base;\n this.clipPath = root.querySelector<SVGPathElement>(\"[data-blob-clip-path]\");\n this.ringPath = root.querySelector<SVGPathElement>(\"[data-blob-ring-path]\");\n }\n\n start(): void {\n if (this.config.mode === \"auto\") {\n this.watchVisibility();\n this.queueNext();\n } else if (this.config.mode === \"hover\") {\n // A marked blob delegates its hover/focus state to the closest card.\n // Unmarked blobs keep their original, local hover behaviour.\n const card = this.root.classList.contains(CARD_ANIMATION_CLASS)\n ? this.root.closest<HTMLElement>(CARD_ANIMATION_TRIGGER_SELECTOR)\n : null;\n const area = card ?? this.root.querySelector<HTMLElement>(\"[data-blob-shape]\") ?? this.root;\n this.listen(area, \"pointerenter\", () => this.hover(true));\n this.listen(area, \"pointerleave\", () => this.hover(false));\n this.listen(area, \"focusin\", () => this.hover(true));\n this.listen(area, \"focusout\", (event) => {\n const next = (event as FocusEvent).relatedTarget;\n if (!(next instanceof Node) || !area.contains(next)) this.hover(false);\n });\n }\n }\n\n destroy(): void {\n window.clearTimeout(this.timer);\n this.scheduler.remove(this);\n this.disposers.splice(0).forEach((dispose) => dispose());\n delete this.root.dataset[INITIALIZED];\n }\n\n /**\n * Motion allowed: resume the automatic cycle. Motion reduced: drop back to\n * the authored shape at once, and stay there until allowed again.\n */\n setMotionAllowed(allowed: boolean): void {\n if (this.allowed === allowed) return;\n this.allowed = allowed;\n if (allowed) {\n this.queueNext();\n return;\n }\n window.clearTimeout(this.timer);\n this.scheduler.remove(this);\n this.transition = null;\n this.settled = this.config.base;\n const base = BLOB_VARIANTS[this.config.base];\n if (base) this.apply(base.fill, base.ring);\n }\n\n /** Jump to the resting state and stop: used off-screen and in hidden tabs. */\n freeze(): void {\n window.clearTimeout(this.timer);\n this.scheduler.remove(this);\n if (this.transition) {\n const target = BLOB_VARIANTS[this.transition.to];\n if (target) this.apply(target.fill, target.ring);\n this.settled = this.transition.to;\n this.transition = null;\n }\n }\n\n /** Advance the active transition. Returns `false` once it has finished. */\n step(now: number): boolean {\n const transition = this.transition;\n const target = transition ? BLOB_VARIANTS[transition.to] : undefined;\n if (!transition || !target) return false;\n const progress = Math.min(1, (now - transition.startedAt) / this.config.duration);\n const eased = easeInOutCubic(progress);\n this.apply(\n lerpShape(transition.from.fill, target.fill, eased),\n lerpShape(transition.from.ring, target.ring, eased),\n );\n if (progress < 1) return true;\n this.settled = transition.to;\n this.transition = null;\n if (this.config.mode === \"auto\") this.queueNext();\n return false;\n }\n\n private listen(target: EventTarget, type: string, handler: (event: Event) => void): void {\n target.addEventListener(type, handler);\n this.disposers.push(() => target.removeEventListener(type, handler));\n }\n\n private watchVisibility(): void {\n if (typeof IntersectionObserver === \"function\") {\n const observer = new IntersectionObserver((entries) => {\n this.visible = entries[entries.length - 1]?.isIntersecting ?? true;\n if (this.visible) this.queueNext();\n else this.freeze();\n });\n observer.observe(this.root);\n this.disposers.push(() => observer.disconnect());\n }\n const onVisibility = () => (document.hidden ? this.freeze() : this.queueNext());\n document.addEventListener(\"visibilitychange\", onVisibility);\n this.disposers.push(() => document.removeEventListener(\"visibilitychange\", onVisibility));\n }\n\n private queueNext(): void {\n window.clearTimeout(this.timer);\n if (!this.allowed || this.config.mode !== \"auto\" || this.transition || !this.visible || document.hidden) return;\n this.timer = window.setTimeout(() => {\n const next = pickMorphTarget(this.config.targets, this.settled);\n if (next !== null) this.morphTo(next);\n }, this.config.interval);\n }\n\n private hover(active: boolean): void {\n if (this.hovered === active) return;\n this.hovered = active;\n if (!this.allowed) return;\n if (active) {\n const next = pickMorphTarget(this.config.targets, this.config.base);\n if (next !== null) this.morphTo(next);\n } else {\n this.morphTo(this.config.base);\n }\n }\n\n private morphTo(index: number): void {\n if (!this.allowed || !BLOB_VARIANTS[index]) return;\n // Restarting mid-flight continues from the shape currently on screen.\n this.transition = {\n startedAt: performance.now(),\n from: { fill: this.fill, ring: this.ring },\n to: index,\n };\n this.scheduler.add(this);\n }\n\n private apply(fill: BlobShape, ring: BlobShape): void {\n this.fill = fill;\n this.ring = ring;\n this.clipPath?.setAttribute(\"d\", shapeToPath(fill, BLOB_BOX));\n this.ringPath?.setAttribute(\"d\", shapeToPath(ring, BLOB_BOX));\n }\n}\n\n/** A single rAF loop shared by every blob on the page. */\nclass Scheduler {\n private readonly active = new Set<MorphingBlob>();\n private frame = 0;\n\n add(blob: MorphingBlob): void {\n this.active.add(blob);\n if (!this.frame) this.frame = requestAnimationFrame(this.tick);\n }\n\n remove(blob: MorphingBlob): void {\n this.active.delete(blob);\n }\n\n private readonly tick = (now: number): void => {\n this.frame = 0;\n for (const blob of [...this.active]) {\n if (!blob.step(now)) this.active.delete(blob);\n }\n if (this.active.size > 0) this.frame = requestAnimationFrame(this.tick);\n };\n}\n\n/**\n * Wire every `[data-sf-blob]` with `data-blob-morph` set to `auto` or `hover`.\n * Blobs are wired even while motion is reduced, so allowing it again starts\n * them without a reload. Returns a disposer that restores the static state\n * (for tests and view swaps).\n */\nexport function initializeSfBlobs(scope: ParentNode = document): () => void {\n const scheduler = new Scheduler();\n const blobs: MorphingBlob[] = [];\n scope.querySelectorAll<HTMLElement>(BLOB_ROOT_SELECTOR).forEach((root) => {\n if (root.dataset[INITIALIZED] === \"true\") return;\n const config = morphConfigFromDataset(root.dataset, BLOB_VARIANTS.length);\n if (config.mode === \"none\") return;\n root.dataset[INITIALIZED] = \"true\";\n const blob = new MorphingBlob(root, config, scheduler);\n blobs.push(blob);\n blob.start();\n });\n\n const applyPreference = (preference: MotionPreference) => {\n blobs.forEach((blob) => blob.setMotionAllowed(preference === \"full\"));\n };\n applyPreference(getMotionPreference());\n const unsubscribe = subscribeMotionPreference(applyPreference);\n return () => {\n unsubscribe();\n blobs.forEach((blob) => blob.destroy());\n };\n}\n"]}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser controller for morphing blobs. The server always renders a correct
|
|
3
|
+
* static shape; this only animates the `d` of the clip and outline paths.
|
|
4
|
+
*
|
|
5
|
+
* - `auto`: after each pause, morph into a random target and repeat.
|
|
6
|
+
* - `hover`: morph into a random target while hovered/focused, back on leave.
|
|
7
|
+
*
|
|
8
|
+
* One shared requestAnimationFrame loop drives every blob. Morphing pauses
|
|
9
|
+
* off-screen and in hidden tabs, and follows the shared motion preference
|
|
10
|
+
* (OS `prefers-reduced-motion`, overridable from the accessibility panel): with
|
|
11
|
+
* motion reduced every blob rests on its authored shape and never morphs, and
|
|
12
|
+
* it picks up again, live, when motion is allowed.
|
|
13
|
+
*/
|
|
14
|
+
import {
|
|
15
|
+
getMotionPreference,
|
|
16
|
+
subscribeMotionPreference,
|
|
17
|
+
type MotionPreference,
|
|
18
|
+
} from "../motion-preference.js";
|
|
19
|
+
import { BLOB_BOX, BLOB_VARIANTS } from "./blob-shapes.generated.js";
|
|
20
|
+
import { pickMorphTarget, morphConfigFromDataset, type BlobMorphConfig } from "./config.js";
|
|
21
|
+
import { easeInOutCubic, lerpShape, shapeToPath, type BlobShape } from "./geometry.js";
|
|
22
|
+
|
|
23
|
+
export const BLOB_ROOT_SELECTOR = "[data-sf-blob]";
|
|
24
|
+
export const CARD_ANIMATION_CLASS = "card__animation";
|
|
25
|
+
export const CARD_ANIMATION_TRIGGER_SELECTOR = ".card__has_animations";
|
|
26
|
+
const INITIALIZED = "blobReady";
|
|
27
|
+
|
|
28
|
+
interface Transition {
|
|
29
|
+
startedAt: number;
|
|
30
|
+
from: { fill: BlobShape; ring: BlobShape };
|
|
31
|
+
to: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
class MorphingBlob {
|
|
35
|
+
private fill: BlobShape;
|
|
36
|
+
private ring: BlobShape;
|
|
37
|
+
private settled: number;
|
|
38
|
+
private transition: Transition | null = null;
|
|
39
|
+
private timer: number | undefined;
|
|
40
|
+
private visible = true;
|
|
41
|
+
private hovered = false;
|
|
42
|
+
private allowed = false;
|
|
43
|
+
private readonly clipPath: SVGPathElement | null;
|
|
44
|
+
private readonly ringPath: SVGPathElement | null;
|
|
45
|
+
private readonly disposers: Array<() => void> = [];
|
|
46
|
+
|
|
47
|
+
constructor(
|
|
48
|
+
private readonly root: HTMLElement,
|
|
49
|
+
private readonly config: BlobMorphConfig,
|
|
50
|
+
private readonly scheduler: Scheduler,
|
|
51
|
+
) {
|
|
52
|
+
const base = BLOB_VARIANTS[config.base] ?? (BLOB_VARIANTS[0] as (typeof BLOB_VARIANTS)[number]);
|
|
53
|
+
this.fill = base.fill;
|
|
54
|
+
this.ring = base.ring;
|
|
55
|
+
this.settled = config.base;
|
|
56
|
+
this.clipPath = root.querySelector<SVGPathElement>("[data-blob-clip-path]");
|
|
57
|
+
this.ringPath = root.querySelector<SVGPathElement>("[data-blob-ring-path]");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
start(): void {
|
|
61
|
+
if (this.config.mode === "auto") {
|
|
62
|
+
this.watchVisibility();
|
|
63
|
+
this.queueNext();
|
|
64
|
+
} else if (this.config.mode === "hover") {
|
|
65
|
+
// A marked blob delegates its hover/focus state to the closest card.
|
|
66
|
+
// Unmarked blobs keep their original, local hover behaviour.
|
|
67
|
+
const card = this.root.classList.contains(CARD_ANIMATION_CLASS)
|
|
68
|
+
? this.root.closest<HTMLElement>(CARD_ANIMATION_TRIGGER_SELECTOR)
|
|
69
|
+
: null;
|
|
70
|
+
const area = card ?? this.root.querySelector<HTMLElement>("[data-blob-shape]") ?? this.root;
|
|
71
|
+
this.listen(area, "pointerenter", () => this.hover(true));
|
|
72
|
+
this.listen(area, "pointerleave", () => this.hover(false));
|
|
73
|
+
this.listen(area, "focusin", () => this.hover(true));
|
|
74
|
+
this.listen(area, "focusout", (event) => {
|
|
75
|
+
const next = (event as FocusEvent).relatedTarget;
|
|
76
|
+
if (!(next instanceof Node) || !area.contains(next)) this.hover(false);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
destroy(): void {
|
|
82
|
+
window.clearTimeout(this.timer);
|
|
83
|
+
this.scheduler.remove(this);
|
|
84
|
+
this.disposers.splice(0).forEach((dispose) => dispose());
|
|
85
|
+
delete this.root.dataset[INITIALIZED];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Motion allowed: resume the automatic cycle. Motion reduced: drop back to
|
|
90
|
+
* the authored shape at once, and stay there until allowed again.
|
|
91
|
+
*/
|
|
92
|
+
setMotionAllowed(allowed: boolean): void {
|
|
93
|
+
if (this.allowed === allowed) return;
|
|
94
|
+
this.allowed = allowed;
|
|
95
|
+
if (allowed) {
|
|
96
|
+
this.queueNext();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
window.clearTimeout(this.timer);
|
|
100
|
+
this.scheduler.remove(this);
|
|
101
|
+
this.transition = null;
|
|
102
|
+
this.settled = this.config.base;
|
|
103
|
+
const base = BLOB_VARIANTS[this.config.base];
|
|
104
|
+
if (base) this.apply(base.fill, base.ring);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Jump to the resting state and stop: used off-screen and in hidden tabs. */
|
|
108
|
+
freeze(): void {
|
|
109
|
+
window.clearTimeout(this.timer);
|
|
110
|
+
this.scheduler.remove(this);
|
|
111
|
+
if (this.transition) {
|
|
112
|
+
const target = BLOB_VARIANTS[this.transition.to];
|
|
113
|
+
if (target) this.apply(target.fill, target.ring);
|
|
114
|
+
this.settled = this.transition.to;
|
|
115
|
+
this.transition = null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Advance the active transition. Returns `false` once it has finished. */
|
|
120
|
+
step(now: number): boolean {
|
|
121
|
+
const transition = this.transition;
|
|
122
|
+
const target = transition ? BLOB_VARIANTS[transition.to] : undefined;
|
|
123
|
+
if (!transition || !target) return false;
|
|
124
|
+
const progress = Math.min(1, (now - transition.startedAt) / this.config.duration);
|
|
125
|
+
const eased = easeInOutCubic(progress);
|
|
126
|
+
this.apply(
|
|
127
|
+
lerpShape(transition.from.fill, target.fill, eased),
|
|
128
|
+
lerpShape(transition.from.ring, target.ring, eased),
|
|
129
|
+
);
|
|
130
|
+
if (progress < 1) return true;
|
|
131
|
+
this.settled = transition.to;
|
|
132
|
+
this.transition = null;
|
|
133
|
+
if (this.config.mode === "auto") this.queueNext();
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private listen(target: EventTarget, type: string, handler: (event: Event) => void): void {
|
|
138
|
+
target.addEventListener(type, handler);
|
|
139
|
+
this.disposers.push(() => target.removeEventListener(type, handler));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private watchVisibility(): void {
|
|
143
|
+
if (typeof IntersectionObserver === "function") {
|
|
144
|
+
const observer = new IntersectionObserver((entries) => {
|
|
145
|
+
this.visible = entries[entries.length - 1]?.isIntersecting ?? true;
|
|
146
|
+
if (this.visible) this.queueNext();
|
|
147
|
+
else this.freeze();
|
|
148
|
+
});
|
|
149
|
+
observer.observe(this.root);
|
|
150
|
+
this.disposers.push(() => observer.disconnect());
|
|
151
|
+
}
|
|
152
|
+
const onVisibility = () => (document.hidden ? this.freeze() : this.queueNext());
|
|
153
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
154
|
+
this.disposers.push(() => document.removeEventListener("visibilitychange", onVisibility));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private queueNext(): void {
|
|
158
|
+
window.clearTimeout(this.timer);
|
|
159
|
+
if (!this.allowed || this.config.mode !== "auto" || this.transition || !this.visible || document.hidden) return;
|
|
160
|
+
this.timer = window.setTimeout(() => {
|
|
161
|
+
const next = pickMorphTarget(this.config.targets, this.settled);
|
|
162
|
+
if (next !== null) this.morphTo(next);
|
|
163
|
+
}, this.config.interval);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private hover(active: boolean): void {
|
|
167
|
+
if (this.hovered === active) return;
|
|
168
|
+
this.hovered = active;
|
|
169
|
+
if (!this.allowed) return;
|
|
170
|
+
if (active) {
|
|
171
|
+
const next = pickMorphTarget(this.config.targets, this.config.base);
|
|
172
|
+
if (next !== null) this.morphTo(next);
|
|
173
|
+
} else {
|
|
174
|
+
this.morphTo(this.config.base);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private morphTo(index: number): void {
|
|
179
|
+
if (!this.allowed || !BLOB_VARIANTS[index]) return;
|
|
180
|
+
// Restarting mid-flight continues from the shape currently on screen.
|
|
181
|
+
this.transition = {
|
|
182
|
+
startedAt: performance.now(),
|
|
183
|
+
from: { fill: this.fill, ring: this.ring },
|
|
184
|
+
to: index,
|
|
185
|
+
};
|
|
186
|
+
this.scheduler.add(this);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private apply(fill: BlobShape, ring: BlobShape): void {
|
|
190
|
+
this.fill = fill;
|
|
191
|
+
this.ring = ring;
|
|
192
|
+
this.clipPath?.setAttribute("d", shapeToPath(fill, BLOB_BOX));
|
|
193
|
+
this.ringPath?.setAttribute("d", shapeToPath(ring, BLOB_BOX));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** A single rAF loop shared by every blob on the page. */
|
|
198
|
+
class Scheduler {
|
|
199
|
+
private readonly active = new Set<MorphingBlob>();
|
|
200
|
+
private frame = 0;
|
|
201
|
+
|
|
202
|
+
add(blob: MorphingBlob): void {
|
|
203
|
+
this.active.add(blob);
|
|
204
|
+
if (!this.frame) this.frame = requestAnimationFrame(this.tick);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
remove(blob: MorphingBlob): void {
|
|
208
|
+
this.active.delete(blob);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private readonly tick = (now: number): void => {
|
|
212
|
+
this.frame = 0;
|
|
213
|
+
for (const blob of [...this.active]) {
|
|
214
|
+
if (!blob.step(now)) this.active.delete(blob);
|
|
215
|
+
}
|
|
216
|
+
if (this.active.size > 0) this.frame = requestAnimationFrame(this.tick);
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Wire every `[data-sf-blob]` with `data-blob-morph` set to `auto` or `hover`.
|
|
222
|
+
* Blobs are wired even while motion is reduced, so allowing it again starts
|
|
223
|
+
* them without a reload. Returns a disposer that restores the static state
|
|
224
|
+
* (for tests and view swaps).
|
|
225
|
+
*/
|
|
226
|
+
export function initializeSfBlobs(scope: ParentNode = document): () => void {
|
|
227
|
+
const scheduler = new Scheduler();
|
|
228
|
+
const blobs: MorphingBlob[] = [];
|
|
229
|
+
scope.querySelectorAll<HTMLElement>(BLOB_ROOT_SELECTOR).forEach((root) => {
|
|
230
|
+
if (root.dataset[INITIALIZED] === "true") return;
|
|
231
|
+
const config = morphConfigFromDataset(root.dataset, BLOB_VARIANTS.length);
|
|
232
|
+
if (config.mode === "none") return;
|
|
233
|
+
root.dataset[INITIALIZED] = "true";
|
|
234
|
+
const blob = new MorphingBlob(root, config, scheduler);
|
|
235
|
+
blobs.push(blob);
|
|
236
|
+
blob.start();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
const applyPreference = (preference: MotionPreference) => {
|
|
240
|
+
blobs.forEach((blob) => blob.setMotionAllowed(preference === "full"));
|
|
241
|
+
};
|
|
242
|
+
applyPreference(getMotionPreference());
|
|
243
|
+
const unsubscribe = subscribeMotionPreference(applyPreference);
|
|
244
|
+
return () => {
|
|
245
|
+
unsubscribe();
|
|
246
|
+
blobs.forEach((blob) => blob.destroy());
|
|
247
|
+
};
|
|
248
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../../../src/astro/native/blob/geometry.ts"],"names":[],"mappings":"AAAA,cAAc,sDAAsD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.js","sourceRoot":"","sources":["../../../../src/astro/native/blob/geometry.ts"],"names":[],"mappings":"AAAA,cAAc,sDAAsD,CAAC","sourcesContent":["export * from \"@styleflow.app/flowpress-components/organic-geometry\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@styleflow.app/flowpress-components/organic-geometry";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unique `<clipPath>` id per rendered blob. A module counter (instead of a
|
|
3
|
+
* random value) keeps the output deterministic for a given render order, and
|
|
4
|
+
* each blob needs its own clip because morphing rewrites the path's `d`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function nextBlobClipId(): string;
|
|
7
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../../../src/astro/native/blob/ids.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAGvC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
let sequence = 0;
|
|
2
|
+
/**
|
|
3
|
+
* Unique `<clipPath>` id per rendered blob. A module counter (instead of a
|
|
4
|
+
* random value) keeps the output deterministic for a given render order, and
|
|
5
|
+
* each blob needs its own clip because morphing rewrites the path's `d`.
|
|
6
|
+
*/
|
|
7
|
+
export function nextBlobClipId() {
|
|
8
|
+
sequence += 1;
|
|
9
|
+
return `sf-blob-clip-${sequence}`;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../../../../src/astro/native/blob/ids.ts"],"names":[],"mappings":"AAAA,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,QAAQ,IAAI,CAAC,CAAC;IACd,OAAO,gBAAgB,QAAQ,EAAE,CAAC;AACpC,CAAC","sourcesContent":["let sequence = 0;\n\n/**\n * Unique `<clipPath>` id per rendered blob. A module counter (instead of a\n * random value) keeps the output deterministic for a given render order, and\n * each blob needs its own clip because morphing rewrites the path's `d`.\n */\nexport function nextBlobClipId(): string {\n sequence += 1;\n return `sf-blob-clip-${sequence}`;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
let sequence = 0;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Unique `<clipPath>` id per rendered blob. A module counter (instead of a
|
|
5
|
+
* random value) keeps the output deterministic for a given render order, and
|
|
6
|
+
* each blob needs its own clip because morphing rewrites the path's `d`.
|
|
7
|
+
*/
|
|
8
|
+
export function nextBlobClipId(): string {
|
|
9
|
+
sequence += 1;
|
|
10
|
+
return `sf-blob-clip-${sequence}`;
|
|
11
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/* Blob: organic clipped container. Geometry only; colours come from Styleflow. */
|
|
2
|
+
.sf-blob {
|
|
3
|
+
position: relative;
|
|
4
|
+
display: block;
|
|
5
|
+
inline-size: 100%;
|
|
6
|
+
aspect-ratio: var(--fp-blob-aspect, 1 / 1);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.sf-blob[data-blob-aspect="square"] {
|
|
10
|
+
aspect-ratio: 1 / 1;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.sf-blob[data-blob-aspect="portrait"] {
|
|
14
|
+
aspect-ratio: 4 / 5;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.sf-blob[data-blob-aspect="landscape"] {
|
|
18
|
+
aspect-ratio: 5 / 4;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* Holds the <clipPath>; it must stay rendered (display: none disables clipping). */
|
|
22
|
+
.sf-blob__defs {
|
|
23
|
+
position: absolute;
|
|
24
|
+
inline-size: 0;
|
|
25
|
+
block-size: 0;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
pointer-events: none;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.sf-blob__shape {
|
|
31
|
+
position: absolute;
|
|
32
|
+
inset: 0;
|
|
33
|
+
display: grid;
|
|
34
|
+
grid-template-columns: minmax(0, 1fr);
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
isolation: isolate;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.sf-blob[data-blob-fit="cover"] .sf-blob__shape {
|
|
40
|
+
grid-auto-rows: minmax(0, 1fr);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.sf-blob[data-blob-fit="cover"] .sf-blob__shape > * {
|
|
44
|
+
min-inline-size: 0;
|
|
45
|
+
min-block-size: 0;
|
|
46
|
+
inline-size: 100%;
|
|
47
|
+
block-size: 100%;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.sf-blob[data-blob-fit="cover"] .sf-blob__shape :is(img, picture, video) {
|
|
51
|
+
display: block;
|
|
52
|
+
inline-size: 100%;
|
|
53
|
+
block-size: 100%;
|
|
54
|
+
object-fit: cover;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.sf-blob[data-blob-fit="center"] .sf-blob__shape {
|
|
58
|
+
place-content: center;
|
|
59
|
+
place-items: center;
|
|
60
|
+
text-align: center;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* The outline sits above the content and may spill past the box edges. */
|
|
64
|
+
.sf-blob__ring {
|
|
65
|
+
position: absolute;
|
|
66
|
+
inset: 0;
|
|
67
|
+
display: block;
|
|
68
|
+
overflow: visible;
|
|
69
|
+
pointer-events: none;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.sf-blob__ring svg {
|
|
73
|
+
display: block;
|
|
74
|
+
inline-size: 100%;
|
|
75
|
+
block-size: 100%;
|
|
76
|
+
overflow: visible;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.sf-blob__ring path {
|
|
80
|
+
fill: none;
|
|
81
|
+
stroke: var(--sf-surface-default-background);
|
|
82
|
+
stroke-linejoin: round;
|
|
83
|
+
}
|