@nakafa/aksara-contracts 8.4.1 → 8.8.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 (47) hide show
  1. package/dist/hash/sha256.d.ts +16 -0
  2. package/dist/hash/sha256.js +164 -0
  3. package/dist/hash/stream.d.ts +7 -5
  4. package/dist/hash/stream.js +13 -18
  5. package/dist/math/boundary.js +3 -22
  6. package/dist/math/edge.d.ts +11 -0
  7. package/dist/math/edge.js +74 -0
  8. package/dist/math/graph.d.ts +9 -0
  9. package/dist/math/graph.js +66 -0
  10. package/dist/math/plane.js +6 -0
  11. package/dist/math/shape.d.ts +392 -0
  12. package/dist/math/shape.js +59 -0
  13. package/dist/math/straight.d.ts +13 -0
  14. package/dist/math/straight.js +26 -0
  15. package/dist/visual/biology/blood.d.ts +91 -0
  16. package/dist/visual/biology/blood.js +55 -0
  17. package/dist/visual/biology/heart.d.ts +92 -0
  18. package/dist/visual/biology/heart.js +54 -0
  19. package/dist/visual/biology/mitochondrion.d.ts +91 -0
  20. package/dist/visual/biology/mitochondrion.js +45 -0
  21. package/dist/visual/biology/muscle.d.ts +103 -0
  22. package/dist/visual/biology/muscle.js +62 -0
  23. package/dist/visual/biology/neuron.d.ts +97 -0
  24. package/dist/visual/biology/neuron.js +48 -0
  25. package/dist/visual/biology/paddy.d.ts +100 -0
  26. package/dist/visual/biology/paddy.js +54 -0
  27. package/dist/visual/biology/synapse.d.ts +101 -0
  28. package/dist/visual/biology/synapse.js +46 -0
  29. package/dist/visual/biology/vessel.d.ts +104 -0
  30. package/dist/visual/biology/vessel.js +60 -0
  31. package/dist/visual/biology/yeast.d.ts +108 -0
  32. package/dist/visual/biology/yeast.js +61 -0
  33. package/dist/visual/catalog.d.ts +2177 -778
  34. package/dist/visual/catalog.js +28 -0
  35. package/dist/visual/mathematics/journey.d.ts +118 -0
  36. package/dist/visual/mathematics/journey.js +125 -0
  37. package/dist/visual/mathematics/logic.d.ts +90 -0
  38. package/dist/visual/mathematics/logic.js +49 -0
  39. package/dist/visual/mathematics/network.d.ts +101 -0
  40. package/dist/visual/mathematics/network.js +97 -0
  41. package/dist/visual/mathematics/numeral.d.ts +81 -0
  42. package/dist/visual/mathematics/numeral.js +48 -0
  43. package/dist/visual/mathematics/sets.d.ts +92 -0
  44. package/dist/visual/mathematics/sets.js +95 -0
  45. package/dist/visual/physics/thermodynamics.d.ts +117 -0
  46. package/dist/visual/physics/thermodynamics.js +95 -0
  47. package/package.json +1 -1
