@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,368 @@
1
+ /* Container-query grid engine. Bands and interpolation weights read the
2
+ same page-container width. `--t` is fluid structural geometry; `--c`
3
+ is fixed material geometry. Literal 1px values are lattice hairlines.
4
+
5
+ Bands. Five anchors where a Figma frame exists: rm 384 · rs 576 · rt 768 ·
6
+ rd1 960 · rd2 1344 (tick 32 · 48 · 64 · 80 · 112). Gates open at the
7
+ midpoints and are written by band name: `@container (--rs)`, `(--rt)`,
8
+ `(--rd1)`, `(--rd2)` (widths live once in grid/gates.cjs), always on
9
+ `.site-root`, never `@media`. Base CSS is the 384 design; each gate
10
+ overrides upward. Above 1344 the tick
11
+ caps and the 1344 design renders exact; gutters paint the side fields.
12
+ JS that needs the band measures the container, never `matchMedia`.
13
+ Light mode only.
14
+
15
+ Every dimension is one of three kinds:
16
+ - structure (columns, section heights, exposure regions, footprints)
17
+ is written in `--t` and is fluid by construction;
18
+ - type and spacing come from tokens;
19
+ - material (buttons, icons, marks, control inners) is fixed px per
20
+ size variant and never band-aware; the section picks the variant.
21
+ A px value that secretly encodes structure breaks fit between anchors.
22
+
23
+ Laws:
24
+ - Flow frames. A section or text block declares its designed rows as
25
+ `min-height: calc(var(--t) * k)`, never `height`; only tick blocks
26
+ (k·t media frames, controls) keep `height`. Blocks stack in normal
27
+ flow with `margin-top` offsets; a bottom-anchored block is
28
+ `margin-top: auto`. Text wraps inside `max-width`, never `width`.
29
+ A gap derived by subtraction floors with `max()` at a spacing token.
30
+ - Line-inclusive boxes. A bordered box whose edge sits on the lattice
31
+ is `k·t + 1px` so its border lands on the line's pixel; `k·t` exactly
32
+ doubles the hairline.
33
+ - Content clears the lattice: flowed content never touches a tick line
34
+ and keeps half a tick before the next block; when copy needs room the
35
+ frame grows and the painted lattice rides with it (`gy` anchors to the
36
+ section top, `gyb` to its bottom, both to stretch).
37
+ - Absolute positioning only for media fills, the exposure vocabulary
38
+ (`--gx/--gy/--gyb`), overlay chrome, and true escapes from flow
39
+ (viewport-fixed controls). Ordinary content is grid or flex order.
40
+ - Lattice paint per section band is one of three states, declared in a
41
+ comment above the region map: unpainted, bookend (paint stops one
42
+ full tick before photography and resumes one tick after), or seated
43
+ (cells are the grid). A line painted through off-grid media is a defect.
44
+ - Nothing overflows at 384; touch targets are 44px; no hover-only states.
45
+
46
+ `npm run test:visual` shoots every route at every anchor and gate. */
47
+
48
+ /* The container reads content width so anchors stay pixel-exact with scrollbars. */
49
+ .site-root {
50
+ container-type: inline-size;
51
+ }
52
+
53
+ /* ---- tick, cell, line, and per-band interpolation weights ---- */
54
+
55
+ .page {
56
+ position: relative;
57
+ /* Keeps the negative-z side field above the page background. */
58
+ isolation: isolate;
59
+ /* The tick caps at 112px so wide layouts preserve the 1344 anchor. */
60
+ --t: min(calc(100cqw / 12), 112px);
61
+ --c: var(--space-xl);
62
+ --line: var(--color-border-000);
63
+
64
+ /* Whole-pixel centering prevents fuzzy lattice lines at 1× DPR. */
65
+ --page-x: max(0px, round(down, calc((100cqw - 1344px) / 2), 1px));
66
+ width: calc(12 * var(--t));
67
+ margin-left: var(--page-x);
68
+
69
+ /* The base band interpolates 384→576 and extrapolates below 384. */
70
+ --wA: calc((48px - var(--t)) / 16);
71
+ --wB: calc((var(--t) - 32px) / 16);
72
+ /* The same weights as plain numbers, for unitless design values
73
+ (type sizes). tan(atan2()) strips the px. */
74
+ --kA: tan(atan2(var(--wA), 1px));
75
+ --kB: tan(atan2(var(--wB), 1px));
76
+ }
77
+
78
+ /* Midpoint gates select the nearest anchor. Compressed slices zoom type
79
+ and containers together so wraps and clearances remain stable. */
80
+
81
+ @container (--rs) {
82
+ .page {
83
+ /* compressed rs: the 576 design zooming down */
84
+ --wA: calc(var(--t) / 48);
85
+ --wB: 0px;
86
+ }
87
+ }
88
+ @container (min-width: 576px) {
89
+ .page {
90
+ --wA: calc((64px - var(--t)) / 16);
91
+ --wB: calc((var(--t) - 48px) / 16);
92
+ }
93
+ }
94
+
95
+ @container (--rt) {
96
+ .page {
97
+ /* compressed rt: the 768 design zooming down */
98
+ --wA: calc(var(--t) / 64);
99
+ --wB: 0px;
100
+ }
101
+ }
102
+ @container (min-width: 768px) {
103
+ .page {
104
+ --wA: calc((80px - var(--t)) / 16);
105
+ --wB: calc((var(--t) - 64px) / 16);
106
+ }
107
+ }
108
+
109
+ @container (--rd1) {
110
+ .page {
111
+ /* compressed rd1: the 960 design zooming down */
112
+ --wA: calc(var(--t) / 80);
113
+ --wB: 0px;
114
+ }
115
+ }
116
+ @container (min-width: 960px) {
117
+ .page {
118
+ --wA: calc((112px - var(--t)) / 32);
119
+ --wB: calc((var(--t) - 80px) / 32);
120
+ }
121
+ }
122
+
123
+ @container (--rd2) {
124
+ .page {
125
+ /* One rule covers the compressed slice, anchor, and capped wide range. */
126
+ --wA: 0px;
127
+ --wB: calc(var(--t) / 112);
128
+ }
129
+ }
130
+
131
+ /* ---- page skeleton ---- */
132
+
133
+ /* isolation is load-bearing: it gives each section its own stacking
134
+ context so the overlay can sit at z-index -1 inside the section —
135
+ above the page background, below all flow content. */
136
+ .sec {
137
+ position: relative;
138
+ isolation: isolate;
139
+ display: flex;
140
+ flex-direction: column;
141
+ align-items: flex-start;
142
+ }
143
+
144
+ /* Flow budget: a block that owns its designed rows (`--budget`, a
145
+ length in ticks) and grows past them only when its content does. The
146
+ trailing half tick keeps overgrown content clear of the next block;
147
+ inside the budget it is slack. Sections stack flow-budget blocks and
148
+ tick blocks (fixed `k·t` media frames) in normal flow, so an anchor
149
+ renders the designed rows exactly and a narrower or taller-wrapping
150
+ render pushes later blocks down instead of colliding. */
151
+ .flow-budget {
152
+ position: relative;
153
+ box-sizing: border-box;
154
+ min-height: var(--budget);
155
+ padding-bottom: calc(var(--t) / 2);
156
+ }
157
+
158
+ /* ---- selective exposure overlay ---- */
159
+
160
+ .gx {
161
+ position: absolute;
162
+ inset: 0;
163
+ z-index: -1;
164
+ pointer-events: none;
165
+ }
166
+
167
+ /* Exposure region: outer rectangle drawn by its own border, sized
168
+ line-inclusively (k·t + 1px) so the far border lands on the same pixel
169
+ as the next lattice line. Interior lines are real 1px children at
170
+ k·t − 1px offsets — same pixel geometry as the border (children measure
171
+ from the padding box, inside the 1px border). */
172
+ .grid-region {
173
+ position: absolute;
174
+ border: 1px solid var(--line);
175
+ left: calc(var(--t) * var(--gx));
176
+ top: calc(var(--t) * var(--gy));
177
+ width: calc(var(--t) * var(--gw) + 1px);
178
+ height: calc(var(--t) * var(--gh) + 1px);
179
+ }
180
+ .grid-region i {
181
+ position: absolute;
182
+ background: var(--line);
183
+ }
184
+ .grid-region i.v {
185
+ top: 0;
186
+ bottom: 0;
187
+ width: 1px;
188
+ left: calc(var(--t) * var(--n) - 1px);
189
+ }
190
+ .grid-region i.h {
191
+ left: 0;
192
+ right: 0;
193
+ height: 1px;
194
+ top: calc(var(--t) * var(--n) - 1px);
195
+ }
196
+
197
+ /* Bottom-anchored region: `--gyb` rows count up from the section's
198
+ bottom edge, minus the line-inclusive pixel, so the exposure follows a
199
+ flow section that grows with its copy. */
200
+ .grid-region.gb {
201
+ top: auto;
202
+ bottom: calc(var(--t) * var(--gyb) - 1px);
203
+ }
204
+ /* Stretched region: both edges set, height follows the section, and
205
+ interior rows past the grown height are clipped. */
206
+ .grid-region.gs {
207
+ bottom: calc(var(--t) * var(--gyb) - 1px);
208
+ height: auto;
209
+ overflow: hidden;
210
+ }
211
+
212
+ /* Ornament shapes: filled squares use bg/200, circles add radius, and
213
+ outlined circles omit the fill. */
214
+ .f-cell {
215
+ display: block;
216
+ width: 100%;
217
+ height: 100%;
218
+ box-sizing: border-box;
219
+ border: 1px solid var(--line);
220
+ }
221
+ .f-cell.fill {
222
+ background: var(--color-bg-200);
223
+ }
224
+ .f-cell.round {
225
+ border-radius: var(--radius-full);
226
+ }
227
+
228
+ /* Ornament cell: paints between lattice and content (z-index 0 inside the
229
+ isolated section), never intercepts the pointer. */
230
+ .decor {
231
+ position: absolute;
232
+ z-index: 0;
233
+ pointer-events: none;
234
+ display: grid;
235
+ place-items: center;
236
+ left: calc(var(--t) * var(--gx));
237
+ top: calc(var(--t) * var(--gy));
238
+ width: calc(var(--t) + 1px);
239
+ height: calc(var(--t) + 1px);
240
+ }
241
+ .decor.gb {
242
+ top: auto;
243
+ bottom: calc(var(--t) * var(--gyb) - 1px);
244
+ }
245
+
246
+ /* ---- wide-viewport side fields ---- */
247
+
248
+ /* The field spans wide gutters behind sections and clips partial outer
249
+ columns. Dedicated classes keep it outside region animations. */
250
+ .gfield {
251
+ position: absolute;
252
+ top: 0;
253
+ bottom: 0;
254
+ left: calc(0px - var(--page-x));
255
+ width: 100cqw;
256
+ z-index: -1;
257
+ pointer-events: none;
258
+ overflow: clip;
259
+ display: none;
260
+ }
261
+ @container (min-width: 1345px) {
262
+ .gfield {
263
+ display: block;
264
+ }
265
+ }
266
+
267
+ /* Strips stretch with the page; inner borders share the page edge pixels. */
268
+ .gf-strip {
269
+ position: absolute;
270
+ top: 0;
271
+ bottom: 0;
272
+ box-sizing: border-box;
273
+ width: calc(12 * var(--t) + 1px);
274
+ border: 1px solid var(--line);
275
+ }
276
+ .gf-strip.gf-w {
277
+ right: calc(100% - var(--page-x) - 1px);
278
+ }
279
+ .gf-strip.gf-e {
280
+ left: calc(var(--page-x) + 12 * var(--t));
281
+ }
282
+ .gf-strip i {
283
+ position: absolute;
284
+ background: var(--line);
285
+ }
286
+ .gf-strip i.v {
287
+ top: 0;
288
+ bottom: 0;
289
+ width: 1px;
290
+ left: calc(var(--t) * var(--n) - 1px);
291
+ }
292
+ .gf-strip i.h {
293
+ left: 0;
294
+ right: 0;
295
+ height: 1px;
296
+ top: calc(var(--t) * var(--n) - 1px);
297
+ }
298
+
299
+ /* A populated field cell: the .decor geometry, hosting the standing
300
+ .f-cell ornament shapes — its own class so no choreography or audit
301
+ selector ever collects it. */
302
+ .gf-cell {
303
+ position: absolute;
304
+ pointer-events: none;
305
+ display: grid;
306
+ place-items: center;
307
+ left: calc(var(--t) * var(--gx));
308
+ top: calc(var(--t) * var(--gy));
309
+ width: calc(var(--t) + 1px);
310
+ height: calc(var(--t) + 1px);
311
+ }
312
+ .decor.gb {
313
+ top: auto;
314
+ bottom: calc(var(--t) * var(--gyb) - 1px);
315
+ }
316
+
317
+ /* ---- band gating: rm (base) · rs · rt · rd1 · rd2 ---- */
318
+ /* Exactly one band class is visible at any width. */
319
+
320
+ .rs,
321
+ .rt,
322
+ .rd1,
323
+ .rd2 {
324
+ display: none;
325
+ }
326
+ @container (--rs) {
327
+ .rm { display: none; }
328
+ .rs { display: block; }
329
+ }
330
+ @container (--rt) {
331
+ .rs { display: none; }
332
+ .rt { display: block; }
333
+ }
334
+ @container (--rd1) {
335
+ .rt { display: none; }
336
+ .rd1 { display: block; }
337
+ }
338
+ @container (--rd2) {
339
+ .rd1 { display: none; }
340
+ .rd2 { display: block; }
341
+ }
342
+
343
+ /* Compound gating for .decor: the .decor
344
+ display:grid above outranks the generic band gating by order, so decors
345
+ carry their own. Any absolutely-positioned vocabulary added after the
346
+ generic gating rules needs the same treatment. */
347
+ .decor.rs,
348
+ .decor.rt,
349
+ .decor.rd1,
350
+ .decor.rd2 {
351
+ display: none;
352
+ }
353
+ @container (--rs) {
354
+ .decor.rm { display: none; }
355
+ .decor.rs { display: grid; }
356
+ }
357
+ @container (--rt) {
358
+ .decor.rs { display: none; }
359
+ .decor.rt { display: grid; }
360
+ }
361
+ @container (--rd1) {
362
+ .decor.rt { display: none; }
363
+ .decor.rd1 { display: grid; }
364
+ }
365
+ @container (--rd2) {
366
+ .decor.rd1 { display: none; }
367
+ .decor.rd2 { display: grid; }
368
+ }
@@ -0,0 +1,31 @@
1
+ /** A coordinate-only hash keeps side-field ornaments deterministic across
2
+ * server renders and viewport growth. Density is 4%; shapes follow a
3
+ * 2:1:1 outlined-circle, filled-square, filled-circle mix. */
4
+
5
+ /** Rendered columns per strip: covers gutters up to 12 whole cells a
6
+ * side (a 4032px container at the 112px capped tick); wider viewports
7
+ * show paper past the strip. */
8
+ export const FIELD_COLS = 12;
9
+
10
+ /** Rendered rows per strip: covers the tallest rd2 page (the 74t case
11
+ * study) plus drawer growth, clipped to the live page height. A page
12
+ * outgrowing this fails the devtools' field-coverage check loudly. */
13
+ export const FIELD_ROWS = 96;
14
+
15
+ /** 1 = west strip · 2 = east strip. */
16
+ export type FieldSide = 1 | 2;
17
+
18
+ /** The `.f-cell` class list for the ornament at (side, col, row), or
19
+ * null for the (common) empty cell. `col` counts outward from the page
20
+ * edge (1 = adjacent); `row` is the zero-based global page row. */
21
+ export function fieldCellClass(side: FieldSide, col: number, row: number): string | null {
22
+ let h =
23
+ (Math.imul(col, 0x9e3779b1) ^ Math.imul(row, 0x85ebca6b) ^ Math.imul(side, 0xc2b2ae35)) >>> 0;
24
+ h = Math.imul(h ^ (h >>> 15), 0x27d4eb2f) >>> 0;
25
+ h = (h ^ (h >>> 15)) >>> 0;
26
+ const v = h % 1000;
27
+ if (v >= 40) return null;
28
+ const s = v % 4;
29
+ // 0,1 → outlined circle · 2 → filled square · 3 → filled circle
30
+ return s === 2 ? "f-cell fill" : s === 3 ? "f-cell fill round" : "f-cell round";
31
+ }
package/grid/field.tsx ADDED
@@ -0,0 +1,48 @@
1
+ /** Wide viewports paint deterministic lattice fields in the side gutters.
2
+ * Their dedicated classes keep page-wide region animations from catching
3
+ * them. Real 1px lines remain in global page phase as the page grows. */
4
+
5
+ import { FIELD_COLS, FIELD_ROWS, fieldCellClass, type FieldSide } from "./field-hash";
6
+
7
+ function Strip({ side }: { side: FieldSide }) {
8
+ const lines = [];
9
+ for (let n = 1; n < FIELD_COLS; n++) {
10
+ lines.push(<i key={`v${n}`} className="v" style={{ "--n": n }} />);
11
+ }
12
+ for (let n = 1; n < FIELD_ROWS; n++) {
13
+ lines.push(<i key={`h${n}`} className="h" style={{ "--n": n }} />);
14
+ }
15
+
16
+ const cells = [];
17
+ for (let col = 1; col <= FIELD_COLS; col++) {
18
+ for (let row = 0; row < FIELD_ROWS; row++) {
19
+ const shape = fieldCellClass(side, col, row);
20
+ if (!shape) continue;
21
+ // strip-local column: outward col 1 is the cell adjacent to the
22
+ // page edge — rightmost in the west strip, leftmost in the east
23
+ const gx = side === 1 ? FIELD_COLS - col : col - 1;
24
+ cells.push(
25
+ <div key={`c${col}-${row}`} className="gf-cell" style={{ "--gx": gx, "--gy": row }}>
26
+ <span className={shape} />
27
+ </div>,
28
+ );
29
+ }
30
+ }
31
+
32
+ return (
33
+ <div className={`gf-strip ${side === 1 ? "gf-w" : "gf-e"}`}>
34
+ {lines}
35
+ {cells}
36
+ </div>
37
+ );
38
+ }
39
+
40
+ /** Mounted before each page's sections. */
41
+ export function GridField() {
42
+ return (
43
+ <div className="gfield" aria-hidden="true">
44
+ <Strip side={1} />
45
+ <Strip side={2} />
46
+ </div>
47
+ );
48
+ }
package/grid/gates.cjs ADDED
@@ -0,0 +1,34 @@
1
+ /** The band gates, named once. `@container (--rt)` in any stylesheet becomes
2
+ * `@container (min-width: 665px)` at build time; container queries cannot
3
+ * read custom properties, so this is the one preprocessing step in the
4
+ * cascade. Wired in postcss.config.mjs. Bands: rm 384 · rs 576 · rt 768 ·
5
+ * rd1 960 · rd2 1344; a gate is the midpoint that opens the next band. */
6
+
7
+ const GATES = {
8
+ rs: "(min-width: 470px)",
9
+ rt: "(min-width: 665px)",
10
+ rd1: "(min-width: 860px)",
11
+ rd2: "(min-width: 1130px)",
12
+ /* Compound gates are parenthesised so they compose: `(--rt-only) or (--rd2)`. */
13
+ "rt-only": "((min-width: 665px) and (max-width: 859.98px))",
14
+ "below-rs": "(max-width: 469px)",
15
+ "below-rt": "(max-width: 664px)",
16
+ "below-rd1": "(max-width: 859px)",
17
+ };
18
+
19
+ const plugin = () => ({
20
+ postcssPlugin: "keystone-gates",
21
+ AtRule: {
22
+ container(rule) {
23
+ rule.params = rule.params.replace(/\(--([\w-]+)\)/g, (match, name) => {
24
+ const gate = GATES[name];
25
+ if (!gate) throw rule.error(`Unknown gate ${match}; see design-system/grid/gates.cjs`);
26
+ return gate;
27
+ });
28
+ },
29
+ },
30
+ });
31
+ plugin.postcss = true;
32
+
33
+ module.exports = plugin;
34
+ module.exports.GATES = GATES;
@@ -0,0 +1,97 @@
1
+ /** Server-safe exposure regions. Real 1px lattice lines render before
2
+ * hydration. Geometry uses ticks; `gy` counts rows from the section top,
3
+ * `gyb` counts rows from the section bottom, and `band` gates
4
+ * visibility. A region with both edges stretches between them so the
5
+ * exposure follows a flow section that grows with its copy. */
6
+
7
+ import type { CSSProperties } from "react";
8
+
9
+ export type GridBand = "rm" | "rs" | "rt" | "rd1" | "rd2";
10
+
11
+ /* Interior rows drawn past a stretched region's designed rows; the
12
+ region clips whatever its grown height does not reach. */
13
+ const STRETCH_SLACK_ROWS = 16;
14
+
15
+ interface RegionGeometry {
16
+ band: GridBand;
17
+ gx: number;
18
+ /** Rows from the section top to the region's top edge. */
19
+ gy?: number;
20
+ /** Rows from the section bottom to the region's bottom edge. */
21
+ gyb?: number;
22
+ gw?: number;
23
+ /** Designed rows; a stretched region uses it only for its line count. */
24
+ gh?: number;
25
+ }
26
+
27
+ interface GridRegionProps extends RegionGeometry {
28
+ className?: string;
29
+ }
30
+
31
+ type Anchor = "top" | "bottom" | "stretch";
32
+
33
+ function anchorOf(gy: number | undefined, gyb: number | undefined): Anchor {
34
+ if (gy !== undefined && gyb !== undefined) return "stretch";
35
+ if (gyb !== undefined) return "bottom";
36
+ return "top";
37
+ }
38
+
39
+ const ANCHOR_CLASS: Record<Anchor, string> = { top: "", bottom: " gb", stretch: " gs" };
40
+
41
+ function geometryStyle({ gx, gy, gyb, gw, gh }: Omit<RegionGeometry, "band">): CSSProperties {
42
+ return {
43
+ "--gx": gx,
44
+ ...(gy !== undefined && { "--gy": gy }),
45
+ ...(gyb !== undefined && { "--gyb": gyb }),
46
+ ...(gw !== undefined && { "--gw": gw }),
47
+ ...(gh !== undefined && { "--gh": gh }),
48
+ };
49
+ }
50
+
51
+ /** Exposure region: bordered rectangle plus its interior lattice lines. */
52
+ export function GridRegion({ band, gx, gy, gyb, gw = 1, gh = 1, className }: GridRegionProps) {
53
+ const anchor = anchorOf(gy, gyb);
54
+ const rows = anchor === "stretch" ? gh + STRETCH_SLACK_ROWS : gh;
55
+ const lines = [];
56
+ for (let n = 1; n < gw; n++) {
57
+ lines.push(<i key={`v${n}`} className="v" style={{ "--n": n }} />);
58
+ }
59
+ for (let n = 1; n < rows; n++) {
60
+ lines.push(<i key={`h${n}`} className="h" style={{ "--n": n }} />);
61
+ }
62
+ const geometry =
63
+ anchor === "stretch"
64
+ ? { gx, gy, gyb, gw }
65
+ : anchor === "bottom"
66
+ ? { gx, gyb, gw, gh }
67
+ : { gx, gy: gy ?? 0, gw, gh };
68
+ return (
69
+ <div
70
+ className={`grid-region ${band}${ANCHOR_CLASS[anchor]}${className ? ` ${className}` : ""}`}
71
+ style={geometryStyle(geometry)}
72
+ >
73
+ {lines}
74
+ </div>
75
+ );
76
+ }
77
+
78
+ /** Ornament cell: hosts decoration between lattice and content. Set
79
+ * `gy` to count from the section top or `gyb` from its bottom. */
80
+ export function GridDecor({
81
+ band,
82
+ gx,
83
+ gy,
84
+ gyb,
85
+ children,
86
+ }: Pick<RegionGeometry, "band" | "gx" | "gy" | "gyb"> & { children?: React.ReactNode }) {
87
+ const fromBottom = gyb !== undefined;
88
+ return (
89
+ <div
90
+ className={`decor ${band}${fromBottom ? " gb" : ""}`}
91
+ style={geometryStyle(fromBottom ? { gx, gyb } : { gx, gy: gy ?? 0 })}
92
+ aria-hidden="true"
93
+ >
94
+ {children}
95
+ </div>
96
+ );
97
+ }