@nakafa/aksara-contracts 6.5.0 → 7.1.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 (159) hide show
  1. package/dist/assessment/catalog.d.ts +18 -5
  2. package/dist/assessment/catalog.js +18 -8
  3. package/dist/assessment/choice.d.ts +10 -0
  4. package/dist/assessment/closure.d.ts +2 -1
  5. package/dist/assessment/closure.js +43 -62
  6. package/dist/assessment/document.d.ts +18 -0
  7. package/dist/assessment/document.js +10 -0
  8. package/dist/assessment/figure.d.ts +25 -2676
  9. package/dist/assessment/figure.js +17 -216
  10. package/dist/assessment/hash.d.ts +274 -4
  11. package/dist/assessment/inline.d.ts +25 -0
  12. package/dist/assessment/inline.js +22 -3
  13. package/dist/assessment/interaction.d.ts +10 -0
  14. package/dist/assessment/item.d.ts +864 -0
  15. package/dist/assessment/item.js +10 -2
  16. package/dist/assessment/locales.d.ts +10 -0
  17. package/dist/assessment/locales.js +58 -0
  18. package/dist/assessment/paper.d.ts +1349 -12
  19. package/dist/assessment/paper.js +93 -9
  20. package/dist/assessment/part.d.ts +5 -0
  21. package/dist/assessment/profile.d.ts +4 -4
  22. package/dist/assessment/rows.d.ts +1409 -0
  23. package/dist/assessment/rows.js +44 -0
  24. package/dist/assessment/scalar.d.ts +1 -1
  25. package/dist/assessment/scoring.d.ts +1 -1
  26. package/dist/assessment/snapshot.d.ts +372 -20
  27. package/dist/assessment/structure.d.ts +6 -0
  28. package/dist/assessment/structure.js +22 -2
  29. package/dist/locale.d.ts +9 -9
  30. package/dist/locale.js +4 -3
  31. package/dist/program/snapshot/hash.d.ts +2 -2
  32. package/dist/program/snapshot/spec.d.ts +2 -2
  33. package/dist/projection/material.d.ts +10 -0
  34. package/dist/projection/material.js +1 -1
  35. package/dist/quran/attribution.d.ts +2 -2
  36. package/dist/quran/identity.d.ts +31 -10
  37. package/dist/quran/identity.js +15 -3
  38. package/dist/quran/provenance.d.ts +16 -16
  39. package/dist/quran/provenance.js +4 -1
  40. package/dist/quran/snapshot/hash.d.ts +2 -2
  41. package/dist/quran/snapshot/row/hash.d.ts +48 -15
  42. package/dist/quran/snapshot/row.d.ts +18 -8
  43. package/dist/quran/snapshot/spec.d.ts +2 -2
  44. package/dist/quran/source.d.ts +17 -7
  45. package/dist/quran/source.js +13 -1
  46. package/dist/quran/spec.d.ts +4 -4
  47. package/dist/quran/spec.js +2 -1
  48. package/dist/release/current/evidence.d.ts +9 -9
  49. package/dist/release/current/state.d.ts +11 -11
  50. package/dist/release/hash.d.ts +2 -2
  51. package/dist/release/identity.d.ts +1 -1
  52. package/dist/release/lifecycle.d.ts +7 -7
  53. package/dist/release/policy.d.ts +1 -1
  54. package/dist/release/snapshot/data.d.ts +36 -11
  55. package/dist/release/snapshot/evidence/assessment.d.ts +1 -1
  56. package/dist/release/snapshot/evidence/program.d.ts +1 -1
  57. package/dist/release/snapshot/evidence/quran.d.ts +1 -1
  58. package/dist/release/snapshot/evidence.d.ts +3 -3
  59. package/dist/release/snapshot/verify.d.ts +179 -12
  60. package/dist/release/spec.d.ts +13 -13
  61. package/dist/release/verify.d.ts +2 -2
  62. package/dist/runtime/spec.d.ts +6 -6
  63. package/dist/runtime/verify.d.ts +4 -4
  64. package/dist/transport/group.d.ts +108 -33
  65. package/dist/transport/request.d.ts +1166 -114
  66. package/dist/transport/response.d.ts +64 -64
  67. package/dist/transport/snapshot.d.ts +72 -22
  68. package/dist/visual/base/layout.d.ts +27 -0
  69. package/dist/visual/base/layout.js +35 -0
  70. package/dist/visual/base/math.d.ts +523 -0
  71. package/dist/visual/base/math.js +72 -0
  72. package/dist/visual/base/media.d.ts +13 -0
  73. package/dist/visual/base/media.js +25 -0
  74. package/dist/visual/biology/bacteria.d.ts +55 -0
  75. package/dist/visual/biology/bacteria.js +79 -0
  76. package/dist/visual/biology/cell.d.ts +89 -0
  77. package/dist/visual/biology/cell.js +95 -0
  78. package/dist/visual/biology/climate.d.ts +75 -0
  79. package/dist/visual/biology/climate.js +94 -0
  80. package/dist/visual/biology/ecology.d.ts +75 -0
  81. package/dist/visual/biology/ecology.js +94 -0
  82. package/dist/visual/biology.d.ts +203 -0
  83. package/dist/visual/biology.js +108 -0
  84. package/dist/visual/card.d.ts +32 -0
  85. package/dist/visual/card.js +30 -0
  86. package/dist/visual/catalog.d.ts +3372 -0
  87. package/dist/visual/catalog.js +119 -0
  88. package/dist/visual/chemistry/atom.d.ts +79 -0
  89. package/dist/visual/chemistry/atom.js +109 -0
  90. package/dist/visual/chemistry/balance.d.ts +79 -0
  91. package/dist/visual/chemistry/balance.js +128 -0
  92. package/dist/visual/chemistry/bonding.d.ts +80 -0
  93. package/dist/visual/chemistry/bonding.js +147 -0
  94. package/dist/visual/chemistry/discovery.d.ts +96 -0
  95. package/dist/visual/chemistry/discovery.js +137 -0
  96. package/dist/visual/chemistry/electron.d.ts +41 -0
  97. package/dist/visual/chemistry/electron.js +69 -0
  98. package/dist/visual/chemistry/laws.d.ts +86 -0
  99. package/dist/visual/chemistry/laws.js +117 -0
  100. package/dist/visual/chemistry/particles.d.ts +114 -0
  101. package/dist/visual/chemistry/particles.js +149 -0
  102. package/dist/visual/chemistry/periodic.d.ts +52 -0
  103. package/dist/visual/chemistry/periodic.js +85 -0
  104. package/dist/visual/chemistry/reaction.d.ts +60 -0
  105. package/dist/visual/chemistry/reaction.js +76 -0
  106. package/dist/visual/entry.d.ts +42 -0
  107. package/dist/visual/entry.js +48 -0
  108. package/dist/visual/mathematics/chart.d.ts +30 -0
  109. package/dist/{assessment → visual/mathematics}/chart.js +26 -18
  110. package/dist/visual/mathematics/charts.d.ts +118 -0
  111. package/dist/visual/mathematics/charts.js +100 -0
  112. package/dist/visual/mathematics/function.d.ts +82 -0
  113. package/dist/visual/mathematics/function.js +102 -0
  114. package/dist/visual/mathematics/geometry.d.ts +222 -0
  115. package/dist/visual/mathematics/geometry.js +81 -0
  116. package/dist/visual/mathematics/line.d.ts +179 -0
  117. package/dist/visual/mathematics/line.js +156 -0
  118. package/dist/visual/mathematics/number.d.ts +21 -0
  119. package/dist/visual/mathematics/number.js +53 -0
  120. package/dist/visual/physics/braking.d.ts +62 -0
  121. package/dist/visual/physics/braking.js +83 -0
  122. package/dist/visual/physics/circular.d.ts +36 -0
  123. package/dist/visual/physics/circular.js +51 -0
  124. package/dist/visual/physics/efficiency.d.ts +93 -0
  125. package/dist/visual/physics/efficiency.js +129 -0
  126. package/dist/visual/physics/falling.d.ts +56 -0
  127. package/dist/visual/physics/falling.js +77 -0
  128. package/dist/visual/physics/force.d.ts +88 -0
  129. package/dist/visual/physics/force.js +115 -0
  130. package/dist/visual/physics/instrument.d.ts +93 -0
  131. package/dist/visual/physics/instrument.js +135 -0
  132. package/dist/visual/physics/measurement.d.ts +66 -0
  133. package/dist/visual/physics/measurement.js +85 -0
  134. package/dist/visual/physics/motion.d.ts +85 -0
  135. package/dist/visual/physics/motion.js +110 -0
  136. package/dist/visual/physics/parabolic.d.ts +42 -0
  137. package/dist/visual/physics/parabolic.js +56 -0
  138. package/dist/visual/physics/position.d.ts +87 -0
  139. package/dist/visual/physics/position.js +123 -0
  140. package/dist/visual/physics/power.d.ts +121 -0
  141. package/dist/visual/physics/power.js +162 -0
  142. package/dist/visual/physics/precision.d.ts +96 -0
  143. package/dist/visual/physics/precision.js +137 -0
  144. package/dist/visual/physics/product.d.ts +73 -0
  145. package/dist/visual/physics/product.js +96 -0
  146. package/dist/visual/physics/record.d.ts +34 -0
  147. package/dist/visual/physics/record.js +46 -0
  148. package/dist/visual/physics/relative.d.ts +55 -0
  149. package/dist/visual/physics/relative.js +76 -0
  150. package/dist/visual/physics/solar.d.ts +91 -0
  151. package/dist/visual/physics/solar.js +126 -0
  152. package/dist/visual/physics/vector.d.ts +103 -0
  153. package/dist/visual/physics/vector.js +123 -0
  154. package/dist/visual/physics/velocity.d.ts +112 -0
  155. package/dist/visual/physics/velocity.js +144 -0
  156. package/dist/visual/politics.d.ts +92 -0
  157. package/dist/visual/politics.js +76 -0
  158. package/package.json +13 -5
  159. package/dist/assessment/chart.d.ts +0 -62
