UNPKG

scrawl-canvas

Version:
1,009 lines (664 loc) 70 kB
<!DOCTYPE html> <html> <head> <title>Stack factory</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <ul id="jump_to"> <li> <a class="large" href="javascript:void(0);">Jump To &hellip;</a> <a class="small" href="javascript:void(0);">+</a> <div id="jump_wrapper"> <div id="jump_page_wrapper"> <div id="jump_page"> <a class="source" href="../core/animationloop.html"> ./source/core/animationloop.js </a> <a class="source" href="../core/document.html"> ./source/core/document.js </a> <a class="source" href="../core/events.html"> ./source/core/events.js </a> <a class="source" href="../core/init.html"> ./source/core/init.js </a> <a class="source" href="../core/library.html"> ./source/core/library.js </a> <a class="source" href="../core/random-seed.html"> ./source/core/random-seed.js </a> <a class="source" href="../core/snippets.html"> ./source/core/snippets.js </a> <a class="source" href="../core/userInteraction.html"> ./source/core/userInteraction.js </a> <a class="source" href="../core/utilities.html"> ./source/core/utilities.js </a> <a class="source" href="action.html"> ./source/factory/action.js </a> <a class="source" href="anchor.html"> ./source/factory/anchor.js </a> <a class="source" href="animation.html"> ./source/factory/animation.js </a> <a class="source" href="bezier.html"> ./source/factory/bezier.js </a> <a class="source" href="block.html"> ./source/factory/block.js </a> <a class="source" href="canvas.html"> ./source/factory/canvas.js </a> <a class="source" href="cell.html"> ./source/factory/cell.js </a> <a class="source" href="cog.html"> ./source/factory/cog.js </a> <a class="source" href="color.html"> ./source/factory/color.js </a> <a class="source" href="conicGradient.html"> ./source/factory/conicGradient.js </a> <a class="source" href="coordinate.html"> ./source/factory/coordinate.js </a> <a class="source" href="crescent.html"> ./source/factory/crescent.js </a> <a class="source" href="element.html"> ./source/factory/element.js </a> <a class="source" href="emitter.html"> ./source/factory/emitter.js </a> <a class="source" href="filter.html"> ./source/factory/filter.js </a> <a class="source" href="filterEngine-bluenoiseData.html"> ./source/factory/filterEngine-bluenoiseData.js </a> <a class="source" href="filterEngine.html"> ./source/factory/filterEngine.js </a> <a class="source" href="fontAttributes.html"> ./source/factory/fontAttributes.js </a> <a class="source" href="gradient.html"> ./source/factory/gradient.js </a> <a class="source" href="grid.html"> ./source/factory/grid.js </a> <a class="source" href="group.html"> ./source/factory/group.js </a> <a class="source" href="imageAsset.html"> ./source/factory/imageAsset.js </a> <a class="source" href="line.html"> ./source/factory/line.js </a> <a class="source" href="lineSpiral.html"> ./source/factory/lineSpiral.js </a> <a class="source" href="loom.html"> ./source/factory/loom.js </a> <a class="source" href="mesh.html"> ./source/factory/mesh.js </a> <a class="source" href="net.html"> ./source/factory/net.js </a> <a class="source" href="noiseAsset.html"> ./source/factory/noiseAsset.js </a> <a class="source" href="oval.html"> ./source/factory/oval.js </a> <a class="source" href="palette.html"> ./source/factory/palette.js </a> <a class="source" href="particle.html"> ./source/factory/particle.js </a> <a class="source" href="particleForce.html"> ./source/factory/particleForce.js </a> <a class="source" href="particleHistory.html"> ./source/factory/particleHistory.js </a> <a class="source" href="particleSpring.html"> ./source/factory/particleSpring.js </a> <a class="source" href="particleWorld.html"> ./source/factory/particleWorld.js </a> <a class="source" href="pattern.html"> ./source/factory/pattern.js </a> <a class="source" href="phrase.html"> ./source/factory/phrase.js </a> <a class="source" href="picture.html"> ./source/factory/picture.js </a> <a class="source" href="polygon.html"> ./source/factory/polygon.js </a> <a class="source" href="polyline.html"> ./source/factory/polyline.js </a> <a class="source" href="quadratic.html"> ./source/factory/quadratic.js </a> <a class="source" href="quaternion.html"> ./source/factory/quaternion.js </a> <a class="source" href="radialGradient.html"> ./source/factory/radialGradient.js </a> <a class="source" href="rawAsset.html"> ./source/factory/rawAsset.js </a> <a class="source" href="rdAsset.html"> ./source/factory/rdAsset.js </a> <a class="source" href="rectangle.html"> ./source/factory/rectangle.js </a> <a class="source" href="renderAnimation.html"> ./source/factory/renderAnimation.js </a> <a class="source" href="shape.html"> ./source/factory/shape.js </a> <a class="source" href="spiral.html"> ./source/factory/spiral.js </a> <a class="source" href="spriteAsset.html"> ./source/factory/spriteAsset.js </a> <a class="source" href="stack.html"> ./source/factory/stack.js </a> <a class="source" href="star.html"> ./source/factory/star.js </a> <a class="source" href="state.html"> ./source/factory/state.js </a> <a class="source" href="tetragon.html"> ./source/factory/tetragon.js </a> <a class="source" href="ticker.html"> ./source/factory/ticker.js </a> <a class="source" href="tracer.html"> ./source/factory/tracer.js </a> <a class="source" href="tween.html"> ./source/factory/tween.js </a> <a class="source" href="unstackedElement.html"> ./source/factory/unstackedElement.js </a> <a class="source" href="vector.html"> ./source/factory/vector.js </a> <a class="source" href="videoAsset.html"> ./source/factory/videoAsset.js </a> <a class="source" href="wheel.html"> ./source/factory/wheel.js </a> <a class="source" href="../mixin/anchor.html"> ./source/mixin/anchor.js </a> <a class="source" href="../mixin/asset.html"> ./source/mixin/asset.js </a> <a class="source" href="../mixin/assetAdvancedFunctionality.html"> ./source/mixin/assetAdvancedFunctionality.js </a> <a class="source" href="../mixin/assetConsumer.html"> ./source/mixin/assetConsumer.js </a> <a class="source" href="../mixin/base.html"> ./source/mixin/base.js </a> <a class="source" href="../mixin/cascade.html"> ./source/mixin/cascade.js </a> <a class="source" href="../mixin/delta.html"> ./source/mixin/delta.js </a> <a class="source" href="../mixin/displayShape.html"> ./source/mixin/displayShape.js </a> <a class="source" href="../mixin/dom.html"> ./source/mixin/dom.js </a> <a class="source" href="../mixin/entity.html"> ./source/mixin/entity.js </a> <a class="source" href="../mixin/filter.html"> ./source/mixin/filter.js </a> <a class="source" href="../mixin/mimic.html"> ./source/mixin/mimic.js </a> <a class="source" href="../mixin/path.html"> ./source/mixin/path.js </a> <a class="source" href="../mixin/pattern.html"> ./source/mixin/pattern.js </a> <a class="source" href="../mixin/pivot.html"> ./source/mixin/pivot.js </a> <a class="source" href="../mixin/position.html"> ./source/mixin/position.js </a> <a class="source" href="../mixin/shapeBasic.html"> ./source/mixin/shapeBasic.js </a> <a class="source" href="../mixin/shapeCurve.html"> ./source/mixin/shapeCurve.js </a> <a class="source" href="../mixin/shapePathCalculation.html"> ./source/mixin/shapePathCalculation.js </a> <a class="source" href="../mixin/styles.html"> ./source/mixin/styles.js </a> <a class="source" href="../mixin/tween.html"> ./source/mixin/tween.js </a> </div> </div> </li> </ul> <ul class="sections"> <li id="section-1"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-1">&#x00a7;</a> </div> <h1 id="stack-factory">Stack factory</h1> <p>The Scrawl-canvas Stack/Element system is an attempt to supplement DOM elements with Scrawl-canvas entity positioning and dimensioning functionality.</p> <ul> <li>Entitys exist in a Cell environment</li> <li>They can position themselves within that Cell either <strong>absolutely</strong> (px coordinates), or <strong>relatively</strong> (% coordinates, with values relative to the Cell’s dimensions), or <strong>by reference</strong> (using other entity’s coordinates to calculate their own coordinates - <code>pivot</code>, <code>mimic</code>, <code>path</code>)</li> <li>They can also base their dimensions on absolute (px) or relative (%) values</li> <li>They can be <strong>animated</strong> directly (<code>set</code>, <code>deltaSet</code>), or through automation (<code>delta</code> object), or through the Scrawl-canvas <code>tween</code> functionality</li> <li>They can be stored and retrieved (‘packet’ functionality), cloned (‘clone’, based on packets) and killed (‘kill’ functions)</li> </ul> <p><strong>A Stack is a wrapper object around a DOM element</strong>, whose direct children are given Scrawl-canvas Element wrappers:</p> <pre><code><span class="hljs-title class_">Stack</span> ~~&gt; <span class="hljs-title class_">Canvas</span>/<span class="hljs-title class_">Cell</span> <span class="hljs-title class_">Element</span> ~~&gt; <span class="hljs-title class_">Entity</span> (eg <span class="hljs-title class_">Block</span>) </code></pre> <p>During initialization Scrawl-canvas will search the DOM tree and automatically create Stack wrappers for any element which has been given a <code>data-scrawl-stack</code> attribute which resolves to true. Every direct (first level) child inside the stack element will have Element wrappers created for them (except for &lt;canvas&gt; elements). As part of this work, Scrawl-canvas will modify the affected elements’ <code>position</code> CSS style:</p> <ul> <li>Stack elements have <code>relative</code> positioning within the DOM</li> <li>Element elements have <code>absolute</code> positioning within the Stack</li> </ul> <p>The Stack factory is not used directly; the factory is not exported as part of the <strong>scrawl object</strong> during Scrawl-canvas initialization. Instead, wrappers can be created for a DOM-based &lt;div&gt; element using the following scrawl function:</p> <ul> <li><code>scrawl.addStack</code> - generates a new &lt;div&gt; element, creates a wrapper for it, then adds it to the DOM.</li> </ul> <p>Stack wrapper objects use the <strong>base</strong>, <strong>position</strong>, <strong>anchor</strong>, <strong>cascade</strong> and <strong>dom</strong> mixins. Thus Stack wrappers are also <strong>artefact</strong> 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.</p> <p>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.</p> <p>Stack wrappers are used by Scrawl-canvas to invoke the <strong>Display cycle cascade</strong>. As such, they include <code>clear</code>, <code>compile</code>, <code>show</code> and <code>render</code> functions to manage the Display cycle. These functions are asynchronous, returning Promises.</p> <p>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 - <strong>including all Elements and Canvases that it contains</strong>.</p> </div> </li> <li id="section-2"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-2">&#x00a7;</a> </div> <h4 id="demos">Demos:</h4> <ul> <li>All stack demos include Stack wrapper functionality - most of which happens behind the scenes and does not need to be directly coded. </li> <li><a href="../../demo/dom-001.html">DOM-001</a> - Loading the scrawl-canvas library using a script tag in the HTML code</li> <li><a href="../../demo/dom-003.html">DOM-003</a> - Dynamically create and clone Element artefacts; drag and drop elements (including SVG elements) around a Stack</li> <li><a href="../../demo/dom-010.html">DOM-010</a> - Add and remove (kill) Scrawl-canvas Stack elements programmatically</li> </ul> </div> </li> <li id="section-3"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-3">&#x00a7;</a> </div> <h4 id="imports">Imports</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { constructors, group, stack, element, artefact, canvas } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/library.js&#x27;</span>; <span class="hljs-keyword">import</span> { mergeOver, pushUnique, isa_dom, removeItem, xt, addStrings, λ<span class="hljs-variable language_">this</span>, λ<span class="hljs-literal">null</span>, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/utilities.js&#x27;</span>; <span class="hljs-keyword">import</span> { rootElements, setRootElementsSort, domShow } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/document.js&#x27;</span>; <span class="hljs-keyword">import</span> { uiSubscribedElements, currentCorePosition } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/userInteraction.js&#x27;</span>; <span class="hljs-keyword">import</span> { makeGroup } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./group.js&#x27;</span>; <span class="hljs-keyword">import</span> { makeElement } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./element.js&#x27;</span>; <span class="hljs-keyword">import</span> { makeCoordinate } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./coordinate.js&#x27;</span>; <span class="hljs-keyword">import</span> baseMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/base.js&#x27;</span>; <span class="hljs-keyword">import</span> cascadeMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/cascade.js&#x27;</span>; <span class="hljs-keyword">import</span> domMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/dom.js&#x27;</span>; <span class="hljs-keyword">import</span> displayMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/displayShape.js&#x27;</span>;</pre></div></div> </li> <li id="section-4"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-4">&#x00a7;</a> </div> <h4 id="stack-constructor">Stack constructor</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">Stack</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) { <span class="hljs-keyword">let</span> g, el; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">makeName</span>(items.<span class="hljs-property">name</span>); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">register</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">initializePositions</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">initializeCascade</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-property">dimensions</span>[<span class="hljs-number">0</span>] = <span class="hljs-number">300</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dimensions</span>[<span class="hljs-number">1</span>] = <span class="hljs-number">150</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">pathCorners</span> = []; <span class="hljs-variable language_">this</span>.<span class="hljs-property">css</span> = {}; <span class="hljs-variable language_">this</span>.<span class="hljs-property">here</span> = {}; <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span> = { <span class="hljs-attr">x</span>: <span class="hljs-string">&#x27;50%&#x27;</span>, <span class="hljs-attr">y</span>: <span class="hljs-string">&#x27;50%&#x27;</span>, <span class="hljs-attr">z</span>: <span class="hljs-number">0</span> }; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPerspective</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">initializeDomLayout</span>(items); g = <span class="hljs-title function_">makeGroup</span>({ <span class="hljs-attr">name</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">name</span>, <span class="hljs-attr">host</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">name</span> }); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">addGroups</span>(g.<span class="hljs-property">name</span>); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">set</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">initializeDisplayShapeActions</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">initializeAccessibility</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">set</span>(items); el = <span class="hljs-variable language_">this</span>.<span class="hljs-property">domElement</span>; <span class="hljs-keyword">if</span> (el) { <span class="hljs-keyword">const</span> ds = el.<span class="hljs-property">dataset</span>; <span class="hljs-keyword">if</span> (ds.<span class="hljs-property">isResponsive</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">isResponsive</span> = <span class="hljs-literal">true</span>; } <span class="hljs-keyword">if</span> (el.<span class="hljs-title function_">getAttribute</span>(<span class="hljs-string">&#x27;data-scrawl-group&#x27;</span>) === <span class="hljs-string">&#x27;root&#x27;</span>) { <span class="hljs-title function_">pushUnique</span>(rootElements, <span class="hljs-variable language_">this</span>.<span class="hljs-property">name</span>); <span class="hljs-title function_">setRootElementsSort</span>(); } } <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>; };</pre></div></div> </li> <li id="section-5"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-5">&#x00a7;</a> </div> <h4 id="stack-prototype">Stack prototype</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> P = <span class="hljs-title class_">Stack</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span> = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">create</span>(<span class="hljs-title class_">Object</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>); P.<span class="hljs-property">type</span> = <span class="hljs-string">&#x27;Stack&#x27;</span>; P.<span class="hljs-property">lib</span> = <span class="hljs-string">&#x27;stack&#x27;</span>; P.<span class="hljs-property">isArtefact</span> = <span class="hljs-literal">true</span>; P.<span class="hljs-property">isAsset</span> = <span class="hljs-literal">false</span>;</pre></div></div> </li> <li id="section-6"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-6">&#x00a7;</a> </div> <h4 id="mixins">Mixins</h4> <ul> <li><a href="../mixin/base.html">base</a></li> <li><a href="../mixin/cascade.html">cascade</a></li> <li><a href="../mixin/dom.html">dom</a></li> <li><a href="../mixin/displayShape.html">display</a></li> </ul> </div> <div class="content"><div class='highlight'><pre>P = <span class="hljs-title function_">baseMix</span>(P); P = <span class="hljs-title function_">cascadeMix</span>(P); P = <span class="hljs-title function_">domMix</span>(P); P = <span class="hljs-title function_">displayMix</span>(P);</pre></div></div> </li> <li id="section-7"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-7">&#x00a7;</a> </div> <h4 id="stack-attributes">Stack attributes</h4> <ul> <li>Attributes defined in the <a href="../mixin/base.html">base mixin</a>: <strong>name</strong>.</li> <li>Attributes defined in the <a href="../mixin/position.html">position mixin</a>: <strong>group, visibility, order, calculateOrder, stampOrder, start, <em>startX</em>, <em>startY</em>, handle, <em>handleX</em>, <em>handleY</em>, offset, <em>offsetX</em>, <em>offsetY</em>, dimensions, <em>width</em>, <em>height</em>, pivoted, mimicked, lockTo, <em>lockXTo</em>, <em>lockYTo</em>, scale, roll, noUserInteraction, noPositionDependencies, noCanvasEngineUpdates, noFilters, noPathUpdates, purge, bringToFrontOnDrag</strong>.</li> <li>Attributes defined in the <a href="../mixin/delta.html">delta mixin</a>: <strong>delta, noDeltaUpdates</strong>.</li> <li>Attributes defined in the <a href="../mixin/pivot.html">pivot mixin</a>: <strong>pivot, pivotCorner, addPivotHandle, addPivotOffset, addPivotRotation</strong>.</li> <li>Attributes defined in the <a href="../mixin/mimic.html">mimic mixin</a>: <strong>mimic, useMimicDimensions, useMimicScale, useMimicStart, useMimicHandle, useMimicOffset, useMimicRotation, useMimicFlip, addOwnDimensionsToMimic, addOwnScaleToMimic, addOwnStartToMimic, addOwnHandleToMimic, addOwnOffsetToMimic, addOwnRotationToMimic</strong>.</li> <li>Attributes defined in the <a href="../mixin/path.html">path mixin</a>: <strong>path, pathPosition, addPathHandle, addPathOffset, addPathRotation, constantPathSpeed</strong>.</li> <li>Attributes defined in the <a href="../mixin/anchor.html">anchor mixin</a>: <strong>anchor</strong>.</li> <li>Attributes defined in the <a href="../mixin/cascade.html">cascade mixin</a>: <strong>groups</strong>.</li> <li>Attributes defined in the <a href="../mixin/dom.html">dom mixin</a>: <strong>domElement, pitch, yaw, offsetZ, css, classes, position, actionResize, trackHere, domAttributes</strong>.</li> <li>Attributes defined in the <a href="../mixin/displayShape.html">display mixin</a>: <strong>breakToBanner, breakToLandscape, breakToPortrait, breakToSkyscraper, actionBannerShape, actionLandscapeShape, actionRectangleShape, actionPortraitShape, actionSkyscraperShape</strong>.</li> </ul> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> defaultAttributes = {</pre></div></div> </li> <li id="section-8"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-8">&#x00a7;</a> </div> <p><strong>position</strong>, <strong>perspective</strong> - while most of the Stack wrapper’s DOM element’s attributes are handled through CSS, Scrawl-canvas takes control of some positioning-related attributes. Most of these are defined in the <a href="../mixin/dom.html">dom mixin</a> - but the position and perspective attributes are managed in this module</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">position</span>: <span class="hljs-string">&#x27;relative&#x27;</span>, <span class="hljs-attr">perspective</span>: <span class="hljs-literal">null</span>,</pre></div></div> </li> <li id="section-9"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-9">&#x00a7;</a> </div> <p><strong>trackHere</strong> </p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">trackHere</span>: <span class="hljs-string">&#x27;subscribe&#x27;</span>,</pre></div></div> </li> <li id="section-10"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-10">&#x00a7;</a> </div> <p>TODO: This is all about a mad idea we may have for making stacks ‘responsive’ to viewport changes. It needs a lot more thinking through. Search on ‘isResponsive’ to find the relevant function below</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">isResponsive</span>: <span class="hljs-literal">false</span>, <span class="hljs-attr">containElementsInHeight</span>: <span class="hljs-literal">false</span>, }; P.<span class="hljs-property">defs</span> = <span class="hljs-title function_">mergeOver</span>(P.<span class="hljs-property">defs</span>, defaultAttributes);</pre></div></div> </li> <li id="section-11"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-11">&#x00a7;</a> </div> <h4 id="packetclone-management">Packet/Clone management</h4> <p>This functionality is disabled for Stack objects</p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">stringifyFunction</span> = λ<span class="hljs-literal">null</span>; P.<span class="hljs-property">processPacketOut</span> = λ<span class="hljs-literal">null</span>; P.<span class="hljs-property">finalizePacketOut</span> = λ<span class="hljs-literal">null</span>; P.<span class="hljs-property">saveAsPacket</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">return</span> <span class="hljs-string">`[<span class="hljs-subst">${<span class="hljs-variable language_">this</span>.name}</span>, <span class="hljs-subst">${<span class="hljs-variable language_">this</span>.type}</span>, <span class="hljs-subst">${<span class="hljs-variable language_">this</span>.lib}</span>, {}]`</span> }; P.<span class="hljs-property">clone</span> = λ<span class="hljs-variable language_">this</span>;</pre></div></div> </li> <li id="section-12"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-12">&#x00a7;</a> </div> <h4 id="kill-functionality">Kill functionality</h4> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">factoryKill</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">let</span> myname = <span class="hljs-variable language_">this</span>.<span class="hljs-property">name</span>;</pre></div></div> </li> <li id="section-13"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-13">&#x00a7;</a> </div> <p>rootElements and uiSubscribedElements arrays</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-title function_">removeItem</span>(rootElements, myname); <span class="hljs-title function_">setRootElementsSort</span>(); <span class="hljs-title function_">removeItem</span>(uiSubscribedElements, myname);</pre></div></div> </li> <li id="section-14"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-14">&#x00a7;</a> </div> <p>Groups</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (group[myname]) group[myname].<span class="hljs-title function_">kill</span>(); <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">entries</span>(artefact).<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">[name, art]</span>) =&gt;</span> { <span class="hljs-keyword">if</span> (art.<span class="hljs-property">host</span> === myname) art.<span class="hljs-title function_">kill</span>(); });</pre></div></div> </li> <li id="section-15"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-15">&#x00a7;</a> </div> <p>DOM removals</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-variable language_">this</span>.<span class="hljs-property">domElement</span>.<span class="hljs-title function_">remove</span>(); }</pre></div></div> </li> <li id="section-16"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-16">&#x00a7;</a> </div> <h4 id="get-set-deltaset">Get, Set, deltaSet</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> G = P.<span class="hljs-property">getters</span>, S = P.<span class="hljs-property">setters</span>, D = P.<span class="hljs-property">deltaSetters</span>;</pre></div></div> </li> <li id="section-17"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-17">&#x00a7;</a> </div> <p>Similar to start, handle, dimensions, etc Scrawl-canvas supplies some pseudo-attributes to help set and manage the Stack wrapper’s <code>perspective</code> object:</p> <ul> <li><code>perspectiveX</code></li> <li><code>perspectiveY</code></li> <li><code>perspectiveZ</code></li> </ul> </div> <div class="content"><div class='highlight'><pre>G.<span class="hljs-property">perspectiveX</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">x</span>; }; G.<span class="hljs-property">perspectiveY</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">y</span>; }; G.<span class="hljs-property">perspectiveZ</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">z</span>; }; S.<span class="hljs-property">perspectiveX</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">x</span> = item; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPerspective</span> = <span class="hljs-literal">true</span>; }; S.<span class="hljs-property">perspectiveY</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">y</span> = item; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPerspective</span> = <span class="hljs-literal">true</span>; }; S.<span class="hljs-property">perspectiveZ</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">z</span> = item; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPerspective</span> = <span class="hljs-literal">true</span>; }; S.<span class="hljs-property">perspective</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item = Ωempty</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">x</span> = (<span class="hljs-title function_">xt</span>(item.<span class="hljs-property">x</span>)) ? item.<span class="hljs-property">x</span> : <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">x</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">y</span> = (<span class="hljs-title function_">xt</span>(item.<span class="hljs-property">y</span>)) ? item.<span class="hljs-property">y</span> : <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">y</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">z</span> = (<span class="hljs-title function_">xt</span>(item.<span class="hljs-property">z</span>)) ? item.<span class="hljs-property">z</span> : <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">z</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPerspective</span> = <span class="hljs-literal">true</span>; }; D.<span class="hljs-property">perspectiveX</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">x</span> = <span class="hljs-title function_">addStrings</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">x</span>, item); <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPerspective</span> = <span class="hljs-literal">true</span>; }; D.<span class="hljs-property">perspectiveY</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">y</span> = <span class="hljs-title function_">addStrings</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">perspective</span>.<span class="hljs-property">y</span>, item); <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPerspective</span> = <span class="hljs-literal">true</span>; };</pre></div></div> </li> <li id="section-18"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-18">&#x00a7;</a> </div> <h4 id="prototype-functions">Prototype functions</h4> </div> </li> <li id="section-19"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-19">&#x00a7;</a> </div> <p><code>updateArtefacts</code> - internal function. Iterate through all Element and Canvas wrappers associated with the Stack wrapper’s Group object and set a range of dirty flags on them, for future processing by each as appropriate.</p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">updateArtefacts</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">groupBuckets</span>.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">grp</span> =&gt;</span> { grp.<span class="hljs-property">artefactCalculateBuckets</span>.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">art</span> =&gt;</span> { <span class="hljs-keyword">if</span> (items.<span class="hljs-property">dirtyScale</span>) art.<span class="hljs-property">dirtyScale</span> = <span class="hljs-literal">true</span>; <span class="hljs-keyword">if</span> (items.<span class="hljs-property">dirtyDimensions</span>) art.<span class="hljs-property">dirtyDimensions</span> = <span class="hljs-literal">true</span>; <span class="hljs-keyword">if</span> (items.<span class="hljs-property">dirtyLock</span>) art.<span class="hljs-property">dirtyLock</span> = <span class="hljs-literal">true</span>; <span class="hljs-keyword">if</span> (items.<span class="hljs-property">dirtyStart</span>) art.<span class="hljs-property">dirtyStart</span> = <span class="hljs-literal">true</span>; <span class="hljs-keyword">if</span> (items.<span class="hljs-property">dirtyOffset</span>) art.<span class="hljs-property">dirtyOffset</span> = <span class="hljs-literal">true</span>; <span class="hljs-keyword">if</span> (items.<span class="hljs-property">dirtyHandle</span>) art.<span class="hljs-property">dirtyHandle</span> = <span class="hljs-literal">true</span>; <span class="hljs-keyword">if</span> (items.<span class="hljs-property">dirtyRotation</span>) art.<span class="hljs-property">dirtyRotation</span> = <span class="hljs-literal">true</span>; <span class="hljs-keyword">if</span> (items.<span class="hljs-property">dirtyPathObject</span>) art.<span class="hljs-property">dirtyPathObject</span> = <span class="hljs-literal">true</span>; }) }); };</pre></div></div> </li> <li id="section-20"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-20">&#x00a7;</a> </div> <p><code>cleanDimensionsAdditionalActions</code> - overwrites mixin/position function. Promulgates Stack dimension changes through to all Element and Canvas wrappers associated with the Stack wrapper’s Group object.</p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">cleanDimensionsAdditionalActions</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">groupBuckets</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateArtefacts</span>({ <span class="hljs-attr">dirtyDimensions</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">dirtyPath</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">dirtyStart</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">dirtyHandle</span>: <span class="hljs-literal">true</span>, }); } <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyDomDimensions</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPath</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyStart</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyHandle</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyDisplayShape</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyDisplayArea</span> = <span class="hljs-literal">true</span>; };</pre></div></div>