@pie-element/hotspot 9.3.4-next.0 → 10.0.0-beta.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.
Files changed (103) hide show
  1. package/configure/lib/DeleteWidget.js +30 -43
  2. package/configure/lib/DeleteWidget.js.map +1 -1
  3. package/configure/lib/button.js +26 -45
  4. package/configure/lib/button.js.map +1 -1
  5. package/configure/lib/buttons/circle.js +20 -27
  6. package/configure/lib/buttons/circle.js.map +1 -1
  7. package/configure/lib/buttons/polygon.js +26 -33
  8. package/configure/lib/buttons/polygon.js.map +1 -1
  9. package/configure/lib/buttons/rectangle.js +26 -33
  10. package/configure/lib/buttons/rectangle.js.map +1 -1
  11. package/configure/lib/defaults.js +2 -3
  12. package/configure/lib/defaults.js.map +1 -1
  13. package/configure/lib/hotspot-circle.js +132 -198
  14. package/configure/lib/hotspot-circle.js.map +1 -1
  15. package/configure/lib/hotspot-container.js +250 -355
  16. package/configure/lib/hotspot-container.js.map +1 -1
  17. package/configure/lib/hotspot-drawable.js +360 -472
  18. package/configure/lib/hotspot-drawable.js.map +1 -1
  19. package/configure/lib/hotspot-palette.js +92 -139
  20. package/configure/lib/hotspot-palette.js.map +1 -1
  21. package/configure/lib/hotspot-polygon.js +212 -317
  22. package/configure/lib/hotspot-polygon.js.map +1 -1
  23. package/configure/lib/hotspot-rectangle.js +128 -192
  24. package/configure/lib/hotspot-rectangle.js.map +1 -1
  25. package/configure/lib/icons.js.map +1 -1
  26. package/configure/lib/image-konva.js +46 -86
  27. package/configure/lib/image-konva.js.map +1 -1
  28. package/configure/lib/index.js +162 -222
  29. package/configure/lib/index.js.map +1 -1
  30. package/configure/lib/root.js +301 -393
  31. package/configure/lib/root.js.map +1 -1
  32. package/configure/lib/shapes/circle.js +69 -101
  33. package/configure/lib/shapes/circle.js.map +1 -1
  34. package/configure/lib/shapes/index.js +4 -12
  35. package/configure/lib/shapes/index.js.map +1 -1
  36. package/configure/lib/shapes/polygon.js +64 -96
  37. package/configure/lib/shapes/polygon.js.map +1 -1
  38. package/configure/lib/shapes/rectagle.js +69 -101
  39. package/configure/lib/shapes/rectagle.js.map +1 -1
  40. package/configure/lib/shapes/utils.js +2 -8
  41. package/configure/lib/shapes/utils.js.map +1 -1
  42. package/configure/lib/upload-control.js +25 -52
  43. package/configure/lib/upload-control.js.map +1 -1
  44. package/configure/lib/utils.js +84 -137
  45. package/configure/lib/utils.js.map +1 -1
  46. package/configure/package.json +11 -10
  47. package/configure/src/__tests__/hotspot-container.test.js +50 -19
  48. package/configure/src/__tests__/hotspot-drawable.test.js +55 -34
  49. package/configure/src/__tests__/index.test.js +167 -5
  50. package/configure/src/__tests__/root.test.js +89 -63
  51. package/configure/src/button.jsx +12 -20
  52. package/configure/src/hotspot-circle.jsx +5 -18
  53. package/configure/src/hotspot-container.jsx +82 -98
  54. package/configure/src/hotspot-drawable.jsx +43 -45
  55. package/configure/src/hotspot-palette.jsx +45 -37
  56. package/configure/src/hotspot-polygon.jsx +4 -20
  57. package/configure/src/hotspot-rectangle.jsx +4 -17
  58. package/configure/src/index.js +12 -2
  59. package/configure/src/root.jsx +85 -79
  60. package/configure/src/upload-control.jsx +6 -16
  61. package/controller/lib/defaults.js +2 -3
  62. package/controller/lib/defaults.js.map +1 -1
  63. package/controller/lib/index.js +151 -205
  64. package/controller/lib/index.js.map +1 -1
  65. package/controller/lib/utils.js +14 -34
  66. package/controller/lib/utils.js.map +1 -1
  67. package/controller/package.json +2 -2
  68. package/lib/hotspot/circle.js +110 -169
  69. package/lib/hotspot/circle.js.map +1 -1
  70. package/lib/hotspot/container.js +174 -260
  71. package/lib/hotspot/container.js.map +1 -1
  72. package/lib/hotspot/icons.js.map +1 -1
  73. package/lib/hotspot/image-konva-tooltip.js +65 -112
  74. package/lib/hotspot/image-konva-tooltip.js.map +1 -1
  75. package/lib/hotspot/index.js +135 -198
  76. package/lib/hotspot/index.js.map +1 -1
  77. package/lib/hotspot/polygon.js +150 -214
  78. package/lib/hotspot/polygon.js.map +1 -1
  79. package/lib/hotspot/rectangle.js +128 -185
  80. package/lib/hotspot/rectangle.js.map +1 -1
  81. package/lib/index.js +187 -256
  82. package/lib/index.js.map +1 -1
  83. package/lib/session-updater.js +12 -18
  84. package/lib/session-updater.js.map +1 -1
  85. package/package.json +14 -11
  86. package/src/__tests__/container.test.jsx +27 -175
  87. package/src/__tests__/index.test.js +70 -30
  88. package/src/hotspot/circle.jsx +2 -13
  89. package/src/hotspot/container.jsx +35 -50
  90. package/src/hotspot/index.jsx +16 -28
  91. package/src/hotspot/polygon.jsx +4 -13
  92. package/src/hotspot/rectangle.jsx +5 -15
  93. package/src/index.js +21 -12
  94. package/configure/src/__tests__/DeleteWidget.test.js +0 -64
  95. package/configure/src/__tests__/__snapshots__/hotspot-container.test.js.snap +0 -192
  96. package/configure/src/__tests__/__snapshots__/hotspot-drawable.test.js.snap +0 -562
  97. package/configure/src/__tests__/__snapshots__/root.test.js.snap +0 -469
  98. package/src/__tests__/__snapshots__/container.test.jsx.snap +0 -264
  99. package/src/__tests__/__snapshots__/index.test.js.snap +0 -81
  100. package/src/__tests__/__snapshots__/polygon.test.jsx.snap +0 -192
  101. package/src/__tests__/__snapshots__/rectangle.test.jsx.snap +0 -127
  102. package/src/__tests__/polygon.test.jsx +0 -230
  103. package/src/__tests__/rectangle.test.jsx +0 -232