@@ -0,0 +1,42 @@
1
+ import { Schema } from "effect";
2
+ /**
3
+ * How a document draws a catalog component. A `figure` is a visual that a
4
+ * lesson places as an element and an assessment places as a figure node. A
5
+ * `markup` component shapes text or layout instead, such as a formula, a
6
+ * highlighted phrase, or a stack of blocks, and an assessment writes it as
7
+ * nodes and marks of its own.
8
+ */
9
+ export type VisualKind = "figure" | "markup";
10
+ /**
11
+ * One step of an answer path: a prop name, or `*` for every entry of a record
12
+ * or every item of a list.
13
+ */
14
+ export type AnswerStep = string;
15
+ /** The path of a prop that holds answer state, such as `["trigValues"]`. */
16
+ export type AnswerPattern = readonly [AnswerStep, ...AnswerStep[]];
17
+ /**
18
+ * Lists the answer state that decoded props hold, each as the dotted path of a
19
+ * prop that is present, such as `labels.modes.closed.calculation`.
20
+ */
21
+ export type AnswerReader = (props: unknown) => readonly string[];
22
+ /**
23
+ * One component of the catalog: its kind, the schema of its props in one
24
+ * document kind, and the reader of the answer state those props hold.
25
+ */
26
+ export interface VisualEntry<Props extends Schema.Top, Kind extends VisualKind = VisualKind> {
27
+ readonly answer: AnswerReader;
28
+ readonly kind: Kind;
29
+ readonly props: Props;
30
+ }
31
+ /**
32
+ * Reads answer state at fixed paths: every prop that one of the patterns names
33
+ * and that the props hold, written as its dotted path. A flag set to `false`
34
+ * shows nothing, so it holds no answer state.
35
+ */
36
+ export declare function answerAt(...patterns: readonly AnswerPattern[]): AnswerReader;
37
+ /** A component whose props never hold answer state. */
38
+ export declare const noAnswer: AnswerReader;
39
+ /** A figure component, with the answer state its props may hold. */
40
+ export declare function figure<Props extends Schema.Top>(props: Props, answer?: AnswerReader): VisualEntry<Props, "figure">;
41
+ /** A markup component: a formula, an emphasis, or a layout around blocks. */
42
+ export declare function markup<Props extends Schema.Top>(props: Props): VisualEntry<Props, "markup">;
@@ -0,0 +1,48 @@
1
+ import { Array as Arr, Predicate, Record as Rec, Schema } from "effect";
2
+ /** The value one step of a path names in a value, with the path so far. */
3
+ const LocatedSchema = Schema.Struct({
4
+ path: Schema.Array(Schema.String),
5
+ value: Schema.Unknown,
6
+ });
7
+ /** Follows one step of a path from every value reached so far. */
8
+ function stepInto(located, step) {
9
+ return Arr.flatMap(located, ({ path, value }) => {
10
+ if (Arr.isArray(value)) {
11
+ return step === "*"
12
+ ? Arr.map(value, (item, index) => ({
13
+ path: [...path, String(index)],
14
+ value: item,
15
+ }))
16
+ : [];
17
+ }
18
+ if (!Predicate.isObject(value)) {
19
+ return [];
20
+ }
21
+ if (step !== "*") {
22
+ const next = Predicate.hasProperty(value, step) ? value[step] : false;
23
+ return next === false ? [] : [{ path: [...path, step], value: next }];
24
+ }
25
+ return Arr.map(Rec.toEntries(value), ([key, item]) => ({
26
+ path: [...path, key],
27
+ value: item,
28
+ }));
29
+ });
30
+ }
31
+ /**
32
+ * Reads answer state at fixed paths: every prop that one of the patterns names
33
+ * and that the props hold, written as its dotted path. A flag set to `false`
34
+ * shows nothing, so it holds no answer state.
35
+ */
36
+ export function answerAt(...patterns) {
37
+ return (props) => Arr.flatMap(patterns, (pattern) => Arr.map(Arr.reduce(pattern, [{ path: [], value: props }], stepInto), ({ path }) => Arr.join(path, ".")));
38
+ }
39
+ /** A component whose props never hold answer state. */
40
+ export const noAnswer = () => [];
41
+ /** A figure component, with the answer state its props may hold. */
42
+ export function figure(props, answer = noAnswer) {
43
+ return { answer, kind: "figure", props };
44
+ }
45
+ /** A markup component: a formula, an emphasis, or a layout around blocks. */
46
+ export function markup(props) {
47
+ return { answer: noAnswer, kind: "markup", props };
48
+ }
@@ -0,0 +1,30 @@
1
+ import { Schema } from "effect";
2
+ import { type RichSlot } from "#contracts/visual/card";
3
+ /**
4
+ * Props of `Chart`: categories along one axis and one or more series of
5
+ * values drawn as bars or lines over them, the data of a bar chart, a line
6
+ * chart, a histogram, or both marks at once. The data is the figure, so a
7
+ * learner reads the same values that the figure draws. Every series has a
8
+ * name, because no meaning may ride on color alone.
9
+ */
10
+ export declare function chartProps<E>(rich: RichSlot<E>): import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
11
+ readonly description: RichSlot<E>;
12
+ readonly title: RichSlot<E>;
13
+ /**
14
+ * How the bars of a chart that has bars stand: `apart` leaves a gap between
15
+ * neighboring categories, as a bar chart does, and `touching` closes it, as
16
+ * a histogram of classes does. A chart of lines alone has no bars to place.
17
+ */
18
+ readonly bars: Schema.optionalKey<Schema.Literals<readonly ["apart", "touching"]>>;
19
+ readonly categories: Schema.NonEmptyArray<Schema.Trimmed>;
20
+ readonly series: Schema.NonEmptyArray<Schema.Struct<{
21
+ readonly label: Schema.Trimmed;
22
+ readonly mark: Schema.Literals<readonly ["bar", "line"]>;
23
+ readonly values: Schema.NonEmptyArray<Schema.NullOr<Schema.Finite>>;
24
+ }>>;
25
+ readonly valueLabel: Schema.optionalKey<Schema.Trimmed>;
26
+ readonly valueRange: Schema.optionalKey<Schema.Struct<{
27
+ readonly max: Schema.Finite;
28
+ readonly min: Schema.Finite;
29
+ }>>;
30
+ }>, "figure">;
@@ -1,7 +1,7 @@
1
1
  import { Array as Arr, Schema } from "effect";
