@mathscan/math-exercise-engine 1.0.0 → 1.0.2
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 +56 -41
- package/dist/index.d.ts +1 -22
- package/dist/index.js +29 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -31
- package/dist/index.mjs.map +1 -1
- package/dist/style.css +216 -4
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -29,14 +29,18 @@ const QUESTION_TEXT = createToken({
|
|
|
29
29
|
name: "QUESTION_TEXT",
|
|
30
30
|
pattern: /QUESTION_TEXT/
|
|
31
31
|
});
|
|
32
|
-
const
|
|
33
|
-
name: "
|
|
34
|
-
pattern: /
|
|
32
|
+
const TEXT_HIGHLIGHTER = createToken({
|
|
33
|
+
name: "TEXT_HIGHLIGHTER",
|
|
34
|
+
pattern: /TEXT_HIGHLIGHTER/
|
|
35
35
|
});
|
|
36
36
|
const W_S_I = createToken({
|
|
37
37
|
name: "W_S_I",
|
|
38
38
|
pattern: /W_S_I/
|
|
39
39
|
});
|
|
40
|
+
const STRING_INPUT = createToken({
|
|
41
|
+
name: "STRING_INPUT",
|
|
42
|
+
pattern: /STRING_INPUT/
|
|
43
|
+
});
|
|
40
44
|
const DRAGABLE_BUTTONS_OPTIONS = createToken({
|
|
41
45
|
name: "DRAGABLE_BUTTONS_OPTIONS",
|
|
42
46
|
pattern: /DRAGABLE_BUTTONS_OPTIONS/
|
|
@@ -53,6 +57,10 @@ const W_N_I = createToken({
|
|
|
53
57
|
name: "W_N_I",
|
|
54
58
|
pattern: /W_N_I/
|
|
55
59
|
});
|
|
60
|
+
const NUMERIC_INPUT = createToken({
|
|
61
|
+
name: "NUMERIC_INPUT",
|
|
62
|
+
pattern: /NUMERIC_INPUT/
|
|
63
|
+
});
|
|
56
64
|
const NumberLiteral = createToken({
|
|
57
65
|
name: "NumberLiteral",
|
|
58
66
|
pattern: /-?\d+(\.\d+)?/
|
|
@@ -135,13 +143,14 @@ const allTokens = [
|
|
|
135
143
|
Comment,
|
|
136
144
|
// Component keywords (before Identifier!)
|
|
137
145
|
QUESTION_TEXT,
|
|
138
|
-
|
|
146
|
+
TEXT_HIGHLIGHTER,
|
|
139
147
|
W_S_I,
|
|
148
|
+
STRING_INPUT,
|
|
140
149
|
DRAGABLE_BUTTONS_OPTIONS,
|
|
141
150
|
NUMERIC_KEYPAD,
|
|
142
151
|
WIDGET_ANSWER,
|
|
143
|
-
// Legacy keywords
|
|
144
152
|
W_N_I,
|
|
153
|
+
NUMERIC_INPUT,
|
|
145
154
|
// Literals
|
|
146
155
|
NumberLiteral,
|
|
147
156
|
StringLiteral,
|
|
@@ -319,14 +328,14 @@ class MathExerciseParser extends CstParser {
|
|
|
319
328
|
// Parentheses (for grouping)
|
|
320
329
|
{ ALT: () => this.CONSUME(LParen) },
|
|
321
330
|
{ ALT: () => this.CONSUME(RParen) },
|
|
322
|
-
//
|
|
323
|
-
{ ALT: () => this.SUBRULE(this.
|
|
331
|
+
// TEXT_HIGHLIGHTER (for highlighting)
|
|
332
|
+
{ ALT: () => this.SUBRULE(this.textHighlighter) },
|
|
324
333
|
// W_S_I (inline input widget)
|
|
325
334
|
{ ALT: () => this.SUBRULE(this.inlineInput) }
|
|
326
335
|
]);
|
|
327
336
|
});
|
|
328
|
-
this.
|
|
329
|
-
this.CONSUME(
|
|
337
|
+
this.textHighlighter = this.RULE("textHighlighter", () => {
|
|
338
|
+
this.CONSUME(TEXT_HIGHLIGHTER);
|
|
330
339
|
this.CONSUME(LBracket);
|
|
331
340
|
this.SUBRULE(this.parameterList);
|
|
332
341
|
this.CONSUME(RBracket);
|
|
@@ -334,7 +343,9 @@ class MathExerciseParser extends CstParser {
|
|
|
334
343
|
this.inlineInput = this.RULE("inlineInput", () => {
|
|
335
344
|
this.OR([
|
|
336
345
|
{ ALT: () => this.CONSUME(W_S_I, { LABEL: "stringInput" }) },
|
|
337
|
-
{ ALT: () => this.CONSUME(
|
|
346
|
+
{ ALT: () => this.CONSUME(STRING_INPUT, { LABEL: "stringInput" }) },
|
|
347
|
+
{ ALT: () => this.CONSUME(W_N_I, { LABEL: "numericInput" }) },
|
|
348
|
+
{ ALT: () => this.CONSUME(NUMERIC_INPUT, { LABEL: "numericInput" }) }
|
|
338
349
|
]);
|
|
339
350
|
this.CONSUME(LBracket);
|
|
340
351
|
this.SUBRULE(this.parameterList);
|
|
@@ -527,13 +538,6 @@ function createNumericInput(name, digits, answer) {
|
|
|
527
538
|
answer
|
|
528
539
|
});
|
|
529
540
|
}
|
|
530
|
-
function createInlineInput(name, inputType, lengthOrDigits, answer) {
|
|
531
|
-
if (inputType === "string") {
|
|
532
|
-
return createStringInput(name, lengthOrDigits, answer);
|
|
533
|
-
} else {
|
|
534
|
-
return createNumericInput(name, lengthOrDigits, answer);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
541
|
function isFreeText(value) {
|
|
538
542
|
return FreeTextInlineSchema.safeParse(value).success;
|
|
539
543
|
}
|
|
@@ -752,18 +756,21 @@ class NaturalDSLVisitor extends BaseCstVisitor {
|
|
|
752
756
|
const token = ctx.RParen[0];
|
|
753
757
|
return createFreeText(token.image);
|
|
754
758
|
}
|
|
755
|
-
if (ctx.
|
|
756
|
-
return this.visit(ctx.
|
|
759
|
+
if (ctx.textHighlighter) {
|
|
760
|
+
return this.visit(ctx.textHighlighter);
|
|
757
761
|
}
|
|
758
762
|
if (ctx.inlineInput) {
|
|
759
763
|
return this.visit(ctx.inlineInput);
|
|
760
764
|
}
|
|
761
765
|
throw new Error("Unknown inline element");
|
|
762
766
|
}
|
|
763
|
-
|
|
767
|
+
textHighlighter(ctx) {
|
|
764
768
|
const params = this.visit(ctx.parameterList);
|
|
765
769
|
const value = params.value;
|
|
766
|
-
|
|
770
|
+
let highlight = void 0;
|
|
771
|
+
if (params.start !== void 0 && params.end !== void 0) {
|
|
772
|
+
highlight = [params.start, params.end];
|
|
773
|
+
}
|
|
767
774
|
return createNumberText(value, highlight);
|
|
768
775
|
}
|
|
769
776
|
inlineInput(ctx) {
|
|
@@ -1022,12 +1029,6 @@ function isDragOptionsJSON(widget) {
|
|
|
1022
1029
|
function isNumericKeypadJSON(widget) {
|
|
1023
1030
|
return widget.type === "numeric-keypad";
|
|
1024
1031
|
}
|
|
1025
|
-
function isWidgetPlaceholder(item) {
|
|
1026
|
-
return item.type === "widget-ref";
|
|
1027
|
-
}
|
|
1028
|
-
function isNumericInputJSON(widget) {
|
|
1029
|
-
return widget.type === "inline-input";
|
|
1030
|
-
}
|
|
1031
1032
|
class LayoutIdGenerator {
|
|
1032
1033
|
constructor() {
|
|
1033
1034
|
this.counter = 0;
|
|
@@ -5743,7 +5744,7 @@ const LayoutRenderer = ({
|
|
|
5743
5744
|
const [start, end] = item.highlight;
|
|
5744
5745
|
return /* @__PURE__ */ jsxs("span", { className: "number-text", children: [
|
|
5745
5746
|
item.value.slice(0, start),
|
|
5746
|
-
/* @__PURE__ */ jsx("
|
|
5747
|
+
/* @__PURE__ */ jsx("span", { className: "highlight", children: item.value.slice(start, end) }),
|
|
5747
5748
|
item.value.slice(end)
|
|
5748
5749
|
] });
|
|
5749
5750
|
}
|
|
@@ -6024,7 +6025,6 @@ export {
|
|
|
6024
6025
|
createExerciseDocument,
|
|
6025
6026
|
createExpressionValidation,
|
|
6026
6027
|
createFreeText,
|
|
6027
|
-
createInlineInput,
|
|
6028
6028
|
createLineBlock,
|
|
6029
6029
|
createNumberText,
|
|
6030
6030
|
createNumericInput,
|
|
@@ -6049,7 +6049,6 @@ export {
|
|
|
6049
6049
|
isLineBlock,
|
|
6050
6050
|
isLinebreak,
|
|
6051
6051
|
isNumberText,
|
|
6052
|
-
isNumericInputJSON,
|
|
6053
6052
|
isNumericKeypad,
|
|
6054
6053
|
isNumericKeypadJSON,
|
|
6055
6054
|
isOperatorItem,
|
|
@@ -6061,7 +6060,6 @@ export {
|
|
|
6061
6060
|
isToolNode,
|
|
6062
6061
|
isValidExpression,
|
|
6063
6062
|
isValidationNode,
|
|
6064
|
-
isWidgetPlaceholder,
|
|
6065
6063
|
isWidgetRef,
|
|
6066
6064
|
parse,
|
|
6067
6065
|
parseSafe,
|