/**
* @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/almond for details
*/
/*
Copyright 2015 Norut Northern Research Institute
Author : Ingar Mæhlum Arntzen
This file is part of the Timingsrc module.
Timingsrc is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Timingsrc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Timingsrc. If not, see .
*/
/*
Copyright 2015 Norut Northern Research Institute
Author : Ingar Mæhlum Arntzen
This file is part of the Timingsrc module.
Timingsrc is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Timingsrc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Timingsrc. If not, see .
*/
/*
Copyright 2017 Norut Northern Research Institute
Author : Ingar Mæhlum Arntzen
This file is part of the Timingsrc module.
Timingsrc is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Timingsrc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Timingsrc. If not, see .
*/
(function(e,t){typeof define=="function"&&define.amd?define([],t):e.TIMINGSRC=t()})(this,function(){var e,t,n;return function(r){function v(e,t){return h.call(e,t)}function m(e,t){var n,r,i,s,o,u,a,f,c,h,p,v=t&&t.split("/"),m=l.map,g=m&&m["*"]||{};if(e&&e.charAt(0)===".")if(t){e=e.split("/"),o=e.length-1,l.nodeIdCompat&&d.test(e[o])&&(e[o]=e[o].replace(d,"")),e=v.slice(0,v.length-1).concat(e);for(c=0;c0&&(e.splice(c-1,2),c-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((v||g)&&m){n=e.split("/");for(c=n.length;c>0;c-=1){r=n.slice(0,c).join("/");if(v)for(h=v.length;h>0;h-=1){i=m[v.slice(0,h).join("/")];if(i){i=i[r];if(i){s=i,u=c;break}}}if(s)break;!a&&g&&g[r]&&(a=g[r],f=c)}!s&&a&&(s=a,u=f),s&&(n.splice(0,u,s),e=n.join("/"))}return e}function g(e,t){return function(){var n=p.call(arguments,0);return typeof n[0]!="string"&&n.length===1&&n.push(null),s.apply(r,n.concat([e,t]))}}function y(e){return function(t){return m(t,e)}}function b(e){return function(t){a[e]=t}}function w(e){if(v(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!v(a,e)&&!v(c,e))throw new Error("No "+e);return a[e]}function E(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function S(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice,d=/\.js$/;o=function(e,t){var n,r=E(e),i=r[0];return e=r[1],i&&(i=m(i,t),n=w(i)),i?n&&n.normalize?e=n.normalize(e,y(t)):e=m(e,t):(e=m(e,t),r=E(e),i=r[0],e=r[1],i&&(n=w(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return g(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:S(e)}}},i=function(e,t,n,i){var s,l,h,p,d,m=[],y=typeof n,E;i=i||e;if(y==="undefined"||y==="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(d=0;d0?n[0]:-1},i.prototype.getItem=function(e){return this._map[e]},i.prototype.register=function(e,t){var n=this._getID(e);if(n>-1)throw new Error("handler already registered");return n=this._newID(),this._map[n]={ID:n,handler:e,ctx:t,count:0,pending:!1},n},i.prototype.unregister=function(e){var t=this._getID(e);t!==-1&&delete this._map[t]},i.prototype.getItems=function(){return Object.keys(this._map).map(function(e){return this.getItem(e)},this)};var s=function(t){return t._ID=e(4),t._callbacks={},t._immediateCallbacks=[],t._eBuffer=[],t._callbacks.events=new i,t._callbacks.events._options={init:!0},t},o=function(e){e.eventifyDefineEvent=function(e,t){if(e==="events")throw new Error("Illegal event type : 'events' is protected");t=t||{},t.init=t.init===undefined?!1:t.init,this._callbacks[e]=new i,this._callbacks[e]._options=t},e._eventifyMakeEItemList=function(e){var t=this.eventifyMakeInitEvents||function(e){return[]};return t.call(this,e).map(function(t){return{type:e,e:t}})},e._eventifyMakeInitEvents=function(e){if(e!=="events")return this._eventifyMakeEItemList(e);var n=Object.keys(this._callbacks).filter(function(e){return e!=="events"&&this._callbacks[e]._options.init===!0},this);return t(n,function(e){return this._eventifyMakeEItemList(e)},this)},e._eventifyEventFormatter=function(e,t){var n=this.eventifyEventFormatter||function(e,t){return t};return e==="events"&&(t=t.map(function(e){return{type:e.type,e:n(e.type,e.e)}})),n(e,t)},e._eventifyCallbackFormatter=function(e,t,n){var r=this.eventifyCallbackFormatter||function(e,t,n){return[t]};return r.call(this,e,t,n)},e.eventifyTriggerEvents=function(e){e.forEach(function(e){if(e.type===undefined)throw new Error("Illegal event type; undefined");if(e.type==="events")throw new Error("Illegal event type; triggering of events on protocted event type 'events'")},this);if(e.length===0)return this;this._eBuffer.push.apply(this._eBuffer,e);if(this._eBuffer.length===e.length){var t=this;Promise.resolve().then(function(){t._eventifyTriggerProtectedEvents(t._eBuffer),t._eventifyTriggerRegularEvents(t._eBuffer),t._eBuffer=[],t._eventifyFlushImmediateCallbacks()})}return this},e.eventifyTriggerEvent=function(e,t){return this.eventifyTriggerEvents([{type:e,e:t}])},e._eventifyTriggerProtectedEvents=function(e,t){this._eventifyTriggerEvent("events",e,t)},e._eventifyTriggerRegularEvents=function(e,t){e.forEach(function(e){this._eventifyTriggerEvent(e.type,e.e,t)},this)},e._eventifyTriggerEvent=function(e,t,n){var r,t,i={};if(!this._callbacks.hasOwnProperty(e))throw new Error("Unsupported event type "+e);var s=this._callbacks[e],o=s._options.init;return s.getItems().forEach(function(s){if(n===undefined){if(s.pending)return!1}else{if(s.ID!==n)return!1;i.init=!0,s.pending=!1}o&&(i.init=s.ID===n?!0:!1),i.count=s.count,i.src=this,t=this._eventifyEventFormatter(e,t),r=this._eventifyCallbackFormatter(e,t,i);try{return s.handler.apply(s.ctx,r),s.count+=1,!0}catch(u){console.log("Error in "+e+": "+s.handler+" "+s.ctx+": ",u)}},this),!1},e.on=function(e,t,n){if(!t||typeof t!="function")throw new Error("Illegal handler");if(!this._callbacks.hasOwnProperty(e))throw new Error("Unsupported event type "+e);var r=this._callbacks[e];n=n||this;var i=r.register(t,n);if(r._options.init){var s=r.getItem(i);s.pending=!0;var o=this,u=function(){var t=o._eventifyMakeInitEvents(e);t.length>0?e==="events"?o._eventifyTriggerProtectedEvents(t,i):o._eventifyTriggerRegularEvents(t,i):s.pending=!1};this._immediateCallbacks.push(u),Promise.resolve().then(function(){o._eventifyFlushImmediateCallbacks()})}return this},e._eventifyFlushImmediateCallbacks=function(){if(this._eBuffer.length===0){var e=this._immediateCallbacks;this._immediateCallbacks=[],e.forEach(function(e){e()})}},e.off=function(e,t){if(this._callbacks[e]!==undefined){var n=this._callbacks[e];n.unregister(t)}return this}},u=function(){s(this)};o(u.prototype),u.inherit=n;var a=function(e,t){if(!(this instanceof a))throw new Error("Contructor function called without new operation");u.call(this),this._value=e?!0:!1,this.eventifyDefineEvent("change",t)};u.inherit(a,u),a.prototype.eventifyMakeInitEvents=function(e){return e==="change"?[this._value]:[]},Object.defineProperty(a.prototype,"value",{get:function(){return this._value},set:function(e){return this.set(e)}}),a.prototype.get=function(){return this._value},a.prototype.set=function(e){return e=e?!0:!1,e!==this._value?(this._value=e,this.eventifyTriggerEvent("change",e),!0):!1},a.prototype.toggle=function(){var e=!this._value;return this._value=e,this.eventifyTriggerEvent("change",e),!0};var f=function(e,t){t=t||{},t.eqFunc=t.eqFunc||r,this._options=t,u.call(this),this._value=e,this._src,this.eventifyDefineEvent("change",t);var n=this;this._onSrcChange=function(e){n.set(e)}};u.inherit(f,u),f.prototype.eventifyMakeInitEvents=function(e){return e==="change"?[this._value]:[]},Object.defineProperty(f.prototype,"value",{get:function(){return this._value},set:function(e){this._src===undefined?this.set(e):this._src.value=e}}),Object.defineProperty(f.prototype,"src",{get:function(){return this._src},set:function(e){this._src&&this._src.off("change",this._onSrcChange),this._src=e,this._src.on("change",this._onSrcChange)}}),f.prototype.get=function(){return this._value},f.prototype.set=function(e){var t=this._options.eqFunc;return t(e,this._value)?!1:(this._value=e,this.eventifyTriggerEvent("change",e),!0)};var l=function(e,t){return t=t!==undefined?t:!0,new Promise(function(n,r){var i=function(r){r===t&&(n(),e.off("change",i))};e.on("change",i)})};return{eventifyPrototype:o,eventifyInstance:s,BaseEventObject:u,EventVariable:f,EventBoolean:a,makeEventPromise:l}}),n("util/motionutils",[],function(){"use strict";(function(){function e(e,t,n){return typeof n=="undefined"||+n===0?Math[e](t):(t=+t,n=+n,isNaN(t)||typeof n!="number"||n%1!==0?NaN:(t=t.toString().split("e"),t=Math[e](+(t[0]+"e"+(t[1]?+t[1]-n:-n))),t=t.toString().split("e"),+(t[0]+"e"+(t[1]?+t[1]+n:n))))}Math.round10||(Math.round10=function(t,n){return e("round",t,n)}),Math.floor10||(Math.floor10=function(t,n){return e("floor",t,n)}),Math.ceil10||(Math.ceil10=function(t,n){return e("ceil",t,n)})})();var e=function(e,t){if(t===undefined)throw new Error("no ts provided for calculateVector");var n=t-e.timestamp;return{position:e.position+e.velocity*n+.5*e.acceleration*n*n,velocity:e.velocity+e.acceleration*n,acceleration:e.acceleration,timestamp:t}},t=Object.freeze({INIT:"init",INSIDE:"inside",OUTSIDE_LOW:"outsidelow",OUTSIDE_HIGH:"outsidehigh"}),n=function(e,n){var r=e.position,i=e.velocity,s=e.acceleration;if(r>n[1])return t.OUTSIDE_HIGH;if(r0)return t.OUTSIDE_HIGH;if(i===0&&s>0)return t.OUTSIDE_HIGH}else if(r===n[0]){if(i<0)return t.OUTSIDE_LOW;if(i==0&&s<0)return t.OUTSIDE_HIGH}return t.INSIDE},r=function(e,r){var i=n(e,r);return i!==t.INSIDE&&(e.velocity=0,e.acceleration=0,i===t.OUTSIDE_HIGH?e.position=r[1]:e.position=r[0]),e},i=function(e,t){if(e>t)return 1;if(e===t)return 0;if(e=0?!0:!1},u=function(e,t,n,r){if(n===0&&t===0)return e!=r?[]:[0];if(n===0)return[(r-e)/t];if(o(e,t,n,r)===!1)return[];var i=t*t-2*n*(e-r);if(i===0)return[-t/n];var s=Math.sqrt(Math.pow(t,2)-2*n*(e-r)),u=(-t+s)/n,a=(-t-s)/n;return[Math.min(u,a),Math.max(u,a)]},a=function(e,t,n,r){var i=u(e,t,n,r);return i.length===0?[]:i.length==1?i[0]>0?[i[0]]:[]:i.length==2?i[1]<0?[]:i[0]>0?[i[0],i[1]]:i[1]>0?[i[1]]:[]:[]},f=function(e,t){var n=e.position,r=e.velocity,i=e.acceleration,s=a(n,r,i,t);return s.length===0?null:s[0]},l=function(e,t){var n=f(e,t[0]),r=f(e,t[1]);return n!==null&&r!==null?n0?[u,Math.max(n,s)]:[Math.min(n,s),u]}}return[Math.min(n,s),Math.max(n,s)]};return{calculateVector:e,calculateDirection:s,calculateMinPositiveRealSolution:f,calculateDelta:l,calculateInterval:v,calculateSolutionsInInterval:p,calculateSolutionsInInterval2:h,getCorrectRangeState:n,checkRange:r,RangeState:t}}),n("util/timeoututils",[],function(){"use strict";var e=function(e,t,n,r){this._clock=e;var i=this._clock.now();this._tid=null,this._callback=t,this._delay_counter=0,this._options=r||{},this._options.anchor=this._options.anchor||i,this._options.early=Math.abs(this._options.early)||0,this._target=this._options.anchor+n;var s=this;window.addEventListener("message",this,!0);var o=this._target-this._clock.now();o>10?this._tid=setTimeout(function(){s._ontimeout()},o-3e3):this._tid=setTimeout(function(){s._ontimeout()},(o-s._options.early)*1e3)};return Object.defineProperty(e.prototype,"target",{get:function(){return this._target}}),e.prototype._ontimeout=function(){if(this._tid!==null){var e=this._target-this._clock.now();if(e<=0)this.cancel(),this._callback();else if(e>this._options.early){var t=this;this._tid=setTimeout(function(){t._ontimeout()},(e-this._options.early)*1e3)}else this._smalldelay()}},e.prototype.handleEvent=function(e){if(e.source===window&&e.data.indexOf("smalldelaymsg_")===0){e.stopPropagation();var t=parseInt(e.data.split("_")[1]);this._tid!==null&&this._tid===t&&this._ontimeout()}},e.prototype._smalldelay=function(){this._delay_counter++;var e=this;window.postMessage("smalldelaymsg_"+e._tid,"*")},e.prototype.cancel=function(){if(this._tid!==null){clearTimeout(this._tid),this._tid=null;var e=this;window.removeEventListener("message",this,!0)}},{setTimeout:function(t,n,r,i){return new e(t,n,r,i)}}}),n("util/masterclock",["./eventify","./timeoututils"],function(e,t){"use strict";(function(){"performance"in window==0&&(window.performance={},window.performance.offset=(new Date).getTime()),"now"in window.performance==0&&(window.performance.now=function(){return(new Date).getTime()-window.performance.offset})})();var n={now:function(){return performance.now()/1e3}},r=function(e,t){t===undefined&&(t=n.now());var r=t-e.timestamp;return{position:e.position+e.velocity*r,velocity:e.velocity,timestamp:t}},i=function(t){var r=n.now();t=t||{},this._vector={position:r,velocity:1,timestamp:r},e.eventifyInstance(this),this.eventifyDefineEvent("change"),this.adjust(t)};return e.eventifyPrototype(i.prototype),i.prototype.adjust=function(e){e=e||{};var t=n.now(),r=this.query(t);if(e.skew===undefined&&e.rate===undefined)return;this._vector={position:e.skew!==undefined?t+e.skew:r.position,velocity:e.rate!==undefined?e.rate:r.velocity,timestamp:r.timestamp},this.eventifyTriggerEvent("change")},i.prototype.now=function(){return r(this._vector,n.now()).position},i.prototype.query=function(e){return r(this._vector,e)},i.prototype.setTimeout=function(e,n,r){return t.setTimeout(this,e,n,r)},i}),n("timingobject/timingobject",["../util/eventify","../util/motionutils","../util/masterclock"],function(e,t,n){"use strict";var r=function(e,t){var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.uber=t.prototype,e.prototype.constructor=e};(function(){"performance"in window==0&&(window.performance={},window.performance.offset=(new Date).getTime()),"now"in window.performance==0&&(window.performance.now=function(){return(new Date).getTime()-window.performance.offset})})();var i=function(t){this._options=t||{},this._vector={position:undefined,velocity:undefined,acceleration:undefined,timestamp:undefined},this._event_variables=[],this._range=[undefined,undefined],this._ready=new e.EventBoolean(!1,{init:!0}),e.eventifyInstance(this),this.eventifyDefineEvent("change",{init:!0}),this.eventifyDefineEvent("timeupdate",{init:!0}),this._timeout=null,this._tid=null,this._options.hasOwnProperty("timeout")||(this._options.timeout=!1)};e.eventifyPrototype(i.prototype),i.prototype.eventifyMakeInitEvents=function(e){return e==="change"?this._ready.value===!0?[undefined]:[]:e==="timeupdate"?this._ready.value===!0?[undefined]:[]:[]},Object.defineProperty(i.prototype,"version",{get:function(){return this._version}}),i.prototype.isReady=function(){return this._ready.value},Object.defineProperty(i.prototype,"ready",{get:function(){var e=this;return new Promise(function(t,n){if(e._ready.value===!0)t();else{var r=function(){e._ready.value===!0&&(e._ready.off("change",r),t())};e._ready.on("change",r)}})}}),Object.defineProperty(i.prototype,"range",{get:function(){return[this._range[0],this._range[1]]}}),Object.defineProperty(i.prototype,"vector",{get:function(){return{position:this._vector.position,velocity:this._vector.velocity,acceleration:this._vector.acceleration,timestamp:this._vector.timestamp}}}),Object.defineProperty(i.prototype,"clock",{get:function(){throw new Error("not implemented")}}),i.prototype.query=function(){if(this._ready.value===!1)return{position:undefined,velocity:undefined,acceleration:undefined,timestamp:undefined};var e=t.calculateVector(this._vector,this.clock.now()),n=t.getCorrectRangeState(e,this._range);return n!==t.RangeState.INSIDE&&this._timeout!==null&&this._preProcess(e),t.calculateVector(this._vector,this.clock.now())},i.prototype.update=function(e){throw new Error("not implemented")},i.prototype.checkUpdateVector=function(e){if(e==undefined)throw new Error("drop update, illegal updatevector");var n=e.position,r=e.velocity,i=e.acceleration;if(n==undefined&&r==undefined&&i==undefined)throw new Error("drop update, noop");var s=0,o=0,u=0,a=e.timestamp||this.clock.now();if(this.isReady()){var f=t.calculateVector(this._vector,a);f=t.checkRange(f,this._range),s=f.position,o=f.velocity,u=f.acceleration}return n=n!=undefined?n:s,r=r!=undefined?r:o,i=i!=undefined?i:u,{position:n,velocity:r,acceleration:i,timestamp:a}},Object.defineProperty(i.prototype,"pos",{get:function(){return this.query().position}}),Object.defineProperty(i.prototype,"vel",{get:function(){return this.query().velocity}}),Object.defineProperty(i.prototype,"acc",{get:function(){return this.query().acceleration}}),i.prototype._preProcess=function(e){e=this.onVectorChange(e),this._process(e)},i.prototype.onRangeChange=function(e){return e},i.prototype.onVectorChange=function(e){return t.checkRange(e,this._range)},i.prototype._process=function(e){if(e!==null){var t=this._vector;this._vector=e,this._ready.value=!0,this._event_variables.forEach(function(e){e.set(!0)}),this._event_variables=[],this._postProcess(this._vector)}this._renewTimeout()},i.prototype._postProcess=function(e){this.eventifyTriggerEvent("change"),this.eventifyTriggerEvent("timeupdate");var t=e.velocity!==0||e.acceleration!==0;if(t&&this._tid===null){var n=this;this._tid=setInterval(function(){n.eventifyTriggerEvent("timeupdate")},200)}else!t&&this._tid!==null&&(clearTimeout(this._tid),this._tid=null)},i.prototype._renewTimeout=function(){if(this._options.timeout===!0){this._clearTimeout();var e=this._calculateTimeoutVector();if(e===null)return;var t=this.clock.now(),n=e.timestamp-t,r=this;this._timeout=this.clock.setTimeout(function(){r._process(r.onTimeout(e))},n,{anchor:t,early:.005})}},i.prototype._calculateTimeoutVector=function(){var e=this.query(),n=t.calculateDelta(e,this._range),r=n[0];if(r===null)return null;if(r===Infinity)return null;var i=n[1],s=t.calculateVector(e,e.timestamp+r);return s.position=i,s},i.prototype._clearTimeout=function(){this._timeout!==null&&(this._timeout.cancel(),this._timeout=null)},i.prototype.onTimeout=function(e){return t.checkRange(e,this._range)};var s=function(e){e=e||{},e.timeout=!0,i.call(this,e),this._clock=new n({skew:0}),this._range=this._options.range||[-Infinity,Infinity];var t=this._options.vector||{position:0,velocity:0,acceleration:0};this.update(t)};r(s,i),Object.defineProperty(s.prototype,"clock",{get:function(){return this._clock}}),s.prototype.update=function(t){var n=this.checkUpdateVector(t),r=new e.EventBoolean;return this._event_variables.push(r),this._preProcess(n),e.makeEventPromise(r)};var o={now:function(){return performance.now()/1e3}},u=function(e,t){t=t||{},t.timeout=!0,i.call(this),this._provider=e,this._provider_clock,this._clock;var n=this;this._provider.on("vectorchange",function(){n._onVectorChange()}),this._provider.on("skewchange",function(){n._onSkewChange()});if(this._provider.skew!=undefined){var n=this;Promise.resolve(function(){n._onSkewChange()})}};r(u,i),Object.defineProperty(u.prototype,"clock",{get:function(){return this._clock}}),Object.defineProperty(u.prototype,"provider",{get:function(){return this._provider}}),u.prototype._onSkewChange=function(){if(!this._clock)this._provider_clock=new n({skew:this._provider.skew}),this._clock=new n({skew:0});else{this._provider_clock.adjust({skew:this._provider.skew});var e=this._provider_clock.now()-this._clock.now(),t=this._provider.skew-e;this._clock.adjust({skew:t})}!this.isReady()&&this._provider.vector!=undefined&&(this._range=this._provider.range,this._preProcess(this._provider.vector))},u.prototype._onVectorChange=function(){this._clock&&(this._range||(this._range=this._provider.range),this._preProcess(this._provider.vector))},u.prototype.onVectorChange=function(e){var t=e.timestamp-this._provider.skew;return{position:e.position,velocity:e.velocity,acceleration:e.acceleration,timestamp:t}},u.prototype.update=function(e){return this._provider.update(e)};var a=function(e,t){i.call(this,t),this._version=4;var n=this;this._internalOnChange=function(){var e=n._timingsrc.vector;n._preProcess(e)},this._timingsrc=undefined,this.timingsrc=e};r(a,i),a.inherit=r,Object.defineProperty(a.prototype,"clock",{get:function(){return this._timingsrc.clock}}),a.prototype.onRangeChange=function(e){return e},a.prototype.onSwitch=function(){},Object.defineProperty(a.prototype,"timingsrc",{get:function(){return this._timingsrc instanceof s?undefined:this._timingsrc instanceof u?this._timingsrc.provider:this._timingsrc},set:function(e){if(!e){var t;this._timingsrc?t={vector:this._vector,range:this._range}:t={vector:this._options.vector,range:this._options.range},e=new s(t)}else if(e instanceof a==0)try{e=new u(e)}catch(n){throw console.log(e),new Error("illegal timingsrc - not instance of timing object base and not timing provider")}var r=this,i=function(){r._timingsrc&&r._timingsrc.off("change",r._internalOnChange),r._timingsrc=e,r._timingsrc.range!==r._range&&(r._range=r.onRangeChange(r._timingsrc.range)),r.onSwitch(),r._timingsrc.on("change",r._internalOnChange)};e.isReady()?i():e.ready.then(function(){i()})}}),a.prototype.update=function(e){return this._timingsrc.update(e)};var f=function(e){e=e||{};var t=e.timingsrc||e.provider;a.call(this,t,e)};return r(f,a),{InternalProvider:s,ExternalProvider:u,TimingObjectBase:a,TimingObject:f}}),n("timingobject/skewconverter",["./timingobject"],function(e){"use strict";var t=e.TimingObjectBase,n=t.inherit,r=function(e,n,i){if(!(this instanceof r))throw new Error("Contructor function called without new operation");this._skew=n,t.call(this,e,i)};return n(r,t),r.prototype.onRangeChange=function(e){return e[0]=e[0]===-Infinity?e[0]:e[0]+this._skew,e[1]=e[1]===Infinity?e[1]:e[1]+this._skew,e},r.prototype.onVectorChange=function(e){return e.position+=this._skew,e},r.prototype.update=function(e){return e.position!==undefined&&e.position!==null&&(e.position=e.position-this._skew),this.timingsrc.update(e)},Object.defineProperty(r.prototype,"skew",{get:function(){return this._skew},set:function(e){this._skew=e;var t=this.timingsrc.vector;this._preProcess(t)}}),r}),n("timingobject/delayconverter",["./timingobject"],function(e){"use strict";var t=e.TimingObjectBase,n=t.inherit,r=function(e,n){if(!(this instanceof r))throw new Error("Contructor function called without new operation");if(n<0)throw new Error("negative delay not supported");if(n===0)throw new Error("zero delay makes delayconverter pointless");t.call(this,e),this._delay=n};return n(r,t),r.prototype.onVectorChange=function(e){var t=this.clock.now()-e.timestamp;e.timestamp+=this._delay;if(tthis._range[1])this._process(this._calculateInitialVector());else{if(!(t.positioni)throw new t("low > high");r===i&&(s=!0,o=!0),r===-Infinity&&(s=!0),i===Infinity&&(o=!0),s===undefined&&(s=!0),o===undefined&&(o=!1);if(typeof s!="boolean")throw new t("lowInclude not boolean");if(typeof o!="boolean")throw new t("highInclude not boolean");this.low=r,this.high=i,this.lowInclude=s,this.highInclude=o,this.length=this.high-this.low,this.singular=this.low===this.high,this.finite=isFinite(this.low)&&isFinite(this.high)};return n.prototype.toString=function(){var e=this.lowInclude?"[":"<",t=this.highInclude?"]":">",n=this.low===-Infinity?"<--":this.low,r=this.high===Infinity?"-->":this.high;return this.singular?e+n+t:e+n+","+r+t},n.prototype.coversPoint=function(e){return this.lowe.high?!1:this.low===e.high?this.coversPoint(e.high)&&e.coversPoint(this.low):!0},n.prototype.coversInterval=function(e){if(e instanceof n==0)throw new t("paramenter not instance of Interval");return e.lowe))return r;n=r-1}}return~n},r.prototype.insert=function(e){var t=this.binaryIndexOf(e);(t<0||t===0&&this.array[0]!==e)&&this.array.splice(Math.abs(t),0,e)},r.prototype.indexOf=function(e){var t=this.binaryIndexOf(e);return t<0||t===0&&this.array[0]!==e?-1:t},r.prototype.hasElement=function(e){var t=this.binaryIndexOf(e);return t<0||t===0&&this.array[0]!==e?!1:!0},r.prototype.remove=function(e){var t=this.binaryIndexOf(e);if(t<0||t===0&&this.array[0]!==e)return;this.array.splice(t,1)},r.prototype.getMinimum=function(){return this.array.length>0?this.array[0]:null},r.prototype.getMaximum=function(){return this.array.length>0?this.array[this.array.length-1]:null},r.prototype.ltIndexOf=function(e){var t=this.binaryIndexOf(e);return t=t<0?Math.abs(t)-1:t-1,t>=0?t:-1},r.prototype.leIndexOf=function(e){var t=this.binaryIndexOf(e);return t>0||t===0&&this.array[0]===e?t:(t=Math.abs(t)-1,t>=0?t:-1)},r.prototype.gtIndexOf=function(e){var t=this.binaryIndexOf(e);return t===0?this.array[0]===e&&(t=1):t=t<0?Math.abs(t):t+1,t0||t===0&&this.array[0]===e?t:(t=Math.abs(t),t-1&&(n.splice(t,1),r.push(e),n.length===0&&delete this._map[e.key]))},this),r},e.prototype.hasKey=function(e){return this._map.hasOwnProperty(e)},e.prototype.keys=function(){return Object.keys(this._map)},e.prototype.getItemsByKey=function(e){var t=[];return this.hasKey(e)&&this._map[e].forEach(function(n){t.push({key:e,value:n})}),t},e.prototype.getItemsByKeys=function(e){e===undefined&&(e=this.keys());var t=[];return e.forEach(function(e){t=t.concat(this.getItemsByKey(e))},this),t},e.prototype.list=e.prototype.getItemsByKeys,e}),n("sequencing/axis",["../util/interval","./sortedarraybinary","./multimap","../util/eventify"],function(e,t,n,r){"use strict";var i=function(e){this.name="AxisError",this.message=e||""};i.prototype=Error.prototype;var s=Object.freeze({INIT:"init",NONE:"none",ADD:"add",UPDATE:"update",REPEAT:"repeat",REMOVE:"remove"}),o=Object.freeze({LOW:"low",SINGULAR:"singular",HIGH:"high",INSIDE:"inside",OUTSIDE:"outside",toInteger:function(e){if(e===o.LOW)return-1;if(e===o.HIGH)return 1;if(e===o.INSIDE)return 2;if(e===o.OUTSIDE)return 3;if(e===o.SINGULAR)return 0;throw new i("illegal string value for point type")},fromInteger:function(e){if(e===-1)return o.LOW;if(e===0)return o.SINGULAR;if(e===1)return o.HIGH;if(e===2)return o.INSIDE;if(e===3)return o.OUTSIDE;throw new i("illegal integer value for point type")}}),u=function(){this._map={},this._reverse=new n,this._index=new t,this._cache={},r.eventifyInstance(this),this.eventifyDefineEvent("change",{init:!0})};return r.eventifyPrototype(u.prototype),u.prototype.eventifyMakeInitEvents=function(e){return e==="change"?this.items().map(function(e){return e.type="add",e}):[]},u.prototype._remove=function(e){if(this._map.hasOwnProperty(e)){var t=this._map[e];delete this._map[e],this._reverse.remove(t.low,e),this._reverse.remove(t.high,e),this._reverse.hasKey(t.low)||this._index.remove(t.low),this._reverse.hasKey(t.high)||this._index.remove(t.high);var n;return this._cache.hasOwnProperty(e)&&(n=this._cache[e],delete this._cache[e]),{type:s.REMOVE,key:e,interval:t,data:n}}return{type:s.NONE,key:e,interval:undefined,data:undefined}},u.prototype._insert=function(e,t,n){var r={key:e,interval:t,data:n};return this._map.hasOwnProperty(e)?(r.old_interval=this._map[e],r.old_data=this._cache[e],this._remove(e),t.equals(r.old_interval)?r.type=s.REPEAT:r.type=s.UPDATE):r.type=s.ADD,this._map[e]=t,this._reverse.hasKey(t.low)||this._index.insert(t.low),this._reverse.hasKey(t.high)||this._index.insert(t.high),this._reverse.insert(t.low,e),this._reverse.insert(t.high,e),this._cache[e]=n,r},u.prototype.updateAll=function(t){var n,r=[],s,o,u;return t.forEach(function(t){s=t.key,o=t.interval,u=t.data;if(typeof s!="string")throw new i("key is "+typeof s+" - must be string");if(o===undefined)n=this._remove(s);else{if(o instanceof e==0)throw new i("parameter must be instanceof Interval");n=this._insert(s,o,u)}this.eventifyTriggerEvent("change",n),r.push(n)},this),r},u.prototype.update=function(e,t,n){return this.updateAll([{key:e,interval:t,data:n}])},u.prototype.lookupKeysByPoint=function(e){var t,n={};return e===undefined?Object.keys(this._map).forEach(function(e){n[e]=undefined}):Object.keys(this._map).forEach(function(r){t=this._map[r],t.coversPoint(e)&&(n[r]=undefined)},this),n},u.prototype.lookupKeysByInterval=function(t){var n={};this._index.lookup(t).forEach(function(e){this._reverse.getItemsByKey(e).forEach(function(e){n[e.value]=undefined})},this);var r=new e(-Infinity,t.low),i=new e(t.high,Infinity);return this._index.lookup(r).forEach(function(e){this._reverse.getItemsByKey(e).forEach(function(e){var t=this._map[e.value];i.coversPoint(t.high)&&(n[e.value]=undefined)},this)},this),n},u.prototype.lookupByPoint=function(e){var t,n=[];return Object.keys(this._map).forEach(function(r){t=this._map[r],(e===undefined||t.coversPoint(e))&&n.push({key:r,interval:t,data:this._cache[r]})},this),n},u.prototype.lookupByInterval=function(e){var t=[],n,r;return this._index.lookup(e).forEach(function(n){this._reverse.getItemsByKey(n).forEach(function(r){n=r.key,e=this._map[r.value],t.push({key:r.value,interval:e,data:this._cache[r.value],point:n,pointType:this.getPointType(n,e)})},this)},this),t},u.prototype.items=function(){return this.lookupByPoint()},u.prototype.keys=function(){return Object.keys(this._map)},u.prototype.getItem=function(e){return this._map.hasOwnProperty(e)?{key:e,interval:this._map[e],data:this._cache[e]}:null},u.prototype.getInterval=function(e){return this._map.hasOwnProperty(e)?this._map[e]:null},u.prototype.getPointType=function(e,t){return t.singular&&e===t.low?o.SINGULAR:e===t.low?o.LOW:e===t.high?o.HIGH:t.low=e)return this.queue.push(r),this.queue.sort(this.sortFunc),!0;console.log("Schedule : task pushed a bit too late, ts < now ",t-e)}return!1},a.prototype.pop=function(e){var t=[];while(this.queue.length>0&&this.queue[0].ts<=e){var n=this.queue.shift(),r={task:n.task,pop_ts:e,push_ts:n.push_ts,ts:n.ts};t.push(r)}return t},a.prototype.invalidate=function(e){var t,n,r,i=[];for(t=0;t-1&&this.queue.splice(n,1)},a.prototype.advance=function(e){ethis.timeInterval.high},a.prototype.getDelayNextTs=function(e){return this.queue.length>0?Math.max(0,this.queue[0].ts-e):Math.max(0,this.timeInterval.high-e)},a.prototype.getNextTaskPoint=function(){return this.queue.length>0?this.queue[0].task.point:null};var f=function(e){this.name="SequencerError",this.message=e||""};f.prototype=Error.prototype;var l=function(e){return e===u.INIT?"init":e===u.NONE?"motion":e===u.ADD?"add":e===u.UPDATE||e===u.REPEAT?"update":e===u.REMOVE?"remove":""},c=function(e,t,n,r,i,u,a,f,c,h){var p=o.fromInteger(i),d=e._axis.getPointType(u,n);this.src=e,this.key=t,this.interval=n,this.data=r,this.point=u,this.pointType=d,this.dueTs=f,this.delay=a-f,this.directionType=p,this.type=h===s.EXIT?"remove":"change",this.cause=l(c),this.enter=h===s.ENTER,this.exit=h===s.EXIT};c.prototype.toString=function(){var e="["+this.point.toFixed(2)+"]";e+=" "+this.key,e+=" "+this.interval.toString(),e+=" "+this.type;var t="none";return this.enter?t="enter":this.exit&&(t="exit"),e+=" ("+this.cause+","+t+")",e+=" "+this.directionType,e+=" "+this.pointType,e+=" delay:"+this.delay.toFixed(4),this.data&&(e+=" "+JSON.stringify(this.data)),e};var h=function(e){this.key=e.key,this.interval=e.interval,this.data=e.data};h.prototype.toString=function(){var e=this.key+" "+this.interval.toString();return this.data&&(e+=" "+JSON.stringify(this.data)),e};var p=function(e,n){if(!(this instanceof p))throw new Error("Contructor function called without new operation");this._to=e,this._axis=n||new r.Axis,this._schedule=null,this._timeout=null,this._currentTimeoutPoint=null,this._activeKeys={},this._first=!1,this._ready=new t.EventBoolean(!1,{init:!0}),t.eventifyInstance(this),this.eventifyDefineEvent("change",{init:!0}),this.eventifyDefineEvent("remove"),this._wrappedOnTimingChange=function(){this._onTimingChange()},this._wrappedOnAxisChange=function(e){var t=e.map(function(e){return e.e});this._onAxisChange(t)},this._to.on("change",this._wrappedOnTimingChange,this)};t.eventifyPrototype(p.prototype),Object.defineProperty(p.prototype,"Interval",{get:function(){return n}}),p.prototype.isReady=function(){return this._ready.value},Object.defineProperty(p.prototype,"ready",{get:function(){var e=this;return new Promise(function(t,n){if(e._ready.value===!0)t();else{var r=function(){e._ready.value===!0&&(e._ready.off("change",r),t())};e._ready.on("change",r)}})}}),p.prototype.eventifyMakeInitEvents=function(e){return e==="change"?this._ready.value?this._processInitialEvents():[]:[]},p.prototype._onTimingChange=function(t){var s=this._to.clock.now(),u=this._to.vector;if(this._first===!1){this._schedule=new a(s),this._axis.on("events",this._wrappedOnAxisChange,this),this._first=!0,this._load(s),this._main(s);return}if(this._ready.value===!1)return;this._schedule.advance(s);var f=e.calculateVector(u,s),l=this._axis.lookupKeysByPoint(f.position),c=Object.keys(this._activeKeys).filter(function(e){return!l.hasOwnProperty(e)}),h=Object.keys(l).filter(function(e){return!this._activeKeys.hasOwnProperty(e)},this),p=i(u);if(p){var d=f.position,v=this._axis.lookupByInterval(new n(d,d,!0,!0));v.forEach(function(t){if(t.pointType===r.PointType.SINGULAR)c.push(t.key);else{var n=t.interval,i=!1;t.pointType===r.PointType.LOW&&n.lowInclude?i=!0:t.pointType===r.PointType.HIGH&&n.highInclude&&(i=!0);var a=o.fromInteger(e.calculateDirection(u,s)),f=!0;t.pointType===r.PointType.LOW&&a===o.BACKWARDS&&(f=!1),t.pointType===r.PointType.HIGH&&a===o.FORWARDS&&(f=!1),!f&&i&&c.push(t.key),f&&!i&&h.push(t.key)}},this)}var m=c.map(function(e){return this._axis.getItem(e)},this),g=h.map(function(e){return this._axis.getItem(e)},this),y=this._processIntervalEvents(s,m,g,[]);this.eventifyTriggerEvents(y),this._load(s),this._main(s)},p.prototype.updateAll=function(e){this._axis.updateAll(e)};var d=function(e){if(e.length<2)return e;var t=[],n,r={};for(var i=0;i0){var x=n._processIntervalEvents(s,[],[],S);n.eventifyTriggerEvents(x)}return}var T=i(o);if(!T){var x=n._processIntervalEvents(s,l,f,S);n.eventifyTriggerEvents(x);return}if(!T)this._schedule.advance(s);else{p.forEach(function(e){this._schedule.invalidate(e.key)},this);var N,C=[];p.forEach(function(e){y=e.interval,g=e.key,b=e.data;if(e.type===u.REMOVE)return;if(T){var t={key:g,interval:y,data:b},n=this._schedule.getPosInterval();n!==null&&(n.coversPoint(y.low)&&(t.point=y.low),n.coversPoint(y.high)&&(t.point=y.high),t.pointType=this._axis.getPointType(t.point,t.interval),t.pointType!==r.PointType.OUTSIDE&&C.push(t))}},this),C.length>0&&this._load(s,C)}var x=n._processIntervalEvents(s,l,f,S);n.eventifyTriggerEvents(x),n._main(s)},p.prototype._main=function(e,t){var n;e=e||this._to.clock.now(),n=this._processScheduleEvents(e,this._schedule.pop(e)),this.eventifyTriggerEvents(n);var r=i(this._to.vector);r&&this._schedule.isExpired(e)&&(e=this._schedule.getTimeInterval().high,this._schedule.advance(e),this._load(e),n=this._processScheduleEvents(e,this._schedule.pop(e)),this.eventifyTriggerEvents(n));if(r){var s=!1;if(this._timeout===null)s=!0;else{var o=this._schedule.getNextTaskPoint();o!==null&&o!==this._currentTimeoutPoint&&(s=!0)}if(s){this._clearTimeout();var u=this._to.clock.now(),a=this._schedule.getDelayNextTs(u);this._currentTimeoutPoint=o;var f=this;this._timeout=this._to.clock.setTimeout(function(){f._clearTimeout(),f._main(undefined,!0)},a,{anchor:u,early:.005})}}},p.prototype._clearTimeout=function(){this._currentTimeoutPoint=null,this._timeout!==null&&(this._timeout.cancel(),this._timeout=null)},p.prototype._load=function(t,s){var o=this._to.vector;if(!i(o))return;var u=this._schedule.getTimeInterval(),a=u.low,f=u.high,l=u.length,c=this._to.range,h=e.calculateVector(o,a),p=s,d,v;if(!p){var m=e.calculateInterval(h,l),g=Math.round10(Math.max(m[0],c[0]),-10),y=Math.round10(Math.min(m[1],c[1]),-10),b=new n(g,y,!1,!0);this._schedule.setPosInterval(b),p=this._axis.lookupByInterval(b)}var w=e.calculateSolutionsInInterval(h,l,p);p.length!==w.length&&console.log("warning : mismatch points and events",p.length,w.length);var E=e.calculateDelta(h,c)[0];w.forEach(function(n){var i=n[0],s=n[1],u=!0;a+iE&&(console.log("drop - events after range violations"),u=!1),i===E&&(console.log("drop - events exactly at range point"),u=!1);if(s.pointType===r.PointType.LOW||s.pointType===r.PointType.HIGH){var f=e.calculateVector(o,a+i);f.velocity===0&&(console.log("drop - touch endpoint during acceleration"),u=!1)}u&&this._schedule.push(t,a+i,s)},this)},p.prototype._processScheduleEvents=function(t,n){var i,a=[],f=e.calculateVector(this._to.vector,t),l=e.calculateDirection(f,t),h=this._to.clock.now();return n.forEach(function(e){if(e.task.interval.singular)a.push(new c(this,e.task.key,e.task.interval,e.task.data,l,e.task.point,h,e.ts,u.NONE,s.ENTER)),a.push(new c(this,e.task.key,e.task.interval,e.task.data,l,e.task.point,h,e.ts,u.NONE,s.EXIT));else{var t=o.fromInteger(l),n=this._axis.getPointType(e.task.point,e.task.interval),i=r.PointType.toInteger(n),f=i*l*-1,p=s.fromInteger(f);a.push(new c(this,e.task.key,e.task.interval,e.task.data,l,e.task.point,h,e.ts,u.NONE,p))}},this),this._makeEvents(t,a,l)},p.prototype._processIntervalEvents=function(t,n,r,i){if(n.length+r.length+i.length===0)return[];var o=e.calculateVector(this._to.vector,t),a=e.calculateDirection(o,t),f=this._to.clock.now(),l=[],h;return n.forEach(function(e){h=e.opType||u.NONE,l.push(new c(this,e.key,e.interval,e.data,a,o.position,f,t,h,s.EXIT))},this),r.forEach(function(e){h=e.opType||u.NONE,l.push(new c(this,e.key,e.interval,e.data,a,o.position,f,t,h,s.ENTER))},this),i.forEach(function(e){l.push(new c(this,e.key,e.interval,e.data,a,o.position,f,t,u.UPDATE,s.NONE))},this),this._makeEvents(t,l,a)},p.prototype._processInitialEvents=function(){var t,n,r=this._to.clock.now(),i=e.calculateVector(this._to.vector,r),o=e.calculateDirection(i,r),a=this._to.clock.now();return Object.keys(this._activeKeys).map(function(e){return t=this._axis.getItem(e),n=new c(this,e,t.interval,t.data,o,i.position,a,r,u.INIT,s.ENTER),n},this).sort(function(e,t){return e.interval.low-t.interval.low})},p.prototype._makeEvents=function(e,t,n){if(t.length===0)return[];var r,i=[];return t.forEach(function(e){e.exit&&this._activeKeys.hasOwnProperty(e.key)&&delete this._activeKeys[e.key],e.enter&&(this._activeKeys.hasOwnProperty(e.key)||(this._activeKeys[e.key]=undefined)),i.push(e)},this),i=this._reorderEventList(i,n),i.map(function(e){return{type:e.type,e:e}})},p.prototype._reorderEventList=function(e,t){if(e.length<2)return e;var n,i,o=[],u={a:[],x:[],b:[],c:[],y:[],d:[]};return e.sort(function(e,t){return e.interval.low-t.interval.low}).forEach(function(e){if(e.point!==n||e.dueTs!==i)t>=0?o=o.concat(u.a,u.x,u.b,u.c,u.y,u.d):o=o.concat(u.d,u.y,u.c,u.b,u.x,u.a),u={a:[],x:[],b:[],c:[],y:[],d:[]},n=e.point,i=e.dueTs;if(e.pointType===r.PointType.SINGULAR)e.type===s.ENTER?u.b.push(e):u.c.push(e);else{var a=!1;e.pointType===r.PointType.LOW&&e.interval.lowInclude?a=!0:e.pointType===r.PointType.HIGH&&e.interval.highInclude&&(a=!0),e.type===s.ENTER?a?u.x.push(e):u.d.push(e):a?u.y.push(e):u.a.push(e)}},this),t>=0?o.concat(u.a,u.x,u.b,u.c,u.y,u.d):o.concat(u.d,u.y,u.c,u.b,u.x,u.a)},p.prototype.addCue=function(e,t,n){return this.updateAll([{key:e,interval:t,data:n}])},p.prototype.removeCue=function(e,t){return this.updateAll([{key:e,interval:undefined,data:t}])},p.prototype.hasCue=function(e){return this._axis.hasKey(e)},p.prototype.keys=function(){return this._axis.keys()},p.prototype.getCue=function(e){if(this._axis.hasKey(e))return new h(this._axis.getItem(e))},p.prototype.getCues=function(){return this.keys().map(function(e){return this.getCue(e)},this)},p.prototype.isActive=function(e){return this._activeKeys.hasOwnProperty(e)},p.prototype.getActiveKeys=function(){return Object.keys(this._activeKeys)},p.prototype.getActiveCues=function(){return Object.keys(this._activeKeys).map(function(e){return this.getCue(e)},this)},p.prototype.get=function(e){return this.isActive(e)?this.getCues(e).map(function(e){return e.data}):undefined},p.prototype.items=function(){return this.getActiveCues().map(function(e){return e.data})},p.prototype.getCuesByPoint=function(e){return this._axis.lookupByPoint(e).map(function(e){return this.getCue(e.key)},this)},p.prototype.getCuesByInterval=function(e){var t={};return this._axis.lookupByInterval(e).forEach(function(e){t[e.key]=e.interval}),Object.keys(t).map(function(e){return this.getCue(e)},this).filter(function(t){return e.overlapsInterval(t.interval)},this)},p.prototype.getCuesCoveredByInterval=function(e){return this.getCuesByInterval(e).filter(function(t){return e.coversInterval(t.interval)?!0:!1},this)},p.prototype.close=function(){this._to.off("change",this._wrappedOnTimingChange,this),this._axis.off("change",this._wrappedOnAxisChange,this),this._timeout!==null&&(this._timeout.cancel(),this._timeout=null)},{Interval:n,DefaultSequencer:p,Axis:r.Axis,SequencerError:f}}),n("sequencing/windowsequencer",["../util/eventify","../util/motionutils","./axis","./sequencer"],function(e,t,n,r){"use strict";var i=r.Interval,s=r.DefaultSequencer,o=function(t,r,i){if(!(this instanceof o))throw new Error("Contructor function called without new operation");this._axis=i||new n.Axis,this._toA=t,this._toB=r,this._seqA=new s(this._toA,this._axis),this._seqB=new s(this._toB,this._axis),this._ready=new e.EventBoolean(!1,{init:!0}),this._pending_reevaluate=!1,this._activeKeys={},e.eventifyInstance(this),this.eventifyDefineEvent("change",{init:!0}),this.eventifyDefineEvent("remove");var u=this;this._onAxisChange=function(e){var t=e.map(function(e){return e.e});u._reevaluate(t)},this._onToAChange=function(){u._request_reevaluate()},this._onToBChange=function(){u._request_reevaluate()},this._onSeqAChange=function(e){u._request_reevaluate()},this._onSeqBChange=function(e){u._request_reevaluate()},this._toA.on("change",this._onToAChange,this),this._toB.on("change",this._onToBChange,this),this._seqA.on("events",this._onSeqAChange,this),this._seqB.on("events",this._onSeqBChange,this),Promise.all([this._seqA.ready,this._seqB.ready]).then(function(e){u._axis.on("events",u._onAxisChange,u),u._ready.value=!0})};e.eventifyPrototype(o.prototype),Object.defineProperty(o.prototype,"Interval",{get:function(){return i}}),o.prototype.isReady=function(){return this._ready.value===!0},Object.defineProperty(o.prototype,"ready",{get:function(){var e=this;return new Promise(function(t,n){if(e._ready.value===!0)t();else{var r=function(){e._ready.value===!0&&(e._ready.off("change",r),t())};e._ready.on("change",r)}})}}),o.prototype.eventifyMakeInitEvents=function(e){return e==="change"?Object.keys(this._activeKeys).map(function(e){var t=this._axis.getItem(e);return{key:e,interval:t.interval,data:t.data,type:"change",cause:"init",enter:!0,exit:!1}},this):[]},o.prototype._getActiveInterval=function(){var e=this._toA.query(),t=this._toB.query(),n=Math.min(e.position,t.position),r=Math.max(e.position,t.position);return new i(n,r,!0,!0)};var u=function(e){return e==="init"?"init":e==="none"?"motion":e==="add"?"add":e==="update"||e==="repeat"?"update":e==="remove"?"remove":""};return o.prototype._getOpFromAxisOpList=function(e,t){var n;if(e)for(var r=0;r=0},r=function(e,r){this._timingsrc,r=r||{},r.value===undefined&&(r.value=0);if(!n(r.value))throw new Error("value not nummeric",r.value);this._value=r.value;if(r.min!==undefined&&!n(r.min))throw new Error("option.min not nummeric",r.min);if(r.max!==undefined&&!n(r.max))throw new Error("option.min not nummeric",r.max);this._options=r,t.eventifyInstance(this),this.eventifyDefineEvent("change",{init:!0}),this._timeout=null;var i=this;this._wrappedOnChange=function(){i._onChange()},this.timingsrc=e};return t.eventifyPrototype(r.prototype),r.prototype.eventifyMakeInitEvents=function(e){return e==="change"?[this.value]:[]},Object.defineProperty(r.prototype,"ready",{get:function(){return this._timingsrc.ready}}),r.prototype.isReady=function(){return this._timingsrc.isReady()},Object.defineProperty(r.prototype,"value",{get:function(){return this._value},set:function(e){this._timingsrc.update({position:e})}}),Object.defineProperty(r.prototype,"timingsrc",{get:function(){return this._timingsrc},set:function(e){this._timingsrc&&this._timingsrc.off("change",this._wrappedOnChange,this),clearTimeout(this._tid),this._timingsrc=e,this._timingsrc.on("change",this._wrappedOnChange,this)}}),r.prototype._renewTimeout=function(){this._clearTimeout();var e=this._calculateTimeout();if(e.delay===null)return null;var t=this;this._timeout=this._timingsrc.clock.setTimeout(function(){t._onTimeout()},e.delay,{anchor:e.anchor,early:.005})},r.prototype._clearTimeout=function(){this._timeout!==null&&(this._timeout.cancel(),this._timeout=null)},r.prototype._onChange=function(){this._refresh(),this._renewTimeout()},r.prototype._onTimeout=function(){this._refresh(),this._renewTimeout()},r.prototype._refresh=function(){var e=Math.floor(this._timingsrc.query().position);this._options.max!==undefined&&e>this._options.max&&(e=this._options.max),this._options.min!==undefined&&e0?this._stack[e-1][1]:undefined;t!==this._value&&(this._value=t,this.eventifyTriggerEvent("change",t)),this._dirty=!1},t.prototype._onSeqEvents=function(e){e.forEach(function(e){var t=e.e;if(e.type==="change")this._stack.push([t.key,t.data]),this._touch();else if(e.type==="remove"){var n=this._stack.findIndex(function(e,n,r){return e[0]===t.key});n>-1&&(this._stack.splice(n,1),this._touch())}},this)},Object.defineProperty(t.prototype,"value",{get:function(){return this._value}}),t.prototype.get=function(){return this._value},t.prototype.close=function(){this._seq.off("events",this._wrappedHandler)},t}),n("sequencing/main",["./sequencer","./windowsequencer","./timingcallbacks","./timinginteger","./activecue"],function(e,t,n,r,i){"use strict";var s=function(n,r,i){return r===undefined?new e.DefaultSequencer(n,i):new t(n,r,i)};return e.DefaultSequencer.prototype.clone=function(e,t){return s(e,t,this._axis)},t.prototype.clone=function(e,t){return s(e,t,this._axis)},{Sequencer:s,Interval:e.Interval,inherit:e.inherit,setPointCallback:n.setPointCallback,setIntervalCallback:n.setIntervalCallback,TimingInteger:r,ActiveCue:i}}),n("mediasync/mediasync",[],function(){"use strict";function e(e){throw new Error("MediaSync is no longer maintained as part of Timingsrc. Get MediaSync from https://mcorp.no/lib/mediasync.js")}function t(e,t,n){throw new Error("MediaSync is no longer maintained as part of Timingsrc. Get MediaSync from https://mcorp.no/lib/mediasync.js")}var n=function(e,t,n){throw new Error("MediaSync is no longer maintained as part of Timingsrc. Get MediaSync from https://mcorp.no/lib/mediasync.js")};return{mediaSync:t,MediaSync:n,mediaNeedKick:e}}),n("timingsrc",["./timingobject/main","./sequencing/main","./mediasync/mediasync"],function(e,t,n){return{version:"v2",TimingObject:e.TimingObject,ConverterBase:e.ConverterBase,SkewConverter:e.SkewConverter,DelayConverter:e.DelayConverter,ScaleConverter:e.ScaleConverter,LoopConverter:e.LoopConverter,RangeConverter:e.RangeConverter,TimeShiftConverter:e.TimeShiftConverter,LocalConverter:e.LocalConverter,DerivativeConverter:e.DerivativeConverter,Interval:t.Interval,Sequencer:t.Sequencer,setPointCallback:t.setPointCallback,setIntervalCallback:t.setIntervalCallback,TimingInteger:t.TimingInteger,ActiveCue:t.ActiveCue,MediaSync:n.MediaSync,mediaNeedKick:n.needKick}}),t("timingsrc")});