@nakafa/aksara-contracts 6.2.0 → 6.3.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.
@@ -256,6 +256,18 @@ export declare const MathVisualPropsSchema: Schema.Struct<{
256
256
  readonly x: Schema.Finite;
257
257
  readonly y: Schema.Finite;
258
258
  }>;
259
+ }>, Schema.Struct<{
260
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
261
+ readonly id: Schema.String;
262
+ readonly from: Schema.Struct<{
263
+ readonly x: Schema.Finite;
264
+ readonly y: Schema.Finite;
265
+ }>;
266
+ readonly kind: Schema.Literal<"vector">;
267
+ readonly to: Schema.Struct<{
268
+ readonly x: Schema.Finite;
269
+ readonly y: Schema.Finite;
270
+ }>;
259
271
  }>]>>;
260
272
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
261
273
  readonly label: Schema.optionalKey<Schema.String>;
@@ -505,6 +517,20 @@ export declare const MathVisualPropsSchema: Schema.Struct<{
505
517
  readonly y: Schema.Finite;
506
518
  readonly z: Schema.Finite;
507
519
  }>;
520
+ }>, Schema.Struct<{
521
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
522
+ readonly id: Schema.String;
523
+ readonly from: Schema.Struct<{
524
+ readonly x: Schema.Finite;
525
+ readonly y: Schema.Finite;
526
+ readonly z: Schema.Finite;
527
+ }>;
528
+ readonly kind: Schema.Literal<"vector">;
529
+ readonly to: Schema.Struct<{
530
+ readonly x: Schema.Finite;
531
+ readonly y: Schema.Finite;
532
+ readonly z: Schema.Finite;
533
+ }>;
508
534
  }>]>>;
509
535
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
510
536
  readonly label: Schema.optionalKey<Schema.String>;
@@ -1113,6 +1139,18 @@ export declare const FigureAttrsSchema: Schema.Union<readonly [Schema.Struct<{
1113
1139
  readonly x: Schema.Finite;
1114
1140
  readonly y: Schema.Finite;
1115
1141
  }>;
1142
+ }>, Schema.Struct<{
1143
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
1144
+ readonly id: Schema.String;
1145
+ readonly from: Schema.Struct<{
1146
+ readonly x: Schema.Finite;
1147
+ readonly y: Schema.Finite;
1148
+ }>;
1149
+ readonly kind: Schema.Literal<"vector">;
1150
+ readonly to: Schema.Struct<{
1151
+ readonly x: Schema.Finite;
1152
+ readonly y: Schema.Finite;
1153
+ }>;
1116
1154
  }>]>>;
1117
1155
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
1118
1156
  readonly label: Schema.optionalKey<Schema.String>;
@@ -1362,6 +1400,20 @@ export declare const FigureAttrsSchema: Schema.Union<readonly [Schema.Struct<{
1362
1400
  readonly y: Schema.Finite;
1363
1401
  readonly z: Schema.Finite;
1364
1402
  }>;
1403
+ }>, Schema.Struct<{
1404
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
1405
+ readonly id: Schema.String;
1406
+ readonly from: Schema.Struct<{
1407
+ readonly x: Schema.Finite;
1408
+ readonly y: Schema.Finite;
1409
+ readonly z: Schema.Finite;
1410
+ }>;
1411
+ readonly kind: Schema.Literal<"vector">;
1412
+ readonly to: Schema.Struct<{
1413
+ readonly x: Schema.Finite;
1414
+ readonly y: Schema.Finite;
1415
+ readonly z: Schema.Finite;
1416
+ }>;
1365
1417
  }>]>>;
1366
1418
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
1367
1419
  readonly label: Schema.optionalKey<Schema.String>;
@@ -2041,6 +2093,18 @@ export declare const FigureNodeSchema: Schema.Struct<{
2041
2093
  readonly x: Schema.Finite;
2042
2094
  readonly y: Schema.Finite;
2043
2095
  }>;
2096
+ }>, Schema.Struct<{
2097
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
2098
+ readonly id: Schema.String;
2099
+ readonly from: Schema.Struct<{
2100
+ readonly x: Schema.Finite;
2101
+ readonly y: Schema.Finite;
2102
+ }>;
2103
+ readonly kind: Schema.Literal<"vector">;
2104
+ readonly to: Schema.Struct<{
2105
+ readonly x: Schema.Finite;
2106
+ readonly y: Schema.Finite;
2107
+ }>;
2044
2108
  }>]>>;
