|
1137 | 1137 | exports._removeMouseEvents = _removeMouseEvents; |
1138 | 1138 | }); |
1139 | 1139 |
|
| 1140 | + var stroke = createCommonjsModule(function (module, exports) { |
| 1141 | + var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || function () { |
| 1142 | + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; |
| 1143 | + for (var r = Array(s), k = 0, i = 0; i < il; i++) |
| 1144 | + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) |
| 1145 | + r[k] = a[j]; |
| 1146 | + return r; |
| 1147 | + }; |
| 1148 | + Object.defineProperty(exports, "__esModule", { value: true }); |
| 1149 | + exports._doStroke = exports._endStroke = exports._startStroke = void 0; |
| 1150 | + function _startStroke(coords) { |
| 1151 | + this._strokeHappening = true; |
| 1152 | + this._drawnPaths[this._pathIndex + 1] = { |
| 1153 | + pathCoords: [], |
| 1154 | + color: this.brushColor.map(function (x) { return x; }), |
| 1155 | + mode: this.mode, |
| 1156 | + brushSize: this.brushSize, |
| 1157 | + eraserSize: this.eraserSize |
| 1158 | + }; |
| 1159 | + this._lastCoords = coords; |
| 1160 | + } |
| 1161 | + exports._startStroke = _startStroke; |
| 1162 | + function _endStroke(endCoords) { |
| 1163 | + if (this._lastCoords[0] === endCoords[0] && |
| 1164 | + this._lastCoords[1] === endCoords[1]) { |
| 1165 | + this._plot.apply(this, endCoords); |
| 1166 | + this._drawnPaths[this._pathIndex + 1].pathCoords.push(__spreadArrays(endCoords, [true])); |
| 1167 | + } |
| 1168 | + if (this._strokeHappening) { |
| 1169 | + this.canvas.removeEventListener('mousemove', this._strokeEventListener); |
| 1170 | + this._lastCoords = null; |
| 1171 | + if (this._drawnPaths[this._pathIndex + 1].pathCoords.length === 0) |
| 1172 | + this._drawnPaths.splice(-1, 1); |
| 1173 | + else { |
| 1174 | + this._drawnPaths = this._drawnPaths.slice(0, this._pathIndex + 2); // Overwrite further paths to prevent wrong redos |
| 1175 | + this._pathIndex++; |
| 1176 | + } |
| 1177 | + this._strokeHappening = false; |
| 1178 | + } |
| 1179 | + } |
| 1180 | + exports._endStroke = _endStroke; |
| 1181 | + function _doStroke(coords) { |
| 1182 | + this._strokeHappening = true; |
| 1183 | + this._drawnPaths[this._pathIndex + 1].pathCoords.push(__spreadArrays(coords, [false])); |
| 1184 | + this._stroke.apply(this, coords); |
| 1185 | + this._lastCoords = coords; |
| 1186 | + } |
| 1187 | + exports._doStroke = _doStroke; |
| 1188 | + }); |
| 1189 | + |
1140 | 1190 | var RealDrawBoard_1 = createCommonjsModule(function (module, exports) { |
1141 | 1191 | var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () { |
1142 | 1192 | var extendStatics = function (d, b) { |
|
1172 | 1222 | var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) { |
1173 | 1223 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); |
1174 | 1224 | }; |
1175 | | - var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || function () { |
1176 | | - for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; |
1177 | | - for (var r = Array(s), k = 0, i = 0; i < il; i++) |
1178 | | - for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) |
1179 | | - r[k] = a[j]; |
1180 | | - return r; |
1181 | | - }; |
1182 | 1225 | Object.defineProperty(exports, "__esModule", { value: true }); |
1183 | 1226 | exports.RealDrawBoard = exports.RealDrawBoardTypes = exports.RealRendererTypes = void 0; |
1184 | 1227 |
|
|
1192 | 1235 |
|
1193 | 1236 |
|
1194 | 1237 |
|
| 1238 | + |
1195 | 1239 | var RealDrawBoard = /** @class */ (function (_super) { |
1196 | 1240 | __extends(RealDrawBoard, _super); |
1197 | 1241 | function RealDrawBoard(options) { |
|
1209 | 1253 | _this._resetBoard = boardManip._resetBoard; |
1210 | 1254 | _this._addMouseEvents = _DOMEvents._addMouseEvents; |
1211 | 1255 | _this._removeMouseEvents = _DOMEvents._removeMouseEvents; |
| 1256 | + _this._startStroke = stroke._startStroke; |
| 1257 | + _this._endStroke = stroke._endStroke; |
| 1258 | + _this._doStroke = stroke._doStroke; |
1212 | 1259 | _this.undo = undo_1.undo; |
1213 | 1260 | _this.redo = undo_1.redo; |
1214 | 1261 | _this.changeBrushColor = boardManip.changeBrushColor; |
|
1226 | 1273 | _this._mouseDownEventListener = function (e) { |
1227 | 1274 | if (e.button === 0 /* Left Click */) { |
1228 | 1275 | _this.canvas.addEventListener('mousemove', _this._strokeEventListener); |
1229 | | - _this._strokeHappening = true; |
1230 | | - _this._drawnPaths[_this._pathIndex + 1] = { |
1231 | | - pathCoords: [], |
1232 | | - color: _this.brushColor.map(function (x) { return x; }), |
1233 | | - mode: _this.mode, |
1234 | | - brushSize: _this.brushSize, |
1235 | | - eraserSize: _this.eraserSize |
1236 | | - }; |
1237 | | - _this._lastCoords = _this._getCoords(e); |
| 1276 | + _this._startStroke(_this._getCoords(e)); |
1238 | 1277 | } |
1239 | 1278 | }; |
1240 | 1279 | _this._mouseUpEventListener = function (e) { |
1241 | | - if (e.button === 0) { |
1242 | | - var currentCoords = _this._getCoords(e); |
1243 | | - if (_this._lastCoords[0] === currentCoords[0] && |
1244 | | - _this._lastCoords[1] === currentCoords[1]) { |
1245 | | - _this._plot.apply(_this, currentCoords); |
1246 | | - _this._drawnPaths[_this._pathIndex + 1].pathCoords.push(__spreadArrays(currentCoords, [true])); |
1247 | | - } |
1248 | | - _this._strokeEnd(); |
| 1280 | + if (e.button === 0 /* Left Click */) { |
| 1281 | + var endCoords = _this._getCoords(e); |
| 1282 | + _this._endStroke(endCoords); |
1249 | 1283 | } |
1250 | 1284 | }; |
1251 | 1285 | _this._mouseEnterEventListener = function (e) { |
1252 | 1286 | _this._lastCoords = _this._getCoords(e); |
1253 | 1287 | }; |
1254 | 1288 | _this._mouseLeaveEventListener = function (e) { |
1255 | | - _this._strokeEnd(); |
| 1289 | + _this._endStroke(_this._getCoords(e)); |
1256 | 1290 | }; |
1257 | 1291 | _this._strokeEventListener = function (e) { |
1258 | 1292 | var coords = _this._getCoords(e); |
1259 | | - _this._strokeHappening = true; |
1260 | | - _this._drawnPaths[_this._pathIndex + 1].pathCoords.push(__spreadArrays(coords, [false])); |
1261 | | - _this._stroke.apply(_this, coords); |
1262 | | - _this._lastCoords = coords; |
1263 | | - }; |
1264 | | - _this._strokeEnd = function () { |
1265 | | - if (_this._strokeHappening) { |
1266 | | - _this.canvas.removeEventListener('mousemove', _this._strokeEventListener); |
1267 | | - _this._lastCoords = null; |
1268 | | - if (_this._drawnPaths[_this._pathIndex + 1].pathCoords.length === 0) |
1269 | | - _this._drawnPaths.splice(-1, 1); |
1270 | | - else { |
1271 | | - _this._drawnPaths = _this._drawnPaths.slice(0, _this._pathIndex + 2); // Overwrite further paths to prevent wrong redos |
1272 | | - _this._pathIndex++; |
1273 | | - } |
1274 | | - _this._strokeHappening = false; |
1275 | | - } |
| 1293 | + _this._doStroke(coords); |
1276 | 1294 | }; |
1277 | 1295 | options = __assign(__assign({}, RealDrawBoardDefaults.RealDrawBoardDefaults), options); |
1278 | 1296 | _this.options = options; |
|
0 commit comments