@42-central/ui-react 0.22.0 → 0.24.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/dist/{chunk-DJAXXLN6.js → chunk-F2FSHVO5.js} +3 -3
- package/dist/{chunk-DJAXXLN6.js.map → chunk-F2FSHVO5.js.map} +1 -1
- package/dist/components/ambient-background/ambient-background.d.ts +14 -3
- package/dist/components/ambient-background/ambient-background.d.ts.map +1 -1
- package/dist/components/ambient-background/index.js +222 -1
- package/dist/components/ambient-background/index.js.map +1 -1
- package/dist/components/ambient-background/starfield.d.ts +13 -0
- package/dist/components/ambient-background/starfield.d.ts.map +1 -0
- package/dist/components/camera/index.js +2 -2
- package/dist/components/data-table/index.js +1 -1
- package/dist/components/geodesic/a11y.d.ts +15 -0
- package/dist/components/geodesic/a11y.d.ts.map +1 -0
- package/dist/components/geodesic/activity-badge.d.ts +5 -0
- package/dist/components/geodesic/activity-badge.d.ts.map +1 -0
- package/dist/components/geodesic/badge-frame.d.ts +60 -0
- package/dist/components/geodesic/badge-frame.d.ts.map +1 -0
- package/dist/components/geodesic/exam-badge.d.ts +5 -0
- package/dist/components/geodesic/exam-badge.d.ts.map +1 -0
- package/dist/components/geodesic/geometry.d.ts +1089 -0
- package/dist/components/geodesic/geometry.d.ts.map +1 -0
- package/dist/components/geodesic/gift-box-badge.d.ts +5 -0
- package/dist/components/geodesic/gift-box-badge.d.ts.map +1 -0
- package/dist/components/geodesic/gift-token.d.ts +23 -0
- package/dist/components/geodesic/gift-token.d.ts.map +1 -0
- package/dist/components/geodesic/glyph-slot.d.ts +8 -0
- package/dist/components/geodesic/glyph-slot.d.ts.map +1 -0
- package/dist/components/geodesic/index.d.ts +12 -0
- package/dist/components/geodesic/index.d.ts.map +1 -0
- package/dist/components/geodesic/index.js +917 -0
- package/dist/components/geodesic/index.js.map +1 -0
- package/dist/components/geodesic/module-badge.d.ts +5 -0
- package/dist/components/geodesic/module-badge.d.ts.map +1 -0
- package/dist/components/geodesic/planet.d.ts +30 -0
- package/dist/components/geodesic/planet.d.ts.map +1 -0
- package/dist/components/geodesic/project-badge.d.ts +5 -0
- package/dist/components/geodesic/project-badge.d.ts.map +1 -0
- package/dist/components/geodesic/skill-badge.d.ts +5 -0
- package/dist/components/geodesic/skill-badge.d.ts.map +1 -0
- package/dist/components/geodesic/social-badge.d.ts +8 -0
- package/dist/components/geodesic/social-badge.d.ts.map +1 -0
- package/dist/components/geodesic/status.d.ts +80 -0
- package/dist/components/geodesic/status.d.ts.map +1 -0
- package/dist/components/geodesic/styles.css +146 -0
- package/dist/components/photo-capture/index.js +2 -2
- package/dist/theme.css +75 -0
- package/package.json +2 -1
- package/src/as-child.contract.test.tsx +2 -0
- package/src/components/ambient-background/ambient-background.test.tsx +59 -0
- package/src/components/ambient-background/ambient-background.tsx +15 -2
- package/src/components/ambient-background/starfield.tsx +331 -0
- package/src/components/geodesic/a11y.ts +10 -0
- package/src/components/geodesic/activity-badge.tsx +17 -0
- package/src/components/geodesic/badge-frame.tsx +324 -0
- package/src/components/geodesic/exam-badge.tsx +17 -0
- package/src/components/geodesic/geometry.test.ts +60 -0
- package/src/components/geodesic/geometry.ts +367 -0
- package/src/components/geodesic/gift-box-badge.tsx +17 -0
- package/src/components/geodesic/gift-token.tsx +104 -0
- package/src/components/geodesic/glyph-slot.tsx +28 -0
- package/src/components/geodesic/index.ts +13 -0
- package/src/components/geodesic/module-badge.tsx +17 -0
- package/src/components/geodesic/planet.tsx +131 -0
- package/src/components/geodesic/project-badge.tsx +17 -0
- package/src/components/geodesic/skill-badge.tsx +17 -0
- package/src/components/geodesic/social-badge.tsx +21 -0
- package/src/components/geodesic/status.test.ts +66 -0
- package/src/components/geodesic/status.ts +176 -0
- package/src/components/geodesic/styles.css +146 -0
- package/src/icon-stroke.test.tsx +7 -0
- package/src/theme.css +75 -0
- package/src/theme.test.ts +10 -2
package/dist/theme.css
CHANGED
|
@@ -1420,6 +1420,81 @@ body {
|
|
|
1420
1420
|
--ambient-noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.4' numOctaves='2' stitchTiles='stitch' result='t'/%3E%3CfeColorMatrix in='t' type='matrix' values='0 0 0 0 0.573 0 0 0 0 0.69 0 0 0 0 0.98 0 0 0 1 0' result='c'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='gamma' amplitude='0.09' exponent='2' offset='0'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
|
|
1421
1421
|
}
|
|
1422
1422
|
|
|
1423
|
+
/* The starfield's motion (`withStarfield`, see ambient-background/starfield.tsx).
|
|
1424
|
+
Every animated piece sets its own delay and duration inline, so these are
|
|
1425
|
+
just the shapes; the utilities are applied behind `motion-safe:`. */
|
|
1426
|
+
@theme static {
|
|
1427
|
+
/* The brighter stars breathe, slowly and out of step. Dimming, never
|
|
1428
|
+
vanishing: a star that blinks out reads as a glitch, not a twinkle. */
|
|
1429
|
+
--animate-ambient-star-twinkle: ambient-star-twinkle 8s ease-in-out infinite;
|
|
1430
|
+
/* The dust dims the same way, deeper and slower, one group per layer. */
|
|
1431
|
+
--animate-ambient-star-dim: ambient-star-dim 17s ease-in-out infinite;
|
|
1432
|
+
/* The nebula's clouds swing slowly away and back, each by its own drift
|
|
1433
|
+
(`--drift-*`, set per cloud): moved, swollen a little and thinned out at
|
|
1434
|
+
the far end, eased at both. */
|
|
1435
|
+
--animate-ambient-nebula-drift: ambient-nebula-drift 90s ease-in-out infinite alternate;
|
|
1436
|
+
/* A meteor's whole cycle is mostly waiting: it streaks across in the first
|
|
1437
|
+
2% (about a second of its long cycle), its tail growing behind the head
|
|
1438
|
+
as it fades in and burning out before it stops, then nothing until the
|
|
1439
|
+
next pass. Linear, because a meteor doesn't ease. */
|
|
1440
|
+
--animate-ambient-meteor: ambient-meteor 40s linear infinite;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
@keyframes ambient-star-twinkle {
|
|
1444
|
+
0%,
|
|
1445
|
+
100% {
|
|
1446
|
+
opacity: 1;
|
|
1447
|
+
}
|
|
1448
|
+
50% {
|
|
1449
|
+
opacity: 0.5;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
@keyframes ambient-star-dim {
|
|
1454
|
+
0%,
|
|
1455
|
+
100% {
|
|
1456
|
+
opacity: 1;
|
|
1457
|
+
}
|
|
1458
|
+
50% {
|
|
1459
|
+
opacity: 0.35;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
@keyframes ambient-nebula-drift {
|
|
1464
|
+
to {
|
|
1465
|
+
transform: translate3d(var(--drift-x), var(--drift-y), 0) scale(var(--drift-scale));
|
|
1466
|
+
opacity: var(--drift-fade);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
@keyframes ambient-meteor {
|
|
1471
|
+
0% {
|
|
1472
|
+
opacity: 0;
|
|
1473
|
+
transform: translateX(0) scaleX(0.2);
|
|
1474
|
+
}
|
|
1475
|
+
0.5% {
|
|
1476
|
+
opacity: 1;
|
|
1477
|
+
}
|
|
1478
|
+
2%,
|
|
1479
|
+
100% {
|
|
1480
|
+
opacity: 0;
|
|
1481
|
+
transform: translateX(18rem) scaleX(1);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
/* `motion-safe:` reads only the OS setting; apps that let people choose
|
|
1486
|
+
in-app set `data-motion="reduced"` on `<html>`, and the sky stills for that
|
|
1487
|
+
too: no drift, no dimming, no meteors. */
|
|
1488
|
+
:where(:root[data-motion="reduced"]) {
|
|
1489
|
+
.ambient-starfield,
|
|
1490
|
+
.ambient-starfield * {
|
|
1491
|
+
animation: none;
|
|
1492
|
+
}
|
|
1493
|
+
.ambient-starfield-meteors {
|
|
1494
|
+
display: none;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1423
1498
|
/* `Tabs`: a trigger whose list's indicator is still `hidden` — the server
|
|
1424
1499
|
render, and the client until Ark has measured the selected trigger (Ark
|
|
1425
1500
|
clears `hidden` and sets the rect in the same render). The selected trigger
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@42-central/ui-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "React UI kit for 42 tools",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"build": "tsup && tsc -p tsconfig.build.json",
|
|
45
45
|
"dev": "tsup --watch",
|
|
46
46
|
"typecheck": "tsc --noEmit",
|
|
47
|
+
"generate:geodesic": "node scripts/generate-geometry.ts",
|
|
47
48
|
"test": "vitest run",
|
|
48
49
|
"test:watch": "vitest",
|
|
49
50
|
"clean": "rm -rf dist .turbo",
|
|
@@ -48,6 +48,7 @@ import * as fileTrigger from "./components/file-trigger"
|
|
|
48
48
|
import * as fileUpload from "./components/file-upload"
|
|
49
49
|
import * as flex from "./components/flex"
|
|
50
50
|
import * as gallery from "./components/gallery"
|
|
51
|
+
import * as geodesic from "./components/geodesic"
|
|
51
52
|
import * as grid from "./components/grid"
|
|
52
53
|
import * as hoverCard from "./components/hover-card"
|
|
53
54
|
import * as image from "./components/image"
|
|
@@ -186,6 +187,7 @@ const modules = {
|
|
|
186
187
|
fileUpload,
|
|
187
188
|
flex,
|
|
188
189
|
gallery,
|
|
190
|
+
geodesic,
|
|
189
191
|
grid,
|
|
190
192
|
hoverCard,
|
|
191
193
|
image,
|
|
@@ -75,4 +75,63 @@ describe("AmbientBackground", () => {
|
|
|
75
75
|
// biome-ignore lint/style/noNonNullAssertion: exactly 2 children are rendered above
|
|
76
76
|
expect(noiseEl!.className).toContain("noise-class")
|
|
77
77
|
})
|
|
78
|
+
describe("withStarfield", () => {
|
|
79
|
+
it("is off by default", () => {
|
|
80
|
+
const { container } = render(<AmbientBackground />)
|
|
81
|
+
expect(container.querySelector(".ambient-starfield")).toBeNull()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it("adds its layers after glow and noise, each fixed at the top level, decorative and out of a forced palette", () => {
|
|
85
|
+
const { container } = render(<AmbientBackground withStarfield />)
|
|
86
|
+
const layers = Array.from(container.children) as HTMLElement[]
|
|
87
|
+
// glow, noise, five nebula clouds, the stars, the meteors
|
|
88
|
+
expect(layers).toHaveLength(9)
|
|
89
|
+
expect(layers[0]?.style.backgroundImage).toBe("var(--ambient-glow)")
|
|
90
|
+
expect(layers[1]?.style.backgroundImage).toBe("var(--ambient-noise)")
|
|
91
|
+
for (const el of layers.slice(2)) {
|
|
92
|
+
expect(el.className).toContain("ambient-starfield")
|
|
93
|
+
expect(el.getAttribute("aria-hidden")).toBe("true")
|
|
94
|
+
expect(el.className).toContain("pointer-events-none")
|
|
95
|
+
expect(el.className).toContain("forced-colors:hidden")
|
|
96
|
+
expect(el.className).toContain("fixed")
|
|
97
|
+
expect(el.className).not.toContain("absolute")
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it("animates only behind motion-safe, and keeps the meteors hidden without it", () => {
|
|
102
|
+
const { container } = render(
|
|
103
|
+
<AmbientBackground withStarfield withGlow={false} withNoise={false} />,
|
|
104
|
+
)
|
|
105
|
+
const animated = container.querySelectorAll('[class*="animate-ambient-"]')
|
|
106
|
+
expect(animated.length).toBeGreaterThan(0)
|
|
107
|
+
for (const el of Array.from(animated)) {
|
|
108
|
+
for (const cls of Array.from(el.classList).filter((c) => c.includes("animate-"))) {
|
|
109
|
+
expect(cls.startsWith("motion-safe:")).toBe(true)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const meteors = container.querySelector(".ambient-starfield-meteors")
|
|
113
|
+
expect(meteors?.classList).toContain("hidden")
|
|
114
|
+
expect(meteors?.classList).toContain("motion-safe:block")
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it("draws the same sky on every render", () => {
|
|
118
|
+
const a = render(<AmbientBackground withStarfield />).container.innerHTML
|
|
119
|
+
const b = render(<AmbientBackground withStarfield />).container.innerHTML
|
|
120
|
+
expect(a).toBe(b)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it("suffixes testId per starfield layer and merges their classNames", () => {
|
|
124
|
+
const { getByTestId, getAllByTestId } = render(
|
|
125
|
+
<AmbientBackground
|
|
126
|
+
withStarfield
|
|
127
|
+
testId="bg"
|
|
128
|
+
classNames={{ nebula: "n", stars: "s", meteors: "m" }}
|
|
129
|
+
/>,
|
|
130
|
+
)
|
|
131
|
+
expect(getByTestId("bg-nebula-0").className).toContain("n")
|
|
132
|
+
expect(getByTestId("bg-stars").className).toContain("s")
|
|
133
|
+
expect(getByTestId("bg-meteors").className).toContain("m")
|
|
134
|
+
expect(getAllByTestId(/^bg-nebula-/)).toHaveLength(5)
|
|
135
|
+
})
|
|
136
|
+
})
|
|
78
137
|
})
|
|
@@ -2,6 +2,7 @@ import { cn } from "../../lib/cn"
|
|
|
2
2
|
import { warnRenamedProp } from "../../lib/dev-warn"
|
|
3
3
|
import { props } from "../../lib/props"
|
|
4
4
|
import type { WithTestId } from "../../lib/test-id"
|
|
5
|
+
import { Starfield, type StarfieldClassNames } from "./starfield"
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* AmbientBackground — a decorative, brand-tinted page background: a soft
|
|
@@ -22,6 +23,12 @@ import type { WithTestId } from "../../lib/test-id"
|
|
|
22
23
|
* regardless of z-index — nesting a blended layer inside another `fixed`
|
|
23
24
|
* wrapper would cut off what it can blend against).
|
|
24
25
|
*
|
|
26
|
+
* `withStarfield` adds a third, opt-in layer set: a slowly moving starry sky
|
|
27
|
+
* over soft violet nebulae (dimming dust, breathing bright stars, a rare
|
|
28
|
+
* meteor), seeded so it is identical on every render. It follows the same
|
|
29
|
+
* recipe — separate fixed layers, no shared wrapper — and stills under reduced
|
|
30
|
+
* motion, either the OS setting or `data-motion="reduced"` on `<html>`.
|
|
31
|
+
*
|
|
25
32
|
* The actual glow/noise values are CSS custom properties (`--ambient-glow` /
|
|
26
33
|
* `--ambient-noise`, defined in `theme.css`, brand-tinted and theme-aware via
|
|
27
34
|
* `data-theme`) rather than hardcoded here — override either on `:root` to
|
|
@@ -40,19 +47,23 @@ import type { WithTestId } from "../../lib/test-id"
|
|
|
40
47
|
*/
|
|
41
48
|
/**
|
|
42
49
|
* There is no root element, so `testId` lands on each layer with its part as a
|
|
43
|
-
* suffix: `` `${testId}-glow` `` and `` `${testId}-noise`
|
|
50
|
+
* suffix: `` `${testId}-glow` `` and `` `${testId}-noise` ``, and with the
|
|
51
|
+
* starfield `` `${testId}-nebula-<n>` ``, `` `${testId}-stars` `` and
|
|
52
|
+
* `` `${testId}-meteors` ``.
|
|
44
53
|
*/
|
|
45
54
|
export type AmbientBackgroundProps = WithTestId & {
|
|
46
55
|
/** Render the radial glow layer. Default `true`. */
|
|
47
56
|
withGlow?: boolean
|
|
48
57
|
/** Render the film-grain noise layer. Default `true`. */
|
|
49
58
|
withNoise?: boolean
|
|
59
|
+
/** Render the starfield over the glow and noise: nebulae, stars and meteors. Default `false`. */
|
|
60
|
+
withStarfield?: boolean
|
|
50
61
|
/** @deprecated Renamed `withGlow`. Removed in the next minor. `withGlow` wins when both are set. */
|
|
51
62
|
glow?: boolean
|
|
52
63
|
/** @deprecated Renamed `withNoise`. Removed in the next minor. `withNoise` wins when both are set. */
|
|
53
64
|
noise?: boolean
|
|
54
65
|
/** Extra classes for each layer. */
|
|
55
|
-
classNames?: {
|
|
66
|
+
classNames?: StarfieldClassNames & {
|
|
56
67
|
glow?: string
|
|
57
68
|
noise?: string
|
|
58
69
|
}
|
|
@@ -63,6 +74,7 @@ export const AmbientBackground = ({
|
|
|
63
74
|
noise,
|
|
64
75
|
withGlow = glow ?? true,
|
|
65
76
|
withNoise = noise ?? true,
|
|
77
|
+
withStarfield = false,
|
|
66
78
|
classNames,
|
|
67
79
|
testId,
|
|
68
80
|
}: AmbientBackgroundProps) => {
|
|
@@ -92,6 +104,7 @@ export const AmbientBackground = ({
|
|
|
92
104
|
{...props({ "data-testid": testId && `${testId}-noise` })}
|
|
93
105
|
/>
|
|
94
106
|
)}
|
|
107
|
+
{withStarfield && <Starfield classNames={classNames} testId={testId} />}
|
|
95
108
|
</>
|
|
96
109
|
)
|
|
97
110
|
}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import type { CSSProperties } from "react"
|
|
2
|
+
import { cn } from "../../lib/cn"
|
|
3
|
+
import { props } from "../../lib/props"
|
|
4
|
+
|
|
5
|
+
// The starfield AmbientBackground draws with `withStarfield`: a starry sky over
|
|
6
|
+
// soft violet nebulae, stacked on the glow and noise (the noise is what
|
|
7
|
+
// dithers these gradients so they never band). Every layer takes the same
|
|
8
|
+
// recipe as glow and noise (fixed, -z-10, no shared wrapper) and paints over
|
|
9
|
+
// them, still under every piece of the app.
|
|
10
|
+
//
|
|
11
|
+
// Everything is computed once at module load from a seeded PRNG, so the sky
|
|
12
|
+
// is identical on every render, on the server and the client, and on every
|
|
13
|
+
// visit. It moves, slowly: the clouds drift and swell, the dust dims and comes
|
|
14
|
+
// back, the brighter stars breathe, and now and then a meteor crosses. All of
|
|
15
|
+
// it is CSS animation of transform and opacity (keyframes in theme.css), so
|
|
16
|
+
// the compositor runs it and no script does per frame; and all of it sits
|
|
17
|
+
// behind `motion-safe:` and the `data-motion="reduced"` rule in theme.css, so
|
|
18
|
+
// with reduced motion the sky is a still picture, without the meteors.
|
|
19
|
+
|
|
20
|
+
// mulberry32: tiny, fast, and good enough to scatter dots.
|
|
21
|
+
const prng = (seed: number) => () => {
|
|
22
|
+
seed = (seed + 0x6d2b79f5) | 0
|
|
23
|
+
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed)
|
|
24
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
|
|
25
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const round = (n: number) => Math.round(n * 100) / 100
|
|
29
|
+
|
|
30
|
+
type Star = { x: number; y: number; r: number; opacity: number }
|
|
31
|
+
|
|
32
|
+
// Most stars are a cool white; a few lean violet or pink, as in the design.
|
|
33
|
+
// On a light sky the same hues go dark, so the dots read as ink, not glare.
|
|
34
|
+
const TONES = [
|
|
35
|
+
"fill-brand-500 dark:fill-brand-100",
|
|
36
|
+
"fill-purple-500 dark:fill-purple-200",
|
|
37
|
+
"fill-pink-500 dark:fill-pink-200",
|
|
38
|
+
] as const
|
|
39
|
+
|
|
40
|
+
type Tone = (typeof TONES)[number]
|
|
41
|
+
|
|
42
|
+
const pickTone = (n: number): Tone => (n < 0.78 ? TONES[0] : n < 0.95 ? TONES[1] : TONES[2])
|
|
43
|
+
|
|
44
|
+
// The dust dims in a few groups, each on its own slow beat, so at any moment
|
|
45
|
+
// some stars are fading and others coming back. A group is a whole layer
|
|
46
|
+
// fading (cheap: the compositor does it), and its stars are scattered all
|
|
47
|
+
// over, so it reads as single stars dimming, not as a region pulsing. The
|
|
48
|
+
// beats share no common factor, so the groups never line up into one blink.
|
|
49
|
+
const DIM_BEATS = [
|
|
50
|
+
{ duration: "11s", delay: "-3s" },
|
|
51
|
+
{ duration: "17s", delay: "-11s" },
|
|
52
|
+
{ duration: "23s", delay: "-7s" },
|
|
53
|
+
] as const
|
|
54
|
+
|
|
55
|
+
// Dots for one repeating tile, by dimming group, then by tone so each tone
|
|
56
|
+
// is one <g>.
|
|
57
|
+
const scatter = (seed: number, size: number, count: number) => {
|
|
58
|
+
const random = prng(seed)
|
|
59
|
+
// Its own sequence, so sorting the dots into groups doesn't move them.
|
|
60
|
+
const group = prng(seed + 1)
|
|
61
|
+
const phases = DIM_BEATS.map(() => new Map<Tone, Star[]>(TONES.map((tone) => [tone, []])))
|
|
62
|
+
for (let i = 0; i < count; i++) {
|
|
63
|
+
// Skewed towards the faintest, smallest dots: a real sky is mostly dust.
|
|
64
|
+
const weight = random() ** 2.4
|
|
65
|
+
const star = {
|
|
66
|
+
// Kept off the tile's edge so no dot is cut in half where tiles meet.
|
|
67
|
+
x: round(2 + random() * (size - 4)),
|
|
68
|
+
y: round(2 + random() * (size - 4)),
|
|
69
|
+
r: round(0.4 + weight * 0.75),
|
|
70
|
+
opacity: round(0.22 + weight * 0.4 + random() * 0.1),
|
|
71
|
+
}
|
|
72
|
+
phases[Math.floor(group() * phases.length)]?.get(pickTone(random()))?.push(star)
|
|
73
|
+
}
|
|
74
|
+
return { size, phases: phases.map((phase) => [...phase]) }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Two tiles of coprime-ish sizes overlap into a pattern that only repeats
|
|
78
|
+
// every few thousand pixels, so the eye never catches the tiling. Fixed pixel
|
|
79
|
+
// tiles (not a scaled viewBox) keep the same density on a phone and a wide
|
|
80
|
+
// screen. Together about one dot per 6000px², the design's own density.
|
|
81
|
+
const TILES = [scatter(42, 509, 26), scatter(1337, 733, 38)]
|
|
82
|
+
|
|
83
|
+
// The few brighter stars, placed by viewport percentage so they spread over
|
|
84
|
+
// any screen. A soft halo rather than a hard disc; the three with `sparkle`
|
|
85
|
+
// carry the design's diffraction spikes, kept thin and short.
|
|
86
|
+
const BRIGHT_STARS = [
|
|
87
|
+
{ x: "8%", y: "14%", sparkle: true, delay: "0s", duration: "7s" },
|
|
88
|
+
{ x: "31%", y: "6%", sparkle: false, delay: "-2s", duration: "9s" },
|
|
89
|
+
{ x: "62%", y: "11%", sparkle: false, delay: "-5s", duration: "8s" },
|
|
90
|
+
{ x: "88%", y: "22%", sparkle: true, delay: "-3s", duration: "10s" },
|
|
91
|
+
{ x: "18%", y: "58%", sparkle: false, delay: "-6s", duration: "8s" },
|
|
92
|
+
{ x: "47%", y: "41%", sparkle: false, delay: "-1s", duration: "11s" },
|
|
93
|
+
{ x: "76%", y: "63%", sparkle: true, delay: "-4s", duration: "9s" },
|
|
94
|
+
{ x: "36%", y: "86%", sparkle: false, delay: "-7s", duration: "10s" },
|
|
95
|
+
{ x: "93%", y: "90%", sparkle: false, delay: "-2.5s", duration: "7s" },
|
|
96
|
+
] as const
|
|
97
|
+
|
|
98
|
+
// A four-point sparkle with concave sides: reads as a lens glint, not a shape.
|
|
99
|
+
const SPARKLE = "M0 -6Q0 0 6 0Q0 0 0 6Q0 0 -6 0Q0 0 0 -6Z"
|
|
100
|
+
|
|
101
|
+
// Each cloud's layer overhangs the viewport by this much on every side, so a
|
|
102
|
+
// cloud cut by the screen's edge (several are) can drift without the cut
|
|
103
|
+
// ever coming into view.
|
|
104
|
+
const BLEED = 15
|
|
105
|
+
const SPAN = 100 + 2 * BLEED
|
|
106
|
+
|
|
107
|
+
// A length or a position given in viewport %, as % of the overhanging layer.
|
|
108
|
+
const inLayer = (viewport: number, offset = 0) => `${round(((viewport + offset) / SPAN) * 100)}%`
|
|
109
|
+
|
|
110
|
+
type Ellipse = { rx: number; ry: number; x: number; y: number }
|
|
111
|
+
type Hue = { color: string; strength: number }
|
|
112
|
+
|
|
113
|
+
// Violet and indigo clouds after the design's "Nébuleuse", softened: wide
|
|
114
|
+
// ellipses that fade out over their whole radius so no edge ever shows. The
|
|
115
|
+
// design's blue core is already the kit's ambient glow; this adds the purple.
|
|
116
|
+
const cloud = ({ rx, ry, x, y }: Ellipse, { color, strength }: Hue) =>
|
|
117
|
+
`radial-gradient(ellipse ${inLayer(rx)} ${inLayer(ry)} at ${inLayer(x, BLEED)} ${inLayer(y, BLEED)}, color-mix(in oklab, var(${color}) ${strength}%, transparent), color-mix(in oklab, var(${color}) ${strength * 0.45}%, transparent) 45%, transparent 100%)`
|
|
118
|
+
|
|
119
|
+
// Each cloud drifts on its own long, slow swing (there and back, eased at
|
|
120
|
+
// both ends), swelling a little and thinning as it goes: a few px a second,
|
|
121
|
+
// so the sky is never seen moving, only found changed. On a light sky the
|
|
122
|
+
// same clouds are pale tints, so the light theme keeps the violet without
|
|
123
|
+
// muddying the page.
|
|
124
|
+
const CLOUDS: {
|
|
125
|
+
at: Ellipse
|
|
126
|
+
dark: Hue
|
|
127
|
+
light: Hue
|
|
128
|
+
drift: { x: string; y: string; scale: number; fade: number; duration: string; delay: string }
|
|
129
|
+
}[] = [
|
|
130
|
+
{
|
|
131
|
+
at: { rx: 42, ry: 34, x: 30, y: 64 },
|
|
132
|
+
dark: { color: "--color-purple-400", strength: 9 },
|
|
133
|
+
light: { color: "--color-purple-200", strength: 14 },
|
|
134
|
+
drift: { x: "6vw", y: "-4vh", scale: 1.12, fade: 0.7, duration: "70s", delay: "-20s" },
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
at: { rx: 60, ry: 38, x: 42, y: 104 },
|
|
138
|
+
dark: { color: "--color-purple-800", strength: 20 },
|
|
139
|
+
light: { color: "--color-purple-200", strength: 26 },
|
|
140
|
+
drift: { x: "-8vw", y: "-3vh", scale: 1.08, fade: 0.85, duration: "95s", delay: "-50s" },
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
at: { rx: 40, ry: 34, x: 92, y: 4 },
|
|
144
|
+
dark: { color: "--color-purple-800", strength: 22 },
|
|
145
|
+
light: { color: "--color-purple-200", strength: 28 },
|
|
146
|
+
drift: { x: "-5vw", y: "5vh", scale: 1.15, fade: 0.8, duration: "85s", delay: "-10s" },
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
at: { rx: 46, ry: 40, x: 24, y: 20 },
|
|
150
|
+
dark: { color: "--color-brand-700", strength: 18 },
|
|
151
|
+
light: { color: "--color-brand-200", strength: 24 },
|
|
152
|
+
drift: { x: "7vw", y: "4vh", scale: 1.1, fade: 0.85, duration: "110s", delay: "-70s" },
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
at: { rx: 36, ry: 30, x: 4, y: 92 },
|
|
156
|
+
dark: { color: "--color-pink-800", strength: 10 },
|
|
157
|
+
light: { color: "--color-pink-200", strength: 16 },
|
|
158
|
+
drift: { x: "5vw", y: "-6vh", scale: 1.2, fade: 0.6, duration: "75s", delay: "-35s" },
|
|
159
|
+
},
|
|
160
|
+
]
|
|
161
|
+
|
|
162
|
+
// The cloud's picture per theme and its drift, as variables the classes and
|
|
163
|
+
// the ambient-nebula-drift keyframes (theme.css) read.
|
|
164
|
+
const cloudStyle = ({ at, dark, light, drift }: (typeof CLOUDS)[number]) =>
|
|
165
|
+
({
|
|
166
|
+
"--nebula-light": cloud(at, light),
|
|
167
|
+
"--nebula-dark": cloud(at, dark),
|
|
168
|
+
"--drift-x": drift.x,
|
|
169
|
+
"--drift-y": drift.y,
|
|
170
|
+
"--drift-scale": drift.scale,
|
|
171
|
+
"--drift-fade": drift.fade,
|
|
172
|
+
inset: `-${BLEED}%`,
|
|
173
|
+
animationDuration: drift.duration,
|
|
174
|
+
animationDelay: drift.delay,
|
|
175
|
+
}) as CSSProperties
|
|
176
|
+
|
|
177
|
+
// The meteors: three, each on its own long cycle and visible for about a
|
|
178
|
+
// second of it, so one crosses every twenty seconds or so, never on arrival
|
|
179
|
+
// and almost never two at once. Thin, short and faint, high in the sky,
|
|
180
|
+
// falling down and to the left. Seen from the corner of the eye, not watched.
|
|
181
|
+
const METEORS = [
|
|
182
|
+
{ x: "72%", y: "8%", angle: "152deg", duration: "37s", delay: "9s" },
|
|
183
|
+
{ x: "50%", y: "20%", angle: "160deg", duration: "53s", delay: "24s" },
|
|
184
|
+
{ x: "92%", y: "30%", angle: "148deg", duration: "71s", delay: "41s" },
|
|
185
|
+
] as const
|
|
186
|
+
|
|
187
|
+
// The halo's stops, per theme: a gradient stop takes no `dark:` class.
|
|
188
|
+
const HALO_THEME =
|
|
189
|
+
"[--star-halo-core:var(--color-brand-400)] [--star-halo-rim:var(--color-purple-400)] dark:[--star-halo-core:var(--color-brand-100)] dark:[--star-halo-rim:var(--color-purple-300)]"
|
|
190
|
+
|
|
191
|
+
// Every layer's recipe: decorative, out of the pointer's way and out of a
|
|
192
|
+
// forced palette's. `ambient-starfield` is the hook theme.css's
|
|
193
|
+
// `data-motion="reduced"` rule stills it by.
|
|
194
|
+
const LAYER = "ambient-starfield pointer-events-none fixed -z-10 forced-colors:hidden"
|
|
195
|
+
|
|
196
|
+
export type StarfieldClassNames = {
|
|
197
|
+
/** Each nebula cloud's layer. */
|
|
198
|
+
nebula?: string
|
|
199
|
+
/** The layer holding the dust and the brighter stars. */
|
|
200
|
+
stars?: string
|
|
201
|
+
/** The meteors' layer. */
|
|
202
|
+
meteors?: string
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export const Starfield = ({
|
|
206
|
+
classNames,
|
|
207
|
+
testId,
|
|
208
|
+
}: {
|
|
209
|
+
classNames?: StarfieldClassNames
|
|
210
|
+
testId?: string
|
|
211
|
+
}) => (
|
|
212
|
+
<>
|
|
213
|
+
{CLOUDS.map((c, i) => (
|
|
214
|
+
<div
|
|
215
|
+
key={`${c.at.x}-${c.at.y}`}
|
|
216
|
+
aria-hidden="true"
|
|
217
|
+
className={cn(
|
|
218
|
+
LAYER,
|
|
219
|
+
"[background-image:var(--nebula-light)] motion-safe:animate-ambient-nebula-drift dark:[background-image:var(--nebula-dark)]",
|
|
220
|
+
classNames?.nebula,
|
|
221
|
+
)}
|
|
222
|
+
style={cloudStyle(c)}
|
|
223
|
+
{...props({ "data-testid": testId && `${testId}-nebula-${i}` })}
|
|
224
|
+
/>
|
|
225
|
+
))}
|
|
226
|
+
|
|
227
|
+
{/* Fainter on a light sky: dark dots at the dark sky's strength read
|
|
228
|
+
as specks rather than dust. Set on the wrapper, because the layers
|
|
229
|
+
inside animate their own opacity. */}
|
|
230
|
+
<div
|
|
231
|
+
aria-hidden="true"
|
|
232
|
+
className={cn(LAYER, "inset-0 opacity-70 dark:opacity-100", HALO_THEME, classNames?.stars)}
|
|
233
|
+
{...props({ "data-testid": testId && `${testId}-stars` })}
|
|
234
|
+
>
|
|
235
|
+
<svg aria-hidden="true" className="absolute size-0">
|
|
236
|
+
<defs>
|
|
237
|
+
{TILES.flatMap(({ size, phases }, i) =>
|
|
238
|
+
phases.map((groups, phase) => (
|
|
239
|
+
<pattern
|
|
240
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: a static, never-reordered list
|
|
241
|
+
key={`${i}-${phase}`}
|
|
242
|
+
id={`ambient-starfield-tile-${i}-${phase}`}
|
|
243
|
+
width={size}
|
|
244
|
+
height={size}
|
|
245
|
+
patternUnits="userSpaceOnUse"
|
|
246
|
+
>
|
|
247
|
+
{groups.map(([tone, stars]) => (
|
|
248
|
+
<g key={tone} className={tone}>
|
|
249
|
+
{stars.map(({ x, y, r, opacity }) => (
|
|
250
|
+
<circle key={`${x}-${y}`} cx={x} cy={y} r={r} fillOpacity={opacity} />
|
|
251
|
+
))}
|
|
252
|
+
</g>
|
|
253
|
+
))}
|
|
254
|
+
</pattern>
|
|
255
|
+
)),
|
|
256
|
+
)}
|
|
257
|
+
<radialGradient id="ambient-starfield-halo">
|
|
258
|
+
<stop offset="0%" style={{ stopColor: "var(--star-halo-core)" }} stopOpacity={0.32} />
|
|
259
|
+
<stop offset="35%" style={{ stopColor: "var(--star-halo-rim)" }} stopOpacity={0.1} />
|
|
260
|
+
<stop offset="100%" style={{ stopColor: "var(--star-halo-rim)" }} stopOpacity={0} />
|
|
261
|
+
</radialGradient>
|
|
262
|
+
</defs>
|
|
263
|
+
</svg>
|
|
264
|
+
|
|
265
|
+
{DIM_BEATS.map(({ duration, delay }, phase) => (
|
|
266
|
+
<svg
|
|
267
|
+
key={duration}
|
|
268
|
+
aria-hidden="true"
|
|
269
|
+
className="absolute inset-0 size-full motion-safe:animate-ambient-star-dim"
|
|
270
|
+
style={{ animationDuration: duration, animationDelay: delay }}
|
|
271
|
+
>
|
|
272
|
+
{TILES.map(({ size }, i) => (
|
|
273
|
+
<rect
|
|
274
|
+
key={size}
|
|
275
|
+
width="100%"
|
|
276
|
+
height="100%"
|
|
277
|
+
fill={`url(#ambient-starfield-tile-${i}-${phase})`}
|
|
278
|
+
/>
|
|
279
|
+
))}
|
|
280
|
+
</svg>
|
|
281
|
+
))}
|
|
282
|
+
|
|
283
|
+
<svg aria-hidden="true" className="absolute inset-0 size-full">
|
|
284
|
+
{BRIGHT_STARS.map(({ x, y, sparkle, delay, duration }) => (
|
|
285
|
+
<svg key={`${x}-${y}`} aria-hidden="true" x={x} y={y} overflow="visible">
|
|
286
|
+
<g
|
|
287
|
+
className="motion-safe:animate-ambient-star-twinkle"
|
|
288
|
+
style={{ animationDelay: delay, animationDuration: duration }}
|
|
289
|
+
>
|
|
290
|
+
<circle r={7} fill="url(#ambient-starfield-halo)" />
|
|
291
|
+
{sparkle ? (
|
|
292
|
+
<path
|
|
293
|
+
d={SPARKLE}
|
|
294
|
+
className="fill-purple-400 dark:fill-purple-100"
|
|
295
|
+
fillOpacity={0.4}
|
|
296
|
+
/>
|
|
297
|
+
) : null}
|
|
298
|
+
<circle r={1.1} className="fill-brand-500 dark:fill-brand-50" fillOpacity={0.85} />
|
|
299
|
+
</g>
|
|
300
|
+
</svg>
|
|
301
|
+
))}
|
|
302
|
+
</svg>
|
|
303
|
+
</div>
|
|
304
|
+
|
|
305
|
+
{/* Only where motion is welcome: a meteor standing still is a scratch. */}
|
|
306
|
+
<div
|
|
307
|
+
aria-hidden="true"
|
|
308
|
+
className={cn(
|
|
309
|
+
LAYER,
|
|
310
|
+
"ambient-starfield-meteors inset-0 hidden overflow-hidden motion-safe:block",
|
|
311
|
+
classNames?.meteors,
|
|
312
|
+
)}
|
|
313
|
+
{...props({ "data-testid": testId && `${testId}-meteors` })}
|
|
314
|
+
>
|
|
315
|
+
{METEORS.map(({ x, y, angle, duration, delay }) => (
|
|
316
|
+
// A zero-size anchor turned to the meteor's heading; the streak
|
|
317
|
+
// ends at it, head first, and flies along that heading.
|
|
318
|
+
<span
|
|
319
|
+
key={`${x}-${y}`}
|
|
320
|
+
className="absolute size-0"
|
|
321
|
+
style={{ left: x, top: y, rotate: angle }}
|
|
322
|
+
>
|
|
323
|
+
<span
|
|
324
|
+
className="absolute top-0 right-0 h-px w-28 origin-right rounded-full bg-linear-to-r from-transparent to-brand-500/50 opacity-0 motion-safe:animate-ambient-meteor dark:to-white/60"
|
|
325
|
+
style={{ animationDuration: duration, animationDelay: delay }}
|
|
326
|
+
/>
|
|
327
|
+
</span>
|
|
328
|
+
))}
|
|
329
|
+
</div>
|
|
330
|
+
</>
|
|
331
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A badge's accessible name lives on its wrapper: with a label it is one image,
|
|
3
|
+
* without one it is decoration and stays out of the accessibility tree. The
|
|
4
|
+
* SVG inside is always hidden — the wrapper already speaks for it.
|
|
5
|
+
*/
|
|
6
|
+
export function imageProps(label: string | undefined) {
|
|
7
|
+
return label
|
|
8
|
+
? ({ role: "img", "aria-label": label } as const)
|
|
9
|
+
: ({ "aria-hidden": true } as const)
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type BadgeBaseProps, BadgeFrame } from "./badge-frame"
|
|
2
|
+
import { GEOMETRY } from "./geometry"
|
|
3
|
+
|
|
4
|
+
export type ActivityBadgeProps = BadgeBaseProps
|
|
5
|
+
|
|
6
|
+
/** An activity (rush, workshop, event): the octahedron in a diamond. Completed is blue — you take part in an activity, you don't validate it. */
|
|
7
|
+
export function ActivityBadge(props: ActivityBadgeProps) {
|
|
8
|
+
return (
|
|
9
|
+
<BadgeFrame
|
|
10
|
+
{...props}
|
|
11
|
+
tile={{ kind: "polygon", points: GEOMETRY.tiles.diamond }}
|
|
12
|
+
solids={[GEOMETRY.activity]}
|
|
13
|
+
doneHue="blue"
|
|
14
|
+
locked="silhouette"
|
|
15
|
+
/>
|
|
16
|
+
)
|
|
17
|
+
}
|