UNPKG

scrawl-canvas

Version:
1,086 lines (712 loc) 85.9 kB
<!DOCTYPE html> <html> <head> <title>Tween factory</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <ul id="jump_to"> <li> <a class="large" href="javascript:void(0);">Jump To &hellip;</a> <a class="small" href="javascript:void(0);">+</a> <div id="jump_wrapper"> <div id="jump_page_wrapper"> <div id="jump_page"> <a class="source" href="../core/animationloop.html"> ./source/core/animationloop.js </a> <a class="source" href="../core/document.html"> ./source/core/document.js </a> <a class="source" href="../core/events.html"> ./source/core/events.js </a> <a class="source" href="../core/init.html"> ./source/core/init.js </a> <a class="source" href="../core/library.html"> ./source/core/library.js </a> <a class="source" href="../core/random-seed.html"> ./source/core/random-seed.js </a> <a class="source" href="../core/snippets.html"> ./source/core/snippets.js </a> <a class="source" href="../core/userInteraction.html"> ./source/core/userInteraction.js </a> <a class="source" href="../core/utilities.html"> ./source/core/utilities.js </a> <a class="source" href="action.html"> ./source/factory/action.js </a> <a class="source" href="anchor.html"> ./source/factory/anchor.js </a> <a class="source" href="animation.html"> ./source/factory/animation.js </a> <a class="source" href="bezier.html"> ./source/factory/bezier.js </a> <a class="source" href="block.html"> ./source/factory/block.js </a> <a class="source" href="canvas.html"> ./source/factory/canvas.js </a> <a class="source" href="cell.html"> ./source/factory/cell.js </a> <a class="source" href="cog.html"> ./source/factory/cog.js </a> <a class="source" href="color.html"> ./source/factory/color.js </a> <a class="source" href="conicGradient.html"> ./source/factory/conicGradient.js </a> <a class="source" href="coordinate.html"> ./source/factory/coordinate.js </a> <a class="source" href="crescent.html"> ./source/factory/crescent.js </a> <a class="source" href="element.html"> ./source/factory/element.js </a> <a class="source" href="emitter.html"> ./source/factory/emitter.js </a> <a class="source" href="filter.html"> ./source/factory/filter.js </a> <a class="source" href="filterEngine-bluenoiseData.html"> ./source/factory/filterEngine-bluenoiseData.js </a> <a class="source" href="filterEngine.html"> ./source/factory/filterEngine.js </a> <a class="source" href="fontAttributes.html"> ./source/factory/fontAttributes.js </a> <a class="source" href="gradient.html"> ./source/factory/gradient.js </a> <a class="source" href="grid.html"> ./source/factory/grid.js </a> <a class="source" href="group.html"> ./source/factory/group.js </a> <a class="source" href="imageAsset.html"> ./source/factory/imageAsset.js </a> <a class="source" href="line.html"> ./source/factory/line.js </a> <a class="source" href="lineSpiral.html"> ./source/factory/lineSpiral.js </a> <a class="source" href="loom.html"> ./source/factory/loom.js </a> <a class="source" href="mesh.html"> ./source/factory/mesh.js </a> <a class="source" href="net.html"> ./source/factory/net.js </a> <a class="source" href="noiseAsset.html"> ./source/factory/noiseAsset.js </a> <a class="source" href="oval.html"> ./source/factory/oval.js </a> <a class="source" href="palette.html"> ./source/factory/palette.js </a> <a class="source" href="particle.html"> ./source/factory/particle.js </a> <a class="source" href="particleForce.html"> ./source/factory/particleForce.js </a> <a class="source" href="particleHistory.html"> ./source/factory/particleHistory.js </a> <a class="source" href="particleSpring.html"> ./source/factory/particleSpring.js </a> <a class="source" href="particleWorld.html"> ./source/factory/particleWorld.js </a> <a class="source" href="pattern.html"> ./source/factory/pattern.js </a> <a class="source" href="phrase.html"> ./source/factory/phrase.js </a> <a class="source" href="picture.html"> ./source/factory/picture.js </a> <a class="source" href="polygon.html"> ./source/factory/polygon.js </a> <a class="source" href="polyline.html"> ./source/factory/polyline.js </a> <a class="source" href="quadratic.html"> ./source/factory/quadratic.js </a> <a class="source" href="quaternion.html"> ./source/factory/quaternion.js </a> <a class="source" href="radialGradient.html"> ./source/factory/radialGradient.js </a> <a class="source" href="rawAsset.html"> ./source/factory/rawAsset.js </a> <a class="source" href="rdAsset.html"> ./source/factory/rdAsset.js </a> <a class="source" href="rectangle.html"> ./source/factory/rectangle.js </a> <a class="source" href="renderAnimation.html"> ./source/factory/renderAnimation.js </a> <a class="source" href="shape.html"> ./source/factory/shape.js </a> <a class="source" href="spiral.html"> ./source/factory/spiral.js </a> <a class="source" href="spriteAsset.html"> ./source/factory/spriteAsset.js </a> <a class="source" href="stack.html"> ./source/factory/stack.js </a> <a class="source" href="star.html"> ./source/factory/star.js </a> <a class="source" href="state.html"> ./source/factory/state.js </a> <a class="source" href="tetragon.html"> ./source/factory/tetragon.js </a> <a class="source" href="ticker.html"> ./source/factory/ticker.js </a> <a class="source" href="tracer.html"> ./source/factory/tracer.js </a> <a class="source" href="tween.html"> ./source/factory/tween.js </a> <a class="source" href="unstackedElement.html"> ./source/factory/unstackedElement.js </a> <a class="source" href="vector.html"> ./source/factory/vector.js </a> <a class="source" href="videoAsset.html"> ./source/factory/videoAsset.js </a> <a class="source" href="wheel.html"> ./source/factory/wheel.js </a> <a class="source" href="../mixin/anchor.html"> ./source/mixin/anchor.js </a> <a class="source" href="../mixin/asset.html"> ./source/mixin/asset.js </a> <a class="source" href="../mixin/assetAdvancedFunctionality.html"> ./source/mixin/assetAdvancedFunctionality.js </a> <a class="source" href="../mixin/assetConsumer.html"> ./source/mixin/assetConsumer.js </a> <a class="source" href="../mixin/base.html"> ./source/mixin/base.js </a> <a class="source" href="../mixin/cascade.html"> ./source/mixin/cascade.js </a> <a class="source" href="../mixin/delta.html"> ./source/mixin/delta.js </a> <a class="source" href="../mixin/displayShape.html"> ./source/mixin/displayShape.js </a> <a class="source" href="../mixin/dom.html"> ./source/mixin/dom.js </a> <a class="source" href="../mixin/entity.html"> ./source/mixin/entity.js </a> <a class="source" href="../mixin/filter.html"> ./source/mixin/filter.js </a> <a class="source" href="../mixin/mimic.html"> ./source/mixin/mimic.js </a> <a class="source" href="../mixin/path.html"> ./source/mixin/path.js </a> <a class="source" href="../mixin/pattern.html"> ./source/mixin/pattern.js </a> <a class="source" href="../mixin/pivot.html"> ./source/mixin/pivot.js </a> <a class="source" href="../mixin/position.html"> ./source/mixin/position.js </a> <a class="source" href="../mixin/shapeBasic.html"> ./source/mixin/shapeBasic.js </a> <a class="source" href="../mixin/shapeCurve.html"> ./source/mixin/shapeCurve.js </a> <a class="source" href="../mixin/shapePathCalculation.html"> ./source/mixin/shapePathCalculation.js </a> <a class="source" href="../mixin/styles.html"> ./source/mixin/styles.js </a> <a class="source" href="../mixin/tween.html"> ./source/mixin/tween.js </a> </div> </div> </li> </ul> <ul class="sections"> <li id="section-1"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-1">&#x00a7;</a> </div> <h1 id="tween-factory">Tween factory</h1> <p>A <em><strong>tween</strong></em> - <em>inbetween animation</em> - is a small, targeted, time-limited animation where we define the start and end points (<em>key frames</em>) of the animation, and a method for calculating the intermediate values between the two (<em>interpolation</em>, using an <em>easing</em> function).</p> <p>Scrawl-canvas includes a full range of functionality to implement tweening. Any Scrawl-canvas object that includes a <code>set</code> function, which accepts a <code>{key:value}</code> object as its single argument, can be tweened.</p> <ul> <li>Tween animations are defined by creating a Tween object using the <code>makeTween</code> factory function.</li> <li>Each Tween object includes a <code>targets</code> Array - one Tween may animate many objects.</li> <li>Each Tween also includes a <code>definitions</code> Array which sets out the details of the animation to be performed.</li> <li>The <code>definitions</code> Array can include multiple objects, each defining a change to a specific attribute that needs to be applied to the target objects.</li> <li><strong>Any number-type attribute can be animated using a Tween</strong> - this includes integer and float Numbers, percentage Strings (<code>12.5%</code>) and measurement Strings (<code>20px</code>).</li> <li>We can run multiple Tween animations at the same time; Tweens can overlap (start one tween while another is running). </li> <li>We can dynamically halt, resume, restart and terminate Tweens in response to user interactions.</li> <li>Tweens include <code>packet</code> functionality: they can be saved, and cloned.</li> </ul> <p>Scrawl-canvas separates the timing aspects of its Tweens from their definitions.</p> <ul> <li>Tweens run against a <em><strong>timeline</strong></em> object called a <a href="./ticker.html">Ticker</a>.</li> <li>When we define a Tween, we can either assign it to an existing Ticker, or get the Tween factory to create a new Ticker for it.</li> <li>Tickers can also have <a href="./action.html">Action</a> objects assigned to them, allowing us to trigger functions at specific points along the timeline.</li> </ul> </div> </li> <li id="section-2"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-2">&#x00a7;</a> </div> <h5 id="using-other-tween-factories">Using other tween factories</h5> <p>We don’t recommend using other tween factories - such as <a href="https://greensock.com/">Greensock</a> - with Scrawl-canvas objects at this time.</p> <ul> <li>The reason is simple. All updates to Scrawl-canvas objects should be made through their dedicated <code>set</code>, <code>setDelta</code> and related functions, which take a single Javascript object as their argument.</li> <li>When attributes are updated in this way, Scrawl-canvas makes sure various <code>dirty</code> flags get set (among other work), so the object can update itself appropriately at the most convenient time for itself.</li> <li>Libraries like GSAP works by directly updating object attributes, which misses out the necessary work of setting the appropriate <code>dirty</code> flags - thus the object will not know that it needs to do work.</li> <li><em><strong>This does not mean you can’t use other tween libraries in your web page</strong></em> - just be aware of the limitations of trying to use them with Scrawl-canvas objects!</li> </ul> </div> </li> <li id="section-3"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-3">&#x00a7;</a> </div> <p>TODO: basic packet and kill functionality tested in Demo DOM-004, but there’s a lot of Ticker/Tween/Action functionality that needs to be explored and tested further (see <a href="./ticker.html#section-2">Ticker TODO section</a> for issues and suggested work).</p> </div> </li> <li id="section-4"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-4">&#x00a7;</a> </div> <h4 id="demos">Demos:</h4> <ul> <li><a href="../../demo/canvas-005.html">Canvas-005</a> - Cell-locked, and Entity-locked, gradients; animating gradients by delta, and by tween</li> <li><a href="../../demo/canvas-006.html">Canvas-006</a> - Canvas tween stress test</li> <li><a href="../../demo/dom-004.html">DOM-004</a> - Limitless rockets (clone and destroy elements, tweens, tickers)</li> <li><a href="../../demo/dom-005.html">DOM-005</a> - DOM tween stress test</li> <li><a href="../../demo/dom-006.html">DOM-006</a> - Tween actions on a DOM element; tracking tween and ticker activity (analytics)</li> <li><a href="../../demo/snippets-001.html">Snippets-001</a> - Scrawl-canvas DOM element snippets</li> </ul> </div> </li> <li id="section-5"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-5">&#x00a7;</a> </div> <h4 id="imports">Imports</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { constructors, animationtickers, radian } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/library.js&#x27;</span>; <span class="hljs-keyword">import</span> { mergeOver, pushUnique, xt, xtGet, xto, convertTime, λ<span class="hljs-literal">null</span>, easeEngines, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/utilities.js&#x27;</span>; <span class="hljs-keyword">import</span> { makeTicker } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./ticker.js&#x27;</span>; <span class="hljs-keyword">import</span> baseMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/base.js&#x27;</span>; <span class="hljs-keyword">import</span> tweenMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/tween.js&#x27;</span>;</pre></div></div> </li> <li id="section-6"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-6">&#x00a7;</a> </div> <h4 id="tween-constructor">Tween constructor</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">Tween</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) { <span class="hljs-keyword">let</span> tn; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">makeName</span>(items.<span class="hljs-property">name</span>); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">register</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">set</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">set</span>(items); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setDefinitionsValues</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><code>status</code> magic numbers: <code>-1</code> = “before”; <code>0</code> = “running”; <code>1</code> = “after”.</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-variable language_">this</span>.<span class="hljs-property">status</span> = -<span class="hljs-number">1</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">calculateEffectiveTime</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">calculateEffectiveDuration</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>All Tweens require a Ticker to act as their timeline.</p> <ul> <li>If no Ticker attribute is included in the argument object, or the Ticker cannot be located, a new Ticker will be created for this Tween.</li> </ul> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (animationtickers[items.<span class="hljs-property">ticker</span>]) <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">addToTicker</span>(items.<span class="hljs-property">ticker</span>); <span class="hljs-keyword">else</span> { tn = <span class="hljs-string">`<span class="hljs-subst">${<span class="hljs-variable language_">this</span>.name}</span>_ticker`</span>; <span class="hljs-title function_">makeTicker</span>({ <span class="hljs-attr">name</span>: tn, <span class="hljs-attr">order</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">order</span>, <span class="hljs-attr">subscribers</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">name</span>, <span class="hljs-attr">duration</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">effectiveDuration</span>, <span class="hljs-attr">eventChoke</span>: <span class="hljs-title function_">xtGet</span>(items.<span class="hljs-property">eventChoke</span>, <span class="hljs-number">0</span>), <span class="hljs-attr">cycles</span>: <span class="hljs-title function_">xtGet</span>(items.<span class="hljs-property">cycles</span>, <span class="hljs-number">1</span>), <span class="hljs-attr">killOnComplete</span>: <span class="hljs-title function_">xtGet</span>(items.<span class="hljs-property">killOnComplete</span>, <span class="hljs-literal">false</span>) }); <span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span> = tn; animationtickers[tn].<span class="hljs-title function_">recalculateEffectiveDuration</span>(); } <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>; };</pre></div></div> </li> <li id="section-9"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-9">&#x00a7;</a> </div> <h4 id="tween-prototype">Tween prototype</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> P = <span class="hljs-title class_">Tween</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span> = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">create</span>(<span class="hljs-title class_">Object</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>); P.<span class="hljs-property">type</span> = <span class="hljs-string">&#x27;Tween&#x27;</span>; P.<span class="hljs-property">lib</span> = <span class="hljs-string">&#x27;tween&#x27;</span>; P.<span class="hljs-property">isArtefact</span> = <span class="hljs-literal">false</span>; P.<span class="hljs-property">isAsset</span> = <span class="hljs-literal">false</span>;</pre></div></div> </li> <li id="section-10"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-10">&#x00a7;</a> </div> <h4 id="mixins">Mixins</h4> </div> <div class="content"><div class='highlight'><pre>P = <span class="hljs-title function_">baseMix</span>(P); P = <span class="hljs-title function_">tweenMix</span>(P);</pre></div></div> </li> <li id="section-11"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-11">&#x00a7;</a> </div> <h4 id="tween-attributes">Tween attributes</h4> <ul> <li>Attributes defined in the <a href="../mixin/base.html">base mixin</a>: <strong>name</strong>.</li> <li>Attributes defined in the <a href="../mixin/tween.html">tween mixin</a>: <strong>order</strong>, <strong>ticker</strong>, <strong>targets</strong>, <strong>time</strong>, <strong>action</strong>, <strong>reverseOnCycleEnd</strong>, <strong>reversed</strong>.</li> </ul> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> defaultAttributes = {</pre></div></div> </li> <li id="section-12"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-12">&#x00a7;</a> </div> <p><strong>definitions</strong> - Array of objects defining the animations to be performed by the Tween. Object attributes include:</p> <ul> <li><strong>attribute</strong> (required) - String attribute key.</li> <li><strong>start</strong> - Number or String value for this attribute’s start point.</li> <li><strong>end</strong> - Number or String value for this attribute’s end point.</li> <li><strong>integer</strong> - Boolean flag indicating whether we should force results to be integers (default: false)</li> <li><strong>engine</strong> - String name for the easing function <em><strong>engine</strong></em> to be used to animate this change; or an easing function supplied by the developer.</li> </ul> <p>Scrawl-canvas includes functionality to allow <code>start</code> and <code>end</code> values to be defined as Strings, with a measurement suffix (<code>%</code>, <code>px</code>, etc) attached to the number. </p> <ul> <li>These values should be of a type that the target object (generally an artefact) expects to receive in its <code>set</code> function.</li> <li>Any object with a <code>set</code> function that takes an object as its argument can be tweened.</li> </ul> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">definitions</span>: <span class="hljs-literal">null</span>,</pre></div></div> </li> <li id="section-13"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-13">&#x00a7;</a> </div> <p><strong>duration</strong> - can accept a variety of values:</p> <ul> <li>Number, representing milliseconds.</li> <li>String time value, for example <code>&#39;500ms&#39;, &#39;0.5s&#39;</code>.</li> <li>% String value - <code>20%</code> - a relative value measured against the Ticker’s <em><strong>effective duration</strong></em>. For example, if the Ticker has an effective duration of 5000 (5 seconds), and the Tween wants to run for 20% of that time, the Tween’s effective duration will be 1000 (1 second).</li> </ul> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">duration</span>: <span class="hljs-number">0</span>,</pre></div></div> </li> <li id="section-14"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-14">&#x00a7;</a> </div> <p><strong>killOnComplete</strong> - Boolean flag; if set, the Tween will kill itself when it completes</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">killOnComplete</span>: <span class="hljs-literal">false</span>,</pre></div></div> </li> <li id="section-15"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-15">&#x00a7;</a> </div> <p>The Tween object supports some <strong>tween animation hook functions</strong>:</p> <ul> <li><strong>commenceAction</strong> - runs immediately before the Tween’s <code>run</code> function is invoked</li> <li><strong>onRun</strong> - triggers immediately after the Tween’s <code>run</code> function is invoked</li> <li><strong>onHalt</strong> - triggers immediately after the Tween’s <code>halt</code> function is invoked</li> <li><strong>onResume</strong> - triggers immediately after the Tween’s <code>resume</code> function is invoked</li> <li><strong>onReverse</strong> - triggers immediately after the Tween’s <code>reverse</code> function is invoked</li> <li><strong>onSeekTo</strong> - triggers immediately after the Tween’s <code>seekTo</code> function is invoked</li> <li><strong>onSeekFor</strong> - triggers immediately after the Tween’s <code>seekFor</code> function is invoked</li> <li><strong>completeAction</strong> - triggers after the Tween completes its run</li> </ul> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">commenceAction</span>: <span class="hljs-literal">null</span>, <span class="hljs-attr">onRun</span>: <span class="hljs-literal">null</span>, <span class="hljs-attr">onHalt</span>: <span class="hljs-literal">null</span>, <span class="hljs-attr">onResume</span>: <span class="hljs-literal">null</span>, <span class="hljs-attr">onReverse</span>: <span class="hljs-literal">null</span>, <span class="hljs-attr">onSeekTo</span>: <span class="hljs-literal">null</span>, <span class="hljs-attr">onSeekFor</span>: <span class="hljs-literal">null</span>, <span class="hljs-attr">completeAction</span>: <span class="hljs-literal">null</span>,</pre></div></div> </li> <li id="section-16"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-16">&#x00a7;</a> </div> <p><strong>ticker</strong> - String name of Ticker object which this Tween will associate itself with.</p> <ul> <li>If no Ticker is specified when building a new Tween, it will create a new Ticker object (sharing its <code>name</code> attribute) to associate with. </li> <li>If the attributes below are included in the argument object, they will be passed on to the new Ticker.</li> <li>This attribute is kept in the Tween object, but is excluded from the Tween prototype’s <code>defs</code> object.</li> </ul> </div> </li> <li id="section-17"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-17">&#x00a7;</a> </div> <p>The following <a href="./ticker.html">Ticker</a>-related attributes are not stored in the Tween object:</p> <ul> <li><strong>cycles</strong> - positive integer Number representing the number of cycles the Ticker will undertake before it completes.</li> <li><strong>eventChoke</strong> Number representing minimum number of milliseconds between Ticker event emissions</li> </ul> </div> <div class="content"><div class='highlight'><pre> }; P.<span class="hljs-property">defs</span> = <span class="hljs-title function_">mergeOver</span>(P.<span class="hljs-property">defs</span>, defaultAttributes);</pre></div></div> </li> <li id="section-18"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-18">&#x00a7;</a> </div> <h4 id="packet-management">Packet management</h4> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">packetExclusions</span> = <span class="hljs-title function_">pushUnique</span>(P.<span class="hljs-property">packetExclusions</span>, [<span class="hljs-string">&#x27;definitions&#x27;</span>, <span class="hljs-string">&#x27;targets&#x27;</span>]); P.<span class="hljs-property">packetFunctions</span> = <span class="hljs-title function_">pushUnique</span>(P.<span class="hljs-property">packetFunctions</span>, [<span class="hljs-string">&#x27;commenceAction&#x27;</span>, <span class="hljs-string">&#x27;completeAction&#x27;</span>, <span class="hljs-string">&#x27;onRun&#x27;</span>, <span class="hljs-string">&#x27;onHalt&#x27;</span>, <span class="hljs-string">&#x27;onResume&#x27;</span>, <span class="hljs-string">&#x27;onReverse&#x27;</span>, <span class="hljs-string">&#x27;onSeekTo&#x27;</span>, <span class="hljs-string">&#x27;onSeekFor&#x27;</span>, <span class="hljs-string">&#x27;action&#x27;</span>]); 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> (<span class="hljs-title class_">Array</span>.<span class="hljs-title function_">isArray</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">targets</span>)) copy.<span class="hljs-property">targets</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">targets</span>.<span class="hljs-title function_">map</span>(<span class="hljs-function"><span class="hljs-params">t</span> =&gt;</span> t.<span class="hljs-property">name</span>); <span class="hljs-keyword">if</span> (<span class="hljs-title class_">Array</span>.<span class="hljs-title function_">isArray</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">definitions</span>)) { copy.<span class="hljs-property">definitions</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">definitions</span>.<span class="hljs-title function_">map</span>(<span class="hljs-function"><span class="hljs-params">d</span> =&gt;</span> { <span class="hljs-keyword">let</span> res = {}; res.<span class="hljs-property">attribute</span> = d.<span class="hljs-property">attribute</span>; res.<span class="hljs-property">start</span> = d.<span class="hljs-property">start</span>; res.<span class="hljs-property">end</span> = d.<span class="hljs-property">end</span>; <span class="hljs-keyword">if</span> (d.<span class="hljs-property">engine</span> &amp;&amp; d.<span class="hljs-property">engine</span>.<span class="hljs-property">substring</span>) res.<span class="hljs-property">engine</span> = d.<span class="hljs-property">engine</span>.<span class="hljs-property">substring</span>; <span class="hljs-keyword">else</span> { <span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(d.<span class="hljs-property">engine</span>) &amp;&amp; d.<span class="hljs-property">engine</span> !== <span class="hljs-literal">null</span>) { <span class="hljs-keyword">let</span> e = <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">stringifyFunction</span>(d.<span class="hljs-property">engine</span>); <span class="hljs-keyword">if</span> (e) { res.<span class="hljs-property">engine</span> = e; res.<span class="hljs-property">engineIsFunction</span> = <span class="hljs-literal">true</span>; } } } <span class="hljs-keyword">return</span> res; }); } <span class="hljs-keyword">return</span> copy; };</pre></div></div> </li> <li id="section-19"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-19">&#x00a7;</a> </div> <h4 id="clone-management">Clone management</h4> <p>When cloning a ticker, we can use an additional attribute in the clone function’s argument object:</p> <ul> <li><strong>useNewTicker</strong> - Boolean flag - when set, the clone will also create its own Ticker object</li> </ul> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">postCloneAction</span> = <span class="hljs-keyword">function</span>(<span class="hljs-params">clone, items</span>) { <span class="hljs-keyword">if</span> (items.<span class="hljs-property">useNewTicker</span>) { <span class="hljs-keyword">let</span> ticker = animationtickers[<span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span>]; <span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(items.<span class="hljs-property">cycles</span>)) clone.<span class="hljs-property">cycles</span> = items.<span class="hljs-property">cycles</span>; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (ticker) clone.<span class="hljs-property">cycles</span> = ticker.<span class="hljs-property">cycles</span>; <span class="hljs-keyword">else</span> clone.<span class="hljs-property">cycles</span> = <span class="hljs-number">1</span>; <span class="hljs-keyword">let</span> cloneTicker = animationtickers[clone.<span class="hljs-property">ticker</span>]; cloneTicker.<span class="hljs-property">cycles</span> = clone.<span class="hljs-property">cycles</span>; <span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(items.<span class="hljs-property">duration</span>)) { clone.<span class="hljs-property">duration</span> = items.<span class="hljs-property">duration</span>; clone.<span class="hljs-title function_">calculateEffectiveDuration</span>(); <span class="hljs-keyword">if</span> (cloneTicker) cloneTicker.<span class="hljs-title function_">recalculateEffectiveDuration</span>(); } } <span class="hljs-keyword">if</span> (<span class="hljs-title class_">Array</span>.<span class="hljs-title function_">isArray</span>(clone.<span class="hljs-property">definitions</span>)) { clone.<span class="hljs-property">definitions</span>.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">def, index</span>) =&gt;</span> { <span class="hljs-keyword">if</span> (def.<span class="hljs-property">engineIsFunction</span>) def.<span class="hljs-property">engine</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">definitions</span>[index].<span class="hljs-property">engine</span>; }); } <span class="hljs-keyword">return</span> clone; };</pre></div></div> </li> <li id="section-20"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-20">&#x00a7;</a> </div> <h4 id="kill-management">Kill management</h4> <p>No additional kill functionality required</p> <ul> <li>Tweens have the ability to auto-destruct when they complete their run, if their <code>killOnComplete</code> flag has been set to <code>true</code>.</li> </ul> </div> </li> <li id="section-21"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-21">&#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-22"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-22">&#x00a7;</a> </div> <p><strong>definitions</strong></p> </div> <div class="content"><div class='highlight'><pre>G.<span class="hljs-property">definitions</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">definitions</span>); }; S.<span class="hljs-property">definitions</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">definitions</span> = [].<span class="hljs-title function_">concat</span>(item); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setDefinitionsValues</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><strong>commenceAction</strong></p> </div> <div class="content"><div class='highlight'><pre>S.<span class="hljs-property">commenceAction</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">commenceAction</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">commenceAction</span> !== <span class="hljs-string">&#x27;function&#x27;</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">commenceAction</span> = λ<span class="hljs-literal">null</span>; };</pre></div></div> </li> <li id="section-24"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-24">&#x00a7;</a> </div> <p><strong>completeAction</strong></p> </div> <div class="content"><div class='highlight'><pre>S.<span class="hljs-property">completeAction</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">completeAction</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">completeAction</span> !== <span class="hljs-string">&#x27;function&#x27;</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">completeAction</span> = λ<span class="hljs-literal">null</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>set</code> - we perform some additional functionality in the Tween <code>set</code> function</p> <ul> <li>updating the Tween’s Ticker object happens here</li> <li>recalculating effectiveDuration happens here if the <strong>time</strong> or <strong>duration</strong> values change</li> </ul> </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> key, i, iz, s, setters = <span class="hljs-variable language_">this</span>.<span class="hljs-property">setters</span>, keys = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">keys</span>(items), d = <span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>, ticker = (<span class="hljs-title function_">xt</span>(items.<span class="hljs-property">ticker</span>)) ? <span class="hljs-variable language_">this</span>.<span class="hljs-property">ticker</span> : <span class="hljs-literal">false</span>; <span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>, iz = keys.<span class="hljs-property">length</span>; i &lt; iz; i++) { key = keys[i]; <span class="hljs-keyword">if</span> (key !== <span class="hljs-string">&#x27;name&#x27;</span>) { s = setters[key]; <span class="hljs-keyword">if</span> (s) s.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>, items[key]); <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> d[key] !== <span class="hljs-st