@nakafa/aksara-contracts 8.16.0 → 8.17.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.
@@ -0,0 +1,286 @@
1
+ import { Schema } from "effect";
2
+ import type { RichSlot } from "#contracts/visual/card";
3
+ /**
4
+ * Human respiratory system labs covering alveolar gas diffusion and thoracic
5
+ * breathing mechanics.
6
+ */
7
+ export declare function respirationVisuals<E>(rich: RichSlot<E>): {
8
+ AlveolusGasExchangeLab: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
9
+ readonly description: RichSlot<E>;
10
+ readonly footer: Schema.optionalKey<Schema.Codec<readonly [{
11
+ readonly marks?: readonly [{
12
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
13
+ } | {
14
+ readonly attrs: {
15
+ readonly href: string;
16
+ };
17
+ readonly type: "link";
18
+ } | {
19
+ readonly attrs: {
20
+ readonly variant: "success" | "warning" | null;
21
+ };
22
+ readonly type: "highlight";
23
+ }, ...({
24
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
25
+ } | {
26
+ readonly attrs: {
27
+ readonly href: string;
28
+ };
29
+ readonly type: "link";
30
+ } | {
31
+ readonly attrs: {
32
+ readonly variant: "success" | "warning" | null;
33
+ };
34
+ readonly type: "highlight";
35
+ })[]];
36
+ readonly text: string;
37
+ readonly type: "text";
38
+ } | {
39
+ readonly attrs: {
40
+ readonly latex: string;
41
+ };
42
+ readonly marks?: readonly [{
43
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
44
+ } | {
45
+ readonly attrs: {
46
+ readonly href: string;
47
+ };
48
+ readonly type: "link";
49
+ } | {
50
+ readonly attrs: {
51
+ readonly variant: "success" | "warning" | null;
52
+ };
53
+ readonly type: "highlight";
54
+ }, ...({
55
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
56
+ } | {
57
+ readonly attrs: {
58
+ readonly href: string;
59
+ };
60
+ readonly type: "link";
61
+ } | {
62
+ readonly attrs: {
63
+ readonly variant: "success" | "warning" | null;
64
+ };
65
+ readonly type: "highlight";
66
+ })[]];
67
+ readonly type: "mathInline";
68
+ }, ...({
69
+ readonly marks?: readonly [{
70
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
71
+ } | {
72
+ readonly attrs: {
73
+ readonly href: string;
74
+ };
75
+ readonly type: "link";
76
+ } | {
77
+ readonly attrs: {
78
+ readonly variant: "success" | "warning" | null;
79
+ };
80
+ readonly type: "highlight";
81
+ }, ...({
82
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
83
+ } | {
84
+ readonly attrs: {
85
+ readonly href: string;
86
+ };
87
+ readonly type: "link";
88
+ } | {
89
+ readonly attrs: {
90
+ readonly variant: "success" | "warning" | null;
91
+ };
92
+ readonly type: "highlight";
93
+ })[]];
94
+ readonly text: string;
95
+ readonly type: "text";
96
+ } | {
97
+ readonly attrs: {
98
+ readonly latex: string;
99
+ };
100
+ readonly marks?: readonly [{
101
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
102
+ } | {
103
+ readonly attrs: {
104
+ readonly href: string;
105
+ };
106
+ readonly type: "link";
107
+ } | {
108
+ readonly attrs: {
109
+ readonly variant: "success" | "warning" | null;
110
+ };
111
+ readonly type: "highlight";
112
+ }, ...({
113
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
114
+ } | {
115
+ readonly attrs: {
116
+ readonly href: string;
117
+ };
118
+ readonly type: "link";
119
+ } | {
120
+ readonly attrs: {
121
+ readonly variant: "success" | "warning" | null;
122
+ };
123
+ readonly type: "highlight";
124
+ })[]];
125
+ readonly type: "mathInline";
126
+ })[]], E, never, never>>;
127
+ readonly title: RichSlot<E>;
128
+ readonly labels: Schema.Struct<{
129
+ readonly diffusionRate: Schema.optionalKey<RichSlot<E>>;
130
+ readonly oxygenUptake: Schema.optionalKey<RichSlot<E>>;
131
+ readonly parts: Schema.$Record<Schema.Literals<readonly ["alveolus", "capillary", "redBloodCell", "oxygen", "carbonDioxide", "surfactantFilm"]>, Schema.Trimmed>;
132
+ readonly state: Schema.Trimmed;
133
+ readonly states: Schema.$Record<Schema.Literals<readonly ["rest", "exercise", "highAltitude"]>, Schema.optionalKey<Schema.Struct<{
134
+ readonly name: Schema.Trimmed;
135
+ readonly summary: RichSlot<E>;
136
+ }>>>;
137
+ readonly ventilation: Schema.Trimmed;
138
+ readonly view: Schema.Trimmed;
139
+ }>;
140
+ readonly states: Schema.NonEmptyArray<Schema.Literals<readonly ["rest", "exercise", "highAltitude"]>>;
141
+ readonly ventilation: Schema.Struct<{
142
+ readonly max: Schema.Finite;
143
+ readonly min: Schema.Finite;
144
+ readonly value: Schema.Finite;
145
+ }>;
146
+ }>, "figure">;
147
+ ThoraxDiaphragmLab: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
148
+ readonly description: RichSlot<E>;
149
+ readonly footer: Schema.optionalKey<Schema.Codec<readonly [{
150
+ readonly marks?: readonly [{
151
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
152
+ } | {
153
+ readonly attrs: {
154
+ readonly href: string;
155
+ };
156
+ readonly type: "link";
157
+ } | {
158
+ readonly attrs: {
159
+ readonly variant: "success" | "warning" | null;
160
+ };
161
+ readonly type: "highlight";
162
+ }, ...({
163
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
164
+ } | {
165
+ readonly attrs: {
166
+ readonly href: string;
167
+ };
168
+ readonly type: "link";
169
+ } | {
170
+ readonly attrs: {
171
+ readonly variant: "success" | "warning" | null;
172
+ };
173
+ readonly type: "highlight";
174
+ })[]];
175
+ readonly text: string;
176
+ readonly type: "text";
177
+ } | {
178
+ readonly attrs: {
179
+ readonly latex: string;
180
+ };
181
+ readonly marks?: readonly [{
182
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
183
+ } | {
184
+ readonly attrs: {
185
+ readonly href: string;
186
+ };
187
+ readonly type: "link";
188
+ } | {
189
+ readonly attrs: {
190
+ readonly variant: "success" | "warning" | null;
191
+ };
192
+ readonly type: "highlight";
193
+ }, ...({
194
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
195
+ } | {
196
+ readonly attrs: {
197
+ readonly href: string;
198
+ };
199
+ readonly type: "link";
200
+ } | {
201
+ readonly attrs: {
202
+ readonly variant: "success" | "warning" | null;
203
+ };
204
+ readonly type: "highlight";
205
+ })[]];
206
+ readonly type: "mathInline";
207
+ }, ...({
208
+ readonly marks?: readonly [{
209
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
210
+ } | {
211
+ readonly attrs: {
212
+ readonly href: string;
213
+ };
214
+ readonly type: "link";
215
+ } | {
216
+ readonly attrs: {
217
+ readonly variant: "success" | "warning" | null;
218
+ };
219
+ readonly type: "highlight";
220
+ }, ...({
221
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
222
+ } | {
223
+ readonly attrs: {
224
+ readonly href: string;
225
+ };
226
+ readonly type: "link";
227
+ } | {
228
+ readonly attrs: {
229
+ readonly variant: "success" | "warning" | null;
230
+ };
231
+ readonly type: "highlight";
232
+ })[]];
233
+ readonly text: string;
234
+ readonly type: "text";
235
+ } | {
236
+ readonly attrs: {
237
+ readonly latex: string;
238
+ };
239
+ readonly marks?: readonly [{
240
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
241
+ } | {
242
+ readonly attrs: {
243
+ readonly href: string;
244
+ };
245
+ readonly type: "link";
246
+ } | {
247
+ readonly attrs: {
248
+ readonly variant: "success" | "warning" | null;
249
+ };
250
+ readonly type: "highlight";
251
+ }, ...({
252
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
253
+ } | {
254
+ readonly attrs: {
255
+ readonly href: string;
256
+ };
257
+ readonly type: "link";
258
+ } | {
259
+ readonly attrs: {
260
+ readonly variant: "success" | "warning" | null;
261
+ };
262
+ readonly type: "highlight";
263
+ })[]];
264
+ readonly type: "mathInline";
265
+ })[]], E, never, never>>;
266
+ readonly title: RichSlot<E>;
267
+ readonly depth: Schema.Struct<{
268
+ readonly max: Schema.Finite;
269
+ readonly min: Schema.Finite;
270
+ readonly value: Schema.Finite;
271
+ }>;
272
+ readonly labels: Schema.Struct<{
273
+ readonly alveolarPressure: Schema.optionalKey<RichSlot<E>>;
274
+ readonly depth: Schema.Trimmed;
275
+ readonly parts: Schema.$Record<Schema.Literals<readonly ["trachea", "lungs", "ribcage", "intercostal", "diaphragm", "pleuralCavity"]>, Schema.Trimmed>;
276
+ readonly phase: Schema.Trimmed;
277
+ readonly phases: Schema.$Record<Schema.Literals<readonly ["inhalation", "exhalation", "forcedExhalation"]>, Schema.optionalKey<Schema.Struct<{
278
+ readonly name: Schema.Trimmed;
279
+ readonly summary: RichSlot<E>;
280
+ }>>>;
281
+ readonly thoracicVolume: Schema.optionalKey<RichSlot<E>>;
282
+ readonly view: Schema.Trimmed;
283
+ }>;
284
+ readonly phases: Schema.NonEmptyArray<Schema.Literals<readonly ["inhalation", "exhalation", "forcedExhalation"]>>;
285
+ }>, "figure">;
286
+ };
@@ -0,0 +1,97 @@
1
+ import { Schema } from "effect";
2
+ import { byIds, byPickedIds, cardFields, namesEach, TextSchema, } from "#contracts/visual/card";
3
+ import { answerAt, figure } from "#contracts/visual/entry";
4
+ /** A strictly positive finite bound for respiratory sliders. */
5
+ const PositiveSchema = Schema.Finite.check(Schema.isGreaterThan(0));
6
+ /** A positive slider whose minimum sits below its maximum. */
7
+ const PositiveSliderSchema = Schema.Struct({
8
+ max: PositiveSchema,
9
+ min: PositiveSchema,
10
+ value: PositiveSchema,
11
+ }).check(Schema.makeFilter(({ max, min, value }) => min < max && min <= value && value <= max, {
12
+ message: "Expected a positive range whose minimum is below its maximum, with the starting value between them.",
13
+ }));
14
+ const ACTIVITY_STATES = ["rest", "exercise", "highAltitude"];
15
+ const BREATHING_PHASES = [
16
+ "inhalation",
17
+ "exhalation",
18
+ "forcedExhalation",
19
+ ];
20
+ /**
21
+ * Props of `AlveolusGasExchangeLab`: a 3D alveolar sac wrapped in a capillary
22
+ * network showing oxygen and carbon dioxide diffusion across the respiratory
23
+ * membrane under rest, exercise, and high altitude. Oxygen uptake and
24
+ * diffusion rate readouts are optional answer state.
25
+ */
26
+ function alveolusGasExchangeLab(rich) {
27
+ return figure(Schema.Struct({
28
+ ...cardFields(rich),
29
+ labels: Schema.Struct({
30
+ diffusionRate: Schema.optionalKey(rich),
31
+ oxygenUptake: Schema.optionalKey(rich),
32
+ parts: byIds([
33
+ "alveolus",
34
+ "capillary",
35
+ "redBloodCell",
36
+ "oxygen",
37
+ "carbonDioxide",
38
+ "surfactantFilm",
39
+ ], TextSchema),
40
+ state: TextSchema,
41
+ states: byPickedIds(ACTIVITY_STATES, Schema.Struct({
42
+ name: TextSchema,
43
+ summary: rich,
44
+ })),
45
+ ventilation: TextSchema,
46
+ view: TextSchema,
47
+ }),
48
+ states: Schema.NonEmptyArray(Schema.Literals(ACTIVITY_STATES)).check(Schema.isUnique()),
49
+ ventilation: PositiveSliderSchema,
50
+ }).check(Schema.makeFilter(({ labels, states }) => namesEach(states, labels.states), {
51
+ message: "Expected a name and summary for every physiological activity state shown, and no other.",
52
+ })), answerAt(["labels", "oxygenUptake"], ["labels", "diffusionRate"]));
53
+ }
54
+ /**
55
+ * Props of `ThoraxDiaphragmLab`: a 3D thoracic cage, intercostal muscles,
56
+ * paired lungs, and dome-shaped diaphragm demonstrating Boyle's law during
57
+ * inhalation, exhalation, and forced exhalation. Thoracic volume and alveolar
58
+ * pressure readouts are optional answer state.
59
+ */
60
+ function thoraxDiaphragmLab(rich) {
61
+ return figure(Schema.Struct({
62
+ ...cardFields(rich),
63
+ depth: PositiveSliderSchema,
64
+ labels: Schema.Struct({
65
+ alveolarPressure: Schema.optionalKey(rich),
66
+ depth: TextSchema,
67
+ parts: byIds([
68
+ "trachea",
69
+ "lungs",
70
+ "ribcage",
71
+ "intercostal",
72
+ "diaphragm",
73
+ "pleuralCavity",
74
+ ], TextSchema),
75
+ phase: TextSchema,
76
+ phases: byPickedIds(BREATHING_PHASES, Schema.Struct({
77
+ name: TextSchema,
78
+ summary: rich,
79
+ })),
80
+ thoracicVolume: Schema.optionalKey(rich),
81
+ view: TextSchema,
82
+ }),
83
+ phases: Schema.NonEmptyArray(Schema.Literals(BREATHING_PHASES)).check(Schema.isUnique()),
84
+ }).check(Schema.makeFilter(({ labels, phases }) => namesEach(phases, labels.phases), {
85
+ message: "Expected a name and summary for every breathing phase shown, and no other.",
86
+ })), answerAt(["labels", "thoracicVolume"], ["labels", "alveolarPressure"]));
87
+ }
88
+ /**
89
+ * Human respiratory system labs covering alveolar gas diffusion and thoracic
90
+ * breathing mechanics.
91
+ */
92
+ export function respirationVisuals(rich) {
93
+ return {
94
+ AlveolusGasExchangeLab: alveolusGasExchangeLab(rich),
95
+ ThoraxDiaphragmLab: thoraxDiaphragmLab(rich),
96
+ };
97
+ }