text: import {  cwv } from "/scripts/ext/Object/prop/desc.js"
  
  import Color from "/scripts/graph/Color.js"
  
  import "/scripts/ext/Object/prop/lazy.js"
  import "/scripts/ext/Object/prop/mixin.js"
  
  import "./Color.js"
  import "./Vec2.js"
  
  Object.mixinDefault(CanvasRenderingContext2D.prototype, {
      draw(dt = 0, ts = window.performance.now()) {
          this.clear(dt, ts)
  
          for (const drawCall of this.drawCalls)
              drawCall.call(this, dt, ts)
  
          if (this.showFPS)
              this.drawFPS(dt, ts)
      },
  
      clear(dt = 0, ts = window.performance.now()) {
          this.save()
          this.resetTransform()
          this.fillStyle = this.clearColor
          this.fillRect(0, 0, this.canvas.getSize())
          this.restore()
      },
  
      drawFPS(dt = 0, ts = window.performance.now()) {
          this.save()
          this.resetTransform()
  
          this.textBaseline = "top"
          this.font         = "32px sans-serif"
          this.fillStyle    = Color.RED
          this.fillText(Math.trunc(1 / dt), 0, 0)
  
          this.restore()
      },
  
      get redrawMode() {
          return this._redrawMode ?? "manual"
      },
  
      set redrawMode(val) {
          switch (val) {
              case "manual":
                  break
  
              case "auto":
                   const step = ts => {
                      ts /= 1000
                      const dt = ts - this.lastTS
                      this.lastTS = ts
  
                      this.draw(dt, ts)
  
                      if (this.redrawMode == "auto")
                          window.requestAnimationFrame(step)
                  }
  
                  window.requestAnimationFrame(step)
                  break
  
              default:
                  throw new Error(`invalid value (${val})`)
          }
  
          Object.defineProperty(this, "_redrawMode", cwv(val))
      }
  })
  
  Object.defineLazyProperties(CanvasRenderingContext2D.prototype, {
      showFPS: cwv(false)
  })
  
  Object.defineLazyInitProperties(CanvasRenderingContext2D.prototype, {
      drawCalls:  cwv(() => []),
      clearColor: cwv(() => Color.white()),
      lastTS:     cwv(() => window.performance.now())
  })
  