@mathscan/math-exercise-engine 1.0.3 → 1.0.5

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/README.md CHANGED
@@ -137,9 +137,11 @@ Creates an input field for text with up to 5 characters.
137
137
 
138
138
  ```
139
139
  TEXT_HIGHLIGHTER[value="123456", start=2, end=3]
140
+ HIGHLIGHT_TEXT[value="123456", start=2, end=3] // Alias
140
141
  ```
141
142
 
142
143
  Displays text with specific characters highlighted (useful for highlighting digits in numbers).
144
+ Both `TEXT_HIGHLIGHTER` and `HIGHLIGHT_TEXT` are supported (aliases).
143
145
 
144
146
  ### Validators
145
147
 
package/dist/index.d.ts CHANGED
@@ -19,6 +19,10 @@ export declare const AST_TYPES: {
19
19
  readonly SPACE: "Space";
20
20
  /** Text with optional character-range highlighting */
21
21
  readonly HIGHLIGHTED_TEXT: "HighlightedText";
22
+ /** Text with color and optional character-range coloring */
23
+ readonly COLOR_TEXT: "ColorText";
24
+ /** Bold text with optional character-range bolding */
25
+ readonly BOLD_TEXT: "BoldText";
22
26
  /** Inline input widget (string or numeric) */
23
27
  readonly INLINE_INPUT: "InlineInput";
24
28
  /** Question/instruction text block */
@@ -42,6 +46,108 @@ export declare const AST_TYPES: {
42
46
  */
43
47
  export declare type ASTType = typeof AST_TYPES[keyof typeof AST_TYPES];
44
48
 
49
+ export declare type BoldText = z.infer<typeof BoldTextSchema>;
50
+
51
+ export declare type BoldTextInline = z.infer<typeof BoldTextInlineSchema>;
52
+
53
+ /**
54
+ * Bold text inline schema - text with optional range bolding
55
+ *
56
+ * highlight: [start, end] character positions for bold range
57
+ *
58
+ * @example
59
+ * {
60
+ * type: "BoldText",
61
+ * value: "123456",
62
+ * highlight: [0, 3] // Bolds "123"
63
+ * }
64
+ */
65
+ export declare const BoldTextInlineSchema: z.ZodObject<{
66
+ type: z.ZodLiteral<"BoldText">;
67
+ value: z.ZodString;
68
+ highlight: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
69
+ }, "strip", z.ZodTypeAny, {
70
+ value: string;
71
+ type: "BoldText";
72
+ highlight?: [number, number] | undefined;
73
+ }, {
74
+ value: string;
75
+ type: "BoldText";
76
+ highlight?: [number, number] | undefined;
77
+ }>;
78
+
79
+ export declare const BoldTextSchema: z.ZodObject<{
80
+ id: z.ZodString;
81
+ type: z.ZodLiteral<"bold-text">;
82
+ value: z.ZodString;
83
+ highlight: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
84
+ }, "strip", z.ZodTypeAny, {
85
+ value: string;
86
+ type: "bold-text";
87
+ id: string;
88
+ highlight?: [number, number] | undefined;
89
+ }, {
90
+ value: string;
91
+ type: "bold-text";
92
+ id: string;
93
+ highlight?: [number, number] | undefined;
94
+ }>;
95
+
96
+ export declare type ColorText = z.infer<typeof ColorTextSchema>;
97
+
98
+ export declare type ColorTextInline = z.infer<typeof ColorTextInlineSchema>;
99
+
100
+ /**
101
+ * Color text inline schema - text with color and optional range coloring
102
+ *
103
+ * highlight: [start, end] character positions for colored range
104
+ * color: CSS color value (e.g., "red", "#ff0000")
105
+ *
106
+ * @example
107
+ * {
108
+ * type: "ColorText",
109
+ * value: "123456",
110
+ * color: "red",
111
+ * highlight: [0, 3] // Colors "123" in red
112
+ * }
113
+ */
114
+ export declare const ColorTextInlineSchema: z.ZodObject<{
115
+ type: z.ZodLiteral<"ColorText">;
116
+ value: z.ZodString;
117
+ color: z.ZodString;
118
+ highlight: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
119
+ }, "strip", z.ZodTypeAny, {
120
+ value: string;
121
+ type: "ColorText";
122
+ color: string;
123
+ highlight?: [number, number] | undefined;
124
+ }, {
125
+ value: string;
126
+ type: "ColorText";
127
+ color: string;
128
+ highlight?: [number, number] | undefined;
129
+ }>;
130
+
131
+ export declare const ColorTextSchema: z.ZodObject<{
132
+ id: z.ZodString;
133
+ type: z.ZodLiteral<"color-text">;
134
+ value: z.ZodString;
135
+ color: z.ZodString;
136
+ highlight: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
137
+ }, "strip", z.ZodTypeAny, {
138
+ value: string;
139
+ type: "color-text";
140
+ color: string;
141
+ id: string;
142
+ highlight?: [number, number] | undefined;
143
+ }, {
144
+ value: string;
145
+ type: "color-text";
146
+ color: string;
147
+ id: string;
148
+ highlight?: [number, number] | undefined;
149
+ }>;
150
+
45
151
  /**
46
152
  * Compile DSL text directly to JSON (convenience function)
47
153
  *
@@ -91,6 +197,15 @@ export declare function compileWithAST(dsl: string): {
91
197
  value: string;
92
198
  type: "HighlightedText";
93
199
  highlight?: [number, number] | undefined;
200
+ } | {
201
+ value: string;
202
+ type: "ColorText";
203
+ color: string;
204
+ highlight?: [number, number] | undefined;
205
+ } | {
206
+ value: string;
207
+ type: "BoldText";
208
+ highlight?: [number, number] | undefined;
94
209
  } | {
95
210
  length: number;
96
211
  type: "InlineInput";
@@ -153,6 +268,16 @@ export declare function compileWithAST(dsl: string): {
153
268
  };
154
269
  };
155
270
 
271
+ /**
272
+ * Create a bold text inline element
273
+ */
274
+ export declare function createBoldText(value: string, highlight?: [number, number]): BoldTextInline;
275
+
276
+ /**
277
+ * Create a color text inline element
278
+ */
279
+ export declare function createColorText(value: string, color: string, highlight?: [number, number]): ColorTextInline;
280
+
156
281
  /**
157
282
  * Create a drag options tool
158
283
  */
@@ -347,6 +472,33 @@ export declare const ExerciseDocumentSchema: z.ZodObject<{
347
472
  value: string;
348
473
  type: "HighlightedText";
349
474
  highlight?: [number, number] | undefined;
475
+ }>, z.ZodObject<{
476
+ type: z.ZodLiteral<"ColorText">;
477
+ value: z.ZodString;
478
+ color: z.ZodString;
479
+ highlight: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
480
+ }, "strip", z.ZodTypeAny, {
481
+ value: string;
482
+ type: "ColorText";
483
+ color: string;
484
+ highlight?: [number, number] | undefined;
485
+ }, {
486
+ value: string;
487
+ type: "ColorText";
488
+ color: string;
489
+ highlight?: [number, number] | undefined;
490
+ }>, z.ZodObject<{
491
+ type: z.ZodLiteral<"BoldText">;
492
+ value: z.ZodString;
493
+ highlight: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
494
+ }, "strip", z.ZodTypeAny, {
495
+ value: string;
496
+ type: "BoldText";
497
+ highlight?: [number, number] | undefined;
498
+ }, {
499
+ value: string;
500
+ type: "BoldText";
501
+ highlight?: [number, number] | undefined;
350
502
  }>, z.ZodDiscriminatedUnion<"inputType", [z.ZodObject<{
351
503
  type: z.ZodLiteral<"InlineInput">;
352
504
  name: z.ZodString;
@@ -395,6 +547,15 @@ export declare const ExerciseDocumentSchema: z.ZodObject<{
395
547
  value: string;
396
548
  type: "HighlightedText";
397
549
  highlight?: [number, number] | undefined;
550
+ } | {
551
+ value: string;
552
+ type: "ColorText";
553
+ color: string;
554
+ highlight?: [number, number] | undefined;
555
+ } | {
556
+ value: string;
557
+ type: "BoldText";
558
+ highlight?: [number, number] | undefined;
398
559
  } | {
399
560
  length: number;
400
561
  type: "InlineInput";
@@ -419,6 +580,15 @@ export declare const ExerciseDocumentSchema: z.ZodObject<{
419
580
  value: string;
420
581
  type: "HighlightedText";
421
582
  highlight?: [number, number] | undefined;
583
+ } | {
584
+ value: string;
585
+ type: "ColorText";
586
+ color: string;
587
+ highlight?: [number, number] | undefined;
588
+ } | {
589
+ value: string;
590
+ type: "BoldText";
591
+ highlight?: [number, number] | undefined;
422
592
  } | {
423
593
  length: number;
424
594
  type: "InlineInput";
@@ -490,6 +660,15 @@ export declare const ExerciseDocumentSchema: z.ZodObject<{
490
660
  value: string;
491
661
  type: "HighlightedText";
492
662
  highlight?: [number, number] | undefined;
663
+ } | {
664
+ value: string;
665
+ type: "ColorText";
666
+ color: string;
667
+ highlight?: [number, number] | undefined;
668
+ } | {
669
+ value: string;
670
+ type: "BoldText";
671
+ highlight?: [number, number] | undefined;
493
672
  } | {
494
673
  length: number;
495
674
  type: "InlineInput";
@@ -535,6 +714,15 @@ export declare const ExerciseDocumentSchema: z.ZodObject<{
535
714
  value: string;
536
715
  type: "HighlightedText";
537
716
  highlight?: [number, number] | undefined;
717
+ } | {
718
+ value: string;
719
+ type: "ColorText";
720
+ color: string;
721
+ highlight?: [number, number] | undefined;
722
+ } | {
723
+ value: string;
724
+ type: "BoldText";
725
+ highlight?: [number, number] | undefined;
538
726
  } | {
539
727
  length: number;
540
728
  type: "InlineInput";
@@ -1021,6 +1209,33 @@ export declare const InlineNodeSchema: z.ZodUnion<[z.ZodObject<{
1021
1209
  value: string;
1022
1210
  type: "HighlightedText";
1023
1211
  highlight?: [number, number] | undefined;
1212
+ }>, z.ZodObject<{
1213
+ type: z.ZodLiteral<"ColorText">;
1214
+ value: z.ZodString;
1215
+ color: z.ZodString;
1216
+ highlight: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
1217
+ }, "strip", z.ZodTypeAny, {
1218
+ value: string;
1219
+ type: "ColorText";
1220
+ color: string;
1221
+ highlight?: [number, number] | undefined;
1222
+ }, {
1223
+ value: string;
1224
+ type: "ColorText";
1225
+ color: string;
1226
+ highlight?: [number, number] | undefined;
1227
+ }>, z.ZodObject<{
1228
+ type: z.ZodLiteral<"BoldText">;
1229
+ value: z.ZodString;
1230
+ highlight: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
1231
+ }, "strip", z.ZodTypeAny, {
1232
+ value: string;
1233
+ type: "BoldText";
1234
+ highlight?: [number, number] | undefined;
1235
+ }, {
1236
+ value: string;
1237
+ type: "BoldText";
1238
+ highlight?: [number, number] | undefined;
1024
1239
  }>, z.ZodDiscriminatedUnion<"inputType", [z.ZodObject<{
1025
1240
  type: z.ZodLiteral<"InlineInput">;
1026
1241
  name: z.ZodString;
@@ -1059,6 +1274,20 @@ export declare const InlineNodeSchema: z.ZodUnion<[z.ZodObject<{
1059
1274
  answer?: string | number | undefined;
1060
1275
  }>]>]>;
1061
1276
 
1277
+ /**
1278
+ * Type guard for BoldText
1279
+ */
1280
+ export declare function isBoldText(item: LayoutItem): item is Extract<LayoutItem, {
1281
+ type: 'bold-text';
1282
+ }>;
1283
+
1284
+ /**
1285
+ * Type guard for ColorText
1286
+ */
1287
+ export declare function isColorText(item: LayoutItem): item is Extract<LayoutItem, {
1288
+ type: 'color-text';
1289
+ }>;
1290
+
1062
1291
  export declare function isDragOptions(value: unknown): value is DragOptionsTool;
1063
1292
 
1064
1293
  /**
@@ -1177,6 +1406,10 @@ export declare const JSON_TYPES: {
1177
1406
  readonly SPACE: "space";
1178
1407
  /** Text with optional highlighting */
1179
1408
  readonly HIGHLIGHTED_TEXT: "highlighted-text";
1409
+ /** Text with color styling */
1410
+ readonly COLOR_TEXT: "color-text";
1411
+ /** Bold text */
1412
+ readonly BOLD_TEXT: "bold-text";
1180
1413
  /** Reference to a widget */
1181
1414
  readonly WIDGET_REF: "widget-ref";
1182
1415
  /** Line break element */
@@ -1272,6 +1505,33 @@ export declare const LineBlockSchema: z.ZodObject<{
1272
1505
  value: string;
1273
1506
  type: "HighlightedText";
1274
1507
  highlight?: [number, number] | undefined;
1508
+ }>, z.ZodObject<{
1509
+ type: z.ZodLiteral<"ColorText">;
1510
+ value: z.ZodString;
1511
+ color: z.ZodString;
1512
+ highlight: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
1513
+ }, "strip", z.ZodTypeAny, {
1514
+ value: string;
1515
+ type: "ColorText";
1516
+ color: string;
1517
+ highlight?: [number, number] | undefined;
1518
+ }, {
1519
+ value: string;
1520
+ type: "ColorText";
1521
+ color: string;
1522
+ highlight?: [number, number] | undefined;
1523
+ }>, z.ZodObject<{
1524
+ type: z.ZodLiteral<"BoldText">;
1525
+ value: z.ZodString;
1526
+ highlight: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
1527
+ }, "strip", z.ZodTypeAny, {
1528
+ value: string;
1529
+ type: "BoldText";
1530
+ highlight?: [number, number] | undefined;
1531
+ }, {
1532
+ value: string;
1533
+ type: "BoldText";
1534
+ highlight?: [number, number] | undefined;
1275
1535
  }>, z.ZodDiscriminatedUnion<"inputType", [z.ZodObject<{
1276
1536
  type: z.ZodLiteral<"InlineInput">;
1277
1537
  name: z.ZodString;
@@ -1320,6 +1580,15 @@ export declare const LineBlockSchema: z.ZodObject<{
1320
1580
  value: string;
1321
1581
  type: "HighlightedText";
1322
1582
  highlight?: [number, number] | undefined;
1583
+ } | {
1584
+ value: string;
1585
+ type: "ColorText";
1586
+ color: string;
1587
+ highlight?: [number, number] | undefined;
1588
+ } | {
1589
+ value: string;
1590
+ type: "BoldText";
1591
+ highlight?: [number, number] | undefined;
1323
1592
  } | {
1324
1593
  length: number;
1325
1594
  type: "InlineInput";
@@ -1344,6 +1613,15 @@ export declare const LineBlockSchema: z.ZodObject<{
1344
1613
  value: string;
1345
1614
  type: "HighlightedText";
1346
1615
  highlight?: [number, number] | undefined;
1616
+ } | {
1617
+ value: string;
1618
+ type: "ColorText";
1619
+ color: string;
1620
+ highlight?: [number, number] | undefined;
1621
+ } | {
1622
+ value: string;
1623
+ type: "BoldText";
1624
+ highlight?: [number, number] | undefined;
1347
1625
  } | {
1348
1626
  length: number;
1349
1627
  type: "InlineInput";