@khanacademy/perseus-core 3.1.0 → 3.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.
- package/dist/data-schema.d.ts +57 -12
- package/dist/es/index.js +3251 -395
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +77 -1
- package/dist/index.js +3290 -394
- package/dist/index.js.map +1 -1
- package/dist/parse-perseus-json/error-tracking-parse-context.d.ts +9 -0
- package/dist/parse-perseus-json/exhaustive-test-tool/index.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/any.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/array.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/array.typetest.d.ts +1 -0
- package/dist/parse-perseus-json/general-purpose-parsers/boolean.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/constant.d.ts +4 -0
- package/dist/parse-perseus-json/general-purpose-parsers/convert.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/defaulted.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/discriminated-union.d.ts +21 -0
- package/dist/parse-perseus-json/general-purpose-parsers/discriminated-union.typetest.d.ts +1 -0
- package/dist/parse-perseus-json/general-purpose-parsers/enumeration.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/enumeration.typetest.d.ts +1 -0
- package/dist/parse-perseus-json/general-purpose-parsers/index.d.ts +17 -0
- package/dist/parse-perseus-json/general-purpose-parsers/is-object.d.ts +1 -0
- package/dist/parse-perseus-json/general-purpose-parsers/nullable.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/number.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/object.d.ts +6 -0
- package/dist/parse-perseus-json/general-purpose-parsers/optional.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/pair.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/pipe-parsers.d.ts +7 -0
- package/dist/parse-perseus-json/general-purpose-parsers/pipe-parsers.typetest.d.ts +1 -0
- package/dist/parse-perseus-json/general-purpose-parsers/record.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/string-to-number.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/string.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/test-helpers.d.ts +8 -0
- package/dist/parse-perseus-json/general-purpose-parsers/trio.d.ts +2 -0
- package/dist/parse-perseus-json/general-purpose-parsers/union.d.ts +7 -0
- package/dist/parse-perseus-json/general-purpose-parsers/union.typetest.d.ts +1 -0
- package/dist/parse-perseus-json/general-purpose-parsers/unknown.d.ts +2 -0
- package/dist/parse-perseus-json/index.d.ts +45 -0
- package/dist/parse-perseus-json/object-path.d.ts +2 -0
- package/dist/parse-perseus-json/parse-failure-detail.d.ts +2 -0
- package/dist/parse-perseus-json/parse.d.ts +3 -0
- package/dist/parse-perseus-json/parser-types.d.ts +30 -0
- package/dist/parse-perseus-json/perseus-parsers/categorizer-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/cs-program-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/definition-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/dropdown-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/explanation-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/expression-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/graded-group-set-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/graded-group-widget.d.ts +16 -0
- package/dist/parse-perseus-json/perseus-parsers/grapher-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/group-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/hint.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/iframe-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/image-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/images-map.d.ts +5 -0
- package/dist/parse-perseus-json/perseus-parsers/input-number-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/interaction-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/interactive-graph-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/label-image-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/matcher-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/matrix-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/measurer-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/molecule-renderer-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/number-line-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/numeric-input-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/orderer-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/passage-ref-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/passage-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/perseus-article.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/perseus-image-background.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/perseus-item.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/perseus-renderer.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/phet-simulation-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/plotter-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/python-program-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/radio-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/sorter-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/table-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/versioned-widget-options.d.ts +36 -0
- package/dist/parse-perseus-json/perseus-parsers/video-widget.d.ts +3 -0
- package/dist/parse-perseus-json/perseus-parsers/widget.d.ts +7 -0
- package/dist/parse-perseus-json/perseus-parsers/widgets-map.d.ts +3 -0
- package/dist/parse-perseus-json/result.d.ts +16 -0
- package/dist/types.d.ts +12 -0
- package/dist/utils/deep-clone.d.ts +3 -0
- package/dist/utils/equality.d.ts +9 -0
- package/dist/utils/get-decimal-separator.d.ts +5 -0
- package/dist/utils/get-matrix-size.d.ts +2 -0
- package/dist/utils/grapher-types.d.ts +58 -0
- package/dist/utils/grapher-util.d.ts +20 -0
- package/dist/utils/is-real-json-parse.d.ts +1 -0
- package/dist/utils/widget-id-utils.d.ts +38 -0
- package/dist/widgets/categorizer/categorizer-util.d.ts +17 -0
- package/dist/widgets/categorizer/index.d.ts +5 -0
- package/dist/widgets/cs-program/index.d.ts +5 -0
- package/dist/widgets/definition/index.d.ts +5 -0
- package/dist/widgets/dropdown/index.d.ts +5 -0
- package/dist/widgets/explanation/index.d.ts +5 -0
- package/dist/widgets/expression/expression-upgrade.d.ts +10 -0
- package/dist/widgets/expression/expression-util.d.ts +19 -0
- package/dist/widgets/expression/index.d.ts +4 -0
- package/dist/widgets/graded-group/index.d.ts +5 -0
- package/dist/widgets/graded-group-set/index.d.ts +5 -0
- package/dist/widgets/group/index.d.ts +5 -0
- package/dist/widgets/iframe/index.d.ts +5 -0
- package/dist/widgets/image/index.d.ts +5 -0
- package/dist/widgets/input-number/index.d.ts +5 -0
- package/dist/widgets/interaction/index.d.ts +5 -0
- package/dist/widgets/interactive-graph/index.d.ts +5 -0
- package/dist/widgets/label-image/index.d.ts +5 -0
- package/dist/widgets/logic-export.types.d.ts +10 -0
- package/dist/widgets/matcher/index.d.ts +5 -0
- package/dist/widgets/matrix/index.d.ts +5 -0
- package/dist/widgets/measurer/index.d.ts +4 -0
- package/dist/widgets/measurer/measurer-upgrade.d.ts +10 -0
- package/dist/widgets/number-line/index.d.ts +5 -0
- package/dist/widgets/numeric-input/index.d.ts +5 -0
- package/dist/widgets/orderer/index.d.ts +5 -0
- package/dist/widgets/orderer/orderer-util.d.ts +16 -0
- package/dist/widgets/passage/index.d.ts +5 -0
- package/dist/widgets/passage-ref/index.d.ts +4 -0
- package/dist/widgets/passage-ref/passage-ref-upgrade.d.ts +7 -0
- package/dist/widgets/passage-ref-target/index.d.ts +5 -0
- package/dist/widgets/phet-simulation/index.d.ts +5 -0
- package/dist/widgets/plotter/index.d.ts +5 -0
- package/dist/widgets/python-program/index.d.ts +5 -0
- package/dist/widgets/radio/index.d.ts +4 -0
- package/dist/widgets/radio/radio-upgrade.d.ts +10 -0
- package/dist/widgets/sorter/index.d.ts +5 -0
- package/dist/widgets/table/index.d.ts +5 -0
- package/dist/widgets/video/index.d.ts +5 -0
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -40,395 +40,103 @@ const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
const libVersion = "3.1.0";
|
|
46
|
-
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @typedef {Object} Errors utility for referencing the Perseus error taxonomy.
|
|
50
|
-
*/
|
|
51
|
-
const Errors = Object.freeze({
|
|
52
|
-
/**
|
|
53
|
-
* @property {ErrorKind} Unknown The kind of error is not known.
|
|
54
|
-
*/
|
|
55
|
-
Unknown: "Unknown",
|
|
56
|
-
/**
|
|
57
|
-
* @property {ErrorKind} Internal The error is internal to the executing code.
|
|
58
|
-
*/
|
|
59
|
-
Internal: "Internal",
|
|
60
|
-
/**
|
|
61
|
-
* @property {ErrorKind} InvalidInput There was a problem with the provided
|
|
62
|
-
* input, such as the wrong format or a null value.
|
|
63
|
-
*/
|
|
64
|
-
InvalidInput: "InvalidInput",
|
|
65
|
-
/**
|
|
66
|
-
* @property {ErrorKind} NotAllowed There was a problem due to the state of
|
|
67
|
-
* the system not matching the requested operation or input. For example,
|
|
68
|
-
* trying to create a username that is valid, but is already taken by
|
|
69
|
-
* another user. Use {@link InvalidInput} instead when the input isn't
|
|
70
|
-
* valid regardless of the state of the system. Use {@link NotFound} when
|
|
71
|
-
* the failure is due to not being able to find a resource.
|
|
72
|
-
*/
|
|
73
|
-
NotAllowed: "NotAllowed",
|
|
74
|
-
/**
|
|
75
|
-
* @property {ErrorKind} TransientService There was a problem when making a
|
|
76
|
-
* request to a service.
|
|
77
|
-
*/
|
|
78
|
-
TransientService: "TransientService",
|
|
79
|
-
/**
|
|
80
|
-
* @property {ErrorKind} Service There was a non-transient problem when
|
|
81
|
-
* making a request to service.
|
|
82
|
-
*/
|
|
83
|
-
Service: "Service"
|
|
84
|
-
});
|
|
43
|
+
// Current version.
|
|
44
|
+
var VERSION = '1.13.3';
|
|
85
45
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
46
|
+
// Establish the root object, `window` (`self`) in the browser, `global`
|
|
47
|
+
// on the server, or `this` in some virtual machines. We use `self`
|
|
48
|
+
// instead of `window` for `WebWorker` support.
|
|
49
|
+
var root = (typeof self == 'object' && self.self === self && self) ||
|
|
50
|
+
(typeof global == 'object' && global.global === global && global) ||
|
|
51
|
+
Function('return this')() ||
|
|
52
|
+
{};
|
|
89
53
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.kind = void 0;
|
|
94
|
-
this.metadata = void 0;
|
|
95
|
-
this.kind = kind;
|
|
96
|
-
this.metadata = options == null ? void 0 : options.metadata;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
54
|
+
// Save bytes in the minified (but not gzipped) version:
|
|
55
|
+
var ArrayProto = Array.prototype, ObjProto = Object.prototype;
|
|
56
|
+
var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;
|
|
99
57
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* that conform to the types in this file. Similarly, the top-level renderers
|
|
106
|
-
* in @khanacademy/perseus, consume objects that conform to these types.
|
|
107
|
-
*
|
|
108
|
-
* WARNING: This file should not import any types from elsewhere so that it is
|
|
109
|
-
* easy to reason about changes that alter the Perseus schema. This helps
|
|
110
|
-
* ensure that it is not changed accidentally when upgrading a dependant
|
|
111
|
-
* package or other part of Perseus code. Note that TypeScript does type
|
|
112
|
-
* checking via something called "structural typing". This means that as long
|
|
113
|
-
* as the shape of a type matches, the name it goes by doesn't matter. As a
|
|
114
|
-
* result, a `Coord` type that looks like this `[x: number, y: number]` is
|
|
115
|
-
* _identical_, in TypeScript's eyes, to this `Vector2` type `[x: number, y:
|
|
116
|
-
* number]`. Also, with tuples, the labels for each entry is ignored, so `[x:
|
|
117
|
-
* number, y: number]` is compatible with `[min: number, max: number]`. The
|
|
118
|
-
* labels are for humans, not TypeScript. :)
|
|
119
|
-
*
|
|
120
|
-
* If you make changes to types in this file, be very sure that:
|
|
121
|
-
*
|
|
122
|
-
* a) the changes are backwards compatible. If they are not, old data from
|
|
123
|
-
* previous versions of the "schema" could become unrenderable, or worse,
|
|
124
|
-
* introduce hard-to-diagnose bugs.
|
|
125
|
-
* b) the parsing code (`util/parse-perseus-json/`) is updated to handle
|
|
126
|
-
* the new format _as well as_ the old format.
|
|
127
|
-
*/
|
|
58
|
+
// Create quick reference variables for speed access to core prototypes.
|
|
59
|
+
var push = ArrayProto.push,
|
|
60
|
+
slice = ArrayProto.slice,
|
|
61
|
+
toString = ObjProto.toString,
|
|
62
|
+
hasOwnProperty = ObjProto.hasOwnProperty;
|
|
128
63
|
|
|
129
|
-
//
|
|
64
|
+
// Modern feature detection.
|
|
65
|
+
var supportsArrayBuffer = typeof ArrayBuffer !== 'undefined',
|
|
66
|
+
supportsDataView = typeof DataView !== 'undefined';
|
|
130
67
|
|
|
131
|
-
//
|
|
68
|
+
// All **ECMAScript 5+** native function implementations that we hope to use
|
|
69
|
+
// are declared here.
|
|
70
|
+
var nativeIsArray = Array.isArray,
|
|
71
|
+
nativeKeys = Object.keys,
|
|
72
|
+
nativeCreate = Object.create,
|
|
73
|
+
nativeIsView = supportsArrayBuffer && ArrayBuffer.isView;
|
|
132
74
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
* This interface is the basis for "registering" all Perseus widget types.
|
|
137
|
-
* There should be one key/value pair for each supported widget. If you create
|
|
138
|
-
* a new widget, an entry should be added to this interface. Note that this
|
|
139
|
-
* only registers the widget options type, you'll also need to register the
|
|
140
|
-
* widget so that it's available at runtime (@see
|
|
141
|
-
* {@link file://./widgets.ts#registerWidget}).
|
|
142
|
-
*
|
|
143
|
-
* Importantly, the key should be the name that is used in widget IDs. For most
|
|
144
|
-
* widgets that is the same as the widget option's `type` field. In cases where
|
|
145
|
-
* a widget has been deprecated and replaced with the deprecated-standin
|
|
146
|
-
* widget, it should be the original widget type!
|
|
147
|
-
*
|
|
148
|
-
* If you define the widget outside of this package, you can still add the new
|
|
149
|
-
* widget to this interface by writing the following in that package that
|
|
150
|
-
* contains the widget. TypeScript will merge that definition of the
|
|
151
|
-
* `PerseusWidgets` with the one defined below.
|
|
152
|
-
*
|
|
153
|
-
* ```typescript
|
|
154
|
-
* declare module "@khanacademy/perseus" {
|
|
155
|
-
* interface PerseusWidgetTypes {
|
|
156
|
-
* // A new widget
|
|
157
|
-
* "new-awesomeness": MyAwesomeNewWidget;
|
|
158
|
-
*
|
|
159
|
-
* // A deprecated widget
|
|
160
|
-
* "super-old-widget": DeprecatedStandinWidget;
|
|
161
|
-
* }
|
|
162
|
-
* }
|
|
163
|
-
*
|
|
164
|
-
* // The new widget's options definition
|
|
165
|
-
* type MyAwesomeNewWidget = WidgetOptions<'new-awesomeness', MyAwesomeNewWidgetOptions>;
|
|
166
|
-
*
|
|
167
|
-
* // The deprecated widget's options definition
|
|
168
|
-
* type SuperOldWidget = WidgetOptions<'super-old-widget', object>;
|
|
169
|
-
* ```
|
|
170
|
-
*
|
|
171
|
-
* This interface can be extended through the magic of TypeScript "Declaration
|
|
172
|
-
* merging". Specifically, we augment this module and extend this interface.
|
|
173
|
-
*
|
|
174
|
-
* @see {@link https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation}
|
|
175
|
-
*/
|
|
75
|
+
// Create references to these builtin functions because we override them.
|
|
76
|
+
var _isNaN = isNaN,
|
|
77
|
+
_isFinite = isFinite;
|
|
176
78
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
* needed. Today Widget IDs are made up of the widget type and an incrementing
|
|
182
|
-
* integer (eg. `interactive-graph 1` or `radio 3`). It is suggested to avoid
|
|
183
|
-
* reading/parsing the widget id to derive any information from it, except in
|
|
184
|
-
* the case of this map.
|
|
185
|
-
*
|
|
186
|
-
* @see {@link PerseusWidgetTypes} additional widgets can be added to this map type
|
|
187
|
-
* by augmenting the PerseusWidgetTypes with new widget types!
|
|
188
|
-
*/
|
|
79
|
+
// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
|
|
80
|
+
var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
|
|
81
|
+
var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
|
|
82
|
+
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
|
|
189
83
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
* `ServerItemRenderer` and the layout is pre-set.
|
|
193
|
-
*
|
|
194
|
-
* To render more complex Perseus items, see the `Item` type in the multi item
|
|
195
|
-
* area.
|
|
196
|
-
*/
|
|
84
|
+
// The largest integer that can be represented exactly.
|
|
85
|
+
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
|
|
197
86
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
87
|
+
// Some functions take a variable number of arguments, or a few expected
|
|
88
|
+
// arguments at the beginning and then a variable number of values to operate
|
|
89
|
+
// on. This helper accumulates all remaining arguments past the function’s
|
|
90
|
+
// argument length (or an explicit `startIndex`), into an array that becomes
|
|
91
|
+
// the last argument. Similar to ES6’s "rest parameter".
|
|
92
|
+
function restArguments(func, startIndex) {
|
|
93
|
+
startIndex = startIndex == null ? func.length - 1 : +startIndex;
|
|
94
|
+
return function() {
|
|
95
|
+
var length = Math.max(arguments.length - startIndex, 0),
|
|
96
|
+
rest = Array(length),
|
|
97
|
+
index = 0;
|
|
98
|
+
for (; index < length; index++) {
|
|
99
|
+
rest[index] = arguments[index + startIndex];
|
|
100
|
+
}
|
|
101
|
+
switch (startIndex) {
|
|
102
|
+
case 0: return func.call(this, rest);
|
|
103
|
+
case 1: return func.call(this, arguments[0], rest);
|
|
104
|
+
case 2: return func.call(this, arguments[0], arguments[1], rest);
|
|
105
|
+
}
|
|
106
|
+
var args = Array(startIndex + 1);
|
|
107
|
+
for (index = 0; index < startIndex; index++) {
|
|
108
|
+
args[index] = arguments[index];
|
|
109
|
+
}
|
|
110
|
+
args[startIndex] = rest;
|
|
111
|
+
return func.apply(this, args);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
202
114
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
// The user might benefit from a monthly payments calculator. Provided on Khan Academy when true
|
|
209
|
-
"financialCalculatorMonthlyPayment",
|
|
210
|
-
// The user might benefit from a total amount calculator. Provided on Khan Academy when true
|
|
211
|
-
"financialCalculatorTotalAmount",
|
|
212
|
-
// The user might benefit from a time to pay off calculator. Provided on Khan Academy when true
|
|
213
|
-
"financialCalculatorTimeToPayOff",
|
|
214
|
-
// The user might benefit from using a Periodic Table of Elements. Provided on Khan Academy when true
|
|
215
|
-
"periodicTable",
|
|
216
|
-
// The user might benefit from using a Periodic Table of Elements with key. Provided on Khan Academy when true
|
|
217
|
-
"periodicTableWithKey",
|
|
218
|
-
// The user might benefit from using a statistics T Table like https://www.statisticshowto.com/tables/t-distribution-table/
|
|
219
|
-
"tTable",
|
|
220
|
-
// The user might benefit from using a statistics Z Table like https://www.ztable.net/
|
|
221
|
-
"zTable"];
|
|
115
|
+
// Is a given variable an object?
|
|
116
|
+
function isObject$1(obj) {
|
|
117
|
+
var type = typeof obj;
|
|
118
|
+
return type === 'function' || (type === 'object' && !!obj);
|
|
119
|
+
}
|
|
222
120
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
121
|
+
// Is a given value equal to null?
|
|
122
|
+
function isNull(obj) {
|
|
123
|
+
return obj === null;
|
|
124
|
+
}
|
|
227
125
|
|
|
228
|
-
//
|
|
126
|
+
// Is a given variable undefined?
|
|
127
|
+
function isUndefined(obj) {
|
|
128
|
+
return obj === void 0;
|
|
129
|
+
}
|
|
229
130
|
|
|
230
|
-
//
|
|
131
|
+
// Is a given value a boolean?
|
|
132
|
+
function isBoolean(obj) {
|
|
133
|
+
return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
|
|
134
|
+
}
|
|
231
135
|
|
|
232
|
-
//
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
// prettier-ignore
|
|
237
|
-
|
|
238
|
-
// prettier-ignore
|
|
239
|
-
|
|
240
|
-
// prettier-ignore
|
|
241
|
-
|
|
242
|
-
// prettier-ignore
|
|
243
|
-
|
|
244
|
-
// prettier-ignore
|
|
245
|
-
|
|
246
|
-
// prettier-ignore
|
|
247
|
-
|
|
248
|
-
// prettier-ignore
|
|
249
|
-
|
|
250
|
-
// prettier-ignore
|
|
251
|
-
|
|
252
|
-
// prettier-ignore
|
|
253
|
-
|
|
254
|
-
// prettier-ignore
|
|
255
|
-
|
|
256
|
-
// prettier-ignore
|
|
257
|
-
|
|
258
|
-
// prettier-ignore
|
|
259
|
-
|
|
260
|
-
// prettier-ignore
|
|
261
|
-
|
|
262
|
-
// prettier-ignore
|
|
263
|
-
|
|
264
|
-
// prettier-ignore
|
|
265
|
-
|
|
266
|
-
// prettier-ignore
|
|
267
|
-
|
|
268
|
-
// prettier-ignore
|
|
269
|
-
|
|
270
|
-
// prettier-ignore
|
|
271
|
-
|
|
272
|
-
// prettier-ignore
|
|
273
|
-
|
|
274
|
-
// prettier-ignore
|
|
275
|
-
|
|
276
|
-
// prettier-ignore
|
|
277
|
-
|
|
278
|
-
// prettier-ignore
|
|
279
|
-
|
|
280
|
-
// prettier-ignore
|
|
281
|
-
|
|
282
|
-
// prettier-ignore
|
|
283
|
-
|
|
284
|
-
// prettier-ignore
|
|
285
|
-
|
|
286
|
-
// prettier-ignore
|
|
287
|
-
|
|
288
|
-
// prettier-ignore
|
|
289
|
-
|
|
290
|
-
// prettier-ignore
|
|
291
|
-
|
|
292
|
-
// prettier-ignore
|
|
293
|
-
|
|
294
|
-
// prettier-ignore
|
|
295
|
-
|
|
296
|
-
//prettier-ignore
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* A background image applied to various widgets.
|
|
300
|
-
*/
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* The type of markings to display on the graph.
|
|
304
|
-
* - axes: shows the axes without the gride lines
|
|
305
|
-
* - graph: shows the axes and the grid lines
|
|
306
|
-
* - grid: shows only the grid lines
|
|
307
|
-
* - none: shows no markings
|
|
308
|
-
*/
|
|
309
|
-
|
|
310
|
-
const PerseusExpressionAnswerFormConsidered = ["correct", "wrong", "ungraded"];
|
|
311
|
-
|
|
312
|
-
// 2D range: xMin, xMax, yMin, yMax
|
|
313
|
-
|
|
314
|
-
const lockedFigureColorNames = ["blue", "green", "grayH", "purple", "pink", "orange", "red"];
|
|
315
|
-
const lockedFigureColors = {
|
|
316
|
-
blue: "#3D7586",
|
|
317
|
-
green: "#447A53",
|
|
318
|
-
grayH: "#3B3D45",
|
|
319
|
-
purple: "#594094",
|
|
320
|
-
pink: "#B25071",
|
|
321
|
-
red: "#D92916",
|
|
322
|
-
orange: "#946700"
|
|
323
|
-
};
|
|
324
|
-
const lockedFigureFillStyles = {
|
|
325
|
-
none: 0,
|
|
326
|
-
white: 1,
|
|
327
|
-
translucent: 0.4,
|
|
328
|
-
solid: 1
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
// Not associated with a specific figure
|
|
332
|
-
|
|
333
|
-
const plotterPlotTypes = ["bar", "line", "pic", "histogram", "dotplot"];
|
|
334
|
-
|
|
335
|
-
// Current version.
|
|
336
|
-
var VERSION = '1.13.3';
|
|
337
|
-
|
|
338
|
-
// Establish the root object, `window` (`self`) in the browser, `global`
|
|
339
|
-
// on the server, or `this` in some virtual machines. We use `self`
|
|
340
|
-
// instead of `window` for `WebWorker` support.
|
|
341
|
-
var root = (typeof self == 'object' && self.self === self && self) ||
|
|
342
|
-
(typeof global == 'object' && global.global === global && global) ||
|
|
343
|
-
Function('return this')() ||
|
|
344
|
-
{};
|
|
345
|
-
|
|
346
|
-
// Save bytes in the minified (but not gzipped) version:
|
|
347
|
-
var ArrayProto = Array.prototype, ObjProto = Object.prototype;
|
|
348
|
-
var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;
|
|
349
|
-
|
|
350
|
-
// Create quick reference variables for speed access to core prototypes.
|
|
351
|
-
var push = ArrayProto.push,
|
|
352
|
-
slice = ArrayProto.slice,
|
|
353
|
-
toString = ObjProto.toString,
|
|
354
|
-
hasOwnProperty = ObjProto.hasOwnProperty;
|
|
355
|
-
|
|
356
|
-
// Modern feature detection.
|
|
357
|
-
var supportsArrayBuffer = typeof ArrayBuffer !== 'undefined',
|
|
358
|
-
supportsDataView = typeof DataView !== 'undefined';
|
|
359
|
-
|
|
360
|
-
// All **ECMAScript 5+** native function implementations that we hope to use
|
|
361
|
-
// are declared here.
|
|
362
|
-
var nativeIsArray = Array.isArray,
|
|
363
|
-
nativeKeys = Object.keys,
|
|
364
|
-
nativeCreate = Object.create,
|
|
365
|
-
nativeIsView = supportsArrayBuffer && ArrayBuffer.isView;
|
|
366
|
-
|
|
367
|
-
// Create references to these builtin functions because we override them.
|
|
368
|
-
var _isNaN = isNaN,
|
|
369
|
-
_isFinite = isFinite;
|
|
370
|
-
|
|
371
|
-
// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
|
|
372
|
-
var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
|
|
373
|
-
var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
|
|
374
|
-
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
|
|
375
|
-
|
|
376
|
-
// The largest integer that can be represented exactly.
|
|
377
|
-
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
|
|
378
|
-
|
|
379
|
-
// Some functions take a variable number of arguments, or a few expected
|
|
380
|
-
// arguments at the beginning and then a variable number of values to operate
|
|
381
|
-
// on. This helper accumulates all remaining arguments past the function’s
|
|
382
|
-
// argument length (or an explicit `startIndex`), into an array that becomes
|
|
383
|
-
// the last argument. Similar to ES6’s "rest parameter".
|
|
384
|
-
function restArguments(func, startIndex) {
|
|
385
|
-
startIndex = startIndex == null ? func.length - 1 : +startIndex;
|
|
386
|
-
return function() {
|
|
387
|
-
var length = Math.max(arguments.length - startIndex, 0),
|
|
388
|
-
rest = Array(length),
|
|
389
|
-
index = 0;
|
|
390
|
-
for (; index < length; index++) {
|
|
391
|
-
rest[index] = arguments[index + startIndex];
|
|
392
|
-
}
|
|
393
|
-
switch (startIndex) {
|
|
394
|
-
case 0: return func.call(this, rest);
|
|
395
|
-
case 1: return func.call(this, arguments[0], rest);
|
|
396
|
-
case 2: return func.call(this, arguments[0], arguments[1], rest);
|
|
397
|
-
}
|
|
398
|
-
var args = Array(startIndex + 1);
|
|
399
|
-
for (index = 0; index < startIndex; index++) {
|
|
400
|
-
args[index] = arguments[index];
|
|
401
|
-
}
|
|
402
|
-
args[startIndex] = rest;
|
|
403
|
-
return func.apply(this, args);
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// Is a given variable an object?
|
|
408
|
-
function isObject(obj) {
|
|
409
|
-
var type = typeof obj;
|
|
410
|
-
return type === 'function' || (type === 'object' && !!obj);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// Is a given value equal to null?
|
|
414
|
-
function isNull(obj) {
|
|
415
|
-
return obj === null;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// Is a given variable undefined?
|
|
419
|
-
function isUndefined(obj) {
|
|
420
|
-
return obj === void 0;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// Is a given value a boolean?
|
|
424
|
-
function isBoolean(obj) {
|
|
425
|
-
return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// Is a given value a DOM element?
|
|
429
|
-
function isElement(obj) {
|
|
430
|
-
return !!(obj && obj.nodeType === 1);
|
|
431
|
-
}
|
|
136
|
+
// Is a given value a DOM element?
|
|
137
|
+
function isElement(obj) {
|
|
138
|
+
return !!(obj && obj.nodeType === 1);
|
|
139
|
+
}
|
|
432
140
|
|
|
433
141
|
// Internal function for creating a `toString`-based type tester.
|
|
434
142
|
function tagTester(name) {
|
|
@@ -519,7 +227,7 @@ function isNaN$1(obj) {
|
|
|
519
227
|
}
|
|
520
228
|
|
|
521
229
|
// Predicate-generating function. Often useful outside of Underscore.
|
|
522
|
-
function constant(value) {
|
|
230
|
+
function constant$1(value) {
|
|
523
231
|
return function() {
|
|
524
232
|
return value;
|
|
525
233
|
};
|
|
@@ -556,7 +264,7 @@ function isTypedArray(obj) {
|
|
|
556
264
|
isBufferLike(obj) && typedArrayPattern.test(toString.call(obj));
|
|
557
265
|
}
|
|
558
266
|
|
|
559
|
-
var isTypedArray$1 = supportsArrayBuffer ? isTypedArray : constant(false);
|
|
267
|
+
var isTypedArray$1 = supportsArrayBuffer ? isTypedArray : constant$1(false);
|
|
560
268
|
|
|
561
269
|
// Internal helper to obtain the `length` property of an object.
|
|
562
270
|
var getLength = shallowProperty('length');
|
|
@@ -601,7 +309,7 @@ function collectNonEnumProps(obj, keys) {
|
|
|
601
309
|
// Retrieve the names of an object's own properties.
|
|
602
310
|
// Delegates to **ECMAScript 5**'s native `Object.keys`.
|
|
603
311
|
function keys(obj) {
|
|
604
|
-
if (!isObject(obj)) return [];
|
|
312
|
+
if (!isObject$1(obj)) return [];
|
|
605
313
|
if (nativeKeys) return nativeKeys(obj);
|
|
606
314
|
var keys = [];
|
|
607
315
|
for (var key in obj) if (has$1(obj, key)) keys.push(key);
|
|
@@ -799,7 +507,7 @@ function isEqual(a, b) {
|
|
|
799
507
|
|
|
800
508
|
// Retrieve all the enumerable property names of an object.
|
|
801
509
|
function allKeys(obj) {
|
|
802
|
-
if (!isObject(obj)) return [];
|
|
510
|
+
if (!isObject$1(obj)) return [];
|
|
803
511
|
var keys = [];
|
|
804
512
|
for (var key in obj) keys.push(key);
|
|
805
513
|
// Ahem, IE < 9.
|
|
@@ -928,7 +636,7 @@ function ctor() {
|
|
|
928
636
|
|
|
929
637
|
// An internal function for creating a new object that inherits from another.
|
|
930
638
|
function baseCreate(prototype) {
|
|
931
|
-
if (!isObject(prototype)) return {};
|
|
639
|
+
if (!isObject$1(prototype)) return {};
|
|
932
640
|
if (nativeCreate) return nativeCreate(prototype);
|
|
933
641
|
var Ctor = ctor();
|
|
934
642
|
Ctor.prototype = prototype;
|
|
@@ -948,7 +656,7 @@ function create(prototype, props) {
|
|
|
948
656
|
|
|
949
657
|
// Create a (shallow-cloned) duplicate of an object.
|
|
950
658
|
function clone(obj) {
|
|
951
|
-
if (!isObject(obj)) return obj;
|
|
659
|
+
if (!isObject$1(obj)) return obj;
|
|
952
660
|
return isArray(obj) ? obj.slice() : extend({}, obj);
|
|
953
661
|
}
|
|
954
662
|
|
|
@@ -1057,7 +765,7 @@ function optimizeCb(func, context, argCount) {
|
|
|
1057
765
|
function baseIteratee(value, context, argCount) {
|
|
1058
766
|
if (value == null) return identity;
|
|
1059
767
|
if (isFunction$1(value)) return optimizeCb(value, context, argCount);
|
|
1060
|
-
if (isObject(value) && !isArray(value)) return matcher(value);
|
|
768
|
+
if (isObject$1(value) && !isArray(value)) return matcher(value);
|
|
1061
769
|
return property(value);
|
|
1062
770
|
}
|
|
1063
771
|
|
|
@@ -1306,7 +1014,7 @@ function executeBound(sourceFunc, boundFunc, context, callingContext, args) {
|
|
|
1306
1014
|
if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
|
|
1307
1015
|
var self = baseCreate(sourceFunc.prototype);
|
|
1308
1016
|
var result = sourceFunc.apply(self, args);
|
|
1309
|
-
if (isObject(result)) return result;
|
|
1017
|
+
if (isObject$1(result)) return result;
|
|
1310
1018
|
return self;
|
|
1311
1019
|
}
|
|
1312
1020
|
|
|
@@ -2068,7 +1776,7 @@ function uniq(array, isSorted, iteratee, context) {
|
|
|
2068
1776
|
|
|
2069
1777
|
// Produce an array that contains the union: each distinct element from all of
|
|
2070
1778
|
// the passed-in arrays.
|
|
2071
|
-
var union = restArguments(function(arrays) {
|
|
1779
|
+
var union$1 = restArguments(function(arrays) {
|
|
2072
1780
|
return uniq(flatten$1(arrays, true, true));
|
|
2073
1781
|
});
|
|
2074
1782
|
|
|
@@ -2108,7 +1816,7 @@ var zip = restArguments(unzip);
|
|
|
2108
1816
|
// Converts lists into objects. Pass either a single array of `[key, value]`
|
|
2109
1817
|
// pairs, or two parallel arrays of the same length -- one of keys, and one of
|
|
2110
1818
|
// the corresponding values. Passing by pairs is the reverse of `_.pairs`.
|
|
2111
|
-
function object(list, values) {
|
|
1819
|
+
function object$1(list, values) {
|
|
2112
1820
|
var result = {};
|
|
2113
1821
|
for (var i = 0, length = getLength(list); i < length; i++) {
|
|
2114
1822
|
if (values) {
|
|
@@ -2203,7 +1911,7 @@ var allExports = /*#__PURE__*/Object.freeze({
|
|
|
2203
1911
|
__proto__: null,
|
|
2204
1912
|
VERSION: VERSION,
|
|
2205
1913
|
restArguments: restArguments,
|
|
2206
|
-
isObject: isObject,
|
|
1914
|
+
isObject: isObject$1,
|
|
2207
1915
|
isNull: isNull,
|
|
2208
1916
|
isUndefined: isUndefined,
|
|
2209
1917
|
isBoolean: isBoolean,
|
|
@@ -2247,7 +1955,7 @@ var allExports = /*#__PURE__*/Object.freeze({
|
|
|
2247
1955
|
has: has,
|
|
2248
1956
|
mapObject: mapObject$1,
|
|
2249
1957
|
identity: identity,
|
|
2250
|
-
constant: constant,
|
|
1958
|
+
constant: constant$1,
|
|
2251
1959
|
noop: noop,
|
|
2252
1960
|
toPath: toPath$1,
|
|
2253
1961
|
property: property,
|
|
@@ -2336,25 +2044,2627 @@ var allExports = /*#__PURE__*/Object.freeze({
|
|
|
2336
2044
|
without: without,
|
|
2337
2045
|
uniq: uniq,
|
|
2338
2046
|
unique: uniq,
|
|
2339
|
-
union: union,
|
|
2047
|
+
union: union$1,
|
|
2340
2048
|
intersection: intersection,
|
|
2341
2049
|
difference: difference,
|
|
2342
2050
|
unzip: unzip,
|
|
2343
2051
|
transpose: unzip,
|
|
2344
2052
|
zip: zip,
|
|
2345
|
-
object: object,
|
|
2053
|
+
object: object$1,
|
|
2346
2054
|
range: range,
|
|
2347
2055
|
chunk: chunk,
|
|
2348
2056
|
mixin: mixin,
|
|
2349
2057
|
'default': _$1
|
|
2350
2058
|
});
|
|
2351
2059
|
|
|
2352
|
-
// Default Export
|
|
2060
|
+
// Default Export
|
|
2061
|
+
|
|
2062
|
+
// Add all of the Underscore functions to the wrapper object.
|
|
2063
|
+
var _ = mixin(allExports);
|
|
2064
|
+
// Legacy Node.js API.
|
|
2065
|
+
_._ = _;
|
|
2066
|
+
|
|
2067
|
+
function getMatrixSize(matrix) {
|
|
2068
|
+
const matrixSize = [1, 1];
|
|
2069
|
+
|
|
2070
|
+
// We need to find the widest row and tallest column to get the correct
|
|
2071
|
+
// matrix size.
|
|
2072
|
+
_(matrix).each((matrixRow, row) => {
|
|
2073
|
+
let rowWidth = 0;
|
|
2074
|
+
_(matrixRow).each((matrixCol, col) => {
|
|
2075
|
+
if (matrixCol != null && matrixCol.toString().length) {
|
|
2076
|
+
rowWidth = col + 1;
|
|
2077
|
+
}
|
|
2078
|
+
});
|
|
2079
|
+
|
|
2080
|
+
// Matrix width:
|
|
2081
|
+
matrixSize[1] = Math.max(matrixSize[1], rowWidth);
|
|
2082
|
+
|
|
2083
|
+
// Matrix height:
|
|
2084
|
+
if (rowWidth > 0) {
|
|
2085
|
+
matrixSize[0] = Math.max(matrixSize[0], row + 1);
|
|
2086
|
+
}
|
|
2087
|
+
});
|
|
2088
|
+
return matrixSize;
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
/**
|
|
2092
|
+
* Get the character used for separating decimals.
|
|
2093
|
+
*/
|
|
2094
|
+
const getDecimalSeparator = locale => {
|
|
2095
|
+
var _match$;
|
|
2096
|
+
switch (locale) {
|
|
2097
|
+
// TODO(somewhatabstract): Remove this when Chrome supports the `ka`
|
|
2098
|
+
// locale properly.
|
|
2099
|
+
// https://github.com/formatjs/formatjs/issues/1526#issuecomment-559891201
|
|
2100
|
+
//
|
|
2101
|
+
// Supported locales in Chrome:
|
|
2102
|
+
// https://source.chromium.org/chromium/chromium/src/+/master:third_party/icu/scripts/chrome_ui_languages.list
|
|
2103
|
+
case "ka":
|
|
2104
|
+
return ",";
|
|
2105
|
+
default:
|
|
2106
|
+
const numberWithDecimalSeparator = 1.1;
|
|
2107
|
+
// TODO(FEI-3647): Update to use .formatToParts() once we no longer have to
|
|
2108
|
+
// support Safari 12.
|
|
2109
|
+
const match = new Intl.NumberFormat(locale).format(numberWithDecimalSeparator)
|
|
2110
|
+
// 0x661 is ARABIC-INDIC DIGIT ONE
|
|
2111
|
+
// 0x6F1 is EXTENDED ARABIC-INDIC DIGIT ONE
|
|
2112
|
+
.match(/[^\d\u0661\u06F1]/);
|
|
2113
|
+
return (_match$ = match == null ? void 0 : match[0]) != null ? _match$ : ".";
|
|
2114
|
+
}
|
|
2115
|
+
};
|
|
2116
|
+
|
|
2117
|
+
/**
|
|
2118
|
+
* APPROXIMATE equality on numbers and primitives.
|
|
2119
|
+
*/
|
|
2120
|
+
function approximateEqual(x, y) {
|
|
2121
|
+
if (typeof x === "number" && typeof y === "number") {
|
|
2122
|
+
return Math.abs(x - y) < 1e-9;
|
|
2123
|
+
}
|
|
2124
|
+
return x === y;
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
/**
|
|
2128
|
+
* Deep APPROXIMATE equality on primitives, numbers, arrays, and objects.
|
|
2129
|
+
* Recursive.
|
|
2130
|
+
*/
|
|
2131
|
+
function approximateDeepEqual(x, y) {
|
|
2132
|
+
if (Array.isArray(x) && Array.isArray(y)) {
|
|
2133
|
+
if (x.length !== y.length) {
|
|
2134
|
+
return false;
|
|
2135
|
+
}
|
|
2136
|
+
for (let i = 0; i < x.length; i++) {
|
|
2137
|
+
if (!approximateDeepEqual(x[i], y[i])) {
|
|
2138
|
+
return false;
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
return true;
|
|
2142
|
+
}
|
|
2143
|
+
if (Array.isArray(x) || Array.isArray(y)) {
|
|
2144
|
+
return false;
|
|
2145
|
+
}
|
|
2146
|
+
if (typeof x === "function" && typeof y === "function") {
|
|
2147
|
+
return approximateEqual(x, y);
|
|
2148
|
+
}
|
|
2149
|
+
if (typeof x === "function" || typeof y === "function") {
|
|
2150
|
+
return false;
|
|
2151
|
+
}
|
|
2152
|
+
if (typeof x === "object" && typeof y === "object" && !!x && !!y) {
|
|
2153
|
+
return x === y || _.all(x, function (v, k) {
|
|
2154
|
+
// @ts-expect-error - TS2536 - Type 'CollectionKey<T>' cannot be used to index type 'T'.
|
|
2155
|
+
return approximateDeepEqual(y[k], v);
|
|
2156
|
+
}) && _.all(y, function (v, k) {
|
|
2157
|
+
// @ts-expect-error - TS2536 - Type 'CollectionKey<T>' cannot be used to index type 'T'.
|
|
2158
|
+
return approximateDeepEqual(x[k], v);
|
|
2159
|
+
});
|
|
2160
|
+
}
|
|
2161
|
+
if (typeof x === "object" && !!x || typeof y === "object" && !!y) {
|
|
2162
|
+
return false;
|
|
2163
|
+
}
|
|
2164
|
+
return approximateEqual(x, y);
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
/**
|
|
2168
|
+
* Add a widget placeholder using the widget ID.
|
|
2169
|
+
* ex. addWidget("radio 1") => "[[☃ radio 1]]"
|
|
2170
|
+
*
|
|
2171
|
+
* @param {string} id
|
|
2172
|
+
* @returns {string}
|
|
2173
|
+
*/
|
|
2174
|
+
function addWidget(id) {
|
|
2175
|
+
return `[[☃ ${id}]]`;
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
/**
|
|
2179
|
+
* Regex for widget placeholders in a string.
|
|
2180
|
+
*
|
|
2181
|
+
* First capture group is the widget ID (ex. 'radio 1')
|
|
2182
|
+
* Second capture group is the widget type (ex. "radio)
|
|
2183
|
+
* exec return will look like: ['[[☃ radio 1]]', 'radio 1', 'radio']
|
|
2184
|
+
*/
|
|
2185
|
+
function getWidgetRegex() {
|
|
2186
|
+
return /\[\[☃ ([A-Za-z0-9- ]+)\]\]/g;
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
/**
|
|
2190
|
+
* Extract all widget IDs, which includes the widget type and instance number.
|
|
2191
|
+
* example output: ['radio 1', 'categorizer 1', 'categorizor 2']
|
|
2192
|
+
*
|
|
2193
|
+
* Content should contain Perseus widget placeholders,
|
|
2194
|
+
* which look like: '[[☃ radio 1]]'.
|
|
2195
|
+
*
|
|
2196
|
+
* @param {string} content
|
|
2197
|
+
* @returns {ReadonlyArray<string>} widgetIds
|
|
2198
|
+
*/
|
|
2199
|
+
function getWidgetIdsFromContent(content) {
|
|
2200
|
+
const widgets = [];
|
|
2201
|
+
const localWidgetRegex = getWidgetRegex();
|
|
2202
|
+
let match = localWidgetRegex.exec(content);
|
|
2203
|
+
while (match !== null) {
|
|
2204
|
+
widgets.push(match[1]);
|
|
2205
|
+
match = localWidgetRegex.exec(content);
|
|
2206
|
+
}
|
|
2207
|
+
return widgets;
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
/**
|
|
2211
|
+
* Get a list of widget IDs from content,
|
|
2212
|
+
* but only for specific widget types
|
|
2213
|
+
*
|
|
2214
|
+
* @param {string} type the type of widget (ie "radio")
|
|
2215
|
+
* @param {string} content the string to parse
|
|
2216
|
+
* @param {PerseusWidgetsMap} widgetMap widget ID to widget map
|
|
2217
|
+
* @returns {ReadonlyArray<string>} the widget type (ie "radio")
|
|
2218
|
+
*/
|
|
2219
|
+
function getWidgetIdsFromContentByType(type, content, widgetMap) {
|
|
2220
|
+
const rv = [];
|
|
2221
|
+
const widgetIdsInContent = getWidgetIdsFromContent(content);
|
|
2222
|
+
widgetIdsInContent.forEach(widgetId => {
|
|
2223
|
+
const widget = widgetMap[widgetId];
|
|
2224
|
+
if ((widget == null ? void 0 : widget.type) === type) {
|
|
2225
|
+
rv.push(widgetId);
|
|
2226
|
+
}
|
|
2227
|
+
});
|
|
2228
|
+
return rv;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
// TODO(benchristel): in the future, we may want to make deepClone work for
|
|
2232
|
+
// Record<string, Cloneable> as well. Currently, it only does arrays.
|
|
2233
|
+
|
|
2234
|
+
function deepClone(obj) {
|
|
2235
|
+
if (Array.isArray(obj)) {
|
|
2236
|
+
return obj.map(deepClone);
|
|
2237
|
+
}
|
|
2238
|
+
return obj;
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
const MOVABLES = {
|
|
2242
|
+
PLOT: "PLOT",
|
|
2243
|
+
PARABOLA: "PARABOLA",
|
|
2244
|
+
SINUSOID: "SINUSOID"
|
|
2245
|
+
};
|
|
2246
|
+
|
|
2247
|
+
// TODO(charlie): These really need to go into a utility file as they're being
|
|
2248
|
+
// used by both interactive-graph and now grapher.
|
|
2249
|
+
function canonicalSineCoefficients(coeffs) {
|
|
2250
|
+
// For a curve of the form f(x) = a * Sin(b * x - c) + d,
|
|
2251
|
+
// this function ensures that a, b > 0, and c is its
|
|
2252
|
+
// smallest possible positive value.
|
|
2253
|
+
let amplitude = coeffs[0];
|
|
2254
|
+
let angularFrequency = coeffs[1];
|
|
2255
|
+
let phase = coeffs[2];
|
|
2256
|
+
const verticalOffset = coeffs[3];
|
|
2257
|
+
|
|
2258
|
+
// Guarantee a > 0
|
|
2259
|
+
if (amplitude < 0) {
|
|
2260
|
+
amplitude *= -1;
|
|
2261
|
+
angularFrequency *= -1;
|
|
2262
|
+
phase *= -1;
|
|
2263
|
+
}
|
|
2264
|
+
const period = 2 * Math.PI;
|
|
2265
|
+
// Guarantee b > 0
|
|
2266
|
+
if (angularFrequency < 0) {
|
|
2267
|
+
angularFrequency *= -1;
|
|
2268
|
+
phase *= -1;
|
|
2269
|
+
phase += period / 2;
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
// Guarantee c is smallest possible positive value
|
|
2273
|
+
while (phase > 0) {
|
|
2274
|
+
phase -= period;
|
|
2275
|
+
}
|
|
2276
|
+
while (phase < 0) {
|
|
2277
|
+
phase += period;
|
|
2278
|
+
}
|
|
2279
|
+
return [amplitude, angularFrequency, phase, verticalOffset];
|
|
2280
|
+
}
|
|
2281
|
+
function canonicalTangentCoefficients(coeffs) {
|
|
2282
|
+
// For a curve of the form f(x) = a * Tan(b * x - c) + d,
|
|
2283
|
+
// this function ensures that a, b > 0, and c is its
|
|
2284
|
+
// smallest possible positive value.
|
|
2285
|
+
let amplitude = coeffs[0];
|
|
2286
|
+
let angularFrequency = coeffs[1];
|
|
2287
|
+
let phase = coeffs[2];
|
|
2288
|
+
const verticalOffset = coeffs[3];
|
|
2289
|
+
|
|
2290
|
+
// Guarantee a > 0
|
|
2291
|
+
if (amplitude < 0) {
|
|
2292
|
+
amplitude *= -1;
|
|
2293
|
+
angularFrequency *= -1;
|
|
2294
|
+
phase *= -1;
|
|
2295
|
+
}
|
|
2296
|
+
const period = Math.PI;
|
|
2297
|
+
// Guarantee b > 0
|
|
2298
|
+
if (angularFrequency < 0) {
|
|
2299
|
+
angularFrequency *= -1;
|
|
2300
|
+
phase *= -1;
|
|
2301
|
+
phase += period / 2;
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
// Guarantee c is smallest possible positive value
|
|
2305
|
+
while (phase > 0) {
|
|
2306
|
+
phase -= period;
|
|
2307
|
+
}
|
|
2308
|
+
while (phase < 0) {
|
|
2309
|
+
phase += period;
|
|
2310
|
+
}
|
|
2311
|
+
return [amplitude, angularFrequency, phase, verticalOffset];
|
|
2312
|
+
}
|
|
2313
|
+
const PlotDefaults = {
|
|
2314
|
+
areEqual: function (coeffs1, coeffs2) {
|
|
2315
|
+
return approximateDeepEqual(coeffs1, coeffs2);
|
|
2316
|
+
},
|
|
2317
|
+
movable: MOVABLES.PLOT,
|
|
2318
|
+
getPropsForCoeffs: function (coeffs) {
|
|
2319
|
+
return {
|
|
2320
|
+
// @ts-expect-error - TS2339 - Property 'getFunctionForCoeffs' does not exist on type '{ readonly areEqual: (coeffs1: any, coeffs2: any) => boolean; readonly Movable: any; readonly getPropsForCoeffs: (coeffs: any) => any; }'.
|
|
2321
|
+
fn: _.partial(this.getFunctionForCoeffs, coeffs)
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
};
|
|
2325
|
+
const Linear = _.extend({}, PlotDefaults, {
|
|
2326
|
+
url: "https://ka-perseus-graphie.s3.amazonaws.com/67aaf581e6d9ef9038c10558a1f70ac21c11c9f8.png",
|
|
2327
|
+
defaultCoords: [[0.25, 0.75], [0.75, 0.75]],
|
|
2328
|
+
getCoefficients: function (coords) {
|
|
2329
|
+
const p1 = coords[0];
|
|
2330
|
+
const p2 = coords[1];
|
|
2331
|
+
const denom = p2[0] - p1[0];
|
|
2332
|
+
const num = p2[1] - p1[1];
|
|
2333
|
+
if (denom === 0) {
|
|
2334
|
+
return;
|
|
2335
|
+
}
|
|
2336
|
+
const m = num / denom;
|
|
2337
|
+
const b = p2[1] - m * p2[0];
|
|
2338
|
+
return [m, b];
|
|
2339
|
+
},
|
|
2340
|
+
getFunctionForCoeffs: function (coeffs, x) {
|
|
2341
|
+
const m = coeffs[0];
|
|
2342
|
+
const b = coeffs[1];
|
|
2343
|
+
return m * x + b;
|
|
2344
|
+
},
|
|
2345
|
+
getEquationString: function (coords) {
|
|
2346
|
+
const coeffs = this.getCoefficients(coords);
|
|
2347
|
+
const m = coeffs[0];
|
|
2348
|
+
const b = coeffs[1];
|
|
2349
|
+
return "y = " + m.toFixed(3) + "x + " + b.toFixed(3);
|
|
2350
|
+
}
|
|
2351
|
+
});
|
|
2352
|
+
const Quadratic = _.extend({}, PlotDefaults, {
|
|
2353
|
+
url: "https://ka-perseus-graphie.s3.amazonaws.com/e23d36e6fc29ee37174e92c9daba2a66677128ab.png",
|
|
2354
|
+
defaultCoords: [[0.5, 0.5], [0.75, 0.75]],
|
|
2355
|
+
movable: MOVABLES.PARABOLA,
|
|
2356
|
+
getCoefficients: function (coords) {
|
|
2357
|
+
const p1 = coords[0];
|
|
2358
|
+
const p2 = coords[1];
|
|
2359
|
+
|
|
2360
|
+
// Parabola with vertex (h, k) has form: y = a * (h - k)^2 + k
|
|
2361
|
+
const h = p1[0];
|
|
2362
|
+
const k = p1[1];
|
|
2363
|
+
|
|
2364
|
+
// Use these to calculate familiar a, b, c
|
|
2365
|
+
const a = (p2[1] - k) / ((p2[0] - h) * (p2[0] - h));
|
|
2366
|
+
const b = -2 * h * a;
|
|
2367
|
+
const c = a * h * h + k;
|
|
2368
|
+
return [a, b, c];
|
|
2369
|
+
},
|
|
2370
|
+
getFunctionForCoeffs: function (coeffs, x) {
|
|
2371
|
+
const a = coeffs[0];
|
|
2372
|
+
const b = coeffs[1];
|
|
2373
|
+
const c = coeffs[2];
|
|
2374
|
+
return (a * x + b) * x + c;
|
|
2375
|
+
},
|
|
2376
|
+
getPropsForCoeffs: function (coeffs) {
|
|
2377
|
+
return {
|
|
2378
|
+
a: coeffs[0],
|
|
2379
|
+
b: coeffs[1],
|
|
2380
|
+
c: coeffs[2]
|
|
2381
|
+
};
|
|
2382
|
+
},
|
|
2383
|
+
getEquationString: function (coords) {
|
|
2384
|
+
const coeffs = this.getCoefficients(coords);
|
|
2385
|
+
const a = coeffs[0];
|
|
2386
|
+
const b = coeffs[1];
|
|
2387
|
+
const c = coeffs[2];
|
|
2388
|
+
return "y = " + a.toFixed(3) + "x^2 + " + b.toFixed(3) + "x + " + c.toFixed(3);
|
|
2389
|
+
}
|
|
2390
|
+
});
|
|
2391
|
+
const Sinusoid = _.extend({}, PlotDefaults, {
|
|
2392
|
+
url: "https://ka-perseus-graphie.s3.amazonaws.com/3d68e7718498475f53b206c2ab285626baf8857e.png",
|
|
2393
|
+
defaultCoords: [[0.5, 0.5], [0.6, 0.6]],
|
|
2394
|
+
movable: MOVABLES.SINUSOID,
|
|
2395
|
+
getCoefficients: function (coords) {
|
|
2396
|
+
const p1 = coords[0];
|
|
2397
|
+
const p2 = coords[1];
|
|
2398
|
+
const a = p2[1] - p1[1];
|
|
2399
|
+
const b = Math.PI / (2 * (p2[0] - p1[0]));
|
|
2400
|
+
const c = p1[0] * b;
|
|
2401
|
+
const d = p1[1];
|
|
2402
|
+
return [a, b, c, d];
|
|
2403
|
+
},
|
|
2404
|
+
getFunctionForCoeffs: function (coeffs, x) {
|
|
2405
|
+
const a = coeffs[0];
|
|
2406
|
+
const b = coeffs[1];
|
|
2407
|
+
const c = coeffs[2];
|
|
2408
|
+
const d = coeffs[3];
|
|
2409
|
+
return a * Math.sin(b * x - c) + d;
|
|
2410
|
+
},
|
|
2411
|
+
getPropsForCoeffs: function (coeffs) {
|
|
2412
|
+
return {
|
|
2413
|
+
a: coeffs[0],
|
|
2414
|
+
b: coeffs[1],
|
|
2415
|
+
c: coeffs[2],
|
|
2416
|
+
d: coeffs[3]
|
|
2417
|
+
};
|
|
2418
|
+
},
|
|
2419
|
+
getEquationString: function (coords) {
|
|
2420
|
+
const coeffs = this.getCoefficients(coords);
|
|
2421
|
+
const a = coeffs[0];
|
|
2422
|
+
const b = coeffs[1];
|
|
2423
|
+
const c = coeffs[2];
|
|
2424
|
+
const d = coeffs[3];
|
|
2425
|
+
return "y = " + a.toFixed(3) + " sin(" + b.toFixed(3) + "x - " + c.toFixed(3) + ") + " + d.toFixed(3);
|
|
2426
|
+
},
|
|
2427
|
+
areEqual: function (coeffs1, coeffs2) {
|
|
2428
|
+
return approximateDeepEqual(canonicalSineCoefficients(coeffs1), canonicalSineCoefficients(coeffs2));
|
|
2429
|
+
}
|
|
2430
|
+
});
|
|
2431
|
+
const Tangent = _.extend({}, PlotDefaults, {
|
|
2432
|
+
url: "https://ka-perseus-graphie.s3.amazonaws.com/7db80d23c35214f98659fe1cf0765811c1bbfbba.png",
|
|
2433
|
+
defaultCoords: [[0.5, 0.5], [0.75, 0.75]],
|
|
2434
|
+
getCoefficients: function (coords) {
|
|
2435
|
+
const p1 = coords[0];
|
|
2436
|
+
const p2 = coords[1];
|
|
2437
|
+
const a = p2[1] - p1[1];
|
|
2438
|
+
const b = Math.PI / (4 * (p2[0] - p1[0]));
|
|
2439
|
+
const c = p1[0] * b;
|
|
2440
|
+
const d = p1[1];
|
|
2441
|
+
return [a, b, c, d];
|
|
2442
|
+
},
|
|
2443
|
+
getFunctionForCoeffs: function (coeffs, x) {
|
|
2444
|
+
const a = coeffs[0];
|
|
2445
|
+
const b = coeffs[1];
|
|
2446
|
+
const c = coeffs[2];
|
|
2447
|
+
const d = coeffs[3];
|
|
2448
|
+
return a * Math.tan(b * x - c) + d;
|
|
2449
|
+
},
|
|
2450
|
+
getEquationString: function (coords) {
|
|
2451
|
+
const coeffs = this.getCoefficients(coords);
|
|
2452
|
+
const a = coeffs[0];
|
|
2453
|
+
const b = coeffs[1];
|
|
2454
|
+
const c = coeffs[2];
|
|
2455
|
+
const d = coeffs[3];
|
|
2456
|
+
return "y = " + a.toFixed(3) + " sin(" + b.toFixed(3) + "x - " + c.toFixed(3) + ") + " + d.toFixed(3);
|
|
2457
|
+
},
|
|
2458
|
+
areEqual: function (coeffs1, coeffs2) {
|
|
2459
|
+
return approximateDeepEqual(canonicalTangentCoefficients(coeffs1), canonicalTangentCoefficients(coeffs2));
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
const Exponential = _.extend({}, PlotDefaults, {
|
|
2463
|
+
url: "https://ka-perseus-graphie.s3.amazonaws.com/9cbfad55525e3ce755a31a631b074670a5dad611.png",
|
|
2464
|
+
defaultCoords: [[0.5, 0.55], [0.75, 0.75]],
|
|
2465
|
+
defaultAsymptote: [[0, 0.5], [1.0, 0.5]],
|
|
2466
|
+
/**
|
|
2467
|
+
* Add extra constraints for movement of the points or asymptote (below):
|
|
2468
|
+
* newCoord: [x, y]
|
|
2469
|
+
* The end position of the point or asymptote endpoint
|
|
2470
|
+
* oldCoord: [x, y]
|
|
2471
|
+
* The old position of the point or asymptote endpoint
|
|
2472
|
+
* coords:
|
|
2473
|
+
* An array of coordinates representing the proposed end configuration
|
|
2474
|
+
* of the plot coordinates.
|
|
2475
|
+
* asymptote:
|
|
2476
|
+
* An array of coordinates representing the proposed end configuration
|
|
2477
|
+
* of the asymptote.
|
|
2478
|
+
*
|
|
2479
|
+
* Return: either a coordinate (to be used as the resulting coordinate of
|
|
2480
|
+
* the move) or a boolean, where `true` uses newCoord as the resulting
|
|
2481
|
+
* coordinate, and `false` uses oldCoord as the resulting coordinate.
|
|
2482
|
+
*/
|
|
2483
|
+
extraCoordConstraint: function (newCoord, oldCoord, coords, asymptote, graph) {
|
|
2484
|
+
const y = asymptote[0][1];
|
|
2485
|
+
return _.all(coords, coord => coord[1] !== y);
|
|
2486
|
+
},
|
|
2487
|
+
extraAsymptoteConstraint: function (newCoord, oldCoord, coords, asymptote, graph) {
|
|
2488
|
+
const y = newCoord[1];
|
|
2489
|
+
const isValid = _.all(coords, coord => coord[1] > y) || _.all(coords, coord => coord[1] < y);
|
|
2490
|
+
if (isValid) {
|
|
2491
|
+
return [oldCoord[0], y];
|
|
2492
|
+
}
|
|
2493
|
+
// Snap the asymptote as close as possible, i.e., if the user moves
|
|
2494
|
+
// the mouse really quickly into an invalid region
|
|
2495
|
+
const oldY = oldCoord[1];
|
|
2496
|
+
const wasBelow = _.all(coords, coord => coord[1] > oldY);
|
|
2497
|
+
if (wasBelow) {
|
|
2498
|
+
const bottomMost = _.min(_.map(coords, coord => coord[1]));
|
|
2499
|
+
return [oldCoord[0], bottomMost - graph.snapStep[1]];
|
|
2500
|
+
}
|
|
2501
|
+
const topMost = _.max(_.map(coords, coord => coord[1]));
|
|
2502
|
+
return [oldCoord[0], topMost + graph.snapStep[1]];
|
|
2503
|
+
},
|
|
2504
|
+
allowReflectOverAsymptote: true,
|
|
2505
|
+
getCoefficients: function (coords, asymptote) {
|
|
2506
|
+
const p1 = coords[0];
|
|
2507
|
+
const p2 = coords[1];
|
|
2508
|
+
const c = asymptote[0][1];
|
|
2509
|
+
const b = Math.log((p1[1] - c) / (p2[1] - c)) / (p1[0] - p2[0]);
|
|
2510
|
+
const a = (p1[1] - c) / Math.exp(b * p1[0]);
|
|
2511
|
+
return [a, b, c];
|
|
2512
|
+
},
|
|
2513
|
+
getFunctionForCoeffs: function (coeffs, x) {
|
|
2514
|
+
const a = coeffs[0];
|
|
2515
|
+
const b = coeffs[1];
|
|
2516
|
+
const c = coeffs[2];
|
|
2517
|
+
return a * Math.exp(b * x) + c;
|
|
2518
|
+
},
|
|
2519
|
+
getEquationString: function (coords, asymptote) {
|
|
2520
|
+
if (!asymptote) {
|
|
2521
|
+
return null;
|
|
2522
|
+
}
|
|
2523
|
+
const coeffs = this.getCoefficients(coords, asymptote);
|
|
2524
|
+
const a = coeffs[0];
|
|
2525
|
+
const b = coeffs[1];
|
|
2526
|
+
const c = coeffs[2];
|
|
2527
|
+
return "y = " + a.toFixed(3) + "e^(" + b.toFixed(3) + "x) + " + c.toFixed(3);
|
|
2528
|
+
}
|
|
2529
|
+
});
|
|
2530
|
+
const Logarithm = _.extend({}, PlotDefaults, {
|
|
2531
|
+
url: "https://ka-perseus-graphie.s3.amazonaws.com/f6491e99d34af34d924bfe0231728ad912068dc3.png",
|
|
2532
|
+
defaultCoords: [[0.55, 0.5], [0.75, 0.75]],
|
|
2533
|
+
defaultAsymptote: [[0.5, 0], [0.5, 1.0]],
|
|
2534
|
+
extraCoordConstraint: function (newCoord, oldCoord, coords, asymptote, graph) {
|
|
2535
|
+
const x = asymptote[0][0];
|
|
2536
|
+
return _.all(coords, coord => coord[0] !== x) && coords[0][1] !== coords[1][1];
|
|
2537
|
+
},
|
|
2538
|
+
extraAsymptoteConstraint: function (newCoord, oldCoord, coords, asymptote, graph) {
|
|
2539
|
+
const x = newCoord[0];
|
|
2540
|
+
const isValid = _.all(coords, coord => coord[0] > x) || _.all(coords, coord => coord[0] < x);
|
|
2541
|
+
if (isValid) {
|
|
2542
|
+
return [x, oldCoord[1]];
|
|
2543
|
+
}
|
|
2544
|
+
// Snap the asymptote as close as possible, i.e., if the user moves
|
|
2545
|
+
// the mouse really quickly into an invalid region
|
|
2546
|
+
const oldX = oldCoord[0];
|
|
2547
|
+
const wasLeft = _.all(coords, coord => coord[0] > oldX);
|
|
2548
|
+
if (wasLeft) {
|
|
2549
|
+
const leftMost = _.min(_.map(coords, coord => coord[0]));
|
|
2550
|
+
return [leftMost - graph.snapStep[0], oldCoord[1]];
|
|
2551
|
+
}
|
|
2552
|
+
const rightMost = _.max(_.map(coords, coord => coord[0]));
|
|
2553
|
+
return [rightMost + graph.snapStep[0], oldCoord[1]];
|
|
2554
|
+
},
|
|
2555
|
+
allowReflectOverAsymptote: true,
|
|
2556
|
+
getCoefficients: function (coords, asymptote) {
|
|
2557
|
+
// It's easiest to calculate the logarithm's coefficients by thinking
|
|
2558
|
+
// about it as the inverse of the exponential, so we flip x and y and
|
|
2559
|
+
// perform some algebra on the coefficients. This also unifies the
|
|
2560
|
+
// logic between the two 'models'.
|
|
2561
|
+
const flip = coord => [coord[1], coord[0]];
|
|
2562
|
+
const inverseCoeffs = Exponential.getCoefficients(_.map(coords, flip), _.map(asymptote, flip));
|
|
2563
|
+
if (inverseCoeffs) {
|
|
2564
|
+
const c = -inverseCoeffs[2] / inverseCoeffs[0];
|
|
2565
|
+
const b = 1 / inverseCoeffs[0];
|
|
2566
|
+
const a = 1 / inverseCoeffs[1];
|
|
2567
|
+
return [a, b, c];
|
|
2568
|
+
}
|
|
2569
|
+
},
|
|
2570
|
+
getFunctionForCoeffs: function (coeffs, x, asymptote) {
|
|
2571
|
+
const a = coeffs[0];
|
|
2572
|
+
const b = coeffs[1];
|
|
2573
|
+
const c = coeffs[2];
|
|
2574
|
+
return a * Math.log(b * x + c);
|
|
2575
|
+
},
|
|
2576
|
+
getEquationString: function (coords, asymptote) {
|
|
2577
|
+
if (!asymptote) {
|
|
2578
|
+
return null;
|
|
2579
|
+
}
|
|
2580
|
+
const coeffs = this.getCoefficients(coords, asymptote);
|
|
2581
|
+
const a = coeffs[0];
|
|
2582
|
+
const b = coeffs[1];
|
|
2583
|
+
const c = coeffs[2];
|
|
2584
|
+
return "y = ln(" + a.toFixed(3) + "x + " + b.toFixed(3) + ") + " + c.toFixed(3);
|
|
2585
|
+
}
|
|
2586
|
+
});
|
|
2587
|
+
const AbsoluteValue = _.extend({}, PlotDefaults, {
|
|
2588
|
+
url: "https://ka-perseus-graphie.s3.amazonaws.com/8256a630175a0cb1d11de223d6de0266daf98721.png",
|
|
2589
|
+
defaultCoords: [[0.5, 0.5], [0.75, 0.75]],
|
|
2590
|
+
getCoefficients: function (coords) {
|
|
2591
|
+
const p1 = coords[0];
|
|
2592
|
+
const p2 = coords[1];
|
|
2593
|
+
const denom = p2[0] - p1[0];
|
|
2594
|
+
const num = p2[1] - p1[1];
|
|
2595
|
+
if (denom === 0) {
|
|
2596
|
+
return;
|
|
2597
|
+
}
|
|
2598
|
+
let m = Math.abs(num / denom);
|
|
2599
|
+
if (p2[1] < p1[1]) {
|
|
2600
|
+
m *= -1;
|
|
2601
|
+
}
|
|
2602
|
+
const horizontalOffset = p1[0];
|
|
2603
|
+
const verticalOffset = p1[1];
|
|
2604
|
+
return [m, horizontalOffset, verticalOffset];
|
|
2605
|
+
},
|
|
2606
|
+
getFunctionForCoeffs: function (coeffs, x) {
|
|
2607
|
+
const m = coeffs[0];
|
|
2608
|
+
const horizontalOffset = coeffs[1];
|
|
2609
|
+
const verticalOffset = coeffs[2];
|
|
2610
|
+
return m * Math.abs(x - horizontalOffset) + verticalOffset;
|
|
2611
|
+
},
|
|
2612
|
+
getEquationString: function (coords) {
|
|
2613
|
+
const coeffs = this.getCoefficients(coords);
|
|
2614
|
+
const m = coeffs[0];
|
|
2615
|
+
const horizontalOffset = coeffs[1];
|
|
2616
|
+
const verticalOffset = coeffs[2];
|
|
2617
|
+
return "y = " + m.toFixed(3) + "| x - " + horizontalOffset.toFixed(3) + "| + " + verticalOffset.toFixed(3);
|
|
2618
|
+
}
|
|
2619
|
+
});
|
|
2620
|
+
|
|
2621
|
+
/* Utility functions for dealing with graphing interfaces. */
|
|
2622
|
+
const functionTypeMapping = {
|
|
2623
|
+
linear: Linear,
|
|
2624
|
+
quadratic: Quadratic,
|
|
2625
|
+
sinusoid: Sinusoid,
|
|
2626
|
+
tangent: Tangent,
|
|
2627
|
+
exponential: Exponential,
|
|
2628
|
+
logarithm: Logarithm,
|
|
2629
|
+
absolute_value: AbsoluteValue
|
|
2630
|
+
};
|
|
2631
|
+
const allTypes = _.keys(functionTypeMapping);
|
|
2632
|
+
function functionForType(type) {
|
|
2633
|
+
// @ts-expect-error: TypeScript doesn't know how to use deal with generics
|
|
2634
|
+
// and conditional types in this way.
|
|
2635
|
+
return functionTypeMapping[type];
|
|
2636
|
+
}
|
|
2637
|
+
|
|
2638
|
+
var grapherUtil = /*#__PURE__*/Object.freeze({
|
|
2639
|
+
__proto__: null,
|
|
2640
|
+
MOVABLES: MOVABLES,
|
|
2641
|
+
allTypes: allTypes,
|
|
2642
|
+
functionForType: functionForType
|
|
2643
|
+
});
|
|
2644
|
+
|
|
2645
|
+
function isRealJSONParse(jsonParse) {
|
|
2646
|
+
const randomPhrase = buildRandomPhrase();
|
|
2647
|
+
const randomHintPhrase = buildRandomPhrase();
|
|
2648
|
+
const randomString = buildRandomString();
|
|
2649
|
+
const testingObject = JSON.stringify({
|
|
2650
|
+
answerArea: {
|
|
2651
|
+
calculator: false,
|
|
2652
|
+
chi2Table: false,
|
|
2653
|
+
financialCalculatorMonthlyPayment: false,
|
|
2654
|
+
financialCalculatorTimeToPayOff: false,
|
|
2655
|
+
financialCalculatorTotalAmount: false,
|
|
2656
|
+
periodicTable: false,
|
|
2657
|
+
periodicTableWithKey: false,
|
|
2658
|
+
tTable: false,
|
|
2659
|
+
zTable: false
|
|
2660
|
+
},
|
|
2661
|
+
hints: [randomHintPhrase, `=${Math.floor(Math.random() * 50) + 1}`],
|
|
2662
|
+
itemDataVersion: {
|
|
2663
|
+
major: 0,
|
|
2664
|
+
minor: 1
|
|
2665
|
+
},
|
|
2666
|
+
question: {
|
|
2667
|
+
content: `${randomPhrase}`,
|
|
2668
|
+
images: {},
|
|
2669
|
+
widgets: {
|
|
2670
|
+
expression1: {
|
|
2671
|
+
alignment: "default",
|
|
2672
|
+
graded: false,
|
|
2673
|
+
options: {
|
|
2674
|
+
answerForms: [{
|
|
2675
|
+
considered: "wrong",
|
|
2676
|
+
form: false,
|
|
2677
|
+
key: 0,
|
|
2678
|
+
simplify: false,
|
|
2679
|
+
value: `${randomString}`
|
|
2680
|
+
}],
|
|
2681
|
+
ariaLabel: "Answer",
|
|
2682
|
+
buttonSets: ["basic"],
|
|
2683
|
+
functions: ["f", "g", "h"],
|
|
2684
|
+
static: true,
|
|
2685
|
+
times: false,
|
|
2686
|
+
visibleLabel: "Answer"
|
|
2687
|
+
},
|
|
2688
|
+
static: true,
|
|
2689
|
+
type: "expression",
|
|
2690
|
+
version: {
|
|
2691
|
+
major: 1,
|
|
2692
|
+
minor: 0
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
});
|
|
2698
|
+
const testJSON = buildTestData(testingObject.replace(/"/g, '\\"'));
|
|
2699
|
+
const parsedTestJSON = jsonParse(testJSON);
|
|
2700
|
+
const parsedTestItemData = parsedTestJSON.data.assessmentItem.item.itemData;
|
|
2701
|
+
return approximateDeepEqual(parsedTestItemData, testingObject);
|
|
2702
|
+
}
|
|
2703
|
+
function buildRandomString(capitalize = false) {
|
|
2704
|
+
let randomString = "";
|
|
2705
|
+
const randomLength = Math.floor(Math.random() * 8) + 3;
|
|
2706
|
+
for (let i = 0; i < randomLength; i++) {
|
|
2707
|
+
const randomLetter = String.fromCharCode(97 + Math.floor(Math.random() * 26));
|
|
2708
|
+
randomString += capitalize && i === 0 ? randomLetter.toUpperCase() : randomLetter;
|
|
2709
|
+
}
|
|
2710
|
+
return randomString;
|
|
2711
|
+
}
|
|
2712
|
+
function buildRandomPhrase() {
|
|
2713
|
+
const phrases = [];
|
|
2714
|
+
const randomLength = Math.floor(Math.random() * 10) + 5;
|
|
2715
|
+
for (let i = 0; i < randomLength; i++) {
|
|
2716
|
+
phrases.push(buildRandomString(i === 0));
|
|
2717
|
+
}
|
|
2718
|
+
const modifierStart = ["**", "$"];
|
|
2719
|
+
const modifierEnd = ["**", "$"];
|
|
2720
|
+
const modifierIndex = Math.floor(Math.random() * modifierStart.length);
|
|
2721
|
+
return `${modifierStart[modifierIndex]}${phrases.join(" ")}${modifierEnd[modifierIndex]}`;
|
|
2722
|
+
}
|
|
2723
|
+
function buildTestData(testObject) {
|
|
2724
|
+
return `{"data":{"assessmentItem":{"__typename":"AssessmentItemOrError","error":null,"item":{"__typename":"AssessmentItem","id":"x890b3c70f3e8f4a6","itemData":"${testObject}","problemType":"Type 1","sha":"c7284a3ad65214b4e62bccce236d92f7f5d35941"}}}}`;
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
process.env.NODE_ENV === 'production';
|
|
2728
|
+
|
|
2729
|
+
function success(value) {
|
|
2730
|
+
return {
|
|
2731
|
+
type: "success",
|
|
2732
|
+
value
|
|
2733
|
+
};
|
|
2734
|
+
}
|
|
2735
|
+
function failure(detail) {
|
|
2736
|
+
return {
|
|
2737
|
+
type: "failure",
|
|
2738
|
+
detail
|
|
2739
|
+
};
|
|
2740
|
+
}
|
|
2741
|
+
function isFailure(result) {
|
|
2742
|
+
return result.type === "failure";
|
|
2743
|
+
}
|
|
2744
|
+
function isSuccess(result) {
|
|
2745
|
+
return result.type === "success";
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
// Result's `all` function is similar to Promise.all: given an array of
|
|
2749
|
+
// results, it returns success if all succeeded, and failure if any failed.
|
|
2750
|
+
function all(results, combineFailureDetails = a => a) {
|
|
2751
|
+
const values = [];
|
|
2752
|
+
const failureDetails = [];
|
|
2753
|
+
for (const result of results) {
|
|
2754
|
+
if (result.type === "success") {
|
|
2755
|
+
values.push(result.value);
|
|
2756
|
+
} else {
|
|
2757
|
+
failureDetails.push(result.detail);
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
if (failureDetails.length > 0) {
|
|
2761
|
+
return failure(failureDetails.reduce(combineFailureDetails));
|
|
2762
|
+
}
|
|
2763
|
+
return success(values);
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
class ErrorTrackingParseContext {
|
|
2767
|
+
constructor(path) {
|
|
2768
|
+
this.path = path;
|
|
2769
|
+
}
|
|
2770
|
+
failure(expected, badValue) {
|
|
2771
|
+
return failure([{
|
|
2772
|
+
expected: wrapInArray(expected),
|
|
2773
|
+
badValue,
|
|
2774
|
+
path: this.path
|
|
2775
|
+
}]);
|
|
2776
|
+
}
|
|
2777
|
+
forSubtree(key) {
|
|
2778
|
+
return new ErrorTrackingParseContext([...this.path, key]);
|
|
2779
|
+
}
|
|
2780
|
+
success(value) {
|
|
2781
|
+
return success(value);
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
function wrapInArray(a) {
|
|
2785
|
+
return Array.isArray(a) ? a : [a];
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
function formatPath(path) {
|
|
2789
|
+
return "(root)" + path.map(formatPathSegment).join("");
|
|
2790
|
+
}
|
|
2791
|
+
function formatPathSegment(segment) {
|
|
2792
|
+
if (typeof segment === "string") {
|
|
2793
|
+
return validIdentifier.test(segment) ? "." + segment : `[${JSON.stringify(segment)}]`;
|
|
2794
|
+
}
|
|
2795
|
+
return `[${segment.toString()}]`;
|
|
2796
|
+
}
|
|
2797
|
+
const validIdentifier = /^[A-Za-z$_][A-Za-z$_0-9]*$/;
|
|
2798
|
+
|
|
2799
|
+
function message(failure) {
|
|
2800
|
+
const expected = conjoin(failure.expected);
|
|
2801
|
+
const path = formatPath(failure.path);
|
|
2802
|
+
const badValue = JSON.stringify(failure.badValue);
|
|
2803
|
+
return `At ${path} -- expected ${expected}, but got ${badValue}`;
|
|
2804
|
+
}
|
|
2805
|
+
function conjoin(items) {
|
|
2806
|
+
switch (items.length) {
|
|
2807
|
+
// TODO(benchristel): handle 0 if this is reused elsewhere.
|
|
2808
|
+
case 1:
|
|
2809
|
+
return items[0];
|
|
2810
|
+
case 2:
|
|
2811
|
+
return items.join(" or ");
|
|
2812
|
+
default:
|
|
2813
|
+
{
|
|
2814
|
+
const allButLast = items.slice(0, items.length - 1);
|
|
2815
|
+
const last = items[items.length - 1];
|
|
2816
|
+
return allButLast.join(", ") + ", or " + last;
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2821
|
+
function parse(value, parser) {
|
|
2822
|
+
const result = parser(value, new ErrorTrackingParseContext([]));
|
|
2823
|
+
if (isFailure(result)) {
|
|
2824
|
+
return failure(result.detail.map(message).join("; "));
|
|
2825
|
+
}
|
|
2826
|
+
return result;
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2829
|
+
const any = (rawValue, ctx) => ctx.success(rawValue);
|
|
2830
|
+
|
|
2831
|
+
function array(elementParser) {
|
|
2832
|
+
return (rawValue, ctx) => {
|
|
2833
|
+
if (!Array.isArray(rawValue)) {
|
|
2834
|
+
return ctx.failure("array", rawValue);
|
|
2835
|
+
}
|
|
2836
|
+
const elementResults = rawValue.map((elem, i) => elementParser(elem, ctx.forSubtree(i)));
|
|
2837
|
+
return all(elementResults, concat);
|
|
2838
|
+
};
|
|
2839
|
+
}
|
|
2840
|
+
function concat(a, b) {
|
|
2841
|
+
return [...a, ...b];
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2844
|
+
function boolean(rawValue, ctx) {
|
|
2845
|
+
if (typeof rawValue === "boolean") {
|
|
2846
|
+
return ctx.success(rawValue);
|
|
2847
|
+
}
|
|
2848
|
+
return ctx.failure("boolean", rawValue);
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
function constant(acceptedValue) {
|
|
2852
|
+
return (rawValue, ctx) => {
|
|
2853
|
+
if (rawValue !== acceptedValue) {
|
|
2854
|
+
return ctx.failure(String(JSON.stringify(acceptedValue)), rawValue);
|
|
2855
|
+
}
|
|
2856
|
+
return ctx.success(acceptedValue);
|
|
2857
|
+
};
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
function enumeration(...acceptedValues) {
|
|
2861
|
+
return (rawValue, ctx) => {
|
|
2862
|
+
if (typeof rawValue === "string") {
|
|
2863
|
+
const index = acceptedValues.indexOf(rawValue);
|
|
2864
|
+
if (index > -1) {
|
|
2865
|
+
return ctx.success(acceptedValues[index]);
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
const expected = acceptedValues.map(v => JSON.stringify(v));
|
|
2869
|
+
return ctx.failure(expected, rawValue);
|
|
2870
|
+
};
|
|
2871
|
+
}
|
|
2872
|
+
|
|
2873
|
+
function isObject(x) {
|
|
2874
|
+
return x != null && Object.getPrototypeOf(x) === Object.prototype;
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
function nullable(parseValue) {
|
|
2878
|
+
return (rawValue, ctx) => {
|
|
2879
|
+
if (rawValue === null) {
|
|
2880
|
+
return ctx.success(rawValue);
|
|
2881
|
+
}
|
|
2882
|
+
return parseValue(rawValue, ctx);
|
|
2883
|
+
};
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
const number = (rawValue, ctx) => {
|
|
2887
|
+
if (typeof rawValue === "number") {
|
|
2888
|
+
return ctx.success(rawValue);
|
|
2889
|
+
}
|
|
2890
|
+
return ctx.failure("number", rawValue);
|
|
2891
|
+
};
|
|
2892
|
+
|
|
2893
|
+
function _extends() {
|
|
2894
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
2895
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
2896
|
+
var t = arguments[e];
|
|
2897
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
2898
|
+
}
|
|
2899
|
+
return n;
|
|
2900
|
+
}, _extends.apply(null, arguments);
|
|
2901
|
+
}
|
|
2902
|
+
|
|
2903
|
+
function object(schema) {
|
|
2904
|
+
return (rawValue, ctx) => {
|
|
2905
|
+
if (!isObject(rawValue)) {
|
|
2906
|
+
return ctx.failure("object", rawValue);
|
|
2907
|
+
}
|
|
2908
|
+
const ret = _extends({}, rawValue);
|
|
2909
|
+
const mismatches = [];
|
|
2910
|
+
for (const [prop, propParser] of Object.entries(schema)) {
|
|
2911
|
+
const result = propParser(rawValue[prop], ctx.forSubtree(prop));
|
|
2912
|
+
if (isSuccess(result)) {
|
|
2913
|
+
if (result.value !== undefined || prop in rawValue) {
|
|
2914
|
+
ret[prop] = result.value;
|
|
2915
|
+
}
|
|
2916
|
+
} else {
|
|
2917
|
+
mismatches.push(...result.detail);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
if (mismatches.length > 0) {
|
|
2921
|
+
return failure(mismatches);
|
|
2922
|
+
}
|
|
2923
|
+
return ctx.success(ret);
|
|
2924
|
+
};
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
function optional(parseValue) {
|
|
2928
|
+
return (rawValue, ctx) => {
|
|
2929
|
+
if (rawValue === undefined) {
|
|
2930
|
+
return ctx.success(rawValue);
|
|
2931
|
+
}
|
|
2932
|
+
return parseValue(rawValue, ctx);
|
|
2933
|
+
};
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2936
|
+
function pair(parseA, parseB) {
|
|
2937
|
+
return (rawValue, ctx) => {
|
|
2938
|
+
if (!Array.isArray(rawValue)) {
|
|
2939
|
+
return ctx.failure("array", rawValue);
|
|
2940
|
+
}
|
|
2941
|
+
if (rawValue.length !== 2) {
|
|
2942
|
+
return ctx.failure("array of length 2", rawValue);
|
|
2943
|
+
}
|
|
2944
|
+
const [rawA, rawB] = rawValue;
|
|
2945
|
+
const resultA = parseA(rawA, ctx.forSubtree(0));
|
|
2946
|
+
if (isFailure(resultA)) {
|
|
2947
|
+
return resultA;
|
|
2948
|
+
}
|
|
2949
|
+
const resultB = parseB(rawB, ctx.forSubtree(1));
|
|
2950
|
+
if (isFailure(resultB)) {
|
|
2951
|
+
return resultB;
|
|
2952
|
+
}
|
|
2953
|
+
return ctx.success([resultA.value, resultB.value]);
|
|
2954
|
+
};
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2957
|
+
function pipeParsers(p) {
|
|
2958
|
+
return new ParserPipeline(p);
|
|
2959
|
+
}
|
|
2960
|
+
class ParserPipeline {
|
|
2961
|
+
constructor(parser) {
|
|
2962
|
+
this.parser = parser;
|
|
2963
|
+
}
|
|
2964
|
+
then(nextParser) {
|
|
2965
|
+
return new ParserPipeline(composeParsers(this.parser, nextParser));
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
function composeParsers(parserA, parserB) {
|
|
2969
|
+
return (rawValue, ctx) => {
|
|
2970
|
+
const partialResult = parserA(rawValue, ctx);
|
|
2971
|
+
if (isFailure(partialResult)) {
|
|
2972
|
+
return partialResult;
|
|
2973
|
+
}
|
|
2974
|
+
return parserB(partialResult.value, ctx);
|
|
2975
|
+
};
|
|
2976
|
+
}
|
|
2977
|
+
|
|
2978
|
+
function record(parseKey, parseValue) {
|
|
2979
|
+
return (rawValue, ctx) => {
|
|
2980
|
+
if (!isObject(rawValue)) {
|
|
2981
|
+
return ctx.failure("object", rawValue);
|
|
2982
|
+
}
|
|
2983
|
+
const result = {};
|
|
2984
|
+
const mismatches = [];
|
|
2985
|
+
for (const [key, value] of Object.entries(rawValue)) {
|
|
2986
|
+
const entryCtx = ctx.forSubtree(key);
|
|
2987
|
+
const keyResult = parseKey(key, entryCtx);
|
|
2988
|
+
if (isFailure(keyResult)) {
|
|
2989
|
+
mismatches.push(...keyResult.detail);
|
|
2990
|
+
}
|
|
2991
|
+
const valueResult = parseValue(value, entryCtx);
|
|
2992
|
+
if (isFailure(valueResult)) {
|
|
2993
|
+
mismatches.push(...valueResult.detail);
|
|
2994
|
+
}
|
|
2995
|
+
if (isSuccess(keyResult) && isSuccess(valueResult)) {
|
|
2996
|
+
result[keyResult.value] = valueResult.value;
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
if (mismatches.length > 0) {
|
|
3000
|
+
return failure(mismatches);
|
|
3001
|
+
}
|
|
3002
|
+
return ctx.success(result);
|
|
3003
|
+
};
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
const string = (rawValue, ctx) => {
|
|
3007
|
+
if (typeof rawValue === "string") {
|
|
3008
|
+
return ctx.success(rawValue);
|
|
3009
|
+
}
|
|
3010
|
+
return ctx.failure("string", rawValue);
|
|
3011
|
+
};
|
|
3012
|
+
|
|
3013
|
+
function trio(parseA, parseB, parseC) {
|
|
3014
|
+
return (rawValue, ctx) => {
|
|
3015
|
+
if (!Array.isArray(rawValue)) {
|
|
3016
|
+
return ctx.failure("array", rawValue);
|
|
3017
|
+
}
|
|
3018
|
+
if (rawValue.length !== 3) {
|
|
3019
|
+
return ctx.failure("array of length 3", rawValue);
|
|
3020
|
+
}
|
|
3021
|
+
const resultA = parseA(rawValue[0], ctx.forSubtree(0));
|
|
3022
|
+
if (isFailure(resultA)) {
|
|
3023
|
+
return resultA;
|
|
3024
|
+
}
|
|
3025
|
+
const resultB = parseB(rawValue[1], ctx.forSubtree(1));
|
|
3026
|
+
if (isFailure(resultB)) {
|
|
3027
|
+
return resultB;
|
|
3028
|
+
}
|
|
3029
|
+
const resultC = parseC(rawValue[2], ctx.forSubtree(2));
|
|
3030
|
+
if (isFailure(resultC)) {
|
|
3031
|
+
return resultC;
|
|
3032
|
+
}
|
|
3033
|
+
return ctx.success([resultA.value, resultB.value, resultC.value]);
|
|
3034
|
+
};
|
|
3035
|
+
}
|
|
3036
|
+
|
|
3037
|
+
function union(parseBranch) {
|
|
3038
|
+
return new UnionBuilder(parseBranch);
|
|
3039
|
+
}
|
|
3040
|
+
class UnionBuilder {
|
|
3041
|
+
constructor(parser) {
|
|
3042
|
+
this.parser = parser;
|
|
3043
|
+
}
|
|
3044
|
+
or(newBranch) {
|
|
3045
|
+
return new UnionBuilder(either(this.parser, newBranch));
|
|
3046
|
+
}
|
|
3047
|
+
}
|
|
3048
|
+
function either(parseA, parseB) {
|
|
3049
|
+
return (rawValue, ctx) => {
|
|
3050
|
+
const resultA = parseA(rawValue, ctx);
|
|
3051
|
+
if (isSuccess(resultA)) {
|
|
3052
|
+
return resultA;
|
|
3053
|
+
}
|
|
3054
|
+
return parseB(rawValue, ctx);
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
function defaulted(parser, fallback) {
|
|
3059
|
+
return (rawValue, ctx) => {
|
|
3060
|
+
if (rawValue == null) {
|
|
3061
|
+
return success(fallback(rawValue));
|
|
3062
|
+
}
|
|
3063
|
+
return parser(rawValue, ctx);
|
|
3064
|
+
};
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
const parseImages = defaulted(record(string, object({
|
|
3068
|
+
width: number,
|
|
3069
|
+
height: number
|
|
3070
|
+
})), () => ({}));
|
|
3071
|
+
|
|
3072
|
+
function parseWidget(parseType, parseOptions) {
|
|
3073
|
+
return object({
|
|
3074
|
+
type: parseType,
|
|
3075
|
+
static: optional(boolean),
|
|
3076
|
+
graded: optional(boolean),
|
|
3077
|
+
alignment: optional(string),
|
|
3078
|
+
options: parseOptions,
|
|
3079
|
+
key: optional(number),
|
|
3080
|
+
version: optional(object({
|
|
3081
|
+
major: number,
|
|
3082
|
+
minor: number
|
|
3083
|
+
}))
|
|
3084
|
+
});
|
|
3085
|
+
}
|
|
3086
|
+
function parseWidgetWithVersion(parseVersion, parseType, parseOptions) {
|
|
3087
|
+
return object({
|
|
3088
|
+
type: parseType,
|
|
3089
|
+
static: optional(boolean),
|
|
3090
|
+
graded: optional(boolean),
|
|
3091
|
+
alignment: optional(string),
|
|
3092
|
+
options: parseOptions,
|
|
3093
|
+
key: optional(number),
|
|
3094
|
+
version: parseVersion
|
|
3095
|
+
});
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
const parseCategorizerWidget = parseWidget(constant("categorizer"), object({
|
|
3099
|
+
items: array(string),
|
|
3100
|
+
categories: array(string),
|
|
3101
|
+
randomizeItems: defaulted(boolean, () => false),
|
|
3102
|
+
static: defaulted(boolean, () => false),
|
|
3103
|
+
values: array(defaulted(number, () => 0)),
|
|
3104
|
+
highlightLint: optional(boolean),
|
|
3105
|
+
linterContext: optional(object({
|
|
3106
|
+
contentType: string,
|
|
3107
|
+
paths: array(string),
|
|
3108
|
+
stack: array(string)
|
|
3109
|
+
}))
|
|
3110
|
+
}));
|
|
3111
|
+
|
|
3112
|
+
const parseCSProgramWidget = parseWidget(constant("cs-program"), object({
|
|
3113
|
+
programID: string,
|
|
3114
|
+
programType: any,
|
|
3115
|
+
settings: array(object({
|
|
3116
|
+
name: string,
|
|
3117
|
+
value: string
|
|
3118
|
+
})),
|
|
3119
|
+
showEditor: boolean,
|
|
3120
|
+
showButtons: boolean,
|
|
3121
|
+
height: number,
|
|
3122
|
+
static: defaulted(boolean, () => false)
|
|
3123
|
+
}));
|
|
3124
|
+
|
|
3125
|
+
const parseDefinitionWidget = parseWidget(constant("definition"), object({
|
|
3126
|
+
togglePrompt: string,
|
|
3127
|
+
definition: string,
|
|
3128
|
+
static: defaulted(boolean, () => false)
|
|
3129
|
+
}));
|
|
3130
|
+
|
|
3131
|
+
const parseDropdownWidget = parseWidget(constant("dropdown"), object({
|
|
3132
|
+
placeholder: defaulted(string, () => ""),
|
|
3133
|
+
ariaLabel: optional(string),
|
|
3134
|
+
visibleLabel: optional(string),
|
|
3135
|
+
static: defaulted(boolean, () => false),
|
|
3136
|
+
choices: array(object({
|
|
3137
|
+
content: string,
|
|
3138
|
+
correct: boolean
|
|
3139
|
+
}))
|
|
3140
|
+
}));
|
|
3141
|
+
|
|
3142
|
+
const parseExplanationWidget = parseWidget(constant("explanation"), object({
|
|
3143
|
+
showPrompt: string,
|
|
3144
|
+
hidePrompt: string,
|
|
3145
|
+
explanation: string,
|
|
3146
|
+
// We wrap parseWidgetsMap in a function here to make sure it is not
|
|
3147
|
+
// referenced before it is defined. There is an import cycle between
|
|
3148
|
+
// this file and widgets-map.ts that could cause it to be undefined.
|
|
3149
|
+
widgets: defaulted((rawVal, ctx) => parseWidgetsMap(rawVal, ctx), () => ({})),
|
|
3150
|
+
static: defaulted(boolean, () => false)
|
|
3151
|
+
}));
|
|
3152
|
+
|
|
3153
|
+
// Given a function, creates a PartialParser that converts one type to another
|
|
3154
|
+
// using that function. The returned parser never fails.
|
|
3155
|
+
function convert(f) {
|
|
3156
|
+
return (rawValue, ctx) => ctx.success(f(rawValue));
|
|
3157
|
+
}
|
|
3158
|
+
|
|
3159
|
+
/**
|
|
3160
|
+
* Creates a parser for a widget options type with multiple major versions. Old
|
|
3161
|
+
* versions are migrated to the latest version. The parse fails if the input
|
|
3162
|
+
* data does not match any of the versions.
|
|
3163
|
+
*
|
|
3164
|
+
* @example
|
|
3165
|
+
* const parseOptions = versionedWidgetOptions(3, parseOptionsV3)
|
|
3166
|
+
* .withMigrationFrom(2, parseOptionsV2, migrateV2ToV3)
|
|
3167
|
+
* .withMigrationFrom(1, parseOptionsV1, migrateV1ToV2)
|
|
3168
|
+
* .withMigrationFrom(0, parseOptionsV0, migrateV0ToV1)
|
|
3169
|
+
* .parser;
|
|
3170
|
+
*
|
|
3171
|
+
* @param latestMajorVersion the latest major version of the widget options.
|
|
3172
|
+
* @param parseLatest a {@link Parser} for the latest version of the widget
|
|
3173
|
+
* options.
|
|
3174
|
+
* @returns a builder object, to which migrations from earlier versions can be
|
|
3175
|
+
* added. Migrations must be added in "reverse chronological" order as in the
|
|
3176
|
+
* example above.
|
|
3177
|
+
*/
|
|
3178
|
+
function versionedWidgetOptions(latestMajorVersion, parseLatest) {
|
|
3179
|
+
return new VersionedWidgetOptionsParserBuilder(latestMajorVersion, parseLatest, latest => latest, (raw, ctx) => ctx.failure("widget options with a known version number", raw));
|
|
3180
|
+
}
|
|
3181
|
+
class VersionedWidgetOptionsParserBuilder {
|
|
3182
|
+
constructor(majorVersion, parseThisVersion, migrateToLatest, parseOtherVersions) {
|
|
3183
|
+
this.parser = void 0;
|
|
3184
|
+
this.migrateToLatest = migrateToLatest;
|
|
3185
|
+
this.parseOtherVersions = parseOtherVersions;
|
|
3186
|
+
const parseThisVersionAndMigrateToLatest = pipeParsers(parseThisVersion).then(convert(this.migrateToLatest)).parser;
|
|
3187
|
+
this.parser = (raw, ctx) => {
|
|
3188
|
+
if (!isObject(raw)) {
|
|
3189
|
+
return ctx.failure("object", raw);
|
|
3190
|
+
}
|
|
3191
|
+
const versionParseResult = parseVersionedObject(raw, ctx);
|
|
3192
|
+
if (isFailure(versionParseResult)) {
|
|
3193
|
+
return versionParseResult;
|
|
3194
|
+
}
|
|
3195
|
+
if (versionParseResult.value.version.major !== majorVersion) {
|
|
3196
|
+
return this.parseOtherVersions(raw, ctx);
|
|
3197
|
+
}
|
|
3198
|
+
return parseThisVersionAndMigrateToLatest(raw, ctx);
|
|
3199
|
+
};
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
/**
|
|
3203
|
+
* Add a migration from an old version of the widget options.
|
|
3204
|
+
*/
|
|
3205
|
+
withMigrationFrom(majorVersion, parseOldVersion, migrateToNextVersion) {
|
|
3206
|
+
const parseOtherVersions = this.parser;
|
|
3207
|
+
const migrateToLatest = old => this.migrateToLatest(migrateToNextVersion(old));
|
|
3208
|
+
return new VersionedWidgetOptionsParserBuilder(majorVersion, parseOldVersion, migrateToLatest, parseOtherVersions);
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
const parseVersionedObject = object({
|
|
3212
|
+
version: defaulted(object({
|
|
3213
|
+
major: number,
|
|
3214
|
+
minor: number
|
|
3215
|
+
}), () => ({
|
|
3216
|
+
major: 0,
|
|
3217
|
+
minor: 0
|
|
3218
|
+
}))
|
|
3219
|
+
});
|
|
3220
|
+
|
|
3221
|
+
const stringOrNumberOrNullOrUndefined = union(string).or(number).or(constant(null)).or(constant(undefined)).parser;
|
|
3222
|
+
const parsePossiblyInvalidAnswerForm = object({
|
|
3223
|
+
// `value` is the possibly invalid part of this. It should always be a
|
|
3224
|
+
// string, but some answer forms don't have it. The Expression widget
|
|
3225
|
+
// ignores invalid values, so we can safely filter them out during parsing.
|
|
3226
|
+
value: optional(string),
|
|
3227
|
+
form: defaulted(boolean, () => false),
|
|
3228
|
+
simplify: defaulted(boolean, () => false),
|
|
3229
|
+
considered: enumeration("correct", "wrong", "ungraded"),
|
|
3230
|
+
key: pipeParsers(stringOrNumberOrNullOrUndefined).then(convert(String)).parser
|
|
3231
|
+
});
|
|
3232
|
+
function removeInvalidAnswerForms(possiblyInvalid) {
|
|
3233
|
+
const valid = [];
|
|
3234
|
+
for (const answerForm of possiblyInvalid) {
|
|
3235
|
+
const {
|
|
3236
|
+
value
|
|
3237
|
+
} = answerForm;
|
|
3238
|
+
if (value != null) {
|
|
3239
|
+
// Copying the object seems to be needed to make TypeScript happy
|
|
3240
|
+
valid.push(_extends({}, answerForm, {
|
|
3241
|
+
value
|
|
3242
|
+
}));
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3245
|
+
return valid;
|
|
3246
|
+
}
|
|
3247
|
+
|
|
3248
|
+
// NOTE(benchristel): I copied the default buttonSets from
|
|
3249
|
+
// expression.tsx. See the parse-perseus-json/README.md for
|
|
3250
|
+
// an explanation of why we want to duplicate the default here.
|
|
3251
|
+
const parseButtonSets = defaulted(array(enumeration("basic", "basic+div", "trig", "prealgebra", "logarithms", "basic relations", "advanced relations")), () => ["basic", "trig", "prealgebra", "logarithms"]);
|
|
3252
|
+
const version1 = object({
|
|
3253
|
+
major: constant(1),
|
|
3254
|
+
minor: number
|
|
3255
|
+
});
|
|
3256
|
+
const parseExpressionWidgetV1 = parseWidgetWithVersion(version1, constant("expression"), object({
|
|
3257
|
+
answerForms: pipeParsers(array(parsePossiblyInvalidAnswerForm)).then(convert(removeInvalidAnswerForms)).parser,
|
|
3258
|
+
functions: array(string),
|
|
3259
|
+
times: boolean,
|
|
3260
|
+
visibleLabel: optional(string),
|
|
3261
|
+
ariaLabel: optional(string),
|
|
3262
|
+
buttonSets: parseButtonSets,
|
|
3263
|
+
buttonsVisible: optional(enumeration("always", "never", "focused"))
|
|
3264
|
+
}));
|
|
3265
|
+
const version0 = optional(object({
|
|
3266
|
+
major: constant(0),
|
|
3267
|
+
minor: number
|
|
3268
|
+
}));
|
|
3269
|
+
const parseExpressionWidgetV0 = parseWidgetWithVersion(version0, constant("expression"), object({
|
|
3270
|
+
functions: array(string),
|
|
3271
|
+
times: boolean,
|
|
3272
|
+
visibleLabel: optional(string),
|
|
3273
|
+
ariaLabel: optional(string),
|
|
3274
|
+
form: boolean,
|
|
3275
|
+
simplify: boolean,
|
|
3276
|
+
value: string,
|
|
3277
|
+
buttonSets: parseButtonSets,
|
|
3278
|
+
buttonsVisible: optional(enumeration("always", "never", "focused"))
|
|
3279
|
+
}));
|
|
3280
|
+
function migrateV0ToV1(widget) {
|
|
3281
|
+
const {
|
|
3282
|
+
options
|
|
3283
|
+
} = widget;
|
|
3284
|
+
return _extends({}, widget, {
|
|
3285
|
+
version: {
|
|
3286
|
+
major: 1,
|
|
3287
|
+
minor: 0
|
|
3288
|
+
},
|
|
3289
|
+
options: {
|
|
3290
|
+
times: options.times,
|
|
3291
|
+
buttonSets: options.buttonSets,
|
|
3292
|
+
functions: options.functions,
|
|
3293
|
+
buttonsVisible: options.buttonsVisible,
|
|
3294
|
+
visibleLabel: options.visibleLabel,
|
|
3295
|
+
ariaLabel: options.ariaLabel,
|
|
3296
|
+
answerForms: [{
|
|
3297
|
+
considered: "correct",
|
|
3298
|
+
form: options.form,
|
|
3299
|
+
simplify: options.simplify,
|
|
3300
|
+
value: options.value
|
|
3301
|
+
}]
|
|
3302
|
+
}
|
|
3303
|
+
});
|
|
3304
|
+
}
|
|
3305
|
+
const parseExpressionWidget = versionedWidgetOptions(1, parseExpressionWidgetV1).withMigrationFrom(0, parseExpressionWidgetV0, migrateV0ToV1).parser;
|
|
3306
|
+
|
|
3307
|
+
const falseToNull = pipeParsers(constant(false)).then(convert(() => null)).parser;
|
|
3308
|
+
const parseGradedGroupWidgetOptions = object({
|
|
3309
|
+
title: defaulted(string, () => ""),
|
|
3310
|
+
hasHint: optional(nullable(boolean)),
|
|
3311
|
+
// This module has an import cycle with parsePerseusRenderer.
|
|
3312
|
+
// The anonymous function below ensures that we don't try to access
|
|
3313
|
+
// parsePerseusRenderer before it's defined.
|
|
3314
|
+
hint: union(falseToNull).or(constant(null)).or(constant(undefined)).or((rawVal, ctx) => parsePerseusRenderer(rawVal, ctx)).parser,
|
|
3315
|
+
content: string,
|
|
3316
|
+
// This module has an import cycle with parseWidgetsMap.
|
|
3317
|
+
// The anonymous function below ensures that we don't try to access
|
|
3318
|
+
// parseWidgetsMap before it's defined.
|
|
3319
|
+
widgets: (rawVal, ctx) => parseWidgetsMap(rawVal, ctx),
|
|
3320
|
+
widgetEnabled: optional(nullable(boolean)),
|
|
3321
|
+
immutableWidgets: optional(nullable(boolean)),
|
|
3322
|
+
images: record(string, object({
|
|
3323
|
+
width: number,
|
|
3324
|
+
height: number
|
|
3325
|
+
}))
|
|
3326
|
+
});
|
|
3327
|
+
const parseGradedGroupWidget = parseWidget(constant("graded-group"), parseGradedGroupWidgetOptions);
|
|
3328
|
+
|
|
3329
|
+
const parseGradedGroupSetWidget = parseWidget(constant("graded-group-set"), object({
|
|
3330
|
+
gradedGroups: array(parseGradedGroupWidgetOptions)
|
|
3331
|
+
}));
|
|
3332
|
+
|
|
3333
|
+
/**
|
|
3334
|
+
* discriminatedUnion() should be preferred over union() when parsing a
|
|
3335
|
+
* discriminated union type, because discriminatedUnion() produces more
|
|
3336
|
+
* understandable failure messages. It takes the discriminant as the source of
|
|
3337
|
+
* truth for which variant is to be parsed, and expects the other data to match
|
|
3338
|
+
* that variant.
|
|
3339
|
+
*/
|
|
3340
|
+
function discriminatedUnionOn(discriminantKey) {
|
|
3341
|
+
const noMoreBranches = (raw, ctx) => {
|
|
3342
|
+
if (!isObject(raw)) {
|
|
3343
|
+
return ctx.failure("object", raw);
|
|
3344
|
+
}
|
|
3345
|
+
return ctx.forSubtree(discriminantKey).failure("a valid value", raw[discriminantKey]);
|
|
3346
|
+
};
|
|
3347
|
+
return new DiscriminatedUnionBuilder(discriminantKey, noMoreBranches);
|
|
3348
|
+
}
|
|
3349
|
+
class DiscriminatedUnionBuilder {
|
|
3350
|
+
constructor(discriminantKey, parser) {
|
|
3351
|
+
this.discriminantKey = discriminantKey;
|
|
3352
|
+
this.parser = parser;
|
|
3353
|
+
}
|
|
3354
|
+
withBranch(discriminantValue, parseNewVariant) {
|
|
3355
|
+
const parseNewBranch = discriminatedUnionBranch(this.discriminantKey, discriminantValue, parseNewVariant, this.parser);
|
|
3356
|
+
return new DiscriminatedUnionBuilder(this.discriminantKey, parseNewBranch);
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
function discriminatedUnionBranch(discriminantKey, discriminantValue, parseVariant, parseOtherBranches) {
|
|
3360
|
+
return (raw, ctx) => {
|
|
3361
|
+
if (!isObject(raw)) {
|
|
3362
|
+
return ctx.failure("object", raw);
|
|
3363
|
+
}
|
|
3364
|
+
if (raw[discriminantKey] === discriminantValue) {
|
|
3365
|
+
return parseVariant(raw, ctx);
|
|
3366
|
+
}
|
|
3367
|
+
return parseOtherBranches(raw, ctx);
|
|
3368
|
+
};
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3371
|
+
const pairOfNumbers$3 = pair(number, number);
|
|
3372
|
+
const pairOfPoints = pair(pairOfNumbers$3, pairOfNumbers$3);
|
|
3373
|
+
const parseGrapherWidget = parseWidget(constant("grapher"), object({
|
|
3374
|
+
availableTypes: array(enumeration("absolute_value", "exponential", "linear", "logarithm", "quadratic", "sinusoid", "tangent")),
|
|
3375
|
+
correct: discriminatedUnionOn("type").withBranch("absolute_value", object({
|
|
3376
|
+
type: constant("absolute_value"),
|
|
3377
|
+
coords: nullable(pairOfPoints)
|
|
3378
|
+
})).withBranch("exponential", object({
|
|
3379
|
+
type: constant("exponential"),
|
|
3380
|
+
asymptote: pairOfPoints,
|
|
3381
|
+
coords: nullable(pairOfPoints)
|
|
3382
|
+
})).withBranch("linear", object({
|
|
3383
|
+
type: constant("linear"),
|
|
3384
|
+
coords: nullable(pairOfPoints)
|
|
3385
|
+
})).withBranch("logarithm", object({
|
|
3386
|
+
type: constant("logarithm"),
|
|
3387
|
+
asymptote: pairOfPoints,
|
|
3388
|
+
coords: nullable(pairOfPoints)
|
|
3389
|
+
})).withBranch("quadratic", object({
|
|
3390
|
+
type: constant("quadratic"),
|
|
3391
|
+
coords: nullable(pairOfPoints)
|
|
3392
|
+
})).withBranch("sinusoid", object({
|
|
3393
|
+
type: constant("sinusoid"),
|
|
3394
|
+
coords: nullable(pairOfPoints)
|
|
3395
|
+
})).withBranch("tangent", object({
|
|
3396
|
+
type: constant("tangent"),
|
|
3397
|
+
coords: nullable(pairOfPoints)
|
|
3398
|
+
})).parser,
|
|
3399
|
+
graph: object({
|
|
3400
|
+
backgroundImage: object({
|
|
3401
|
+
bottom: optional(number),
|
|
3402
|
+
height: optional(number),
|
|
3403
|
+
left: optional(number),
|
|
3404
|
+
scale: optional(number),
|
|
3405
|
+
url: optional(nullable(string)),
|
|
3406
|
+
width: optional(number)
|
|
3407
|
+
}),
|
|
3408
|
+
box: optional(pairOfNumbers$3),
|
|
3409
|
+
editableSettings: optional(array(enumeration("graph", "snap", "image", "measure"))),
|
|
3410
|
+
gridStep: optional(pairOfNumbers$3),
|
|
3411
|
+
labels: pair(string, string),
|
|
3412
|
+
markings: enumeration("graph", "none", "grid"),
|
|
3413
|
+
range: pair(pairOfNumbers$3, pairOfNumbers$3),
|
|
3414
|
+
rulerLabel: constant(""),
|
|
3415
|
+
rulerTicks: number,
|
|
3416
|
+
showProtractor: optional(boolean),
|
|
3417
|
+
showRuler: optional(boolean),
|
|
3418
|
+
showTooltips: optional(boolean),
|
|
3419
|
+
snapStep: optional(pairOfNumbers$3),
|
|
3420
|
+
step: pairOfNumbers$3,
|
|
3421
|
+
valid: optional(union(boolean).or(string).parser)
|
|
3422
|
+
})
|
|
3423
|
+
}));
|
|
3424
|
+
|
|
3425
|
+
const parseGroupWidget = parseWidget(constant("group"),
|
|
3426
|
+
// This module has an import cycle with parsePerseusRenderer.
|
|
3427
|
+
// The anonymous function below ensures that we don't try to access
|
|
3428
|
+
// parsePerseusRenderer before it's defined.
|
|
3429
|
+
(rawVal, ctx) => parsePerseusRenderer(rawVal, ctx));
|
|
3430
|
+
|
|
3431
|
+
const parseIframeWidget = parseWidget(constant("iframe"), object({
|
|
3432
|
+
url: string,
|
|
3433
|
+
settings: optional(array(object({
|
|
3434
|
+
name: string,
|
|
3435
|
+
value: string
|
|
3436
|
+
}))),
|
|
3437
|
+
width: union(number).or(string).parser,
|
|
3438
|
+
height: union(number).or(string).parser,
|
|
3439
|
+
allowFullScreen: defaulted(boolean, () => false),
|
|
3440
|
+
allowTopNavigation: optional(boolean),
|
|
3441
|
+
static: defaulted(boolean, () => false)
|
|
3442
|
+
}));
|
|
3443
|
+
|
|
3444
|
+
const stringToNumber = (rawValue, ctx) => {
|
|
3445
|
+
if (typeof rawValue === "number") {
|
|
3446
|
+
return ctx.success(rawValue);
|
|
3447
|
+
}
|
|
3448
|
+
const parsedNumber = +rawValue;
|
|
3449
|
+
if (rawValue === "" || isNaN(parsedNumber)) {
|
|
3450
|
+
return ctx.failure("a number or numeric string", rawValue);
|
|
3451
|
+
}
|
|
3452
|
+
return ctx.success(parsedNumber);
|
|
3453
|
+
};
|
|
3454
|
+
|
|
3455
|
+
function emptyToZero(x) {
|
|
3456
|
+
return x === "" ? 0 : x;
|
|
3457
|
+
}
|
|
3458
|
+
const imageDimensionToNumber = pipeParsers(union(number).or(string).parser)
|
|
3459
|
+
// In this specific case, empty string is equivalent to zero. An empty
|
|
3460
|
+
// string parses to either NaN (using parseInt) or 0 (using unary +) and
|
|
3461
|
+
// CSS will treat NaN as invalid and default to 0 instead.
|
|
3462
|
+
.then(convert(emptyToZero)).then(stringToNumber).parser;
|
|
3463
|
+
const parsePerseusImageBackground = object({
|
|
3464
|
+
url: optional(nullable(string)),
|
|
3465
|
+
width: optional(imageDimensionToNumber),
|
|
3466
|
+
height: optional(imageDimensionToNumber),
|
|
3467
|
+
top: optional(imageDimensionToNumber),
|
|
3468
|
+
left: optional(imageDimensionToNumber),
|
|
3469
|
+
bottom: optional(imageDimensionToNumber),
|
|
3470
|
+
scale: optional(imageDimensionToNumber)
|
|
3471
|
+
});
|
|
3472
|
+
|
|
3473
|
+
const pairOfNumbers$2 = pair(number, number);
|
|
3474
|
+
const parseImageWidget = parseWidget(constant("image"), object({
|
|
3475
|
+
title: optional(string),
|
|
3476
|
+
caption: optional(string),
|
|
3477
|
+
alt: optional(string),
|
|
3478
|
+
backgroundImage: parsePerseusImageBackground,
|
|
3479
|
+
static: optional(boolean),
|
|
3480
|
+
labels: optional(array(object({
|
|
3481
|
+
content: string,
|
|
3482
|
+
alignment: string,
|
|
3483
|
+
coordinates: array(number)
|
|
3484
|
+
}))),
|
|
3485
|
+
range: optional(pair(pairOfNumbers$2, pairOfNumbers$2)),
|
|
3486
|
+
box: optional(pairOfNumbers$2)
|
|
3487
|
+
}));
|
|
3488
|
+
|
|
3489
|
+
const booleanToString = (rawValue, ctx) => {
|
|
3490
|
+
if (typeof rawValue === "boolean") {
|
|
3491
|
+
return ctx.success(String(rawValue));
|
|
3492
|
+
}
|
|
3493
|
+
return ctx.failure("boolean", rawValue);
|
|
3494
|
+
};
|
|
3495
|
+
const parseInputNumberWidget = parseWidget(constant("input-number"), object({
|
|
3496
|
+
answerType: optional(enumeration("number", "decimal", "integer", "rational", "improper", "mixed", "percent", "pi")),
|
|
3497
|
+
inexact: optional(boolean),
|
|
3498
|
+
maxError: optional(union(number).or(string).parser),
|
|
3499
|
+
rightAlign: optional(boolean),
|
|
3500
|
+
simplify: enumeration("required", "optional", "enforced"),
|
|
3501
|
+
size: enumeration("normal", "small"),
|
|
3502
|
+
// TODO(benchristel): there are some content items where value is a
|
|
3503
|
+
// boolean, even though that makes no sense. We should figure out if
|
|
3504
|
+
// those content items are actually published anywhere, and consider
|
|
3505
|
+
// updating them.
|
|
3506
|
+
value: union(number).or(string).or(booleanToString).parser,
|
|
3507
|
+
customKeypad: optional(boolean)
|
|
3508
|
+
}));
|
|
3509
|
+
|
|
3510
|
+
const pairOfNumbers$1 = pair(number, number);
|
|
3511
|
+
const stringOrEmpty = defaulted(string, () => "");
|
|
3512
|
+
const parseKey = pipeParsers(optional(string)).then(convert(String)).parser;
|
|
3513
|
+
const parseFunctionElement = object({
|
|
3514
|
+
type: constant("function"),
|
|
3515
|
+
key: parseKey,
|
|
3516
|
+
options: object({
|
|
3517
|
+
value: string,
|
|
3518
|
+
funcName: string,
|
|
3519
|
+
rangeMin: string,
|
|
3520
|
+
rangeMax: string,
|
|
3521
|
+
color: string,
|
|
3522
|
+
strokeDasharray: string,
|
|
3523
|
+
strokeWidth: number
|
|
3524
|
+
})
|
|
3525
|
+
});
|
|
3526
|
+
const parseLabelElement = object({
|
|
3527
|
+
type: constant("label"),
|
|
3528
|
+
key: parseKey,
|
|
3529
|
+
options: object({
|
|
3530
|
+
label: string,
|
|
3531
|
+
color: string,
|
|
3532
|
+
coordX: string,
|
|
3533
|
+
coordY: string
|
|
3534
|
+
})
|
|
3535
|
+
});
|
|
3536
|
+
const parseLineElement = object({
|
|
3537
|
+
type: constant("line"),
|
|
3538
|
+
key: parseKey,
|
|
3539
|
+
options: object({
|
|
3540
|
+
color: string,
|
|
3541
|
+
startX: string,
|
|
3542
|
+
startY: string,
|
|
3543
|
+
endX: string,
|
|
3544
|
+
endY: string,
|
|
3545
|
+
strokeDasharray: string,
|
|
3546
|
+
strokeWidth: number,
|
|
3547
|
+
arrows: string
|
|
3548
|
+
})
|
|
3549
|
+
});
|
|
3550
|
+
const parseMovableLineElement = object({
|
|
3551
|
+
type: constant("movable-line"),
|
|
3552
|
+
key: parseKey,
|
|
3553
|
+
options: object({
|
|
3554
|
+
startX: string,
|
|
3555
|
+
startY: string,
|
|
3556
|
+
startSubscript: number,
|
|
3557
|
+
endX: string,
|
|
3558
|
+
endY: string,
|
|
3559
|
+
endSubscript: number,
|
|
3560
|
+
constraint: string,
|
|
3561
|
+
snap: number,
|
|
3562
|
+
constraintFn: string,
|
|
3563
|
+
constraintXMin: string,
|
|
3564
|
+
constraintXMax: string,
|
|
3565
|
+
constraintYMin: string,
|
|
3566
|
+
constraintYMax: string
|
|
3567
|
+
})
|
|
3568
|
+
});
|
|
3569
|
+
const parseMovablePointElement = object({
|
|
3570
|
+
type: constant("movable-point"),
|
|
3571
|
+
key: parseKey,
|
|
3572
|
+
options: object({
|
|
3573
|
+
startX: string,
|
|
3574
|
+
startY: string,
|
|
3575
|
+
varSubscript: number,
|
|
3576
|
+
constraint: string,
|
|
3577
|
+
snap: number,
|
|
3578
|
+
constraintFn: string,
|
|
3579
|
+
constraintXMin: stringOrEmpty,
|
|
3580
|
+
constraintXMax: stringOrEmpty,
|
|
3581
|
+
constraintYMin: stringOrEmpty,
|
|
3582
|
+
constraintYMax: stringOrEmpty
|
|
3583
|
+
})
|
|
3584
|
+
});
|
|
3585
|
+
const parseParametricElement = object({
|
|
3586
|
+
type: constant("parametric"),
|
|
3587
|
+
key: parseKey,
|
|
3588
|
+
options: object({
|
|
3589
|
+
x: string,
|
|
3590
|
+
y: string,
|
|
3591
|
+
rangeMin: string,
|
|
3592
|
+
rangeMax: string,
|
|
3593
|
+
color: string,
|
|
3594
|
+
strokeDasharray: string,
|
|
3595
|
+
strokeWidth: number
|
|
3596
|
+
})
|
|
3597
|
+
});
|
|
3598
|
+
const parsePointElement = object({
|
|
3599
|
+
type: constant("point"),
|
|
3600
|
+
key: parseKey,
|
|
3601
|
+
options: object({
|
|
3602
|
+
color: string,
|
|
3603
|
+
coordX: string,
|
|
3604
|
+
coordY: string
|
|
3605
|
+
})
|
|
3606
|
+
});
|
|
3607
|
+
const parseRectangleElement = object({
|
|
3608
|
+
type: constant("rectangle"),
|
|
3609
|
+
key: parseKey,
|
|
3610
|
+
options: object({
|
|
3611
|
+
color: string,
|
|
3612
|
+
coordX: string,
|
|
3613
|
+
coordY: string,
|
|
3614
|
+
width: string,
|
|
3615
|
+
height: string
|
|
3616
|
+
})
|
|
3617
|
+
});
|
|
3618
|
+
const parseInteractionWidget = parseWidget(constant("interaction"), object({
|
|
3619
|
+
static: defaulted(boolean, () => false),
|
|
3620
|
+
graph: object({
|
|
3621
|
+
editableSettings: optional(array(enumeration("canvas", "graph"))),
|
|
3622
|
+
box: pairOfNumbers$1,
|
|
3623
|
+
labels: array(string),
|
|
3624
|
+
range: pair(pairOfNumbers$1, pairOfNumbers$1),
|
|
3625
|
+
gridStep: pairOfNumbers$1,
|
|
3626
|
+
markings: enumeration("graph", "grid", "none"),
|
|
3627
|
+
snapStep: optional(pairOfNumbers$1),
|
|
3628
|
+
valid: optional(union(boolean).or(string).parser),
|
|
3629
|
+
backgroundImage: optional(parsePerseusImageBackground),
|
|
3630
|
+
showProtractor: optional(boolean),
|
|
3631
|
+
showRuler: optional(boolean),
|
|
3632
|
+
rulerLabel: optional(string),
|
|
3633
|
+
rulerTicks: optional(number),
|
|
3634
|
+
tickStep: pairOfNumbers$1
|
|
3635
|
+
}),
|
|
3636
|
+
elements: array(discriminatedUnionOn("type").withBranch("function", parseFunctionElement).withBranch("label", parseLabelElement).withBranch("line", parseLineElement).withBranch("movable-line", parseMovableLineElement).withBranch("movable-point", parseMovablePointElement).withBranch("parametric", parseParametricElement).withBranch("point", parsePointElement).withBranch("rectangle", parseRectangleElement).parser)
|
|
3637
|
+
}));
|
|
3638
|
+
|
|
3639
|
+
/**
|
|
3640
|
+
* The Perseus "data schema" file.
|
|
3641
|
+
*
|
|
3642
|
+
* This file, and the types in it, represents the "data schema" that Perseus
|
|
3643
|
+
* uses. The @khanacademy/perseus-editor package edits and produces objects
|
|
3644
|
+
* that conform to the types in this file. Similarly, the top-level renderers
|
|
3645
|
+
* in @khanacademy/perseus, consume objects that conform to these types.
|
|
3646
|
+
*
|
|
3647
|
+
* WARNING: This file should not import any types from elsewhere so that it is
|
|
3648
|
+
* easy to reason about changes that alter the Perseus schema. This helps
|
|
3649
|
+
* ensure that it is not changed accidentally when upgrading a dependant
|
|
3650
|
+
* package or other part of Perseus code. Note that TypeScript does type
|
|
3651
|
+
* checking via something called "structural typing". This means that as long
|
|
3652
|
+
* as the shape of a type matches, the name it goes by doesn't matter. As a
|
|
3653
|
+
* result, a `Coord` type that looks like this `[x: number, y: number]` is
|
|
3654
|
+
* _identical_, in TypeScript's eyes, to this `Vector2` type `[x: number, y:
|
|
3655
|
+
* number]`. Also, with tuples, the labels for each entry is ignored, so `[x:
|
|
3656
|
+
* number, y: number]` is compatible with `[min: number, max: number]`. The
|
|
3657
|
+
* labels are for humans, not TypeScript. :)
|
|
3658
|
+
*
|
|
3659
|
+
* If you make changes to types in this file, be very sure that:
|
|
3660
|
+
*
|
|
3661
|
+
* a) the changes are backwards compatible. If they are not, old data from
|
|
3662
|
+
* previous versions of the "schema" could become unrenderable, or worse,
|
|
3663
|
+
* introduce hard-to-diagnose bugs.
|
|
3664
|
+
* b) the parsing code (`util/parse-perseus-json/`) is updated to handle
|
|
3665
|
+
* the new format _as well as_ the old format.
|
|
3666
|
+
*/
|
|
3667
|
+
|
|
3668
|
+
// TODO(FEI-4010): Remove `Perseus` prefix for all types here
|
|
3669
|
+
|
|
3670
|
+
// Same name as Mafs
|
|
3671
|
+
|
|
3672
|
+
/**
|
|
3673
|
+
* A utility type that constructs a widget map from a "registry interface".
|
|
3674
|
+
* The keys of the registry should be the widget type (aka, "categorizer" or
|
|
3675
|
+
* "radio", etc) and the value should be the option type stored in the value
|
|
3676
|
+
* of the map.
|
|
3677
|
+
*
|
|
3678
|
+
* You can think of this as a type that generates another type. We use
|
|
3679
|
+
* "registry interfaces" as a way to keep a set of widget types to their data
|
|
3680
|
+
* type in several places in Perseus. This type then allows us to generate a
|
|
3681
|
+
* map type that maps a widget id to its data type and keep strong typing by
|
|
3682
|
+
* widget id.
|
|
3683
|
+
*
|
|
3684
|
+
* For example, given a fictitious registry such as this:
|
|
3685
|
+
*
|
|
3686
|
+
* ```
|
|
3687
|
+
* interface DummyRegistry {
|
|
3688
|
+
* categorizer: { categories: ReadonlyArray<string> };
|
|
3689
|
+
* dropdown: { choices: ReadonlyArray<string> }:
|
|
3690
|
+
* }
|
|
3691
|
+
* ```
|
|
3692
|
+
*
|
|
3693
|
+
* If we create a DummyMap using this helper:
|
|
3694
|
+
*
|
|
3695
|
+
* ```
|
|
3696
|
+
* type DummyMap = MakeWidgetMap<DummyRegistry>;
|
|
3697
|
+
* ```
|
|
3698
|
+
*
|
|
3699
|
+
* We'll get a map that looks like this:
|
|
3700
|
+
*
|
|
3701
|
+
* ```
|
|
3702
|
+
* type DummyMap = {
|
|
3703
|
+
* `categorizer ${number}`: { categories: ReadonlyArray<string> };
|
|
3704
|
+
* `dropdown ${number}`: { choices: ReadonlyArray<string> };
|
|
3705
|
+
* }
|
|
3706
|
+
* ```
|
|
3707
|
+
*
|
|
3708
|
+
* We use interfaces for the registries so that they can be extended in cases
|
|
3709
|
+
* where the consuming app brings along their own widgets. Interfaces in
|
|
3710
|
+
* TypeScript are always open (ie. you can extend them) whereas types aren't.
|
|
3711
|
+
*/
|
|
3712
|
+
|
|
3713
|
+
/**
|
|
3714
|
+
* Our core set of Perseus widgets.
|
|
3715
|
+
*
|
|
3716
|
+
* This interface is the basis for "registering" all Perseus widget types.
|
|
3717
|
+
* There should be one key/value pair for each supported widget. If you create
|
|
3718
|
+
* a new widget, an entry should be added to this interface. Note that this
|
|
3719
|
+
* only registers the widget options type, you'll also need to register the
|
|
3720
|
+
* widget so that it's available at runtime (@see
|
|
3721
|
+
* {@link file://./widgets.ts#registerWidget}).
|
|
3722
|
+
*
|
|
3723
|
+
* Importantly, the key should be the name that is used in widget IDs. For most
|
|
3724
|
+
* widgets that is the same as the widget option's `type` field. In cases where
|
|
3725
|
+
* a widget has been deprecated and replaced with the deprecated-standin
|
|
3726
|
+
* widget, it should be the original widget type!
|
|
3727
|
+
*
|
|
3728
|
+
* If you define the widget outside of this package, you can still add the new
|
|
3729
|
+
* widget to this interface by writing the following in that package that
|
|
3730
|
+
* contains the widget. TypeScript will merge that definition of the
|
|
3731
|
+
* `PerseusWidgets` with the one defined below.
|
|
3732
|
+
*
|
|
3733
|
+
* ```typescript
|
|
3734
|
+
* declare module "@khanacademy/perseus-core" {
|
|
3735
|
+
* interface PerseusWidgetTypes {
|
|
3736
|
+
* // A new widget
|
|
3737
|
+
* "new-awesomeness": MyAwesomeNewWidget;
|
|
3738
|
+
*
|
|
3739
|
+
* // A deprecated widget
|
|
3740
|
+
* "super-old-widget": DeprecatedStandinWidget;
|
|
3741
|
+
* }
|
|
3742
|
+
* }
|
|
3743
|
+
*
|
|
3744
|
+
* // The new widget's options definition
|
|
3745
|
+
* type MyAwesomeNewWidget = WidgetOptions<'new-awesomeness', MyAwesomeNewWidgetOptions>;
|
|
3746
|
+
*
|
|
3747
|
+
* // The deprecated widget's options definition
|
|
3748
|
+
* type SuperOldWidget = WidgetOptions<'super-old-widget', object>;
|
|
3749
|
+
* ```
|
|
3750
|
+
*
|
|
3751
|
+
* This interface can be extended through the magic of TypeScript "Declaration
|
|
3752
|
+
* merging". Specifically, we augment this module and extend this interface.
|
|
3753
|
+
*
|
|
3754
|
+
* @see {@link https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation}
|
|
3755
|
+
*/
|
|
3756
|
+
|
|
3757
|
+
/**
|
|
3758
|
+
* A map of widget IDs to widget options. This is most often used as the type
|
|
3759
|
+
* for a set of widgets defined in a `PerseusItem` but can also be useful to
|
|
3760
|
+
* represent a function parameter where only `widgets` from a `PerseusItem` are
|
|
3761
|
+
* needed. Today Widget IDs are made up of the widget type and an incrementing
|
|
3762
|
+
* integer (eg. `interactive-graph 1` or `radio 3`). It is suggested to avoid
|
|
3763
|
+
* reading/parsing the widget id to derive any information from it, except in
|
|
3764
|
+
* the case of this map.
|
|
3765
|
+
*
|
|
3766
|
+
* @see {@link PerseusWidgetTypes} additional widgets can be added to this map type
|
|
3767
|
+
* by augmenting the PerseusWidgetTypes with new widget types!
|
|
3768
|
+
*/
|
|
3769
|
+
|
|
3770
|
+
/**
|
|
3771
|
+
* PerseusWidget is a union of all the different types of widget options that
|
|
3772
|
+
* Perseus knows about.
|
|
3773
|
+
*
|
|
3774
|
+
* Thanks to it being based on PerseusWidgetTypes interface, this union is
|
|
3775
|
+
* automatically extended to include widgets used in tests without those widget
|
|
3776
|
+
* option types seeping into our production types.
|
|
3777
|
+
*
|
|
3778
|
+
* @see MockWidget for an example
|
|
3779
|
+
*/
|
|
3780
|
+
|
|
3781
|
+
/**
|
|
3782
|
+
* A "PerseusItem" is a classic Perseus item. It is rendered by the
|
|
3783
|
+
* `ServerItemRenderer` and the layout is pre-set.
|
|
3784
|
+
*
|
|
3785
|
+
* To render more complex Perseus items, see the `Item` type in the multi item
|
|
3786
|
+
* area.
|
|
3787
|
+
*/
|
|
3788
|
+
|
|
3789
|
+
/**
|
|
3790
|
+
* A "PerseusArticle" is an item that is meant to be rendered as an article.
|
|
3791
|
+
* This item is never scored and is rendered by the `ArticleRenderer`.
|
|
3792
|
+
*/
|
|
3793
|
+
|
|
3794
|
+
const ItemExtras = [
|
|
3795
|
+
// The user might benefit from using a Scientific Calculator. Provided on Khan Academy when true
|
|
3796
|
+
"calculator",
|
|
3797
|
+
// The user might benefit from using a statistics Chi Squared Table like https://people.richland.edu/james/lecture/m170/tbl-chi.html
|
|
3798
|
+
"chi2Table",
|
|
3799
|
+
// The user might benefit from a monthly payments calculator. Provided on Khan Academy when true
|
|
3800
|
+
"financialCalculatorMonthlyPayment",
|
|
3801
|
+
// The user might benefit from a total amount calculator. Provided on Khan Academy when true
|
|
3802
|
+
"financialCalculatorTotalAmount",
|
|
3803
|
+
// The user might benefit from a time to pay off calculator. Provided on Khan Academy when true
|
|
3804
|
+
"financialCalculatorTimeToPayOff",
|
|
3805
|
+
// The user might benefit from using a Periodic Table of Elements. Provided on Khan Academy when true
|
|
3806
|
+
"periodicTable",
|
|
3807
|
+
// The user might benefit from using a Periodic Table of Elements with key. Provided on Khan Academy when true
|
|
3808
|
+
"periodicTableWithKey",
|
|
3809
|
+
// The user might benefit from using a statistics T Table like https://www.statisticshowto.com/tables/t-distribution-table/
|
|
3810
|
+
"tTable",
|
|
3811
|
+
// The user might benefit from using a statistics Z Table like https://www.ztable.net/
|
|
3812
|
+
"zTable"];
|
|
3813
|
+
|
|
3814
|
+
/**
|
|
3815
|
+
* The type representing the common structure of all widget's options. The
|
|
3816
|
+
* `Options` generic type represents the widget-specific option data.
|
|
3817
|
+
*/
|
|
3818
|
+
|
|
3819
|
+
// prettier-ignore
|
|
3820
|
+
|
|
3821
|
+
// prettier-ignore
|
|
3822
|
+
|
|
3823
|
+
// prettier-ignore
|
|
3824
|
+
|
|
3825
|
+
// prettier-ignore
|
|
3826
|
+
|
|
3827
|
+
// prettier-ignore
|
|
3828
|
+
|
|
3829
|
+
// prettier-ignore
|
|
3830
|
+
|
|
3831
|
+
// prettier-ignore
|
|
3832
|
+
|
|
3833
|
+
// prettier-ignore
|
|
3834
|
+
|
|
3835
|
+
// prettier-ignore
|
|
3836
|
+
|
|
3837
|
+
// prettier-ignore
|
|
3838
|
+
|
|
3839
|
+
// prettier-ignore
|
|
3840
|
+
|
|
3841
|
+
// prettier-ignore
|
|
3842
|
+
|
|
3843
|
+
// prettier-ignore
|
|
3844
|
+
|
|
3845
|
+
// prettier-ignore
|
|
3846
|
+
|
|
3847
|
+
// prettier-ignore
|
|
3848
|
+
|
|
3849
|
+
// prettier-ignore
|
|
3850
|
+
|
|
3851
|
+
// prettier-ignore
|
|
3852
|
+
|
|
3853
|
+
// prettier-ignore
|
|
3854
|
+
|
|
3855
|
+
// prettier-ignore
|
|
3856
|
+
|
|
3857
|
+
// prettier-ignore
|
|
3858
|
+
|
|
3859
|
+
// prettier-ignore
|
|
3860
|
+
|
|
3861
|
+
// prettier-ignore
|
|
3862
|
+
|
|
3863
|
+
// prettier-ignore
|
|
3864
|
+
|
|
3865
|
+
// prettier-ignore
|
|
3866
|
+
|
|
3867
|
+
// prettier-ignore
|
|
3868
|
+
|
|
3869
|
+
// prettier-ignore
|
|
3870
|
+
|
|
3871
|
+
// prettier-ignore
|
|
3872
|
+
|
|
3873
|
+
// prettier-ignore
|
|
3874
|
+
|
|
3875
|
+
// prettier-ignore
|
|
3876
|
+
|
|
3877
|
+
// prettier-ignore
|
|
3878
|
+
|
|
3879
|
+
// prettier-ignore
|
|
3880
|
+
|
|
3881
|
+
// prettier-ignore
|
|
3882
|
+
|
|
3883
|
+
// prettier-ignore
|
|
3884
|
+
|
|
3885
|
+
//prettier-ignore
|
|
3886
|
+
|
|
3887
|
+
/**
|
|
3888
|
+
* A background image applied to various widgets.
|
|
3889
|
+
*/
|
|
3890
|
+
|
|
3891
|
+
/**
|
|
3892
|
+
* The type of markings to display on the graph.
|
|
3893
|
+
* - axes: shows the axes without the gride lines
|
|
3894
|
+
* - graph: shows the axes and the grid lines
|
|
3895
|
+
* - grid: shows only the grid lines
|
|
3896
|
+
* - none: shows no markings
|
|
3897
|
+
*/
|
|
3898
|
+
|
|
3899
|
+
const PerseusExpressionAnswerFormConsidered = ["correct", "wrong", "ungraded"];
|
|
3900
|
+
|
|
3901
|
+
// 2D range: xMin, xMax, yMin, yMax
|
|
3902
|
+
|
|
3903
|
+
const lockedFigureColorNames = ["blue", "green", "grayH", "purple", "pink", "orange", "red"];
|
|
3904
|
+
const lockedFigureColors = {
|
|
3905
|
+
blue: "#3D7586",
|
|
3906
|
+
green: "#447A53",
|
|
3907
|
+
grayH: "#3B3D45",
|
|
3908
|
+
purple: "#594094",
|
|
3909
|
+
pink: "#B25071",
|
|
3910
|
+
red: "#D92916",
|
|
3911
|
+
orange: "#946700"
|
|
3912
|
+
};
|
|
3913
|
+
const lockedFigureFillStyles = {
|
|
3914
|
+
none: 0,
|
|
3915
|
+
white: 1,
|
|
3916
|
+
translucent: 0.4,
|
|
3917
|
+
solid: 1
|
|
3918
|
+
};
|
|
3919
|
+
|
|
3920
|
+
// Not associated with a specific figure
|
|
3921
|
+
|
|
3922
|
+
const plotterPlotTypes = ["bar", "line", "pic", "histogram", "dotplot"];
|
|
3923
|
+
|
|
3924
|
+
// Used to represent 2-D points and ranges
|
|
3925
|
+
const pairOfNumbers = pair(number, number);
|
|
3926
|
+
const parsePerseusGraphTypeAngle = object({
|
|
3927
|
+
type: constant("angle"),
|
|
3928
|
+
showAngles: optional(boolean),
|
|
3929
|
+
allowReflexAngles: optional(boolean),
|
|
3930
|
+
angleOffsetDeg: optional(number),
|
|
3931
|
+
snapDegrees: optional(number),
|
|
3932
|
+
match: optional(constant("congruent")),
|
|
3933
|
+
coords: optional(trio(pairOfNumbers, pairOfNumbers, pairOfNumbers)),
|
|
3934
|
+
startCoords: optional(trio(pairOfNumbers, pairOfNumbers, pairOfNumbers))
|
|
3935
|
+
});
|
|
3936
|
+
const parsePerseusGraphTypeCircle = object({
|
|
3937
|
+
type: constant("circle"),
|
|
3938
|
+
center: optional(pairOfNumbers),
|
|
3939
|
+
radius: optional(number),
|
|
3940
|
+
startCoords: optional(object({
|
|
3941
|
+
center: pairOfNumbers,
|
|
3942
|
+
radius: number
|
|
3943
|
+
})),
|
|
3944
|
+
// TODO: remove coord? it's legacy.
|
|
3945
|
+
coord: optional(pairOfNumbers)
|
|
3946
|
+
});
|
|
3947
|
+
const parsePerseusGraphTypeLinear = object({
|
|
3948
|
+
type: constant("linear"),
|
|
3949
|
+
coords: optional(nullable(pair(pairOfNumbers, pairOfNumbers))),
|
|
3950
|
+
startCoords: optional(pair(pairOfNumbers, pairOfNumbers)),
|
|
3951
|
+
// TODO: remove coord? it's legacy.
|
|
3952
|
+
coord: optional(pairOfNumbers)
|
|
3953
|
+
});
|
|
3954
|
+
const parsePerseusGraphTypeLinearSystem = object({
|
|
3955
|
+
type: constant("linear-system"),
|
|
3956
|
+
// TODO(benchristel): default coords to empty array?
|
|
3957
|
+
coords: optional(nullable(array(pair(pairOfNumbers, pairOfNumbers)))),
|
|
3958
|
+
startCoords: optional(array(pair(pairOfNumbers, pairOfNumbers))),
|
|
3959
|
+
// TODO: remove coord? it's legacy.
|
|
3960
|
+
coord: optional(pairOfNumbers)
|
|
3961
|
+
});
|
|
3962
|
+
const parsePerseusGraphTypeNone = object({
|
|
3963
|
+
type: constant("none")
|
|
3964
|
+
});
|
|
3965
|
+
const parsePerseusGraphTypePoint = object({
|
|
3966
|
+
type: constant("point"),
|
|
3967
|
+
numPoints: optional(union(number).or(constant("unlimited")).parser),
|
|
3968
|
+
coords: optional(nullable(array(pairOfNumbers))),
|
|
3969
|
+
startCoords: optional(array(pairOfNumbers)),
|
|
3970
|
+
// TODO: remove coord? it's legacy.
|
|
3971
|
+
coord: optional(pairOfNumbers)
|
|
3972
|
+
});
|
|
3973
|
+
const parsePerseusGraphTypePolygon = object({
|
|
3974
|
+
type: constant("polygon"),
|
|
3975
|
+
numSides: optional(union(number).or(constant("unlimited")).parser),
|
|
3976
|
+
showAngles: optional(boolean),
|
|
3977
|
+
showSides: optional(boolean),
|
|
3978
|
+
snapTo: optional(enumeration("grid", "angles", "sides")),
|
|
3979
|
+
match: optional(enumeration("similar", "congruent", "approx", "exact")),
|
|
3980
|
+
startCoords: optional(array(pairOfNumbers)),
|
|
3981
|
+
// TODO: remove coord? it's legacy.
|
|
3982
|
+
coord: optional(pairOfNumbers)
|
|
3983
|
+
});
|
|
3984
|
+
const parsePerseusGraphTypeQuadratic = object({
|
|
3985
|
+
type: constant("quadratic"),
|
|
3986
|
+
coords: optional(nullable(trio(pairOfNumbers, pairOfNumbers, pairOfNumbers))),
|
|
3987
|
+
startCoords: optional(trio(pairOfNumbers, pairOfNumbers, pairOfNumbers)),
|
|
3988
|
+
// TODO: remove coord? it's legacy.
|
|
3989
|
+
coord: optional(pairOfNumbers)
|
|
3990
|
+
});
|
|
3991
|
+
const parsePerseusGraphTypeRay = object({
|
|
3992
|
+
type: constant("ray"),
|
|
3993
|
+
coords: optional(nullable(pair(pairOfNumbers, pairOfNumbers))),
|
|
3994
|
+
startCoords: optional(pair(pairOfNumbers, pairOfNumbers)),
|
|
3995
|
+
// TODO: remove coord? it's legacy.
|
|
3996
|
+
coord: optional(pairOfNumbers)
|
|
3997
|
+
});
|
|
3998
|
+
const parsePerseusGraphTypeSegment = object({
|
|
3999
|
+
type: constant("segment"),
|
|
4000
|
+
// TODO(benchristel): default numSegments?
|
|
4001
|
+
numSegments: optional(number),
|
|
4002
|
+
coords: optional(nullable(array(pair(pairOfNumbers, pairOfNumbers)))),
|
|
4003
|
+
startCoords: optional(array(pair(pairOfNumbers, pairOfNumbers))),
|
|
4004
|
+
// TODO: remove coord? it's legacy.
|
|
4005
|
+
coord: optional(pairOfNumbers)
|
|
4006
|
+
});
|
|
4007
|
+
const parsePerseusGraphTypeSinusoid = object({
|
|
4008
|
+
type: constant("sinusoid"),
|
|
4009
|
+
coords: optional(nullable(array(pairOfNumbers))),
|
|
4010
|
+
startCoords: optional(array(pairOfNumbers)),
|
|
4011
|
+
// TODO: remove coord? it's legacy.
|
|
4012
|
+
coord: optional(pairOfNumbers)
|
|
4013
|
+
});
|
|
4014
|
+
const parsePerseusGraphType = discriminatedUnionOn("type").withBranch("angle", parsePerseusGraphTypeAngle).withBranch("circle", parsePerseusGraphTypeCircle).withBranch("linear", parsePerseusGraphTypeLinear).withBranch("linear-system", parsePerseusGraphTypeLinearSystem).withBranch("none", parsePerseusGraphTypeNone).withBranch("point", parsePerseusGraphTypePoint).withBranch("polygon", parsePerseusGraphTypePolygon).withBranch("quadratic", parsePerseusGraphTypeQuadratic).withBranch("ray", parsePerseusGraphTypeRay).withBranch("segment", parsePerseusGraphTypeSegment).withBranch("sinusoid", parsePerseusGraphTypeSinusoid).parser;
|
|
4015
|
+
const parseLockedFigureColor = enumeration(...lockedFigureColorNames);
|
|
4016
|
+
const parseLockedFigureFillType = enumeration("none", "white", "translucent", "solid");
|
|
4017
|
+
const parseLockedLineStyle = enumeration("solid", "dashed");
|
|
4018
|
+
const parseLockedLabelType = object({
|
|
4019
|
+
type: constant("label"),
|
|
4020
|
+
coord: pairOfNumbers,
|
|
4021
|
+
text: string,
|
|
4022
|
+
color: parseLockedFigureColor,
|
|
4023
|
+
size: enumeration("small", "medium", "large")
|
|
4024
|
+
});
|
|
4025
|
+
const parseLockedPointType = object({
|
|
4026
|
+
type: constant("point"),
|
|
4027
|
+
coord: pairOfNumbers,
|
|
4028
|
+
color: parseLockedFigureColor,
|
|
4029
|
+
filled: boolean,
|
|
4030
|
+
// TODO(benchristel): default labels to empty array?
|
|
4031
|
+
labels: optional(array(parseLockedLabelType)),
|
|
4032
|
+
ariaLabel: optional(string)
|
|
4033
|
+
});
|
|
4034
|
+
const parseLockedLineType = object({
|
|
4035
|
+
type: constant("line"),
|
|
4036
|
+
kind: enumeration("line", "ray", "segment"),
|
|
4037
|
+
points: pair(parseLockedPointType, parseLockedPointType),
|
|
4038
|
+
color: parseLockedFigureColor,
|
|
4039
|
+
lineStyle: parseLockedLineStyle,
|
|
4040
|
+
showPoint1: defaulted(boolean, () => false),
|
|
4041
|
+
showPoint2: defaulted(boolean, () => false),
|
|
4042
|
+
// TODO(benchristel): default labels to empty array?
|
|
4043
|
+
labels: optional(array(parseLockedLabelType)),
|
|
4044
|
+
ariaLabel: optional(string)
|
|
4045
|
+
});
|
|
4046
|
+
const parseLockedVectorType = object({
|
|
4047
|
+
type: constant("vector"),
|
|
4048
|
+
points: pair(pairOfNumbers, pairOfNumbers),
|
|
4049
|
+
color: parseLockedFigureColor,
|
|
4050
|
+
// TODO(benchristel): default labels to empty array?
|
|
4051
|
+
labels: optional(array(parseLockedLabelType)),
|
|
4052
|
+
ariaLabel: optional(string)
|
|
4053
|
+
});
|
|
4054
|
+
const parseLockedEllipseType = object({
|
|
4055
|
+
type: constant("ellipse"),
|
|
4056
|
+
center: pairOfNumbers,
|
|
4057
|
+
radius: pairOfNumbers,
|
|
4058
|
+
angle: number,
|
|
4059
|
+
color: parseLockedFigureColor,
|
|
4060
|
+
fillStyle: parseLockedFigureFillType,
|
|
4061
|
+
strokeStyle: parseLockedLineStyle,
|
|
4062
|
+
// TODO(benchristel): default labels to empty array?
|
|
4063
|
+
labels: optional(array(parseLockedLabelType)),
|
|
4064
|
+
ariaLabel: optional(string)
|
|
4065
|
+
});
|
|
4066
|
+
const parseLockedPolygonType = object({
|
|
4067
|
+
type: constant("polygon"),
|
|
4068
|
+
points: array(pairOfNumbers),
|
|
4069
|
+
color: parseLockedFigureColor,
|
|
4070
|
+
showVertices: boolean,
|
|
4071
|
+
fillStyle: parseLockedFigureFillType,
|
|
4072
|
+
strokeStyle: parseLockedLineStyle,
|
|
4073
|
+
// TODO(benchristel): default labels to empty array?
|
|
4074
|
+
labels: optional(array(parseLockedLabelType)),
|
|
4075
|
+
ariaLabel: optional(string)
|
|
4076
|
+
});
|
|
4077
|
+
const parseLockedFunctionType = object({
|
|
4078
|
+
type: constant("function"),
|
|
4079
|
+
color: parseLockedFigureColor,
|
|
4080
|
+
strokeStyle: parseLockedLineStyle,
|
|
4081
|
+
equation: string,
|
|
4082
|
+
directionalAxis: enumeration("x", "y"),
|
|
4083
|
+
domain: optional(pairOfNumbers),
|
|
4084
|
+
// TODO(benchristel): default labels to empty array?
|
|
4085
|
+
labels: optional(array(parseLockedLabelType)),
|
|
4086
|
+
ariaLabel: optional(string)
|
|
4087
|
+
});
|
|
4088
|
+
const parseLockedFigure = discriminatedUnionOn("type").withBranch("point", parseLockedPointType).withBranch("line", parseLockedLineType).withBranch("vector", parseLockedVectorType).withBranch("ellipse", parseLockedEllipseType).withBranch("polygon", parseLockedPolygonType).withBranch("function", parseLockedFunctionType).withBranch("label", parseLockedLabelType).parser;
|
|
4089
|
+
const parseInteractiveGraphWidget = parseWidget(constant("interactive-graph"), object({
|
|
4090
|
+
step: pairOfNumbers,
|
|
4091
|
+
// TODO(benchristel): rather than making gridStep and snapStep
|
|
4092
|
+
// optional, we should duplicate the defaulting logic from the
|
|
4093
|
+
// InteractiveGraph component. See parse-perseus-json/README.md for
|
|
4094
|
+
// why.
|
|
4095
|
+
gridStep: optional(pairOfNumbers),
|
|
4096
|
+
snapStep: optional(pairOfNumbers),
|
|
4097
|
+
backgroundImage: optional(parsePerseusImageBackground),
|
|
4098
|
+
markings: enumeration("graph", "grid", "none"),
|
|
4099
|
+
labels: optional(array(string)),
|
|
4100
|
+
showProtractor: boolean,
|
|
4101
|
+
showRuler: optional(boolean),
|
|
4102
|
+
showTooltips: optional(boolean),
|
|
4103
|
+
rulerLabel: optional(string),
|
|
4104
|
+
rulerTicks: optional(number),
|
|
4105
|
+
range: pair(pairOfNumbers, pairOfNumbers),
|
|
4106
|
+
// NOTE(benchristel): I copied the default graph from
|
|
4107
|
+
// interactive-graph.tsx. See the parse-perseus-json/README.md for
|
|
4108
|
+
// an explanation of why we want to duplicate the default here.
|
|
4109
|
+
graph: defaulted(parsePerseusGraphType, () => ({
|
|
4110
|
+
type: "linear"
|
|
4111
|
+
})),
|
|
4112
|
+
correct: parsePerseusGraphType,
|
|
4113
|
+
// TODO(benchristel): default lockedFigures to empty array
|
|
4114
|
+
lockedFigures: optional(array(parseLockedFigure)),
|
|
4115
|
+
fullGraphLabel: optional(string),
|
|
4116
|
+
fullGraphAriaDescription: optional(string)
|
|
4117
|
+
}));
|
|
4118
|
+
|
|
4119
|
+
const parseLabelImageWidget = parseWidget(constant("label-image"), object({
|
|
4120
|
+
choices: array(string),
|
|
4121
|
+
imageUrl: string,
|
|
4122
|
+
imageAlt: string,
|
|
4123
|
+
imageHeight: number,
|
|
4124
|
+
imageWidth: number,
|
|
4125
|
+
markers: array(object({
|
|
4126
|
+
answers: array(string),
|
|
4127
|
+
label: string,
|
|
4128
|
+
x: number,
|
|
4129
|
+
y: number
|
|
4130
|
+
})),
|
|
4131
|
+
hideChoicesFromInstructions: boolean,
|
|
4132
|
+
multipleAnswers: boolean,
|
|
4133
|
+
static: defaulted(boolean, () => false)
|
|
4134
|
+
}));
|
|
4135
|
+
|
|
4136
|
+
const parseMatcherWidget = parseWidget(constant("matcher"), object({
|
|
4137
|
+
labels: array(string),
|
|
4138
|
+
left: array(string),
|
|
4139
|
+
right: array(string),
|
|
4140
|
+
orderMatters: boolean,
|
|
4141
|
+
padding: boolean
|
|
4142
|
+
}));
|
|
4143
|
+
|
|
4144
|
+
const numberOrString = union(number).or(string).parser;
|
|
4145
|
+
const numeric = pipeParsers(defaulted(numberOrString, () => NaN)).then(stringToNumber).parser;
|
|
4146
|
+
const parseMatrixWidget = parseWidget(defaulted(constant("matrix"), () => "matrix"), object({
|
|
4147
|
+
prefix: optional(string),
|
|
4148
|
+
suffix: optional(string),
|
|
4149
|
+
answers: array(array(numeric)),
|
|
4150
|
+
cursorPosition: optional(array(number)),
|
|
4151
|
+
matrixBoardSize: array(number),
|
|
4152
|
+
static: optional(boolean)
|
|
4153
|
+
}));
|
|
4154
|
+
|
|
4155
|
+
const parseMeasurerWidget = parseWidget(constant("measurer"), object({
|
|
4156
|
+
// The default value for image comes from measurer.tsx.
|
|
4157
|
+
// See parse-perseus-json/README.md for why we want to duplicate the
|
|
4158
|
+
// defaults here.
|
|
4159
|
+
image: defaulted(parsePerseusImageBackground, () => ({
|
|
4160
|
+
url: null,
|
|
4161
|
+
top: 0,
|
|
4162
|
+
left: 0
|
|
4163
|
+
})),
|
|
4164
|
+
showProtractor: boolean,
|
|
4165
|
+
showRuler: boolean,
|
|
4166
|
+
rulerLabel: string,
|
|
4167
|
+
rulerTicks: number,
|
|
4168
|
+
rulerPixels: number,
|
|
4169
|
+
rulerLength: number,
|
|
4170
|
+
box: pair(number, number),
|
|
4171
|
+
// TODO(benchristel): static is not used. Remove it?
|
|
4172
|
+
static: defaulted(boolean, () => false)
|
|
4173
|
+
}));
|
|
4174
|
+
|
|
4175
|
+
const parseMoleculeRendererWidget = parseWidget(constant("molecule-renderer"), object({
|
|
4176
|
+
widgetId: string,
|
|
4177
|
+
rotationAngle: optional(number),
|
|
4178
|
+
smiles: optional(string)
|
|
4179
|
+
}));
|
|
4180
|
+
|
|
4181
|
+
const emptyStringToNull = pipeParsers(constant("")).then(convert(() => null)).parser;
|
|
4182
|
+
const parseNumberLineWidget = parseWidget(constant("number-line"), object({
|
|
4183
|
+
range: array(number),
|
|
4184
|
+
labelRange: array(nullable(union(number).or(emptyStringToNull).parser)),
|
|
4185
|
+
labelStyle: string,
|
|
4186
|
+
labelTicks: boolean,
|
|
4187
|
+
isTickCtrl: optional(nullable(boolean)),
|
|
4188
|
+
divisionRange: array(number),
|
|
4189
|
+
numDivisions: optional(nullable(number)),
|
|
4190
|
+
// NOTE(benchristel): I copied the default snapDivisions from
|
|
4191
|
+
// number-line.tsx. See the parse-perseus-json/README.md for
|
|
4192
|
+
// an explanation of why we want to duplicate the default here.
|
|
4193
|
+
snapDivisions: defaulted(number, () => 2),
|
|
4194
|
+
tickStep: optional(nullable(number)),
|
|
4195
|
+
correctRel: optional(nullable(string)),
|
|
4196
|
+
correctX: nullable(number),
|
|
4197
|
+
initialX: optional(nullable(number)),
|
|
4198
|
+
showTooltips: optional(boolean),
|
|
4199
|
+
static: defaulted(boolean, () => false)
|
|
4200
|
+
}));
|
|
4201
|
+
|
|
4202
|
+
const parseMathFormat = enumeration("integer", "mixed", "improper", "proper", "decimal", "percent", "pi");
|
|
4203
|
+
const parseNumericInputWidget = parseWidget(constant("numeric-input"), object({
|
|
4204
|
+
answers: array(object({
|
|
4205
|
+
message: string,
|
|
4206
|
+
// TODO(benchristel): value should never be null or undefined,
|
|
4207
|
+
// but we have some content where it is anyway. If we backfill
|
|
4208
|
+
// the data, simplify this.
|
|
4209
|
+
value: optional(nullable(number)),
|
|
4210
|
+
status: string,
|
|
4211
|
+
answerForms: optional(array(parseMathFormat)),
|
|
4212
|
+
strict: boolean,
|
|
4213
|
+
maxError: optional(nullable(number)),
|
|
4214
|
+
// TODO(benchristel): simplify should never be a boolean, but we
|
|
4215
|
+
// have some content where it is anyway. If we ever backfill
|
|
4216
|
+
// the data, we should simplify `simplify`.
|
|
4217
|
+
simplify: optional(nullable(union(string).or(pipeParsers(boolean).then(convert(String)).parser).parser))
|
|
4218
|
+
})),
|
|
4219
|
+
labelText: optional(string),
|
|
4220
|
+
size: string,
|
|
4221
|
+
coefficient: defaulted(boolean, () => false),
|
|
4222
|
+
rightAlign: optional(boolean),
|
|
4223
|
+
static: defaulted(boolean, () => false),
|
|
4224
|
+
answerForms: optional(array(object({
|
|
4225
|
+
name: parseMathFormat,
|
|
4226
|
+
simplify: optional(nullable(enumeration("required", "correct", "enforced", "optional")))
|
|
4227
|
+
})))
|
|
4228
|
+
}));
|
|
4229
|
+
|
|
4230
|
+
// There is an import cycle between orderer-widget.ts and perseus-renderer.ts.
|
|
4231
|
+
// This wrapper ensures that we don't refer to parsePerseusRenderer before
|
|
4232
|
+
// it's defined.
|
|
4233
|
+
function parseRenderer(rawValue, ctx) {
|
|
4234
|
+
return parsePerseusRenderer(rawValue, ctx);
|
|
4235
|
+
}
|
|
4236
|
+
const largeToAuto = (height, ctx) => {
|
|
4237
|
+
if (height === "large") {
|
|
4238
|
+
return ctx.success("auto");
|
|
4239
|
+
}
|
|
4240
|
+
return ctx.success(height);
|
|
4241
|
+
};
|
|
4242
|
+
const parseOrdererWidget = parseWidget(constant("orderer"), object({
|
|
4243
|
+
options: defaulted(array(parseRenderer), () => []),
|
|
4244
|
+
correctOptions: array(parseRenderer),
|
|
4245
|
+
otherOptions: array(parseRenderer),
|
|
4246
|
+
height: pipeParsers(enumeration("normal", "auto", "large")).then(largeToAuto).parser,
|
|
4247
|
+
layout: defaulted(enumeration("horizontal", "vertical"), () => "horizontal")
|
|
4248
|
+
}));
|
|
4249
|
+
|
|
4250
|
+
const parsePassageRefWidget = parseWidget(constant("passage-ref"), object({
|
|
4251
|
+
passageNumber: number,
|
|
4252
|
+
referenceNumber: number,
|
|
4253
|
+
summaryText: optional(string)
|
|
4254
|
+
}));
|
|
4255
|
+
|
|
4256
|
+
const parsePassageWidget = parseWidget(constant("passage"), object({
|
|
4257
|
+
footnotes: defaulted(string, () => ""),
|
|
4258
|
+
passageText: string,
|
|
4259
|
+
passageTitle: defaulted(string, () => ""),
|
|
4260
|
+
showLineNumbers: boolean,
|
|
4261
|
+
static: defaulted(boolean, () => false)
|
|
4262
|
+
}));
|
|
4263
|
+
|
|
4264
|
+
const parsePhetSimulationWidget = parseWidget(constant("phet-simulation"), object({
|
|
4265
|
+
url: string,
|
|
4266
|
+
description: string
|
|
4267
|
+
}));
|
|
4268
|
+
|
|
4269
|
+
const parsePlotterWidget = parseWidget(constant("plotter"), object({
|
|
4270
|
+
labels: array(string),
|
|
4271
|
+
categories: array(string),
|
|
4272
|
+
type: enumeration(...plotterPlotTypes),
|
|
4273
|
+
maxY: number,
|
|
4274
|
+
// The default value for scaleY comes from plotter.tsx.
|
|
4275
|
+
// See parse-perseus-json/README.md for why we want to duplicate the
|
|
4276
|
+
// defaults here.
|
|
4277
|
+
scaleY: defaulted(number, () => 1),
|
|
4278
|
+
labelInterval: optional(nullable(number)),
|
|
4279
|
+
// The default value for snapsPerLine comes from plotter.tsx.
|
|
4280
|
+
// See parse-perseus-json/README.md for why we want to duplicate the
|
|
4281
|
+
// defaults here.
|
|
4282
|
+
snapsPerLine: defaulted(number, () => 2),
|
|
4283
|
+
starting: array(number),
|
|
4284
|
+
correct: array(number),
|
|
4285
|
+
picUrl: optional(nullable(string)),
|
|
4286
|
+
picSize: optional(nullable(number)),
|
|
4287
|
+
picBoxHeight: optional(nullable(number)),
|
|
4288
|
+
// NOTE(benchristel): I copied the default plotDimensions from
|
|
4289
|
+
// plotter.tsx. See the parse-perseus-json/README.md for an explanation
|
|
4290
|
+
// of why we want to duplicate the defaults here.
|
|
4291
|
+
plotDimensions: defaulted(array(number), () => [380, 300])
|
|
4292
|
+
}));
|
|
4293
|
+
|
|
4294
|
+
const parsePythonProgramWidget = parseWidget(constant("python-program"), object({
|
|
4295
|
+
programID: string,
|
|
4296
|
+
height: number
|
|
4297
|
+
}));
|
|
4298
|
+
|
|
4299
|
+
const parseRadioWidget = parseWidget(constant("radio"), object({
|
|
4300
|
+
choices: array(object({
|
|
4301
|
+
content: defaulted(string, () => ""),
|
|
4302
|
+
clue: optional(string),
|
|
4303
|
+
correct: optional(boolean),
|
|
4304
|
+
isNoneOfTheAbove: optional(boolean),
|
|
4305
|
+
// deprecated
|
|
4306
|
+
// There is an import cycle between radio-widget.ts and
|
|
4307
|
+
// widgets-map.ts. The anonymous function below ensures that we
|
|
4308
|
+
// don't refer to parseWidgetsMap before it's defined.
|
|
4309
|
+
widgets: optional((rawVal, ctx) => parseWidgetsMap(rawVal, ctx))
|
|
4310
|
+
})),
|
|
4311
|
+
hasNoneOfTheAbove: optional(boolean),
|
|
4312
|
+
countChoices: optional(boolean),
|
|
4313
|
+
randomize: optional(boolean),
|
|
4314
|
+
multipleSelect: optional(boolean),
|
|
4315
|
+
deselectEnabled: optional(boolean),
|
|
4316
|
+
// deprecated
|
|
4317
|
+
onePerLine: optional(boolean),
|
|
4318
|
+
// deprecated
|
|
4319
|
+
displayCount: optional(any),
|
|
4320
|
+
// v0 props
|
|
4321
|
+
// `noneOfTheAbove` is still in use (but only set to `false`).
|
|
4322
|
+
noneOfTheAbove: optional(constant(false))
|
|
4323
|
+
}));
|
|
4324
|
+
|
|
4325
|
+
const parseSorterWidget = parseWidget(constant("sorter"), object({
|
|
4326
|
+
correct: array(string),
|
|
4327
|
+
padding: boolean,
|
|
4328
|
+
layout: enumeration("horizontal", "vertical")
|
|
4329
|
+
}));
|
|
4330
|
+
|
|
4331
|
+
const parseTableWidget = parseWidget(constant("table"), object({
|
|
4332
|
+
headers: array(string),
|
|
4333
|
+
rows: number,
|
|
4334
|
+
columns: number,
|
|
4335
|
+
answers: array(array(string))
|
|
4336
|
+
}));
|
|
4337
|
+
|
|
4338
|
+
const parseVideoWidget = parseWidget(constant("video"), object({
|
|
4339
|
+
location: string,
|
|
4340
|
+
static: optional(boolean)
|
|
4341
|
+
}));
|
|
4342
|
+
|
|
4343
|
+
const parseWidgetsMap = (rawValue, ctx) => {
|
|
4344
|
+
if (!isObject(rawValue)) {
|
|
4345
|
+
return ctx.failure("PerseusWidgetsMap", rawValue);
|
|
4346
|
+
}
|
|
4347
|
+
const widgetsMap = {};
|
|
4348
|
+
for (const key of Object.keys(rawValue)) {
|
|
4349
|
+
// parseWidgetsMapEntry modifies the widgetsMap. This is kind of gross,
|
|
4350
|
+
// but it's the only way I could find to make TypeScript check the key
|
|
4351
|
+
// against the widget type.
|
|
4352
|
+
const entryResult = parseWidgetsMapEntry([key, rawValue[key]], widgetsMap, ctx.forSubtree(key));
|
|
4353
|
+
if (isFailure(entryResult)) {
|
|
4354
|
+
return entryResult;
|
|
4355
|
+
}
|
|
4356
|
+
}
|
|
4357
|
+
return ctx.success(widgetsMap);
|
|
4358
|
+
};
|
|
4359
|
+
const parseWidgetsMapEntry = ([id, widget], widgetMap, ctx) => {
|
|
4360
|
+
const idComponentsResult = parseWidgetIdComponents(id.split(" "), ctx.forSubtree("(widget ID)"));
|
|
4361
|
+
if (isFailure(idComponentsResult)) {
|
|
4362
|
+
return idComponentsResult;
|
|
4363
|
+
}
|
|
4364
|
+
const [type, n] = idComponentsResult.value;
|
|
4365
|
+
function parseAndAssign(key, parse) {
|
|
4366
|
+
const widgetResult = parse(widget, ctx);
|
|
4367
|
+
if (isFailure(widgetResult)) {
|
|
4368
|
+
return widgetResult;
|
|
4369
|
+
}
|
|
4370
|
+
widgetMap[key] = widgetResult.value;
|
|
4371
|
+
return ctx.success(undefined);
|
|
4372
|
+
}
|
|
4373
|
+
switch (type) {
|
|
4374
|
+
case "categorizer":
|
|
4375
|
+
return parseAndAssign(`categorizer ${n}`, parseCategorizerWidget);
|
|
4376
|
+
case "cs-program":
|
|
4377
|
+
return parseAndAssign(`cs-program ${n}`, parseCSProgramWidget);
|
|
4378
|
+
case "definition":
|
|
4379
|
+
return parseAndAssign(`definition ${n}`, parseDefinitionWidget);
|
|
4380
|
+
case "dropdown":
|
|
4381
|
+
return parseAndAssign(`dropdown ${n}`, parseDropdownWidget);
|
|
4382
|
+
case "explanation":
|
|
4383
|
+
return parseAndAssign(`explanation ${n}`, parseExplanationWidget);
|
|
4384
|
+
case "expression":
|
|
4385
|
+
return parseAndAssign(`expression ${n}`, parseExpressionWidget);
|
|
4386
|
+
case "grapher":
|
|
4387
|
+
return parseAndAssign(`grapher ${n}`, parseGrapherWidget);
|
|
4388
|
+
case "group":
|
|
4389
|
+
return parseAndAssign(`group ${n}`, parseGroupWidget);
|
|
4390
|
+
case "graded-group":
|
|
4391
|
+
return parseAndAssign(`graded-group ${n}`, parseGradedGroupWidget);
|
|
4392
|
+
case "graded-group-set":
|
|
4393
|
+
return parseAndAssign(`graded-group-set ${n}`, parseGradedGroupSetWidget);
|
|
4394
|
+
case "iframe":
|
|
4395
|
+
return parseAndAssign(`iframe ${n}`, parseIframeWidget);
|
|
4396
|
+
case "image":
|
|
4397
|
+
return parseAndAssign(`image ${n}`, parseImageWidget);
|
|
4398
|
+
case "input-number":
|
|
4399
|
+
return parseAndAssign(`input-number ${n}`, parseInputNumberWidget);
|
|
4400
|
+
case "interaction":
|
|
4401
|
+
return parseAndAssign(`interaction ${n}`, parseInteractionWidget);
|
|
4402
|
+
case "interactive-graph":
|
|
4403
|
+
return parseAndAssign(`interactive-graph ${n}`, parseInteractiveGraphWidget);
|
|
4404
|
+
case "label-image":
|
|
4405
|
+
return parseAndAssign(`label-image ${n}`, parseLabelImageWidget);
|
|
4406
|
+
case "matcher":
|
|
4407
|
+
return parseAndAssign(`matcher ${n}`, parseMatcherWidget);
|
|
4408
|
+
case "matrix":
|
|
4409
|
+
return parseAndAssign(`matrix ${n}`, parseMatrixWidget);
|
|
4410
|
+
case "measurer":
|
|
4411
|
+
return parseAndAssign(`measurer ${n}`, parseMeasurerWidget);
|
|
4412
|
+
case "molecule-renderer":
|
|
4413
|
+
return parseAndAssign(`molecule-renderer ${n}`, parseMoleculeRendererWidget);
|
|
4414
|
+
case "number-line":
|
|
4415
|
+
return parseAndAssign(`number-line ${n}`, parseNumberLineWidget);
|
|
4416
|
+
case "numeric-input":
|
|
4417
|
+
return parseAndAssign(`numeric-input ${n}`, parseNumericInputWidget);
|
|
4418
|
+
case "orderer":
|
|
4419
|
+
return parseAndAssign(`orderer ${n}`, parseOrdererWidget);
|
|
4420
|
+
case "passage":
|
|
4421
|
+
return parseAndAssign(`passage ${n}`, parsePassageWidget);
|
|
4422
|
+
case "passage-ref":
|
|
4423
|
+
return parseAndAssign(`passage-ref ${n}`, parsePassageRefWidget);
|
|
4424
|
+
case "passage-ref-target":
|
|
4425
|
+
// NOTE(benchristel): as of 2024-11-12, passage-ref-target is only
|
|
4426
|
+
// used in test content. See:
|
|
4427
|
+
// https://www.khanacademy.org/devadmin/content/search?query=widget:passage-ref-target
|
|
4428
|
+
return parseAndAssign(`passage-ref-target ${n}`, any);
|
|
4429
|
+
case "phet-simulation":
|
|
4430
|
+
return parseAndAssign(`phet-simulation ${n}`, parsePhetSimulationWidget);
|
|
4431
|
+
case "plotter":
|
|
4432
|
+
return parseAndAssign(`plotter ${n}`, parsePlotterWidget);
|
|
4433
|
+
case "python-program":
|
|
4434
|
+
return parseAndAssign(`python-program ${n}`, parsePythonProgramWidget);
|
|
4435
|
+
case "radio":
|
|
4436
|
+
return parseAndAssign(`radio ${n}`, parseRadioWidget);
|
|
4437
|
+
case "sorter":
|
|
4438
|
+
return parseAndAssign(`sorter ${n}`, parseSorterWidget);
|
|
4439
|
+
case "table":
|
|
4440
|
+
return parseAndAssign(`table ${n}`, parseTableWidget);
|
|
4441
|
+
case "video":
|
|
4442
|
+
return parseAndAssign(`video ${n}`, parseVideoWidget);
|
|
4443
|
+
case "sequence":
|
|
4444
|
+
// sequence is a deprecated widget type, and the corresponding
|
|
4445
|
+
// widget component no longer exists.
|
|
4446
|
+
return parseAndAssign(`sequence ${n}`, parseDeprecatedWidget);
|
|
4447
|
+
case "lights-puzzle":
|
|
4448
|
+
return parseAndAssign(`lights-puzzle ${n}`, parseDeprecatedWidget);
|
|
4449
|
+
case "simulator":
|
|
4450
|
+
return parseAndAssign(`simulator ${n}`, parseDeprecatedWidget);
|
|
4451
|
+
case "transformer":
|
|
4452
|
+
return parseAndAssign(`transformer ${n}`, parseDeprecatedWidget);
|
|
4453
|
+
default:
|
|
4454
|
+
return parseAndAssign(`${type} ${n}`, parseWidget(constant(type), any));
|
|
4455
|
+
}
|
|
4456
|
+
};
|
|
4457
|
+
const parseDeprecatedWidget = parseWidget(
|
|
4458
|
+
// Ignore the incoming widget type and hardcode "deprecated-standin"
|
|
4459
|
+
(_, ctx) => ctx.success("deprecated-standin"),
|
|
4460
|
+
// Allow any widget options
|
|
4461
|
+
object({}));
|
|
4462
|
+
const parseStringToPositiveInt = (rawValue, ctx) => {
|
|
4463
|
+
if (typeof rawValue !== "string" || !/^[1-9][0-9]*$/.test(rawValue)) {
|
|
4464
|
+
return ctx.failure("a string representing a positive integer", rawValue);
|
|
4465
|
+
}
|
|
4466
|
+
return ctx.success(+rawValue);
|
|
4467
|
+
};
|
|
4468
|
+
const parseWidgetIdComponents = pair(string, parseStringToPositiveInt);
|
|
4469
|
+
|
|
4470
|
+
const parsePerseusRenderer = defaulted(object({
|
|
4471
|
+
// TODO(benchristel): content is also defaulted to empty string in
|
|
4472
|
+
// renderer.tsx. See if we can remove one default or the other.
|
|
4473
|
+
content: defaulted(string, () => ""),
|
|
4474
|
+
// This module has an import cycle with parseWidgetsMap, because the
|
|
4475
|
+
// `group` widget can contain another renderer.
|
|
4476
|
+
// The anonymous function below ensures that we don't try to access
|
|
4477
|
+
// parseWidgetsMap before it's defined.
|
|
4478
|
+
widgets: defaulted((rawVal, ctx) => parseWidgetsMap(rawVal, ctx), () => ({})),
|
|
4479
|
+
metadata: optional(array(string)),
|
|
4480
|
+
images: parseImages
|
|
4481
|
+
}),
|
|
4482
|
+
// Default value
|
|
4483
|
+
() => ({
|
|
4484
|
+
content: "",
|
|
4485
|
+
widgets: {},
|
|
4486
|
+
images: {}
|
|
4487
|
+
}));
|
|
4488
|
+
|
|
4489
|
+
const parsePerseusArticle = union(parsePerseusRenderer).or(array(parsePerseusRenderer)).parser;
|
|
4490
|
+
|
|
4491
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
4492
|
+
if (null == r) return {};
|
|
4493
|
+
var t = {};
|
|
4494
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
4495
|
+
if (e.includes(n)) continue;
|
|
4496
|
+
t[n] = r[n];
|
|
4497
|
+
}
|
|
4498
|
+
return t;
|
|
4499
|
+
}
|
|
4500
|
+
|
|
4501
|
+
const parseHint = object({
|
|
4502
|
+
replace: optional(boolean),
|
|
4503
|
+
content: string,
|
|
4504
|
+
widgets: defaulted(parseWidgetsMap, () => ({})),
|
|
4505
|
+
metadata: optional(array(string)),
|
|
4506
|
+
images: parseImages
|
|
4507
|
+
});
|
|
2353
4508
|
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
4509
|
+
const _excluded$2 = ["type", "options"];
|
|
4510
|
+
const parsePerseusItem$1 = object({
|
|
4511
|
+
question: parsePerseusRenderer,
|
|
4512
|
+
hints: defaulted(array(parseHint), () => []),
|
|
4513
|
+
answerArea: pipeParsers(defaulted(object({}), () => ({}))).then(migrateAnswerArea).then(record(enumeration(...ItemExtras), boolean)).parser,
|
|
4514
|
+
itemDataVersion: optional(object({
|
|
4515
|
+
major: number,
|
|
4516
|
+
minor: number
|
|
4517
|
+
})),
|
|
4518
|
+
// Deprecated field
|
|
4519
|
+
answer: any
|
|
4520
|
+
});
|
|
4521
|
+
|
|
4522
|
+
// Some answerAreas have extra fields, like:
|
|
4523
|
+
//
|
|
4524
|
+
// "answerArea": {
|
|
4525
|
+
// "type": "multiple",
|
|
4526
|
+
// "options": {
|
|
4527
|
+
// "content": "",
|
|
4528
|
+
// "images": {},
|
|
4529
|
+
// "widgets": {}
|
|
4530
|
+
// }
|
|
4531
|
+
// }
|
|
4532
|
+
//
|
|
4533
|
+
// The "type" and "options" fields don't seem to be used anywhere. This
|
|
4534
|
+
// migration function removes them.
|
|
4535
|
+
function migrateAnswerArea(rawValue, ctx) {
|
|
4536
|
+
const rest = _objectWithoutPropertiesLoose(rawValue, _excluded$2);
|
|
4537
|
+
return ctx.success(rest);
|
|
4538
|
+
}
|
|
4539
|
+
|
|
4540
|
+
/**
|
|
4541
|
+
* Helper to parse PerseusItem JSON
|
|
4542
|
+
* Why not just use JSON.parse? We want:
|
|
4543
|
+
* - To make sure types are correct
|
|
4544
|
+
* - To give us a central place to validate/transform output if needed
|
|
4545
|
+
* @deprecated - use parseAndMigratePerseusItem instead
|
|
4546
|
+
* @param {string} json - the stringified PerseusItem JSON
|
|
4547
|
+
* @returns {PerseusItem} the parsed PerseusItem object
|
|
4548
|
+
*/
|
|
4549
|
+
function parsePerseusItem(json) {
|
|
4550
|
+
// Try to block a cheating vector which relies on monkey-patching
|
|
4551
|
+
// JSON.parse
|
|
4552
|
+
if (isRealJSONParse(JSON.parse)) {
|
|
4553
|
+
return JSON.parse(json);
|
|
4554
|
+
}
|
|
4555
|
+
throw new Error("Something went wrong.");
|
|
4556
|
+
}
|
|
4557
|
+
/**
|
|
4558
|
+
* Parses a PerseusItem from a JSON string, migrates old formats to the latest
|
|
4559
|
+
* schema, and runtime-typechecks the result. Use this to parse assessmentItem
|
|
4560
|
+
* data.
|
|
4561
|
+
*
|
|
4562
|
+
* @returns a {@link Result} of the parsed PerseusItem. If the result is a
|
|
4563
|
+
* failure, it will contain an error message describing where in the tree
|
|
4564
|
+
* parsing failed.
|
|
4565
|
+
* @throws SyntaxError if the argument is not well-formed JSON.
|
|
4566
|
+
*/
|
|
4567
|
+
function parseAndMigratePerseusItem(json) {
|
|
4568
|
+
throwErrorIfCheatingDetected();
|
|
4569
|
+
const object = JSON.parse(json);
|
|
4570
|
+
const result = parse(object, parsePerseusItem$1);
|
|
4571
|
+
if (isFailure(result)) {
|
|
4572
|
+
return failure({
|
|
4573
|
+
message: result.detail,
|
|
4574
|
+
invalidObject: object
|
|
4575
|
+
});
|
|
4576
|
+
}
|
|
4577
|
+
return result;
|
|
4578
|
+
}
|
|
4579
|
+
|
|
4580
|
+
/**
|
|
4581
|
+
* Parses a PerseusArticle from a JSON string, migrates old formats to the
|
|
4582
|
+
* latest schema, and runtime-typechecks the result.
|
|
4583
|
+
*
|
|
4584
|
+
* @returns a {@link Result} of the parsed PerseusArticle. If the result is a
|
|
4585
|
+
* failure, it will contain an error message describing where in the tree
|
|
4586
|
+
* parsing failed.
|
|
4587
|
+
* @throws SyntaxError if the argument is not well-formed JSON.
|
|
4588
|
+
*/
|
|
4589
|
+
function parseAndMigratePerseusArticle(json) {
|
|
4590
|
+
throwErrorIfCheatingDetected();
|
|
4591
|
+
const object = JSON.parse(json);
|
|
4592
|
+
const result = parse(object, parsePerseusArticle);
|
|
4593
|
+
if (isFailure(result)) {
|
|
4594
|
+
return failure({
|
|
4595
|
+
message: result.detail,
|
|
4596
|
+
invalidObject: object
|
|
4597
|
+
});
|
|
4598
|
+
}
|
|
4599
|
+
return result;
|
|
4600
|
+
}
|
|
4601
|
+
|
|
4602
|
+
/**
|
|
4603
|
+
* Tries to block a cheating vector that relies on monkey-patching JSON.parse.
|
|
4604
|
+
*/
|
|
4605
|
+
// TODO(LEMS-2331): delete this function once server-side scoring is done.
|
|
4606
|
+
function throwErrorIfCheatingDetected() {
|
|
4607
|
+
if (!isRealJSONParse(JSON.parse)) {
|
|
4608
|
+
throw new Error("Something went wrong.");
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4611
|
+
|
|
4612
|
+
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
4613
|
+
const libName = "@khanacademy/perseus-core";
|
|
4614
|
+
const libVersion = "3.3.0";
|
|
4615
|
+
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
4616
|
+
|
|
4617
|
+
/**
|
|
4618
|
+
* @typedef {Object} Errors utility for referencing the Perseus error taxonomy.
|
|
4619
|
+
*/
|
|
4620
|
+
const Errors = Object.freeze({
|
|
4621
|
+
/**
|
|
4622
|
+
* @property {ErrorKind} Unknown The kind of error is not known.
|
|
4623
|
+
*/
|
|
4624
|
+
Unknown: "Unknown",
|
|
4625
|
+
/**
|
|
4626
|
+
* @property {ErrorKind} Internal The error is internal to the executing code.
|
|
4627
|
+
*/
|
|
4628
|
+
Internal: "Internal",
|
|
4629
|
+
/**
|
|
4630
|
+
* @property {ErrorKind} InvalidInput There was a problem with the provided
|
|
4631
|
+
* input, such as the wrong format or a null value.
|
|
4632
|
+
*/
|
|
4633
|
+
InvalidInput: "InvalidInput",
|
|
4634
|
+
/**
|
|
4635
|
+
* @property {ErrorKind} NotAllowed There was a problem due to the state of
|
|
4636
|
+
* the system not matching the requested operation or input. For example,
|
|
4637
|
+
* trying to create a username that is valid, but is already taken by
|
|
4638
|
+
* another user. Use {@link InvalidInput} instead when the input isn't
|
|
4639
|
+
* valid regardless of the state of the system. Use {@link NotFound} when
|
|
4640
|
+
* the failure is due to not being able to find a resource.
|
|
4641
|
+
*/
|
|
4642
|
+
NotAllowed: "NotAllowed",
|
|
4643
|
+
/**
|
|
4644
|
+
* @property {ErrorKind} TransientService There was a problem when making a
|
|
4645
|
+
* request to a service.
|
|
4646
|
+
*/
|
|
4647
|
+
TransientService: "TransientService",
|
|
4648
|
+
/**
|
|
4649
|
+
* @property {ErrorKind} Service There was a non-transient problem when
|
|
4650
|
+
* making a request to service.
|
|
4651
|
+
*/
|
|
4652
|
+
Service: "Service"
|
|
4653
|
+
});
|
|
4654
|
+
|
|
4655
|
+
/**
|
|
4656
|
+
* @type {ErrorKind} The kind of error being reported
|
|
4657
|
+
*/
|
|
4658
|
+
|
|
4659
|
+
class PerseusError extends Error {
|
|
4660
|
+
constructor(message, kind, options) {
|
|
4661
|
+
super(message);
|
|
4662
|
+
this.kind = void 0;
|
|
4663
|
+
this.metadata = void 0;
|
|
4664
|
+
this.kind = kind;
|
|
4665
|
+
this.metadata = options == null ? void 0 : options.metadata;
|
|
4666
|
+
}
|
|
4667
|
+
}
|
|
2358
4668
|
|
|
2359
4669
|
/**
|
|
2360
4670
|
* _ utilities for objects
|
|
@@ -2400,5 +4710,551 @@ const mapObject = function mapObject(obj, lambda) {
|
|
|
2400
4710
|
return result;
|
|
2401
4711
|
};
|
|
2402
4712
|
|
|
2403
|
-
|
|
4713
|
+
const defaultWidgetOptions$u = {
|
|
4714
|
+
items: [],
|
|
4715
|
+
categories: [],
|
|
4716
|
+
values: [],
|
|
4717
|
+
randomizeItems: false
|
|
4718
|
+
};
|
|
4719
|
+
const categorizerWidgetLogic = {
|
|
4720
|
+
name: "categorizer",
|
|
4721
|
+
defaultWidgetOptions: defaultWidgetOptions$u
|
|
4722
|
+
};
|
|
4723
|
+
|
|
4724
|
+
const DEFAULT_HEIGHT = 400;
|
|
4725
|
+
const defaultWidgetOptions$t = {
|
|
4726
|
+
programID: "",
|
|
4727
|
+
programType: null,
|
|
4728
|
+
settings: [{
|
|
4729
|
+
name: "",
|
|
4730
|
+
value: ""
|
|
4731
|
+
}],
|
|
4732
|
+
showEditor: false,
|
|
4733
|
+
showButtons: false,
|
|
4734
|
+
height: DEFAULT_HEIGHT
|
|
4735
|
+
};
|
|
4736
|
+
const csProgramWidgetLogic = {
|
|
4737
|
+
name: "cs-program",
|
|
4738
|
+
defaultWidgetOptions: defaultWidgetOptions$t
|
|
4739
|
+
};
|
|
4740
|
+
|
|
4741
|
+
const defaultWidgetOptions$s = {
|
|
4742
|
+
togglePrompt: "",
|
|
4743
|
+
definition: ""
|
|
4744
|
+
};
|
|
4745
|
+
const definitionWidgetLogic = {
|
|
4746
|
+
name: "definition",
|
|
4747
|
+
defaultWidgetOptions: defaultWidgetOptions$s
|
|
4748
|
+
};
|
|
4749
|
+
|
|
4750
|
+
const defaultWidgetOptions$r = {
|
|
4751
|
+
placeholder: "",
|
|
4752
|
+
choices: [{
|
|
4753
|
+
content: "",
|
|
4754
|
+
correct: false
|
|
4755
|
+
}]
|
|
4756
|
+
};
|
|
4757
|
+
const dropdownWidgetLogic = {
|
|
4758
|
+
name: "definition",
|
|
4759
|
+
defaultWidgetOptions: defaultWidgetOptions$r
|
|
4760
|
+
};
|
|
4761
|
+
|
|
4762
|
+
const defaultWidgetOptions$q = {
|
|
4763
|
+
showPrompt: "Explain",
|
|
4764
|
+
hidePrompt: "Hide explanation",
|
|
4765
|
+
explanation: "explanation goes here\n\nmore explanation",
|
|
4766
|
+
widgets: {}
|
|
4767
|
+
};
|
|
4768
|
+
const explanationWidgetLogic = {
|
|
4769
|
+
name: "explanation",
|
|
4770
|
+
defaultWidgetOptions: defaultWidgetOptions$q
|
|
4771
|
+
};
|
|
4772
|
+
|
|
4773
|
+
const currentVersion$3 = {
|
|
4774
|
+
major: 1,
|
|
4775
|
+
minor: 0
|
|
4776
|
+
};
|
|
4777
|
+
const widgetOptionsUpgrades$2 = {
|
|
4778
|
+
"1": v0options => ({
|
|
4779
|
+
times: v0options.times,
|
|
4780
|
+
buttonSets: v0options.buttonSets,
|
|
4781
|
+
functions: v0options.functions,
|
|
4782
|
+
buttonsVisible: v0options.buttonsVisible,
|
|
4783
|
+
visibleLabel: v0options.visibleLabel,
|
|
4784
|
+
ariaLabel: v0options.ariaLabel,
|
|
4785
|
+
answerForms: [{
|
|
4786
|
+
considered: "correct",
|
|
4787
|
+
form: v0options.form,
|
|
4788
|
+
simplify: v0options.simplify,
|
|
4789
|
+
value: v0options.value
|
|
4790
|
+
}]
|
|
4791
|
+
})
|
|
4792
|
+
};
|
|
4793
|
+
const defaultWidgetOptions$p = {
|
|
4794
|
+
answerForms: [],
|
|
4795
|
+
times: false,
|
|
4796
|
+
buttonSets: ["basic"],
|
|
4797
|
+
functions: ["f", "g", "h"]
|
|
4798
|
+
};
|
|
4799
|
+
|
|
4800
|
+
const expressionWidgetLogic = {
|
|
4801
|
+
name: "expression",
|
|
4802
|
+
version: currentVersion$3,
|
|
4803
|
+
widgetOptionsUpgrades: widgetOptionsUpgrades$2,
|
|
4804
|
+
defaultWidgetOptions: defaultWidgetOptions$p
|
|
4805
|
+
};
|
|
4806
|
+
|
|
4807
|
+
const defaultWidgetOptions$o = {
|
|
4808
|
+
title: "",
|
|
4809
|
+
content: "",
|
|
4810
|
+
widgets: {},
|
|
4811
|
+
images: {},
|
|
4812
|
+
hint: null
|
|
4813
|
+
};
|
|
4814
|
+
const GradedGroupWidgetLogic = {
|
|
4815
|
+
name: "graded-group",
|
|
4816
|
+
defaultWidgetOptions: defaultWidgetOptions$o
|
|
4817
|
+
};
|
|
4818
|
+
|
|
4819
|
+
const defaultWidgetOptions$n = {
|
|
4820
|
+
gradedGroups: []
|
|
4821
|
+
};
|
|
4822
|
+
const GradedGroupSetWidgetLogic = {
|
|
4823
|
+
name: "graded-group-set",
|
|
4824
|
+
defaultWidgetOptions: defaultWidgetOptions$n
|
|
4825
|
+
};
|
|
4826
|
+
|
|
4827
|
+
const defaultWidgetOptions$m = {
|
|
4828
|
+
content: "",
|
|
4829
|
+
widgets: {},
|
|
4830
|
+
images: {},
|
|
4831
|
+
// `undefined` instead of `null` so that getDefaultProps works for
|
|
4832
|
+
// `the GroupMetadataEditor`
|
|
4833
|
+
metadata: undefined
|
|
4834
|
+
};
|
|
4835
|
+
const GroupWidgetLogic = {
|
|
4836
|
+
name: "group",
|
|
4837
|
+
defaultWidgetOptions: defaultWidgetOptions$m
|
|
4838
|
+
};
|
|
4839
|
+
|
|
4840
|
+
const defaultWidgetOptions$l = {
|
|
4841
|
+
url: "",
|
|
4842
|
+
settings: [{
|
|
4843
|
+
name: "",
|
|
4844
|
+
value: ""
|
|
4845
|
+
}],
|
|
4846
|
+
width: "400",
|
|
4847
|
+
height: "400",
|
|
4848
|
+
allowFullScreen: false,
|
|
4849
|
+
allowTopNavigation: false
|
|
4850
|
+
};
|
|
4851
|
+
const iframeWidgetLogic = {
|
|
4852
|
+
name: "iframe",
|
|
4853
|
+
defaultWidgetOptions: defaultWidgetOptions$l
|
|
4854
|
+
};
|
|
4855
|
+
|
|
4856
|
+
const defaultWidgetOptions$k = {
|
|
4857
|
+
title: "",
|
|
4858
|
+
range: [[0, 10], [0, 10]],
|
|
4859
|
+
box: [400, 400],
|
|
4860
|
+
backgroundImage: {
|
|
4861
|
+
url: null,
|
|
4862
|
+
width: 0,
|
|
4863
|
+
height: 0
|
|
4864
|
+
},
|
|
4865
|
+
labels: [],
|
|
4866
|
+
alt: "",
|
|
4867
|
+
caption: ""
|
|
4868
|
+
};
|
|
4869
|
+
const imageWidgetLogic = {
|
|
4870
|
+
name: "image",
|
|
4871
|
+
defaultWidgetOptions: defaultWidgetOptions$k
|
|
4872
|
+
};
|
|
4873
|
+
|
|
4874
|
+
const defaultWidgetOptions$j = {
|
|
4875
|
+
value: 0,
|
|
4876
|
+
simplify: "required",
|
|
4877
|
+
size: "normal",
|
|
4878
|
+
inexact: false,
|
|
4879
|
+
maxError: 0.1,
|
|
4880
|
+
answerType: "number",
|
|
4881
|
+
rightAlign: false
|
|
4882
|
+
};
|
|
4883
|
+
const inputNumberWidgetLogic = {
|
|
4884
|
+
name: "input-number",
|
|
4885
|
+
defaultWidgetOptions: defaultWidgetOptions$j
|
|
4886
|
+
};
|
|
4887
|
+
|
|
4888
|
+
const defaultWidgetOptions$i = {
|
|
4889
|
+
graph: {
|
|
4890
|
+
box: [400, 400],
|
|
4891
|
+
labels: ["x", "y"],
|
|
4892
|
+
range: [[-10, 10], [-10, 10]],
|
|
4893
|
+
tickStep: [1, 1],
|
|
4894
|
+
gridStep: [1, 1],
|
|
4895
|
+
markings: "graph"
|
|
4896
|
+
},
|
|
4897
|
+
elements: []
|
|
4898
|
+
};
|
|
4899
|
+
const interactionWidgetLogic = {
|
|
4900
|
+
name: "interaction",
|
|
4901
|
+
defaultWidgetOptions: defaultWidgetOptions$i
|
|
4902
|
+
};
|
|
4903
|
+
|
|
4904
|
+
const defaultWidgetOptions$h = {
|
|
4905
|
+
labels: ["x", "y"],
|
|
4906
|
+
range: [[-10, 10], [-10, 10]],
|
|
4907
|
+
step: [1, 1],
|
|
4908
|
+
backgroundImage: {
|
|
4909
|
+
url: null
|
|
4910
|
+
},
|
|
4911
|
+
markings: "graph",
|
|
4912
|
+
showTooltips: false,
|
|
4913
|
+
showProtractor: false,
|
|
4914
|
+
graph: {
|
|
4915
|
+
type: "linear"
|
|
4916
|
+
},
|
|
4917
|
+
correct: {
|
|
4918
|
+
type: "linear",
|
|
4919
|
+
coords: null
|
|
4920
|
+
}
|
|
4921
|
+
};
|
|
4922
|
+
const interactiveGraphWidgetLogic = {
|
|
4923
|
+
name: "interactive-graph",
|
|
4924
|
+
defaultWidgetOptions: defaultWidgetOptions$h
|
|
4925
|
+
};
|
|
4926
|
+
|
|
4927
|
+
const defaultWidgetOptions$g = {
|
|
4928
|
+
choices: [],
|
|
4929
|
+
imageAlt: "",
|
|
4930
|
+
imageUrl: "",
|
|
4931
|
+
imageWidth: 0,
|
|
4932
|
+
imageHeight: 0,
|
|
4933
|
+
markers: [],
|
|
4934
|
+
multipleAnswers: false,
|
|
4935
|
+
hideChoicesFromInstructions: false
|
|
4936
|
+
};
|
|
4937
|
+
const labelImageWidgetLogic = {
|
|
4938
|
+
name: "label-image",
|
|
4939
|
+
defaultWidgetOptions: defaultWidgetOptions$g
|
|
4940
|
+
};
|
|
4941
|
+
|
|
4942
|
+
const defaultWidgetOptions$f = {
|
|
4943
|
+
left: ["$x$", "$y$", "$z$"],
|
|
4944
|
+
right: ["$1$", "$2$", "$3$"],
|
|
4945
|
+
labels: ["test", "label"],
|
|
4946
|
+
orderMatters: false,
|
|
4947
|
+
padding: true
|
|
4948
|
+
};
|
|
4949
|
+
const matcherWidgetLogic = {
|
|
4950
|
+
name: "matcher",
|
|
4951
|
+
defaultWidgetOptions: defaultWidgetOptions$f
|
|
4952
|
+
};
|
|
4953
|
+
|
|
4954
|
+
const defaultWidgetOptions$e = {
|
|
4955
|
+
matrixBoardSize: [3, 3],
|
|
4956
|
+
answers: [[]],
|
|
4957
|
+
prefix: "",
|
|
4958
|
+
suffix: "",
|
|
4959
|
+
cursorPosition: [0, 0]
|
|
4960
|
+
};
|
|
4961
|
+
const matrixWidgetLogic = {
|
|
4962
|
+
name: "matrix",
|
|
4963
|
+
defaultWidgetOptions: defaultWidgetOptions$e
|
|
4964
|
+
};
|
|
4965
|
+
|
|
4966
|
+
const _excluded$1 = ["imageUrl", "imageTop", "imageLeft"];
|
|
4967
|
+
const currentVersion$2 = {
|
|
4968
|
+
major: 1,
|
|
4969
|
+
minor: 0
|
|
4970
|
+
};
|
|
4971
|
+
const widgetOptionsUpgrades$1 = {
|
|
4972
|
+
"1": v0options => {
|
|
4973
|
+
const {
|
|
4974
|
+
imageUrl,
|
|
4975
|
+
imageTop,
|
|
4976
|
+
imageLeft
|
|
4977
|
+
} = v0options,
|
|
4978
|
+
rest = _objectWithoutPropertiesLoose(v0options, _excluded$1);
|
|
4979
|
+
return _extends({}, rest, {
|
|
4980
|
+
image: {
|
|
4981
|
+
url: imageUrl,
|
|
4982
|
+
top: imageTop,
|
|
4983
|
+
left: imageLeft
|
|
4984
|
+
}
|
|
4985
|
+
});
|
|
4986
|
+
}
|
|
4987
|
+
};
|
|
4988
|
+
const defaultWidgetOptions$d = {
|
|
4989
|
+
box: [480, 480],
|
|
4990
|
+
image: {},
|
|
4991
|
+
showProtractor: true,
|
|
4992
|
+
showRuler: false,
|
|
4993
|
+
rulerLabel: "",
|
|
4994
|
+
rulerTicks: 10,
|
|
4995
|
+
rulerPixels: 40,
|
|
4996
|
+
rulerLength: 10
|
|
4997
|
+
};
|
|
4998
|
+
|
|
4999
|
+
const measurerWidgetLogic = {
|
|
5000
|
+
name: "measurer",
|
|
5001
|
+
version: currentVersion$2,
|
|
5002
|
+
widgetOptionsUpgrades: widgetOptionsUpgrades$1,
|
|
5003
|
+
defaultWidgetOptions: defaultWidgetOptions$d
|
|
5004
|
+
};
|
|
5005
|
+
|
|
5006
|
+
const defaultWidgetOptions$c = {
|
|
5007
|
+
range: [0, 10],
|
|
5008
|
+
labelRange: [null, null],
|
|
5009
|
+
labelStyle: "decimal",
|
|
5010
|
+
labelTicks: true,
|
|
5011
|
+
divisionRange: [1, 12],
|
|
5012
|
+
numDivisions: 5,
|
|
5013
|
+
snapDivisions: 2,
|
|
5014
|
+
tickStep: null,
|
|
5015
|
+
correctRel: "eq",
|
|
5016
|
+
correctX: null,
|
|
5017
|
+
initialX: null,
|
|
5018
|
+
showTooltips: false
|
|
5019
|
+
};
|
|
5020
|
+
const numberLineWidgetLogic = {
|
|
5021
|
+
name: "number-line",
|
|
5022
|
+
defaultWidgetOptions: defaultWidgetOptions$c
|
|
5023
|
+
};
|
|
5024
|
+
|
|
5025
|
+
const defaultWidgetOptions$b = {
|
|
5026
|
+
answers: [{
|
|
5027
|
+
value: null,
|
|
5028
|
+
status: "correct",
|
|
5029
|
+
message: "",
|
|
5030
|
+
simplify: "required",
|
|
5031
|
+
answerForms: [],
|
|
5032
|
+
strict: false,
|
|
5033
|
+
maxError: null
|
|
5034
|
+
}],
|
|
5035
|
+
size: "normal",
|
|
5036
|
+
coefficient: false,
|
|
5037
|
+
labelText: "",
|
|
5038
|
+
rightAlign: false
|
|
5039
|
+
};
|
|
5040
|
+
const numericInputWidgetLogic = {
|
|
5041
|
+
name: "numeric-input",
|
|
5042
|
+
defaultWidgetOptions: defaultWidgetOptions$b
|
|
5043
|
+
};
|
|
5044
|
+
|
|
5045
|
+
const defaultWidgetOptions$a = {
|
|
5046
|
+
correctOptions: [{
|
|
5047
|
+
content: "$x$"
|
|
5048
|
+
}],
|
|
5049
|
+
otherOptions: [{
|
|
5050
|
+
content: "$y$"
|
|
5051
|
+
}],
|
|
5052
|
+
height: "normal",
|
|
5053
|
+
layout: "horizontal"
|
|
5054
|
+
};
|
|
5055
|
+
const ordererWidgetLogic = {
|
|
5056
|
+
name: "orderer",
|
|
5057
|
+
defaultWidgetOptions: defaultWidgetOptions$a
|
|
5058
|
+
};
|
|
5059
|
+
|
|
5060
|
+
const defaultWidgetOptions$9 = {
|
|
5061
|
+
passageTitle: "",
|
|
5062
|
+
passageText: "",
|
|
5063
|
+
footnotes: "",
|
|
5064
|
+
showLineNumbers: true
|
|
5065
|
+
};
|
|
5066
|
+
const passageWidgetLogic = {
|
|
5067
|
+
name: "passage",
|
|
5068
|
+
defaultWidgetOptions: defaultWidgetOptions$9
|
|
5069
|
+
};
|
|
5070
|
+
|
|
5071
|
+
const currentVersion$1 = {
|
|
5072
|
+
major: 0,
|
|
5073
|
+
minor: 1
|
|
5074
|
+
};
|
|
5075
|
+
const defaultWidgetOptions$8 = {
|
|
5076
|
+
passageNumber: 1,
|
|
5077
|
+
referenceNumber: 1,
|
|
5078
|
+
summaryText: ""
|
|
5079
|
+
};
|
|
5080
|
+
|
|
5081
|
+
const passageRefWidgetLogic = {
|
|
5082
|
+
name: "passageRef",
|
|
5083
|
+
version: currentVersion$1,
|
|
5084
|
+
defaultWidgetOptions: defaultWidgetOptions$8
|
|
5085
|
+
};
|
|
5086
|
+
|
|
5087
|
+
const defaultWidgetOptions$7 = {
|
|
5088
|
+
content: ""
|
|
5089
|
+
};
|
|
5090
|
+
const passageRefTargetWidgetLogic = {
|
|
5091
|
+
name: "passageRefTarget",
|
|
5092
|
+
defaultWidgetOptions: defaultWidgetOptions$7
|
|
5093
|
+
};
|
|
5094
|
+
|
|
5095
|
+
const defaultWidgetOptions$6 = {
|
|
5096
|
+
url: "",
|
|
5097
|
+
description: ""
|
|
5098
|
+
};
|
|
5099
|
+
const PhetSimulationWidgetLogic = {
|
|
5100
|
+
name: "phet-simulation",
|
|
5101
|
+
defaultWidgetOptions: defaultWidgetOptions$6
|
|
5102
|
+
};
|
|
5103
|
+
|
|
5104
|
+
const defaultWidgetOptions$5 = {
|
|
5105
|
+
scaleY: 1,
|
|
5106
|
+
maxY: 10,
|
|
5107
|
+
snapsPerLine: 2,
|
|
5108
|
+
correct: [1],
|
|
5109
|
+
starting: [1],
|
|
5110
|
+
type: "bar",
|
|
5111
|
+
labels: ["", ""],
|
|
5112
|
+
categories: [""],
|
|
5113
|
+
picSize: 30,
|
|
5114
|
+
picBoxHeight: 36,
|
|
5115
|
+
plotDimensions: [275, 200],
|
|
5116
|
+
labelInterval: 1,
|
|
5117
|
+
picUrl: null
|
|
5118
|
+
};
|
|
5119
|
+
const plotterWidgetLogic = {
|
|
5120
|
+
name: "plotter",
|
|
5121
|
+
defaultWidgetOptions: defaultWidgetOptions$5
|
|
5122
|
+
};
|
|
5123
|
+
|
|
5124
|
+
const defaultWidgetOptions$4 = {
|
|
5125
|
+
programID: "",
|
|
5126
|
+
height: 400
|
|
5127
|
+
};
|
|
5128
|
+
const pythonProgramWidgetLogic = {
|
|
5129
|
+
name: "python-program",
|
|
5130
|
+
defaultWidgetOptions: defaultWidgetOptions$4
|
|
5131
|
+
};
|
|
5132
|
+
|
|
5133
|
+
const _excluded = ["noneOfTheAbove"];
|
|
5134
|
+
const currentVersion = {
|
|
5135
|
+
major: 1,
|
|
5136
|
+
minor: 0
|
|
5137
|
+
};
|
|
5138
|
+
const widgetOptionsUpgrades = {
|
|
5139
|
+
"1": v0props => {
|
|
5140
|
+
const {
|
|
5141
|
+
noneOfTheAbove
|
|
5142
|
+
} = v0props,
|
|
5143
|
+
rest = _objectWithoutPropertiesLoose(v0props, _excluded);
|
|
5144
|
+
if (noneOfTheAbove) {
|
|
5145
|
+
throw new Error("radio widget v0 no longer supports auto noneOfTheAbove");
|
|
5146
|
+
}
|
|
5147
|
+
return _extends({}, rest, {
|
|
5148
|
+
hasNoneOfTheAbove: false
|
|
5149
|
+
});
|
|
5150
|
+
}
|
|
5151
|
+
};
|
|
5152
|
+
const defaultWidgetOptions$3 = {
|
|
5153
|
+
choices: [{}, {}, {}, {}],
|
|
5154
|
+
displayCount: null,
|
|
5155
|
+
randomize: false,
|
|
5156
|
+
hasNoneOfTheAbove: false,
|
|
5157
|
+
multipleSelect: false,
|
|
5158
|
+
countChoices: false,
|
|
5159
|
+
deselectEnabled: false
|
|
5160
|
+
};
|
|
5161
|
+
|
|
5162
|
+
const radioWidgetLogic = {
|
|
5163
|
+
name: "radio",
|
|
5164
|
+
version: currentVersion,
|
|
5165
|
+
widgetOptionsUpgrades: widgetOptionsUpgrades,
|
|
5166
|
+
defaultWidgetOptions: defaultWidgetOptions$3
|
|
5167
|
+
};
|
|
5168
|
+
|
|
5169
|
+
const defaultWidgetOptions$2 = {
|
|
5170
|
+
correct: ["$x$", "$y$", "$z$"],
|
|
5171
|
+
layout: "horizontal",
|
|
5172
|
+
padding: true
|
|
5173
|
+
};
|
|
5174
|
+
const sorterWidgetLogic = {
|
|
5175
|
+
name: "sorter",
|
|
5176
|
+
defaultWidgetOptions: defaultWidgetOptions$2
|
|
5177
|
+
};
|
|
5178
|
+
|
|
5179
|
+
const defaultRows = 4;
|
|
5180
|
+
const defaultColumns = 1;
|
|
5181
|
+
|
|
5182
|
+
// initialize a 2D array
|
|
5183
|
+
// (defaultRows x defaultColumns) of empty strings
|
|
5184
|
+
const answers = new Array(defaultRows).fill(0).map(() => new Array(defaultColumns).fill(""));
|
|
5185
|
+
const defaultWidgetOptions$1 = {
|
|
5186
|
+
headers: [""],
|
|
5187
|
+
rows: defaultRows,
|
|
5188
|
+
columns: defaultColumns,
|
|
5189
|
+
answers: answers
|
|
5190
|
+
};
|
|
5191
|
+
const tableWidgetLogic = {
|
|
5192
|
+
name: "table",
|
|
5193
|
+
defaultWidgetOptions: defaultWidgetOptions$1
|
|
5194
|
+
};
|
|
5195
|
+
|
|
5196
|
+
const defaultWidgetOptions = {
|
|
5197
|
+
location: ""
|
|
5198
|
+
};
|
|
5199
|
+
const videoWidgetLogic = {
|
|
5200
|
+
name: "video",
|
|
5201
|
+
defaultWidgetOptions
|
|
5202
|
+
};
|
|
5203
|
+
|
|
5204
|
+
/**
|
|
5205
|
+
* For details on the individual options, see the
|
|
5206
|
+
* PerseusOrdererWidgetOptions type
|
|
5207
|
+
*/
|
|
5208
|
+
|
|
5209
|
+
/**
|
|
5210
|
+
* Given a PerseusOrdererWidgetOptions object, return a new object with only
|
|
5211
|
+
* the public options that should be exposed to the client.
|
|
5212
|
+
*/
|
|
5213
|
+
function getOrdererPublicWidgetOptions(options) {
|
|
5214
|
+
return {
|
|
5215
|
+
options: options.options,
|
|
5216
|
+
height: options.height,
|
|
5217
|
+
layout: options.layout
|
|
5218
|
+
};
|
|
5219
|
+
}
|
|
5220
|
+
|
|
5221
|
+
/**
|
|
5222
|
+
* For details on the individual options, see the
|
|
5223
|
+
* PerseusCategorizerWidgetOptions type
|
|
5224
|
+
*/
|
|
5225
|
+
|
|
5226
|
+
/**
|
|
5227
|
+
* Given a PerseusCategorizerWidgetOptions object, return a new object with only
|
|
5228
|
+
* the public options that should be exposed to the client.
|
|
5229
|
+
*/
|
|
5230
|
+
function getCategorizerPublicWidgetOptions(options) {
|
|
5231
|
+
return {
|
|
5232
|
+
items: options.items,
|
|
5233
|
+
categories: options.categories,
|
|
5234
|
+
randomizeItems: options.randomizeItems,
|
|
5235
|
+
static: options.static
|
|
5236
|
+
};
|
|
5237
|
+
}
|
|
5238
|
+
|
|
5239
|
+
/**
|
|
5240
|
+
* For details on the individual options, see the
|
|
5241
|
+
* PerseusExpressionWidgetOptions type
|
|
5242
|
+
*/
|
|
5243
|
+
|
|
5244
|
+
/**
|
|
5245
|
+
* Given a PerseusExpressionWidgetOptions object, return a new object with only
|
|
5246
|
+
* the public options that should be exposed to the client.
|
|
5247
|
+
*/
|
|
5248
|
+
function getExpressionPublicWidgetOptions(options) {
|
|
5249
|
+
return {
|
|
5250
|
+
buttonSets: options.buttonSets,
|
|
5251
|
+
functions: options.functions,
|
|
5252
|
+
times: options.times,
|
|
5253
|
+
visibleLabel: options.visibleLabel,
|
|
5254
|
+
ariaLabel: options.ariaLabel,
|
|
5255
|
+
buttonsVisible: options.buttonsVisible
|
|
5256
|
+
};
|
|
5257
|
+
}
|
|
5258
|
+
|
|
5259
|
+
export { Errors, grapherUtil as GrapherUtil, ItemExtras, PerseusError, PerseusExpressionAnswerFormConsidered, addLibraryVersionToPerseusDebug, addWidget, approximateDeepEqual, approximateEqual, categorizerWidgetLogic as categorizerLogic, csProgramWidgetLogic as csProgramLogic, deepClone, definitionWidgetLogic as definitionLogic, dropdownWidgetLogic as dropdownLogic, explanationWidgetLogic as explanationLogic, expressionWidgetLogic as expressionLogic, getCategorizerPublicWidgetOptions, getDecimalSeparator, getExpressionPublicWidgetOptions, getMatrixSize, getOrdererPublicWidgetOptions, getWidgetIdsFromContent, getWidgetIdsFromContentByType, GradedGroupWidgetLogic as gradedGroupLogic, GradedGroupSetWidgetLogic as gradedGroupSetLogic, GroupWidgetLogic as groupLogic, iframeWidgetLogic as iframeLogic, imageWidgetLogic as imageLogic, inputNumberWidgetLogic as inputNumberLogic, interactionWidgetLogic as interactionLogic, interactiveGraphWidgetLogic as interactiveGraphLogic, isFailure, isSuccess, labelImageWidgetLogic as labelImageLogic, libVersion, lockedFigureColorNames, lockedFigureColors, lockedFigureFillStyles, mapObject, matcherWidgetLogic as matcherLogic, matrixWidgetLogic as matrixLogic, measurerWidgetLogic as measurerLogic, numberLineWidgetLogic as numberLineLogic, numericInputWidgetLogic as numericInputLogic, ordererWidgetLogic as ordererLogic, parseAndMigratePerseusArticle, parseAndMigratePerseusItem, parsePerseusItem, passageWidgetLogic as passageLogic, passageRefWidgetLogic as passageRefLogic, passageRefTargetWidgetLogic as passageRefTargetLogic, PhetSimulationWidgetLogic as phetSimulationLogic, plotterWidgetLogic as plotterLogic, plotterPlotTypes, pluck, pythonProgramWidgetLogic as pythonProgramLogic, radioWidgetLogic as radioLogic, sorterWidgetLogic as sorterLogic, tableWidgetLogic as tableLogic, videoWidgetLogic as videoLogic };
|
|
2404
5260
|
//# sourceMappingURL=index.js.map
|