@pie-element/hotspot 5.7.1-beta.0 → 5.7.1-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/configure/package.json +2 -2
  2. package/package.json +2 -2
  3. package/configure/lib/button.js +0 -61
  4. package/configure/lib/button.js.map +0 -1
  5. package/configure/lib/defaults.js +0 -82
  6. package/configure/lib/defaults.js.map +0 -1
  7. package/configure/lib/hotspot-container.js +0 -398
  8. package/configure/lib/hotspot-container.js.map +0 -1
  9. package/configure/lib/hotspot-drawable.js +0 -445
  10. package/configure/lib/hotspot-drawable.js.map +0 -1
  11. package/configure/lib/hotspot-palette.js +0 -154
  12. package/configure/lib/hotspot-palette.js.map +0 -1
  13. package/configure/lib/hotspot-polygon.js +0 -202
  14. package/configure/lib/hotspot-polygon.js.map +0 -1
  15. package/configure/lib/hotspot-rectangle.js +0 -150
  16. package/configure/lib/hotspot-rectangle.js.map +0 -1
  17. package/configure/lib/index.js +0 -212
  18. package/configure/lib/index.js.map +0 -1
  19. package/configure/lib/root.js +0 -401
  20. package/configure/lib/root.js.map +0 -1
  21. package/configure/lib/upload-control.js +0 -68
  22. package/configure/lib/upload-control.js.map +0 -1
  23. package/configure/lib/utils.js +0 -160
  24. package/configure/lib/utils.js.map +0 -1
  25. package/controller/lib/defaults.js +0 -26
  26. package/controller/lib/defaults.js.map +0 -1
  27. package/controller/lib/index.js +0 -263
  28. package/controller/lib/index.js.map +0 -1
  29. package/controller/lib/utils.js +0 -50
  30. package/controller/lib/utils.js.map +0 -1
  31. package/lib/hotspot/container.js +0 -246
  32. package/lib/hotspot/container.js.map +0 -1
  33. package/lib/hotspot/icons.js +0 -8
  34. package/lib/hotspot/icons.js.map +0 -1
  35. package/lib/hotspot/image.js +0 -133
  36. package/lib/hotspot/image.js.map +0 -1
  37. package/lib/hotspot/index.js +0 -207
  38. package/lib/hotspot/index.js.map +0 -1
  39. package/lib/hotspot/polygon.js +0 -225
  40. package/lib/hotspot/polygon.js.map +0 -1
  41. package/lib/hotspot/rectangle.js +0 -207
  42. package/lib/hotspot/rectangle.js.map +0 -1
  43. package/lib/index.js +0 -114
  44. package/lib/index.js.map +0 -1
  45. package/lib/session-updater.js +0 -30
  46. package/lib/session-updater.js.map +0 -1