@@ -1,213 +1,162 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.updateImageDimensions = exports.isPointInsidePolygon = exports.groupShapes = exports.getUpdatedShapes = exports.getUpdatedRectangle = exports.getUpdatedPolygon = exports.getAllShapes = exports.generateValidationMessage = exports.calculate = 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
8
  var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
17
-
18
9
  var _shapes = require("./shapes");
19
-
20
- var _excluded = ["group"];
21
-
22
- 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; }
23
-
24
- 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; }
25
-
26
- var updateImageDimensions = function updateImageDimensions(initialDim, nextDim, keepAspectRatio, resizeType) {
10
+ const updateImageDimensions = (initialDim, nextDim, keepAspectRatio, resizeType) => {
27
11
  // if we want to keep image aspect ratio
28
12
  if (keepAspectRatio) {
29
- var imageAspectRatio = initialDim.width / initialDim.height;
30
-
13
+ const imageAspectRatio = initialDim.width / initialDim.height;
31
14
  if (resizeType === 'height') {
32
15
  // if we want to change image height => we update the width accordingly
33
16
  return {
34
17
  width: nextDim.height * imageAspectRatio,
35
18
  height: nextDim.height
36
19
  };
37
- } // if we want to change image width => we update the height accordingly
38
-
20
+ }
39
21
 
22
+ // if we want to change image width => we update the height accordingly
40
23
  return {
41
24
  width: nextDim.width,
42
25
  height: nextDim.width / imageAspectRatio
43
26
  };
44
- } // if we don't want to keep aspect ratio, we just update both values
45
-
27
+ }
46
28
 
29
+ // if we don't want to keep aspect ratio, we just update both values
47
30
  return {
48
31
  width: nextDim.width,
49
32
  height: nextDim.height
50
33
  };
51
- }; // referenceInitialValue = the initial value of the Stage
34
+ };
35
+
36
+ // referenceInitialValue = the initial value of the Stage
52
37
  // referenceNextValue = the next value of the Stage
53
38
  // currentValue = the value that has to be re-sized influenced by the changes that were made on the Stage
54
-
55
-
56
39
  exports.updateImageDimensions = updateImageDimensions;
