CanvasGradient.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _parseColor = _interopRequireDefault(require("parse-color"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. class CanvasGradient {
  9. constructor() {
  10. this.addColorStop = jest.fn(this.addColorStop.bind(this));
  11. }
  12. addColorStop(offset, color) {
  13. const numoffset = Number(offset);
  14. const colorstr = String(color);
  15. if (!Number.isFinite(numoffset) || numoffset < 0 || numoffset > 1) {
  16. throw new DOMException('IndexSizeError', 'Failed to execute \'addColorStop\' on \'CanvasGradient\': The provided value (\'' + numoffset + '\') is outside the range (0.0, 1.0)');
  17. }
  18. const output = (0, _parseColor.default)(colorstr);
  19. if (!output.hex) {
  20. throw new SyntaxError('Failed to execute \'addColorStop\' on \'CanvasGradient\': The value provided (\'' + color + '\') could not be parsed as a color.');
  21. }
  22. }
  23. }
  24. exports.default = CanvasGradient;