scrawl-canvas
Version:
Version 8.9.4 - 19 Nov 2022
1,052 lines (680 loc) • 96.8 kB
HTML
<!DOCTYPE html>
<html>
<head>
<title>Styles 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 …</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">§</a>
</div>
<h1 id="styles-mixin">Styles mixin</h1>
<p>The styles mixin contains most of the code required for the <a href="../factory/gradient.html">Gradient</a>, <a href="../factory/radialGradient.html">RadialGradient</a> an <a href="../factory/conicGradient.html">ConicGradient</a> styles factories. It is not used by the other styles objects (<a href="../factory/color.html">Color</a>, <a href="../factory/pattern.html">Pattern</a>).</p>
<ul>
<li>the <strong>start</strong> and <strong>end</strong> positioning attributes are defined here rather than in the factories</li>
<li>gradient-type styles manage their color stops in <a href="../factory/palette.html">Palette factory</a> objects; that functionality is entirely defined here</li>
</ul>
<p>The Canvas API CanvasRenderingContext2D interface defines three types of gradient: the widely supported <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createLinearGradient">linear</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createRadialGradient">radial</a> gradients, and the <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createConicGradient">conic</a> which, while widely supported as a CSS feature, is very much an experimental technology for CanvasRenderingContext2D engines.</p>
<ul>
<li>the <code>createLinearGradient</code> method creates a gradient along the line connecting two given coordinates (<strong>start</strong> and <strong>end</strong>) which are absolute values (measured in pixels) from the <canvas> elements top-left corner</li>
<li>the <code>createRadialGradient</code> method creates a radial gradient using the size and coordinates of two circles.</li>
<li>the <code>createConicGradient</code> method creates a conic gradient as a 360° sweep around the gradient’s start coordinate. For browsers which don’t support this gradient out of the box, the method will apply no gradient to the entity.</li>
</ul>
<p>Common to linear and radial types of gradient is the idea of a start coordinate and an end coordinate, supplied in pixels. </p>
<ul>
<li>Scrawl-canvas extends this idea so that the coordinates can be supplied as a percentage value (String%) of the host Cell’s dimensions. </li>
<li>Furthermore Scrawl-canvas allows each entity that uses a Gradient-type style to indicate whether the reference box should be that of the host Cell, or of the entity itself, through their <code>lockFillStyleToEntity</code> and <code>lockStrokeStyleToEntity</code> attribute flags.</li>
</ul>
</div>
</li>
<li id="section-2">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-2">§</a>
</div>
<h4 id="imports">Imports</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { entity, palette, styles, stylesnames } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/library.js'</span>;
<span class="hljs-keyword">import</span> { addStrings, λ<span class="hljs-literal">null</span>, mergeOver, xt, isa_obj, mergeDiscard, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/utilities.js'</span>;
<span class="hljs-keyword">import</span> { makeAnimation } <span class="hljs-keyword">from</span> <span class="hljs-string">'../factory/animation.js'</span>;
<span class="hljs-keyword">import</span> { makeCoordinate } <span class="hljs-keyword">from</span> <span class="hljs-string">'../factory/coordinate.js'</span>;
<span class="hljs-keyword">import</span> { makePalette, paletteKeys } <span class="hljs-keyword">from</span> <span class="hljs-string">'../factory/palette.js'</span>;</pre></div></div>
</li>
<li id="section-3">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-3">§</a>
</div>
<p>Create an animation to handle automated delta gradient animation</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-title function_">makeAnimation</span>({
<span class="hljs-attr">name</span>: <span class="hljs-string">'SC-system-gradient-delta-animation'</span>,
<span class="hljs-attr">fn</span>: <span class="hljs-function">() =></span> {
stylesnames.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">name</span> =></span> {
<span class="hljs-keyword">const</span> style = styles[name];
<span class="hljs-keyword">if</span> (style && style.<span class="hljs-property">animateByDelta</span>) style.<span class="hljs-title function_">updateByDelta</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="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-5">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-5">§</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">§</a>
</div>
<p><strong>start</strong>, <strong>end</strong> - Gradient-type styles use Coordinate factory Arrays to hold details of their start and end coordinates. The following <em>pseudo-attributes</em> can also be used to reference these values:</p>
<ul>
<li>for the start coordinate, <strong>startX</strong> and <strong>startY</strong></li>
<li>for the end coordinate, <strong>endX</strong> and <strong>endY</strong></li>
</ul>
<p>In all cases, the attribute values can be Numbers, which indicate absolute pixel coordinates, or String% values for coordinates calculated relative to either Cell or entity current dimensions </p>
<ul>
<li>for the <code>x</code> coordinate, the Strings <strong>left</strong>, <strong>center</strong> and <strong>right</strong> are also supported</li>
<li>for the <code>y</code> coordinate, the Strings <strong>top</strong>, <strong>center</strong> and <strong>bottom</strong> are also supported</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">start</span>: <span class="hljs-literal">null</span>,
<span class="hljs-attr">end</span>: <span class="hljs-literal">null</span>,</pre></div></div>
</li>
<li id="section-7">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-7">§</a>
</div>
<p><strong>palette</strong> - Every gradient requires a Palette object containing color stop instructions. Generation of the object is automated and should ot be tampered with. Add and remove colors to the gradient using the <code>updateColor</code> and <code>removeColor</code> functions.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">palette</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">§</a>
</div>
<p><strong>paletteStart</strong>, <strong>paletteEnd</strong> - We don’t need to use the entire palette when building a gradient; we can restrict the palette using these start and end attributes.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">paletteStart</span>: <span class="hljs-number">0</span>,
<span class="hljs-attr">paletteEnd</span>: <span class="hljs-number">999</span>,</pre></div></div>
</li>
<li id="section-9">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-9">§</a>
</div>
<p>The <strong>cyclePalette</strong> attribute tells the Palette object how to handle situations where the paletteStart value is greater than the paletteEnd value:</p>
<ul>
<li>when false, we reverse the color stops</li>
<li>when true, we keep the normal order of color stops and pass through the 1/0 border</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">cyclePalette</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">§</a>
</div>
<p>The <strong>animateByDelta</strong> attribute, when true, will delta animate the gradient at the start of each Display cycle. When the gradient is used in the <code>mapToGradient`` filter, setting this attribute to </code>false` (default) should speed up the filter</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">animateByDelta</span>: <span class="hljs-literal">false</span>,</pre></div></div>
</li>
<li id="section-11">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-11">§</a>
</div>
<p>The <strong>delta</strong> object is not stored in the defs object; it acts in a similar way to the artefact delta object - though it is restricted to adding delta values to Number and ‘String%’ attributes.</p>
<ul>
<li>Unlike artefacts, where delta animation will be applied to artefacts by default as part of each Display cycle, gradient delta animations need to be explicitly invoked: <code>my_gradient.updateByDelta();</code></li>
</ul>
<p>The <strong>colors</strong> <em>pseudo-attribute</em> can be used to pass through an array of palette color objects to the Palette object. The data is not retained by the gradient object.</p>
<ul>
<li>A better approach to managing gradient colors is to use the <code>updateColor</code> and <code>removeColor</code> functions</li>
</ul>
</div>
</li>
<li id="section-12">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-12">§</a>
</div>
<p>The <strong>easing</strong> <em>pseudo-attribute</em> represents a transformation that will be applied to a copy of the color stops Array - this allows us to create non-linear gradients. Value is passed through to the Palette object</p>
</div>
</li>
<li id="section-13">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-13">§</a>
</div>
<p>The <strong>precision</strong> <em>pseudo-attribute</em> - value is passed through to the Palette object</p>
</div>
</li>
<li id="section-14">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-14">§</a>
</div>
<p>The <strong>colorSpace</strong> - String <em>pseudo-attribute</em> defines the color space to be used by the Palette’s Color object for its internal calculations - value is passed through to the Palette object</p>
<ul>
<li>Accepted values from: <code>'RGB', 'HSL', 'HWB', 'XYZ', 'LAB', 'LCH', 'OKLAB', 'OKLCH'</code> with <code>RGB</code> as the default</li>
</ul>
<p>The <strong>returnColorAs</strong> - String <em>pseudo-attribute</em> defines the type of color String the Palette’s Color object will return - value is passed through to the Palette object</p>
<ul>
<li>Accepted values from: <code>'RGB', 'HSL', 'HWB', 'LAB', 'LCH', 'OKLAB', 'OKLCH'</code> with <code>RGB</code> as the default</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-15">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-15">§</a>
</div>
<h4 id="packet-management">Packet management</h4>
</div>
<div class="content"><div class='highlight'><pre> P.<span class="hljs-property">finalizePacketOut</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">copy, items</span>) {
<span class="hljs-keyword">if</span> (items.<span class="hljs-property">colors</span>) copy.<span class="hljs-property">colors</span> = items.<span class="hljs-property">colors</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>) copy.<span class="hljs-property">colors</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>.<span class="hljs-title function_">get</span>(<span class="hljs-string">'colors'</span>);
<span class="hljs-keyword">else</span> copy.<span class="hljs-property">colors</span> = [[<span class="hljs-number">0</span>, <span class="hljs-string">'rgba(0 0 0 / 1)'</span>], [<span class="hljs-number">999</span>, <span class="hljs-string">'rgba(255 255 255 / 1)'</span>]];</pre></div></div>
</li>
<li id="section-16">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-16">§</a>
</div>
<p>TODO: don’t think this will return bespoke easing functions - need to think further on how to accomplish this</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (items.<span class="hljs-property">easing</span>) copy.<span class="hljs-property">easing</span> = items.<span class="hljs-property">easing</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span> && <span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>.<span class="hljs-property">easing</span>) copy.<span class="hljs-property">easing</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>.<span class="hljs-property">easing</span>;
<span class="hljs-keyword">else</span> copy.<span class="hljs-property">easing</span> = <span class="hljs-string">'linear'</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(items.<span class="hljs-property">precision</span>)) copy.<span class="hljs-property">precision</span> = items.<span class="hljs-property">precision</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span> && <span class="hljs-title function_">xt</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>.<span class="hljs-property">precision</span>)) copy.<span class="hljs-property">precision</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>.<span class="hljs-property">precision</span>;
<span class="hljs-keyword">else</span> copy.<span class="hljs-property">precision</span> = <span class="hljs-number">0</span>;
<span class="hljs-keyword">if</span> (items.<span class="hljs-property">colorSpace</span>) copy.<span class="hljs-property">colorSpace</span> = items.<span class="hljs-property">colorSpace</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>) copy.<span class="hljs-property">colorSpace</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>.<span class="hljs-title function_">getColorSpace</span>();
<span class="hljs-keyword">else</span> copy.<span class="hljs-property">colorSpace</span> = <span class="hljs-string">'RGB'</span>;
<span class="hljs-keyword">if</span> (items.<span class="hljs-property">returnColorAs</span>) copy.<span class="hljs-property">returnColorAs</span> = items.<span class="hljs-property">returnColorAs</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>) copy.<span class="hljs-property">returnColorAs</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>.<span class="hljs-title function_">getReturnColorAs</span>();
<span class="hljs-keyword">else</span> copy.<span class="hljs-property">returnColorAs</span> = <span class="hljs-string">'RGB'</span>;
<span class="hljs-keyword">return</span> copy;
};</pre></div></div>
</li>
<li id="section-17">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-17">§</a>
</div>
<h4 id="clone-management">Clone management</h4>
<p>No additional clone functionality defined here</p>
</div>
</li>
<li id="section-18">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-18">§</a>
</div>
<h4 id="kill-management">Kill management</h4>
</div>
<div class="content"><div class='highlight'><pre> P.<span class="hljs-property">kill</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>;
<span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span> && <span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>.<span class="hljs-property">kill</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span>.<span class="hljs-title function_">kill</span>();</pre></div></div>
</li>
<li id="section-19">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-19">§</a>
</div>
<p>Remove style from all entity state objects</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">entries</span>(entity).<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">[name, ent]</span>) =></span> {
<span class="hljs-keyword">let</span> state = ent.<span class="hljs-property">state</span>;
<span class="hljs-keyword">if</span> (state) {
<span class="hljs-keyword">let</span> fill = state.<span class="hljs-property">fillStyle</span>,
stroke = state.<span class="hljs-property">strokeStyle</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_obj</span>(fill) && fill.<span class="hljs-property">name</span> === myname) state.<span class="hljs-property">fillStyle</span> = state.<span class="hljs-property">defs</span>.<span class="hljs-property">fillStyle</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_obj</span>(stroke) && stroke.<span class="hljs-property">name</span> === myname) state.<span class="hljs-property">strokeStyle</span> = state.<span class="hljs-property">defs</span>.<span class="hljs-property">strokeStyle</span>;
}
});</pre></div></div>
</li>
<li id="section-20">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-20">§</a>
</div>
<p>Remove style from the Scrawl-canvas library</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">deregister</span>();
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};</pre></div></div>
</li>
<li id="section-21">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-21">§</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-22">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-22">§</a>
</div>
<p><code>start</code>, <code>startX</code>, <code>startY</code></p>
</div>
<div class="content"><div class='highlight'><pre> G.<span class="hljs-property">startX</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">currentStart</span>[<span class="hljs-number">0</span>];
};
G.<span class="hljs-property">startY</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">currentStart</span>[<span class="hljs-number">1</span>];
};
S.<span class="hljs-property">startX</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">coord</span>) {
<span class="hljs-keyword">if</span> (coord != <span class="hljs-literal">null</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">start</span>[<span class="hljs-number">0</span>] = coord;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyStart</span> = <span class="hljs-literal">true</span>;
}
};
S.<span class="hljs-property">startY</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">coord</span>) {
<span class="hljs-keyword">if</span> (coord != <span class="hljs-literal">null</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">start</span>[<span class="hljs-number">1</span>] = coord;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyStart</span> = <span class="hljs-literal">true</span>;
}
};
S.<span class="hljs-property">start</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">x, y</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setCoordinateHelper</span>(<span class="hljs-string">'start'</span>, x, y);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyStart</span> = <span class="hljs-literal">true</span>;
};
D.<span class="hljs-property">startX</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">coord</span>) {
<span class="hljs-keyword">let</span> c = <span class="hljs-variable language_">this</span>.<span class="hljs-property">start</span>;
c[<span class="hljs-number">0</span>] = <span class="hljs-title function_">addStrings</span>(c[<span class="hljs-number">0</span>], coord);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyStart</span> = <span class="hljs-literal">true</span>;
};
D.<span class="hljs-property">startY</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">coord</span>) {
<span class="hljs-keyword">let</span> c = <span class="hljs-variable language_">this</span>.<span class="hljs-property">start</span>;
c[<span class="hljs-number">1</span>] = <span class="hljs-title function_">addStrings</span>(c[<span class="hljs-number">1</span>], coord);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyStart</span> = <span class="hljs-literal">true</span>;
};
D.<span class="hljs-property">start</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">x, y</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setDeltaCoordinateHelper</span>(<span class="hljs-string">'start'</span>, x, y);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyStart</span> = <span class="hljs-literal">true</span>;
};</pre></div></div>
</li>
<li id="section-23">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-23">§</a>
</div>
<p><code>end</code>, <code>endX</code>, <code>endY</code></p>
</div>
<div class="content"><div class='highlight'><pre> G.<span class="hljs-property">endX</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">currentEnd</span>[<span class="hljs-number">0</span>];
};
G.<span class="hljs-property">endY</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">currentEnd</span>[<span class="hljs-number">1</span>];
};
S.<span class="hljs-property">endX</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">coord</span>) {
<span class="hljs-keyword">if</span> (coord != <span class="hljs-literal">null</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">end</span>[<span class="hljs-number">0</span>] = coord;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyEnd</span> = <span class="hljs-literal">true</span>;
}
};
S.<span class="hljs-property">endY</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">coord</span>) {
<span class="hljs-keyword">if</span> (coord != <span class="hljs-literal">null</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">end</span>[<span class="hljs-number">1</span>] = coord;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyEnd</span> = <span class="hljs-literal">true</span>;
}
};
S.<span class="hljs-property">end</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">x, y</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setCoordinateHelper</span>(<span class="hljs-string">'end'</span>, x, y);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyEnd</span> = <span class="hljs-literal">true</span>;
};
D.<span class="hljs-property">endX</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">coord</span>) {
<span class="hljs-keyword">let</span> c = <span class="hljs-variable language_">this</span>.<span class="hljs-property">end</span>;
c[<span class="hljs-number">0</span>] = <span class="hljs-title function_">addStrings</span>(c[<span class="hljs-number">0</span>], coord);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyEnd</span> = <span class="hljs-literal">true</span>;
};
D.<span class="hljs-property">endY</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">coord</span>) {
<span class="hljs-keyword">let</span> c = <span class="hljs-variable language_">this</span>.<span class="hljs-property">end</span>;
c[<span class="hljs-number">1</span>] = <span class="hljs-title function_">addStrings</span>(c[<span class="hljs-number">1</span>], coord);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyEnd</span> = <span class="hljs-literal">true</span>;
};
D.<span class="hljs-property">end</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">x, y</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setDeltaCoordinateHelper</span>(<span class="hljs-string">'end'</span>, x, y);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyEnd</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><code>palette</code> - argument has to be a Palette object</p>
</div>
<div class="content"><div class='highlight'><pre> S.<span class="hljs-property">palette</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item = Ωempty</span>) {
<span class="hljs-keyword">if</span>(item.<span class="hljs-property">type</span> === <span class="hljs-string">'Palette'</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">palette</span> = item;
};</pre></div></div>
</li>
<li id="section-25">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-25">§</a>
</div>
<p><code>paletteStart</code> - argument must be a positive integer Number in the range 0 - 999</p>
</div>
<div class="content"><div class='highlight'><pre> S.<span class="hljs-property">paletteStart</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (item.<span class="hljs-property">toFixed</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">paletteStart</span> = item;
<span class="hljs-keyword">if