@42-central/ui-react 0.20.2 → 0.23.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 (137) hide show
  1. package/dist/{chunk-45QRQKRC.js → chunk-3L5GLI67.js} +12 -8
  2. package/dist/chunk-3L5GLI67.js.map +1 -0
  3. package/dist/{chunk-C74TV64U.js → chunk-4FEOMQYR.js} +4 -4
  4. package/dist/{chunk-C74TV64U.js.map → chunk-4FEOMQYR.js.map} +1 -1
  5. package/dist/{chunk-LFQDB5OD.js → chunk-D3JYDAUZ.js} +3 -3
  6. package/dist/{chunk-LFQDB5OD.js.map → chunk-D3JYDAUZ.js.map} +1 -1
  7. package/dist/{chunk-UVQXRDRO.js → chunk-DHJB4UJD.js} +3 -3
  8. package/dist/{chunk-UVQXRDRO.js.map → chunk-DHJB4UJD.js.map} +1 -1
  9. package/dist/{chunk-UCCJUFOG.js → chunk-F2FSHVO5.js} +3 -3
  10. package/dist/{chunk-UCCJUFOG.js.map → chunk-F2FSHVO5.js.map} +1 -1
  11. package/dist/{chunk-Z4MBCKG5.js → chunk-FB2G4LNH.js} +4 -4
  12. package/dist/{chunk-Z4MBCKG5.js.map → chunk-FB2G4LNH.js.map} +1 -1
  13. package/dist/{chunk-FDCPMUJK.js → chunk-IRNF274I.js} +3 -3
  14. package/dist/chunk-IRNF274I.js.map +1 -0
  15. package/dist/{chunk-O5W3QWJ6.js → chunk-J44FJ7PH.js} +3 -3
  16. package/dist/{chunk-O5W3QWJ6.js.map → chunk-J44FJ7PH.js.map} +1 -1
  17. package/dist/{chunk-WXL5RP6P.js → chunk-MRAJ45IM.js} +3 -3
  18. package/dist/{chunk-WXL5RP6P.js.map → chunk-MRAJ45IM.js.map} +1 -1
  19. package/dist/{chunk-45TG7H5Q.js → chunk-OZMSXYBX.js} +3 -3
  20. package/dist/{chunk-45TG7H5Q.js.map → chunk-OZMSXYBX.js.map} +1 -1
  21. package/dist/{chunk-37VQGKD6.js → chunk-SZEOTXRZ.js} +4 -4
  22. package/dist/{chunk-37VQGKD6.js.map → chunk-SZEOTXRZ.js.map} +1 -1
  23. package/dist/{chunk-2BNIHOMT.js → chunk-YPFSRZ3T.js} +3 -3
  24. package/dist/{chunk-2BNIHOMT.js.map → chunk-YPFSRZ3T.js.map} +1 -1
  25. package/dist/{chunk-5CNVVA7I.js → chunk-YWTOW7PZ.js} +4 -4
  26. package/dist/{chunk-5CNVVA7I.js.map → chunk-YWTOW7PZ.js.map} +1 -1
  27. package/dist/components/autocomplete/index.js +2 -2
  28. package/dist/components/calendar-heatmap/calendar-heatmap-grid.d.ts +94 -0
  29. package/dist/components/calendar-heatmap/calendar-heatmap-grid.d.ts.map +1 -0
  30. package/dist/components/calendar-heatmap/calendar-heatmap.d.ts +76 -0
  31. package/dist/components/calendar-heatmap/calendar-heatmap.d.ts.map +1 -0
  32. package/dist/components/calendar-heatmap/index.d.ts +2 -0
  33. package/dist/components/calendar-heatmap/index.d.ts.map +1 -0
  34. package/dist/components/calendar-heatmap/index.js +311 -0
  35. package/dist/components/calendar-heatmap/index.js.map +1 -0
  36. package/dist/components/camera/index.js +4 -4
  37. package/dist/components/clipboard/index.js +1 -1
  38. package/dist/components/combobox/index.js +2 -2
  39. package/dist/components/combobox-list/index.js +4 -4
  40. package/dist/components/data-table/index.js +13 -13
  41. package/dist/components/date-picker/index.js +5 -5
  42. package/dist/components/geodesic/a11y.d.ts +15 -0
  43. package/dist/components/geodesic/a11y.d.ts.map +1 -0
  44. package/dist/components/geodesic/activity-badge.d.ts +5 -0
  45. package/dist/components/geodesic/activity-badge.d.ts.map +1 -0
  46. package/dist/components/geodesic/badge-frame.d.ts +60 -0
  47. package/dist/components/geodesic/badge-frame.d.ts.map +1 -0
  48. package/dist/components/geodesic/exam-badge.d.ts +5 -0
  49. package/dist/components/geodesic/exam-badge.d.ts.map +1 -0
  50. package/dist/components/geodesic/geometry.d.ts +1089 -0
  51. package/dist/components/geodesic/geometry.d.ts.map +1 -0
  52. package/dist/components/geodesic/gift-box-badge.d.ts +5 -0
  53. package/dist/components/geodesic/gift-box-badge.d.ts.map +1 -0
  54. package/dist/components/geodesic/gift-token.d.ts +23 -0
  55. package/dist/components/geodesic/gift-token.d.ts.map +1 -0
  56. package/dist/components/geodesic/glyph-slot.d.ts +8 -0
  57. package/dist/components/geodesic/glyph-slot.d.ts.map +1 -0
  58. package/dist/components/geodesic/index.d.ts +12 -0
  59. package/dist/components/geodesic/index.d.ts.map +1 -0
  60. package/dist/components/geodesic/index.js +917 -0
  61. package/dist/components/geodesic/index.js.map +1 -0
  62. package/dist/components/geodesic/module-badge.d.ts +5 -0
  63. package/dist/components/geodesic/module-badge.d.ts.map +1 -0
  64. package/dist/components/geodesic/planet.d.ts +30 -0
  65. package/dist/components/geodesic/planet.d.ts.map +1 -0
  66. package/dist/components/geodesic/project-badge.d.ts +5 -0
  67. package/dist/components/geodesic/project-badge.d.ts.map +1 -0
  68. package/dist/components/geodesic/skill-badge.d.ts +5 -0
  69. package/dist/components/geodesic/skill-badge.d.ts.map +1 -0
  70. package/dist/components/geodesic/social-badge.d.ts +8 -0
  71. package/dist/components/geodesic/social-badge.d.ts.map +1 -0
  72. package/dist/components/geodesic/status.d.ts +80 -0
  73. package/dist/components/geodesic/status.d.ts.map +1 -0
  74. package/dist/components/geodesic/styles.css +146 -0
  75. package/dist/components/input/index.js +1 -1
  76. package/dist/components/input/input.d.ts.map +1 -1
  77. package/dist/components/menu/index.js +1 -1
  78. package/dist/components/menu/menu.d.ts +7 -5
  79. package/dist/components/menu/menu.d.ts.map +1 -1
  80. package/dist/components/multi-combobox-list/index.js +4 -4
  81. package/dist/components/multi-select/index.js +3 -3
  82. package/dist/components/navigation-progress/index.d.ts +2 -0
  83. package/dist/components/navigation-progress/index.d.ts.map +1 -0
  84. package/dist/components/navigation-progress/index.js +133 -0
  85. package/dist/components/navigation-progress/index.js.map +1 -0
  86. package/dist/components/navigation-progress/navigation-progress.d.ts +46 -0
  87. package/dist/components/navigation-progress/navigation-progress.d.ts.map +1 -0
  88. package/dist/components/number-input/index.js +2 -2
  89. package/dist/components/number-input/number-input.d.ts.map +1 -1
  90. package/dist/components/password-input/index.js +1 -1
  91. package/dist/components/photo-capture/index.js +4 -4
  92. package/dist/components/pills-input/index.js +2 -2
  93. package/dist/components/pin-input/index.js +1 -1
  94. package/dist/components/select/index.js +3 -3
  95. package/dist/components/spotlight/index.js +3 -3
  96. package/dist/components/tags-input/index.js +2 -2
  97. package/dist/components/text-input/index.js +1 -1
  98. package/dist/components/textarea/index.js +1 -1
  99. package/dist/components/time-input/index.js +3 -3
  100. package/dist/components/tree-multi-select/index.js +3 -3
  101. package/dist/components/tree-select/index.js +2 -2
  102. package/dist/index.js +2 -2
  103. package/package.json +2 -1
  104. package/src/as-child.contract.test.tsx +6 -0
  105. package/src/components/calendar-heatmap/calendar-heatmap-grid.test.ts +186 -0
  106. package/src/components/calendar-heatmap/calendar-heatmap-grid.ts +192 -0
  107. package/src/components/calendar-heatmap/calendar-heatmap.test.tsx +180 -0
  108. package/src/components/calendar-heatmap/calendar-heatmap.tsx +385 -0
  109. package/src/components/calendar-heatmap/index.ts +11 -0
  110. package/src/components/geodesic/a11y.ts +10 -0
  111. package/src/components/geodesic/activity-badge.tsx +17 -0
  112. package/src/components/geodesic/badge-frame.tsx +324 -0
  113. package/src/components/geodesic/exam-badge.tsx +17 -0
  114. package/src/components/geodesic/geometry.test.ts +60 -0
  115. package/src/components/geodesic/geometry.ts +367 -0
  116. package/src/components/geodesic/gift-box-badge.tsx +17 -0
  117. package/src/components/geodesic/gift-token.tsx +104 -0
  118. package/src/components/geodesic/glyph-slot.tsx +28 -0
  119. package/src/components/geodesic/index.ts +13 -0
  120. package/src/components/geodesic/module-badge.tsx +17 -0
  121. package/src/components/geodesic/planet.tsx +131 -0
  122. package/src/components/geodesic/project-badge.tsx +17 -0
  123. package/src/components/geodesic/skill-badge.tsx +17 -0
  124. package/src/components/geodesic/social-badge.tsx +21 -0
  125. package/src/components/geodesic/status.test.ts +66 -0
  126. package/src/components/geodesic/status.ts +176 -0
  127. package/src/components/geodesic/styles.css +146 -0
  128. package/src/components/input/input.test.tsx +23 -0
  129. package/src/components/input/input.tsx +10 -6
  130. package/src/components/menu/menu.tsx +16 -9
  131. package/src/components/navigation-progress/index.ts +14 -0
  132. package/src/components/navigation-progress/navigation-progress.test.tsx +184 -0
  133. package/src/components/navigation-progress/navigation-progress.tsx +228 -0
  134. package/src/components/number-input/number-input.tsx +3 -4
  135. package/src/icon-stroke.test.tsx +5 -0
  136. package/dist/chunk-45QRQKRC.js.map +0 -1
  137. package/dist/chunk-FDCPMUJK.js.map +0 -1
