@nakafa/aksara-contracts 8.16.0 → 8.17.1

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,146 @@
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 integral 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 slider range whose minimum is below its maximum, with the starting value between them.",
13
+ }));
14
+ /** An integer partition slider for Riemann sums. */
15
+ const PartitionSliderSchema = Schema.Struct({
16
+ max: Schema.Int.check(Schema.isGreaterThan(1)),
17
+ min: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
18
+ value: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
19
+ }).check(Schema.makeFilter(({ max, min, value }) => min < max && min <= value && value <= max, {
20
+ message: "Expected a partition range whose minimum is below its maximum, with the starting value between them.",
21
+ }));
22
+ const RIEMANN_METHODS = ["left", "right", "midpoint", "trapezoid"];
23
+ const RIEMANN_CURVES = ["parabola", "sineArch", "exponential"];
24
+ const REVOLUTION_PROFILES = [
25
+ "paraboloid",
26
+ "trumpetHorn",
27
+ "washerBowl",
28
+ "frustumCone",
29
+ ];
30
+ const CURVE_PAIRS = [
31
+ "lineAndParabola",
32
+ "twoParabolas",
33
+ "sineAndCosine",
34
+ ];
35
+ /**
36
+ * Props of `RiemannSumConvergenceLab`: a 3D prism stage comparing left, right,
37
+ * midpoint, and trapezoid Riemann sums converging toward the exact definite
38
+ * integral as partition count grows. Approximate area and exact integral
39
+ * readouts are optional answer state.
40
+ */
41
+ function riemannSumConvergenceLab(rich) {
42
+ return figure(Schema.Struct({
43
+ ...cardFields(rich),
44
+ curves: Schema.NonEmptyArray(Schema.Literals(RIEMANN_CURVES)).check(Schema.isUnique()),
45
+ labels: Schema.Struct({
46
+ approxArea: Schema.optionalKey(rich),
47
+ curve: TextSchema,
48
+ curves: byPickedIds(RIEMANN_CURVES, Schema.Struct({
49
+ formula: rich,
50
+ name: TextSchema,
51
+ })),
52
+ exactIntegral: Schema.optionalKey(rich),
53
+ method: TextSchema,
54
+ methods: byPickedIds(RIEMANN_METHODS, TextSchema),
55
+ partitions: TextSchema,
56
+ parts: byIds([
57
+ "curveSurface",
58
+ "riemannPrisms",
59
+ "samplePoints",
60
+ "exactArea",
61
+ "baseAxis",
62
+ ], TextSchema),
63
+ view: TextSchema,
64
+ }),
65
+ methods: Schema.NonEmptyArray(Schema.Literals(RIEMANN_METHODS)).check(Schema.isUnique()),
66
+ partitions: PartitionSliderSchema,
67
+ }).check(Schema.makeFilter(({ curves, labels, methods }) => namesEach(curves, labels.curves) &&
68
+ namesEach(methods, labels.methods), {
69
+ message: "Expected a name for every Riemann method and curve shown, and no other.",
70
+ })), answerAt(["labels", "approxArea"], ["labels", "exactIntegral"]));
71
+ }
72
+ /**
73
+ * Props of `SolidOfRevolutionLab`: a 3D lathe solid swept around the x-axis
74
+ * from 0 to 360 degrees with a highlighted disk or washer cross-section. Slice
75
+ * area and total volume readouts are optional answer state.
76
+ */
77
+ function solidOfRevolutionLab(rich) {
78
+ return figure(Schema.Struct({
79
+ ...cardFields(rich),
80
+ labels: Schema.Struct({
81
+ parts: byIds([
82
+ "profileCurve",
83
+ "revolvedShell",
84
+ "crossSectionDisk",
85
+ "rotationAxis",
86
+ "radiusArrow",
87
+ ], TextSchema),
88
+ profile: TextSchema,
89
+ profiles: byPickedIds(REVOLUTION_PROFILES, Schema.Struct({
90
+ formula: rich,
91
+ name: TextSchema,
92
+ })),
93
+ sliceArea: Schema.optionalKey(rich),
94
+ sweepAngle: TextSchema,
95
+ totalVolume: Schema.optionalKey(rich),
96
+ view: TextSchema,
97
+ }),
98
+ profiles: Schema.NonEmptyArray(Schema.Literals(REVOLUTION_PROFILES)).check(Schema.isUnique()),
99
+ sweepAngle: PositiveSliderSchema,
100
+ }).check(Schema.makeFilter(({ labels, profiles }) => namesEach(profiles, labels.profiles), {
101
+ message: "Expected a name and formula for every solid-of-revolution profile shown, and no other.",
102
+ })), answerAt(["labels", "sliceArea"], ["labels", "totalVolume"]));
103
+ }
104
+ /**
105
+ * Props of `AreaBetweenCurvesLab`: a 3D ribbon bounded between an upper curve
106
+ * f(x) and lower curve g(x) with intersection pins and a sliding vertical
107
+ * strip. Enclosed area and height gap readouts are optional answer state.
108
+ */
109
+ function areaBetweenCurvesLab(rich) {
110
+ return figure(Schema.Struct({
111
+ ...cardFields(rich),
112
+ labels: Schema.Struct({
113
+ enclosedArea: Schema.optionalKey(rich),
114
+ heightGap: Schema.optionalKey(rich),
115
+ pair: TextSchema,
116
+ pairs: byPickedIds(CURVE_PAIRS, Schema.Struct({
117
+ formula: rich,
118
+ name: TextSchema,
119
+ })),
120
+ parts: byIds([
121
+ "upperCurve",
122
+ "lowerCurve",
123
+ "shadedRibbon",
124
+ "verticalStrip",
125
+ "intersectionPins",
126
+ ], TextSchema),
127
+ upperBound: TextSchema,
128
+ view: TextSchema,
129
+ }),
130
+ pairs: Schema.NonEmptyArray(Schema.Literals(CURVE_PAIRS)).check(Schema.isUnique()),
131
+ upperBound: PositiveSliderSchema,
132
+ }).check(Schema.makeFilter(({ labels, pairs }) => namesEach(pairs, labels.pairs), {
133
+ message: "Expected a name and formula for every curve pair shown, and no other.",
134
+ })), answerAt(["labels", "enclosedArea"], ["labels", "heightGap"]));
135
+ }
136
+ /**
137
+ * Integral calculus 3D labs covering Riemann sum convergence, solids of
138
+ * revolution, and enclosed areas between curves.
139
+ */
140
+ export function integralVisuals(rich) {
141
+ return {
142
+ AreaBetweenCurvesLab: areaBetweenCurvesLab(rich),
143
+ RiemannSumConvergenceLab: riemannSumConvergenceLab(rich),
144
+ SolidOfRevolutionLab: solidOfRevolutionLab(rich),
145
+ };
146
+ }
@@ -0,0 +1,425 @@
1
+ import { Schema } from "effect";
2
+ import type { RichSlot } from "#contracts/visual/card";
3
+ /**
4
+ * Limit calculus 3D labs covering epsilon-delta corridors, asymptote
5
+ * behavior, and the squeeze theorem.
6
+ */
7
+ export declare function limitVisuals<E>(rich: RichSlot<E>): {
8
+ AsymptoteBehaviorLab: 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 curves: Schema.NonEmptyArray<Schema.Literals<readonly ["reciprocalPole", "rationalHorizontal", "obliqueSlant"]>>;
129
+ readonly labels: Schema.Struct<{
130
+ readonly approachValue: Schema.optionalKey<RichSlot<E>>;
131
+ readonly asymptoteSummary: Schema.optionalKey<RichSlot<E>>;
132
+ readonly curve: Schema.Trimmed;
133
+ readonly curves: Schema.$Record<Schema.Literals<readonly ["reciprocalPole", "rationalHorizontal", "obliqueSlant"]>, Schema.optionalKey<Schema.Struct<{
134
+ readonly formula: RichSlot<E>;
135
+ readonly name: Schema.Trimmed;
136
+ }>>>;
137
+ readonly parts: Schema.$Record<Schema.Literals<readonly ["curveBranches", "verticalAsymptote", "horizontalAsymptote", "leftProbe", "rightProbe"]>, Schema.Trimmed>;
138
+ readonly probeX: Schema.Trimmed;
139
+ readonly view: Schema.Trimmed;
140
+ }>;
141
+ readonly probeX: Schema.Struct<{
142
+ readonly max: Schema.Finite;
143
+ readonly min: Schema.Finite;
144
+ readonly value: Schema.Finite;
145
+ }>;
146
+ }>, "figure">;
147
+ EpsilonDeltaBandLab: 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 epsilon: Schema.Struct<{
268
+ readonly max: Schema.Finite;
269
+ readonly min: Schema.Finite;
270
+ readonly value: Schema.Finite;
271
+ }>;
272
+ readonly functions: Schema.NonEmptyArray<Schema.Literals<readonly ["removableHole", "quadraticSmooth", "steepLinear"]>>;
273
+ readonly labels: Schema.Struct<{
274
+ readonly deltaBound: Schema.optionalKey<RichSlot<E>>;
275
+ readonly epsilon: Schema.Trimmed;
276
+ readonly functionLabel: Schema.Trimmed;
277
+ readonly functions: Schema.$Record<Schema.Literals<readonly ["removableHole", "quadraticSmooth", "steepLinear"]>, Schema.optionalKey<Schema.Struct<{
278
+ readonly formula: RichSlot<E>;
279
+ readonly name: Schema.Trimmed;
280
+ }>>>;
281
+ readonly limitVerdict: Schema.optionalKey<RichSlot<E>>;
282
+ readonly parts: Schema.$Record<Schema.Literals<readonly ["curvePath", "epsilonBand", "deltaBand", "holePoint", "limitTarget"]>, Schema.Trimmed>;
283
+ readonly view: Schema.Trimmed;
284
+ }>;
285
+ }>, "figure">;
286
+ SqueezeTheoremWaveLab: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
287
+ readonly description: RichSlot<E>;
288
+ readonly footer: Schema.optionalKey<Schema.Codec<readonly [{
289
+ readonly marks?: readonly [{
290
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
291
+ } | {
292
+ readonly attrs: {
293
+ readonly href: string;
294
+ };
295
+ readonly type: "link";
296
+ } | {
297
+ readonly attrs: {
298
+ readonly variant: "success" | "warning" | null;
299
+ };
300
+ readonly type: "highlight";
301
+ }, ...({
302
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
303
+ } | {
304
+ readonly attrs: {
305
+ readonly href: string;
306
+ };
307
+ readonly type: "link";
308
+ } | {
309
+ readonly attrs: {
310
+ readonly variant: "success" | "warning" | null;
311
+ };
312
+ readonly type: "highlight";
313
+ })[]];
314
+ readonly text: string;
315
+ readonly type: "text";
316
+ } | {
317
+ readonly attrs: {
318
+ readonly latex: string;
319
+ };
320
+ readonly marks?: readonly [{
321
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
322
+ } | {
323
+ readonly attrs: {
324
+ readonly href: string;
325
+ };
326
+ readonly type: "link";
327
+ } | {
328
+ readonly attrs: {
329
+ readonly variant: "success" | "warning" | null;
330
+ };
331
+ readonly type: "highlight";
332
+ }, ...({
333
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
334
+ } | {
335
+ readonly attrs: {
336
+ readonly href: string;
337
+ };
338
+ readonly type: "link";
339
+ } | {
340
+ readonly attrs: {
341
+ readonly variant: "success" | "warning" | null;
342
+ };
343
+ readonly type: "highlight";
344
+ })[]];
345
+ readonly type: "mathInline";
346
+ }, ...({
347
+ readonly marks?: readonly [{
348
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
349
+ } | {
350
+ readonly attrs: {
351
+ readonly href: string;
352
+ };
353
+ readonly type: "link";
354
+ } | {
355
+ readonly attrs: {
356
+ readonly variant: "success" | "warning" | null;
357
+ };
358
+ readonly type: "highlight";
359
+ }, ...({
360
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
361
+ } | {
362
+ readonly attrs: {
363
+ readonly href: string;
364
+ };
365
+ readonly type: "link";
366
+ } | {
367
+ readonly attrs: {
368
+ readonly variant: "success" | "warning" | null;
369
+ };
370
+ readonly type: "highlight";
371
+ })[]];
372
+ readonly text: string;
373
+ readonly type: "text";
374
+ } | {
375
+ readonly attrs: {
376
+ readonly latex: string;
377
+ };
378
+ readonly marks?: readonly [{
379
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
380
+ } | {
381
+ readonly attrs: {
382
+ readonly href: string;
383
+ };
384
+ readonly type: "link";
385
+ } | {
386
+ readonly attrs: {
387
+ readonly variant: "success" | "warning" | null;
388
+ };
389
+ readonly type: "highlight";
390
+ }, ...({
391
+ readonly type: "bold" | "code" | "italic" | "subscript" | "superscript" | "underline";
392
+ } | {
393
+ readonly attrs: {
394
+ readonly href: string;
395
+ };
396
+ readonly type: "link";
397
+ } | {
398
+ readonly attrs: {
399
+ readonly variant: "success" | "warning" | null;
400
+ };
401
+ readonly type: "highlight";
402
+ })[]];
403
+ readonly type: "mathInline";
404
+ })[]], E, never, never>>;
405
+ readonly title: RichSlot<E>;
406
+ readonly envelopes: Schema.NonEmptyArray<Schema.Literals<readonly ["quadraticSine", "linearDamped", "sincEnvelope"]>>;
407
+ readonly labels: Schema.Struct<{
408
+ readonly boundSpread: Schema.optionalKey<RichSlot<E>>;
409
+ readonly envelope: Schema.Trimmed;
410
+ readonly envelopes: Schema.$Record<Schema.Literals<readonly ["quadraticSine", "linearDamped", "sincEnvelope"]>, Schema.optionalKey<Schema.Struct<{
411
+ readonly formula: RichSlot<E>;
412
+ readonly name: Schema.Trimmed;
413
+ }>>>;
414
+ readonly parts: Schema.$Record<Schema.Literals<readonly ["upperBound", "lowerBound", "squeezedWave", "pinchPoint", "windowFrame"]>, Schema.Trimmed>;
415
+ readonly radius: Schema.Trimmed;
416
+ readonly squeezedLimit: Schema.optionalKey<RichSlot<E>>;
417
+ readonly view: Schema.Trimmed;
418
+ }>;
419
+ readonly radius: Schema.Struct<{
420
+ readonly max: Schema.Finite;
421
+ readonly min: Schema.Finite;
422
+ readonly value: Schema.Finite;
423
+ }>;
424
+ }>, "figure">;
425
+ };