@pie-element/hotspot 11.1.2-next.2 → 11.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +997 -0
- package/CHANGELOG.md +2220 -0
- package/LICENSE.md +5 -0
- package/README.md +1 -0
- package/configure/CHANGELOG.json +682 -0
- package/configure/CHANGELOG.md +1957 -0
- package/configure/lib/DeleteWidget.js +64 -0
- package/configure/lib/DeleteWidget.js.map +1 -0
- package/configure/lib/button.js +42 -0
- package/configure/lib/button.js.map +1 -0
- package/configure/lib/buttons/circle.js +33 -0
- package/configure/lib/buttons/circle.js.map +1 -0
- package/configure/lib/buttons/polygon.js +39 -0
- package/configure/lib/buttons/polygon.js.map +1 -0
- package/configure/lib/buttons/rectangle.js +39 -0
- package/configure/lib/buttons/rectangle.js.map +1 -0
- package/configure/lib/defaults.js +155 -0
- package/configure/lib/defaults.js.map +1 -0
- package/configure/lib/hotspot-circle.js +192 -0
- package/configure/lib/hotspot-circle.js.map +1 -0
- package/configure/lib/hotspot-container.js +320 -0
- package/configure/lib/hotspot-container.js.map +1 -0
- package/configure/lib/hotspot-drawable.js +519 -0
- package/configure/lib/hotspot-drawable.js.map +1 -0
- package/configure/lib/hotspot-palette.js +107 -0
- package/configure/lib/hotspot-palette.js.map +1 -0
- package/configure/lib/hotspot-polygon.js +293 -0
- package/configure/lib/hotspot-polygon.js.map +1 -0
- package/configure/lib/hotspot-rectangle.js +190 -0
- package/configure/lib/hotspot-rectangle.js.map +1 -0
- package/configure/lib/icons.js +7 -0
- package/configure/lib/icons.js.map +1 -0
- package/configure/lib/image-konva.js +66 -0
- package/configure/lib/image-konva.js.map +1 -0
- package/configure/lib/index.js +194 -0
- package/configure/lib/index.js.map +1 -0
- package/configure/lib/root.js +330 -0
- package/configure/lib/root.js.map +1 -0
- package/configure/lib/shapes/circle.js +84 -0
- package/configure/lib/shapes/circle.js.map +1 -0
- package/configure/lib/shapes/index.js +50 -0
- package/configure/lib/shapes/index.js.map +1 -0
- package/configure/lib/shapes/polygon.js +82 -0
- package/configure/lib/shapes/polygon.js.map +1 -0
- package/configure/lib/shapes/rectagle.js +84 -0
- package/configure/lib/shapes/rectagle.js.map +1 -0
- package/configure/lib/shapes/utils.js +21 -0
- package/configure/lib/shapes/utils.js.map +1 -0
- package/configure/lib/upload-control.js +41 -0
- package/configure/lib/upload-control.js.map +1 -0
- package/configure/lib/utils.js +185 -0
- package/configure/lib/utils.js.map +1 -0
- package/configure/package.json +26 -0
- package/configure/src/DeleteWidget.jsx +51 -0
- package/configure/src/__tests__/DeleteWidget.test.jsx +366 -0
- package/configure/src/__tests__/button.test.jsx +198 -0
- package/configure/src/__tests__/hotspot-circle.test.jsx +259 -0
- package/configure/src/__tests__/hotspot-container.test.js +366 -0
- package/configure/src/__tests__/hotspot-drawable.test.js +271 -0
- package/configure/src/__tests__/hotspot-palette.test.jsx +71 -0
- package/configure/src/__tests__/image-konva.test.jsx +226 -0
- package/configure/src/__tests__/index.test.js +329 -0
- package/configure/src/__tests__/root.test.js +400 -0
- package/configure/src/__tests__/utils.test.js +241 -0
- package/configure/src/button.jsx +35 -0
- package/configure/src/buttons/circle.jsx +18 -0
- package/configure/src/buttons/polygon.jsx +29 -0
- package/configure/src/buttons/rectangle.jsx +29 -0
- package/configure/src/defaults.js +109 -0
- package/configure/src/hotspot-circle.jsx +183 -0
- package/configure/src/hotspot-container.jsx +330 -0
- package/configure/src/hotspot-drawable.jsx +527 -0
- package/configure/src/hotspot-palette.jsx +90 -0
- package/configure/src/hotspot-polygon.jsx +294 -0
- package/configure/src/hotspot-rectangle.jsx +169 -0
- package/configure/src/icons.js +5 -0
- package/configure/src/image-konva.jsx +63 -0
- package/configure/src/index.js +208 -0
- package/configure/src/root.jsx +346 -0
- package/configure/src/shapes/circle.js +81 -0
- package/configure/src/shapes/index.js +4 -0
- package/configure/src/shapes/polygon.js +81 -0
- package/configure/src/shapes/rectagle.js +82 -0
- package/configure/src/shapes/utils.js +16 -0
- package/configure/src/upload-control.jsx +33 -0
- package/configure/src/utils.js +210 -0
- package/controller/CHANGELOG.json +362 -0
- package/controller/CHANGELOG.md +1304 -0
- package/controller/lib/defaults.js +33 -0
- package/controller/lib/defaults.js.map +1 -0
- package/controller/lib/index.js +341 -0
- package/controller/lib/index.js.map +1 -0
- package/controller/lib/utils.js +32 -0
- package/controller/lib/utils.js.map +1 -0
- package/controller/package.json +18 -0
- package/controller/src/__tests__/index.test.js +419 -0
- package/controller/src/__tests__/utils.test.js +5 -0
- package/controller/src/defaults.js +19 -0
- package/controller/src/index.js +328 -0
- package/controller/src/utils.js +29 -0
- package/docs/config-schema.json +2023 -0
- package/docs/config-schema.json.md +1495 -0
- package/docs/demo/config.js +8 -0
- package/docs/demo/generate.js +118 -0
- package/docs/demo/index.html +1 -0
- package/docs/demo/session.js +11 -0
- package/docs/pie-schema.json +1204 -0
- package/docs/pie-schema.json.md +851 -0
- package/lib/hotspot/circle.js +156 -0
- package/lib/hotspot/circle.js.map +1 -0
- package/lib/hotspot/container.js +206 -0
- package/lib/hotspot/container.js.map +1 -0
- package/lib/hotspot/icons.js +8 -0
- package/lib/hotspot/icons.js.map +1 -0
- package/lib/hotspot/image-konva-tooltip.js +86 -0
- package/lib/hotspot/image-konva-tooltip.js.map +1 -0
- package/lib/hotspot/index.js +163 -0
- package/lib/hotspot/index.js.map +1 -0
- package/lib/hotspot/polygon.js +203 -0
- package/lib/hotspot/polygon.js.map +1 -0
- package/lib/hotspot/rectangle.js +175 -0
- package/lib/hotspot/rectangle.js.map +1 -0
- package/lib/index.js +213 -0
- package/lib/index.js.map +1 -0
- package/lib/session-updater.js +42 -0
- package/lib/session-updater.js.map +1 -0
- package/package.json +18 -83
- package/src/__tests__/container.test.jsx +58 -0
- package/src/__tests__/index.test.js +123 -0
- package/src/__tests__/session-updater.test.jsx +69 -0
- package/src/hotspot/__tests__/circle.test.jsx +464 -0
- package/src/hotspot/__tests__/container.test.jsx +546 -0
- package/src/hotspot/__tests__/image-konva-tooltip.test.jsx +510 -0
- package/src/hotspot/__tests__/polygon.test.jsx +502 -0
- package/src/hotspot/__tests__/rectangle.test.jsx +418 -0
- package/src/hotspot/circle.jsx +152 -0
- package/src/hotspot/container.jsx +217 -0
- package/src/hotspot/icons.js +7 -0
- package/src/hotspot/image-konva-tooltip.jsx +76 -0
- package/src/hotspot/index.jsx +165 -0
- package/src/hotspot/polygon.jsx +195 -0
- package/src/hotspot/rectangle.jsx +171 -0
- package/src/index.js +226 -0
- package/src/session-updater.js +29 -0
- package/configure.js +0 -2
- package/controller.js +0 -1
- package/dist/author/DeleteWidget.d.ts +0 -38
- package/dist/author/DeleteWidget.js +0 -46
- package/dist/author/button.d.ts +0 -31
- package/dist/author/button.js +0 -27
- package/dist/author/buttons/circle.d.ts +0 -18
- package/dist/author/buttons/circle.js +0 -25
- package/dist/author/buttons/polygon.d.ts +0 -18
- package/dist/author/buttons/polygon.js +0 -36
- package/dist/author/buttons/rectangle.d.ts +0 -18
- package/dist/author/buttons/rectangle.js +0 -36
- package/dist/author/defaults.d.ts +0 -157
- package/dist/author/defaults.js +0 -119
- package/dist/author/hotspot-circle.d.ts +0 -21
- package/dist/author/hotspot-circle.js +0 -124
- package/dist/author/hotspot-container.d.ts +0 -29
- package/dist/author/hotspot-container.js +0 -210
- package/dist/author/hotspot-drawable.d.ts +0 -31
- package/dist/author/hotspot-drawable.js +0 -312
- package/dist/author/hotspot-palette.d.ts +0 -14
- package/dist/author/hotspot-palette.js +0 -72
- package/dist/author/hotspot-polygon.d.ts +0 -38
- package/dist/author/hotspot-polygon.js +0 -200
- package/dist/author/hotspot-rectangle.d.ts +0 -20
- package/dist/author/hotspot-rectangle.js +0 -119
- package/dist/author/icons.d.ts +0 -9
- package/dist/author/icons.js +0 -4
- package/dist/author/image-konva.d.ts +0 -19
- package/dist/author/image-konva.js +0 -49
- package/dist/author/index.d.ts +0 -52
- package/dist/author/index.js +0 -143
- package/dist/author/root.d.ts +0 -15
- package/dist/author/root.js +0 -215
- package/dist/author/shapes/circle.d.ts +0 -18
- package/dist/author/shapes/circle.js +0 -47
- package/dist/author/shapes/index.d.ts +0 -12
- package/dist/author/shapes/polygon.d.ts +0 -19
- package/dist/author/shapes/polygon.js +0 -51
- package/dist/author/shapes/rectagle.d.ts +0 -18
- package/dist/author/shapes/rectagle.js +0 -57
- package/dist/author/shapes/utils.d.ts +0 -19
- package/dist/author/shapes/utils.js +0 -16
- package/dist/author/upload-control.d.ts +0 -29
- package/dist/author/upload-control.js +0 -28
- package/dist/author/utils.d.ts +0 -24
- package/dist/author/utils.js +0 -83
- package/dist/browser/ReactKonva-DI5WIo8o.js +0 -19336
- package/dist/browser/ReactKonva-DI5WIo8o.js.map +0 -1
- package/dist/browser/author/index.js +0 -41646
- package/dist/browser/author/index.js.map +0 -1
- package/dist/browser/browser-CfnAFove.js +0 -219
- package/dist/browser/browser-CfnAFove.js.map +0 -1
- package/dist/browser/controller/index.js +0 -198
- package/dist/browser/controller/index.js.map +0 -1
- package/dist/browser/delivery/index.js +0 -2460
- package/dist/browser/delivery/index.js.map +0 -1
- package/dist/browser/dist-C78LDz6R.js +0 -96
- package/dist/browser/dist-C78LDz6R.js.map +0 -1
- package/dist/browser/hotspot.css +0 -2
- package/dist/controller/defaults.d.ts +0 -35
- package/dist/controller/defaults.js +0 -29
- package/dist/controller/index.d.ts +0 -22
- package/dist/controller/index.js +0 -154
- package/dist/controller/utils.d.ts +0 -10
- package/dist/controller/utils.js +0 -12
- package/dist/delivery/hotspot/circle.d.ts +0 -19
- package/dist/delivery/hotspot/circle.js +0 -100
- package/dist/delivery/hotspot/container.d.ts +0 -16
- package/dist/delivery/hotspot/container.js +0 -150
- package/dist/delivery/hotspot/icons.d.ts +0 -10
- package/dist/delivery/hotspot/icons.js +0 -4
- package/dist/delivery/hotspot/image-konva-tooltip.d.ts +0 -19
- package/dist/delivery/hotspot/image-konva-tooltip.js +0 -66
- package/dist/delivery/hotspot/index.d.ts +0 -17
- package/dist/delivery/hotspot/index.js +0 -114
- package/dist/delivery/hotspot/polygon.d.ts +0 -21
- package/dist/delivery/hotspot/polygon.js +0 -108
- package/dist/delivery/hotspot/rectangle.d.ts +0 -19
- package/dist/delivery/hotspot/rectangle.js +0 -104
- package/dist/delivery/index.d.ts +0 -20
- package/dist/delivery/index.js +0 -107
- package/dist/delivery/session-updater.d.ts +0 -10
- package/dist/delivery/session-updater.js +0 -14
- package/dist/index.d.ts +0 -1
- package/dist/index.iife.d.ts +0 -8
- package/dist/index.iife.js +0 -169
- package/dist/index.js +0 -2
- package/dist/runtime-support.d.ts +0 -12
- package/dist/runtime-support.js +0 -12
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _reactKonva = require("react-konva");
|
|
12
|
+
var _imageKonvaTooltip = _interopRequireDefault(require("./image-konva-tooltip"));
|
|
13
|
+
var _icons = require("./icons");
|
|
14
|
+
class PolygonComponent extends _react.default.Component {
|
|
15
|
+
constructor(props) {
|
|
16
|
+
super(props);
|
|
17
|
+
(0, _defineProperty2.default)(this, "getPolygonCenter", points => {
|
|
18
|
+
const x = points.map(({
|
|
19
|
+
x
|
|
20
|
+
}) => x);
|
|
21
|
+
const y = points.map(({
|
|
22
|
+
y
|
|
23
|
+
}) => y);
|
|
24
|
+
const minX = Math.min.apply(null, x);
|
|
25
|
+
const maxX = Math.max.apply(null, x);
|
|
26
|
+
const minY = Math.min.apply(null, y);
|
|
27
|
+
const maxY = Math.max.apply(null, y);
|
|
28
|
+
return [(minX + maxX) / 2, (minY + maxY) / 2];
|
|
29
|
+
});
|
|
30
|
+
(0, _defineProperty2.default)(this, "parsePointsForKonva", points => {
|
|
31
|
+
const parsedPoints = [];
|
|
32
|
+
points.forEach(({
|
|
33
|
+
x,
|
|
34
|
+
y
|
|
35
|
+
}) => {
|
|
36
|
+
parsedPoints.push(x);
|
|
37
|
+
parsedPoints.push(y);
|
|
38
|
+
});
|
|
39
|
+
return parsedPoints;
|
|
40
|
+
});
|
|
41
|
+
(0, _defineProperty2.default)(this, "handleClick", e => {
|
|
42
|
+
const {
|
|
43
|
+
onClick,
|
|
44
|
+
id,
|
|
45
|
+
selected,
|
|
46
|
+
disabled
|
|
47
|
+
} = this.props;
|
|
48
|
+
if (!disabled) {
|
|
49
|
+
e.cancelBubble = true;
|
|
50
|
+
onClick({
|
|
51
|
+
id,
|
|
52
|
+
selected: !selected,
|
|
53
|
+
selector: 'Mouse'
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
(0, _defineProperty2.default)(this, "handleMouseEnter", () => {
|
|
58
|
+
const {
|
|
59
|
+
disabled
|
|
60
|
+
} = this.props;
|
|
61
|
+
if (!disabled) {
|
|
62
|
+
document.body.style.cursor = 'pointer';
|
|
63
|
+
}
|
|
64
|
+
this.setState({
|
|
65
|
+
hovered: true
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
(0, _defineProperty2.default)(this, "handleMouseLeave", () => {
|
|
69
|
+
document.body.style.cursor = 'default';
|
|
70
|
+
this.setState({
|
|
71
|
+
hovered: false
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
(0, _defineProperty2.default)(this, "getEvaluateOutlineColor", (isCorrect, markAsCorrect, outlineColor) => markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red');
|
|
75
|
+
(0, _defineProperty2.default)(this, "getOutlineWidth", (showCorrectEnabled, selected, markAsCorrect, strokeWidth) => markAsCorrect || !markAsCorrect && !showCorrectEnabled && selected ? strokeWidth : 0);
|
|
76
|
+
this.state = {
|
|
77
|
+
hovered: false
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
render() {
|
|
81
|
+
const {
|
|
82
|
+
hotspotColor,
|
|
83
|
+
isCorrect,
|
|
84
|
+
isEvaluateMode,
|
|
85
|
+
hoverOutlineColor,
|
|
86
|
+
outlineColor,
|
|
87
|
+
selected,
|
|
88
|
+
points,
|
|
89
|
+
evaluateText,
|
|
90
|
+
strokeWidth,
|
|
91
|
+
scale,
|
|
92
|
+
markAsCorrect,
|
|
93
|
+
selectedHotspotColor,
|
|
94
|
+
showCorrectEnabled
|
|
95
|
+
} = this.props;
|
|
96
|
+
const {
|
|
97
|
+
hovered
|
|
98
|
+
} = this.state;
|
|
99
|
+
const outlineColorParsed = isEvaluateMode ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor) : outlineColor;
|
|
100
|
+
const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);
|
|
101
|
+
const pointsParsed = this.parsePointsForKonva(points);
|
|
102
|
+
const center = this.getPolygonCenter(points);
|
|
103
|
+
const iconX = center[0];
|
|
104
|
+
const iconY = center[1];
|
|
105
|
+
|
|
106
|
+
// "Show Correct Answer" Enabled:
|
|
107
|
+
// - Correctly Selected: white checkmark in green circle
|
|
108
|
+
// - Correctly Not Selected: none
|
|
109
|
+
// - Incorrectly Selected: none
|
|
110
|
+
// - Incorrectly Not Selected: white checkmark in green circle
|
|
111
|
+
// "Show Correct Answer" Disabled:
|
|
112
|
+
// - Correctly Selected:
|
|
113
|
+
// - white checkmark in green circle
|
|
114
|
+
// - heavy outline, as on “Gather”
|
|
115
|
+
// - Correctly Not Selected: none
|
|
116
|
+
// - Incorrectly Selected:
|
|
117
|
+
// - white "X" in red circle
|
|
118
|
+
// - heavy outline around the selection should appear in red
|
|
119
|
+
// - Incorrectly Not Selected: white "X" in red circle
|
|
120
|
+
let iconSrc;
|
|
121
|
+
if (showCorrectEnabled) {
|
|
122
|
+
if (selected && isCorrect || !selected && !isCorrect) {
|
|
123
|
+
iconSrc = _icons.faCorrect;
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
if (selected) {
|
|
127
|
+
if (isCorrect) {
|
|
128
|
+
iconSrc = _icons.faCorrect;
|
|
129
|
+
} else {
|
|
130
|
+
iconSrc = _icons.faWrong;
|
|
131
|
+
}
|
|
132
|
+
} else if (!isCorrect) {
|
|
133
|
+
iconSrc = _icons.faWrong;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const useHoveredStyle = hovered && hoverOutlineColor;
|
|
137
|
+
const xValues = pointsParsed.filter((_, index) => index % 2 === 0); // Even indices are x-coordinates
|
|
138
|
+
const yValues = pointsParsed.filter((_, index) => index % 2 !== 0); // Odd indices are y-coordinates
|
|
139
|
+
|
|
140
|
+
const minX = Math.min(...xValues);
|
|
141
|
+
const maxX = Math.max(...xValues);
|
|
142
|
+
const minY = Math.min(...yValues);
|
|
143
|
+
const maxY = Math.max(...yValues);
|
|
144
|
+
const rectX = minX;
|
|
145
|
+
const rectY = minY;
|
|
146
|
+
const rectWidth = maxX - minX;
|
|
147
|
+
const rectHeight = maxY - minY;
|
|
148
|
+
return /*#__PURE__*/_react.default.createElement(_reactKonva.Group, {
|
|
149
|
+
scaleX: scale,
|
|
150
|
+
scaleY: scale
|
|
151
|
+
}, useHoveredStyle && /*#__PURE__*/_react.default.createElement(_reactKonva.Rect, {
|
|
152
|
+
x: rectX,
|
|
153
|
+
y: rectY,
|
|
154
|
+
width: rectWidth,
|
|
155
|
+
height: rectHeight,
|
|
156
|
+
stroke: selected ? 'transparent' : hoverOutlineColor,
|
|
157
|
+
strokeWidth: strokeWidth
|
|
158
|
+
}), /*#__PURE__*/_react.default.createElement(_reactKonva.Line, {
|
|
159
|
+
points: pointsParsed,
|
|
160
|
+
closed: true,
|
|
161
|
+
fill: selected && selectedHotspotColor ? selectedHotspotColor : hotspotColor,
|
|
162
|
+
onClick: this.handleClick,
|
|
163
|
+
onTap: this.handleClick,
|
|
164
|
+
draggable: false,
|
|
165
|
+
stroke: useHoveredStyle && !selected ? 'transparent' : outlineColorParsed,
|
|
166
|
+
strokeWidth: useHoveredStyle && !selected ? 0 : outlineWidth,
|
|
167
|
+
onMouseLeave: this.handleMouseLeave,
|
|
168
|
+
onMouseEnter: this.handleMouseEnter,
|
|
169
|
+
cursor: "pointer",
|
|
170
|
+
position: "relative"
|
|
171
|
+
}), isEvaluateMode && iconSrc ? /*#__PURE__*/_react.default.createElement(_imageKonvaTooltip.default, {
|
|
172
|
+
src: iconSrc,
|
|
173
|
+
x: iconX,
|
|
174
|
+
y: iconY,
|
|
175
|
+
tooltip: evaluateText
|
|
176
|
+
}) : null);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
PolygonComponent.propTypes = {
|
|
180
|
+
hotspotColor: _propTypes.default.string.isRequired,
|
|
181
|
+
id: _propTypes.default.string.isRequired,
|
|
182
|
+
isCorrect: _propTypes.default.bool.isRequired,
|
|
183
|
+
isEvaluateMode: _propTypes.default.bool.isRequired,
|
|
184
|
+
hoverOutlineColor: _propTypes.default.string,
|
|
185
|
+
disabled: _propTypes.default.bool.isRequired,
|
|
186
|
+
onClick: _propTypes.default.func.isRequired,
|
|
187
|
+
outlineColor: _propTypes.default.string.isRequired,
|
|
188
|
+
points: _propTypes.default.array.isRequired,
|
|
189
|
+
selected: _propTypes.default.bool.isRequired,
|
|
190
|
+
evaluateText: _propTypes.default.string,
|
|
191
|
+
selectedHotspotColor: _propTypes.default.string,
|
|
192
|
+
strokeWidth: _propTypes.default.number,
|
|
193
|
+
scale: _propTypes.default.number,
|
|
194
|
+
markAsCorrect: _propTypes.default.bool.isRequired,
|
|
195
|
+
showCorrectEnabled: _propTypes.default.bool.isRequired
|
|
196
|
+
};
|
|
197
|
+
PolygonComponent.defaultProps = {
|
|
198
|
+
evaluateText: null,
|
|
199
|
+
strokeWidth: 5,
|
|
200
|
+
scale: 1
|
|
201
|
+
};
|
|
202
|
+
var _default = exports.default = PolygonComponent;
|
|
203
|
+
//# sourceMappingURL=polygon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polygon.js","names":["_react","_interopRequireDefault","require","_propTypes","_reactKonva","_imageKonvaTooltip","_icons","PolygonComponent","React","Component","constructor","props","_defineProperty2","default","points","x","map","y","minX","Math","min","apply","maxX","max","minY","maxY","parsedPoints","forEach","push","e","onClick","id","selected","disabled","cancelBubble","selector","document","body","style","cursor","setState","hovered","isCorrect","markAsCorrect","outlineColor","showCorrectEnabled","strokeWidth","state","render","hotspotColor","isEvaluateMode","hoverOutlineColor","evaluateText","scale","selectedHotspotColor","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","pointsParsed","parsePointsForKonva","center","getPolygonCenter","iconX","iconY","iconSrc","faCorrect","faWrong","useHoveredStyle","xValues","filter","_","index","yValues","rectX","rectY","rectWidth","rectHeight","createElement","Group","scaleX","scaleY","Rect","width","height","stroke","Line","closed","fill","handleClick","onTap","draggable","onMouseLeave","handleMouseLeave","onMouseEnter","handleMouseEnter","position","src","tooltip","propTypes","PropTypes","string","isRequired","bool","func","array","number","defaultProps","_default","exports"],"sources":["../../src/hotspot/polygon.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Line, Group, Rect } from 'react-konva';\nimport ImageComponent from './image-konva-tooltip';\nimport { faCorrect, faWrong } from './icons';\n\nclass PolygonComponent extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n hovered: false,\n };\n }\n\n getPolygonCenter = (points) => {\n const x = points.map(({ x }) => x);\n const y = points.map(({ y }) => y);\n const minX = Math.min.apply(null, x);\n const maxX = Math.max.apply(null, x);\n const minY = Math.min.apply(null, y);\n const maxY = Math.max.apply(null, y);\n return [(minX + maxX) / 2, (minY + maxY) / 2];\n };\n\n parsePointsForKonva = (points) => {\n const parsedPoints = [];\n points.forEach(({ x, y }) => {\n parsedPoints.push(x);\n parsedPoints.push(y);\n });\n return parsedPoints;\n };\n\n handleClick = (e) => {\n const { onClick, id, selected, disabled } = this.props;\n\n if (!disabled) {\n e.cancelBubble = true;\n onClick({ id, selected: !selected, selector: 'Mouse' });\n }\n };\n\n handleMouseEnter = () => {\n const { disabled } = this.props;\n\n if (!disabled) {\n document.body.style.cursor = 'pointer';\n }\n this.setState({ hovered: true });\n };\n\n handleMouseLeave = () => {\n document.body.style.cursor = 'default';\n this.setState({ hovered: false });\n };\n\n getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) =>\n markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red';\n\n getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) =>\n markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;\n\n render() {\n const {\n hotspotColor,\n isCorrect,\n isEvaluateMode,\n hoverOutlineColor,\n outlineColor,\n selected,\n points,\n evaluateText,\n strokeWidth,\n scale,\n markAsCorrect,\n selectedHotspotColor,\n showCorrectEnabled,\n } = this.props;\n\n const { hovered } = this.state;\n\n const outlineColorParsed = isEvaluateMode\n ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor)\n : outlineColor;\n const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);\n\n const pointsParsed = this.parsePointsForKonva(points);\n const center = this.getPolygonCenter(points);\n const iconX = center[0];\n const iconY = center[1];\n\n // \"Show Correct Answer\" Enabled:\n // - Correctly Selected: white checkmark in green circle\n // - Correctly Not Selected: none\n // - Incorrectly Selected: none\n // - Incorrectly Not Selected: white checkmark in green circle\n // \"Show Correct Answer\" Disabled:\n // - Correctly Selected:\n // - white checkmark in green circle\n // - heavy outline, as on “Gather”\n // - Correctly Not Selected: none\n // - Incorrectly Selected:\n // - white \"X\" in red circle\n // - heavy outline around the selection should appear in red\n // - Incorrectly Not Selected: white \"X\" in red circle\n let iconSrc;\n\n if (showCorrectEnabled) {\n if ((selected && isCorrect) || (!selected && !isCorrect)) {\n iconSrc = faCorrect;\n }\n } else {\n if (selected) {\n if (isCorrect) {\n iconSrc = faCorrect;\n } else {\n iconSrc = faWrong;\n }\n } else if (!isCorrect) {\n iconSrc = faWrong;\n }\n }\n const useHoveredStyle = hovered && hoverOutlineColor;\n\n const xValues = pointsParsed.filter((_, index) => index % 2 === 0); // Even indices are x-coordinates\n const yValues = pointsParsed.filter((_, index) => index % 2 !== 0); // Odd indices are y-coordinates\n\n const minX = Math.min(...xValues);\n const maxX = Math.max(...xValues);\n const minY = Math.min(...yValues);\n const maxY = Math.max(...yValues);\n\n const rectX = minX;\n const rectY = minY;\n const rectWidth = maxX - minX;\n const rectHeight = maxY - minY;\n\n return (\n <Group scaleX={scale} scaleY={scale}>\n {useHoveredStyle && (\n <Rect\n x={rectX}\n y={rectY}\n width={rectWidth}\n height={rectHeight}\n stroke={selected ? 'transparent' : hoverOutlineColor}\n strokeWidth={strokeWidth}\n />\n )}\n <Line\n points={pointsParsed}\n closed={true}\n fill={selected && selectedHotspotColor? selectedHotspotColor : hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable={false}\n stroke={useHoveredStyle && !selected ? 'transparent' : outlineColorParsed}\n strokeWidth={useHoveredStyle && !selected ? 0 : outlineWidth}\n onMouseLeave={this.handleMouseLeave}\n onMouseEnter={this.handleMouseEnter}\n cursor='pointer'\n position='relative'\n />\n {isEvaluateMode && iconSrc ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}\n </Group>\n );\n }\n}\n\nPolygonComponent.propTypes = {\n hotspotColor: PropTypes.string.isRequired,\n id: PropTypes.string.isRequired,\n isCorrect: PropTypes.bool.isRequired,\n isEvaluateMode: PropTypes.bool.isRequired,\n hoverOutlineColor: PropTypes.string,\n disabled: PropTypes.bool.isRequired,\n onClick: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n points: PropTypes.array.isRequired,\n selected: PropTypes.bool.isRequired,\n evaluateText: PropTypes.string,\n selectedHotspotColor: PropTypes.string,\n strokeWidth: PropTypes.number,\n scale: PropTypes.number,\n markAsCorrect: PropTypes.bool.isRequired,\n showCorrectEnabled: PropTypes.bool.isRequired,\n};\n\nPolygonComponent.defaultProps = {\n evaluateText: null,\n strokeWidth: 5,\n scale: 1,\n};\n\nexport default PolygonComponent;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,MAAMK,gBAAgB,SAASC,cAAK,CAACC,SAAS,CAAC;EAC7CC,WAAWA,CAACC,KAAK,EAAE;IACjB,KAAK,CAACA,KAAK,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA,4BAMKC,MAAM,IAAK;MAC7B,MAAMC,CAAC,GAAGD,MAAM,CAACE,GAAG,CAAC,CAAC;QAAED;MAAE,CAAC,KAAKA,CAAC,CAAC;MAClC,MAAME,CAAC,GAAGH,MAAM,CAACE,GAAG,CAAC,CAAC;QAAEC;MAAE,CAAC,KAAKA,CAAC,CAAC;MAClC,MAAMC,IAAI,GAAGC,IAAI,CAACC,GAAG,CAACC,KAAK,CAAC,IAAI,EAAEN,CAAC,CAAC;MACpC,MAAMO,IAAI,GAAGH,IAAI,CAACI,GAAG,CAACF,KAAK,CAAC,IAAI,EAAEN,CAAC,CAAC;MACpC,MAAMS,IAAI,GAAGL,IAAI,CAACC,GAAG,CAACC,KAAK,CAAC,IAAI,EAAEJ,CAAC,CAAC;MACpC,MAAMQ,IAAI,GAAGN,IAAI,CAACI,GAAG,CAACF,KAAK,CAAC,IAAI,EAAEJ,CAAC,CAAC;MACpC,OAAO,CAAC,CAACC,IAAI,GAAGI,IAAI,IAAI,CAAC,EAA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AACC,MAAM,CAACC,UAAU;EACzCvE,EAAE,EAAEqE,kBAAS,CAACC,MAAM,CAACC,UAAU;EAC/B5D,SAAS,EAAE0D,kBAAS,CAACG,IAAI,CAACD,UAAU;EACpCpD,cAAc,EAAEkD,kBAAS,CAACG,IAAI,CAACD,UAAU;EACzCnD,iBAAiB,EAAEiD,kBAAS,CAACC,MAAM;EACnCpE,QAAQ,EAAEmE,kBAAS,CAACG,IAAI,CAACD,UAAU;EACnCxE,OAAO,EAAEsE,kBAAS,CAACI,IAAI,CAACF,UAAU;EAClC1D,YAAY,EAAEwD,kBAAS,CAACC,MAAM,CAACC,UAAU;EACzCxF,MAAM,EAAEsF,kBAAS,CAACK,KAAK,CAACH,UAAU;EAClCtE,QAAQ,EAAEoE,kBAAS,CAACG,IAAI,CAACD,UAAU;EACnClD,YAAY,EAAEgD,kBAAS,CAACC,MAAM;EAC9B/C,oBAAoB,EAAE8C,kBAAS,CAACC,MAAM;EACtCvD,WAAW,EAAEsD,kBAAS,CAACM,MAAM;EAC7BrD,KAAK,EAAE+C,kBAAS,CAACM,MAAM;EACvB/D,aAAa,EAAEyD,kBAAS,CAACG,IAAI,CAACD,UAAU;EACxCzD,kBAAkB,EAAEuD,kBAAS,CAACG,IAAI,CAACD;AACrC,CAAC;AAED/F,gBAAgB,CAACoG,YAAY,GAAG;EAC9BvD,YAAY,EAAE,IAAI;EAClBN,WAAW,EAAE,CAAC;EACdO,KAAK,EAAE;AACT,CAAC;AAAC,IAAAuD,QAAA,GAAAC,OAAA,CAAAhG,OAAA,GAEaN,gBAAgB","ignoreList":[]}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _reactKonva = require("react-konva");
|
|
12
|
+
var _imageKonvaTooltip = _interopRequireDefault(require("./image-konva-tooltip"));
|
|
13
|
+
var _icons = require("./icons");
|
|
14
|
+
class RectComponent extends _react.default.Component {
|
|
15
|
+
constructor(props) {
|
|
16
|
+
super(props);
|
|
17
|
+
(0, _defineProperty2.default)(this, "handleClick", e => {
|
|
18
|
+
const {
|
|
19
|
+
onClick,
|
|
20
|
+
id,
|
|
21
|
+
selected,
|
|
22
|
+
disabled
|
|
23
|
+
} = this.props;
|
|
24
|
+
if (!disabled) {
|
|
25
|
+
e.cancelBubble = true;
|
|
26
|
+
onClick({
|
|
27
|
+
id,
|
|
28
|
+
selected: !selected,
|
|
29
|
+
selector: 'Mouse'
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
(0, _defineProperty2.default)(this, "handleMouseEnter", () => {
|
|
34
|
+
const {
|
|
35
|
+
disabled
|
|
36
|
+
} = this.props;
|
|
37
|
+
if (!disabled) {
|
|
38
|
+
document.body.style.cursor = 'pointer';
|
|
39
|
+
}
|
|
40
|
+
this.setState({
|
|
41
|
+
hovered: true
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
(0, _defineProperty2.default)(this, "handleMouseLeave", () => {
|
|
45
|
+
document.body.style.cursor = 'default';
|
|
46
|
+
this.setState({
|
|
47
|
+
hovered: false
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
(0, _defineProperty2.default)(this, "getEvaluateOutlineColor", (isCorrect, markAsCorrect, outlineColor) => markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red');
|
|
51
|
+
(0, _defineProperty2.default)(this, "getOutlineWidth", (showCorrectEnabled, selected, markAsCorrect, strokeWidth) => markAsCorrect || !markAsCorrect && !showCorrectEnabled && selected ? strokeWidth : 0);
|
|
52
|
+
this.state = {
|
|
53
|
+
hovered: false
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
render() {
|
|
57
|
+
const {
|
|
58
|
+
height,
|
|
59
|
+
hotspotColor,
|
|
60
|
+
hoverOutlineColor,
|
|
61
|
+
selectedHotspotColor,
|
|
62
|
+
isCorrect,
|
|
63
|
+
isEvaluateMode,
|
|
64
|
+
outlineColor,
|
|
65
|
+
selected,
|
|
66
|
+
width,
|
|
67
|
+
x,
|
|
68
|
+
y,
|
|
69
|
+
evaluateText,
|
|
70
|
+
strokeWidth,
|
|
71
|
+
scale,
|
|
72
|
+
markAsCorrect,
|
|
73
|
+
showCorrectEnabled
|
|
74
|
+
} = this.props;
|
|
75
|
+
const outlineColorParsed = isEvaluateMode ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor) : outlineColor;
|
|
76
|
+
const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);
|
|
77
|
+
const iconX = x + width / 2 - 10;
|
|
78
|
+
const iconY = y + height / 2 - 10;
|
|
79
|
+
|
|
80
|
+
// "Show Correct Answer" Enabled:
|
|
81
|
+
// - Correctly Selected: white checkmark in green circle
|
|
82
|
+
// - Correctly Not Selected: none
|
|
83
|
+
// - Incorrectly Selected: none
|
|
84
|
+
// - Incorrectly Not Selected: white checkmark in green circle
|
|
85
|
+
// "Show Correct Answer" Disabled:
|
|
86
|
+
// - Correctly Selected:
|
|
87
|
+
// - white checkmark in green circle
|
|
88
|
+
// - heavy outline, as on “Gather”
|
|
89
|
+
// - Correctly Not Selected: none
|
|
90
|
+
// - Incorrectly Selected:
|
|
91
|
+
// - white "X" in red circle
|
|
92
|
+
// - heavy outline around the selection should appear in red
|
|
93
|
+
// - Incorrectly Not Selected: white "X" in red circle
|
|
94
|
+
let iconSrc;
|
|
95
|
+
if (showCorrectEnabled) {
|
|
96
|
+
if (selected && isCorrect || !selected && !isCorrect) {
|
|
97
|
+
iconSrc = _icons.faCorrect;
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
if (selected) {
|
|
101
|
+
if (isCorrect) {
|
|
102
|
+
iconSrc = _icons.faCorrect;
|
|
103
|
+
} else {
|
|
104
|
+
iconSrc = _icons.faWrong;
|
|
105
|
+
}
|
|
106
|
+
} else if (!isCorrect) {
|
|
107
|
+
iconSrc = _icons.faWrong;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const {
|
|
111
|
+
hovered
|
|
112
|
+
} = this.state;
|
|
113
|
+
const useHoveredStyle = hovered && hoverOutlineColor;
|
|
114
|
+
return /*#__PURE__*/_react.default.createElement(_reactKonva.Group, {
|
|
115
|
+
scaleX: scale,
|
|
116
|
+
scaleY: scale
|
|
117
|
+
}, useHoveredStyle && /*#__PURE__*/_react.default.createElement(_reactKonva.Rect, {
|
|
118
|
+
x: x,
|
|
119
|
+
y: y,
|
|
120
|
+
width: width,
|
|
121
|
+
height: height,
|
|
122
|
+
stroke: selected ? 'transparent' : hoverOutlineColor,
|
|
123
|
+
strokeWidth: strokeWidth,
|
|
124
|
+
listening: false
|
|
125
|
+
}), /*#__PURE__*/_react.default.createElement(_reactKonva.Rect, {
|
|
126
|
+
x: x,
|
|
127
|
+
y: y,
|
|
128
|
+
width: width,
|
|
129
|
+
height: height,
|
|
130
|
+
fill: selected && selectedHotspotColor ? selectedHotspotColor : hotspotColor,
|
|
131
|
+
onClick: this.handleClick,
|
|
132
|
+
onTap: this.handleClick,
|
|
133
|
+
draggable: false,
|
|
134
|
+
stroke: useHoveredStyle && !selected ? 'transparent' : outlineColorParsed,
|
|
135
|
+
strokeWidth: useHoveredStyle && !selected ? 0 : outlineWidth,
|
|
136
|
+
onMouseLeave: this.handleMouseLeave,
|
|
137
|
+
onMouseEnter: this.handleMouseEnter,
|
|
138
|
+
cursor: "pointer"
|
|
139
|
+
}), isEvaluateMode && iconSrc ? /*#__PURE__*/_react.default.createElement(_imageKonvaTooltip.default, {
|
|
140
|
+
src: iconSrc,
|
|
141
|
+
x: iconX,
|
|
142
|
+
y: iconY,
|
|
143
|
+
tooltip: evaluateText
|
|
144
|
+
}) : null);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
RectComponent.propTypes = {
|
|
148
|
+
height: _propTypes.default.number.isRequired,
|
|
149
|
+
hotspotColor: _propTypes.default.string.isRequired,
|
|
150
|
+
id: _propTypes.default.string.isRequired,
|
|
151
|
+
isCorrect: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.string]),
|
|
152
|
+
isEvaluateMode: _propTypes.default.bool.isRequired,
|
|
153
|
+
hoverOutlineColor: _propTypes.default.string,
|
|
154
|
+
disabled: _propTypes.default.bool.isRequired,
|
|
155
|
+
onClick: _propTypes.default.func.isRequired,
|
|
156
|
+
outlineColor: _propTypes.default.string.isRequired,
|
|
157
|
+
selected: _propTypes.default.bool.isRequired,
|
|
158
|
+
width: _propTypes.default.number.isRequired,
|
|
159
|
+
x: _propTypes.default.number.isRequired,
|
|
160
|
+
y: _propTypes.default.number.isRequired,
|
|
161
|
+
evaluateText: _propTypes.default.string,
|
|
162
|
+
strokeWidth: _propTypes.default.number,
|
|
163
|
+
scale: _propTypes.default.number,
|
|
164
|
+
selectedHotspotColor: _propTypes.default.string,
|
|
165
|
+
markAsCorrect: _propTypes.default.bool.isRequired,
|
|
166
|
+
showCorrectEnabled: _propTypes.default.bool.isRequired
|
|
167
|
+
};
|
|
168
|
+
RectComponent.defaultProps = {
|
|
169
|
+
isCorrect: false,
|
|
170
|
+
evaluateText: null,
|
|
171
|
+
strokeWidth: 5,
|
|
172
|
+
scale: 1
|
|
173
|
+
};
|
|
174
|
+
var _default = exports.default = RectComponent;
|
|
175
|
+
//# sourceMappingURL=rectangle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rectangle.js","names":["_react","_interopRequireDefault","require","_propTypes","_reactKonva","_imageKonvaTooltip","_icons","RectComponent","React","Component","constructor","props","_defineProperty2","default","e","onClick","id","selected","disabled","cancelBubble","selector","document","body","style","cursor","setState","hovered","isCorrect","markAsCorrect","outlineColor","showCorrectEnabled","strokeWidth","state","render","height","hotspotColor","hoverOutlineColor","selectedHotspotColor","isEvaluateMode","width","x","y","evaluateText","scale","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","iconX","iconY","iconSrc","faCorrect","faWrong","useHoveredStyle","createElement","Group","scaleX","scaleY","Rect","stroke","listening","fill","handleClick","onTap","draggable","onMouseLeave","handleMouseLeave","onMouseEnter","handleMouseEnter","src","tooltip","propTypes","PropTypes","number","isRequired","string","oneOfType","bool","func","defaultProps","_default","exports"],"sources":["../../src/hotspot/rectangle.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Rect, Group } from 'react-konva';\nimport ImageComponent from './image-konva-tooltip';\nimport { faCorrect, faWrong } from './icons';\n\nclass RectComponent extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n hovered: false,\n };\n }\n\n handleClick = (e) => {\n const { onClick, id, selected, disabled } = this.props;\n\n if (!disabled) {\n e.cancelBubble = true;\n onClick({ id, selected: !selected, selector: 'Mouse' });\n }\n };\n\n handleMouseEnter = () => {\n const { disabled } = this.props;\n\n if (!disabled) {\n document.body.style.cursor = 'pointer';\n }\n this.setState({ hovered: true });\n };\n\n handleMouseLeave = () => {\n document.body.style.cursor = 'default';\n this.setState({ hovered: false });\n };\n\n getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) =>\n markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red';\n\n getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) =>\n markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;\n\n render() {\n const {\n height,\n hotspotColor,\n hoverOutlineColor,\n selectedHotspotColor,\n isCorrect,\n isEvaluateMode,\n outlineColor,\n selected,\n width,\n x,\n y,\n evaluateText,\n strokeWidth,\n scale,\n markAsCorrect,\n showCorrectEnabled,\n } = this.props;\n\n const outlineColorParsed = isEvaluateMode\n ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor)\n : outlineColor;\n\n const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);\n\n const iconX = x + width / 2 - 10;\n const iconY = y + height / 2 - 10;\n\n // \"Show Correct Answer\" Enabled:\n // - Correctly Selected: white checkmark in green circle\n // - Correctly Not Selected: none\n // - Incorrectly Selected: none\n // - Incorrectly Not Selected: white checkmark in green circle\n // \"Show Correct Answer\" Disabled:\n // - Correctly Selected:\n // - white checkmark in green circle\n // - heavy outline, as on “Gather”\n // - Correctly Not Selected: none\n // - Incorrectly Selected:\n // - white \"X\" in red circle\n // - heavy outline around the selection should appear in red\n // - Incorrectly Not Selected: white \"X\" in red circle\n let iconSrc;\n\n if (showCorrectEnabled) {\n if ((selected && isCorrect) || (!selected && !isCorrect)) {\n iconSrc = faCorrect;\n }\n } else {\n if (selected) {\n if (isCorrect) {\n iconSrc = faCorrect;\n } else {\n iconSrc = faWrong;\n }\n } else if (!isCorrect) {\n iconSrc = faWrong;\n }\n }\n\n const { hovered } = this.state;\n const useHoveredStyle = hovered && hoverOutlineColor;\n\n return (\n <Group scaleX={scale} scaleY={scale}>\n {useHoveredStyle && (\n <Rect\n x={x}\n y={y}\n width={width}\n height={height}\n stroke={selected ? 'transparent' : hoverOutlineColor}\n strokeWidth={strokeWidth}\n listening={false}\n />\n )}\n <Rect\n x={x}\n y={y}\n width={width}\n height={height}\n fill={selected && selectedHotspotColor ? selectedHotspotColor : hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable={false}\n stroke={useHoveredStyle && !selected ? 'transparent' : outlineColorParsed}\n strokeWidth={useHoveredStyle && !selected ? 0 : outlineWidth}\n onMouseLeave={this.handleMouseLeave}\n onMouseEnter={this.handleMouseEnter}\n cursor=\"pointer\"\n />\n {isEvaluateMode && iconSrc ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}\n </Group>\n );\n }\n}\n\nRectComponent.propTypes = {\n height: PropTypes.number.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n id: PropTypes.string.isRequired,\n isCorrect: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),\n isEvaluateMode: PropTypes.bool.isRequired,\n hoverOutlineColor: PropTypes.string,\n disabled: PropTypes.bool.isRequired,\n onClick: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n selected: PropTypes.bool.isRequired,\n width: PropTypes.number.isRequired,\n x: PropTypes.number.isRequired,\n y: PropTypes.number.isRequired,\n evaluateText: PropTypes.string,\n strokeWidth: PropTypes.number,\n scale: PropTypes.number,\n selectedHotspotColor: PropTypes.string,\n markAsCorrect: PropTypes.bool.isRequired,\n showCorrectEnabled: PropTypes.bool.isRequired,\n};\n\nRectComponent.defaultProps = {\n isCorrect: false,\n evaluateText: null,\n strokeWidth: 5,\n scale: 1,\n};\n\nexport default RectComponent;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,MAAMK,aAAa,SAASC,cAAK,CAACC,SAAS,CAAC;EAC1CC,WAAWA,CAACC,KAAK,EAAE;IACjB,KAAK,CAACA,KAAK,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA,uBAMAC,CAAC,IAAK;MACnB,MAAM;QAAEC,OAAO;QAAEC,EAAE;QAAEC,QAAQ;QAAEC;MAAS,CAAC,GAAG,IAAI,CAACP,KAAK;MAEtD,IAAI,CAACO,QAAQ,EAAE;QACbJ,CAAC,CAACK,YAAY,GAAG,IAAI;QACrBJ,OAAO,CAAC;UAAEC,EAAE;UAAEC,QAAQ,EAAE,CAACA,Q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,CAAC,CAACJ,kBAAS,CAACK,IAAI,EAAEL,kBAAS,CAACG,MAAM,CAAC,CAAC;EAClErC,cAAc,EAAEkC,kBAAS,CAACK,IAAI,CAACH,UAAU;EACzCtC,iBAAiB,EAAEoC,kBAAS,CAACG,MAAM;EACnCzD,QAAQ,EAAEsD,kBAAS,CAACK,IAAI,CAACH,UAAU;EACnC3D,OAAO,EAAEyD,kBAAS,CAACM,IAAI,CAACJ,UAAU;EAClC7C,YAAY,EAAE2C,kBAAS,CAACG,MAAM,CAACD,UAAU;EACzCzD,QAAQ,EAAEuD,kBAAS,CAACK,IAAI,CAACH,UAAU;EACnCnC,KAAK,EAAEiC,kBAAS,CAACC,MAAM,CAACC,UAAU;EAClClC,CAAC,EAAEgC,kBAAS,CAACC,MAAM,CAACC,UAAU;EAC9BjC,CAAC,EAAE+B,kBAAS,CAACC,MAAM,CAACC,UAAU;EAC9BhC,YAAY,EAAE8B,kBAAS,CAACG,MAAM;EAC9B5C,WAAW,EAAEyC,kBAAS,CAACC,MAAM;EAC7B9B,KAAK,EAAE6B,kBAAS,CAACC,MAAM;EACvBpC,oBAAoB,EAAEmC,kBAAS,CAACG,MAAM;EACtC/C,aAAa,EAAE4C,kBAAS,CAACK,IAAI,CAACH,UAAU;EACxC5C,kBAAkB,EAAE0C,kBAAS,CAACK,IAAI,CAACH;AACrC,CAAC;AAEDnE,aAAa,CAACwE,YAAY,GAAG;EAC3BpD,SAAS,EAAE,KAAK;EAChBe,YAAY,EAAE,IAAI;EAClBX,WAAW,EAAE,CAAC;EACdY,KAAK,EAAE;AACT,CAAC;AAAC,IAAAqC,QAAA,GAAAC,OAAA,CAAApE,OAAA,GAEaN,aAAa","ignoreList":[]}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _client = require("react-dom/client");
|
|
10
|
+
var _mathRendering = require("@pie-lib/math-rendering");
|
|
11
|
+
var _renderUi = require("@pie-lib/render-ui");
|
|
12
|
+
var _piePlayerEvents = require("@pie-framework/pie-player-events");
|
|
13
|
+
var _hotspot = _interopRequireDefault(require("./hotspot"));
|
|
14
|
+
var _sessionUpdater = require("./session-updater");
|
|
15
|
+
class Hotspot extends HTMLElement {
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
this._model = null;
|
|
19
|
+
this._session = null;
|
|
20
|
+
this._audioInitialized = false;
|
|
21
|
+
this.audioComplete = false;
|
|
22
|
+
this._root = null;
|
|
23
|
+
}
|
|
24
|
+
set model(m) {
|
|
25
|
+
this._model = m;
|
|
26
|
+
this.dispatchEvent(new _piePlayerEvents.ModelSetEvent(this.tagName.toLowerCase(), this.isComplete(), !!this._model));
|
|
27
|
+
this._audioInitialized = false;
|
|
28
|
+
this._render();
|
|
29
|
+
}
|
|
30
|
+
isComplete() {
|
|
31
|
+
if (!this._session || !this._session.answers) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const {
|
|
35
|
+
autoplayAudioEnabled,
|
|
36
|
+
completeAudioEnabled
|
|
37
|
+
} = this._model || {};
|
|
38
|
+
const elementContext = this;
|
|
39
|
+
|
|
40
|
+
// check audio completion if audio settings are enabled and audio actually exists
|
|
41
|
+
if (autoplayAudioEnabled && completeAudioEnabled && !this.audioComplete) {
|
|
42
|
+
if (elementContext) {
|
|
43
|
+
const audio = elementContext.querySelector('audio');
|
|
44
|
+
const isInsidePrompt = audio && audio.closest('#preview-prompt');
|
|
45
|
+
|
|
46
|
+
// only require audio completion if audio exists and is inside the prompt
|
|
47
|
+
if (audio && isInsidePrompt) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!Array.isArray(this._session.answers)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return this._session.answers.length > 0;
|
|
56
|
+
}
|
|
57
|
+
set session(s) {
|
|
58
|
+
if (s && !s.answers) {
|
|
59
|
+
s.answers = [];
|
|
60
|
+
}
|
|
61
|
+
this._session = s;
|
|
62
|
+
this._render();
|
|
63
|
+
}
|
|
64
|
+
get session() {
|
|
65
|
+
return this._session;
|
|
66
|
+
}
|
|
67
|
+
onSelectChoice(data) {
|
|
68
|
+
(0, _sessionUpdater.updateSessionValue)(this._session, this._model, data);
|
|
69
|
+
this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(this.tagName.toLowerCase(), this.isComplete()));
|
|
70
|
+
this._render();
|
|
71
|
+
}
|
|
72
|
+
_createAudioInfoToast() {
|
|
73
|
+
const info = document.createElement('div');
|
|
74
|
+
info.id = 'play-audio-info';
|
|
75
|
+
Object.assign(info.style, {
|
|
76
|
+
position: 'absolute',
|
|
77
|
+
top: 0,
|
|
78
|
+
width: '100%',
|
|
79
|
+
height: '100%',
|
|
80
|
+
display: 'flex',
|
|
81
|
+
justifyContent: 'center',
|
|
82
|
+
alignItems: 'center',
|
|
83
|
+
background: 'white',
|
|
84
|
+
zIndex: '1000',
|
|
85
|
+
cursor: 'pointer'
|
|
86
|
+
});
|
|
87
|
+
const img = document.createElement('img');
|
|
88
|
+
img.src = _renderUi.EnableAudioAutoplayImage;
|
|
89
|
+
img.alt = 'Click anywhere to enable audio autoplay';
|
|
90
|
+
img.width = 500;
|
|
91
|
+
img.height = 300;
|
|
92
|
+
info.appendChild(img);
|
|
93
|
+
return info;
|
|
94
|
+
}
|
|
95
|
+
connectedCallback() {
|
|
96
|
+
this._render();
|
|
97
|
+
|
|
98
|
+
// Observation: audio in Chrome will have the autoplay attribute,
|
|
99
|
+
// while other browsers will not have the autoplay attribute and will need a user interaction to play the audio
|
|
100
|
+
// This workaround fixes the issue of audio being cached and played on any user interaction in Safari and Firefox
|
|
101
|
+
const observer = new MutationObserver((mutationsList, observer) => {
|
|
102
|
+
mutationsList.forEach(mutation => {
|
|
103
|
+
if (mutation.type === 'childList') {
|
|
104
|
+
if (this._audioInitialized) return;
|
|
105
|
+
const audio = this.querySelector('audio');
|
|
106
|
+
const isInsidePrompt = audio && audio.closest('#preview-prompt');
|
|
107
|
+
if (!this._model) return;
|
|
108
|
+
if (!this._model.autoplayAudioEnabled) return;
|
|
109
|
+
if (audio && !isInsidePrompt) return;
|
|
110
|
+
if (!audio) return;
|
|
111
|
+
const info = this._createAudioInfoToast();
|
|
112
|
+
const container = this.querySelector('#main-container');
|
|
113
|
+
const enableAudio = () => {
|
|
114
|
+
if (this.querySelector('#play-audio-info')) {
|
|
115
|
+
audio.play();
|
|
116
|
+
container.removeChild(info);
|
|
117
|
+
}
|
|
118
|
+
document.removeEventListener('click', enableAudio);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// if the audio is paused, it means the user has not interacted with the page yet and the audio will not play
|
|
122
|
+
// FIX FOR SAFARI: play with a slight delay to check if autoplay was blocked
|
|
123
|
+
setTimeout(() => {
|
|
124
|
+
if (audio.paused && !this.querySelector('#play-audio-info')) {
|
|
125
|
+
// add info message as a toast to enable audio playback
|
|
126
|
+
container.appendChild(info);
|
|
127
|
+
document.addEventListener('click', enableAudio);
|
|
128
|
+
} else {
|
|
129
|
+
document.removeEventListener('click', enableAudio);
|
|
130
|
+
}
|
|
131
|
+
}, 500);
|
|
132
|
+
|
|
133
|
+
// we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering
|
|
134
|
+
const handlePlaying = () => {
|
|
135
|
+
//timestamp when auto-played audio started playing
|
|
136
|
+
(0, _sessionUpdater.updateSessionMetadata)(this._session, {
|
|
137
|
+
audioStartTime: new Date().getTime()
|
|
138
|
+
});
|
|
139
|
+
const info = this.querySelector('#play-audio-info');
|
|
140
|
+
if (info) {
|
|
141
|
+
container.removeChild(info);
|
|
142
|
+
}
|
|
143
|
+
audio.removeEventListener('playing', handlePlaying);
|
|
144
|
+
};
|
|
145
|
+
audio.addEventListener('playing', handlePlaying);
|
|
146
|
+
|
|
147
|
+
// we need to listen for the ended event to update the isComplete state
|
|
148
|
+
const handleEnded = () => {
|
|
149
|
+
//timestamp when auto-played audio completed playing
|
|
150
|
+
(0, _sessionUpdater.updateSessionMetadata)(this._session, {
|
|
151
|
+
audioEndTime: new Date().getTime()
|
|
152
|
+
});
|
|
153
|
+
let {
|
|
154
|
+
audioStartTime,
|
|
155
|
+
audioEndTime,
|
|
156
|
+
waitTime
|
|
157
|
+
} = this._session;
|
|
158
|
+
if (!waitTime && audioStartTime && audioEndTime) {
|
|
159
|
+
// waitTime is elapsed time the user waited for auto-played audio to finish
|
|
160
|
+
this._session.waitTime = audioEndTime - audioStartTime;
|
|
161
|
+
}
|
|
162
|
+
this.audioComplete = true;
|
|
163
|
+
this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(this.tagName.toLowerCase(), this.isComplete()));
|
|
164
|
+
audio.removeEventListener('ended', handleEnded);
|
|
165
|
+
};
|
|
166
|
+
audio.addEventListener('ended', handleEnded);
|
|
167
|
+
|
|
168
|
+
// store references to remove later
|
|
169
|
+
this._audio = audio;
|
|
170
|
+
this._handlePlaying = handlePlaying;
|
|
171
|
+
this._handleEnded = handleEnded;
|
|
172
|
+
this._enableAudio = enableAudio;
|
|
173
|
+
// set to true to prevent multiple initializations
|
|
174
|
+
this._audioInitialized = true;
|
|
175
|
+
observer.disconnect();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
observer.observe(this, {
|
|
180
|
+
childList: true,
|
|
181
|
+
subtree: true
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
_render() {
|
|
185
|
+
if (this._model && this._session) {
|
|
186
|
+
const el = /*#__PURE__*/_react.default.createElement(_hotspot.default, {
|
|
187
|
+
model: this._model,
|
|
188
|
+
session: this._session,
|
|
189
|
+
onSelectChoice: this.onSelectChoice.bind(this)
|
|
190
|
+
});
|
|
191
|
+
if (!this._root) {
|
|
192
|
+
this._root = (0, _client.createRoot)(this);
|
|
193
|
+
}
|
|
194
|
+
this._root.render(el);
|
|
195
|
+
queueMicrotask(() => {
|
|
196
|
+
(0, _mathRendering.renderMath)(this);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
disconnectedCallback() {
|
|
201
|
+
document.removeEventListener('click', this._enableAudio);
|
|
202
|
+
if (this._audio) {
|
|
203
|
+
this._audio.removeEventListener('playing', this._handlePlaying);
|
|
204
|
+
this._audio.removeEventListener('ended', this._handleEnded);
|
|
205
|
+
this._audio = null;
|
|
206
|
+
}
|
|
207
|
+
if (this._root) {
|
|
208
|
+
this._root.unmount();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.default = Hotspot;
|
|
213
|
+
//# sourceMappingURL=index.js.map
|