2045
2109
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
2046
2110
  readonly label: Schema.optionalKey<Schema.String>;
@@ -2290,6 +2354,20 @@ export declare const FigureNodeSchema: Schema.Struct<{
2290
2354
  readonly y: Schema.Finite;
2291
2355
  readonly z: Schema.Finite;
2292
2356
  }>;
2357
+ }>, Schema.Struct<{
2358
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
2359
+ readonly id: Schema.String;
2360
+ readonly from: Schema.Struct<{
2361
+ readonly x: Schema.Finite;
2362
+ readonly y: Schema.Finite;
2363
+ readonly z: Schema.Finite;
2364
+ }>;
2365
+ readonly kind: Schema.Literal<"vector">;
2366
+ readonly to: Schema.Struct<{
2367
+ readonly x: Schema.Finite;
2368
+ readonly y: Schema.Finite;
2369
+ readonly z: Schema.Finite;
2370
+ }>;
2293
2371
  }>]>>;
2294
2372
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
2295
2373
  readonly label: Schema.optionalKey<Schema.String>;
@@ -68,7 +68,7 @@ function planeObjectContained(frame, object, scope, labels) {
68
68
  if (object.kind === "point") {
69
69
  return planeContains(frame, object.at);
70
70
  }
71
- if (object.kind === "segment") {
71
+ if (object.kind === "segment" || object.kind === "vector") {
72
72
  return Arr.every([object.from, object.to], (point) => planeContains(frame, point));
73
73
  }
74
74
  if (object.kind === "polyline" || object.kind === "polygon") {
@@ -102,7 +102,7 @@ function spaceObjectContained(frame, object, scope) {
102
102
  if (object.kind === "point") {
103
103
  return spaceContains(frame, object.at);
104
104
  }
105
- if (object.kind === "segment") {
105
+ if (object.kind === "segment" || object.kind === "vector") {
106
106
  return Arr.every([object.from, object.to], (point) => spaceContains(frame, point));
107
107
  }
108
108
  if (object.kind === "polyline" || object.kind === "polygon") {
@@ -22,3 +22,5 @@ export declare const MATH_POLYLINE_MESSAGE = "Expected unique polyline vertices.
22
22
  export declare const MATH_RAY_MESSAGE = "Expected a ray through a position distinct from its start.";
23
23
  /** Message for a segment whose two ends coincide. */
24
24
  export declare const MATH_SEGMENT_MESSAGE = "Expected a segment with distinct ends.";
25
+ /** Message for a vector whose tail and head coincide. */
26
+ export declare const MATH_VECTOR_MESSAGE = "Expected a vector with distinct tail and head.";
@@ -25,3 +25,5 @@ export const MATH_POLYLINE_MESSAGE = "Expected unique polyline vertices.";
25
25
  export const MATH_RAY_MESSAGE = "Expected a ray through a position distinct from its start.";
26
26
  /** Message for a segment whose two ends coincide. */
27
27
  export const MATH_SEGMENT_MESSAGE = "Expected a segment with distinct ends.";
28
+ /** Message for a vector whose tail and head coincide. */
29
+ export const MATH_VECTOR_MESSAGE = "Expected a vector with distinct tail and head.";
@@ -169,6 +169,18 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
169
169
  readonly x: Schema.Finite;
170
170
  readonly y: Schema.Finite;
171
171
  }>;
172
+ }>, Schema.Struct<{
173
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
174
+ readonly id: Schema.String;
175
+ readonly from: Schema.Struct<{
176
+ readonly x: Schema.Finite;
177
+ readonly y: Schema.Finite;
178
+ }>;
179
+ readonly kind: Schema.Literal<"vector">;
180
+ readonly to: Schema.Struct<{
181
+ readonly x: Schema.Finite;
182
+ readonly y: Schema.Finite;
183
+ }>;
172
184
  }>]>;
173
185
  export type PlaneMathObject = typeof PlaneMathObjectSchema.Type;
174
186
  /** Exact Cartesian frame presented behind a plane construction. */
@@ -401,6 +413,18 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
401
413
  readonly x: Schema.Finite;
402
414
  readonly y: Schema.Finite;
403
415
  }>;
416
+ }>, Schema.Struct<{
417
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
418
+ readonly id: Schema.String;
419
+ readonly from: Schema.Struct<{
420
+ readonly x: Schema.Finite;
421
+ readonly y: Schema.Finite;
422
+ }>;
423
+ readonly kind: Schema.Literal<"vector">;
424
+ readonly to: Schema.Struct<{
425
+ readonly x: Schema.Finite;
426
+ readonly y: Schema.Finite;
427
+ }>;
404
428
  }>]>>;
