@keystone-sites/marketing-design-system 1.0.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.
- package/AGENTS.md +163 -0
- package/README.md +85 -0
- package/assets/media/brand/ks-lockup.svg +13 -0
- package/assets/media/brand/ks-logomark.svg +4 -0
- package/assets/media/brand/ks-wordmark-inline.svg +13 -0
- package/assets/media/brand/ks-wordmark.svg +11 -0
- package/assets/media/fonts/gt-standard-standard-vf.woff2 +0 -0
- package/assets/media/fonts/pp-kyoto-variable-upright-vf.woff2 +0 -0
- package/base.css +111 -0
- package/css-vars.d.ts +10 -0
- package/grid/engine.css +368 -0
- package/grid/field-hash.ts +31 -0
- package/grid/field.tsx +48 -0
- package/grid/gates.cjs +34 -0
- package/grid/region.tsx +97 -0
- package/icons.tsx +1224 -0
- package/index.css +77 -0
- package/lib/autoplay-gate.ts +88 -0
- package/lib/focus-trap.ts +42 -0
- package/lib/grader.ts +131 -0
- package/lib/legal-data.ts +1 -0
- package/lib/legal.ts +41 -0
- package/lib/noise.tsx +114 -0
- package/lib/render-boundary.tsx +27 -0
- package/lib/scroll-lock.ts +25 -0
- package/lib/swipe.ts +124 -0
- package/lib/use-active-section.ts +43 -0
- package/lib/use-count-up.ts +26 -0
- package/lib/use-grader-search.ts +118 -0
- package/lib/use-video-carousel.ts +271 -0
- package/media.ts +558 -0
- package/package.json +201 -0
- package/primitives/button-inline.css +52 -0
- package/primitives/button-inline.tsx +38 -0
- package/primitives/buttons.css +449 -0
- package/primitives/buttons.tsx +263 -0
- package/primitives/case-study-button.css +71 -0
- package/primitives/case-study-button.tsx +28 -0
- package/primitives/case-study-card.css +318 -0
- package/primitives/case-study-card.tsx +116 -0
- package/primitives/closer-row.css +14 -0
- package/primitives/closer-row.tsx +22 -0
- package/primitives/cta-row.css +41 -0
- package/primitives/cta-row.tsx +39 -0
- package/primitives/disclosure.css +210 -0
- package/primitives/disclosure.tsx +144 -0
- package/primitives/faq-question.css +220 -0
- package/primitives/faq-question.tsx +55 -0
- package/primitives/field.css +225 -0
- package/primitives/field.tsx +266 -0
- package/primitives/footer-item.css +72 -0
- package/primitives/footer-item.tsx +42 -0
- package/primitives/grader-menu.tsx +84 -0
- package/primitives/grader.css +302 -0
- package/primitives/grader.tsx +284 -0
- package/primitives/modal.css +151 -0
- package/primitives/modal.tsx +90 -0
- package/primitives/notice.css +39 -0
- package/primitives/notice.tsx +56 -0
- package/primitives/persona-card.css +374 -0
- package/primitives/persona-card.tsx +74 -0
- package/primitives/picture.css +11 -0
- package/primitives/picture.tsx +41 -0
- package/primitives/plan-card.css +378 -0
- package/primitives/plan-card.tsx +91 -0
- package/primitives/prose.css +118 -0
- package/primitives/prose.tsx +170 -0
- package/primitives/ramps.css +84 -0
- package/primitives/slider.css +179 -0
- package/primitives/slider.tsx +69 -0
- package/primitives/slug.css +87 -0
- package/primitives/slug.tsx +37 -0
- package/primitives/status.css +298 -0
- package/primitives/status.tsx +222 -0
- package/primitives/strip.css +40 -0
- package/primitives/surface.css +78 -0
- package/primitives/surface.tsx +95 -0
- package/primitives/table.css +226 -0
- package/primitives/table.tsx +122 -0
- package/primitives/tabs.css +85 -0
- package/primitives/tabs.tsx +122 -0
- package/primitives/text.css +110 -0
- package/primitives/toc.css +65 -0
- package/primitives/toc.tsx +42 -0
- package/rules/design-system.md +154 -0
- package/rules/grid-and-layout.md +166 -0
- package/scripts/generate-exports.mjs +61 -0
- package/scripts/generate-type-css.mjs +130 -0
- package/sections/faq-island.tsx +102 -0
- package/sections/faq.css +213 -0
- package/sections/faq.tsx +46 -0
- package/sections/footer-nav.tsx +95 -0
- package/sections/footer-signature.css +183 -0
- package/sections/footer-signature.tsx +114 -0
- package/sections/footer.css +735 -0
- package/sections/footer.tsx +283 -0
- package/sections/gallery-overlay.css +213 -0
- package/sections/gallery-overlay.tsx +267 -0
- package/sections/landing-benefits.css +59 -0
- package/sections/landing-benefits.tsx +81 -0
- package/sections/landing-closer.css +23 -0
- package/sections/landing-closer.tsx +26 -0
- package/sections/landing-hero.css +80 -0
- package/sections/landing-hero.tsx +69 -0
- package/sections/landing-quote.css +19 -0
- package/sections/landing-quote.tsx +30 -0
- package/sections/landing-sample.ts +66 -0
- package/sections/landing.css +45 -0
- package/sections/landing.tsx +69 -0
- package/sections/load-orchestrator.tsx +43 -0
- package/sections/load.css +138 -0
- package/sections/nav-desktop.css +530 -0
- package/sections/nav-desktop.tsx +155 -0
- package/sections/nav-mobile.css +571 -0
- package/sections/nav-mobile.tsx +222 -0
- package/sections/nav.css +126 -0
- package/sections/nav.tsx +394 -0
- package/sections/site-chat-data.ts +16 -0
- package/sections/site-chat-open.tsx +25 -0
- package/sections/site-chat.tsx +67 -0
- package/site-links.ts +36 -0
- package/site.ts +2 -0
- package/themes/inverted.css +139 -0
- package/tokens/fonts.css +38 -0
- package/tokens/motion.css +125 -0
- package/tokens/primitives.css +163 -0
- package/tokens/semantic.css +153 -0
- package/tokens/type-styles.json +145 -0
- package/tokens/type.css +1548 -0
- package/widgets.css +78 -0
package/index.css
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* The cascade is declared, not implied by import order. A later layer
|
|
2
|
+
beats an earlier one regardless of specificity, so a section rule always
|
|
3
|
+
wins over a primitive, and a page rule over a section. A consumer adds
|
|
4
|
+
its own files to `shared`, `sections`, and `pages` after importing this
|
|
5
|
+
file; it never adds rules here.
|
|
6
|
+
|
|
7
|
+
`theme` is the Tailwind theme that `widgets.css` imports for the
|
|
8
|
+
packaged widgets. It is declared first so the system's tokens win every
|
|
9
|
+
shared name (`--font-serif`, `--radius-*`, `--font-weight-*`). The
|
|
10
|
+
widget utilities themselves stay unlayered on purpose; see widgets.css.
|
|
11
|
+
|
|
12
|
+
Colour themes live in `themes/`. The light system is the default and
|
|
13
|
+
needs no import; a consumer on another ground imports one theme file
|
|
14
|
+
into `layer(skin)` after this one (see themes/inverted.css). `skin` is
|
|
15
|
+
last so a theme's remaps win over every layer's defaults; a theme only
|
|
16
|
+
ever sets custom properties the components already read. */
|
|
17
|
+
|
|
18
|
+
@layer theme, tokens, base, grid, primitives, shared, sections, pages, skin;
|
|
19
|
+
|
|
20
|
+
/* Tokens: fonts, palette, semantic roles, type, motion. */
|
|
21
|
+
@import "./tokens/fonts.css" layer(tokens);
|
|
22
|
+
@import "./tokens/primitives.css" layer(tokens);
|
|
23
|
+
@import "./tokens/semantic.css" layer(tokens);
|
|
24
|
+
@import "./tokens/type.css" layer(tokens);
|
|
25
|
+
@import "./tokens/motion.css" layer(tokens);
|
|
26
|
+
|
|
27
|
+
/* Base: the document reset and the site root. */
|
|
28
|
+
@import "./base.css" layer(base);
|
|
29
|
+
|
|
30
|
+
/* Grid: the tick engine, exposure vocabulary, side fields, band gates. */
|
|
31
|
+
@import "./grid/engine.css" layer(grid);
|
|
32
|
+
|
|
33
|
+
/* Primitives */
|
|
34
|
+
@import "./primitives/text.css" layer(primitives);
|
|
35
|
+
@import "./primitives/buttons.css" layer(primitives);
|
|
36
|
+
@import "./primitives/grader.css" layer(primitives);
|
|
37
|
+
@import "./primitives/faq-question.css" layer(primitives);
|
|
38
|
+
@import "./primitives/footer-item.css" layer(primitives);
|
|
39
|
+
@import "./primitives/plan-card.css" layer(primitives);
|
|
40
|
+
@import "./primitives/slider.css" layer(primitives);
|
|
41
|
+
@import "./primitives/persona-card.css" layer(primitives);
|
|
42
|
+
@import "./primitives/button-inline.css" layer(primitives);
|
|
43
|
+
@import "./primitives/case-study-card.css" layer(primitives);
|
|
44
|
+
@import "./primitives/case-study-button.css" layer(primitives);
|
|
45
|
+
@import "./primitives/field.css" layer(primitives);
|
|
46
|
+
@import "./primitives/slug.css" layer(primitives);
|
|
47
|
+
@import "./primitives/picture.css" layer(primitives);
|
|
48
|
+
@import "./primitives/ramps.css" layer(primitives);
|
|
49
|
+
@import "./primitives/closer-row.css" layer(primitives);
|
|
50
|
+
@import "./primitives/cta-row.css" layer(primitives);
|
|
51
|
+
@import "./primitives/toc.css" layer(primitives);
|
|
52
|
+
@import "./primitives/surface.css" layer(primitives);
|
|
53
|
+
@import "./primitives/prose.css" layer(primitives);
|
|
54
|
+
@import "./primitives/status.css" layer(primitives);
|
|
55
|
+
@import "./primitives/tabs.css" layer(primitives);
|
|
56
|
+
@import "./primitives/notice.css" layer(primitives);
|
|
57
|
+
@import "./primitives/modal.css" layer(primitives);
|
|
58
|
+
@import "./primitives/table.css" layer(primitives);
|
|
59
|
+
@import "./primitives/disclosure.css" layer(primitives);
|
|
60
|
+
@import "./primitives/strip.css" layer(primitives);
|
|
61
|
+
|
|
62
|
+
/* Shared: the landing kit's frame, which its sections refine. */
|
|
63
|
+
@import "./sections/landing.css" layer(shared);
|
|
64
|
+
|
|
65
|
+
/* Sections: site chrome and the kit. */
|
|
66
|
+
@import "./sections/footer.css" layer(sections);
|
|
67
|
+
@import "./sections/footer-signature.css" layer(sections);
|
|
68
|
+
@import "./sections/nav.css" layer(sections);
|
|
69
|
+
@import "./sections/nav-desktop.css" layer(sections);
|
|
70
|
+
@import "./sections/nav-mobile.css" layer(sections);
|
|
71
|
+
@import "./sections/faq.css" layer(sections);
|
|
72
|
+
@import "./sections/gallery-overlay.css" layer(sections);
|
|
73
|
+
@import "./sections/load.css" layer(sections);
|
|
74
|
+
@import "./sections/landing-hero.css" layer(sections);
|
|
75
|
+
@import "./sections/landing-benefits.css" layer(sections);
|
|
76
|
+
@import "./sections/landing-quote.css" layer(sections);
|
|
77
|
+
@import "./sections/landing-closer.css" layer(sections);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** The one rule for ambient motion: it runs only while the element is on
|
|
2
|
+
* screen, the tab is visible, the pointer and focus are elsewhere, and the
|
|
3
|
+
* reader has not asked for reduced motion. Every autoplaying carousel
|
|
4
|
+
* attaches this gate and asks `canRun()` before it advances. */
|
|
5
|
+
|
|
6
|
+
const VISIBILITY_THRESHOLD = 0.1;
|
|
7
|
+
|
|
8
|
+
export interface AutoplayGateHandlers {
|
|
9
|
+
/** The gate opened (or a condition that closed it cleared). */
|
|
10
|
+
onResume: () => void;
|
|
11
|
+
/** The gate closed. */
|
|
12
|
+
onPause: () => void;
|
|
13
|
+
/** The reduced-motion preference changed; runs before resume/pause. */
|
|
14
|
+
onMotionChange?: (reduced: boolean) => void;
|
|
15
|
+
/** The element resized (a band or tier may have changed). */
|
|
16
|
+
onResize?: () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AutoplayGate {
|
|
20
|
+
canRun: () => boolean;
|
|
21
|
+
detach: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function attachAutoplayGate(root: HTMLElement, h: AutoplayGateHandlers): AutoplayGate {
|
|
25
|
+
const motion = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
26
|
+
let visible = false;
|
|
27
|
+
let hovered = false;
|
|
28
|
+
let focused = false;
|
|
29
|
+
let detached = false;
|
|
30
|
+
|
|
31
|
+
const canRun = () =>
|
|
32
|
+
!detached && visible && !hovered && !focused && !document.hidden && !motion.matches;
|
|
33
|
+
const settle = () => (canRun() ? h.onResume() : h.onPause());
|
|
34
|
+
|
|
35
|
+
const onVisibility = settle;
|
|
36
|
+
const onPointerEnter = () => {
|
|
37
|
+
hovered = true;
|
|
38
|
+
h.onPause();
|
|
39
|
+
};
|
|
40
|
+
const onPointerLeave = () => {
|
|
41
|
+
hovered = false;
|
|
42
|
+
settle();
|
|
43
|
+
};
|
|
44
|
+
const onFocusIn = () => {
|
|
45
|
+
focused = true;
|
|
46
|
+
h.onPause();
|
|
47
|
+
};
|
|
48
|
+
const onFocusOut = (event: FocusEvent) => {
|
|
49
|
+
focused = event.relatedTarget instanceof Node && root.contains(event.relatedTarget);
|
|
50
|
+
if (!focused) settle();
|
|
51
|
+
};
|
|
52
|
+
const onMotionChange = () => {
|
|
53
|
+
h.onMotionChange?.(motion.matches);
|
|
54
|
+
settle();
|
|
55
|
+
};
|
|
56
|
+
const io = new IntersectionObserver(
|
|
57
|
+
([entry]) => {
|
|
58
|
+
visible = entry.isIntersecting;
|
|
59
|
+
settle();
|
|
60
|
+
},
|
|
61
|
+
{ threshold: VISIBILITY_THRESHOLD },
|
|
62
|
+
);
|
|
63
|
+
const ro = h.onResize ? new ResizeObserver(h.onResize) : null;
|
|
64
|
+
|
|
65
|
+
io.observe(root);
|
|
66
|
+
ro?.observe(root);
|
|
67
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
68
|
+
root.addEventListener("pointerenter", onPointerEnter);
|
|
69
|
+
root.addEventListener("pointerleave", onPointerLeave);
|
|
70
|
+
root.addEventListener("focusin", onFocusIn);
|
|
71
|
+
root.addEventListener("focusout", onFocusOut);
|
|
72
|
+
motion.addEventListener("change", onMotionChange);
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
canRun,
|
|
76
|
+
detach: () => {
|
|
77
|
+
detached = true;
|
|
78
|
+
io.disconnect();
|
|
79
|
+
ro?.disconnect();
|
|
80
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
81
|
+
root.removeEventListener("pointerenter", onPointerEnter);
|
|
82
|
+
root.removeEventListener("pointerleave", onPointerLeave);
|
|
83
|
+
root.removeEventListener("focusin", onFocusIn);
|
|
84
|
+
root.removeEventListener("focusout", onFocusOut);
|
|
85
|
+
motion.removeEventListener("change", onMotionChange);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const FOCUSABLE_SELECTOR = [
|
|
2
|
+
"a[href]",
|
|
3
|
+
"button:not(:disabled)",
|
|
4
|
+
"input:not(:disabled)",
|
|
5
|
+
"select:not(:disabled)",
|
|
6
|
+
"textarea:not(:disabled)",
|
|
7
|
+
"[tabindex]:not([tabindex='-1'])",
|
|
8
|
+
].join(",");
|
|
9
|
+
|
|
10
|
+
interface TabKeyEvent {
|
|
11
|
+
key: string;
|
|
12
|
+
shiftKey: boolean;
|
|
13
|
+
preventDefault(): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Keeps Tab navigation inside an active modal container. */
|
|
17
|
+
export function trapModalTab(event: TabKeyEvent, container: HTMLElement): void {
|
|
18
|
+
if (event.key !== "Tab") return;
|
|
19
|
+
|
|
20
|
+
const focusable = [...container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)].filter(
|
|
21
|
+
(element) =>
|
|
22
|
+
element.getClientRects().length > 0 && element.getAttribute("aria-hidden") !== "true",
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (!focusable.length) {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
container.focus();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const first = focusable[0];
|
|
32
|
+
const last = focusable[focusable.length - 1];
|
|
33
|
+
const active = document.activeElement;
|
|
34
|
+
|
|
35
|
+
if (event.shiftKey && (active === first || !container.contains(active))) {
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
last.focus();
|
|
38
|
+
} else if (!event.shiftKey && (active === last || !container.contains(active))) {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
first.focus();
|
|
41
|
+
}
|
|
42
|
+
}
|
package/lib/grader.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/** The grader input asks the Grader API for business
|
|
2
|
+
* suggestions (Google Places + independent websites) and hands the
|
|
3
|
+
* chosen one to the Grader web app, which reads these params on load
|
|
4
|
+
* and opens the business hub directly — no landing step.
|
|
5
|
+
*
|
|
6
|
+
* Plain constants and pure functions, no 'use client': the URL builders
|
|
7
|
+
* serve the server-rendered form (the no-JS fallback action) and the
|
|
8
|
+
* client island alike. The endpoints come from the environment (.env
|
|
9
|
+
* locally; the deploy's build env) with no guessed hosts: a marketing
|
|
10
|
+
* host names the Grader app and API; the Grader itself leaves the app
|
|
11
|
+
* URL unset (same origin) and is reached through its own API URL. A
|
|
12
|
+
* missing API fails the build's prerender rather than shipping a guess. */
|
|
13
|
+
|
|
14
|
+
/** `NEXT_PUBLIC_*` values are inlined at build time, so each one must be
|
|
15
|
+
* spelled out as a literal `process.env.NAME` read (no dynamic lookup). */
|
|
16
|
+
function required(name: string, value: string | undefined): string {
|
|
17
|
+
const trimmed = value?.trim();
|
|
18
|
+
if (!trimmed) {
|
|
19
|
+
throw new Error(`Missing environment variable ${name} (see .env — the Grader entry points).`);
|
|
20
|
+
}
|
|
21
|
+
return trimmed;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function optional(value: string | undefined, fallback: string): string {
|
|
25
|
+
const trimmed = value?.trim();
|
|
26
|
+
return trimmed || fallback;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function trimTrailingSlash(value: string): string {
|
|
30
|
+
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function splitCsv(value: string): string[] {
|
|
34
|
+
return value
|
|
35
|
+
.split(",")
|
|
36
|
+
.map((v) => v.trim())
|
|
37
|
+
.filter(Boolean);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The public Grader web app — the deep-link target. Empty means this
|
|
41
|
+
* origin is the Grader. */
|
|
42
|
+
export const GRADER_URL = trimTrailingSlash(optional(process.env.NEXT_PUBLIC_GRADER_URL, ""));
|
|
43
|
+
|
|
44
|
+
/** The Grader API base (the blue-ocean backend): the marketing host's
|
|
45
|
+
* `NEXT_PUBLIC_GRADER_API_URL`, or the Grader's own `NEXT_PUBLIC_API_URL`. */
|
|
46
|
+
const GRADER_API_BASE_URL = trimTrailingSlash(
|
|
47
|
+
required(
|
|
48
|
+
"NEXT_PUBLIC_GRADER_API_URL or NEXT_PUBLIC_API_URL",
|
|
49
|
+
process.env.NEXT_PUBLIC_GRADER_API_URL?.trim() || process.env.NEXT_PUBLIC_API_URL,
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
/** Search endpoint paths, tried in order (comma-separated in the env);
|
|
54
|
+
* the API's own route when unset. */
|
|
55
|
+
const GRADER_SEARCH_PATHS = splitCsv(
|
|
56
|
+
optional(process.env.NEXT_PUBLIC_GRADER_SEARCH_PATHS, "/grader/search"),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
/** One typeahead request's ceiling before the next path is tried. */
|
|
60
|
+
const GRADER_SEARCH_TIMEOUT_MS = 8000;
|
|
61
|
+
|
|
62
|
+
/** A business suggestion from the Grader search endpoint. */
|
|
63
|
+
export interface GraderSuggestion {
|
|
64
|
+
/** Google Places place_id, or the synthetic `web:{domain}` for a website pick. */
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
address: string;
|
|
68
|
+
website?: string | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface GraderSearchResponse {
|
|
72
|
+
places: GraderSuggestion[];
|
|
73
|
+
web: GraderSuggestion[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const EMPTY_GRADER_SEARCH: GraderSearchResponse = { places: [], web: [] };
|
|
77
|
+
|
|
78
|
+
function isSuggestion(value: unknown): value is GraderSuggestion {
|
|
79
|
+
if (!value || typeof value !== "object") return false;
|
|
80
|
+
const r = value as Record<string, unknown>;
|
|
81
|
+
return typeof r.id === "string" && typeof r.name === "string" && typeof r.address === "string";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Drop malformed entries from the grouped API response. */
|
|
85
|
+
function normalizeGraderSearchResponse(body: unknown): GraderSearchResponse {
|
|
86
|
+
if (body && typeof body === "object") {
|
|
87
|
+
const r = body as Record<string, unknown>;
|
|
88
|
+
return {
|
|
89
|
+
places: Array.isArray(r.places) ? r.places.filter(isSuggestion) : [],
|
|
90
|
+
web: Array.isArray(r.web) ? r.web.filter(isSuggestion) : [],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return EMPTY_GRADER_SEARCH;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The Grader deep link for a chosen business. The hub keys on `placeId`;
|
|
97
|
+
* name/address/website let it skip the metadata lookup. */
|
|
98
|
+
export function graderScanUrl(business: GraderSuggestion): string {
|
|
99
|
+
const params = new URLSearchParams({ placeId: business.id });
|
|
100
|
+
if (business.name.trim()) params.set("name", business.name.trim());
|
|
101
|
+
if (business.address.trim()) params.set("address", business.address.trim());
|
|
102
|
+
if (business.website?.trim()) params.set("website", business.website.trim());
|
|
103
|
+
return `${GRADER_URL}/?${params.toString()}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function graderSearchApiUrl(query: string, path: string): string {
|
|
107
|
+
return `${GRADER_API_BASE_URL}${path}?q=${encodeURIComponent(query)}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Query the search endpoint, walking the configured paths until one
|
|
111
|
+
* answers; a non-OK response or a network error moves to the next path,
|
|
112
|
+
* exhausting them yields the empty response. An aborted signal stops
|
|
113
|
+
* the walk immediately (re-thrown so the caller can ignore stale runs). */
|
|
114
|
+
export async function fetchGraderSuggestions(
|
|
115
|
+
query: string,
|
|
116
|
+
signal?: AbortSignal,
|
|
117
|
+
): Promise<GraderSearchResponse> {
|
|
118
|
+
for (const path of GRADER_SEARCH_PATHS) {
|
|
119
|
+
try {
|
|
120
|
+
const timeout = AbortSignal.timeout(GRADER_SEARCH_TIMEOUT_MS);
|
|
121
|
+
const combined = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
122
|
+
const resp = await fetch(graderSearchApiUrl(query, path), { signal: combined });
|
|
123
|
+
if (!resp.ok) continue;
|
|
124
|
+
return normalizeGraderSearchResponse(await resp.json());
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (signal?.aborted) throw error;
|
|
127
|
+
// timeout or network failure — try the next configured path
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return EMPTY_GRADER_SEARCH;
|
|
131
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const LEGAL_CONTACT_FALLBACK = "through the chat on this website";
|
package/lib/legal.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CompanyInformation } from "@keystone-sites/core/types";
|
|
2
|
+
import { SITE_URL } from "../site";
|
|
3
|
+
import { LEGAL_CONTACT_FALLBACK } from "./legal-data";
|
|
4
|
+
|
|
5
|
+
function siteHost(): string {
|
|
6
|
+
return new URL(SITE_URL).host;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Replaces backend legal-markdown tokens with current company values. */
|
|
10
|
+
export function replaceLegalPlaceholders(markdown: string, company: CompanyInformation): string {
|
|
11
|
+
const name = company.company_name?.trim() || "Keystone";
|
|
12
|
+
const email = company.primary_email || company.support_email || null;
|
|
13
|
+
const phone = company.primary_phone || null;
|
|
14
|
+
const contact = email ? `at ${email}` : phone ? `at ${phone}` : LEGAL_CONTACT_FALLBACK;
|
|
15
|
+
const locality = [company.primary_city, company.primary_state].filter(Boolean).join(", ");
|
|
16
|
+
const cityLine = [locality, company.primary_zip_code].filter(Boolean).join(" ");
|
|
17
|
+
const address = [
|
|
18
|
+
company.primary_address_line_1,
|
|
19
|
+
company.primary_address_line_2,
|
|
20
|
+
cityLine,
|
|
21
|
+
company.primary_country,
|
|
22
|
+
]
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.join(", ");
|
|
25
|
+
|
|
26
|
+
const values: Record<string, string | undefined> = {
|
|
27
|
+
"business.name": name,
|
|
28
|
+
"business.website": siteHost(),
|
|
29
|
+
"business.contact": contact,
|
|
30
|
+
"business.email": email ?? LEGAL_CONTACT_FALLBACK,
|
|
31
|
+
"business.phone": phone ?? LEGAL_CONTACT_FALLBACK,
|
|
32
|
+
"business.address": address || undefined,
|
|
33
|
+
"right_now.year": String(new Date().getFullYear()),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return markdown.replace(/\{\{\s*([\w.]+)\s*\}\}/g, (_match, token: string) => {
|
|
37
|
+
const value = values[token];
|
|
38
|
+
if (value !== undefined) return value;
|
|
39
|
+
throw new Error(`Missing or unsupported legal template token: ${token}`);
|
|
40
|
+
});
|
|
41
|
+
}
|
package/lib/noise.tsx
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** Server-safe duotone grain matching Figma's `noise-duo` effect.
|
|
2
|
+
* User-space filtering keeps grain size independent of the box; optional
|
|
3
|
+
* clips use object-bounding-box fractions for proportional scaling. */
|
|
4
|
+
|
|
5
|
+
import { useId, type ReactNode } from "react";
|
|
6
|
+
|
|
7
|
+
interface NoiseDuoProps {
|
|
8
|
+
/** Speckle size in CSS px. */
|
|
9
|
+
size?: number;
|
|
10
|
+
/** Total coverage from 0..1, split evenly across both inks. */
|
|
11
|
+
density?: number;
|
|
12
|
+
/** Ink colors and alphas. */
|
|
13
|
+
dark?: string;
|
|
14
|
+
darkAlpha?: number;
|
|
15
|
+
light?: string;
|
|
16
|
+
lightAlpha?: number;
|
|
17
|
+
/** Optional clip shapes in objectBoundingBox units (0..1). */
|
|
18
|
+
clip?: ReactNode;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* turbulence cell frequency in the scaled user space — one cell per
|
|
23
|
+
user unit reads as one speckle per `size` CSS px */
|
|
24
|
+
const BASE_FREQUENCY = 0.9;
|
|
25
|
+
|
|
26
|
+
/* discrete threshold: the top `coverage` of the channel range passes —
|
|
27
|
+
a fixed-step table keeps the cut stable across renderers */
|
|
28
|
+
function thresholdTable(coverage: number): string {
|
|
29
|
+
const steps = 24;
|
|
30
|
+
const cut = Math.round(steps * (1 - coverage));
|
|
31
|
+
return Array.from({ length: steps }, (_, i) => (i < cut ? "0" : "1")).join(" ");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function NoiseDuo({
|
|
35
|
+
size = 0.5,
|
|
36
|
+
density = 0.8,
|
|
37
|
+
dark = "#000000",
|
|
38
|
+
darkAlpha = 0.15,
|
|
39
|
+
light = "#ffffff",
|
|
40
|
+
lightAlpha = 0.15,
|
|
41
|
+
clip,
|
|
42
|
+
className,
|
|
43
|
+
}: NoiseDuoProps) {
|
|
44
|
+
const id = useId();
|
|
45
|
+
const filterId = `${id}nd`;
|
|
46
|
+
const clipId = `${id}ndc`;
|
|
47
|
+
const table = thresholdTable(density / 2);
|
|
48
|
+
/* the rect over-sizes by 1/size and the group scales back down, so
|
|
49
|
+
the user-space turbulence cells render at `size` CSS px while the
|
|
50
|
+
painted area stays the full box */
|
|
51
|
+
const overscan = `${100 / size}%`;
|
|
52
|
+
const grain = (
|
|
53
|
+
<g transform={`scale(${size})`}>
|
|
54
|
+
<rect width={overscan} height={overscan} filter={`url(#${filterId})`} />
|
|
55
|
+
</g>
|
|
56
|
+
);
|
|
57
|
+
return (
|
|
58
|
+
<svg className={className} aria-hidden="true" focusable="false">
|
|
59
|
+
<defs>
|
|
60
|
+
<filter
|
|
61
|
+
id={filterId}
|
|
62
|
+
x="0"
|
|
63
|
+
y="0"
|
|
64
|
+
width="100%"
|
|
65
|
+
height="100%"
|
|
66
|
+
primitiveUnits="userSpaceOnUse"
|
|
67
|
+
>
|
|
68
|
+
<feTurbulence
|
|
69
|
+
type="fractalNoise"
|
|
70
|
+
baseFrequency={BASE_FREQUENCY}
|
|
71
|
+
numOctaves={1}
|
|
72
|
+
seed={7}
|
|
73
|
+
stitchTiles="stitch"
|
|
74
|
+
result="field"
|
|
75
|
+
/>
|
|
76
|
+
{/* dark ink: the field's R channel over the threshold */}
|
|
77
|
+
<feColorMatrix
|
|
78
|
+
in="field"
|
|
79
|
+
type="matrix"
|
|
80
|
+
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0"
|
|
81
|
+
result="dark-a"
|
|
82
|
+
/>
|
|
83
|
+
<feComponentTransfer in="dark-a" result="dark-m">
|
|
84
|
+
<feFuncA type="discrete" tableValues={table} />
|
|
85
|
+
</feComponentTransfer>
|
|
86
|
+
<feFlood floodColor={dark} floodOpacity={darkAlpha} result="dark-c" />
|
|
87
|
+
<feComposite in="dark-c" in2="dark-m" operator="in" result="dark" />
|
|
88
|
+
{/* light ink: the G channel — an independent speckle set */}
|
|
89
|
+
<feColorMatrix
|
|
90
|
+
in="field"
|
|
91
|
+
type="matrix"
|
|
92
|
+
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0"
|
|
93
|
+
result="light-a"
|
|
94
|
+
/>
|
|
95
|
+
<feComponentTransfer in="light-a" result="light-m">
|
|
96
|
+
<feFuncA type="discrete" tableValues={table} />
|
|
97
|
+
</feComponentTransfer>
|
|
98
|
+
<feFlood floodColor={light} floodOpacity={lightAlpha} result="light-c" />
|
|
99
|
+
<feComposite in="light-c" in2="light-m" operator="in" result="light" />
|
|
100
|
+
<feMerge>
|
|
101
|
+
<feMergeNode in="dark" />
|
|
102
|
+
<feMergeNode in="light" />
|
|
103
|
+
</feMerge>
|
|
104
|
+
</filter>
|
|
105
|
+
{clip && (
|
|
106
|
+
<clipPath id={clipId} clipPathUnits="objectBoundingBox">
|
|
107
|
+
{clip}
|
|
108
|
+
</clipPath>
|
|
109
|
+
)}
|
|
110
|
+
</defs>
|
|
111
|
+
{clip ? <g clipPath={`url(#${clipId})`}>{grain}</g> : grain}
|
|
112
|
+
</svg>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Component, type ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
export interface RenderBoundaryProps {
|
|
6
|
+
/** Shown when the children crash mid-render. Defaults to nothing. */
|
|
7
|
+
fallback?: ReactNode;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Catches render-time crashes from one section of a document and shows its
|
|
13
|
+
* fallback instead of breaking the whole page. Stored reports are immutable
|
|
14
|
+
* artifacts that may predate the code rendering them; a boundary around each
|
|
15
|
+
* independent section makes a drifted shape degrade that section only.
|
|
16
|
+
*/
|
|
17
|
+
export class RenderBoundary extends Component<RenderBoundaryProps, { failed: boolean }> {
|
|
18
|
+
override state = { failed: false };
|
|
19
|
+
|
|
20
|
+
static getDerivedStateFromError() {
|
|
21
|
+
return { failed: true };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override render() {
|
|
25
|
+
return this.state.failed ? <>{this.props.fallback ?? null}</> : this.props.children;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Shared overlay scroll lock. Fixing the body handles iOS touch scroll;
|
|
2
|
+
* keeping the root scrollbar gutter preserves fixed-chrome coordinates. */
|
|
3
|
+
export function lockScroll(): () => void {
|
|
4
|
+
const savedY = window.scrollY;
|
|
5
|
+
const root = document.documentElement;
|
|
6
|
+
const body = document.body;
|
|
7
|
+
const prev = {
|
|
8
|
+
rootOverflowY: root.style.overflowY,
|
|
9
|
+
position: body.style.position,
|
|
10
|
+
top: body.style.top,
|
|
11
|
+
width: body.style.width,
|
|
12
|
+
};
|
|
13
|
+
root.style.overflowY = "scroll";
|
|
14
|
+
body.style.position = "fixed";
|
|
15
|
+
body.style.top = `-${savedY}px`;
|
|
16
|
+
body.style.width = "100%";
|
|
17
|
+
|
|
18
|
+
return () => {
|
|
19
|
+
root.style.overflowY = prev.rootOverflowY;
|
|
20
|
+
body.style.position = prev.position;
|
|
21
|
+
body.style.top = prev.top;
|
|
22
|
+
body.style.width = prev.width;
|
|
23
|
+
window.scrollTo(0, savedY);
|
|
24
|
+
};
|
|
25
|
+
}
|
package/lib/swipe.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/** One horizontal swipe engine for every strip carousel.
|
|
2
|
+
*
|
|
3
|
+
* The gesture tracks live through a custom property on the track, clamps
|
|
4
|
+
* to the strip's travel, and snaps on release to the nearest slot. Pointer
|
|
5
|
+
* capture starts only after the movement clears the slop so buttons and
|
|
6
|
+
* links inside the strip keep their ordinary clicks; a real swipe swallows
|
|
7
|
+
* the click the browser emits after it. Native image dragging is blocked
|
|
8
|
+
* so a press on a photo still resolves as a swipe. */
|
|
9
|
+
|
|
10
|
+
/* Horizontal movement required before a gesture becomes a swipe. */
|
|
11
|
+
const SWIPE_SLOP = 6;
|
|
12
|
+
|
|
13
|
+
export interface SwipeOptions {
|
|
14
|
+
/** Receives the pointer stream and the capture-phase click. */
|
|
15
|
+
viewport: HTMLElement;
|
|
16
|
+
/** Carries the live offset property and `data-dragging`. */
|
|
17
|
+
track: HTMLElement;
|
|
18
|
+
/** Custom property that receives the live offset (a px length). */
|
|
19
|
+
offsetVar: string;
|
|
20
|
+
/** Runs before the pitch is measured at gesture start. */
|
|
21
|
+
onStart?: () => void;
|
|
22
|
+
/** Slot pitch in px at gesture start; a non-positive pitch ignores the gesture. */
|
|
23
|
+
pitch: () => number;
|
|
24
|
+
/** Clamps the live offset to the strip's travel; default ±one pitch. */
|
|
25
|
+
clamp?: (dx: number, pitch: number) => number;
|
|
26
|
+
/** Runs on every move with the clamped offset. */
|
|
27
|
+
onMove?: (dx: number, pitch: number) => void;
|
|
28
|
+
/** Runs on release with the whole slots travelled (positive moves toward the start). */
|
|
29
|
+
onRelease: (steps: number) => void;
|
|
30
|
+
/** Handles a click that is not a swipe echo (capture phase). */
|
|
31
|
+
onClick?: (e: MouseEvent) => void;
|
|
32
|
+
/** Gate checked at gesture start. */
|
|
33
|
+
enabled?: () => boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function attachSwipe(o: SwipeOptions): () => void {
|
|
37
|
+
const { viewport, track, offsetVar } = o;
|
|
38
|
+
const clamp = o.clamp ?? ((dx, pitch) => Math.max(-pitch, Math.min(pitch, dx)));
|
|
39
|
+
let dragging = false;
|
|
40
|
+
let suppressClick = false;
|
|
41
|
+
let startX = 0;
|
|
42
|
+
let dx = 0;
|
|
43
|
+
let pitch = 1;
|
|
44
|
+
|
|
45
|
+
const onDown = (e: PointerEvent) => {
|
|
46
|
+
if (!e.isPrimary || (o.enabled && !o.enabled())) return;
|
|
47
|
+
o.onStart?.();
|
|
48
|
+
pitch = o.pitch();
|
|
49
|
+
if (!(pitch > 0)) return;
|
|
50
|
+
dragging = true;
|
|
51
|
+
suppressClick = false;
|
|
52
|
+
startX = e.clientX;
|
|
53
|
+
dx = 0;
|
|
54
|
+
track.dataset.dragging = "";
|
|
55
|
+
};
|
|
56
|
+
const onMove = (e: PointerEvent) => {
|
|
57
|
+
if (!dragging) return;
|
|
58
|
+
dx = clamp(e.clientX - startX, pitch);
|
|
59
|
+
track.style.setProperty(offsetVar, `${dx}px`);
|
|
60
|
+
o.onMove?.(dx, pitch);
|
|
61
|
+
if (!suppressClick && Math.abs(e.clientX - startX) > SWIPE_SLOP) {
|
|
62
|
+
suppressClick = true;
|
|
63
|
+
try {
|
|
64
|
+
viewport.setPointerCapture(e.pointerId);
|
|
65
|
+
} catch {
|
|
66
|
+
/* Uncaptured pointers still deliver move/up through the viewport. */
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const onUp = () => {
|
|
71
|
+
if (!dragging) return;
|
|
72
|
+
dragging = false;
|
|
73
|
+
delete track.dataset.dragging;
|
|
74
|
+
o.onRelease(Math.round(dx / pitch));
|
|
75
|
+
track.style.removeProperty(offsetVar);
|
|
76
|
+
};
|
|
77
|
+
const onClickCapture = (e: MouseEvent) => {
|
|
78
|
+
if (suppressClick) {
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
suppressClick = false;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
o.onClick?.(e);
|
|
85
|
+
};
|
|
86
|
+
const onDragStart = (e: DragEvent) => e.preventDefault();
|
|
87
|
+
|
|
88
|
+
viewport.addEventListener("pointerdown", onDown);
|
|
89
|
+
viewport.addEventListener("pointermove", onMove);
|
|
90
|
+
viewport.addEventListener("pointerup", onUp);
|
|
91
|
+
viewport.addEventListener("pointercancel", onUp);
|
|
92
|
+
viewport.addEventListener("click", onClickCapture, true);
|
|
93
|
+
viewport.addEventListener("dragstart", onDragStart);
|
|
94
|
+
return () => {
|
|
95
|
+
viewport.removeEventListener("pointerdown", onDown);
|
|
96
|
+
viewport.removeEventListener("pointermove", onMove);
|
|
97
|
+
viewport.removeEventListener("pointerup", onUp);
|
|
98
|
+
viewport.removeEventListener("pointercancel", onUp);
|
|
99
|
+
viewport.removeEventListener("click", onClickCapture, true);
|
|
100
|
+
viewport.removeEventListener("dragstart", onDragStart);
|
|
101
|
+
delete track.dataset.dragging;
|
|
102
|
+
track.style.removeProperty(offsetVar);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Left/right arrow keys step a strip. */
|
|
107
|
+
export function attachArrowKeys(
|
|
108
|
+
el: HTMLElement,
|
|
109
|
+
step: (delta: 1 | -1) => void,
|
|
110
|
+
enabled = () => true,
|
|
111
|
+
) {
|
|
112
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
113
|
+
if (!enabled()) return;
|
|
114
|
+
if (e.key === "ArrowRight") {
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
step(1);
|
|
117
|
+
} else if (e.key === "ArrowLeft") {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
step(-1);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
el.addEventListener("keydown", onKeyDown);
|
|
123
|
+
return () => el.removeEventListener("keydown", onKeyDown);
|
|
124
|
+
}
|