@pie-element/hotspot 6.1.2-next.44 → 6.1.2-next.57
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/configure/lib/buttons/circle.js +40 -0
- package/configure/lib/buttons/circle.js.map +1 -0
- package/configure/lib/buttons/polygon.js +46 -0
- package/configure/lib/buttons/polygon.js.map +1 -0
- package/configure/lib/buttons/rectangle.js +46 -0
- package/configure/lib/buttons/rectangle.js.map +1 -0
- package/configure/lib/hotspot-container.js +44 -4
- package/configure/lib/hotspot-container.js.map +1 -1
- package/configure/lib/hotspot-drawable.js +180 -115
- package/configure/lib/hotspot-drawable.js.map +1 -1
- package/configure/lib/hotspot-polygon.js +11 -2
- package/configure/lib/hotspot-polygon.js.map +1 -1
- package/configure/lib/shapes/circle.js +96 -0
- package/configure/lib/shapes/circle.js.map +1 -0
- package/configure/lib/shapes/polygon.js +111 -0
- package/configure/lib/shapes/polygon.js.map +1 -0
- package/configure/lib/shapes/rectagle.js +115 -0
- package/configure/lib/shapes/rectagle.js.map +1 -0
- package/configure/package.json +1 -1
- package/configure/src/__tests__/__snapshots__/hotspot-container.test.js.snap +16 -0
- package/configure/src/__tests__/__snapshots__/hotspot-drawable.test.js.snap +42 -0
- package/configure/src/__tests__/hotspot-drawable.test.js +4 -1
- 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/hotspot-container.jsx +31 -2
- package/configure/src/hotspot-drawable.jsx +112 -54
- package/configure/src/hotspot-polygon.jsx +12 -2
- package/configure/src/shapes/circle.js +67 -0
- package/configure/src/shapes/polygon.js +79 -0
- package/configure/src/shapes/rectagle.js +80 -0
- package/controller/package.json +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hotspot-polygon.jsx"],"names":["HOVERED_COLOR","PolComponent","points","xList","map","p","x","yList","y","Math","min","max","getOffset","xOffset","yOffset","reduce","acc","point","length","id","hovered","isDragging","getInitialState","props","e","width","height","isDrawing","onClick","cancelBubble","setState","document","body","style","cursor","updateModel","onDragEnd","target","serialize","state","newPoints","currentPointCoordinate","index","changedIndex","onDeleteShape","classes","correct","hotspotColor","outlineColor","strokeWidth","calculatedStrokeWidth","calculatedStroke","group","handleMouseLeave","handleMouseEnter","base","handleClick","onDragStart","handleOnDragEnd","circle","handleOnDragVertex","handleDelete","nextProps","prevState","imageHeight","imageWidth","React","Component","styles","opacity","padding","propTypes","PropTypes","object","isRequired","bool","string","number","func","arrayOf","shape","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,aAAa,GAAG,SAAtB;;IAEMC,Y;;;;;;;;;;;;;;;kGAuCQ,UAACC,MAAD,EAAY;AACtB,UAAMC,KAAK,GAAGD,MAAM,CAACE,GAAP,CAAW,UAACC,CAAD;AAAA,eAAOA,CAAC,CAACC,CAAT;AAAA,OAAX,CAAd;AACA,UAAMC,KAAK,GAAGL,MAAM,CAACE,GAAP,CAAW,UAACC,CAAD;AAAA,eAAOA,CAAC,CAACG,CAAT;AAAA,OAAX,CAAd;AAEA,aAAO;AACLF,QAAAA,CAAC,EAAEG,IAAI,CAACC,GAAL,OAAAD,IAAI,sCAAQN,KAAR,EADF;AAELK,QAAAA,CAAC,EAAEC,IAAI,CAACE,GAAL,OAAAF,IAAI,sCAAQF,KAAR;AAFF,OAAP;AAID,K;kGAEW,UAACL,MAAD,EAAY;AACtB,4BAAmC,MAAKU,SAAL,CAAeV,MAAf,CAAnC;AAAA,UAAWW,OAAX,mBAAQP,CAAR;AAAA,UAAuBQ,OAAvB,mBAAoBN,CAApB;;AAEA,aAAON,MAAM,CAACa,MAAP,CAAc,UAACC,GAAD,EAAMC,KAAN;AAAA,6DAAoBD,GAApB,IAAyBC,KAAK,CAACX,CAAN,GAAUO,OAAnC,EAA4CI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AAV,CAAiBF,UAXR;AAYvBxE,EAAAA,MAAM,EAAEsE,sBAAUO,OAAV,CACNP,sBAAUQ,KAAV,CAAgB;AACd1E,IAAAA,CAAC,EAAEkE,sBAAUK,MADC;AAEdrE,IAAAA,CAAC,EAAEgE,sBAAUK;AAFC,GAAhB,CADM,EAKNH,UAjBqB;AAkBvBzB,EAAAA,WAAW,EAAEuB,sBAAUK;AAlBA,CAAzB;AAqBA5E,YAAY,CAACgF,YAAb,GAA4B;AAC1BnC,EAAAA,OAAO,EAAE;AADiB,CAA5B;;eAIe,uBAAWsB,MAAX,EAAmBnE,YAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Group, Line, Circle } from 'react-konva';\nimport { withStyles } from '@material-ui/core/styles/index';\nimport DeleteWidget from './DeleteWidget';\n\nconst HOVERED_COLOR = '#00BFFF';\n\nclass PolComponent extends React.Component {\n static getDerivedStateFromProps(nextProps, prevState) {\n const { id, points, imageHeight, imageWidth } = nextProps;\n // we execute this code only if image dimensions changed or an hotspot was added/deleted\n if (\n prevState.imageHeight !== nextProps.imageHeight ||\n prevState.imageWidth !== nextProps.imageWidth ||\n prevState.id !== nextProps.id\n ) {\n if (points.length) {\n const xList = points.map((p) => p.x);\n const yList = points.map((p) => p.y);\n\n const x = Math.min(...xList);\n const y = Math.max(...yList);\n\n return {\n id,\n x,\n y,\n points,\n imageHeight,\n imageWidth,\n };\n }\n\n return {\n id: '',\n x: 0,\n y: 0,\n points: [],\n imageHeight,\n imageWidth,\n };\n } else {\n return null;\n }\n }\n\n getOffset = (points) => {\n const xList = points.map((p) => p.x);\n const yList = points.map((p) => p.y);\n\n return {\n x: Math.min(...xList),\n y: Math.max(...yList),\n };\n };\n\n serialize = (points) => {\n const { x: xOffset, y: yOffset } = this.getOffset(points);\n\n return points.reduce((acc, point) => [...acc, point.x - xOffset, point.y - yOffset], []);\n };\n\n getInitialState = (points) => {\n if (points.length) {\n const { x, y } = this.getOffset(points);\n\n return {\n x,\n y,\n points,\n };\n }\n\n return {\n id: '',\n x: 0,\n y: 0,\n points: [],\n };\n };\n\n state = {\n hovered: false,\n isDragging: false,\n ...this.getInitialState(this.props.points),\n };\n\n handleClick = (e) => {\n const { points } = this.props;\n const xList = points.map((p) => p.x);\n const yList = points.map((p) => p.y);\n\n const width = Math.max(...xList) - Math.min(...xList);\n const height = Math.max(...yList) - Math.min(...yList);\n\n const { isDrawing, onClick, id } = this.props;\n\n if (width < 0 && height < 0 && isDrawing) {\n return;\n }\n\n e.cancelBubble = true;\n onClick(id);\n };\n\n handleMouseEnter = () => {\n this.setState({ hovered: true });\n document.body.style.cursor = 'pointer';\n };\n\n handleMouseLeave = () => {\n this.setState({ hovered: false });\n document.body.style.cursor = 'default';\n };\n\n handleOnDragEnd = (e, updateModel = false) => {\n const { onDragEnd, id } = this.props;\n const points = e.target.points() || this.serialize(this.state.points);\n\n const newPoints = points.reduce((acc, currentPointCoordinate, index) => {\n if (index % 2 === 0 && index + 1 < points.length) {\n return [\n ...acc,\n {\n x: currentPointCoordinate + e.target.x(),\n y: points[index + 1] + e.target.y(),\n },\n ];\n }\n\n return acc;\n }, []);\n\n this.setState({\n points: newPoints,\n ...this.getOffset(newPoints),\n isDragging: updateModel ? false : this.state.isDragging,\n });\n };\n\n handleOnDragVertex = (e, changedIndex, updateModel) => {\n const { onDragEnd, id } = this.props;\n const { points } = this.state;\n\n const newPoints = points.map((point, index) =>\n index === changedIndex ? { x: e.target.x(), y: e.target.y() } : point,\n );\n\n this.setState({\n points: newPoints,\n ...this.getOffset(newPoints),\n isDragging: updateModel ? false : this.state.isDragging,\n });\n\n if (updateModel) {\n onDragEnd(id, { points: newPoints });\n }\n };\n\n onDragStart = () => {\n this.setState({ isDragging: true });\n };\n\n handleDelete = (id) => {\n const { onDeleteShape } = this.props;\n onDeleteShape(id);\n };\n\n render() {\n const { classes, correct, id, hotspotColor, outlineColor, strokeWidth = 5 } = this.props;\n const { points, x, y, hovered } = this.state;\n\n const calculatedStrokeWidth = correct ? strokeWidth : hovered ? 1 : 0;\n const calculatedStroke = correct ? outlineColor : hovered ? HOVERED_COLOR : '';\n return (\n <Group classes={classes.group} onMouseLeave={this.handleMouseLeave} onMouseEnter={this.handleMouseEnter}>\n <Line\n classes={classes.base}\n points={this.serialize(points)}\n closed={true}\n fill={hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable\n stroke={calculatedStroke}\n strokeWidth={calculatedStrokeWidth}\n onDragStart={this.onDragStart}\n onDragMove={this.handleOnDragEnd}\n onDragEnd={(e) => this.handleOnDragEnd(e, true)}\n x={x}\n y={y}\n />\n\n {hovered &&\n points.map((point, index) => (\n <Circle\n key={index}\n className={classes.circle}\n x={point.x}\n y={point.y}\n radius={5}\n fill={'white'}\n stroke={HOVERED_COLOR}\n strokeWidth={1}\n onDragStart={this.onDragStart}\n onDragMove={(e) => {\n this.handleOnDragVertex(e, index);\n }}\n onDragEnd={(e) => {\n this.handleOnDragVertex(e, index, true);\n }}\n draggable\n />\n ))}\n {!this.state.isDragging && this.state.hovered && (\n <DeleteWidget\n x={x}\n y={y}\n id={id}\n handleWidgetClick={this.handleDelete}\n points={points}\n outlineColor={outlineColor}\n />\n )}\n </Group>\n );\n }\n}\n\nconst styles = () => ({\n base: {\n cursor: 'pointer',\n opacity: 0.5,\n },\n circle: {\n opacity: 4,\n },\n group: {\n padding: '12px',\n },\n});\n\nPolComponent.propTypes = {\n classes: PropTypes.object.isRequired,\n correct: PropTypes.bool,\n isDrawing: PropTypes.bool.isRequired,\n id: PropTypes.string.isRequired,\n imageHeight: PropTypes.number,\n imageWidth: PropTypes.number,\n hotspotColor: PropTypes.string.isRequired,\n onClick: PropTypes.func.isRequired,\n onDeleteShape: PropTypes.func.isRequired,\n onDragEnd: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n points: PropTypes.arrayOf(\n PropTypes.shape({\n x: PropTypes.number,\n y: PropTypes.number,\n }),\n ).isRequired,\n strokeWidth: PropTypes.number,\n};\n\nPolComponent.defaultProps = {\n correct: false,\n};\n\nexport default withStyles(styles)(PolComponent);\n"],"file":"hotspot-polygon.js"}
|
|
1
|
+
{"version":3,"sources":["../src/hotspot-polygon.jsx"],"names":["HOVERED_COLOR","PolComponent","points","xList","map","p","x","yList","y","Math","min","max","getOffset","xOffset","yOffset","reduce","acc","point","length","id","hovered","isDragging","getInitialState","props","e","width","height","isDrawing","onClick","addPolygonPoint","cancelBubble","setState","document","body","style","cursor","updateModel","onDragEnd","target","serialize","state","newPoints","currentPointCoordinate","index","changedIndex","onDeleteShape","classes","correct","hotspotColor","outlineColor","strokeWidth","showPoints","calculatedStrokeWidth","calculatedStroke","group","handleMouseLeave","handleMouseEnter","base","handleClick","onDragStart","handleOnDragEnd","circle","handleOnDragVertex","handleDelete","nextProps","prevState","imageHeight","imageWidth","React","Component","styles","opacity","padding","propTypes","PropTypes","object","isRequired","bool","string","number","func","arrayOf","shape","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,aAAa,GAAG,SAAtB;;IAEMC,Y;;;;;;;;;;;;;;;kGAwCQ,UAACC,MAAD,EAAY;AACtB,UAAMC,KAAK,GAAGD,MAAM,CAACE,GAAP,CAAW,UAACC,CAAD;AAAA,eAAOA,CAAC,CAACC,CAAT;AAAA,OAAX,CAAd;AACA,UAAMC,KAAK,GAAGL,MAAM,CAACE,GAAP,CAAW,UAACC,CAAD;AAAA,eAAOA,CAAC,CAACG,CAAT;AAAA,OAAX,CAAd;AAEA,aAAO;AACLF,QAAAA,CAAC,EAAEG,IAAI,CAACC,GAAL,OAAAD,IAAI,sCAAQN,KAAR,EADF;AAELK,QAAAA,CAAC,EAAEC,IAAI,CAACE,GAAL,OAAAF,IAAI,sCAAQF,KAAR;AAFF,OAAP;AAID,K;kGAEW,UAACL,MAAD,EAAY;AACtB,4BAAmC,MAAKU,SAAL,CAAeV,MAAf,CAAnC;A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AE2B,sBAAUG,IAFI;AAGvBlD,EAAAA,SAAS,EAAE+C,sBAAUG,IAAV,CAAeD,UAHH;AAIvBzD,EAAAA,EAAE,EAAEuD,sBAAUI,MAAV,CAAiBF,UAJE;AAKvBV,EAAAA,WAAW,EAAEQ,sBAAUK,MALA;AAMvBZ,EAAAA,UAAU,EAAEO,sBAAUK,MANC;AAOvB/B,EAAAA,YAAY,EAAE0B,sBAAUI,MAAV,CAAiBF,UAPR;AAQvBhD,EAAAA,OAAO,EAAE8C,sBAAUM,IAAV,CAAeJ,UARD;AASvB/C,EAAAA,eAAe,EAAE6C,sBAAUM,IAAV,CAAeJ,UATT;AAUvB/B,EAAAA,aAAa,EAAE6B,sBAAUM,IAAV,CAAeJ,UAVP;AAWvBvC,EAAAA,SAAS,EAAEqC,sBAAUM,IAAV,CAAeJ,UAXH;AAYvB3B,EAAAA,YAAY,EAAEyB,sBAAUI,MAAV,CAAiBF,UAZR;AAavB1E,EAAAA,MAAM,EAAEwE,sBAAUO,OAAV,CACNP,sBAAUQ,KAAV,CAAgB;AACd5E,IAAAA,CAAC,EAAEoE,sBAAUK,MADC;AAEdvE,IAAAA,CAAC,EAAEkE,sBAAUK;AAFC,GAAhB,CADM,EAKNH,UAlBqB;AAmBvB1B,EAAAA,WAAW,EAAEwB,sBAAUK;AAnBA,CAAzB;AAsBA9E,YAAY,CAACkF,YAAb,GAA4B;AAC1BpC,EAAAA,OAAO,EAAE;AADiB,CAA5B;;eAIe,uBAAWuB,MAAX,EAAmBrE,YAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Group, Line, Circle } from 'react-konva';\nimport { withStyles } from '@material-ui/core/styles/index';\nimport DeleteWidget from './DeleteWidget';\n\nconst HOVERED_COLOR = '#00BFFF';\n\nclass PolComponent extends React.Component {\n static getDerivedStateFromProps(nextProps, prevState) {\n const { id, points, imageHeight, imageWidth } = nextProps;\n // we execute this code only if image dimensions changed or an hotspot was added/deleted\n if (\n prevState.imageHeight !== nextProps.imageHeight ||\n prevState.imageWidth !== nextProps.imageWidth ||\n prevState.id !== nextProps.id ||\n prevState.points.length !== points.length\n ) {\n if (points.length) {\n const xList = points.map((p) => p.x);\n const yList = points.map((p) => p.y);\n\n const x = Math.min(...xList);\n const y = Math.max(...yList);\n\n return {\n id,\n x,\n y,\n points,\n imageHeight,\n imageWidth,\n };\n }\n\n return {\n id: '',\n x: 0,\n y: 0,\n points: [],\n imageHeight,\n imageWidth,\n };\n } else {\n return null;\n }\n }\n\n getOffset = (points) => {\n const xList = points.map((p) => p.x);\n const yList = points.map((p) => p.y);\n\n return {\n x: Math.min(...xList),\n y: Math.max(...yList),\n };\n };\n\n serialize = (points) => {\n const { x: xOffset, y: yOffset } = this.getOffset(points);\n\n return points.reduce((acc, point) => [...acc, point.x - xOffset, point.y - yOffset], []);\n };\n\n getInitialState = (points) => {\n if (points.length) {\n const { x, y } = this.getOffset(points);\n\n return {\n x,\n y,\n points,\n };\n }\n\n return {\n id: '',\n x: 0,\n y: 0,\n points: [],\n };\n };\n\n state = {\n hovered: false,\n isDragging: false,\n ...this.getInitialState(this.props.points),\n };\n\n handleClick = (e) => {\n const { points } = this.props;\n const xList = points.map((p) => p.x);\n const yList = points.map((p) => p.y);\n\n const width = Math.max(...xList) - Math.min(...xList);\n const height = Math.max(...yList) - Math.min(...yList);\n\n const { isDrawing, onClick, id } = this.props;\n\n if (width < 0 && height < 0 && isDrawing) {\n return;\n }\n\n if (isDrawing && id === 'newPolygon') {\n this.props.addPolygonPoint(e);\n return;\n }\n\n e.cancelBubble = true;\n onClick(id);\n };\n\n handleMouseEnter = () => {\n this.setState({ hovered: true });\n document.body.style.cursor = 'pointer';\n };\n\n handleMouseLeave = () => {\n this.setState({ hovered: false });\n document.body.style.cursor = 'default';\n };\n\n handleOnDragEnd = (e, updateModel = false) => {\n const { onDragEnd, id } = this.props;\n const points = e.target.points() || this.serialize(this.state.points);\n\n const newPoints = points.reduce((acc, currentPointCoordinate, index) => {\n if (index % 2 === 0 && index + 1 < points.length) {\n return [\n ...acc,\n {\n x: currentPointCoordinate + e.target.x(),\n y: points[index + 1] + e.target.y(),\n },\n ];\n }\n\n return acc;\n }, []);\n\n this.setState({\n points: newPoints,\n ...this.getOffset(newPoints),\n isDragging: updateModel ? false : this.state.isDragging,\n });\n };\n\n handleOnDragVertex = (e, changedIndex, updateModel) => {\n const { onDragEnd, id } = this.props;\n const { points } = this.state;\n\n const newPoints = points.map((point, index) =>\n index === changedIndex ? { x: e.target.x(), y: e.target.y() } : point,\n );\n\n this.setState({\n points: newPoints,\n ...this.getOffset(newPoints),\n isDragging: updateModel ? false : this.state.isDragging,\n });\n\n if (updateModel) {\n onDragEnd(id, { points: newPoints });\n }\n };\n\n onDragStart = () => {\n this.setState({ isDragging: true });\n };\n\n handleDelete = (id) => {\n const { onDeleteShape } = this.props;\n onDeleteShape(id);\n };\n\n render() {\n const { classes, correct, id, hotspotColor, outlineColor, strokeWidth = 5 } = this.props;\n const { points, x, y, hovered } = this.state;\n const showPoints = hovered || id === 'newPolygon';\n\n const calculatedStrokeWidth = correct ? strokeWidth : hovered ? 1 : 0;\n const calculatedStroke = correct ? outlineColor : hovered ? HOVERED_COLOR : '';\n\n return (\n <Group classes={classes.group} onMouseLeave={this.handleMouseLeave} onMouseEnter={this.handleMouseEnter}>\n <Line\n classes={classes.base}\n points={this.serialize(points)}\n closed={true}\n fill={hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable\n stroke={calculatedStroke}\n strokeWidth={calculatedStrokeWidth}\n onDragStart={this.onDragStart}\n onDragMove={this.handleOnDragEnd}\n onDragEnd={(e) => this.handleOnDragEnd(e, true)}\n x={x}\n y={y}\n />\n\n {showPoints &&\n points.map((point, index) => (\n <Circle\n key={index}\n className={classes.circle}\n x={point.x}\n y={point.y}\n radius={5}\n fill={'white'}\n stroke={HOVERED_COLOR}\n strokeWidth={1}\n onClick={this.handleClick}\n onDragStart={this.onDragStart}\n onDragMove={(e) => {\n this.handleOnDragVertex(e, index);\n }}\n onDragEnd={(e) => {\n this.handleOnDragVertex(e, index, true);\n }}\n draggable\n />\n ))}\n {!this.state.isDragging && this.state.hovered && (\n <DeleteWidget\n x={x}\n y={y}\n id={id}\n handleWidgetClick={this.handleDelete}\n points={points}\n outlineColor={outlineColor}\n />\n )}\n </Group>\n );\n }\n}\n\nconst styles = () => ({\n base: {\n cursor: 'pointer',\n opacity: 0.5,\n },\n circle: {\n opacity: 4,\n },\n group: {\n padding: '12px',\n },\n});\n\nPolComponent.propTypes = {\n classes: PropTypes.object.isRequired,\n correct: PropTypes.bool,\n isDrawing: PropTypes.bool.isRequired,\n id: PropTypes.string.isRequired,\n imageHeight: PropTypes.number,\n imageWidth: PropTypes.number,\n hotspotColor: PropTypes.string.isRequired,\n onClick: PropTypes.func.isRequired,\n addPolygonPoint: PropTypes.func.isRequired,\n onDeleteShape: PropTypes.func.isRequired,\n onDragEnd: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n points: PropTypes.arrayOf(\n PropTypes.shape({\n x: PropTypes.number,\n y: PropTypes.number,\n }),\n ).isRequired,\n strokeWidth: PropTypes.number,\n};\n\nPolComponent.defaultProps = {\n correct: false,\n};\n\nexport default withStyles(styles)(PolComponent);\n"],"file":"hotspot-polygon.js"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
+
|
|
16
|
+
var CircleShape = /*#__PURE__*/function () {
|
|
17
|
+
function CircleShape() {
|
|
18
|
+
(0, _classCallCheck2["default"])(this, CircleShape);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
(0, _createClass2["default"])(CircleShape, null, [{
|
|
22
|
+
key: "create",
|
|
23
|
+
value: function create(shapes, e) {
|
|
24
|
+
var newShapes = (0, _toConsumableArray2["default"])(shapes);
|
|
25
|
+
var highestId = Math.max.apply(Math, (0, _toConsumableArray2["default"])(newShapes.map(function (shape) {
|
|
26
|
+
return parseInt(shape.id);
|
|
27
|
+
})).concat([0]));
|
|
28
|
+
var newCircle = {
|
|
29
|
+
id: "".concat(highestId + 1),
|
|
30
|
+
radius: 0,
|
|
31
|
+
x: e.evt.layerX,
|
|
32
|
+
y: e.evt.layerY,
|
|
33
|
+
group: 'circles',
|
|
34
|
+
index: newShapes.length
|
|
35
|
+
};
|
|
36
|
+
newShapes.push(newCircle);
|
|
37
|
+
return {
|
|
38
|
+
newShapes: newShapes,
|
|
39
|
+
isDrawing: true,
|
|
40
|
+
isDrawingShapeId: newCircle.id
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
key: "finalizeCreation",
|
|
45
|
+
value: function finalizeCreation(state, props) {
|
|
46
|
+
var currentShapeIndex = state.shapes.findIndex(function (shape) {
|
|
47
|
+
return shape.id === state.isDrawingShapeId;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (currentShapeIndex !== -1) {
|
|
51
|
+
var currentShape = state.shapes[currentShapeIndex];
|
|
52
|
+
var updatedShapes = (0, _toConsumableArray2["default"])(props.shapes);
|
|
53
|
+
|
|
54
|
+
if (currentShape.radius > 0) {
|
|
55
|
+
updatedShapes.push(currentShape);
|
|
56
|
+
return {
|
|
57
|
+
isDrawing: false,
|
|
58
|
+
stateShapes: false,
|
|
59
|
+
isDrawingShapeId: undefined,
|
|
60
|
+
shapes: updatedShapes
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return state;
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "handleMouseMove",
|
|
69
|
+
value: function handleMouseMove(state, e) {
|
|
70
|
+
var isDrawing = state.isDrawing,
|
|
71
|
+
isDrawingShapeId = state.isDrawingShapeId,
|
|
72
|
+
shapes = state.shapes;
|
|
73
|
+
|
|
74
|
+
if (isDrawing) {
|
|
75
|
+
var tempShapes = (0, _toConsumableArray2["default"])(shapes);
|
|
76
|
+
var resizingShapeIndex = tempShapes.findIndex(function (shape) {
|
|
77
|
+
return shape.id === isDrawingShapeId;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (resizingShapeIndex !== -1) {
|
|
81
|
+
var resizingShape = tempShapes[resizingShapeIndex];
|
|
82
|
+
resizingShape.radius = Math.sqrt(Math.pow(e.evt.layerX - resizingShape.x, 2) + Math.pow(e.evt.layerY - resizingShape.y, 2));
|
|
83
|
+
return {
|
|
84
|
+
shapes: tempShapes
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return state;
|
|
90
|
+
}
|
|
91
|
+
}]);
|
|
92
|
+
return CircleShape;
|
|
93
|
+
}();
|
|
94
|
+
|
|
95
|
+
exports["default"] = CircleShape;
|
|
96
|
+
//# sourceMappingURL=circle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shapes/circle.js"],"names":["CircleShape","shapes","e","newShapes","highestId","Math","max","map","shape","parseInt","id","newCircle","radius","x","evt","layerX","y","layerY","group","index","length","push","isDrawing","isDrawingShapeId","state","props","currentShapeIndex","findIndex","currentShape","updatedShapes","stateShapes","undefined","tempShapes","resizingShapeIndex","resizingShape","sqrt","pow"],"mappings":";;;;;;;;;;;;;;;IAAqBA,W;;;;;;;WACnB,gBAAcC,MAAd,EAAsBC,CAAtB,EAAyB;AACvB,UA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,YAAAA,SAAS,EAAE,KADN;AAELQ,YAAAA,WAAW,EAAE,KAFR;AAGLP,YAAAA,gBAAgB,EAAEQ,SAHb;AAIL9B,YAAAA,MAAM,EAAE4B;AAJH,WAAP;AAMD;AACF;;AAED,aAAOL,KAAP;AACD;;;WAED,yBAAuBA,KAAvB,EAA8BtB,CAA9B,EAAiC;AAC/B,UAAQoB,SAAR,GAAgDE,KAAhD,CAAQF,SAAR;AAAA,UAAmBC,gBAAnB,GAAgDC,KAAhD,CAAmBD,gBAAnB;AAAA,UAAqCtB,MAArC,GAAgDuB,KAAhD,CAAqCvB,MAArC;;AAEA,UAAIqB,SAAJ,EAAe;AACb,YAAMU,UAAU,uCAAO/B,MAAP,CAAhB;AACA,YAAMgC,kBAAkB,GAAGD,UAAU,CAACL,SAAX,CAAqB,UAACnB,KAAD;AAAA,iBAAWA,KAAK,CAACE,EAAN,KAAaa,gBAAxB;AAAA,SAArB,CAA3B;;AAEA,YAAIU,kBAAkB,KAAK,CAAC,CAA5B,EAA+B;AAC7B,cAAMC,aAAa,GAAGF,UAAU,CAACC,kBAAD,CAAhC;AAEAC,UAAAA,aAAa,CAACtB,MAAd,GAAuBP,IAAI,CAAC8B,IAAL,CACrB9B,IAAI,CAAC+B,GAAL,CAASlC,CAAC,CAACY,GAAF,CAAMC,MAAN,GAAemB,aAAa,CAACrB,CAAtC,EAAyC,CAAzC,IAA8CR,IAAI,CAAC+B,GAAL,CAASlC,CAAC,CAACY,GAAF,CAAMG,MAAN,GAAeiB,aAAa,CAAClB,CAAtC,EAAyC,CAAzC,CADzB,CAAvB;AAIA,iBAAO;AACLf,YAAAA,MAAM,EAAE+B;AADH,WAAP;AAGD;AACF;;AAED,aAAOR,KAAP;AACD","sourcesContent":["export default class CircleShape {\n static create(shapes, e) {\n const newShapes = [...shapes];\n const highestId = Math.max(...newShapes.map((shape) => parseInt(shape.id)), 0);\n const newCircle = {\n id: `${highestId + 1}`,\n radius: 0,\n x: e.evt.layerX,\n y: e.evt.layerY,\n group: 'circles',\n index: newShapes.length,\n };\n\n newShapes.push(newCircle);\n\n return {\n newShapes,\n isDrawing: true,\n isDrawingShapeId: newCircle.id,\n };\n }\n\n static finalizeCreation(state, props) {\n const currentShapeIndex = state.shapes.findIndex((shape) => shape.id === state.isDrawingShapeId);\n\n if (currentShapeIndex !== -1) {\n const currentShape = state.shapes[currentShapeIndex];\n const updatedShapes = [...props.shapes];\n\n if (currentShape.radius > 0) {\n updatedShapes.push(currentShape);\n\n return {\n isDrawing: false,\n stateShapes: false,\n isDrawingShapeId: undefined,\n shapes: updatedShapes,\n };\n }\n }\n\n return state;\n }\n\n static handleMouseMove(state, e) {\n const { isDrawing, isDrawingShapeId, shapes } = state;\n\n if (isDrawing) {\n const tempShapes = [...shapes];\n const resizingShapeIndex = tempShapes.findIndex((shape) => shape.id === isDrawingShapeId);\n\n if (resizingShapeIndex !== -1) {\n const resizingShape = tempShapes[resizingShapeIndex];\n\n resizingShape.radius = Math.sqrt(\n Math.pow(e.evt.layerX - resizingShape.x, 2) + Math.pow(e.evt.layerY - resizingShape.y, 2),\n );\n\n return {\n shapes: tempShapes,\n };\n }\n }\n\n return state;\n }\n}\n"],"file":"circle.js"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
+
|
|
16
|
+
var PolygonShape = /*#__PURE__*/function () {
|
|
17
|
+
function PolygonShape() {
|
|
18
|
+
(0, _classCallCheck2["default"])(this, PolygonShape);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
(0, _createClass2["default"])(PolygonShape, null, [{
|
|
22
|
+
key: "create",
|
|
23
|
+
value: function create(shapes, e) {
|
|
24
|
+
var newShapes = (0, _toConsumableArray2["default"])(shapes);
|
|
25
|
+
var newPolygon = {
|
|
26
|
+
id: 'newPolygon',
|
|
27
|
+
points: [{
|
|
28
|
+
x: e.evt.layerX,
|
|
29
|
+
y: e.evt.layerY
|
|
30
|
+
}],
|
|
31
|
+
group: 'polygons',
|
|
32
|
+
index: newShapes.length
|
|
33
|
+
};
|
|
34
|
+
newShapes.push(newPolygon);
|
|
35
|
+
return {
|
|
36
|
+
shapes: newShapes,
|
|
37
|
+
isDrawing: true,
|
|
38
|
+
isDrawingShapeId: newPolygon.id
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
key: "addPoint",
|
|
43
|
+
value: function addPoint(state, e, onPolygonComplete) {
|
|
44
|
+
// Number of pixels allowed to determine if the first point was clicked
|
|
45
|
+
var clickDelta = 5;
|
|
46
|
+
var shapesCopy = JSON.parse(JSON.stringify(state.shapes));
|
|
47
|
+
var currentShapeIndex = shapesCopy.findIndex(function (shape) {
|
|
48
|
+
return shape.id === state.isDrawingShapeId;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (currentShapeIndex !== -1) {
|
|
52
|
+
var currentShape = shapesCopy[currentShapeIndex];
|
|
53
|
+
|
|
54
|
+
if (currentShape.points && Array.isArray(currentShape.points)) {
|
|
55
|
+
var firstPoint = currentShape.points[0]; // If click is close enough to the first point (within clickDelta pixels), close the polygon
|
|
56
|
+
|
|
57
|
+
if (Math.abs(firstPoint.x - e.evt.layerX) <= clickDelta && Math.abs(firstPoint.y - e.evt.layerY) <= clickDelta) {
|
|
58
|
+
return PolygonShape.finalizeCreation(state, onPolygonComplete);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
currentShape.points.push({
|
|
62
|
+
x: e.evt.layerX,
|
|
63
|
+
y: e.evt.layerY
|
|
64
|
+
});
|
|
65
|
+
shapesCopy[currentShapeIndex] = currentShape;
|
|
66
|
+
return {
|
|
67
|
+
shapes: shapesCopy
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return state;
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
key: "finalizeCreation",
|
|
76
|
+
value: function finalizeCreation(state, onPolygonComplete) {
|
|
77
|
+
var shapes = state.shapes;
|
|
78
|
+
var tempShapes = (0, _toConsumableArray2["default"])(shapes);
|
|
79
|
+
var highestId = Math.max.apply(Math, (0, _toConsumableArray2["default"])(state.shapes.map(function (shape) {
|
|
80
|
+
return parseInt(shape.id) || 0;
|
|
81
|
+
})).concat([0]));
|
|
82
|
+
var polygonIndex = tempShapes.findIndex(function (shape) {
|
|
83
|
+
return shape.id === state.isDrawingShapeId;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (polygonIndex !== -1 && tempShapes[polygonIndex].points.length > 2) {
|
|
87
|
+
var completedPolygon = tempShapes[polygonIndex];
|
|
88
|
+
completedPolygon.id = "".concat(highestId + 1);
|
|
89
|
+
onPolygonComplete(tempShapes);
|
|
90
|
+
return {
|
|
91
|
+
isDrawing: false,
|
|
92
|
+
shapes: tempShapes,
|
|
93
|
+
isDrawingShapeId: undefined
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return state;
|
|
98
|
+
} // No need to update anything on mouse move,
|
|
99
|
+
// but it's here if we need to add any logic later.
|
|
100
|
+
|
|
101
|
+
}, {
|
|
102
|
+
key: "handleMouseMove",
|
|
103
|
+
value: function handleMouseMove(state, e) {
|
|
104
|
+
return state;
|
|
105
|
+
}
|
|
106
|
+
}]);
|
|
107
|
+
return PolygonShape;
|
|
108
|
+
}();
|
|
109
|
+
|
|
110
|
+
exports["default"] = PolygonShape;
|
|
111
|
+
//# sourceMappingURL=polygon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shapes/polygon.js"],"names":["PolygonShape","shapes","e","newShapes","newPolygon","id","points","x","evt","layerX","y","layerY","group","index","length","push","isDrawing","isDrawingShapeId","state","onPolygonComplete","clickDelta","shapesCopy","JSON","parse","stringify","currentShapeIndex","findIndex","shape","currentShape","Array","isArray","firstPoint","Math","abs","finalizeCreation","tempShapes","highestId","max","map","parseInt","polygonIndex","completedPolygon","undefined"],"mappings":";;;;;;;;;;;;;;;IAAqBA,Y;;;;;;;WACnB,gBAAcC,MAAd,EAAsBC,CAAtB,EAAyB;AACvB,UAAMC,SAAS,uCAAOF,MAAP,CAAf;AACA,UAAMG,UAAU,GAAG;AACjBC,QAAAA,EAAE,EAAE,YADa;AAEjBC,QAAAA,MAAM,EAAE,CAAC;AAAEC,UAAAA,CAAC,EAAEL,CAAC,CAACM,GAAF,CAAMC,MAAX;AAAmBC,UAAAA,CAAC,EAAER,CAAC,CAACM,GAAF,CAAMG;AAA5B,SAAD,CAFS;AAGjBC,QAAAA,KAAK,EAAE,UAHU;AAIjBC,QAAAA,KAAK,EAAEV,SAAS,CAACW;AAJA,OAAnB;AAOAX,MAAAA,SAAS,CAACY,IAAV,CAAeX,UAAf;AAEA,aAAO;AACLH,QAAAA,MAAM,EAAEE,SADH;AAELa,QAAAA,SAAS,EAAE,IAFN;AAGLC,QAAAA,gBAAgB,EAAEb,UAAU,CAACC;AAHxB,OAAP;AAKD;;;WAED,kBAAgBa,KAAhB,EAAuBhB,CAAvB,EAA0BiB,iBAA1B,EAA6C;AAC3C;AACA,UAAMC,UAAU,GAAG,CAAnB;AAEA,UAAMC,UAAU,GAAGC,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,SAAL,CAAeN,KAAK,CAACjB,MAArB,CAAX,CAAnB;AACA,UAAMwB,iBAAiB,GAAGJ,UAAU,CAACK,S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,CAACjB,MAAN,CAAaqC,GAAb,CAAiB,UAACX,KAAD;AAAA,eAAWY,QAAQ,CAACZ,KAAK,CAACtB,EAAP,CAAR,IAAsB,CAAjC;AAAA,OAAjB,CAAR,UAA8D,CAA9D,GAAtB;AAEA,UAAMmC,YAAY,GAAGL,UAAU,CAACT,SAAX,CAAqB,UAACC,KAAD;AAAA,eAAWA,KAAK,CAACtB,EAAN,KAAaa,KAAK,CAACD,gBAA9B;AAAA,OAArB,CAArB;;AAEA,UAAIuB,YAAY,KAAK,CAAC,CAAlB,IAAuBL,UAAU,CAACK,YAAD,CAAV,CAAyBlC,MAAzB,CAAgCQ,MAAhC,GAAyC,CAApE,EAAuE;AACrE,YAAM2B,gBAAgB,GAAGN,UAAU,CAACK,YAAD,CAAnC;AAEAC,QAAAA,gBAAgB,CAACpC,EAAjB,aAAyB+B,SAAS,GAAG,CAArC;AACAjB,QAAAA,iBAAiB,CAACgB,UAAD,CAAjB;AAEA,eAAO;AACLnB,UAAAA,SAAS,EAAE,KADN;AAELf,UAAAA,MAAM,EAAEkC,UAFH;AAGLlB,UAAAA,gBAAgB,EAAEyB;AAHb,SAAP;AAKD;;AAED,aAAOxB,KAAP;AACD,K,CAED;AACA;;;;WACA,yBAAuBA,KAAvB,EAA8BhB,CAA9B,EAAiC;AAC/B,aAAOgB,KAAP;AACD","sourcesContent":["export default class PolygonShape {\n static create(shapes, e) {\n const newShapes = [...shapes];\n const newPolygon = {\n id: 'newPolygon',\n points: [{ x: e.evt.layerX, y: e.evt.layerY }],\n group: 'polygons',\n index: newShapes.length,\n };\n\n newShapes.push(newPolygon);\n\n return {\n shapes: newShapes,\n isDrawing: true,\n isDrawingShapeId: newPolygon.id,\n };\n }\n\n static addPoint(state, e, onPolygonComplete) {\n // Number of pixels allowed to determine if the first point was clicked\n const clickDelta = 5;\n\n const shapesCopy = JSON.parse(JSON.stringify(state.shapes));\n const currentShapeIndex = shapesCopy.findIndex((shape) => shape.id === state.isDrawingShapeId);\n\n if (currentShapeIndex !== -1) {\n const currentShape = shapesCopy[currentShapeIndex];\n if (currentShape.points && Array.isArray(currentShape.points)) {\n const firstPoint = currentShape.points[0];\n\n // If click is close enough to the first point (within clickDelta pixels), close the polygon\n if (\n Math.abs(firstPoint.x - e.evt.layerX) <= clickDelta &&\n Math.abs(firstPoint.y - e.evt.layerY) <= clickDelta\n ) {\n return PolygonShape.finalizeCreation(state, onPolygonComplete);\n }\n\n currentShape.points.push({ x: e.evt.layerX, y: e.evt.layerY });\n shapesCopy[currentShapeIndex] = currentShape;\n\n return {\n shapes: shapesCopy,\n };\n }\n }\n return state;\n }\n\n static finalizeCreation(state, onPolygonComplete) {\n const { shapes } = state;\n const tempShapes = [...shapes];\n const highestId = Math.max(...state.shapes.map((shape) => parseInt(shape.id) || 0), 0);\n\n const polygonIndex = tempShapes.findIndex((shape) => shape.id === state.isDrawingShapeId);\n\n if (polygonIndex !== -1 && tempShapes[polygonIndex].points.length > 2) {\n const completedPolygon = tempShapes[polygonIndex];\n\n completedPolygon.id = `${highestId + 1}`;\n onPolygonComplete(tempShapes);\n\n return {\n isDrawing: false,\n shapes: tempShapes,\n isDrawingShapeId: undefined,\n };\n }\n\n return state;\n }\n\n // No need to update anything on mouse move,\n // but it's here if we need to add any logic later.\n static handleMouseMove(state, e) {\n return state;\n }\n}\n"],"file":"polygon.js"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
+
|
|
14
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
+
|
|
16
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
var RectangleShape = /*#__PURE__*/function () {
|
|
23
|
+
function RectangleShape() {
|
|
24
|
+
(0, _classCallCheck2["default"])(this, RectangleShape);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
(0, _createClass2["default"])(RectangleShape, null, [{
|
|
28
|
+
key: "create",
|
|
29
|
+
value: function create(shapes, e) {
|
|
30
|
+
var newShapes = (0, _toConsumableArray2["default"])(shapes);
|
|
31
|
+
var highestId = Math.max.apply(Math, (0, _toConsumableArray2["default"])(newShapes.map(function (shape) {
|
|
32
|
+
return parseInt(shape.id);
|
|
33
|
+
})).concat([0])) || 0;
|
|
34
|
+
var newRectangle = {
|
|
35
|
+
id: "".concat(highestId + 1),
|
|
36
|
+
height: 0,
|
|
37
|
+
width: 0,
|
|
38
|
+
x: e.evt.layerX,
|
|
39
|
+
y: e.evt.layerY,
|
|
40
|
+
group: 'rectangles',
|
|
41
|
+
index: newShapes.length
|
|
42
|
+
};
|
|
43
|
+
newShapes.push(newRectangle);
|
|
44
|
+
return {
|
|
45
|
+
shapes: newShapes,
|
|
46
|
+
isDrawing: true,
|
|
47
|
+
isDrawingShapeId: newRectangle.id
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "finalizeCreation",
|
|
52
|
+
value: function finalizeCreation(state, props) {
|
|
53
|
+
var currentShapeIndex = state.shapes.findIndex(function (shape) {
|
|
54
|
+
return shape.id === state.isDrawingShapeId;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (currentShapeIndex !== -1) {
|
|
58
|
+
var currentShape = state.shapes[currentShapeIndex]; // Check if the shape is a valid rectangle (has more than 0 width and height) before finalizing
|
|
59
|
+
|
|
60
|
+
if (currentShape.width > 0 && currentShape.height > 0) {
|
|
61
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
62
|
+
isDrawing: false,
|
|
63
|
+
stateShapes: false,
|
|
64
|
+
isDrawingShapeId: undefined
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
68
|
+
isDrawing: false,
|
|
69
|
+
stateShapes: false,
|
|
70
|
+
isDrawingShapeId: undefined,
|
|
71
|
+
shapes: state.shapes.filter(function (shape) {
|
|
72
|
+
return shape.id !== state.isDrawingShapeId;
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
} // Return current state if not drawing a rectangle
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
80
|
+
isDrawing: false,
|
|
81
|
+
stateShapes: false,
|
|
82
|
+
isDrawingShapeId: undefined
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
key: "handleMouseMove",
|
|
87
|
+
value: function handleMouseMove(state, e) {
|
|
88
|
+
var isDrawing = state.isDrawing,
|
|
89
|
+
isDrawingShapeId = state.isDrawingShapeId,
|
|
90
|
+
shapes = state.shapes;
|
|
91
|
+
|
|
92
|
+
if (isDrawing) {
|
|
93
|
+
var tempShapes = (0, _toConsumableArray2["default"])(shapes);
|
|
94
|
+
var resizingShapeIndex = tempShapes.findIndex(function (shape) {
|
|
95
|
+
return shape.id === isDrawingShapeId;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (resizingShapeIndex !== -1) {
|
|
99
|
+
var resizingShape = tempShapes[resizingShapeIndex];
|
|
100
|
+
resizingShape.width = e.evt.layerX - resizingShape.x;
|
|
101
|
+
resizingShape.height = e.evt.layerY - resizingShape.y;
|
|
102
|
+
return {
|
|
103
|
+
shapes: tempShapes
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return state;
|
|
109
|
+
}
|
|
110
|
+
}]);
|
|
111
|
+
return RectangleShape;
|
|
112
|
+
}();
|
|
113
|
+
|
|
114
|
+
exports["default"] = RectangleShape;
|
|
115
|
+
//# sourceMappingURL=rectagle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shapes/rectagle.js"],"names":["RectangleShape","shapes","e","newShapes","highestId","Math","max","map","shape","parseInt","id","newRectangle","height","width","x","evt","layerX","y","layerY","group","index","length","push","isDrawing","isDrawingShapeId","state","props","currentShapeIndex","findIndex","currentShape","stateShapes","undefined","filter","tempShapes","resizingShapeIndex","resizingShape"],"mappings":";;;;;;;;;;;;;;;;;;;;;IAAqBA,c;;;;;;;WACnB,gBAAcC,MAAd,EAAsBC,CAAtB,EAAyB;AACvB,UAAMC,SAAS,uCAAOF,MAAP,CAAf;AACA,UAAMG,SAAS,GAAGC,IAAI,CAACC,GAAL,OAAAD,IAAI,sCAAQF,SAAS,CAACI,GAAV,CAAc,UAACC,KAAD;AAAA,eAAWC,QAAQ,CAACD,KAAK,CAACE,EAAP,CAAnB;AAAA,OAAd,CAAR,UAAsD,CAAtD,GAAJ,IAAgE,CAAlF;AAEA,UAAMC,YAAY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AM,EAAEwB,KAAK,CAACxB,MAAN,CAAa+B,MAAb,CAAoB,UAACxB,KAAD;AAAA,qBAAWA,KAAK,CAACE,EAAN,KAAae,KAAK,CAACD,gBAA9B;AAAA,aAApB;AALV;AAOD;AACF,OAvBmC,CAyBpC;;;AACA,6CACKC,KADL;AAEEF,QAAAA,SAAS,EAAE,KAFb;AAGEO,QAAAA,WAAW,EAAE,KAHf;AAIEN,QAAAA,gBAAgB,EAAEO;AAJpB;AAMD;;;WAED,yBAAuBN,KAAvB,EAA8BvB,CAA9B,EAAiC;AAC/B,UAAQqB,SAAR,GAAgDE,KAAhD,CAAQF,SAAR;AAAA,UAAmBC,gBAAnB,GAAgDC,KAAhD,CAAmBD,gBAAnB;AAAA,UAAqCvB,MAArC,GAAgDwB,KAAhD,CAAqCxB,MAArC;;AAEA,UAAIsB,SAAJ,EAAe;AACb,YAAMU,UAAU,uCAAOhC,MAAP,CAAhB;AACA,YAAMiC,kBAAkB,GAAGD,UAAU,CAACL,SAAX,CAAqB,UAACpB,KAAD;AAAA,iBAAWA,KAAK,CAACE,EAAN,KAAac,gBAAxB;AAAA,SAArB,CAA3B;;AAEA,YAAIU,kBAAkB,KAAK,CAAC,CAA5B,EAA+B;AAC7B,cAAMC,aAAa,GAAGF,UAAU,CAACC,kBAAD,CAAhC;AAEAC,UAAAA,aAAa,CAACtB,KAAd,GAAsBX,CAAC,CAACa,GAAF,CAAMC,MAAN,GAAemB,aAAa,CAACrB,CAAnD;AACAqB,UAAAA,aAAa,CAACvB,MAAd,GAAuBV,CAAC,CAACa,GAAF,CAAMG,MAAN,GAAeiB,aAAa,CAAClB,CAApD;AAEA,iBAAO;AACLhB,YAAAA,MAAM,EAAEgC;AADH,WAAP;AAGD;AACF;;AAED,aAAOR,KAAP;AACD","sourcesContent":["export default class RectangleShape {\n static create(shapes, e) {\n const newShapes = [...shapes];\n const highestId = Math.max(...newShapes.map((shape) => parseInt(shape.id)), 0) || 0;\n\n const newRectangle = {\n id: `${highestId + 1}`,\n height: 0,\n width: 0,\n x: e.evt.layerX,\n y: e.evt.layerY,\n group: 'rectangles',\n index: newShapes.length,\n };\n\n newShapes.push(newRectangle);\n\n return {\n shapes: newShapes,\n isDrawing: true,\n isDrawingShapeId: newRectangle.id,\n };\n }\n\n static finalizeCreation(state, props) {\n const currentShapeIndex = state.shapes.findIndex((shape) => shape.id === state.isDrawingShapeId);\n\n if (currentShapeIndex !== -1) {\n const currentShape = state.shapes[currentShapeIndex];\n\n // Check if the shape is a valid rectangle (has more than 0 width and height) before finalizing\n if (currentShape.width > 0 && currentShape.height > 0) {\n return {\n ...state,\n isDrawing: false,\n stateShapes: false,\n isDrawingShapeId: undefined,\n };\n } else {\n return {\n ...state,\n isDrawing: false,\n stateShapes: false,\n isDrawingShapeId: undefined,\n shapes: state.shapes.filter((shape) => shape.id !== state.isDrawingShapeId),\n };\n }\n }\n\n // Return current state if not drawing a rectangle\n return {\n ...state,\n isDrawing: false,\n stateShapes: false,\n isDrawingShapeId: undefined,\n };\n }\n\n static handleMouseMove(state, e) {\n const { isDrawing, isDrawingShapeId, shapes } = state;\n\n if (isDrawing) {\n const tempShapes = [...shapes];\n const resizingShapeIndex = tempShapes.findIndex((shape) => shape.id === isDrawingShapeId);\n\n if (resizingShapeIndex !== -1) {\n const resizingShape = tempShapes[resizingShapeIndex];\n\n resizingShape.width = e.evt.layerX - resizingShape.x;\n resizingShape.height = e.evt.layerY - resizingShape.y;\n\n return {\n shapes: tempShapes,\n };\n }\n }\n\n return state;\n }\n}\n"],"file":"rectagle.js"}
|
package/configure/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@material-ui/core": "^3.9.2",
|
|
11
11
|
"@material-ui/icons": "^3.0.2",
|
|
12
12
|
"@pie-framework/pie-configure-events": "^1.3.0",
|
|
13
|
-
"@pie-lib/pie-toolbox": "1.
|
|
13
|
+
"@pie-lib/pie-toolbox": "1.3.0",
|
|
14
14
|
"classnames": "^2.2.6",
|
|
15
15
|
"debug": "^3.1.0",
|
|
16
16
|
"konva": "^3.2.4",
|
|
@@ -11,6 +11,20 @@ exports[`HotspotContainer render renders 1`] = `
|
|
|
11
11
|
onPaste={[Function]}
|
|
12
12
|
>
|
|
13
13
|
<div>
|
|
14
|
+
<div
|
|
15
|
+
onClick={[Function]}
|
|
16
|
+
>
|
|
17
|
+
<RectangleButton
|
|
18
|
+
isActive={false}
|
|
19
|
+
/>
|
|
20
|
+
</div>
|
|
21
|
+
<div
|
|
22
|
+
onClick={[Function]}
|
|
23
|
+
>
|
|
24
|
+
<PolygonButton
|
|
25
|
+
isActive={false}
|
|
26
|
+
/>
|
|
27
|
+
</div>
|
|
14
28
|
<WithStyles(UploadControl)
|
|
15
29
|
label="Replace Image"
|
|
16
30
|
onInputClick={[Function]}
|
|
@@ -32,6 +46,7 @@ exports[`HotspotContainer render renders 1`] = `
|
|
|
32
46
|
}
|
|
33
47
|
disableDrag={[Function]}
|
|
34
48
|
enableDrag={[Function]}
|
|
49
|
+
handleFinishDrawing={[Function]}
|
|
35
50
|
hotspotColor="rgba(137, 183, 244, 0.65)"
|
|
36
51
|
imageUrl="https://cdn.fluence.net/image/0240eb1455ce4c4bb6180232347b6aef_W"
|
|
37
52
|
multipleCorrect={true}
|
|
@@ -39,6 +54,7 @@ exports[`HotspotContainer render renders 1`] = `
|
|
|
39
54
|
onUpdateImageDimension={[MockFunction]}
|
|
40
55
|
onUpdateShapes={[Function]}
|
|
41
56
|
outlineColor="blue"
|
|
57
|
+
shapeType="none"
|
|
42
58
|
shapes={
|
|
43
59
|
Array [
|
|
44
60
|
Object {
|