@styleflow.app/flowpress-astro-core 1.0.0-beta.4 → 1.0.0-beta.40
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 +242 -1
- package/README.md +104 -5
- 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 +37 -0
- package/dist/astro/FontStylesheets.astro +35 -0
- package/dist/astro/GutenbergRenderer.astro +267 -80
- 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 +169 -0
- package/dist/astro/blocks/FormBlock.astro +23 -20
- package/dist/astro/blocks/GridBlock.astro +6 -4
- package/dist/astro/blocks/HeroBlock.astro +6 -6
- package/dist/astro/blocks/ImageBlock.astro +6 -6
- package/dist/astro/blocks/ListItemFallback.astro +9 -7
- 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 +55 -39
- package/dist/astro/blocks/helpers.js.map +1 -1
- package/dist/astro/blocks/helpers.ts +69 -44
- 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 +139 -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/image.d.ts +5 -0
- package/dist/astro/native/image.d.ts.map +1 -0
- package/dist/astro/native/image.js +65 -0
- package/dist/astro/native/image.js.map +1 -0
- package/dist/astro/native/image.ts +56 -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 +81 -0
- package/dist/astro/native/registry.js.map +1 -0
- package/dist/astro/native/registry.ts +82 -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 +23 -3
- package/dist/block-renderers.d.ts.map +1 -1
- package/dist/block-renderers.js.map +1 -1
- package/dist/build-cache.d.ts +8 -0
- package/dist/build-cache.d.ts.map +1 -0
- package/dist/build-cache.js +81 -0
- package/dist/build-cache.js.map +1 -0
- package/dist/client.d.ts +23 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +78 -39
- 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 +117 -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 +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/media.d.ts +20 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +106 -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 +13 -0
- package/dist/svg-media.d.ts.map +1 -0
- package/dist/svg-media.js +47 -0
- package/dist/svg-media.js.map +1 -0
- package/dist/template-hierarchy.d.ts +0 -7
- package/dist/template-hierarchy.d.ts.map +1 -1
- package/dist/template-hierarchy.js +0 -21
- package/dist/template-hierarchy.js.map +1 -1
- 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 +75 -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 +58 -7
- package/dist/astro/DefaultTemplate.astro +0 -42
- package/dist/templates.d.ts +0 -19
- package/dist/templates.d.ts.map +0 -1
- package/dist/templates.js +0 -20
- package/dist/templates.js.map +0 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Presentation of the existing WordPress core/image attributes. */
|
|
2
|
+
const cssNumber = /^(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
3
|
+
const dimensionUnits = new Set(["px", "%", "em", "rem", "ex", "ch", "lh", "rlh", "vw", "vh", "vmin", "vmax", "vi", "vb", "svw", "svh", "lvw", "lvh", "dvw", "dvh", "cm", "mm", "q", "in", "pt", "pc"]);
|
|
4
|
+
function positiveNumber(value) {
|
|
5
|
+
const number = Number(value);
|
|
6
|
+
return cssNumber.test(value) && Number.isFinite(number) && number > 0 ? String(number) : undefined;
|
|
7
|
+
}
|
|
8
|
+
export function imageAspectRatio(value) {
|
|
9
|
+
if (typeof value !== "string" && typeof value !== "number")
|
|
10
|
+
return undefined;
|
|
11
|
+
const candidate = String(value).trim();
|
|
12
|
+
if (candidate === "auto")
|
|
13
|
+
return candidate;
|
|
14
|
+
const parts = candidate.split("/").map(part => positiveNumber(part.trim()));
|
|
15
|
+
if (parts.length === 1)
|
|
16
|
+
return parts[0];
|
|
17
|
+
return parts.length === 2 && parts[0] && parts[1] ? `${parts[0]} / ${parts[1]}` : undefined;
|
|
18
|
+
}
|
|
19
|
+
export function imageDimension(value) {
|
|
20
|
+
if (typeof value !== "string" && typeof value !== "number")
|
|
21
|
+
return undefined;
|
|
22
|
+
const candidate = String(value).trim().toLowerCase();
|
|
23
|
+
if (candidate === "auto")
|
|
24
|
+
return candidate;
|
|
25
|
+
const match = candidate.match(/^((?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)([a-z%]*)$/);
|
|
26
|
+
if (!match || !Number.isFinite(Number(match[1])))
|
|
27
|
+
return undefined;
|
|
28
|
+
const unit = match[2] || "px";
|
|
29
|
+
return dimensionUnits.has(unit) ? `${Number(match[1])}${unit}` : undefined;
|
|
30
|
+
}
|
|
31
|
+
export function imageObjectPosition(value) {
|
|
32
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
33
|
+
return "50% 50%";
|
|
34
|
+
const { x, y } = value;
|
|
35
|
+
if (typeof x !== "number" || typeof y !== "number" || !Number.isFinite(x) || !Number.isFinite(y))
|
|
36
|
+
return "50% 50%";
|
|
37
|
+
const percentage = (coordinate) => Number((Math.min(1, Math.max(0, coordinate)) * 100).toFixed(6));
|
|
38
|
+
return `${percentage(x)}% ${percentage(y)}%`;
|
|
39
|
+
}
|
|
40
|
+
export function imageMediaStyle(attributes) {
|
|
41
|
+
const ratio = imageAspectRatio(attributes.aspectRatio);
|
|
42
|
+
const width = imageDimension(attributes.width);
|
|
43
|
+
const height = imageDimension(attributes.height);
|
|
44
|
+
const hasRatio = ratio !== undefined && ratio !== "auto";
|
|
45
|
+
const scale = ["cover", "contain", "fill"].includes(String(attributes.scale))
|
|
46
|
+
? String(attributes.scale)
|
|
47
|
+
: hasRatio || (height !== undefined && height !== "auto") ? "cover" : undefined;
|
|
48
|
+
const style = {};
|
|
49
|
+
if (ratio)
|
|
50
|
+
style["aspect-ratio"] = ratio;
|
|
51
|
+
if (scale) {
|
|
52
|
+
style["object-fit"] = scale;
|
|
53
|
+
style["object-position"] = imageObjectPosition(attributes.focalPoint);
|
|
54
|
+
}
|
|
55
|
+
if (width !== undefined)
|
|
56
|
+
style.width = width;
|
|
57
|
+
else if (hasRatio && height !== undefined && height !== "auto")
|
|
58
|
+
style.width = "auto";
|
|
59
|
+
if (height !== undefined)
|
|
60
|
+
style.height = height;
|
|
61
|
+
else if (ratio || width !== undefined)
|
|
62
|
+
style.height = "auto";
|
|
63
|
+
return style;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../src/astro/native/image.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,MAAM,SAAS,GAAG,sCAAsC,CAAC;AACzD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEvM,SAAS,cAAc,CAAC,KAAa;IACnC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM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AC,CAAC;IACjD,MAAM,QAAQ,GAAG,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,MAAM,CAAC;IACzD,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC3E,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC;QAC1B,CAAC,CAAC,QAAQ,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAClF,MAAM,KAAK,GAA2B,EAAE,CAAC;IACzC,IAAI,KAAK;QAAE,KAAK,CAAC,cAAc,CAAC,GAAG,KAAK,CAAC;IACzC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;QAC5B,KAAK,CAAC,iBAAiB,CAAC,GAAG,mBAAmB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACxE,CAAC;IACD,IAAI,KAAK,KAAK,SAAS;QAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;SACxC,IAAI,QAAQ,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,MAAM;QAAE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;IACrF,IAAI,MAAM,KAAK,SAAS;QAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;SAC3C,IAAI,KAAK,IAAI,KAAK,KAAK,SAAS;QAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;IAC7D,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/** Presentation of the existing WordPress core/image attributes. */\nconst cssNumber = /^(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?$/i;\nconst dimensionUnits = new Set([\"px\", \"%\", \"em\", \"rem\", \"ex\", \"ch\", \"lh\", \"rlh\", \"vw\", \"vh\", \"vmin\", \"vmax\", \"vi\", \"vb\", \"svw\", \"svh\", \"lvw\", \"lvh\", \"dvw\", \"dvh\", \"cm\", \"mm\", \"q\", \"in\", \"pt\", \"pc\"]);\n\nfunction positiveNumber(value: string): string | undefined {\n const number = Number(value);\n return cssNumber.test(value) && Number.isFinite(number) && number > 0 ? String(number) : undefined;\n}\n\nexport function imageAspectRatio(value: unknown): string | undefined {\n if (typeof value !== \"string\" && typeof value !== \"number\") return undefined;\n const candidate = String(value).trim();\n if (candidate === \"auto\") return candidate;\n const parts = candidate.split(\"/\").map(part => positiveNumber(part.trim()));\n if (parts.length === 1) return parts[0];\n return parts.length === 2 && parts[0] && parts[1] ? `${parts[0]} / ${parts[1]}` : undefined;\n}\n\nexport function imageDimension(value: unknown): string | undefined {\n if (typeof value !== \"string\" && typeof value !== \"number\") return undefined;\n const candidate = String(value).trim().toLowerCase();\n if (candidate === \"auto\") return candidate;\n const match = candidate.match(/^((?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?)([a-z%]*)$/);\n if (!match || !Number.isFinite(Number(match[1]))) return undefined;\n const unit = match[2] || \"px\";\n return dimensionUnits.has(unit) ? `${Number(match[1])}${unit}` : undefined;\n}\n\nexport function imageObjectPosition(value: unknown): string {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return \"50% 50%\";\n const { x, y } = value as Record<string, unknown>;\n if (typeof x !== \"number\" || typeof y !== \"number\" || !Number.isFinite(x) || !Number.isFinite(y)) return \"50% 50%\";\n const percentage = (coordinate: number) => Number((Math.min(1, Math.max(0, coordinate)) * 100).toFixed(6));\n return `${percentage(x)}% ${percentage(y)}%`;\n}\n\nexport function imageMediaStyle(attributes: Record<string, unknown>): Record<string, string> {\n const ratio = imageAspectRatio(attributes.aspectRatio);\n const width = imageDimension(attributes.width);\n const height = imageDimension(attributes.height);\n const hasRatio = ratio !== undefined && ratio !== \"auto\";\n const scale = [\"cover\", \"contain\", \"fill\"].includes(String(attributes.scale))\n ? String(attributes.scale)\n : hasRatio || (height !== undefined && height !== \"auto\") ? \"cover\" : undefined;\n const style: Record<string, string> = {};\n if (ratio) style[\"aspect-ratio\"] = ratio;\n if (scale) {\n style[\"object-fit\"] = scale;\n style[\"object-position\"] = imageObjectPosition(attributes.focalPoint);\n }\n if (width !== undefined) style.width = width;\n else if (hasRatio && height !== undefined && height !== \"auto\") style.width = \"auto\";\n if (height !== undefined) style.height = height;\n else if (ratio || width !== undefined) style.height = \"auto\";\n return style;\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Presentation of the existing WordPress core/image attributes. */
|
|
2
|
+
const cssNumber = /^(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
3
|
+
const dimensionUnits = new Set(["px", "%", "em", "rem", "ex", "ch", "lh", "rlh", "vw", "vh", "vmin", "vmax", "vi", "vb", "svw", "svh", "lvw", "lvh", "dvw", "dvh", "cm", "mm", "q", "in", "pt", "pc"]);
|
|
4
|
+
|
|
5
|
+
function positiveNumber(value: string): string | undefined {
|
|
6
|
+
const number = Number(value);
|
|
7
|
+
return cssNumber.test(value) && Number.isFinite(number) && number > 0 ? String(number) : undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function imageAspectRatio(value: unknown): string | undefined {
|
|
11
|
+
if (typeof value !== "string" && typeof value !== "number") return undefined;
|
|
12
|
+
const candidate = String(value).trim();
|
|
13
|
+
if (candidate === "auto") return candidate;
|
|
14
|
+
const parts = candidate.split("/").map(part => positiveNumber(part.trim()));
|
|
15
|
+
if (parts.length === 1) return parts[0];
|
|
16
|
+
return parts.length === 2 && parts[0] && parts[1] ? `${parts[0]} / ${parts[1]}` : undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function imageDimension(value: unknown): string | undefined {
|
|
20
|
+
if (typeof value !== "string" && typeof value !== "number") return undefined;
|
|
21
|
+
const candidate = String(value).trim().toLowerCase();
|
|
22
|
+
if (candidate === "auto") return candidate;
|
|
23
|
+
const match = candidate.match(/^((?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)([a-z%]*)$/);
|
|
24
|
+
if (!match || !Number.isFinite(Number(match[1]))) return undefined;
|
|
25
|
+
const unit = match[2] || "px";
|
|
26
|
+
return dimensionUnits.has(unit) ? `${Number(match[1])}${unit}` : undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function imageObjectPosition(value: unknown): string {
|
|
30
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return "50% 50%";
|
|
31
|
+
const { x, y } = value as Record<string, unknown>;
|
|
32
|
+
if (typeof x !== "number" || typeof y !== "number" || !Number.isFinite(x) || !Number.isFinite(y)) return "50% 50%";
|
|
33
|
+
const percentage = (coordinate: number) => Number((Math.min(1, Math.max(0, coordinate)) * 100).toFixed(6));
|
|
34
|
+
return `${percentage(x)}% ${percentage(y)}%`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function imageMediaStyle(attributes: Record<string, unknown>): Record<string, string> {
|
|
38
|
+
const ratio = imageAspectRatio(attributes.aspectRatio);
|
|
39
|
+
const width = imageDimension(attributes.width);
|
|
40
|
+
const height = imageDimension(attributes.height);
|
|
41
|
+
const hasRatio = ratio !== undefined && ratio !== "auto";
|
|
42
|
+
const scale = ["cover", "contain", "fill"].includes(String(attributes.scale))
|
|
43
|
+
? String(attributes.scale)
|
|
44
|
+
: hasRatio || (height !== undefined && height !== "auto") ? "cover" : undefined;
|
|
45
|
+
const style: Record<string, string> = {};
|
|
46
|
+
if (ratio) style["aspect-ratio"] = ratio;
|
|
47
|
+
if (scale) {
|
|
48
|
+
style["object-fit"] = scale;
|
|
49
|
+
style["object-position"] = imageObjectPosition(attributes.focalPoint);
|
|
50
|
+
}
|
|
51
|
+
if (width !== undefined) style.width = width;
|
|
52
|
+
else if (hasRatio && height !== undefined && height !== "auto") style.width = "auto";
|
|
53
|
+
if (height !== undefined) style.height = height;
|
|
54
|
+
else if (ratio || width !== undefined) style.height = "auto";
|
|
55
|
+
return style;
|
|
56
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* Inline text inherits its typed ancestor; explicitly typed children retain their contract rules. */
|
|
2
|
+
@layer styleflow {
|
|
3
|
+
:where([data-text-style]) :is(a, strong, em) {
|
|
4
|
+
font-family: inherit;
|
|
5
|
+
font-size: inherit;
|
|
6
|
+
font-style: inherit;
|
|
7
|
+
font-weight: inherit;
|
|
8
|
+
line-height: inherit;
|
|
9
|
+
letter-spacing: inherit;
|
|
10
|
+
text-transform: inherit;
|
|
11
|
+
font-variation-settings: inherit;
|
|
12
|
+
}
|
|
13
|
+
:where([data-text-style]) strong { font-weight: var(--sf-text-body-md-strong-font-weight, bolder); }
|
|
14
|
+
:where([data-text-style]) em { font-style: italic; }
|
|
15
|
+
}
|
|
@@ -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,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACxE,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC1D,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAC7B,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC,QAAQ,CAAC,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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;;;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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;AAC5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,yBAAyB,CAAC;AAChE,MAAM,CAAC,MAAM,oBAAoB,GAAG,kCAAkC,CAAC;AAKvE,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,QAAQ,CAAC;AAChD,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,uBAAuB,CAAC,MAAe,EAAE,aAAsB;IAC7E,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AO,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"]}
|