getContext2dOrThrow.js 839 B

123456789101112131415161718192021
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var env_1 = require("../env");
  4. var resolveInput_1 = require("./resolveInput");
  5. function getContext2dOrThrow(canvasArg) {
  6. var _a = env_1.env.getEnv(), Canvas = _a.Canvas, CanvasRenderingContext2D = _a.CanvasRenderingContext2D;
  7. if (canvasArg instanceof CanvasRenderingContext2D) {
  8. return canvasArg;
  9. }
  10. var canvas = resolveInput_1.resolveInput(canvasArg);
  11. if (!(canvas instanceof Canvas)) {
  12. throw new Error('resolveContext2d - expected canvas to be of instance of Canvas');
  13. }
  14. var ctx = canvas.getContext('2d');
  15. if (!ctx) {
  16. throw new Error('resolveContext2d - canvas 2d context is null');
  17. }
  18. return ctx;
  19. }
  20. exports.getContext2dOrThrow = getContext2dOrThrow;
  21. //# sourceMappingURL=getContext2dOrThrow.js.map