@nakafa/aksara-contracts 0.27.0 → 0.31.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 (44) hide show
  1. package/README.md +18 -10
  2. package/dist/math/base.d.ts +49 -0
  3. package/dist/math/base.js +103 -0
  4. package/dist/math/plane.d.ts +317 -0
  5. package/dist/math/plane.js +151 -0
  6. package/dist/math/space.d.ts +397 -0
  7. package/dist/math/space.js +129 -0
  8. package/dist/math/vector.d.ts +3 -0
  9. package/dist/math/vector.js +74 -0
  10. package/dist/math/visual.d.ts +984 -0
  11. package/dist/math/visual.js +15 -0
  12. package/dist/preview/artifact.d.ts +4 -32
  13. package/dist/preview/artifact.js +2 -2
  14. package/dist/preview/spec.d.ts +8 -64
  15. package/dist/projection/digest.d.ts +4 -74
  16. package/dist/projection/page.d.ts +1 -50
  17. package/dist/projection/page.js +9 -38
  18. package/dist/projection/question.d.ts +16 -184
  19. package/dist/projection/spec.d.ts +7 -253
  20. package/dist/projection/spec.js +2 -9
  21. package/dist/projection/verify.d.ts +4 -74
  22. package/dist/question/item.d.ts +24 -304
  23. package/dist/question/item.js +4 -4
  24. package/dist/question/response.d.ts +9 -97
  25. package/dist/question/response.js +8 -31
  26. package/dist/release/policy.d.ts +3 -0
  27. package/dist/release/policy.js +2 -0
  28. package/dist/release/rollback/spec.d.ts +36 -288
  29. package/dist/release/snapshot/data.d.ts +4 -32
  30. package/dist/release/snapshot/verify.d.ts +4 -60
  31. package/dist/renderer/compatibility.d.ts +49 -2
  32. package/dist/renderer/compatibility.js +49 -1
  33. package/dist/runtime/spec.d.ts +4 -46
  34. package/dist/runtime/verify.d.ts +0 -28
  35. package/dist/transport/batch.d.ts +8 -481
  36. package/dist/transport/batch.js +2 -14
  37. package/dist/transport/group.d.ts +50 -836
  38. package/dist/transport/group.js +1 -2
  39. package/dist/transport/request.d.ts +440 -2356
  40. package/dist/transport/response.d.ts +44 -436
  41. package/dist/transport/snapshot.d.ts +8 -64
  42. package/dist/tryout/content-hash.d.ts +4 -32
  43. package/dist/tryout/placement.d.ts +12 -96
  44. package/package.json +9 -1