405
429
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
406
430
  readonly label: Schema.optionalKey<Schema.String>;
@@ -5,7 +5,7 @@ import { PlaneCurveObjectSchemas } from "#contracts/math/curve";
5
5
  import { FormulaParameterSchema, FormulaReadoutSchema, PlaneFormulaPointSchema, } from "#contracts/math/formula/field";
6
6
  import { formulaScopeIssues, parameterScope, planeFormulaFields, } from "#contracts/math/formula/scope";
7
7
  import { sliderFormulaIssues } from "#contracts/math/formula/slider";
8
- import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MathObjectFields, mathLabelAnchorFields, } from "#contracts/math/object";
8
+ import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MATH_VECTOR_MESSAGE, MathObjectFields, mathLabelAnchorFields, } from "#contracts/math/object";
9
9
  import { planeResolutionIssues } from "#contracts/math/resolution";
10
10
  /** Checks a plane polygon has non-zero signed area. */
11
11
  function hasPlaneArea(vertices) {
@@ -76,6 +76,18 @@ const PlaneSegmentObjectSchema = Schema.Struct({
76
76
  }).pipe(Schema.check(Schema.makeFilter(({ from, to }) => !samePlanePoint(from, to), {
77
77
  message: MATH_SEGMENT_MESSAGE,
78
78
  })));
79
+ /**
80
+ * An arrow from its tail to its head, such as a displacement, a force, or a
81
+ * position vector: a segment that ends in an arrowhead.
82
+ */
83
+ const PlaneVectorObjectSchema = Schema.Struct({
84
+ ...MathObjectFields,
85
+ from: PlanePointSchema,
86
+ kind: Schema.Literal("vector"),
87
+ to: PlanePointSchema,
88
+ }).pipe(Schema.check(Schema.makeFilter(({ from, to }) => !samePlanePoint(from, to), {
89
+ message: MATH_VECTOR_MESSAGE,
90
+ })));
79
91
  const PlanePolylineObjectSchema = Schema.Struct({
80
92
  ...MathObjectFields,
81
93
  kind: Schema.Literal("polyline"),
@@ -125,6 +137,7 @@ export const PlaneMathObjectSchema = Schema.Union([
125
137
  PlaneQuadraticObjectSchema,
126
138
  PlaneRayObjectSchema,
127
139
  PlaneSegmentObjectSchema,
140
+ PlaneVectorObjectSchema,
128
141
  ]);
129
142
  /** Exact Cartesian frame presented behind a plane construction. */
130
143
  export const PlaneMathFrameSchema = Schema.Struct({
@@ -64,7 +64,7 @@ function objectCoordinates(frame, object, index, threshold) {
64
64
  if (object.kind === "ray") {
65
65
  return clippedPathCoordinates(frame, "ray", object.from, object.through, root, threshold);
66
66
  }
67
- if (object.kind === "segment") {
67
+ if (object.kind === "segment" || object.kind === "vector") {
68
68
  return [
69
69
  ...pointCoordinates(object.from, [...root, "from"]),
70
70
  ...pointCoordinates(object.to, [...root, "to"]),
@@ -205,6 +205,20 @@ export declare const SpaceMathObjectSchema: Schema.Union<readonly [Schema.Struct
205
205
  readonly y: Schema.Finite;
206
206
  readonly z: Schema.Finite;
207
207
  }>;
208
+ }>, Schema.Struct<{
209
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
210
+ readonly id: Schema.String;
211
+ readonly from: Schema.Struct<{
212
+ readonly x: Schema.Finite;
213
+ readonly y: Schema.Finite;
214
+ readonly z: Schema.Finite;
215
+ }>;
216
+ readonly kind: Schema.Literal<"vector">;
217
+ readonly to: Schema.Struct<{
218
+ readonly x: Schema.Finite;
219
+ readonly y: Schema.Finite;
220
+ readonly z: Schema.Finite;
221
+ }>;
208
222
  }>]>;
209
223
  export type SpaceMathObject = typeof SpaceMathObjectSchema.Type;
210
224
  /** Exact Cartesian frame presented behind a space construction. */
@@ -493,6 +507,20 @@ export declare const SpaceMathVisualSchema: Schema.Struct<{
493
507
  readonly y: Schema.Finite;
494
508
  readonly z: Schema.Finite;
495
509
  }>;
510
+ }>, Schema.Struct<{
511
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
512
+ readonly id: Schema.String;
513
+ readonly from: Schema.Struct<{
514
+ readonly x: Schema.Finite;
515
+ readonly y: Schema.Finite;
516
+ readonly z: Schema.Finite;
517
+ }>;
518
+ readonly kind: Schema.Literal<"vector">;
519
+ readonly to: Schema.Struct<{
520
+ readonly x: Schema.Finite;
521
+ readonly y: Schema.Finite;
522
+ readonly z: Schema.Finite;
523
+ }>;
496
524
  }>]>>;
497
525
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
498
526
  readonly label: Schema.optionalKey<Schema.String>;
@@ -3,7 +3,7 @@ import { hasUniquePositions, MathAxisRangeSchema, MathViewPaddingSchema, mathVis
3
3
  import { spaceBoundsIssues } from "#contracts/math/bounds";
4
4
  import { FormulaParameterSchema } from "#contracts/math/formula/field";
5
5
  import { formulaScopeIssues, parameterScope, spaceFormulaFields, } from "#contracts/math/formula/scope";
6
- import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MathObjectFields, mathLabelAnchorFields, } from "#contracts/math/object";
6
+ import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MATH_VECTOR_MESSAGE, MathObjectFields, mathLabelAnchorFields, } from "#contracts/math/object";
7
7
  import { spaceResolutionIssues } from "#contracts/math/resolution";
8
8
  import { SpaceSolidObjectSchemas } from "#contracts/math/solid";
9
9
  import { hasCoplanarArea } from "#contracts/math/vector";
@@ -37,6 +37,18 @@ const SpaceSegmentObjectSchema = Schema.Struct({
37
37
  }).pipe(Schema.check(Schema.makeFilter(({ from, to }) => !sameSpacePoint(from, to), {
38
38
  message: MATH_SEGMENT_MESSAGE,
39
39
  })));
40
+ /**
41
+ * An arrow from its tail to its head, such as a displacement, a force, or a
42
+ * position vector: a segment that ends in an arrowhead.
43
+ */
44
+ const SpaceVectorObjectSchema = Schema.Struct({
45
+ ...MathObjectFields,
46
+ from: SpacePointSchema,
47
+ kind: Schema.Literal("vector"),
48
+ to: SpacePointSchema,
49
+ }).pipe(Schema.check(Schema.makeFilter(({ from, to }) => !sameSpacePoint(from, to), {
50
+ message: MATH_VECTOR_MESSAGE,
51
+ })));
40
52
  const SpacePolylineObjectSchema = Schema.Struct({
41
53
  ...MathObjectFields,
42
54
  kind: Schema.Literal("polyline"),
@@ -73,6 +85,7 @@ export const SpaceMathObjectSchema = Schema.Union([
73
85
  SpacePolylineObjectSchema,
74
86
  SpaceRayObjectSchema,
75
87
  SpaceSegmentObjectSchema,
88
+ SpaceVectorObjectSchema,
76
89
  ]);
77
90
  /** Exact Cartesian frame presented behind a space construction. */
78
91
  export const SpaceMathFrameSchema = Schema.Struct({
@@ -193,6 +193,18 @@ export declare const MathVisualSchema: Schema.Union<readonly [Schema.Struct<{
193
193
  readonly x: Schema.Finite;
194
194
  readonly y: Schema.Finite;
195
195
  }>;
196
+ }>, Schema.Struct<{
197
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
198
+ readonly id: Schema.String;
199
+ readonly from: Schema.Struct<{
200
+ readonly x: Schema.Finite;
201
+ readonly y: Schema.Finite;
202
+ }>;
203
+ readonly kind: Schema.Literal<"vector">;
204
+ readonly to: Schema.Struct<{
205
+ readonly x: Schema.Finite;
206
+ readonly y: Schema.Finite;
207
+ }>;
196
208
  }>]>>;
197
209
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
198
210
  readonly label: Schema.optionalKey<Schema.String>;
@@ -442,6 +454,20 @@ export declare const MathVisualSchema: Schema.Union<readonly [Schema.Struct<{
442
454
  readonly y: Schema.Finite;
443
455
  readonly z: Schema.Finite;
444
456
  }>;
457
+ }>, Schema.Struct<{
458
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
459
+ readonly id: Schema.String;
460
+ readonly from: Schema.Struct<{
461
+ readonly x: Schema.Finite;
462
+ readonly y: Schema.Finite;
463
+ readonly z: Schema.Finite;
464
+ }>;
465
+ readonly kind: Schema.Literal<"vector">;
466
+ readonly to: Schema.Struct<{
467
+ readonly x: Schema.Finite;
468
+ readonly y: Schema.Finite;
469
+ readonly z: Schema.Finite;
470
+ }>;
445
471
  }>]>>;
446
472
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
447
473
  readonly label: Schema.optionalKey<Schema.String>;
@@ -642,6 +668,20 @@ export declare const decodeMathVisual: (input: unknown) => Effect.Effect<{
642
668
  readonly y: number;
643
669
  readonly z: number;
644
670
  };
671
+ } | {
672
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
673
+ readonly id: string;
674
+ readonly from: {
675
+ readonly x: number;
676
+ readonly y: number;
677
+ readonly z: number;
678
+ };
679
+ readonly kind: "vector";
680
+ readonly to: {
681
+ readonly x: number;
682
+ readonly y: number;
683
+ readonly z: number;
684
+ };
645
685
  } | {
646
686
  readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
647
687
  readonly id: string;
@@ -847,6 +887,20 @@ export declare const decodeMathVisual: (input: unknown) => Effect.Effect<{
847
887
  readonly y: number;
848
888
  readonly z: number;
849
889
  };
890
+ } | {
891
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
892
+ readonly id: string;
893
+ readonly from: {
894
+ readonly x: number;
895
+ readonly y: number;
896
+ readonly z: number;
897
+ };
898
+ readonly kind: "vector";
899
+ readonly to: {
900
+ readonly x: number;
901
+ readonly y: number;
902
+ readonly z: number;
903
+ };
850
904
  } | {
851
905
  readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
852
906
  readonly id: string;
@@ -1065,6 +1119,18 @@ export declare const decodeMathVisual: (input: unknown) => Effect.Effect<{
1065
1119
  readonly x: number;
1066
1120
  readonly y: number;
1067
1121
  };
1122
+ } | {
1123
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
1124
+ readonly id: string;
1125
+ readonly from: {
1126
+ readonly x: number;
1127
+ readonly y: number;
1128
+ };
1129
+ readonly kind: "vector";
1130
+ readonly to: {
1131
+ readonly x: number;
1132
+ readonly y: number;
1133
+ };
1068
1134
  } | {
1069
1135
  readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
1070
1136
  readonly id: string;
@@ -1234,6 +1300,18 @@ export declare const decodeMathVisual: (input: unknown) => Effect.Effect<{
1234
1300
  readonly x: number;
1235
1301
  readonly y: number;
1236
1302
  };
1303
+ } | {
1304
+ readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
1305
+ readonly id: string;
1306
+ readonly from: {
1307
+ readonly x: number;
1308
+ readonly y: number;
1309
+ };
1310
+ readonly kind: "vector";
1311
+ readonly to: {
1312
+ readonly x: number;
1313
+ readonly y: number;
1314
+ };
1237
1315
  } | {
1238
1316
  readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
1239
1317
  readonly id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakafa/aksara-contracts",
3
- "version": "6.2.0",
3
+ "version": "6.3.0",
4
4
  "description": "Schemas and verification contracts for Nakafa content releases.",
5
5
  "homepage": "https://github.com/nakafaai/aksara#readme",
6
6
  "license": "SEE LICENSE IN LICENSE",