Path2D.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _CanvasRenderingContext2D = _interopRequireDefault(require("./CanvasRenderingContext2D"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  9. // Path2D.prototype
  10. const Path2DFunc = ['addPath'];
  11. const borrowedFromCanvas = ['closePath', 'moveTo', 'lineTo', 'bezierCurveTo', 'quadraticCurveTo', 'arc', 'arcTo', 'ellipse', 'rect'];
  12. class Path2D {
  13. constructor() {
  14. _defineProperty(this, "_path", []);
  15. _defineProperty(this, "_events", []);
  16. _defineProperty(this, "_stackIndex", 0);
  17. _defineProperty(this, "_transformStack", [[1, 0, 0, 1, 0, 0]]);
  18. borrowedFromCanvas.forEach(key => {
  19. this[key] = jest.fn(_CanvasRenderingContext2D.default.prototype[key].bind(this));
  20. });
  21. Path2DFunc.forEach(key => {
  22. this[key] = jest.fn(this[key].bind(this));
  23. });
  24. }
  25. addPath(path) {
  26. if (arguments.length < 1) throw new TypeError('Failed to execute \'addPath\' on \'Path2D\': 1 argument required, but only 0 present.');
  27. if (!(path instanceof Path2D)) throw new TypeError('Failed to execute \'addPath\' on \'Path2D\': parameter 1 is not of type \'Path2D\'.');
  28. this._path = this._path.concat(path._path);
  29. }
  30. }
  31. exports.default = Path2D;