UNPKG

606 BJavaScriptView Raw
1import { findDOM } from '../../utils';
2import { CanvasContext } from './CanvasContext';
3/**
4 * 创建 canvas 的绘图上下文 CanvasContext 对象
5 */
6export const createCanvasContext = (canvasId, inst) => {
7 const el = findDOM(inst);
8 const canvas = el === null || el === void 0 ? void 0 : el.querySelector(`canvas[canvas-id="${canvasId}"]`);
9 const ctx = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d');
10 const context = new CanvasContext(canvas, ctx);
11 if (!ctx)
12 return context;
13 context.canvas = canvas;
14 context.ctx = ctx;
15 return context;
16};