57
-
58
- var getDelta = function getDelta(referenceInitialValue, referenceNextValue, currentValue) {
59
- return referenceNextValue / referenceInitialValue * currentValue;
60
- };
61
-
62
- var getUpdatedRectangle = function getUpdatedRectangle(initialDim, nextDim, shape) {
63
- return _objectSpread(_objectSpread({}, shape), {}, {
64
- width: getDelta(initialDim.width, nextDim.width, shape.width),
65
- height: getDelta(initialDim.height, nextDim.height, shape.height),
66
- x: getDelta(initialDim.width, nextDim.width, shape.x),
67
- y: getDelta(initialDim.height, nextDim.height, shape.y)
68
- });
69
- };
70
-
40
+ const getDelta = (referenceInitialValue, referenceNextValue, currentValue) => referenceNextValue / referenceInitialValue * currentValue;
41
+ const getUpdatedRectangle = (initialDim, nextDim, shape) => ({
42
+ ...shape,
43
+ width: getDelta(initialDim.width, nextDim.width, shape.width),
44
+ height: getDelta(initialDim.height, nextDim.height, shape.height),
45
+ x: getDelta(initialDim.width, nextDim.width, shape.x),
46
+ y: getDelta(initialDim.height, nextDim.height, shape.y)
47
+ });
71
48
  exports.getUpdatedRectangle = getUpdatedRectangle;
49
+ const getUpdatedCircles = (initialDim, nextDim, shape) => ({
50
+ ...shape,
51
+ radius: getDelta(initialDim.width, nextDim.width, shape.radius),
52
+ x: getDelta(initialDim.width, nextDim.width, shape.x),
53
+ y: getDelta(initialDim.height, nextDim.height, shape.y)
54
+ });
55
+ const getUpdatedPolygon = (initialDim, nextDim, shape) => ({
56
+ ...shape,
57
+ points: shape.points.map(point => ({
58
+ x: getDelta(initialDim.width, nextDim.width, point.x),
59
+ y: getDelta(initialDim.height, nextDim.height, point.y)
60
+ }))
61
+ });
72
62
 
73
- var getUpdatedCircles = function getUpdatedCircles(initialDim, nextDim, shape) {
74
- return _objectSpread(_objectSpread({}, shape), {}, {
75
- radius: getDelta(initialDim.width, nextDim.width, shape.radius),
76
- x: getDelta(initialDim.width, nextDim.width, shape.x),
77
- y: getDelta(initialDim.height, nextDim.height, shape.y)
78
- });
79
- };
80
-
81
- var getUpdatedPolygon = function getUpdatedPolygon(initialDim, nextDim, shape) {
82
- return _objectSpread(_objectSpread({}, shape), {}, {
83
- points: shape.points.map(function (point) {
84
- return {
85
- x: getDelta(initialDim.width, nextDim.width, point.x),
86
- y: getDelta(initialDim.height, nextDim.height, point.y)
87
- };
88
- })
89
- });
90
- }; // initialDim = the initial dimensions: { width, height } of the Stage
63
+ // initialDim = the initial dimensions: { width, height } of the Stage
91
64
  // nextDim = the next dimensions: { width, height } of the Stage
92
65
  // shapes = array of shapes that have to be re-sized and re-positioned
93
-
94
-
95
66
  exports.getUpdatedPolygon = getUpdatedPolygon;