@@ -0,0 +1,151 @@
1
+ import { Schema } from "effect";
2
+ import { ArcStartDegreesSchema, ArcSweepDegreesSchema, GEOMETRY_TOLERANCE, hasUniquePositions, MathAppearanceSchema, MathAxisRangeSchema, MathFeatureVisibilitySchema, MathLabelPlacementSchema, MathViewPaddingSchema, MathVisualKeySchema, mathVisualIdentityIssues, PlanePointSchema, PositiveMeasureSchema, samePlanePoint, } from "#contracts/math/base";
3
+ const ObjectFields = {
4
+ appearance: MathAppearanceSchema,
5
+ id: MathVisualKeySchema,
6
+ };
7
+ /** Checks a plane polygon has non-zero signed area. */
8
+ function hasPlaneArea(vertices) {
9
+ const offsets = normalizedPlaneOffsets(vertices);
10
+ let twiceArea = 0;
11
+ let termMagnitude = 0;
12
+ let previous = { x: 0, y: 0 };
13
+ for (const current of offsets.slice(1)) {
14
+ const positive = previous.x * current.y;
15
+ const negative = previous.y * current.x;
16
+ twiceArea += positive - negative;
17
+ termMagnitude += Math.abs(positive) + Math.abs(negative);
18
+ previous = current;
19
+ }
20
+ return Math.abs(twiceArea) > GEOMETRY_TOLERANCE * Math.max(1, termMagnitude);
21
+ }
22
+ /** Translates before scaling so polygon area is independent of its location. */
23
+ function normalizedPlaneOffsets(vertices) {
24
+ const [origin] = vertices;
25
+ let offsets = vertices.map(({ x, y }) => ({
26
+ x: x - origin.x,
27
+ y: y - origin.y,
28
+ }));
29
+ if (offsets.some(({ x, y }) => !(Number.isFinite(x) && Number.isFinite(y)))) {
30
+ let sourceScale = 1;
31
+ for (const { x, y } of vertices) {
32
+ sourceScale = Math.max(sourceScale, Math.abs(x), Math.abs(y));
33
+ }
34
+ offsets = vertices.map(({ x, y }) => ({
35
+ x: x / sourceScale - origin.x / sourceScale,
36
+ y: y / sourceScale - origin.y / sourceScale,
37
+ }));
38
+ }
39
+ let extent = 0;
40
+ for (const { x, y } of offsets) {
41
+ extent = Math.max(extent, Math.abs(x), Math.abs(y));
42
+ }
43
+ const divisor = Math.max(extent, Number.MIN_VALUE);
44
+ return offsets.map(({ x, y }) => ({ x: x / divisor, y: y / divisor }));
45
+ }
46
+ const PlanePointObjectSchema = Schema.Struct({
47
+ ...ObjectFields,
48
+ at: PlanePointSchema,
49
+ kind: Schema.Literal("point"),
50
+ });
51
+ const PlanePathSchema = Schema.TupleWithRest(Schema.Tuple([PlanePointSchema, PlanePointSchema]), [PlanePointSchema]);
52
+ const PlaneShapeSchema = Schema.TupleWithRest(Schema.Tuple([PlanePointSchema, PlanePointSchema, PlanePointSchema]), [PlanePointSchema]);
53
+ const PlaneLineObjectSchema = Schema.Struct({
54
+ ...ObjectFields,
55
+ kind: Schema.Literal("line"),
56
+ through: Schema.Tuple([PlanePointSchema, PlanePointSchema]),
57
+ }).pipe(Schema.check(Schema.makeFilter(({ through: [from, to] }) => !samePlanePoint(from, to), {
58
+ message: "Expected a line through two distinct positions.",
59
+ })));
60
+ const PlaneRayObjectSchema = Schema.Struct({
61
+ ...ObjectFields,
62
+ from: PlanePointSchema,
63
+ kind: Schema.Literal("ray"),
64
+ through: PlanePointSchema,
65
+ }).pipe(Schema.check(Schema.makeFilter(({ from, through }) => !samePlanePoint(from, through), {
66
+ message: "Expected a ray through a position distinct from its start.",
67
+ })));
68
+ const PlaneSegmentObjectSchema = Schema.Struct({
69
+ ...ObjectFields,
70
+ from: PlanePointSchema,
71
+ kind: Schema.Literal("segment"),
72
+ to: PlanePointSchema,
73
+ }).pipe(Schema.check(Schema.makeFilter(({ from, to }) => !samePlanePoint(from, to), {
74
+ message: "Expected a segment with distinct ends.",
75
+ })));
76
+ const PlanePolylineObjectSchema = Schema.Struct({
77
+ ...ObjectFields,
78
+ kind: Schema.Literal("polyline"),
79
+ vertices: PlanePathSchema,
80
+ }).pipe(Schema.check(Schema.makeFilter(({ vertices }) => hasUniquePositions(vertices, samePlanePoint), { message: "Expected unique polyline vertices." })));
81
+ const PlanePolygonObjectSchema = Schema.Struct({
82
+ ...ObjectFields,
83
+ kind: Schema.Literal("polygon"),
84
+ vertices: PlaneShapeSchema,
85
+ }).pipe(Schema.check(Schema.makeFilter(({ vertices }) => hasUniquePositions(vertices, samePlanePoint) && hasPlaneArea(vertices), { message: "Expected unique vertices forming a non-degenerate polygon." })));
86
+ const PlaneSplineObjectSchema = Schema.Struct({
87
+ ...ObjectFields,
88
+ kind: Schema.Literal("spline"),
89
+ samples: PlaneShapeSchema,
90
+ }).pipe(Schema.check(Schema.makeFilter(({ samples }) => hasUniquePositions(samples, samePlanePoint), { message: "Expected at least three unique spline samples." })));
91
+ const PlaneClosedSplineObjectSchema = Schema.Struct({
92
+ ...ObjectFields,
93
+ kind: Schema.Literal("closed-spline"),
94
+ samples: PlaneShapeSchema,
95
+ }).pipe(Schema.check(Schema.makeFilter(({ samples }) => hasUniquePositions(samples, samePlanePoint), {
96
+ message: "Expected unique closed-spline samples without a repeated closing sample.",
97
+ })));
98
+ const PlaneCircleObjectSchema = Schema.Struct({
99
+ ...ObjectFields,
100
+ center: PlanePointSchema,
101
+ kind: Schema.Literal("circle"),
102
+ radius: PositiveMeasureSchema,
103
+ });
104
+ const PlaneArcObjectSchema = Schema.Struct({
105
+ ...ObjectFields,
106
+ center: PlanePointSchema,
107
+ kind: Schema.Literal("arc"),
108
+ radius: PositiveMeasureSchema,
109
+ startDegrees: ArcStartDegreesSchema,
110
+ sweepDegrees: ArcSweepDegreesSchema,
111
+ });
112
+ /** Mathematical objects supported by a Cartesian plane scene. */
113
+ export const PlaneMathObjectSchema = Schema.Union([
114
+ PlaneArcObjectSchema,
115
+ PlaneCircleObjectSchema,
116
+ PlaneClosedSplineObjectSchema,
117
+ PlaneLineObjectSchema,
118
+ PlanePointObjectSchema,
119
+ PlanePolygonObjectSchema,
120
+ PlanePolylineObjectSchema,
121
+ PlaneRayObjectSchema,
122
+ PlaneSegmentObjectSchema,
123
+ PlaneSplineObjectSchema,
124
+ ]);
125
+ /** Exact Cartesian frame presented behind a plane construction. */
126
+ export const PlaneMathFrameSchema = Schema.Struct({
127
+ axes: MathFeatureVisibilitySchema,
128
+ grid: MathFeatureVisibilitySchema,
129
+ kind: Schema.Literal("cartesian"),
130
+ x: MathAxisRangeSchema,
131
+ y: MathAxisRangeSchema,
132
+ });
133
+ /** Plane visuals use semantic fit instead of renderer camera parameters. */
134
+ export const PlaneMathViewSchema = Schema.Struct({
135
+ kind: Schema.Literal("fit"),
136
+ padding: Schema.optionalKey(MathViewPaddingSchema),
137
+ });
138
+ /** One coordinate anchor resolved against a separate rich-label map. */
139
+ export const PlaneLabelAnchorSchema = Schema.Struct({
140
+ at: PlanePointSchema,
141
+ key: MathVisualKeySchema,
142
+ placement: Schema.optionalKey(MathLabelPlacementSchema),
143
+ });
144
+ /** Complete stable plane visual before rich labels are attached. */
145
+ export const PlaneMathVisualSchema = Schema.Struct({
146
+ frame: PlaneMathFrameSchema,
147
+ labels: Schema.optionalKey(Schema.Array(PlaneLabelAnchorSchema)),
148
+ objects: Schema.NonEmptyArray(PlaneMathObjectSchema),
149
+ space: Schema.Literal("plane"),
150
+ view: PlaneMathViewSchema,
151
+ }).pipe(Schema.check(Schema.makeFilter(({ labels = [], objects }) => mathVisualIdentityIssues(objects, labels))));
@@ -0,0 +1,397 @@
1
+ import { Schema } from "effect";
2
+ /** Mathematical objects supported by a Cartesian space scene. */
3
+ export declare const SpaceMathObjectSchema: Schema.Union<readonly [Schema.Struct<{
4
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
5
+ readonly id: Schema.String;
6
+ readonly kind: Schema.Literal<"closed-spline">;
7
+ readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
8
+ readonly x: Schema.Finite;
9
+ readonly y: Schema.Finite;
10
+ readonly z: Schema.Finite;
11
+ }>, Schema.Struct<{
12
+ readonly x: Schema.Finite;
13
+ readonly y: Schema.Finite;
14
+ readonly z: Schema.Finite;
15
+ }>, Schema.Struct<{
16
+ readonly x: Schema.Finite;
17
+ readonly y: Schema.Finite;
18
+ readonly z: Schema.Finite;
19
+ }>]>, readonly [Schema.Struct<{
20
+ readonly x: Schema.Finite;
21
+ readonly y: Schema.Finite;
22
+ readonly z: Schema.Finite;
23
+ }>]>;
24
+ }>, Schema.Struct<{
25
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
26
+ readonly id: Schema.String;
27
+ readonly center: Schema.Struct<{
28
+ readonly x: Schema.Finite;
29
+ readonly y: Schema.Finite;
30
+ readonly z: Schema.Finite;
31
+ }>;
32
+ readonly kind: Schema.Literal<"cuboid">;
33
+ readonly size: Schema.Struct<{
34
+ readonly height: Schema.Finite;
35
+ readonly length: Schema.Finite;
36
+ readonly width: Schema.Finite;
37
+ }>;
38
+ }>, Schema.Struct<{
39
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
40
+ readonly id: Schema.String;
41
+ readonly kind: Schema.Literal<"line">;
42
+ readonly through: Schema.Tuple<readonly [Schema.Struct<{
43
+ readonly x: Schema.Finite;
44
+ readonly y: Schema.Finite;
45
+ readonly z: Schema.Finite;
46
+ }>, Schema.Struct<{
47
+ readonly x: Schema.Finite;
48
+ readonly y: Schema.Finite;
49
+ readonly z: Schema.Finite;
50
+ }>]>;
51
+ }>, Schema.Struct<{
52
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
53
+ readonly id: Schema.String;
54
+ readonly at: Schema.Struct<{
55
+ readonly x: Schema.Finite;
56
+ readonly y: Schema.Finite;
57
+ readonly z: Schema.Finite;
58
+ }>;
59
+ readonly kind: Schema.Literal<"point">;
60
+ }>, Schema.Struct<{
61
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
62
+ readonly id: Schema.String;
63
+ readonly kind: Schema.Literal<"polygon">;
64
+ readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
65
+ readonly x: Schema.Finite;
66
+ readonly y: Schema.Finite;
67
+ readonly z: Schema.Finite;
68
+ }>, Schema.Struct<{
69
+ readonly x: Schema.Finite;
70
+ readonly y: Schema.Finite;
71
+ readonly z: Schema.Finite;
72
+ }>, Schema.Struct<{
73
+ readonly x: Schema.Finite;
74
+ readonly y: Schema.Finite;
75
+ readonly z: Schema.Finite;
76
+ }>]>, readonly [Schema.Struct<{
77
+ readonly x: Schema.Finite;
78
+ readonly y: Schema.Finite;
79
+ readonly z: Schema.Finite;
80
+ }>]>;
81
+ }>, Schema.Struct<{
82
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
83
+ readonly id: Schema.String;
84
+ readonly kind: Schema.Literal<"polyline">;
85
+ readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
86
+ readonly x: Schema.Finite;
87
+ readonly y: Schema.Finite;
88
+ readonly z: Schema.Finite;
89
+ }>, Schema.Struct<{
90
+ readonly x: Schema.Finite;
91
+ readonly y: Schema.Finite;
92
+ readonly z: Schema.Finite;
93
+ }>]>, readonly [Schema.Struct<{
94
+ readonly x: Schema.Finite;
95
+ readonly y: Schema.Finite;
96
+ readonly z: Schema.Finite;
97
+ }>]>;
98
+ }>, Schema.Struct<{
99
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
100
+ readonly id: Schema.String;
101
+ readonly from: Schema.Struct<{
102
+ readonly x: Schema.Finite;
103
+ readonly y: Schema.Finite;
104
+ readonly z: Schema.Finite;
105
+ }>;
106
+ readonly kind: Schema.Literal<"ray">;
107
+ readonly through: Schema.Struct<{
108
+ readonly x: Schema.Finite;
109
+ readonly y: Schema.Finite;
110
+ readonly z: Schema.Finite;
111
+ }>;
112
+ }>, Schema.Struct<{
113
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
114
+ readonly id: Schema.String;
115
+ readonly from: Schema.Struct<{
116
+ readonly x: Schema.Finite;
117
+ readonly y: Schema.Finite;
118
+ readonly z: Schema.Finite;
119
+ }>;
120
+ readonly kind: Schema.Literal<"segment">;
121
+ readonly to: Schema.Struct<{
122
+ readonly x: Schema.Finite;
123
+ readonly y: Schema.Finite;
124
+ readonly z: Schema.Finite;
125
+ }>;
126
+ }>, Schema.Struct<{
127
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
128
+ readonly id: Schema.String;
129
+ readonly kind: Schema.Literal<"spline">;
130
+ readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
131
+ readonly x: Schema.Finite;
132
+ readonly y: Schema.Finite;
133
+ readonly z: Schema.Finite;
134
+ }>, Schema.Struct<{
135
+ readonly x: Schema.Finite;
136
+ readonly y: Schema.Finite;
137
+ readonly z: Schema.Finite;
138
+ }>, Schema.Struct<{
139
+ readonly x: Schema.Finite;
140
+ readonly y: Schema.Finite;
141
+ readonly z: Schema.Finite;
142
+ }>]>, readonly [Schema.Struct<{
143
+ readonly x: Schema.Finite;
144
+ readonly y: Schema.Finite;
145
+ readonly z: Schema.Finite;
146
+ }>]>;
147
+ }>]>;
148
+ /** Exact Cartesian frame presented behind a space construction. */
149
+ export declare const SpaceMathFrameSchema: Schema.Struct<{
150
+ readonly axes: Schema.Literals<readonly ["hidden", "visible"]>;
151
+ readonly grid: Schema.Literals<readonly ["hidden", "visible"]>;
152
+ readonly kind: Schema.Literal<"cartesian">;
153
+ readonly x: Schema.Struct<{
154
+ readonly max: Schema.Finite;
155
+ readonly min: Schema.Finite;
156
+ }>;
157
+ readonly y: Schema.Struct<{
158
+ readonly max: Schema.Finite;
159
+ readonly min: Schema.Finite;
160
+ }>;
161
+ readonly z: Schema.Struct<{
162
+ readonly max: Schema.Finite;
163
+ readonly min: Schema.Finite;
164
+ }>;
165
+ }>;
166
+ /** Minimal semantic views supported by one space scene. */
167
+ export declare const SpaceMathViewSchema: Schema.Union<readonly [Schema.Struct<{
168
+ readonly kind: Schema.Literal<"camera">;
169
+ readonly position: Schema.Struct<{
170
+ readonly x: Schema.Finite;
171
+ readonly y: Schema.Finite;
172
+ readonly z: Schema.Finite;
173
+ }>;
174
+ readonly target: Schema.Struct<{
175
+ readonly x: Schema.Finite;
176
+ readonly y: Schema.Finite;
177
+ readonly z: Schema.Finite;
178
+ }>;
179
+ }>, Schema.Struct<{
180
+ readonly kind: Schema.Literal<"fit">;
181
+ readonly padding: Schema.optionalKey<Schema.Finite>;
182
+ }>, Schema.Struct<{
183
+ readonly kind: Schema.Literal<"isometric">;
184
+ readonly target: Schema.optionalKey<Schema.Struct<{
185
+ readonly x: Schema.Finite;
186
+ readonly y: Schema.Finite;
187
+ readonly z: Schema.Finite;
188
+ }>>;
189
+ }>]>;
190
+ /** One coordinate anchor resolved against a separate rich-label map. */
191
+ export declare const SpaceLabelAnchorSchema: Schema.Struct<{
192
+ readonly at: Schema.Struct<{
193
+ readonly x: Schema.Finite;
194
+ readonly y: Schema.Finite;
195
+ readonly z: Schema.Finite;
196
+ }>;
197
+ readonly key: Schema.String;
198
+ readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
199
+ }>;
200
+ /** Complete stable space visual before rich labels are attached. */
201
+ export declare const SpaceMathVisualSchema: Schema.Struct<{
202
+ readonly frame: Schema.Struct<{
203
+ readonly axes: Schema.Literals<readonly ["hidden", "visible"]>;
204
+ readonly grid: Schema.Literals<readonly ["hidden", "visible"]>;
205
+ readonly kind: Schema.Literal<"cartesian">;
206
+ readonly x: Schema.Struct<{
207
+ readonly max: Schema.Finite;
208
+ readonly min: Schema.Finite;
209
+ }>;
210
+ readonly y: Schema.Struct<{
211
+ readonly max: Schema.Finite;
212
+ readonly min: Schema.Finite;
213
+ }>;
214
+ readonly z: Schema.Struct<{
215
+ readonly max: Schema.Finite;
216
+ readonly min: Schema.Finite;
217
+ }>;
218
+ }>;
219
+ readonly labels: Schema.optionalKey<Schema.$Array<Schema.Struct<{
220
+ readonly at: Schema.Struct<{
221
+ readonly x: Schema.Finite;
222
+ readonly y: Schema.Finite;
223
+ readonly z: Schema.Finite;
224
+ }>;
225
+ readonly key: Schema.String;
226
+ readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
227
+ }>>>;
228
+ readonly objects: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
229
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
230
+ readonly id: Schema.String;
231
+ readonly kind: Schema.Literal<"closed-spline">;
232
+ readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
233
+ readonly x: Schema.Finite;
234
+ readonly y: Schema.Finite;
235
+ readonly z: Schema.Finite;
236
+ }>, Schema.Struct<{
237
+ readonly x: Schema.Finite;
238
+ readonly y: Schema.Finite;
239
+ readonly z: Schema.Finite;
240
+ }>, Schema.Struct<{
241
+ readonly x: Schema.Finite;
242
+ readonly y: Schema.Finite;
243
+ readonly z: Schema.Finite;
244
+ }>]>, readonly [Schema.Struct<{
245
+ readonly x: Schema.Finite;
246
+ readonly y: Schema.Finite;
247
+ readonly z: Schema.Finite;
248
+ }>]>;
249
+ }>, Schema.Struct<{
250
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
251
+ readonly id: Schema.String;
252
+ readonly center: Schema.Struct<{
253
+ readonly x: Schema.Finite;
254
+ readonly y: Schema.Finite;
255
+ readonly z: Schema.Finite;
256
+ }>;
257
+ readonly kind: Schema.Literal<"cuboid">;
258
+ readonly size: Schema.Struct<{
259
+ readonly height: Schema.Finite;
260
+ readonly length: Schema.Finite;
261
+ readonly width: Schema.Finite;
262
+ }>;
263
+ }>, Schema.Struct<{
264
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
265
+ readonly id: Schema.String;
266
+ readonly kind: Schema.Literal<"line">;
267
+ readonly through: Schema.Tuple<readonly [Schema.Struct<{
268
+ readonly x: Schema.Finite;
269
+ readonly y: Schema.Finite;
270
+ readonly z: Schema.Finite;
271
+ }>, Schema.Struct<{
272
+ readonly x: Schema.Finite;
273
+ readonly y: Schema.Finite;
274
+ readonly z: Schema.Finite;
275
+ }>]>;
276
+ }>, Schema.Struct<{
277
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
278
+ readonly id: Schema.String;
279
+ readonly at: Schema.Struct<{
280
+ readonly x: Schema.Finite;
281
+ readonly y: Schema.Finite;
282
+ readonly z: Schema.Finite;
283
+ }>;
284
+ readonly kind: Schema.Literal<"point">;
285
+ }>, Schema.Struct<{
286
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
287
+ readonly id: Schema.String;
288
+ readonly kind: Schema.Literal<"polygon">;
289
+ readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
290
+ readonly x: Schema.Finite;
291
+ readonly y: Schema.Finite;
292
+ readonly z: Schema.Finite;
293
+ }>, Schema.Struct<{
294
+ readonly x: Schema.Finite;
295
+ readonly y: Schema.Finite;
296
+ readonly z: Schema.Finite;
297
+ }>, Schema.Struct<{
298
+ readonly x: Schema.Finite;
299
+ readonly y: Schema.Finite;
300
+ readonly z: Schema.Finite;
301
+ }>]>, readonly [Schema.Struct<{
302
+ readonly x: Schema.Finite;
303
+ readonly y: Schema.Finite;
304
+ readonly z: Schema.Finite;
305
+ }>]>;
306
+ }>, Schema.Struct<{
307
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
308
+ readonly id: Schema.String;
309
+ readonly kind: Schema.Literal<"polyline">;
310
+ readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
311
+ readonly x: Schema.Finite;
312
+ readonly y: Schema.Finite;
313
+ readonly z: Schema.Finite;
314
+ }>, Schema.Struct<{
315
+ readonly x: Schema.Finite;
316
+ readonly y: Schema.Finite;
317
+ readonly z: Schema.Finite;
318
+ }>]>, readonly [Schema.Struct<{
319
+ readonly x: Schema.Finite;
320
+ readonly y: Schema.Finite;
321
+ readonly z: Schema.Finite;
322
+ }>]>;
323
+ }>, Schema.Struct<{
324
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
325
+ readonly id: Schema.String;
326
+ readonly from: Schema.Struct<{
327
+ readonly x: Schema.Finite;
328
+ readonly y: Schema.Finite;
329
+ readonly z: Schema.Finite;
330
+ }>;
331
+ readonly kind: Schema.Literal<"ray">;
332
+ readonly through: Schema.Struct<{
333
+ readonly x: Schema.Finite;
334
+ readonly y: Schema.Finite;
335
+ readonly z: Schema.Finite;
336
+ }>;
337
+ }>, Schema.Struct<{
338
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
339
+ readonly id: Schema.String;
340
+ readonly from: Schema.Struct<{
341
+ readonly x: Schema.Finite;
342
+ readonly y: Schema.Finite;
343
+ readonly z: Schema.Finite;
344
+ }>;
345
+ readonly kind: Schema.Literal<"segment">;
346
+ readonly to: Schema.Struct<{
347
+ readonly x: Schema.Finite;
348
+ readonly y: Schema.Finite;
349
+ readonly z: Schema.Finite;
350
+ }>;
351
+ }>, Schema.Struct<{
352
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
353
+ readonly id: Schema.String;
354
+ readonly kind: Schema.Literal<"spline">;
355
+ readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
356
+ readonly x: Schema.Finite;
357
+ readonly y: Schema.Finite;
358
+ readonly z: Schema.Finite;
359
+ }>, Schema.Struct<{
360
+ readonly x: Schema.Finite;
361
+ readonly y: Schema.Finite;
362
+ readonly z: Schema.Finite;
363
+ }>, Schema.Struct<{
364
+ readonly x: Schema.Finite;
365
+ readonly y: Schema.Finite;
366
+ readonly z: Schema.Finite;
367
+ }>]>, readonly [Schema.Struct<{
368
+ readonly x: Schema.Finite;
369
+ readonly y: Schema.Finite;
370
+ readonly z: Schema.Finite;
371
+ }>]>;
372
+ }>]>>;
373
+ readonly space: Schema.Literal<"space">;
374
+ readonly view: Schema.Union<readonly [Schema.Struct<{
375
+ readonly kind: Schema.Literal<"camera">;
376
+ readonly position: Schema.Struct<{
377
+ readonly x: Schema.Finite;
378
+ readonly y: Schema.Finite;
379
+ readonly z: Schema.Finite;
380
+ }>;
381
+ readonly target: Schema.Struct<{
382
+ readonly x: Schema.Finite;
383
+ readonly y: Schema.Finite;
384
+ readonly z: Schema.Finite;
385
+ }>;
386
+ }>, Schema.Struct<{
387
+ readonly kind: Schema.Literal<"fit">;
388
+ readonly padding: Schema.optionalKey<Schema.Finite>;
389
+ }>, Schema.Struct<{
390
+ readonly kind: Schema.Literal<"isometric">;
391
+ readonly target: Schema.optionalKey<Schema.Struct<{
392
+ readonly x: Schema.Finite;
393
+ readonly y: Schema.Finite;
394
+ readonly z: Schema.Finite;
395
+ }>>;
396
+ }>]>;
397
+ }>;
@@ -0,0 +1,129 @@
1
+ import { Schema } from "effect";
2
+ import { hasUniquePositions, MathAppearanceSchema, MathAxisRangeSchema, MathFeatureVisibilitySchema, MathLabelPlacementSchema, MathViewPaddingSchema, MathVisualKeySchema, mathVisualIdentityIssues, PositiveMeasureSchema, SpacePointSchema, sameSpacePoint, } from "#contracts/math/base";
3
+ import { hasCoplanarArea } from "#contracts/math/vector";
4
+ const ObjectFields = {
5
+ appearance: MathAppearanceSchema,
6
+ id: MathVisualKeySchema,
7
+ };
8
+ const SpacePointObjectSchema = Schema.Struct({
9
+ ...ObjectFields,
10
+ at: SpacePointSchema,
11
+ kind: Schema.Literal("point"),
12
+ });
13
+ const SpacePathSchema = Schema.TupleWithRest(Schema.Tuple([SpacePointSchema, SpacePointSchema]), [SpacePointSchema]);
14
+ const SpaceShapeSchema = Schema.TupleWithRest(Schema.Tuple([SpacePointSchema, SpacePointSchema, SpacePointSchema]), [SpacePointSchema]);
15
+ const SpaceLineObjectSchema = Schema.Struct({
16
+ ...ObjectFields,
17
+ kind: Schema.Literal("line"),
18
+ through: Schema.Tuple([SpacePointSchema, SpacePointSchema]),
19
+ }).pipe(Schema.check(Schema.makeFilter(({ through: [from, to] }) => !sameSpacePoint(from, to), {
20
+ message: "Expected a line through two distinct positions.",
21
+ })));
22
+ const SpaceRayObjectSchema = Schema.Struct({
23
+ ...ObjectFields,
24
+ from: SpacePointSchema,
25
+ kind: Schema.Literal("ray"),
26
+ through: SpacePointSchema,
27
+ }).pipe(Schema.check(Schema.makeFilter(({ from, through }) => !sameSpacePoint(from, through), {
28
+ message: "Expected a ray through a position distinct from its start.",
29
+ })));
30
+ const SpaceSegmentObjectSchema = Schema.Struct({
31
+ ...ObjectFields,
32
+ from: SpacePointSchema,
33
+ kind: Schema.Literal("segment"),
34
+ to: SpacePointSchema,
35
+ }).pipe(Schema.check(Schema.makeFilter(({ from, to }) => !sameSpacePoint(from, to), {
36
+ message: "Expected a segment with distinct ends.",
37
+ })));
38
+ const SpacePolylineObjectSchema = Schema.Struct({
39
+ ...ObjectFields,
40
+ kind: Schema.Literal("polyline"),
41
+ vertices: SpacePathSchema,
42
+ }).pipe(Schema.check(Schema.makeFilter(({ vertices }) => hasUniquePositions(vertices, sameSpacePoint), { message: "Expected unique polyline vertices." })));
43
+ const SpacePolygonObjectSchema = Schema.Struct({
44
+ ...ObjectFields,
45
+ kind: Schema.Literal("polygon"),
46
+ vertices: SpaceShapeSchema,
47
+ }).pipe(Schema.check(Schema.makeFilter(({ vertices }) => hasUniquePositions(vertices, sameSpacePoint) &&
48
+ hasCoplanarArea(vertices), {
49
+ message: "Expected unique, coplanar vertices forming a non-degenerate polygon.",
50
+ })));
51
+ const SpaceSplineObjectSchema = Schema.Struct({
52
+ ...ObjectFields,
53
+ kind: Schema.Literal("spline"),
54
+ samples: SpaceShapeSchema,
55
+ }).pipe(Schema.check(Schema.makeFilter(({ samples }) => hasUniquePositions(samples, sameSpacePoint), { message: "Expected at least three unique spline samples." })));
56
+ const SpaceClosedSplineObjectSchema = Schema.Struct({
57
+ ...ObjectFields,
58
+ kind: Schema.Literal("closed-spline"),
59
+ samples: SpaceShapeSchema,
60
+ }).pipe(Schema.check(Schema.makeFilter(({ samples }) => hasUniquePositions(samples, sameSpacePoint), {
61
+ message: "Expected unique closed-spline samples without a repeated closing sample.",
62
+ })));
63
+ /**
64
+ * Axis-aligned cuboid whose length spans x, height spans y, and width spans z.
65
+ */
66
+ const SpaceCuboidObjectSchema = Schema.Struct({
67
+ ...ObjectFields,
68
+ center: SpacePointSchema,
69
+ kind: Schema.Literal("cuboid"),
70
+ size: Schema.Struct({
71
+ height: PositiveMeasureSchema,
72
+ length: PositiveMeasureSchema,
73
+ width: PositiveMeasureSchema,
74
+ }),
75
+ });
76
+ /** Mathematical objects supported by a Cartesian space scene. */
77
+ export const SpaceMathObjectSchema = Schema.Union([
78
+ SpaceClosedSplineObjectSchema,
79
+ SpaceCuboidObjectSchema,
80
+ SpaceLineObjectSchema,
81
+ SpacePointObjectSchema,
82
+ SpacePolygonObjectSchema,
83
+ SpacePolylineObjectSchema,
84
+ SpaceRayObjectSchema,
85
+ SpaceSegmentObjectSchema,
86
+ SpaceSplineObjectSchema,
87
+ ]);
88
+ /** Exact Cartesian frame presented behind a space construction. */
89
+ export const SpaceMathFrameSchema = Schema.Struct({
90
+ axes: MathFeatureVisibilitySchema,
91
+ grid: MathFeatureVisibilitySchema,
92
+ kind: Schema.Literal("cartesian"),
93
+ x: MathAxisRangeSchema,
94
+ y: MathAxisRangeSchema,
95
+ z: MathAxisRangeSchema,
96
+ });
97
+ const SpaceFitViewSchema = Schema.Struct({
98
+ kind: Schema.Literal("fit"),
99
+ padding: Schema.optionalKey(MathViewPaddingSchema),
100
+ });
101
+ const SpaceIsometricViewSchema = Schema.Struct({
102
+ kind: Schema.Literal("isometric"),
103
+ target: Schema.optionalKey(SpacePointSchema),
104
+ });
105
+ const SpaceCameraViewSchema = Schema.Struct({
106
+ kind: Schema.Literal("camera"),
107
+ position: SpacePointSchema,
108
+ target: SpacePointSchema,
109
+ }).pipe(Schema.check(Schema.makeFilter(({ position, target }) => !sameSpacePoint(position, target), { message: "Expected distinct camera position and target." })));
110
+ /** Minimal semantic views supported by one space scene. */
111
+ export const SpaceMathViewSchema = Schema.Union([
112
+ SpaceCameraViewSchema,
113
+ SpaceFitViewSchema,
114
+ SpaceIsometricViewSchema,
115
+ ]);
116
+ /** One coordinate anchor resolved against a separate rich-label map. */
117
+ export const SpaceLabelAnchorSchema = Schema.Struct({
118
+ at: SpacePointSchema,
119
+ key: MathVisualKeySchema,
120
+ placement: Schema.optionalKey(MathLabelPlacementSchema),
121
+ });
122
+ /** Complete stable space visual before rich labels are attached. */
123
+ export const SpaceMathVisualSchema = Schema.Struct({
124
+ frame: SpaceMathFrameSchema,
125
+ labels: Schema.optionalKey(Schema.Array(SpaceLabelAnchorSchema)),
126
+ objects: Schema.NonEmptyArray(SpaceMathObjectSchema),
127
+ space: Schema.Literal("space"),
128
+ view: SpaceMathViewSchema,
129
+ }).pipe(Schema.check(Schema.makeFilter(({ labels = [], objects }) => mathVisualIdentityIssues(objects, labels))));
@@ -0,0 +1,3 @@
1
+ import { type SpacePoint } from "#contracts/math/base";
2
+ /** Checks a space polygon is planar and has non-zero area. */
3
+ export declare function hasCoplanarArea(vertices: readonly [SpacePoint, SpacePoint, SpacePoint, ...SpacePoint[]]): boolean;