@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.
Files changed (130) hide show
  1. package/AGENTS.md +163 -0
  2. package/README.md +85 -0
  3. package/assets/media/brand/ks-lockup.svg +13 -0
  4. package/assets/media/brand/ks-logomark.svg +4 -0
  5. package/assets/media/brand/ks-wordmark-inline.svg +13 -0
  6. package/assets/media/brand/ks-wordmark.svg +11 -0
  7. package/assets/media/fonts/gt-standard-standard-vf.woff2 +0 -0
  8. package/assets/media/fonts/pp-kyoto-variable-upright-vf.woff2 +0 -0
  9. package/base.css +111 -0
  10. package/css-vars.d.ts +10 -0
  11. package/grid/engine.css +368 -0
  12. package/grid/field-hash.ts +31 -0
  13. package/grid/field.tsx +48 -0
  14. package/grid/gates.cjs +34 -0
  15. package/grid/region.tsx +97 -0
  16. package/icons.tsx +1224 -0
  17. package/index.css +77 -0
  18. package/lib/autoplay-gate.ts +88 -0
  19. package/lib/focus-trap.ts +42 -0
  20. package/lib/grader.ts +131 -0
  21. package/lib/legal-data.ts +1 -0
  22. package/lib/legal.ts +41 -0
  23. package/lib/noise.tsx +114 -0
  24. package/lib/render-boundary.tsx +27 -0
  25. package/lib/scroll-lock.ts +25 -0
  26. package/lib/swipe.ts +124 -0
  27. package/lib/use-active-section.ts +43 -0
  28. package/lib/use-count-up.ts +26 -0
  29. package/lib/use-grader-search.ts +118 -0
  30. package/lib/use-video-carousel.ts +271 -0
  31. package/media.ts +558 -0
  32. package/package.json +201 -0
  33. package/primitives/button-inline.css +52 -0
  34. package/primitives/button-inline.tsx +38 -0
  35. package/primitives/buttons.css +449 -0
  36. package/primitives/buttons.tsx +263 -0
  37. package/primitives/case-study-button.css +71 -0
  38. package/primitives/case-study-button.tsx +28 -0
  39. package/primitives/case-study-card.css +318 -0
  40. package/primitives/case-study-card.tsx +116 -0
  41. package/primitives/closer-row.css +14 -0
  42. package/primitives/closer-row.tsx +22 -0
  43. package/primitives/cta-row.css +41 -0
  44. package/primitives/cta-row.tsx +39 -0
  45. package/primitives/disclosure.css +210 -0
  46. package/primitives/disclosure.tsx +144 -0
  47. package/primitives/faq-question.css +220 -0
  48. package/primitives/faq-question.tsx +55 -0
  49. package/primitives/field.css +225 -0
  50. package/primitives/field.tsx +266 -0
  51. package/primitives/footer-item.css +72 -0
  52. package/primitives/footer-item.tsx +42 -0
  53. package/primitives/grader-menu.tsx +84 -0
  54. package/primitives/grader.css +302 -0
  55. package/primitives/grader.tsx +284 -0
  56. package/primitives/modal.css +151 -0
  57. package/primitives/modal.tsx +90 -0
  58. package/primitives/notice.css +39 -0
  59. package/primitives/notice.tsx +56 -0
  60. package/primitives/persona-card.css +374 -0
  61. package/primitives/persona-card.tsx +74 -0
  62. package/primitives/picture.css +11 -0
  63. package/primitives/picture.tsx +41 -0
  64. package/primitives/plan-card.css +378 -0
  65. package/primitives/plan-card.tsx +91 -0
  66. package/primitives/prose.css +118 -0
  67. package/primitives/prose.tsx +170 -0
  68. package/primitives/ramps.css +84 -0
  69. package/primitives/slider.css +179 -0
  70. package/primitives/slider.tsx +69 -0
  71. package/primitives/slug.css +87 -0
  72. package/primitives/slug.tsx +37 -0
  73. package/primitives/status.css +298 -0
  74. package/primitives/status.tsx +222 -0
  75. package/primitives/strip.css +40 -0
  76. package/primitives/surface.css +78 -0
  77. package/primitives/surface.tsx +95 -0
  78. package/primitives/table.css +226 -0
  79. package/primitives/table.tsx +122 -0
  80. package/primitives/tabs.css +85 -0
  81. package/primitives/tabs.tsx +122 -0
  82. package/primitives/text.css +110 -0
  83. package/primitives/toc.css +65 -0
  84. package/primitives/toc.tsx +42 -0
  85. package/rules/design-system.md +154 -0
  86. package/rules/grid-and-layout.md +166 -0
  87. package/scripts/generate-exports.mjs +61 -0
  88. package/scripts/generate-type-css.mjs +130 -0
  89. package/sections/faq-island.tsx +102 -0
  90. package/sections/faq.css +213 -0
  91. package/sections/faq.tsx +46 -0
  92. package/sections/footer-nav.tsx +95 -0
  93. package/sections/footer-signature.css +183 -0
  94. package/sections/footer-signature.tsx +114 -0
  95. package/sections/footer.css +735 -0
  96. package/sections/footer.tsx +283 -0
  97. package/sections/gallery-overlay.css +213 -0
  98. package/sections/gallery-overlay.tsx +267 -0
  99. package/sections/landing-benefits.css +59 -0
  100. package/sections/landing-benefits.tsx +81 -0
  101. package/sections/landing-closer.css +23 -0
  102. package/sections/landing-closer.tsx +26 -0
  103. package/sections/landing-hero.css +80 -0
  104. package/sections/landing-hero.tsx +69 -0
  105. package/sections/landing-quote.css +19 -0
  106. package/sections/landing-quote.tsx +30 -0
  107. package/sections/landing-sample.ts +66 -0
  108. package/sections/landing.css +45 -0
  109. package/sections/landing.tsx +69 -0
  110. package/sections/load-orchestrator.tsx +43 -0
  111. package/sections/load.css +138 -0
  112. package/sections/nav-desktop.css +530 -0
  113. package/sections/nav-desktop.tsx +155 -0
  114. package/sections/nav-mobile.css +571 -0
  115. package/sections/nav-mobile.tsx +222 -0
  116. package/sections/nav.css +126 -0
  117. package/sections/nav.tsx +394 -0
  118. package/sections/site-chat-data.ts +16 -0
  119. package/sections/site-chat-open.tsx +25 -0
  120. package/sections/site-chat.tsx +67 -0
  121. package/site-links.ts +36 -0
  122. package/site.ts +2 -0
  123. package/themes/inverted.css +139 -0
  124. package/tokens/fonts.css +38 -0
  125. package/tokens/motion.css +125 -0
  126. package/tokens/primitives.css +163 -0
  127. package/tokens/semantic.css +153 -0
  128. package/tokens/type-styles.json +145 -0
  129. package/tokens/type.css +1548 -0
  130. package/widgets.css +78 -0
