scrawl-canvas
Version:
Version 8.9.4 - 19 Nov 2022
1,171 lines (753 loc) • 62.4 kB
HTML
<!DOCTYPE html>
<html>
<head>
<title>State 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 …</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">§</a>
</div>
<h1 id="state-factory">State factory</h1>
<p>Scrawl-canvas uses State objects to keep track of Cell object <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D">CanvasRenderingContext2D</a> rendering engine state. </p>
<p>Every entity object also has a State object. Before an entity is ‘stamped’ onto a Cell <canvas> their State objects are compared, to draw up a list of changes required by the entity to bring the engine’s state into alignment.</p>
<ul>
<li>State objects are not stored in the Scrawl-canvas library; they can only be accessed through their Cell or entity object.</li>
<li>State objects <strong>can be shared</strong> between entity Objects, either by setting one entity object’s state attribute to another entity’s State object, or by setting a <code>sharedState</code> flag in the argument object when cloning a new entity from an existing one.</li>
<li>Entitys can skip the engine comparison step during their Display cycle stamp functionality by setting their <code>noCanvasEngineUpdates</code> flag to true.</li>
<li>State attributes can be updated directly on the Entity or Cell using those object’s normal <code>set</code> and <code>deltaSet</code> functions.</li>
<li>State objects will be saved, cloned and killed as part of the Cell or entity save/clone/kill functionality.</li>
</ul>
</div>
</li>
<li id="section-2">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-2">§</a>
</div>
<h4 id="demos">Demos:</h4>
<ul>
<li>All Canvas demos make use of the State object.</li>
</ul>
</div>
</li>
<li id="section-3">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-3">§</a>
</div>
<h4 id="imports">Imports</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { constructors, entity, styles } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/library.js'</span>;
<span class="hljs-keyword">import</span> { isa_obj, xt, xtGet, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/utilities.js'</span>;
<span class="hljs-keyword">import</span> baseMix <span class="hljs-keyword">from</span> <span class="hljs-string">'../mixin/base.js'</span>;</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-4">§</a>
</div>
<h4 id="state-constructor">State constructor</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">State</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</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-property">lineDash</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">§</a>
</div>
<h4 id="state-prototype">State prototype</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> P = <span class="hljs-title class_">State</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">'State'</span>;</pre></div></div>
</li>
<li id="section-6">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-6">§</a>
</div>
<h4 id="mixins">Mixins</h4>
</div>
<div class="content"><div class='highlight'><pre>P = <span class="hljs-title function_">baseMix</span>(P);</pre></div></div>
</li>
<li id="section-7">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-7">§</a>
</div>
<h4 id="state-attributes">State attributes</h4>
<ul>
<li>Attributes defined in the <a href="../mixin/base.html">base mixin</a>: <strong>name</strong>.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">defs</span> = {</pre></div></div>
</li>
<li id="section-8">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-8">§</a>
</div>
<h5 id="fills-and-strokes">Fills and Strokes</h5>
<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>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">fillStyle</span>: <span class="hljs-string">'rgba(0,0,0,1)'</span>,
<span class="hljs-attr">strokeStyle</span>: <span class="hljs-string">'rgba(0,0,0,1)'</span>,</pre></div></div>
</li>
<li id="section-9">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-9">§</a>
</div>
<h5 id="miscellaneous-engine-settings">Miscellaneous engine settings</h5>
<p><strong>globalAlpha</strong> - entity transparency - a value between 0 and 1, where 0 is completely transparent and 1 is completely opaque</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">globalAlpha</span>: <span class="hljs-number">1</span>,</pre></div></div>
</li>
<li id="section-10">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-10">§</a>
</div>
<p><strong>globalCompositeOperation</strong> - compositing method for applying the entity to an existing Cell (<canvas>) 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>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">globalCompositeOperation</span>: <span class="hljs-string">'source-over'</span>,</pre></div></div>
</li>
<li id="section-11">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-11">§</a>
</div>
<h5 id="stroke-line-styling">Stroke line styling</h5>
<p><strong>lineWidth</strong> - in pixels</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">lineWidth</span>: <span class="hljs-number">1</span>,</pre></div></div>
</li>
<li id="section-12">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-12">§</a>
</div>
<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>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">lineCap</span>: <span class="hljs-string">'butt'</span>,</pre></div></div>
</li>
<li id="section-13">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-13">§</a>
</div>
<p><strong>lineJoin</strong> - how line joints will display. Permitted values include:</p>
<ul>
<li>‘miter’</li>
<li>‘round’</li>
<li>‘bevel’</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">lineJoin</span>: <span class="hljs-string">'miter'</span>,</pre></div></div>
</li>
<li id="section-14">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-14">§</a>
</div>
<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>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">lineDash</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">§</a>
</div>
<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>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">lineDashOffset</span>: <span class="hljs-number">0</span>,</pre></div></div>
</li>
<li id="section-16">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-16">§</a>
</div>
<p><strong>miterLimit</strong> - affecting the ‘pointiness’ of the line join where two lines join at an acute angle</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">miterLimit</span>: <span class="hljs-number">10</span>,</pre></div></div>
</li>
<li id="section-17">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-17">§</a>
</div>
<h5 id="shadow-styling">Shadow styling</h5>
<p>If these attributes are set to values different from their defaults, then the shadowing effect will have consequences on how the entity displays. Scrawl-canvas uses a 2-step procedure to displaying both an entity’s fill and stroke, applying one before the other - <code>method</code> <strong>fillThenDraw</strong>, <strong>drawThenFill</strong>. The shadow will be applied for both operations, which leads to the second operation applying a shadow over the first operation.</p>
<p>If this is not the desired effect - we want the stroke and fill to display as a unified whole, with the shadow underneath them both - we can use <code>method</code> <strong>fillAndDraw</strong>, <strong>drawAndFill</strong>.</p>
<p>The <strong>clear</strong> <code>method</code> will also include any shadow effect.</p>
</div>
</li>
<li id="section-18">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-18">§</a>
</div>
<p><strong>shadowOffsetX</strong>, <strong>shadowOffsetY</strong> - horizontal and vertical offsets for a entity’s shadow, in Number pixels</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">shadowOffsetX</span>: <span class="hljs-number">0</span>,
<span class="hljs-attr">shadowOffsetY</span>: <span class="hljs-number">0</span>,</pre></div></div>
</li>
<li id="section-19">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-19">§</a>
</div>
<p><strong>shadowBlur</strong> - the blur width for a entity’s shadow, in Number pixels</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">shadowBlur</span>: <span class="hljs-number">0</span>,</pre></div></div>
</li>
<li id="section-20">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-20">§</a>
</div>
<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>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">shadowColor</span>: <span class="hljs-string">'rgba(0,0,0,0)'</span>,</pre></div></div>
</li>
<li id="section-21">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-21">§</a>
</div>
<h5 id="font-styling">Font styling</h5>
<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>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">font</span>: <span class="hljs-string">'12px sans-serif'</span>,
<span class="hljs-attr">textAlign</span>: <span class="hljs-string">'left'</span>,
<span class="hljs-attr">textBaseline</span>: <span class="hljs-string">'top'</span>,</pre></div></div>
</li>
<li id="section-22">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-22">§</a>
</div>
<h5 id="csssvg-filters">CSS/SVG filters</h5>
<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> <span class="hljs-attr">filter</span>: <span class="hljs-string">'none'</span>,</pre></div></div>
</li>
<li id="section-23">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-23">§</a>
</div>
<h5 id="image-smoothing">Image smoothing</h5>
<p><strong>imageSmoothingEnabled</strong> - switch image smoothing on or off, on a per-entity basis</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">imageSmoothingEnabled</span>: <span class="hljs-literal">true</span>,</pre></div></div>
</li>
<li id="section-24">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-24">§</a>
</div>
<p><strong>imageSmoothingQuality</strong> - when image smoothing is enabled, determine the quality of image smoothing to apply to the entity.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">imageSmoothingQuality</span>: <span class="hljs-string">'high'</span>,
};</pre></div></div>
</li>
<li id="section-25">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-25">§</a>
</div>
<h4 id="packet-management">Packet management</h4>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">processPacketOut</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">switch</span> (key) {
<span class="hljs-keyword">case</span> <span class="hljs-string">'lineDash'</span> :
<span class="hljs-keyword">if</span> (!value.<span class="hljs-property">length</span>) {
result = (includes.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'lineDash'</span>) >= <span class="hljs-number">0</span>) ? <span class="hljs-literal">true</span> : <span class="hljs-literal">false</span>;
}
<span class="hljs-keyword">break</span>;
<span class="hljs-keyword">default</span> :
<span class="hljs-keyword">if</span> (includes.<span class="hljs-title function_">indexOf</span>(key) < <span class="hljs-number">0</span> && 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> fill = copy.<span class="hljs-property">fillStyle</span>,
stroke = copy.<span class="hljs-property">strokeStyle</span>;
<span class="hljs-keyword">if</span> (fill && !fill.<span class="hljs-property">substring</span>) copy.<span class="hljs-property">fillStyle</span> = fill.<span class="hljs-property">name</span>;
<span class="hljs-keyword">if</span> (stroke && !stroke.<span class="hljs-property">substring</span>) copy.<span class="hljs-property">strokeStyle</span> = stroke.<span class="hljs-property">name</span>;
<span class="hljs-keyword">return</span> copy;
};</pre></div></div>
</li>
<li id="section-26">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-26">§</a>
</div>
<h4 id="clone-management">Clone management</h4>
<p>Handled by Cell and entity objects, not by the State object</p>
</div>
</li>
<li id="section-27">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-27">§</a>
</div>
<h4 id="kill-management">Kill management</h4>
<p>Handled by Cell and entity objects, not by the State object</p>
</div>
</li>
<li id="section-28">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-28">§</a>
</div>
<h4 id="get-set-deltaset">Get, Set, deltaSet</h4>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">set</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) {
<span class="hljs-keyword">let</span> keys = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">keys</span>(items),
keysLen = keys.<span class="hljs-property">length</span>,
key, i,
d = <span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>;
<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i < keysLen; i++) {
key = keys[i];
<span class="hljs-keyword">if</span> (key != <span class="hljs-string">'name'</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> d[key] != <span class="hljs-string">'undefined'</span>) {
<span class="hljs-variable language_">this</span>[key] = items[key];
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>;
}
}
}
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};
P.<span class="hljs-property">get</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">let</span> undef, d, i;
d = <span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>[item];
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> d !== <span class="hljs-string">'undefined'</span>) {
i = <span class="hljs-variable language_">this</span>[item];
<span class="hljs-keyword">return</span> (<span class="hljs-keyword">typeof</span> i !== <span class="hljs-string">'undefined'</span>) ? i : d;
}
<span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> undef;
};
<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-29">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-29">§</a>
</div>
<p>The following setters use the <code>window.scrawlEnvironmentColorChecker</code> Color factory. This factory gets created and attached to the window object during Scrawl-canvas initialization. Code for creating the factory can be found in the <code>core/init.js</code> module</p>
</div>
<div class="content"><div class='highlight'><pre>S.<span class="hljs-property">fillStyle</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">let</span> temp;
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_obj</span>(item) && item.<span class="hljs-property">lib</span> === <span class="hljs-string">'styles'</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">fillStyle</span> = item;
<span class="hljs-keyword">else</span>{
temp = styles[item];
<span class="hljs-keyword">if</span> (temp) <span class="hljs-variable language_">this</span>.<span class="hljs-property">fillStyle</span> = temp;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">includes</span>(<span class="hljs-string">'rgb'</span>) || item.<span class="hljs-title function_">includes</span>(<span class="hljs-string">'hsl'</span>) || item.<span class="hljs-title function_">includes</span>(<span class="hljs-string">'#'</span>)) <span class="hljs-variable language_">this</span>.<span class="hljs-property">fillStyle</span> = item;
<span class="hljs-keyword">else</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">fillStyle</span> = <span class="hljs-variable language_">window</span>.<span class="hljs-property">scrawlEnvironmentColorChecker</span>.<span class="hljs-title function_">checkColor</span>(item);
}
};
S.<span class="hljs-property">strokeStyle</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">let</span> temp;
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_obj</span>(item) && item.<span class="hljs-property">lib</span> === <span class="hljs-string">'styles'</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">strokeStyle</span> = item;
<span class="hljs-keyword">else</span>{
temp = styles[item];
<span class="hljs-keyword">if</span> (temp) <span class="hljs-variable language_">this</span>.<span class="hljs-property">strokeStyle</span> = temp;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">includes</span>(<span class="hljs-string">'rgb'</span>) || item.<span class="hljs-title function_">includes</span>(<span class="hljs-string">'hsl'</span>) || item.<span class="hljs-title function_">includes</span>(<span class="hljs-string">'#'</span>)) <span class="hljs-variable language_">this</span>.<span class="hljs-property">strokeStyle</span> = item;
<span class="hljs-keyword">else</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">strokeStyle</span> = <span class="hljs-variable language_">window</span>.<span class="hljs-property">scrawlEnvironmentColorChecker</span>.<span class="hljs-title function_">checkColor</span>(item);
}
};
S.<span class="hljs-property">shadowColor</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">includes</span>(<span class="hljs-string">'rgb'</span>) || item.<span class="hljs-title function_">includes</span>(<span class="hljs-string">'hsl'</span>) || item.<span class="hljs-title function_">includes</span>(<span class="hljs-string">'#'</span>)) <span class="hljs-variable language_">this</span>.<span class="hljs-property">shadowColor</span> = item;
<span class="hljs-keyword">else</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">shadowColor</span> = <span class="hljs-variable language_">window</span>.<span class="hljs-property">scrawlEnvironmentColorChecker</span>.<span class="hljs-title function_">checkColor</span>(item);
};</pre></div></div>
</li>
<li id="section-30">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-30">§</a>
</div>
<h4 id="prototype-functions">Prototype functions</h4>
<p>Internal arrays used by a number of Style functions</p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">allKeys</span> = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">keys</span>(P.<span class="hljs-property">defs</span>);
P.<span class="hljs-property">mainKeys</span> = [<span class="hljs-string">'filter'</span>, <span class="hljs-string">'globalAlpha'</span>, <span class="hljs-string">'globalCompositeOperation'</span>, <span class="hljs-string">'imageSmoothingEnabled'</span>, <span class="hljs-string">'imageSmoothingQuality'</span>, <span class="hljs-string">'shadowBlur'</span>, <span class="hljs-string">'shadowOffsetX'</span>, <span class="hljs-string">'shadowOffsetY'</span>];
P.<span class="hljs-property">lineKeys</span> = [<span class="hljs-string">'lineCap'</span>, <span class="hljs-string">'lineDash'</span>, <span class="hljs-string">'lineDashOffset'</span>, <span class="hljs-string">'lineJoin'</span>, <span class="hljs-string">'lineWidth'</span>, <span class="hljs-string">'miterLimit'</span>];
P.<span class="hljs-property">styleKeys</span> = [<span class="hljs-string">'fillStyle'</span>, <span class="hljs-string">'shadowColor'</span>, <span class="hljs-string">'strokeStyle'</span>];
P.<span class="hljs-property">textKeys</span> = [<span class="hljs-string">'font'</span>];</pre></div></div>
</li>
<li id="section-31">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-31">§</a>
</div>
<p><code>getChanges</code> is the key function performed by State objects. This is where the entity’s state is compared to a Cell engine’s current state, to identify which engine attributes need to change to bring it into alignment with the entity object’s requirements</p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">getChanges</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">ent, engineState</span>) {
<span class="hljs-keyword">let</span> mainKeys = <span class="hljs-variable language_">this</span>.<span class="hljs-property">mainKeys</span>,
lineKeys = <span class="hljs-variable language_">this</span>.<span class="hljs-property">lineKeys</span>,
styleKeys = <span class="hljs-variable language_">this</span>.<span class="hljs-property">styleKeys</span>,
textKeys = <span class="hljs-variable language_">this</span>.<span class="hljs-property">textKeys</span>,
k, style, scaled, i, iz, j, jz,
linedashFlag, desired, current,
defs = <span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>,
result = {};
<span class="hljs-keyword">let</span> getItem = <span class="hljs-keyword">function</span> (<span class="hljs-params">source, key</span>) {
<span class="hljs-keyword">return</span> (<span class="hljs-keyword">typeof</span> source[key] != <span class="hljs-string">'undefined'</span>) ? source[key] : defs[key];
};
<span class="hljs-keyword">if</span> (ent.<span class="hljs-property">substring</span>) ent = entity[ent];</pre></div></div>
</li>
<li id="section-32">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-32">§</a>
</div>
<p>‘filter’, ‘globalAlpha’, ‘globalCompositeOperation’, ‘imageSmoothingEnabled’, ‘imageSmoothingQuality’, ‘shadowBlur’, ‘shadowOffsetX’, ‘shadowOffsetY’</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>, iz = mainKeys.<span class="hljs-property">length</span>; i < iz; i++) {
k = mainKeys[i];
desired = <span class="hljs-title function_">getItem</span>(<span class="hljs-variable language_">this</span>, k);
current = <span class="hljs-title function_">getItem</span>(engineState, k);
<span class="hljs-keyword">if</span> (current !== desired) result[k] = desired;
}</pre></div></div>
</li>
<li id="section-33">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-33">§</a>
</div>
<p>‘lineCap’, ‘lineDas