import { TypeBoardOptions , TypeContext } from '@idraw/types' ; import util from '@idraw/util' ; const Context = util . Context ; type TempDataDesc = { ctx : TypeContext ; } ; function createDefaultData ( opts ) { const canvas = document . createElement ( 'canvas' ) ; const ctx2d = canvas . getContext ( '2d' ) as CanvasRenderingContext2D ; const ctx = new Context ( ctx2d , { width : opts . width , height : opts . height , contextWidth : opts . contextWidth , contextHeight : opts . contextHeight , devicePixelRatio : opts . devicePixelRatio || window . devicePixelRatio || 1 , } ) ; return { plugins : [ ] , ctx : ctx } ; } export class TempData { private _temp : TempDataDesc ; constructor ( opts ) { this . _temp = createDefaultData ( opts ) ; } set < T extends keyof TempDataDesc > ( name , value ) { this . _temp [ name ] = value ; } get < T extends keyof TempDataDesc > ( name ) { return this . _temp [ name ] ; } clear ( opts ) { this . _temp = createDefaultData ( opts ) ; } }