@veroxm/react-sdk 0.0.0-stage → 0.1.0

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.
Files changed (98) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +295 -2
  4. package/dist/cache.d.ts +69 -0
  5. package/dist/cache.js +89 -0
  6. package/dist/client-slots.d.ts +35 -0
  7. package/dist/client-slots.js +169 -0
  8. package/dist/client.d.ts +65 -0
  9. package/dist/client.js +87 -0
  10. package/dist/editor/constants.d.ts +12 -0
  11. package/dist/editor/constants.js +12 -0
  12. package/dist/editor/handler.d.ts +16 -0
  13. package/dist/editor/handler.js +175 -0
  14. package/dist/editor/inline.d.ts +25 -0
  15. package/dist/editor/inline.js +149 -0
  16. package/dist/editor/menu-input.d.ts +26 -0
  17. package/dist/editor/menu-input.js +110 -0
  18. package/dist/editor/overlay.d.ts +31 -0
  19. package/dist/editor/overlay.js +856 -0
  20. package/dist/editor/rich-text.d.ts +21 -0
  21. package/dist/editor/rich-text.js +232 -0
  22. package/dist/editor/server.d.ts +9 -0
  23. package/dist/editor/server.js +43 -0
  24. package/dist/errors.d.ts +20 -0
  25. package/dist/errors.js +26 -0
  26. package/dist/hooks/use-cached-query.d.ts +21 -0
  27. package/dist/hooks/use-cached-query.js +59 -0
  28. package/dist/hooks/use-collection.d.ts +10 -0
  29. package/dist/hooks/use-collection.js +14 -0
  30. package/dist/hooks/use-entries.d.ts +18 -0
  31. package/dist/hooks/use-entries.js +25 -0
  32. package/dist/hooks/use-entry.d.ts +21 -0
  33. package/dist/hooks/use-entry.js +22 -0
  34. package/dist/hooks/use-media.d.ts +9 -0
  35. package/dist/hooks/use-media.js +13 -0
  36. package/dist/hydration-boundary.d.ts +35 -0
  37. package/dist/hydration-boundary.js +38 -0
  38. package/dist/image.d.ts +34 -0
  39. package/dist/image.js +39 -0
  40. package/dist/index.d.ts +46 -0
  41. package/dist/index.js +32 -0
  42. package/dist/next/cache-components.d.ts +15 -0
  43. package/dist/next/cache-components.js +25 -0
  44. package/dist/next/cached.d.ts +9 -0
  45. package/dist/next/cached.js +20 -0
  46. package/dist/next/edge-slot.d.ts +21 -0
  47. package/dist/next/edge-slot.js +29 -0
  48. package/dist/next/editor.d.ts +7 -0
  49. package/dist/next/editor.js +13 -0
  50. package/dist/next/index.d.ts +17 -0
  51. package/dist/next/index.js +21 -0
  52. package/dist/next/llms.d.ts +2 -0
  53. package/dist/next/llms.js +44 -0
  54. package/dist/next/route.d.ts +12 -0
  55. package/dist/next/route.js +16 -0
  56. package/dist/next/slot.d.ts +21 -0
  57. package/dist/next/slot.js +160 -0
  58. package/dist/node.d.ts +43 -0
  59. package/dist/node.js +67 -0
  60. package/dist/preview.d.ts +35 -0
  61. package/dist/preview.js +46 -0
  62. package/dist/provider.d.ts +29 -0
  63. package/dist/provider.js +37 -0
  64. package/dist/query-keys.d.ts +19 -0
  65. package/dist/query-keys.js +49 -0
  66. package/dist/site/chart-view.d.ts +14 -0
  67. package/dist/site/chart-view.js +44 -0
  68. package/dist/site/chart.d.ts +127 -0
  69. package/dist/site/chart.js +639 -0
  70. package/dist/site/map-embed.d.ts +32 -0
  71. package/dist/site/map-embed.js +139 -0
  72. package/dist/site/map-math.d.ts +27 -0
  73. package/dist/site/map-math.js +89 -0
  74. package/dist/site/nav-menu.d.ts +19 -0
  75. package/dist/site/nav-menu.js +76 -0
  76. package/dist/site/site-parts.d.ts +87 -0
  77. package/dist/site/site-parts.js +46 -0
  78. package/dist/site/slider.d.ts +17 -0
  79. package/dist/site/slider.js +78 -0
  80. package/dist/site/styles.d.ts +3 -0
  81. package/dist/site/styles.js +155 -0
  82. package/dist/site/video-embed.d.ts +15 -0
  83. package/dist/site/video-embed.js +27 -0
  84. package/dist/site/video.d.ts +18 -0
  85. package/dist/site/video.js +73 -0
  86. package/dist/slots-core.d.ts +397 -0
  87. package/dist/slots-core.js +367 -0
  88. package/dist/slots.d.ts +13 -0
  89. package/dist/slots.js +30 -0
  90. package/dist/ssr.d.ts +20 -0
  91. package/dist/ssr.js +35 -0
  92. package/dist/structured-data.d.ts +13 -0
  93. package/dist/structured-data.js +36 -0
  94. package/dist/tracking.d.ts +142 -0
  95. package/dist/tracking.js +152 -0
  96. package/dist/types.d.ts +106 -0
  97. package/dist/types.js +6 -0
  98. package/package.json +95 -4
