@keystone-sites/marketing-design-system 1.0.6 → 1.0.8
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/grid/engine.css +3 -4
- package/lib/grader.ts +19 -27
- package/lib/use-grader-search.ts +41 -22
- package/package.json +1 -1
- package/primitives/text.css +7 -5
- package/sections/nav.css +1 -1
- package/site-links.ts +1 -1
- package/tokens/semantic.css +2 -0
package/grid/engine.css
CHANGED
|
@@ -69,10 +69,9 @@
|
|
|
69
69
|
/* The base band interpolates 384→576 and extrapolates below 384. */
|
|
70
70
|
--wA: calc((48px - var(--t)) / 16);
|
|
71
71
|
--wB: calc((var(--t) - 32px) / 16);
|
|
72
|
-
/*
|
|
73
|
-
(
|
|
74
|
-
|
|
75
|
-
--kB: tan(atan2(var(--wB), 1px));
|
|
72
|
+
/* Type multiplies these px weights by its unitless design sizes
|
|
73
|
+
directly (primitives/text.css); no unit-stripping trig, which iOS
|
|
74
|
+
Safari has resolved wrongly. */
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
/* Midpoint gates select the nearest anchor. Compressed slices zoom type
|
package/lib/grader.ts
CHANGED
|
@@ -68,12 +68,9 @@ export interface GraderSuggestion {
|
|
|
68
68
|
website?: string | null;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const EMPTY_GRADER_SEARCH: GraderSearchResponse = { places: [], web: [] };
|
|
71
|
+
/** The two suggestion sources, each its own request so the fast one is
|
|
72
|
+
* never held back by the slow one. */
|
|
73
|
+
export type GraderSearchGroup = "places" | "web";
|
|
77
74
|
|
|
78
75
|
function isSuggestion(value: unknown): value is GraderSuggestion {
|
|
79
76
|
if (!value || typeof value !== "object") return false;
|
|
@@ -81,16 +78,9 @@ function isSuggestion(value: unknown): value is GraderSuggestion {
|
|
|
81
78
|
return typeof r.id === "string" && typeof r.name === "string" && typeof r.address === "string";
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
/** Drop malformed entries from the
|
|
85
|
-
function
|
|
86
|
-
|
|
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;
|
|
81
|
+
/** Drop malformed entries from the API's list. */
|
|
82
|
+
function normalizeSuggestions(body: unknown): GraderSuggestion[] {
|
|
83
|
+
return Array.isArray(body) ? body.filter(isSuggestion) : [];
|
|
94
84
|
}
|
|
95
85
|
|
|
96
86
|
/** The Grader deep link for a chosen business. The hub keys on `placeId`;
|
|
@@ -103,29 +93,31 @@ export function graderScanUrl(business: GraderSuggestion): string {
|
|
|
103
93
|
return `${GRADER_URL}/?${params.toString()}`;
|
|
104
94
|
}
|
|
105
95
|
|
|
106
|
-
function graderSearchApiUrl(query: string, path: string): string {
|
|
107
|
-
return `${GRADER_API_BASE_URL}${path}?q=${encodeURIComponent(query)}`;
|
|
96
|
+
function graderSearchApiUrl(group: GraderSearchGroup, query: string, path: string): string {
|
|
97
|
+
return `${GRADER_API_BASE_URL}${path}/${group}?q=${encodeURIComponent(query)}`;
|
|
108
98
|
}
|
|
109
99
|
|
|
110
|
-
/** Query the search endpoint, walking the configured paths
|
|
111
|
-
* answers; a non-OK response or a network error moves to the
|
|
112
|
-
* exhausting them yields
|
|
113
|
-
* the walk immediately (re-thrown so the caller can ignore stale
|
|
114
|
-
|
|
100
|
+
/** Query one group of the search endpoint, walking the configured paths
|
|
101
|
+
* until one answers; a non-OK response or a network error moves to the
|
|
102
|
+
* next path, exhausting them yields no suggestions. An aborted signal
|
|
103
|
+
* stops the walk immediately (re-thrown so the caller can ignore stale
|
|
104
|
+
* runs). */
|
|
105
|
+
export async function fetchGraderGroup(
|
|
106
|
+
group: GraderSearchGroup,
|
|
115
107
|
query: string,
|
|
116
108
|
signal?: AbortSignal,
|
|
117
|
-
): Promise<
|
|
109
|
+
): Promise<GraderSuggestion[]> {
|
|
118
110
|
for (const path of GRADER_SEARCH_PATHS) {
|
|
119
111
|
try {
|
|
120
112
|
const timeout = AbortSignal.timeout(GRADER_SEARCH_TIMEOUT_MS);
|
|
121
113
|
const combined = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
122
|
-
const resp = await fetch(graderSearchApiUrl(query, path), { signal: combined });
|
|
114
|
+
const resp = await fetch(graderSearchApiUrl(group, query, path), { signal: combined });
|
|
123
115
|
if (!resp.ok) continue;
|
|
124
|
-
return
|
|
116
|
+
return normalizeSuggestions(await resp.json());
|
|
125
117
|
} catch (error) {
|
|
126
118
|
if (signal?.aborted) throw error;
|
|
127
119
|
// timeout or network failure — try the next configured path
|
|
128
120
|
}
|
|
129
121
|
}
|
|
130
|
-
return
|
|
122
|
+
return [];
|
|
131
123
|
}
|
package/lib/use-grader-search.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
/** Grader typeahead state.
|
|
4
|
-
*
|
|
3
|
+
/** Grader typeahead state. Each group is its own request so Google's
|
|
4
|
+
* ~100ms matches show while the web search is still out; debouncing,
|
|
5
|
+
* cancellation, grouped limits, and a small cache prevent stale results
|
|
6
|
+
* and backspace flicker. */
|
|
5
7
|
|
|
6
8
|
import { useEffect, useMemo, useState } from "react";
|
|
7
|
-
import {
|
|
9
|
+
import { fetchGraderGroup, type GraderSearchGroup, type GraderSuggestion } from "./grader";
|
|
8
10
|
|
|
9
11
|
/** Keystroke settle time before a request goes out. */
|
|
10
12
|
const DEBOUNCE_MS = 200;
|
|
11
13
|
/** Rows offered per group. */
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
+
const MAX: Record<GraderSearchGroup, number> = { places: 5, web: 3 };
|
|
15
|
+
const GROUPS: GraderSearchGroup[] = ["places", "web"];
|
|
14
16
|
/** Answers remembered per session (queries are short; this is tiny). */
|
|
15
17
|
const CACHE_SIZE = 50;
|
|
16
18
|
|
|
@@ -34,13 +36,15 @@ export interface GraderSearchState {
|
|
|
34
36
|
resultsFor: string;
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
/** What has answered so far for one query; a group is absent until it does. */
|
|
37
40
|
interface Answer {
|
|
38
|
-
groups: GraderSearchGroups;
|
|
39
41
|
resultsFor: string;
|
|
42
|
+
places?: GraderSuggestion[];
|
|
43
|
+
web?: GraderSuggestion[];
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
const EMPTY_GROUPS: GraderSearchGroups = { places: [], web: [] };
|
|
43
|
-
const EMPTY_ANSWER: Answer = {
|
|
47
|
+
const EMPTY_ANSWER: Answer = { resultsFor: "" };
|
|
44
48
|
|
|
45
49
|
function capped(items: GraderSuggestion[], max: number, seen: Set<string>): GraderSuggestion[] {
|
|
46
50
|
const out: GraderSuggestion[] = [];
|
|
@@ -53,14 +57,18 @@ function capped(items: GraderSuggestion[], max: number, seen: Set<string>): Grad
|
|
|
53
57
|
return out;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
|
-
function group(
|
|
60
|
+
function group(answer: Answer): GraderSearchGroups {
|
|
57
61
|
const seen = new Set<string>();
|
|
58
62
|
return {
|
|
59
|
-
places: capped(
|
|
60
|
-
web: capped(
|
|
63
|
+
places: capped(answer.places ?? [], MAX.places, seen),
|
|
64
|
+
web: capped(answer.web ?? [], MAX.web, seen),
|
|
61
65
|
};
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
function complete(answer: Answer): boolean {
|
|
69
|
+
return GROUPS.every((g) => answer[g] !== undefined);
|
|
70
|
+
}
|
|
71
|
+
|
|
64
72
|
const cache = new Map<string, GraderSearchGroups>();
|
|
65
73
|
|
|
66
74
|
function remember(query: string, groups: GraderSearchGroups) {
|
|
@@ -89,17 +97,18 @@ export function useGraderSearch(query: string, enabled = true): GraderSearchStat
|
|
|
89
97
|
if (!q || cache.has(q)) return;
|
|
90
98
|
const controller = new AbortController();
|
|
91
99
|
const timer = window.setTimeout(() => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
for (const g of GROUPS) {
|
|
101
|
+
fetchGraderGroup(g, q, controller.signal)
|
|
102
|
+
.catch((): GraderSuggestion[] => [])
|
|
103
|
+
.then((items) => {
|
|
104
|
+
if (controller.signal.aborted) return;
|
|
105
|
+
setAnswer((prev) => ({
|
|
106
|
+
...(prev.resultsFor === q ? prev : {}),
|
|
107
|
+
resultsFor: q,
|
|
108
|
+
[g]: items,
|
|
109
|
+
}));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
103
112
|
}, DEBOUNCE_MS);
|
|
104
113
|
return () => {
|
|
105
114
|
window.clearTimeout(timer);
|
|
@@ -107,12 +116,22 @@ export function useGraderSearch(query: string, enabled = true): GraderSearchStat
|
|
|
107
116
|
};
|
|
108
117
|
}, [q]);
|
|
109
118
|
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (answer.resultsFor && complete(answer)) remember(answer.resultsFor, group(answer));
|
|
121
|
+
}, [answer]);
|
|
122
|
+
|
|
110
123
|
return useMemo<GraderSearchState>(() => {
|
|
111
124
|
if (!q) return state("idle", EMPTY_GROUPS, "");
|
|
112
125
|
// A remembered query answers in the same render — no fetch, no flicker.
|
|
113
126
|
const cached = cache.get(q);
|
|
114
127
|
if (cached) return state("ready", cached, q);
|
|
115
|
-
if (answer.resultsFor === q)
|
|
128
|
+
if (answer.resultsFor === q) {
|
|
129
|
+
const groups = group(answer);
|
|
130
|
+
// Ready as soon as there is something to show, or nothing left to wait for.
|
|
131
|
+
if (answer.places !== undefined && (groups.places.length > 0 || complete(answer))) {
|
|
132
|
+
return state("ready", groups, q);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
116
135
|
return state("loading", EMPTY_GROUPS, "");
|
|
117
136
|
}, [q, answer]);
|
|
118
137
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keystone-sites/marketing-design-system",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Keystone's marketing design system: tokens, the tick grid, type, primitives, site chrome, and the landing kit. Source-shipped CSS and TSX for Next.js consumers.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
package/primitives/text.css
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
inherit, so a container may name the ramp for the plain `type` labels
|
|
34
34
|
inside it (`.csi-grid`); an element's own ts- class resets only --fs-rm.
|
|
35
35
|
|
|
36
|
-
--fs/--lh are the fluid
|
|
36
|
+
--fs/--lh are the fluid px results; --fs-band/--lh-band are the
|
|
37
37
|
current band's anchor alone, for a component that scales through its
|
|
38
38
|
own unit and pins `--fs-px: calc(var(--_u) * var(--fs-band))`.
|
|
39
39
|
|
|
@@ -71,10 +71,12 @@
|
|
|
71
71
|
--lh-band: var(--lh-rm);
|
|
72
72
|
--_lh-next: var(--lh-rm-to, var(--lh-band));
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
/* px weights times unitless anchors gives px: the same interpolation
|
|
75
|
+
the grid uses for geometry, with no unit-stripping step. */
|
|
76
|
+
--fs: calc(var(--wA) * var(--fs-band) + var(--wB) * var(--_fs-next));
|
|
77
|
+
--lh: calc(var(--wA) * var(--lh-band) + var(--wB) * var(--_lh-next));
|
|
78
|
+
font-size: var(--fs-px, var(--fs));
|
|
79
|
+
line-height: var(--lh-px, var(--lh));
|
|
78
80
|
}
|
|
79
81
|
@container (--rs) {
|
|
80
82
|
.type:not(.type-fixed) {
|
package/sections/nav.css
CHANGED
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
display: block;
|
|
93
93
|
width: var(--knav-logomark);
|
|
94
94
|
height: var(--knav-logomark);
|
|
95
|
-
background: var(--
|
|
95
|
+
background: var(--knav-mark-ink);
|
|
96
96
|
-webkit-mask: url("/media/brand/ks-logomark.svg") center / contain no-repeat;
|
|
97
97
|
mask: url("/media/brand/ks-logomark.svg") center / contain no-repeat;
|
|
98
98
|
}
|
package/site-links.ts
CHANGED
|
@@ -31,7 +31,7 @@ export const SITE_LINKS = {
|
|
|
31
31
|
terms: "/terms",
|
|
32
32
|
privacy: "/privacy",
|
|
33
33
|
accessibility: "/accessibility",
|
|
34
|
-
login: "https://
|
|
34
|
+
login: "https://go.keystone.app/login",
|
|
35
35
|
spotify: "https://open.spotify.com/show/41MuXEI3TIvCAQW20Ko9cX",
|
|
36
36
|
applePodcasts: "https://podcasts.apple.com/us/podcast/made-locally/id1895736090",
|
|
37
37
|
} as const;
|
package/tokens/semantic.css
CHANGED
|
@@ -138,6 +138,8 @@
|
|
|
138
138
|
--z-sticky: 20;
|
|
139
139
|
--knav-bar-h: 44px;
|
|
140
140
|
--knav-logomark: 18px;
|
|
141
|
+
/* The mark's ink; a product app sets it to its own brand color. */
|
|
142
|
+
--knav-mark-ink: var(--color-text-200);
|
|
141
143
|
--hx-wm-w: 3.9563em;
|
|
142
144
|
--hx-wm-h: 0.8031em;
|
|
143
145
|
--hx-wm-drop: 0.19045;
|