stage

<script src="./point_src/stage"></script>

A Stage acts as a convenience tool to hoist a canvas and begin drawing however it's not fundamental.

The Stage helps manage loading and looping of draw functions Extend with your own custom functionality and run the go() method:

class MainStage extends Stage {
    // canvas = document.getElementById('playspace');
    canvas = 'playspace'
}

stage = MainStage.go({
    loop: true
})

This will execute the canvas name. It provides some free tools:

  1. mount() and draw(ctx) functions
  2. load capture events
  3. size locking and auto resizing
  4. optional request frame loop
  5. builtin measurement tools; center and dimensions
Meta Data
dependencies ()
unused_keys ('title',)
unknown_keys ('files',)
files ['', 'stage-hooks.js', 'functions/resolve.js']
filepath_exists True
path stage
filepath stage.js
clean_files ('stage-hooks.js', 'functions/resolve.js')

  • ClassDeclaration
    class comments:
    an addon instance has anounced itself. Perform the addComponent
    • method

      addonAnnounceHandler

      (
      ev
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      an addon instance has anounced itself. Perform the addComponent

      this.dispatch('stage:prepare', {target, id, canvas })

    • method

      dispatch

      (
      name , data
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      this.dispatch('prepare', { target, id, stage: this, canvas })

    • method

      _dispatchPrepare

      (
      data
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Given a dictionary, return a finished dictionary, ready for event dispatch

    • method

      addComponent

      (
      name , instance
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      a given object is mounted on this - such as the mouse. This may be called in response to a 'stage:prepare' event.

    • method

      log

      (
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      console.log.apply(console, Array.from(arguments))

    dict_keys(['kind', 'word', 'parentName', 'type', 'body', 'comments', 'pos'])
  • ClassDeclaration
    class comments:
    Accept a `canvas` node and an optional `draw` function, prepare the stage draw routine. If the `canvas` is given, immediately call `this.prepare(canvas)` to initiate the layer. new StageRender(canvas, ()=>{}) Any given `drawFunc` overrides the existing `this.stageStartDraw` method and expects the _next_ method to call once complete: The default `this.draw(ctx)` method is given` this.stageStartDraw(this.draw)
    • property

      _drawFunc

      from class_name
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos'])
    • property

      _loopDraw

      = true
      from class_name
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos'])
    • property

      debounceResize

      = true
      from class_name
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos'])
    • property

      debounceResizeTimeout

      = 100
      from class_name
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos'])
    • constructor

      constructor

      (
      canvas , drawFunc
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
              Accept a `canvas` node and an optional `draw` function, prepare
              the stage draw routine. If the `canvas` is given, immediately call
              `this.prepare(canvas)` to initiate the layer.
      
                  new StageRender(canvas, ()=>{})
      
              Any given `drawFunc` overrides the existing `this.stageStartDraw` method
              and expects the _next_ method to call once complete:
      
              The default `this.draw(ctx)` method is given`
      
                  this.stageStartDraw(this.draw)
      
    • method

      stickCanvasSize

      (
      canvas , size
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Return the result of the bounding box function, else resort to the object w/h

    • get

      center

      (
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      prepare

      (
      target
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Perform any preparations for this stage instance to run the canvas tools. This includes resolving and measuring the canvas.

              class MainStage extends Stage {
                  canvas = playspace
                  prepare(target){
                      super.prepare(target)
                      // ...
                  }
              }
      
          This will run automatically if the canvas is given in the constructor
      
              new MainStage(canvas)
              // _prepared == true
      
          Once prepared the stage is essentially ready-to-go.
      
              stage = new MainStage()
              stage.prepare(canvas)
              stage.update()
      
    • method

      mounted

      (
      canvas
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      A Convenient place to perform initial work.

    • method

      stop

      (
      freeze = True
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      ensurePrepared

      (
      canvas
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      go

      (
      additionalData = {}
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Make a copy of a new Stage. Call prepare() if required. If additionalData.loop is true (default) start the update loopDraw

    • method

      freeze

      (
      freeze = True
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      unfreeze

      (
      timeout , force
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      1ms delay for a next tick.

    • method

      cleanGoConfig

      (
      info
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
              Return a dict, if the:
      
              + is dict,
              + thing is a string, assume name
              + thing is node, assume canvas
      
    • method

      go

      (
      additionalData = {}
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Make a copy of a new Stage. Call prepare() if required. If additionalData.loop is true (default) start the update loopDraw

    • method

      stageStartDraw

      (
      drawFunc
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      When using the internal loop drawing the first draw call occurs through this method, calling firstDraw once, then changing the internal draw function to the typical this.draw

          If `this.draw` is not a method, `this.update()` is called and the
          `stopDraw` method is called.
      
    • method

      loopDraw

      (
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      A helper function to apply this stage to the animation frame, calling update() for every frame.

          Call once to start the loop.
      
                  stage = new MainStage()
                  stage.prepare(canvas)
                  stage.loopDraw()
      
    • get

      ctx

      (
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Return the cached context object of the current canvas.

    • method

      getContext

      (
      canvas , type = 2d
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
          + `alpha`:
                  A boolean value that indicates if the canvas contains an alpha
                  channel. If set to false, the browser now knows that the
                  backdrop is always opaque, which can speed up drawing of
                  transparent content and images.
      
          + `colorSpace` Optional:
                  Specifies the color space of the rendering context.
                  Possible values are:
      
                      "srgb" selects the sRGB color space. (default value)
                      "display-p3" selects the display-p3 color space.
      
          + `desynchronized`:
                  A boolean value that hints the user agent to reduce the
                  latency by desynchronizing the canvas paint cycle from the
                  event loop.
      
          + `willReadFrequently`:
                  A boolean value that indicates whether or not a lot of
                  read-back operations are planned. This will force the use of
                  a software (instead of hardware accelerated) 2D canvas and
                  can save memory when calling getImageData() frequently.
      
    • method

      update

      (
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
              inline update per draw. For each call:
      
              + all _drawBefore_ methods
              + all _nextTick_ methods
              + the `draw` method (mapped through `this._drawFunc`)
              + all _drawAfter_ methods
      
    • method

      nextTick

      (
      func
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Run the given function (with context) on the next draw call. This function is very similar to onDrawBefore, but only runs once.

              stage.nextTick(function(ctx){
                  // run next time.
                  stage.runCustomRender(ctx)
              })
      
          This is useful for performing clearups, or running routines on
          single action:
      
              let v = this.v = new Value(this.p.radius, width, easing)
              v.doneHandler = ()=>{
                  // st.switchOut()
                  this.nextTick(this.switchOut.bind(this))
              }
      
              switchOut() {
                  this.log('doneHandler')
                  this.v = undefined;
              }
      
    • method

      onTick

      (
      tick , func
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      modulo auto

    • method

      onDrawAfter

      (
      func
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      offDrawAfter

      (
      func
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      onDrawBefore

      (
      func
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      offDrawBefore

      (
      func
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      firstDraw

      (
      ctx
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      The firstDraw(ctx) method us used once when drawing starts. This occurs before the first update() call is performed.

          This is useful if you're setting context arguments - but only need to
          set them once.
      
              class Main extends Stage {
                  firstDraw(ctx) {
                      ctx.fillStyle = '#ccc'
                      ctx.font = 'normal 1em arial'
                  }
              }
      
    • method

      draw

      (
      ctx
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      The primary rendering function to override. Called by the update() method, given the context ctx of the target canvas.

          This is essentially the same as running the update function
          manually:
      
      
              const ctx = canvas.getContext('2d');
              const stage = new MainStage()
      
              stage.prepare(canvas)
      
              function draw() {
      
                  // or: stage.clear(ctx)
                  ctx.clearRect(0, 0, canvas.width, canvas.height);
      
                  // Run the draw routines
                  stage.draw(ctx)
      
                  // And rinse repeat.
                  requestAnimationFrame(draw);
      
              }
      
              draw()
      
    • method

      clear

      (
      ctx , fillStyle
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Perform a standard 'clearRect' using the cached dimensions of the canvas.

              stage.clear(ctx)
      
          Synonymous to:
      
              const ctx = canvas.getContext('2d');
              ctx.clearRect(0, 0, canvas.width, canvas.height);
      
          Apply an optional flood fillStyle:
      
              stage.clear(ctx, '#000')
      
    dict_keys(['kind', 'word', 'parentName', 'type', 'body', 'comments', 'pos'])
  • ClassDeclaration
    class comments:
    Called once by the prepare() method, to act as a first-time loader for the stage. Apply global hooks here.
    • property

      loaded

      = false
      from class_name
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos'])
    • method

      prepare

      (
      target
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      load

      (
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Called once by the prepare() method, to act as a first-time loader for the stage.

           Apply global hooks here.
      
    dict_keys(['kind', 'word', 'parentName', 'type', 'body', 'comments', 'pos'])
  • ExpressionStatement

    :

    dict_keys(['type', 'expression', 'pos'])