@@ -0,0 +1,43 @@
1
+ "use client";
2
+
3
+ /** The id of the last section whose top has crossed one-third of the
4
+ * viewport, for sticky tables of contents. Clamps to the first section
5
+ * above the page and the last below it. */
6
+
7
+ import { useLayoutEffect, useState } from "react";
8
+
9
+ const VIEWPORT_LINE_DIVISOR = 3;
10
+ /* Pins the observer boundary to one-third of the viewport. */
11
+ const ROOT_MARGIN = "0px 0px -66.667% 0px";
12
+ const THRESHOLDS = [0, 1];
13
+
14
+ export function useActiveSection(ids: readonly string[]): string {
15
+ const [active, setActive] = useState(ids[0] ?? "");
16
+
17
+ useLayoutEffect(() => {
18
+ const sections = ids
19
+ .map((id) => document.getElementById(id))
20
+ .filter((el): el is HTMLElement => el !== null);
21
+ if (sections.length === 0) return;
22
+
23
+ const compute = () => {
24
+ const line = window.innerHeight / VIEWPORT_LINE_DIVISOR;
25
+ let current = sections[0].id;
26
+ for (const section of sections) {
27
+ if (section.getBoundingClientRect().top <= line) current = section.id;
28
+ }
29
+ setActive(current);
30
+ };
31
+ const io = new IntersectionObserver(compute, {
32
+ rootMargin: ROOT_MARGIN,
33
+ threshold: THRESHOLDS,
34
+ });
35
+ sections.forEach((section) => io.observe(section));
36
+ compute();
37
+ return () => io.disconnect();
38
+ // A new id list is a new table of contents.
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, [ids.join("\u0000")]);
41
+
42
+ return active;
43
+ }
@@ -0,0 +1,26 @@
1
+ "use client";
2
+
3
+ import { useEffect, useRef, useState } from "react";
4
+
5
+ /** Animates a number from 0 to `target` with a cubic ease-out. */
6
+ export function useCountUp(target: number, durationMs = 1400, start = true) {
7
+ const [value, setValue] = useState(0);
8
+ const raf = useRef<number | null>(null);
9
+
10
+ useEffect(() => {
11
+ if (!start) return;
12
+ const begin = performance.now();
13
+ const tick = (now: number) => {
14
+ const t = Math.min(1, (now - begin) / durationMs);
15
+ const eased = 1 - Math.pow(1 - t, 3);
16
+ setValue(target * eased);
17
+ if (t < 1) raf.current = requestAnimationFrame(tick);
18
+ };
19
+ raf.current = requestAnimationFrame(tick);
20
+ return () => {
21
+ if (raf.current) cancelAnimationFrame(raf.current);
22
+ };
23
+ }, [target, durationMs, start]);
24
+
25
+ return value;
26
+ }
@@ -0,0 +1,118 @@
1
+ "use client";
2
+
3
+ /** Grader typeahead state. Debouncing, cancellation, grouped limits, and
4
+ * a small cache prevent stale results and backspace flicker. */
5
+
6
+ import { useEffect, useMemo, useState } from "react";
7
+ import { fetchGraderSuggestions, type GraderSearchResponse, type GraderSuggestion } from "./grader";
8
+
9
+ /** Keystroke settle time before a request goes out. */
10
+ const DEBOUNCE_MS = 200;
11
+ /** Rows offered per group. */
12
+ const MAX_PLACES = 5;
13
+ const MAX_WEB = 3;
14
+ /** Answers remembered per session (queries are short; this is tiny). */
15
+ const CACHE_SIZE = 50;
16
+
17
+ type GraderSearchStatus = "idle" | "loading" | "ready";
18
+
19
+ export interface GraderSearchGroups {
20
+ /** Google Places matches (`id` is the place_id). */
21
+ places: GraderSuggestion[];
22
+ /** Independent websites (`id` is `web:{domain}`). */
23
+ web: GraderSuggestion[];
24
+ }
25
+
26
+ export interface GraderSearchState {
27
+ /** `idle` while the query is blank. */
28
+ status: GraderSearchStatus;
29
+ /** The two groups, deduplicated and capped — what the menu renders. */
30
+ groups: GraderSearchGroups;
31
+ /** The groups flattened in display order — what the keyboard walks. */
32
+ results: GraderSuggestion[];
33
+ /** The query `groups` answers ("" until the first answer). */
34
+ resultsFor: string;
35
+ }
36
+
37
+ interface Answer {
38
+ groups: GraderSearchGroups;
39
+ resultsFor: string;
40
+ }
41
+
42
+ const EMPTY_GROUPS: GraderSearchGroups = { places: [], web: [] };
43
+ const EMPTY_ANSWER: Answer = { groups: EMPTY_GROUPS, resultsFor: "" };
44
+
45
+ function capped(items: GraderSuggestion[], max: number, seen: Set<string>): GraderSuggestion[] {
46
+ const out: GraderSuggestion[] = [];
47
+ for (const item of items) {
48
+ if (out.length >= max) break;
49
+ if (seen.has(item.id)) continue;
50
+ seen.add(item.id);
51
+ out.push(item);
52
+ }
53
+ return out;
54
+ }
55
+
56
+ function group(response: GraderSearchResponse): GraderSearchGroups {
57
+ const seen = new Set<string>();
58
+ return {
59
+ places: capped(response.places, MAX_PLACES, seen),
60
+ web: capped(response.web, MAX_WEB, seen),
61
+ };
62
+ }
63
+
64
+ const cache = new Map<string, GraderSearchGroups>();
65
+
66
+ function remember(query: string, groups: GraderSearchGroups) {
67
+ if (cache.size >= CACHE_SIZE) {
68
+ const oldest = cache.keys().next().value;
69
+ if (oldest !== undefined) cache.delete(oldest);
70
+ }
71
+ cache.set(query, groups);
72
+ }
73
+
74
+ function state(
75
+ status: GraderSearchStatus,
76
+ groups: GraderSearchGroups,
77
+ resultsFor: string,
78
+ ): GraderSearchState {
79
+ return { status, groups, results: [...groups.places, ...groups.web], resultsFor };
80
+ }
81
+
82
+ /** `enabled` false parks the search (no fetch, `idle`) — the island uses
83
+ * it once a business is chosen, so the chosen name is never looked up. */
84
+ export function useGraderSearch(query: string, enabled = true): GraderSearchState {
85
+ const q = enabled ? query.trim() : "";
86
+ const [answer, setAnswer] = useState<Answer>(EMPTY_ANSWER);
87
+
88
+ useEffect(() => {
89
+ if (!q || cache.has(q)) return;
90
+ const controller = new AbortController();
91
+ const timer = window.setTimeout(() => {
92
+ fetchGraderSuggestions(q, controller.signal)
93
+ .then((response) => {
94
+ if (controller.signal.aborted) return;
95
+ const groups = group(response);
96
+ remember(q, groups);
97
+ setAnswer({ groups, resultsFor: q });
98
+ })
99
+ .catch(() => {
100
+ if (controller.signal.aborted) return;
101
+ setAnswer({ groups: EMPTY_GROUPS, resultsFor: q });
102
+ });
103
+ }, DEBOUNCE_MS);
104
+ return () => {
105
+ window.clearTimeout(timer);
106
+ controller.abort();
107
+ };
108
+ }, [q]);
109
+
110
+ return useMemo<GraderSearchState>(() => {
111
+ if (!q) return state("idle", EMPTY_GROUPS, "");
112
+ // A remembered query answers in the same render — no fetch, no flicker.
113
+ const cached = cache.get(q);
114
+ if (cached) return state("ready", cached, q);
115
+ if (answer.resultsFor === q) return state("ready", answer.groups, q);
116
+ return state("loading", EMPTY_GROUPS, "");
117
+ }, [q, answer]);
118
+ }
@@ -0,0 +1,271 @@
1
+ "use client";
2
+
3
+ import { useEffect, useRef } from "react";
4
+ import { attachAutoplayGate } from "./autoplay-gate";
5
+
6
+ const PLAY_RETRIES = 3;
7
+ const PLAY_RETRY_MS = 250;
8
+
9
+ interface UseVideoCarouselResult {
10
+ rootRef: React.RefObject<HTMLDivElement | null>;
11
+ videoRefs: React.MutableRefObject<(HTMLVideoElement | null)[]>;
12
+ }
13
+
14
+ export function useVideoCarousel(videoCount: number): UseVideoCarouselResult {
15
+ const rootRef = useRef<HTMLDivElement>(null);
16
+ const videoRefs = useRef<(HTMLVideoElement | null)[]>([]);
17
+
18
+ useEffect(() => {
19
+ const root = rootRef.current;
20
+ const videos = videoRefs.current.slice(0, videoCount);
21
+ if (!root || videos.length !== videoCount || videos.some((video) => video === null)) return;
22
+
23
+ const media = videos as HTMLVideoElement[];
24
+ const retryWaiters = new Map<number, () => void>();
25
+ const failed = new Set<number>();
26
+ const unlocked = new Set<number>();
27
+
28
+ let activeIndex = 0;
29
+ let operation = 0;
30
+ let starting = false;
31
+ let transitioning = false;
32
+ let pendingAdvance = false;
33
+ let cancelled = false;
34
+ let settleCrossfade: (() => void) | null = null;
35
+ let sourceTier = getComputedStyle(root).getPropertyValue("--coh-video-tier").trim();
36
+
37
+ /* The gate attaches below, once the handlers it calls exist. */
38
+ let gateOpen = () => false;
39
+ const canRun = () => !cancelled && gateOpen();
40
+
41
+ const waitToRetry = () =>
42
+ new Promise<void>((resolve) => {
43
+ const timer = window.setTimeout(() => {
44
+ retryWaiters.delete(timer);
45
+ resolve();
46
+ }, PLAY_RETRY_MS);
47
+ retryWaiters.set(timer, () => {
48
+ window.clearTimeout(timer);
49
+ resolve();
50
+ });
51
+ });
52
+
53
+ const playWithRetry = async (video: HTMLVideoElement) => {
54
+ for (let attempt = 0; attempt <= PLAY_RETRIES; attempt += 1) {
55
+ if (!canRun()) return false;
56
+ try {
57
+ await video.play();
58
+ return true;
59
+ } catch {
60
+ if (attempt === PLAY_RETRIES || video.error) return false;
61
+ await waitToRetry();
62
+ }
63
+ }
64
+ return false;
65
+ };
66
+
67
+ const unlock = (index: number) => {
68
+ if (unlocked.has(index)) return;
69
+ unlocked.add(index);
70
+ media[index].load();
71
+ media[index].preload = "auto";
72
+ };
73
+
74
+ const nextUsableIndex = (from: number) => {
75
+ for (let offset = 1; offset <= videoCount; offset += 1) {
76
+ const index = (from + offset) % videoCount;
77
+ if (!failed.has(index)) return index;
78
+ }
79
+ return null;
80
+ };
81
+
82
+ const unlockNext = () => {
83
+ const next = nextUsableIndex(activeIndex);
84
+ if (next !== null && next !== activeIndex) unlock(next);
85
+ };
86
+
87
+ const showPoster = () => {
88
+ media.forEach((video) => {
89
+ delete video.dataset.visible;
90
+ });
91
+ };
92
+
93
+ const resetVideo = (video: HTMLVideoElement) => {
94
+ video.pause();
95
+ if (video.readyState > HTMLMediaElement.HAVE_NOTHING) video.currentTime = 0;
96
+ };
97
+
98
+ const pauseAll = () => {
99
+ operation += 1;
100
+ starting = false;
101
+ if (settleCrossfade) settleCrossfade();
102
+ else transitioning = false;
103
+ media.forEach((video) => video.pause());
104
+ };
105
+
106
+ const crossfade = (outgoing: HTMLVideoElement, incoming: HTMLVideoElement) => {
107
+ transitioning = true;
108
+ root.dataset.crossfading = "";
109
+
110
+ const settle = () => {
111
+ if (settleCrossfade !== settle) return;
112
+ outgoing.removeEventListener("transitionend", onTransitionEnd);
113
+ delete root.dataset.crossfading;
114
+ settleCrossfade = null;
115
+ transitioning = false;
116
+ resetVideo(outgoing);
117
+ };
118
+ const onTransitionEnd = (event: TransitionEvent) => {
119
+ if (event.propertyName === "opacity") settle();
120
+ };
121
+
122
+ settleCrossfade = settle;
123
+ outgoing.addEventListener("transitionend", onTransitionEnd);
124
+ void outgoing.offsetWidth;
125
+ incoming.dataset.visible = "";
126
+ delete outgoing.dataset.visible;
127
+ };
128
+
129
+ const startActive = async () => {
130
+ if (!canRun() || starting || transitioning) return;
131
+ if (pendingAdvance) {
132
+ void advance();
133
+ return;
134
+ }
135
+
136
+ starting = true;
137
+ const run = ++operation;
138
+ const active = media[activeIndex];
139
+ unlock(activeIndex);
140
+ const didPlay = await playWithRetry(active);
141
+
142
+ if (cancelled || run !== operation) {
143
+ active.pause();
144
+ return;
145
+ }
146
+ starting = false;
147
+
148
+ if (!didPlay) {
149
+ failed.add(activeIndex);
150
+ pendingAdvance = true;
151
+ void advance();
152
+ return;
153
+ }
154
+
155
+ active.dataset.visible = "";
156
+ unlockNext();
157
+ };
158
+
159
+ async function advance() {
160
+ if (!canRun() || transitioning) return;
161
+
162
+ pendingAdvance = false;
163
+ transitioning = true;
164
+ const run = ++operation;
165
+ const outgoingIndex = activeIndex;
166
+ const outgoing = media[outgoingIndex];
167
+ let incomingIndex = nextUsableIndex(outgoingIndex);
168
+
169
+ while (incomingIndex !== null && incomingIndex !== outgoingIndex) {
170
+ const incoming = media[incomingIndex];
171
+ unlock(incomingIndex);
172
+ const didPlay = await playWithRetry(incoming);
173
+
174
+ if (cancelled || run !== operation) {
175
+ incoming.pause();
176
+ if (!cancelled) transitioning = false;
177
+ return;
178
+ }
179
+ if (didPlay) {
180
+ activeIndex = incomingIndex;
181
+ unlockNext();
182
+ crossfade(outgoing, incoming);
183
+ return;
184
+ }
185
+
186
+ failed.add(incomingIndex);
187
+ incomingIndex = nextUsableIndex(incomingIndex);
188
+ }
189
+
190
+ transitioning = false;
191
+ showPoster();
192
+ resetVideo(outgoing);
193
+ }
194
+
195
+ const resume = () => {
196
+ if (canRun()) void startActive();
197
+ };
198
+ const onMotionChange = () => {
199
+ pauseAll();
200
+ activeIndex = 0;
201
+ pendingAdvance = false;
202
+ media.forEach(resetVideo);
203
+ showPoster();
204
+ };
205
+ const onTierChange = () => {
206
+ const nextTier = getComputedStyle(root).getPropertyValue("--coh-video-tier").trim();
207
+ if (nextTier === sourceTier) return;
208
+
209
+ sourceTier = nextTier;
210
+ pauseAll();
211
+ activeIndex = 0;
212
+ pendingAdvance = false;
213
+ failed.clear();
214
+ unlocked.clear();
215
+ showPoster();
216
+ media.forEach((video) => {
217
+ video.preload = "none";
218
+ });
219
+ resume();
220
+ };
221
+
222
+ const endedHandlers = media.map((_, index) => {
223
+ const handler = () => {
224
+ if (index !== activeIndex) return;
225
+ pendingAdvance = true;
226
+ if (canRun()) void advance();
227
+ };
228
+ media[index].addEventListener("ended", handler);
229
+ return handler;
230
+ });
231
+ const errorHandlers = media.map((_, index) => {
232
+ const handler = () => {
233
+ failed.add(index);
234
+ if (index === activeIndex && !starting && !transitioning) {
235
+ pendingAdvance = true;
236
+ if (canRun()) void advance();
237
+ }
238
+ };
239
+ media[index].addEventListener("error", handler);
240
+ return handler;
241
+ });
242
+
243
+ media.forEach((video) => {
244
+ video.preload = "none";
245
+ });
246
+
247
+ const gate = attachAutoplayGate(root, {
248
+ onResume: resume,
249
+ onPause: pauseAll,
250
+ onMotionChange,
251
+ onResize: onTierChange,
252
+ });
253
+ gateOpen = gate.canRun;
254
+
255
+ return () => {
256
+ cancelled = true;
257
+ operation += 1;
258
+ settleCrossfade?.();
259
+ gate.detach();
260
+ retryWaiters.forEach((cancelWait) => cancelWait());
261
+ retryWaiters.clear();
262
+ media.forEach((video, index) => {
263
+ video.removeEventListener("ended", endedHandlers[index]);
264
+ video.removeEventListener("error", errorHandlers[index]);
265
+ video.pause();
266
+ });
267
+ };
268
+ }, [videoCount]);
269
+
270
+ return { rootRef, videoRefs };
271
+ }