@mathscan/math-exercise-engine 1.2.7 → 1.2.9

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/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { CheckGeometryAnswerResult } from '@mathscan/geometry-engine/validation';
1
2
  import { CstNode } from 'chevrotain';
2
3
  import { default as default_2 } from 'react';
3
4
  import { ForwardRefExoticComponent } from 'react';
@@ -57,6 +58,8 @@ export declare const AST_TYPES: {
57
58
  readonly NUMBER_LINE_BLOCK: "NumberLineBlock";
58
59
  /** Symmetry exercise on a square grid */
59
60
  readonly GRID_SYMMETRY_BLOCK: "GridSymmetryBlock";
61
+ /** Geometry widget definition carried as raw JSON for the external engine */
62
+ readonly GEOMETRY_BLOCK: "GeometryBlock";
60
63
  /** A position marker on the number line */
61
64
  readonly NUMBER_LINE_POSITION: "NumberLinePosition";
62
65
  /** A draggable cursor on the number line */
@@ -6268,6 +6271,10 @@ export declare function compileWithAST(dsl: string): {
6268
6271
  interactiveArea: "left" | "right" | "top" | "bottom";
6269
6272
  cellSize: number;
6270
6273
  cells: [number, number][];
6274
+ } | {
6275
+ type: "GeometryBlock";
6276
+ name?: string | undefined;
6277
+ json?: unknown;
6271
6278
  } | {
6272
6279
  type: "TableBlock";
6273
6280
  rows: {
@@ -7083,6 +7090,9 @@ export declare function compileWithAST(dsl: string): {
7083
7090
  } | {
7084
7091
  type: "set-square";
7085
7092
  size?: number | undefined;
7093
+ } | {
7094
+ type: "geometry";
7095
+ json?: unknown;
7086
7096
  }>;
7087
7097
  validation?: {
7088
7098
  mode: "simple" | "expression" | "mixed";
@@ -16365,6 +16375,18 @@ export declare const ContentBlockSchema: z.ZodUnion<[z.ZodObject<{
16365
16375
  snap?: number | undefined;
16366
16376
  })[] | undefined;
16367
16377
  }[] | undefined;
16378
+ }>, z.ZodObject<{
16379
+ type: z.ZodLiteral<"GeometryBlock">;
16380
+ json: z.ZodUnknown;
16381
+ name: z.ZodOptional<z.ZodString>;
16382
+ }, "strip", z.ZodTypeAny, {
16383
+ type: "GeometryBlock";
16384
+ name?: string | undefined;
16385
+ json?: unknown;
16386
+ }, {
16387
+ type: "GeometryBlock";
16388
+ name?: string | undefined;
16389
+ json?: unknown;
16368
16390
  }>]>;
16369
16391
 
16370
16392
  /**
@@ -16452,6 +16474,10 @@ export declare function createFraction(name: string, options?: {
16452
16474
  */
16453
16475
  export declare function createFreeText(value: string): FreeTextInline;
16454
16476
 
16477
+ export declare function createGeometryBlock(json: unknown, options?: {
16478
+ name?: unknown;
16479
+ }): GeometryBlock;
16480
+
16455
16481
  export declare function createGridSymmetryBlock(rows: number, cols: number, axis: GridSymmetryAxis, interactiveArea: GridSymmetryInteractiveArea, cells: GridCell[], cellSize?: number): GridSymmetryBlock;
16456
16482
 
16457
16483
  /**
@@ -26120,6 +26146,18 @@ export declare const ExerciseDocumentSchema: z.ZodEffects<z.ZodObject<{
26120
26146
  snap?: number | undefined;
26121
26147
  })[] | undefined;
26122
26148
  }[] | undefined;
26149
+ }>, z.ZodObject<{
26150
+ type: z.ZodLiteral<"GeometryBlock">;
26151
+ json: z.ZodUnknown;
26152
+ name: z.ZodOptional<z.ZodString>;
26153
+ }, "strip", z.ZodTypeAny, {
26154
+ type: "GeometryBlock";
26155
+ name?: string | undefined;
26156
+ json?: unknown;
26157
+ }, {
26158
+ type: "GeometryBlock";
26159
+ name?: string | undefined;
26160
+ json?: unknown;
26123
26161
  }>]>, "many">;
26124
26162
  tools: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
26125
26163
  type: z.ZodLiteral<"DragOptions">;
@@ -26492,6 +26530,10 @@ export declare const ExerciseDocumentSchema: z.ZodEffects<z.ZodObject<{
26492
26530
  interactiveArea: "left" | "right" | "top" | "bottom";
26493
26531
  cellSize: number;
26494
26532
  cells: [number, number][];
26533
+ } | {
26534
+ type: "GeometryBlock";
26535
+ name?: string | undefined;
26536
+ json?: unknown;
26495
26537
  } | {
26496
26538
  type: "TableBlock";
26497
26539
  rows: {
@@ -27505,6 +27547,10 @@ export declare const ExerciseDocumentSchema: z.ZodEffects<z.ZodObject<{
27505
27547
  interactiveArea: "left" | "right" | "top" | "bottom";
27506
27548
  cells: [number, number][];
27507
27549
  cellSize?: number | undefined;
27550
+ } | {
27551
+ type: "GeometryBlock";
27552
+ name?: string | undefined;
27553
+ json?: unknown;
27508
27554
  } | {
27509
27555
  type: "TableBlock";
27510
27556
  rows: {
@@ -28518,6 +28564,10 @@ export declare const ExerciseDocumentSchema: z.ZodEffects<z.ZodObject<{
28518
28564
  interactiveArea: "left" | "right" | "top" | "bottom";
28519
28565
  cellSize: number;
28520
28566
  cells: [number, number][];
28567
+ } | {
28568
+ type: "GeometryBlock";
28569
+ name?: string | undefined;
28570
+ json?: unknown;
28521
28571
  } | {
28522
28572
  type: "TableBlock";
28523
28573
  rows: {
@@ -29531,6 +29581,10 @@ export declare const ExerciseDocumentSchema: z.ZodEffects<z.ZodObject<{
29531
29581
  interactiveArea: "left" | "right" | "top" | "bottom";
29532
29582
  cells: [number, number][];
29533
29583
  cellSize?: number | undefined;
29584
+ } | {
29585
+ type: "GeometryBlock";
29586
+ name?: string | undefined;
29587
+ json?: unknown;
29534
29588
  } | {
29535
29589
  type: "TableBlock";
29536
29590
  rows: {
@@ -30632,6 +30686,15 @@ export declare const ExerciseJSONSchema: z.ZodObject<{
30632
30686
  }, {
30633
30687
  value: number;
30634
30688
  type: "chart-picto";
30689
+ }>, z.ZodObject<{
30690
+ type: z.ZodLiteral<"geometry">;
30691
+ json: z.ZodUnknown;
30692
+ }, "strip", z.ZodTypeAny, {
30693
+ type: "geometry";
30694
+ json?: unknown;
30695
+ }, {
30696
+ type: "geometry";
30697
+ json?: unknown;
30635
30698
  }>]>>;
30636
30699
  validation: z.ZodOptional<z.ZodObject<{
30637
30700
  mode: z.ZodEnum<["simple", "expression", "mixed"]>;
@@ -30760,6 +30823,9 @@ export declare const ExerciseJSONSchema: z.ZodObject<{
30760
30823
  } | {
30761
30824
  type: "set-square";
30762
30825
  size?: number | undefined;
30826
+ } | {
30827
+ type: "geometry";
30828
+ json?: unknown;
30763
30829
  }>;
30764
30830
  validation?: {
30765
30831
  mode: "simple" | "expression" | "mixed";
@@ -30869,6 +30935,9 @@ export declare const ExerciseJSONSchema: z.ZodObject<{
30869
30935
  } | {
30870
30936
  type: "set-square";
30871
30937
  size?: number | undefined;
30938
+ } | {
30939
+ type: "geometry";
30940
+ json?: unknown;
30872
30941
  }>;
30873
30942
  validation?: {
30874
30943
  mode: "simple" | "expression" | "mixed";
@@ -31109,6 +31178,48 @@ export declare const FreeTextInlineSchema: z.ZodObject<{
31109
31178
  type: "FreeText";
31110
31179
  }>;
31111
31180
 
31181
+ export declare type GeometryBlock = z.infer<typeof GeometryBlockSchema>;
31182
+
31183
+ /**
31184
+ * Geometry widget definition carried as raw JSON for the external
31185
+ * @mathscan/geometry-engine package. Domain validation is intentionally not
31186
+ * duplicated here — this layer only guarantees the DSL payload is valid JSON.
31187
+ *
31188
+ * `name` comes from the DSL parameters, not the JSON: it is a host-side
31189
+ * setting (the widget id) the engine never sees.
31190
+ */
31191
+ export declare const GeometryBlockSchema: z.ZodObject<{
31192
+ type: z.ZodLiteral<"GeometryBlock">;
31193
+ json: z.ZodUnknown;
31194
+ name: z.ZodOptional<z.ZodString>;
31195
+ }, "strip", z.ZodTypeAny, {
31196
+ type: "GeometryBlock";
31197
+ name?: string | undefined;
31198
+ json?: unknown;
31199
+ }, {
31200
+ type: "GeometryBlock";
31201
+ name?: string | undefined;
31202
+ json?: unknown;
31203
+ }>;
31204
+
31205
+ export declare type GeometryJSON = z.infer<typeof GeometryJSONSchema>;
31206
+
31207
+ /**
31208
+ * Geometry widget. The payload is a raw JSON blob owned by the external
31209
+ * `@mathscan/geometry-engine` package — this layer does not validate its
31210
+ * shape (no domain validation, no answer checking, yet).
31211
+ */
31212
+ export declare const GeometryJSONSchema: z.ZodObject<{
31213
+ type: z.ZodLiteral<"geometry">;
31214
+ json: z.ZodUnknown;
31215
+ }, "strip", z.ZodTypeAny, {
31216
+ type: "geometry";
31217
+ json?: unknown;
31218
+ }, {
31219
+ type: "geometry";
31220
+ json?: unknown;
31221
+ }>;
31222
+
31112
31223
  /**
31113
31224
  * List every widget the exercise expects an answer for (simple answers,
31114
31225
  * expression variables, or both in mixed mode). Empty when the exercise has
@@ -31893,6 +32004,15 @@ export declare function isFractionKey(key: string): boolean;
31893
32004
 
31894
32005
  export declare function isFreeText(value: unknown): value is FreeTextInline;
31895
32006
 
32007
+ export declare function isGeometryBlock(value: unknown): value is GeometryBlock;
32008
+
32009
+ /**
32010
+ * Type guard for GeometryJSON
32011
+ */
32012
+ export declare function isGeometryJSON(widget: WidgetJSON): widget is Extract<WidgetJSON, {
32013
+ type: 'geometry';
32014
+ }>;
32015
+
31896
32016
  export declare function isGridSymmetryBlock(value: unknown): value is GridSymmetryBlock;
31897
32017
 
31898
32018
  export declare function isGridSymmetryJSON(widget: WidgetJSON): widget is Extract<WidgetJSON, {
@@ -32193,6 +32313,8 @@ export declare const JSON_TYPES: {
32193
32313
  readonly PROTRACTOR: "protractor";
32194
32314
  /** Set square geometry tool widget */
32195
32315
  readonly SET_SQUARE: "set-square";
32316
+ /** Geometry widget definition carried as raw JSON for the external engine */
32317
+ readonly GEOMETRY: "geometry";
32196
32318
  };
32197
32319
 
32198
32320
  /**
@@ -39409,6 +39531,18 @@ export declare const RulerWidgetSchema: z.ZodObject<{
39409
39531
  size?: number | undefined;
39410
39532
  }>;
39411
39533
 
39534
+ /** Explicit scoring units contributed by a validator. */
39535
+ export declare interface ScoreContribution {
39536
+ correct: boolean;
39537
+ earned: number;
39538
+ possible: number;
39539
+ }
39540
+
39541
+ /** A result from one of this package's validators: `scoreContribution` is always present. */
39542
+ export declare type ScoredValidationResult = ValidationResult & {
39543
+ scoreContribution: ScoreContribution;
39544
+ };
39545
+
39412
39546
  export declare type SetSquareTool = z.infer<typeof SetSquareToolSchema>;
39413
39547
 
39414
39548
  export declare const SetSquareToolSchema: z.ZodObject<{
@@ -41747,7 +41881,7 @@ export declare function useSound(): (event: SoundEvent) => void;
41747
41881
  * }
41748
41882
  * ```
41749
41883
  */
41750
- export declare function validate(exercise: ExerciseJSON, userInputs: Record<string, string | number | string[][] | number[] | GridCell[]>): ValidationResult;
41884
+ export declare function validate(exercise: ExerciseJSON, userInputs: Record<string, string | number | string[][] | number[] | GridCell[]>): ScoredValidationResult;
41751
41885
 
41752
41886
  /**
41753
41887
  * Validate that an expression will return a boolean
@@ -41873,6 +42007,9 @@ export declare function validateExerciseJSON(data: unknown): {
41873
42007
  } | {
41874
42008
  type: "set-square";
41875
42009
  size?: number | undefined;
42010
+ } | {
42011
+ type: "geometry";
42012
+ json?: unknown;
41876
42013
  }>;
41877
42014
  validation?: {
41878
42015
  mode: "simple" | "expression" | "mixed";
@@ -42000,6 +42137,9 @@ export declare function validateExerciseJSONSafe(data: unknown): z.SafeParseRetu
42000
42137
  } | {
42001
42138
  type: "set-square";
42002
42139
  size?: number | undefined;
42140
+ } | {
42141
+ type: "geometry";
42142
+ json?: unknown;
42003
42143
  }>;
42004
42144
  validation?: {
42005
42145
  mode: "simple" | "expression" | "mixed";
@@ -42109,6 +42249,9 @@ export declare function validateExerciseJSONSafe(data: unknown): z.SafeParseRetu
42109
42249
  } | {
42110
42250
  type: "set-square";
42111
42251
  size?: number | undefined;
42252
+ } | {
42253
+ type: "geometry";
42254
+ json?: unknown;
42112
42255
  }>;
42113
42256
  validation?: {
42114
42257
  mode: "simple" | "expression" | "mixed";
@@ -42132,7 +42275,7 @@ export declare function validateExerciseJSONSafe(data: unknown): z.SafeParseRetu
42132
42275
  * @param userInputs - User's answers keyed by widget ID (variable names)
42133
42276
  * @returns Validation result
42134
42277
  */
42135
- export declare function validateExpression(exercise: ValidatedExerciseJSON, userInputs: Record<string, string | number>): ValidationResult;
42278
+ export declare function validateExpression(exercise: ValidatedExerciseJSON, userInputs: Record<string, string | number>): ScoredValidationResult;
42136
42279
 
42137
42280
  /**
42138
42281
  * Check if user inputs are valid (proper format, etc.)
@@ -42151,7 +42294,7 @@ export declare function validateInputFormats(exercise: ExerciseJSON, userInputs:
42151
42294
  * @param userInputs - User's answers keyed by widget ID
42152
42295
  * @returns Validation result
42153
42296
  */
42154
- export declare function validateMixed(exercise: ValidatedExerciseJSON, userInputs: Record<string, string | number | string[][] | number[] | GridCell[]>): ValidationResult;
42297
+ export declare function validateMixed(exercise: ValidatedExerciseJSON, userInputs: Record<string, string | number | string[][] | number[] | GridCell[]>): ScoredValidationResult;
42155
42298
 
42156
42299
  /**
42157
42300
  * Validate using simple mode (predetermined answers)
@@ -42160,7 +42303,7 @@ export declare function validateMixed(exercise: ValidatedExerciseJSON, userInput
42160
42303
  * @param userInputs - User's answers keyed by widget ID
42161
42304
  * @returns Validation result
42162
42305
  */
42163
- export declare function validateSimple(exercise: ValidatedExerciseJSON, userInputs: Record<string, string | number | string[][] | number[] | GridCell[]>): ValidationResult;
42306
+ export declare function validateSimple(exercise: ValidatedExerciseJSON, userInputs: Record<string, string | number | string[][] | number[] | GridCell[]>): ScoredValidationResult;
42164
42307
 
42165
42308
  export declare function validateVisualFractionCapacity(data: {
42166
42309
  divisions: number;
@@ -42268,6 +42411,9 @@ export declare function validateWidgetJSON(data: unknown): {
42268
42411
  } | {
42269
42412
  type: "set-square";
42270
42413
  size?: number | undefined;
42414
+ } | {
42415
+ type: "geometry";
42416
+ json?: unknown;
42271
42417
  };
42272
42418
 
42273
42419
  /**
@@ -42368,6 +42514,9 @@ export declare function validateWidgetJSONSafe(data: unknown): z.SafeParseReturn
42368
42514
  } | {
42369
42515
  type: "set-square";
42370
42516
  size?: number | undefined;
42517
+ } | {
42518
+ type: "geometry";
42519
+ json?: unknown;
42371
42520
  }, {
42372
42521
  length: number;
42373
42522
  type: "inline-input";
@@ -42460,6 +42609,9 @@ export declare function validateWidgetJSONSafe(data: unknown): z.SafeParseReturn
42460
42609
  } | {
42461
42610
  type: "set-square";
42462
42611
  size?: number | undefined;
42612
+ } | {
42613
+ type: "geometry";
42614
+ json?: unknown;
42463
42615
  }>;
42464
42616
 
42465
42617
  /**
@@ -42530,6 +42682,12 @@ export declare interface ValidationResult {
42530
42682
  details: Record<string, WidgetValidation>;
42531
42683
  /** Numeric score (0-1) for partial grading */
42532
42684
  score?: number;
42685
+ /**
42686
+ * Raw scoring units, used when combining independent validators. Always set
42687
+ * by this package's validators; optional so host code that builds its own
42688
+ * results keeps compiling.
42689
+ */
42690
+ scoreContribution?: ScoreContribution;
42533
42691
  /** The expression that was evaluated (expression mode only) */
42534
42692
  expression?: string;
42535
42693
  /** The scope used for evaluation (expression mode only, debugging) */
@@ -45581,6 +45739,15 @@ export declare const WidgetJSONSchema: z.ZodUnion<[z.ZodDiscriminatedUnion<"inpu
45581
45739
  }, {
45582
45740
  value: number;
45583
45741
  type: "chart-picto";
45742
+ }>, z.ZodObject<{
45743
+ type: z.ZodLiteral<"geometry">;
45744
+ json: z.ZodUnknown;
45745
+ }, "strip", z.ZodTypeAny, {
45746
+ type: "geometry";
45747
+ json?: unknown;
45748
+ }, {
45749
+ type: "geometry";
45750
+ json?: unknown;
45584
45751
  }>]>;
45585
45752
 
45586
45753
  export declare type WidgetRef = z.infer<typeof WidgetRefSchema>;
@@ -45650,6 +45817,14 @@ export declare interface WidgetValidation {
45650
45817
  * Equal to the overall expression boolean; the per-widget granularity comes from `simpleCorrect`.
45651
45818
  */
45652
45819
  expressionCorrect?: boolean;
45820
+ /**
45821
+ * GEOMETRY widgets: the geometry engine's own verdict, passed through
45822
+ * untouched. The renderer hands it back to `StudentGeometryExercise` as
45823
+ * `validationFeedback`; the engine decides what the canvas shows and, through
45824
+ * the fingerprints inside it, whether the result still describes the figure on
45825
+ * screen. Nothing in this package reads its contents.
45826
+ */
45827
+ geometryFeedback?: CheckGeometryAnswerResult;
45653
45828
  /** Optional error message (for debugging) */
45654
45829
  error?: string;
45655
45830
  }