@@ -1,160 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.updateImageDimensions = exports.groupShapes = exports.getUpdatedShapes = exports.getUpdatedRectangle = exports.getUpdatedPlygon = exports.getAllShapes = exports.generateValidationMessage = void 0;
9
-
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
-
14
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
-
16
- var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
17
-
18
- var _excluded = ["group"];
19
-
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
-
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
-
24
- var updateImageDimensions = function updateImageDimensions(initialDim, nextDim, keepAspectRatio, resizeType) {
25
- // if we want to keep image aspect ratio
26
- if (keepAspectRatio) {
27
- var imageAspectRatio = initialDim.width / initialDim.height;
28
-
29
- if (resizeType === 'height') {
30
- // if we want to change image height => we update the width accordingly
31
- return {
32
- width: nextDim.height * imageAspectRatio,
33
- height: nextDim.height
34
- };
35
- } // if we want to change image width => we update the height accordingly
36
-
37
-
38
- return {
39
- width: nextDim.width,
40
- height: nextDim.width / imageAspectRatio
41
- };
42
- } // if we don't want to keep aspect ratio, we just update both values
43
-
44
-
45
- return {
46
- width: nextDim.width,
47
- height: nextDim.height
48
- };
49
- }; // referenceInitialValue = the initial value of the Stage
50
- // referenceNextValue = the next value of the Stage
51
- // currentValue = the value that has to be re-sized influenced by the changes that were made on the Stage
52
-
53
-
54
- exports.updateImageDimensions = updateImageDimensions;
55
-
56
- var getDelta = function getDelta(referenceInitialValue, referenceNextValue, currentValue) {
57
- return referenceNextValue / referenceInitialValue * currentValue;
58
- };
59
-
60
- var getUpdatedRectangle = function getUpdatedRectangle(initialDim, nextDim, shape) {
61
- return _objectSpread(_objectSpread({}, shape), {}, {
62
- width: getDelta(initialDim.width, nextDim.width, shape.width),
63
- height: getDelta(initialDim.height, nextDim.height, shape.height),
64
- x: getDelta(initialDim.width, nextDim.width, shape.x),
65
- y: getDelta(initialDim.height, nextDim.height, shape.y)
66
- });
67
- };
68
-
69
- exports.getUpdatedRectangle = getUpdatedRectangle;
70
-
71
- var getUpdatedPlygon = function getUpdatedPlygon(initialDim, nextDim, shape) {
72
- return _objectSpread(_objectSpread({}, shape), {}, {
73
- points: shape.points.map(function (point) {
74
- return {
75
- x: getDelta(initialDim.width, nextDim.width, point.x),
76
- y: getDelta(initialDim.height, nextDim.height, point.y)
77
- };
78
- })
79
- });
80
- }; // initialDim = the initial dimensions: { width, height } of the Stage
81
- // nextDim = the next dimensions: { width, height } of the Stage
82
- // shapes = array of shapes that have to be re-sized and re-positioned
83
-
84
-
85
- exports.getUpdatedPlygon = getUpdatedPlygon;
86
-
87
- var getUpdatedShapes = function getUpdatedShapes(initialDim, nextDim, shapes) {
88
- return shapes.map(function (shape) {
89
- if (shape.group === 'rectangles') {
90
- return getUpdatedRectangle(initialDim, nextDim, shape);
91
- }
92
-
93
- if (shape.group === 'polygons') {
94
- return getUpdatedPlygon(initialDim, nextDim, shape);
95
- }
96
- });
97
- }; // converts shapes map to shapes array
98
- // example:
99
- // from: { rectangles: [r1], polygons: [p1, p2]}
100
- // to: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]
101
- // if a shape has index defined, keep it, otherwise initialize it
102
- // index is used for the UNDO function
103
-
104
-
105
- exports.getUpdatedShapes = getUpdatedShapes;
106
-
107
- var getAllShapes = function getAllShapes(shapesMap) {
108
- shapesMap = shapesMap || {};
109
- var shapesArray = [];
110
- var shapesKeys = Object.keys(shapesMap);
111
- return shapesKeys.length ? shapesKeys.reduce(function (acc, currentShapeKey) {
112
- return acc.concat(shapesMap[currentShapeKey] ? shapesMap[currentShapeKey].map(function (shape, index) {
113
- return _objectSpread(_objectSpread({}, shape), {}, {
114
- group: currentShapeKey,
115
- index: shape.index || acc.length + index
116
- });
117
- }) : []);
118
- }, shapesArray) : shapesArray;
119
- }; // converts shapes array to shapes map
120
- // is the reverse of getAllShapes function
121
- // example:
122
- // from: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]
123
- // to: { rectangles: [r1], polygons: [p1, p2]}
124
-
125
-
126
- exports.getAllShapes = getAllShapes;
127
-
128
- var groupShapes = function groupShapes(shapesArray) {
129
- shapesArray = shapesArray || [];
130
- var shapesMap = {
131
- rectangles: [],
132
- polygons: []
133
- };
134
-
135
- if (shapesArray.length) {
136
- return shapesArray.reduce(function (acc, _ref) {
137
- var group = _ref.group,
138
- shapeProps = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
139
- acc[group] = [].concat((0, _toConsumableArray2["default"])(acc[group] || []), [shapeProps]);
140
- return acc;
141
- }, shapesMap);
142
- }
143
-
144
- return (0, _cloneDeep["default"])(shapesMap);
145
- };
146
-
147
- exports.groupShapes = groupShapes;
148
-
149
- var generateValidationMessage = function generateValidationMessage(config) {
150
- var minShapes = config.minShapes,
151
- maxShapes = config.maxShapes,
152
- maxSelections = config.maxSelections;
153
- var shapesMessage = "\nThere should be at least ".concat(minShapes, " ") + (maxShapes ? "and at most ".concat(maxShapes, " ") : '') + 'shapes defined.';
154
- var selectionsMessage = "\nThere should be at least 1 " + (maxSelections ? "and at most ".concat(maxSelections, " ") : '') + 'shape' + (maxSelections ? 's' : '') + ' selected.';
155
- var message = 'Validation requirements:' + shapesMessage + selectionsMessage;
156
- return message;
157
- };
158
-
159
- exports.generateValidationMessage = generateValidationMessage;
160
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.js"],"names":["updateImageDimensions","initialDim","nextDim","keepAspectRatio","resizeType","imageAspectRatio","width","height","getDelta","referenceInitialValue","referenceNextValue","currentValue","getUpdatedRectangle","shape","x","y","getUpdatedPlygon","points","map","point","getUpdatedShapes","shapes","group","getAllShapes","shapesMap","shapesArray","shapesKeys","Object","keys","length","reduce","acc","currentShapeKey","concat","index","groupShapes","rectangles","polygons","shapeProps","generateValidationMessage","config","minShapes","maxShapes","maxSelections","shapesMessage","selectionsMessage","message"],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;AAEA,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,UAAD,EAAaC,OAAb,EAAsBC,eAAtB,EAAuCC,UAAvC,EAAsD;AAClF;AACA,MAAID,eAAJ,EAAqB;AACnB,QAAME,gBAAgB,GAAGJ,UAAU,CAACK,KAAX,GAAmBL,UAAU,CAACM,MAAvD;;AAEA,QAAIH,UAAU,KAAK,QAAnB,EAA6B;AAC3B;AACA,aAAO;AACLE,QAAAA,KAAK,EAAEJ,OAAO,CAACK,MAAR,GAAiBF,gBADnB;AAELE,QAAAA,MAAM,EAAEL,OAAO,CAACK;A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AlB,SAAqC,EADnD,IAEA,OAFA,IAGCA,aAAa,GAAG,GAAH,GAAS,EAHvB,IAIA,YALF;AAOA,MAAMG,OAAO,GAAG,6BAA6BF,aAA7B,GAA6CC,iBAA7D;AAEA,SAAOC,OAAP;AACD,CAhBD","sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\n\nconst updateImageDimensions = (initialDim, nextDim, keepAspectRatio, resizeType) => {\n // if we want to keep image aspect ratio\n if (keepAspectRatio) {\n const imageAspectRatio = initialDim.width / initialDim.height;\n\n if (resizeType === 'height') {\n // if we want to change image height => we update the width accordingly\n return {\n width: nextDim.height * imageAspectRatio,\n height: nextDim.height,\n };\n }\n\n // if we want to change image width => we update the height accordingly\n return {\n width: nextDim.width,\n height: nextDim.width / imageAspectRatio,\n };\n }\n\n // if we don't want to keep aspect ratio, we just update both values\n return {\n width: nextDim.width,\n height: nextDim.height,\n };\n};\n\n// referenceInitialValue = the initial value of the Stage\n// referenceNextValue = the next value of the Stage\n// currentValue = the value that has to be re-sized influenced by the changes that were made on the Stage\nconst getDelta = (referenceInitialValue, referenceNextValue, currentValue) =>\n (referenceNextValue / referenceInitialValue) * currentValue;\n\nconst getUpdatedRectangle = (initialDim, nextDim, shape) => ({\n ...shape,\n width: getDelta(initialDim.width, nextDim.width, shape.width),\n height: getDelta(initialDim.height, nextDim.height, shape.height),\n x: getDelta(initialDim.width, nextDim.width, shape.x),\n y: getDelta(initialDim.height, nextDim.height, shape.y),\n});\n\nconst getUpdatedPlygon = (initialDim, nextDim, shape) => ({\n ...shape,\n points: shape.points.map((point) => ({\n x: getDelta(initialDim.width, nextDim.width, point.x),\n y: getDelta(initialDim.height, nextDim.height, point.y),\n })),\n});\n\n// initialDim = the initial dimensions: { width, height } of the Stage\n// nextDim = the next dimensions: { width, height } of the Stage\n// shapes = array of shapes that have to be re-sized and re-positioned\nconst getUpdatedShapes = (initialDim, nextDim, shapes) => {\n return shapes.map((shape) => {\n if (shape.group === 'rectangles') {\n return getUpdatedRectangle(initialDim, nextDim, shape);\n }\n\n if (shape.group === 'polygons') {\n return getUpdatedPlygon(initialDim, nextDim, shape);\n }\n });\n};\n\n// converts shapes map to shapes array\n// example:\n// from: { rectangles: [r1], polygons: [p1, p2]}\n// to: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// if a shape has index defined, keep it, otherwise initialize it\n// index is used for the UNDO function\nconst getAllShapes = (shapesMap) => {\n shapesMap = shapesMap || {};\n const shapesArray = [];\n const shapesKeys = Object.keys(shapesMap);\n\n return shapesKeys.length\n ? shapesKeys.reduce(\n (acc, currentShapeKey) =>\n acc.concat(\n shapesMap[currentShapeKey]\n ? shapesMap[currentShapeKey].map((shape, index) => ({\n ...shape,\n group: currentShapeKey,\n index: shape.index || acc.length + index,\n }))\n : [],\n ),\n shapesArray,\n )\n : shapesArray;\n};\n\n// converts shapes array to shapes map\n// is the reverse of getAllShapes function\n// example:\n// from: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// to: { rectangles: [r1], polygons: [p1, p2]}\nconst groupShapes = (shapesArray) => {\n shapesArray = shapesArray || [];\n const shapesMap = {\n rectangles: [],\n polygons: [],\n };\n\n if (shapesArray.length) {\n return shapesArray.reduce((acc, { group, ...shapeProps }) => {\n acc[group] = [...(acc[group] || []), shapeProps];\n return acc;\n }, shapesMap);\n }\n\n return cloneDeep(shapesMap);\n};\n\nconst generateValidationMessage = (config) => {\n const { minShapes, maxShapes, maxSelections } = config;\n\n const shapesMessage =\n `\\nThere should be at least ${minShapes} ` + (maxShapes ? `and at most ${maxShapes} ` : '') + 'shapes defined.';\n\n const selectionsMessage =\n `\\nThere should be at least 1 ` +\n (maxSelections ? `and at most ${maxSelections} ` : '') +\n 'shape' +\n (maxSelections ? 's' : '') +\n ' selected.';\n\n const message = 'Validation requirements:' + shapesMessage + selectionsMessage;\n\n return message;\n};\n\nexport {\n updateImageDimensions,\n generateValidationMessage,\n getUpdatedShapes,\n getAllShapes,\n groupShapes,\n getUpdatedRectangle,\n getUpdatedPlygon,\n};\n"],"file":"utils.js"}
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _default = {
8
- prompt: 'This is the question prompt',
9
- imageUrl: '',
10
- shapes: {
11
- rectangles: [],
12
- polygons: []
13
- },
14
- multipleCorrect: true,
15
- partialScoring: false,
16
- dimensions: {
17
- height: 0,
18
- width: 0
19
- },
20
- hotspotColor: 'rgba(137, 183, 244, 0.25)',
21
- hotspotList: ['rgba(137, 183, 244, 0.25)'],
22
- outlineColor: 'blue',
23
- outlineList: ['blue']
24
- };
25
- exports["default"] = _default;
26
- //# sourceMappingURL=defaults.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/defaults.js"],"names":["prompt","imageUrl","shapes","rectangles","polygons","multipleCorrect","partialScoring","dimensions","height","width","hotspotColor","hotspotList","outlineColor","outlineList"],"mappings":";;;;;;eAAe;AACbA,EAAAA,MAAM,EAAE,6BADK;AAEbC,EAAAA,QAAQ,EAAE,EAFG;AAGbC,EAAAA,MAAM,EAAE;AACNC,IAAAA,UAAU,EAAE,EADN;AAENC,IAAAA,QAAQ,EAAE;AAFJ,GAHK;AAObC,EAAAA,eAAe,EAAE,IAPJ;AAQbC,EAAAA,cAAc,EAAE,KARH;AASbC,EAAAA,UAAU,EAAE;AACVC,IAAAA,MAAM,EAAE,CADE;AAEVC,IAAAA,KAAK,EAAE;AAFG,GATC;AAabC,EAAAA,YAAY,EAAE,2BAbD;AAcbC,EAAAA,WAAW,EAAE,CAAC,2BAAD,CAdA;AAebC,EAAAA,YAAY,EAAE,MAfD;AAgBbC,EAAAA,WAAW,EAAE,CAAC,MAAD;AAhBA,C","sourcesContent":["export default {\n prompt: 'This is the question prompt',\n imageUrl: '',\n shapes: {\n rectangles: [],\n polygons: [],\n },\n multipleCorrect: true,\n partialScoring: false,\n dimensions: {\n height: 0,\n width: 0,\n },\n hotspotColor: 'rgba(137, 183, 244, 0.25)',\n hotspotList: ['rgba(137, 183, 244, 0.25)'],\n outlineColor: 'blue',\n outlineList: ['blue'],\n};\n"],"file":"defaults.js"}
@@ -1,263 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createDefaultModel = exports.createCorrectResponseSession = void 0;
9
- exports.model = model;
10
- exports.normalize = void 0;
11
- exports.outcome = outcome;
12
- exports.validate = void 0;
13
-
14
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
15
-
16
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
17
-
18
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
-
20
- var _debug = _interopRequireDefault(require("debug"));
21
-
22
- var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
23
-
24
- var _controllerUtils = require("@pie-lib/controller-utils");
25
-
26
- var _utils = require("./utils");
27
-
28
- var _defaults = _interopRequireDefault(require("./defaults"));
29
-
30
- var _excluded = ["index"],
31
- _excluded2 = ["index"];
32
-
33
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
34
-
35
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
36
-
37
- var log = (0, _debug["default"])('pie-elements:hotspot:controller');
38
-
39
- var normalize = function normalize(question) {
40
- return _objectSpread({
41
- promptEnabled: true,
42
- rationaleEnabled: true,
43
- teacherInstructionsEnabled: true,
44
- studentInstructionsEnabled: true,
45
- strokeWidth: 5
46
- }, question);
47
- };
48
-
49
- exports.normalize = normalize;
50
-
51
- function model(question, session, env) {
52
- var normalizedQuestion = normalize(question);
53
- var imageUrl = normalizedQuestion.imageUrl,
54
- dimensions = normalizedQuestion.dimensions,
55
- hotspotColor = normalizedQuestion.hotspotColor,
56
- multipleCorrect = normalizedQuestion.multipleCorrect,
57
- outlineColor = normalizedQuestion.outlineColor,
58
- partialScoring = normalizedQuestion.partialScoring,
59
- prompt = normalizedQuestion.prompt,
60
- shapes = normalizedQuestion.shapes;
61
-
62
- var _ref = shapes || {},
63
- rectangles = _ref.rectangles,
64
- polygons = _ref.polygons;
65
-
66
- return new Promise(function (resolve) {
67
- var out = {
68
- disabled: env.mode !== 'gather',
69
- mode: env.mode,
70
- dimensions: dimensions,
71
- imageUrl: imageUrl,
72
- outlineColor: outlineColor,
73
- hotspotColor: hotspotColor,
74
- multipleCorrect: multipleCorrect,
75
- partialScoring: partialScoring,
76
- shapes: _objectSpread(_objectSpread({}, shapes), {}, {
77
- // eslint-disable-next-line no-unused-vars
78
- rectangles: (rectangles || []).map(function (_ref2) {
79
- var index = _ref2.index,
80
- rectProps = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
81
- return _objectSpread({}, rectProps);
82
- }),
83
- // eslint-disable-next-line no-unused-vars
84
- polygons: (polygons || []).map(function (_ref3) {
85
- var index = _ref3.index,
86
- polyProps = (0, _objectWithoutProperties2["default"])(_ref3, _excluded2);
87
- return _objectSpread({}, polyProps);
88
- })
89
- }),
90
- responseCorrect: env.mode === 'evaluate' ? (0, _utils.isResponseCorrect)(normalizedQuestion, session) : undefined
91
- };
92
-
93
- if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
94
- out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
95
- out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
96
- } else {
97
- out.rationale = null;
98
- out.teacherInstructions = null;
99
- }
100
-
101
- out.prompt = normalizedQuestion.promptEnabled ? prompt : null;
102
- out.strokeWidth = normalizedQuestion.strokeWidth; // console.log(out);
103
-
104
- resolve(out);
105
- });
106
- }
107
-
108
- var createDefaultModel = function createDefaultModel() {
109
- var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
110
- return new Promise(function (resolve) {
111
- resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
112
- });
113
- };
114
-
115
- exports.createDefaultModel = createDefaultModel;
116
-
117
- var getScore = function getScore(config, session) {
118
- var env = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
119
-
120
- var _ref4 = session || {},
121
- answers = _ref4.answers;
122
-
123
- if (!config.shapes || !config.shapes.rectangles && !config.shapes.polygons) {
124
- return 0;
125
- }
126
-
127
- var _config$shapes = config.shapes;
128
- _config$shapes = _config$shapes === void 0 ? {} : _config$shapes;
129
- var _config$shapes$rectan = _config$shapes.rectangles,
130
- rectangles = _config$shapes$rectan === void 0 ? [] : _config$shapes$rectan,
131
- _config$shapes$polygo = _config$shapes.polygons,
132
- polygons = _config$shapes$polygo === void 0 ? [] : _config$shapes$polygo;
133
-
134
- var partialScoringEnabled = _controllerUtils.partialScoring.enabled(config, env);
135
-
136
- if (!partialScoringEnabled) {
137
- return (0, _utils.isResponseCorrect)(config, session) ? 1 : 0;
138
- }
139
-
140
- var correctAnswers = 0;
141
- var selectedChoices = 0;
142
- var choices = [].concat((0, _toConsumableArray2["default"])(rectangles), (0, _toConsumableArray2["default"])(polygons));
143
- var correctChoices = choices.filter(function (choice) {
144
- return choice.correct;
145
- });
146
- choices.forEach(function (shape) {
147
- var selected = answers && answers.filter(function (answer) {
148
- return answer.id === shape.id;
149
- })[0];
150
- var correctlySelected = shape.correct && selected;
151
-
152
- if (selected) {
153
- selectedChoices += 1;
154
- }
155
-
156
- if (correctlySelected) {
157
- correctAnswers += 1;
158
- }
159
- });
160
- var extraAnswers = selectedChoices > correctChoices.length ? selectedChoices - correctChoices.length : 0;
161
- var total = correctChoices.length === 0 ? 1 : correctChoices.length;
162
- var str = ((correctAnswers - extraAnswers) / total).toFixed(2);
163
- return str < 0 ? 0 : parseFloat(str);
164
- };
165
-
166
- function outcome(config, session) {
167
- var env = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
168
- return new Promise(function (resolve) {
169
- log('outcome...');
170
-
171
- if (!session || (0, _isEmpty["default"])(session)) {
172
- resolve({
173
- score: 0,
174
- empty: true
175
- });
176
- }
177
-
178
- if (session.answers) {
179
- var score = getScore(config, session, env);
180
- resolve({
181
- score: score
182
- });
183
- } else {
184
- resolve({
185
- score: 0,
186
- empty: true
187
- });
188
- }
189
- });
190
- }
191
-
192
- var returnShapesCorrect = function returnShapesCorrect(shapes) {
193
- var answers = [];
194
- shapes.forEach(function (i) {
195
- var correct = i.correct,
196
- id = i.id;
197
-
198
- if (correct) {
199
- answers.push({
200
- id: id
201
- });
202
- }
203
- });
204
- return answers;
205
- };
206
-
207
- var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
208
- return new Promise(function (resolve) {
209
- if (env.mode !== 'evaluate' && env.role === 'instructor') {
210
- var _question$shapes = question.shapes;
211
- _question$shapes = _question$shapes === void 0 ? {} : _question$shapes;
212
- var _question$shapes$rect = _question$shapes.rectangles,
213
- rectangles = _question$shapes$rect === void 0 ? [] : _question$shapes$rect,
214
- _question$shapes$poly = _question$shapes.polygons,
215
- polygons = _question$shapes$poly === void 0 ? {} : _question$shapes$poly;
216
- var rectangleCorrect = returnShapesCorrect(rectangles);
217
- var polygonsCorrect = returnShapesCorrect(polygons);
218
- resolve({
219
- answers: [].concat((0, _toConsumableArray2["default"])(rectangleCorrect), (0, _toConsumableArray2["default"])(polygonsCorrect)),
220
- id: '1'
221
- });
222
- } else {
223
- resolve(null);
224
- }
225
- });
226
- };
227
-
228
- exports.createCorrectResponseSession = createCorrectResponseSession;
229
-
230
- var validate = function validate() {
231
- var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
232
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
233
- var shapes = model.shapes;
234
- var _config$minShapes = config.minShapes,
235
- minShapes = _config$minShapes === void 0 ? 2 : _config$minShapes,
236
- maxShapes = config.maxShapes,
237
- maxSelections = config.maxSelections;
238
- var errors = {};
239
- var allShapes = Object.values(shapes || {}).reduce(function (acc, shape) {
240
- return [].concat((0, _toConsumableArray2["default"])(acc), (0, _toConsumableArray2["default"])(shape));
241
- }, []);
242
- var nbOfSelections = (allShapes || []).reduce(function (acc, shape) {
243
- return shape.correct ? acc + 1 : acc;
244
- }, 0);
245
- var nbOfShapes = (allShapes || []).length;
246
-
247
- if (nbOfShapes < minShapes) {
248
- errors.shapesError = "There should be at least ".concat(minShapes, " shapes defined.");
249
- } else if (nbOfShapes > maxShapes) {
250
- errors.shapesError = "No more than ".concat(maxShapes, " shapes should be defined.");
251
- }
252
-
253
- if (nbOfSelections < 1) {
254
- errors.selectionsError = 'There should be at least 1 shape selected.';
255
- } else if (nbOfSelections > maxSelections) {
256
- errors.selectionsError = "No more than ".concat(maxSelections, " shapes should be selected.");
257
- }
258
-
259
- return errors;
260
- };
261
-
262
- exports.validate = validate;
263
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["log","normalize","question","promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","strokeWidth","model","session","env","normalizedQuestion","imageUrl","dimensions","hotspotColor","multipleCorrect","outlineColor","partialScoring","prompt","shapes","rectangles","polygons","Promise","resolve","out","disabled","mode","map","index","rectProps","polyProps","responseCorrect","undefined","role","rationale","teacherInstructions","createDefaultModel","defaults","getScore","config","answers","partialScoringEnabled","enabled","correctAnswers","selectedChoices","choices","correctChoices","filter","choice","correct","forEach","shape","selected","answer","id","correctlySelected","extraAnswers","length","total","str","toFixed","parseFloat","outcome","score","empty","returnShapesCorrect","i","push","createCorrectResponseSession","rectangleCorrect","polygonsCorrect","validate","minShapes","maxShapes","maxSelections","errors","allShapes","Object","values","reduce","acc","nbOfSelections","nbOfShapes","shapesError","selectionsError"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AAEA;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,iCAAN,CAAZ;;AAEO,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,QAAD;AAAA;AACvBC,IAAAA,aAAa,EAAE,IADQ;AAEvBC,IAAAA,gBAAgB,EAAE,IAFK;AAGvBC,IAAAA,0BAA0B,EAAE,IAHL;AAIvBC,IAAAA,0BAA0B,EAAE,IAJL;AAKvBC,IAAAA,WAAW,EAAE;AALU,KAMpBL,QANoB;AAAA,CAAlB;;;;AASA,SAASM,KAAT,CAAeN,QAAf,EAAyBO,OAAzB,EAAkCC,GAAlC,EAAuC;AAC5C,MAAMC,kBAAkB,GAAGV,SAAS,CAACC,QAAD,CAApC;AACA,MAAQU,QAAR,GACED,kBADF,CAAQC,QAAR;AAAA,MAAkBC,UAAlB,GACEF,kBADF,CAAkBE,UAAlB;AAAA,MAA8BC,YAA9B,GACEH,kBADF,CAA8BG,YAA9B;AAAA,MAA4CC,eAA5C,GACEJ,kBADF,CAA4CI,eAA5C;AAAA,MAA6DC,YAA7D,GACEL,kBADF,CAA6DK,YAA7D;AAAA,MAA2EC,cAA3E,GACEN,kBADF,CAA2EM,cAA3E;AAAA,MAA2FC,MAA3F,GACEP,kBADF,CAA2FO,MAA3F;AAAA,MAAmGC,MAAnG,GACER,kBADF,CAAmGQ,MAAnG;;AAEA,aAAiCA,MAAM,IAAI,EAA3C;AAAA,MAAQC,UAAR,QAAQA,U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cAAc,GAAG,CAACL,SAAS,IAAI,EAAd,EAAkBG,MAAlB,CAAyB,UAACC,GAAD,EAAM7B,KAAN;AAAA,WAAiBA,KAAK,CAACF,OAAN,GAAgB+B,GAAG,GAAG,CAAtB,GAA0BA,GAA3C;AAAA,GAAzB,EAA0E,CAA1E,CAAvB;AAEA,MAAME,UAAU,GAAG,CAACN,SAAS,IAAI,EAAd,EAAkBnB,MAArC;;AAEA,MAAIyB,UAAU,GAAGV,SAAjB,EAA4B;AAC1BG,IAAAA,MAAM,CAACQ,WAAP,sCAAiDX,SAAjD;AACD,GAFD,MAEO,IAAIU,UAAU,GAAGT,SAAjB,EAA4B;AACjCE,IAAAA,MAAM,CAACQ,WAAP,0BAAqCV,SAArC;AACD;;AAED,MAAIQ,cAAc,GAAG,CAArB,EAAwB;AACtBN,IAAAA,MAAM,CAACS,eAAP,GAAyB,4CAAzB;AACD,GAFD,MAEO,IAAIH,cAAc,GAAGP,aAArB,EAAoC;AACzCC,IAAAA,MAAM,CAACS,eAAP,0BAAyCV,aAAzC;AACD;;AAED,SAAOC,MAAP;AACD,CAxBM","sourcesContent":["import debug from 'debug';\nimport isEmpty from 'lodash/isEmpty';\nimport { partialScoring } from '@pie-lib/controller-utils';\n\nimport { isResponseCorrect } from './utils';\n\nimport defaults from './defaults';\n\nconst log = debug('pie-elements:hotspot:controller');\n\nexport const normalize = (question) => ({\n promptEnabled: true,\n rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n strokeWidth: 5,\n ...question,\n});\n\nexport function model(question, session, env) {\n const normalizedQuestion = normalize(question);\n const { imageUrl, dimensions, hotspotColor, multipleCorrect, outlineColor, partialScoring, prompt, shapes } =\n normalizedQuestion;\n const { rectangles, polygons } = shapes || {};\n\n return new Promise((resolve) => {\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n dimensions,\n imageUrl,\n outlineColor,\n hotspotColor,\n multipleCorrect,\n partialScoring,\n shapes: {\n ...shapes,\n // eslint-disable-next-line no-unused-vars\n rectangles: (rectangles || []).map(({ index, ...rectProps }) => ({ ...rectProps })),\n // eslint-disable-next-line no-unused-vars\n polygons: (polygons || []).map(({ index, ...polyProps }) => ({ ...polyProps })),\n },\n responseCorrect: env.mode === 'evaluate' ? isResponseCorrect(normalizedQuestion, session) : undefined,\n };\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n out.prompt = normalizedQuestion.promptEnabled ? prompt : null;\n out.strokeWidth = normalizedQuestion.strokeWidth;\n\n // console.log(out);\n resolve(out);\n });\n}\n\nexport const createDefaultModel = (model = {}) =>\n new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n\nconst getScore = (config, session, env = {}) => {\n const { answers } = session || {};\n\n if (!config.shapes || (!config.shapes.rectangles && !config.shapes.polygons)) {\n return 0;\n }\n\n const { shapes: { rectangles = [], polygons = [] } = {} } = config;\n const partialScoringEnabled = partialScoring.enabled(config, env);\n\n if (!partialScoringEnabled) {\n return isResponseCorrect(config, session) ? 1 : 0;\n }\n\n let correctAnswers = 0;\n let selectedChoices = 0;\n\n const choices = [...rectangles, ...polygons];\n\n const correctChoices = choices.filter((choice) => choice.correct);\n\n choices.forEach((shape) => {\n const selected = answers && answers.filter((answer) => answer.id === shape.id)[0];\n const correctlySelected = shape.correct && selected;\n\n if (selected) {\n selectedChoices += 1;\n }\n\n if (correctlySelected) {\n correctAnswers += 1;\n }\n });\n\n const extraAnswers = selectedChoices > correctChoices.length ? selectedChoices - correctChoices.length : 0;\n\n const total = correctChoices.length === 0 ? 1 : correctChoices.length;\n const str = ((correctAnswers - extraAnswers) / total).toFixed(2);\n\n return str < 0 ? 0 : parseFloat(str);\n};\n\nexport function outcome(config, session, env = {}) {\n return new Promise((resolve) => {\n log('outcome...');\n\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (session.answers) {\n const score = getScore(config, session, env);\n resolve({ score });\n } else {\n resolve({ score: 0, empty: true });\n }\n });\n}\n\nconst returnShapesCorrect = (shapes) => {\n let answers = [];\n\n shapes.forEach((i) => {\n const { correct, id } = i;\n if (correct) {\n answers.push({ id });\n }\n });\n return answers;\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { shapes: { rectangles = [], polygons = {} } = {} } = question;\n\n const rectangleCorrect = returnShapesCorrect(rectangles);\n const polygonsCorrect = returnShapesCorrect(polygons);\n\n resolve({\n answers: [...rectangleCorrect, ...polygonsCorrect],\n id: '1',\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { shapes } = model;\n const { minShapes = 2, maxShapes, maxSelections } = config;\n const errors = {};\n\n const allShapes = Object.values(shapes || {}).reduce((acc, shape) => [...acc, ...shape], []);\n\n const nbOfSelections = (allShapes || []).reduce((acc, shape) => (shape.correct ? acc + 1 : acc), 0);\n\n const nbOfShapes = (allShapes || []).length;\n\n if (nbOfShapes < minShapes) {\n errors.shapesError = `There should be at least ${minShapes} shapes defined.`;\n } else if (nbOfShapes > maxShapes) {\n errors.shapesError = `No more than ${maxShapes} shapes should be defined.`;\n }\n\n if (nbOfSelections < 1) {\n errors.selectionsError = 'There should be at least 1 shape selected.';\n } else if (nbOfSelections > maxSelections) {\n errors.selectionsError = `No more than ${maxSelections} shapes should be selected.`;\n }\n\n return errors;\n};\n"],"file":"index.js"}
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.isResponseCorrect = exports.getCorrectResponse = void 0;
9
-
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
- var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
13
-
14
- var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
15
-
16
- var getCorrectResponse = function getCorrectResponse(choices) {
17
- return choices.filter(function (c) {
18
- return c.correct;
19
- }).map(function (c) {
20
- return c.id;
21
- }).sort();
22
- };
23
-
24
- exports.getCorrectResponse = getCorrectResponse;
25
-
26
- var isResponseCorrect = function isResponseCorrect(question, session) {
27
- var _question$shapes = question.shapes,
28
- rectangles = _question$shapes.rectangles,
29
- polygons = _question$shapes.polygons;
30
- var choices = [].concat((0, _toConsumableArray2["default"])(rectangles), (0, _toConsumableArray2["default"])(polygons));
31
- var correctResponseIds = getCorrectResponse(choices);
32
-
33
- if (!session || (0, _isEmpty["default"])(session)) {
34
- return false;
35
- }
36
-
37
- if (session.answers && session.answers.length) {
38
- var answerIds = (session.answers || []).map(function (a) {
39
- return a.id;
40
- });
41
- return (0, _isEqual["default"])(answerIds.sort(), correctResponseIds);
42
- } else if (!(correctResponseIds && correctResponseIds.length)) {
43
- return true;
44
- }
45
-
46
- return false;
47
- };
48
-
49
- exports.isResponseCorrect = isResponseCorrect;
50
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.js"],"names":["getCorrectResponse","choices","filter","c","correct","map","id","sort","isResponseCorrect","question","session","shapes","rectangles","polygons","correctResponseIds","answers","length","answerIds","a"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAqB,CAACC,OAAD;AAAA,SAChCA,OAAO,CACJC,MADH,CACU,UAACC,CAAD;AAAA,WAAOA,CAAC,CAACC,OAAT;AAAA,GADV,EAEGC,GAFH,CAEO,UAACF,CAAD;AAAA,WAAOA,CAAC,CAACG,EAAT;AAAA,GAFP,EAGGC,IAHH,EADgC;AAAA,CAA3B;;;;AAMA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,QAAD,EAAWC,OAAX,EAAuB;AACtD,yBAEID,QAFJ,CACEE,MADF;AAAA,MACYC,UADZ,oBACYA,UADZ;AAAA,MACwBC,QADxB,oBACwBA,QADxB;AAGA,MAAMZ,OAAO,iDAAOW,UAAP,uCAAsBC,QAAtB,EAAb;AACA,MAAIC,kBAAkB,GAAGd,kBAAkB,CAACC,OAAD,CAA3C;;AAEA,MAAI,CAACS,OAAD,IAAY,yBAAQA,OAAR,CAAhB,EAAkC;AAChC,WAAO,KAAP;AACD;;AAED,MAAIA,OAAO,CAACK,OAAR,IAAmBL,OAAO,CAACK,OAAR,CAAgBC,MAAvC,EAA+C;AAC7C,QAAIC,SAAS,GAAG,CAACP,OAAO,CAACK,OAAR,IAAmB,EAApB,EAAwBV,GAAxB,CAA4B,UAACa,CAAD;AAAA,aAAOA,CAAC,CAACZ,EAAT;AAAA,KAA5B,CAAhB;AAEA,WAAO,yBAAQW,SAAS,CAACV,IAAV,EAAR,EAA0BO,kBAA1B,CAAP;AACD,GAJD,MAIO,IAAI,EAAEA,kBAAkB,IAAIA,kBAAkB,CAACE,MAA3C,CAAJ,EAAwD;AAC7D,WAAO,IAAP;AACD;;AAED,SAAO,KAAP;AACD,CApBM","sourcesContent":["import isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\n\nexport const getCorrectResponse = (choices) =>\n choices\n .filter((c) => c.correct)\n .map((c) => c.id)\n .sort();\n\nexport const isResponseCorrect = (question, session) => {\n const {\n shapes: { rectangles, polygons },\n } = question;\n const choices = [...rectangles, ...polygons];\n let correctResponseIds = getCorrectResponse(choices);\n\n if (!session || isEmpty(session)) {\n return false;\n }\n\n if (session.answers && session.answers.length) {\n let answerIds = (session.answers || []).map((a) => a.id);\n\n return isEqual(answerIds.sort(), correctResponseIds);\n } else if (!(correctResponseIds && correctResponseIds.length)) {\n return true;\n }\n\n return false;\n};\n"],"file":"utils.js"}