UNPKG

scrawl-canvas

Version:
1,118 lines (699 loc) 46.2 kB
<!DOCTYPE html> <html> <head> <title>Tween 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="tween-mixin">Tween mixin</h1> <p>This mixin defines attributes and functions shared by <a href="../factory/tween.html">Tween</a> objects and <a href="../factory/action.html">Action</a> objects</p> <ul> <li><a href="../factory/ticker.html">Ticker</a> objects do not use this mixin</li> </ul> </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-keyword">as</span> library <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/library.js&#x27;</span>; <span class="hljs-keyword">import</span> { animationtickers } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/library.js&#x27;</span>; <span class="hljs-keyword">import</span> { mergeOver, isa_fn, isa_obj, xt, xtGet, convertTime, λ<span class="hljs-literal">null</span>, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/utilities.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> <p><strong>locateTarget</strong> - a private function and attribute to help retrieve data from the scrawl-canvas library</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> locateTargetSections = [<span class="hljs-string">&#x27;artefact&#x27;</span>, <span class="hljs-string">&#x27;group&#x27;</span>, <span class="hljs-string">&#x27;animation&#x27;</span>, <span class="hljs-string">&#x27;tween&#x27;</span>, <span class="hljs-string">&#x27;styles&#x27;</span>]; <span class="hljs-keyword">const</span> <span class="hljs-title function_">locateTarget</span> = (<span class="hljs-params">item</span>) =&gt; { <span class="hljs-keyword">if</span>(item &amp;&amp; item.<span class="hljs-property">substring</span>){ <span class="hljs-keyword">let</span> result; <span class="hljs-keyword">return</span> (locateTargetSections.<span class="hljs-title function_">some</span>(<span class="hljs-function"><span class="hljs-params">section</span> =&gt;</span> { result = library[section][item]; <span class="hljs-keyword">return</span> result; })) ? result : <span class="hljs-literal">false</span>; } <span class="hljs-keyword">return</span> <span class="hljs-literal">false</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="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">&#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>order</strong> - integer Number (defaults to <code>1</code>) - the order in which Tween/Actions run is determined by their order value: Tween/Actions with a lower order value run before those with a higher value</p> <ul> <li>Run order for Tween/Actions with the same order value is determined by the order in which they are defined in code</li> </ul> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">order</span>: <span class="hljs-number">1</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>ticker</strong> - String - the name-String of the Ticker the Tween/Action uses for its timeline</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">ticker</span>: <span class="hljs-string">&#x27;&#x27;</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>targets</strong> - Array containing the Scrawl-canvas objects on which the Tween/Action will act; one Tween/Action can modify attributes in multiple objects</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">targets</span>: <span class="hljs-literal">null</span>,</pre></div></div> </li> <li id="section-9"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-9">&#x00a7;</a> </div> <p><strong>time</strong> - the timeline time when the Tween/Action activates and runs.</p> <ul> <li>Tween/Actions given a time value of <code>0</code> will run as soon as their associated Ticker timeline runs; values greater than 0 will delay their run until that time is reached on the timeline.</li> <li>Time can be set as a Number value representing microseconds</li> <li>It can also be set as a time string - <code>3s</code> is 3000 milliseconds; <code>200ms</code> is 200 milliseconds</li> <li>Or it can be set as a percentage String - <code>30%</code> - measured against the duration of the Ticker timeline.</li> </ul> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">time</span>: <span class="hljs-number">0</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>action</strong> - a user-defined function which will run every time the Tween/Action completes an update - generally once each Display cycle while the Tween/Action is running</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">action</span>: <span class="hljs-literal">null</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>reverseOnCycleEnd</strong> - Boolean flag; when set, the Tween/Action will reverse its direction and continue running, rather than halt.</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">reverseOnCycleEnd</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> <p><strong>reversed</strong> - internal Boolean flag indicating whether the Tween/Action is running in <code>forwards</code> or <code>backwards</code> mode</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">reversed</span>: <span class="hljs-literal">false</span>, }; P.<span class="hljs-property">defs</span> = <span class="hljs-title function_">mergeOver</span>(P.<span class="hljs-property">defs</span>, defaultAttributes);</pre></div></div> </li> <li id="section-13"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-13">&#x00a7;</a> </div> <h4 id="packet-management">Packet management</h4> <p>No additional packet functionality defined here</p> </div> </li> <li id="section-14"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-14">&#x00a7;</a> </div> <h4 id="clone-management">Clone management</h4> <p>No additional clone functionality defined here</p> </div> </li> <li id="section-15"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-15">&#x00a7;</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> t, ticker = <span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span>; <span class="hljs-keyword">if</span> (ticker === <span class="hljs-string">`<span class="hljs-subst">${<span class="hljs-variable language_">this</span>.name}</span>_ticker`</span>) { t = animationtickers[ticker]; <span class="hljs-keyword">if</span> (t) t.<span class="hljs-title function_">kill</span>(); } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (ticker) <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">removeFromTicker</span>(ticker); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">deregister</span>(); <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>; };</pre></div></div> </li> <li id="section-16"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-16">&#x00a7;</a> </div> <h4 id="get-set-deltaset">Get, Set, deltaSet</h4> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> G = P.<span class="hljs-property">getters</span>, S = P.<span class="hljs-property">setters</span>;</pre></div></div> </li> <li id="section-17"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-17">&#x00a7;</a> </div> <p><strong>targets</strong></p> <ul> <li>the getter returns a fresh copy of the current targets Array</li> </ul> </div> <div class="content"><div class='highlight'><pre> G.<span class="hljs-property">targets</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">return</span> [].<span class="hljs-title function_">concat</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">targets</span>); }; S.<span class="hljs-property">targets</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item = []</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setTargets</span>(item); };</pre></div></div> </li> <li id="section-18"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-18">&#x00a7;</a> </div> <p><strong>action</strong></p> </div> <div class="content"><div class='highlight'><pre> S.<span class="hljs-property">action</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">action</span> = item; <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">action</span> !== <span class="hljs-string">&#x27;function&#x27;</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">action</span> = λ<span class="hljs-literal">null</span>; };</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="prototype-functions">Prototype functions</h4> </div> </li> <li id="section-20"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-20">&#x00a7;</a> </div> <p><code>calculateEffectiveTime</code> The <em><strong>effective time</strong></em> is the time, relative to the Tween/Action’s associated Ticker timeline, when the Tween/Action will start running</p> </div> <div class="content"><div class='highlight'><pre> P.<span class="hljs-property">calculateEffectiveTime</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">let</span> time = <span class="hljs-title function_">xtGet</span>(item, <span class="hljs-variable language_">this</span>.<span class="hljs-property">time</span>), calculatedTime = <span class="hljs-title function_">convertTime</span>(time), cTime = calculatedTime[<span class="hljs-number">1</span>], cType = calculatedTime[<span class="hljs-number">0</span>], ticker, tickerDuration = <span class="hljs-number">0</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">effectiveTime</span> = <span class="hljs-number">0</span>; <span class="hljs-keyword">if</span> (cType === <span class="hljs-string">&#x27;%&#x27;</span> &amp;&amp; cTime &lt;= <span class="hljs-number">100</span>) { <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span>) { ticker = animationtickers[<span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span>]; <span class="hljs-keyword">if</span> (ticker) { tickerDuration = ticker.<span class="hljs-property">effectiveDuration</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">effectiveTime</span> = tickerDuration * (cTime / <span class="hljs-number">100</span>); } } } <span class="hljs-keyword">else</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">effectiveTime</span> = cTime; <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">&#x00a7;</a> </div> <p><code>addToTicker</code></p> </div> <div class="content"><div class='highlight'><pre> P.<span class="hljs-property">addToTicker</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">let</span> tick; <span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(item)) { <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span> &amp;&amp; <span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span> !== item) <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">removeFromTicker</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span>); tick = animationtickers[item]; <span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(tick)) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span> = item; tick.<span class="hljs-title function_">subscribe</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">name</span>); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">calculateEffectiveTime</span>(); } } <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>; };</pre></div></div> </li> <li id="section-22"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-22">&#x00a7;</a> </div> <p><code>removeFromTicker</code></p> </div> <div class="content"><div class='highlight'><pre> P.<span class="hljs-property">removeFromTicker</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">let</span> tick; item = (<span class="hljs-title function_">xt</span>(item)) ? item : <span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span>; <span class="hljs-keyword">if</span> (item) { tick = animationtickers[item]; <span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(tick)) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span> = <span class="hljs-string">&#x27;&#x27;</span>; tick.<span class="hljs-title function_">unsubscribe</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">name</span>); } } <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>; };</pre></div></div> </li> <li id="section-23"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-23">&#x00a7;</a> </div> <p><code>setTargets</code></p> </div> <div class="content"><div class='highlight'><pre> P.<span class="hljs-property">setTargets</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items</span>) { items = [].<span class="hljs-title function_">concat</span>(items); <span class="hljs-keyword">let</span> newTargets = []; items.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> { <span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_fn</span>(item)) { <span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_fn</span>(item.<span class="hljs-property">set</span>)) newTargets.<span class="hljs-title function_">push</span>(item); } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_obj</span>(item) &amp;&amp; <span class="hljs-title function_">xt</span>(item.<span class="hljs-property">name</span>)) newTargets.<span class="hljs-title function_">push</span>(item); <span class="hljs-keyword">else</span> { <span class="hljs-keyword">let</span> result = <span class="hljs-title function_">locateTarget</span>(item); <span class="hljs-keyword">if</span> (result) newTargets.<span class="hljs-title function_">push</span>(result); } }); <span class="hljs-variable language_">this</span>.<span class="hljs-property">targets</span> = newTargets; <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</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><code>addToTargets</code></p> </div> <div class="content"><div class='highlight'><pre> P.<span class="hljs-property">addToTargets</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items</span>) { items = [].<span class="hljs-title function_">concat</span>(items); items.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> { <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> item === <span class="hljs-string">&#x27;function&#x27;</span>) { <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> item.<span class="hljs-property">set</span> === <span class="hljs-string">&#x27;function&#x27;</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">targets</span>.<span class="hljs-title function_">push</span>(item); } <span class="hljs-keyword">else</span> { result = <span class="hljs-title function_">locateTarget</span>(item); <span class="hljs-keyword">if</span> (result) <span class="hljs-variable language_">this</span>.<span class="hljs-property">targets</span>.<span class="hljs-title function_">push</span>(result); } }, <span class="hljs-variable language_">this</span>); <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</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><code>removeFromTargets</code></p> </div> <div class="content"><div class='highlight'><pre> P.<span class="hljs-property">removeFromTargets</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items</span>) { items = [].<span class="hljs-title function_">concat</span>(items); <span class="hljs-keyword">let</span> identifiers = [], newTargets = [].<span class="hljs-title function_">concat</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">targets</span>); newTargets.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">target</span> =&gt;</span> { <span class="hljs-keyword">let</span> type = target.<span class="hljs-property">type</span> || <span class="hljs-string">&#x27;unknown&#x27;</span>, name = target.<span class="hljs-property">name</span> || <span class="hljs-string">&#x27;unnamed&#x27;</span>; <span class="hljs-keyword">if</span> (type !== <span class="hljs-string">&#x27;unknown&#x27;</span> &amp;&amp; name !== <span class="hljs-string">&#x27;unnamed&#x27;</span>) identifiers.<span class="hljs-title function_">push</span>(<span class="hljs-string">`<span class="hljs-subst">${type}</span>_<span class="hljs-subst">${name}</span>`</span>); }); items.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> { <span class="hljs-keyword">let</span> myObj; <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> item === <span class="hljs-string">&#x27;function&#x27;</span>) myObj = item; <span class="hljs-keyword">else</span> myObj = <span class="hljs-title function_">locateTarget</span>(item); <span class="hljs-keyword">if</span> (myObj) { <span class="hljs-keyword">let</span> type = myObj.<span class="hljs-property">type</span> || <span class="hljs-string">&#x27;unknown&#x27;</span>, name = myObj.<span class="hljs-property">name</span> || <span class="hljs-string">&#x27;unnamed&#x27;</span>; <span class="hljs-keyword">if</span> (type !== <span class="hljs-string">&#x27;unknown&#x27;</span> &amp;&amp; name !== <span class="hljs-string">&#x27;unnamed&#x27;</span>) { <span class="hljs-keyword">let</span> objName = <span class="hljs-string">`<span class="hljs-subst">${type}</span>_<span class="hljs-subst">${name}</span>`</span>, doRemove = identifiers.<span class="hljs-title function_">indexOf</span>(objName); <span class="hljs-keyword">if</span> (doRemove &gt;= <span class="hljs-number">0</span>) newTargets[doRemove] = <span class="hljs-literal">false</span>; } } }); <span class="hljs-variable language_">this</span>.<span class="hljs-property">targets</span> = []; newTargets.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">target</span> =&gt;</span> { <span class="hljs-keyword">if</span> (target) <span class="hljs-variable language_">this</span>.<span class="hljs-property">targets</span>.<span class="hljs-title function_">push</span>(target); }, <span class="hljs-variable language_">this</span>); <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>; };</pre></div></div> </li> <li id="section-26"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-26">&#x00a7;</a> </div> <p><code>checkForTarget</code></p> </div> <div class="content"><div class='highlight'><pre> P.<span class="hljs-property">checkForTarget</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">if</span> (!item.<span class="hljs-property">substring</span>) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">targets</span>.<span class="hljs-title function_">some</span>(<span class="hljs-function"><span class="hljs-params">t</span> =&gt;</span> t.<span class="hljs-property">name</span> === item); }; P.<span class="hljs-property">run</span> = λ<span class="hljs-literal">null</span>; P.<span class="hljs-property">isRunning</span> = λ<span class="hljs-literal">null</span>; P.<span class="hljs-property">halt</span> = λ<span class="hljs-literal">null</span>; P.<span class="hljs-property">reverse</span> = λ<span class="hljs-literal">null</span>; P.<span class="hljs-property">resume</span> = λ<span class="hljs-literal">null</span>; P.<span class="hljs-property">seekTo</span> = λ<span class="hljs-literal">null</span>; P.<span class="hljs-property">seekFor</span> = λ<span class="hljs-literal">null</span>;</pre></div></div> </li> <li id="section-27"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-27">&#x00a7;</a> </div> <p>Return the prototype</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> P; };</pre></div></div> </li> </ul> </div> </body> </html>