@styleflow.app/flowpress-astro-core 1.0.0-beta.16 → 1.0.0-beta.17
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 +5 -0
- package/README.md +2 -0
- package/dist/astro/BaseLayout.astro +6 -6
- package/dist/astro/CompositionRenderer.astro +6 -6
- package/dist/astro/GutenbergRenderer.astro +33 -20
- package/dist/astro/blocks/CarouselBlock.astro +3 -3
- package/dist/astro/blocks/CarouselItemBlock.astro +1 -1
- package/dist/astro/blocks/ColumnBlock.astro +1 -1
- package/dist/astro/blocks/CoverBlock.astro +3 -3
- package/dist/astro/blocks/FormBlock.astro +13 -11
- package/dist/astro/blocks/GridBlock.astro +1 -1
- package/dist/astro/blocks/HeroBlock.astro +1 -1
- package/dist/astro/blocks/ImageBlock.astro +1 -1
- package/dist/astro/blocks/NumberSpinnerBlock.astro +1 -1
- package/dist/astro/blocks/SemanticElement.astro +2 -2
- package/dist/astro/blocks/SiteLogoBlock.astro +4 -4
- package/dist/astro/blocks/TextBlock.astro +2 -2
- package/dist/astro/blocks/cover.d.ts +2 -1
- package/dist/astro/blocks/cover.d.ts.map +1 -1
- package/dist/astro/blocks/cover.js.map +1 -1
- package/dist/astro/blocks/cover.ts +3 -2
- package/dist/astro/native/Blob.astro +113 -0
- package/dist/astro/native/BlobBlock.astro +52 -0
- package/dist/astro/native/CustomFieldValue.astro +86 -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 +33 -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 +37 -0
- package/dist/astro/native/Timeline.astro +20 -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 +11 -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 +70 -0
- package/dist/astro/native/core-navigation-submenu.astro +32 -0
- package/dist/astro/native/core-navigation.astro +94 -0
- package/dist/astro/native/core-page-list-data-item.astro +18 -0
- package/dist/astro/native/core-page-list-item.astro +7 -0
- package/dist/astro/native/core-page-list.astro +40 -0
- package/dist/astro/native/core-post-date.astro +20 -0
- package/dist/astro/native/core-post-excerpt.astro +25 -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 +46 -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-site-title.astro +15 -0
- package/dist/astro/native/core-term-description.astro +12 -0
- package/dist/astro/native/core-term-name.astro +20 -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/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 +72 -0
- package/dist/astro/native/registry.js.map +1 -0
- package/dist/astro/native/registry.ts +72 -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/block-renderers.d.ts +3 -3
- package/dist/block-renderers.d.ts.map +1 -1
- package/dist/block-renderers.js.map +1 -1
- package/dist/default-blocks.d.ts +1 -1
- package/dist/default-blocks.d.ts.map +1 -1
- package/dist/default-blocks.js +36 -2
- package/dist/default-blocks.js.map +1 -1
- package/dist/templates.d.ts +16 -16
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { normalizeIconSvg, scopeIconSvgIds } from "@styleflow.app/flowpress-components/icon-svg";
|
|
2
|
+
|
|
3
|
+
export function nativeIconWidth(value: unknown): string | undefined {
|
|
4
|
+
if (typeof value !== "string") return undefined;
|
|
5
|
+
const match = value.trim().match(/^(\d+(?:\.\d+)?|\.\d+)(px|rem|em|%|vw|vh)$/);
|
|
6
|
+
if (!match) return undefined;
|
|
7
|
+
const limit = match[2] === "px" ? 1536 : ["%", "vw", "vh"].includes(match[2]!) ? 100 : 96;
|
|
8
|
+
return Number(match[1]) > 0 && Number(match[1]) <= limit ? value.trim() : undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function nativeIconSvg(name: unknown, resolved: unknown, prefix: string): string | undefined {
|
|
12
|
+
if (typeof name !== "string") return undefined;
|
|
13
|
+
let svg: string | undefined;
|
|
14
|
+
if (!svg) {
|
|
15
|
+
const data = resolved && typeof resolved === "object" ? resolved as Record<string, unknown> : {};
|
|
16
|
+
if (data.name === name && data.empty === false && typeof data.svg === "string" && data.svg) {
|
|
17
|
+
svg = normalizeIconSvg(data.svg, name);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return svg ? scopeIconSvgIds(svg, prefix) : undefined;
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type MapAttributes = {
|
|
2
|
+
address?: unknown;
|
|
3
|
+
latitude?: unknown;
|
|
4
|
+
longitude?: unknown;
|
|
5
|
+
provider?: unknown;
|
|
6
|
+
zoom?: unknown;
|
|
7
|
+
};
|
|
8
|
+
export declare function resolveMap(attributes: MapAttributes, googleKey?: string): {
|
|
9
|
+
address: string;
|
|
10
|
+
query: string;
|
|
11
|
+
iframeSrc: string;
|
|
12
|
+
linkHref: string;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../../src/astro/native/map.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAeF,wBAAgB,UAAU,CAAC,UAAU,EAAE,aAAa,EAAE,SAAS,SAAK;;;;;EAgDnE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const coordinate = (value, limit) => {
|
|
2
|
+
if (typeof value !== "string" && typeof value !== "number")
|
|
3
|
+
return null;
|
|
4
|
+
const normalized = String(value).trim().replace(",", ".");
|
|
5
|
+
if (!normalized)
|
|
6
|
+
return null;
|
|
7
|
+
const number = Number(normalized);
|
|
8
|
+
return Number.isFinite(number) && Math.abs(number) <= limit ? number : null;
|
|
9
|
+
};
|
|
10
|
+
const zoomValue = (value) => {
|
|
11
|
+
const number = Number(value);
|
|
12
|
+
return Number.isFinite(number) ? Math.max(1, Math.min(20, Math.round(number))) : 14;
|
|
13
|
+
};
|
|
14
|
+
export function resolveMap(attributes, googleKey = "") {
|
|
15
|
+
const address = typeof attributes.address === "string" ? attributes.address.trim() : "";
|
|
16
|
+
const latitude = coordinate(attributes.latitude, 90);
|
|
17
|
+
const longitude = coordinate(attributes.longitude, 180);
|
|
18
|
+
const hasCoordinates = latitude !== null && longitude !== null;
|
|
19
|
+
const query = hasCoordinates ? `${latitude},${longitude}` : address;
|
|
20
|
+
const provider = attributes.provider === "google" ? "google" : "openstreetmap";
|
|
21
|
+
const zoom = zoomValue(attributes.zoom);
|
|
22
|
+
if (!query)
|
|
23
|
+
return { address, query, iframeSrc: "", linkHref: "" };
|
|
24
|
+
if (provider === "google") {
|
|
25
|
+
const link = new URL("https://www.google.com/maps/search/");
|
|
26
|
+
link.search = new URLSearchParams({ api: "1", query }).toString();
|
|
27
|
+
const embed = new URL("https://www.google.com/maps/embed/v1/place");
|
|
28
|
+
embed.search = new URLSearchParams({ key: googleKey, q: query, zoom: String(zoom) }).toString();
|
|
29
|
+
return {
|
|
30
|
+
address,
|
|
31
|
+
query,
|
|
32
|
+
iframeSrc: googleKey.trim() ? embed.toString() : "",
|
|
33
|
+
linkHref: link.toString(),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (!hasCoordinates) {
|
|
37
|
+
return {
|
|
38
|
+
address,
|
|
39
|
+
query,
|
|
40
|
+
iframeSrc: "",
|
|
41
|
+
linkHref: `https://www.openstreetmap.org/search?query=${encodeURIComponent(query)}`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const halfDelta = Math.max(0.001, 180 / 2 ** zoom);
|
|
45
|
+
const bbox = [
|
|
46
|
+
Math.max(-180, longitude - halfDelta),
|
|
47
|
+
Math.max(-90, latitude - halfDelta),
|
|
48
|
+
Math.min(180, longitude + halfDelta),
|
|
49
|
+
Math.min(90, latitude + halfDelta),
|
|
50
|
+
].join(",");
|
|
51
|
+
const embed = new URL("https://www.openstreetmap.org/export/embed.html");
|
|
52
|
+
embed.search = new URLSearchParams({ bbox, layer: "mapnik", marker: query }).toString();
|
|
53
|
+
return {
|
|
54
|
+
address,
|
|
55
|
+
query,
|
|
56
|
+
iframeSrc: embed.toString(),
|
|
57
|
+
linkHref: `https://www.openstreetmap.org/?mlat=${latitude}&mlon=${longitude}#map=${zoom}/${latitude}/${longitude}`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../../src/astro/native/map.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,GAAG,CAAC,KAAc,EAAE,KAAa,EAAiB,EAAE;IAClE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AE,8CAA8C,kBAAkB,CAAC,KAAK,CAAC,EAAE;SACpF,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC;IACnD,MAAM,IAAI,GAAG;QACX,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,SAAS,GAAG,SAAS,CAAC;QACrC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,QAAQ,GAAG,SAAS,CAAC;QACnC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,GAAG,SAAS,CAAC;QACpC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,GAAG,SAAS,CAAC;KACnC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,iDAAiD,CAAC,CAAC;IACzE,KAAK,CAAC,MAAM,GAAG,IAAI,eAAe,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;IACxF,OAAO;QACL,OAAO;QACP,KAAK;QACL,SAAS,EAAE,KAAK,CAAC,QAAQ,EAAE;QAC3B,QAAQ,EAAE,uCAAuC,QAAQ,SAAS,SAAS,QAAQ,IAAI,IAAI,QAAQ,IAAI,SAAS,EAAE;KACnH,CAAC;AACJ,CAAC","sourcesContent":["export type MapAttributes = {\n address?: unknown;\n latitude?: unknown;\n longitude?: unknown;\n provider?: unknown;\n zoom?: unknown;\n};\n\nconst coordinate = (value: unknown, limit: number): number | null => {\n if (typeof value !== \"string\" && typeof value !== \"number\") return null;\n const normalized = String(value).trim().replace(\",\", \".\");\n if (!normalized) return null;\n const number = Number(normalized);\n return Number.isFinite(number) && Math.abs(number) <= limit ? number : null;\n};\n\nconst zoomValue = (value: unknown): number => {\n const number = Number(value);\n return Number.isFinite(number) ? Math.max(1, Math.min(20, Math.round(number))) : 14;\n};\n\nexport function resolveMap(attributes: MapAttributes, googleKey = \"\") {\n const address = typeof attributes.address === \"string\" ? attributes.address.trim() : \"\";\n const latitude = coordinate(attributes.latitude, 90);\n const longitude = coordinate(attributes.longitude, 180);\n const hasCoordinates = latitude !== null && longitude !== null;\n const query = hasCoordinates ? `${latitude},${longitude}` : address;\n const provider = attributes.provider === \"google\" ? \"google\" : \"openstreetmap\";\n const zoom = zoomValue(attributes.zoom);\n\n if (!query) return { address, query, iframeSrc: \"\", linkHref: \"\" };\n\n if (provider === \"google\") {\n const link = new URL(\"https://www.google.com/maps/search/\");\n link.search = new URLSearchParams({ api: \"1\", query }).toString();\n const embed = new URL(\"https://www.google.com/maps/embed/v1/place\");\n embed.search = new URLSearchParams({ key: googleKey, q: query, zoom: String(zoom) }).toString();\n return {\n address,\n query,\n iframeSrc: googleKey.trim() ? embed.toString() : \"\",\n linkHref: link.toString(),\n };\n }\n\n if (!hasCoordinates) {\n return {\n address,\n query,\n iframeSrc: \"\",\n linkHref: `https://www.openstreetmap.org/search?query=${encodeURIComponent(query)}`,\n };\n }\n\n const halfDelta = Math.max(0.001, 180 / 2 ** zoom);\n const bbox = [\n Math.max(-180, longitude - halfDelta),\n Math.max(-90, latitude - halfDelta),\n Math.min(180, longitude + halfDelta),\n Math.min(90, latitude + halfDelta),\n ].join(\",\");\n const embed = new URL(\"https://www.openstreetmap.org/export/embed.html\");\n embed.search = new URLSearchParams({ bbox, layer: \"mapnik\", marker: query }).toString();\n return {\n address,\n query,\n iframeSrc: embed.toString(),\n linkHref: `https://www.openstreetmap.org/?mlat=${latitude}&mlon=${longitude}#map=${zoom}/${latitude}/${longitude}`,\n };\n}\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type MapAttributes = {
|
|
2
|
+
address?: unknown;
|
|
3
|
+
latitude?: unknown;
|
|
4
|
+
longitude?: unknown;
|
|
5
|
+
provider?: unknown;
|
|
6
|
+
zoom?: unknown;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const coordinate = (value: unknown, limit: number): number | null => {
|
|
10
|
+
if (typeof value !== "string" && typeof value !== "number") return null;
|
|
11
|
+
const normalized = String(value).trim().replace(",", ".");
|
|
12
|
+
if (!normalized) return null;
|
|
13
|
+
const number = Number(normalized);
|
|
14
|
+
return Number.isFinite(number) && Math.abs(number) <= limit ? number : null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const zoomValue = (value: unknown): number => {
|
|
18
|
+
const number = Number(value);
|
|
19
|
+
return Number.isFinite(number) ? Math.max(1, Math.min(20, Math.round(number))) : 14;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function resolveMap(attributes: MapAttributes, googleKey = "") {
|
|
23
|
+
const address = typeof attributes.address === "string" ? attributes.address.trim() : "";
|
|
24
|
+
const latitude = coordinate(attributes.latitude, 90);
|
|
25
|
+
const longitude = coordinate(attributes.longitude, 180);
|
|
26
|
+
const hasCoordinates = latitude !== null && longitude !== null;
|
|
27
|
+
const query = hasCoordinates ? `${latitude},${longitude}` : address;
|
|
28
|
+
const provider = attributes.provider === "google" ? "google" : "openstreetmap";
|
|
29
|
+
const zoom = zoomValue(attributes.zoom);
|
|
30
|
+
|
|
31
|
+
if (!query) return { address, query, iframeSrc: "", linkHref: "" };
|
|
32
|
+
|
|
33
|
+
if (provider === "google") {
|
|
34
|
+
const link = new URL("https://www.google.com/maps/search/");
|
|
35
|
+
link.search = new URLSearchParams({ api: "1", query }).toString();
|
|
36
|
+
const embed = new URL("https://www.google.com/maps/embed/v1/place");
|
|
37
|
+
embed.search = new URLSearchParams({ key: googleKey, q: query, zoom: String(zoom) }).toString();
|
|
38
|
+
return {
|
|
39
|
+
address,
|
|
40
|
+
query,
|
|
41
|
+
iframeSrc: googleKey.trim() ? embed.toString() : "",
|
|
42
|
+
linkHref: link.toString(),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!hasCoordinates) {
|
|
47
|
+
return {
|
|
48
|
+
address,
|
|
49
|
+
query,
|
|
50
|
+
iframeSrc: "",
|
|
51
|
+
linkHref: `https://www.openstreetmap.org/search?query=${encodeURIComponent(query)}`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const halfDelta = Math.max(0.001, 180 / 2 ** zoom);
|
|
56
|
+
const bbox = [
|
|
57
|
+
Math.max(-180, longitude - halfDelta),
|
|
58
|
+
Math.max(-90, latitude - halfDelta),
|
|
59
|
+
Math.min(180, longitude + halfDelta),
|
|
60
|
+
Math.min(90, latitude + halfDelta),
|
|
61
|
+
].join(",");
|
|
62
|
+
const embed = new URL("https://www.openstreetmap.org/export/embed.html");
|
|
63
|
+
embed.search = new URLSearchParams({ bbox, layer: "mapnik", marker: query }).toString();
|
|
64
|
+
return {
|
|
65
|
+
address,
|
|
66
|
+
query,
|
|
67
|
+
iframeSrc: embed.toString(),
|
|
68
|
+
linkHref: `https://www.openstreetmap.org/?mlat=${latitude}&mlon=${longitude}#map=${zoom}/${latitude}/${longitude}`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for "may this page animate?".
|
|
3
|
+
*
|
|
4
|
+
* The default follows the OS (`prefers-reduced-motion`). A visitor's explicit
|
|
5
|
+
* choice from the accessibility panel wins in both directions and is stored in
|
|
6
|
+
* localStorage. The resolved value is mirrored on
|
|
7
|
+
* `<html data-sf-motion-preference="full|reduce">`, so CSS and scripts read the
|
|
8
|
+
* same state, and every change is announced with `sf:motion-change`.
|
|
9
|
+
*
|
|
10
|
+
* Do not read `matchMedia("(prefers-reduced-motion)")` or write a bare
|
|
11
|
+
* `@media (prefers-reduced-motion)` rule elsewhere: neither can be overridden
|
|
12
|
+
* by the visitor.
|
|
13
|
+
*/
|
|
14
|
+
export declare const MOTION_STORAGE_KEY = "sf:motion";
|
|
15
|
+
export declare const MOTION_ATTRIBUTE = "data-sf-motion-preference";
|
|
16
|
+
export declare const MOTION_CHANGE_EVENT = "sf:motion-change";
|
|
17
|
+
export declare const MOTION_TOGGLE_SELECTOR = "[data-sf-motion-toggle]";
|
|
18
|
+
export declare const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
19
|
+
/** `full` animates, `reduce` keeps everything still. */
|
|
20
|
+
export type MotionPreference = "full" | "reduce";
|
|
21
|
+
export declare function isMotionPreference(value: unknown): value is MotionPreference;
|
|
22
|
+
/** An explicit choice beats the OS; without one the OS decides. */
|
|
23
|
+
export declare function resolveMotionPreference(stored: unknown, systemReduces: boolean): MotionPreference;
|
|
24
|
+
/**
|
|
25
|
+
* Inline script for `<head>`: mirrors the resolved preference on `<html>`
|
|
26
|
+
* before first paint, so nothing starts animating and then snaps to a stop.
|
|
27
|
+
*/
|
|
28
|
+
export declare function motionPreferenceBootstrapScript(): string;
|
|
29
|
+
/** The browser surface this module needs, injectable for tests. */
|
|
30
|
+
export interface MotionEnvironment {
|
|
31
|
+
document: Pick<Document, "documentElement" | "dispatchEvent" | "addEventListener" | "removeEventListener">;
|
|
32
|
+
storage: Pick<Storage, "getItem" | "setItem"> | null;
|
|
33
|
+
media: Pick<MediaQueryList, "matches" | "addEventListener" | "removeEventListener"> | null;
|
|
34
|
+
}
|
|
35
|
+
export declare function browserMotionEnvironment(): MotionEnvironment;
|
|
36
|
+
/** The mirrored value when the bootstrap ran, otherwise resolved from storage and OS. */
|
|
37
|
+
export declare function getMotionPreference(env?: MotionEnvironment): MotionPreference;
|
|
38
|
+
/** Store an explicit choice and announce it. */
|
|
39
|
+
export declare function setMotionPreference(preference: MotionPreference, env?: MotionEnvironment): void;
|
|
40
|
+
/**
|
|
41
|
+
* Call `listener` whenever the effective preference changes: an explicit
|
|
42
|
+
* choice, or the OS setting while the visitor has not made one.
|
|
43
|
+
*/
|
|
44
|
+
export declare function subscribeMotionPreference(listener: (preference: MotionPreference) => void, env?: MotionEnvironment): () => void;
|
|
45
|
+
/**
|
|
46
|
+
* Wire every server-rendered `[data-sf-motion-toggle]` switch: a click flips
|
|
47
|
+
* the preference, `aria-checked` mirrors it (checked means animations on).
|
|
48
|
+
*/
|
|
49
|
+
export declare function initializeMotionToggles(scope?: ParentNode, env?: MotionEnvironment): () => void;
|
|
50
|
+
//# sourceMappingURL=motion-preference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion-preference.d.ts","sourceRoot":"","sources":["../../../src/astro/native/motion-preference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAC9C,eAAO,MAAM,gBAAgB,8BAA8B,CAAC;AAC5D,eAAO,MAAM,mBAAmB,qBAAqB,CAAC;AACtD,eAAO,MAAM,sBAAsB,4BAA4B,CAAC;AAChE,eAAO,MAAM,oBAAoB,qCAAqC,CAAC;AAEvE,wDAAwD;AACxD,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEjD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAE5E;AAED,mEAAmE;AACnE,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,GAAG,gBAAgB,CAGjG;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,IAAI,MAAM,CAKxD;AAED,mEAAmE;AACnE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,iBAAiB,GAAG,eAAe,GAAG,kBAAkB,GAAG,qBAAqB,CAAC,CAAC;IAC3G,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;IACrD,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,kBAAkB,GAAG,qBAAqB,CAAC,GAAG,IAAI,CAAC;CAC5F;AAED,wBAAgB,wBAAwB,IAAI,iBAAiB,CAY5D;AAeD,yFAAyF;AACzF,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,iBAA8C,GAAG,gBAAgB,CAEzG;AAQD,gDAAgD;AAChD,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,gBAAgB,EAC5B,GAAG,GAAE,iBAA8C,GAClD,IAAI,CAON;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,CAAC,UAAU,EAAE,gBAAgB,KAAK,IAAI,EAChD,GAAG,GAAE,iBAA8C,GAClD,MAAM,IAAI,CAeZ;AAID;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,GAAE,UAAqB,EAC5B,GAAG,GAAE,iBAA8C,GAClD,MAAM,IAAI,CAsBZ"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for "may this page animate?".
|
|
3
|
+
*
|
|
4
|
+
* The default follows the OS (`prefers-reduced-motion`). A visitor's explicit
|
|
5
|
+
* choice from the accessibility panel wins in both directions and is stored in
|
|
6
|
+
* localStorage. The resolved value is mirrored on
|
|
7
|
+
* `<html data-sf-motion-preference="full|reduce">`, so CSS and scripts read the
|
|
8
|
+
* same state, and every change is announced with `sf:motion-change`.
|
|
9
|
+
*
|
|
10
|
+
* Do not read `matchMedia("(prefers-reduced-motion)")` or write a bare
|
|
11
|
+
* `@media (prefers-reduced-motion)` rule elsewhere: neither can be overridden
|
|
12
|
+
* by the visitor.
|
|
13
|
+
*/
|
|
14
|
+
export const MOTION_STORAGE_KEY = "sf:motion";
|
|
15
|
+
export const MOTION_ATTRIBUTE = "data-sf-motion-preference";
|
|
16
|
+
export const MOTION_CHANGE_EVENT = "sf:motion-change";
|
|
17
|
+
export const MOTION_TOGGLE_SELECTOR = "[data-sf-motion-toggle]";
|
|
18
|
+
export const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
19
|
+
export function isMotionPreference(value) {
|
|
20
|
+
return value === "full" || value === "reduce";
|
|
21
|
+
}
|
|
22
|
+
/** An explicit choice beats the OS; without one the OS decides. */
|
|
23
|
+
export function resolveMotionPreference(stored, systemReduces) {
|
|
24
|
+
if (isMotionPreference(stored))
|
|
25
|
+
return stored;
|
|
26
|
+
return systemReduces ? "reduce" : "full";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Inline script for `<head>`: mirrors the resolved preference on `<html>`
|
|
30
|
+
* before first paint, so nothing starts animating and then snaps to a stop.
|
|
31
|
+
*/
|
|
32
|
+
export function motionPreferenceBootstrapScript() {
|
|
33
|
+
const key = JSON.stringify(MOTION_STORAGE_KEY);
|
|
34
|
+
const query = JSON.stringify(REDUCED_MOTION_QUERY);
|
|
35
|
+
const attribute = JSON.stringify(MOTION_ATTRIBUTE);
|
|
36
|
+
return `(()=>{let s=null,r=false;try{s=localStorage.getItem(${key})}catch{}try{r=matchMedia(${query}).matches}catch{}document.documentElement.setAttribute(${attribute},s==="full"||s==="reduce"?s:r?"reduce":"full")})()`;
|
|
37
|
+
}
|
|
38
|
+
export function browserMotionEnvironment() {
|
|
39
|
+
let storage = null;
|
|
40
|
+
try {
|
|
41
|
+
storage = localStorage;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Blocked storage keeps the preference in memory for the page only.
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
document,
|
|
48
|
+
storage,
|
|
49
|
+
media: typeof matchMedia === "function" ? matchMedia(REDUCED_MOTION_QUERY) : null,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function readStored(env) {
|
|
53
|
+
try {
|
|
54
|
+
return env.storage?.getItem(MOTION_STORAGE_KEY) ?? null;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function mirrored(env) {
|
|
61
|
+
const value = env.document.documentElement.getAttribute(MOTION_ATTRIBUTE);
|
|
62
|
+
return isMotionPreference(value) ? value : null;
|
|
63
|
+
}
|
|
64
|
+
/** The mirrored value when the bootstrap ran, otherwise resolved from storage and OS. */
|
|
65
|
+
export function getMotionPreference(env = browserMotionEnvironment()) {
|
|
66
|
+
return mirrored(env) ?? resolveMotionPreference(readStored(env), env.media?.matches ?? false);
|
|
67
|
+
}
|
|
68
|
+
function apply(preference, env) {
|
|
69
|
+
if (mirrored(env) === preference)
|
|
70
|
+
return;
|
|
71
|
+
env.document.documentElement.setAttribute(MOTION_ATTRIBUTE, preference);
|
|
72
|
+
env.document.dispatchEvent(new CustomEvent(MOTION_CHANGE_EVENT, { detail: { preference } }));
|
|
73
|
+
}
|
|
74
|
+
/** Store an explicit choice and announce it. */
|
|
75
|
+
export function setMotionPreference(preference, env = browserMotionEnvironment()) {
|
|
76
|
+
try {
|
|
77
|
+
env.storage?.setItem(MOTION_STORAGE_KEY, preference);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// The choice still applies to this page.
|
|
81
|
+
}
|
|
82
|
+
apply(preference, env);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Call `listener` whenever the effective preference changes: an explicit
|
|
86
|
+
* choice, or the OS setting while the visitor has not made one.
|
|
87
|
+
*/
|
|
88
|
+
export function subscribeMotionPreference(listener, env = browserMotionEnvironment()) {
|
|
89
|
+
const onChange = (event) => {
|
|
90
|
+
const preference = event.detail?.preference;
|
|
91
|
+
if (isMotionPreference(preference))
|
|
92
|
+
listener(preference);
|
|
93
|
+
};
|
|
94
|
+
// Every subscriber may see the OS change; `apply` announces it only once.
|
|
95
|
+
const onSystemChange = () => {
|
|
96
|
+
if (readStored(env) === null)
|
|
97
|
+
apply(resolveMotionPreference(null, env.media?.matches ?? false), env);
|
|
98
|
+
};
|
|
99
|
+
env.document.addEventListener(MOTION_CHANGE_EVENT, onChange);
|
|
100
|
+
env.media?.addEventListener("change", onSystemChange);
|
|
101
|
+
return () => {
|
|
102
|
+
env.document.removeEventListener(MOTION_CHANGE_EVENT, onChange);
|
|
103
|
+
env.media?.removeEventListener("change", onSystemChange);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const TOGGLE_BOUND = "sfMotionToggleBound";
|
|
107
|
+
/**
|
|
108
|
+
* Wire every server-rendered `[data-sf-motion-toggle]` switch: a click flips
|
|
109
|
+
* the preference, `aria-checked` mirrors it (checked means animations on).
|
|
110
|
+
*/
|
|
111
|
+
export function initializeMotionToggles(scope = document, env = browserMotionEnvironment()) {
|
|
112
|
+
const toggles = [...scope.querySelectorAll(MOTION_TOGGLE_SELECTOR)]
|
|
113
|
+
.filter((toggle) => toggle.dataset[TOGGLE_BOUND] !== "true");
|
|
114
|
+
const sync = (preference) => {
|
|
115
|
+
toggles.forEach((toggle) => toggle.setAttribute("aria-checked", String(preference === "full")));
|
|
116
|
+
};
|
|
117
|
+
const flip = () => setMotionPreference(getMotionPreference(env) === "full" ? "reduce" : "full", env);
|
|
118
|
+
toggles.forEach((toggle) => {
|
|
119
|
+
toggle.dataset[TOGGLE_BOUND] = "true";
|
|
120
|
+
toggle.addEventListener("click", flip);
|
|
121
|
+
});
|
|
122
|
+
sync(getMotionPreference(env));
|
|
123
|
+
const unsubscribe = subscribeMotionPreference(sync, env);
|
|
124
|
+
return () => {
|
|
125
|
+
unsubscribe();
|
|
126
|
+
toggles.forEach((toggle) => {
|
|
127
|
+
toggle.removeEventListener("click", flip);
|
|
128
|
+
delete toggle.dataset[TOGGLE_BOUND];
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=motion-preference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion-preference.js","sourceRoot":"","sources":["../../../src/astro/native/motion-preference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AA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AC5C,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;IAClG,CAAC,CAAC;IACF,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAErG,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACzB,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC;QACtC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,MAAM,WAAW,GAAG,yBAAyB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAEzD,OAAO,GAAG,EAAE;QACV,WAAW,EAAE,CAAC;QACd,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACzB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC1C,OAAO,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Single source of truth for \"may this page animate?\".\n *\n * The default follows the OS (`prefers-reduced-motion`). A visitor's explicit\n * choice from the accessibility panel wins in both directions and is stored in\n * localStorage. The resolved value is mirrored on\n * `<html data-sf-motion-preference=\"full|reduce\">`, so CSS and scripts read the\n * same state, and every change is announced with `sf:motion-change`.\n *\n * Do not read `matchMedia(\"(prefers-reduced-motion)\")` or write a bare\n * `@media (prefers-reduced-motion)` rule elsewhere: neither can be overridden\n * by the visitor.\n */\n\nexport const MOTION_STORAGE_KEY = \"sf:motion\";\nexport const MOTION_ATTRIBUTE = \"data-sf-motion-preference\";\nexport const MOTION_CHANGE_EVENT = \"sf:motion-change\";\nexport const MOTION_TOGGLE_SELECTOR = \"[data-sf-motion-toggle]\";\nexport const REDUCED_MOTION_QUERY = \"(prefers-reduced-motion: reduce)\";\n\n/** `full` animates, `reduce` keeps everything still. */\nexport type MotionPreference = \"full\" | \"reduce\";\n\nexport function isMotionPreference(value: unknown): value is MotionPreference {\n return value === \"full\" || value === \"reduce\";\n}\n\n/** An explicit choice beats the OS; without one the OS decides. */\nexport function resolveMotionPreference(stored: unknown, systemReduces: boolean): MotionPreference {\n if (isMotionPreference(stored)) return stored;\n return systemReduces ? \"reduce\" : \"full\";\n}\n\n/**\n * Inline script for `<head>`: mirrors the resolved preference on `<html>`\n * before first paint, so nothing starts animating and then snaps to a stop.\n */\nexport function motionPreferenceBootstrapScript(): string {\n const key = JSON.stringify(MOTION_STORAGE_KEY);\n const query = JSON.stringify(REDUCED_MOTION_QUERY);\n const attribute = JSON.stringify(MOTION_ATTRIBUTE);\n return `(()=>{let s=null,r=false;try{s=localStorage.getItem(${key})}catch{}try{r=matchMedia(${query}).matches}catch{}document.documentElement.setAttribute(${attribute},s===\"full\"||s===\"reduce\"?s:r?\"reduce\":\"full\")})()`;\n}\n\n/** The browser surface this module needs, injectable for tests. */\nexport interface MotionEnvironment {\n document: Pick<Document, \"documentElement\" | \"dispatchEvent\" | \"addEventListener\" | \"removeEventListener\">;\n storage: Pick<Storage, \"getItem\" | \"setItem\"> | null;\n media: Pick<MediaQueryList, \"matches\" | \"addEventListener\" | \"removeEventListener\"> | null;\n}\n\nexport function browserMotionEnvironment(): MotionEnvironment {\n let storage: MotionEnvironment[\"storage\"] = null;\n try {\n storage = localStorage;\n } catch {\n // Blocked storage keeps the preference in memory for the page only.\n }\n return {\n document,\n storage,\n media: typeof matchMedia === \"function\" ? matchMedia(REDUCED_MOTION_QUERY) : null,\n };\n}\n\nfunction readStored(env: MotionEnvironment): string | null {\n try {\n return env.storage?.getItem(MOTION_STORAGE_KEY) ?? null;\n } catch {\n return null;\n }\n}\n\nfunction mirrored(env: MotionEnvironment): MotionPreference | null {\n const value = env.document.documentElement.getAttribute(MOTION_ATTRIBUTE);\n return isMotionPreference(value) ? value : null;\n}\n\n/** The mirrored value when the bootstrap ran, otherwise resolved from storage and OS. */\nexport function getMotionPreference(env: MotionEnvironment = browserMotionEnvironment()): MotionPreference {\n return mirrored(env) ?? resolveMotionPreference(readStored(env), env.media?.matches ?? false);\n}\n\nfunction apply(preference: MotionPreference, env: MotionEnvironment): void {\n if (mirrored(env) === preference) return;\n env.document.documentElement.setAttribute(MOTION_ATTRIBUTE, preference);\n env.document.dispatchEvent(new CustomEvent(MOTION_CHANGE_EVENT, { detail: { preference } }));\n}\n\n/** Store an explicit choice and announce it. */\nexport function setMotionPreference(\n preference: MotionPreference,\n env: MotionEnvironment = browserMotionEnvironment(),\n): void {\n try {\n env.storage?.setItem(MOTION_STORAGE_KEY, preference);\n } catch {\n // The choice still applies to this page.\n }\n apply(preference, env);\n}\n\n/**\n * Call `listener` whenever the effective preference changes: an explicit\n * choice, or the OS setting while the visitor has not made one.\n */\nexport function subscribeMotionPreference(\n listener: (preference: MotionPreference) => void,\n env: MotionEnvironment = browserMotionEnvironment(),\n): () => void {\n const onChange = (event: Event) => {\n const preference = (event as CustomEvent<{ preference?: unknown }>).detail?.preference;\n if (isMotionPreference(preference)) listener(preference);\n };\n // Every subscriber may see the OS change; `apply` announces it only once.\n const onSystemChange = () => {\n if (readStored(env) === null) apply(resolveMotionPreference(null, env.media?.matches ?? false), env);\n };\n env.document.addEventListener(MOTION_CHANGE_EVENT, onChange);\n env.media?.addEventListener(\"change\", onSystemChange);\n return () => {\n env.document.removeEventListener(MOTION_CHANGE_EVENT, onChange);\n env.media?.removeEventListener(\"change\", onSystemChange);\n };\n}\n\nconst TOGGLE_BOUND = \"sfMotionToggleBound\";\n\n/**\n * Wire every server-rendered `[data-sf-motion-toggle]` switch: a click flips\n * the preference, `aria-checked` mirrors it (checked means animations on).\n */\nexport function initializeMotionToggles(\n scope: ParentNode = document,\n env: MotionEnvironment = browserMotionEnvironment(),\n): () => void {\n const toggles = [...scope.querySelectorAll<HTMLElement>(MOTION_TOGGLE_SELECTOR)]\n .filter((toggle) => toggle.dataset[TOGGLE_BOUND] !== \"true\");\n const sync = (preference: MotionPreference) => {\n toggles.forEach((toggle) => toggle.setAttribute(\"aria-checked\", String(preference === \"full\")));\n };\n const flip = () => setMotionPreference(getMotionPreference(env) === \"full\" ? \"reduce\" : \"full\", env);\n\n toggles.forEach((toggle) => {\n toggle.dataset[TOGGLE_BOUND] = \"true\";\n toggle.addEventListener(\"click\", flip);\n });\n sync(getMotionPreference(env));\n const unsubscribe = subscribeMotionPreference(sync, env);\n\n return () => {\n unsubscribe();\n toggles.forEach((toggle) => {\n toggle.removeEventListener(\"click\", flip);\n delete toggle.dataset[TOGGLE_BOUND];\n });\n };\n}\n"]}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for "may this page animate?".
|
|
3
|
+
*
|
|
4
|
+
* The default follows the OS (`prefers-reduced-motion`). A visitor's explicit
|
|
5
|
+
* choice from the accessibility panel wins in both directions and is stored in
|
|
6
|
+
* localStorage. The resolved value is mirrored on
|
|
7
|
+
* `<html data-sf-motion-preference="full|reduce">`, so CSS and scripts read the
|
|
8
|
+
* same state, and every change is announced with `sf:motion-change`.
|
|
9
|
+
*
|
|
10
|
+
* Do not read `matchMedia("(prefers-reduced-motion)")` or write a bare
|
|
11
|
+
* `@media (prefers-reduced-motion)` rule elsewhere: neither can be overridden
|
|
12
|
+
* by the visitor.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const MOTION_STORAGE_KEY = "sf:motion";
|
|
16
|
+
export const MOTION_ATTRIBUTE = "data-sf-motion-preference";
|
|
17
|
+
export const MOTION_CHANGE_EVENT = "sf:motion-change";
|
|
18
|
+
export const MOTION_TOGGLE_SELECTOR = "[data-sf-motion-toggle]";
|
|
19
|
+
export const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
20
|
+
|
|
21
|
+
/** `full` animates, `reduce` keeps everything still. */
|
|
22
|
+
export type MotionPreference = "full" | "reduce";
|
|
23
|
+
|
|
24
|
+
export function isMotionPreference(value: unknown): value is MotionPreference {
|
|
25
|
+
return value === "full" || value === "reduce";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** An explicit choice beats the OS; without one the OS decides. */
|
|
29
|
+
export function resolveMotionPreference(stored: unknown, systemReduces: boolean): MotionPreference {
|
|
30
|
+
if (isMotionPreference(stored)) return stored;
|
|
31
|
+
return systemReduces ? "reduce" : "full";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Inline script for `<head>`: mirrors the resolved preference on `<html>`
|
|
36
|
+
* before first paint, so nothing starts animating and then snaps to a stop.
|
|
37
|
+
*/
|
|
38
|
+
export function motionPreferenceBootstrapScript(): string {
|
|
39
|
+
const key = JSON.stringify(MOTION_STORAGE_KEY);
|
|
40
|
+
const query = JSON.stringify(REDUCED_MOTION_QUERY);
|
|
41
|
+
const attribute = JSON.stringify(MOTION_ATTRIBUTE);
|
|
42
|
+
return `(()=>{let s=null,r=false;try{s=localStorage.getItem(${key})}catch{}try{r=matchMedia(${query}).matches}catch{}document.documentElement.setAttribute(${attribute},s==="full"||s==="reduce"?s:r?"reduce":"full")})()`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The browser surface this module needs, injectable for tests. */
|
|
46
|
+
export interface MotionEnvironment {
|
|
47
|
+
document: Pick<Document, "documentElement" | "dispatchEvent" | "addEventListener" | "removeEventListener">;
|
|
48
|
+
storage: Pick<Storage, "getItem" | "setItem"> | null;
|
|
49
|
+
media: Pick<MediaQueryList, "matches" | "addEventListener" | "removeEventListener"> | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function browserMotionEnvironment(): MotionEnvironment {
|
|
53
|
+
let storage: MotionEnvironment["storage"] = null;
|
|
54
|
+
try {
|
|
55
|
+
storage = localStorage;
|
|
56
|
+
} catch {
|
|
57
|
+
// Blocked storage keeps the preference in memory for the page only.
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
document,
|
|
61
|
+
storage,
|
|
62
|
+
media: typeof matchMedia === "function" ? matchMedia(REDUCED_MOTION_QUERY) : null,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function readStored(env: MotionEnvironment): string | null {
|
|
67
|
+
try {
|
|
68
|
+
return env.storage?.getItem(MOTION_STORAGE_KEY) ?? null;
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function mirrored(env: MotionEnvironment): MotionPreference | null {
|
|
75
|
+
const value = env.document.documentElement.getAttribute(MOTION_ATTRIBUTE);
|
|
76
|
+
return isMotionPreference(value) ? value : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The mirrored value when the bootstrap ran, otherwise resolved from storage and OS. */
|
|
80
|
+
export function getMotionPreference(env: MotionEnvironment = browserMotionEnvironment()): MotionPreference {
|
|
81
|
+
return mirrored(env) ?? resolveMotionPreference(readStored(env), env.media?.matches ?? false);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function apply(preference: MotionPreference, env: MotionEnvironment): void {
|
|
85
|
+
if (mirrored(env) === preference) return;
|
|
86
|
+
env.document.documentElement.setAttribute(MOTION_ATTRIBUTE, preference);
|
|
87
|
+
env.document.dispatchEvent(new CustomEvent(MOTION_CHANGE_EVENT, { detail: { preference } }));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Store an explicit choice and announce it. */
|
|
91
|
+
export function setMotionPreference(
|
|
92
|
+
preference: MotionPreference,
|
|
93
|
+
env: MotionEnvironment = browserMotionEnvironment(),
|
|
94
|
+
): void {
|
|
95
|
+
try {
|
|
96
|
+
env.storage?.setItem(MOTION_STORAGE_KEY, preference);
|
|
97
|
+
} catch {
|
|
98
|
+
// The choice still applies to this page.
|
|
99
|
+
}
|
|
100
|
+
apply(preference, env);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Call `listener` whenever the effective preference changes: an explicit
|
|
105
|
+
* choice, or the OS setting while the visitor has not made one.
|
|
106
|
+
*/
|
|
107
|
+
export function subscribeMotionPreference(
|
|
108
|
+
listener: (preference: MotionPreference) => void,
|
|
109
|
+
env: MotionEnvironment = browserMotionEnvironment(),
|
|
110
|
+
): () => void {
|
|
111
|
+
const onChange = (event: Event) => {
|
|
112
|
+
const preference = (event as CustomEvent<{ preference?: unknown }>).detail?.preference;
|
|
113
|
+
if (isMotionPreference(preference)) listener(preference);
|
|
114
|
+
};
|
|
115
|
+
// Every subscriber may see the OS change; `apply` announces it only once.
|
|
116
|
+
const onSystemChange = () => {
|
|
117
|
+
if (readStored(env) === null) apply(resolveMotionPreference(null, env.media?.matches ?? false), env);
|
|
118
|
+
};
|
|
119
|
+
env.document.addEventListener(MOTION_CHANGE_EVENT, onChange);
|
|
120
|
+
env.media?.addEventListener("change", onSystemChange);
|
|
121
|
+
return () => {
|
|
122
|
+
env.document.removeEventListener(MOTION_CHANGE_EVENT, onChange);
|
|
123
|
+
env.media?.removeEventListener("change", onSystemChange);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const TOGGLE_BOUND = "sfMotionToggleBound";
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Wire every server-rendered `[data-sf-motion-toggle]` switch: a click flips
|
|
131
|
+
* the preference, `aria-checked` mirrors it (checked means animations on).
|
|
132
|
+
*/
|
|
133
|
+
export function initializeMotionToggles(
|
|
134
|
+
scope: ParentNode = document,
|
|
135
|
+
env: MotionEnvironment = browserMotionEnvironment(),
|
|
136
|
+
): () => void {
|
|
137
|
+
const toggles = [...scope.querySelectorAll<HTMLElement>(MOTION_TOGGLE_SELECTOR)]
|
|
138
|
+
.filter((toggle) => toggle.dataset[TOGGLE_BOUND] !== "true");
|
|
139
|
+
const sync = (preference: MotionPreference) => {
|
|
140
|
+
toggles.forEach((toggle) => toggle.setAttribute("aria-checked", String(preference === "full")));
|
|
141
|
+
};
|
|
142
|
+
const flip = () => setMotionPreference(getMotionPreference(env) === "full" ? "reduce" : "full", env);
|
|
143
|
+
|
|
144
|
+
toggles.forEach((toggle) => {
|
|
145
|
+
toggle.dataset[TOGGLE_BOUND] = "true";
|
|
146
|
+
toggle.addEventListener("click", flip);
|
|
147
|
+
});
|
|
148
|
+
sync(getMotionPreference(env));
|
|
149
|
+
const unsubscribe = subscribeMotionPreference(sync, env);
|
|
150
|
+
|
|
151
|
+
return () => {
|
|
152
|
+
unsubscribe();
|
|
153
|
+
toggles.forEach((toggle) => {
|
|
154
|
+
toggle.removeEventListener("click", flip);
|
|
155
|
+
delete toggle.dataset[TOGGLE_BOUND];
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export declare const SF_REVEAL_SELECTOR = ".sf-reveal:not(.sf-motion-static)";
|
|
2
|
+
export declare const SF_REVEAL_CLASS = "sf-reveal";
|
|
3
|
+
export declare const SF_MOTION_STATIC_CLASS = "sf-motion-static";
|
|
4
|
+
export declare const SF_MOTION_DISABLE_CLASS = "sf-motion-disable";
|
|
5
|
+
export declare const SF_MOTION_DRAWER_EXIT_MS = 820;
|
|
6
|
+
export declare const SF_REVEAL_VISIBLE_RATIO = 0.2;
|
|
7
|
+
export declare const SF_REVEAL_STAGGER_SELECTOR = ".sf-reveal-stagger";
|
|
8
|
+
export declare const SF_REVEAL_STAGGER_STEP_MS = 90;
|
|
9
|
+
export declare const SF_REVEAL_STAGGER_MAX_MS = 450;
|
|
10
|
+
export type SfRevealModifier = `sf-reveal--${string}`;
|
|
11
|
+
export type SfDefaultReveal = false | SfRevealModifier;
|
|
12
|
+
export interface SfRevealRule {
|
|
13
|
+
/** Any selector accepted by `document.querySelectorAll`. */
|
|
14
|
+
selector: string;
|
|
15
|
+
/** Reveal modifier enforced on every matching element. */
|
|
16
|
+
reveal: SfRevealModifier;
|
|
17
|
+
}
|
|
18
|
+
export interface SfRevealClassChanges {
|
|
19
|
+
add: string[];
|
|
20
|
+
remove: SfRevealModifier[];
|
|
21
|
+
}
|
|
22
|
+
export interface SfMotionOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Allows reveal elements already in the initial viewport to animate.
|
|
25
|
+
* Defaults to `false`, so initial content is immediately available.
|
|
26
|
+
*/
|
|
27
|
+
revealAboveFold?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Ordered selector-specific reveal rules. The first matching rule wins and
|
|
30
|
+
* enforces its modifier. Any valid CSS selector may be used.
|
|
31
|
+
*/
|
|
32
|
+
revealRules?: readonly SfRevealRule[];
|
|
33
|
+
/**
|
|
34
|
+
* Preset applied to automatically selected elements. `false` keeps the
|
|
35
|
+
* reveal system strictly opt-in.
|
|
36
|
+
*/
|
|
37
|
+
defaultReveal?: SfDefaultReveal;
|
|
38
|
+
/**
|
|
39
|
+
* Standard CSS selectors. Tags, classes, IDs, attributes and combinations
|
|
40
|
+
* can be mixed in the same array.
|
|
41
|
+
*/
|
|
42
|
+
autoRevealSelectors?: readonly string[];
|
|
43
|
+
}
|
|
44
|
+
export interface ResolvedSfMotionOptions {
|
|
45
|
+
autoRevealSelectors: string[];
|
|
46
|
+
defaultReveal: SfDefaultReveal;
|
|
47
|
+
revealAboveFold: boolean;
|
|
48
|
+
revealRules: SfRevealRule[];
|
|
49
|
+
}
|
|
50
|
+
export type SfRevealState = "pending" | "visible" | "settled";
|
|
51
|
+
export interface InitialRevealStateInput {
|
|
52
|
+
bottom: number;
|
|
53
|
+
containsHashTarget: boolean;
|
|
54
|
+
protectedContent: boolean;
|
|
55
|
+
reducedMotion: boolean;
|
|
56
|
+
revealAboveFold: boolean;
|
|
57
|
+
top: number;
|
|
58
|
+
viewportHeight: number;
|
|
59
|
+
}
|
|
60
|
+
export interface RevealVisibilityInput {
|
|
61
|
+
bottom: number;
|
|
62
|
+
height: number;
|
|
63
|
+
top: number;
|
|
64
|
+
viewportHeight: number;
|
|
65
|
+
}
|
|
66
|
+
export declare function isSfRevealModifier(value: unknown): value is SfRevealModifier;
|
|
67
|
+
/**
|
|
68
|
+
* Normalizes server- or client-provided configuration. Invalid values fail
|
|
69
|
+
* open by disabling automatic reveals; empty and duplicate selectors are
|
|
70
|
+
* removed without changing their order.
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveSfMotionOptions(options?: SfMotionOptions): ResolvedSfMotionOptions;
|
|
73
|
+
/** Exact class mutation required by an authoritative selector rule. */
|
|
74
|
+
export declare function ruleRevealClassChanges(existingClasses: Iterable<string>, reveal: SfRevealModifier): SfRevealClassChanges;
|
|
75
|
+
/** Delay for a zero-based participant index in a reveal stagger group. */
|
|
76
|
+
export declare function staggerRevealDelayMs(index: number): number;
|
|
77
|
+
/**
|
|
78
|
+
* Returns only the classes that automatic inheritance must add. Explicit
|
|
79
|
+
* modifiers win over the configured default and `sf-motion-static` remains a
|
|
80
|
+
* complete opt-out.
|
|
81
|
+
*/
|
|
82
|
+
export declare function automaticRevealClasses(existingClasses: Iterable<string>, defaultReveal: SfDefaultReveal): string[];
|
|
83
|
+
/** Returns the longest combined CSS transition duration and delay. */
|
|
84
|
+
export declare function maximumTransitionTimeMs(transitionDuration: string, transitionDelay: string): number;
|
|
85
|
+
/**
|
|
86
|
+
* Initial viewport content stays static unless the project explicitly enables
|
|
87
|
+
* above-the-fold reveals. Deep links and protected content remain visible.
|
|
88
|
+
*/
|
|
89
|
+
export declare function initialRevealState({ bottom, containsHashTarget, protectedContent, reducedMotion, revealAboveFold, top, viewportHeight, }: InitialRevealStateInput): SfRevealState;
|
|
90
|
+
/**
|
|
91
|
+
* Reveal ordinary content once 20% of its perceivable height is visible.
|
|
92
|
+
* For elements taller than the viewport, the viewport height is the reference.
|
|
93
|
+
*/
|
|
94
|
+
export declare function hasEnoughVisibleArea({ bottom, height, top, viewportHeight, }: RevealVisibilityInput): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Reveal is deliberately one-way: focus and viewport entry can complete it,
|
|
97
|
+
* while leaving the viewport never conceals content again.
|
|
98
|
+
*/
|
|
99
|
+
export declare function nextRevealState(current: SfRevealState, event: "focus" | "intersect" | "leave"): SfRevealState;
|
|
100
|
+
export declare function shouldInitializeMotion(initialized: string | undefined): boolean;
|
|
101
|
+
//# sourceMappingURL=motion.d.ts.map
|