UNPKG

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