UNPKG

scrawl-canvas

Version:
1,077 lines (709 loc) 117 kB
<!DOCTYPE html> <html> <head> <title>Entity mixin</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="../factory/action.html"> ./source/factory/action.js </a> <a class="source" href="../factory/anchor.html"> ./source/factory/anchor.js </a> <a class="source" href="../factory/animation.html"> ./source/factory/animation.js </a> <a class="source" href="../factory/bezier.html"> ./source/factory/bezier.js </a> <a class="source" href="../factory/block.html"> ./source/factory/block.js </a> <a class="source" href="../factory/canvas.html"> ./source/factory/canvas.js </a> <a class="source" href="../factory/cell.html"> ./source/factory/cell.js </a> <a class="source" href="../factory/cog.html"> ./source/factory/cog.js </a> <a class="source" href="../factory/color.html"> ./source/factory/color.js </a> <a class="source" href="../factory/conicGradient.html"> ./source/factory/conicGradient.js </a> <a class="source" href="../factory/coordinate.html"> ./source/factory/coordinate.js </a> <a class="source" href="../factory/crescent.html"> ./source/factory/crescent.js </a> <a class="source" href="../factory/element.html"> ./source/factory/element.js </a> <a class="source" href="../factory/emitter.html"> ./source/factory/emitter.js </a> <a class="source" href="../factory/filter.html"> ./source/factory/filter.js </a> <a class="source" href="../factory/filterEngine-bluenoiseData.html"> ./source/factory/filterEngine-bluenoiseData.js </a> <a class="source" href="../factory/filterEngine.html"> ./source/factory/filterEngine.js </a> <a class="source" href="../factory/fontAttributes.html"> ./source/factory/fontAttributes.js </a> <a class="source" href="../factory/gradient.html"> ./source/factory/gradient.js </a> <a class="source" href="../factory/grid.html"> ./source/factory/grid.js </a> <a class="source" href="../factory/group.html"> ./source/factory/group.js </a> <a class="source" href="../factory/imageAsset.html"> ./source/factory/imageAsset.js </a> <a class="source" href="../factory/line.html"> ./source/factory/line.js </a> <a class="source" href="../factory/lineSpiral.html"> ./source/factory/lineSpiral.js </a> <a class="source" href="../factory/loom.html"> ./source/factory/loom.js </a> <a class="source" href="../factory/mesh.html"> ./source/factory/mesh.js </a> <a class="source" href="../factory/net.html"> ./source/factory/net.js </a> <a class="source" href="../factory/noiseAsset.html"> ./source/factory/noiseAsset.js </a> <a class="source" href="../factory/oval.html"> ./source/factory/oval.js </a> <a class="source" href="../factory/palette.html"> ./source/factory/palette.js </a> <a class="source" href="../factory/particle.html"> ./source/factory/particle.js </a> <a class="source" href="../factory/particleForce.html"> ./source/factory/particleForce.js </a> <a class="source" href="../factory/particleHistory.html"> ./source/factory/particleHistory.js </a> <a class="source" href="../factory/particleSpring.html"> ./source/factory/particleSpring.js </a> <a class="source" href="../factory/particleWorld.html"> ./source/factory/particleWorld.js </a> <a class="source" href="../factory/pattern.html"> ./source/factory/pattern.js </a> <a class="source" href="../factory/phrase.html"> ./source/factory/phrase.js </a> <a class="source" href="../factory/picture.html"> ./source/factory/picture.js </a> <a class="source" href="../factory/polygon.html"> ./source/factory/polygon.js </a> <a class="source" href="../factory/polyline.html"> ./source/factory/polyline.js </a> <a class="source" href="../factory/quadratic.html"> ./source/factory/quadratic.js </a> <a class="source" href="../factory/quaternion.html"> ./source/factory/quaternion.js </a> <a class="source" href="../factory/radialGradient.html"> ./source/factory/radialGradient.js </a> <a class="source" href="../factory/rawAsset.html"> ./source/factory/rawAsset.js </a> <a class="source" href="../factory/rdAsset.html"> ./source/factory/rdAsset.js </a> <a class="source" href="../factory/rectangle.html"> ./source/factory/rectangle.js </a> <a class="source" href="../factory/renderAnimation.html"> ./source/factory/renderAnimation.js </a> <a class="source" href="../factory/shape.html"> ./source/factory/shape.js </a> <a class="source" href="../factory/spiral.html"> ./source/factory/spiral.js </a> <a class="source" href="../factory/spriteAsset.html"> ./source/factory/spriteAsset.js </a> <a class="source" href="../factory/stack.html"> ./source/factory/stack.js </a> <a class="source" href="../factory/star.html"> ./source/factory/star.js </a> <a class="source" href="../factory/state.html"> ./source/factory/state.js </a> <a class="source" href="../factory/tetragon.html"> ./source/factory/tetragon.js </a> <a class="source" href="../factory/ticker.html"> ./source/factory/ticker.js </a> <a class="source" href="../factory/tracer.html"> ./source/factory/tracer.js </a> <a class="source" href="../factory/tween.html"> ./source/factory/tween.js </a> <a class="source" href="../factory/unstackedElement.html"> ./source/factory/unstackedElement.js </a> <a class="source" href="../factory/vector.html"> ./source/factory/vector.js </a> <a class="source" href="../factory/videoAsset.html"> ./source/factory/videoAsset.js </a> <a class="source" href="../factory/wheel.html"> ./source/factory/wheel.js </a> <a class="source" href="anchor.html"> ./source/mixin/anchor.js </a> <a class="source" href="asset.html"> ./source/mixin/asset.js </a> <a class="source" href="assetAdvancedFunctionality.html"> ./source/mixin/assetAdvancedFunctionality.js </a> <a class="source" href="assetConsumer.html"> ./source/mixin/assetConsumer.js </a> <a class="source" href="base.html"> ./source/mixin/base.js </a> <a class="source" href="cascade.html"> ./source/mixin/cascade.js </a> <a class="source" href="delta.html"> ./source/mixin/delta.js </a> <a class="source" href="displayShape.html"> ./source/mixin/displayShape.js </a> <a class="source" href="dom.html"> ./source/mixin/dom.js </a> <a class="source" href="entity.html"> ./source/mixin/entity.js </a> <a class="source" href="filter.html"> ./source/mixin/filter.js </a> <a class="source" href="mimic.html"> ./source/mixin/mimic.js </a> <a class="source" href="path.html"> ./source/mixin/path.js </a> <a class="source" href="pattern.html"> ./source/mixin/pattern.js </a> <a class="source" href="pivot.html"> ./source/mixin/pivot.js </a> <a class="source" href="position.html"> ./source/mixin/position.js </a> <a class="source" href="shapeBasic.html"> ./source/mixin/shapeBasic.js </a> <a class="source" href="shapeCurve.html"> ./source/mixin/shapeCurve.js </a> <a class="source" href="shapePathCalculation.html"> ./source/mixin/shapePathCalculation.js </a> <a class="source" href="styles.html"> ./source/mixin/styles.js </a> <a class="source" href="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="entity-mixin">Entity mixin</h1> <p>This mixin builds on the base and position mixins to give Canvas entity objects (Scrawl-canvas <a href="../factory/block.html">Block</a>, <a href="../factory/grid.html">Grid</a>, <a href="../factory/loom.html">Loom</a>, <a href="../factory/phrase.html">Phrase</a>, <a href="../factory/picture.html">Picture</a>, <a href="../factory/shape.html">Shape</a>, <a href="../factory/wheel.html">Wheel</a>) the ability to act as <strong>artefacts</strong>.</p> <p>Entitys differ from non-entity artefacts in that they are restricted to Cell wrappers (though no harm should come if they are included in Stack-related Groups).</p> <ul> <li>The entity object represents a set of instructions for rendering graphical lines and shapes onto a &lt;canvas&gt; CanvasRenderingContext2D engine, using the Canvas API to do this</li> <li>The engine requirements for the render - <code>fillStyle</code>, <code>font</code>, <code>globalAlpha</code>, <code>globalCompositeOperation</code>, <code>lineCap</code>, <code>lineDash</code>, <code>lineDashOffset</code>, <code>lineJoin</code>, <code>lineWidth</code>, <code>miterLimit</code>, <code>shadowBlur</code>, <code>shadowColor</code>, <code>shadowOffsetX</code>, <code>shadowOffsetY</code>, <code>strokeStyle</code>, <code>textAlign</code>, <code>textBaseline</code> - are kept in a separate <a href="../factory.state.html">State object</a>. Note that these attributes are initialized/updated directly on the entity object</li> <li>Entitys can act as hotspots within a &lt;canvas&gt; display; we can create hover and click effects for them</li> </ul> <p>Entitys are, nevertheless, full artefact objects which can interact with other artefacts and the mouse/touch cursor in all the normal ways: positioning (<code>pivot</code> and <code>path</code>) and dimensioning (<code>mimic</code>) functionality; collision detection (including <strong>drag-and-drop</strong>); etc</p> </div> </li> <li id="section-2"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-2">&#x00a7;</a> </div> <h4 id="imports">Imports</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { λ<span class="hljs-literal">null</span>, mergeOver, pushUnique, xt, addStrings, isa_obj, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/utilities.js&#x27;</span>; <span class="hljs-keyword">import</span> { currentGroup, scrawlCanvasHold } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/document.js&#x27;</span>; <span class="hljs-keyword">import</span> { asset } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/library.js&#x27;</span>; <span class="hljs-keyword">import</span> { makeState, stateKeys } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../factory/state.js&#x27;</span>; <span class="hljs-keyword">import</span> { requestCell, releaseCell } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../factory/cell.js&#x27;</span>; <span class="hljs-keyword">import</span> { filterEngine } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../factory/filterEngine.js&#x27;</span>; <span class="hljs-keyword">import</span> { importDomImage } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../factory/imageAsset.js&#x27;</span>; <span class="hljs-keyword">import</span> positionMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/position.js&#x27;</span>; <span class="hljs-keyword">import</span> deltaMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/delta.js&#x27;</span>; <span class="hljs-keyword">import</span> pivotMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/pivot.js&#x27;</span>; <span class="hljs-keyword">import</span> mimicMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/mimic.js&#x27;</span>; <span class="hljs-keyword">import</span> pathMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/path.js&#x27;</span>; <span class="hljs-keyword">import</span> anchorMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/anchor.js&#x27;</span>; <span class="hljs-keyword">import</span> filterMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/filter.js&#x27;</span>;</pre></div></div> </li> <li id="section-3"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-3">&#x00a7;</a> </div> <h4 id="export-function">Export function</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">function</span> (<span class="hljs-params">P = Ωempty</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="mixins">Mixins</h4> <ul> <li><a href="../mixin/position.html">position</a></li> <li><a href="../mixin/delta.html">delta</a></li> <li><a href="../mixin/pivot.html">pivot</a></li> <li><a href="../mixin/mimic.html">mimic</a></li> <li><a href="../mixin/path.html">path</a></li> <li><a href="../mixin/anchor.html">anchor</a></li> <li><a href="../mixin/filter.html">filter</a></li> </ul> </div> <div class="content"><div class='highlight'><pre> P = <span class="hljs-title function_">positionMix</span>(P); P = <span class="hljs-title function_">deltaMix</span>(P); P = <span class="hljs-title function_">pivotMix</span>(P); P = <span class="hljs-title function_">mimicMix</span>(P); P = <span class="hljs-title function_">pathMix</span>(P); P = <span class="hljs-title function_">anchorMix</span>(P); P = <span class="hljs-title function_">filterMix</span>(P);</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="shared-attributes">Shared attributes</h4> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> defaultAttributes = {</pre></div></div> </li> <li id="section-6"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-6">&#x00a7;</a> </div> <p><strong>method</strong> - String value which tells the entity <em>how</em> it will display itself on the canvas. Available options are:</p> <ul> <li><code>draw</code> - stroke the entity outline with the entity’s <code>strokeStyle</code> color, gradient or pattern - including shadow</li> <li><code>fill</code> - fill the entity with the entity’s <code>fillStyle</code> color, gradient or pattern - including shadow</li> <li><code>drawAndFill</code> - stroke the entity’s outline, remove shadow, then fill it</li> <li><code>fillAndDraw</code> - fill the entity’s outline, remove shadow, then stroke it</li> <li><code>drawThenFill</code> - stroke the entity’s outline, then fill it (shadow applied twice)</li> <li><code>fillThenDraw</code> - fill the entity’s outline, then stroke it (shadow applied twice)</li> <li><code>clip</code> - use shape to restrict future drawing area (best used in a separate group)</li> <li><code>clear</code> - remove everything that would have been covered if the entity had performed fill (including shadow)</li> <li><code>none</code> - perform all the calculations required, but don’t perform the final stamping</li> </ul> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;fill&#x27;</span>,</pre></div></div> </li> <li id="section-7"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-7">&#x00a7;</a> </div> <p><strong>pathObject</strong> - Scrawl-canvas holds details of every type of entity’s outline in a <code>Path2D</code> object - used both for draw/fill operations, and for collision detection work</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">pathObject</span>: <span class="hljs-literal">null</span>,</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>winding</strong> - String with value <code>evenodd</code> or <code>nonzero</code> (default)</p> <ul> <li>Canvas fill (flood) drawing operations can take into account an entity’s winding choice. Two are available: the <a href="https://en.wikipedia.org/wiki/Nonzero-rule">non-zero rule</a>; and the <a href="https://en.wikipedia.org/wiki/Even%E2%80%93odd_rule">even-odd rule</a></li> </ul> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">winding</span>: <span class="hljs-string">&#x27;nonzero&#x27;</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>flipReverse</strong>, <strong>flipUpend</strong> - Boolean flags which determine the orientation of the entity when it stamps itself on the display. </p> <ul> <li>a <code>reversed</code> entity is effectively flipped 180&deg; around a vertical line passing through that entity’s rotation-reflection (start) point - a face looking to the right will now look to the left</li> <li>an <code>upended</code> entity is effectively flipped 180&deg; around a horizontal line passing through that entity’s rotation-reflection (start) point - a normal face will now appear upside-down</li> </ul> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">flipReverse</span>: <span class="hljs-literal">false</span>, <span class="hljs-attr">flipUpend</span>: <span class="hljs-literal">false</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><strong>scaleOutline</strong> - Boolean flag. When set, the entity will increase its <code>lineWidth</code> proportionat to the entity’s <code>scale</code> value - an entity of scale = 2 will display lines twice the thickness of the same entity at scale = 1</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">scaleOutline</span>: <span class="hljs-literal">true</span>,</pre></div></div> </li> <li id="section-11"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-11">&#x00a7;</a> </div> <p><strong>lockFillStyleToEntity</strong>, <strong>lockStrokeStyleToEntity</strong> - Boolean flags. </p> <ul> <li>When set, these flags instruct any gradient-type style (Scrawl-canvas Gradient, RadialGradient) to map their <code>start</code> and <code>end</code> coordinates to the entity’s dimensions</li> <li>Default action is for gradient-type styles to map their coordinates to the host Cell’s dimensions</li> </ul> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">lockFillStyleToEntity</span>: <span class="hljs-literal">false</span>, <span class="hljs-attr">lockStrokeStyleToEntity</span>: <span class="hljs-literal">false</span>,</pre></div></div> </li> <li id="section-12"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-12">&#x00a7;</a> </div> <h5 id="event-listener-functions">Event listener functions</h5> <p>Entity objects have the ability to act as ‘hotspots’ within a canvas display, reacting to mouse/pointer movements over the canvas. Four mouse-like events are supported:</p> <ul> <li><code>enter</code> - triggers when the cursor passes over the entity’s outline into its fillable area</li> <li><code>down</code> - triggers when a user presses their (left) mouse key while inside the entity’s fillable area</li> <li><code>up</code> - triggers when a user releases their (left) mouse key while inside the entity’s fillable area - this can also be used for capturing mouse click and touch tap actions</li> <li><code>leave</code> - triggers when the cursor passes over the entity’s outline away from its fillable area</li> </ul> <p>The events are regular functions. </p> <ul> <li><code>this</code> refers to the entity object, giving the functions access to any attribute and method set on it. </li> <li>They can also use variables defined elsewhere in the script code (though these will need to be rehydrated if the entity is packet stored and resurrected - see Demo <a href="../../demo/canvas-009.html">Canvas-009</a> tests for an example of doing this)</li> </ul> <p>Scrawl-canvas will not automatically trigger these functions: </p> <ul> <li>They can be triggered as part of an Animation object’s function checking for hits on a Group of entitys</li> <li>Similar checks can be included in a RenderAnimation hook function</li> <li>Alternatively we can set up an event listener on the DOM &lt;canvas&gt; element, which invokes a call to cascade a mouse/touch <code>move</code> event down to its associated entitys - in this case the entitys will check the event themselves and trigger the appropriate function</li> </ul> <p>The functions defined in these attributes will be included in entity <code>packet</code> functionality, and can be safely cloned</p> </div> </li> <li id="section-13"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-13">&#x00a7;</a> </div> <p><strong>onEnter</strong> - define tasks to be performed for <code>enter</code> events</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">onEnter</span>: <span class="hljs-literal">null</span>,</pre></div></div> </li> <li id="section-14"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-14">&#x00a7;</a> </div> <p><strong>onLeave</strong> - define tasks to be performed for <code>leave</code> events</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">onLeave</span>: <span class="hljs-literal">null</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><strong>onDown</strong> - define tasks to be performed for <code>down</code> events</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">onDown</span>: <span class="hljs-literal">null</span>,</pre></div></div> </li> <li id="section-16"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-16">&#x00a7;</a> </div> <p><strong>onUp</strong> - define tasks to be performed for <code>up</code> events</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">onUp</span>: <span class="hljs-literal">null</span>,</pre></div></div> </li> <li id="section-17"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-17">&#x00a7;</a> </div> <h5 id="state-object-attributes">State object attributes</h5> <p>We can treat the following attributes as if they are entity object attributes, though in fact they are stored and managed by <strong>State objects</strong></p> <p><strong>fillStyle</strong> and <strong>strokeStyle</strong> - color, gradient or pattern used to outline or fill a entity. Can be:</p> <ul> <li>CSS format color String - <code>#fff</code>, <code>#ffffff</code>, <code>rgb(255,255,255)</code>, <code>rgba(255,255,255,1)</code>, <code>white</code>, etc</li> <li>COLORNAME String</li> <li>GRADIENTNAME String</li> <li>RADIALGRADIENTNAME String</li> <li>PATTERNNAME String</li> </ul> <p><strong>globalAlpha</strong> - entity transparency - a value between 0 and 1, where 0 is completely transparent and 1 is completely opaque</p> <p><strong>globalCompositeOperation</strong> - compositing method for applying the entity to an existing Cell (&lt;canvas&gt;) display. Permitted values include</p> <ul> <li>‘source-over’</li> <li>‘source-atop’</li> <li>‘source-in’</li> <li>‘source-out’</li> <li>‘destination-over’</li> <li>‘destination-atop’</li> <li>‘destination-in’</li> <li>‘destination-out’</li> <li>‘lighter’</li> <li>‘darker’</li> <li>‘copy’</li> <li>‘xor’</li> <li>any other permitted value - be aware that different browsers may render these operations in different ways, and some options are not supported by all browsers.</li> </ul> <p><strong>lineWidth</strong> - Number (in pixels)</p> <p><strong>lineCap</strong> - how the ends of lines will display. Permitted values include:</p> <ul> <li>‘butt’</li> <li>‘round’</li> <li>‘square’</li> </ul> <p><strong>lineJoin</strong> - how line joints will display. Permitted values include:</p> <ul> <li>‘miter’</li> <li>‘round’</li> <li>‘bevel’</li> </ul> <p><strong>lineDash</strong> - an array of integer Numbers representing line and gap values (in pixels), for example [5,2,2,2] for a long-short dash pattern</p> <p><strong>lineDashOffset</strong> - distance along the entity’s outline at which to start the line dash. Changing this value can be used to create a ‘marching ants effect</p> <p><strong>miterLimit</strong> - affecting the ‘pointiness’ of the line join where two lines join at an acute angle</p> <p><strong>shadowOffsetX</strong>, <strong>shadowOffsetY</strong> - horizontal and vertical offsets for a entity’s shadow, in Number pixels</p> <p><strong>shadowBlur</strong> - the blur width for a entity’s shadow, in Number pixels</p> <p><strong>shadowColor</strong> - the color used for an entity’s shadow effect. Can be:</p> <ul> <li>CSS format color String - <code>#fff</code>, <code>#ffffff</code>, <code>rgb(255,255,255)</code>, <code>rgba(255,255,255,1)</code>, <code>white</code>, etc</li> <li>COLORNAME String</li> </ul> <p><strong>font</strong>, <strong>textAlign</strong>, <strong>textBaseline</strong> - the Canvas API standards for using fonts on a canvas are near-useless, and often lead to a sub-par display of text. The Scrawl-canvas Phrase entity uses the following attributes internally, but has its own set of attributes for defining the font styling used by its text.</p> <p><strong>filter</strong> - the Canvas 2D engine supports the <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/filter">filter attribute</a> on an experimental basis, thus it is not guaranteed to work in all browsers and devices. The filter attribute takes a String value (default: ‘none’) defining one or more filter functions to be applied to the entity as it is stamped on the canvas.</p> <ul> <li>Be aware that entitys can also take a <code>filters</code> Array - this represents an array of Scrawl-canvas filters to be applied to the entity (or group or Cell). The two filter systems are completely separate - combine their effects at your own risk!</li> </ul> </div> <div class="content"><div class='highlight'><pre> }; 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-18"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-18">&#x00a7;</a> </div> <h4 id="packet-management">Packet management</h4> </div> <div class="content"><div class='highlight'><pre> P.<span class="hljs-property">packetExclusions</span> = <span class="hljs-title function_">pushUnique</span>(P.<span class="hljs-property">packetExclusions</span>, [<span class="hljs-string">&#x27;state&#x27;</span>]); P.<span class="hljs-property">packetFunctions</span> = <span class="hljs-title function_">pushUnique</span>(P.<span class="hljs-property">packetFunctions</span>, [<span class="hljs-string">&#x27;onEnter&#x27;</span>, <span class="hljs-string">&#x27;onLeave&#x27;</span>, <span class="hljs-string">&#x27;onDown&#x27;</span>, <span class="hljs-string">&#x27;onUp&#x27;</span>]); P.<span class="hljs-property">processEntityPacketOut</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">key, value, includes</span>) { <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">processFactoryPacketOut</span>(key, value, includes); }; P.<span class="hljs-property">processFactoryPacketOut</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">key, value, includes</span>) { <span class="hljs-keyword">let</span> result = <span class="hljs-literal">true</span>; <span class="hljs-keyword">if</span>(includes.<span class="hljs-title function_">indexOf</span>(key) &lt; <span class="hljs-number">0</span> &amp;&amp; value === <span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>[key]) result = <span class="hljs-literal">false</span>; <span class="hljs-keyword">return</span> result; }; P.<span class="hljs-property">finalizePacketOut</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">copy, items</span>) { <span class="hljs-keyword">let</span> stateCopy = <span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">parse</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">state</span>.<span class="hljs-title function_">saveAsPacket</span>(items))[<span class="hljs-number">3</span>]; copy = <span class="hljs-title function_">mergeOver</span>(copy, stateCopy); copy = <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">handlePacketAnchor</span>(copy, items); <span class="hljs-keyword">return</span> copy; };</pre></div></div> </li> <li id="section-19"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-19">&#x00a7;</a> </div> <h4 id="clone-management">Clone management</h4> </div> <div class="content"><div class='highlight'><pre> P.<span class="hljs-property">postCloneAction</span> = <span class="hljs-keyword">function</span>(<span class="hljs-params">clone, items</span>) { <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">onEnter</span>) clone.<span class="hljs-property">onEnter</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">onEnter</span>; <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">onLeave</span>) clone.<span class="hljs-property">onLeave</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">onLeave</span>; <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">onDown</span>) clone.<span class="hljs-property">onDown</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">onDown</span>; <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">onUp</span>) clone.<span class="hljs-property">onUp</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">onUp</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>Shared state</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (items.<span class="hljs-property">sharedState</span>) clone.<span class="hljs-property">state</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">state</span>;</pre></div></div> </li> <li id="section-21"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-21">&#x00a7;</a> </div> <p>Cloned anchors</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (items.<span class="hljs-property">anchor</span>) { items.<span class="hljs-property">anchor</span>.<span class="hljs-property">host</span> = clone; <span class="hljs-keyword">if</span> (!<span class="hljs-title function_">xt</span>(items.<span class="hljs-property">anchor</span>.<span class="hljs-property">focusAction</span>)) items.<span class="hljs-property">anchor</span>.<span class="hljs-property">focusAction</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">anchor</span>.<span class="hljs-property">focusAction</span>; <span class="hljs-keyword">if</span> (!<span class="hljs-title function_">xt</span>(items.<span class="hljs-property">anchor</span>.<span class="hljs-property">blurAction</span>)) items.<span class="hljs-property">anchor</span>.<span class="hljs-property">blurAction</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">anchor</span>.<span class="hljs-property">blurAction</span>; clone.<span class="hljs-title function_">buildAnchor</span>(items.<span class="hljs-property">anchor</span>); <span class="hljs-keyword">if</span> (!items.<span class="hljs-property">anchor</span>.<span class="hljs-property">clickAction</span>) clone.<span class="hljs-property">anchor</span>.<span class="hljs-property">clickAction</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">anchor</span>.<span class="hljs-property">clickAction</span>; } <span class="hljs-keyword">return</span> clone; };</pre></div></div> </li> <li id="section-22"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-22">&#x00a7;</a> </div> <h4 id="kill-management">Kill management</h4> <p>No additional kill functionality defined here</p> </div> </li> <li id="section-23"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-23">&#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-24"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-24">&#x00a7;</a> </div> <p><strong>group</strong> - returns the entity’s latest Group’s String name, not the Group object itself</p> </div> <div class="content"><div class='highlight'><pre> G.<span class="hljs-property">group</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">group</span>) ? <span class="hljs-variable language_">this</span>.<span class="hljs-property">group</span>.<span class="hljs-property">name</span> : <span class="hljs-string">&#x27;&#x27;</span>; };</pre></div></div> </li> <li id="section-25"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-25">&#x00a7;</a> </div> <p><strong>lockStylesToEntity</strong> - a pseudo-attribute which will set the <code>lockFillStyleToEntity</code> and <code>lockStrokeStyleToEntity</code> flags to the same Boolean value</p> </div> <div class="content"><div class='highlight'><pre> S.<span class="hljs-property">lockStylesToEntity</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">lockFillStyleToEntity</span> = item; <span class="hljs-variable language_">this</span>.<span class="hljs-property">lockStrokeStyleToEntity</span> = item; };</pre></div></div> </li> <li id="section-26"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-26">&#x00a7;</a> </div> <p>Entity <code>get</code>, <code>set</code> and <code>deltaSet</code> functions need to take into account the entity State object, whose attributes can be retrieved/amended directly on the entity object</p> </div> <div class="content"><div class='highlight'><pre> P.<span class="hljs-property">get</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">const</span> getter = <span class="hljs-variable language_">this</span>.<span class="hljs-property">getters</span>[item]; <span class="hljs-keyword">if</span> (getter) <span class="hljs-keyword">return</span> getter.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>); <span class="hljs-keyword">else</span> { <span class="hljs-keyword">let</span> def = <span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>[item], state = <span class="hljs-variable language_">this</span>.<span class="hljs-property">state</span>; <span class="hljs-keyword">let</span> val; <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> def != <span class="hljs-string">&#x27;undefined&#x27;</span>) { val = <span class="hljs-variable language_">this</span>[item]; <span class="hljs-keyword">return</span> (<span class="hljs-keyword">typeof</span> val != <span class="hljs-string">&#x27;undefined&#x27;</span>) ? val : def; } def = state.<span class="hljs-property">defs</span>[item]; <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> def != <span class="hljs-string">&#x27;undefined&#x27;</span>) { val = state[item]; <span class="hljs-keyword