2
2
  import { hasDistinctIds } from "#contracts/assessment/identity";
3
- import { RichTextSchema } from "#contracts/assessment/inline";
4
- import { PlainTextSchema } from "#contracts/assessment/scalar";
3
+ import { cardFields, TextSchema } from "#contracts/visual/card";
4
+ import { figure } from "#contracts/visual/entry";
5
5
  /**
6
6
  * One series of a chart: its name, whether it is drawn as bars or as a line,
7
7
  * and one value for each category. A value is null where the series has no
@@ -9,7 +9,7 @@ import { PlainTextSchema } from "#contracts/assessment/scalar";
9
9
  * some years.
10
10
  */
11
11
  const ChartSeriesSchema = Schema.Struct({
12
- label: PlainTextSchema,
12
+ label: TextSchema,
13
13
  mark: Schema.Literals(["bar", "line"]),
14
14
  values: Schema.NonEmptyArray(Schema.NullOr(Schema.Finite)),
15
15
  });
@@ -20,20 +20,26 @@ const ValueRangeSchema = Schema.Struct({
20
20
  }).check(Schema.makeFilter(({ max, min }) => min < max, {
21
21
  message: "Expected a value range whose minimum is below its maximum.",
22
22
  }));
23
- const ChartFieldsSchema = Schema.Struct({
23
+ /** The data a chart relates: its bar placement, its categories, and its series. */
24
+ const ChartDataSchema = Schema.Struct({
24
25
  /**
25
26
  * How the bars of a chart that has bars stand: `apart` leaves a gap between
26
- * neighboring categories, as a bar chart does, and `touching` closes it, as a
27
- * histogram of classes does. A chart of lines alone has no bars to place.
27
+ * neighboring categories, as a bar chart does, and `touching` closes it, as
28
+ * a histogram of classes does. A chart of lines alone has no bars to place.
28
29
  */
29
30
  bars: Schema.optionalKey(Schema.Literals(["apart", "touching"])),
30
- categories: Schema.NonEmptyArray(PlainTextSchema),
31
- description: RichTextSchema,
31
+ categories: Schema.NonEmptyArray(TextSchema),
32
32
  series: Schema.NonEmptyArray(ChartSeriesSchema),
33
- title: RichTextSchema,
34
- valueLabel: Schema.optionalKey(PlainTextSchema),
35
- valueRange: Schema.optionalKey(ValueRangeSchema),
36
33
  });
34
+ /** The fields of a chart, before the checks that relate them. */
35
+ function chartFields(rich) {
36
+ return Schema.Struct({
37
+ ...cardFields(rich),
38
+ ...ChartDataSchema.fields,
39
+ valueLabel: Schema.optionalKey(TextSchema),
40
+ valueRange: Schema.optionalKey(ValueRangeSchema),
41
+ });
42
+ }
37
43
  /** Checks that every series has one value for each category, and at least one that is not null. */
38
44
  function hasValuePerCategory(chart) {
39
45
  return Arr.every(chart.series, ({ values }) => values.length === chart.categories.length &&
@@ -55,10 +61,12 @@ function hasBarPlacement(chart) {
55
61
  * learner reads the same values that the figure draws. Every series has a
56
62
  * name, because no meaning may ride on color alone.
57
63
  */
58
- export const ChartPropsSchema = ChartFieldsSchema.check(Schema.makeFilter(hasValuePerCategory, {
59
- message: "Expected each series to have one value for each category, and at least one value.",
60
- }), Schema.makeFilter(hasDistinctSeries, {
61
- message: "Expected each series to have a name of its own.",
62
- }), Schema.makeFilter(hasBarPlacement, {
63
- message: "Expected a bar placement on a chart with bars, and on no other.",
64
- }));
64
+ export function chartProps(rich) {
65
+ return figure(chartFields(rich).check(Schema.makeFilter(hasValuePerCategory, {
66
+ message: "Expected each series to have one value for each category, and at least one value.",
67
+ }), Schema.makeFilter(hasDistinctSeries, {
68
+ message: "Expected each series to have a name of its own.",
69
+ }), Schema.makeFilter(hasBarPlacement, {
70
+ message: "Expected a bar placement on a chart with bars, and on no other.",
71
+ })));
72
+ }
@@ -0,0 +1,118 @@
1
+ import { Schema } from "effect";
2
+ import { type RichSlot } from "#contracts/visual/card";
3
+ /**
4
+ * The charts of data and functions. A regression line and its residuals are
5
+ * the result of fitting the points, so they are answer state; the data a chart
6
+ * draws is the question itself.
7
+ */
8
+ export declare function chartVisuals<E>(rich: RichSlot<E>): {
9
+ BarChart: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
10
+ readonly description: RichSlot<E>;
11
+ readonly title: RichSlot<E>;
12
+ readonly chartConfig: Schema.$Record<Schema.Trimmed, Schema.Struct<{
13
+ readonly colors: Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
14
+ readonly dark: Schema.optionalKey<Schema.$Array<Schema.Trimmed>>;
15
+ readonly light: Schema.$Array<Schema.Trimmed>;
16
+ }>, Schema.Struct<{
17
+ readonly dark: Schema.$Array<Schema.Trimmed>;
18
+ }>]>>;
19
+ readonly cue: Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
20
+ readonly activeDot: Schema.Literals<readonly ["default", "border", "colored-border", "square", "square-border", "diamond", "diamond-border", "triangle", "triangle-border"]>;
21
+ readonly dot: Schema.Literals<readonly ["default", "border", "colored-border", "square", "square-border", "diamond", "diamond-border", "triangle", "triangle-border"]>;
22
+ readonly kind: Schema.Literal<"line">;
23
+ readonly strokeDasharray: Schema.optionalKey<Schema.Trimmed>;
24
+ }>, Schema.Struct<{
25
+ readonly activeDot: Schema.Literals<readonly ["default", "border", "colored-border", "square", "square-border", "diamond", "diamond-border", "triangle", "triangle-border"]>;
26
+ readonly dot: Schema.Literals<readonly ["default", "border", "colored-border", "square", "square-border", "diamond", "diamond-border", "triangle", "triangle-border"]>;
27
+ readonly kind: Schema.Literal<"point">;
28
+ }>, Schema.Struct<{
29
+ readonly kind: Schema.Literal<"bar">;
30
+ readonly radius: Schema.Finite;
31
+ readonly variant: Schema.Literals<readonly ["default", "hatched"]>;
32
+ }>]>>;
33
+ readonly label: Schema.optionalKey<RichSlot<E>>;
34
+ }>>;
35
+ readonly data: Schema.$Array<Schema.Struct<{
36
+ readonly name: Schema.Trimmed;
37
+ readonly value: Schema.Finite;
38
+ }>>;
39
+ readonly yAxisLabel: Schema.Trimmed;
40
+ }>, "figure">;
41
+ Chart: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
42
+ readonly description: RichSlot<E>;
43
+ readonly title: RichSlot<E>;
44
+ readonly bars: Schema.optionalKey<Schema.Literals<readonly ["apart", "touching"]>>;
45
+ readonly categories: Schema.NonEmptyArray<Schema.Trimmed>;
46
+ readonly series: Schema.NonEmptyArray<Schema.Struct<{
47
+ readonly label: Schema.Trimmed;
48
+ readonly mark: Schema.Literals<readonly ["bar", "line"]>;
49
+ readonly values: Schema.NonEmptyArray<Schema.NullOr<Schema.Finite>>;
50
+ }>>;
51
+ readonly valueLabel: Schema.optionalKey<Schema.Trimmed>;
52
+ readonly valueRange: Schema.optionalKey<Schema.Struct<{
53
+ readonly max: Schema.Finite;
54
+ readonly min: Schema.Finite;
55
+ }>>;
56
+ }>, "figure">;
57
+ FunctionChart: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
58
+ readonly description: RichSlot<E>;
59
+ readonly title: RichSlot<E>;
60
+ readonly a: Schema.Finite;
61
+ readonly mode: Schema.optionalKey<Schema.Literals<readonly ["continuous", "discrete"]>>;
62
+ readonly n: Schema.optionalKey<Schema.Int>;
63
+ readonly p: Schema.Finite;
64
+ }>, "figure">;
65
+ HistogramChart: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
66
+ readonly description: RichSlot<E>;
67
+ readonly title: RichSlot<E>;
68
+ readonly chartConfig: Schema.$Record<Schema.Trimmed, Schema.Struct<{
69
+ readonly colors: Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
70
+ readonly dark: Schema.optionalKey<Schema.$Array<Schema.Trimmed>>;
71
+ readonly light: Schema.$Array<Schema.Trimmed>;
72
+ }>, Schema.Struct<{
73
+ readonly dark: Schema.$Array<Schema.Trimmed>;
74
+ }>]>>;
75
+ readonly cue: Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
76
+ readonly activeDot: Schema.Literals<readonly ["default", "border", "colored-border", "square", "square-border", "diamond", "diamond-border", "triangle", "triangle-border"]>;
77
+ readonly dot: Schema.Literals<readonly ["default", "border", "colored-border", "square", "square-border", "diamond", "diamond-border", "triangle", "triangle-border"]>;
78
+ readonly kind: Schema.Literal<"line">;
79
+ readonly strokeDasharray: Schema.optionalKey<Schema.Trimmed>;
80
+ }>, Schema.Struct<{
81
+ readonly activeDot: Schema.Literals<readonly ["default", "border", "colored-border", "square", "square-border", "diamond", "diamond-border", "triangle", "triangle-border"]>;
82
+ readonly dot: Schema.Literals<readonly ["default", "border", "colored-border", "square", "square-border", "diamond", "diamond-border", "triangle", "triangle-border"]>;
83
+ readonly kind: Schema.Literal<"point">;
84
+ }>, Schema.Struct<{
85
+ readonly kind: Schema.Literal<"bar">;
86
+ readonly radius: Schema.Finite;
87
+ readonly variant: Schema.Literals<readonly ["default", "hatched"]>;
88
+ }>]>>;
89
+ readonly label: Schema.optionalKey<RichSlot<E>>;
90
+ }>>;
91
+ readonly data: Schema.$Array<Schema.Struct<{
92
+ readonly name: Schema.Trimmed;
93
+ readonly value: Schema.Finite;
94
+ }>>;
95
+ readonly yAxisLabel: Schema.Trimmed;
96
+ }>, "figure">;
97
+ ScatterDiagram: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
98
+ readonly description: RichSlot<E>;
99
+ readonly title: RichSlot<E>;
100
+ readonly calculateRegressionLine: Schema.optionalKey<Schema.Boolean>;
101
+ readonly datasets: Schema.$Array<Schema.Struct<{
102
+ readonly color: Schema.Trimmed;
103
+ readonly name: Schema.Trimmed;
104
+ readonly points: Schema.$Array<Schema.Struct<{
105
+ readonly x: Schema.Finite;
106
+ readonly y: Schema.Finite;
107
+ }>>;
108
+ }>>;
109
+ readonly regressionLineStyle: Schema.optionalKey<Schema.Struct<{
110
+ readonly color: Schema.optionalKey<Schema.Trimmed>;
111
+ readonly strokeDasharray: Schema.optionalKey<Schema.Trimmed>;
112
+ }>>;
113
+ readonly showResiduals: Schema.optionalKey<Schema.Boolean>;
114
+ readonly xAxisDomain: Schema.optionalKey<Schema.Literal<"min-max">>;
115
+ readonly xAxisLabel: Schema.optionalKey<Schema.Trimmed>;
116
+ readonly yAxisLabel: Schema.optionalKey<Schema.Trimmed>;
117
+ }>, "figure">;
118
+ };
@@ -0,0 +1,100 @@
1
+ import { Schema } from "effect";
2
+ import { cardFields, TextSchema } from "#contracts/visual/card";
3
+ import { answerAt, figure } from "#contracts/visual/entry";
4
+ import { chartProps } from "#contracts/visual/mathematics/chart";
5
+ /** How a chart marks a point of a line or a scatter. */
6
+ const DotSchema = Schema.Literals([
7
+ "default",
8
+ "border",
9
+ "colored-border",
10
+ "square",
11
+ "square-border",
12
+ "diamond",
13
+ "diamond-border",
14
+ "triangle",
15
+ "triangle-border",
16
+ ]);
17
+ /** The cue that tells one series apart without its color: a line, points, or bars. */
18
+ const SeriesCueSchema = Schema.Union([
19
+ Schema.Struct({
20
+ activeDot: DotSchema,
21
+ dot: DotSchema,
22
+ kind: Schema.Literal("line"),
23
+ strokeDasharray: Schema.optionalKey(TextSchema),
24
+ }),
25
+ Schema.Struct({
26
+ activeDot: DotSchema,
27
+ dot: DotSchema,
28
+ kind: Schema.Literal("point"),
29
+ }),
30
+ Schema.Struct({
31
+ kind: Schema.Literal("bar"),
32
+ radius: Schema.Finite,
33
+ variant: Schema.Literals(["default", "hatched"]),
34
+ }),
35
+ ]);
36
+ /** The colors of one series in a light and a dark theme; at least one theme is set. */
37
+ const ThemeColorsSchema = Schema.Union([
38
+ Schema.Struct({
39
+ dark: Schema.optionalKey(Schema.Array(TextSchema)),
40
+ light: Schema.Array(TextSchema),
41
+ }),
42
+ Schema.Struct({ dark: Schema.Array(TextSchema) }),
43
+ ]);
44
+ /** Props of `BarChart` and `HistogramChart`: one value for each named bar. */
45
+ function barChart(rich) {
46
+ return figure(Schema.Struct({
47
+ ...cardFields(rich),
48
+ chartConfig: Schema.Record(TextSchema, Schema.Struct({
49
+ colors: Schema.optionalKey(ThemeColorsSchema),
50
+ cue: Schema.optionalKey(SeriesCueSchema),
51
+ label: Schema.optionalKey(rich),
52
+ })),
53
+ data: Schema.Array(Schema.Struct({ name: TextSchema, value: Schema.Finite })),
54
+ yAxisLabel: TextSchema,
55
+ }));
56
+ }
57
+ /** Props of `ScatterDiagram`: named series of points, with an optional regression. */
58
+ function scatterDiagram(rich) {
59
+ return Schema.Struct({
60
+ ...cardFields(rich),
61
+ calculateRegressionLine: Schema.optionalKey(Schema.Boolean),
62
+ datasets: Schema.Array(Schema.Struct({
63
+ color: TextSchema,
64
+ name: TextSchema,
65
+ points: Schema.Array(Schema.Struct({ x: Schema.Finite, y: Schema.Finite })),
66
+ })),
67
+ regressionLineStyle: Schema.optionalKey(Schema.Struct({
68
+ color: Schema.optionalKey(TextSchema),
69
+ strokeDasharray: Schema.optionalKey(TextSchema),
70
+ })),
71
+ showResiduals: Schema.optionalKey(Schema.Boolean),
72
+ xAxisDomain: Schema.optionalKey(Schema.Literal("min-max")),
73
+ xAxisLabel: Schema.optionalKey(TextSchema),
74
+ yAxisLabel: Schema.optionalKey(TextSchema),
75
+ });
76
+ }
77
+ /** Props of `FunctionChart`: the exponential model `p · aˣ` and its table. */
78
+ function functionChart(rich) {
79
+ return figure(Schema.Struct({
80
+ ...cardFields(rich),
81
+ a: Schema.Finite.check(Schema.isGreaterThan(0)),
82
+ mode: Schema.optionalKey(Schema.Literals(["continuous", "discrete"])),
83
+ n: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThanOrEqualTo(2))),
84
+ p: Schema.Finite,
85
+ }));
86
+ }
87
+ /**
88
+ * The charts of data and functions. A regression line and its residuals are
89
+ * the result of fitting the points, so they are answer state; the data a chart
90
+ * draws is the question itself.
91
+ */
92
+ export function chartVisuals(rich) {
93
+ return {
94
+ BarChart: barChart(rich),
95
+ Chart: chartProps(rich),
96
+ FunctionChart: functionChart(rich),
97
+ HistogramChart: barChart(rich),
98
+ ScatterDiagram: figure(scatterDiagram(rich), answerAt(["calculateRegressionLine"], ["showResiduals"])),
99
+ };
100
+ }
@@ -0,0 +1,82 @@
1
+ import { Schema } from "effect";
2
+ import { type RichSlot } from "#contracts/visual/card";
3
+ /**
4
+ * The visuals of functions, relations, and sequences. The output of the
5
+ * inverse machine is the value the reader would compute, so it is answer
6
+ * state. A diagram is a card around relation visualizers, its children, so
7
+ * it is markup, and an assessment places the visualizer itself as its figure.
8
+ */
9
+ export declare function functionVisuals<E>(rich: RichSlot<E>): {
10
+ BacterialGrowth: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
11
+ readonly formulaType: Schema.optionalKey<Schema.Literals<readonly ["geometric", "exponential"]>>;
12
+ readonly initialCount: Schema.optionalKey<Schema.Finite>;
13
+ readonly labels: Schema.optionalKey<Schema.Struct<{
14
+ readonly bacterial: Schema.optionalKey<Schema.Trimmed>;
15
+ readonly description: Schema.optionalKey<RichSlot<E>>;
16
+ readonly title: Schema.optionalKey<RichSlot<E>>;
17
+ }>>;
18
+ readonly maxGenerations: Schema.optionalKey<Schema.Int>;
19
+ readonly ratio: Schema.optionalKey<Schema.Finite>;
20
+ readonly timeInterval: Schema.optionalKey<Schema.Finite>;
21
+ readonly timeUnit: Schema.optionalKey<Schema.Trimmed>;
22
+ }>, "figure">;
23
+ FunctionAndNonFunctionDiagram: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
24
+ readonly description: RichSlot<E>;
25
+ readonly title: RichSlot<E>;
26
+ }>, "markup">;
27
+ FunctionAndNonFunctionRelationVisualizer: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
28
+ readonly accessibilityLabel: Schema.Trimmed;
29
+ readonly codomain: Schema.$Array<Schema.Struct<{
30
+ readonly id: Schema.Trimmed;
31
+ readonly label: RichSlot<E>;
32
+ }>>;
33
+ readonly codomainLabel: RichSlot<E>;
34
+ readonly domain: Schema.$Array<Schema.Struct<{
35
+ readonly id: Schema.Trimmed;
36
+ readonly label: RichSlot<E>;
37
+ }>>;
38
+ readonly domainLabel: RichSlot<E>;
39
+ readonly mappings: Schema.$Array<Schema.Struct<{
40
+ readonly from: Schema.Trimmed;
41
+ readonly to: Schema.Trimmed;
42
+ }>>;
43
+ }>, "figure">;
44
+ FunctionExplorationVirusChart: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
45
+ readonly labels: Schema.Struct<{
46
+ readonly caption: RichSlot<E>;
47
+ readonly description: RichSlot<E>;
48
+ readonly exponential: RichSlot<E>;
49
+ readonly linear: RichSlot<E>;
50
+ readonly logarithmic: RichSlot<E>;
51
+ readonly phase: Schema.Trimmed;
52
+ readonly title: RichSlot<E>;
53
+ readonly yLabel: Schema.Trimmed;
54
+ }>;
55
+ }>, "figure">;
56
+ FunctionMachine: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
57
+ readonly description: RichSlot<E>;
58
+ readonly title: RichSlot<E>;
59
+ readonly inputLabel: Schema.Trimmed;
60
+ }>, "figure">;
61
+ InverseFunctionIllustration: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
62
+ readonly description: RichSlot<E>;
63
+ readonly title: RichSlot<E>;
64
+ readonly content: Schema.Struct<{
65
+ readonly input: RichSlot<E>;
66
+ readonly output: RichSlot<E>;
67
+ }>;
68
+ readonly machineLabel: RichSlot<E>;
69
+ }>, "figure">;
70
+ SequenceConceptTableChairsAnimation: import("#contracts/visual/entry").VisualEntry<Schema.Struct<{
71
+ readonly labels: Schema.Struct<{
72
+ readonly chair: Schema.Trimmed;
73
+ readonly pause: Schema.Trimmed;
74
+ readonly play: Schema.Trimmed;
75
+ readonly reset: Schema.Trimmed;
76
+ readonly setSpeed: Schema.Trimmed;
77
+ readonly setTableCount: Schema.Trimmed;
78
+ readonly table: Schema.Trimmed;
79
+ readonly title: RichSlot<E>;
80
+ }>;
81
+ }>, "figure">;
82
+ };
@@ -0,0 +1,102 @@
1
+ import { Schema } from "effect";
2
+ import { cardFields, TextSchema } from "#contracts/visual/card";
3
+ import { answerAt, figure, markup } from "#contracts/visual/entry";
4
+ /** The ways the bacterial growth animation counts generations. */
5
+ const GROWTH_FORMULAS = ["geometric", "exponential"];
6
+ /** One element of a set in a relation diagram: an identifier and its label. */
7
+ function relationElement(rich) {
8
+ return Schema.Struct({ id: TextSchema, label: rich });
9
+ }
10
+ /**
11
+ * Props of `FunctionAndNonFunctionDiagram`: the card around one or more
12
+ * relation visualizers, which are its children.
13
+ */
14
+ function functionDiagram(rich) {
15
+ return markup(Schema.Struct({ ...cardFields(rich) }));
16
+ }
17
+ /** Props of `FunctionAndNonFunctionRelationVisualizer`: arrows from a domain to a codomain. */
18
+ function relationVisualizer(rich) {
19
+ return figure(Schema.Struct({
20
+ accessibilityLabel: TextSchema,
21
+ codomain: Schema.Array(relationElement(rich)),
22
+ codomainLabel: rich,
23
+ domain: Schema.Array(relationElement(rich)),
24
+ domainLabel: rich,
25
+ mappings: Schema.Array(Schema.Struct({ from: TextSchema, to: TextSchema })),
26
+ }));
27
+ }
28
+ /** Props of `FunctionMachine`: an input that a machine turns into an output. */
29
+ function functionMachine(rich) {
30
+ return figure(Schema.Struct({ ...cardFields(rich), inputLabel: TextSchema }));
31
+ }
32
+ /** Props of `InverseFunctionIllustration`: a machine run forward and back. */
33
+ function inverseIllustration(rich) {
34
+ return figure(Schema.Struct({
35
+ ...cardFields(rich),
36
+ content: Schema.Struct({ input: rich, output: rich }),
37
+ machineLabel: rich,
38
+ }), answerAt(["content", "output"]));
39
+ }
40
+ /** Props of `FunctionExplorationVirusChart`: linear, exponential, and logarithmic spread. */
41
+ function virusChart(rich) {
42
+ return figure(Schema.Struct({
43
+ labels: Schema.Struct({
44
+ caption: rich,
45
+ description: rich,
46
+ exponential: rich,
47
+ linear: rich,
48
+ logarithmic: rich,
49
+ phase: TextSchema,
50
+ title: rich,
51
+ yLabel: TextSchema,
52
+ }),
53
+ }));
54
+ }
55
+ /** Props of `BacterialGrowth`: cells that split once in each time interval. */
56
+ function bacterialGrowth(rich) {
57
+ return figure(Schema.Struct({
58
+ formulaType: Schema.optionalKey(Schema.Literals(GROWTH_FORMULAS)),
59
+ initialCount: Schema.optionalKey(Schema.Finite),
60
+ labels: Schema.optionalKey(Schema.Struct({
61
+ bacterial: Schema.optionalKey(TextSchema),
62
+ description: Schema.optionalKey(rich),
63
+ title: Schema.optionalKey(rich),
64
+ })),
65
+ maxGenerations: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
66
+ ratio: Schema.optionalKey(Schema.Finite),
67
+ timeInterval: Schema.optionalKey(Schema.Finite),
68
+ timeUnit: Schema.optionalKey(TextSchema),
69
+ }));
70
+ }
71
+ /** Props of `SequenceConceptTableChairsAnimation`: tables in a row and the chairs around them. */
72
+ function tableChairs(rich) {
73
+ return figure(Schema.Struct({
74
+ labels: Schema.Struct({
75
+ chair: TextSchema,
76
+ pause: TextSchema,
77
+ play: TextSchema,
78
+ reset: TextSchema,
79
+ setSpeed: TextSchema,
80
+ setTableCount: TextSchema,
81
+ table: TextSchema,
82
+ title: rich,
83
+ }),
84
+ }));
85
+ }
86
+ /**
87
+ * The visuals of functions, relations, and sequences. The output of the
88
+ * inverse machine is the value the reader would compute, so it is answer
89
+ * state. A diagram is a card around relation visualizers, its children, so
90
+ * it is markup, and an assessment places the visualizer itself as its figure.
91
+ */
92
+ export function functionVisuals(rich) {
93
+ return {
94
+ BacterialGrowth: bacterialGrowth(rich),
95
+ FunctionAndNonFunctionDiagram: functionDiagram(rich),
96
+ FunctionAndNonFunctionRelationVisualizer: relationVisualizer(rich),
97
+ FunctionExplorationVirusChart: virusChart(rich),
98
+ FunctionMachine: functionMachine(rich),
99
+ InverseFunctionIllustration: inverseIllustration(rich),
100
+ SequenceConceptTableChairsAnimation: tableChairs(rich),
101
+ };
102
+ }