@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.
- package/dist/hash/sha256.d.ts +16 -0
- package/dist/hash/sha256.js +164 -0
- package/dist/hash/stream.d.ts +7 -5
- package/dist/hash/stream.js +13 -18
- package/dist/math/boundary.js +3 -22
- package/dist/math/edge.d.ts +11 -0
- package/dist/math/edge.js +74 -0
- package/dist/math/graph.d.ts +9 -0
- package/dist/math/graph.js +66 -0
- package/dist/math/plane.js +6 -0
- package/dist/math/shape.d.ts +392 -0
- package/dist/math/shape.js +59 -0
- package/dist/math/straight.d.ts +13 -0
- package/dist/math/straight.js +26 -0
- package/dist/visual/biology/blood.d.ts +91 -0
- package/dist/visual/biology/blood.js +55 -0
- package/dist/visual/biology/heart.d.ts +92 -0
- package/dist/visual/biology/heart.js +54 -0
- package/dist/visual/biology/mitochondrion.d.ts +91 -0
- package/dist/visual/biology/mitochondrion.js +45 -0
- package/dist/visual/biology/muscle.d.ts +103 -0
- package/dist/visual/biology/muscle.js +62 -0
- package/dist/visual/biology/neuron.d.ts +97 -0
- package/dist/visual/biology/neuron.js +48 -0
- package/dist/visual/biology/paddy.d.ts +100 -0
- package/dist/visual/biology/paddy.js +54 -0
- package/dist/visual/biology/synapse.d.ts +101 -0
- package/dist/visual/biology/synapse.js +46 -0
- package/dist/visual/biology/vessel.d.ts +104 -0
- package/dist/visual/biology/vessel.js +60 -0
- package/dist/visual/biology/yeast.d.ts +108 -0
- package/dist/visual/biology/yeast.js +61 -0
- package/dist/visual/catalog.d.ts +2177 -778
- package/dist/visual/catalog.js +28 -0
- package/dist/visual/mathematics/journey.d.ts +118 -0
- package/dist/visual/mathematics/journey.js +125 -0
- package/dist/visual/mathematics/logic.d.ts +90 -0
- package/dist/visual/mathematics/logic.js +49 -0
- package/dist/visual/mathematics/network.d.ts +101 -0
- package/dist/visual/mathematics/network.js +97 -0
- package/dist/visual/mathematics/numeral.d.ts +81 -0
- package/dist/visual/mathematics/numeral.js +48 -0
- package/dist/visual/mathematics/sets.d.ts +92 -0
- package/dist/visual/mathematics/sets.js +95 -0
- package/dist/visual/physics/thermodynamics.d.ts +117 -0
- package/dist/visual/physics/thermodynamics.js +95 -0
- package/package.json +1 -1
package/dist/visual/catalog.js
CHANGED
|
@@ -5,11 +5,20 @@ import { mathVisuals } from "#contracts/visual/base/math";
|
|
|
5
5
|
import { mediaVisuals } from "#contracts/visual/base/media";
|
|
6
6
|
import { biologyVisuals } from "#contracts/visual/biology";
|
|
7
7
|
import { bacteriaVisuals } from "#contracts/visual/biology/bacteria";
|
|
8
|
+
import { bloodVisuals } from "#contracts/visual/biology/blood";
|
|
8
9
|
import { cellVisuals } from "#contracts/visual/biology/cell";
|
|
9
10
|
import { climateVisuals } from "#contracts/visual/biology/climate";
|
|
10
11
|
import { ecologyVisuals } from "#contracts/visual/biology/ecology";
|
|
12
|
+
import { heartVisuals } from "#contracts/visual/biology/heart";
|
|
13
|
+
import { mitochondrionVisuals } from "#contracts/visual/biology/mitochondrion";
|
|
14
|
+
import { muscleVisuals } from "#contracts/visual/biology/muscle";
|
|
15
|
+
import { neuronVisuals } from "#contracts/visual/biology/neuron";
|
|
16
|
+
import { paddyVisuals } from "#contracts/visual/biology/paddy";
|
|
11
17
|
import { physiologyVisuals } from "#contracts/visual/biology/physiology";
|
|
12
18
|
import { plantVisuals } from "#contracts/visual/biology/plant";
|
|
19
|
+
import { synapseVisuals } from "#contracts/visual/biology/synapse";
|
|
20
|
+
import { vesselVisuals } from "#contracts/visual/biology/vessel";
|
|
21
|
+
import { yeastVisuals } from "#contracts/visual/biology/yeast";
|
|
13
22
|
import { atomVisuals } from "#contracts/visual/chemistry/atom";
|
|
14
23
|
import { balanceVisuals } from "#contracts/visual/chemistry/balance";
|
|
15
24
|
import { bondingVisuals } from "#contracts/visual/chemistry/bonding";
|
|
@@ -26,7 +35,11 @@ import { chanceVisuals } from "#contracts/visual/mathematics/chance";
|
|
|
26
35
|
import { chartVisuals } from "#contracts/visual/mathematics/charts";
|
|
27
36
|
import { functionVisuals } from "#contracts/visual/mathematics/function";
|
|
28
37
|
import { geometryVisuals } from "#contracts/visual/mathematics/geometry";
|
|
38
|
+
import { journeyVisuals } from "#contracts/visual/mathematics/journey";
|
|
39
|
+
import { logicVisuals } from "#contracts/visual/mathematics/logic";
|
|
40
|
+
import { networkVisuals } from "#contracts/visual/mathematics/network";
|
|
29
41
|
import { numeralVisuals } from "#contracts/visual/mathematics/numeral";
|
|
42
|
+
import { setVisuals } from "#contracts/visual/mathematics/sets";
|
|
30
43
|
import { brakingVisuals } from "#contracts/visual/physics/braking";
|
|
31
44
|
import { circuitVisuals } from "#contracts/visual/physics/circuit";
|
|
32
45
|
import { circularVisuals } from "#contracts/visual/physics/circular";
|
|
@@ -53,6 +66,7 @@ import { readingVisuals } from "#contracts/visual/physics/reading";
|
|
|
53
66
|
import { recordVisuals } from "#contracts/visual/physics/record";
|
|
54
67
|
import { relativeVisuals } from "#contracts/visual/physics/relative";
|
|
55
68
|
import { solarVisuals } from "#contracts/visual/physics/solar";
|
|
69
|
+
import { thermodynamicsVisuals } from "#contracts/visual/physics/thermodynamics";
|
|
56
70
|
import { vectorVisuals } from "#contracts/visual/physics/vector";
|
|
57
71
|
import { velocityVisuals } from "#contracts/visual/physics/velocity";
|
|
58
72
|
import { waveVisuals } from "#contracts/visual/physics/wave";
|
|
@@ -85,7 +99,11 @@ export function visualCatalog(rich) {
|
|
|
85
99
|
...chartVisuals(rich),
|
|
86
100
|
...functionVisuals(rich),
|
|
87
101
|
...geometryVisuals(rich),
|
|
102
|
+
...journeyVisuals(rich),
|
|
103
|
+
...logicVisuals(rich),
|
|
104
|
+
...networkVisuals(rich),
|
|
88
105
|
...numeralVisuals(rich),
|
|
106
|
+
...setVisuals(rich),
|
|
89
107
|
...measurementVisuals(rich),
|
|
90
108
|
...motionVisuals(rich),
|
|
91
109
|
...parabolicVisuals(rich),
|
|
@@ -96,6 +114,15 @@ export function visualCatalog(rich) {
|
|
|
96
114
|
...ecologyVisuals(rich),
|
|
97
115
|
...physiologyVisuals(rich),
|
|
98
116
|
...plantVisuals(rich),
|
|
117
|
+
...heartVisuals(rich),
|
|
118
|
+
...vesselVisuals(rich),
|
|
119
|
+
...bloodVisuals(rich),
|
|
120
|
+
...neuronVisuals(rich),
|
|
121
|
+
...synapseVisuals(rich),
|
|
122
|
+
...mitochondrionVisuals(rich),
|
|
123
|
+
...muscleVisuals(rich),
|
|
124
|
+
...yeastVisuals(rich),
|
|
125
|
+
...paddyVisuals(rich),
|
|
99
126
|
...balanceVisuals(rich),
|
|
100
127
|
...bondingVisuals(rich),
|
|
101
128
|
...discoveryVisuals(rich),
|
|
@@ -120,6 +147,7 @@ export function visualCatalog(rich) {
|
|
|
120
147
|
...fluidVisuals(rich),
|
|
121
148
|
...gravityVisuals(rich),
|
|
122
149
|
...heatVisuals(rich),
|
|
150
|
+
...thermodynamicsVisuals(rich),
|
|
123
151
|
...lightVisuals(rich),
|
|
124
152
|
...nuclearVisuals(rich),
|
|
125
153
|
...readingVisuals(rich),
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import type { RichSlot } from "#contracts/visual/card";
|
|
3
|
+
/** The motion-graph labs, where a journey is read from its distance-time graph. */
|
|
4
|
+
export declare function journeyVisuals<E>(rich: RichSlot<E>): {
|
|
5
|
+
JourneyGraphLab: 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 bus: Schema.Struct<{
|
|
76
|
+
readonly legs: Schema.NonEmptyArray<Schema.Struct<{
|
|
77
|
+
readonly change: Schema.Finite;
|
|
78
|
+
readonly minutes: Schema.Int;
|
|
79
|
+
}>>;
|
|
80
|
+
readonly name: Schema.Trimmed;
|
|
81
|
+
}>;
|
|
82
|
+
readonly labels: Schema.Struct<{
|
|
83
|
+
readonly average: RichSlot<E>;
|
|
84
|
+
readonly axes: Schema.Struct<{
|
|
85
|
+
readonly distance: Schema.Trimmed;
|
|
86
|
+
readonly time: Schema.Trimmed;
|
|
87
|
+
}>;
|
|
88
|
+
readonly distance: RichSlot<E>;
|
|
89
|
+
readonly meeting: Schema.optionalKey<RichSlot<E>>;
|
|
90
|
+
readonly motion: Schema.$Record<Schema.Literals<readonly ["away", "back", "still"]>, RichSlot<E>>;
|
|
91
|
+
readonly parts: Schema.Trimmed;
|
|
92
|
+
readonly speed: RichSlot<E>;
|
|
93
|
+
readonly time: Schema.Trimmed;
|
|
94
|
+
readonly units: Schema.Struct<{
|
|
95
|
+
readonly distance: Schema.Trimmed;
|
|
96
|
+
readonly speed: Schema.Trimmed;
|
|
97
|
+
readonly time: Schema.Trimmed;
|
|
98
|
+
}>;
|
|
99
|
+
readonly viewLabel: Schema.Trimmed;
|
|
100
|
+
readonly whole: Schema.Trimmed;
|
|
101
|
+
}>;
|
|
102
|
+
readonly second: Schema.optionalKey<Schema.Struct<{
|
|
103
|
+
readonly depart: Schema.Int;
|
|
104
|
+
readonly from: Schema.Finite;
|
|
105
|
+
readonly legs: Schema.NonEmptyArray<Schema.Struct<{
|
|
106
|
+
readonly change: Schema.Finite;
|
|
107
|
+
readonly minutes: Schema.Int;
|
|
108
|
+
}>>;
|
|
109
|
+
readonly name: Schema.Trimmed;
|
|
110
|
+
}>>;
|
|
111
|
+
readonly showMeeting: Schema.optionalKey<Schema.Boolean>;
|
|
112
|
+
readonly showSpeeds: Schema.optionalKey<Schema.Boolean>;
|
|
113
|
+
readonly stops: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
114
|
+
readonly at: Schema.Finite;
|
|
115
|
+
readonly name: Schema.Trimmed;
|
|
116
|
+
}>>>;
|
|
117
|
+
}>, "figure">;
|
|
118
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
/** How a leg moves: away from the start, back toward it, or not at all. */
|
|
5
|
+
const MOTIONS = ["away", "back", "still"];
|
|
6
|
+
/** The most legs one traveller drives, so the toolbar's leg picker fits a phone. */
|
|
7
|
+
const LEG_LIMIT = 5;
|
|
8
|
+
/** A whole number of minutes, at least zero. */
|
|
9
|
+
const MinuteSchema = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
10
|
+
/** A distance from the start of the road in kilometres, never behind it. */
|
|
11
|
+
const DistanceSchema = Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0));
|
|
12
|
+
/** One leg: how many whole minutes it lasts, and how it changes the distance from the start, in kilometres. */
|
|
13
|
+
const LegSchema = Schema.Struct({
|
|
14
|
+
change: Schema.Finite,
|
|
15
|
+
minutes: Schema.Int.check(Schema.isGreaterThan(0)),
|
|
16
|
+
});
|
|
17
|
+
/** A traveller's legs in order, one to five of them. */
|
|
18
|
+
const LegsSchema = Schema.NonEmptyArray(LegSchema).check(Schema.isMaxLength(LEG_LIMIT));
|
|
19
|
+
/** The bus: it leaves the start of the road at minute 0. */
|
|
20
|
+
const BusSchema = Schema.Struct({ legs: LegsSchema, name: TextSchema });
|
|
21
|
+
/** A second traveller on the same road, leaving at its own minute and place. */
|
|
22
|
+
const SecondSchema = Schema.Struct({
|
|
23
|
+
depart: MinuteSchema,
|
|
24
|
+
from: DistanceSchema,
|
|
25
|
+
legs: LegsSchema,
|
|
26
|
+
name: TextSchema,
|
|
27
|
+
});
|
|
28
|
+
/** A named place on the road, such as a stop, at its distance from the start. */
|
|
29
|
+
const StopSchema = Schema.Struct({ at: DistanceSchema, name: TextSchema });
|
|
30
|
+
/** Whether a distance is written to at most one decimal place, as the graph's readouts print it. */
|
|
31
|
+
function inTenths(value) {
|
|
32
|
+
return Math.abs(value * 10 - Math.round(value * 10)) < 1e-9;
|
|
33
|
+
}
|
|
34
|
+
/** The distances from the start after each leg, beginning at `from`. */
|
|
35
|
+
function distancesAfter(from, legs) {
|
|
36
|
+
return Arr.scan(legs, from, (distance, leg) => distance + leg.change);
|
|
37
|
+
}
|
|
38
|
+
/** Whether a traveller's legs keep it on the road, never behind its start. */
|
|
39
|
+
function staysOnRoad(from, legs) {
|
|
40
|
+
return Arr.every(distancesAfter(from, legs), (distance) => distance >= 0);
|
|
41
|
+
}
|
|
42
|
+
/** Where the bus is at a minute: it moves steadily through each leg and waits at the end of its last. */
|
|
43
|
+
function busAt(legs, minute) {
|
|
44
|
+
return Arr.reduce(legs, { distance: 0, start: 0 }, (state, leg) => {
|
|
45
|
+
const into = Math.min(Math.max(minute - state.start, 0), leg.minutes);
|
|
46
|
+
return {
|
|
47
|
+
distance: state.distance + (leg.change * into) / leg.minutes,
|
|
48
|
+
start: state.start + leg.minutes,
|
|
49
|
+
};
|
|
50
|
+
}).distance;
|
|
51
|
+
}
|
|
52
|
+
/** Whether the second traveller sets off apart from the bus, so their first meeting is a real crossing. */
|
|
53
|
+
function startsApart(legs, second) {
|
|
54
|
+
return (second === undefined ||
|
|
55
|
+
Math.abs(busAt(legs, second.depart) - second.from) > 1e-9);
|
|
56
|
+
}
|
|
57
|
+
/** Whether the stops sit at distinct places within the stretch the bus drives. */
|
|
58
|
+
function stopsOnRoute(legs, stops) {
|
|
59
|
+
const farthest = Math.max(...distancesAfter(0, legs));
|
|
60
|
+
const places = Arr.map(stops, ({ at }) => at);
|
|
61
|
+
return (Arr.dedupe(places).length === places.length &&
|
|
62
|
+
Arr.every(places, (at) => at <= farthest));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Whether the journey draws a graph the lab can read: every change in
|
|
66
|
+
* tenths of a kilometre, at least one leg of the bus moving, both travellers
|
|
67
|
+
* staying on the road, a second traveller setting off apart from the bus,
|
|
68
|
+
* and the stops on the bus's stretch of road.
|
|
69
|
+
*/
|
|
70
|
+
function isJourney(bus, second, stops) {
|
|
71
|
+
const legs = Arr.appendAll(bus.legs, second?.legs ?? []);
|
|
72
|
+
return (Arr.every(legs, ({ change }) => inTenths(change)) &&
|
|
73
|
+
Arr.some(bus.legs, ({ change }) => change !== 0) &&
|
|
74
|
+
staysOnRoad(0, bus.legs) &&
|
|
75
|
+
(second === undefined || staysOnRoad(second.from, second.legs)) &&
|
|
76
|
+
startsApart(bus.legs, second) &&
|
|
77
|
+
stopsOnRoute(bus.legs, stops));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Props of `JourneyGraphLab`: a bus drives one straight road through its
|
|
81
|
+
* `stops` while its distance-time graph draws itself on graph paper beside
|
|
82
|
+
* the road, the paper's distance axis running the same way and to the same
|
|
83
|
+
* scale as the road. Each leg is a segment named by its corners O, A, B and
|
|
84
|
+
* on; picking one draws its rise and run, and the footer works out its speed
|
|
85
|
+
* as distance over time, while the whole journey shows its average speed.
|
|
86
|
+
* An optional `second` traveller has its own line, and where the two lines
|
|
87
|
+
* first cross they meet. Speeds are in the unit per hour, worked out from
|
|
88
|
+
* kilometres and minutes. With `showSpeeds`, the footer shows each speed,
|
|
89
|
+
* and with `showMeeting` the meeting time and place and its mark on the
|
|
90
|
+
* graph, so both are answer state.
|
|
91
|
+
*/
|
|
92
|
+
function journeyGraphLab(rich) {
|
|
93
|
+
return figure(Schema.Struct({
|
|
94
|
+
...cardFields(rich),
|
|
95
|
+
bus: BusSchema,
|
|
96
|
+
labels: Schema.Struct({
|
|
97
|
+
average: rich,
|
|
98
|
+
axes: Schema.Struct({ distance: TextSchema, time: TextSchema }),
|
|
99
|
+
distance: rich,
|
|
100
|
+
meeting: Schema.optionalKey(rich),
|
|
101
|
+
motion: byIds(MOTIONS, rich),
|
|
102
|
+
parts: TextSchema,
|
|
103
|
+
speed: rich,
|
|
104
|
+
time: TextSchema,
|
|
105
|
+
units: Schema.Struct({
|
|
106
|
+
distance: TextSchema,
|
|
107
|
+
speed: TextSchema,
|
|
108
|
+
time: TextSchema,
|
|
109
|
+
}),
|
|
110
|
+
viewLabel: TextSchema,
|
|
111
|
+
whole: TextSchema,
|
|
112
|
+
}),
|
|
113
|
+
second: Schema.optionalKey(SecondSchema),
|
|
114
|
+
showMeeting: Schema.optionalKey(Schema.Boolean),
|
|
115
|
+
showSpeeds: Schema.optionalKey(Schema.Boolean),
|
|
116
|
+
stops: Schema.optionalKey(Schema.Array(StopSchema)),
|
|
117
|
+
}).check(Schema.makeFilter(({ bus, labels, second, stops = [] }) => isJourney(bus, second, stops) &&
|
|
118
|
+
(second === undefined || labels.meeting !== undefined), {
|
|
119
|
+
message: "Expected changes in tenths of a kilometre, a bus that moves, travellers that never go behind the start, a second traveller that sets off apart from the bus with a meeting label, and stops at distinct places on the bus's stretch.",
|
|
120
|
+
})), answerAt(["showSpeeds"], ["showMeeting"]));
|
|
121
|
+
}
|
|
122
|
+
/** The motion-graph labs, where a journey is read from its distance-time graph. */
|
|
123
|
+
export function journeyVisuals(rich) {
|
|
124
|
+
return { JourneyGraphLab: journeyGraphLab(rich) };
|
|
125
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import type { RichSlot } from "#contracts/visual/card";
|
|
3
|
+
/** The logic labs, where the truth of a compound statement is read. */
|
|
4
|
+
export declare function logicVisuals<E>(rich: RichSlot<E>): {
|
|
5
|
+
SwitchLogicLab: 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 modes: Schema.NonEmptyArray<Schema.Literals<readonly ["and", "or", "not"]>>;
|
|
76
|
+
readonly startMode: Schema.optionalKey<Schema.Literals<readonly ["and", "or", "not"]>>;
|
|
77
|
+
readonly labels: Schema.Struct<{
|
|
78
|
+
readonly compounds: Schema.$Record<Schema.Literals<readonly ["and", "or", "not"]>, RichSlot<E>>;
|
|
79
|
+
readonly false: Schema.Trimmed;
|
|
80
|
+
readonly mode: Schema.Trimmed;
|
|
81
|
+
readonly modes: Schema.$Record<Schema.Literals<readonly ["and", "or", "not"]>, Schema.Trimmed>;
|
|
82
|
+
readonly p: RichSlot<E>;
|
|
83
|
+
readonly q: RichSlot<E>;
|
|
84
|
+
readonly switches: Schema.Trimmed;
|
|
85
|
+
readonly true: Schema.Trimmed;
|
|
86
|
+
readonly viewLabel: Schema.Trimmed;
|
|
87
|
+
}>;
|
|
88
|
+
readonly showTable: Schema.optionalKey<Schema.Boolean>;
|
|
89
|
+
}>, "figure">;
|
|
90
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
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 circuits the board wires: switches in a row, side by side, or across the lamp. */
|
|
5
|
+
const LOGIC_MODES = ["and", "or", "not"];
|
|
6
|
+
/** One circuit, named by the compound statement its lamp shows. */
|
|
7
|
+
const LogicModeSchema = Schema.Literals(LOGIC_MODES);
|
|
8
|
+
/** The circuits a lab offers and the one it opens on, the first when unset. */
|
|
9
|
+
const ModeChoiceSchema = Schema.Struct({
|
|
10
|
+
modes: Schema.NonEmptyArray(LogicModeSchema),
|
|
11
|
+
startMode: Schema.optionalKey(LogicModeSchema),
|
|
12
|
+
});
|
|
13
|
+
/** Whether each circuit is offered once and the opening circuit is one of them. */
|
|
14
|
+
function isModeChoice({ modes, startMode }) {
|
|
15
|
+
return (Arr.dedupe(modes).length === modes.length &&
|
|
16
|
+
(startMode === undefined || Arr.contains(modes, startMode)));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Props of `SwitchLogicLab`: a battery, a lamp and switches P and Q on a
|
|
20
|
+
* pegboard, wired in a row for `p ∧ q`, side by side for `p ∨ q`, or across
|
|
21
|
+
* the lamp for `~p`. The learner closes and opens the switches, a lit lamp
|
|
22
|
+
* means the compound statement is true, and each case fills its row of the
|
|
23
|
+
* truth table as it is tried. With `showTable`, every row's compound value
|
|
24
|
+
* shows from the start, so it is answer state.
|
|
25
|
+
*/
|
|
26
|
+
function switchLogicLab(rich) {
|
|
27
|
+
return figure(Schema.Struct({
|
|
28
|
+
...cardFields(rich),
|
|
29
|
+
labels: Schema.Struct({
|
|
30
|
+
compounds: byIds(LOGIC_MODES, rich),
|
|
31
|
+
false: TextSchema,
|
|
32
|
+
mode: TextSchema,
|
|
33
|
+
modes: byIds(LOGIC_MODES, TextSchema),
|
|
34
|
+
p: rich,
|
|
35
|
+
q: rich,
|
|
36
|
+
switches: TextSchema,
|
|
37
|
+
true: TextSchema,
|
|
38
|
+
viewLabel: TextSchema,
|
|
39
|
+
}),
|
|
40
|
+
...ModeChoiceSchema.fields,
|
|
41
|
+
showTable: Schema.optionalKey(Schema.Boolean),
|
|
42
|
+
}).check(Schema.makeFilter(isModeChoice, {
|
|
43
|
+
message: "Expected each circuit once, and an opening circuit that is one of them.",
|
|
44
|
+
})), answerAt(["showTable"]));
|
|
45
|
+
}
|
|
46
|
+
/** The logic labs, where the truth of a compound statement is read. */
|
|
47
|
+
export function logicVisuals(rich) {
|
|
48
|
+
return { SwitchLogicLab: switchLogicLab(rich) };
|
|
49
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import type { RichSlot } from "#contracts/visual/card";
|
|
3
|
+
/** The graph-theory labs, where a network of vertices and edges is read. */
|
|
4
|
+
export declare function networkVisuals<E>(rich: RichSlot<E>): {
|
|
5
|
+
RouteNetworkLab: 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 end: Schema.String;
|
|
76
|
+
readonly roads: Schema.NonEmptyArray<Schema.Struct<{
|
|
77
|
+
readonly from: Schema.String;
|
|
78
|
+
readonly length: Schema.Finite;
|
|
79
|
+
readonly to: Schema.String;
|
|
80
|
+
}>>;
|
|
81
|
+
readonly start: Schema.String;
|
|
82
|
+
readonly towns: Schema.NonEmptyArray<Schema.Struct<{
|
|
83
|
+
readonly id: Schema.String;
|
|
84
|
+
readonly name: Schema.Trimmed;
|
|
85
|
+
}>>;
|
|
86
|
+
readonly labels: Schema.Struct<{
|
|
87
|
+
readonly degreeSum: RichSlot<E>;
|
|
88
|
+
readonly length: RichSlot<E>;
|
|
89
|
+
readonly mode: Schema.Trimmed;
|
|
90
|
+
readonly modes: Schema.$Record<Schema.Literals<readonly ["degrees", "route"]>, Schema.Trimmed>;
|
|
91
|
+
readonly route: Schema.Trimmed;
|
|
92
|
+
readonly shortest: RichSlot<E>;
|
|
93
|
+
readonly town: Schema.Trimmed;
|
|
94
|
+
readonly trip: RichSlot<E>;
|
|
95
|
+
readonly twiceRoads: RichSlot<E>;
|
|
96
|
+
readonly viewLabel: Schema.Trimmed;
|
|
97
|
+
}>;
|
|
98
|
+
readonly mode: Schema.optionalKey<Schema.Literals<readonly ["degrees", "route"]>>;
|
|
99
|
+
readonly showShortest: Schema.optionalKey<Schema.Boolean>;
|
|
100
|
+
}>, "figure">;
|
|
101
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
/** What the learner looks at: the degree of each town, or routes between two towns. */
|
|
5
|
+
const NETWORK_MODES = ["degrees", "route"];
|
|
6
|
+
/** The fewest and the most towns the board shows legibly on a phone. */
|
|
7
|
+
const TOWN_RANGE = { maximum: 8, minimum: 2 };
|
|
8
|
+
/** The id a road and a route use to name a town. */
|
|
9
|
+
const TownIdSchema = Schema.String.check(Schema.isNonEmpty());
|
|
10
|
+
/** One town: a vertex of the network, with the name its sign shows. */
|
|
11
|
+
const TownSchema = Schema.Struct({ id: TownIdSchema, name: TextSchema });
|
|
12
|
+
/** One road: an edge of the network, weighted by its length in kilometres. */
|
|
13
|
+
const RoadSchema = Schema.Struct({
|
|
14
|
+
from: TownIdSchema,
|
|
15
|
+
length: Schema.Finite.check(Schema.isGreaterThan(0)),
|
|
16
|
+
to: TownIdSchema,
|
|
17
|
+
});
|
|
18
|
+
/** The towns, the roads between them, and the trip's two ends. */
|
|
19
|
+
const NetworkSchema = Schema.Struct({
|
|
20
|
+
end: TownIdSchema,
|
|
21
|
+
roads: Schema.NonEmptyArray(RoadSchema),
|
|
22
|
+
start: TownIdSchema,
|
|
23
|
+
towns: Schema.NonEmptyArray(TownSchema).check(Schema.isMinLength(TOWN_RANGE.minimum), Schema.isMaxLength(TOWN_RANGE.maximum)),
|
|
24
|
+
});
|
|
25
|
+
/** The unordered pair a road joins, so a road and its reverse read the same. */
|
|
26
|
+
function roadPair({ from, to }) {
|
|
27
|
+
return from < to ? `${from}|${to}` : `${to}|${from}`;
|
|
28
|
+
}
|
|
29
|
+
/** The towns a road leads to from the frontier that were not reached before. */
|
|
30
|
+
function newTowns({ from, to }, frontier, reached) {
|
|
31
|
+
if (Arr.contains(frontier, from) && !Arr.contains(reached, to)) {
|
|
32
|
+
return [to];
|
|
33
|
+
}
|
|
34
|
+
if (Arr.contains(frontier, to) && !Arr.contains(reached, from)) {
|
|
35
|
+
return [from];
|
|
36
|
+
}
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
/** The towns reachable along the roads, widening from the frontier one road at a time. */
|
|
40
|
+
function reachedTowns(roads, reached, frontier) {
|
|
41
|
+
const next = Arr.dedupe(Arr.flatMap(roads, (road) => newTowns(road, frontier, reached)));
|
|
42
|
+
return next.length === 0
|
|
43
|
+
? reached
|
|
44
|
+
: reachedTowns(roads, Arr.appendAll(reached, next), next);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Whether the network is one simple, connected graph: each town once, each
|
|
48
|
+
* road joining two different listed towns at most once in either direction,
|
|
49
|
+
* every town reachable, and the trip running between two different towns.
|
|
50
|
+
*/
|
|
51
|
+
function isSimpleNetwork(network) {
|
|
52
|
+
const ids = Arr.map(network.towns, ({ id }) => id);
|
|
53
|
+
/** Whether the network lists a town with this id. */
|
|
54
|
+
const listed = (id) => Arr.contains(ids, id);
|
|
55
|
+
const pairs = Arr.map(network.roads, roadPair);
|
|
56
|
+
return (Arr.dedupe(ids).length === ids.length &&
|
|
57
|
+
Arr.every(network.roads, ({ from, to }) => from !== to && listed(from) && listed(to)) &&
|
|
58
|
+
Arr.dedupe(pairs).length === pairs.length &&
|
|
59
|
+
reachedTowns(network.roads, [ids[0]], [ids[0]]).length === ids.length &&
|
|
60
|
+
network.start !== network.end &&
|
|
61
|
+
listed(network.start) &&
|
|
62
|
+
listed(network.end));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Props of `RouteNetworkLab`: a network as a model landscape of `towns`
|
|
66
|
+
* joined by weighted `roads`. In the degrees mode each town shows how many
|
|
67
|
+
* roads meet there and the footer adds the degrees up to twice the number of
|
|
68
|
+
* roads; in the route mode the learner picks a route from `start` to `end`, a
|
|
69
|
+
* van drives it, and the footer adds up its roads. With `showShortest`, the
|
|
70
|
+
* footer also names the shortest route and its length, so it is answer state.
|
|
71
|
+
*/
|
|
72
|
+
function routeNetworkLab(rich) {
|
|
73
|
+
return figure(Schema.Struct({
|
|
74
|
+
...cardFields(rich),
|
|
75
|
+
...NetworkSchema.fields,
|
|
76
|
+
labels: Schema.Struct({
|
|
77
|
+
degreeSum: rich,
|
|
78
|
+
length: rich,
|
|
79
|
+
mode: TextSchema,
|
|
80
|
+
modes: byIds(NETWORK_MODES, TextSchema),
|
|
81
|
+
route: TextSchema,
|
|
82
|
+
shortest: rich,
|
|
83
|
+
town: TextSchema,
|
|
84
|
+
trip: rich,
|
|
85
|
+
twiceRoads: rich,
|
|
86
|
+
viewLabel: TextSchema,
|
|
87
|
+
}),
|
|
88
|
+
mode: Schema.optionalKey(Schema.Literals(NETWORK_MODES)),
|
|
89
|
+
showShortest: Schema.optionalKey(Schema.Boolean),
|
|
90
|
+
}).check(Schema.makeFilter(isSimpleNetwork, {
|
|
91
|
+
message: "Expected each town once, roads between two different listed towns at most once each, one connected network, and a trip between two different towns.",
|
|
92
|
+
})), answerAt(["showShortest"]));
|
|
93
|
+
}
|
|
94
|
+
/** The graph-theory labs, where a network of vertices and edges is read. */
|
|
95
|
+
export function networkVisuals(rich) {
|
|
96
|
+
return { RouteNetworkLab: routeNetworkLab(rich) };
|
|
97
|
+
}
|