-
Notifications
You must be signed in to change notification settings - Fork 3
/
sqimitive.min.js
5 lines (5 loc) · 26.3 KB
/
sqimitive.min.js
1
2
3
4
5
/*!
Sqimitive.js - a JavaScript primitive
https://squizzle.me/js/sqimitive | Public domain/Unlicense
*/
!function(t){var i,n,e="nodash?main:_",s="Sqimitive";"undefined"==typeof exports||exports.nodeType?"function"==typeof define&&define.amd?define(e.replace(/\?/g,"/").match(/\S+(?=:)/g)||[],t):(i="object"==typeof self?self:"object"==typeof global?global:this||{},n=function(t,e){for(e=e.split(".");t&&e.length;)t=t[e.shift()];return t},e=(e.match(/:\S+/g)||[]).map(function(t){var e=n(i,t=t.substr(1));if(e)return e;throw s+": missing dependency: "+t}),s=s.split(/\.([^.]+)$/),(i=1<s.length?n(i,s.shift()):i)[s[0]]=t.apply(this,e)):(e=(e.replace(/\?[^:]*/g,"").match(/\S+(?=:)/g)||[]).map(require),"undefined"!=typeof module&&module.exports?module.exports=t.apply(this,e):exports=t.apply(this,e))}.call(this,function(p){"use strict";var a=Array.prototype,n={version:"1.3",_:p},u=n.Core=function(){u.trace&&(this.trace=(new Error).stack),this.constructor._copyProps.call(this,this),this._cid="p"+u.unique("p"),this._eventsByCx=new Map};function r(){var t,e=this.constructor.deepCloner();for(t in e.func=[],this)this._mustClone(t)&&(e.func.push("\nthis["+JSON.stringify(t)+"]="),this.constructor.deepCloner(this[t],e));(this.constructor._copyProps=e.compile()).call(this,this)}return p.assign(u,{trace:!1,lastFired:[],_unique:{},_mergeProps:[],_shareProps:[],_copyProps:null,extend:function(t,e,i){t="string"==typeof arguments[0]?a.shift.call(arguments):this.name,n=this,s=(r=arguments[0])&&p.has(r,"constructor")?r.constructor:function(){return n.apply(this,arguments)},o.prototype=n.prototype,s.prototype=new o,s.__super__=n.prototype;var n,s,r=s;function o(){this.constructor=s}return p.assign(r,this,{__super__:r.__super__}),r._mergeProps=(r._mergeProps||this._mergeProps).concat(),r._shareProps=(r._shareProps||this._shareProps).concat(),Object.defineProperty(r,"length",{value:"NotAnArray"}),t&&Object.defineProperty(r,"name",{value:t}),arguments[1]&&((arguments[0]=arguments[0]||{}).staticProps=arguments[1]),arguments[0]&&r.mixIn(arguments[0]),"string"==typeof r.prototype._childClass&&(r.prototype._childClass=[r,r.prototype._childClass]),r},mixIn:function(t,e){return this.prototype.mixIn(t,e)},stub:function(){},unique:function(t){return this._unique[t]=1+(this._unique[t]||0)},picker:function(r,o){function t(t){var e,i=0;function n(){"function"!=typeof t||/^[A-Z]/.test(t.name)||(t=t.apply(e,o&&o[i++]))}n();for(var s=0;s<r.length;s++){if(null==t)return;t=(e=t)[r[s]],n()}return t}return p.isArray(r)||(r=(r+"").split(".")),1<arguments.length&&!p.isArray(o)&&(o=[[o]]),u.trace&&(t.trace=arguments),t},expandFunc:function(e,i){function t(){var t=i||this;return t[e].apply(t,arguments)}var n;return"string"==typeof e?1<(n=e.split(/([.-][\d.-]*)$/)).length?u.masker(n[0],n[1],i):(u.trace&&(t.trace=arguments),t):i?p.bind(e,i):e},masker:function(n,s,r,o){var h="string"==typeof n,c="number"==typeof(s=null==s?1:s);function t(){for(var t=r||this,e=c?o.concat(p.rest(arguments,s)):o.concat(),i=0;i<s.length;i++)"-"!=s[i]&&e.push(arguments[s[i]-1]);return(h?t[n]:n).apply(t,e)}return o=o||[],c||(s=s.replace(/\./g,function(t,e){return 8<e?"-":e+1}).replace(/[^1-9.\-]+/g,"-").replace(/-+$/,"")),u.trace&&(t.trace=arguments),t},deepClone:function(t){if("object"==typeof t&&null!=t)if(p.isArray(t))t=t.map(u.deepClone);else for(var e in t=p.assign({},t))t[e]=u.deepClone(t[e]);return t},deepCloner:function(t,e){if(e=e||{func:["return "],shared:[],compile:function(){return p.partial(new Function("s",e.func.splice(0).join("")),e.shared)}},!arguments.length)return e;switch(typeof t){case"string":if(t.length<50){e.func.push(JSON.stringify(t));break}default:e.func.push("s["+(e.shared.push(t)-1)+"]");break;case"object":if(null!=t){if(p.isArray(t)){e.func.push("[");for(var i=0;i<t.length;i++)u.deepCloner(t[i],e),e.func.push(",");e.func.push("]");break}for(var n in e.func.push("{"),t)e.func.push(JSON.stringify(n)+":"),u.deepCloner(t[n],e),e.func.push(",");e.func.push("}");break}case"undefined":case"boolean":case"number":e.func.push(t+"")}return arguments[1]?e:e.compile()},parseEvent:function(t){var e=t.match(/^(\^?)(-?\d+\^)?([+\-=]?)(.+?)(_*)$/);if(e)return{batch:!e[1],priority:parseInt(e[2])||0,prefix:e[3],event:e[4],args:e[5].length||null,trace:u.trace&&(new Error).stack};throw new SyntaxError("Bad event name: "+t)},fire:function(t,n,s){var r;return n=n||[],p.isArray(t)&&t.concat().some(function(t){var e,i;if(null==s||t.batch===s)return u.trace&&50<u.lastFired.push(p.assign({self:this},t))&&u.lastFired.shift(),i=(e=t.func&&(null==t.args||t.args==n.length))?(t.sup||t.res?(i=a.slice.call(n),t.sup&&i.unshift(t.sup),t.res&&i.unshift(r)):i=n,t.func.apply(t.cx||this,i)):t.sup?t.sup(t.cx||this,n):void 0,t.ret&&void 0!==i&&(r=i),!!(t.post&&e&&(t.stop=!1,r=t.post.call(t.cx||this,t,r,n),t.stop))||void 0},this),r},firer:function(t,e,i){var n=1<arguments.length?(e=u.toArray(e),function(){return(i||this).fire(t,e.concat(a.slice.call(arguments)))}):function(){return(i||this).fire(t,arguments)};return u.trace&&(n.trace=arguments),n},batchGuard:function(s,r,o){if("string"==typeof s){if(!s.match(/^[.+=]*c_?$/))throw new Error("batchGuard: Invalid index: "+s);s=s.length+("_"==p.last(s)?0:2)}o=o||{},r=u.expandFunc(r,o.cx);var h=o.seen||(o.seen=new Set),c=u.unique("bg")+"bg";function t(){var e,i,t=arguments[s],n=t.batchID;if(!n)throw new Error("batchGuard: No batchID in "+s);if(h.size!=h.add(n).size)return e=c+n,i=0,p.forEach(t.batched,function(t){t[1].length&&(i++,t[1].push([e]),t[0].once(e,function(){--i||h.delete(n)}))}),r.apply(this,arguments);o.skip&&o.skip.apply(o.cx||this,arguments)}return u.trace&&(t.trace=arguments),t},toArray:function(t){return p.isArguments(t)?a.slice.call(t):p.isArray(t)?t:[t]}}),p.assign(u.prototype,{_cid:"",_events:{},_eventsByID:{},_eventsByCx:null,_wrapUndeclared:!0,_autoOff:null,_logEventID:null,_batches:null,_batch:null,_batchID:null,_batched:[],mixIn:function(e,t){var i={mixIns:void 0,finishMixIn:void 0,staticProps:void 0,events:void 0};if(p.forEach(e.mixIns||[],function(t){this.mixIn.apply(this,[].concat(t))},this),p.forEach(this.constructor._mergeProps,function(t){t in this&&t in e&&(p.isArray(e[t])?i[t]=this[t].concat(e[t]):i[t]=p.assign({},this[t],e[t]))},this),p.assign(this,e,i),p.assign(this.constructor,e.staticProps||{}),e.events){if(this._events===this.constructor.__super__._events)for(var n in this._events=p.assign({},this._events),this._events)this._events[n]=this._events[n].concat();this.on(e.events)}if(this===this.constructor.prototype)this.constructor._copyProps=r;else for(var s in e)s in i||!this._mustClone(s)||(this[s]=this.constructor.deepClone(this[s]));e.finishMixIn&&e.finishMixIn(this,t)},_mustClone:function(t){return"object"==typeof this[t]&&null!=this[t]&&-1==this.constructor._shareProps.indexOf(t)},fire:function(t,e,i){if(this._events.all&&"all"!=t){var n=arguments.length<2?[]:u.toArray(e).concat(),n=(n.unshift(t),this.constructor.fire.call(this,this._events.all,n));if(void 0!==n)return n}return this.constructor.fire.call(this,this._events[t],e,i)},logEvents:function(t){var e,i;return"string"==typeof t?(e=this._cid,this.el&&(e+="\t\t"+(i=this.el.nodeType?this.el:this.el[0]).tagName,""!=(i=i.className.trim())&&(e+=(" "+i).replace(/\s+/g,"."))),void console.log(t+" ("+(arguments.length-1)+") on "+e)):(!t&&arguments.length?(this.off(this._logEventID),this._logEventID=null):console&&console.log&&!this._logEventID&&(this._logEventID=this.on("all",u.logEvents)),this)},on:function(t,e,i){if(t instanceof Object){for(var n in t)for(var s=n.split(", "),r=0,o=s.length;r<o;r++)this.fuse(s[r],t[n],e);return this}if(2<=arguments.length)return this._regHandler(this.fuse(t,e,i));throw new TypeError("on: Bad arguments")},once:function(t,i,e,n){var s=arguments,r=this,o=0;switch(typeof i){case"string":case"function":a.splice.call(s,1,0,i={})}function h(){var t={},e=t;try{o++||(e=u.expandFunc(s[2]).apply(this,arguments))}finally{e===i?o--:r.off(c)}return e===t?void 0:e}u.trace&&(h.trace=arguments);var c=this.on(t,h,s[3]);return c},autoOff:function(r,e,o){var i,t=this._autoOff;switch(arguments.length){case 0:return t&&t.size&&(this._autoOff=null,t.forEach(function(t){t.off(this)},this)),this;case 1:case 2:if("function"==typeof r)return t&&t.forEach(function(t){i=null==i&&r.call(e||this,t)},this),i;if(1==arguments.length||!0===e)return t&&t.delete(r)&&!0!==e&&r.off(this),r;o=this;default:(t||(this._autoOff=new Set)).add(r);var h=this;function n(t,e){o!==h&&(t=u.expandFunc(t,o||r));for(var i=e.split(", "),n=0,s=i.length;n<s;n++)r.on(i[n],t,h)}if(p.isArray(e))for(var s=1,c=e.length;s<c;s+=2)n(e[s],e[s-1]);else p.forEach(e,n);return r}},fuse:function(t,e,i){e=u.expandFunc(e);var n,s=u.parseEvent(t),t=p.has(this._events,s.event)?this._events[s.event]:this._events[s.event]=[];return this._wrapHandler(s.event),s.func=e,s.cx=i,"+"==s.prefix?s.res=s.ret=!0:"="==s.prefix&&(s.ret=!0,s.supList=t.splice(0),n=s.sup=function(t,e){return e&&e[0]===n&&p.isArguments(e)&&(e=a.slice.call(e,1)),u.fire.call(t,s.supList,e)},Object.defineProperty(n,"name",{value:s.event})),this._insertHandler(t,s),s},_insertHandler:function(t,e){var i=n.Ordered.staticProps.indexFor(t,e.priority+.5-("-"==e.prefix),function(t,e){return 1<arguments.length&&t.priority-e});t.splice(i,0,e)},_wrapHandler:function(t){if(!/\W/.test(t)){var e=this[t];if(void 0!==e||this._wrapUndeclared||t in this){if(void 0!==e&&e!==u.stub){if("function"!=typeof e||e._wrapHandler)return;var i=u.parseEvent("e");p.assign(i,{event:t,func:e,ret:!0}),this._insertHandler(this._events[t],i)}(this[t]=this.constructor.firer(t))._wrapHandler=t}}},_regHandler:function(t){var e,i=t.id=this.constructor.unique("e");return(this._eventsByID[i]=t).cx&&((e=this._eventsByCx.get(t.cx))?e.push(t):this._eventsByCx.set(t.cx,[t])),i},off:function(t){var e;return p.isArray(t)?p.forEach(t,this.off,this):t instanceof Object?(e=this._eventsByCx.get(t))&&(this._eventsByCx.delete(t),p.forEach(e,this._unregHandler.bind(this,{cx:!0}))):"string"==typeof t?(e=this._events[t])&&(delete this._events[t],p.forEach(e,this._unregHandler.bind(this,{sup:!0}))):(e=this._eventsByID[t])&&this._unregHandler({},e),this},_unregHandler:function(e,t){t.func=null,delete this._eventsByID[t.id],t.cx&&!e.cx&&(1==(i=this._eventsByCx.get(t.cx)).length?this._eventsByCx.delete(t.cx):i.splice(i.lastIndexOf(t),1));var i,n,s=this,r=function(t){p.forEach(t.supList||[],function(t){t.func?e.sup?s._unregHandler(e,t):s._insertHandler(i,t):r(t)})};e.sup?r(t):-1!=(n=(i=this._events[t.event])["-"==t.prefix?"indexOf":"lastIndexOf"](t))&&(i.splice(n,1),r(t),i.length||delete this._events[t.event])},_forward:function(n,s,r,o){return p.forEach(s.concat(),function(t){var e=n+t;function i(){return a.unshift.apply(arguments,o||[r]),this.fire(e,arguments)}u.trace&&(i.trace=[n,s,r,o]),r.on(t,i,this)},this),r},_batchOptions:function(t,e){return p.assign({},e,{batch:this._batch,batched:this._batched,batchID:t,operationID:u.unique("o"),trace:u.trace&&(new Error).stack})},batch:function(t,e,i){var n=this._batchID||(this._batchID=u.unique("b"));if(t){if(this._batch)throw new Error("Batch already active");var s=+(t[0]===this);t.length>s&&((h=t[s])._batch||(h._batchID=n,h._batched=this._batched),e=h.batch.bind(h,t.slice(1+s),e,i||this))}if(this._batch)return e.call(i||this,n);var r,o=this._batch=[],h=!this._batches;h?this._batches=[o]:this._batches.push(o),this._batched.push([this,o]);try{try{var c=e.call(i||this,n)}finally{p.forEach(this._batched,function(t){t[0]._batch=t[0]._batchID=null,t[0]._batched=[]})}for(o.eventIndex=-1;r=o[++o.eventIndex];)this.fire(r[0],r.slice(1),!1);if(o.eventIndex=null,h)for(;o=this._batches.shift();)for(;o.length;)this.fire(o[0][0],o[0].slice(1),!0),o.shift();return c}finally{h&&(this._batches=null)}}}),n.Base=u.extend({_opt:{},_parent:null,_parentKey:null,_children:{},_owning:!0,_childClass:null,_childEvents:[],_respToOpt:{},_initToOpt:{el:!1},el:!1,elEvents:{},length:0,constructor:function(t){t||a.unshift.call(arguments,{}),n.Base.__super__.constructor.apply(this,arguments),this.init.apply(this,arguments),this.postInit.apply(this,arguments)},init:function(t){var e=this._childClass;if(p.isArray(e)){for(var i=e[1].split("."),e=e[0];e&&i[0];)e=e[i.shift()];if(!e)throw new ReferenceError("init: _childClass by path not found");this.constructor.prototype._childClass=e}this.assignResp(t,{schema:"_initToOpt"})},postInit:u.stub,render:function(){return this.invoke("attach"),this},attach:function(t){return this},getSet:function(t,e,i,n,s){for(var r=u.toArray(arguments),o=0;o<=2;o++){"function"==typeof r[o]?r.splice(o,0,r[o-1]):null==r[o]&&(r[o]=r[o-1]);var h=r["a"+o]=p.isArray(r[o])?r[o]:[r[o]];o<2&&h.forEach(function(t,e){h[e]=t.substr("-"==t[0])})}var c=p.map(r.a0,this.get,this),a={};return r.a2.forEach(function(t,e){"-"==t[0]&&(a[e]=this.get(t.substr(1)))},this),r[3]&&(c=r[3].apply(r[4]||this,c),p.isArray(r[1])||(c=[c])),this.assignResp(p.object(r.a1,c),{schema:{}}),p.isArray(r[2])?p.assign(p.map(r[2],this.get,this),a):0 in a?a[0]:this.get(r[2])},get:function(t){return arguments.length?this._opt[t]:p.assign({},this._opt)},set:function(t,e,i){return this.ifSet(t,e,i),this},ifSet:function(e,i,n){n=n||{};var t,s=this._opt[e],r="normalize_"+e;if(r in this?this[r]&&(t=this[r](i,n)):t=this.fire(r,[i,n]),void 0!==t&&(i=t),n.forceFire||!this.isEqual(i,s))return this._opt[e]=i,this.batch(null,function(t){n=this._batchOptions(t,n),this._batch.push(["change_"+e,i,s,n]),this._batch.push(["change",e,i,s,n])}),!0},isEqual:function(t,e){return t===e},nest:function(t,e,i){t=+!(t instanceof Object);return arguments[t].constructor===Object&&this._childClass!==Object&&(arguments[t]=new this._childClass(arguments[t])),t||a.unshift.call(arguments,this._defaultKey(arguments[0])),i=p.assign({},arguments[2]||{},{key:arguments[0],child:arguments[1]}),this.nestEx(i).child},nestEx:function(t){var e=t.child;if(!(e instanceof this._childClass))throw new TypeError("nestEx: Nesting Sqimitive of wrong class");if("object"==typeof t.key||void 0===t.key)throw new TypeError("nestEx: Bad key given");var i=t.key+="",n=t.previous=this._children[i];return(t.changed=n!==e)&&(this._owning?(n&&n.unnest(),e.unnest(),(this._children[i]=e)._parent=this,e._parentKey=i,this.length++):(this._children[i]=e,n?this.unnested(n,i):this.length++),this._forward(".",this._childEvents,e),this._owning&&e.owned()),this._nested(t),t},_nested:u.stub,_unnested:u.stub,_defaultKey:function(t){return t._cid},owned:u.stub,unlist:function(t){var e;return(e=null!=(t=t instanceof Object?this.findKey(t):t)?this._children[t+=""]:e)&&(this._owning?e.remove():(delete this._children[t],--this.length,this.unnested(e,t))),e},unnest:function(){var t,e=this._parent;return e&&(t=this._parentKey,delete e._children[t],this._parent=this._parentKey=null,--e.length,e.unnested(this,t)),this},unnested:function(t,e){t.off(this),this._unnested(t,e),this.length<0&&console&&console.error&&console.error("Broken nesting: sqimitive.length below zero")},nested:function(t){return arguments.length?null!=t?t instanceof Object?null!=this.findKey(t)?t:void 0:this._children[t+""]:void 0:p.assign({},this._children)},slice:function(t,e){return p.values(this._children).slice(t,e)},findKey:function(t,e){var i,n=t instanceof Object;if(n&&this._owning)return t._parent===this?t._parentKey:void 0;for(i in this._children)if(n?this._children[i]===t:t.call(e||this,this._children[i],i,this._children))return i},sort:function(t,e){return this.slice().sort(t.bind(e||this))},_:function(){return p.chain(this.slice())},remove:function(){return this.unnest()},assignChildren:function(t,e){(e=e||{}).assignChildren=!0;for(var i,n,s=e.eqFunc,r=e.keyFunc||this._defaultKey,o=e.unFunc||this.unlist,h=(null==s?(i=e.keepMissing?{}:this.nested(),e.keepMissing||this.forEach(o,this)):"function"!=typeof s&&(n=s,s=function(t,e){return e&&t.get(n)==e[n]}),p.isArray(t)||(t=p.values(t)),s?this.nested():{}),c=[],a=0;a<t.length;a++){var u,l,f=!1;for(u in h)if(s.call(this,h[u],t[a])){h[u].assignResp(t[a],e),delete h[u],f=!0;break}f||((l=e.newFunc?e.newFunc.call(this,t[a]):new this._childClass).assignResp(t[a],e),l=this.nestEx(p.assign({},e,{key:r.call(this,l,t[a]),child:l,pos:e.posFunc?e.posFunc.call(this,l,t[a]):null})),c.push(l))}return e.keepMissing||p.forEach(h,o,this),[c,i||h]},assignResp:function(o,h){return this.batch(null,function(){(h=h||{}).assignResp=!0;var t,i=[],e=this[h.schema]||h.schema||this._respToOpt,n=e[""]&&e[""].call(this,o,h)||{};for(t in p.forEach(n,function(t,e){this.ifSet(e,t,h)&&i.push(e)},this),o){var s=o[t],r=e[t];"function"==typeof(r=!0===(r=void 0===r?!h.onlyDefined:r)?t:r)&&(s=(r=r.call(this,s,t,o,h)||[!1])[1],r=r[0]),!1!==r&&("."==r[0]&&"."!=t[0]?this[r.substr(1)||t]=s:this.ifSet(r,s,h)&&i.push(r))}return i})},bubble:function(t,e,i){return i&&this[t]&&this[t].apply(this,e),this._parent&&this._parent.bubble(t,e,!0),this},sink:function(t,e,i){return i&&this[t]&&this[t].apply(this,e),this.invoke("sink",t,e,!0),this}}),n.Base.prototype._childClass=n.Base,n.Base._mergeProps.push("_opt","elEvents","_respToOpt","_initToOpt","_childEvents"),n.Base._shareProps.push("_childClass"),n.Ordered={_ordered:[],events:{_nested:function(t){var e,i=t.changed;i||(t.oldIndex=this._indexOf(t.child),i=t.repos||!this.isEqual(t.pos,this._ordered[t.oldIndex].pos)),i&&(i=p.pick(t,"child","key","pos"),t.index=this._indexFor(t,t.oldIndex),e=t.index-=t.index>t.oldIndex,t.oldIndex==e?p.assign(this._ordered[e],i):(t.changed||this._ordered.splice(t.oldIndex,1),this._ordered.splice(e,0,i),this._repos(t.child,e)))},_unnested:function(t,e){this._removeFromOrdered(e,t)},"=slice":function(t,e,i){return p.pluck(this._ordered.slice(e,i),"child")}},_removeFromOrdered:function(t,e){e=this._indexOf(e);if(-1==e)throw new TypeError("Broken nesting: sqimitive missing from _ordered");this._ordered.splice(e,1)},_indexOf:function(e){return p.findIndex(this._ordered,function(t){return t.child===e})},_indexFor:function(t,e){return this.constructor.indexFor(this._ordered,t,this._sorter,this,e)},_sorter:function(t,e,i){return t=null==t.pos?t.key:t.pos,1==arguments.length?t:i<t?1:t<i?-1:0},resort:function(){return this._ordered.sort(function(t,e){return this._sorter(t,e,this._sorter(e))}.bind(this)),this.forEach(this._repos,this),this},_repos:u.stub,at:function(t){return this._ordered[t]},shift:function(){var t=this._ordered[0];return t&&this.unlist(t.key)},pop:function(){var t=p.last(this._ordered);return t&&this.unlist(t.key)},reverse:function(){for(var t=[],e=this.length;e--;)t.push(this._ordered[e].child);return t},staticProps:{indexFor:function(t,e,i,n,s){for(var r=t.length&&i.call(n,e),o=t.length-(t.length-1==s),h=0,c=1;h<o&&c;){var a=h+o>>>1;0<(c=i.call(n,t[a+(a==s)],e,r))?o=a:h=1+a}return h}}},p.forEach("pick omit keys".split(" "),function(t,e){var i=1<e&&[];n.Base.prototype[t]=function(){return p[t].apply(p,[this._children].concat(a.slice.call(arguments),i||this))}}),p.forEach("each map find filter reject reduce every some max min sortBy groupBy indexBy countBy forEach partition includes invoke pluck chunk shuffle sample toArray without union intersection difference".split(" "),function(t,e){var i=15<e&&[];n.Base.prototype[t]=function(){return p[t].apply(p,[this.slice()].concat(a.slice.call(arguments),i||this))}}),p.forEach("reduceRight findIndex findLastIndex first initial last rest indexOf lastIndexOf".split(" "),function(t,e){var i=2<e&&[];n.Ordered[t]=function(){return p[t].apply(p,[this.slice()].concat(a.slice.call(arguments),i||this))}}),n}),function(t){var i,n,e="sqimitive/main:Sqimitive jquery:$",s="Sqimitive.jQuery";"undefined"==typeof exports||exports.nodeType?"function"==typeof define&&define.amd?define(e.replace(/\?/g,"/").match(/\S+(?=:)/g)||[],t):(i="object"==typeof self?self:"object"==typeof global?global:this||{},n=function(t,e){for(e=e.split(".");t&&e.length;)t=t[e.shift()];return t},e=(e.match(/:\S+/g)||[]).map(function(t){var e=n(i,t=t.substr(1));if(e)return e;throw s+": missing dependency: "+t}),s=s.split(/\.([^.]+)$/),(i=1<s.length?n(i,s.shift()):i)[s[0]]=t.apply(this,e)):(e=(e.replace(/\?[^:]*/g,"").match(/\S+(?=:)/g)||[]).map(require),"undefined"!=typeof module&&module.exports?module.exports=t.apply(this,e):exports=t.apply(this,e))}.call(this,function(n,e){"use strict";var s=n._,t={staticProps:{$:e,is$:function(t){return t instanceof e||e.zepto&&e.zepto.isZ(t)},canWrap:function(t){return t&&(s.isElement(t)||9===t.nodeType||t.window===t)}},_opt:{},el:{tag:"div",className:""},_invokeAttach:!0,_removeEl:!0,events:{"-init":function(t){if(t&&"el"in t&&(this.el=t.el),this.el&&!this.constructor.is$(this.el)&&(this.constructor.canWrap(this.el)||"string"==typeof this.el?this.el=e(this.el):(t=s.omit(this.el,"tag","className"),this.el.className&&(t.class=this.el.className),this.el=e(document.createElement(this.el.tag||"div")).attr(t).data("sqimitive",this))),this.el&&!this.el.length)throw new TypeError("init: Empty el")},attach:function(t){var i;arguments.length||(t=this.get("attachPath")),this.el&&(t=t&&(this._parent?this._parent.$(t):e(t))||[],s.isElement(t[0])&&t[0]!==this.el[0].parentNode&&(this.el.appendTo(t),this._invokeAttach&&this.invoke("attach")),i=".sqim-"+this._cid,this.el.off(i),s.forEach(this.elEvents,function(t,e){t=n.Core.expandFunc(t,this),(e=e.match(/^\s*([^\s.]+)(\.\S*)?(\s+(.*))?$/))[1]+=i,e[4]?this.el.on(e[1],e[4],t):this.el.on(e[1],t)},this))},"-remove":function(){this.el&&(this._removeEl?this.el.remove():this.el.off(".sqim-"+this._cid))}},$:function(t){return this.constructor.is$(t)||this.constructor.canWrap(t)?e(t):this.el?""==t||"."==t?this.el:this.el.find(t):e()}};return n.Base.extend("Sqimitive.jQuery",{mixIns:[t]},{MixIn:t})}),function(t){var i,n,e="sqimitive/main:Sqimitive",s="Sqimitive.Async";"undefined"==typeof exports||exports.nodeType?"function"==typeof define&&define.amd?define(e.replace(/\?/g,"/").match(/\S+(?=:)/g)||[],t):(i="object"==typeof self?self:"object"==typeof global?global:this||{},n=function(t,e){for(e=e.split(".");t&&e.length;)t=t[e.shift()];return t},e=(e.match(/:\S+/g)||[]).map(function(t){var e=n(i,t=t.substr(1));if(e)return e;throw s+": missing dependency: "+t}),s=s.split(/\.([^.]+)$/),(i=1<s.length?n(i,s.shift()):i)[s[0]]=t.apply(this,e)):(e=(e.replace(/\?[^:]*/g,"").match(/\S+(?=:)/g)||[]).map(require),"undefined"!=typeof module&&module.exports?module.exports=t.apply(this,e):exports=t.apply(this,e))}.call(this,function(s){"use strict";var n=s._,o={},t=s.Base.extend("Sqimitive.Async",{MAX_PRIORITY:2,_childClass:"",_childEvents:["change_status","=exception"],_opt:{status:null,ignoreError:!1,immediateError:!1},events:{".change_status":"_childComplete",".=exception":function(){this.exception.apply(this,n.rest(arguments,2))},"=nestEx":function(t,e){e=!this.includes(e.child),t=t(this,arguments);return e&&this._childComplete(t.child),t},change_status:function(){var t,e;this.isLoading()||(e=!0===(t=this._callPriorities(this.isSuccessful()?"success":"error",[this]))||this._callPriorities("complete",[this]),"object"==typeof t?this.exception(t):"object"==typeof e&&this.exception(e))},"=toString":function(){return[this.constructor.name,"["+this.length+"]",this.get("ignoreError")?"~":"",this.get("immediateError")?"@":"",null==this.get("status")?"LOADING":this.get("status")?"DONE":"ERROR"].join(" ")}},_callPriorities:function(t,e){for(var i,n=this.MAX_PRIORITY,s=-n;s<=n;s++)try{var r=this.fire(t+(s||""),e);if(r===o)break}catch(t){i=i||t}return i||r===o},fuse:function(i,t,e){var n=s.Base.prototype.fuse.apply(this,arguments);return i.match(/^(success|error|complete)(-?\d+)?$/)&&(n.post=function(t,e){return t.func=s.Core.stub,t.post=void 0,t.stop="c"==i[0]?this.isLoading():this.isSuccessful()!==("s"==i[0]),t.stop?o:e}.bind(this)),n},_childComplete:function(){var t;!1!==this.isSuccessful()&&(t=this.countBy(function(t){return""+t.isSuccessful()}),this.set("status",this.get("immediateError")?!t.false&&(!t.null||null):t.null?null:!t.false))},_when:function(t,e,i,n,s){if("number"==typeof e)throw new TypeError("Sqimitive.Async: mistaken cx for priority?");if(n)try{t.call(e||this,this)}catch(t){this.exception(t)}else i=Math.max(-this.MAX_PRIORITY,Math.min(this.MAX_PRIORITY,i)),this.on(s+(+i||""),t,e);return this},whenComplete:function(t,e,i){return this._when(t,e,i,!this.isLoading(),"complete")},whenError:function(t,e,i){return this._when(t,e,i,0==this.isSuccessful(),"error")},whenSuccess:function(t,e,i){return this._when(t,e,i,1==this.isSuccessful(),"success")},doneIfEmpty:function(){if(!this.length&&this.isLoading())return this.set("status",!0),!0},clear:function(){return n.forEach(["success","error","complete"],function(t){this.off(t)},this),this.sink("abort",[],!0),this.forEach(this.unlist),this.set("status",null),this},nestDoner:function(){var e=this.nest({});function t(t){e&&e.set("status",t!==o)}return e.on("abort",function(){e=null}),t.error=function(){t(o)},t},isSuccessful:function(){var t=this.get("status");return null==t?null:!(!this.get("ignoreError")&&!t)},isLoading:function(){return null==this.get("status")},success:s.Core.stub,error:s.Core.stub,complete:s.Core.stub,exception:function(t){throw t},abort:s.Core.stub});return t.Fetch=t.extend("Sqimitive.Async.Fetch",{request:null,requestError:null,response:null,_abortController:null,_opt:{function:null},events:{init:function(){this._start(this.get())},"=abort":function(t,e){var i;return this.isLoading()&&((i=this.request.abort?this.request:this._abortController)?i.abort.apply(i,n.rest(arguments)):this.set("status",!1)),this},"=toString":function(t){return[t(this),this.request&&this.request.constructor.name||"???",this.readyStateText(),this.request&&this.request.statusText||"",this.get("url")].join(" ")}},readyStateText:function(){return this.request&&["UNSENT","OPENED","HEADERS_RECEIVED","LOADING","DONE"][this.request.readyState]||""},_start:function(t){if(this.request)throw new Error("Sqimitive.Async.Fetch has already started.");function i(t,e){this.isLoading()&&this.batch(null,function(){t?this._assign(e):this.requestError=e,this.set("status",t)})}t=n.assign({method:t.type,body:t.data},t,{context:this,success:function(t){i.call(this,!0,t)},error:function(t,e){i.call(this,!1,e)},signal:"function"==typeof AbortController?(this._abortController=new AbortController).signal:null});t=this._fetch(t);this.request=this.request||t},_fetch:function(e){var t=(this.get("function")||this.constructor.defaultFunction)(e);return"function"==typeof t.then&&t.then(function(t){(t.ok?e.success:e.error)(t,t)},e.error.bind(null,null)),t},_assign:function(t){if("responseJSON"in t)var e=t.responseJSON;else switch(t.responseType){case"":case"document":if(t.responseXML){e=t.responseXML;break}case"text":e=t.responseText;break;default:e="response"in t?t.response:t}this.response=e}}),t.Fetch.defaultFunction="object"==typeof self&&((self.jQuery||self.Zepto||self._||{}).ajax||self.fetch&&function(t){return self.fetch(t.url,t)}),t});