@nakafa/aksara-contracts 8.12.0 → 8.14.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.
@@ -124,6 +124,19 @@ declare const MathBlockSchema: Schema.Struct<{
124
124
  }>;
125
125
  readonly type: Schema.Literal<"mathBlock">;
126
126
  }>;
127
+ /**
128
+ * A vertical stack of consecutive block formulas from one derivation or
129
+ * comparison, matching `<MathContainer>` in lessons and articles.
130
+ */
131
+ declare const MathContainerSchema: Schema.Struct<{
132
+ readonly content: Schema.NonEmptyArray<Schema.Struct<{
133
+ readonly attrs: Schema.Struct<{
134
+ readonly latex: Schema.Trimmed;
135
+ }>;
136
+ readonly type: Schema.Literal<"mathBlock">;
137
+ }>>;
138
+ readonly type: Schema.Literal<"mathContainer">;
139
+ }>;
127
140
  declare const ImageNodeSchema: Schema.Struct<{
128
141
  readonly attrs: Schema.Struct<{
129
142
  readonly alt: Schema.Trimmed;
@@ -149,7 +162,7 @@ export type InteractionNode = typeof InteractionNodeSchema.Type;
149
162
  * out here, because a recursive schema needs its type named in its own
150
163
  * definition; every other node type is derived from its schema.
151
164
  */
152
- export type BlockNode = ParagraphNode | typeof HeadingSchema.Type | typeof CodeBlockSchema.Type | typeof MathBlockSchema.Type | typeof FigureNodeSchema.Type | typeof ImageNodeSchema.Type | InteractionNode | {
165
+ export type BlockNode = ParagraphNode | typeof HeadingSchema.Type | typeof CodeBlockSchema.Type | typeof MathBlockSchema.Type | typeof MathContainerSchema.Type | typeof FigureNodeSchema.Type | typeof ImageNodeSchema.Type | InteractionNode | {
153
166
  readonly content: readonly [ListItemNode, ...ListItemNode[]];
154
167
  readonly type: "bulletList";
155
168
  } | {
@@ -166,7 +179,7 @@ export type BlockNode = ParagraphNode | typeof HeadingSchema.Type | typeof CodeB
166
179
  readonly type: "table";
167
180
  } | {
168
181
  readonly content: readonly [BlockNode, ...BlockNode[]];
169
- readonly type: "contentBlock" | "contentStack";
182
+ readonly type: "contentBlock" | "contentGrid" | "contentStack";
170
183
  };
171
184
  export type ListItemNode = typeof ListItemSchema.Type;
172
185
  export type TableRowNode = typeof TableRowSchema.Type;
@@ -37,6 +37,14 @@ const MathBlockSchema = Schema.Struct({
37
37
  attrs: Schema.Struct({ latex: LatexSchema }),
38
38
  type: Schema.Literal("mathBlock"),
39
39
  });
40
+ /**
41
+ * A vertical stack of consecutive block formulas from one derivation or
42
+ * comparison, matching `<MathContainer>` in lessons and articles.
43
+ */
44
+ const MathContainerSchema = Schema.Struct({
45
+ content: Schema.NonEmptyArray(MathBlockSchema),
46
+ type: Schema.Literal("mathContainer"),
47
+ });
40
48
  const ImageNodeSchema = Schema.Struct({
41
49
  attrs: ImageSchema,
42
50
  type: Schema.Literal("image"),
@@ -79,12 +87,12 @@ const TableCellSchema = Schema.Struct({
79
87
  });
80
88
  /**
81
89
  * A group of blocks, as a lesson groups them: `contentStack` stacks related
82
- * blocks, such as a formula and the graph it draws, and `contentBlock` sets one
83
- * block apart with space around it.
90
+ * blocks, `contentGrid` arranges related visuals or blocks in a responsive grid,
91
+ * and `contentBlock` sets one block apart with space around it.
84
92
  */
85
93
  const ContentGroupSchema = Schema.Struct({
86
94
  content: Schema.NonEmptyArray(BlockRef),
87
- type: Schema.Literals(["contentBlock", "contentStack"]),
95
+ type: Schema.Literals(["contentBlock", "contentGrid", "contentStack"]),
88
96
  });
89
97
  const TableRowSchema = Schema.Struct({
90
98
  content: Schema.NonEmptyArray(TableCellSchema),
@@ -100,6 +108,7 @@ export const BlockSchema = Schema.Union([
100
108
  HeadingSchema,
101
109
  CodeBlockSchema,
102
110
  MathBlockSchema,
111
+ MathContainerSchema,
103
112
  FigureNodeSchema,
104
113
  ImageNodeSchema,
105
114
  InteractionNodeSchema,
@@ -0,0 +1,284 @@
1
+ import { Schema } from "effect";
2
+ import type { RichSlot } from "#contracts/visual/card";
3
+ /**
4
+ * Homeostasis labs covering mammalian skin thermoregulation and pancreatic
5
+ * blood-glucose negative feedback.
6
+ */
7
+ export declare function homeostasisVisuals<E>(rich: RichSlot<E>): {
8
+ BloodGlucoseFeedbackLab: 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 glucose: Schema.Struct<{
129
+ readonly max: Schema.Finite;
130
+ readonly min: Schema.Finite;
131
+ readonly value: Schema.Finite;
132
+ }>;
133
+ readonly labels: Schema.Struct<{
134
+ readonly actions: Schema.$Record<Schema.Literals<readonly ["afterMeal", "normal", "fasting", "diabetes"]>, Schema.optionalKey<RichSlot<E>>>;
135
+ readonly glucose: Schema.Trimmed;
136
+ readonly hormone: Schema.optionalKey<RichSlot<E>>;
137
+ readonly hormones: Schema.$Record<Schema.Literals<readonly ["insulin", "glucagon", "balanced", "deficient"]>, Schema.Trimmed>;
138
+ readonly liverAction: Schema.optionalKey<RichSlot<E>>;
139
+ readonly parts: Schema.$Record<Schema.Literals<readonly ["pancreas", "alphaCell", "betaCell", "liver", "glycogen", "bloodVessel"]>, Schema.Trimmed>;
140
+ readonly state: Schema.Trimmed;
141
+ readonly states: Schema.$Record<Schema.Literals<readonly ["afterMeal", "normal", "fasting", "diabetes"]>, Schema.optionalKey<Schema.Trimmed>>;
142
+ readonly view: Schema.Trimmed;
143
+ }>;
144
+ readonly states: Schema.NonEmptyArray<Schema.Literals<readonly ["afterMeal", "normal", "fasting", "diabetes"]>>;
145
+ }>, "figure">;
146
+ ThermoregulationSkinLab: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
147
+ readonly description: RichSlot<E>;
148
+ readonly footer: Schema.optionalKey<Schema.Codec<readonly [{
149
+ readonly marks?: readonly [{
150
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
151
+ } | {
152
+ readonly attrs: {
153
+ readonly href: string;
154
+ };
155
+ readonly type: "link";
156
+ } | {
157
+ readonly attrs: {
158
+ readonly variant: "success" | "warning" | null;
159
+ };
160
+ readonly type: "highlight";
161
+ }, ...({
162
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
163
+ } | {
164
+ readonly attrs: {
165
+ readonly href: string;
166
+ };
167
+ readonly type: "link";
168
+ } | {
169
+ readonly attrs: {
170
+ readonly variant: "success" | "warning" | null;
171
+ };
172
+ readonly type: "highlight";
173
+ })[]];
174
+ readonly text: string;
175
+ readonly type: "text";
176
+ } | {
177
+ readonly attrs: {
178
+ readonly latex: string;
179
+ };
180
+ readonly marks?: readonly [{
181
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
182
+ } | {
183
+ readonly attrs: {
184
+ readonly href: string;
185
+ };
186
+ readonly type: "link";
187
+ } | {
188
+ readonly attrs: {
189
+ readonly variant: "success" | "warning" | null;
190
+ };
191
+ readonly type: "highlight";
192
+ }, ...({
193
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
194
+ } | {
195
+ readonly attrs: {
196
+ readonly href: string;
197
+ };
198
+ readonly type: "link";
199
+ } | {
200
+ readonly attrs: {
201
+ readonly variant: "success" | "warning" | null;
202
+ };
203
+ readonly type: "highlight";
204
+ })[]];
205
+ readonly type: "mathInline";
206
+ }, ...({
207
+ readonly marks?: readonly [{
208
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
209
+ } | {
210
+ readonly attrs: {
211
+ readonly href: string;
212
+ };
213
+ readonly type: "link";
214
+ } | {
215
+ readonly attrs: {
216
+ readonly variant: "success" | "warning" | null;
217
+ };
218
+ readonly type: "highlight";
219
+ }, ...({
220
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
221
+ } | {
222
+ readonly attrs: {
223
+ readonly href: string;
224
+ };
225
+ readonly type: "link";
226
+ } | {
227
+ readonly attrs: {
228
+ readonly variant: "success" | "warning" | null;
229
+ };
230
+ readonly type: "highlight";
231
+ })[]];
232
+ readonly text: string;
233
+ readonly type: "text";
234
+ } | {
235
+ readonly attrs: {
236
+ readonly latex: string;
237
+ };
238
+ readonly marks?: readonly [{
239
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
240
+ } | {
241
+ readonly attrs: {
242
+ readonly href: string;
243
+ };
244
+ readonly type: "link";
245
+ } | {
246
+ readonly attrs: {
247
+ readonly variant: "success" | "warning" | null;
248
+ };
249
+ readonly type: "highlight";
250
+ }, ...({
251
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
252
+ } | {
253
+ readonly attrs: {
254
+ readonly href: string;
255
+ };
256
+ readonly type: "link";
257
+ } | {
258
+ readonly attrs: {
259
+ readonly variant: "success" | "warning" | null;
260
+ };
261
+ readonly type: "highlight";
262
+ })[]];
263
+ readonly type: "mathInline";
264
+ })[]], E, never, never>>;
265
+ readonly title: RichSlot<E>;
266
+ readonly ambient: Schema.Struct<{
267
+ readonly max: Schema.Finite;
268
+ readonly min: Schema.Finite;
269
+ readonly value: Schema.Finite;
270
+ }>;
271
+ readonly conditions: Schema.NonEmptyArray<Schema.Literals<readonly ["cold", "normal", "hot"]>>;
272
+ readonly labels: Schema.Struct<{
273
+ readonly ambient: Schema.Trimmed;
274
+ readonly bloodFlow: Schema.optionalKey<RichSlot<E>>;
275
+ readonly condition: Schema.Trimmed;
276
+ readonly conditions: Schema.$Record<Schema.Literals<readonly ["cold", "normal", "hot"]>, Schema.optionalKey<Schema.Trimmed>>;
277
+ readonly heatLoss: Schema.optionalKey<RichSlot<E>>;
278
+ readonly parts: Schema.$Record<Schema.Literals<readonly ["epidermis", "sweatGland", "arteriole", "capillary", "erectorMuscle", "hairShaft", "fatLayer"]>, Schema.Trimmed>;
279
+ readonly response: RichSlot<E>;
280
+ readonly responses: Schema.$Record<Schema.Literals<readonly ["cold", "normal", "hot"]>, Schema.optionalKey<RichSlot<E>>>;
281
+ readonly view: Schema.Trimmed;
282
+ }>;
283
+ }>, "figure">;
284
+ };
@@ -0,0 +1,101 @@
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 measure for physiological sliders. */
5
+ const PositiveSchema = Schema.Finite.check(Schema.isGreaterThan(0));
6
+ /** A finite slider whose minimum sits below its maximum. */
7
+ const RangeSliderSchema = Schema.Struct({
8
+ max: Schema.Finite,
9
+ min: Schema.Finite,
10
+ value: Schema.Finite,
11
+ }).check(Schema.makeFilter(({ max, min, value }) => min < max && min <= value && value <= max, {
12
+ message: "Expected a slider range whose minimum is below its maximum, with the starting value between them.",
13
+ }));
14
+ /** A strictly positive slider whose minimum sits below its maximum. */
15
+ const PositiveSliderSchema = Schema.Struct({
16
+ max: PositiveSchema,
17
+ min: PositiveSchema,
18
+ value: PositiveSchema,
19
+ }).check(Schema.makeFilter(({ max, min, value }) => min < max && min <= value && value <= max, {
20
+ message: "Expected a positive slider range whose minimum is below its maximum, with the starting value between them.",
21
+ }));
22
+ const THERMAL_CONDITIONS = ["cold", "normal", "hot"];
23
+ const GLUCOSE_STATES = ["afterMeal", "normal", "fasting", "diabetes"];
24
+ /**
25
+ * Props of `ThermoregulationSkinLab`: a 3D mammalian skin cross-section
26
+ * contrasting cold, normal, and hot conditions across arteriolar diameter,
27
+ * sweat gland activity, erector pili muscles, and hair shaft tilt. Blood flow
28
+ * and heat-loss readouts are optional answer state.
29
+ */
30
+ function thermoregulationSkinLab(rich) {
31
+ return figure(Schema.Struct({
32
+ ...cardFields(rich),
33
+ ambient: RangeSliderSchema,
34
+ conditions: Schema.NonEmptyArray(Schema.Literals(THERMAL_CONDITIONS)).check(Schema.isUnique()),
35
+ labels: Schema.Struct({
36
+ ambient: TextSchema,
37
+ bloodFlow: Schema.optionalKey(rich),
38
+ condition: TextSchema,
39
+ conditions: byPickedIds(THERMAL_CONDITIONS, TextSchema),
40
+ heatLoss: Schema.optionalKey(rich),
41
+ parts: byIds([
42
+ "epidermis",
43
+ "sweatGland",
44
+ "arteriole",
45
+ "capillary",
46
+ "erectorMuscle",
47
+ "hairShaft",
48
+ "fatLayer",
49
+ ], TextSchema),
50
+ response: rich,
51
+ responses: byPickedIds(THERMAL_CONDITIONS, rich),
52
+ view: TextSchema,
53
+ }),
54
+ }).check(Schema.makeFilter(({ conditions, labels }) => namesEach(conditions, labels.conditions) &&
55
+ namesEach(conditions, labels.responses), {
56
+ message: "Expected a name and response note for every thermal condition shown, and no other.",
57
+ })), answerAt(["labels", "bloodFlow"], ["labels", "heatLoss"]));
58
+ }
59
+ /**
60
+ * Props of `BloodGlucoseFeedbackLab`: a 3D negative-feedback circuit linking
61
+ * pancreatic islets, insulin and glucagon secretion, liver glycogen storage,
62
+ * and blood glucose concentration across meal, fasting, and diabetes states.
63
+ * Active hormone and liver-action readouts are optional answer state.
64
+ */
65
+ function bloodGlucoseFeedbackLab(rich) {
66
+ return figure(Schema.Struct({
67
+ ...cardFields(rich),
68
+ glucose: PositiveSliderSchema,
69
+ labels: Schema.Struct({
70
+ actions: byPickedIds(GLUCOSE_STATES, rich),
71
+ glucose: TextSchema,
72
+ hormone: Schema.optionalKey(rich),
73
+ hormones: byIds(["insulin", "glucagon", "balanced", "deficient"], TextSchema),
74
+ liverAction: Schema.optionalKey(rich),
75
+ parts: byIds([
76
+ "pancreas",
77
+ "alphaCell",
78
+ "betaCell",
79
+ "liver",
80
+ "glycogen",
81
+ "bloodVessel",
82
+ ], TextSchema),
83
+ state: TextSchema,
84
+ states: byPickedIds(GLUCOSE_STATES, TextSchema),
85
+ view: TextSchema,
86
+ }),
87
+ states: Schema.NonEmptyArray(Schema.Literals(GLUCOSE_STATES)).check(Schema.isUnique()),
88
+ }).check(Schema.makeFilter(({ labels, states }) => namesEach(states, labels.states) && namesEach(states, labels.actions), {
89
+ message: "Expected a name and liver action note for every glucose state shown, and no other.",
90
+ })), answerAt(["labels", "hormone"], ["labels", "liverAction"]));
91
+ }
92
+ /**
93
+ * Homeostasis labs covering mammalian skin thermoregulation and pancreatic
94
+ * blood-glucose negative feedback.
95
+ */
96
+ export function homeostasisVisuals(rich) {
97
+ return {
98
+ BloodGlucoseFeedbackLab: bloodGlucoseFeedbackLab(rich),
99
+ ThermoregulationSkinLab: thermoregulationSkinLab(rich),
100
+ };
101
+ }