@@ -0,0 +1,32 @@
1
+ import type { SlotMap } from '../slots-core.js';
2
+ import { type GeoPoint } from './map-math.js';
3
+ export interface MapEmbedProps {
4
+ map: SlotMap | null | undefined;
5
+ /** The map's accessible name. Default "Map". */
6
+ label?: string;
7
+ /** Pixels. Default 380. */
8
+ height?: number;
9
+ /** Tile address with {z}, {x} and {y}. Default OpenStreetMap's. */
10
+ tileUrl?: string;
11
+ /** Credit shown on the map, as the tile provider requires. Default OpenStreetMap's. */
12
+ attribution?: {
13
+ text: string;
14
+ href: string;
15
+ };
16
+ /** Show a button instead of the map until the visitor presses it. */
17
+ deferred?: boolean;
18
+ /** List the places under the map. Default true. */
19
+ showList?: boolean;
20
+ className?: string;
21
+ /** Spread on the wrapper, e.g. slot.edit('map') for VeroXM's on-page editor. */
22
+ editProps?: Record<string, string>;
23
+ }
24
+ export declare const osmLink: (p: GeoPoint, zoom?: number) => string;
25
+ /** The tiles covering a view: each with its address and where it goes in the view. */
26
+ export declare function tilesFor(center: GeoPoint, zoom: number, width: number, height: number, tileUrl: string): {
27
+ key: string;
28
+ src: string;
29
+ x: number;
30
+ y: number;
31
+ }[];
32
+ export declare function MapEmbed({ map, label, height, tileUrl, attribution, deferred, showList, className, editProps, }: MapEmbedProps): import("react").JSX.Element | null;
@@ -0,0 +1,139 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from 'react';
4
+ import { MAP_TILE_SIZE, MAX_MAP_ZOOM, MIN_MAP_ZOOM, fitPoints, projectPoint, unprojectPoint } from './map-math.js';
5
+ import { isSafeMenuHref } from './nav-menu.js';
6
+ const OSM_TILES = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
7
+ const OSM_CREDIT = { text: '© OpenStreetMap contributors', href: 'https://www.openstreetmap.org/copyright' };
8
+ const PAN_STEP = 96;
9
+ export const osmLink = (p, zoom = 17) => `https://www.openstreetmap.org/?mlat=${p.lat}&mlon=${p.lng}#map=${zoom}/${p.lat}/${p.lng}`;
10
+ /** The tiles covering a view: each with its address and where it goes in the view. */
11
+ export function tilesFor(center, zoom, width, height, tileUrl) {
12
+ const c = projectPoint(center, zoom);
13
+ const left = c.x - width / 2;
14
+ const top = c.y - height / 2;
15
+ const count = 2 ** zoom;
16
+ const out = [];
17
+ for (let ty = Math.floor(top / MAP_TILE_SIZE); ty < Math.ceil((top + height) / MAP_TILE_SIZE); ty++) {
18
+ if (ty < 0 || ty >= count)
19
+ continue;
20
+ for (let tx = Math.floor(left / MAP_TILE_SIZE); tx < Math.ceil((left + width) / MAP_TILE_SIZE); tx++) {
21
+ const wx = ((tx % count) + count) % count;
22
+ out.push({
23
+ key: `${zoom}/${tx}/${ty}`,
24
+ src: tileUrl.replace('{z}', String(zoom)).replace('{x}', String(wx)).replace('{y}', String(ty)),
25
+ x: tx * MAP_TILE_SIZE - left,
26
+ y: ty * MAP_TILE_SIZE - top,
27
+ });
28
+ }
29
+ }
30
+ return out;
31
+ }
32
+ function PlaceLines({ place }) {
33
+ return (_jsxs(_Fragment, { children: [_jsx("span", { className: "vxs-place-name", children: place.name }), place.address ? _jsx("span", { className: "vxs-place-address", children: place.address }) : null, _jsxs("span", { className: "vxs-place-links", children: [place.link && isSafeMenuHref(place.link) ? _jsx("a", { href: place.link, children: "Details" }) : null, _jsxs("a", { href: osmLink(place), target: "_blank", rel: "noopener noreferrer", children: ["Open map", _jsxs("span", { className: "vxs-sr", children: [" of ", place.name, " in a new tab"] })] })] })] }));
34
+ }
35
+ export function MapEmbed({ map, label = 'Map', height = 380, tileUrl = OSM_TILES, attribution = tileUrl === OSM_TILES ? OSM_CREDIT : undefined, deferred = false, showList = true, className, editProps, }) {
36
+ const id = useId();
37
+ const places = useMemo(() => (map?.places ?? []).filter((p) => Number.isFinite(p.lat) && Number.isFinite(p.lng) && Math.abs(p.lat) <= 90 && Math.abs(p.lng) <= 180), [map]);
38
+ const viewRef = useRef(null);
39
+ const [width, setWidth] = useState(0);
40
+ const [shown, setShown] = useState(!deferred);
41
+ const placesKey = `${JSON.stringify(places)}|${map?.zoom ?? ''}`;
42
+ // Where "show all places" goes: every place in view, or the editor's zoom.
43
+ const home = useMemo(() => {
44
+ const fit = fitPoints(places, width || 640, height);
45
+ return map?.zoom ? { center: fit.center, zoom: map.zoom } : fit;
46
+ // placesKey stands for places and map.zoom.
47
+ // eslint-disable-next-line react-hooks/exhaustive-deps
48
+ }, [placesKey, width, height]);
49
+ const [view, setView] = useState(home);
50
+ const [selected, setSelected] = useState(null);
51
+ const drag = useRef(null);
52
+ useLayoutEffect(() => {
53
+ const el = viewRef.current;
54
+ if (!el)
55
+ return;
56
+ const measure = () => {
57
+ if (el.clientWidth)
58
+ setWidth(el.clientWidth);
59
+ };
60
+ measure();
61
+ if (typeof ResizeObserver === 'undefined')
62
+ return;
63
+ const ro = new ResizeObserver(measure);
64
+ ro.observe(el);
65
+ return () => ro.disconnect();
66
+ }, [shown]);
67
+ // Fit the places when they change and once the real width is known; a resize after that keeps the visitor's view.
68
+ const measured = width > 0;
69
+ useEffect(() => {
70
+ setView(home);
71
+ setSelected(null);
72
+ // eslint-disable-next-line react-hooks/exhaustive-deps
73
+ }, [placesKey, measured]);
74
+ // Before the width is measured (server render), cover a wide view: positions are from the centre, so it fits any width.
75
+ const w = width || 1280;
76
+ if (!places.length)
77
+ return null;
78
+ const cls = `vxs-map${className ? ` ${className}` : ''}`;
79
+ const zoomTo = (z, around) => {
80
+ const zoom = Math.max(MIN_MAP_ZOOM, Math.min(MAX_MAP_ZOOM, z));
81
+ if (zoom === view.zoom)
82
+ return;
83
+ if (!around)
84
+ return setView({ center: view.center, zoom });
85
+ // Keep the point under the pointer where it is.
86
+ const c = projectPoint(view.center, view.zoom);
87
+ const at = unprojectPoint(c.x - w / 2 + around.x, c.y - height / 2 + around.y, view.zoom);
88
+ const after = projectPoint(at, zoom);
89
+ setView({ center: unprojectPoint(after.x - around.x + w / 2, after.y - around.y + height / 2, zoom), zoom });
90
+ };
91
+ const panBy = (dx, dy) => {
92
+ const c = projectPoint(view.center, view.zoom);
93
+ setView({ center: unprojectPoint(c.x + dx, c.y + dy, view.zoom), zoom: view.zoom });
94
+ };
95
+ const c = projectPoint(view.center, view.zoom);
96
+ const left = c.x - w / 2;
97
+ /** A horizontal position from the view's centre, right whatever its width. */
98
+ const fromCentre = (px) => `calc(50% + ${Math.round(px - w / 2)}px)`;
99
+ const top = c.y - height / 2;
100
+ const chosen = selected !== null ? places[selected] : undefined;
101
+ const chosenAt = chosen ? projectPoint(chosen, view.zoom) : null;
102
+ return (_jsxs("figure", { className: cls, ...editProps, children: [!shown ? (_jsxs("button", { type: "button", className: "vxs-map-defer", style: { height }, onClick: () => setShown(true), children: ["Show the map", _jsxs("span", { className: "vxs-map-defer-note", children: ["Loads map images from ", tileUrl === OSM_TILES ? 'OpenStreetMap' : new URL(tileUrl.replace(/\{[a-z]\}/g, '0')).hostname] })] })) : (_jsxs("div", { ref: viewRef, className: "vxs-map-view", style: { height }, role: "group", "aria-roledescription": "map", "aria-label": `${label}: ${places.length === 1 ? places[0].name : `${places.length} places`}. Arrow keys move the map, + and - zoom.`, tabIndex: 0, onKeyDown: (e) => {
103
+ const moves = { ArrowLeft: [-PAN_STEP, 0], ArrowRight: [PAN_STEP, 0], ArrowUp: [0, -PAN_STEP], ArrowDown: [0, PAN_STEP] };
104
+ if (moves[e.key] && e.target === e.currentTarget) {
105
+ e.preventDefault();
106
+ panBy(...moves[e.key]);
107
+ }
108
+ else if (e.key === '+' || e.key === '=')
109
+ zoomTo(view.zoom + 1);
110
+ else if (e.key === '-' || e.key === '_')
111
+ zoomTo(view.zoom - 1);
112
+ else if (e.key === 'Escape')
113
+ setSelected(null);
114
+ }, onPointerDown: (e) => {
115
+ if (e.target.closest('button,a'))
116
+ return;
117
+ drag.current = { x: e.clientX, y: e.clientY, center: projectPoint(view.center, view.zoom), moved: false };
118
+ e.currentTarget.setPointerCapture?.(e.pointerId);
119
+ }, onPointerMove: (e) => {
120
+ const d = drag.current;
121
+ if (!d)
122
+ return;
123
+ const dx = e.clientX - d.x;
124
+ const dy = e.clientY - d.y;
125
+ if (Math.abs(dx) + Math.abs(dy) > 3)
126
+ d.moved = true;
127
+ setView((v) => ({ center: unprojectPoint(d.center.x - dx, d.center.y - dy, v.zoom), zoom: v.zoom }));
128
+ }, onPointerUp: () => {
129
+ if (drag.current && !drag.current.moved)
130
+ setSelected(null);
131
+ drag.current = null;
132
+ }, onDoubleClick: (e) => {
133
+ const r = e.currentTarget.getBoundingClientRect();
134
+ zoomTo(view.zoom + 1, { x: e.clientX - r.left, y: e.clientY - r.top });
135
+ }, children: [_jsx("div", { className: "vxs-map-tiles", "aria-hidden": "true", children: tilesFor(view.center, view.zoom, w, height, tileUrl).map((t) => (_jsx("img", { src: t.src, alt: "", draggable: false, loading: "lazy", decoding: "async", width: MAP_TILE_SIZE, height: MAP_TILE_SIZE, style: { left: fromCentre(t.x), top: t.y } }, t.key))) }), places.map((p, i) => {
136
+ const at = projectPoint(p, view.zoom);
137
+ return (_jsx("button", { type: "button", className: "vxs-map-pin", style: { left: fromCentre(at.x - left), top: at.y - top }, "aria-label": p.name, "aria-expanded": selected === i, "aria-controls": `${id}-card`, onClick: () => setSelected(selected === i ? null : i) }, i));
138
+ }), chosen && chosenAt ? (_jsx("div", { id: `${id}-card`, className: "vxs-map-card", style: { left: fromCentre(chosenAt.x - left), top: chosenAt.y - top }, children: _jsx(PlaceLines, { place: chosen }) })) : null, _jsxs("div", { className: "vxs-map-zoom", children: [_jsx("button", { type: "button", onClick: () => zoomTo(view.zoom + 1), disabled: view.zoom >= MAX_MAP_ZOOM, "aria-label": "Zoom in", children: "+" }), _jsx("button", { type: "button", onClick: () => zoomTo(view.zoom - 1), disabled: view.zoom <= MIN_MAP_ZOOM, "aria-label": "Zoom out", children: "\u2212" }), places.length > 1 || view.zoom !== home.zoom ? (_jsx("button", { type: "button", className: "vxs-map-home", onClick: () => setView(home), "aria-label": places.length > 1 ? 'Show all places' : `Back to ${places[0].name}`, children: "\u2302" })) : null] }), attribution ? (_jsx("a", { className: "vxs-map-credit", href: attribution.href, target: "_blank", rel: "noopener noreferrer", children: attribution.text })) : null] })), showList ? (_jsx("ul", { className: "vxs-map-list", "aria-label": `${label}: places`, children: places.map((p, i) => (_jsx("li", { className: "vxs-map-item", children: _jsx(PlaceLines, { place: p }) }, i))) })) : null] }));
139
+ }
@@ -0,0 +1,27 @@
1
+ export interface GeoPoint {
2
+ lat: number;
3
+ lng: number;
4
+ }
5
+ export declare const MIN_MAP_ZOOM = 1;
6
+ export declare const MAX_MAP_ZOOM = 19;
7
+ export declare const MAP_TILE_SIZE = 256;
8
+ /**
9
+ * A place from what an editor pastes: '24.7136, 46.6753', or a link to
10
+ * OpenStreetMap, Google Maps or Apple Maps. The zoom comes along when the
11
+ * link has one.
12
+ */
13
+ export declare function parseMapLink(input: string): (GeoPoint & {
14
+ zoom?: number;
15
+ }) | null;
16
+ /** World pixel position of a point at a zoom (Web Mercator, 256-pixel tiles). */
17
+ export declare function projectPoint(p: GeoPoint, zoom: number): {
18
+ x: number;
19
+ y: number;
20
+ };
21
+ /** The point at a world pixel position (the inverse of projectPoint). */
22
+ export declare function unprojectPoint(x: number, y: number, zoom: number): GeoPoint;
23
+ /** The centre and highest zoom that show every point in a box of width × height pixels (with padding). */
24
+ export declare function fitPoints(points: GeoPoint[], width: number, height: number, padding?: number, maxZoom?: number): {
25
+ center: GeoPoint;
26
+ zoom: number;
27
+ };
@@ -0,0 +1,89 @@
1
+ // Places on a map, and the Web Mercator arithmetic for drawing
2
+ // OpenStreetMap tiles. A copy of @mycms/shared-types' version (this
3
+ // package can't depend on it); keep the two in step.
4
+ export const MIN_MAP_ZOOM = 1;
5
+ export const MAX_MAP_ZOOM = 19;
6
+ export const MAP_TILE_SIZE = 256;
7
+ /** Web Mercator stops here; tiles don't go nearer the poles. */
8
+ const MAX_LAT = 85.05112878;
9
+ const inRange = (lat, lng) => Number.isFinite(lat) && Number.isFinite(lng) && Math.abs(lat) <= 90 && Math.abs(lng) <= 180;
10
+ const round6 = (v) => Math.round(v * 1e6) / 1e6;
11
+ /**
12
+ * A place from what an editor pastes: '24.7136, 46.6753', or a link to
13
+ * OpenStreetMap, Google Maps or Apple Maps. The zoom comes along when the
14
+ * link has one.
15
+ */
16
+ export function parseMapLink(input) {
17
+ const text = input.trim();
18
+ const pair = /^(-?\d{1,2}(?:\.\d+)?)\s*[,\s]\s*(-?\d{1,3}(?:\.\d+)?)$/.exec(text);
19
+ if (pair) {
20
+ const lat = Number(pair[1]);
21
+ const lng = Number(pair[2]);
22
+ return inRange(lat, lng) ? { lat: round6(lat), lng: round6(lng) } : null;
23
+ }
24
+ let url;
25
+ try {
26
+ url = new URL(text);
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ if (url.protocol !== 'https:' && url.protocol !== 'http:')
32
+ return null;
33
+ const found = (lat, lng, zoom) => inRange(lat, lng) ? { lat: round6(lat), lng: round6(lng), ...(zoom && zoom >= MIN_MAP_ZOOM ? { zoom: Math.min(MAX_MAP_ZOOM, Math.round(zoom)) } : {}) } : null;
34
+ // OpenStreetMap: ?mlat=&mlon= and/or #map=zoom/lat/lng
35
+ const hash = /#map=(\d{1,2})\/(-?[\d.]+)\/(-?[\d.]+)/.exec(url.hash);
36
+ const mlat = url.searchParams.get('mlat');
37
+ const mlon = url.searchParams.get('mlon');
38
+ if (mlat && mlon)
39
+ return found(Number(mlat), Number(mlon), hash ? Number(hash[1]) : undefined);
40
+ if (hash)
41
+ return found(Number(hash[2]), Number(hash[3]), Number(hash[1]));
42
+ // Google Maps: /@lat,lng,15z (or 15m), or ?q=lat,lng / ?query=lat,lng
43
+ const at = /@(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)(?:,(\d+(?:\.\d+)?)z)?/.exec(url.pathname);
44
+ if (at)
45
+ return found(Number(at[1]), Number(at[2]), at[3] ? Number(at[3]) : undefined);
46
+ // Apple Maps ?ll= or ?coordinate=, Google ?q= / ?query=
47
+ for (const key of ['ll', 'coordinate', 'q', 'query', 'center']) {
48
+ const v = url.searchParams.get(key);
49
+ const m = v ? /^(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)$/.exec(v) : null;
50
+ if (m) {
51
+ const z = Number(url.searchParams.get('z') ?? url.searchParams.get('zoom') ?? NaN);
52
+ return found(Number(m[1]), Number(m[2]), Number.isFinite(z) ? z : undefined);
53
+ }
54
+ }
55
+ return null;
56
+ }
57
+ /** World pixel position of a point at a zoom (Web Mercator, 256-pixel tiles). */
58
+ export function projectPoint(p, zoom) {
59
+ const scale = MAP_TILE_SIZE * 2 ** zoom;
60
+ const lat = Math.max(-MAX_LAT, Math.min(MAX_LAT, p.lat));
61
+ const sin = Math.sin((lat * Math.PI) / 180);
62
+ return { x: ((p.lng + 180) / 360) * scale, y: (0.5 - Math.log((1 + sin) / (1 - sin)) / (4 * Math.PI)) * scale };
63
+ }
64
+ /** The point at a world pixel position (the inverse of projectPoint). */
65
+ export function unprojectPoint(x, y, zoom) {
66
+ const scale = MAP_TILE_SIZE * 2 ** zoom;
67
+ const lng = (x / scale) * 360 - 180;
68
+ const n = Math.PI - (2 * Math.PI * y) / scale;
69
+ return { lat: (180 / Math.PI) * Math.atan(Math.sinh(n)), lng: ((((lng + 180) % 360) + 360) % 360) - 180 };
70
+ }
71
+ /** The centre and highest zoom that show every point in a box of width × height pixels (with padding). */
72
+ export function fitPoints(points, width, height, padding = 48, maxZoom = 16) {
73
+ if (!points.length)
74
+ return { center: { lat: 20, lng: 0 }, zoom: 2 };
75
+ if (points.length === 1)
76
+ return { center: points[0], zoom: Math.min(maxZoom, 15) };
77
+ for (let z = maxZoom; z > MIN_MAP_ZOOM; z--) {
78
+ const px = points.map((p) => projectPoint(p, z));
79
+ const xs = px.map((p) => p.x);
80
+ const ys = px.map((p) => p.y);
81
+ if (Math.max(...xs) - Math.min(...xs) <= width - padding * 2 && Math.max(...ys) - Math.min(...ys) <= height - padding * 2) {
82
+ return { center: unprojectPoint((Math.max(...xs) + Math.min(...xs)) / 2, (Math.max(...ys) + Math.min(...ys)) / 2, z), zoom: z };
83
+ }
84
+ }
85
+ const px = points.map((p) => projectPoint(p, MIN_MAP_ZOOM));
86
+ const cx = px.reduce((a, p) => a + p.x, 0) / px.length;
87
+ const cy = px.reduce((a, p) => a + p.y, 0) / px.length;
88
+ return { center: unprojectPoint(cx, cy, MIN_MAP_ZOOM), zoom: MIN_MAP_ZOOM };
89
+ }
@@ -0,0 +1,19 @@
1
+ import { type ElementType } from 'react';
2
+ import type { SlotMenuItem } from '../slots-core.js';
3
+ export interface NavMenuProps {
4
+ items: SlotMenuItem[];
5
+ /** The nav's accessible name. Default "Main". */
6
+ label?: string;
7
+ /** The current page's path, marked aria-current="page" when an item links to it. */
8
+ currentPath?: string;
9
+ /** Renders links, e.g. Next.js Link. Default <a>. */
10
+ linkComponent?: ElementType;
11
+ /** Text on the button that opens the menu on small screens. Default "Menu". */
12
+ toggleLabel?: string;
13
+ className?: string;
14
+ /** Spread on the nav, e.g. slot.edit('menu') for VeroXM's on-page editor. */
15
+ editProps?: Record<string, string>;
16
+ }
17
+ /** Links VeroXM accepts in a menu; anything else renders as plain text. */
18
+ export declare function isSafeMenuHref(href: string): boolean;
19
+ export declare function NavMenu({ items, label, currentPath, linkComponent, toggleLabel, className, editProps }: NavMenuProps): import("react").JSX.Element | null;
@@ -0,0 +1,76 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useRef, useState } from 'react';
4
+ /** Links VeroXM accepts in a menu; anything else renders as plain text. */
5
+ export function isSafeMenuHref(href) {
6
+ return /^(https?:\/\/|mailto:|tel:|\/(?!\/)|#)/i.test(href.trim());
7
+ }
8
+ const samePage = (href, current) => {
9
+ if (!current || !href.startsWith('/'))
10
+ return false;
11
+ const clean = (p) => p.split(/[?#]/)[0].replace(/\/+$/, '') || '/';
12
+ return clean(href) === clean(current);
13
+ };
14
+ function MenuLink({ item, currentPath, Link, onNavigate }) {
15
+ if (!item.href || !isSafeMenuHref(item.href))
16
+ return _jsx("span", { className: "vxs-nav-text", children: item.label });
17
+ return (_jsxs(Link, { className: "vxs-nav-link", href: item.href, onClick: onNavigate, ...(samePage(item.href, currentPath) ? { 'aria-current': 'page' } : {}), ...(item.newTab ? { target: '_blank', rel: 'noopener noreferrer' } : {}), children: [item.label, item.newTab ? _jsx("span", { className: "vxs-sr", children: " (opens in a new tab)" }) : null] }));
18
+ }
19
+ export function NavMenu({ items, label = 'Main', currentPath, linkComponent = 'a', toggleLabel = 'Menu', className, editProps }) {
20
+ const id = useId();
21
+ const navRef = useRef(null);
22
+ // Open sub-menus, by path ("0", "0-2"); opening one closes its siblings.
23
+ const [open, setOpen] = useState([]);
24
+ const [mobileOpen, setMobileOpen] = useState(false);
25
+ const closeAll = () => {
26
+ setOpen([]);
27
+ setMobileOpen(false);
28
+ };
29
+ useEffect(() => {
30
+ if (!open.length && !mobileOpen)
31
+ return;
32
+ const outside = (e) => {
33
+ if (navRef.current && e.target instanceof Node && !navRef.current.contains(e.target)) {
34
+ setOpen([]);
35
+ if (e.type !== 'focusin')
36
+ setMobileOpen(false);
37
+ }
38
+ };
39
+ const onKey = (e) => {
40
+ if (e.key !== 'Escape')
41
+ return;
42
+ const deepest = open[open.length - 1];
43
+ if (deepest !== undefined) {
44
+ setOpen(open.slice(0, -1));
45
+ navRef.current?.querySelector(`[data-vxs-toggle="${deepest}"]`)?.focus();
46
+ }
47
+ else if (mobileOpen) {
48
+ setMobileOpen(false);
49
+ navRef.current?.querySelector('.vxs-nav-toggle')?.focus();
50
+ }
51
+ };
52
+ document.addEventListener('pointerdown', outside);
53
+ document.addEventListener('focusin', outside);
54
+ document.addEventListener('keydown', onKey);
55
+ return () => {
56
+ document.removeEventListener('pointerdown', outside);
57
+ document.removeEventListener('focusin', outside);
58
+ document.removeEventListener('keydown', onKey);
59
+ };
60
+ }, [open, mobileOpen]);
61
+ const toggle = (key) => setOpen((cur) => {
62
+ if (cur.includes(key))
63
+ return cur.filter((k) => k !== key && !k.startsWith(`${key}-`));
64
+ // Keep the open ancestors, close everything else.
65
+ return [...cur.filter((k) => key.startsWith(`${k}-`)), key];
66
+ });
67
+ const list = (entries, parent, level) => (_jsx("ul", { className: level === 1 ? 'vxs-nav-list' : `vxs-nav-sub vxs-nav-sub-${level}`, id: level === 1 ? `${id}-list` : `${id}-sub-${parent}`, hidden: level === 1 ? undefined : !open.includes(parent), "data-open": level === 1 ? (mobileOpen ? 'true' : 'false') : undefined, children: entries.map((item, i) => {
68
+ const key = parent ? `${parent}-${i}` : `${i}`;
69
+ const kids = item.children?.length ? item.children : null;
70
+ const isOpen = open.includes(key);
71
+ return (_jsxs("li", { className: `vxs-nav-item${kids ? ' vxs-nav-parent' : ''}`, children: [kids && !item.href ? (_jsxs("button", { type: "button", className: "vxs-nav-button", "aria-expanded": isOpen, "aria-controls": `${id}-sub-${key}`, "data-vxs-toggle": key, onClick: () => toggle(key), children: [item.label, _jsx("span", { className: "vxs-caret", "aria-hidden": "true" })] })) : (_jsxs("span", { className: "vxs-nav-row", children: [_jsx(MenuLink, { item: item, currentPath: currentPath, Link: linkComponent, onNavigate: closeAll }), kids ? (_jsx("button", { type: "button", className: "vxs-nav-button vxs-nav-more", "aria-expanded": isOpen, "aria-controls": `${id}-sub-${key}`, "aria-label": `${item.label}: more links`, "data-vxs-toggle": key, onClick: () => toggle(key), children: _jsx("span", { className: "vxs-caret", "aria-hidden": "true" }) })) : null] })), kids ? list(kids, key, level + 1) : null] }, key));
72
+ }) }));
73
+ if (!items.length)
74
+ return null;
75
+ return (_jsxs("nav", { ref: navRef, "aria-label": label, className: `vxs-nav${className ? ` ${className}` : ''}`, ...editProps, children: [_jsxs("button", { type: "button", className: "vxs-nav-toggle", "aria-expanded": mobileOpen, "aria-controls": `${id}-list`, onClick: () => setMobileOpen((v) => !v), children: [_jsx("span", { className: "vxs-burger", "aria-hidden": "true" }), _jsx("span", { className: "vxs-nav-toggle-text", children: toggleLabel })] }), list(items, '', 1)] }));
76
+ }
@@ -0,0 +1,87 @@
1
+ import type { ElementType, ReactNode } from 'react';
2
+ import { type SlotLink, type SlotMedia, type SlotMenuItem } from '../slots-core.js';
3
+ /** What marketers edit in a site header. */
4
+ export declare const headerFields: {
5
+ logo: {
6
+ label?: string;
7
+ required?: boolean;
8
+ type: "media";
9
+ };
10
+ logoText: {
11
+ label?: string;
12
+ required?: boolean;
13
+ max?: number;
14
+ type: "text";
15
+ };
16
+ menu: {
17
+ label?: string;
18
+ required?: boolean;
19
+ depth?: 1 | 2 | 3;
20
+ type: "menu";
21
+ };
22
+ cta: {
23
+ label?: string;
24
+ required?: boolean;
25
+ type: "link";
26
+ };
27
+ };
28
+ /** What marketers edit in a site footer. Each top-level item of `columns` is a column heading, its sub-items the links under it. */
29
+ export declare const footerFields: {
30
+ columns: {
31
+ label?: string;
32
+ required?: boolean;
33
+ depth?: 1 | 2 | 3;
34
+ type: "menu";
35
+ };
36
+ text: {
37
+ label?: string;
38
+ required?: boolean;
39
+ max?: number;
40
+ type: "richText";
41
+ };
42
+ social: {
43
+ label?: string;
44
+ required?: boolean;
45
+ depth?: 1 | 2 | 3;
46
+ type: "menu";
47
+ };
48
+ legal: {
49
+ label?: string;
50
+ required?: boolean;
51
+ max?: number;
52
+ type: "text";
53
+ };
54
+ };
55
+ type Edit = (fieldName: string) => Record<string, string>;
56
+ export interface SiteHeaderProps {
57
+ logo?: SlotMedia | null;
58
+ logoText?: string;
59
+ menu?: SlotMenuItem[];
60
+ cta?: SlotLink | null;
61
+ /** Where the logo links. Default "/". */
62
+ homeHref?: string;
63
+ currentPath?: string;
64
+ /** Renders links, e.g. Next.js Link. Default <a>. */
65
+ linkComponent?: ElementType;
66
+ /** slot.edit, so each part can be picked in VeroXM's on-page editor. */
67
+ edit?: Edit;
68
+ /** Stays at the top while the page scrolls. */
69
+ sticky?: boolean;
70
+ className?: string;
71
+ /** Extra content at the end, such as a language switcher or a search button. */
72
+ children?: ReactNode;
73
+ }
74
+ export declare function SiteHeader({ logo, logoText, menu, cta, homeHref, currentPath, linkComponent, edit, sticky, className, children }: SiteHeaderProps): import("react").JSX.Element;
75
+ export interface SiteFooterProps {
76
+ columns?: SlotMenuItem[];
77
+ /** Rich text, as VeroXM stores it (already cleaned to a safe set of tags). */
78
+ text?: string;
79
+ social?: SlotMenuItem[];
80
+ legal?: string;
81
+ linkComponent?: ElementType;
82
+ edit?: Edit;
83
+ className?: string;
84
+ children?: ReactNode;
85
+ }
86
+ export declare function SiteFooter({ columns, text, social, legal, linkComponent, edit, className, children }: SiteFooterProps): import("react").JSX.Element;
87
+ export {};
@@ -0,0 +1,46 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { field } from '../slots-core.js';
3
+ import { NavMenu, isSafeMenuHref } from './nav-menu.js';
4
+ // A site's header and footer, edited from VeroXM like any slot. The field
5
+ // presets say what marketers can change; the components render them:
6
+ //
7
+ // <VeroxmSlot name="site.header" fields={headerFields} fallback={{ logoText: 'Acme' }}>
8
+ // {(s, slot) => <SiteHeader {...s} edit={slot.edit} />}
9
+ // </VeroxmSlot>
10
+ //
11
+ // No hooks here, so both work in Server Components (NavMenu, inside the
12
+ // header, is the only client part).
13
+ /** What marketers edit in a site header. */
14
+ export const headerFields = {
15
+ logo: field.media({ label: 'Logo' }),
16
+ logoText: field.text({ label: 'Site name', max: 60 }),
17
+ menu: field.menu({ label: 'Main menu', depth: 2 }),
18
+ cta: field.link({ label: 'Button' }),
19
+ };
20
+ /** What marketers edit in a site footer. Each top-level item of `columns` is a column heading, its sub-items the links under it. */
21
+ export const footerFields = {
22
+ columns: field.menu({ label: 'Link columns', depth: 2 }),
23
+ text: field.richText({ label: 'About text', max: 500 }),
24
+ social: field.menu({ label: 'Social links', depth: 1 }),
25
+ legal: field.text({ label: 'Legal line', max: 200 }),
26
+ };
27
+ const noEdit = () => ({});
28
+ function Logo({ logo, text }) {
29
+ if (!logo?.url)
30
+ return _jsx("span", { className: "vxs-brand-text", children: text });
31
+ const img = _jsx("img", { className: "vxs-logo", src: logo.url, alt: text || logo.alt, width: logo.width ?? undefined, height: logo.height ?? undefined });
32
+ return logo.webpUrl ? (_jsxs("picture", { children: [_jsx("source", { srcSet: logo.webpUrl, type: "image/webp" }), img] })) : (img);
33
+ }
34
+ function Anchor({ href, className, children, Link, newTab, ...rest }) {
35
+ if (!isSafeMenuHref(href))
36
+ return _jsx("span", { className: className, children: children });
37
+ return (_jsx(Link, { href: href, className: className, ...(newTab ? { target: '_blank', rel: 'noopener noreferrer' } : {}), ...rest, children: children }));
38
+ }
39
+ export function SiteHeader({ logo = null, logoText = '', menu = [], cta = null, homeHref = '/', currentPath, linkComponent = 'a', edit = noEdit, sticky, className, children }) {
40
+ const Link = linkComponent;
41
+ return (_jsx("header", { className: `vxs-header${sticky ? ' vxs-sticky' : ''}${className ? ` ${className}` : ''}`, children: _jsxs("div", { className: "vxs-header-inner", children: [_jsx(Link, { href: homeHref, className: "vxs-brand", "aria-label": logo?.url ? `${logoText || logo.alt || 'Home'}, home` : undefined, ...edit(logo?.url ? 'logo' : 'logoText'), children: _jsx(Logo, { logo: logo, text: logoText }) }), _jsx(NavMenu, { items: menu, currentPath: currentPath, linkComponent: linkComponent, editProps: edit('menu') }), cta?.href ? (_jsx(Anchor, { href: cta.href, className: "vxs-cta", Link: Link, ...edit('cta'), children: cta.label || cta.href })) : null, children] }) }));
42
+ }
43
+ export function SiteFooter({ columns = [], text = '', social = [], legal = '', linkComponent = 'a', edit = noEdit, className, children }) {
44
+ const Link = linkComponent;
45
+ return (_jsxs("footer", { className: `vxs-footer${className ? ` ${className}` : ''}`, children: [_jsxs("div", { className: "vxs-footer-inner", children: [text ? _jsx("div", { className: "vxs-footer-text", ...edit('text'), dangerouslySetInnerHTML: { __html: text } }) : null, columns.length ? (_jsx("nav", { "aria-label": "Footer", className: "vxs-footer-columns", ...edit('columns'), children: columns.map((col, i) => (_jsxs("div", { className: "vxs-footer-column", children: [col.href ? (_jsx(Anchor, { href: col.href, className: "vxs-footer-heading", Link: Link, newTab: col.newTab, children: col.label })) : (_jsx("p", { className: "vxs-footer-heading", children: col.label })), col.children?.length ? (_jsx("ul", { children: col.children.map((item, j) => (_jsx("li", { children: _jsx(Anchor, { href: item.href, className: "vxs-footer-link", Link: Link, newTab: item.newTab, children: item.label }) }, j))) })) : null] }, i))) })) : null] }), social.length || legal || children ? (_jsxs("div", { className: "vxs-footer-bottom", children: [legal ? (_jsx("p", { className: "vxs-legal", ...edit('legal'), children: legal })) : null, social.length ? (_jsx("ul", { className: "vxs-social", "aria-label": "Social media", ...edit('social'), children: social.map((item, i) => (_jsx("li", { children: _jsx(Anchor, { href: item.href, className: "vxs-footer-link", Link: Link, newTab: item.newTab, children: item.label }) }, i))) })) : null, children] })) : null] }));
46
+ }
@@ -0,0 +1,17 @@
1
+ import { type ElementType, type ReactNode } from 'react';
2
+ import type { SlotSlide } from '../slots-core.js';
3
+ export interface SliderProps {
4
+ slides: SlotSlide[];
5
+ /** The slider's accessible name. Default "Slides". */
6
+ label?: string;
7
+ /** Seconds per slide when moving by itself; 0 (the default) never moves by itself. */
8
+ autoplay?: number;
9
+ /** Your own markup for a slide, instead of the image with its title, text and button. */
10
+ renderSlide?: (slide: SlotSlide, index: number) => ReactNode;
11
+ /** Renders slide buttons' links, e.g. Next.js Link. Default <a>. */
12
+ linkComponent?: ElementType;
13
+ className?: string;
14
+ /** Spread on the slider, e.g. slot.edit('slides') for VeroXM's on-page editor. */
15
+ editProps?: Record<string, string>;
16
+ }
17
+ export declare function Slider({ slides, label, autoplay, renderSlide, linkComponent, className, editProps }: SliderProps): import("react").JSX.Element | null;
@@ -0,0 +1,78 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useCallback, useEffect, useId, useRef, useState } from 'react';
4
+ import { isSafeMenuHref } from './nav-menu.js';
5
+ const reducedMotion = () => typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
6
+ function DefaultSlide({ slide, index, Link }) {
7
+ const img = slide.image;
8
+ const p = img?.focalPoint;
9
+ const position = p ? `${Math.round(p.x * 100)}% ${Math.round(p.y * 100)}%` : undefined;
10
+ return (_jsxs(_Fragment, { children: [img?.url ? (_jsxs("picture", { children: [img.webpUrl ? _jsx("source", { srcSet: img.webpUrl, type: "image/webp" }) : null, _jsx("img", { className: "vxs-slide-img", src: img.url, alt: slide.title ? '' : img.alt, width: img.width ?? undefined, height: img.height ?? undefined, loading: index === 0 ? 'eager' : 'lazy', decoding: "async", style: position ? { objectPosition: position } : undefined })] })) : null, slide.title || slide.text || slide.link?.href ? (_jsxs("div", { className: "vxs-slide-caption", children: [slide.title ? _jsx("p", { className: "vxs-slide-title", children: slide.title }) : null, slide.text ? _jsx("p", { className: "vxs-slide-text", children: slide.text }) : null, slide.link?.href && isSafeMenuHref(slide.link.href) ? (_jsx(Link, { className: "vxs-slide-link", href: slide.link.href, children: slide.link.label || slide.link.href })) : null] })) : null] }));
11
+ }
12
+ export function Slider({ slides, label = 'Slides', autoplay = 0, renderSlide, linkComponent = 'a', className, editProps }) {
13
+ const id = useId();
14
+ const rootRef = useRef(null);
15
+ const slideRefs = useRef([]);
16
+ const [index, setIndex] = useState(0);
17
+ const [paused, setPaused] = useState(false); // the pause button
18
+ const [held, setHeld] = useState(false); // pointer or focus on the slider
19
+ const [rtl, setRtl] = useState(false);
20
+ const [still, setStill] = useState(false);
21
+ const swipe = useRef(null);
22
+ const count = slides.length;
23
+ const current = count ? Math.min(index, count - 1) : 0;
24
+ const go = useCallback((to) => setIndex(((to % count) + count) % count), [count]);
25
+ useEffect(() => {
26
+ if (rootRef.current)
27
+ setRtl(getComputedStyle(rootRef.current).direction === 'rtl');
28
+ setStill(reducedMotion());
29
+ }, []);
30
+ // Slides off screen can't be reached by keyboard or read out.
31
+ useEffect(() => {
32
+ slideRefs.current.forEach((el, i) => {
33
+ if (el)
34
+ el.inert = i !== current;
35
+ });
36
+ }, [current, count]);
37
+ const moving = autoplay > 0 && count > 1 && !paused && !held && !still;
38
+ useEffect(() => {
39
+ if (!moving)
40
+ return;
41
+ const t = setInterval(() => setIndex((i) => (i + 1) % count), autoplay * 1000);
42
+ return () => clearInterval(t);
43
+ }, [moving, autoplay, count]);
44
+ if (!count)
45
+ return null;
46
+ const prev = () => go(current - 1);
47
+ const next = () => go(current + 1);
48
+ const shift = `${(rtl ? 1 : -1) * current * 100}%`;
49
+ return (_jsxs("section", { ref: rootRef, className: `vxs-slider${className ? ` ${className}` : ''}`, "aria-roledescription": "carousel", "aria-label": label, onMouseEnter: () => setHeld(true), onMouseLeave: () => setHeld(false), onFocus: () => setHeld(true), onBlur: (e) => {
50
+ if (!e.currentTarget.contains(e.relatedTarget))
51
+ setHeld(false);
52
+ }, onKeyDown: (e) => {
53
+ if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight')
54
+ return;
55
+ const forward = (e.key === 'ArrowRight') !== rtl;
56
+ e.preventDefault();
57
+ if (forward)
58
+ next();
59
+ else
60
+ prev();
61
+ }, ...editProps, children: [_jsx("div", { className: "vxs-slider-viewport", onPointerDown: (e) => {
62
+ swipe.current = { x: e.clientX, y: e.clientY };
63
+ }, onPointerUp: (e) => {
64
+ const start = swipe.current;
65
+ swipe.current = null;
66
+ if (!start)
67
+ return;
68
+ const dx = e.clientX - start.x;
69
+ if (Math.abs(dx) < 40 || Math.abs(dx) < Math.abs(e.clientY - start.y))
70
+ return;
71
+ if (dx < 0 !== rtl)
72
+ next();
73
+ else
74
+ prev();
75
+ }, children: _jsx("div", { className: "vxs-slider-track", id: `${id}-track`, "aria-live": moving ? 'off' : 'polite', style: { transform: `translateX(${shift})` }, children: slides.map((slide, i) => (_jsx("div", { ref: (el) => {
76
+ slideRefs.current[i] = el;
77
+ }, className: "vxs-slide", role: "group", "aria-roledescription": "slide", "aria-label": `${i + 1} of ${count}${slide.title ? `: ${slide.title}` : ''}`, children: renderSlide ? renderSlide(slide, i) : _jsx(DefaultSlide, { slide: slide, index: i, Link: linkComponent }) }, i))) }) }), count > 1 ? (_jsxs("div", { className: "vxs-slider-controls", children: [autoplay > 0 && !still ? (_jsx("button", { type: "button", className: "vxs-slider-btn vxs-slider-pause", onClick: () => setPaused((p) => !p), "aria-label": paused ? 'Play slides' : 'Pause slides', children: _jsx("span", { className: paused ? 'vxs-icon-play' : 'vxs-icon-pause', "aria-hidden": "true" }) })) : null, _jsx("button", { type: "button", className: "vxs-slider-btn vxs-slider-prev", onClick: prev, "aria-controls": `${id}-track`, "aria-label": "Previous slide", children: _jsx("span", { className: "vxs-chevron", "aria-hidden": "true" }) }), _jsx("div", { className: "vxs-slider-dots", children: slides.map((slide, i) => (_jsx("button", { type: "button", className: "vxs-slider-dot", "aria-controls": `${id}-track`, "aria-current": i === current ? 'true' : undefined, "aria-label": `Show slide ${i + 1}${slide.title ? `: ${slide.title}` : ''}`, onClick: () => go(i) }, i))) }), _jsx("button", { type: "button", className: "vxs-slider-btn vxs-slider-next", onClick: next, "aria-controls": `${id}-track`, "aria-label": "Next slide", children: _jsx("span", { className: "vxs-chevron", "aria-hidden": "true" }) })] })) : null] }));
78
+ }