96
-
97
- var getUpdatedShapes = function getUpdatedShapes(initialDim, nextDim, shapes) {
98
- return shapes.map(function (shape) {
67
+ const getUpdatedShapes = (initialDim, nextDim, shapes) => {
68
+ return shapes.map(shape => {
99
69
  if (shape.group === _shapes.SHAPE_GROUPS.RECTANGLES) {
100
70
  return getUpdatedRectangle(initialDim, nextDim, shape);
101
71
  }
102
-
103
72
  if (shape.group === _shapes.SHAPE_GROUPS.POLYGONS) {
104
73
  return getUpdatedPolygon(initialDim, nextDim, shape);
105
74
  }
106
-
107
75
  if (shape.group === _shapes.SHAPE_GROUPS.CIRCLES) {
108
76
  return getUpdatedCircles(initialDim, nextDim, shape);
109
77
  }
110
78
  });
111
- }; // converts shapes map to shapes array
79
+ };
80
+
81
+ // converts shapes map to shapes array
112
82
  // example:
113
83
  // from: { rectangles: [r1], polygons: [p1, p2]}
114
84
  // to: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]
115
85
  // if a shape has index defined, keep it, otherwise initialize it
116
86
  // index is used for the UNDO function
117
-
118
-
119
87
  exports.getUpdatedShapes = getUpdatedShapes;
120
-
121
- var getAllShapes = function getAllShapes(shapesMap) {
88
+ const getAllShapes = shapesMap => {
122
89
  shapesMap = shapesMap || {};
123
- var shapesArray = [];
124
- var shapesKeys = Object.keys(shapesMap);
125
- return shapesKeys.length ? shapesKeys.reduce(function (acc, currentShapeKey) {
126
- return acc.concat(shapesMap[currentShapeKey] ? shapesMap[currentShapeKey].map(function (shape, index) {
127
- return _objectSpread(_objectSpread({}, shape), {}, {
128
- group: currentShapeKey,
129
- index: shape.index || acc.length + index
130
- });
131
- }) : []);
132
- }, shapesArray) : shapesArray;
133
- }; // converts shapes array to shapes map
90
+ const shapesArray = [];
91
+ const shapesKeys = Object.keys(shapesMap);
92
+ return shapesKeys.length ? shapesKeys.reduce((acc, currentShapeKey) => acc.concat(shapesMap[currentShapeKey] ? shapesMap[currentShapeKey].map((shape, index) => ({
93
+ ...shape,
94
+ group: currentShapeKey,
95
+ index: shape.index || acc.length + index
96
+ })) : []), shapesArray) : shapesArray;
97
+ };
98
+
99
+ // converts shapes array to shapes map
134
100
  // is the reverse of getAllShapes function
135
101
  // example:
136
102
  // from: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]
137
103
  // to: { rectangles: [r1], polygons: [p1, p2]}
138
-
139
-
140
104
  exports.getAllShapes = getAllShapes;
141
-
142
- var groupShapes = function groupShapes(shapesArray) {
105
+ const groupShapes = shapesArray => {
143
106
  shapesArray = shapesArray || [];
144
- var shapesMap = {
107
+ const shapesMap = {
145
108
  rectangles: [],
146
109
  polygons: [],
147
110
  circles: []
148
111
  };
149
-
150
112
  if (shapesArray.length) {
151
- return shapesArray.reduce(function (acc, _ref) {
152
- var group = _ref.group,
153
- shapeProps = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
154
- acc[group] = [].concat((0, _toConsumableArray2["default"])(acc[group] || []), [shapeProps]);
113
+ return shapesArray.reduce((acc, {
114
+ group,
115
+ ...shapeProps
116
+ }) => {
117
+ acc[group] = [...(acc[group] || []), shapeProps];
155
118
  return acc;
156
119
  }, shapesMap);
157
120
  }
158
-
159
- return (0, _cloneDeep["default"])(shapesMap);
121
+ return (0, _cloneDeep.default)(shapesMap);
160
122
  };
161
-
162
123
  exports.groupShapes = groupShapes;
163
-
164
- var isPointInsidePolygon = function isPointInsidePolygon(polygon, x, y) {
165
- var inside = false;
166
-
124
+ const isPointInsidePolygon = (polygon, x, y) => {
125
+ let inside = false;
167
126
  if (!polygon || polygon.length <= 0) {
168
127
  return inside;
169
128
  }
170
-
171
- for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
172
- var xi = polygon[i].x;
173
- var yi = polygon[i].y;
174
- var xj = polygon[j].x;
175
- var yj = polygon[j].y;
176
- var intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
177
-
129
+ for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
130
+ const xi = polygon[i].x;
131
+ const yi = polygon[i].y;
132
+ const xj = polygon[j].x;
133
+ const yj = polygon[j].y;
134
+ const intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
178
135
  if (intersect) {
179
136
  inside = !inside;
180
137
  }
181
138
  }
182
-
183
139
  return inside;
184
140
  };
185
-
186
141
  exports.isPointInsidePolygon = isPointInsidePolygon;
187
-
188
- var calculate = function calculate(polygonPoints) {
142
+ const calculate = polygonPoints => {
189
143
  if (!polygonPoints || polygonPoints.length <= 0) {
190
144
  return {
191
145
  x: 0,
192
146
  y: 0
193
147
  };
194
148
  }
195
-
196
- var xPoints = polygonPoints.map(function (point) {
197
- return point.x;
198
- });
199
- var yPoints = polygonPoints.map(function (point) {
200
- return point.y;
201
- });
202
- var minX = Math.min.apply(Math, (0, _toConsumableArray2["default"])(xPoints));
203
- var minY = Math.min.apply(Math, (0, _toConsumableArray2["default"])(yPoints));
204
- var maxX = Math.max.apply(Math, (0, _toConsumableArray2["default"])(xPoints));
205
- var maxY = Math.max.apply(Math, (0, _toConsumableArray2["default"])(yPoints)); // Find a suitable position for the text element within the polygon
206
-
207
- var textX, textY;
208
-
209
- for (var x = minX; x <= maxX - 20; x++) {
210
- for (var y = maxY - 20; y > minY; y--) {
149
+ const xPoints = polygonPoints.map(point => point.x);
150
+ const yPoints = polygonPoints.map(point => point.y);
151
+ const minX = Math.min(...xPoints);
152
+ const minY = Math.min(...yPoints);
153
+ const maxX = Math.max(...xPoints);
154
+ const maxY = Math.max(...yPoints);
155
+
156
+ // Find a suitable position for the text element within the polygon
157
+ let textX, textY;
158
+ for (let x = minX; x <= maxX - 20; x++) {
159
+ for (let y = maxY - 20; y > minY; y--) {
211
160
  // Check if the text element's position (x, y) is within the polygon
212
161
  if (isPointInsidePolygon(polygonPoints, x, y)) {
213
162
  textX = x - 10;
@@ -216,24 +165,22 @@ var calculate = function calculate(polygonPoints) {
216
165
  }
217
166
  }
218
167
  }
219
-
220
168
  return {
221
169
  x: textX,
222
170
  y: textY
223
171
  };
224
172
  };
225
-
226
173
  exports.calculate = calculate;
227
-
228
- var generateValidationMessage = function generateValidationMessage(config) {
229
- var minShapes = config.minShapes,
230
- maxShapes = config.maxShapes,
231
- maxSelections = config.maxSelections;
232
- var shapesMessage = "\nThere should be at least ".concat(minShapes, " ") + (maxShapes ? "and at most ".concat(maxShapes, " ") : '') + 'shapes defined.';
233
- var selectionsMessage = '\nThere should be at least 1 ' + (maxSelections ? "and at most ".concat(maxSelections, " ") : '') + 'shape' + (maxSelections ? 's' : '') + ' selected.';
234
- var message = 'Validation requirements:' + shapesMessage + selectionsMessage;
174
+ const generateValidationMessage = config => {
175
+ const {
176
+ minShapes,
177
+ maxShapes,
178
+ maxSelections
179
+ } = config;
180
+ const shapesMessage = `\nThere should be at least ${minShapes} ` + (maxShapes ? `and at most ${maxShapes} ` : '') + 'shapes defined.';
181
+ const selectionsMessage = '\nThere should be at least 1 ' + (maxSelections ? `and at most ${maxSelections} ` : '') + 'shape' + (maxSelections ? 's' : '') + ' selected.';
182
+ const message = 'Validation requirements:' + shapesMessage + selectionsMessage;
235
183
  return message;
236
184
  };
237
-
238
185
  exports.generateValidationMessage = generateValidationMessage;
239
186
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.js"],"names":["updateImageDimensions","initialDim","nextDim","keepAspectRatio","resizeType","imageAspectRatio","width","height","getDelta","referenceInitialValue","referenceNextValue","currentValue","getUpdatedRectangle","shape","x","y","getUpdatedCircles","radius","getUpdatedPolygon","points","map","point","getUpdatedShapes","shapes","group","SHAPE_GROUPS","RECTANGLES","POLYGONS","CIRCLES","getAllShapes","shapesMap","shapesArray","shapesKeys","Object","keys","length","reduce","acc","currentShapeKey","concat","index","groupShapes","rectangles","polygons","circles","shapeProps","isPointInsidePolygon","polygon","inside","i","j","xi","yi","xj","yj","intersect","calculate","polygonPoints","xPoints","yPoints","minX","Math","min","minY","maxX","max","maxY","textX","textY","generateValidationMessage","config","minShapes","maxShapes","maxSelections","shapesMessage","selectionsMessage","message"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;;;;;;;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;AAFX,OAAP;AAID,KATkB,CAWnB;;;AACA,WAAO;AACLD,MAAAA,KAAK,EAAEJ,OAAO,CAACI,KADV;AAELC,MAAAA,MAAM,EAAEL,OAAO,CAACI,KAAR,GAAgBD;AAFnB,KAA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GAAP;AACD,CA3BD;;;;AA6BA,IAAMC,yBAAyB,GAAG,SAA5BA,yBAA4B,CAACC,MAAD,EAAY;AAC5C,MAAQC,SAAR,GAAgDD,MAAhD,CAAQC,SAAR;AAAA,MAAmBC,SAAnB,GAAgDF,MAAhD,CAAmBE,SAAnB;AAAA,MAA8BC,aAA9B,GAAgDH,MAAhD,CAA8BG,aAA9B;AAEA,MAAMC,aAAa,GACjB,qCAA8BH,SAA9B,UAA8CC,SAAS,yBAAkBA,SAAlB,SAAiC,EAAxF,IAA8F,iBADhG;AAGA,MAAMG,iBAAiB,GACrB,mCACCF,aAAa,yBAAkBA,aAAlB,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';\nimport { SHAPE_GROUPS } from './shapes';\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 getUpdatedCircles = (initialDim, nextDim, shape) => ({\n ...shape,\n radius: getDelta(initialDim.width, nextDim.width, shape.radius),\n x: getDelta(initialDim.width, nextDim.width, shape.x),\n y: getDelta(initialDim.height, nextDim.height, shape.y),\n});\n\nconst getUpdatedPolygon = (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 === SHAPE_GROUPS.RECTANGLES) {\n return getUpdatedRectangle(initialDim, nextDim, shape);\n }\n\n if (shape.group === SHAPE_GROUPS.POLYGONS) {\n return getUpdatedPolygon(initialDim, nextDim, shape);\n }\n\n if (shape.group === SHAPE_GROUPS.CIRCLES) {\n return getUpdatedCircles(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 circles: [],\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 isPointInsidePolygon = (polygon, x, y) => {\n let inside = false;\n\n if (!polygon || polygon.length <= 0) {\n return inside;\n }\n\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n const xi = polygon[i].x;\n const yi = polygon[i].y;\n const xj = polygon[j].x;\n const yj = polygon[j].y;\n\n const intersect = yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;\n\n if (intersect) {\n inside = !inside;\n }\n }\n\n return inside;\n};\n\nconst calculate = (polygonPoints) => {\n if (!polygonPoints || polygonPoints.length <= 0) {\n return { x: 0, y: 0 };\n }\n\n const xPoints = polygonPoints.map((point) => point.x);\n const yPoints = polygonPoints.map((point) => point.y);\n const minX = Math.min(...xPoints);\n const minY = Math.min(...yPoints);\n const maxX = Math.max(...xPoints);\n const maxY = Math.max(...yPoints);\n\n // Find a suitable position for the text element within the polygon\n let textX, textY;\n\n for (let x = minX; x <= maxX - 20; x++) {\n for (let y = maxY - 20; y > minY; y--) {\n // Check if the text element's position (x, y) is within the polygon\n if (isPointInsidePolygon(polygonPoints, x, y)) {\n textX = x - 10;\n textY = y;\n break;\n }\n }\n }\n\n return { x: textX, y: textY };\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 calculate,\n isPointInsidePolygon,\n updateImageDimensions,\n generateValidationMessage,\n getUpdatedShapes,\n getAllShapes,\n groupShapes,\n getUpdatedRectangle,\n getUpdatedPolygon,\n};\n"],"file":"utils.js"}
1
+ {"version":3,"file":"utils.js","names":["_cloneDeep","_interopRequireDefault","require","_shapes","updateImageDimensions","initialDim","nextDim","keepAspectRatio","resizeType","imageAspectRatio","width","height","exports","getDelta","referenceInitialValue","referenceNextValue","currentValue","getUpdatedRectangle","shape","x","y","getUpdatedCircles","radius","getUpdatedPolygon","points","map","point","getUpdatedShapes","shapes","group","SHAPE_GROUPS","RECTANGLES","POLYGONS","CIRCLES","getAllShapes","shapesMap","shapesArray","shapesKeys","Object","keys","length","reduce","acc","currentShapeKey","concat","index","groupShapes","rectangles","polygons","circles","shapeProps","cloneDeep","isPointInsidePolygon","polygon","inside","i","j","xi","yi","xj","yj","intersect","calculate","polygonPoints","xPoints","yPoints","minX","Math","min","minY","maxX","max","maxY","textX","textY","generateValidationMessage","config","minShapes","maxShapes","maxSelections","shapesMessage","selectionsMessage","message"],"sources":["../src/utils.js"],"sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\nimport { SHAPE_GROUPS } from './shapes';\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 getUpdatedCircles = (initialDim, nextDim, shape) => ({\n ...shape,\n radius: getDelta(initialDim.width, nextDim.width, shape.radius),\n x: getDelta(initialDim.width, nextDim.width, shape.x),\n y: getDelta(initialDim.height, nextDim.height, shape.y),\n});\n\nconst getUpdatedPolygon = (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 === SHAPE_GROUPS.RECTANGLES) {\n return getUpdatedRectangle(initialDim, nextDim, shape);\n }\n\n if (shape.group === SHAPE_GROUPS.POLYGONS) {\n return getUpdatedPolygon(initialDim, nextDim, shape);\n }\n\n if (shape.group === SHAPE_GROUPS.CIRCLES) {\n return getUpdatedCircles(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 circles: [],\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 isPointInsidePolygon = (polygon, x, y) => {\n let inside = false;\n\n if (!polygon || polygon.length <= 0) {\n return inside;\n }\n\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n const xi = polygon[i].x;\n const yi = polygon[i].y;\n const xj = polygon[j].x;\n const yj = polygon[j].y;\n\n const intersect = yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;\n\n if (intersect) {\n inside = !inside;\n }\n }\n\n return inside;\n};\n\nconst calculate = (polygonPoints) => {\n if (!polygonPoints || polygonPoints.length <= 0) {\n return { x: 0, y: 0 };\n }\n\n const xPoints = polygonPoints.map((point) => point.x);\n const yPoints = polygonPoints.map((point) => point.y);\n const minX = Math.min(...xPoints);\n const minY = Math.min(...yPoints);\n const maxX = Math.max(...xPoints);\n const maxY = Math.max(...yPoints);\n\n // Find a suitable position for the text element within the polygon\n let textX, textY;\n\n for (let x = minX; x <= maxX - 20; x++) {\n for (let y = maxY - 20; y > minY; y--) {\n // Check if the text element's position (x, y) is within the polygon\n if (isPointInsidePolygon(polygonPoints, x, y)) {\n textX = x - 10;\n textY = y;\n break;\n }\n }\n }\n\n return { x: textX, y: textY };\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 calculate,\n isPointInsidePolygon,\n updateImageDimensions,\n generateValidationMessage,\n getUpdatedShapes,\n getAllShapes,\n groupShapes,\n getUpdatedRectangle,\n getUpdatedPolygon,\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA,MAAME,qBAAqB,GAAGA,CAACC,UAAU,EAAEC,OAAO,EAAEC,eAAe,EAAEC,UAAU,KAAK;EAClF;EACA,IAAID,eAAe,EAAE;IACnB,MAAME,gBAAgB,GAAGJ,UAAU,CAACK,KAAK,GAAGL,UAAU,CAACM,MAAM;IAE7D,IAAIH,UAAU,KAAK,QAAQ,EAAE;MAC3B;MACA,OAAO;QACLE,KAAK,EAAEJ,OAAO,CAACK,MAAM,GAAGF,gBAAgB;QACxCE,MAAM,EAAEL,OAAO,CAACK;MAClB,CAAC;IACH;;IAEA;IACA,OAAO;MACLD,KAAK,EAAEJ,OAAO,CAACI,KAAK;MACpBC,MAAM,EAAEL,OAAO,CAACI,KAAK,GAAGD;IAC1B,CAAC;EACH;;EAEA;EACA,OAAO;IACLC,KAAK,EAAEJ,OAAO,CAACI,KAAK;IACpBC,MAAM,EAAEL,OAAO,CAACK;EAClB,CAAC;AACH,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AG,0BAA0B,GAAGF,aAAa,GAAGC,iBAAiB;EAE9E,OAAOC,OAAO;AAChB,CAAC;AAACtE,OAAA,CAAA+D,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -1,25 +1,26 @@
1
1
  {
2
2
  "name": "@pie-element/hotspot-configure",
3
3
  "private": true,
4
- "version": "8.3.3",
4
+ "version": "9.0.0-beta.0",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
8
8
  "author": "",
9
9
  "dependencies": {
10
- "@material-ui/core": "^3.9.2",
11
- "@material-ui/icons": "^3.0.2",
10
+ "@emotion/react": "^11.14.0",
11
+ "@emotion/style": "^0.8.0",
12
+ "@mui/icons-material": "^7.3.4",
13
+ "@mui/material": "^7.3.4",
12
14
  "@pie-framework/pie-configure-events": "^1.3.0",
13
- "@pie-lib/config-ui": "11.30.2",
14
- "@pie-lib/editable-html": "11.21.2",
15
- "classnames": "^2.2.6",
15
+ "@pie-lib/config-ui": "11.30.4-next.0",
16
+ "@pie-lib/editable-html": "11.21.4-next.0",
16
17
  "debug": "^3.1.0",
17
- "konva": "^3.2.4",
18
+ "konva": "8.3.0",
18
19
  "lodash": "^4.17.15",
19
20
  "prop-types": "^15.7.2",
20
- "react": "^16.8.6",
21
- "react-dom": "^16.8.6",
22
- "react-konva": "^16.9.0-0"
21
+ "react": "18.2.0",
22
+ "react-dom": "18.2.0",
23
+ "react-konva": "18.1.0"
23
24
  },
24
25
  "license": "ISC"
25
26
  }
@@ -1,8 +1,21 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@testing-library/react';
2
2
  import React from 'react';
3
3
  import { Container } from '../hotspot-container';
4
4
  import { getAllShapes, groupShapes } from '../utils';
5
5
 
6
+ jest.mock('react-konva', () => {
7
+ const React = require('react');
8
+ return {
9
+ Stage: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'stage', ...props }, children),
10
+ Layer: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'layer', ...props }, children),
11
+ Rect: (props) => React.createElement('div', { 'data-testid': 'rect', ...props }),
12
+ Circle: (props) => React.createElement('div', { 'data-testid': 'circle', ...props }),
13
+ Line: (props) => React.createElement('div', { 'data-testid': 'line', ...props }),
14
+ Group: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'group', ...props }, children),
15
+ Image: (props) => React.createElement('div', { 'data-testid': 'image', ...props }),
16
+ };
17
+ });
18
+
6
19
  const model = () => ({
7
20
  imageUrl: 'https://cdn.fluence.net/image/0240eb1455ce4c4bb6180232347b6aef_W',
8
21
  shapes: groupShapes(
@@ -114,18 +127,36 @@ describe('HotspotContainer', () => {
114
127
  ...extras,
115
128
  };
116
129
 
117
- return shallow(<Container {...props} />);
130
+ return render(<Container {...props} />);
118
131
  };
119
132
  });
120
133
 
121
- describe('render', () => {
122
- it('renders', () => {
123
- expect(w()).toMatchSnapshot();
124
- });
125
- });
126
-
127
134
  describe('logic', () => {
128
- let wrapper;
135
+ const createInstance = () => {
136
+ const props = {
137
+ classes: {},
138
+ dimensions: initialModel.dimensions,
139
+ imageUrl: initialModel.imageUrl,
140
+ multipleCorrect: initialModel.multipleCorrect,
141
+ hotspotColor: initialModel.hotspotColor,
142
+ outlineColor: initialModel.outlineColor,
143
+ onUpdateImageDimension: onUpdateImageDimension,
144
+ onUpdateShapes: onUpdateShapes,
145
+ onDeleteShape: onDeleteShape,
146
+ onImageUpload: onImageUpload,
147
+ shapes: initialModel.shapes,
148
+ };
149
+ const instance = new Container(props);
150
+
151
+ // Mock setState to execute callback immediately for testing
152
+ instance.setState = jest.fn((state, callback) => {
153
+ Object.assign(instance.state, typeof state === 'function' ? state(instance.state) : state);
154
+ if (callback) callback();
155
+ });
156
+
157
+ return instance;
158
+ };
159
+
129
160
  let formattedShapes = [
130
161
  {
131
162
  id: '0',
@@ -211,15 +242,13 @@ describe('HotspotContainer', () => {
211
242
  },
212
243
  ];
213
244
 
214
- beforeEach(() => {
215
- wrapper = w();
216
- });
217
-
218
245
  it('state will contain formatted shapes', () => {
219
- expect(wrapper.instance().state.shapes).toEqual(expect.arrayContaining(formattedShapes));
246
+ const instance = createInstance();
247
+ expect(instance.state.shapes).toEqual(expect.arrayContaining(formattedShapes));
220
248
  });
221
249
 
222
250
  it('onUpdateShapes with new added shape', () => {
251
+ const instance = createInstance();
223
252
  const newShape = {
224
253
  id: '8',
225
254
  height: 140,
@@ -229,7 +258,7 @@ describe('HotspotContainer', () => {
229
258
  group: 'rectangles',
230
259
  };
231
260
 
232
- wrapper.instance().onUpdateShapes([...formattedShapes, newShape]);
261
+ instance.onUpdateShapes([...formattedShapes, newShape]);
233
262
 
234
263
  expect(onUpdateShapes).toHaveBeenLastCalledWith({
235
264
  rectangles: [
@@ -248,8 +277,8 @@ describe('HotspotContainer', () => {
248
277
  });
249
278
 
250
279
  it('onDeleteShape by id', () => {
251
- console.log('wrapper', wrapper.instance());
252
- wrapper.instance().onDeleteShape('8');
280
+ const instance = createInstance();
281
+ instance.onDeleteShape('8');
253
282
  expect(onUpdateShapes).toHaveBeenCalledWith(
254
283
  groupShapes([
255
284
  { correct: true, group: 'rectangles', height: 140, id: '0', index: 0, width: 130, x: 1, y: 1 },
@@ -314,7 +343,8 @@ describe('HotspotContainer', () => {
314
343
  });
315
344
 
316
345
  it('onUpdateShapes with no shapes', () => {
317
- wrapper.instance().onUpdateShapes([]);
346
+ const instance = createInstance();
347
+ instance.onUpdateShapes([]);
318
348
 
319
349
  expect(onUpdateShapes).toHaveBeenLastCalledWith({
320
350
  rectangles: [],
@@ -324,7 +354,8 @@ describe('HotspotContainer', () => {
324
354
  });
325
355
 
326
356
  it('handleClearAll', () => {
327
- wrapper.instance().handleClearAll();
357
+ const instance = createInstance();
358
+ instance.handleClearAll();
328
359
  expect(onUpdateShapes).toHaveBeenLastCalledWith({
329
360
  rectangles: [],
330
361
  polygons: [],