@@ -0,0 +1,392 @@
1
+ import type { Schema } from "effect";
2
+ import type { PlaneMathFrame, PlaneMathObject, PlaneMathView } from "#contracts/math/plane";
3
+ /**
4
+ * The plane objects whose meaning is their shape: a circle is round, an arc's
5
+ * angle is true, a polygon's sides keep their proportion, and a vector or a
6
+ * ray points the way it is drawn. A parametric curve counts, because circles
7
+ * and angle marks are drawn with it. A scene that draws one keeps one scale on
8
+ * both axes; any other plane scene is a graph, which may scale each axis on
9
+ * its own.
10
+ */
11
+ export declare const PLANE_FIGURE_KINDS: readonly ["arc", "circle", "implicit", "parametric", "polar", "polygon", "ray", "vector"];
12
+ /** Whether a plane scene keeps one scale on both axes, because it draws a figure. */
13
+ export declare function keepsShape(objects: readonly PlaneMathObject[]): objects is readonly [{
14
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
15
+ readonly id: string;
16
+ readonly kind: "parametric";
17
+ readonly parameter: {
18
+ readonly max: number;
19
+ readonly min: number;
20
+ };
21
+ readonly x: string;
22
+ readonly y: string;
23
+ } | {
24
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
25
+ readonly id: string;
26
+ readonly angle: {
27
+ readonly max: number;
28
+ readonly min: number;
29
+ };
30
+ readonly kind: "polar";
31
+ readonly radius: string;
32
+ } | {
33
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
34
+ readonly id: string;
35
+ readonly equation: string;
36
+ readonly kind: "implicit";
37
+ } | {
38
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
39
+ readonly id: string;
40
+ readonly inequalities: readonly [string, ...string[]];
41
+ readonly kind: "region";
42
+ } | {
43
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
44
+ readonly id: string;
45
+ readonly kind: "marker";
46
+ readonly x: string;
47
+ readonly y: string;
48
+ } | {
49
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
50
+ readonly id: string;
51
+ readonly kind: "path";
52
+ readonly points: readonly {
53
+ readonly x: string;
54
+ readonly y: string;
55
+ }[];
56
+ } | {
57
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
58
+ readonly id: string;
59
+ readonly kind: "loop";
60
+ readonly points: readonly {
61
+ readonly x: string;
62
+ readonly y: string;
63
+ }[];
64
+ } | {
65
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
66
+ readonly id: string;
67
+ readonly at: {
68
+ readonly x: number;
69
+ readonly y: number;
70
+ };
71
+ readonly kind: "point";
72
+ } | {
73
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
74
+ readonly id: string;
75
+ readonly from: {
76
+ readonly x: number;
77
+ readonly y: number;
78
+ };
79
+ readonly kind: "vector";
80
+ readonly to: {
81
+ readonly x: number;
82
+ readonly y: number;
83
+ };
84
+ } | {
85
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
86
+ readonly id: string;
87
+ readonly kind: "polygon";
88
+ readonly vertices: readonly [{
89
+ readonly x: number;
90
+ readonly y: number;
91
+ }, {
92
+ readonly x: number;
93
+ readonly y: number;
94
+ }, {
95
+ readonly x: number;
96
+ readonly y: number;
97
+ }, ...{
98
+ readonly x: number;
99
+ readonly y: number;
100
+ }[]];
101
+ } | {
102
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
103
+ readonly id: string;
104
+ readonly center: {
105
+ readonly x: number;
106
+ readonly y: number;
107
+ };
108
+ readonly kind: "circle";
109
+ readonly radius: number;
110
+ } | {
111
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
112
+ readonly id: string;
113
+ readonly center: {
114
+ readonly x: number;
115
+ readonly y: number;
116
+ };
117
+ readonly kind: "arc";
118
+ readonly radius: number;
119
+ readonly startDegrees: number;
120
+ readonly sweepDegrees: number;
121
+ } | {
122
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
123
+ readonly id: string;
124
+ readonly coefficients: {
125
+ readonly a: number;
126
+ readonly b: number;
127
+ readonly c: number;
128
+ };
129
+ readonly domain: {
130
+ readonly max: number;
131
+ readonly min: number;
132
+ };
133
+ readonly inputAxis: "x" | "y";
134
+ readonly kind: "quadratic";
135
+ } | {
136
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
137
+ readonly id: string;
138
+ readonly stroke?: "dashed";
139
+ readonly domain?: {
140
+ readonly max: number;
141
+ readonly min: number;
142
+ };
143
+ readonly formula: string;
144
+ readonly inputAxis?: "x" | "y";
145
+ readonly kind: "function";
146
+ } | {
147
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
148
+ readonly id: string;
149
+ readonly stroke?: "dashed";
150
+ readonly kind: "line";
151
+ readonly through: readonly [{
152
+ readonly x: number;
153
+ readonly y: number;
154
+ }, {
155
+ readonly x: number;
156
+ readonly y: number;
157
+ }];
158
+ } | {
159
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
160
+ readonly id: string;
161
+ readonly stroke?: "dashed";
162
+ readonly from: {
163
+ readonly x: number;
164
+ readonly y: number;
165
+ };
166
+ readonly kind: "ray";
167
+ readonly through: {
168
+ readonly x: number;
169
+ readonly y: number;
170
+ };
171
+ } | {
172
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
173
+ readonly id: string;
174
+ readonly stroke?: "dashed";
175
+ readonly from: {
176
+ readonly x: number;
177
+ readonly y: number;
178
+ };
179
+ readonly kind: "segment";
180
+ readonly to: {
181
+ readonly x: number;
182
+ readonly y: number;
183
+ };
184
+ } | {
185
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
186
+ readonly id: string;
187
+ readonly stroke?: "dashed";
188
+ readonly kind: "polyline";
189
+ readonly vertices: readonly [{
190
+ readonly x: number;
191
+ readonly y: number;
192
+ }, {
193
+ readonly x: number;
194
+ readonly y: number;
195
+ }, ...{
196
+ readonly x: number;
197
+ readonly y: number;
198
+ }[]];
199
+ }, ...({
200
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
201
+ readonly id: string;
202
+ readonly kind: "parametric";
203
+ readonly parameter: {
204
+ readonly max: number;
205
+ readonly min: number;
206
+ };
207
+ readonly x: string;
208
+ readonly y: string;
209
+ } | {
210
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
211
+ readonly id: string;
212
+ readonly angle: {
213
+ readonly max: number;
214
+ readonly min: number;
215
+ };
216
+ readonly kind: "polar";
217
+ readonly radius: string;
218
+ } | {
219
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
220
+ readonly id: string;
221
+ readonly equation: string;
222
+ readonly kind: "implicit";
223
+ } | {
224
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
225
+ readonly id: string;
226
+ readonly inequalities: readonly [string, ...string[]];
227
+ readonly kind: "region";
228
+ } | {
229
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
230
+ readonly id: string;
231
+ readonly kind: "marker";
232
+ readonly x: string;
233
+ readonly y: string;
234
+ } | {
235
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
236
+ readonly id: string;
237
+ readonly kind: "path";
238
+ readonly points: readonly {
239
+ readonly x: string;
240
+ readonly y: string;
241
+ }[];
242
+ } | {
243
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
244
+ readonly id: string;
245
+ readonly kind: "loop";
246
+ readonly points: readonly {
247
+ readonly x: string;
248
+ readonly y: string;
249
+ }[];
250
+ } | {
251
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
252
+ readonly id: string;
253
+ readonly at: {
254
+ readonly x: number;
255
+ readonly y: number;
256
+ };
257
+ readonly kind: "point";
258
+ } | {
259
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
260
+ readonly id: string;
261
+ readonly from: {
262
+ readonly x: number;
263
+ readonly y: number;
264
+ };
265
+ readonly kind: "vector";
266
+ readonly to: {
267
+ readonly x: number;
268
+ readonly y: number;
269
+ };
270
+ } | {
271
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
272
+ readonly id: string;
273
+ readonly kind: "polygon";
274
+ readonly vertices: readonly [{
275
+ readonly x: number;
276
+ readonly y: number;
277
+ }, {
278
+ readonly x: number;
279
+ readonly y: number;
280
+ }, {
281
+ readonly x: number;
282
+ readonly y: number;
283
+ }, ...{
284
+ readonly x: number;
285
+ readonly y: number;
286
+ }[]];
287
+ } | {
288
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
289
+ readonly id: string;
290
+ readonly center: {
291
+ readonly x: number;
292
+ readonly y: number;
293
+ };
294
+ readonly kind: "circle";
295
+ readonly radius: number;
296
+ } | {
297
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
298
+ readonly id: string;
299
+ readonly center: {
300
+ readonly x: number;
301
+ readonly y: number;
302
+ };
303
+ readonly kind: "arc";
304
+ readonly radius: number;
305
+ readonly startDegrees: number;
306
+ readonly sweepDegrees: number;
307
+ } | {
308
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
309
+ readonly id: string;
310
+ readonly coefficients: {
311
+ readonly a: number;
312
+ readonly b: number;
313
+ readonly c: number;
314
+ };
315
+ readonly domain: {
316
+ readonly max: number;
317
+ readonly min: number;
318
+ };
319
+ readonly inputAxis: "x" | "y";
320
+ readonly kind: "quadratic";
321
+ } | {
322
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
323
+ readonly id: string;
324
+ readonly stroke?: "dashed";
325
+ readonly domain?: {
326
+ readonly max: number;
327
+ readonly min: number;
328
+ };
329
+ readonly formula: string;
330
+ readonly inputAxis?: "x" | "y";
331
+ readonly kind: "function";
332
+ } | {
333
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
334
+ readonly id: string;
335
+ readonly stroke?: "dashed";
336
+ readonly kind: "line";
337
+ readonly through: readonly [{
338
+ readonly x: number;
339
+ readonly y: number;
340
+ }, {
341
+ readonly x: number;
342
+ readonly y: number;
343
+ }];
344
+ } | {
345
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
346
+ readonly id: string;
347
+ readonly stroke?: "dashed";
348
+ readonly from: {
349
+ readonly x: number;
350
+ readonly y: number;
351
+ };
352
+ readonly kind: "ray";
353
+ readonly through: {
354
+ readonly x: number;
355
+ readonly y: number;
356
+ };
357
+ } | {
358
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
359
+ readonly id: string;
360
+ readonly stroke?: "dashed";
361
+ readonly from: {
362
+ readonly x: number;
363
+ readonly y: number;
364
+ };
365
+ readonly kind: "segment";
366
+ readonly to: {
367
+ readonly x: number;
368
+ readonly y: number;
369
+ };
370
+ } | {
371
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
372
+ readonly id: string;
373
+ readonly stroke?: "dashed";
374
+ readonly kind: "polyline";
375
+ readonly vertices: readonly [{
376
+ readonly x: number;
377
+ readonly y: number;
378
+ }, {
379
+ readonly x: number;
380
+ readonly y: number;
381
+ }, ...{
382
+ readonly x: number;
383
+ readonly y: number;
384
+ }[]];
385
+ })[]];
386
+ /**
387
+ * Guardrail G1: the frame of a plane scene that keeps one scale is between
388
+ * 0.7 and 2 times as wide as it is tall, padding included. The frame is only
389
+ * the region the figure teaches, and the world continues past it, so a frame
390
+ * stretched to reach a far point only shrinks the figure.
391
+ */
392
+ export declare function figureAspectIssues(frame: PlaneMathFrame, objects: readonly PlaneMathObject[], view: PlaneMathView): readonly Schema.FilterIssue[];
@@ -0,0 +1,59 @@
1
+ import { Array as Arr } from "effect";
2
+ /**
3
+ * The plane objects whose meaning is their shape: a circle is round, an arc's
4
+ * angle is true, a polygon's sides keep their proportion, and a vector or a
5
+ * ray points the way it is drawn. A parametric curve counts, because circles
6
+ * and angle marks are drawn with it. A scene that draws one keeps one scale on
7
+ * both axes; any other plane scene is a graph, which may scale each axis on
8
+ * its own.
9
+ */
10
+ export const PLANE_FIGURE_KINDS = [
11
+ "arc",
12
+ "circle",
13
+ "implicit",
14
+ "parametric",
15
+ "polar",
16
+ "polygon",
17
+ "ray",
18
+ "vector",
19
+ ];
20
+ /** Whether a plane scene keeps one scale on both axes, because it draws a figure. */
21
+ export function keepsShape(objects) {
22
+ return Arr.some(objects, ({ kind }) => Arr.contains(PLANE_FIGURE_KINDS, kind));
23
+ }
24
+ /**
25
+ * The aspects, wide over tall and padding included, between which a frame
26
+ * kept at one scale fills a card on a phone and on a desk: a wider frame
27
+ * shrinks the figure to a strip, a taller one to a column.
28
+ */
29
+ const FIGURE_ASPECT = { max: 2, min: 0.7 };
30
+ /** A number of a frame's message, to two decimals at most. */
31
+ function short(value) {
32
+ return String(Math.round(value * 100) / 100);
33
+ }
34
+ /**
35
+ * Guardrail G1: the frame of a plane scene that keeps one scale is between
36
+ * 0.7 and 2 times as wide as it is tall, padding included. The frame is only
37
+ * the region the figure teaches, and the world continues past it, so a frame
38
+ * stretched to reach a far point only shrinks the figure.
39
+ */
40
+ export function figureAspectIssues(frame, objects, view) {
41
+ if (!keepsShape(objects)) {
42
+ return [];
43
+ }
44
+ const padding = view.padding ?? 0;
45
+ // Halves keep a frame as wide as the largest finite numbers from overflowing.
46
+ const halfWidth = frame.x.max / 2 - frame.x.min / 2 + padding;
47
+ const halfHeight = frame.y.max / 2 - frame.y.min / 2 + padding;
48
+ const aspect = halfWidth / halfHeight;
49
+ const width = 2 * halfWidth;
50
+ const height = 2 * halfHeight;
51
+ return aspect >= FIGURE_ASPECT.min && aspect <= FIGURE_ASPECT.max
52
+ ? []
53
+ : [
54
+ {
55
+ issue: `Expected the frame of a scene that keeps one scale (it draws one of: ${Arr.join(PLANE_FIGURE_KINDS, ", ")}) to be between ${FIGURE_ASPECT.min} and ${FIGURE_ASPECT.max} times as wide as it is tall, padding included; this frame is ${short(width)} by ${short(height)} (${short(aspect)}). Frame the region the figure teaches: the grid, the axes and every unbounded object continue past it.`,
56
+ path: ["frame"],
57
+ },
58
+ ];
59
+ }
@@ -0,0 +1,13 @@
1
+ import { Option } from "effect";
2
+ import type { PlaneMathObject } from "#contracts/math/plane";
3
+ /**
4
+ * Two points of a straight object of a plane scene, which name the line it
5
+ * runs along: a line, ray, segment, or the graph of an affine formula.
6
+ */
7
+ export declare function straightPoints(object: PlaneMathObject): Option.Option<readonly [{
8
+ readonly x: number;
9
+ readonly y: number;
10
+ }, {
11
+ readonly x: number;
12
+ readonly y: number;
13
+ }]>;
@@ -0,0 +1,26 @@
1
+ import { Match, Option, Result } from "effect";
2
+ import { readAffine } from "#contracts/math/formula/affine";
3
+ import { readFormula } from "#contracts/math/formula/parse";
4
+ /** Two points of a graph that is a straight line: an affine formula in its input axis. */
5
+ function straightGraph(formula, input) {
6
+ return Result.getSuccess(readFormula(formula)).pipe(Option.flatMap((node) => readAffine(node, [input])), Option.map(({ constant, terms }) => {
7
+ const slope = terms[input] ?? 0;
8
+ /** The graph's point at one value of its input. */
9
+ const at = (value) => input === "x"
10
+ ? { x: value, y: slope * value + constant }
11
+ : { x: slope * value + constant, y: value };
12
+ return [at(0), at(1)];
13
+ }));
14
+ }
15
+ /**
16
+ * Two points of a straight object of a plane scene, which name the line it
17
+ * runs along: a line, ray, segment, or the graph of an affine formula.
18
+ */
19
+ export function straightPoints(object) {
20
+ return Match.value(object).pipe(Match.discriminators("kind")({
21
+ function: ({ formula, inputAxis = "x" }) => straightGraph(formula, inputAxis),
22
+ line: ({ through }) => Option.some(through),
23
+ ray: ({ from, through }) => Option.some([from, through]),
24
+ segment: ({ from, to }) => Option.some([from, to]),
25
+ }), Match.orElse(() => Option.none()));
26
+ }
@@ -0,0 +1,91 @@
1
+ import { Schema } from "effect";
2
+ import type { RichSlot } from "#contracts/visual/card";
3
+ /** The blood labs. The named group is answer state. */
4
+ export declare function bloodVisuals<E>(rich: RichSlot<E>): {
5
+ BloodTypingLab: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
6
+ readonly description: RichSlot<E>;
7
+ readonly footer: Schema.optionalKey<Schema.Codec<readonly [{
8
+ readonly attrs: {
9
+ readonly latex: string;
10
+ };
11
+ readonly type: "mathInline";
12
+ } | {
13
+ readonly marks?: readonly [{
14
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
15
+ } | {
16
+ readonly attrs: {
17
+ readonly href: string;
18
+ };
19
+ readonly type: "link";
20
+ } | {
21
+ readonly attrs: {
22
+ readonly variant: "success" | "warning" | null;
23
+ };
24
+ readonly type: "highlight";
25
+ }, ...({
26
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
27
+ } | {
28
+ readonly attrs: {
29
+ readonly href: string;
30
+ };
31
+ readonly type: "link";
32
+ } | {
33
+ readonly attrs: {
34
+ readonly variant: "success" | "warning" | null;
35
+ };
36
+ readonly type: "highlight";
37
+ })[]];
38
+ readonly text: string;
39
+ readonly type: "text";
40
+ }, ...({
41
+ readonly attrs: {
42
+ readonly latex: string;
43
+ };
44
+ readonly type: "mathInline";
45
+ } | {
46
+ readonly marks?: readonly [{
47
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
48
+ } | {
49
+ readonly attrs: {
50
+ readonly href: string;
51
+ };
52
+ readonly type: "link";
53
+ } | {
54
+ readonly attrs: {
55
+ readonly variant: "success" | "warning" | null;
56
+ };
57
+ readonly type: "highlight";
58
+ }, ...({
59
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
60
+ } | {
61
+ readonly attrs: {
62
+ readonly href: string;
63
+ };
64
+ readonly type: "link";
65
+ } | {
66
+ readonly attrs: {
67
+ readonly variant: "success" | "warning" | null;
68
+ };
69
+ readonly type: "highlight";
70
+ })[]];
71
+ readonly text: string;
72
+ readonly type: "text";
73
+ })[]], E, never, never>>;
74
+ readonly title: RichSlot<E>;
75
+ readonly labels: Schema.Struct<{
76
+ readonly clumped: RichSlot<E>;
77
+ readonly group: Schema.optionalKey<RichSlot<E>>;
78
+ readonly groups: Schema.optionalKey<Schema.$Record<Schema.Literals<readonly ["A", "B", "AB", "O"]>, RichSlot<E>>>;
79
+ readonly sample: Schema.Trimmed;
80
+ readonly sera: Schema.$Record<Schema.Literals<readonly ["a", "b", "d"]>, RichSlot<E>>;
81
+ readonly smooth: RichSlot<E>;
82
+ readonly time: RichSlot<E>;
83
+ readonly view: Schema.Trimmed;
84
+ }>;
85
+ readonly samples: Schema.NonEmptyArray<Schema.Struct<{
86
+ readonly group: Schema.Literals<readonly ["A", "B", "AB", "O"]>;
87
+ readonly name: Schema.Trimmed;
88
+ readonly rhesus: Schema.Literals<readonly ["positive", "negative"]>;
89
+ }>>;
90
+ }>, "figure">;
91
+ };
@@ -0,0 +1,55 @@
1
+ import { Array as Arr, Schema } from "effect";
2
+ import { byIds, cardFields, TextSchema } from "#contracts/visual/card";
3
+ import { answerAt, figure } from "#contracts/visual/entry";
4
+ /** The ABO blood groups. */
5
+ const GROUPS = ["A", "B", "AB", "O"];
6
+ /**
7
+ * How many samples one grouping tile tests: its twelve cavities hold four
8
+ * rows of anti-A, anti-B and anti-D.
9
+ */
10
+ const TILE_ROWS = 4;
11
+ /**
12
+ * One blood sample on the tile: its name, its ABO group, and whether its red
13
+ * cells carry the Rhesus D antigen. The tile shows only how each drop reacts
14
+ * with each antiserum, never the group by name.
15
+ */
16
+ const SampleSchema = Schema.Struct({
17
+ group: Schema.Literals(GROUPS),
18
+ name: TextSchema,
19
+ rhesus: Schema.Literals(["positive", "negative"]),
20
+ });
21
+ /**
22
+ * The samples on one tile: one to four, each in its own row and named once,
23
+ * since the name labels its row and its choice in the toolbar.
24
+ */
25
+ const SamplesSchema = Schema.NonEmptyArray(SampleSchema).check(Schema.isMaxLength(TILE_ROWS), Schema.makeFilter((samples) => Arr.dedupe(Arr.map(samples, (sample) => sample.name)).length ===
26
+ samples.length, { message: "Expected every sample to have its own name." }));
27
+ /**
28
+ * Props of `BloodTypingLab`: each sample tested with anti-A, anti-B and
29
+ * anti-D sera on a white porcelain tile, the slide test read a minute after
30
+ * mixing. `labels.time` names that minute's clock. Naming the group the drops
31
+ * point to is the result a question asks for, so `labels.group` and
32
+ * `labels.groups` are answer state.
33
+ */
34
+ function bloodTypingLab(rich) {
35
+ return Schema.Struct({
36
+ ...cardFields(rich),
37
+ labels: Schema.Struct({
38
+ clumped: rich,
39
+ group: Schema.optionalKey(rich),
40
+ groups: Schema.optionalKey(byIds(GROUPS, rich)),
41
+ sample: TextSchema,
42
+ sera: byIds(["a", "b", "d"], rich),
43
+ smooth: rich,
44
+ time: rich,
45
+ view: TextSchema,
46
+ }),
47
+ samples: SamplesSchema,
48
+ });
49
+ }
50
+ /** The blood labs. The named group is answer state. */
51
+ export function bloodVisuals(rich) {
52
+ return {
53
+ BloodTypingLab: figure(bloodTypingLab(rich), answerAt(["labels", "group"], ["labels", "groups"])),
54
+ };
55
+ }