@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,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, DOM-free parsing of the blob authoring options. Shared by the Astro
|
|
3
|
+
* component (server) and the morph controller (browser) so both read the same
|
|
4
|
+
* `data-blob-*` contract and clamp values identically.
|
|
5
|
+
*/
|
|
6
|
+
export const BLOB_MORPH_MODES = ["none", "auto", "hover"];
|
|
7
|
+
export const BLOB_CONTENT_FITS = ["cover", "center"];
|
|
8
|
+
export const BLOB_ASPECT_RATIOS = ["natural", "square", "portrait", "landscape"];
|
|
9
|
+
export const BLOB_DEFAULT_MORPH_DURATION = 2400;
|
|
10
|
+
export const BLOB_DEFAULT_MORPH_INTERVAL = 1200;
|
|
11
|
+
export const BLOB_DEFAULT_OUTLINE_WIDTH = 2;
|
|
12
|
+
export function clampNumber(value, min, max, fallback) {
|
|
13
|
+
const number = typeof value === "number" ? value : Number(value);
|
|
14
|
+
if (value === "" || value === null || value === undefined || !Number.isFinite(number)) {
|
|
15
|
+
return fallback;
|
|
16
|
+
}
|
|
17
|
+
return Math.min(max, Math.max(min, number));
|
|
18
|
+
}
|
|
19
|
+
function oneOf(values, value, fallback) {
|
|
20
|
+
return typeof value === "string" && values.includes(value)
|
|
21
|
+
? value
|
|
22
|
+
: fallback;
|
|
23
|
+
}
|
|
24
|
+
/** Authors count from 1; the registry is zero-based. Invalid input rests on variant 1. */
|
|
25
|
+
export function resolveVariantIndex(value, count) {
|
|
26
|
+
const number = typeof value === "number" ? value : Number(String(value ?? ""));
|
|
27
|
+
return Number.isInteger(number) && number >= 1 && number <= count ? number - 1 : 0;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* `"2, 5, 9"` or `[2, 5, 9]` → zero-based unique indices in authoring order.
|
|
31
|
+
* Empty input means every variant; unknown numbers are ignored.
|
|
32
|
+
*/
|
|
33
|
+
export function parseVariantList(value, count) {
|
|
34
|
+
const parts = Array.isArray(value) ? value : String(value ?? "").split(/[\s,;]+/);
|
|
35
|
+
const indices = [];
|
|
36
|
+
for (const part of parts) {
|
|
37
|
+
const number = typeof part === "number" ? part : Number(String(part));
|
|
38
|
+
if (Number.isInteger(number) && number >= 1 && number <= count && !indices.includes(number - 1)) {
|
|
39
|
+
indices.push(number - 1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return indices.length > 0 ? indices : Array.from({ length: count }, (_, index) => index);
|
|
43
|
+
}
|
|
44
|
+
export const resolveMorphMode = (value) => oneOf(BLOB_MORPH_MODES, value, "none");
|
|
45
|
+
export const resolveContentFit = (value) => oneOf(BLOB_CONTENT_FITS, value, "cover");
|
|
46
|
+
export const resolveAspectRatio = (value) => oneOf(BLOB_ASPECT_RATIOS, value, "natural");
|
|
47
|
+
export function resolveOutlineWidth(value) {
|
|
48
|
+
return clampNumber(value, 0, 12, BLOB_DEFAULT_OUTLINE_WIDTH);
|
|
49
|
+
}
|
|
50
|
+
export function resolveMorphConfig(input, count) {
|
|
51
|
+
return {
|
|
52
|
+
mode: resolveMorphMode(input.morph),
|
|
53
|
+
base: resolveVariantIndex(input.variant, count),
|
|
54
|
+
targets: parseVariantList(input.targets, count),
|
|
55
|
+
duration: clampNumber(input.duration, 400, 10000, BLOB_DEFAULT_MORPH_DURATION),
|
|
56
|
+
interval: clampNumber(input.interval, 0, 30000, BLOB_DEFAULT_MORPH_INTERVAL),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** The `data-blob-*` attributes the server writes and the controller reads back. */
|
|
60
|
+
export function morphDataAttributes(config) {
|
|
61
|
+
return {
|
|
62
|
+
"data-blob-variant": String(config.base + 1),
|
|
63
|
+
"data-blob-morph": config.mode,
|
|
64
|
+
"data-blob-targets": config.targets.map((index) => index + 1).join(","),
|
|
65
|
+
"data-blob-duration": String(config.duration),
|
|
66
|
+
"data-blob-interval": String(config.interval),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function morphConfigFromDataset(dataset, count) {
|
|
70
|
+
return resolveMorphConfig({
|
|
71
|
+
variant: dataset.blobVariant,
|
|
72
|
+
morph: dataset.blobMorph,
|
|
73
|
+
targets: dataset.blobTargets,
|
|
74
|
+
duration: dataset.blobDuration,
|
|
75
|
+
interval: dataset.blobInterval,
|
|
76
|
+
}, count);
|
|
77
|
+
}
|
|
78
|
+
/** Random candidate different from `current`, or `null` when nothing else is allowed. */
|
|
79
|
+
export function pickMorphTarget(candidates, current, random = Math.random) {
|
|
80
|
+
const options = candidates.filter((index) => index !== current);
|
|
81
|
+
if (options.length === 0)
|
|
82
|
+
return null;
|
|
83
|
+
const position = Math.min(options.length - 1, Math.floor(random() * options.length));
|
|
84
|
+
return options[position] ?? null;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/astro/native/blob/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAGnE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAU,CAAC;AAG9D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAU,CAAC;AAG1F,MAAM,CAAC,MAAM,2BAA2B,GAAG,I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B,KAAK,EAAE,OAAO,CAAC,SAAS;QACxB,OAAO,EAAE,OAAO,CAAC,WAAW;QAC5B,QAAQ,EAAE,OAAO,CAAC,YAAY;QAC9B,QAAQ,EAAE,OAAO,CAAC,YAAY;KAC/B,EACD,KAAK,CACN,CAAC;AACJ,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,eAAe,CAC7B,UAA6B,EAC7B,OAAe,EACf,SAAuB,IAAI,CAAC,MAAM;IAElC,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC;IAChE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACrF,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC;AACnC,CAAC","sourcesContent":["/**\n * Pure, DOM-free parsing of the blob authoring options. Shared by the Astro\n * component (server) and the morph controller (browser) so both read the same\n * `data-blob-*` contract and clamp values identically.\n */\n\nexport const BLOB_MORPH_MODES = [\"none\", \"auto\", \"hover\"] as const;\nexport type BlobMorphMode = (typeof BLOB_MORPH_MODES)[number];\n\nexport const BLOB_CONTENT_FITS = [\"cover\", \"center\"] as const;\nexport type BlobContentFit = (typeof BLOB_CONTENT_FITS)[number];\n\nexport const BLOB_ASPECT_RATIOS = [\"natural\", \"square\", \"portrait\", \"landscape\"] as const;\nexport type BlobAspectRatio = (typeof BLOB_ASPECT_RATIOS)[number];\n\nexport const BLOB_DEFAULT_MORPH_DURATION = 2400;\nexport const BLOB_DEFAULT_MORPH_INTERVAL = 1200;\nexport const BLOB_DEFAULT_OUTLINE_WIDTH = 2;\n\nexport interface BlobMorphConfig {\n mode: BlobMorphMode;\n /** Zero-based index of the variant the blob rests on. */\n base: number;\n /** Zero-based variants the blob may morph into. */\n targets: number[];\n duration: number;\n interval: number;\n}\n\nexport function clampNumber(value: unknown, min: number, max: number, fallback: number): number {\n const number = typeof value === \"number\" ? value : Number(value);\n if (value === \"\" || value === null || value === undefined || !Number.isFinite(number)) {\n return fallback;\n }\n return Math.min(max, Math.max(min, number));\n}\n\nfunction oneOf<T extends string>(values: readonly T[], value: unknown, fallback: T): T {\n return typeof value === \"string\" && (values as readonly string[]).includes(value)\n ? (value as T)\n : fallback;\n}\n\n/** Authors count from 1; the registry is zero-based. Invalid input rests on variant 1. */\nexport function resolveVariantIndex(value: unknown, count: number): number {\n const number = typeof value === \"number\" ? value : Number(String(value ?? \"\"));\n return Number.isInteger(number) && number >= 1 && number <= count ? number - 1 : 0;\n}\n\n/**\n * `\"2, 5, 9\"` or `[2, 5, 9]` → zero-based unique indices in authoring order.\n * Empty input means every variant; unknown numbers are ignored.\n */\nexport function parseVariantList(value: unknown, count: number): number[] {\n const parts = Array.isArray(value) ? value : String(value ?? \"\").split(/[\\s,;]+/);\n const indices: number[] = [];\n for (const part of parts) {\n const number = typeof part === \"number\" ? part : Number(String(part));\n if (Number.isInteger(number) && number >= 1 && number <= count && !indices.includes(number - 1)) {\n indices.push(number - 1);\n }\n }\n return indices.length > 0 ? indices : Array.from({ length: count }, (_, index) => index);\n}\n\nexport const resolveMorphMode = (value: unknown): BlobMorphMode =>\n oneOf(BLOB_MORPH_MODES, value, \"none\");\nexport const resolveContentFit = (value: unknown): BlobContentFit =>\n oneOf(BLOB_CONTENT_FITS, value, \"cover\");\nexport const resolveAspectRatio = (value: unknown): BlobAspectRatio =>\n oneOf(BLOB_ASPECT_RATIOS, value, \"natural\");\n\nexport function resolveOutlineWidth(value: unknown): number {\n return clampNumber(value, 0, 12, BLOB_DEFAULT_OUTLINE_WIDTH);\n}\n\nexport interface BlobMorphInput {\n variant?: unknown;\n morph?: unknown;\n targets?: unknown;\n duration?: unknown;\n interval?: unknown;\n}\n\nexport function resolveMorphConfig(input: BlobMorphInput, count: number): BlobMorphConfig {\n return {\n mode: resolveMorphMode(input.morph),\n base: resolveVariantIndex(input.variant, count),\n targets: parseVariantList(input.targets, count),\n duration: clampNumber(input.duration, 400, 10000, BLOB_DEFAULT_MORPH_DURATION),\n interval: clampNumber(input.interval, 0, 30000, BLOB_DEFAULT_MORPH_INTERVAL),\n };\n}\n\n/** The `data-blob-*` attributes the server writes and the controller reads back. */\nexport function morphDataAttributes(config: BlobMorphConfig): Record<string, string> {\n return {\n \"data-blob-variant\": String(config.base + 1),\n \"data-blob-morph\": config.mode,\n \"data-blob-targets\": config.targets.map((index) => index + 1).join(\",\"),\n \"data-blob-duration\": String(config.duration),\n \"data-blob-interval\": String(config.interval),\n };\n}\n\nexport function morphConfigFromDataset(\n dataset: Readonly<Record<string, string | undefined>>,\n count: number,\n): BlobMorphConfig {\n return resolveMorphConfig(\n {\n variant: dataset.blobVariant,\n morph: dataset.blobMorph,\n targets: dataset.blobTargets,\n duration: dataset.blobDuration,\n interval: dataset.blobInterval,\n },\n count,\n );\n}\n\n/** Random candidate different from `current`, or `null` when nothing else is allowed. */\nexport function pickMorphTarget(\n candidates: readonly number[],\n current: number,\n random: () => number = Math.random,\n): number | null {\n const options = candidates.filter((index) => index !== current);\n if (options.length === 0) return null;\n const position = Math.min(options.length - 1, Math.floor(random() * options.length));\n return options[position] ?? null;\n}\n"]}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, DOM-free parsing of the blob authoring options. Shared by the Astro
|
|
3
|
+
* component (server) and the morph controller (browser) so both read the same
|
|
4
|
+
* `data-blob-*` contract and clamp values identically.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const BLOB_MORPH_MODES = ["none", "auto", "hover"] as const;
|
|
8
|
+
export type BlobMorphMode = (typeof BLOB_MORPH_MODES)[number];
|
|
9
|
+
|
|
10
|
+
export const BLOB_CONTENT_FITS = ["cover", "center"] as const;
|
|
11
|
+
export type BlobContentFit = (typeof BLOB_CONTENT_FITS)[number];
|
|
12
|
+
|
|
13
|
+
export const BLOB_ASPECT_RATIOS = ["natural", "square", "portrait", "landscape"] as const;
|
|
14
|
+
export type BlobAspectRatio = (typeof BLOB_ASPECT_RATIOS)[number];
|
|
15
|
+
|
|
16
|
+
export const BLOB_DEFAULT_MORPH_DURATION = 2400;
|
|
17
|
+
export const BLOB_DEFAULT_MORPH_INTERVAL = 1200;
|
|
18
|
+
export const BLOB_DEFAULT_OUTLINE_WIDTH = 2;
|
|
19
|
+
|
|
20
|
+
export interface BlobMorphConfig {
|
|
21
|
+
mode: BlobMorphMode;
|
|
22
|
+
/** Zero-based index of the variant the blob rests on. */
|
|
23
|
+
base: number;
|
|
24
|
+
/** Zero-based variants the blob may morph into. */
|
|
25
|
+
targets: number[];
|
|
26
|
+
duration: number;
|
|
27
|
+
interval: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function clampNumber(value: unknown, min: number, max: number, fallback: number): number {
|
|
31
|
+
const number = typeof value === "number" ? value : Number(value);
|
|
32
|
+
if (value === "" || value === null || value === undefined || !Number.isFinite(number)) {
|
|
33
|
+
return fallback;
|
|
34
|
+
}
|
|
35
|
+
return Math.min(max, Math.max(min, number));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function oneOf<T extends string>(values: readonly T[], value: unknown, fallback: T): T {
|
|
39
|
+
return typeof value === "string" && (values as readonly string[]).includes(value)
|
|
40
|
+
? (value as T)
|
|
41
|
+
: fallback;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Authors count from 1; the registry is zero-based. Invalid input rests on variant 1. */
|
|
45
|
+
export function resolveVariantIndex(value: unknown, count: number): number {
|
|
46
|
+
const number = typeof value === "number" ? value : Number(String(value ?? ""));
|
|
47
|
+
return Number.isInteger(number) && number >= 1 && number <= count ? number - 1 : 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* `"2, 5, 9"` or `[2, 5, 9]` → zero-based unique indices in authoring order.
|
|
52
|
+
* Empty input means every variant; unknown numbers are ignored.
|
|
53
|
+
*/
|
|
54
|
+
export function parseVariantList(value: unknown, count: number): number[] {
|
|
55
|
+
const parts = Array.isArray(value) ? value : String(value ?? "").split(/[\s,;]+/);
|
|
56
|
+
const indices: number[] = [];
|
|
57
|
+
for (const part of parts) {
|
|
58
|
+
const number = typeof part === "number" ? part : Number(String(part));
|
|
59
|
+
if (Number.isInteger(number) && number >= 1 && number <= count && !indices.includes(number - 1)) {
|
|
60
|
+
indices.push(number - 1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return indices.length > 0 ? indices : Array.from({ length: count }, (_, index) => index);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const resolveMorphMode = (value: unknown): BlobMorphMode =>
|
|
67
|
+
oneOf(BLOB_MORPH_MODES, value, "none");
|
|
68
|
+
export const resolveContentFit = (value: unknown): BlobContentFit =>
|
|
69
|
+
oneOf(BLOB_CONTENT_FITS, value, "cover");
|
|
70
|
+
export const resolveAspectRatio = (value: unknown): BlobAspectRatio =>
|
|
71
|
+
oneOf(BLOB_ASPECT_RATIOS, value, "natural");
|
|
72
|
+
|
|
73
|
+
export function resolveOutlineWidth(value: unknown): number {
|
|
74
|
+
return clampNumber(value, 0, 12, BLOB_DEFAULT_OUTLINE_WIDTH);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface BlobMorphInput {
|
|
78
|
+
variant?: unknown;
|
|
79
|
+
morph?: unknown;
|
|
80
|
+
targets?: unknown;
|
|
81
|
+
duration?: unknown;
|
|
82
|
+
interval?: unknown;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function resolveMorphConfig(input: BlobMorphInput, count: number): BlobMorphConfig {
|
|
86
|
+
return {
|
|
87
|
+
mode: resolveMorphMode(input.morph),
|
|
88
|
+
base: resolveVariantIndex(input.variant, count),
|
|
89
|
+
targets: parseVariantList(input.targets, count),
|
|
90
|
+
duration: clampNumber(input.duration, 400, 10000, BLOB_DEFAULT_MORPH_DURATION),
|
|
91
|
+
interval: clampNumber(input.interval, 0, 30000, BLOB_DEFAULT_MORPH_INTERVAL),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The `data-blob-*` attributes the server writes and the controller reads back. */
|
|
96
|
+
export function morphDataAttributes(config: BlobMorphConfig): Record<string, string> {
|
|
97
|
+
return {
|
|
98
|
+
"data-blob-variant": String(config.base + 1),
|
|
99
|
+
"data-blob-morph": config.mode,
|
|
100
|
+
"data-blob-targets": config.targets.map((index) => index + 1).join(","),
|
|
101
|
+
"data-blob-duration": String(config.duration),
|
|
102
|
+
"data-blob-interval": String(config.interval),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function morphConfigFromDataset(
|
|
107
|
+
dataset: Readonly<Record<string, string | undefined>>,
|
|
108
|
+
count: number,
|
|
109
|
+
): BlobMorphConfig {
|
|
110
|
+
return resolveMorphConfig(
|
|
111
|
+
{
|
|
112
|
+
variant: dataset.blobVariant,
|
|
113
|
+
morph: dataset.blobMorph,
|
|
114
|
+
targets: dataset.blobTargets,
|
|
115
|
+
duration: dataset.blobDuration,
|
|
116
|
+
interval: dataset.blobInterval,
|
|
117
|
+
},
|
|
118
|
+
count,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Random candidate different from `current`, or `null` when nothing else is allowed. */
|
|
123
|
+
export function pickMorphTarget(
|
|
124
|
+
candidates: readonly number[],
|
|
125
|
+
current: number,
|
|
126
|
+
random: () => number = Math.random,
|
|
127
|
+
): number | null {
|
|
128
|
+
const options = candidates.filter((index) => index !== current);
|
|
129
|
+
if (options.length === 0) return null;
|
|
130
|
+
const position = Math.min(options.length - 1, Math.floor(random() * options.length));
|
|
131
|
+
return options[position] ?? null;
|
|
132
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const BLOB_ROOT_SELECTOR = "[data-sf-blob]";
|
|
2
|
+
export declare const CARD_ANIMATION_CLASS = "card__animation";
|
|
3
|
+
export declare const CARD_ANIMATION_TRIGGER_SELECTOR = ".card__has_animations";
|
|
4
|
+
/**
|
|
5
|
+
* Wire every `[data-sf-blob]` with `data-blob-morph` set to `auto` or `hover`.
|
|
6
|
+
* Blobs are wired even while motion is reduced, so allowing it again starts
|
|
7
|
+
* them without a reload. Returns a disposer that restores the static state
|
|
8
|
+
* (for tests and view swaps).
|
|
9
|
+
*/
|
|
10
|
+
export declare function initializeSfBlobs(scope?: ParentNode): () => void;
|
|
11
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/astro/native/blob/controller.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AACnD,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AACtD,eAAO,MAAM,+BAA+B,0BAA0B,CAAC;AAmMvE;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,GAAE,UAAqB,GAAG,MAAM,IAAI,CAsB1E"}
|
|
@@ -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,CAAwB;IAChC,SAAS,GAAsB,EAAE,CAAC;IAEnD,YACmB,IAAiB,EACjB,MAAuB,EACvB,SAAoB;QAFpB,SAAI,GAAJ,IAAI,CAAa;QACjB,WAAM,GAAN,MAAM,CAAiB;QACvB,cAAS,GAAT,SAAS,CAAW;QAErC,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,IAAK,aAAa,CAAC,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AM,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"]}
|