Stack factory
The Scrawl-canvas Stack/Element system is an attempt to supplement DOM elements with Scrawl-canvas entity positioning and dimensioning functionality.
- Entitys exist in a Cell environment
- They can position themselves within that Cell either absolutely (px coordinates), or relatively (% coordinates, with values relative to the Cell’s dimensions), or by reference (using other entity’s coordinates to calculate their own coordinates -
pivot, mimic, path)
- They can also base their dimensions on absolute (px) or relative (%) values
- They can be animated directly (
set, deltaSet), or through automation (delta object), or through the Scrawl-canvas tween functionality
- They can be stored and retrieved (‘packet’ functionality), cloned (‘clone’, based on packets) and killed (‘kill’ functions)
A Stack is a wrapper object around a DOM element, whose direct children are given Scrawl-canvas Element wrappers:
Stack ~~> Canvas/Cell
Element ~~> Entity (eg Block)
During initialization Scrawl-canvas will search the DOM tree and automatically create Stack wrappers for any element which has been given a data-stack attribute which resolves to true. Every direct (first level) child inside the stack element will have Element wrappers created for them (except for <canvas> elements). As part of this work, Scrawl-canvas will modify the affected elements’ position CSS style:
- Stack elements have
relative positioning within the DOM
- Element elements have
absolute positioning within the Stack
The Stack factory is not used directly; the factory is not exported as part of the scrawl object during Scrawl-canvas initialization. Instead, wrappers can be created for a DOM-based <div> element using the following scrawl function:
scrawl.addStack - generates a new <div> element, creates a wrapper for it, then adds it to the DOM.
Stack wrapper objects use the base, position, anchor, cascade and dom mixins. Thus Stack wrappers are also artefact objects: if a Stack’s DOM element is a direct child of another Stack wrapper’s element then it can be positioned, dimensioned and rotated like any other artefact.
By default, all Stack wrappers will track mouse/touch movements across their DOM element, supplying this data to constituent Canvas objects and artefacts as-and-when-required.
Stack wrappers are used by Scrawl-canvas to invoke the Display cycle cascade. As such, they include clear, compile, show and render functions to manage the Display cycle. These functions are asynchronous, returning Promises.
Stack wrappers are excluded from the Scrawl-canvas packet system; they cannot be saved or cloned. Killing a Stack wrapper will remove its DOM element from the document - including all Elements and Canvases that it contains.