@@ -0,0 +1,324 @@
1
+ "use client"
2
+
3
+ import { type CSSProperties, type SVGProps, useEffect, useId, useState } from "react"
4
+ import { cn } from "../../lib/cn"
5
+ import { props as attrs } from "../../lib/props"
6
+ import type { WithTestId } from "../../lib/test-id"
7
+ import { imageProps } from "./a11y"
8
+ import {
9
+ type BadgeStatus,
10
+ faceFill,
11
+ fillLevel,
12
+ type Hue,
13
+ hueOf,
14
+ liquidFadeWidth,
15
+ paint,
16
+ type Tone,
17
+ tint,
18
+ } from "./status"
19
+
20
+ /** The shape every generated solid has (see `packages/react/scripts/generate-geometry.ts`). */
21
+ export type SolidData = {
22
+ readonly facets: readonly {
23
+ readonly points: string
24
+ readonly tone: Tone
25
+ readonly rank: number
26
+ }[]
27
+ readonly edges: string
28
+ readonly hidden: string
29
+ readonly hull: string
30
+ readonly details: string
31
+ }
32
+
33
+ export type BadgeTile =
34
+ | { readonly kind: "circle" }
35
+ | { readonly kind: "polygon"; readonly points: string }
36
+
37
+ /** Props every badge shares. */
38
+ export type BadgeBaseProps = WithTestId & {
39
+ status: BadgeStatus
40
+ /**
41
+ * Completion while `in-progress`, 0–100: fills the solid from the bottom
42
+ * up, each face from its own base through a soft gradient, animating
43
+ * between values. 0–100 is drawn as 15–100% of the fill, so
44
+ * started work always shows light. Ignored in other statuses. Defaults to 50.
45
+ */
46
+ progress?: number
47
+ /** Rendered width and height, in px. */
48
+ size?: number
49
+ /** Accessible name. Without one the badge is decorative and hidden from assistive tech. */
50
+ label?: string
51
+ className?: string
52
+ style?: CSSProperties
53
+ }
54
+
55
+ type BadgeFrameProps = BadgeBaseProps & {
56
+ tile: BadgeTile
57
+ solids: readonly SolidData[]
58
+ doneHue: Hue
59
+ /**
60
+ * How a locked badge shows its solid: the module keeps its wireframe, the
61
+ * other shapes collapse to a dotted silhouette.
62
+ */
63
+ locked: "wire" | "silhouette"
64
+ /** Dotted connectors drawn between the solids (the social badge). */
65
+ links?: string
66
+ }
67
+
68
+ const VIEWBOX = "0 0 64 64"
69
+ const DASH = "3 2"
70
+ const DOT = "0.1 1.6"
71
+
72
+ function Tile({ tile, ...paint }: { tile: BadgeTile } & SVGProps<SVGCircleElement>) {
73
+ if (tile.kind === "circle") return <circle cx={32} cy={32} r={29} {...paint} />
74
+ return <polygon points={tile.points} {...(paint as SVGProps<SVGPolygonElement>)} />
75
+ }
76
+
77
+ /**
78
+ * A padlock on a dark plate, set in a soft shade of the page's own body
79
+ * colour (brand-950 on a dark page, brand-25 on a light one) that clears
80
+ * the wireframe or silhouette behind it, so the lock reads on its own. It is
81
+ * a radial gradient rather than a blur filter: it renders the same in every
82
+ * browser and costs nothing to draw.
83
+ */
84
+ function Lock({ shown }: { shown: boolean }) {
85
+ // useId's characters are not all valid in a `url(#…)` reference.
86
+ const glow = `geodesic-lock-glow-${useId().replace(/[^\w-]/g, "")}`
87
+ const shade = paint("brand", [950, 25])
88
+ // Always mounted, faded in and out, so unlocking eases instead of popping.
89
+ return (
90
+ <g className="geodesic-crossfade geodesic-lock" data-shown={shown}>
91
+ <defs>
92
+ <radialGradient id={glow}>
93
+ <stop offset="0" stopColor={shade} stopOpacity={1} />
94
+ <stop offset="0.55" stopColor={shade} stopOpacity={0.8} />
95
+ <stop offset="1" stopColor={shade} stopOpacity={0} />
96
+ </radialGradient>
97
+ </defs>
98
+ <circle cx={32} cy={33} r={15} fill={`url(#${glow})`} />
99
+ {/* An icon, so a 1.5px stroke at any badge size, like the slotted glyphs. */}
100
+ <g
101
+ fill="none"
102
+ stroke={paint("neutral", [25, 700])}
103
+ strokeWidth={1.5}
104
+ strokeLinecap="round"
105
+ strokeLinejoin="round"
106
+ >
107
+ <rect
108
+ x={27}
109
+ y={31}
110
+ width={10}
111
+ height={8}
112
+ rx={1.6}
113
+ fill={paint("neutral", [950, 25], 85)}
114
+ vectorEffect="non-scaling-stroke"
115
+ />
116
+ {/* Filled like the body, so the wireframe behind does not show through the loop. */}
117
+ <path
118
+ d="M29 31v-2.4a3 3 0 0 1 6 0V31"
119
+ fill={paint("neutral", [950, 25], 85)}
120
+ vectorEffect="non-scaling-stroke"
121
+ />
122
+ </g>
123
+ </g>
124
+ )
125
+ }
126
+
127
+ function Solid({
128
+ solid,
129
+ status,
130
+ hue,
131
+ progress,
132
+ locked,
133
+ }: {
134
+ solid: SolidData
135
+ status: BadgeStatus
136
+ hue: Hue
137
+ progress: number
138
+ locked: "wire" | "silhouette"
139
+ }) {
140
+ const lit = <LiquidSolid solid={solid} status={status} hue={hue} progress={progress} />
141
+ if (locked === "wire") return lit
142
+ // The silhouette and the solid are both kept mounted and cross-faded, so
143
+ // locking and unlocking ease like every other status change.
144
+ const silhouette = status === "locked"
145
+ return (
146
+ <>
147
+ <polygon
148
+ className="geodesic-crossfade"
149
+ data-shown={silhouette}
150
+ points={solid.hull}
151
+ fill={paint("neutral", [900, 100], 70)}
152
+ stroke={paint("neutral", [400, 400])}
153
+ strokeWidth={0.8}
154
+ strokeDasharray={DOT}
155
+ strokeLinecap="round"
156
+ />
157
+ <g className="geodesic-crossfade" data-shown={!silhouette}>
158
+ {lit}
159
+ </g>
160
+ </>
161
+ )
162
+ }
163
+
164
+ type SolidProps = { solid: SolidData; status: BadgeStatus; hue: Hue; progress: number }
165
+
166
+ /** The visible edges, and the hidden ones dotted until the badge is done. */
167
+ function Wires({ solid, status, hue }: Omit<SolidProps, "progress">) {
168
+ const done = status === "done"
169
+ // Done glints over its own faces, the same on either page; the bare
170
+ // wireframe takes one step darker on a light page, just enough to show.
171
+ const wire = done
172
+ ? paint(hue, [200, 200], 50)
173
+ : paint(hue, status === "locked" ? [400, 400] : [200, 400])
174
+ return (
175
+ <>
176
+ {!done && solid.hidden && (
177
+ <path
178
+ d={solid.hidden}
179
+ fill="none"
180
+ stroke={wire}
181
+ strokeOpacity={0.55}
182
+ strokeWidth={0.5}
183
+ strokeDasharray={DOT}
184
+ strokeLinecap="round"
185
+ />
186
+ )}
187
+ <path
188
+ d={solid.edges + solid.details}
189
+ fill="none"
190
+ stroke={wire}
191
+ strokeWidth={0.55}
192
+ strokeLinejoin="round"
193
+ />
194
+ </>
195
+ )
196
+ }
197
+
198
+ /** Starts at `from` and moves to `target` on the next frame, so CSS can transition it. */
199
+ export function useSettled<T>(from: T, target: T) {
200
+ const [value, setValue] = useState(from)
201
+ useEffect(() => {
202
+ const frame = requestAnimationFrame(() => setValue(target))
203
+ return () => cancelAnimationFrame(frame)
204
+ }, [target])
205
+ return value
206
+ }
207
+
208
+ /**
209
+ * How progress fills a solid: a registered CSS property (`--geodesic-level`),
210
+ * transitioned by CSS, is how many faces along the bottom-up order are lit,
211
+ * and each face fills from its own base to its top through a soft gradient
212
+ * mask. One gradient rule serves every face: a CSS mask on an SVG shape is
213
+ * laid out on that shape's bounding box (see styles.css). The first frame
214
+ * renders nothing lit, so a badge fills up when it appears too.
215
+ */
216
+ function LiquidSolid({ solid, status, hue, progress }: SolidProps) {
217
+ const faces = solid.facets.length
218
+ const fade = liquidFadeWidth(faces)
219
+ const level = useSettled(0, fillLevel(status, progress, faces, fade))
220
+ return (
221
+ <g
222
+ className="geodesic-solid-smooth"
223
+ style={{ "--geodesic-level": level, "--geodesic-fade": fade } as CSSProperties}
224
+ >
225
+ {solid.facets.map((facet) => (
226
+ <polygon
227
+ key={facet.points}
228
+ className="geodesic-facet-liquid"
229
+ points={facet.points}
230
+ fill={faceFill(hue, status, facet.tone)}
231
+ style={{ "--geodesic-rank": facet.rank } as CSSProperties}
232
+ />
233
+ ))}
234
+ <Wires solid={solid} status={status} hue={hue} />
235
+ </g>
236
+ )
237
+ }
238
+
239
+ /**
240
+ * Draws any statused badge: a tile, one or more solids, and what the status
241
+ * adds (lock, glow). The per-shape components only pick the geometry
242
+ * and the done hue.
243
+ */
244
+ export function BadgeFrame({
245
+ status,
246
+ size = 64,
247
+ label,
248
+ className,
249
+ style,
250
+ testId,
251
+ tile,
252
+ solids,
253
+ doneHue,
254
+ progress = 50,
255
+ locked,
256
+ links,
257
+ }: BadgeFrameProps) {
258
+ const hue = hueOf(status, doneHue)
259
+ const done = status === "done"
260
+ const tileFill =
261
+ // Locked is a fully transparent tint, not `none`, so the fill can ease in.
262
+ paint(hue, [500, 500], status === "locked" ? 0 : done ? 20 : status === "available" ? 22 : 16)
263
+ const tileStroke =
264
+ status === "locked"
265
+ ? paint("neutral", [500, 400])
266
+ : done
267
+ ? paint(hue, [400, 400])
268
+ : paint(hue, [400, 400], 65)
269
+
270
+ return (
271
+ <span
272
+ className={cn("geodesic-badge", className)}
273
+ {...imageProps(label)}
274
+ {...attrs({ "data-testid": testId })}
275
+ style={{
276
+ display: "inline-grid",
277
+ width: size,
278
+ height: size,
279
+ flex: "none",
280
+ filter: done ? `drop-shadow(0 0 ${size * 0.09}px ${tint(hue, 500, 55)})` : undefined,
281
+ ...style,
282
+ }}
283
+ >
284
+ <svg
285
+ aria-hidden="true"
286
+ viewBox={VIEWBOX}
287
+ width={size}
288
+ height={size}
289
+ style={{ gridArea: "1 / 1", display: "block" }}
290
+ >
291
+ <Tile
292
+ tile={tile}
293
+ fill={tileFill}
294
+ stroke={tileStroke}
295
+ strokeWidth={1}
296
+ strokeDasharray={done ? undefined : DASH}
297
+ strokeLinejoin="round"
298
+ />
299
+ {links && (
300
+ <path
301
+ d={links}
302
+ fill="none"
303
+ stroke={paint(hue, [300, 300])}
304
+ strokeOpacity={0.6}
305
+ strokeWidth={0.6}
306
+ strokeDasharray={DOT}
307
+ strokeLinecap="round"
308
+ />
309
+ )}
310
+ {solids.map((solid) => (
311
+ <Solid
312
+ key={solid.hull}
313
+ solid={solid}
314
+ status={status}
315
+ hue={hue}
316
+ progress={progress}
317
+ locked={locked}
318
+ />
319
+ ))}
320
+ <Lock shown={status === "locked"} />
321
+ </svg>
322
+ </span>
323
+ )
324
+ }
@@ -0,0 +1,17 @@
1
+ import { type BadgeBaseProps, BadgeFrame } from "./badge-frame"
2
+ import { GEOMETRY } from "./geometry"
3
+
4
+ export type ExamBadgeProps = BadgeBaseProps
5
+
6
+ /** An exam: the tetrahedron in a triangle. Validated, gold. */
7
+ export function ExamBadge(props: ExamBadgeProps) {
8
+ return (
9
+ <BadgeFrame
10
+ {...props}
11
+ tile={{ kind: "polygon", points: GEOMETRY.tiles.triangle }}
12
+ solids={[GEOMETRY.exam]}
13
+ doneHue="yellow"
14
+ locked="silhouette"
15
+ />
16
+ )
17
+ }
@@ -0,0 +1,60 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import { GEOMETRY } from "./geometry"
3
+
4
+ const parse = (points: string) =>
5
+ points.split(" ").map((p) => {
6
+ const [x = 0, y = 0] = p.split(",").map(Number)
7
+ return [x, y] as const
8
+ })
9
+
10
+ const centroidY = (points: string) => {
11
+ const ys = parse(points).map(([, y]) => y)
12
+ return ys.reduce((a, b) => a + b, 0) / ys.length
13
+ }
14
+
15
+ /** Twice the signed area; positive is clockwise on screen (y points down). */
16
+ const signedArea = (points: string) => {
17
+ const p = parse(points)
18
+ return p.reduce((sum, [x, y], i) => {
19
+ const [nx, ny] = p[(i + 1) % p.length] ?? [x, y]
20
+ return sum + (x * ny - nx * y)
21
+ }, 0)
22
+ }
23
+
24
+ describe("geodesic geometry", () => {
25
+ const solids = {
26
+ module: GEOMETRY.module,
27
+ project: GEOMETRY.project,
28
+ exam: GEOMETRY.exam,
29
+ activity: GEOMETRY.activity,
30
+ skill: GEOMETRY.skill,
31
+ gift: GEOMETRY.gift,
32
+ }
33
+
34
+ it.each(Object.entries(solids))("%s ranks every facet once, bottom first", (_, solid) => {
35
+ const ranks = solid.facets.map((f) => f.rank).sort((a, b) => a - b)
36
+ expect(ranks).toEqual(solid.facets.map((_, i) => i))
37
+ const heights = [...solid.facets]
38
+ .sort((a, b) => a.rank - b.rank)
39
+ .map((facet) => centroidY(facet.points))
40
+ for (const [i, height] of heights.entries())
41
+ if (i > 0) expect(height).toBeLessThanOrEqual((heights[i - 1] ?? height) + 1e-9)
42
+ })
43
+
44
+ it.each(Object.entries(solids))("%s keeps only facets turned to the viewer", (_, solid) => {
45
+ const signs = solid.facets.map((f) => Math.sign(signedArea(f.points)))
46
+ expect(new Set(signs).size).toBe(1)
47
+ })
48
+
49
+ it("fits every solid inside the 64×64 viewBox", () => {
50
+ const all = [...Object.values(solids), ...GEOMETRY.social].flatMap((s) =>
51
+ s.facets.flatMap((f) => parse(f.points)),
52
+ )
53
+ for (const [x, y] of all) {
54
+ expect(x).toBeGreaterThanOrEqual(0)
55
+ expect(x).toBeLessThanOrEqual(64)
56
+ expect(y).toBeGreaterThanOrEqual(0)
57
+ expect(y).toBeLessThanOrEqual(64)
58
+ }
59
+ })
60
+ })